aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2009-02-02 22:32:08 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2009-02-02 22:32:08 +0000
commit1dfa6e15cba39f27a438d63837435596e58af1c1 (patch)
tree738525588a18ffa898ffaa39fd6edd8b3e11693d
parent2b1e0039a1937e3df59b5c99bcf4746360db3441 (diff)
fix TryToFixInvalidVariablyModifiedType to reject negative array sizes
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63557 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDecl.cpp7
-rw-r--r--test/Sema/struct-decl.c1
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index d03879e907..21fe6e1ce4 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3114,9 +3114,10 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T,
assert(EvalResult.Val.isInt() && "Size expressions must be integers!");
llvm::APSInt &Res = EvalResult.Val.getInt();
-
- return Context.getConstantArrayType(VLATy->getElementType(),
- Res, ArrayType::Normal, 0);
+ if (Res >= llvm::APSInt(Res.getBitWidth(), Res.isUnsigned()))
+ return Context.getConstantArrayType(VLATy->getElementType(),
+ Res, ArrayType::Normal, 0);
+ return QualType();
}
bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
diff --git a/test/Sema/struct-decl.c b/test/Sema/struct-decl.c
index cacd847658..7d7961b16c 100644
--- a/test/Sema/struct-decl.c
+++ b/test/Sema/struct-decl.c
@@ -7,4 +7,5 @@ struct bar {
struct foo {
char name[(int)&((struct bar *)0)->n];
+ char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{fields must have a constant size}}
};