aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2016-09-27 20:15:21 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2016-09-27 20:15:21 +0200
commit459bcfb0bec5bb642685e0b54551995ab51fb156 (patch)
tree08e55ef5b8d2b493e0bc44e07eef1794f49a4747 /gcc
parentbbfac6da602bfe02c347edcb1639aa62ce63c2d4 (diff)
downloadgcc-459bcfb0bec5bb642685e0b54551995ab51fb156.zip
gcc-459bcfb0bec5bb642685e0b54551995ab51fb156.tar.gz
gcc-459bcfb0bec5bb642685e0b54551995ab51fb156.tar.bz2
re PR c++/77722 (-fsanitize=undefined doesn't give runtime error in function without return value, unless at least 2 instructions)
PR c++/77722 * cp-gimplify.c (cp_ubsan_maybe_instrument_return): Instrument also functions that have just a STATEMENT_LIST instead of BIND_EXPR, or BIND_EXPR with some statement rather than STATEMENT_LIST as body. * g++.dg/ubsan/return-4.C: New test. * g++.dg/ubsan/return-5.C: New test. * g++.dg/ubsan/return-6.C: New test. From-SVN: r240555
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/cp-gimplify.c13
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/g++.dg/ubsan/return-4.C18
-rw-r--r--gcc/testsuite/g++.dg/ubsan/return-5.C19
-rw-r--r--gcc/testsuite/g++.dg/ubsan/return-6.C20
6 files changed, 76 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f250a82..75c9d36 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2016-09-27 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/77722
+ * cp-gimplify.c (cp_ubsan_maybe_instrument_return): Instrument also
+ functions that have just a STATEMENT_LIST instead of BIND_EXPR, or
+ BIND_EXPR with some statement rather than STATEMENT_LIST as body.
+
2016-09-26 Nathan Sidwell <nathan@acm.org>
* init.c (expand_default_init): Fix } indentation.
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 6d514d0..5aca8f2 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -1570,14 +1570,11 @@ cp_ubsan_maybe_instrument_return (tree fndecl)
}
if (t == NULL_TREE)
return;
- t = DECL_SAVED_TREE (fndecl);
- if (TREE_CODE (t) == BIND_EXPR
- && TREE_CODE (BIND_EXPR_BODY (t)) == STATEMENT_LIST)
- {
- tree_stmt_iterator i = tsi_last (BIND_EXPR_BODY (t));
- t = ubsan_instrument_return (DECL_SOURCE_LOCATION (fndecl));
- tsi_link_after (&i, t, TSI_NEW_STMT);
- }
+ tree *p = &DECL_SAVED_TREE (fndecl);
+ if (TREE_CODE (*p) == BIND_EXPR)
+ p = &BIND_EXPR_BODY (*p);
+ t = ubsan_instrument_return (DECL_SOURCE_LOCATION (fndecl));
+ append_to_statement_list (t, p);
}
void
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ddbb525..443a917 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2016-09-27 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/77722
+ * g++.dg/ubsan/return-4.C: New test.
+ * g++.dg/ubsan/return-5.C: New test.
+ * g++.dg/ubsan/return-6.C: New test.
+
2016-09-27 Jiong Wang <jiong.wang@arm.com>
* lib/target-supports.exp
diff --git a/gcc/testsuite/g++.dg/ubsan/return-4.C b/gcc/testsuite/g++.dg/ubsan/return-4.C
new file mode 100644
index 0000000..d30eef8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/return-4.C
@@ -0,0 +1,18 @@
+// PR c++/77722
+// { dg-do run }
+// { dg-options "-fsanitize=return -w" }
+// { dg-shouldfail "ubsan" }
+
+int
+foo ()
+{
+}
+
+int
+main ()
+{
+ foo ();
+ return 0;
+}
+
+// { dg-output "execution reached the end of a value-returning function without returning a value" }
diff --git a/gcc/testsuite/g++.dg/ubsan/return-5.C b/gcc/testsuite/g++.dg/ubsan/return-5.C
new file mode 100644
index 0000000..2956c33
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/return-5.C
@@ -0,0 +1,19 @@
+// PR c++/77722
+// { dg-do run }
+// { dg-options "-fsanitize=return -w" }
+// { dg-shouldfail "ubsan" }
+
+int
+foo ()
+{
+ int a = 5;
+}
+
+int
+main ()
+{
+ foo ();
+ return 0;
+}
+
+// { dg-output "execution reached the end of a value-returning function without returning a value" }
diff --git a/gcc/testsuite/g++.dg/ubsan/return-6.C b/gcc/testsuite/g++.dg/ubsan/return-6.C
new file mode 100644
index 0000000..0c1e792
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/return-6.C
@@ -0,0 +1,20 @@
+// PR c++/77722
+// { dg-do run }
+// { dg-options "-fsanitize=return -w" }
+// { dg-shouldfail "ubsan" }
+
+int
+foo ()
+{
+ int a = 5;
+ int b = 5;
+}
+
+int
+main ()
+{
+ foo ();
+ return 0;
+}
+
+// { dg-output "execution reached the end of a value-returning function without returning a value" }