Skip to content

Commit ee87e86

Browse files
Sebastian Popweltling
Sebastian Pop
authored andcommitted
inline by hand to avoid uninitialized variable warning
When compiling with "-Wall -Werror" gcc emits two errors: ../src/pcre2_jit_neon_inc.h:211:8: error: ‘cmp1b’ is used uninitialized in this function [-Werror=uninitialized] 211 | data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/pcre2_jit_neon_inc.h:212:9: error: ‘cmp2b’ is used uninitialized in this function [-Werror=uninitialized] 212 | data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The compiler emits the error message before inlining. Because the warning is based on an intra-procedural data flow analysis, the compiler does not see that cmp1b and cmp2b are not used when they are not initialized. Here is the code of that function, cmp2 is only used when ctype is compare_match2 or compare_match1i, and not when ctype is compare_match1: static inline vect_t fast_forward_char_pair_compare(compare_type ctype, vect_t dst, vect_t cmp1, vect_t cmp2) { if (ctype == compare_match2) { vect_t tmp = dst; dst = VCEQQ(dst, cmp1); tmp = VCEQQ(tmp, cmp2); dst = VORRQ(dst, tmp); return dst; } if (ctype == compare_match1i) dst = VORRQ(dst, cmp2); dst = VCEQQ(dst, cmp1); return dst; } The patch inlines by hand the case of compare_match1 such that the code avoids referring to cmp1b and cmp2b. Tested on aarch64-linux with `make check`.
1 parent 2b279b4 commit ee87e86

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

ext/pcre/pcre2lib/pcre2_jit_neon_inc.h

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,24 @@ vect_t vmask = VDUPQ(mask);
109109
#if defined(FFCPS)
110110
compare_type compare1_type = compare_match1;
111111
compare_type compare2_type = compare_match1;
112-
vect_t cmp1a = vdupq_n_u8(0), cmp1b = vdupq_n_u8(0), cmp2a = vdupq_n_u8(0), cmp2b = vdupq_n_u8(0);
112+
vect_t cmp1a, cmp1b, cmp2a, cmp2b;
113113
const sljit_u32 diff = IN_UCHARS(offs1 - offs2);
114114
PCRE2_UCHAR char1a = ic.c.c1;
115115
PCRE2_UCHAR char2a = ic.c.c3;
116116

117117
# ifdef FFCPS_CHAR1A2A
118118
cmp1a = VDUPQ(char1a);
119119
cmp2a = VDUPQ(char2a);
120+
cmp1b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */
121+
cmp2b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */
120122
# else
121123
PCRE2_UCHAR char1b = ic.c.c2;
122124
PCRE2_UCHAR char2b = ic.c.c4;
123125
if (char1a == char1b)
126+
{
124127
cmp1a = VDUPQ(char1a);
128+
cmp1b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */
129+
}
125130
else
126131
{
127132
sljit_u32 bit1 = char1a ^ char1b;
@@ -140,7 +145,10 @@ else
140145
}
141146

142147
if (char2a == char2b)
148+
{
143149
cmp2a = VDUPQ(char2a);
150+
cmp2b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */
151+
}
144152
else
145153
{
146154
sljit_u32 bit2 = char2a ^ char2b;
@@ -207,9 +215,17 @@ if (p1 < str_ptr)
207215
}
208216
else
209217
data2 = shift_left_n_lanes(data, offs1 - offs2);
210-
211-
data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b);
212-
data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b);
218+
219+
if (compare1_type == compare_match1)
220+
data = VCEQQ(data, cmp1a);
221+
else
222+
data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b);
223+
224+
if (compare2_type == compare_match1)
225+
data2 = VCEQQ(data2, cmp2a);
226+
else
227+
data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b);
228+
213229
vect_t eq = VANDQ(data, data2);
214230
#endif
215231

@@ -275,8 +291,14 @@ while (str_ptr < str_end)
275291
data = VCEQQ(data, cmp1a);
276292
data2 = VCEQQ(data2, cmp2a);
277293
# else
278-
data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b);
279-
data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b);
294+
if (compare1_type == compare_match1)
295+
data = VCEQQ(data, cmp1a);
296+
else
297+
data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b);
298+
if (compare2_type == compare_match1)
299+
data2 = VCEQQ(data2, cmp2a);
300+
else
301+
data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b);
280302
# endif
281303

282304
eq = VANDQ(data, data2);

0 commit comments

Comments
 (0)