if(raceenabled)
m->racepc = runtime·getcallerpc(&typ);
- flag = typ->kind&KindNoPointers ? FlagNoPointers : 0;
- ret = runtime·mallocgc(typ->size, flag, 1, 1);
- if(UseSpanType && !flag) {
- if(false) {
- runtime·printf("new %S: %p\n", *typ->string, ret);
+ if(typ->size == 0) {
+ // All 0-length allocations use this pointer.
+ // The language does not require the allocations to
+ // have distinct values.
+ ret = (uint8*)&runtime·zerobase;
+ } else {
+ flag = typ->kind&KindNoPointers ? FlagNoPointers : 0;
+ ret = runtime·mallocgc(typ->size, flag, 1, 1);
+
+ if(UseSpanType && !flag) {
+ if(false) {
+ runtime·printf("new %S: %p\n", *typ->string, ret);
+ }
+ runtime·settype(ret, (uintptr)typ | TypeInfo_SingleObject);
}
- runtime·settype(ret, (uintptr)typ | TypeInfo_SingleObject);
}
FLUSH(&ret);
if(raceenabled)
m->racepc = runtime·getcallerpc(&typ);
- flag = typ->kind&KindNoPointers ? FlagNoPointers : 0;
- ret = runtime·mallocgc(typ->size, flag, 1, 1);
- if(UseSpanType && !flag) {
- if(false) {
- runtime·printf("new %S: %p\n", *typ->string, ret);
+ if(typ->size == 0) {
+ // All 0-length allocations use this pointer.
+ // The language does not require the allocations to
+ // have distinct values.
+ ret = (uint8*)&runtime·zerobase;
+ } else {
+ flag = typ->kind&KindNoPointers ? FlagNoPointers : 0;
+ ret = runtime·mallocgc(typ->size, flag, 1, 1);
+
+ if(UseSpanType && !flag) {
+ if(false) {
+ runtime·printf("new %S: %p\n", *typ->string, ret);
+ }
+ runtime·settype(ret, (uintptr)typ | TypeInfo_SingleObject);
}
- runtime·settype(ret, (uintptr)typ | TypeInfo_SingleObject);
}
+
return ret;
}