brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · b4de356 Raw
57 lines · c
1// RUN: %clang_cc1 -fsyntax-only %s -std=c99 -verify=expected2// RUN: %clang_cc1 -fsyntax-only %s -std=c11 -verify=expected3// RUN: %clang_cc1 -fsyntax-only %s -std=c23 -verify=expected,proto4 5// This verifies that -Wincompatible-function-pointer-type diagnostics for6// extended function type information are consistent, also in case of other7// allowed funcion type difference in C.8//9// Test case adapted from issue #41465, with suggestions from PR #160477.10 11enum E { A = -1, B };12 13// Case 1: assignment adding noreturn14 15int      f1   (int);16int    (*fp1a)(int) __attribute__((noreturn)) = &f1; // expected-error {{incompatible function pointer types}}17enum E (*fp1b)(int) __attribute__((noreturn)) = &f1; // expected-error {{incompatible function pointer types}}18int    (*fp1c)()    __attribute__((noreturn)) = &f1; // expected-error {{incompatible function pointer types}}19 20// Case 2: assignment adding noescape on arg21 22int   f2   (int*                          ) __attribute__((noreturn));23int (*fp2a)(int* __attribute__((noescape))) __attribute__((noreturn)) = &f2; // expected-error {{incompatible function pointer types}}24int (*fp2b)(int* __attribute__((noescape)))                           = &f2; // expected-error {{incompatible function pointer types}}25 26// Case 3: assignment adding cfi_unchecked_callee27 28int   f3   (int*                          );29int (*fp3a)(int*                          ) __attribute__((noreturn                     )) = &f3; // expected-error {{incompatible function pointer types}}30int (*fp3b)(int* __attribute__((noescape)))                                                = &f3; // expected-error {{incompatible function pointer types}}31int (*fp3c)(int*                          ) __attribute__((noreturn,cfi_unchecked_callee)) = &f3; // expected-error {{incompatible function pointer types}}32int (*fp3d)(int* __attribute__((noescape))) __attribute__((         cfi_unchecked_callee)) = &f3; // expected-error {{incompatible function pointer types}}33int (*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-prototype36 37void p1(void);38void i1(int );39void n1(    );40void p2(void) __attribute__((noreturn));41void i2(int ) __attribute__((noreturn));42void n2(    ) __attribute__((noreturn));43 44void (*t1)() = p1;45void (*t2)() = i1; // proto-error {{incompatible function pointer types}}46void (*t3)() = n1;47void (*t4)() __attribute__((noreturn)) = p1; // expected-error {{incompatible function pointer types}}48void (*t5)() __attribute__((noreturn)) = i1; // expected-error {{incompatible function pointer types}}49void (*t6)() __attribute__((noreturn)) = n1; // expected-error {{incompatible function pointer types}}50 51void (*t7)() = p2;52void (*t8)() = i2; // proto-error {{incompatible function pointer types}}53void (*t9)() = n2;54void (*tA)() __attribute__((noreturn)) = p2;55void (*tB)() __attribute__((noreturn)) = i2; // proto-error {{incompatible function pointer types}}56void (*tC)() __attribute__((noreturn)) = n2;57