]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: fix ICE on operator new with discarded result [PR116228]
authorDavid Malcolm <dmalcolm@redhat.com>
Sat, 7 Feb 2026 15:21:00 +0000 (10:21 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Sat, 7 Feb 2026 15:21:00 +0000 (10:21 -0500)
gcc/analyzer/ChangeLog:
PR analyzer/116228
* kf-lang-cp.cc (kf_operator_new::impl_call_post): Don't try to
add a constraint if the return value is discarded.

gcc/testsuite/ChangeLog:
PR analyzer/116228
* g++.dg/analyzer/ice-pr116228.C: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/kf-lang-cp.cc
gcc/testsuite/g++.dg/analyzer/ice-pr116228.C [new file with mode: 0644]

index c92864b0b27639b947b1b69c05b8caf871a38170..5d57bcc5fcb6e68ecaaa1d96bc4aa368a8653ba9 100644 (file)
@@ -140,7 +140,9 @@ public:
 
     /* If the call is guaranteed to return nonnull
        then add a nonnull constraint to the allocated region.  */
-    if (!TREE_NOTHROW (callee_fndecl) && flag_exceptions)
+    if (!TREE_NOTHROW (callee_fndecl)
+       && flag_exceptions
+       && cd.get_lhs_type ())
       {
        const svalue *null_sval
          = mgr->get_or_create_null_ptr (cd.get_lhs_type ());
diff --git a/gcc/testsuite/g++.dg/analyzer/ice-pr116228.C b/gcc/testsuite/g++.dg/analyzer/ice-pr116228.C
new file mode 100644 (file)
index 0000000..df6d2aa
--- /dev/null
@@ -0,0 +1,33 @@
+// { dg-additional-options "-O3" }
+
+void *operator new(unsigned long, void *);
+int to_constant();
+int vec_copy_construct_n, vec_stmts_size, vectorizable_load_vec_stmt,
+    vectorizable_load_offvar;
+enum tree_code { POINTER_PLUS_EXPR };
+void gimple_build_assign(int, tree_code, int, int);
+int cse_and_gimplify_to_preheader(int, int);
+void vectorizable_load() {
+  int i, stride_step, const_nunits = to_constant();
+  bool costing_p = vectorizable_load_vec_stmt;
+  if (!costing_p) {
+    stride_step = 0;
+    stride_step = cse_and_gimplify_to_preheader(0, stride_step);
+  }
+  for (; vec_stmts_size;) {
+    i = 0;
+    for (; i < const_nunits; i++) {
+      if (costing_p)
+        continue;
+      gimple_build_assign(0, POINTER_PLUS_EXPR, vectorizable_load_offvar,
+                          stride_step);
+    }
+    if (const_nunits)
+      if (!costing_p) {
+        {
+          for (; vec_copy_construct_n;)
+            new (0) int;
+        }
+      }
+  }
+}