diff options
author | Marek Polacek <polacek@redhat.com> | 2013-09-18 10:01:40 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2013-09-18 10:01:40 +0000 |
commit | ce6923c53da68bc3e0eabb1d071217402a104148 (patch) | |
tree | 03f7c27c5287577987f7b1ef007495fd35f4beb0 /gcc | |
parent | d30d00a2f1851cf6e6fe3b392a90b10e54388c20 (diff) | |
download | gcc-ce6923c53da68bc3e0eabb1d071217402a104148.zip gcc-ce6923c53da68bc3e0eabb1d071217402a104148.tar.gz gcc-ce6923c53da68bc3e0eabb1d071217402a104148.tar.bz2 |
re PR sanitizer/58411 (no_sanitize_undefined function attribute)
2013-09-18 Marek Polacek <polacek@redhat.com>
PR sanitizer/58411
* doc/extend.texi: Document no_sanitize_undefined attribute.
* builtins.c (fold_builtin_0): Don't sanitize function if it has the
no_sanitize_undefined attribute.
From-SVN: r202682
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/builtins.c | 5 | ||||
-rw-r--r-- | gcc/c-family/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 21 | ||||
-rw-r--r-- | gcc/c/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 2 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 2 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/ubsan/attrib-1.c | 33 |
11 files changed, 100 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ea746bc..8460d0a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2013-09-18 Marek Polacek <polacek@redhat.com> + + PR sanitizer/58411 + * doc/extend.texi: Document no_sanitize_undefined attribute. + * builtins.c (fold_builtin_0): Don't sanitize function if it has the + no_sanitize_undefined attribute. + 2013-09-18 Nick Clifton <nickc@redhat.com> * config/msp430/msp430.h (ASM_SPEC): Pass -md on to the assembler. diff --git a/gcc/builtins.c b/gcc/builtins.c index 0ab6d9b..d19ca68 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -10313,7 +10313,10 @@ fold_builtin_0 (location_t loc, tree fndecl, bool ignore ATTRIBUTE_UNUSED) return fold_builtin_classify_type (NULL_TREE); case BUILT_IN_UNREACHABLE: - if (flag_sanitize & SANITIZE_UNREACHABLE) + if (flag_sanitize & SANITIZE_UNREACHABLE + && (current_function_decl == NULL + || !lookup_attribute ("no_sanitize_undefined", + DECL_ATTRIBUTES (current_function_decl)))) return ubsan_instrument_unreachable (loc); break; diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 3061b4a..1772ba5 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2013-09-18 Marek Polacek <polacek@redhat.com> + + PR sanitizer/58411 + * c-common.c (handle_no_sanitize_undefined_attribute): New function. + Declare it. + (struct attribute_spec c_common_att): Add no_sanitize_undefined. + 2013-09-14 Iain Sandoe <iain@codesourcery.com> PR target/48094 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 62aa9fc..8ecb70c 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -311,6 +311,8 @@ static tree handle_no_sanitize_address_attribute (tree *, tree, tree, int, bool *); static tree handle_no_address_safety_analysis_attribute (tree *, tree, tree, int, bool *); +static tree handle_no_sanitize_undefined_attribute (tree *, tree, tree, int, + bool *); static tree handle_noinline_attribute (tree *, tree, tree, int, bool *); static tree handle_noclone_attribute (tree *, tree, tree, int, bool *); static tree handle_leaf_attribute (tree *, tree, tree, int, bool *); @@ -722,6 +724,9 @@ const struct attribute_spec c_common_attribute_table[] = { "no_sanitize_address", 0, 0, true, false, false, handle_no_sanitize_address_attribute, false }, + { "no_sanitize_undefined", 0, 0, true, false, false, + handle_no_sanitize_undefined_attribute, + false }, { "warning", 1, 1, true, false, false, handle_error_attribute, false }, { "error", 1, 1, true, false, false, @@ -6575,6 +6580,22 @@ handle_no_address_safety_analysis_attribute (tree *node, tree name, tree, int, return NULL_TREE; } +/* Handle a "no_sanitize_undefined" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_no_sanitize_undefined_attribute (tree *node, tree name, tree, int, + bool *no_add_attrs) +{ + if (TREE_CODE (*node) != FUNCTION_DECL) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* Handle a "noinline" attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 8b0cc2f..59b71aa 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2013-09-18 Marek Polacek <polacek@redhat.com> + + PR sanitizer/58411 + * c-typeck.c (build_binary_op): Don't sanitize function if it has the + no_sanitize_undefined attribute. + 2013-09-13 Kai Tietz <ktietz@redhat.com> PR target/57848 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index e52533e..7dc5527 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -10498,6 +10498,8 @@ build_binary_op (location_t location, enum tree_code code, if (flag_sanitize & SANITIZE_UNDEFINED && current_function_decl != 0 + && !lookup_attribute ("no_sanitize_undefined", + DECL_ATTRIBUTES (current_function_decl)) && (doing_div_or_mod || doing_shift)) { /* OP0 and/or OP1 might have side-effects. */ diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7e2c13b..c16d682 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-09-18 Marek Polacek <polacek@redhat.com> + + PR sanitizer/58411 + * typeck.c (cp_build_binary_op): Don't sanitize function if it has the + no_sanitize_undefined attribute. + 2013-09-17 Paolo Carlini <paolo.carlini@oracle.com> PR c++/58435 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 6c48f24..f7d6208 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4887,6 +4887,8 @@ cp_build_binary_op (location_t location, if ((flag_sanitize & SANITIZE_UNDEFINED) && !processing_template_decl && current_function_decl != 0 + && !lookup_attribute ("no_sanitize_undefined", + DECL_ATTRIBUTES (current_function_decl)) && (doing_div_or_mod || doing_shift)) { /* OP0 and/or OP1 might have side-effects. */ diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index cb0306b..1d0dfbe 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2136,6 +2136,7 @@ attributes are currently defined for functions on all targets: @code{warn_unused_result}, @code{nonnull}, @code{gnu_inline}, @code{externally_visible}, @code{hot}, @code{cold}, @code{artificial}, @code{no_sanitize_address}, @code{no_address_safety_analysis}, +@code{no_sanitize_undefined}, @code{error} and @code{warning}. Several other attributes are defined for functions on particular target systems. Other attributes, including @code{section} are @@ -3500,6 +3501,12 @@ The @code{no_address_safety_analysis} is a deprecated alias of the @code{no_sanitize_address} attribute, new code should use @code{no_sanitize_address}. +@item no_sanitize_undefined +@cindex @code{no_sanitize_undefined} function attribute +The @code{no_sanitize_undefined} attribute on functions is used +to inform the compiler that it should not check for undefined behavior +in the function when compiling with the @option{-fsanitize=undefined} option. + @item regparm (@var{number}) @cindex @code{regparm} attribute @cindex functions that are passed arguments in registers on the 386 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 796e143..2b1cad2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-09-18 Marek Polacek <polacek@redhat.com> + + PR sanitizer/58411 + * c-c++-common/ubsan/attrib-1.c: New test. + 2013-09-17 Cong Hou <congh@google.com> * gcc.dg/vect/vect-reduc-dot-s16c.c: Add a test case with dot product diff --git a/gcc/testsuite/c-c++-common/ubsan/attrib-1.c b/gcc/testsuite/c-c++-common/ubsan/attrib-1.c new file mode 100644 index 0000000..2e9141c --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/attrib-1.c @@ -0,0 +1,33 @@ +/* PR sanitizer/58411 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined -w" } */ + +__attribute__((no_sanitize_undefined)) int +f1 (int i) +{ + return 16 << i; +} + +int f2 (int i); +int f2 (int i) __attribute__((no_sanitize_undefined)); +int f2 (int i) __attribute__((no_sanitize_undefined)); +int f2 (int i); + +int +f2 (int i) +{ + return 1 / i; +} + +void f3 (void); +__typeof (f3) f3 __attribute__((__no_sanitize_undefined__)); + +void +f3 (void) +{ + __builtin_unreachable (); +} + +/* { dg-final { scan-assembler-not "__ubsan_handle_shift_out_of_bounds" } } */ +/* { dg-final { scan-assembler-not "__ubsan_handle_divrem_overflow" } } */ +/* { dg-final { scan-assembler-not "__ubsan_handle_builtin_unreachable" } } */ |