mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fixing #380 where const aggregates were copied by value.
This commit is contained in:
@@ -60,7 +60,7 @@ enum Seek
|
|||||||
END = 2
|
END = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
errtype IoError
|
optenum IoError
|
||||||
{
|
{
|
||||||
FILE_NOT_FOUND,
|
FILE_NOT_FOUND,
|
||||||
FILE_NOT_SEEKABLE,
|
FILE_NOT_SEEKABLE,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ enum AllocationKind
|
|||||||
FREE,
|
FREE,
|
||||||
}
|
}
|
||||||
|
|
||||||
errtype AllocationFailure
|
optenum AllocationFailure
|
||||||
{
|
{
|
||||||
OUT_OF_MEMORY
|
OUT_OF_MEMORY
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,6 +328,10 @@ void llvm_emit_global_variable_init(GenContext *c, Decl *decl)
|
|||||||
AlignSize alignment = type_alloca_alignment(var_type);
|
AlignSize alignment = type_alloca_alignment(var_type);
|
||||||
|
|
||||||
Expr *init_expr = decl->var.init_expr;
|
Expr *init_expr = decl->var.init_expr;
|
||||||
|
if (init_expr && init_expr->expr_kind == EXPR_CONST_IDENTIFIER)
|
||||||
|
{
|
||||||
|
init_expr = init_expr->identifier_expr.decl->var.init_expr;
|
||||||
|
}
|
||||||
if (init_expr)
|
if (init_expr)
|
||||||
{
|
{
|
||||||
if (init_expr->expr_kind == EXPR_CONST && init_expr->const_expr.const_kind == CONST_LIST)
|
if (init_expr->expr_kind == EXPR_CONST && init_expr->const_expr.const_kind == CONST_LIST)
|
||||||
|
|||||||
@@ -661,6 +661,7 @@ static inline bool sema_cast_ident_rvalue(SemaContext *context, Expr *expr)
|
|||||||
{
|
{
|
||||||
UNREACHABLE
|
UNREACHABLE
|
||||||
}
|
}
|
||||||
|
if (type_is_abi_aggregate(decl->type)) return true;
|
||||||
expr_replace(expr, copy_expr(decl->var.init_expr));
|
expr_replace(expr, copy_expr(decl->var.init_expr));
|
||||||
return sema_analyse_expr(context, expr);
|
return sema_analyse_expr(context, expr);
|
||||||
case VARDECL_PARAM_EXPR:
|
case VARDECL_PARAM_EXPR:
|
||||||
|
|||||||
29
test/test_suite/constants/const_var_copy.c3t
Normal file
29
test/test_suite/constants/const_var_copy.c3t
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// #target: x64-darwin
|
||||||
|
module foo;
|
||||||
|
const char[100] FOO = { [50] = 1 };
|
||||||
|
const int[<4>] BAR = { 1, 2, 3, 4 };
|
||||||
|
|
||||||
|
fn void test(int z)
|
||||||
|
{
|
||||||
|
char s = FOO[z];
|
||||||
|
int zd = BAR[z];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #expect: foo.ll
|
||||||
|
|
||||||
|
@foo.FOO = local_unnamed_addr constant { [50 x i8], i8, [49 x i8] } { [50 x i8] zeroinitializer, i8 1, [49 x i8] zeroinitializer }, align 16
|
||||||
|
@foo.BAR = local_unnamed_addr constant <4 x i32> <i32 1, i32 2, i32 3, i32 4>, align 16
|
||||||
|
|
||||||
|
define void @foo.test(i32 %0) #0 {
|
||||||
|
entry:
|
||||||
|
%s = alloca i8, align 1
|
||||||
|
%zd = alloca i32, align 4
|
||||||
|
%sisiext = sext i32 %0 to i64
|
||||||
|
%1 = getelementptr inbounds [100 x i8], [100 x i8]* bitcast ({ [50 x i8], i8, [49 x i8] }* @foo.FOO to [100 x i8]*), i64 0, i64 %sisiext
|
||||||
|
%2 = load i8, i8* %1, align 1
|
||||||
|
store i8 %2, i8* %s, align 1
|
||||||
|
%sisiext1 = sext i32 %0 to i64
|
||||||
|
%3 = extractelement <4 x i32> <i32 1, i32 2, i32 3, i32 4>, i64 %sisiext1
|
||||||
|
store i32 %3, i32* %zd, align 4
|
||||||
|
ret void
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
module foo;
|
module foo;
|
||||||
|
|
||||||
errtype Blurg
|
optenum Blurg
|
||||||
{
|
{
|
||||||
Z
|
Z
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module foo;
|
module foo;
|
||||||
|
|
||||||
errtype Blurg
|
optenum Blurg
|
||||||
{
|
{
|
||||||
X, Y, Z
|
X, Y, Z
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ struct Foo
|
|||||||
int x, y;
|
int x, y;
|
||||||
}
|
}
|
||||||
|
|
||||||
errtype MyErr
|
optenum MyErr
|
||||||
{
|
{
|
||||||
FOO
|
FOO
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// #target: x64-darwin
|
// #target: x64-darwin
|
||||||
|
|
||||||
errtype MyErr
|
errnum MyErr
|
||||||
{
|
{
|
||||||
TEST
|
TEST
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ fn int main()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #expect: failable_catch.ll
|
/* #expect: failable_catch.ll
|
||||||
|
|
||||||
define i32 @main() #0 {
|
define i32 @main() #0 {
|
||||||
entry:
|
entry:
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ fn Type getMult(Type a)
|
|||||||
}
|
}
|
||||||
Type argh = 234;
|
Type argh = 234;
|
||||||
|
|
||||||
errtype MyErr
|
optenum MyErr
|
||||||
{
|
{
|
||||||
X,
|
X,
|
||||||
Y
|
Y
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ private Foo foo6;
|
|||||||
private const Foo FOO7 = { 1, 2 };
|
private const Foo FOO7 = { 1, 2 };
|
||||||
private Foo foo8 = FOO7;
|
private Foo foo8 = FOO7;
|
||||||
|
|
||||||
// #expect: structo.ll
|
/* #expect: structo.ll
|
||||||
|
|
||||||
%Foo = type { i32, i64 }
|
%Foo = type { i32, i64 }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user