Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Oct 9, 2024
1 parent 403b59d commit 6f8f030
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ module Crystal
@main = @llvm_mod.functions.add(MAIN_NAME, main_type)
@fun_types = { {@llvm_mod, MAIN_NAME} => main_type }

if @program.has_flag?("windows") && !@program.has_flag?("gnu")
if @program.has_flag?("msvc")
@personality_name = "__CxxFrameHandler3"
@main.personality_function = windows_personality_fun.func
else
Expand Down Expand Up @@ -2488,7 +2488,7 @@ module Crystal
end

def self.safe_mangling(program, name)
if program.has_flag?("windows") && !program.has_flag?("gnu")
if program.has_flag?("msvc")
String.build do |str|
name.each_char do |char|
if char.ascii_alphanumeric? || char == '_'
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/debug.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Crystal
def push_debug_info_metadata(mod)
di_builder(mod).end

if @program.has_flag?("windows") && !@program.has_flag?("gnu")
if @program.has_flag?("msvc")
# Windows uses CodeView instead of DWARF
mod.add_flag(
LibLLVM::ModuleFlagBehavior::Warning,
Expand Down
17 changes: 9 additions & 8 deletions src/compiler/crystal/codegen/exception.cr
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class Crystal::CodeGenVisitor
#
# Note we codegen the ensure body three times! In practice this isn't a big deal, since ensure bodies are typically small.

windows = @program.has_flag?("windows") && !@program.has_flag?("gnu")
msvc = @program.has_flag?("msvc")

context.fun.personality_function = windows_personality_fun.func if windows
context.fun.personality_function = windows_personality_fun.func if msvc

# This is the block which is entered when the body raises an exception
rescue_block = new_block "rescue"
Expand Down Expand Up @@ -109,7 +109,7 @@ class Crystal::CodeGenVisitor

old_catch_pad = @catch_pad

if windows
if msvc
# Windows structured exception handling must enter a catch_switch instruction
# which decides which catch body block to enter. Crystal only ever generates one catch body
# which is used for all exceptions. For more information on how structured exception handling works in LLVM,
Expand Down Expand Up @@ -138,7 +138,8 @@ class Crystal::CodeGenVisitor
caught_exception = load exception_llvm_type, caught_exception_ptr
exception_type_id = type_id(caught_exception, exception_type)
else
# Unwind exception handling code - used on non-windows platforms - is a lot simpler.
# Unwind exception handling code - used on non-MSVC platforms (essentially the Itanium
# C++ ABI) - is a lot simpler.
# First we generate the landing pad instruction, this returns a tuple of the libunwind
# exception object and the type ID of the exception. This tuple is set up in the crystal
# personality function in raise.cr
Expand Down Expand Up @@ -188,7 +189,7 @@ class Crystal::CodeGenVisitor
# If the rescue restriction matches, codegen the rescue block.
position_at_end this_rescue_block

# On windows, we are "inside" the catchpad block. It's difficult to track when to catch_ret when
# On MSVC, we are "inside" the catchpad block. It's difficult to track when to catch_ret when
# codegenning the entire rescue body, so we catch_ret early and execute the rescue bodies "outside" the
# rescue block.
if catch_pad = @catch_pad
Expand Down Expand Up @@ -248,7 +249,7 @@ class Crystal::CodeGenVisitor

# Codegen catchswitch+pad or landing pad as described above.
# This code is simpler because we never need to extract the exception type
if windows
if msvc
rescue_ensure_body = new_block "rescue_ensure_body"
catch_switch = builder.catch_switch(old_catch_pad || LLVM::Value.null, @rescue_block || LLVM::BasicBlock.null, 1)
builder.add_handler catch_switch, rescue_ensure_body
Expand Down Expand Up @@ -283,8 +284,8 @@ class Crystal::CodeGenVisitor
end

def codegen_re_raise(node, unwind_ex_obj)
if @program.has_flag?("windows") && !@program.has_flag?("gnu")
# On windows we can re-raise by calling _CxxThrowException with two null arguments
if @program.has_flag?("msvc")
# On the MSVC C++ ABI we can re-raise by calling _CxxThrowException with two null arguments
call windows_throw_fun, [llvm_context.void_pointer.null, llvm_context.void_pointer.null]
unreachable
else
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/link.cr
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ module Crystal

class Program
def lib_flags
has_flag?("windows") && !has_flag?("gnu") ? lib_flags_windows : lib_flags_posix
has_flag?("msvc") ? lib_flags_windows : lib_flags_posix
end

private def lib_flags_windows
Expand Down

0 comments on commit 6f8f030

Please sign in to comment.