From 45a16f9ad36a82782cf0a59e3ea3b11ebd7a4683 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Wed, 21 Jan 2026 23:00:23 +0000 Subject: [PATCH] [IR] Support constructing `dead_on_return` without an argument After #171712, `dead_on_return` takes an optional argument indicating the number of bytes known dead. The existing clang callsite uses the attribute builder interface directly which supports the optional argument through `DeadOnReturnInfo`. However, users constructing the Attribute directly (e.g. `rustc`) were using `Attribute::get` which will now default to providing a 0 value to the optional argument. Add the additional method `Attribute::getWithDeadOnReturnInfo` to allow users which produce explicit `Attribute` values to continue to indicate `dead_on_return` without an argument. --- llvm/include/llvm/IR/Attributes.h | 2 ++ llvm/lib/IR/Attributes.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h index ec451f6b08695..534d96d2c46e5 100644 --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -212,6 +212,8 @@ class Attribute { MemoryEffects ME); LLVM_ABI static Attribute getWithNoFPClass(LLVMContext &Context, FPClassTest Mask); + LLVM_ABI static Attribute getWithDeadOnReturnInfo(LLVMContext &Context, + DeadOnReturnInfo DI); LLVM_ABI static Attribute getWithCaptureInfo(LLVMContext &Context, CaptureInfo CI); diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index f156202ce6775..f4bdf959f05f3 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -288,6 +288,11 @@ Attribute Attribute::getWithNoFPClass(LLVMContext &Context, return get(Context, NoFPClass, ClassMask); } +Attribute Attribute::getWithDeadOnReturnInfo(LLVMContext &Context, + DeadOnReturnInfo DI) { + return get(Context, DeadOnReturn, DI.toIntValue()); +} + Attribute Attribute::getWithCaptureInfo(LLVMContext &Context, CaptureInfo CI) { return get(Context, Captures, CI.toIntValue()); }