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