From: Eli Friedman Date: Thu, 30 Apr 2009 07:03:22 +0000 (+0000) Subject: Fix for PR4108: be a bit looser with the casts that we accept in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=944af7156db03d4ad15973dad259ab51d405e609;p=clang Fix for PR4108: be a bit looser with the casts that we accept in constant initializers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70483 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index d7c6457ff8..e618dab33e 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -59,8 +59,9 @@ public: return EmitUnion(CGM.EmitConstantExpr(SubExpr, SubExpr->getType(), CGF), Ty); } - if (CGM.getContext().getCanonicalType(E->getSubExpr()->getType()) == - CGM.getContext().getCanonicalType(E->getType())) { + // Explicit and implicit no-op casts + QualType Ty = E->getType(), SubTy = E->getSubExpr()->getType(); + if (CGM.getContext().hasSameUnqualifiedType(Ty, SubTy)) { return Visit(E->getSubExpr()); } return 0; diff --git a/test/CodeGen/const-init.c b/test/CodeGen/const-init.c index a7220e0c29..1f9d74c7e9 100644 --- a/test/CodeGen/const-init.c +++ b/test/CodeGen/const-init.c @@ -96,4 +96,9 @@ void *g20(void) { return l0.f1; } +// PR4108 +struct g21 {int g21;}; +const struct g21 g21 = (struct g21){1}; + // RUN: true +