Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix crash passing array slice to constrained array formal argument

  • Loading branch information...
commit 22ac5a5ab4c4d2df34177778455239f3b87f8926 1 parent 6177e6a
@nickg authored
Showing with 20 additions and 14 deletions.
  1. +14 −13 src/cgen.c
  2. +6 −1 test/regress/func6.vhd
View
27 src/cgen.c
@@ -486,7 +486,9 @@ static LLVMValueRef cgen_get_slice(LLVMValueRef array, type_t type,
LLVMValueRef ptr = LLVMBuildGEP(builder, data, &off, 1, "");
- if (cgen_const_bounds(type))
+ bool unwrap = cgen_is_const(r.left) && cgen_is_const(r.right);
+
+ if (unwrap)
return ptr;
else
return cgen_array_meta(type,
@@ -804,19 +806,18 @@ static void cgen_call_args(tree_t t, LLVMValueRef *args, struct cgen_ctx *ctx)
// If we are passing an unconstrained array actual to a
// constrained formal then we need to unwrap the array
- bool need_unwrap =
- (type_kind(formal_type) == T_CARRAY)
- && !(cgen_const_bounds(type))
- && (builtin == NULL);
-
- if (need_unwrap) {
- // XXX: insert bounds checking here
+ if (type_kind(formal_type) == T_CARRAY) {
+ bool need_unwrap = (!cgen_const_bounds(type)
+ && (builtin == NULL));
+
+ LLVMValueRef ptr = args[i];
+ if (need_unwrap) {
+ // XXX: insert bounds checking here
+ ptr = LLVMBuildExtractValue(builder, args[i], 0, "aptr");
+ }
- args[i] = LLVMBuildPointerCast(
- builder,
- LLVMBuildExtractValue(builder, args[i], 0, "aptr"),
- LLVMPointerType(llvm_type(formal_type), 0),
- "unwrapped");
+ LLVMTypeRef lt = LLVMPointerType(llvm_type(formal_type), 0);
+ args[i] = LLVMBuildPointerCast(builder, ptr, lt, "");
}
}
}
View
7 test/regress/func6.vhd
@@ -17,7 +17,11 @@ architecture test of func6 is
begin
return flip(x);
end function;
-
+
+ function flipu2(x : bit_vector) return bit_vector is
+ begin
+ return flip(x(3 downto 0));
+ end function;
begin
process is
@@ -27,6 +31,7 @@ begin
b := "1100";
assert flip(b) = "0011";
assert flipu(b) = "0011";
+ assert flipu2(b) = "0011";
wait;
end process;
Please sign in to comment.
Something went wrong with that request. Please try again.