Skip to content

Commit 49c87e7

Browse files
brooksdavisresistor
authored andcommitted
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 37ece36 commit 49c87e7

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
@@ -1122,7 +1122,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
11221122
if (TI.SupportsCapabilities()) {
11231123
const uint64_t CapWidth = TI.getCHERICapabilityWidth();
11241124
const uint64_t CapRange = TI.getPointerRangeForCHERICapability();
1125-
Builder.defineMacro("__CHERI__", "1"); // TODO: or define __CHERI__ to 128/256?
11261125
Builder.defineMacro("__CHERI_CAPABILITY_WIDTH__", Twine(CapWidth));
11271126
DefineTypeSizeof("__SIZEOF_CHERI_CAPABILITY__", CapWidth, TI, Builder);
11281127
Builder.defineMacro("__CHERI_ADDRESS_BITS__", Twine(CapRange));
@@ -1137,6 +1136,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
11371136
DefineTypeSize("__UINTCAP_MAX__", TI.getIntTypeByWidth(CapRange, false), TI, Builder);
11381137

11391138
if (TI.areAllPointersCapabilities()) {
1139+
Builder.defineMacro("__CHERI__");
1140+
11401141
// XXXAR is there a reason we use two instead of just defining it?
11411142
// I don't think we have any checks that rely on the value
11421143
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
@@ -434,7 +434,6 @@
434434
// CHERI-COMMON-NEXT: #define __CHERI_CAP_PERMISSION_PERMIT_STORE_LOCAL__ 64
435435
// CHERI-COMMON-NEXT: #define __CHERI_CAP_PERMISSION_PERMIT_STORE__ 8
436436
// CHERI-COMMON-NEXT: #define __CHERI_CAP_PERMISSION_PERMIT_UNSEAL__ 512
437-
// CHERI-COMMON-NEXT: #define __CHERI__ 1
438437
// CHERI-COMMON-NEXT: #define __CHERI_HYBRID__ 1
439438
// CHERI64: #define __POINTER_WIDTH__ 32
440439
// CHERI128: #define __POINTER_WIDTH__ 64
@@ -487,6 +486,7 @@
487486
// CHERI128-PURECAP: #define _MIPS_FPSET 32
488487
// CHERI128-PURECAP: #define __CHERI_PURE_CAPABILITY__ 2
489488
// CHERI128-PURECAP: #define __CHERI_SANDBOX__ 4
489+
// CHERI128-PURECAP: #define __CHERI__ 1
490490
// CHERI128-PURECAP: #define __INTPTR_FMTd__ "Pd"
491491
// CHERI128-PURECAP: #define __INTPTR_FMTi__ "Pi"
492492
// CHERI128-PURECAP: #define __INTPTR_MAX__ 9223372036854775807L

0 commit comments

Comments
 (0)