1. Список говнокодов пользователя j123123

    Всего: 338

  2. Java / Говнокод #19142

    −32

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    MethodHandle mov256MH = CodeSnippet.make("move256",
         MethodType.methodType(void.class,            // return type
                               Object.class /*rdi*/,  // src
                               long.class   /*rsi*/,  // offset
                               Object.class /*rdx*/,  // dst
                               long.class   /*rcx*/), // offset
         CPUID.has(AVX),
         0xC4, 0xE1, 0x7E, 0x6F, 0x04, 0x37,  // vmovdqu ymm0,[rsi+rdi]
         0xC4, 0xE1, 0x7E, 0x7F, 0x04, 0x0A); // vmovdqu [rdx+rcx],ymm0
    
    
       static void move256(Object src, long off1, Object dst, long off2) {
           try {
               mov256MH.invokeExact(src, off1, dst, off2);
           } catch (Throwable e) {
               throw new Error(e);
           }
       }
    
       byte[] src = ...; long off1 = ...;
       byte[] dst = ...; long off2 = ...;
       move256(src, off1, dst, off2);

    Вставка машинного кода (прямо как в http://govnokod.ru/19017 ) теперь и в Java
    http://mail.openjdk.java.net/pipermail/panama-dev/2015-December/000225.html

    j123123, 06 Декабря 2015

    Комментарии (76)
  3. Си / Говнокод #19119

    −98

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    void *_band_get_aligned(Band *p, size_t alignment, size_t size)
    {
    	Block     *which;
    	ListNode  *x;
    
    	if (!__mallocsizes_inited) {
    		__malloc_sizes_init();
    	}
    	assert(size <= p->nbpe);
    	if (alignment != _MALLOC_ALIGN) {
    		size_t esize = p->nbpe + SB_OVERHEAD();
    		size_t	   dividend = (alignment / esize);
    		assert(alignment >= _MALLOC_ALIGN);
    
    		if (dividend > p->nalloc
    			|| (alignment != _MALLOC_ALIGN 
          && dividend * esize != alignment)) { /* not an even multiple */
    			errno = EINVAL;
    			return NULL;
    		}
    	}
    
    	if ((which = p->alist) != NULL) {
    		if (alignment != _MALLOC_ALIGN) {
    			x = (ListNode *)_block_memalign(p, which, alignment);
    		}
    		else {
    			x = (ListNode *)_block_mem_malloc_align(p, which);
    		}
    		if (x != NULL) {
    #ifdef STATISTICS
    			p->alloc_counter++;
    #endif
    			x->ln_offset = (char *)which - (char *)x;
    			assert(x->ln_offset < 0);
    			assert(which->navail > 0);
    
    			/*
    		 	* If no more blocks, put this on the depleted-list
    		 	*/
    			if (--which->navail == 0) {
    				Block        *b;
    
    				assert(which->head == NULL);
    				assert(which->prev == NULL);
    
    				/*
    			 	* Simple delete -- which is first.
    			 	*/
    				p->alist = b = which->next;
    				if (b)
    					b->prev = NULL;
    
    				/*
    			 	* insert into d(epleted)list
    			 	*/
    				which->next = b = p->dlist;
    				p->dlist = which;
    				if (b)
    					b->prev = which;
    			}
    			_malloc_stats.m_small_allocmem += p->nbpe;
    			_malloc_stats.m_small_freemem -= p->nbpe;
    
    			return x+1;
    		}
    	}
    
    	if ((which = band_addblk(p)) == NULL) {
    		return 0; /* failed */
    	}
    	assert(which->navail);
    	return _band_get_aligned(p, alignment, size);
    }

    [color=blue]http://sourceforge.net/p/monartis/openqnx/ci/master/tree/trunk/lib/c/alloc/band.c#l346[color] - рекурсия в аллокаторе QNX. Некоторые компиляторы эту рекурсию оптимизируют, некоторые - нет. И когда не оптимизируют, она способна при определенных условия выжрать стек, что приводит к сегфолту, например как тут [color=blue]http://www.openqnx.com/phpbbforum/viewtopic.php?f=7&t=12896&view=print[color]

    j123123, 02 Декабря 2015

    Комментарии (10)
  4. Си / Говнокод #19117

    −100

    1. 1
    https://youtu.be/sm-W4Tzg9-o?t=692

    Анимированные 3D модели в С коде. К сожалению, передать это в виде текста не представляется возможным.

    j123123, 01 Декабря 2015

    Комментарии (18)
  5. Си / Говнокод #19105

    −96

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    #include <stdio.h>
    #include <inttypes.h>
    
    int main() {
        int arr[] = {34, 12, 24, 65, 63, 22};
        size_t arraySize = (sizeof(arr) / sizeof(*arr));
    
        size_t i;
        startloop1:;
            void * loop1val = &&endloop1;
            i = 0;
            startloop2:
                goto *( (void *[]){&&noexchange, &&exchange}[arr[i] >= arr[i+1]]);
                exchange:;
                    int tmp;
                    tmp=arr[i];
                    arr[i]=arr[i+1];
                    arr[i+1]=tmp;
                    loop1val = &&startloop1;
                noexchange:
                i++;
                goto *( (void *[]){&&startloop2, &&endloop2}[i >= arraySize-1]);
            endloop2:
            goto *loop1val; 
        endloop1:
        i = 0;
        
        startloop3:
            printf("%i ", arr[i]);
            i++;
            goto *( (void *[]){&&startloop3, &&endloop3}[i >= arraySize]);
        endloop3:
        
        return 0;
    }

    На говнохабре http://habrahabr.ru/post/269875/ очередная хуита написана, вот типа напишите сортировку не используя if. Но в том коде есть циклы, любой настоящий программист знает, что циклы это по сути то же самое, что и if(условие) goto куда-тотам. Как написано в одном фундаментальном труде http://www.lib.ru/ANEKDOTY/non_pas.txt
    - поскольку в Фортране отсутствуют структурные операторы IF,
    REPEAT ... UNTIL или CASE, настоящим программистам не
    нужно беспокоиться, что они их не используют; кроме того
    эти операторы можно при необходимости симулировать с
    помощью присваиваемых GOTO.

    Пользуясь этой вселенской мудростью, а так же зная про наличие присваиваемых goto в gcc, решил я сей код написать.

    j123123, 28 Ноября 2015

    Комментарии (785)
  6. C++ / Говнокод #18139

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    typedef enum {
            INIT1=0, INIT2,  INIT3,  INIT4,  INIT5,  INIT6,  INITN,
            BIND1,   BIND2,  BIND3,  BIND4,  BIND5,  BIND6,  BINDN,
            YIELD1,  YIELD2, YIELD3, YIELD4, YIELD5, YIELD6, YIELDN, 
            COMPARE, CHECK, FILTER, CFILTER, PFILTER, CHOOSE, NOOP, CONTINUE,
            GET_ENODE, 
            GET_CGR1, GET_CGR2, GET_CGR3, GET_CGR4, GET_CGR5, GET_CGR6, GET_CGRN,
            IS_CGR
        } opcode;
    ...
    ...
    ...
    
    
    
            switch (m_pc->m_opcode) {
            case INIT1:
                m_app          = m_registers[0];
                if (m_app->get_num_args() != 1)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INIT2:
                m_app          = m_registers[0];
                if (m_app->get_num_args() != 2)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_registers[2] = m_app->get_arg(1);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INIT3:
                m_app          = m_registers[0];
                if (m_app->get_num_args() != 3)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_registers[2] = m_app->get_arg(1);
                m_registers[3] = m_app->get_arg(2);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INIT4:
                m_app          = m_registers[0];
                if (m_app->get_num_args() != 4)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_registers[2] = m_app->get_arg(1);
                m_registers[3] = m_app->get_arg(2);
                m_registers[4] = m_app->get_arg(3);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INIT5:
                m_app          = m_registers[0]; 
                if (m_app->get_num_args() != 5)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_registers[2] = m_app->get_arg(1);
                m_registers[3] = m_app->get_arg(2);
                m_registers[4] = m_app->get_arg(3);
                m_registers[5] = m_app->get_arg(4);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INIT6: 
                m_app          = m_registers[0];
                if (m_app->get_num_args() != 6)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_registers[2] = m_app->get_arg(1);
                m_registers[3] = m_app->get_arg(2);
                m_registers[4] = m_app->get_arg(3);
                m_registers[5] = m_app->get_arg(4);
                m_registers[6] = m_app->get_arg(5);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INITN:
                m_app      = m_registers[0];
                m_num_args = m_app->get_num_args();
                if (m_num_args != static_cast<const initn *>(m_pc)->m_num_args)
                    goto backtrack;
                for (unsigned i = 0; i < m_num_args; i++)
                    m_registers[i+1] = m_app->get_arg(i);
                m_pc = m_pc->m_next;
                goto main_loop;

    Из изходников STM-солвера Z3
    https://github.com/Z3Prover/z3/blob/master/src/smt/mam.cpp#L2298
    Почему нельзя было оставить только вариант INITN? Цикл отбирает так много ресурсов?

    j123123, 10 Мая 2015

    Комментарии (2)
  7. Си / Говнокод #18030

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    #include <inttypes.h>
    #include <stdio.h>
     
    typedef union
    {
      struct
      {
        #define BITG(n) uint8_t bit##n : 1
        BITG(0);
        BITG(1);
        BITG(2);
        BITG(3);
        BITG(4);
        BITG(5);
        BITG(6);
        BITG(7);
        #undef BITG
      } bits;
      uint8_t value;
    }getbit;
     
    uint8_t bit_sum(uint8_t, uint8_t);
     
     
    uint8_t bit_sum(uint8_t a, uint8_t b)
    {
      getbit op1, op2, opr;
      uint8_t carry;
      op1.value=a; op2.value=b;
      #define OP1(n) op1.bits.bit##n
      #define OP2(n) op2.bits.bit##n
      #define OPR(n) opr.bits.bit##n
      #define XOR(a,b) ((a)^(b))
      #define AND(a,b) ((a)&(b))
      OPR(0) = XOR(OP1(0), OP2(0));
      carry = AND(OP1(0), OP2(0));
      #define SETBIT(n)                \
      OPR(n) = XOR                     \
               (                       \
                 carry,                \
                 XOR(OP1(n), OP2(n))   \
               );
     
      #define CARRYBIT(n)              \
      carry = XOR                      \
              (                        \
                AND(OP1(n), OP2(n)),   \
                AND                    \
                (                      \
                  XOR(OP1(n), OP2(n)), \
                  carry                \
                )                      \
              );
      SETBIT(1);
      CARRYBIT(1);
      SETBIT(2);
      CARRYBIT(2);
      SETBIT(3);
      CARRYBIT(3);
      SETBIT(4);
      CARRYBIT(4);
      SETBIT(5);
      CARRYBIT(5);
      SETBIT(6);
      CARRYBIT(6);
      SETBIT(7);
      return opr.value;
      #undef SETBIT
      #undef CARRYBIT
      #undef OP1
      #undef OP2
      #undef OPR
      #undef XOR
      #undef AND
    }
     
    int main (int argc, char *argv[], char *envp[])
    {
      uint8_t a, b, c;
      scanf ("%"SCNu8"%"SCNu8, &a, &b);
      c = bit_sum(a,b);
      printf("%"PRIu8"\n", c);
      return 0;
    }

    Побитовое сложение двух 8-битных чисел по схеме двоичного сумматора

    j123123, 20 Апреля 2015

    Комментарии (11)
  8. Си / Говнокод #17978

    +138

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    if(argc > 6){
    	for(arg = argv[6]; strlen((char *)arg) >= 17 &&
    					isdigit(arg[0]) &&
    					isdigit(arg[1]) &&
    					isdigit(arg[3]) &&
    					isdigit(arg[4]) &&
    					isdigit(arg[6]) &&
    					isdigit(arg[7]) &&
    					isdigit(arg[9]) &&
    					isdigit(arg[10]) &&
    					isdigit(arg[12]) &&
    					isdigit(arg[13]) &&
    					isdigit(arg[15]) &&
    					isdigit(arg[16])
    					; arg+=18){
    
    		int t1, t2;
    		struct period *sp;
    
    		t1 = (arg[0] - '0') * 10 + (arg[1] - '0');
    		t1 = (t1 * 60) + (arg[3] - '0') * 10 + (arg[4] - '0');
    		t1 = (t1 * 60) + (arg[6] - '0') * 10 + (arg[7] - '0');
    		t2 = (arg[9] - '0') * 10 + (arg[10] - '0');
    		t2 = (t2 * 60) + (arg[12] - '0') * 10 + (arg[13] - '0');
    		t2 = (t2 * 60) + (arg[15] - '0') * 10 + (arg[16] - '0');
    		if(t2 < t1) break;
    		sp = myalloc(sizeof(struct period));
    		if(sp){
    			sp->fromtime = t1;
    			sp->totime = t2;
    			sp->next = acl->periods;
    			acl->periods = sp;
    		}
    		if(arg[17]!=',') break;
    	}
    }

    Получение временных диапазонов, из https://github.com/z3APA3A/3proxy/blob/devel/src/3proxy.c#L1470
    Основное говно в том, что нифига не проверяются входные данные т.е. секунд и минут может быть больше 59, а часов может быть больше 23. И проверку if(t2 < t1) лучше заменить на if(t2 <= t1)
    А еще там в том исходнике в качестве отступов используются и пробелы и табы. Вообще там очень много говнокода

    j123123, 12 Апреля 2015

    Комментарии (5)
  9. Си / Говнокод #17821

    +135

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    #include "mono-math.h"
    
    #ifndef HAVE_SIGNBIT
    
    int
    mono_signbit_float (float x)
    {
    	union { float f; int i; } u;
    
    	u.f = x;
    
    	return u.i < 0;
    }
    
    int
    mono_signbit_double (double x)
    {
    	union { double d; int i[2]; } u;
    
    	u.d = x;
    
    #if G_BYTE_ORDER == G_LITTLE_ENDIAN
    	return u.i [1] < 0;
    #else
    	return u.i [0] < 0;
    #endif
    }
    
    #endif

    Говно тут в том, что int далеко не везде будет 32 бит.
    https://github.com/mono/mono/blob/master/mono/utils/mono-math.c оттуда

    j123123, 19 Марта 2015

    Комментарии (5)
  10. Си / Говнокод #17804

    +138

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    #define poff    acurp + curp * (nSQs+2)        /*probs: offset*/
    long psum() {return  c(poff+ 1);}    long pmax()    {return c(poff+2);}
    long pn     (long n)                {return          c(poff+2+n);   }
    void setp   (long n, long x){set    (poff+2+n, x);} /*prob changes:*/ 
    void setmax         (long x){set    (poff+2,   x);} /*metasearching*/
    void setsum         (long x){set    (poff+1,   x);}
    long get2ndmax()    {long n= poff+2, x=pmax(), m=n,  s=0,end=n+nSQs;   
         do     {n++;}   while  (c(n) != x);  /*find 2nd-highest <=pmax*/     
         do     {m++;    if (s < c(m) && m !=n) s= c(m);}/*jue tncheck?*/
                 while      (s < x    && m < end);       return  s;}
    void addtoSQ(long i, long val) {long x;   /*increase prob of ith SQ*/
         if  (val < 1 || i >nSQs || i<1) return;        /*not possible!*/
         x =  psum()+val;if (x > maxint) return;   /*has max normalizer*/
         setsum (x);    /*normalizer +*/ x =  pn(i)+val; setp(i, x); 
         if (x > pmax()) setmax (x);}   /*maximal SQprob has increased */    
    void subofSQ(long i, long val) {long x;   /*decrease prob of ith SQ*/
         if  (val < 1 || i >nSQs || i<1) return;        /*not possible!*/
         x =  pn(i)-val; if (x < 0)      return;/*no neg probabilities!*/
         setsum (psum()- val);           setp(i,x);/*don't check if =0!*/   
         if (x + val  == pmax()) setmax (get2ndmax());} /*change of max*/
    void incSQ()        {long i= top();  addtoSQ(i,1);} /*top, not pop!*/
    void decSQ()        {long i= top(),  x,y,z; /*decrem prob of the SQ*/
         if  (i> nSQs   || i< 1) return;/*no such search Q number known*/
         x =  pn(i);     if     (x==0)   return;        /*SQ: already 0*/
         y  = psum();    z =     pmax();              
         if  (x == 1 &&  y    <= z+1)    stop    /*leave at least 2 SQs*/
         if  (x == z)    setmax         (get2ndmax());  /*change of max*/
         setp(i, x-1);   setsum (y-1);}                 /*normalizer -1*/
    long upSQ;          /*SQ probability:enumerator  +=  upSQ: increase*/
    void oldSQ()   {long a=pop()+ndecl,  n,i; if(a<0||a> oldp)stop/*bad*/
         n=old[a].size;  a=old[a].start;/*all SQs of old nondecl: +upSQ*/
         tncheck  n+=a;  for(i=a;i<n;i++)addtoSQ(SQ[q[i].Q],     upSQ);}
    
    void setpat()       {long i= pop(); /*instantiate my search pattern*/
         if  (i<0 || i > patp)     stop /*no such search pattern exists*/
         set (acurp,i);}/*next SQ-search defined via new probabilities!*/
    void pupat()        {long    i  =    apatp;   /*push search pattern*/ 
         if  (i>maxpat)  stop    i++;    set(apatp,i);  /*not too many?*/
         cpabn  (poff+1, acurp + 1 + i *(2+ nSQs),       2 + nSQs,  
                                         acurp + 1,      aendpats);     }  
    void popat()        {long i= apatp;  if(i==0)   stop
         set(apatp,i-1); push(i); }                /*pop search pattern*/

    Полный исходник http://www.idsia.ch/~juergen/oopscode.c

    j123123, 17 Марта 2015

    Комментарии (11)
  11. Си / Говнокод #16026

    +135

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    // Hammer the CFG with large numbers of overlapping variable scopes, which
    // implicit destructors triggered at each edge.
    
    #define EXPAND_BASIC_STRUCT(i) struct X##i { X##i(int); ~X##i(); };
    #define EXPAND_NORET_STRUCT(i) struct X##i { X##i(int); ~X##i() __attribute__((noreturn)); };
    EXPAND_BASIC_STRUCT(0000); EXPAND_NORET_STRUCT(0001);
    EXPAND_BASIC_STRUCT(0010); EXPAND_BASIC_STRUCT(0011);
    EXPAND_BASIC_STRUCT(0100); EXPAND_NORET_STRUCT(0101);
    EXPAND_NORET_STRUCT(0110); EXPAND_BASIC_STRUCT(0111);
    EXPAND_BASIC_STRUCT(1000); EXPAND_NORET_STRUCT(1001);
    EXPAND_BASIC_STRUCT(1010); EXPAND_BASIC_STRUCT(1011);
    EXPAND_NORET_STRUCT(1100); EXPAND_NORET_STRUCT(1101);
    EXPAND_BASIC_STRUCT(1110); EXPAND_BASIC_STRUCT(1111);
    
    #define EXPAND_2_VARS(c, i, x)  const X##i var_##c##_##i##0(x), &var_##c##_##i##1 = X##i(x)
    #define EXPAND_4_VARS(c, i, x)  EXPAND_2_VARS(c, i##0, x);  EXPAND_2_VARS(c, i##1, x)
    #define EXPAND_8_VARS(c, i, x)  EXPAND_4_VARS(c, i##0, x);  EXPAND_4_VARS(c, i##1, x)
    #define EXPAND_16_VARS(c, i, x) EXPAND_8_VARS(c, i##0, x);  EXPAND_8_VARS(c, i##1, x)
    #define EXPAND_32_VARS(c, x)    EXPAND_16_VARS(c, 0, x);    EXPAND_16_VARS(c, 1, x)
    
    #define EXPAND_2_INNER_CASES(i, x, y)    INNER_CASE(i, x, y);             INNER_CASE(i + 1, x, y);
    #define EXPAND_4_INNER_CASES(i, x, y)    EXPAND_2_INNER_CASES(i, x, y)    EXPAND_2_INNER_CASES(i + 2, x, y)
    #define EXPAND_8_INNER_CASES(i, x, y)    EXPAND_4_INNER_CASES(i, x, y)    EXPAND_4_INNER_CASES(i + 4, x, y)
    #define EXPAND_16_INNER_CASES(i, x, y)   EXPAND_8_INNER_CASES(i, x, y)    EXPAND_8_INNER_CASES(i + 8, x, y)
    #define EXPAND_32_INNER_CASES(i, x, y)   EXPAND_16_INNER_CASES(i, x, y)   EXPAND_16_INNER_CASES(i + 16, x, y)
    
    #define EXPAND_2_OUTER_CASES(i, x, y)    OUTER_CASE(i, x, y);             OUTER_CASE(i + 1, x, y);
    #define EXPAND_4_OUTER_CASES(i, x, y)    EXPAND_2_OUTER_CASES(i, x, y)    EXPAND_2_OUTER_CASES(i + 2, x, y)
    #define EXPAND_8_OUTER_CASES(i, x, y)    EXPAND_4_OUTER_CASES(i, x, y)    EXPAND_4_OUTER_CASES(i + 4, x, y)
    #define EXPAND_16_OUTER_CASES(i, x, y)   EXPAND_8_OUTER_CASES(i, x, y)    EXPAND_8_OUTER_CASES(i + 8, x, y)
    #define EXPAND_32_OUTER_CASES(i, x, y)   EXPAND_16_OUTER_CASES(i, x, y)   EXPAND_16_OUTER_CASES(i + 16, x, y)

    Рекурсивное (EXPAND_... ) макроговно из clang и генератор (EXPAND_..._STRUCT) структур через какую-то непонятную жопу
    https://github.com/llvm-mirror/clang/blob/master/INPUTS/cfg-nested-var-scopes.cpp

    j123123, 21 Мая 2014

    Комментарии (8)