summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-10-24 08:07:57 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-10-24 08:07:57 +0000
commitd7be95d60a098e4643cf049309ce1f51806cd781 (patch)
tree7455a5125f74d6054a30a391af9a26f1e0eb60e8
parentb2d68310cb81c31e721e8dbb74d9713430147edb (diff)
downloadbcm5719-llvm-d7be95d60a098e4643cf049309ce1f51806cd781.tar.gz
bcm5719-llvm-d7be95d60a098e4643cf049309ce1f51806cd781.zip
PR2919: __builtin_types_compatible_p strips CRV qualifiers.
llvm-svn: 58079
-rw-r--r--clang/lib/AST/Expr.cpp8
-rw-r--r--clang/lib/AST/ExprConstant.cpp8
-rw-r--r--clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c5
3 files changed, 19 insertions, 2 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 6e62d09474c..c20ca25f283 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -717,7 +717,13 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
case TypesCompatibleExprClass: {
const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this);
Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
- Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2());
+ // Per gcc docs "this built-in function ignores top level
+ // qualifiers". We need to use the canonical version to properly
+ // be able to strip CRV qualifiers from the type.
+ QualType T0 = Ctx.getCanonicalType(TCE->getArgType1());
+ QualType T1 = Ctx.getCanonicalType(TCE->getArgType2());
+ Result = Ctx.typesAreCompatible(T0.getUnqualifiedType(),
+ T1.getUnqualifiedType());
break;
}
case CallExprClass: {
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5bc4170e70a..12010646bce 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -205,7 +205,13 @@ public:
}
bool VisitTypesCompatibleExpr(const TypesCompatibleExpr *E) {
Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
- Result = Info.Ctx.typesAreCompatible(E->getArgType1(), E->getArgType2());
+ // Per gcc docs "this built-in function ignores top level
+ // qualifiers". We need to use the canonical version to properly
+ // be able to strip CRV qualifiers from the type.
+ QualType T0 = Info.Ctx.getCanonicalType(E->getArgType1());
+ QualType T1 = Info.Ctx.getCanonicalType(E->getArgType2());
+ Result = Info.Ctx.typesAreCompatible(T0.getUnqualifiedType(),
+ T1.getUnqualifiedType());
return true;
}
bool VisitDeclRefExpr(const DeclRefExpr *E);
diff --git a/clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c b/clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c
new file mode 100644
index 00000000000..75d0bdcea64
--- /dev/null
+++ b/clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c
@@ -0,0 +1,5 @@
+typedef struct foo T0;
+typedef const struct foo T1;
+
+int a0[__builtin_types_compatible_p(T0,
+ const T1) ? 1 : -1];
OpenPOWER on IntegriCloud