]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/117254 - ICE with access diangostics
authorRichard Biener <rguenther@suse.de>
Tue, 22 Oct 2024 09:46:47 +0000 (11:46 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 22 Oct 2024 11:25:48 +0000 (13:25 +0200)
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.

gcc/gimple-ssa-warn-access.cc
gcc/testsuite/gcc.dg/pr117254.c [new file with mode: 0644]

index 950d96bf9d62f318773af490ef0176fe5ea22082..5061af389c23d63f806837ab8c174e98c0a8d031 100644 (file)
@@ -607,7 +607,8 @@ maybe_warn_nonstring_arg (tree fndecl, GimpleOrTree exp)
        {
          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;
diff --git a/gcc/testsuite/gcc.dg/pr117254.c b/gcc/testsuite/gcc.dg/pr117254.c
new file mode 100644 (file)
index 0000000..c7a5106
--- /dev/null
@@ -0,0 +1,10 @@
+/* { 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);
+}