From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id F1205385781F for ; Fri, 17 Feb 2023 17:08:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1205385781F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676653692; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8jqhvEDLswwUAuYqHT2AT0zBFh6j6Z7Zx2HqM/Tjnu8=; b=IJ2TXtu8+54iRRMB/X2NE5qNbtSwY0E5rvry1kb6LA2+OIQVbABXw9hKwBzphLyZXJdpSU 4ZQYoQfyrxR7ZX0a1BRNfb5Kdr8KRPwk0JWirGSVX0wuR8G2mO0LnhmNkZPPfh+OoIaX7k WhW3oG2yZiItFmRqTNfzwa8OCvHwWPc= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-290-klVGHXdiN-eZ8roObgJfcw-1; Fri, 17 Feb 2023 12:08:11 -0500 X-MC-Unique: klVGHXdiN-eZ8roObgJfcw-1 Received: by mail-qv1-f69.google.com with SMTP id x1-20020ad44581000000b0056bec2871e8so797039qvu.1 for ; Fri, 17 Feb 2023 09:08:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8jqhvEDLswwUAuYqHT2AT0zBFh6j6Z7Zx2HqM/Tjnu8=; b=5WswczJldggFp+4fgi7b3pA/dqt97kN0WhtZVovTXHgrSHEcqQWvhhemMavpExN5WY PAVIpcwK81n3rbIXiy5AmBNjrzPgJF546uLRtE2JdNZUJaOxZTHyYbly/M7qOsqDSwiD 7Cwvc7cXh0gl0AeLDN/QqGu/ZRwhrA90Dn1BUzouk1e3fCsktyCX3NiuCrtUCqeLSRl8 9wzESr8lYNHedpj3IcCDu3tgpEhQDmetKlco+l9fpArF8EmBvIgU4hXGlFL1evYl5TdC dtMJVIRAkmn2Cj4WJEp/rtPu0hpGVCvHxDbm09NrjycxwylbfTsh3+akBSbwrKHp7XnU U+Tw== X-Gm-Message-State: AO0yUKXa7vA9GzrUzhrLyA+77lpiqzfXuKCU5gCicjOB7d2n7VwqLQ0h mi+h9lJf+sFh+EgLoECHI/AaO2kcrkc0G+cXdvEEjSgl4kpFVFUvwKK+b1R8mf8FYkhrMhBdOW0 sjHzq7j0bQd94K/ghAA== X-Received: by 2002:a05:622a:18d:b0:3b6:3a12:2bf9 with SMTP id s13-20020a05622a018d00b003b63a122bf9mr2336036qtw.2.1676653690755; Fri, 17 Feb 2023 09:08:10 -0800 (PST) X-Google-Smtp-Source: AK7set98WvDXICudiHoXVeMfEQYbc9CFf2c9ZMbWGdpoq+7r++k4EYchFXoMga6NevT9Gv2IwNhMgw== X-Received: by 2002:a05:622a:18d:b0:3b6:3a12:2bf9 with SMTP id s13-20020a05622a018d00b003b63a122bf9mr2336004qtw.2.1676653690382; Fri, 17 Feb 2023 09:08:10 -0800 (PST) Received: from [192.168.1.108] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id t22-20020a05620a0b1600b0073917fae4f8sm3605749qkg.25.2023.02.17.09.08.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Feb 2023 09:08:09 -0800 (PST) Message-ID: <340c8b27-a042-43b5-4151-2341114da87a@redhat.com> Date: Fri, 17 Feb 2023 12:08:08 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: [PATCH] [vxworks] make wint_t and wchar_t the same distinct type To: Alexandre Oliva , gcc-patches@gcc.gnu.org Cc: hainque@adacore.com, joseph@codesourcery.com, nathan@acm.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2/17/23 23:04, Alexandre Oliva wrote: > > 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 And fixing that isn't an option? Do the integer builtins work properly if we force them to use wchar_t instead of an integer type? > 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. > > Regstrapped on x86_64-linux-gnu. > Tested on arm-vxworks7 (gcc-12) and arm-eabi (trunk). Ok to install? > > 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. > --- > 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 ae92cd5adaf5e..a92597c2f544f 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 b333f97fd3237..98f5aef2af95d 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 83580d0dec288..9733c90fe4c6f 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 ------------------ */ > >