1 // RUN: %riscv64_cheri_cc1 -fsyntax-only -verify=expected,hybrid %s
2 // RUN: %riscv64_cheri_purecap_cc1 -fsyntax-only -verify=expected,purecap %s
3
4 int printf(const char *restrict, ...);
5
test_plain_pointer(void * p)6 void test_plain_pointer(void *p) {
7 printf("%#p", p);
8 printf("%.4p", p); // expected-warning{{precision used with 'p' conversion specifier, resulting in undefined behavior}}
9 printf("%#.4p", p);
10 }
11
test_long_pointer(void * __capability p)12 void test_long_pointer(void * __capability p) {
13 printf("%lp", p);
14 printf("%#lp", p);
15 printf("%.4lp", p); // expected-warning{{precision used with 'p' conversion specifier, resulting in undefined behavior}}
16 printf("%#.4lp", p);
17 printf("%lp", &p); // hybrid-warning{{format specifies type 'void * __capability' but the argument has type 'void * __capability *'}}
18 printf("%lp", (void *)0); // hybrid-warning{{format specifies type 'void * __capability' but the argument has type 'void *'}}
19 printf("%lp", (void **)(void *)0); // hybrid-warning{{format specifies type 'void * __capability' but the argument has type 'void **'}}
20 printf("%lp", (int *)(void *)0); // hybrid-warning{{format specifies type 'void * __capability' but the argument has type 'int *'}}
21 }
22
test_invalid_length_modifiers(void * p)23 void test_invalid_length_modifiers(void *p) {
24 printf("%hhp", p); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 'p' conversion specifier}}
25 printf("%hp", p); // expected-warning{{length modifier 'h' results in undefined behavior or no effect with 'p' conversion specifier}}
26 printf("%llp", p); // expected-warning{{length modifier 'll' results in undefined behavior or no effect with 'p' conversion specifier}}
27 printf("%jp", p); // expected-warning{{length modifier 'j' results in undefined behavior or no effect with 'p' conversion specifier}}
28 printf("%tp", p); // expected-warning{{length modifier 't' results in undefined behavior or no effect with 'p' conversion specifier}}
29 printf("%zp", p); // expected-warning{{length modifier 'z' results in undefined behavior or no effect with 'p' conversion specifier}}
30 printf("%qp", p); // expected-warning{{length modifier 'q' results in undefined behavior or no effect with 'p' conversion specifier}}
31 }
32