Fix initializer for variables with attribute address_space set.

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
This commit is contained in:
Matt Arsenault 2013-02-26 21:15:54 +00:00
parent 5222195831
commit 7d36c01747
2 changed files with 26 additions and 5 deletions

View 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;
}

View File

@ -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;