Skip to content

Commit 8b7f165

Browse files
Merge pull request #21 from OliverKillane/enh/add-warning-checks
Improved testing with linting checks and higher instantiation coverage
2 parents 7df1e64 + 2ff6b85 commit 8b7f165

File tree

126 files changed

+1651
-1000
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1651
-1000
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Checks: >
88
misc-*,
99
-misc-no-recursion,
1010
performance-*,
11+
-performance-no-int-to-ptr,
1112
portability-*,
1213
readability-*,
1314
-readability-braces-around-statements,
@@ -17,6 +18,7 @@ Checks: >
1718
-readability-avoid-const-params-in-decls,
1819
-readability-implicit-bool-conversion,
1920
-readability-duplicate-include,
21+
-readability-redundant-casting,
2022
-bugprone-macro-parentheses,
2123
-misc-non-private-member-variables-in-classes,
2224
-clang-diagnostic-*,

CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,46 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1919
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
2020
endif()
2121

22+
# Warnings
23+
# Applied to the derive-c (c compiled) examples, and for warning tests.
24+
# - Not used for tests, as these are not a product of the library, and as rapidcheck and gtest
25+
# fail many stricter warnings.
26+
add_library(dc_warnings_c INTERFACE)
27+
target_compile_options(dc_warnings_c INTERFACE
28+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wall>
29+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wextra>
30+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wpedantic>
31+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Werror>
32+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wformat=2>
33+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wformat-security>
34+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wnull-dereference>
35+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wvla>
36+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wcast-align>
37+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wwrite-strings>
38+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wconversion>
39+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wsign-conversion>
40+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wshadow>
41+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wundef>
42+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wpointer-arith>
43+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wswitch-enum>
44+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wmissing-noreturn>
45+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wimplicit-fallthrough>
46+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wunreachable-code>
47+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wdouble-promotion>
48+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wfloat-equal>
49+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wstrict-aliasing>
50+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wstrict-prototypes>
51+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wmissing-prototypes>
52+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wmissing-declarations>
53+
54+
# We expect to have unused functions when analysing the library without user code.
55+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wno-unused-function>
56+
57+
# We allow for empty structs (required to keep the release overhead of debug
58+
# only memory tracking, invalidation tracking zero)
59+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Wno-gnu-empty-struct>
60+
)
61+
2262
# Sanitizers
2363
# - Supporting address,undefined by default. Msan and tsan are enableable separately.
2464
# - Defaulted only in debug

docs/Doxyfile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ HTML_EXTRA_FILES = @AWESOME_CSS_DIR@/doxygen-awesome-darkmode-toggle.js \
6464
@AWESOME_CSS_DIR@/doxygen-awesome-paragraph-link.js \
6565
@AWESOME_CSS_DIR@/doxygen-custom/toggle-alternative-theme.js \
6666
@AWESOME_CSS_DIR@/doxygen-awesome-interactive-toc.js \
67-
@AWESOME_CSS_DIR@/doxygen-awesome-tabs.js
67+
@AWESOME_CSS_DIR@/doxygen-awesome-tabs.js

examples/CMakeLists.txt

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
1+
# Examples
12

23
# Optional toggle for dumping IR (very noisy)
34
option(CLANG_IR_DUMPS "Dump IR before/after all passes" OFF)
45

