r335807 - [modules] Do not serialize / deserialize pending new/delete mismatch

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 27 18:57:05 PDT 2018


Author: rsmith
Date: Wed Jun 27 18:57:04 2018
New Revision: 335807

URL: http://llvm.org/viewvc/llvm-project?rev=335807&view=rev
Log:
[modules] Do not serialize / deserialize pending new/delete mismatch
checks across module boundaries. This was causing us to load constructor
definitions for all consumers of a module with a pending check.

(In one case we saw ~7% of total frontend time spent loading
constructors for this check.)

Added:
    cfe/trunk/test/Modules/new-delete.cpp
Modified:
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=335807&r1=335806&r2=335807&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Wed Jun 27 18:57:04 2018
@@ -1010,11 +1010,6 @@ void Sema::ActOnEndOfTranslationUnit() {
     // Warnings emitted in ActOnEndOfTranslationUnit() should be emitted for
     // modules when they are built, not every time they are used.
     emitAndClearUnusedLocalTypedefWarnings();
-
-    // Modules don't need any of the checking below.
-    if (!PP.isIncrementalProcessingEnabled())
-      TUScope = nullptr;
-    return;
   }
 
   // C99 6.9.2p2:
@@ -1032,8 +1027,7 @@ void Sema::ActOnEndOfTranslationUnit() {
   for (TentativeDefinitionsType::iterator
             T = TentativeDefinitions.begin(ExternalSource),
          TEnd = TentativeDefinitions.end();
-       T != TEnd; ++T)
-  {
+       T != TEnd; ++T) {
     VarDecl *VD = (*T)->getActingDefinition();
 
     // If the tentative definition was completed, getActingDefinition() returns
@@ -1060,12 +1054,13 @@ void Sema::ActOnEndOfTranslationUnit() {
     // Notify the consumer that we've completed a tentative definition.
     if (!VD->isInvalidDecl())
       Consumer.CompleteTentativeDefinition(VD);
-
   }
 
   // If there were errors, disable 'unused' warnings since they will mostly be
-  // noise.
-  if (!Diags.hasErrorOccurred()) {
+  // noise. Don't warn for a use from a module: either we should warn on all
+  // file-scope declarations in modules or not at all, but whether the
+  // declaration is used is immaterial.
+  if (!Diags.hasErrorOccurred() && TUKind != TU_Module) {
     // Output warning for unused file scoped decls.
     for (UnusedFileScopedDeclsType::iterator
            I = UnusedFileScopedDecls.begin(ExternalSource),
@@ -1133,6 +1128,8 @@ void Sema::ActOnEndOfTranslationUnit() {
   }
 
   if (!Diags.isIgnored(diag::warn_unused_private_field, SourceLocation())) {
+    // FIXME: Load additional unused private field candidates from the external
+    // source.
     RecordCompleteMap RecordsComplete;
     RecordCompleteMap MNCComplete;
     for (NamedDeclSetType::iterator I = UnusedPrivateFields.begin(),

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=335807&r1=335806&r2=335807&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed Jun 27 18:57:04 2018
@@ -4769,13 +4769,15 @@ ASTFileSignature ASTWriter::WriteASTCore
   // analyze later in AST.
   RecordData DeleteExprsToAnalyze;
 
-  for (const auto &DeleteExprsInfo :
-       SemaRef.getMismatchingDeleteExpressions()) {
-    AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze);
-    DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size());
-    for (const auto &DeleteLoc : DeleteExprsInfo.second) {
-      AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze);
-      DeleteExprsToAnalyze.push_back(DeleteLoc.second);
+  if (!isModule) {
+    for (const auto &DeleteExprsInfo :
+         SemaRef.getMismatchingDeleteExpressions()) {
+      AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze);
+      DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size());
+      for (const auto &DeleteLoc : DeleteExprsInfo.second) {
+        AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze);
+        DeleteExprsToAnalyze.push_back(DeleteLoc.second);
+      }
     }
   }
 

Added: cfe/trunk/test/Modules/new-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/new-delete.cpp?rev=335807&view=auto
==============================================================================
--- cfe/trunk/test/Modules/new-delete.cpp (added)
+++ cfe/trunk/test/Modules/new-delete.cpp Wed Jun 27 18:57:04 2018
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fmodules -verify %s
+// expected-no-diagnostics
+
+#pragma clang module build M
+module M {}
+#pragma clang module contents
+#pragma clang module begin M
+struct A {
+  A();
+  ~A() { delete p; } // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'}}
+  int *p;
+};
+inline A::A() : p(new int[32]) {} // expected-note {{allocated}}
+struct B {
+  B();
+  ~B() { delete p; }
+  int *p;
+};
+#pragma clang module end
+#pragma clang module endbuild
+
+#pragma clang module import M
+B::B() : p(new int[32]) {}




More information about the cfe-commits mailing list