From 69727bb3de59952fb8a34535b21fc5fa8eebe745 Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Tue, 22 Aug 2023 16:51:02 +0100 Subject: [PATCH] [cxx-interop] Add test for `INADDR_ANY` usage At some point several months ago the `INADDR_ANY` macro from `Darwin.POSIX` module was not imported into Swift correctly. The issue seems to be resolved now. This change adds a test to make sure we don't regress again. rdar://107429566 --- test/Interop/Cxx/objc-correctness/Inputs/POSIX.h | 9 +++++++++ .../Interop/Cxx/objc-correctness/Inputs/module.modulemap | 4 ++++ test/Interop/Cxx/objc-correctness/posix.swift | 6 ++++++ 3 files changed, 19 insertions(+) create mode 100644 test/Interop/Cxx/objc-correctness/Inputs/POSIX.h create mode 100644 test/Interop/Cxx/objc-correctness/posix.swift diff --git a/test/Interop/Cxx/objc-correctness/Inputs/POSIX.h b/test/Interop/Cxx/objc-correctness/Inputs/POSIX.h new file mode 100644 index 0000000000000..f52ab58d2769b --- /dev/null +++ b/test/Interop/Cxx/objc-correctness/Inputs/POSIX.h @@ -0,0 +1,9 @@ +typedef unsigned int __uint32_t; +typedef unsigned int u_int32_t; +typedef __uint32_t in_addr_t; + +struct in_addr { + in_addr_t s_addr; +}; + +#define INADDR_ANY (u_int32_t)0x00000000 diff --git a/test/Interop/Cxx/objc-correctness/Inputs/module.modulemap b/test/Interop/Cxx/objc-correctness/Inputs/module.modulemap index 005f2287098e1..03b14c92c6d2e 100644 --- a/test/Interop/Cxx/objc-correctness/Inputs/module.modulemap +++ b/test/Interop/Cxx/objc-correctness/Inputs/module.modulemap @@ -38,3 +38,7 @@ module NSTextCheckingResult { header "NSTextCheckingResult.h" requires objc } + +module MockPOSIX { + header "POSIX.h" +} diff --git a/test/Interop/Cxx/objc-correctness/posix.swift b/test/Interop/Cxx/objc-correctness/posix.swift new file mode 100644 index 0000000000000..56ae3d326648b --- /dev/null +++ b/test/Interop/Cxx/objc-correctness/posix.swift @@ -0,0 +1,6 @@ +// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs -cxx-interoperability-mode=swift-5.9 %s +// REQUIRES: objc_interop + +import MockPOSIX + +let _ = in_addr(s_addr: INADDR_ANY)