From patchwork Tue Feb 28 10:03:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9595055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 527DC60429 for ; Tue, 28 Feb 2017 10:06:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31F0128526 for ; Tue, 28 Feb 2017 10:06:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 267DA28518; Tue, 28 Feb 2017 10:06:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2B5228518 for ; Tue, 28 Feb 2017 10:06:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751769AbdB1KGp (ORCPT ); Tue, 28 Feb 2017 05:06:45 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33091 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751037AbdB1KGk (ORCPT ); Tue, 28 Feb 2017 05:06:40 -0500 Received: by mail-wm0-f66.google.com with SMTP id v77so1504823wmv.0 for ; Tue, 28 Feb 2017 02:06:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VKrLqgY1zkPcwXrS3DBB553X4H7xJfA+5wmn7suOqLM=; b=bGn+doaXzf3dJvhahNT6MqMWTatMNwC5k+I1zqASHMEWkXQfw1UZF8m792F5nyIeSL Xhl2MZO1AJjqGIYO2sXWrD86aaCgdH2cOA7oi2tGgOhTcP/E2r+6aR31KnUSqwJQpYMM QWtm5md/nr6TQnItKWukRyMGKTYROfJvikVycguJKJdozxHdQkMpX1ilrcg+CPo+HV8c TW0ISF4R1AIdVH/jhWA7UATbMR1t71dkE+TFB6PXLaQu2k63c3YYe3GpM+sG5Ep50wIJ 7isFP7X6w1lLR7frqABRDDhZyOsmJ7Wv0fvHk69i+9KXhjUl2XSskw+2GZFIb2K1vIt6 3M2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VKrLqgY1zkPcwXrS3DBB553X4H7xJfA+5wmn7suOqLM=; b=fNrcniwkVCyx8Z1Y216SnO5nJTaevIcJEJVxA2XDxPnpgh31eRJuQZV1TKKu7wbhEf pnHF8uJRP2KT+x8unPCsezTiIMHwtbE0i7eXU+3zKY+Xw6jREByDIKrvZpGQ9zFgmGQv llt0p0w0urdOdOukU8OiGn76tO6qKUrKuzfgr39ANJoTudFHPQO8qxU2MNrqS0Es2CoI P6GZ2P6XO5Pihqnx8byKYnxveKBR6GsTxHRv2er58sqfByOVjWKuAsU6wiRViG14TVdw IGmvxCZjhZo2E9RbEkWaWc1/syyi3zOizTTrOXjI8jv3DSchSeah9RyCoQBLI5uLWMRL 6g7w== X-Gm-Message-State: AMke39k3BHJahisUMgZ6F5nCuf8Jr87Yd/ERC4WJwKplzily2jG6QYs0WVsBK/vRAgKYCw== X-Received: by 10.28.28.69 with SMTP id c66mr1934900wmc.28.1488276370913; Tue, 28 Feb 2017 02:06:10 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:85e:d600:80dd:dea5:aa0f:9d7c]) by smtp.gmail.com with ESMTPSA id 4sm1601762wrp.61.2017.02.28.02.06.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 02:06:10 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH v3 1/7] replace test for c99 for-loop initializers Date: Tue, 28 Feb 2017 11:03:57 +0100 Message-Id: <20170228100403.33184-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170228100403.33184-1-luc.vanoostenryck@gmail.com> References: <20170228094635.qbod5dwqwrw6etvt@macbook.local> <20170228100403.33184-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This test is to insure that a for-loop with C99-style initializer linearize correctly: the same as a C89-style one (modulo any effect on the scope of the variables). For example that code like: for (int = 0; i < 10; i++) do_stuff(i); is linearized the same as code like: int i; for (i = 0; i < 10; i++) do_stuff(i); A test for this already exist in the testsuite: 0e91f878 ("validation: Check C99 for loop variables") which show the correctness of the fix:: ed73fd32 ("linearize: Emit C99 declarations correctly") But this test is an indirect one, using the presence or absence of warning about context imbalance to show that some part of code is present or not. Now that we have the minimal tools to test the output of test-linearize, use them to replace the test by a direct one. Note: ideally we would like to show that the C89 & the C99 version generate the same code but the testsuie deosn't allow this (yet). Test-case-for: ed73fd32 ("linearize: Emit C99 declarations correctly") Replaces: 0e91f878 ("validation: Check C99 for loop variables") Signed-off-by: Luc Van Oostenryck --- validation/c99-for-loop.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/validation/c99-for-loop.c b/validation/c99-for-loop.c index 42246c513..427fde268 100644 --- a/validation/c99-for-loop.c +++ b/validation/c99-for-loop.c @@ -1,33 +1,21 @@ -int op(int); - -static int good(void) +int c99(void); +int c99(void) { - __context__(1); - for (int i = 0; i < 10; i++) { - if (!op(i)) { - __context__(-1); - return 0; - } - } - __context__(-1); - return 1; -} + int r = -1; -static int bad(void) -{ - __context__(1); for (int i = 0; i < 10; i++) { - if (!op(i)) { - __context__(-1); - return 0; - } + r = i; } - return 1; + + return r; } + /* * check-name: C99 for loop variable declaration + * check-command: test-linearize $file * - * check-error-start -c99-for-loop.c:16:12: warning: context imbalance in 'bad' - different lock contexts for basic block - * check-error-end + * check-output-ignore + * check-output-contains: phisrc\\. + * check-output-contains: phi\\. + * check-output-contains: add\\. */