From patchwork Sat Oct 14 16:48:18 2017 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: 825837 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-464219-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="QHXFwOFn"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yDrBm02MMz9t3H for ; Sun, 15 Oct 2017 03:48:47 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=qc+PASfRQEmO2INFFcMoqasdbQC91NTOoXPWDss+EVyiLyhNlS yKvgrA4lQ6r6N6OnDHrNKRKru3mmdLXq3QXL6jIgmkkLlEXyATQvzY4USpQZdnrk SUQvOQ7N41MK/QYmTKxqyQEbS+xtTE+tMPOmprEybt9cfJl1MF4MMiHEE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=NNlUptoWlwHAycz+XLLTaKwHIuQ=; b=QHXFwOFn6fXH1iP741ds FocRToQ2MQLOqLIgE7RLETMmSvYzI7GopDA3xQ8BNxVu64XaZ2Dghsr24aDXpdWc yZhFjAbHR4QeJJKy1w3ewpnAqbVcpndt4Sg+GDVWzWAjE94vESPy/H6U7VM5gu7M zgjdwUSfUFLswbRgbEYKcRA= Received: (qmail 1342 invoked by alias); 14 Oct 2017 16:48:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 1097 invoked by uid 89); 14 Oct 2017 16:48:21 -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, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=miranda, Miranda, javier, Javier X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 14 Oct 2017 16:48:20 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 6F19956153; Sat, 14 Oct 2017 12:48:18 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id MQwxAAQxzK3o; Sat, 14 Oct 2017 12:48:18 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 5F20F56079; Sat, 14 Oct 2017 12:48:18 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 5E15C319; Sat, 14 Oct 2017 12:48:18 -0400 (EDT) Date: Sat, 14 Oct 2017 12:48:18 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [Ada] Missing validity check on record type component Message-ID: <20171014164818.GA103205@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes The compiler may silently skip generating a validity check on a type conversion of a component of a record type. After this patch the error is reported on the following sources. pragma Initialize_Scalars; package Pkg is type T is record Major : Natural; Minor : Natural; end record; procedure Do_Test (Value : in out T); end; pragma Initialize_Scalars; package body Pkg is type Integer_T is range -2 ** 31 .. 2 ** 31 - 1; subtype Natural_T is Integer_T range 0 .. Integer_T'Last; Next_Val : Integer_T := 0; procedure Do_Update (Int : in out Integer_T) is begin Next_Val := Next_Val + 1; if Next_Val > 1000 then Next_Val := Int; else Int := Next_Val; end if; end; procedure Do_Test (Value : in out T) is begin Do_Update (Natural_T (Value.Minor)); -- Run-time error end; end; with Pkg; use Pkg; procedure Main is Obj : T; begin Do_Test (Obj); end Main; Command: gnatmake -q -gnatVaM main.adb; ./main Output: raised CONSTRAINT_ERROR : pkg.adb:20 invalid data Tested on x86_64-pc-linux-gnu, committed on trunk 2017-10-14 Javier Miranda * checks.adb (Ensure_Valid): Do not skip adding the validity check on renamings of objects that come from the sources. Index: checks.adb =================================================================== --- checks.adb (revision 253753) +++ checks.adb (working copy) @@ -5940,6 +5940,10 @@ -- In addition, we force a check if Force_Validity_Checks is set elsif not Comes_From_Source (Expr) + and then not + (Nkind (Expr) = N_Identifier + and then Present (Renamed_Object (Entity (Expr))) + and then Comes_From_Source (Renamed_Object (Entity (Expr)))) and then not Force_Validity_Checks and then (Nkind (Expr) /= N_Unchecked_Type_Conversion or else Kill_Range_Check (Expr))