]> granicus.if.org Git - clang/commitdiff
Fix assert/crash on invalid with __builtin_constant_p conditionals in constant expres...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 13 Nov 2014 23:03:19 +0000 (23:03 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 13 Nov 2014 23:03:19 +0000 (23:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221942 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/SemaCXX/constant-expression-cxx11.cpp

index 2ce5ac590bd7da07eedd55d608e9f7bac10fb983..ea28d74ddc7098507a1d55949ce53d5ed97e57f2 100644 (file)
@@ -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;
 }
index 7c938d54ffa69165f285c9bde88c135a41d39d06..e706750540a8b3d89a2af091b5d5217de6119ff4 100644 (file)
@@ -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}}
     }
   }
 }