From patchwork Tue Nov 21 10:01:02 2023 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: 80457 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D82253858C42 for ; Tue, 21 Nov 2023 10:06:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 66F5438582AE for ; Tue, 21 Nov 2023 10:01:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66F5438582AE Authentication-Results: sourceware.org; dmarc=pass (p=none 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 66F5438582AE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::329 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700560870; cv=none; b=IvqxOLOzntCQL+v/44xkWoS2revjYOzUywax+1ocP3Xl/nXxnSjB28MuX7Uzhra3g80f2S39tNWtIAk5+okZJ1jVYh/MVOti3AX8PCntVCuVcldkd7Gli82LvIYa1YlPC/qpBUfuc2JxVjYfynS0MBWge55eao/JCO6CELrN42s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700560870; c=relaxed/simple; bh=WN5zF7DJgqS+Rxhcm0ECwsDJa6JSfUzuAtPTaSRjLXE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qDwpS7nmU2ofs9BgGK9LuPsuecgIpMaT2Dn891gGc4gdqdv5Yj18pfZ+HhD3SdslxYjElnnux99rZ0g+yoPV0lOgkNotB/QfSHu0JPRpVgIlOr5Y8+P0Uxzb6W8WSf+le83AIrRb+HgfzF+m+FGB4D33+RHJ1DQkOkZ1SDk4+VA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40b27b498c3so4481955e9.0 for ; Tue, 21 Nov 2023 02:01:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1700560864; x=1701165664; 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=yKrMwfbeoIf58o6CSfNDNzTwA0O29WgTjrowtByJSog=; b=Ie6xKNUivGFhw4zkgyQBgz5epf5ognwEBrM7piQeGVNwqU4hOVDi15+NA4aqWhdC6g DlkgAG154liXTZfs3LLYMyAFrKEsPler5u2QCZLlLpHgRoUwUkXTeyAnt3FyzWyR11OL tr/tkGmu9qNPaJ5HEtaraR0OGF6YYOfdgiOJZ6P8Vpz9fafLwKi50uEP+u8jwxYxbS9j aYfuvfeES5cCaB3p5y80qihfNuunawgFsTMjh0xD624/mqM/ArVhtrTSNgG2Y/772tPW ljZqnpJUrR3dLCUpQOyvxcMp8DXgmICAktv4dFcb+Rc5TNo9YOt8UVGdNM441aInBtz+ piGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700560864; x=1701165664; 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=yKrMwfbeoIf58o6CSfNDNzTwA0O29WgTjrowtByJSog=; b=SdGuhvY03V98uTf0Y1Ipmlk/iueFGwYtV5Q986eM5f9NUMTSVoAM+7YtL8ZlZDB9sq KsAbfHWhOH2CsGQ2PNv4NGh/GIYhCu038YXv1CtUw7q/4v7zc9J+4XnxwqXj4BemDXGd 0nWOxae1dWa8wLbaV58qsGf6rFgg2/GB0eqWrOhckcj1rK8G8jn+OaMNCjRYTAgJ4e83 P8xQ8lFmNMozfyP2z9Mau7GuNEpNAcNw7hk8vl0rNR+ZCEtFvm+8EHIXRfKaK5F1nsNK TF0ht2vYv2WH7LE71Fl2FcZk2sa+IDGqEktkbIDKFRaWWypiS39MSAWmpr5gA6m/UNx5 7BvA== X-Gm-Message-State: AOJu0YwZoswwYyx/IilNNja1HB7Ll1MvtuipG0+osXfnxSqFs/C5Jzj5 tDa3UYwEAKHCahHB+QUrki168L0V6aynuLLRG1b7ow== X-Google-Smtp-Source: AGHT+IGocpdkicK3WRLq7fUXSSaCuBkOrjcDnwVSDDdTo4Q1Lk1NunENl+8817TajUByZN5u0AxIpw== X-Received: by 2002:a05:600c:350a:b0:409:19a0:d247 with SMTP id h10-20020a05600c350a00b0040919a0d247mr8081374wmq.18.1700560864127; Tue, 21 Nov 2023 02:01:04 -0800 (PST) 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 u25-20020a7bcb19000000b00405391f485fsm16142885wmj.41.2023.11.21.02.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:01:03 -0800 (PST) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix miscompilation of loop over boolean range Date: Tue, 21 Nov 2023 11:01:02 +0100 Message-ID: <20231121100102.1965404-1-poulhies@adacore.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 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 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+patchwork=sourceware.org@gcc.gnu.org From: Eric Botcazou The optimized form generated in this case turns out to be problematic. gcc/ada/ * gcc-interface/trans.cc (Loop_Statement_to_gnu): Always use the simpler form for a loop with a boolean iteration variable. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/trans.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index c7d91628f80..9c418beda96 100644 --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -3021,7 +3021,9 @@ Loop_Statement_to_gnu (Node_Id gnat_node) } /* We use two different strategies to translate the loop, depending on - whether optimization is enabled. + whether optimization is enabled, except for the very peculiar case + of a loop running over a boolean type where we use the simpler form + in order to avoid manipulating negative values in a boolean context. If it is, we generate the canonical loop form expected by the loop optimizer and the loop vectorizer, which is the do-while form: @@ -3067,7 +3069,9 @@ Loop_Statement_to_gnu (Node_Id gnat_node) which works in all cases. */ - if (optimize && !optimize_debug) + if (optimize + && !optimize_debug + && TREE_CODE (gnu_base_type) != BOOLEAN_TYPE) { /* We can use the do-while form directly if GNU_FIRST-1 doesn't overflow. */