aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-11-12 19:48:13 +0000
committerChris Lattner <sabre@nondot.org>2008-11-12 19:48:13 +0000
commit57d5788b45b677463f3132410d6f530ae5a2cf87 (patch)
tree6c27d776b050bc8eba006cd64853323f21762cfc /lib/Sema/SemaDecl.cpp
parent3ab5543acfbaca11409c87efdc5154d7af21d47f (diff)
Restructure code to encourage fallthrough, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59157 91177308-0d34-0410-b5e6-96231b3b80d8
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();
}