[clang] bb3d261 - [clang][Interp] Protect GetPtrField ops from unknown size arrays

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue May 21 03:33:31 PDT 2024


Author: Timm Bäder
Date: 2024-05-21T12:32:59+02:00
New Revision: bb3d261f55e72e313fd8ddfefac3b47cfca2f656

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

LOG: [clang][Interp] Protect GetPtrField ops from unknown size arrays

Added: 
    

Modified: 
    clang/lib/AST/Interp/Interp.h
    clang/test/AST/Interp/arrays.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index d9f23a4b8c965..bc2ca126ce364 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1245,6 +1245,8 @@ inline bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off) {
     return false;
   if (!CheckRange(S, OpPC, Ptr, CSK_Field))
     return false;
+  if (!CheckArray(S, OpPC, Ptr))
+    return false;
   if (!CheckSubobject(S, OpPC, Ptr, CSK_Field))
     return false;
 

diff  --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp
index 929f25b95fa1f..71b6dabf39e45 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -595,3 +595,12 @@ int test_multiarray22() {
 }
 
 #endif
+
+namespace ArrayMemberAccess {
+  struct A {
+    int x;
+  };
+  void f(const A (&a)[]) {
+    bool cond = a->x;
+  }
+}


        


More information about the cfe-commits mailing list