From 098c09835b1b1dd08431a59f076e77bb0125d93a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 21 Sep 2023 11:34:40 +0100 Subject: [PATCH] Add `ODIN_SANITIZER_FLAGS` global constant --- core/runtime/core.odin | 13 +++++++++++++ src/checker.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 0634f573a..44717f8d0 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -510,6 +510,19 @@ Odin_Endian_Type :: type_of(ODIN_ENDIAN) */ Odin_Platform_Subtarget_Type :: type_of(ODIN_PLATFORM_SUBTARGET) +/* + // Defined internally by the compiler + Odin_Sanitizer_Flag :: enum u32 { + Address = 0, + Memory = 1, + Thread = 2, + } + Odin_Sanitizer_Flags :: distinct bitset[Odin_Sanitizer_Flag; u32] + + ODIN_SANITIZER_FLAGS // is a constant +*/ +Odin_Sanitizer_Flags :: type_of(ODIN_SANITIZER_FLAGS) + ///////////////////////////// // Init Startup Procedures // diff --git a/src/checker.cpp b/src/checker.cpp index cda7d50a0..984a00a90 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1086,6 +1086,33 @@ gb_internal void init_universal(void) { add_global_bool_constant("__ODIN_LLVM_F16_SUPPORTED", lb_use_new_pass_system()); + { + GlobalEnumValue values[3] = { + {"Address", 0}, + {"Memory", 1}, + {"Thread", 2}, + }; + + Type *enum_type = nullptr; + auto flags = add_global_enum_type(str_lit("Odin_Sanitizer_Flag"), values, gb_count_of(values), &enum_type); + Type *bit_set_type = alloc_type_bit_set(); + bit_set_type->BitSet.elem = enum_type; + bit_set_type->BitSet.underlying = t_u32; + bit_set_type->BitSet.lower = 0; + bit_set_type->BitSet.upper = 2; + type_size_of(bit_set_type); + + String type_name = str_lit("Odin_Sanitizer_Flags"); + Scope *scope = create_scope(nullptr, builtin_pkg->scope); + Entity *entity = alloc_entity_type_name(scope, make_token_ident(type_name), nullptr, EntityState_Resolved); + + Type *named_type = alloc_type_named(type_name, bit_set_type, entity); + set_base_type(named_type, bit_set_type); + + add_global_constant("ODIN_SANITIZER_FLAGS", named_type, exact_value_u64(bc->sanitizer_flags)); + } + + // Builtin Procedures for (isize i = 0; i < gb_count_of(builtin_procs); i++) {