From 0effc26f5f8ce98739f05c51e91020ed74287abb Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Wed, 13 Oct 2021 05:52:52 +0300 Subject: [PATCH 1/4] Fix build with clang 13 Tested with: ```sh $ clang --version | head -1 Ubuntu clang version 13.0.0-++20211006103153+fd1d8c2f04dd-1~exp1~20211006223759.3 ``` --- eng/native/configurecompiler.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 3e819071f6111..775e75e9b6a19 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -390,6 +390,10 @@ if (CLR_CMAKE_HOST_UNIX) # to a struct or a class that has virtual members or a base class. In that case, clang # may not generate the same object layout as MSVC. add_compile_options(-Wno-incompatible-ms-struct) + + add_compile_options(-Wno-reserved-identifier) + add_compile_options(-Wno-cast-function-type) + add_compile_options(-Wno-unused-but-set-variable) else() add_compile_options(-Wno-unused-but-set-variable) add_compile_options(-Wno-uninitialized) From 78ebd6211ddd366a145c40e608b9242d66d70e23 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Wed, 13 Oct 2021 06:22:13 +0300 Subject: [PATCH 2/4] Fix gcc build --- src/coreclr/jit/morph.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 2f6f32593a717..7e6a4523f2db5 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -10912,7 +10912,7 @@ GenTree* Compiler::fgMorphCastedBitwiseOp(GenTreeOp* tree) // tree op1 // / \ | // op1 op2 ==> tree - // | | / \ + // | | / \. // x y x y // // (op2 becomes garbage) From 6ea6ee60a3fc3045a83941acdc729fc965174983 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Wed, 13 Oct 2021 06:31:05 +0300 Subject: [PATCH 3/4] Unify supressions --- eng/native/configurecompiler.cmake | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 775e75e9b6a19..73434fabb662e 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -367,6 +367,8 @@ if (CLR_CMAKE_HOST_UNIX) #These seem to indicate real issues add_compile_options($<$:-Wno-invalid-offsetof>) + add_compile_options(-Wno-unused-but-set-variable) + if (CMAKE_C_COMPILER_ID MATCHES "Clang") add_compile_options(-Wno-unknown-warning-option) @@ -376,8 +378,6 @@ if (CLR_CMAKE_HOST_UNIX) # Disabled warnings add_compile_options(-Wno-unused-private-field) - # Explicit constructor calls are not supported by clang (this->ClassName::ClassName()) - add_compile_options(-Wno-microsoft) # There are constants of type BOOL used in a condition. But BOOL is defined as int # and so the compiler thinks that there is a mistake. add_compile_options(-Wno-constant-logical-operand) @@ -393,9 +393,7 @@ if (CLR_CMAKE_HOST_UNIX) add_compile_options(-Wno-reserved-identifier) add_compile_options(-Wno-cast-function-type) - add_compile_options(-Wno-unused-but-set-variable) else() - add_compile_options(-Wno-unused-but-set-variable) add_compile_options(-Wno-uninitialized) add_compile_options(-Wno-strict-aliasing) add_compile_options(-Wno-array-bounds) From 177bb989e65dc4a5314086d5975ba0fe38636196 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 13 Oct 2021 06:45:28 +0300 Subject: [PATCH 4/4] Fix Clang 13 -Wcast-function-type warning `cast from 'void (*)(int, siginfo_t *, void *)' to 'void (*)(int)' converts to incompatible function type` But going through an intermediate `void (*) (void)` function type is allowed. --- eng/native/configurecompiler.cmake | 1 - .../Native/Unix/System.Native/pal_process.c | 20 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 73434fabb662e..a29857451bc79 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -392,7 +392,6 @@ if (CLR_CMAKE_HOST_UNIX) add_compile_options(-Wno-incompatible-ms-struct) add_compile_options(-Wno-reserved-identifier) - add_compile_options(-Wno-cast-function-type) else() add_compile_options(-Wno-uninitialized) add_compile_options(-Wno-strict-aliasing) diff --git a/src/libraries/Native/Unix/System.Native/pal_process.c b/src/libraries/Native/Unix/System.Native/pal_process.c index 5e97d958f74d1..fabdfae76187c 100644 --- a/src/libraries/Native/Unix/System.Native/pal_process.c +++ b/src/libraries/Native/Unix/System.Native/pal_process.c @@ -191,6 +191,24 @@ static int SetGroups(uint32_t* userGroups, int32_t userGroupsLength, uint32_t* p return rv; } +typedef void (*VoidIntFn)(int); + +static +VoidIntFn +handler_from_sigaction (struct sigaction *sa) +{ + if (((unsigned int)sa->sa_flags) & SA_SIGINFO) + { + // work around -Wcast-function-type + void (*tmp)(void) = (void (*)(void))sa->sa_sigaction; + return (void (*)(int))tmp; + } + else + { + return sa->sa_handler; + } +} + int32_t SystemNative_ForkAndExecProcess(const char* filename, char* const argv[], char* const envp[], @@ -371,7 +389,7 @@ int32_t SystemNative_ForkAndExecProcess(const char* filename, } if (!sigaction(sig, NULL, &sa_old)) { - void (*oldhandler)(int) = (((unsigned int)sa_old.sa_flags) & SA_SIGINFO) ? (void (*)(int))sa_old.sa_sigaction : sa_old.sa_handler; + void (*oldhandler)(int) = handler_from_sigaction (&sa_old); if (oldhandler != SIG_IGN && oldhandler != SIG_DFL) { // It has a custom handler, put the default handler back.