-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/ClangImporter/AllowErrors/invalid-pch-bridging-header.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// REQUIRES: objc_interop | ||
|
||
// RUN: %empty-directory(%t) | ||
// RUN: mkdir -p %t/pch %t/pch-dir | ||
// RUN: split-file %s %t | ||
|
||
// Check that the pch is output even though it has errors | ||
// RUN: %target-swift-frontend -emit-pch -o %t/pch/bridging-header.pch -Xcc -Xclang -Xcc -fallow-pcm-with-compiler-errors -Xcc -Xclang -Xcc -fmodule-format=raw %t/bridging-header.h | ||
// RUN: %target-swift-frontend -typecheck -verify -import-objc-header %t/pch/bridging-header.pch -Xcc -Xclang -Xcc -fallow-pcm-with-compiler-errors -Xcc -Xclang -Xcc -fmodule-format=raw %t/use.swift | ||
// RUN: ls %t/pch/*.pch | count 1 | ||
|
||
// Same but with implicit PCH instead | ||
// RUN: %target-swift-frontend -typecheck -verify -import-objc-header %t/bridging-header.h -pch-output-dir %t/pch-dir -Xcc -Xclang -Xcc -fallow-pcm-with-compiler-errors -Xcc -Xclang -Xcc -fmodule-format=raw %t/use.swift | ||
// RUN: ls %t/pch-dir/*.pch | count 1 | ||
|
||
// Second implicit run since we may go down a different path if the PCH already | ||
// exists | ||
// RUN: %target-swift-frontend -typecheck -verify -import-objc-header %t/bridging-header.h -pch-output-dir %t/pch-dir -Xcc -Xclang -Xcc -fallow-pcm-with-compiler-errors -Xcc -Xclang -Xcc -fmodule-format=raw %t/use.swift | ||
// RUN: ls %t/pch-dir/*.pch | count 1 | ||
|
||
//--- bridging-header.h | ||
@import DoesNotExist; | ||
|
||
struct SomeTy { | ||
int a; | ||
}; | ||
|
||
//--- use.swift | ||
func use(s: SomeTy) {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: split-file %s %t | ||
|
||
// RUN: %target-swift-emit-pcm -module-name m -o %t/m.pcm -Xcc -Xclang -Xcc -fallow-pcm-with-compiler-errors -Xcc -Xclang -Xcc -fmodule-format=raw %t/mods/module.map | ||
// RUN: %target-swift-frontend -typecheck -verify -Xcc -Xclang -Xcc -fallow-pcm-with-compiler-errors -Xcc -fmodule-file=%t/m.pcm %t/use.swift | ||
|
||
//--- mods/module.map | ||
module m { | ||
header "m.h" | ||
} | ||
|
||
//--- mods/m.h | ||
@import DoesNotExist; | ||
|
||
struct SomeTy { | ||
int a; | ||
}; | ||
|
||
//--- use.swift | ||
import m | ||
func use(s: SomeTy) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.