summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2008-09-02 05:09:35 +0000
committerEli Friedman <eli.friedman@gmail.com>2008-09-02 05:09:35 +0000
commite7175d83dcb3ec0837036a92200f565dad63b784 (patch)
tree0b459fd9f014c9d8b366688dc518d769a4351c24
parenta1035df101054f1cb32beef2da0d30e04efe6823 (diff)
downloadbcm5719-llvm-e7175d83dcb3ec0837036a92200f565dad63b784.tar.gz
bcm5719-llvm-e7175d83dcb3ec0837036a92200f565dad63b784.zip
Make sure to take the unqualified versions of the canonical types for
type-checking pointer subtraction; if the canonical types aren't used, the qualifiers won't always get stripped off correctly. llvm-svn: 55620
-rw-r--r--clang/lib/Sema/SemaExpr.cpp7
-rw-r--r--clang/test/Sema/pointer-subtract-compat.c6
2 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ba13e7fe66c..fe9a13e4643 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -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/clang/test/Sema/pointer-subtract-compat.c b/clang/test/Sema/pointer-subtract-compat.c
new file mode 100644
index 00000000000..4ed6abf8af7
--- /dev/null
+++ b/clang/test/Sema/pointer-subtract-compat.c
@@ -0,0 +1,6 @@
+// RUN: clang %s -fsyntax-only -verify -pedantic
+
+typedef const char rchar;
+int a(char* a, rchar* b) {
+ return a-b;
+}
OpenPOWER on IntegriCloud