From a7c3e87ed900cb2b6ff0f72292e8a18cb87187b6 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 29 Jan 2015 21:40:07 +0100 Subject: [PATCH] =?utf8?q?re=20PR=20sanitizer/64717=20(-fsanitize=3Dvptr?= =?utf8?q?=20leads=20to=20warning:=20=E2=80=98=E2=80=99=20may?= =?utf8?q?=20be=20used=20uninitialized=20in=20this=20function=20[-Wmaybe-u?= =?utf8?q?ninitialized])?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit PR c++/64717 * cp-ubsan.c (cp_ubsan_instrument_vptr): Don't wrap vptr into SAVE_EXPR. * g++.dg/ubsan/pr64717-1.C: New test. * g++.dg/ubsan/pr64717-2.C: New test. From-SVN: r220262 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/cp-ubsan.c | 1 - gcc/testsuite/ChangeLog | 8 +++++++- gcc/testsuite/g++.dg/ubsan/pr64717-1.C | 15 +++++++++++++++ gcc/testsuite/g++.dg/ubsan/pr64717-2.C | 20 ++++++++++++++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ubsan/pr64717-1.C create mode 100644 gcc/testsuite/g++.dg/ubsan/pr64717-2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2280e6bd094..308e5bcc17f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-01-29 Jakub Jelinek + + PR c++/64717 + * cp-ubsan.c (cp_ubsan_instrument_vptr): Don't wrap vptr + into SAVE_EXPR. + 2015-01-29 Jason Merrill PR c++/49508 diff --git a/gcc/cp/cp-ubsan.c b/gcc/cp/cp-ubsan.c index 69e486442fe..ce122631770 100644 --- a/gcc/cp/cp-ubsan.c +++ b/gcc/cp/cp-ubsan.c @@ -107,7 +107,6 @@ cp_ubsan_instrument_vptr (location_t loc, tree op, tree type, bool is_addr, fold_build2 (NE_EXPR, boolean_type_node, op, build_zero_cst (TREE_TYPE (op))), vptr, build_int_cst (uint64_type_node, 0)); - vptr = build1_loc (loc, SAVE_EXPR, uint64_type_node, vptr); tree ti_decl = get_tinfo_decl (type); mark_used (ti_decl); tree ptype = build_pointer_type (type); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 66a2e2bc124..d3b38839083 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,10 @@ -2015-22-01 Uros Bizjak +2015-01-29 Jakub Jelinek + + PR c++/64717 + * g++.dg/ubsan/pr64717-1.C: New test. + * g++.dg/ubsan/pr64717-2.C: New test. + +2015-01-29 Uros Bizjak * gcc.dg/tree-ssa/pr64801.c: Fix scan-tree-dump-not directive. diff --git a/gcc/testsuite/g++.dg/ubsan/pr64717-1.C b/gcc/testsuite/g++.dg/ubsan/pr64717-1.C new file mode 100644 index 00000000000..45ed8c6f039 --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr64717-1.C @@ -0,0 +1,15 @@ +// PR c++/64717 +// { dg-do compile } +// { dg-options "-O2 -Wuninitialized -fsanitize=vptr" } + +class Foo {}; +Foo make_foo (); + +struct Handle { virtual ~Handle (); }; +Handle open (Foo); + +void +bar () +{ + Handle file (open (make_foo ())); // { dg-bogus "is used uninitialized" } +} diff --git a/gcc/testsuite/g++.dg/ubsan/pr64717-2.C b/gcc/testsuite/g++.dg/ubsan/pr64717-2.C new file mode 100644 index 00000000000..3f10440735f --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr64717-2.C @@ -0,0 +1,20 @@ +// PR c++/64717 +// { dg-do compile } +// { dg-options "-O2 -Wuninitialized -fsanitize=vptr" } + +class ios {}; + +struct stringstream : virtual ios { + stringstream (char *); + ~stringstream (); +}; + +struct string { char *c_str (); }; + +string make_str (); + +void +bar () +{ + stringstream param (make_str ().c_str ()); // { dg-bogus "is used uninitialized" } +} -- 2.30.2