]> granicus.if.org Git - clang/commitdiff
Make sure to take the unqualified versions of the canonical types for
authorEli Friedman <eli.friedman@gmail.com>
Tue, 2 Sep 2008 05:09:35 +0000 (05:09 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 2 Sep 2008 05:09:35 +0000 (05:09 +0000)
type-checking pointer subtraction; if the canonical types aren't used,
the qualifiers won't always get stripped off correctly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55620 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/pointer-subtract-compat.c [new file with mode: 0644]

index ba13e7fe66c45aa6532b69f71dd4f6f6667e74ff..fe9a13e4643e039da2e7295f9baa7ba7397e1ec0 100644 (file)
@@ -1013,7 +1013,7 @@ ActOnCallExpr(ExprTy *fn, SourceLocation LParenLoc,
       AssignConvertType ConvTy =
         CheckSingleAssignmentConstraints(ProtoArgType, Arg);
       TheCall->setArg(i, Arg);
-      
+
       if (DiagnoseAssignmentResult(ConvTy, Arg->getLocStart(), ProtoArgType,
                                    ArgType, Arg, "passing"))
         return true;
@@ -1700,8 +1700,9 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex,
       }
       
       // Pointee types must be compatible.
-      if (!Context.typesAreCompatible(lpointee.getUnqualifiedType(), 
-                                      rpointee.getUnqualifiedType())) {
+      if (!Context.typesAreCompatible(
+              Context.getCanonicalType(lpointee).getUnqualifiedType(), 
+              Context.getCanonicalType(rpointee).getUnqualifiedType())) {
         Diag(loc, diag::err_typecheck_sub_ptr_compatible,
              lex->getType().getAsString(), rex->getType().getAsString(),
              lex->getSourceRange(), rex->getSourceRange());
diff --git a/test/Sema/pointer-subtract-compat.c b/test/Sema/pointer-subtract-compat.c
new file mode 100644 (file)
index 0000000..4ed6abf
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: clang %s -fsyntax-only -verify -pedantic
+
+typedef const char rchar;
+int a(char* a, rchar* b) {
+  return a-b;
+}