{"id":825837,"url":"http://patchwork.ozlabs.org/api/1.2/patches/825837/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20171014164818.GA103205@adacore.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.2/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20171014164818.GA103205@adacore.com>","list_archive_url":null,"date":"2017-10-14T16:48:18","name":"[Ada] Missing validity check on record type component","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"8cf21f0570a17c42ede095f39cd2bc1ad1ffc670","submitter":{"id":64226,"url":"http://patchwork.ozlabs.org/api/1.2/people/64226/?format=json","name":"Pierre-Marie de Rodat","email":"derodat@adacore.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20171014164818.GA103205@adacore.com/mbox/","series":[{"id":8200,"url":"http://patchwork.ozlabs.org/api/1.2/series/8200/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=8200","date":"2017-10-14T16:48:18","name":"[Ada] Missing validity check on record type component","version":1,"mbox":"http://patchwork.ozlabs.org/series/8200/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/825837/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/825837/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-return-464219-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-464219-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"QHXFwOFn\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yDrBm02MMz9t3H\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun, 15 Oct 2017 03:48:47 +1100 (AEDT)","(qmail 1342 invoked by alias); 14 Oct 2017 16:48:26 -0000","(qmail 1097 invoked by uid 89); 14 Oct 2017 16:48:21 -0000","from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tSat, 14 Oct 2017 16:48:20 +0000","from localhost (localhost.localdomain [127.0.0.1])\tby\n\tfiltered-rock.gnat.com (Postfix) with ESMTP id 6F19956153;\n\tSat, 14 Oct 2017 12:48:18 -0400 (EDT)","from rock.gnat.com ([127.0.0.1])\tby localhost (rock.gnat.com\n\t[127.0.0.1]) (amavisd-new, port 10024)\twith LMTP id\n\tMQwxAAQxzK3o; Sat, 14 Oct 2017 12:48:18 -0400 (EDT)","from tron.gnat.com (tron.gnat.com\n\t[IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294])\tby rock.gnat.com\n\t(Postfix) with ESMTP id 5F20F56079;\n\tSat, 14 Oct 2017 12:48:18 -0400 (EDT)","by tron.gnat.com (Postfix, from userid 4862)\tid 5E15C319;\n\tSat, 14 Oct 2017 12:48:18 -0400 (EDT)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:mime-version:content-type; q=dns;\n\ts=default; b=qc+PASfRQEmO2INFFcMoqasdbQC91NTOoXPWDss+EVyiLyhNlS\n\tyKvgrA4lQ6r6N6OnDHrNKRKru3mmdLXq3QXL6jIgmkkLlEXyATQvzY4USpQZdnrk\n\tSUQvOQ7N41MK/QYmTKxqyQEbS+xtTE+tMPOmprEybt9cfJl1MF4MMiHEE=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:mime-version:content-type; s=\n\tdefault; bh=NNlUptoWlwHAycz+XLLTaKwHIuQ=; b=QHXFwOFn6fXH1iP741ds\n\tFocRToQ2MQLOqLIgE7RLETMmSvYzI7GopDA3xQ8BNxVu64XaZ2Dghsr24aDXpdWc\n\tyZhFjAbHR4QeJJKy1w3ewpnAqbVcpndt4Sg+GDVWzWAjE94vESPy/H6U7VM5gu7M\n\tzgjdwUSfUFLswbRgbEYKcRA=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2,\n\tGIT_PATCH_3, RCVD_IN_DNSWL_NONE,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=miranda, Miranda,\n\tjavier, Javier","X-HELO":"rock.gnat.com","Date":"Sat, 14 Oct 2017 12:48:18 -0400","From":"Pierre-Marie de Rodat <derodat@adacore.com>","To":"gcc-patches@gcc.gnu.org","Cc":"Javier Miranda <miranda@adacore.com>","Subject":"[Ada] Missing validity check on record type component","Message-ID":"<20171014164818.GA103205@adacore.com>","MIME-Version":"1.0","Content-Type":"multipart/mixed; boundary=\"envbJBWh7q8WU6mo\"","Content-Disposition":"inline","User-Agent":"Mutt/1.5.23 (2014-03-12)","X-IsSubscribed":"yes"},"content":"The compiler may silently skip generating a validity check on a\ntype conversion of a component of a record type. After this patch\nthe error is reported on the following sources.\n\npragma Initialize_Scalars;\npackage Pkg is\n   type T is record\n      Major : Natural;\n      Minor : Natural;\n   end record;\n\n   procedure Do_Test (Value : in out T);\nend;\n\npragma Initialize_Scalars;\npackage body Pkg is\n   type    Integer_T is range -2 ** 31 .. 2 ** 31 - 1;\n   subtype Natural_T is Integer_T range 0 .. Integer_T'Last;\n   Next_Val : Integer_T := 0;\n\n   procedure Do_Update (Int : in out Integer_T) is\n   begin\n      Next_Val := Next_Val + 1;\n      if Next_Val > 1000 then\n         Next_Val := Int;\n      else\n         Int := Next_Val;\n      end if;\n   end;\n\n   procedure Do_Test (Value : in out T) is\n   begin\n      Do_Update (Natural_T (Value.Minor));   -- Run-time error\n   end;\n\nend;\n\nwith Pkg; use Pkg;\nprocedure Main is\n   Obj : T;\nbegin\n   Do_Test (Obj);\nend Main;\n\nCommand: gnatmake -q -gnatVaM main.adb; ./main\nOutput:\n  raised CONSTRAINT_ERROR : pkg.adb:20 invalid data\n\nTested on x86_64-pc-linux-gnu, committed on trunk\n\n2017-10-14  Javier Miranda  <miranda@adacore.com>\n\n\t* checks.adb (Ensure_Valid): Do not skip adding the validity check on\n\trenamings of objects that come from the sources.","diff":"Index: checks.adb\n===================================================================\n--- checks.adb\t(revision 253753)\n+++ checks.adb\t(working copy)\n@@ -5940,6 +5940,10 @@\n       --  In addition, we force a check if Force_Validity_Checks is set\n \n       elsif not Comes_From_Source (Expr)\n+        and then not\n+          (Nkind (Expr) = N_Identifier\n+            and then Present (Renamed_Object (Entity (Expr)))\n+            and then Comes_From_Source (Renamed_Object (Entity (Expr))))\n         and then not Force_Validity_Checks\n         and then (Nkind (Expr) /= N_Unchecked_Type_Conversion\n                     or else Kill_Range_Check (Expr))\n","prefixes":["Ada"]}