tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] [patch] ignore qualifiers when comparing function paramet


From: Dave Dodge
Subject: [Tinycc-devel] [patch] ignore qualifiers when comparing function parameters
Date: Thu, 28 Oct 2004 21:41:21 -0400
User-agent: Mutt/1.4.2i

I have lots of code that results in constructs like this:

  extern void foo(int);
  void foo(int const x) { /* do something */ }

gcc and icc have no problem with this even in their strictest
settings, and I'm pretty sure I've used it with other compilers over
the years.  tcc 0.9.21 however rejects it because it sees "int" as not
being compatible with "int const".

According to N869 6.7.5.3 #11:
  [...]
  (In the determination of type compatibility and of a composite type,
  each parameter declared with function or array type is taken as
  having the adjusted type and each parameter declared with qualified
  type is taken as having the unqualified version of its declared
  type.)

The way I read this, qualifiers are supposed to be ignored when comparing
function parameters for compatibility.  The following patch implements
this for tcc.
                                                  -Dave Dodge


--- tcc-0.9.21/tcc.c    2004-10-25 17:18:51.000000000 -0400
+++ tcc-0.9.21-dododge/tcc.c    2004-10-28 21:08:49.000000000 -0400
@@ -751,7 +751,9 @@
 static int lvalue_type(int t);
 static int parse_btype(CType *type, AttributeDef *ad);
 static void type_decl(CType *type, AttributeDef *ad, int *v, int td);
+static int compare_types(CType *type1, CType *type2, int unqualified);
 static int is_compatible_types(CType *type1, CType *type2);
+static int is_compatible_parameter_types(CType *type1, CType *type2);
 
 int ieee_finite(double d);
 void error(const char *fmt, ...);
@@ -5821,7 +5823,7 @@
     while (s1 != NULL) {
         if (s2 == NULL)
             return 0;
-        if (!is_compatible_types(&s1->type, &s2->type))
+        if (!is_compatible_parameter_types(&s1->type, &s2->type))
             return 0;
         s1 = s1->next;
         s2 = s2->next;
@@ -5831,17 +5833,22 @@
     return 1;
 }
 
-/* return true if type1 and type2 are exactly the same (including
-   qualifiers). 
+/* return true if type1 and type2 are the same.  If unqualified is
+   true, qualifiers on the types are ignored.
 
    - enums are not checked as gcc __builtin_types_compatible_p () 
  */
-static int is_compatible_types(CType *type1, CType *type2)
+static int compare_types(CType *type1, CType *type2, int unqualified)
 {
     int bt1, t1, t2;
 
     t1 = type1->t & VT_TYPE;
     t2 = type2->t & VT_TYPE;
+    if (unqualified) {
+        /* strip qualifiers before comparing */
+        t1 &= ~(VT_CONSTANT | VT_VOLATILE);
+        t2 &= ~(VT_CONSTANT | VT_VOLATILE);
+    }
     /* XXX: bitfields ? */
     if (t1 != t2)
         return 0;
@@ -5860,6 +5867,21 @@
     }
 }
 
+/* return true if type1 and type2 are exactly the same (including
+   qualifiers). 
+*/
+static int is_compatible_types(CType *type1, CType *type2)
+{
+    return compare_types(type1,type2,0);
+}
+
+/* return true if type1 and type2 are the same (ignoring qualifiers).
+*/
+static int is_compatible_parameter_types(CType *type1, CType *type2)
+{
+    return compare_types(type1,type2,1);
+}
+
 /* print a type. If 'varstr' is not NULL, then the variable is also
    printed in the type */
 /* XXX: union */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]