From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 92BBB3858C35 for ; Mon, 20 May 2024 07:49:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92BBB3858C35 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 92BBB3858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191359; cv=none; b=ptfsLcC4AHo4ouvmkBbCOsr3LW0TUjzhC3jyMFPCgaXvQO0q+X9it81ByYjgV28CeJ/CqJhbELiXLoWCDqUR3yXh/2HaioFsAgmYQC9+MszyT7IQJKMId6WvAgOEhNukIrwTp+wTe8TOB+nLqtj468BNvjj1MORK1eU5+dwcT30= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191359; c=relaxed/simple; bh=U3BN9eg8vxph/1ClXAkbjgBL/TnryuPtlb9TEhH4P3E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UtTn3F5DSsqerAl2rcB6C1F0v1avPM/wDlNFlUi5HmGM0YOWbHp6QrXaLtijyxmCPeHoC0k3xzuCO4sEv8EWhvf+cKcj7OhZX23jUo6vFqnRRLxp620dpDTLwbaQVxK34Bp4udpcwiSLZn1153jXLD7fym+/Ik+3lL7d+OLmFWk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4200ee47de7so17465385e9.2 for ; Mon, 20 May 2024 00:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1716191356; x=1716796156; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cQRzrL2gGLTxVp7O65tItGNXnzE43M+go1zzWQ5GQWI=; b=GDFiqAWPfuNpxLQkHFsAc8NHakDcT4BFryrXFE6vft27bIctax3K+toINYEiW/PY3F JarjUv6tqzdrkuGxobxb5rYUj9OL7wpwhaoJQtSg/JP43273H0rlitvnKss2EToF+qgk iA+6zgrxewuMaq6xq0FyVrY8y5Ow/6Idy4EbdvfLWzkUwIh0liJJ/M4EamESb3WyVLIZ 1WAeHJQQC45gIaGYpZvYcGp1Aem6Xl9srLmc4Js7Q7ljr5i1wkr8xU5to3YCCnbRQsF8 0s7HaqrMylVctfR9CwBokr4oVGcpy/SHs0pURIba67Ff9lbHRSWS0f0+1S/zj2WvUBIC foSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716191356; x=1716796156; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cQRzrL2gGLTxVp7O65tItGNXnzE43M+go1zzWQ5GQWI=; b=RW+d1ol1K28LKuI+FkcOq1+AHCF92HWYsOi+HIFYQvDW/XhqoRMHl7VA45gPp6Vzyj HVhFl785lMNAN4RSNcaXupBcgAc0Rww8fpNyH9lZaLjUfVRaje+SqUoWAGRxh6MYWYJu 4nx0T4K9afESLkMb98d1lbU4QpwONINm0XaX9rgYFWeb4N/XMeTf5jG7a1D/39nS9563 YL8evKL/dDqsOXfDc4OqPe5pSV1ILdxkL9+Cl4nDfqpq8alKjqYELJY89Szh9PMnParl MWV8Ct34Df+elrf7egwXpsjOJluQi5zKNOwzLPb8WhZ5tsZjEDdoHMpmj+A+jne7ZIAD RsUA== X-Gm-Message-State: AOJu0YzbTk3JiF+Hy+UMyRqY3lPkbv+VIuQplvl0mBAZXm+Cwrj/9IRT eDQa3k2P2Vjv3ehRfCNB4OjTUZJWzeGGtxh7f3r+xQNsS1IXO8O9MMr+m+EaZFbstgAMLIERB4w = X-Google-Smtp-Source: AGHT+IEwrAs6LyUzr0bQHgoHxFAkkl8EiADVIRsWb9AzE/RD7vikc0IBdL75ZEs6oXLmNqZ9fpvxjw== X-Received: by 2002:a05:600c:358d:b0:420:66e:f5c with SMTP id 5b1f17b1804b1-420066e0f77mr202154205e9.14.1716191356330; Mon, 20 May 2024 00:49:16 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:de37:8b1c:1f33:2610]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41f88111033sm446892175e9.34.2024.05.20.00.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 00:49:15 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [COMMITTED 06/30] ada: Reject too-strict alignment specifications. Date: Mon, 20 May 2024 09:48:32 +0200 Message-ID: <20240520074858.222435-6-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240520074858.222435-1-poulhies@adacore.com> References: <20240520074858.222435-1-poulhies@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.9 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 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: Steve Baird For a discrete (or fixed-point) type T, GNAT requires that T'Object_Size shall be a multiple of T'Alignment * 8 . GNAT also requires that T'Object_Size shall be no larger than Standard'Max_Integer_Size. For a sufficiently-large alignment specification, these requirements can conflict. The conflict is resolved by rejecting such alignment specifications (which were previously accepted in some cases). gcc/ada/ * freeze.adb (Adjust_Esize_For_Alignment): Assert that a valid Alignment specification cannot result in adjusting the given type's Esize to be larger than System_Max_Integer_Size. * sem_ch13.adb (Analyze_Attribute_Definition_Clause): In analyzing an Alignment specification, enforce the rule that a specified Alignment value for a discrete or fixed-point type shall not be larger than System_Max_Integer_Size / 8 . gcc/testsuite/ChangeLog: * gnat.dg/specs/alignment2.ads: Adjust. * gnat.dg/specs/alignment2_bis.ads: New test. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/freeze.adb | 8 +++-- gcc/ada/sem_ch13.adb | 15 ++++++++ gcc/testsuite/gnat.dg/specs/alignment2.ads | 14 -------- .../gnat.dg/specs/alignment2_bis.ads | 36 +++++++++++++++++++ 4 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/specs/alignment2_bis.ads diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index a980c7e5b47..26e9d01d8b2 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -303,8 +303,12 @@ package body Freeze is if Known_Esize (Typ) and then Known_Alignment (Typ) then Align := Alignment_In_Bits (Typ); - if Align > Esize (Typ) and then Align <= System_Max_Integer_Size then - Set_Esize (Typ, Align); + if Align > Esize (Typ) then + if Align > System_Max_Integer_Size then + pragma Assert (Serious_Errors_Detected > 0); + else + Set_Esize (Typ, Align); + end if; end if; end if; end Adjust_Esize_For_Alignment; diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 13bf93ca548..59c80022c20 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -6573,6 +6573,21 @@ package body Sem_Ch13 is ("alignment for & set to Maximum_Aligment??", Nam); Set_Alignment (U_Ent, Max_Align); + -- Because Object_Size must be multiple of Alignment (in bits), + -- System_Max_Integer_Size limit for discrete and fixed point + -- types implies a limit on alignment for such types. + + elsif (Is_Discrete_Type (U_Ent) + or else Is_Fixed_Point_Type (U_Ent)) + and then Align > System_Max_Integer_Size / System_Storage_Unit + then + Error_Msg_N + ("specified alignment too large for discrete or fixed " & + "point type", Expr); + Set_Alignment + (U_Ent, UI_From_Int (System_Max_Integer_Size / + System_Storage_Unit)); + -- All other cases else diff --git a/gcc/testsuite/gnat.dg/specs/alignment2.ads b/gcc/testsuite/gnat.dg/specs/alignment2.ads index 0b6c14f1b7d..75a002e9bee 100644 --- a/gcc/testsuite/gnat.dg/specs/alignment2.ads +++ b/gcc/testsuite/gnat.dg/specs/alignment2.ads @@ -32,18 +32,4 @@ package Alignment2 is end record; for R4'Alignment use 32; - -- warning - type I1 is new Integer_32; - for I1'Size use 32; - for I1'Alignment use 32; -- { dg-warning "suspiciously large alignment" } - - -- warning - type I2 is new Integer_32; - for I2'Alignment use 32; -- { dg-warning "suspiciously large alignment" } - - -- OK, big size - type I3 is new Integer_32; - for I3'Size use 32 * 8; -- { dg-warning "unused" } - for I3'Alignment use 32; - end Alignment2; diff --git a/gcc/testsuite/gnat.dg/specs/alignment2_bis.ads b/gcc/testsuite/gnat.dg/specs/alignment2_bis.ads new file mode 100644 index 00000000000..ad31a400b84 --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/alignment2_bis.ads @@ -0,0 +1,36 @@ +-- { dg-do compile } + +with Interfaces; use Interfaces; + +package Alignment2_Bis is + + pragma Warnings (Off, "*size*"); + + -- OK, big size + type R3 is record + A, B, C, D : Integer_8; + end record; + for R3'Size use 32 * 8; + for R3'Alignment use 32; + + -- OK, big size + type R4 is record + A, B, C, D, E, F, G, H : Integer_32; + end record; + for R4'Alignment use 32; + + -- warning + type I1 is new Integer_32; + for I1'Size use 32; + for I1'Alignment use 32; -- { dg-error "error: specified alignment too large for discrete or fixed point type" } + + -- warning + type I2 is new Integer_32; + for I2'Alignment use 32; -- { dg-error "error: specified alignment too large for discrete or fixed point type" } + + -- OK, big size + type I3 is new Integer_32; + for I3'Size use 32 * 8; + for I3'Alignment use 32; -- { dg-error "error: specified alignment too large for discrete or fixed point type" } + +end Alignment2_Bis; -- 2.43.2