From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id 9DF673858421; Tue, 21 Sep 2021 09:13:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DF673858421 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] Add __PTRADDR_TYPE__, __PTRADDR_WIDTH__, and ptraddr_t X-Act-Checkin: gcc X-Git-Author: Matthew Malcomson X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: 3d93394b6134556de82bb8ae9e7b9e10faa6d93d X-Git-Newrev: 7dd3220ffff8bb12ba27d0d0be5497b17cb9f930 Message-Id: <20210921091314.9DF673858421@sourceware.org> Date: Tue, 21 Sep 2021 09:13:14 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Sep 2021 09:13:14 -0000 https://gcc.gnu.org/g:7dd3220ffff8bb12ba27d0d0be5497b17cb9f930 commit 7dd3220ffff8bb12ba27d0d0be5497b17cb9f930 Author: Matthew Malcomson Date: Mon Aug 9 10:51:01 2021 +0100 Add __PTRADDR_TYPE__, __PTRADDR_WIDTH__, and ptraddr_t These two macros and a typedef are defined by LLVM. They represent the type that can contain an address value and its width. __PTRADDR_TYPE__ is a macro that contains the relevant type name that can be used to typedef ptraddr_t in a similar manner to __UINTPTR_TYPE__ and uintptr_t. Analogous to __INTPTR_WIDTH__, __PTRADDR_WIDTH__ holds the width of this type. Following LLVM we put the typedef of ptraddr_t in stddef.h, but we try and follow the way that the existing GCC stddef.h definitions are conditioned since the headers seem different between LLVM and GCC. When not targetting capabilities LLVM defines the __PTRADDR_TYPE__ to match __UINTPTR_TYPE__, so we make that the default. This does mean that architectutres which target capabilities must defined both __UINTPTR_TYPE__ and __PTRADDR_TYPE__ since on those architectures these types must be different. For consistencies sake we define an internal tree node ptraddr_type_node to represent this type in a manner similar to uintptr_type_node. This type is not quite a replacement for the "address" attribute mode, since the type is unsigned and hence we can't generate a signed integer type from this macro. We need this ability to define the `saddr` type in libgcc/unwind-dw2-fde.h (though this may change when we look closer at the unwinder). Diff: --- gcc/c-family/c-common.c | 5 +++++ gcc/c-family/c-common.h | 2 ++ gcc/c-family/c-cppbuiltin.c | 2 ++ gcc/defaults.h | 4 ++++ gcc/doc/tm.texi | 15 +++++++++++++++ gcc/doc/tm.texi.in | 15 +++++++++++++++ gcc/ginclude/stddef.h | 13 +++++++++++-- gcc/testsuite/gcc.target/aarch64/morello/predefines.c | 4 ++++ 8 files changed, 58 insertions(+), 2 deletions(-) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index e489a90b1a8..6e241245eb7 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -4528,6 +4528,9 @@ c_common_nodes_and_builtins (void) if (UINTPTR_TYPE) uintptr_type_node = TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE))); + if (PTRADDR_TYPE) + ptraddr_type_node = + TREE_TYPE (identifier_global_value (c_get_ident (PTRADDR_TYPE))); default_function_type = build_varargs_function_type_list (integer_type_node, NULL_TREE); @@ -5258,6 +5261,8 @@ c_stddef_cpp_builtins(void) builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE, 0); if (UINTPTR_TYPE) builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE, 0); + if (PTRADDR_TYPE) + builtin_define_with_value ("__PTRADDR_TYPE__", PTRADDR_TYPE, 0); /* GIMPLE FE testcases need access to the GCC internal 'sizetype'. Expose it as __SIZETYPE__. */ if (flag_gimple) diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index ca5606cea10..fedaede361d 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -344,6 +344,7 @@ enum c_tree_index CTI_UINT_FAST64_TYPE, CTI_INTPTR_TYPE, CTI_UINTPTR_TYPE, + CTI_PTRADDR_TYPE, CTI_CHAR_ARRAY_TYPE, CTI_CHAR8_ARRAY_TYPE, @@ -492,6 +493,7 @@ extern const unsigned int num_c_common_reswords; #define uint_fast64_type_node c_global_trees[CTI_UINT_FAST64_TYPE] #define intptr_type_node c_global_trees[CTI_INTPTR_TYPE] #define uintptr_type_node c_global_trees[CTI_UINTPTR_TYPE] +#define ptraddr_type_node c_global_trees[CTI_PTRADDR_TYPE] #define truthvalue_type_node c_global_trees[CTI_TRUTHVALUE_TYPE] #define truthvalue_true_node c_global_trees[CTI_TRUTHVALUE_TRUE] diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c index 8c94c104b57..8e4c338b8b0 100644 --- a/gcc/c-family/c-cppbuiltin.c +++ b/gcc/c-family/c-cppbuiltin.c @@ -1090,6 +1090,8 @@ c_cpp_builtins (cpp_reader *pfile) builtin_define_type_width ("__WINT_WIDTH__", wint_type_node, NULL_TREE); builtin_define_type_width ("__PTRDIFF_WIDTH__", ptrdiff_type_node, NULL_TREE); builtin_define_type_width ("__SIZE_WIDTH__", size_type_node, NULL_TREE); + if (ptraddr_type_node) + builtin_define_type_width ("__PTRADDR_WIDTH__", ptraddr_type_node, NULL_TREE); if (c_dialect_cxx ()) for (i = 0; i < NUM_INT_N_ENTS; i ++) diff --git a/gcc/defaults.h b/gcc/defaults.h index 167f5ff002e..205a982dec9 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -742,6 +742,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define UINTPTR_TYPE ((const char *) NULL) #endif +#ifndef PTRADDR_TYPE +#define PTRADDR_TYPE UINTPTR_TYPE +#endif + /* Width in bits of a pointer. Mind the value of the macro `Pmode'. */ #ifndef POINTER_SIZE #define POINTER_SIZE BITS_PER_WORD diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index dfed4c3dfc1..56fe193f363 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -1697,6 +1697,21 @@ unsigned int"} that has as much precision as @code{long long unsigned int}. @end defmac +@defmac PTRADDR_TYPE +A C expression for a string describing the name of the data type that +can represent any address value of a pointer. The typedef name +@code{ptraddr_t} is defined using the contents of the string. See +@code{SIZE_TYPE} above for more information. + +If this macro evaluates to a null pointer, the corresponding type is not +supported. If this type is supported and GCC is configured to provide +@code{} then the typedef of @code{ptraddr_t} is provided there. +This defaults to the the same as @code{UINTPTR_TYPE} if that is defined. + +Note: If your architecture has capabilities as pointers this default will need +to be changed. +@end defmac + @defmac SIG_ATOMIC_TYPE @defmacx INT8_TYPE @defmacx INT16_TYPE diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 885b9a0eccb..6d037ef77e1 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -1509,6 +1509,21 @@ unsigned int"} that has as much precision as @code{long long unsigned int}. @end defmac +@defmac PTRADDR_TYPE +A C expression for a string describing the name of the data type that +can represent any address value of a pointer. The typedef name +@code{ptraddr_t} is defined using the contents of the string. See +@code{SIZE_TYPE} above for more information. + +If this macro evaluates to a null pointer, the corresponding type is not +supported. If this type is supported and GCC is configured to provide +@code{} then the typedef of @code{ptraddr_t} is provided there. +This defaults to the the same as @code{UINTPTR_TYPE} if that is defined. + +Note: If your architecture has capabilities as pointers this default will need +to be changed. +@end defmac + @defmac SIG_ATOMIC_TYPE @defmacx INT8_TYPE @defmacx INT16_TYPE diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h index 9d67eac4947..f6606d7292f 100644 --- a/gcc/ginclude/stddef.h +++ b/gcc/ginclude/stddef.h @@ -28,14 +28,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see && !defined(__STDDEF_H__)) \ || defined(__need_wchar_t) || defined(__need_size_t) \ || defined(__need_ptrdiff_t) || defined(__need_NULL) \ - || defined(__need_wint_t) + || defined(__need_wint_t) || defined(__need_ptrdiff_t) /* Any one of these symbols __need_* means that GNU libc wants us just to define one data type. So don't define the symbols that indicate this file's entire job has been done. */ #if (!defined(__need_wchar_t) && !defined(__need_size_t) \ && !defined(__need_ptrdiff_t) && !defined(__need_NULL) \ - && !defined(__need_wint_t)) + && !defined(__need_wint_t)) && !defined(__need_ptrdiff_t) #define _STDDEF_H #define _STDDEF_H_ /* snaroff@next.com says the NeXT needs this. */ @@ -156,6 +156,15 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; #endif /* _STDDEF_H or __need_ptrdiff_t. */ +/* Type that contains an address. */ +#if defined (_STDDEF_H) || defined (__need_ptraddr_t) +#if defined(__PTRADDR_TYPE__) +typedef __PTRADDR_TYPE__ ptraddr_t; +#endif + +#undef __need_ptraddr_t +#endif + /* Unsigned type of `sizeof' something. */ /* Define this type if we are doing the whole job, diff --git a/gcc/testsuite/gcc.target/aarch64/morello/predefines.c b/gcc/testsuite/gcc.target/aarch64/morello/predefines.c index 19f7564f9bf..2a2b47109dc 100644 --- a/gcc/testsuite/gcc.target/aarch64/morello/predefines.c +++ b/gcc/testsuite/gcc.target/aarch64/morello/predefines.c @@ -8,6 +8,9 @@ __intcap_t x(int); __UINTPTR_TYPE__ y(int); __uintcap_t y(int); +/* Declare twice to ensure that the types are the same (error otherwise). */ +__PTRADDR_TYPE__ z(int); +long unsigned int z(int); /* Include this test for types being the same too since I like it -- probably should remove one later since having two is superfluous. */ @@ -47,6 +50,7 @@ int main() */ /* assert (__INTPTR_WIDTH__ == 64); */ assert (__UINTPTR_MAX__ == __UINT64_MAX__); + assert (__PTRADDR_WIDTH__ == 64); assert (myconst[2] == 'l'); assert (__CHERI_CAP_PERMISSION_GLOBAL__ == 1); assert (__ARM_CAP_PERMISSION_EXECUTIVE__ == 2);