Skip to content

Commit

Permalink
Fix invalid codegen when returning a static array.
Browse files Browse the repository at this point in the history
Bug: issue #977
Test: new test case
  • Loading branch information
dvander committed Nov 29, 2024
1 parent d23897e commit a90c134
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/code-generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ CodeGenerator::EmitRvalue(value* lval)
auto var = lval->sym->as<VarDeclBase>();
if (var->vclass() == sLOCAL || var->vclass() == sARGUMENT)
__ emit(OP_LOAD_S_PRI, var->addr());
else
else if (!(var->type()->isArray() || var->type()->isEnumStruct()))
__ emit(OP_LOAD_PRI, var->addr());
break;
}
Expand Down
1 change: 1 addition & 0 deletions tests/regressions/return-static-array.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asdada
13 changes: 13 additions & 0 deletions tests/regressions/return-static-array.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
native void print(const char[] x);
#define MAX_LEN 32

public void main() {
print(FooterGet());
}

char[] FooterGet()
{
static char buffer[MAX_LEN] = "asdada";

return buffer;
}

0 comments on commit a90c134

Please sign in to comment.