public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "thiago at kde dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/109895] New: -Walloc-size-larger-than complains about code it generated itself under -flto -fno-exceptions
Date: Wed, 17 May 2023 18:07:33 +0000	[thread overview]
Message-ID: <bug-109895-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2023-05-17 18:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17 18:07 thiago at kde dot org [this message]
2023-05-17 18:22 ` [Bug tree-optimization/109895] " pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-109895-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).