From 30b82644e1bbd348d513e7ee5bed71edd8dddb53 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Sun, 10 Sep 2023 16:44:52 -0700 Subject: [PATCH] [CHERI][Coroutines] Disable LangOpts.Coroutines for purecap Attempting to generate code for C++20 coroutines is not yet possible since the underlying LLVM intrinsics are not overloaded. See https://github.com/CTSRD-CHERI/llvm-project/issues/717 --- clang/lib/Basic/TargetInfo.cpp | 6 ++++ clang/lib/Frontend/InitPreprocessor.cpp | 3 +- clang/test/Preprocessor/cheri-coroutines.cpp | 32 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 clang/test/Preprocessor/cheri-coroutines.cpp diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 705e6e14cb15..50682672c1fe 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -391,6 +391,12 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) { LongDoubleAlign = 64; } + if (areAllPointersCapabilities()) { + // C++20 coroutines are not yet supported for purecap: + // https://github.com/CTSRD-CHERI/llvm-project/issues/717 + Opts.Coroutines = false; + } + if (Opts.OpenCL) { // OpenCL C requires specific widths for types, irrespective of // what these normally are for the target. diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d1bfa52186a8..14d586990206 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -682,7 +682,8 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, //Builder.defineMacro("__cpp_consteval", "201811L"); Builder.defineMacro("__cpp_constexpr_dynamic_alloc", "201907L"); Builder.defineMacro("__cpp_constinit", "201907L"); - Builder.defineMacro("__cpp_impl_coroutine", "201902L"); + if (LangOpts.Coroutines) + Builder.defineMacro("__cpp_impl_coroutine", "201902L"); Builder.defineMacro("__cpp_designated_initializers", "201707L"); Builder.defineMacro("__cpp_impl_three_way_comparison", "201907L"); //Builder.defineMacro("__cpp_modules", "201907L"); diff --git a/clang/test/Preprocessor/cheri-coroutines.cpp b/clang/test/Preprocessor/cheri-coroutines.cpp new file mode 100644 index 000000000000..d9f40a9f2897 --- /dev/null +++ b/clang/test/Preprocessor/cheri-coroutines.cpp @@ -0,0 +1,32 @@ +/// Coroutines are not yet supported for purecap, make sure we emit an error +/// instead crashing while trying to generate code. +/// See https://github.com/CTSRD-CHERI/llvm-project/issues/717 + +// RUN: %riscv64_cheri_cc1 -std=c++17 -fcoroutines-ts -E -dM -x c++ /dev/null \ +// RUN: | FileCheck %s --check-prefixes=HYBRID-CXX17-TS +// HYBRID-CXX17-TS: #define __cplusplus 201703L +// HYBRID-CXX17-TS: #define __cpp_coroutines 201703L +// RUN: %riscv64_cheri_purecap_cc1 -std=c++17 -fcoroutines-ts -E -dM -x c++ /dev/null \ +// RUN: | FileCheck %s --check-prefix=PURECAP-CXX17-TS +// PURECAP-CXX17-TS: #define __cplusplus 201703L +// PURECAP-CXX17-TS-NOT: #define __cpp_coroutines +// PURECAP-CXX17-TS-NOT: #define __cpp_impl_coroutine + +// RUN: %riscv64_cheri_cc1 -std=c++17 -E -dM -x c++ /dev/null \ +// RUN: | FileCheck %s --check-prefix=CXX17-NO-TS +// RUN: %riscv64_cheri_purecap_cc1 -std=c++17 -E -dM -x c++ /dev/null \ +// RUN: | FileCheck %s --check-prefix=CXX17-NO-TS +// CXX17-NO-TS: #define __cplusplus 201703L +// CXX17-NO-TS-NOT: #define __cpp_coroutines +// CXX17-NO-TS-NOT: #define __cpp_impl_coroutine + +// RUN: %riscv64_cheri_cc1 -std=c++20 -E -dM -x c++ /dev/null \ +// RUN: | FileCheck %s --check-prefixes=HYBRID-CXX20 +// HYBRID-CXX20: #define __cplusplus 202002L +// HYBRID-CXX20: #define __cpp_coroutines 201703L +// HYBRID-CXX20: #define __cpp_impl_coroutine 201902L +// RUN: %riscv64_cheri_purecap_cc1 -std=c++20 -E -dM -x c++ /dev/null \ +// RUN: | FileCheck %s --check-prefix=PURECAP-CXX20 +// PURECAP-CXX20: #define __cplusplus 202002L +// PURECAP-CXX20-NOT: #define __cpp_coroutines +// PURECAP-CXX20-NOT: #define __cpp_impl_coroutine