https://github.com/dev-priyanshu15 updated https://github.com/llvm/llvm-project/pull/172092
>From e4b8541ab405bf31e5f49bfd0a1c43134f5df39c Mon Sep 17 00:00:00 2001 From: spriyanshucoder <[email protected]> Date: Sat, 13 Dec 2025 03:31:19 +0530 Subject: [PATCH] [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 +++++++++ clang/tools/libclang/CXType.cpp | 10 ++++++++++ 3 files changed, 33 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(), diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp index 3feb56334d79c..f317976905e48 100644 --- a/clang/tools/libclang/CXType.cpp +++ b/clang/tools/libclang/CXType.cpp @@ -150,6 +150,16 @@ CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) { return MakeCXType(PTT->getInnerType(), TU); } + // Handle auto in function parameters + if (auto *TTP = T->getAs<TemplateTypeParmType>()) { + auto *D = TTP->getDecl(); + if (D && D->isImplicit()) { + if (auto *TC = D->getTypeConstraint(); !TC) { + TK = CXType_Auto; + } + } + } + ASTContext &Ctx = cxtu::getASTUnit(TU)->getASTContext(); if (Ctx.getLangOpts().ObjC) { QualType UnqualT = T.getUnqualifiedType(); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
