Skip to content

Commit c505ce9

Browse files
authored
Deprecate -fheinous-gnu-extensions; introduce a new warning flag (#105821)
The new warning flag is `-Winvalid-gnu-asm-cast`, which is enabled by default and is a downgradable diagnostic which defaults to an error. This language dialect flag only controls whether a single diagnostic is emitted as a warning or as an error, and has never been expanded to include other behaviors. Given the rather perjorative name, it's better for us to just expose a diagnostic flag for the one warning in question and let the user elect to do `-Wno-error=` if they need to. There's not a lot of use of the language dialect flag in the wild, but there is some use of it. For the time being, this aliases the -f flag to `-Wno-error=invalid-gnu-asm-cast`, but the -f flag can eventually be removed.
1 parent 52a7116 commit c505ce9

File tree

12 files changed

+40
-32
lines changed

12 files changed

+40
-32
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ New Compiler Flags
174174
Deprecated Compiler Flags
175175
-------------------------
176176

177+
- ``-fheinous-gnu-extensions`` is deprecated; it is now equivalent to
178+
specifying ``-Wno-error=invalid-gnu-asm-cast`` and may be removed in the
179+
future.
180+
177181
Modified Compiler Flags
178182
-----------------------
179183

@@ -238,6 +242,11 @@ Improvements to Clang's diagnostics
238242

239243
- Improved diagnostic when trying to befriend a concept. (#GH45182).
240244

245+
- Added the ``-Winvalid-gnu-asm-cast`` diagnostic group to control warnings
246+
about use of "noop" casts for lvalues (a GNU extension). This diagnostic is
247+
a warning which defaults to being an error, is enabled by default, and is
248+
also controlled by the now-deprecated ``-fheinous-gnu-extensions`` flag.
249+
241250
Improvements to Clang's time-trace
242251
----------------------------------
243252

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9365,9 +9365,6 @@ let CategoryName = "Inline Assembly Issue" in {
93659365
"invalid input size for constraint '%0'">;
93669366
def err_asm_invalid_output_size : Error<
93679367
"invalid output size for constraint '%0'">;
9368-
def err_invalid_asm_cast_lvalue : Error<
9369-
"invalid use of a cast in a inline asm context requiring an lvalue: "
9370-
"remove the cast or build with -fheinous-gnu-extensions">;
93719368
def err_invalid_asm_value_for_constraint
93729369
: Error <"value '%0' out of range for constraint '%1'">;
93739370
def err_asm_non_addr_value_in_memory_constraint : Error <
@@ -9381,9 +9378,8 @@ let CategoryName = "Inline Assembly Issue" in {
93819378
def warn_asm_label_on_auto_decl : Warning<
93829379
"ignored asm label '%0' on automatic variable">;
93839380
def warn_invalid_asm_cast_lvalue : Warning<
9384-
"invalid use of a cast in an inline asm context requiring an lvalue: "
9385-
"accepted due to -fheinous-gnu-extensions, but clang may remove support "
9386-
"for this in the future">;
9381+
"invalid use of a cast in an inline asm context requiring an lvalue">,
9382+
InGroup<DiagGroup<"invalid-gnu-asm-cast">>, DefaultError;
93879383
def warn_asm_mismatched_size_modifier : Warning<
93889384
"value size does not match register size specified by the constraint "
93899385
"and modifier">,

clang/include/clang/Basic/LangOptions.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ LANGOPT(POSIXThreads , 1, 0, "POSIX thread support")
190190
LANGOPT(Blocks , 1, 0, "blocks extension to C")
191191
BENIGN_LANGOPT(EmitAllDecls , 1, 0, "emitting all declarations")
192192
LANGOPT(MathErrno , 1, 1, "errno in math functions")
193-
BENIGN_LANGOPT(HeinousExtensions , 1, 0, "extensions that we really don't like and may be ripped out at any time")
194193
LANGOPT(Modules , 1, 0, "modules semantics")
195194
COMPATIBLE_LANGOPT(CPlusPlusModules, 1, 0, "C++ modules syntax")
196195
LANGOPT(SkipODRCheckInGMF, 1, 0, "Skip ODR checks for decls in the global module fragment")

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,8 @@ def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group<W_Group>,
10111011
Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>;
10121012
def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group<W_Group>,
10131013
Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>;
1014+
def Winvalid_gnu_asm_cast : Flag<["-"], "Winvalid-gnu-asm-cast">, Group<W_Group>,
1015+
Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>;
10141016
def W_Joined : Joined<["-"], "W">, Group<W_Group>,
10151017
Visibility<[ClangOption, CC1Option, CLOption, DXCOption, FC1Option, FlangOption]>,
10161018
MetaVarName<"<warning>">, HelpText<"Enable the specified warning">;
@@ -2761,9 +2763,13 @@ defm gnu89_inline : BoolFOption<"gnu89-inline",
27612763
NegFlag<SetFalse>>, ShouldParseIf<!strconcat("!", cplusplus.KeyPath)>;
27622764
def fgnu_runtime : Flag<["-"], "fgnu-runtime">, Group<f_Group>,
27632765
HelpText<"Generate output compatible with the standard GNU Objective-C runtime">;
2766+
// This used to be a standalone flag but is now mapped to
2767+
// -Wno-error=invalid-gnu-asm-cast, which is the only thing the flag used to
2768+
// control.
27642769
def fheinous_gnu_extensions : Flag<["-"], "fheinous-gnu-extensions">,
2765-
Visibility<[ClangOption, CC1Option]>,
2766-
MarshallingInfoFlag<LangOpts<"HeinousExtensions">>;
2770+
Alias<W_Joined>, AliasArgs<["no-error=invalid-gnu-asm-cast"]>,
2771+
HelpText<"(Deprecated) Controls whether '-Winvalid-gnu-asm-cast' defaults to "
2772+
"an error or a warning">;
27672773
def filelist : Separate<["-"], "filelist">, Flags<[LinkerInput]>,
27682774
Group<Link_Group>;
27692775
def : Flag<["-"], "findirect-virtual-calls">, Alias<fapple_kext>;

clang/lib/Sema/SemaStmtAsm.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,8 @@ static void removeLValueToRValueCast(Expr *E) {
7171
/// and fix the argument with removing LValueToRValue cast from the expression.
7272
static void emitAndFixInvalidAsmCastLValue(const Expr *LVal, Expr *BadArgument,
7373
Sema &S) {
74-
if (!S.getLangOpts().HeinousExtensions) {
75-
S.Diag(LVal->getBeginLoc(), diag::err_invalid_asm_cast_lvalue)
76-
<< BadArgument->getSourceRange();
77-
} else {
78-
S.Diag(LVal->getBeginLoc(), diag::warn_invalid_asm_cast_lvalue)
79-
<< BadArgument->getSourceRange();
80-
}
74+
S.Diag(LVal->getBeginLoc(), diag::warn_invalid_asm_cast_lvalue)
75+
<< BadArgument->getSourceRange();
8176
removeLValueToRValueCast(BadArgument);
8277
}
8378

clang/test/Analysis/asm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_analyze_cc1 -triple=x86_64-unknown-unknown \
2-
// RUN: -analyzer-checker debug.ExprInspection,core -fheinous-gnu-extensions -w %s -verify
2+
// RUN: -analyzer-checker debug.ExprInspection,core -Wno-error=invalid-gnu-asm-cast -w %s -verify
33

44
int clang_analyzer_eval(int);
55

clang/test/Analysis/cfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -fheinous-gnu-extensions %s > %t 2>&1
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -Wno-error=invalid-gnu-asm-cast %s > %t 2>&1
22
// RUN: FileCheck --input-file=%t --check-prefix=CHECK %s
33

44
// This file is the C version of cfg.cpp.

clang/test/Analysis/cfg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -fheinous-gnu-extensions -std=c++11 -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -Wno-error=invalid-gnu-asm-cast -std=c++11 -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
22
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s
3-
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -fheinous-gnu-extensions -std=c++11 -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
3+
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -Wno-error=invalid-gnu-asm-cast -std=c++11 -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
44
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s
55

66
// This file tests how we construct two different flavors of the Clang CFG -
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang -### -fsyntax-only -fheinous-gnu-extensions %s 2>&1 | FileCheck %s
2+
3+
// CHECK: -Wno-error=invalid-gnu-asm-cast
4+
5+
int main(void) {}

clang/test/Misc/warning-flags.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This test serves two purposes:
1818

1919
The list of warnings below should NEVER grow. It should gradually shrink to 0.
2020

21-
CHECK: Warnings without flags (64):
21+
CHECK: Warnings without flags (63):
2222

2323
CHECK-NEXT: ext_expected_semi_decl_list
2424
CHECK-NEXT: ext_missing_whitespace_after_macro_name
@@ -55,7 +55,6 @@ CHECK-NEXT: warn_fe_macro_contains_embedded_newline
5555
CHECK-NEXT: warn_ignoring_ftabstop_value
5656
CHECK-NEXT: warn_implements_nscopying
5757
CHECK-NEXT: warn_incompatible_qualified_id
58-
CHECK-NEXT: warn_invalid_asm_cast_lvalue
5958
CHECK-NEXT: warn_invalid_cpu_supports
6059
CHECK-NEXT: warn_maynot_respond
6160
CHECK-NEXT: warn_method_param_redefinition
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// RUN: %clang_cc1 %s -verify
22

3-
int foo(void) {
4-
int a;
5-
// PR3788
6-
asm("nop" : : "m"((int)(a))); // expected-error {{cast in a inline asm context requiring an lvalue}}
7-
// PR3794
8-
asm("nop" : "=r"((unsigned)a)); // expected-error {{cast in a inline asm context requiring an lvalue}}
3+
void foo(void) {
4+
int a;
5+
// PR3788
6+
asm("nop" : : "m"((int)(a))); // expected-error {{invalid use of a cast in an inline asm context requiring an lvalue}}
7+
// PR3794
8+
asm("nop" : "=r"((unsigned)a)); // expected-error {{invalid use of a cast in an inline asm context requiring an lvalue}}
99
}
10-
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// RUN: %clang_cc1 %s -verify -fheinous-gnu-extensions
1+
// RUN: %clang_cc1 %s -verify -Wno-error=invalid-gnu-asm-cast
22

33
void foo(void) {
44
int a;
55
// PR3788
6-
asm("nop" : : "m"((int)(a))); // expected-warning {{cast in an inline asm context requiring an lvalue}}
6+
asm("nop" : : "m"((int)(a))); // expected-warning {{invalid use of a cast in an inline asm context requiring an lvalue}}
77
// PR3794
8-
asm("nop" : "=r"((unsigned)a)); // expected-warning {{cast in an inline asm context requiring an lvalue}}
8+
asm("nop" : "=r"((unsigned)a)); // expected-warning {{invalid use of a cast in an inline asm context requiring an lvalue}}
99
}

0 commit comments

Comments
 (0)