Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set warnings on tests as well as src #8022

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,80 @@ if (TARGET_VULKAN)
set(TARGET_SPIRV ON) # required
endif()

# Helper function to set C++ compiler warnings in a sane way
function(set_halide_compiler_warnings NAME)
target_compile_options(
${NAME}
PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall>

# variable length arrays in C++ are a Clang extension, we don't want to use them
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wvla-extension>

$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wcast-qual>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wignored-qualifiers>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Woverloaded-virtual>

$<$<CXX_COMPILER_ID:GNU>:-Wsuggest-override>

$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Winconsistent-missing-destructor-override>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Winconsistent-missing-override>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wdeprecated-declarations>

$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-double-promotion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-float-conversion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-float-equal>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-missing-field-initializers>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-old-style-cast>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-shadow>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-sign-conversion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-switch-enum>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-undef>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-function>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-macros>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-parameter>

$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-c++98-compat-pedantic>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-c++98-compat>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-cast-align>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-comma>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-covered-switch-default>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-documentation-unknown-command>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-documentation>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-exit-time-destructors>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-global-constructors>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-implicit-float-conversion>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-implicit-int-conversion>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-implicit-int-float-conversion>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-missing-prototypes>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-nonportable-system-include-path>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-reserved-id-macro>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-shadow-field-in-constructor>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-shadow-field>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-shorten-64-to-32>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-undefined-func-template>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-member-function>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-template>

# This warning was removed in Clang 13
$<$<AND:$<CXX_COMPILER_ID:Clang,AppleClang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,13.0>>:-Wno-return-std-move-in-c++11>

$<$<CXX_COMPILER_ID:MSVC>:/W3>
$<$<CXX_COMPILER_ID:MSVC>:/wd4018> # 4018: disable "signed/unsigned mismatch"
$<$<CXX_COMPILER_ID:MSVC>:/wd4141> # 4141: 'inline' used more than once
$<$<CXX_COMPILER_ID:MSVC>:/wd4146> # 4146: unary minus applied to unsigned type
$<$<CXX_COMPILER_ID:MSVC>:/wd4244> # 4244: conversion, possible loss of data
$<$<CXX_COMPILER_ID:MSVC>:/wd4267> # 4267: conversion from 'size_t' to 'int', possible loss of data
$<$<CXX_COMPILER_ID:MSVC>:/wd4291> # 4291: No matching operator delete found
$<$<CXX_COMPILER_ID:MSVC>:/wd4503> # 4503: disable "decorated name length exceeded, name was truncated"
$<$<CXX_COMPILER_ID:MSVC>:/wd4800> # 4800: forcing value to bool 'true' or 'false' (performance warning)

# No: enable deprecation warnings
# $<$<CXX_COMPILER_ID:MSVC>:/wd4996> # 4996: compiler encountered deprecated declaration
)
endfunction()


##
# Import dependencies
##
Expand Down
1 change: 1 addition & 0 deletions cmake/HalideTestHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function(add_halide_test TARGET)
add_test(NAME ${TARGET}
COMMAND ${args_COMMAND} ${args_ARGS}
WORKING_DIRECTORY "${args_WORKING_DIRECTORY}")
set_halide_compiler_warnings(${TARGET})

# We can't add Halide::TerminateHandler here, because it requires Halide::Error
# and friends to be present in the final linkage, but some callers of add_halide_test()
Expand Down
68 changes: 1 addition & 67 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -575,73 +575,7 @@ endif ()
##
# Set compiler options for libHalide
##

target_compile_options(
Halide
PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall>

$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wcast-qual>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wignored-qualifiers>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Woverloaded-virtual>

$<$<CXX_COMPILER_ID:GNU>:-Wsuggest-override>

$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Winconsistent-missing-destructor-override>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Winconsistent-missing-override>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wdeprecated-declarations>

$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-double-promotion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-float-conversion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-float-equal>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-missing-field-initializers>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-old-style-cast>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-shadow>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-sign-conversion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-switch-enum>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-undef>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-function>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-macros>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-parameter>

$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-c++98-compat-pedantic>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-c++98-compat>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-cast-align>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-comma>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-covered-switch-default>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-documentation-unknown-command>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-documentation>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-exit-time-destructors>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-global-constructors>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-implicit-float-conversion>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-implicit-int-conversion>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-implicit-int-float-conversion>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-missing-prototypes>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-nonportable-system-include-path>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-reserved-id-macro>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-shadow-field-in-constructor>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-shadow-field>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-shorten-64-to-32>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-undefined-func-template>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-member-function>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-template>

# This warning was removed in Clang 13
$<$<AND:$<CXX_COMPILER_ID:Clang,AppleClang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,13.0>>:-Wno-return-std-move-in-c++11>

$<$<CXX_COMPILER_ID:MSVC>:/W3>
$<$<CXX_COMPILER_ID:MSVC>:/wd4018> # 4018: disable "signed/unsigned mismatch"
$<$<CXX_COMPILER_ID:MSVC>:/wd4141> # 4141: 'inline' used more than once
$<$<CXX_COMPILER_ID:MSVC>:/wd4146> # 4146: unary minus applied to unsigned type
$<$<CXX_COMPILER_ID:MSVC>:/wd4244> # 4244: conversion, possible loss of data
$<$<CXX_COMPILER_ID:MSVC>:/wd4267> # 4267: conversion from 'size_t' to 'int', possible loss of data
$<$<CXX_COMPILER_ID:MSVC>:/wd4291> # 4291: No matching operator delete found
$<$<CXX_COMPILER_ID:MSVC>:/wd4503> # 4503: disable "decorated name length exceeded, name was truncated"
$<$<CXX_COMPILER_ID:MSVC>:/wd4800> # 4800: forcing value to bool 'true' or 'false' (performance warning)

# No: enable deprecation warnings
# $<$<CXX_COMPILER_ID:MSVC>:/wd4996> # 4996: compiler encountered deprecated declaration
)
set_halide_compiler_warnings(Halide)

if (CMAKE_GENERATOR MATCHES "Visual Studio")
# We could expose the /MP flag to all targets, but that might end up saturating the build
Expand Down
1 change: 1 addition & 0 deletions test/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function(_set_target_options NAME)
COMPILING_HALIDE_RUNTIME
COMPILING_HALIDE_RUNTIME_TESTS
)
set_halide_compiler_warnings(${NAME})
endfunction()

function(halide_define_runtime_internal_test NAME)
Expand Down
4 changes: 2 additions & 2 deletions test/runtime/memory_arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char **argv) {
MemoryArena::Config config = {sizeof(double), 32, 0};
MemoryArena *arena = MemoryArena::create(user_context, config, test_allocator);

size_t count = 4 * 1024;
constexpr size_t count = 4 * 1024;
void *pointers[count];
for (size_t n = 0; n < count; ++n) {
pointers[n] = arena->reserve(user_context, true);
Expand Down Expand Up @@ -75,7 +75,7 @@ int main(int argc, char **argv) {

arena.destroy(user_context);

size_t count = 4 * 1024;
constexpr size_t count = 4 * 1024;
void *pointers[count];
for (size_t n = 0; n < count; ++n) {
pointers[n] = arena.reserve(user_context, true);
Expand Down