]> granicus.if.org Git - clang/commitdiff
Check module signature when the module has already been loaded
authorBen Langmuir <blangmuir@apple.com>
Sat, 8 Nov 2014 00:34:30 +0000 (00:34 +0000)
committerBen Langmuir <blangmuir@apple.com>
Sat, 8 Nov 2014 00:34:30 +0000 (00:34 +0000)
We may need to verify the signature on subsequent imports as well, just
like we verify the size/modtime:
@import A;
@import B; // imports A
@import C; // imports A

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

lib/Serialization/ModuleManager.cpp
test/Modules/rebuild.m

index 3baaa0a4b280534503acfa728c0ad1aafa3bb05c..b5ee41450208f079217d5136ec303eb6958b73f4 100644 (file)
@@ -132,21 +132,27 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
     // Initialize the stream
     New->StreamFile.init((const unsigned char *)New->Buffer->getBufferStart(),
                          (const unsigned char *)New->Buffer->getBufferEnd());
+  }
+
+  if (ExpectedSignature) {
+    if (NewModule)
+      ModuleEntry->Signature = ReadSignature(ModuleEntry->StreamFile);
+    else
+      assert(ModuleEntry->Signature == ReadSignature(ModuleEntry->StreamFile));
 
-    if (ExpectedSignature) {
-      New->Signature = ReadSignature(New->StreamFile);
-      if (New->Signature != ExpectedSignature) {
-        ErrorStr = New->Signature ? "signature mismatch"
-                                  : "could not read module signature";
+    if (ModuleEntry->Signature != ExpectedSignature) {
+      ErrorStr = ModuleEntry->Signature ? "signature mismatch"
+                                        : "could not read module signature";
 
+      if (NewModule) {
         // Remove the module file immediately, since removeModules might try to
         // invalidate the file cache for Entry, and that is not safe if this
         // module is *itself* up to date, but has an out-of-date importer.
         Modules.erase(Entry);
         Chain.pop_back();
-        delete New;
-        return OutOfDate;
+        delete ModuleEntry;
       }
+      return OutOfDate;
     }
   }
   
index 53a1fff90bbf1ce5da3f6b66b9da479ae080e7da..4d4d05529e7d3fe9b1b0aebcd475b47753c088d7 100644 (file)
 // RUN: diff %t/Module.pcm %t/Module.pcm.saved.2
 // RUN: not 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
+// RUN: echo '@import Module;' | %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash -fsyntax-only -F %S/Inputs -x objective-c -
+// RUN: touch -m -a -t 201101010000 %t/Module.pcm
+// RUN: wc -c %t/Module.pcm > %t/Module.size
+// RUN: diff %t/Module.size %t/Module.size.saved
+// 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 -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
+
+#ifdef PREIMPORT
+@import Module;
+#endif
 @import DependsOnModule;