diff --git a/clang/test/Misc/inline-asm-clobber-warning.c b/clang/test/Misc/inline-asm-clobber-warning.c new file mode 100644 --- /dev/null +++ b/clang/test/Misc/inline-asm-clobber-warning.c @@ -0,0 +1,26 @@ +/// This test checks that the warning includes the location in the C source +/// file that contains the inline asm. Instead of saying for both. +/// Although this warning is emitted in llvm it cannot be tested from IR as +/// it does not have that location information at that stage. + +// RUN: %clang -target arm-arm-none-eabi -march=armv7-m -c %s -o /dev/null \ +// RUN: 2>&1 | FileCheck %s + +// REQUIRES: arm-registered-target + +void bar(void) { + __asm__ __volatile__ ( "nop" : : : "sp"); +} + +// CHECK: inline-asm-clobber-warning.c:12:28: warning: inline asm clobber list contains reserved registers: SP [-Winline-asm] +// CHECK-NEXT: __asm__ __volatile__ ( "nop" : : : "sp"); +// CHECK-NEXT: ^ +// CHECK-NEXT: :1:1: note: instantiated into assembly here +// CHECK-NEXT: nop +// CHECK-NEXT: ^ +// CHECK-NEXT: inline-asm-clobber-warning.c:12:28: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour. +// CHECK-NEXT: __asm__ __volatile__ ( "nop" : : : "sp"); +// CHECK-NEXT: ^ +// CHECK-NEXT: :1:1: note: instantiated into assembly here +// CHECK-NEXT: nop +// CHECK-NEXT: ^ diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -805,6 +805,7 @@ void diagnose(const SMDiagnostic &SMD); void reportError(SMLoc L, const Twine &Msg); void reportWarning(SMLoc L, const Twine &Msg); + void reportNote(SMLoc L, const Twine &Msg); // Unrecoverable error has occurred. Display the best diagnostic we can // and bail via exit(1). For now, most MC backend errors are unrecoverable. // FIXME: We should really do something about that. diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -542,8 +542,8 @@ "Reserved registers on the clobber list may not be " "preserved across the asm statement, and clobbering them may " "lead to undefined behaviour."; - SrcMgr.PrintMessage(Loc, SourceMgr::DK_Warning, Msg); - SrcMgr.PrintMessage(Loc, SourceMgr::DK_Note, Note); + MMI->getContext().reportWarning(Loc, Msg); + MMI->getContext().reportNote(Loc, Note); } emitInlineAsm(OS.str(), getSubtargetInfo(), TM.Options.MCOptions, LocMD, diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -964,6 +964,12 @@ } } +void MCContext::reportNote(SMLoc Loc, const Twine &Msg) { + reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) { + D = SMP->GetMessage(Loc, SourceMgr::DK_Note, Msg); + }); +} + void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) { reportError(Loc, Msg);