[cfe-commits] commit r46522

Steve Naroff snaroff at apple.com
Tue Jan 29 13:06:55 PST 2008


Folks,

For some reason, my commit this morning never posted (http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080128/date.html 
).

In case anyone is interested in reviewing the bug/fix, I've included  
the diff below.

We should also keep an eye out for this "bug" with cfe-commits.

snaroff

[snaroff:llvm/tools/clang] snarofflocal% svn diff -r 46521:46522
Index: test/Sema/function.c
===================================================================
--- test/Sema/function.c	(revision 46521)
+++ test/Sema/function.c	(revision 46522)
@@ -1,4 +1,4 @@
-// RUN: clang %s -fsyntax-only
+// RUN: clang %s -fsyntax-only -verify
  // PR1892
  void f(double a[restrict][5]);  // should promote to restrict ptr.
  void f(double (* restrict a)[5]);
@@ -6,6 +6,9 @@
  int foo (__const char *__path);
  int foo(__const char *__restrict __file);

+void func(const char*); //expected-error{{previous declaration is  
here}}
+void func(char*); //expected-error{{conflicting types for 'func'}}
+
  void g(int (*)(const void **, const void **));
  void g(int (*compar)()) {
  }
Index: Sema/SemaExpr.cpp
===================================================================
--- Sema/SemaExpr.cpp	(revision 46521)
+++ Sema/SemaExpr.cpp	(revision 46522)
@@ -1337,10 +1337,12 @@

    // Either ptr - int   or   ptr - ptr.
    if (const PointerType *LHSPTy = lex->getType()- 
 >getAsPointerType()) {
+    QualType lpointee = LHSPTy->getPointeeType();
+	
      // The LHS must be an object type, not incomplete, function, etc.
-    if (!LHSPTy->getPointeeType()->isObjectType()) {
+    if (!lpointee->isObjectType()) {
        // Handle the GNU void* extension.
-      if (LHSPTy->getPointeeType()->isVoidType()) {
+      if (lpointee->isVoidType()) {
          Diag(loc, diag::ext_gnu_void_ptr,
               lex->getSourceRange(), rex->getSourceRange());
        } else {
@@ -1356,11 +1358,13 @@

      // Handle pointer-pointer subtractions.
      if (const PointerType *RHSPTy = rex->getType()- 
 >getAsPointerType()) {
+	  QualType rpointee = RHSPTy->getPointeeType();
+	
        // RHS must be an object type, unless void (GNU).
-      if (!RHSPTy->getPointeeType()->isObjectType()) {
+      if (!rpointee->isObjectType()) {
          // Handle the GNU void* extension.
-        if (RHSPTy->getPointeeType()->isVoidType()) {
-          if (!LHSPTy->getPointeeType()->isVoidType())
+        if (rpointee->isVoidType()) {
+          if (!lpointee->isVoidType())
              Diag(loc, diag::ext_gnu_void_ptr,
                   lex->getSourceRange(), rex->getSourceRange());
          } else {
@@ -1371,8 +1375,8 @@
        }

        // Pointee types must be compatible.
-      if (!Context.typesAreCompatible(LHSPTy->getPointeeType(),
-                                      RHSPTy->getPointeeType())) {
+      if (!Context.typesAreCompatible(lpointee.getUnqualifiedType(),
+                                      rpointee.getUnqualifiedType())) {
          Diag(loc, diag::err_typecheck_sub_ptr_compatible,
               lex->getType().getAsString(), rex- 
 >getType().getAsString(),
               lex->getSourceRange(), rex->getSourceRange());
@@ -1446,12 +1450,13 @@
    // when handling null pointer constants. One day, we can consider  
making them
    // errors (when -pedantic-errors is enabled).
    if (lType->isPointerType() && rType->isPointerType()) { // C99  
6.5.8p2
-
+	QualType lpointee = lType->getAsPointerType()->getPointeeType();
+	QualType rpointee = rType->getAsPointerType()->getPointeeType();
+	
      if (!LHSIsNull && !RHSIsNull &&                       // C99  
6.5.9p2
-        !lType->getAsPointerType()->getPointeeType()->isVoidType() &&
-        !rType->getAsPointerType()->getPointeeType()->isVoidType() &&
-        !Context.pointerTypesAreCompatible(lType.getUnqualifiedType(),
-                                            
rType.getUnqualifiedType())) {
+        !lpointee->isVoidType() && !lpointee->isVoidType() &&
+        !Context.typesAreCompatible(lpointee.getUnqualifiedType(),
+									rpointee.getUnqualifiedType())) {
        Diag(loc, diag::ext_typecheck_comparison_of_distinct_pointers,
             lType.getAsString(), rType.getAsString(),
             lex->getSourceRange(), rex->getSourceRange());
Index: AST/ASTContext.cpp
===================================================================
--- AST/ASTContext.cpp	(revision 46521)
+++ AST/ASTContext.cpp	(revision 46522)
@@ -1617,6 +1617,9 @@
  /// C99 6.2.7p1: Two types have compatible types if their types are  
the
  /// same. See 6.7.[2,3,5] for additional rules.
  bool ASTContext::typesAreCompatible(QualType lhs, QualType rhs) {
+  if (lhs.getQualifiers() != rhs.getQualifiers())
+    return false;
+
    QualType lcanon = lhs.getCanonicalType();
    QualType rcanon = rhs.getCanonicalType();

[snaroff:llvm/tools/clang] snarofflocal%




More information about the cfe-commits mailing list