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