This is an archive of the discontinued LLVM Phabricator instance.

[llvm][AsmPrinter] Restore source location to register clobber warning
ClosedPublic

Authored by DavidSpickett on May 11 2021, 8:30 AM.

Details

Summary

Since 5de2d189e6ad466a1f0616195e8c524a4eb3cbc0 this particular warning
hasn't had the location of the source file containing the inline
assembly.

Fix this by reporting via LLVMContext. Which means that we no longer
have the "instantiated into assembly here" lines but they were going to
point to the start of the inline asm string anyway.

This message is already tested via IR in llvm. However we won't have
the required location info there so I've added a C file test in clang
to cover it.
(though strictly, this is testing llvm code)

Diff Detail

Event Timeline

DavidSpickett created this revision.May 11 2021, 8:30 AM
DavidSpickett requested review of this revision.May 11 2021, 8:30 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 11 2021, 8:30 AM

This works as expected, let me know if this is the intended use relative to the changes you made.

The existing test in llvm llvm/test/CodeGen/AArch64/inline-asm-clobber.ll never reported the location in the .ll file so I can't test it there. (which might be its own issue) I looked for any similar tests but didn't find anything, testing from clang with a C file seems like the only way.

clang/test/Misc/inline-asm-clobber-warning.c
26

I think this ^ is wrong because we don't/can't account for the asm printer tabbing in the instruction.

I still wanted to check that there are ^ just because it's one aspect of the location information.

ychen added inline comments.May 11 2021, 11:18 AM
clang/test/Misc/inline-asm-clobber-warning.c
26

This probably is due to Loc is not right.

llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
545

For this diagnose, it is better to use LLVMContext since the location inside inlineasm does not matter. There is an example above.

Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
  • Report via LLVMContext
DavidSpickett edited the summary of this revision. (Show Details)May 12 2021, 7:58 AM

Looks good except for one suggestion and the patch need rebasing on an upstream commit.

llvm/include/llvm/IR/LLVMContext.h
300 ↗(On Diff #344821)

It would be best to avoid adding these two methods for single-use since LLVMContext.h is included everywhere. We could add them once it turns out to be needed in other places. Could we use LLVMContext::diagnose instead?

  • Use diagnose instead of adding methods to LLVMContext
  • clang-format the test file
DavidSpickett marked an inline comment as done.May 13 2021, 2:16 AM
DavidSpickett marked an inline comment as done.
ychen accepted this revision.May 13 2021, 10:04 AM

LGTM. Thanks.

This revision is now accepted and ready to land.May 13 2021, 10:04 AM
This revision was landed with ongoing or failed builds.May 14 2021, 1:23 AM
This revision was automatically updated to reflect the committed changes.