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