As mentioned in bug 79929, comment 17, the -Wstringop-overflow warnings are enabled by -Wall and because they are implemented in the middle-end, may be issued for code emitted by front ends other than C and C++. But the corresponding options that control the warnings are C/C++ family only and aren't accepted by the driver for other front ends. That makes it difficult to control the warnings.
I suggest to enable them only for C family languages (I notice the options do not use EnabledBy()). Supposedly the option machinery initializes warn_stringop_overflow to 2 even when not in the set of options it is guarded with: Wstringop-overflow= C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_stringop_overflow) Init(2) Warning Under the control of Object Size type, warn about buffer overflow in string manipulation functions like memcpy and strcpy.
(In reply to Richard Biener from comment #1) > I suggest to enable them only for C family languages (I notice the options > do not use EnabledBy()). I guess that would also fix the bogus warning from PR 79929 ...
Patch posted for review: https://gcc.gnu.org/ml/gcc-patches/2017-04/msg01544.html
(In reply to Martin Sebor from comment #3) > Patch posted for review: > https://gcc.gnu.org/ml/gcc-patches/2017-04/msg01544.html It seems this patch has been committed as part of r247401 (but unfortunately not mentioned in the ChangeLog). However, I still see warnings like: f951: Warning: ‘__builtin_memset’ writing between 8 and 17179869176 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=] in Fortran code with a recent trunk build: gcc version 8.0.0 20170831 (experimental) [trunk revision 251566] (GCC) I see that there are two entries for Wstringop-overflow in c.opt, but only one of them has LangEnabledBy(). Could that be the problem?
As best I can tell the problem is that the option_enabled() function doesn't consider the front-end's lang_mask and returns true even for options that are not supported in the current language. I'm working on a fix.
Patch: https://gcc.gnu.org/ml/gcc-patches/2019-07/msg01457.html
Author: msebor Date: Wed Jul 24 20:34:03 2019 New Revision: 273771 URL: https://gcc.gnu.org/viewcvs?rev=273771&root=gcc&view=rev Log: PR driver/80545 - option -Wstringop-overflow not recognized by Fortran gcc/cp/ChangeLog: PR driver/80545 * decl.c (finish_function): Use lang_mask. gcc/testsuite/ChangeLog: PR driver/80545 * gcc.misc-tests/help.exp: Add tests. * lib/options.exp: Handle C++. gcc/ChangeLog: PR driver/80545 * diagnostic.c (diagnostic_classify_diagnostic): Use lang_mask. (diagnostic_report_diagnostic): Same. * diagnostic.h (diagnostic_context::option_enabled): Add an argument. (diagnostic_context::lang_mask): New data member. * ipa-pure-const.c (suggest_attribute): Use lang_hooks.option_lang_mask (). * opts-common.c (option_enabled): Handle new argument. (get_option_state): Pass an additional argument. * opts.c (print_filtered_help): Print supported languages for unsupported options. Adjust printing of current state. * opts.h (option_enabled): Add argument. * toplev.c (print_switch_values): Use lang_mask. (general_init): Set global_dc->lang_mask. Modified: trunk/gcc/ChangeLog trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/diagnostic.c trunk/gcc/diagnostic.h trunk/gcc/ipa-pure-const.c trunk/gcc/opts-common.c trunk/gcc/opts.c trunk/gcc/opts.h trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.misc-tests/help.exp trunk/gcc/testsuite/lib/options.exp trunk/gcc/toplev.c
I believe r273771 fully this bug.
Author: msebor Date: Wed Aug 28 16:24:38 2019 New Revision: 274996 URL: https://gcc.gnu.org/viewcvs?rev=274996&root=gcc&view=rev Log: PR driver/80545 - option -Wstringop-overflow not recognized by Fortran gcc/ChangeLog: PR driver/80545 * opts-common.c (option_enabled): Correct checking for language options. Modified: trunk/gcc/ChangeLog trunk/gcc/opts-common.c