[PATCH] D72811: [WIP][OPENMP5.0] allow lvalue for motion clause

Alexey Bataev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 21 13:37:54 PST 2020


ABataev added inline comments.


================
Comment at: clang/lib/Sema/SemaOpenMP.cpp:15442-15443
+      CurComponents.emplace_back(CurE, nullptr);
+    } else if (auto *CurE = dyn_cast<BinaryOperator>(E)) {
+      E = CurE->getLHS()->IgnoreParenImpCasts();
     } else {
----------------
cchen wrote:
> cchen wrote:
> > ABataev wrote:
> > > cchen wrote:
> > > > ABataev wrote:
> > > > > cchen wrote:
> > > > > > cchen wrote:
> > > > > > > ABataev wrote:
> > > > > > > > Why just the LHS is analyzed? Also, what about support for other expressions, like casting, call, choose etc., which may result in lvalue?
> > > > > > > 1. LHS: I'll fix that
> > > > > > > 2. I'll add support for casting, call, etc
> > > > > > > 3. For "choose" are you referring to something like (a < b ? b : a)?
> > > > > > For the handling of BinaryOperator, I'm not sure why should we handle RHS since the possible source code I can imagine is `*(ptr+l)` or something like `(ptr+l)[3]`.
> > > > > `*(2+ptr)` is correct too. And, btw, `3[ptr+1]` too, especially in C. Moreover, something like `*(b+c)` is also allowed. That's why I said that better to avoid deep analysis of lvalues, there are too many combinations and better to switch to something basic.
> > > > But at least we need the base declaration for motion/map clause, right? And to achieve this, we need to peel the expression to get the DeclRefExpr.
> > > What's the base declaration in `*(a+b)`?
> > I understand your point, I'm just not sure how to handle (do not analyze) this given that we need to fill VarDecl for OMPToClause/OMPFromClause.
> But is *(a+b) even valid? Clang and GCC both emit error message: https://godbolt.org/z/jqDBx_
Yes, in this form it is not. But here is another form `*(a+*b)` or `*(a+(unsigned long long)b)`. You an try to filter rvalues out of all these forms, though and still try to find a base decl. But still, there are going to be some cases where you won't be possible to handle them correctly, like `foo()`.
If you still want to dig that deep, I would recommend to use RecursiseStmtVisitor. If an expression is rvalue - throw it out of analysis. If base decl is not single, not variable and not member decl - emit an error.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72811/new/

https://reviews.llvm.org/D72811





More information about the cfe-commits mailing list