Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions clang/test/Index/auto-function-param.cpp
Original file line number Diff line number Diff line change
@@ -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<typename T>
concept Integral = __is_integral(T);

int baz(Integral auto q) {
return q;
}

// CHECK: FunctionDecl=baz:{{.*}} CXType_FunctionProto
// CHECK: ParmDecl=q:{{.*}} CXType_Auto
9 changes: 9 additions & 0 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 8 additions & 0 deletions clang/tools/libclang/CXType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TemplateTypeParmType>()) {
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();
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down