Skip to content

Conversation

@ArcaneNibble
Copy link
Member

Previous PR: #129308

Changes: I added REQUIRES: x86-registered-target to the newly-added test so that it won't break the other buildbots.

@ArcaneNibble ArcaneNibble requested a review from clementval March 8, 2025 03:02
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:codegen labels Mar 8, 2025
@ArcaneNibble
Copy link
Member Author

Apologies, wrong branch

@llvmbot
Copy link
Member

llvmbot commented Mar 8, 2025

@llvm/pr-subscribers-flang-fir-hlfir

@llvm/pr-subscribers-flang-codegen

Author: R (ArcaneNibble)

Changes

Previous PR: #129308

Changes: I added REQUIRES: x86-registered-target to the newly-added test so that it won't break the other buildbots.


Patch is 110.40 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/130384.diff

14 Files Affected:

  • (modified) flang-rt/lib/runtime/execute.cpp (+8)
  • (modified) flang-rt/lib/runtime/extensions.cpp (+2-2)
  • (modified) flang-rt/lib/runtime/file.cpp (+5)
  • (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+72-7)
  • (modified) flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h (+166-160)
  • (modified) flang/lib/Lower/Allocatable.cpp (+2-2)
  • (modified) flang/lib/Lower/IO.cpp (+4-4)
  • (modified) flang/lib/Optimizer/Builder/FIRBuilder.cpp (+19)
  • (modified) flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp (+7-5)
  • (modified) flang/lib/Optimizer/Builder/Runtime/Numeric.cpp (+44-22)
  • (modified) flang/lib/Optimizer/Builder/Runtime/Reduction.cpp (+224-112)
  • (modified) flang/lib/Optimizer/Builder/Runtime/Support.cpp (+2-2)
  • (modified) flang/lib/Optimizer/Builder/Runtime/Transformational.cpp (+31-21)
  • (modified) flang/lib/Optimizer/CodeGen/Target.cpp (+41)
diff --git a/flang-rt/lib/runtime/execute.cpp b/flang-rt/lib/runtime/execute.cpp
index f180da846a32c..da13f74d17884 100644
--- a/flang-rt/lib/runtime/execute.cpp
+++ b/flang-rt/lib/runtime/execute.cpp
@@ -21,7 +21,9 @@
 #include "flang/Common/windows-include.h"
 #else
 #include <signal.h>
+#ifndef __wasi__
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 #endif
 
@@ -65,6 +67,7 @@ void CheckAndStoreIntToDescriptor(
   }
 }
 
+#ifndef __wasi__
 // If a condition occurs that would assign a nonzero value to CMDSTAT but
 // the CMDSTAT variable is not present, error termination is initiated.
 std::int64_t TerminationCheck(std::int64_t status, const Descriptor *cmdstat,
@@ -180,6 +183,7 @@ std::int64_t TerminationCheck(std::int64_t status, const Descriptor *cmdstat,
 #endif
   return exitStatusVal;
 }
+#endif
 
 void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
     const Descriptor *exitstat, const Descriptor *cmdstat,
@@ -202,6 +206,7 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
     RUNTIME_CHECK(terminator, IsValidCharDescriptor(cmdmsg));
   }
 
+#ifndef __wasi__
   if (wait) {
     // either wait is not specified or wait is true: synchronous mode
     std::int64_t status{std::system(newCmd)};
@@ -278,6 +283,9 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
     }
 #endif
   }
