Commit 6ef0921
authored
[CIR] support union without field in C++ (#1703)
In [libstdc++ std::variant
implementation](https://github.com/gcc-mirror/gcc/blob/b0419798447ae25de2f58d1a695db6dadb5d8547/libstdc%2B%2B-v3/include/std/variant#L387-L394),
union without any fields is used.
According to current CodeGen logic, append 1 byte padding for this kind
of union.
Handle this union in `mlir::RecordType` for getLargestMember` return
nullptr also.
The original LLVM IR
```llvm
%union.EmptyUnion = type { i8 }
@__const._Z2f0v.e = private unnamed_addr constant %union.EmptyUnion undef, align 1
define dso_local void @_Z2f0v() #0 {
entry:
%e = alloca %union.EmptyUnion, align 1
call void @llvm.memcpy.p0.p0.i64(ptr align 1 %e, ptr align 1 @__const._Z2f0v.e, i64 1, i1 false)
ret void
}
```
The CIR lowered LLVM IR
```llvm
%union.EmptyUnion = type { i8 }
define dso_local void @_Z2f0v() #0 {
%1 = alloca %union.EmptyUnion, i64 1, align 1
store %union.EmptyUnion undef, ptr %1, align 1
ret void
}
```
The major different is original use global const and memcpy, the current
use store. The difference between the two is not related to this
revision.1 parent 4820d60 commit 6ef0921
File tree
3 files changed
+30
-4
lines changed- clang
- lib/CIR
- CodeGen
- Dialect/IR
- test/CIR/CodeGen
3 files changed
+30
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
367 | | - | |
| 367 | + | |
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
453 | 453 | | |
454 | 454 | | |
455 | 455 | | |
456 | | - | |
457 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
458 | 459 | | |
459 | 460 | | |
460 | 461 | | |
| |||
517 | 518 | | |
518 | 519 | | |
519 | 520 | | |
520 | | - | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
521 | 525 | | |
522 | 526 | | |
523 | 527 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
0 commit comments