llvm-mirror/tools
Roman Tereshin eecdf22144 [DebugInfo][OPT] Fixing a couple of DI duplication bugs of CloneModule
As demonstrated by the regression tests added in this patch, the
following cases are valid cases:

1. A Function with no DISubprogram attached, but various debug info
  related to its instructions, coming, for instance, from an inlined
  function, also defined somewhere else in the same module;
2. ... or coming exclusively from the functions inlined and eliminated
  from the module entirely.

The ValueMap shared between CloneFunctionInto calls within CloneModule
needs to contain identity mappings for all of the DISubprogram's to
prevent them from being duplicated by MapMetadata / RemapInstruction
calls, this is achieved via DebugInfoFinder collecting all the
DISubprogram's. However, CloneFunctionInto was missing calls into
DebugInfoFinder for functions w/o DISubprogram's attached, but still
referring DISubprogram's from within (case 1). This patch fixes that.

The fix above, however, exposes another issue: if a module contains a
DISubprogram referenced only indirectly from other debug info
metadata, but not attached to any Function defined within the module
(case 2), cloning such a module causes a DICompileUnit duplication: it
will be moved in indirecty via a DISubprogram by DebugInfoFinder first
(because of the first bug fix described above), without being
self-mapped within the shared ValueMap, and then will be copied during
named metadata cloning. So this patch makes sure DebugInfoFinder
visits DICompileUnit's referenced from DISubprogram's as it goes w/o
re-processing llvm.dbg.cu list over and over again for every function
cloned, and makes sure that CloneFunctionInto self-maps
DICompileUnit's referenced from the entire function, not just its own
DISubprogram attached that may also be missing.

The most convenient way of tesing CloneModule I found is to rely on
CloneModule call from `opt -run-twice`, instead of writing tedious
unit tests. That feature has a couple of properties that makes it hard
to use for this purpose though:

1. CloneModule doesn't copy source filename, making `opt -run-twice`
  report it as a difference.
2. `opt -run-twice` does the second run on the original module, not
  its clone, making the result of cloning completely invisible in opt's
  actual output with and without `-run-twice` both, which directly
  contradicts `opt -run-twice`s own error message.

This patch fixes this as well.

Reviewed By: aprantl

Reviewers: loladiro, GorNishanov, espindola, echristo, dexonsmith

Subscribers: vsk, debug-info, JDevlieghere, llvm-commits

Differential Revision: https://reviews.llvm.org/D45593

llvm-svn: 330069
2018-04-13 21:22:24 +00:00
..
bugpoint Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
bugpoint-passes Remove redundant includes from tools. 2017-12-13 21:31:10 +00:00
dsymutil Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
gold Enable debug fission for thinLTO linked via gold-plugin 2018-04-13 05:03:28 +00:00
llc Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
lli Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-ar Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-as Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-as-fuzzer cmake: Invent add_llvm_fuzzer to set up fuzzer targets 2017-08-31 00:36:33 +00:00
llvm-bcanalyzer Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-c-test [LLVM-C] Move DIBuilder Bindings For Block Scopes 2018-04-07 06:07:55 +00:00
llvm-cat Pass a reference to a module to the bitcode writer. 2018-02-14 19:11:32 +00:00
llvm-cfi-verify Fix broken builds due to mismatched min/max types 2018-02-02 00:07:14 +00:00
llvm-config [tools] Change std::sort to llvm::sort in response to r327219 2018-04-01 21:24:53 +00:00
llvm-cov Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-cvtres Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-cxxdump Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-cxxfilt Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-demangle-fuzzer llvm-demangle-fuzzer: Link in Support 2017-11-17 20:46:55 +00:00
llvm-diff Let llvm-diff correctly deal with Undef/ConstantAggregateZero/ConstantVector/IndirectBr 2018-04-12 21:28:04 +00:00
llvm-dis Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-dwarfdump Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-dwp Rename *CommandFlags.def to *CommandFlags.inc 2018-04-11 18:49:37 +00:00
llvm-exegesis [llvm-exegesis] Fix use after free. 2018-04-13 14:46:48 +00:00
llvm-extract Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-go Update some code.google.com links 2017-11-13 23:47:58 +00:00
llvm-isel-fuzzer Rename *CommandFlags.def to *CommandFlags.inc 2018-04-11 18:49:37 +00:00
llvm-jitlistener Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-link Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-lto Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-lto2 Rename *CommandFlags.def to *CommandFlags.inc 2018-04-11 18:49:37 +00:00
llvm-mc Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-mc-assemble-fuzzer Rename *CommandFlags.def to *CommandFlags.inc 2018-04-11 18:49:37 +00:00
llvm-mc-disassemble-fuzzer cmake: Invent add_llvm_fuzzer to set up fuzzer targets 2017-08-31 00:36:33 +00:00
llvm-mca Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-modextract Pass a reference to a module to the bitcode writer. 2018-02-14 19:11:32 +00:00
llvm-mt Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-nm Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-objcopy Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-objdump Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-opt-fuzzer Rename *CommandFlags.def to *CommandFlags.inc 2018-04-11 18:49:37 +00:00
llvm-opt-report Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-pdbutil Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-profdata Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-rc Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-readobj Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-rtdyld Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-shlib Rename llvm library from libLLVM-X.Y to libLLVM-X 2018-03-29 09:44:09 +00:00
llvm-size Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-special-case-list-fuzzer [llvm-special-case-list-fuzzer] Add fuzz target. 2017-10-17 17:43:34 +00:00
llvm-split Pass a reference to a module to the bitcode writer. 2018-02-14 19:11:32 +00:00
llvm-stress [Support] Rename tool_output_file to ToolOutputFile, NFC 2017-09-23 01:03:17 +00:00
llvm-strings Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-symbolizer Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-xray [tools] Change std::sort to llvm::sort in response to r327219 2018-04-01 21:24:53 +00:00
lto Rename *CommandFlags.def to *CommandFlags.inc 2018-04-11 18:49:37 +00:00
msbuild Create msbuild only when using MSVC 2017-03-16 20:24:14 +00:00
obj2yaml Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
opt [DebugInfo][OPT] Fixing a couple of DI duplication bugs of CloneModule 2018-04-13 21:22:24 +00:00
opt-viewer [opt-viewer] Kill parser processes before moving onto rendering 2018-02-26 21:15:51 +00:00
sancov Remove redundant includes from tools. 2017-12-13 21:31:10 +00:00
sanstats Fix broken links to the Itanium CXX ABI 2017-09-12 00:19:11 +00:00
verify-uselistorder Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
xcode-toolchain [llvm] Add stripped installation targets 2017-11-30 21:48:26 +00:00
yaml2obj Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
CMakeLists.txt Fixup r271533, or check-clang didn't find llvm-lto as the target. 2016-06-02 20:39:24 +00:00
LLVMBuild.txt Re-land r329156 "Add llvm-exegesis tool." 2018-04-04 11:37:06 +00:00