[cfe-dev] ASTImporter triggers assertions in some cases.

Gaetano Checinski via cfe-dev cfe-dev at lists.llvm.org
Wed Jan 18 08:05:29 PST 2017


The following test fails on my machine:

> // svn: E155007
> // unittests/AST/ASTImporterTest.cpp
> TEST(ImportExpr, ImportIOstream) {
>  MatchVerifier<Decl> Verifier;
>  EXPECT_TRUE(testImport(
>  "#include<iostream> \n"
>  "inline namespace D {\n"
>  "  template<class>\n"
>  "  struct declToImport {};\n"
>  "}\n", Lang_CXX, "", Lang_CXX, Verifier, decl()));
> }

It seems that the astImporter is not completely deterministic.
In anycase, I encounter one of two errors:
1) If it calls `TagDecl::setTypedefDeclForAnonDecl` it fails as
`assert(T->isLinkageValid());`
is false
2) If it parses a FriendDecl it gets stuck in an infinite loop :

Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) {
/*......*/
 │3437      while (ImportedFriend) {
 │3438        if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) {
                            // ^^^ evaluates to false
 │3439          if (Context.IsStructurallyEquivalent(D->getFriendDecl(),
 │3440
ImportedFriend->getFriendDecl()))
 │3441            return Importer.Imported(D, ImportedFriend);
 │3442
 │3443        } else if (D->getFriendType() &&
ImportedFriend->getFriendType()) {
 │3444          if (Importer.IsStructurallyEquivalent(
                                    // ^^^ always false
 │3445                D->getFriendType()->getType(),
 │3446                ImportedFriend->getFriendType()->getType(), true))
 │3447            return Importer.Imported(D, ImportedFriend);
 │3448        }
 │3449        ImportedFriend = ImportedFriend->getNextFriend();
                      //  ^^^ returns always the same frienddecl;
                      //   why does a Frienddecl has itself as a friend ?
 │3450      }

Does anybody have an idea what's going on?




2017-01-09 13:49 GMT+00:00 Gaetano Checinski <gaetano.checinski at gmail.com>:

> Hi Guys,
> I've noticed that the ASTImporter fails to import some named decls from
> <iostream> due to an invalid linkagecache (in TagDecl::
> setTypedefNameForAnonDecl()).
> Running with assertions disabled never terminates.
> However, while trying to build an minimal reproducible example, i stumbled
> on a different error regarding templated structs with frienddecls.
> I think they may be related because i found this commit:
> https://public.cdl.uni-saarland.de/noise/clang/commit/
> ad0e27b18b0cefab049121d4bfd7b12216e7de6e
> <https://mailtrack.io/trace/link/3bfa5f729eac3d7d441cda522b04d9aa06778eec?url=https%3A%2F%2Fpublic.cdl.uni-saarland.de%2Fnoise%2Fclang%2Fcommit%2Fad0e27b18b0cefab049121d4bfd7b12216e7de6e&signature=1e3968956e628307>
>
>
> The following test fails:
>
> > // svn: E155007
> > // unittests/AST/ASTImporterTest.cpp
> > TEST(ImportExpr, TemplatedStructFriend) {
> >  MatchVerifier<Decl> Verifier;
> >  EXPECT_TRUE(testImport(
> >  "void foo() {}; \n"
> >  "inline namespace D {\n"
> >  "  template<class>\n"
> >  "  struct declToImport {\n"
> >  "    friend bool f(const declToImport &);\n"
> >  "  };\n"
> >  "  template class declToImport<int>;\n"
> >  "}\n", Lang_CXX, "", Lang_CXX, Verifier, decl()));
> > }
>
> stacktrace:
> > clang/llvm/tools/clang/lib/AST/DeclFriend.cpp, line 43.
> > 0  ASTTests                 0x0000000104f8e135 l
> > lvm::sys::PrintStackTrace(llvm::raw_ostream&) + 101
> > 1  ASTTests                 0x0000000104f8e779
> PrintStackTraceSignalHandler(void*) + 25
> > 2  ASTTests                 0x0000000104f8a6d9
> llvm::sys::RunSignalHandlers() + 425
> > 3  ASTTests                 0x0000000104f8ec92 SignalHandler(int) + 354
> > 4  libsystem_platform.dylib 0x00007fff9e3eebba _sigtramp + 26
>
> Thanks in advance,
> Gaetano Checinski
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170118/5666dfeb/attachment.html>


More information about the cfe-dev mailing list