[compiler-rt] a097c4c - [compiler-rt] Fix issue with compiler-rt tests mixing <atomic> and <stdatomic.h>
Louis Dionne via llvm-commits
llvm-commits at lists.llvm.org
Fri May 6 14:37:06 PDT 2022
Author: Louis Dionne
Date: 2022-05-06T17:36:12-04:00
New Revision: a097c4ce95335f5c38d20f4e260f80c5e002be01
URL: https://github.com/llvm/llvm-project/commit/a097c4ce95335f5c38d20f4e260f80c5e002be01
DIFF: https://github.com/llvm/llvm-project/commit/a097c4ce95335f5c38d20f4e260f80c5e002be01.diff
LOG: [compiler-rt] Fix issue with compiler-rt tests mixing <atomic> and <stdatomic.h>
Since D97044, libc++ implements <stdatomic.h>, which is not compatible
with the <atomic> header in C++03 mode. To fix the tests, avoid using
<stdatomic.h> at all, since it is not strictly required.
rdar://92867529
Differential Revision: https://reviews.llvm.org/D125118
Added:
Modified:
compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm
compiler-rt/test/tsan/libdispatch/groups-destructor.cpp
Removed:
################################################################################
diff --git a/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm b/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm
index e5cd7edc6bb7..5ce016ae7c48 100644
--- a/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm
+++ b/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm
@@ -3,33 +3,35 @@
#import <Foundation/Foundation.h>
-#import <assert.h>
+#import <atomic>
+#import <cassert>
+#import <cstdio>
#import <memory>
-#import <stdatomic.h>
-_Atomic(long) shared_call_counter = 0;
-_Atomic(long) weak_call_counter = 0;
-_Atomic(long) destructor_counter = 0;
-_Atomic(long) weak_destroyed_counter = 0;
+std::atomic<long> shared_call_counter(0);
+std::atomic<long> weak_call_counter(0);
+std::atomic<long> destructor_counter(0);
+std::atomic<long> weak_destroyed_counter(0);
struct MyStruct {
- _Atomic(long) self_counter = 0;
+ std::atomic<long> self_counter;
+ MyStruct() : self_counter(0) { }
virtual void shared_call() {
- atomic_fetch_add_explicit(&self_counter, 1, memory_order_relaxed);
- atomic_fetch_add_explicit(&shared_call_counter, 1, memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&self_counter, 1, std::memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&shared_call_counter, 1, std::memory_order_relaxed);
}
virtual void weak_call() {
- atomic_fetch_add_explicit(&weak_call_counter, 1, memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&weak_call_counter, 1, std::memory_order_relaxed);
}
virtual ~MyStruct() {
long n = self_counter;
assert(n == 1000);
- atomic_fetch_add_explicit(&destructor_counter, 1, memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&destructor_counter, 1, std::memory_order_relaxed);
}
};
int main(int argc, const char *argv[]) {
- fprintf(stderr, "Hello world.\n");
+ std::fprintf(stderr, "Hello world.\n");
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
@@ -51,7 +53,7 @@ int main(int argc, const char *argv[]) {
if (weak_copy) {
weak_copy->weak_call();
} else {
- atomic_fetch_add_explicit(&weak_destroyed_counter, 1, memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&weak_destroyed_counter, 1, std::memory_order_relaxed);
break;
}
}
@@ -60,12 +62,12 @@ int main(int argc, const char *argv[]) {
dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
- fprintf(stderr, "shared_call_counter = %ld\n", shared_call_counter);
- fprintf(stderr, "weak_call_counter = %ld\n", weak_call_counter);
- fprintf(stderr, "destructor_counter = %ld\n", destructor_counter);
- fprintf(stderr, "weak_destroyed_counter = %ld\n", weak_destroyed_counter);
+ std::fprintf(stderr, "shared_call_counter = %ld\n", shared_call_counter.load());
+ std::fprintf(stderr, "weak_call_counter = %ld\n", weak_call_counter.load());
+ std::fprintf(stderr, "destructor_counter = %ld\n", destructor_counter.load());
+ std::fprintf(stderr, "weak_destroyed_counter = %ld\n", weak_destroyed_counter.load());
- fprintf(stderr, "Done.\n");
+ std::fprintf(stderr, "Done.\n");
}
// CHECK: Hello world.
diff --git a/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp b/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp
index 72338ce6c5ce..2ea1f2d3bb5f 100644
--- a/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp
+++ b/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp
@@ -3,21 +3,21 @@
#include <dispatch/dispatch.h>
-#include <memory>
-#include <stdatomic.h>
+#include <atomic>
#include <cstdio>
+#include <memory>
-_Atomic(long) destructor_counter = 0;
+std::atomic<long> destructor_counter(0);
struct MyStruct {
virtual ~MyStruct() {
usleep(10000);
- atomic_fetch_add_explicit(&destructor_counter, 1, memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&destructor_counter, 1, std::memory_order_relaxed);
}
};
int main(int argc, const char *argv[]) {
- fprintf(stderr, "Hello world.\n");
+ std::fprintf(stderr, "Hello world.\n");
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t g = dispatch_group_create();
@@ -33,10 +33,10 @@ int main(int argc, const char *argv[]) {
dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
if (destructor_counter != 100) {
- abort();
+ std::abort();
}
- fprintf(stderr, "Done.\n");
+ std::fprintf(stderr, "Done.\n");
}
// CHECK: Hello world.
More information about the llvm-commits
mailing list