[cfe-commits] r140747 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Frontend/Warnings.cpp
Daniel Dunbar
daniel at zuster.org
Wed Sep 28 17:53:47 PDT 2011
Author: ddunbar
Date: Wed Sep 28 19:53:47 2011
New Revision: 140747
URL: http://llvm.org/viewvc/llvm-project?rev=140747&view=rev
Log:
Basic/Diagnostic: Factor out
DiagnosticsEngine::setDiagnosticGroup{ErrorAsFatal,WarningAsError} methods which
more accurately model the correct API -- no internal change to the diagnostics
engine yet though.
- Also, stop honoring -Werror=everything (etc.) as a valid (but oddly behaved) option.
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/lib/Frontend/Warnings.cpp
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=140747&r1=140746&r2=140747&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Sep 28 19:53:47 2011
@@ -452,6 +452,16 @@
return Diags->setDiagnosticGroupMapping(Group, Map, Loc, *this);
}
+ /// \brief Set the warning-as-error flag for the given diagnostic group.
+ ///
+ /// \returns True if the given group is unknown, false otherwise.
+ bool setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled);
+
+ /// \brief Set the error-as-fatal flag for the given diagnostic group.
+ ///
+ /// \returns True if the given group is unknown, false otherwise.
+ bool setDiagnosticGroupErrorAsFatal(StringRef Group, bool Enabled);
+
bool hasErrorOccurred() const { return ErrorOccurred; }
bool hasFatalErrorOccurred() const { return FatalErrorOccurred; }
Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=140747&r1=140746&r2=140747&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Sep 28 19:53:47 2011
@@ -220,6 +220,18 @@
FullSourceLoc(Loc, *SourceMgr)));
}
+bool DiagnosticsEngine::setDiagnosticGroupWarningAsError(StringRef Group,
+ bool Enabled) {
+ diag::Mapping Map = Enabled ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR;
+ return setDiagnosticGroupMapping(Group, Map);
+}
+
+bool DiagnosticsEngine::setDiagnosticGroupErrorAsFatal(StringRef Group,
+ bool Enabled) {
+ diag::Mapping Map = Enabled ? diag::MAP_FATAL : diag::MAP_ERROR_NO_WFATAL;
+ return setDiagnosticGroupMapping(Group, Map);
+}
+
void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) {
assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
Modified: cfe/trunk/lib/Frontend/Warnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Warnings.cpp?rev=140747&r1=140746&r2=140747&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/Warnings.cpp (original)
+++ cfe/trunk/lib/Frontend/Warnings.cpp Wed Sep 28 19:53:47 2011
@@ -75,6 +75,13 @@
Diags.setSuppressSystemWarnings(!isPositive);
continue;
}
+
+ // -Weverything is a special case as well. It implicitly enables all
+ // warnings, including ones not explicitly in a warning group.
+ if (Opt == "everything") {
+ Diags.setEnableAllWarnings(true);
+ continue;
+ }
// -Werror/-Wno-error is a special case, not controlled by the option table.
// It also has the "specifier" form of -Werror=foo and -Werror-foo.
@@ -94,15 +101,12 @@
continue;
}
- // -Werror=foo maps foo to Error, -Wno-error=foo maps it to Warning.
- Mapping = isPositive ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR;
- Opt = Specifier;
- }
-
- // -Weverything is a special case as well. It implicitly enables all
- // warnings, including ones not explicitly in a warning group.
- if (Opt == "everything") {
- Diags.setEnableAllWarnings(true);
+ // Set the warning as error flag for this specifier.
+ if (Diags.setDiagnosticGroupWarningAsError(Specifier, isPositive)) {
+ Diags.Report(isPositive ? diag::warn_unknown_warning_option :
+ diag::warn_unknown_negative_warning_option)
+ << ("-W" + Opt.str());
+ }
continue;
}
@@ -123,15 +127,19 @@
continue;
}
- // -Wfatal-errors=foo maps foo to Fatal, -Wno-fatal-errors=foo
- // maps it to Error.
- Mapping = isPositive ? diag::MAP_FATAL : diag::MAP_ERROR_NO_WFATAL;
- Opt = Specifier;
+ // Set the error as fatal flag for this specifier.
+ if (Diags.setDiagnosticGroupErrorAsFatal(Specifier, isPositive)) {
+ Diags.Report(isPositive ? diag::warn_unknown_warning_option :
+ diag::warn_unknown_negative_warning_option)
+ << ("-W" + Opt.str());
+ }
+ continue;
}
- if (Diags.setDiagnosticGroupMapping(Opt, Mapping))
+ if (Diags.setDiagnosticGroupMapping(Opt, Mapping)) {
Diags.Report(isPositive ? diag::warn_unknown_warning_option :
diag::warn_unknown_negative_warning_option)
<< ("-W" + Opt.str());
+ }
}
}
More information about the cfe-commits
mailing list