On 2/2/2022 7:42 AM, Richard Biener via Gcc-patches wrote:
This adds a flag to CONSTRUCTOR nodes indicating that for
clobbers this marks the end-of-life of storage as opposed to
just ending the lifetime of the object that occupied it.
The dangling pointer diagnostics uses CLOBBERs but is confused
by those emitted by the C++ frontend for example which emits
them for the second purpose at the start of CTORs.  The issue
is also appearant for aarch64 in PR104092.

Distinguishing the two cases is also necessary for the PR90348 fix.

Bootstrapped and tested on x86_64-unknown-linux-gnu.  I verified
the bogus diagnostic in PR104092 is gone with a cross.

OK for trunk?

Thanks,
Richard.

2022-02-02  Richard Biener  <rguent...@suse.de>

        PR middle-end/90348
        PR middle-end/104092
        * tree-core.h: Document protected_flag use on CONSTRUCTOR nodes.
        * tree.h (CLOBBER_MARKS_EOL): Add.
        * tree-pretty-print.cc (dump_generic_node): Mark EOL CLOBBERs.
        * gimplify.c (gimplify_bind_expr): Mark storage end-of-life clobbers
        with CLOBBER_MARKS_EOL.
        (gimplify_target_expr): Likewise.
        * tree-inline.cc (expand_call_inline): Likewise.
        * tree-ssa-ccp.cc (insert_clobber_before_stack_restore): Likewise.
        * gimple-ssa-warn-access.cc (pass_waccess::check_stmt): Only treat
        CLOBBER_MARKS_EOL clobbers as ending lifetime of storage.

        * gcc.dg/pr87052.c: Adjust.
OK.   Note that I think something similar may be needed to mark EOL for the pointer passed to realloc to fix a related set of false positives for code like this

  bool something = p != q;
  whatever = realloc (p, newsize)
  if (something)

We forward propagate the p != q test generating something like this;

  whatever - realloc (p, newsize);
  if (p != q)

Which triggers a warning even though the original source was reasonable.  I think a well placed clobber of p should expose the dataflow necessary to prevent the propagation and ultimately avoid the false positive.  IIRC something like this came up in glibc and/or gnulib.

I realize it's not exactly the same, but they're reasonably closely related.

jeff

Reply via email to