On 4/19/2021 3:21 AM, Richard Sandiford via Gcc-patches wrote:
switch_to_section warns if we try to output a retain decl in a
section without a retain flag, or if we try to output a non-retain
decl in a section with a retain flag.  However, the warning only
applied if we were trying to “switch” to the current section.
This works if all decls that use a section are generated consecutively,
but not if there is an unrelated decl in between.

This patch makes the check unconditional, but suppresses the warning
if we're writing the section's named.decl (i.e. the decl from which
the section name and original flags were derived).

Also, the warning didn't fire for -fsection-anchors, for two reasons:
we allowed retain and non-retain to be put into the same block,
and we didn't pass a decl to switch_to_section.

Although these are arguably separate bugs, it isn't easy to fix them
independently without temporarily regressing -fsection-anchor targets.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


gcc/
        PR middle-end/100130
        * varasm.c (get_block_for_decl): Make sure that any use of the
        retain attribute matches the section's retain flag.
        (switch_to_section): Check for retain mismatches even when
        changing sections, but do not warn if the given decl is the
        section's named.decl.
        (output_object_block): Pass the first decl in the block (if any)
        to switch_to_section.

gcc/testsuite/
        PR middle-end/100130
        * c-c++-common/attr-retain-10.c: New test.
        * c-c++-common/attr-retain-11.c: Likewise.

OK

Jeff

Reply via email to