Skip to content

[NFC][Fuzzer] Refactor to avoid a false warning from gcc #112944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,18 @@ static void handleLLVMFatalError(void *, const char *Message, bool) {
extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
char ***argv) {
EnableDebugBuffering = true;
StringRef ExecName = *argv[0];

InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmPrinters();
InitializeAllAsmParsers();

handleExecNameEncodedBEOpts(*argv[0]);
handleExecNameEncodedBEOpts(ExecName);
parseFuzzerCLOpts(*argc, *argv);

if (TargetTriple.empty()) {
errs() << *argv[0] << ": -mtriple must be specified\n";
errs() << ExecName << ": -mtriple must be specified\n";
exit(1);
}

Expand All @@ -135,10 +136,10 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
if (auto Level = CodeGenOpt::parseLevel(OptLevel)) {
OLvl = *Level;
} else {
errs() << argv[0] << ": invalid optimization level.\n";
errs() << ExecName << ": invalid optimization level.\n";
return 1;
}
ExitOnError ExitOnErr(std::string(*argv[0]) + ": error:");
ExitOnError ExitOnErr(std::string(ExecName) + ": error:");
TM = ExitOnErr(codegen::createTargetMachineForTriple(
Triple::normalize(TargetTriple), OLvl));
assert(TM && "Could not allocate target machine!");
Expand Down
12 changes: 6 additions & 6 deletions llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ static void handleLLVMFatalError(void *, const char *Message, bool) {
extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
char ***argv) {
EnableDebugBuffering = true;
StringRef ExecName = *argv[0];

// Make sure we print the summary and the current unit when LLVM errors out.
install_fatal_error_handler(handleLLVMFatalError, nullptr);
Expand All @@ -188,32 +189,31 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
// Parse input options
//

handleExecNameEncodedOptimizerOpts(*argv[0]);
handleExecNameEncodedOptimizerOpts(ExecName);
parseFuzzerCLOpts(*argc, *argv);

// Create TargetMachine
//

if (TargetTripleStr.empty()) {
errs() << *argv[0] << ": -mtriple must be specified\n";
errs() << ExecName << ": -mtriple must be specified\n";
exit(1);
}
ExitOnError ExitOnErr(std::string(*argv[0]) + ": error:");
ExitOnError ExitOnErr(std::string(ExecName) + ": error:");
TM = ExitOnErr(codegen::createTargetMachineForTriple(
Triple::normalize(TargetTripleStr)));

// Check that pass pipeline is specified and correct
//

if (PassPipeline.empty()) {
errs() << *argv[0] << ": at least one pass should be specified\n";
errs() << ExecName << ": at least one pass should be specified\n";
exit(1);
}

PassBuilder PB(TM.get());
ModulePassManager MPM;
if (auto Err = PB.parsePassPipeline(MPM, PassPipeline)) {
errs() << *argv[0] << ": " << toString(std::move(Err)) << "\n";
errs() << ExecName << ": " << toString(std::move(Err)) << "\n";
exit(1);
}

Expand Down
Loading