1  /* { dg-do run } */
       2  /* { dg-options "-std=gnu99 -fno-lto -fno-toplevel-reorder" } */
       3  
       4  // No LTO for now due to PR lto/68384.
       5  
       6  #ifdef __AVR_TINY__
       7  unsigned char reg2;
       8  #else
       9  register unsigned char reg2 __asm("r2");
      10  #endif
      11  
      12  #include "../isr-test.h"
      13  
      14  #define SET_REG(reg,val)                        \
      15    do {                                          \
      16      reg = (val);                                \
      17      __asm __volatile__("" : "+r" (reg));        \
      18    } while (0)                                   \
      19  
      20  #define GET_REG(reg)                            \
      21    ({                                            \
      22      __asm __volatile__("" : "+r" (reg));        \
      23      reg;                                        \
      24    })
      25  
      26  /**********************************************************************/
      27  
      28  ISR (1, signal)
      29  {
      30    reg2++;
      31  }
      32  
      33  MK_RUN_ISR (1, 1ul << 2)
      34  
      35  void test1 (void)
      36  {
      37    SET_REG (reg2, 0);
      38    run_isr_1();
      39    if (GET_REG (reg2) != 1)
      40      __builtin_abort();
      41  }
      42  
      43  /**********************************************************************/
      44  
      45  __attribute__((noinline,noclone))
      46  void inc_r2 (void)
      47  {
      48    reg2++;
      49  }
      50  
      51  ISR (2, signal)
      52  {
      53    inc_r2 ();
      54  }
      55  
      56  MK_RUN_ISR (2, 1ul << 2)
      57  
      58  void test2 (void)
      59  {
      60    run_isr_2();
      61    if (GET_REG (reg2) != 2)
      62      __builtin_abort();
      63  }
      64  
      65  
      66  /**********************************************************************/
      67  
      68  ISR (3, signal)
      69  {
      70  #ifndef __AVR_TINY__
      71    register char r4 __asm ("r4");
      72    __asm __volatile ("inc %0" : "+r" (r4));
      73    __asm __volatile ("inc r5" ::: "r5");
      74  #endif
      75  }
      76  
      77  MK_RUN_ISR (3, 0)
      78  
      79  void test3 (void)
      80  {
      81    run_isr_3();
      82  }
      83  
      84  
      85  /**********************************************************************/
      86  
      87  #define CLOBB(reg)                                 \
      88    do {                                             \
      89      __asm __volatile__ ("inc " #reg ::: #reg);     \
      90    } while (0)
      91  
      92  ISR (4, signal)
      93  {
      94    char volatile v;
      95    v = 1;
      96  
      97  #ifndef __AVR_TINY__
      98    CLOBB (r3);
      99    CLOBB (r4);
     100    CLOBB (r5);
     101    CLOBB (r6);
     102    CLOBB (r7);
     103    CLOBB (r8);
     104    CLOBB (r9);
     105    CLOBB (r10);
     106    CLOBB (r11);
     107    CLOBB (r12);
     108    CLOBB (r13);
     109    CLOBB (r14);
     110    CLOBB (r15);
     111    CLOBB (r16);
     112    CLOBB (r17);
     113  #endif
     114  
     115    CLOBB (r18);
     116    CLOBB (r19);
     117    CLOBB (r20);
     118    CLOBB (r21);
     119    CLOBB (r22);
     120    CLOBB (r23);
     121    CLOBB (r24);
     122    CLOBB (r25);
     123    CLOBB (r26);
     124    CLOBB (r27);
     125    CLOBB (r30);
     126    CLOBB (r31);
     127  }
     128  
     129  MK_RUN_ISR (4, 0)
     130  
     131  void test4 (void)
     132  {
     133    run_isr_4();
     134  }
     135  
     136  
     137  /**********************************************************************/
     138  
     139  int main (void)
     140  {
     141    test1();
     142    test2();
     143    test3();
     144    test4();
     145    return 0;
     146  }