public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Small tweak to -Wuninitialized
@ 2012-12-03  9:55 Eric Botcazou
  2012-12-03 11:18 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2012-12-03  9:55 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1033 bytes --]

Hi,

if you compile the attached testcase on x86 with -O2 -Wuninitialized, you get:

strip.adb: In function 'Strip':
strip.adb:4:4: warning: 'Last' may be used uninitialized in this function [-
Wuninitialized]
strip.adb:26:44: warning: 'First' may be used uninitialized in this function 
[-Wmaybe-uninitialized]

The same warning is apparently associated with 2 different options so, if you 
want to disable "maybe" warnings, -O2 -Wuninitialized -Wno-maybe-uninitialized 
only disables the second one:

strip.adb: In function 'Strip':
strip.adb:4:4: warning: 'Last' may be used uninitialized in this function [-
Wuninitialized]

Of course the story under the hood is a bit different, but this doesn't really 
matter to the user I think, so I propose using the -Wmaybe-uninitialized tag 
in both cases.  Tested on x86-64-suse-linux, OK for the mainline?


2012-12-03  Eric Botcazou  <ebotcazou@adacore.com>

	* tree-ssa.c (warn_uninitialized_var): Use OPT_Wmaybe_uninitialized tag
	in the non-always executed case.


-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 1189 bytes --]

Index: tree-ssa.c
===================================================================
--- tree-ssa.c	(revision 194049)
+++ tree-ssa.c	(working copy)
@@ -1664,7 +1664,7 @@ warn_uninitialized_vars (bool warn_possi
 			     "%qD is used uninitialized in this function",
 			     stmt);
 	      else if (warn_possibly_uninitialized)
-		warn_uninit (OPT_Wuninitialized, use,
+		warn_uninit (OPT_Wmaybe_uninitialized, use,
 			     SSA_NAME_VAR (use), SSA_NAME_VAR (use),
 			     "%qD may be used uninitialized in this function",
 			     stmt);
@@ -1696,13 +1696,13 @@ warn_uninitialized_vars (bool warn_possi
 		continue;
 
 	      if (always_executed)
-		warn_uninit (OPT_Wuninitialized, use, gimple_assign_rhs1 (stmt),
-			     base,
+		warn_uninit (OPT_Wuninitialized, use, 
+			     gimple_assign_rhs1 (stmt), base,
 			     "%qE is used uninitialized in this function",
 			     stmt);
 	      else if (warn_possibly_uninitialized)
-		warn_uninit (OPT_Wuninitialized, use, gimple_assign_rhs1 (stmt),
-			     base,
+		warn_uninit (OPT_Wmaybe_uninitialized, use,
+			     gimple_assign_rhs1 (stmt), base,
 			     "%qE may be used uninitialized in this function",
 			     stmt);
 	    }

[-- Attachment #3: strip.adb --]
[-- Type: text/x-adasrc, Size: 664 bytes --]

function Strip (Str : in String) return String is

   First : Natural;
   Last : Natural;
   Blank_Str : constant String (Str'Range) := (others => ' ');

begin
   if Str = "" or Str = Blank_Str then
      return "";
   end if;
   for I in Str'Range loop
      if Str (I) /= ' ' and Str (I) /= Ascii.Ht then
         First := I;
         exit;
      end if;
   end loop;

   for I in reverse Str'Range loop
      if Str (I) /= ' ' and Str (I) /= Ascii.Ht then
         Last := I;
         exit;
      end if;
   end loop;

   declare
      Ret_Str : constant String (1 .. Last - First + 1) := Str (First .. Last);
   begin
      return Ret_Str;
   end;

end Strip;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch] Small tweak to -Wuninitialized
  2012-12-03  9:55 [patch] Small tweak to -Wuninitialized Eric Botcazou
@ 2012-12-03 11:18 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2012-12-03 11:18 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches

On Mon, Dec 3, 2012 at 10:51 AM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> if you compile the attached testcase on x86 with -O2 -Wuninitialized, you get:
>
> strip.adb: In function 'Strip':
> strip.adb:4:4: warning: 'Last' may be used uninitialized in this function [-
> Wuninitialized]
> strip.adb:26:44: warning: 'First' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
>
> The same warning is apparently associated with 2 different options so, if you
> want to disable "maybe" warnings, -O2 -Wuninitialized -Wno-maybe-uninitialized
> only disables the second one:
>
> strip.adb: In function 'Strip':
> strip.adb:4:4: warning: 'Last' may be used uninitialized in this function [-
> Wuninitialized]
>
> Of course the story under the hood is a bit different, but this doesn't really
> matter to the user I think, so I propose using the -Wmaybe-uninitialized tag
> in both cases.  Tested on x86-64-suse-linux, OK for the mainline?

Ok.

Thanks,
Richard.

>
> 2012-12-03  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * tree-ssa.c (warn_uninitialized_var): Use OPT_Wmaybe_uninitialized tag
>         in the non-always executed case.
>
>
> --
> Eric Botcazou

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-03 11:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-03  9:55 [patch] Small tweak to -Wuninitialized Eric Botcazou
2012-12-03 11:18 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).