Fix initializer for variables with attribute address_space set.
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 26 Feb 2013 21:15:54 +0000 (21:15 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 26 Feb 2013 21:15:54 +0000 (21:15 +0000)
This would error in C++ mode unless the variable also had a cv
qualifier.

e.g.

__attribute__((address_space(2))) float foo = 1.0f; would error but
__attribute__((address_space(2))) const float foo = 1.0f; would not.

llvm-svn: 176121

clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/address-space-initialize.cpp [new file with mode: 0644]

index 9bba5f6..16fd28e 100644 (file)
@@ -1667,11 +1667,7 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType,
     CanonTo = S.Context.getCanonicalType(ToType);
     if (CanonFrom.getLocalUnqualifiedType()
                                        == CanonTo.getLocalUnqualifiedType() &&
-        (CanonFrom.getLocalCVRQualifiers() != CanonTo.getLocalCVRQualifiers()
-         || CanonFrom.getObjCGCAttr() != CanonTo.getObjCGCAttr()
-         || CanonFrom.getObjCLifetime() != CanonTo.getObjCLifetime()
-         || (CanonFrom->isSamplerT() && 
-           CanonFrom.getAddressSpace() != CanonTo.getAddressSpace()))) {
+        CanonFrom.getLocalQualifiers() != CanonTo.getLocalQualifiers()) {
       FromType = ToType;
       CanonFrom = CanonTo;
     }
diff --git a/clang/test/SemaCXX/address-space-initialize.cpp b/clang/test/SemaCXX/address-space-initialize.cpp
new file mode 100644 (file)
index 0000000..5091338
--- /dev/null
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+__attribute__((address_space(42)))
+const float withc = 1.0f;
+
+__attribute__((address_space(42)))
+volatile float withv = 1.0f;
+
+__attribute__((address_space(42)))
+float nocv = 1.0f;
+
+__attribute__((address_space(42)))
+float nocv_array[10] = { 1.0f };
+
+__attribute__((address_space(42)))
+int nocv_iarray[10] = { 4 };
+
+
+__attribute__((address_space(9999)))
+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]'}}
+
+
+__attribute__((address_space(42))) int* __attribute__((address_space(42))) ptr_in_same_addr_space = nocv_iarray;
+__attribute__((address_space(42))) int* __attribute__((address_space(999))) ptr_in_different_addr_space = nocv_iarray;
+