From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59340 invoked by alias); 16 May 2017 13:41:14 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 59197 invoked by uid 89); 16 May 2017 13:41:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 May 2017 13:41:07 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2478A80511; Tue, 16 May 2017 13:40:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2478A80511 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=polacek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2478A80511 Received: from redhat.com (ovpn-204-170.brq.redhat.com [10.40.204.170]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v4GDeqjm004357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 16 May 2017 09:40:55 -0400 Date: Tue, 16 May 2017 13:42:00 -0000 From: Marek Polacek To: GCC Patches , Jakub Jelinek , Richard Biener , Martin =?utf-8?B?TGnFoWth?= Subject: C PATCH to fix ASAN ICE with a compound literal (PR sanitizer/80659) Message-ID: <20170516134051.GE24582@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.8.0 (2017-02-23) X-SW-Source: 2017-05/txt/msg01278.txt.bz2 Martin L. asked me to have a look at this ICE with ASAN. This is an ICE with a compound literal in a switch. A hash map gimplify_ctxp->live_switch_vars is filled when processing DECL_EXPRs with their DECL_EXPR_DECLs. Such decls should then be removed from the hash map when gimplifying a BIND_EXPR. In C, non-static compound literals aren't pushed into any scope, so they were never found by gimplify_bind_expr, so they stayed in the hash map resulting in a crash on 2299 if (gimplify_ctxp->live_switch_vars) 2300 { 2301 gcc_assert (gimplify_ctxp->live_switch_vars->elements () == 0); 2302 delete gimplify_ctxp->live_switch_vars; 2303 } We don't add artificial decls to the hash map: 1647 if (!DECL_ARTIFICIAL (decl) && gimplify_ctxp->live_switch_vars) 1648 gimplify_ctxp->live_switch_vars->add (decl); build_compound_literal only marks a decl of a compound literal as artificial when the compound literal is static. I think there's no harm in marking decls of non-static compound literals as artificial, too (provided it's fine to skip asan instrumentation of compound literals). Bootstrapped/regtested on x86_64-linux, ok for trunk? 2017-05-16 Marek Polacek PR sanitizer/80659 * c-decl.c (build_compound_literal): Set DECL_ARTIFICIAL even for non-static compound literals. * gcc.dg/asan/pr80659.c: New test. diff --git gcc/c/c-decl.c gcc/c/c-decl.c index b779d37..887e95d 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -5261,6 +5261,7 @@ build_compound_literal (location_t loc, tree type, tree init, bool non_const) DECL_CONTEXT (decl) = current_function_decl; TREE_USED (decl) = 1; DECL_READ_P (decl) = 1; + DECL_ARTIFICIAL (decl) = 1; TREE_TYPE (decl) = type; TREE_READONLY (decl) = (TYPE_READONLY (type) || (TREE_CODE (type) == ARRAY_TYPE @@ -5297,7 +5298,6 @@ build_compound_literal (location_t loc, tree type, tree init, bool non_const) set_compound_literal_name (decl); DECL_DEFER_OUTPUT (decl) = 1; DECL_COMDAT (decl) = 1; - DECL_ARTIFICIAL (decl) = 1; DECL_IGNORED_P (decl) = 1; pushdecl (decl); rest_of_decl_compilation (decl, 1, 0); diff --git gcc/testsuite/gcc.dg/asan/pr80659.c gcc/testsuite/gcc.dg/asan/pr80659.c index e69de29..0cbf2e4 100644 --- gcc/testsuite/gcc.dg/asan/pr80659.c +++ gcc/testsuite/gcc.dg/asan/pr80659.c @@ -0,0 +1,13 @@ +/* PR sanitizer/80659 */ +/* { dg-do compile } */ + +void +foo (int a) +{ + switch (a) + { + case 0: + (int[3]) { }; + int h; + } +} Marek