$ cat test.c<br>void foo() {<br>  int i;<br>}<br><br>$ clang -serialize test.c<br><br>$ clang -emit-llvm test.c.ast<br>clang: CGDecl.cpp:41: void clang::CodeGen::CodeGenFunction::EmitDecl(const clang::Decl&): Assertion `0 && "Should not see file-scope variables inside a function!"' failed.<br>
clang[0x84f5f2a]<br>clang[0x84f605c]<br>[0x110420]<br>/lib/libc.so.6(abort+0x101)[0x578f91]<br>/lib/libc.so.6(__assert_fail+0xee)[0x57093e]<br>clang(_ZN5clang7CodeGen15CodeGenFunction8EmitDeclERKNS_4DeclE+0xc8)[0x82ca9d2]<br>
clang(_ZN5clang7CodeGen15CodeGenFunction12EmitDeclStmtERKNS_8DeclStmtE+0x28)[0x82df094]<br>clang(_ZN5clang7CodeGen15CodeGenFunction8EmitStmtEPKNS_4StmtE+0x274)[0x82df86e]<br>clang(_ZN5clang7CodeGen15CodeGenFunction16EmitCompoundStmtERKNS_12CompoundStmtEbPN4llvm5ValueEb+0x98)[0x82e0c86]<br>
clang(_ZN5clang7CodeGen15CodeGenFunction8EmitStmtEPKNS_4StmtE+0x179)[0x82df773]<br>clang(_ZN5clang7CodeGen15CodeGenFunction12GenerateCodeEPKNS_12FunctionDeclE+0x56b)[0x82c7963]<br>clang(_ZN5clang7CodeGen13CodeGenModule12EmitFunctionEPKNS_12FunctionDeclE+0x120)[0x82aff9e]<br>
clang[0x82ad772]<br>clang[0x829efc8]<br>clang(main+0x3c8)[0x82a2206]<br>/lib/libc.so.6(__libc_start_main+0xe0)[0x564390]<br>clang[0x82783a1]<br>Aborted<br><br>The assertion fails because the DeclContext * field of i becomes 0x0 after deserialization. <br>
<br>I am investigating the problem. What is the difference between InRec and OutRec methods in serialization?<br><br>Thanks.<br>--Zhongxing Xu<br>