1; REQUIRES: x86-registered-target
2
3; Test case 5 - Incorrect lexical scope variable.
4
5; pr-43860.cpp
6;  1  #include "definitions.h"
7;  2  forceinline int InlineFunction(int Param) {
8;  3    int Var_1 = Param;
9;  4    {
10;  5      int Var_2 = Param + Var_1;
11;  6      Var_1 = Var_2;
12;  7    }
13;  8    return Var_1;
14;  9  }
15; 10
16; 11  int test(int Param_1, int Param_2) {
17; 12    int A = Param_1;
18; 13    A += InlineFunction(Param_2);
19; 14    return A;
20; 15  }
21
22; The above test is used to illustrate a variable issue found in the
23; Clang compiler.
24; PR43860: https://bugs.llvm.org/show_bug.cgi?id=43860
25; PR43205: https://github.com/llvm/llvm-project/issues/43205
26
27; In the following logical views, we can see that the DWARF debug
28; information generated by the Clang compiler shows the variables
29; 'Var_1' and 'Var_2' are at the same lexical scope (4) in the function
30; 'InlineFuction'.
31; The DWARF generated by GCC/Clang show those variables at the correct
32; lexical scope: '3' and '4' respectively.
33
34; RUN: llvm-debuginfo-analyzer --attribute=level,format,producer \
35; RUN:                         --output-sort=name \
36; RUN:                         --print=symbols \
37; RUN:                         %p/Inputs/pr-43860-dwarf-clang.o \
38; RUN:                         %p/Inputs/pr-43860-dwarf-gcc.o 2>&1 | \
39; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s
40
41; ONE:      Logical View:
42; ONE-NEXT: [000]           {File} 'pr-43860-dwarf-clang.o' -> elf64-x86-64
43; ONE-EMPTY:
44; ONE-NEXT: [001]             {CompileUnit} 'pr-43860.cpp'
45; ONE-NEXT: [002]               {Producer} 'clang version 15.0.0 {{.*}}'
46; ONE-NEXT: [002]     2         {Function} extern inlined 'InlineFunction' -> 'int'
47; ONE-NEXT: [003]                 {Block}
48; ONE-NEXT: [004]     5             {Variable} 'Var_2' -> 'int'
49; ONE-NEXT: [003]     2           {Parameter} 'Param' -> 'int'
50; ONE-NEXT: [003]     3           {Variable} 'Var_1' -> 'int'
51; ONE-NEXT: [002]    11         {Function} extern not_inlined 'test' -> 'int'
52; ONE-NEXT: [003]    12           {Variable} 'A' -> 'int'
53; ONE-NEXT: [003]    13           {InlinedFunction} inlined 'InlineFunction' -> 'int'
54; ONE-NEXT: [004]                   {Block}
55; ONE-NEXT: [005]                     {Variable} 'Var_2' -> 'int'
56; ONE-NEXT: [004]                   {Parameter} 'Param' -> 'int'
57; ONE-NEXT: [004]                   {Variable} 'Var_1' -> 'int'
58; ONE-NEXT: [003]    11           {Parameter} 'Param_1' -> 'int'
59; ONE-NEXT: [003]    11           {Parameter} 'Param_2' -> 'int'
60; ONE-EMPTY:
61; ONE-NEXT: Logical View:
62; ONE-NEXT: [000]           {File} 'pr-43860-dwarf-gcc.o' -> elf64-x86-64
63; ONE-EMPTY:
64; ONE-NEXT: [001]             {CompileUnit} 'pr-43860.cpp'
65; ONE-NEXT: [002]               {Producer} 'GNU C++14 10.3.0 {{.*}}'
66; ONE-NEXT: [002]     2         {Function} extern declared_inlined 'InlineFunction' -> 'int'
67; ONE-NEXT: [003]                 {Block}
68; ONE-NEXT: [004]     5             {Variable} 'Var_2' -> 'int'
69; ONE-NEXT: [003]     2           {Parameter} 'Param' -> 'int'
70; ONE-NEXT: [003]     3           {Variable} 'Var_1' -> 'int'
71; ONE-NEXT: [002]    11         {Function} extern not_inlined 'test' -> 'int'
72; ONE-NEXT: [003]    12           {Variable} 'A' -> 'int'
73; ONE-NEXT: [003]    13           {InlinedFunction} declared_inlined 'InlineFunction' -> 'int'
74; ONE-NEXT: [004]                   {Block}
75; ONE-NEXT: [005]                     {Variable} 'Var_2' -> 'int'
76; ONE-NEXT: [004]                   {Parameter} 'Param' -> 'int'
77; ONE-NEXT: [004]                   {Variable} 'Var_1' -> 'int'
78; ONE-NEXT: [003]    11           {Parameter} 'Param_1' -> 'int'
79; ONE-NEXT: [003]    11           {Parameter} 'Param_2' -> 'int'
80
81; Using the selection facilities, we can produce a simple tabular output
82; showing just the logical elements that have in their name the 'var'
83; pattern. The logical view is sorted by the variables name.
84
85; RUN: llvm-debuginfo-analyzer --attribute=level,format \
86; RUN:                         --output-sort=name \
87; RUN:                         --select-regex --select-nocase \
88; RUN:                         --select=Var \
89; RUN:                         --report=list \
90; RUN:                         --print=symbols \
91; RUN:                         %p/Inputs/pr-43860-*.o 2>&1 | \
92; RUN: FileCheck --strict-whitespace -check-prefix=TWO %s
93
94; TWO:      Logical View:
95; TWO-NEXT: [000]           {File} 'pr-43860-dwarf-clang.o' -> elf64-x86-64
96; TWO-EMPTY:
97; TWO-NEXT: [001]           {CompileUnit} 'pr-43860.cpp'
98; TWO-NEXT: [004]           {Variable} 'Var_1' -> 'int'
99; TWO-NEXT: [003]     3     {Variable} 'Var_1' -> 'int'
100; TWO-NEXT: [005]           {Variable} 'Var_2' -> 'int'
101; TWO-NEXT: [004]     5     {Variable} 'Var_2' -> 'int'
102; TWO-EMPTY:
103; TWO-NEXT: Logical View:
104; TWO-NEXT: [000]           {File} 'pr-43860-dwarf-gcc.o' -> elf64-x86-64
105; TWO-EMPTY:
106; TWO-NEXT: [001]           {CompileUnit} 'pr-43860.cpp'
107; TWO-NEXT: [004]           {Variable} 'Var_1' -> 'int'
108; TWO-NEXT: [003]     3     {Variable} 'Var_1' -> 'int'
109; TWO-NEXT: [005]           {Variable} 'Var_2' -> 'int'
110; TWO-NEXT: [004]     5     {Variable} 'Var_2' -> 'int'
111