-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[codegen] Emit missing cleanups when an expression contains a branch #80698
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
28d9071
[misc-coroutine-hostile-raii] Use getOperand instead of getCommonExpr
usx95 442809c
[codegen] Emit cleanups for lifetime-extended temporaries when statme…
usx95 eeabfa2
Merge branch 'llvm:main' into coro-destruct-temporary
usx95 4125808
format
usx95 3543711
Emit not-all but only necessary lifetime-extended cleanups for each b…
usx95 d23cdb3
format
usx95 dc3659a
format
usx95 ddf7c24
format
usx95 a58284b
Add BranchInExpr cleanups kind to handle more missing dtor calls
usx95 cf5024c
remove dead code
usx95 db43f02
format
usx95 034ebda
add branch-in-expr cleanup for lambda init
usx95 b902c61
fix var name
usx95 12706f2
fix pre-existing bug
usx95 ed016d6
fix EmitNewArrayInitializer
usx95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
clang/test/CodeGenCXX/control-flow-in-stmt-expr-cleanup.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s | ||
|
||
// Context: GH63818 | ||
struct Printy { | ||
~Printy() { } | ||
}; | ||
|
||
struct Printies { | ||
const Printy &a; | ||
const Printy &b; | ||
~Printies() {} | ||
}; | ||
|
||
bool foo(); | ||
|
||
void bar() { | ||
// CHECK: define dso_local void @_Z3barv() | ||
// CHECK-NOT: call void @_ZN6PrintyD1Ev | ||
Printies p2{ | ||
Printy(), | ||
({ | ||
if(foo()) { | ||
// CHECK: if.then: | ||
// CHECK-NEXT: call void @_ZN6PrintyD1Ev | ||
// CHECK-NEXT: br label %return | ||
// CHECK-NOT: call void @_ZN6PrintyD1Ev | ||
return; | ||
} | ||
Printy(); | ||
})}; | ||
// CHECK: if.end: | ||
// CHECK: call void @_ZN8PrintiesD1Ev | ||
// CHECK: call void @_ZN6PrintyD1Ev | ||
// CHECK: call void @_ZN6PrintyD1Ev | ||
// CHECK-NEXT: br label %return | ||
return; | ||
// CHECK-NOT: call void @_ZN6PrintyD1Ev | ||
} | ||
|
||
|
||
void test_break() { | ||
// CHECK: define dso_local void @_Z10test_breakv() | ||
// CHECK-NOT: call void @_ZN6PrintyD1Ev | ||
Printies p2{Printy(), ({ | ||
for (;;) { | ||
Printies p3{Printy(), ({ | ||
if(foo()) { | ||
break; | ||
// CHECK: if.then: | ||
// CHECK-NEXT: call void @_ZN6PrintyD1Ev | ||
// CHECK-NEXT: br label %for.end | ||
// CHECK-NOT: call void @_ZN6PrintyD1Ev | ||
} | ||
Printy(); | ||
})}; | ||
// CHECK: if.end: | ||
// CHECK: call void @_ZN6PrintyD1Ev | ||
// CHECK: call void @_ZN6PrintyD1Ev | ||
// CHECK-NOT: call void @_ZN6PrintyD1Ev | ||
} | ||
Printy(); | ||
})}; | ||
// CHECK: for.end: | ||
// CHECK-COUNT-2: call void @_ZN6PrintyD1Ev | ||
// CHECK-NEXT: ret void | ||
// CHECK-NOT: call void @_ZN6PrintyD1Ev | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// RUN: %clang_cc1 --std=c++20 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s | ||
|
||
// Context: GH63818 | ||
|
||
#include "Inputs/coroutine.h" | ||
|
||
struct coroutine { | ||
struct promise_type; | ||
std::coroutine_handle<promise_type> handle; | ||
}; | ||
|
||
struct coroutine::promise_type { | ||
coroutine get_return_object() { | ||
return {std::coroutine_handle<promise_type>::from_promise(*this)}; | ||
} | ||
std::suspend_never initial_suspend() noexcept { return {}; } | ||
std::suspend_always final_suspend() noexcept { return {}; } | ||
void return_void() {} | ||
void unhandled_exception() {} | ||
}; | ||
|
||
struct Printy { ~Printy(); }; | ||
|
||
struct Printies { | ||
const Printy &a; | ||
const Printy &b; | ||
const Printy &c; | ||
}; | ||
|
||
struct Awaiter : std::suspend_always { | ||
Printy await_resume() { return {}; } | ||
}; | ||
|
||
// CHECK: define dso_local ptr @_Z5test1v() | ||
coroutine test1() { | ||
// CHECK-NOT: @_ZN6PrintyD1Ev | ||
Printies p1{ | ||
Printy(), | ||
co_await Awaiter{}, | ||
// CHECK: await.cleanup: | ||
// CHECK-NEXT: call void @_ZN6PrintyD1Ev | ||
// CHECK-NEXT: br label %cleanup{{.*}}.from.await.cleanup | ||
// CHECK-NOT: @_ZN6PrintyD1Ev | ||
|
||
co_await Awaiter{} | ||
// CHECK: await2.cleanup: | ||
// CHECK-NEXT: call void @_ZN6PrintyD1Ev | ||
// CHECK-NEXT: call void @_ZN6PrintyD1Ev | ||
// CHECK-NEXT: br label %cleanup{{.*}}.from.await2.cleanup | ||
// CHECK-NOT: @_ZN6PrintyD1Ev | ||
}; | ||
|
||
// CHECK-COUNT-3: call void @_ZN6PrintyD1Ev | ||
// CHECK-NEXT: br label | ||
|
||
// CHECK-NOT: @_ZN6PrintyD1Ev | ||
|
||
// CHECK: unreachable: | ||
} | ||
|
||
void bar(const Printy& a, const Printy& b); | ||
|
||
// CHECK: define dso_local ptr @_Z5test2v() | ||
coroutine test2() { | ||
// CHECK-NOT: @_ZN6PrintyD1Ev | ||
bar( | ||
Printy(), | ||
co_await Awaiter{} | ||
// CHECK: await.cleanup: | ||
// CHECK-NEXT: br label %cleanup{{.*}}.from.await.cleanup | ||
// CHECK-NOT: @_ZN6PrintyD1Ev | ||
); | ||
// CHECK: await.ready: | ||
// CHECK: call void @_ZN6PrintyD1Ev | ||
// CHECK-NOT: @_ZN6PrintyD1Ev | ||
|
||
// CHECK: cleanup{{.*}}: | ||
// CHECK: call void @_ZN6PrintyD1Ev | ||
// CHECK-NOT: @_ZN6PrintyD1Ev | ||
|
||
// CHECK: unreachable: | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"0" seems wrong; goto out of a StmtExpr is legal, the same way "break" is legal. But I guess we can't actually compute the correct number here; maybe we need to do something with BranchFixups?
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.
(I'm okay with implementing a fix with restricted scope if you want to get something into the LLVM 18 branch. But before we decide that, I'd like some idea of what's required to actually implement this completely.)