add some -Werror pragmas for tilegx

Message ID 549DF701.606@ezchip.com
State Superseded
Headers

Commit Message

Chris Metcalf Dec. 27, 2014, 12:02 a.m. UTC
  We see some crazy warnings on tilegx with gcc 4.8.2:

In file included from regex.c:66:0:
regcomp.c: In function ‘parse_expression’:
regcomp.c:2849:15: error: ‘end_elem’ may be used uninitialized in this
function [-Werror=maybe-uninitialized]
        else if (br_elem->type == COLL_SYM)
                ^
regcomp.c:3109:34: note: ‘end_elem’ was declared here
        bracket_elem_t start_elem, end_elem;
                                   ^
regcomp.c:3109:22: error: ‘start_elem’ may be used uninitialized in
this function [-Werror=maybe-uninitialized]
        bracket_elem_t start_elem, end_elem;
                       ^

These warnings are not seen on x86, and in fact if I compile the
preprocessed tile sources with the x86 gcc 4.8.2, I don't see the
warnings.  I do see equivalent warnings if I compile the
x86-preprocessed source code with tilegx gcc 4.8.2.

The change seems to be the minimally scoped thing necessary to avoid
the warnings on tilegx, but it is somewhat ugly.  Any suggestions as
to other ways to avoid this issue?

2014-12-26  Chris Metcalf  <cmetcalf@ezchip.com>

         * posix/regcomp.c (parse_bracket_exp): Add DIAG_xxx macros to
         suppress two uninitialized variable warnings on tilegx gcc 4.8.2.
  

Comments

Paul Eggert Dec. 27, 2014, 12:49 a.m. UTC | #1
Chris Metcalf wrote:
> +          /* Using the tilegx gcc 4.8.2 yields uninitialized warnings
> +             here (on the "else if" line) and below.  Compiling the same
> +             source code with the same gcc version on x86_64 does not
> +             yield the warning, so it is something subtle.  */
> +          DIAG_PUSH_NEEDS_COMMENT;
> +          DIAG_IGNORE_NEEDS_COMMENT(4.8, "-Wmaybe-uninitialized");
>          }
>         else if (br_elem->type == COLL_SYM)
>          {
> +          DIAG_POP_NEEDS_COMMENT;

Can you fix this in a way that doesn't feel like ifdefs that are improperly 
nested with respect to the actual code?  E.g., by moving the "br_elem->type == 
COLL_SYM" expression into a static function, and playing with the pragmas only 
inside that function's body?
  

Patch

diff --git a/posix/regcomp.c b/posix/regcomp.c
index 897fe276a3fa..8ec8126888e3 100644
--- a/posix/regcomp.c
+++ b/posix/regcomp.c
@@ -18,6 +18,7 @@ 
     <http://www.gnu.org/licenses/>.  */

  #include <stdint.h>
+#include <libc-internal.h>

  #ifdef _LIBC
  # include <locale/weight.h>
@@ -2845,9 +2846,16 @@  parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
         {
           if (nrules != 0)
             return __collseq_table_lookup (collseqwc, br_elem->opr.wch);
+          /* Using the tilegx gcc 4.8.2 yields uninitialized warnings
+             here (on the "else if" line) and below.  Compiling the same
+             source code with the same gcc version on x86_64 does not
+             yield the warning, so it is something subtle.  */
+          DIAG_PUSH_NEEDS_COMMENT;
+          DIAG_IGNORE_NEEDS_COMMENT(4.8, "-Wmaybe-uninitialized");
         }
        else if (br_elem->type == COLL_SYM)
         {
+          DIAG_POP_NEEDS_COMMENT;
           size_t sym_name_len = strlen ((char *) br_elem->opr.name);
           if (nrules != 0)
             {
@@ -3106,7 +3114,11 @@  parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,

    while (1)
      {
+      /* See above for tilegx 4.8.2 warnings generated in this file.  */
+      DIAG_PUSH_NEEDS_COMMENT;
+      DIAG_IGNORE_NEEDS_COMMENT(4.8, "-Wmaybe-uninitialized");
        bracket_elem_t start_elem, end_elem;
+      DIAG_POP_NEEDS_COMMENT;
        unsigned char start_name_buf[BRACKET_NAME_BUF_SIZE];
        unsigned char end_name_buf[BRACKET_NAME_BUF_SIZE];
        reg_errcode_t ret;