Bug 80545 - option -Wstringop-overflow not recognized by Fortran
Summary: option -Wstringop-overflow not recognized by Fortran
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Martin Sebor
URL:
Keywords: diagnostic, patch
Depends on:
Blocks: 82813
  Show dependency treegraph
 
Reported: 2017-04-27 14:17 UTC by Martin Sebor
Modified: 2019-09-20 20:24 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-04-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2017-04-27 14:17:20 UTC
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.
Comment 1 Richard Biener 2017-04-28 09:28:37 UTC
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.
Comment 2 janus 2017-04-28 11:29:24 UTC
(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 ...
Comment 3 Martin Sebor 2017-04-28 22:03:36 UTC
Patch posted for review: https://gcc.gnu.org/ml/gcc-patches/2017-04/msg01544.html
Comment 4 janus 2017-09-05 07:23:03 UTC
(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?
Comment 5 Martin Sebor 2019-07-21 23:45:01 UTC
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.
Comment 6 Martin Sebor 2019-07-22 21:55:30 UTC
Patch: https://gcc.gnu.org/ml/gcc-patches/2019-07/msg01457.html
Comment 7 Martin Sebor 2019-07-24 20:34:34 UTC
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
Comment 8 Martin Sebor 2019-08-08 22:48:25 UTC
I believe r273771 fully this bug.
Comment 9 Martin Sebor 2019-08-28 16:25:10 UTC
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