2017-05-30 Jakub Jelinek <jakub@redhat.com>
Backported from mainline
+ 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-20 Jakub Jelinek <jakub@redhat.com>
PR c++/77637
}
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
Backported from mainline
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.
+
PR fortran/77666
* gfortran.dg/gomp/pr77666.f90: New test.
--- /dev/null
+// 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" }
--- /dev/null
+// 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" }
--- /dev/null
+// 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" }