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

[libc] raise CMAKE_CXX_STANDARD to C++20 #87020

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nickdesaulniers
Copy link
Member

This is supported by clang-10+ and gcc-10+. Our minimum supported versions are
currently clang-11+, gcc-12+.

We have a few places where we were already using C++20.

libc++ is currently using C++23. We can likely join them, but let's jump to
C++20 first (and ensure our buildbots can support C++23).

This is supported by clang-10+ and gcc-10+. Our minimum supported versions are
currently clang-11+, gcc-12+.

We have a few places where we were already using C++20.

libc++ is currently using C++23. We can likely join them, but let's jump to
C++20 first (and ensure our buildbots can support C++23).
@llvmbot llvmbot added the libc label Mar 28, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 28, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

Changes

This is supported by clang-10+ and gcc-10+. Our minimum supported versions are
currently clang-11+, gcc-12+.

We have a few places where we were already using C++20.

libc++ is currently using C++23. We can likely join them, but let's jump to
C++20 first (and ensure our buildbots can support C++23).


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

6 Files Affected:

  • (modified) libc/CMakeLists.txt (+2-2)
  • (modified) libc/config/linux/app.h (-2)
  • (modified) libc/src/__support/threads/fork_callbacks.cpp (-1)
  • (modified) libc/src/stdlib/CMakeLists.txt (-2)
  • (modified) libc/test/src/network/CMakeLists.txt (-8)
  • (modified) libc/test/src/time/CMakeLists.txt (-6)
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index a0d79858a896ad..1517d698915510 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -26,8 +26,8 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
   add_definitions("-D_DEBUG")
 endif()
 
-# Default to C++17
-set(CMAKE_CXX_STANDARD 17)
+# Default to C++20
+set(CMAKE_CXX_STANDARD 20)
 
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
 
diff --git a/libc/config/linux/app.h b/libc/config/linux/app.h
index 766cd49e88f6f7..0e29176a18d018 100644
--- a/libc/config/linux/app.h
+++ b/libc/config/linux/app.h
@@ -108,8 +108,6 @@ struct TLSDescriptor {
   // Note that, dependending the target architecture ABI, it can be the
   // same as |addr| or something else.
   uintptr_t tp = 0;
-
-  constexpr TLSDescriptor() = default;
 };
 
 // Create and initialize the TLS area for the current thread. Should not
diff --git a/libc/src/__support/threads/fork_callbacks.cpp b/libc/src/__support/threads/fork_callbacks.cpp
index 54fda676f281ed..c019337afc829e 100644
--- a/libc/src/__support/threads/fork_callbacks.cpp
+++ b/libc/src/__support/threads/fork_callbacks.cpp
@@ -20,7 +20,6 @@ struct ForkCallbackTriple {
   ForkCallback *prepare = nullptr;
   ForkCallback *parent = nullptr;
   ForkCallback *child = nullptr;
-  constexpr ForkCallbackTriple() = default;
 };
 
 class AtForkCallbackManager {
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index e526ba040befb7..2a6bda804ea4e5 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -411,8 +411,6 @@ add_entrypoint_object(
     atexit.cpp
   HDRS
     atexit.h
-  CXX_STANDARD
-    20 # For constinit of the atexit callback list.
   DEPENDS
     libc.src.__support.CPP.new
     libc.src.__support.OSUtil.osutil
diff --git a/libc/test/src/network/CMakeLists.txt b/libc/test/src/network/CMakeLists.txt
index 222205dfe247a6..1cda9289c2beec 100644
--- a/libc/test/src/network/CMakeLists.txt
+++ b/libc/test/src/network/CMakeLists.txt
@@ -6,8 +6,6 @@ add_libc_unittest(
     libc_network_unittests
   SRCS
     htonl_test.cpp
-  CXX_STANDARD
-    20
   DEPENDS
     libc.src.network.htonl
     libc.src.network.ntohl
@@ -19,8 +17,6 @@ add_libc_unittest(
     libc_network_unittests
   SRCS
     htons_test.cpp
-  CXX_STANDARD
-    20
   DEPENDS
     libc.src.network.htons
     libc.src.network.ntohs
@@ -32,8 +28,6 @@ add_libc_unittest(
     libc_network_unittests
   SRCS
     ntohl_test.cpp
-  CXX_STANDARD
-    20
   DEPENDS
     libc.src.network.htonl
     libc.src.network.ntohl
@@ -45,8 +39,6 @@ add_libc_unittest(
     libc_network_unittests
   SRCS
     ntohs_test.cpp
-  CXX_STANDARD
-    20
   DEPENDS
     libc.src.network.htons
     libc.src.network.ntohs
diff --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt
index 51cacef0a62fe8..32cad8cf6c5784 100644
--- a/libc/test/src/time/CMakeLists.txt
+++ b/libc/test/src/time/CMakeLists.txt
@@ -9,8 +9,6 @@ add_libc_unittest(
   HDRS
     TmHelper.h
     TmMatcher.h
-  CXX_STANDARD
-    20
   DEPENDS
     libc.src.time.asctime
 )
@@ -24,8 +22,6 @@ add_libc_unittest(
   HDRS
     TmHelper.h
     TmMatcher.h
-  CXX_STANDARD
-    20
   DEPENDS
     libc.src.time.asctime_r
 )
@@ -95,8 +91,6 @@ add_libc_unittest(
   HDRS
     TmHelper.h
     TmMatcher.h
-  CXX_STANDARD
-    20
   DEPENDS
     libc.src.time.mktime
     libc.src.__support.CPP.limits

@nickdesaulniers
Copy link
Member Author

Probably should mention that there was some change to C++20 from C++17 around aggregate initialization.
https://stackoverflow.com/questions/57271400/why-does-aggregate-initialization-not-work-anymore-since-c20-if-a-constructor

@nickdesaulniers
Copy link
Member Author

@gchatelet should I be upgrading benchmarks, too?

-DCMAKE_CXX_STANDARD:STRING=14

@gchatelet
Copy link
Contributor

Just linking in all the goodies we get from C++20
https://en.cppreference.com/w/cpp/20

  • Three-way comparison operator <=> and operator==() = default
  • Designated initializers
  • New attributes: [[no_unique_address]], [[likely]], [[unlikely]]
  • consteval, constinit
  • Signed integers are 2's complement
  • Constraints and concepts

@gchatelet
Copy link
Contributor

@gchatelet should I be upgrading benchmarks, too?

-DCMAKE_CXX_STANDARD:STRING=14

For consistency yes

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

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

LGTM

@nickdesaulniers
Copy link
Member Author

(going to sit on this PR for at least a week to collect feedback RFC style)

@jyknight
Copy link
Member

I do not recommend using C++20 until Clang 17, due to multiple serious bugs in codegen in previous versions. For LLVM, we also upped the minimum to 17.0.6 due to a late issue with the spaceship operator implementation.

If you switch to C++20 for libc, you ought to raise the minimum version as well.

See also https://discourse.llvm.org/t/rfc-clang-17-0-6-would-be-minimum-version-to-build-llvm-in-c-20/75345/8

@nickdesaulniers
Copy link
Member Author

@jyknight , thanks for speaking up and linking to that thread. I'll trust your experience to say we should avoid having to redebug problems @jyknight has already observed. Let's start by first revisiting our documented supported compiler versions. I'll start a new PR/RFC for that.

Once we raise minimum compiler versions, then we can revisit raising the C++ language standard used for the project. Moving this to draft for now to help signal that it's on the back burner.

@nickdesaulniers nickdesaulniers marked this pull request as draft April 5, 2024 18:42
@nickdesaulniers
Copy link
Member Author

Further discussions today; it sounds like libc++ was able to move away from the DLLVM_ENABLE_PROJECTS and now only supports DLLVM_ENABLE_RUNTIMES:

This might be tricky for us because of host dependencies such as:

  • libc-hdrgen
  • gpu server/utilities

Though it sounds like a have a "bootstrap cross build" https://libc.llvm.org/full_cross_build.html#bootstrap-cross-build where this might not be a problem?

cc @petrhosek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants