aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJeanHeyd Meneide <phdofthehouse@gmail.com>2020-12-01 14:39:47 -0700
committerJeff Law <law@redhat.com>2020-12-01 14:46:51 -0700
commiteccec8684142e05f2f92f0f5bd5b47dda3ba1529 (patch)
treefe7097d15b7f8eaa5cfa1635f0783e1824908083 /gcc
parent39836f8324d819459cb21198e95b993588c6a2b1 (diff)
downloadgcc-eccec8684142e05f2f92f0f5bd5b47dda3ba1529.zip
gcc-eccec8684142e05f2f92f0f5bd5b47dda3ba1529.tar.gz
gcc-eccec8684142e05f2f92f0f5bd5b47dda3ba1529.tar.bz2
Feature: Macros for identifying the wide and narrow execution string literal encoding
gcc/c-family * c-cppbuiltin.c (c_cpp_builtins): Add predefined {__GNUC_EXECUTION_CHARSET_NAME} and _WIDE_EXECUTION_CHARSET_NAME} macros. gcc/ * doc/cpp.texi: Document new macros. gcc/testsuite/ * c-c++-common/cpp/wide-narrow-predef-macros.c: New test. libcpp/ * charset.c (init_iconv_desc): Initialize "to" and "from" fields. * directives.c (cpp_get_narrow_charset_name): New function. (cpp_get_wide_charset_name): Likewise. * include/cpplib.h (cpp_get_narrow_charset_name): Prototype. (cpp_get_wide_charset_name): Likewise. * internal.h (cset_converter): Add "to" and "from" fields.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/c-cppbuiltin.c7
-rw-r--r--gcc/doc/cpp.texi9
-rw-r--r--gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c13
3 files changed, 29 insertions, 0 deletions
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 41914f6..7b7b07d 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -877,6 +877,13 @@ c_cpp_builtins (cpp_reader *pfile)
define_language_independent_builtin_macros (pfile);
+ /* encoding definitions used by users and libraries */
+ builtin_define_with_value ("__GNUC_EXECUTION_CHARSET_NAME",
+ cpp_get_narrow_charset_name (pfile), 1);
+ builtin_define_with_value ("__GNUC_WIDE_EXECUTION_CHARSET_NAME",
+ cpp_get_wide_charset_name (pfile), 1);
+
+
if (c_dialect_cxx ())
{
int major;
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index 291e146..5dcd672 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -2451,6 +2451,15 @@ features are supported by GCC.
@item __NO_MATH_ERRNO__
This macro is defined if @option{-fno-math-errno} is used, or enabled
by another option such as @option{-ffast-math} or by default.
+
+@item __GNUC_EXECUTION_CHARSET_NAME
+@itemx __GNUC_WIDE_EXECUTION_CHARSET_NAME
+These macros are defined to expand to a narrow string literal of
+the name of the narrow and wide compile-time execution character
+set used. It directly reflects the name passed to the options
+@option{-fexec-charset} and @option{-fwide-exec-charset}, or the defaults
+documented for those options (that is, it can expand to something like
+@code{"UTF-8"}). @xref{Invocation}.
@end table
@node System-specific Predefined Macros
diff --git a/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c b/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c
new file mode 100644
index 0000000..d5440f8a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c
@@ -0,0 +1,13 @@
+/*
+ { dg-do compile }
+ */
+
+#if !defined(__GNUC_EXECUTION_CHARSET_NAME)
+#error "Required implementation macro for comple-time charset name is not present"
+#endif
+#if !defined(__GNUC_WIDE_EXECUTION_CHARSET_NAME)
+#error "Required implementation macro for wide comple-time charset name is not present"
+#endif
+
+const char narrow_name[] = __GNUC_EXECUTION_CHARSET_NAME;
+const char wide_name[] = __GNUC_WIDE_EXECUTION_CHARSET_NAME;