This is an archive of the discontinued LLVM Phabricator instance.

[Modules] Do not remove failed modules after the control block phase
ClosedPublic

Authored by bnbarham on Aug 6 2021, 11:40 PM.

Details

Summary

Reading modules first reads each control block in the chain and then all
AST blocks.

The first phase is intended to find recoverable errors, eg. an out of
date or missing module. If any error occurs during this phase, it is
safe to remove all modules in the chain as no references to them will
exist.

While reading the AST blocks, however, various fields in ASTReader are
updated with references to the module. Removing modules at this point
can cause dangling pointers which can be accessed later. These would be
otherwise harmless, eg. a binary search over GlobalSLocEntryMap may
access a failed module that could error, but shouldn't crash. Do not
remove modules in this phase, regardless of failures.

Since this is the case, it also doesn't make sense to return OutOfDate
during this phase, so remove the two cases where this happens.

When they were originally added these checks would return a failure when
the serialized and current path didn't match up. That was updated to an
OutOfDate as it was found to be hit when using VFS and overriding the
umbrella. Later on the path was changed to instead be the name as
written in the module file, resolved using the serialized base
directory. At this point the check is really only comparing the name of
the umbrella and only works for frameworks since those don't include
Headers/ in the name (which means the resolved path will never exist)

Given all that, it seems safe to ignore this case entirely for now.
This makes the handling of an umbrella header/directory the same as
regular headers, which also don't check for differences in the path
caused by VFS.

Resolves rdar://79329355

Diff Detail

Event Timeline

bnbarham created this revision.Aug 6 2021, 11:40 PM
bnbarham requested review of this revision.Aug 6 2021, 11:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2021, 11:40 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
bnbarham added a comment.EditedAug 6 2021, 11:42 PM

I have another change to update the post-control-block functions to llvm::Error instead to hopefully make the distinction more clear as well. Let me know if you think it belongs in this PR, otherwise I'll open another once this one is in.

Made the first review pass and return Failure makes sense to me as recovery isn't the best idea at this point. Still want to check more thoroughly if the removed code for SUBMODULE_UMBRELLA_HEADER and SUBMODULE_UMBRELLA_DIR has any load-bearing side-effects.

Have no opinion on updating post-control-block functions to llvm::Error.

clang/test/VFS/module-header-mismatches.m
3

Didn't know about split-file, that's nice.

clang/test/VFS/umbrella-mismatch.m
4

Are you deleting this test case because it is subsumed by module-header-mismatches.m?

Also if it makes sense to delete this test, need to do more cleanup because UsesFoo.framework and Foo.framework seem to be used only from this test. Though I'm not 100% sure.

vsapsai added a subscriber: Restricted Project.Aug 10 2021, 12:49 PM
bnbarham added inline comments.Aug 10 2021, 3:26 PM
clang/test/VFS/umbrella-mismatch.m
4

Yep, the check in this one is the same as the header-frameworks.

Foo.framework is used by subframework-symlink.m. But UsesFoo.framework isn't used by anything else, thanks.

bnbarham updated this revision to Diff 365619.Aug 10 2021, 3:31 PM

Removed the now unused UsesFoo.framework in the tests

Why are you not just changing return OutOfDate to return Failure for SUBMODULE_UMBRELLA_HEADER and SUBMODULE_UMBRELLA_DIR? I have no strong opinion on this but it feels more in line with the rest of the changes. Also I've tried to do that and nothing seems to be broken.

And for the rest of the code for these records I think it is worth keeping ModMap.setUmbrellaHeader and ModMap.setUmbrellaDir with preceding preparation and checks. The code in ModuleMap seems to be complicated enough and stateful, so removing those setters can break some stuff. It is possible everything will be fine but I don't want to chance that unless required.

bnbarham updated this revision to Diff 366152.Aug 12 2021, 5:17 PM
bnbarham marked an inline comment as done.
bnbarham edited the summary of this revision. (Show Details)

Changed to keep setting the umbrella header/directory with a FIXME that it currently doesn't work for framework modules.

vsapsai accepted this revision.Aug 12 2021, 5:23 PM

Looks good to me. The only nitpicky thing is I don't remember if the code style requires braces around multi-line case blocks or not.

This revision is now accepted and ready to land.Aug 12 2021, 5:23 PM
bnbarham updated this revision to Diff 366154.Aug 12 2021, 5:28 PM

Forgot to add the braces back in for the case statements

bnbarham updated this revision to Diff 366378.Aug 13 2021, 4:52 PM
yaron.keren added inline comments.
clang/lib/Serialization/ASTReader.cpp
4268

Result is unused now.

4279

Same here.

vsapsai added inline comments.Aug 19 2021, 10:27 AM
clang/lib/Serialization/ASTReader.cpp
4268

Thanks for pointing it out. Are there any bots failing because of that now? Asking if should have a small urgent fix or if can wait for https://reviews.llvm.org/D108268 to land.

yaron.keren added inline comments.Aug 19 2021, 10:31 AM
clang/lib/Serialization/ASTReader.cpp
4268

Just a compiler warning, could wait.

clang/lib/Serialization/ASTReader.cpp