From f6746a3cc334e986c6fd9d7df80b6c13c9a38af6 Mon Sep 17 00:00:00 2001 From: Omair Majid Date: Fri, 16 Feb 2018 07:18:00 -0500 Subject: [PATCH] Fix build on clang 5 (dotnet/corefx#27178) This contains two fixes, both related to new warnings introduced with clang 5: http://releases.llvm.org/5.0.0/tools/clang/docs/ReleaseNotes.html 1. clang 5 introduces a -Wzero-as-null-pointer-constant warning, which becomes an error with Werror. This warning is not known by older versions of clang and affects a lot of C/C++ code, such as: static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; It also affects code we pick up from our dependency libraries. Lets check if the compiler knows about this warning and disable it if so. 2. clang 5 introduces checks for casts. The library expects a `char *`, so lets cast our pointer to the expected type so it will continue working. Commit migrated from https://github.com/dotnet/corefx/commit/a9f4a46f48baeaadd515d85ac9de1249b8023a5a --- src/libraries/Native/Unix/CMakeLists.txt | 3 +++ .../Native/Unix/System.Security.Cryptography.Native/pal_ssl.cpp | 2 +- src/libraries/Native/Unix/configure.cmake | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libraries/Native/Unix/CMakeLists.txt b/src/libraries/Native/Unix/CMakeLists.txt index 739c2d2..7d804a1 100644 --- a/src/libraries/Native/Unix/CMakeLists.txt +++ b/src/libraries/Native/Unix/CMakeLists.txt @@ -259,6 +259,9 @@ add_subdirectory(System.IO.Compression.Native) add_compile_options(-Weverything) add_compile_options(-Wno-c++98-compat-pedantic) +if (HAVE_ZERO_AS_NULL_POINTER_CONSTANT_FLAG) + add_compile_options(-Wno-zero-as-null-pointer-constant) +endif() add_subdirectory(System.Native) add_subdirectory(System.Net.Http.Native) diff --git a/src/libraries/Native/Unix/System.Security.Cryptography.Native/pal_ssl.cpp b/src/libraries/Native/Unix/System.Security.Cryptography.Native/pal_ssl.cpp index 3e40d6c..7489aff 100644 --- a/src/libraries/Native/Unix/System.Security.Cryptography.Native/pal_ssl.cpp +++ b/src/libraries/Native/Unix/System.Security.Cryptography.Native/pal_ssl.cpp @@ -609,6 +609,6 @@ extern "C" void CryptoNative_SslGet0AlpnSelected(SSL* ssl, const uint8_t** proto extern "C" int32_t CryptoNative_SslSetTlsExtHostName(SSL* ssl, const uint8_t* name) { - return static_cast(SSL_set_tlsext_host_name(ssl, name)); + return static_cast(SSL_set_tlsext_host_name(ssl, const_cast(name))); } diff --git a/src/libraries/Native/Unix/configure.cmake b/src/libraries/Native/Unix/configure.cmake index 497dc21..8e7726f 100644 --- a/src/libraries/Native/Unix/configure.cmake +++ b/src/libraries/Native/Unix/configure.cmake @@ -1,3 +1,4 @@ +include(CheckCXXCompilerFlag) include(CheckCXXSourceCompiles) include(CheckCXXSourceRuns) include(CheckCSourceCompiles) @@ -29,6 +30,13 @@ endif () # We compile with -Werror, so we need to make sure these code fragments compile without warnings. set(CMAKE_REQUIRED_FLAGS -Werror) +# This compiler warning will fail code as innocuous as: +# static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +# Check if the compiler knows about this warning so we can disable it +check_cxx_compiler_flag( + -Wzero-as-null-pointer-constant + HAVE_ZERO_AS_NULL_POINTER_CONSTANT_FLAG) + # in_pktinfo: Find whether this struct exists check_include_files( "sys/socket.h;linux/in.h" -- 2.7.4