Skip to content

[clang][DebugInfo][gmodules] Set runtimeLang on ObjC forward declarations #9759

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2966,20 +2966,21 @@ llvm::DIType *CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
if (!ID)
return nullptr;

auto RuntimeLang =
static_cast<llvm::dwarf::SourceLanguage>(TheCU->getSourceLanguage());

// Return a forward declaration if this type was imported from a clang module,
// and this is not the compile unit with the implementation of the type (which
// may contain hidden ivars).
if (DebugTypeExtRefs && ID->isFromASTFile() && ID->getDefinition() &&
!ID->getImplementation())
return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
ID->getName(),
getDeclContextDescriptor(ID), Unit, 0);
return DBuilder.createForwardDecl(
llvm::dwarf::DW_TAG_structure_type, ID->getName(),
getDeclContextDescriptor(ID), Unit, 0, RuntimeLang);

// Get overall information about the record type for the debug info.
llvm::DIFile *DefUnit = getOrCreateFile(ID->getLocation());
unsigned Line = getLineNumber(ID->getLocation());
auto RuntimeLang =
static_cast<llvm::dwarf::SourceLanguage>(TheCU->getSourceLanguage());

// If this is just a forward declaration return a special forward-declaration
// debug type since we won't be able to lay out the entire type.
Expand Down
3 changes: 2 additions & 1 deletion clang/test/Modules/ExtDebugInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ int foo(ObjCClass *c) {

// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass",
// CHECK-SAME: scope: ![[MOD]],
// CHECK-SAME: flags: DIFlagFwdDecl)
// CHECK-SAME: flags: DIFlagFwdDecl,
// CHECK-SAME: runtimeLang: DW_LANG_ObjC)

// CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type,
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
Expand Down
1 change: 1 addition & 0 deletions clang/test/Modules/ModuleDebugInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "FwdDecl",
// CHECK-SAME: scope: ![[MODULE]],
// CHECK-SAME: runtimeLang: DW_LANG_ObjC

// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass",
// CHECK-SAME: scope: ![[MODULE]],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# REQUIRES: system-darwin

# Test that we can set a breakpoint in a method of a class extension.
# This requires us to parse the method into an AST type, and the context
# too (which in DWARF is just a forward declaration).
#
# RUN: split-file %s %t
# RUN: %clangxx_host %t/lib.m -c -g -gmodules -fmodules -o %t/lib.o
# RUN: %clangxx_host %t/main.m -g -gmodules -fmodules %t/lib.o -o %t/a.out -framework Foundation
#
# RUN: %lldb %t/a.out -o "breakpoint set -f lib.m -l 6" -o exit | FileCheck %s

# CHECK: (lldb) breakpoint set -f lib.m -l 6
# CHECK: Breakpoint 1: where = a.out`-[NSObject(Foo) func]

#--- main.m
int main() {
return 0;
}

#--- lib.m
#import <Foundation/Foundation.h>

@implementation NSObject (Foo)
- (NSError *)func {
NSLog(@"Hello, World!");
return 0;
}
@end

NSObject * func() {
return 0;
}