From patchwork Mon Mar 20 21:22:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 741213 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vn86s2FD9z9s06 for ; Tue, 21 Mar 2017 08:22:40 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="k6TOsLCj"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=OuDsM6wOGch/R4Q9FnVY0ygcppq4E /5osUbJw2VijjYyToKCSMblVRYNElm1NeWAeBlqXtYRtJ7dS0a3oNQ2Ari8noUxI +1G/1Z0GGA1o9e4jue5XYTPSZndWeCWVnoG4vkC9+bT+5n/IMUEuiLc+RJSSZ06B DT7ZMyNpkppE60= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=B9DDm4smvhzo2xq5JQaCureVWa4=; b=k6T OsLCjfNdys3xrINErdvRshj2q0tKpk6QtkAp3ZxAzU622F0bXB8WDoAkjjkOC0Mg ExBR9oWEYySurtosb3xNTeRv6JyiVtjBS4iW+bj+KteRM4NJ3vEJ1LhWP6hOUQaK D9lqbnFNDo0+vuOJzGpoJfjdgfEeCv7HiFgmSqV0= Received: (qmail 6664 invoked by alias); 20 Mar 2017 21:22:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk 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 6639 invoked by uid 89); 20 Mar 2017 21:22:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*MI:20170320212224 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; Mon, 20 Mar 2017 21:22:28 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47FDE64387; Mon, 20 Mar 2017 21:22:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 47FDE64387 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 47FDE64387 Received: from tucnak.zalov.cz (ovpn-116-72.ams2.redhat.com [10.36.116.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2A7CE4B86; Mon, 20 Mar 2017 21:22:28 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v2KLMPX0010535; Mon, 20 Mar 2017 22:22:25 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v2KLMOqK010534; Mon, 20 Mar 2017 22:22:24 +0100 Date: Mon, 20 Mar 2017 22:22:24 +0100 From: Jakub Jelinek To: Richard Biener , Dodji Seketeli Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix -fsanitize=thread -O0 handling of atomics (PR sanitizer/78158) Message-ID: <20170320212224.GP11094@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! libtsan only handles the standard memory model values, so I've added just in case some new unknown memory model is used bail outs (keeping the __atomic_* builtins instead of transforming them to __tsan_atomic*). Except that at -O0 (or if unlucky enough otherwise) if the memory model is variable, that means we never use __tsan_atomic*, which means libtsan reports false positive races. We could do those checks at runtime by performing if ((last_arg & 0x7fff) >= 6) __atomic_* else __tsan_atomic_*, but as there are no such values yet I think it isn't worth it (the sync/hle acq/hle rel bits which are ored are 0x8000, 0x10000 and 0x20000 and memmodel_base strips them off). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-03-20 Jakub Jelinek PR sanitizer/78158 * tsan.c (instrument_builtin_call): If the memory model argument is not a constant, assume it is valid. Jakub --- gcc/tsan.c.jj 2017-01-01 12:45:38.000000000 +0100 +++ gcc/tsan.c 2017-03-20 17:55:25.509294018 +0100 @@ -499,8 +499,8 @@ instrument_builtin_call (gimple_stmt_ite case check_last: case fetch_op: last_arg = gimple_call_arg (stmt, num - 1); - if (!tree_fits_uhwi_p (last_arg) - || memmodel_base (tree_to_uhwi (last_arg)) >= MEMMODEL_LAST) + if (tree_fits_uhwi_p (last_arg) + && memmodel_base (tree_to_uhwi (last_arg)) >= MEMMODEL_LAST) return; gimple_call_set_fndecl (stmt, decl); update_stmt (stmt); @@ -564,11 +564,11 @@ instrument_builtin_call (gimple_stmt_ite gcc_assert (num == 6); for (j = 0; j < 6; j++) args[j] = gimple_call_arg (stmt, j); - if (!tree_fits_uhwi_p (args[4]) - || memmodel_base (tree_to_uhwi (args[4])) >= MEMMODEL_LAST) + if (tree_fits_uhwi_p (args[4]) + && memmodel_base (tree_to_uhwi (args[4])) >= MEMMODEL_LAST) return; - if (!tree_fits_uhwi_p (args[5]) - || memmodel_base (tree_to_uhwi (args[5])) >= MEMMODEL_LAST) + if (tree_fits_uhwi_p (args[5]) + && memmodel_base (tree_to_uhwi (args[5])) >= MEMMODEL_LAST) return; update_gimple_call (gsi, decl, 5, args[0], args[1], args[2], args[4], args[5]); @@ -642,8 +642,8 @@ instrument_builtin_call (gimple_stmt_ite return; } last_arg = gimple_call_arg (stmt, num - 1); - if (!tree_fits_uhwi_p (last_arg) - || memmodel_base (tree_to_uhwi (last_arg)) >= MEMMODEL_LAST) + if (tree_fits_uhwi_p (last_arg) + && memmodel_base (tree_to_uhwi (last_arg)) >= MEMMODEL_LAST) return; t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t = TREE_VALUE (TREE_CHAIN (t));