================
@@ -324,30 +324,207 @@ OpenACCAtomicConstruct *OpenACCAtomicConstruct::Create(
return Inst;
}
-static std::pair<const Expr *, const Expr *> getBinaryOpArgs(const Expr *Op) {
+static std::optional<std::pair<const Expr *, const Expr *>>
+getBinaryAssignOpArgs(const Expr *Op, bool &isCompoundAssign) {
if (const auto *BO = dyn_cast<BinaryOperator>(Op)) {
- assert(BO->isAssignmentOp());
- return {BO->getLHS(), BO->getRHS()};
+ if (!BO->isAssignmentOp())
+ return std::nullopt;
+ isCompoundAssign = BO->isCompoundAssignmentOp();
+ return std::pair<const Expr *, const Expr *>({BO->getLHS(), BO->getRHS()});
}
- const auto *OO = cast<CXXOperatorCallExpr>(Op);
- assert(OO->isAssignmentOp());
- return {OO->getArg(0), OO->getArg(1)};
+ if (const auto *OO = dyn_cast<CXXOperatorCallExpr>(Op)) {
+ if (!OO->isAssignmentOp())
+ return std::nullopt;
+ isCompoundAssign = OO->getOperator() != OO_Equal;
+ return std::pair<const Expr *, const Expr *>(
+ {OO->getArg(0), OO->getArg(1)});
+ }
+ return std::nullopt;
+}
+static std::optional<std::pair<const Expr *, const Expr *>>
+getBinaryAssignOpArgs(const Expr *Op) {
+ bool isCompoundAssign;
+ return getBinaryAssignOpArgs(Op, isCompoundAssign);
}
-static std::pair<bool, const Expr *> getUnaryOpArgs(const Expr *Op) {
+static std::optional<const Expr *> getUnaryOpArgs(const Expr *Op) {
if (const auto *UO = dyn_cast<UnaryOperator>(Op))
- return {true, UO->getSubExpr()};
+ return UO->getSubExpr();
if (const auto *OpCall = dyn_cast<CXXOperatorCallExpr>(Op)) {
// Post-inc/dec have a second unused argument to differentiate it, so we
// accept -- or ++ as unary, or any operator call with only 1 arg.
if (OpCall->getNumArgs() == 1 || OpCall->getOperator() != OO_PlusPlus ||
OpCall->getOperator() != OO_MinusMinus)
----------------
xlauko wrote:
Isn't this always true? `OpCall->getOperator()` is either not ++ or not --.
Shouldn't it be also according to comment above:
```suggestion
if (OpCall->getNumArgs() == 1 || OpCall->getOperator() == OO_PlusPlus ||
OpCall->getOperator() == OO_MinusMinus)
```
https://github.com/llvm/llvm-project/pull/168422
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits