On Tue, Feb 19, 2013 at 3:44 PM, Matt Arsenault <span dir="ltr"><<a href="mailto:whatmannerofburgeristhis@gmail.com" target="_blank">whatmannerofburgeristhis@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I encountered this error when trying to use address_space when compiling as C++, but not C.<br>
<br>
// No error<br>
__attribute__((address_space(42)))<br>
const float withc = 1.0f;<br>
<br>
// No error<br>
__attribute__((address_space(42)))<br>
volatile float withv = 1.0f;<br>
<br>
// Error<br>
__attribute__((address_space(42)))<br>
float nocv = 1.0f;<br>
<br>
<br>
This would produce the error:<br>
<br>
as_initializer.cpp:12:7: error: cannot initialize a variable of type<br>
      '__attribute__((address_space(42))) float' with an rvalue of type 'float'<br>
float nocv = 1.0f;<br>
      ^      ~~~~<br>
1 error generated.<br>
<br>
This patch adds a test for this case, and allows the conversion if the address spaces are different for non-pointer types. I'm not really familiar with the code so I'm not particularly confident that this is the correct fix. Please review!<br>

<br>
<a href="http://llvm-reviews.chandlerc.com/D426" target="_blank">http://llvm-reviews.chandlerc.com/D426</a><br>
<br>
Files:<br>
  lib/Sema/SemaOverload.cpp<br>
  test/SemaCXX/address-space-initialize.cpp<br>
<br>
Index: lib/Sema/SemaOverload.cpp<br>
===================================================================<br>
--- lib/Sema/SemaOverload.cpp<br>
+++ lib/Sema/SemaOverload.cpp<br>
@@ -1678,7 +1678,7 @@<br>
         (CanonFrom.getLocalCVRQualifiers() != CanonTo.getLocalCVRQualifiers()<br>
          || CanonFrom.getObjCGCAttr() != CanonTo.getObjCGCAttr()<br>
          || CanonFrom.getObjCLifetime() != CanonTo.getObjCLifetime()<br>
-         || (CanonFrom->isSamplerT() &&<br>
+         || (!CanonFrom->isAnyPointerType() &&<br></blockquote><div><br></div><div>Why should this not apply for pointer types? If I have a pointer-to-default-address-space in address space 42, I would think I should be able to initialize that with a pointer-to-default-address-space. I think that would make this whole check be just</div>
<div><br></div><div>  CanonFrom.getLocalUnqualifiedType() == CanonTo.getLocalUnqualifiedType() &&</div><div>  CanonFrom.getLocalQualifiers() != CanonTo.getLocalQualifiers()</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

            CanonFrom.getAddressSpace() != CanonTo.getAddressSpace()))) {<br>
       FromType = ToType;<br>
       CanonFrom = CanonTo;<br>
Index: test/SemaCXX/address-space-initialize.cpp<br>
===================================================================<br>
--- /dev/null<br>
+++ test/SemaCXX/address-space-initialize.cpp<br>
@@ -0,0 +1,24 @@<br>
+// RUN: %clang_cc1 -fsyntax-only -verify %s<br>
+<br>
+<br>
+__attribute__((address_space(42)))<br>
+const float withc = 1.0f;<br>
+<br>
+__attribute__((address_space(42)))<br>
+volatile float withv = 1.0f;<br>
+<br>
+__attribute__((address_space(42)))<br>
+float nocv = 1.0f;<br>
+<br>
+__attribute__((address_space(42)))<br>
+float nocv_array[10] = { 1.0f };<br>
+<br>
+__attribute__((address_space(42)))<br>
+int nocv_iarray[10] = { 4 };<br>
+<br>
+<br>
+__attribute__((address_space(9999)))<br>
+int* as_ptr = nocv_iarray; // expected-error{{cannot initialize a variable of type '__attribute__((address_space(9999))) int *' with an lvalue of type '__attribute__((address_space(42))) int [10]'}}<br>
+<br>
+<br>
+<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br>