Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr113253.c

raw
1 /* Regression test for PR analyzer/113253 which was showing analyzer
2 differences with and without -g.
3
4 C only: reduced reproducer doesn't easily work with C++. */
5
6 /* { dg-additional-options "-O2 -g" } */
7
8 typedef __PTRDIFF_TYPE__ ptrdiff_t;
9 typedef __UINTPTR_TYPE__ uintptr_t;
10 typedef __PTRDIFF_TYPE__ EMACS_INT;
11 enum
12 {
13 EMACS_INT_WIDTH = sizeof(EMACS_INT) * 8,
14 VALBITS = EMACS_INT_WIDTH - 3,
15 };
16 typedef struct Lisp_X* Lisp_Word;
17 enum Lisp_Type
18 {
19 Lisp_Symbol = 0,
20 Lisp_Vectorlike = 5,
21 };
22 typedef Lisp_Word Lisp_Object;
23 static inline EMACS_INT(XLI)(Lisp_Object o)
24 {
25 return ((EMACS_INT)(o));
26 }
27 static inline void*(XLP)(Lisp_Object o)
28 {
29 return ((void*)(o));
30 }
31 struct Lisp_Symbol
32 {};
33 typedef uintptr_t Lisp_Word_tag;
34 extern struct Lisp_Symbol lispsym[1608];
35 union vectorlike_header
36 {
37 ptrdiff_t size;
38 };
39 enum pvec_type
40 {
41 PVEC_MARKER,
42 };
43 enum More_Lisp_Bits
44 {
45 PSEUDOVECTOR_SIZE_BITS = 12,
46 PSEUDOVECTOR_REST_BITS = 12,
47 PSEUDOVECTOR_AREA_BITS = PSEUDOVECTOR_SIZE_BITS + PSEUDOVECTOR_REST_BITS,
48 PVEC_TYPE_MASK = 0x3f << PSEUDOVECTOR_AREA_BITS
49 };
50 static inline _Bool
51 PSEUDOVECTORP(Lisp_Object a, int code)
52 {
53 return (
54 ((((union vectorlike_header*)((uintptr_t)XLP((a)) -
55 (uintptr_t)(
56 (Lisp_Word_tag)(Lisp_Vectorlike)
57 << (((0x7fffffffffffffffL >> (3 - 1)) / 2 <
58 (9223372036854775807L))
59 ? 0
60 : VALBITS))))
61 ->size &
62 (((9223372036854775807L) - (9223372036854775807L) / 2) |
63 PVEC_TYPE_MASK)) ==
64 (((9223372036854775807L) - (9223372036854775807L) / 2) |
65 ((code) << PSEUDOVECTOR_AREA_BITS))));
66 }
67 static inline Lisp_Object
68 make_lisp_symbol(struct Lisp_Symbol* sym)
69 {
70 Lisp_Object a = ((Lisp_Word)(
71 ((Lisp_Word_tag)(Lisp_Symbol)
72 << (((0x7fffffffffffffffL >> (3 - 1)) / 2 < (9223372036854775807L))
73 ? 0
74 : VALBITS))));
75 return a;
76 }
77 static inline Lisp_Object
78 builtin_lisp_symbol(int index)
79 {
80 return make_lisp_symbol(&lispsym[index]);
81 }
82 static inline _Bool(BASE_EQ)(Lisp_Object x, Lisp_Object y)
83 {
84 return (XLI(x) == XLI(y));
85 }
86 static inline _Bool(NILP)(Lisp_Object x)
87 {
88 return BASE_EQ(x, builtin_lisp_symbol(0));
89 }
90 struct thread_state
91 {
92 struct buffer* m_current_buffer;
93 };
94 extern struct thread_state* current_thread;
95 struct Lisp_Marker
96 {
97 struct buffer* buffer;
98 };
99 static inline _Bool
100 MARKERP(Lisp_Object x)
101 {
102 return PSEUDOVECTORP(x, PVEC_MARKER);
103 }
104 static inline struct Lisp_Marker*
105 XMARKER(Lisp_Object a)
106 {
107 return ((
108 struct Lisp_Marker*)((uintptr_t)XLP(a) -
109 (uintptr_t)((Lisp_Word_tag)(Lisp_Vectorlike)
110 << (((0x7fffffffffffffffL >> (3 - 1)) / 2 <
111 (9223372036854775807L))
112 ? 0
113 : VALBITS))));
114 }
115 extern void
116 unchain_marker();
117 struct buffer
118 {
119 Lisp_Object name_;
120 };
121 static inline struct buffer*
122 XBUFFER(Lisp_Object a)
123 {
124 return (
125 (struct buffer*)((uintptr_t)XLP(a) -
126 (uintptr_t)((Lisp_Word_tag)(Lisp_Vectorlike)
127 << (((0x7fffffffffffffffL >> (3 - 1)) / 2 <
128 (9223372036854775807L))
129 ? 0
130 : VALBITS))));
131 }
132 static inline _Bool
133 BUFFER_LIVE_P(struct buffer* b)
134 {
135 return !NILP(((b)->name_));
136 }
137 static inline struct buffer*
138 decode_buffer(Lisp_Object b)
139 {
140 return NILP(b) ? (current_thread->m_current_buffer) : (XBUFFER(b));
141 }
142 static struct buffer*
143 live_buffer(Lisp_Object buffer)
144 {
145 struct buffer* b = decode_buffer(buffer);
146 return BUFFER_LIVE_P(b) ? b : ((void*)0);
147 }
148 Lisp_Object
149 set_marker_internal(Lisp_Object position, Lisp_Object buffer)
150 {
151 struct buffer* b = live_buffer(buffer);
152 if (NILP(position) || (MARKERP(position) && !XMARKER(position)->buffer) || !b) /* { dg-bogus "Wanalyzer-deref-before-check" } */
153 unchain_marker();
154 return 0;
155 }