https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/208988
We pass this when evaluting opcodes in EvalEmitter, but we never set it to anything, so the underlying pointer is always null and we later and up using the source location of the expression we're evaluating. This seems to only cause problems when Statement expressions are involved so far. >From cf82f34e6bbb968d7d7e6b62be6d649d0599a76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Sun, 12 Jul 2026 08:19:31 +0200 Subject: [PATCH] [clang][bytecode] Remove EvalEmitter::OpPC We pass this when evaluting opcodes in EvalEmitter, but we never set it to anything, so the underlying pointer is always null and we later and up using the source location of the expression we're evaluating. This seems to only cause problems when Statement expressions are involved so far. --- clang/lib/AST/ByteCode/EvalEmitter.cpp | 11 ++++++----- clang/lib/AST/ByteCode/EvalEmitter.h | 3 --- clang/utils/TableGen/ClangOpcodesEmitter.cpp | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index 34c85c7c66bdd..18921ca27cd09 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -219,7 +219,7 @@ bool EvalEmitter::speculate(const CallExpr *E, const LabelTy &EndLabel) { if (S.inConstantContext() || Arg->HasSideEffects(S.getASTContext())) return this->emitBool(false, E); - return Invalid(S, OpPC); + return Invalid(S, CodePtr()); } PrimType T = Ctx.classify(Arg->getType()).value_or(PT_Ptr); @@ -244,13 +244,14 @@ template <PrimType OpType> bool EvalEmitter::emitRet(SourceInfo Info) { } template <> bool EvalEmitter::emitRet<PT_Ptr>(SourceInfo Info) { + // llvm::errs()<< __PRETTY_FUNCTION__ << "Ret\n"; if (!isActive()) return true; const Pointer &Ptr = S.Stk.pop<Pointer>(); // If we're returning a raw pointer, call our callback. if (this->PtrCB) - return (*this->PtrCB)(S, OpPC, Ptr); + return (*this->PtrCB)(S, CodePtr(), Ptr); if (!EvalResult.checkDynamicAllocations(S, Ctx, Ptr, Info)) return false; @@ -271,7 +272,7 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(SourceInfo Info) { if (Ptr.pointsToStringLiteral() && Ptr.isArrayRoot()) return false; - if (!Ptr.isZero() && !CheckFinalLoad(S, OpPC, Ptr)) + if (!Ptr.isZero() && !CheckFinalLoad(S, CodePtr(), Ptr)) return false; // Never allow reading from a non-const pointer, unless the memory @@ -351,7 +352,7 @@ bool EvalEmitter::emitGetRefLocal(uint32_t I, SourceInfo Info) { return true; Block *B = getLocal(I); - return handleReference(S, OpPC, B); + return handleReference(S, CodePtr(), B); } template <PrimType OpType> @@ -363,7 +364,7 @@ bool EvalEmitter::emitGetLocal(uint32_t I, SourceInfo Info) { Block *B = getLocal(I); - if (!CheckLocalLoad(S, OpPC, B)) + if (!CheckLocalLoad(S, CodePtr(), B)) return false; S.Stk.push<T>(B->deref<T>()); diff --git a/clang/lib/AST/ByteCode/EvalEmitter.h b/clang/lib/AST/ByteCode/EvalEmitter.h index f939ef4839a19..6ad4f833f9dad 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.h +++ b/clang/lib/AST/ByteCode/EvalEmitter.h @@ -137,9 +137,6 @@ class EvalEmitter : public SourceMapper { void updateGlobalTemporaries(); - // The emitter always tracks the current instruction and sets OpPC to a token - // value which is mapped to the location of the opcode being evaluated. - CodePtr OpPC; /// Location of the current instruction. SourceInfo CurrentSource; diff --git a/clang/utils/TableGen/ClangOpcodesEmitter.cpp b/clang/utils/TableGen/ClangOpcodesEmitter.cpp index 4a3c901d2de7f..8e70a070696ea 100644 --- a/clang/utils/TableGen/ClangOpcodesEmitter.cpp +++ b/clang/utils/TableGen/ClangOpcodesEmitter.cpp @@ -444,7 +444,7 @@ void ClangOpcodesEmitter::EmitEval(raw_ostream &OS, StringRef N, PrintTypes(OS, TS); OS << "(S"; if (PassOpPC) - OS << ", OpPC"; + OS << ", CodePtr()"; for (size_t I = 0, N = Args.size(); I < N; ++I) OS << ", A" << I; OS << ");\n"; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
