Ver código fonte

Improve static assertion macro.

Mike Pall 14 anos atrás
pai
commit
0a50356b6f
2 arquivos alterados com 7 adições e 1 exclusões
  1. 5 0
      src/lj_def.h
  2. 2 1
      src/lj_ir.h

+ 5 - 0
src/lj_def.h

@@ -239,7 +239,12 @@ static LJ_AINLINE uint32_t lj_fls(uint32_t x)
 /* Static assertions. */
 #define LJ_ASSERT_NAME2(name, line)	name ## line
 #define LJ_ASSERT_NAME(line)		LJ_ASSERT_NAME2(lj_assert_, line)
+#ifdef __COUNTER__
+#define LJ_STATIC_ASSERT(cond) \
+  extern void LJ_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
+#else
 #define LJ_STATIC_ASSERT(cond) \
   extern void LJ_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
+#endif
 
 #endif

+ 2 - 1
src/lj_ir.h

@@ -591,7 +591,6 @@ typedef union IRIns {
   check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))
 #define ir_kptr(ir) \
   check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, mref((ir)->ptr, void))
-LJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W);
 
 /* A store or any other op with a non-weak guard has a side-effect. */
 static LJ_AINLINE int ir_sideeff(IRIns *ir)
@@ -599,4 +598,6 @@ static LJ_AINLINE int ir_sideeff(IRIns *ir)
   return (((ir->t.irt | ~IRT_GUARD) & lj_ir_mode[ir->o]) >= IRM_S);
 }
 
+LJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W);
+
 #endif