Windows: Fix InterpreterException not being caught and terminating.

This commit is contained in:
Frederich Munch 2016-12-19 08:57:52 -05:00 committed by sftnight
parent 4d41bd315f
commit f846990f8d
4 changed files with 41 additions and 43 deletions

View File

@ -288,8 +288,45 @@ macro(add_cling_library name)
if(ARG_SHARED)
set(ARG_ENABLE_SHARED SHARED)
endif()
if (MSVC)
# On Windows exceptions arent as generic as an x64 ABI.
# Stack unwinding code must be generated for every function between the
# throw and catch blocks.
if (${name} STREQUAL "clingInterpreter")
# All of libClingInterpreter is compiled with exceptions, mostly because
# llvm_unreachable throws an exception. Otherwise it could be reduced:
# Exception.cpp, Interpreter.cpp, IncrementalParser.cpp,
# IncrementalExecutor.cpp
set(cling_ex_file_match ".cpp$")
elseif(${name} STREQUAL "clingUserInterface")
# For libClingUserInterface, only UserInterface.cpp uses exceptions.
set(cling_ex_file_match "^UserInterface.cpp$")
endif()
if(cling_ex_file_match)
# needs to be on before llvm_add_library so flags can be set below
set(LLVM_REQUIRES_EH ON)
set(LLVM_REQUIRES_RTTI ON)
endif()
endif()
llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
if (MSVC AND cling_ex_file_match)
# /EHs because cling_runtime_internal_throwIfInvalidPointer is extern C
if (cling_ex_file_match)
foreach(file_var ${ARGN})
if (file_var MATCHES ${cling_ex_file_match})
set_property(SOURCE ${file_var} APPEND_STRING PROPERTY COMPILE_FLAGS
" /D _HAS_EXCEPTIONS=1 /EHs /GR /wd4714 ")
elseif (file_var MATCHES ".cpp$")
set_property(SOURCE ${file_var} APPEND_STRING PROPERTY COMPILE_FLAGS
" /D _HAS_EXCEPTIONS=0 /EHs-c- /GR- ")
endif()
endforeach()
endif()
endif()
if(TARGET ${name})
target_link_libraries(${name} ${INTERFACE} ${LLVM_COMMON_LIBS})

View File

@ -80,32 +80,11 @@ add_cling_library(clingInterpreter OBJECT
${LIBS}
)
if(NOT WIN32)
set_source_files_properties(ExceptionRTTI.cpp COMPILE_FLAGS "-fexceptions -frtti")
endif()
#set_source_files_properties(Exception.cpp COMPILE_FLAGS " /EHsc ")
# the line above doesn't work, and it gives the following warnings:
# cl : Command line warning D9025: overriding '/EHs' with '/EHs-'
# cl : Command line warning D9025: overriding '/EHc' with '/EHc-'
# so let's change the target compiler flags instead:
if(MSVC)
get_target_property(CI_COMPILE_FLAGS clingInterpreter COMPILE_FLAGS)
if(${CI_COMPILE_FLAGS})
string(REPLACE "/EHs-c-" "" CI_COMPILE_FLAGS ${CI_COMPILE_FLAGS})
# add /EHsc exception handling flag
set(CI_COMPILE_FLAGS "${CI_COMPILE_FLAGS} /EHsc")
else()
set(CI_COMPILE_FLAGS "/EHsc")
endif()
set_target_properties(clingInterpreter PROPERTIES
COMPILE_FLAGS ${CI_COMPILE_FLAGS})
endif()
#add_dependencies(clangDriver ClangAttrList ClangDiagnosticDriver
# ClangDriverOptions ClangCC1Options ClangCC1AsOptions)
if (UNIX)
set_source_files_properties(Exception.cpp COMPILE_FLAGS "-fexceptions -frtti")
# Remove all -I from CMAKE_CXX_FLAGS
string(REPLACE ";" " " __flags "${CMAKE_CXX_FLAGS}")

View File

@ -30,8 +30,3 @@ add_cling_library(clingMetaProcessor OBJECT
clingInterpreter
clingUtils
)
if ( MSVC )
set_target_properties(clingMetaProcessor PROPERTIES
COMPILE_FLAGS "/D_HAS_EXCEPTIONS=0")
endif ()

View File

@ -6,9 +6,6 @@
# LICENSE.TXT for details.
#------------------------------------------------------------------------------
set(LLVM_REQUIRES_EH true)
set(LLVM_REQUIRES_RTTI true)
set( LLVM_LINK_COMPONENTS
support
)
@ -51,16 +48,6 @@ add_cling_library(clingUserInterface
clingUtils
)
IF(MSVC)
# windows.h doesn't compile with /Za
get_target_property(NON_ANSI_COMPILE_FLAGS clingUserInterface COMPILE_FLAGS)
if(${NON_ANSI_COMPILE_FLAGS})
string(REPLACE "/Za" "" NON_ANSI_COMPILE_FLAGS ${NON_ANSI_COMPILE_FLAGS})
# add /EHsc exception handling flag
set(NON_ANSI_COMPILE_FLAGS "${NON_ANSI_COMPILE_FLAGS} /EHsc")
else()
set(NON_ANSI_COMPILE_FLAGS "/EHsc")
endif()
set_target_properties(clingUserInterface PROPERTIES
COMPILE_FLAGS ${NON_ANSI_COMPILE_FLAGS})
ENDIF()
if(UNIX)
set_source_files_properties(UserInterface.cpp COMPILE_FLAGS "-fexceptions")
endif()