This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Provide inlining context in strict-overflow warnings


Patterns that trigger the optimization and warning can form after inlining, and it can be rather difficult to figure out what exactly is causing the warning. The inlining context at least provides additional hints, enabling developers to substitute the arguments and discover what, precisely, is happening.

More context is provided with -g than without, but I think this is acceptable.

I bootstrapped and tested the attached patch on x86_64-redhat-linux-gnu, with no new regressions.

--
Florian Weimer / Red Hat Product Security Team
gcc/

2014-05-13  Florian Weimer  <fweimer@redhat.com>

	* fold-const.c (fold_undefer_overflow_warnings): Print notes with
	inlining information.

gcc/testsuite/

2014-05-13  Florian Weimer  <fweimer@redhat.com>

	* c-c++-common/Wstrict-overflow-1.c: New test.

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 0fcb87f..5f13992 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -268,6 +268,12 @@ fold_undefer_overflow_warnings (bool issue, const_gimple stmt, int code)
   else
     locus = gimple_location (stmt);
   warning_at (locus, OPT_Wstrict_overflow, "%s", warnmsg);
+
+  /* Print notes with inlining information.  */
+  for (tree block = gimple_block (stmt); block && TREE_CODE (block) == BLOCK;
+       block = BLOCK_SUPERCONTEXT (block))
+    if (BLOCK_SOURCE_LOCATION (block))
+      inform (BLOCK_SOURCE_LOCATION (block), "inlined from here");
 }
 
 /* Stop deferring overflow warnings, ignoring any deferred
diff --git a/gcc/testsuite/c-c++-common/Wstrict-overflow-1.c b/gcc/testsuite/c-c++-common/Wstrict-overflow-1.c
new file mode 100644
index 0000000..693c52b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wstrict-overflow-1.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -Wstrict-overflow" } */
+
+int f (void);
+
+static int g (int a, int b, int c)
+{
+  if (a + b < c) /* { dg-warning "assuming signed overflow" } */
+    return -1;
+  return f ();
+}
+
+static int h (int a, int b)
+{
+  return g(a, 1, b); /* { dg-message "note: inlined from here" } */
+}
+
+int k (int a)
+{
+  return h(a, a); /* { dg-message "note: inlined from here" } */
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]