[clang] c8c9af1 - [clang][Interp] Decay arrays to the first element (#72660)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 12 02:01:51 PST 2023
Author: Timm Baeder
Date: 2023-12-12T11:01:47+01:00
New Revision: c8c9af150d34306ee0af94baf8357891ace233ba
URL: https://github.com/llvm/llvm-project/commit/c8c9af150d34306ee0af94baf8357891ace233ba
DIFF: https://github.com/llvm/llvm-project/commit/c8c9af150d34306ee0af94baf8357891ace233ba.diff
LOG: [clang][Interp] Decay arrays to the first element (#72660)
This way we have a pointer to the
first element on the stack.
Added:
Modified:
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/arrays.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 6cf122f2ba55e1..a240d74d63425e 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1826,10 +1826,12 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) {
/// Just takes a pointer and checks if its' an incomplete
/// array type.
inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
- const Pointer &Ptr = S.Stk.peek<Pointer>();
+ const Pointer &Ptr = S.Stk.pop<Pointer>();
- if (!Ptr.isUnknownSizeArray())
+ if (!Ptr.isUnknownSizeArray()) {
+ S.Stk.push<Pointer>(Ptr.atIndex(0));
return true;
+ }
const SourceInfo &E = S.Current->getSource(OpPC);
S.FFDiag(E, diag::note_constexpr_unsupported_unsized_array);
diff --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp
index 34e0086fb9ee8c..c455731e76699f 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -27,6 +27,10 @@ static_assert(foo[2][3] == &m, "");
static_assert(foo[2][4] == nullptr, "");
+constexpr int SomeInt[] = {1};
+constexpr int getSomeInt() { return *SomeInt; }
+static_assert(getSomeInt() == 1, "");
+
/// A init list for a primitive value.
constexpr int f{5};
static_assert(f == 5, "");
More information about the cfe-commits
mailing list