https://github.com/dev-priyanshu15 created https://github.com/llvm/llvm-project/pull/172092
[clang][libclang] Fix auto function parameter type reporting When auto is used as a function parameter type, clang-c API was incorrectly reporting it as TypeRef with kind unexposed instead of reporting it as CXType_Auto. The issue was that CursorVisitor did not have a handler for AutoTypeLoc, so it fell back to default behavior which resulted in unexposed types. Add VisitAutoTypeLoc method to properly handle auto type locations in function parameters. This brings consistency with how auto is handled in variable declarations. Fixes issue #172072 >From 5bc0f4afb423c085addebd009aaff9c8733b3931 Mon Sep 17 00:00:00 2001 From: spriyanshucoder <[email protected]> Date: Sat, 13 Dec 2025 02:50:35 +0530 Subject: [PATCH 1/2] [flang][OpenMP] Fix regression in OpenMP master region with private target integer When handling TARGET variables in dummy arguments, the code was calling getFuncArgName() unconditionally. This could cause an assertion failure when getUniqName() returns an unengaged optional for TARGET variables. Move getFuncArgName() call to only execute when the variable is not a TARGET or POINTER, avoiding the assertion error. Fixes issue #172075 --- .../lib/Optimizer/Transforms/AddAliasTags.cpp | 20 ++++++++------ .../alias-tags-master-private-target.f90 | 26 +++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 flang/test/Transforms/alias-tags-master-private-target.f90 diff --git a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp index 3718848c05775..a0b10d1858a92 100644 --- a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp +++ b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp @@ -702,20 +702,24 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op, source.kind == fir::AliasAnalysis::SourceKind::Argument) { LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to dummy argument at " << *op << "\n"); - std::string name = getFuncArgName(llvm::cast<mlir::Value>(source.origin.u)); // POINTERS can alias with any POINTER or TARGET. Assume that TARGET dummy // arguments might alias with each other (because of the "TARGET" hole for // dummy arguments). See flang/docs/Aliasing.md. + // If it is a TARGET or POINTER, then we do not care about the name, + // because the tag points to the root of the subtree currently. if (source.isTargetOrPointer()) { tag = state.getFuncTreeWithScope(func, scopeOp).targetDataTree.getTag(); - } else if (!name.empty()) { - tag = state.getFuncTreeWithScope(func, scopeOp) - .dummyArgDataTree.getTag(name); } else { - LLVM_DEBUG(llvm::dbgs().indent(2) - << "WARN: couldn't find a name for dummy argument " << *op - << "\n"); - tag = state.getFuncTreeWithScope(func, scopeOp).dummyArgDataTree.getTag(); + std::string name = getFuncArgName(llvm::cast<mlir::Value>(source.origin.u)); + if (!name.empty()) { + tag = state.getFuncTreeWithScope(func, scopeOp) + .dummyArgDataTree.getTag(name); + } else { + LLVM_DEBUG(llvm::dbgs().indent(2) + << "WARN: couldn't find a name for dummy argument " << *op + << "\n"); + tag = state.getFuncTreeWithScope(func, scopeOp).dummyArgDataTree.getTag(); + } } // TBAA for global variables without descriptors diff --git a/flang/test/Transforms/alias-tags-master-private-target.f90 b/flang/test/Transforms/alias-tags-master-private-target.f90 new file mode 100644 index 0000000000000..0251376476c64 --- /dev/null +++ b/flang/test/Transforms/alias-tags-master-private-target.f90 @@ -0,0 +1,26 @@ +! Test case for regression in OpenMP master region with private target integer +! This test was failing with an assertion error in AddAliasTags.cpp +! See issue #172075 + +! RUN: %flang -fopenmp -c -O1 %s -o %t.o 2>&1 | FileCheck %s --allow-empty + +module test +contains +subroutine omp_master_repro() + implicit none + integer, parameter :: nim = 4 + integer, parameter :: nvals = 8 + integer, target :: ui + integer :: hold1(nvals, nim) + hold1 = 0 + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP PRIVATE(ui) & + !$OMP SHARED(hold1, nim) + !$OMP MASTER + do ui = 1, nim + hold1(:, ui) = 1 + end do + !$OMP END MASTER + !$OMP END PARALLEL +end subroutine omp_master_repro +end module test >From 4a09c499bc2a366f6073097e5342acc8700e7b15 Mon Sep 17 00:00:00 2001 From: spriyanshucoder <[email protected]> Date: Sat, 13 Dec 2025 03:31:19 +0530 Subject: [PATCH 2/2] [clang][libclang] Fix auto function parameter type reporting When auto is used as a function parameter type, clang-c API was incorrectly reporting it as TypeRef with kind unexposed instead of reporting it as CXType_Auto. The issue was that CursorVisitor did not have a handler for AutoTypeLoc, so it fell back to default behavior which resulted in unexposed types. Add VisitAutoTypeLoc method to properly handle auto type locations in function parameters. This brings consistency with how auto is handled in variable declarations. Fixes issue #172072 --- clang/test/Index/auto-function-param.cpp | 14 ++++++++++++++ clang/tools/libclang/CIndex.cpp | 9 +++++++++ 2 files changed, 23 insertions(+) create mode 100644 clang/test/Index/auto-function-param.cpp diff --git a/clang/test/Index/auto-function-param.cpp b/clang/test/Index/auto-function-param.cpp new file mode 100644 index 0000000000000..5366d8468007e --- /dev/null +++ b/clang/test/Index/auto-function-param.cpp @@ -0,0 +1,14 @@ +// Test case for auto function parameter reported as CXType_Auto +// This test verifies that auto parameters in function declarations +// are properly reported as CXType_Auto in the libclang C API +// See issue #172072 + +// RUN: c-index-test -test-type %s | FileCheck %s + +// Function with auto parameter +int bar(auto p) { + return p; +} + +// CHECK: FunctionDecl=bar:{{.*}} CXType_FunctionProto +// CHECK: ParmDecl=p:{{.*}} CXType_Auto diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 32e84248c1b27..bb0816b0447a9 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -1789,6 +1789,15 @@ bool CursorVisitor::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { return Visit(TL.getOriginalLoc()); } +bool CursorVisitor::VisitAutoTypeLoc(AutoTypeLoc TL) { + // AutoTypeLoc represents the location of an auto type specifier. + // We do not visit children because the auto type itself is complete. + // This handler ensures that auto function parameters are properly + // reported as CXType_Auto in the libclang C API, rather than being + // incorrectly reported as TypeRef/unexposed. + return false; +} + bool CursorVisitor::VisitDeducedTemplateSpecializationTypeLoc( DeducedTemplateSpecializationTypeLoc TL) { if (VisitTemplateName(TL.getTypePtr()->getTemplateName(), _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
