From 7c19ca2fbc0c804ea15d47d7249e60acd4a47e94 Mon Sep 17 00:00:00 2001 From: Ellis Hoag Date: Thu, 15 Aug 2024 16:35:18 -0700 Subject: [PATCH 1/2] [IRGen][DebugInfo] Emit declarations for CFunctionPointer reps --- lib/IRGen/IRGenDebugInfo.cpp | 1 + test/DebugInfo/method-declaration.swift | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 166578a784096..733a27433efa4 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -2971,6 +2971,7 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn, Rep == SILFunctionTypeRepresentation::ObjCMethod || Rep == SILFunctionTypeRepresentation::WitnessMethod || Rep == SILFunctionTypeRepresentation::CXXMethod || + Rep == SILFunctionTypeRepresentation::CFunctionPointer || Rep == SILFunctionTypeRepresentation::Thin)) { llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::toSPFlags( /*IsLocalToUnit=*/Fn ? Fn->hasInternalLinkage() : true, diff --git a/test/DebugInfo/method-declaration.swift b/test/DebugInfo/method-declaration.swift index b1fdb35d5dfa0..25e400475bf8c 100644 --- a/test/DebugInfo/method-declaration.swift +++ b/test/DebugInfo/method-declaration.swift @@ -1,4 +1,7 @@ -// RUN: %target-swift-frontend -primary-file %s -emit-ir -gdwarf-types -o - | %FileCheck %s +// RUN: %empty-directory(%t) +// RUN: split-file %s %t + +// RUN: %target-swift-frontend -primary-file %t/a.swift -import-objc-header %t/objc.h -enable-objc-interop -emit-ir -gdwarf-types -o - | %FileCheck %s // Verify that we added a declaration for a method. @@ -8,6 +11,7 @@ // CHECK: define{{.*}}bar_method{{.*}} !dbg ![[BAR_METHOD_DEF_DBG:[0-9]+]] // CHECK: define{{.*}}a_function{{.*}} !dbg ![[FUNC_DEF_DBG:[0-9]+]] +//--- a.swift // CHECK-DAG: ![[FOO_DBG:[0-9]+]] = !DICompositeType(tag: {{.*}} name: "Foo", {{.*}} identifier: public struct Foo { // CHECK-DAG: ![[FOO_STATIC_METHOD_DEF_DBG]] = distinct !DISubprogram(name: "foo_static_method"{{.*}}, scope: ![[FOO_DBG]]{{.*}}DISPFlagDefinition{{.*}}, declaration: ![[FOO_STATIC_METHOD_DECL_DBG:[0-9]+]] @@ -16,6 +20,13 @@ public struct Foo { // CHECK-DAG: ![[FOO_METHOD_DEF_DBG]] = distinct !DISubprogram(name: "foo_method"{{.*}}, scope: ![[FOO_DBG]]{{.*}}DISPFlagDefinition{{.*}}, declaration: ![[FOO_METHOD_DECL_DBG:[0-9]+]] // CHECK-DAG: ![[FOO_METHOD_DECL_DBG]] = !DISubprogram(name: "foo_method"{{.*}}, scope: ![[FOO_DBG]] func foo_method() {} + +// CHECK-DAG: !DISubprogram(linkageName: "$s1a3FooVACycfcyycfU_To" +// CHECK-SAME: scope: ![[FOO_DBG]] +// CHECK-SAME: declaration: ! + init() { + let _ = ObjCGoo(myVal:{}) + } } // CHECK-DAG: ![[BAR_DBG:[0-9]+]] = !DICompositeType(tag: {{.*}} name: "Bar", {{.*}} identifier: @@ -35,3 +46,7 @@ public class Bar { // CHECK-SAME: ) func a_function() {} +//--- objc.h +@interface ObjCGoo +- (instancetype)initWithMyVal:(void (*)())myVal; +@end From c8a64e145fdb8a784b8127d5ebe8102ee80d7b80 Mon Sep 17 00:00:00 2001 From: Ellis Hoag Date: Fri, 16 Aug 2024 12:49:07 -0700 Subject: [PATCH 2/2] Fix CHECK lines in test --- test/DebugInfo/method-declaration.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/DebugInfo/method-declaration.swift b/test/DebugInfo/method-declaration.swift index 25e400475bf8c..604f6f9eeaf9c 100644 --- a/test/DebugInfo/method-declaration.swift +++ b/test/DebugInfo/method-declaration.swift @@ -7,6 +7,7 @@ // CHECK: define{{.*}}foo_static_method{{.*}} !dbg ![[FOO_STATIC_METHOD_DEF_DBG:[0-9]+]] // CHECK: define{{.*}}foo_method{{.*}} !dbg ![[FOO_METHOD_DEF_DBG:[0-9]+]] +// CHECK: define{{.*}}s1a3FooVACycfcyycfU_To{{.*}} !dbg ![[COMPILER_GEN_METHOD_DEF_DBG:[0-9]+]] // CHECK: define{{.*}}bar_static_method{{.*}} !dbg ![[BAR_STATIC_METHOD_DEF_DBG:[0-9]+]] // CHECK: define{{.*}}bar_method{{.*}} !dbg ![[BAR_METHOD_DEF_DBG:[0-9]+]] // CHECK: define{{.*}}a_function{{.*}} !dbg ![[FUNC_DEF_DBG:[0-9]+]] @@ -20,10 +21,8 @@ public struct Foo { // CHECK-DAG: ![[FOO_METHOD_DEF_DBG]] = distinct !DISubprogram(name: "foo_method"{{.*}}, scope: ![[FOO_DBG]]{{.*}}DISPFlagDefinition{{.*}}, declaration: ![[FOO_METHOD_DECL_DBG:[0-9]+]] // CHECK-DAG: ![[FOO_METHOD_DECL_DBG]] = !DISubprogram(name: "foo_method"{{.*}}, scope: ![[FOO_DBG]] func foo_method() {} - -// CHECK-DAG: !DISubprogram(linkageName: "$s1a3FooVACycfcyycfU_To" -// CHECK-SAME: scope: ![[FOO_DBG]] -// CHECK-SAME: declaration: ! +// CHECK-DAG: ![[COMPILER_GEN_METHOD_DEF_DBG]] = distinct !DISubprogram(linkageName: "$s1a3FooVACycfcyycfU_To"{{.*}}, scope: ![[FOO_DBG]]{{.*}}DISPFlagDefinition{{.*}}, declaration: ![[COMPILER_GEN_METHOD_DECL_DBG:[0-9]+]] +// CHECK-DAG: ![[COMPILER_GEN_METHOD_DECL_DBG]] = !DISubprogram(linkageName: "$s1a3FooVACycfcyycfU_To"{{.*}}, scope: ![[FOO_DBG]] init() { let _ = ObjCGoo(myVal:{}) }