brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · bccdfc4 Raw
61 lines · c
1// RUN: %clang_cc1 -std=c11 -fsyntax-only -fsanitize=kcfi -verify %s2// RUN: %clang_cc1 -std=c89 -DKNR -fsyntax-only -fsanitize=kcfi -verify %s3 4#define __cfi_salt(S) __attribute__((cfi_salt(S)))5 6int bad1(void) __cfi_salt(); // expected-error{{'cfi_salt' attribute takes one argument}}7int bad2(void) __cfi_salt(42); // expected-error{{expected string literal as argument of 'cfi_salt' attribute}}8int bad3(void) __attribute__((cfi_salt("a", "b", "c"))); // expected-error{{'cfi_salt' attribute takes one argument}}9 10 11int foo(int a, int b) __cfi_salt("pepper"); // ok12int foo(int a, int b) __cfi_salt("pepper"); // ok13 14#ifndef KNR15typedef int (*bar_t)(void) __cfi_salt("pepper"); // ok16typedef int (*bar_t)(void) __cfi_salt("pepper"); // ok17#endif18 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 23int baz __cfi_salt("salt"); // expected-warning{{'cfi_salt' only applies to function types}}24 25int baz_fn(int a, int b) __cfi_salt("salt 'n"); // expected-note{{previous declaration is here}}26int baz_fn(int a, int b) __cfi_salt("pepper"); // expected-error{{conflicting types for 'baz_fn'}}27 28int mux_fn(int a, int b) __cfi_salt("salt 'n"); // expected-note{{previous declaration is here}}29int mux_fn(int a, int b) __cfi_salt("pepper") { // expected-error{{conflicting types for 'mux_fn'}}30  return a * b;31}32 33typedef int qux_t __cfi_salt("salt"); // expected-warning{{'cfi_salt' only applies to function types}}34 35typedef int (*quux_t)(void) __cfi_salt("salt 'n"); // expected-note{{previous definition is here}}36typedef int (*quux_t)(void) __cfi_salt("pepper"); // expected-error{{typedef redefinition with different type}}37 38void func1(int a) __cfi_salt("pepper"); // expected-note{{previous declaration is here}}39void func1(int a) { } // expected-error{{conflicting types for 'func1'}}40void (*fp1)(int) = func1; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}41 42void func2(int) [[clang::cfi_salt("test")]]; // expected-note{{previous declaration is here}}43void func2(int a) { } // expected-error{{conflicting types for 'func2'}}44void (*fp2)(int) = func2; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}45 46void func3(int) __cfi_salt("pepper"); // ok47void func3(int a) __cfi_salt("pepper") { } // ok48void (* __cfi_salt("pepper") fp3)(int) = func3; // ok49void (*fp3_noattr)(int) = func3; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}50 51void func4(int) [[clang::cfi_salt("test")]]; // ok52void func4(int a) [[clang::cfi_salt("test")]] { } // ok53void (* [[clang::cfi_salt("test")]] fp4)(int) = func4; // ok54void (*fp4_noattr)(int) = func4; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}55 56#ifdef KNR57// K&R C function without a prototype58void func() __attribute__((cfi_salt("pepper"))); // expected-error {{attribute only applies to non-K&R-style functions}}59void (*fp)() __attribute__((cfi_salt("pepper")));  // expected-error {{attribute only applies to non-K&R-style functions}}60#endif61