[Bug middle-end/77357] strlen of constant strings not folded

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Aug 24 14:22:00 GMT 2016


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Sorry, wrong test case.  Here's the right one:

const char a[] = "abc";
const char* const s = "abc";

void global_array (void)
{
  if (__builtin_strlen (a) != 3)
    __builtin_abort ();
}

void local_array (void)
{
  static const char a[] = "abc";
  if (__builtin_strlen (a) != 3)
    __builtin_abort ();
}

void global_pointer (void)
{
  if (__builtin_strlen (s) != 3)
    __builtin_abort ();
}

void local_pointer (void)
{
  static const char* const s = "abc";
  if (__builtin_strlen (s) != 3)
    __builtin_abort ();
}


struct X { char a [4]; };
const struct X x = { "abc" };

void global_struct (void)
{
  if (__builtin_strlen (x.a) != 3)
    __builtin_abort ();
}

void local_struct (void)
{
  static const struct X x =  { "abc" };
  if (__builtin_strlen (x.a) != 3)
    __builtin_abort ();
}


More information about the Gcc-bugs mailing list