llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (nataliakokoromyti)

<details>
<summary>Changes</summary>

The existing check for BS.Base == sizeof(GlobalInlineDescriptor) required both 
isRoot() and Offset == BS.Base to be true. The pointer can have BS.Base == 
sizeof(GlobalInlineDescriptor) without satisfying isRoot() (which checks if 
Base equals getMetadataSize() or 0). This caused getFieldDesc() to be called, 
which then calls getInlineDesc(), triggering the assertion 'BS.Base != 
sizeof(GlobalInlineDescriptor)'. The fix removes the overly restrictive 
conditions and checks only for BS.Base == sizeof(GlobalInlineDescriptor) to 
determine if we should go to the GlobalInlineDescriptor's InitState.

Fixes #<!-- -->175432

---
Full diff: https://github.com/llvm/llvm-project/pull/175512.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/AST/ByteCode/Pointer.cpp (+1-2) 
- (modified) clang/test/AST/ByteCode/arrays.cpp (+9) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f62298938af93..45f0bbcec748b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -663,6 +663,8 @@ Bug Fixes to AST Handling
 - Fix comment lexing of special command names (#GH152943)
 - Use `extern` as a hint to continue parsing when recovering from a malformed 
declaration.
 
+- Fixed assertion crash in bytecode interpreter when checking initialization of
+  constexpr pointer arrays with GlobalInlineDescriptor. (#GH175432)
 Miscellaneous Bug Fixes
 ^^^^^^^^^^^^^^^^^^^^^^^
 - Fixed missing diagnostics of ``diagnose_if`` on templates involved in 
initialization. (#GH160776)
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index c5e0fd83021d7..53582bccba5b8 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -448,8 +448,7 @@ bool Pointer::isInitialized() const {
   if (!isBlockPointer())
     return true;
 
-  if (isRoot() && BS.Base == sizeof(GlobalInlineDescriptor) &&
-      Offset == BS.Base) {
+  if (BS.Base == sizeof(GlobalInlineDescriptor)) {
     const auto &GD = block()->getBlockDesc<GlobalInlineDescriptor>();
     return GD.InitState == GlobalInitState::Initialized;
   }
diff --git a/clang/test/AST/ByteCode/arrays.cpp 
b/clang/test/AST/ByteCode/arrays.cpp
index d83ae97fc8213..f9b4f7b55332a 100644
--- a/clang/test/AST/ByteCode/arrays.cpp
+++ b/clang/test/AST/ByteCode/arrays.cpp
@@ -835,3 +835,12 @@ namespace MultiDimConstructExpr {
   constexpr b d;
   static_assert(d.m[2][1].p == &d.m[2][1]);
 }
+
+// Test for issue #175432 - assertion crash with GlobalInlineDescriptor
+// Previously crashed with: Assertion `BS.Base != 
sizeof(GlobalInlineDescriptor)` failed
+namespace gh175432 {
+  constexpr const int *arr[][2] = {{nullptr, nullptr}};
+  static_assert(arr[0][0] == nullptr, "");
+  static_assert(arr[0][1] == nullptr, "");
+}
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/175512
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to