[flang] Change complex type define in runtime for clang-cl
When compiling the runtime with a version of clang-cl newer than 12, we
define CMPLXF as __builtin_complex, which returns a float _Complex type.
This errors out in contexts where the result of CMPLXF is expected to be
a float_Complex_t. This is defined as _Fcomplex whenever _MSC_VER is
defined (and as float _Complex otherwise).
This patch defines float_Complex_t & friends as _Fcomplex only when
we're using "true" MSVC, and not just clang-pretending-to-be-MSVC. This
should only affect clang-cl >= 12.
Differential Revision: https://reviews.llvm.org/D110139
GitOrigin-RevId: abbb0f901ad85aaa06780deefbda9c0ee0c2c7a2
diff --git a/runtime/complex-reduction.c b/runtime/complex-reduction.c
index d0ca50f..0e40c04 100644
--- a/runtime/complex-reduction.c
+++ b/runtime/complex-reduction.c
@@ -23,7 +23,7 @@
/* Not all environments define CMPLXF, CMPLX, CMPLXL. */
#ifndef CMPLXF
-#if __clang_major__ >= 12
+#if defined(__clang_major__) && (__clang_major__ >= 12)
#define CMPLXF __builtin_complex
#else
static float_Complex_t CMPLXF(float r, float i) {
@@ -39,7 +39,7 @@
#endif
#ifndef CMPLX
-#if __clang_major__ >= 12
+#if defined(__clang_major__) && (__clang_major__ >= 12)
#define CMPLX __builtin_complex
#else
static double_Complex_t CMPLX(double r, double i) {
@@ -55,7 +55,7 @@
#endif
#ifndef CMPLXL
-#if __clang_major__ >= 12
+#if defined(__clang_major__) && (__clang_major__ >= 12)
#define CMPLXL __builtin_complex
#else
static long_double_Complex_t CMPLXL(long double r, long double i) {
diff --git a/runtime/complex-reduction.h b/runtime/complex-reduction.h
index 5940fff..8e57f7c 100644
--- a/runtime/complex-reduction.h
+++ b/runtime/complex-reduction.h
@@ -20,7 +20,7 @@
struct CppDescriptor; /* dummy type name for Fortran::runtime::Descriptor */
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && !(defined(__clang_major__) && __clang_major__ >= 12)
typedef _Fcomplex float_Complex_t;
typedef _Dcomplex double_Complex_t;
typedef _Lcomplex long_double_Complex_t;