public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x
@ 2023-10-19 20:02 amonakov at gcc dot gnu.org
2023-10-19 20:19 ` [Bug c/111884] " sjames at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: amonakov at gcc dot gnu.org @ 2023-10-19 20:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
Bug ID: 111884
Summary: unsigned char no longer aliases anything under
-std=c2x
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: amonakov at gcc dot gnu.org
Target Milestone: ---
int f(int i)
{
int f = 1;
return i[(unsigned char *)&f];
}
int g(int i)
{
int f = 1;
return i[(signed char *)&f];
}
int h(int i)
{
int f = 1;
return i[(char *)&f];
}
gcc -O2 -std=c2x compiles 'f' as though inspecting representation via an
'unsigned char *' is not valid (with a confusing warning under -Wall).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/111884] unsigned char no longer aliases anything under -std=c2x
2023-10-19 20:02 [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x amonakov at gcc dot gnu.org
@ 2023-10-19 20:19 ` sjames at gcc dot gnu.org
2023-10-19 20:23 ` joseph at codesourcery dot com
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-10-19 20:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
Sam James <sjames at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jsm28 at gcc dot gnu.org,
| |sjames at gcc dot gnu.org
--- Comment #1 from Sam James <sjames at gcc dot gnu.org> ---
Originally reported at
https://inbox.sourceware.org/gcc-help/e18818e9-396c-41fe-6c4a-9ac86c564525@ispras.ru/T/#m147d6322a26e2bc094dd5e0935b7f2223bc910ac.
Curious indeed..
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/111884] unsigned char no longer aliases anything under -std=c2x
2023-10-19 20:02 [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x amonakov at gcc dot gnu.org
2023-10-19 20:19 ` [Bug c/111884] " sjames at gcc dot gnu.org
@ 2023-10-19 20:23 ` joseph at codesourcery dot com
2023-10-19 20:30 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: joseph at codesourcery dot com @ 2023-10-19 20:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
I'm going to guess this was introduced by the char8_t changes ("C:
Implement C2X N2653 char8_t and UTF-8 string literal changes", commit
703837b2cc8ac03c53ac7cc0fb1327055acaebd2).
/* Unlike char, char8_t doesn't alias. */
if (flag_char8_t && t == char8_type_node)
return -1;
is not correct for C, where char8_t is not a distinct type.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/111884] unsigned char no longer aliases anything under -std=c2x
2023-10-19 20:02 [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x amonakov at gcc dot gnu.org
2023-10-19 20:19 ` [Bug c/111884] " sjames at gcc dot gnu.org
2023-10-19 20:23 ` joseph at codesourcery dot com
@ 2023-10-19 20:30 ` mpolacek at gcc dot gnu.org
2023-10-19 20:39 ` [Bug c/111884] [13/14 Regression] " pinskia at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-10-19 20:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
CC| |mpolacek at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thanks, I can test
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -3828,8 +3828,9 @@ c_common_get_alias_set (tree t)
if (!TYPE_P (t))
return -1;
- /* Unlike char, char8_t doesn't alias. */
- if (flag_char8_t && t == char8_type_node)
+ /* Unlike char, char8_t doesn't alias in C++. (In C, char8_t is not
+ a distinct type.) */
+ if (flag_char8_t && t == char8_type_node && c_dialect_cxx ())
return -1;
/* The C standard guarantees that any object may be accessed via an
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/111884] [13/14 Regression] unsigned char no longer aliases anything under -std=c2x
2023-10-19 20:02 [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x amonakov at gcc dot gnu.org
` (2 preceding siblings ...)
2023-10-19 20:30 ` mpolacek at gcc dot gnu.org
@ 2023-10-19 20:39 ` pinskia at gcc dot gnu.org
2023-10-19 20:57 ` tom at honermann dot net
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-19 20:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|unsigned char no longer |[13/14 Regression] unsigned
|aliases anything under |char no longer aliases
|-std=c2x |anything under -std=c2x
Keywords| |diagnostic
Target Milestone|--- |13.3
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/111884] [13/14 Regression] unsigned char no longer aliases anything under -std=c2x
2023-10-19 20:02 [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x amonakov at gcc dot gnu.org
` (3 preceding siblings ...)
2023-10-19 20:39 ` [Bug c/111884] [13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-10-19 20:57 ` tom at honermann dot net
2023-10-20 6:51 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: tom at honermann dot net @ 2023-10-19 20:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
--- Comment #4 from Tom Honermann <tom at honermann dot net> ---
(In reply to Marek Polacek from comment #3)
> Thanks, I can test
Thank you. That change looks right. My apologies for introducing the
regression.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/111884] [13/14 Regression] unsigned char no longer aliases anything under -std=c2x
2023-10-19 20:02 [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x amonakov at gcc dot gnu.org
` (4 preceding siblings ...)
2023-10-19 20:57 ` tom at honermann dot net
@ 2023-10-20 6:51 ` rguenth at gcc dot gnu.org
2023-10-20 19:37 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-20 6:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/111884] [13/14 Regression] unsigned char no longer aliases anything under -std=c2x
2023-10-19 20:02 [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x amonakov at gcc dot gnu.org
` (5 preceding siblings ...)
2023-10-20 6:51 ` rguenth at gcc dot gnu.org
@ 2023-10-20 19:37 ` cvs-commit at gcc dot gnu.org
2023-10-20 19:40 ` cvs-commit at gcc dot gnu.org
2023-10-20 19:40 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-20 19:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:281699fbff6262766674ab13087d37db751cd40a
commit r14-4802-g281699fbff6262766674ab13087d37db751cd40a
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Oct 19 16:32:10 2023 -0400
c-family: char8_t and aliasing in C vs C++ [PR111884]
In the PR, Joseph says that in C char8_t is not a distinct type. So
we should behave as if it can alias anything, like ordinary char.
In C, unsigned_char_type_node == char8_type_node, so with this patch
we return 0 instead of -1. And the following comment says:
/* The C standard guarantees that any object may be accessed via an
lvalue that has narrow character type (except char8_t). */
if (t == char_type_node
|| t == signed_char_type_node
|| t == unsigned_char_type_node)
return 0;
Which appears to be wrong, so I'm adjusting that as well.
PR c/111884
gcc/c-family/ChangeLog:
* c-common.cc (c_common_get_alias_set): Return -1 for char8_t only
in C++.
gcc/testsuite/ChangeLog:
* c-c++-common/alias-1.c: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/111884] [13/14 Regression] unsigned char no longer aliases anything under -std=c2x
2023-10-19 20:02 [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x amonakov at gcc dot gnu.org
` (6 preceding siblings ...)
2023-10-20 19:37 ` cvs-commit at gcc dot gnu.org
@ 2023-10-20 19:40 ` cvs-commit at gcc dot gnu.org
2023-10-20 19:40 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-20 19:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:4f93c6027fb09c94ca8dc7fe13f92a3b9205b68a
commit r13-7967-g4f93c6027fb09c94ca8dc7fe13f92a3b9205b68a
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Oct 19 16:32:10 2023 -0400
c-family: char8_t and aliasing in C vs C++ [PR111884]
In the PR, Joseph says that in C char8_t is not a distinct type. So
we should behave as if it can alias anything, like ordinary char.
In C, unsigned_char_type_node == char8_type_node, so with this patch
we return 0 instead of -1. And the following comment says:
/* The C standard guarantees that any object may be accessed via an
lvalue that has narrow character type (except char8_t). */
if (t == char_type_node
|| t == signed_char_type_node
|| t == unsigned_char_type_node)
return 0;
Which appears to be wrong, so I'm adjusting that as well.
PR c/111884
gcc/c-family/ChangeLog:
* c-common.cc (c_common_get_alias_set): Return -1 for char8_t only
in C++.
gcc/testsuite/ChangeLog:
* c-c++-common/alias-1.c: New test.
(cherry picked from commit 281699fbff6262766674ab13087d37db751cd40a)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/111884] [13/14 Regression] unsigned char no longer aliases anything under -std=c2x
2023-10-19 20:02 [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x amonakov at gcc dot gnu.org
` (7 preceding siblings ...)
2023-10-20 19:40 ` cvs-commit at gcc dot gnu.org
@ 2023-10-20 19:40 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-10-20 19:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Resolution|--- |FIXED
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-10-20 19:41 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-19 20:02 [Bug c/111884] New: unsigned char no longer aliases anything under -std=c2x amonakov at gcc dot gnu.org
2023-10-19 20:19 ` [Bug c/111884] " sjames at gcc dot gnu.org
2023-10-19 20:23 ` joseph at codesourcery dot com
2023-10-19 20:30 ` mpolacek at gcc dot gnu.org
2023-10-19 20:39 ` [Bug c/111884] [13/14 Regression] " pinskia at gcc dot gnu.org
2023-10-19 20:57 ` tom at honermann dot net
2023-10-20 6:51 ` rguenth at gcc dot gnu.org
2023-10-20 19:37 ` cvs-commit at gcc dot gnu.org
2023-10-20 19:40 ` cvs-commit at gcc dot gnu.org
2023-10-20 19:40 ` mpolacek 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).