llvm-project/llvm/lib/Transforms/Utils
Adrian Prantl 6825fb64e9 PR32382: Fix emitting complex DWARF expressions.
The DWARF specification knows 3 kinds of non-empty simple location
descriptions:
1. Register location descriptions
  - describe a variable in a register
  - consist of only a DW_OP_reg
2. Memory location descriptions
  - describe the address of a variable
3. Implicit location descriptions
  - describe the value of a variable
  - end with DW_OP_stack_value & friends

The existing DwarfExpression code is pretty much ignorant of these
restrictions. This used to not matter because we only emitted very
short expressions that we happened to get right by accident.  This
patch makes DwarfExpression aware of the rules defined by the DWARF
standard and now chooses the right kind of location description for
each expression being emitted.

This would have been an NFC commit (for the existing testsuite) if not
for the way that clang describes captured block variables. Based on
how the previous code in LLVM emitted locations, DW_OP_deref
operations that should have come at the end of the expression are put
at its beginning. Fixing this means changing the semantics of
DIExpression, so this patch bumps the version number of DIExpression
and implements a bitcode upgrade.

There are two major changes in this patch:

I had to fix the semantics of dbg.declare for describing function
arguments. After this patch a dbg.declare always takes the *address*
of a variable as the first argument, even if the argument is not an
alloca.

When lowering a DBG_VALUE, the decision of whether to emit a register
location description or a memory location description depends on the
MachineLocation — register machine locations may get promoted to
memory locations based on their DIExpression. (Future) optimization
passes that want to salvage implicit debug location for variables may
do so by appending a DW_OP_stack_value. For example:
  DBG_VALUE, [RBP-8]                        --> DW_OP_fbreg -8
  DBG_VALUE, RAX                            --> DW_OP_reg0 +0
  DBG_VALUE, RAX, DIExpression(DW_OP_deref) --> DW_OP_reg0 +0

All testcases that were modified were regenerated from clang. I also
added source-based testcases for each of these to the debuginfo-tests
repository over the last week to make sure that no synchronized bugs
slip in. The debuginfo-tests compile from source and run the debugger.

https://bugs.llvm.org/show_bug.cgi?id=32382
<rdar://problem/31205000>

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

