[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-14 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 created https://github.com/llvm/llvm-project/pull/112289 Currently, the following program ```cpp [[nodiscard]] int fun() { return 1; } [[deprecated]] int fun2() { return 2; } int main() { fun(); fun2(); } ``` generates the following diagnostics on Clang trunk:

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
@@ -302,27 +312,38 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) { if (const Decl *FD = CE->getCalleeDecl()) { if (ShouldSuppress) return; - if (FD->hasAttr()) { + if (const auto *A = FD->getAttr()) { Diag(Loc, diag

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 edited https://github.com/llvm/llvm-project/pull/112289 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr *E) { return true; } -static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A, - SourceLocation Loc, SourceRange R1, - Sourc

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
@@ -290,9 +297,12 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) { if (E->getType()->isVoidType()) return; -if (DiagnoseNoDiscard(*this, cast_or_null( - CE->getUnusedResultAttr(Context)), -

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr *E) { return true; } -static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A, - SourceLocation Loc, SourceRange R1, - Sourc

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
@@ -9290,6 +9290,8 @@ def warn_unused_result_typedef_unsupported_spelling : Warning< def warn_unused_volatile : Warning< "expression result unused; assign into a variable to force a volatile load">, InGroup>; +def note_nodiscard_specified_here : Note< Mick

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
Mick235711 wrote: > That is, keep the current wording if the function is nodiscard, but change it > to mention the type instead if the type is marked nodiscard—provided there is > a relatively straight-forward way of doing this. I think this should be okay-ish to implement since we basically a

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr *E) { return true; } -static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A, - SourceLocation Loc, SourceRange R1, - Sourc

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
Mick235711 wrote: > I don’t really see that happening for nodiscard tho—making only some > overloads nodiscard instead of none or all of them just seems like a really > weird thing to do personally... I think there is still some merits for these kind of overload sets. For instance, API like

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
@@ -9290,6 +9290,8 @@ def warn_unused_result_typedef_unsupported_spelling : Warning< def warn_unused_volatile : Warning< "expression result unused; assign into a variable to force a volatile load">, InGroup>; +def note_nodiscard_specified_here : Note< Mick

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr *E) { return true; } -static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A, - SourceLocation Loc, SourceRange R1, - Sourc

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112289 >From 2376ab367715ef2f7f77ffc4d5af21393af876bd Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Tue, 15 Oct 2024 08:13:22 +0800 Subject: [PATCH] [clang] Generate note on declaration for nodiscard-related attribu

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
@@ -302,27 +307,43 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) { if (const Decl *FD = CE->getCalleeDecl()) { if (ShouldSuppress) return; - if (FD->hasAttr()) { -Diag(Loc, diag::warn_unused_call) << R1 << R2 << "pure"; -

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 edited https://github.com/llvm/llvm-project/pull/112289 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112289 >From aaad12bcc38cfd11597e2e0c5ba93f2197e5a4ac Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Tue, 15 Oct 2024 08:13:22 +0800 Subject: [PATCH] [clang] Generate note on declaration for nodiscard-related attribu

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112289 >From b9911d5b997306376fcf5348a24f8bae7b71bfeb Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Tue, 15 Oct 2024 08:13:22 +0800 Subject: [PATCH] [clang] Generate note on declaration for nodiscard-related attribu

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 created https://github.com/llvm/llvm-project/pull/112521 A follow-up and alternative proposal to #112289. In this PR, no new notes are added to avoid noise. Instead, originally, every `[[nodiscard]]` trigger, regardless of whether it is on function declaration or

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits
Mick235711 wrote: CC @Sirraide @erichkeane. (Sorry, I do not have permission to request reviewers, so instead used ping) https://github.com/llvm/llvm-project/pull/112521 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cg

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits
@@ -115,20 +115,20 @@ void usage() { S('A'); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't let that S-Char go!}} S(1); S(2.2); - Y(); // expected-warning {{ignoring temporary created by a constructor declar

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112521 >From 10f7bb8cd7d6eef26065d20437dc126cd4e7138c Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Wed, 16 Oct 2024 18:53:04 +0800 Subject: [PATCH] [clang] Improve diagnostic on [[nodiscard]] attribute --- clang/d

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits
@@ -115,20 +115,20 @@ void usage() { S('A'); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't let that S-Char go!}} S(1); S(2.2); - Y(); // expected-warning {{ignoring temporary created by a constructor declar

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112521 >From 59f7dbdd8eed456b76e93f6260bf0e361242e9fd Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Wed, 16 Oct 2024 18:53:04 +0800 Subject: [PATCH] [clang] Improve diagnostic on [[nodiscard]] attribute --- clang/d

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112521 >From e69fcc089b8a0cb2d6c420f829ad74bd26a8ad21 Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Wed, 16 Oct 2024 18:53:04 +0800 Subject: [PATCH] [clang] Improve diagnostic on [[nodiscard]] attribute --- clang/d

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112521 >From 35be44832bdc81ddbdeaa98500e65ec1de0cc049 Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Wed, 16 Oct 2024 18:53:04 +0800 Subject: [PATCH] [clang] Improve diagnostic on [[nodiscard]] attribute --- clang/d

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-16 Thread Yihe Li via cfe-commits
Mick235711 wrote: Release note added. Incidentally, this also fixes an inconsistency for Clang compared to GCC/MSVC: In the following program ```cpp struct [[nodiscard("Reason 1")]] S {}; [[nodiscard("Reason 2")]] S getS(); int main() { getS(); } ``` My opinion is that the function's attri

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-22 Thread Yihe Li via cfe-commits
@@ -416,6 +416,9 @@ Improvements to Clang's diagnostics name was a reserved name, which we improperly allowed to suppress the diagnostic. +- Clang now includes the return type of the function or constructor in the warning generated + when `[[nodiscard]]` is triggered by

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-22 Thread Yihe Li via cfe-commits
Mick235711 wrote: > Side note: please try to avoid force-pushing in the future as that makes it > really annoying to try and figure out what has changed since the last review. > We always squash on merge anyway, so a clean commit history on a pr is > irrelevant. Oh, sorry about that, I don't u

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-10-22 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112521 >From 59f7dbdd8eed456b76e93f6260bf0e361242e9fd Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Wed, 16 Oct 2024 18:53:04 +0800 Subject: [PATCH 1/2] [clang] Improve diagnostic on [[nodiscard]] attribute --- cla

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-11-19 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 closed https://github.com/llvm/llvm-project/pull/112289 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112521 >From 59f7dbdd8eed456b76e93f6260bf0e361242e9fd Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Wed, 16 Oct 2024 18:53:04 +0800 Subject: [PATCH 1/3] [clang] Improve diagnostic on [[nodiscard]] attribute --- cla

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits
@@ -9300,6 +9300,12 @@ def warn_unused_container_subscript_expr : Warning< def warn_unused_call : Warning< "ignoring return value of function declared with %0 attribute">, InGroup; +def warn_unused_return_type : Warning< + "ignoring %select{return value|temporary}0 of type

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112521 >From 59f7dbdd8eed456b76e93f6260bf0e361242e9fd Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Wed, 16 Oct 2024 18:53:04 +0800 Subject: [PATCH 1/4] [clang] Improve diagnostic on [[nodiscard]] attribute --- cla

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits
@@ -9300,6 +9300,12 @@ def warn_unused_container_subscript_expr : Warning< def warn_unused_call : Warning< "ignoring return value of function declared with %0 attribute">, InGroup; +def warn_unused_return_type : Warning< + "ignoring %select{return value|temporary}0 of type

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112521 >From 59f7dbdd8eed456b76e93f6260bf0e361242e9fd Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Wed, 16 Oct 2024 18:53:04 +0800 Subject: [PATCH 1/5] [clang] Improve diagnostic on [[nodiscard]] attribute --- cla

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits
@@ -148,6 +148,19 @@ C++ Specific Potentially Breaking Changes // Now diagnoses with an error. void f(int& i [[clang::lifetimebound]]); +- Clang will now prefer the ``[[nodiscard]]`` declaration on function declarations over ``[[nodiscard]]`` Mick2357

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 updated https://github.com/llvm/llvm-project/pull/112521 >From 59f7dbdd8eed456b76e93f6260bf0e361242e9fd Mon Sep 17 00:00:00 2001 From: Yihe Li Date: Wed, 16 Oct 2024 18:53:04 +0800 Subject: [PATCH 1/2] [clang] Improve diagnostic on [[nodiscard]] attribute --- cla

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits
@@ -17,10 +17,10 @@ E get_e(); // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}} void f() { - get_s(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + get_s(); // expected-warning {{ignoring return

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits
@@ -1616,22 +1616,24 @@ QualType CallExpr::getCallReturnType(const ASTContext &Ctx) const { return FnType->getReturnType(); } -const Attr *CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const { +std::pair +CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const { +

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits
Mick235711 wrote: Gentle ping @erichkeane https://github.com/llvm/llvm-project/pull/112521 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-12-04 Thread Yihe Li via cfe-commits
@@ -1615,22 +1615,24 @@ QualType CallExpr::getCallReturnType(const ASTContext &Ctx) const { return FnType->getReturnType(); } -const Attr *CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const { +std::pair +CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const { +

[clang] [clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr (PR #118636)

2024-12-04 Thread Yihe Li via cfe-commits
https://github.com/Mick235711 created https://github.com/llvm/llvm-project/pull/118636 Fixes #117975, a regression introduced by #112521 due to me forgetting to check for `nullptr` before dereferencing in `CallExpr::getUnusedResultAttr`. A regression test has been added as per the comments on t

[clang] [clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr (PR #118636)

2024-12-04 Thread Yihe Li via cfe-commits
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 Date: Wed, 4 Dec 2024 21:45:19 +0800 Subject: [PATCH 1/2] [clang] Fix missing check for nullptr in CallExpr::getUnusedRes

[clang] [clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr (PR #118636)

2025-01-06 Thread Yihe Li via cfe-commits
Mick235711 wrote: Gentle ping @cor3ntin @Sirraide https://github.com/llvm/llvm-project/pull/118636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr (PR #118636)

2024-12-17 Thread Yihe Li via cfe-commits
Mick235711 wrote: > This was approved, do you need someone to merge this for you? Yes, I do; I don't really have merge permissions. Thanks a lot for the helping hand. https://github.com/llvm/llvm-project/pull/118636 ___ cfe-commits mailing list cfe-c

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-11-21 Thread Yihe Li via cfe-commits
Mick235711 wrote: Closed in favor of #112521. https://github.com/llvm/llvm-project/pull/112289 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits