[clang] [clang][bytecode] Fix assertion in Pointer::isInitialized() for GlobalInlineDescriptor (PR #175512)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 12 02:26:15 PST 2026
https://github.com/nataliakokoromyti created https://github.com/llvm/llvm-project/pull/175512
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
>From 99a8764678429036c989dd2ba2d4c0f112c627b9 Mon Sep 17 00:00:00 2001
From: Natalia Kokoromyti <nataliakokoromyti at gmail.com>
Date: Mon, 12 Jan 2026 02:02:56 -0800
Subject: [PATCH 1/3] [clang][bytecode] Fix assertion in
Pointer::isInitialized() for GlobalInlineDescriptor
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
---
clang/lib/AST/ByteCode/Pointer.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
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;
}
>From 02e6ceb4705970bb7c7aa81345363c4148e3f22a Mon Sep 17 00:00:00 2001
From: Natalia Kokoromyti <nataliakokoromyti at gmail.com>
Date: Mon, 12 Jan 2026 02:12:16 -0800
Subject: [PATCH 2/3] [clang][bytecode] Add test case for issue #175432
Add test case for assertion crash with GlobalInlineDescriptor
when checking initialization of constexpr pointer arrays.
---
clang/test/AST/ByteCode/arrays.cpp | 9 +++++++++
1 file changed, 9 insertions(+)
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, "");
+}
+
>From d6b4680612cb5e79692309201681a82694c3d698 Mon Sep 17 00:00:00 2001
From: Natalia Kokoromyti <nataliakokoromyti at gmail.com>
Date: Mon, 12 Jan 2026 02:24:44 -0800
Subject: [PATCH 3/3] [clang] Add release note for #175432 fix
---
clang/docs/ReleaseNotes.rst | 2 ++
1 file changed, 2 insertions(+)
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)
More information about the cfe-commits
mailing list