From 14f7dacb8825e81e14d85c7b4546e735a6e2f7c1 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 30 Nov 2018 20:40:06 +0000 Subject: [PATCH] We're in a constant context in the ConstantEmitter. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348029 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 3 ++- test/CodeGen/builtin-constant-p.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index eb5e010968..ca86e10710 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -1552,7 +1552,8 @@ llvm::Constant *ConstantEmitter::tryEmitPrivate(const Expr *E, if (destType->isReferenceType()) Success = E->EvaluateAsLValue(Result, CGM.getContext()); else - Success = E->EvaluateAsRValue(Result, CGM.getContext()); + Success = E->EvaluateAsRValue(Result, CGM.getContext(), + /* InConstantContext */ true); llvm::Constant *C; if (Success && !Result.HasSideEffects) diff --git a/test/CodeGen/builtin-constant-p.c b/test/CodeGen/builtin-constant-p.c index 5cdcc72123..943d288632 100644 --- a/test/CodeGen/builtin-constant-p.c +++ b/test/CodeGen/builtin-constant-p.c @@ -157,3 +157,14 @@ static void src_fn(void) { void test14() { assign(dest_p, src_fn); } + +struct test15_s { + const char *name; + int num_args; +}; + +extern int test15_v; + +struct test15_s tcg_op_defs_org_x86_64[] = { + {"tag", __builtin_constant_p(test15_v) && !test15_v ? 0x10 : 0 }, +}; -- 2.50.1