From owner-freebsd-ppc@freebsd.org Thu Jul 14 01:00:34 2016 Return-Path: Delivered-To: freebsd-ppc@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 769B1B97653 for ; Thu, 14 Jul 2016 01:00:34 +0000 (UTC) (envelope-from mailing-machine@vniz.net) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E61FB13C5 for ; Thu, 14 Jul 2016 01:00:33 +0000 (UTC) (envelope-from mailing-machine@vniz.net) Received: by mail-lf0-f47.google.com with SMTP id f93so51204563lfi.2 for ; Wed, 13 Jul 2016 18:00:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=GaZX3Zul7amFxu9OXBSO+o+VbSL2HHuNJ57ZuUh8dXA=; b=hXNNUND7XzQeaU3tyq4Mvx+bYSjzKP51UX2TfnRwJdZWxabqbkUMXZlhxiHgv/z98i Zj6vbe24UepIXF5mamyVVAMkH6ME3QBQhl+lbScTcFAbN7Dd/tG/vTMZpz1KIrQBgU3E q8wR8Xu6523jKStHC9TgmRiOTcilCDs36dehYsyodYpXt2vGlOnoiV3NaB93JsG6bYco hcnsLkXrPTp4qJ9KHgfeiTVuNuBUA7TPXn8k07e05LXVGP5B44U7ht5PhJ36OP5V7jVH t4iXz92MedSbs+TW3NlVCrCd+dYR+ZwVeWM5LIeAGjlb6DsbLnPk0D4VHJ/uu00pIcR1 uqnw== X-Gm-Message-State: ALyK8tJ2FVQMQrb+mJqpMX72hzxoLMvnvcRoN5aXrsBTVjFqJKLzkF5BOoG+ulitfK8WQw== X-Received: by 10.25.154.136 with SMTP id c130mr5564967lfe.87.1468458026291; Wed, 13 Jul 2016 18:00:26 -0700 (PDT) Received: from [192.168.1.2] ([89.169.173.68]) by smtp.gmail.com with ESMTPSA id o10sm2456631lfo.47.2016.07.13.18.00.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jul 2016 18:00:25 -0700 (PDT) Subject: Re: svn commit: r302601 - in head/sys: arm/include arm64/include [clang 3.8.0: powerpc has odd mix of signed wchar_t and unsigned char] To: Mark Millard References: <46153340-D2F4-48BD-B738-4792BC25FA3F@dsl-only.net> <38CF2C28-3BD1-4D09-939F-4DD0C2E8B58F@dsl-only.net> Cc: svn-src-head@freebsd.org, FreeBSD Current , freebsd-stable@freebsd.org, freebsd-arm , FreeBSD PowerPC ML , Bruce Evans , FreeBSD Toolchain From: Andrey Chernov Message-ID: Date: Thu, 14 Jul 2016 04:00:24 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <38CF2C28-3BD1-4D09-939F-4DD0C2E8B58F@dsl-only.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-ppc@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Porting FreeBSD to the PowerPC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jul 2016 01:00:34 -0000 On 13.07.2016 11:53, Mark Millard wrote: > [The below does note that TARGET=powerpc has a mix of signed wchar_t and unsigned char types and most architectures have both being signed types.] POSIX says nothing about wchar_t and char should be the same (un)signed. It is arm ABI docs may say so only. They are different entities differently encoded and cross assigning between wchar_t and char is not recommended. > > On 2016-Jul-11, at 8:57 PM, Andrey Chernov wrote: > >> On 12.07.2016 5:44, Mark Millard wrote: >>> My understanding of the criteria for __WCHAR_MIN and __WCHAR_MAX: >>> >>> A) __WCHAR_MIN and __WCHAR_MAX: same type as the integer promotion of >>> ___wchar_t (if that is distinct). >>> B) __WCHAR_MIN is the low value for ___wchar_t as an integer type; not >>> necessarily a valid char value >>> C) __WCHAR_MAX is the high value for ___wchar_t as an integer type; not >>> necessarily a valid char value >> >> It seems you are right about "not a valid char value", I'll back this >> change out. >> >>> As far as I know arm FreeBSD uses unsigned character types (of whatever >>> width). >> >> Probably it should be unsigned for other architectures too, clang does >> not generate negative values with L'' literals and locale use only >> positive values too. > > Looking around: > > # grep -i wchar sys/*/include/_types.h > sys/arm/include/_types.h:typedef unsigned int ___wchar_t; > sys/arm/include/_types.h:#define __WCHAR_MIN 0 /* min value for a wchar_t */ > sys/arm/include/_types.h:#define __WCHAR_MAX __UINT_MAX /* max value for a wchar_t */ > sys/arm64/include/_types.h:typedef unsigned int ___wchar_t; > sys/arm64/include/_types.h:#define __WCHAR_MIN 0 /* min value for a wchar_t */ > sys/arm64/include/_types.h:#define __WCHAR_MAX __UINT_MAX /* max value for a wchar_t */ > sys/mips/include/_types.h:typedef int ___wchar_t; > sys/mips/include/_types.h:#define __WCHAR_MIN __INT_MIN /* min value for a wchar_t */ > sys/mips/include/_types.h:#define __WCHAR_MAX __INT_MAX /* max value for a wchar_t */ > sys/powerpc/include/_types.h:typedef int ___wchar_t; > sys/powerpc/include/_types.h:#define __WCHAR_MIN __INT_MIN /* min value for a wchar_t */ > sys/powerpc/include/_types.h:#define __WCHAR_MAX __INT_MAX /* max value for a wchar_t */ > sys/riscv/include/_types.h:typedef int ___wchar_t; > sys/riscv/include/_types.h:#define __WCHAR_MIN __INT_MIN /* min value for a wchar_t */ > sys/riscv/include/_types.h:#define __WCHAR_MAX __INT_MAX /* max value for a wchar_t */ > sys/sparc64/include/_types.h:typedef int ___wchar_t; > sys/sparc64/include/_types.h:#define __WCHAR_MIN __INT_MIN /* min value for a wchar_t */ > sys/sparc64/include/_types.h:#define __WCHAR_MAX __INT_MAX /* max value for a wchar_t */ > sys/x86/include/_types.h:typedef int ___wchar_t; > sys/x86/include/_types.h:#define __WCHAR_MIN __INT_MIN /* min value for a wchar_t */ > sys/x86/include/_types.h:#define __WCHAR_MAX __INT_MAX /* max value for a wchar_t */ > > So only arm and arm64 have unsigned wchar_t types. > > [NOTE: __CHAR16_TYPE__ and __CHAR32_TYPE__ are always unsigned: in C++11 terms char16_t is like std::uint_least16_t and char32_t is like std::uint_least32_t despite being distinct types. So __CHAR16_TYPE__ and __CHAR32_TYPE__ are ignored below.] > > The clang 3.8.0 compiler output has an odd mix for TARGET_ARCH=powerpc and TARGET_ARCH=powerpc64 . . . > > armv6 has unsigned types for both char and __WCHAR_TYPE__. > aarch64 has unsigned types for both char and __WCHAR_TYPE__. > powerpc has unsigned for char but signed for __WCHAR_TYPE__. > powerpc64 has unsigned for char but signed for __WCHAR_TYPE__. > amd64 has signed types for both char and __WCHAR_TYPE__. > i386 has signed types for both char and __WCHAR_TYPE__. > mips has signed types for both char and __WCHAR_TYPE__. > sparc64 has signed types for both char and __WCHAR_TYPE__. > (riscv is not covered by clang as I understand) > > The details via compiler #define's. . . > > # clang --target=armv6-freebsd11 -std=c99 -E -dM - < /dev/null | more > . . . > #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ > . . . > #define __CHAR_BIT__ 8 > #define __CHAR_UNSIGNED__ 1 > . . . > #define __WCHAR_MAX__ 4294967295U > #define __WCHAR_TYPE__ unsigned int > #define __WCHAR_UNSIGNED__ 1 > #define __WCHAR_WIDTH__ 32 > . . . > > # clang --target=aarch64-freebsd11 -std=c99 -E -dM - < /dev/null | more > . . . > #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ > . . . > #define __CHAR_BIT__ 8 > #define __CHAR_UNSIGNED__ 1 > . . . > #define __WCHAR_MAX__ 4294967295U > #define __WCHAR_TYPE__ unsigned int > #define __WCHAR_UNSIGNED__ 1 > #define __WCHAR_WIDTH__ 32 > . . . > > # clang --target=powerpc-freebsd11 -std=c99 -E -dM - < /dev/null | more > . . . > #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ > . . . > #define __CHAR_BIT__ 8 > #define __CHAR_UNSIGNED__ 1 > . . . > #define __WCHAR_MAX__ 2147483647 > #define __WCHAR_TYPE__ int > #define __WCHAR_WIDTH__ 32 > . . . (note the lack of __WCHAR_UNSIGNED__) . . . > > Is powerpc wrong? > > # clang --target=powerpc64-freebsd11 -std=c99 -E -dM - < /dev/null | more > . . . > #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ > . . . > #define __CHAR_BIT__ 8 > #define __CHAR_UNSIGNED__ 1 > . . . > #define __WCHAR_MAX__ 2147483647 > #define __WCHAR_TYPE__ int > #define __WCHAR_WIDTH__ 32 > . . . (note the lack of __WCHAR_UNSIGNED__) . . . > > Is powerpc64 wrong? > > > # clang --target=amd64-freebsd11 -std=c99 -E -dM - < /dev/null | more > . . . > #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ > . . . > #define __CHAR_BIT__ 8 > . . . (note the lack of __CHAR_UNSIGNED__) . . . > > #define __WCHAR_MAX__ 2147483647 > #define __WCHAR_TYPE__ int > #define __WCHAR_WIDTH__ 32 > . . . (note the lack of __WCHAR_UNSIGNED__) . . . > > # clang --target=i386-freebsd11 -std=c99 -E -dM - < /dev/null | more > . . . > #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ > . . . > #define __CHAR_BIT__ 8 > . . . (note the lack of __CHAR_UNSIGNED__) . . . > > #define __WCHAR_MAX__ 2147483647 > #define __WCHAR_TYPE__ int > #define __WCHAR_WIDTH__ 32 > . . . (note the lack of __WCHAR_UNSIGNED__) . . . > > > # clang --target=mips-freebsd11 -std=c99 -E -dM - < /dev/null | more > . . . > #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ > . . . > #define __CHAR_BIT__ 8 > . . . (note the lack of __CHAR_UNSIGNED__) . . . > > #define __WCHAR_MAX__ 2147483647 > #define __WCHAR_TYPE__ int > #define __WCHAR_WIDTH__ 32 > . . . (note the lack of __WCHAR_UNSIGNED__) . . . > > # clang --target=sparc64-freebsd11 -std=c99 -E -dM - < /dev/null | more > . . . > #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ > . . . > #define __CHAR_BIT__ 8 > . . . (note the lack of __CHAR_UNSIGNED__) . . . > > #define __WCHAR_MAX__ 2147483647 > #define __WCHAR_TYPE__ int > #define __WCHAR_WIDTH__ 32 > . . . (note the lack of __WCHAR_UNSIGNED__) . . . > > > > === > Mark Millard > markmi at dsl-only.net >