Skip to content

Commit 8e23a99

Browse files
Lewis HyattLewis Hyatt
authored andcommitted
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.
1 parent ffa9842 commit 8e23a99

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

gcc/gimple-ssa-warn-access.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,14 +2334,14 @@ maybe_warn_alloc_args_overflow (gimple *stmt, const tree args[2],
23342334
}
23352335
else if (tree_int_cst_lt (maxobjsize, args[i]))
23362336
{
2337-
/* G++ emits calls to ::operator new[](SIZE_MAX) in C++98
2338-
mode and with -fno-exceptions as a way to indicate array
2339-
size overflow. There's no good way to detect C++98 here
2340-
so avoid diagnosing these calls for all C++ modes. */
2337+
/* G++ emits calls to ::operator new[](SIZE_MAX) in C++98 mode or
2338+
with -fno-exceptions as a way to indicate array size overflow.
2339+
Avoid diagnosing these calls. Additionally, see e.g. PR99934,
2340+
G++ also potentially generates such calls in C++11 and later as
2341+
well, so suppress the diagnostic in all C++ modes. */
23412342
if (i == 0
23422343
&& fn
23432344
&& !args[1]
2344-
&& lang_GNU_CXX ()
23452345
&& DECL_IS_OPERATOR_NEW_P (fn)
23462346
&& integer_all_onesp (args[i]))
23472347
continue;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* PR tree-optimization/106409 */
2+
/* { dg-lto-do link } */
3+
/* { dg-lto-options { { -flto -W -Wall -O2 -fno-exceptions } { -flto -W -Wall -O2 -std=c++98 } { -flto -W -Wall -O2 -std=gnu++20 } } } */
4+
struct bb
5+
{
6+
int t;
7+
int t1;
8+
int t2;
9+
int t3;
10+
};
11+
12+
[[gnu::noipa]]
13+
void *f(unsigned long paramCount)
14+
{
15+
if (paramCount == 0)
16+
return 0;
17+
return new bb[paramCount]();
18+
}
19+
20+
int main(void)
21+
{
22+
f(100);
23+
}

0 commit comments

Comments
 (0)