@@ -26,7 +26,7 @@ bool User::replaceUsesOfWith(Value *From, Value *To) {
2626 " Cannot call User::replaceUsesOfWith on a constant!" );
2727
2828 for (unsigned i = 0 , E = getNumOperands (); i != E; ++i)
29- if (getOperand (i) == From) { // Is This operand is pointing to oldval?
29+ if (getOperand (i) == From) { // Is This operand is pointing to oldval?
3030 // The side effects of this setOperand call include linking to
3131 // "To", adding "this" to the uses list of To, and
3232 // most importantly, removing "this" from the use list of "From".
@@ -146,9 +146,6 @@ 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 ;
152149 for (; Start != End; Start++)
153150 new (Start) Use (Obj);
154151
@@ -175,9 +172,6 @@ void *User::operator new(size_t Size, HungOffOperandsAllocMarker) {
175172 void *Storage = ::operator new (Size + sizeof (Use *));
176173 Use **HungOffOperandList = static_cast <Use **>(Storage);
177174 User *Obj = reinterpret_cast <User *>(HungOffOperandList + 1 );
178- Obj->NumUserOperands = 0 ;
179- Obj->HasHungOffUses = true ;
180- Obj->HasDescriptor = false ;
181175 *HungOffOperandList = nullptr ;
182176 return Obj;
183177}
@@ -191,28 +185,54 @@ void *User::operator new(size_t Size, HungOffOperandsAllocMarker) {
191185LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE void User::operator delete (void *Usr) {
192186 // Hung off uses use a single Use* before the User, while other subclasses
193187 // use a Use[] allocated prior to the user.
194- User *Obj = static_cast <User *>(Usr);
188+ const auto *Obj = static_cast <User *>(Usr);
195189 if (Obj->HasHungOffUses ) {
196- assert (!Obj->HasDescriptor && " not supported!" );
197-
198- Use **HungOffOperandList = static_cast <Use **>(Usr) - 1 ;
199- // drop the hung off uses.
200- Use::zap (*HungOffOperandList, *HungOffOperandList + Obj->NumUserOperands ,
201- /* Delete */ true );
202- ::operator delete (HungOffOperandList);
190+ const HungOffOperandsAllocMarker Marker{
191+ Obj->NumUserOperands ,
192+ };
193+ operator delete (Usr, Marker);
203194 } else if (Obj->HasDescriptor ) {
204- Use *UseBegin = static_cast <Use *>(Usr) - Obj->NumUserOperands ;
205- Use::zap (UseBegin, UseBegin + Obj->NumUserOperands , /* Delete */ false );
206-
207- auto *DI = reinterpret_cast <DescriptorInfo *>(UseBegin) - 1 ;
208- uint8_t *Storage = reinterpret_cast <uint8_t *>(DI) - DI->SizeInBytes ;
209- ::operator delete (Storage);
195+ const IntrusiveOperandsAndDescriptorAllocMarker Marker{
196+ Obj->NumUserOperands ,
197+ Obj->HasDescriptor ,
198+ };
199+ operator delete (Usr, Marker);
210200 } else {
211- Use *Storage = static_cast <Use *>(Usr) - Obj-> NumUserOperands ;
212- Use::zap (Storage, Storage + Obj->NumUserOperands ,
213- /* Delete */ false ) ;
214- :: operator delete (Storage );
201+ const IntrusiveOperandsAllocMarker Marker{
202+ Obj->NumUserOperands ,
203+ } ;
204+ operator delete (Usr, Marker );
215205 }
216206}
217207
208+ // Repress memory sanitization, due to use-after-destroy by operator
209+ // delete. Bug report 24578 identifies this issue.
210+ void User::operator delete (void *Usr, HungOffOperandsAllocMarker Marker) {
211+ Use **HungOffOperandList = static_cast <Use **>(Usr) - 1 ;
212+ // drop the hung off uses.
213+ Use::zap (*HungOffOperandList, *HungOffOperandList + Marker.NumOps ,
214+ /* Delete */ true );
215+ ::operator delete (HungOffOperandList);
216+ }
217+
218+ // Repress memory sanitization, due to use-after-destroy by operator
219+ // delete. Bug report 24578 identifies this issue.
220+ void User::operator delete (void *Usr, IntrusiveOperandsAllocMarker Marker) {
221+ Use *Storage = static_cast <Use *>(Usr) - Marker.NumOps ;
222+ Use::zap (Storage, Storage + Marker.NumOps , /* Delete */ false );
223+ ::operator delete (Storage);
224+ }
225+
226+ // Repress memory sanitization, due to use-after-destroy by operator
227+ // delete. Bug report 24578 identifies this issue.
228+ void User::operator delete (void *Usr,
229+ IntrusiveOperandsAndDescriptorAllocMarker Marker) {
230+ Use *UseBegin = static_cast <Use *>(Usr) - Marker.NumOps ;
231+ Use::zap (UseBegin, UseBegin + Marker.NumOps , /* Delete */ false );
232+
233+ auto *DI = reinterpret_cast <DescriptorInfo *>(UseBegin) - 1 ;
234+ uint8_t *Storage = reinterpret_cast <uint8_t *>(DI) - DI->SizeInBytes ;
235+ ::operator delete (Storage);
236+ }
237+
218238} // namespace llvm
0 commit comments