0f6998164125d3cc84962fbd057dc17dcdd99dea
[openwrt/openwrt.git] / toolchain / gcc / patches / 4.9-linaro / 910-mbsd_multi.patch
1
2 This patch brings over a few features from MirBSD:
3 * -fhonour-copts
4 If this option is not given, it's warned (depending
5 on environment variables). This is to catch errors
6 of misbuilt packages which override CFLAGS themselves.
7 * -Werror-maybe-reset
8 Has the effect of -Wno-error if GCC_NO_WERROR is
9 set and not '0', a no-operation otherwise. This is
10 to be able to use -Werror in "make" but prevent
11 GNU autoconf generated configure scripts from
12 freaking out.
13
14 This patch was authored by Thorsten Glaser <tg at mirbsd.de>
15 with copyright assignment to the FSF in effect.
16
17 --- a/gcc/c-family/c-opts.c
18 +++ b/gcc/c-family/c-opts.c
19 @@ -105,6 +105,9 @@ static size_t include_cursor;
20 /* Whether any standard preincluded header has been preincluded. */
21 static bool done_preinclude;
22
23 +/* Check if a port honours COPTS. */
24 +static int honour_copts = 0;
25 +
26 static void handle_OPT_d (const char *);
27 static void set_std_cxx98 (int);
28 static void set_std_cxx11 (int);
29 @@ -384,6 +387,9 @@ c_common_handle_option (size_t scode, co
30 cpp_opts->warn_endif_labels = value;
31 break;
32
33 + case OPT_Werror_maybe_reset:
34 + break;
35 +
36 case OPT_Winvalid_pch:
37 cpp_opts->warn_invalid_pch = value;
38 break;
39 @@ -492,6 +498,12 @@ c_common_handle_option (size_t scode, co
40 flag_no_builtin = !value;
41 break;
42
43 + case OPT_fhonour_copts:
44 + if (c_language == clk_c) {
45 + honour_copts++;
46 + }
47 + break;
48 +
49 case OPT_fconstant_string_class_:
50 constant_string_class_name = arg;
51 break;
52 @@ -1048,6 +1060,47 @@ c_common_init (void)
53 return false;
54 }
55
56 + if (c_language == clk_c) {
57 + char *ev = getenv ("GCC_HONOUR_COPTS");
58 + int evv;
59 + if (ev == NULL)
60 + evv = -1;
61 + else if ((*ev == '0') || (*ev == '\0'))
62 + evv = 0;
63 + else if (*ev == '1')
64 + evv = 1;
65 + else if (*ev == '2')
66 + evv = 2;
67 + else if (*ev == 's')
68 + evv = -1;
69 + else {
70 + warning (0, "unknown GCC_HONOUR_COPTS value, assuming 1");
71 + evv = 1; /* maybe depend this on something like MIRBSD_NATIVE? */
72 + }
73 + if (evv == 1) {
74 + if (honour_copts == 0) {
75 + error ("someone does not honour COPTS at all in lenient mode");
76 + return false;
77 + } else if (honour_copts != 1) {
78 + warning (0, "someone does not honour COPTS correctly, passed %d times",
79 + honour_copts);
80 + }
81 + } else if (evv == 2) {
82 + if (honour_copts == 0) {
83 + error ("someone does not honour COPTS at all in strict mode");
84 + return false;
85 + } else if (honour_copts != 1) {
86 + error ("someone does not honour COPTS correctly, passed %d times",
87 + honour_copts);
88 + return false;
89 + }
90 + } else if (evv == 0) {
91 + if (honour_copts != 1)
92 + inform (0, "someone does not honour COPTS correctly, passed %d times",
93 + honour_copts);
94 + }
95 + }
96 +
97 return true;
98 }
99
100 --- a/gcc/c-family/c.opt
101 +++ b/gcc/c-family/c.opt
102 @@ -391,6 +391,10 @@ Wfloat-conversion
103 C ObjC C++ ObjC++ Var(warn_float_conversion) LangEnabledBy(C ObjC C++ ObjC++,Wconversion)
104 Warn for implicit type conversions that cause loss of floating point precision
105
106 +Werror-maybe-reset
107 +C ObjC C++ ObjC++
108 +; Documented in common.opt
109 +
110 Wfloat-equal
111 C ObjC C++ ObjC++ Var(warn_float_equal) Warning
112 Warn if testing floating point numbers for equality
113 @@ -972,6 +976,9 @@ C++ ObjC++ Optimization Alias(fexception
114 fhonor-std
115 C++ ObjC++ Ignore Warn(switch %qs is no longer supported)
116
117 +fhonour-copts
118 +C ObjC C++ ObjC++ RejectNegative
119 +
120 fhosted
121 C ObjC
122 Assume normal C execution environment
123 --- a/gcc/common.opt
124 +++ b/gcc/common.opt
125 @@ -549,6 +549,10 @@ Werror=
126 Common Joined
127 Treat specified warning as error
128
129 +Werror-maybe-reset
130 +Common
131 +If environment variable GCC_NO_WERROR is set, act as -Wno-error
132 +
133 Wextra
134 Common Var(extra_warnings) Warning
135 Print extra (possibly unwanted) warnings
136 @@ -1287,6 +1291,9 @@ fguess-branch-probability
137 Common Report Var(flag_guess_branch_prob) Optimization
138 Enable guessing of branch probabilities
139
140 +fhonour-copts
141 +Common RejectNegative
142 +
143 ; Nonzero means ignore `#ident' directives. 0 means handle them.
144 ; Generate position-independent code for executables if possible
145 ; On SVR4 targets, it also controls whether or not to emit a
146 --- a/gcc/opts.c
147 +++ b/gcc/opts.c
148 @@ -1572,6 +1572,17 @@ common_handle_option (struct gcc_options
149 opts, opts_set, loc, dc);
150 break;
151
152 + case OPT_Werror_maybe_reset:
153 + {
154 + char *ev = getenv ("GCC_NO_WERROR");
155 + if ((ev != NULL) && (*ev != '0'))
156 + warnings_are_errors = 0;
157 + }
158 + break;
159 +
160 + case OPT_fhonour_copts:
161 + break;
162 +
163 case OPT_Wlarger_than_:
164 opts->x_larger_than_size = value;
165 opts->x_warn_larger_than = value != -1;
166 --- a/gcc/doc/cppopts.texi
167 +++ b/gcc/doc/cppopts.texi
168 @@ -163,6 +163,11 @@ in older programs. This warning is on b
169 Make all warnings into hard errors. Source code which triggers warnings
170 will be rejected.
171
172 + at item -Werror-maybe-reset
173 + at opindex Werror-maybe-reset
174 +Act like @samp{-Wno-error} if the @env{GCC_NO_WERROR} environment
175 +variable is set to anything other than 0 or empty.
176 +
177 @item -Wsystem-headers
178 @opindex Wsystem-headers
179 Issue warnings for code in system headers. These are normally unhelpful
180 --- a/gcc/doc/invoke.texi
181 +++ b/gcc/doc/invoke.texi
182 @@ -243,7 +243,7 @@ Objective-C and Objective-C++ Dialects}.
183 -Wconversion -Wcoverage-mismatch -Wdate-time -Wdelete-incomplete -Wno-cpp @gol
184 -Wno-deprecated -Wno-deprecated-declarations -Wdisabled-optimization @gol
185 -Wno-div-by-zero -Wdouble-promotion -Wempty-body -Wenum-compare @gol
186 --Wno-endif-labels -Werror -Werror=* @gol
187 +-Wno-endif-labels -Werror -Werror=* -Werror-maybe-reset @gol
188 -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol
189 -Wno-format-contains-nul -Wno-format-extra-args -Wformat-nonliteral @gol
190 -Wformat-security -Wformat-y2k @gol
191 @@ -5042,6 +5042,22 @@ This option is only supported for C and
192 @option{-Wall} and by @option{-Wpedantic}, which can be disabled with
193 @option{-Wno-pointer-sign}.
194
195 + at item -Werror-maybe-reset
196 + at opindex Werror-maybe-reset
197 +Act like @samp{-Wno-error} if the @env{GCC_NO_WERROR} environment
198 +variable is set to anything other than 0 or empty.
199 +
200 + at item -fhonour-copts
201 + at opindex fhonour-copts
202 +If @env{GCC_HONOUR_COPTS} is set to 1, abort if this option is not
203 +given at least once, and warn if it is given more than once.
204 +If @env{GCC_HONOUR_COPTS} is set to 2, abort if this option is not
205 +given exactly once.
206 +If @env{GCC_HONOUR_COPTS} is set to 0 or unset, warn if this option
207 +is not given exactly once.
208 +The warning is quelled if @env{GCC_HONOUR_COPTS} is set to @samp{s}.
209 +This flag and environment variable only affect the C language.
210 +
211 @item -Wstack-protector
212 @opindex Wstack-protector
213 @opindex Wno-stack-protector
214 @@ -7194,7 +7210,7 @@ so, the first branch is redirected to ei
215 second branch or a point immediately following it, depending on whether
216 the condition is known to be true or false.
217
218 -Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}.
219 +Enabled at levels @option{-O3}.
220
221 @item -fsplit-wide-types
222 @opindex fsplit-wide-types
223 --- a/gcc/java/jvspec.c
224 +++ b/gcc/java/jvspec.c
225 @@ -626,6 +626,7 @@ lang_specific_pre_link (void)
226 class name. Append dummy `.c' that can be stripped by set_input so %b
227 is correct. */
228 set_input (concat (main_class_name, "main.c", NULL));
229 + putenv ("GCC_HONOUR_COPTS=s"); /* XXX hack! */
230 err = do_spec (jvgenmain_spec);
231 if (err == 0)
232 {