https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/118636
>From e81792ade5cda7afbba6ba161a3a9b9184065d82 Mon Sep 17 00:00:00 2001 From: Yihe Li <winmiked...@hotmail.com> Date: Wed, 4 Dec 2024 21:45:19 +0800 Subject: [PATCH 1/2] [clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr --- clang/lib/AST/Expr.cpp | 5 +++-- clang/test/SemaCXX/warn-unused-result.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index a4fb4d5a1f2ec4..286f02ded27196 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1619,8 +1619,9 @@ std::pair<const NamedDecl *, const Attr *> CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const { // If the callee is marked nodiscard, return that attribute const Decl *D = getCalleeDecl(); - if (const auto *A = D->getAttr<WarnUnusedResultAttr>()) - return {nullptr, A}; + if (D != nullptr) + if (const auto *A = D->getAttr<WarnUnusedResultAttr>()) + return {nullptr, A}; // If the return type is a struct, union, or enum that is marked nodiscard, // then return the return type attribute. diff --git a/clang/test/SemaCXX/warn-unused-result.cpp b/clang/test/SemaCXX/warn-unused-result.cpp index 682c500dc1d96d..5105f347db8b53 100644 --- a/clang/test/SemaCXX/warn-unused-result.cpp +++ b/clang/test/SemaCXX/warn-unused-result.cpp @@ -355,3 +355,12 @@ void use2() { (void)G{"Hello"}; } } // namespace nodiscard_specialization + +namespace GH117975 { +// Test for a regression for ICE in CallExpr::getUnusedResultAttr +int f() { return 0; } +void id_print_name() { + (int) // expected-warning {{expression result unused}} + ((int(*)())f)(); +} +} // namespace GH117975 >From 9e8950a1f7cf9a3822b7954618085813a5e8ffdc Mon Sep 17 00:00:00 2001 From: Yihe Li <winmiked...@hotmail.com> Date: Thu, 5 Dec 2024 00:27:34 +0800 Subject: [PATCH 2/2] Use inline decl in if to test nullptr --- clang/lib/AST/Expr.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 286f02ded27196..d8119543e9f8f8 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1618,8 +1618,7 @@ QualType CallExpr::getCallReturnType(const ASTContext &Ctx) const { std::pair<const NamedDecl *, const Attr *> CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const { // If the callee is marked nodiscard, return that attribute - const Decl *D = getCalleeDecl(); - if (D != nullptr) + if (const Decl *D = getCalleeDecl()) if (const auto *A = D->getAttr<WarnUnusedResultAttr>()) return {nullptr, A}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits