[cfe-commits] r101372 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/constant-expression.cpp

Douglas Gregor dgregor at apple.com
Thu Apr 15 08:53:31 PDT 2010


Author: dgregor
Date: Thu Apr 15 10:53:31 2010
New Revision: 101372

URL: http://llvm.org/viewvc/llvm-project?rev=101372&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/constant-expression.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=101372&r1=101371&r2=101372&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Apr 15 10:53:31 2010
@@ -6006,7 +6006,7 @@
                                         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 @@
         // 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 @@
   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());
   }
   

Modified: cfe/trunk/test/SemaCXX/constant-expression.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression.cpp?rev=101372&r1=101371&r2=101372&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression.cpp Thu Apr 15 10:53:31 2010
@@ -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 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
+};





More information about the cfe-commits mailing list