From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 781CE3858C2A for ; Tue, 1 Aug 2023 08:08:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 781CE3858C2A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fe2048c910so17190135e9.1 for ; Tue, 01 Aug 2023 01:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1690877295; x=1691482095; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EHomJ9xq6EjdU3BDYfVbjHQh5p4CRwrmfbOg0GLdjC8=; b=C6xyiOeA83Oy7+ItL+vT53w9TZIVgm8BMmc9DcwW7BGJkXg9GT/BlHdm27WyG/OBej pnDjOHLsqT9+HS239XcD0zfC9WfqjSlL2qZl1iGRPmQJIHYEW9xY5KyzcVAMnJeVlEpF UjlOZ59+ODHoST57F5EutpLCxXwYH1/ADASov2GIaIhk+4FEUueBClqiCQ6NFoCZNYLr XlaalV6flEg4ZBLxI51PHDHYaiKZAc9v4jUgkaphuK9DW2hH4jcPI7gvPC3pKJOksl2Y v768g+NdwlUC9xTXtEluJf0FpeHQfvwj/Z06dKKcy+vaKMmvNGQxvGacHJ6U5QaEOIuB ZSUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690877295; x=1691482095; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EHomJ9xq6EjdU3BDYfVbjHQh5p4CRwrmfbOg0GLdjC8=; b=E+oJIu/uFnhQzXdPKz9dh9uK0kd/DgSxmGHz7kB2JzfpVF7GD23/Lj2LDg9rlgzR9c aI/46dtQbNFQWobVoXZJDHCb8+6OOgEBH3W+Qfuwf4WKYAWuAhRIri94ZytEOxYiWFyd 862Xrdb6NYtssvEHnUPnljlrP36eby6Bp0cAZfBrDWN5Po62wdQugylVG4OcQwQvCTqR oYaSGwkAGgW1gUvTDuJpSqKL81bnaOIqaa6QTY8QvQmptBMbl4oaAA84oIncFOtQ+fko InIG3pJ4W87oaIj7gKJM8+0oOjvUJqmfdcvSgijkhYr8ZVcamT/WMZYOfmH3wVZ+sM7Q B/Ow== X-Gm-Message-State: ABy/qLbvHGw52ZPsKELIUxnIzniMJpKN4gT51AJl8L9/ONhUtYubMk65 xxEcedKMF3N98+jlvdgcj3xG7HZlBPflWIQUoMNbJA== X-Google-Smtp-Source: APBJJlGcON7oUA6Np6S5n4leBG66MajocIYoGerflwFbj44ILuIMpA6TIDBAl3UP3hWdAMR+mqouJA== X-Received: by 2002:a7b:c392:0:b0:3fc:62c:8275 with SMTP id s18-20020a7bc392000000b003fc062c8275mr1849165wmj.35.1690877294788; Tue, 01 Aug 2023 01:08:14 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id n2-20020a05600c294200b003fbbe41fd78sm13403712wmd.10.2023.08.01.01.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 01:08:14 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITTED] ada: check Atree.Get/Set_Field_Value Date: Tue, 1 Aug 2023 10:08:12 +0200 Message-Id: <20230801080812.2271398-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Bob Duff Get_Field_Value and Set_Field_Value now check that the Nkind or Ekind is correct. However, the checks are partially disabled, because they sometimes fail. gcc/ada/ * atree.adb (Field_Present): New function to detect whether or not a given field is present in a given node, based on either the node kind or the entity kind as appropriate. (Get_Field_Value): Check that the field begin fetched exists. However, disable the check in the case of Scope_Depth_Value, because we have failures in that case. Those failures need to be fixed, and then the check can be enabled for all fields. (Set_Field_Value): Check that the field begin set exists. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/atree.adb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb index f1e4e2ca8bb..5597d166cdb 100644 --- a/gcc/ada/atree.adb +++ b/gcc/ada/atree.adb @@ -265,6 +265,10 @@ package body Atree is -- True if a node/entity of the given Kind has the given Field. -- Always True if assertions are disabled. + function Field_Present + (N : Node_Id; Field : Node_Or_Entity_Field) return Boolean; + -- Same for a node, which could be an entity + end Field_Checking; package body Field_Checking is @@ -366,6 +370,17 @@ package body Atree is return Entity_Fields_Present (Kind) (Field); end Field_Present; + function Field_Present + (N : Node_Id; Field : Node_Or_Entity_Field) return Boolean is + begin + case Field is + when Node_Field => + return Field_Present (Nkind (N), Field); + when Entity_Field => + return Field_Present (Ekind (N), Field); + end case; + end Field_Present; + end Field_Checking; ------------------------ @@ -885,6 +900,10 @@ package body Atree is function Get_Field_Value (N : Node_Id; Field : Node_Or_Entity_Field) return Field_Size_32_Bit is + pragma Assert + (if Field /= F_Scope_Depth_Value then -- ???Temporarily disable check + Field_Checking.Field_Present (N, Field)); + -- Assert partially disabled because it fails in rare cases Desc : Field_Descriptor renames Field_Descriptors (Field); NN : constant Node_Or_Entity_Id := Node_To_Fetch_From (N, Field); @@ -905,6 +924,7 @@ package body Atree is procedure Set_Field_Value (N : Node_Id; Field : Node_Or_Entity_Field; Val : Field_Size_32_Bit) is + pragma Assert (Field_Checking.Field_Present (N, Field)); Desc : Field_Descriptor renames Field_Descriptors (Field); begin -- 2.40.0