On Tue, Oct 12, 2021 at 8:34 PM Siddhesh Poyarekar <siddh...@gotplt.org> wrote:
>
> The warning is falsely triggered for THREAD_SELF in glibc when
> accessing TCB through the segment register.

I think this is a more generic bug - the warning is also bogus if the
general address space is involved.

Martin?

> gcc/ChangeLog:
>
>         * gimple-array-bounds.cc
>         (array_bounds_checker::check_mem_ref): Bail out for
>         non-generic address spaces.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/i386/addr-space-3.c: New test case.
>
> Signed-off-by: Siddhesh Poyarekar <siddh...@gotplt.org>
> ---
>  gcc/gimple-array-bounds.cc                   | 3 +++
>  gcc/testsuite/gcc.target/i386/addr-space-3.c | 5 +++++
>  2 files changed, 8 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/i386/addr-space-3.c
>
> diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc
> index 0517e5ddd8e..36fc1dbe3f8 100644
> --- a/gcc/gimple-array-bounds.cc
> +++ b/gcc/gimple-array-bounds.cc
> @@ -432,6 +432,9 @@ array_bounds_checker::check_mem_ref (location_t location, 
> tree ref,
>    if (aref.offset_in_range (axssize))
>      return false;
>
> +  if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (axstype)))
> +    return false;
> +
>    if (TREE_CODE (aref.ref) == SSA_NAME)
>      {
>        gimple *def = SSA_NAME_DEF_STMT (aref.ref);
> diff --git a/gcc/testsuite/gcc.target/i386/addr-space-3.c 
> b/gcc/testsuite/gcc.target/i386/addr-space-3.c
> new file mode 100644
> index 00000000000..4bd940e696a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/addr-space-3.c
> @@ -0,0 +1,5 @@
> +/* Verify that __seg_fs/gs marked variables do not trigger an array bounds
> +   warning.  */
> +/* { dg-do compile */
> +/* { dg-options "-O2 -Warray-bounds" } */
> +#include "addr-space-2.c"
> --
> 2.31.1
>

Reply via email to