From: Nuno Lopes Date: Mon, 2 Feb 2009 15:00:55 +0000 (+0000) Subject: fix PR3459: improve compatibility with gcc when checking for constant exprs X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f23199847b686ca2d674274ee7271f75640c1e0e;p=clang fix PR3459: improve compatibility with gcc when checking for constant exprs git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63517 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 5dd45fb072..7d7badd2cb 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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 index 0000000000..cacd847658 --- /dev/null +++ b/test/Sema/struct-decl.c @@ -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]; +};