llvm-project/clang/test/Modules/ModuleDebugInfo.m
Michael Buch 9fc54c0e80
[clang][DebugInfo][gmodules] Set runtimeLang on ObjC forward declarations (#120154)
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 https://github.com/llvm/llvm-project/pull/119860).
2024-12-17 16:40:10 +00:00

89 lines
3.3 KiB
Objective-C

// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
// Test that debug info is emitted for an Objective-C module and
// a precompiled header.
// REQUIRES: asserts
// Modules:
// RUN: rm -rf %t
// RUN: %clang_cc1 -x objective-c -fmodules -fmodule-format=obj \
// RUN: -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s \
// RUN: -I %S/Inputs -I %t -emit-llvm -o %t.ll \
// RUN: -mllvm -debug-only=pchcontainer &>%t-mod.ll
// RUN: cat %t-mod.ll | FileCheck %s
// RUN: cat %t-mod.ll | FileCheck %s --check-prefix=CHECK2
// PCH:
// RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs \
// RUN: -o %t.pch %S/Inputs/DebugObjC.h \
// RUN: -mllvm -debug-only=pchcontainer &>%t-pch.ll
// RUN: cat %t-pch.ll | FileCheck %s
// RUN: cat %t-pch.ll | FileCheck %s --check-prefix=CHECK2
#ifdef MODULES
@import DebugObjC;
#endif
// CHECK: distinct !DICompileUnit(language: DW_LANG_ObjC, file: ![[FILE:[0-9]+]],
// CHECK-SAME: isOptimized: false
// CHECK: ![[FILE]] = !DIFile(filename: "{{DebugObjC|.*DebugObjC.h}}"
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
// CHECK-SAME: scope: ![[MODULE:[0-9]+]],
// CHECK: ![[MODULE]] = !DIModule(scope: null, name: "DebugObjC
// CHECK: ![[TD_ENUM:.*]] = !DICompositeType(tag: DW_TAG_enumeration_type,
// CHECK-NOT: name:
// CHECK-SAME: elements:
// 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]],
// CHECK-SAME: elements
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClassWithPrivateIVars",
// CHECK-SAME: scope: ![[MODULE]],
// CHECK-SAME: elements
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "FwdDeclared"
// CHECK-SAME: elements:
// CHECK: ![[TD_UNION:.*]] = distinct !DICompositeType(tag: DW_TAG_union_type,
// CHECK-NOT: name:
// CHECK-SAME: elements:
// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefUnion",
// CHECK-SAME: baseType: ![[TD_UNION]])
// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefEnum",
// CHECK-SAME: baseType: ![[TD_ENUM:.*]])
// CHECK: ![[TD_STRUCT:.*]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
// CHECK-NOT: name:
// CHECK-SAME: elements:
// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefStruct",
// CHECK-SAME: baseType: ![[TD_STRUCT]])
// CHECK: !DICompositeType(tag: DW_TAG_union_type,
// CHECK-NOT: name:
// CHECK-SAME: )
// CHECK: !DICompositeType(tag: DW_TAG_structure_type,
// CHECK-NOT: name:
// CHECK-SAME: )
// CHECK-NEG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "PureForwardDecl"
// The output order is sublty different for module vs. pch,
// so these are checked separately:
//
// CHECK2: !DICompositeType(tag: DW_TAG_structure_type, name: "FwdDecl",
// CHECK2: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass",
// CHECK2: !DIObjCProperty(name: "property",
// CHECK2: !DIDerivedType(tag: DW_TAG_member, name: "ivar"
// CHECK2: !DIDerivedType(tag: DW_TAG_typedef, name: "InnerEnum"