Skip to content

Commit b344224

Browse files
author
Diego Novillo
committedApr 22, 2014
Use a manipulator to add a value to the current diagnostic flag.
Summary: This addresses the feedback to http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20140421/103598.html Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D3453 llvm-svn: 206920
1 parent 71a2634 commit b344224

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed
 

Diff for: ‎clang/include/clang/Basic/Diagnostic.h

+25-15
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,6 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
654654
/// \param DiagID A member of the @c diag::kind enum.
655655
/// \param Loc Represents the source location associated with the diagnostic,
656656
/// which can be an invalid location if no position information is available.
657-
/// \param Val A string that represents the value that triggered
658-
/// this diagnostic. If given, this value will be emitted as "=value"
659-
/// after the flag name.
660-
inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID,
661-
StringRef Val);
662657
inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID);
663658
inline DiagnosticBuilder Report(unsigned DiagID);
664659

@@ -694,9 +689,12 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
694689
/// \brief Clear out the current diagnostic.
695690
void Clear() { CurDiagID = ~0U; }
696691

697-
/// \brief Return the overridden name for this diagnostic flag.
692+
/// \brief Return the value associated to this diagnostic flag.
698693
StringRef getFlagNameValue() const { return StringRef(FlagNameValue); }
699694

695+
/// \brief Set the value associated to this diagnostic flag.
696+
void setFlagNameValue(StringRef V) { FlagNameValue = V; }
697+
700698
private:
701699
/// \brief Report the delayed diagnostic.
702700
void ReportDelayed();
@@ -1010,8 +1008,25 @@ class DiagnosticBuilder {
10101008
bool hasMaxFixItHints() const {
10111009
return NumFixits == DiagnosticsEngine::MaxFixItHints;
10121010
}
1011+
1012+
void addFlagValue(StringRef V) const { DiagObj->setFlagNameValue(V); }
1013+
};
1014+
1015+
struct AddFlagValue {
1016+
explicit AddFlagValue(StringRef V) : Val(V) {}
1017+
StringRef Val;
10131018
};
10141019

1020+
/// \brief Register a value for the flag in the current diagnostic. This
1021+
/// value will be shown as the suffix "=value" after the flag name. It is
1022+
/// useful in cases where the diagnostic flag accepts values (e.g.,
1023+
/// -Rpass or -Wframe-larger-than).
1024+
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1025+
const AddFlagValue V) {
1026+
DB.addFlagValue(V.Val);
1027+
return DB;
1028+
}
1029+
10151030
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
10161031
StringRef S) {
10171032
DB.AddString(S);
@@ -1100,22 +1115,17 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
11001115
return DB;
11011116
}
11021117

1103-
inline DiagnosticBuilder
1104-
DiagnosticsEngine::Report(SourceLocation Loc, unsigned DiagID, StringRef Val) {
1118+
inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
1119+
unsigned DiagID) {
11051120
assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
11061121
CurDiagLoc = Loc;
11071122
CurDiagID = DiagID;
1108-
FlagNameValue = Val.str();
1123+
FlagNameValue.clear();
11091124
return DiagnosticBuilder(this);
11101125
}
11111126

1112-
inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
1113-
unsigned DiagID) {
1114-
return Report(Loc, DiagID, "");
1115-
}
1116-
11171127
inline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) {
1118-
return Report(SourceLocation(), DiagID, "");
1128+
return Report(SourceLocation(), DiagID);
11191129
}
11201130

11211131
//===----------------------------------------------------------------------===//

Diff for: ‎clang/lib/CodeGen/CodeGenAction.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,8 @@ void BackendConsumer::OptimizationRemarkHandler(
404404
Loc = SourceMgr.translateFileLineCol(FileMgr.getFile(Filename), Line,
405405
Column);
406406
}
407-
Diags.Report(Loc, diag::remark_fe_backend_optimization_remark,
408-
D.getPassName())
409-
<< D.getMsg().str();
407+
Diags.Report(Loc, diag::remark_fe_backend_optimization_remark)
408+
<< AddFlagValue(D.getPassName()) << D.getMsg().str();
410409

411410
if (Line == 0)
412411
// If we could not extract a source location for the diagnostic,

0 commit comments

Comments
 (0)
Please sign in to comment.