Skip to content

Commit 34cf0e6

Browse files
committed
Fix clang warnings
1 parent 1b2451f commit 34cf0e6

12 files changed

Lines changed: 159 additions & 134 deletions

File tree

software/runtime/kmp/barrier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "barrier.hpp"
22

33
namespace kmp {
4-
Barrier::Barrier(uint32_t numThreads) : numThreads(numThreads) {}
4+
Barrier::Barrier(uint32_t numThreads) : barrier(0), numThreads(numThreads) {}
55

66
Barrier::~Barrier() { DEBUG_PRINT("Destroying barrier at %p\n", this); }
77

software/runtime/kmp/cppsupport.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <cstdlib>
12
#include <mutex>
23

34
// Comment so that <mutex> is imported before
@@ -25,13 +26,24 @@ void *operator new[](size_t size) { return operator new(size); }
2526
void operator delete[](void *ptr) noexcept { return operator delete(ptr); }
2627

2728
namespace std {
28-
void __throw_bad_alloc() { printf("Bad alloc\n"); }
29-
void __throw_length_error(const char *msg) { printf("Length error: %s\n", msg); }
29+
void __throw_bad_alloc() {
30+
printf("Bad alloc\n");
31+
abort();
32+
}
33+
34+
void __throw_length_error(const char *msg) {
35+
printf("Length error: %s\n", msg);
36+
abort();
37+
}
38+
3039
void __throw_bad_optional_access() { printf("Bad optional access\n"); }
3140
} // namespace std
3241

3342
extern "C" void abort() {
3443
printf("Aborting\n");
44+
while (true) {
45+
mempool_wfi();
46+
}
3547
}
3648

3749
extern "C" int __cxa_atexit(void (*func)(void *), void *arg, void *dso_handle) {
@@ -45,5 +57,5 @@ extern "C" void __assert_func(const char *file, int line, const char *func,
4557
const char *failedexpr) {
4658
printf("Assertion failed: %s, file %s, line %d, function %s\n", failedexpr,
4759
file, line, func);
48-
mempool_wfi();
60+
abort();
4961
}
Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
#include "kmp/runtime.hpp"
2-
#include "kmp/types.h"
32
#include "kmp/team.hpp"
3+
#include "kmp/types.h"
4+
5+
using kmp::Mutex;
46

57
extern "C" {
68
#include "runtime.h"
79

8-
// NOLINTBEGIN(bugprone-reserved-identifier)
9-
10-
void __kmpc_barrier(ident_t *loc, kmp_int32 global_tid) {
11-
// DEBUG_PRINT("__kmpc_barrier called by %d\n", global_tid);
12-
kmp::runtime::getCurrentThread(global_tid)
10+
void __kmpc_barrier(ident_t * /*loc*/, kmp_int32 global_tid) {
11+
kmp::runtime::getCurrentThread(static_cast<kmp_uint32>(global_tid))
1312
.getCurrentTeam()
1413
->getBarrier()
1514
.wait();
1615
};
1716

1817
// Parallel
19-
void __kmpc_fork_call(ident_t *loc, kmp_int32 argc, kmpc_micro microtask, ...) {
20-
// NOLINTBEGIN(cppcoreguidelines-pro-type-vararg,cppcoreguidelines-pro-bounds-array-to-pointer-decay)
18+
void __kmpc_fork_call(ident_t * /*loc*/, kmp_int32 argc, kmpc_micro microtask,
19+
...) {
20+
// NOLINTBEGIN(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
2121
va_list args;
2222
va_start(args, microtask);
2323
kmp::Microtask kmpMicrotask(microtask, args, argc);
2424
va_end(args);
25-
// NOLINTEND(cppcoreguidelines-pro-type-vararg,cppcoreguidelines-pro-bounds-array-to-pointer-decay)
25+
// NOLINTEND(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
2626

2727
kmp::runtime::getCurrentThread().forkCall(std::move(kmpMicrotask));
2828
};
@@ -47,22 +47,24 @@ void __kmpc_for_static_init_4u(ident_t *loc, kmp_int32 gtid,
4747
pupper, pstride, incr, chunk);
4848
};
4949

50-
void __kmpc_for_static_init_8(ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype,
51-
kmp_int64 *plastiter, kmp_int64 *plower,
52-
kmp_int64 *pupper, kmp_int64 *pstride,
53-
kmp_int64 incr, kmp_int64 chunk) {
50+
void __kmpc_for_static_init_8(ident_t * /*loc*/, kmp_int32 /*gtid*/,
51+
kmp_int32 /*schedtype*/,
52+
kmp_int64 * /*plastiter*/, kmp_int64 * /*plower*/,
53+
kmp_int64 * /*pupper*/, kmp_int64 * /*pstride*/,
54+
kmp_int64 /*incr*/, kmp_int64 /*chunk*/) {
5455
assert(false && "Unsupported loop index type");
5556
};
5657

57-
void __kmpc_for_static_init_8u(ident_t *loc, kmp_int32 gtid,
58-
kmp_int32 schedtype, kmp_uint64 *plastiter,
59-
kmp_uint64 *plower, kmp_uint64 *pupper,
60-
kmp_int64 *pstride, kmp_int64 incr,
61-
kmp_int64 chunk) {
58+
void __kmpc_for_static_init_8u(ident_t * /*loc*/, kmp_int32 /*gtid*/,
59+
kmp_int32 /*schedtype*/,
60+
kmp_uint64 * /*plastiter*/,
61+
kmp_uint64 * /*plower*/, kmp_uint64 * /*pupper*/,
62+
kmp_int64 * /*pstride*/, kmp_int64 /*incr*/,
63+
kmp_int64 /*chunk*/) {
6264
assert(false && "Unsupported loop index type");
6365
};
6466

65-
void __kmpc_for_static_fini(ident_t *loc, kmp_int32 global_tid){};
67+
void __kmpc_for_static_fini(ident_t * /*loc*/, kmp_int32 /*global_tid*/){};
6668

6769
// Dynamic loops
6870
void __kmpc_dispatch_init_4(ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype,
@@ -83,75 +85,84 @@ void __kmpc_dispatch_init_4u(ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype,
8385
upper, incr, chunk);
8486
}
8587

86-
void __kmpc_dispatch_init_8(ident_t *loc, kmp_int64 gtid,
87-
kmp_sched_type schedtype, kmp_int64 lower,
88-
kmp_int64 upper, kmp_int64 incr, kmp_int64 chunk) {
88+
void __kmpc_dispatch_init_8(ident_t * /*loc*/, kmp_int64 /*gtid*/,
89+
kmp_sched_type /*schedtype*/, kmp_int64 /*lower*/,
90+
kmp_int64 /*upper*/, kmp_int64 /*incr*/,
91+
kmp_int64 /*chunk*/) {
8992
assert(false && "Unsupported loop index type");
9093
}
9194

92-
void __kmpc_dispatch_init_8u(ident_t *loc, kmp_int64 gtid,
93-
kmp_sched_type schedtype, kmp_uint64 lower,
94-
kmp_uint64 upper, kmp_int64 incr,
95-
kmp_int64 chunk) {
95+
void __kmpc_dispatch_init_8u(ident_t * /*loc*/, kmp_int64 /*gtid*/,
96+
kmp_sched_type /*schedtype*/, kmp_uint64 /*lower*/,
97+
kmp_uint64 /*upper*/, kmp_int64 /*incr*/,
98+
kmp_int64 /*chunk*/) {
9699
assert(false && "Unsupported loop index type");
97100
}
98101

99102
int __kmpc_dispatch_next_4(ident_t *loc, kmp_int32 gtid, kmp_int32 *plastiter,
100103
kmp_int32 *plower, kmp_int32 *pupper,
101104
kmp_int32 *pstride) {
102-
return kmp::runtime::getCurrentThread().getCurrentTeam()->dispatchNext(
103-
loc, gtid, plastiter, plower, pupper, pstride);
105+
return static_cast<int>(
106+
kmp::runtime::getCurrentThread().getCurrentTeam()->dispatchNext(
107+
loc, gtid, plastiter, plower, pupper, pstride));
104108
}
105109

106110
int __kmpc_dispatch_next_4u(ident_t *loc, kmp_int32 gtid, kmp_int32 *plastiter,
107111
kmp_uint32 *plower, kmp_uint32 *pupper,
108112
kmp_int32 *pstride) {
109-
return kmp::runtime::getCurrentThread().getCurrentTeam()->dispatchNext(
110-
loc, gtid, plastiter, plower, pupper, pstride);
113+
return static_cast<int>(
114+
kmp::runtime::getCurrentThread().getCurrentTeam()->dispatchNext(
115+
loc, gtid, plastiter, plower, pupper, pstride));
111116
}
112117

113-
int __kmpc_dispatch_next_8(ident_t *loc, kmp_int64 gtid, kmp_int64 *plastiter,
114-
kmp_int64 *plower, kmp_int64 *pupper,
115-
kmp_int64 *pstride) {
118+
int __kmpc_dispatch_next_8(ident_t * /*loc*/, kmp_int64 /*gtid*/,
119+
kmp_int64 * /*plastiter*/, kmp_int64 * /*plower*/,
120+
kmp_int64 * /*pupper*/, kmp_int64 * /*pstride*/) {
116121
assert(false && "Unsupported loop index type");
117122
}
118123

119-
int __kmpc_dispatch_next_8u(ident_t *loc, kmp_int64 gtid, kmp_int64 *plastiter,
120-
kmp_uint64 *plower, kmp_uint64 *pupper,
121-
kmp_int64 *pstride) {
124+
int __kmpc_dispatch_next_8u(ident_t * /*loc*/, kmp_int64 /*gtid*/,
125+
kmp_int64 * /*plastiter*/, kmp_uint64 * /*plower*/,
126+
kmp_uint64 * /*pupper*/, kmp_int64 * /*pstride*/) {
122127
assert(false && "Unsupported loop index type");
123128
}
124129

125-
void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
130+
void __kmpc_push_num_threads(ident_t * /*loc*/, kmp_int32 /*global_tid*/,
126131
kmp_int32 num_threads) {
127132
kmp::runtime::getCurrentThread().requestNumThreads(num_threads);
128133
};
129134

130135
// Critical sections
131-
void __kmpc_critical(ident_t *, kmp_int32 gtid, kmp_critical_name *crit) {
136+
void __kmpc_critical(ident_t * /*unused*/, kmp_int32 /*gtid*/,
137+
kmp_critical_name *crit) {
132138
static_assert(sizeof(kmp::Mutex) <= sizeof(kmp_critical_name));
139+
140+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
133141
kmp::Mutex *mutex = reinterpret_cast<kmp::Mutex *>(*crit);
134142
mutex->lock();
135143
};
136144

137-
void __kmpc_end_critical(ident_t *, kmp_int32 gtid, kmp_critical_name *crit) {
138-
kmp::Mutex *mutex = reinterpret_cast<kmp::Mutex *>(*crit);
145+
void __kmpc_end_critical(ident_t * /*unused*/, kmp_int32 /*gtid*/,
146+
kmp_critical_name *crit) {
147+
148+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
149+
Mutex *mutex = reinterpret_cast<kmp::Mutex *>(*crit);
139150
mutex->unlock();
140151
};
141152

142153
// Master
143-
kmp_int32 __kmpc_master(ident_t *loc, int32_t gtid) {
154+
kmp_int32 __kmpc_master(ident_t * /*loc*/, kmp_int32 /*gtid*/) {
144155
return static_cast<kmp_int32>(kmp::runtime::getCurrentThread().getTid() == 0);
145156
};
146157

147-
void __kmpc_end_master(ident_t *loc, int32_t gtid){/* NOOP */};
158+
void __kmpc_end_master(ident_t * /*loc*/, kmp_int32 /*gtid*/){/* NOOP */};
148159

149160
// Single (same as master for now)
150-
kmp_int32 __kmpc_single(ident_t *loc, int32_t gtid) {
161+
kmp_int32 __kmpc_single(ident_t * /*loc*/, kmp_int32 /*gtid*/) {
151162
return static_cast<kmp_int32>(kmp::runtime::getCurrentThread().getTid() == 0);
152163
};
153164

154-
void __kmpc_end_single(ident_t *loc, int32_t gtid){/* NOOP */};
165+
void __kmpc_end_single(ident_t * /*loc*/, kmp_int32 /*gtid*/){/* NOOP */};
155166

156167
// Copyprivate
157168
void __kmpc_copyprivate(ident_t *loc, kmp_int32 gtid, size_t cpy_size,
@@ -162,16 +173,17 @@ void __kmpc_copyprivate(ident_t *loc, kmp_int32 gtid, size_t cpy_size,
162173
};
163174

164175
// Reduction
165-
kmp_int32
166-
__kmpc_reduce_nowait(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_vars,
167-
size_t reduce_size, void *reduce_data,
168-
void (*reduce_func)(void *lhs_data, void *rhs_data),
169-
kmp_critical_name *lck) {
176+
kmp_int32 __kmpc_reduce_nowait(ident_t * /*loc*/, kmp_int32 /*global_tid*/,
177+
kmp_int32 /*num_vars*/, size_t /*reduce_size*/,
178+
void * /*reduce_data*/,
179+
void (* /*reduce_func*/)(void *lhs_data,
180+
void *rhs_data),
181+
kmp_critical_name * /*lck*/) {
170182
return 2; // Atomic reduction
171183
}
172184

173-
void __kmpc_end_reduce_nowait(ident_t *loc, kmp_int32 global_tid,
174-
kmp_critical_name *lck) {
185+
void __kmpc_end_reduce_nowait(ident_t * /*loc*/, kmp_int32 /*global_tid*/,
186+
kmp_critical_name * /*lck*/) {
175187
/* NOOP */
176188
}
177189

@@ -185,13 +197,11 @@ kmp_int32 __kmpc_reduce(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_vars,
185197
}
186198

187199
void __kmpc_end_reduce(ident_t *loc, kmp_int32 global_tid,
188-
kmp_critical_name *lck) {
200+
kmp_critical_name * /*lck*/) {
189201
return __kmpc_barrier(loc, global_tid);
190202
}
191203

192-
kmp_int32 __kmpc_global_thread_num(ident_t *loc) {
193-
return mempool_get_core_id();
204+
kmp_int32 __kmpc_global_thread_num(ident_t * /*loc*/) {
205+
return static_cast<kmp_int32>(mempool_get_core_id());
194206
};
195-
196-
// NOLINTEND(bugprone-reserved-identifier)
197207
}

software/runtime/kmp/main_wrapper.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ extern "C" {
66

77
// https://etherealwake.com/2021/09/crt-startup/
88
typedef void (*init_func)(void);
9-
extern init_func __init_array_start[];
10-
extern init_func __init_array_end[];
9+
extern init_func *__init_array_start;
10+
extern init_func *__init_array_end;
1111

1212
static inline void initGlobals() {
13-
uint32_t n = __init_array_end - __init_array_start;
14-
for (size_t i = 0; i < n; i++) {
13+
//NOLINTNEXTLINE(*-narrowing-conversions)
14+
int32_t len = __init_array_end - __init_array_start;
15+
for (int32_t i = 0; i < len; i++) {
16+
17+
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
1518
__init_array_start[i]();
1619
}
1720
}
@@ -23,7 +26,7 @@ std::atomic<bool> initLock = true;
2326
extern "C" int __wrap_main() {
2427
const mempool_id_t core_id = mempool_get_core_id();
2528
if (core_id == 0) {
26-
printf("Running OpenMP program on %d cores\n", mempool_get_core_count());
29+
DEBUG_PRINT("Running OpenMP program on %d cores\n", mempool_get_core_count());
2730

2831
// Init heap allocators
2932
mempool_init(0);
@@ -36,7 +39,7 @@ extern "C" int __wrap_main() {
3639

3740
initLock = false;
3841

39-
printf("Init done\n");
42+
DEBUG_PRINT("Init done\n");
4043

4144
// Run the program
4245
__real_main();

software/runtime/kmp/runtime.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
#include <array>
44
#include <utility>
55

6-
extern "C" {
7-
#include "runtime.h"
8-
}
9-
106
namespace kmp {
117

128
namespace runtime {

software/runtime/kmp/runtime.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
#pragma once
22

3+
#include "etl/error_handler.h"
34
#include "kmp/thread.hpp"
45
#include "kmp/types.h"
5-
#include "etl/error_handler.h"
6-
7-
extern "C" {
8-
#include "runtime.h"
9-
}
106

117
// NOLINTNEXTLINE(bugprone-reserved-identifier)
128
extern void __assert_func(const char *file, int line, const char *func,
139
const char *failedexpr);
14-
static inline void assertWrapper(const etl::exception &e) {
15-
__assert_func(e.file_name(), e.line_number(), "n/a", e.what());
10+
11+
static inline void assertWrapper(const etl::exception &exception) {
12+
__assert_func(exception.file_name(), exception.line_number(), "n/a",
13+
exception.what());
1614
};
1715

1816
namespace kmp {
@@ -33,7 +31,7 @@ static inline void init() {
3331

3432
static inline void runThread(kmp_uint32 core_id) { threads[core_id].run(); };
3533

36-
static inline Thread &getCurrentThread(kmp_int32 gtid) {
34+
static inline Thread &getCurrentThread(kmp_uint32 gtid) {
3735
return threads[gtid];
3836
};
3937

software/runtime/kmp/task.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Microtask::Microtask(kmpc_micro func, va_list args, kmp_int32 argc)
1919
return;
2020
}
2121

22-
this->args = new void *[argc];
22+
this->args = new void *[static_cast<kmp_uint32>(argc)];
2323

2424
DEBUG_PRINT("Microtask constructor, args: %p\n", this->args);
2525

@@ -49,9 +49,7 @@ Microtask &Microtask::operator=(Microtask &&other) noexcept {
4949
return *this;
5050
};
5151

52-
Microtask::~Microtask() {
53-
delete[] args;
54-
};
52+
Microtask::~Microtask() { delete[] args; };
5553

5654
void Microtask::run() const {
5755
kmp_int32 gtid = static_cast<kmp_int32>(mempool_get_core_id());

software/runtime/kmp/team.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
namespace kmp {
66

7-
Team::Team(kmp_int32 masterGtid, kmp_uint32 numThreads,
7+
Team::Team(kmp_uint32 masterGtid, kmp_uint32 numThreads,
88
std::optional<Task> implicitTask)
9-
: numThreads(numThreads), barrier(numThreads),
10-
dynamicSchedule{.valid = false}, implicitTask(std::move(implicitTask)),
11-
copyPrivateData(nullptr), masterGtid(masterGtid) {}
9+
: masterGtid(masterGtid), numThreads(numThreads), barrier(numThreads),
10+
implicitTask(std::move(implicitTask)) {}
1211

1312
} // namespace kmp

0 commit comments

Comments
 (0)