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

--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Dominic Plunkett <[email protected]>:

https://gcc.gnu.org/g:389e48d33719dba3fda447f9e2d8fedf72ccda4c

commit r17-6819-g389e48d33719dba3fda447f9e2d8fedf72ccda4c
Author: Dominic P <[email protected]>
Date:   Wed Nov 25 10:42:35 2026 +0000

    Do not apply a target attribute that is dropped for an empty string

    handle_target_attribute calls targetm.target_option.valid_attribute_p
    before it looks for empty strings among the arguments (the check added
    for PR c++/81355).  The target hooks
    record the parsed options in DECL_FUNCTION_SPECIFIC_TARGET (and possibly
    DECL_FUNCTION_SPECIFIC_OPTIMIZATION) of the decl, so when an empty string
    is then found the attribute is warned about and dropped from the decl's
    attributes, but the options are still used for code generation.  For
    example target ("avx2", "") on x86 still vectorizes with AVX2, and
    target ("arm", "") under -mthumb still emits the function in Arm state.

    Check for empty strings first and call the hook only when the attribute
    is not being dropped.  As a consequence, the other strings of an attribute
    that is dropped for an empty string are no longer validated, so e.g.
    target ("bogus", "") now only gets the empty-string warning instead of
    also an error for "bogus"; the attribute is ignored either way.  For
    the same reason target ("") no longer gets the LoongArch "malformed"
    error, so remove that case from attr-check-error-message.c.

    Assisted-by: Claude Opus 5.5 (Anthropic)
    Signed-off-by: Dominic P <[email protected]>

    gcc/ChangeLog:

            * attr-handlers.cc (handle_target_attribute): Check for empty
            strings before calling the valid_attribute_p hook, and do not call
            it if the attribute is dropped.

    gcc/testsuite/ChangeLog:

            * gcc.target/arm/attr-target-empty.c: New test.
            * gcc.target/i386/attr-target-empty.c: New test.
            * gcc.target/loongarch/attr-check-error-message.c: Remove the
            target ("") case.

Reply via email to