Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-06 Thread David Majnemer via cfe-commits
majnemer added a comment.

In http://reviews.llvm.org/D19654#423382, @andreybokhanko wrote:

> David, thank you for the thorough review! -- it definitely made the patch 
> stronger and me even more paranoid than the rest of Intel. :-)


Thanks for implementing this :)

> 

> 

> In http://reviews.llvm.org/D19654#422445, @majnemer wrote:

> 

> > FYI, we will also want to update `getAddrOfCXXCatchHandler` and 
> > `getThrowInfo` to correctly handle `__unaligned`.

> 

> 

> Do you want me to implement this (I have no idea how EH works on Windows, but 
> can try...) or plan to implement yourself?


I have no plans to implement this but I don't think it is very difficult.  The 
way I'd go about this is to see what happens when the following occur:

  throw (int *__unaligned)nullptr;

MSVC should emit a ThrowInfo object, _TI... which points to a 
CatchableTypeArray, _CTA... which will point to two CatchableTypes, _CT...: one 
for pointer-to-void and the other for pointer-to-int.
Both of the CatchableTypes have a bitfield containing qualifiers, among other 
things.  One of these are where __unaligned should go, see `getThrowInfo` for 
more details.

> Yours,

> Andrey



Repository:
  rL LLVM

http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-06 Thread Andrey Bokhanko via cfe-commits
andreybokhanko added a comment.

David, thank you for the thorough review! -- it definitely made the patch 
stronger and me even more paranoid than the rest of Intel. :-)

In http://reviews.llvm.org/D19654#422445, @majnemer wrote:

> FYI, we will also want to update `getAddrOfCXXCatchHandler` and 
> `getThrowInfo` to correctly handle `__unaligned`.


Do you want me to implement this (I have no idea how EH works on Windows, but 
can try...) or plan to implement yourself?

Yours,
Andrey


Repository:
  rL LLVM

http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-06 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268727: [MSVC] Implementation of __unaligned as a proper 
type qualifier (authored by asbokhan).

Changed prior to commit:
  http://reviews.llvm.org/D19654?vs=55588&id=56401#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19654

Files:
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Basic/AddressSpaces.h
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Sema/DeclSpec.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/AST/MicrosoftMangle.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Parse/ParseTentative.cpp
  cfe/trunk/lib/Sema/DeclSpec.cpp
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclObjC.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaOverload.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp
  cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp
  cfe/trunk/test/Sema/MicrosoftExtensions.c
  cfe/trunk/test/Sema/address_spaces.c
  cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c
  cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp

Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -152,8 +152,8 @@
 
   enum {
 /// The maximum supported address space number.
-/// 24 bits should be enough for anyone.
-MaxAddressSpace = 0xffu,
+/// 23 bits should be enough for anyone.
+MaxAddressSpace = 0x7fu,
 
 /// The width of the "fast" qualifier mask.
 FastWidth = 3,
@@ -265,6 +265,13 @@
 Mask |= mask;
   }
 
+  bool hasUnaligned() const { return Mask & UMask; }
+  void setUnaligned(bool flag) {
+Mask = (Mask & ~UMask) | (flag ? UMask : 0);
+  }
+  void removeUnaligned() { Mask &= ~UMask; }
+  void addUnaligned() { Mask |= UMask; }
+
   bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
   GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
   void setObjCGCAttr(GC type) {
@@ -433,7 +440,9 @@
// ObjC lifetime qualifiers must match exactly.
getObjCLifetime() == other.getObjCLifetime() &&
// CVR qualifiers may subset.
-   (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
+   (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
+   // U qualifier may superset.
+   (!(other.Mask & UMask) || (Mask & UMask));
   }
 
   /// \brief Determines if these qualifiers compatibly include another set of
@@ -501,16 +510,19 @@
 
 private:
 
-  // bits: |0 1 2|3 .. 4|5  ..  7|8   ...   31|
-  //   |C R V|GCAttr|Lifetime|AddressSpace|
+  // bits: |0 1 2|3|4 .. 5|6  ..  8|9   ...   31|
+  //   |C R V|U|GCAttr|Lifetime|AddressSpace|
   uint32_t Mask;
 
-  static const uint32_t GCAttrMask = 0x18;
-  static const uint32_t GCAttrShift = 3;
-  static const uint32_t LifetimeMask = 0xE0;
-  static const uint32_t LifetimeShift = 5;
-  static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask);
-  static const uint32_t AddressSpaceShift = 8;
+  static const uint32_t UMask = 0x8;
+  static const uint32_t UShift = 3;
+  static const uint32_t GCAttrMask = 0x30;
+  static const uint32_t GCAttrShift = 4;
+  static const uint32_t LifetimeMask = 0x1C0;
+  static const uint32_t LifetimeShift = 6;
+  static const uint32_t AddressSpaceMask =
+  ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
+  static const uint32_t AddressSpaceShift = 9;
 };
 
 /// A std::pair-like structure for storing a qualified type split
@@ -5377,7 +5389,13 @@
 /// int" is at least as qualified as "const int", "volatile int",
 /// "int", and "const volatile int".
 inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
-  return getQualifiers().compatiblyIncludes(other.getQualifiers());
+  Qualifiers otherQuals = other.getQualifiers();
+
+  // Ignore __unaligned qualifier if this type is a void.
+  if (getUnqualifiedType()->isVoidType())
+otherQuals.removeUnaligned();
+
+  return getQualifiers().compatiblyIncludes(otherQuals);
 }
 
 /// If Type is a reference type (e.g., const
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -1675,7 +1675,8 @@
 SourceLocation ConstQualLoc = SourceLocation(),
 SourceLocation VolatileQualLoc = SourceLocation(),
 SourceLocation RestrictQualLoc = SourceLocation(),
-SourceLocation AtomicQualLoc = SourceLocation());
+SourceLocation AtomicQualLoc = SourceLocation(),
+SourceLocation UnalignedQua

Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-05 Thread David Majnemer via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM

FYI, we will also want to update `getAddrOfCXXCatchHandler` and `getThrowInfo` 
to correctly handle `__unaligned`.


http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-05 Thread Andrey Bokhanko via cfe-commits
andreybokhanko added a comment.

David, just noticed that your first question doesn't have a redefinition. For 
this program:

__unaligned int unaligned_foo3() { return 0; }
auto z = unaligned_foo3();

Both MS and us mangle z the same:

?z@@3HA

Yours,
Andrey


http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-05 Thread Andrey Bokhanko via cfe-commits
andreybokhanko marked an inline comment as done.


Comment at: lib/AST/MicrosoftMangle.cpp:1583-1584
@@ -1579,2 +1582,4 @@
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {

majnemer wrote:
> majnemer wrote:
> > rnk wrote:
> > > majnemer wrote:
> > > > andreybokhanko wrote:
> > > > > majnemer wrote:
> > > > > > andreybokhanko wrote:
> > > > > > > Done. Test added.
> > > > > > Hmm, can you give a concrete example why we need this line?
> > > > > Sure. An example is:
> > > > > 
> > > > > __unaligned int unaligned_foo3() { return 0; }
> > > > > 
> > > > > MS mangles it as
> > > > > 
> > > > > ?unaligned_foo3@@YAHXZ
> > > > > 
> > > > > However, if __unaligned is taken into account, "if ((!IsPointer && 
> > > > > Quals) || isa(T))" computes to true and clang adds "?A", 
> > > > > resulting to
> > > > > 
> > > > > ?unaligned_foo3@@YA?AHXZ
> > > > > 
> > > > > Yours,
> > > > > Andrey
> > > > > 
> > > > Wait, I thought __unaligned can only apply to pointer types.  Is this 
> > > > not so?!
> > > > Does `__unaligned int x;` really keep it's `__unaligned` qualifier?
> > > Yeah it does:
> > >   $ cat t.cpp
> > >   __unaligned int x;
> > >   $ cl -nologo -c t.cpp && dumpbin /symbols t.obj  | grep ?x
> > >   t.cpp
> > >   008  SECT3  notype   External | ?x@@3HFA (int 
> > > __unaligned x)
> > Woah.  So if you do:
> > 
> > > __unaligned int unaligned_foo3() { return 0; }
> > > auto z = foo3();
> > 
> > How is `z` mangled?
> `z` is mangled without the qualifiers.  In fact:
> 
> ```
> __unaligned int unaligned_foo3() { return 0; }
> __unaligned int z;
> auto z = unaligned_foo3();
> ```
> 
> Is an error:
> 
> 
> > x.cpp(3): error C2373: 'z': redefinition; different type modifiers
> > x.cpp(2): note: see declaration of 'z'
> 
> Do we have comparable behavior?
Not exactly the same, but comparable, indeed:

