Skip to content

[ClangImporter] Handle allowing PCM/PCH errors #40273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2021

Conversation

bnbarham
Copy link
Contributor

Ignore errors when emitting/reading a PCM/PCH and Clang has
-fallow-(pcm|pch)-with-compiler-errors set.

Resolves rdar://85576570.

@bnbarham bnbarham requested review from akyrtzi and beccadax November 20, 2021 12:12
@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@bnbarham
Copy link
Contributor Author

@swift-ci please test

};

//--- use.swift
func use(s: SomeTy) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little nervous about how thin these tests are. If I understand correctly, this change will allow invalid clang ASTs to appear in many parts of the ClangImporter where they were previously impossible, but your test case only exercises the tiny fraction of the importer that is involved in importing a struct without any interesting attributes or features, and there isn't actually anything invalid in this struct itself. Any other failure would not be caught here and would presumably surface as a weird crash in ClangImporter that we'd need to triage and test later.

Can you think of a way to (a) significantly improve test coverage (maybe you could re-run existing ClangImporter tests but with a broken code added to the headers?) and (b) make sure that crash logs clearly indicate that invalid clang ASTs were allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid ASTs are already possible when -fallow-pcm-with-compiler-errors is passed in when loading PCMs (there's no check for diagnostics in that case). But I agree the test coverage isn't great here.

Regarding the crash logs, I had originally added a While allowing modules with compiler errors enabled line to the pretty stack trace a while ago, but have since removed that as it duplicates the information in the program arguments. I'm happy to put that back in if you think it'd be better to make it more obvious.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be good to add that back. The program arguments are often truncated and always difficult to visually parse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately if the program arguments are truncated then the extra line won't be output anyway (since the arguments are the first thing printed). But I can add it in to address the second part (difficult to visually parse them).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added that line back in as an extension to the existing frontend "Compiling with..."

If we think it's worth it I could also do some LLVM changes to allow printing the pretty stacktrace in reverse order. That would print arguments last rather than first (which then truncates everything). It currently reverses the stored "frames" in order to print, so should be pretty simple.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 5703e89985031a741bb288d31a4a999c745fe93a

Ignore errors when emitting/reading a PCM/PCH and Clang has
`-fallow-(pcm|pch)-with-compiler-errors` set.

Resolves rdar://85576570.
While this will be in the compiler arguments, it's easy to miss when
skimming over the pretty stacktrace. Add an explicit message to make it
easier to see while looking over crashes.
@bnbarham
Copy link
Contributor Author

bnbarham commented Dec 3, 2021

@swift-ci please test

@bnbarham
Copy link
Contributor Author

bnbarham commented Dec 3, 2021

@beccadax given the addition of the pretty stacktrace line and that invalid ASTs are already allowed for modules (this change is just for the bridging header), would you be okay with this being merged? Happy to talk more about tests, but it would be good to get this in so that allowing errors works for bridging headers as well.

@akyrtzi
Copy link
Contributor

akyrtzi commented Dec 4, 2021

Let's get this in and we can follow-up with further enhancements in a separate PR.

@akyrtzi akyrtzi merged commit 7ad553f into swiftlang:main Dec 4, 2021
@bnbarham bnbarham deleted the pch-allow-errors branch December 4, 2021 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants