Repository navigation
[#204] Add version coverage for clang and gcc - #209
Conversation
|
@Jubilee101 Cc: |
|
@bassamadnan Can you look at the warnings ? Some should be fixed, and some should be ignored |
|
@jesperpedersen do you mean the Wall/Wextra warnings or are there some make warnings? |
|
All the warnings when compiling - check clang/Debug -- using 19.1.7 here |
|
@jesperpedersen yes i would be happy to take a look at them! I think priority for now is
I am using Clang 20+ and i do see quite a few warnings; i think we can have an issue for it? I will ask to be assigned. Will work on them accross the next few days and crosscheck with gcc too whenever i can. I hope this sounds fine |
|
Just do them as part of this |
|
@jesperpedersen There's alot of comparision related errors, should i typecast it or redefine the datatypes? also a few unused variable errors, should i just remove them? |
|
Redefine. The unused are likely due to APIs where they are necessary - so you need to add an ignore if that is the case |
|
|
|
I added unused attribute so compiler excludes the parameters from warnings. Some places are hard to fix without refactoring, if I naively typecast |
| offset = 0; | ||
|
|
||
| while (offset < data_length) | ||
| while (offset < (size_t) data_length) |
There was a problem hiding this comment.
This is the only place i've typcasted at
There was a problem hiding this comment.
Hi, i fixed whatever looked fine. Could you please have a look ? @jesperpedersen .
|
I'm getting warns from -Wsign-compare |
|
gcc says |
I think you might have to build again, i Just to be sure i run this: The clang warnings I had left were intentional, but i'll remove those warnings by typcasting during comparision (Do we really want this?) . Same for gcc edit: for gcc alot of them come from our macro usage of MIN, should be safe to ignore this i feel |
|
gcc (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7) |
|
|
|
I could typecast them inside the MIN function before calling the macro or modify the MIN macro to convert to the larger integer type before checking like this: (sizeof(_a) >= sizeof(_b)) ? \
(_a < (__typeof__(_a))_b ? _a : (__typeof__(_a))_b) : \
((__typeof__(_b))_a < _b ? (__typeof__(_b))_a : _b); \I am strongly considering disabling the About the make error happening , I am not sure but the error message indicates it cant find the address sanitizer library I think? Which is weird. GCC 14 should have support for the asan flag. I'll get rid of the remaining clang warnings. |
|
Ah, it is 2 packages extra That need to be documented |
|
Yeah, just remove sign-compare for both, and unused-parameter for gcc |
I'll add that in this PR, in the same .md i have added. I don't explicitly remember installing it; they mightve come with the compiler. Glad this worked though i was abit freaked out. |
| /* Sleep for 100ms */ | ||
| SLEEP(100000000L); | ||
| } | ||
| __attribute__((fallthrough)); |
There was a problem hiding this comment.
put this here to remove the fall through warning, i think a break; is supposed to be here
There was a problem hiding this comment.
I kept the unused parameter warning for both. I realized the way gcc/clang handles __attribute is abit different so I just kept it in a standard way. No more errors now.
|
Do a It seems that a lot need to be sync'ed with README.md (and PostgreSQL 17) too... |
|
is this fine? @jesperpedersen |
|
|
||
| add_compile_options(-fno-sanitize=alignment) | ||
|
|
||
| set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment") |
There was a problem hiding this comment.
There was a problem hiding this comment.
tried it, among other things, it just does not work and fails to find refferences (linking).
Code block for Debug section
# Debug
if (CMAKE_BUILD_TYPE MATCHES Debug)
add_compile_options(-O0)
add_compile_options(-DDEBUG)
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
if (NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.2)
add_compile_options(-fsanitize=address)
add_compile_options(-fno-sanitize=null)
add_link_options(-fsanitize=address -fno-sanitize=null)
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.3)
add_compile_options(-fsanitize=undefined)
add_compile_options(-fsanitize=float-divide-by-zero)
add_compile_options(-fsanitize=float-cast-overflow)
add_link_options(-fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow)
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.6)
add_compile_options(-fno-sanitize-recover=all)
add_link_options(-fno-sanitize-recover=all)
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.8)
add_compile_options(-fsanitize-recover=address)
add_link_options(-fsanitize-recover=address)
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.9)
add_compile_options(-fsanitize-address-use-after-scope)
add_link_options(-fsanitize-address-use-after-scope)
endif()
add_compile_options(-fno-sanitize=alignment)
add_link_options(-fno-sanitize=alignment)
endif()
endif()
endif()
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
if (NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
add_compile_options(-fsanitize=address)
set(TEMP_EXE_LINKER_FLAGS "-fsanitize=address")
set(TEMP_SHARED_LINKER_FLAGS "-fsanitize=address")
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9)
add_compile_options(-fsanitize=undefined)
set(TEMP_EXE_LINKER_FLAGS "${TEMP_EXE_LINKER_FLAGS} -fsanitize=undefined")
set(TEMP_SHARED_LINKER_FLAGS "${TEMP_SHARED_LINKER_FLAGS} -fsanitize=undefined")
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.1)
add_compile_options(-fno-sanitize=alignment)
add_compile_options(-fno-sanitize-recover=all)
add_compile_options(-fsanitize=float-cast-overflow)
add_compile_options(-fsanitize=float-divide-by-zero)
set(TEMP_EXE_LINKER_FLAGS "${TEMP_EXE_LINKER_FLAGS} -fno-sanitize=alignment -fno-sanitize-recover=all -fsanitize=float-cast-overflow -fsanitize=float-divide-by-zero")
set(TEMP_SHARED_LINKER_FLAGS "${TEMP_SHARED_LINKER_FLAGS} -fno-sanitize=alignment -fno-sanitize-recover=all -fsanitize=float-cast-overflow -fsanitize=float-divide-by-zero")
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
add_compile_options(-fsanitize-recover=address)
set(TEMP_EXE_LINKER_FLAGS "${TEMP_EXE_LINKER_FLAGS} -fsanitize-recover=address")
set(TEMP_SHARED_LINKER_FLAGS "${TEMP_SHARED_LINKER_FLAGS} -fsanitize-recover=address")
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0)
add_compile_options(-fsanitize-address-use-after-scope)
set(TEMP_EXE_LINKER_FLAGS "${TEMP_EXE_LINKER_FLAGS} -fsanitize-address-use-after-scope")
set(TEMP_SHARED_LINKER_FLAGS "${TEMP_SHARED_LINKER_FLAGS} -fsanitize-address-use-after-scope")
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEMP_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${TEMP_SHARED_LINKER_FLAGS}")
endif()
endif()
endif()
endif()
check_c_compiler_flag(-fno-omit-frame-pointer HAS_NO_OMIT_FRAME_POINTER)
if (HAS_NO_OMIT_FRAME_POINTER)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer")
endif()
check_c_compiler_flag(-Wextra HAS_WEXTRA)
if (HAS_WEXTRA)
add_compile_options(-Wextra)
check_c_compiler_flag(-Wno-sign-compare HAS_NO_SIGN_COMPARE)
if (HAS_NO_SIGN_COMPARE)
add_compile_options(-Wno-sign-compare)
endif()
endif()
endif()
|
@bassamadnan Otherwise it looks ok |
|
Merged. Thanks for your contribution ! |
|
@bassamadnan Please, port this patch to pgagroal and pgmoneta |
yessir will be on it, i'll fix the warnings produced too (first without disabling the sign compare flag) wherever I can. |
Added the sanitizer flags for Debug builds with version checking, new flags added are
-fsanitize-address-use-after-scope: helps detecting when a variable is accessed after it has gone out of scope such as when a pointer to a local variable continues to be used after the function returns or when a reference to a variable in an inner scope is accessed after that scope ends.-fsanitize-recover=address: continues execution after error detection.-Wextrafor extra warnings around operatorsRest are unchanged, heres a minimum version report for each of the flags.
Clang Sanitizer Flags
GCC Sanitizer Flags
These were added by testing them on godbolt. They provide their APIs so I sent it requests for each of the versions available. Apart from that I manually downloaded the source code from LLVM repositry (for their flags and sanitzer args) and from the gcc repositry and wrote a script to check these flags using string matching accross different version files. These can be found here. I have cross checked the results from godbolt as well.
The implementation of clang is abit different from gcc because clang depeends on the order in which these flags are added otherwise we run into linking issues, and the version check is done for the minimum version after which it has continously been supported (some flags in clang have disruptions where they throw errors). This wouldn't matter since the compiler version which has support for C17 will not run into these issues. I hope this looks fine.