aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2015-01-27 10:58:00 +0100
committerYury Gribov <ygribov@gcc.gnu.org>2015-01-27 09:58:00 +0000
commitf4bdb96a3476e1e10655173cb8df2c41ea33038e (patch)
tree07e1b3004f5755f9ffcdb4ab6e91855bc8a0dd52 /gcc
parentd9c1646658cfa8c81c1d37b8a67fa7af59748546 (diff)
downloadgcc-f4bdb96a3476e1e10655173cb8df2c41ea33038e.zip
gcc-f4bdb96a3476e1e10655173cb8df2c41ea33038e.tar.gz
gcc-f4bdb96a3476e1e10655173cb8df2c41ea33038e.tar.bz2
re PR sanitizer/64741 (Incorrect size of UBSan type descriptors)
2015-01-27 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> PR ubsan/64741 * ubsan.c (ubsan_source_location): Refactor code. (ubsan_type_descriptor): Update type size. Refactor code. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r220159
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/ubsan.c26
2 files changed, 22 insertions, 11 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7972a4d..9a7d553 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-27 Jakub Jelinek <jakub@redhat.com>
+ Yury Gribov <y.gribov@samsung.com>
+
+ PR ubsan/64741
+ * ubsan.c (ubsan_source_location): Refactor code.
+ (ubsan_type_descriptor): Update type size. Refactor code.
+
2015-01-27 Richard Biener <rguenther@suse.de>
PR tree-optimization/56273
diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index a9df290..036e67e 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -328,10 +328,9 @@ ubsan_source_location (location_t loc)
else
{
/* Fill in the values from LOC. */
- size_t len = strlen (xloc.file);
- str = build_string (len + 1, xloc.file);
- TREE_TYPE (str) = build_array_type (char_type_node,
- build_index_type (size_int (len)));
+ size_t len = strlen (xloc.file) + 1;
+ str = build_string (len, xloc.file);
+ TREE_TYPE (str) = build_array_type_nelts (char_type_node, len);
TREE_READONLY (str) = 1;
TREE_STATIC (str) = 1;
str = build_fold_addr_expr (str);
@@ -504,6 +503,13 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
tinfo = get_ubsan_type_info_for_type (type);
/* Create a new VAR_DECL of type descriptor. */
+ const char *tmp = pp_formatted_text (&pretty_name);
+ size_t len = strlen (tmp) + 1;
+ tree str = build_string (len, tmp);
+ TREE_TYPE (str) = build_array_type_nelts (char_type_node, len);
+ TREE_READONLY (str) = 1;
+ TREE_STATIC (str) = 1;
+
char tmp_name[32];
static unsigned int type_var_id_num;
ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_type", type_var_id_num++);
@@ -514,14 +520,12 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
DECL_ARTIFICIAL (decl) = 1;
DECL_IGNORED_P (decl) = 1;
DECL_EXTERNAL (decl) = 0;
+ DECL_SIZE (decl)
+ = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (TREE_TYPE (str)));
+ DECL_SIZE_UNIT (decl)
+ = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
+ TYPE_SIZE_UNIT (TREE_TYPE (str)));
- const char *tmp = pp_formatted_text (&pretty_name);
- size_t len = strlen (tmp);
- tree str = build_string (len + 1, tmp);
- TREE_TYPE (str) = build_array_type (char_type_node,
- build_index_type (size_int (len)));
- TREE_READONLY (str) = 1;
- TREE_STATIC (str) = 1;
tree ctor = build_constructor_va (dtype, 3, NULL_TREE,
build_int_cst (short_unsigned_type_node,
tkind), NULL_TREE,