[clang] c6062d3 - [clang][Interp][NFC] Cleanup CheckActive()

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 11 23:35:12 PDT 2024


Author: Timm Bäder
Date: 2024-08-12T08:28:13+02:00
New Revision: c6062d38f74e600c185c30eec7afaa8d0a007424

URL: https://github.com/llvm/llvm-project/commit/c6062d38f74e600c185c30eec7afaa8d0a007424
DIFF: https://github.com/llvm/llvm-project/commit/c6062d38f74e600c185c30eec7afaa8d0a007424.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Interp.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 89ac6938931133..13390007fde33c 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -125,6 +125,8 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
   if (Ptr.isActive())
     return true;
 
+  assert(Ptr.inUnion());
+
   Pointer U = Ptr.getBase();
   Pointer C = Ptr;
   while (!U.isRoot() && U.inUnion() && !U.isActive()) {
@@ -155,8 +157,8 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
   assert(R && R->isUnion() && "Not a union");
 
   const FieldDecl *ActiveField = nullptr;
-  for (unsigned I = 0, N = R->getNumFields(); I < N; ++I) {
-    const Pointer &Field = U.atField(R->getField(I)->Offset);
+  for (const Record::Field &F : R->fields()) {
+    const Pointer &Field = U.atField(F.Offset);
     if (Field.isActive()) {
       ActiveField = Field.getField();
       break;


        


More information about the cfe-commits mailing list