llvm/llvm/test/tools/llvm-debuginfo-analyzer/WebAssembly/05-wasm-incorrect-lexical-scope-variable.test

; REQUIRES: webassembly-registered-target

; Test case 5 - Incorrect lexical scope variable.

; pr-43860.cpp
;  1  #include "definitions.h"
;  2  forceinline int InlineFunction(int Param) {
;  3    int Var_1 = Param;
;  4    {
;  5      int Var_2 = Param + Var_1;
;  6      Var_1 = Var_2;
;  7    }
;  8    return Var_1;
;  9  }
; 10
; 11  int test(int Param_1, int Param_2) {
; 12    int A = Param_1;
; 13    A += InlineFunction(Param_2);
; 14    return A;
; 15  }

; The above test is used to illustrate a variable issue found in the
; Clang compiler.
; PR43860: https://bugs.llvm.org/show_bug.cgi?id=43860
; PR43205: https://github.com/llvm/llvm-project/issues/43205

; In the following logical views, we can see that the DWARF debug
; information generated by the Clang compiler shows the variables
; 'Var_1' and 'Var_2' are at the same lexical scope (4) in the function
; 'InlineFuction'.
; The DWARF generated by GCC/Clang show those variables at the correct
; lexical scope: '3' and '4' respectively.

; RUN: llvm-mc -arch=wasm32 -filetype=obj \
; RUN:         %p/Inputs/pr-43860-clang.s -o %t.pr-43860-clang.o

; RUN: llvm-debuginfo-analyzer --attribute=level,format,producer \
; RUN:                         --output-sort=name \
; RUN:                         --print=symbols \
; RUN:                         %t.pr-43860-clang.o \
; RUN:                         %p/../DWARF/Inputs/pr-43860-dwarf-gcc.o 2>&1 | \
; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s

; ONE:      Logical View:
; ONE-NEXT: [000]           {File} '{{.*}}pr-43860-clang.o' -> WASM
; ONE-EMPTY:
; ONE-NEXT: [001]             {CompileUnit} 'pr-43860.cpp'
; ONE-NEXT: [002]               {Producer} 'clang version 19{{.*}}'
; ONE-NEXT: [002]     2         {Function} extern inlined 'InlineFunction' -> 'int'
; ONE-NEXT: [003]                 {Block}
; ONE-NEXT: [004]     5             {Variable} 'Var_2' -> 'int'
; ONE-NEXT: [003]     2           {Parameter} 'Param' -> 'int'
; ONE-NEXT: [003]     3           {Variable} 'Var_1' -> 'int'
; ONE-NEXT: [002]    11         {Function} extern not_inlined 'test' -> 'int'
; ONE-NEXT: [003]    12           {Variable} 'A' -> 'int'
; ONE-NEXT: [003]    13           {InlinedFunction} inlined 'InlineFunction' -> 'int'
; ONE-NEXT: [004]                   {Block}
; ONE-NEXT: [005]                     {Variable} 'Var_2' -> 'int'
; ONE-NEXT: [004]                   {Parameter} 'Param' -> 'int'
; ONE-NEXT: [004]                   {Variable} 'Var_1' -> 'int'
; ONE-NEXT: [003]    11           {Parameter} 'Param_1' -> 'int'
; ONE-NEXT: [003]    11           {Parameter} 'Param_2' -> 'int'
; ONE-EMPTY:
; ONE-NEXT: Logical View:
; ONE-NEXT: [000]           {File} 'pr-43860-dwarf-gcc.o' -> elf64-x86-64
; ONE-EMPTY:
; ONE-NEXT: [001]             {CompileUnit} 'pr-43860.cpp'
; ONE-NEXT: [002]               {Producer} 'GNU C++14 10.3.0 {{.*}}'
; ONE-NEXT: [002]     2         {Function} extern declared_inlined 'InlineFunction' -> 'int'
; ONE-NEXT: [003]                 {Block}
; ONE-NEXT: [004]     5             {Variable} 'Var_2' -> 'int'
; ONE-NEXT: [003]     2           {Parameter} 'Param' -> 'int'
; ONE-NEXT: [003]     3           {Variable} 'Var_1' -> 'int'
; ONE-NEXT: [002]    11         {Function} extern not_inlined 'test' -> 'int'
; ONE-NEXT: [003]    12           {Variable} 'A' -> 'int'
; ONE-NEXT: [003]    13           {InlinedFunction} declared_inlined 'InlineFunction' -> 'int'
; ONE-NEXT: [004]                   {Block}
; ONE-NEXT: [005]                     {Variable} 'Var_2' -> 'int'
; ONE-NEXT: [004]                   {Parameter} 'Param' -> 'int'
; ONE-NEXT: [004]                   {Variable} 'Var_1' -> 'int'
; ONE-NEXT: [003]    11           {Parameter} 'Param_1' -> 'int'
; ONE-NEXT: [003]    11           {Parameter} 'Param_2' -> 'int'

; Using the selection facilities, we can produce a simple tabular output
; showing just the logical elements that have in their name the 'var'
; pattern. The logical view is sorted by the variables name.

; RUN: llvm-debuginfo-analyzer --attribute=level,format \
; RUN:                         --output-sort=name \
; RUN:                         --select-regex --select-nocase \
; RUN:                         --select=Var \
; RUN:                         --report=list \
; RUN:                         --print=symbols \
; RUN:                         %t.pr-43860-clang.o \
; RUN:                         %p/../DWARF/Inputs/pr-43860-dwarf-gcc.o 2>&1 | \
; RUN: FileCheck --strict-whitespace -check-prefix=TWO %s

; TWO:      Logical View:
; TWO-NEXT: [000]           {File} '{{.*}}pr-43860-clang.o' -> WASM
; TWO-EMPTY:
; TWO-NEXT: [001]           {CompileUnit} 'pr-43860.cpp'
; TWO-NEXT: [004]           {Variable} 'Var_1' -> 'int'
; TWO-NEXT: [003]     3     {Variable} 'Var_1' -> 'int'
; TWO-NEXT: [005]           {Variable} 'Var_2' -> 'int'
; TWO-NEXT: [004]     5     {Variable} 'Var_2' -> 'int'
; TWO-EMPTY:
; TWO-NEXT: Logical View:
; TWO-NEXT: [000]           {File} 'pr-43860-dwarf-gcc.o' -> elf64-x86-64
; TWO-EMPTY:
; TWO-NEXT: [001]           {CompileUnit} 'pr-43860.cpp'
; TWO-NEXT: [004]           {Variable} 'Var_1' -> 'int'
; TWO-NEXT: [003]     3     {Variable} 'Var_1' -> 'int'
; TWO-NEXT: [005]           {Variable} 'Var_2' -> 'int'
; TWO-NEXT: [004]     5     {Variable} 'Var_2' -> 'int'