[gcc r16-6110] middle-end: Fix spurious -Walloc-size-larger-than warning during LTO [PR106409]
Lewis Hyatt
lhyatt@gcc.gnu.org
Sun Dec 14 20:24:40 GMT 2025
https://gcc.gnu.org/g:8e23a9982fa4b885a27608825cbe326d61f20498
commit r16-6110-g8e23a9982fa4b885a27608825cbe326d61f20498
Author: Lewis Hyatt <lhyatt@gmail.com>
Date: Sun Dec 14 09:51:12 2025 -0500
middle-end: Fix spurious -Walloc-size-larger-than warning during LTO [PR106409]
The implementation of -Walloc-size-larger-than has logic to avoid issuing
the warning for ::operator new[] calls emitted by the C++ front end, which
otherwise produce known false positives. The logic for suppressing the
warning only activates in the C++ front end, and so it does not prevent the
LTO front end from issuing the warning. Fix by applying the logic in all
cases.
gcc/ChangeLog:
PR tree-optimization/106409
* gimple-ssa-warn-access.cc (maybe_warn_alloc_args_overflow): Adjust
comment for clarity, and augment check to work in LTO as well.
gcc/testsuite/ChangeLog:
PR tree-optimization/106409
* g++.dg/lto/pr106409_0.C: New test.
Diff:
---
gcc/gimple-ssa-warn-access.cc | 10 +++++-----
gcc/testsuite/g++.dg/lto/pr106409_0.C | 23 +++++++++++++++++++++++
2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index d12f797f36b3..0625a36ca35a 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -2334,14 +2334,14 @@ maybe_warn_alloc_args_overflow (gimple *stmt, const tree args[2],
}
else if (tree_int_cst_lt (maxobjsize, args[i]))
{
- /* G++ emits calls to ::operator new[](SIZE_MAX) in C++98
- mode and with -fno-exceptions as a way to indicate array
- size overflow. There's no good way to detect C++98 here
- so avoid diagnosing these calls for all C++ modes. */
+ /* G++ emits calls to ::operator new[](SIZE_MAX) in C++98 mode or
+ with -fno-exceptions as a way to indicate array size overflow.
+ Avoid diagnosing these calls. Additionally, see e.g. PR99934,
+ G++ also potentially generates such calls in C++11 and later as
+ well, so suppress the diagnostic in all C++ modes. */
if (i == 0
&& fn
&& !args[1]
- && lang_GNU_CXX ()
&& DECL_IS_OPERATOR_NEW_P (fn)
&& integer_all_onesp (args[i]))
continue;
diff --git a/gcc/testsuite/g++.dg/lto/pr106409_0.C b/gcc/testsuite/g++.dg/lto/pr106409_0.C
new file mode 100644
index 000000000000..464d13a79479
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr106409_0.C
@@ -0,0 +1,23 @@
+/* PR tree-optimization/106409 */
+/* { dg-lto-do link } */
+/* { dg-lto-options { { -flto -W -Wall -O2 -fno-exceptions } { -flto -W -Wall -O2 -std=c++98 } { -flto -W -Wall -O2 -std=gnu++20 } } } */
+struct bb
+{
+ int t;
+ int t1;
+ int t2;
+ int t3;
+};
+
+[[gnu::noipa]]
+void *f(unsigned long paramCount)
+{
+ if (paramCount == 0)
+ return 0;
+ return new bb[paramCount]();
+}
+
+int main(void)
+{
+ f(100);
+}
More information about the Gcc-cvs
mailing list