<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61027>61027</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[OpenMP] Compiler crashes when using `use_device_ptr` in an inheriting class
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jhuber6
</td>
</tr>
</table>
<pre>
Currently, we crash on an assertion when we try to use a member from a parent class. This is caused by an assertion that the initializer of the variable is a `this` clause, which isn't true in this case as it is actually a cast.
```
class A {
public:
double *ptr;
virtual void foo() = 0;
};
class B : public A {
public:
virtual void foo() override;
};
void B::foo() {
#pragma omp target data use_device_ptr(A::ptr)
{}
}
```
```
$ clang bug.cpp -fopenmp --offload-arch=sm_80 --offload-device-only -S -emit-llvm -o -
clang-17: /root/llvm-project/clang/lib/CodeGen/CGStmtOpenMP.cpp:7149: void clang::CodeGen::CodeGenFunction::EmitOMPUseDevicePtrClause(const clang::OMPUseDevicePtrClause&, clang::CodeGen::CodeGenFunction::OMPPrivateScope&, const llvm::DenseMap<const clang::ValueDecl*, clang::CodeGen::Address>&): Assertion `isa<CXXThisExpr>(ME->getBase()) && "Base should be the current struct!"' failed.
```
The AST dump for the problematic expression shows
```
MemberExpr 0x5558ae7245b0 'double *' lvalue ->ptr 0x5558ae7053d0
`-ImplicitCastExpr 0x5558ae724590 'class A *' <UncheckedDerivedToBase (A)>
`-CXXThisExpr 0x5558ae724580 'class B *' implicit this
```
This bug is reproducible from the following link https://godbolt.org/z/Kand715qs.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVV1v2zgQ_DX0y0KGTFkffvCDbcXF4RA0QNJD3wpKXFlsKVJHUk7TX39YykncNg1wgGGI1HJmOFwNhffqZBC3LN-zvF6IKfTWbb_2U4OuWDRWPm0Pk3Nogn5i_ACPCK0TvgdrQBgQ3qMLyhp47NHQ2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