diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2024-07-19 00:05:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-19 00:05:12 -0700 |
| commit | bf293360d31e6e4aa40f64d82317de9e5b4edb47 (patch) | |
| tree | f8dff9524bb198c9fb733c83d53397e602ee7780 | |
| parent | 335c1a2d0013091e8ecc1691b3521cf22fed3c6c (diff) | |
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 <yonghe@outlook.com>
| -rw-r--r-- | include/slang.h | 9 |
1 files changed, 3 insertions, 6 deletions
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)); |
