[cfe-commits] r170636 - in /cfe/trunk: include/clang/AST/ASTImporter.h include/clang/Basic/Diagnostic.h include/clang/Basic/DiagnosticASTKinds.td lib/AST/ASTImporter.cpp lib/Basic/Diagnostic.cpp lib/Driver/Driver.cpp test/ASTMerge/Inputs/class1.cpp test/ASTMerge/Inputs/class2.cpp test/ASTMerge/class.cpp test/Misc/warning-flags.c

Richard Smith richard-llvm at metafoo.co.uk
Wed Dec 19 18:22:16 PST 2012


Author: rsmith
Date: Wed Dec 19 20:22:15 2012
New Revision: 170636

URL: http://llvm.org/viewvc/llvm-project?rev=170636&view=rev
Log:
Fix code that attempted to produce a diagnostic with one DiagnosticEngine, then
produce a note for that diagnostic either with a different DiagnosticEngine or
after calling DiagnosticEngine::Reset(). That didn't make any sense, and did the
wrong thing if the original diagnostic was suppressed.

Modified:
    cfe/trunk/include/clang/AST/ASTImporter.h
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/lib/Basic/Diagnostic.cpp
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/test/ASTMerge/Inputs/class1.cpp
    cfe/trunk/test/ASTMerge/Inputs/class2.cpp
    cfe/trunk/test/ASTMerge/class.cpp
    cfe/trunk/test/Misc/warning-flags.c

Modified: cfe/trunk/include/clang/AST/ASTImporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTImporter.h?rev=170636&r1=170635&r2=170636&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTImporter.h (original)
+++ cfe/trunk/include/clang/AST/ASTImporter.h Wed Dec 19 20:22:15 2012
@@ -48,6 +48,9 @@
 
     /// \brief Whether to perform a minimal import.
     bool Minimal;
+
+    /// \brief Whether the last diagnostic came from the "from" context.
+    bool LastDiagFromFrom;
     
     /// \brief Mapping from the already-imported types in the "from" context
     /// to the corresponding types in the "to" context.

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=170636&r1=170635&r2=170636&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Dec 19 20:22:15 2012
@@ -607,6 +607,12 @@
     ArgToStringCookie = Cookie;
   }
 
+  /// \brief Note that the prior diagnostic was emitted by some other
+  /// \c DiagnosticsEngine, and we may be attaching a note to that diagnostic.
+  void notePriorDiagnosticFrom(const DiagnosticsEngine &Other) {
+    LastDiagLevel = Other.LastDiagLevel;
+  }
+
   /// \brief Reset the state of the diagnostic object to its initial 
   /// configuration.
   void Reset();

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=170636&r1=170635&r2=170636&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Wed Dec 19 20:22:15 2012
@@ -135,7 +135,8 @@
   "external function %0 declared with incompatible types in different "
   "translation units (%1 vs. %2)">;
 def warn_odr_tag_type_inconsistent : Warning<
-  "type %0 has incompatible definitions in different translation units">;
+  "type %0 has incompatible definitions in different translation units">,
+  InGroup<DiagGroup<"odr">>;
 def note_odr_tag_kind_here: Note<
   "%0 is a %select{struct|interface|union|class|enum}1 here">;
 def note_odr_field : Note<"field %0 has type %1 here">;

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=170636&r1=170635&r2=170636&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Dec 19 20:22:15 2012
@@ -206,12 +206,16 @@
     /// \brief Whether to complain about failures.
     bool Complain;
 
+    /// \brief \c true if the last diagnostic came from C2.
+    bool LastDiagFromC2;
+
     StructuralEquivalenceContext(ASTContext &C1, ASTContext &C2,
                llvm::DenseSet<std::pair<Decl *, Decl *> > &NonEquivalentDecls,
                                  bool StrictTypeSpelling = false,
                                  bool Complain = true)
       : C1(C1), C2(C2), NonEquivalentDecls(NonEquivalentDecls),
-        StrictTypeSpelling(StrictTypeSpelling), Complain(Complain) { }
+        StrictTypeSpelling(StrictTypeSpelling), Complain(Complain),
+        LastDiagFromC2(false) {}
 
     /// \brief Determine whether the two declarations are structurally
     /// equivalent.
@@ -229,11 +233,17 @@
   public:
     DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID) {
       assert(Complain && "Not allowed to complain");
+      if (LastDiagFromC2)
+        C1.getDiagnostics().notePriorDiagnosticFrom(C2.getDiagnostics());
+      LastDiagFromC2 = false;
       return C1.getDiagnostics().Report(Loc, DiagID);
     }
 
     DiagnosticBuilder Diag2(SourceLocation Loc, unsigned DiagID) {
       assert(Complain && "Not allowed to complain");
+      if (!LastDiagFromC2)
+        C2.getDiagnostics().notePriorDiagnosticFrom(C1.getDiagnostics());
+      LastDiagFromC2 = true;
       return C2.getDiagnostics().Report(Loc, DiagID);
     }
   };
@@ -4319,7 +4329,7 @@
                          bool MinimalImport)
   : ToContext(ToContext), FromContext(FromContext),
     ToFileManager(ToFileManager), FromFileManager(FromFileManager),
