From bdf40184ab40eb59642cd825781d71d0711493eb Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Wed, 9 Oct 2024 13:54:43 -0400 Subject: [PATCH] [Frontend] Fix a small `unique_ptr` array access. When the size of the array accessed here is zero, retrieving the address of the zero-th element here is undefined. When the frontend is linked against a libc++ that has the `unique_ptr` hardening in [this commit](https://github.com/llvm/llvm-project/commit/18df9d23ea390eaa50b41f3083a42f700a2b0e39) enabled, it traps here. Instead, simply call `.get()` to retrieve the address of the array, which works even when it is a zero-byte allocation. --- lib/FrontendTool/FrontendTool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 5a0aae2a3277b..afceb34d2c1c8 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -1988,7 +1988,7 @@ int swift::performFrontend(ArrayRef Args, // hundreds or thousands of lines. Skip dumping this output in that case. if (!Invocation.getFrontendOptions().InputsAndOutputs.isWholeModule()) { for_each(configurationFileBuffers.begin(), configurationFileBuffers.end(), - &configurationFileStackTraces[0], + configurationFileStackTraces.get(), [](const std::unique_ptr &buffer, std::optional &trace) { trace.emplace(*buffer);