18747, "jlbyrne-hpe", "Array assignment of BlockDist arrays segfaults, forall zip does not", "2021-11-18T21:51:05Z"
// segfaults
region.array = array;
// works
forall (d,s) in zip(region.array, array) do
d = s;
Steps to Reproduce
Source Code: spam.chpl
module Spam {
use BlockDist;
use CPtr;
use IO;
use IO.FormattedIO;
use Reflection;
type region_desc = c_ptr(void);
class Sam {
proc lookup_region(regionName:string): region_desc throws {
return c_nil;
}
}
class Region {
const regionName: string;
var regionDescs = newBlockArr({0..#numLocales}, region_desc);
const size: uint(64);
var iAmDestroyed = false;
proc init(regionName: string, size: uint(64)) {
this.regionName = regionName;
this.size = size;
}
}
// An attempted workaround for typing and initialization issues
// I thought because I initialized Region.regionDescs the declaration
// that something was getting confused about initialization and assignment
// in init(). This didn't change things, though.
proc newSharedRegion(regionName: string, size: uint(64),
ref regionDescs: [] region_desc) throws {
try! stderr.writeln("%s %i".format(getRoutineName(), getLineNumber()));
var region = new shared Region(regionName, size);
try! stderr.writeln("%s %i".format(getRoutineName(), getLineNumber()));
// This segfaults for me.
region.regionDescs = regionDescs;
// This doesn't.
// forall (d, s) in zip(region.regionDescs, regionDescs) do
// d = s;
try! stderr.writeln("%s %i".format(getRoutineName(), getLineNumber()));
return region;
}
var sammy = new Sam();
private proc regionLookups(ref regionDescs, regionName: string) throws {
// Won't break if the try isn't there.
try {
// The "with in" seems to be required as well
forall r in regionDescs {
var rName = regionName;
r = sammy.lookup_region(rName);
}
}
}
private proc lookup(regionName: string) throws {
var regionDescs = newBlockArr(0..#numLocales, region_desc);
regionLookups(regionDescs, regionName);
return newSharedRegion(regionName, 1024, regionDescs);
}
proc main() : int {
try! lookup("a");
return 0;
}
}
Compile command:
chpl -o spam spam.chpl
Execution command:
./spam -nl 1
Configuration Information
- Output of
chpl --version
:
chpl version 1.25.0
built with LLVM version 11.0.1 - Output of
$CHPL_HOME/util/printchplenv --anonymize
:
-CHPL_TARGET_PLATFORM: linux64
CHPL_TARGET_COMPILER: clang *
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: native *
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none *
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_ATOMICS: cstdlib
CHPL_GMP: bundled
CHPL_HWLOC: bundled
CHPL_RE2: bundled *
CHPL_LLVM: bundled *
CHPL_AUX_FILESYS: none - Back-end compiler and version, e.g.
gcc --version
orclang --version
:
clang version 11.0.1 (git@github.hpe.com:john-l-byrne/chapel.git 400cb9af1a54df5ae00a106bd7404c15657be9ac)
Target: x86_64-unknown-linux-gnu
Thread model: posix