```
$ clang -cc1 ~/test.cpp -std=c++11 -triple i686-pc-win32 -fms-extensions
/nfs/ims/home/asbokhan/test.cpp:3:6: error: redefinition of 'z'
auto z = unaligned_foo3();
 ^
/nfs/ims/home/asbokhan/test.cpp:2:17: note: previous definition is here
__unaligned int z;
^
1 error generated.
```

This has nothing to do with __unaligned, though, as both MS compiler and us 
don't allow redefinitions. If a redefinition has a different __unaligned 
modifier, MS also notes this (with "; different type modifiers" suffix in the 
message), but it doesn't serve any practical purpose, as changing modifier 
won't make the code compilable.

Yours,
Andrey


http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-04 Thread David Majnemer via cfe-commits
majnemer added inline comments.


Comment at: lib/AST/MicrosoftMangle.cpp:1583-1584
@@ -1579,2 +1582,4 @@
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {

majnemer wrote:
> rnk wrote:
> > majnemer wrote:
> > > andreybokhanko wrote:
> > > > majnemer wrote:
> > > > > andreybokhanko wrote:
> > > > > > Done. Test added.
> > > > > Hmm, can you give a concrete example why we need this line?
> > > > Sure. An example is:
> > > > 
> > > > __unaligned int unaligned_foo3() { return 0; }
> > > > 
> > > > MS mangles it as
> > > > 
> > > > ?unaligned_foo3@@YAHXZ
> > > > 
> > > > However, if __unaligned is taken into account, "if ((!IsPointer && 
> > > > Quals) || isa(T))" computes to true and clang adds "?A", 
> > > > resulting to
> > > > 
> > > > ?unaligned_foo3@@YA?AHXZ
> > > > 
> > > > Yours,
> > > > Andrey
> > > > 
> > > Wait, I thought __unaligned can only apply to pointer types.  Is this not 
> > > so?!
> > > Does `__unaligned int x;` really keep it's `__unaligned` qualifier?
> > Yeah it does:
> >   $ cat t.cpp
> >   __unaligned int x;
> >   $ cl -nologo -c t.cpp && dumpbin /symbols t.obj  | grep ?x
> >   t.cpp
> >   008  SECT3  notype   External | ?x@@3HFA (int __unaligned 
> > x)
> Woah.  So if you do:
> 
> > __unaligned int unaligned_foo3() { return 0; }
> > auto z = foo3();
> 
> How is `z` mangled?
`z` is mangled without the qualifiers.  In fact:

```
__unaligned int unaligned_foo3() { return 0; }
__unaligned int z;
auto z = unaligned_foo3();
```

Is an error:


> x.cpp(3): error C2373: 'z': redefinition; different type modifiers
> x.cpp(2): note: see declaration of 'z'

Do we have comparable behavior?


http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-04 Thread David Majnemer via cfe-commits
majnemer added inline comments.


Comment at: lib/AST/MicrosoftMangle.cpp:1583-1584
@@ -1579,2 +1582,4 @@
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {

rnk wrote:
> majnemer wrote:
> > andreybokhanko wrote:
> > > majnemer wrote:
> > > > andreybokhanko wrote:
> > > > > Done. Test added.
> > > > Hmm, can you give a concrete example why we need this line?
> > > Sure. An example is:
> > > 
> > > __unaligned int unaligned_foo3() { return 0; }
> > > 
> > > MS mangles it as
> > > 
> > > ?unaligned_foo3@@YAHXZ
> > > 
> > > However, if __unaligned is taken into account, "if ((!IsPointer && Quals) 
> > > || isa(T))" computes to true and clang adds "?A", resulting to
> > > 
> > > ?unaligned_foo3@@YA?AHXZ
> > > 
> > > Yours,
> > > Andrey
> > > 
> > Wait, I thought __unaligned can only apply to pointer types.  Is this not 
> > so?!
> > Does `__unaligned int x;` really keep it's `__unaligned` qualifier?
> Yeah it does:
>   $ cat t.cpp
>   __unaligned int x;
>   $ cl -nologo -c t.cpp && dumpbin /symbols t.obj  | grep ?x
>   t.cpp
>   008  SECT3  notype   External | ?x@@3HFA (int __unaligned x)
Woah.  So if you do:

