Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flang-rt/lib/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(supported_sources
assign.cpp
buffer.cpp
character.cpp
complex-powi.cpp
connection.cpp
copy.cpp
derived-api.cpp
Expand Down
17 changes: 10 additions & 7 deletions flang-rt/lib/runtime/complex-powi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Common/api-attrs.h"
#include "flang/Common/float128.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/entry-names.h"
Expand All @@ -18,7 +19,7 @@ namespace Fortran::runtime {
#pragma clang diagnostic ignored "-Wc99-extensions"
#endif

template <typename C, typename I> C tgpowi(C base, I exp) {
template <typename C, typename I> inline RT_API_ATTRS C tgpowi(C base, I exp) {
if (exp == 0) {
return C{1};
}
Expand Down Expand Up @@ -65,21 +66,23 @@ template <typename C, typename I> C tgpowi(C base, I exp) {
#ifndef _MSC_VER
// With most compilers, C complex is implemented as a builtin type that may have
// specific ABI requirements
extern "C" float _Complex RTNAME(cpowi)(float _Complex base, std::int32_t exp) {
extern "C" RT_API_ATTRS CppTypeFor<TypeCategory::Complex, 4> RTNAME(cpowi)(
CppTypeFor<TypeCategory::Complex, 4> base, std::int32_t exp) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I do not know where we stand with passing the complex values from Flang to the runtime, but the C complex was used here to match the ABI of pure C complex. The discussion was here: https://reviews.llvm.org/D134889

This change may be unsafe, but this needs to be investigated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'm a bit confused since lots of other runtime functions use the CppType and only complex-powi.cpp and complex-reduction.h use the C complex. I'll have a deeper look when I have more time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the other APIs are passing args as references/pointers, and the memory layout is assumed to be the same for C and C++ complex. The problem (or not) is passing it by value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right! I missed that part. Thanks. I'll gonna keep a look on that.

return tgpowi(base, exp);
}

extern "C" double _Complex RTNAME(zpowi)(
double _Complex base, std::int32_t exp) {
extern "C" RT_API_ATTRS CppTypeFor<TypeCategory::Complex, 8> RTNAME(zpowi)(
CppTypeFor<TypeCategory::Complex, 8> base, std::int32_t exp) {
return tgpowi(base, exp);
}

extern "C" float _Complex RTNAME(cpowk)(float _Complex base, std::int64_t exp) {
extern "C" RT_API_ATTRS CppTypeFor<TypeCategory::Complex, 4> RTNAME(cpowk)(
CppTypeFor<TypeCategory::Complex, 4> base, std::int64_t exp) {
return tgpowi(base, exp);
}

extern "C" double _Complex RTNAME(zpowk)(
double _Complex base, std::int64_t exp) {
extern "C" RT_API_ATTRS CppTypeFor<TypeCategory::Complex, 8> RTNAME(zpowk)(
CppTypeFor<TypeCategory::Complex, 8> base, std::int64_t exp) {
return tgpowi(base, exp);
}

Expand Down
Loading