[clang] [clang][bytecode] Add InitLinkScope for toplevel Expr temporary (PR #123319)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 17 02:52:56 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/123319.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+1)
- (modified) clang/test/AST/ByteCode/cxx20.cpp (+15)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 4bfb80589620c1..6677119d092119 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4247,6 +4247,7 @@ bool Compiler<Emitter>::visitExpr(const Expr *E, bool DestroyToplevelScope) {
// For us, that means everything we don't
// have a PrimType for.
if (std::optional<unsigned> LocalOffset = this->allocateLocal(E)) {
+ InitLinkScope<Emitter> ILS(this, InitLink::Temp(*LocalOffset));
if (!this->emitGetPtrLocal(*LocalOffset, E))
return false;
diff --git a/clang/test/AST/ByteCode/cxx20.cpp b/clang/test/AST/ByteCode/cxx20.cpp
index 268362ceff635b..268226a7c143ed 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -893,3 +893,18 @@ namespace VirtDtor {
static_assert(test('C', 'B'));
}
+
+namespace TemporaryInNTTP {
+ template<auto n> struct B { /* ... */ };
+ struct J1 {
+ J1 *self=this;
+ };
+ /// FIXME: The bytecode interpreter emits a different diagnostic here.
+ /// The current interpreter creates a fake MaterializeTemporaryExpr (see EvaluateAsConstantExpr)
+ /// which is later used as the LValueBase of the created APValue.
+ B<J1{}> j1; // ref-error {{pointer to temporary object is not allowed in a template argument}} \
+ // expected-error {{non-type template argument is not a constant expression}} \
+ // expected-note {{pointer to temporary is not a constant expression}} \
+ // expected-note {{created here}}
+ B<2> j2; /// Ok.
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/123319
More information about the cfe-commits
mailing list