From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 9F9343858414 for ; Tue, 21 May 2024 07:30:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F9343858414 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 9F9343858414 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716276664; cv=none; b=tYGwoF6DNvCl39Ki2fKbYXjVmLWLzbypOLIMD8U7NqMJCi4m84bhJ0bJOiQrTisnxTq2f8++PSG9esJHUg9aOP3TesnBUbwfDMduoAJEl5iDF9FIEdZSz04MOtq9A85arc1vipRUVYSSyC9x6onqlWCO/djQO8bYbDqa4fmvCJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716276664; c=relaxed/simple; bh=xqH6fwc+bC0NTHUSgXqLHiNOxPV9Um9d7apK0JmmXhI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xJlpr0hruE8T6fzj6V5JZjR02pSvwdfIoq9s3QfKK9gOpZy3VUVuvdDNU/cn1G93rd5JOSQxiZ/3iebtiXkaHLCEF2QO4MvkOGHzmPJ75IWpoj/il5AOofh3apiO21F54UcpBnqDBxISBd5AC6HXgrJbrv9LO8fRaXF/CSR3GCQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2e576057c56so38878411fa.3 for ; Tue, 21 May 2024 00:30:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1716276658; x=1716881458; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Hp6FHk886dw8tutJUGrs9O0+SKU9DGSzjmfJ2aASCEk=; b=d4kqL7WM40kfC3gaurH7/FrAcjTJmZwSpEcF+PdulqLGgcSl5jXZasWXvDB69YeFon UBkSoU8ZlI8M7ExjXCOJ0hK5sbaqNqiD5Cc9wjtS2VvyY79vvU/8FtAquC/JFNg6/AvE kGOCCmBciaX6/jEzsMJJ+62qG7eJcLTfRdscjwUI135abmg2jG56jSxrPZpU8lokrbwN 1GCtJpZT6ly511sShX4KD6B/swESFSmlUE+TvPfvQwO6ugUULe9fbMIsYZN4LJtI2qt3 ooxRBdks1WGn6G1k2TXxIqBaRJH1BSvotM9FCmbwljGPEzE4+Ag1Pk7fe2YnHY57hyDX OsaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716276658; x=1716881458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hp6FHk886dw8tutJUGrs9O0+SKU9DGSzjmfJ2aASCEk=; b=Uk8QR9SihQfLEg66Hs1NibfBLcQXEDzVFuXmNnobiWb28TdY6agcrqxPhOFcgDy5A+ LAtiWBt7aWsfTBtj9ochu6QF0LSXwPv7zWmotavYNggr/Zja0mQNz/vG0HLlf4NfKRfA 5ZgGvpvCzKF2BiOgB2l5L9kEE7w3ObO1OfHsUdkt1Ncn4jNpCfZ4Prgs3U83bRQSImqG PvVF2gmIgPqL+dh4IRc/2QirUCKoZ+RJBwsYDxeUoLiadFM6pQzheLfX0hlahCJaeV79 5FKw8kFAvKvjEZ3PrfLwxOaLYBIMmkz5in/tP2Nl8uMDjfxzdK3+orfnTPtQZw4WyVim degg== X-Gm-Message-State: AOJu0YyEbozcjz1qvc0npd5OXlRzeO7ilcqj0hj+UtAt8goLLMI+k4Et OGiQbrXV7N0jZ350XrItclzbYDXH4U1/UUd023o09J3tRadyExsA+5YUWuQNa1j2I25A0EPnJ84 = X-Google-Smtp-Source: AGHT+IHYLFj21mC+iy45Xtjg23v3urwG1khhY5n45k3XWgKXPgzgYqO0pA70T7luvbtz/uIlDxJkMw== X-Received: by 2002:a05:651c:14f:b0:2df:eee9:c71f with SMTP id 38308e7fff4ca-2e51fc36881mr189791041fa.7.1716276658271; Tue, 21 May 2024 00:30:58 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:de37:8b1c:1f33:2610]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccee9292sm453333645e9.37.2024.05.21.00.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 00:30:57 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 13/31] ada: Remove useless trampolines caused by Unchecked_Conversion Date: Tue, 21 May 2024 09:30:16 +0200 Message-ID: <20240521073035.314024-13-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240521073035.314024-1-poulhies@adacore.com> References: <20240521073035.314024-1-poulhies@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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 List-Id: From: Eric Botcazou The partial solution implemented in Validate_Unchecked_Conversion to support unchecked conversions between addresses and pointers to subprograms, for the platforms where pointers to subprograms do not all have the same size, turns out to be counter-productive for others because it may cause the creation of useless trampolines, which in turn makes the stack executable. gcc/ada/ * sem_ch13.adb (Validate_Unchecked_Conversion): Restrict forcing the Can_Use_Internal_Rep flag to platforms that require unnesting. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch13.adb | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 59c80022c20..4cf6fc9a645 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -18132,20 +18132,23 @@ package body Sem_Ch13 is Set_No_Strict_Aliasing (Implementation_Base_Type (Target)); end if; - -- If the unchecked conversion is between Address and an access - -- subprogram type, show that we shouldn't use an internal - -- representation for the access subprogram type. + -- For code generators that do not support nested subprograms, if the + -- unchecked conversion is between Address and an access subprogram + -- type, show that we shouldn't use an internal representation for the + -- access subprogram type. - if Is_Access_Subprogram_Type (Target) - and then Is_Descendant_Of_Address (Source) - and then In_Same_Source_Unit (Target, N) - then - Set_Can_Use_Internal_Rep (Base_Type (Target), False); - elsif Is_Access_Subprogram_Type (Source) - and then Is_Descendant_Of_Address (Target) - and then In_Same_Source_Unit (Source, N) - then - Set_Can_Use_Internal_Rep (Base_Type (Source), False); + if Unnest_Subprogram_Mode then + if Is_Access_Subprogram_Type (Target) + and then Is_Descendant_Of_Address (Source) + and then In_Same_Source_Unit (Target, N) + then + Set_Can_Use_Internal_Rep (Base_Type (Target), False); + elsif Is_Access_Subprogram_Type (Source) + and then Is_Descendant_Of_Address (Target) + and then In_Same_Source_Unit (Source, N) + then + Set_Can_Use_Internal_Rep (Base_Type (Source), False); + end if; end if; -- Generate N_Validate_Unchecked_Conversion node for back end in case -- 2.43.2