public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "i at maskray dot me" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/102317] signed integer overflow sanitizer cannot work well with -fno-strict-overflow
Date: Thu, 15 Feb 2024 01:22:26 +0000	[thread overview]
Message-ID: <bug-102317-4-3pBRuPnXwg@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102317-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102317

Fangrui Song <i at maskray dot me> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |i at maskray dot me

--- Comment #13 from Fangrui Song <i at maskray dot me> ---
I see a Clang patch that proposes -fsanitize=signed-integer-wrap, which appears
to be the same as signed-integer-overflow, but performs the check in the
-fwrapv mode.

I feel that it's better to make -fsanitize=signed-integer-overflow work with
-fwrapv
https://github.com/llvm/llvm-project/pull/80089#issuecomment-1945202620

--- Copying here for folks prefer not to read github

This is a UI discussion about how command line options should behave.
Some folks prefer simpler rules while some prefer smart rules (guessing user
intention).

A
[-fwrapv](https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fwrapv)
user may either:

* rely on the wraparound behavior
* or prevent certain optimizations that would raise security concerns

Our -fsanitize=signed-integer-overflow design have been assuming that -fwrapv
users don't need the check.
This PR suggests that an important user does want overflow checks and our guess
has failed.
It seems very confusing to have two options doing the same thing.

https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html is clear that not
all checks are undefined behavior in the standards.

> Issues caught by this sanitizer are not undefined behavior, but are often unintentional.

Sure -fwrapv makes wraparound defined, but it doesn't prevent us from making
-fsanitize=signed-integer-overflow useful. "-fwrapv => no
signed-integer-overflow" is not a solid argument.

I think we can try making -fsanitize=signed-integer-overflow effective even
when -fwrapv if specified.
-fsanitize=signed-integer-overflow is rare in the wild, probably rarer when
combined with -fwrapv.

There is a precedent that -fsanitize=undefined enables different checks for
different targets.
We could make -fsanitize=undefined not imply -fsanitize=signed-integer-overflow
when -fwrapv is specified, if we do want to guess the user intention.
Personally I'd prefer moving away from such behaviors and be more orthogonal.

      parent reply	other threads:[~2024-02-15  1:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 21:31 [Bug sanitizer/102317] New: " qinzhao at gcc dot gnu.org
2021-09-13 21:35 ` [Bug sanitizer/102317] " pinskia at gcc dot gnu.org
2021-09-13 21:41 ` qinzhao at gcc dot gnu.org
2021-09-13 21:45 ` pinskia at gcc dot gnu.org
2021-09-13 21:57 ` jakub at gcc dot gnu.org
2021-09-13 22:01 ` qing.zhao at oracle dot com
2021-09-14  5:55 ` jakub at gcc dot gnu.org
2021-09-14 15:57 ` kees at outflux dot net
2021-09-14 16:04 ` jakub at gcc dot gnu.org
2021-09-14 18:36 ` kees at outflux dot net
2021-09-14 18:53 ` jakub at gcc dot gnu.org
2021-09-23 22:58 ` kees at outflux dot net
2023-09-07 20:53 ` qinzhao at gcc dot gnu.org
2024-02-15  1:22 ` i at maskray dot me [this message]

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-102317-4-3pBRuPnXwg@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).