mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 07:31:28 +00:00
[CMake] Detect information about test compiler
Perform a nested CMake invocation to avoid writing our own parser for compiler versions when we are not testing the in-tree compiler. Use the extracted information to mark a test as unsupported that hangs with Clang prior to version 4.0.1 and restrict tests for libomptarget to Clang version 6.0.0 and later. Differential Revision: https://reviews.llvm.org/D40083 llvm-svn: 319448
This commit is contained in:
parent
c7832045d5
commit
fc473dee98
@ -48,7 +48,7 @@ include(OpenMPTesting)
|
||||
|
||||
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.")
|
||||
|
||||
|
||||
|
19
openmp/cmake/DetectTestCompiler/CMakeLists.txt
Normal file
19
openmp/cmake/DetectTestCompiler/CMakeLists.txt
Normal file
@ -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)
|
@ -61,6 +61,81 @@ else()
|
||||
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)
|
||||
|
@ -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)
|
||||
@ -6,30 +12,6 @@ else()
|
||||
set(LIBOMPTARGET_DEBUG False)
|
||||
endif()
|
||||
|
||||
if(${OPENMP_STANDALONE_BUILD})
|
||||
if (NOT(${OPENMP_TEST_C_COMPILER} MATCHES "clang" AND ${OPENMP_TEST_CXX_COMPILER} MATCHES "clang"))
|
||||
libomptarget_say("Can only test with Clang compiler!")
|
||||
libomptarget_warning_say("The check-libomptarget target will not be available!")
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${OPENMP_TEST_C_COMPILER} --version
|
||||
OUTPUT_VARIABLE TEST_COMPILER_VERSION)
|
||||
string(REGEX MATCH "version ([0-9.]+)" TEST_COMPILER_VERSION ${TEST_COMPILER_VERSION})
|
||||
if (NOT(TEST_COMPILER_VERSION))
|
||||
libomptarget_say("Unable to determine Clang compiler version!")
|
||||
libomptarget_warning_say("The check-libomptarget target will not be available!")
|
||||
return()
|
||||
endif()
|
||||
set(TEST_COMPILER_VERSION ${CMAKE_MATCH_1})
|
||||
if (TEST_COMPILER_VERSION VERSION_LESS 6.0.0)
|
||||
libomptarget_say("Clang compiler version does not implement all codegen, please update to 6.0.0!")
|
||||
libomptarget_warning_say("The check-libomptarget target will not be available!")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_openmp_testsuite(check-libomptarget "Running libomptarget tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS omptarget omp)
|
||||
|
||||
if(${OPENMP_STANDALONE_BUILD})
|
||||
|
@ -56,8 +56,8 @@ if config.has_libatomic:
|
||||
|
||||
# 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)
|
||||
|
@ -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@"
|
||||
|
@ -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 @@ int main(void) {
|
||||
printf("PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -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 <cstdio>
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
|
Loading…
Reference in New Issue
Block a user