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

2019-12-05 Thread Amy Huang via Phabricator via cfe-commits
akhuang abandoned this revision.
akhuang added a comment.

I split this into two reviews-- the backend part 
 is landed and the frontend part 
 is at https://reviews.llvm.org/D71039.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827



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


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

2019-10-30 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

I split off the backend changes into a separate patch -> 
https://reviews.llvm.org/D69639
The issue with passing 0 for a pointer should be fixed there.

@DarkShadow44 
Some of the differences come from the fact that we're implementing the mixed 
pointer sizes with three address spaces, which get printed out as 
`__ptr32_sptr`, `__ptr32_uptr`, and `__ptr64`. So they are intended but maybe 
also confusing.

> __ptr32_sptr doesn't exist and seems wrong

In this case it picks the address space __ptr32_sptr because it does sign 
extension by default.

> The __ptr32 part should be right of the asterisk

I think this happens because address spaces are attached to the pointee type 
and not the pointer.

> Why does PINT64 have PINT64 as type, but PINT32 not PINT32?

I'm not sure why this happens, but I can look into it later. It makes sense 
that PINT64 would work as it did before because on a 64-bit system adding 
__ptr64 doesn't do anything.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827



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


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

2019-10-17 Thread Fabian Maurer via Phabricator via cfe-commits
DarkShadow44 added a comment.

@akhuang Thanks for looking into this!

I've found something else, I've written a small dumper to demonstrate. Pardon 
the long comment please.

Program:

  typedef int* __ptr32 PINT32;
  typedef int* PINT64;
  
  struct s1
  {
PINT32 i32;
PINT64 i64;
  };

AST:

  Kind: 'TranslationUnit(300)', Type: '', Name: 
'/home/fabian/Programming/Wine/wine-git/tools/test.c'
  Kind: 'TypedefDecl(20)', Type: '__ptr32_sptr int *', Name: 'PINT32'
  Kind: 'TypedefDecl(20)', Type: 'PINT64', Name: 'PINT64'
  Kind: 'StructDecl(2)', Type: 'struct s1', Name: 's1'
  Kind: 'FieldDecl(6)', Type: '__ptr32_sptr int *', Name: 'i32'
  Kind: 'TypeRef(43)', Type: '__ptr32_sptr int *', 
Name: 'PINT32'
  Kind: 'FieldDecl(6)', Type: 'PINT64', Name: 'i64'
  Kind: 'TypeRef(43)', Type: 'PINT64', Name: 'PINT64'

Note the difference between

  Type: '__ptr32_sptr int *', Name: 'PINT32'
  Type: 'PINT64', Name: 'PINT64'

3 Issues I have here:

- __ptr32_sptr doesn't exist and seems wrong
- The __ptr32 part should be right of the asterisk
- Why does PINT64 have PINT64 as type, but PINT32 not PINT32?

I'm not sure if this is/should still be part of this patchset or even is an 
issue, just pointing out inconsistencies I noticed - hope I'm not a bother.

Dumper attached, for convenience.
F10298035: dumper.cpp 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827



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


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

2019-10-16 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

@DarkShadow44 Thanks for finding this bug! I haven't had time to look at this 
for a while but will start working on it soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827



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


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

2019-10-14 Thread Fabian Maurer via Phabricator via cfe-commits
DarkShadow44 added a comment.

@akhuang 
Any update on this? I'd love to see this upstreamed. I'd offer to help, but I'm 
not well versed in clang.

FWIW, I also found a small bug when using this patchset:

  void func1(void * __ptr32 test) { 
  }
  int main() {
func1(0);
return 0;
  }

gives

  fatal error: error in backend: Cannot emit physreg copy instruction

This only happens when passing a 0. If you pass 1, for example, it gives a 
warning (because of no cast) but compiles.
Tested against MSCV, which compiles the code without problems.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827



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


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

2019-09-04 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 218795.
akhuang added a comment.

- Change existing tests so they still pass
- Fix so that it parses all the __ptr32/64 attributes instead of just the last 
one


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827

Files:
  clang/include/clang/AST/ASTContext.h
  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/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/ms-mixed-ptr-sizes.c
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/SemaTemplate/address_space-dependent.cpp
  llvm/lib/Target/X86/X86.h
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/mixed-ptr-sizes.ll

Index: llvm/test/CodeGen/X86/mixed-ptr-sizes.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/mixed-ptr-sizes.ll
@@ -0,0 +1,110 @@
+; RUN: llc < %s | FileCheck --check-prefixes=CHECK %s
+
+; Source to regenerate:
+; struct Foo {
+;   int * __ptr32 p32;
+;   int * __ptr64 p64;
+; }
+; void test_sign_ext(struct Foo *f, int * __ptr32 i) {
+;   f->p64 = i;
+; }
+; void test_sign_ext2(struct Foo *f, int * __ptr32 __sptr i) {
+;   f->p64 = i;
+; }
+; void test_zero_ext(struct Foo *f, int * __ptr32 __uptr i) {
+;   f->p64 = i;
+; }
+; void test_trunc(struct Foo *f, int * __ptr64 i) {
+;   f->p32 = i;
+; }
+; void test_noop1(struct Foo *f, int * __ptr32 i) {
+;   f->p32 = i;
+; }
+; void test_noop2(struct Foo *f, int * __ptr64 i) {
+;   f->p64 = i;
+; }
+;
+; $ clang -cc1 -triple x86_64-windows-msvc -fms-extensions -O2 -emit-llvm -x c t.cpp
+
+; ModuleID = 't.cpp'
+source_filename = "t.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc"
+
+%struct.Foo = type { i32 addrspace(270)*, i32* }
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_sign_ext(%struct.Foo* nocapture %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_sign_ext:
+; CHECK:   movslq %edx, %rax
+entry:
+  %0 = addrspacecast i32 addrspace(270)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_sign_ext2(%struct.Foo* nocapture %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_sign_ext2:
+; CHECK:   movslq %edx, %rax
+entry:
+  %0 = addrspacecast i32 addrspace(270)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_zero_ext(%struct.Foo* nocapture %f, i32 addrspace(271)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_zero_ext:
+; CHECK:   movl %edx, %eax
+entry:
+  %0 = addrspacecast i32 addrspace(271)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_trunc(%struct.Foo* nocapture %f, i32* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_trunc:
+; CHECK:   movl %edx, (%rcx)
+entry:
+  %0 = addrspacecast i32* %i to i32 addrspace(270)*
+  %p32 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 0
+  store i32 addrspace(270)* %0, i32 addrspace(270)** %p32, align 8, !tbaa !7
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_noop1(%struct.Foo* nocapture %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_noop1:
+; CHECK:   movl %edx, (%rcx)
+entry:
+  %p32 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 0
+  store i32 addrspace(270)* %i, i32 addrspace(270)** %p32, align 8, !tbaa !7
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_noop2(%struct.Foo* nocapture %f, i32* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_noop2:
+; CHECK:   movq %rdx, 8(%rcx)
+entry:
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %i, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+!0 = !{i32 1, !"wchar_size", i32 2}
+!1 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git b4887f121b485fb2b6d4c1fa8296724fb78a244d)"}
+!2 

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

2019-09-04 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1718
  QualType PointeeType) 
{
-  if (PointersAre64Bit &&
-  (PointeeType.isNull() || !PointeeType->isFunctionType()))
+  // Check if this is a defulat 64-bit pointer or has __ptr64 qualifier.
+  bool is64Bit = PointeeType.isNull() ? PointersAre64Bit :

defulat -> default


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827



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


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

2019-08-29 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked 2 inline comments as done.
akhuang added inline comments.



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

rnk wrote:
> Hm, we should actually mangle these as they do. See the FIXME comment above 
> the definition of `PointersAre64Bit`. If you look at the uses of 
> PointersAre64Bit, you should be able to find the places where you need to 
> check if a pointer type is either in the explicit 64-bit address space or in 
> the default address space for a 64-bit target. That check sounds like a good 
> helper function.
Added a function to check for 64-bit address space / default 64-bit pointer. I 
also changed it so that the pointer size address spaces mangle as normal types 
and not address space types. 



Comment at: clang/lib/Sema/SemaOverload.cpp:2874
  N->getUnqualifiedType())) {
+  const PointerType *OldTypePtr =
+  dyn_cast(O->getUnqualifiedType());

rnk wrote:
> This probably deserves a comment. It looks like this lets you do this:
> ```
> void foo(int *__ptr64);
> void foo(int *p) { } // assume x64 target
> ```
> ... without having the compiler think it's creating an overload.
> 
> Separately, MSVC doesn't permit `__ptr32/__ptr64` overloads. Is it possible 
> to implement that here as well?
Comment added. 

Although I think that for 
```
void foo(int *__ptr64);
void foo(int *p) { } // assume x64 target
```
this code doesn't affect the overload because `int * __ptr64` and `int *` are 
already the same type?

As far as I can tell this also doesn't allow `__ptr32/__ptr64` overloads, 
because it counts them as the same type. It gives a "conflicting types" error 
instead of a "redefintion" error though, so I'll look into that. 



Comment at: llvm/test/CodeGen/X86/mixed-ptr-sizes.ll:11
+;   f->p64 = i;
+;   use_foo(f);
+; }

rnk wrote:
> Do you need use_foo? I think `f` is a parameter, so the compiler can't remove 
> any stores to it, even without a call to use it. You should be able to 
> simplify the test to skip these calls.
Deleted `use_foo`, thanks.



Comment at: llvm/test/CodeGen/X86/mixed-ptr-sizes.ll:30
+;
+; $ clang -cc1 -triple x86_64-windows-msvc -fms-extensions -O2 -S t.cpp
+

rnk wrote:
> If you compile this code as plain C code, then it won't have as much name 
> mangling, which makes the .ll file more readable.
done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827



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


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

2019-08-29 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 217940.
akhuang marked 4 inline comments as done.
akhuang added a comment.

- Test that codegen adds the correct address spaces
- Modify microsoft mangling to match microsoft mangling.
- add comment for overloading


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827

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/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/ms-mixed-ptr-sizes.c
  llvm/lib/Target/X86/X86.h
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/mixed-ptr-sizes.ll

Index: llvm/test/CodeGen/X86/mixed-ptr-sizes.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/mixed-ptr-sizes.ll
@@ -0,0 +1,110 @@
+; RUN: llc < %s | FileCheck --check-prefixes=CHECK %s
+
+; Source to regenerate:
+; struct Foo {
+;   int * __ptr32 p32;
+;   int * __ptr64 p64;
+; }
+; void test_sign_ext(struct Foo *f, int * __ptr32 i) {
+;   f->p64 = i;
+; }
+; void test_sign_ext2(struct Foo *f, int * __ptr32 __sptr i) {
+;   f->p64 = i;
+; }
+; void test_zero_ext(struct Foo *f, int * __ptr32 __uptr i) {
+;   f->p64 = i;
+; }
+; void test_trunc(struct Foo *f, int * __ptr64 i) {
+;   f->p32 = i;
+; }
+; void test_noop1(struct Foo *f, int * __ptr32 i) {
+;   f->p32 = i;
+; }
+; void test_noop2(struct Foo *f, int * __ptr64 i) {
+;   f->p64 = i;
+; }
+;
+; $ clang -cc1 -triple x86_64-windows-msvc -fms-extensions -O2 -emit-llvm -x c t.cpp
+
+; ModuleID = 't.cpp'
+source_filename = "t.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc"
+
+%struct.Foo = type { i32 addrspace(270)*, i32* }
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_sign_ext(%struct.Foo* nocapture %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_sign_ext:
+; CHECK:   movslq %edx, %rax
+entry:
+  %0 = addrspacecast i32 addrspace(270)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_sign_ext2(%struct.Foo* nocapture %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_sign_ext2:
+; CHECK:   movslq %edx, %rax
+entry:
+  %0 = addrspacecast i32 addrspace(270)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_zero_ext(%struct.Foo* nocapture %f, i32 addrspace(271)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_zero_ext:
+; CHECK:   movl %edx, %eax
+entry:
+  %0 = addrspacecast i32 addrspace(271)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_trunc(%struct.Foo* nocapture %f, i32* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_trunc:
+; CHECK:   movl %edx, (%rcx)
+entry:
+  %0 = addrspacecast i32* %i to i32 addrspace(270)*
+  %p32 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 0
+  store i32 addrspace(270)* %0, i32 addrspace(270)** %p32, align 8, !tbaa !7
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_noop1(%struct.Foo* nocapture %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_noop1:
+; CHECK:   movl %edx, (%rcx)
+entry:
+  %p32 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 0
+  store i32 addrspace(270)* %i, i32 addrspace(270)** %p32, align 8, !tbaa !7
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_noop2(%struct.Foo* nocapture %f, i32* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_noop2:
+; CHECK:   movq %rdx, 8(%rcx)
+entry:
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %i, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+!0 = !{i32 1, !"wchar_size", i32 2}
+!1 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git b4887f121b485fb2b6d4c1fa8296724fb78a244d)"}
+!2 = !{!3, !4, i64 8}
+!3 = !{!"Foo", !4, i64 0, !4, i64 8}
+!4 = !{!"any 

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

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

This change needs a clang CodeGen test to show that we generate IR with 
`__ptr32` / `__ptr64` in the correct places. We should already have some 
semantic tests, but we may need more.




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

Hm, we should actually mangle these as they do. See the FIXME comment above the 
definition of `PointersAre64Bit`. If you look at the uses of PointersAre64Bit, 
you should be able to find the places where you need to check if a pointer type 
is either in the explicit 64-bit address space or in the default address space 
for a 64-bit target. That check sounds like a good helper function.



Comment at: clang/lib/Sema/SemaOverload.cpp:2874
  N->getUnqualifiedType())) {
+  const PointerType *OldTypePtr =
+  dyn_cast(O->getUnqualifiedType());

This probably deserves a comment. It looks like this lets you do this:
```
void foo(int *__ptr64);
void foo(int *p) { } // assume x64 target
```
... without having the compiler think it's creating an overload.

Separately, MSVC doesn't permit `__ptr32/__ptr64` overloads. Is it possible to 
implement that here as well?



Comment at: llvm/test/CodeGen/X86/mixed-ptr-sizes.ll:11
+;   f->p64 = i;
+;   use_foo(f);
+; }

Do you need use_foo? I think `f` is a parameter, so the compiler can't remove 
any stores to it, even without a call to use it. You should be able to simplify 
the test to skip these calls.



Comment at: llvm/test/CodeGen/X86/mixed-ptr-sizes.ll:30
+;
+; $ clang -cc1 -triple x86_64-windows-msvc -fms-extensions -O2 -S t.cpp
+

If you compile this code as plain C code, then it won't have as much name 
mangling, which makes the .ll file more readable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827



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


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

2019-08-27 Thread Amy Huang via Phabricator via cfe-commits
akhuang created this revision.
akhuang added reviewers: rnk, rsmith.
Herald added subscribers: llvm-commits, cfe-commits, erik.pilkington, 
hiraditya, nhaehnle, jvesely, jholewinski.
Herald added projects: clang, LLVM.

Previously, these qualifiers were being parsed but otherwise ignored.
This change makes it so that an address space is added to specify whether the 
pointer is
32-bit or 64-bit and whether it is sign extended or zero extended.

In the backend, the address space casts are lowered to the corresponding
sign/zero extension or truncation.

The data layout for the address spaces was changed in 
https://reviews.llvm.org/D64931

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66827

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/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  llvm/lib/Target/X86/X86.h
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/mixed-ptr-sizes.ll

Index: llvm/test/CodeGen/X86/mixed-ptr-sizes.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/mixed-ptr-sizes.ll
@@ -0,0 +1,108 @@
+; RUN: llc < %s | FileCheck --check-prefixes=CHECK %s
+
+; Source to regenerate:
+; struct Foo {
+;   int * __ptr32 p32;
+;   int * __ptr64 p64;
+; }
+; void use_foo(Foo *f);
+; void test_sign_ext(Foo *f, int * __ptr32 __sptr i) {
+;   f->p64 = i;
+;   use_foo(f);
+; }
+; void test_zero_ext(Foo *f, int * __ptr32 __uptr i) {
+;   f->p64 = i;
+;   use_foo(f);
+; }
+; void test_trunc(foo *f, int * __ptr64 i) {
+;   f->p32 = i;
+;   use_foo(f);
+; }
+; void test_noop1(foo *f, int * __ptr32 i) {
+;   f->p32 = i;
+;   use_foo(f);
+; }
+; void test_noop2(foo *f, int * __ptr64 i) {
+;   f->p64 = i;
+;   use_foo(f);
+; }
+;
+; $ clang -cc1 -triple x86_64-windows-msvc -fms-extensions -O2 -S t.cpp
+
+; ModuleID = 't.cpp'
+source_filename = "t.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc"
+
+%struct.Foo = type { i32 addrspace(270)*, i32* }
+declare dso_local void @"?use_foo@@YAXPEAUFoo@@@Z"(%struct.Foo*) local_unnamed_addr #1
+
+; Function Attrs: nounwind
+define dso_local void @"?test_sign_ext@@YAXPEAUFoo@@PEAU?$_ASPtr32_sptr@$$CAH@__clang@@@Z"(%struct.Foo* %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: {{.*}}test_sign_ext{{.*}}
+; CHECK:   movslq %edx, %rax
+entry:
+  %0 = addrspacecast i32 addrspace(270)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  tail call void @"?use_foo@@YAXPEAUFoo@@@Z"(%struct.Foo* %f) #2
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @"?test_zero_ext@@YAXPEAUFoo@@PEAU?$_ASPtr32_uptr@$$CAH@__clang@@@Z"(%struct.Foo* %f, i32 addrspace(271)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: {{.*}}test_zero_ext{{.*}}
+; CHECK:   movl %edx, %eax
+entry:
+  %0 = addrspacecast i32 addrspace(271)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  tail call void @"?use_foo@@YAXPEAUFoo@@@Z"(%struct.Foo* %f) #2
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @"?test_trunc@@YAXPEAUFoo@@PEAH@Z"(%struct.Foo* %f, i32* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: {{.*}}test_trunc{{.*}}
+; CHECK:   movl %edx, (%rcx)
+entry:
+  %0 = addrspacecast i32* %i to i32 addrspace(270)*
+  %p32 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 0
+  store i32 addrspace(270)* %0, i32 addrspace(270)** %p32, align 8, !tbaa !7
+  tail call void @"?use_foo@@YAXPEAUFoo@@@Z"(%struct.Foo* %f) #2
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @"?test_noop1@@YAXPEAUFoo@@PEAU?$_ASPtr32_sptr@$$CAH@__clang@@@Z"(%struct.Foo* %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: {{.*}}test_noop1{{.*}}
+; CHECK:   movl %edx, (%rcx)
+entry:
+  %p32 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 0
+  store i32 addrspace(270)* %i, i32 addrspace(270)** %p32, align 8, !tbaa !7
+  tail call void @"?use_foo@@YAXPEAUFoo@@@Z"(%struct.Foo* %f) #2
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @"?test_noop2@@YAXPEAUFoo@@PEAH@Z"(%struct.Foo* %f, i32* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: {{.*}}test_noop2{{.*}}
+; CHECK:   movq %rdx, 8(%rcx)
+entry:
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %i, i32** %p64, align 8,