| 1 |
// RUN: %clang_cc1 -std=c11 -fsyntax-only -fsanitize=kcfi -verify %s |
| 2 |
// RUN: %clang_cc1 -std=c89 -DKNR -fsyntax-only -fsanitize=kcfi -verify %s |
| 3 |
|
| 4 |
#define __cfi_salt(S) __attribute__((cfi_salt(S))) |
| 5 |
|
| 6 |
int bad1(void) __cfi_salt(); // expected-error{{'cfi_salt' attribute takes one argument}} |
| 7 |
int bad2(void) __cfi_salt(42); // expected-error{{expected string literal as argument of 'cfi_salt' attribute}} |
| 8 |
int bad3(void) __attribute__((cfi_salt("a", "b", "c"))); // expected-error{{'cfi_salt' attribute takes one argument}} |
| 9 |
|
| 10 |
|
| 11 |
int foo(int a, int b) __cfi_salt("pepper"); // ok |
| 12 |
int foo(int a, int b) __cfi_salt("pepper"); // ok |
| 13 |
|
| 14 |
#ifndef KNR |
| 15 |
typedef int (*bar_t)(void) __cfi_salt("pepper"); // ok |
| 16 |
typedef int (*bar_t)(void) __cfi_salt("pepper"); // ok |
| 17 |
#endif |
| 18 |
|
| 19 |
// FIXME: Should we allow this? |
| 20 |
// int b(void) __cfi_salt("salt 'n") __cfi_salt("pepper"); |
| 21 |
// bar_t bar_fn __cfi_salt("salt 'n"); |
| 22 |
|
| 23 |
int baz __cfi_salt("salt"); // expected-warning{{'cfi_salt' only applies to function types}} |
| 24 |
|
| 25 |
int baz_fn(int a, int b) __cfi_salt("salt 'n"); // expected-note{{previous declaration is here}} |
| 26 |
int baz_fn(int a, int b) __cfi_salt("pepper"); // expected-error{{conflicting types for 'baz_fn'}} |
| 27 |
|
| 28 |
int mux_fn(int a, int b) __cfi_salt("salt 'n"); // expected-note{{previous declaration is here}} |
| 29 |
int mux_fn(int a, int b) __cfi_salt("pepper") { // expected-error{{conflicting types for 'mux_fn'}} |
| 30 |
return a * b; |
| 31 |
} |
| 32 |
|
| 33 |
typedef int qux_t __cfi_salt("salt"); // expected-warning{{'cfi_salt' only applies to function types}} |
| 34 |
|
| 35 |
typedef int (*quux_t)(void) __cfi_salt("salt 'n"); // expected-note{{previous definition is here}} |
| 36 |
typedef int (*quux_t)(void) __cfi_salt("pepper"); // expected-error{{typedef redefinition with different type}} |
| 37 |
|
| 38 |
void func1(int a) __cfi_salt("pepper"); // expected-note{{previous declaration is here}} |
| 39 |
void func1(int a) { } // expected-error{{conflicting types for 'func1'}} |
| 40 |
void (*fp1)(int) = func1; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}} |
| 41 |
|
| 42 |
void func2(int) [[clang::cfi_salt("test")]]; // expected-note{{previous declaration is here}} |
| 43 |
void func2(int a) { } // expected-error{{conflicting types for 'func2'}} |
| 44 |
void (*fp2)(int) = func2; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}} |
| 45 |
|
| 46 |
void func3(int) __cfi_salt("pepper"); // ok |
| 47 |
void func3(int a) __cfi_salt("pepper") { } // ok |
| 48 |
void (* __cfi_salt("pepper") fp3)(int) = func3; // ok |
| 49 |
void (*fp3_noattr)(int) = func3; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}} |
| 50 |
|
| 51 |
void func4(int) [[clang::cfi_salt("test")]]; // ok |
| 52 |
void func4(int a) [[clang::cfi_salt("test")]] { } // ok |
| 53 |
void (* [[clang::cfi_salt("test")]] fp4)(int) = func4; // ok |
| 54 |
void (*fp4_noattr)(int) = func4; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}} |
| 55 |
|
| 56 |
#ifdef KNR |
| 57 |
// K&R C function without a prototype |
| 58 |
void func() __attribute__((cfi_salt("pepper"))); // expected-error {{attribute only applies to non-K&R-style functions}} |
| 59 |
void (*fp)() __attribute__((cfi_salt("pepper"))); // expected-error {{attribute only applies to non-K&R-style functions}} |
| 60 |
#endif |