brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · 889c106 Raw
72 lines · c
1// RUN: %clang_cc1 -Wall -Wno-unused -Wno-uninitialized -verify %s2 3#define CFI_UNCHECKED_CALLEE __attribute__((cfi_unchecked_callee))4 5void unchecked(void) CFI_UNCHECKED_CALLEE {}6void checked(void) {}7 8void (*checked_ptr)(void) = unchecked;  // expected-warning{{implicit conversion from 'void (void) __attribute__((cfi_unchecked_callee))' to 'void (*)(void)' discards 'cfi_unchecked_callee' attribute}}9void (CFI_UNCHECKED_CALLEE *unchecked_ptr)(void) = unchecked;10void (CFI_UNCHECKED_CALLEE *from_normal)(void) = checked;11void (CFI_UNCHECKED_CALLEE *c_no_function_decay)(void) = &unchecked;12 13typedef void (CFI_UNCHECKED_CALLEE unchecked_func_t)(void);14typedef void (checked_func_t)(void);15typedef void (CFI_UNCHECKED_CALLEE *cfi_unchecked_func_ptr_t)(void);16typedef void (*checked_func_ptr_t)(void);17checked_func_t *cfi_func = unchecked;  // expected-warning{{implicit conversion from 'void (void) __attribute__((cfi_unchecked_callee))' to 'void (*)(void)' discards 'cfi_unchecked_callee' attribute}}18unchecked_func_t *unchecked_func = unchecked;19 20void CFI_UNCHECKED_CALLEE after_ret_type(void);21CFI_UNCHECKED_CALLEE void before_ret_type(void);22void (* CFI_UNCHECKED_CALLEE after_name)(void);23 24void UsageOnImproperTypes() {25  int CFI_UNCHECKED_CALLEE i;  // expected-warning{{'cfi_unchecked_callee' only applies to function types; type here is 'int'}}26 27  /// The attribute must be used only on functions with prototypes. The omission of `void` means it is not prototyped.28  void (CFI_UNCHECKED_CALLEE *noproto)(void);  // expecteed-warning{{'cfi_unchecked_callee' attribute only applies to non-K&R-style functions}}29}30 31/// Explicit casts suppress the warning.32void CheckCasts() {33  void (*should_warn)(void) = unchecked;  // expected-warning{{implicit conversion from 'void (void) __attribute__((cfi_unchecked_callee))' to 'void (*)(void)' discards 'cfi_unchecked_callee' attribute}}34 35  void (*no_warn_c_style_cast)(void) = (void (*)(void))unchecked;36 37  struct B {} CFI_UNCHECKED_CALLEE b;  // expected-warning{{'cfi_unchecked_callee' attribute only applies to functions and methods}}38  struct CFI_UNCHECKED_CALLEE C {} c;  // expected-warning{{'cfi_unchecked_callee' attribute only applies to functions and methods}}39  CFI_UNCHECKED_CALLEE struct D {} d;  // expected-warning{{'cfi_unchecked_callee' only applies to function types; type here is 'struct D'}}40 41  void *ptr2 = (void *)unchecked;42}43 44int checked_arg_func(checked_func_t *checked_func);45 46void CheckDifferentConstructions() {47  void (CFI_UNCHECKED_CALLEE *arr[10])(void);48  void (*cfi_elem)(void) = arr[1];  // expected-warning{{implicit conversion from 'void (*)(void) __attribute__((cfi_unchecked_callee))' to 'void (*)(void)' discards 'cfi_unchecked_callee' attribute}}49  void (CFI_UNCHECKED_CALLEE *cfi_unchecked_elem)(void) = arr[1];50 51  int invoke = checked_arg_func(unchecked);  // expected-warning{{implicit conversion from 'void (void) __attribute__((cfi_unchecked_callee))' to 'void (*)(void)' discards 'cfi_unchecked_callee' attribute}}52}53 54checked_func_t *returning_checked_func() {55  return unchecked;  // expected-warning{{implicit conversion from 'void (void) __attribute__((cfi_unchecked_callee))' to 'void (*)(void)' discards 'cfi_unchecked_callee' attribute}}56}57 58void no_args(void) __attribute__((cfi_unchecked_callee(10)));  // expected-error{{'cfi_unchecked_callee' attribute takes no arguments}}59 60void Comparisons() {61  /// Let's be able to compare checked and unchecked pointers without warnings.62  unchecked == checked_ptr;63  checked_ptr == unchecked;64  unchecked == unchecked_ptr;65  unchecked != checked_ptr;66  checked_ptr != unchecked;67  unchecked != unchecked_ptr;68 69  (void (*)(void))unchecked == checked_ptr;70  checked_ptr == (void (*)(void))unchecked;71}72