Author: hans Date: Wed Dec 9 19:38:04 2015 New Revision: 255201 URL: http://llvm.org/viewvc/llvm-project?rev=255201&view=rev Log: 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 Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp cfe/trunk/test/CodeGen/ms-inline-asm.c Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=255201&r1=255200&r2=255201&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGStmt.cpp (original) +++ cfe/trunk/lib/CodeGen/CGStmt.cpp Wed Dec 9 19:38:04 2015 @@ -1999,6 +1999,15 @@ void CodeGenFunction::EmitAsmStmt(const Result->addAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::NoUnwind); + if (isa<MSAsmStmt>(&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) Modified: cfe/trunk/test/CodeGen/ms-inline-asm.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-inline-asm.c?rev=255201&r1=255200&r2=255201&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/ms-inline-asm.c (original) +++ cfe/trunk/test/CodeGen/ms-inline-asm.c Wed Dec 9 19:38:04 2015 @@ -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 La } // 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{{.*}} } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits