summaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-11-17 08:20:42 +0000
committerChris Lattner <sabre@nondot.org>2010-11-17 08:20:42 +0000
commitce1b9ad539e67c6d05cc6b47ca5f6e62a6d91eff (patch)
treedebf961a7171bd33964c44e61f506dca00f678b5 /lib/CodeGen
parent4afa12890f679034e9741a687a6ce33f2846f129 (diff)
downloadllvm-ce1b9ad539e67c6d05cc6b47ca5f6e62a6d91eff.tar.gz
llvm-ce1b9ad539e67c6d05cc6b47ca5f6e62a6d91eff.tar.bz2
llvm-ce1b9ad539e67c6d05cc6b47ca5f6e62a6d91eff.tar.xz
With the newly simplified SourceMgr interfaces and the generalized
SrcMgrDiagHandler, we can improve clang diagnostics for inline asm: instead of reporting them on a source line of the original line, we can report it on the correct line wherever the string literal came from. For something like this: void foo() { asm("push %rax\n" ".code32\n"); } we used to get this: (note that the line in t.c isn't helpful) t.c:4:7: error: warning: ignoring directive for now asm("push %rax\n" ^ <inline asm>:2:1: note: instantiated into assembly here .code32 ^ now we get: t.c:5:8: error: warning: ignoring directive for now ".code32\n" ^ <inline asm>:2:1: note: instantiated into assembly here .code32 ^ Note that we're pointing to line 5 properly now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119488 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index 9e5d679aa3..ff9ecf2dbd 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -49,11 +49,19 @@ static void SrcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) {
SrcMgrDiagInfo *DiagInfo = static_cast<SrcMgrDiagInfo *>(diagInfo);
assert(DiagInfo && "Diagnostic context not passed down?");
+ // If the inline asm had metadata associated with it, pull out a location
+ // cookie corresponding to which line the error occurred on.
unsigned LocCookie = 0;
- if (const MDNode *LocInfo = DiagInfo->LocInfo)
- if (LocInfo->getNumOperands() > 0)
- if (const ConstantInt *CI = dyn_cast<ConstantInt>(LocInfo->getOperand(0)))
+ if (const MDNode *LocInfo = DiagInfo->LocInfo) {
+ unsigned ErrorLine = Diag.getLineNo()-1;
+ if (ErrorLine >= LocInfo->getNumOperands())
+ ErrorLine = 0;
+
+ if (LocInfo->getNumOperands() != 0)
+ if (const ConstantInt *CI =
+ dyn_cast<ConstantInt>(LocInfo->getOperand(ErrorLine)))
LocCookie = CI->getZExtValue();
+ }
DiagInfo->DiagHandler(Diag, DiagInfo->DiagContext, LocCookie);
}