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
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.
@@ -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
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr
*ParenE) {
ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E,
bool IsConstexpr) {
- DiagnoseAssignmentAsCondition(E);
+ // This warning is a
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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
@@ -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
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
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
@@ -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
@@ -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
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr
*ParenE) {
ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E,
bool IsConstexpr) {
- DiagnoseAssignmentAsCondition(E);
+ // This warning is a
@@ -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
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr
*ParenE) {
ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E,
bool IsConstexpr) {
- DiagnoseAssignmentAsCondition(E);
+ // This warning is a
@@ -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
@@ -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}} \
+
@@ -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
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr
*ParenE) {
ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E,
bool IsConstexpr) {
- DiagnoseAssignmentAsCondition(E);
+ // This warning is a
@@ -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
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr
*ParenE) {
ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E,
bool IsConstexpr) {
- DiagnoseAssignmentAsCondition(E);
+ // This warning is a
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
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
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
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
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
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
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
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
33 matches
Mail list logo