llvm-project/llvm/lib/Transforms/Instrumentation
Jann Horn a22685885d [AddressSanitizer] Instrument byval call arguments
Summary:
In the LLVM IR, "call" instructions read memory for each byval operand.
For example:

```
$ cat blah.c
struct foo { void *a, *b, *c; };
struct bar { struct foo foo; };
void func1(const struct foo);
void func2(struct bar *bar) { func1(bar->foo); }
$ [...]/bin/clang -S -flto -c blah.c -O2 ; cat blah.s
[...]
define dso_local void @func2(%struct.bar* %bar) local_unnamed_addr #0 {
entry:
  %foo = getelementptr inbounds %struct.bar, %struct.bar* %bar, i64 0, i32 0
  tail call void @func1(%struct.foo* byval(%struct.foo) align 8 %foo) #2
  ret void
}
[...]
$ [...]/bin/clang -S -c blah.c -O2 ; cat blah.s
[...]
func2:                                  # @func2
[...]
        subq    $24, %rsp
[...]
        movq    16(%rdi), %rax
        movq    %rax, 16(%rsp)
        movups  (%rdi), %xmm0
        movups  %xmm0, (%rsp)
        callq   func1
        addq    $24, %rsp
[...]
        retq
```

Let ASAN instrument these hidden memory accesses.

This is patch 4/4 of a patch series:
https://reviews.llvm.org/D77616 [PATCH 1/4] [AddressSanitizer] Refactor ClDebug{Min,Max} handling
https://reviews.llvm.org/D77617 [PATCH 2/4] [AddressSanitizer] Split out memory intrinsic handling
https://reviews.llvm.org/D77618 [PATCH 3/4] [AddressSanitizer] Refactor: Permit >1 interesting operands per instruction
https://reviews.llvm.org/D77619 [PATCH 4/4] [AddressSanitizer] Instrument byval call arguments

Reviewers: kcc, glider

Reviewed By: glider

Subscribers: hiraditya, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77619
2020-04-30 17:09:13 +02:00
..
AddressSanitizer.cpp [AddressSanitizer] Instrument byval call arguments 2020-04-30 17:09:13 +02:00
BoundsChecking.cpp [IRBuilder] Fix unnecessary IRBuilder copies; NFC 2020-02-16 17:57:18 +01:00
CFGMST.h [llvm] Migrate llvm::make_unique to std::make_unique 2019-08-15 15:54:37 +00:00
CGProfile.cpp [llvm][NFC][CallSite] Remove CallSite from a few trivial locations 2020-04-22 08:39:21 -07:00
CMakeLists.txt [cmake] Explicitly mark libraries defined in lib/ as "Component Libraries" 2019-11-21 10:48:08 -08:00
ControlHeightReduction.cpp [CHR] Clean up some code and reduce copying. NFCI. 2020-04-13 23:11:20 +02:00
DataFlowSanitizer.cpp [IR] Replace all uses of CallBase::getCalledValue() with getCalledOperand(). 2020-04-27 22:17:03 -07:00
GCOVProfiling.cpp Revert "[compiler-rt] Add a critical section when flushing gcov counters" 2020-02-26 13:27:44 +01:00
HWAddressSanitizer.cpp [AddressSanitizer] Instrument byval call arguments 2020-04-30 17:09:13 +02:00
IndirectCallPromotion.cpp [llvm][NFC] Change parameter type to more specific CallBase in IndirectCallPromotion 2020-04-29 08:42:32 -07:00
InstrOrderFile.cpp [CallSite removal] Remove unneeded includes of CallSite.h. NFC 2020-04-22 00:07:13 -07:00
InstrProfiling.cpp Reland: [Coverage] Revise format to reduce binary size 2020-02-28 18:12:04 -08:00
Instrumentation.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
LLVMBuild.txt Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MaximumSpanningTree.h Use llvm::stable_sort 2019-04-23 14:51:27 +00:00
MemorySanitizer.cpp [IR] Replace all uses of CallBase::getCalledValue() with getCalledOperand(). 2020-04-27 22:17:03 -07:00
PGOInstrumentation.cpp [CallSite removal] Remove unneeded includes of CallSite.h. NFC 2020-04-23 21:01:48 -07:00
PGOMemOPSizeOpt.cpp [Pass] Ensure we don't include PassSupport.h or PassAnalysisSupport.h directly 2020-04-26 12:58:20 +01:00
PoisonChecking.cpp [SVE] Remove calls to isScalable from Transforms 2020-04-23 13:50:07 -07:00
SanitizerCoverage.cpp [IR] Replace all uses of CallBase::getCalledValue() with getCalledOperand(). 2020-04-27 22:17:03 -07:00
ThreadSanitizer.cpp [TSAN] Add optional support for distinguishing volatiles 2020-04-22 17:27:09 +02:00
ValueProfileCollector.cpp [PGO] Refactor Value Profiling into a plugin based oracle and create a well defined API for the plugins. 2019-10-03 14:20:50 +00:00
ValueProfileCollector.h [PGO] Refactor Value Profiling into a plugin based oracle and create a well defined API for the plugins. 2019-10-03 14:20:50 +00:00
ValueProfilePlugins.inc [llvm][NFC] Refactor APIs operating on CallBase 2020-04-28 13:23:47 -07:00