Skip to content

Commit

Permalink
Extend the __capability qualifier tests for typeof() and decltype()
Browse files Browse the repository at this point in the history
This exposed a new crash: CTSRD-CHERI#710
  • Loading branch information
arichardson committed Jul 6, 2023
1 parent 8f70491 commit 3baec7f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
25 changes: 23 additions & 2 deletions clang/test/Sema/cheri/cheri-capability-qualifier-declspec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
// RUN: %cheri_cc1 -o - %s -fsyntax-only -verify
// RUN: %cheri_cc1 %s -fsyntax-only -verify
// expected-no-diagnostics

void * __capability test_typeof(void *p) {
void *__capability test_typeof(void *p) {
__typeof__(p) __capability c = (__cheri_tocap __typeof__(p) __capability)p;
_Static_assert(__builtin_types_compatible_p(typeof(c), void *__capability), "");
__capability __typeof__(p) c2 = (__cheri_tocap __capability __typeof__(p))p;
_Static_assert(__builtin_types_compatible_p(typeof(c2), void *__capability), "");
__capability __typeof__(p) *__capability c3 = (__cheri_tocap __capability __typeof__(p) *__capability)p;
_Static_assert(__builtin_types_compatible_p(typeof(c3), void *__capability *__capability), "");
return c;
}

static int *global_intptr = 0;
static __capability typeof(global_intptr) global_intcap = 0;
_Static_assert(__builtin_types_compatible_p(typeof(global_intptr), int *), "");
_Static_assert(__builtin_types_compatible_p(typeof(global_intcap), int *__capability), "");

/// Crash reproducer for https://github.com/CTSRD-CHERI/llvm-project/issues/710
// RUN: not --crash %cheri_cc1 %s -fsyntax-only -verify -DCRASH
// REQUIRES: asserts
#ifdef CRASH
struct s { int i; };
static struct s *global_sptr = 0;
static __capability typeof(global_sptr) global_scap = 0;
_Static_assert(__builtin_types_compatible_p(typeof(global_sptr), struct s *), "");
_Static_assert(__builtin_types_compatible_p(typeof(global_scap), struct s *__capability), "");
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@

void * __capability test_decltype(void *p) {
decltype(p) __capability c = (__cheri_tocap decltype(p) __capability)p;
static_assert(__is_same(typeof(c)*, void * __capability *), "");
static_assert(__is_same(decltype(c) & __capability, void*__capability & __capability), "");
void *__capability &cref = c;
static_assert(__is_same(decltype(cref) __capability, void *__capability & __capability), "");
static_assert(__is_same(__capability decltype(cref), void *__capability & __capability), "");

using intref = int&;
static_assert(__is_same(intref __capability, int& __capability), "");
static_assert(__is_same(__capability intref, int& __capability), "");
return c;
}

0 comments on commit 3baec7f

Please sign in to comment.