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

--- Comment #7 from Thomas Schwinge <tschwinge at gcc dot gnu.org> ---
One step further (hopefully): 'h' is special in that it '#embed's the
'__FILE__' itself:

    const unsigned char h[] = {
    #embed __FILE__ suffix (, 0)
    };

Now, I realized that to make it PASS, it's not *what* "random junk" I add to
the file, but *how much*.  As reported, the original one FAILs.  Adding one
byte, it PASSes:

    --- gcc/testsuite/c-c++-common/cpp/embed-1.c
    +++ gcc/testsuite/c-c++-common/cpp/embed-1.c
    @@ -259,5 +259,5 @@ main ()
       if (g.a != 'H' || g.b != 'e' || g.c != 'n' || g.d != 'r')
         abort ();
    -  if (!strstr ((const char *) h, "imprisonétur")
    +   if (!strstr ((const char *) h, "imprisonétur")
           || !strstr ((const char *) h, "blah blah"))
         abort ();

Adding one more byte, it FAILs, adding another one, it PASSes.

So, two wild theories: either something's going wrong at the GCN assembly level
(?), or something's going wrong in newlib 'strstr' -- but why for
'-march=gfx908' only, but not '-march=gfx1100' (or nvptx, for example).  A
'strstr' vectorization issue maybe?

For FAIL vs. PASS 'embed-1.s', we've got:

    --- 0/embed-1.s 2024-10-22 16:30:19.355457261 +0200
    +++ ./embed-1.s 2024-10-22 16:30:29.867333623 +0200
    @@ -470,7 +470,7 @@
            .section        .rodata
            .align  16
            .type   h, @object
    -       .size   h, 8879
    +       .size   h, 8880
     h:
            .byte   47
            .ascii  "* { dg-do run } */\n/* { dg-options
\"--embed-dir=${srcdir}/"
    @@ -594,30 +594,30 @@
            .ascii  "abort ();\n#endif\n  f = (\n#embed \"magna-carta.txt\"
limit"
            .ascii  " (4) prefix (172 + ) suffix (+ 2)\n  );\n  if (f != 'r' +
2)"
            .ascii  "\n    abort ();\n  if (g.a != 'H' || g.b != 'e' || g.c !=
'n"
    -       .ascii  "' || g.d != 'r')\n    abort ();\n  if (!strstr ((const
char "
    -       .ascii  "*) h, \"imprison\303\251tur\")\n      || !strstr ((const
cha"
    -       .ascii  "r *) h, \"blah blah\"))\n    abort ();\n  if (v.a != 42 ||
v"
    -       .ascii  ".b.a != 'H' || v.b.b.a != 'e'\n      || v.b.c != 'n' ||
v.c "
    -       .ascii  "!= 'r' || v.d != -42)\n    abort ();\n#ifndef
__cplusplus\n "
    -       .ascii  " if (sizeof (w) != 1572 || w[0] != 42 || w[1] != 0 ||
w[71] "
    -       .ascii  "!= 0\n      || w[72] != 'H' || w[73] != 'e' || w[74] !=
'n' "
    -       .ascii  "|| w[75] != 'r')\n    abort ();\n#endif\n  if (sizeof (x)
!="
    -       .ascii  " 5 || x[0] != 0 || x[1] != 1 || x[2] != 2\n      || x[3]
!= "
    -       .ascii  "3 || x[4] != 4)\n    abort ();\n  foo (\n#embed
<magna-carta"
    -       .ascii  ".txt> limit(5)\n  );\n  if (sizeof (y) > 100\n      ||
!strs"
    -       .ascii  "tr ((const char *) y, \"Dummy file.\")\n      || strstr
((co"
    -       .ascii  "nst char *) y, \"__gnu__::__non_existent_parameter\"))\n  
 "
    -       .ascii  "abort ();\n  if (sizeof (z) < 100\n      || strstr ((const
c"
    -       .ascii  "har *) z, \"Dummy file.\")\n      || !strstr ((const char
*)"
    -       .ascii  " z, \"__gnu__::__non_existent_parameter\"))\n    abort
();\n"
    +       .ascii  "' || g.d != 'r')\n    abort ();\n   if (!strstr ((const
char"
    +       .ascii  " *) h, \"imprison\303\251tur\")\n      || !strstr ((const
ch"
    +       .ascii  "ar *) h, \"blah blah\"))\n    abort ();\n  if (v.a != 42
|| "
    +       .ascii  "v.b.a != 'H' || v.b.b.a != 'e'\n      || v.b.c != 'n' ||
v.c"
    +       .ascii  " != 'r' || v.d != -42)\n    abort ();\n#ifndef
__cplusplus\n"
    +       .ascii  "  if (sizeof (w) != 1572 || w[0] != 42 || w[1] != 0 ||
w[71]"
    +       .ascii  " != 0\n      || w[72] != 'H' || w[73] != 'e' || w[74] !=
'n'"
    +       .ascii  " || w[75] != 'r')\n    abort ();\n#endif\n  if (sizeof (x)
!"
    +       .ascii  "= 5 || x[0] != 0 || x[1] != 1 || x[2] != 2\n      || x[3]
!="
    +       .ascii  " 3 || x[4] != 4)\n    abort ();\n  foo (\n#embed
<magna-cart"
    +       .ascii  "a.txt> limit(5)\n  );\n  if (sizeof (y) > 100\n      ||
!str"
    +       .ascii  "str ((const char *) y, \"Dummy file.\")\n      || strstr
((c"
    +       .ascii  "onst char *) y, \"__gnu__::__non_existent_parameter\"))\n 
 "
    +       .ascii  " abort ();\n  if (sizeof (z) < 100\n      || strstr
((const "
    +       .ascii  "char *) z, \"Dummy file.\")\n      || !strstr ((const char
*"
    +       .ascii  ") z, \"__gnu__::__non_existent_parameter\"))\n    abort
();\n"
            .ascii  "  if (sizeof (\n#embed \"embed-1.inc\"\n      ) != sizeof
(i"
            .ascii  "nt))\n    abort ();\n#ifndef __cplusplus\n  if (_Generic
(\n"
            .ascii  "#embed \"embed-1.inc\" __limit__ (1) __suffix__ (, int:
42, "
            .ascii  "default: 0)\n      ) != 42)\n    abort ();\n#endif\n#if
__ST"
            .ascii  "DC_VERSION__ >= 202311L\n  typeof (\n#embed
\"embed-1.inc\" "
            .ascii  "limit (1)\n  ) j;\n  if (sizeof (j) != sizeof (int))\n   
ab"
    -       .ascii  "or"
    -       .ascii  "t ();\n#elif __cplusplus >= 201103L\n  decltype (\n#embed
\""
    +       .ascii  "o"
    +       .ascii  "rt ();\n#elif __cplusplus >= 201103L\n  decltype (\n#embed
\""
            .ascii  "embed-1.inc\" limit (1)\n  ) j;\n  if (sizeof (j) !=
sizeof "
            .ascii  "(int))\n    abort ();\n#endif\n#if __has_embed
(\"embed-5.c\""
            .ascii  " ds9000::element_type(short))\n  short meow[] = {\n   
#embe"

Reply via email to