[Clang] Add `-funstable` flag to enable unstable and experimental features

This new flag enables `__has_feature(cxx_unstable)` that would replace libc++ macros for individual unstable/experimental features, e.g. `_LIBCPP_HAS_NO_INCOMPLETE_RANGES` or `_LIBCPP_HAS_NO_INCOMPLETE_FORMAT`.

This would make it easier and more convenient to opt-in into all libc++ unstable features at once.

Differential Revision: https://reviews.llvm.org/D120160
This commit is contained in:
Egor Zhdan 2022-02-18 21:04:49 +00:00
parent 640e45b9b2
commit 3cdc1c155b
6 changed files with 29 additions and 0 deletions

View File

@ -173,6 +173,7 @@ FEATURE(cxx_thread_local,
FEATURE(cxx_trailing_return, LangOpts.CPlusPlus11)
FEATURE(cxx_unicode_literals, LangOpts.CPlusPlus11)
FEATURE(cxx_unrestricted_unions, LangOpts.CPlusPlus11)
FEATURE(cxx_unstable, LangOpts.Unstable)
FEATURE(cxx_user_literals, LangOpts.CPlusPlus11)
FEATURE(cxx_variadic_templates, LangOpts.CPlusPlus11)
// C++14 features

View File

@ -150,6 +150,7 @@ LANGOPT(GNUAsm , 1, 1, "GNU-style inline assembly")
LANGOPT(Coroutines , 1, 0, "C++20 coroutines")
LANGOPT(DllExportInlines , 1, 1, "dllexported classes dllexport inline methods")
LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template template arguments")
LANGOPT(Unstable , 1, 0, "Enable unstable and experimental features")
LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for all language standard modes")

View File

@ -1160,6 +1160,11 @@ defm coroutines_ts : BoolFOption<"coroutines-ts",
PosFlag<SetTrue, [CC1Option], "Enable support for the C++ Coroutines TS">,
NegFlag<SetFalse>>;
defm unstable : BoolFOption<"unstable",
LangOpts<"Unstable">, DefaultFalse,
PosFlag<SetTrue, [CC1Option, CoreOption], "Enable unstable and experimental features">,
NegFlag<SetFalse>>;
def fembed_offload_object_EQ : Joined<["-"], "fembed-offload-object=">,
Group<f_Group>, Flags<[NoXarchOption, CC1Option]>,
HelpText<"Embed Offloading device-side binary into host object file as a section.">,

View File

@ -5764,6 +5764,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(A->getValue());
}
if (Args.hasArg(options::OPT_funstable)) {
CmdArgs.push_back("-funstable");
if (!Args.hasArg(options::OPT_fno_coroutines_ts))
CmdArgs.push_back("-fcoroutines-ts");
CmdArgs.push_back("-fmodules-ts");
}
if (Args.hasArg(options::OPT_fexperimental_new_constant_interpreter))
CmdArgs.push_back("-fexperimental-new-constant-interpreter");

View File

@ -0,0 +1,5 @@
// RUN: %clang -funstable -### %s 2>&1 | FileCheck %s
// CHECK: -funstable
// CHECK: -fcoroutines-ts
// CHECK: -fmodules-ts

View File

@ -0,0 +1,10 @@
// RUN: %clang_cc1 -funstable -E %s -o - | FileCheck --check-prefix=CHECK-UNSTABLE %s
// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-UNSTABLE %s
#if __has_feature(cxx_unstable)
int has_cxx_unstable();
#else
int has_no_cxx_unstable();
#endif
// CHECK-UNSTABLE: int has_cxx_unstable();
// CHECK-NO-UNSTABLE: int has_no_cxx_unstable();