Skip to content

Commit b1f5cfd

Browse files
stuellisbanach-space
authored andcommitted
[flang][driver] Add support for the "-init-only" option
Adding the `-init-only` option and corresponding frontend action to generate a diagnostic. `-init-only` vs `-test-io`: `-init-only` ignores the input (it never calls the prescanner) `-test-io` is similar to `-init-only`, but does read and print the input without calling the prescanner. This patch also adds a Driver test to check this action. Reviewed By: awarzynski, AMDChirag Differential Revision: https://reviews.llvm.org/D102849
1 parent 93d3219 commit b1f5cfd

File tree

8 files changed

+33
-4
lines changed

8 files changed

+33
-4
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5275,8 +5275,6 @@ def analyze : Flag<["-"], "analyze">,
52755275
HelpText<"Run static analysis engine">;
52765276
def dump_tokens : Flag<["-"], "dump-tokens">,
52775277
HelpText<"Run preprocessor, dump internal rep of tokens">;
5278-
def init_only : Flag<["-"], "init-only">,
5279-
HelpText<"Only execute frontend initialization">;
52805278
def fixit : Flag<["-"], "fixit">,
52815279
HelpText<"Apply fix-it advice to the input source">;
52825280
def fixit_EQ : Joined<["-"], "fixit=">,
@@ -5742,6 +5740,8 @@ let Group = Action_Group in {
57425740

57435741
def emit_obj : Flag<["-"], "emit-obj">,
57445742
HelpText<"Emit native object files">;
5743+
def init_only : Flag<["-"], "init-only">,
5744+
HelpText<"Only execute frontend initialization">;
57455745

57465746
} // let Group = Action_Group
57475747
} // let Flags = [CC1Option, FC1Option, NoDriverOption]

flang/include/flang/Frontend/FrontendActions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class EmitObjAction : public FrontendAction {
3838
void ExecuteAction() override;
3939
};
4040

41+
class InitOnlyAction : public FrontendAction {
42+
void ExecuteAction() override;
43+
};
44+
4145
//===----------------------------------------------------------------------===//
4246
// Prescan Actions
4347
//===----------------------------------------------------------------------===//

flang/include/flang/Frontend/FrontendOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ enum ActionKind {
7474
GetDefinition,
7575

7676
/// Parse, run semantics and then dump symbol sources map
77-
GetSymbolsSources
77+
GetSymbolsSources,
78+
79+
/// Only execute frontend initialization
80+
InitOnly
7881

7982
/// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
8083
/// EmitCodeGenOnly, EmitAssembly, (...)

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,12 @@ static bool ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
165165
case clang::driver::options::OPT_fget_definition:
166166
opts.programAction_ = GetDefinition;
167167
break;
168+
case clang::driver::options::OPT_init_only:
169+
opts.programAction_ = InitOnly;
170+
break;
168171

169172
// TODO:
170-
// case calng::driver::options::OPT_emit_llvm:
173+
// case clang::driver::options::OPT_emit_llvm:
171174
// case clang::driver::options::OPT_emit_llvm_only:
172175
// case clang::driver::options::OPT_emit_codegen_only:
173176
// case clang::driver::options::OPT_emit_module:

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,11 @@ void EmitObjAction::ExecuteAction() {
484484
clang::DiagnosticsEngine::Error, "code-generation is not available yet");
485485
ci.diagnostics().Report(DiagID);
486486
}
487+
488+
void InitOnlyAction::ExecuteAction() {
489+
CompilerInstance &ci = this->instance();
490+
unsigned DiagID =
491+
ci.diagnostics().getCustomDiagID(clang::DiagnosticsEngine::Warning,
492+
"Use `-init-only` for testing purposes only");
493+
ci.diagnostics().Report(DiagID);
494+
}

flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
7676
case GetSymbolsSources:
7777
return std::make_unique<GetSymbolsSourcesAction>();
7878
break;
79+
case InitOnly:
80+
return std::make_unique<InitOnlyAction>();
81+
break;
7982
default:
8083
break;
8184
// TODO:

flang/test/Driver/driver-help.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
108108
! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
109109
! HELP-FC1-NEXT: -help Display available options
110+
! HELP-FC1-NEXT: -init-only Only execute frontend initialization
110111
! HELP-FC1-NEXT: -I <dir> Add directory to the end of the list of include search paths
111112
! HELP-FC1-NEXT: -module-dir <dir> Put MODULE files in <dir>
112113
! HELP-FC1-NEXT: -module-suffix <suffix> Use <suffix> as the suffix for module files (the default value is `.mod`)

flang/test/Driver/init-only.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
! Verify that -init-only flag generates a diagnostic as expected
2+
3+
! REQUIRES: new-flang-driver
4+
5+
! RUN: %flang_fc1 -init-only 2>&1 | FileCheck %s
6+
7+
! CHECK: warning: Use `-init-only` for testing purposes only

0 commit comments

Comments
 (0)