(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
avr/
torture/
tiny-progmem.c
       1  /* { dg-do run } */
       2  /* { dg-options "-Wl,--defsym,test6_xdata=0" } */
       3  
       4  #ifdef __AVR_TINY__
       5  #define PM __attribute__((__progmem__))
       6  #else
       7  /* On general core, just resort to vanilla C. */
       8  #define PM /* Empty */
       9  #endif
      10  
      11  #define PSTR(s) (__extension__({ static const char __c[] PM = (s); &__c[0];}))
      12  
      13  #define NI __attribute__((noinline,noclone))
      14  
      15  const volatile int data[] PM = { 1234, 5678 };
      16  const volatile int * volatile pdata = &data[1];
      17  
      18  int ram[2];
      19  
      20  const int myvar PM = 42;
      21  extern const int xvar __asm ("myvar") PM;
      22  
      23  NI int const volatile* get_addr_1 (void)
      24  {
      25    return &data[1];
      26  }
      27  
      28  NI int const volatile* get_addr_x (int x)
      29  {
      30    return &data[x];
      31  }
      32  
      33  void test_1 (void)
      34  {
      35    if (data[0] != 1234)
      36      __builtin_abort();
      37  
      38    if (data[1] != 5678)
      39      __builtin_abort();
      40  }
      41  
      42  void test_2 (void)
      43  {
      44    if (data[1] != 5678)
      45      __builtin_abort();
      46  }
      47  
      48  void test_3 (void)
      49  {
      50    if (&data[1] != pdata)
      51      __builtin_abort();
      52  }
      53  
      54  void test_4 (void)
      55  {
      56    if (5678 != *get_addr_1())
      57      __builtin_abort();
      58    if (5678 != *get_addr_x(1))
      59      __builtin_abort();
      60  }
      61  
      62  void test_5 (void)
      63  {
      64    __builtin_memcpy (&ram, (void*) &data, 4);
      65    if (ram[0] - ram[1] != 1234 - 5678)
      66      __builtin_abort();
      67  }
      68  
      69  const char pmSTR[] PM = "01234";
      70  
      71  NI const char* get_pmSTR (int i)
      72  {
      73    return pmSTR + 2 + i;
      74  }
      75  
      76  void test_6 (void)
      77  {
      78  #ifdef __AVR_TINY__
      79    extern const int test6_xdata PM;
      80    const char* str = PSTR ("Hallo");
      81    if (0 == (__AVR_TINY_PM_BASE_ADDRESS__ & (__UINTPTR_TYPE__) str))
      82      __builtin_abort();
      83    if (0 == (__AVR_TINY_PM_BASE_ADDRESS__ & (__UINTPTR_TYPE__) test6_xdata))
      84      __builtin_abort();
      85  #endif
      86    
      87    if (get_pmSTR (0)[0] != '0' + 2)
      88      __builtin_abort();
      89    if (get_pmSTR (1)[0] != '1' + 2)
      90      __builtin_abort();
      91  }
      92  
      93  void test_7 (void)
      94  {
      95    if (xvar != 42)
      96      __builtin_abort();
      97  }
      98  
      99  int main()
     100  {
     101    test_1();
     102    test_2();
     103    test_3();
     104    test_4();
     105    test_5();
     106    test_6();
     107    test_7();
     108    return 0;
     109  }