[clang] 11ba795 - [clang][Interp][NFC] Add sanity checks to This op

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 8 22:55:52 PDT 2024


Author: Timm Bäder
Date: 2024-04-09T07:55:37+02:00
New Revision: 11ba795565c231a95a7e34bb0e4dff099234c736

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

LOG: [clang][Interp][NFC] Add sanity checks to This op

The instance pointer must be casted to the right base.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Interp.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index fe5da47d9027c8..3dc223f97a8cce 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1846,6 +1846,15 @@ inline bool This(InterpState &S, CodePtr OpPC) {
   if (!CheckThis(S, OpPC, This))
     return false;
 
+  // Ensure the This pointer has been cast to the correct base.
+  if (!This.isDummy()) {
+    assert(isa<CXXMethodDecl>(S.Current->getFunction()->getDecl()));
+    assert(This.getRecord());
+    assert(
+        This.getRecord()->getDecl() ==
+        cast<CXXMethodDecl>(S.Current->getFunction()->getDecl())->getParent());
+  }
+
   S.Stk.push<Pointer>(This);
   return true;
 }


        


More information about the cfe-commits mailing list