diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-10-07 21:25:22 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2024-10-07 21:25:22 +0200 |
commit | e4c0595ec4ed3cd2f6fb471081a9d2d3960e1672 (patch) | |
tree | 70409b86e70deccbb9c63742ad858ecf19e0fe5e /libcpp/init.cc | |
parent | c0002a675a92e76d2f326bf4629d8e4127a0c9da (diff) | |
download | gcc-e4c0595ec4ed3cd2f6fb471081a9d2d3960e1672.zip gcc-e4c0595ec4ed3cd2f6fb471081a9d2d3960e1672.tar.gz gcc-e4c0595ec4ed3cd2f6fb471081a9d2d3960e1672.tar.bz2 |
libcpp: Use constexpr for _cpp_trigraph_map initialization for C++14
The _cpp_trigraph_map initialization used to be done for C99+ using
designated initializers, but can't be done that way for C++ because
the designated initializer support in C++ as array designators are just
an extension there and don't allow skipping anything nor going backwards.
But, we can get the same effect using C++14 constexpr constructor.
With the following patch we get rid of the runtime initialization
and the array can be in .rodata.
2024-10-07 Jakub Jelinek <jakub@redhat.com>
* internal.h (_cpp_trigraph_map_s): New type for C++14 or later.
(_cpp_trigraph_map_d): New variable for C++14 or later.
(_cpp_trigraph_map): Define to _cpp_trigraph_map_d.map for C++14 or
later.
* init.cc (init_trigraph_map): Define to nothing for C++14 or later.
(TRIGRAPH_MAP, END, s): Define differently for C++14 or later.
Diffstat (limited to 'libcpp/init.cc')
-rw-r--r-- | libcpp/init.cc | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/libcpp/init.cc b/libcpp/init.cc index 2c80d63..3e4a2bc 100644 --- a/libcpp/init.cc +++ b/libcpp/init.cc @@ -41,8 +41,8 @@ static void read_original_directory (cpp_reader *); static void post_options (cpp_reader *); /* If we have designated initializers (GCC >2.7) these tables can be - initialized, constant data. Otherwise, they have to be filled in at - runtime. */ + initialized, constant data. Similarly for C++14 and later. + Otherwise, they have to be filled in at runtime. */ #if HAVE_DESIGNATED_INITIALIZERS #define init_trigraph_map() /* Nothing. */ @@ -52,6 +52,15 @@ __extension__ const uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { #define END }; #define s(p, v) [p] = v, +#elif __cpp_constexpr >= 201304L + +#define init_trigraph_map() /* Nothing. */ +#define TRIGRAPH_MAP \ +constexpr _cpp_trigraph_map_s::_cpp_trigraph_map_s () : map {} { +#define END } \ +constexpr _cpp_trigraph_map_s _cpp_trigraph_map_d; +#define s(p, v) map[p] = v; + #else #define TRIGRAPH_MAP uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \ |