[PATCH] ms-inline-asm: Scope inline asm labels to functions

Reid Kleckner rnk at google.com
Thu Jul 24 11:52:12 PDT 2014


================
Comment at: lib/Parse/ParseStmtAsm.cpp:96
@@ -95,1 +95,3 @@
 
+  void LookupInlineAsmLabel(StringRef &Identifier, llvm::SourceMgr &LSM,
+                            llvm::SMLoc Location, bool Create) {
----------------
You can return a StringRef directly.

================
Comment at: lib/Sema/SemaDecl.cpp:1492
@@ -1491,1 +1491,3 @@
 
+  HandleMSAsmLabelsOnScopePop();
+
----------------
I believe ActOnPopScope happens on any closing curly brace, so this won't do the "right" thing:
  void f() {
    bool failed;
    __asm retry:
    {
      failed = g();
    } // The label is cleared here.
    if (failed)
      __asm jmp retry
  }

Thinking more carefully, I don't think having the label map right on Sema works at all in the general case of nested functions.  Consider this C++ example with inner classes:
  void f() {
    __asm some_label:
    struct A {
      static void g() {
        __asm jmp some_label ; This should jump forwards
        __asm some_label:
        __asm nop
      }
    };
  }

You can build similar test cases from C++11 lambdas and Obj-C blocks, and now OpenMP captured statements.

We need to associate this label map with the function we're currently processing.  Now that I'm considering the actual implementation difficulties, I'm going back to your "proposal #3" on PR20023, where we model these labels as regular label statements.  That way, we reuse all the right name lookup machinery.  We won't be able to 'goto' a label from an inline asm statement or 'jmp' to a non-asm label, so if you go this way, please diagnose both cases.  You can probably add a bit to LabelDecl to track whether the label was from MS inline asm or regular source code.

Apologies for the runaround, but I think it's probably better to rewrite along these lines.  What do you think?

http://reviews.llvm.org/D4589






More information about the cfe-commits mailing list