> __unaligned int unaligned_foo3() { return 0; }
> auto z = foo3();

How is `z` mangled?


http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-04 Thread andreybokhanko via cfe-commits
What Reid said...

Yours,
Andrey

> 5 мая 2016 г., в 1:48, Reid Kleckner  написал(а):
> 
> rnk added inline comments.
> 
> 
> Comment at: lib/AST/MicrosoftMangle.cpp:1583-1584
> @@ -1579,2 +1582,4 @@
>   case QMM_Result:
> +// Presence of __unaligned qualifier shouldn't affect mangling here.
> +Quals.removeUnaligned();
> if ((!IsPointer && Quals) || isa(T)) {
> 
> majnemer wrote:
>> andreybokhanko wrote:
>>> majnemer wrote:
 andreybokhanko wrote:
> Done. Test added.
 Hmm, can you give a concrete example why we need this line?
>>> Sure. An example is:
>>> 
>>> __unaligned int unaligned_foo3() { return 0; }
>>> 
>>> MS mangles it as
>>> 
>>> ?unaligned_foo3@@YAHXZ
>>> 
>>> However, if __unaligned is taken into account, "if ((!IsPointer && Quals) 
>>> || isa(T))" computes to true and clang adds "?A", resulting to
>>> 
>>> ?unaligned_foo3@@YA?AHXZ
>>> 
>>> Yours,
>>> Andrey
>> Wait, I thought __unaligned can only apply to pointer types.  Is this not 
>> so?!
>> Does `__unaligned int x;` really keep it's `__unaligned` qualifier?
> Yeah it does:
>  $ cat t.cpp
>  __unaligned int x;
>  $ cl -nologo -c t.cpp && dumpbin /symbols t.obj  | grep ?x
>  t.cpp
>  008  SECT3  notype   External | ?x@@3HFA (int __unaligned x)
> 
> 
> http://reviews.llvm.org/D19654
> 
> 
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-04 Thread Reid Kleckner via cfe-commits
rnk added inline comments.


Comment at: lib/AST/MicrosoftMangle.cpp:1583-1584
@@ -1579,2 +1582,4 @@
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {

majnemer wrote:
> andreybokhanko wrote:
> > majnemer wrote:
> > > andreybokhanko wrote:
> > > > Done. Test added.
> > > Hmm, can you give a concrete example why we need this line?
> > Sure. An example is:
> > 
> > __unaligned int unaligned_foo3() { return 0; }
> > 
> > MS mangles it as
> > 
> > ?unaligned_foo3@@YAHXZ
> > 
> > However, if __unaligned is taken into account, "if ((!IsPointer && Quals) 
> > || isa(T))" computes to true and clang adds "?A", resulting to
> > 
> > ?unaligned_foo3@@YA?AHXZ
> > 
> > Yours,
> > Andrey
> > 
> Wait, I thought __unaligned can only apply to pointer types.  Is this not so?!
> Does `__unaligned int x;` really keep it's `__unaligned` qualifier?
Yeah it does:
  $ cat t.cpp
  __unaligned int x;
  $ cl -nologo -c t.cpp && dumpbin /symbols t.obj  | grep ?x
  t.cpp
  008  SECT3  notype   External | ?x@@3HFA (int __unaligned x)


http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-04 Thread David Majnemer via cfe-commits
majnemer added inline comments.


