]> granicus.if.org Git - clang/commitdiff
fix PR3459: improve compatibility with gcc when checking for constant exprs
authorNuno Lopes <nunoplopes@sapo.pt>
Mon, 2 Feb 2009 15:00:55 +0000 (15:00 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Mon, 2 Feb 2009 15:00:55 +0000 (15:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63517 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/struct-decl.c [new file with mode: 0644]

index 5dd45fb072d9799c6bd5eaa4c50e52c1ab5315af..7d7badd2cb6c6b696472b055355f8974f0d58255 100644 (file)
@@ -3128,10 +3128,9 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T,
     
   assert(EvalResult.Val.isInt() && "Size expressions must be integers!");
   llvm::APSInt &Res = EvalResult.Val.getInt();
-  if (Res > llvm::APSInt(Res.getBitWidth(), Res.isUnsigned()))
-    return Context.getConstantArrayType(VLATy->getElementType(),
-                                        Res, ArrayType::Normal, 0);
-  return QualType();
+
+  return Context.getConstantArrayType(VLATy->getElementType(),
+                                      Res, ArrayType::Normal, 0);
 }
 
 bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 
diff --git a/test/Sema/struct-decl.c b/test/Sema/struct-decl.c
new file mode 100644 (file)
index 0000000..cacd847
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: clang -fsyntax-only -verify %s
+
+// PR3459
+struct bar {
+       char n[1];
+};
+
+struct foo {
+       char name[(int)&((struct bar *)0)->n];
+};