GCC Middle and Back End API Reference
tsan.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "rtl.h"
#include "tree.h"
#include "memmodel.h"
#include "gimple.h"
#include "tree-pass.h"
#include "ssa.h"
#include "cgraph.h"
#include "fold-const.h"
#include "gimplify.h"
#include "gimple-iterator.h"
#include "gimplify-me.h"
#include "tree-cfg.h"
#include "tree-iterator.h"
#include "gimple-fold.h"
#include "tree-ssa-loop-ivopts.h"
#include "tree-eh.h"
#include "tsan.h"
#include "stringpool.h"
#include "attribs.h"
#include "asan.h"
#include "builtins.h"
#include "target.h"
#include "diagnostic-core.h"
Include dependency graph for tsan.cc:

Data Structures

struct  tsan_map_atomic
 

Macros

#define TRANSFORM(fcode, tsan_fcode, action, code)    { BUILT_IN_##fcode, BUILT_IN_##tsan_fcode, action, code }
 
#define CHECK_LAST(fcode, tsan_fcode)    TRANSFORM (fcode, tsan_fcode, check_last, ERROR_MARK)
 
#define ADD_SEQ_CST(fcode, tsan_fcode)    TRANSFORM (fcode, tsan_fcode, add_seq_cst, ERROR_MARK)
 
#define ADD_ACQUIRE(fcode, tsan_fcode)    TRANSFORM (fcode, tsan_fcode, add_acquire, ERROR_MARK)
 
#define WEAK_CAS(fcode, tsan_fcode)    TRANSFORM (fcode, tsan_fcode, weak_cas, ERROR_MARK)
 
#define STRONG_CAS(fcode, tsan_fcode)    TRANSFORM (fcode, tsan_fcode, strong_cas, ERROR_MARK)
 
#define BOOL_CAS(fcode, tsan_fcode)    TRANSFORM (fcode, tsan_fcode, bool_cas, ERROR_MARK)
 
#define VAL_CAS(fcode, tsan_fcode)    TRANSFORM (fcode, tsan_fcode, val_cas, ERROR_MARK)
 
#define LOCK_RELEASE(fcode, tsan_fcode)    TRANSFORM (fcode, tsan_fcode, lock_release, ERROR_MARK)
 
#define FETCH_OP(fcode, tsan_fcode, code)    TRANSFORM (fcode, tsan_fcode, fetch_op, code)
 
#define FETCH_OPS(fcode, tsan_fcode, code)    TRANSFORM (fcode, tsan_fcode, fetch_op_seq_cst, code)
 
#define BOOL_CLEAR(fcode, tsan_fcode)    TRANSFORM (fcode, tsan_fcode, bool_clear, ERROR_MARK)
 
#define BOOL_TEST_AND_SET(fcode, tsan_fcode)    TRANSFORM (fcode, tsan_fcode, bool_test_and_set, ERROR_MARK)
 

Enumerations

enum  tsan_atomic_action {
  check_last , add_seq_cst , add_acquire , weak_cas ,
  strong_cas , bool_cas , val_cas , lock_release ,
  fetch_op , fetch_op_seq_cst , bool_clear , bool_test_and_set
}
 

Functions

static tree get_memory_access_decl (bool is_write, unsigned size, bool volatilep)
 
static tree is_vptr_store (gimple *stmt, tree expr, bool is_write)
 
static bool instrument_expr (gimple_stmt_iterator gsi, tree expr, bool is_write)
 
static void instrument_builtin_call (gimple_stmt_iterator *gsi)
 
static bool instrument_gimple (gimple_stmt_iterator *gsi)
 
static void replace_func_exit (gimple *stmt)
 
static void instrument_func_exit (void)
 
static bool instrument_memory_accesses (bool *cfg_changed)
 
static void instrument_func_entry (void)
 
static unsigned tsan_pass (void)
 
void tsan_finish_file (void)
 
gimple_opt_passmake_pass_tsan (gcc::context *ctxt)
 
gimple_opt_passmake_pass_tsan_O0 (gcc::context *ctxt)
 

Variables

static const struct tsan_map_atomic tsan_atomic_table []
 

Macro Definition Documentation

◆ ADD_ACQUIRE

#define ADD_ACQUIRE ( fcode,
tsan_fcode )    TRANSFORM (fcode, tsan_fcode, add_acquire, ERROR_MARK)

◆ ADD_SEQ_CST

#define ADD_SEQ_CST ( fcode,
tsan_fcode )    TRANSFORM (fcode, tsan_fcode, add_seq_cst, ERROR_MARK)

◆ BOOL_CAS

#define BOOL_CAS ( fcode,
tsan_fcode )    TRANSFORM (fcode, tsan_fcode, bool_cas, ERROR_MARK)

◆ BOOL_CLEAR

