[PATCH] D64569: [OpenCL] Improve destructor support in C++ for OpenCL

Marco Antognini via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 11 09:16:51 PDT 2019


mantognini created this revision.
Herald added subscribers: cfe-commits, Anastasia, yaxunl.
Herald added a project: clang.

This patch does mainly three things:

1. It fixes a false positive error detection in Sema that is similar to D62156 <https://reviews.llvm.org/D62156>. The error happens when explicitly calling an overloaded destructor for different address spaces.
2. It selects the correct destructor when multiple overloads for address spaces are available.
3. It inserts the expected address space cast when invoking a destructor, if needed, and therefore fixes a crash due to the unmet assertion in llvm::CastInst::Create.

The following is a reproducer of the three issues:

  struct MyType {
    ~MyType() {}
    ~MyType() __constant {}
  };
  
  __constant MyType myGlobal{};
  
  kernel void foo() {
    myGlobal.~MyType(); // 1 and 2.
    // 1. error: cannot initialize object parameter of type
    //    '__generic MyType' with an expression of type '__constant MyType'
    // 2. error: no matching member function for call to '~MyType'
  }
  
  kernel void bar() {
    // 3. The implicit call to the destructor crashes due to:
    //    Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.
    //    in llvm::CastInst::Create.
    MyType myLocal;
  }

The added test depends on D62413 <https://reviews.llvm.org/D62413> and covers a few more things than the
above reproducer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64569

Files:
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-ctor.cl
  clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64569.209245.patch
Type: text/x-patch
Size: 15607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190711/064c6f4f/attachment.bin>


More information about the cfe-commits mailing list