aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 3484849161..bab55bf829 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2482,16 +2482,19 @@ QualType Sema::TryFixInvalidVariablyModifiedType(QualType T) {
// 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];}
- if (const VariableArrayType* VLATy = dyn_cast<VariableArrayType>(T)) {
- APValue Result;
- if (VLATy->getSizeExpr() &&
- VLATy->getSizeExpr()->tryEvaluate(Result, Context) && Result.isInt()) {
- llvm::APSInt &Res = Result.getInt();
- if (Res > llvm::APSInt(Res.getBitWidth(), Res.isUnsigned()))
- return Context.getConstantArrayType(VLATy->getElementType(),
- Res, ArrayType::Normal, 0);
- }
- }
+ const VariableArrayType* VLATy = dyn_cast<VariableArrayType>(T);
+ if (!VLATy) return QualType();
+
+ APValue Result;
+ if (!VLATy->getSizeExpr() ||
+ !VLATy->getSizeExpr()->tryEvaluate(Result, Context))
+ return QualType();
+
+ assert(Result.isInt() && "Size expressions must be integers!");
+ llvm::APSInt &Res = Result.getInt();
+ if (Res > llvm::APSInt(Res.getBitWidth(), Res.isUnsigned()))
+ return Context.getConstantArrayType(VLATy->getElementType(),
+ Res, ArrayType::Normal, 0);
return QualType();
}