annotate clang/test/Analysis/PR24184.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // UNSUPPORTED: z3
anatofuz
parents:
diff changeset
2 // RUN: %clang_analyze_cc1 -w -fcxx-exceptions -analyzer-checker=core -analyzer-checker=alpha.core.PointerArithm,alpha.core.CastToStruct -analyzer-max-loop 64 -verify %s
anatofuz
parents:
diff changeset
3 // RUN: %clang_analyze_cc1 -w -analyzer-checker=core -analyzer-checker=cplusplus -fcxx-exceptions -analyzer-checker alpha.core.PointerArithm,alpha.core.CastToStruct -analyzer-max-loop 63 -verify %s
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 // These tests used to hit an assertion in the bug report. Test case from http://llvm.org/PR24184.
anatofuz
parents:
diff changeset
6 typedef struct {
anatofuz
parents:
diff changeset
7 int cbData;
anatofuz
parents:
diff changeset
8 unsigned pbData;
anatofuz
parents:
diff changeset
9 } CRYPT_DATA_BLOB;
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 typedef enum { DT_NONCE_FIXED } DATA_TYPE;
anatofuz
parents:
diff changeset
12 int a;
anatofuz
parents:
diff changeset
13 typedef int *vcreate_t(int *, DATA_TYPE, int, int);
anatofuz
parents:
diff changeset
14 void fn1(unsigned, unsigned) {
anatofuz
parents:
diff changeset
15 char b = 0;
anatofuz
parents:
diff changeset
16 for (; 1; a++, &b + a * 0)
anatofuz
parents:
diff changeset
17 ;
anatofuz
parents:
diff changeset
18 }
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 vcreate_t fn2;
anatofuz
parents:
diff changeset
21 struct A {
anatofuz
parents:
diff changeset
22 CRYPT_DATA_BLOB value;
anatofuz
parents:
diff changeset
23 int m_fn1() {
anatofuz
parents:
diff changeset
24 int c;
anatofuz
parents:
diff changeset
25 value.pbData == 0;
anatofuz
parents:
diff changeset
26 fn1(0, 0);
anatofuz
parents:
diff changeset
27 }
anatofuz
parents:
diff changeset
28 };
anatofuz
parents:
diff changeset
29 struct B {
anatofuz
parents:
diff changeset
30 A IkeHashAlg;
anatofuz
parents:
diff changeset
31 A IkeGType;
anatofuz
parents:
diff changeset
32 A NoncePhase1_r;
anatofuz
parents:
diff changeset
33 };
anatofuz
parents:
diff changeset
34 class C {
anatofuz
parents:
diff changeset
35 int m_fn2(B *);
anatofuz
parents:
diff changeset
36 void m_fn3(B *, int, int, int);
anatofuz
parents:
diff changeset
37 };
anatofuz
parents:
diff changeset
38 int C::m_fn2(B *p1) {
anatofuz
parents:
diff changeset
39 int *d;
anatofuz
parents:
diff changeset
40 int e = p1->IkeHashAlg.m_fn1();
anatofuz
parents:
diff changeset
41 unsigned f = p1->IkeGType.m_fn1(), h;
anatofuz
parents:
diff changeset
42 int g;
anatofuz
parents:
diff changeset
43 d = fn2(0, DT_NONCE_FIXED, (char)0, p1->NoncePhase1_r.value.cbData);
anatofuz
parents:
diff changeset
44 h = 0 | 0;
anatofuz
parents:
diff changeset
45 m_fn3(p1, 0, 0, 0);
anatofuz
parents:
diff changeset
46 }
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 // case 2:
anatofuz
parents:
diff changeset
49 typedef struct {
anatofuz
parents:
diff changeset
50 int cbData;
anatofuz
parents:
diff changeset
51 unsigned char *pbData;
anatofuz
parents:
diff changeset
52 } CRYPT_DATA_BLOB_1;
anatofuz
parents:
diff changeset
53 typedef unsigned uint32_t;
anatofuz
parents:
diff changeset
54 void fn1_1(void *p1, const void *p2) { p1 != p2; }
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 void fn2_1(uint32_t *p1, unsigned char *p2, uint32_t p3) {
anatofuz
parents:
diff changeset
57 unsigned i = 0;
anatofuz
parents:
diff changeset
58 for (0; i < p3; i++)
anatofuz
parents:
diff changeset
59 fn1_1(p1 + i, p2 + i * 0);
anatofuz
parents:
diff changeset
60 }
anatofuz
parents:
diff changeset
61
anatofuz
parents:
diff changeset
62 struct A_1 {
anatofuz
parents:
diff changeset
63 CRYPT_DATA_BLOB_1 value;
anatofuz
parents:
diff changeset
64 uint32_t m_fn1() {
anatofuz
parents:
diff changeset
65 uint32_t a;
anatofuz
parents:
diff changeset
66 if (value.pbData)
anatofuz
parents:
diff changeset
67 fn2_1(&a, value.pbData, value.cbData);
anatofuz
parents:
diff changeset
68 return 0;
anatofuz
parents:
diff changeset
69 }
anatofuz
parents:
diff changeset
70 };
anatofuz
parents:
diff changeset
71 struct {
anatofuz
parents:
diff changeset
72 A_1 HashAlgId;
anatofuz
parents:
diff changeset
73 } *b;
anatofuz
parents:
diff changeset
74 void fn3() {
anatofuz
parents:
diff changeset
75 uint32_t c, d;
anatofuz
parents:
diff changeset
76 d = b->HashAlgId.m_fn1();
anatofuz
parents:
diff changeset
77 d << 0 | 0 | 0;
anatofuz
parents:
diff changeset
78 c = 0;
anatofuz
parents:
diff changeset
79 0 | 1 << 0 | 0 && b;
anatofuz
parents:
diff changeset
80 }
anatofuz
parents:
diff changeset
81
anatofuz
parents:
diff changeset
82 // case 3:
anatofuz
parents:
diff changeset
83 struct ST {
anatofuz
parents:
diff changeset
84 char c;
anatofuz
parents:
diff changeset
85 };
anatofuz
parents:
diff changeset
86 char *p;
anatofuz
parents:
diff changeset
87 int foo1(ST);
anatofuz
parents:
diff changeset
88 int foo2() {
anatofuz
parents:
diff changeset
89 ST *p1 = (ST *)(p); // expected-warning{{Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption}}
anatofuz
parents:
diff changeset
90 while (p1->c & 0x0F || p1->c & 0x07)
anatofuz
parents:
diff changeset
91 p1 = p1 + foo1(*p1);
anatofuz
parents:
diff changeset
92 }
anatofuz
parents:
diff changeset
93
anatofuz
parents:
diff changeset
94 int foo3(int *node) {
anatofuz
parents:
diff changeset
95 int i = foo2();
anatofuz
parents:
diff changeset
96 if (i)
anatofuz
parents:
diff changeset
97 return foo2();
anatofuz
parents:
diff changeset
98 }