Skip to content

Commit 602df27

Browse files
[Flang] RFC: Add support for -w option 1/n (#90420)
Add support for the -w option to switch OFF all Flang warnings. This patch only supports switching OFF the frontend warnings. TODO : Support for MLIR, LLVM and Driver warnings. TODO : Support interactions between -w, -pedantic, -Wall
1 parent 746bf29 commit 602df27

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5703,7 +5703,7 @@ def whatsloaded : Flag<["-"], "whatsloaded">;
57035703
def why_load : Flag<["-"], "why_load">;
57045704
def whyload : Flag<["-"], "whyload">, Alias<why_load>;
57055705
def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">,
5706-
Visibility<[ClangOption, CC1Option]>,
5706+
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
57075707
MarshallingInfoFlag<DiagnosticOpts<"IgnoreWarnings">>;
57085708
def x : JoinedOrSeparate<["-"], "x">,
57095709
Flags<[NoXarchOption]>,

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
748748
// Add other compile options
749749
addOtherOptions(Args, CmdArgs);
750750

751+
// Disable all warnings
752+
// TODO: Handle interactions between -w, -pedantic, -Wall, -WOption
753+
Args.AddLastArg(CmdArgs, options::OPT_w);
754+
751755
// Forward flags for OpenMP. We don't do this if the current action is an
752756
// device offloading action other than OpenMP.
753757
if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,

flang/include/flang/Frontend/CompilerInvocation.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ class CompilerInvocation : public CompilerInvocationBase {
114114
// Fortran Dialect options
115115
Fortran::common::IntrinsicTypeDefaultKinds defaultKinds;
116116

117+
// Fortran Warning options
117118
bool enableConformanceChecks = false;
118119
bool enableUsageChecks = false;
120+
bool disableWarnings = false;
119121

120122
/// Used in e.g. unparsing to dump the analyzed rather than the original
121123
/// parse-tree objects.
@@ -197,6 +199,9 @@ class CompilerInvocation : public CompilerInvocationBase {
197199
bool &getEnableUsageChecks() { return enableUsageChecks; }
198200
const bool &getEnableUsageChecks() const { return enableUsageChecks; }
199201

202+
bool &getDisableWarnings() { return disableWarnings; }
203+
const bool &getDisableWarnings() const { return disableWarnings; }
204+
200205
Fortran::parser::AnalyzedObjectsAsFortran &getAsFortran() {
201206
return asFortran;
202207
}
@@ -226,6 +231,9 @@ class CompilerInvocation : public CompilerInvocationBase {
226231
// Enables the usage checks
227232
void setEnableUsageChecks() { enableUsageChecks = true; }
228233

234+
// Disables all Warnings
235+
void setDisableWarnings() { disableWarnings = true; }
236+
229237
/// Useful setters
230238
void setArgv0(const char *dir) { argv0 = dir; }
231239

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,11 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
975975
res.setEnableConformanceChecks();
976976
res.setEnableUsageChecks();
977977
}
978+
979+
// -w
980+
if (args.hasArg(clang::driver::options::OPT_w))
981+
res.setDisableWarnings();
982+
978983
// -std=f2018
979984
// TODO: Set proper options when more fortran standards
980985
// are supported.
@@ -1403,6 +1408,11 @@ void CompilerInvocation::setFortranOpts() {
14031408

14041409
if (getEnableUsageChecks())
14051410
fortranOptions.features.WarnOnAllUsage();
1411+
1412+
if (getDisableWarnings()) {
1413+
fortranOptions.features.DisableAllNonstandardWarnings();
1414+
fortranOptions.features.DisableAllUsageWarnings();
1415+
}
14061416
}
14071417

14081418
std::unique_ptr<Fortran::semantics::SemanticsContext>

flang/test/Driver/w-option.f90

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
! Test the default setting. Emit warnings only.
2+
! RUN: %flang -c %s 2>&1 | FileCheck %s -check-prefix=DEFAULT
3+
4+
! Test that the warnings are not generated with `-w` option.
5+
! RUN: %flang -c -w %s 2>&1 | FileCheck --allow-empty %s -check-prefix=WARNING
6+
7+
! Test that warnings are portability messages are generated.
8+
! RUN: %flang -c -pedantic %s 2>&1 | FileCheck %s -check-prefixes=DEFAULT,PORTABILITY
9+
10+
! Test that warnings and portability messages are not generated.
11+
! TODO: Support the last flag wins behaviour.
12+
! RUN: %flang -c -pedantic -w %s 2>&1 | FileCheck --allow-empty %s -check-prefixes=WARNING,PORTABILITY-WARNING
13+
! RUN: %flang -c -w -pedantic %s 2>&1 | FileCheck --allow-empty %s -check-prefixes=WARNING,PORTABILITY-WARNING
14+
! DEFAULT: warning: Label '40' is in a construct that should not be used as a branch target here
15+
! DEFAULT: warning: Label '50' is in a construct that should not be used as a branch target here
16+
! WARNING-NOT: warning
17+
! PORTABILITY: portability: Statement function 'sf1' should not contain an array constructor
18+
! PORTABILITY-WARNING-NOT: portability
19+
20+
subroutine sub01(n)
21+
integer n
22+
GOTO (40,50,60) n
23+
if (n .eq. 1) then
24+
40 print *, "xyz"
25+
50 end if
26+
60 continue
27+
end subroutine sub01
28+
29+
subroutine sub02
30+
sf1(n) = sum([(j,j=1,n)])
31+
end subroutine sub02

0 commit comments

Comments
 (0)