[cfe-commits] r63557 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/struct-decl.c
Nuno Lopes
nunoplopes at sapo.pt
Mon Feb 2 14:32:08 PST 2009
Author: nlopes
Date: Mon Feb 2 16:32:08 2009
New Revision: 63557
URL: http://llvm.org/viewvc/llvm-project?rev=63557&view=rev
Log:
fix TryToFixInvalidVariablyModifiedType to reject negative array sizes
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/struct-decl.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=63557&r1=63556&r2=63557&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Feb 2 16:32:08 2009
@@ -3114,9 +3114,10 @@
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,
Modified: cfe/trunk/test/Sema/struct-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/struct-decl.c?rev=63557&r1=63556&r2=63557&view=diff
==============================================================================
--- cfe/trunk/test/Sema/struct-decl.c (original)
+++ cfe/trunk/test/Sema/struct-decl.c Mon Feb 2 16:32:08 2009
@@ -7,4 +7,5 @@
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}}
};
More information about the cfe-commits
mailing list