[PATCH] D63369: [AST] Fixed extraneous warnings for binary conditional operator
Nathan Huckleberry via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 18 16:43:17 PDT 2019
Nathan-Huckleberry updated this revision to Diff 205470.
Nathan-Huckleberry added a comment.
- [analyzer] Fix clang-tidy crash on GCCAsmStmt
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63369/new/
https://reviews.llvm.org/D63369
Files:
clang-tools-extra/test/clang-tidy/asm-goto.cpp
clang/lib/AST/Expr.cpp
clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
clang/test/Sema/warn-binary-conditional-expression-unused.c
Index: clang/test/Sema/warn-binary-conditional-expression-unused.c
===================================================================
--- /dev/null
+++ clang/test/Sema/warn-binary-conditional-expression-unused.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-value -verify %s
+int main() {
+ int a;
+ int b;
+ a ? : b; //expected-warning{{expression result unused}}
+ a ? a : b; //expected-warning{{expression result unused}}
+ a ? : ++b;
+ a ? a : ++b;
+ ++a ? : b; //expected-warning{{expression result unused}}
+ ++a ? a : b; //expected-warning{{expression result unused}}
+ ++a ? : ++b;
+ ++a ? a : ++b;
+ return 0;
+};
+
Index: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -396,6 +396,9 @@
case Stmt::WhileStmtClass:
HandleBranch(cast<WhileStmt>(Term)->getCond(), Term, B, Pred);
return;
+
+ case Stmt::GCCAsmStmtClass:
+ return;
}
}
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2345,12 +2345,13 @@
// If only one of the LHS or RHS is a warning, the operator might
// be being used for control flow. Only warn if both the LHS and
// RHS are warnings.
- const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
- if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx))
- return false;
- if (!Exp->getLHS())
- return true;
- return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+ const auto *Exp = cast<ConditionalOperator>(this);
+ return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) &&
+ Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+ }
+ case BinaryConditionalOperatorClass: {
+ const auto *Exp = cast<BinaryConditionalOperator>(this);
+ return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
}
case MemberExprClass:
Index: clang-tools-extra/test/clang-tidy/asm-goto.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/asm-goto.cpp
@@ -0,0 +1,29 @@
+// REQUIRES: static-analyzer
+// RUN: clang-tidy %s -checks='bugprone-use-after-move' -- | FileCheck %s
+#include <string>
+#include <utility>
+int main() {
+ struct S {
+ std::string str;
+ int i;
+ };
+
+ S s = { "Hello, world!\n", 42 };
+ S s_other = std::move(s);
+ asm goto( "xor %0, %0\n je %l[label1]\n jl %l[label2]" : /* no outputs */ : /* inputs */ : /* clobbers */ : label1, label2 /* any labels used */ );
+ return 0;
+
+ label1:
+ // CHECK: warning: 's' used after it was moved [bugprone-use-after-move]
+ s.str = "ABC";
+ s.i = 99;
+ return 2;
+
+ label2:
+ // There should be a warning here, but UseAfterMoveCheck only reports one
+ // warning per std::move
+ s.str = "DEF";
+ s.i = 100;
+ return 0;
+}
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63369.205470.patch
Type: text/x-patch
Size: 3151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190618/f21418c6/attachment.bin>
More information about the cfe-commits
mailing list