2013-08-30 18:12:58 +02:00
|
|
|
/* UndefinedBehaviorSanitizer, undefined behavior detector.
|
2014-01-02 23:23:26 +01:00
|
|
|
Copyright (C) 2013-2014 Free Software Foundation, Inc.
|
2013-08-30 18:12:58 +02:00
|
|
|
Contributed by Marek Polacek <polacek@redhat.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/>. */
|
|
|
|
|
|
|
|
#ifndef GCC_UBSAN_H
|
|
|
|
#define GCC_UBSAN_H
|
|
|
|
|
2013-11-19 12:45:15 +01:00
|
|
|
/* The various kinds of NULL pointer checks. */
|
|
|
|
enum ubsan_null_ckind {
|
|
|
|
UBSAN_LOAD_OF,
|
|
|
|
UBSAN_STORE_OF,
|
|
|
|
UBSAN_REF_BINDING,
|
|
|
|
UBSAN_MEMBER_ACCESS,
|
opts.c (common_handle_option): Handle -fsanitize=alignment.
* opts.c (common_handle_option): Handle -fsanitize=alignment.
* ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL.
(ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return
type to bool.
* stor-layout.h (min_align_of_type): New prototype.
* asan.c (pass_sanopt::execute): Don't perform gsi_next if
ubsan_expand* told us not to do it. Remove the extra gsi_end_p
check.
* ubsan.c: Include builtins.h.
(ubsan_expand_bounds_ifn): Change return type to bool,
always return true.
(ubsan_expand_null_ifn): Change return type to bool, change
argument to gimple_stmt_iterator *. Handle both null and alignment
sanitization, take type from ckind argument's type rather than
first argument.
(instrument_member_call): Removed.
(instrument_mem_ref): Remove t argument, add mem and base arguments.
Handle both null and alignment sanitization, don't say whole
struct access is member access. Build 3 argument IFN_UBSAN_NULL
call instead of 2 argument.
(instrument_null): Adjust instrument_mem_ref caller. Don't
instrument calls here.
(pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT
like SANITIZE_NULL.
* stor-layout.c (min_align_of_type): New function.
* flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT.
Or it into SANITIZE_UNDEFINED.
* doc/invoke.texi (-fsanitize=alignment): Document.
cp/
* cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or
-fsanitize=alignment call ubsan_maybe_instrument_reference
for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call
for calls to member functions.
c-family/
* c-common.h (min_align_of_type): Removed prototype.
* c-common.c (min_align_of_type): Removed.
* c-ubsan.h (ubsan_maybe_instrument_reference,
ubsan_maybe_instrument_member_call): New prototypes.
* c-ubsan.c: Include stor-layout.h and builtins.h.
(ubsan_maybe_instrument_reference_or_call,
ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New
functions.
testsuite/
* c-c++-common/ubsan/align-1.c: New test.
* c-c++-common/ubsan/align-2.c: New test.
* c-c++-common/ubsan/align-3.c: New test.
* c-c++-common/ubsan/align-4.c: New test.
* c-c++-common/ubsan/align-5.c: New test.
* c-c++-common/ubsan/attrib-4.c: New test.
* g++.dg/ubsan/align-1.C: New test.
* g++.dg/ubsan/align-2.C: New test.
* g++.dg/ubsan/align-3.C: New test.
* g++.dg/ubsan/attrib-1.C: New test.
* g++.dg/ubsan/null-1.C: New test.
* g++.dg/ubsan/null-2.C: New test.
From-SVN: r213406
2014-08-01 09:52:43 +02:00
|
|
|
UBSAN_MEMBER_CALL,
|
|
|
|
UBSAN_CTOR_CALL
|
2013-11-19 12:45:15 +01:00
|
|
|
};
|
|
|
|
|
2014-06-20 23:20:51 +02:00
|
|
|
/* This controls how ubsan prints types. Used in ubsan_type_descriptor. */
|
|
|
|
enum ubsan_print_style {
|
|
|
|
UBSAN_PRINT_NORMAL,
|
|
|
|
UBSAN_PRINT_POINTER,
|
|
|
|
UBSAN_PRINT_ARRAY
|
|
|
|
};
|
|
|
|
|
2013-11-19 12:45:15 +01:00
|
|
|
/* An extra data used by ubsan pointer checking. */
|
|
|
|
struct ubsan_mismatch_data {
|
|
|
|
tree align;
|
|
|
|
tree ckind;
|
|
|
|
};
|
|
|
|
|
opts.c (common_handle_option): Handle -fsanitize=alignment.
* opts.c (common_handle_option): Handle -fsanitize=alignment.
* ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL.
(ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return
type to bool.
* stor-layout.h (min_align_of_type): New prototype.
* asan.c (pass_sanopt::execute): Don't perform gsi_next if
ubsan_expand* told us not to do it. Remove the extra gsi_end_p
check.
* ubsan.c: Include builtins.h.
(ubsan_expand_bounds_ifn): Change return type to bool,
always return true.
(ubsan_expand_null_ifn): Change return type to bool, change
argument to gimple_stmt_iterator *. Handle both null and alignment
sanitization, take type from ckind argument's type rather than
first argument.
(instrument_member_call): Removed.
(instrument_mem_ref): Remove t argument, add mem and base arguments.
Handle both null and alignment sanitization, don't say whole
struct access is member access. Build 3 argument IFN_UBSAN_NULL
call instead of 2 argument.
(instrument_null): Adjust instrument_mem_ref caller. Don't
instrument calls here.
(pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT
like SANITIZE_NULL.
* stor-layout.c (min_align_of_type): New function.
* flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT.
Or it into SANITIZE_UNDEFINED.
* doc/invoke.texi (-fsanitize=alignment): Document.
cp/
* cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or
-fsanitize=alignment call ubsan_maybe_instrument_reference
for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call
for calls to member functions.
c-family/
* c-common.h (min_align_of_type): Removed prototype.
* c-common.c (min_align_of_type): Removed.
* c-ubsan.h (ubsan_maybe_instrument_reference,
ubsan_maybe_instrument_member_call): New prototypes.
* c-ubsan.c: Include stor-layout.h and builtins.h.
(ubsan_maybe_instrument_reference_or_call,
ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New
functions.
testsuite/
* c-c++-common/ubsan/align-1.c: New test.
* c-c++-common/ubsan/align-2.c: New test.
* c-c++-common/ubsan/align-3.c: New test.
* c-c++-common/ubsan/align-4.c: New test.
* c-c++-common/ubsan/align-5.c: New test.
* c-c++-common/ubsan/attrib-4.c: New test.
* g++.dg/ubsan/align-1.C: New test.
* g++.dg/ubsan/align-2.C: New test.
* g++.dg/ubsan/align-3.C: New test.
* g++.dg/ubsan/attrib-1.C: New test.
* g++.dg/ubsan/null-1.C: New test.
* g++.dg/ubsan/null-2.C: New test.
From-SVN: r213406
2014-08-01 09:52:43 +02:00
|
|
|
extern bool ubsan_expand_bounds_ifn (gimple_stmt_iterator *);
|
|
|
|
extern bool ubsan_expand_null_ifn (gimple_stmt_iterator *);
|
2013-08-30 18:12:58 +02:00
|
|
|
extern tree ubsan_instrument_unreachable (location_t);
|
2014-03-26 20:33:40 +01:00
|
|
|
extern tree ubsan_create_data (const char *, const location_t *,
|
2013-11-19 12:45:15 +01:00
|
|
|
const struct ubsan_mismatch_data *, ...);
|
2014-06-20 23:20:51 +02:00
|
|
|
extern tree ubsan_type_descriptor (tree, enum ubsan_print_style = UBSAN_PRINT_NORMAL);
|
2013-12-05 19:03:44 +01:00
|
|
|
extern tree ubsan_encode_value (tree, bool = false);
|
2013-08-30 18:12:58 +02:00
|
|
|
extern bool is_ubsan_builtin_p (tree);
|
2013-12-04 23:47:11 +01:00
|
|
|
extern tree ubsan_build_overflow_builtin (tree_code, location_t, tree, tree, tree);
|
2014-05-23 16:44:42 +02:00
|
|
|
extern tree ubsan_instrument_float_cast (location_t, tree, tree);
|
2013-08-30 18:12:58 +02:00
|
|
|
|
|
|
|
#endif /* GCC_UBSAN_H */
|
|
|
|
|