This is an archive of the discontinued LLVM Phabricator instance.

[MemorySanitizer] Support memcpy.inline and memset.inline
ClosedPublic

Authored by melver on Aug 10 2022, 8:29 AM.

Details

Summary

Other sanitizers (ASan, TSan, see added tests) already handle
memcpy.inline and memset.inline by not relying on InstVisitor to turn
the intrinsics into calls. Only MSan instrumentation currently does not
support them due to missing InstVisitor callbacks.

Fix it by actually making InstVisitor handle Mem*InlineInst.

While the mem*.inline intrinsics promise no calls to external functions
as an optimization, for the sanitizers we need to break this guarantee
since access into the runtime is required either way, and performance
can no longer be guaranteed. All other cases, where generating a call is
incorrect, should instead use no_sanitize.

Fixes: https://github.com/llvm/llvm-project/issues/57048

Diff Detail

Event Timeline

melver created this revision.Aug 10 2022, 8:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2022, 8:29 AM
melver requested review of this revision.Aug 10 2022, 8:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2022, 8:29 AM
dvyukov accepted this revision.Aug 10 2022, 8:52 AM
dvyukov added inline comments.
llvm/test/Instrumentation/AddressSanitizer/mem-intrinsics.ll
34

llvm is not confused by 2 tail calls in a row?

This revision is now accepted and ready to land.Aug 10 2022, 8:52 AM
vitalybuka added inline comments.Aug 10 2022, 10:35 AM
llvm/include/llvm/IR/InstVisitor.h
210–214

I believe this should be like this

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
2583

we don't need this if it's properly fowarded to MemCpyInst

vitalybuka added inline comments.Aug 10 2022, 10:38 AM
llvm/include/llvm/IR/InstVisitor.h
210–214

because visitor here always delegate to the base class

vitalybuka accepted this revision.Aug 10 2022, 10:42 AM

LGTM if you address the comments above

If it's related to https://github.com/llvm/llvm-project/issues/57048, please include it into commit message

melver updated this revision to Diff 451764.Aug 11 2022, 1:34 AM
melver marked an inline comment as done.
melver edited the summary of this revision. (Show Details)
  • Make InstVisitor delegate Mem*InlineInst to Mem*Inst.
melver marked 3 inline comments as done.Aug 11 2022, 1:35 AM
melver added inline comments.
llvm/test/Instrumentation/AddressSanitizer/mem-intrinsics.ll
34

No - the test passes, and just follows convention from above. Presumably it was done to make sure instrumentation isn't confused by tail calls? I can't say...

This revision was landed with ongoing or failed builds.Aug 11 2022, 1:45 AM
This revision was automatically updated to reflect the committed changes.