Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rtsan][test] Prevent test check from being optimized out in LTO builds #122524

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,23 @@ TEST(TestRtsan, LaunchingAThreadDiesWhenRealtime) {

namespace {
void InvokeStdFunction(std::function<void()> &&function) { function(); }

template <typename T> void HideMemoryFromCompiler(T *memory) {
// Pass the pointer to an empty assembly block as an input, and inform
// the compiler that memory is read to and possibly modified. This should not
// be architecture specific, since the asm block is empty.
__asm__ __volatile__("" ::"r"(memory) : "memory");
}
} // namespace

TEST(TestRtsan, CopyingALambdaWithLargeCaptureDiesWhenRealtime) {
std::array<float, 16> lots_of_data;
auto LargeLambda = [lots_of_data]() mutable {
// Stop everything getting optimised out
lots_of_data[3] = 0.25f;
// In LTO builds, this lambda can be optimized away, since the compiler can
// see through the memory accesses after inlining across TUs. Ensure it can
// no longer reason about the memory access, so that won't happen.
HideMemoryFromCompiler(&lots_of_data[3]);
EXPECT_EQ(16u, lots_of_data.size());
EXPECT_EQ(0.25f, lots_of_data[3]);
};
Expand Down
Loading