https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100130

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Sandiford <rsand...@gcc.gnu.org>:

https://gcc.gnu.org/g:b67778b59932fdc64dc89a97550349e973ca0352

commit r12-17-gb67778b59932fdc64dc89a97550349e973ca0352
Author: Richard Sandiford <richard.sandif...@arm.com>
Date:   Wed Apr 21 09:08:44 2021 +0100

    varasm: Two SECTION_RETAIN fixes [PR100130]

    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 decls 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.

    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.

Reply via email to