[clang] [clang][NFC] Copy `CharUnits` instances in `APValue` (PR #226115)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 24 04:02:36 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/226115
`CharUnits` is just an `int64_t`, but passed around by const reference in `APValue` for some reason.
>From 9ec0a862e347b617b74320fbab8e347ef13ea714 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 24 Sep 2026 12:05:26 +0200
Subject: [PATCH] Copy CharUnits parameters
---
clang/include/clang/AST/APValue.h | 28 +++++++++++++---------------
clang/lib/AST/APValue.cpp | 7 +++----
2 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h
index c5c871ef953cb5..6bea43d9c82b45 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -13,6 +13,7 @@
#ifndef LLVM_CLANG_AST_APVALUE_H
#define LLVM_CLANG_AST_APVALUE_H
+#include "clang/AST/CharUnits.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/APFixedPoint.h"
#include "llvm/ADT/APFloat.h"
@@ -29,7 +30,6 @@ template <typename T> class BasicReaderBase;
class AddrLabelExpr;
class ASTContext;
- class CharUnits;
class CXXRecordDecl;
class Decl;
class DiagnosticBuilder;
@@ -375,7 +375,7 @@ class APValue {
/// \param Base The base of the lvalue.
/// \param Offset The offset of the lvalue.
/// \param IsNullPtr Whether this lvalue is a null pointer.
- APValue(LValueBase Base, const CharUnits &Offset, NoLValuePath,
+ APValue(LValueBase Base, CharUnits Offset, NoLValuePath,
bool IsNullPtr = false)
: Kind(None), AllowConstexprUnknown(false) {
MakeLValue();
@@ -388,9 +388,8 @@ class APValue {
/// \param OnePastTheEnd Whether this lvalue is one-past-the-end of the
/// subobject it points to.
/// \param IsNullPtr Whether this lvalue is a null pointer.
- APValue(LValueBase Base, const CharUnits &Offset,
- ArrayRef<LValuePathEntry> Path, bool OnePastTheEnd,
- bool IsNullPtr = false)
+ APValue(LValueBase Base, CharUnits Offset, ArrayRef<LValuePathEntry> Path,
+ bool OnePastTheEnd, bool IsNullPtr = false)
: Kind(None), AllowConstexprUnknown(false) {
MakeLValue();
setLValue(Base, Offset, Path, OnePastTheEnd, IsNullPtr);
@@ -399,7 +398,7 @@ class APValue {
/// \param Base The base of the lvalue.
/// \param Offset The offset of the lvalue.
/// \param IsNullPtr Whether this lvalue is a null pointer.
- APValue(LValueBase Base, const CharUnits &Offset, ConstexprUnknown,
+ APValue(LValueBase Base, CharUnits Offset, ConstexprUnknown,
bool IsNullPtr = false)
: Kind(None), AllowConstexprUnknown(true) {
MakeLValue();
@@ -572,7 +571,7 @@ class APValue {
const LValueBase getLValueBase() const;
CharUnits &getLValueOffset();
- const CharUnits &getLValueOffset() const {
+ CharUnits getLValueOffset() const {
return const_cast<APValue*>(this)->getLValueOffset();
}
bool isLValueOnePastTheEnd() const;
@@ -753,11 +752,9 @@ class APValue {
((ComplexAPFloat *)(char *)&Data)->Real = std::move(R);
((ComplexAPFloat *)(char *)&Data)->Imag = std::move(I);
}
- void setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
- bool IsNullPtr);
- void setLValue(LValueBase B, const CharUnits &O,
- ArrayRef<LValuePathEntry> Path, bool OnePastTheEnd,
- bool IsNullPtr);
+ void setLValue(LValueBase B, CharUnits O, NoLValuePath, bool IsNullPtr);
+ void setLValue(LValueBase B, CharUnits O, ArrayRef<LValuePathEntry> Path,
+ bool OnePastTheEnd, bool IsNullPtr);
void setUnion(const FieldDecl *Field, const APValue &Value);
void setAddrLabelDiff(const AddrLabelExpr* LHSExpr,
const AddrLabelExpr* RHSExpr) {
@@ -852,9 +849,10 @@ class APValue {
M->NumCols = NumCols;
return {M->Elts, NumElts};
}
- MutableArrayRef<LValuePathEntry>
- setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size,
- bool OnePastTheEnd, bool IsNullPtr);
+ MutableArrayRef<LValuePathEntry> setLValueUninit(LValueBase B, CharUnits O,
+ unsigned Size,
+ bool OnePastTheEnd,
+ bool IsNullPtr);
MutableArrayRef<const CXXRecordDecl *>
setMemberPointerUninit(const ValueDecl *Member, bool IsDerivedMember,
unsigned Size);
diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 5cf5a4aa6431b8..27e281d1142a4b 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -13,7 +13,6 @@
#include "clang/AST/APValue.h"
#include "Linkage.h"
#include "clang/AST/ASTContext.h"
-#include "clang/AST/CharUnits.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
@@ -1056,7 +1055,7 @@ bool APValue::isNullPointer() const {
return ((const LV *)(const char *)&Data)->IsNullPtr;
}
-void APValue::setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
+void APValue::setLValue(LValueBase B, CharUnits O, NoLValuePath,
bool IsNullPtr) {
assert(isLValue() && "Invalid accessor");
LV &LVal = *((LV *)(char *)&Data);
@@ -1068,7 +1067,7 @@ void APValue::setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
}
MutableArrayRef<APValue::LValuePathEntry>
-APValue::setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size,
+APValue::setLValueUninit(LValueBase B, CharUnits O, unsigned Size,
bool IsOnePastTheEnd, bool IsNullPtr) {
assert(isLValue() && "Invalid accessor");
LV &LVal = *((LV *)(char *)&Data);
@@ -1080,7 +1079,7 @@ APValue::setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size,
return {LVal.getPath(), Size};
}
-void APValue::setLValue(LValueBase B, const CharUnits &O,
+void APValue::setLValue(LValueBase B, CharUnits O,
ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd,
bool IsNullPtr) {
MutableArrayRef<APValue::LValuePathEntry> InternalPath =
More information about the cfe-commits
mailing list