[clang] 2ac696e - [clang][bytecode] Try to avoid a `SmallVector` in `Pointer::toAPValue()` (#226143)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 24 06:24:35 PDT 2026
Author: Timm Baeder
Date: 2026-09-24T15:24:28+02:00
New Revision: 2ac696e23ca31d68a89060c7a935c75bc4efb846
URL: https://github.com/llvm/llvm-project/commit/2ac696e23ca31d68a89060c7a935c75bc4efb846
DIFF: https://github.com/llvm/llvm-project/commit/2ac696e23ca31d68a89060c7a935c75bc4efb846.diff
LOG: [clang][bytecode] Try to avoid a `SmallVector` in `Pointer::toAPValue()` (#226143)
Only create the local variable if we really need it.
Added:
Modified:
clang/lib/AST/ByteCode/Pointer.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp
index 552cdf1bf8ec7..0f564306704a6 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -251,17 +251,16 @@ bool Pointer::operator==(const Pointer &P) const {
}
APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
- llvm::SmallVector<APValue::LValuePathEntry, 5> Path;
if (isZero())
- return APValue(APValue::LValueBase(), CharUnits::Zero(), Path,
+ return APValue(APValue::LValueBase(), CharUnits::Zero(), {},
/*IsOnePastEnd=*/false, /*IsNullPtr=*/true);
switch (StorageKind) {
case Storage::Int:
return APValue(static_cast<const Expr *>(nullptr),
CharUnits::fromQuantity(asIntPointer().Value + this->Offset),
- Path,
+ {},
/*IsOnePastEnd=*/false, /*IsNullPtr=*/false);
case Storage::Block:
// See below.
@@ -281,13 +280,15 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
CharUnits::Zero(), {},
/*OnePastTheEnd=*/false, /*IsNull=*/false);
} break;
- case Storage::String:
+ case Storage::String: {
+ llvm::SmallVector<APValue::LValuePathEntry, 1> Path;
if (Offset != 0 || Str.Decayed)
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Offset));
return APValue(APValue::LValueBase(Str.Base),
CharUnits::fromQuantity(Offset * elemSize()), Path,
/*OnePastTheEnd=*/false, /*IsNull=*/false);
+ }
case Storage::Opaque: {
bool ValidBase = Opaque.hasValidBase() || this->Offset <= 1;
@@ -307,6 +308,7 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
// For valid bases, assemble the LValuePath.
APValue Result;
if (ValidBase) {
+ llvm::SmallVector<APValue::LValuePathEntry, 5> Path;
for (const PointerPathEntry &Entry : Opaque.path()) {
switch (Entry.Kind) {
case PointerPathEntry::Field:
@@ -368,6 +370,7 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
// Build the path into the object.
bool OnePastEnd = isOnePastEnd() && !isZeroSizeArray();
+ llvm::SmallVector<APValue::LValuePathEntry, 5> Path;
PtrView Ptr = view();
while (Ptr.isField() || Ptr.isArrayElement()) {
More information about the cfe-commits
mailing list