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

[C++ Safe Buffers][BoundsSafety] Fix that some interop diagnostics cannot be suppressed by unsafe_buffer_usage_begin/end #10198

Merged
merged 2 commits into from
Mar 7, 2025

Conversation

ziqingluo-90
Copy link

The interop diagnostics emitted in Sema cannot be suppressed by #pragma clang unsafe_buffer_usage begin/end. This is because the opt-out regions marked by those pragmas are stored in Preprocessor not DiagnosticsEngine. We need query both the Preprocessor and DiagnosticsEngine to confirm if C++ Safe Buffers is enabled at a location. This commit fixes this problem.

(rdar://146438364)

…nnot be suppressed by __unsafe_buffer_usage_begin/end

The interop diagnostics emitted in Sema cannot be suppressed by
`#pragma clang unsafe_buffer_usage begin/end`.  This is because the
opt-out regions marked by those pragmas are stored in Preprocessor not
DiagnosticsEngine.  We need query both the Preprocessor and
DiagnosticsEngine to confirm if C++ Safe Buffers is enabled at a
location.  This commit fixes this problem.

(rdar://146438364)
@ziqingluo-90
Copy link
Author

CC @dtarditi

@ziqingluo-90
Copy link
Author

@swift-ci test

@ziqingluo-90 ziqingluo-90 merged commit 0e05226 into swiftlang:next Mar 7, 2025
@ziqingluo-90 ziqingluo-90 deleted the eng/PR-146438364 branch March 7, 2025 04:22
Loc.isInvalid() || !getPreprocessor().isSafeBufferOptOut(SourceMgr, Loc);
return LangOpts.CPlusPlus && LangOpts.isBoundsSafetyAttributeOnlyMode() &&
NotSupressedByPragmas &&
!Diags.isIgnored(diag::warn_unsafe_buffer_operation, Loc);
Copy link

Choose a reason for hiding this comment

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

Why do we need to check whether the diagnostic is ignored? If it's ignored it wouldn't be emitted anyways, right?

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