Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASTImporter] Fix infinite recurse on return type declared inside body (#68775) #89096

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Limit TypeVisitor checking to 'auto' and lambda definition only
1. Fix potential perf regression;
2. Fix comment.
  • Loading branch information
danix800 committed Apr 18, 2024
commit 3f1d714a2aa4b236afe9bb1384be073fb155a2b8
16 changes: 12 additions & 4 deletions clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3647,17 +3647,25 @@ class IsTypeDeclaredInsideVisitor
};
} // namespace

/// This function checks if the function has 'auto' return type that contains
/// This function checks if the given function has a return type that contains
/// a reference (in any way) to a declaration inside the same function.
bool ASTNodeImporter::hasReturnTypeDeclaredInside(FunctionDecl *D) {
QualType FromTy = D->getType();
const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
assert(FromFPT && "Must be called on FunctionProtoType");

bool IsLambdaDefinition = false;
if (const auto *MD = dyn_cast<CXXMethodDecl>(D))
IsLambdaDefinition = cast<CXXRecordDecl>(MD->getDeclContext())->isLambda();
mizvekov marked this conversation as resolved.
Show resolved Hide resolved

QualType RetT = FromFPT->getReturnType();
FunctionDecl *Def = D->getDefinition();
IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
return Visitor.CheckType(RetT);
if (isa<AutoType>(RetT.getTypePtr()) || IsLambdaDefinition) {
FunctionDecl *Def = D->getDefinition();
IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
return Visitor.CheckType(RetT);
}

return false;
}

ExplicitSpecifier
Expand Down
Loading