[PATCH] Diagnose the usage of an MS inline assembly label not defined in the same assembly block

Reid Kleckner rnk at google.com
Tue Oct 14 15:35:27 PDT 2014


I think recording the MSAsmStmt in the statement field of the LabelDecl is probably the way to go here. Then we can wait until the end of the function to check what label went where.

================
Comment at: lib/Parse/ParseStmtAsm.cpp:50
@@ +49,3 @@
+  /// The LabelDecls encountered when parsing the asm block.
+  std::set<LabelDecl*> LabelDecls;
+
----------------
This can be `SmallPtrSet<LabelDecl*, 4>`. Sorry, we have a silly STL allergy. :)

================
Comment at: lib/Parse/ParseStmtAsm.cpp:118
@@ +117,3 @@
+    for (const auto *Label : LabelDecls) {
+      if (!Label->isResolvedMSAsmLabel()) {
+        TheParser.getActions().DiagnoseCrossBlockLabelUse(Label);
----------------
Do we reject this?
  void f(int x) {
    __asm {
    label:
      nop
    }
    x++;
    __asm {
      cmp x, 10
      je label
    }
  }

================
Comment at: test/Sema/ms-inline-asm.c:109
@@ -108,3 +108,3 @@
 __declspec(naked) int t5(int x) { // expected-note {{attribute is here}}
-  asm { movl eax, x } // expected-error {{parameter references not allowed in naked functions}} expected-error {{use of undeclared label 'x'}}
+  asm { movl eax, x } // expected-error {{parameter references not allowed in naked functions}} expected-error {{use of undeclared label 'x'}} expected-error {{cannot use inline assembly label 'x' defined outside of an inline assembly block}}
   asm { retl }
----------------
Hm, this diagnostic is pretty bad. :( We should try returning the found declaration even when we generate the first diagnostic to suppress these follow on diagnostics.

http://reviews.llvm.org/D5694






More information about the cfe-commits mailing list