llvm-project/llvm/lib/Transforms/Instrumentation
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
..
AddressSanitizer.cpp PR32382: Fix emitting complex DWARF expressions. 2017-04-18 01:21:53 +00:00
BoundsChecking.cpp Apply clang-tidy's modernize-loop-convert to most of lib/Transforms. 2016-06-26 12:28:59 +00:00
CFGMST.h [PGO] Fix PGO use ICE when there are unreachable BBs 2016-12-02 19:10:29 +00:00
CMakeLists.txt [CMake] NFC. Updating CMake dependency specifications 2016-11-17 04:36:50 +00:00
DataFlowSanitizer.cpp Allow DataLayout to specify addrspace for allocas. 2017-04-10 22:27:50 +00:00
EfficiencySanitizer.cpp Module::getOrInsertFunction is using C-style vararg instead of variadic templates. 2017-04-11 15:01:18 +00:00
GCOVProfiling.cpp Use StringRef in Pass/PassManager APIs (NFC) 2016-10-01 02:56:57 +00:00
IndirectCallPromotion.cpp [PGO] Preserve GlobalsAA in pgo-memop-opt pass. 2017-04-06 20:56:00 +00:00
InstrProfiling.cpp [ProfileData] Unify getInstrProf*SectionName helpers 2017-04-15 00:09:57 +00:00
Instrumentation.cpp [PGO] Memory intrinsic calls optimization based on profiled size 2017-04-04 16:42:20 +00:00
LLVMBuild.txt [PGO] Resubmit "MST based PGO instrumentation infrastructure" (r254021) 2015-12-09 18:08:16 +00:00
MaximumSpanningTree.h
MemorySanitizer.cpp [IR] Make paramHasAttr to use arg indices instead of attr indices 2017-04-14 20:19:02 +00:00
PGOInstrumentation.cpp [PGO] Memory intrinsic calls optimization based on profiled size 2017-04-04 16:42:20 +00:00
SanitizerCoverage.cpp Module::getOrInsertFunction is using C-style vararg instead of variadic templates. 2017-04-11 15:01:18 +00:00
ThreadSanitizer.cpp [ProfileData] Unify getInstrProf*SectionName helpers 2017-04-15 00:09:57 +00:00