]> granicus.if.org Git - clang/commitdiff
More APSInt appeasement
authorDouglas Gregor <dgregor@apple.com>
Fri, 23 Jan 2009 22:22:29 +0000 (22:22 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 23 Jan 2009 22:22:29 +0000 (22:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62884 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/Sema/designated-initializers.c

index 15e2d5d13f2f73b9303dc9f3c693f6bf34463069..55d11b439854d5eee93415ed0acddabf221b6c63 100644 (file)
@@ -671,18 +671,26 @@ Sema::OwningExprResult Sema::ActOnDesignatedInitializer(Designation &Desig,
       if (CheckArrayDesignatorExpr(*this, StartIndex, StartValue) ||
           CheckArrayDesignatorExpr(*this, EndIndex, EndValue))
         Invalid = true;
-      else if (EndValue < StartValue) {
-        Diag(D.getEllipsisLoc(), diag::err_array_designator_empty_range)
-          << StartValue.toString(10) << EndValue.toString(10) 
-          << StartIndex->getSourceRange() << EndIndex->getSourceRange();
-        Invalid = true;
-      } else {
-        Designators.push_back(ASTDesignator(InitExpressions.size(),
-                                            D.getLBracketLoc(), 
-                                            D.getEllipsisLoc(),
-                                            D.getRBracketLoc()));
-        InitExpressions.push_back(StartIndex);
-        InitExpressions.push_back(EndIndex);
+      else {
+        // Make sure we're comparing values with the same bit width.
+        if (StartValue.getBitWidth() > EndValue.getBitWidth())
+          EndValue.extend(StartValue.getBitWidth());
+        else if (StartValue.getBitWidth() < EndValue.getBitWidth())
+          StartValue.extend(EndValue.getBitWidth());
+
+        if (EndValue < StartValue) {
+          Diag(D.getEllipsisLoc(), diag::err_array_designator_empty_range)
+            << StartValue.toString(10) << EndValue.toString(10) 
+            << StartIndex->getSourceRange() << EndIndex->getSourceRange();
+          Invalid = true;
+        } else {
+          Designators.push_back(ASTDesignator(InitExpressions.size(),
+                                              D.getLBracketLoc(), 
+                                              D.getEllipsisLoc(),
+                                              D.getRBracketLoc()));
+          InitExpressions.push_back(StartIndex);
+          InitExpressions.push_back(EndIndex);
+        }
       }
       break;
     }
index 8f7eb8cda92809c9962abcf1519eeefe0c2b2ae7..fd4873193cfd366a79d9237af6594895db48172d 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -verify -arch x86_64 %s
 
 int complete_array_from_init[] = { 1, 2, [10] = 5, 1, 2, [5] = 2, 6 };