https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109895
Bug ID: 109895
Summary: -Walloc-size-larger-than complains about code it
generated itself under -flto -fno-exceptions
Product: gcc
Version: 13.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: thiago at kde dot org
Target Milestone: ---
Reference: https://bugreports.qt.io/browse/QTBUG-113603
Code in question:
const auto paramCount = mysql_stmt_param_count(d->stmt);
if (paramCount > 0) // allocate memory for outvalues
d->outBinds = new MYSQL_BIND[paramCount]();
mysql_stmt_param_count returns unsigned long.
GCC 13.1 with -flto -fno-exceptions produced:
src/plugins/sqldrivers/mysql/qsql_mysql.cpp: In member function ‘prepare’:
src/plugins/sqldrivers/mysql/qsql_mysql.cpp:891:50: warning: argument 1 value
‘18446744073709551615’ exceeds maximum object size 9223372036854775807
[-Walloc-size-larger-than=]
891 | d->outBinds = new MYSQL_BIND[paramCount]();
| ^
/usr/include/c++/13/new:128:26: note: in a call to allocation function
‘operator new []’ declared here
128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW
(std::bad_alloc)
| ^
Disassembling the code shows it looks similar to this:
https://godbolt.org/z/9eKPxbEMY
movq $-1, %rdi
cmpq %rbx, %rax
jb .L2
...
.L2:
call operator new[](unsigned long)@PLT
So that 18446744073709551615 value is the -1 inserted by GCC itself to deal
with the multiplication overflow.