aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/ir.cpp1
-rw-r--r--src/translate_c.cpp25
-rw-r--r--test/translate_c.zig14
4 files changed, 41 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0fca21fbc..96a6fca5cd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8784,6 +8784,8 @@ endif()
if(ZIG_STATIC)
if(APPLE)
set(EXE_LDFLAGS "-static-libgcc -static-libstdc++")
+ elseif(MINGW)
+ set(EXE_LDFLAGS "-static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lwinpthread -lz3 -lz -lgomp -Wl,--no-whole-archive")
else()
set(EXE_LDFLAGS "-static")
endif()
diff --git a/src/ir.cpp b/src/ir.cpp
index 616bb23132..5193a63ec4 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -17129,6 +17129,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
for (size_t i = 0; i < new_incoming_values.length; i += 1) {
IrInstruction *new_value = new_incoming_values.at(i);
IrBasicBlock *predecessor = new_incoming_blocks.at(i);
+ ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base);
IrInstruction *branch_instruction = predecessor->instruction_list.pop();
ir_set_cursor_at_end(&ira->new_irb, predecessor);
IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
diff --git a/src/translate_c.cpp b/src/translate_c.cpp
index 1487db0ff4..69c70958e5 100644
--- a/src/translate_c.cpp
+++ b/src/translate_c.cpp
@@ -833,6 +833,27 @@ static bool qual_type_has_wrapping_overflow(Context *c, ZigClangQualType qt) {
}
}
+static bool type_is_function(Context *c, const ZigClangType *ty, ZigClangSourceLocation source_loc) {
+ switch (ZigClangType_getTypeClass(ty)) {
+ case ZigClangType_FunctionProto:
+ case ZigClangType_FunctionNoProto:
+ return true;
+ case ZigClangType_Elaborated: {
+ const clang::ElaboratedType *elaborated_ty = reinterpret_cast<const clang::ElaboratedType*>(ty);
+ ZigClangQualType qt = bitcast(elaborated_ty->getNamedType());
+ return type_is_function(c, ZigClangQualType_getTypePtr(qt), source_loc);
+ }
+ case ZigClangType_Typedef: {
+ const ZigClangTypedefType *typedef_ty = reinterpret_cast<const ZigClangTypedefType*>(ty);
+ const ZigClangTypedefNameDecl *typedef_decl = ZigClangTypedefType_getDecl(typedef_ty);
+ ZigClangQualType underlying_type = ZigClangTypedefNameDecl_getUnderlyingType(typedef_decl);
+ return type_is_function(c, ZigClangQualType_getTypePtr(underlying_type), source_loc);
+ }
+ default:
+ return false;
+ }
+}
+
static bool type_is_opaque(Context *c, const ZigClangType *ty, ZigClangSourceLocation source_loc) {
switch (ZigClangType_getTypeClass(ty)) {
case ZigClangType_Builtin: {
@@ -1034,7 +1055,9 @@ static AstNode *trans_type(Context *c, const ZigClangType *ty, ZigClangSourceLoc
return trans_create_node_prefix_op(c, PrefixOpOptional, child_node);
}
- if (type_is_opaque(c, ZigClangQualType_getTypePtr(child_qt), source_loc)) {
+ if (type_is_function(c, ZigClangQualType_getTypePtr(child_qt), source_loc)) {
+ return trans_create_node_prefix_op(c, PrefixOpOptional, child_node);
+ } else if (type_is_opaque(c, ZigClangQualType_getTypePtr(child_qt), source_loc)) {
AstNode *pointer_node = trans_create_node_ptr_type(c,
ZigClangQualType_isConstQualified(child_qt),
ZigClangQualType_isVolatileQualified(child_qt),
diff --git a/test/translate_c.zig b/test/translate_c.zig
index 48dac1e127..f25d708f32 100644
--- a/test/translate_c.zig
+++ b/test/translate_c.zig
@@ -40,6 +40,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
);
/////////////// Cases for only stage1 which are TODO items for stage2 ////////////////
+ cases.add("typedef of function in struct field",
+ \\typedef void lws_callback_function(void);
+ \\struct Foo {
+ \\ void (*func)(void);
+ \\ lws_callback_function *callback_http;
+ \\};
+ ,
+ \\pub const lws_callback_function = extern fn() void;
+ \\pub const struct_Foo = extern struct {
+ \\ func: ?extern fn() void,
+ \\ callback_http: ?lws_callback_function,
+ \\};
+ );
+
cases.add("pointer to struct demoted to opaque due to bit fields",
\\struct Foo {
\\ unsigned int: 1;