From patchwork Tue Jul 7 00:42:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 50802 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 32627218EA for ; Tue, 7 Jul 2015 00:42:51 +0000 (UTC) Received: by wgjx7 with SMTP id x7sf54949843wgj.3 for ; Mon, 06 Jul 2015 17:42:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:mime-version:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-original-sender :x-original-authentication-results; bh=a4Nnu9GF+jJlLYsJ5oO5z+m3pV9d3qLsQJCWlkNkwak=; b=PhK9pKOF3SXjxF3bdPQfW/9b5I6Xb9LmU+t8TsJxBkfChY+fnfs1qDYT3qbslTZD8q QvyL9CkpCwkLA0WatSdFOckR/bi7aVtRNFVViUbjloX03DUJiJ++VvHgHjk6qWolmn8m zfERhsCkbQw4Q91fvZ1ih7GleV7s9UG0tRVbvAKc609dS74vOV61cQd3J2SP0Yj+vRyE 6/YZeHBYPNus3xyPlVLzUkU/AKdIMfKsiN8RjZ8HXIJa9Mh69lkqah7FFVqCZq4dBxBX 8BtAWl21YQ4uGVhQBmSD4Iuxf8A2A5sXDL+fE85iqXjg2XPnvBLyYe9vEiCamNowEl3Z kVnw== X-Gm-Message-State: ALoCoQn1HueUA/1sff3d281tRvK942BNeXoOC0rWjPwM4NZPe2gjno1TuQdgpGfHir5lhJBMvmNH X-Received: by 10.152.120.69 with SMTP id la5mr734769lab.7.1436229770110; Mon, 06 Jul 2015 17:42:50 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.4 with SMTP id x4ls746276lag.100.gmail; Mon, 06 Jul 2015 17:42:49 -0700 (PDT) X-Received: by 10.112.210.137 with SMTP id mu9mr1370494lbc.95.1436229769844; Mon, 06 Jul 2015 17:42:49 -0700 (PDT) Received: from mail-la0-x234.google.com (mail-la0-x234.google.com. [2a00:1450:4010:c03::234]) by mx.google.com with ESMTPS id k5si16662782lag.54.2015.07.06.17.42.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 17:42:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::234 as permitted sender) client-ip=2a00:1450:4010:c03::234; Received: by laar3 with SMTP id r3so176065831laa.0 for ; Mon, 06 Jul 2015 17:42:49 -0700 (PDT) X-Received: by 10.152.26.163 with SMTP id m3mr1460069lag.86.1436229769605; Mon, 06 Jul 2015 17:42:49 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp2045613lbb; Mon, 6 Jul 2015 17:42:48 -0700 (PDT) X-Received: by 10.66.184.133 with SMTP id eu5mr2814434pac.75.1436229768056; Mon, 06 Jul 2015 17:42:48 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id o6si31526513pds.214.2015.07.06.17.42.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 17:42:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-402173-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 97838 invoked by alias); 7 Jul 2015 00:42:35 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 97823 invoked by uid 89); 7 Jul 2015 00:42:34 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yk0-f172.google.com Received: from mail-yk0-f172.google.com (HELO mail-yk0-f172.google.com) (209.85.160.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 07 Jul 2015 00:42:33 +0000 Received: by ykfs198 with SMTP id s198so59390130ykf.2 for ; Mon, 06 Jul 2015 17:42:31 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.129.46.143 with SMTP id u137mr1782840ywu.92.1436229751527; Mon, 06 Jul 2015 17:42:31 -0700 (PDT) Received: by 10.37.88.137 with HTTP; Mon, 6 Jul 2015 17:42:31 -0700 (PDT) In-Reply-To: References: Date: Tue, 7 Jul 2015 06:12:31 +0530 Message-ID: Subject: Re: fix segfault in verify_flow_info() with -dx option From: Prathamesh Kulkarni To: Richard Biener Cc: gcc Patches , Jeff Law X-IsSubscribed: yes X-Original-Sender: prathamesh.kulkarni@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::234 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 On 6 July 2015 at 12:00, Richard Biener wrote: > On Sun, Jul 5, 2015 at 2:07 PM, Prathamesh Kulkarni > wrote: >> Hi, >> Passing -dx causes segmentation fault: >> Test case: void f(void) {} >> >> ./test.c: In function 'f': >> ../test.c:3:1: internal compiler error: Segmentation fault >> } >> ^ >> 0xab6baf crash_signal >> /home/prathamesh.kulkarni/gnu-toolchain/src/gcc.git/gcc/toplev.c:366 >> 0x694b14 verify_flow_info() >> /home/prathamesh.kulkarni/gnu-toolchain/src/gcc.git/gcc/cfghooks.c:109 >> 0x9f7e64 execute_function_todo >> /home/prathamesh.kulkarni/gnu-toolchain/src/gcc.git/gcc/passes.c:1997 >> 0x9f86eb execute_todo >> /home/prathamesh.kulkarni/gnu-toolchain/src/gcc.git/gcc/passes.c:2042 >> >> Started with r210068. >> It looks like -dx causes cfun->cfg to be NULL, and hence the segfault >> in verify_flow_info(). >> The attached patch tries to fix it by adding a check to cfun->cfg before calling >> verify_flow_info() from execute_function_todo(). >> Bootstrapped and tested on x86_64-unknown-linux-gnu. >> OK for trunk ? > > No. We've checked cfun->curr_properties & PROP_cfg already. So whatever > is keeping that set but frees the CFG is the offender (and should > clear the flag). I think I have somewhat understood what's happening. -dx turns on flag rtl_dump_and_exit. pass_rest_of_compilation is gated on !rtl_dump_and_exit. Since rtl_dump_and_exit == 1 when -dx is passed, pass_rest_of_compilation and all the rtl passes inserted within pass_rest_of_compilation don't execute. One of these passes is pass_free_cfg which destorys PROP_cfg, but with -dx passed, this pass doesn't get executed and PROP_cfg remains set. Then pass_clean_state::execute() calls free_after_compilation(), which sets cfun->cfg = NULL. And hence after pass_clean_state finishes in execute_function_todo, we end up with cfun->cfg == NULL and CFG_prop set, which calls verify_flow_info() and we hit the segfault. The following untested patch tries to fix this by clearing CFG_prop in free_after_compilation. Shall that be correct approach ? Thanks, Prathamesh > > Richard. > >> Thank you, >> Prathamesh diff --git a/gcc/function.c b/gcc/function.c index 8134c4e..d540dc3 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -216,6 +216,7 @@ free_after_compilation (struct function *f) f->eh = NULL; f->machine = NULL; f->cfg = NULL; + f->curr_properties &= ~PROP_cfg; regno_reg_rtx = NULL; } diff --git a/gcc/testsuite/gcc.dg/dx-test.c b/gcc/testsuite/gcc.dg/dx-test.c new file mode 100644 index 0000000..579ccfb --- /dev/null +++ b/gcc/testsuite/gcc.dg/dx-test.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-dx" } */ + +void f(void) +{}