aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2019-11-25 13:45:42 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2019-11-25 13:45:42 +0000
commit5b8d9367684f266c30c280b4d3c98830a88c70ab (patch)
treef3d44301e44a62097c89ae2d9b87cb97780f5d94 /gcc/c-family
parent1723e1bedb9545c45619c4023729755243524584 (diff)
downloadgcc-5b8d9367684f266c30c280b4d3c98830a88c70ab.zip
gcc-5b8d9367684f266c30c280b4d3c98830a88c70ab.tar.gz
gcc-5b8d9367684f266c30c280b4d3c98830a88c70ab.tar.bz2
Prevent all uses of DFP when unsupported (PR c/91985).
Code that directly uses _Decimal* types on architectures not supporting DFP is properly diagnosed ("error: decimal floating-point not supported for this target"), via a call to targetm.decimal_float_supported_p, if the _Decimal32, _Decimal64 or _Decimal128 keywords are used to access it. Use via mode attributes is also diagnosed ("unable to emulate 'SD'"); so is use of the FLOAT_CONST_DECIMAL64 pragma. However, it is possible to access those types via typeof applied to constants or built-in functions without such an error. I expect that there are ways to get an ICE from this; certainly it uses a completely undefined ABI. This patch arranges for the types not to exist in the compiler at all when DFP is not supported. As is done with unsupported _FloatN / _FloatNx types, the global tree nodes are left as NULL_TREE, and the built-in function machinery is made to use error_mark_node for them in that case in builtin-types.def, so that the built-in functions are unavailable. Code handling constants is adjusted to give an error, and other code that might not work with the global tree nodes being NULL_TREE is also updated. Bootstrapped with no regressions for x86_64-pc-linux-gnu. Also tested with no regressions for cross to aarch64-linux-gnu, as a configuration without DFP support. PR c/91985 gcc: * builtin-types.def (BT_DFLOAT32, BT_DFLOAT64, BT_DFLOAT128) (BT_DFLOAT32_PTR, BT_DFLOAT64_PTR, BT_DFLOAT128_PTR): Define to error_mark_node if corresponding global tree node is NULL. * tree.c (build_common_tree_nodes): Do not initialize dfloat32_type_node, dfloat64_type_node or dfloat128_type_node if decimal floating-point not supported. gcc/c: * c-decl.c (finish_declspecs): Use int instead of decimal floating-point types if decimal floating-point not supported. gcc/c-family: * c-common.c (c_common_type_for_mode): Handle decimal floating-point types being NULL_TREE. * c-format.c (get_format_for_type_1): Handle specified types being NULL_TREE. * c-lex.c (interpret_float): Give an error for decimal floating-point constants when decimal floating-point not supported. gcc/lto: * lto-lang.c (lto_type_for_mode): Handle decimal floating-point types being NULL_TREE. gcc/testsuite: * gcc.dg/c2x-no-dfp-1.c, gcc.dg/gnu2x-builtins-no-dfp-1.c: New tests. * gcc.dg/fltconst-pedantic-dfp.c: Expect errors when decimal floating-point not supported. From-SVN: r278684
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog11
-rw-r--r--gcc/c-family/c-common.c9
-rw-r--r--gcc/c-family/c-format.c2
-rw-r--r--gcc/c-family/c-lex.c7
4 files changed, 24 insertions, 5 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 281d7f4..30b5b6a 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,14 @@
+2019-11-25 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/91985
+ * c-common.c (c_common_type_for_mode): Handle decimal
+ floating-point types being NULL_TREE.
+ * c-format.c (get_format_for_type_1): Handle specified types being
+ NULL_TREE.
+ * c-lex.c (interpret_float): Give an error for decimal
+ floating-point constants when decimal floating-point not
+ supported.
+
2019-11-23 Jakub Jelinek <jakub@redhat.com>
PR middle-end/83859
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 3e70b6d..5b9af1a 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -2321,11 +2321,14 @@ c_common_type_for_mode (machine_mode mode, int unsignedp)
return build_vector_type_for_mode (inner_type, mode);
}
- if (mode == TYPE_MODE (dfloat32_type_node))
+ if (dfloat32_type_node != NULL_TREE
+ && mode == TYPE_MODE (dfloat32_type_node))
return dfloat32_type_node;
- if (mode == TYPE_MODE (dfloat64_type_node))
+ if (dfloat64_type_node != NULL_TREE
+ && mode == TYPE_MODE (dfloat64_type_node))
return dfloat64_type_node;
- if (mode == TYPE_MODE (dfloat128_type_node))
+ if (dfloat128_type_node != NULL_TREE
+ && mode == TYPE_MODE (dfloat128_type_node))
return dfloat128_type_node;
if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index d70d1e0..519bc8f 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -4390,7 +4390,7 @@ get_format_for_type_1 (const format_kind_info *fki, tree arg_type,
for (int i = 0; i < FMT_LEN_MAX; i++)
{
const format_type_detail *ftd = &spec->types[i];
- if (!ftd->type)
+ if (!ftd->type || *ftd->type == NULL_TREE)
continue;
if (matching_type_p (*ftd->type, effective_arg_type))
{
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index d446633f..107c4c3 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -877,7 +877,12 @@ interpret_float (const cpp_token *token, unsigned int flags,
/* Decode type based on width and properties. */
if (flags & CPP_N_DFLOAT)
- if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
+ if (!targetm.decimal_float_supported_p ())
+ {
+ error ("decimal floating-point not supported for this target");
+ return error_mark_node;
+ }
+ else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
type = dfloat128_type_node;
else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
type = dfloat32_type_node;