r246526 - Don't use fprintf to emit this diagnostic!

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 31 19:35:58 PDT 2015


Author: rsmith
Date: Mon Aug 31 21:35:58 2015
New Revision: 246526

URL: http://llvm.org/viewvc/llvm-project?rev=246526&view=rev
Log:
Don't use fprintf to emit this diagnostic!

Added:
    cfe/trunk/test/PCH/datetime.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=246526&r1=246525&r2=246526&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Mon Aug 31 21:35:58 2015
@@ -111,6 +111,10 @@ def note_module_odr_violation_different_
 def err_module_odr_violation_different_instantiations : Error<
   "instantiation of %q0 is different in different modules">;
 
+def warn_module_uses_date_time : Warning<
+  "%select{precompiled header|module}0 uses __DATE__ or __TIME__">,
+  InGroup<DiagGroup<"pch-date-time">>;
+
 } // let CategoryName
 } // let Component
 

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=246526&r1=246525&r2=246526&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon Aug 31 21:35:58 2015
@@ -43,6 +43,7 @@
 #include "clang/Sema/IdentifierResolver.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Serialization/ASTReader.h"
+#include "clang/Serialization/SerializationDiagnostic.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/Hashing.h"
@@ -2054,10 +2055,9 @@ void ASTWriter::WritePreprocessor(const
   Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3);
 
   // If the AST file contains __DATE__ or __TIME__ emit a warning about this.
-  // FIXME: use diagnostics subsystem for localization etc.
+  // FIXME: Include a location for the use, and say which one was used.
   if (PP.SawDateOrTime())
-    fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n");
-
+    PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule;
 
   // Loop over all the macro directives that are live at the end of the file,
   // emitting each to the PP section.

Added: cfe/trunk/test/PCH/datetime.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/datetime.c?rev=246526&view=auto
==============================================================================
--- cfe/trunk/test/PCH/datetime.c (added)
+++ cfe/trunk/test/PCH/datetime.c Mon Aug 31 21:35:58 2015
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -x c-header %s -emit-pch -o %t 2>&1 | FileCheck %s
+// CHECK: precompiled header uses __DATE__ or __TIME__
+const char *p = __DATE__;




More information about the cfe-commits mailing list