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

            Bug ID: 129186
           Summary: c-family: access attribute accepts invalid mode names
                    that start with a valid mode
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lzy20000419 at outlook dot com
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu

Fails with trunk (gcc 17.0.0 20261201, 96693d6f00bd) and with 10.1.0 through
16.2.0. The access attribute was not implemented in 8.5.0 or 9.5.0 (the
attribute is ignored with a warning). Target: x86_64-pc-linux-gnu.

handle_access_attribute accepts a mode name with a prefix comparison, so any
identifier that starts with read_only, read_write, write_only or none is taken
as that mode with no error or warning. The "invalid mode" error after the loop
is never reached for such names.

    __attribute__((access(read_only_junk, 1))) void f1(char *p);
    __attribute__((access(nonesense, 1))) void f2(char *p);
    __attribute__((access(read_onlx, 1))) void f3(char *p);

    gcc -c -Wall -Wextra -Wattributes t.c

All three names should be rejected with "attribute 'access' invalid mode ...".
On trunk, and on 11.1.0 through 16.2.0, only f3 is diagnosed ("invalid mode
'read_onlx'"); f1 is accepted as read_only and f2 is accepted as none. gcc
14.2.0 is the same.

On 10.1.0 through 10.5.0, f1 is already accepted as read_only, but f2 is still
diagnosed because those releases do not have a none mode (the error lists only
read_only, read_write and write_only). After none was added in GCC 11, names
such as nonesense are accepted as well.

Godbolt (trunk): https://godbolt.org/z/fqM9651n5

This is not PR123721 (ICE on an invalid mode character) and not PR103056. It is
also not PR103223 (the access attribute dropped by IPA SRA) or PR123465 (ICE in
handle_access_attribute after a redeclaration error).

The mode name appears to be matched as a prefix of a valid mode, so a name that
only starts with a valid mode is not rejected. I have not tested a patch.

Disclaimer: This test case was found with LLM-assisted targeted testing, and
the report was written with LLM assistance.
  • [Bug c/129186] New: c-family: ... lzy20000419 at outlook dot com via Gcc-bugs

Reply via email to