Skip to content

clang-21 on macos fixes#126235

Open
AaronRobinsonMSFT wants to merge 9 commits intodotnet:mainfrom
AaronRobinsonMSFT:clang21_macos_fixes
Open

clang-21 on macos fixes#126235
AaronRobinsonMSFT wants to merge 9 commits intodotnet:mainfrom
AaronRobinsonMSFT:clang21_macos_fixes

Conversation

@AaronRobinsonMSFT
Copy link
Copy Markdown
Member

@AaronRobinsonMSFT AaronRobinsonMSFT commented Mar 28, 2026

Addresses various build failures when compiling with the latest Xcode.

% clang --version
Apple clang version 21.0.0 (clang-2100.0.123.102)
Target: arm64-apple-darwin25.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

See #119706 (comment)

Clang 21 changes for -Wc++-keyword - https://releases.llvm.org/21.1.0/tools/clang/docs/ReleaseNotes.html#id11
Partially related unicode-org/icu#2913

Addresses various build failures when compiling with the latest Xcode.

```
% clang --version
Apple clang version 21.0.0 (clang-2100.0.123.102)
Target: arm64-apple-darwin25.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Addresses build failures / new diagnostics when compiling dotnet/runtime native components with newer Clang/Xcode toolchains (e.g., Apple clang 21), primarily by tightening up pointer/CF type conversions and suppressing a new ICU-header warning.

Changes:

  • Add explicit casts to satisfy newer Clang diagnostics around implicit void* conversions and CoreFoundation type APIs.
  • Minor Objective-C formatting cleanups in Network.framework PAL.
  • Suppress -Wc++-keyword warnings when building System.Globalization.Native (ICU headers).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509chain.c Add explicit malloc cast to avoid new implicit void* conversion diagnostics.
src/native/libs/System.Security.Cryptography.Native.Apple/pal_ssl.c Add casts for CF APIs (bytes pointer + CFArray element type).
src/native/libs/System.Security.Cryptography.Native.Apple/pal_networkframework.m Formatting cleanups and cast to tls_ciphersuite_t for Clang strictness.
src/native/libs/System.Security.Cryptography.Native.Apple/pal_ecc.c Cast CFDictionaryGetValue result to CFNumberRef for stricter compilation.
src/native/libs/System.Native/pal_networking.c Add casts on calloc return to satisfy stricter pointer conversion rules (Darwin unlimited select path).
src/native/libs/System.Native/pal_environment.m Add explicit malloc cast to avoid new implicit void* conversion diagnostics.
src/native/libs/System.Globalization.Native/CMakeLists.txt Suppress Clang warning -Wc++-keyword likely triggered by ICU headers.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 28, 2026 01:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

@AaronRobinsonMSFT AaronRobinsonMSFT requested a review from am11 March 28, 2026 01:38
@AaronRobinsonMSFT
Copy link
Copy Markdown
Member Author

FYI @am11

@AaronRobinsonMSFT AaronRobinsonMSFT enabled auto-merge (squash) March 28, 2026 02:20
Copilot AI review requested due to automatic review settings March 28, 2026 02:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

…acceptableIssuers in AppleCryptoNative_NwConnectionCreate
Copilot AI review requested due to automatic review settings March 28, 2026 03:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

@am11
Copy link
Copy Markdown
Member

am11 commented Mar 28, 2026

This gets us through the native build with Apple clang 21. There are two (non-fatal) warnings:

When building src/tests native components:

[372/376] Generating SwiftErrorHandling library
/Users/adeel/projects/runtime2/src/tests/Interop/Swift/SwiftErrorHandling/SwiftErrorHandling.swift:7:10: warning: associated value 'runtimeError(message:)' of 'Sendable'-conforming enum 'MyError' contains non-Sendable type 'NSString'
 5 | 
 6 | public enum MyError: Error {
 7 |     case runtimeError(message: NSString)
   |          `- warning: associated value 'runtimeError(message:)' of 'Sendable'-conforming enum 'MyError' contains non-Sendable type 'NSString'
 8 | }
 9 | 

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:103:12: note: class 'NSString' does not conform to the 'Sendable' protocol
101 | 
102 | 
103 | @interface NSString : NSObject <NSCopying, NSMutableCopying, NSSecureCoding>
    |            `- note: class 'NSString' does not conform to the 'Sendable' protocol
104 | 
105 | #pragma mark *** String funnel methods ***
[375/376] Install the project...
-- Install configuration: "DEBUG"

When building libs.native:

[141/288] Building C object System.Native/CMakeFiles/System.Native.dir/pal_memory.c.o
/Users/adeel/projects/runtime2/src/native/libs/System.Native/pal_memory.c:22:7: warning: function SystemNative_AlignedAlloc might be an allocator wrapper [-Wallocator-wrappers]
   22 | void* SystemNative_AlignedAlloc(uintptr_t alignment, uintptr_t size)
      |       ^
/Users/adeel/projects/runtime2/src/native/libs/System.Native/pal_memory.c:26:5: note: value obtained from allocator call is returned here
   26 |     return aligned_alloc(alignment, size);
      |     ^
/Users/adeel/projects/runtime2/src/native/libs/System.Native/pal_memory.c:70:7: warning: function SystemNative_Calloc might be an allocator wrapper [-Wallocator-wrappers]
   70 | void* SystemNative_Calloc(uintptr_t num, uintptr_t size)
      |       ^
/Users/adeel/projects/runtime2/src/native/libs/System.Native/pal_memory.c:72:5: note: value obtained from allocator call is returned here
   72 |     return calloc(num, size);
      |     ^
/Users/adeel/projects/runtime2/src/native/libs/System.Native/pal_memory.c:80:7: warning: function SystemNative_Malloc might be an allocator wrapper [-Wallocator-wrappers]
   80 | void* SystemNative_Malloc(uintptr_t size)
      |       ^
/Users/adeel/projects/runtime2/src/native/libs/System.Native/pal_memory.c:82:5: note: value obtained from allocator call is returned here
   82 |     return malloc(size);
      |     ^
/Users/adeel/projects/runtime2/src/native/libs/System.Native/pal_memory.c:85:7: warning: function SystemNative_Realloc might be an allocator wrapper [-Wallocator-wrappers]
   85 | void* SystemNative_Realloc(void* ptr, uintptr_t new_size)
      |       ^
/Users/adeel/projects/runtime2/src/native/libs/System.Native/pal_memory.c:87:5: note: value obtained from allocator call is returned here
   87 |     return realloc(ptr, new_size);
      |     ^
4 warnings generated.

We can figure out best way to fix them in a follow-up.

Copilot AI review requested due to automatic review settings March 29, 2026 02:21
@AaronRobinsonMSFT
Copy link
Copy Markdown
Member Author

This gets us through the native build with Apple clang 21. There are two (non-fatal) warnings:

Forgot about the -Wallocator-wrappers ones. Thanks for calling out the test failures, updated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/tests/Interop/Swift/SwiftErrorHandling/SwiftErrorHandling.swift:35

  • getMyErrorMessage returns nil when the error is not MyError, but it never sets messageLength in that path. The C# P/Invoke uses an out int length, so this can surface as an uninitialized length value if the cast fails. Set messageLength = 0 before returning nil (or initialize it at function entry).
public func getMyErrorMessage(from error: Error, messageLength: inout Int32) -> UnsafePointer<unichar>? {
    if let myError = error as? MyError {
        switch myError {
        case .runtimeError(let message):
            let nsMessage = message as NSString
            let buffer = UnsafeMutableBufferPointer<unichar>.allocate(capacity: nsMessage.length)
            nsMessage.getCharacters(buffer.baseAddress!, range: NSRange(location: 0, length: nsMessage.length))
            messageLength = Int32(nsMessage.length)
            return UnsafePointer(buffer.baseAddress!)
        }
    }
    return nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants