[clang] f951a6b - Fix potentially uninitialized memory

Mikhail Goncharov via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 1 06:32:37 PDT 2022


Author: Mikhail Goncharov
Date: 2022-06-01T15:31:37+02:00
New Revision: f951a6b2f37baf6ae832318fcca9ba4121c29529

URL: https://github.com/llvm/llvm-project/commit/f951a6b2f37baf6ae832318fcca9ba4121c29529
DIFF: https://github.com/llvm/llvm-project/commit/f951a6b2f37baf6ae832318fcca9ba4121c29529.diff

LOG: Fix potentially uninitialized memory

For https://github.com/llvm/llvm-project/commit/7d76d6095880f34914d85d876b260cc4a4ea640d

Added: 
    

Modified: 
    clang/tools/driver/driver.cpp

Removed: 
    


################################################################################
diff  --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index c9aee57d92cf4..d361457f8cecd 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -505,7 +505,9 @@ int main(int Argc, const char **Argv) {
   bool IsCrash = false;
   Driver::CommandStatus CommandStatus = Driver::CommandStatus::Ok;
   // Pretend the first command failed if ReproStatus is Always.
-  const Command *FailingCommand = &*C->getJobs().begin();
+  const Command *FailingCommand = nullptr;
+  if (!C->getJobs().empty())
+    FailingCommand = &*C->getJobs().begin();
   if (C && !C->containsError()) {
     SmallVector<std::pair<int, const Command *>, 4> FailingCommands;
     Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
@@ -542,8 +544,9 @@ int main(int Argc, const char **Argv) {
   // crash, but only if we're crashing due to FORCE_CLANG_DIAGNOSTICS_CRASH.
   if (::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH"))
     llvm::dbgs() << llvm::getBugReportMsg();
-  if (TheDriver.maybeGenerateCompilationDiagnostics(CommandStatus, ReproLevel,
-                                                    *C, *FailingCommand))
+  if (FailingCommand != nullptr &&
+    TheDriver.maybeGenerateCompilationDiagnostics(CommandStatus, ReproLevel,
+                                                  *C, *FailingCommand))
     Res = 1;
 
   Diags.getClient()->finish();


        


More information about the cfe-commits mailing list