5-
# TODO(oliverkillane): get the ui for opt reports working
66
function(enable_clang_opt_reports target)
7-
# C
87
target_compile_options(${target} PRIVATE
9-
$<$<COMPILE_LANG_AND_ID:C,Clang>:
10-
-gline-tables-only
11-
-Rpass=inline -Rpass-missed=inline -Rpass-analysis=inline
12-
-Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize
13-
-Rpass=slp-vectorizer -Rpass-missed=slp-vectorizer -Rpass-analysis=slp-vectorizer
14-
-fsave-optimization-record
15-
-Xclang -fdebug-pass-manager
16-
>
17-
)
18-
19-
# C++
20-
target_compile_options(${target} PRIVATE
21-
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:
22-
-gline-tables-only
23-
-Rpass=inline -Rpass-missed=inline -Rpass-analysis=inline
24-
-Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize
25-
-Rpass=slp-vectorizer -Rpass-missed=slp-vectorizer -Rpass-analysis=slp-vectorizer
26-
-fsave-optimization-record
27-
-Xclang -fdebug-pass-manager
28-
>
8+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-gline-tables-only>
9+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Rpass=inline>
10+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Rpass-missed=inline>
11+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Rpass-analysis=inline>
12+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Rpass=loop-vectorize>
13+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Rpass-missed=loop-vectorize>
14+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Rpass-analysis=loop-vectorize>
15+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Rpass=slp-vectorizer>
16+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Rpass-missed=slp-vectorizer>
17+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Rpass-analysis=slp-vectorizer>
18+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-fsave-optimization-record>
19+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-Xclang>
20+
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-fdebug-pass-manager>
2921
)
3022
endfunction()
3123

@@ -37,11 +29,14 @@ function(add_example file)
3729
string(REPLACE "/" "_" example_target_safe "${example_target}")
3830

3931
add_executable(${example_target_safe} ${file})
32+
33+
target_link_libraries(${example_target_safe} PRIVATE derivec dc_warnings_c)
34+
4035
if(OPT_REPORTS)
4136
enable_clang_opt_reports(${example_target_safe})
4237
endif()
4338

