Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenMP] Compiler crashes when using use_device_ptr in an inheriting class #61027

Closed
jhuber6 opened this issue Feb 27, 2023 · 3 comments
Closed
Assignees
Labels
clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] openmp

Comments

@jhuber6
Copy link
Contributor

jhuber6 commented Feb 27, 2023

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.

@jhuber6 jhuber6 self-assigned this Feb 27, 2023
@EugeneZelenko EugeneZelenko added openmp clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Feb 27, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 27, 2023

@llvm/issue-subscribers-clang-codegen

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 27, 2023

@llvm/issue-subscribers-openmp

@jhuber6
Copy link
Contributor Author

jhuber6 commented Feb 27, 2023

Proposed fix https://reviews.llvm.org/D144873

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] openmp
Projects
None yet
Development

No branches or pull requests

3 participants