Preserve address space information through member accesses, e.g.,  
   __attribute__((address_space(1))) struct {int arr[ 3 ]; }  *p1;
   ... = p1->arr[2];  // load from address space 1

llvm-svn: 76717
diff --git a/clang/test/CodeGen/address-space-field1.c b/clang/test/CodeGen/address-space-field1.c
new file mode 100644
index 0000000..e7c655a
--- /dev/null
+++ b/clang/test/CodeGen/address-space-field1.c
@@ -0,0 +1,20 @@
+// RUN: clang-cc -emit-llvm < %s -o %t &&
+// RUN: grep addrspace\(1\) %t | count 9 &&
+// RUN: grep addrspace\(2\) %t | count 9
+
+// Check that we don't lose the address space when accessing a member
+// of a structure.
+
+#define __addr1    __attribute__((address_space(1)))
+#define __addr2    __attribute__((address_space(2)))
+
+typedef struct S {
+  int a;
+  int b;
+} S;
+
+void test_addrspace(__addr1 S* p1, __addr2 S*p2) {
+  // swap
+  p1->a = p2->b;
+  p1->b = p2->a;
+}
diff --git a/clang/test/CodeGen/address-space-field2.c b/clang/test/CodeGen/address-space-field2.c
new file mode 100644
index 0000000..8b09d57
--- /dev/null
+++ b/clang/test/CodeGen/address-space-field2.c
@@ -0,0 +1,22 @@
+// RUN: clang-cc -emit-llvm < %s -o %t &&
+// RUN: grep addrspace\(1\) %t | count 8 &&
+// RUN: grep addrspace\(2\) %t | count 9
+
+// Check that we don't lose the address space when accessing an array element
+// inside a structure.
+
+#define __addr1    __attribute__((address_space(1)))
+#define __addr2    __attribute__((address_space(2)))
+
+typedef struct S {
+  int arr[ 3 ];
+} S;
+
+void test_addrspace(__addr1 S* p1, __addr2 S*p2, int* val, int n) {
+  for (int i=0; i < 3; ++i) {
+    int t = val[i];
+    p1->arr[i] = t;
+    for (int j=0; j < n; ++j)
+      p2[j].arr[i] = t;
+  }
+}
diff --git a/clang/test/CodeGen/address-space-field3.c b/clang/test/CodeGen/address-space-field3.c
new file mode 100644
index 0000000..f0b9dba
--- /dev/null
+++ b/clang/test/CodeGen/address-space-field3.c
@@ -0,0 +1,20 @@
+// RUN: clang-cc -emit-llvm < %s -o %t &&
+// RUN: grep addrspace\(1\) %t | count 8 &&
+// RUN: grep addrspace\(2\) %t | count 8
+
+// Check that we don't lose the address space when accessing an array element
+// inside a structure.
+
+#define __addr1    __attribute__((address_space(1)))
+#define __addr2    __attribute__((address_space(2)))
+
+typedef struct S {
+  int arr[ 3 ];
+} S;
+
+void test_addrspace(__addr1 S* p1, __addr2 S*p2, int* val, int n) {
+  for (int i=0; i < 3; ++i) {
+    int t = val[i];
+    p1->arr[i] = p2->arr[i];
+  }
+}
diff --git a/clang/test/CodeGen/address-space-field4.c b/clang/test/CodeGen/address-space-field4.c
new file mode 100644
index 0000000..d258f61
--- /dev/null
+++ b/clang/test/CodeGen/address-space-field4.c
@@ -0,0 +1,23 @@
+// RUN: clang-cc -emit-llvm < %s -o %t &&
+// RUN: grep addrspace\(2\) %t | count 4
+// RUN: grep addrspace\(3\) %t | count 4
+
+// Check the load and store are using the correct address space to access
+// the variables.
+
+#define __addr1    __attribute__((address_space(1)))
+#define __addr2    __attribute__((address_space(2)))
+#define __addr3    __attribute__((address_space(3)))
+
+typedef struct Pair {
+  __addr2 int* a;
+  __addr3 int* b;
+} Pair;
+
+typedef struct S {
+  Pair arr[ 3 ];
+} S;
+
+void test_addrspace(__addr1 S* p1, __addr1 S* p2) {
+  *p1->arr[0].a = *p2->arr[1].b;
+}