8000 [ClangImporter] Look through __ended_by and __null_terminated by hnrklssn · Pull Request #81630 · swiftlang/swift · GitHub
[go: up one dir, main page]

Skip to content

[ClangImporter] Look through __ended_by and __null_terminated #81630

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 6 commits into from
May 31, 2025

Conversation

hnrklssn
Copy link
Contributor

Previously we would not import decls containing these types. This was not an issue, because they can only occur when -fbounds-safety or -fexperimental-bounds-safety-attributes is passed to clang. When SafeInteropWrappers is enabled we pass
-fexperimental-bound-safety-attributes to clang however, so these types can now occur without the user specifying any -Xcc flags.

rdar://151611718

@hnrklssn
8000 Copy link
Contributor Author

@swift-ci please smoke test

1 similar comment
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn hnrklssn force-pushed the ignore-unused-bounds-attributes branch from 2c488a2 to 1090ee0 Compare May 20, 2025 20:52
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test macos

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor
@j-hui j-hui left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the really thorough testing! Left some nits, mostly about documentation and formatting.

#endif

#if !__cplusplus
void p(int len, int p[len]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this isn't allowed in C++? (And can you add a comment with your explanation?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VLAs are a C only feature

char * __single j(char *__single p);
void *__single k(void *__single p);

#if __has_ptrcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are only __indexable and __bidi_indexable guarded with __has_ptrcheck?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other macros defined in ptrcheck.h are defined to nothing when -fbounds-safety is not enabled, these two are intentionally left undefined since they can affect ABI, so you don't want one TU thinking they are normal pointers and one TU expanding them to wide pointers

@@ -0,0 +1,48 @@
#pragma once

#include <ptrcheck.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this header file guaranteed to be on every platform we deploy to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah probably not, no

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or actually, maybe? We ship it with clang, and we ship clang with swift. So I think it ought to be there

hnrklssn added 3 commits May 21, 2025 18:23
Previously we would not import decls containing these types. This was
not an issue, because they can only occur when -fbounds-safety or
-fexperimental-bounds-safety-attributes is passed to clang. When
SafeInteropWrappers is enabled we pass
-fexperimental-bound-safety-attributes to clang however, so these types
can now occur without the user specifying any -Xcc flags.

rdar://151611718
@hnrklssn hnrklssn force-pushed the ignore-unused-bounds-attributes branch from 1090ee0 to 51eb212 Compare May 22, 2025 01:55
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test windows

Copy link
Contributor
@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

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

LGTM!

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test windows

2 similar comments
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test windows

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test windows

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test


func access() {
#if VERIFY
let _ = a // expected-error{{cannot reference invalid declaration 'a'}} rdar://151665752
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@egorzhdan Do you have any idea why this wouldn't error on Windows?

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn hnrklssn enabled auto-merge (squash) May 30, 2025 05:16
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn hnrklssn merged commit ac068c2 into swiftlang:main May 31, 2025
3 checks passed
hnrklssn added a commit to hnrklssn/swift that referenced this pull request Jun 4, 2025
…ang#81630)

Previously we would not import decls containing these types. This was
not an issue, because they can only occur when -fbounds-safety or
-fexperimental-bounds-safety-attributes is passed to clang. When
SafeInteropWrappers is enabled we pass
-fexperimental-bound-safety-attributes to clang however, so these types
can now occur without the user specifying any -Xcc flags.

rdar://151611718
(cherry picked from commit ac068c2)
hnrklssn added a commit that referenced this pull request Jun 6, 2025
…es-6.2

[ClangImporter] Look through __ended_by and __null_terminated (#81630)
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
0