Use the target address space value when mangling names.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174688 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp
index 792bda6..dadf9d3 100644
--- a/lib/AST/ItaniumMangle.cpp
+++ b/lib/AST/ItaniumMangle.cpp
@@ -1668,7 +1668,8 @@
     // where <address-space-number> is a source name consisting of 'AS' 
     // followed by the address space <number>.
     SmallString<64> ASString;
-    ASString = "AS" + llvm::utostr_32(Quals.getAddressSpace());
+    ASString = "AS" + llvm::utostr_32(
+        Context.getASTContext().getTargetAddressSpace(Quals.getAddressSpace()));
     Out << 'U' << ASString.size() << ASString;
   }
   
diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp
index 5dad030..e7955a8 100644
--- a/test/CodeGenCXX/mangle.cpp
+++ b/test/CodeGenCXX/mangle.cpp
@@ -872,3 +872,6 @@
     func(foo().d);
   }
 }
+
+// CHECK: define void @_Z6ASfuncPU3AS3i
+void ASfunc(__attribute__((address_space(3))) int* x) {}
diff --git a/test/CodeGenOpenCL/local.cl b/test/CodeGenOpenCL/local.cl
index 32fa7be..b4bd008 100644
--- a/test/CodeGenOpenCL/local.cl
+++ b/test/CodeGenOpenCL/local.cl
@@ -5,3 +5,8 @@
   __local int i;
   ++i;
 }
+
+// CHECK: define void @_Z3barPU3AS2i
+__kernel void __attribute__((__overloadable__)) bar(local int *x) {
+  *x = 5;
+}