This is an archive of the discontinued LLVM Phabricator instance.

sanmd: improve precision of UAR analysis
ClosedPublic

Authored by dvyukov on Dec 11 2022, 11:43 PM.

Details

Summary

Only mark functions that have address-taken locals
as requiring UAR checking.

On a large internal app this reduces number of marked functions
from 78441 to 66618. Mostly small, trivial getter/setter-type
functions are unmarked, but also some amount of larger
number-crunching-type functions are unmarked as well.

Diff Detail

Event Timeline

dvyukov created this revision.Dec 11 2022, 11:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2022, 11:43 PM
dvyukov requested review of this revision.Dec 11 2022, 11:43 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 11 2022, 11:43 PM
Herald added subscribers: llvm-commits, Restricted Project. · View Herald Transcript
dvyukov added inline comments.Dec 11 2022, 11:55 PM
llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
274

Btw, isSafeAndProfitableToSinkLoad is broken. All allocas now sink to lifetime intrinsics. So it will conclude all allocas are address-taken. This immediately popped up in our end-to-end C++ tests, but wasn't detected by the InstCombine bitcode tests.

melver added inline comments.Dec 12 2022, 1:56 AM
compiler-rt/test/metadata/uar.cpp
94

Add test for explicit __builtin_alloca ?

llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
274

All this is already in a big anonymous namespace, so static not needed.

274

Could file bug (https://github.com/llvm/llvm-project/issues) and point out that it needs the isLifetimeStartOrEnd() check, but we don't quite know if it's intended?

280–293

LoadInst, StoreInst, GetElementPtrInst and BitCastInst all are derived from Instruction, so these checks can be moved in the 'if (... dyn_cast<Instruction>' branch.

dvyukov marked an inline comment as done.Dec 12 2022, 2:17 AM
dvyukov added inline comments.
llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
280–293

Can users be a non-instruction?
I assumed that I need a cast to Instruction just to get access to its methods.

melver added inline comments.Dec 12 2022, 2:21 AM
llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
280–293

Yes, all I'm suggesting is a small optimization, because the additional casts to *Inst will fail if the cast to Instruction above failed.

dvyukov updated this revision to Diff 482043.Dec 12 2022, 2:36 AM

addressed the comments

dvyukov marked 3 inline comments as done.Dec 12 2022, 2:36 AM

PTAL

melver accepted this revision.Dec 12 2022, 2:38 AM
This revision is now accepted and ready to land.Dec 12 2022, 2:38 AM
This revision was landed with ongoing or failed builds.Dec 12 2022, 2:42 AM
This revision was automatically updated to reflect the committed changes.