KhronosGroup / KhronosGroup/KTX-Software

ClangCL Windows 10 build errors (ClangCL v16.0.5)

Open
#1,248 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.4k
Forks
317
Avg merge
20h 12m
Merged PRs (30d)
3

Description

While trying to figure out a non-determinism issue with a BC6HU (HDR) test (in my BCn PR) that randomly fails only on Clang-CL (and on x64, apparently), I tried to replicate the build instructions for the corresponding CI job (see here: https://github.com/KhronosGroup/KTX-Software/actions/runs/34260205148/job/102175963632?pr=1167)

On Windows 10, build using:
```
cmake -S . -G "Visual Studio 17 2022" -A x64 -T CLangCL -B build -DCMAKE_BUILD_TYPE=Debug -DKTX_FEATURE_TOOLS=OFF -DKTX_FEATURE_TOOLS_CTS=OFF -DKTX_WERROR=ON
```

clang-cl.exe version: `clang version 16.0.5`

Then I get a set of issues:

1. `KTX-Software\lib\src\multithreading.cpp(15,42): error : unknown warning group '-Wcast-function-type-mismatch'`. '-Wcast-function-type-mismatch' was introduced in clang 19.x. => easlity fixable by adding a CMake genex on clang version >= 19.x. Fixed by the following patch:

```patch
diff --git a/lib/src/gl_funcs.c b/lib/src/gl_funcs.c
index eedaa4b5..596e339e 100644
--- a/lib/src/gl_funcs.c
+++ b/lib/src/gl_funcs.c
@@ -149,14 +149,14 @@ ktxFindOpenGL() {

if (found) {
// Need wglGetProcAddr for non-OpenGL-2 functions.
-#ifdef __clang__
+#if defined(__clang__) && (__clang_major__ >= 19)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
#endif
pfnWglGetProcAddress =
(PFNGLGETPROCADDRESS)GetProcAddress(module,
"wglGetProcAddress");
-#ifdef __clang__
+#if defined(__clang__) && (__clang_major__ >= 19)
#pragma clang diagnostic pop
#endif

diff --git a/lib/src/multithreading.cpp b/lib/src/multithreading.cpp
index 23ec4dd7..b270fb64 100644
--- a/lib/src/multithreading.cpp
+++ b/lib/src/multithreading.cpp
@@ -10,12 +10,12 @@ int
pthread_create(pthread_t* thread, const pthread_attr_t* attribs, void* (*threadfunc)(void*),
void* thread_arg) {
(void)attribs;
- #ifdef __clang__
+ #if defined(__clang__) && (__clang_major__ >= 19)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
#endif
LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)(threadfunc);
- #ifdef __clang__
+ #if defined(__clang__) && (__clang_major__ >= 19)
#pragma clang diagnostic pop
#endif
*thread = CreateThread(nullptr, 0, func, thread_arg, 0, nullptr);
```

2. For ktxtools CMake target, -fno-exceptions is weirdly being propagated from somewhere (either from `fmt` or from basisu's code, definitely not in KTX-Software core source code...). Compiler is complaining about try/throw keywords in imageio (e.g., `KTX-Software\tools\imageio\./formatdesc.h(274,17): error : cannot use 'throw' with exceptions disabled`) being used while no-exceptions is specified (again, from where?). => I will update once I figure out why this is occurring...

clang-cl.exe version: `clang version 16.0.5`
(Latest version I could install from Visual Studio 17 2022 Installer).

If clang-cl < 19.x is not supported, then I will close this (from my part I will edit the code and try to make it work with clang-cl 16 since that's the only version(?) I can install on my Windows 10 machine ...)

Edit: mistakenly clicked `create` before finishing the issue description. Another edit for typos.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided CMake Visual Studio 2022 ClangCL command on Windows 10. Inspect lib/src/multithreading.cpp, lib/src/gl_funcs.c, the ktxtools target, and tools/imageio/formatdesc.h to trace the warning and exception settings. Done means the reported ClangCL build errors are resolved or the supported compiler range is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.