ilya-biryukov updated this revision to Diff 506623. ilya-biryukov marked an inline comment as done. ilya-biryukov added a comment.
- rename test file to GH61441.cpp, add a comment this checks for no crash - Update outdated comment Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146426/new/ https://reviews.llvm.org/D146426 Files: clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaLambda.cpp clang/lib/Sema/SemaTemplateInstantiate.cpp clang/test/SemaCXX/GH61441.cpp Index: clang/test/SemaCXX/GH61441.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/GH61441.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// Checks Clang does not crash. + +template <bool> +int foo() { + auto x = [&](__fp16) { return 0; }; // expected-error {{parameters cannot have __fp16 type}} + return 0; +} + +int bar() { return foo<true>(); } Index: clang/lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- clang/lib/Sema/SemaTemplateInstantiate.cpp +++ clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1343,7 +1343,7 @@ CXXMethodDecl *MD = Result.getAs<LambdaExpr>()->getCallOperator(); for (ParmVarDecl *PVD : MD->parameters()) { - if (!PVD->hasDefaultArg()) + if (!PVD || !PVD->hasDefaultArg()) continue; Expr *UninstExpr = PVD->getUninstantiatedDefaultArg(); // FIXME: Obtain the source location for the '=' token. Index: clang/lib/Sema/SemaLambda.cpp =================================================================== --- clang/lib/Sema/SemaLambda.cpp +++ clang/lib/Sema/SemaLambda.cpp @@ -966,8 +966,11 @@ if (!Params.empty()) { CheckParmsForFunctionDef(Params, /*CheckParameterNames=*/false); Method->setParams(Params); - for (auto P : Method->parameters()) + for (auto P : Method->parameters()) { + if (!P) + continue; P->setOwningFunction(Method); + } } buildLambdaScopeReturnType(*this, LSI, Method, HasExplicitResultType); Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -1712,6 +1712,8 @@ /// Check whether a function's parameter types are all literal types. If so, /// return true. If not, produce a suitable diagnostic and return false. +/// If any ParamDecl is null, return false without producing a diagnostic. +/// The code creating null parameters is responsible for producing a diagnostic. static bool CheckConstexprParameterTypes(Sema &SemaRef, const FunctionDecl *FD, Sema::CheckConstexprKind Kind) { @@ -1721,6 +1723,8 @@ e = FT->param_type_end(); i != e; ++i, ++ArgIndex) { const ParmVarDecl *PD = FD->getParamDecl(ArgIndex); + if (!PD) + return false; SourceLocation ParamLoc = PD->getLocation(); if (CheckLiteralType(SemaRef, Kind, ParamLoc, *i, diag::err_constexpr_non_literal_param, ArgIndex + 1, Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -15879,6 +15879,10 @@ bool CheckParameterNames) { bool HasInvalidParm = false; for (ParmVarDecl *Param : Parameters) { + if (!Param) { + HasInvalidParm = true; + continue; + } // C99 6.7.5.3p4: the parameters in a parameter type list in a // function declarator that is part of a function definition of // that function shall not have incomplete type.
Index: clang/test/SemaCXX/GH61441.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/GH61441.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// Checks Clang does not crash. + +template <bool> +int foo() { + auto x = [&](__fp16) { return 0; }; // expected-error {{parameters cannot have __fp16 type}} + return 0; +} + +int bar() { return foo<true>(); } Index: clang/lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- clang/lib/Sema/SemaTemplateInstantiate.cpp +++ clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1343,7 +1343,7 @@ CXXMethodDecl *MD = Result.getAs<LambdaExpr>()->getCallOperator(); for (ParmVarDecl *PVD : MD->parameters()) { - if (!PVD->hasDefaultArg()) + if (!PVD || !PVD->hasDefaultArg()) continue; Expr *UninstExpr = PVD->getUninstantiatedDefaultArg(); // FIXME: Obtain the source location for the '=' token. Index: clang/lib/Sema/SemaLambda.cpp =================================================================== --- clang/lib/Sema/SemaLambda.cpp +++ clang/lib/Sema/SemaLambda.cpp @@ -966,8 +966,11 @@ if (!Params.empty()) { CheckParmsForFunctionDef(Params, /*CheckParameterNames=*/false); Method->setParams(Params); - for (auto P : Method->parameters()) + for (auto P : Method->parameters()) { + if (!P) + continue; P->setOwningFunction(Method); + } } buildLambdaScopeReturnType(*this, LSI, Method, HasExplicitResultType); Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -1712,6 +1712,8 @@ /// Check whether a function's parameter types are all literal types. If so, /// return true. If not, produce a suitable diagnostic and return false. +/// If any ParamDecl is null, return false without producing a diagnostic. +/// The code creating null parameters is responsible for producing a diagnostic. static bool CheckConstexprParameterTypes(Sema &SemaRef, const FunctionDecl *FD, Sema::CheckConstexprKind Kind) { @@ -1721,6 +1723,8 @@ e = FT->param_type_end(); i != e; ++i, ++ArgIndex) { const ParmVarDecl *PD = FD->getParamDecl(ArgIndex); + if (!PD) + return false; SourceLocation ParamLoc = PD->getLocation(); if (CheckLiteralType(SemaRef, Kind, ParamLoc, *i, diag::err_constexpr_non_literal_param, ArgIndex + 1, Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -15879,6 +15879,10 @@ bool CheckParameterNames) { bool HasInvalidParm = false; for (ParmVarDecl *Param : Parameters) { + if (!Param) { + HasInvalidParm = true; + continue; + } // C99 6.7.5.3p4: the parameters in a parameter type list in a // function declarator that is part of a function definition of // that function shall not have incomplete type.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits