Skip to content

Commit

Permalink
[CHERI][Coroutines] Disable LangOpts.Coroutines for purecap
Browse files Browse the repository at this point in the history
Attempting to generate code for C++20 coroutines is not yet possible
since the underlying LLVM intrinsics are not overloaded.

See #717
  • Loading branch information
arichardson committed Sep 11, 2023
1 parent 39fb83d commit 30b8264
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
6 changes: 6 additions & 0 deletions clang/lib/Basic/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
32 changes: 32 additions & 0 deletions clang/test/Preprocessor/cheri-coroutines.cpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 30b8264

Please sign in to comment.