aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-02-14 16:14:30 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-02-14 16:14:30 -0700
commitbaf889c87913b08f444291242e0c170b1aad14f4 (patch)
treea71b79db04b201cd0ab459e9a52cf32cc6c7cd98 /src
parent87922bfae0cbb90bd8e05a00c51a0c737ef3245f (diff)
downloadzig-baf889c87913b08f444291242e0c170b1aad14f4.tar.gz
zig-baf889c87913b08f444291242e0c170b1aad14f4.zip
parseh: fix __cdecl causing a fn ptr to be double ptr
Diffstat (limited to 'src')
-rw-r--r--src/analyze.cpp10
-rw-r--r--src/parseh.cpp27
2 files changed, 27 insertions, 10 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index adab231124..d2381a9156 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -3886,17 +3886,19 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B
}
// explicit cast from pointer to another pointer
- if (actual_type->id == TypeTableEntryIdPointer &&
- wanted_type->id == TypeTableEntryIdPointer)
+ if ((actual_type->id == TypeTableEntryIdPointer || actual_type->id == TypeTableEntryIdFn) &&
+ (wanted_type->id == TypeTableEntryIdPointer || wanted_type->id == TypeTableEntryIdFn))
{
return resolve_cast(g, context, node, expr_node, wanted_type, CastOpPointerReinterpret, false);
}
// explicit cast from maybe pointer to another maybe pointer
if (actual_type->id == TypeTableEntryIdMaybe &&
- actual_type->data.maybe.child_type->id == TypeTableEntryIdPointer &&
+ (actual_type->data.maybe.child_type->id == TypeTableEntryIdPointer ||
+ actual_type->data.maybe.child_type->id == TypeTableEntryIdFn) &&
wanted_type->id == TypeTableEntryIdMaybe &&
- wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
+ (wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer ||
+ wanted_type->data.maybe.child_type->id == TypeTableEntryIdFn))
{
return resolve_cast(g, context, node, expr_node, wanted_type, CastOpPointerReinterpret, false);
}
diff --git a/src/parseh.cpp b/src/parseh.cpp
index 96b34ddca4..3513092e70 100644
--- a/src/parseh.cpp
+++ b/src/parseh.cpp
@@ -314,6 +314,19 @@ static bool is_c_void_type(Context *c, TypeTableEntry *type_entry) {
return false;
}
+static bool qual_type_child_is_fn_proto(const QualType &qt) {
+ if (qt.getTypePtr()->getTypeClass() == Type::Paren) {
+ const ParenType *paren_type = static_cast<const ParenType *>(qt.getTypePtr());
+ if (paren_type->getInnerType()->getTypeClass() == Type::FunctionProto) {
+ return true;
+ }
+ } else if (qt.getTypePtr()->getTypeClass() == Type::Attributed) {
+ const AttributedType *attr_type = static_cast<const AttributedType *>(qt.getTypePtr());
+ return qual_type_child_is_fn_proto(attr_type->getEquivalentType());
+ }
+ return false;
+}
+
static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const Decl *decl,
HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> *type_table)
{
@@ -395,11 +408,8 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
return c->codegen->builtin_types.entry_invalid;
}
- if (child_qt.getTypePtr()->getTypeClass() == Type::Paren) {
- const ParenType *paren_type = static_cast<const ParenType *>(child_qt.getTypePtr());
- if (paren_type->getInnerType()->getTypeClass() == Type::FunctionProto) {
- return get_maybe_type(c->codegen, child_type);
- }
+ if (qual_type_child_is_fn_proto(child_qt)) {
+ return get_maybe_type(c->codegen, child_type);
}
bool is_const = child_qt.isConstQualified();
@@ -1639,7 +1649,12 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
unsigned offset = fsl.getManager().getFileOffset(fsl);
const char *source = (const char *)fsl.getManager().getBufferData(file_id).bytes_begin();
Buf *msg = buf_create_from_str((const char *)msg_str_ref.bytes_begin());
- Buf *path = buf_create_from_str((const char *)filename.bytes_begin());
+ Buf *path;
+ if (filename.empty()) {
+ path = buf_alloc();
+ } else {
+ path = buf_create_from_mem((const char *)filename.bytes_begin(), filename.size());
+ }
ErrorMsg *err_msg = err_msg_create_with_offset(path, line, column, offset, source, msg);