Skip to content

Commit b87db5b

Browse files
authored
[flang][runtime] Fixed flang-runtime-cuda-gcc builder after af964c7. (#85144)
1 parent db058b9 commit b87db5b

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

flang/include/flang/Runtime/api-attrs.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@
109109
#endif
110110
#endif /* !defined(RT_CONST_VAR_ATTRS) */
111111

112+
/*
113+
* RT_VAR_ATTRS is marking non-const/constexpr module scope variables
114+
* referenced by Flang runtime.
115+
*/
116+
#ifndef RT_VAR_ATTRS
117+
#if (defined(__CUDACC__) || defined(__CUDA__)) && defined(__CUDA_ARCH__)
118+
#define RT_VAR_ATTRS __device__
119+
#else
120+
#define RT_VAR_ATTRS
121+
#endif
122+
#endif /* !defined(RT_VAR_ATTRS) */
123+
112124
/*
113125
* RT_DEVICE_COMPILATION is defined for any device compilation.
114126
* Note that it can only be used reliably with compilers that perform

flang/runtime/environment.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ extern char **environ;
2323

2424
namespace Fortran::runtime {
2525

26-
ExecutionEnvironment executionEnvironment;
26+
RT_OFFLOAD_VAR_GROUP_BEGIN
27+
RT_VAR_ATTRS ExecutionEnvironment executionEnvironment;
28+
RT_OFFLOAD_VAR_GROUP_END
2729

2830
static void SetEnvironmentDefaults(const EnvironmentDefaultList *envDefaults) {
2931
if (!envDefaults) {

flang/runtime/environment.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define FORTRAN_RUNTIME_ENVIRONMENT_H_
1111

1212
#include "flang/Decimal/decimal.h"
13+
#include "flang/Runtime/api-attrs.h"
1314
#include <optional>
1415

1516
struct EnvironmentDefaultList;
@@ -32,7 +33,11 @@ enum class Convert { Unknown, Native, LittleEndian, BigEndian, Swap };
3233
std::optional<Convert> GetConvertFromString(const char *, std::size_t);
3334

3435
struct ExecutionEnvironment {
35-
constexpr ExecutionEnvironment(){};
36+
#if !defined(_OPENMP)
37+
// FIXME: https://github.com/llvm/llvm-project/issues/84942
38+
constexpr
39+
#endif
40+
ExecutionEnvironment(){};
3641
void Configure(int argc, const char *argv[], const char *envp[],
3742
const EnvironmentDefaultList *envDefaults);
3843
const char *GetEnv(
@@ -51,7 +56,10 @@ struct ExecutionEnvironment {
5156
bool checkPointerDeallocation{true}; // FORT_CHECK_POINTER_DEALLOCATION
5257
};
5358

54-
extern ExecutionEnvironment executionEnvironment;
59+
RT_OFFLOAD_VAR_GROUP_BEGIN
60+
extern RT_VAR_ATTRS ExecutionEnvironment executionEnvironment;
61+
RT_OFFLOAD_VAR_GROUP_END
62+
5563
} // namespace Fortran::runtime
5664

5765
#endif // FORTRAN_RUNTIME_ENVIRONMENT_H_

0 commit comments

Comments
 (0)