-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[clang][bytecode] Add InitLinkScope for temporary variables #106552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesFull diff: https://github.com/llvm/llvm-project/pull/106552.diff 2 Files Affected:
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({}), "");
+}
|
shafik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add more details to the summary explaining why the fix is necessary.
|
@AaronBallman Can you confirm whether the following behavior is correct? When a To properly implement this, I'd need to create a temporary variable whenever I encounter a |
What do you mean "point to"? (They would point to the |
|
In this code: namespace ExplicitThisInTemporary {
struct B { B *p = this; };
constexpr bool g(B b) { return &b == b.p; }
static_assert(g({}), "");
}The AST for the the |
I believe that is correct. The CC @zygoloid @hubert-reinterpretcast @cor3ntin @shafik for some additional opinions. |
|
Fixed differently by #122871 |
No description provided.