From patchwork Wed Dec 9 09:24:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1413293 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CrWpv0271z9sTg for ; Wed, 9 Dec 2020 20:24:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB6BE3842438; Wed, 9 Dec 2020 09:24:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 256583842433 for ; Wed, 9 Dec 2020 09:24:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 256583842433 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mliska@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E673EADB3; Wed, 9 Dec 2020 09:24:44 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] Add -Wtsan. To: gcc-patches@gcc.gnu.org Message-ID: Date: Wed, 9 Dec 2020 10:24:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: Jakub Jelinek , Marc Glisse Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hello. The newly added warning is about warning a user that std::atomic_thread_fence is not supported by TSAN. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin gcc/ChangeLog: PR sanitizer/97868 * common.opt: Add new warning -Wtsan. * doc/invoke.texi: Likewise. * tsan.c (instrument_builtin_call): Warn users about unsupported std::atomic_thread_fence. --- gcc/common.opt | 4 ++++ gcc/doc/invoke.texi | 8 +++++++- gcc/tsan.c | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/common.opt b/gcc/common.opt index 6645539f5e5..6c24c7bbffb 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -842,6 +842,10 @@ Wvector-operation-performance Common Var(warn_vector_operation_performance) Warning Warn when a vector operation is compiled outside the SIMD. +Wtsan +Common Var(warn_tsan) Init(1) Warning +Warn about unsupported features in the ThreadSanitizer. + Xassembler Driver Separate diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index f7e8c8b29b0..5bd18c78e99 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -377,7 +377,7 @@ Objective-C and Objective-C++ Dialects}. -Wswitch -Wno-switch-bool -Wswitch-default -Wswitch-enum @gol -Wno-switch-outside-range -Wno-switch-unreachable -Wsync-nand @gol -Wsystem-headers -Wtautological-compare -Wtrampolines -Wtrigraphs @gol --Wtype-limits -Wundef @gol +-Wtsan -Wtype-limits -Wundef @gol -Wuninitialized -Wunknown-pragmas @gol -Wunsuffixed-float-constants -Wunused @gol -Wunused-but-set-parameter -Wunused-but-set-variable @gol @@ -7951,6 +7951,12 @@ Note that the code above is invalid in C++11. This warning is enabled by default. +@item -Wtsan +@opindex Wtsan +@opindex Wno-tsan +Warn about unsupported features in the ThreadSanitizer. +This warning is enabled by default. + @item -Wtype-limits @opindex Wtype-limits @opindex Wno-type-limits diff --git a/gcc/tsan.c b/gcc/tsan.c index 4d6223454b5..be9fabea62a 100644 --- a/gcc/tsan.c +++ b/gcc/tsan.c @@ -45,6 +45,7 @@ along with GCC; see the file COPYING3. If not see #include "asan.h" #include "builtins.h" #include "target.h" +#include "diagnostic-core.h" /* Number of instrumented memory accesses in the current function. */ @@ -500,6 +501,11 @@ instrument_builtin_call (gimple_stmt_iterator *gsi) continue; else { + if (fcode == BUILT_IN_ATOMIC_THREAD_FENCE) + warning_at (gimple_location (stmt), OPT_Wtsan, + "%qs is not supported by ThreadSanitizer and may " + "lead to false positives", "atomic_thread_fence"); + tree decl = builtin_decl_implicit (tsan_atomic_table[i].tsan_fcode); if (decl == NULL_TREE) return;