From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7635 invoked by alias); 22 Jun 2017 10:28:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 7618 invoked by uid 89); 22 Jun 2017 10:28:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Jun 2017 10:28:57 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D4773345A3; Thu, 22 Jun 2017 10:28:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0D4773345A3 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0D4773345A3 Received: from tucnak.zalov.cz (ovpn-116-143.ams2.redhat.com [10.36.116.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A9F1E5C7C1; Thu, 22 Jun 2017 10:28:54 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v5MASq9r005181; Thu, 22 Jun 2017 12:28:52 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v5MASpZd005180; Thu, 22 Jun 2017 12:28:51 +0200 Date: Thu, 22 Jun 2017 10:28:00 -0000 From: Jakub Jelinek To: Eric Botcazou Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Avoid UB in the Ada FE Message-ID: <20170622102850.GX2123@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-06/txt/msg01638.txt.bz2 Hi! I'm seeing almost 750 of runtime errors like: ../../gcc/ada/gcc-interface/trans.c:6992:20: runtime error: load of value 240, which is not a valid value for type 'bool' (with random values in place of the 240 above) during bootstrap-ubsan. The problem is that atomic_access_required_p only initializes what the last argument points to if it returns true. Usually it is used like else if (atomic_access_required_p (gnat_actual, &sync)) gnu_result = build_atomic_store (gnu_actual, gnu_result, sync); so it is fine, but in this particular snippet we have: bool atomic_access = !outer_atomic_access && atomic_access_required_p (Name (gnat_node), &sync); gnu_result = Call_to_gnu (Expression (gnat_node), &gnu_result_type, gnu_lhs, outer_atomic_access, atomic_access, sync); i.e. we unconditionally load a bool value that is only conditionally initialized, and pass it to another function (which uses it conditionally only, but the UB is already the load of the uninitialized value). Fixed thusly, ok for trunk if it passes bootstrap/regtest? Another option would be to change atomic_access_required_p to add *sync = false; before the first return, or to initialize bool sync = false; at the definition. 2017-06-22 Jakub Jelinek * gcc-interface/trans.c (gnat_to_gnu): Initialize sync to false to avoid UB. --- gcc/ada/gcc-interface/trans.c.jj 2017-06-21 16:53:37.000000000 +0200 +++ gcc/ada/gcc-interface/trans.c 2017-06-22 12:19:45.458928009 +0200 @@ -6985,6 +6985,7 @@ gnat_to_gnu (Node_Id gnat_node) { bool outer_atomic_access = outer_atomic_access_required_p (Name (gnat_node)); + sync = false; bool atomic_access = !outer_atomic_access && atomic_access_required_p (Name (gnat_node), &sync); Jakub