[Lldb-commits] [lldb] [lldb][Fortran] Add support for functions in TypeSystemFortran (PR #234285)

Iasonas Karaprodromidis via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 3 09:47:55 PST 2026


https://github.com/Iasonaskrpr updated https://github.com/llvm/llvm-project/pull/234285

>From 03189aa28d85de28e8f577fdc231c35edcb05c43 Mon Sep 17 00:00:00 2001
From: Iasonaskrpr <iaskarapro at gmail.com>
Date: Tue, 20 Oct 2026 17:51:59 +0300
Subject: [PATCH 1/3] [lldb][Fortran] Added support for functions in
 TypeSystemFortran and added tests for them

---
 .../TypeSystem/Fortran/FortranTypes.cpp       | 35 +++++++
 .../Plugins/TypeSystem/Fortran/FortranTypes.h | 37 +++++++
 .../TypeSystem/Fortran/TypeSystemFortran.cpp  | 98 +++++++++++++++++++
 .../TypeSystem/Fortran/TypeSystemFortran.h    | 33 +++----
 .../Symbol/TestTypeSystemFortran.cpp          | 53 ++++++++++
 5 files changed, 238 insertions(+), 18 deletions(-)

diff --git a/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.cpp b/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.cpp
index e84684aab28f80..eb1de33ef34736 100644
--- a/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.cpp
+++ b/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.cpp
@@ -14,3 +14,38 @@ using namespace lldb_private::plugin::fortran;
 char FortranType::ID;
 
 FortranType::~FortranType() = default;
+
+static ConstString CreateFortranFunctionSignature(
+    ConstString func_name,
+    const llvm::SmallVectorImpl<CompilerType> &parameters,
+    const llvm::SmallVectorImpl<llvm::StringRef> &parameter_names,
+    CompilerType return_type) {
+  std::string name_buffer;
+  llvm::raw_string_ostream name_stream(name_buffer);
+
+  if (return_type.IsValid())
+    name_stream << return_type.GetTypeName().AsCString("") << " ";
+
+  name_stream << func_name.AsCString("<unnamed function>") << "(";
+
+  for (size_t idx = 0; idx < parameters.size(); idx++) {
+    if (idx != 0)
+      name_stream << ", ";
+    name_stream << parameters[idx].GetTypeName().AsCString("") << " ";
+    name_stream << parameter_names[idx].str();
+  }
+  name_stream << ")";
+  name_stream.flush();
+  return ConstString(name_buffer);
+}
+
+FortranFunction::FortranFunction(
+    ConstString func_name,
+    const llvm::SmallVectorImpl<CompilerType> &parameters,
+    const llvm::SmallVectorImpl<llvm::StringRef> &parameter_names,
+    CompilerType return_type)
+    : FortranType(FortranType::KIND_FUNCTION, 0, func_name),
+      m_parameters(parameters.begin(), parameters.end()),
+      m_return_type(return_type),
+      m_function_signature(CreateFortranFunctionSignature(
+          func_name, parameters, parameter_names, return_type)) {}
diff --git a/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h b/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h
index 20f775899f1fa6..722f68d1f355a2 100644
--- a/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h
+++ b/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h
@@ -44,12 +44,14 @@ class FortranType : public llvm::FoldingSetNode {
     KIND_LOGICAL,
     KIND_REAL,
     KIND_COMPLEX,
+    KIND_FUNCTION,
     KIND_UNKNOWN
   };
 
   FortranType(int32_t kind, uint64_t bitsize, const ConstString &name)
       : m_kind(kind), m_bitsize(bitsize), m_type_name(name) {}
   virtual ~FortranType();
+
   int GetKind() const { return m_kind; }
   uint64_t GetBitSize() const { return m_bitsize; }
   ConstString GetName() const { return m_type_name; }
@@ -70,6 +72,41 @@ class FortranType : public llvm::FoldingSetNode {
   ConstString m_type_name;
 };
 
+class FortranFunction : public FortranType {
+public:
+  FortranFunction(ConstString func_name,
+                  const llvm::SmallVectorImpl<CompilerType> &parameters,
+                  const llvm::SmallVectorImpl<llvm::StringRef> &parameter_names,
+                  CompilerType return_type);
+
+  llvm::ArrayRef<CompilerType> GetParameters() const { return m_parameters; }
+  size_t GetNumberOfParameters() const { return m_parameters.size(); }
+  CompilerType GetReturnType() const { return m_return_type; }
+  ConstString GetFunctionSignature() const { return m_function_signature; };
+
+  void Profile(llvm::FoldingSetNodeID &id) const {
+    Profile(id, GetName(), m_parameters, m_return_type);
+  }
+
+  static void Profile(llvm::FoldingSetNodeID &id, ConstString func_name,
+                      llvm::ArrayRef<CompilerType> parameters,
+                      CompilerType return_type) {
+    id.AddString(func_name.GetStringRef());
+    id.AddInteger(parameters.size());
+
+    if (return_type.IsValid())
+      id.AddPointer(return_type.GetOpaqueQualType());
+
+    for (const auto &param : parameters)
+      id.AddPointer(param.GetOpaqueQualType());
+  }
+
+private:
+  llvm::SmallVector<CompilerType, 4> m_parameters;
+  CompilerType m_return_type;
+  ConstString m_function_signature;
+};
+
 } // namespace fortran
 } // namespace plugin
 } // namespace lldb_private
