From: Reid Kleckner Date: Mon, 28 Nov 2016 20:52:19 +0000 (+0000) Subject: [MS] Mangle a unique ID into all MS inline asm labels X-Git-Tag: llvmorg-4.0.0-rc1~3541 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=08ebbcebb984b115ad1feb5984306f46cacdc616;p=platform%2Fupstream%2Fllvm.git [MS] Mangle a unique ID into all MS inline asm labels This solves PR23715 in a way that is compatible with LTO. MSVC supports jumping to source-level labels and between inline asm blocks, but we don't. Also revert the old solution, r255201, which was to mark these calls as noduplicate. llvm-svn: 288059 --- diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 397c034..05031ed 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -788,9 +788,6 @@ public: /// \brief will hold 'respondsToSelector:' Selector RespondsToSelectorSel; - /// \brief counter for internal MS Asm label names. - unsigned MSAsmLabelNameCounter; - /// A flag to remember whether the implicit forms of operator new and delete /// have been declared. bool GlobalNewDeleteDeclared; diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 32233b1..c68fc18 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -2103,15 +2103,6 @@ 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/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 250e31b..fd1a94e 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -96,7 +96,6 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, ValueWithBytesObjCTypeMethod(nullptr), NSArrayDecl(nullptr), ArrayWithObjectsMethod(nullptr), NSDictionaryDecl(nullptr), DictionaryWithObjectsMethod(nullptr), - MSAsmLabelNameCounter(0), GlobalNewDeleteDeclared(false), TUKind(TUKind), NumSFINAEErrors(0), diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp index b36abb4..f11e7aa 100644 --- a/clang/lib/Sema/SemaStmtAsm.cpp +++ b/clang/lib/Sema/SemaStmtAsm.cpp @@ -753,14 +753,12 @@ LabelDecl *Sema::GetOrCreateMSAsmLabel(StringRef ExternalLabelName, // Create an internal name for the label. The name should not be a valid mangled // name, and should be unique. We use a dot to make the name an invalid mangled // name. - OS << "__MSASMLABEL_." << MSAsmLabelNameCounter++ << "__"; - for (auto it = ExternalLabelName.begin(); it != ExternalLabelName.end(); - ++it) { - OS << *it; - if (*it == '$') { - // We escape '$' in asm strings by replacing it with "$$" + OS << "__MSASMLABEL_.{:uid}__"; + for (char C : ExternalLabelName) { + OS << C; + // We escape '$' in asm strings by replacing it with "$$" + if (C == '$') OS << '$'; - } } Label->setMSAsmLabel(OS.str()); } diff --git a/clang/test/CodeGen/mozilla-ms-inline-asm.c b/clang/test/CodeGen/mozilla-ms-inline-asm.c index b8b7a2d..b155956 100644 --- a/clang/test/CodeGen/mozilla-ms-inline-asm.c +++ b/clang/test/CodeGen/mozilla-ms-inline-asm.c @@ -20,7 +20,7 @@ void invoke(void* that, unsigned methodIndex, // CHECK: call void asm sideeffect inteldialect // CHECK: mov edx,dword ptr $1 // CHECK: test edx,edx -// CHECK: jz {{[^_]*}}__MSASMLABEL_.0__noparams +// CHECK: jz {{[^_]*}}__MSASMLABEL_.{:uid}__noparams // ^ Can't use {{.*}} here because the matching is greedy. // CHECK: mov eax,edx // CHECK: shl eax,$$3 @@ -28,7 +28,7 @@ void invoke(void* that, unsigned methodIndex, // CHECK: mov ecx,esp // CHECK: push dword ptr $0 // CHECK: call dword ptr $2 -// CHECK: {{.*}}__MSASMLABEL_.0__noparams: +// CHECK: {{.*}}__MSASMLABEL_.{:uid}__noparams: // CHECK: mov ecx,dword ptr $3 // CHECK: push ecx // CHECK: mov edx,[ecx] diff --git a/clang/test/CodeGen/ms-inline-asm.c b/clang/test/CodeGen/ms-inline-asm.c index aa1a474..0e9271f 100644 --- a/clang/test/CodeGen/ms-inline-asm.c +++ b/clang/test/CodeGen/ms-inline-asm.c @@ -249,7 +249,7 @@ void t23() { the_label: } // CHECK: t23 -// CHECK: call void asm sideeffect inteldialect "{{.*}}__MSASMLABEL_.0__the_label:", "~{dirflag},~{fpsr},~{flags}"() +// CHECK: call void asm sideeffect inteldialect "{{.*}}__MSASMLABEL_.{:uid}__the_label:", "~{dirflag},~{fpsr},~{flags}"() } void t24_helper(void) {} @@ -595,7 +595,7 @@ void label1() { jmp label } // 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]+]] + // CHECK: call void asm sideeffect inteldialect "{{.*}}__MSASMLABEL_.{:uid}__label:\0A\09jmp {{.*}}__MSASMLABEL_.{:uid}__label", "~{dirflag},~{fpsr},~{flags}"() [[ATTR1:#[0-9]+]] } void label2() { @@ -604,7 +604,7 @@ void label2() { label: } // CHECK-LABEL: define void @label2 - // CHECK: call void asm sideeffect inteldialect "jmp {{.*}}__MSASMLABEL_.2__label\0A\09{{.*}}__MSASMLABEL_.2__label:", "~{dirflag},~{fpsr},~{flags}"() + // CHECK: call void asm sideeffect inteldialect "jmp {{.*}}__MSASMLABEL_.{:uid}__label\0A\09{{.*}}__MSASMLABEL_.{:uid}__label:", "~{dirflag},~{fpsr},~{flags}"() } void label3() { @@ -613,7 +613,7 @@ void label3() { mov eax, label } // CHECK-LABEL: define void @label3 - // CHECK: call void asm sideeffect inteldialect "{{.*}}__MSASMLABEL_.3__label:\0A\09mov eax, {{.*}}__MSASMLABEL_.3__label", "~{eax},~{dirflag},~{fpsr},~{flags}"() + // CHECK: call void asm sideeffect inteldialect "{{.*}}__MSASMLABEL_.{:uid}__label:\0A\09mov eax, {{.*}}__MSASMLABEL_.{:uid}__label", "~{eax},~{dirflag},~{fpsr},~{flags}"() } void label4() { @@ -622,7 +622,7 @@ void label4() { mov eax, [label] } // CHECK-LABEL: define void @label4 - // CHECK: call void asm sideeffect inteldialect "{{.*}}__MSASMLABEL_.4__label:\0A\09mov eax, {{.*}}__MSASMLABEL_.4__label", "~{eax},~{dirflag},~{fpsr},~{flags}"() + // CHECK: call void asm sideeffect inteldialect "{{.*}}__MSASMLABEL_.{:uid}__label:\0A\09mov eax, {{.*}}__MSASMLABEL_.{:uid}__label", "~{eax},~{dirflag},~{fpsr},~{flags}"() } void label5() { @@ -631,7 +631,7 @@ void label5() { dollar_label$: } // CHECK-LABEL: define void @label5 - // CHECK: call void asm sideeffect inteldialect "jmp {{.*}}__MSASMLABEL_.5__dollar_label$$\0A\09{{.*}}__MSASMLABEL_.5__dollar_label$$:", "~{dirflag},~{fpsr},~{flags}"() + // CHECK: call void asm sideeffect inteldialect "jmp {{.*}}__MSASMLABEL_.{:uid}__dollar_label$$\0A\09{{.*}}__MSASMLABEL_.{:uid}__dollar_label$$:", "~{dirflag},~{fpsr},~{flags}"() } void label6(){ @@ -640,7 +640,7 @@ void label6(){ label: } // CHECK-LABEL: define void @label6 - // CHECK: call void asm sideeffect inteldialect "jmp {{.*}}__MSASMLABEL_.6__label\0A\09{{.*}}__MSASMLABEL_.6__label:", "~{dirflag},~{fpsr},~{flags}"() + // CHECK: call void asm sideeffect inteldialect "jmp {{.*}}__MSASMLABEL_.{:uid}__label\0A\09{{.*}}__MSASMLABEL_.{:uid}__label:", "~{dirflag},~{fpsr},~{flags}"() } typedef union _LARGE_INTEGER { @@ -662,4 +662,6 @@ int test_indirect_field(LARGE_INTEGER LargeInteger) { // CHECK: call i32 asm sideeffect inteldialect "mov eax, dword ptr $1", // MS ASM containing labels must not be duplicated (PR23715). -// CHECK: attributes [[ATTR1]] = { {{.*}}noduplicate{{.*}} } +// CHECK: attributes [[ATTR1]] = { +// CHECK-NOT: noduplicate +// CHECK-SAME: }{{$}} diff --git a/clang/test/CodeGen/ms-inline-asm.cpp b/clang/test/CodeGen/ms-inline-asm.cpp index 123a0e3..584122f 100644 --- a/clang/test/CodeGen/ms-inline-asm.cpp +++ b/clang/test/CodeGen/ms-inline-asm.cpp @@ -126,14 +126,14 @@ void t7_using() { void t8() { __asm some_label: // CHECK-LABEL: define void @_Z2t8v() - // CHECK: call void asm sideeffect inteldialect "L__MSASMLABEL_.1__some_label:", "~{dirflag},~{fpsr},~{flags}"() + // CHECK: call void asm sideeffect inteldialect "L__MSASMLABEL_.{:uid}__some_label:", "~{dirflag},~{fpsr},~{flags}"() struct A { static void g() { __asm jmp some_label ; This should jump forwards __asm some_label: __asm nop // CHECK-LABEL: define internal void @_ZZ2t8vEN1A1gEv() - // CHECK: call void asm sideeffect inteldialect "jmp L__MSASMLABEL_.2__some_label\0A\09L__MSASMLABEL_.2__some_label:\0A\09nop", "~{dirflag},~{fpsr},~{flags}"() + // CHECK: call void asm sideeffect inteldialect "jmp L__MSASMLABEL_.{:uid}__some_label\0A\09L__MSASMLABEL_.{:uid}__some_label:\0A\09nop", "~{dirflag},~{fpsr},~{flags}"() } }; A::g();