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

[Runtime] Mark swift_asprintf with __attribute__((__format__)) #35525

Merged
merged 1 commit into from
Jan 22, 2021

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented Jan 20, 2021

This gives us build-time warnings about format string mistakes, like we would get if we called the built-in asprintf directly.

Wrap TypeLookupError format string creation in a macro that uses this to provide build-time warnings for its users as well.

This reveals various mistakes in format strings and arguments in the runtime, which are now fixed.

rdar://73417805

@mikeash mikeash requested a review from compnerd January 20, 2021 22:36
Node->hasText() ? (int)Node->getText().size() : 0, \
Node->hasText() ? Node->getText().data() : "", __VA_ARGS__)
TYPE_LOOKUP_ERROR_FMT( \
"TypeDecoder.h:%d: Node kind %u \"%.*s\" - " Fmt, __LINE__, \
Copy link
Member

Choose a reason for hiding this comment

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

%u for the line is probably better.

Node->hasText() ? Node->getText().data() : "", __VA_ARGS__)
TYPE_LOOKUP_ERROR_FMT( \
"TypeDecoder.h:%d: Node kind %u \"%.*s\" - " Fmt, __LINE__, \
(int)Node->getKind(), Node->hasText() ? (int)Node->getText().size() : 0, \
Copy link
Member

Choose a reason for hiding this comment

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

cast to unsigned please given that you are converting with %u.

This gives us build-time warnings about format string mistakes, like we would get if we called the built-in asprintf directly.

Make TypeLookupError's format string constructor a macro instead so that its callers can get these build-time warnings.

This reveals various mistakes in format strings and arguments in the runtime, which are now fixed.

rdar://73417805
@mikeash mikeash force-pushed the swift_asprintf-static-checking branch from 2a00f03 to 216e555 Compare January 22, 2021 15:55
@mikeash
Copy link
Contributor Author

mikeash commented Jan 22, 2021

@compnerd Thanks, fixed those.

@mikeash
Copy link
Contributor Author

mikeash commented Jan 22, 2021

@swift-ci please test and merge

@mikeash
Copy link
Contributor Author

mikeash commented Jan 22, 2021

@swift-ci please smoke test os x platform

@mikeash mikeash merged commit 4988127 into swiftlang:main Jan 22, 2021
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.

2 participants