Skip to content

[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

Merged
merged 1 commit into from
Nov 16, 2016

Conversation

jrose-apple
Copy link
Contributor

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.

@jrose-apple
Copy link
Contributor Author

@milseman Does this look okay?

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor Author

jrose-apple commented Nov 9, 2016

@milseman bump

@milseman
Copy link
Member

milseman commented Nov 10, 2016

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))
Copy link
Member

@milseman milseman Nov 8, 2016

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.)

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 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.
@jrose-apple jrose-apple force-pushed the static-qualified-arrays branch from 683cdd7 to 544b4e8 Compare November 16, 2016 16:54
@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit d7cc1fd into swiftlang:master Nov 16, 2016
@jrose-apple jrose-apple deleted the static-qualified-arrays branch November 16, 2016 17:14
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.

3 participants