Skip to content

Commit

Permalink
Fix build with clang 13 (dotnet#60328)
Browse files Browse the repository at this point in the history
* Fix build with clang 13
Tested with:
```sh
$ clang --version | head -1
Ubuntu clang version 13.0.0-++20211006103153+fd1d8c2f04dd-1~exp1~20211006223759.3
```

* Fix gcc build

* Unify supressions

* 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.

Co-authored-by: Aleksey Kliger <[email protected]>
  • Loading branch information
am11 and lambdageek authored Oct 13, 2021
1 parent c4a15de commit 2265a61
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 4 additions & 3 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ if (CLR_CMAKE_HOST_UNIX)
#These seem to indicate real issues
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-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)

Expand All @@ -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)
Expand All @@ -390,8 +390,9 @@ 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)
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)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10913,7 +10913,7 @@ GenTree* Compiler::fgMorphCastedBitwiseOp(GenTreeOp* tree)
// tree op1
// / \ |
// op1 op2 ==> tree
// | | / \
// | | / \.
// x y x y
//
// (op2 becomes garbage)
Expand Down
20 changes: 19 additions & 1 deletion src/libraries/Native/Unix/System.Native/pal_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2265a61

Please sign in to comment.