]> granicus.if.org Git - clang/commitdiff
ms-inline-asm: Correctly mark MS inline ASM labels as used
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Wed, 8 Oct 2014 17:28:34 +0000 (17:28 +0000)
committerEhsan Akhgari <ehsan.akhgari@gmail.com>
Wed, 8 Oct 2014 17:28:34 +0000 (17:28 +0000)
Summary: This fixes PR21155.

Test Plan: The patch includes a test.

Reviewers: rnk

Subscribers: cfe-commits

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

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

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

index 7f79a05b46d16b9de8a84a38041ecaed75ed5a67..a2e436ae7eeee3b53471e4a93d2ba7905f962d2a 100644 (file)
@@ -561,7 +561,10 @@ LabelDecl *Sema::GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
   LabelDecl* Label = LookupOrCreateLabel(PP.getIdentifierInfo(ExternalLabelName),
                                          Location);
 
-  if (!Label->isMSAsmLabel()) {
+  if (Label->isMSAsmLabel()) {
+    // If we have previously created this label implicitly, mark it as used.
+    Label->markUsed(Context);
+  } else {
     // Otherwise, insert it, but only resolve it if we have seen the label itself.
     std::string InternalName;
     llvm::raw_string_ostream OS(InternalName);
index 6eac769505430a0216c9294f32d508c719da52a2..4c6948f4d45d17aa7b783e49cbfa0eb0cd5a66ca 100644 (file)
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fasm-blocks -Wno-microsoft -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fasm-blocks -Wno-microsoft -Wunused-label -verify -fsyntax-only
 
 void t1(void) { 
  __asm __asm // expected-error {{__asm used with no assembly instructions}}
@@ -146,5 +146,11 @@ void t10() {
 
 void t11() {
 foo:
-  __asm mov eax, foo // expected-error {{use of undeclared label 'foo'}}
+  __asm mov eax, foo // expected-error {{use of undeclared label 'foo'}} expected-warning {{unused label 'foo'}}
+}
+
+void t12() {
+  __asm foo:
+  __asm bar: // expected-warning {{unused label 'bar'}}
+  __asm jmp foo
 }