User account creation filtered due to spam.

Bug 79677 - Weird handling of -Werror=
Summary: Weird handling of -Werror=
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-22 14:43 UTC by Jakub Jelinek
Modified: 2017-02-27 18:20 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-02-24 00:00:00


Attachments
gcc7-pr79677.patch (1.79 KB, patch)
2017-02-24 15:52 UTC, Jakub Jelinek
Details | Diff
/builddir/build/BUILD/cmake-3.7.2/Utilities/KWIML/test/test.c (309 bytes, text/plain)
2017-02-27 17:20 UTC, Orion Poplawski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2017-02-22 14:43:31 UTC
On the following testcase:

int
main()
{
  char message[10] = "";
  __builtin_printf(message);
  return 0;
}

we warn (or error) e.g. with:
-Wformat -Wformat-security
-Wformat -Werror=format-security
-Wall -Wformat-security
-Wall -Werror=format-security
-Wformat -Wformat-security -Wformat
-Wall -Wformat-security -Wformat
-Wformat -Wformat-security -Wall
-Wall -Wformat-security -Wall
-Wformat -Wformat-security -Werror=format-security -Wformat
-Wall -Wformat-security -Werror=format-security -Wformat
-Wformat -Wformat-security -Werror=format-security -Wall
-Wall -Wformat-security -Werror=format-security -Wall
but not with:
-Wformat -Werror=format-security -Wformat
-Wall -Werror=format-security -Wformat
-Wformat -Werror=format-security -Wall
-Wall -Werror=format-security -Wall

-Wall implies -Wformat (level 1) and -Wformat only for level 2 implies -Wformat-security, so something in the -Wformat or -Wall handling disables warn_format_security, but strangely only when the -Werror option is used.
Comment 1 joseph@codesourcery.com 2017-02-22 17:29:03 UTC
For the theory of how I think this should behave, see 
<https://gcc.gnu.org/ml/gcc-patches/2012-05/msg00419.html> (referring back 
to <https://gcc.gnu.org/ml/gcc-bugs/2012-04/msg02134.html> and 
<https://gcc.gnu.org/ml/gcc/2010-01/msg00063.html> for the concept of 
distance for options overriding each other).  That is, 
-Werror=format-security should act like a -Wformat-security variant, and 
so all these examples should warn/error.

I don't know what the immediate cause of this issue or appropriate fix in 
the context of the present implementation might be.
Comment 2 Jakub Jelinek 2017-02-24 15:52:02 UTC
Created attachment 40824 [details]
gcc7-pr79677.patch

Untested fix.
Comment 3 Jakub Jelinek 2017-02-24 23:16:27 UTC
Author: jakub
Date: Fri Feb 24 23:15:56 2017
New Revision: 245728

URL: https://gcc.gnu.org/viewcvs?rev=245728&root=gcc&view=rev
Log:
	PR c/79677
	* opts.h (handle_generated_option): Add GENERATED_P argument.
	* opts-common.c (handle_option): Adjust function comment.
	(handle_generated_option): Add GENERATED_P argument, pass it to
	handle_option.
	(control_warning_option): Pass false to handle_generated_option
	GENERATED_P.
	* opts.c (maybe_default_option): Pass true to handle_generated_option
	GENERATED_P.
	* optc-gen.awk: Likewise.
ada/
	* gcc-interface/misc.c (gnat_handle_option): Pass true to
	handle_generated_option GENERATED_P.
testsuite/
	* gcc.dg/pr79677.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr79677.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/gcc-interface/misc.c
    trunk/gcc/optc-gen.awk
    trunk/gcc/opts-common.c
    trunk/gcc/opts.c
    trunk/gcc/opts.h
    trunk/gcc/testsuite/ChangeLog
Comment 4 Jakub Jelinek 2017-02-24 23:17:09 UTC
Fixed.
Comment 5 Orion Poplawski 2017-02-27 16:59:53 UTC
With gcc 7.0.1-0.10.fc26 I'm starting to see errors like:

cc1plus: error: -Wformat-security ignored without -Wformat [-Werror=format-security]

If this is intended, we're going to need to fix redhat-rpm-config to change:

%__global_compiler_flags -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches %{_hardened_cflags}

to add -Wformat.
Comment 6 Jakub Jelinek 2017-02-27 17:11:12 UTC
(In reply to Orion Poplawski from comment #5)
> With gcc 7.0.1-0.10.fc26 I'm starting to see errors like:
> 
> cc1plus: error: -Wformat-security ignored without -Wformat
> [-Werror=format-security]
> 
> If this is intended, we're going to need to fix redhat-rpm-config to change:
> 
> %__global_compiler_flags -O2 -g -pipe -Wall -Werror=format-security
> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong
> --param=ssp-buffer-size=4 -grecord-gcc-switches %{_hardened_cflags}
> 
> to add -Wformat.

Well, -Wformat is implied by -Wall, so it must be packages doing -Wno-format or similar.  -Wformat -Wformat-security -Wno-format used to warn in the past,
-Wformat -Werror=format-security -Wno-format used to be quite due to a bug, but
now errors out.
We have one instance of this problem in gcc too:
AS_IF([test $enable_build_format_warnings = no],
      [wf_opt=-Wno-format],[wf_opt=])
Guess we want there:
AS_IF([test $enable_build_format_warnings = no],
      [wf_opt="-Wno-format -Wno-format-security -Wno-format-y2k -Wno-format-extra-args -Wno-format-zero-length -Wno-format-nonliteral"],[wf_opt=])
Comment 7 Jakub Jelinek 2017-02-27 17:12:35 UTC
Or perhaps makefiles filtering away -Wall or using -Wno-all.
Comment 8 Orion Poplawski 2017-02-27 17:20:47 UTC
Created attachment 40838 [details]
/builddir/build/BUILD/cmake-3.7.2/Utilities/KWIML/test/test.c

/usr/lib64/ccache/gcc  -DKWIML_LANGUAGE_C -DKWIML_LANGUAGE_CXX -I/builddir/build/BUILD/cmake-3.7.2/build/Utilities -I/builddir/build/BUILD/cmake-3.7.2/Utilities  -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -Wno-format   -std=gnu11 -o CMakeFiles/kwiml_test.dir/test.c.o   -c /builddir/build/BUILD/cmake-3.7.2/Utilities/KWIML/test/test.c
cc1: error: -Wformat-security ignored without -Wformat [-Werror=format-security]
cc1: some warnings being treated as errors

I don't see any extra options myself.
Comment 9 Orion Poplawski 2017-02-27 17:21:09 UTC
Ah, just got the -Wno-format
Comment 10 Orion Poplawski 2017-02-27 17:57:55 UTC
I'm not sure how I'm practically supposed to handle this.  In this case, for one sub-directory upstream adds -Wno-format to the flags:

./Utilities/KWIML/test/CMakeLists.txt:    set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -Wno-format")

Is this still a bug in gcc?
Comment 11 Jakub Jelinek 2017-02-27 18:04:51 UTC
It is not a GCC bug, the general rule is that the options that enable suboptions don't change those (either way) if that option has been specified explicitly.
So, -Wformat -Wformat-security -Wno-format does not disable -Wformat-security, but e.g. disables -Wformat-y2k because that option has not been set explicitly.
So, either you change that
    set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -Wno-format")
to
    set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -Wno-format -Wno-format-security")
or e.g. strip off -Werror=format-security from RPM_OPT_FLAGS.
Comment 12 Orion Poplawski 2017-02-27 18:20:43 UTC
Adding -Wno-format-security does indeed work.  Thank you.