From patchwork Fri Nov 22 16:40:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1199550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514417-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xFwSmQZx"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47KMc26Mdyz9sPK for ; Sat, 23 Nov 2019 03:40:18 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Eve8j+71a25aDPQR9vNBqa/pniPa1PLaytNGekGILpjfxUjwqox87 zgd8sGNZUnK7TLBqqrF9hKinVJxginTq2ntWLXe8QTEEqVZzdpLmzqjfamgKNuJD Ruamr17HCpcyX9PCammY0LmiWWn3EZF0yjns2ZjcVownTYVnCS1aXE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=5dPT4ubQcrTj2eYmHTjpsjksHrk=; b=xFwSmQZxX5U2me1RtExP 9Ii2gUokQGJ/7sy4z5k5oCP0jRiYNU9T8zYYIpylr1nI1cXQCbNw2wUapMd8m/bO c3/DTpY3H/ekCEMgkbJ+y7x4bvkg7EZj/3NRiZnvhDQyKAMm4xshDrQNCZrGjtFx E516lii5xRS4W2FuJb/C+Go= Received: (qmail 77603 invoked by alias); 22 Nov 2019 16:40:11 -0000 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 Received: (qmail 77594 invoked by uid 89); 22 Nov 2019 16:40:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=pedantic, DFP, dfp X-HELO: esa4.mentor.iphmx.com Received: from esa4.mentor.iphmx.com (HELO esa4.mentor.iphmx.com) (68.232.137.252) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 Nov 2019 16:40:09 +0000 IronPort-SDR: gKPfYBqgVxQ0Qty0QyUluXkVG/EQSiR/+Wi+CpGoQXMbRF6f3n6mY0TUO4bGNA+tGLqJr5z0lD 92uNtFl7VmuoXRs6difhPAIkUxgb0cz5zDRI9niQcpTJQFc16wf+affl24SlhFeKH8eovAsaDY i1tbBeo/0idBJD/7x5QjQVKAsa4n8kvzcV4A0lW0C8OJ6YnodEFeIbvD5zcRwWVaMvxZwl4NG5 PW+/jrFJEUI+f5Cqhf2CvWpeQlgt3cnJcjPiU5YTVkXAkOrJGdvkuCPS88BP/O2Mxj/ck72jKo O9w= Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 08:40:07 -0800 IronPort-SDR: 9QBDYNDoDrmmSTtznx9LFfasAEC1YTJI0gy7tWjmwjiodq6ZgM7P65lhMh2JbcuVLB5O3vSs+O hjF3F5itrTByIXJ464cQfQQpN1jXDARVsGLpdWCqEc/Fbx//HeXw5xXh+etC+KurWJrN2/DrtL NenP+ZBw6US0tXKpNEc7pNGMR8scD4GwmKAQMPNnmYPW6jrp5x97LlR7zHMXph61doS0mogaWY 46nNpc+zzE4q6jNi0vwjKuLtBhPoNrdecKUNLmY4BBPetTu9OrO6OnbFlKoKS+m2LHxrfdFPrG +bQ= Date: Fri, 22 Nov 2019 16:40:01 +0000 From: Joseph Myers To: Subject: Prevent all uses of DFP when unsupported (PR c/91985) Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 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. OK to commit (the changes that aren't C front-end changes)? gcc: 2019-11-22 Joseph Myers PR c/91985 * 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: 2019-11-22 Joseph Myers PR c/91985 * c-decl.c (finish_declspecs): Use int instead of decimal floating-point types if decimal floating-point not supported. gcc/c-family: 2019-11-22 Joseph Myers 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. gcc/lto: 2019-11-22 Joseph Myers PR c/91985 * lto-lang.c (lto_type_for_mode): Handle decimal floating-point types being NULL_TREE. gcc/testsuite: 2019-11-22 Joseph Myers PR c/91985 * 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. Index: gcc/builtin-types.def =================================================================== --- gcc/builtin-types.def (revision 278603) +++ gcc/builtin-types.def (working copy) @@ -136,12 +136,24 @@ DEF_PRIMITIVE_TYPE (BT_WINT, wint_type_node) DEF_PRIMITIVE_TYPE (BT_STRING, string_type_node) DEF_PRIMITIVE_TYPE (BT_CONST_STRING, const_string_type_node) -DEF_PRIMITIVE_TYPE (BT_DFLOAT32, dfloat32_type_node) -DEF_PRIMITIVE_TYPE (BT_DFLOAT64, dfloat64_type_node) -DEF_PRIMITIVE_TYPE (BT_DFLOAT128, dfloat128_type_node) -DEF_PRIMITIVE_TYPE (BT_DFLOAT32_PTR, dfloat32_ptr_type_node) -DEF_PRIMITIVE_TYPE (BT_DFLOAT64_PTR, dfloat64_ptr_type_node) -DEF_PRIMITIVE_TYPE (BT_DFLOAT128_PTR, dfloat128_ptr_type_node) +DEF_PRIMITIVE_TYPE (BT_DFLOAT32, (dfloat32_type_node + ? dfloat32_type_node + : error_mark_node)) +DEF_PRIMITIVE_TYPE (BT_DFLOAT64, (dfloat64_type_node + ? dfloat64_type_node + : error_mark_node)) +DEF_PRIMITIVE_TYPE (BT_DFLOAT128, (dfloat128_type_node + ? dfloat128_type_node + : error_mark_node)) +DEF_PRIMITIVE_TYPE (BT_DFLOAT32_PTR, (dfloat32_ptr_type_node + ? dfloat32_ptr_type_node + : error_mark_node)) +DEF_PRIMITIVE_TYPE (BT_DFLOAT64_PTR, (dfloat64_ptr_type_node + ? dfloat64_ptr_type_node + : error_mark_node)) +DEF_PRIMITIVE_TYPE (BT_DFLOAT128_PTR, (dfloat128_ptr_type_node + ? dfloat128_ptr_type_node + : error_mark_node)) DEF_PRIMITIVE_TYPE (BT_VALIST_REF, va_list_ref_type_node) DEF_PRIMITIVE_TYPE (BT_VALIST_ARG, va_list_arg_type_node) Index: gcc/c/c-decl.c =================================================================== --- gcc/c/c-decl.c (revision 278603) +++ gcc/c/c-decl.c (working copy) @@ -11619,7 +11619,9 @@ finish_declspecs (struct c_declspecs *specs) case cts_dfloat128: gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p && !specs->signed_p && !specs->unsigned_p && !specs->complex_p); - if (specs->typespec_word == cts_dfloat32) + if (!targetm.decimal_float_supported_p ()) + specs->type = integer_type_node; + else if (specs->typespec_word == cts_dfloat32) specs->type = dfloat32_type_node; else if (specs->typespec_word == cts_dfloat64) specs->type = dfloat64_type_node; Index: gcc/c-family/c-common.c =================================================================== --- gcc/c-family/c-common.c (revision 278603) +++ gcc/c-family/c-common.c (working copy) @@ -2321,11 +2321,14 @@ c_common_type_for_mode (machine_mode mode, int uns 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)) Index: gcc/c-family/c-format.c =================================================================== --- gcc/c-family/c-format.c (revision 278603) +++ gcc/c-family/c-format.c (working copy) @@ -4390,7 +4390,7 @@ get_format_for_type_1 (const format_kind_info *fki 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)) { Index: gcc/c-family/c-lex.c =================================================================== --- gcc/c-family/c-lex.c (revision 278603) +++ gcc/c-family/c-lex.c (working copy) @@ -877,7 +877,12 @@ interpret_float (const cpp_token *token, unsigned /* 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; Index: gcc/lto/lto-lang.c =================================================================== --- gcc/lto/lto-lang.c (revision 278603) +++ gcc/lto/lto-lang.c (working copy) @@ -1051,11 +1051,14 @@ lto_type_for_mode (machine_mode mode, int unsigned 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)) Index: gcc/testsuite/gcc.dg/c2x-no-dfp-1.c =================================================================== --- gcc/testsuite/gcc.dg/c2x-no-dfp-1.c (nonexistent) +++ gcc/testsuite/gcc.dg/c2x-no-dfp-1.c (working copy) @@ -0,0 +1,12 @@ +/* Test DFP types and constants rejected if no DFP support. Bug + 91985. */ +/* { dg-do compile { target { ! dfp } } } */ +/* { dg-options "-std=c2x" } */ + +_Decimal32 d32a; /* { dg-error "not supported" } */ +_Decimal64 d64a; /* { dg-error "not supported" } */ +_Decimal128 d128a; /* { dg-error "not supported" } */ + +_Bool d32b = 1.0DF; /* { dg-error "not supported" } */ +_Bool d64b = 1.0DD; /* { dg-error "not supported" } */ +_Bool d128b = 1.0DL; /* { dg-error "not supported" } */ Index: gcc/testsuite/gcc.dg/fltconst-pedantic-dfp.c =================================================================== --- gcc/testsuite/gcc.dg/fltconst-pedantic-dfp.c (revision 278603) +++ gcc/testsuite/gcc.dg/fltconst-pedantic-dfp.c (working copy) @@ -2,5 +2,8 @@ /* { dg-options "-pedantic" } */ double a = 1.dl; /* { dg-warning "decimal float" } */ +/* { dg-error "not supported for this target" "not supported" { target { ! dfp } } .-1 } */ double b = 1.df; /* { dg-warning "decimal float" } */ +/* { dg-error "not supported for this target" "not supported" { target { ! dfp } } .-1 } */ double c = 1.dd; /* { dg-warning "decimal float" } */ +/* { dg-error "not supported for this target" "not supported" { target { ! dfp } } .-1 } */ Index: gcc/testsuite/gcc.dg/gnu2x-builtins-no-dfp-1.c =================================================================== --- gcc/testsuite/gcc.dg/gnu2x-builtins-no-dfp-1.c (nonexistent) +++ gcc/testsuite/gcc.dg/gnu2x-builtins-no-dfp-1.c (working copy) @@ -0,0 +1,18 @@ +/* Test C2x built-in functions: test DFP built-in functions are not + available when no DFP support. Bug 91985. */ +/* { dg-do compile { target { ! dfp } } } */ +/* { dg-options "-std=gnu2x" } */ + +int fabsd32 (void); +int fabsd64 (void); +int fabsd128 (void); +int nand32 (void); +int nand64 (void); +int nand128 (void); + +__typeof__ (__builtin_fabsd32 (0)) d32; /* { dg-warning "implicit" } */ +__typeof__ (__builtin_fabsd64 (0)) d64; /* { dg-warning "implicit" } */ +__typeof__ (__builtin_fabsd128 (0)) d128; /* { dg-warning "implicit" } */ +__typeof__ (__builtin_nand32 (0)) d32n; /* { dg-warning "implicit" } */ +__typeof__ (__builtin_nand64 (0)) d64n; /* { dg-warning "implicit" } */ +__typeof__ (__builtin_nand128 (0)) d128n; /* { dg-warning "implicit" } */ Index: gcc/tree.c =================================================================== --- gcc/tree.c (revision 278603) +++ gcc/tree.c (working copy) @@ -10334,23 +10334,26 @@ build_common_tree_nodes (bool signed_char) uint64_type_node = make_or_reuse_type (64, 1); /* Decimal float types. */ - dfloat32_type_node = make_node (REAL_TYPE); - TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE; - SET_TYPE_MODE (dfloat32_type_node, SDmode); - layout_type (dfloat32_type_node); - dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node); + if (targetm.decimal_float_supported_p ()) + { + dfloat32_type_node = make_node (REAL_TYPE); + TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE; + SET_TYPE_MODE (dfloat32_type_node, SDmode); + layout_type (dfloat32_type_node); + dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node); - dfloat64_type_node = make_node (REAL_TYPE); - TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE; - SET_TYPE_MODE (dfloat64_type_node, DDmode); - layout_type (dfloat64_type_node); - dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node); + dfloat64_type_node = make_node (REAL_TYPE); + TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE; + SET_TYPE_MODE (dfloat64_type_node, DDmode); + layout_type (dfloat64_type_node); + dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node); - dfloat128_type_node = make_node (REAL_TYPE); - TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE; - SET_TYPE_MODE (dfloat128_type_node, TDmode); - layout_type (dfloat128_type_node); - dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node); + dfloat128_type_node = make_node (REAL_TYPE); + TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE; + SET_TYPE_MODE (dfloat128_type_node, TDmode); + layout_type (dfloat128_type_node); + dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node); + } complex_integer_type_node = build_complex_type (integer_type_node, true); complex_float_type_node = build_complex_type (float_type_node, true);