aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2013-11-03 17:59:31 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2013-11-03 17:59:31 +0000
commitb906f4ca813779c4df4a9449700e8f52022f757f (patch)
tree47ea0e1220f5468397f6fdb89cae25257bd9e763 /gcc/c-family
parent612211412cdcd9112fb2538f2a2bbc5a18c2d16d (diff)
downloadgcc-b906f4ca813779c4df4a9449700e8f52022f757f.zip
gcc-b906f4ca813779c4df4a9449700e8f52022f757f.tar.gz
gcc-b906f4ca813779c4df4a9449700e8f52022f757f.tar.bz2
Implement -fsanitize=vla-bound.
* opts.c (common_handle_option): Handle vla-bound. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE): Define. * flag-types.h (enum sanitize_code): Add SANITIZE_VLA. * asan.c (initialize_sanitizer_builtins): Build BT_FN_VOID_PTR_PTR. c-family/ * c-ubsan.c: Don't include hash-table.h. (ubsan_instrument_vla): New function. * c-ubsan.h: Declare it. cp/ * decl.c (cp_finish_decl): Move C++1y bounds checking... (compute_array_index_type): ...here. Add VLA instrumentation. Call stabilize_vla_size. (grokdeclarator): Don't call stabilize_vla_size here. c/ * c-decl.c (grokdeclarator): Add VLA instrumentation. testsuite/ * g++.dg/ubsan/cxx1y-vla.C: New test. * c-c++-common/ubsan/vla-3.c: New test. * c-c++-common/ubsan/vla-2.c: New test. * c-c++-common/ubsan/vla-4.c: New test. * c-c++-common/ubsan/vla-1.c: New test. From-SVN: r204334
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-ubsan.c23
-rw-r--r--gcc/c-family/c-ubsan.h1
3 files changed, 27 insertions, 3 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 13a6687..569f4c2 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2013-11-03 Marek Polacek <polacek@redhat.com>
+
+ * c-ubsan.c: Don't include hash-table.h.
+ (ubsan_instrument_vla): New function.
+ * c-ubsan.h: Declare it.
+
2013-10-31 David Malcolm <dmalcolm@redhat.com>
Automated part of renaming of symtab_node_base to symtab_node.
diff --git a/gcc/c-family/c-ubsan.c b/gcc/c-family/c-ubsan.c
index 0bfc660..c989638 100644
--- a/gcc/c-family/c-ubsan.c
+++ b/gcc/c-family/c-ubsan.c
@@ -25,7 +25,6 @@ along with GCC; see the file COPYING3. If not see
#include "alloc-pool.h"
#include "cgraph.h"
#include "gimple.h"
-#include "hash-table.h"
#include "output.h"
#include "toplev.h"
#include "ubsan.h"
@@ -86,8 +85,7 @@ ubsan_instrument_division (location_t loc, tree op0, tree op1)
return t;
}
-/* Instrument left and right shifts. If not instrumenting, return
- NULL_TREE. */
+/* Instrument left and right shifts. */
tree
ubsan_instrument_shift (location_t loc, enum tree_code code,
@@ -158,3 +156,22 @@ ubsan_instrument_shift (location_t loc, enum tree_code code,
return t;
}
+
+/* Instrument variable length array bound. */
+
+tree
+ubsan_instrument_vla (location_t loc, tree size)
+{
+ tree type = TREE_TYPE (size);
+ tree t, tt;
+
+ t = fold_build2 (LE_EXPR, boolean_type_node, size, build_int_cst (type, 0));
+ tree data = ubsan_create_data ("__ubsan_vla_data",
+ loc, ubsan_type_descriptor (type), NULL_TREE);
+ data = build_fold_addr_expr_loc (loc, data);
+ tt = builtin_decl_explicit (BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE);
+ tt = build_call_expr_loc (loc, tt, 2, data, ubsan_encode_value (size));
+ t = fold_build3 (COND_EXPR, void_type_node, t, tt, void_zero_node);
+
+ return t;
+}
diff --git a/gcc/c-family/c-ubsan.h b/gcc/c-family/c-ubsan.h
index b032b70..fdf27d9 100644
--- a/gcc/c-family/c-ubsan.h
+++ b/gcc/c-family/c-ubsan.h
@@ -23,5 +23,6 @@ along with GCC; see the file COPYING3. If not see
extern tree ubsan_instrument_division (location_t, tree, tree);
extern tree ubsan_instrument_shift (location_t, enum tree_code, tree, tree);
+extern tree ubsan_instrument_vla (location_t, tree);
#endif /* GCC_C_UBSAN_H */