From e2d7cd685d40edd302da7396d9b9c97087e6ff20 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Wed, 21 Jan 2026 08:22:05 -0800 Subject: [IR] Make dead_on_return attribute optionally sized This patch makes the dead_on_return parameter attribute optionally require a number of bytes to be passed in to specify the number of bytes known to be dead upon function return/unwind. This is aimed at enabling annotating the this pointer in C++ destructors with dead_on_return in clang. We need this to handle cases like the following: ``` struct X { int n; ~X() { this[n].n = 0; } }; void f() { X xs[] = {42, -1}; } ``` Where we only certain that sizeof(X) bytes are dead upon return of ~X. Otherwise DSE would be able to eliminate the store in ~X which would not be correct. This patch only does the wiring within IR. Future patches will make clang emit correct sizing information and update DSE to only delete stores to objects marked dead_on_return that are provably in bounds of the number of bytes specified to be dead_on_return. Reviewers: nikic, alinas, antoniofrighetto Pull Request: https://github.com/llvm/llvm-project/pull/171712 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 34dcce9..816ef37 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2384,6 +2384,8 @@ Error BitcodeReader::parseAttributeGroupBlock() { B.addInAllocaAttr(nullptr); else if (Kind == Attribute::UWTable) B.addUWTableAttr(UWTableKind::Default); + else if (Kind == Attribute::DeadOnReturn) + B.addDeadOnReturnAttr(DeadOnReturnInfo()); else if (Attribute::isEnumAttrKind(Kind)) B.addAttribute(Kind); else @@ -2402,6 +2404,9 @@ Error BitcodeReader::parseAttributeGroupBlock() { B.addDereferenceableAttr(Record[++i]); else if (Kind == Attribute::DereferenceableOrNull) B.addDereferenceableOrNullAttr(Record[++i]); + else if (Kind == Attribute::DeadOnReturn) + B.addDeadOnReturnAttr( + DeadOnReturnInfo::createFromIntValue(Record[++i])); else if (Kind == Attribute::AllocSize) B.addAllocSizeAttrFromRawRepr(Record[++i]); else if (Kind == Attribute::VScaleRange) -- cgit v1.1