public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] [vxworks] make wint_t and wchar_t the same distinct type
@ 2023-02-23 13:26 Alexandre Oliva
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-02-23 13:26 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:6936ea500d53d08827b395a5b5bf422be92f69fb
commit 6936ea500d53d08827b395a5b5bf422be92f69fb
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Feb 16 06:52:19 2023 -0300
[vxworks] make wint_t and wchar_t the same distinct type
We used to define WINT_TYPE to WCHAR_TYPE, so that both wint_t and
wchar_t mapped to the same underlying type, but this caused a glitch
in Wstringop-overflow-6.C: on vxworks, wint_t is typedef'ed to
wchar_t, headers got included in the test that declared functions that
take wint_t parameters, and those conflicted with the builtin
declarations that had wint_t mapped to the underlying integral type.
The problem is that, in C++, wchar_t is a distinct type. Having
wint_t be a typedef to wchar_t in the headers, but a typedef to
wchar_t's underlying integral type in builtins, makes for mismatches
between the declarations.
This patch defines WINT_TYPE to "wchar_t" for vxworks, and adjusts the
fallout, namely:
- since wchar_t may not have been defined yet when
c_common_nodes_and_builtins runs, use the node already reserved for
wchar_t for wint_t when WINT_TYPE is defined to wchar_t.
- for the same reason, when WINT_TYPE is wchar_t and we're not
compiling C++ where wchar_t is a compiler built-in, define
__WINT_TYPE__ to WCHAR_TYPE rather than WINT_TYPE, because wchar_t
may not even be defined in the translation unit.
- recognize and handle wchar_type_node when type_suffix is called for
wint_type_node.
for gcc/ChangeLog
* config/vx-common.h (WINT_TYPE): Alias to "wchar_t".
for gcc/c-family/ChangeLog
* c-common.cc (c_common_nodes_and_builtins): Take
wchar_type_node for wint_type_node when aliased.
(c_stddef_cpp_builtins): Define __WINT_TYPE__, when aliased to
wchar_t, to the underlying type rather than wchar_t in
non-C++.
* c-cppbuiltin.cc (type_suffix): Handle wchar_type_node.
Diff:
---
gcc/c-family/c-common.cc | 16 +++++++++++++---
gcc/c-family/c-cppbuiltin.cc | 2 ++
gcc/config/vx-common.h | 2 +-
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index ae92cd5adaf..a92597c2f54 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -4576,8 +4576,11 @@ c_common_nodes_and_builtins (void)
char32_array_type_node
= build_array_type (char32_type_node, array_domain_type);
- wint_type_node =
- TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
+ if (strcmp (WINT_TYPE, "wchar_t") == 0)
+ wint_type_node = wchar_type_node;
+ else
+ wint_type_node =
+ TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
intmax_type_node =
TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
@@ -5359,7 +5362,14 @@ c_stddef_cpp_builtins(void)
builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
- builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
+ /* C++ has wchar_t as a builtin type, C doesn't, so if WINT_TYPE
+ maps to wchar_t, define it to the underlying WCHAR_TYPE in C, and
+ to wchar_t in C++, so the desired type equivalence holds. */
+ if (!c_dialect_cxx ()
+ && strcmp (WINT_TYPE, "wchar_t") == 0)
+ builtin_define_with_value ("__WINT_TYPE__", WCHAR_TYPE, 0);
+ else
+ builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
if (flag_char8_t)
diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index b333f97fd32..98f5aef2af9 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -1903,6 +1903,8 @@ type_suffix (tree type)
systems use it anyway. */
|| type == char_type_node)
is_long = 0;
+ else if (type == wchar_type_node)
+ return type_suffix (underlying_wchar_type_node);
else
gcc_unreachable ();
diff --git a/gcc/config/vx-common.h b/gcc/config/vx-common.h
index 83580d0dec2..9733c90fe4c 100644
--- a/gcc/config/vx-common.h
+++ b/gcc/config/vx-common.h
@@ -69,7 +69,7 @@ along with GCC; see the file COPYING3. If not see
#undef WINT_TYPE_SIZE
#define WINT_TYPE_SIZE WCHAR_TYPE_SIZE
#undef WINT_TYPE
-#define WINT_TYPE WCHAR_TYPE
+#define WINT_TYPE "wchar_t"
/* ---------------------- Debug and unwind info formats ------------------ */
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] [vxworks] make wint_t and wchar_t the same distinct type
@ 2023-02-23 14:02 Alexandre Oliva
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-02-23 14:02 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c527b2d748aa542b32eca0a1e3a402dbefd5f879
commit c527b2d748aa542b32eca0a1e3a402dbefd5f879
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Feb 23 11:01:16 2023 -0300
[vxworks] make wint_t and wchar_t the same distinct type
We used to define WINT_TYPE to WCHAR_TYPE, so that both wint_t and
wchar_t mapped to the same underlying type, but this caused a glitch
in Wstringop-overflow-6.C: on vxworks, wint_t is typedef'ed to
wchar_t, headers got included in the test that declared functions that
take wint_t parameters, and those conflicted with the builtin
declarations that had wint_t mapped to the underlying integral type.
The problem is that, in C++, wchar_t is a distinct type. Having
wint_t be a typedef to wchar_t in the headers, but a typedef to
wchar_t's underlying integral type in builtins, makes for mismatches
between the declarations.
This patch defines WINT_TYPE to "wchar_t" for vxworks, and adjusts the
fallout, namely:
- since wchar_t may not have been defined yet when
c_common_nodes_and_builtins runs, use the node already reserved for
wchar_t for wint_t when WINT_TYPE is defined to wchar_t.
- for the same reason, when WINT_TYPE is wchar_t and we're not
compiling C++ where wchar_t is a compiler built-in, define
__WINT_TYPE__ to WCHAR_TYPE rather than WINT_TYPE, because wchar_t
may not even be defined in the translation unit.
- recognize and handle wchar_type_node when type_suffix is called for
wint_type_node.
for gcc/ChangeLog
* config/vx-common.h (WINT_TYPE): Alias to "wchar_t".
for gcc/c-family/ChangeLog
* c-common.cc (c_common_nodes_and_builtins): Take
wchar_type_node for wint_type_node when aliased.
(c_stddef_cpp_builtins): Define __WINT_TYPE__, when aliased to
wchar_t, to the underlying type rather than wchar_t in
non-C++.
* c-cppbuiltin.cc (type_suffix): Handle wchar_type_node.
Diff:
---
gcc/c-family/c-common.cc | 16 +++++++++++++---
gcc/c-family/c-cppbuiltin.cc | 2 ++
gcc/config/vx-common.h | 2 +-
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index ae92cd5adaf..a92597c2f54 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -4576,8 +4576,11 @@ c_common_nodes_and_builtins (void)
char32_array_type_node
= build_array_type (char32_type_node, array_domain_type);
- wint_type_node =
- TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
+ if (strcmp (WINT_TYPE, "wchar_t") == 0)
+ wint_type_node = wchar_type_node;
+ else
+ wint_type_node =
+ TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
intmax_type_node =
TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
@@ -5359,7 +5362,14 @@ c_stddef_cpp_builtins(void)
builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
- builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
+ /* C++ has wchar_t as a builtin type, C doesn't, so if WINT_TYPE
+ maps to wchar_t, define it to the underlying WCHAR_TYPE in C, and
+ to wchar_t in C++, so the desired type equivalence holds. */
+ if (!c_dialect_cxx ()
+ && strcmp (WINT_TYPE, "wchar_t") == 0)
+ builtin_define_with_value ("__WINT_TYPE__", WCHAR_TYPE, 0);
+ else
+ builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
if (flag_char8_t)
diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index b333f97fd32..98f5aef2af9 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -1903,6 +1903,8 @@ type_suffix (tree type)
systems use it anyway. */
|| type == char_type_node)
is_long = 0;
+ else if (type == wchar_type_node)
+ return type_suffix (underlying_wchar_type_node);
else
gcc_unreachable ();
diff --git a/gcc/config/vx-common.h b/gcc/config/vx-common.h
index 83580d0dec2..9733c90fe4c 100644
--- a/gcc/config/vx-common.h
+++ b/gcc/config/vx-common.h
@@ -69,7 +69,7 @@ along with GCC; see the file COPYING3. If not see
#undef WINT_TYPE_SIZE
#define WINT_TYPE_SIZE WCHAR_TYPE_SIZE
#undef WINT_TYPE
-#define WINT_TYPE WCHAR_TYPE
+#define WINT_TYPE "wchar_t"
/* ---------------------- Debug and unwind info formats ------------------ */
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] [vxworks] make wint_t and wchar_t the same distinct type
@ 2023-02-23 13:57 Alexandre Oliva
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-02-23 13:57 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:281be2027b3a7ec6b27d6927eeee0e7b6d7e36f1
commit 281be2027b3a7ec6b27d6927eeee0e7b6d7e36f1
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Feb 23 10:30:47 2023 -0300
[vxworks] make wint_t and wchar_t the same distinct type
We used to define WINT_TYPE to WCHAR_TYPE, so that both wint_t and
wchar_t mapped to the same underlying type, but this caused a glitch
in Wstringop-overflow-6.C: on vxworks, wint_t is typedef'ed to
wchar_t, headers got included in the test that declared functions that
take wint_t parameters, and those conflicted with the builtin
declarations that had wint_t mapped to the underlying integral type.
The problem is that, in C++, wchar_t is a distinct type. Having
wint_t be a typedef to wchar_t in the headers, but a typedef to
wchar_t's underlying integral type in builtins, makes for mismatches
between the declarations.
This patch defines WINT_TYPE to "wchar_t" for vxworks, and adjusts the
fallout, namely:
- since wchar_t may not have been defined yet when
c_common_nodes_and_builtins runs, use the node already reserved for
wchar_t for wint_t when WINT_TYPE is defined to wchar_t.
- for the same reason, when WINT_TYPE is wchar_t and we're not
compiling C++ where wchar_t is a compiler built-in, define
__WINT_TYPE__ to WCHAR_TYPE rather than WINT_TYPE, because wchar_t
may not even be defined in the translation unit.
- recognize and handle wchar_type_node when type_suffix is called for
wint_type_node.
for gcc/ChangeLog
* config/vx-common.h (WINT_TYPE): Alias to "wchar_t".
for gcc/c-family/ChangeLog
* c-common.cc (c_common_nodes_and_builtins): Take
wchar_type_node for wint_type_node when aliased.
(c_stddef_cpp_builtins): Define __WINT_TYPE__, when aliased to
wchar_t, to the underlying type rather than wchar_t in
non-C++.
* c-cppbuiltin.cc (type_suffix): Handle wchar_type_node.
Diff:
---
gcc/c-family/c-common.cc | 16 +++++++++++++---
gcc/c-family/c-cppbuiltin.cc | 2 ++
gcc/config/vx-common.h | 2 +-
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index ae92cd5adaf..a92597c2f54 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -4576,8 +4576,11 @@ c_common_nodes_and_builtins (void)
char32_array_type_node
= build_array_type (char32_type_node, array_domain_type);
- wint_type_node =
- TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
+ if (strcmp (WINT_TYPE, "wchar_t") == 0)
+ wint_type_node = wchar_type_node;
+ else
+ wint_type_node =
+ TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
intmax_type_node =
TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
@@ -5359,7 +5362,14 @@ c_stddef_cpp_builtins(void)
builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
- builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
+ /* C++ has wchar_t as a builtin type, C doesn't, so if WINT_TYPE
+ maps to wchar_t, define it to the underlying WCHAR_TYPE in C, and
+ to wchar_t in C++, so the desired type equivalence holds. */
+ if (!c_dialect_cxx ()
+ && strcmp (WINT_TYPE, "wchar_t") == 0)
+ builtin_define_with_value ("__WINT_TYPE__", WCHAR_TYPE, 0);
+ else
+ builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
if (flag_char8_t)
diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index b333f97fd32..98f5aef2af9 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -1903,6 +1903,8 @@ type_suffix (tree type)
systems use it anyway. */
|| type == char_type_node)
is_long = 0;
+ else if (type == wchar_type_node)
+ return type_suffix (underlying_wchar_type_node);
else
gcc_unreachable ();
diff --git a/gcc/config/vx-common.h b/gcc/config/vx-common.h
index 83580d0dec2..9733c90fe4c 100644
--- a/gcc/config/vx-common.h
+++ b/gcc/config/vx-common.h
@@ -69,7 +69,7 @@ along with GCC; see the file COPYING3. If not see
#undef WINT_TYPE_SIZE
#define WINT_TYPE_SIZE WCHAR_TYPE_SIZE
#undef WINT_TYPE
-#define WINT_TYPE WCHAR_TYPE
+#define WINT_TYPE "wchar_t"
/* ---------------------- Debug and unwind info formats ------------------ */
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] [vxworks] make wint_t and wchar_t the same distinct type
@ 2023-02-23 13:49 Alexandre Oliva
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-02-23 13:49 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d27c078fa87e22142c6748bf0246b6055d31571b
commit d27c078fa87e22142c6748bf0246b6055d31571b
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Feb 23 10:30:47 2023 -0300
[vxworks] make wint_t and wchar_t the same distinct type
We used to define WINT_TYPE to WCHAR_TYPE, so that both wint_t and
wchar_t mapped to the same underlying type, but this caused a glitch
in Wstringop-overflow-6.C: on vxworks, wint_t is typedef'ed to
wchar_t, headers got included in the test that declared functions that
take wint_t parameters, and those conflicted with the builtin
declarations that had wint_t mapped to the underlying integral type.
The problem is that, in C++, wchar_t is a distinct type. Having
wint_t be a typedef to wchar_t in the headers, but a typedef to
wchar_t's underlying integral type in builtins, makes for mismatches
between the declarations.
This patch defines WINT_TYPE to "wchar_t" for vxworks, and adjusts the
fallout, namely:
- since wchar_t may not have been defined yet when
c_common_nodes_and_builtins runs, use the node already reserved for
wchar_t for wint_t when WINT_TYPE is defined to wchar_t.
- for the same reason, when WINT_TYPE is wchar_t and we're not
compiling C++ where wchar_t is a compiler built-in, define
__WINT_TYPE__ to WCHAR_TYPE rather than WINT_TYPE, because wchar_t
may not even be defined in the translation unit.
- recognize and handle wchar_type_node when type_suffix is called for
wint_type_node.
for gcc/ChangeLog
* config/vx-common.h (WINT_TYPE): Alias to "wchar_t".
for gcc/c-family/ChangeLog
* c-common.cc (c_common_nodes_and_builtins): Take
wchar_type_node for wint_type_node when aliased.
(c_stddef_cpp_builtins): Define __WINT_TYPE__, when aliased to
wchar_t, to the underlying type rather than wchar_t in
non-C++.
* c-cppbuiltin.cc (type_suffix): Handle wchar_type_node.
Diff:
---
gcc/c-family/c-common.cc | 16 +++++++++++++---
gcc/c-family/c-cppbuiltin.cc | 2 ++
gcc/config/vx-common.h | 2 +-
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index ae92cd5adaf..a92597c2f54 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -4576,8 +4576,11 @@ c_common_nodes_and_builtins (void)
char32_array_type_node
= build_array_type (char32_type_node, array_domain_type);
- wint_type_node =
- TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
+ if (strcmp (WINT_TYPE, "wchar_t") == 0)
+ wint_type_node = wchar_type_node;
+ else
+ wint_type_node =
+ TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
intmax_type_node =
TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
@@ -5359,7 +5362,14 @@ c_stddef_cpp_builtins(void)
builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
- builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
+ /* C++ has wchar_t as a builtin type, C doesn't, so if WINT_TYPE
+ maps to wchar_t, define it to the underlying WCHAR_TYPE in C, and
+ to wchar_t in C++, so the desired type equivalence holds. */
+ if (!c_dialect_cxx ()
+ && strcmp (WINT_TYPE, "wchar_t") == 0)
+ builtin_define_with_value ("__WINT_TYPE__", WCHAR_TYPE, 0);
+ else
+ builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
if (flag_char8_t)
diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index b333f97fd32..98f5aef2af9 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -1903,6 +1903,8 @@ type_suffix (tree type)
systems use it anyway. */
|| type == char_type_node)
is_long = 0;
+ else if (type == wchar_type_node)
+ return type_suffix (underlying_wchar_type_node);
else
gcc_unreachable ();
diff --git a/gcc/config/vx-common.h b/gcc/config/vx-common.h
index 83580d0dec2..9733c90fe4c 100644
--- a/gcc/config/vx-common.h
+++ b/gcc/config/vx-common.h
@@ -69,7 +69,7 @@ along with GCC; see the file COPYING3. If not see
#undef WINT_TYPE_SIZE
#define WINT_TYPE_SIZE WCHAR_TYPE_SIZE
#undef WINT_TYPE
-#define WINT_TYPE WCHAR_TYPE
+#define WINT_TYPE "wchar_t"
/* ---------------------- Debug and unwind info formats ------------------ */
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] [vxworks] make wint_t and wchar_t the same distinct type
@ 2023-02-16 11:12 Alexandre Oliva
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-02-16 11:12 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:27f1d9aa5b6de8c89356608519c30ca1d4469ee7
commit 27f1d9aa5b6de8c89356608519c30ca1d4469ee7
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Feb 16 06:52:19 2023 -0300
[vxworks] make wint_t and wchar_t the same distinct type
We used to define WINT_TYPE to WCHAR_TYPE, so that both wint_t and
wchar_t mapped to the same underlying type, but this caused a glitch
in Wstringop-overflow-6.C: on vxworks, wint_t is typedef'ed to
wchar_t, headers got included in the test that declared functions that
take wint_t parameters, and those conflicted with the builtin
declarations that had wint_t mapped to the underlying integral type.
The problem is that, in C++, wchar_t is a distinct type. Having
wint_t be a typedef to wchar_t in the headers, but a typedef to
wchar_t's underlying integral type in builtins, makes for mismatches
between the declarations.
This patch defines WINT_TYPE to "wchar_t" for vxworks, and adjusts the
fallout, namely:
- since wchar_t may not have been defined yet when
c_common_nodes_and_builtins runs, use the node already reserved for
wchar_t for wint_t when WINT_TYPE is defined to wchar_t.
- for the same reason, when WINT_TYPE is wchar_t and we're not
compiling C++ where wchar_t is a compiler built-in, define
__WINT_TYPE__ to WCHAR_TYPE rather than WINT_TYPE, because wchar_t
may not even be defined in the translation unit.
- recognize and handle wchar_type_node when type_suffix is called for
wint_type_node.
for gcc/ChangeLog
* config/vx-common.h (WINT_TYPE): Alias to "wchar_t".
for gcc/c-family/ChangeLog
* c-common.cc (c_common_nodes_and_builtins): Take
wchar_type_node for wint_type_node when aliased.
(c_stddef_cpp_builtins): Define __WINT_TYPE__, when aliased to
wchar_t, to the underlying type rather than wchar_t in
non-C++.
* c-cppbuiltin.cc (type_suffix): Handle wchar_type_node.
Diff:
---
gcc/c-family/c-common.cc | 16 +++++++++++++---
gcc/c-family/c-cppbuiltin.cc | 2 ++
gcc/config/vx-common.h | 2 +-
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index ae92cd5adaf..a92597c2f54 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -4576,8 +4576,11 @@ c_common_nodes_and_builtins (void)
char32_array_type_node
= build_array_type (char32_type_node, array_domain_type);
- wint_type_node =
- TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
+ if (strcmp (WINT_TYPE, "wchar_t") == 0)
+ wint_type_node = wchar_type_node;
+ else
+ wint_type_node =
+ TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
intmax_type_node =
TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
@@ -5359,7 +5362,14 @@ c_stddef_cpp_builtins(void)
builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
- builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
+ /* C++ has wchar_t as a builtin type, C doesn't, so if WINT_TYPE
+ maps to wchar_t, define it to the underlying WCHAR_TYPE in C, and
+ to wchar_t in C++, so the desired type equivalence holds. */
+ if (!c_dialect_cxx ()
+ && strcmp (WINT_TYPE, "wchar_t") == 0)
+ builtin_define_with_value ("__WINT_TYPE__", WCHAR_TYPE, 0);
+ else
+ builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
if (flag_char8_t)
diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index b333f97fd32..98f5aef2af9 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -1903,6 +1903,8 @@ type_suffix (tree type)
systems use it anyway. */
|| type == char_type_node)
is_long = 0;
+ else if (type == wchar_type_node)
+ return type_suffix (underlying_wchar_type_node);
else
gcc_unreachable ();
diff --git a/gcc/config/vx-common.h b/gcc/config/vx-common.h
index 83580d0dec2..9733c90fe4c 100644
--- a/gcc/config/vx-common.h
+++ b/gcc/config/vx-common.h
@@ -69,7 +69,7 @@ along with GCC; see the file COPYING3. If not see
#undef WINT_TYPE_SIZE
#define WINT_TYPE_SIZE WCHAR_TYPE_SIZE
#undef WINT_TYPE
-#define WINT_TYPE WCHAR_TYPE
+#define WINT_TYPE "wchar_t"
/* ---------------------- Debug and unwind info formats ------------------ */
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-02-23 14:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-23 13:26 [gcc(refs/users/aoliva/heads/testme)] [vxworks] make wint_t and wchar_t the same distinct type Alexandre Oliva
-- strict thread matches above, loose matches on Subject: below --
2023-02-23 14:02 Alexandre Oliva
2023-02-23 13:57 Alexandre Oliva
2023-02-23 13:49 Alexandre Oliva
2023-02-16 11:12 Alexandre Oliva
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).