[clang] [clang][bytecode] Fix isZero() assertion in OffsetHelper (PR #242271)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 13 03:54:19 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
zero pointers are possible and expected here, e.g. integer pointers with zero value.
---
Full diff: https://github.com/llvm/llvm-project/pull/242271.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.h (+1-3)
- (modified) clang/test/Parser/cxx-ambig-paren-expr.cpp (+1)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 3b1df5fe7615e..18c2421a67231 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2504,9 +2504,6 @@ bool TrivialCopy(InterpState &S, CodePtr OpPC, bool Activate,
template <class T, ArithOp Op>
std::optional<Pointer> OffsetHelper(InterpState &S, CodePtr OpPC,
const T &Offset, const Pointer &Ptr) {
- if (S.getLangOpts().CPlusPlus)
- assert(!Ptr.isZero());
-
// This is much simpler for integral pointers, so handle them first.
if (Ptr.isIntegralPointer()) {
uint64_t V = Ptr.getIntegerRepresentation();
@@ -2549,6 +2546,7 @@ std::optional<Pointer> OffsetHelper(InterpState &S, CodePtr OpPC,
}
assert(Ptr.isBlockPointer());
+ assert(!Ptr.isZero());
PtrView P = Ptr.view();
// Arrays of unknown bounds cannot have pointers into them.
diff --git a/clang/test/Parser/cxx-ambig-paren-expr.cpp b/clang/test/Parser/cxx-ambig-paren-expr.cpp
index 160ce4c3bb72f..1985f3c96e0ed 100644
--- a/clang/test/Parser/cxx-ambig-paren-expr.cpp
+++ b/clang/test/Parser/cxx-ambig-paren-expr.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s -fexperimental-new-constant-interpreter
void f() {
typedef int T;
``````````
</details>
https://github.com/llvm/llvm-project/pull/242271
More information about the cfe-commits
mailing list