[PATCH] D83922: [OpenMP] Fix map clause for unused var: don't ignore it

Alexey Bataev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 17 07:48:16 PDT 2020


ABataev added inline comments.


================
Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9470-9471
+          MappedVarSet.insert(CI->getCapturedVar()->getCanonicalDecl());
+        else
+          MappedVarSet.insert(nullptr);
         if (CurBasePointers.empty())
----------------
jdenny wrote:
> ABataev wrote:
> > jdenny wrote:
> > > ABataev wrote:
> > > > No need to insert `nullptr` here, it is not used later.
> > > Without this `nulltpr` insertion, many tests fail because of duplicate map entries.  Independently of my patch, `nulltptr` is used to indicate `this` capture (see the `generateInfoForCapture` implementation) .
> > > 
> > > For example:
> > > 
> > > ```
> > > struct S {
> > >   int i;
> > >   void foo() {
> > >     #pragma omp target map(i)
> > >     i = 5;
> > >   }
> > > };
> > > ```
> > > 
> > > We should have:
> > > 
> > > ```
> > > @.offload_maptypes = private unnamed_addr constant [2 x i64] [i64 32, i64 281474976710659]
> > > ```
> > > 
> > > Without the `nullptr` insertion, we have:
> > > 
> > > ```
> > > @.offload_maptypes = private unnamed_addr constant [4 x i64] [i64 32, i64 281474976710659, i64 32, i64 844424930131971]
> > > ```
> > This is strange, because you don't check for `nullptr`. You only check for `ValueDecl`s, but not capture of `this`.
> I'm not sure what code you're referring to when you say "you check".
> 
> Both with and without my patch, my understanding is that `nullptr` is a special key that means `this`.  I'm depending on that to avoid generating map entries twice for `this`.
> 
> My understanding is based on the way `generateInfoForCapture` works.  If `Cap->capturesThis()`, then `VD = nullptr`.  That `VD` is then used by `C->decl_component_lists(VD)` to find entries for `this` in map clauses.
> 
> Unless I'm misreading it, the code that sets `nullptr` for `this` in decl components is `checkMappableExpressionList` in SemaOpenMP.cpp.  The last few lines of that function have a comment to this effect.  (That comment would probably be more useful in a header file somewhere.)
`MappedVarSet` is a new variable, right? It is used only in 2 places: here, where you add elements to this set, and in `generateAllInfo` where you have a check:
```
if (SkipVarSet.count(VD))
            return;
```
I don't see other places where it is used. And I don't see places where you check for the presence of `nullptr` in this set. That's why I think you don't need to add it, if you don't check for its presence later.


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

https://reviews.llvm.org/D83922





More information about the cfe-commits mailing list