@@ -303,8 +303,6 @@ struct TldVar {
303
303
Tld base;
304
304
305
305
VariableTableEntry *var;
306
- AstNode *set_global_align_node;
307
- uint32_t alignment;
308
306
AstNode *set_global_section_node;
309
307
Buf *section_name;
310
308
AstNode *set_global_linkage_node;
@@ -358,6 +356,7 @@ enum NodeType {
358
356
NodeTypeCharLiteral,
359
357
NodeTypeSymbol,
360
358
NodeTypePrefixOpExpr,
359
+ NodeTypeAddrOfExpr,
361
360
NodeTypeFnCallExpr,
362
361
NodeTypeArrayAccessExpr,
363
362
NodeTypeSliceExpr,
@@ -415,6 +414,8 @@ struct AstNodeFnProto {
415
414
AstNode *fn_def_node;
416
415
// populated if this is an extern declaration
417
416
Buf *lib_name;
417
+ // populated if the "align A" is present
418
+ AstNode *align_expr;
418
419
};
419
420
420
421
struct AstNodeFnDef {
@@ -470,6 +471,8 @@ struct AstNodeVariableDeclaration {
470
471
AstNode *expr;
471
472
// populated if this is an extern declaration
472
473
Buf *lib_name;
474
+ // populated if the "align A" is present
475
+ AstNode *align_expr;
473
476
};
474
477
475
478
struct AstNodeErrorValueDecl {
@@ -579,10 +582,6 @@ enum PrefixOp {
579
582
PrefixOpBinNot,
580
583
PrefixOpNegation,
581
584
PrefixOpNegationWrap,
582
- PrefixOpAddressOf,
583
- PrefixOpConstAddressOf,
584
- PrefixOpVolatileAddressOf,
585
- PrefixOpConstVolatileAddressOf,
586
585
PrefixOpDereference,
587
586
PrefixOpMaybe,
588
587
PrefixOpError,
@@ -595,6 +594,23 @@ struct AstNodePrefixOpExpr {
595
594
AstNode *primary_expr;
596
595
};
597
596
597
+ struct AstNodeAddrOfExpr {
598
+ AstNode *align_expr;
599
+ BigInt *bit_offset_start;
600
+ BigInt *bit_offset_end;
601
+ bool is_const;
602
+ bool is_volatile;
603
+ AstNode *op_expr;
604
+ };
605
+
606
+ struct AstNodeArrayType {
607
+ AstNode *size;
608
+ AstNode *child_type;
609
+ AstNode *align_expr;
610
+ bool is_const;
611
+ bool is_volatile;
612
+ };
613
+
598
614
struct AstNodeUse {
599
615
VisibMod visib_mod;
600
616
AstNode *expr;
@@ -807,12 +823,6 @@ struct AstNodeUnreachableExpr {
807
823
};
808
824
809
825
810
- struct AstNodeArrayType {
811
- AstNode *size;
812
- AstNode *child_type;
813
- bool is_const;
814
- };
815
-
816
826
struct AstNodeErrorType {
817
827
};
818
828
@@ -841,6 +851,7 @@ struct AstNode {
841
851
AstNodeBinOpExpr bin_op_expr;
842
852
AstNodeUnwrapErrorExpr unwrap_err_expr;
843
853
AstNodePrefixOpExpr prefix_op_expr;
854
+ AstNodeAddrOfExpr addr_of_expr;
844
855
AstNodeFnCallExpr fn_call_expr;
845
856
AstNodeArrayAccessExpr array_access_expr;
846
857
AstNodeSliceExpr slice_expr;
@@ -911,8 +922,10 @@ struct TypeTableEntryPointer {
911
922
TypeTableEntry *child_type;
912
923
bool is_const;
913
924
bool is_volatile;
925
+ uint32_t alignment;
914
926
uint32_t bit_offset;
915
927
uint32_t unaligned_bit_count;
928
+ TypeTableEntry *slice_parent;
916
929
};
917
930
918
931
struct TypeTableEntryInt {
@@ -958,6 +971,7 @@ struct TypeTableEntryStruct {
958
971
959
972
bool zero_bits_loop_flag;
960
973
bool zero_bits_known;
974
+ uint32_t abi_alignment; // also figured out with zero_bits pass
961
975
};
962
976
963
977
struct TypeTableEntryMaybe {
@@ -989,6 +1003,7 @@ struct TypeTableEntryEnum {
989
1003
990
1004
bool zero_bits_loop_flag;
991
1005
bool zero_bits_known;
1006
+ uint32_t abi_alignment; // also figured out with zero_bits pass
992
1007
993
1008
size_t gen_union_index;
994
1009
size_t gen_tag_index;
@@ -1101,7 +1116,6 @@ struct TypeTableEntry {
1101
1116
1102
1117
// use these fields to make sure we don't duplicate type table entries for the same type
1103
1118
TypeTableEntry *pointer_parent[2 ]; // [0 - mut, 1 - const]
1104
- TypeTableEntry *slice_parent[2 ]; // [0 - mut, 1 - const]
1105
1119
TypeTableEntry *maybe_parent;
1106
1120
TypeTableEntry *error_parent;
1107
1121
// If we generate a constant name value for this type, we memoize it here.
@@ -1164,15 +1178,14 @@ struct FnTableEntry {
1164
1178
size_t prealloc_bbc;
1165
1179
AstNode **param_source_nodes;
1166
1180
Buf **param_names;
1181
+ uint32_t align_bytes;
1167
1182
1168
1183
AstNode *fn_no_inline_set_node;
1169
1184
AstNode *fn_static_eval_set_node;
1170
1185
1171
1186
ZigList<IrInstruction *> alloca_list;
1172
1187
ZigList<VariableTableEntry *> variable_list;
1173
1188
1174
- AstNode *set_global_align_node;
1175
- uint32_t alignment;
1176
1189
AstNode *set_global_section_node;
1177
1190
Buf *section_name;
1178
1191
AstNode *set_global_linkage_node;
@@ -1187,8 +1200,7 @@ enum BuiltinFnId {
1187
1200
BuiltinFnIdMemcpy,
1188
1201
BuiltinFnIdMemset,
1189
1202
BuiltinFnIdSizeof,
1190
- BuiltinFnIdPreferredAlignOf,
1191
- BuiltinFnIdAbiAlignOf,
1203
+ BuiltinFnIdAlignOf,
1192
1204
BuiltinFnIdMaxValue,
1193
1205
BuiltinFnIdMinValue,
1194
1206
BuiltinFnIdMemberCount,
@@ -1224,7 +1236,6 @@ enum BuiltinFnId {
1224
1236
BuiltinFnIdSetFloatMode,
1225
1237
BuiltinFnIdTypeName,
1226
1238
BuiltinFnIdCanImplicitCast,
1227
- BuiltinFnIdSetGlobalAlign,
1228
1239
BuiltinFnIdSetGlobalSection,
1229
1240
BuiltinFnIdSetGlobalLinkage,
1230
1241
BuiltinFnIdPanic,
@@ -1277,6 +1288,7 @@ struct TypeId {
1277
1288
TypeTableEntry *child_type;
1278
1289
bool is_const;
1279
1290
bool is_volatile;
1291
+ uint32_t alignment;
1280
1292
uint32_t bit_offset;
1281
1293
uint32_t unaligned_bit_count;
1282
1294
} pointer;
@@ -1392,7 +1404,7 @@ struct CodeGen {
1392
1404
1393
1405
struct {
1394
1406
TypeTableEntry *entry_bool;
1395
- TypeTableEntry *entry_int[2 ][10 ]; // [signed,unsigned][3,4,5,6,7,8,16,32,64,128]
1407
+ TypeTableEntry *entry_int[2 ][11 ]; // [signed,unsigned][2, 3,4,5,6,7,8,16,32,64,128]
1396
1408
TypeTableEntry *entry_c_int[CIntTypeCount];
1397
1409
TypeTableEntry *entry_c_longdouble;
1398
1410
TypeTableEntry *entry_c_void;
@@ -1547,6 +1559,8 @@ struct CodeGen {
1547
1559
1548
1560
ZigList<FnTableEntry *> inline_fns;
1549
1561
ZigList<AstNode *> tld_ref_source_node_stack;
1562
+
1563
+ TypeTableEntry *align_amt_type;
1550
1564
};
1551
1565
1552
1566
enum VarLinkage {
@@ -1575,6 +1589,7 @@ struct VariableTableEntry {
1575
1589
size_t ref_count;
1576
1590
VarLinkage linkage;
1577
1591
IrInstruction *decl_instruction;
1592
+ uint32_t align_bytes;
1578
1593
};
1579
1594
1580
1595
struct ErrorTableEntry {
@@ -1808,8 +1823,7 @@ enum IrInstructionId {
1808
1823
IrInstructionIdBreakpoint,
1809
1824
IrInstructionIdReturnAddress,
1810
1825
IrInstructionIdFrameAddress,
1811
- IrInstructionIdPreferredAlignOf,
1812
- IrInstructionIdAbiAlignOf,
1826
+ IrInstructionIdAlignOf,
1813
1827
IrInstructionIdOverflowOp,
1814
1828
IrInstructionIdTestErr,
1815
1829
IrInstructionIdUnwrapErrCode,
@@ -1831,7 +1845,6 @@ enum IrInstructionId {
1831
1845
IrInstructionIdCheckStatementIsVoid,
1832
1846
IrInstructionIdTypeName,
1833
1847
IrInstructionIdCanImplicitCast,
1834
- IrInstructionIdSetGlobalAlign,
1835
1848
IrInstructionIdSetGlobalSection,
1836
1849
IrInstructionIdSetGlobalLinkage,
1837
1850
IrInstructionIdDeclRef,
@@ -1841,6 +1854,7 @@ enum IrInstructionId {
1841
1854
IrInstructionIdOffsetOf,
1842
1855
IrInstructionIdTypeId,
1843
1856
IrInstructionIdSetEvalBranchQuota,
1857
+ IrInstructionIdPtrTypeOf,
1844
1858
};
1845
1859
1846
1860
struct IrInstruction {
@@ -1976,6 +1990,7 @@ struct IrInstructionDeclVar {
1976
1990
1977
1991
VariableTableEntry *var;
1978
1992
IrInstruction *var_type;
1993
+ IrInstruction *align_value;
1979
1994
IrInstruction *init_value;
1980
1995
};
1981
1996
@@ -2152,7 +2167,9 @@ struct IrInstructionArrayType {
2152
2167
struct IrInstructionSliceType {
2153
2168
IrInstruction base;
2154
2169
2170
+ IrInstruction *align_value;
2155
2171
bool is_const;
2172
+ bool is_volatile;
2156
2173
IrInstruction *child_type;
2157
2174
};
2158
2175
@@ -2393,13 +2410,7 @@ struct IrInstructionOverflowOp {
2393
2410
TypeTableEntry *result_ptr_type;
2394
2411
};
2395
2412
2396
- struct IrInstructionPreferredAlignOf {
2397
- IrInstruction base;
2398
-
2399
- IrInstruction *type_value;
2400
- };
2401
-
2402
- struct IrInstructionAbiAlignOf {
2413
+ struct IrInstructionAlignOf {
2403
2414
IrInstruction base;
2404
2415
2405
2416
IrInstruction *type_value;
@@ -2554,13 +2565,6 @@ struct IrInstructionCanImplicitCast {
2554
2565
IrInstruction *target_value;
2555
2566
};
2556
2567
2557
- struct IrInstructionSetGlobalAlign {
2558
- IrInstruction base;
2559
-
2560
- Tld *tld;
2561
- IrInstruction *value;
2562
- };
2563
-
2564
2568
struct IrInstructionSetGlobalSection {
2565
2569
IrInstruction base;
2566
2570
@@ -2622,6 +2626,17 @@ struct IrInstructionSetEvalBranchQuota {
2622
2626
IrInstruction *new_quota;
2623
2627
};
2624
2628
2629
+ struct IrInstructionPtrTypeOf {
2630
+ IrInstruction base;
2631
+
2632
+ IrInstruction *align_value;
2633
+ IrInstruction *child_type;
2634
+ uint32_t bit_offset_start;
2635
+ uint32_t bit_offset_end;
2636
+ bool is_const;
2637
+ bool is_volatile;
2638
+ };
2639
+
2625
2640
static const size_t slice_ptr_index = 0 ;
2626
2641
static const size_t slice_len_index = 1 ;
2627
2642
0 commit comments