Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -47,7 +47,7 @@ set(OPENMP_TEST_FLAGS "" CACHE STRING "Extra compiler flags to send to the test compiler.") -set(OPENMP_TEST_OPENMP_FLAGS "-fopenmp" CACHE STRING +set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING "OpenMP compiler flag to use for testing OpenMP runtime libraries.") Index: cmake/DetectTestCompiler/CMakeLists.txt =================================================================== --- /dev/null +++ cmake/DetectTestCompiler/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8) +project(DetectTestCompiler C CXX) + +function(write_compiler_information lang) + set(information "${CMAKE_${lang}_COMPILER}") + set(information "${information}\\;${CMAKE_${lang}_COMPILER_ID}") + set(information "${information}\\;${CMAKE_${lang}_COMPILER_VERSION}") + set(information "${information}\\;${OpenMP_${lang}_FLAGS}") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${lang}CompilerInformation.txt ${information}) +endfunction(write_compiler_information) + +find_package(OpenMP) +if (NOT OpenMP_Found) + set(OpenMP_C_FLAGS "-fopenmp") + set(OpenMP_CXX_FLAGS "-fopenmp") +endif() + +write_compiler_information(C) +write_compiler_information(CXX) Index: cmake/OpenMPTesting.cmake =================================================================== --- cmake/OpenMPTesting.cmake +++ cmake/OpenMPTesting.cmake @@ -61,6 +61,81 @@ set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck) endif() +# Macro to extract information about compiler from file. (no own scope) +macro(extract_test_compiler_information lang file) + file(READ ${file} information) + list(GET information 0 path) + list(GET information 1 id) + list(GET information 2 version) + list(GET information 3 openmp_flags) + + set(OPENMP_TEST_${lang}_COMPILER_PATH ${path}) + set(OPENMP_TEST_${lang}_COMPILER_ID ${id}) + set(OPENMP_TEST_${lang}_COMPILER_VERSION ${version}) + set(OPENMP_TEST_${lang}_COMPILER_OPENMP_FLAGS ${openmp_flags}) +endmacro() + +# Function to set variables with information about the test compiler. +function(set_test_compiler_information dir) + extract_test_compiler_information(C ${dir}/CCompilerInformation.txt) + extract_test_compiler_information(CXX ${dir}/CXXCompilerInformation.txt) + if (NOT("${OPENMP_TEST_C_COMPILER_ID}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_ID}" AND + "${OPENMP_TEST_C_COMPILER_VERSION}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_VERSION}")) + message(STATUS "Test compilers for C and C++ don't match.") + message(WARNING "The check targets will not be available!") + set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE) + else() + set(OPENMP_TEST_COMPILER_ID "${OPENMP_TEST_C_COMPILER_ID}" PARENT_SCOPE) + set(OPENMP_TEST_COMPILER_VERSION "${OPENMP_TEST_C_COMPILER_VERSION}" PARENT_SCOPE) + set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "${OPENMP_TEST_C_COMPILER_OPENMP_FLAGS}" PARENT_SCOPE) + + # Determine major version. + string(REGEX MATCH "[0-9]+" major "${OPENMP_TEST_C_COMPILER_VERSION}") + set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${major}" PARENT_SCOPE) + endif() +endfunction() + +if (${OPENMP_STANDALONE_BUILD}) + # Detect compiler that should be used for testing. + # We cannot use ExternalProject_Add() because its configuration runs when this + # project is built which is too late for detecting the compiler... + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler) + execute_process( + COMMAND ${CMAKE_COMMAND} ${CMAKE_CURRENT_LIST_DIR}/DetectTestCompiler + -DCMAKE_C_COMPILER=${OPENMP_TEST_C_COMPILER} + -DCMAKE_CXX_COMPILER=${OPENMP_TEST_CXX_COMPILER} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler + OUTPUT_VARIABLE DETECT_COMPILER_OUT + ERROR_VARIABLE DETECT_COMPILER_ERR + RESULT_VARIABLE DETECT_COMPILER_RESULT) + if (DETECT_COMPILER_RESULT) + message(STATUS "Could not detect test compilers.") + message(WARNING "The check targets will not be available!") + set(ENABLE_CHECK_TARGETS FALSE) + else() + set_test_compiler_information(${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler) + endif() +else() + # Set the information that we know. + set(OPENMP_TEST_COMPILER_ID "Clang") + # Cannot use CLANG_VERSION because we are not guaranteed that this is already set. + set(OPENMP_TEST_COMPILER_VERSION "${LLVM_VERSION}") + set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${LLVM_MAJOR_VERSION}") + set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp") +endif() + +# Function to set compiler features for use in lit. +function(set_test_compiler_features) + if ("${OPENMP_TEST_COMPILER_ID}" STREQUAL "GNU") + set(comp "gcc") + else() + # Just use the lowercase of the compiler ID as fallback. + string(TOLOWER "${OPENMP_TEST_COMPILER_ID}" comp) + endif() + set(OPENMP_TEST_COMPILER_FEATURES "['${comp}', '${comp}-${OPENMP_TEST_COMPILER_VERSION_MAJOR}', '${comp}-${OPENMP_TEST_COMPILER_VERSION}']" PARENT_SCOPE) +endfunction() +set_test_compiler_features() + # Function to add a testsuite for an OpenMP runtime library. function(add_openmp_testsuite target comment) if (NOT ENABLE_CHECK_TARGETS) Index: libomptarget/test/CMakeLists.txt =================================================================== --- libomptarget/test/CMakeLists.txt +++ libomptarget/test/CMakeLists.txt @@ -1,4 +1,10 @@ # CMakeLists.txt file for unit testing OpenMP offloading runtime library. +if(NOT "${OPENMP_TEST_COMPILER_ID}" STREQUAL "Clang" OR + ${OPENMP_TEST_COMPILER_VERSION} VERSION_LESS 6.0.0) + libomptarget_say("Can only test with Clang compiler in version 6.0.0 or later.") + libomptarget_warning_say("The check-libomptarget target will not be available!") + return() +endif() if(LIBOMPTARGET_CMAKE_BUILD_TYPE MATCHES debug) set(LIBOMPTARGET_DEBUG True) Index: runtime/test/lit.cfg =================================================================== --- runtime/test/lit.cfg +++ runtime/test/lit.cfg @@ -56,8 +56,8 @@ # Allow XFAIL to work config.target_triple = [ ] -if re.search('gcc', config.test_c_compiler) is not None: - config.available_features.add('gcc') +for feature in config.test_compiler_features: + config.available_features.add(feature) # Setup environment to find dynamic library at runtime append_dynamic_library_path(config.library_dir) Index: runtime/test/lit.site.cfg.in =================================================================== --- runtime/test/lit.site.cfg.in +++ runtime/test/lit.site.cfg.in @@ -2,6 +2,7 @@ config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@" config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@" +config.test_compiler_features = @OPENMP_TEST_COMPILER_FEATURES@ config.test_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@" config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@" config.test_extra_flags = "@OPENMP_TEST_FLAGS@" Index: runtime/test/misc_bugs/cancellation_for_sections.c =================================================================== --- runtime/test/misc_bugs/cancellation_for_sections.c +++ runtime/test/misc_bugs/cancellation_for_sections.c @@ -1,5 +1,8 @@ // RUN: %libomp-compile && env OMP_CANCELLATION=true %libomp-run // XFAIL: gcc +// Clang had a bug until version 4.0.1 which resulted in a hang. +// UNSUPPORTED: clang-3, clang-4.0.0 + // Regression test for a bug in cancellation to cover effect of `#pragma omp cancel` // in a loop construct, on sections construct. // Pass condition: Cancellation status from `for` does not persist @@ -59,4 +62,3 @@ printf("PASSED\n"); return 0; } - Index: runtime/test/tasking/kmp_task_reduction_nest.cpp =================================================================== --- runtime/test/tasking/kmp_task_reduction_nest.cpp +++ runtime/test/tasking/kmp_task_reduction_nest.cpp @@ -1,5 +1,7 @@ // RUN: %libomp-cxx-compile-and-run // RUN: %libomp-cxx-compile -DFLG=1 && %libomp-run +// GCC-5 is needed for OpenMP 4.0 support (taskgroup) +// XFAIL: gcc-4 #include #include #include