Skip to content

Commit f0cf3c5

Browse files
committed
minor fixes in tools and move memory deallocate to bottom.
1 parent 438362d commit f0cf3c5

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

flang/runtime/execute.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
177177
exit(status);
178178
}
179179
#endif
180-
FreeMemory((void *)newCmd);
181180
}
181+
FreeMemory((void *)newCmd);
182182
}
183183

184184
} // namespace Fortran::runtime

flang/runtime/tools.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,30 +195,26 @@ RT_API_ATTRS std::size_t LengthWithoutTrailingSpaces(const Descriptor &d) {
195195

196196
// Returns the length of the \p string. Assumes \p string is valid.
197197
RT_API_ATTRS std::int64_t StringLength(const char *string) {
198-
std::size_t length{std::strlen(string)};
199-
if constexpr (sizeof(std::size_t) < sizeof(std::int64_t)) {
200-
return static_cast<std::int64_t>(length);
201-
} else {
202-
std::size_t max{std::numeric_limits<std::int64_t>::max()};
203-
return length > max ? 0 // Just fail.
204-
: static_cast<std::int64_t>(length);
205-
}
198+
return static_cast<std::int64_t>(std::strlen(string));
206199
}
207200

201+
// Assumes Descriptor \p value is not nullptr.
208202
RT_API_ATTRS bool IsValidCharDescriptor(const Descriptor *value) {
209203
return value && value->IsAllocated() &&
210204
value->type() == TypeCode(TypeCategory::Character, 1) &&
211205
value->rank() == 0;
212206
}
213207

214-
RT_API_ATTRS bool IsValidIntDescriptor(const Descriptor *length) {
215-
auto typeCode{length->type().GetCategoryAndKind()};
208+
// Assumes Descriptor \p intVal is not nullptr.
209+
RT_API_ATTRS bool IsValidIntDescriptor(const Descriptor *intVal) {
210+
auto typeCode{intVal->type().GetCategoryAndKind()};
216211
// Check that our descriptor is allocated and is a scalar integer with
217212
// kind != 1 (i.e. with a large enough decimal exponent range).
218-
return length->IsAllocated() && length->rank() == 0 &&
219-
length->type().IsInteger() && typeCode && typeCode->second != 1;
213+
return intVal->IsAllocated() && intVal->rank() == 0 &&
214+
intVal->type().IsInteger() && typeCode && typeCode->second != 1;
220215
}
221216

217+
// Assume Descriptor \p value is valid: pass IsValidCharDescriptor check.
222218
RT_API_ATTRS void FillWithSpaces(const Descriptor &value, std::size_t offset) {
223219
if (offset < value.ElementBytes()) {
224220
std::memset(

flang/runtime/tools.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,13 @@ RT_API_ATTRS std::size_t LengthWithoutTrailingSpaces(const Descriptor &d);
420420
// Returns the length of the \p string. Assumes \p string is valid.
421421
RT_API_ATTRS std::int64_t StringLength(const char *string);
422422

423+
// Assumes Descriptor \p value is not nullptr.
423424
RT_API_ATTRS bool IsValidCharDescriptor(const Descriptor *value);
424425

425-
RT_API_ATTRS bool IsValidIntDescriptor(const Descriptor *length);
426+
// Assumes Descriptor \p intVal is not nullptr.
427+
RT_API_ATTRS bool IsValidIntDescriptor(const Descriptor *intVal);
426428

429+
// Assume Descriptor \p value is valid: pass IsValidCharDescriptor check.
427430
RT_API_ATTRS void FillWithSpaces(
428431
const Descriptor &value, std::size_t offset = 0);
429432

0 commit comments

Comments
 (0)