Fix potentially uninitialized memory
authorMikhail Goncharov <goncharov.mikhail@gmail.com>
Wed, 1 Jun 2022 13:30:10 +0000 (15:30 +0200)
committerMikhail Goncharov <goncharov.mikhail@gmail.com>
Wed, 1 Jun 2022 13:31:37 +0000 (15:31 +0200)
For https://github.com/llvm/llvm-project/commit/7d76d6095880f34914d85d876b260cc4a4ea640d

clang/tools/driver/driver.cpp

index c9aee57..d361457 100644 (file)
@@ -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();