-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@@ -193,27 +193,27 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc, | |||
|
|||
// Create TargetMachine | |||
// | |||
|
|||
std::string execName = *argv[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest doing something like this instead:
diff --git a/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp b/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
index fcccf0e07ef8..8e8e73967e3c 100644
--- a/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
+++ b/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
@@ -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);
@@ -188,17 +189,17 @@ 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)));
@@ -206,14 +207,14 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
//
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);
}
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:"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do this rather small change if it makes life simpler for those using gcc.
Afaict the problem is that the warning was incorrect/false, right?
It would be nice if the commit message say something about that this just refactors the code to avoid a false warning from gcc, rather than saying that it fixes a warning (because the end result is supposed to be the same, so if I understand correctly this patch is a NFC refactoring and not really fixing a problem with zero-size arrays).
So LG, if you update the commit message to clarify that part.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/7972 Here is the relevant piece of the build log for the reference
|
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:");
|