[clang] [clang][ASTImporter] Fix typos in trailing return testing on lambda p… (PR #101031)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 29 08:41:29 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Ding Fei (danix800)
<details>
<summary>Changes</summary>
The test should be true on function with trailing return.
This fixes crashes (infinite recursion) on lambda expr without parameters (no parentheses).
---
Full diff: https://github.com/llvm/llvm-project/pull/101031.diff
2 Files Affected:
- (modified) clang/lib/AST/ASTImporter.cpp (+3-5)
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+17)
``````````diff
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index da1981d8dd05f..83aa017a00a7f 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -3665,13 +3665,10 @@ bool ASTNodeImporter::hasReturnTypeDeclaredInside(FunctionDecl *D) {
const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
assert(FromFPT && "Must be called on FunctionProtoType");
- auto IsCXX11LambdaWithouTrailingReturn = [&]() {
+ auto IsCXX11LambdaWithoutTrailingReturn = [&]() {
if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
return false;
- if (FromFPT->hasTrailingReturn())
- return false;
-
if (const auto *MD = dyn_cast<CXXMethodDecl>(D))
return cast<CXXRecordDecl>(MD->getDeclContext())->isLambda();
@@ -3679,7 +3676,8 @@ bool ASTNodeImporter::hasReturnTypeDeclaredInside(FunctionDecl *D) {
};
QualType RetT = FromFPT->getReturnType();
- if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11LambdaWithouTrailingReturn()) {
+ if (FromFPT->hasTrailingReturn() || isa<AutoType>(RetT.getTypePtr()) ||
+ IsCXX11LambdaWithoutTrailingReturn()) {
FunctionDecl *Def = D->getDefinition();
IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
return Visitor.CheckType(RetT);
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 57c5f79651824..d275a08dca895 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -6738,6 +6738,23 @@ TEST_P(ASTImporterOptionSpecificTestBase,
EXPECT_TRUE(ToLambda);
}
+TEST_P(ASTImporterOptionSpecificTestBase,
+ ReturnTypeDeclaredInsideOfCXX11LambdaWithTrailingReturn) {
+ Decl *From, *To;
+ std::tie(From, To) = getImportedDecl(
+ R"(
+ void foo() {
+ (void) [] {
+ struct X {};
+ return X();
+ };
+ }
+ )",
+ Lang_CXX11, "", Lang_CXX11, "foo"); // c++11 only
+ auto *ToLambda = FirstDeclMatcher<LambdaExpr>().match(To, lambdaExpr());
+ EXPECT_TRUE(ToLambda);
+}
+
TEST_P(ASTImporterOptionSpecificTestBase, LambdaInFunctionParam) {
Decl *FromTU = getTuDecl(
R"(
``````````
</details>
https://github.com/llvm/llvm-project/pull/101031
More information about the cfe-commits
mailing list