diff --git a/clang/test/Index/auto-function-param.cpp b/clang/test/Index/auto-function-param.cpp new file mode 100644 index 0000000000000..bb32b72e6f7a2 --- /dev/null +++ b/clang/test/Index/auto-function-param.cpp @@ -0,0 +1,24 @@ +// 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 +// C++20 constrained auto parameter +template +concept Integral = __is_integral(T); + +int baz(Integral auto q) { + return q; +} + +// CHECK: FunctionDecl=baz:{{.*}} CXType_FunctionProto +// CHECK: ParmDecl=q:{{.*}} CXType_Auto \ No newline at end of file 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..9115108efd24d 100644 --- a/clang/tools/libclang/CXType.cpp +++ b/clang/tools/libclang/CXType.cpp @@ -150,6 +150,14 @@ CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) { return MakeCXType(PTT->getInnerType(), TU); } + // Handle auto in function parameters (including constrained auto) + if (auto *TTP = T->getAs()) { + auto *D = TTP->getDecl(); + if (D && D->isImplicit()) { + TK = CXType_Auto; + } + } + ASTContext &Ctx = cxtu::getASTUnit(TU)->getASTContext(); if (Ctx.getLangOpts().ObjC) { QualType UnqualT = T.getUnqualifiedType(); diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 9ba1c06b6d3fa..757f7952a2ca0 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2912,6 +2912,7 @@ uint64_t LoopVectorizationCostModel::getPredBlockCostDivisor( uint64_t BBFreq = getBFI().getBlockFreq(BB).getFrequency(); assert(HeaderFreq >= BBFreq && "Header has smaller block freq than dominated BB?"); + assert(BBFreq != 0 && "BlockFrequencyInfo should never return zero frequency"); return std::round((double)HeaderFreq / BBFreq); }