GCC Middle and Back End API Reference
ubsan.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "cgraph.h"
#include "gimple.h"
#include "hashtab.h"
#include "pointer-set.h"
#include "output.h"
#include "tm_p.h"
#include "toplev.h"
#include "ubsan.h"
#include "c-family/c-common.h"
#include "gt-ubsan.h"
Include dependency graph for ubsan.c:

Data Structures

struct  tree_type_map

Macros

#define tree_type_map_eq   tree_map_base_eq
#define tree_type_map_hash   tree_map_base_hash
#define tree_type_map_marked_p   tree_map_base_marked_p

Functions

static tree decl_for_type_lookup ()
static void decl_for_type_insert ()
tree ubsan_encode_value ()
static tree ubsan_type_descriptor_type ()
static tree ubsan_source_location_type ()
static tree ubsan_source_location ()
static unsigned short get_ubsan_type_info_for_type ()
tree ubsan_type_descriptor ()
tree ubsan_create_data ()
tree ubsan_instrument_unreachable ()
bool is_ubsan_builtin_p ()

Variables

static htab_t decl_tree_for_type

Macro Definition Documentation

#define tree_type_map_eq   tree_map_base_eq

Referenced by decl_for_type_lookup().

#define tree_type_map_hash   tree_map_base_hash

Referenced by decl_for_type_lookup().

#define tree_type_map_marked_p   tree_map_base_marked_p

Function Documentation

static void decl_for_type_insert ( )
static

Insert a mapping TYPE->DECL in the VAR_DECL for type hashtable.

static tree decl_for_type_lookup ( )
static

Lookup a VAR_DECL for TYPE, and return it if we find one.

If the hash table is not initialized yet, create it now.

     That also means we don't have to bother with the lookup.   

References htab_create_ggc, NULL_TREE, tree_type_map_eq, and tree_type_map_hash.

Referenced by get_ubsan_type_info_for_type().

static unsigned short get_ubsan_type_info_for_type ( )
static

This routine returns a magic number for TYPE.

References tree_type_map::decl, decl_for_type_lookup(), NULL_TREE, TYPE_MAIN_VARIANT, and ubsan_type_descriptor_type().

bool is_ubsan_builtin_p ( )

Return true if T is a call to a libubsan routine.

tree ubsan_create_data ( )

Create a structure for the ubsan library. NAME is a name of the new structure. The arguments in ... are of __ubsan_type_descriptor type and there are at most two of them.

 Firstly, create a pointer to type descriptor type.   
 Create the structure type.   
     Save the tree argument for later use.   
 Now, fill in the type.   
 If desirable, set the __ubsan_source_location element.   
tree ubsan_encode_value ( )

Helper routine, which encodes a value in the pointer_sized_int_node. Arguments with precision <= POINTER_SIZE are passed directly, the rest is passed by reference. T is a value we are to encode.

The reason for this is that we don't want to pessimize code by making vars unnecessarily addressable.

tree ubsan_instrument_unreachable ( )

Instrument the __builtin_unreachable call. We just call the libubsan routine instead.

static tree ubsan_source_location ( )
static

Helper routine that returns a CONSTRUCTOR of __ubsan_source_location type with its fields filled from a location_t LOC.

Fill in the values from LOC.

static tree ubsan_source_location_type ( )
static

Build struct ubsan_source_location { const char *filename; unsigned int __line; unsigned int __column; } type.

References build_decl, build_pointer_type(), DECL_CHAIN, DECL_CONTEXT, get_identifier(), UNKNOWN_LOCATION, and unsigned_type_node.

tree ubsan_type_descriptor ( )

Helper routine that returns ADDR_EXPR of a VAR_DECL of a type descriptor. It first looks into the pointer map; if not found, create the VAR_DECL, put it into the pointer map and return the ADDR_EXPR of it. TYPE describes a particular type.

 See through any typedefs.   
 At least for INTEGER_TYPE/REAL_TYPE/COMPLEX_TYPE, this should work.
 For e.g. type_unsigned_for (type) or bit-fields, the TYPE_NAME
 would be NULL.   
     For INTEGER_TYPE, this is 0x0000.   
   We don't have float support yet.   
 Create a new VAR_DECL of type descriptor.   
 Save the address of the VAR_DECL into the pointer map.   

References DECL_NAME, gdbhooks::IDENTIFIER_NODE, IDENTIFIER_POINTER, TREE_CODE, and TYPE_NAME.

static tree ubsan_type_descriptor_type ( )
static

Build struct __ubsan_type_descriptor { unsigned short __typekind; unsigned short __typeinfo; char __typename[]; } type.

Referenced by get_ubsan_type_info_for_type().


Variable Documentation

htab_t decl_tree_for_type
static