[PATCH] D28845: Prototype of modules codegen

2017-01-28 Thread David Blaikie via Phabricator via cfe-commits
dblaikie marked 6 inline comments as done.
dblaikie added a comment.

Addressed CR feedback




Comment at: lib/AST/ExternalASTSource.cpp:33
+ExternalASTSource::hasExternalDefinitions(unsigned ID) {
+  return EK_ReplyHazy;
+}

rsmith wrote:
> You should add support for this function to 
> `clang::MultiplexExternalSemaSource` too.
Done - though is there any test coverage I should add? Not sure exactly 
when/where/how this is used.

Also only made a rough guess at what the right behavior is here. It could be a 
bit more obvious if I made "hasExternalDefinitions" return Optional - 
then when we find an ExternalASTSource that owns the ID (are the IDs unique 
across the MultiplexExternalSemaSource? I assume they have to be, but thought 
they'd only be valid within a single Module... guess I'm confused in a few ways 
- certainly haven't thought about it in great detail) we'd know to stop asking 
other sources. Probably not worth it unless there's a lot of sources?



Comment at: lib/Serialization/ASTWriterDecl.cpp:2215-2219
+  if (isRequiredDecl(D, Context, WritingModule, false))
 EagerlyDeserializedDecls.push_back(ID);
+  else if (Context.getLangOpts().ModularCodegen && WritingModule &&
+   isRequiredDecl(D, Context, true, true))
+ModularCodegenDecls.push_back(ID);

rsmith wrote:
> I suspect we'll want to seriously prune back the contents of 
> `EagerlyDeserializedDecls` for the modular codegen case at some point, but we 
> don't need to do that in this change.
Right - I was wondering if we'd end up with anything in 
EagerlyDeserializedDecls when modular codegen is fully implemented. (if that's 
the case - we could have only one list, and a 'bit' to say whether it's modular 
codegen decls or EagerlyDeserializedDecls, if these records/blobs/whatnot are 
expensive to have two of rather than one - but I don't think that's the case so 
probably more readable/self-documenting to use two lists as we are)


https://reviews.llvm.org/D28845



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28845: Prototype of modules codegen

2017-01-28 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 86200.
dblaikie added a comment.

- Address code review feedback
- Formatting


https://reviews.llvm.org/D28845

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/ExternalASTSource.h
  include/clang/Basic/LangOptions.def
  include/clang/Basic/Module.h
  include/clang/Driver/CC1Options.td
  include/clang/Sema/MultiplexExternalSemaSource.h
  include/clang/Serialization/ASTBitCodes.h
  include/clang/Serialization/ASTReader.h
  include/clang/Serialization/ASTWriter.h
  lib/AST/ASTContext.cpp
  lib/AST/ExternalASTSource.cpp
  lib/Basic/Module.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/ModuleMap.cpp
  lib/Sema/MultiplexExternalSemaSource.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/Modules/Inputs/codegen/bar.h
  test/Modules/Inputs/codegen/bar.modulemap
  test/Modules/Inputs/codegen/foo.h
  test/Modules/Inputs/codegen/foo.modulemap
  test/Modules/Inputs/codegen/use.cpp
  test/Modules/codegen.test

Index: test/Modules/codegen.test
===
--- /dev/null
+++ test/Modules/codegen.test
@@ -0,0 +1,64 @@
+RUN: rm -rf %t
+
+RUN: %clang_cc1 -fmodules-codegen -x c++ -fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen/foo.modulemap -o %t/foo.pcm
+RUN: %clang_cc1 -fmodules-codegen -x c++ -fmodules -emit-module -fmodule-name=bar %S/Inputs/codegen/bar.modulemap -o %t/bar.pcm -fmodule-file=%t/foo.pcm
+
+RUN: %clang_cc1 -emit-llvm %t/foo.pcm -o - | FileCheck --check-prefix=FOO %s
+RUN: %clang_cc1 -emit-llvm %t/bar.pcm -o - -fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-prefix=BAR %s
+RUN: %clang_cc1 -fmodules -fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen/use.cpp -emit-llvm -o - | FileCheck --check-prefix=USE-CMN --check-prefix=USE %s
+
+RUN: %clang_cc1 -O2 -disable-llvm-passes -emit-llvm %t/foo.pcm -o - | FileCheck --check-prefix=FOO %s
+RUN: %clang_cc1 -O2 -disable-llvm-passes -emit-llvm %t/bar.pcm -o - -fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-prefix=BAR-OPT %s
+RUN: %clang_cc1 -O2 -disable-llvm-passes -fmodules -fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen/use.cpp -emit-llvm -o - | FileCheck --check-prefix=USE-CMN --check-prefix=USE-OPT %s
+
+FOO-NOT: comdat
+FOO: $_Z3foov = comdat any
+FOO: $_Z4foo2v = comdat any
+FOO: $_ZZ3foovE1i = comdat any
+FOO: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat
+FOO-NOT: {{comdat|define|declare}}
+FOO: define void @_Z7foo_extv()
+FOO-NOT: {{define|declare}}
+FOO: define weak_odr void @_Z3foov() #{{[0-9]+}} comdat
+FOO-NOT: {{define|declare}}
+FOO: declare void @_Z2f1Ri(i32*
+FOO-NOT: {{define|declare}}
+
+FIXME: this internal function should be weak_odr, comdat, and with a new mangling
+FOO: define internal void @_ZL2f2v() #{{[0-9]+}}
+FOO-NOT: {{define|declare}}
+
+FOO: define weak_odr void @_Z4foo2v() #{{[0-9]+}} comdat
+FOO-NOT: {{define|declare}}
+
+
+BAR-CMN-NOT: comdat
+BAR-CMN: $_Z3barv = comdat any
+BAR-OPT: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat
+BAR-CMN-NOT: {{comdat|define|declare}}
+BAR-CMN: define weak_odr void @_Z3barv() #{{[0-9]+}} comdat
+BAR-CMN-NOT: {{define|declare}}
+BAR: declare void @_Z3foov()
+Include all the available_externally definitions required for bar (foo -> f2)
+BAR-OPT: define available_externally void @_Z3foov()
+BAR-CMN-NOT: {{define|declare}}
+BAR-OPT: declare void @_Z2f1Ri(i32*
+BAR-OPT-NOT: {{define|declare}}
+BAR-OPT: define available_externally void @_ZL2f2v()
+BAR-OPT-NOT: {{define|declare}}
+
+
+USE-OPT: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat
+USE-CMN-NOT: {{comdat|define|declare}}
+USE-CMN: define i32 @main()
+USE-CMN-NOT: {{define|declare}}
+USE: declare void @_Z3barv()
+Include all the available_externally definitions required for main (bar -> foo -> f2)
+USE-OPT: define available_externally void @_Z3barv()
+USE-CMN-NOT: {{define|declare}}
+USE-OPT: define available_externally void @_Z3foov()
+USE-OPT-NOT: {{define|declare}}
+USE-OPT: declare void @_Z2f1Ri(i32*
+USE-OPT-NOT: {{define|declare}}
+USE-OPT: define available_externally void @_ZL2f2v()
+USE-OPT-NOT: {{define|declare}}
Index: test/Modules/Inputs/codegen/use.cpp
===
--- /dev/null
+++ test/Modules/Inputs/codegen/use.cpp
@@ -0,0 +1,2 @@
+#include "bar.h"
+int main() { bar(); }
Index: test/Modules/Inputs/codegen/foo.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/codegen/foo.modulemap
@@ -0,0 +1 @@
+module foo { header "foo.h" }
Index: test/Modules/Inputs/codegen/foo.h
===
--- /dev/null
+++ test/Modules/Inputs/codegen/foo.h
@@ -0,0 +1,10 @@
+void f1(int &);
+static void f2() {}
+inline void foo() {
+  static int i;
+  f1(i);
+  f2();
+}
+inline void foo2() {

r293416 - [c-index-test] Provide capability for 'c-index-test core' to dump symbol information from a PCH/module file.

2017-01-28 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Sat Jan 28 22:50:35 2017
New Revision: 293416

URL: http://llvm.org/viewvc/llvm-project?rev=293416=rev
Log:
[c-index-test] Provide capability for 'c-index-test core' to dump symbol 
information from a PCH/module file.

Added:
cfe/trunk/test/Index/Core/index-pch.c
Modified:
cfe/trunk/tools/c-index-test/CMakeLists.txt
cfe/trunk/tools/c-index-test/core_main.cpp

Added: cfe/trunk/test/Index/Core/index-pch.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-pch.c?rev=293416=auto
==
--- cfe/trunk/test/Index/Core/index-pch.c (added)
+++ cfe/trunk/test/Index/Core/index-pch.c Sat Jan 28 22:50:35 2017
@@ -0,0 +1,13 @@
+// RUN: c-index-test core -print-source-symbols -- %s | FileCheck %s
+// RUN: %clang_cc1 -emit-pch %s -o %t.pch
+// RUN: c-index-test core -print-source-symbols -module-file %t.pch | 
FileCheck %s
+
+// CHECK: [[@LINE+1]]:6 | function/C | test1 | [[TEST1_USR:.*]] | 
[[TEST1_CG:.*]] | Decl | rel: 0
+void test1();
+
+// CHECK: [[@LINE+1]]:20 | function/C | test2 | [[TEST2_USR:.*]] | {{.*}} | 
Def | rel: 0
+static inline void test2() {
+  // CHECK: [[@LINE+2]]:3 | function/C | test1 | [[TEST1_USR]] | [[TEST1_CG]] 
| Ref,Call,RelCall,RelCont | rel: 1
+  // CHECK-NEXT: RelCall,RelCont | test2 | [[TEST2_USR]]
+  test1();
+}

Modified: cfe/trunk/tools/c-index-test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/CMakeLists.txt?rev=293416=293415=293416=diff
==
--- cfe/trunk/tools/c-index-test/CMakeLists.txt (original)
+++ cfe/trunk/tools/c-index-test/CMakeLists.txt Sat Jan 28 22:50:35 2017
@@ -24,6 +24,7 @@ else()
 libclang
 clangAST
 clangBasic
+clangCodeGen
 clangFrontend
 clangIndex
   )

Modified: cfe/trunk/tools/c-index-test/core_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/core_main.cpp?rev=293416=293415=293416=diff
==
--- cfe/trunk/tools/c-index-test/core_main.cpp (original)
+++ cfe/trunk/tools/c-index-test/core_main.cpp Sat Jan 28 22:50:35 2017
@@ -7,6 +7,7 @@
 //
 
//===--===//
 
+#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
@@ -49,6 +50,13 @@ static cl::extrahelp MoreHelp(
   "invocation\n"
 );
 
+static cl::opt
+ModuleFilePath("module-file",
+   cl::desc("Path to module file to print symbols from"));
+static cl::opt
+  ModuleFormat("fmodule-format", cl::init("raw"),
+cl::desc("Container format for clang modules and PCH, 'raw' or 
'obj'"));
+
 }
 } // anonymous namespace
 
@@ -160,6 +168,39 @@ static bool printSourceSymbols(ArrayRef<
   return false;
 }
 
+static bool printSourceSymbolsFromModule(StringRef modulePath,
+ StringRef format) {
+  FileSystemOptions FileSystemOpts;
+  auto pchContOps = std::make_shared();
+  // Register the support for object-file-wrapped Clang modules.
+  
pchContOps->registerReader(llvm::make_unique());
+  auto pchRdr = pchContOps->getReaderOrNull(format);
+  if (!pchRdr) {
+errs() << "unknown module format: " << format << '\n';
+return true;
+  }
+
+  IntrusiveRefCntPtr Diags =
+  CompilerInstance::createDiagnostics(new DiagnosticOptions());
+  std::unique_ptr AU = ASTUnit::LoadFromASTFile(
+  modulePath, *pchRdr, Diags,
+  FileSystemOpts, /*UseDebugInfo=*/false,
+  /*OnlyLocalDecls=*/true, None,
+  /*CaptureDiagnostics=*/false,
+  /*AllowPCHWithCompilerErrors=*/true,
+  /*UserFilesAreVolatile=*/false);
+  if (!AU) {
+errs() << "failed to create TU for: " << modulePath << '\n';
+return true;
+  }
+
+  auto DataConsumer = std::make_shared(outs());
+  IndexingOptions IndexOpts;
+  indexASTUnit(*AU, DataConsumer, IndexOpts);
+
+  return false;
+}
+
 
//===--===//
 // Helper Utils
 
//===--===//
@@ -219,6 +260,10 @@ int indextest_core_main(int argc, const
   }
 
   if (options::Action == ActionType::PrintSourceSymbols) {
+if (!options::ModuleFilePath.empty()) {
+  return printSourceSymbolsFromModule(options::ModuleFilePath,
+  options::ModuleFormat);
+}
 if (CompArgs.empty()) {
   errs() << "error: missing compiler args; pass '-- '\n";
   return 1;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293415 - Modules: Fix a minor performance bug from r293393

2017-01-28 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Jan 28 22:42:21 2017
New Revision: 293415

URL: http://llvm.org/viewvc/llvm-project?rev=293415=rev
Log:
Modules: Fix a minor performance bug from r293393

Oops... r293393 started calling ReadSignature in
ModuleManager::addModule even when there was no ExpectedSignature.

Whether or not this would have a measurable performance impact (I
spotted this by inspection, and ReadSignature should be fairly fast), we
might as well get what we can.  Add an extra check against
ExpectedSignature to avoid the hit.

Modified:
cfe/trunk/lib/Serialization/ModuleManager.cpp

Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=293415=293414=293415=diff
==
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Sat Jan 28 22:42:21 2017
@@ -165,9 +165,10 @@ ModuleManager::addModule(StringRef FileN
   // Initialize the stream.
   NewModule->Data = PCHContainerRdr.ExtractPCH(*NewModule->Buffer);
 
-  // Read the signature eagerly now so that we can check it.
-  if (checkSignature(ReadSignature(NewModule->Data), ExpectedSignature,
- ErrorStr))
+  // Read the signature eagerly now so that we can check it.  Avoid calling
+  // ReadSignature unless there's something to check though.
+  if (ExpectedSignature && checkSignature(ReadSignature(NewModule->Data),
+  ExpectedSignature, ErrorStr))
 return OutOfDate;
 
   // We're keeping this module.  Store it everywhere.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r293123 - Remove and replace DiagStatePoint tracking and lookup data structure.

2017-01-28 Thread Richard Smith via cfe-commits
On 28 Jan 2017 8:16 pm, "Duncan P. N. Exon Smith via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

Hi Richard,

This commit makes one of the tests fail in:
https://reviews.llvm.org/D27689

The implicit modules model expects to be able to "upgrade" an implicit PCM
with more -Werror flags *without* affecting the signature.  However, with
your commit, the command-line diagnostic flags (e.g., -Wconversion vs
-Wno-conversion) now change the AST, and thus change the ASTFileSignature.

One possible hammer would be to disable this pragma-diagnostic-stuff
somehow for implicit modules.  Do you have any other suggestions?


I think that upgrade model is incorrect in the fully general case. For
instance, in C++, enabling more warning flags in the definition of a
template can cause behaviour changes in users of the template. Likewise, in
C, as I recall we'll sometimes look at the warning state at the point of
definition of a macro to determine whether to emit a warning in a macro
expansion.

That said, for implicit modules we can probably assume that the effects of
changing the starting state can be simulated. Right now ,the implicit /
explicit module decision is not made until the point of import, so we would
need to commit to that earlier to avoid emitting the information at all in
that case. Another alternative would be to exclude the diagnostic settings
in the initial state from the hash, either by never emitting it and
recomputing it from the diagnostic flags as needed, or by emitting it into
an unhashed portion of the file.

Thanks,
Duncan

> On 2017-Jan-25, at 17:01, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:
>
> Author: rsmith
> Date: Wed Jan 25 19:01:01 2017
> New Revision: 293123
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293123=rev
> Log:
> Remove and replace DiagStatePoint tracking and lookup data structure.
>
> Rather than storing a single flat list of SourceLocations where the
diagnostic
> state changes (in source order), we now store a separate list for each
FileID
> in which there is a diagnostic state transition. (State for other files is
> built and cached lazily, on demand.) This has two consequences:
>
> 1) We can now sensibly support modules, and properly track the diagnostic
state
> for modular headers (this matters when, for instance, triggering
instantiation
> of a template defined within a module triggers diagnostics).
>
> 2) It's much faster than the old approach, since we can now just do a
binary
> search on the offsets within the FileID rather than needing to call
> isBeforeInTranslationUnit to determine source order (which is surprisingly
> slow). For some pathological (but real world) files, this reduces total
> compilation time by more than 10%.
>
> For now, the diagnostic state points for modules are loaded eagerly. It
seems
> feasible to defer this until diagnostic state information for one of the
> module's files is needed, but that's not part of this patch.
>
> Added:
>cfe/trunk/test/Modules/diag-pragma.cpp
> Modified:
>cfe/trunk/include/clang/Basic/Diagnostic.h
>cfe/trunk/lib/Basic/Diagnostic.cpp
>cfe/trunk/lib/Basic/DiagnosticIDs.cpp
>cfe/trunk/lib/Serialization/ASTReader.cpp
>cfe/trunk/lib/Serialization/ASTWriter.cpp
>cfe/trunk/test/Modules/Inputs/diag_pragma.h
>
> Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
clang/Basic/Diagnostic.h?rev=293123=293122=293123=diff
> 
==
> --- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
> +++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Jan 25 19:01:01 2017
> @@ -29,6 +29,7 @@
> #include 
> #include 
> #include 
> +#include 
> #include 
> #include 
> #include 
> @@ -232,40 +233,97 @@ private:
>   /// \brief Keeps and automatically disposes all DiagStates that we
create.
>   std::list DiagStates;
>
> -  /// \brief Represents a point in source where the diagnostic state was
> -  /// modified because of a pragma.
> -  ///
> -  /// 'Loc' can be null if the point represents the diagnostic state
> -  /// modifications done through the command-line.
> -  struct DiagStatePoint {
> -DiagState *State;
> -SourceLocation Loc;
> -DiagStatePoint(DiagState *State, SourceLocation Loc)
> -  : State(State), Loc(Loc) { }
> +  /// A mapping from files to the diagnostic states for those files.
Lazily
> +  /// built on demand for files in which the diagnostic state has not
changed.
> +  class DiagStateMap {
> +  public:
> +/// Add an initial diagnostic state.
> +void appendFirst(DiagState *State);
> +/// Add a new latest state point.
> +void append(SourceManager , SourceLocation Loc, DiagState
*State);
> +/// Look up the diagnostic state at a given source location.
> +DiagState *lookup(SourceManager , SourceLocation Loc) const;
> +/// Determine whether this map is empty.
> +bool empty() const { return 

Re: r293123 - Remove and replace DiagStatePoint tracking and lookup data structure.

2017-01-28 Thread Duncan P. N. Exon Smith via cfe-commits
Hi Richard,

This commit makes one of the tests fail in:
https://reviews.llvm.org/D27689

The implicit modules model expects to be able to "upgrade" an implicit PCM with 
more -Werror flags *without* affecting the signature.  However, with your 
commit, the command-line diagnostic flags (e.g., -Wconversion vs 
-Wno-conversion) now change the AST, and thus change the ASTFileSignature.

One possible hammer would be to disable this pragma-diagnostic-stuff somehow 
for implicit modules.  Do you have any other suggestions?

Thanks,
Duncan

> On 2017-Jan-25, at 17:01, Richard Smith via cfe-commits 
>  wrote:
> 
> Author: rsmith
> Date: Wed Jan 25 19:01:01 2017
> New Revision: 293123
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=293123=rev
> Log:
> Remove and replace DiagStatePoint tracking and lookup data structure.
> 
> Rather than storing a single flat list of SourceLocations where the diagnostic
> state changes (in source order), we now store a separate list for each FileID
> in which there is a diagnostic state transition. (State for other files is
> built and cached lazily, on demand.) This has two consequences:
> 
> 1) We can now sensibly support modules, and properly track the diagnostic 
> state
> for modular headers (this matters when, for instance, triggering instantiation
> of a template defined within a module triggers diagnostics).
> 
> 2) It's much faster than the old approach, since we can now just do a binary
> search on the offsets within the FileID rather than needing to call
> isBeforeInTranslationUnit to determine source order (which is surprisingly
> slow). For some pathological (but real world) files, this reduces total
> compilation time by more than 10%.
> 
> For now, the diagnostic state points for modules are loaded eagerly. It seems
> feasible to defer this until diagnostic state information for one of the
> module's files is needed, but that's not part of this patch.
> 
> Added:
>cfe/trunk/test/Modules/diag-pragma.cpp
> Modified:
>cfe/trunk/include/clang/Basic/Diagnostic.h
>cfe/trunk/lib/Basic/Diagnostic.cpp
>cfe/trunk/lib/Basic/DiagnosticIDs.cpp
>cfe/trunk/lib/Serialization/ASTReader.cpp
>cfe/trunk/lib/Serialization/ASTWriter.cpp
>cfe/trunk/test/Modules/Inputs/diag_pragma.h
> 
> Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=293123=293122=293123=diff
> ==
> --- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
> +++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Jan 25 19:01:01 2017
> @@ -29,6 +29,7 @@
> #include 
> #include 
> #include 
> +#include 
> #include 
> #include 
> #include 
> @@ -232,40 +233,97 @@ private:
>   /// \brief Keeps and automatically disposes all DiagStates that we create.
>   std::list DiagStates;
> 
> -  /// \brief Represents a point in source where the diagnostic state was
> -  /// modified because of a pragma.
> -  ///
> -  /// 'Loc' can be null if the point represents the diagnostic state
> -  /// modifications done through the command-line.
> -  struct DiagStatePoint {
> -DiagState *State;
> -SourceLocation Loc;
> -DiagStatePoint(DiagState *State, SourceLocation Loc)
> -  : State(State), Loc(Loc) { } 
> +  /// A mapping from files to the diagnostic states for those files. Lazily
> +  /// built on demand for files in which the diagnostic state has not 
> changed.
> +  class DiagStateMap {
> +  public:
> +/// Add an initial diagnostic state.
> +void appendFirst(DiagState *State);
> +/// Add a new latest state point.
> +void append(SourceManager , SourceLocation Loc, DiagState *State);
> +/// Look up the diagnostic state at a given source location.
> +DiagState *lookup(SourceManager , SourceLocation Loc) const;
> +/// Determine whether this map is empty.
> +bool empty() const { return Files.empty(); }
> +/// Clear out this map.
> +void clear() {
> +  Files.clear();
> +  FirstDiagState = CurDiagState = nullptr;
> +  CurDiagStateLoc = SourceLocation();
> +}
> +
> +/// Grab the most-recently-added state point.
> +DiagState *getCurDiagState() const { return CurDiagState; }
> +/// Get the location at which a diagnostic state was last added.
> +SourceLocation getCurDiagStateLoc() const { return CurDiagStateLoc; }
> +
> +  private:
> +/// \brief Represents a point in source where the diagnostic state was
> +/// modified because of a pragma.
> +///
> +/// 'Loc' can be null if the point represents the diagnostic state
> +/// modifications done through the command-line.
> +struct DiagStatePoint {
> +  DiagState *State;
> +  unsigned Offset;
> +  DiagStatePoint(DiagState *State, unsigned Offset)
> +: State(State), Offset(Offset) { } 
> +};
> +
> +/// Description of the diagnostic states and state 

[PATCH] D27689: Module: hash the pcm content and use it as SIGNATURE for implicit modules.

2017-01-28 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 86193.
dexonsmith added a comment.

I've rebased the patch on ToT and cleaned a few things up.

Sadly, the clang/test/Modules/diagnostic-options-out-of-date.m test fails 
because r293123 makes the command-line diagnostic options affect the AST, and 
thus makes -Wconversion vs -Wno-conversion change ASTFileSignature.

I'm not sure how to move forward.


https://reviews.llvm.org/D27689

Files:
  clang/include/clang/AST/ExternalASTSource.h
  clang/include/clang/Basic/Module.h
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/PCHContainerOperations.h
  clang/include/clang/Lex/HeaderSearchOptions.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/Module.h
  clang/lib/Basic/Module.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GeneratePCH.cpp
  clang/lib/Serialization/GlobalModuleIndex.cpp
  clang/test/Modules/diagnostic-options-out-of-date.m
  clang/test/Modules/module_file_info.m
  clang/test/Modules/rebuild.m

Index: clang/test/Modules/rebuild.m
===
--- clang/test/Modules/rebuild.m
+++ clang/test/Modules/rebuild.m
@@ -19,11 +19,10 @@
 // RUN: diff %t/Module.size %t/Module.size.saved
 // RUN: cp %t/Module.pcm %t/Module.pcm.saved.2
 
-// But the signature at least is expected to change, so we rebuild DependsOnModule.
-// NOTE: if we change how the signature is created, this test may need updating.
+// The signature is the hash of the PCM content, we will not rebuild rebuild DependsOnModule.
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -fsyntax-only -F %S/Inputs %s
 // RUN: diff %t/Module.pcm %t/Module.pcm.saved.2
-// RUN: not diff %t/DependsOnModule.pcm %t/DependsOnModule.pcm.saved
+// RUN: diff %t/DependsOnModule.pcm %t/DependsOnModule.pcm.saved
 
 // Rebuild Module, reset its timestamp, and verify its size hasn't changed
 // RUN: rm %t/Module.pcm
@@ -34,10 +33,9 @@
 // RUN: cp %t/Module.pcm %t/Module.pcm.saved.2
 
 // Verify again with Module pre-imported.
-// NOTE: if we change how the signature is created, this test may need updating.
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -fsyntax-only -F %S/Inputs %s
 // RUN: diff %t/Module.pcm %t/Module.pcm.saved.2
-// RUN: not diff %t/DependsOnModule.pcm %t/DependsOnModule.pcm.saved
+// RUN: diff %t/DependsOnModule.pcm %t/DependsOnModule.pcm.saved
 
 #ifdef PREIMPORT
 @import Module;
Index: clang/test/Modules/module_file_info.m
===
--- clang/test/Modules/module_file_info.m
+++ clang/test/Modules/module_file_info.m
@@ -29,11 +29,6 @@
 // CHECK: CPU:
 // CHECK: ABI:
 
-// CHECK: Diagnostic options:
-// CHECK:   IgnoreWarnings: Yes
-// CHECK:   Diagnostic flags:
-// CHECK: -Wunused
-
 // CHECK: Header search options:
 // CHECK:   System root [-isysroot=]: '/'
 // CHECK:   Use builtin include directories [-nobuiltininc]: Yes
@@ -47,3 +42,8 @@
 // CHECK:   Predefined macros:
 // CHECK: -DBLARG
 // CHECK: -DWIBBLE=WOBBLE
+
+// CHECK: Diagnostic options:
+// CHECK:   IgnoreWarnings: Yes
+// CHECK:   Diagnostic flags:
+// CHECK: -Wunused
Index: clang/test/Modules/diagnostic-options-out-of-date.m
===
--- clang/test/Modules/diagnostic-options-out-of-date.m
+++ clang/test/Modules/diagnostic-options-out-of-date.m
@@ -7,6 +7,16 @@
 // RUN: %clang_cc1 -Werror -Wconversion -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs %s -fmodules-disable-diagnostic-validation
 // Make sure we don't error out when using the pch
 // RUN: %clang_cc1 -Werror -Wno-conversion -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -fsyntax-only -I %S/Inputs -include-pch %t.pch %s -verify -fmodules-disable-diagnostic-validation
+
+// Build A.pcm
+// RUN: %clang_cc1 -Werror -Wno-conversion -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs %s
+// Build pch that imports A.pcm
+// RUN: %clang_cc1 -Werror -Wno-conversion -emit-pch -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -o %t.pch -I %S/Inputs -x objective-c-header %S/Inputs/pch-import-module-out-of-date.pch
+// We will rebuild A.pcm and overwrite the original A.pcm that the pch imports, but the two versions have the same hash.
+// RUN: %clang_cc1 -Werror -Wconversion -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs %s
+// Make sure we don't error out when using the pch
+// RUN: %clang_cc1 

[PATCH] D27689: Module: hash the pcm content and use it as SIGNATURE for implicit modules.

2017-01-28 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith commandeered this revision.
dexonsmith added a reviewer: manmanren.
dexonsmith added a comment.

Taking this over to rebase.


https://reviews.llvm.org/D27689



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293404 - Modules: Simplify the ModuleFile constructor; likely NFC

2017-01-28 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Jan 28 18:39:09 2017
New Revision: 293404

URL: http://llvm.org/viewvc/llvm-project?rev=293404=rev
Log:
Modules: Simplify the ModuleFile constructor; likely NFC

Zero-initialize ModuleFile members directly in the class definition, and
move the (now uninteresting) constructor into the class definition.

There were a few members that weren't being initialized at all.  I
zero-initialized them for consistency, but it's likely that they were
somehow initialized before their first use; i.e., there's likely no
functionality change here.

Modified:
cfe/trunk/include/clang/Serialization/Module.h
cfe/trunk/lib/Serialization/Module.cpp

Modified: cfe/trunk/include/clang/Serialization/Module.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/Module.h?rev=293404=293403=293404=diff
==
--- cfe/trunk/include/clang/Serialization/Module.h (original)
+++ cfe/trunk/include/clang/Serialization/Module.h Sat Jan 28 18:39:09 2017
@@ -100,13 +100,14 @@ typedef unsigned ASTFileSignature;
 /// other modules.
 class ModuleFile {
 public:
-  ModuleFile(ModuleKind Kind, unsigned Generation);
+  ModuleFile(ModuleKind Kind, unsigned Generation)
+  : Kind(Kind), Generation(Generation) {}
   ~ModuleFile();
 
   // === General information ===
 
   /// \brief The index of this module in the list of modules.
-  unsigned Index;
+  unsigned Index = 0;
 
   /// \brief The type of this module.
   ModuleKind Kind;
@@ -144,21 +145,21 @@ public:
   std::string ModuleMapPath;
 
   /// \brief Whether this precompiled header is a relocatable PCH file.
-  bool RelocatablePCH;
+  bool RelocatablePCH = false;
 
   /// \brief Whether timestamps are included in this module file.
-  bool HasTimestamps;
+  bool HasTimestamps = false;
 
   /// \brief The file entry for the module file.
-  const FileEntry *File;
+  const FileEntry *File = nullptr;
 
   /// \brief The signature of the module file, which may be used along with 
size
   /// and modification time to identify this particular file.
-  ASTFileSignature Signature;
+  ASTFileSignature Signature = 0;
 
   /// \brief Whether this module has been directly imported by the
   /// user.
-  bool DirectlyImported;
+  bool DirectlyImported = false;
 
   /// \brief The generation of which this module file is a part.
   unsigned Generation;
@@ -168,10 +169,10 @@ public:
   std::unique_ptr Buffer;
 
   /// \brief The size of this file, in bits.
-  uint64_t SizeInBits;
+  uint64_t SizeInBits = 0;
 
   /// \brief The global bit offset (or base) of this module
-  uint64_t GlobalBitOffset;
+  uint64_t GlobalBitOffset = 0;
 
   /// \brief The serialized bitstream data for this file.
   StringRef Data;
@@ -205,7 +206,7 @@ public:
   llvm::BitstreamCursor InputFilesCursor;
 
   /// \brief Offsets for all of the input file entries in the AST file.
-  const llvm::support::unaligned_uint64_t *InputFileOffsets;
+  const llvm::support::unaligned_uint64_t *InputFileOffsets = nullptr;
 
   /// \brief The input files that have been loaded from this AST file.
   std::vector InputFilesLoaded;
@@ -214,7 +215,7 @@ public:
   /// files.  Zero means we never validated them.
   ///
   /// The time is specified in seconds since the start of the Epoch.
-  uint64_t InputFilesValidationTimestamp;
+  uint64_t InputFilesValidationTimestamp = 0;
 
   // === Source Locations ===
 
@@ -222,17 +223,17 @@ public:
   llvm::BitstreamCursor SLocEntryCursor;
 
   /// \brief The number of source location entries in this AST file.
-  unsigned LocalNumSLocEntries;
+  unsigned LocalNumSLocEntries = 0;
 
   /// \brief The base ID in the source manager's view of this module.
-  int SLocEntryBaseID;
+  int SLocEntryBaseID = 0;
 
   /// \brief The base offset in the source manager's view of this module.
-  unsigned SLocEntryBaseOffset;
+  unsigned SLocEntryBaseOffset = 0;
 
   /// \brief Offsets for all of the source location entries in the
   /// AST file.
-  const uint32_t *SLocEntryOffsets;
+  const uint32_t *SLocEntryOffsets = nullptr;
 
   /// \brief SLocEntries that we're going to preload.
   SmallVector PreloadSLocEntries;
@@ -243,17 +244,17 @@ public:
   // === Identifiers ===
 
   /// \brief The number of identifiers in this AST file.
-  unsigned LocalNumIdentifiers;
+  unsigned LocalNumIdentifiers = 0;
 
   /// \brief Offsets into the identifier table data.
   ///
   /// This array is indexed by the identifier ID (-1), and provides
   /// the offset into IdentifierTableData where the string data is
   /// stored.
-  const uint32_t *IdentifierOffsets;
+  const uint32_t *IdentifierOffsets = nullptr;
 
   /// \brief Base identifier ID for identifiers local to this module.
-  serialization::IdentID BaseIdentifierID;
+  serialization::IdentID BaseIdentifierID = 0;
 
   /// \brief Remapping table for identifier IDs in this module.
   ContinuousRangeMap IdentifierRemap;
@@ 

r293400 - Modules: Return early in ModuleManager::addModule; NFC

2017-01-28 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Jan 28 17:22:40 2017
New Revision: 293400

URL: http://llvm.org/viewvc/llvm-project?rev=293400=rev
Log:
Modules: Return early in ModuleManager::addModule; NFC

Invert the main branch in ModuleManager::addModule to return early and
reduce indentation, and clean up a bunch of logic as a result.  I split
out a function called updateModuleImports to avoid triggering code
duplication.

Modified:
cfe/trunk/lib/Serialization/ModuleManager.cpp

Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=293400=293399=293400=diff
==
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Sat Jan 28 17:22:40 2017
@@ -63,6 +63,19 @@ static bool checkSignature(ASTFileSignat
   return true;
 }
 
+static void updateModuleImports(ModuleFile , ModuleFile *ImportedBy,
+SourceLocation ImportLoc) {
+  if (ImportedBy) {
+MF.ImportedBy.insert(ImportedBy);
+ImportedBy->Imports.insert();
+  } else {
+if (!MF.DirectlyImported)
+  MF.ImportLoc = ImportLoc;
+
+MF.DirectlyImported = true;
+  }
+}
+
 ModuleManager::AddModuleResult
 ModuleManager::addModule(StringRef FileName, ModuleKind Type,
  SourceLocation ImportLoc, ModuleFile *ImportedBy,
@@ -95,91 +108,79 @@ ModuleManager::addModule(StringRef FileN
   }
 
   // Check whether we already loaded this module, before
-  ModuleFile *ModuleEntry = Modules[Entry];
-  std::unique_ptr NewModule;
-  if (!ModuleEntry) {
-// Allocate a new module.
-NewModule = llvm::make_unique(Type, Generation);
-NewModule->Index = Chain.size();
-NewModule->FileName = FileName.str();
-NewModule->File = Entry;
-NewModule->ImportLoc = ImportLoc;
-NewModule->InputFilesValidationTimestamp = 0;
-
-if (NewModule->Kind == MK_ImplicitModule) {
-  std::string TimestampFilename = NewModule->getTimestampFilename();
-  vfs::Status Status;
-  // A cached stat value would be fine as well.
-  if (!FileMgr.getNoncachedStatValue(TimestampFilename, Status))
-NewModule->InputFilesValidationTimestamp =
-llvm::sys::toTimeT(Status.getLastModificationTime());
-}
+  if (ModuleFile *ModuleEntry = Modules.lookup(Entry)) {
+// Check the stored signature.
+if (checkSignature(ModuleEntry->Signature, ExpectedSignature, ErrorStr))
+  return OutOfDate;
 
-// Load the contents of the module
-if (std::unique_ptr Buffer = lookupBuffer(FileName)) {
-  // The buffer was already provided for us.
-  NewModule->Buffer = std::move(Buffer);
-} else {
-  // Open the AST file.
-  llvm::ErrorOr Buf(
-  (std::error_code()));
-  if (FileName == "-") {
-Buf = llvm::MemoryBuffer::getSTDIN();
-  } else {
-// Leave the FileEntry open so if it gets read again by another
-// ModuleManager it must be the same underlying file.
-// FIXME: Because FileManager::getFile() doesn't guarantee that it will
-// give us an open file, this may not be 100% reliable.
-Buf = FileMgr.getBufferForFile(NewModule->File,
-   /*IsVolatile=*/false,
-   /*ShouldClose=*/false);
-  }
-
-  if (!Buf) {
-ErrorStr = Buf.getError().message();
-return Missing;
-  }
+Module = ModuleEntry;
+updateModuleImports(*ModuleEntry, ImportedBy, ImportLoc);
+return AlreadyLoaded;
+  }
 
-  NewModule->Buffer = std::move(*Buf);
-}
+  // Allocate a new module.
+  auto NewModule = llvm::make_unique(Type, Generation);
+  NewModule->Index = Chain.size();
+  NewModule->FileName = FileName.str();
+  NewModule->File = Entry;
+  NewModule->ImportLoc = ImportLoc;
+  NewModule->InputFilesValidationTimestamp = 0;
+
+  if (NewModule->Kind == MK_ImplicitModule) {
+std::string TimestampFilename = NewModule->getTimestampFilename();
+vfs::Status Status;
+// A cached stat value would be fine as well.
+if (!FileMgr.getNoncachedStatValue(TimestampFilename, Status))
+  NewModule->InputFilesValidationTimestamp =
+  llvm::sys::toTimeT(Status.getLastModificationTime());
+  }
 
-// Initialize the stream.
-NewModule->Data = PCHContainerRdr.ExtractPCH(*NewModule->Buffer);
+  // Load the contents of the module
+  if (std::unique_ptr Buffer = lookupBuffer(FileName)) {
+// The buffer was already provided for us.
+NewModule->Buffer = std::move(Buffer);
+  } else {
+// Open the AST file.
+llvm::ErrorOr 
Buf((std::error_code()));
+if (FileName == "-") {
+  Buf = llvm::MemoryBuffer::getSTDIN();
+} else {
+  // Leave the FileEntry open so if it gets read again by another
+  // ModuleManager it must be the same 

r293399 - Modules: Clean up ModuleFile::Imports in ModuleManager::removeModules

2017-01-28 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Jan 28 17:12:13 2017
New Revision: 293399

URL: http://llvm.org/viewvc/llvm-project?rev=293399=rev
Log:
Modules: Clean up ModuleFile::Imports in ModuleManager::removeModules

I don't have a testcase for this (and I'm not sure if it's an observable
bug), but it seems obviously wrong that ModuleManager::removeModules is
failing to clean up deleted modules from ModuleFile::Imports.  See the
code in ModuleManager::addModule that inserts into ModuleFile::Imports;
we need the inverse operation.

Modified:
cfe/trunk/lib/Serialization/ModuleManager.cpp

Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=293399=293398=293399=diff
==
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Sat Jan 28 17:12:13 2017
@@ -204,10 +204,10 @@ void ModuleManager::removeModules(
 return victimSet.count(MF);
   };
   // Remove any references to the now-destroyed modules.
-  //
-  // FIXME: this should probably clean up Imports as well.
-  for (auto I = begin(); I != First; ++I)
+  for (auto I = begin(); I != First; ++I) {
+I->Imports.remove_if(IsVictim);
 I->ImportedBy.remove_if(IsVictim);
+  }
   Roots.erase(std::remove_if(Roots.begin(), Roots.end(), IsVictim),
   Roots.end());
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293398 - Modules: Enforce that ModuleManager::removeModules deletes the tail

2017-01-28 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Jan 28 17:02:12 2017
New Revision: 293398

URL: http://llvm.org/viewvc/llvm-project?rev=293398=rev
Log:
Modules: Enforce that ModuleManager::removeModules deletes the tail

ModuleManager::removeModules always deletes a tail of the
ModuleManager::Chain.  Change the API to enforce that so that we can
simplify the code inside.

There's no real functionality change, although there's a slight
performance hack to loop to the First deleted module instead of the
final module in the chain (skipping the about-to-be-deleted tail).

Also document something suspicious: we fail to clean deleted modules out
of ModuleFile::Imports.

Modified:
cfe/trunk/include/clang/Serialization/ModuleManager.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ModuleManager.cpp

Modified: cfe/trunk/include/clang/Serialization/ModuleManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ModuleManager.h?rev=293398=293397=293398=diff
==
--- cfe/trunk/include/clang/Serialization/ModuleManager.h (original)
+++ cfe/trunk/include/clang/Serialization/ModuleManager.h Sat Jan 28 17:02:12 
2017
@@ -228,8 +228,8 @@ public:
 ModuleFile *,
 std::string );
 
-  /// \brief Remove the given set of modules.
-  void removeModules(ModuleIterator first, ModuleIterator last,
+  /// \brief Remove the modules starting from First (to the end).
+  void removeModules(ModuleIterator First,
  llvm::SmallPtrSetImpl ,
  ModuleMap *modMap);
 

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=293398=293397=293398=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sat Jan 28 17:02:12 2017
@@ -3643,11 +3643,10 @@ ASTReader::ASTReadResult ASTReader::Read
 for (const ImportedModule  : Loaded)
   LoadedSet.insert(IM.Mod);
 
-ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, ModuleMgr.end(),
-LoadedSet,
+ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, LoadedSet,
 Context.getLangOpts().Modules
-  ? ().getModuleMap()
-  : nullptr);
+? ().getModuleMap()
+: nullptr);
 
 // If we find that any modules are unusable, the global index is going
 // to be out-of-date. Just remove it.

Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=293398=293397=293398=diff
==
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Sat Jan 28 17:02:12 2017
@@ -184,32 +184,35 @@ ModuleManager::addModule(StringRef FileN
 }
 
 void ModuleManager::removeModules(
-ModuleIterator first, ModuleIterator last,
+ModuleIterator First,
 llvm::SmallPtrSetImpl ,
 ModuleMap *modMap) {
-  if (first == last)
+  auto Last = end();
+  if (First == Last)
 return;
 
+
   // Explicitly clear VisitOrder since we might not notice it is stale.
   VisitOrder.clear();
 
   // Collect the set of module file pointers that we'll be removing.
   llvm::SmallPtrSet victimSet(
-  (llvm::pointer_iterator(first)),
-  (llvm::pointer_iterator(last)));
+  (llvm::pointer_iterator(First)),
+  (llvm::pointer_iterator(Last)));
 
   auto IsVictim = [&](ModuleFile *MF) {
 return victimSet.count(MF);
   };
   // Remove any references to the now-destroyed modules.
-  for (unsigned i = 0, n = Chain.size(); i != n; ++i) {
-Chain[i]->ImportedBy.remove_if(IsVictim);
-  }
+  //
+  // FIXME: this should probably clean up Imports as well.
+  for (auto I = begin(); I != First; ++I)
+I->ImportedBy.remove_if(IsVictim);
   Roots.erase(std::remove_if(Roots.begin(), Roots.end(), IsVictim),
   Roots.end());
 
   // Remove the modules from the PCH chain.
-  for (auto I = first; I != last; ++I) {
+  for (auto I = First; I != Last; ++I) {
 if (!I->isModule()) {
   PCHChain.erase(std::find(PCHChain.begin(), PCHChain.end(), &*I),
  PCHChain.end());
@@ -218,7 +221,7 @@ void ModuleManager::removeModules(
   }
 
   // Delete the modules and erase them from the various structures.
-  for (ModuleIterator victim = first; victim != last; ++victim) {
+  for (ModuleIterator victim = First; victim != Last; ++victim) {
 Modules.erase(victim->File);
 
 if (modMap) {
@@ -236,8 +239,7 @@ void ModuleManager::removeModules(
   }
 
   // Delete the modules.
-  

r293397 - [scan-build-py] remove batch files

2017-01-28 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Sat Jan 28 16:55:25 2017
New Revision: 293397

URL: http://llvm.org/viewvc/llvm-project?rev=293397=rev
Log:
[scan-build-py] remove batch files

Removed:
cfe/trunk/tools/scan-build-py/bin/analyze-build.bat
cfe/trunk/tools/scan-build-py/bin/analyze-c++.bat
cfe/trunk/tools/scan-build-py/bin/analyze-cc.bat
cfe/trunk/tools/scan-build-py/bin/intercept-build.bat
cfe/trunk/tools/scan-build-py/bin/intercept-c++.bat
cfe/trunk/tools/scan-build-py/bin/intercept-cc.bat
cfe/trunk/tools/scan-build-py/bin/scan-build.bat

Removed: cfe/trunk/tools/scan-build-py/bin/analyze-build.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/analyze-build.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/analyze-build.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/analyze-build.bat (removed)
@@ -1 +0,0 @@
-python %~dp0analyze-build %*

Removed: cfe/trunk/tools/scan-build-py/bin/analyze-c++.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/analyze-c%2B%2B.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/analyze-c++.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/analyze-c++.bat (removed)
@@ -1 +0,0 @@
-python %~dp0analyze-c++ %*

Removed: cfe/trunk/tools/scan-build-py/bin/analyze-cc.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/analyze-cc.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/analyze-cc.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/analyze-cc.bat (removed)
@@ -1 +0,0 @@
-python %~dp0analyze-cc %*

Removed: cfe/trunk/tools/scan-build-py/bin/intercept-build.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/intercept-build.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/intercept-build.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/intercept-build.bat (removed)
@@ -1 +0,0 @@
-python %~dp0intercept-build %*

Removed: cfe/trunk/tools/scan-build-py/bin/intercept-c++.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/intercept-c%2B%2B.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/intercept-c++.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/intercept-c++.bat (removed)
@@ -1 +0,0 @@
-python %~dp0intercept-c++ %*

Removed: cfe/trunk/tools/scan-build-py/bin/intercept-cc.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/intercept-cc.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/intercept-cc.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/intercept-cc.bat (removed)
@@ -1 +0,0 @@
-python %~dp0intercept-cc %*

Removed: cfe/trunk/tools/scan-build-py/bin/scan-build.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/scan-build.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/scan-build.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/scan-build.bat (removed)
@@ -1 +0,0 @@
-python %~dp0scan-build %*


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293396 - [scan-build-py] use subprocess wrapper

2017-01-28 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Sat Jan 28 16:48:26 2017
New Revision: 293396

URL: http://llvm.org/viewvc/llvm-project?rev=293396=rev
Log:
[scan-build-py] use subprocess wrapper

Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py
cfe/trunk/tools/scan-build-py/libscanbuild/clang.py
cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py
cfe/trunk/tools/scan-build-py/libscanbuild/runner.py
cfe/trunk/tools/scan-build-py/tests/unit/test_intercept.py
cfe/trunk/tools/scan-build-py/tests/unit/test_runner.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py?rev=293396=293395=293396=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py Sat Jan 28 16:48:26 
2017
@@ -3,10 +3,13 @@
 #
 # This file is distributed under the University of Illinois Open Source
 # License. See LICENSE.TXT for details.
-"""
-This module responsible to run the Clang static analyzer against any build
-and generate reports.
-"""
+""" This module is a collection of methods commonly used in this project. """
+import functools
+import logging
+import os
+import os.path
+import subprocess
+import sys
 
 
 def duplicate_check(method):
@@ -33,16 +36,35 @@ def duplicate_check(method):
 def tempdir():
 """ Return the default temorary directory. """
 
-from os import getenv
-return getenv('TMPDIR', getenv('TEMP', getenv('TMP', '/tmp')))
+return os.getenv('TMPDIR', os.getenv('TEMP', os.getenv('TMP', '/tmp')))
+
+
+def run_command(command, cwd=None):
+""" Run a given command and report the execution.
+
+:param command: array of tokens
+:param cwd: the working directory where the command will be executed
+:return: output of the command
+"""
+def decode_when_needed(result):
+""" check_output returns bytes or string depend on python version """
+return result.decode('utf-8') if isinstance(result, bytes) else result
+
+try:
+directory = os.path.abspath(cwd) if cwd else os.getcwd()
+logging.debug('exec command %s in %s', command, directory)
+output = subprocess.check_output(command,
+ cwd=directory,
+ stderr=subprocess.STDOUT)
+return decode_when_needed(output).splitlines()
+except subprocess.CalledProcessError as ex:
+ex.output = decode_when_needed(ex.output).splitlines()
+raise ex
 
 
 def initialize_logging(verbose_level):
 """ Output content controlled by the verbosity level. """
 
-import sys
-import os.path
-import logging
 level = logging.WARNING - min(logging.WARNING, (10 * verbose_level))
 
 if verbose_level <= 3:
@@ -57,9 +79,6 @@ def initialize_logging(verbose_level):
 def command_entry_point(function):
 """ Decorator for command entry points. """
 
-import functools
-import logging
-
 @functools.wraps(function)
 def wrapper(*args, **kwargs):
 

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/clang.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/clang.py?rev=293396=293395=293396=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/clang.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/clang.py Sat Jan 28 16:48:26 2017
@@ -9,8 +9,7 @@ Since Clang command line interface is so
 a subset of that, it makes sense to create a function specific wrapper. """
 
 import re
-import subprocess
-import logging
+from libscanbuild import run_command
 from libscanbuild.shell import decode
 
 __all__ = ['get_version', 'get_arguments', 'get_checkers']
@@ -25,8 +24,9 @@ def get_version(clang):
 :param clang:   the compiler we are using
 :return:the version string printed to stderr """
 
-output = subprocess.check_output([clang, '-v'], stderr=subprocess.STDOUT)
-return output.decode('utf-8').splitlines()[0]
+output = run_command([clang, '-v'])
+# the relevant version info is in the first line
+return output[0]
 
 
 def get_arguments(command, cwd):
@@ -38,12 +38,11 @@ def get_arguments(command, cwd):
 
 cmd = command[:]
 cmd.insert(1, '-###')
-logging.debug('exec command in %s: %s', cwd, ' '.join(cmd))
 
-output = subprocess.check_output(cmd, cwd=cwd, stderr=subprocess.STDOUT)
+output = run_command(cmd, cwd=cwd)
 # The relevant information is in the last line of the output.
 # Don't check if finding last line fails, would throw exception anyway.
-last_line = output.decode('utf-8').splitlines()[-1]
+last_line = output[-1]
 if re.search(r'clang(.*): error:', last_line):
 raise Exception(last_line)
 return decode(last_line)

r293395 - Modules: Clarify ownership of ModuleFile instances in ModuleManager, NFC

2017-01-28 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Jan 28 16:24:01 2017
New Revision: 293395

URL: http://llvm.org/viewvc/llvm-project?rev=293395=rev
Log:
Modules: Clarify ownership of ModuleFile instances in ModuleManager, NFC

Use std::unique_ptr to clarify the ownership of the ModuleFile instances in
ModuleManager.

Modified:
cfe/trunk/include/clang/Serialization/ModuleManager.h
cfe/trunk/lib/Serialization/ModuleManager.cpp

Modified: cfe/trunk/include/clang/Serialization/ModuleManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ModuleManager.h?rev=293395=293394=293395=diff
==
--- cfe/trunk/include/clang/Serialization/ModuleManager.h (original)
+++ cfe/trunk/include/clang/Serialization/ModuleManager.h Sat Jan 28 16:24:01 
2017
@@ -33,7 +33,7 @@ namespace serialization {
 class ModuleManager {
   /// \brief The chain of AST files, in the order in which we started to load
   /// them (this order isn't really useful for anything).
-  SmallVector Chain;
+  SmallVector Chain;
 
   /// \brief The chain of non-module PCH files. The first entry is the one 
named
   /// by the user, the last one is the one that doesn't depend on anything
@@ -112,12 +112,14 @@ class ModuleManager {
   void returnVisitState(VisitState *State);
 
 public:
-  typedef llvm::pointee_iterator
+  typedef llvm::pointee_iterator<
+  SmallVectorImpl::iterator>
   ModuleIterator;
-  typedef llvm::pointee_iterator
+  typedef llvm::pointee_iterator<
+  SmallVectorImpl::const_iterator>
   ModuleConstIterator;
   typedef llvm::pointee_iterator<
-  SmallVectorImpl::reverse_iterator>
+  SmallVectorImpl::reverse_iterator>
   ModuleReverseIterator;
   typedef std::pair ModuleOffset;
 

Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=293395=293394=293395=diff
==
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Sat Jan 28 16:24:01 2017
@@ -96,30 +96,29 @@ ModuleManager::addModule(StringRef FileN
 
   // Check whether we already loaded this module, before
   ModuleFile *ModuleEntry = Modules[Entry];
-  bool NewModule = false;
+  std::unique_ptr NewModule;
   if (!ModuleEntry) {
 // Allocate a new module.
-NewModule = true;
-ModuleEntry = new ModuleFile(Type, Generation);
-ModuleEntry->Index = Chain.size();
-ModuleEntry->FileName = FileName.str();
-ModuleEntry->File = Entry;
-ModuleEntry->ImportLoc = ImportLoc;
-ModuleEntry->InputFilesValidationTimestamp = 0;
+NewModule = llvm::make_unique(Type, Generation);
+NewModule->Index = Chain.size();
+NewModule->FileName = FileName.str();
+NewModule->File = Entry;
+NewModule->ImportLoc = ImportLoc;
+NewModule->InputFilesValidationTimestamp = 0;
 
-if (ModuleEntry->Kind == MK_ImplicitModule) {
-  std::string TimestampFilename = ModuleEntry->getTimestampFilename();
+if (NewModule->Kind == MK_ImplicitModule) {
+  std::string TimestampFilename = NewModule->getTimestampFilename();
   vfs::Status Status;
   // A cached stat value would be fine as well.
   if (!FileMgr.getNoncachedStatValue(TimestampFilename, Status))
-ModuleEntry->InputFilesValidationTimestamp =
+NewModule->InputFilesValidationTimestamp =
 llvm::sys::toTimeT(Status.getLastModificationTime());
 }
 
 // Load the contents of the module
 if (std::unique_ptr Buffer = lookupBuffer(FileName)) {
   // The buffer was already provided for us.
-  ModuleEntry->Buffer = std::move(Buffer);
+  NewModule->Buffer = std::move(Buffer);
 } else {
   // Open the AST file.
   llvm::ErrorOr Buf(
@@ -131,28 +130,28 @@ ModuleManager::addModule(StringRef FileN
 // ModuleManager it must be the same underlying file.
 // FIXME: Because FileManager::getFile() doesn't guarantee that it will
 // give us an open file, this may not be 100% reliable.
-Buf = FileMgr.getBufferForFile(ModuleEntry->File,
+Buf = FileMgr.getBufferForFile(NewModule->File,
/*IsVolatile=*/false,
/*ShouldClose=*/false);
   }
 
   if (!Buf) {
 ErrorStr = Buf.getError().message();
-delete ModuleEntry;
 return Missing;
   }
 
-  ModuleEntry->Buffer = std::move(*Buf);
+  NewModule->Buffer = std::move(*Buf);
 }
 
 // Initialize the stream.
-ModuleEntry->Data = PCHContainerRdr.ExtractPCH(*ModuleEntry->Buffer);
+NewModule->Data = 

r293394 - Modules: Return ModuleFile& from ModuleManager::begin, etc.; NFC

2017-01-28 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Jan 28 16:15:22 2017
New Revision: 293394

URL: http://llvm.org/viewvc/llvm-project?rev=293394=rev
Log:
Modules: Return ModuleFile& from ModuleManager::begin, etc.; NFC

Hide the pointer indirection in ModuleManager::begin, ModuleManager::end,
ModuleManager::rbegin, and ModuleManager::rend.  Besides tidying up the call
sites, this is preparation for making ownership of ModuleFile explicit.

Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/ModuleManager.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ModuleManager.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=293394=293393=293394=diff
==
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Sat Jan 28 16:15:22 2017
@@ -1633,7 +1633,7 @@ public:
 unsigned Result = 0;
 for (ModuleConstIterator I = ModuleMgr.begin(),
 E = ModuleMgr.end(); I != E; ++I) {
-  Result += (*I)->NumPreprocessedEntities;
+  Result += I->NumPreprocessedEntities;
 }
 
 return Result;

Modified: cfe/trunk/include/clang/Serialization/ModuleManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ModuleManager.h?rev=293394=293393=293394=diff
==
--- cfe/trunk/include/clang/Serialization/ModuleManager.h (original)
+++ cfe/trunk/include/clang/Serialization/ModuleManager.h Sat Jan 28 16:15:22 
2017
@@ -19,6 +19,7 @@
 #include "clang/Serialization/Module.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/iterator.h"
 
 namespace clang { 
 
@@ -111,9 +112,13 @@ class ModuleManager {
   void returnVisitState(VisitState *State);
 
 public:
-  typedef SmallVectorImpl::iterator ModuleIterator;
-  typedef SmallVectorImpl::const_iterator ModuleConstIterator;
-  typedef SmallVectorImpl::reverse_iterator ModuleReverseIterator;
+  typedef llvm::pointee_iterator
+  ModuleIterator;
+  typedef llvm::pointee_iterator
+  ModuleConstIterator;
+  typedef llvm::pointee_iterator<
+  SmallVectorImpl::reverse_iterator>
+  ModuleReverseIterator;
   typedef std::pair ModuleOffset;
 
   explicit ModuleManager(FileManager ,
@@ -136,7 +141,8 @@ public:
   ModuleReverseIterator rend() { return Chain.rend(); }
 
   /// \brief A range covering the PCH and preamble module files loaded.
-  llvm::iterator_range pch_modules() const {
+  llvm::iterator_range
+  pch_modules() const {
 return llvm::make_range(PCHChain.begin(), PCHChain.end());
   }
 

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=293394=293393=293394=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sat Jan 28 16:15:22 2017
@@ -482,7 +482,7 @@ bool PCHValidator::ReadDiagnosticOptions
   // Note: ModuleMgr.rbegin() may not be the current module, but it must be in
   // the transitive closure of its imports, since unrelated modules cannot be
   // imported until after this module finishes validation.
-  ModuleFile *TopImport = *ModuleMgr.rbegin();
+  ModuleFile *TopImport = &*ModuleMgr.rbegin();
   while (!TopImport->ImportedBy.empty())
 TopImport = TopImport->ImportedBy[0];
   if (TopImport->Kind != MK_ImplicitModule)
@@ -1713,15 +1713,15 @@ void ASTReader::ReadDefinedMacros() {
   // Note that we are loading defined macros.
   Deserializing Macros(this);
 
-  for (auto  : llvm::reverse(ModuleMgr)) {
-BitstreamCursor  = I->MacroCursor;
+  for (ModuleFile  : llvm::reverse(ModuleMgr)) {
+BitstreamCursor  = I.MacroCursor;
 
 // If there was no preprocessor block, skip this file.
 if (MacroCursor.getBitcodeBytes().empty())
   continue;
 
 BitstreamCursor Cursor = MacroCursor;
-Cursor.JumpToBit(I->MacroStartOffset);
+Cursor.JumpToBit(I.MacroStartOffset);
 
 RecordData Record;
 while (true) {
@@ -1743,7 +1743,7 @@ void ASTReader::ReadDefinedMacros() {
 
 case PP_MACRO_OBJECT_LIKE:
 case PP_MACRO_FUNCTION_LIKE: {
-  IdentifierInfo *II = getLocalIdentifier(*I, Record[0]);
+  IdentifierInfo *II = getLocalIdentifier(I, Record[0]);
   if (II->isOutOfDate())
 updateOutOfDateIdentifier(*II);
   break;
@@ -3351,8 +3351,7 @@ ASTReader::ReadModuleMapFileBlock(Record
   // usable header search 

r293393 - Modules: Separate out a checkSignature helper, almost NFC

2017-01-28 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Jan 28 15:34:28 2017
New Revision: 293393

URL: http://llvm.org/viewvc/llvm-project?rev=293393=rev
Log:
Modules: Separate out a checkSignature helper, almost NFC

The main point is to move the delete-the-new-module logic into the same block
that creates it, so I can simplify the memory management in a follow-up, but I
think it's clearer to use use a checkSignature helper here anyway.

There is a minor functionality change: we now scan ahead to pull the signature
out of the control block *only* if this is a new ModuleFile.  For old ones,
ASTReader::ReadControlBlock will have already read the signature.

Modified:
cfe/trunk/lib/Serialization/ModuleManager.cpp

Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=293393=293392=293393=diff
==
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Sat Jan 28 15:34:28 2017
@@ -52,6 +52,17 @@ ModuleManager::lookupBuffer(StringRef Na
   return std::move(InMemoryBuffers[Entry]);
 }
 
+static bool checkSignature(ASTFileSignature Signature,
+   ASTFileSignature ExpectedSignature,
+   std::string ) {
+  if (!ExpectedSignature || Signature == ExpectedSignature)
+return false;
+
+  ErrorStr =
+  Signature ? "signature mismatch" : "could not read module signature";
+  return true;
+}
+
 ModuleManager::AddModuleResult
 ModuleManager::addModule(StringRef FileName, ModuleKind Type,
  SourceLocation ImportLoc, ModuleFile *ImportedBy,
@@ -136,22 +147,14 @@ ModuleManager::addModule(StringRef FileN
 
 // Initialize the stream.
 ModuleEntry->Data = PCHContainerRdr.ExtractPCH(*ModuleEntry->Buffer);
-  }
 
-  if (ExpectedSignature) {
-// If we've not read the control block yet, read the signature eagerly now
-// so that we can check it.
-if (!ModuleEntry->Signature)
-  ModuleEntry->Signature = ReadSignature(ModuleEntry->Data);
-
-if (ModuleEntry->Signature != ExpectedSignature) {
-  ErrorStr = ModuleEntry->Signature ? "signature mismatch"
-: "could not read module signature";
-
-  if (NewModule)
-delete ModuleEntry;
+// Read the signature eagerly now so that we can check it.
+if (checkSignature(ReadSignature(ModuleEntry->Data), ExpectedSignature, 
ErrorStr)) {
+  delete ModuleEntry;
   return OutOfDate;
 }
+  } else if (checkSignature(ModuleEntry->Signature, ExpectedSignature, 
ErrorStr)) {
+return OutOfDate;
   }
 
   if (ImportedBy) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28952: [analyzer] Add new Z3 constraint manager backend

2017-01-28 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes added a comment.

Let me give just 2 more Z3-related suggestions:

- instead of re-creating the solver, it might be faster to do Z3_solver_reset
- "once in a while" it might be helpful to delete everything (all solvers, 
asts, context) and call Z3_reset_memory.  Z3's small object pool is not very 
good and keeps growing /ad infinitum/, so cleaning it up once a while is a good 
thing (improves cache usage and reduces memory consumption).

BTW, you may want to call Z3_finalize_memory at exit to keep clang 
valgrind/asan-clean.  (Z3 keeps a lot of internal buffers otherwise)


https://reviews.llvm.org/D28952



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D22057: Prevent devirtualization of calls to un-instantiated functions.

2017-01-28 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added a comment.

I have read the patch, but I don't have enough knowledge about C++ rules and 
fronted to accept it. Richard?




Comment at: lib/Sema/Sema.cpp:684
+  for (auto PII : Pending) 
+if (FunctionDecl *Func = dyn_cast(PII.first))
+  Func->setMarkedForPendingInstantiation();

Prazek wrote:
> Dry. Use auto
auto *


https://reviews.llvm.org/D22057



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293381 - Remove unused 'using' declaration. Found by clang-tidy: misc-unused-using-decls NFC

2017-01-28 Thread Sylvestre Ledru via cfe-commits
Author: sylvestre
Date: Sat Jan 28 07:41:50 2017
New Revision: 293381

URL: http://llvm.org/viewvc/llvm-project?rev=293381=rev
Log:
Remove unused 'using' declaration. Found by clang-tidy: misc-unused-using-decls 
NFC

Modified:
cfe/trunk/lib/Analysis/OSLog.cpp

Modified: cfe/trunk/lib/Analysis/OSLog.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/OSLog.cpp?rev=293381=293380=293381=diff
==
--- cfe/trunk/lib/Analysis/OSLog.cpp (original)
+++ cfe/trunk/lib/Analysis/OSLog.cpp Sat Jan 28 07:41:50 2017
@@ -10,7 +10,6 @@
 #include "llvm/ADT/SmallBitVector.h"
 
 using namespace clang;
-using llvm::APInt;
 
 using clang::analyze_os_log::OSLogBufferItem;
 using clang::analyze_os_log::OSLogBufferLayout;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293379 - Pass a char instead of a string to the find function. clang-tidy: performance-faster-string-find

2017-01-28 Thread Sylvestre Ledru via cfe-commits
Author: sylvestre
Date: Sat Jan 28 07:36:34 2017
New Revision: 293379

URL: http://llvm.org/viewvc/llvm-project?rev=293379=rev
Log:
Pass a char instead of a string to the find function. clang-tidy: 
performance-faster-string-find

Modified:
cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp

Modified: cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp?rev=293379=293378=293379=diff
==
--- cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp Sat Jan 28 07:36:34 
2017
@@ -4454,7 +4454,7 @@ static void BuildUniqueMethodName(std::s
   Name += "__" + MD->getSelector().getAsString();
   // Convert colons to underscores.
   std::string::size_type loc = 0;
-  while ((loc = Name.find(":", loc)) != std::string::npos)
+  while ((loc = Name.find(':', loc)) != std::string::npos)
 Name.replace(loc, 1, "_");
 }
 

Modified: cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp?rev=293379=293378=293379=diff
==
--- cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp Sat Jan 28 07:36:34 2017
@@ -3629,7 +3629,7 @@ static void BuildUniqueMethodName(std::s
   Name += "__" + MD->getSelector().getAsString();
   // Convert colons to underscores.
   std::string::size_type loc = 0;
-  while ((loc = Name.find(":", loc)) != std::string::npos)
+  while ((loc = Name.find(':', loc)) != std::string::npos)
 Name.replace(loc, 1, "_");
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits