(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
sparc/
attr-aligned.c
       1  /* Verify that valid alignment on functions is accepted and results
       2     in the alignment expected for the target and that alignment of
       3     zero is ignored with a warning.
       4     { dg-do compile }
       5     { dg-options "-Wno-pedantic -ftrack-macro-expansion=0" }  */
       6  
       7  #define ASSERT(expr)     _Static_assert (expr, #expr)
       8  #define ALIGN(n)         __attribute__ ((aligned (n)))
       9  #define alignof(expr)    __alignof__ (expr)
      10  #define HAS_ALIGN(f, n)  __builtin_has_attribute (f, __aligned__ (n))
      11  
      12  #define MINALIGN(N)   ((N) < 4 ? 4 : (N))
      13  #if defined(__sparcv9) || defined(__arch64__)
      14  #define MAXALIGN      16
      15  #else
      16  #define MAXALIGN      8
      17  #endif
      18  
      19  /* No alignment specified.  */
      20  void f (void) { }
      21  
      22  /* Empty alignment means maximum.  */
      23  ALIGN () void f_ (void) { }
      24  
      25  ALIGN (0) void f0 (void) { }    /* { dg-warning "requested alignment .0. is not a positive power of 2" } */
      26  ALIGN (1) void f1 (void) { }
      27  ALIGN (2) void f2 (void) { }
      28  ALIGN (4) void f4 (void) { }
      29  ALIGN (8) void f8 (void) { }
      30  ALIGN (16) void f16 (void) { }
      31  ALIGN (32) void f32 (void) { }
      32  
      33  ASSERT (alignof (f_) == MAXALIGN);
      34  ASSERT (alignof (f0) == alignof (f));
      35  ASSERT (alignof (f1) == MINALIGN (1));
      36  ASSERT (alignof (f2) == MINALIGN (2));
      37  ASSERT (alignof (f4) == MINALIGN (4));
      38  ASSERT (alignof (f8) == MINALIGN (8));
      39  ASSERT (alignof (f16) == MINALIGN (16));
      40  ASSERT (alignof (f32) == MINALIGN (32));
      41  
      42  ASSERT (!__builtin_has_attribute (f, aligned));
      43  ASSERT (__builtin_has_attribute (f_, aligned));
      44  ASSERT (!__builtin_has_attribute (f0, aligned));
      45  
      46  ASSERT (!HAS_ALIGN (f_, MAXALIGN));
      47  
      48  ASSERT (HAS_ALIGN (f1, 1));
      49  ASSERT (!HAS_ALIGN (f1, 2));
      50  
      51  ASSERT (!HAS_ALIGN (f2, 1));
      52  ASSERT (HAS_ALIGN (f2, 2));
      53  ASSERT (!HAS_ALIGN (f2, 4));
      54  
      55  ASSERT (!HAS_ALIGN (f4, 2));
      56  ASSERT (HAS_ALIGN (f4, 4));
      57  ASSERT (!HAS_ALIGN (f4, 8));
      58  
      59  ASSERT (!HAS_ALIGN (f8, 4));
      60  ASSERT (HAS_ALIGN (f8, 8));
      61  ASSERT (!HAS_ALIGN (f8, 16));
      62  
      63  ASSERT (!HAS_ALIGN (f16, 8));
      64  ASSERT (HAS_ALIGN (f16, 16));
      65  ASSERT (!HAS_ALIGN (f16, 32));
      66  
      67  ASSERT (!HAS_ALIGN (f32, 16));
      68  ASSERT (HAS_ALIGN (f32, 32));
      69  ASSERT (!HAS_ALIGN (f32, 64));