Skip to content

Commit 67500fa

Browse files
committed
Make __CHERI__ a synonym for __CHERI_PURE_CAPABILITY__
WARNING: This is a breaking change for hybrid + standard C/C++ code. Rationale: We strongly encourage all CHERI consumers to use a pure-capability ABI whenever possible. Therefore it should be the easiest thing to type and less preferred options should be longer. The existing macros date to the earliest compiler support which barely supported capability types. Before broad adoption of CHERI we should make the macros be sensible. We're past Stuart Feldman's too many users of make to change the tabs threshold (12), but few codebases will be effected, the required changes are simple can be safely performed without automatic review, and we shouldn't have to live with this aspect of history forever. Backwards compatible code transition: For purecap + standard C/C++ code (no hybrid): No change required. For hybrid + standard C/C++ (with or without purecap): defined(__CHERI__) -> __has_feature(capabilities) or defined(__CHERI__) -> defined(__CHERI__) || defined(__CHERI_HYBRID__) 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__) -> defined(__CHERI_HYBRID__)
1 parent 9f009aa commit 67500fa

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__");
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
@@ -17,3 +17,4 @@
1717
// CHECK: #define __CHERI_PURE_CAPABILITY__ 2
1818
// SUBOBJECT-DISABLED-NOT: __CHERI_SUBOBJECT_BOUNDS__
1919
// SUBOBJECT-SAFE: #define __CHERI_SUBOBJECT_BOUNDS__ 2
20+
// CHECK: #define __CHERI__ 1

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
// CHECK: #define __CHERI_ADDRESS_BITS__ 64
3838
// CHERI128: #define __CHERI_CAPABILITY_WIDTH__ 128
3939
// PURECAP: #define __CHERI_PURE_CAPABILITY__ 2
40+
// PURECAP: #define __CHERI__ 1
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
@@ -25,10 +25,10 @@ void* __capability x = 0;
2525

2626
#if defined(__CHERI__)
2727
#pragma message("__CHERI__ defined")
28-
// CHECK-CHERI: warning: __CHERI__ defined
2928
void* __capability y = 0;
3029
#else
3130
#pragma message("__CHERI__ not defined")
31+
// CHECK-CHERI: warning: __CHERI__ not defined
3232
// CHECK-MIPS: warning: __CHERI__ not defined
3333
#endif
3434

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
@@ -408,6 +407,7 @@
408407
// CHERI128-PURECAP: #define _MIPS_FPSET 32
409408
// CHERI128-PURECAP: #define __CHERI_PURE_CAPABILITY__ 2
410409
// CHERI128-PURECAP: #define __CHERI_SANDBOX__ 4
410+
// CHERI128-PURECAP: #define __CHERI__ 1
411411
// CHERI128-PURECAP: #define __INTPTR_FMTd__ "Pd"
412412
// CHERI128-PURECAP: #define __INTPTR_FMTi__ "Pi"
413413
// CHERI128-PURECAP: #define __INTPTR_MAX__ 9223372036854775807L

0 commit comments

Comments
 (0)