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

--- Comment #2 from Kees Cook <kees at outflux dot net> ---
Ugh, I'm sorry I botched this example so badly. I'm not sure where I got off
track in trying to get it into one of the selftests. The problem I ran into was
with querying array members of the multidimensional array. Here are correct
examples. These should all pass, but looking into the "middle" of the array
fails, similar to how the warning was failing before:


static const char single[] __attribute__((nonstring)) = "ohai";
_Static_assert (__builtin_has_attribute(single, nonstring)); // array of char
_Static_assert (!__builtin_has_attribute(single[2], nonstring)); // is a char,
not array

static const char multi2[][4] __attribute__((nonstring)) = {
        "hola", "here", "test"
};
_Static_assert (__builtin_has_attribute(multi2, nonstring)); // array of array
of char
_Static_assert (__builtin_has_attribute(multi2[1], nonstring)); // array of
char [missed]
_Static_assert (!__builtin_has_attribute(multi2[1][3], nonstring)); // is a
char, not array

static const char multi3[][16][5] __attribute__((nonstring)) = {
        { "hello", "test!", "again", },
        { "haloo", "!test", "check", },
};
_Static_assert (__builtin_has_attribute(multi3, nonstring)); // array of array
of array of char
_Static_assert (__builtin_has_attribute(multi3[0], nonstring)); // array of
array of char [missed]
_Static_assert (__builtin_has_attribute(multi3[0][1], nonstring)); // array of
char [missed]
_Static_assert (!__builtin_has_attribute(multi3[0][1][4], nonstring)); // is a
char, not array



$ gcc -Wall -O2 -c multi.c
multi.c:9:1: error: static assertion failed
    9 | _Static_assert (__builtin_has_attribute(multi2[1], nonstring)); //
array of char [missed]
      | ^~~~~~~~~~~~~~
multi.c:17:1: error: static assertion failed
   17 | _Static_assert (__builtin_has_attribute(multi3[0], nonstring)); //
array of array of char [missed]
      | ^~~~~~~~~~~~~~
multi.c:18:1: error: static assertion failed
   18 | _Static_assert (__builtin_has_attribute(multi3[0][1], nonstring)); //
array of char [missed]
      | ^~~~~~~~~~~~~~

Reply via email to