diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -233,7 +233,8 @@ for (const auto *CallExpr : CEF.getCallExprs()) { const Decl *Decl = CallExpr->getCalleeDecl(); - if (Decl->hasAttr() || Decl->hasAttr()) + if (Decl && + (Decl->hasAttr() || Decl->hasAttr())) S.Diag(St->getBeginLoc(), diag::warn_function_stmt_attribute_precedence) << A << (Decl->hasAttr() ? 0 : 1); } @@ -259,7 +260,7 @@ for (const auto *CallExpr : CEF.getCallExprs()) { const Decl *Decl = CallExpr->getCalleeDecl(); - if (Decl->hasAttr() || Decl->hasAttr()) + if (Decl && (Decl->hasAttr() || Decl->hasAttr())) S.Diag(St->getBeginLoc(), diag::warn_function_stmt_attribute_precedence) << A << (Decl->hasAttr() ? 2 : 1); } diff --git a/clang/test/Sema/attr-alwaysinline.cpp b/clang/test/Sema/attr-alwaysinline.cpp --- a/clang/test/Sema/attr-alwaysinline.cpp +++ b/clang/test/Sema/attr-alwaysinline.cpp @@ -25,3 +25,13 @@ } [[clang::always_inline]] static int i = bar(); // expected-warning {{'always_inline' attribute only applies to functions and statements}} + +// This used to crash the compiler. +template +int foo(int x) { + if constexpr (D > 1) + [[clang::always_inline]] return foo(x + 1); + else + return x; +} + diff --git a/clang/test/Sema/attr-noinline.cpp b/clang/test/Sema/attr-noinline.cpp --- a/clang/test/Sema/attr-noinline.cpp +++ b/clang/test/Sema/attr-noinline.cpp @@ -25,3 +25,13 @@ } [[clang::noinline]] static int i = bar(); // expected-warning {{'noinline' attribute only applies to functions and statements}} + +// This used to crash the compiler. +template +int foo(int x) { + if constexpr (D > 1) + [[clang::noinline]] return foo(x + 1); + else + return x; +} +