summaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2017-07-31 10:53:00 +0200
committerMartin Liska <marxin@gcc.gnu.org>2017-07-31 08:53:00 +0000
commitf34ebeb25ef25e5937f60b7e6115c3f693a12ac3 (patch)
treebbf935d2f3780cbc507657f93feae23ae87fbd39 /gcc/c
parent066bbc5721fbda2affe061fc4025a622bf30d5b5 (diff)
downloadgcc-f34ebeb25ef25e5937f60b7e6115c3f693a12ac3.tar.gz
Do UBSAN sanitization just when current_function_decl != NULL_TREE (PR sanitize/81530).
2017-07-31 Martin Liska <mliska@suse.cz> PR sanitize/81530 * cp-gimplify.c (cp_genericize): Guard condition with flag_sanitize_p also with current_function_decl non-null equality. * cp-ubsan.c (cp_ubsan_instrument_vptr_p): Likewise. * decl.c (compute_array_index_type): Likewise. * init.c (finish_length_check): Likewise. * typeck.c (cp_build_binary_op): Likewise. 2017-07-31 Martin Liska <mliska@suse.cz> PR sanitize/81530 * c-convert.c (convert): Guard condition with flag_sanitize_p also with current_function_decl non-null equality. * c-decl.c (grokdeclarator): Likewise. * c-typeck.c (build_binary_op): Likewise. 2017-07-31 Martin Liska <mliska@suse.cz> PR sanitize/81530 * convert.c (convert_to_integer_1): Guard condition with flag_sanitize_p also with current_function_decl non-null equality. 2017-07-31 Martin Liska <mliska@suse.cz> PR sanitize/81530 * c-ubsan.c (ubsan_maybe_instrument_array_ref): Guard condition with flag_sanitize_p also with current_function_decl non-null equality. (ubsan_maybe_instrument_reference_or_call): Likewise. 2017-07-31 Martin Liska <mliska@suse.cz> PR sanitize/81530 * g++.dg/ubsan/pr81530.C: New test. From-SVN: r250730
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog8
-rw-r--r--gcc/c/c-convert.c1
-rw-r--r--gcc/c/c-decl.c1
-rw-r--r--gcc/c/c-typeck.c1
4 files changed, 11 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 4ce5360c0c1..ab2a4c88cee 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,11 @@
+2017-07-31 Martin Liska <mliska@suse.cz>
+
+ PR sanitize/81530
+ * c-convert.c (convert): Guard condition with flag_sanitize_p
+ also with current_function_decl non-null equality.
+ * c-decl.c (grokdeclarator): Likewise.
+ * c-typeck.c (build_binary_op): Likewise.
+
2017-07-25 Marek Polacek <polacek@redhat.com>
* c-decl.c (grokfield): Remove local variable.
diff --git a/gcc/c/c-convert.c b/gcc/c/c-convert.c
index 33c9143e354..bc649178f4c 100644
--- a/gcc/c/c-convert.c
+++ b/gcc/c/c-convert.c
@@ -108,6 +108,7 @@ convert (tree type, tree expr)
case INTEGER_TYPE:
case ENUMERAL_TYPE:
if (sanitize_flags_p (SANITIZE_FLOAT_CAST)
+ && current_function_decl != NULL_TREE
&& TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
&& COMPLETE_TYPE_P (type))
{
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 12fbc18bb94..a54e1218434 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -6052,6 +6052,7 @@ grokdeclarator (const struct c_declarator *declarator,
this_size_varies = size_varies = true;
warn_variable_length_array (name, size);
if (sanitize_flags_p (SANITIZE_VLA)
+ && current_function_decl != NULL_TREE
&& decl_context == NORMAL)
{
/* Evaluate the array size only once. */
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 4d067e96dd3..7451f3249fd 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -11838,6 +11838,7 @@ build_binary_op (location_t location, enum tree_code code,
if (sanitize_flags_p ((SANITIZE_SHIFT
| SANITIZE_DIVIDE | SANITIZE_FLOAT_DIVIDE))
+ && current_function_decl != NULL_TREE
&& (doing_div_or_mod || doing_shift)
&& !require_constant_value)
{