From bf293360d31e6e4aa40f64d82317de9e5b4edb47 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Fri, 19 Jul 2024 00:05:12 -0700 Subject: Fix LLVM compile error on Windows (#4658) The following compile error is observed when build with LLVM on Windows: ``` D:/sbf/git/slang/test_wsl/source/slang-glslang/slang-glslang.cpp:39:31: error: static assertion expression is not an integral constant expression 39 | SLANG_COMPILE_TIME_ASSERT(SLANG_OFFSET_OF(TBuiltInResource, limits) > 0); | ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` To address the problem, SLANG_OFFSET_OF is defined as `offsetof` when `__clang__` is defined. Co-authored-by: Yong He --- include/slang.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/slang.h b/include/slang.h index 76743a426..1671e7f38 100644 --- a/include/slang.h +++ b/include/slang.h @@ -254,15 +254,16 @@ convention for interface methods. // GCC Specific #if SLANG_GCC_FAMILY - # define SLANG_NO_INLINE __attribute__((noinline)) # define SLANG_FORCE_INLINE inline __attribute__((always_inline)) # define SLANG_BREAKPOINT(id) __builtin_trap(); # define SLANG_ALIGN_OF(T) __alignof__(T) +#endif // SLANG_GCC_FAMILY +#if SLANG_GCC_FAMILY || defined(__clang__) // Use the builtin directly so we don't need to have an include of stddef.h # define SLANG_OFFSET_OF(T, ELEMENT) __builtin_offsetof(T, ELEMENT) -#endif // SLANG_GCC_FAMILY +#endif #ifndef SLANG_OFFSET_OF # define SLANG_OFFSET_OF(T, ELEMENT) (size_t(&((T*)1)->ELEMENT) - 1) @@ -290,10 +291,6 @@ convention for interface methods. # define SLANG_COMPILE_TIME_ASSERT(x) static_assert(x) #endif -#ifndef SLANG_OFFSET_OF -# define SLANG_OFFSET_OF(X, Y) offsetof(X, Y) -#endif - #ifndef SLANG_BREAKPOINT // Make it crash with a write to 0! # define SLANG_BREAKPOINT(id) (*((int*)0) = int(id)); -- cgit v1.2.3