From patchwork Tue Mar 28 08:04:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 75887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2045847vqo; Tue, 28 Mar 2023 01:05:25 -0700 (PDT) X-Google-Smtp-Source: AKy350ZjnQQ/HD0O+6sJDVCCmnC8I3y3+cATKqHxP+EGfjthysnzK/ITkY6yH4vprKmOmJGsmVwq X-Received: by 2002:a17:907:1c2a:b0:886:7e24:82eb with SMTP id nc42-20020a1709071c2a00b008867e2482ebmr16145646ejc.21.1679990725457; Tue, 28 Mar 2023 01:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679990725; cv=none; d=google.com; s=arc-20160816; b=NYcADugh/N9uUEJLpIbxNhj5AmDfv+PabPJ2FGC1SqrejZHCD4KI8HWV4utClbuHi5 e+4LwwmEHCqoS8UnvbzyvXPlHNL7zNtSCJDs27tGeT00cbYKFtmKyD/hBNusk4j1MF5C EUg42jcZg23cVLWKPpkOXVTaG+DNyBUhHENw0VvaFUxLVGQ2MY5W+7ns/37qP1vSUv+5 J8ajz+z63YDTLmj3lXzKM2BIZ1HHKgTAglSpa90BXmHxHQ/Am1F5uI0PvVSclTS2Em0N kzqu5IKW80kY1PJYCBgUZkX11MOvBcy0DDEoOLa4hA6Mei6f60KKoYeRExWUrrcqn99O QkxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=XbaRvXa/Q5eLQwQ/we2xOIGb9CD0vYQt19DTSBFDLYw=; b=esQj5V4LI+ylVe8ALm0O95N2uO9TLCNsrYzsvYXNEg0UbBmW2/b55jWVosENI0Bnes CDFtKHsLRK30qQOk5BHEt4TkJ3UOPLcnFxYgqm0tBZBCZkxWfhflcMNELk60mnRg36LC 5AOypUXe4ge+dVQG32VmF+MgAWzKZULZHsCIq+DKnHHZop2b+V/1Lpczu49tjawGVTCZ r3NkERb0FpSNxkja0s/Rc2OjmCzx5N7waMG3tcz7RGqE0qg10FUZC1DlNfRAwviyZ/Xx kkptJlz397Q+1kVI1ALn5BERwHhoH+Rnp3WuBsxA0LosZRnWuE4I2hskzaMYhJaHwrpy QpJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LLlyY63Q; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u22-20020a170906951600b0092a8aa23062si27735576ejx.571.2023.03.28.01.05.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 01:05:25 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LLlyY63Q; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FBF13858C1F for ; Tue, 28 Mar 2023 08:05:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FBF13858C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679990724; bh=XbaRvXa/Q5eLQwQ/we2xOIGb9CD0vYQt19DTSBFDLYw=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=LLlyY63Q/5b3Pnk+ZBwHUcdljLZV2MxwL1a7municLROgV/dgJ47w6bzI7d4AjsAy GL38zB7QZIY4Dt+83gkT1KM5zF8MrpPw2TlxEQKyzrZOQxr+QDT2TnFA88l7ojIS09 cDlXALFoDRYfqbAA1nTwbbdrSniqG1PwXV7LGasg= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 615B03858CDA for ; Tue, 28 Mar 2023 08:04:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 615B03858CDA 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-382-wm8zMZHVOcG5U_Qbxz69jQ-1; Tue, 28 Mar 2023 04:04:38 -0400 X-MC-Unique: wm8zMZHVOcG5U_Qbxz69jQ-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 7440180C8C1; Tue, 28 Mar 2023 08:04:38 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3702DC15BA0; Tue, 28 Mar 2023 08:04:38 +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 32S84Zaf1441980 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 28 Mar 2023 10:04:35 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32S84YsW1441979; Tue, 28 Mar 2023 10:04:34 +0200 Date: Tue, 28 Mar 2023 10:04:34 +0200 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] sanopt: Return TODO_cleanup_cfg if any .{UB,HWA,A}SAN_* calls were lowered [PR106190] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.3 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_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 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761597954820827708?= X-GMAIL-MSGID: =?utf-8?q?1761597954820827708?= Hi! The following testcase ICEs, because without optimization eh lowering decides not to duplicate finally block of try/finally and so we end up with variable guarded cleanup. The sanopt pass creates a cfg that ought to be cleaned up (some IFN_UBSAN_* functions are lowered in this case with constant conditions in gcond and when not allowing recovery some bbs which end with noreturn calls actually have successor edges), but the cfg cleanup is actually (it is -O0) done only during the optimized pass. We notice there that the d[1][a] = 0; statement which has an EH edge is unreachable (because ubsan would always abort on the out of bounds d[1] access), remove the EH landing pad and block, but because that block just sets a variable and jumps to another one which tests that variable and that one is reachable from normal control flow, the __builtin_eh_pointer (1) later in there is kept in the IL and we ICE during expansion of that statement because the EH region has been removed. The following patch fixes it by doing the cfg cleanup already during sanopt pass if we create something that might need it, while the EH landing pad is then removed already during sanopt pass, there is ehcleanup later and we don't ICE anymore. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-28 Jakub Jelinek PR middle-end/106190 * sanopt.cc (pass_sanopt::execute): Return TODO_cleanup_cfg if any of the IFN_{UB,HWA,A}SAN_* internal fns are lowered. * gcc.dg/asan/pr106190.c: New test. Jakub --- gcc/sanopt.cc.jj 2023-02-15 09:23:27.832389821 +0100 +++ gcc/sanopt.cc 2023-03-27 16:00:23.758621014 +0200 @@ -1300,6 +1300,7 @@ pass_sanopt::execute (function *fun) basic_block bb; int asan_num_accesses = 0; bool contains_asan_mark = false; + int ret = 0; /* Try to remove redundant checks. */ if (optimize @@ -1352,6 +1353,7 @@ pass_sanopt::execute (function *fun) if (gimple_call_internal_p (stmt)) { enum internal_fn ifn = gimple_call_internal_fn (stmt); + int this_ret = TODO_cleanup_cfg; switch (ifn) { case IFN_UBSAN_NULL: @@ -1387,8 +1389,10 @@ pass_sanopt::execute (function *fun) no_next = hwasan_expand_mark_ifn (&gsi); break; default: + this_ret = 0; break; } + ret |= this_ret; } else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { @@ -1418,7 +1422,7 @@ pass_sanopt::execute (function *fun) if (need_commit_edge_insert) gsi_commit_edge_inserts (); - return 0; + return ret; } } // anon namespace --- gcc/testsuite/gcc.dg/asan/pr106190.c.jj 2023-03-27 16:50:15.685501029 +0200 +++ gcc/testsuite/gcc.dg/asan/pr106190.c 2023-03-27 16:51:25.187499082 +0200 @@ -0,0 +1,15 @@ +/* PR middle-end/106190 */ +/* { dg-do compile } */ +/* { dg-options "-fnon-call-exceptions -fsanitize=address,undefined -fno-sanitize-recover=all" } */ + +int +main () +{ + int a; + int *b[1]; + int c[10]; + int d[1][1]; + for (a = 0; a < 1; a++) + d[1][a] = 0; + return 0; +}