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 4C2843858C74 for ; Tue, 29 Mar 2022 00:44:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C2843858C74 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-347-Wlzj2Q3AO9aL2dKE7Nz07A-1; Mon, 28 Mar 2022 20:43:56 -0400 X-MC-Unique: Wlzj2Q3AO9aL2dKE7Nz07A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B2BE63800503 for ; Tue, 29 Mar 2022 00:43:55 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.16.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91833C15D59; Tue, 29 Mar 2022 00:43:55 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Subject: [committed] analyzer: fix ICE with incorrect lookup of cgraph node [PR105074] Date: Mon, 28 Mar 2022 20:43:54 -0400 Message-Id: <20220329004354.1095189-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Tue, 29 Mar 2022 00:44:02 -0000 Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r12-7868-g1203e8f7880c9751ece5f5302e413b20f4608a00. gcc/analyzer/ChangeLog: PR analyzer/105074 * region.cc (ipa_ref_requires_tracking): Drop "context_fndecl", instead using the ref->referring to get the cgraph node of the caller. (symnode_requires_tracking_p): Likewise. gcc/testsuite/ChangeLog: PR analyzer/105074 * gcc.dg/analyzer/pr105074.c: New test. * gcc.dg/analyzer/untracked-1.c (extern_fn_char_ptr): New decl. (test_13): New. Signed-off-by: David Malcolm --- gcc/analyzer/region.cc | 13 +++++++------ gcc/testsuite/gcc.dg/analyzer/pr105074.c | 9 +++++++++ gcc/testsuite/gcc.dg/analyzer/untracked-1.c | 6 ++++++ 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr105074.c diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc index 9c9e043c658..749e6182b06 100644 --- a/gcc/analyzer/region.cc +++ b/gcc/analyzer/region.cc @@ -1168,11 +1168,10 @@ decl_region::get_svalue_for_initializer (region_model_manager *mgr) const } /* Subroutine of symnode_requires_tracking_p; return true if REF - within CONTEXT_FNDECL might imply that we should be tracking the - value of a decl. */ + might imply that we should be tracking the value of its decl. */ static bool -ipa_ref_requires_tracking (const ipa_ref *ref, tree context_fndecl) +ipa_ref_requires_tracking (ipa_ref *ref) { /* If we have a load/store/alias of the symbol, then we'll track the decl's value. */ @@ -1188,8 +1187,10 @@ ipa_ref_requires_tracking (const ipa_ref *ref, tree context_fndecl) return true; case GIMPLE_CALL: { - cgraph_node *context_cnode = cgraph_node::get (context_fndecl); - cgraph_edge *edge = context_cnode->get_edge (ref->stmt); + cgraph_node *caller_cnode = dyn_cast (ref->referring); + if (caller_cnode == NULL) + return true; + cgraph_edge *edge = caller_cnode->get_edge (ref->stmt); if (!edge) return true; if (edge->callee == NULL) @@ -1232,7 +1233,7 @@ symnode_requires_tracking_p (symtab_node *symnode) if (TREE_CODE (context_fndecl) != FUNCTION_DECL) return true; for (auto ref : symnode->ref_list.referring) - if (ipa_ref_requires_tracking (ref, context_fndecl)) + if (ipa_ref_requires_tracking (ref)) return true; /* If we get here, then we don't have uses of this decl that require diff --git a/gcc/testsuite/gcc.dg/analyzer/pr105074.c b/gcc/testsuite/gcc.dg/analyzer/pr105074.c new file mode 100644 index 00000000000..2735854d79a --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr105074.c @@ -0,0 +1,9 @@ +/* { dg-additional-options "-O2 -fdump-analyzer-untracked" } */ + +void _gnutls_log(const char *); +static void _gnutls_ocsp_verify_mandatory_stapling(void) { + _gnutls_log(__func__); /* { dg-warning "track '__func__': no" } */ +} +void check_ocsp_response_gnutls_x509_cert_verify_peers(void) { + _gnutls_ocsp_verify_mandatory_stapling(); +} diff --git a/gcc/testsuite/gcc.dg/analyzer/untracked-1.c b/gcc/testsuite/gcc.dg/analyzer/untracked-1.c index b7536c399fd..d07c2975670 100644 --- a/gcc/testsuite/gcc.dg/analyzer/untracked-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/untracked-1.c @@ -11,6 +11,7 @@ typedef struct boxed_int { int value; } boxed_int; extern void extern_fn (struct st *); static void __attribute__((noinline)) internal_fn (struct st *) {} extern int extern_get_int (void); +extern void extern_fn_char_ptr (const char *); void test_0 (void) { @@ -97,3 +98,8 @@ int test_12 (void (*fnptr) (struct st *)) static struct st s12 = { __FILE__, __LINE__ }; /* { dg-warning "track 's12': yes" } */ fnptr (&s12); } + +void test_13 (void) +{ + extern_fn_char_ptr (__func__); /* { dg-warning "track '__func__': no" } */ +} -- 2.26.3