[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
This commit is contained in:
Louis Dionne 2022-05-06 14:46:08 -04:00
parent 0102527352
commit a097c4ce95
2 changed files with 27 additions and 25 deletions

View File

@ -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.

View File

@ -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.