diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-04-15 15:53:31 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-04-15 15:53:31 +0000 |
| commit | c1cf814c8b660c98912ac00d00dfd24b9f23900c (patch) | |
| tree | 132c76591169d15265c80e614565bdeb12b1ab68 | |
| parent | ff3c8b7eaf2de9640a4b99cedacd370511897a92 (diff) | |
| download | bcm5719-llvm-c1cf814c8b660c98912ac00d00dfd24b9f23900c.tar.gz bcm5719-llvm-c1cf814c8b660c98912ac00d00dfd24b9f23900c.zip | |
Fix a few cases where enum constant handling was using
ASTContext::getTypeSize() rather than ASTContext::getIntWidth() for
the width of an integral type. The former includes padding for bools
(to the target's size) while the latter does not, so we woud end up
zero-extending bools to the target width when we shouldn't. Fixes a
crash-on-valid in the included test.
llvm-svn: 101372
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 6 | ||||
| -rw-r--r-- | clang/test/SemaCXX/constant-expression.cpp | 10 |
2 files changed, 10 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 8e46b9b6576..42d18cd27aa 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -6006,7 +6006,7 @@ static bool isRepresentableIntegerValue(ASTContext &Context, llvm::APSInt &Value, QualType T) { assert(T->isIntegralType() && "Integral type required!"); - unsigned BitWidth = Context.getTypeSize(T); + unsigned BitWidth = Context.getIntWidth(T); if (Value.isUnsigned() || Value.isNonNegative()) return Value.getActiveBits() < BitWidth; @@ -6139,7 +6139,7 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, // value, then increment. EnumVal = LastEnumConst->getInitVal(); EnumVal.setIsSigned(EltTy->isSignedIntegerType()); - EnumVal.zextOrTrunc(Context.getTypeSize(EltTy)); + EnumVal.zextOrTrunc(Context.getIntWidth(EltTy)); ++EnumVal; // If we're not in C++, diagnose the overflow of enumerator values, @@ -6161,7 +6161,7 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, if (!EltTy->isDependentType()) { // Make the enumerator value match the signedness and size of the // enumerator's type. - EnumVal.zextOrTrunc(Context.getTypeSize(EltTy)); + EnumVal.zextOrTrunc(Context.getIntWidth(EltTy)); EnumVal.setIsSigned(EltTy->isSignedIntegerType()); } diff --git a/clang/test/SemaCXX/constant-expression.cpp b/clang/test/SemaCXX/constant-expression.cpp index 0d4d3874330..a17dd58dab0 100644 --- a/clang/test/SemaCXX/constant-expression.cpp +++ b/clang/test/SemaCXX/constant-expression.cpp @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s - // C++ [expr.const]p1: // In several places, C++ requires expressions that evaluate to an integral // or enumeration constant: as array bounds, as case expressions, as @@ -79,5 +78,10 @@ template <int itval, Enum etval> struct C { }; template struct C<1, eval>; -//template struct C<cval, ceval>; -//template struct C<Struct::sval, Struct::seval>; +template struct C<cval, ceval>; +template struct C<Struct::sval, Struct::seval>; + +enum { + a = sizeof(int) == 8, + b = a? 8 : 4 +}; |

