[clang] e9174ba - [clang][Interp] Always decay root array pointers to the first element
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 6 08:43:57 PDT 2024
Author: Timm Bäder
Date: 2024-06-06T17:43:40+02:00
New Revision: e9174ba789531b26709764b4f404ec368b77db44
URL: https://github.com/llvm/llvm-project/commit/e9174ba789531b26709764b4f404ec368b77db44
DIFF: https://github.com/llvm/llvm-project/commit/e9174ba789531b26709764b4f404ec368b77db44.diff
LOG: [clang][Interp] Always decay root array pointers to the first element
This is similar to what the current interpreter does.
Added:
Modified:
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/arrays.cpp
clang/test/AST/Interp/literals.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 1248eeb79cbfa..98caea5c70147 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2194,7 +2194,7 @@ inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
if (!CheckRange(S, OpPC, Ptr, CSK_ArrayToPointer))
return false;
- if (!Ptr.isUnknownSizeArray() || Ptr.isDummy()) {
+ if (Ptr.isRoot() || !Ptr.isUnknownSizeArray() || Ptr.isDummy()) {
S.Stk.push<Pointer>(Ptr.atIndex(0));
return true;
}
diff --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp
index 6146d41c5ff57..6f6fca8c1cfd8 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -615,3 +615,11 @@ namespace OnePastEndSub {
constexpr A a[3][3];
constexpr int
diff 2 = &a[1][3] - &a[1][0]; /// Used to crash.
}
+
+static int same_entity_2[3];
+constexpr int *get2() {
+ // This is a redeclaration of the same entity, even though it doesn't
+ // inherit the type of the prior declaration.
+ extern int same_entity_2[];
+ return same_entity_2;
+}
diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index 27b2af7db0da0..5a29013a053a2 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -1209,7 +1209,7 @@ namespace incdecbool {
constexpr int externvar1() { // both-error {{never produces a constant expression}}
extern char arr[]; // ref-note {{declared here}}
return arr[0]; // ref-note {{read of non-constexpr variable 'arr'}} \
- // expected-note {{array-to-pointer decay of array member without known bound is not supported}}
+ // expected-note {{indexing of array without known bound}}
}
#endif
More information about the cfe-commits
mailing list