https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/106552
None >From 5d313ed583f9ca8209fbdc04ecb0fd8174e74239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Thu, 29 Aug 2024 13:46:18 +0200 Subject: [PATCH] [clang][bytecode] Add InitLinkScope for temporary variables --- clang/lib/AST/ByteCode/Compiler.cpp | 4 +--- clang/test/AST/ByteCode/records.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 0fc942a4f1bc4f..46545a5b3267e6 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -3287,6 +3287,7 @@ template <class Emitter> bool Compiler<Emitter>::visit(const Expr *E) { if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; + InitLinkScope<Emitter> ILS(this, InitLink::Temp(*LocalIndex)); return this->visitInitializer(E); } @@ -4254,9 +4255,6 @@ bool Compiler<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) { // instance pointer of the current function frame, but e.g. to the declaration // currently being initialized. Here we emit the necessary instruction(s) for // this scenario. - if (!InitStackActive || !E->isImplicit()) - return this->emitThis(E); - if (InitStackActive && !InitStack.empty()) { unsigned StartIndex = 0; for (StartIndex = InitStack.size() - 1; StartIndex > 0; --StartIndex) { diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp index 7e3cf5b94518f7..2799afa9577b78 100644 --- a/clang/test/AST/ByteCode/records.cpp +++ b/clang/test/AST/ByteCode/records.cpp @@ -1653,3 +1653,9 @@ namespace ExprWithCleanups { constexpr auto F = true ? 1i : 2i; static_assert(F == 1i, ""); } + +namespace ExplicitThisInTemporary { + struct B { B *p = this; }; + constexpr bool g(B b) { return &b == b.p; } + static_assert(g({}), ""); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits