[cfe-commits] r100608 - /cfe/trunk/lib/CodeGen/CGStmt.cpp

Chris Lattner sabre at nondot.org
Tue Apr 6 22:46:54 PDT 2010


Author: lattner
Date: Wed Apr  7 00:46:54 2010
New Revision: 100608

URL: http://llvm.org/viewvc/llvm-project?rev=100608&view=rev
Log:
a ridiculous amount of propagation through the backend later, 
have the code generate slap a srcloc metadata on inline asm nodes.
This allows us to diagnose invalid inline asms with such nice 
diagnostics as:

<inline asm>:1:2: error: unrecognized instruction
        abc incl    %eax
        ^
asm.c:2:12: note: generated from here
  __asm__ ("abc incl    %0" : "+r" (X));
           ^
2 diagnostics generated.


Modified:
    cfe/trunk/lib/CodeGen/CGStmt.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=100608&r1=100607&r2=100608&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Wed Apr  7 00:46:54 2010
@@ -1044,9 +1044,10 @@
         // Use ptrtoint as appropriate so that we can do our extension.
         if (isa<llvm::PointerType>(Arg->getType()))
           Arg = Builder.CreatePtrToInt(Arg,
-                                      llvm::IntegerType::get(VMContext, LLVMPointerWidth));
+                           llvm::IntegerType::get(VMContext, LLVMPointerWidth));
         unsigned OutputSize = (unsigned)getContext().getTypeSize(OutputTy);
-        Arg = Builder.CreateZExt(Arg, llvm::IntegerType::get(VMContext, OutputSize));
+        Arg = Builder.CreateZExt(Arg,
+                                 llvm::IntegerType::get(VMContext, OutputSize));
       }
     }
 
@@ -1102,6 +1103,12 @@
   llvm::CallInst *Result = Builder.CreateCall(IA, Args.begin(), Args.end());
   Result->addAttribute(~0, llvm::Attribute::NoUnwind);
 
+  // Slap the source location of the inline asm into a !srcloc metadata on the
+  // call.
+  unsigned LocID = S.getAsmString()->getLocStart().getRawEncoding();
+  llvm::Value *LocIDC =
+    llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LocID);
+  Result->setMetadata("srcloc", llvm::MDNode::get(VMContext, &LocIDC, 1));
 
   // Extract all of the register value results from the asm.
   std::vector<llvm::Value*> RegResults;





More information about the cfe-commits mailing list