From 2bdea71c2513fda6b99674dc3c48ff6f64f8a188 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 18 Apr 2025 15:05:25 -0700 Subject: [PATCH] Simplify freeing with new LLVM (#5334) We now have upstream support for a clean way to forcibly enable freeing memory in a library context, so use that. --- toolchain/driver/clang_runner.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/toolchain/driver/clang_runner.cpp b/toolchain/driver/clang_runner.cpp index 2cd32a84c457..8ffbae9e6c08 100644 --- a/toolchain/driver/clang_runner.cpp +++ b/toolchain/driver/clang_runner.cpp @@ -113,15 +113,9 @@ auto ClangRunner::Run(llvm::ArrayRef args) -> bool { // execution here, as subprocesses leaking memory won't impact this process. auto cc1_main = [enable_leaking = enable_leaking_]( llvm::SmallVectorImpl& cc1_args) -> int { - // Clang doesn't expose any option to disable injecting `-disable-free` into - // the CC1 invocation, or any way to append a flag that undoes it. So to - // avoid leaks, we need to edit the `cc1_args` here and remove - // `-disable-free`. - // - // TODO: We should see if upstream would be open to some configuration hook - // to suppress this when it is generating the CC1 flags and use that. if (!enable_leaking) { - llvm::erase(cc1_args, llvm::StringRef("-disable-free")); + // Last-flag wins, so this forcibly re-enables freeing memory. + cc1_args.push_back("-no-disable-free"); } // cc1_args[0] will be the `clang_path` so we don't need the prepend arg.