[clang] [clang][bytecode] Allow constexpr-unknown values in GetPtrBase{,Pop} (PR #193903)

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 23 23:49:44 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

We can handle them here and it's needed to make some libc++ tests work.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.h (-6) 
- (added) clang/test/AST/ByteCode/libcxx/constexpr-unknown-getbase.cpp (+35) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 0f7f2c4e1fdec..3cf50cb212df1 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2031,9 +2031,6 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
     return true;
   }
 
-  if (isConstexprUnknown(Ptr))
-    return false;
-
   if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
     return false;
   const Pointer &Result = Ptr.atField(Off);
@@ -2057,9 +2054,6 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off,
     return true;
   }
 
-  if (isConstexprUnknown(Ptr))
-    return false;
-
   if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
     return false;
   const Pointer &Result = Ptr.atField(Off);
diff --git a/clang/test/AST/ByteCode/libcxx/constexpr-unknown-getbase.cpp b/clang/test/AST/ByteCode/libcxx/constexpr-unknown-getbase.cpp
new file mode 100644
index 0000000000000..740a01c09517a
--- /dev/null
+++ b/clang/test/AST/ByteCode/libcxx/constexpr-unknown-getbase.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -std=c++2c -fexperimental-new-constant-interpreter -verify=expected,both %s
+// RUN: %clang_cc1 -std=c++2c  -verify=ref,both                                             %s
+
+// both-no-diagnostics
+
+namespace std {
+template <class _Tp> struct __cw_fixed_value {
+  constexpr __cw_fixed_value(_Tp) : __data() {}
+  _Tp __data;
+};
+template <__cw_fixed_value> struct constant_wrapper;
+template <class _Tp>
+concept __constexpr_param = requires { typename constant_wrapper<_Tp::value>; };
+template <__cw_fixed_value _Xp> auto cw = constant_wrapper<_Xp>{};
+struct __cw_operators {
+  template <__constexpr_param _Lp, __constexpr_param _Rp>
+  friend constexpr auto operator==(_Lp, _Rp) -> constant_wrapper<_Rp::value> {
+    return {};
+  }
+};
+template <__cw_fixed_value _Xp> struct constant_wrapper : __cw_operators {
+  static constexpr auto value = _Xp.__data;
+  constexpr operator decltype(value)() { return value; }
+};
+} // namespace std
+void final_phase(auto gathered, auto available) {
+  if constexpr (gathered == available)
+    ;
+}
+void impeccable_underground_planning() {
+  auto gathered_quantity(std::cw<3>), all_available = std::cw<5>;
+  final_phase(gathered_quantity, all_available);
+}
+
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/193903


More information about the cfe-commits mailing list