[PATCH] D47969: [Verifier] Check that ValueAsMetadata belongs to the module

Roman Tereshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 8 17:48:08 PDT 2018


rtereshin created this revision.
rtereshin added reviewers: aprantl, dexonsmith, mehdi_amini, vlad.tsyrklevich.
Herald added subscribers: llvm-commits, JDevlieghere.

Judging from https://bugs.llvm.org/show_bug.cgi?id=37685 we sometimes end up with module-level metadata that have value-operands belonging to a different module.

I've added the IR Verifier check and hit another interesting case:

`llvm/test/ThinLTO/X86/dicompositetype-unique2.ll` fails on the 3rd RUN-line (`llvm-lto --thinlto-action=run %t1.bc %t2.bc -thinlto-save-temps=%t3.`) with the following (partial) stack trace:

  frame #11: 0x0000000100df4c5f llvm-lto`llvm::verifyModule(M=0x00000001077017c0, OS=0x00000001039aba08, BrokenDebugInfo=0x0000700002f56d4b) at Verifier.cpp:4672
      frame #12: 0x0000000100b448f3 llvm-lto`llvm::UpgradeDebugInfo(M=0x00000001077017c0) at AutoUpgrade.cpp:3099
      frame #13: 0x000000010221037c llvm-lto`llvm::FunctionImporter::importFunctions(this=0x0000700002f57d80, DestModule=0x0000000107700f00, ImportList=0x000000010750b9c8) at FunctionImport.cpp:970
      frame #14: 0x0000000100ee52b3 llvm-lto`(anonymous namespace)::crossImportIntoModule(TheModule=0x0000000107700f00, Index=0x000000010750bd50, ModuleMap=0x00007ffeefbfb8f0, ImportList=0x000000010750b9c8) at ThinLTOCodeGenerator.cpp:202
      frame #15: 0x0000000100f03d82 llvm-lto`(anonymous namespace)::ProcessThinLTOModule(TheModule=0x0000000107700f00, Index=0x000000010750bd50, ModuleMap=0x00007ffeefbfb8f0, TM=0x0000000107306be0, ImportList=0x000000010750b9c8, ExportList=size=0, GUIDPreservedSymbols=0x00007ffeefbfb8a8, DefinedGlobals=0x000000010750b888, CacheOptions=0x00007ffeefbff608, DisableCodeGen=false, SaveTempsDir=(Data = "/Volumes/Data/llvm/build/obj/test/ThinLTO/X86/Output/dicompositetype-unique2.ll.tmp3", Length = 84), Freestanding=false, OptLevel=3, count=0) at ThinLTOCodeGenerator.cpp:460
      frame #16: 0x0000000100f022d6 llvm-lto`llvm::ThinLTOCodeGenerator::run(this=0x000000010750dd88, count=0)::$_2::operator()(int) const at ThinLTOCodeGenerator.cpp:1016

That is an independent problem as `CloneFunctionInto` isn't used by this llvm-lto run at all, though it's quite similar: it would be `!DITemplateValueParameter(name: "F", type: !24, value: %struct.S* ()* @_Z3Getv)` referenced from a DISubprogram associated with a function belonging to a module https://reviews.llvm.org/M1, while the global value referenced by `DITemplateValueParameter` itself would belong to a different module M2.


Repository:
  rL LLVM

https://reviews.llvm.org/D47969

Files:
  lib/IR/Verifier.cpp


Index: lib/IR/Verifier.cpp
===================================================================
--- lib/IR/Verifier.cpp
+++ lib/IR/Verifier.cpp
@@ -808,6 +808,11 @@
   Assert(!MD.getValue()->getType()->isMetadataTy(),
          "Unexpected metadata round-trip through values", &MD, MD.getValue());
 
+  if (auto *GV = dyn_cast<GlobalValue>(MD.getValue())) {
+    Module *ActualM = GV->getParent();
+    Assert(ActualM == &M, "module-local metadata used in wrong module", &MD);
+  }
+
   auto *L = dyn_cast<LocalAsMetadata>(&MD);
   if (!L)
     return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47969.150595.patch
Type: text/x-patch
Size: 552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180609/b288d228/attachment-0001.bin>


More information about the llvm-commits mailing list