public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
@ 2021-06-25 14:11 jlegg at feralinteractive dot com
2021-06-25 16:50 ` [Bug c++/101210] [9/10/11/12 " jakub at gcc dot gnu.org
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: jlegg at feralinteractive dot com @ 2021-06-25 14:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
Bug ID: 101210
Summary: [7/8/9/10/11/12 regression] spurious "reference
binding to misaligned address" ubsan error for integer
comparison
Product: gcc
Version: 11.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jlegg at feralinteractive dot com
Target Milestone: ---
With -fsanitize=undefined, this C++ code:
int main()
{
int x;
int & y {x};
return reinterpret_cast<long int>(&y) == 1;
}
Produces this error at runtime:
test.cc:5:40: runtime error: reference binding to misaligned address
0x000000000001 for type 'int', which requires 4 byte alignment
0x000000000001: note: pointer points here
<memory cannot be printed>
However, address 1 is never bound to a reference to an int. It is an integer
which is compared to another integer (which happens to be pointer sized and
derived from an address taken from a reference).
Checking various versions with compiler explorer, GCC 6 did not have this
issue, but later releases did.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
@ 2021-06-25 16:50 ` jakub at gcc dot gnu.org
2021-06-28 7:37 ` jakub at gcc dot gnu.org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-06-25 16:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[7/8/9/10/11/12 regression] |[9/10/11/12 regression]
|spurious "reference binding |spurious "reference binding
|to misaligned address" |to misaligned address"
|ubsan error for integer |ubsan error for integer
|comparison |comparison
CC| |jakub at gcc dot gnu.org
Target Milestone|--- |9.5
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think this is caused by the PR70920 fix
r7-2226-g8f63caf6826e918678482413161e34b037a13fa7
We have (long) y == 1 where y has REFERENCE_TYPE and that match.pd
rule transforms it into y == 1 where 1 has also that REFERENCE_TYPE.
As ubsan instrumentation happens on partially GENERIC folded trees, doing that
in GENERIC for REFERENCE_TYPE is wrong, we should defer it to GIMPLE.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
2021-06-25 16:50 ` [Bug c++/101210] [9/10/11/12 " jakub at gcc dot gnu.org
@ 2021-06-28 7:37 ` jakub at gcc dot gnu.org
2021-06-28 8:18 ` jakub at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-06-28 7:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
Last reconfirmed| |2021-06-28
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
2021-06-25 16:50 ` [Bug c++/101210] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-28 7:37 ` jakub at gcc dot gnu.org
@ 2021-06-28 8:18 ` jakub at gcc dot gnu.org
2021-06-28 8:20 ` marxin at gcc dot gnu.org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-06-28 8:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 51069
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51069&action=edit
gcc12-pr101210.patch
Untested fix.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
` (2 preceding siblings ...)
2021-06-28 8:18 ` jakub at gcc dot gnu.org
@ 2021-06-28 8:20 ` marxin at gcc dot gnu.org
2021-06-28 8:22 ` jakub at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-06-28 8:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
You should Jakub likely use sanitize_flags_p rather than direct flag_sanitize?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
` (3 preceding siblings ...)
2021-06-28 8:20 ` marxin at gcc dot gnu.org
@ 2021-06-28 8:22 ` jakub at gcc dot gnu.org
2021-06-28 8:27 ` marxin at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-06-28 8:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It should match what the FE is doing, and it uses
if (TREE_CODE (stmt) == INTEGER_CST
&& TYPE_REF_P (TREE_TYPE (stmt))
&& (flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT))
&& !wtd->no_sanitize_p)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
` (4 preceding siblings ...)
2021-06-28 8:22 ` jakub at gcc dot gnu.org
@ 2021-06-28 8:27 ` marxin at gcc dot gnu.org
2021-06-29 9:25 ` cvs-commit at gcc dot gnu.org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-06-28 8:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
You are right, it might be a location which I forgot to convert g:45b2222a13ea.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
` (5 preceding siblings ...)
2021-06-28 8:27 ` marxin at gcc dot gnu.org
@ 2021-06-29 9:25 ` cvs-commit at gcc dot gnu.org
2021-06-29 9:50 ` [Bug c++/101210] [9/10/11 " jakub at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-29 9:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:53fd7544aff6d0a18869017cb9bb921a7f5dcd04
commit r12-1867-g53fd7544aff6d0a18869017cb9bb921a7f5dcd04
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Jun 29 11:24:38 2021 +0200
match.pd: Avoid (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST opt in
GENERIC when sanitizing [PR101210]
When we have (intptr_t) x == cst where x has REFERENCE_TYPE, this
optimization creates x == cst out of it where cst has REFERENCE_TYPE.
If it is done in GENERIC folding, it can results in ubsan failures
where the INTEGER_CST with REFERENCE_TYPE is instrumented.
Fixed by deferring it to GIMPLE folding in this case.
2021-06-29 Jakub Jelinek <jakub@redhat.com>
PR c++/101210
* match.pd ((intptr_t)x eq/ne CST to x eq/ne (typeof x) CST): Don't
perform the optimization in GENERIC when sanitizing and x has a
reference type.
* g++.dg/ubsan/pr101210.C: New test.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10/11 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
` (6 preceding siblings ...)
2021-06-29 9:25 ` cvs-commit at gcc dot gnu.org
@ 2021-06-29 9:50 ` jakub at gcc dot gnu.org
2021-07-18 23:28 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-06-29 9:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[9/10/11/12 regression] |[9/10/11 regression]
|spurious "reference binding |spurious "reference binding
|to misaligned address" |to misaligned address"
|ubsan error for integer |ubsan error for integer
|comparison |comparison
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk so far.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10/11 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
` (7 preceding siblings ...)
2021-06-29 9:50 ` [Bug c++/101210] [9/10/11 " jakub at gcc dot gnu.org
@ 2021-07-18 23:28 ` cvs-commit at gcc dot gnu.org
2021-07-19 7:55 ` [Bug c++/101210] [9/10 " jakub at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-18 23:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:86a9718e162b08cd4263402bcbf0d17a557bfcf1
commit r11-8768-g86a9718e162b08cd4263402bcbf0d17a557bfcf1
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Jun 29 11:24:38 2021 +0200
match.pd: Avoid (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST opt in
GENERIC when sanitizing [PR101210]
When we have (intptr_t) x == cst where x has REFERENCE_TYPE, this
optimization creates x == cst out of it where cst has REFERENCE_TYPE.
If it is done in GENERIC folding, it can results in ubsan failures
where the INTEGER_CST with REFERENCE_TYPE is instrumented.
Fixed by deferring it to GIMPLE folding in this case.
2021-06-29 Jakub Jelinek <jakub@redhat.com>
PR c++/101210
* match.pd ((intptr_t)x eq/ne CST to x eq/ne (typeof x) CST): Don't
perform the optimization in GENERIC when sanitizing and x has a
reference type.
* g++.dg/ubsan/pr101210.C: New test.
(cherry picked from commit 53fd7544aff6d0a18869017cb9bb921a7f5dcd04)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
` (8 preceding siblings ...)
2021-07-18 23:28 ` cvs-commit at gcc dot gnu.org
@ 2021-07-19 7:55 ` jakub at gcc dot gnu.org
2022-05-10 8:19 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-07-19 7:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[9/10/11 regression] |[9/10 regression] spurious
|spurious "reference binding |"reference binding to
|to misaligned address" |misaligned address" ubsan
|ubsan error for integer |error for integer
|comparison |comparison
--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 11.2 too.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
` (9 preceding siblings ...)
2021-07-19 7:55 ` [Bug c++/101210] [9/10 " jakub at gcc dot gnu.org
@ 2022-05-10 8:19 ` cvs-commit at gcc dot gnu.org
2022-05-11 6:21 ` cvs-commit at gcc dot gnu.org
2022-05-11 6:36 ` jakub at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-10 8:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:208ad9a001f192c763e2c9682a4c296b4696a10c
commit r10-10628-g208ad9a001f192c763e2c9682a4c296b4696a10c
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Jun 29 11:24:38 2021 +0200
match.pd: Avoid (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST opt in
GENERIC when sanitizing [PR101210]
When we have (intptr_t) x == cst where x has REFERENCE_TYPE, this
optimization creates x == cst out of it where cst has REFERENCE_TYPE.
If it is done in GENERIC folding, it can results in ubsan failures
where the INTEGER_CST with REFERENCE_TYPE is instrumented.
Fixed by deferring it to GIMPLE folding in this case.
2021-06-29 Jakub Jelinek <jakub@redhat.com>
PR c++/101210
* match.pd ((intptr_t)x eq/ne CST to x eq/ne (typeof x) CST): Don't
perform the optimization in GENERIC when sanitizing and x has a
reference type.
* g++.dg/ubsan/pr101210.C: New test.
(cherry picked from commit 53fd7544aff6d0a18869017cb9bb921a7f5dcd04)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
` (10 preceding siblings ...)
2022-05-10 8:19 ` cvs-commit at gcc dot gnu.org
@ 2022-05-11 6:21 ` cvs-commit at gcc dot gnu.org
2022-05-11 6:36 ` jakub at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-11 6:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:57aeb7f535b9c04ed34ab9479498143ee73fb568
commit r9-10085-g57aeb7f535b9c04ed34ab9479498143ee73fb568
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Jun 29 11:24:38 2021 +0200
match.pd: Avoid (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST opt in
GENERIC when sanitizing [PR101210]
When we have (intptr_t) x == cst where x has REFERENCE_TYPE, this
optimization creates x == cst out of it where cst has REFERENCE_TYPE.
If it is done in GENERIC folding, it can results in ubsan failures
where the INTEGER_CST with REFERENCE_TYPE is instrumented.
Fixed by deferring it to GIMPLE folding in this case.
2021-06-29 Jakub Jelinek <jakub@redhat.com>
PR c++/101210
* match.pd ((intptr_t)x eq/ne CST to x eq/ne (typeof x) CST): Don't
perform the optimization in GENERIC when sanitizing and x has a
reference type.
* g++.dg/ubsan/pr101210.C: New test.
(cherry picked from commit 53fd7544aff6d0a18869017cb9bb921a7f5dcd04)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/101210] [9/10 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
` (11 preceding siblings ...)
2022-05-11 6:21 ` cvs-commit at gcc dot gnu.org
@ 2022-05-11 6:36 ` jakub at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-11 6:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2022-05-11 6:36 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
2021-06-25 16:50 ` [Bug c++/101210] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-28 7:37 ` jakub at gcc dot gnu.org
2021-06-28 8:18 ` jakub at gcc dot gnu.org
2021-06-28 8:20 ` marxin at gcc dot gnu.org
2021-06-28 8:22 ` jakub at gcc dot gnu.org
2021-06-28 8:27 ` marxin at gcc dot gnu.org
2021-06-29 9:25 ` cvs-commit at gcc dot gnu.org
2021-06-29 9:50 ` [Bug c++/101210] [9/10/11 " jakub at gcc dot gnu.org
2021-07-18 23:28 ` cvs-commit at gcc dot gnu.org
2021-07-19 7:55 ` [Bug c++/101210] [9/10 " jakub at gcc dot gnu.org
2022-05-10 8:19 ` cvs-commit at gcc dot gnu.org
2022-05-11 6:21 ` cvs-commit at gcc dot gnu.org
2022-05-11 6:36 ` jakub at gcc dot gnu.org
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).