public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug d/96435] New: d: Returning boolean in a union violates @safe code
@ 2020-08-03 15:49 ibuclaw at gdcproject dot org
2021-07-29 15:12 ` [Bug d/96435] " cvs-commit at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: ibuclaw at gdcproject dot org @ 2020-08-03 15:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96435
Bug ID: 96435
Summary: d: Returning boolean in a union violates @safe code
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: d
Assignee: ibuclaw at gdcproject dot org
Reporter: ibuclaw at gdcproject dot org
Target Milestone: ---
In this test, the return value is both true and false at the same time.
---
bool schrodingersCat() @safe {
union Box { bool b; int state; }
Box u;
u.state = 42;
return u.b;
}
void main() @safe {
import std.stdio;
bool b = schrodingersCat();
if (b) writeln("alive");
if (!b) writeln("dead");
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug d/96435] d: Returning boolean in a union violates @safe code
2020-08-03 15:49 [Bug d/96435] New: d: Returning boolean in a union violates @safe code ibuclaw at gdcproject dot org
@ 2021-07-29 15:12 ` cvs-commit at gcc dot gnu.org
2021-07-29 15:20 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-29 15:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96435
--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Iain Buclaw <ibuclaw@gcc.gnu.org>:
https://gcc.gnu.org/g:5c9b7408dc578cb2ae142a5c1b724c183497bdb2
commit r12-2597-g5c9b7408dc578cb2ae142a5c1b724c183497bdb2
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Mon Jul 26 19:28:02 2021 +0200
d: Ensure casting from bool results in either 0 or 1 (PR96435)
If casting from bool, the result is either 0 or 1, any other value
violates @safe code, so enforce that it is never invalid.
PR d/96435
gcc/d/ChangeLog:
* d-convert.cc (convert_for_rvalue): New function.
* d-tree.h (convert_for_rvalue): Declare.
* expr.cc (ExprVisitor::visit (CastExp *)): Use convert_for_rvalue.
(build_return_dtor): Likewise.
gcc/testsuite/ChangeLog:
* gdc.dg/torture/pr96435.d: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug d/96435] d: Returning boolean in a union violates @safe code
2020-08-03 15:49 [Bug d/96435] New: d: Returning boolean in a union violates @safe code ibuclaw at gdcproject dot org
2021-07-29 15:12 ` [Bug d/96435] " cvs-commit at gcc dot gnu.org
@ 2021-07-29 15:20 ` cvs-commit at gcc dot gnu.org
2021-07-29 15:21 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-29 15:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96435
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:
https://gcc.gnu.org/g:22589586940439fb5878180a7c586ea753d179f6
commit r11-8816-g22589586940439fb5878180a7c586ea753d179f6
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Mon Jul 26 19:28:02 2021 +0200
d: Ensure casting from bool results in either 0 or 1 (PR96435)
If casting from bool, the result is either 0 or 1, any other value
violates @safe code, so enforce that it is never invalid.
PR d/96435
gcc/d/ChangeLog:
* d-convert.cc (convert_for_rvalue): New function.
* d-tree.h (convert_for_rvalue): Declare.
* expr.cc (ExprVisitor::visit (CastExp *)): Use convert_for_rvalue.
(build_return_dtor): Likewise.
gcc/testsuite/ChangeLog:
* gdc.dg/torture/pr96435.d: New test.
(cherry picked from commit 5c9b7408dc578cb2ae142a5c1b724c183497bdb2)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug d/96435] d: Returning boolean in a union violates @safe code
2020-08-03 15:49 [Bug d/96435] New: d: Returning boolean in a union violates @safe code ibuclaw at gdcproject dot org
2021-07-29 15:12 ` [Bug d/96435] " cvs-commit at gcc dot gnu.org
2021-07-29 15:20 ` cvs-commit at gcc dot gnu.org
@ 2021-07-29 15:21 ` cvs-commit at gcc dot gnu.org
2021-07-29 15:22 ` cvs-commit at gcc dot gnu.org
2021-07-29 15:27 ` ibuclaw at gdcproject dot org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-29 15:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96435
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:
https://gcc.gnu.org/g:10490b7a453159f9b602b7f273f0aa6b4caebca7
commit r10-10012-g10490b7a453159f9b602b7f273f0aa6b4caebca7
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Mon Jul 26 19:28:02 2021 +0200
d: Ensure casting from bool results in either 0 or 1 (PR96435)
If casting from bool, the result is either 0 or 1, any other value
violates @safe code, so enforce that it is never invalid.
PR d/96435
gcc/d/ChangeLog:
* d-convert.cc (convert_for_rvalue): New function.
* d-tree.h (convert_for_rvalue): Declare.
* expr.cc (ExprVisitor::visit (CastExp *)): Use convert_for_rvalue.
(build_return_dtor): Likewise.
gcc/testsuite/ChangeLog:
* gdc.dg/pr96435.d: New test.
(cherry picked from commit 5c9b7408dc578cb2ae142a5c1b724c183497bdb2)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug d/96435] d: Returning boolean in a union violates @safe code
2020-08-03 15:49 [Bug d/96435] New: d: Returning boolean in a union violates @safe code ibuclaw at gdcproject dot org
` (2 preceding siblings ...)
2021-07-29 15:21 ` cvs-commit at gcc dot gnu.org
@ 2021-07-29 15:22 ` cvs-commit at gcc dot gnu.org
2021-07-29 15:27 ` ibuclaw at gdcproject dot org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-29 15:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96435
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:
https://gcc.gnu.org/g:c848c0ec7fab0c0a220683ad234c8842939941cf
commit r9-9653-gc848c0ec7fab0c0a220683ad234c8842939941cf
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Mon Jul 26 19:28:02 2021 +0200
d: Ensure casting from bool results in either 0 or 1 (PR96435)
If casting from bool, the result is either 0 or 1, any other value
violates @safe code, so enforce that it is never invalid.
PR d/96435
gcc/d/ChangeLog:
* d-convert.cc (convert_for_rvalue): New function.
* d-tree.h (convert_for_rvalue): Declare.
* expr.cc (ExprVisitor::visit (CastExp *)): Use convert_for_rvalue.
(build_return_dtor): Likewise.
gcc/testsuite/ChangeLog:
* gdc.dg/pr96435.d: New test.
(cherry picked from commit 5c9b7408dc578cb2ae142a5c1b724c183497bdb2)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug d/96435] d: Returning boolean in a union violates @safe code
2020-08-03 15:49 [Bug d/96435] New: d: Returning boolean in a union violates @safe code ibuclaw at gdcproject dot org
` (3 preceding siblings ...)
2021-07-29 15:22 ` cvs-commit at gcc dot gnu.org
@ 2021-07-29 15:27 ` ibuclaw at gdcproject dot org
4 siblings, 0 replies; 6+ messages in thread
From: ibuclaw at gdcproject dot org @ 2021-07-29 15:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96435
Iain Buclaw <ibuclaw at gdcproject dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |FIXED
--- Comment #5 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
Fix committed.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-07-29 15:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-03 15:49 [Bug d/96435] New: d: Returning boolean in a union violates @safe code ibuclaw at gdcproject dot org
2021-07-29 15:12 ` [Bug d/96435] " cvs-commit at gcc dot gnu.org
2021-07-29 15:20 ` cvs-commit at gcc dot gnu.org
2021-07-29 15:21 ` cvs-commit at gcc dot gnu.org
2021-07-29 15:22 ` cvs-commit at gcc dot gnu.org
2021-07-29 15:27 ` ibuclaw at gdcproject dot 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).