| ... | @@ -671,15 +671,6 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co | ... | @@ -671,15 +671,6 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co |
| 671 | break :blk null; | 671 | break :blk null; |
| 672 | }; | 672 | }; |
| 673 | | 673 | |
| 674 | const alignment = blk: { | | |
| 675 | const alignment = var_decl.getAlignedAttribute(c.clang_context); | | |
| 676 | if (alignment != 0) { | | |
| 677 | // Clang reports the alignment in bits | | |
| 678 | break :blk alignment / 8; | | |
| 679 | } | | |
| 680 | break :blk null; | | |
| 681 | }; | | |
| 682 | | | |
| 683 | const node = try Tag.var_decl.create(c.arena, .{ | 674 | const node = try Tag.var_decl.create(c.arena, .{ |
| 684 | .is_pub = is_pub, | 675 | .is_pub = is_pub, |
| 685 | .is_const = is_const, | 676 | .is_const = is_const, |
| ... | @@ -687,7 +678,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co | ... | @@ -687,7 +678,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co |
| 687 | .is_export = is_export, | 678 | .is_export = is_export, |
| 688 | .is_threadlocal = is_threadlocal, | 679 | .is_threadlocal = is_threadlocal, |
| 689 | .linksection_string = linksection_string, | 680 | .linksection_string = linksection_string, |
| 690 | .alignment = alignment, | 681 | .alignment = zigAlignment(var_decl.getAlignedAttribute(c.clang_context)), |
| 691 | .name = checked_name, | 682 | .name = checked_name, |
| 692 | .type = type_node, | 683 | .type = type_node, |
| 693 | .init = init_node, | 684 | .init = init_node, |
| ... | @@ -833,14 +824,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD | ... | @@ -833,14 +824,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD |
| 833 | else => |e| return e, | 824 | else => |e| return e, |
| 834 | }; | 825 | }; |
| 835 | | 826 | |
| 836 | const alignment = blk_2: { | 827 | const alignment = zigAlignment(field_decl.getAlignedAttribute(c.clang_context)); |
| 837 | const alignment = field_decl.getAlignedAttribute(c.clang_context); | | |
| 838 | if (alignment != 0) { | | |
| 839 | // Clang reports the alignment in bits | | |
| 840 | break :blk_2 alignment / 8; | | |
| 841 | } | | |
| 842 | break :blk_2 null; | | |
| 843 | }; | | |
| 844 | | 828 | |
| 845 | if (is_anon) { | 829 | if (is_anon) { |
| 846 | try c.decl_table.putNoClobber(c.gpa, @ptrToInt(field_decl.getCanonicalDecl()), field_name); | 830 | try c.decl_table.putNoClobber(c.gpa, @ptrToInt(field_decl.getCanonicalDecl()), field_name); |
| ... | @@ -1373,6 +1357,13 @@ fn transCStyleCastExprClass( | ... | @@ -1373,6 +1357,13 @@ fn transCStyleCastExprClass( |
| 1373 | return maybeSuppressResult(c, scope, result_used, cast_node); | 1357 | return maybeSuppressResult(c, scope, result_used, cast_node); |
| 1374 | } | 1358 | } |
| 1375 | | 1359 | |
| | 1360 | /// Clang reports the alignment in bits, we use bytes |
| | 1361 | /// Clang uses 0 for "no alignment specified", we use null |
| | 1362 | fn zigAlignment(bit_alignment: c_uint) ?c_uint { |
| | 1363 | if (bit_alignment == 0) return null; |
| | 1364 | return bit_alignment / 8; |
| | 1365 | } |
| | 1366 | |
| 1376 | fn transDeclStmtOne( | 1367 | fn transDeclStmtOne( |
| 1377 | c: *Context, | 1368 | c: *Context, |
| 1378 | scope: *Scope, | 1369 | scope: *Scope, |
| ... | @@ -1412,6 +1403,7 @@ fn transDeclStmtOne( | ... | @@ -1412,6 +1403,7 @@ fn transDeclStmtOne( |
| 1412 | if (!qualTypeIsBoolean(qual_type) and isBoolRes(init_node)) { | 1403 | if (!qualTypeIsBoolean(qual_type) and isBoolRes(init_node)) { |
| 1413 | init_node = try Tag.bool_to_int.create(c.arena, init_node); | 1404 | init_node = try Tag.bool_to_int.create(c.arena, init_node); |
| 1414 | } | 1405 | } |
| | 1406 | |
| 1415 | const node = try Tag.var_decl.create(c.arena, .{ | 1407 | const node = try Tag.var_decl.create(c.arena, .{ |
| 1416 | .is_pub = false, | 1408 | .is_pub = false, |
| 1417 | .is_const = is_const, | 1409 | .is_const = is_const, |
| ... | @@ -1419,7 +1411,7 @@ fn transDeclStmtOne( | ... | @@ -1419,7 +1411,7 @@ fn transDeclStmtOne( |
| 1419 | .is_export = false, | 1411 | .is_export = false, |
| 1420 | .is_threadlocal = false, | 1412 | .is_threadlocal = false, |
| 1421 | .linksection_string = null, | 1413 | .linksection_string = null, |
| 1422 | .alignment = null, | 1414 | .alignment = zigAlignment(var_decl.getAlignedAttribute(c.clang_context)), |
| 1423 | .name = mangled_name, | 1415 | .name = mangled_name, |
| 1424 | .type = type_node, | 1416 | .type = type_node, |
| 1425 | .init = init_node, | 1417 | .init = init_node, |
| ... | @@ -4111,16 +4103,7 @@ fn finishTransFnProto( | ... | @@ -4111,16 +4103,7 @@ fn finishTransFnProto( |
| 4111 | break :blk null; | 4103 | break :blk null; |
| 4112 | }; | 4104 | }; |
| 4113 | | 4105 | |
| 4114 | const alignment = blk: { | 4106 | const alignment = if (fn_decl) |decl| zigAlignment(decl.getAlignedAttribute(c.clang_context)) else null; |
| 4115 | if (fn_decl) |decl| { | | |
| 4116 | const alignment = decl.getAlignedAttribute(c.clang_context); | | |
| 4117 | if (alignment != 0) { | | |
| 4118 | // Clang reports the alignment in bits | | |
| 4119 | break :blk alignment / 8; | | |
| 4120 | } | | |
| 4121 | } | | |
| 4122 | break :blk null; | | |
| 4123 | }; | | |
| 4124 | | 4107 | |
| 4125 | const explicit_callconv = if ((is_export or is_extern) and cc == .C) null else cc; | 4108 | const explicit_callconv = if ((is_export or is_extern) and cc == .C) null else cc; |
| 4126 | | 4109 | |