Skip to content

Fix build issue when using clang (#2137)#2140

Merged
doug-walker merged 3 commits intoAcademySoftwareFoundation:mainfrom
anthony-linaro:fix-clang-cl
Jun 20, 2025
Merged

Fix build issue when using clang (#2137)#2140
doug-walker merged 3 commits intoAcademySoftwareFoundation:mainfrom
anthony-linaro:fix-clang-cl

Conversation

@anthony-linaro
Copy link
Copy Markdown
Contributor

Fixes the issue described in #2137 by defining the correct type when using clang-cl (which masquerades as MSVC).

Tested using LLVM 20.1.0's clang-cl, with the following command line:

mkdir build
cd build
cmake -G"Ninja" .. -DCMAKE_C_COMPILER="clang-cl" -DCMAKE_CXX_COMPILER="clang-cl"
cmake --build .
ctest

@anthony-linaro
Copy link
Copy Markdown
Contributor Author

FYI @lazka and @kmilos

Signed-off-by: Anthony Roberts <anthony.roberts@linaro.org>
@kmilos
Copy link
Copy Markdown

kmilos commented Mar 27, 2025

Thanks, but I'm not 100% sure this covers #2137 - we're not using clang-cl in MSYS2 CLANGARM64, so _M_ARM64 is not defined AFAIK. llvm-mingw based clang is used instead.

@anthony-linaro
Copy link
Copy Markdown
Contributor Author

@kmilos I've just tried it with this line instead, which uses the GNU command line:

cmake -G"Ninja" .. -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++"

And it still appears to work. Are you able to test to see if it fixes your issue?

@kmilos
Copy link
Copy Markdown

kmilos commented Mar 27, 2025

Sorry, that'll have to be @lazka confirming, I have no access...

But generally, I think you'll find that regardless of the frontend command (and architecture), the "official" LLVM Windows binary packages I assume you're using, and the MSYS2 CLANGARM64 (and CLANG64 equally) have different targets defined and are not, in fact, identical/equivalent toolchains: {aarch64,x86_64}-pc-windows-msvc vs {aarch64,x86_64}-w64-windows-gnu?

In other words, both clang and clang-cl targeting *-pc-windows-msvc will in any case emulate MSVC, just that clang-cl supports cl arguments syntax on top vs the GNU style.

@anthony-linaro
Copy link
Copy Markdown
Contributor Author

ACK, I'm not able to use that triplet without an msys2 env, so I'll await the response from lazka.

I can't see any other way it would have float16_t defined as int16_t though, unless it was hitting that define statement.

@lazka
Copy link
Copy Markdown

lazka commented Mar 27, 2025

Thanks, but I'm not 100% sure this covers #2137 - we're not using clang-cl in MSYS2 CLANGARM64, so _M_ARM64 is not defined AFAIK. llvm-mingw based clang is used instead.

https://github.com/mingw-w64/mingw-w64/blob/90da6c6535c503159e952dc8b44f8778bed6f622/mingw-w64-headers/crt/_mingw_mac.h#L87

ACK, I'm not able to use that triplet without an msys2 env, so I'll await the response from lazka.

I can't easily test right now, but this looks functionally equivalent to the patch I was using, so lgtm!

@kmilos
Copy link
Copy Markdown

kmilos commented Mar 27, 2025

I can't easily test right now, but this looks functionally equivalent to the patch I was using, so lgtm!

Sorry, but I'm still not convinced. This is guarded by _M_ARM64 which should not be defined in CLANGARM64.

Oops, didn't see that link at first, apologies! (So, not defined by the compiler, as expected, but by MinGW headers.)

I'd still prefer to make it explicit like it is in other places then: (defined(__aarch64__) || defined(_M_ARM64))?

@kmilos
Copy link
Copy Markdown

kmilos commented Mar 28, 2025

However, we do also have GCC 15 around the corner finally supporting the aarch64-w64-mingw32 target, so the second __clang__ conditional might not be ideal? Don't know (and can't test) if and how float16_t is defined there... Looks like __fp16 is available?

Maybe use #if defined(__GNUC__), or turn the logic around for MSVC specifically #if defined(_MSC_VER) && !defined(__clang__) instead?

@anthony-linaro
Copy link
Copy Markdown
Contributor Author

@kmilos I can't easily test the new version of GCC, but I think an inversion may well work here (assuming it does __fp16 as per the docs), so I'll update it to that, and add an explicit check for __aarch64__ too (just in case headers end up differing for some reason in the future and not defining _M_ARM64 anymore)

@kmilos
Copy link
Copy Markdown

kmilos commented Mar 28, 2025

Thanks @anthony-linaro

I think you can actually ignore my GCC comment and leave it as __clang__ only: unlike LLVM's, float16_t seems to be defined there in arm_fp16.h (via arm_neon.h), and I guess this was already working on Linux.

@anthony-linaro
Copy link
Copy Markdown
Contributor Author

Given that, looking at the code, it's already entirely in an #elif defined(__aarch64__) || defined(_M_ARM64) block, so I'll just clean it up and check for #if !defined(float16_t), and drop the _M_ARM64 bit entirely - the lack of definition for float16_t should suffice

Signed-off-by: Anthony Roberts <anthony.roberts@linaro.org>
@kmilos
Copy link
Copy Markdown

kmilos commented Mar 28, 2025

LGTM

@doug-walker doug-walker requested a review from cozdas May 16, 2025 00:04
@doug-walker doug-walker merged commit db68839 into AcademySoftwareFoundation:main Jun 20, 2025
25 checks passed
michaelHADSK pushed a commit to autodesk-forks/OpenColorIO that referenced this pull request Jul 24, 2025
…ademySoftwareFoundation#2140)

* Fix build issue when using clang (AcademySoftwareFoundation#2137)

Signed-off-by: Anthony Roberts <anthony.roberts@linaro.org>

* Change define check, and update comment

Signed-off-by: Anthony Roberts <anthony.roberts@linaro.org>

---------

Signed-off-by: Anthony Roberts <anthony.roberts@linaro.org>
Co-authored-by: Doug Walker <doug.walker@autodesk.com>
michaelHADSK pushed a commit to autodesk-forks/OpenColorIO that referenced this pull request Jul 24, 2025
…ademySoftwareFoundation#2140)

* Fix build issue when using clang (AcademySoftwareFoundation#2137)

Signed-off-by: Anthony Roberts <anthony.roberts@linaro.org>

* Change define check, and update comment

Signed-off-by: Anthony Roberts <anthony.roberts@linaro.org>

---------

Signed-off-by: Anthony Roberts <anthony.roberts@linaro.org>
Co-authored-by: Doug Walker <doug.walker@autodesk.com>
Signed-off-by: Michael Horsch <michael.horsch@autodesk.com>
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.

5 participants