[clang] [clang][bytecode] Refactor collectBlocks() (PR #204062)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 15 23:16:20 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/204062
If the record has no pointer field, return from the function completely.
>From 8116c37a64bfd1ea2c3e414b0af3e7063ad027d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 16 Jun 2026 07:47:25 +0200
Subject: [PATCH] [clang][bytecode] Refactor collectBlocks()
If the record has no pointer field, return from the function
completely.
---
clang/lib/AST/ByteCode/EvaluationResult.cpp | 22 ++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/clang/lib/AST/ByteCode/EvaluationResult.cpp b/clang/lib/AST/ByteCode/EvaluationResult.cpp
index 24f242758324e..149ba1f092bfa 100644
--- a/clang/lib/AST/ByteCode/EvaluationResult.cpp
+++ b/clang/lib/AST/ByteCode/EvaluationResult.cpp
@@ -162,7 +162,8 @@ static void collectBlocks(PtrView Ptr, llvm::SetVector<const Block *> &Blocks) {
P.isDereferencable() && !P.isUnknownSizeArray() && !P.isOnePastEnd();
};
- if (!isUsefulPtr(Pointer(Ptr)))
+ if (!Ptr.isLive() || Ptr.isZero() || Ptr.isDummy() ||
+ Ptr.isUnknownSizeArray() || Ptr.isOnePastEnd())
return;
Blocks.insert(Ptr.Pointee);
@@ -171,7 +172,9 @@ static void collectBlocks(PtrView Ptr, llvm::SetVector<const Block *> &Blocks) {
if (!Desc)
return;
- if (const Record *R = Desc->ElemRecord; R && R->hasPtrField()) {
+ if (const Record *R = Desc->ElemRecord) {
+ if (!R->hasPtrField())
+ return;
for (const Record::Field &F : R->fields()) {
if (!isOrHasPtr(F.Desc))
@@ -179,18 +182,27 @@ static void collectBlocks(PtrView Ptr, llvm::SetVector<const Block *> &Blocks) {
PtrView FieldPtr = Ptr.atField(F.Offset);
collectBlocks(FieldPtr, Blocks);
}
- } else if (Desc->isPrimitive() && Desc->getPrimType() == PT_Ptr) {
+ return;
+ }
+
+ if (Desc->isPrimitive() && Desc->getPrimType() == PT_Ptr) {
Pointer Pointee = Ptr.deref<Pointer>();
if (isUsefulPtr(Pointee) && !Blocks.contains(Pointee.block()))
collectBlocks(Pointee.view(), Blocks);
- } else if (Desc->isPrimitiveArray() && Desc->getPrimType() == PT_Ptr) {
+ return;
+ }
+
+ if (Desc->isPrimitiveArray() && Desc->getPrimType() == PT_Ptr) {
for (unsigned I = 0; I != Desc->getNumElems(); ++I) {
Pointer ElemPointee = Ptr.elem<Pointer>(I);
if (isUsefulPtr(ElemPointee) && !Blocks.contains(ElemPointee.block()))
collectBlocks(ElemPointee.view(), Blocks);
}
- } else if (Desc->isCompositeArray() && isOrHasPtr(Desc->ElemDesc)) {
+ return;
+ }
+
+ if (Desc->isCompositeArray() && isOrHasPtr(Desc->ElemDesc)) {
for (unsigned I = 0; I != Desc->getNumElems(); ++I) {
PtrView ElemPtr = Ptr.atIndex(I).narrow();
collectBlocks(ElemPtr, Blocks);
More information about the cfe-commits
mailing list