From: Martin Sebor Date: Wed, 28 Feb 2018 18:28:53 +0000 (+0000) Subject: PR testsuite/84617 - new test cases g++.dg/ext/attr-const.C and g++.dg/ext/attr-pure... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=be583c04a448ef4e97065fd0f5b7f6c5e40e41fb;p=gcc.git PR testsuite/84617 - new test cases g++.dg/ext/attr-const.C and g++.dg/ext/attr-pure.C fail gcc/cp/ChangeLog: * decl.c (duplicate_decls): Fully merge attributes const, pure, and malloc. gcc/testsuite/ChangeLog: * g++.dg/ext/attr-malloc-3.C: New test. * g++.dg/ext/attr-const.C: Adjust. Xfail assertions failing due to pre-existing problems. * g++.dg/ext/attr-pure.C: Same. From-SVN: r258077 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e2d88dcf240..457bfc2a4c7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-02-28 Martin Sebor + + PR testsuite/84617 + * decl.c (duplicate_decls): Fully merge attributes const, pure, + and malloc. + 2018-02-28 Nathan Sidwell PR c++/84602 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 4a1267c9367..f1be2292c59 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -2234,8 +2234,11 @@ next_arg:; TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl); TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl); TREE_READONLY (newdecl) |= TREE_READONLY (olddecl); + TREE_READONLY (olddecl) |= TREE_READONLY (newdecl); DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl); + DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl); DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl); + DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl); } else { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 33387b022a2..bfdc0f18645 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2018-02-28 Martin Sebor + + PR testsuite/84617 + * g++.dg/ext/attr-malloc-3.C: New test. + * g++.dg/ext/attr-const.C: Adjust. Xfail assertions failing due + to pre-existing problems. + * g++.dg/ext/attr-pure.C: Same. + 2018-02-28 Paul Thomas PR fortran/83901 diff --git a/gcc/testsuite/g++.dg/ext/attr-const.C b/gcc/testsuite/g++.dg/ext/attr-const.C index a9884db765f..28f2c6ea4b6 100644 --- a/gcc/testsuite/g++.dg/ext/attr-const.C +++ b/gcc/testsuite/g++.dg/ext/attr-const.C @@ -1,54 +1,55 @@ /* PR c++/83871 - wrong code for attribute const and pure on distinct template specializations { dg-do compile } - { dg-options "-O -Wall" } */ + { dg-options "-O1 -Wall -fdump-tree-optimized" } */ int __attribute__ ((const)) fconst_none (); int fconst_none (); -void test_const_none_failed (); +void func_const_none_failed (); void func_const_none () { int i0 = fconst_none (); int i1 = fconst_none (); if (i0 != i1) - test_const_none_failed (); + func_const_none_failed (); - // { dg-final { scan-tree-dump-not "test_const_none_failed" "optimized" } } + // { dg-final { scan-tree-dump-not "func_const_none_failed" "optimized" } } } int fnone_const (); int __attribute__ ((const)) fnone_const (); -void test_none_const_failed (); +void func_none_const_failed (); void func_none_const () { int i0 = fnone_const (); int i1 = fnone_const (); if (i0 != i1) - test_none_const_failed (); + func_none_const_failed (); - // { dg-final { scan-tree-dump-not "test_none_const_failed" "optimized" } } + // { dg-final { scan-tree-dump-not "func_none_const_failed" "optimized" } } } - template int __attribute__ ((const)) fconst_none (T); template int fconst_none (T); +void templ_const_none_failed (); + void template_const_none () { int i0 = fconst_none (0); int i1 = fconst_none (0); if (i0 != i1) - test_const_none_failed (); + templ_const_none_failed (); - // { dg-final { scan-tree-dump-not "test_const_none_failed" "optimized" } } + // { dg-final { scan-tree-dump-not "templ_const_none_failed" "optimized" } } } @@ -58,12 +59,15 @@ int fnone_const (T); template int __attribute__ ((const)) fnone_const (T); +void templ_none_const_failed (); + void test_fnone_const () { int i0 = fnone_const (0); int i1 = fnone_const (0); if (i0 != i1) - test_none_const_failed (); + templ_none_const_failed (); - // { dg-final { scan-tree-dump-not "test_none_const_failed" "optimized" } } + // The following fails (most likely) due to bug 84294. + // { dg-final { scan-tree-dump-not "templ_none_const_failed" "optimized" { xfail *-*-* } } } } diff --git a/gcc/testsuite/g++.dg/ext/attr-malloc-3.C b/gcc/testsuite/g++.dg/ext/attr-malloc-3.C new file mode 100644 index 00000000000..e4470af7927 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-malloc-3.C @@ -0,0 +1,97 @@ +// Bug c++/84617 - new test cases g++.dg/ext/attr-const.C and +// g++.dg/ext/attr-pure.C fail +// { dg-do compile } +// { dg-options "-O -Wall -fdump-tree-optimized" } + +static char a[8]; + +void* __attribute__ ((malloc)) +func_malloc_none (unsigned); + +void* +func_alloc_none (unsigned); // redeclare with no attribute + +void func_malloc_none_failed (); + +void test_func_malloc_none (void) +{ + void *p = func_malloc_none (1); + if (!p) + return; + + if (p == a) // must be false + func_malloc_none_failed (); // should be eliminated + + // Verify that the call to func_malloc_none_failed() is eliminated. + // { dg-final { scan-tree-dump-not "func_malloc_none_failed" "optimized" } } +} + + +void* +func_none_malloc (unsigned); + +void* __attribute__ ((malloc)) +func_none_malloc (unsigned); // redeclare with an attribute + +void func_none_malloc_failed (); + +void test_func_none_malloc (void) +{ + void *p = func_none_malloc (1); + if (!p) + return; + + if (p == a) // must be false + func_none_malloc_failed (); // should be eliminated + + // Verify that the call to func_none_malloc_failed() is eliminated. + // { dg-final { scan-tree-dump-not "func_none_malloc_failed" "optimized" } } +} + + +template +void* __attribute__ ((malloc)) +templ_malloc_none (unsigned); + +template +void* +templ_malloc_none (unsigned); // redeclare with no attribute + +void templ_malloc_none_failed (); + +void test_templ_malloc_none (void) +{ + void *p = templ_malloc_none(1); + if (!p) + return; + + if (p == a) // must be false + templ_malloc_none_failed (); // should be eliminated + + // Verify that the call to templ_malloc_none_failed() is eliminated. + // { dg-final { scan-tree-dump-not "templ_malloc_none_failed" "optimized" } } +} + +template +void* +templ_none_malloc (unsigned); + +template +void* __attribute__ ((malloc)) +templ_none_malloc (unsigned); // redeclared with an attribute + +void templ_none_malloc_failed (); + +void test_templ_none_malloc (void) +{ + void *p = templ_none_malloc(1); + if (!p) + return; + + if (p == a) // must be false + templ_none_malloc_failed (); // should be eliminated + + // The following fails (most likely) due to bug 84294. + // Verify that the call to templ_none_malloc_failed() is eliminated. + // { dg-final { scan-tree-dump-not "templ_none_malloc_failed" "optimized" { xfail *-*-* } } } +} diff --git a/gcc/testsuite/g++.dg/ext/attr-pure.C b/gcc/testsuite/g++.dg/ext/attr-pure.C index af36a31d6d5..12532cb91ef 100644 --- a/gcc/testsuite/g++.dg/ext/attr-pure.C +++ b/gcc/testsuite/g++.dg/ext/attr-pure.C @@ -1,37 +1,37 @@ /* PR c++/83871 - wrong code for attribute const and pure on distinct template specializations { dg-do compile } - { dg-options "-O -Wall" } */ + { dg-options "-O -Wall -fdump-tree-optimized" } */ int __attribute__ ((pure)) fpure_none (); int fpure_none (); -void test_pure_none_failed (); +void func_pure_none_failed (); void func_pure_none () { int i0 = fpure_none (); int i1 = fpure_none (); if (i0 != i1) - test_pure_none_failed (); + func_pure_none_failed (); - // { dg-final { scan-tree-dump-not "test_pure_none_failed" "optimized" } } + // { dg-final { scan-tree-dump-not "func_pure_none_failed" "optimized" } } } int fnone_pure (); int __attribute__ ((pure)) fnone_pure (); -void test_none_pure_failed (); +void func_none_pure_failed (); void func_none_pure () { int i0 = fnone_pure (); int i1 = fnone_pure (); if (i0 != i1) - test_none_pure_failed (); + func_none_pure_failed (); - // { dg-final { scan-tree-dump-not "test_none_pure_failed" "optimized" } } + // { dg-final { scan-tree-dump-not "func_none_pure_failed" "optimized" } } } @@ -41,29 +41,34 @@ int __attribute__ ((pure)) fpure_none (T); template int fpure_none (T); +void templ_pure_none_failed (); + void template_pure_none () { int i0 = fpure_none (0); int i1 = fpure_none (0); if (i0 != i1) - test_pure_none_failed (); + templ_pure_none_failed (); - // { dg-final { scan-tree-dump-not "test_pure_none_failed" "optimized" } } + // { dg-final { scan-tree-dump-not "templ_pure_none_failed" "optimized" } } } template -int fnone_pure (T); +int fnone_const (T); template -int __attribute__ ((pure)) fnone_pure (T); +int __attribute__ ((const)) fnone_const (T); + +void templ_none_const_failed (); -void test_fnone_pure () +void test_fnone_const () { - int i0 = fnone_pure (0); - int i1 = fnone_pure (0); + int i0 = fnone_const (0); + int i1 = fnone_const (0); if (i0 != i1) - test_none_pure_failed (); + templ_none_const_failed (); - // { dg-final { scan-tree-dump-not "test_none_pure_failed" "optimized" } } + // The following fails (most likely) due to bug 84294. + // { dg-final { scan-tree-dump-not "templ_none_const_failed" "optimized" { xfail *-*-* } } } }