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

[tsan] Replace ALIGNED with alignas #98959

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions compiler-rt/lib/asan/asan_globals_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace __asan {

#pragma section(".ASAN$GA", read, write)
#pragma section(".ASAN$GZ", read, write)
extern "C" __declspec(allocate(".ASAN$GA"))
ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_start = {};
extern "C" __declspec(allocate(".ASAN$GZ"))
ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_end = {};
extern "C" alignas(sizeof(__asan_global))
__declspec(allocate(".ASAN$GA")) __asan_global __asan_globals_start = {};
extern "C" alignas(sizeof(__asan_global))
__declspec(allocate(".ASAN$GZ")) __asan_global __asan_globals_end = {};
#pragma comment(linker, "/merge:.ASAN=.data")

static void call_on_globals(void (*hook)(__asan_global *, uptr)) {
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/asan/asan_malloc_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ struct MallocDebugL {
void* (*valloc)(uptr size);
};

ALIGNED(32) const MallocDebugK asan_malloc_dispatch_k = {
alignas(32) const MallocDebugK asan_malloc_dispatch_k = {
WRAP(malloc), WRAP(free), WRAP(calloc),
WRAP(realloc), WRAP(memalign), WRAP(malloc_usable_size)};

ALIGNED(32) const MallocDebugL asan_malloc_dispatch_l = {
alignas(32) const MallocDebugL asan_malloc_dispatch_l = {
WRAP(calloc), WRAP(free), WRAP(mallinfo),
WRAP(malloc), WRAP(malloc_usable_size), WRAP(memalign),
WRAP(posix_memalign), WRAP(pvalloc), WRAP(realloc),
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/asan/asan_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace __asan {
// -------------------- User-specified callbacks ----------------- {{{1
static void (*error_report_callback)(const char*);
using ErrorMessageBuffer = InternalMmapVectorNoCtor<char, true>;
static ALIGNED(
alignof(ErrorMessageBuffer)) char error_message_buffer_placeholder
alignas(
alignof(ErrorMessageBuffer)) static char error_message_buffer_placeholder
[sizeof(ErrorMessageBuffer)];
static ErrorMessageBuffer *error_message_buffer = nullptr;
static Mutex error_message_buf_mutex;
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/asan/asan_suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace __asan {

ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
alignas(64) static char suppression_placeholder[sizeof(SuppressionContext)];
static SuppressionContext *suppression_ctx = nullptr;
static const char kInterceptorName[] = "interceptor_name";
static const char kInterceptorViaFunction[] = "interceptor_via_fun";
Expand Down
8 changes: 4 additions & 4 deletions compiler-rt/lib/asan/asan_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ static void InitThreads() {
// thread before all TSD destructors will be called for it.

// MIPS requires aligned address
static ALIGNED(alignof(
ThreadRegistry)) char thread_registry_placeholder[sizeof(ThreadRegistry)];
static ALIGNED(alignof(
ThreadArgRetval)) char thread_data_placeholder[sizeof(ThreadArgRetval)];
alignas(alignof(ThreadRegistry)) static char
thread_registry_placeholder[sizeof(ThreadRegistry)];
alignas(alignof(ThreadArgRetval)) static char
thread_data_placeholder[sizeof(ThreadArgRetval)];

asan_thread_registry =
new (thread_registry_placeholder) ThreadRegistry(GetAsanThreadContext);
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/dfsan/dfsan_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace __dfsan {

struct DFsanThreadLocalMallocStorage {
ALIGNED(8) uptr allocator_cache[96 * (512 * 8 + 16)]; // Opaque.
alignas(8) uptr allocator_cache[96 * (512 * 8 + 16)]; // Opaque.
void CommitBack();

private:
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/hwasan/hwasan_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum {


// Initialized in HwasanAllocatorInit, an never changed.
static ALIGNED(16) u8 tail_magic[kShadowAlignment - 1];
alignas(16) static u8 tail_magic[kShadowAlignment - 1];
static uptr max_malloc_size;

bool HwasanChunkView::IsAllocated() const {
Expand Down
8 changes: 4 additions & 4 deletions compiler-rt/lib/hwasan/hwasan_thread_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ ThreadArgRetval &hwasanThreadArgRetval() { return *thread_data; }
void InitThreadList(uptr storage, uptr size) {
CHECK_EQ(hwasan_thread_list, nullptr);

static ALIGNED(alignof(
HwasanThreadList)) char thread_list_placeholder[sizeof(HwasanThreadList)];
alignas(alignof(HwasanThreadList)) static char
thread_list_placeholder[sizeof(HwasanThreadList)];
hwasan_thread_list =
new (thread_list_placeholder) HwasanThreadList(storage, size);

CHECK_EQ(thread_data, nullptr);

static ALIGNED(alignof(
ThreadArgRetval)) char thread_data_placeholder[sizeof(ThreadArgRetval)];
alignas(alignof(ThreadArgRetval)) static char
thread_data_placeholder[sizeof(ThreadArgRetval)];
thread_data = new (thread_data_placeholder) ThreadArgRetval();
}

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/lsan/lsan_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class LeakSuppressionContext {
void PrintMatchedSuppressions();
};

ALIGNED(64) static char suppression_placeholder[sizeof(LeakSuppressionContext)];
alignas(64) static char suppression_placeholder[sizeof(LeakSuppressionContext)];
static LeakSuppressionContext *suppression_ctx = nullptr;
static const char kSuppressionLeak[] = "leak";
static const char *kSuppressionTypes[] = {kSuppressionLeak};
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/lsan/lsan_common_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace __lsan {

static const char kLinkerName[] = "ld";

static char linker_placeholder[sizeof(LoadedModule)] ALIGNED(64);
alignas(64) static char linker_placeholder[sizeof(LoadedModule)];
static LoadedModule *linker = nullptr;

static bool IsLinker(const LoadedModule& module) {
Expand Down
6 changes: 3 additions & 3 deletions compiler-rt/lib/lsan/lsan_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ static ThreadContextBase *CreateThreadContext(u32 tid) {
}

void InitializeThreads() {
static ALIGNED(alignof(
ThreadRegistry)) char thread_registry_placeholder[sizeof(ThreadRegistry)];
alignas(alignof(ThreadRegistry)) static char
thread_registry_placeholder[sizeof(ThreadRegistry)];
thread_registry =
new (thread_registry_placeholder) ThreadRegistry(CreateThreadContext);

static ALIGNED(alignof(ThreadArgRetval)) char
alignas(alignof(ThreadArgRetval)) static char
thread_arg_retval_placeholder[sizeof(ThreadArgRetval)];
thread_arg_retval = new (thread_arg_retval_placeholder) ThreadArgRetval();
}
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/memprof/memprof_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void MemprofThreadContext::OnFinished() {
thread = nullptr;
}

static ALIGNED(16) char thread_registry_placeholder[sizeof(ThreadRegistry)];
alignas(16) static char thread_registry_placeholder[sizeof(ThreadRegistry)];
static ThreadRegistry *memprof_thread_registry;

static Mutex mu_for_thread_context;
Expand Down
9 changes: 4 additions & 5 deletions compiler-rt/lib/msan/msan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ THREADLOCAL u64 __msan_retval_tls[kMsanRetvalTlsSize / sizeof(u64)];
SANITIZER_INTERFACE_ATTRIBUTE
THREADLOCAL u32 __msan_retval_origin_tls;

SANITIZER_INTERFACE_ATTRIBUTE
ALIGNED(16) THREADLOCAL u64 __msan_va_arg_tls[kMsanParamTlsSize / sizeof(u64)];
alignas(16) SANITIZER_INTERFACE_ATTRIBUTE THREADLOCAL u64
__msan_va_arg_tls[kMsanParamTlsSize / sizeof(u64)];

SANITIZER_INTERFACE_ATTRIBUTE
ALIGNED(16)
THREADLOCAL u32 __msan_va_arg_origin_tls[kMsanParamTlsSize / sizeof(u32)];
alignas(16) SANITIZER_INTERFACE_ATTRIBUTE THREADLOCAL u32
__msan_va_arg_origin_tls[kMsanParamTlsSize / sizeof(u32)];

SANITIZER_INTERFACE_ATTRIBUTE
THREADLOCAL u64 __msan_va_arg_overflow_size_tls;
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/msan/msan_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace __msan {

struct MsanThreadLocalMallocStorage {
// Allocator cache contains atomic_uint64_t which must be 8-byte aligned.
ALIGNED(8) uptr allocator_cache[96 * (512 * 8 + 16)]; // Opaque.
alignas(8) uptr allocator_cache[96 * (512 * 8 + 16)]; // Opaque.
void Init();
void CommitBack();

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/msan/msan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ struct InterceptorContext {
}
};

static ALIGNED(64) char interceptor_placeholder[sizeof(InterceptorContext)];
alignas(64) static char interceptor_placeholder[sizeof(InterceptorContext)];
InterceptorContext *interceptor_ctx() {
return reinterpret_cast<InterceptorContext*>(&interceptor_placeholder[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace __sanitizer {
const char *PrimaryAllocatorName = "SizeClassAllocator";
const char *SecondaryAllocatorName = "LargeMmapAllocator";

static ALIGNED(64) char internal_alloc_placeholder[sizeof(InternalAllocator)];
alignas(64) static char internal_alloc_placeholder[sizeof(InternalAllocator)];
static atomic_uint8_t internal_allocator_initialized;
static StaticSpinMutex internal_alloc_init_mu;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class SizeClassAllocator32 {
static const uptr kRegionSize = 1 << kRegionSizeLog;
static const uptr kNumPossibleRegions = kSpaceSize / kRegionSize;

struct ALIGNED(SANITIZER_CACHE_LINE_SIZE) SizeClassInfo {
struct alignas(SANITIZER_CACHE_LINE_SIZE) SizeClassInfo {
StaticSpinMutex mutex;
IntrusiveList<TransferBatch> free_list;
u32 rand_state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ class SizeClassAllocator64 {
u64 last_released_bytes;
};

struct ALIGNED(SANITIZER_CACHE_LINE_SIZE) RegionInfo {
struct alignas(SANITIZER_CACHE_LINE_SIZE) RegionInfo {
Mutex mutex;
uptr num_freed_chunks; // Number of elements in the freearray.
uptr mapped_free_array; // Bytes mapped for freearray.
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct atomic_uint32_t {
struct atomic_uint64_t {
typedef u64 Type;
// On 32-bit platforms u64 is not necessary aligned on 8 bytes.
volatile ALIGNED(8) Type val_dont_use;
alignas(8) volatile Type val_dont_use;
};

struct atomic_uintptr_t {
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/tsan/rtl/tsan_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# define __MM_MALLOC_H
# include <emmintrin.h>
# include <smmintrin.h>
# define VECTOR_ALIGNED ALIGNED(16)
# define VECTOR_ALIGNED alignas(16)
typedef __m128i m128;
#else
# define VECTOR_ALIGNED
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ struct AtExitCtx {
struct InterceptorContext {
// The object is 64-byte aligned, because we want hot data to be located
// in a single cache line if possible (it's accessed in every interceptor).
ALIGNED(64) LibIgnore libignore;
alignas(64) LibIgnore libignore;
__sanitizer_sigaction sigactions[kSigCount];
#if !SANITIZER_APPLE && !SANITIZER_NETBSD
unsigned finalize_key;
Expand All @@ -220,7 +220,7 @@ struct InterceptorContext {
InterceptorContext() : libignore(LINKER_INITIALIZED), atexit_mu(MutexTypeAtExit), AtExitStack() {}
};

static ALIGNED(64) char interceptor_placeholder[sizeof(InterceptorContext)];
alignas(64) static char interceptor_placeholder[sizeof(InterceptorContext)];
InterceptorContext *interceptor_ctx() {
return reinterpret_cast<InterceptorContext*>(&interceptor_placeholder[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/tsan/rtl/tsan_interface_ann.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct DynamicAnnContext {
};

static DynamicAnnContext *dyn_ann_ctx;
static char dyn_ann_ctx_placeholder[sizeof(DynamicAnnContext)] ALIGNED(64);
alignas(64) static char dyn_ann_ctx_placeholder[sizeof(DynamicAnnContext)];

static void AddExpectRace(ExpectRace *list,
char *f, int l, uptr addr, uptr size, char *desc) {
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/tsan/rtl/tsan_mman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct MapUnmapCallback {
}
};

static char allocator_placeholder[sizeof(Allocator)] ALIGNED(64);
alignas(64) static char allocator_placeholder[sizeof(Allocator)];
Allocator *allocator() {
return reinterpret_cast<Allocator*>(&allocator_placeholder);
}
Expand All @@ -75,7 +75,7 @@ struct GlobalProc {
internal_alloc_mtx(MutexTypeInternalAlloc) {}
};

static char global_proc_placeholder[sizeof(GlobalProc)] ALIGNED(64);
alignas(64) static char global_proc_placeholder[sizeof(GlobalProc)];
GlobalProc *global_proc() {
return reinterpret_cast<GlobalProc*>(&global_proc_placeholder);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
namespace __tsan {

#if !SANITIZER_GO
static char main_thread_state[sizeof(ThreadState)] ALIGNED(
static char main_thread_state[sizeof(ThreadState)] alignas(
SANITIZER_CACHE_LINE_SIZE);
static ThreadState *dead_thread_state;
static pthread_key_t thread_state_key;
Expand Down
9 changes: 4 additions & 5 deletions compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ int (*on_finalize)(int);
#endif

#if !SANITIZER_GO && !SANITIZER_APPLE
__attribute__((tls_model("initial-exec")))
THREADLOCAL char cur_thread_placeholder[sizeof(ThreadState)] ALIGNED(
SANITIZER_CACHE_LINE_SIZE);
alignas(SANITIZER_CACHE_LINE_SIZE) THREADLOCAL __attribute__((tls_model(
"initial-exec"))) char cur_thread_placeholder[sizeof(ThreadState)];
#endif
static char ctx_placeholder[sizeof(Context)] ALIGNED(SANITIZER_CACHE_LINE_SIZE);
Context *ctx;
alignas(SANITIZER_CACHE_LINE_SIZE) static char ctx_placeholder[sizeof(Context)];
Context* ctx;

// Can be overriden by a front-end.
#ifdef TSAN_EXTERNAL_HOOKS
Expand Down
8 changes: 4 additions & 4 deletions compiler-rt/lib/tsan/rtl/tsan_rtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct TidEpoch {
Epoch epoch;
};

struct TidSlot {
struct alignas(SANITIZER_CACHE_LINE_SIZE) TidSlot {
Mutex mtx;
Sid sid;
atomic_uint32_t raw_epoch;
Expand All @@ -153,10 +153,10 @@ struct TidSlot {
}

TidSlot();
} ALIGNED(SANITIZER_CACHE_LINE_SIZE);
};

// This struct is stored in TLS.
struct ThreadState {
struct alignas(SANITIZER_CACHE_LINE_SIZE) ThreadState {
FastState fast_state;
int ignore_sync;
#if !SANITIZER_GO
Expand Down Expand Up @@ -234,7 +234,7 @@ struct ThreadState {
const ReportDesc *current_report;

explicit ThreadState(Tid tid);
} ALIGNED(SANITIZER_CACHE_LINE_SIZE);
};

#if !SANITIZER_GO
#if SANITIZER_APPLE || SANITIZER_ANDROID
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/tsan/rtl/tsan_suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const char *__tsan_default_suppressions() {

namespace __tsan {

ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
alignas(64) static char suppression_placeholder[sizeof(SuppressionContext)];
static SuppressionContext *suppression_ctx = nullptr;
static const char *kSuppressionTypes[] = {
kSuppressionRace, kSuppressionRaceTop, kSuppressionMutex,
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/tsan/rtl/tsan_vector_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class VectorClock {
VectorClock& operator=(const VectorClock& other);

private:
Epoch clk_[kThreadSlotCount] VECTOR_ALIGNED;
VECTOR_ALIGNED Epoch clk_[kThreadSlotCount];
};

ALWAYS_INLINE Epoch VectorClock::Get(Sid sid) const {
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/ubsan/ubsan_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ ScopedReport::~ScopedReport() {
Die();
}

ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
alignas(64) static char suppression_placeholder[sizeof(SuppressionContext)];
static SuppressionContext *suppression_ctx = nullptr;
static const char kVptrCheck[] = "vptr_check";
static const char *kSuppressionTypes[] = {
Expand Down
Loading