<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 29, 2014 at 8:07 AM, Jason Dagit <span dir="ltr"><<a href="mailto:dagit@galois.com" target="_blank">dagit@galois.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">Hello,<div><br></div><div>
I’m very new to the clang source and I’m trying to understand how AST serialization works. As far as I can tell valid FileIDs can be positive or negative but not 0. Yet I see the following in ASTReader: <a href="https://github.com/llvm-mirror/clang/blob/master/lib/Serialization/ASTReader.cpp#L1036" target="_blank">https://github.com/llvm-mirror/clang/blob/master/lib/Serialization/ASTReader.cpp#L1036</a></div>
<div><br></div><div>I’m wondering, shouldn’t that line be:</div><div><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap">assert</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap">(</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap">FID</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,204)"> </span><span style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap">></span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,204)"> </span><span style="color:rgb(0,153,153);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap">0</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,204)"> </span><span style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap">&&</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,204)"> </span><span style="color:rgb(221,17,68);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap">"Serialized line entries for non-local file.”</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;line-height:18px;white-space:pre-wrap">);</span></div>
</div></blockquote><div><br></div><div>Yes, I think it should.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><span style="line-height:18px;white-space:pre-wrap">It looks like SLocEntryBaseID is always initialized to 0, and I can’t find a place that changes it.</span></div></div></blockquote>
<div><br></div><div>It's changed here:</div><div><br></div><div><a href="https://github.com/llvm-mirror/clang/blob/master/lib/Serialization/ASTReader.cpp#L2890">https://github.com/llvm-mirror/clang/blob/master/lib/Serialization/ASTReader.cpp#L2890</a><br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span style="line-height:18px;white-space:pre-wrap">if FID was 0, then `</span><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)">FID</span><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)"> </span><span style="font-weight:bold;line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)">+=</span><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)"> </span><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)">F</span><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)">.</span><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)">SLocEntryBaseID</span><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)"> </span><span style="font-weight:bold;line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)">-</span><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)"> </span><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)">1</span><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)">;` would be -1? I see that FileIDs can be negative, but in this case it looks like an error to me.</span></div>
<div><span style="line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)"><br></span></div><div><span style="line-height:18px;white-space:pre-wrap">Perhaps I missed something? Does the serialization sometimes write out invalid FileIDs (meaning, 0 values) for some reason?</span></div>
</div></blockquote><div><br></div><div>The table is written out here:</div><div><br></div><div><a href="https://github.com/llvm-mirror/clang/blob/master/lib/Serialization/ASTWriter.cpp#L1887">https://github.com/llvm-mirror/clang/blob/master/lib/Serialization/ASTWriter.cpp#L1887</a><br>
</div><div><br></div><div>I would not expect this table to contain any entries for the invalid FileID 0. You get some basic confidence in this (or a counterexample) by changing the assert and seeing if any tests fail.</div>
</div></div></div>