Skip to content
Closed
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
26 changes: 26 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-unix.Malloc,-clang-analyzer-cplusplus.NewDeleteLeaks'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
CheckOptions:
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
540 changes: 279 additions & 261 deletions CMakeLists.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ libc. Create demo games using Zig.

##### POSIX

* cmake >= 2.8.5
* cmake >= 3.1
* gcc >= 5.0.0 or clang >= 3.6.0
* LLVM, Clang, LLD development libraries == 6.x, compiled with the same gcc or clang version above
- These depend on zlib and libxml2.
Expand Down
2 changes: 1 addition & 1 deletion ci/travis_linux_install
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -x

sudo apt-get remove -y llvm-*
sudo rm -rf /usr/local/*
sudo apt-get install -y clang-6.0 libclang-6.0 libclang-6.0-dev llvm-6.0 llvm-6.0-dev liblld-6.0 liblld-6.0-dev cmake wine1.6-amd64 s3cmd
sudo apt-get install -y clang-6.0 libclang-6.0 libclang-6.0-dev llvm-6.0 llvm-6.0-dev liblld-6.0 liblld-6.0-dev cmake3 wine1.6-amd64 s3cmd
4 changes: 4 additions & 0 deletions src/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type);
static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type);

ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
assert(node != nullptr);
assert(node->owner != nullptr);

if (node->owner->c_import_node != nullptr) {
// if this happens, then translate_c generated code that
// failed semantic analysis, which isn't supposed to happen
Expand Down Expand Up @@ -4236,6 +4239,7 @@ TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_b
}

TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
assert(g != nullptr);
TypeTableEntry **common_entry = get_int_type_ptr(g, is_signed, size_in_bits);
if (common_entry)
return *common_entry;
Expand Down
2 changes: 2 additions & 0 deletions src/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static inline size_t buf_len(Buf *buf) {
}

static inline char *buf_ptr(Buf *buf) {
assert(buf != nullptr);
assert(buf->list.length);
return buf->list.items;
}
Expand Down Expand Up @@ -119,6 +120,7 @@ static inline void buf_append_buf(Buf *buf, Buf *append_buf) {
}

static inline void buf_append_char(Buf *buf, uint8_t c) {
assert(buf != nullptr);
assert(buf->list.length);
buf_append_mem(buf, (const char *)&c, 1);
}
Expand Down
20 changes: 20 additions & 0 deletions src/c_tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateFloat:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case '.':
break;
Expand All @@ -276,6 +277,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateExpSign:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case '+':
case '-':
Expand All @@ -291,6 +293,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateFloatExpFirst:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case DIGIT:
buf_append_char(&ctok->buf, *c);
Expand All @@ -301,6 +304,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateFloatExp:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case DIGIT:
buf_append_char(&ctok->buf, *c);
Expand All @@ -318,6 +322,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateDecimal:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case DIGIT:
buf_append_char(&ctok->buf, *c);
Expand Down Expand Up @@ -352,6 +357,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateGotZero:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case 'x':
case 'X':
Expand All @@ -369,6 +375,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateOctal:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case '0':
case '1':
Expand Down Expand Up @@ -396,6 +403,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateHex:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case '0':
hex_digit(ctok, 0);
Expand Down Expand Up @@ -476,6 +484,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateNumLitIntSuffixU:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case 'l':
case 'L':
Expand All @@ -490,6 +499,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateNumLitIntSuffixL:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case 'l':
case 'L':
Expand All @@ -510,6 +520,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateNumLitIntSuffixLL:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case 'u':
case 'U':
Expand All @@ -525,6 +536,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateNumLitIntSuffixUL:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case 'l':
case 'L':
Expand All @@ -540,6 +552,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateIdentifier:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case IDENT:
buf_append_char(&ctok->cur_tok->data.symbol, *c);
Expand All @@ -552,6 +565,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateString:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case '\\':
ctok->state = CTokStateCharEscape;
Expand All @@ -565,6 +579,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateExpectChar:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case '\\':
ctok->state = CTokStateCharEscape;
Expand All @@ -577,6 +592,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateCharEscape:
assert(ctok->cur_tok != nullptr);
switch (*c) {
case '\'':
case '"':
Expand Down Expand Up @@ -733,6 +749,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
}
break;
case CTokStateLineComment:
assert(ctok->cur_tok != nullptr);
if (*c == '\n') {
ctok->state = CTokStateStart;
goto found_end_of_macro;
Expand Down Expand Up @@ -784,10 +801,12 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
case CTokStateNumLitIntSuffixL:
case CTokStateNumLitIntSuffixUL:
case CTokStateNumLitIntSuffixLL:
assert(ctok->cur_tok != nullptr);
end_token(ctok);
break;
case CTokStateFloat:
case CTokStateFloatExp:
assert(ctok->cur_tok != nullptr);
end_float(ctok);
break;
case CTokStateExpectChar:
Expand All @@ -803,6 +822,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
case CTokStateFloatExpFirst:
case CTokStateStrHex:
case CTokStateStrOctal:
assert(ctok->cur_tok != nullptr);
return mark_error(ctok);
}

Expand Down
21 changes: 10 additions & 11 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4306,7 +4306,7 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
LLVMValueRef alloc_fn_val = LLVMGetParam(fn_val, next_arg);
next_arg += 1;

LLVMValueRef stack_trace_val;
LLVMValueRef stack_trace_val = nullptr;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix issue with using uninitialized value.

if (g->have_err_ret_tracing) {
stack_trace_val = LLVMGetParam(fn_val, next_arg);
next_arg += 1;
Expand All @@ -4317,7 +4317,6 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
LLVMValueRef err_code_ptr = LLVMGetParam(fn_val, next_arg);
next_arg += 1;
LLVMValueRef coro_size = LLVMGetParam(fn_val, next_arg);
next_arg += 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead store.

LLVMValueRef alignment_val = LLVMConstInt(g->builtin_types.entry_u29->type_ref,
get_coro_frame_align_bytes(g), false);

Expand Down Expand Up @@ -5828,20 +5827,20 @@ static const uint8_t int_sizes_in_bits[] = {
};

struct CIntTypeInfo {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize struct padding.

CIntType id;
const char *name;
CIntType id;
bool is_signed;
};

static const CIntTypeInfo c_int_type_infos[] = {
{CIntTypeShort, "c_short", true},
{CIntTypeUShort, "c_ushort", false},
{CIntTypeInt, "c_int", true},
{CIntTypeUInt, "c_uint", false},
{CIntTypeLong, "c_long", true},
{CIntTypeULong, "c_ulong", false},
{CIntTypeLongLong, "c_longlong", true},
{CIntTypeULongLong, "c_ulonglong", false},
{"c_short", CIntTypeShort, true},
{"c_ushort", CIntTypeUShort, false},
{"c_int", CIntTypeInt, true},
{"c_uint", CIntTypeUInt, false},
{"c_long", CIntTypeLong,true},
{"c_ulong", CIntTypeULong, false},
{"c_longlong", CIntTypeLongLong, true},
{"c_ulonglong", CIntTypeULongLong, false},
};

static const bool is_signed_list[] = { false, true, };
Expand Down
Loading