[clang] e625f9c - -fbasic-block-sections=list=: Suppress output if failed to open the file
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 9 09:26:43 PST 2020
Author: Fangrui Song
Date: 2020-11-09T09:26:37-08:00
New Revision: e625f9c5d1e2e69d18febae0e8d3f808df35c4c8
URL: https://github.com/llvm/llvm-project/commit/e625f9c5d1e2e69d18febae0e8d3f808df35c4c8
DIFF: https://github.com/llvm/llvm-project/commit/e625f9c5d1e2e69d18febae0e8d3f808df35c4c8.diff
LOG: -fbasic-block-sections=list=: Suppress output if failed to open the file
Reviewed By: tmsriram
Differential Revision: https://reviews.llvm.org/D90815
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/basic-block-sections.c
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 81ae79482d90..a5ca113b9e77 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -446,7 +446,7 @@ static CodeGenFileType getCodeGenFileType(BackendAction Action) {
}
}
-static void initTargetOptions(DiagnosticsEngine &Diags,
+static bool initTargetOptions(DiagnosticsEngine &Diags,
llvm::TargetOptions &Options,
const CodeGenOptions &CodeGenOpts,
const clang::TargetOptions &TargetOpts,
@@ -517,11 +517,12 @@ static void initTargetOptions(DiagnosticsEngine &Diags,
if (Options.BBSections == llvm::BasicBlockSection::List) {
ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
MemoryBuffer::getFile(CodeGenOpts.BBSections.substr(5));
- if (!MBOrErr)
+ if (!MBOrErr) {
Diags.Report(diag::err_fe_unable_to_load_basic_block_sections_file)
<< MBOrErr.getError().message();
- else
- Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
+ return false;
+ }
+ Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
}
Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
@@ -572,6 +573,8 @@ static void initTargetOptions(DiagnosticsEngine &Diags,
Entry.IgnoreSysRoot ? Entry.Path : HSOpts.Sysroot + Entry.Path);
Options.MCOptions.Argv0 = CodeGenOpts.Argv0;
Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
+
+ return true;
}
static Optional<GCOVOptions> getGCOVOptions(const CodeGenOptions &CodeGenOpts,
@@ -858,7 +861,9 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
CodeGenOpt::Level OptLevel = getCGOptLevel(CodeGenOpts);
llvm::TargetOptions Options;
- initTargetOptions(Diags, Options, CodeGenOpts, TargetOpts, LangOpts, HSOpts);
+ if (!initTargetOptions(Diags, Options, CodeGenOpts, TargetOpts, LangOpts,
+ HSOpts))
+ return;
TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
Options, RM, CM, OptLevel));
}
diff --git a/clang/test/CodeGen/basic-block-sections.c b/clang/test/CodeGen/basic-block-sections.c
index 0381bc78c6a9..805539f06f08 100644
--- a/clang/test/CodeGen/basic-block-sections.c
+++ b/clang/test/CodeGen/basic-block-sections.c
@@ -6,7 +6,9 @@
// RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all -o - < %s | FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_ALL
// RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=list=%S/Inputs/basic-block-sections.funcnames -o - < %s | FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_LIST
// RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all -funique-basic-block-section-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
-// RUN: not %clang_cc1 -fbasic-block-sections=list= -emit-llvm -o - %s 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: rm -f %t
+// RUN: not %clang_cc1 -fbasic-block-sections=list= -emit-obj -o %t %s 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: not ls %t
int world(int a) {
if (a > 10)
More information about the cfe-commits
mailing list