Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The TwoArrayRadixSort path causes memory corruption (?) when it is used with records that have array fields #26730

Open
e-kayrakli opened this issue Feb 19, 2025 · 1 comment

Comments

@e-kayrakli
Copy link
Contributor

... though this is probably a compiler bug that is exposed by TwoArrayRadixSort

use Sort;

record r {
  var keyField: real;
  var dummyField: [1..3] real;
}

record myComparator { }
proc myComparator.key(const ref obj: r){
  return obj.keyField;
}

config const n = 10;
var Arr: [1..n] r;

sort(Arr, comparator=new myComparator());
writeln(Arr[1]);

Here r is a record with a keyField and a dummyField that's not used. keyField is used while sorting the array Arr.

Any option avoiding the TwoArrayRadixSort path works. Namely, stable=true works, using 49999 element array works, 50000 doesn't as that's the TwoArrayRadixSort threshold.

I get

$CHPL_HOME/modules/internal/ChapelArray.chpl:1531: error: attempt to dereference nil

This is array deallocation code.

In the real case, I get similar errors, but the issue is harder to debug as it generates a core dump. My theory is that this is about deinitializing dummyField for the second array we use or some temporary. But I haven't looked any deeper into the sort code to understand.

The potential workaround is to use a tuple instead of an array for dummyField, assuming that it is relatively small.

@e-kayrakli
Copy link
Contributor Author

Tagging @mppf because of his Sort expertise. The issue is most likely a compiler issue, but understanding the algorithm would be helpful in understanding the bug.

@e-kayrakli e-kayrakli changed the title The TwoArrayRadixSort path causes memory corruption (?) when it is used with records that has array fields The TwoArrayRadixSort path causes memory corruption (?) when it is used with records that have array fields Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant