[compiler-rt] [sanitizer] Replace ALIGNED with alignas (PR #98958)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 15 13:37:54 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
Author: Fangrui Song (MaskRay)
<details>
<summary>Changes</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.
---
Full diff: https://github.com/llvm/llvm-project/pull/98958.diff
20 Files Affected:
- (modified) compiler-rt/lib/asan/asan_globals_win.cpp (+4-4)
- (modified) compiler-rt/lib/asan/asan_malloc_linux.cpp (+2-2)
- (modified) compiler-rt/lib/asan/asan_report.cpp (+2-2)
- (modified) compiler-rt/lib/asan/asan_suppressions.cpp (+1-1)
- (modified) compiler-rt/lib/asan/asan_thread.cpp (+4-4)
- (modified) compiler-rt/lib/dfsan/dfsan_allocator.h (+1-1)
- (modified) compiler-rt/lib/hwasan/hwasan_allocator.cpp (+1-1)
- (modified) compiler-rt/lib/hwasan/hwasan_thread_list.cpp (+4-4)
- (modified) compiler-rt/lib/lsan/lsan_common.cpp (+1-1)
- (modified) compiler-rt/lib/lsan/lsan_common_linux.cpp (+1-1)
- (modified) compiler-rt/lib/lsan/lsan_thread.cpp (+3-3)
- (modified) compiler-rt/lib/memprof/memprof_thread.cpp (+1-1)
- (modified) compiler-rt/lib/msan/msan.cpp (+4-5)
- (modified) compiler-rt/lib/msan/msan_allocator.h (+1-1)
- (modified) compiler-rt/lib/msan/msan_interceptors.cpp (+1-1)
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp (+1-1)
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h (+1-1)
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h (+1-1)
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_atomic.h (+1-1)
- (modified) compiler-rt/lib/ubsan/ubsan_diag.cpp (+1-1)
``````````diff
diff --git a/compiler-rt/lib/asan/asan_globals_win.cpp b/compiler-rt/lib/asan/asan_globals_win.cpp
index 19af88ab12b40..9442cc35d5ab7 100644
--- a/compiler-rt/lib/asan/asan_globals_win.cpp
+++ b/compiler-rt/lib/asan/asan_globals_win.cpp
@@ -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)) {
diff --git a/compiler-rt/lib/asan/asan_malloc_linux.cpp b/compiler-rt/lib/asan/asan_malloc_linux.cpp
index d426b923c94ed..08a63045c4e65 100644
--- a/compiler-rt/lib/asan/asan_malloc_linux.cpp
+++ b/compiler-rt/lib/asan/asan_malloc_linux.cpp
@@ -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),
diff --git a/compiler-rt/lib/asan/asan_report.cpp b/compiler-rt/lib/asan/asan_report.cpp
index c9730dd368cb4..fd590e401f67f 100644
--- a/compiler-rt/lib/asan/asan_report.cpp
+++ b/compiler-rt/lib/asan/asan_report.cpp
@@ -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;
diff --git a/compiler-rt/lib/asan/asan_suppressions.cpp b/compiler-rt/lib/asan/asan_suppressions.cpp
index 6cee674960395..94289d14d7e78 100644
--- a/compiler-rt/lib/asan/asan_suppressions.cpp
+++ b/compiler-rt/lib/asan/asan_suppressions.cpp
@@ -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";
diff --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp
index 480a423952e8f..c79c33ab01342 100644
--- a/compiler-rt/lib/asan/asan_thread.cpp
+++ b/compiler-rt/lib/asan/asan_thread.cpp
@@ -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);
diff --git a/compiler-rt/lib/dfsan/dfsan_allocator.h b/compiler-rt/lib/dfsan/dfsan_allocator.h
index 3b4171b6314d6..6ff24fc57a855 100644
--- a/compiler-rt/lib/dfsan/dfsan_allocator.h
+++ b/compiler-rt/lib/dfsan/dfsan_allocator.h
@@ -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:
diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index 7771127731de8..75dbb336e3445 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -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 {
diff --git a/compiler-rt/lib/hwasan/hwasan_thread_list.cpp b/compiler-rt/lib/hwasan/hwasan_thread_list.cpp
index e56d19aad2673..794cfb7550d77 100644
--- a/compiler-rt/lib/hwasan/hwasan_thread_list.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_thread_list.cpp
@@ -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();
}
diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp
index 0ecded8b28cdb..183df6e5ca14b 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -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};
diff --git a/compiler-rt/lib/lsan/lsan_common_linux.cpp b/compiler-rt/lib/lsan/lsan_common_linux.cpp
index 692ad35169e1d..7a0b2f038be0d 100644
--- a/compiler-rt/lib/lsan/lsan_common_linux.cpp
+++ b/compiler-rt/lib/lsan/lsan_common_linux.cpp
@@ -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) {
diff --git a/compiler-rt/lib/lsan/lsan_thread.cpp b/compiler-rt/lib/lsan/lsan_thread.cpp
index 8aa3111eecf7d..07c7b923623fa 100644
--- a/compiler-rt/lib/lsan/lsan_thread.cpp
+++ b/compiler-rt/lib/lsan/lsan_thread.cpp
@@ -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();
}
diff --git a/compiler-rt/lib/memprof/memprof_thread.cpp b/compiler-rt/lib/memprof/memprof_thread.cpp
index 9512a87cf98e4..e2bca9bb422f7 100644
--- a/compiler-rt/lib/memprof/memprof_thread.cpp
+++ b/compiler-rt/lib/memprof/memprof_thread.cpp
@@ -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;
diff --git a/compiler-rt/lib/msan/msan.cpp b/compiler-rt/lib/msan/msan.cpp
index b04a72595b93d..2ee05f43ec5e5 100644
--- a/compiler-rt/lib/msan/msan.cpp
+++ b/compiler-rt/lib/msan/msan.cpp
@@ -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;
diff --git a/compiler-rt/lib/msan/msan_allocator.h b/compiler-rt/lib/msan/msan_allocator.h
index c2a38a401f3b6..109e24dc509a3 100644
--- a/compiler-rt/lib/msan/msan_allocator.h
+++ b/compiler-rt/lib/msan/msan_allocator.h
@@ -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();
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index 789b739b41189..c540523e0eaed 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -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]);
}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
index 0513ae36fbc72..1d5058c81acbc 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
@@ -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;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h
index 52fe3fe3d15bd..602b197c42ae3 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h
@@ -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;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 6e73065d7f53c..16cdc4ce53b35 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -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.
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_atomic.h b/compiler-rt/lib/sanitizer_common/sanitizer_atomic.h
index 0609a11ffdebb..257c457351dbc 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_atomic.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_atomic.h
@@ -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 {
diff --git a/compiler-rt/lib/ubsan/ubsan_diag.cpp b/compiler-rt/lib/ubsan/ubsan_diag.cpp
index 67e884e4916c5..1625dfe89eb11 100644
--- a/compiler-rt/lib/ubsan/ubsan_diag.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_diag.cpp
@@ -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[] = {
``````````
</details>
https://github.com/llvm/llvm-project/pull/98958
More information about the llvm-commits
mailing list