-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SILOptimizer] Don't diagnose infinite recursion if a branch terminates the program #19781
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
[SILOptimizer] Don't diagnose infinite recursion if a branch terminates the program #19781
Conversation
0ee9bea
to
9f6164b
Compare
…es the program This patch augments the infinite recursion checker to not warn if a branch terminates, but still warns if a branch calls into something with @_semantics("programtermination_point"). This way, calling fatalError doesn't disqualify you for the diagnostic, but calling exit does. This also removes the warning workaround in the standard library, and annotates the internal _assertionFailure functions as programtermination_points, so they get this treatment too.
9f6164b
to
ed00dbc
Compare
@swift-ci please test |
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.
Looks great. Some questions:
- Did you use clang-format? I thought that clang-format formatted the case statements so that they are directly under the switch?
- I was thinking about the problem that was run into. Is it possible for us to get tests for that. I am hesitant if it is truly needed since the implementation is so simple.
But functionally, LGTM! I really like where we iterated to with this. = ).
lib/SIL/SILInstructions.cpp
Outdated
@@ -1061,6 +1061,30 @@ bool TermInst::isFunctionExiting() const { | |||
llvm_unreachable("Unhandled TermKind in switch."); | |||
} | |||
|
|||
bool TermInst::isProgramTerminating() const { | |||
switch (getTermKind()) { | |||
case TermKind::BranchInst: |
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.
Did you run this through git-clang-format?
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.
Ah! Thanks, I will. Xcode's reindent-on-paste indents each case 😢
@gottesmm For posterity, the problem that caused this to revert was that By checking explicitly for the presence of an apply of something with All that to say that a possible test to ensure we don't regress on this specific bug is: func mayHaveSideEffects() {}
func x() { // expected-warning {{all paths through this function will call itself}}
if Bool.random() {
// execute some side effects
mayHaveSideEffects()
fatalError()
}
x()
} And I'll add that test. |
@swift-ci please test |
Build failed |
Build failed |
…es the program (swiftlang#19781) * [SILOptimizer] Don't diagnose infinite recursion if a branch terminates the program This patch augments the infinite recursion checker to not warn if a branch terminates, but still warns if a branch calls into something with @_semantics("programtermination_point"). This way, calling fatalError doesn't disqualify you for the diagnostic, but calling exit does. This also removes the warning workaround in the standard library, and annotates the internal _assertionFailure functions as programtermination_points, so they get this treatment too. * Fix formatting in SILInstructions.cpp * Re-add missing test
(Re-applies commit e94450e, but alters the strategy)
This patch augments the infinite recursion checker to not warn if a
branch terminates, but still warns if a branch calls into something with
@_semantics("programtermination_point"). This way, calling fatalError
doesn't disqualify you for the diagnostic, but calling exit does.
This also removes the warning workaround in the standard library, and
annotates the internal _assertionFailure functions as
programtermination_points, so they get this treatment too.
rdar://45080912