LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 44884 - Debug information shows incorrect lexical scope for typedef.
Summary: Debug information shows incorrect lexical scope for typedef.
Status: NEW
Alias: None
Product: libraries
Classification: Unclassified
Component: DebugInfo (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-12 05:18 PST by Carlos Alberto Enciso
Modified: 2020-02-12 05:32 PST (History)
8 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Alberto Enciso 2020-02-12 05:18:16 PST
Given the following test case:

//------------------------------------------------------------
// typedef.cpp
//------------------------------------------------------------

int bar(float Input) { return (int)Input; }

unsigned foo(char Param) {
  typedef int INT;
  INT Value = Param;
  {
    typedef float FLOAT;
    {
      FLOAT Added = Value + Param;
      Value = bar(Added);
    }
  }
  return Value + Param;
}

//------------------------------------------------------------

Using the following command line options to generate debug info
(DWARF) and (COFF):

clang -c -g -O0 typedef.cpp -o typedef.o
clang -c -g -O0 typedef.cpp -o typedef-coff.o -gcodeview --target=x86_64-windows

Looking at the output generated by llvm-dwarfdump and llvm-diva,
the debug info shows the typedefs 'INT'and 'FLOAT' to be at the same lexical scope (function scope).
Comment 1 Carlos Alberto Enciso 2020-02-12 05:26:56 PST
Using llvm-diva with the following command:

llvm-diva --print=scopes,types --attribute=level,format typedef.o typedef-coff.o

Logical View:
[000]           {File} 'typedef.o' -> ELF64-x86-64

[001]             {CompileUnit} 'typedef.cpp'
[002]     1         {Function} extern not_inlined 'bar' -> 'int'
[002]     3         {Function} extern not_inlined 'foo' -> 'unsigned int'
[003]                 {Block} 
[003]     4           {TypeAlias} 'INT' -> 'int'
[003]     7           {TypeAlias} 'FLOAT' -> 'float'

Logical View:
[000]           {File} 'typedef-coff.o' -> COFF-x86-64

[001]             {CompileUnit} 'typedef.cpp'
[002]               {Function} not_inlined 'bar' -> 'int'
[002]               {Function} not_inlined 'foo' -> 'unsigned'
[003]                 {Block} 
[002]               {Namespace} 'foo'
[003]                 {TypeAlias} 'FLOAT' -> 'float'
[003]                 {TypeAlias} 'INT' -> 'int'

Both outputs shows 'FLOAT' and 'INT' at level 3, which is incorrect.
Comment 2 Carlos Alberto Enciso 2020-02-12 05:32:05 PST
Now using GCC with the following line:

gcc -c -g -O0 typedef.cpp -o typedef-gcc.o

the output generated by llvm-diva is:

Logical View:
[000]           {File} 'typedef-gcc.o' -> ELF64-x86-64

[001]             {CompileUnit} 'typedef.cpp'
[002]     1         {Function} extern not_inlined 'bar' -> 'int'
[002]     3         {Function} extern not_inlined 'foo' -> 'unsigned int'
[003]                 {Block} 
[004]                   {Block} 
[004]     7             {TypeAlias} 'FLOAT' -> 'float'
[003]     4           {TypeAlias} 'INT' -> 'int'

It shows:

'INT' at level (3) (Function scope).
'FLOAT' at level (4) (Lexical scope).

which is correct.