diff options
author | Marek Polacek <polacek@redhat.com> | 2013-11-03 17:59:31 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2013-11-03 17:59:31 +0000 |
commit | b906f4ca813779c4df4a9449700e8f52022f757f (patch) | |
tree | 47ea0e1220f5468397f6fdb89cae25257bd9e763 /gcc/c | |
parent | 612211412cdcd9112fb2538f2a2bbc5a18c2d16d (diff) | |
download | gcc-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')
-rw-r--r-- | gcc/c/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 11 |
2 files changed, 15 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index f009ee9..efb4ba8 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,7 @@ +2013-11-03 Marek Polacek <polacek@redhat.com> + + * c-decl.c (grokdeclarator): Add VLA instrumentation. + 2013-11-01 Jakub Jelinek <jakub@redhat.com> * c-typeck.c (c_finish_omp_clauses) <case OMP_CLAUSE_UNIFORM>: Go to diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 64718c5..2833fdb 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -45,6 +45,7 @@ along with GCC; see the file COPYING3. If not see #include "c-family/c-common.h" #include "c-family/c-objc.h" #include "c-family/c-pragma.h" +#include "c-family/c-ubsan.h" #include "c-lang.h" #include "langhooks.h" #include "tree-iterator.h" @@ -5411,6 +5412,16 @@ grokdeclarator (const struct c_declarator *declarator, with known value. */ this_size_varies = size_varies = true; warn_variable_length_array (name, size); + if (flag_sanitize & SANITIZE_VLA + && decl_context == NORMAL) + { + /* Evaluate the array size only once. */ + size = c_save_expr (size); + size = c_fully_fold (size, false, NULL); + size = fold_build2 (COMPOUND_EXPR, TREE_TYPE (size), + ubsan_instrument_vla (loc, size), + size); + } } if (integer_zerop (size) && !this_size_varies) |