Author: Timm Baeder
Date: 2026-07-12T09:12:32+02:00
New Revision: 77929619bc93b86e99f6ae6a9b10ef85a27c4c18

URL: 
https://github.com/llvm/llvm-project/commit/77929619bc93b86e99f6ae6a9b10ef85a27c4c18
DIFF: 
https://github.com/llvm/llvm-project/commit/77929619bc93b86e99f6ae6a9b10ef85a27c4c18.diff

LOG: [clang][bytecode] Remove EvalEmitter::OpPC (#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.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/EvalEmitter.cpp
    clang/lib/AST/ByteCode/EvalEmitter.h
    clang/utils/TableGen/ClangOpcodesEmitter.cpp

Removed: 
    


################################################################################
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

Reply via email to