Skip to content

Commit 62d6ff5

Browse files
committed
[dsymutil] Track incompleteness across unions
When determining the incompleteness of a DIE based on its children, make sure we propagate it across union types. See test case for an example. Without this patch we never emit the definition of Container_ivars. Differential revision: https://reviews.llvm.org/D110443
1 parent 1422fa5 commit 62d6ff5

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ static void updateChildIncompleteness(const DWARFDie &Die, CompileUnit &CU,
549549
switch (Die.getTag()) {
550550
case dwarf::DW_TAG_structure_type:
551551
case dwarf::DW_TAG_class_type:
552+
case dwarf::DW_TAG_union_type:
552553
break;
553554
default:
554555
return;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Test binaries created with the following commands:
2+
3+
$ cat container.cpp
4+
#include "container.h"
5+
#include <stdlib.h>
6+
7+
struct Container_ivars {
8+
// real definition here
9+
};
10+
11+
ContainerPtr allocateContainer() {
12+
Container *c = (Container *)malloc(sizeof(Container));
13+
c->ivars = (Container_ivars *)malloc(sizeof(Container_ivars));
14+
return c;
15+
}
16+
17+
extern void doSomething(ContainerPtr);
18+
19+
int main() {
20+
ContainerPtr c = allocateContainer();
21+
doSomething(c);
22+
return 0;
23+
}
24+
25+
$ cat container.h
26+
struct Container_ivars;
27+
28+
struct Container {
29+
union {
30+
struct Container_ivars *ivars;
31+
};
32+
};
33+
34+
typedef Container *ContainerPtr;
35+
36+
$ cat use.cpp
37+
#include "container.h"
38+
39+
void doSomething(ContainerPtr c) {}
40+
41+
42+
$ clang++ -O0 -g container.cpp -c -o container.o
43+
$ clang++ -O0 -g use.cpp -c -o use.o
44+
$ clang++ use.o container.o -o a.out
45+
46+
Note that the link order in the last command matters for this test.
47+
48+
RUN: dsymutil -oso-prepend-path %p/../Inputs %p/../Inputs/private/tmp/union/a.out -o %t.dSYM
49+
RUN: llvm-dwarfdump %t.dSYM | FileCheck %s
50+
51+
CHECK: DW_TAG_compile_unit
52+
53+
CHECK: DW_AT_name ("Container_ivars")
54+
CHECK-NEXT: DW_AT_declaration (true)
55+
56+
CHECK: DW_TAG_compile_unit
57+
58+
CHECK: DW_AT_name ("Container_ivars")
59+
CHECK-NEXT: DW_AT_byte_size (0x01)
60+
CHECK-NEXT: DW_AT_decl_file ("/tmp/union/container.cpp")
61+
CHECK-NEXT: DW_AT_decl_line (4)

0 commit comments

Comments
 (0)