1  /* Contributed by Dodji Seketeli <dodji@redhat.com>
       2     Origin: PR debug/37801
       3  
       4    Abstract instances (DW_TAG_subroutines having the DW_AT_inline attribute)
       5    of second and first were having a DW_TAG_lexical_block DIE wrongly
       6    representing the inlined calls to third (in second) and to
       7    second (in first). At the same time, main didn't have children
       8    DW_TAG_inlined_subroutine DIEs representing the inlined calls to
       9    first, second and third.
      10  
      11    The ideal goal here is to test that we have no superfluous
      12    DW_TAG_lexical_block DIE anymore, that abstract instances DIEs have
      13    no descendant DIE with a DW_AT_abstract_origin attribute, and that main has
      14    properly nested DW_TAG_inlined_subroutine DIEs for third, second and first.
      15  */
      16  
      17  /* Explicitly use dwarf-2 because dwarf-5 might use DW_FORM_implicit_const
      18     which is hard to scan for. */
      19  /* { dg-options "-O -g3 -gdwarf-2 -dA -fgnu89-inline" } */
      20  /* { dg-do compile } */
      21  
      22  /* There are 6 inlined subroutines:
      23     - One for each subroutine inlined into main, that's 3.
      24     - One for earch subroutine inline into the out of line instances
      25       of third, second and first.  */
      26  /* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) DW_TAG_inlined_subroutine" 6 } } */
      27  
      28  /* We should have no DW_TAG_lexical_block DIEs, all inline instances
      29     should have the first subblock elided to match the abstract instance
      30     layout.  */
      31  /* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) DW_TAG_lexical_block" 0 } } */
      32  
      33  
      34  /* There are 3 DW_AT_inline attributes: one per abstract inline instance.
      35     The value of the attribute must be 0x3, meaning the function was
      36     actually inlined.  */
      37  /* { dg-final { scan-assembler-times  "(?:byte|data1)\[^\n\]*0x3\[^\n\]* DW_AT_inline" 3 } } */
      38  
      39  volatile int *a;
      40  
      41  inline void
      42  third (int arg3)
      43  {
      44    int var3 = arg3;
      45    a[0] = var3;
      46  }
      47  
      48  inline void
      49  second (int arg2)
      50  {
      51    int var2 = arg2;
      52    third (var2+1);
      53  }
      54  
      55  inline void
      56  first (int arg1)
      57  {
      58    int var1 = arg1;
      59    second (var1+1);
      60  }
      61  
      62  int
      63  main ()
      64  {
      65    int some_int = 1;
      66    first (some_int);
      67    return 0;
      68  }
      69  
      70