[clang] [Clang] Add fake use emission to Clang with -fextend-lifetimes (PR #110102)

Stephen Tozer via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 4 06:15:51 PST 2024


================
@@ -1353,6 +1353,19 @@ void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) {
   C->setDoesNotThrow();
 }
 
+void CodeGenFunction::EmitFakeUse(Address Addr) {
+  // We do not emit a fake use if we want to apply optnone to this function,
+  // even if we might not apply it anyway due to minsize or similar attributes.
+  if (!CGM.getCodeGenOpts().DisableO0ImplyOptNone &&
+      CGM.getCodeGenOpts().OptimizationLevel == 0)
+    return;
----------------
SLTozer wrote:

The thoughts I have are that by default, in a typical `-O0` build, `-fextend-lifetimes` is useless. But there may be atypical circumstances that would make it useful - such as following the somewhat common pattern (in LLVM development) of compiling with `-O0 -emit-llvm -disable-O0-optnone` to produce unoptimized IR (except for compulsory optimizations) from clang to pass to `opt` or some other tool that may modify it; in these cases if a user has explicitly requested `-fextend-lifetimes`, it seems reasonable to me to still emit fake uses. The argument _against_ emitting fake uses is that they have no value, but given that the flag is opt-in only I think it's fine to trust that the user isn't going to accidentally add a flag that they don't need.

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


More information about the cfe-commits mailing list