Skip to content

[llvm] Replace deprecated aligned_storage with aligned byte array #94169

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

Conversation

marcauberer
Copy link
Member

std::aligned_storage is deprecated with C++23, see here.

This replaces the usages of std::aligned_storage within llvm (only one in ADT and one in Support) with an aligned std::byte array.
I will provide patches for other subcomponents as well.

@llvmbot
Copy link
Member

llvmbot commented Jun 2, 2024

@llvm/pr-subscribers-llvm-adt

Author: Marc Auberer (marcauberer)

Changes

std::aligned_storage is deprecated with C++23, see here.

This replaces the usages of std::aligned_storage within llvm (only one in ADT and one in Support) with an aligned std::byte array.
I will provide patches for other subcomponents as well.


Full diff: https://github.com/llvm/llvm-project/pull/94169.diff

2 Files Affected:

  • (modified) llvm/include/llvm/ADT/FunctionExtras.h (+1-2)
  • (modified) llvm/lib/Support/PrettyStackTrace.cpp (+2-4)
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index c0bc30c7450fe..49e0e8ab0db40 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -161,8 +161,7 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
     // provide three pointers worth of storage here.
     // This is mutable as an inlined `const unique_function<void() const>` may
     // still modify its own mutable members.
-    mutable std::aligned_storage_t<InlineStorageSize, alignof(void *)>
-        InlineStorage;
+    alignas(void *) mutable std::byte InlineStorage[InlineStorageSize];
   } StorageUnion;
 
   // A compressed pointer to either our dispatching callback or our table of
diff --git a/llvm/lib/Support/PrettyStackTrace.cpp b/llvm/lib/Support/PrettyStackTrace.cpp
index f9f1b8a419b82..7c6d84d3697db 100644
--- a/llvm/lib/Support/PrettyStackTrace.cpp
+++ b/llvm/lib/Support/PrettyStackTrace.cpp
@@ -143,10 +143,8 @@ static void setCrashLogMessage(const char *msg) {
 
 #ifdef __APPLE__
 using CrashHandlerString = SmallString<2048>;
-using CrashHandlerStringStorage =
-    std::aligned_storage<sizeof(CrashHandlerString),
-                         alignof(CrashHandlerString)>::type;
-static CrashHandlerStringStorage crashHandlerStringStorage;
+using CrashHandlerStringStorage = std::byte[sizeof(CrashHandlerString)];
+alignas(CrashHandlerString) static CrashHandlerStringStorage crashHandlerStringStorage;
 #endif
 
 /// This callback is run if a fatal signal is delivered to the process, it

@llvmbot
Copy link
Member

llvmbot commented Jun 2, 2024

@llvm/pr-subscribers-llvm-support

Author: Marc Auberer (marcauberer)

Changes

std::aligned_storage is deprecated with C++23, see here.

This replaces the usages of std::aligned_storage within llvm (only one in ADT and one in Support) with an aligned std::byte array.
I will provide patches for other subcomponents as well.


Full diff: https://github.com/llvm/llvm-project/pull/94169.diff

2 Files Affected:

  • (modified) llvm/include/llvm/ADT/FunctionExtras.h (+1-2)
  • (modified) llvm/lib/Support/PrettyStackTrace.cpp (+2-4)
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index c0bc30c7450fe..49e0e8ab0db40 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -161,8 +161,7 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
     // provide three pointers worth of storage here.
     // This is mutable as an inlined `const unique_function<void() const>` may
     // still modify its own mutable members.
-    mutable std::aligned_storage_t<InlineStorageSize, alignof(void *)>
-        InlineStorage;
+    alignas(void *) mutable std::byte InlineStorage[InlineStorageSize];
   } StorageUnion;
 
   // A compressed pointer to either our dispatching callback or our table of
diff --git a/llvm/lib/Support/PrettyStackTrace.cpp b/llvm/lib/Support/PrettyStackTrace.cpp
index f9f1b8a419b82..7c6d84d3697db 100644
--- a/llvm/lib/Support/PrettyStackTrace.cpp
+++ b/llvm/lib/Support/PrettyStackTrace.cpp
@@ -143,10 +143,8 @@ static void setCrashLogMessage(const char *msg) {
 
 #ifdef __APPLE__
 using CrashHandlerString = SmallString<2048>;
-using CrashHandlerStringStorage =
-    std::aligned_storage<sizeof(CrashHandlerString),
-                         alignof(CrashHandlerString)>::type;
-static CrashHandlerStringStorage crashHandlerStringStorage;
+using CrashHandlerStringStorage = std::byte[sizeof(CrashHandlerString)];
+alignas(CrashHandlerString) static CrashHandlerStringStorage crashHandlerStringStorage;
 #endif
 
 /// This callback is run if a fatal signal is delivered to the process, it

Copy link

github-actions bot commented Jun 2, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@tschuett
Copy link

tschuett commented Jun 2, 2024

Why? We are not even close to C++20?

@marcauberer
Copy link
Member Author

Why? We are not even close to C++20?

As these are in headers, which are transitively included by users (which potentially use C++23). So they will get the deprecation warnings as well.

Copy link
Collaborator

@dwblaikie dwblaikie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@marcauberer marcauberer merged commit bf4eaec into llvm:main Jun 3, 2024
7 checks passed
@marcauberer marcauberer deleted the llvm/replace-aligned-storage-with-aligned-byte-array branch June 3, 2024 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants