[DebugInfo] Check size of variable in ConvertDebugDeclareToDebugValue
authorBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Thu, 14 Jun 2018 11:23:42 +0000 (11:23 +0000)
committerBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Thu, 14 Jun 2018 11:23:42 +0000 (11:23 +0000)
commite406b29c2295b8d41ebb084ee0dd79f87bcf16fa
tree21f2ae4376ec1058b86dd2b0ba8008ab6a1b30ac
parent1bbab1e558523e8a3acce350250fc85819a7ebf3
[DebugInfo] Check size of variable in ConvertDebugDeclareToDebugValue

Summary:
Do not convert a DbgDeclare to DbgValue if the store
instruction only refer to a fragment of the variable
described by the DbgDeclare.

Problem was seen when for example having an alloca for an
array or struct, and there were stores to individual elements.
In the past we inserted a DbgValue intrinsics for each store,
just as if the store wrote the whole variable.

When handling store instructions we insert a DbgValue that
indicates that the variable is "undefined", as we do not know
which part of the variable that is updated by the store.

When ConvertDebugDeclareToDebugValue is used with a load/phi
instruction we assert that the referenced value is large enough
to cover the whole variable. Afaict this should be true for all
scenarios where those methods are used on trunk. If the assert
blows in the future I guess we could simply skip to insert a
dbg.value instruction.

In the future I think we should examine which part of the variable
that is accessed, and add a DbgValue instrinsic with an appropriate
DW_OP_LLVM_fragment expression.

Reviewers: dblaikie, aprantl, rnk

Reviewed By: aprantl

Subscribers: JDevlieghere, llvm-commits

Tags: #debug-info

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

llvm-svn: 334704
llvm/include/llvm/IR/IntrinsicInst.h
llvm/lib/IR/IntrinsicInst.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/InstCombine/debuginfo.ll
llvm/test/Transforms/Mem2Reg/debug-alloca-phi-2.ll [new file with mode: 0644]