Commit 459bcfb0 by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/77722 (-fsanitize=undefined doesn't give runtime error in function…

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
parent bbfac6da
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> 2016-09-26 Nathan Sidwell <nathan@acm.org>
* init.c (expand_default_init): Fix } indentation. * init.c (expand_default_init): Fix } indentation.
......
...@@ -1570,14 +1570,11 @@ cp_ubsan_maybe_instrument_return (tree fndecl) ...@@ -1570,14 +1570,11 @@ cp_ubsan_maybe_instrument_return (tree fndecl)
} }
if (t == NULL_TREE) if (t == NULL_TREE)
return; return;
t = DECL_SAVED_TREE (fndecl); tree *p = &DECL_SAVED_TREE (fndecl);
if (TREE_CODE (t) == BIND_EXPR if (TREE_CODE (*p) == BIND_EXPR)
&& TREE_CODE (BIND_EXPR_BODY (t)) == STATEMENT_LIST) p = &BIND_EXPR_BODY (*p);
{ t = ubsan_instrument_return (DECL_SOURCE_LOCATION (fndecl));
tree_stmt_iterator i = tsi_last (BIND_EXPR_BODY (t)); append_to_statement_list (t, p);
t = ubsan_instrument_return (DECL_SOURCE_LOCATION (fndecl));
tsi_link_after (&i, t, TSI_NEW_STMT);
}
} }
void void
......
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> 2016-09-27 Jiong Wang <jiong.wang@arm.com>
* lib/target-supports.exp * lib/target-supports.exp
......
// 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" }
// 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" }
// 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" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment