Question about valid FileID values and assert

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.”);

It looks like SLocEntryBaseID is always initialized to 0, and I can’t find a place that changes it. 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?

Thanks,
Jason

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.