aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2014-11-18 14:55:44 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2014-11-18 14:55:44 +0000
commitbebcdc6742b065545ae976c8ed6638de17fe6ed7 (patch)
tree199a22a70f5272caac9621c1da38551db5437a84
parent594bdd53d8f24ad406af1aa192d98d23bc841ae9 (diff)
downloadgcc-bebcdc6742b065545ae976c8ed6638de17fe6ed7.zip
gcc-bebcdc6742b065545ae976c8ed6638de17fe6ed7.tar.gz
gcc-bebcdc6742b065545ae976c8ed6638de17fe6ed7.tar.bz2
re PR sanitizer/63866 (ICE in C++ printer with -fdump-ipa)
PR sanitizer/63866 * asan.c (asan_global_struct): Create a TYPE_DECL for "__asan_global", put it into TYPE_NAME and TYPE_STUB_DECL. * ubsan.c (ubsan_type_descriptor_type): New variable. Function renamed to ... (ubsan_get_type_descriptor_type): ... this. Cache return value in ubsan_type_descriptor_type variable. Create a TYPE_DECL for "__ubsan_type_descriptor", put it into TYPE_NAME and TYPE_STUB_DECL. (ubsan_get_source_location_type): Create a TYPE_DECL for "__ubsan_source_location", put it into TYPE_NAME and TYPE_STUB_DECL. (ubsan_type_descriptor, ubsan_create_data): Call ubsan_get_type_descriptor_type instead of ubsan_type_descriptor_type. Create a TYPE_DECL for name, put it into TYPE_NAME and TYPE_STUB_DECL. * c-c++-common/ubsan/pr63866.c: New test. From-SVN: r217718
-rw-r--r--gcc/ChangeLog17
-rw-r--r--gcc/asan.c7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/pr63866.c11
-rw-r--r--gcc/ubsan.c38
5 files changed, 70 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b8f9bd4..1e1d355 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,20 @@
+2014-11-18 Marek Polacek <polacek@redhat.com>
+
+ PR sanitizer/63866
+ * asan.c (asan_global_struct): Create a TYPE_DECL for "__asan_global",
+ put it into TYPE_NAME and TYPE_STUB_DECL.
+ * ubsan.c (ubsan_type_descriptor_type): New variable.
+ Function renamed to ...
+ (ubsan_get_type_descriptor_type): ... this. Cache
+ return value in ubsan_type_descriptor_type variable.
+ Create a TYPE_DECL for "__ubsan_type_descriptor", put it into
+ TYPE_NAME and TYPE_STUB_DECL.
+ (ubsan_get_source_location_type): Create a TYPE_DECL for
+ "__ubsan_source_location", put it into TYPE_NAME and TYPE_STUB_DECL.
+ (ubsan_type_descriptor, ubsan_create_data): Call
+ ubsan_get_type_descriptor_type instead of ubsan_type_descriptor_type.
+ Create a TYPE_DECL for name, put it into TYPE_NAME and TYPE_STUB_DECL.
+
2014-11-18 Felix Yang <felix.yang@huawei.com>
* config/aarch64/aarch64.c (doloop_end): New pattern.
diff --git a/gcc/asan.c b/gcc/asan.c
index 2961b44..d50e098 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -2168,8 +2168,13 @@ asan_global_struct (void)
if (i)
DECL_CHAIN (fields[i - 1]) = fields[i];
}
+ tree type_decl = build_decl (input_location, TYPE_DECL,
+ get_identifier ("__asan_global"), ret);
+ DECL_IGNORED_P (type_decl) = 1;
+ DECL_ARTIFICIAL (type_decl) = 1;
TYPE_FIELDS (ret) = fields[0];
- TYPE_NAME (ret) = get_identifier ("__asan_global");
+ TYPE_NAME (ret) = type_decl;
+ TYPE_STUB_DECL (ret) = type_decl;
layout_type (ret);
return ret;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 679db5b..ca77cc0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-11-18 Marek Polacek <polacek@redhat.com>
+
+ PR sanitizer/63866
+ * c-c++-common/ubsan/pr63866.c: New test.
+
2014-11-18 Richard Biener <rguenther@suse.de>
PR tree-optimization/63914
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr63866.c b/gcc/testsuite/c-c++-common/ubsan/pr63866.c
new file mode 100644
index 0000000..e70daa7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/pr63866.c
@@ -0,0 +1,11 @@
+/* PR sanitizer/63866 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined -fdump-ipa-cgraph" } */
+
+int
+foo (int x, int y)
+{
+ return x + y;
+}
+
+/* { dg-final { cleanup-ipa-dump "cgraph" } } */
diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index b5b1b92..98a6c2f 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -179,6 +179,9 @@ ubsan_encode_value (tree t, bool in_expand_p)
}
}
+/* Cached ubsan_get_type_descriptor_type () return value. */
+static GTY(()) tree ubsan_type_descriptor_type;
+
/* Build
struct __ubsan_type_descriptor
{
@@ -189,11 +192,15 @@ ubsan_encode_value (tree t, bool in_expand_p)
type. */
static tree
-ubsan_type_descriptor_type (void)
+ubsan_get_type_descriptor_type (void)
{
static const char *field_names[3]
= { "__typekind", "__typeinfo", "__typename" };
tree fields[3], ret;
+
+ if (ubsan_type_descriptor_type)
+ return ubsan_type_descriptor_type;
+
tree itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
tree flex_arr_type = build_array_type (char_type_node, itype);
@@ -208,9 +215,16 @@ ubsan_type_descriptor_type (void)
if (i)
DECL_CHAIN (fields[i - 1]) = fields[i];
}
+ tree type_decl = build_decl (input_location, TYPE_DECL,
+ get_identifier ("__ubsan_type_descriptor"),
+ ret);
+ DECL_IGNORED_P (type_decl) = 1;
+ DECL_ARTIFICIAL (type_decl) = 1;
TYPE_FIELDS (ret) = fields[0];
- TYPE_NAME (ret) = get_identifier ("__ubsan_type_descriptor");
+ TYPE_NAME (ret) = type_decl;
+ TYPE_STUB_DECL (ret) = type_decl;
layout_type (ret);
+ ubsan_type_descriptor_type = ret;
return ret;
}
@@ -249,8 +263,14 @@ ubsan_get_source_location_type (void)
if (i)
DECL_CHAIN (fields[i - 1]) = fields[i];
}
+ tree type_decl = build_decl (input_location, TYPE_DECL,
+ get_identifier ("__ubsan_source_location"),
+ ret);
+ DECL_IGNORED_P (type_decl) = 1;
+ DECL_ARTIFICIAL (type_decl) = 1;
TYPE_FIELDS (ret) = fields[0];
- TYPE_NAME (ret) = get_identifier ("__ubsan_source_location");
+ TYPE_NAME (ret) = type_decl;
+ TYPE_STUB_DECL (ret) = type_decl;
layout_type (ret);
ubsan_source_location_type = ret;
return ret;
@@ -333,7 +353,7 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
if (decl != NULL_TREE && varpool_node::get (decl))
return build_fold_addr_expr (decl);
- tree dtype = ubsan_type_descriptor_type ();
+ tree dtype = ubsan_get_type_descriptor_type ();
tree type2 = type;
const char *tname = NULL;
char *pretty_name;
@@ -498,8 +518,7 @@ ubsan_create_data (const char *name, int loccnt, const location_t *ploc, ...)
int j;
/* Firstly, create a pointer to type descriptor type. */
- tree td_type = ubsan_type_descriptor_type ();
- TYPE_READONLY (td_type) = 1;
+ tree td_type = ubsan_get_type_descriptor_type ();
td_type = build_pointer_type (td_type);
/* Create the structure type. */
@@ -543,8 +562,13 @@ ubsan_create_data (const char *name, int loccnt, const location_t *ploc, ...)
}
va_end (args);
+ tree type_decl = build_decl (input_location, TYPE_DECL,
+ get_identifier (name), ret);
+ DECL_IGNORED_P (type_decl) = 1;
+ DECL_ARTIFICIAL (type_decl) = 1;
TYPE_FIELDS (ret) = fields[0];
- TYPE_NAME (ret) = get_identifier (name);
+ TYPE_NAME (ret) = type_decl;
+ TYPE_STUB_DECL (ret) = type_decl;
layout_type (ret);
/* Now, fill in the type. */