-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Builtin functions should ignore return type nullability… #74494
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
hyp
merged 3 commits into
swiftlang:main
from
hyp:eng/android-memcpy-nonnull-me-timbers
Jun 26, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <stddef.h> | ||
|
||
#define __attribute_pure__ __attribute__((__pure__)) | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
#define TEST_CONST_RETURN const | ||
#else | ||
#define TEST_CONST_RETURN | ||
#endif | ||
|
||
|
||
void* _Nonnull memcpy(void* _Nonnull, const void* _Nonnull, size_t); | ||
|
||
void* _Nonnull memcpy42(void* _Nonnull, const void* _Nonnull, size_t); | ||
|
||
void TEST_CONST_RETURN* _Nullable memchr(const void* _Nonnull __s, int __ch, size_t __n) __attribute_pure__; | ||
|
||
void* _Nonnull memmove(void* _Nonnull __dst, const void* _Nonnull __src, size_t __n); | ||
|
||
void* _Nonnull memset(void* _Nonnull __dst, int __ch, size_t __n); | ||
|
||
char TEST_CONST_RETURN* strrchr(const char* __s, int __ch) __attribute_pure__; | ||
|
||
char* _Nonnull strcpy(char* _Nonnull __dst, const char* _Nonnull __src); | ||
char* _Nonnull strcat(char* _Nonnull __dst, const char* _Nonnull __src); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/Interop/Cxx/function/builtin-nullability-return-type-typechecker.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource) -typecheck -verify -verify-ignore-unknown -I %S/Inputs -cxx-interoperability-mode=default -Xcc -D_CRT_SECURE_NO_WARNINGS %s | ||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource) -typecheck -verify -verify-ignore-unknown -I %S/Inputs -Xcc -D_CRT_SECURE_NO_WARNINGS %s | ||
|
||
import CustomStringBuiltins | ||
|
||
public func testMemcpyOptionalReturn(p: UnsafeMutableRawPointer, e: UnsafeRawPointer, c: UnsafePointer<CChar>, pc: UnsafeMutablePointer<CChar>) { | ||
// This 'memcpy' is a builtin and is always an optional, regardless of _Nonnull. | ||
let x = CustomStringBuiltins.memcpy(p, e, 1)! | ||
|
||
// Not a builtin, _Nonnull makes it a non-optional. | ||
let y = CustomStringBuiltins.memcpy42(p, e, 1)! // expected-error {{cannot force unwrap value of non-optional type 'UnsafeMutableRawPointer'}} | ||
|
||
// other builtins from 'string.h' | ||
let _ = CustomStringBuiltins.memchr(e, 42, 1)! | ||
let _ = CustomStringBuiltins.memmove(p, e, 42)! | ||
let _ = CustomStringBuiltins.memset(p, 1, 42)! | ||
let _ = CustomStringBuiltins.strrchr(c, 0)! | ||
let _ = CustomStringBuiltins.strcpy(pc, c)! | ||
let _ = CustomStringBuiltins.strcat(pc, c)! | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.