/* This file contains the definitions and documentation for the
   Address Sanitizer and Thread Sanitizer builtins used in the GNU compiler.
   Copyright (C) 2012-2013 Free Software Foundation, Inc.

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/>.  */

/* Before including this file, you should define a macro:

     DEF_SANITIZER_BUILTIN (ENUM, NAME, TYPE, ATTRS)

   See builtins.def for details.
   The builtins are created by the C-family of FEs in c-family/c-common.c,
   for other FEs by asan.c.  */

/* Address Sanitizer */
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_INIT, "__asan_init_v1",
		      BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
/* Do not reorder the BUILT_IN_ASAN_REPORT* builtins, e.g. cfgcleanup.c
   relies on this order.  */
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REPORT_LOAD1, "__asan_report_load1",
		      BT_FN_VOID_PTR, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REPORT_LOAD2, "__asan_report_load2",
		      BT_FN_VOID_PTR, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REPORT_LOAD4, "__asan_report_load4",
		      BT_FN_VOID_PTR, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REPORT_LOAD8, "__asan_report_load8",
		      BT_FN_VOID_PTR, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REPORT_LOAD16, "__asan_report_load16",
		      BT_FN_VOID_PTR, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REPORT_STORE1, "__asan_report_store1",
		      BT_FN_VOID_PTR, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REPORT_STORE2, "__asan_report_store2",
		      BT_FN_VOID_PTR, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REPORT_STORE4, "__asan_report_store4",
		      BT_FN_VOID_PTR, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REPORT_STORE8, "__asan_report_store8",
		      BT_FN_VOID_PTR, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REPORT_STORE16, "__asan_report_store16",
		      BT_FN_VOID_PTR, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_REGISTER_GLOBALS,
		      "__asan_register_globals",
		      BT_FN_VOID_PTR_PTRMODE, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_UNREGISTER_GLOBALS,
		      "__asan_unregister_globals",
		      BT_FN_VOID_PTR_PTRMODE, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_ASAN_HANDLE_NO_RETURN,
		      "__asan_handle_no_return",
		      BT_FN_VOID, ATTR_TMPURE_NOTHROW_LEAF_LIST)

