[clang] [clang][bytecode] Pass `SourceInfo` objects by value (PR #159532)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 18 03:40:45 PDT 2025
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/159532
>From 151dfc42b7708fb137c098fab053421c6a2423de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 18 Sep 2025 06:42:51 +0200
Subject: [PATCH] Copy sourceinfo around
---
clang/lib/AST/ByteCode/ByteCodeEmitter.cpp | 3 +--
clang/lib/AST/ByteCode/ByteCodeEmitter.h | 2 +-
clang/lib/AST/ByteCode/EvalEmitter.cpp | 16 ++++++++--------
clang/lib/AST/ByteCode/Source.h | 1 +
clang/utils/TableGen/ClangOpcodesEmitter.cpp | 12 ++++++------
5 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
index 274efccac79dc..ed743768d077e 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
@@ -207,8 +207,7 @@ void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code,
}
template <typename... Tys>
-bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args,
- const SourceInfo &SI) {
+bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args, SourceInfo SI) {
bool Success = true;
// The opcode is followed by arguments. The source info is
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.h b/clang/lib/AST/ByteCode/ByteCodeEmitter.h
index c050b299d8f61..ca8dc38e65246 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.h
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.h
@@ -99,7 +99,7 @@ class ByteCodeEmitter {
/// Emits an opcode.
template <typename... Tys>
- bool emitOp(Opcode Op, const Tys &...Args, const SourceInfo &L);
+ bool emitOp(Opcode Op, const Tys &...Args, SourceInfo L);
protected:
#define GET_LINK_PROTO
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index c7287999dd9c0..007321791fdd4 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -177,7 +177,7 @@ bool EvalEmitter::speculate(const CallExpr *E, const LabelTy &EndLabel) {
return this->emitBool(true, E);
}
-template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) {
+template <PrimType OpType> bool EvalEmitter::emitRet(SourceInfo Info) {
if (!isActive())
return true;
@@ -186,7 +186,7 @@ template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) {
return true;
}
-template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
+template <> bool EvalEmitter::emitRet<PT_Ptr>(SourceInfo Info) {
if (!isActive())
return true;
@@ -247,12 +247,12 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
return true;
}
-bool EvalEmitter::emitRetVoid(const SourceInfo &Info) {
+bool EvalEmitter::emitRetVoid(SourceInfo Info) {
EvalResult.setValid();
return true;
}
-bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
+bool EvalEmitter::emitRetValue(SourceInfo Info) {
const auto &Ptr = S.Stk.pop<Pointer>();
if (!EvalResult.checkReturnValue(S, Ctx, Ptr, Info))
@@ -270,7 +270,7 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
return false;
}
-bool EvalEmitter::emitGetPtrLocal(uint32_t I, const SourceInfo &Info) {
+bool EvalEmitter::emitGetPtrLocal(uint32_t I, SourceInfo Info) {
if (!isActive())
return true;
@@ -280,7 +280,7 @@ bool EvalEmitter::emitGetPtrLocal(uint32_t I, const SourceInfo &Info) {
}
template <PrimType OpType>
-bool EvalEmitter::emitGetLocal(uint32_t I, const SourceInfo &Info) {
+bool EvalEmitter::emitGetLocal(uint32_t I, SourceInfo Info) {
if (!isActive())
return true;
@@ -296,7 +296,7 @@ bool EvalEmitter::emitGetLocal(uint32_t I, const SourceInfo &Info) {
}
template <PrimType OpType>
-bool EvalEmitter::emitSetLocal(uint32_t I, const SourceInfo &Info) {
+bool EvalEmitter::emitSetLocal(uint32_t I, SourceInfo Info) {
if (!isActive())
return true;
@@ -310,7 +310,7 @@ bool EvalEmitter::emitSetLocal(uint32_t I, const SourceInfo &Info) {
return true;
}
-bool EvalEmitter::emitDestroy(uint32_t I, const SourceInfo &Info) {
+bool EvalEmitter::emitDestroy(uint32_t I, SourceInfo Info) {
if (!isActive())
return true;
diff --git a/clang/lib/AST/ByteCode/Source.h b/clang/lib/AST/ByteCode/Source.h
index d5d294e31d90c..f355d14db5e30 100644
--- a/clang/lib/AST/ByteCode/Source.h
+++ b/clang/lib/AST/ByteCode/Source.h
@@ -92,6 +92,7 @@ class SourceInfo final {
private:
llvm::PointerUnion<const Decl *, const Stmt *> Source;
};
+static_assert(sizeof(SourceInfo) == sizeof(void *));
using SourceMap = std::vector<std::pair<unsigned, SourceInfo>>;
diff --git a/clang/utils/TableGen/ClangOpcodesEmitter.cpp b/clang/utils/TableGen/ClangOpcodesEmitter.cpp
index 9d0773e1aff8f..d26122aca46bd 100644
--- a/clang/utils/TableGen/ClangOpcodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpcodesEmitter.cpp
@@ -200,7 +200,7 @@ void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N,
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "") << "A"
<< I << ", ";
}
- OS << "const SourceInfo &L) {\n";
+ OS << "SourceInfo L) {\n";
// Emit a call to write the opcodes.
OS << " return emitOp<";
@@ -231,7 +231,7 @@ void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N,
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "")
<< ", ";
}
- OS << "const SourceInfo &);\n";
+ OS << "SourceInfo);\n";
});
// Emit a template method for custom emitters to have less to implement.
@@ -248,7 +248,7 @@ void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N,
OS << "bool emit" << N << "(";
for (const auto *Arg : Args)
OS << Arg->getValueAsString("Name") << ", ";
- OS << "const SourceInfo &);\n";
+ OS << "SourceInfo);\n";
OS << "#endif\n";
}
@@ -272,7 +272,7 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
OS << "PrimType, ";
for (auto *Arg : Args)
OS << Arg->getValueAsString("Name") << ", ";
- OS << "const SourceInfo &I);\n";
+ OS << "SourceInfo I);\n";
OS << "#endif\n";
// Emit the dispatch implementation in the source.
@@ -294,7 +294,7 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "") << "A"
<< I << ", ";
}
- OS << "const SourceInfo &I) {\n";
+ OS << "SourceInfo I) {\n";
std::function<void(size_t, const Twine &)> Rec;
SmallVector<const Record *, 2> TS;
@@ -368,7 +368,7 @@ void ClangOpcodesEmitter::EmitEval(raw_ostream &OS, StringRef N,
OS << (AsRef ? "const " : " ") << Name << " "
<< (AsRef ? "&" : "") << "A" << I << ", ";
}
- OS << "const SourceInfo &L) {\n";
+ OS << "SourceInfo L) {\n";
OS << " if (!isActive()) return true;\n";
OS << " CurrentSource = L;\n";
More information about the cfe-commits
mailing list