[cfe-commits] r166213 - /cfe/trunk/lib/Sema/SemaStmtAsm.cpp

Chad Rosier mcrosier at apple.com
Thu Oct 18 12:39:37 PDT 2012


Author: mcrosier
Date: Thu Oct 18 14:39:37 2012
New Revision: 166213

URL: http://llvm.org/viewvc/llvm-project?rev=166213&view=rev
Log:
[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.

Modified:
    cfe/trunk/lib/Sema/SemaStmtAsm.cpp

Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=166213&r1=166212&r2=166213&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Thu Oct 18 14:39:37 2012
@@ -367,19 +367,10 @@
   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<void*>(OpDecl->getIdentifier());
-    return static_cast<void *>(OpExpr.take());
+    return static_cast<void *>(OpDecl);
   }
 };
 
@@ -468,14 +459,13 @@
   unsigned NumOutputs;
   unsigned NumInputs;
   std::string AsmStringIR;
-  SmallVector<void *, 4> VoidNames;
+  SmallVector<void *, 4> OpDecls;
   SmallVector<std::string, 4> Constraints;
-  SmallVector<void *, 4> VoidExprs;
   SmallVector<std::string, 4> 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 @@
 
   // 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<IdentifierInfo *>(VoidNames[i]);
+    NamedDecl *OpDecl = static_cast<NamedDecl *>(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<Expr *>(VoidExprs[i]);
+    Exprs[i] = OpExpr.take();
   }
 
   bool IsSimple = NumExprs > 0;





More information about the cfe-commits mailing list