Skip to content

Commit e0db588

Browse files
marcauberertstellar
authored andcommitted
[IR] Fix assertion error in User new/delete edge case (#129914)
Fixes #129900 If `operator delete` was called after an unsuccessful constructor call after `operator new`, we ran into undefined behaviour. This was discovered by our malfunction tests while preparing an upgrade to LLVM 20, that explicitly check for such kind of bugs. (cherry picked from commit 8d38906)
1 parent d5bb7b8 commit e0db588

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

llvm/lib/IR/User.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ void *User::allocateFixedOperandUser(size_t Size, unsigned Us,
146146
Use *Start = reinterpret_cast<Use *>(Storage + DescBytesToAllocate);
147147
Use *End = Start + Us;
148148
User *Obj = reinterpret_cast<User *>(End);
149+
Obj->NumUserOperands = Us;
150+
Obj->HasHungOffUses = false;
151+
Obj->HasDescriptor = DescBytes != 0;
149152
for (; Start != End; Start++)
150153
new (Start) Use(Obj);
151154

@@ -172,6 +175,9 @@ void *User::operator new(size_t Size, HungOffOperandsAllocMarker) {
172175
void *Storage = ::operator new(Size + sizeof(Use *));
173176
Use **HungOffOperandList = static_cast<Use **>(Storage);
174177
User *Obj = reinterpret_cast<User *>(HungOffOperandList + 1);
178+
Obj->NumUserOperands = 0;
179+
Obj->HasHungOffUses = true;
180+
Obj->HasDescriptor = false;
175181
*HungOffOperandList = nullptr;
176182
return Obj;
177183
}

0 commit comments

Comments
 (0)