diff options
author | manu <manu@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-08-05 17:36:29 +0000 |
---|---|---|
committer | manu <manu@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-08-05 17:36:29 +0000 |
commit | 254d68a930fa4cd7a429910706454830d6b7ef07 (patch) | |
tree | 95eb22912610de69685ef6ec213edea83c4c6c6d /gcc/gimple-ssa-isolate-paths.c | |
parent | 373f5172dd219254b2f0fb6ce3553c25eb98c61e (diff) | |
download | gcc-254d68a930fa4cd7a429910706454830d6b7ef07.tar.gz |
gcc/ChangeLog:
2015-08-05 Manuel López-Ibáñez <manu@gcc.gnu.org>
Jeff Law <law@redhat.com>
PR c/16351
* doc/invoke.texi (Wnull-dereference): New.
* tree-vrp.c (infer_value_range): Update call to infer_nonnull_range.
* gimple-ssa-isolate-paths.c (find_implicit_erroneous_behaviour):
Warn for potential NULL dereferences.
(find_explicit_erroneous_behaviour): Warn for NULL dereferences.
* ubsan.c (instrument_nonnull_arg): Call
infer_nonnull_range_by_attribute.
(instrument_nonnull_return): Likewise.
* common.opt (Wnull-dereference); New.
* gimple.c (infer_nonnull_range): Remove bool arguments.
(infer_nonnull_range_by_dereference): New.
(infer_nonnull_range_by_attribute): New.
* gimple.h: Update declarations.
gcc/testsuite/ChangeLog:
2015-08-05 Manuel López-Ibáñez <manu@gcc.gnu.org>
Jeff Law <law@redhat.com>
PR c/16351
* gcc.dg/tree-ssa/isolate-2.c: Close comment.
* gcc.dg/tree-ssa/isolate-4.c: Likewise.
* gcc.dg/tree-ssa/wnull-dereference.c: New test.
* gcc.dg/tree-ssa/isolate-1.c: Test warnings with -Wnull-dereference.
* gcc.dg/tree-ssa/isolate-3.c: Likewise.
* gcc.dg/tree-ssa/isolate-5.c: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@226640 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gimple-ssa-isolate-paths.c')
-rw-r--r-- | gcc/gimple-ssa-isolate-paths.c | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/gcc/gimple-ssa-isolate-paths.c b/gcc/gimple-ssa-isolate-paths.c index 7d3758ce5ab..6f84f85856b 100644 --- a/gcc/gimple-ssa-isolate-paths.c +++ b/gcc/gimple-ssa-isolate-paths.c @@ -331,11 +331,29 @@ find_implicit_erroneous_behaviour (void) if (gimple_bb (use_stmt) != bb) continue; - if (infer_nonnull_range (use_stmt, lhs, - flag_isolate_erroneous_paths_dereference, - flag_isolate_erroneous_paths_attribute)) + bool by_dereference + = infer_nonnull_range_by_dereference (use_stmt, lhs); + if (by_dereference + || infer_nonnull_range_by_attribute (use_stmt, lhs)) { + location_t loc = gimple_location (use_stmt) + ? gimple_location (use_stmt) + : gimple_phi_arg_location (phi, i); + + if (by_dereference) + { + warning_at (loc, OPT_Wnull_dereference, + "potential null pointer dereference"); + if (!flag_isolate_erroneous_paths_dereference) + continue; + } + else + { + if (!flag_isolate_erroneous_paths_attribute) + continue; + } + duplicate = isolate_path (bb, duplicate, e, use_stmt, lhs, false); @@ -381,13 +399,29 @@ find_explicit_erroneous_behaviour (void) { gimple stmt = gsi_stmt (si); - /* By passing null_pointer_node, we can use infer_nonnull_range - to detect explicit NULL pointer dereferences and other uses - where a non-NULL value is required. */ - if (infer_nonnull_range (stmt, null_pointer_node, - flag_isolate_erroneous_paths_dereference, - flag_isolate_erroneous_paths_attribute)) + /* By passing null_pointer_node, we can use the + infer_nonnull_range functions to detect explicit NULL + pointer dereferences and other uses where a non-NULL + value is required. */ + + bool by_dereference + = infer_nonnull_range_by_dereference (stmt, null_pointer_node); + if (by_dereference + || infer_nonnull_range_by_attribute (stmt, null_pointer_node)) { + if (by_dereference) + { + warning_at (gimple_location (stmt), OPT_Wnull_dereference, + "null pointer dereference"); + if (!flag_isolate_erroneous_paths_dereference) + continue; + } + else + { + if (!flag_isolate_erroneous_paths_attribute) + continue; + } + insert_trap_and_remove_trailing_statements (&si, null_pointer_node); @@ -534,7 +568,8 @@ public: /* If we do not have a suitable builtin function for the trap statement, then do not perform the optimization. */ return (flag_isolate_erroneous_paths_dereference != 0 - || flag_isolate_erroneous_paths_attribute != 0); + || flag_isolate_erroneous_paths_attribute != 0 + || warn_null_dereference); } virtual unsigned int execute (function *) |