From: Eli Friedman Date: Thu, 28 May 2009 23:04:00 +0000 (+0000) Subject: PR4281: Fix bogus CodeGen assertion. The issue is that X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2dce5f8a99b5c48f1287ff3941288ca6f7fde2de;p=clang PR4281: Fix bogus CodeGen assertion. The issue is that 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 --- diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index af1bbfdd58..d90f701758 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -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 index 0000000000..e46e83b947 --- /dev/null +++ b/test/CodeGen/2009-05-28-const-typedef.c @@ -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(); +} +