From patchwork Thu Sep 10 16:04:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1361673 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=RyZCgG4D; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4BnNy748CLz9sTK for ; Fri, 11 Sep 2020 02:05:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 355903861802; Thu, 10 Sep 2020 16:05:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 69BD33857C50 for ; Thu, 10 Sep 2020 16:04:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 69BD33857C50 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=botcazou@adacore.com Received: by mail-wr1-x42f.google.com with SMTP id x14so7283882wrl.12 for ; Thu, 10 Sep 2020 09:04:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=TR667mnR49bYonbM0CWEDajhT2G38u3s0ZJlfprZIGk=; b=RyZCgG4DN3Y4UWin29gMSB6xhUSh4n+cH2w+cj8p2cFa91hfMAIihqasDdVKI1uro7 T9EjjHCILCIYLcsgB0VInBHWAMGxTE3KKLkd5ydL28cMGswTS3gRawlZFTW6I+v9BEd/ v4HuJ7qKYyGfmjzRUS8P/N3h8OXH0xtguo8jmacswsnIITHZk5aKQ0EsXQuY3ceWICfw H99OC/Lwa/JdaD3BcHLGu1kddTthemveF4EyJ5FDhlyIplhHdaydvDqiQYrxOXVsunmo L7vOCzzEsiSE68kjdksVsUHa2q2CKlapm0BL5jjbhcEvv4NJFvJ/U0wrSpL7j/z7ered d91w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=TR667mnR49bYonbM0CWEDajhT2G38u3s0ZJlfprZIGk=; b=Zk2/PQ2Uhsho9luzOFlaRDz3wGh8Aan3gu7fvfaS1c+jesmxUtUoAv1oGm7zWvmUlR ZF2gZNYVvK4H+MJzbwR6fRQLdfqIZPfDLmxt2T4Za1dv4U9TnK056iIegXjogpJA+fN+ 4/7eNJjHSFTnR5mVw1P1FJMGc5qh4QJz+b4xe340YDtVVdWkK7uh4216vSuzRWed7Cvt LdsSPfyWyH8gGIVizLremddimZXpGQuyl6z3O3n4eBMUNVpLyYyV7yGKnflEnBYq6QWv kZP4TZyDZJUrrmrWURT2WldSR/HcbaFhs4VpLs8xQ4CZyZPrCLVuUKqodSU5dnWggVz0 y8PA== X-Gm-Message-State: AOAM532PlqMc5Y0j2+w+ses4BQjMF8ylJFPhXmegtGGXAVg+mQF+HStL pQNhdDQk6eTxG2ttsdM8Y8ZKADt0cJo5t77u X-Google-Smtp-Source: ABdhPJz4mO9VGVlhNb6voxTS4KWiVHjZOUKTaJR79Jg6Y9vKxEn7GsDEygdUlr7aiMmy5VmFo/nAtQ== X-Received: by 2002:a5d:4a49:: with SMTP id v9mr5817849wrs.153.1599753896174; Thu, 10 Sep 2020 09:04:56 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:9230:7f82:53f4:769e:54b6]) by smtp.gmail.com with ESMTPSA id d2sm10373729wro.34.2020.09.10.09.04.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Sep 2020 09:04:55 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix uninitialized variable with nested variant record types Date: Thu, 10 Sep 2020 18:04:54 +0200 Message-ID: <2220376.IqttJVBmUs@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This fixes a wrong code issue with nested variant record types: the compiler generates move instructions that depend on an uninitialized variable, which was initially a SAVE_EXPR not instantiated early enough. Tested on x86_64-suse-linux, applied on mainline, 10 and 9 branches. 2020-09-10 Eric Botcazou * gcc-interface/decl.c (build_subst_list): For a definition, make sure to instantiate the SAVE_EXPRs generated by the elaboration of the constraints in front of the elaboration of the type itself. 2020-09-10 Eric Botcazou * gnat.dg/discr59.adb: New test. * gnat.dg/discr59_pkg1.ads: New helper. * gnat.dg/discr59_pkg2.ads: Likewise. diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index 025714bd339..f85b2b5bbbb 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -8849,11 +8849,15 @@ build_subst_list (Entity_Id gnat_subtype, Entity_Id gnat_type, bool definition) if (!Is_Access_Type (Etype (Node (gnat_constr)))) { tree gnu_field = gnat_to_gnu_field_decl (gnat_discrim); - tree replacement = convert (TREE_TYPE (gnu_field), - elaborate_expression - (Node (gnat_constr), gnat_subtype, - get_entity_char (gnat_discrim), - definition, true, false)); + tree replacement + = elaborate_expression (Node (gnat_constr), gnat_subtype, + get_entity_char (gnat_discrim), + definition, true, false); + /* If this is a definition, we need to make sure that the SAVE_EXPRs + are instantiated on every possibly path in size computations. */ + if (definition && TREE_CODE (replacement) == SAVE_EXPR) + add_stmt (replacement); + replacement = convert (TREE_TYPE (gnu_field), replacement); subst_pair s = { gnu_field, replacement }; gnu_list.safe_push (s); }