Bug 57200 - [4.8/4.9 Regression] aggressive-loop-optimizations notes appear even when warning itself is suppressed
Summary: [4.8/4.9 Regression] aggressive-loop-optimizations notes appear even when war...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.8.1
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-07 22:17 UTC by Paul Pluzhnikov
Modified: 2013-05-08 09:10 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-05-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Pluzhnikov 2013-05-07 22:17:27 UTC
Test:

int x[10];

void fn ()
{
  int i;

  for (i = 0; i < 100; ++i)
    x[i] = 1;
}


Using trunk at r198689:

gcc -O2 -c t.c 
t.c: In function ‘fn’:
t.c:8:10: warning: iteration 10u invokes undefined behavior [-Waggressive-loop-optimizations]
     x[i] = 1;
          ^
t.c:7:3: note: containing loop
   for (i = 0; i < 100; ++i)
   ^


Looks good. But this doesn't:

gcc -O2 -c t.c -w
t.c: In function ‘fn’:
t.c:7:3: note: containing loop
   for (i = 0; i < 100; ++i)
   ^

A note suddenly appears from "nowhere" :-(
Comment 1 Paolo Carlini 2013-05-07 23:08:40 UTC
This issue is easy, isn't it? Something like:

Index: tree-ssa-loop-niter.c
===================================================================
--- tree-ssa-loop-niter.c	(revision 198676)
+++ tree-ssa-loop-niter.c	(working copy)
@@ -2553,10 +2553,11 @@ do_warn_aggressive_loop_optimizations (struct loop
     return;
 
   gimple estmt = last_stmt (e->src);
-  warning_at (gimple_location (stmt), OPT_Waggressive_loop_optimizations,
-	      "iteration %E invokes undefined behavior",
-	      double_int_to_tree (TREE_TYPE (loop->nb_iterations), i_bound));
-  inform (gimple_location (estmt), "containing loop");
+  if (warning_at (gimple_location (stmt), OPT_Waggressive_loop_optimizations,
+		  "iteration %E invokes undefined behavior",
+		  double_int_to_tree (TREE_TYPE (loop->nb_iterations),
+				      i_bound)))
+    inform (gimple_location (estmt), "containing loop");
   loop->warned_aggressive_loop_optimizations = true;
 }
Comment 2 Richard Biener 2013-05-08 08:44:56 UTC
(In reply to comment #1)
> This issue is easy, isn't it? Something like:
> 
> Index: tree-ssa-loop-niter.c
> ===================================================================
> --- tree-ssa-loop-niter.c    (revision 198676)
> +++ tree-ssa-loop-niter.c    (working copy)
> @@ -2553,10 +2553,11 @@ do_warn_aggressive_loop_optimizations (struct loop
>      return;
> 
>    gimple estmt = last_stmt (e->src);
> -  warning_at (gimple_location (stmt), OPT_Waggressive_loop_optimizations,
> -          "iteration %E invokes undefined behavior",
> -          double_int_to_tree (TREE_TYPE (loop->nb_iterations), i_bound));
> -  inform (gimple_location (estmt), "containing loop");
> +  if (warning_at (gimple_location (stmt), OPT_Waggressive_loop_optimizations,
> +          "iteration %E invokes undefined behavior",
> +          double_int_to_tree (TREE_TYPE (loop->nb_iterations),
> +                      i_bound)))
> +    inform (gimple_location (estmt), "containing loop");
>    loop->warned_aggressive_loop_optimizations = true;
>  }

Yes, approved.
Comment 3 Paolo Carlini 2013-05-08 09:10:55 UTC
Done, mainline and 4.8.1.