Skip to content

Commit 6d44387

Browse files
committed
[flang] Make subscript list argument a nullable pointer
Component::CreatePointerDescriptor unconditionally expects a vector of subscripts to be passed as an argument, but is called from NAMELIST input with a null pointer. Make that argument a nullable pointer, move it to the end of the argument list, and give it a default value of nullptr. Differential Revision: https://reviews.llvm.org/D113312
1 parent 80f0bb5 commit 6d44387

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

flang/runtime/assign.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ void Assign(Descriptor &to, const Descriptor &from, Terminator &terminator) {
193193
Descriptor &fromCompDesc{statDesc[1].descriptor()};
194194
for (std::size_t j{0}; j < toElements; ++j,
195195
to.IncrementSubscripts(toAt), from.IncrementSubscripts(fromAt)) {
196-
comp.CreatePointerDescriptor(toCompDesc, to, toAt, terminator);
196+
comp.CreatePointerDescriptor(toCompDesc, to, terminator, toAt);
197197
comp.CreatePointerDescriptor(
198-
fromCompDesc, from, fromAt, terminator);
198+
fromCompDesc, from, terminator, fromAt);
199199
Assign(toCompDesc, fromCompDesc, terminator);
200200
}
201201
} else { // Component has intrinsic type; simply copy raw bytes

flang/runtime/descriptor-io.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static bool DefaultFormattedComponentIO(IoStatementState &io,
249249
StaticDescriptor<maxRank, true, 16 /*?*/> statDesc;
250250
Descriptor &desc{statDesc.descriptor()};
251251
component.CreatePointerDescriptor(
252-
desc, origDescriptor, origSubscripts, terminator);
252+
desc, origDescriptor, terminator, origSubscripts);
253253
return DescriptorIO<DIR>(io, desc);
254254
} else {
255255
// Component is itself a descriptor

flang/runtime/namelist.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,18 @@ static bool HandleComponent(IoStatementState &io, Descriptor &desc,
236236
type{addendum ? addendum->derivedType() : nullptr}) {
237237
if (const typeInfo::Component *
238238
comp{type->FindDataComponent(compName, std::strlen(compName))}) {
239-
comp->CreatePointerDescriptor(desc, source, nullptr, handler);
239+
comp->CreatePointerDescriptor(desc, source, handler);
240240
return true;
241241
} else {
242242
handler.SignalError(
243243
"NAMELIST component reference '%%%s' of input group item %s is not "
244244
"a component of its derived type",
245245
compName, name);
246246
}
247+
} else if (source.type().IsDerived()) {
248+
handler.Crash("Derived type object '%s' in NAMELIST is missing its "
249+
"derived type information!",
250+
name);
247251
} else {
248252
handler.SignalError("NAMELIST component reference '%%%s' of input group "
249253
"item %s for non-derived type",
@@ -320,9 +324,14 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
320324
Descriptor &mutableDescriptor{staticDesc[whichStaticDesc].descriptor()};
321325
whichStaticDesc ^= 1;
322326
if (*next == '(') {
323-
HandleSubscripts(io, mutableDescriptor, *useDescriptor, name);
327+
if (!(HandleSubscripts(
328+
io, mutableDescriptor, *useDescriptor, name))) {
329+
return false;
330+
}
324331
} else {
325-
HandleComponent(io, mutableDescriptor, *useDescriptor, name);
332+
if (!HandleComponent(io, mutableDescriptor, *useDescriptor, name)) {
333+
return false;
334+
}
326335
}
327336
useDescriptor = &mutableDescriptor;
328337
next = io.GetCurrentChar();

flang/runtime/type-info.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,15 @@ void Component::EstablishDescriptor(Descriptor &descriptor,
116116
}
117117

118118
void Component::CreatePointerDescriptor(Descriptor &descriptor,
119-
const Descriptor &container, const SubscriptValue subscripts[],
120-
Terminator &terminator) const {
119+
const Descriptor &container, Terminator &terminator,
120+
const SubscriptValue *subscripts) const {
121121
RUNTIME_CHECK(terminator, genre_ == Genre::Data);
122122
EstablishDescriptor(descriptor, container, terminator);
123-
descriptor.set_base_addr(container.Element<char>(subscripts) + offset_);
123+
if (subscripts) {
124+
descriptor.set_base_addr(container.Element<char>(subscripts) + offset_);
125+
} else {
126+
descriptor.set_base_addr(container.OffsetElement<char>() + offset_);
127+
}
124128
descriptor.raw().attribute = CFI_attribute_pointer;
125129
}
126130

@@ -167,12 +171,11 @@ static void DumpScalarCharacter(
167171
}
168172

169173
FILE *DerivedType::Dump(FILE *f) const {
170-
std::fprintf(
171-
f, "DerivedType @ 0x%p:\n", reinterpret_cast<const void *>(this));
174+
std::fprintf(f, "DerivedType @ %p:\n", reinterpret_cast<const void *>(this));
172175
const std::uint64_t *uints{reinterpret_cast<const std::uint64_t *>(this)};
173176
for (int j{0}; j < 64; ++j) {
174177
int offset{j * static_cast<int>(sizeof *uints)};
175-
std::fprintf(f, " [+%3d](0x%p) 0x%016jx", offset,
178+
std::fprintf(f, " [+%3d](%p) 0x%016jx", offset,
176179
reinterpret_cast<const void *>(&uints[j]),
177180
static_cast<std::uintmax_t>(uints[j]));
178181
if (offset == offsetof(DerivedType, binding_)) {
@@ -235,7 +238,7 @@ FILE *DerivedType::Dump(FILE *f) const {
235238
}
236239

237240
FILE *Component::Dump(FILE *f) const {
238-
std::fprintf(f, "Component @ 0x%p:\n", reinterpret_cast<const void *>(this));
241+
std::fprintf(f, "Component @ %p:\n", reinterpret_cast<const void *>(this));
239242
std::fputs(" name: ", f);
240243
DumpScalarCharacter(f, name(), "Component::name");
241244
if (genre_ == Genre::Data) {
@@ -252,7 +255,7 @@ FILE *Component::Dump(FILE *f) const {
252255
std::fprintf(f, " category %d kind %d rank %d offset 0x%zx\n", category_,
253256
kind_, rank_, static_cast<std::size_t>(offset_));
254257
if (initialization_) {
255-
std::fprintf(f, " initialization @ 0x%p:\n",
258+
std::fprintf(f, " initialization @ %p:\n",
256259
reinterpret_cast<const void *>(initialization_));
257260
for (int j{0}; j < 128; j += sizeof(std::uint64_t)) {
258261
std::fprintf(f, " [%3d] 0x%016jx\n", j,
@@ -265,7 +268,7 @@ FILE *Component::Dump(FILE *f) const {
265268

266269
FILE *SpecialBinding::Dump(FILE *f) const {
267270
std::fprintf(
268-
f, "SpecialBinding @ 0x%p:\n", reinterpret_cast<const void *>(this));
271+
f, "SpecialBinding @ %p:\n", reinterpret_cast<const void *>(this));
269272
switch (which_) {
270273
case Which::ScalarAssignment:
271274
std::fputs(" ScalarAssignment", f);
@@ -297,7 +300,7 @@ FILE *SpecialBinding::Dump(FILE *f) const {
297300
break;
298301
}
299302
std::fprintf(f, " isArgDescriptorSet: 0x%x\n", isArgDescriptorSet_);
300-
std::fprintf(f, " proc: 0x%p\n", reinterpret_cast<void *>(proc_));
303+
std::fprintf(f, " proc: %p\n", reinterpret_cast<void *>(proc_));
301304
return f;
302305
}
303306

flang/runtime/type-info.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ class Component {
8686
void EstablishDescriptor(
8787
Descriptor &, const Descriptor &container, Terminator &) const;
8888

89-
// Creates a pointer descriptor from this component description.
89+
// Creates a pointer descriptor from this component description, possibly
90+
// with subscripts
9091
void CreatePointerDescriptor(Descriptor &, const Descriptor &container,
91-
const SubscriptValue[], Terminator &) const;
92+
Terminator &, const SubscriptValue * = nullptr) const;
9293

9394
FILE *Dump(FILE * = stdout) const;
9495

0 commit comments

Comments
 (0)