From patchwork Fri Mar 16 10:39:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tristan Gingold X-Patchwork-Id: 147181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BA7E9B6EEA for ; Fri, 16 Mar 2012 21:39:43 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1332499185; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:Content-Type:Content-Transfer-Encoding:Subject: Date:Message-Id:Cc:To:Mime-Version:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=TyJDHbx2HvR+bZKVlx+SOFYUzQU=; b=RGtuADZsNNPhP8+ g1i8++eiU7Q0BWiN0XTviGYNu+7+vvL6eygwDLzBPP7X+O1oqB+CCSXI6PfORTl4 SSrsOZHAKe9Mw6f8BWuqZplol89D8rsrD/V0gIyBMR3iDPZKwYAp1eZRh+4eBBxr htMEBxku3KTIHsD7mBUFQxGl0Qlg= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:Content-Type:Content-Transfer-Encoding:Subject:Date:Message-Id:Cc:To:Mime-Version:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=VpclpaJxG2SRPsbUZu/8i8WmICa9ZmMz46XP5sfpD1ae0jlGMyRPq1yYGcx6Px tKz9G4v16iOaV/KDRNz3aQ1ol9r27tbQHx99GfzcsxYRF8QLvBprXNz3GmV9Estv ISBsx0/LHJ0Z82uIrHmDW4GU1Kl4/aMQBBP6kjUBdIgKU=; Received: (qmail 6769 invoked by alias); 16 Mar 2012 10:39:36 -0000 Received: (qmail 6262 invoked by uid 22791); 16 Mar 2012 10:39:32 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 16 Mar 2012 10:39:14 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 08041290082; Fri, 16 Mar 2012 11:39:15 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4xMc+uI1CC8K; Fri, 16 Mar 2012 11:39:14 +0100 (CET) Received: from ulanbator.act-europe.fr (ulanbator.act-europe.fr [10.10.1.67]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id E946229003E; Fri, 16 Mar 2012 11:39:14 +0100 (CET) From: Tristan Gingold Subject: [Patch]: Uncouple size_t and sizetype Date: Fri, 16 Mar 2012 11:39:12 +0100 Message-Id: Cc: Richard Guenther To: GCC Patches Mime-Version: 1.0 (Apple Message framework v1257) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, currently sizetype precision (cf store-layout.c:initialize_sizetypes) is the same as size_t. This is an issue on VMS, where size_t is 'unsigned int', but we'd like to have a 64 bit sizetype for Ada. My understanding is that ISO-C doesn't require size_t precision to match the one of void *. We can't really lie about size_t because it is exposed in API (such as writev). I don't see any reason (other than historic one) to have an exact match between sizetype and size_t. So this patch adds an hook to allow targets to define sizetype. I initially thought about using Pmode precision for sizetype precision, but there are a few machines (m32c, sh, h8300) where the precisions aren't the same. I don't know wether this is on purpose or unintentional. Manually tested on ia64 and alpha vms. Not yet regression tested on a more common machine. Comments are welcome, Tristan. 2012-03-16 Tristan Gingold * target.def (sizetype_cdecl): New hook. * stor-layout.c (initialize_sizetypes): Use sizetype_cdecl hook to get sizetype name. * targhooks.c (default_sizetype_cdecl): New function. * targhooks.h (default_sizetype_cdecl): New prototype. * doc/tm.texi.in (Type Layout): Add TARGET_SIZETYPE_CDECL hook. * doc/tm.texi: Regenerate. * config/vms/vms.h (SIZE_TYPE): Always unsigned int. diff --git a/gcc/config/vms/vms.h b/gcc/config/vms/vms.h index e11b1bf..dc44441 100644 --- a/gcc/config/vms/vms.h +++ b/gcc/config/vms/vms.h @@ -58,14 +58,12 @@ extern void vms_c_register_includes (const char *, const char *, int); #define POINTER_SIZE (flag_vms_pointer_size == VMS_POINTER_SIZE_NONE ? 32 : 64) #define POINTERS_EXTEND_UNSIGNED 0 -/* FIXME: It should always be a 32 bit type. */ +/* Always 32 bits. */ #undef SIZE_TYPE -#define SIZE_TYPE (flag_vms_pointer_size == VMS_POINTER_SIZE_NONE ? \ - "unsigned int" : "long long unsigned int") -/* ???: Defined as a 'int' by dec-c, but obstack.h doesn't like it. */ +#define SIZE_TYPE "unsigned int" #undef PTRDIFF_TYPE #define PTRDIFF_TYPE (flag_vms_pointer_size == VMS_POINTER_SIZE_NONE ? \ "int" : "long long int") #define C_COMMON_OVERRIDE_OPTIONS vms_c_common_override_options () diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 69f8aba..48d7b60 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -1651,6 +1651,12 @@ for the result of subtracting two pointers. The typedef name If you don't define this macro, the default is @code{"long int"}. @end defmac +@deftypefn {Target Hook} {const char *} TARGET_SIZETYPE_CDECL (void) +This hooks should return the corresponding C declaration for the internal@code{sizetype} type, from which are also derived @code{bitsizetype} and thesigned variant. + +If you don't define it, the default is @code{SIZE_TYPE}. +@end deftypefn + @defmac WCHAR_TYPE A C expression for a string describing the name of the data type to use for wide characters. The typedef name @code{wchar_t} is defined using diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index c24cf1e..0028b76 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -1639,6 +1639,8 @@ for the result of subtracting two pointers. The typedef name If you don't define this macro, the default is @code{"long int"}. @end defmac +@hook TARGET_SIZETYPE_CDECL + @defmac WCHAR_TYPE A C expression for a string describing the name of the data type to use for wide characters. The typedef name @code{wchar_t} is defined using diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 264edd7..d77abc2 100644 diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 7c7fabc..5ed0f12 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -2383,15 +2383,16 @@ void initialize_sizetypes (void) { int precision, bprecision; + const char *sizetype_name = targetm.sizetype_cdecl (); /* Get sizetypes precision from the SIZE_TYPE target macro. */ - if (strcmp (SIZE_TYPE, "unsigned int") == 0) + if (strcmp (sizetype_name, "unsigned int") == 0) precision = INT_TYPE_SIZE; - else if (strcmp (SIZE_TYPE, "long unsigned int") == 0) + else if (strcmp (sizetype_name, "long unsigned int") == 0) precision = LONG_TYPE_SIZE; - else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0) + else if (strcmp (sizetype_name, "long long unsigned int") == 0) precision = LONG_LONG_TYPE_SIZE; - else if (strcmp (SIZE_TYPE, "short unsigned int") == 0) + else if (strcmp (sizetype_name, "short unsigned int") == 0) precision = SHORT_TYPE_SIZE; else gcc_unreachable (); diff --git a/gcc/target.def b/gcc/target.def index d658b11..bde3388 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -2674,6 +2674,19 @@ DEFHOOKPOD @code{bool} @code{true}.", unsigned char, 1) +/* The corresponding C declaration for the internal 'sizetype' type, from which + are also derived 'bitsizetype' and the signed variant. The default is + SIZE_TYPE. */ +DEFHOOK +(sizetype_cdecl, + "This hooks should return the corresponding C declaration for the internal\ +@code{sizetype} type, from which are also derived @code{bitsizetype} and the\ +signed variant.\n\ +\n\ +If you don't define it, the default is @code{SIZE_TYPE}.", + const char *, (void), + default_sizetype_cdecl) + /* Leave the boolean fields at the end. */ /* True if we can create zeroed data by switching to a BSS section diff --git a/gcc/targhooks.c b/gcc/targhooks.c index 8e3d74e..d490384 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -1340,6 +1340,15 @@ default_get_reg_raw_mode(int regno) return reg_raw_mode[regno]; } +/* To be used by almost any targets, except when size_t precision is less than + pointers precision. */ + +const char * +default_sizetype_cdecl (void) +{ + return SIZE_TYPE; +} + /* Return true if the state of option OPTION should be stored in PCH files and checked by default_pch_valid_p. Store the option's current state in STATE if so. */ diff --git a/gcc/targhooks.h b/gcc/targhooks.h index 8618115..41f44f8 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -47,6 +47,7 @@ extern unsigned HOST_WIDE_INT default_shift_truncation_mask (enum machine_mode); extern unsigned int default_min_divisions_for_recip_mul (enum machine_mode); extern int default_mode_rep_extended (enum machine_mode, enum machine_mode); +extern const char *default_sizetype_cdecl (void); extern tree default_stack_protect_guard (void); extern tree default_external_stack_protect_fail (void);