[PATCH] D67263: [DwarfExpression] Disallow some rewrites to avoid undefined behavior

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 6 04:47:17 PDT 2019


bjope created this revision.
bjope added reviewers: sdesmalen, rnk, JDevlieghere.
bjope added a project: debug-info.
Herald added subscribers: ychen, hiraditya, aprantl.
Herald added a project: LLVM.

The value operand in DW_OP_plus_uconst/DW_OP_constu value can be
large (it uses uint64_t as representation internally in LLVM).
This means that in the uint64_t to int conversions, previously done
by DwarfExpression::addMachineRegExpression, could lose information.
Also, the negation done in "-Offset" was undefined behavior in case
Offset was exactly INT_MIN.

To avoid the above problems, we now avoid transformation like
 [Reg, DW_OP_plus_uconst, Offset] --> [DW_OP_breg, Offset]
and
 [Reg, DW_OP_constu, Offset, DW_OP_plus]  --> [DW_OP_breg, Offset]
when Offset > INT_MAX.

And we avoid to transform
 [Reg, DW_OP_constu, Offset, DW_OP_minus] --> [DW_OP_breg,-Offset]
when Offset > INT_MAX+1.

The patch also adjusts DwarfCompileUnit::constructVariableDIEImpl
to make sure that "DW_OP_constu, Offset, DW_OP_minus" is used
instead of "DW_OP_plus_uconst, Offset" when creating DIExpressions
with negative frame index offsets.

Notice that this might just be the tip of the iceberg. There
are lots of fishy handling related to these constants. I think both
DIExpression::appendOffset and DIExpression::extractIfOffset may
trigger undefined behavior for certain values.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67263

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
  llvm/test/DebugInfo/X86/dw_op_constu.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67263.219062.patch
Type: text/x-patch
Size: 16663 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190906/6640325b/attachment-0001.bin>


More information about the llvm-commits mailing list