From 49eba8bf1780684f1173a455b909ce37008eaa09 Mon Sep 17 00:00:00 2001 From: Adam Czachorowski Date: Mon, 7 Jun 2021 18:26:21 +0200 Subject: [PATCH] [clang] Do not crash when ArgTy is null in CheckArgAlignment This can happen around RecoveryExpr. Differential Revision: https://reviews.llvm.org/D103825 --- clang/lib/Sema/SemaChecking.cpp | 8 ++++++-- clang/test/SemaCXX/recovery-expr-type.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 99110c6..86c8885 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4571,8 +4571,9 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, // 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,9 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, 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; + QualType ParamTy = Proto->getParamType(ArgIdx); QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), diff --git a/clang/test/SemaCXX/recovery-expr-type.cpp b/clang/test/SemaCXX/recovery-expr-type.cpp index 8bdf83e..d3ac772 100644 --- a/clang/test/SemaCXX/recovery-expr-type.cpp +++ b/clang/test/SemaCXX/recovery-expr-type.cpp @@ -136,3 +136,9 @@ void baz() { 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 -- 2.7.4