Skip to content

Commit 00f9977

Browse files
committed
Make __CHERI__ a synonym for __CHERI_PURE_CAPABILITY__
WARNING: This is a breaking change for hybrid code bases. Rational: We strongly encourage all CHERI consumers to use a pure-capability ABI whenever possible. In order to do so more firmly, make __CHERI__ (the shortest macro) a synonym for __CHERI_PURE_CAPABILITY__ rather than __has_feature(capabilities). Backwards compatible code transition: For purecap + standard C/C++ code: No change required. For hybrid + standard C/C++ code: __CHERI__ -> __has_feature(capabilities) For mixed code: __CHERI__ -> __has_feature(capabilities) Once the need for compatability with old compilers is passed further simplication is possible. For purecap + standard C/C++ code: __CHERI_PURE_CAPABILITY__ -> __CHERI__ For hybrid + standard C/C++ code: __has_feature(capabilities) && !defined(__CHERI_PURE_CAPABILITY__) -> __CHERI_HYBRID__
1 parent 4c706b5 commit 00f9977

File tree

6 files changed

+7
-5
lines changed

6 files changed

+7
-5
lines changed

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
997997
if (TI.SupportsCapabilities()) {
998998
const uint64_t CapWidth = TI.getCHERICapabilityWidth();
999999
const uint64_t CapRange = TI.getPointerRangeForCHERICapability();
1000-
Builder.defineMacro("__CHERI__", "1"); // TODO: or define __CHERI__ to 128/256?
10011000
Builder.defineMacro("__CHERI_CAPABILITY_WIDTH__", Twine(CapWidth));
10021001
DefineTypeSizeof("__SIZEOF_CHERI_CAPABILITY__", CapWidth, TI, Builder);
10031002
Builder.defineMacro("__CHERI_ADDRESS_BITS__", Twine(CapRange));
@@ -1012,6 +1011,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
10121011
DefineTypeSize("__UINTCAP_MAX__", TI.getIntTypeByWidth(CapRange, false), TI, Builder);
10131012

10141013
if (TI.areAllPointersCapabilities()) {
1014+
Builder.defineMacro("__CHERI__", "1");
1015+
10151016
// XXXAR is there a reason we use two instead of just defining it?
10161017
// I don't think we have any checks that rely on the value
10171018
Builder.defineMacro("__CHERI_PURE_CAPABILITY__", "2");

clang/test/Driver/cheri/bounds-mode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// RUN: %cheri_purecap_clang -E -dM -Xclang -cheri-bounds=conservative %s 2>&1 | FileCheck --check-prefixes=CHECK,SUBOBJECT-DISABLED %s
1515
// Without any flag subobject bounds should currently be disabled
1616
// RUN: %cheri_purecap_clang -E -dM %s 2>&1 | FileCheck --check-prefixes=SUBOBJECT-DISABLED %s
17+
// CHECK: #define __CHERI__ 1
1718
// CHECK: #define __CHERI_PURE_CAPABILITY__ 2
1819
// SUBOBJECT-DISABLED-NOT: __CHERI_SUBOBJECT_BOUNDS__
1920
// SUBOBJECT-SAFE: #define __CHERI_SUBOBJECT_BOUNDS__ 2

clang/test/Preprocessor/cheri-cap-sizes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
// CHERI128: #define _MIPS_SZCAP 128
3737
// CHECK: #define __CHERI_ADDRESS_BITS__ 64
3838
// CHERI128: #define __CHERI_CAPABILITY_WIDTH__ 128
39+
// PURECAP: #define __CHERI__ 1
3940
// PURECAP: #define __CHERI_PURE_CAPABILITY__ 2
4041
// MIPS-NOT: __CHERI_PURE_CAPABILITY__
41-
// CHECK: #define __CHERI__ 1
42+
// MIPS-NOT: __CHERI__
4243
// MIPS: #define __CHERI_HYBRID__ 1
4344
// Note: 64-bit range for intcap makes more sense than the full range for pointers
4445
// CHECK: #define __INTCAP_MAX__ 9223372036854775807L

clang/test/Preprocessor/cheri-features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void* __capability x = 0;
1616

1717
#if defined(__CHERI__)
1818
#pragma message("__CHERI__ defined")
19-
// CHECK-CHERI: warning: __CHERI__ defined
19+
// CHECK-CHERI: warning: __CHERI__ not defined
2020
void* __capability y = 0;
2121
#else
2222
#pragma message("__CHERI__ not defined")

clang/test/Preprocessor/cheri-riscv-feature-flags.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// CHECK: #define __CHERI_CAP_PERMISSION_PERMIT_STORE_LOCAL__ 64
1919
// CHECK: #define __CHERI_CAP_PERMISSION_PERMIT_STORE__ 8
2020
// CHECK: #define __CHERI_CAP_PERMISSION_PERMIT_UNSEAL__ 512
21-
// CHECK: #define __CHERI__ 1
2221
// CHECK: #define __CHERI_HYBRID__ 1
2322
// CHECK32: #define __SIZEOF_CHERI_CAPABILITY__ 8
2423
// CHECK64: #define __SIZEOF_CHERI_CAPABILITY__ 16

clang/test/Preprocessor/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@
355355
// CHERI-COMMON-NEXT: #define __CHERI_CAP_PERMISSION_PERMIT_STORE_LOCAL__ 64
356356
// CHERI-COMMON-NEXT: #define __CHERI_CAP_PERMISSION_PERMIT_STORE__ 8
357357
// CHERI-COMMON-NEXT: #define __CHERI_CAP_PERMISSION_PERMIT_UNSEAL__ 512
358-
// CHERI-COMMON-NEXT: #define __CHERI__ 1
359358
// CHERI-COMMON-NEXT: #define __CHERI_HYBRID__ 1
360359
// CHERI64: #define __POINTER_WIDTH__ 32
361360
// CHERI128: #define __POINTER_WIDTH__ 64
@@ -406,6 +405,7 @@
406405

407406
// RUN: %cheri_cc1 -E -dM -ffreestanding -triple=mips64-none-none -target-abi purecap < /dev/null | FileCheck -check-prefix CHERI128-PURECAP %s
408407
// CHERI128-PURECAP: #define _MIPS_FPSET 32
408+
// CHERI128-PURECAP: #define __CHERI__ 1
409409
// CHERI128-PURECAP: #define __CHERI_PURE_CAPABILITY__ 2
410410
// CHERI128-PURECAP: #define __CHERI_SANDBOX__ 4
411411
// CHERI128-PURECAP: #define __INTPTR_FMTd__ "Pd"

0 commit comments

Comments
 (0)