| ... | @@ -386,6 +386,10 @@ pub const DeclGen = struct { | ... | @@ -386,6 +386,10 @@ pub const DeclGen = struct { |
| 386 | val: Value, | 386 | val: Value, |
| 387 | decl_index: Decl.Index, | 387 | decl_index: Decl.Index, |
| 388 | ) error{ OutOfMemory, AnalysisFail }!void { | 388 | ) error{ OutOfMemory, AnalysisFail }!void { |
| | 389 | if (ty.isPtrAtRuntime() and !ty.elemType2().isFnOrHasRuntimeBits()) { |
| | 390 | return dg.writeCValue(writer, CValue{ .undefined_ptr = ty }); |
| | 391 | } |
| | 392 | |
| 389 | if (ty.isSlice()) { | 393 | if (ty.isSlice()) { |
| 390 | try writer.writeByte('('); | 394 | try writer.writeByte('('); |
| 391 | try dg.renderTypecast(writer, ty); | 395 | try dg.renderTypecast(writer, ty); |
| ... | @@ -404,23 +408,15 @@ pub const DeclGen = struct { | ... | @@ -404,23 +408,15 @@ pub const DeclGen = struct { |
| 404 | // them). The analysis until now should ensure that the C function | 408 | // them). The analysis until now should ensure that the C function |
| 405 | // pointers are compatible. If they are not, then there is a bug | 409 | // pointers are compatible. If they are not, then there is a bug |
| 406 | // somewhere and we should let the C compiler tell us about it. | 410 | // somewhere and we should let the C compiler tell us about it. |
| 407 | if (ty.castPtrToFn() == null) { | 411 | const need_typecast = if (ty.castPtrToFn()) |_| false else !ty.eql(decl.ty, dg.module); |
| 408 | // Determine if we must pointer cast. | 412 | if (need_typecast) { |
| 409 | if (ty.eql(decl.ty, dg.module)) { | | |
| 410 | try writer.writeByte('&'); | | |
| 411 | try dg.renderDeclName(writer, decl_index); | | |
| 412 | return; | | |
| 413 | } | | |
| 414 | | | |
| 415 | try writer.writeAll("(("); | 413 | try writer.writeAll("(("); |
| 416 | try dg.renderTypecast(writer, ty); | 414 | try dg.renderTypecast(writer, ty); |
| 417 | try writer.writeAll(")&"); | | |
| 418 | try dg.renderDeclName(writer, decl_index); | | |
| 419 | try writer.writeByte(')'); | 415 | try writer.writeByte(')'); |
| 420 | return; | | |
| 421 | } | 416 | } |
| 422 | | 417 | try writer.writeByte('&'); |
| 423 | try dg.renderDeclName(writer, decl_index); | 418 | try dg.renderDeclName(writer, decl_index); |
| | 419 | if (need_typecast) try writer.writeByte(')'); |
| 424 | } | 420 | } |
| 425 | | 421 | |
| 426 | // Renders a "parent" pointer by recursing to the root decl/variable | 422 | // Renders a "parent" pointer by recursing to the root decl/variable |
| ... | @@ -1830,7 +1826,7 @@ pub const DeclGen = struct { | ... | @@ -1830,7 +1826,7 @@ pub const DeclGen = struct { |
| 1830 | | 1826 | |
| 1831 | if (dg.module.decl_exports.get(decl_index)) |exports| { | 1827 | if (dg.module.decl_exports.get(decl_index)) |exports| { |
| 1832 | return writer.writeAll(exports[0].options.name); | 1828 | return writer.writeAll(exports[0].options.name); |
| 1833 | } else if (decl.val.tag() == .extern_fn) { | 1829 | } else if (decl.isExtern()) { |
| 1834 | return writer.writeAll(mem.sliceTo(decl.name, 0)); | 1830 | return writer.writeAll(mem.sliceTo(decl.name, 0)); |
| 1835 | } else { | 1831 | } else { |
| 1836 | const gpa = dg.module.gpa; | 1832 | const gpa = dg.module.gpa; |
| ... | @@ -1997,7 +1993,7 @@ pub fn genDecl(o: *Object) !void { | ... | @@ -1997,7 +1993,7 @@ pub fn genDecl(o: *Object) !void { |
| 1997 | try o.dg.renderTypeAndName(fwd_decl_writer, o.dg.decl.ty, decl_c_value, .Mut, o.dg.decl.@"align"); | 1993 | try o.dg.renderTypeAndName(fwd_decl_writer, o.dg.decl.ty, decl_c_value, .Mut, o.dg.decl.@"align"); |
| 1998 | try fwd_decl_writer.writeAll(";\n"); | 1994 | try fwd_decl_writer.writeAll(";\n"); |
| 1999 | | 1995 | |
| 2000 | if (variable.init.isUndefDeep()) { | 1996 | if (variable.is_extern or variable.init.isUndefDeep()) { |
| 2001 | return; | 1997 | return; |
| 2002 | } | 1998 | } |
| 2003 | | 1999 | |