]> granicus.if.org Git - clang/commitdiff
PR4281: Fix bogus CodeGen assertion. The issue is that
authorEli Friedman <eli.friedman@gmail.com>
Thu, 28 May 2009 23:04:00 +0000 (23:04 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 28 May 2009 23:04:00 +0000 (23:04 +0000)
getUnqualifiedType() doesn't strip off all qualifiers for non-canonical
types.

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

lib/CodeGen/CGExprAgg.cpp
test/CodeGen/2009-05-28-const-typedef.c [new file with mode: 0644]

index af1bbfdd58bc21e7cede18695de4ac68bac690fe..d90f701758c77e246110ec80b996707c2224992e 100644 (file)
@@ -178,9 +178,8 @@ void AggExprEmitter::VisitCStyleCastExpr(CStyleCastExpr *E) {
 }
 
 void AggExprEmitter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
-  assert(CGF.getContext().typesAreCompatible(
-                          E->getSubExpr()->getType().getUnqualifiedType(),
-                          E->getType().getUnqualifiedType()) &&
+  assert(CGF.getContext().hasSameUnqualifiedType(E->getSubExpr()->getType(),
+                                                 E->getType()) &&
          "Implicit cast types must be compatible");
   Visit(E->getSubExpr());
 }
@@ -226,9 +225,8 @@ void AggExprEmitter::VisitBinaryOperator(const BinaryOperator *E) {
 void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) {
   // For an assignment to work, the value on the right has
   // to be compatible with the value on the left.
-  assert(CGF.getContext().typesAreCompatible(
-             E->getLHS()->getType().getUnqualifiedType(),
-             E->getRHS()->getType().getUnqualifiedType())
+  assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(),
+                                                 E->getRHS()->getType())
          && "Invalid assignment");
   LValue LHS = CGF.EmitLValue(E->getLHS());
 
@@ -378,8 +376,7 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
     if (E->getNumInits() > 0) {
       QualType T1 = E->getType();
       QualType T2 = E->getInit(0)->getType();
-      if (CGF.getContext().getCanonicalType(T1).getUnqualifiedType() == 
-          CGF.getContext().getCanonicalType(T2).getUnqualifiedType()) {
+      if (CGF.getContext().hasSameUnqualifiedType(T1, T2)) {
         EmitAggLoadOfLValue(E->getInit(0));
         return;
       }
diff --git a/test/CodeGen/2009-05-28-const-typedef.c b/test/CodeGen/2009-05-28-const-typedef.c
new file mode 100644 (file)
index 0000000..e46e83b
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: clang-cc -emit-llvm %s -o -
+// PR4281
+
+typedef struct {
+        int i;
+} something;
+
+typedef const something const_something;
+
+something fail(void);
+
+int
+main(int argc, char *argv[])
+{
+        const_something R = fail();
+}
+