-    Minimal(MinimalImport) 
+    Minimal(MinimalImport), LastDiagFromFrom(false)
 {
   ImportedDecls[FromContext.getTranslationUnitDecl()]
     = ToContext.getTranslationUnitDecl();
@@ -4822,10 +4832,18 @@
 }
 
 DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) {
+  if (LastDiagFromFrom)
+    ToContext.getDiagnostics().notePriorDiagnosticFrom(
+      FromContext.getDiagnostics());
+  LastDiagFromFrom = false;
   return ToContext.getDiagnostics().Report(Loc, DiagID);
 }
 
 DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) {
+  if (!LastDiagFromFrom)
+    FromContext.getDiagnostics().notePriorDiagnosticFrom(
+      ToContext.getDiagnostics());
+  LastDiagFromFrom = true;
   return FromContext.getDiagnostics().Report(Loc, DiagID);
 }
 

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=170636&r1=170635&r2=170636&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Dec 19 20:22:15 2012
@@ -108,11 +108,7 @@
   TrapNumUnrecoverableErrorsOccurred = 0;
   
   CurDiagID = ~0U;
-  // Set LastDiagLevel to an "unset" state. If we set it to 'Ignored', notes
-  // using a DiagnosticsEngine associated to a translation unit that follow
-  // diagnostics from a DiagnosticsEngine associated to anoter t.u. will not be
-  // displayed.
-  LastDiagLevel = (DiagnosticIDs::Level)-1;
+  LastDiagLevel = DiagnosticIDs::Ignored;
   DelayedDiagID = 0;
 
   // Clear state related to #pragma diagnostic.

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=170636&r1=170635&r2=170636&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Dec 19 20:22:15 2012
@@ -366,9 +366,12 @@
     C.PrintDiagnosticJob(OS, C.getJobs());
   OS.flush();
 
-  // Clear stale state and suppress tool output.
+  // Keep track of whether we produce any errors while trying to produce
+  // preprocessed sources.
+  DiagnosticErrorTrap Trap(Diags);
+
+  // Suppress tool output.
   C.initCompilationForDiagnostics();
-  Diags.Reset();
 
   // Construct the list of inputs.
   InputList Inputs;
@@ -430,7 +433,7 @@
   BuildJobs(C);
 
   // If there were errors building the compilation, quit now.
-  if (Diags.hasErrorOccurred()) {
+  if (Trap.hasErrorOccurred()) {
     Diag(clang::diag::note_drv_command_failed_diag_msg)
       << "Error generating preprocessed source(s).";
     return;

Modified: cfe/trunk/test/ASTMerge/Inputs/class1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/class1.cpp?rev=170636&r1=170635&r2=170636&view=diff
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/class1.cpp (original)
+++ cfe/trunk/test/ASTMerge/Inputs/class1.cpp Wed Dec 19 20:22:15 2012
@@ -13,3 +13,7 @@
   C &operator=(C&);
   ~C();
 };
+
+enum E {
+  b = 1
+};

Modified: cfe/trunk/test/ASTMerge/Inputs/class2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/class2.cpp?rev=170636&r1=170635&r2=170636&view=diff
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/class2.cpp (original)
+++ cfe/trunk/test/ASTMerge/Inputs/class2.cpp Wed Dec 19 20:22:15 2012
@@ -7,3 +7,7 @@
   int foo();
 };
 
+enum E {
+  a = 0,
+  b = 1
+};

Modified: cfe/trunk/test/ASTMerge/class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/class.cpp?rev=170636&r1=170635&r2=170636&view=diff
==============================================================================
--- cfe/trunk/test/ASTMerge/class.cpp (original)
+++ cfe/trunk/test/ASTMerge/class.cpp Wed Dec 19 20:22:15 2012
@@ -1,9 +1,14 @@
 // RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/class1.cpp
 // RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/class2.cpp
 // RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 -Wno-odr | count 0
 
 // CHECK: class1.cpp:5:8: warning: type 'B' has incompatible definitions in different translation units
 // CHECK: class1.cpp:6:9: note: field 'y' has type 'float' here
 // CHECK: class2.cpp:6:7: note: field 'y' has type 'int' here
 
 // FIXME: we should also complain about mismatched types on the method
+
+// CHECK: class1.cpp:17:6: warning: type 'E' has incompatible definitions in different translation units
+// CHECK: class1.cpp:18:3: note: enumerator 'b' with value 1 here
+// CHECK: class2.cpp:11:3: note: enumerator 'a' with value 0 here

Modified: cfe/trunk/test/Misc/warning-flags.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/warning-flags.c?rev=170636&r1=170635&r2=170636&view=diff
==============================================================================
--- cfe/trunk/test/Misc/warning-flags.c (original)
+++ cfe/trunk/test/Misc/warning-flags.c Wed Dec 19 20:22:15 2012
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (148):
+CHECK: Warnings without flags (147):
 CHECK-NEXT:   ext_delete_void_ptr_operand
 CHECK-NEXT:   ext_enum_friend
 CHECK-NEXT:   ext_expected_semi_decl_list
@@ -106,7 +106,6 @@
 CHECK-NEXT:   warn_objc_property_copy_missing_on_block
 CHECK-NEXT:   warn_objc_protocol_qualifier_missing_id
 CHECK-NEXT:   warn_octal_escape_too_large
-CHECK-NEXT:   warn_odr_tag_type_inconsistent
 CHECK-NEXT:   warn_on_superclass_use
 CHECK-NEXT:   warn_param_default_argument_redefinition
 CHECK-NEXT:   warn_partial_specs_not_deducible





More information about the cfe-commits mailing list