This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH to fix segv with [[noreturn]] (PR c++/79967)
- From: Jason Merrill <jason at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 10 Mar 2017 10:19:47 -0500
- Subject: Re: C++ PATCH to fix segv with [[noreturn]] (PR c++/79967)
- Authentication-results: sourceware.org; auth=none
- References: <20170310114811.GK3172@redhat.com>
OK.
On Fri, Mar 10, 2017 at 6:48 AM, Marek Polacek <polacek@redhat.com> wrote:
> Not sure of the validity of the test, but clang accepts it and so do we,
> with this patch. We shouldn't attempt to dereference a pointer that
> could be NULL without checking it first.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2017-03-10 Marek Polacek <polacek@redhat.com>
>
> PR c++/79967
> * decl.c (grokdeclarator): Check ATTRLIST before dereferencing it.
>
> * g++.dg/cpp0x/gen-attrs-63.C: New test.
>
> diff --git gcc/cp/decl.c gcc/cp/decl.c
> index 3e7316f..b51ef8a 100644
> --- gcc/cp/decl.c
> +++ gcc/cp/decl.c
> @@ -11402,7 +11402,8 @@ grokdeclarator (const cp_declarator *declarator,
>
> if (declarator
> && declarator->kind == cdk_id
> - && declarator->std_attributes)
> + && declarator->std_attributes
> + && attrlist != NULL)
> /* [dcl.meaning]/1: The optional attribute-specifier-seq following
> a declarator-id appertains to the entity that is declared. */
> *attrlist = chainon (*attrlist, declarator->std_attributes);
> diff --git gcc/testsuite/g++.dg/cpp0x/gen-attrs-63.C gcc/testsuite/g++.dg/cpp0x/gen-attrs-63.C
> index e69de29..05f53e3 100644
> --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-63.C
> +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-63.C
> @@ -0,0 +1,12 @@
> +// PR c++/79967
> +// { dg-do compile { target c++11 } }
> +
> +template <void f [[noreturn]]()>
> +struct A
> +{
> + int g () { f (); return 0; }
> +};
> +
> +void f ();
> +
> +void g (A<f> a) { a.g (); }
>
> Marek