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

Add minimal syntactic support for type _Float16 #525

Merged
merged 1 commit into from
Oct 22, 2024
Merged

Conversation

xavierleroy
Copy link
Contributor

@xavierleroy xavierleroy commented Oct 4, 2024

Appendix H of ISO C 2023 makes provisions for built-in binary floating-point types _FloatN, where N is the bit size of the type.

Some C compilers and math libraries already make use of type _Float16 to denote half-precision FP numbers. That's the case for XCode 16 on macOS 15, which declares _Float16 functions in <math.h> without guarding them with a #ifdef, e.g.

extern _Float16 __fabsf16(_Float16) __API_AVAILABLE(macos(15.0), ios(18.0), watchos(11.0), tvos(18.0));

With the current CompCert, any C source code that includes <math.h> causes a syntax error on these declarations.

This PR proposes to add minimal syntactic support for type _Float16. It is kept as a distinct FP type during elaboration, then rejected during conversion to CompCert C. This way, _Float16 functions declared in header files but not used in the C source file are silently ignored. If these functions are used, an "unsupported feature" error is reported.

The verified part of CompCert is unchanged.

@xavierleroy xavierleroy changed the title Add minimal syntactic support for types _Float16, _Float32 and _Float64 Add minimal syntactic support for type _Float16 Oct 4, 2024
@xavierleroy
Copy link
Contributor Author

xavierleroy commented Oct 4, 2024

A first cut of this PR also added _Float32 and _Float64 as synonymous for float and double, but this causes problems with Glibc header files, and is not needed.

This is part of C23 appendix H, and is starting to be used in system
header files.

`_Float16` is kept as a distinct FP type during elaboration, then rejected
during conversion to CompCert C.

The verified part of CompCert is unchanged.
@xavierleroy
Copy link
Contributor Author

Thanks for the feedback and testing. Merging!

@xavierleroy xavierleroy merged commit a735bfb into master Oct 22, 2024
7 checks passed
@xavierleroy xavierleroy deleted the FloatN branch October 22, 2024 07:47
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.

2 participants