[PATCH] D48958: [clang][ubsan] Implicit Cast Sanitizer - integer truncation - clang part

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 13 03:57:47 PDT 2018


lebedev.ri added a comment.

In https://reviews.llvm.org/D48958#1160853, @lebedev.ri wrote:

> In https://reviews.llvm.org/D48958#1160848, @vsk wrote:
>
> > <...>
> >  The stage2 build traps before it finishes:
> >
> >   FAILED: lib/IR/AttributesCompatFunc.inc.tmp
> >   cd /Users/vsk/src/builds/llvm.org-lldbsan-stage2-R/tools/clang/stage2-bins && /Users/vsk/src/builds/llvm.org-lldbsan-stage2-R/tools/clang/stage2-bins/bin/llvm-tblgen -gen-attrs -I /Users/vsk/src/llvm.org-lldbsan/llvm/lib/IR -I /Users/vsk/src/llvm.org-lldbsan/llvm/include /Users/vsk/src/llvm.org-lldbsan/llvm/lib/IR/AttributesCompatFunc.td -o lib/IR/AttributesCompatFunc.inc.tmp -d lib/IR/AttributesCompatFunc.inc.d
> >   /Users/vsk/src/llvm.org-lldbsan/llvm/include/llvm/ADT/DenseMap.h:732:66: runtime error: implicit cast from type 'uint64_t' (aka 'unsigned long long') of value 4294967296 (64-bit, unsigned) to type 'unsigned int' changed the value to 0 (32-bit, unsigned)
> >   /bin/sh: line 1: 96848 Abort trap: 6
> >
> >
> > This looks like a false positive to me. It's complaining about `static_cast<unsigned>(NextPowerOf2(...))`, but the static_cast is explicit.
>
>
> Good to know, so the stack-based logic for `ExplicitCastExpr` detection needs further tests/refinements..


creduced down to:

  template <typename a> a b(a c, const a &d) {
    if (d)
      ;
    return c;
  }
  int e = b<unsigned>(4, static_cast<unsigned>(4294967296));
  int main() {}

https://godbolt.org/g/1kwGk9

  $ ./a.out 
  test.cpp:6:46: runtime error: implicit cast from type 'long' of value 4294967296 (64-bit, signed) to type 'unsigned int' changed the value to 0 (32-bit, unsigned)
      #0 0x232f56 in _GLOBAL__sub_I_test.cpp (/home/lebedevri/CREDUCE/a.out+0x232f56)
      #1 0x232fbc in __libc_csu_init (/home/lebedevri/CREDUCE/a.out+0x232fbc)
      #2 0x7fa8c113aaa7 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x22aa7)
      #3 0x212029 in _start (/home/lebedevri/CREDUCE/a.out+0x212029)


Repository:
  rC Clang

https://reviews.llvm.org/D48958





More information about the cfe-commits mailing list