From patchwork Fri Feb 17 07:04:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 58370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp740451wrn; Thu, 16 Feb 2023 23:05:51 -0800 (PST) X-Google-Smtp-Source: AK7set9zLfiD9XDeteFQb8KqKM2g/zhR1T1fLEeRd+B8PuZwFid7MicavEz2KhvBg+AJ7ubgJSck X-Received: by 2002:a17:907:3e15:b0:8b2:fb3d:95e6 with SMTP id hp21-20020a1709073e1500b008b2fb3d95e6mr1192669ejc.74.1676617551483; Thu, 16 Feb 2023 23:05:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676617551; cv=none; d=google.com; s=arc-20160816; b=b1IS8raQggk4FawF6wmYiaNwxUYnZwWqODxG6T2UKEdzn/iM4sv5E37ViF6A20DhdR oWf724DEZoB2Nf/NYXPxi/q3E2XqXIvlCNrhhMwDAF9u0moPgQxFCbK9ugLZzxJLCgDt rQAG9oR0e5IXYUM03kKAbofvPJoHh0MeNYRxKChJRuRIHZ6Ud9U4TjrQLjWw54uDN+yl Jy23LS2rg2xAWHIC1Nb++ZX/Ife39nydTcWMSevA7eCRjPq/FaHB9QF+elH5STXeat8g uwUNsEe/URc7xexLQt2RxJ2QG0BrjwxWzUoQi0fM477pmzWCJO7TvWKiX4BcD9zsfG+z o2fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:message-id:date:organization:subject:cc:to:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=7+lrmbuyIWpvb6h/7A4QIvjYm1CfR6M3gWAlANj3OwI=; b=ihd4kEYWPlna2Z33qvgvGxypa+0RLv4WwsC34/EnVtrRbO1vfRfYTRN+ZXmT+yIg4m Q8jpWLFAqLKpsaKsadvjFQEtEbRGZBXLzyJwj25BzYn7LZQhrM19VmTinccdCdoyyc4P QvQpA6CPLfcySdu+i2sZVF/IgKMb79ncGi0n8s5F+qfITREuqH0DpX+S6fQVm89CZKh8 N3trKmd7AlH0Ah+Zz6r1rHb2yF1J4CArZzl29m0o+jHoUcaIq4ZvgCKPkiCUOgceXluL EDxNiQNlSuup98wK3QWEPtJQbxSKCxYE/e/bgLq78Fc0Jpj4759OAhLz6TxiEut2cAyX CBxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=O9Kw+W3E; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j29-20020a170906105d00b008b1417a763dsi5482621ejj.796.2023.02.16.23.05.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 23:05:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=O9Kw+W3E; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4ABF23858296 for ; Fri, 17 Feb 2023 07:05:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4ABF23858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676617550; bh=7+lrmbuyIWpvb6h/7A4QIvjYm1CfR6M3gWAlANj3OwI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=O9Kw+W3E5Xu0bKMKqROagHF9CUclATx3vzluMs70F8NN4bKi9wSx0pIiO+f41c1zD 7iYYMVgEbncUL7FqExlVOb4Wzg5YnqQLbnPHV3K+N7arrPtmK6TSl2d0tYCCj0LT7y iUfPUG9rBgl8TXlmN2Seplkt6Wp0fAzRwZhAuh2Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTPS id 8250F3858D33 for ; Fri, 17 Feb 2023 07:05:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8250F3858D33 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5624B116B60; Fri, 17 Feb 2023 02:05:06 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id m0tQ6jJKFgW3; Fri, 17 Feb 2023 02:05:06 -0500 (EST) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 89180116936; Fri, 17 Feb 2023 02:05:05 -0500 (EST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 31H74nO4090795 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 17 Feb 2023 04:04:49 -0300 To: gcc-patches@gcc.gnu.org Cc: hainque@adacore.com, joseph@codesourcery.com, jason@redhat.com, nathan@acm.org Subject: [PATCH] [vxworks] make wint_t and wchar_t the same distinct type Organization: Free thinker, does not speak for AdaCore Date: Fri, 17 Feb 2023 04:04:49 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alexandre Oliva via Gcc-patches From: Alexandre Oliva Reply-To: Alexandre Oliva Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758060925792582787?= X-GMAIL-MSGID: =?utf-8?q?1758060925792582787?= 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. 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 ------------------ */