yonghong-song added a comment.

For the first example, actually clang is smart enough to remove all dead code, 
so nothing generated.

[yhs@devbig003.ftw2 ~/tmp/ext_func_var]$ cat t1.c
extern void f1();
void f2(void *);
inline void f3() {

  f2(f1);

}
[yhs@devbig003.ftw2 ~/tmp/ext_func_var]$ clang -target bpf -g -S -emit-llvm t1.c
[yhs@devbig003.ftw2 ~/tmp/ext_func_var]$ cat t1.ll
; ModuleID = 't1.c'
source_filename = "t1.c"
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "bpf"

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang 
version 13.0.0 (https://github.com/llvm/llvm-project.git 
68275c77c92b89fafbacc31b4f40303bb9e0c9a7)", isOptimized: false, runtimeVersion: 
0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, 
nameTableKind: None)
!1 = !DIFile(filename: "t1.c", directory: "/home/yhs/tmp/ext_func_var")
!2 = !{}
!3 = !{i32 7, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 
68275c77c92b89fafbacc31b4f40303bb9e0c9a7)"}
[yhs@devbig003.ftw2 ~/tmp/ext_func_var]$

For the second example,

[yhs@devbig003.ftw2 ~/tmp/ext_func_var]$ cat t2.c                               
                                    
void f1();                                                                      
                                    
int main() {

  int x = sizeof(&f1);                                                          
                                    
  return x;                                                                     
                                    

}                                                                               
                                    
[yhs@devbig003.ftw2 ~/tmp/ext_func_var]$ clang -target bpf -g -S -emit-llvm 
t2.c                                    
[yhs@devbig003.ftw2 ~/tmp/ext_func_var]$ cat t2.ll                              
                                    
; ModuleID = 't2.c'                                                             
                                    
source_filename = "t2.c"                                                        
                                    
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"                 
                                    
target triple = "bpf"

                                      

; Function Attrs: noinline nounwind optnone                                     
                                    
define dso_local i32 @main() #0 !dbg !7 {                                       
                                    
entry:

  %retval = alloca i32, align 4                                                 
                                    
  %x = alloca i32, align 4                                                      
                                    
  store i32 0, i32* %retval, align 4                                            
                                    
  call void @llvm.dbg.declare(metadata i32* %x, metadata !11, metadata 
!DIExpression()), !dbg !12                   
  store i32 8, i32* %x, align 4, !dbg !12                                       
                                    
  %0 = load i32, i32* %x, align 4, !dbg !13                                     
                                    
  ret i32 %0, !dbg !14                                                          
                                    

}

; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1

attributes #0 = { noinline nounwind optnone "frame-pointer"="all" 
"min-legal-vector-width"="0" "no-trapping-math"="t
rue" "stack-protector-buffer-size"="8" }
attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang 
version 13.0.0 (https://github.com/ll
vm/llvm-project.git 68275c77c92b89fafbacc31b4f40303bb9e0c9a7)", isOptimized: 
false, runtimeVersion: 0, emissionKind:
 FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "t2.c", directory: "/home/yhs/tmp/ext_func_var")
!2 = !{}
!3 = !{i32 7, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 
68275c77c92b89fafbacc31b4f40303bb9e0c9a7)"}
!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 2, type: 
!8, scopeLine: 2, spFlags: DISPFlagDef
inition, unit: !0, retainedNodes: !2)
!8 = !DISubroutineType(types: !9)
!9 = !{!10}
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!11 = !DILocalVariable(name: "x", scope: !7, file: !1, line: 3, type: !10)
!12 = !DILocation(line: 3, column: 7, scope: !7)
!13 = !DILocation(line: 4, column: 10, scope: !7)
!14 = !DILocation(line: 4, column: 3, scope: !7)

The debuginfo for "f1" is not generated for case "sizeof(&f1);". I think it is 
okay in this case as in most cases, people wants debuginfo only if that pointer 
ptr appears in generated code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100567/new/

https://reviews.llvm.org/D100567

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to