From patchwork Mon Jul 22 16:12:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 94331 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 635B83858401 for ; Mon, 22 Jul 2024 16:12:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 08E56385E003 for ; Mon, 22 Jul 2024 16:12:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08E56385E003 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kam.mff.cuni.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 08E56385E003 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.113.20.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721664729; cv=none; b=Xg5J2eshkKnvNebF3pcA7lZTxui/EzsOTbPsBP3oMQHvqOR3IIiGqIR1HksLdaAuxAf+B2bMajNjxz2G9oIrTYELKKjzAUUecuUsB7p+kQ1vOICy4wSTom8eKaCo/8+J72PHzs+v4RYJXVOhrGOJSBUhnDiMy3m+WDBbliJJjv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721664729; c=relaxed/simple; bh=CJSrwE5rDeAViaDxd1FHUqkrUOdzPwoW4/6pQfR6gtw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=KmyigvZFVzyfbYuSS7MEGIcwF8rY0cbDsdgdlFYU3AbKTxpmVH7NuGojlmFST91YYRjvPS9FPjVB2AyYvkL3qtkH4lYR3gtbKton2kht6YUyOVo9gszvN2elBQmnNhOlixZxlyB2gwTaqL0WWyaKW2YBfWFmC3cBg6OeNnUVfOE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 239D1287926; Mon, 22 Jul 2024 18:12:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1721664726; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=gYyHOET+yp0e5cKkmPmR57yIWbmoEaAmEe6KeH5fEXk=; b=b0oG6m3FaqRcXl1ojS5AptClfRMsPOdsaDoFsLynQ1b5ssEM4b5GQnzYxcRBS2OcjEeUn/ oYE6D/utKCOlJudqSgJql60TeRI2RhRsDAq4AMax7jotwhi36fxMblc7TdlAuIay/gfPHd jXljkSyk7iufTVUPVndCPojQG3Jv56s= Date: Mon, 22 Jul 2024 18:12:06 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix modref_eaf_analysis::analyze_ssa_name handling of values dereferenced to function call parameters Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Hi, modref_eaf_analysis::analyze_ssa_name misinterprets EAF flags. If dereferenced parameter is passed (to map_iterator in the testcase) it can be returned indirectly which in turn makes it to escape into the next function call. Bootstrapped/rgtested x86_64-linux, comitted. Will backport it to gcc14 PR ipa/115033 gcc/ChangeLog: * ipa-modref.cc (modref_eaf_analysis::analyze_ssa_name): Fix checking of EAF flags when analysing values dereferenced as function parameters. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/pr115033.c: New test. diff --git a/gcc/ipa-modref.cc b/gcc/ipa-modref.cc index a5adce8ea39..f994388a96a 100644 --- a/gcc/ipa-modref.cc +++ b/gcc/ipa-modref.cc @@ -2571,8 +2571,10 @@ modref_eaf_analysis::analyze_ssa_name (tree name, bool deferred) int call_flags = deref_flags (gimple_call_arg_flags (call, i), ignore_stores); if (!ignore_retval && !(call_flags & EAF_UNUSED) - && !(call_flags & EAF_NOT_RETURNED_DIRECTLY) - && !(call_flags & EAF_NOT_RETURNED_INDIRECTLY)) + && (call_flags & (EAF_NOT_RETURNED_DIRECTLY + | EAF_NOT_RETURNED_INDIRECTLY)) + != (EAF_NOT_RETURNED_DIRECTLY + | EAF_NOT_RETURNED_INDIRECTLY)) merge_call_lhs_flags (call, i, name, false, true); if (ecf_flags & (ECF_CONST | ECF_NOVOPS)) m_lattice[index].merge_direct_load (); diff --git a/gcc/testsuite/gcc.c-torture/execute/pr115033.c b/gcc/testsuite/gcc.c-torture/execute/pr115033.c new file mode 100644 index 00000000000..3e79367d401 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr115033.c @@ -0,0 +1,35 @@ + +typedef struct func +{ + int *a; +}func; +__attribute__((noinline)) +void ff(struct func *t) +{ + *(t->a) = 0; +} + + +typedef struct mapped_iterator { + func F; +}mapped_iterator; + +__attribute__((noinline)) +mapped_iterator map_iterator(func F) { + mapped_iterator t = {F}; + return t; +} + +void map_to_vector(func *F) { + mapped_iterator t = map_iterator(*F); + ff(&t.F); +} +int main() { + int resultIsStatic = 1; + func t ={&resultIsStatic}; + map_to_vector(&t); + + if (resultIsStatic) + __builtin_trap(); + __builtin_exit(0); +}