nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1From 1a2293c7593e4eeb3fbad74fa8d362abafb43b56 Mon Sep 17 00:00:00 2001
2From: Tony Allevato <allevato@google.com>
3Date: Wed, 9 Oct 2024 13:54:43 -0400
4Subject: [PATCH] [Frontend] Fix a small `unique_ptr` array access.
5
6When the size of the array accessed here is zero, retrieving the
7address of the zero-th element here is undefined. When the frontend
8is linked against a libc++ that has the `unique_ptr` hardening in
9[this commit](https://github.com/llvm/llvm-project/commit/18df9d23ea390eaa50b41f3083a42f700a2b0e39)
10enabled, it traps here.
11
12Instead, simply call `.get()` to retrieve the address of the
13array, which works even when it is a zero-byte allocation.
14
15(cherry picked from commit bdf40184ab40eb59642cd825781d71d0711493eb)
16---
17 lib/FrontendTool/FrontendTool.cpp | 2 +-
18 1 file changed, 1 insertion(+), 1 deletion(-)
19
20diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp
21index afbc57cdf2f..ba64a306494 100644
22--- a/lib/FrontendTool/FrontendTool.cpp
23+++ b/lib/FrontendTool/FrontendTool.cpp
24@@ -2202,7 +2202,7 @@ int swift::performFrontend(ArrayRef<const char *> Args,
25 std::make_unique<llvm::Optional<PrettyStackTraceFileContents>[]>(
26 configurationFileBuffers.size());
27 for_each(configurationFileBuffers.begin(), configurationFileBuffers.end(),
28- &configurationFileStackTraces[0],
29+ configurationFileStackTraces.get(),
30 [](const std::unique_ptr<llvm::MemoryBuffer> &buffer,
31 llvm::Optional<PrettyStackTraceFileContents> &trace) {
32 trace.emplace(*buffer);
33--
342.52.0
35