Hi rsmith,
This allows callers of Diags.Report() to override the name of the flag
associated with the diagnostic. This is useful in cases like the -Rpass
flag, where we want the diagnostic to show the name of the pass that
matched the pattern. Instead of showing "... [-Rpass]", this allows
us to show "... [-Rpass=passname]".
http://reviews.llvm.org/D3441
Files:
include/clang/Basic/Diagnostic.h
lib/CodeGen/CodeGenAction.cpp
lib/Frontend/TextDiagnosticPrinter.cpp
test/Frontend/optimization-remark.c
Index: include/clang/Basic/Diagnostic.h
===================================================================
--- include/clang/Basic/Diagnostic.h
+++ include/clang/Basic/Diagnostic.h
@@ -341,6 +341,14 @@
/// \brief Second string argument for the delayed diagnostic.
std::string DelayedDiagArg2;
+ /// \brief Flag name override.
+ ///
+ /// It is sometimes necessary for diagnostics to rename the flag name
+ /// that triggered them. For example, in the case of the -Rpass family,
+ /// in addition to "Rpass", we need to append the name of the optimization
+ /// pass that matched it.
+ std::string FlagNameOverride;
+
public:
explicit DiagnosticsEngine(
const IntrusiveRefCntPtr<DiagnosticIDs> &Diags,
@@ -646,6 +654,11 @@
/// \param DiagID A member of the @c diag::kind enum.
/// \param Loc Represents the source location associated with the diagnostic,
/// which can be an invalid location if no position information is available.
+ /// \param FlagNameOverride A string that can be used to override the
+ /// name of the flag emitted as part of the diagnostic. If not given,
+ /// the original flag name is used.
+ inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID,
+ StringRef Override);
inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID);
inline DiagnosticBuilder Report(unsigned DiagID);
@@ -681,6 +694,9 @@
/// \brief Clear out the current diagnostic.
void Clear() { CurDiagID = ~0U; }
+ /// \brief Return the overridden name for this diagnostic flag.
+ StringRef getFlagNameOverride() const { return StringRef(FlagNameOverride); }
+
private:
/// \brief Report the delayed diagnostic.
void ReportDelayed();
@@ -1084,15 +1100,23 @@
return DB;
}
-inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
- unsigned DiagID) {
+inline DiagnosticBuilder
+DiagnosticsEngine::Report(SourceLocation Loc, unsigned DiagID,
+ StringRef Override) {
assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
CurDiagLoc = Loc;
CurDiagID = DiagID;
+ FlagNameOverride = Override.str();
return DiagnosticBuilder(this);
}
+
+inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
+ unsigned DiagID) {
+ return Report(Loc, DiagID, "");
+}
+
inline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) {
- return Report(SourceLocation(), DiagID);
+ return Report(SourceLocation(), DiagID, "");
}
//===----------------------------------------------------------------------===//
Index: lib/CodeGen/CodeGenAction.cpp
===================================================================
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -404,7 +404,8 @@
Loc = SourceMgr.translateFileLineCol(FileMgr.getFile(Filename), Line,
Column);
}
- Diags.Report(Loc, diag::remark_fe_backend_optimization_remark)
+ Diags.Report(Loc, diag::remark_fe_backend_optimization_remark,
+ (StringRef("-Rpass=") + D.getPassName()).str())
<< D.getMsg().str();
if (Line == 0)
Index: lib/Frontend/TextDiagnosticPrinter.cpp
===================================================================
--- lib/Frontend/TextDiagnosticPrinter.cpp
+++ lib/Frontend/TextDiagnosticPrinter.cpp
@@ -79,10 +79,14 @@
Started = true;
}
+ StringRef OptOverride = Info.getDiags()->getFlagNameOverride();
StringRef Opt = DiagnosticIDs::getWarningOptionForDiag(Info.getID());
if (!Opt.empty()) {
- OS << (Started ? "," : " [")
- << (DiagnosticIDs::isRemark(Info.getID()) ? "-R" : "-W") << Opt;
+ OS << (Started ? "," : " [");
+ if (OptOverride.empty())
+ OS << (DiagnosticIDs::isRemark(Info.getID()) ? "-R" : "-W") << Opt;
+ else
+ OS << OptOverride;
Started = true;
}
}
Index: test/Frontend/optimization-remark.c
===================================================================
--- test/Frontend/optimization-remark.c
+++ test/Frontend/optimization-remark.c
@@ -13,7 +13,7 @@
int foo(int x, int y) { return x + y; }
int bar(int j) { return foo(j, j - 2); }
-// INLINE: remark: foo inlined into bar [-Rpass]
+// INLINE: remark: foo inlined into bar [-Rpass=inline]
// INLINE-NO-LOC: {{^remark: foo inlined into bar}}
// INLINE-NO-LOC: note: use -gline-tables-only -gcolumn-info to track
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits