From: Chad Rosier Date: Thu, 18 Oct 2012 19:39:37 +0000 (+0000) Subject: [ms-inline asm] Have the LookupInlineAsmIdentifier() callback function return a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d052ebf6ca1a9ae3123a8ee22bc37e58ddb61018;p=clang [ms-inline asm] Have the LookupInlineAsmIdentifier() callback function return a *NamedDecl. In turn, build the expressions after we're finished parsing the asm. This avoids a crasher if the lookup fails. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166213 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp index d36afd6b30..875821c14d 100644 --- a/lib/Sema/SemaStmtAsm.cpp +++ b/lib/Sema/SemaStmtAsm.cpp @@ -367,19 +367,10 @@ public: MCAsmParserSemaCallbackImpl(class Sema *Ref) { SemaRef = Ref; } ~MCAsmParserSemaCallbackImpl() {} - void *LookupInlineAsmIdentifier(StringRef Name, void *SrcLoc, - void **IdentifierInfoPtr) { + void *LookupInlineAsmIdentifier(StringRef Name, void *SrcLoc) { SourceLocation Loc = SourceLocation::getFromPtrEncoding(SrcLoc); NamedDecl *OpDecl = SemaRef->LookupInlineAsmIdentifier(Name, Loc); - DeclarationNameInfo NameInfo(OpDecl->getDeclName(), Loc); - ExprResult OpExpr = SemaRef->BuildDeclarationNameExpr(CXXScopeSpec(), - NameInfo, - OpDecl); - if (OpExpr.isInvalid()) - return 0; - - *IdentifierInfoPtr = static_cast(OpDecl->getIdentifier()); - return static_cast(OpExpr.take()); + return static_cast(OpDecl); } }; @@ -468,14 +459,13 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, unsigned NumOutputs; unsigned NumInputs; std::string AsmStringIR; - SmallVector VoidNames; + SmallVector OpDecls; SmallVector Constraints; - SmallVector VoidExprs; SmallVector Clobbers; MCAsmParserSemaCallbackImpl MCAPSI(this); if (Parser->ParseMSInlineAsm(AsmLoc.getPtrEncoding(), AsmStringIR, - NumOutputs, NumInputs, VoidNames, Constraints, - VoidExprs, Clobbers, MII, IP, MCAPSI)) + NumOutputs, NumInputs, OpDecls, Constraints, + Clobbers, MII, IP, MCAPSI)) return StmtError(); // Build the vector of clobber StringRefs. @@ -486,15 +476,23 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, // Recast the void pointers and build the vector of constraint StringRefs. unsigned NumExprs = NumOutputs + NumInputs; - assert (VoidNames.size() == NumExprs && "Unexpected number of names!"); - assert (VoidExprs.size() == NumExprs && "Unexpected number of exprs!"); Names.resize(NumExprs); ConstraintRefs.resize(NumExprs); Exprs.resize(NumExprs); for (unsigned i = 0, e = NumExprs; i != e; ++i) { - Names[i] = static_cast(VoidNames[i]); + NamedDecl *OpDecl = static_cast(OpDecls[i]); + if (!OpDecl) + return StmtError(); + + DeclarationNameInfo NameInfo(OpDecl->getDeclName(), AsmLoc); + ExprResult OpExpr = BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, + OpDecl); + if (OpExpr.isInvalid()) + return StmtError(); + + Names[i] = OpDecl->getIdentifier(); ConstraintRefs[i] = StringRef(Constraints[i]); - Exprs[i] = static_cast(VoidExprs[i]); + Exprs[i] = OpExpr.take(); } bool IsSimple = NumExprs > 0;