File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -754,14 +754,18 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
754
754
Offset %= EltSize;
755
755
} else if (auto StructTy = Ty.dyn_cast <mlir::cir::StructType>()) {
756
756
auto Elts = StructTy.getMembers ();
757
+ unsigned Pos = 0 ;
757
758
for (size_t I = 0 ; I < Elts.size (); ++I) {
758
759
auto EltSize = Layout.getTypeAllocSize (Elts[I]);
759
- if (Offset < EltSize) {
760
+ unsigned AlignMask = Layout.getABITypeAlign (Elts[I]) - 1 ;
761
+ Pos = (Pos + AlignMask) & ~AlignMask;
762
+ if (Offset < Pos + EltSize) {
760
763
Indices.push_back (I);
761
764
SubType = Elts[I];
765
+ Offset -= Pos;
762
766
break ;
763
767
}
764
- Offset - = EltSize;
768
+ Pos + = EltSize;
765
769
}
766
770
} else {
767
771
llvm_unreachable (" unexpected type" );
Original file line number Diff line number Diff line change @@ -83,6 +83,15 @@ int foo() {
83
83
// CHECK: cir.func {{.*@foo}}
84
84
// CHECK: {{.*}} = cir.get_global @optind : cir.ptr <!s32i>
85
85
86
+ struct Glob {
87
+ double a [42 ];
88
+ int pad1 [3 ];
89
+ double b [42 ];
90
+ } glob ;
91
+
92
+ double * const glob_ptr = & glob .b [1 ];
93
+ // CHECK: cir.global external @glob_ptr = #cir.global_view<@glob, [2 : i32, 1 : i32]> : !cir.ptr<f64>
94
+
86
95
// TODO: test tentatives with internal linkage.
87
96
88
97
// Tentative definition is THE definition. Should be zero-initialized.
You can’t perform that action at this time.
0 commit comments