Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug information shows incorrect lexical scope for typedef. #44229

Open
CarlosAlbertoEnciso opened this issue Feb 12, 2020 · 2 comments
Open
Labels
bugzilla Issues migrated from bugzilla debuginfo

Comments

@CarlosAlbertoEnciso
Copy link
Member

Bugzilla Link 44884
Version trunk
OS All
CC @dwblaikie,@gregbedwell,@JDevlieghere,@jmorse,@walkerkd,@OCHyams,@pogo59

Extended Description

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).

@CarlosAlbertoEnciso
Copy link
Member Author

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.

@CarlosAlbertoEnciso
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla debuginfo
Projects
None yet
Development

No branches or pull requests

1 participant