Avoid array-bounds warning in testsuite on i586

Message ID mvm60ssicqy.fsf@hawking.suse.de
State New, archived
Headers

Commit Message

Andreas Schwab June 29, 2016, 9:08 a.m. UTC
  gcc-6 is complaining about this, breaking the testsuite run:

In file included from ../string/string.h:627:0,
                 from ../include/string.h:54,
                 from tester.c:32,
                 from inl-tester.c:6:
tester.c: In function 'test_strncat':
../sysdeps/x86/bits/string.h:1092:3: error: array subscript is below array bounds [-Werror=array-bounds]
   --__tmp;
   ^~~~~~~

I don't see any other way to avoid the warning.

Andreas.

	[BZ #20260]
	* sysdeps/i386/Makefile (CFLAGS-inl-tester.c): Define.
	* string/Makefile (CFLAGS-inl-tester.c, CFLAGS-noinl-tester.c)
	(CFLAGS-tst-strlen.c, CFLAGS-stratcliff.c, CFLAGS-test-ffs.c)
	(CFLAGS-tst-inlcall.c): Append value.
---
 string/Makefile       | 12 ++++++------
 sysdeps/i386/Makefile |  4 ++++
 2 files changed, 10 insertions(+), 6 deletions(-)
  

Comments

Florian Weimer June 29, 2016, 11:32 a.m. UTC | #1
On 06/29/2016 11:08 AM, Andreas Schwab wrote:
> gcc-6 is complaining about this, breaking the testsuite run:
>
> In file included from ../string/string.h:627:0,
>                  from ../include/string.h:54,
>                  from tester.c:32,
>                  from inl-tester.c:6:
> tester.c: In function 'test_strncat':
> ../sysdeps/x86/bits/string.h:1092:3: error: array subscript is below array bounds [-Werror=array-bounds]
>    --__tmp;
>    ^~~~~~~
>
> I don't see any other way to avoid the warning.

We could move the decrement operation into the assembly part, where GCC 
cannot see it.  Or we could cast to uintptr_t before subtracting 1.

> +# Suppress array bounds warning from strncat macro in
> +# sysdeps/x86/bits/string.h when building for i[345]86
> +CFLAGS-inl-tester.c += -Wno-array-bounds

It's triggered by an installed header, so this does not fix the bug at 
all.  I expect applications run into the warning as well.

Thanks,
Florian
  
Andreas Schwab June 29, 2016, 11:58 a.m. UTC | #2
Florian Weimer <fweimer@redhat.com> writes:

> It's triggered by an installed header, so this does not fix the bug at
> all.  I expect applications run into the warning as well.

Only if compiled with -Wsystem-headers.

Andreas.
  
Florian Weimer June 29, 2016, 12:04 p.m. UTC | #3
On 06/29/2016 01:58 PM, Andreas Schwab wrote:
> Florian Weimer <fweimer@redhat.com> writes:
>
>> It's triggered by an installed header, so this does not fix the bug at
>> all.  I expect applications run into the warning as well.
>
> Only if compiled with -Wsystem-headers.

I would expect that this could trip ubsan as well.

Florian
  

Patch

diff --git a/string/Makefile b/string/Makefile
index 9c87419..48a0e85 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -64,12 +64,12 @@  endif
 
 include ../Rules
 
-CFLAGS-inl-tester.c = -fno-builtin
-CFLAGS-noinl-tester.c = -fno-builtin
-CFLAGS-tst-strlen.c = -fno-builtin
-CFLAGS-stratcliff.c = -fno-builtin
-CFLAGS-test-ffs.c = -fno-builtin
-CFLAGS-tst-inlcall.c = -fno-builtin
+CFLAGS-inl-tester.c += -fno-builtin
+CFLAGS-noinl-tester.c += -fno-builtin
+CFLAGS-tst-strlen.c += -fno-builtin
+CFLAGS-stratcliff.c += -fno-builtin
+CFLAGS-test-ffs.c += -fno-builtin
+CFLAGS-tst-inlcall.c += -fno-builtin
 
 ifeq ($(run-built-tests),yes)
 $(objpfx)tst-svc-cmp.out: tst-svc.expect $(objpfx)tst-svc.out
diff --git a/sysdeps/i386/Makefile b/sysdeps/i386/Makefile
index 6c91842..a0e80a9 100644
--- a/sysdeps/i386/Makefile
+++ b/sysdeps/i386/Makefile
@@ -7,6 +7,10 @@  long-double-fcts = yes
 
 ifeq ($(subdir),string)
 sysdep_routines += cacheinfo
+
+# Suppress array bounds warning from strncat macro in
+# sysdeps/x86/bits/string.h when building for i[345]86
+CFLAGS-inl-tester.c += -Wno-array-bounds
 endif
 
 ifeq ($(subdir),gmon)