]> granicus.if.org Git - clang/commitdiff
Allow adding a value to a flag in diagnostics.
authorDiego Novillo <dnovillo@google.com>
Mon, 21 Apr 2014 23:16:03 +0000 (23:16 +0000)
committerDiego Novillo <dnovillo@google.com>
Mon, 21 Apr 2014 23:16:03 +0000 (23:16 +0000)
Summary:
This allows callers of Diags.Report() to append a value to 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]".

Reviewers: rsmith

CC: cfe-commits
Differential Revision: http://reviews.llvm.org/D3441

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206826 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.h
lib/CodeGen/CodeGenAction.cpp
lib/Frontend/TextDiagnosticPrinter.cpp
test/Frontend/optimization-remark.c

index 6082ec8b1f3ad0edeffc66058bf2ec0cbc6e0b60..0a1b5405f5102cd0a7f0b29361abcc881425177e 100644 (file)
@@ -341,6 +341,14 @@ private:
   /// \brief Second string argument for the delayed diagnostic.
   std::string DelayedDiagArg2;
 
+  /// \brief Flag name value.
+  ///
+  /// Some flags accept values. For instance, -Wframe-larger-than or -Rpass.
+  /// When reporting a diagnostic with those flags, it is useful to also
+  /// report the value that actually triggered the flag. The content of this
+  /// string is a value to be emitted after the flag name.
+  std::string FlagNameValue;
+
 public:
   explicit DiagnosticsEngine(
                       const IntrusiveRefCntPtr<DiagnosticIDs> &Diags,
@@ -646,6 +654,11 @@ 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 FlagNameValue 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);
 
@@ -681,6 +694,9 @@ public:
   /// \brief Clear out the current diagnostic.
   void Clear() { CurDiagID = ~0U; }
 
+  /// \brief Return the overridden name for this diagnostic flag.
+  StringRef getFlagNameValue() const { return StringRef(FlagNameValue); }
+
 private:
   /// \brief Report the delayed diagnostic.
   void ReportDelayed();
@@ -1084,15 +1100,22 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
   return DB;
 }
 
-inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
-                                                   unsigned DiagID) {
+inline DiagnosticBuilder
+DiagnosticsEngine::Report(SourceLocation Loc, unsigned DiagID, StringRef Val) {
   assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
   CurDiagLoc = Loc;
   CurDiagID = DiagID;
+  FlagNameValue = Val.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 67859bad2b45874740854f202079fbbff45ec184..5952e671b5b5ef799a4a0e609878a36c9d743ef4 100644 (file)
@@ -404,7 +404,8 @@ void BackendConsumer::OptimizationRemarkHandler(
       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,
+                 D.getPassName())
         << D.getMsg().str();
 
     if (Line == 0)
index 3b5eca6dd9d36ea1c4f21de777d95c1007355fcc..e0516146b1a2da3cafeb5242315bd11a630c482c 100644 (file)
@@ -83,6 +83,9 @@ static void printDiagnosticOptions(raw_ostream &OS,
     if (!Opt.empty()) {
       OS << (Started ? "," : " [")
          << (DiagnosticIDs::isRemark(Info.getID()) ? "-R" : "-W") << Opt;
+      StringRef OptValue = Info.getDiags()->getFlagNameValue();
+      if (!OptValue.empty())
+        OS << "=" << OptValue;
       Started = true;
     }
   }
index 53edeed4f0ef6174c19b18dfc8587c6547ca14cb..03bb8f875ac83739ec9582de6a86de89b9b8f0bc 100644 (file)
@@ -13,7 +13,7 @@ int foo(int x, int y) __attribute__((always_inline));
 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