[clang] [clang][bytecode] Diagnose array-to-pointer decays of dummy pointers (PR #106366)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 28 03:59:50 PDT 2024
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/106366
We have type information for them now, so we can do this.
>From 670598d602949cee9bc8cbfe563563aa699d8505 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 28 Aug 2024 12:58:29 +0200
Subject: [PATCH] [clang][bytecode] Diagnose array-to-pointer decays of dummy
pointers
We have type information for them now, so we can do this.
---
clang/lib/AST/ByteCode/Interp.h | 2 +-
clang/test/AST/ByteCode/arrays.cpp | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 7ba51f737db491..72f4e8e2764c4e 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2535,7 +2535,7 @@ inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
if (!CheckRange(S, OpPC, Ptr, CSK_ArrayToPointer))
return false;
- if (Ptr.isRoot() || !Ptr.isUnknownSizeArray() || Ptr.isDummy()) {
+ if (Ptr.isRoot() || !Ptr.isUnknownSizeArray()) {
S.Stk.push<Pointer>(Ptr.atIndex(0));
return true;
}
diff --git a/clang/test/AST/ByteCode/arrays.cpp b/clang/test/AST/ByteCode/arrays.cpp
index 47706bedcf3f0c..4097c65f7c6fba 100644
--- a/clang/test/AST/ByteCode/arrays.cpp
+++ b/clang/test/AST/ByteCode/arrays.cpp
@@ -436,6 +436,15 @@ namespace Incomplete {
constexpr int C = *F.a; // both-error {{must be initialized by a constant expression}} \
// both-note {{array-to-pointer decay of array member without known bound}}
+ struct X {
+ int a;
+ int b[];
+ };
+ extern X x;
+ constexpr int *xb = x.b; // both-error {{must be initialized by a constant expression}} \
+ // both-note {{array-to-pointer decay of array member without known bound}}
+
+
/// These are from test/SemaCXX/constant-expression-cxx11.cpp
extern int arr[];
constexpr int *c = &arr[1]; // both-error {{must be initialized by a constant expression}} \
More information about the cfe-commits
mailing list