]> granicus.if.org Git - clang/commit
[ubsan] Skip overflow checks on safe arithmetic (fixes PR32874)
authorVedant Kumar <vsk@apple.com>
Tue, 2 May 2017 23:46:56 +0000 (23:46 +0000)
committerVedant Kumar <vsk@apple.com>
Tue, 2 May 2017 23:46:56 +0000 (23:46 +0000)
commit424867959dc6688bd83a448daa8560360b485ffd
tree13fda5f766b3a136df20f2699dbc9af876caed1a
parente28cd553dd99aba7921c3e39740ada1b1166c9d9
[ubsan] Skip overflow checks on safe arithmetic (fixes PR32874)

Currently, ubsan emits overflow checks for arithmetic that is known to
be safe at compile-time, e.g:

  1 + 1 => CheckedAdd(1, 1)

This leads to breakage when using the __builtin_prefetch intrinsic. LLVM
expects the arguments to @llvm.prefetch to be constant integers, and
when ubsan inserts unnecessary checks on the operands to the intrinsic,
this contract is broken, leading to verifier failures (see PR32874).

Instead of special-casing __builtin_prefetch for ubsan, this patch fixes
the underlying problem, i.e that clang currently emits unnecessary
overflow checks.

Testing: I ran the check-clang and check-ubsan targets with a stage2,
ubsan-enabled build of clang. I added a regression test for PR32874, and
some extra checking to make sure we don't regress runtime checking for
unsafe arithmetic. The existing ubsan-promoted-arithmetic.cpp test also
provides coverage for this change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301988 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGExprScalar.cpp
test/CodeGen/PR32874.c [new file with mode: 0644]