From patchwork Thu Jan 23 02:16:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1227587 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518098-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=Hown0N9N; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QQEmtHzF; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4835W65pvHz9sR1 for ; Thu, 23 Jan 2020 13:16:48 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=pbzDxKCcD2PSyajW cYK01jbsOj/qz3VUrt0f+0C7+oO/94rYNeqW6mAj2Xh3Wkzh44eNpSLT0RbXO8bI hGpSZIzJCiy+kAymjni7X4Hu6/gocD40ScVsWu7iA6NT3JgMYmPuRR3zY2rGP465 Eqrkasgw5EuoV20eF4EQ2Td3Z4I= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=qwcS9oCG3eETNHrUSjXWxm JVKFE=; b=Hown0N9NHKNu2nVsaosr7yxbqF92EimkrmuLrBlWOy2Dme1dcMBFvo 03h+N+StF5cioyJPXRjW7raqJPUGwsEmuyXHS37WrPShJTe5MBvVYik37JNXMEuA jGfffQuDfnf+i3Y/e7yfJQQ7EDOoiOefrTHY5BMTTlWezej6k0bTk= Received: (qmail 130692 invoked by alias); 23 Jan 2020 02:16:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 130682 invoked by uid 89); 23 Jan 2020 02:16:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jan 2020 02:16:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579745797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kK1a3EmZlMDPrNVVafYqEy8wfk3TvCrhw0xS9mTlHP0=; b=QQEmtHzFf36CTxq5339XhXeJq12AWnnh3Z7nQg2SGqo/vXjNsjUj69t5VV8Z4zfsEQs9x+ 2Fcqsr+raMZ3aWOXBwLt9/cJSo5q3456dvWz/1dvM3Xc/0UpY6rJ1fSnj15bRL5QZ2KYgq 0gvPmTWrfp+ll5I9TAiZtiSpaNMHwcw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-385-ouxplO8OMi-k2XcP5j9B_Q-1; Wed, 22 Jan 2020 21:16:35 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 474D31005510 for ; Thu, 23 Jan 2020 02:16:34 +0000 (UTC) Received: from t470.redhat.com (ovpn-117-41.phx2.redhat.com [10.3.117.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5C675DA2C; Thu, 23 Jan 2020 02:16:33 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH] analyzer: testsuite: introduce analyzer-torture.exp Date: Wed, 22 Jan 2020 21:16:32 -0500 Message-Id: <20200123021632.12466-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. OK for master? I'm working on various followup bugfixes that could use this for test coverage. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/data-model-3.c: Remove hardcoded "-O2" and move to torture/conftest-1.c. * gcc.dg/analyzer/torture/analyzer-torture.exp: New. * gcc.dg/analyzer/torture/conftest-1.c: Move here from analyzer/data-model-3.c. * gcc.dg/analyzer/torture/poc.c: New test. --- gcc/testsuite/gcc.dg/analyzer/data-model-3.c | 15 ------- .../analyzer/torture/analyzer-torture.exp | 44 +++++++++++++++++++ .../gcc.dg/analyzer/torture/conftest-1.c | 10 +++++ gcc/testsuite/gcc.dg/analyzer/torture/poc.c | 24 ++++++++++ 4 files changed, 78 insertions(+), 15 deletions(-) delete mode 100644 gcc/testsuite/gcc.dg/analyzer/data-model-3.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/poc.c diff --git a/gcc/testsuite/gcc.dg/analyzer/data-model-3.c b/gcc/testsuite/gcc.dg/analyzer/data-model-3.c deleted file mode 100644 index 3d572eb8d73..00000000000 --- a/gcc/testsuite/gcc.dg/analyzer/data-model-3.c +++ /dev/null @@ -1,15 +0,0 @@ -/* { dg-additional-options "-O2" } */ -/* TODO:is there a way to automatically run the tests on various - optimizations levels, and with/without debuginfo, rather than - hardcoding options? Adapt from torture .exp, presumably. */ - -#include -int -main () -{ - FILE *f = fopen ("conftest.out", "w"); - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp b/gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp new file mode 100644 index 00000000000..a4d98bb2297 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp @@ -0,0 +1,44 @@ +# Copyright (C) 2020 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# This harness is for tests that should be run at all optimisation levels. + +load_lib gcc-dg.exp + +# If the analyzer has not been enabled, bail. +if { ![check_effective_target_analyzer] } { + return +} + +dg-init + +global DEFAULT_CFLAGS +if [info exists DEFAULT_CFLAGS] then { + set save_default_cflags $DEFAULT_CFLAGS +} + +# If a testcase doesn't have special options, use these. +set DEFAULT_CFLAGS "-fanalyzer -fdiagnostics-path-format=separate-events -Wanalyzer-too-complex -fanalyzer-call-summaries" + +gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" $DEFAULT_CFLAGS + +dg-finish + +if [info exists save_default_cflags] { + set DEFAULT_CFLAGS $save_default_cflags +} else { + unset DEFAULT_CFLAGS +} diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c b/gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c new file mode 100644 index 00000000000..0cf85f0ebe1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c @@ -0,0 +1,10 @@ +#include +int +main () +{ + FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/poc.c b/gcc/testsuite/gcc.dg/analyzer/torture/poc.c new file mode 100644 index 00000000000..1ad45b2f63e --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/torture/poc.c @@ -0,0 +1,24 @@ +/* { dg-do link } */ + +#include + +void test_1 (void *ptr) +{ + free (ptr); + free (ptr); /* { dg-warning "double-free" } */ +} + +struct s +{ + void *ptr; +}; + +void test_2 (struct s *x) +{ + free (x->ptr); + free (x->ptr); /* { dg-warning "double-free" } */ +} + +/* TODO: be more precise about what is freed. */ + +int main () {}