[cfe-commits] r62858 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/Sema/designated-initializers.c

Douglas Gregor dgregor at apple.com
Fri Jan 23 10:58:43 PST 2009


Author: dgregor
Date: Fri Jan 23 12:58:42 2009
New Revision: 62858

URL: http://llvm.org/viewvc/llvm-project?rev=62858&view=rev
Log:
Make sure all of the isUnsigned flags line up when comparing initializer values, to really really fix PR clang/3377

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/Sema/designated-initializers.c

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=62858&r1=62857&r2=62858&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Jan 23 12:58:42 2009
@@ -271,12 +271,13 @@
   }
 
   // We might know the maximum number of elements in advance.
-  llvm::APSInt maxElements(elementIndex.getBitWidth(), 0);
+  llvm::APSInt maxElements(elementIndex.getBitWidth(), elementIndex.isUnsigned());
   bool maxElementsKnown = false;
   if (const ConstantArrayType *CAT =
         SemaRef->Context.getAsConstantArrayType(DeclType)) {
     maxElements = CAT->getSize();
     elementIndex.extOrTrunc(maxElements.getBitWidth());
+    elementIndex.setIsUnsigned(maxElements.isUnsigned());
     maxElementsKnown = true;
   }
 
@@ -303,6 +304,7 @@
         maxElements.extend(elementIndex.getBitWidth());
       else if (elementIndex.getBitWidth() < maxElements.getBitWidth())
         elementIndex.extend(maxElements.getBitWidth());
+      elementIndex.setIsUnsigned(maxElements.isUnsigned());
 
       // If the array is of incomplete type, keep track of the number of
       // elements in the initializer.
@@ -329,7 +331,7 @@
   if (DeclType->isIncompleteArrayType()) {
     // If this is an incomplete array type, the actual type needs to
     // be calculated here.
-    llvm::APInt Zero(maxElements.getBitWidth(), 0);
+    llvm::APSInt Zero(maxElements.getBitWidth(), maxElements.isUnsigned());
     if (maxElements == Zero) {
       // Sizing an array implicitly to zero is not allowed by ISO C,
       // but is supported by GNU.
@@ -568,6 +570,7 @@
   if (isa<ConstantArrayType>(AT)) {
     llvm::APSInt MaxElements(cast<ConstantArrayType>(AT)->getSize(), false);
     DesignatedIndex.extOrTrunc(MaxElements.getBitWidth());
+    DesignatedIndex.setIsUnsigned(MaxElements.isUnsigned());
     if (DesignatedIndex >= MaxElements) {
       SemaRef->Diag(IndexExpr->getSourceRange().getBegin(),
                     diag::err_array_designator_too_large)
@@ -617,7 +620,8 @@
       << Index->getSourceRange();
 
   // Make sure this constant expression is non-negative.
-  llvm::APSInt Zero(llvm::APSInt::getNullValue(Value.getBitWidth()), false);
+  llvm::APSInt Zero(llvm::APSInt::getNullValue(Value.getBitWidth()), 
+                    Value.isUnsigned());
   if (Value < Zero)
     return Self.Diag(Loc, diag::err_array_designator_negative)
       << Value.toString(10) << Index->getSourceRange();

Modified: cfe/trunk/test/Sema/designated-initializers.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/designated-initializers.c?rev=62858&r1=62857&r2=62858&view=diff

==============================================================================
--- cfe/trunk/test/Sema/designated-initializers.c (original)
+++ cfe/trunk/test/Sema/designated-initializers.c Fri Jan 23 12:58:42 2009
@@ -115,3 +115,4 @@
 
 // PR clang/3377
 int bitwidth[] = { [(long long int)1] = 5, [(short int)2] = 2 };
+int a[]= { [sizeof(int)] = 0 };





More information about the cfe-commits mailing list