dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.23k stars 4.45k forks source link

`pal.h` will not build with clang 18 for x86 #101639

Closed richlander closed 2 weeks ago

richlander commented 2 weeks ago

Builds with clang 16 but not clang 18. This is specific to 32-bit Linux.

  /__w/1/s/src/coreclr/pal/inc/pal.h:3605:5: error: __sync builtin operation MUST have natural alignment (consider using __atomic). [-Werror,-Wsync-alignment]
   3605 |     __sync_val_compare_and_swap(
        |     ^
  /__w/1/s/src/coreclr/pal/inc/pal.h:3471:5: error: __sync builtin operation MUST have natural alignment (consider using __atomic). [-Werror,-Wsync-alignment]
   3471 |     __sync_add_and_fetch(lpAddend, (LONGLONG)1)
        |     ^
  /__w/1/s/src/coreclr/pal/inc/pal.h:3506:5: error: __sync builtin operation MUST have natural alignment (consider using __atomic). [-Werror,-Wsync-alignment]
   3506 |     __sync_sub_and_fetch(lpAddend, (LONGLONG)1)
        |     ^
  3 errors generated.

https://github.com/dotnet/runtime/pull/101630#issuecomment-2080438905

am11 commented 2 weeks ago

This diagnostic was added in https://reviews.llvm.org/D143813, it is looking for something like

-    InterlockedIncrement64(IN OUT LONGLONG volatile *lpAddend),
+    InterlockedIncrement64(IN OUT LONGLONG volatile *lpAddend DECLSPEC_ALIGN(8)),
richlander commented 2 weeks ago

Looks like that change is in LLVM 17+. Thanks for the extra info.