[PATCH] D126776: Fix potentially uninitialized memory

Mikhail Goncharov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 1 06:28:21 PDT 2022


goncharov updated this revision to Diff 433373.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126776/new/

https://reviews.llvm.org/D126776

Files:
  clang/tools/driver/driver.cpp


Index: clang/tools/driver/driver.cpp
===================================================================
--- clang/tools/driver/driver.cpp
+++ clang/tools/driver/driver.cpp
@@ -505,7 +505,9 @@
   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 @@
   // 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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126776.433373.patch
Type: text/x-patch
Size: 1281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220601/17c89aec/attachment.bin>


More information about the llvm-commits mailing list