r221942 - Fix assert/crash on invalid with __builtin_constant_p conditionals in constant expressions.
Richard Smith
richard-llvm at metafoo.co.uk
Thu Nov 13 15:03:19 PST 2014
Author: rsmith
Date: Thu Nov 13 17:03:19 2014
New Revision: 221942
URL: http://llvm.org/viewvc/llvm-project?rev=221942&view=rev
Log:
Fix assert/crash on invalid with __builtin_constant_p conditionals in constant expressions.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=221942&r1=221941&r2=221942&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Nov 13 17:03:19 2014
@@ -8971,7 +8971,11 @@ static bool EvaluateCPlusPlus11IntegralC
if (!E->isCXX11ConstantExpr(Ctx, &Result, Loc))
return false;
- assert(Result.isInt() && "pointer cast to int is not an ICE");
+ if (!Result.isInt()) {
+ if (Loc) *Loc = E->getExprLoc();
+ return false;
+ }
+
if (Value) *Value = Result.getInt();
return true;
}
Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=221942&r1=221941&r2=221942&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Thu Nov 13 17:03:19 2014
@@ -95,11 +95,13 @@ namespace TemplateArgumentConversion {
}
namespace CaseStatements {
+ int x;
void f(int n) {
switch (n) {
case MemberZero().zero: // expected-error {{did you mean to call it with no arguments?}} expected-note {{previous}}
case id(0): // expected-error {{duplicate case value '0'}}
return;
+ case __builtin_constant_p(true) ? (__SIZE_TYPE__)&x : 0:; // expected-error {{constant}}
}
}
}
More information about the cfe-commits
mailing list