[clang] [clang][bytecode] Emit has_lvalue for opaque pointers (PR #235616)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 25 23:41:10 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/235616
They always have a base and need the note emitted so HasConstantInitialization of the variable is false.
>From 15478bfdef9a7b20abdd3b3fdce40bd2669257eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 26 Oct 2026 07:39:40 +0100
Subject: [PATCH] [clang][bytecode] Emit has_lvalue for opaque pointers
They always have a base and need the note emitted so
HasConstantInitialization of the variable is false.
---
clang/lib/AST/ByteCode/Interp.cpp | 2 +-
clang/test/AST/ByteCode/ms.cpp | 16 +++++++++++-----
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 02beb38b7e2c65..4d3ee95df216c0 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -2998,7 +2998,7 @@ bool CheckPointerToIntegralCast(InterpState &S, CodePtr OpPC,
S.CCEDiag(E, diag::note_constexpr_invalid_cast_ptrtoint)
<< diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
<< S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
- if (Ptr.isBlockPointer() && !Ptr.isZero())
+ if ((Ptr.isBlockPointer() && !Ptr.isZero()) || Ptr.isOpaquePointer())
S.CCEDiag(E, diag::note_constexpr_has_lvalue) << S.Current->getRange(OpPC);
if (Ptr.isIntegralPointer())
return true;
diff --git a/clang/test/AST/ByteCode/ms.cpp b/clang/test/AST/ByteCode/ms.cpp
index 35ffcbccae3b3a..4a77ef4b543f86 100644
--- a/clang/test/AST/ByteCode/ms.cpp
+++ b/clang/test/AST/ByteCode/ms.cpp
@@ -1,8 +1,5 @@
-// RUN: %clang_cc1 -verify=ref,both %s -fms-extensions -fcxx-exceptions
-// RUN: %clang_cc1 -verify=expected,both %s -fexperimental-new-constant-interpreter -fms-extensions -fcxx-exceptions
-
-// ref-no-diagnostics
-// expected-no-diagnostics
+// RUN: %clang_cc1 -verify=ref,both %s -fms-compatibility -fms-extensions -fcxx-exceptions
+// RUN: %clang_cc1 -verify=expected,both %s -fexperimental-new-constant-interpreter -fms-compatibility -fms-extensions -fcxx-exceptions
/// Used to assert because the two parameters to _rotl do not have the same type.
static_assert(_rotl(0x01, 5) == 32);
@@ -19,3 +16,12 @@ constexpr int noopIsActuallyNoop() {
return a;
}
static_assert(noopIsActuallyNoop() == 0);
+
+
+auto foo() {
+ const long bar = (long)&&label; // both-note {{via initialization of variable 'bar' here}}
+ return (void *)bar; // both-warning {{returning address of label, which is local}}
+label:
+} // both-warning {{C++23 extension}}
+
+
More information about the cfe-commits
mailing list