]> granicus.if.org Git - clang/commitdiff
[ms inline asm] Add support for label names with '$' chars
authorMarina Yatsina <marina.yatsina@intel.com>
Tue, 29 Dec 2015 08:49:34 +0000 (08:49 +0000)
committerMarina Yatsina <marina.yatsina@intel.com>
Tue, 29 Dec 2015 08:49:34 +0000 (08:49 +0000)
In MS inline asm syntax a label with '$' char produces an error, while in AT&T it does not.
In AT&T inline asm syntax Clang escapes the '$' char and replaces it with "$$". Adopted same approach for MS syntax.

Differential Revision: http://reviews.llvm.org/D15795

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256545 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmtAsm.cpp
test/CodeGen/ms-inline-asm.c

index 2917c5a3603478129847ece8c3c9c1771f0219c4..0d6e0f8e41b07ed4fbc7a20233640725ed366d2a 100644 (file)
@@ -750,7 +750,15 @@ 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++ << "__" << ExternalLabelName;
+    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 << '$';
+      }
+    }
     Label->setMSAsmLabel(OS.str());
   }
   if (AlwaysCreate) {
index 619d3bceb8f61fbc4acf34e160a50968930c0580..2f5de676c72fe8ed44e2f81b6e577b0e08ea5761 100644 (file)
@@ -616,6 +616,15 @@ void label4() {
   // CHECK: call void asm sideeffect inteldialect "{{.*}}__MSASMLABEL_.4__label:\0A\09mov eax, {{.*}}__MSASMLABEL_.4__label", "~{eax},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void label5() {
+  __asm {
+    jmp dollar_label$
+    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}"()
+}
+
 typedef union _LARGE_INTEGER {
   struct {
     unsigned int LowPart;