This is an archive of the discontinued LLVM Phabricator instance.

Diagnose the usage of an MS inline assembly label not defined in the same assembly block
Needs ReviewPublic

Authored by ehsan on Oct 8 2014, 8:20 PM.

Details

Reviewers
rnk
Summary

This addresses PR21035. For now, we are unable to represent the
possibility of jumping between asm IR blocks in LLVM, so these kinds of
jumps don't play well with the SSA model. This patch adds a diagnostic
that detect those kinds of jumps, based on the information that the LLVM
side patch exposes from MC.

Note that this diagnostic is unable to differentiate between branches
versus other kinds of label access, so it covers them all.

Diff Detail

Event Timeline

ehsan updated this revision to Diff 14623.Oct 8 2014, 8:20 PM
ehsan retitled this revision from to Diagnose the usage of an MS inline assembly label not defined in the same assembly block.
ehsan updated this object.
ehsan edited the test plan for this revision. (Show Details)
ehsan added a reviewer: rnk.
ehsan added a subscriber: Unknown Object (MLST).
rnk edited edge metadata.Oct 14 2014, 3:35 PM

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.

lib/Parse/ParseStmtAsm.cpp
50

This can be SmallPtrSet<LabelDecl*, 4>. Sorry, we have a silly STL allergy. :)

118

Do we reject this?

void f(int x) {
  __asm {
  label:
    nop
  }
  x++;
  __asm {
    cmp x, 10
    je label
  }
}
test/Sema/ms-inline-asm.c
109

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.

In D5694#4, @rnk wrote:

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.

OK, I'll try doing that.

lib/Parse/ParseStmtAsm.cpp
50

np, I'm not new to that allergy. ;)

118

Ah, no. :( Sorry I must have caught this myself. I'll fix it.

test/Sema/ms-inline-asm.c
109

Can I do that in a separate patch? It's only tangentially related to this change.

rnk added inline comments.Oct 14 2014, 4:58 PM
test/Sema/ms-inline-asm.c
109

Yeah.

Playing with the idea of checking these LabelDecl's at the end of the function, here's another issue I just thought about. At the end of the function we will know which MSAsmStmt has defined a given LabelDecl, but how do we know which LabelDecl has *used* it? Should I record that info in LabelDecl too?