| 1 |
// RUN: %clang_cc1 -fsyntax-only %s -std=c99 -verify=expected |
| 2 |
// RUN: %clang_cc1 -fsyntax-only %s -std=c11 -verify=expected |
| 3 |
// RUN: %clang_cc1 -fsyntax-only %s -std=c23 -verify=expected,proto |
| 4 |
|
| 5 |
// This verifies that -Wincompatible-function-pointer-type diagnostics for |
| 6 |
// extended function type information are consistent, also in case of other |
| 7 |
// allowed funcion type difference in C. |
| 8 |
// |
| 9 |
// Test case adapted from issue #41465, with suggestions from PR #160477. |
| 10 |
|
| 11 |
enum E { A = -1, B }; |
| 12 |
|
| 13 |
// Case 1: assignment adding noreturn |
| 14 |
|
| 15 |
int f1 (int); |
| 16 |
int (*fp1a)(int) __attribute__((noreturn)) = &f1; // expected-error {{incompatible function pointer types}} |
| 17 |
enum E (*fp1b)(int) __attribute__((noreturn)) = &f1; // expected-error {{incompatible function pointer types}} |
| 18 |
int (*fp1c)() __attribute__((noreturn)) = &f1; // expected-error {{incompatible function pointer types}} |
| 19 |
|
| 20 |
// Case 2: assignment adding noescape on arg |
| 21 |
|
| 22 |
int f2 (int* ) __attribute__((noreturn)); |
| 23 |
int (*fp2a)(int* __attribute__((noescape))) __attribute__((noreturn)) = &f2; // expected-error {{incompatible function pointer types}} |
| 24 |
int (*fp2b)(int* __attribute__((noescape))) = &f2; // expected-error {{incompatible function pointer types}} |
| 25 |
|
| 26 |
// Case 3: assignment adding cfi_unchecked_callee |
| 27 |
|
| 28 |
int f3 (int* ); |
| 29 |
int (*fp3a)(int* ) __attribute__((noreturn )) = &f3; // expected-error {{incompatible function pointer types}} |
| 30 |
int (*fp3b)(int* __attribute__((noescape))) = &f3; // expected-error {{incompatible function pointer types}} |
| 31 |
int (*fp3c)(int* ) __attribute__((noreturn,cfi_unchecked_callee)) = &f3; // expected-error {{incompatible function pointer types}} |
| 32 |
int (*fp3d)(int* __attribute__((noescape))) __attribute__(( cfi_unchecked_callee)) = &f3; // expected-error {{incompatible function pointer types}} |
| 33 |
int (*fp3e)(int* __attribute__((noescape))) __attribute__((noreturn,cfi_unchecked_callee)) = &f3; // expected-error {{incompatible function pointer types}} |
| 34 |
|
| 35 |
// Case 4: assignment converting between prototype/no-prototype |
| 36 |
|
| 37 |
void p1(void); |
| 38 |
void i1(int ); |
| 39 |
void n1( ); |
| 40 |
void p2(void) __attribute__((noreturn)); |
| 41 |
void i2(int ) __attribute__((noreturn)); |
| 42 |
void n2( ) __attribute__((noreturn)); |
| 43 |
|
| 44 |
void (*t1)() = p1; |
| 45 |
void (*t2)() = i1; // proto-error {{incompatible function pointer types}} |
| 46 |
void (*t3)() = n1; |
| 47 |
void (*t4)() __attribute__((noreturn)) = p1; // expected-error {{incompatible function pointer types}} |
| 48 |
void (*t5)() __attribute__((noreturn)) = i1; // expected-error {{incompatible function pointer types}} |
| 49 |
void (*t6)() __attribute__((noreturn)) = n1; // expected-error {{incompatible function pointer types}} |
| 50 |
|
| 51 |
void (*t7)() = p2; |
| 52 |
void (*t8)() = i2; // proto-error {{incompatible function pointer types}} |
| 53 |
void (*t9)() = n2; |
| 54 |
void (*tA)() __attribute__((noreturn)) = p2; |
| 55 |
void (*tB)() __attribute__((noreturn)) = i2; // proto-error {{incompatible function pointer types}} |
| 56 |
void (*tC)() __attribute__((noreturn)) = n2; |