aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-06-05 18:03:21 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-06-05 18:03:21 -0400
commit652f4bdf6242462182005f4c7149f13beaaa3259 (patch)
treee8b131095700c37604ebad9934f836e51538aabe /src/ir.cpp
parent7a0948253636080e5abe59b938761ee7348a7025 (diff)
downloadzig-652f4bdf6242462182005f4c7149f13beaaa3259.tar.gz
zig-652f4bdf6242462182005f4c7149f13beaaa3259.zip
disallow unknown-length pointer to opaque
This also means that translate-c has to detect when a pointer to opaque is happening, and use `*` instead of `[*]`. See #1059
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 9578795fcc..5c44e7c0ff 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -4620,11 +4620,8 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) {
assert(node->type == NodeTypePointerType);
- // The null check here is for C imports which don't set a token on the AST node. We could potentially
- // update that code to create a fake token and then remove this check.
- PtrLen ptr_len = (node->data.pointer_type.star_token != nullptr &&
- (node->data.pointer_type.star_token->id == TokenIdStar ||
- node->data.pointer_type.star_token->id == TokenIdStarStar)) ? PtrLenSingle : PtrLenUnknown;
+ PtrLen ptr_len = (node->data.pointer_type.star_token->id == TokenIdStar ||
+ node->data.pointer_type.star_token->id == TokenIdStarStar) ? PtrLenSingle : PtrLenUnknown;
bool is_const = node->data.pointer_type.is_const;
bool is_volatile = node->data.pointer_type.is_volatile;
AstNode *expr_node = node->data.pointer_type.op_expr;
@@ -18973,6 +18970,9 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc
if (child_type->id == TypeTableEntryIdUnreachable) {
ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed"));
return ira->codegen->builtin_types.entry_invalid;
+ } else if (child_type->id == TypeTableEntryIdOpaque && instruction->ptr_len == PtrLenUnknown) {
+ ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque"));
+ return ira->codegen->builtin_types.entry_invalid;
}
uint32_t align_bytes;