Skip to content

Commit 69335f0

Browse files
committed
[diagnostics] Add the llvm option swift-diagnostics-assert-on-warning to cause the diagnostics engine to assert upon triggering a warning.
This is an option only intending to help compiler developers triage/track down why a warning is being emitted in a quick manner. It will only be in asserts builds since it is an LLVM option.
1 parent bf418eb commit 69335f0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,14 @@ static DiagnosticKind toDiagnosticKind(DiagnosticState::Behavior behavior) {
622622
llvm_unreachable("Unhandled DiagnosticKind in switch.");
623623
}
624624

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

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

639643
assert((!AssertOnError || !anyErrorOccurred) && "We emitted an error?!");
644+
assert((!AssertOnWarning || (lvl != Behavior::Warning)) &&
645+
"We emitted a warning?!");
640646
previousBehavior = lvl;
641647
return lvl;
642648
};

0 commit comments

Comments
 (0)