/* Thread Sanitizer */
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_INIT, "__tsan_init", 
		      BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_FUNC_ENTRY, "__tsan_func_entry",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_FUNC_EXIT, "__tsan_func_exit",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_VPTR_UPDATE, "__tsan_vptr_update",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_READ1, "__tsan_read1",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_READ2, "__tsan_read2",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_READ4, "__tsan_read4",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_READ8, "__tsan_read8",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_READ16, "__tsan_read16",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_WRITE1, "__tsan_write1",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_WRITE2, "__tsan_write2",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_WRITE4, "__tsan_write4",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_WRITE8, "__tsan_write8",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_WRITE16, "__tsan_write16",
		      BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_LOAD,
		      "__tsan_atomic8_load",
		      BT_FN_I1_CONST_VPTR_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_LOAD,
		      "__tsan_atomic16_load",
		      BT_FN_I2_CONST_VPTR_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_LOAD,
		      "__tsan_atomic32_load",
		      BT_FN_I4_CONST_VPTR_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_LOAD,
		      "__tsan_atomic64_load",
		      BT_FN_I8_CONST_VPTR_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_LOAD,
		      "__tsan_atomic128_load",
		      BT_FN_I16_CONST_VPTR_INT, ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_STORE,
		      "__tsan_atomic8_store",
		      BT_FN_VOID_VPTR_I1_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_STORE,
		      "__tsan_atomic16_store",
		      BT_FN_VOID_VPTR_I2_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_STORE,
		      "__tsan_atomic32_store",
		      BT_FN_VOID_VPTR_I4_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_STORE,
		      "__tsan_atomic64_store",
		      BT_FN_VOID_VPTR_I8_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_STORE,
		      "__tsan_atomic128_store",
		      BT_FN_VOID_VPTR_I16_INT, ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_EXCHANGE,
		      "__tsan_atomic8_exchange",
		      BT_FN_I1_VPTR_I1_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_EXCHANGE,
		      "__tsan_atomic16_exchange",
		      BT_FN_I2_VPTR_I2_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_EXCHANGE,
		      "__tsan_atomic32_exchange",
		      BT_FN_I4_VPTR_I4_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_EXCHANGE,
		      "__tsan_atomic64_exchange",
		      BT_FN_I8_VPTR_I8_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_EXCHANGE,
		      "__tsan_atomic128_exchange",
		      BT_FN_I16_VPTR_I16_INT, ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_FETCH_ADD,
		      "__tsan_atomic8_fetch_add",
		      BT_FN_I1_VPTR_I1_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_FETCH_ADD,
		      "__tsan_atomic16_fetch_add",
		      BT_FN_I2_VPTR_I2_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_FETCH_ADD,
		      "__tsan_atomic32_fetch_add",
		      BT_FN_I4_VPTR_I4_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_FETCH_ADD,
		      "__tsan_atomic64_fetch_add",
		      BT_FN_I8_VPTR_I8_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_FETCH_ADD,
		      "__tsan_atomic128_fetch_add",
		      BT_FN_I16_VPTR_I16_INT, ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_FETCH_SUB,
		      "__tsan_atomic8_fetch_sub",
		      BT_FN_I1_VPTR_I1_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_FETCH_SUB,
		      "__tsan_atomic16_fetch_sub",
		      BT_FN_I2_VPTR_I2_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_FETCH_SUB,
		      "__tsan_atomic32_fetch_sub",
		      BT_FN_I4_VPTR_I4_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_FETCH_SUB,
		      "__tsan_atomic64_fetch_sub",
		      BT_FN_I8_VPTR_I8_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_FETCH_SUB,
		      "__tsan_atomic128_fetch_sub",
		      BT_FN_I16_VPTR_I16_INT, ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_FETCH_AND,
		      "__tsan_atomic8_fetch_and",
		      BT_FN_I1_VPTR_I1_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_FETCH_AND,
		      "__tsan_atomic16_fetch_and",
		      BT_FN_I2_VPTR_I2_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_FETCH_AND,
		      "__tsan_atomic32_fetch_and",
		      BT_FN_I4_VPTR_I4_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_FETCH_AND,
		      "__tsan_atomic64_fetch_and",
		      BT_FN_I8_VPTR_I8_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_FETCH_AND,
		      "__tsan_atomic128_fetch_and",
		      BT_FN_I16_VPTR_I16_INT, ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_FETCH_OR,
		      "__tsan_atomic8_fetch_or",
		      BT_FN_I1_VPTR_I1_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_FETCH_OR,
		      "__tsan_atomic16_fetch_or",
		      BT_FN_I2_VPTR_I2_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_FETCH_OR,
		      "__tsan_atomic32_fetch_or",
		      BT_FN_I4_VPTR_I4_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_FETCH_OR,
		      "__tsan_atomic64_fetch_or",
		      BT_FN_I8_VPTR_I8_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_FETCH_OR,
		      "__tsan_atomic128_fetch_or",
		      BT_FN_I16_VPTR_I16_INT, ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_FETCH_XOR,
		      "__tsan_atomic8_fetch_xor",
		      BT_FN_I1_VPTR_I1_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_FETCH_XOR,
		      "__tsan_atomic16_fetch_xor",
		      BT_FN_I2_VPTR_I2_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_FETCH_XOR,
		      "__tsan_atomic32_fetch_xor",
		      BT_FN_I4_VPTR_I4_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_FETCH_XOR,
		      "__tsan_atomic64_fetch_xor",
		      BT_FN_I8_VPTR_I8_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_FETCH_XOR,
		      "__tsan_atomic128_fetch_xor",
		      BT_FN_I16_VPTR_I16_INT, ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_FETCH_NAND,
		      "__tsan_atomic8_fetch_nand",
		      BT_FN_I1_VPTR_I1_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_FETCH_NAND,
		      "__tsan_atomic16_fetch_nand",
		      BT_FN_I2_VPTR_I2_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_FETCH_NAND,
		      "__tsan_atomic32_fetch_nand",
		      BT_FN_I4_VPTR_I4_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_FETCH_NAND,
		      "__tsan_atomic64_fetch_nand",
		      BT_FN_I8_VPTR_I8_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_FETCH_NAND,
		      "__tsan_atomic128_fetch_nand",
		      BT_FN_I16_VPTR_I16_INT, ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_COMPARE_EXCHANGE_STRONG,
		      "__tsan_atomic8_compare_exchange_strong",
		      BT_FN_BOOL_VPTR_PTR_I1_INT_INT,
		      ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_COMPARE_EXCHANGE_STRONG,
		      "__tsan_atomic16_compare_exchange_strong",
		      BT_FN_BOOL_VPTR_PTR_I2_INT_INT,
		      ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_COMPARE_EXCHANGE_STRONG,
		      "__tsan_atomic32_compare_exchange_strong",
		      BT_FN_BOOL_VPTR_PTR_I4_INT_INT,
		      ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_COMPARE_EXCHANGE_STRONG,
		      "__tsan_atomic64_compare_exchange_strong",
		      BT_FN_BOOL_VPTR_PTR_I8_INT_INT,
		      ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_COMPARE_EXCHANGE_STRONG,
		      "__tsan_atomic128_compare_exchange_strong",
		      BT_FN_BOOL_VPTR_PTR_I16_INT_INT,
		      ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC8_COMPARE_EXCHANGE_WEAK,
		      "__tsan_atomic8_compare_exchange_weak",
		      BT_FN_BOOL_VPTR_PTR_I1_INT_INT,
		      ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC16_COMPARE_EXCHANGE_WEAK,
		      "__tsan_atomic16_compare_exchange_weak",
		      BT_FN_BOOL_VPTR_PTR_I2_INT_INT,
		      ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC32_COMPARE_EXCHANGE_WEAK,
		      "__tsan_atomic32_compare_exchange_weak",
		      BT_FN_BOOL_VPTR_PTR_I4_INT_INT,
		      ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC64_COMPARE_EXCHANGE_WEAK,
		      "__tsan_atomic64_compare_exchange_weak",
		      BT_FN_BOOL_VPTR_PTR_I8_INT_INT,
		      ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC128_COMPARE_EXCHANGE_WEAK,
		      "__tsan_atomic128_compare_exchange_weak",
		      BT_FN_BOOL_VPTR_PTR_I16_INT_INT,
		      ATTR_NOTHROW_LEAF_LIST)

DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC_THREAD_FENCE,
		      "__tsan_atomic_thread_fence",
		      BT_FN_VOID_INT, ATTR_NOTHROW_LEAF_LIST)
DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_ATOMIC_SIGNAL_FENCE,
		      "__tsan_atomic_signal_fence",
		      BT_FN_VOID_INT, ATTR_NOTHROW_LEAF_LIST)
