-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LLVM] Create lf_alias
nodes for typedef
and using
#153936
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
Open
Walnut356
wants to merge
4
commits into
llvm:main
Choose a base branch
from
Walnut356:create_lf_alias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
; ModuleID = 'typedef.cpp' | ||
source_filename = "typedef.cpp" | ||
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-pc-windows-msvc19.44.35214" | ||
|
||
; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable | ||
define dso_local noundef i32 @main() #0 !dbg !14 { | ||
entry: | ||
%retval = alloca i32, align 4 | ||
%val = alloca i8, align 1 | ||
%val2 = alloca i64, align 8 | ||
store i32 0, ptr %retval, align 4 | ||
#dbg_declare(ptr %val, !19, !DIExpression(), !22) | ||
store i8 15, ptr %val, align 1, !dbg !22 | ||
#dbg_declare(ptr %val2, !23, !DIExpression(), !26) | ||
store i64 -1, ptr %val2, align 8, !dbg !26 | ||
ret i32 0, !dbg !27 | ||
} | ||
|
||
attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } | ||
|
||
!llvm.dbg.cu = !{!2} | ||
!llvm.module.flags = !{!7, !8} | ||
!llvm.ident = !{!13} | ||
|
||
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !5, producer: "clang version 22.0.0git (https://github.com/Walnut356/llvm-project.git 0e257f7d7edfcda5655eeaac55d0ffc398e773a2)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) | ||
!5 = !DIFile(filename: "typedef.cpp", directory: "llvm-project") | ||
!7 = !{i32 2, !"CodeView", i32 1} | ||
!8 = !{i32 2, !"Debug Info Version", i32 3} | ||
!13 = !{!"clang version 22.0.0git (https://github.com/Walnut356/llvm-project.git 0e257f7d7edfcda5655eeaac55d0ffc398e773a2)"} | ||
!14 = distinct !DISubprogram(name: "main", scope: !5, file: !5, line: 6, type: !15, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2) | ||
!15 = !DISubroutineType(types: !16) | ||
!16 = !{!17} | ||
!17 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) | ||
!19 = !DILocalVariable(name: "val", scope: !14, file: !5, line: 7, type: !20) | ||
!20 = !DIDerivedType(tag: DW_TAG_typedef, name: "u8", file: !5, line: 3, baseType: !21) | ||
!21 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char) | ||
!22 = !DILocation(line: 7, scope: !14) | ||
!23 = !DILocalVariable(name: "val2", scope: !14, file: !5, line: 8, type: !24) | ||
!24 = !DIDerivedType(tag: DW_TAG_typedef, name: "i64", file: !5, line: 4, baseType: !25) | ||
!25 = !DIBasicType(name: "long long", size: 64, encoding: DW_ATE_signed) | ||
!26 = !DILocation(line: 8, scope: !14) | ||
!27 = !DILocation(line: 10, scope: !14) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
TpiStream: | ||
Records: | ||
- Kind: LF_ALIAS | ||
Alias: | ||
UnderlyingType: 32 | ||
Name: u8 | ||
- Kind: LF_ALIAS | ||
Alias: | ||
UnderlyingType: 19 | ||
Name: i64 | ||
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
Built with clang (22+) because MSVC does not output lf_alias for typedefs | ||
|
||
Build typedef.ll with clang -S -emit-llvm -g: | ||
|
||
``` | ||
void *__purecall = 0; | ||
|
||
typedef unsigned char u8; | ||
using i64 = long long; | ||
|
||
int main() { | ||
u8 val = 15; | ||
i64 val2 = -1; | ||
|
||
return 0; | ||
} | ||
``` | ||
|
||
RUN: llc -O0 %p/Inputs/typedef.ll --filetype=obj -o %t.obj | ||
RUN: llvm-pdbutil dump --types %t.obj | FileCheck --check-prefix=OBJTYPE %s | ||
|
||
OBJTYPE: 0x1003 | LF_ALIAS [size = 12] alias = u8, underlying type = 0x0020 (unsigned char) | ||
OBJTYPE-NEXT: 0x1004 | LF_ALIAS [size = 12] alias = i64, underlying type = 0x0013 (__int64) | ||
|
||
RUN: llvm-pdbutil dump --symbols %t.obj | FileCheck --check-prefix=OBJSYM %s | ||
|
||
OBJSYM: 0 | S_LOCAL [size = 16] `val` | ||
OBJSYM-NEXT: type=0x1003 (u8), flags = none | ||
OBJSYM: 0 | S_LOCAL [size = 16] `val2` | ||
OBJSYM: type=0x1004 (i64), flags = none | ||
OBJSYM: 0 | S_UDT [size = 12] `u8` | ||
OBJSYM-NEXT: original type = 0x1003 | ||
OBJSYM-NEXT: 0 | S_UDT [size = 12] `i64` | ||
OBJSYM-NEXT: original type = 0x1004 | ||
|
||
|
||
typedef.yaml file generated via `clang -fno-rtti -g -O0 typedef.cpp` and `llvm-pdbutil pdb2yaml -tpi-stream`, and then manually | ||
reduced to only the typedef nodes | ||
|
||
RUN: llvm-pdbutil yaml2pdb -pdb=%t.yaml.pdb %p/Inputs/typedef.yaml | ||
RUN: llvm-pdbutil dump --types %t.yaml.pdb \ | ||
RUN: | FileCheck --check-prefix=TYPES %s | ||
|
||
Also check that the YAML output hasn't drifted | ||
RUN: llvm-pdbutil pdb2yaml -tpi-stream %t.yaml.pdb \ | ||
RUN: | FileCheck --check-prefixes=YAML %s | ||
|
||
TYPES: Types (TPI Stream) | ||
TYPES-NEXT:============================================================ | ||
TYPES-NEXT: Showing 2 records | ||
TYPES-NEXT: 0x1000 | LF_ALIAS [size = 12] alias = u8, underlying type = 0x0020 (unsigned char) | ||
TYPES-NEXT: 0x1001 | LF_ALIAS [size = 12] alias = i64, underlying type = 0x0013 (__int64) | ||
|
||
|
||
YAML: - Kind: LF_ALIAS | ||
YAML-NEXT: Alias: | ||
YAML-NEXT: UnderlyingType: 32 | ||
YAML-NEXT: Name: u8 | ||
YAML-NEXT: - Kind: LF_ALIAS | ||
YAML-NEXT: Alias: | ||
YAML-NEXT: UnderlyingType: 19 | ||
YAML-NEXT: Name: i64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so, I would dig around in the yaml tests for an example to add to.