-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ClangImporter] C static-qualified array params are non-nullable. #5617
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
[ClangImporter] C static-qualified array params are non-nullable. #5617
Conversation
@milseman bump |
I left a code review question @jrose-apple edit: Oh crap! It didn't save! My bad |
return translateNullability(*nullability); | ||
} | ||
|
||
// If it's known non-null, use that. | ||
if (knownNonNull || param->hasAttr<clang::NonNullAttr>()) | ||
return OTK_None; | ||
|
||
// Check for the 'static' annotation on C arrays. | ||
if (!swiftVersion.isVersion3()) | ||
if (const auto *DT = dyn_cast<clang::DecayedType>(paramTy)) |
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.
Is the intent here for 4 and later, or this a problem only in swift 3?
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.
"4 and later". I'm honestly not sure what our idiom should be here (why do we have a particular accessor at all?). @graydon?
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.
Just a convenience accessor, I figured people sprinkling explicit version comparisons in their code would be worse.
(nb: there's no support for setting --swift-version earlier than 3 so "not 3" means >= 3 in this case, but probably a more explicit convenience accessor would be better.)
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 guess in the C world you don't say "C > 99" or something. It's only because we have sequential version numbers that we even have this option.
In Clang we check for the new version of the language (if (LangOpts.C99)
, if (LangOpts.CXX14)
), but those checks are designed to stay around. Checking isVersion3
feels like a reminder that the check will go away if/when we drop support for Swift 3 mode.
If the keyword 'static' also appears within the '[' and ']' of the array type derivation, then for each call to the function, the value of the corresponding actual argument shall provide access to the first element of an array with at least as many elements as specified by the size expression. (C11 6.7.6.3p7) Limit this change to Swift 4 so as not to break existing code, though use of 'static' in this way is rare to begin with and passing nil would probably be an error anyway. Small part of rdar://problem/25846421.
683cdd7
to
544b4e8
Compare
@swift-ci Please smoke test |
Limit this change to Swift 4 so as not to break existing code, though use of
static
in this way is rare to begin with and passing nil would probably be an error anyway.Small part of rdar://problem/25846421.