aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-10-16 10:48:29 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-10-16 10:48:29 +0000
commit04a0426cc283fe6a03f16612e0f172c3c97a1102 (patch)
treead3137e505d12f3d62cc9895a0505fafebad649c
parentc32a8c9073e5aafe9b4c41dddd416d378216758f (diff)
downloadexternal_llvm-04a0426cc283fe6a03f16612e0f172c3c97a1102.zip
external_llvm-04a0426cc283fe6a03f16612e0f172c3c97a1102.tar.gz
external_llvm-04a0426cc283fe6a03f16612e0f172c3c97a1102.tar.bz2
PR11143: Save the old diagnostic handler and call it when munging diagnostics for #line directives.
This reenables proper inline asm diagnostics in clang git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142132 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/SourceMgr.h3
-rw-r--r--lib/MC/MCParser/AsmParser.cpp18
2 files changed, 18 insertions, 3 deletions
diff --git a/include/llvm/Support/SourceMgr.h b/include/llvm/Support/SourceMgr.h
index 4c0d992..58b8fab 100644
--- a/include/llvm/Support/SourceMgr.h
+++ b/include/llvm/Support/SourceMgr.h
@@ -82,6 +82,9 @@ public:
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];
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp
index a05f767..50fa4d4 100644
--- a/lib/MC/MCParser/AsmParser.cpp
+++ b/lib/MC/MCParser/AsmParser.cpp
@@ -87,6 +87,8 @@ private:
MCStreamer &Out;
const MCAsmInfo &MAI;
SourceMgr &SrcMgr;
+ SourceMgr::DiagHandlerTy SavedDiagHandler;
+ void *SavedDiagContext;
MCAsmParserExtension *GenericParser;
MCAsmParserExtension *PlatformParser;
@@ -353,6 +355,10 @@ AsmParser::AsmParser(SourceMgr &_SM, MCContext &_Ctx,
: 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));
@@ -1276,7 +1282,7 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) {
// 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);
}
@@ -1287,7 +1293,10 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) {
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;
}
@@ -1307,7 +1316,10 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) {
Diag.getKind(), Diag.getMessage(),
Diag.getLineContents(), Diag.getRanges());
- 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,