diff options
author | Anders Carlsson <andersca@mac.com> | 2009-02-20 18:53:20 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-02-20 18:53:20 +0000 |
commit | 540b146d013b3b6d5ab7c485b9e692a866173e15 (patch) | |
tree | ef6bf43a8c4068236571bfc342d56277f8694615 /lib/Sema/SemaDecl.cpp | |
parent | 9876edc067ca5aae3102669e7e8eac100da0f93d (diff) |
Always try to fold array sizes, and warn if we could fold something that isn't an ICE. This makes us compatible with GCC.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65140 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 47 |
1 files changed, 3 insertions, 44 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 08b5a8c2ab..b69453d447 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3398,36 +3398,6 @@ void Sema::ActOnTagFinishDefinition(Scope *S, DeclTy *TagD) { Consumer.HandleTagDeclDefinition(Tag); } -/// TryToFixInvalidVariablyModifiedType - Helper method to turn variable array -/// types into constant array types in certain situations which would otherwise -/// be errors (for GCC compatibility). -static QualType TryToFixInvalidVariablyModifiedType(QualType T, - ASTContext &Context, - bool &SizeIsNegative) { - // This method tries to turn a variable array into a constant - // array even when the size isn't an ICE. This is necessary - // for compatibility with code that depends on gcc's buggy - // constant expression folding, like struct {char x[(int)(char*)2];} - SizeIsNegative = false; - - const VariableArrayType* VLATy = dyn_cast<VariableArrayType>(T); - if (!VLATy) return QualType(); - - Expr::EvalResult EvalResult; - if (!VLATy->getSizeExpr() || - !VLATy->getSizeExpr()->Evaluate(EvalResult, Context)) - return QualType(); - - 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); - - SizeIsNegative = true; - return QualType(); -} - bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, QualType FieldTy, const Expr *BitWidth) { // FIXME: 6.7.2.1p4 - verify the field type. @@ -3473,20 +3443,9 @@ Sema::DeclTy *Sema::ActOnField(Scope *S, DeclTy *TagD, // C99 6.7.2.1p8: A member of a structure or union may have any type other // than a variably modified type. if (T->isVariablyModifiedType()) { - bool SizeIsNegative; - QualType FixedTy = TryToFixInvalidVariablyModifiedType(T, Context, - SizeIsNegative); - if (!FixedTy.isNull()) { - Diag(Loc, diag::warn_illegal_constant_array_size); - T = FixedTy; - } else { - if (SizeIsNegative) - Diag(Loc, diag::err_typecheck_negative_array_size); - else - Diag(Loc, diag::err_typecheck_field_variable_size); - T = Context.IntTy; - InvalidDecl = true; - } + Diag(Loc, diag::err_typecheck_field_variable_size); + T = Context.IntTy; + InvalidDecl = true; } if (BitWidth) { |