diff options
author | mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-11-11 14:47:03 +0000 |
---|---|---|
committer | mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-11-11 14:47:03 +0000 |
commit | 81b1b2a83ca0cbbd36da96e6c982ba0edd6a86a2 (patch) | |
tree | 48b3e7d70614879dd48b43b013beb7831d9ad8ba /gcc/c-family/c-common.c | |
parent | 2f6fec152e06bcc38c0ae16eb31255e762f9aa37 (diff) | |
download | gcc-81b1b2a83ca0cbbd36da96e6c982ba0edd6a86a2.tar.gz |
PR c/68107
PR c++/68266
* c-common.c (valid_array_size_p): New function.
* c-common.h (valid_array_size_p): Declare.
* c-decl.c (grokdeclarator): Call valid_array_size_p. Remove code
checking the size of an array.
* decl.c (grokdeclarator): Call valid_array_size_p. Remove code
checking the size of an array.
* c-c++-common/pr68107.c: New test.
* g++.dg/init/new38.C (large_array_char): Adjust dg-error.
(large_array_char_template): Likewise.
* g++.dg/init/new44.C: Adjust dg-error.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@230174 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-family/c-common.c')
-rw-r--r-- | gcc/c-family/c-common.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 8b424d3477b..6e2ce0a736c 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -13107,4 +13107,26 @@ warn_duplicated_cond_add_or_warn (location_t loc, tree cond, vec<tree> **chain) (*chain)->safe_push (cond); } +/* Check if array size calculations overflow or if the array covers more + than half of the address space. Return true if the size of the array + is valid, false otherwise. TYPE is the type of the array and NAME is + the name of the array, or NULL_TREE for unnamed arrays. */ + +bool +valid_array_size_p (location_t loc, tree type, tree name) +{ + if (type != error_mark_node + && COMPLETE_TYPE_P (type) + && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST + && !valid_constant_size_p (TYPE_SIZE_UNIT (type))) + { + if (name) + error_at (loc, "size of array %qE is too large", name); + else + error_at (loc, "size of unnamed array is too large"); + return false; + } + return true; +} + #include "gt-c-family-c-common.h" |