Skip to content

Commit 00d62ad

Browse files
cebtenzzrexaedes
andauthored
fix some warnings from gcc and clang-tidy (#3038)
Co-authored-by: xaedes <[email protected]>
1 parent 4fa2cc1 commit 00d62ad

File tree

22 files changed

+63
-101
lines changed

22 files changed

+63
-101
lines changed

.clang-tidy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Checks: >
33
bugprone-*,
44
-bugprone-easily-swappable-parameters,
55
-bugprone-implicit-widening-of-multiplication-result,
6+
-bugprone-misplaced-widening-cast,
67
-bugprone-narrowing-conversions,
78
readability-*,
89
-readability-avoid-unconditional-preprocessor-if,
@@ -15,4 +16,8 @@ Checks: >
1516
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
1617
performance-*,
1718
portability-*,
19+
misc-*,
20+
-misc-const-correctness,
21+
-misc-non-private-member-variables-in-classes,
22+
-misc-no-recursion,
1823
FormatStyle: none

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ if (LLAMA_ALL_WARNINGS)
426426
)
427427
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
428428
# g++ only
429-
set(cxx_flags ${cxx_flags} -Wno-format-truncation)
429+
set(cxx_flags ${cxx_flags} -Wno-format-truncation -Wno-array-bounds)
430430
endif()
431431
else()
432432
# todo : msvc

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ MK_CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wno-m
134134

135135
ifeq '' '$(findstring clang++,$(CXX))'
136136
# g++ only
137-
MK_CXXFLAGS += -Wno-format-truncation
137+
MK_CXXFLAGS += -Wno-format-truncation -Wno-array-bounds
138138
endif
139139

140140
# OS specific

common/common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int32_t get_num_physical_cores() {
5757
siblings.insert(line);
5858
}
5959
}
60-
if (siblings.size() > 0) {
60+
if (!siblings.empty()) {
6161
return static_cast<int32_t>(siblings.size());
6262
}
6363
#elif defined(__APPLE__) && defined(__MACH__)

common/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#define DIRECTORY_SEPARATOR '/'
2121
#endif // _WIN32
2222

23+
#define die(msg) do { fputs("error: " msg "\n", stderr); exit(1); } while (0)
24+
#define die_fmt(fmt, ...) do { fprintf(stderr, "error: " fmt "\n", ##__VA_ARGS__); exit(1); } while (0)
25+
2326
//
2427
// CLI argument parsing
2528
//

common/grammar-parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ namespace grammar_parser {
415415

416416
std::vector<const llama_grammar_element *> parse_state::c_rules() {
417417
std::vector<const llama_grammar_element *> ret;
418+
ret.reserve(rules.size());
418419
for (const auto & rule : rules) {
419420
ret.push_back(rule.data());
420421
}

examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "ggml.h"
22
#include "llama.h"
3+
#include "common.h"
34

45
#include <unordered_map>
56
#include <vector>
@@ -499,10 +500,10 @@ struct llama_file {
499500
errno = 0;
500501
std::size_t ret = std::fread(ptr, size, 1, fp);
501502
if (ferror(fp)) {
502-
throw std::runtime_error(format("read error: %s", strerror(errno)));
503+
die_fmt("fread failed: %s", strerror(errno));
503504
}
504505
if (ret != 1) {
505-
throw std::runtime_error(std::string("unexpectedly reached end of file"));
506+
die("unexpectedly reached end of file");
506507
}
507508
}
508509

@@ -597,8 +598,7 @@ void load_vocab(const char *filename, Config *config, struct llama_vocab *vocab)
597598
printf("Assuming llama2.c vocabulary since %s is not a gguf file\n", filename);
598599
llama_file file(filename, "rb");
599600
if (!file.fp) {
600-
fprintf(stderr, "error: %s: %s\n", strerror(errno), filename);
601-
exit(1);
601+
die_fmt("%s: %s", strerror(errno), filename);
602602
}
603603
const int n_vocab = config->vocab_size;
604604
/* uint32_t max_token_length = */ file.read_u32(); // unused

examples/embd-input/embd-input-lib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern "C" {
2323
struct MyModel* create_mymodel(int argc, char ** argv) {
2424
gpt_params params;
2525

26-
if (gpt_params_parse(argc, argv, params) == false) {
26+
if (!gpt_params_parse(argc, argv, params)) {
2727
return nullptr;
2828
}
2929

examples/embedding/embedding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
int main(int argc, char ** argv) {
1212
gpt_params params;
1313

14-
if (gpt_params_parse(argc, argv, params) == false) {
14+
if (!gpt_params_parse(argc, argv, params)) {
1515
return 1;
1616
}
1717

examples/gptneox-wip/falcon-main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ int main(int argc, char ** argv) {
953953

954954
gpt_params params;
955955

956-
if (gpt_params_parse(argc, argv, params) == false) {
956+
if (!gpt_params_parse(argc, argv, params)) {
957957
return 1;
958958
}
959959

0 commit comments

Comments
 (0)