Hello. Even though the original test-case is slp target-specific, one can easily come up with a test-case which fails on arbitrary target. Problem is a register variable that is used wrongly in a function call that expects an address to be given. Fixed by not instrumenting such declarations.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. On x86_64-linux-gnu target ubsan.exp tests work. Ready to be installed? Martin
>From 87ce95625d97638a29efebdc0520599ce2379fbd Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Tue, 11 Apr 2017 09:58:19 +0200 Subject: [PATCH] Do not instrument register variables in object-size sanitizer (PR sanitizer/80387). gcc/ChangeLog: 2017-04-11 Martin Liska <mli...@suse.cz> PR sanitizer/80387 * ubsan.c (instrument_object_size): Do not instrument register variables. gcc/testsuite/ChangeLog: 2017-04-11 Martin Liska <mli...@suse.cz> PR sanitizer/80387 * gcc.dg/ubsan/pr70878.c: New test. --- gcc/testsuite/gcc.dg/ubsan/pr70878.c | 9 +++++++++ gcc/ubsan.c | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/ubsan/pr70878.c diff --git a/gcc/testsuite/gcc.dg/ubsan/pr70878.c b/gcc/testsuite/gcc.dg/ubsan/pr70878.c new file mode 100644 index 00000000000..15b54e244fc --- /dev/null +++ b/gcc/testsuite/gcc.dg/ubsan/pr70878.c @@ -0,0 +1,9 @@ +/* PR sanitizer/80878 */ +/* { dg-do compile { target { x86_64-*-* } } } */ +/* { dg-options "-fsanitize=object-size" } */ + +void * sbrk () +{ + volatile register unsigned int sp_r1 __asm__ ("ebx"); + return __builtin_strcat ((char*)sp_r1, 0); /* { dg-warning "cast to pointer from integer of different size" } */ +} diff --git a/gcc/ubsan.c b/gcc/ubsan.c index 323c1ccdb49..c01d63318c2 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -1806,7 +1806,11 @@ instrument_object_size (gimple_stmt_iterator *gsi, bool is_lhs) bool decl_p = DECL_P (inner); tree base; if (decl_p) - base = inner; + { + if (DECL_REGISTER (inner)) + return; + base = inner; + } else if (TREE_CODE (inner) == MEM_REF) base = TREE_OPERAND (inner, 0); else -- 2.12.2