aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-03-14 09:50:23 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2018-03-14 09:50:23 +0100
commitbe9dd15c70d45088a48e6f5d3e0967798ade096e (patch)
treef4f3711ee363640386969022eb05acdb40fd2237 /gcc
parent2062c40cb5deeea3ef964c7f5bb8a48b3d38831e (diff)
downloadgcc-be9dd15c70d45088a48e6f5d3e0967798ade096e.zip
gcc-be9dd15c70d45088a48e6f5d3e0967798ade096e.tar.gz
gcc-be9dd15c70d45088a48e6f5d3e0967798ade096e.tar.bz2
re PR sanitizer/83392 (FAIL: c-c++-common/ubsan/ptr-overflow-sanitization-1.c scan-tree-dump-times)
PR sanitizer/83392 * sanopt.c (maybe_optimize_ubsan_ptr_ifn): Handle also INTEGER_CST offset, add it together with bitpos / 8 and sign extend based on POINTER_SIZE. * c-c++-common/ubsan/ptr-overflow-sanitization-1.c: Adjust expected check count from 17 to 14. From-SVN: r258516
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/sanopt.c13
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/ptr-overflow-sanitization-1.c8
4 files changed, 22 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3e174c5..0bfc201 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,10 @@
2018-03-14 Jakub Jelinek <jakub@redhat.com>
+ PR sanitizer/83392
+ * sanopt.c (maybe_optimize_ubsan_ptr_ifn): Handle also
+ INTEGER_CST offset, add it together with bitpos / 8 and
+ sign extend based on POINTER_SIZE.
+
PR target/84844
Revert
2017-04-20 Uros Bizjak <ubizjak@gmail.com>
diff --git a/gcc/sanopt.c b/gcc/sanopt.c
index 4374313..116bc38 100644
--- a/gcc/sanopt.c
+++ b/gcc/sanopt.c
@@ -486,12 +486,17 @@ maybe_optimize_ubsan_ptr_ifn (sanopt_ctx *ctx, gimple *stmt)
HOST_WIDE_INT bitpos;
base = get_inner_reference (base, &bitsize, &pbitpos, &offset, &mode,
&unsignedp, &reversep, &volatilep);
- if (offset == NULL_TREE
+ if ((offset == NULL_TREE || TREE_CODE (offset) == INTEGER_CST)
&& DECL_P (base)
&& pbitpos.is_constant (&bitpos))
{
gcc_assert (!DECL_REGISTER (base));
- offset_int expr_offset = bitpos / BITS_PER_UNIT;
+ offset_int expr_offset;
+ if (offset)
+ expr_offset = wi::to_offset (offset) + bitpos / BITS_PER_UNIT;
+ else
+ expr_offset = bitpos / BITS_PER_UNIT;
+ expr_offset = wi::sext (expr_offset, POINTER_SIZE);
offset_int total_offset = expr_offset + cur_offset;
if (total_offset != wi::sext (total_offset, POINTER_SIZE))
{
@@ -511,7 +516,7 @@ maybe_optimize_ubsan_ptr_ifn (sanopt_ctx *ctx, gimple *stmt)
&& (!is_global_var (base) || decl_binds_to_current_def_p (base)))
{
offset_int base_size = wi::to_offset (DECL_SIZE_UNIT (base));
- if (bitpos >= 0
+ if (!wi::neg_p (expr_offset)
&& wi::les_p (total_offset, base_size))
{
if (!wi::neg_p (total_offset)
@@ -532,7 +537,7 @@ maybe_optimize_ubsan_ptr_ifn (sanopt_ctx *ctx, gimple *stmt)
*/
bool sign_cur_offset = !wi::neg_p (cur_offset);
- bool sign_expr_offset = bitpos >= 0;
+ bool sign_expr_offset = !wi::neg_p (expr_offset);
tree base_addr
= build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (base)), base);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 215e302..a86d8cc 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2018-03-14 Jakub Jelinek <jakub@redhat.com>
+ PR sanitizer/83392
+ * c-c++-common/ubsan/ptr-overflow-sanitization-1.c: Adjust expected
+ check count from 17 to 14.
+
PR target/84844
* gcc.target/i386/pr84844.c: New test.
diff --git a/gcc/testsuite/c-c++-common/ubsan/ptr-overflow-sanitization-1.c b/gcc/testsuite/c-c++-common/ubsan/ptr-overflow-sanitization-1.c
index c12c7df..14569d5 100644
--- a/gcc/testsuite/c-c++-common/ubsan/ptr-overflow-sanitization-1.c
+++ b/gcc/testsuite/c-c++-common/ubsan/ptr-overflow-sanitization-1.c
@@ -25,9 +25,9 @@ void foo(void)
p2 = p + 2;
p = b - SMAX; /* pointer overflow check is needed */
- p2 = p + (SMAX - 2); /* b - 2: pointer overflow check is needed */
- p2 = p + (SMAX - 1); /* b - 1: pointer overflow check is needed */
- p2 = p + SMAX; /* b: pointer overflow check is needed */
+ p2 = p + (SMAX - 2); /* b - 2: no need to check this */
+ p2 = p + (SMAX - 1); /* b - 1: no need to check this */
+ p2 = p + SMAX; /* b: no need to check this */
p2++; /* b + 1 */
p = c;
@@ -75,4 +75,4 @@ void negative_to_negative (char *ptr)
p2 += 5;
}
-/* { dg-final { scan-tree-dump-times "__ubsan_handle_pointer_overflow" 17 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "__ubsan_handle_pointer_overflow" 14 "optimized" } } */