From patchwork Thu Dec 2 16:29:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1562925 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=dvs+C5jB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J4htr0VWGz9s5P for ; Fri, 3 Dec 2021 03:56:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 063FD3857831 for ; Thu, 2 Dec 2021 16:56:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 063FD3857831 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638464193; bh=PwxwRCo6gGZ034w8PTgIRjOQPcP/lcxIMfKidLzRcjg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=dvs+C5jBxC/EbBpnRs5zTUzMFN6Y0P2UUveZm++F6jz6TSOrXgJVPcHxCFttC7Wl+ a0QlKFRXsGiu8EoOW462O+xK1zX55UHWGpcGEC+PKTnAvftO3D6027Ngg6A1orogYU XuWNS0UqrV78YoT+QpuJZVHRa0nmFmio7SlmptzI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 4A5E73857825 for ; Thu, 2 Dec 2021 16:29:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4A5E73857825 Received: by mail-wr1-x432.google.com with SMTP id a9so60834695wrr.8 for ; Thu, 02 Dec 2021 08:29:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=PwxwRCo6gGZ034w8PTgIRjOQPcP/lcxIMfKidLzRcjg=; b=AuhLPfOPpU7cJCsL6YvtSxd3Tf8qZ7R3b9P1fzC/X+Qr7DTqWe4bDFMbJVnrBRltj+ NMk87O7oybW6dVgAzitNFj5bU6hg2hfhlPRbu9t83R5xyFD6ErHGkUEvn/IKazoUpIMc 42dy/BC+g8KXNPHzVIFIFpHruk1B7M3niwpHQmdOPTpdykWaupOKnvErByiOIixRQZPa +HV1Vxim55TTig4M/bK5ySaiuSetd26SWQkjnBufY6Cc73Hzyp7NZ7zRzog80PfCnaqU DJh/06kfllYO7UwmXJHBXgBbdusRm86svHeK82nvI52VWJLwJyFDNlZ2hsSCGXDGdP63 dUMA== X-Gm-Message-State: AOAM531WO9AehWeJiXYeQ6V5OYHSMhXwa6jZkTUFpAxUipnbp6jDK16J jBDBsbCi9bnnO0u3Q6VVtWsR/XkgkEgh8Q== X-Google-Smtp-Source: ABdhPJxfzAxuTell/Nvq14ZsMLhmqiDy6S7K2cVr7BvpmvmxVWAC8ZcIcXf+lJGBImy2Mb2AV1HkdQ== X-Received: by 2002:adf:da41:: with SMTP id r1mr15632134wrl.443.1638462553367; Thu, 02 Dec 2021 08:29:13 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id az4sm2677855wmb.20.2021.12.02.08.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 08:29:12 -0800 (PST) Date: Thu, 2 Dec 2021 16:29:11 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Invalid memory access on finalization of class-wide type Message-ID: <20211202162911.GA2160047@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.1 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Justin Squirek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch is the first part of a correction for issues in the compiler whereby finalization of a heap-allocated class-wide type may cause an invalid memory read at runtime when the type in question contains a component whose type has alignment specified. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gcc-interface/decl.c (gnat_to_gnu_entity): Skip normal processing for Itypes that are E_Class_Wide_Subtype with Equivalent_Type set. diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -335,11 +335,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) /* Since a use of an itype is a definition, process it as such if it is in the main unit, except for E_Access_Subtype because it's actually a use - of its base type, see below. */ + of its base type, and for E_Class_Wide_Subtype with an Equivalent_Type + because it's actually a use of the latter type. */ if (!definition && is_type && Is_Itype (gnat_entity) && Ekind (gnat_entity) != E_Access_Subtype + && !(Ekind (gnat_entity) == E_Class_Wide_Subtype + && Present (Equivalent_Type (gnat_entity))) && !present_gnu_tree (gnat_entity) && In_Extended_Main_Code_Unit (gnat_entity)) {