From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 68F0638582BD for ; Fri, 11 Nov 2022 21:54:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 68F0638582BD Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668203664; 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=jkJ9lVqi2QOKcB4UtxtlBYEfyeXoj1a8F/0VHuwdt8A=; b=cwrhqjczY1DA4sCFQAaIfhojeLTlhUh79cqA0a9ri7nFtSlGi41W3N4xBqh2NAsadtcL0t ExJbJMUfb+SfIx0bdZlKk9v3b5aZIexVyt5V9Pgz6ExJ3gRn2H59vkI34kA7YbdQf4HjMl pUPzohibrjr4fNNrjtWrDjMzSBs/tGQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-365-2t_HYY52PiWfUL-B48JenA-1; Fri, 11 Nov 2022 16:54:23 -0500 X-MC-Unique: 2t_HYY52PiWfUL-B48JenA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3A2A185A7AA for ; Fri, 11 Nov 2022 21:54:22 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F0C540C83DD; Fri, 11 Nov 2022 21:54:22 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] analyzer: more state machine documentation Date: Fri, 11 Nov 2022 16:54:21 -0500 Message-Id: <20221111215421.2709259-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 List-Id: gcc/analyzer/ChangeLog: * sm-fd.dot: Fix typo in comment. * sm-file.dot: New file. * varargs.cc: Fix typo in comment. * varargs.dot: New file. Signed-off-by: David Malcolm --- gcc/analyzer/sm-fd.dot | 2 +- gcc/analyzer/sm-file.dot | 67 ++++++++++++++++++++++++++++++++++++++++ gcc/analyzer/varargs.cc | 2 +- gcc/analyzer/varargs.dot | 56 +++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 gcc/analyzer/sm-file.dot create mode 100644 gcc/analyzer/varargs.dot diff --git a/gcc/analyzer/sm-fd.dot b/gcc/analyzer/sm-fd.dot index 175daae44ae..5c9984a0fb7 100644 --- a/gcc/analyzer/sm-fd.dot +++ b/gcc/analyzer/sm-fd.dot @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see . */ -/* Keep this in-sync with sm-dot.cc */ +/* Keep this in-sync with sm-fd.cc */ digraph "fd" { diff --git a/gcc/analyzer/sm-file.dot b/gcc/analyzer/sm-file.dot new file mode 100644 index 00000000000..ac0f3610f14 --- /dev/null +++ b/gcc/analyzer/sm-file.dot @@ -0,0 +1,67 @@ +/* An overview of the state machine from sm-file.cc. + Copyright (C) 2022 Free Software Foundation, Inc. + Contributed by David Malcolm . + +This file is part of GCC. + +GCC 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, or (at your option) +any later version. + +GCC 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 +. */ + +/* Keep this in-sync with sm-file.cc */ + +digraph "file" { + + /* STATES. */ + + /* Start state. */ + start; + + /* State for a FILE * returned from fopen that hasn't been checked for + NULL. + It could be an open stream, or could be NULL. */ + unchecked; + + /* State for a FILE * that's known to be NULL. */ + null; + + /* State for a FILE * that's known to be a non-NULL open stream. */ + nonnull; + + /* State for a FILE * that's had fclose called on it. */ + closed; + + /* Stop state, for a FILE * we don't want to track any more. */ + stop; + + /* TRANSITIONS. */ + + /* On "fopen". */ + start -> unchecked [label="on 'X = fopen(...);'"]; + + /* On "fclose". */ + start -> closed [label="on 'close(X);'"]; + /* TODO: is it safe to call fclose (NULL) ? */ + unchecked -> closed [label="on 'close(X);'"]; + null -> closed [label="on 'close(X);'"]; + nonnull -> closed [label="on 'close(X);'"]; + closed -> stop [label="on 'close(X);':\nWarn('double fclose')"]; + + /* on_condition. */ + unchecked -> nonnull [label="on 'X != 0'"]; + unchecked -> null [label="on 'X == 0'"]; + + /* Leaks. */ + unchecked -> stop [label="on leak:\nWarn('leak')"]; + nonnull -> stop [label="on leak:\nWarn('leak')"]; +} diff --git a/gcc/analyzer/varargs.cc b/gcc/analyzer/varargs.cc index f7d4838ecb1..6fc20f07a37 100644 --- a/gcc/analyzer/varargs.cc +++ b/gcc/analyzer/varargs.cc @@ -216,7 +216,7 @@ public: } std::unique_ptr on_leak (tree var) const final override; - /* State for a va_list that the result of a va_start or va_copy. */ + /* State for a va_list that is the result of a va_start or va_copy. */ state_t m_started; /* State for a va_list that has had va_end called on it. */ diff --git a/gcc/analyzer/varargs.dot b/gcc/analyzer/varargs.dot new file mode 100644 index 00000000000..b456c9675c6 --- /dev/null +++ b/gcc/analyzer/varargs.dot @@ -0,0 +1,56 @@ +/* An overview of the state machine from varargs.cc + Copyright (C) 2022 Free Software Foundation, Inc. + Contributed by David Malcolm . + +This file is part of GCC. + +GCC 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, or (at your option) +any later version. + +GCC 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 +. */ + +/* Keep this in-sync with varargs.cc */ + +digraph "va_list" { + + /* STATES. */ + + /* Start state. */ + start; + + /* State for a va_list that is the result of a va_start or va_copy. */ + started; + + /* State for a va_list that has had va_end called on it. */ + ended; + + /* TRANSITIONS. */ + + /* on_va_start: */ + start -> started [label="on 'va_start(X, ...)'"]; + + /* on_va_copy: */ + start -> started [label="on 'va_copy(X, ...)'"]; + // in check_for_ended_va_list: + ended -> ended [label="on 'va_copy(X, ...)':\nWarn('use after va_end')"]; + + /* on_va_arg: */ + started -> started [label="on 'va_arg(X, ...)'"]; + started -> started [label="on 'va_copy(..., X)'"]; + // in check_for_ended_va_list: + ended -> ended [label="on 'va_arg(X, ...)':\nWarn('use after va_end')"]; + + /* on_va_end: */ + started -> ended [label="on 'va_end(X)'"]; + // in check_for_ended_va_list: + ended -> ended [label="on 'va_end(X)':\nWarn('use after va_end')"]; +} -- 2.26.3