r206920 - Use a manipulator to add a value to the current diagnostic flag.

Diego Novillo dnovillo at google.com
Tue Apr 22 12:56:49 PDT 2014


Author: dnovillo
Date: Tue Apr 22 14:56:49 2014
New Revision: 206920

URL: http://llvm.org/viewvc/llvm-project?rev=206920&view=rev
Log:
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

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/CodeGen/CodeGenAction.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=206920&r1=206919&r2=206920&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Tue Apr 22 14:56:49 2014
@@ -654,11 +654,6 @@ public:
   /// \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 Val A string that represents the value that triggered
-  /// this diagnostic. If given, this value will be emitted as "=value"
-  /// after the flag name.
-  inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID,
-                                  StringRef Val);
   inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID);
   inline DiagnosticBuilder Report(unsigned DiagID);
 
@@ -694,9 +689,12 @@ public:
   /// \brief Clear out the current diagnostic.
   void Clear() { CurDiagID = ~0U; }
 
-  /// \brief Return the overridden name for this diagnostic flag.
+  /// \brief Return the value associated to this diagnostic flag.
   StringRef getFlagNameValue() const { return StringRef(FlagNameValue); }
 
+  /// \brief Set the value associated to this diagnostic flag.
+  void setFlagNameValue(StringRef V) { FlagNameValue = V; }
+
 private:
   /// \brief Report the delayed diagnostic.
   void ReportDelayed();
@@ -1010,8 +1008,25 @@ public:
   bool hasMaxFixItHints() const {
     return NumFixits == DiagnosticsEngine::MaxFixItHints;
   }
+
+  void addFlagValue(StringRef V) const { DiagObj->setFlagNameValue(V); }
+};
+
+struct AddFlagValue {
+  explicit AddFlagValue(StringRef V) : Val(V) {}
+  StringRef Val;
 };
 
+/// \brief Register a value for the flag in the current diagnostic. This
+/// value will be shown as the suffix "=value" after the flag name. It is
+/// useful in cases where the diagnostic flag accepts values (e.g.,
+/// -Rpass or -Wframe-larger-than).
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+                                           const AddFlagValue V) {
+  DB.addFlagValue(V.Val);
+  return DB;
+}
+
 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                            StringRef S) {
   DB.AddString(S);
@@ -1100,22 +1115,17 @@ inline const DiagnosticBuilder &operator
   return DB;
 }
 
-inline DiagnosticBuilder
-DiagnosticsEngine::Report(SourceLocation Loc, unsigned DiagID, StringRef Val) {
+inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
+                                                   unsigned DiagID) {
   assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
   CurDiagLoc = Loc;
   CurDiagID = DiagID;
-  FlagNameValue = Val.str();
+  FlagNameValue.clear();
   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);
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=206920&r1=206919&r2=206920&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Tue Apr 22 14:56:49 2014
@@ -404,9 +404,8 @@ void BackendConsumer::OptimizationRemark
       Loc = SourceMgr.translateFileLineCol(FileMgr.getFile(Filename), Line,
                                            Column);
     }
-    Diags.Report(Loc, diag::remark_fe_backend_optimization_remark,
-                 D.getPassName())
-        << D.getMsg().str();
+    Diags.Report(Loc, diag::remark_fe_backend_optimization_remark)
+        << AddFlagValue(D.getPassName()) << D.getMsg().str();
 
     if (Line == 0)
       // If we could not extract a source location for the diagnostic,





More information about the cfe-commits mailing list