Skip to content

Commit 45cd185

Browse files
am11lambdageek
andcommitted
Fix build with clang 13 (dotnet#60328)
* 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 <aleksey@lambdageek.org>
1 parent 2da6a44 commit 45cd185

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

eng/native/configurecompiler.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ if (CLR_CMAKE_HOST_UNIX)
367367
#These seem to indicate real issues
368368
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-invalid-offsetof>)
369369

370+
add_compile_options(-Wno-unused-but-set-variable)
371+
370372
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
371373
add_compile_options(-Wno-unknown-warning-option)
372374

@@ -376,8 +378,6 @@ if (CLR_CMAKE_HOST_UNIX)
376378

377379
# Disabled warnings
378380
add_compile_options(-Wno-unused-private-field)
379-
# Explicit constructor calls are not supported by clang (this->ClassName::ClassName())
380-
add_compile_options(-Wno-microsoft)
381381
# There are constants of type BOOL used in a condition. But BOOL is defined as int
382382
# and so the compiler thinks that there is a mistake.
383383
add_compile_options(-Wno-constant-logical-operand)
@@ -390,8 +390,9 @@ if (CLR_CMAKE_HOST_UNIX)
390390
# to a struct or a class that has virtual members or a base class. In that case, clang
391391
# may not generate the same object layout as MSVC.
392392
add_compile_options(-Wno-incompatible-ms-struct)
393+
394+
add_compile_options(-Wno-reserved-identifier)
393395
else()
394-
add_compile_options(-Wno-unused-but-set-variable)
395396
add_compile_options(-Wno-uninitialized)
396397
add_compile_options(-Wno-strict-aliasing)
397398
add_compile_options(-Wno-array-bounds)

src/libraries/Native/Unix/System.Native/pal_process.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,24 @@ static int SetGroups(uint32_t* userGroups, int32_t userGroupsLength, uint32_t* p
191191
return rv;
192192
}
193193

194+
typedef void (*VoidIntFn)(int);
195+
196+
static
197+
VoidIntFn
198+
handler_from_sigaction (struct sigaction *sa)
199+
{
200+
if (((unsigned int)sa->sa_flags) & SA_SIGINFO)
201+
{
202+
// work around -Wcast-function-type
203+
void (*tmp)(void) = (void (*)(void))sa->sa_sigaction;
204+
return (void (*)(int))tmp;
205+
}
206+
else
207+
{
208+
return sa->sa_handler;
209+
}
210+
}
211+
194212
int32_t SystemNative_ForkAndExecProcess(const char* filename,
195213
char* const argv[],
196214
char* const envp[],
@@ -371,7 +389,7 @@ int32_t SystemNative_ForkAndExecProcess(const char* filename,
371389
}
372390
if (!sigaction(sig, NULL, &sa_old))
373391
{
374-
void (*oldhandler)(int) = (((unsigned int)sa_old.sa_flags) & SA_SIGINFO) ? (void (*)(int))sa_old.sa_sigaction : sa_old.sa_handler;
392+
void (*oldhandler)(int) = handler_from_sigaction (&sa_old);
375393
if (oldhandler != SIG_IGN && oldhandler != SIG_DFL)
376394
{
377395
// It has a custom handler, put the default handler back.

0 commit comments

Comments
 (0)