From ee6d4bd4f87934944a8aa7c5a6ffb3bed59535e6 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 26 Aug 2015 21:57:20 +0000 Subject: [ms-inline-asm] Add field access to MS inline asm identifier lookup Now we can parse code like this: struct A { int field; }; int f(A o) { __asm mov eax, o.field } Fixes PR19117. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246088 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseStmtAsm.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'lib/Parse/ParseStmtAsm.cpp') diff --git a/lib/Parse/ParseStmtAsm.cpp b/lib/Parse/ParseStmtAsm.cpp index 8cdae6a74b..d3281393f9 100644 --- a/lib/Parse/ParseStmtAsm.cpp +++ b/lib/Parse/ParseStmtAsm.cpp @@ -222,6 +222,25 @@ ExprResult Parser::ParseMSAsmIdentifier(llvm::SmallVectorImpl &LineToks, /*AllowConstructorName=*/false, /*ObjectType=*/ParsedType(), TemplateKWLoc, Id); + // Perform the lookup. + ExprResult Result = Actions.LookupInlineAsmIdentifier( + SS, TemplateKWLoc, Id, Info, IsUnevaluatedContext); + + // While the next two tokens are 'period' 'identifier', repeatedly parse it as + // a field access. We have to avoid consuming assembler directives that look + // like '.' 'else'. + while (Result.isUsable() && Tok.is(tok::period)) { + Token IdTok = PP.LookAhead(0); + if (IdTok.isNot(tok::identifier)) + break; + ConsumeToken(); // Consume the period. + IdentifierInfo *Id = Tok.getIdentifierInfo(); + ConsumeToken(); // Consume the identifier. + unsigned OffsetUnused; + Result = Actions.LookupInlineAsmVarDeclField( + Result.get(), Id->getName(), OffsetUnused, Info, Tok.getLocation()); + } + // Figure out how many tokens we are into LineToks. unsigned LineIndex = 0; if (Tok.is(EndOfStream)) { @@ -254,9 +273,7 @@ ExprResult Parser::ParseMSAsmIdentifier(llvm::SmallVectorImpl &LineToks, LineToks.pop_back(); LineToks.pop_back(); - // Perform the lookup. - return Actions.LookupInlineAsmIdentifier(SS, TemplateKWLoc, Id, Info, - IsUnevaluatedContext); + return Result; } /// Turn a sequence of our tokens back into a string that we can hand -- cgit v1.2.1