]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: extend GNU C guards to clang where applicable, fix fallouts
authorViktor Szakats <commit@vsz.me>
Thu, 17 Jul 2025 17:01:42 +0000 (19:01 +0200)
committerViktor Szakats <commit@vsz.me>
Sun, 27 Jul 2025 21:02:05 +0000 (23:02 +0200)
Some GNU C version guards implicitly include the clang compiler, because
clang reports itself as GCC 4.2.1.

This implicit inclusion doesn't happen if the guard requires a GCC
version above 4.2.1.

Fix two such guards to explicitly include clang where it does support
the guarded feature:

- curl/curl.h: use `typecheck-gcc.h` with clang.
  llvm clang v14+ supports this. The corresponding Apple clang version
  is also v14.
  Ref: https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
  Apple clang v14 tested OK in CI:
  https://github.com/curl/curl/actions/runs/16353901480/job/46207437204

- tool_urlglib: use `__builtin_mul_overflow()` with clang v8+.
  llvm clang v3.8+ supports this, but to accommodate for Apple clang,
  start with v8, the Apple version having the mainline v3.8 feature set.

Also fix compile warnings triggered by the above:
- lib1912: fix duplicate `;`:
  ```
  tests/libtest/lib1912.c:44:57: error: empty expression statement has no effect; remove unnecessary ';' to silence this warning [-Werror,-Wextra-semi-stmt]
   44 |       print_err(o->name, "CURLOT_LONG or CURLOT_VALUES");
      |                                                         ^
  [...]
  ```
  Ref: https://github.com/curl/curl/actions/runs/16351302841/job/46198524880?pr=17955#step:12:61

- lib2032: silence typcheck warning with a cast:
  ```
  tests/libtest/lib2032.c:145:29: error: sizeof on pointer operation will return size of 'CURL **' (aka 'void **') instead of 'CURL *[3]' (aka 'void *[3]') [-Werror,-Wsizeof-array-decay]
    145 |                   ntlm_easy + num_handles);
        |                   ~~~~~~~~~ ^
  ```
  Ref: https://github.com/curl/curl/actions/runs/16351302841/job/46198524880?pr=17955#step:12:86

Closes #17955

include/curl/curl.h
src/tool_urlglob.c
tests/libtest/lib1912.c
tests/libtest/lib2032.c

index 4e2cf9ada57a78c6fa17d433d40cb348d542fcca..cb4e523c38b95c7559c45c2bcb416dbdf8a1dd4b 100644 (file)
@@ -3317,8 +3317,9 @@ CURL_EXTERN CURLcode curl_easy_ssls_export(CURL *handle,
 #include "mprintf.h"
 
 /* the typechecker does not work in C++ (yet) */
-#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \
-    ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && \
+#if ((defined(__GNUC__) && defined(__GNUC_MINOR__) && \
+      ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \
+    (defined(__clang__) && __clang_major__ >= 14)) && \
     !defined(__cplusplus) && !defined(CURL_DISABLE_TYPECHECK)
 #include "typecheck-gcc.h"
 #else
index 29c4119cd71a4f219954e6cdc75d311c9e67e0d2..c20bbd4ea3e4f8babb982886ac379982c2cbfc1b 100644 (file)
@@ -68,8 +68,9 @@ static int multiply(curl_off_t *amount, curl_off_t with)
     sum = 0;
   }
   else {
-#if defined(__GNUC__) && \
-  ((__GNUC__ > 5) || ((__GNUC__ == 5) && (__GNUC_MINOR__ >= 1)))
+#if (defined(__GNUC__) && \
+  ((__GNUC__ > 5) || ((__GNUC__ == 5) && (__GNUC_MINOR__ >= 1)))) || \
+  (defined(__clang__) && __clang_major__ >= 8)
     if(__builtin_mul_overflow(*amount, with, &sum))
       return 1;
 #else
index db6c3d1e68109c586eed25c5bf29bb46b52f5f6c..e74808c3c09043878472c8ac9f513c7ef91f230d 100644 (file)
@@ -27,7 +27,7 @@
 
 #define print_err(name, exp)                                            \
   curl_mfprintf(stderr, "Type mismatch for CURLOPT_%s (expected %s)\n", \
-                name, exp);
+                name, exp)
 
 static CURLcode test_lib1912(char *URL)
 {
index a998c7223073d232a1da757f6726a2543e94b65a..993626bb35f4fbe68cc008e79df9ef2471fbe5d6 100644 (file)
@@ -142,7 +142,7 @@ static CURLcode test_lib2032(char *URL)  /* libntlmconnect */
                   "testuser:testpass");
       easy_setopt(ntlm_easy[num_handles], CURLOPT_WRITEFUNCTION, callback);
       easy_setopt(ntlm_easy[num_handles], CURLOPT_WRITEDATA,
-                  ntlm_easy + num_handles);
+                  (void *)(ntlm_easy + num_handles));
       easy_setopt(ntlm_easy[num_handles], CURLOPT_HEADER, 1L);
 
       multi_add_handle(multi, ntlm_easy[num_handles]);