brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 2a94df0 Raw
54 lines · c
1// RUN: %clang_cc1 -Wformat %s -verify2// RUN: %clang_cc1 -Wformat -std=c23 %s -verify3// RUN: %clang_cc1 -xc++ -Wformat %s -verify4// RUN: %clang_cc1 -xobjective-c -Wformat -fblocks %s -verify5// RUN: %clang_cc1 -xobjective-c++ -Wformat -fblocks %s -verify6// RUN: %clang_cc1 -std=c23 -Wformat %s -pedantic -verify=expected,pedantic7// RUN: %clang_cc1 -xc++ -Wformat %s -pedantic -verify=expected,pedantic8// RUN: %clang_cc1 -xobjective-c -Wformat -fblocks -pedantic %s -verify=expected,pedantic9 10__attribute__((__format__(__printf__, 1, 2)))11int printf(const char *, ...);12__attribute__((__format__(__scanf__, 1, 2)))13int scanf(const char *, ...);14 15void f(void *vp, const void *cvp, char *cp, signed char *scp, int *ip) {16  int arr[2];17 18  printf("%p", cp);19  printf("%p", cvp);20  printf("%p", vp);21  printf("%p", scp);22  printf("%p", ip); // pedantic-warning {{format specifies type 'void *' but the argument has type 'int *'}}23  printf("%p", arr); // pedantic-warning {{format specifies type 'void *' but the argument has type 'int *'}}24 25  scanf("%p", &vp);26  scanf("%p", &cvp);27  scanf("%p", (void *volatile*)&vp);28  scanf("%p", (const void *volatile*)&cvp);29  scanf("%p", &cp); // pedantic-warning {{format specifies type 'void **' but the argument has type 'char **'}}30  scanf("%p", &ip); // pedantic-warning {{format specifies type 'void **' but the argument has type 'int **'}}31  scanf("%p", &arr); // expected-warning {{format specifies type 'void **' but the argument has type 'int (*)[2]'}}32 33#if !__is_identifier(nullptr)34  typedef __typeof__(nullptr) nullptr_t;35  nullptr_t np = nullptr;36  nullptr_t *npp = &np;37 38  printf("%p", np);39  scanf("%p", &np); // expected-warning {{format specifies type 'void **' but the argument has type 'nullptr_t *'}}40  scanf("%p", &npp); // pedantic-warning {{format specifies type 'void **' but the argument has type 'nullptr_t **'}}41#endif42 43#ifdef __OBJC__44  id i = 0;45  void (^b)(void) = ^{};46 47  printf("%p", i); // pedantic-warning {{format specifies type 'void *' but the argument has type 'id'}}48  printf("%p", b); // pedantic-warning {{format specifies type 'void *' but the argument has type 'void (^)(void)'}}49  scanf("%p", &i); // pedantic-warning {{format specifies type 'void **' but the argument has type 'id *'}}50  scanf("%p", &b); // pedantic-warning {{format specifies type 'void **' but the argument has type 'void (^*)(void)'}}51#endif52 53}54