From: Richard Smith Date: Thu, 13 Nov 2014 23:03:19 +0000 (+0000) Subject: Fix assert/crash on invalid with __builtin_constant_p conditionals in constant expres... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98710fc4f549f70a094690c70272cb6cbda6fb02;p=platform%2Fupstream%2Fllvm.git Fix assert/crash on invalid with __builtin_constant_p conditionals in constant expressions. llvm-svn: 221942 --- diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 2ce5ac5..ea28d74 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -8971,7 +8971,11 @@ static bool EvaluateCPlusPlus11IntegralConstantExpr(const ASTContext &Ctx, 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; } diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index 7c938d5..e706750 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -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}} } } }