Skip to content

Commit cc9ecaa

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.6-beta.1 [skip ci]
1 parent ff24e9a commit cc9ecaa

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,24 @@ TEST(TestRtsan, LaunchingAThreadDiesWhenRealtime) {
145145

146146
namespace {
147147
void InvokeStdFunction(std::function<void()> &&function) { function(); }
148+
149+
template <typename T>
150+
void HideMemoryFromCompiler(T* memory) {
151+
// Pass the pointer to an empty assembly block as an input, and inform
152+
// the compiler that memory is read to and possibly modified. This should not
153+
// be architecture specific, since the asm block is empty.
154+
__asm__ __volatile__("" ::"r"(memory) : "memory");
155+
}
148156
} // namespace
149157

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

0 commit comments

Comments
 (0)