Skip to content

Commit d985197

Browse files
authored
[NFC][Fuzzer] Refactor to avoid a false warning from gcc (#112944)
This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11. Refactor the code to avoid the false warning llvm-project/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp llvm-project/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp: In function ‘int LLVMFuzzerInitialize(int*, char***)’: llvm-project/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp:141:43: error: ISO C++ forbids zero-size array ‘argv’ [-Werror=pedantic] 141 | ExitOnError ExitOnErr(std::string(*argv[0]) + ": error:"); |
1 parent 519eef3 commit d985197

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,18 @@ static void handleLLVMFatalError(void *, const char *Message, bool) {
115115
extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
116116
char ***argv) {
117117
EnableDebugBuffering = true;
118+
StringRef ExecName = *argv[0];
118119

119120
InitializeAllTargets();
120121
InitializeAllTargetMCs();
121122
InitializeAllAsmPrinters();
122123
InitializeAllAsmParsers();
123124

124-
handleExecNameEncodedBEOpts(*argv[0]);
125+
handleExecNameEncodedBEOpts(ExecName);
125126
parseFuzzerCLOpts(*argc, *argv);
126127

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

@@ -135,10 +136,10 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
135136
if (auto Level = CodeGenOpt::parseLevel(OptLevel)) {
136137
OLvl = *Level;
137138
} else {
138-
errs() << argv[0] << ": invalid optimization level.\n";
139+
errs() << ExecName << ": invalid optimization level.\n";
139140
return 1;
140141
}
141-
ExitOnError ExitOnErr(std::string(*argv[0]) + ": error:");
142+
ExitOnError ExitOnErr(std::string(ExecName) + ": error:");
142143
TM = ExitOnErr(codegen::createTargetMachineForTriple(
143144
Triple::normalize(TargetTriple), OLvl));
144145
assert(TM && "Could not allocate target machine!");

llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ static void handleLLVMFatalError(void *, const char *Message, bool) {
175175
extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
176176
char ***argv) {
177177
EnableDebugBuffering = true;
178+
StringRef ExecName = *argv[0];
178179

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

191-
handleExecNameEncodedOptimizerOpts(*argv[0]);
192+
handleExecNameEncodedOptimizerOpts(ExecName);
192193
parseFuzzerCLOpts(*argc, *argv);
193194

194195
// Create TargetMachine
195196
//
196-
197197
if (TargetTripleStr.empty()) {
198-
errs() << *argv[0] << ": -mtriple must be specified\n";
198+
errs() << ExecName << ": -mtriple must be specified\n";
199199
exit(1);
200200
}
201-
ExitOnError ExitOnErr(std::string(*argv[0]) + ": error:");
201+
ExitOnError ExitOnErr(std::string(ExecName) + ": error:");
202202
TM = ExitOnErr(codegen::createTargetMachineForTriple(
203203
Triple::normalize(TargetTripleStr)));
204204

205205
// Check that pass pipeline is specified and correct
206206
//
207207

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

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

0 commit comments

Comments
 (0)