[llvm] [NFC][Fuzzer] Fix zero-size array argv warning (PR #112944)

Jinsong Ji via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 19 06:27:15 PDT 2024


https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/112944

>From 1b0d4c32710d3e70206b59b45339fb1eda39056c Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 19:41:43 +0200
Subject: [PATCH] [NFC][Fuzzer] Fix zero-size array argv warning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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:");
      |
---
 llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp |  8 +++++---
 llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp   | 10 +++++-----
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp b/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
index 742f7b94e116f3..e91c7a9c3618d0 100644
--- a/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
+++ b/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
@@ -124,8 +124,10 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
   handleExecNameEncodedBEOpts(*argv[0]);
   parseFuzzerCLOpts(*argc, *argv);
 
+  std::string execName = *argv[0];
+
   if (TargetTriple.empty()) {
-    errs() << *argv[0] << ": -mtriple must be specified\n";
+    errs() << execName << ": -mtriple must be specified\n";
     exit(1);
   }
 
@@ -135,10 +137,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!");
diff --git a/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp b/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
index fcccf0e07ef8d2..1d5bd06ed40919 100644
--- a/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
+++ b/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
@@ -193,12 +193,12 @@ extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
 
   // Create TargetMachine
   //
-
+  std::string execName = *argv[0];
   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 +206,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);
   }
 



More information about the llvm-commits mailing list