Comment at: lib/AST/MicrosoftMangle.cpp:1583-1584
@@ -1579,2 +1582,4 @@
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {

andreybokhanko wrote:
> majnemer wrote:
> > andreybokhanko wrote:
> > > Done. Test added.
> > Hmm, can you give a concrete example why we need this line?
> Sure. An example is:
> 
> __unaligned int unaligned_foo3() { return 0; }
> 
> MS mangles it as
> 
> ?unaligned_foo3@@YAHXZ
> 
> However, if __unaligned is taken into account, "if ((!IsPointer && Quals) || 
> isa(T))" computes to true and clang adds "?A", resulting to
> 
> ?unaligned_foo3@@YA?AHXZ
> 
> Yours,
> Andrey
> 
Wait, I thought __unaligned can only apply to pointer types.  Is this not so?!
Does `__unaligned int x;` really keep it's `__unaligned` qualifier?


http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-04 Thread Andrey Bokhanko via cfe-commits
andreybokhanko marked 3 inline comments as done.


Comment at: lib/AST/MicrosoftMangle.cpp:1583-1584
@@ -1579,2 +1582,4 @@
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {

majnemer wrote:
> andreybokhanko wrote:
> > Done. Test added.
> Hmm, can you give a concrete example why we need this line?
Sure. An example is:

__unaligned int unaligned_foo3() { return 0; }

MS mangles it as

?unaligned_foo3@@YAHXZ

However, if __unaligned is taken into account, "if ((!IsPointer && Quals) || 
isa(T))" computes to true and clang adds "?A", resulting to

?unaligned_foo3@@YA?AHXZ

Yours,
Andrey



http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-04-30 Thread David Majnemer via cfe-commits
majnemer added inline comments.


Comment at: lib/AST/MicrosoftMangle.cpp:1583-1584
@@ -1579,2 +1582,4 @@
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {

andreybokhanko wrote:
> Done. Test added.
Hmm, can you give a concrete example why we need this line?


http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-04-29 Thread Andrey Bokhanko via cfe-commits
andreybokhanko marked 3 inline comments as done.
andreybokhanko added a comment.

David, thank you for the review!

In http://reviews.llvm.org/D19654#416408, @majnemer wrote:

> It would be good to have a test for the variable template case:
>
>   template 
>   T x;
>  
>   auto g() { return x; }
>
>
> should mangle to `??$x@PEFAH@@3PEFAHEFA`


It mangles exaclty to `??$x@PEFAH@@3PEFAHEFA` (in 64 bit mode). Test added.



Comment at: lib/AST/MicrosoftMangle.cpp:1446-1451
@@ -1445,5 +1445,8 @@
 Out << 'E';
 
   if (HasRestrict)
 Out << 'I';
+
+  if (!PointeeType.isNull() && PointeeType.getLocalQualifiers().hasUnaligned())
+Out << 'F';
 }

Good catch!

Indeed, __restrict and __unaligned are mangled in a different order. Fixed; 
test added.


Comment at: lib/AST/MicrosoftMangle.cpp:1583-1585
@@ -1579,3 +1582,5 @@
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {
   Out << '?';

Done. Test added.


http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-04-29 Thread Andrey Bokhanko via cfe-commits
andreybokhanko updated this revision to Diff 55588.
andreybokhanko added a comment.

Fixed a bug uncovered by David Majnemer's review; added tests he asked for.


http://reviews.llvm.org/D19654

Files:
  include/clang/AST/Type.h
  include/clang/Basic/AddressSpaces.h
  include/clang/Basic/Attr.td
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/Sema.h
  lib/AST/MicrosoftMangle.cpp
  lib/AST/TypePrinter.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaCodeComplete.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenCXX/mangle-ms-cxx11.cpp
  test/CodeGenCXX/mangle-ms-cxx14.cpp
  test/Sema/MicrosoftExtensions.c
  test/Sema/address_spaces.c
  test/Sema/invalid-assignment-constant-address-space.c
  test/SemaCXX/MicrosoftExtensions.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -609,7 +609,6 @@
 case tok::kw___ptr64:
 case tok::kw___w64:
 case tok::kw___ptr32:
-case tok::kw___unaligned:
 case tok::kw___sptr:
 case tok::kw___uptr: {
   IdentifierInfo *AttrName = Tok.getIdentifierInfo();
@@ -3087,6 +3086,11 @@
   break;
 }
 
+case tok::kw___unaligned:
+  isInvalid = DS.SetTypeQual(DeclSpec::TQ_unaligned, Loc, PrevSpec, DiagID,
+ getLangOpts());
+  break;
+
 case tok::kw___sptr:
 case tok::kw___uptr:
 case tok::kw___ptr64:
@@ -3097,7 +3101,6 @@
 case tok::kw___fastcall:
 case tok::kw___thiscall:
 case tok::kw___vectorcall:
-case tok::kw___unaligned:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
 
@@ -4791,6 +4794,10 @@
   ParseOpenCLQualifiers(DS.getAttributes());
   break;
 
+case tok::kw___unaligned:
+  isInvalid = DS.SetTypeQual(DeclSpec::TQ_unaligned, Loc, PrevSpec, DiagID,
+ getLangOpts());
+  break;
 case tok::kw___uptr:
   // GNU libc headers in C mode use '__uptr' as an identifer which conflicts
   // with the MS modifier keyword.
@@ -4808,7 +4815,6 @@
 case tok::kw___fastcall:
 case tok::kw___thiscall:
 case tok::kw___vectorcall:
-case tok::kw___unaligned:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
 continue;
@@ -5031,7 +5037,8 @@
 DS.getConstSpecLoc(),
 DS.getVolatileSpecLoc(),
 DS.getRestrictSpecLoc(),
-DS.getAtomicSpecLoc()),
+DS.getAtomicSpecLoc(),
+DS.getUnalignedSpecLoc()),
 DS.getAttributes(),
 SourceLocation());
 else
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -833,7 +833,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall, tok::kw___unaligned))
+  tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -1446,6 +1446,9 @@
 
   if (HasRestrict)
 Out << 'I';
+
+  if (!PointeeType.isNull() && PointeeType.getLocalQualifiers().hasUnaligned())
+Out << 'F';
 }
 
 void MicrosoftCXXNameMangler::manglePointerCVQualifiers(Qualifiers Quals) {
@@ -1577,6 +1580,8 @@
 }
 break;
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {
   Out << '?';
   mangleQualifiers(Quals, false);
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -1592,6 +1592,12 @@
 AppendTypeQualList(OS, quals, Policy.LangOpts.C99);
 addSpace = true;
   }
+  if (hasUnaligned()) {
+if (addSpace)
+  OS << ' ';
+OS << "__unaligned";
+addSpace = true;
+  }
   if (unsigned addrspace = getAddressSpace()) {
 if (addSpace)
   OS << ' ';
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.c

Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-04-28 Thread David Majnemer via cfe-commits
majnemer added a comment.

It would be good to have a test for the variable template case:

  template 
  T x;
  
  auto g() { return x; }

should mangle to `??$x@PEFAH@@3PEFAHEFA`


http://reviews.llvm.org/D19654



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


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-04-28 Thread David Majnemer via cfe-commits
majnemer added inline comments.


Comment at: lib/AST/MicrosoftMangle.cpp:1446-1451
@@ -1445,5 +1445,8 @@
 Out << 'E';
 
+  if (!PointeeType.isNull() && PointeeType.getLocalQualifiers().hasUnaligned())
+Out << 'F';
+
   if (HasRestrict)
 Out << 'I';
 }

Have you tested `__restrict` with `__unaligned` on MSVC?  I don't see a test 
for it here.


Comment at: lib/AST/MicrosoftMangle.cpp:1583-1585
@@ -1579,3 +1582,5 @@
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {
   Out << '?';

It would be good to see what MSVC does with:

```
template 
T f(T t) { return t; }
```

Where `T` is instantiated with `int *` and `int __unaligned *`.


Comment at: lib/Sema/SemaType.cpp:1787
@@ -1787,1 +1786,3 @@
+  // TQ_unaligned;
+  unsigned CVR = CVRAU & ~DeclSpec::TQ_atomic & ~DeclSpec::TQ_unaligned;
 

This would probably be easier to read if written as:
  unsigned CVR = CVRAU & ~(DeclSpec::TQ_atomic | DeclSpec::TQ_unaligned);


http://reviews.llvm.org/D19654



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


[PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-04-28 Thread Andrey Bokhanko via cfe-commits
andreybokhanko created this revision.
andreybokhanko added reviewers: rnk, thakis, majnemer.
andreybokhanko added a subscriber: cfe-commits.

This is exactly same patch as http://reviews.llvm.org/D18596 (already reviewed 
and LGTMed by rnk), with a couple of changes to fix PR27367:

* A check for void pointer added to include/clang/AST/Type.h
* A check for void pointer added to lib/Sema/SemaOverload.cpp
* A test (from PR27367) added to test/SemaCXX/MicrosoftExtensions.cpp

Yours,
Andrey
=
Software Engineer
Intel Compiler Team


http://reviews.llvm.org/D19654

Files:
  include/clang/AST/Type.h
  include/clang/Basic/AddressSpaces.h
  include/clang/Basic/Attr.td
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/Sema.h
  lib/AST/MicrosoftMangle.cpp
  lib/AST/TypePrinter.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaCodeComplete.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenCXX/mangle-ms-cxx11.cpp
  test/Sema/MicrosoftExtensions.c
  test/Sema/address_spaces.c
  test/Sema/invalid-assignment-constant-address-space.c
  test/SemaCXX/MicrosoftExtensions.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -609,7 +609,6 @@
 case tok::kw___ptr64:
 case tok::kw___w64:
 case tok::kw___ptr32:
-case tok::kw___unaligned:
 case tok::kw___sptr:
 case tok::kw___uptr: {
   IdentifierInfo *AttrName = Tok.getIdentifierInfo();
@@ -3087,6 +3086,11 @@
   break;
 }
 
+case tok::kw___unaligned:
+  isInvalid = DS.SetTypeQual(DeclSpec::TQ_unaligned, Loc, PrevSpec, DiagID,
+ getLangOpts());
+  break;
+
 case tok::kw___sptr:
 case tok::kw___uptr:
 case tok::kw___ptr64:
@@ -3097,7 +3101,6 @@
 case tok::kw___fastcall:
 case tok::kw___thiscall:
 case tok::kw___vectorcall:
-case tok::kw___unaligned:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
 
@@ -4791,6 +4794,10 @@
   ParseOpenCLQualifiers(DS.getAttributes());
   break;
 
+case tok::kw___unaligned:
+  isInvalid = DS.SetTypeQual(DeclSpec::TQ_unaligned, Loc, PrevSpec, DiagID,
+ getLangOpts());
+  break;
 case tok::kw___uptr:
   // GNU libc headers in C mode use '__uptr' as an identifer which conflicts
   // with the MS modifier keyword.
@@ -4808,7 +4815,6 @@
 case tok::kw___fastcall:
 case tok::kw___thiscall:
 case tok::kw___vectorcall:
-case tok::kw___unaligned:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
 continue;
@@ -5031,7 +5037,8 @@
 DS.getConstSpecLoc(),
 DS.getVolatileSpecLoc(),
 DS.getRestrictSpecLoc(),
-DS.getAtomicSpecLoc()),
+DS.getAtomicSpecLoc(),
+DS.getUnalignedSpecLoc()),
 DS.getAttributes(),
 SourceLocation());
 else
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -833,7 +833,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall, tok::kw___unaligned))
+  tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -1444,6 +1444,9 @@
   (PointeeType.isNull() || !PointeeType->isFunctionType()))
 Out << 'E';
 
+  if (!PointeeType.isNull() && PointeeType.getLocalQualifiers().hasUnaligned())
+Out << 'F';
+
   if (HasRestrict)
 Out << 'I';
 }
@@ -1577,6 +1580,8 @@
 }
 break;
   case QMM_Result:
+// Presence of __unaligned qualifier shouldn't affect mangling here.
+Quals.removeUnaligned();
 if ((!IsPointer && Quals) || isa(T)) {
   Out << '?';
   mangleQualifiers(Quals, false);
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -1592,6 +1592,12 @@
 AppendTypeQualList(OS, quals, Policy.LangOpts.C99);
 add