]> granicus.if.org Git - php/commitdiff
inline by hand to avoid uninitialized variable warning
authorSebastian Pop <spop@amazon.com>
Wed, 29 Jan 2020 14:54:19 +0000 (14:54 +0000)
committerAnatol Belski <ab@php.net>
Fri, 31 Jan 2020 13:56:51 +0000 (14:56 +0100)
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`.

ext/pcre/pcre2lib/pcre2_jit_neon_inc.h

index aec48219eafa23374818b96edbeb9f8132bd5d0c..0265f36a0b3093fbeb8c8b699cdca1a805881861 100644 (file)
@@ -109,7 +109,7 @@ vect_t vmask = VDUPQ(mask);
 #if defined(FFCPS)
 compare_type compare1_type = compare_match1;
 compare_type compare2_type = compare_match1;
-vect_t cmp1a = vdupq_n_u8(0), cmp1b = vdupq_n_u8(0), cmp2a = vdupq_n_u8(0), cmp2b = vdupq_n_u8(0);
+vect_t cmp1a, cmp1b, cmp2a, cmp2b;
 const sljit_u32 diff = IN_UCHARS(offs1 - offs2);
 PCRE2_UCHAR char1a = ic.c.c1;
 PCRE2_UCHAR char2a = ic.c.c3;
@@ -117,11 +117,16 @@ PCRE2_UCHAR char2a = ic.c.c3;
 # ifdef FFCPS_CHAR1A2A
 cmp1a = VDUPQ(char1a);
 cmp2a = VDUPQ(char2a);
+cmp1b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */
+cmp2b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */
 # else
 PCRE2_UCHAR char1b = ic.c.c2;
 PCRE2_UCHAR char2b = ic.c.c4;
 if (char1a == char1b)
+  {
   cmp1a = VDUPQ(char1a);
+  cmp1b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */
+  }
 else
   {
   sljit_u32 bit1 = char1a ^ char1b;
@@ -140,7 +145,10 @@ else
   }
 
 if (char2a == char2b)
+  {
   cmp2a = VDUPQ(char2a);
+  cmp2b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */
+  }
 else
   {
   sljit_u32 bit2 = char2a ^ char2b;
@@ -207,9 +215,17 @@ if (p1 < str_ptr)
   }
 else
   data2 = shift_left_n_lanes(data, offs1 - offs2);
-data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b);
-data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b);
+
+if (compare1_type == compare_match1)
+  data = VCEQQ(data, cmp1a);
+else
+  data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b);
+
+if (compare2_type == compare_match1)
+  data2 = VCEQQ(data2, cmp2a);
+else
+  data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b);
+
 vect_t eq = VANDQ(data, data2);
 #endif
 
@@ -275,8 +291,14 @@ while (str_ptr < str_end)
   data = VCEQQ(data, cmp1a);
   data2 = VCEQQ(data2, cmp2a);
 # else
-  data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b);
-  data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b);
+  if (compare1_type == compare_match1)
+    data = VCEQQ(data, cmp1a);
+  else
+    data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b);
+  if (compare2_type == compare_match1)
+    data2 = VCEQQ(data2, cmp2a);
+  else
+    data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b);
 # endif
 
   eq = VANDQ(data, data2);