44-
set_target_properties(${example_target_safe} PROPERTIES
39+
set_target_properties(${example_target_safe} PROPERTIES
4540
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${example_dir}"
4641
OUTPUT_NAME "${example_name_we}"
4742
)
@@ -52,14 +47,13 @@ function(add_example file)
5247
set_property(GLOBAL APPEND PROPERTY EXAMPLE_TARGETS ${example_target_safe})
5348

5449
add_test(NAME examples/${example_target} COMMAND $<TARGET_FILE:${example_target_safe}>)
55-
set_tests_properties(examples/${example_target}
50+
set_tests_properties(examples/${example_target}
5651
PROPERTIES
57-
DEPENDS ${example_target_safe}
52+
DEPENDS ${example_target_safe}
5853
LABELS "examples"
5954
)
6055
endfunction()
6156

62-
6357
file(GLOB_RECURSE EXAMPLES "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
6458

6559
foreach(EXAMPLE_FILE ${EXAMPLES})
@@ -70,7 +64,7 @@ if(OPT_REPORTS)
7064
# (optional) ensure the tool exists
7165
find_program(LLVM_OPT_REPORT llvm-opt-report REQUIRED)
7266

73-
# NEW: fetch the list of example targets
67+
# fetch the list of example targets
7468
get_property(_examples GLOBAL PROPERTY EXAMPLE_TARGETS)
7569

7670
file(GLOB_RECURSE OPT_YAMLS "${CMAKE_BINARY_DIR}/*.opt.yaml")
@@ -86,4 +80,4 @@ if(OPT_REPORTS)
8680
COMMENT "Generating HTML optimization report"
8781
VERBATIM
8882
)
89-
endif()
83+
endif()

examples/basic/alloc/hybridstatic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

22
#include <stdio.h>
3-
#include <derive-c/core/prelude.h>
3+
#include <derive-c/prelude.h>
44
#include <derive-c/alloc/std.h>
55

66
#define ALLOC stdalloc
77
#define CAPACITY 1024
88
#define NAME foopool
99
#include <derive-c/alloc/hybridstatic/template.h>
1010

11-
void foopool_raw_example() {
11+
static void foopool_raw_example() {
1212
foopool_buffer buf;
1313
foopool pool = foopool_new(&buf, stdalloc_get_ref());
1414

examples/basic/container/arena/basic.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
#include <derive-c/utils/for.h>
99

1010
#include <derive-c/alloc/std.h>
11-
#include <derive-c/core/prelude.h>
11+
#include <derive-c/prelude.h>
1212

1313
#define INDEX_BITS 32
1414
#define VALUE uint32_t
1515
#define NAME ints
1616
#include <derive-c/container/arena/contiguous/template.h>
1717

18-
void int_example() {
18+
static void int_example() {
1919
ints arena = ints_new_with_capacity_for(12, stdalloc_get_ref());
2020
ints_insert(&arena, 23);
2121
ints_insert(&arena, 42);
@@ -48,15 +48,15 @@ struct foo {
4848
int* owned_data;
4949
};
5050

51-
void my_foo_delete(struct foo* self) { free(self->owned_data); }
51+
static void my_foo_delete(struct foo* self) { free(self->owned_data); }
5252

53-
void foo_debug(struct foo const* self, dc_debug_fmt fmt, FILE* stream) {
53+
static void foo_debug(struct foo const* self, dc_debug_fmt fmt, FILE* stream) {
5454
(void)fmt;
5555
fprintf(stream, "foo@%p { x: %d, y: \"%s\", owned_data: @%p { %d }, }", self, self->x, self->y,
5656
self->owned_data, *self->owned_data);
5757
}
5858

59-
int* new_owned_int(int value) {
59+
static int* new_owned_int(int value) {
6060
int* v = (int*)malloc(sizeof(int));
6161
*v = value;
6262
return v;
@@ -69,7 +69,7 @@ int* new_owned_int(int value) {
6969
#define NAME foo_arena
7070
#include <derive-c/container/arena/contiguous/template.h>
7171

72-
void foo_example() {
72+
static void foo_example() {
7373
foo_arena arena = foo_arena_new_with_capacity_for(12, stdalloc_get_ref());
7474
foo_arena_index_t index_a =
7575
foo_arena_insert(&arena, (struct foo){.x = 42, .y = "A", .owned_data = new_owned_int(3)});

examples/basic/container/map/decomposed.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <derive-c/algorithm/hash/combine.h>
1515

1616
#include <derive-c/alloc/std.h>
17-
#include <derive-c/core/prelude.h>
17+
#include <derive-c/prelude.h>
1818
#include <derive-c/utils/for.h>
1919

2020
#define KEY uint32_t
@@ -23,7 +23,7 @@
2323
#define NAME id_to_name
2424
#include <derive-c/container/map/decomposed/template.h>
2525

26-
void print_map(id_to_name const* map) {
26+
static void print_map(id_to_name const* map) {
2727
printf("Map has items:\n");
2828
size_t pos = 0;
2929
DC_FOR_CONST(id_to_name, map, iter, entry) {
@@ -32,7 +32,7 @@ void print_map(id_to_name const* map) {
3232
}
3333
}
3434

35-
void id_to_name_example() {
35+
static void id_to_name_example() {
3636
printf("Id to Name Map Example:\n");
3737
id_to_name map = id_to_name_new(stdalloc_get_ref());
3838

@@ -59,34 +59,34 @@ struct report_id {
5959
uint32_t section;
6060
};
6161

62-
void report_id_debug(struct report_id const* self, dc_debug_fmt fmt, FILE* stream) {
62+
static void report_id_debug(struct report_id const* self, dc_debug_fmt fmt, FILE* stream) {
6363
(void)fmt;
6464
fprintf(stream, " report_id@%p { name: \"%s\", section: %d}", self, self->name, self->section);
6565
}
6666

67-
bool report_id_equality(struct report_id const* report_1, struct report_id const* report_2) {
67+
static bool report_id_equality(struct report_id const* report_1, struct report_id const* report_2) {
6868
return strcmp(report_1->name, report_2->name) == 0 && report_1->section == report_2->section;
6969
}
7070

71-
size_t report_id_hash(struct report_id const* report_id) {
71+
static size_t report_id_hash(struct report_id const* report_id) {
7272
return dc_hash_combine(dc_murmur_hash_string(report_id->name),
7373
uint32_t_hash_id(&report_id->section));
7474
}
7575

76-
void report_id_delete(struct report_id* self) { free(self->name); }
76+
static void report_id_delete(struct report_id* self) { free(self->name); }
7777

7878
struct report {
7979
char* description;
8080
int value;
8181
};
8282

83-
void report_debug(struct report const* self, dc_debug_fmt fmt, FILE* stream) {
83+
static void report_debug(struct report const* self, dc_debug_fmt fmt, FILE* stream) {
8484
(void)fmt;
8585
fprintf(stream, " report@%p { description: \"%s\", value: %d}", self, self->description,
8686
self->value);
8787
}
8888

89-
void report_delete(struct report* self) { free(self->description); }
89+
static void report_delete(struct report* self) { free(self->description); }
9090

9191
#define KEY struct report_id
9292
#define KEY_EQ report_id_equality
@@ -99,7 +99,7 @@ void report_delete(struct report* self) { free(self->description); }
9999
#define NAME report_map
100100
#include <derive-c/container/map/decomposed/template.h>
101101

102-
void report_map_example() {
102+
static void report_map_example() {
103103
printf("Report Map Example:\n");
104104
report_map map = report_map_new(stdalloc_get_ref());
105105

@@ -136,16 +136,16 @@ struct fixed_string {
136136
char value[4];
137137
};
138138

139-
void fixed_string_debug(struct fixed_string const* self, dc_debug_fmt fmt, FILE* stream) {
139+
static void fixed_string_debug(struct fixed_string const* self, dc_debug_fmt fmt, FILE* stream) {
140140
(void)fmt;
141141
fprintf(stream, "fixed_string@%p { value: \"%.*s\" }", self, 4, self->value);
142142
}
143143

144-
bool fixed_string_eq(struct fixed_string const* str1, struct fixed_string const* str2) {
144+
static bool fixed_string_eq(struct fixed_string const* str1, struct fixed_string const* str2) {
145145
return memcmp(str1->value, str2->value, sizeof(str1->value)) == 0;
146146
}
147147

148-
size_t fixed_string_hash(struct fixed_string const* str) {
148+
static size_t fixed_string_hash(struct fixed_string const* str) {
149149
return dc_murmur_hash_string_4(str->value);
150150
}
151151

@@ -157,7 +157,7 @@ size_t fixed_string_hash(struct fixed_string const* str) {
157157
#define NAME fixed_string_map
158158
#include <derive-c/container/map/decomposed/template.h>
159159

160-
void fixed_string_example() {
160+
static void fixed_string_example() {
161161
printf("Fixed Strings Example:\n");
162162
fixed_string_map map = fixed_string_map_new(stdalloc_get_ref());
163163

examples/basic/container/queue/circular.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include <derive-c/core/prelude.h>
2+
#include <derive-c/prelude.h>
33

44
#define CAPACITY 300000
55
#define NAME bump_alloc
@@ -10,7 +10,7 @@
1010
#define NAME int_queue
1111
#include <derive-c/container/queue/circular/template.h>
1212

13-
void basic_example() {
13+
static void basic_example() {
1414
bump_alloc_buffer buffer = {};
1515
bump_alloc alloc = bump_alloc_new(&buffer, stdalloc_get_ref());
1616

examples/basic/container/queue/deque.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include <derive-c/core/prelude.h>
2+
#include <derive-c/prelude.h>
33

44
#define CAPACITY 300000
55
#define NAME bump_alloc
@@ -10,7 +10,7 @@
1010
#define NAME int_queue
1111
#include <derive-c/container/queue/deque/template.h>
1212

13-
void basic_example() {
13+
static void basic_example() {
1414
bump_alloc_buffer buffer = {};
1515
bump_alloc alloc = bump_alloc_new(&buffer, stdalloc_get_ref());
1616

0 commit comments

Comments
 (0)