Clang Project

clang_source_code/test/Sema/format-strings-bitfield-promotion.c
1// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
2// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only -verify %s
3
4int printf(const char *restrict, ...);
5
6struct bitfields {
7  long a : 2;
8  unsigned long b : 2;
9  long c : 32;          // assumes that int is 32 bits
10  unsigned long d : 32; // assumes that int is 32 bits
11} bf;
12
13void bitfield_promotion() {
14  printf("%ld", bf.a); // expected-warning {{format specifies type 'long' but the argument has type 'int'}}
15  printf("%lu", bf.b); // expected-warning {{format specifies type 'unsigned long' but the argument has type 'int'}}
16  printf("%ld", bf.c); // expected-warning {{format specifies type 'long' but the argument has type 'int'}}
17  printf("%lu", bf.d); // expected-warning {{format specifies type 'unsigned long' but the argument has type 'unsigned int'}}
18}
19