From patchwork Mon May 13 08:36:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 1934638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=AoHO8Dv8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VdCzC522vz1ymg for ; Mon, 13 May 2024 18:56:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4F0F386F45F for ; Mon, 13 May 2024 08:56:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 637A538708A7 for ; Mon, 13 May 2024 08:36:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 637A538708A7 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 637A538708A7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715589449; cv=none; b=UVVD5ISKyHarijoxSV5EdABpvMwNLulMR9Z+kRx03IWV8ieMZIZt97n3qlRYbap2//HF7NvT5D7VDD36C8eE/wBqUcn0gUNTSHulljnCkU6sZ/Ryo0e0d2JHTEc7aCkFxinJKmOqm5ZDbOUXVIEV9KEHEr375bGm3r5VmqEinwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715589449; c=relaxed/simple; bh=567XZLJPjNGeh7xD2vGg5A5MUndcNK6EovTqY48x2YU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HD/pH2ZNw1mleY63rh8nZvfis+rEDadA4VtKYII7RsE+7XB+5UI7hVuMPsQvekP2YTv1hVY2/Wx7A1M6dnjTpGWdzYXYrHs0ZyEmOxdHrtiqgMQ1u5eNPcG8pwv+Mrigyva6LgAAMuv54SDDMwQyV9RN8YU6X/Zr7Y0HDc1DQo0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-41fe54cb0e3so24915215e9.2 for ; Mon, 13 May 2024 01:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1715589398; x=1716194198; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NSaUgRBtMXbJ+IdNWsC5CQig1sZ7KdcALZyg47194qE=; b=AoHO8Dv8mOzr7ZWfgQ4Fy9iDseA3jk220XVL5kjFmGomMi/17fAQHb6ZTHeINohUgK rEfAeuC1iBq8Ertqjiu9TiaVp9vdab8wdUajOdeC+vvT3KP2VV5zV7TItfXnxQOIV/ck P3nPY2XO8ZbNk03U8+NGoNe6N/60vZQNGsF/PN3luFPxgJO8zC2lTkMM3r0CBWPeUhW4 RboBGSHkvyubi8YGGztDtwzzpTh2q8Guk0TwTKrEW3hZZumTYqH+hqqlIpsIuXNiGGbJ H1dEyzKaIPUPJi7iYbQnHxQigZQ/zmf/cL6QXk6GLl5bF0W9VFXeina161rOJYmug+9N 8nZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715589398; x=1716194198; 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=NSaUgRBtMXbJ+IdNWsC5CQig1sZ7KdcALZyg47194qE=; b=pTbVppegaq9vrrc+xzHhsIbBo1U4SINmo+Ihx8plmt6xY8jgXfrnfXar/zS8ZtnYSB qAxHadRoB0JYaqD+ZiLCsM6LHkP5WDTAOHayLxux4DGEmf4dC/7pZlKHu67BD9aE7TK5 kUAotZz5wnTXZGl5J5Knb9tm8WiXny2Z05j3y9M3H/ncY0b708u62o42P9s5+AMUPcqi yVXYCjdFVAaTJKiS29dzZFIUGtJpGU1XAlWh2rTENTPEqqQeJox5z4/cfdOJuHMLWEEL 26702DpEb2E1wioB8UaNer1J0qeQsLzmHLjqdKeFpQov00MiN2Vgy4iUFHLtF97e8w6y kItA== X-Gm-Message-State: AOJu0YzmLKNihTmf4OYM1CO9Rf16uKq/f6f11ZsNqafcT5ppKcyk0DiA bSdB2qOu7Qy85ZDCTehxoIAN60CHTILC+O3Z3rLp5nzuIbSm771ntncUHA+4hpxyTQvZGc2M01o = X-Google-Smtp-Source: AGHT+IGsKa0e+GvymkpKBKb/G4rsB2AqTOlrfTWoCe7Xm8iHxLdt8+/A8Etiv4oobiz/Lx7LjsATqA== X-Received: by 2002:a05:600c:4705:b0:418:f5a9:b91c with SMTP id 5b1f17b1804b1-41fead65a1bmr60929445e9.33.1715589398229; Mon, 13 May 2024 01:36:38 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:cf0f:cd6c:7a6a:cbed]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccfe1527sm147193675e9.44.2024.05.13.01.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:36:37 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITTED] ada: Fix crash on Compile_Time_Warning in dead code Date: Mon, 13 May 2024 10:36:36 +0200 Message-ID: <20240513083636.165968-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Bob Duff If a pragma Compile_Time_Warning triggers, and the pragma is later removed because it is dead code, then the compiler can return a bad exit code. This causes gprbuild to report "*** compilation phase failed". This is because Total_Errors_Detected, which is declared as Nat, goes negative, causing Constraint_Error. In assertions-off mode, the Constraint_Error is not detected, but the compiler nonetheless reports a bad exit code. This patch prevents that negative count. gcc/ada/ * errout.adb (Output_Messages): Protect against the total going negative. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/errout.adb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb index d28a410f47b..c4761bd1bc9 100644 --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -3399,11 +3399,16 @@ package body Errout is if Warning_Mode = Treat_As_Error then declare - Compile_Time_Pragma_Warnings : constant Int := + Compile_Time_Pragma_Warnings : constant Nat := Count_Compile_Time_Pragma_Warnings; - begin - Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected + Total : constant Int := Total_Errors_Detected + Warnings_Detected - Warning_Info_Messages - Compile_Time_Pragma_Warnings; + -- We need to protect against a negative Total here, because + -- if a pragma Compile_Time_Warning occurs in dead code, it + -- gets counted in Compile_Time_Pragma_Warnings but not in + -- Warnings_Detected. + begin + Total_Errors_Detected := Int'Max (Total, 0); Warnings_Detected := Warning_Info_Messages + Compile_Time_Pragma_Warnings; end;