diff options
| author | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2014-09-22 02:21:54 +0000 |
|---|---|---|
| committer | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2014-09-22 02:21:54 +0000 |
| commit | 31097581aad843ffb85befeeedb2e23a4d8cc287 (patch) | |
| tree | bb169eaa18a5fcf9baef086f133e1c6d2bafa80a /clang/lib/Parse/ParseStmtAsm.cpp | |
| parent | db0e7061c6b45357f83b121d6b97f67104288993 (diff) | |
| download | bcm5719-llvm-31097581aad843ffb85befeeedb2e23a4d8cc287.tar.gz bcm5719-llvm-31097581aad843ffb85befeeedb2e23a4d8cc287.zip | |
ms-inline-asm: Scope inline asm labels to functions
Summary:
This fixes PR20023. In order to implement this scoping rule, we piggy
back on the existing LabelDecl machinery, by creating LabelDecl's that
will carry the "internal" name of the inline assembly label, which we
will rewrite the asm label to.
Reviewers: rnk
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D4589
llvm-svn: 218230
Diffstat (limited to 'clang/lib/Parse/ParseStmtAsm.cpp')
| -rw-r--r-- | clang/lib/Parse/ParseStmtAsm.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/clang/lib/Parse/ParseStmtAsm.cpp b/clang/lib/Parse/ParseStmtAsm.cpp index be3d79e2231..35e2e6294f8 100644 --- a/clang/lib/Parse/ParseStmtAsm.cpp +++ b/clang/lib/Parse/ParseStmtAsm.cpp @@ -93,6 +93,15 @@ public: return Info.OpDecl; } + StringRef LookupInlineAsmLabel(StringRef Identifier, llvm::SourceMgr &LSM, + llvm::SMLoc Location, + bool Create) override { + SourceLocation Loc = translateLocation(LSM, Location); + LabelDecl *Label = + TheParser.getActions().GetOrCreateMSAsmLabel(Identifier, Loc, Create); + return Label->getMSAsmLabel(); + } + bool LookupInlineAsmField(StringRef Base, StringRef Member, unsigned &Offset) override { return TheParser.getActions().LookupInlineAsmField(Base, Member, Offset, @@ -133,14 +142,13 @@ private: } } - void handleDiagnostic(const llvm::SMDiagnostic &D) { + SourceLocation translateLocation(const llvm::SourceMgr &LSM, llvm::SMLoc SMLoc) { // Compute an offset into the inline asm buffer. // FIXME: This isn't right if .macro is involved (but hopefully, no // real-world code does that). - const llvm::SourceMgr &LSM = *D.getSourceMgr(); const llvm::MemoryBuffer *LBuf = - LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc())); - unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart(); + LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(SMLoc)); + unsigned Offset = SMLoc.getPointer() - LBuf->getBufferStart(); // Figure out which token that offset points into. const unsigned *TokOffsetPtr = @@ -157,6 +165,12 @@ private: Loc = Tok.getLocation(); Loc = Loc.getLocWithOffset(Offset - TokOffset); } + return Loc; + } + + void handleDiagnostic(const llvm::SMDiagnostic &D) { + const llvm::SourceMgr &LSM = *D.getSourceMgr(); + SourceLocation Loc = translateLocation(LSM, D.getLoc()); TheParser.Diag(Loc, diag::err_inline_ms_asm_parsing) << D.getMessage(); } }; |

