summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-01-23 18:58:42 +0000
committerDouglas Gregor <dgregor@apple.com>2009-01-23 18:58:42 +0000
commit583cf0ac574d74b2fd05f2ee87ca3785e7406e8d (patch)
tree042747f6921a2afd05565e9bdf78b4e1a50bc24f /clang/lib
parent42a8cd37b23e6482f7a6f4c5264d0d39d680142e (diff)
downloadbcm5719-llvm-583cf0ac574d74b2fd05f2ee87ca3785e7406e8d.tar.gz
bcm5719-llvm-583cf0ac574d74b2fd05f2ee87ca3785e7406e8d.zip
Make sure all of the isUnsigned flags line up when comparing initializer values, to really really fix PR clang/3377
llvm-svn: 62858
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaInit.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ba8312b7b52..aff46ef61d5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -271,12 +271,13 @@ void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType,
}
// 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 @@ void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType,
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 @@ void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType,
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 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList,
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 @@ CheckArrayDesignatorExpr(Sema &Self, Expr *Index, llvm::APSInt &Value) {
<< 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();
OpenPOWER on IntegriCloud