forked from OSchip/llvm-project
DiagnosticIDs: use diagnostic severities to simplify extension handling
llvm-svn: 211479
This commit is contained in:
parent
343cd6f056
commit
ac4e8e5fca
|
@ -146,13 +146,6 @@ public:
|
|||
Fatal = DiagnosticIDs::Fatal
|
||||
};
|
||||
|
||||
/// \brief How do we handle otherwise-unmapped extension?
|
||||
///
|
||||
/// This is controlled by -pedantic and -pedantic-errors.
|
||||
enum ExtensionHandling {
|
||||
Ext_Ignore, Ext_Warn, Ext_Error
|
||||
};
|
||||
|
||||
enum ArgumentKind {
|
||||
ak_std_string, ///< std::string
|
||||
ak_c_string, ///< const char *
|
||||
|
@ -190,7 +183,7 @@ private:
|
|||
// 0 -> no limit.
|
||||
unsigned ConstexprBacktraceLimit; // Cap on depth of constexpr evaluation
|
||||
// backtrace stack, 0 -> no limit.
|
||||
ExtensionHandling ExtBehavior; // Map extensions onto warnings or errors?
|
||||
diag::Severity ExtBehavior; // Map extensions to warnings or errors?
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> Diags;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
DiagnosticConsumer *Client;
|
||||
|
@ -523,10 +516,8 @@ public:
|
|||
/// mapped onto ignore/warning/error.
|
||||
///
|
||||
/// This corresponds to the GCC -pedantic and -pedantic-errors option.
|
||||
void setExtensionHandlingBehavior(ExtensionHandling H) {
|
||||
ExtBehavior = H;
|
||||
}
|
||||
ExtensionHandling getExtensionHandlingBehavior() const { return ExtBehavior; }
|
||||
void setExtensionHandlingBehavior(diag::Severity H) { ExtBehavior = H; }
|
||||
diag::Severity getExtensionHandlingBehavior() const { return ExtBehavior; }
|
||||
|
||||
/// \brief Counter bumped when an __extension__ block is/ encountered.
|
||||
///
|
||||
|
|
|
@ -54,7 +54,7 @@ DiagnosticsEngine::DiagnosticsEngine(
|
|||
PrintTemplateTree = false;
|
||||
ShowColors = false;
|
||||
ShowOverloads = Ovl_All;
|
||||
ExtBehavior = Ext_Ignore;
|
||||
ExtBehavior = diag::Severity::Ignored;
|
||||
|
||||
ErrorLimit = 0;
|
||||
TemplateBacktraceLimit = 0;
|
||||
|
|
|
@ -440,23 +440,8 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
|
|||
|
||||
// For extension diagnostics that haven't been explicitly mapped, check if we
|
||||
// should upgrade the diagnostic.
|
||||
if (IsExtensionDiag && !Mapping.isUser()) {
|
||||
switch (Diag.ExtBehavior) {
|
||||
case DiagnosticsEngine::Ext_Ignore:
|
||||
break;
|
||||
case DiagnosticsEngine::Ext_Warn:
|
||||
// Upgrade ignored diagnostics to warnings.
|
||||
if (Result == diag::Severity::Ignored)
|
||||
Result = diag::Severity::Warning;
|
||||
break;
|
||||
case DiagnosticsEngine::Ext_Error:
|
||||
// Upgrade ignored or warning diagnostics to errors.
|
||||
if (Result == diag::Severity::Ignored ||
|
||||
Result == diag::Severity::Warning)
|
||||
Result = diag::Severity::Error;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (IsExtensionDiag && !Mapping.isUser())
|
||||
Result = std::max(Result, Diag.ExtBehavior);
|
||||
|
||||
// At this point, ignored errors can no longer be upgraded.
|
||||
if (Result == diag::Severity::Ignored)
|
||||
|
|
|
@ -67,11 +67,11 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
|
|||
// extension diagnostics onto WARNING or ERROR unless the user has futz'd
|
||||
// around with them explicitly.
|
||||
if (Opts.PedanticErrors)
|
||||
Diags.setExtensionHandlingBehavior(DiagnosticsEngine::Ext_Error);
|
||||
Diags.setExtensionHandlingBehavior(diag::Severity::Error);
|
||||
else if (Opts.Pedantic)
|
||||
Diags.setExtensionHandlingBehavior(DiagnosticsEngine::Ext_Warn);
|
||||
Diags.setExtensionHandlingBehavior(diag::Severity::Warning);
|
||||
else
|
||||
Diags.setExtensionHandlingBehavior(DiagnosticsEngine::Ext_Ignore);
|
||||
Diags.setExtensionHandlingBehavior(diag::Severity::Ignored);
|
||||
|
||||
SmallVector<diag::kind, 10> _Diags;
|
||||
const IntrusiveRefCntPtr< DiagnosticIDs > DiagIDs =
|
||||
|
|
|
@ -1006,8 +1006,8 @@ static bool HasExtension(const Preprocessor &PP, const IdentifierInfo *II) {
|
|||
|
||||
// If the use of an extension results in an error diagnostic, extensions are
|
||||
// effectively unavailable, so just return false here.
|
||||
if (PP.getDiagnostics().getExtensionHandlingBehavior() ==
|
||||
DiagnosticsEngine::Ext_Error)
|
||||
if (PP.getDiagnostics().getExtensionHandlingBehavior() >=
|
||||
diag::Severity::Error)
|
||||
return false;
|
||||
|
||||
const LangOptions &LangOpts = PP.getLangOpts();
|
||||
|
|
|
@ -328,13 +328,11 @@ static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags,
|
|||
return false;
|
||||
}
|
||||
|
||||
static DiagnosticsEngine::ExtensionHandling
|
||||
isExtHandlingFromDiagsError(DiagnosticsEngine &Diags) {
|
||||
DiagnosticsEngine::ExtensionHandling Ext =
|
||||
Diags.getExtensionHandlingBehavior();
|
||||
if (Ext == DiagnosticsEngine::Ext_Warn && Diags.getWarningsAsErrors())
|
||||
Ext = DiagnosticsEngine::Ext_Error;
|
||||
return Ext;
|
||||
static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags) {
|
||||
diag::Severity Ext = Diags.getExtensionHandlingBehavior();
|
||||
if (Ext == diag::Severity::Warning && Diags.getWarningsAsErrors())
|
||||
return true;
|
||||
return Ext >= diag::Severity::Error;
|
||||
}
|
||||
|
||||
static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags,
|
||||
|
|
Loading…
Reference in New Issue