Skip to content

Commit

Permalink
[clang][DebugInfo][gmodules] Set runtimeLang on ObjC forward declarat…
Browse files Browse the repository at this point in the history
…ions

In Objective-C, forward declarations are currently represented as:
```
DW_TAG_structure_type
  DW_AT_name                ("Foo")
  DW_AT_declaration         (true)
  DW_AT_APPLE_runtime_class (DW_LANG_ObjC)
```
However, when compiling with `-gmodules`, when a class definition
is turned into a forward declaration within a `DW_TAG_module`, the
DIE for the forward declaration looks as follows:
```
DW_TAG_structure_type
  DW_AT_name                ("Foo")
  DW_AT_declaration         (true)
```

Note the absence of `DW_AT_APPLE_runtime_class`. With recent changes in
LLDB, not being able to differentiate between C++ and Objective-C
forward declarations has become problematic (see attached test-case
and explanation in llvm#119860).
  • Loading branch information
Michael137 committed Dec 16, 2024
1 parent 3769fcb commit 37b6714
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2995,20 +2995,22 @@ 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);
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 @@ -39,6 +39,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

0 comments on commit 37b6714

Please sign in to comment.