[PATCH] D71039: Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

2019-12-18 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

This seems to be failing on aarch64-linux-gnu:

   TEST 'Clang :: 
CodeGenCXX/mangle-ptr-size-address-space.cpp' FAILED 
  Script:
  --
  : 'RUN: at line 1';   
/b/s/w/ir/k/recipe_cleanup/clangdgOoVq/llvm_build_dir/bin/clang -cc1 
-internal-isystem 
/b/s/w/ir/k/recipe_cleanup/clangdgOoVq/llvm_build_dir/lib/clang/10.0.0/include 
-nostdsysteminc -fms-extensions -emit-llvm -triple aarch64-unknown-linux-gnu -o 
- 
/b/s/w/ir/k/llvm-project/clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
 | /b/s/w/ir/k/recipe_cleanup/clangdgOoVq/llvm_build_dir/bin/FileCheck 
/b/s/w/ir/k/llvm-project/clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
 --check-prefixes=CHECK
  : 'RUN: at line 2';   
/b/s/w/ir/k/recipe_cleanup/clangdgOoVq/llvm_build_dir/bin/clang -cc1 
-internal-isystem 
/b/s/w/ir/k/recipe_cleanup/clangdgOoVq/llvm_build_dir/lib/clang/10.0.0/include 
-nostdsysteminc -fms-extensions -emit-llvm -triple x86_64-windows-msvc -o - 
/b/s/w/ir/k/llvm-project/clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
 | /b/s/w/ir/k/recipe_cleanup/clangdgOoVq/llvm_build_dir/bin/FileCheck 
/b/s/w/ir/k/llvm-project/clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
 --check-prefixes=WIN
  --
  Exit Code: 1
  
  Command Output (stderr):
  --
  
/b/s/w/ir/k/llvm-project/clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp:8:17:
 error: CHECK-LABEL: expected string not found in input
  // CHECK-LABEL: define {{.*}}i8 addrspace(271)* @_Z2f1PU10ptr32_sptri
  ^
  :6:34: note: scanning from here
  define void @_Z2f0PU10ptr32_sptri(i32* %p) #0 {
   ^
  :13:1: note: possible intended match here
  define i8* @_Z2f1PU10ptr32_sptri(i32* %p) #0 {
  ^
  
  --
  
  

The full output is here: 
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8893704790849741184/+/steps/clang/0/steps/test/0/stdout


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71039/new/

https://reviews.llvm.org/D71039



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71039: Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

2019-12-18 Thread Amy Huang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa85f5efd9597: Add support for the MS qualifiers __ptr32, 
__ptr64, __sptr, __uptr. (authored by akhuang).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71039/new/

https://reviews.llvm.org/D71039

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/ms-mixed-ptr-sizes.c
  clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388598)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388595)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x76>();
+  correct<0x73>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/Sema/MicrosoftExtensions.c
===
--- clang/test/Sema/MicrosoftExtensions.c
+++ clang/test/Sema/MicrosoftExtensions.c
@@ -150,6 +150,20 @@
 void ptr_func2(int * __sptr __ptr32 i) {}  // expected-note {{previous definition is here}}
 void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}}
 
+// Check for warning when return types have the type attribute.
+void *__ptr32 ptr_func3() { return 0; } // expected-note {{previous definition is here}}
+void *__ptr64 ptr_func3() { return 0; } // expected-error {{redefinition of 'ptr_func3'}}
+
+// Test that __ptr32/__ptr64 can be passed as arguments with other address
+// spaces.
+void ptr_func4(int *i);
+void ptr_func5(int *__ptr32 i);
+void test_ptr_arguments() {
+  int *__ptr64 i64;
+  ptr_func4(i64);
+  ptr_func5(i64);
+}
+
 int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}}
 
 __ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
Index: clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fms-extensions -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_cc1 -fms-extensions -emit-llvm -triple x86_64-windows-msvc -o - %s | FileCheck %s --check-prefixes=WIN
+
+// CHECK-LABEL: define {{.*}}void @_Z2f0PU10ptr32_sptri
+// WIN-LABEL: define {{.*}}void @"?f0@@YAXPAH@Z"
+void f0(int * __ptr32 p) {}
+
+// CHECK-LABEL: define {{.*}}i8 addrspace(271)* @_Z2f1PU10ptr32_sptri
+// WIN-LABEL: define {{.*}}i8 addrspace(271)* @"?f1@@YAPAXPAH@Z"
+void * __ptr32 __uptr f1(int * __ptr32 p) { return 0; }
+
+// CHECK-LABEL: define {{.*}}void @_Z2f2Pi
+// WIN-LABEL: define {{.*}}void @"?f2@@YAXPEAH@Z"
+void f2(int * __ptr64 p) {}
+
+  // CHECK-LABEL: define {{.*}}i8* @_Z2f3Pi
+// WIN-LABEL: define {{.*}}i8* @"?f3@@YAPEAXPEAH@Z"
+void * __ptr64 f3(int * __ptr64 p) { return 0; }
Index: clang/test/CodeGen/ms-mixed-ptr-sizes.c
===
--- /dev/null
+++ clang/test/CodeGen/ms-mixed-ptr-sizes.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 \
+// RUN:   < %s | FileCheck %s --check-prefixes=X64,CHECK
+// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 \
+// RUN:   < %s | FileCheck %s --check-prefixes=X86,CHECK
+
+struct Foo {
+  int * __ptr32 p32;
+  int * __ptr64 p64;
+};
+void use_foo(struct Foo *f);
+void test_sign_ext(struct Foo *f, int * __ptr32 __sptr i) {
+// X64-

[PATCH] D71039: Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

2019-12-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

Looks great to me.

This has the potential to break some existing code, though. I would suggest 
either landing it early in the day, watching for breakage, and hoping for the 
best, or you could try building an application that makes significant use of 
Windows SDK headers to get more confidence that we won't have to revert it. You 
could build the `sbox_integration_tests` target in Chrome or `chrome_elf`, and 
see if that works.




Comment at: clang/lib/AST/ASTContext.cpp:2922
 
+QualType ASTContext::getFunctionTypeWithoutPtrSizes(QualType T) {
+  if (const auto *Proto = T->getAs()) {

Nice, this version is very simple.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71039/new/

https://reviews.llvm.org/D71039



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71039: Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

2019-12-16 Thread Amy Huang via Phabricator via cfe-commits
akhuang added inline comments.



Comment at: clang/include/clang/AST/Type.h:477-479
+   ((isPtrSizeAddressSpace(A) && B == LangAS::Default) ||
+(isPtrSizeAddressSpace(B) && A == LangAS::Default) ||
+(isPtrSizeAddressSpace(A) && isPtrSizeAddressSpace(B)));

rnk wrote:
> Can this be simplified to:
>   ((isPtrSizeAddressSpace(A) || A == LangAS::Default) &&
>(isPtrSizeAddressSpace(B) || B == LangAS::Default))
> Mainly I wanted to avoid recomputing isPtrSizeAddressSpace for A and B.
> 
> I think it's only not equivalent when A and B are both default, but we 
> already return true in that case.
Yes -- I think I considered doing this and then forgot that we already return 
true when A and B are both default. 



Comment at: clang/lib/Sema/SemaDecl.cpp:3156
+
+static bool HasSameFunctionTypeIgnoringPointerSizes(ASTContext &Ctx,
+QualType Old,

rnk wrote:
> I wonder if the simplest way to express this would be to follow the pattern 
> of getFunctionTypeWithExceptionSpec and 
> hasSameFunctionTypeIgnoringExceptionSpec, i.e. make a function that strips 
> pointer sized address spaces off of pointer typed arguments, returns it, and 
> then compare them. ASTContext would be a natural place for that kind of type 
> adjustment.
Done, this does make the code a bit shorter. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71039/new/

https://reviews.llvm.org/D71039



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71039: Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

2019-12-16 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 234125.
akhuang marked 8 inline comments as done.
akhuang added a comment.

- Added docs for __ptr32, __ptr64, __sptr, __utr
- Moved some functions into ASTContext
- and addressed other comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71039/new/

https://reviews.llvm.org/D71039

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/ms-mixed-ptr-sizes.c
  clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388598)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388595)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x76>();
+  correct<0x73>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/Sema/MicrosoftExtensions.c
===
--- clang/test/Sema/MicrosoftExtensions.c
+++ clang/test/Sema/MicrosoftExtensions.c
@@ -150,6 +150,20 @@
 void ptr_func2(int * __sptr __ptr32 i) {}  // expected-note {{previous definition is here}}
 void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}}
 
+// Check for warning when return types have the type attribute.
+void *__ptr32 ptr_func3() { return 0; } // expected-note {{previous definition is here}}
+void *__ptr64 ptr_func3() { return 0; } // expected-error {{redefinition of 'ptr_func3'}}
+
+// Test that __ptr32/__ptr64 can be passed as arguments with other address
+// spaces.
+void ptr_func4(int *i);
+void ptr_func5(int *__ptr32 i);
+void test_ptr_arguments() {
+  int *__ptr64 i64;
+  ptr_func4(i64);
+  ptr_func5(i64);
+}
+
 int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}}
 
 __ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
Index: clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fms-extensions -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_cc1 -fms-extensions -emit-llvm -triple x86_64-windows-msvc -o - %s | FileCheck %s --check-prefixes=WIN
+
+// CHECK-LABEL: define {{.*}}void @_Z2f0PU10ptr32_sptri
+// WIN-LABEL: define {{.*}}void @"?f0@@YAXPAH@Z"
+void f0(int * __ptr32 p) {}
+
+// CHECK-LABEL: define {{.*}}i8 addrspace(271)* @_Z2f1PU10ptr32_sptri
+// WIN-LABEL: define {{.*}}i8 addrspace(271)* @"?f1@@YAPAXPAH@Z"
+void * __ptr32 __uptr f1(int * __ptr32 p) { return 0; }
+
+// CHECK-LABEL: define {{.*}}void @_Z2f2Pi
+// WIN-LABEL: define {{.*}}void @"?f2@@YAXPEAH@Z"
+void f2(int * __ptr64 p) {}
+
+  // CHECK-LABEL: define {{.*}}i8* @_Z2f3Pi
+// WIN-LABEL: define {{.*}}i8* @"?f3@@YAPEAXPEAH@Z"
+void * __ptr64 f3(int * __ptr64 p) { return 0; }
Index: clang/test/CodeGen/ms-mixed-ptr-sizes.c
===
--- /dev/null
+++ clang/test/CodeGen/ms-mixed-ptr-sizes.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 \
+// RUN:   < %s | FileCheck %s --check-prefixes=X64,CHECK
+// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 \
+// RUN:   < %s | FileCheck %s --check-prefixes=X86,CHECK
+
+struct Foo {
+  int * __ptr32 p32;
+  int * __ptr64 p64;
+};
+void use_foo(struct Foo *f);
+void test_sign_ext(struct Foo *f,

[PATCH] D71039: Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

2019-12-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Can you also add documentation to the attribute in AttrDocs.td and hook it up 
to the attribute in Attr.td now that we're actually processing these attributes 
rather than ignoring them?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71039/new/

https://reviews.llvm.org/D71039



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71039: Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

2019-12-12 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Sorry for the delay, overall this seems like the right approach.




Comment at: clang/include/clang/AST/Type.h:477-479
+   ((isPtrSizeAddressSpace(A) && B == LangAS::Default) ||
+(isPtrSizeAddressSpace(B) && A == LangAS::Default) ||
+(isPtrSizeAddressSpace(A) && isPtrSizeAddressSpace(B)));

Can this be simplified to:
  ((isPtrSizeAddressSpace(A) || A == LangAS::Default) &&
   (isPtrSizeAddressSpace(B) || B == LangAS::Default))
Mainly I wanted to avoid recomputing isPtrSizeAddressSpace for A and B.

I think it's only not equivalent when A and B are both default, but we already 
return true in that case.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1874-1881
+case LangAS::ptr32_sptr:
+  Extra.mangleSourceName("_ASPtr32_sptr");
+  break;
+case LangAS::ptr32_uptr:
+  Extra.mangleSourceName("_ASPtr32_uptr");
+  break;
+case LangAS::ptr64:

This code should be unreachable because you check for these address spaces at 
the call site. I think you can do something like this:
  case LangAS::...:
  case LangAS::...:
  case LangAS::...:
llvm_unreachable("don't mangle ptr address spaces with _AS");



Comment at: clang/lib/AST/TypePrinter.cpp:1824
+  case LangAS::ptr32_sptr:
+OS << "__ptr32_sptr";
+break;

Think we should say `"__sptr __ptr32"`? This code doesn't guarantee that it can 
be parsed back as valid source, but it's closer.



Comment at: clang/lib/Sema/SemaDecl.cpp:3156
+
+static bool HasSameFunctionTypeIgnoringPointerSizes(ASTContext &Ctx,
+QualType Old,

I wonder if the simplest way to express this would be to follow the pattern of 
getFunctionTypeWithExceptionSpec and hasSameFunctionTypeIgnoringExceptionSpec, 
i.e. make a function that strips pointer sized address spaces off of pointer 
typed arguments, returns it, and then compare them. ASTContext would be a 
natural place for that kind of type adjustment.



Comment at: clang/lib/Sema/SemaOverload.cpp:2890
 
+static QualType RemovePtrSizeAddrSpace(ASTContext &Ctx, QualType T) {
+  if (const PointerType *Ptr = T->getAs()) {

I think it would be fair to raise this method up to ASTContext, next to 
getAddrSpaceQualType, removeAddrSpaceQualType, etc.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71039/new/

https://reviews.llvm.org/D71039



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71039: Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

2019-12-04 Thread Amy Huang via Phabricator via cfe-commits
akhuang created this revision.
akhuang added reviewers: rnk, rsmith.
Herald added subscribers: cfe-commits, nhaehnle, jvesely, jholewinski.
Herald added a project: clang.

This adds parsing of the qualifiers __ptr32, __ptr64, __sptr, and __uptr and
lowers them to the corresponding address space pointer for 32-bit and 64-bit 
pointers.
(32/64-bit pointers added in https://reviews.llvm.org/D69639)

A large part of this patch is making these pointers ignore the address space
when doing things like overloading and casting.

https://bugs.llvm.org/show_bug.cgi?id=42359


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71039

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/ms-mixed-ptr-sizes.c
  clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388598)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388595)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x76>();
+  correct<0x73>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/Sema/MicrosoftExtensions.c
===
--- clang/test/Sema/MicrosoftExtensions.c
+++ clang/test/Sema/MicrosoftExtensions.c
@@ -150,6 +150,20 @@
 void ptr_func2(int * __sptr __ptr32 i) {}  // expected-note {{previous definition is here}}
 void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}}
 
+// Check for warning when return types have the type attribute.
+void *__ptr32 ptr_func3() { return 0; } // expected-note {{previous definition is here}}
+void *__ptr64 ptr_func3() { return 0; } // expected-error {{redefinition of 'ptr_func3'}}
+
+// Test that __ptr32/__ptr64 can be passed as arguments with other address
+// spaces.
+void ptr_func4(int *i);
+void ptr_func5(int *__ptr32 i);
+void test_ptr_arguments() {
+  int *__ptr64 i64;
+  ptr_func4(i64);
+  ptr_func5(i64);
+}
+
 int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}}
 
 __ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
