Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / array-punned-region.c
blobd319fd7367ec5b014cfd9aab43d6d5691948a16e
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false -triple x86_64-pc-linux-gnu %s
3 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false -triple i386-pc-linux-gnu %s
5 int clang_analyzer_eval(int);
7 typedef struct {
8 int a : 1;
9 int b[2];
10 } BITFIELD_CAST;
12 void array_struct_bitfield_1() {
13 BITFIELD_CAST ff = {0};
14 BITFIELD_CAST *pff = &ff;
15 clang_analyzer_eval(*((int *)pff + 1) == 0); // expected-warning{{TRUE}}
16 ff.b[0] = 3;
17 clang_analyzer_eval(*((int *)pff + 1) == 3); // expected-warning{{TRUE}}
20 int array_struct_bitfield_2() {
21 BITFIELD_CAST ff = {0};
22 BITFIELD_CAST *pff = &ff;
23 int a = *((int *)pff + 2); // expected-warning{{Assigned value is garbage or undefined [core.uninitialized.Assign]}}
24 return a;
27 typedef struct {
28 unsigned int a : 1;
29 unsigned int x : 31;
30 unsigned int c : 1;
31 int b[2];
32 } mystruct;
34 void array_struct_bitfield_3() {
35 mystruct ff;
36 mystruct *pff = &ff;
37 ff.b[0] = 3;
38 clang_analyzer_eval(*((int *)pff + 2) == 3); // expected-warning{{TRUE}}