diff --git a/llvm/docs/LangRef.html b/llvm/docs/LangRef.html index f15f139aeb38..1c31e4533697 100644 --- a/llvm/docs/LangRef.html +++ b/llvm/docs/LangRef.html @@ -2625,8 +2625,8 @@ call void asm alignstack "eieio", ""()

The call instructions that wrap inline asm nodes may have a "!srcloc" MDNode - attached to it that contains a constant integer. If present, the code - generator will use the integer as the location cookie value when report + attached to it that contains a list of constant integers. If present, the + code generator will use the integer as the location cookie value when report errors through the LLVMContext error reporting mechanisms. This allows a front-end to correlate backend errors that occur with inline asm back to the source code that produced it. For example:

@@ -2638,7 +2638,8 @@ call void asm sideeffect "something bad", ""(), !srcloc !42

It is up to the front-end to make sense of the magic numbers it places in the - IR.

+ IR. If the MDNode contains multiple constants, the code generator will use + the one that corresponds to the line of the asm that the error occurs on.

diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp index 9e5d679aa3c2..ff9ecf2dbd07 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -49,11 +49,19 @@ static void SrcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) { SrcMgrDiagInfo *DiagInfo = static_cast(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(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(LocInfo->getOperand(ErrorLine))) LocCookie = CI->getZExtValue(); + } DiagInfo->DiagHandler(Diag, DiagInfo->DiagContext, LocCookie); }