[clang] Make the `-disable-free` flag more full featured (PR #136213)

Chandler Carruth via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 18 10:34:18 PDT 2025


chandlerc wrote:

> You might want to change the `DisableFree` default for library uses so that users don't need to specify `-no-disable-free`.
> 
> ```
>   // Clang calls BuryPointer on the internal AST and CodeGen-related elements like TargetMachine.
>   // This will cause memory leaks if `compile` is executed many times.
>   ci->getCodeGenOpts().DisableFree = false;
>   ci->getFrontendOpts().DisableFree = false;
> ```

Not really sure what default change you're thinking about?

The default that was causing me problems was the driver adding `-disable-free` to the CC1 flags by default -- but I think that's probably the *correct* default. I just wanted a way to override it in a library where the behavior would be problematic. Having the flag support appending `-no-disable-free` to the CC1 flags seemed like the cleanest solution that keeps the best defaults for the most common cases, but gives a path to handle the case of CC1 flags. Does that make sense?

https://github.com/llvm/llvm-project/pull/136213


More information about the cfe-commits mailing list