This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] add -Wstringop-overflow to LTO options (PR 84212)
- From: Martin Sebor <msebor at gmail dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 7 Feb 2018 12:30:09 -0700
- Subject: [PATCH] add -Wstringop-overflow to LTO options (PR 84212)
- Authentication-results: sourceware.org; auth=none
In PR 84212 the reporter asks why -Wno-stringop-overflow has
no effect during LTO linking. It turns out that the reason
is the same as in bug 78768: the specification in the c.opt
file is missing LTO among the languages.
The attached patch adds LTO to it and to -Wstringop-truncation.
Bootstrapped and regtested on x86_64-linux.
There are other middle-end options in the c.opt file that do
not mention LTO that arguably should (*). I didn't change
those in this patch, in part because I don't have test cases
showing where it matters, and in part because I don't think
that having to remember to include LTO in these options (and,
ideally, also include a test in the test suite for each) is
a good approach.
It seems that including LTO implicitly for all options would
obviate this manual step and eliminate the risk of missing
them. Is there a reason not to do that?
If implicitly including LTO for every option is not feasible,
then it might be worthwhile to write a small script to verify
that every middle-end option does mention LTO, and have make
run the script as part of the self-test step.
Is there support for either of these changes? If not, are
there any other ideas for how to avoid these kind of bugs?
Martin
[*] Here are a few examples. I'm fine with adding LTO to
any or all of these as well as any others that I may have
missed for GCC 8 if that sounds like a good idea.
-Walloc-size-larger-than
-Warray-bounds
-Wformat-truncation=
-Wmaybe-uninitialized
-Wnonnull
-Wrestrict
-Wstrict-overflow
-Wsuggest-attribute
-Wuninitialized
PR lto/84212 - -Wno-* does not disable warnings from -flto link stage
gcc/c-family/ChangeLog:
PR lto/84212
* c.opt (-Wstringop-overflow): Add LTO.
gcc/testsuite/ChangeLog:
PR lto/84212
* gcc.dg/lto/pr84212_0.c: New test file.
* gcc.dg/lto/pr84212_1.c: Same.
Index: gcc/c-family/c.opt
===================================================================
--- gcc/c-family/c.opt (revision 257453)
+++ gcc/c-family/c.opt (working copy)
@@ -739,17 +739,17 @@ C ObjC C++ ObjC++ Var(warn_sizeof_array_argument)
Warn when sizeof is applied on a parameter declared as an array.
Wstringop-overflow
-C ObjC C++ ObjC++ Warning Alias(Wstringop-overflow=, 2, 0)
+C ObjC C++ LTO ObjC++ Warning Alias(Wstringop-overflow=, 2, 0)
Warn about buffer overflow in string manipulation functions like memcpy
and strcpy.
Wstringop-overflow=
-C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_stringop_overflow) Init(2) Warning LangEnabledBy(C ObjC C++ ObjC++, Wall, 2, 0) IntegerRange(0, 4)
+C ObjC C++ LTO ObjC++ Joined RejectNegative UInteger Var(warn_stringop_overflow) Init(2) Warning LangEnabledBy(C ObjC C++ ObjC++ LTO, Wall, 2, 0) IntegerRange(0, 4)
Under the control of Object Size type, warn about buffer overflow in string
manipulation functions like memcpy and strcpy.
Wstringop-truncation
-C ObjC C++ ObjC++ Var(warn_stringop_truncation) Warning Init (1) LangEnabledBy(C ObjC C++ ObjC++, Wall)
+C ObjC C++ LTO ObjC++ Var(warn_stringop_truncation) Warning Init (1) LangEnabledBy(C ObjC C++ ObjC++ LTO, Wall)
Warn about truncation in string manipulation functions like strncat and strncpy.
Wsuggest-attribute=format
Index: gcc/testsuite/gcc.dg/lto/pr84212_0.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr84212_0.c (nonexistent)
+++ gcc/testsuite/gcc.dg/lto/pr84212_0.c (working copy)
@@ -0,0 +1,11 @@
+/* PR lto/84212 - -Wno-stringop-verflow does not disable warnings from
+ -flto link stage
+ { dg-lto-do link }
+ { dg-lto-options { { -O2 -Werror -Wno-stringop-overflow -flto } } } */
+
+#include <string.h>
+
+void clear (char *p, unsigned n)
+{
+ memset (p, 0, n);
+}
Index: gcc/testsuite/gcc.dg/lto/pr84212_1.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr84212_1.c (nonexistent)
+++ gcc/testsuite/gcc.dg/lto/pr84212_1.c (working copy)
@@ -0,0 +1,11 @@
+/* PR lto/84212 - -Wno-stringop-verflow does not disable warnings from
+ -flto link stage */
+
+extern void clear (char*, unsigned);
+
+int main (void)
+{
+ char x[3];
+
+ clear (x, 4);
+}