From patchwork Sat Oct 5 08:21:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1993026 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=MPg8+6/P; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XLJKz6Vstz1xtG for ; Sat, 5 Oct 2024 18:21:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2FDC385ED69 for ; Sat, 5 Oct 2024 08:21:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 0BB32385DDDB for ; Sat, 5 Oct 2024 08:21:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BB32385DDDB Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0BB32385DDDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728116494; cv=none; b=NNN/Qn4576DiCq45NLizOB50jWlze9XzHBxUHUlSFmTl4qQ5XjRtZ0giTntyCBI/UULy+8KywMjDPWC/j65DVxjl9IkK/o2zieZhhD31Hausjz+xi+XSs9rG07BU6u6Bn0wGr5nfII9SNecIwjJuKB6zyVWut/T8mLBAT7ztBs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728116494; c=relaxed/simple; bh=EdL/p1AhgAwonfvxMURVeD1S8ViY3P+s9skDPiJwO5A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bJT403jVYO+7WqFqv4yWvlZCzrrxfaQZHeNe/6dN0CSN7ZoTFBPl95zvALLL4oNULFlyUN12qjtrfU/evzD4vvQ412JYAz8fNLjC1E/BoY6VE42TROOHncJ9FYhlb065kTVhQT/sOhTh+k68hlKYxrQ21w8s1G3lkEeikCMxeN0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-42cbface8d6so36229775e9.3 for ; Sat, 05 Oct 2024 01:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1728116491; x=1728721291; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=T7ImXdOvVm0MNniWOsDzPC+kwznTIUNP7ZXaXQOKDDE=; b=MPg8+6/PVW66TLXINDgox+vUAMB2p3U6VbD1Z5np7NCb5WZd30AkNFfeXoNjbndDOd lTHM6aT2n1KRKyalxlB49EbYM62mhcKqx01c6kymknPx5Xr6WsdutVClQTFTg3hoSQoN pOI6scTCBCWRr6DEwBKtJxR4g13loYV8MNOdE8yV6X9Wj2c5WTqSdOn4hggTvhHMm693 clPo2afhKZwtKILky5DgpGT6QPEaIEYn4PwogPWzTPADIiSeg7VT2/K5H+kTX194HTrG sxRhH/obyajgFl0KOJEew2t/0BKydzCJuk+j/6yJCmHEATM7DWJje1Mp3N+VawlBLiM9 ph9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728116491; x=1728721291; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T7ImXdOvVm0MNniWOsDzPC+kwznTIUNP7ZXaXQOKDDE=; b=ZqqDe6zE/48cNEi5LPB/W9ihB7RWlWukbnmOlufy9ybIOlbZvbEsMlXvC+vynkSSxz hqVHzQL4LVOO5BM0ySi4mPWVRHfrV69pt/Wg48adsAsUSeHLVzjoXpgi0vFuBfiFQa2g 95jUIqOSqIut80qApuisD7yBAZ1r/LWUxcobehDu750wID3N1umaBit9rkdBv8MhQaDc 4FsPXxpIb2uZVgwc+msK2WEBXGL7YLfYCJHtWasNBOgyhhQA8fXx1IaZhy6J/hd58cwR CMfRP04Xk+sq0bg+iUxGG0XADGvhmK1QhOpGoM4oLPlk5lJA2Zw0uewhZgnlstuDshEv XQTg== X-Gm-Message-State: AOJu0Yyvv+WkHyJGyEuKizHPaxbARmv6UnqE5BnP3ot1g4FqkNCRSse4 B2oiet/e4JlfQIrxwF1lobd8jGHokZjaGLzdN2WF6H3Ym5ttVsVXvCTqx6XxQmQDIk+5PTZrfuY = X-Google-Smtp-Source: AGHT+IFb2dY4bBoPvm/cGrKQLis79S0Qh1R/c/KiOHE2fxiQrLyJovw1UhZZ/FSI3QwPEph1opTi0A== X-Received: by 2002:a05:600c:293:b0:42c:b802:47bc with SMTP id 5b1f17b1804b1-42f8db3e896mr216125e9.34.1728116490488; Sat, 05 Oct 2024 01:21:30 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f89e89fcbsm16594765e9.15.2024.10.05.01.21.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2024 01:21:29 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR middle-end/116933 Date: Sat, 05 Oct 2024 10:21:28 +0200 Message-ID: <9767203.eNJFYEL58v@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, this polishes a few rough edges that prevent -ftrivial-auto-var-init=zero from working in Ada: - build_common_builtin_nodes declares BUILT_IN_CLEAR_PADDING with 3 instead of 2 parameters, now gimple_fold_builtin_clear_padding contains the assertion: gcc_assert (gimple_call_num_args (stmt) == 2) This causes gimple_builtin_call_types_compatible_p to always return false in Ada (this works in C/C++ because yet another declaration is used AFAICS). - gimple_add_init_for_auto_var uses EXPR_LOCATION to fetch the location of a DECL notes, which always returns UNKNOWN_LOCATION. - the machinery attempts to initialize Out parameters, which is problematic. Tested on x86-64/Linux, OK for the mainline? 2024-10-05 Eric Botcazou PR middle-end/116933 * gimplify.cc (gimple_add_init_for_auto_var): Use the correct macro to fetch the source location of the variable. * tree.c (common_builtin_nodes): Remove the 3rd parameter in the type of BUILT_IN_CLEAR_PADDING. 2024-10-05 Eric Botcazou ada/ PR middle-end/116933 * gcc-interface/decl.cc (gnat_to_gnu_entity) : Add the "uninitialized" attribute on Out parameters. * gcc-interface/utils.cc (gnat_internal_attributes): Add entry for the "uninitialized" attribute. (handle_uninitialized_attribute): New function. 2024-10-05 Eric Botcazou testsuite/ * gnat.dg/auto_var_init.adb: New test. diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc index 4252e627b0c..880eaff8d0b 100644 --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -1563,6 +1563,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) prepend_one_attribute_pragma (&attr_list, Linker_Section_Pragma (gnat_entity)); + /* Do not initialize Out parameters with -ftrivial-auto-var-init. */ + if (kind == E_Out_Parameter) + prepend_one_attribute + (&attr_list, ATTR_MACHINE_ATTRIBUTE, + get_identifier ("uninitialized"), NULL_TREE, + gnat_entity); + /* Now create the variable or the constant and set various flags. */ gnu_decl = create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type, diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc index 60f36b1e50d..a88a23860d3 100644 --- a/gcc/ada/gcc-interface/utils.cc +++ b/gcc/ada/gcc-interface/utils.cc @@ -107,6 +107,7 @@ static tree handle_malloc_attribute (tree *, tree, tree, int, bool *); static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *); static tree handle_flatten_attribute (tree *, tree, tree, int, bool *); static tree handle_used_attribute (tree *, tree, tree, int, bool *); +static tree handle_uninitialized_attribute (tree *, tree, tree, int, bool *); static tree handle_cold_attribute (tree *, tree, tree, int, bool *); static tree handle_hot_attribute (tree *, tree, tree, int, bool *); static tree handle_simd_attribute (tree *, tree, tree, int, bool *); @@ -214,6 +215,8 @@ static const attribute_spec gnat_internal_attributes[] = handle_flatten_attribute, NULL }, { "used", 0, 0, true, false, false, false, handle_used_attribute, NULL }, + { "uninitialized",0, 0, true, false, false, false, + handle_uninitialized_attribute, NULL }, { "cold", 0, 0, true, false, false, false, handle_cold_attribute, attr_cold_hot_exclusions }, { "hot", 0, 0, true, false, false, false, @@ -7171,6 +7174,30 @@ handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args), return NULL_TREE; } +/* Handle an "uninitialized" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_uninitialized_attribute (tree *node, tree name, tree ARG_UNUSED (args), + int ARG_UNUSED (flags), bool *no_add_attrs) +{ + tree decl = *node; + if (!VAR_P (decl)) + { + warning (OPT_Wattributes, "%qE attribute ignored because %qD " + "is not a variable", name, decl); + *no_add_attrs = true; + } + else if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)) + { + warning (OPT_Wattributes, "%qE attribute ignored because %qD " + "is not a local variable", name, decl); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* Handle a "cold" and attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index ceb53e5d5bb..935f1251846 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -1993,17 +1993,14 @@ gimple_add_init_for_auto_var (tree decl, { gcc_assert (auto_var_p (decl)); gcc_assert (init_type > AUTO_INIT_UNINITIALIZED); - location_t loc = EXPR_LOCATION (decl); - tree decl_size = TYPE_SIZE_UNIT (TREE_TYPE (decl)); - tree init_type_node - = build_int_cst (integer_type_node, (int) init_type); + const location_t loc = DECL_SOURCE_LOCATION (decl); + tree decl_size = TYPE_SIZE_UNIT (TREE_TYPE (decl)); + tree init_type_node = build_int_cst (integer_type_node, (int) init_type); + tree decl_name; - tree decl_name = NULL_TREE; if (DECL_NAME (decl)) - decl_name = build_string_literal (DECL_NAME (decl)); - else { char decl_name_anonymous[3 + (HOST_BITS_PER_INT + 2) / 3]; diff --git a/gcc/tree.cc b/gcc/tree.cc index bc50afca9a3..095c02c5474 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -9848,7 +9848,6 @@ build_common_builtin_nodes (void) ftype = build_function_type_list (void_type_node, ptr_type_node, ptr_type_node, - integer_type_node, NULL_TREE); local_define_builtin ("__builtin_clear_padding", ftype, BUILT_IN_CLEAR_PADDING,