[clang] ed32737 - [clang][bytecode] Move past-end check into CheckFinalLoad (#227181)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 30 00:56:39 PDT 2026


Author: Timm Baeder
Date: 2026-09-30T09:56:31+02:00
New Revision: ed327377a67f812a13ca783ffab67efff11a80fb

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

LOG: [clang][bytecode] Move past-end check into CheckFinalLoad (#227181)

It makes more sense there. Also remove the one of for non-const
pointers, since that one isn't needed anymore

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/EvalEmitter.cpp
    clang/lib/AST/ByteCode/Interp.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index c3de67a63cf84..72ed8ad1f7a83 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -282,18 +282,9 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(SourceInfo Info) {
 
   // Implicitly convert lvalue to rvalue, if requested.
   if (ConvertResultToRValue) {
-    if (Ptr.isPastEnd())
-      return false;
-
     if (!Ptr.isZero() && !CheckFinalLoad(S, CodePtr(), Ptr))
       return false;
 
-    // Never allow reading from a non-const pointer, unless the memory
-    // has been created in this evaluation.
-    if (!Ptr.isZero() && !Ptr.isConst() && Ptr.isBlockPointer() &&
-        Ptr.block()->getEvalID() != Ctx.getEvalID())
-      return false;
-
     if (!EvalResult.checkLValueFields(S, Ptr, Info, ConstexprKind))
       return false;
 

diff  --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 08b78e2030f13..25605ba04c7bd 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1082,6 +1082,9 @@ bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
     return CheckWeak(S, OpPC, Ptr.block());
   }
 
+  if (Ptr.isPastEnd())
+    return false;
+
   if (!CheckConstant(S, OpPC, Ptr))
     return false;
 


        


More information about the cfe-commits mailing list