From f6a9f0e112f396471709c7f5897375dceba9f251 Mon Sep 17 00:00:00 2001 From: Ahmed Bougacha Date: Sat, 13 Jun 2015 01:16:10 +0000 Subject: [PATCH] [CodeGen] Don't evaluate immediate inlineasm arguments using isICE(). Instead, just EvaluateAsInt(). Follow-up to r239549: rsmith points out that isICE() is expensive; seems like it's not the right concept anyway, as it fails on `static const' in C, and will actually trigger the assert below on: test/Sema/inline-asm-validate-x86.c llvm-svn: 239651 --- clang/lib/CodeGen/CGStmt.cpp | 2 +- clang/test/CodeGen/inline-asm-immediate-ubsan.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 57f55aac..a79b3e3 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -1754,7 +1754,7 @@ llvm::Value* CodeGenFunction::EmitAsmInput( // (immediate or symbolic), try to emit it as such. if (!Info.allowsRegister() && !Info.allowsMemory()) { llvm::APSInt Result; - if (InputExpr->isIntegerConstantExpr(Result, getContext())) + if (InputExpr->EvaluateAsInt(Result, getContext())) return llvm::ConstantInt::get(getLLVMContext(), Result); assert(!Info.requiresImmediateConstant() && "Required-immediate inlineasm arg isn't constant?"); diff --git a/clang/test/CodeGen/inline-asm-immediate-ubsan.c b/clang/test/CodeGen/inline-asm-immediate-ubsan.c index 2773c6e..77d5e4f 100644 --- a/clang/test/CodeGen/inline-asm-immediate-ubsan.c +++ b/clang/test/CodeGen/inline-asm-immediate-ubsan.c @@ -20,6 +20,11 @@ void test_inlineasm_i() { // CHECK-LABEL: @test_inlineasm_I // CHECK: call void asm sideeffect "int $0", "I{{.*}}"(i32 2) +// CHECK: call void asm sideeffect "int $0", "I{{.*}}"(i32 3) void test_inlineasm_I() { __asm__ __volatile__("int %0" :: "I"(1 + 1)); + + // Also check a C non-ICE. + static const int N = 1; + __asm__ __volatile__("int %0" :: "I"(N + 2)); } -- 2.7.4