[lldb] [llvm] [NFC] Ensure MCTargetOptions outlives MCAsmInfo at createMCAsmInfo call sites (PR #180465)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 10 23:55:19 PST 2026
MaskRay wrote:
> Is there a reason we just want to move the pointer reference from MCContext to MCAsmInfo versus making MCAsmInfo own MCTargetOptions?
The current state is not ideal.
Prominent MCContext users, such as `cc1as_main.cpp` and `llvm-mc.cpp`, define `MCTargetOptions` (~280 bytes) as a local variable, initialize its members, then pass a reference to `createMCAsmInfo` and a pointer to `MCContext` ctor.
However, some users forget to pass the `MCTargetOptions` pointer to the `MCContext`, causing the object streamer to check nullness and fall back to the default `MCTargetOptions` member values.
Since MCTargetOptions is quite large with many strings and vectors, copying it isn't desirable.
Having MCContext own a raw pointer from the createMCAsmInfo argument is admittedly error-prone (stack-use-after-return), but most users don't outlive the MCAsmInfo object, so I believe this trade-off is acceptable.
https://github.com/llvm/llvm-project/pull/180465
More information about the llvm-commits
mailing list