[clang] [clang][Interp] Fix `ArrayInitLoopExpr` handling (PR #67886)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 30 08:11:54 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
<details>
<summary>Changes</summary>
This patch implements the changes from #<!-- -->67722 in Interp.
---
Full diff: https://github.com/llvm/llvm-project/pull/67886.diff
2 Files Affected:
- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+1)
- (modified) clang/test/AST/Interp/cxx20.cpp (+4-6)
``````````diff
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 46906377863bd74..1e2db3219865a53 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -803,6 +803,7 @@ bool ByteCodeExprGen<Emitter>::VisitArrayInitLoopExpr(
// where the LHS is on the stack (the target array)
// and the RHS is our SubExpr.
for (size_t I = 0; I != Size; ++I) {
+ BlockScope<Emitter> Scope(this);
ArrayIndexScope<Emitter> IndexScope(this, I);
if (ElemT) {
diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 197090b0a37d9df..5c0a88ce9612e1b 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -701,13 +701,12 @@ namespace ThreeWayCmp {
static_assert(pa2 <=> pa1 == 1, "");
}
-// FIXME: Interp should also be able to evaluate this snippet properly.
namespace ConstexprArrayInitLoopExprDestructors
{
struct Highlander {
int *p = 0;
constexpr Highlander() {}
- constexpr void set(int *p) { this->p = p; ++*p; if (*p != 1) throw "there can be only one"; } // expected-note {{not valid in a constant expression}}
+ constexpr void set(int *p) { this->p = p; ++*p; if (*p != 1) throw "there can be only one"; }
constexpr ~Highlander() { --*p; }
};
@@ -715,19 +714,18 @@ namespace ConstexprArrayInitLoopExprDestructors
int *p;
constexpr X(int *p) : p(p) {}
constexpr X(const X &x, Highlander &&h = Highlander()) : p(x.p) {
- h.set(p); // expected-note {{in call to '&Highlander()->set(&n)'}}
+ h.set(p);
}
};
constexpr int f() {
int n = 0;
X x[3] = {&n, &n, &n};
- auto [a, b, c] = x; // expected-note {{in call to 'X(x[0], Highlander())'}}
+ auto [a, b, c] = x;
return n;
}
- static_assert(f() == 0); // expected-error {{not an integral constant expression}} \
- // expected-note {{in call to 'f()'}}
+ static_assert(f() == 0);
int main() {
return f();
``````````
</details>
https://github.com/llvm/llvm-project/pull/67886
More information about the cfe-commits
mailing list