[all-commits] [llvm/llvm-project] f0bbda: [CodeGen] [ubsan] Respect integer overflow handlin...

Лабазов Артем Александрович via All-commits all-commits at lists.llvm.org
Mon Aug 21 09:13:41 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f0bbda00bd060919a548b97d564c5208312993a3
      https://github.com/llvm/llvm-project/commit/f0bbda00bd060919a548b97d564c5208312993a3
  Author: Artem Labazov <123321artyom at gmail.com>
  Date:   2023-08-21 (Mon, 21 Aug 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/CodeGen/CGBuiltin.cpp
    A clang/test/CodeGen/abs-overflow.c
    A compiler-rt/test/ubsan/TestCases/Misc/abs.cpp

  Log Message:
  -----------
  [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

Currenly both Clang and GCC support the following set of flags that control
code gen of signed overflow:

* -fwrapv: overflow is defined as in two-complement
* -ftrapv: overflow traps
* -fsanitize=signed-integer-overflow: if undefined (no -fwrapv), then overflow
  behaviour is controlled by UBSan runtime, overrides -ftrapv

Howerver, clang ignores these flags for __builtin_abs(int) and its higher-width
versions, so passing minimum integer value always causes poison.

The same holds for *abs(), which are not handled in frontend at all but folded
to llvm.abs.* intrinsics during InstCombinePass. The intrinsics are not
instrumented by UBSan, so the functions need special handling as well.

This patch does a few things:

* Handle *abs() in CGBuiltin the same way as __builtin_*abs()
* -fsanitize=signed-integer-overflow now properly instruments abs() with UBSan
* -fwrapv and -ftrapv handling for abs() is made consistent with GCC

Fixes #45129 and #45794

Reviewed By: efriedma, MaskRay

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




More information about the All-commits mailing list