diff options
| author | Aiden Grossman <aidengrossman@google.com> | 2026-01-21 08:22:05 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-21 08:22:05 -0800 |
| commit | e2d7cd685d40edd302da7396d9b9c97087e6ff20 (patch) | |
| tree | 116ae324b63e277ad8cc41aa3fc5ae29a97966f5 /llvm/lib/Bitcode/Reader | |
| parent | 224f2bdc37fbf9c1198deefe3908c930572fbfe7 (diff) | |
| download | llvm-e2d7cd685d40edd302da7396d9b9c97087e6ff20.zip llvm-e2d7cd685d40edd302da7396d9b9c97087e6ff20.tar.gz llvm-e2d7cd685d40edd302da7396d9b9c97087e6ff20.tar.bz2 | |
[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
Diffstat (limited to 'llvm/lib/Bitcode/Reader')
| -rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
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) |
