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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:533241c6c60bc7c9f7dc47a94e94b5eed1b370e6

commit r14-5265-g533241c6c60bc7c9f7dc47a94e94b5eed1b370e6
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Thu Nov 9 09:05:54 2023 +0100

    attribs: Fix ICE with -Wno-attributes= [PR112339]

    The following testcase ICEs, because with -Wno-attributes=foo::no_sanitize
    (but generally any other non-gnu namespace and some gnu well known
attribute
    name within that other namespace) the FEs don't really parse attribute
    arguments of such attribute, but lookup_attribute_spec is non-NULL with
    NULL handler and such attributes are added to DECL_ATTRIBUTES or
    TYPE_ATTRIBUTES and then when e.g. middle-end does lookup_attribute
    on a particular attribute and expects the attribute to mean something
    and/or have a particular verified arguments, it can crash when seeing
    the foreign attribute in there instead.

    The following patch fixes that by never adding ignored attributes
    to DECL_ATTRIBUTES/TYPE_ATTRIBUTES, previously that was the case just
    for attributes in ignored namespace (where lookup_attribute_space
    returned NULL).  We don't really know anything about those attributes,
    so shouldn't pretend we know something about them, especially when
    the arguments are error_mark_node or NULL instead of something that
    would have been parsed.  And it would be really weird if we normally
    ignore say [[clang::unused]] attribute, but when people use
    -Wno-attributes=clang::unused we actually treated it as gnu::unused.
    All the user asked for is suppress warnings about that attribute being
    unknown.

    The first hunk is just playing safe, I'm worried people could
    -Wno-attributes=gnu::
    and get various crashes with known GNU attributes not being actually
    parsed and recorded (or worse e.g. when we tweak standard attributes
    into GNU attributes and we wouldn't add those).
    The -Wno-attributes= documentation says that it suppresses warning about
    unknown attributes, so I think -Wno-attributes=gnu:: should prevent
    warning about say [[gnu::foobarbaz]] attribute, but not about
    [[gnu::unused]] because the latter is a known attribute.
    The routine would return true for any scoped attribute in the ignored
    namespace, with the change it ignores only unknown attributes in ignored
    namespace, known ones in there will be ignored only if they have
    max_length of -2 (e.g.. with
    -Wno-attributes=gnu:: -Wno-attributes=gnu::foobarbaz).

    2023-11-09  Jakub Jelinek  <ja...@redhat.com>

            PR c/112339
            * attribs.cc (attribute_ignored_p): Only return true for
            attr_namespace_ignored_p if as is NULL.
            (decl_attributes): Never add ignored attributes.

            * c-c++-common/ubsan/Wno-attributes-1.c: New test.

Reply via email to