Skip to content

Commit 37ece36

Browse files
brooksdavisresistor
authored andcommitted
Introduce __CHERI_HYBRID__ macro
This is meant to replace expressions like: __has_feature(capabilities) && !defined(__CHERI_PURE_CAPABILITY__) or (currently( __CHERI__ && !defined(__CHERI_PURE_CAPABILITY__)
1 parent 559eeb0 commit 37ece36

File tree

6 files changed

+17
-3
lines changed

6 files changed

+17
-3
lines changed

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
11481148
if (LangOpts.getCheriBounds() > LangOptions::CBM_Conservative)
11491149
Builder.defineMacro("__CHERI_SUBOBJECT_BOUNDS__",
11501150
Twine(LangOpts.getCheriBounds()));
1151+
} else {
1152+
Builder.defineMacro("__CHERI_HYBRID__");
11511153
}
11521154
}
11531155

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// PURECAP: #define __CHERI_PURE_CAPABILITY__ 2
4040
// MIPS-NOT: __CHERI_PURE_CAPABILITY__
4141
// CHECK: #define __CHERI__ 1
42+
// MIPS: #define __CHERI_HYBRID__ 1
4243
// Note: 64-bit range for intcap makes more sense than the full range for pointers
4344
// CHECK: #define __INTCAP_MAX__ 9223372036854775807L
4445

clang/test/Preprocessor/cheri-features.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ void* __capability y = 0;
3232
// CHECK-MIPS: warning: __CHERI__ not defined
3333
#endif
3434

35+
#if defined(__CHERI_HYBRID__)
36+
#pragma message("__CHERI_HYBRID__ defined")
37+
// CHECK-CHERI: warning: __CHERI_HYBRID__ defined
38+
void* __capability y = 0;
39+
#else
40+
#pragma message("__CHERI_HYBRID__ not defined")
41+
// CHECK-MIPS: warning: __CHERI_HYBRID__ not defined
42+
#endif
43+
3544
int main() {
3645
return 0;
3746
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// CHECK: #define __CHERI_CAP_PERMISSION_PERMIT_STORE__ 8
2020
// CHECK: #define __CHERI_CAP_PERMISSION_PERMIT_UNSEAL__ 512
2121
// CHECK: #define __CHERI__ 1
22+
// CHECK: #define __CHERI_HYBRID__ 1
2223
// CHECK32: #define __SIZEOF_CHERI_CAPABILITY__ 8
2324
// CHECK64: #define __SIZEOF_CHERI_CAPABILITY__ 16
2425
// __VERSION__ and __clang_version__ could contain CHERI due to the Git URL.

clang/test/Preprocessor/init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@
435435
// CHERI-COMMON-NEXT: #define __CHERI_CAP_PERMISSION_PERMIT_STORE__ 8
436436
// CHERI-COMMON-NEXT: #define __CHERI_CAP_PERMISSION_PERMIT_UNSEAL__ 512
437437
// CHERI-COMMON-NEXT: #define __CHERI__ 1
438+
// CHERI-COMMON-NEXT: #define __CHERI_HYBRID__ 1
438439
// CHERI64: #define __POINTER_WIDTH__ 32
439440
// CHERI128: #define __POINTER_WIDTH__ 64
440441
// CHERI-COMMON-NEXT: #define __PRAGMA_REDEFINE_EXTNAME 1

libcxx/test/std/utilities/function.objects/unord.hash/integral.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ int main(int, char**)
126126
test<__uint128_t>();
127127
#endif
128128

129-
#if defined(__CHERI__) && !defined(__CHERI_PURE_CAPABILITY__)
130-
test<__intcap_t>();
131-
test<__uintcap_t>();
129+
#ifdef __CHERI_HYBRID__
130+
test<__intcap_t>();
131+
test<__uintcap_t>();
132132
#endif
133133

134134
return 0;

0 commit comments

Comments
 (0)