https://gcc.gnu.org/g:6cfe4fd3fb44b660eaf52302235c4a9992a9ddb4

commit r14-10999-g6cfe4fd3fb44b660eaf52302235c4a9992a9ddb4
Author: Richard Biener <rguent...@suse.de>
Date:   Tue Oct 22 11:46:47 2024 +0200

    tree-optimization/117254 - ICE with access diangostics
    
    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.
    
    (cherry picked from commit d464a52d0678dfea523a60efe8b792ba1b8d40db)

Diff:
---
 gcc/gimple-ssa-warn-access.cc   |  3 ++-
 gcc/testsuite/gcc.dg/pr117254.c | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 194d1a2c02ae..5c1f3a414b1a 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -606,7 +606,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
index 000000000000..c7a510677f13
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr117254.c
@@ -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);
+}

Reply via email to