[compiler-rt] d49aaaf - [memprof] Fix UB.
Florian Mayer via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 11 13:01:24 PST 2022
Author: Florian Mayer
Date: 2022-02-11T13:01:14-08:00
New Revision: d49aaaf44f508c8731672dcacaa62dd947acd414
URL: https://github.com/llvm/llvm-project/commit/d49aaaf44f508c8731672dcacaa62dd947acd414
DIFF: https://github.com/llvm/llvm-project/commit/d49aaaf44f508c8731672dcacaa62dd947acd414.diff
LOG: [memprof] Fix UB.
An infinite loop without any effects is illegal C++ and can be optimized
away by the compiler.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D119575
Added:
Modified:
compiler-rt/lib/asan/asan_rtl.cpp
compiler-rt/lib/memprof/memprof_rtl.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp
index 338aa5046408..18df9f7e5494 100644
--- a/compiler-rt/lib/asan/asan_rtl.cpp
+++ b/compiler-rt/lib/asan/asan_rtl.cpp
@@ -45,7 +45,9 @@ static void AsanDie() {
static atomic_uint32_t num_calls;
if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) {
// Don't die twice - run a busy loop.
- while (1) { }
+ while (1) {
+ internal_sched_yield();
+ }
}
if (common_flags()->print_module_map >= 1)
DumpProcessMap();
diff --git a/compiler-rt/lib/memprof/memprof_rtl.cpp b/compiler-rt/lib/memprof/memprof_rtl.cpp
index d5ea4102f388..21424fb4f072 100644
--- a/compiler-rt/lib/memprof/memprof_rtl.cpp
+++ b/compiler-rt/lib/memprof/memprof_rtl.cpp
@@ -39,6 +39,7 @@ static void MemprofDie() {
if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) {
// Don't die twice - run a busy loop.
while (1) {
+ internal_sched_yield();
}
}
if (common_flags()->print_module_map >= 1)
More information about the llvm-commits
mailing list