Skip to content

Commit

Permalink
fix argument pointer wrapping in function pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 committed Mar 22, 2024
1 parent b1f53e7 commit 071b5c5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/common/scripting/frontend/zcc_compile.cpp
Expand Up @@ -43,6 +43,11 @@
FSharedStringArena VMStringConstants;


static bool ShouldWrapPointer(PType * type)
{
return ((type->isStruct() && type != TypeVector2 && type != TypeVector3 && type != TypeVector4 && type != TypeQuaternion && type != TypeFVector2 && type != TypeFVector3 && type != TypeFVector4 && type != TypeFQuaternion) || type->isDynArray() || type->isMap() || type->isMapIterator());
}

int GetIntConst(FxExpression *ex, FCompileContext &ctx)
{
ex = new FxIntCast(ex, false);
Expand Down Expand Up @@ -2049,8 +2054,17 @@ PType *ZCCCompiler::DetermineType(PType *outertype, ZCC_TreeNode *field, FName n
} while( (t = (ZCC_Type *)t->SiblingNext) != fn->RetType);

if(auto *t = fn->Params; t != nullptr) do {
args.Push(DetermineType(outertype, field, name, t->Type, false, false));
argflags.Push(t->Flags == ZCC_Out ? VARF_Out : 0);
PType * tt = DetermineType(outertype, field, name, t->Type, false, false);
int flags = 0;

if (ShouldWrapPointer(tt))
{
tt = NewPointer(tt);
flags = VARF_Ref;
}

args.Push(tt);
argflags.Push(t->Flags == ZCC_Out ? VARF_Out|flags : flags);
} while( (t = (ZCC_FuncPtrParamDecl *) t->SiblingNext) != fn->Params);

auto proto = NewPrototype(returns,args);
Expand Down Expand Up @@ -2550,7 +2564,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
{
auto type = DetermineType(c->Type(), p, f->Name, p->Type, false, false);
int flags = 0;
if ((type->isStruct() && type != TypeVector2 && type != TypeVector3 && type != TypeVector4 && type != TypeQuaternion && type != TypeFVector2 && type != TypeFVector3 && type != TypeFVector4 && type != TypeFQuaternion) || type->isDynArray() || type->isMap() || type->isMapIterator())
if (ShouldWrapPointer(type))
{
// Structs are being passed by pointer, but unless marked 'out' that pointer must be readonly.
type = NewPointer(type /*, !(p->Flags & ZCC_Out)*/);
Expand Down

0 comments on commit 071b5c5

Please sign in to comment.