Skip to content

Commit

Permalink
translate-c: support static incomplete array inside function
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Nov 30, 2017
1 parent 716b0b8 commit 7729f6c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/translate_c.cpp
Expand Up @@ -976,11 +976,23 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou
const AttributedType *attributed_ty = static_cast<const AttributedType *>(ty);
return trans_qual_type(c, attributed_ty->getEquivalentType(), source_loc);
}
case Type::IncompleteArray:
{
const IncompleteArrayType *incomplete_array_ty = static_cast<const IncompleteArrayType *>(ty);
QualType child_qt = incomplete_array_ty->getElementType();
AstNode *child_type_node = trans_qual_type(c, child_qt, source_loc);
if (child_type_node == nullptr) {
emit_warning(c, source_loc, "unresolved array element type");
return nullptr;
}
AstNode *pointer_node = trans_create_node_addr_of(c, child_qt.isConstQualified(),
child_qt.isVolatileQualified(), child_type_node);
return pointer_node;
}
case Type::BlockPointer:
case Type::LValueReference:
case Type::RValueReference:
case Type::MemberPointer:
case Type::IncompleteArray:
case Type::VariableArray:
case Type::DependentSizedArray:
case Type::DependentSizedExtVector:
Expand Down Expand Up @@ -4301,7 +4313,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
}
}

return 0;
return ErrorUnexpected;
}

c->ctx = &ast_unit->getASTContext();
Expand Down
10 changes: 10 additions & 0 deletions test/translate_c.zig
Expand Up @@ -1178,4 +1178,14 @@ pub fn addCases(cases: &tests.TranslateCContext) {
,
\\pub var v0: ?&const u8 = c"0.0.0";
);

cases.add("static incomplete array inside function",
\\void foo(void) {
\\ static const char v2[] = "2.2.2";
\\}
,
\\pub fn foo() {
\\ const v2: &const u8 = c"2.2.2";
\\}
);
}

0 comments on commit 7729f6c

Please sign in to comment.