llvm-svn: 300522
2017-04-18 01:21:53 +00:00
..
ASanStackFrameLayout.cpp [asan] Replace std::to_string with llvm::to_string 2016-10-19 00:16:56 +00:00
AddDiscriminators.cpp [AddDiscriminators] Assign discriminators to MemIntrinsic calls. 2017-04-11 19:07:30 +00:00
BasicBlockUtils.cpp [BasicBlockUtils] Check for nullptr before updating LoopInfo. 2017-03-06 15:33:05 +00:00
BreakCriticalEdges.cpp [PM] Port BreakCriticalEdges to the new PM. 2016-07-22 18:04:25 +00:00
BuildLibCalls.cpp Module::getOrInsertFunction is using C-style vararg instead of variadic templates. 2017-04-11 15:01:18 +00:00
BypassSlowDivision.cpp [BypassSlowDivision] Do not bypass division of hash-like values 2017-04-02 13:14:30 +00:00
CMakeLists.txt MemorySSA: Move to Analysis, from Transforms/Utils. It's used as 2017-04-11 20:06:36 +00:00
CloneFunction.cpp [IR] Make getParamAttributes take argument numbers, not ArgNo+1 2017-04-13 23:12:13 +00:00
CloneModule.cpp Cloning: Copy comdats when cloning globals. 2017-01-18 20:02:31 +00:00
CmpInstAnalysis.cpp move decomposeBitTestICmp() to Transforms/Utils; NFC 2016-07-20 17:18:45 +00:00
CodeExtractor.cpp Reland "[IR] Make AttributeSetNode public, avoid temporary AttributeList copies" 2017-04-10 23:31:05 +00:00
CtorUtils.cpp [CtorUtils] Modernize. No functional changes intended. 2016-10-22 01:21:24 +00:00
DemoteRegToStack.cpp Allow DataLayout to specify addrspace for allocas. 2017-04-10 22:27:50 +00:00
EscapeEnumerator.cpp [tsan] Add support for C++ exceptions into TSan (call __tsan_func_exit during unwinding), LLVM part 2016-11-14 21:41:13 +00:00
Evaluator.cpp [IR] Redesign the case iterator in SwitchInst to actually be an iterator 2017-04-12 07:27:28 +00:00
FlattenCFG.cpp [FlattenCFG] Simplify + remove unused variable. NFCI. 2016-08-05 20:53:35 +00:00
FunctionComparator.cpp Rename AttributeSet to AttributeList 2017-03-21 16:57:19 +00:00
FunctionImportUtils.cpp FunctionImport: Use IRMover directly. 2017-02-03 16:56:27 +00:00
GlobalStatus.cpp [Transforms/Utils] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-01-14 00:32:38 +00:00
ImportedFunctionsInliningStatistics.cpp [ThinLTO] Correct counting of functions in inliner stats 2017-03-24 17:59:06 +00:00
InlineFunction.cpp Allow DataLayout to specify addrspace for allocas. 2017-04-10 22:27:50 +00:00
InstructionNamer.cpp Apply clang-tidy's modernize-loop-convert to most of lib/Transforms. 2016-06-26 12:28:59 +00:00
IntegerDivision.cpp
LCSSA.cpp [LCSSA] Don't insert tokens into the worklist at all. 2017-04-17 14:32:05 +00:00
LLVMBuild.txt
LibCallsShrinkWrap.cpp [Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC) 2017-01-23 23:16:46 +00:00
Local.cpp PR32382: Fix emitting complex DWARF expressions. 2017-04-18 01:21:53 +00:00
LoopSimplify.cpp [LoopSimplify] Simplify how we compute UniqueExit 2017-02-21 19:10:58 +00:00
LoopUnroll.cpp The patch turns on epilogue unroll for loops with constant recurency start. 2017-03-02 17:38:46 +00:00
LoopUnrollPeel.cpp [LoopPeeling] Get rid of Phis that become invariant after N steps 2017-04-17 09:52:02 +00:00
LoopUnrollRuntime.cpp [LoopUnroll] Use addClonedBlockToLoopInfo to clone the top level loop (NFC) 2017-01-31 11:13:44 +00:00
LoopUtils.cpp [LV] Fix the vector code generation for first order recurrence 2017-04-13 18:59:25 +00:00
LoopVersioning.cpp [LoopVersioning] Require loop-simplify form for loop versioning. 2016-12-19 17:13:37 +00:00
LowerInvoke.cpp [PM] Port LowerInvoke to the new pass manager 2016-08-12 17:28:27 +00:00
LowerMemIntrinsics.cpp NVPTX: Extract mem intrinsic expansions into utilities 2017-02-08 17:49:52 +00:00
LowerSwitch.cpp [IR] Redesign the case iterator in SwitchInst to actually be an iterator 2017-04-12 07:27:28 +00:00
Mem2Reg.cpp [Mem2Reg] Remove AliasSetTracker updating logic from the pass. 2017-04-09 20:47:14 +00:00
MetaRenamer.cpp [MetaRenamer] Don't rename library functions. 2017-03-23 23:21:07 +00:00
ModuleUtils.cpp Revert "[asan] Fix dead stripping of globals on Linux." 2017-04-10 20:36:30 +00:00
NameAnonGlobals.cpp Use StringRef in Pass/PassManager APIs (NFC) 2016-10-01 02:56:57 +00:00
PredicateInfo.cpp Simplify the code and remove dead code 2017-04-11 08:21:27 +00:00
PromoteMemoryToRegister.cpp [Mem2Reg] Remove AliasSetTracker updating logic from the pass. 2017-04-09 20:47:14 +00:00
SSAUpdater.cpp [Target, Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-01-18 00:57:48 +00:00
SanitizerStats.cpp
SimplifyCFG.cpp [SimplifyCFG] Use hasNUses instead of comparing getNumUses to a constant." 2017-04-17 22:13:00 +00:00
SimplifyIndVar.cpp [SimplifyIndvar] Replace the sdiv used by IV if we can prove both of its operands are non-negative 2017-03-30 21:56:56 +00:00
SimplifyInstructions.cpp [ValueTracking] emit a remark when we detect a conflicting assumption (PR31809) 2017-02-06 18:26:06 +00:00
SimplifyLibCalls.cpp Module::getOrInsertFunction is using C-style vararg instead of variadic templates. 2017-04-11 15:01:18 +00:00
SplitModule.cpp Move instances of std::function. 2016-06-12 16:13:55 +00:00
StripGCRelocates.cpp [StripGCRelocates] New pass to remove gc.relocates added by RS4GC 2016-10-21 18:43:16 +00:00
StripNonLineTableDebugInfo.cpp Add -strip-nonlinetable-debuginfo capability 2016-10-25 18:44:13 +00:00
SymbolRewriter.cpp [PM] Port SymbolRewriter to the new PM 2016-07-25 20:52:00 +00:00
UnifyFunctionExitNodes.cpp Apply clang-tidy's modernize-loop-convert to most of lib/Transforms. 2016-06-26 12:28:59 +00:00
Utils.cpp MemorySSA: Move to Analysis, from Transforms/Utils. It's used as 2017-04-11 20:06:36 +00:00
VNCoercion.cpp Templatize parts of VNCoercion, and add constant-only versions of the functions to be used in NewGVN. 2017-03-20 16:08:29 +00:00
ValueMapper.cpp "Use" lambda captures which are otherwise only used in asserts. NFC 2017-01-13 21:02:41 +00:00