Skip to content

Commit

Permalink
[Native] Avoid overwrite with zero
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyTy committed May 23, 2024
1 parent 3de69ae commit 072549f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions source/targets/genC.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -738,16 +738,24 @@ class GenCxx {
}

if defaults {
//types.push('void* ' + name + '_;\n')
globalVariables.push(stringifyType(type))
globalVariables.push(' ' + name + '_;\n')
if expr != null {
out.push('\t' + name + '_ = ' + printExpression(expr) + ';\n')
}
//types.push('void* ' + name + '_;\n')
globalVariables.push(stringifyType(type))
globalVariables.push(' ' + name + '_;\n')
if expr != null {
let value String = printExpression(expr)

// Printing zero global integers causes bug in Hexa runtime code
// due to assignment of heap offset of zero after strings allocation
// Also in C global values are guaranteed to be initialized to 0
// TODO check for `project.typer.typeInt` and other integer types
if value != '(int32_t)0' {
out.push('\t' + name + '_ = ' + value + ';\n')
}
}
}
//out.push('\n\tvar ' + name)
//if (expr != null) out.push(' = ' + printExpression(expr))
// TODO meybe not useful
// TODO maybe not useful
//else out.push(' = null')
case Const(name, expr, type):
globalVariables.push(stringifyType(type))
Expand Down

0 comments on commit 072549f

Please sign in to comment.