[PATCH] D86299: [compiler-rt][builtins] Factor out some common bit manipulations

Anatoly Trosinenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 20 08:52:32 PDT 2020


atrosinenko created this revision.
atrosinenko added reviewers: howard.hinnant, jfb, vsk, lebedev.ri.
Herald added subscribers: Sanitizers, dexonsmith, dberris.
Herald added a project: Sanitizers.
atrosinenko requested review of this revision.

This patch incapsulates some commonly used hacks in a (hopefully) UB-free manner.

Some existing LibCall implementations contain constants like this one:

  const di_int MIN = (di_int)1 << ((int)(sizeof(di_int) * CHAR_BIT) - 1);

UBSan complains on such expressions and that seems to be true positive.

This patch is expected to be NFC except for eliminating some UB. It consists of the following parts:

- implementing helpers in `int_types.h`
- replacing some `typedef`s with `#define`s so these type alises can be handled by the above machinery
- replacing some constants with these common helper invocations
  - this is expected to be unable to cause any performance regressions as these are actually **compile-time** constants
- fixing a couple of UBs in `__neg?i2` LibCalls


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86299

Files:
  compiler-rt/lib/builtins/fixdfdi.c
  compiler-rt/lib/builtins/fixdfsi.c
  compiler-rt/lib/builtins/fixdfti.c
  compiler-rt/lib/builtins/fixsfdi.c
  compiler-rt/lib/builtins/fixsfsi.c
  compiler-rt/lib/builtins/fixsfti.c
  compiler-rt/lib/builtins/fixtfdi.c
  compiler-rt/lib/builtins/fixtfsi.c
  compiler-rt/lib/builtins/fixtfti.c
  compiler-rt/lib/builtins/fp_fixint_impl.inc
  compiler-rt/lib/builtins/int_mulo_impl.inc
  compiler-rt/lib/builtins/int_mulv_impl.inc
  compiler-rt/lib/builtins/int_types.h
  compiler-rt/lib/builtins/negdi2.c
  compiler-rt/lib/builtins/negti2.c
  compiler-rt/lib/builtins/negvdi2.c
  compiler-rt/lib/builtins/negvsi2.c
  compiler-rt/lib/builtins/negvti2.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86299.286833.patch
Type: text/x-patch
Size: 10563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200820/f84e83ba/attachment-0001.bin>


More information about the cfe-commits mailing list