mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
c36f842bed
llvm::cl::opt flags are compiled out in non-asserts builds, making these
debug flags unavailable in an important category of use cases — debugging
a release compiler in lldb. By promoting them to Swift frontend flags stored
in DiagnosticOptions/SILOptions, they are available in all build
configurations.
The three existing flags are migrated:
-diagnostics-assert-on-error
-diagnostics-assert-on-warning
-sil-region-isolation-assert-on-unknown-pattern
(backing field renamed to AbortOnUnknownRegionIsolationPatternError)
A new flag is added:
-diagnostics-assert-on-group <group>
Traps when any diagnostic belonging to the named group is emitted,
allowing targeted breakpoints on a single diagnostic group rather than
all errors or all warnings.
The assert-on-{error,warning,group} flags are intentionally kept separate
from the normal diagnostic suppression/escalation machinery so that they
remain useful while other diagnostics are also being emitted.
Tests are added for all four flags.
149 lines
5.7 KiB
C++
149 lines
5.7 KiB
C++
//===--- DiagnosticOptions.h ------------------------------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_BASIC_DIAGNOSTICOPTIONS_H
|
|
#define SWIFT_BASIC_DIAGNOSTICOPTIONS_H
|
|
|
|
#include "swift/Basic/PrintDiagnosticNamesMode.h"
|
|
#include "swift/Basic/WarningGroupBehaviorRule.h"
|
|
#include "llvm/ADT/Hashing.h"
|
|
#include "llvm/ADT/SmallSet.h"
|
|
#include <vector>
|
|
|
|
namespace swift {
|
|
|
|
/// Options for controlling diagnostics.
|
|
class DiagnosticOptions {
|
|
public:
|
|
/// Indicates whether textual diagnostics should use color.
|
|
bool UseColor = false;
|
|
|
|
/// Indicates whether the diagnostics produced during compilation should be
|
|
/// checked against expected diagnostics, indicated by markers in the
|
|
/// input source file.
|
|
enum {
|
|
NoVerify,
|
|
Verify,
|
|
VerifyAndApplyFixes
|
|
} VerifyMode = NoVerify;
|
|
|
|
enum FormattingStyle { LLVM, Swift };
|
|
|
|
/// Indicates whether to allow diagnostics for \c <unknown> locations if
|
|
/// \c VerifyMode is not \c NoVerify.
|
|
bool VerifyIgnoreUnknown = false;
|
|
|
|
/// Indicates whether to allow diagnostics for locations outside files parsed
|
|
/// for 'expected' diagnostics if \c VerifyMode is not \c NoVerify. Does not
|
|
/// allow diagnostics at <unknown>, that is controlled by VerifyIgnoreUnknown.
|
|
bool VerifyIgnoreUnrelated = false;
|
|
|
|
/// Indicates whether to ignore \c diag::in_macro_expansion. This is useful
|
|
/// for when they occur in unnamed buffers (such as clang attribute buffers),
|
|
/// but VerifyIgnoreUnrelated is too blunt of a tool. Note that notes of this
|
|
/// kind are not printed by \c PrintingDiagnosticConsumer.
|
|
bool VerifyIgnoreMacroLocationNote = false;
|
|
|
|
/// Indicates whether diagnostic passes should be skipped.
|
|
bool SkipDiagnosticPasses = false;
|
|
|
|
/// Additional non-source files which will have diagnostics emitted in them,
|
|
/// and which should be scanned for expectations by the diagnostic verifier.
|
|
std::vector<std::string> AdditionalVerifierFiles;
|
|
|
|
/// Keep emitting subsequent diagnostics after a fatal error.
|
|
bool ShowDiagnosticsAfterFatalError = false;
|
|
|
|
/// Trap when any error diagnostic is emitted. For compiler developers only.
|
|
///
|
|
/// These flags are intentionally separate from the normal diagnostic
|
|
/// suppression and escalation machinery. That separation is deliberate:
|
|
/// they are useful precisely when *other* diagnostics are being emitted (e.g.
|
|
/// when debugging a miscompile by setting an lldb breakpoint on the trap), so
|
|
/// they must not be suppressed by -suppress-warnings or similar options.
|
|
bool AssertOnError = false;
|
|
|
|
/// Trap when any warning diagnostic is emitted. For compiler developers only.
|
|
/// See AssertOnError for why this is separate from the normal machinery.
|
|
bool AssertOnWarning = false;
|
|
|
|
/// Trap when any diagnostic belonging to one of these groups is emitted.
|
|
/// Allows targeting a single diagnostic group rather than all errors or all
|
|
/// warnings. For compiler developers only.
|
|
/// See AssertOnError for why this is separate from the normal machinery.
|
|
llvm::SmallSet<DiagGroupID, 1> AssertOnGroupIDs;
|
|
|
|
/// When emitting fixits as code edits, apply all fixits from diagnostics
|
|
/// without any filtering.
|
|
bool FixitCodeForAllDiagnostics = false;
|
|
|
|
/// Suppress all warnings
|
|
bool SuppressWarnings = false;
|
|
|
|
/// Suppress all notes
|
|
bool SuppressNotes = false;
|
|
|
|
/// Suppress all remarks
|
|
bool SuppressRemarks = false;
|
|
|
|
/// Rules for escalating warnings to errors
|
|
llvm::SmallVector<WarningGroupBehaviorRule, 4> WarningGroupControlRules;
|
|
|
|
/// Unknown warning group names specified via -Werror or -Wwarning.
|
|
/// These will be diagnosed when the DiagnosticEngine is configured.
|
|
llvm::SmallVector<std::string, 1> UnknownWarningGroups;
|
|
|
|
/// When printing diagnostics, include either the diagnostic name
|
|
/// (diag::whatever) at the end or the associated diagnostic group.
|
|
PrintDiagnosticNamesMode PrintDiagnosticNames =
|
|
PrintDiagnosticNamesMode::None;
|
|
|
|
/// Whether to emit diagnostics in the terse LLVM style or in a more
|
|
/// descriptive style that's specific to Swift.
|
|
FormattingStyle PrintedFormattingStyle = FormattingStyle::Swift;
|
|
|
|
/// Whether to emit macro expansion buffers into separate, temporary files.
|
|
bool EmitMacroExpansionFiles = true;
|
|
|
|
std::string DiagnosticDocumentationPath = "";
|
|
|
|
std::string LocalizationCode = "";
|
|
|
|
/// Path to a directory of diagnostic localization tables.
|
|
std::string LocalizationPath = "";
|
|
|
|
/// A list of prefixes that are appended to expected- that the diagnostic
|
|
/// verifier should check for diagnostics.
|
|
///
|
|
/// For example, if one placed the phrase "NAME", the verifier will check for:
|
|
/// expected-$NAME{error,note,warning,remark} as well as the normal expected-
|
|
/// prefixes.
|
|
std::vector<std::string> AdditionalDiagnosticVerifierPrefixes;
|
|
|
|
/// Return a hash code of any components from these options that should
|
|
/// contribute to a Swift Bridging PCH hash.
|
|
llvm::hash_code getPCHHashComponents() const {
|
|
// Nothing here that contributes anything significant when emitting the PCH.
|
|
return llvm::hash_value(0);
|
|
}
|
|
|
|
/// Return a hash code of any components from these options that should
|
|
/// contribute to a Swift Dependency Scanning hash.
|
|
llvm::hash_code getModuleScanningHashComponents() const {
|
|
return llvm::hash_value(0);
|
|
}
|
|
};
|
|
|
|
} // end namespace swift
|
|
|
|
#endif // SWIFT_BASIC_DIAGNOSTICOPTIONS_H
|