Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve handling of subtypes in some places

  • Loading branch information...
commit c0a65d84cca889aba0534e7d042f9c888ae0e753 1 parent c9e3471
@nickg authored
Showing with 7 additions and 5 deletions.
  1. +5 −4 src/cgen.c
  2. +2 −1  src/simp.c
View
9 src/cgen.c
@@ -203,8 +203,10 @@ static LLVMTypeRef llvm_type(type_t t)
return LLVMIntType(bit_width(t));
case T_SUBTYPE:
- return llvm_type(type_base(t));
+ if (!type_is_array(t))
+ return llvm_type(type_base(t));
+ // Fall-through
case T_CARRAY:
case T_UARRAY:
{
@@ -737,7 +739,6 @@ static void cgen_call_args(tree_t t, LLVMValueRef *args, struct cgen_ctx *ctx)
args[i] = NULL;
type_t type = tree_type(p.value);
- type_kind_t type_k = type_kind(type);
// If this is a scalar out or inout parameter then we need
// to pass a pointer rather than the value
@@ -756,7 +757,7 @@ static void cgen_call_args(tree_t t, LLVMValueRef *args, struct cgen_ctx *ctx)
// a structure with its metadata. Note we don't need to do
// this for unconstrained arrays as they are already wrapped.
bool need_wrap =
- (type_k == T_CARRAY)
+ type_is_array(type)
&& cgen_const_bounds(type)
&& (builtin == NULL);
@@ -2237,7 +2238,7 @@ static void cgen_process(tree_t t)
LLVMValueRef var_ptr = cgen_get_var(v, &ctx);
type_t ty = tree_type(v);
- if (type_kind(ty) == T_CARRAY)
+ if (type_is_array(ty))
cgen_array_copy(ty, ty, val, var_ptr, NULL);
else
LLVMBuildStore(builder, val, var_ptr);
View
3  src/simp.c
@@ -304,7 +304,7 @@ static tree_t simp_attr_ref(tree_t t)
if (icmp(builtin, "length")) {
tree_t array = tree_param(t, 0).value;
- if (type_kind(tree_type(array)) == T_CARRAY) {
+ if (type_kind(tree_type(array)) != T_UARRAY) {
range_t r = type_dim(tree_type(array), 0);
if (tree_kind(r.left) == T_LITERAL
&& tree_kind(r.right) == T_LITERAL) {
@@ -405,6 +405,7 @@ static tree_t simp_array_slice(tree_t t)
type_t base_type = tree_type(base_decl);
switch (type_kind(base_type)) {
+ case T_SUBTYPE:
case T_CARRAY:
{
range_t slice_r = tree_range(t);
Please sign in to comment.
Something went wrong with that request. Please try again.