[clang] [sema] Improve -Wsign-compare (PR #65684)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 8 08:37:23 PDT 2023
================
@@ -14043,28 +14039,61 @@ static bool CheckTautologicalComparison(Sema &S, BinaryOperator *E,
return true;
}
+namespace {
+struct AnalyzeImplicitConversionsWorkItem {
+ Expr *E;
+ SourceLocation CC;
+ unsigned IsListInit : 1;
+ unsigned IsTopLevelExpr : 1;
+};
+
+class ImplicitConversionChecker {
+ Sema &S;
+ Expr *TopLevelExpr;
+
+ void AnalyzeCompoundAssignment(BinaryOperator *E);
+ void AnalyzeImplicitConversions(
+ AnalyzeImplicitConversionsWorkItem Item,
+ llvm::SmallVectorImpl<AnalyzeImplicitConversionsWorkItem> &WorkList);
+ void AnalyzeImpConvsInComparison(BinaryOperator *E);
+ void AnalyzeComparison(BinaryOperator *E);
+ void AnalyzeAssignment(BinaryOperator *E);
+ void CheckConditionalOperand(Expr *E, QualType T, SourceLocation CC,
+ bool &ICContext);
+ void CheckConditionalOperator(AbstractConditionalOperator *E,
+ SourceLocation CC, QualType T);
+
+public:
+ ImplicitConversionChecker(Sema &S) : S(S), TopLevelExpr(nullptr) {}
+
+ void AnalyzeImplicitConversions(Expr *E, SourceLocation CC,
+ bool IsInitList = false,
+ bool IsTopLevelExpr = false);
+};
+} // namespace
+
/// Analyze the operands of the given comparison. Implements the
/// fallback case from AnalyzeComparison.
-static void AnalyzeImpConvsInComparison(Sema &S, BinaryOperator *E) {
- AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
- AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
+void ImplicitConversionChecker::AnalyzeImpConvsInComparison(BinaryOperator *E) {
+ AnalyzeImplicitConversions(E->getLHS(), E->getOperatorLoc(), false, false);
+ AnalyzeImplicitConversions(E->getRHS(), E->getOperatorLoc(), false, false);
----------------
shafik wrote:
```suggestion
AnalyzeImplicitConversions(E->getLHS(), E->getOperatorLoc(), /*IsInitList=*/false, /*IsTopLevelExpr=*/false);
AnalyzeImplicitConversions(E->getRHS(), E->getOperatorLoc(), /*IsInitList=*/false, /*IsTopLevelExpr=*/false);
```
https://github.com/llvm/llvm-project/pull/65684
More information about the cfe-commits
mailing list