Skip to content

[diagnostics] Add the llvm option swift-diagnostics-assert-on-warning… #25006

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/AST/DiagnosticEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,14 @@ static DiagnosticKind toDiagnosticKind(DiagnosticState::Behavior behavior) {
llvm_unreachable("Unhandled DiagnosticKind in switch.");
}

/// A special option only for compiler writers that causes Diagnostics to assert
/// when a failure diagnostic is emitted. Intended for use in the debugger.
// A special option only for compiler writers that causes Diagnostics to assert
// when a failure diagnostic is emitted. Intended for use in the debugger.
llvm::cl::opt<bool> AssertOnError("swift-diagnostics-assert-on-error",
llvm::cl::init(false));
// A special option only for compiler writers that causes Diagnostics to assert
// when a warning diagnostic is emitted. Intended for use in the debugger.
llvm::cl::opt<bool> AssertOnWarning("swift-diagnostics-assert-on-warning",
llvm::cl::init(false));

DiagnosticState::Behavior DiagnosticState::determineBehavior(DiagID id) {
auto set = [this](DiagnosticState::Behavior lvl) {
Expand All @@ -637,6 +641,8 @@ DiagnosticState::Behavior DiagnosticState::determineBehavior(DiagID id) {
}

assert((!AssertOnError || !anyErrorOccurred) && "We emitted an error?!");
assert((!AssertOnWarning || (lvl != Behavior::Warning)) &&
"We emitted a warning?!");
previousBehavior = lvl;
return lvl;
};
Expand Down