mjansson / rpmalloc

Public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build failure with recent version of clang

sdefresne opened this issue · comments

When trying to build with a recent version of clang (a218706cba90248be0c60bd6a8f10dbcf0270955), it fails with the following error:

clang -MMD -MT build/ninja/linux/release/x86-64/rpmalloc-a8e50b6/rpmalloc-65d008a.o -MF build/ninja/linux/release/x86-64/rpmalloc-a8e50b6/rpmalloc-65d008a.o.d -I.  -DRPMALLOC_COMPILE=1 -funit-at-a-time -fstrict-aliasing -fvisibility=hidden -fno-stack-protector -fomit-frame-pointer -fno-math-errno -ffinite-math-only -funsafe-math-optimizations -fno-trapping-math -ffast-math -D_GNU_SOURCE=1 -W -Werror -pedantic -Wall -Weverything -Wno-c++98-compat -Wno-padded -Wno-documentation-unknown-command -Wno-implicit-fallthrough -Wno-static-in-inline -Wno-reserved-id-macro -Wno-disabled-macro-expansion -std=c11 -m64 -g -DBUILD_RELEASE=1 -O3 -funroll-loops -DENABLE_PRELOAD=1 -DENABLE_OVERRIDE=1 --target=x86_64-linux-gnu --sysroot=/b/s/w/ir/x/w/cipd/sysroot -c rpmalloc/rpmalloc.c -o build/ninja/linux/release/x86-64/rpmalloc-a8e50b6/rpmalloc-65d008a.o
rpmalloc/rpmalloc.c:869:6: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement]
        int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_UNINITIALIZED;
            ^
rpmalloc/rpmalloc.c:1108:11: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement]
                        size_t remain_count = reserved_count - _memory_heap_reserve_count;
                               ^

This is because -Weverything enables all warnings, even those that are incompatible with the selected standard ("because its point is to enable all warnings, no matter if they make sense or not. (Maybe you want to build your code with a newer standard but keep it somewhat compatible with the old standard or something like that)").

Adding -Wno-declaration-after-statement to the clang command-line suppress this warning and allow the build to succeed.

Sigh, warning about standards before C99 when -std=c11 is present on command line, wonderful ... I'll just add that to the command line then.

Unfortunately, the issue still isn't fixed due to the fact that the first commit in the PR added the right Clang compiler flags, but the second one, which address MacOS issues, removed it!

[1] e0e00ff
[2] f2b3c49

Can we re-open this issue, or get a fix instead?

Oh crap 😢 I reapplied the commit on develop branch, hope it works now.

Well, that happens, thanks for the quick fix :) I confirm that this fixes the issue for us!