[PATCH] D50909: [PSV] Make the API for TargetCustom values not trigger UB

Marcello Maggioni via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 17 10:17:00 PDT 2018


kariddi created this revision.
kariddi added reviewers: tstellar, arsenm, yaxunl.
Herald added subscribers: llvm-commits, nhaehnle, wdng.

Hi,

this patch tries to fix a problem with the API for TargetCustom PseudoSourceValue types that is currently exhibiting UB if you try to use it in the intended way with more than 1 PseudoSourceValue custom kind.

How the API is intended to be used (by looking at getTargetCustom() or the printCustom() method) is that passing a value >= PSVKind::TargetCustom as the "Kind" parameter of the PseudoSourceValue constructor is a way to specify that our PSV is of a custom kind. So, if you have 2 different custom PSV types you should pass as the Kind parameter for the first one PSVKind::TargetCustom and for the second on "PSVKind::TargetCustom+1"

getTargetCustom() will return 0 if the PSV is not custom, 1 if it is the first custom PSV, 2 if it is the second

The problem is that PSVKind::TargetCustom+1 is not an entry of the PSVKind enum and passing that as a value to the constructor is theoretically undefined behavior and is reported as such by the UB sanitizer.

This results in the fact that having more than 1 PSV custom kind is actually not possible without triggering UB.

This patch tries to address it to use "unsigned" (the underlying value of the enum) to store and pass around the Kind instead of the PSVKind enum type.

This patch is NFC otherwise


Repository:
  rL LLVM

https://reviews.llvm.org/D50909

Files:
  include/llvm/CodeGen/PseudoSourceValue.h
  include/llvm/CodeGen/TargetInstrInfo.h
  lib/CodeGen/PseudoSourceValue.cpp
  lib/Target/AMDGPU/R600InstrInfo.cpp
  lib/Target/AMDGPU/R600InstrInfo.h
  lib/Target/AMDGPU/SIInstrInfo.cpp
  lib/Target/AMDGPU/SIInstrInfo.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50909.161283.patch
Type: text/x-patch
Size: 4586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180817/dbd6896e/attachment.bin>


More information about the llvm-commits mailing list