Clang Project

clang_source_code/test/Sema/attr-nocf_check.c
1// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -verify -fcf-protection=branch -fsyntax-only %s
2
3// Function pointer definition.
4typedef void (*FuncPointerWithNoCfCheck)(void) __attribute__((nocf_check)); // no-warning
5typedef void (*FuncPointer)(void);
6
7// Dont allow function declaration and definition mismatch.
8void __attribute__((nocf_check)) testNoCfCheck();   // expected-note {{previous declaration is here}}
9void testNoCfCheck(){}; //  expected-error {{conflicting types for 'testNoCfCheck'}}
10
11// No variable or parameter declaration
12__attribute__((nocf_check)) int i;                              // expected-warning {{'nocf_check' attribute only applies to function}}
13void testNoCfCheckImpl(double __attribute__((nocf_check)) i) {} // expected-warning {{'nocf_check' attribute only applies to function}}
14
15// Allow attributed function pointers as well as casting between attributed
16// and non-attributed function pointers.
17void testNoCfCheckMismatch(FuncPointer f) {
18  FuncPointerWithNoCfCheck fNoCfCheck = f; // expected-warning {{incompatible function pointer types}}
19  (*fNoCfCheck)();                         // no-warning
20}
21
22// 'nocf_check' Attribute has no parameters.
23int testNoCfCheckParams() __attribute__((nocf_check(1))); // expected-error {{'nocf_check' attribute takes no arguments}}
24