Skip to content

Commit 2a0483f

Browse files
committed
[NFC][Fuzzer] Fix zero-size array argv warning
This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11. Fix 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 dca43a1 commit 2a0483f

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
124124
handleExecNameEncodedBEOpts(*argv[0]);
125125
parseFuzzerCLOpts(*argc, *argv);
126126

127+
std::string execName = *argv[0];
128+
127129
if (TargetTriple.empty()) {
128-
errs() << *argv[0] << ": -mtriple must be specified\n";
130+
errs() << execName << ": -mtriple must be specified\n";
129131
exit(1);
130132
}
131133

@@ -135,10 +137,10 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
135137
if (auto Level = CodeGenOpt::parseLevel(OptLevel)) {
136138
OLvl = *Level;
137139
} else {
138-
errs() << argv[0] << ": invalid optimization level.\n";
140+
errs() << execName << ": invalid optimization level.\n";
139141
return 1;
140142
}
141-
ExitOnError ExitOnErr(std::string(*argv[0]) + ": error:");
143+
ExitOnError ExitOnErr(std::string(execName) + ": error:");
142144
TM = ExitOnErr(codegen::createTargetMachineForTriple(
143145
Triple::normalize(TargetTriple), OLvl));
144146
assert(TM && "Could not allocate target machine!");

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,27 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
193193

194194
// Create TargetMachine
195195
//
196-
196+
std::string execName = *argv[0];
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)