adamcz updated this revision to Diff 350629. adamcz added a comment. Added some containsErrors() calls, not sure if that's the right thing to do
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D103825/new/ https://reviews.llvm.org/D103825 Files: clang/lib/Sema/SemaChecking.cpp clang/test/SemaCXX/recovery-expr-type.cpp Index: clang/test/SemaCXX/recovery-expr-type.cpp =================================================================== --- clang/test/SemaCXX/recovery-expr-type.cpp +++ clang/test/SemaCXX/recovery-expr-type.cpp @@ -136,3 +136,9 @@ bar(S(123)); // expected-error {{no matching conversion}} } } // namespace test11 + +namespace test12 { +// Verify we do not crash. +void fun(int *foo = no_such_function()); // expected-error {{undeclared identifier}} +void baz() { fun(); } +} // namespace test12 Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -4571,8 +4571,9 @@ // Find expected alignment, and the actual alignment of the passed object. // getTypeAlignInChars requires complete types - if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() || - ParamTy->isUndeducedType() || ArgTy->isUndeducedType()) + if (ArgTy.isNull() || ParamTy->isIncompleteType() || + ArgTy->isIncompleteType() || ParamTy->isUndeducedType() || + ArgTy->isUndeducedType()) return; CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy); @@ -4654,6 +4655,14 @@ for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { + if (Arg->containsErrors()) + continue; + // If default expr is RecoveryExpr then Arg->containsErrors() is false, + // but we still don't want to check argument like that. + if (auto *DefaultArg = cast<CXXDefaultArgExpr>(Arg)) + if (!DefaultArg->getExpr() || DefaultArg->getExpr()->containsErrors()) + continue; + QualType ParamTy = Proto->getParamType(ArgIdx); QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1),
Index: clang/test/SemaCXX/recovery-expr-type.cpp =================================================================== --- clang/test/SemaCXX/recovery-expr-type.cpp +++ clang/test/SemaCXX/recovery-expr-type.cpp @@ -136,3 +136,9 @@ bar(S(123)); // expected-error {{no matching conversion}} } } // namespace test11 + +namespace test12 { +// Verify we do not crash. +void fun(int *foo = no_such_function()); // expected-error {{undeclared identifier}} +void baz() { fun(); } +} // namespace test12 Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -4571,8 +4571,9 @@ // Find expected alignment, and the actual alignment of the passed object. // getTypeAlignInChars requires complete types - if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() || - ParamTy->isUndeducedType() || ArgTy->isUndeducedType()) + if (ArgTy.isNull() || ParamTy->isIncompleteType() || + ArgTy->isIncompleteType() || ParamTy->isUndeducedType() || + ArgTy->isUndeducedType()) return; CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy); @@ -4654,6 +4655,14 @@ for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { + if (Arg->containsErrors()) + continue; + // If default expr is RecoveryExpr then Arg->containsErrors() is false, + // but we still don't want to check argument like that. + if (auto *DefaultArg = cast<CXXDefaultArgExpr>(Arg)) + if (!DefaultArg->getExpr() || DefaultArg->getExpr()->containsErrors()) + continue; + QualType ParamTy = Proto->getParamType(ArgIdx); QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits