Commit Graph

1451 Commits

Author SHA1 Message Date
Evgenii Stepanov
e72c949c15 [msan] Overflow intrinsics. (#88210) 2024-04-10 09:12:25 -07:00
Evgenii Stepanov
e8a3b72272 [msan] Precommit tests.
Precommit tests for overflowing and saturating arithmetic intrinsics.
2024-04-09 16:32:48 -07:00
Vitaly Buka
0646344062 [HWASAN][UBSAN] Reverse random logic (#88070)
It feels more intuitive to make higher P to keep more checks.
2024-04-08 17:23:47 -07:00
Evgenii Stepanov
3b74f8c1de Revert "[msan] Precommit tests."
This reverts commit 79343fa8c3.
2024-04-08 17:02:21 -07:00
Evgenii Stepanov
5bc87dac75 Revert "Overflow and saturating intrinsics (#88068)"
This reverts commit 118a5d8236.
2024-04-08 17:02:21 -07:00
Evgenii Stepanov
118a5d8236 Overflow and saturating intrinsics (#88068) 2024-04-08 16:33:45 -07:00
Evgenii Stepanov
79343fa8c3 [msan] Precommit tests.
Precommit tests for overflowing and saturating arithmetic intrinsics.
2024-04-08 16:21:59 -07:00
Vitaly Buka
18380c522a [UBSAN][HWASAN] Remove redundant flags (#87709)
Presense of `cutoff-hot` or `random-skip-rate`
should be enough to trigger optimization.
2024-04-04 14:32:30 -07:00
Vitaly Buka
03f54725c3 [HWASAN][UBSAN] Don't use default profile-summary-cutoff-hot (#87691)
Default cutoff is not usefull here. Decision to
enable or not sanitizer causes more significant
performance impact, than a typical optimizations
which rely on `profile-summary-cutoff-hot`.
2024-04-04 14:25:53 -07:00
Vitaly Buka
c0c11e788a [NFC][HWASAN] Cleanup opt opt test (#87687)
Main change is replacing DEFAULT with HOT99.
I'll remove DEFAULT related functionality in the followup patches.
2024-04-04 12:27:18 -07:00
Vitaly Buka
70e8cf0c31 [HWASAN] Don't instrument loads from global if globals are not tagged (#86774) 2024-03-27 13:43:18 -07:00
Vitaly Buka
3522de9e41 [TEST][HWASAN] Fix test after #86771 2024-03-27 13:19:00 -07:00
Vitaly Buka
4d4626d9d5 [TEST][HWASAN] Fix test after #86771 2024-03-27 13:10:42 -07:00
Vitaly Buka
96b3969a4d [NFC][HWASAN] Precommit globals-access test
HWASAN does not behave as expected yet.

Reviewers: fmayer, thurstond

Reviewed By: fmayer, thurstond

Pull Request: https://github.com/llvm/llvm-project/pull/86771
2024-03-27 10:30:58 -07:00
Alex Voicu
ab7dba233a [CodeGen][LLVM] Make the va_list related intrinsics generic. (#85460)
Currently, the builtins used for implementing `va_list` handling
unconditionally take their arguments as unqualified `ptr`s i.e. pointers
to AS 0. This does not work for targets where the default AS is not 0 or
AS 0 is not a viable AS (for example, a target might choose 0 to
represent the constant address space). This patch changes the builtins'
signature to take generic `anyptr` args, which corrects this issue. It
is noisy due to the number of tests affected. A test for an upstream
target which does not use 0 as its default AS (SPIRV for HIP device
compilations) is added as well.
2024-03-27 11:41:34 +00:00
Vitaly Buka
16993c793a [NFC][HWASAN] Regenerate test 2024-03-26 22:48:13 -07:00
Nikita Popov
ff2fb2a1d7 [TSan] Fix atomicrmw xchg with pointer and floats (#85228)
atomicrmw xchg also accepts pointer and floating-point values. To handle
those, insert necessary casts to and from integer. This is what we do
for cmpxchg as well.

Fixes https://github.com/llvm/llvm-project/issues/85226.
2024-03-15 09:02:10 +01:00
Hans Wennborg
f2d02ce04f [Coroutines] Remove some stale FIXMEs (NFC)
The calls are already musttail.
2024-03-14 17:55:20 +01:00
sylvain-audi
ea12c1fa15 [Asan] Add "funclet" OpBundle to generated runtime calls if required by EH personality (#82533)
Previously, runtime calls introduced by ASan instrumentation into EH
pads were missing the funclet token expected by WinEHPrepare.
WinEHPrepare would then identify the containing BB as invalid and
discard it, causing invalid code generation that most likely crashes.

Also fixed localescape test, switching its EH personality to match code
without funclets.

This PR is based on the Phabricator patch
https://reviews.llvm.org/D143108

Fixes https://github.com/llvm/llvm-project/issues/64990
2024-03-08 12:29:15 -05:00
Fangrui Song
30f098ef9d [Instrumentation] Convert tests to opaque pointers (NFC)
Link: https://discourse.llvm.org/t/enabling-opaque-pointers-by-default/61322
2024-03-07 16:39:57 -08:00
Kirill Stoimenov
4258b0e13f [HWASAN] Follow up for #83503 implement selective instrumentation (#83942)
1. Change tests to use IR instead of -stats to avoid depending on Debug
mode
2. Add SkipInstrumentationRandomRate 
3. Remove HWASAN from stat strings
2024-03-06 16:16:59 -08:00
Kirill Stoimenov
56754478e7 Reapply "[HWASAN] Implement selective instrumentation based on profiling information (#83503)"
Added REQUIRES: asserts, which should fix the build problem.

This reverts commit f6f79d46e5.
2024-03-04 18:16:38 +00:00
sylvain-audi
dd426fa5f9 [Asan] Pre-commit test for asan support of funclet token (#82631)
This is in preparation for PR
https://github.com/llvm/llvm-project/pull/82533.

Here we Introduce a test for asan instrumentation where invalid code is
output (see bug https://github.com/llvm/llvm-project/issues/64990)
The `CHECK` lines are generated using `update_test_checks.py` script.
The actual fix PR will udpate this test to highlight the changes in the
generated code.
2024-03-01 13:34:57 -05:00
Kirill Stoimenov
f6f79d46e5 Revert "[HWASAN] Implement selective instrumentation based on profiling information (#83503)"
Broke a build bot: https://lab.llvm.org/buildbot/#/builders/124/builds/9846

This reverts commit e7c3cd2456.
2024-03-01 17:17:37 +00:00
Kirill Stoimenov
e7c3cd2456 [HWASAN] Implement selective instrumentation based on profiling information (#83503) 2024-02-29 17:34:32 -08:00
Wu Yingcong
3250330997 [asan] Disable instrumentation for available_externally global with COFF (#81109)
For COFF, available_externally global will be instrumented because of
the lack of filtering, and will trigger the Verifier pass assertion and
crash the compilation. This patch will filter out the
available_externally global for COFF.

For non-COFF, `!G->hasExactDefinition()` in line 1954 will filter out
the available_externally globals.

There is a related bug reported in
https://bugs.llvm.org/show_bug.cgi?id=47950 /
https://github.com/llvm/llvm-project/issues/47294. I tried the
reproducer posted on the page and this will fix the problem.

Reproducer:
```
#include <locale>

void grouping_impl() {
  std::use_facet<std::numpunct<char>>(std::locale());
}

// clang -fsanitize=address -D_DLL -std=c++14 -c format.cc
```
2024-02-27 12:52:04 -08:00
Mingming Liu
16e74fd489 Reland "[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling." (#82711)
New change on top of [reviewed
patch](https://github.com/llvm/llvm-project/pull/81691) are [in commits
after this
one](d0757f46b3).
Previous commits are restored from the remote branch with timestamps.

1. Fix build breakage for non-ELF platforms, by defining the missing
functions {`__llvm_profile_begin_vtables`, `__llvm_profile_end_vtables`,
`__llvm_profile_begin_vtabnames `, `__llvm_profile_end_vtabnames`}
everywhere.
* Tested on mac laptop (for darwins) and Windows. Specifically,
functions in `InstrProfilingPlatformWindows.c` returns `NULL` to make it
more explicit that type prof isn't supported; see comments for the
reason.
* For the rest (AIX, other), mostly follow existing examples (like this
[one](f95b2f1acf))
   
2. Rename `__llvm_prf_vtabnames` -> `__llvm_prf_vns` for shorter section
name, and make returned pointers
[const](a825d2a4ec (diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR120-R121))

**Original Description**

* Raw profile format
- Header: records the byte size of compressed vtable names, and the
number of profiled vtable entries (call it `VTableProfData`). Header
also records padded bytes of each section.
- Payload: adds a section for compressed vtable names, and a section to
store `VTableProfData`. Both sections are padded so the size is a
multiple of 8.
* Indexed profile format
  - Header: records the byte offset of compressed vtable names.
- Payload: adds a section to store compressed vtable names. This section
is used by `llvm-profdata` to show the list of vtables profiled for an
instrumented site.
  
[The originally reviewed
patch](https://github.com/llvm/llvm-project/pull/66825) will have
profile reader/write change and llvm-profdata change.
- To ensure this PR has all the necessary profile format change along
with profile version bump, created a copy of the originally reviewed
patch in https://github.com/llvm/llvm-project/pull/80761. The copy
doesn't have profile format change, but it has the set of tests which
covers type profile generation, profile read and profile merge. Tests
pass there.
  
rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600

---------

Co-authored-by: modiking <modiking213@gmail.com>
2024-02-27 11:07:40 -08:00
NAKAMURA Takumi
cc53707a5c LLVMInstrumentation: Simplify mcdc.tvbitmap.update with GEP. 2024-02-25 11:21:46 +09:00
NAKAMURA Takumi
7b9504fc01 test: Refine InstrProfiling/mcdc.ll 2024-02-25 11:21:46 +09:00
Mingming Liu
0e8d1877cd Revert type profiling change as compiler-rt test break on Windows. (#82583)
Examples
https://lab.llvm.org/buildbot/#/builders/127/builds/62532/steps/8/logs/stdio
2024-02-21 21:41:33 -08:00
Mingming Liu
db7e9e6841 [TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling. (#81691)
* Raw profile format
- Header: records the byte size of compressed vtable names, and the
number of profiled vtable entries (call it `VTableProfData`). Header
also records padded bytes of each section.
- Payload: adds a section for compressed vtable names, and a section to
store `VTableProfData`. Both sections are padded so the size is a
multiple of 8.
* Indexed profile format
  - Header: records the byte offset of compressed vtable names.
- Payload: adds a section to store compressed vtable names. This section
is used by `llvm-profdata` to show the list of vtables profiled for an
instrumented site.
  
[The originally reviewed
patch](https://github.com/llvm/llvm-project/pull/66825) will have
profile reader/write change and llvm-profdata change.
- To ensure this PR has all the necessary profile format change along
with profile version bump, created a copy of the originally reviewed
patch in https://github.com/llvm/llvm-project/pull/80761. The copy
doesn't have profile format change, but it has the set of tests which
covers type profile generation, profile read and profile merge. Tests
pass there.
  
rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600

---------

Co-authored-by: modiking <modiking213@gmail.com>
2024-02-21 20:59:42 -08:00
Arthur Eubanks
6841395953 [PGOForceFunctionAttrs] Don't mark alwaysinline function optnone (#81930)
optnone requires noinline, which is incompatible with alwaysinline.
2024-02-16 11:33:45 -08:00
Orlando Cazalet-Hyams
d860ea96b1 [HWASAN] Update dbg.assign intrinsics in HWAsan pass (#79864)
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to
update the second expression.

Fixes #76545. This is #78606 rebased and with the addition of DPValue handling.
Note the addition of --try-experimental-debuginfo-iterators in the tests and
some shuffling of code in MemoryTaggingSupport.cpp.
2024-02-13 09:11:09 +00:00
Arthur Eubanks
93cdd1b5cf [PGO] Add ability to mark cold functions as optsize/minsize/optnone (#69030)
The performance of cold functions shouldn't matter too much, so if we
care about binary sizes, add an option to mark cold functions as
optsize/minsize for binary size, or optnone for compile times [1]. Clang
patch will be in a future patch.

This is intended to replace `shouldOptimizeForSize(Function&, ...)`.
We've seen multiple cases where calls to this expensive function, if not
careful, can blow up compile times. I will clean up users of that
function in a followup patch.

Initial version: https://reviews.llvm.org/D149800

[1]
https://discourse.llvm.org/t/rfc-new-feature-proposal-de-optimizing-cold-functions-using-pgo-info/56388
2024-02-12 14:52:08 -08:00
Stephen Tozer
afa413a132 [RemoveDIs][DebugInfo] Correctly visit DPValues in StackInfoBuilder::visit (#81247)
In `StackInfoBuilder::visit(Instruction &Inst)`, operations are
performed on memory-related instructions, including debug intrinsics
that refer to "interesting" allocas. There is a block that also visits
DPValues attached to the instruction, but this block is near the end of
the function; this has two problems:
1. The DPValues attached to an instruction precede that instruction, so
they should always be processed before the instruction itself.
2. More importantly, some of the paths for visiting other instructions
contain early returns, which will result in the DPValues not being
visited at all.

This patch simply moves the DPValue-visiting block to the top of the
function, which should resolve both of these problems.
2024-02-12 13:50:37 +00:00
Usama Hameed
ec73441f2b [Clang][Test] Delete hardcoded version string from test (#80384)
Remove hardcoded string from test

rdar://120498671
2024-02-02 14:00:28 -08:00
Fangrui Song
9b91c54d9b [msan] Unpoison indirect outputs for userspace using memset for large operands (#79924)
Modify #77393 to clear shadow memory using `llvm.memset.*` when the size
is large, similar to `shouldUseBZeroPlusStoresToInitialize` in clang for
`-ftrivial-auto-var-init=`. The intrinsic, if lowered to libcall, will
use the msan interceptor.

The instruction selector lowers a `StoreInst` to multiple stores, not
utilizing `memset`. When the size is large (e.g.
`store { [100 x i32] } zeroinitializer, ptr %12, align 1`), the
generated code will be long (and `CodeGenPrepare::optimizeInst` will
even crash for a huge size).

```
// Test stack size
template <class T>
void DoNotOptimize(const T& var) { // deprecated by https://github.com/google/benchmark/pull/1493
  asm volatile("" : "+m"(const_cast<T&>(var)));
}

int main() {
  using LargeArray = std::array<int, 1000000>;
  auto large_stack = []() { DoNotOptimize(LargeArray()); };
  /////// CodeGenPrepare::optimizeInst triggers an assertion failure when creating an integer type with a bit width>2**23
  large_stack();
}
```
2024-01-30 13:45:47 -08:00
ampandey-1995
67f0a6917c [ASan][AMDGPU] Fix Assertion Failure. (#79795)
Assertion failure `(i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Calling a function with a bad signature!"'. The
'llvm.memcpy' intercepted by ASan instrumentation pass is implemented by
it's own __asan_memcpy implementation. The second argument of
llvm.memcpy accepts ptr to addrspace(4), __asan_memcpy also has to
follow ptr to addrspace(4) convention.

---------

Co-authored-by: Amit Pandey <amit.pandey@amd.com>
2024-01-30 12:31:40 +05:30
Fangrui Song
1ae0448ed3 [msan] Enable msan-handle-asm-conservative for userspace by default (#79251)
msan-handle-asm-conservative is enabled by KMSAN by default.
Enable the userspace by default as well after #77393.
2024-01-24 15:31:43 -08:00
Jeremy Morse
fe0e632b00 [DebugInfo][RemoveDIs] Support DPValues in HWAsan (#78731)
This patch extends HWASAN to support maintenance of debug-info that
isn't stored as intrinsics, but is instead in a DPValue object. This is
straight-forwards: we collect any such objects in StackInfoBuilder, and
apply the same operations to them as we would to dbg.value and similar
intrinsics.

I've also replaced some calls to getNextNode with debug-info skipping
next calls, and use iterators for instruction insertion rather than
instruction pointers. This avoids any difference in output between
intrinsic / non-intrinsic debug-info, but also means that any debug-info
comes before code inserted by HWAsan, rather than afterwards. See the
test modifications, where the variable assignment (presented as a
dbg.value) jumps up over all the code inserted by HWAsan. Seeing how the
code inserted by HWAsan is always (AFAIUI) given the source-location of
the instruction being instrumented, I don't believe this will have any
effect on which lines variable assignments become visible on; it may
extend the number of instructions covered by the assignments though.
2024-01-24 10:38:35 +00:00
gulfemsavrun
7fe951ad8a Revert "Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass … (#79186)
…#78606"

This reverts commit 13c6f1ea2e because it
causes an assertion in DebugInfoMetadata.cpp:1968 in Clang Linux
builders for Fuchsia.

https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8758111613576762817/+/u/clang/build/stdout
2024-01-23 10:12:10 -08:00
OCHyams
13c6f1ea2e Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass #78606
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update
the second expression.

Fixes #76545
2024-01-23 11:24:21 +00:00
gulfemsavrun
b00aa1c77b Revert "Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass … (#79053)
…#78606"

This reverts commit 76160718df because it
caused an assertion failure in emitDbgValue function in Codegen in Clang
Linux toolchain builders for Fuchsia.
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8758181086086431185/+/u/clang/build/stdout
2024-01-22 12:44:46 -08:00
Mingming Liu
5ce286849a [CGProfile] Use callee's PGO name when caller->callee is an indirect call. (#78610)
- With PGO, indirect call edges are constructed using value profiles, and the profile address is mapped to a function's PGO name. The PGO name is computed using a functions linkage before LTO internalization or global promotion.
- With ThinLTO, local functions [could be
promoted](2663d2cb9c/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp (L288)) to have external linkage; and with
[full](2663d2cb9c/llvm/lib/LTO/LTO.cpp (L1328))
or
[thin](2663d2cb9c/llvm/lib/LTO/LTO.cpp (L448))
LTO, global functions could be internalized. Edge construction should use a function's PGO name before its linkage is updated.
2024-01-22 10:36:03 -08:00
OCHyams
76160718df Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass #78606
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update
the second expression.

Fixes #76545
2024-01-22 17:07:44 +00:00
Orlando Cazalet-Hyams
5266c1285b Revert "[hwasan] Update dbg.assign intrinsics in HWAsan pass" (#78971)
Reverts llvm/llvm-project#78606

https://lab.llvm.org/buildbot/#/builders/77/builds/33963
2024-01-22 13:30:50 +00:00
Orlando Cazalet-Hyams
a590f2315f [hwasan] Update dbg.assign intrinsics in HWAsan pass (#78606)
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update
the second expression.

Fixes #76545
2024-01-22 11:38:00 +00:00
Fangrui Song
c71a5bf940 [msan] Unpoison indirect outputs for userspace when -msan-handle-asm-conservative is specified (#77393)
KMSAN defaults to `msan-handle-asm-conservative`, which inserts
`__msan_instrument_asm_store` calls to unpoison indirect outputs in
inline assembly (e.g. `=m` constraints in source).

```c
unsigned f() {
  unsigned v;
  // __msan_instrument_asm_store unpoisons v before invoking the asm.
  asm("movl $1,%0" : "=m"(v));
  return v;
}
```

Extend the mechanism to userspace, but require explicit
`-mllvm -msan-handle-asm-conservative` for experiments for now.

As

https://docs.kernel.org/dev-tools/kmsan.html#inline-assembly-instrumentation
says, this approach may mask certain errors (an indirect output may not
actually be initialized), but it also helps to avoid a lot of false
positives.

Link: https://github.com/google/sanitizers/issues/192
2024-01-19 16:18:28 -08:00
Fangrui Song
7740565f56 [asan] Enable StackSafetyAnalysis by default
StackSafetyAnalysis determines whether stack-allocated variables are
guaranteed to be safe from memory access bugs and enables the removal of
certain unneeded instrumentations.
(hwasan enables StackSafetyAnalysis in https://reviews.llvm.org/D108381)

In a release build of clang, text sections are 9% smaller.

Test updates:

* asan-stack-safety.ll: test the -asan-use-stack-safety=1 default
* lifetime-uar-uas.ll: switch to an indexed store to prevent
  StackSafetyAnalysis from optimizing out instrumentation for %c
* alloca_vla_interact.cpp: add a load to prevent StackSafetyAnalysis
  from optimizing out `__asan_alloca_poison` for the VLA `array`
* scariness_score_test.cpp: add -asan-use-stack-safety=0 to make a load
  of a `__asan_poison_memory_region`-poisoned local variable fail as
  intended.
* other .ll tests: add -asan-use-stack-safety=0

Reviewed By: kstoimenov

Pull Request: https://github.com/llvm/llvm-project/pull/77210
2024-01-11 14:03:28 -08:00
Zequan Wu
e7f7948751 Revert "[asan] Enable StackSafetyAnalysis by default"
This reverts commit 51fbab1345.
This causes the compiler to crash. Will file a issue to track the status.
2024-01-11 15:24:44 -05:00