summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-04-25 20:37:58 +0000
committerChris Lattner <sabre@nondot.org>2011-04-25 20:37:58 +0000
commitcdb591af0338a197bdf6b9a77c89c630e556369a (patch)
tree4cdeab46dc44944c600c6bb218d7b6b49955ea2e /clang/lib
parentfc87e2dd5c997060e4d82dd50f7a5e8ebd439998 (diff)
downloadbcm5719-llvm-cdb591af0338a197bdf6b9a77c89c630e556369a.tar.gz
bcm5719-llvm-cdb591af0338a197bdf6b9a77c89c630e556369a.zip
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. llvm-svn: 130148
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaTemplate.cpp19
-rw-r--r--clang/lib/Sema/TreeTransform.h3
2 files changed, 10 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index bc29a4cbdc0..3123f5fc675 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3840,18 +3840,18 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
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 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
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);
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c642e642cc8..b2aa85e7198 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -2819,8 +2819,7 @@ bool TreeTransform<Derived>::TransformTemplateArgument(
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;
OpenPOWER on IntegriCloud