From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30564 invoked by alias); 17 Sep 2019 08:06:43 -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 30425 invoked by uid 89); 17 Sep 2019 08:06:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=views, parents, semantic, concrete 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; Tue, 17 Sep 2019 08:06:40 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id A378C117BF6; Tue, 17 Sep 2019 04:06:36 -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 zv-YmsRo3NuG; Tue, 17 Sep 2019 04:06:36 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id E1F94117C0C; Tue, 17 Sep 2019 04:06:33 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id DDCEE6AD; Tue, 17 Sep 2019 04:06:33 -0400 (EDT) Date: Tue, 17 Sep 2019 08:06:00 -0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [Ada] Don't accept illegal (e.g., Integer'(null)) generic actuals Message-ID: <20190917080633.GA37548@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="YZ5djTAD1cGYuMQK" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00962.txt.bz2 --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1226 Sem_Util.Wrong_Type usually emits an error message, but in some cases it does not. The code which prevents emitting an error message was going too far in some cases, causing illegal constructs to be accepted. For example, a qualified expression such as Integer'(null) might be passed in as an actual parameter in an instantiation of a generic and generate no error message. Running this command: gcc -c inst.ads On the following sources: package Inst is type Ptr is new Integer; generic type TElement is private; NonDefini : TElement; package ArbMgr is end ArbMgr; package Pack is new ArbMgr (Ptr, Ptr'(null)); procedure Dummy; end Inst; Should produce the following output: inst.ads:10:42: expected type "Ptr" defined at line 2 inst.ads:10:42: found an access type compilation abandoned due to previous error Tested on x86_64-pc-linux-gnu, committed on trunk 2019-09-17 Steve Baird gcc/ada/ * sem_util.adb (Wrong_Type): In deciding to suppress a message, it is not enough for In_Instance to be True; in addition, In_Generic_Actual (Expr) must be False. * sem_type.adb (In_Generic_Actual): Fix bug where traversal of parents skips every other node. --YZ5djTAD1cGYuMQK Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" Content-length: 1811 --- gcc/ada/sem_type.adb +++ gcc/ada/sem_type.adb @@ -2849,7 +2849,7 @@ package body Sem_Type is return False; else - return In_Generic_Actual (Parent (Par)); + return In_Generic_Actual (Par); end if; end In_Generic_Actual; --- gcc/ada/sem_util.adb +++ gcc/ada/sem_util.adb @@ -26689,7 +26689,7 @@ package body Sem_Util is return; -- In an instance, there is an ongoing problem with completion of - -- type derived from private types. Their structure is what Gigi + -- types derived from private types. Their structure is what Gigi -- expects, but the Etype is the parent type rather than the -- derived private type itself. Do not flag error in this case. The -- private completion is an entity without a parent, like an Itype. @@ -26700,7 +26700,17 @@ package body Sem_Util is -- same reason: inserted body may be outside of the original package -- and only partial views are visible at the point of insertion. - elsif In_Instance or else In_Inlined_Body then + -- If In_Generic_Actual (Expr) is True then we cannot assume that + -- the successful semantic analysis of the generic guarantees anything + -- useful about type checking of this instance, so we ignore + -- In_Instance in that case. There may be cases where this is not + -- right (the symptom would probably be rejecting something + -- that ought to be accepted) but we don't currently have any + -- concrete examples of this. + + elsif (In_Instance and then not In_Generic_Actual (Expr)) + or else In_Inlined_Body + then if Etype (Etype (Expr)) = Etype (Expected_Type) and then (Has_Private_Declaration (Expected_Type) --YZ5djTAD1cGYuMQK--