+#else
+  terminator.Crash("not supported on WASI");
+#endif
   // Deallocate memory if EnsureNullTerminated dynamically allocated memory
   if (newCmd != command.OffsetElement()) {
     FreeMemory(newCmd);
diff --git a/flang-rt/lib/runtime/extensions.cpp b/flang-rt/lib/runtime/extensions.cpp
index 75195c33a6c21..eb016bd733e0e 100644
--- a/flang-rt/lib/runtime/extensions.cpp
+++ b/flang-rt/lib/runtime/extensions.cpp
@@ -61,7 +61,7 @@ extern "C" {
 namespace Fortran::runtime {
 
 gid_t RTNAME(GetGID)() {
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__wasi__)
   // Group IDs don't exist on Windows, return 1 to avoid errors
   return 1;
 #else
@@ -70,7 +70,7 @@ gid_t RTNAME(GetGID)() {
 }
 
 uid_t RTNAME(GetUID)() {
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__wasi__)
   // User IDs don't exist on Windows, return 1 to avoid errors
   return 1;
 #else
diff --git a/flang-rt/lib/runtime/file.cpp b/flang-rt/lib/runtime/file.cpp
index 16e73db488727..8e2bc97ef7dac 100644
--- a/flang-rt/lib/runtime/file.cpp
+++ b/flang-rt/lib/runtime/file.cpp
@@ -31,6 +31,10 @@ void OpenFile::set_path(OwningPtr<char> &&path, std::size_t bytes) {
 }
 
 static int openfile_mkstemp(IoErrorHandler &handler) {
+#ifdef __wasi__
+  handler.SignalError("not supported on WASI");
+  return -1;
+#else
 #ifdef _WIN32
   const unsigned int uUnique{0};
   // GetTempFileNameA needs a directory name < MAX_PATH-14 characters in length.
@@ -58,6 +62,7 @@ static int openfile_mkstemp(IoErrorHandler &handler) {
   ::unlink(path);
 #endif
   return fd;
+#endif
 }
 
 void OpenFile::Open(OpenStatus status, Fortran::common::optional<Action> action,
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index 1675c15363868..fe496d34813eb 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -43,9 +43,28 @@ class BoxValue;
 inline mlir::Type getIntPtrType(mlir::OpBuilder &builder) {
   // TODO: Delay the need of such type until codegen or find a way to use
   // llvm::DataLayout::getPointerSizeInBits here.
+  // (Note: this is *only* used by MemoryUtils.cpp)
   return builder.getI64Type();
 }
 
+//===----------------------------------------------------------------------===//
+// MinimalCTargetInfo
+//===----------------------------------------------------------------------===//
+
+/// Minimal information needed to interface with C code on the target,
+/// for generating runtime calls.
+struct MinimalCTargetInfo {
+  unsigned char CharWidth;
+  unsigned char ShortWidth;
+  unsigned char IntWidth;
+  unsigned char LongWidth;
+  unsigned char LongLongWidth;
+  unsigned char DataPointerWidth;
+  unsigned char EnumWidth;
+
+  MinimalCTargetInfo(const llvm::Triple &T);
+};
+
 //===----------------------------------------------------------------------===//
 // FirOpBuilder
 //===----------------------------------------------------------------------===//
@@ -57,7 +76,8 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
   explicit FirOpBuilder(mlir::Operation *op, fir::KindMapping kindMap,
                         mlir::SymbolTable *symbolTable = nullptr)
       : OpBuilder{op, /*listener=*/this}, kindMap{std::move(kindMap)},
-        symbolTable{symbolTable} {
+        symbolTable{symbolTable},
+        cTargetInfo{fir::getTargetTriple(getModule())} {
     auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
     if (fmi) {
       // Set the builder with FastMathFlags attached to the operation.
@@ -67,17 +87,20 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
   explicit FirOpBuilder(mlir::OpBuilder &builder, fir::KindMapping kindMap,
                         mlir::SymbolTable *symbolTable = nullptr)
       : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)},
-        symbolTable{symbolTable} {
+        symbolTable{symbolTable},
+        cTargetInfo{fir::getTargetTriple(getModule())} {
     setListener(this);
   }
   explicit FirOpBuilder(mlir::OpBuilder &builder, mlir::ModuleOp mod)
       : OpBuilder(builder), OpBuilder::Listener(),
-        kindMap{getKindMapping(mod)} {
+        kindMap{getKindMapping(mod)},
+        cTargetInfo{fir::getTargetTriple(getModule())} {
     setListener(this);
   }
   explicit FirOpBuilder(mlir::OpBuilder &builder, fir::KindMapping kindMap,
                         mlir::Operation *op)
-      : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)} {
+      : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)},
+        cTargetInfo{fir::getTargetTriple(getModule())} {
     setListener(this);
     auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
     if (fmi) {
@@ -93,7 +116,8 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
       : OpBuilder(other), OpBuilder::Listener(), kindMap{other.kindMap},
         fastMathFlags{other.fastMathFlags},
         integerOverflowFlags{other.integerOverflowFlags},
-        symbolTable{other.symbolTable} {
+        symbolTable{other.symbolTable},
+        cTargetInfo{other.cTargetInfo} {
     setListener(this);
   }
 
@@ -101,7 +125,8 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
       : OpBuilder(other), OpBuilder::Listener(),
         kindMap{std::move(other.kindMap)}, fastMathFlags{other.fastMathFlags},
         integerOverflowFlags{other.integerOverflowFlags},
-        symbolTable{other.symbolTable} {
+        symbolTable{other.symbolTable},
+        cTargetInfo{other.cTargetInfo} {
     setListener(this);
   }
 
@@ -160,7 +185,45 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
 
   /// Get the integer type whose bit width corresponds to the width of pointer
   /// types, or is bigger.
-  mlir::Type getIntPtrType() { return fir::getIntPtrType(*this); }
+  mlir::Type getIntPtrType() {
+    return getIntegerType(cTargetInfo.DataPointerWidth);
+  }
+
+  /// Get the integer type whose bit width corresponds to the width of
+  /// the `char` type in C
+  mlir::Type getCCharType() {
+    return getIntegerType(cTargetInfo.CharWidth);
+  }
+
+  /// Get the integer type whose bit width corresponds to the width of
+  /// the `short` type in C
+  mlir::Type getCShortType() {
+    return getIntegerType(cTargetInfo.ShortWidth);
+  }
+
+  /// Get the integer type whose bit width corresponds to the width of
+  /// the `int` type in C
+  mlir::Type getCIntType() {
+    return getIntegerType(cTargetInfo.IntWidth);
+  }
+
+  /// Get the integer type whose bit width corresponds to the width of
+  /// the `long` type in C
+  mlir::Type getCLongType() {
+    return getIntegerType(cTargetInfo.LongWidth);
+  }
+
+  /// Get the integer type whose bit width corresponds to the width of
+  /// the `long long` type in C
+  mlir::Type getCLongLongType() {
+    return getIntegerType(cTargetInfo.LongLongWidth);
+  }
+
+  /// Get the integer type whose bit width corresponds to the width of
+  /// enums in C
+  mlir::Type getCEnumType() {
+    return getIntegerType(cTargetInfo.EnumWidth);
+  }
 
   /// Wrap `str` to a SymbolRefAttr.
   mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str) {
@@ -619,6 +682,8 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
   /// Stored via a unique_ptr rather than an optional so as not to bloat this
   /// class when most instances won't ever need a data layout.
   std::unique_ptr<mlir::DataLayout> dataLayout = nullptr;
+
+  MinimalCTargetInfo cTargetInfo;
 };
 
 } // namespace fir
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index 5158abaa31ed1..4021e8149fadf 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -51,17 +51,18 @@ class DerivedType;
 
 namespace fir::runtime {
 
-using TypeBuilderFunc = mlir::Type (*)(mlir::MLIRContext *);
-using FuncTypeBuilderFunc = mlir::FunctionType (*)(mlir::MLIRContext *);
+using TypeBuilderFunc = mlir::Type (*)(fir::FirOpBuilder &);
+using FuncTypeBuilderFunc = mlir::FunctionType (*)(fir::FirOpBuilder &);
 
 #define REDUCTION_REF_OPERATION_MODEL(T)                                       \
   template <>                                                                  \
   constexpr TypeBuilderFunc                                                    \
   getModel<Fortran::runtime::ReferenceReductionOperation<T>>() {               \
-    return [](mlir::MLIRContext *context) -> mlir::Type {                      \
+    return [](fir::FirOpBuilder &builder) -> mlir::Type {                      \
       TypeBuilderFunc f{getModel<T>()};                                        \
-      auto refTy = fir::ReferenceType::get(f(context));                        \
-      return mlir::FunctionType::get(context, {refTy, refTy}, refTy);          \
+      auto refTy = fir::ReferenceType::get(f(builder));                        \
+      return mlir::FunctionType::get(builder.getContext(), {refTy, refTy},     \
+                                     refTy);                                   \
     };                                                                         \
   }
 
@@ -69,11 +70,11 @@ using FuncTypeBuilderFunc = mlir::FunctionType (*)(mlir::MLIRContext *);
   template <>                                                                  \
   constexpr TypeBuilderFunc                                                    \
   getModel<Fortran::runtime::ValueReductionOperation<T>>() {                   \
-    return [](mlir::MLIRContext *context) -> mlir::Type {                      \
+    return [](fir::FirOpBuilder &builder) -> mlir::Type {                      \
       TypeBuilderFunc f{getModel<T>()};                                        \
-      auto refTy = fir::ReferenceType::get(f(context));                        \
-      return mlir::FunctionType::get(context, {f(context), f(context)},        \
-                                     refTy);                                   \
+      auto refTy = fir::ReferenceType::get(f(builder));                        \
+      return mlir::FunctionType::get(builder.getContext(),                     \
+                                     {f(builder), f(builder)}, refTy);         \
     };                                                                         \
   }
 
@@ -81,16 +82,16 @@ using FuncTypeBuilderFunc = mlir::FunctionType (*)(mlir::MLIRContext *);
   template <>                                                                  \
   constexpr TypeBuilderFunc                                                    \
   getModel<Fortran::runtime::ReductionCharOperation<T>>() {                    \
-    return [](mlir::MLIRContext *context) -> mlir::Type {                      \
+    return [](fir::FirOpBuilder &builder) -> mlir::Type {                      \
       TypeBuilderFunc f{getModel<T>()};                                        \
       auto voidTy = fir::LLVMPointerType::get(                                 \
-          context, mlir::IntegerType::get(context, 8));                        \
-      auto size_tTy =                                                          \
-          mlir::IntegerType::get(context, 8 * sizeof(std::size_t));            \
-      auto refTy = fir::ReferenceType::get(f(context));                        \
+          builder.getContext(),                                                \
+          mlir::IntegerType::get(builder.getContext(), 8));                    \
+      auto size_tTy = builder.getIntPtrType();                                 \
+      auto refTy = fir::ReferenceType::get(f(builder));                        \
       return mlir::FunctionType::get(                                          \
-          context, {refTy, size_tTy, refTy, refTy, size_tTy, size_tTy},        \
-          voidTy);                                                             \
+          builder.getContext(),                                                \
+          {refTy, size_tTy, refTy, refTy, size_tTy, size_tTy}, voidTy);        \
     };                                                                         \
   }
 
@@ -98,8 +99,8 @@ using FuncTypeBuilderFunc = mlir::FunctionType (*)(mlir::MLIRContext *);
 // Type builder models
 //===----------------------------------------------------------------------===//
 
-// TODO: all usages of sizeof in this file assume build ==  host == target.
-// This will need to be re-visited for cross compilation.
+// TODO: not all usages of sizeof have been necessarily correctly audited
+// for cross compilation.
 
 /// Return a function that returns the type signature model for the type `T`
 /// when provided an MLIRContext*. This allows one to translate C(++) function
@@ -113,21 +114,21 @@ static constexpr TypeBuilderFunc getModel();
 
 template <>
 constexpr TypeBuilderFunc getModel<unsigned int>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return mlir::IntegerType::get(context, 8 * sizeof(unsigned int));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return builder.getCIntType();
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<short int>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return mlir::IntegerType::get(context, 8 * sizeof(short int));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return builder.getCShortType();
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<short int *>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
     TypeBuilderFunc f{getModel<short int>()};
-    return fir::ReferenceType::get(f(context));
+    return fir::ReferenceType::get(f(builder));
   };
 }
 template <>
@@ -136,15 +137,15 @@ constexpr TypeBuilderFunc getModel<const short int *>() {
 }
 template <>
 constexpr TypeBuilderFunc getModel<int>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return mlir::IntegerType::get(context, 8 * sizeof(int));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return builder.getCIntType();
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<int &>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
     TypeBuilderFunc f{getModel<int>()};
-    return fir::ReferenceType::get(f(context));
+    return fir::ReferenceType::get(f(builder));
   };
 }
 template <>
@@ -153,15 +154,16 @@ constexpr TypeBuilderFunc getModel<int *>() {
 }
 template <>
 constexpr TypeBuilderFunc getModel<const int *>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
     TypeBuilderFunc f{getModel<int>()};
-    return fir::ReferenceType::get(f(context));
+    return fir::ReferenceType::get(f(builder));
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<char *>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return fir::ReferenceType::get(mlir::IntegerType::get(context, 8));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return fir::ReferenceType::get(
+        mlir::IntegerType::get(builder.getContext(), 8));
   };
 }
 template <>
@@ -170,33 +172,35 @@ constexpr TypeBuilderFunc getModel<const char *>() {
 }
 template <>
 constexpr TypeBuilderFunc getModel<const char16_t *>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return fir::ReferenceType::get(mlir::IntegerType::get(context, 16));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return fir::ReferenceType::get(
+        mlir::IntegerType::get(builder.getContext(), 16));
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<const char32_t *>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return fir::ReferenceType::get(mlir::IntegerType::get(context, 32));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return fir::ReferenceType::get(
+        mlir::IntegerType::get(builder.getContext(), 32));
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<char>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return mlir::IntegerType::get(context, 8 * sizeof(char));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return builder.getCCharType();
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<signed char>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return mlir::IntegerType::get(context, 8 * sizeof(signed char));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return builder.getCCharType();
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<signed char *>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
     TypeBuilderFunc f{getModel<signed char>()};
-    return fir::ReferenceType::get(f(context));
+    return fir::ReferenceType::get(f(builder));
   };
 }
 template <>
@@ -205,69 +209,70 @@ constexpr TypeBuilderFunc getModel<const signed char *>() {
 }
 template <>
 constexpr TypeBuilderFunc getModel<char16_t>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return mlir::IntegerType::get(context, 8 * sizeof(char16_t));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return mlir::IntegerType::get(builder.getContext(), 16);
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<char16_t *>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
     TypeBuilderFunc f{getModel<char16_t>()};
-    return fir::ReferenceType::get(f(context));
+    return fir::ReferenceType::get(f(builder));
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<char32_t>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return mlir::IntegerType::get(context, 8 * sizeof(char32_t));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return mlir::IntegerType::get(builder.getContext(), 32);
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<char32_t *>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
     TypeBuilderFunc f{getModel<char32_t>()};
-    return fir::ReferenceType::get(f(context));
+    return fir::ReferenceType::get(f(builder));
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<unsigned char>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return mlir::IntegerType::get(context, 8 * sizeof(unsigned char));
+  return [](fir::FirOpBuilder &builder) -> mlir::Type {
+    return builder.getCCharType();
   };
 }
 template <>
 constexpr TypeBuilderFunc getModel<void *>() {
-  return [](mlir::MLIRContext *context) -> mlir::Type {
-    return fir::LLVMPointerType::get(context,
-                                     mlir::IntegerType::get(context, 8));
+  return [](fir...
[truncated]

@github-actions
Copy link

github-actions bot commented Mar 8, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff cf1964af5a461196904b663ede04c26555fcff69 3a89328312912996fa9009249f5ea89f64e3f20d --extensions cpp,h -- flang-rt/lib/runtime/execute.cpp flang-rt/lib/runtime/extensions.cpp flang-rt/lib/runtime/file.cpp flang/include/flang/Optimizer/Builder/FIRBuilder.h flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h flang/lib/Lower/Allocatable.cpp flang/lib/Lower/IO.cpp flang/lib/Optimizer/Builder/FIRBuilder.cpp flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp flang/lib/Optimizer/Builder/Runtime/Numeric.cpp flang/lib/Optimizer/Builder/Runtime/Reduction.cpp flang/lib/Optimizer/Builder/Runtime/Support.cpp flang/lib/Optimizer/Builder/Runtime/Transformational.cpp flang/lib/Optimizer/CodeGen/Target.cpp
View the diff from clang-format here.
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index fe496d3481..61f71459ef 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -92,8 +92,7 @@ public:
     setListener(this);
   }
   explicit FirOpBuilder(mlir::OpBuilder &builder, mlir::ModuleOp mod)
-      : OpBuilder(builder), OpBuilder::Listener(),
-        kindMap{getKindMapping(mod)},
+      : OpBuilder(builder), OpBuilder::Listener(), kindMap{getKindMapping(mod)},
         cTargetInfo{fir::getTargetTriple(getModule())} {
     setListener(this);
   }
@@ -116,8 +115,7 @@ public:
       : OpBuilder(other), OpBuilder::Listener(), kindMap{other.kindMap},
         fastMathFlags{other.fastMathFlags},
         integerOverflowFlags{other.integerOverflowFlags},
-        symbolTable{other.symbolTable},
-        cTargetInfo{other.cTargetInfo} {
+        symbolTable{other.symbolTable}, cTargetInfo{other.cTargetInfo} {
     setListener(this);
   }
 
@@ -125,8 +123,7 @@ public:
       : OpBuilder(other), OpBuilder::Listener(),
         kindMap{std::move(other.kindMap)}, fastMathFlags{other.fastMathFlags},
         integerOverflowFlags{other.integerOverflowFlags},
-        symbolTable{other.symbolTable},
-        cTargetInfo{other.cTargetInfo} {
+        symbolTable{other.symbolTable}, cTargetInfo{other.cTargetInfo} {
     setListener(this);
   }
 
@@ -191,27 +188,19 @@ public:
 
   /// Get the integer type whose bit width corresponds to the width of
   /// the `char` type in C
-  mlir::Type getCCharType() {
-    return getIntegerType(cTargetInfo.CharWidth);
-  }
+  mlir::Type getCCharType() { return getIntegerType(cTargetInfo.CharWidth); }
 
   /// Get the integer type whose bit width corresponds to the width of
   /// the `short` type in C
-  mlir::Type getCShortType() {
-    return getIntegerType(cTargetInfo.ShortWidth);
-  }
+  mlir::Type getCShortType() { return getIntegerType(cTargetInfo.ShortWidth); }
 
   /// Get the integer type whose bit width corresponds to the width of
   /// the `int` type in C
-  mlir::Type getCIntType() {
-    return getIntegerType(cTargetInfo.IntWidth);
-  }
+  mlir::Type getCIntType() { return getIntegerType(cTargetInfo.IntWidth); }
 
   /// Get the integer type whose bit width corresponds to the width of
   /// the `long` type in C
-  mlir::Type getCLongType() {
-    return getIntegerType(cTargetInfo.LongWidth);
-  }
+  mlir::Type getCLongType() { return getIntegerType(cTargetInfo.LongWidth); }
 
   /// Get the integer type whose bit width corresponds to the width of
   /// the `long long` type in C
@@ -221,9 +210,7 @@ public:
 
   /// Get the integer type whose bit width corresponds to the width of
   /// enums in C
-  mlir::Type getCEnumType() {
-    return getIntegerType(cTargetInfo.EnumWidth);
-  }
+  mlir::Type getCEnumType() { return getIntegerType(cTargetInfo.EnumWidth); }
 
   /// Wrap `str` to a SymbolRefAttr.
   mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str) {
diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 280c911b14..b4b8f5ed09 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -266,8 +266,7 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter,
 
   mlir::StringAttr linkOnce = builder.createLinkOnceLinkage();
   mlir::Type idxTy = builder.getIndexType();
-  mlir::Type sizeTy =
-      fir::runtime::getModel<std::size_t>()(builder);
+  mlir::Type sizeTy = fir::runtime::getModel<std::size_t>()(builder);
   mlir::Type intTy = fir::runtime::getModel<int>()(builder);
   mlir::Type boolTy = fir::runtime::getModel<bool>()(builder);
   mlir::Type listTy = fir::SequenceType::get(
@@ -426,8 +425,7 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter,
   mlir::MLIRContext *context = builder.getContext();
   mlir::StringAttr linkOnce = builder.createLinkOnceLinkage();
   mlir::Type idxTy = builder.getIndexType();
-  mlir::Type sizeTy =
-      fir::runtime::getModel<std::size_t>()(builder);
+  mlir::Type sizeTy = fir::runtime::getModel<std::size_t>()(builder);
   mlir::Type charRefTy = fir::ReferenceType::get(builder.getIntegerType(8));
   mlir::Type descRefTy =
       fir::ReferenceType::get(fir::BoxType::get(mlir::NoneType::get(context)));
diff --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp
index 932c5fbcb9..7da3ee737c 100644
--- a/flang/lib/Optimizer/CodeGen/Target.cpp
+++ b/flang/lib/Optimizer/CodeGen/Target.cpp
@@ -1845,10 +1845,10 @@ struct TargetWasm32 : public GenericTarget<TargetWasm32> {
     CodeGenSpecifics::Marshalling marshal;
     // Use a type that will be translated into LLVM as:
     // { t, t }   struct of 2 eleTy, sret, align 4
-    auto structTy = mlir::TupleType::get(eleTy.getContext(),
-                                          mlir::TypeRange{eleTy, eleTy});
+    auto structTy =
+        mlir::TupleType::get(eleTy.getContext(), mlir::TypeRange{eleTy, eleTy});
     marshal.emplace_back(fir::ReferenceType::get(structTy),
-                          AT{/*alignment=*/4, /*byval=*/false, /*sret=*/true});
+                         AT{/*alignment=*/4, /*byval=*/false, /*sret=*/true});
     return marshal;
   }
 };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:codegen flang:fir-hlfir flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants