Bug 104092 - [12 Regression] Invalid -Wdangling-pointer warning after writes by calls
Summary: [12 Regression] Invalid -Wdangling-pointer warning after writes by calls
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: 12.0
Assignee: Richard Sandiford
Keywords: diagnostic
Depends on:
Blocks: Wdangling-pointer
  Show dependency treegraph
Reported: 2022-01-18 11:12 UTC by Richard Sandiford
Modified: 2022-02-04 08:09 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2022-01-18 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Richard Sandiford 2022-01-18 11:12:07 UTC
Compiling the following testcase with -march=armv8.2-a+sve -O2 -Wall:

#include <arm_sve.h>

svuint64_t bar(svbool_t pg, const uint64_t *addr) {
  return svget2(svld2_u64(pg, addr), 0);


foo.c:4:16: warning: using a dangling pointer to an unnamed temporary [-Wdangling-pointer=]
    4 |   return svget2(svld2_u64(pg, addr), 0);
      |          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foo.c:4:16: note: unnamed temporary defined here
    4 |   return svget2(svld2_u64(pg, addr), 0);
      |          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

This is because the code looks only at gassigns when tracking whether
a clobber has been overwritten, so it misses assignments by calls.

This seems to be different from PR104076.
Comment 1 Richard Sandiford 2022-01-18 11:12:26 UTC
Testing a patch.
Comment 2 CVS Commits 2022-02-04 07:17:12 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:


commit r12-7044-g551aa75778a4c5165d9533cd447c8fc822f583e1
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Feb 2 14:24:39 2022 +0100

    Add CLOBBER_EOL to mark storage end-of-life clobbers
    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.
    Since I'm going to add another flag I added an enum clobber_flags
    and a defaulted argument to build_clobber plus a convenient way to
    query the enum from the CTOR tree and specify it for gimple_clobber_p.
    Since 'CLOBBER' is already taken and I needed a name for the unspecified
    clobber we have now I used 'CLOBBER_UNDEF'.
    2022-02-03  Richard Biener  <rguenther@suse.de>
            PR middle-end/90348
            PR middle-end/104092
            * tree-core.h (clobber_kind): New enum.
            (tree_base::u::bits::address_space): Document use in CONSTRUCTORs.
            * tree.h (CLOBBER_KIND): Add.
            (build_clobber): Add clobber kind argument, defaulted to
            * tree.cc (build_clobber): Likewise.
            * gimple.h (gimple_clobber_p): New overload with specified kind.
            * tree-streamer-in.cc (streamer_read_tree_bitfields): Stream
            * tree-streamer-out.cc (streamer_write_tree_bitfields):
            * tree-pretty-print.cc (dump_generic_node): Mark EOL CLOBBERs.
            * gimplify.cc (gimplify_bind_expr): Build storage end-of-life clobbers
            with CLOBBER_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_EOL clobbers as ending lifetime of storage.
            * lto-common.cc (compare_tree_sccs_1): Compare CLOBBER_KIND.
            * gcc.dg/pr87052.c: Adjust.
Comment 3 Richard Biener 2022-02-04 07:17:29 UTC
Should be fixed now.
Comment 4 CVS Commits 2022-02-04 08:09:20 UTC
The trunk branch has been updated by Richard Sandiford <rsandifo@gcc.gnu.org>:


commit r12-7045-g5b6370295d1efaa563f6d8c45f1fb779c3db452e
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Fri Feb 4 08:08:59 2022 +0000

    aarch64: Add test for PR104092
            PR middle-end/104092
            * gcc.target/aarch64/sve/acle/general/pr104092.c: New test.