Skip to content

Commit 56870b7

Browse files
committed
fix some ptr issues
1 parent 4fe8978 commit 56870b7

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/shady/emit/c/emit_c_instructions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static void emit_primop(Emitter* emitter, Printer* p, const Node* node, Instruct
349349
// this means such code is never going to be legal in GLSL
350350
// also the cast is to account for our arrays-in-structs hack
351351
const Type* pointee_type = get_pointee_type(arena, curr_ptr_type);
352-
acc = term_from_cvalue(format_string_arena(arena->arena, "((%s) &%s)", emit_type(emitter, curr_ptr_type, NULL), index_into_array(emitter, pointee_type, acc, offset)));
352+
acc = term_from_cvalue(format_string_arena(arena->arena, "((%s) &(%s)[%s])", emit_type(emitter, curr_ptr_type, NULL), to_cvalue(emitter, acc), to_cvalue(emitter, offset)));
353353
uniform &= is_qualified_type_uniform(prim_op->operands.nodes[1]->type);
354354
}
355355

src/shady/passes/opt_mem2reg.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ static const Node* process_instruction(Context* ctx, KnowledgeBase* kb, const No
352352
// }
353353
return prim_op_helper(a, load_op, empty(a), singleton(rewrite_node(r, optr)));
354354
}
355+
// case memcpy_op: {
356+
// const Node* optr = first(payload.operands);
357+
// }
355358
case store_op: {
356359
const Node* optr = first(payload.operands);
357360
PtrKnowledge* k = find_or_create_ptr_knowledge_for_updating(ctx, kb, optr, true);

src/shady/type.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ const Type* check_type_prim_op(IrArena* arena, PrimOp prim_op) {
802802
const IntLiteral* lit = resolve_to_int_literal(offset);
803803
bool offset_is_zero = lit && lit->value == 0;
804804
assert(offset_is_zero || !base_ptr_type->payload.ptr_type.is_reference && "if an offset is used, the base cannot be a reference");
805+
assert(offset_is_zero || is_data_type(pointee_type) && "if an offset is used, the base must point to a data type");
805806
uniform &= offset_uniform;
806807

807808
Nodes indices = nodes(arena, prim_op.operands.count - 2, &prim_op.operands.nodes[2]);
@@ -1036,7 +1037,7 @@ const Type* check_type_prim_op(IrArena* arena, PrimOp prim_op) {
10361037
case get_stack_base_op: {
10371038
assert(prim_op.type_arguments.count == 0);
10381039
assert(prim_op.operands.count == 0);
1039-
const Node* ptr = ptr_type(arena, (PtrType) { .pointed_type = arr_type(arena, (ArrType) { .element_type = uint8_type(arena), .size = NULL }), .address_space = AsPrivate});
1040+
const Node* ptr = ptr_type(arena, (PtrType) { .pointed_type = uint8_type(arena), .address_space = AsPrivate});
10401041
return qualified_type(arena, (QualifiedType) { .is_uniform = false, .type = ptr });
10411042
}
10421043
case set_stack_pointer_op: {

0 commit comments

Comments
 (0)