Skip to content

Commit a250de8

Browse files
[Flang][Driver] Add support for -w option 1/n
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 294eecd commit a250de8

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5698,7 +5698,7 @@ def whatsloaded : Flag<["-"], "whatsloaded">;
56985698
def why_load : Flag<["-"], "why_load">;
56995699
def whyload : Flag<["-"], "whyload">, Alias<why_load>;
57005700
def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">,
5701-
Visibility<[ClangOption, CC1Option]>,
5701+
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
57025702
MarshallingInfoFlag<DiagnosticOpts<"IgnoreWarnings">>;
57035703
def x : JoinedOrSeparate<["-"], "x">,
57045704
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/driver-help-hidden.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
! CHECK-NEXT: -v Show commands to run and use verbose output
163163
! CHECK-NEXT: -Wl,<arg> Pass the comma separated arguments in <arg> to the linker
164164
! CHECK-NEXT: -W<warning> Enable the specified warning
165+
! CHECK-NEXT: -w Suppress all warnings
165166
! CHECK-NEXT: -Xflang <arg> Pass <arg> to the flang compiler
166167
! CHECK-NEXT: -x <language> Treat subsequent input files as having type <language>
167168

flang/test/Driver/w-option.f90

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
! RUN: %flang -c %s 2>&1 | FileCheck %s
2+
! RUN: %flang -c -w %s 2>&1 | FileCheck --allow-empty %s -check-prefix=CHECK-W
3+
! RUN: %flang -c -pedantic %s 2>&1 | FileCheck %s -check-prefixes=CHECK,CHECK-PORT
4+
! RUN: %flang -c -pedantic -w %s 2>&1 | FileCheck --allow-empty %s -check-prefixes=CHECK-W,CHECK-PORT-W
5+
! RUN: %flang -c -w -pedantic %s 2>&1 | FileCheck --allow-empty %s -check-prefixes=CHECK-W,CHECK-PORT-W
6+
! CHECK: warning: Label '40' is in a construct that should not be used as a branch target here
7+
! CHECK: warning: Label '50' is in a construct that should not be used as a branch target here
8+
! CHECK-W-NOT: warning
9+
! CHECK-PORT: portability: Statement function 'sf1' should not contain an array constructor
10+
! CHECK-PORT-W-NOT: portability
11+
12+
subroutine sub01(n)
13+
integer n
14+
GOTO (40,50,60) n
15+
if (n .eq. 1) then
16+
40 print *, "xyz"
17+
50 end if
18+
60 continue
19+
end subroutine sub01
20+
21+
subroutine sub02
22+
sf1(n) = sum([(j,j=1,n)])
23+
end subroutine sub02

0 commit comments

Comments
 (0)