[PATCH] D67154: MCRegisterInfo: Merge getLLVMRegNum and getLLVMRegNumFromEH

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 05:06:59 PDT 2019


labath created this revision.
labath added reviewers: dsanders, arsenm, JDevlieghere.
Herald added subscribers: javed.absar, aprantl, wdng.
Herald added a project: LLVM.

The functions different in two ways:

- getLLVMRegNum could return both "eh" and "other" dwarf register numbers, while getLLVMRegNumFromEH only returned the "eh" number.
- getLLVMRegNum asserted if the register was not found, while the second function returned -1.

The second distinction was pretty important, but it was very hard to
infer that from the function name. Aditionally, for the use case of
dumping dwarf expressions, we needed a function which can work with both
kinds of number, but does not assert.

This patch solves both of these issues by merging the two functions into
one, returning an Optional<unsigned> value. While the same thing could
be achieved by adding an "IsEH" argument to the (renamed)
getLLVMRegNumFromEH function, it seemed better to avoid the confusion of
two functions and put the choice of asserting into the hands of the
caller -- if he checks the Optional value, he can safely process
"untrusted" input, and if he blindly dereferences the Optional, he gets
the assertion.

I've updated all call sites to the new API, choosing between the two
options according to the function they were calling originally, except
that I've updated the usage in DWARFExpression.cpp to use the "safe"
method instead, and added a test case which would have previously
triggered an assertion failure when processing (incorrect?) dwarf
expressions.


Repository:
  rL LLVM

https://reviews.llvm.org/D67154

Files:
  include/llvm/MC/MCRegisterInfo.h
  lib/CodeGen/MachineOperand.cpp
  lib/CodeGen/StackMaps.cpp
  lib/DebugInfo/DWARF/DWARFExpression.cpp
  lib/MC/MCAsmStreamer.cpp
  lib/MC/MCRegisterInfo.cpp
  lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
  lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
  lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
  test/DebugInfo/X86/dwarfdump-debug-loc-error-cases.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67154.218653.patch
Type: text/x-patch
Size: 11245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190904/dd0b54c9/attachment.bin>


More information about the llvm-commits mailing list