Skip to content

Fix compilation of Apple native shim on newer Clang #108888

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 1 commit into from
Oct 15, 2024

Conversation

vcsjones
Copy link
Member

@vcsjones vcsjones commented Oct 15, 2024

Newer versions of Clang warn when you are doing enum comparisons of different enum types.

Fixes #108827.

Newer versions of Clang warn when you are doing enum comparisons of different enum types.
@@ -6,21 +6,21 @@

#include <assert.h>

c_static_assert(PAL_OperationEncrypt == kCCEncrypt);
c_static_assert(PAL_OperationDecrypt == kCCDecrypt);
c_static_assert((uint32_t)PAL_OperationEncrypt == (uint32_t)kCCEncrypt);
Copy link
Member Author

Choose a reason for hiding this comment

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

Both the enum types are uint32_t.

@@ -151,7 +151,7 @@ int32_t AppleCryptoNative_X509GetRawData(SecCertificateRef cert, CFDataRef* ppDa
}

*ppDataOut = SecCertificateCopyData(cert);
*pOSStatus = *ppDataOut == NULL ? errSecParam : noErr;
*pOSStatus = *ppDataOut == NULL ? errSecParam : (OSStatus)noErr;
Copy link
Member Author

Choose a reason for hiding this comment

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

This feels like a weird one to me, or the Clang compiler being a little confused. We use noErr all over the place but only complained in this place.

The reason it complains here is it is the only place we don't assign it to some OSStatus as an intermediate, and use it in an expression directly mixing it with an OSStatus. noErr is an anonymous enum in MacTypes.h.

The alternative is to use errSecSuccess. This is functionally the same as noErr (both have a value of 0), but I opted for the smaller change here. It would be a tad weird to use errSecSuccess in this function, but keep using noErr everywhere else, and changing everything seemed unnecessary.

@vcsjones
Copy link
Member Author

With these changes I get a clean build on macOS with Clang 19.1.1.

@vcsjones vcsjones merged commit e9e0ab4 into dotnet:main Oct 15, 2024
97 checks passed
@vcsjones vcsjones deleted the fix-anon-anon-enum-conversion branch October 15, 2024 16:48
@dacheng-gao
Copy link
Contributor

Hey @vcsjones I want to say thank you for the fix.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

build error: comparison of different enumeration types
3 participants