Index: clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fms-extensions -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_cc1 -fms-extensions -emit-llvm -triple x86_64-windows-msvc -o - %s | FileCheck %s --check-prefixes=WIN
+
+// CHECK-LABEL: define {{.*}}void @_Z2f0PU10ptr32_sptri
+// WIN-LABEL: define {{.*}}void @"?f0@@YAXPAH@Z"
+void f0(int * __ptr32 p) {}
+
+// CHECK-LABEL: define {{.*}}i8 addrspace(271)* @_Z2f1PU10ptr32_sptri
+// WIN-LABEL: define {{.*}}i8 addrspace(271)* @"?f1@@YAPAXPAH@Z"
+void * __ptr32 __uptr f1(int * __ptr32 p) { return 0; }
+
+// CHECK-LABEL: define {{.*}}void @_Z2f2Pi
+// WIN-LABEL: define {{.*}}void @"?f2@@YAXPEAH@Z"
+void f2(int * __ptr64 p) {}
+
+  // CHECK-LABEL: define {{.*}}i8* @_Z2f3Pi
+// WIN-LABEL: define {{.*}}i8* @"?f3@@YAPEAXPEAH@Z"
+void * __ptr64 f3(int * __ptr64 p) { return 0; }
Index: clang/test/CodeGen/ms-mixed-ptr-sizes.c
===
--- /dev/null
+++ clang/test/CodeGen/ms-mixed-ptr-sizes.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 \
+// RUN:   < %s | FileCheck %s --check-prefixes=X64,CHECK
+// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 \
+// RUN:   < %s | FileCheck %s