Skip to content

Commit c6062d3

Browse files
committed
[clang][Interp][NFC] Cleanup CheckActive()
Assert that the given pointer is in a union if it's not active and use a range-based for loop to find the active field.
1 parent 7d4aa1f commit c6062d3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

clang/lib/AST/Interp/Interp.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
125125
if (Ptr.isActive())
126126
return true;
127127

128+
assert(Ptr.inUnion());
129+
128130
Pointer U = Ptr.getBase();
129131
Pointer C = Ptr;
130132
while (!U.isRoot() && U.inUnion() && !U.isActive()) {
@@ -155,8 +157,8 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
155157
assert(R && R->isUnion() && "Not a union");
156158

157159
const FieldDecl *ActiveField = nullptr;
158-
for (unsigned I = 0, N = R->getNumFields(); I < N; ++I) {
159-
const Pointer &Field = U.atField(R->getField(I)->Offset);
160+
for (const Record::Field &F : R->fields()) {
161+
const Pointer &Field = U.atField(F.Offset);
160162
if (Field.isActive()) {
161163
ActiveField = Field.getField();
162164
break;

0 commit comments

Comments
 (0)