Skip to content

Commit 764706e

Browse files
authored
[clang] Added a new option '-fdisable-try-stmt'
1 parent 9cb524f commit 764706e

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ CODEGENOPT(SanitizeMemoryUseAfterDtor, 1, 0) ///< Enable use-after-delete detect
247247
CODEGENOPT(SanitizeCfiCrossDso, 1, 0) ///< Enable cross-dso support in CFI.
248248
CODEGENOPT(Jumptablerdata, 1, 0) ///< Put switch case jump tables in .rdata
249249
CODEGENOPT(DisableInlineOpt, 1, 0) ///< Disables the optimization of inline functions.
250+
CODEGENOPT(DisableTryStmt, 1, 0) ///< Disables the try statements.
250251
CODEGENOPT(DisableCFICheckFail, 1, 0) ///< Disables the failure checks in CFI.
251252
CODEGENOPT(DisableCFICheck, 1, 0) ///< Disables the checks in CFI.
252253
CODEGENOPT(DisableCFISlowPathCheck, 1, 0) ///< Disables the slow path checks in CFI.

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,10 @@ def fdisable_inline_opt : Flag<["-"], "fdisable-inline-opt">,
24392439
Group<f_clang_Group>,
24402440
HelpText<"Disables the optimization of inline functions">,
24412441
MarshallingInfoFlag<CodeGenOpts<"DisableInlineOpt">>;
2442+
def fdisable_try_stmt : Flag<["-"], "fdisable-try-stmt">,
2443+
Group<f_clang_Group>,
2444+
HelpText<"Disables the try statements">,
2445+
MarshallingInfoFlag<CodeGenOpts<"DisableTryStmt">>;
24422446
def fdisable_cfi_check : Flag<["-"], "fdisable-cfi-check">,
24432447
Group<f_clang_Group>,
24442448
HelpText<"Disables the checks in CFI">,

clang/lib/CodeGen/CGException.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,14 @@ void CodeGenFunction::FixSEHEnd(llvm::InvokeInst *InvokeIst) {
630630
}
631631

632632
void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) {
633+
634+
// If try statements are disabled, just emit the try statement as a compound
635+
// stmt.
636+
if (CGM.getCodeGenOpts().DisableTryStmt) {
637+
EmitStmt(S.getTryBlock());
638+
return;
639+
}
640+
633641
const llvm::Triple &T = Target.getTriple();
634642
// If we encounter a try statement on in an OpenMP target region offloaded to
635643
// a GPU, we treat it as a basic block.
@@ -1741,6 +1749,14 @@ llvm::BasicBlock *CodeGenFunction::getEHResumeBlock(bool isCleanup) {
17411749
}
17421750

17431751
void CodeGenFunction::EmitSEHTryStmt(const SEHTryStmt &S) {
1752+
1753+
// If try statements are disabled, just emit the try statement as a compound
1754+
// stmt.
1755+
if (CGM.getCodeGenOpts().DisableTryStmt) {
1756+
EmitStmt(S.getTryBlock());
1757+
return;
1758+
}
1759+
17441760
bool ContainsRetStmt = false;
17451761
EnterSEHTryStmt(S, ContainsRetStmt);
17461762
{

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,11 @@ void CodeGenModule::Release() {
10471047
getModule().addModuleFlag(llvm::Module::Override, "DisableInlineOpt", 1);
10481048
}
10491049

1050+
if (CodeGenOpts.DisableTryStmt) {
1051+
// Indicate that we want to disable the try statements.
1052+
getModule().addModuleFlag(llvm::Module::Override, "DisableTryStmt", 1);
1053+
}
1054+
10501055
if (CodeGenOpts.Jumptablerdata) {
10511056
// Indicate that we want to emit jump table to .rdata.
10521057
getModule().addModuleFlag(llvm::Module::Override, "Jumptablerdata", 1);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6797,6 +6797,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
67976797
if (Args.hasArg(options::OPT_fdisable_inline_opt))
67986798
CmdArgs.push_back("-fdisable-inline-opt");
67996799

6800+
// -fdisable-try-stmt(Disables the try statements)
6801+
if (Args.hasArg(options::OPT_fdisable_try_stmt))
6802+
CmdArgs.push_back("-fdisable-try-stmt");
6803+
68006804
// -fdisable-cfi-check(Disables the checks in CFI)
68016805
if (Args.hasArg(options::OPT_fdisable_cfi_check))
68026806
CmdArgs.push_back("-fdisable-cfi-check");

0 commit comments

Comments
 (0)