[cfe-dev] Question about valid FileID values and assert
Richard Smith
richard at metafoo.co.uk
Thu Jul 31 17:49:25 PDT 2014
On Tue, Jul 29, 2014 at 8:07 AM, Jason Dagit <dagit at galois.com> wrote:
> Hello,
>
> 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:
> https://github.com/llvm-mirror/clang/blob/master/lib/Serialization/ASTReader.cpp#L1036
>
> I’m wondering, shouldn’t that line be:
> assert(FID > 0 && "Serialized line entries for non-local file.”);
>
Yes, I think it should.
> It looks like SLocEntryBaseID is always initialized to 0, and I can’t find
> a place that changes it.
>
It's changed here:
https://github.com/llvm-mirror/clang/blob/master/lib/Serialization/ASTReader.cpp#L2890
> if FID was 0, then `FID += F.SLocEntryBaseID - 1;` would be -1? I see
> that FileIDs can be negative, but in this case it looks like an error to me.
>
> Perhaps I missed something? Does the serialization sometimes write out
> invalid FileIDs (meaning, 0 values) for some reason?
>
The table is written out here:
https://github.com/llvm-mirror/clang/blob/master/lib/Serialization/ASTWriter.cpp#L1887
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140731/274475cb/attachment.html>
More information about the cfe-dev
mailing list