diff --git a/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.cpp b/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.cpp
index 0454d4cc192c7e..1c33618b43778c 100644
--- a/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.cpp
+++ b/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.cpp
@@ -86,6 +86,46 @@ bool TypeSystemFortran::IsFloatingPointType(opaque_compiler_type_t type) {
   return false;
 }
 
+bool TypeSystemFortran::IsFunctionType(opaque_compiler_type_t type) {
+  if (!type)
+    return false;
+
+  if (static_cast<FortranType *>(type)->GetKind() == FortranType::KIND_FUNCTION)
+    return true;
+
+  return false;
+}
+
+size_t TypeSystemFortran::GetNumberOfFunctionArguments(
+    lldb::opaque_compiler_type_t type) {
+  if (!type)
+    return 0;
+
+  FortranType *fortran_type = static_cast<FortranType *>(type);
+  if (fortran_type->GetKind() != FortranType::KIND_FUNCTION)
+    return 0;
+
+  return static_cast<FortranFunction *>(fortran_type)->GetNumberOfParameters();
+}
+
+CompilerType
+TypeSystemFortran::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
+                                              const size_t index) {
+  if (!type)
+    return CompilerType();
+
+  FortranType *fortran_type = static_cast<FortranType *>(type);
+  if (fortran_type->GetKind() != FortranType::KIND_FUNCTION)
+    return CompilerType();
+
+  auto parameters =
+      static_cast<FortranFunction *>(fortran_type)->GetParameters();
+  if (index >= parameters.size())
+    return CompilerType();
+
+  return parameters[index];
+}
+
 bool TypeSystemFortran::IsIntegerType(opaque_compiler_type_t type,
                                       bool &is_signed) {
   if (!type)
@@ -118,6 +158,8 @@ ConstString TypeSystemFortran::GetTypeName(opaque_compiler_type_t type,
   case FortranType::KIND_COMPLEX:
   case FortranType::KIND_UNSIGNED:
     return fortran_type->GetName();
+  case FortranType::KIND_FUNCTION:
+    return static_cast<FortranFunction *>(fortran_type)->GetFunctionSignature();
   case FortranType::KIND_UNKNOWN:
     return ConstString("Unsupported");
   }
@@ -183,6 +225,29 @@ CompilerType TypeSystemFortran::GetOrCreateFortranBaseType(int kind,
   return CompilerType(weak_from_this(), (void *)candidate_type);
 }
 
+CompilerType TypeSystemFortran::CreateFortranFunction(
+    ConstString name, const SmallVectorImpl<CompilerType> &parameters,
+    const SmallVectorImpl<StringRef> &parameter_names,
+    CompilerType return_type) {
+  llvm::FoldingSetNodeID id;
+  FortranFunction::Profile(id, name, parameters, return_type);
+  FoldingSetInsertToken token;
+
+  FortranFunction *fortran_function = m_functions.lookup(id, token);
+
+  if (fortran_function)
+    return CompilerType(weak_from_this(), (void *)fortran_function);
+
+  auto new_type_up = std::make_unique<FortranFunction>(
+      name, parameters, parameter_names, return_type);
+  fortran_function = new_type_up.get();
+
+  m_functions.insert(fortran_function, token);
+  m_types.push_back(std::move(new_type_up));
+
+  return CompilerType(weak_from_this(), (void *)fortran_function);
+}
+
 lldb::TypeClass
 TypeSystemFortran::GetTypeClass(lldb::opaque_compiler_type_t type) {
   return type ? lldb::eTypeClassBuiltin : lldb::eTypeClassInvalid;
@@ -195,6 +260,39 @@ TypeSystemFortran::GetCanonicalType(lldb::opaque_compiler_type_t type) {
   return CompilerType(weak_from_this(), type);
 }
 
+int TypeSystemFortran::GetFunctionArgumentCount(
+    lldb::opaque_compiler_type_t type) {
+  if (!type)
+    return -1;
+
+  FortranType *fortran_type = static_cast<FortranType *>(type);
+  int kind = fortran_type->GetKind();
+  if (kind != FortranType::KIND_FUNCTION)
+    return -1;
+
+  FortranFunction *fortran_function =
+      static_cast<FortranFunction *>(fortran_type);
+  return fortran_function->GetNumberOfParameters();
+}
+
+CompilerType
+TypeSystemFortran::GetFunctionReturnType(lldb::opaque_compiler_type_t type) {
+  if (!type)
+    return CompilerType();
+
+  FortranType *fortran_type = static_cast<FortranType *>(type);
+  if (fortran_type->GetKind() != FortranType::KIND_FUNCTION)
+    return CompilerType();
+
+  CompilerType return_type =
+      static_cast<FortranFunction *>(fortran_type)->GetReturnType();
+
+  if (!return_type.IsValid())
+    return CompilerType();
+
+  return return_type;
+}
+
 Expected<uint64_t>
 TypeSystemFortran::GetBitSize(opaque_compiler_type_t type,
                               ExecutionContextScope *exe_scope) {
diff --git a/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.h b/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.h
index 5be3d3c1703314..c1e83565be293e 100644
--- a/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.h
+++ b/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.h
@@ -14,6 +14,7 @@
 #include "lldb/Symbol/TypeSystem.h"
 
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace lldb_private {
@@ -101,19 +102,13 @@ class TypeSystemFortran : public TypeSystem {
 
   bool IsFloatingPointType(lldb::opaque_compiler_type_t type) override;
 
-  bool IsFunctionType(lldb::opaque_compiler_type_t type) override {
-    return false;
-  }
+  bool IsFunctionType(lldb::opaque_compiler_type_t type) override;
 
   size_t
-  GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override {
-    return 0;
-  }
+  GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override;
 
   CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
-                                          const size_t index) override {
-    return CompilerType();
-  }
+                                          const size_t index) override;
 
   bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override {
     return false;
@@ -213,13 +208,18 @@ class TypeSystemFortran : public TypeSystem {
 
   lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override;
 
+  // Creating related types
+
   CompilerType GetOrCreateFortranBaseType(int kind, uint64_t bitsize,
                                           ConstString name);
 
   CompilerType CreateBaseType(llvm::dwarf::TypeKind dwarf_encoding,
                               uint64_t bitsize, ConstString name);
 
-  // Creating related types
+  CompilerType CreateFortranFunction(
+      ConstString name, const llvm::SmallVectorImpl<CompilerType> &parameters,
+      const llvm::SmallVectorImpl<llvm::StringRef> &parameter_names,
+      CompilerType return_type);
 
   CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type,
                                    ExecutionContextScope *exe_scope) override {
@@ -233,21 +233,17 @@ class TypeSystemFortran : public TypeSystem {
     return CompilerType();
   }
 
-  // Returns -1 if this isn't a function of if the function doesn't have a
+  // Returns -1 if this isn't a function or if the function doesn't have a
   // prototype Returns a value >= 0 if there is a prototype.
-  int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override {
-    return -1;
-  }
+  int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override;
 
   CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type,
                                               size_t idx) override {
-    return CompilerType();
+    return GetFunctionArgumentAtIndex(type, idx);
   }
 
   CompilerType
-  GetFunctionReturnType(lldb::opaque_compiler_type_t type) override {
-    return CompilerType();
-  }
+  GetFunctionReturnType(lldb::opaque_compiler_type_t type) override;
 
   size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override {
     return 0;
@@ -472,6 +468,7 @@ class TypeSystemFortran : public TypeSystem {
 
 private:
   mutable llvm::FoldingSet<plugin::fortran::FortranType> m_basic_types;
+  mutable llvm::FoldingSet<plugin::fortran::FortranFunction> m_functions;
   // We store all unique pointer types here so we can manage the lifecycle
   // of the types
   mutable llvm::SmallVector<std::unique_ptr<plugin::fortran::FortranType>>
diff --git a/lldb/unittests/Symbol/TestTypeSystemFortran.cpp b/lldb/unittests/Symbol/TestTypeSystemFortran.cpp
index bf29c6938ed856..c3dbda41f9c570 100644
--- a/lldb/unittests/Symbol/TestTypeSystemFortran.cpp
+++ b/lldb/unittests/Symbol/TestTypeSystemFortran.cpp
@@ -289,3 +289,56 @@ TEST_F(TestTypeSystemFortran, TestGetBasicTypeFromAST) {
   EXPECT_TRUE(complex_type.IsValid());
   EXPECT_STREQ(complex_type.GetTypeName().GetCString(), "COMPLEX(KIND=8)");
 }
+
+TEST_F(TestTypeSystemFortran, TestFortranFunctions) {
+  llvm::SmallVector<CompilerType, 2> parameters;
+  llvm::SmallVector<llvm::StringRef, 2> parameter_names;
+  CompilerType logical_type = m_ast->CreateBaseType(llvm::dwarf::DW_ATE_boolean,
+                                                    32, ConstString("LOGICAL"));
+  CompilerType int32_type = m_ast->CreateBaseType(llvm::dwarf::DW_ATE_signed,
+                                                  32, ConstString("INTEGER"));
+  parameters.push_back(logical_type);
+  parameters.push_back(int32_type);
+  parameter_names.push_back("arg_1");
+  parameter_names.push_back("arg_2");
+
+  CompilerType function_type = m_ast->CreateFortranFunction(
+      ConstString("test_func"), parameters, parameter_names, int32_type);
+
+  CompilerType first_arg = function_type.GetFunctionArgumentAtIndex(0);
+  CompilerType second_arg = function_type.GetFunctionArgumentAtIndex(1);
+  CompilerType invalid_arg = function_type.GetFunctionArgumentAtIndex(2);
+  CompilerType return_type = function_type.GetFunctionReturnType();
+
+  EXPECT_TRUE(function_type.IsFunctionType());
+  EXPECT_STREQ(function_type.GetTypeName().GetCString(),
+               "INTEGER test_func(LOGICAL arg_1, INTEGER arg_2)");
+  EXPECT_EQ(function_type.GetNumberOfFunctionArguments(), 2U);
+  EXPECT_EQ(function_type.GetFunctionArgumentCount(), 2);
+
+  EXPECT_EQ(first_arg.GetBasicTypeEnumeration(), eBasicTypeBool);
+  EXPECT_TRUE(second_arg.IsInteger());
+  EXPECT_FALSE(invalid_arg.IsValid());
+  EXPECT_TRUE(return_type.IsInteger());
+
+  // For non-function types this should return -1
+  EXPECT_EQ(return_type.GetFunctionArgumentCount(), -1);
+  EXPECT_FALSE(return_type.IsFunctionType());
+
+  CompilerType invalid_return_type;
+  CompilerType subroutine_type = m_ast->CreateFortranFunction(
+      ConstString("my_sub"), parameters, parameter_names, invalid_return_type);
+
+  EXPECT_STREQ(subroutine_type.GetTypeName().GetCString(),
+               "my_sub(LOGICAL arg_1, INTEGER arg_2)");
+  EXPECT_FALSE(subroutine_type.GetFunctionReturnType().IsValid());
+
+  llvm::SmallVector<CompilerType, 0> no_args;
+  llvm::SmallVector<llvm::StringRef, 0> no_args_names;
+  CompilerType void_func_type = m_ast->CreateFortranFunction(
+      ConstString("do_nothing"), no_args, no_args_names, invalid_return_type);
+
+  EXPECT_STREQ(void_func_type.GetTypeName().GetCString(), "do_nothing()");
+  EXPECT_EQ(void_func_type.GetFunctionArgumentCount(), 0);
+  EXPECT_EQ(void_func_type.GetNumberOfFunctionArguments(), 0U);
+}

>From 5e7bc615d16e25d067820b7e830d22cc5f3cce96 Mon Sep 17 00:00:00 2001
From: Iasonaskrpr <iaskarapro at gmail.com>
Date: Fri, 23 Oct 2026 18:44:09 +0300
Subject: [PATCH 2/3] [lldb][Fortran] Added llvm RTTI support to
 FortranFunction, renamed variable names in functions, GetFunctionType static
 function to get function type pointer and addressed feedback about code style

---
 .../TypeSystem/Fortran/FortranTypes.cpp       | 56 +++++++++------
 .../Plugins/TypeSystem/Fortran/FortranTypes.h | 34 ++++++---
 .../TypeSystem/Fortran/TypeSystemFortran.cpp  | 72 +++++++------------
 .../TypeSystem/Fortran/TypeSystemFortran.h    |  2 +-
 4 files changed, 83 insertions(+), 81 deletions(-)

diff --git a/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.cpp b/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.cpp
index eb1de33ef34736..e8d6f1eb160c25 100644
--- a/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.cpp
+++ b/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.cpp
@@ -12,40 +12,52 @@ using namespace lldb_private;
 using namespace lldb_private::plugin::fortran;
 
 char FortranType::ID;
+char FortranFunction::ID;
 
 FortranType::~FortranType() = default;
 
-static ConstString CreateFortranFunctionSignature(
-    ConstString func_name,
-    const llvm::SmallVectorImpl<CompilerType> &parameters,
-    const llvm::SmallVectorImpl<llvm::StringRef> &parameter_names,
-    CompilerType return_type) {
-  std::string name_buffer;
-  llvm::raw_string_ostream name_stream(name_buffer);
+static ConstString
+CreateFuncSignature(ConstString func_name,
+                    const llvm::SmallVectorImpl<CompilerType> &param_types,
+                    const llvm::SmallVectorImpl<llvm::StringRef> &param_names,
+                    CompilerType return_type) {
+  std::string buf;
+  llvm::raw_string_ostream ss(buf);
 
   if (return_type.IsValid())
-    name_stream << return_type.GetTypeName().AsCString("") << " ";
+    ss << return_type.GetTypeName().AsCString("") << " ";
 
-  name_stream << func_name.AsCString("<unnamed function>") << "(";
+  ss << func_name.AsCString("<unnamed function>") << "(";
 
-  for (size_t idx = 0; idx < parameters.size(); idx++) {
-    if (idx != 0)
-      name_stream << ", ";
-    name_stream << parameters[idx].GetTypeName().AsCString("") << " ";
-    name_stream << parameter_names[idx].str();
+  for (size_t i = 0; i < param_types.size(); i++) {
+    if (i)
+      ss << ", ";
+    ss << param_types[i].GetTypeName().AsCString("") << " ";
+    ss << param_names[i];
   }
-  name_stream << ")";
-  name_stream.flush();
-  return ConstString(name_buffer);
+  ss << ")";
+  ss.flush();
+  return ConstString(buf);
 }
 
 FortranFunction::FortranFunction(
     ConstString func_name,
-    const llvm::SmallVectorImpl<CompilerType> &parameters,
-    const llvm::SmallVectorImpl<llvm::StringRef> &parameter_names,
+    const llvm::SmallVectorImpl<CompilerType> &param_types,
+    const llvm::SmallVectorImpl<llvm::StringRef> &param_names,
     CompilerType return_type)
     : FortranType(FortranType::KIND_FUNCTION, 0, func_name),
-      m_parameters(parameters.begin(), parameters.end()),
+      m_param_types(param_types.begin(), param_types.end()),
       m_return_type(return_type),
-      m_function_signature(CreateFortranFunctionSignature(
-          func_name, parameters, parameter_names, return_type)) {}
+      m_func_signature(CreateFuncSignature(func_name, param_types, param_names,
+                                           return_type)) {}
+
+FortranFunction *FortranFunction::GetFunctionType(void *type) {
+  if (!type)
+    return nullptr;
+
+  FortranType *base_type = static_cast<FortranType *>(type);
+  if (base_type->GetKind() != FortranType::KIND_FUNCTION)
+    return nullptr;
+
+  return llvm::cast<FortranFunction>(base_type);
+}
diff --git a/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h b/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h
index 722f68d1f355a2..783611fd73cb2f 100644
--- a/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h
+++ b/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h
@@ -73,38 +73,50 @@ class FortranType : public llvm::FoldingSetNode {
 };
 
 class FortranFunction : public FortranType {
+  // LLVM RTTI support
+  static char ID;
+
 public:
+  // llvm casting support
+  bool isA(const void *ClassID) const override {
+    return ClassID == &ID || FortranType::isA(ClassID);
+  }
+
+  static bool classof(const FortranType *ft) { return ft->isA(&ID); }
+
   FortranFunction(ConstString func_name,
-                  const llvm::SmallVectorImpl<CompilerType> &parameters,
-                  const llvm::SmallVectorImpl<llvm::StringRef> &parameter_names,
+                  const llvm::SmallVectorImpl<CompilerType> &param_types,
+                  const llvm::SmallVectorImpl<llvm::StringRef> &param_names,
                   CompilerType return_type);
 
-  llvm::ArrayRef<CompilerType> GetParameters() const { return m_parameters; }
-  size_t GetNumberOfParameters() const { return m_parameters.size(); }
+  llvm::ArrayRef<CompilerType> GetParamTypes() const { return m_param_types; }
+  size_t GetNumParams() const { return m_param_types.size(); }
   CompilerType GetReturnType() const { return m_return_type; }
-  ConstString GetFunctionSignature() const { return m_function_signature; };
+  ConstString GetSignature() const { return m_func_signature; };
 
   void Profile(llvm::FoldingSetNodeID &id) const {
-    Profile(id, GetName(), m_parameters, m_return_type);
+    Profile(id, GetName(), m_param_types, m_return_type);
   }
 
   static void Profile(llvm::FoldingSetNodeID &id, ConstString func_name,
-                      llvm::ArrayRef<CompilerType> parameters,
+                      llvm::ArrayRef<CompilerType> param_types,
                       CompilerType return_type) {
     id.AddString(func_name.GetStringRef());
-    id.AddInteger(parameters.size());
+    id.AddInteger(param_types.size());
 
     if (return_type.IsValid())
       id.AddPointer(return_type.GetOpaqueQualType());
 
-    for (const auto &param : parameters)
+    for (const auto &param : param_types)
       id.AddPointer(param.GetOpaqueQualType());
   }
 
+  static FortranFunction *GetFunctionType(void *type);
+
 private:
-  llvm::SmallVector<CompilerType, 4> m_parameters;
+  llvm::SmallVector<CompilerType, 4> m_param_types;
   CompilerType m_return_type;
-  ConstString m_function_signature;
+  ConstString m_func_signature;
 };
 
 } // namespace fortran
diff --git a/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.cpp b/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.cpp
index 1c33618b43778c..365ae2b6d106c5 100644
--- a/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.cpp
+++ b/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.cpp
@@ -90,40 +90,32 @@ bool TypeSystemFortran::IsFunctionType(opaque_compiler_type_t type) {
   if (!type)
     return false;
 
-  if (static_cast<FortranType *>(type)->GetKind() == FortranType::KIND_FUNCTION)
-    return true;
-
-  return false;
+  return static_cast<FortranType *>(type)->GetKind() ==
+         FortranType::KIND_FUNCTION;
 }
 
 size_t TypeSystemFortran::GetNumberOfFunctionArguments(
     lldb::opaque_compiler_type_t type) {
-  if (!type)
+  FortranFunction *function_type = FortranFunction::GetFunctionType(type);
+  if (!function_type)
     return 0;
 
-  FortranType *fortran_type = static_cast<FortranType *>(type);
-  if (fortran_type->GetKind() != FortranType::KIND_FUNCTION)
-    return 0;
-
-  return static_cast<FortranFunction *>(fortran_type)->GetNumberOfParameters();
+  return function_type->GetNumParams();
 }
 
 CompilerType
 TypeSystemFortran::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
                                               const size_t index) {
-  if (!type)
-    return CompilerType();
-
-  FortranType *fortran_type = static_cast<FortranType *>(type);
-  if (fortran_type->GetKind() != FortranType::KIND_FUNCTION)
+  FortranFunction *function_type = FortranFunction::GetFunctionType(type);
+  if (!function_type)
     return CompilerType();
 
-  auto parameters =
-      static_cast<FortranFunction *>(fortran_type)->GetParameters();
-  if (index >= parameters.size())
+  llvm::ArrayRef<lldb_private::CompilerType> param_types =
+      function_type->GetParamTypes();
+  if (index >= param_types.size())
     return CompilerType();
 
-  return parameters[index];
+  return param_types[index];
 }
 
 bool TypeSystemFortran::IsIntegerType(opaque_compiler_type_t type,
@@ -159,7 +151,7 @@ ConstString TypeSystemFortran::GetTypeName(opaque_compiler_type_t type,
   case FortranType::KIND_UNSIGNED:
     return fortran_type->GetName();
   case FortranType::KIND_FUNCTION:
-    return static_cast<FortranFunction *>(fortran_type)->GetFunctionSignature();
+    return static_cast<FortranFunction *>(fortran_type)->GetSignature();
   case FortranType::KIND_UNKNOWN:
     return ConstString("Unsupported");
   }
@@ -233,19 +225,18 @@ CompilerType TypeSystemFortran::CreateFortranFunction(
   FortranFunction::Profile(id, name, parameters, return_type);
   FoldingSetInsertToken token;
 
-  FortranFunction *fortran_function = m_functions.lookup(id, token);
-
-  if (fortran_function)
-    return CompilerType(weak_from_this(), (void *)fortran_function);
+  FortranFunction *function_type = m_functions.lookup(id, token);
+  if (function_type)
+    return CompilerType(weak_from_this(), (void *)function_type);
 
   auto new_type_up = std::make_unique<FortranFunction>(
       name, parameters, parameter_names, return_type);
-  fortran_function = new_type_up.get();
+  function_type = new_type_up.get();
 
-  m_functions.insert(fortran_function, token);
+  m_functions.insert(function_type, token);
   m_types.push_back(std::move(new_type_up));
 
-  return CompilerType(weak_from_this(), (void *)fortran_function);
+  return CompilerType(weak_from_this(), (void *)function_type);
 }
 
 lldb::TypeClass
@@ -262,35 +253,22 @@ TypeSystemFortran::GetCanonicalType(lldb::opaque_compiler_type_t type) {
 
 int TypeSystemFortran::GetFunctionArgumentCount(
     lldb::opaque_compiler_type_t type) {
-  if (!type)
-    return -1;
-
-  FortranType *fortran_type = static_cast<FortranType *>(type);
-  int kind = fortran_type->GetKind();
-  if (kind != FortranType::KIND_FUNCTION)
+  FortranFunction *function_type = FortranFunction::GetFunctionType(type);
+  if (!function_type)
     return -1;
 
-  FortranFunction *fortran_function =
-      static_cast<FortranFunction *>(fortran_type);
-  return fortran_function->GetNumberOfParameters();
+  return function_type->GetNumParams();
 }
 
 CompilerType
 TypeSystemFortran::GetFunctionReturnType(lldb::opaque_compiler_type_t type) {
-  if (!type)
+  FortranFunction *function_type = FortranFunction::GetFunctionType(type);
+  if (!function_type)
     return CompilerType();
 
-  FortranType *fortran_type = static_cast<FortranType *>(type);
-  if (fortran_type->GetKind() != FortranType::KIND_FUNCTION)
-    return CompilerType();
-
-  CompilerType return_type =
-      static_cast<FortranFunction *>(fortran_type)->GetReturnType();
-
-  if (!return_type.IsValid())
-    return CompilerType();
+  CompilerType return_type = function_type->GetReturnType();
 
-  return return_type;
+  return return_type.IsValid() ? return_type : CompilerType();
 }
 
 Expected<uint64_t>
diff --git a/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.h b/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.h
index c1e83565be293e..f0377672dd12ce 100644
--- a/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.h
+++ b/lldb/source/Plugins/TypeSystem/Fortran/TypeSystemFortran.h
@@ -234,7 +234,7 @@ class TypeSystemFortran : public TypeSystem {
   }
 
   // Returns -1 if this isn't a function or if the function doesn't have a
-  // prototype Returns a value >= 0 if there is a prototype.
+  // prototype. Returns a value >= 0 if there is a prototype.
   int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override;
 
   CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type,

>From bea7230d3a0fac4113579b24d61d8144dc2b0910 Mon Sep 17 00:00:00 2001
From: Iasonaskrpr <iaskarapro at gmail.com>
Date: Tue, 3 Nov 2026 19:44:16 +0200
Subject: [PATCH 3/3] Used more concrete type profile, when looping through
 parameter types

---
 lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h b/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h
index 783611fd73cb2f..5a95ebeddef1b6 100644
--- a/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h
+++ b/lldb/source/Plugins/TypeSystem/Fortran/FortranTypes.h
@@ -107,7 +107,7 @@ class FortranFunction : public FortranType {
     if (return_type.IsValid())
       id.AddPointer(return_type.GetOpaqueQualType());
 
-    for (const auto &param : param_types)
+    for (const CompilerType &param : param_types)
       id.AddPointer(param.GetOpaqueQualType());
   }
 



More information about the lldb-commits mailing list