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

Chad Rosier mcrosier at apple.com
Tue Oct 2 14:49:15 PDT 2012


Author: mcrosier
Date: Tue Oct  2 16:49:14 2012
New Revision: 165058

URL: http://llvm.org/viewvc/llvm-project?rev=165058&view=rev
Log:
[ms-inline asm] Rewrite the symbol references as wildcard MCParsedAsmOperands.
A Sema lookup is used to determine the size of the variable, which is in turn
used during wildcard matching.

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=165058&r1=165057&r2=165058&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Tue Oct  2 16:49:14 2012
@@ -575,6 +575,43 @@
     // If we had an error parsing the operands, fail gracefully.
     if (HadError) { DEF_SIMPLE_MSASM(EmptyAsmStr); return Owned(NS); }
 
+    // Rewrite the symbol references as wildcard MCParsedAsmOperands.
+    for (unsigned i = 1, e = Operands.size(); i != e; ++i)
+      if (Operands[i]->isMem()) {
+        StringRef Name = getMSInlineAsmExprName(Pieces[StrIdx][i]);
+
+        // The expr may be a register.  E.g., DWORD PTR [eax]
+        if (Context.getTargetInfo().isValidGCCRegisterName(Name))
+          continue;
+
+        IdentifierInfo *II = getIdentifierInfo(Name, AsmToks,
+                                               AsmTokRanges[StrIdx].first,
+                                               AsmTokRanges[StrIdx].second);
+        // Lookup the identifier.
+        // TODO: Someone with more experience with clang should verify this the
+        // proper way of doing a symbol lookup.
+        DeclarationName DeclName(II);
+        Scope *CurScope = getCurScope();
+        LookupResult R(*this, DeclName, AsmLoc, Sema::LookupOrdinaryName);
+        if (!this->LookupName(R, CurScope, false/*AllowBuiltinCreation*/))
+          assert(0 && "Sema::LookupName failed!");
+        assert (R.isSingleResult() && "Expected a single result?!");
+        NamedDecl *Decl = R.getFoundDecl();
+        switch (Decl->getKind()) {
+        default:
+          assert(0 && "Unknown decl kind.");
+          break;
+        case Decl::Var: {
+        case Decl::ParmVar:
+          VarDecl *Var = cast<VarDecl>(Decl);
+          QualType Ty = Var->getType();
+          // Set the expected operand size.
+          Operands[i]->setMSAsmWildcard(Context.getTypeInfo(Ty).first);
+          break;
+        }
+        }
+      }
+
     // Match the MCInstr.
     unsigned Kind;
     unsigned Opcode;
@@ -619,8 +656,7 @@
       // Expr/Input or Output.
       StringRef Name = getMSInlineAsmExprName(Pieces[StrIdx][i]);
 
-      // The expr may be a register.
-      // E.g., DWORD PTR [eax]
+      // The expr may be a register.  E.g., DWORD PTR [eax]
       if (Context.getTargetInfo().isValidGCCRegisterName(Name))
         continue;
 





More information about the cfe-commits mailing list