[PATCH] D62156: [Sema] Diagnose addr space mismatch while constructing objects

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 20 11:21:35 PDT 2019


Anastasia created this revision.
Anastasia added a reviewer: rjmccall.
Herald added a subscriber: ebevhan.
Anastasia edited the summary of this revision.
Anastasia marked 3 inline comments as done.
Anastasia added inline comments.


================
Comment at: lib/Sema/SemaInit.cpp:3771
     else {
-      // C++ [over.match.copy]p1:
-      //   - When initializing a temporary to be bound to the first parameter
-      //     of a constructor [for type T] that takes a reference to possibly
-      //     cv-qualified T as its first argument, called with a single
-      //     argument in the context of direct-initialization, explicit
-      //     conversion functions are also considered.
-      // FIXME: What if a constructor template instantiates to such a signature?
-      bool AllowExplicitConv = AllowExplicit && !CopyInitializing &&
-                               Args.size() == 1 &&
-                               hasCopyOrMoveCtorParam(S.Context, Info);
-      S.AddOverloadCandidate(Info.Constructor, Info.FoundDecl, Args,
-                             CandidateSet, SuppressUserConversions,
-                             /*PartialOverloading=*/false,
-                             /*AllowExplicit=*/AllowExplicitConv);
+      // Check that address space match to resolve the constructors correctly.
+      if (Info.Constructor->getMethodQualifiers().isAddressSpaceSupersetOf(
----------------
matches


================
Comment at: lib/Sema/SemaInit.cpp:5023
           else
+              // Check that address space match to resolve the constructors
+              // correctly.
----------------
matches


================
Comment at: test/CodeGenOpenCLCXX/addrspace-ctor.cl:7
+  int i;
+  void bar();
+};
----------------
remove unused bar


If we construct an object in some arbitrary non-default addr space it should fail unless either:

1. There is an implicit conversion from the address space to default/generic address space.
2. There is a matching ctor qualified with an address space that is either exactly matching or convertible to the address space of an object.

Example - case 1:

  struct MyType {
     MyType(int i)  : i(i) {}
     int i;
   };
  __constant MyType m(1); // error: can't convert from __constant to __generic

Example - case 2:

  struct MyType {
     MyType(int i) __constant  : i(i) {}
     MyType(int i)  : i(i) {}
     int i;
   };
  __constant MyType c(1); // there is __constant qualified ctor
  __global MyType g(1); // there is a valid conversion between __global and __generic




https://reviews.llvm.org/D62156

Files:
  include/clang/Sema/DeclSpec.h
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaInit.cpp
  test/CodeGenCXX/address-space-of-this.cpp
  test/CodeGenOpenCLCXX/addrspace-ctor.cl
  test/SemaCXX/address-space-ctor.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62156.200338.patch
Type: text/x-patch
Size: 6951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190520/df4e2db6/attachment.bin>


More information about the cfe-commits mailing list