view gcc/testsuite/g++.dg/warn/Wstringop-overflow-2.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
line wrap: on
line source

/* PR tree-optimization/89688 - -Wstringop-overflow confused by const 2D
   array of char
   { dg-do compile }
   { dg-options "-Wall -fdump-tree-gimple -fdump-tree-optimized" } */

extern "C" __SIZE_TYPE__ strlen (const char*);

const char a2[2] = { '1' };

void a2_len ()
{
  if (strlen (a2) != 1)
    __builtin_abort ();
}

const char a2_2[2][3] = { { '1' }, { '1', '2' } };

void a2_2_len ()
{
  if  (strlen (a2_2[0]) != 1)   // { dg-bogus "-Wstringop-overflow" }
    __builtin_abort ();

  if  (strlen (a2_2[1]) != 2)   // { dg-bogus "-Wstringop-overflow" }
    __builtin_abort ();
}


/* { dg-final { scan-tree-dump-not "abort" "optimized" } }
   { dg-final { scan-tree-dump-not "strlen" "gimple" } } */