From patchwork Thu Oct 29 20:45:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Hainque X-Patchwork-Id: 1390363 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=fILdNiLi; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CMcsj2bYyz9sSG for ; Fri, 30 Oct 2020 07:46:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A607384A87E; Thu, 29 Oct 2020 20:45:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 7D5AF3857C77 for ; Thu, 29 Oct 2020 20:45:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7D5AF3857C77 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hainque@adacore.com Received: by mail-wr1-x42a.google.com with SMTP id w14so4210021wrs.9 for ; Thu, 29 Oct 2020 13:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:mime-version:subject:message-id:date:cc:to; bh=wS37zpWUINgDm6P1m5+ASpqIUkPzydBasOymLfaWpKA=; b=fILdNiLiQr1AaKAYdSY4+DH8NYy4VH3YBoVhweilonHiUjjRa5gKtXLUJpXpM/cRYM hp23CCMuqDj132X21PYXl0vV+QyRa3JW5skohGdb4BABbnYLIjbZAXbcYGDU7mul+0o1 Q10qhvaxtx8D9TWZYqpMrrqI9oxHRu6l/TUqk4zYCyPrAgA/c7kYWUW3CL6Jcl0wiQZq 0jOZUtLc9wt98gc7/bfj9EkS8UqcMsS0Gw3fBgAuD+mFeGdr596jtLYhEQj9w87OCXrJ SDw+BzgsaPU8vRTx9qZNCuB4WFwdm9rtw2RDvrpo6HPM8FL+h4yBaOoXIMBn1AV3Cf1l 0Zgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:cc:to; bh=wS37zpWUINgDm6P1m5+ASpqIUkPzydBasOymLfaWpKA=; b=oCiSNABX0ZSWwhAaJfiF2mrodCgHgwsuIiF8h/tFBDnmDJV9UVUPVvIqH5mZQeVibp wl+LBxPQ5FxjGg2XioTt4NMUNlJTC5+J9/ZOFMldQCEJwpk1o/HmqizAldjdQ7Lbfyzn Ng8nNeV80aMr+gd/qfS6/7KMyTTvIYsH6Iz0Im69A4fRu9UyEr1MzyVYN4xndOcx4eQo en926X3NsDOpyvgd0Z8oBiyB1X+ZDETrmtc5wHFjAz9Ag4jwMJS7fInF0cKsk+CA2M2R x6+yLk84Jl7g4on8Gt1Q4UC/7ldAxY0nFlCxULpzPH/QZYdg8DjI5qYPJdJuI0YoGYOg mmww== X-Gm-Message-State: AOAM530SewnpN5v/rr8B2fJt2zxLcp171YwV69f+ZG3j8pb7quv3QLFh 6uVRwRpvEhdmx1DdLvdNsq2g0VWs64ppSzdu X-Google-Smtp-Source: ABdhPJzZmeL3lb1Y3HynncJfFTcZlDipX1MigD93nUr5BkbrE/wxgT0wDodWb9oPgtqEL4mxdbkd5A== X-Received: by 2002:adf:aad0:: with SMTP id i16mr4999170wrc.270.1604004355178; Thu, 29 Oct 2020 13:45:55 -0700 (PDT) Received: from imac-2020.home (2a01cb0002912700d5b92c923a062952.ipv6.abo.wanadoo.fr. [2a01:cb00:291:2700:d5b9:2c92:3a06:2952]) by smtp.gmail.com with ESMTPSA id b1sm1609233wmd.43.2020.10.29.13.45.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Oct 2020 13:45:54 -0700 (PDT) From: Olivier Hainque Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: [patch] gcc.dg/analyzer tests: relax dependency on alloca.h Message-Id: Date: Thu, 29 Oct 2020 21:45:54 +0100 To: GCC Patches X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hello, Some of the tests in gcc.dg/analyzer exercize alloca and #include . Some systems, e.g. VxWorks, don't feature alloca.h and the aforementioned tests fail. Other tests in the suite have been in this situation and the usual way around consists in resorting to __builtin_alloca directly. This patch is a proposal in this direction for gcc.dg/analyzer. It introduces a common "analyzer-alloca.h" where we can stick a common comment and a macro to redirect "alloca" directly to "__builtin_alloca". The intermediate macro in a non system header unfortunately diverts some of the warning expectations, as the allocation point for "x = alloca(128);" is shown on the macro definition and not at the macro invocation point. The patch circumvents this by calling __builtin_alloca directly from the points where the tests perform a warning check. I have verified that all the tests adjusted by the change now pass in a run for a powerpc-vxworks configuration. I'll gladly perform an extra regression test on a native system if the patch is considered ok. Would this be ok to commit ? Thanks in advance, With Kind Regards, Olivier 2020-10-29 Olivier Hainque gcc/testsuite/ * gcc.dg/analyzer/analyzer-alloca.h: New file. * gcc.dg/analyzer/alloca-leak.c: Use it. * gcc.dg/analyzer/data-model-1.c: Use it. * gcc.dg/analyzer/malloc-1.c: Use it and replace call to be tracked by a direct call to __builtin_alloca. * gcc.dg/analyzer/malloc-paths-8.c: Likewise. diff --git a/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c b/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c index 93319932d44a..e990cbc642b9 100644 --- a/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c +++ b/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c @@ -1,6 +1,6 @@ /* { dg-require-effective-target alloca } */ -#include +#include "analyzer-alloca.h" void *test (void) { diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer-alloca.h b/gcc/testsuite/gcc.dg/analyzer/analyzer-alloca.h new file mode 100644 index 000000000000..edb20b118db3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/analyzer-alloca.h @@ -0,0 +1,8 @@ + +/* This header is provided to circumvent the absence of alloca.h on + some systems. Spots that rely on the ability to designate + allocation points within tests can use __builtin_alloca directly + to prevent the diagnostic redirection to the local macro definition + here, as this is not a system header. */ + +#define alloca(n) __builtin_alloca(n) diff --git a/gcc/testsuite/gcc.dg/analyzer/data-model-1.c b/gcc/testsuite/gcc.dg/analyzer/data-model-1.c index 3f16a38ab14d..f4ba96b1e997 100644 --- a/gcc/testsuite/gcc.dg/analyzer/data-model-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/data-model-1.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include "analyzer-alloca.h" #include "analyzer-decls.h" struct foo diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c index 38ce1a52987b..b0039597c5fb 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c @@ -1,6 +1,6 @@ /* { dg-require-effective-target alloca } */ -#include +#include "analyzer-alloca.h" #include extern int foo (void); @@ -273,7 +273,7 @@ int *test_23a (int n) int test_24 (void) { - void *ptr = alloca (sizeof (int)); /* { dg-message "memory is allocated on the stack here" } */ + void *ptr = __builtin_alloca (sizeof (int)); /* { dg-message "memory is allocated on the stack here" } */ free (ptr); /* { dg-warning "'free' of memory allocated on the stack by 'alloca' \\('ptr'\\) will corrupt the heap \\\[CWE-590\\\]" } */ } diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c b/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c index 35c9385b2061..417459edf8cc 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c @@ -2,7 +2,7 @@ /* { dg-require-effective-target alloca } */ #include -#include +#include "analyzer-alloca.h" #include extern void do_stuff (const void *); @@ -41,7 +41,7 @@ void test_3 (size_t sz) { void *ptr; if (sz <= LIMIT) - ptr = alloca (sz); /* { dg-message "memory is allocated on the stack here" } */ + ptr = __builtin_alloca (sz); /* { dg-message "memory is allocated on the stack here" } */ else ptr = malloc (sz);