#define BOOL_CLEAR ( fcode,
tsan_fcode )    TRANSFORM (fcode, tsan_fcode, bool_clear, ERROR_MARK)

◆ BOOL_TEST_AND_SET

#define BOOL_TEST_AND_SET ( fcode,
tsan_fcode )    TRANSFORM (fcode, tsan_fcode, bool_test_and_set, ERROR_MARK)

◆ CHECK_LAST

#define CHECK_LAST ( fcode,
tsan_fcode )    TRANSFORM (fcode, tsan_fcode, check_last, ERROR_MARK)

◆ FETCH_OP

#define FETCH_OP ( fcode,
tsan_fcode,
code )    TRANSFORM (fcode, tsan_fcode, fetch_op, code)

◆ FETCH_OPS

#define FETCH_OPS ( fcode,
tsan_fcode,
code )    TRANSFORM (fcode, tsan_fcode, fetch_op_seq_cst, code)

◆ LOCK_RELEASE

#define LOCK_RELEASE ( fcode,
tsan_fcode )    TRANSFORM (fcode, tsan_fcode, lock_release, ERROR_MARK)

◆ STRONG_CAS

#define STRONG_CAS ( fcode,
tsan_fcode )    TRANSFORM (fcode, tsan_fcode, strong_cas, ERROR_MARK)

◆ TRANSFORM

#define TRANSFORM ( fcode,
tsan_fcode,
action,
code )    { BUILT_IN_##fcode, BUILT_IN_##tsan_fcode, action, code }

◆ VAL_CAS

#define VAL_CAS ( fcode,
tsan_fcode )    TRANSFORM (fcode, tsan_fcode, val_cas, ERROR_MARK)

◆ WEAK_CAS

#define WEAK_CAS ( fcode,
tsan_fcode )    TRANSFORM (fcode, tsan_fcode, weak_cas, ERROR_MARK)

Enumeration Type Documentation

◆ tsan_atomic_action

Actions for sync/atomic builtin transformations.   
Enumerator
check_last 
add_seq_cst 
add_acquire 
weak_cas 
strong_cas 
bool_cas 
val_cas 
lock_release 
fetch_op 
fetch_op_seq_cst 
bool_clear 
bool_test_and_set 

Function Documentation

◆ get_memory_access_decl()

static tree get_memory_access_decl ( bool is_write,
unsigned size,
bool volatilep )
static
GCC instrumentation plugin for ThreadSanitizer.
   Copyright (C) 2011-2024 Free Software Foundation, Inc.
   Contributed by Dmitry Vyukov <dvyukov@google.com>

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
Number of instrumented memory accesses in the current function.   
Builds the following decl
void __tsan_read/writeX (void *addr);   

References builtin_decl_implicit(), and ggc_alloc().

Referenced by instrument_expr().

◆ instrument_builtin_call()

◆ instrument_expr()

◆ instrument_func_entry()

◆ instrument_func_exit()

◆ instrument_gimple()

◆ instrument_memory_accesses()

static bool instrument_memory_accesses ( bool * cfg_changed)
static
Instruments all interesting memory accesses in the current function.
Return true if func entry/exit should be instrumented.   

References cfg_changed, cfun, FOR_EACH_BB_FN, FOR_EACH_VEC_ELT, ggc_alloc(), gimple_call_internal_p(), gimple_purge_dead_eh_edges(), gsi_end_p(), gsi_for_stmt(), gsi_next(), gsi_remove(), gsi_start_bb(), gsi_stmt(), i, instrument_func_exit(), instrument_gimple(), and replace_func_exit().

Referenced by tsan_pass().

◆ is_vptr_store()

static tree is_vptr_store ( gimple * stmt,
tree expr,
bool is_write )
static
Check as to whether EXPR refers to a store to vptr.   

References DECL_VIRTUAL_P, ggc_alloc(), gimple_assign_rhs1(), gimple_assign_single_p(), NULL, TREE_CODE, and TREE_OPERAND.

Referenced by instrument_expr().

◆ make_pass_tsan()

gimple_opt_pass * make_pass_tsan ( gcc::context * ctxt)

References ggc_alloc().

◆ make_pass_tsan_O0()

gimple_opt_pass * make_pass_tsan_O0 ( gcc::context * ctxt)

References ggc_alloc().

◆ replace_func_exit()

static void replace_func_exit ( gimple * stmt)
static
Replace TSAN_FUNC_EXIT internal call with function exit tsan builtin.   

References builtin_decl_implicit(), cfun, g, ggc_alloc(), gimple_build_call(), gimple_set_location(), gsi_for_stmt(), and gsi_replace().

Referenced by instrument_memory_accesses().

◆ tsan_finish_file()

◆ tsan_pass()

static unsigned tsan_pass ( void )
static

Variable Documentation

◆ tsan_atomic_table

const struct tsan_map_atomic tsan_atomic_table[]
static

Referenced by instrument_builtin_call().