[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-25 Thread Philipp Rados via cfe-commits
https://github.com/PhilippRados updated https://github.com/llvm/llvm-project/pull/115234 >From e819360e6510f12f19b7df9d4eb22c0943776440 Mon Sep 17 00:00:00 2001 From: PhilippR Date: Thu, 7 Nov 2024 00:06:24 +0100 Subject: [PATCH 1/5] [clang] Added warn-assignment-bool-context This warning is i

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-25 Thread Philipp Rados via cfe-commits
PhilippRados wrote: I applied the mentioned changes from above and merged the two diagnostics into a single one. I also added the field IsInsideCondition to the `Expr` class and everything works. However I’m not sure whether or not this single diagnostic warrants the extra field in the class.

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-21 Thread Philipp Rados via cfe-commits
@@ -8477,6 +8477,9 @@ def err_incomplete_object_call : Error< def warn_condition_is_assignment : Warning<"using the result of an " "assignment as a condition without parentheses">, InGroup; +def warn_assignment_bool_context : Warning<"suggest parentheses around assignment

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-21 Thread Philipp Rados via cfe-commits
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr *ParenE) { ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr) { - DiagnoseAssignmentAsCondition(E); + // This warning is a

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-21 Thread Philipp Rados via cfe-commits
@@ -8477,6 +8477,9 @@ def err_incomplete_object_call : Error< def warn_condition_is_assignment : Warning<"using the result of an " "assignment as a condition without parentheses">, InGroup; +def warn_assignment_bool_context : Warning<"suggest parentheses around assignment

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-21 Thread Erich Keane via cfe-commits
@@ -687,6 +687,48 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) { << FixItHint::CreateReplacement(E->getSourceRange(), "nullptr"); } +void Sema::DiagnoseAssignmentBoolContext(Expr *E, QualType Ty) { + // Use copy to not alter original expr

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-21 Thread Philipp Rados via cfe-commits
@@ -687,6 +687,48 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) { << FixItHint::CreateReplacement(E->getSourceRange(), "nullptr"); } +void Sema::DiagnoseAssignmentBoolContext(Expr *E, QualType Ty) { + // Use copy to not alter original expr

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-21 Thread Philipp Rados via cfe-commits
@@ -687,6 +687,48 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) { << FixItHint::CreateReplacement(E->getSourceRange(), "nullptr"); } +void Sema::DiagnoseAssignmentBoolContext(Expr *E, QualType Ty) { + // Use copy to not alter original expr

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-20 Thread Erich Keane via cfe-commits
@@ -8477,6 +8477,9 @@ def err_incomplete_object_call : Error< def warn_condition_is_assignment : Warning<"using the result of an " "assignment as a condition without parentheses">, InGroup; +def warn_assignment_bool_context : Warning<"suggest parentheses around assignment

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-20 Thread Erich Keane via cfe-commits
@@ -687,6 +687,48 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) { << FixItHint::CreateReplacement(E->getSourceRange(), "nullptr"); } +void Sema::DiagnoseAssignmentBoolContext(Expr *E, QualType Ty) { + // Use copy to not alter original expr

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-20 Thread Erich Keane via cfe-commits
https://github.com/erichkeane commented: Still hasn't changed based on my previous feedback, but a few more things as I was scrolling through. https://github.com/llvm/llvm-project/pull/115234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org htt

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-20 Thread Erich Keane via cfe-commits
@@ -687,6 +687,48 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) { << FixItHint::CreateReplacement(E->getSourceRange(), "nullptr"); } +void Sema::DiagnoseAssignmentBoolContext(Expr *E, QualType Ty) { + // Use copy to not alter original expr

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-02-20 Thread Erich Keane via cfe-commits
https://github.com/erichkeane edited https://github.com/llvm/llvm-project/pull/115234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Philipp Rados via cfe-commits
https://github.com/PhilippRados edited https://github.com/llvm/llvm-project/pull/115234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Philipp Rados via cfe-commits
@@ -761,6 +803,17 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, } } + // FIXME: Doesn't include C89, so this warning isn't emitted when passing + // `std=c89`. + auto isC = getLangOpts().C99 || getLangOpts().C11 || getLangOpts().C17 || P

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Erich Keane via cfe-commits
@@ -761,6 +803,17 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, } } + // FIXME: Doesn't include C89, so this warning isn't emitted when passing + // `std=c89`. + auto isC = getLangOpts().C99 || getLangOpts().C11 || getLangOpts().C17 || e

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Erich Keane via cfe-commits
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr *ParenE) { ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr) { - DiagnoseAssignmentAsCondition(E); + // This warning is a

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Philipp Rados via cfe-commits
@@ -761,6 +803,17 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, } } + // FIXME: Doesn't include C89, so this warning isn't emitted when passing + // `std=c89`. + auto isC = getLangOpts().C99 || getLangOpts().C11 || getLangOpts().C17 || P

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Philipp Rados via cfe-commits
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr *ParenE) { ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr) { - DiagnoseAssignmentAsCondition(E); + // This warning is a

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Erich Keane via cfe-commits
@@ -8477,6 +8477,9 @@ def err_incomplete_object_call : Error< def warn_condition_is_assignment : Warning<"using the result of an " "assignment as a condition without parentheses">, InGroup; +def warn_assignment_bool_context : Warning<"suggest parentheses around assignment

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Erich Keane via cfe-commits
@@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -x c++ -fsyntax-only -Wparentheses -verify %s + +// Do not emit the warning for compound-assignments. +bool f(int x) { return x = 0; } // expected-warning {{suggest parentheses around assignment used as truth value}} \ +

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Erich Keane via cfe-commits
@@ -761,6 +803,17 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, } } + // FIXME: Doesn't include C89, so this warning isn't emitted when passing + // `std=c89`. + auto isC = getLangOpts().C99 || getLangOpts().C11 || getLangOpts().C17 || e

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Erich Keane via cfe-commits
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr *ParenE) { ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr) { - DiagnoseAssignmentAsCondition(E); + // This warning is a

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Erich Keane via cfe-commits
@@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -x c -fsyntax-only -Wparentheses -verify %s + +// NOTE: Don't know if tests allow includes. +#include erichkeane wrote: Include shouldn't be here, you can just define the thing manually if you'd like. https://github.com/llvm

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-21 Thread Erich Keane via cfe-commits
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr *ParenE) { ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr) { - DiagnoseAssignmentAsCondition(E); + // This warning is a

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-18 Thread Philipp Rados via cfe-commits
PhilippRados wrote: Yup ok. I thought that was what draft was for to check on not-finished implementations but I just changed it back for review. https://github.com/llvm/llvm-project/pull/115234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-18 Thread Vlad Serebrennikov via cfe-commits
Endilll wrote: > No problem, I know everybody is busy. > > > The first step is to get the PR out of draft state. > > Do you just mean to mark it "read for review" or to apply changes so that it > can be merged? Because the current implementation is not ready as I still > have some questions a

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-18 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Author: Philipp Rados (PhilippRados) Changes This is a fix for #33528 as I messed up my other PR with unsynced changes. A couple of things make this less straightforward as initially thought, which is why I would like some feedback as to how the

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-18 Thread Philipp Rados via cfe-commits
https://github.com/PhilippRados ready_for_review https://github.com/llvm/llvm-project/pull/115234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-18 Thread Philipp Rados via cfe-commits
PhilippRados wrote: No problem, I know everybody is busy. > The first step is to get the PR out of draft state. Do you just mean to mark it "read for review" or to apply changes so that it can be merged? Because the current implementation is not ready as I still have some questions as to how t

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2025-01-16 Thread Vlad Serebrennikov via cfe-commits
Endilll wrote: I'm sorry it took us a while. The first step is to get the PR out of draft state. https://github.com/llvm/llvm-project/pull/115234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cf

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2024-11-13 Thread Philipp Rados via cfe-commits
PhilippRados wrote: @Endilll Do you have some advice regarding this implementation? Or can you otherwise maybe forward this to someone who can take a look. https://github.com/llvm/llvm-project/pull/115234 ___ cfe-commits mailing list cfe-commits@lists

[clang] [clang] Added warn-assignment-bool-context (PR #115234)

2024-11-06 Thread Philipp Rados via cfe-commits
https://github.com/PhilippRados created https://github.com/llvm/llvm-project/pull/115234 This is a fix for #33528 as I messed up my other PR with unsynced changes. A couple of things make this less straightforward as initially thought, which is why I would like some feedback as to how these th