Skip to content

Commit 66caad7

Browse files
Martien de Jongmartien-de-jong
authored andcommitted
[CodeGenFormat] Prevent UB
Default slot's ID and SlotBits are default initialized, never touched afterwards
1 parent 277e0fb commit 66caad7

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

llvm/utils/TableGen/CodeGenFormat.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,11 +1112,9 @@ void TGTargetSlots::finalizeSlots() {
11121112

11131113
// Give an ID for each slot
11141114
int SlotID = 0;
1115-
for (RecordSlot &Slot : Slots)
1116-
if (Slot.second.isDefaultSlot())
1117-
Slot.second.setNumSlot(-1);
1118-
else
1119-
Slot.second.setNumSlot(SlotID++);
1115+
for (auto &[_, Slot] : Slots)
1116+
if (!Slot.isDefaultSlot())
1117+
Slot.setNumSlot(SlotID++);
11201118

11211119
// Sort the slot container by ID
11221120
std::sort(Slots.begin(), Slots.end(),

llvm/utils/TableGen/CodeGenFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class TGTargetSlot {
279279
bool Artificial = false;
280280
// Unique number attributed (in the pool) for the slot.
281281
// It is used to generate a unique "SlotSet".
282-
int NumSlot;
282+
int NumSlot = -1;
283283

284284
// The Slot bits for this slot. These are the pristine bits that correspond
285285
// to the slots a format accommodates.

0 commit comments

Comments
 (0)