From 85b8c025d41ecda9c83424dbd30d84cbeba958e7 Mon Sep 17 00:00:00 2001 From: Hal Finkel Date: Thu, 17 Jul 2014 14:49:58 +0000 Subject: [PATCH] Handle __assume in the VoidExprEvaluator This is a follow-up to an IRC conversation with Richard last night; __assume does not evaluate its argument, and so the argument should not contribute to whether (__assume(e), constant) can be used where a constant is required. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213267 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 10 ++++++++++ test/Sema/builtin-assume.c | 3 +++ 2 files changed, 13 insertions(+) diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 3552d65930..b1d2265872 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -7955,6 +7955,16 @@ public: return true; } } + + bool VisitCallExpr(const CallExpr *E) { + switch (E->getBuiltinCallee()) { + default: + return ExprEvaluatorBaseTy::VisitCallExpr(E); + case Builtin::BI__assume: + // The argument is not evaluated! + return true; + } + } }; } // end anonymous namespace diff --git a/test/Sema/builtin-assume.c b/test/Sema/builtin-assume.c index 6c83b6907e..1f6a3a0cd9 100644 --- a/test/Sema/builtin-assume.c +++ b/test/Sema/builtin-assume.c @@ -3,6 +3,9 @@ int foo(int *a, int i) { __assume(i != 4); __assume(++i > 2); //expected-warning {{the argument to __assume has side effects that will be discarded}} + + int test = sizeof(struct{char qq[(__assume(i != 5), 7)];}); + return a[i]; } -- 2.50.1