Skip to content

Commit

Permalink
Fix warnings in debug and release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed Jul 11, 2023
1 parent 4091e43 commit 26dbe4a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/libasr/runtime/lfortran_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1683,27 +1683,30 @@ LFORTRAN_API void _lfortran_rewind(int32_t unit_num)

LFORTRAN_API void _lfortran_read_int32(int32_t *p, int32_t unit_num)
{
size_t tmp;
if (unit_num == -1) {
// Read from stdin
FILE *fp = fdopen(0, "r+");
(void)fread(p, sizeof(int32_t), 1, fp);
tmp = fread(p, sizeof(int32_t), 1, fp);
fclose(fp);
return;
}
if (!unit_to_file[unit_num]) {
printf("No file found with given unit\n");
exit(1);
}
(void)fread(p, sizeof(int32_t), 1, unit_to_file[unit_num]);
tmp = fread(p, sizeof(int32_t), 1, unit_to_file[unit_num]);
if (tmp) {}
}

LFORTRAN_API void _lfortran_read_char(char **p, int32_t unit_num)
{
size_t tmp;
if (unit_num == -1) {
// Read from stdin
*p = (char*)malloc(16);
FILE *fp = fdopen(0, "r+");
(void)fread(*p, sizeof(char), 16, fp);
tmp = fread(*p, sizeof(char), 16, fp);
fclose(fp);
return;
}
Expand All @@ -1712,7 +1715,8 @@ LFORTRAN_API void _lfortran_read_char(char **p, int32_t unit_num)
exit(1);
}
*p = (char*)malloc(16);
(void)fread(*p, sizeof(char), 16, unit_to_file[unit_num]);
tmp = fread(*p, sizeof(char), 16, unit_to_file[unit_num]);
if (tmp) {}
}

LFORTRAN_API char* _lpython_read(int64_t fd, int64_t n)
Expand Down
2 changes: 1 addition & 1 deletion src/lpython/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Result<LPython::AST::ast_t*> parse_python_file(Allocator &al,
const std::string &infile,
diag::Diagnostics &diagnostics,
uint32_t prev_loc,
bool new_parser) {
[[maybe_unused]] bool new_parser) {
LPython::AST::ast_t* ast;
// We will be using the new parser from now on
new_parser = true;
Expand Down
20 changes: 12 additions & 8 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
this->visit_expr(*exprs[i]);
ASR::expr_t* expr = nullptr;
ASR::call_arg_t arg;
arg.loc.first = -1;
arg.loc.last = -1;
if (tmp) {
expr = ASRUtils::EXPR(tmp);
arg.loc = expr->base.loc;
Expand Down Expand Up @@ -1009,7 +1011,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {

ASR::ttype_t* get_type_from_var_annotation(std::string var_annotation,
const Location& loc, Vec<ASR::dimension_t>& dims,
AST::expr_t** m_args=nullptr, size_t n_args=0,
AST::expr_t** m_args=nullptr, [[maybe_unused]] size_t n_args=0,
bool raise_error=true, ASR::abiType abi=ASR::abiType::Source,
bool is_argument=false) {
ASR::ttype_t* type = nullptr;
Expand Down Expand Up @@ -2364,7 +2366,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
result = left_value >> right_value;
break;
}
default: { LCOMPILERS_ASSERT(false); } // should never happen
default: { throw SemanticError("ICE: Unknown binary operator", loc); } // should never happen
}
value = ASR::down_cast<ASR::expr_t>(ASR::make_IntegerConstant_t(
al, loc, result, dest_type));
Expand Down Expand Up @@ -2418,7 +2420,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
result = left_value >> right_value;
break;
}
default: { LCOMPILERS_ASSERT(false); } // should never happen
default: { throw SemanticError("ICE: Unknown binary operator", loc); } // should never happen
}
value = ASR::down_cast<ASR::expr_t>(ASR::make_UnsignedIntegerConstant_t(
al, loc, result, dest_type));
Expand Down Expand Up @@ -2460,7 +2462,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
case (ASR::binopType::Mul): { result = left_value * right_value; break; }
case (ASR::binopType::Div): { result = left_value / right_value; break; }
case (ASR::binopType::Pow): { result = std::pow(left_value, right_value); break; }
default: { LCOMPILERS_ASSERT(false); }
default: { throw SemanticError("ICE: Unknown binary operator", loc); }
}
value = ASR::down_cast<ASR::expr_t>(ASR::make_RealConstant_t(
al, loc, result, dest_type));
Expand Down Expand Up @@ -3293,7 +3295,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
void visit_NamedExpr(const AST::NamedExpr_t &x) {
this->visit_expr(*x.m_target);
ASR::expr_t *target = ASRUtils::EXPR(tmp);
ASR::ttype_t *target_type = ASRUtils::expr_type(target);
[[maybe_unused]] ASR::ttype_t *target_type = ASRUtils::expr_type(target);
this->visit_expr(*x.m_value);
ASR::expr_t *value = ASRUtils::EXPR(tmp);
ASR::ttype_t *value_type = ASRUtils::expr_type(value);
Expand Down Expand Up @@ -3400,7 +3402,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
ASR::expr_t *left = ASRUtils::EXPR(tmp);
this->visit_expr(*x.m_right);
ASR::expr_t *right = ASRUtils::EXPR(tmp);
ASR::binopType op;
ASR::binopType op = ASR::binopType::Add /* temporary assignment */;
std::string op_name = "";
switch (x.m_op) {
case (AST::operatorType::Add) : { op = ASR::binopType::Add; break; }
Expand Down Expand Up @@ -5611,7 +5613,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
ASR::expr_t *right = ASRUtils::EXPR(tmp);
ASR::ttype_t* left_type = ASRUtils::expr_type(left);
ASR::ttype_t* right_type = ASRUtils::expr_type(right);
ASR::binopType op;
ASR::binopType op = ASR::binopType::Add /* temporary assignment */;
std::string op_name = "";
switch (x.m_op) {
case (AST::operatorType::Add) : { op = ASR::binopType::Add; break; }
Expand Down Expand Up @@ -6322,7 +6324,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
result = (strcmp < 0 || strcmp == 0);
break;
}
default: LCOMPILERS_ASSERT(false); // should never happen
default: {
throw SemanticError("ICE: Unknown compare operator", x.base.base.loc); // should never happen
}
}
value = ASR::down_cast<ASR::expr_t>(ASR::make_LogicalConstant_t(
al, x.base.base.loc, result, type));
Expand Down

0 comments on commit 26dbe4a

Please sign in to comment.