Crash in Sema + PATCH

Richard Smith richard at metafoo.co.uk
Wed Mar 25 21:18:22 PDT 2015


On Tue, Feb 24, 2015 at 5:38 PM, Davide Italiano <davide.italiano at gmail.com>
wrote:

> Hi Richard.
>
> Building the following testcase
>  % cat blah.cpp
> struct {
>   struct A <struct A {
>
> results in a crash in Sema, namely:
>
> % clang blah.cpp -o blah
> [...]
> Invalid access specifier!
> UNREACHABLE executed at
>
> /usr/src/lib/clang/libclangast/../../../contrib/llvm/tools/clang/lib/AST/DeclCXX.cpp:2145!
>
> I would like to propose the following patch to fix that up.
> Rather than crashing, if we don't have informations about the previous
> declaration access specifier, we can just throw an error.
>
> diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp
> index 37240c2..7433c8c 100644
> --- a/lib/Sema/SemaAccess.cpp
> +++ b/lib/Sema/SemaAccess.cpp
> @@ -45,6 +45,11 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl
> *MemberDecl,
>      return false;
>    }
>
> +  // If a previous member declaration exists, and the access specifier
> +  // is not valid, just error out.
> +  if (PrevMemberDecl->getAccess() == AS_none)
>

(As discussed on IRC) Please assert that the previous declaration is marked
invalid here, and mark the new member declaration as invalid in this case.

+    return true;
> +
>    // C++ [class.access.spec]p3: When a member is redeclared its access
>    // specifier must be same as its initial declaration.
>    if (LexicalAS != AS_none && LexicalAS != PrevMemberDecl->getAccess()) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150325/0a17aeb7/attachment.html>


More information about the cfe-commits mailing list