pch generation of C++ header failure...

Hi,

   should pch generation for a simple C++ class already work in clang (trunk of today)?

I try:

clang -x c++-header myclass.h

which gives an assert error:

Assertion failed: (Writer.Code != pch::STMT_NULL_PTR && "Unhandled expression writing PCH file"), function WriteSubStmt, file /Users/rdm/llvm/src/tools/clang/lib/Frontend/PCHWriterStmt.cpp, line 834.
0 clang-cc 0x0000000100ccfee7 PrintStackTrace(void*) + 38
1 clang-cc 0x0000000100cd0475 SignalHandler(int) + 336
2 libSystem.B.dylib 0x00007fff882480aa _sigtramp + 26
3 libSystem.B.dylib 0x00007fff881ecb2a tiny_malloc_from_free_list + 1196
4 libSystem.B.dylib 0x00007fff882c40b4 __pthread_markcancel + 0
5 clang-cc 0x00000001000b590c clang::PCHWriter::WriteSubStmt(clang::Stmt*) + 232
6 clang-cc 0x00000001000b7318 (anonymous namespace)::PCHStmtWriter::VisitMemberExpr(clang::MemberExpr*) + 54
7 clang-cc 0x00000001000b50f2 clang::StmtVisitor<(anonymous namespace)::PCHStmtWriter, void>::Visit(clang::Stmt*) + 2742
8 clang-cc 0x00000001000b58d9 clang::PCHWriter::WriteSubStmt(clang::Stmt*) + 181
9 clang-cc 0x00000001000b6b4a (anonymous namespace)::PCHStmtWriter::VisitBinaryOperator(clang::BinaryOperator*) + 54
10 clang-cc 0x00000001000b6e57 clang::StmtVisitor<(anonymous namespace)::PCHStmtWriter, void>::VisitBinAssign(clang::BinaryOperator*) + 29
11 clang-cc 0x00000001000b48f7 clang::StmtVisitor<(anonymous namespace)::PCHStmtWriter, void>::Visit(clang::Stmt*) + 699
12 clang-cc 0x00000001000b58d9 clang::PCHWriter::WriteSubStmt(clang::Stmt*) + 181
13 clang-cc 0x00000001000b82b0 (anonymous namespace)::PCHStmtWriter::VisitCompoundStmt(clang::CompoundStmt*) + 112
14 clang-cc 0x00000001000b4dd4 clang::StmtVisitor<(anonymous namespace)::PCHStmtWriter, void>::Visit(clang::Stmt*) + 1944
15 clang-cc 0x00000001000b56f3 clang::PCHWriter::FlushStmts() + 253
16 clang-cc 0x00000001000b2c86 clang::PCHWriter::WriteDeclsBlock(clang::ASTContext&) + 846
17 clang-cc 0x00000001000a48cb clang::PCHWriter::WritePCH(clang::Sema&, clang::MemorizeStatCalls*, char const*) + 1701
18 clang-cc 0x0000000100055bee (anonymous namespace)::PCHGenerator::HandleTranslationUnit(clang::ASTContext&) + 256
19 clang-cc 0x00000001002847e0 clang::ParseAST(clang::Preprocessor&, clang::ASTConsumer*, clang::ASTContext&, bool, bool, clang::CodeCompleteConsumer* (*)(clang::Sema&, void*), void*) + 760
20 clang-cc 0x000000010002ba21 ProcessInputFile(clang::Preprocessor&, clang::PreprocessorFactory&, std::string const&, ProgActions, llvm::StringMap<bool, llvm::MallocAllocator> const&, llvm::LLVMContext&) + 3664
21 clang-cc 0x000000010002d137 main + 3269
22 clang-cc 0x00000001000270dc start + 52
23 clang-cc 0x0000000000000016 start + 4294807406
Stack dump:
0. Program arguments: /Users/rdm/llvm/inst/bin/../libexec/clang-cc -triple x86_64-apple-darwin10 -emit-pch -disable-free -main-file-name myclass.h --relocation-model pic -pic-level=1 --disable-fp-elim --unwind-tables=1 --mcpu=core2 --fmath-errno=0 -mmacosx-version-min=10.6 -fexceptions -fdiagnostics-show-option -o myclass.h.gch -x c++-header myclass.h
1. <eof> parser at end of file
clang: error: precompiler command failed due to signal 6 (use -v to see invocation)

For the attached trivial myclass.h.

Cheers, Fons.

myclass.h (118 Bytes)

To follow up. The assert seems to be due to any content in an inline function body. This works fine:

class myclass {
    int fInt;
    double fD;
public:
    myclass() : fInt(10), fD(1.1) { }
    virtual ~myclass() { }
};

and this does not work:

class myclass {
    int fInt;
    double fD;
public:
    myclass() { fInt = 10; fD = 1.1; }
    virtual ~myclass() { }
};

Is this expected? During the dev-meeting it was reported that 80% of the Qt4 headers could already be parsed. What statement was used to do that? Something like:

clang-cc -x=c++-header -fsyntax-only myclass.h ?

Cheers, Fons.

Fons Rademakers wrote:

No. PCH is only implemented for C and Objective-C so far.

  - Doug

Hi Doug,

  thanks for the prompt answers. Really helps us going... Axel will be working on querying the AST so I hope he will be able to help plug a lot of holes (soon).

Concerning the partial template specialization issue any known ETA? Due to this assertion there are about 70 of the 1250 headers that fail. Very encouraging.

Cheers, Fons.

Douglas Gregor wrote:

thanks for the prompt answers. Really helps us going... Axel will be working on querying the AST so I hope he will be able to help plug a lot of holes (soon).

Okay!

Concerning the partial template specialization issue any known ETA? Due to this assertion there are about 70 of the 1250 headers that fail. Very encouraging.

A week, maybe? It's queued behind a few other features and fixes in the template system.

  - Doug