[llvm-branch-commits] [llvm-branch] r142169 - in /llvm/branches/release_30: include/llvm/Support/SourceMgr.h lib/MC/MCParser/AsmParser.cpp

Bill Wendling isanbard at gmail.com
Sun Oct 16 20:47:20 PDT 2011


Author: void
Date: Sun Oct 16 22:47:20 2011
New Revision: 142169

URL: http://llvm.org/viewvc/llvm-project?rev=142169&view=rev
Log:
Apply r142132:

PR11143: Save the old diagnostic handler and call it when munging diagnostics for #line directives.

This reenables proper inline asm diagnostics in clang


Modified:
    llvm/branches/release_30/include/llvm/Support/SourceMgr.h
    llvm/branches/release_30/lib/MC/MCParser/AsmParser.cpp

Modified: llvm/branches/release_30/include/llvm/Support/SourceMgr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_30/include/llvm/Support/SourceMgr.h?rev=142169&r1=142168&r2=142169&view=diff
==============================================================================
--- llvm/branches/release_30/include/llvm/Support/SourceMgr.h (original)
+++ llvm/branches/release_30/include/llvm/Support/SourceMgr.h Sun Oct 16 22:47:20 2011
@@ -78,6 +78,9 @@
     DiagContext = Ctx;
   }
 
+  DiagHandlerTy getDiagHandler() const { return DiagHandler; }
+  void *getDiagContext() const { return DiagContext; }
+
   const SrcBuffer &getBufferInfo(unsigned i) const {
     assert(i < Buffers.size() && "Invalid Buffer ID!");
     return Buffers[i];

Modified: llvm/branches/release_30/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_30/lib/MC/MCParser/AsmParser.cpp?rev=142169&r1=142168&r2=142169&view=diff
==============================================================================
--- llvm/branches/release_30/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/branches/release_30/lib/MC/MCParser/AsmParser.cpp Sun Oct 16 22:47:20 2011
@@ -87,6 +87,8 @@
   MCStreamer &Out;
   const MCAsmInfo &MAI;
   SourceMgr &SrcMgr;
+  SourceMgr::DiagHandlerTy SavedDiagHandler;
+  void *SavedDiagContext;
   MCAsmParserExtension *GenericParser;
   MCAsmParserExtension *PlatformParser;
 
@@ -351,6 +353,10 @@
   : Lexer(_MAI), Ctx(_Ctx), Out(_Out), MAI(_MAI), SrcMgr(_SM),
     GenericParser(new GenericAsmParser), PlatformParser(0),
     CurBuffer(0), MacrosEnabled(true), CppHashLineNumber(0) {
+  // Save the old handler.
+  SavedDiagHandler = SrcMgr.getDiagHandler();
+  SavedDiagContext = SrcMgr.getDiagContext();
+  // Set our own handler which calls the saved handler.
   SrcMgr.setDiagHandler(DiagHandler, this);
   Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
 
@@ -1273,7 +1279,7 @@
   // Like SourceMgr::PrintMessage() we need to print the include stack if any
   // before printing the message.
   int DiagCurBuffer = DiagSrcMgr.FindBufferContainingLoc(DiagLoc);
-  if (DiagCurBuffer > 0) {
+  if (!Parser->SavedDiagHandler && DiagCurBuffer > 0) {
      SMLoc ParentIncludeLoc = DiagSrcMgr.getParentIncludeLoc(DiagCurBuffer);
      DiagSrcMgr.PrintIncludeStack(ParentIncludeLoc, OS);
   }
@@ -1284,7 +1290,10 @@
   if (!Parser->CppHashLineNumber ||
       &DiagSrcMgr != &Parser->SrcMgr ||
       DiagBuf != CppHashBuf) {
-    Diag.Print(0, OS);
+    if (Parser->SavedDiagHandler)
+      Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
+    else
+      Diag.Print(0, OS);
     return;
   }
 
@@ -1308,7 +1317,10 @@
                        Diag.getLineContents(),
                        Diag.getShowLine());
 
-  NewDiag.Print(0, OS);
+  if (Parser->SavedDiagHandler)
+    Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
+  else
+    NewDiag.Print(0, OS);
 }
 
 bool AsmParser::expandMacro(SmallString<256> &Buf, StringRef Body,





More information about the llvm-branch-commits mailing list