mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix global noinit. Add @noinit. With tests.
This commit is contained in:
@@ -210,13 +210,13 @@ add_executable(c3c
|
|||||||
src/compiler/libraries.c
|
src/compiler/libraries.c
|
||||||
src/compiler/linker.c
|
src/compiler/linker.c
|
||||||
src/compiler/llvm_codegen.c
|
src/compiler/llvm_codegen.c
|
||||||
src/compiler/llvm_codegen_c_abi_aarch64.c
|
src/compiler/abi/c_abi_aarch64.c
|
||||||
src/compiler/llvm_codegen_c_abi.c
|
src/compiler/abi/c_abi.c
|
||||||
src/compiler/llvm_codegen_c_abi_riscv.c
|
src/compiler/abi/c_abi_riscv.c
|
||||||
src/compiler/llvm_codegen_c_abi_wasm.c
|
src/compiler/abi/c_abi_wasm.c
|
||||||
src/compiler/llvm_codegen_c_abi_win64.c
|
src/compiler/abi/c_abi_win64.c
|
||||||
src/compiler/llvm_codegen_c_abi_x64.c
|
src/compiler/abi/c_abi_x64.c
|
||||||
src/compiler/llvm_codegen_c_abi_x86.c
|
src/compiler/abi/c_abi_x86.c
|
||||||
src/compiler/llvm_codegen_debug_info.c
|
src/compiler/llvm_codegen_debug_info.c
|
||||||
src/compiler/llvm_codegen_expr.c
|
src/compiler/llvm_codegen_expr.c
|
||||||
src/compiler/llvm_codegen_function.c
|
src/compiler/llvm_codegen_function.c
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by the GNU LGPLv3.0 license
|
// Use of this source code is governed by the GNU LGPLv3.0 license
|
||||||
// a copy of which can be found in the LICENSE file.
|
// a copy of which can be found in the LICENSE file.
|
||||||
|
|
||||||
#include "c_abi_internal.h"
|
#include "compiler/c_abi_internal.h"
|
||||||
|
|
||||||
|
|
||||||
static ABIArgInfo *abi_arg_new(ABIKind kind)
|
static ABIArgInfo *abi_arg_new(ABIKind kind)
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a LGPLv3.0
|
// Use of this source code is governed by a LGPLv3.0
|
||||||
// a copy of which can be found in the LICENSE file.
|
// a copy of which can be found in the LICENSE file.
|
||||||
|
|
||||||
#include "c_abi_internal.h"
|
#include "compiler/c_abi_internal.h"
|
||||||
|
|
||||||
INLINE bool is_aarch64_illegal_vector(Type *type)
|
INLINE bool is_aarch64_illegal_vector(Type *type)
|
||||||
{
|
{
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a LGPLv3.0
|
// Use of this source code is governed by a LGPLv3.0
|
||||||
// a copy of which can be found in the LICENSE file.
|
// a copy of which can be found in the LICENSE file.
|
||||||
|
|
||||||
#include "c_abi_internal.h"
|
#include "compiler/c_abi_internal.h"
|
||||||
|
|
||||||
|
|
||||||
static ABIArgInfo *riscv_coerce_and_expand_fpcc_struct(AbiType field1, unsigned field1_offset, AbiType field2, unsigned field2_offset)
|
static ABIArgInfo *riscv_coerce_and_expand_fpcc_struct(AbiType field1, unsigned field1_offset, AbiType field2, unsigned field2_offset)
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a LGPLv3.0
|
// Use of this source code is governed by a LGPLv3.0
|
||||||
// a copy of which can be found in the LICENSE file.
|
// a copy of which can be found in the LICENSE file.
|
||||||
|
|
||||||
#include "c_abi_internal.h"
|
#include "compiler/c_abi_internal.h"
|
||||||
|
|
||||||
static ABIArgInfo *wasm_classify_argument_type(Type *type)
|
static ABIArgInfo *wasm_classify_argument_type(Type *type)
|
||||||
{
|
{
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a LGPLv3.0
|
// Use of this source code is governed by a LGPLv3.0
|
||||||
// a copy of which can be found in the LICENSE file.
|
// a copy of which can be found in the LICENSE file.
|
||||||
|
|
||||||
#include "c_abi_internal.h"
|
#include "compiler/c_abi_internal.h"
|
||||||
|
|
||||||
ABIArgInfo *win64_classify(Regs *regs, Type *type, bool is_return, bool is_vector)
|
ABIArgInfo *win64_classify(Regs *regs, Type *type, bool is_return, bool is_vector)
|
||||||
{
|
{
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a LGPLv3.0
|
// Use of this source code is governed by a LGPLv3.0
|
||||||
// a copy of which can be found in the LICENSE file.
|
// a copy of which can be found in the LICENSE file.
|
||||||
|
|
||||||
#include "c_abi_internal.h"
|
#include "compiler/c_abi_internal.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a LGPLv3.0
|
// Use of this source code is governed by a LGPLv3.0
|
||||||
// a copy of which can be found in the LICENSE file.
|
// a copy of which can be found in the LICENSE file.
|
||||||
|
|
||||||
#include "c_abi_internal.h"
|
#include "compiler/c_abi_internal.h"
|
||||||
|
|
||||||
#define MIN_ABI_STACK_ALIGN 4
|
#define MIN_ABI_STACK_ALIGN 4
|
||||||
|
|
||||||
@@ -768,6 +768,7 @@ typedef enum
|
|||||||
ATTRIBUTE_MAYDISCARD,
|
ATTRIBUTE_MAYDISCARD,
|
||||||
ATTRIBUTE_NAKED,
|
ATTRIBUTE_NAKED,
|
||||||
ATTRIBUTE_NODISCARD,
|
ATTRIBUTE_NODISCARD,
|
||||||
|
ATTRIBUTE_NOINIT,
|
||||||
ATTRIBUTE_NOINLINE,
|
ATTRIBUTE_NOINLINE,
|
||||||
ATTRIBUTE_NORETURN,
|
ATTRIBUTE_NORETURN,
|
||||||
ATTRIBUTE_OBFUSCATE,
|
ATTRIBUTE_OBFUSCATE,
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ void llvm_emit_global_variable_init(GenContext *c, Decl *decl)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
init_value = llvm_get_zero(c, var_type);
|
init_value = decl->var.no_init ? llvm_get_undef(c, var_type) : llvm_get_zero(c, var_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1441,6 +1441,7 @@ static bool sema_analyse_attribute(SemaContext *context, Decl *decl, Attr *attr,
|
|||||||
[ATTRIBUTE_MAYDISCARD] = ATTR_FUNC | ATTR_MACRO,
|
[ATTRIBUTE_MAYDISCARD] = ATTR_FUNC | ATTR_MACRO,
|
||||||
[ATTRIBUTE_NAKED] = ATTR_FUNC,
|
[ATTRIBUTE_NAKED] = ATTR_FUNC,
|
||||||
[ATTRIBUTE_NODISCARD] = ATTR_FUNC | ATTR_MACRO,
|
[ATTRIBUTE_NODISCARD] = ATTR_FUNC | ATTR_MACRO,
|
||||||
|
[ATTRIBUTE_NOINIT] = ATTR_GLOBAL | ATTR_LOCAL,
|
||||||
[ATTRIBUTE_NOINLINE] = ATTR_FUNC | ATTR_CALL,
|
[ATTRIBUTE_NOINLINE] = ATTR_FUNC | ATTR_CALL,
|
||||||
[ATTRIBUTE_NORETURN] = ATTR_FUNC | ATTR_MACRO,
|
[ATTRIBUTE_NORETURN] = ATTR_FUNC | ATTR_MACRO,
|
||||||
[ATTRIBUTE_OBFUSCATE] = ATTR_ENUM,
|
[ATTRIBUTE_OBFUSCATE] = ATTR_ENUM,
|
||||||
@@ -1635,6 +1636,9 @@ static bool sema_analyse_attribute(SemaContext *context, Decl *decl, Attr *attr,
|
|||||||
decl->func_decl.attr_noinline = true;
|
decl->func_decl.attr_noinline = true;
|
||||||
decl->func_decl.attr_inline = false;
|
decl->func_decl.attr_inline = false;
|
||||||
break;
|
break;
|
||||||
|
case ATTRIBUTE_NOINIT:
|
||||||
|
decl->var.no_init = true;
|
||||||
|
break;
|
||||||
case ATTRIBUTE_NODISCARD:
|
case ATTRIBUTE_NODISCARD:
|
||||||
decl->func_decl.signature.attrs.nodiscard = true;
|
decl->func_decl.signature.attrs.nodiscard = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -304,6 +304,7 @@ void symtab_init(uint32_t capacity)
|
|||||||
attribute_list[ATTRIBUTE_MAYDISCARD] = KW_DEF("@maydiscard");
|
attribute_list[ATTRIBUTE_MAYDISCARD] = KW_DEF("@maydiscard");
|
||||||
attribute_list[ATTRIBUTE_NAKED] = KW_DEF("@naked");
|
attribute_list[ATTRIBUTE_NAKED] = KW_DEF("@naked");
|
||||||
attribute_list[ATTRIBUTE_NODISCARD] = KW_DEF("@nodiscard");
|
attribute_list[ATTRIBUTE_NODISCARD] = KW_DEF("@nodiscard");
|
||||||
|
attribute_list[ATTRIBUTE_NOINIT] = KW_DEF("@noinit");
|
||||||
attribute_list[ATTRIBUTE_NOINLINE] = KW_DEF("@noinline");
|
attribute_list[ATTRIBUTE_NOINLINE] = KW_DEF("@noinline");
|
||||||
attribute_list[ATTRIBUTE_NORETURN] = KW_DEF("@noreturn");
|
attribute_list[ATTRIBUTE_NORETURN] = KW_DEF("@noreturn");
|
||||||
attribute_list[ATTRIBUTE_OBFUSCATE] = KW_DEF("@obfuscate");
|
attribute_list[ATTRIBUTE_OBFUSCATE] = KW_DEF("@obfuscate");
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define COMPILER_VERSION "0.4.55"
|
#define COMPILER_VERSION "0.4.56"
|
||||||
25
test/test_suite/globals/global_no_init.c3t
Normal file
25
test/test_suite/globals/global_no_init.c3t
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
module test;
|
||||||
|
|
||||||
|
struct Abc
|
||||||
|
{
|
||||||
|
int[100] x;
|
||||||
|
}
|
||||||
|
int z @noinit;
|
||||||
|
Abc y @noinit;
|
||||||
|
|
||||||
|
fn void main()
|
||||||
|
{
|
||||||
|
z = y.x[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #expect: test.ll
|
||||||
|
|
||||||
|
@test_z = local_unnamed_addr global i32 undef, align 4
|
||||||
|
@test_y = local_unnamed_addr global %Abc undef, align 4
|
||||||
|
|
||||||
|
define void @test_main() #0 {
|
||||||
|
entry:
|
||||||
|
%0 = load i32, ptr @test_y, align 4
|
||||||
|
store i32 %0, ptr @test_z, align 4
|
||||||
|
ret void
|
||||||
|
}
|
||||||
26
test/test_suite/variables/var_init.c3t
Normal file
26
test/test_suite/variables/var_init.c3t
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
module test;
|
||||||
|
|
||||||
|
struct Abc
|
||||||
|
{
|
||||||
|
int[100] x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn void main()
|
||||||
|
{
|
||||||
|
int z @noinit;
|
||||||
|
Abc y @noinit;
|
||||||
|
int x;
|
||||||
|
Abc w;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #expect: test.ll
|
||||||
|
|
||||||
|
entry:
|
||||||
|
%z = alloca i32, align 4
|
||||||
|
%y = alloca %Abc, align 4
|
||||||
|
%x = alloca i32, align 4
|
||||||
|
%w = alloca %Abc, align 4
|
||||||
|
store i32 0, ptr %x, align 4
|
||||||
|
call void @llvm.memset.p0.i64(ptr align 4 %w, i8 0, i64 400, i1 false)
|
||||||
|
ret void
|
||||||
Reference in New Issue
Block a user