From: Douglas Gregor Date: Fri, 23 Jan 2009 22:22:29 +0000 (+0000) Subject: More APSInt appeasement X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d6f584ff262f51b40f4c9e317b13f1f21db29755;p=clang More APSInt appeasement git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62884 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 15e2d5d13f..55d11b4398 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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; } diff --git a/test/Sema/designated-initializers.c b/test/Sema/designated-initializers.c index 8f7eb8cda9..fd4873193c 100644 --- a/test/Sema/designated-initializers.c +++ b/test/Sema/designated-initializers.c @@ -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 };