[cfe-commits] r130148 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp lib/Sema/TreeTransform.h test/SemaCXX/short-enums.cpp
Chris Lattner
sabre at nondot.org
Mon Apr 25 13:37:58 PDT 2011
Author: lattner
Date: Mon Apr 25 15:37:58 2011
New Revision: 130148
URL: http://llvm.org/viewvc/llvm-project?rev=130148&view=rev
Log:
fix PR9474, a crash with -fshort-enum and C++ templates: when instantiating
the enum decl, we need to use an integer type the same size as the enumerator,
which may not be the promoted type with packed enums.
Added:
cfe/trunk/test/SemaCXX/short-enums.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/TreeTransform.h
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=130148&r1=130147&r2=130148&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Apr 25 15:37:58 2011
@@ -3840,18 +3840,18 @@
if (T->isCharType() || T->isWideCharType())
return Owned(new (Context) CharacterLiteral(
Arg.getAsIntegral()->getZExtValue(),
- T->isWideCharType(),
- T,
- Loc));
+ T->isWideCharType(), T, Loc));
if (T->isBooleanType())
return Owned(new (Context) CXXBoolLiteralExpr(
Arg.getAsIntegral()->getBoolValue(),
- T,
- Loc));
+ T, Loc));
+ // If this is an enum type that we're instantiating, we need to use an integer
+ // type the same size as the enumerator. We don't want to build an
+ // IntegerLiteral with enum type.
QualType BT;
if (const EnumType *ET = T->getAs<EnumType>())
- BT = ET->getDecl()->getPromotionType();
+ BT = ET->getDecl()->getIntegerType();
else
BT = T;
@@ -3859,10 +3859,9 @@
if (T->isEnumeralType()) {
// FIXME: This is a hack. We need a better way to handle substituted
// non-type template parameters.
- E = CStyleCastExpr::Create(Context, T, VK_RValue, CK_IntegralCast,
- E, 0,
- Context.getTrivialTypeSourceInfo(T, Loc),
- Loc, Loc);
+ E = CStyleCastExpr::Create(Context, T, VK_RValue, CK_IntegralCast, E, 0,
+ Context.getTrivialTypeSourceInfo(T, Loc),
+ Loc, Loc);
}
return Owned(E);
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=130148&r1=130147&r2=130148&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Mon Apr 25 15:37:58 2011
@@ -2819,8 +2819,7 @@
Expr *InputExpr = Input.getSourceExpression();
if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
- ExprResult E
- = getDerived().TransformExpr(InputExpr);
+ ExprResult E = getDerived().TransformExpr(InputExpr);
if (E.isInvalid()) return true;
Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
return false;
Added: cfe/trunk/test/SemaCXX/short-enums.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/short-enums.cpp?rev=130148&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/short-enums.cpp (added)
+++ cfe/trunk/test/SemaCXX/short-enums.cpp Mon Apr 25 15:37:58 2011
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fshort-enums -fsyntax-only %s
+
+// This shouldn't crash: PR9474
+
+enum E { VALUE_1 };
+
+template <typename T>
+struct A {};
+
+template <E Enum>
+struct B : A<B<Enum> > {};
+
+void bar(int x) {
+ switch (x) {
+ case sizeof(B<VALUE_1>): ;
+ }
+}
\ No newline at end of file
More information about the cfe-commits
mailing list