Skip to content

Commit 256ebe7

Browse files
MaskRayyuxuanchen1997
authored andcommitted
[sanitizer] Replace ALIGNED with alignas
Summary: C++11 `alignas` is already used extensively. `alignas` must precede `static`, so adjust the ordering accordingly. msan.cpp: Clang 15 doesn't allow `__attribute__((visibility("default"))) alignas(16)`. Use the order `alignas(16) SANITIZER_INTERFACE_ATTRIBUTE`. Tested with Clang 7. Pull Request: #98958 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251486
1 parent 2134b3d commit 256ebe7

20 files changed

+36
-37
lines changed

compiler-rt/lib/asan/asan_globals_win.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ namespace __asan {
1717

1818
#pragma section(".ASAN$GA", read, write)
1919
#pragma section(".ASAN$GZ", read, write)
20-
extern "C" __declspec(allocate(".ASAN$GA"))
21-
ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_start = {};
22-
extern "C" __declspec(allocate(".ASAN$GZ"))
23-
ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_end = {};
20+
extern "C" alignas(sizeof(__asan_global))
21+
__declspec(allocate(".ASAN$GA")) __asan_global __asan_globals_start = {};
22+
extern "C" alignas(sizeof(__asan_global))
23+
__declspec(allocate(".ASAN$GZ")) __asan_global __asan_globals_end = {};
2424
#pragma comment(linker, "/merge:.ASAN=.data")
2525

2626
static void call_on_globals(void (*hook)(__asan_global *, uptr)) {

compiler-rt/lib/asan/asan_malloc_linux.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ struct MallocDebugL {
185185
void* (*valloc)(uptr size);
186186
};
187187

188-
ALIGNED(32) const MallocDebugK asan_malloc_dispatch_k = {
188+
alignas(32) const MallocDebugK asan_malloc_dispatch_k = {
189189
WRAP(malloc), WRAP(free), WRAP(calloc),
190190
WRAP(realloc), WRAP(memalign), WRAP(malloc_usable_size)};
191191

192-
ALIGNED(32) const MallocDebugL asan_malloc_dispatch_l = {
192+
alignas(32) const MallocDebugL asan_malloc_dispatch_l = {
193193
WRAP(calloc), WRAP(free), WRAP(mallinfo),
194194
WRAP(malloc), WRAP(malloc_usable_size), WRAP(memalign),
195195
WRAP(posix_memalign), WRAP(pvalloc), WRAP(realloc),

compiler-rt/lib/asan/asan_report.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ namespace __asan {
3434
// -------------------- User-specified callbacks ----------------- {{{1
3535
static void (*error_report_callback)(const char*);
3636
using ErrorMessageBuffer = InternalMmapVectorNoCtor<char, true>;
37-
static ALIGNED(
38-
alignof(ErrorMessageBuffer)) char error_message_buffer_placeholder
37+
alignas(
38+
alignof(ErrorMessageBuffer)) static char error_message_buffer_placeholder
3939
[sizeof(ErrorMessageBuffer)];
4040
static ErrorMessageBuffer *error_message_buffer = nullptr;
4141
static Mutex error_message_buf_mutex;

compiler-rt/lib/asan/asan_suppressions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace __asan {
2222

23-
ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
23+
alignas(64) static char suppression_placeholder[sizeof(SuppressionContext)];
2424
static SuppressionContext *suppression_ctx = nullptr;
2525
static const char kInterceptorName[] = "interceptor_name";
2626
static const char kInterceptorViaFunction[] = "interceptor_via_fun";

compiler-rt/lib/asan/asan_thread.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ static void InitThreads() {
6767
// thread before all TSD destructors will be called for it.
6868

6969
// MIPS requires aligned address
70-
static ALIGNED(alignof(
71-
ThreadRegistry)) char thread_registry_placeholder[sizeof(ThreadRegistry)];
72-
static ALIGNED(alignof(
73-
ThreadArgRetval)) char thread_data_placeholder[sizeof(ThreadArgRetval)];
70+
alignas(alignof(ThreadRegistry)) static char
71+
thread_registry_placeholder[sizeof(ThreadRegistry)];
72+
alignas(alignof(ThreadArgRetval)) static char
73+
thread_data_placeholder[sizeof(ThreadArgRetval)];
7474

7575
asan_thread_registry =
7676
new (thread_registry_placeholder) ThreadRegistry(GetAsanThreadContext);

compiler-rt/lib/dfsan/dfsan_allocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace __dfsan {
1919

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

2424
private:

compiler-rt/lib/hwasan/hwasan_allocator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum {
4444

4545

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

5050
bool HwasanChunkView::IsAllocated() const {

compiler-rt/lib/hwasan/hwasan_thread_list.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ ThreadArgRetval &hwasanThreadArgRetval() { return *thread_data; }
1414
void InitThreadList(uptr storage, uptr size) {
1515
CHECK_EQ(hwasan_thread_list, nullptr);
1616

17-
static ALIGNED(alignof(
18-
HwasanThreadList)) char thread_list_placeholder[sizeof(HwasanThreadList)];
17+
alignas(alignof(HwasanThreadList)) static char
18+
thread_list_placeholder[sizeof(HwasanThreadList)];
1919
hwasan_thread_list =
2020
new (thread_list_placeholder) HwasanThreadList(storage, size);
2121

2222
CHECK_EQ(thread_data, nullptr);
2323

24-
static ALIGNED(alignof(
25-
ThreadArgRetval)) char thread_data_placeholder[sizeof(ThreadArgRetval)];
24+
alignas(alignof(ThreadArgRetval)) static char
25+
thread_data_placeholder[sizeof(ThreadArgRetval)];
2626
thread_data = new (thread_data_placeholder) ThreadArgRetval();
2727
}
2828

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class LeakSuppressionContext {
108108
void PrintMatchedSuppressions();
109109
};
110110

111-
ALIGNED(64) static char suppression_placeholder[sizeof(LeakSuppressionContext)];
111+
alignas(64) static char suppression_placeholder[sizeof(LeakSuppressionContext)];
112112
static LeakSuppressionContext *suppression_ctx = nullptr;
113113
static const char kSuppressionLeak[] = "leak";
114114
static const char *kSuppressionTypes[] = {kSuppressionLeak};

compiler-rt/lib/lsan/lsan_common_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace __lsan {
2828

2929
static const char kLinkerName[] = "ld";
3030

31-
static char linker_placeholder[sizeof(LoadedModule)] ALIGNED(64);
31+
alignas(64) static char linker_placeholder[sizeof(LoadedModule)];
3232
static LoadedModule *linker = nullptr;
3333

3434
static bool IsLinker(const LoadedModule& module) {

compiler-rt/lib/lsan/lsan_thread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ static ThreadContextBase *CreateThreadContext(u32 tid) {
3535
}
3636

3737
void InitializeThreads() {
38-
static ALIGNED(alignof(
39-
ThreadRegistry)) char thread_registry_placeholder[sizeof(ThreadRegistry)];
38+
alignas(alignof(ThreadRegistry)) static char
39+
thread_registry_placeholder[sizeof(ThreadRegistry)];
4040
thread_registry =
4141
new (thread_registry_placeholder) ThreadRegistry(CreateThreadContext);
4242

43-
static ALIGNED(alignof(ThreadArgRetval)) char
43+
alignas(alignof(ThreadArgRetval)) static char
4444
thread_arg_retval_placeholder[sizeof(ThreadArgRetval)];
4545
thread_arg_retval = new (thread_arg_retval_placeholder) ThreadArgRetval();
4646
}

compiler-rt/lib/memprof/memprof_thread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void MemprofThreadContext::OnFinished() {
3737
thread = nullptr;
3838
}
3939

40-
static ALIGNED(16) char thread_registry_placeholder[sizeof(ThreadRegistry)];
40+
alignas(16) static char thread_registry_placeholder[sizeof(ThreadRegistry)];
4141
static ThreadRegistry *memprof_thread_registry;
4242

4343
static Mutex mu_for_thread_context;

compiler-rt/lib/msan/msan.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ THREADLOCAL u64 __msan_retval_tls[kMsanRetvalTlsSize / sizeof(u64)];
5656
SANITIZER_INTERFACE_ATTRIBUTE
5757
THREADLOCAL u32 __msan_retval_origin_tls;
5858

59-
SANITIZER_INTERFACE_ATTRIBUTE
60-
ALIGNED(16) THREADLOCAL u64 __msan_va_arg_tls[kMsanParamTlsSize / sizeof(u64)];
59+
alignas(16) SANITIZER_INTERFACE_ATTRIBUTE THREADLOCAL u64
60+
__msan_va_arg_tls[kMsanParamTlsSize / sizeof(u64)];
6161

62-
SANITIZER_INTERFACE_ATTRIBUTE
63-
ALIGNED(16)
64-
THREADLOCAL u32 __msan_va_arg_origin_tls[kMsanParamTlsSize / sizeof(u32)];
62+
alignas(16) SANITIZER_INTERFACE_ATTRIBUTE THREADLOCAL u32
63+
__msan_va_arg_origin_tls[kMsanParamTlsSize / sizeof(u32)];
6564

6665
SANITIZER_INTERFACE_ATTRIBUTE
6766
THREADLOCAL u64 __msan_va_arg_overflow_size_tls;

compiler-rt/lib/msan/msan_allocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace __msan {
1919

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

compiler-rt/lib/msan/msan_interceptors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ struct InterceptorContext {
12551255
}
12561256
};
12571257

1258-
static ALIGNED(64) char interceptor_placeholder[sizeof(InterceptorContext)];
1258+
alignas(64) static char interceptor_placeholder[sizeof(InterceptorContext)];
12591259
InterceptorContext *interceptor_ctx() {
12601260
return reinterpret_cast<InterceptorContext*>(&interceptor_placeholder[0]);
12611261
}

compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace __sanitizer {
2525
const char *PrimaryAllocatorName = "SizeClassAllocator";
2626
const char *SecondaryAllocatorName = "LargeMmapAllocator";
2727

28-
static ALIGNED(64) char internal_alloc_placeholder[sizeof(InternalAllocator)];
28+
alignas(64) static char internal_alloc_placeholder[sizeof(InternalAllocator)];
2929
static atomic_uint8_t internal_allocator_initialized;
3030
static StaticSpinMutex internal_alloc_init_mu;
3131

compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class SizeClassAllocator32 {
278278
static const uptr kRegionSize = 1 << kRegionSizeLog;
279279
static const uptr kNumPossibleRegions = kSpaceSize / kRegionSize;
280280

281-
struct ALIGNED(SANITIZER_CACHE_LINE_SIZE) SizeClassInfo {
281+
struct alignas(SANITIZER_CACHE_LINE_SIZE) SizeClassInfo {
282282
StaticSpinMutex mutex;
283283
IntrusiveList<TransferBatch> free_list;
284284
u32 rand_state;

compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ class SizeClassAllocator64 {
667667
u64 last_released_bytes;
668668
};
669669

670-
struct ALIGNED(SANITIZER_CACHE_LINE_SIZE) RegionInfo {
670+
struct alignas(SANITIZER_CACHE_LINE_SIZE) RegionInfo {
671671
Mutex mutex;
672672
uptr num_freed_chunks; // Number of elements in the freearray.
673673
uptr mapped_free_array; // Bytes mapped for freearray.

compiler-rt/lib/sanitizer_common/sanitizer_atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct atomic_uint32_t {
6161
struct atomic_uint64_t {
6262
typedef u64 Type;
6363
// On 32-bit platforms u64 is not necessary aligned on 8 bytes.
64-
volatile ALIGNED(8) Type val_dont_use;
64+
alignas(8) volatile Type val_dont_use;
6565
};
6666

6767
struct atomic_uintptr_t {

compiler-rt/lib/ubsan/ubsan_diag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ ScopedReport::~ScopedReport() {
402402
Die();
403403
}
404404

405-
ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
405+
alignas(64) static char suppression_placeholder[sizeof(SuppressionContext)];
406406
static SuppressionContext *suppression_ctx = nullptr;
407407
static const char kVptrCheck[] = "vptr_check";
408408
static const char *kSuppressionTypes[] = {

0 commit comments

Comments
 (0)