From: Hans Wennborg Date: Thu, 10 Dec 2015 01:38:04 +0000 (+0000) Subject: Mark MS inline ASM 'nodplicate' it it has labels (PR23715) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=df439c8a2843e2f7cf217bbc9cea03a93a170a24;p=clang Mark MS inline ASM 'nodplicate' it it has labels (PR23715) Duplicating it can lead to labels being defined twice. Differential revision: http://reviews.llvm.org/D15399 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255201 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index b0ca80e941..aae867bd3f 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -1999,6 +1999,15 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { Result->addAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::NoUnwind); + if (isa(&S)) { + // If the assembly contains any labels, mark the call noduplicate to prevent + // defining the same ASM label twice (PR23715). This is pretty hacky, but it + // works. + if (AsmString.find("__MSASMLABEL_") != std::string::npos) + Result->addAttribute(llvm::AttributeSet::FunctionIndex, + llvm::Attribute::NoDuplicate); + } + // Attach readnone and readonly attributes. if (!HasSideEffect) { if (ReadNone) diff --git a/test/CodeGen/ms-inline-asm.c b/test/CodeGen/ms-inline-asm.c index cc0fb06dd0..36dac6e69e 100644 --- a/test/CodeGen/ms-inline-asm.c +++ b/test/CodeGen/ms-inline-asm.c @@ -533,8 +533,8 @@ void label1() { label: jmp label } - // CHECK-LABEL: define void @label1 - // CHECK: call void asm sideeffect inteldialect "{{.*}}__MSASMLABEL_.1__label:\0A\09jmp {{.*}}__MSASMLABEL_.1__label", "~{dirflag},~{fpsr},~{flags}"() + // CHECK-LABEL: define void @label1() + // CHECK: call void asm sideeffect inteldialect "{{.*}}__MSASMLABEL_.1__label:\0A\09jmp {{.*}}__MSASMLABEL_.1__label", "~{dirflag},~{fpsr},~{flags}"() [[ATTR1:#[0-9]+]] } void label2() { @@ -581,3 +581,6 @@ int test_indirect_field(LARGE_INTEGER LargeInteger) { } // CHECK-LABEL: define i32 @test_indirect_field( // CHECK: call i32 asm sideeffect inteldialect "mov eax, dword ptr $1", + +// MS ASM containing labels must not be duplicated (PR23715). +// CHECK: attributes [[ATTR1]] = { {{.*}}noduplicate{{.*}} }