From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30998 invoked by alias); 6 May 2016 11:16:03 -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 30982 invoked by uid 89); 6 May 2016 11:16:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Fri, 06 May 2016 11:16:02 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3DC63AB9D; Fri, 6 May 2016 11:15:59 +0000 (UTC) Subject: Re: [PATCH, RFC] Introduce -fsanitize=use-after-scope To: GCC Patches References: <572C7A3E.4000905@suse.cz> Cc: Jakub Jelinek From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: <572C7CEE.3070808@suse.cz> Date: Fri, 06 May 2016 11:16:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <572C7A3E.4000905@suse.cz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-05/txt/msg00471.txt.bz2 Hello. One more issue I forgot to mention in the previous email: e) As one can come up with a source code which jumps to a label within a block scope (use-after-scope-goto-1.c): // { dg-do run } // { dg-additional-options "-fsanitize=use-after-scope -fstack-reuse=none" } int main(int argc, char **argv) { int a = 123; if (argc == 0) { int *ptr; label: { ptr = &a; *ptr = 1; return 0; } } else goto label; return 0; } It's necessary to record all local variables in gimplifier and possibly emit unpoisoning code when a LABEL_EXPR is seen. That results in following gimple output: label: _20 = (unsigned long) &a; _21 = (unsigned long) 4; __builtin___asan_unpoison_stack_memory (_20, _21); _22 = (unsigned long) &ptr; _23 = (unsigned long) 8; __builtin___asan_unpoison_stack_memory (_22, _23); ptr = &a; ptr.0_10 = ptr; _24 = (unsigned long) ptr.0_10; _25 = _24 >> 3; _26 = _25 + 2147450880; _27 = (signed char *) _26; _28 = *_27; _29 = _28 != 0; _30 = _24 & 7; _31 = (signed char) _30; _32 = _31 + 3; _33 = _32 >= _28; _34 = _29 & _33; if (_34 != 0) goto ; else goto ; I know that the solution is a big hammer, but it works. Martin