The diagnostics code fails to handle non-constant domain max.
PR tree-optimization/117254
* gimple-ssa-warn-access.cc (maybe_warn_nonstring_arg):
Check the array domain max is constant before using it.
* gcc.dg/pr117254.c: New testcase.
{
if (tree arrbnd = TYPE_DOMAIN (type))
{
- if ((arrbnd = TYPE_MAX_VALUE (arrbnd)))
+ if ((arrbnd = TYPE_MAX_VALUE (arrbnd))
+ && TREE_CODE (arrbnd) == INTEGER_CST)
{
asize = wi::to_offset (arrbnd) + 1;
known_size = true;
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int g;
+void e(int s) {
+ struct {
+ __attribute__((nonstring)) char bn[g];
+ } f;
+ __builtin_strncpy (f.bn, f.bn, s);
+}