From patchwork Fri Apr 12 07:50:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1922922 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=a6Aqb57x; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VG7yw44Qrz1yYP for ; Fri, 12 Apr 2024 17:50:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A8C193858427 for ; Fri, 12 Apr 2024 07:50:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 A580E3858D38 for ; Fri, 12 Apr 2024 07:50:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A580E3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A580E3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712908213; cv=none; b=dWLxjcFavIibP09BGq88R1KZLUDHEg55ZjSrL/7vQDzohqSaBcSYG5pie0oZvzDA2Sjdvai5zIe+sID3sxrYf+Wf/zbMLSBquo4tUxe21EjEmherpy6vITkiwR5xdMg+QwsA5AFkDwOhi8L+h22kkQc31OUUN0hRU/wPpRTwLEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712908213; c=relaxed/simple; bh=QqODwz9SYrIQTUxmKhXkh0AH27IpNOqV08/KhW6J/TM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=AWDw+BGej8h+jVXGQ3fQtaAN052iJ5mg5KFvZROqz1jj9O9HmgVkQOFCaH7YfFbXmCnws4gbYPYJsNKLkWzGPWI8P9tOfZuwFsd+lTJEqQ/HV2PT0eAgc5Kh+ksDvrGyVLK6YF9++ZE6EJvPWk+Dk0YlD/dMqMUAkH9X4R7RmWo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712908211; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=AHRybQs62Yk2+AV1/YZj5w83b98j4mR6P05oN4HhSU8=; b=a6Aqb57xWwygLDXVlSQtnfPV2sj7Xjf4kbq9VzeQf4MVQLnFHJCpeCRhJrNCfjmAWS4XKD oQf2uOj4ZloApluqHwhKOoDzsw4taxKAtogSGCtim/T5KPiIYswBuZs3+nBPqr+Zlu2rj6 D+o0//IBZvU+wUHV60rr5BowEYlGMjg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-463-xzq0hSgtNVW1bShfC7FE-Q-1; Fri, 12 Apr 2024 03:50:07 -0400 X-MC-Unique: xzq0hSgtNVW1bShfC7FE-Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8583A380391B; Fri, 12 Apr 2024 07:50:07 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 489F21121306; Fri, 12 Apr 2024 07:50:07 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 43C7o1cj1725319 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 12 Apr 2024 09:50:01 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 43C7o18w1725318; Fri, 12 Apr 2024 09:50:01 +0200 Date: Fri, 12 Apr 2024 09:50:01 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Limit special asan/ubsan/bitint returns_twice handling to calls in bbs with abnormal pred [PR114687] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The tree-cfg.cc verifier only diagnoses returns_twice calls preceded by non-label/debug stmts if it is in a bb with abnormal predecessor. The following testcase shows that if a user lies in the attributes (a function which never returns can't be pure, and can't return twice when it doesn't ever return at all), when we figure it out, we can remove the abnormal edges to the "returns_twice" call and perhaps whole .ABNORMAL_DISPATCHER etc. edge_before_returns_twice_call then ICEs because it can't find such an edge. The following patch limits the special handling to calls in bbs where the verifier requires that. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-04-12 Jakub Jelinek PR sanitizer/114687 * gimple-iterator.cc (gsi_safe_insert_before): Only use edge_before_returns_twice_call if bb_has_abnormal_pred. (gsi_safe_insert_seq_before): Likewise. * gimple-lower-bitint.cc (bitint_large_huge::lower_call): Only push to m_returns_twice_calls if bb_has_abnormal_pred. * gcc.dg/asan/pr114687.c: New test. Jakub --- gcc/gimple-iterator.cc.jj 2024-03-14 09:57:09.024966285 +0100 +++ gcc/gimple-iterator.cc 2024-04-11 17:05:06.267081433 +0200 @@ -1049,7 +1049,8 @@ gsi_safe_insert_before (gimple_stmt_iter gimple *stmt = gsi_stmt (*iter); if (stmt && is_gimple_call (stmt) - && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0) + && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0 + && bb_has_abnormal_pred (gsi_bb (*iter))) { edge e = edge_before_returns_twice_call (gsi_bb (*iter)); basic_block new_bb = gsi_insert_on_edge_immediate (e, g); @@ -1072,7 +1073,8 @@ gsi_safe_insert_seq_before (gimple_stmt_ gimple *stmt = gsi_stmt (*iter); if (stmt && is_gimple_call (stmt) - && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0) + && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0 + && bb_has_abnormal_pred (gsi_bb (*iter))) { edge e = edge_before_returns_twice_call (gsi_bb (*iter)); gimple *f = gimple_seq_first_stmt (seq); --- gcc/gimple-lower-bitint.cc.jj 2024-04-09 09:28:21.261123664 +0200 +++ gcc/gimple-lower-bitint.cc 2024-04-11 17:06:58.033548199 +0200 @@ -5320,7 +5320,7 @@ bitint_large_huge::lower_call (tree obj, arg = make_ssa_name (TREE_TYPE (arg)); gimple *g = gimple_build_assign (arg, v); gsi_insert_before (&gsi, g, GSI_SAME_STMT); - if (returns_twice) + if (returns_twice && bb_has_abnormal_pred (gimple_bb (stmt))) { m_returns_twice_calls.safe_push (stmt); returns_twice = false; --- gcc/testsuite/gcc.dg/asan/pr114687.c.jj 2024-04-11 17:09:54.518127165 +0200 +++ gcc/testsuite/gcc.dg/asan/pr114687.c 2024-04-11 17:09:22.699563654 +0200 @@ -0,0 +1,22 @@ +/* PR sanitizer/114687 */ +/* { dg-do compile } */ + +int a; +int foo (int); + +__attribute__((pure, returns_twice)) int +bar (void) +{ + a = 1; + while (a) + a = 2; + return a; +} + +int +baz (void) +{ + int d = bar (); + foo (d); + return 0; +}