[PATCH] D12001: Implement __emutls_get_address

Chih-Hung Hsieh via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 15:25:24 PDT 2015


chh added inline comments.

================
Comment at: compiler-rt/lib/builtins/int_util.h:31
@@ +30,3 @@
+    typedef char dummy[(pred) ? 0 : -1] __attribute__((unused)); \
+}
+
----------------
joerg wrote:
> More like:
> 
> #define COMPILE_TIME_ASSERT0(pred,cnt) typedef char dummy#cnt[(pred) ? 1 : -1]
> #define COMPILE_TIME_ASSERT(pred) COMPILE_TIME_ASSERT0(pred,__LINE__)
> 
> or so.
I think what you want is dummy##cnt to add line number to each dummy typedef.
However, above macros were expanded to `dummy__LINE__`, and I got multiple definition errors.

A trick to get cpp do the right thing is:


```
#define COMPILE_TIME_ASSERT(expr)    typedef char UNIQUE_NAME[(expr) ? 1 : -1] __attribute__((unused))
#define UNIQUE_NAME                     MAKE_NAME(__LINE__)
#define MAKE_NAME(line)                 MAKE_NAME2(line)
#define MAKE_NAME2(line)               constraint_ ## line

```
The `__attribute__((unused))` is still necessary to avoid unused typedef warnings.

Would you rather to have that complicated macros?

My current definition should give line number on error and also avoid multiple definition errors.




http://reviews.llvm.org/D12001





More information about the llvm-commits mailing list