Skip to content

Commit 26dbe4a

Browse files
committed
Fix warnings in debug and release builds
1 parent 4091e43 commit 26dbe4a

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/libasr/runtime/lfortran_intrinsics.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,27 +1683,30 @@ LFORTRAN_API void _lfortran_rewind(int32_t unit_num)
16831683

16841684
LFORTRAN_API void _lfortran_read_int32(int32_t *p, int32_t unit_num)
16851685
{
1686+
size_t tmp;
16861687
if (unit_num == -1) {
16871688
// Read from stdin
16881689
FILE *fp = fdopen(0, "r+");
1689-
(void)fread(p, sizeof(int32_t), 1, fp);
1690+
tmp = fread(p, sizeof(int32_t), 1, fp);
16901691
fclose(fp);
16911692
return;
16921693
}
16931694
if (!unit_to_file[unit_num]) {
16941695
printf("No file found with given unit\n");
16951696
exit(1);
16961697
}
1697-
(void)fread(p, sizeof(int32_t), 1, unit_to_file[unit_num]);
1698+
tmp = fread(p, sizeof(int32_t), 1, unit_to_file[unit_num]);
1699+
if (tmp) {}
16981700
}
16991701

17001702
LFORTRAN_API void _lfortran_read_char(char **p, int32_t unit_num)
17011703
{
1704+
size_t tmp;
17021705
if (unit_num == -1) {
17031706
// Read from stdin
17041707
*p = (char*)malloc(16);
17051708
FILE *fp = fdopen(0, "r+");
1706-
(void)fread(*p, sizeof(char), 16, fp);
1709+
tmp = fread(*p, sizeof(char), 16, fp);
17071710
fclose(fp);
17081711
return;
17091712
}
@@ -1712,7 +1715,8 @@ LFORTRAN_API void _lfortran_read_char(char **p, int32_t unit_num)
17121715
exit(1);
17131716
}
17141717
*p = (char*)malloc(16);
1715-
(void)fread(*p, sizeof(char), 16, unit_to_file[unit_num]);
1718+
tmp = fread(*p, sizeof(char), 16, unit_to_file[unit_num]);
1719+
if (tmp) {}
17161720
}
17171721

17181722
LFORTRAN_API char* _lpython_read(int64_t fd, int64_t n)

src/lpython/parser/parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Result<LPython::AST::ast_t*> parse_python_file(Allocator &al,
117117
const std::string &infile,
118118
diag::Diagnostics &diagnostics,
119119
uint32_t prev_loc,
120-
bool new_parser) {
120+
[[maybe_unused]] bool new_parser) {
121121
LPython::AST::ast_t* ast;
122122
// We will be using the new parser from now on
123123
new_parser = true;

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
831831
this->visit_expr(*exprs[i]);
832832
ASR::expr_t* expr = nullptr;
833833
ASR::call_arg_t arg;
834+
arg.loc.first = -1;
835+
arg.loc.last = -1;
834836
if (tmp) {
835837
expr = ASRUtils::EXPR(tmp);
836838
arg.loc = expr->base.loc;
@@ -1009,7 +1011,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
10091011

10101012
ASR::ttype_t* get_type_from_var_annotation(std::string var_annotation,
10111013
const Location& loc, Vec<ASR::dimension_t>& dims,
1012-
AST::expr_t** m_args=nullptr, size_t n_args=0,
1014+
AST::expr_t** m_args=nullptr, [[maybe_unused]] size_t n_args=0,
10131015
bool raise_error=true, ASR::abiType abi=ASR::abiType::Source,
10141016
bool is_argument=false) {
10151017
ASR::ttype_t* type = nullptr;
@@ -2364,7 +2366,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
23642366
result = left_value >> right_value;
23652367
break;
23662368
}
2367-
default: { LCOMPILERS_ASSERT(false); } // should never happen
2369+
default: { throw SemanticError("ICE: Unknown binary operator", loc); } // should never happen
23682370
}
23692371
value = ASR::down_cast<ASR::expr_t>(ASR::make_IntegerConstant_t(
23702372
al, loc, result, dest_type));
@@ -2418,7 +2420,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
24182420
result = left_value >> right_value;
24192421
break;
24202422
}
2421-
default: { LCOMPILERS_ASSERT(false); } // should never happen
2423+
default: { throw SemanticError("ICE: Unknown binary operator", loc); } // should never happen
24222424
}
24232425
value = ASR::down_cast<ASR::expr_t>(ASR::make_UnsignedIntegerConstant_t(
24242426
al, loc, result, dest_type));
@@ -2460,7 +2462,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
24602462
case (ASR::binopType::Mul): { result = left_value * right_value; break; }
24612463
case (ASR::binopType::Div): { result = left_value / right_value; break; }
24622464
case (ASR::binopType::Pow): { result = std::pow(left_value, right_value); break; }
2463-
default: { LCOMPILERS_ASSERT(false); }
2465+
default: { throw SemanticError("ICE: Unknown binary operator", loc); }
24642466
}
24652467
value = ASR::down_cast<ASR::expr_t>(ASR::make_RealConstant_t(
24662468
al, loc, result, dest_type));
@@ -3293,7 +3295,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
32933295
void visit_NamedExpr(const AST::NamedExpr_t &x) {
32943296
this->visit_expr(*x.m_target);
32953297
ASR::expr_t *target = ASRUtils::EXPR(tmp);
3296-
ASR::ttype_t *target_type = ASRUtils::expr_type(target);
3298+
[[maybe_unused]] ASR::ttype_t *target_type = ASRUtils::expr_type(target);
32973299
this->visit_expr(*x.m_value);
32983300
ASR::expr_t *value = ASRUtils::EXPR(tmp);
32993301
ASR::ttype_t *value_type = ASRUtils::expr_type(value);
@@ -3400,7 +3402,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
34003402
ASR::expr_t *left = ASRUtils::EXPR(tmp);
34013403
this->visit_expr(*x.m_right);
34023404
ASR::expr_t *right = ASRUtils::EXPR(tmp);
3403-
ASR::binopType op;
3405+
ASR::binopType op = ASR::binopType::Add /* temporary assignment */;
34043406
std::string op_name = "";
34053407
switch (x.m_op) {
34063408
case (AST::operatorType::Add) : { op = ASR::binopType::Add; break; }
@@ -5611,7 +5613,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
56115613
ASR::expr_t *right = ASRUtils::EXPR(tmp);
56125614
ASR::ttype_t* left_type = ASRUtils::expr_type(left);
56135615
ASR::ttype_t* right_type = ASRUtils::expr_type(right);
5614-
ASR::binopType op;
5616+
ASR::binopType op = ASR::binopType::Add /* temporary assignment */;
56155617
std::string op_name = "";
56165618
switch (x.m_op) {
56175619
case (AST::operatorType::Add) : { op = ASR::binopType::Add; break; }
@@ -6322,7 +6324,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
63226324
result = (strcmp < 0 || strcmp == 0);
63236325
break;
63246326
}
6325-
default: LCOMPILERS_ASSERT(false); // should never happen
6327+
default: {
6328+
throw SemanticError("ICE: Unknown compare operator", x.base.base.loc); // should never happen
6329+
}
63266330
}
63276331
value = ASR::down_cast<ASR::expr_t>(ASR::make_LogicalConstant_t(
63286332
al, x.base.base.loc, result, type));

0 commit comments

Comments
 (0)