#include "pointer-query.h"
#include "tree-pretty-print.h"
#include "tree-ssanames.h"
+#include "target.h"
static bool compute_objsize_r (tree, int, access_ref *, ssa_name_limit_t &,
pointer_query *);
if (code == INTEGER_CST)
{
/* Pointer constants other than null are most likely the result
- of erroneous null pointer addition/subtraction. Set size to
- zero. For null pointers, set size to the maximum for now
- since those may be the result of jump threading. */
+ of erroneous null pointer addition/subtraction. Unless zero
+ is a valid address set size to zero. For null pointers, set
+ size to the maximum for now since those may be the result of
+ jump threading. */
if (integer_zerop (ptr))
pref->set_max_size_range ();
+ else if (POINTER_TYPE_P (TREE_TYPE (ptr)))
+ {
+ tree deref_type = TREE_TYPE (TREE_TYPE (ptr));
+ addr_space_t as = TYPE_ADDR_SPACE (deref_type);
+ if (targetm.addr_space.zero_address_valid (as))
+ pref->set_max_size_range ();
+ else
+ pref->sizrng[0] = pref->sizrng[1] = 0;
+ }
else
pref->sizrng[0] = pref->sizrng[1] = 0;
+
pref->ref = ptr;
return true;
/* { dg-do compile } */
-/* { dg-options "-O" } */
+/* { dg-options "-O -Wall" } */
/* { dg-final { scan-assembler "fs:16" } } */
/* { dg-final { scan-assembler "gs:16" } } */
int test(void)
{
+ /* Also verify the accesses don't trigger warnings. */
int __seg_fs *f = (int __seg_fs *)16;
int __seg_gs *g = (int __seg_gs *)16;
return *f + *g;
--- /dev/null
+/* PR middle-end/102630 - Spurious -Warray-bounds with named address space
+ { dg-do compile }
+ { dg-options "-O -Wall" }
+ { dg-final { scan-assembler "fs:0" } }
+ { dg-final { scan-assembler "gs:0" } } */
+
+void test_fs_null_store (void)
+{
+ int __seg_fs *fs = (int __seg_fs *)0;
+ *fs = 1;
+}
+
+void test_gs_null_store (void)
+{
+ int __seg_gs *gs = (int __seg_gs *)0;
+ *gs = 2;
+}