In base-gcc -Wno-error=uninitialized is currently ineffective, in that
cc1 still errors out with the following flags combination:

  billy /tmp$ cat t.c
  #include <stdio.h>

  int
  f(void)
  {
          int r;
          return r;
  }
  billy /tmp$ gcc -v -c -O2 -Wall -Werror  -Wno-error=uninitialized t.c

Previous behavior:

  [...]
  cc1.old: warnings being treated as errors
  t.c: In function 'f':
  t.c:7: warning: 'r' is used uninitialized in this function
  billy /tmp$ echo $?
  1
  billy /tmp$

After the patch (expected behavior):

  billy /tmp$ gcc -c -O2 -Wall -Werror -Wno-error=uninitialized t.c
  t.c: In function 'f':
  t.c:7: warning: 'r' is used uninitialized in this function
  billy /tmp$ echo $?
  0
  billy /tmp$

I know that base-gcc is low priority on our roadmap so I'll explain the
rationale for this diff:

I had plans for using -Wall -Werror -Wno-error=uninitialized in our
kernel builds, but those plans went nowhere - so far.  One of the
problems was adding more differences between clang and gcc in kernel
Makefiles (because -Wno-error=uninitialized didn't work with base-gcc).
Another problem was (in my mind at least) base-gcc spewing lots of bogus
"may be used uninitialized" warnings.  I have another possible fix
for that.

Anyway, I'd like to see where those tiny fixes can lead us.  Even if the
answer is "nowhere", the fix below is simple and worth committing
I think.

(If you care about how it works, see diagnostic_report_diagnostic() and
diagnostic_action_after_output() in diagnostic.c)

ok?


Index: tree-ssa.c
===================================================================
RCS file: /cvs/src/gnu/gcc/gcc/tree-ssa.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 tree-ssa.c
--- tree-ssa.c  15 Oct 2009 17:11:28 -0000      1.1.1.1
+++ tree-ssa.c  21 Jun 2021 23:37:37 -0000
@@ -1177,7 +1177,7 @@ warn_uninit (tree t, const char *gmsgid,
   locus = (context != NULL && EXPR_HAS_LOCATION (context)
           ? EXPR_LOCUS (context)
           : &DECL_SOURCE_LOCATION (var));
-  warning (0, gmsgid, locus, var);
+  warning (OPT_Wuninitialized, gmsgid, locus, var);
   fun_locus = &DECL_SOURCE_LOCATION (cfun->decl);
   if (locus->file != fun_locus->file
       || locus->line < fun_locus->line


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to