Skip to content
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

[SR-9373] Clang importer should refuse to import arrays with excessive numbers of elements #51839

Closed
belkadan opened this issue Nov 29, 2018 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers

Comments

@belkadan
Copy link
Contributor

Previous ID SR-9373
Radar rdar://problem/46325364
Original Reporter @belkadan
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, ClangImporter, StarterBug
Assignee @dnadoba
Priority Medium

md5: ceda7a47d94b61660b417b8d9c1437e5

Issue Description:

The Swift importer will blindly try to create an N-element tuple for C arrays of size N. This quickly becomes ridiculous even for fairly small arrays like 16 or 32. It becomes downright pathological from a visual standpoint as the array goes past 128 or so, and at arrays past 1024 starts exhibiting semi-exponential behavior in time; generating the Swift interface for a header containing a 65536-element array takes almost 5 full minutes on a MBP. The importer should refuse to handle such large arrays.

Steps To Reproduce:

  1. Create an Objective-C project.
  2. In any header, declare a huge array; for example, “static char myLudicrousArray[65536];”
  3. Attempt to view the generated Swift interface for the header, or import the header in a Swift bridging header and try to build any Swift code.

Results:
The interface takes quite a long time to generate.

Regression:
This has always been the case for as far back as the “generate N-element tuples for N-element arrays” logic has existed.

Notes:
Arrays of such excessive size are not necessarily common, but they do appear in practice. Pending a better way to import C arrays in general, especially large ones, Swift should better own its inability to handle them effectively.

@belkadan
Copy link
Contributor Author

I'm worried about breaking arrays of size PATH_MAX (not that PATH_MAX is a good idea), and the largest number I know of for PATH_MAX is 4096. For now, let's set this limit at 4097, even though that still allows some ridiculous behavior. The place to do this check is VisitConstantArrayType in ImportType.cpp.

@dnadoba
Copy link
Member

dnadoba commented May 13, 2019

#20912

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants