summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2017-07-31 08:46:29 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2017-07-31 08:46:29 +0000
commit33e4f1ba7f17a42bbcdc72011e97dcec6932e4f6 (patch)
treed45b2364794bcf8ebeb15c4bee7a20fdb02496a8
parent6fd6385c7a79f761cfdd7ad5bb9d4de9182a9373 (diff)
downloadgcc-33e4f1ba7f17a42bbcdc72011e97dcec6932e4f6.tar.gz
PR sanitizer/81604
* ubsan.c (ubsan_type_descriptor): For UBSAN_PRINT_ARRAY don't change type to the element type, instead add eltype variable and use it where we are interested in the element type. * c-c++-common/ubsan/pr81604.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@250729 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/pr81604.c31
-rw-r--r--gcc/ubsan.c13
4 files changed, 50 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9695b23c276..04949df8594 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2017-07-31 Jakub Jelinek <jakub@redhat.com>
+
+ PR sanitizer/81604
+ * ubsan.c (ubsan_type_descriptor): For UBSAN_PRINT_ARRAY don't
+ change type to the element type, instead add eltype variable and
+ use it where we are interested in the element type.
+
2017-07-28 Peter Bergner <bergner@vnet.ibm.com>
Backport from mainline
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5f7ff85a294..0659b699920 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-07-31 Jakub Jelinek <jakub@redhat.com>
+
+ PR sanitizer/81604
+ * c-c++-common/ubsan/pr81604.c: New test.
+
2017-07-28 Peter Bergner <bergner@vnet.ibm.com>
Backport from mainline
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr81604.c b/gcc/testsuite/c-c++-common/ubsan/pr81604.c
new file mode 100644
index 00000000000..a06de76b023
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/pr81604.c
@@ -0,0 +1,31 @@
+/* PR sanitizer/81604 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=bounds,signed-integer-overflow" } */
+
+long a[10];
+
+__attribute__((noinline, noclone)) long *
+foo (int i)
+{
+ return &a[i];
+}
+
+__attribute__((noinline, noclone)) long
+bar (long x, long y)
+{
+ return x * y;
+}
+
+int
+main ()
+{
+ volatile int i = -1;
+ volatile long l = __LONG_MAX__;
+ long *volatile p;
+ p = foo (i);
+ l = bar (l, l);
+ return 0;
+}
+
+/* { dg-output "index -1 out of bounds for type 'long int \\\[10\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*signed integer overflow: \[0-9]+ \\* \[0-9]+ cannot be represented in type 'long int'" } */
diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index fa58589b7d8..daee6975a64 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -400,6 +400,7 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
/* We weren't able to determine the type name. */
tname = "<unknown>";
+ tree eltype = type;
if (pstyle == UBSAN_PRINT_POINTER)
{
pp_printf (&pretty_name, "'%s%s%s%s%s%s%s",
@@ -450,12 +451,12 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
pp_quote (&pretty_name);
/* Save the tree with stripped types. */
- type = t;
+ eltype = t;
}
else
pp_printf (&pretty_name, "'%s'", tname);
- switch (TREE_CODE (type))
+ switch (TREE_CODE (eltype))
{
case BOOLEAN_TYPE:
case ENUMERAL_TYPE:
@@ -465,9 +466,9 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
case REAL_TYPE:
/* FIXME: libubsan right now only supports float, double and
long double type formats. */
- if (TYPE_MODE (type) == TYPE_MODE (float_type_node)
- || TYPE_MODE (type) == TYPE_MODE (double_type_node)
- || TYPE_MODE (type) == TYPE_MODE (long_double_type_node))
+ if (TYPE_MODE (eltype) == TYPE_MODE (float_type_node)
+ || TYPE_MODE (eltype) == TYPE_MODE (double_type_node)
+ || TYPE_MODE (eltype) == TYPE_MODE (long_double_type_node))
tkind = 0x0001;
else
tkind = 0xffff;
@@ -476,7 +477,7 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
tkind = 0xffff;
break;
}
- tinfo = get_ubsan_type_info_for_type (type);
+ tinfo = get_ubsan_type_info_for_type (eltype);
/* Create a new VAR_DECL of type descriptor. */
const char *tmp = pp_formatted_text (&pretty_name);