Skip to content

Commit 02299cb

Browse files
committed
Add test for _Generic, overloadable functions, and arrays
1 parent 636e815 commit 02299cb

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

clang/test/Sema/ptrauth-qualifier.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -verify -fptrauth-intrinsics %s
2-
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fsyntax-only -verify -fptrauth-intrinsics %s
1+
// RUN: %clang_cc1 -triple arm64-apple-ios -std=c23 -fsyntax-only -verify -fptrauth-intrinsics %s
2+
// RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c23 -fsyntax-only -verify -fptrauth-intrinsics %s
33

44
#if __has_feature(ptrauth_qualifier)
55
#warning __ptrauth qualifier enabled!
@@ -15,6 +15,7 @@
1515
#endif
1616

1717
int * __ptrauth(VALID_DATA_KEY) valid0;
18+
int *ptr0;
1819

1920
typedef int *intp;
2021

@@ -45,6 +46,9 @@ int * __ptrauth(VALID_DATA_KEY, (_Bool) 1) valid8;
4546
int * __ptrauth(VALID_DATA_KEY, 1, 0) valid9;
4647
int * __ptrauth(VALID_DATA_KEY, 1, 65535) valid10;
4748

49+
int * __ptrauth(VALID_DATA_KEY) array0[10];
50+
int (* __ptrauth(VALID_DATA_KEY) array1)[10];
51+
4852
extern intp redeclaration0; // expected-note {{previous declaration}}
4953
extern intp __ptrauth(VALID_DATA_KEY) redeclaration0; // expected-error{{redeclaration of 'redeclaration0' with a different type: '__ptrauth(2,0,0) intp' (aka 'int *__ptrauth(2,0,0)') vs 'intp' (aka 'int *')}}
5054

@@ -60,6 +64,14 @@ intp redeclaration3 = 0; // expected-error{{redefinition o
6064
void illegal0(intp __ptrauth(VALID_DATA_KEY)); // expected-error {{parameter type may not be qualified with '__ptrauth'; type is '__ptrauth(2,0,0) intp' (aka 'int *__ptrauth(2,0,0)')}}
6165
intp __ptrauth(VALID_DATA_KEY) illegal1(void); // expected-error {{return type may not be qualified with '__ptrauth'; type is '__ptrauth(2,0,0) intp' (aka 'int *__ptrauth(2,0,0)')}}
6266

67+
static_assert(_Generic(typeof(valid0), int * __ptrauth(VALID_DATA_KEY) : 1, int * : 0, default : 0));
68+
static_assert(_Generic(typeof(valid0), int * __ptrauth(VALID_CODE_KEY) : 0, default : 1));
69+
static_assert(_Generic(typeof_unqual(valid0), int * __ptrauth(VALID_DATA_KEY) : 0, int * : 1, default : 0));
70+
static_assert(_Generic(valid0, int * __ptrauth(VALID_DATA_KEY) : 0, int * : 1, default : 0)); // expected-warning {{association of type 'int *__ptrauth(2,0,0)' will never be selected}}
71+
72+
static_assert(_Generic(array0, int * __ptrauth(VALID_DATA_KEY) * : 1, default : 0));
73+
static_assert(_Generic(*array1, int * : 1, default : 0));
74+
6375
void test_code(intp p) {
6476
p = (intp __ptrauth(VALID_DATA_KEY)) 0; // expected-error {{cannot cast to '__ptrauth'-qualified type '__ptrauth(2,0,0) intp' (aka 'int *__ptrauth(2,0,0)')}}
6577

@@ -81,3 +93,11 @@ void test_array(void) {
8193
intp __ptrauth(VALID_DATA_KEY) *ppSpecial0 = pSpecialArray;
8294
intp __ptrauth(VALID_DATA_KEY) *ppSpecial1 = &pSpecialArray[0];
8395
}
96+
97+
__attribute__((overloadable)) int overload_func(int **);
98+
__attribute__((overloadable)) float overload_func(int * __ptrauth(VALID_DATA_KEY) *);
99+
100+
static_assert(_Generic(typeof(overload_func(&ptr0)), int : 1, default : 0));
101+
static_assert(_Generic(typeof(overload_func(&valid0)), float : 1, default : 0));
102+
103+
void func(int array[__ptrauth(VALID_DATA_KEY) 10]); // expected-error {{'__ptrauth' qualifier only applies to pointer types; 'int[10]' is invalid}}

0 commit comments

Comments
 (0)