r269220 - [MSVC] Implementation of __unaligned as a proper type qualifier

Andrey Bokhanko via cfe-commits cfe-commits at lists.llvm.org
Thu May 19 08:34:07 PDT 2016


David,

All these cases are handled properly now.

Could you, please, review?

http://reviews.llvm.org/D20437

Yours,
Andrey


On Sat, May 14, 2016 at 6:11 AM, David Majnemer <david.majnemer at gmail.com>
wrote:

> FYI, the following is a little shorter:
> using Ty = int () __unaligned;
>
> Also, this case (in C mode) is interesting:
> void f(int x[__unaligned 4]);
>
> DeclaratorChunk::getArray will truncate the TypeQuals
> because ArrayTypeInfo's TypeQuals doesn't have enough bits.
>
> similar issues arise with:
> struct A;
>
> void (A::*__unaligned vpa)();
>
> On Fri, May 13, 2016 at 4:03 PM, <andreybokhanko at gmail.com> wrote:
>
>> Hi David,
>>
>> Thanks for letting me know -- will investigate after the weekend.
>>
>> Yours,
>> Andrey
>>
>> Отправлено с iPad
>>
>> 13 мая 2016 г., в 20:33, David Majnemer <david.majnemer at gmail.com>
>> написал(а):
>>
>> This seems to crash clang:
>> struct S {
>>   void f() __unaligned;
>> };
>> void S::f() __unaligned {
>> }
>>
>> clang/lib/Sema/DeclSpec.cpp:214: static clang::DeclaratorChunk
>> clang::DeclaratorChunk::getFunction(bool, bool, clang::SourceLocation,
>> clang::DeclaratorChunk::ParamInfo *, unsigned int, clang::SourceLocation,
>> clang::SourceLocation, unsigned int, bool, clang::SourceLocation,
>> clang::SourceLocation, clang::SourceLocation, clang::SourceLocation,
>> clang::SourceLocation, clang::ExceptionSpecificationType,
>> clang::SourceRange, ParsedType *, clang::SourceRange *, unsigned int,
>> clang::Expr *, CachedTokens *, clang::SourceLocation,
>> clang::SourceLocation, clang::Declarator &, TypeResult): Assertion
>> `I.Fun.TypeQuals == TypeQuals && "bitfield overflow"' failed.
>>
>>
>> On Wed, May 11, 2016 at 11:38 AM, Andrey Bokhanko via cfe-commits <
>> cfe-commits at lists.llvm.org> wrote:
>>
>>> Author: asbokhan
>>> Date: Wed May 11 13:38:21 2016
>>> New Revision: 269220
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=269220&view=rev
>>> Log:
>>> [MSVC] Implementation of __unaligned as a proper type qualifier
>>>
>>> This patch implements __unaligned (MS extension) as a proper type
>>> qualifier
>>> (before that, it was implemented as an ignored attribute).
>>>
>>> It also fixes PR27367 and PR27666.
>>>
>>> Differential Revision: http://reviews.llvm.org/D20103
>>>
>>> Modified:
>>>     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/Basic/DiagnosticSemaKinds.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
>>>
>>> Modified: cfe/trunk/include/clang/AST/Type.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/include/clang/AST/Type.h (original)
>>> +++ cfe/trunk/include/clang/AST/Type.h Wed May 11 13:38:21 2016
>>> @@ -111,6 +111,7 @@ namespace clang {
>>>  /// The collection of all-type qualifiers we support.
>>>  /// Clang supports five independent qualifiers:
>>>  /// * C99: const, volatile, and restrict
>>> +/// * MS: __unaligned
>>>  /// * Embedded C (TR18037): address spaces
>>>  /// * Objective C: the GC attributes (none, weak, or strong)
>>>  class Qualifiers {
>>> @@ -152,8 +153,8 @@ public:
>>>
>>>    enum {
>>>      /// The maximum supported address space number.
>>> -    /// 24 bits should be enough for anyone.
>>> -    MaxAddressSpace = 0xffffffu,
>>> +    /// 23 bits should be enough for anyone.
>>> +    MaxAddressSpace = 0x7fffffu,
>>>
>>>      /// The width of the "fast" qualifier mask.
>>>      FastWidth = 3,
>>> @@ -265,6 +266,13 @@ public:
>>>      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 +441,9 @@ public:
>>>             // 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.hasUnaligned() || hasUnaligned());
>>>    }
>>>
>>>    /// \brief Determines if these qualifiers compatibly include another
>>> set of
>>> @@ -501,16 +511,19 @@ public:
>>>
>>>  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
>>> @@ -5367,9 +5380,9 @@ inline FunctionType::ExtInfo getFunction
>>>  /// "int". However, it is not more qualified than "const volatile
>>>  /// int".
>>>  inline bool QualType::isMoreQualifiedThan(QualType other) const {
>>> -  Qualifiers myQuals = getQualifiers();
>>> -  Qualifiers otherQuals = other.getQualifiers();
>>> -  return (myQuals != otherQuals &&
>>> myQuals.compatiblyIncludes(otherQuals));
>>> +  Qualifiers MyQuals = getQualifiers();
>>> +  Qualifiers OtherQuals = other.getQualifiers();
>>> +  return (MyQuals != OtherQuals &&
>>> MyQuals.compatiblyIncludes(OtherQuals));
>>>  }
>>>
>>>  /// Determine whether this type is at last
>>> @@ -5377,7 +5390,13 @@ inline bool QualType::isMoreQualifiedTha
>>>  /// 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
>>>
>>> Modified: cfe/trunk/include/clang/Basic/AddressSpaces.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AddressSpaces.h?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/include/clang/Basic/AddressSpaces.h (original)
>>> +++ cfe/trunk/include/clang/Basic/AddressSpaces.h Wed May 11 13:38:21
>>> 2016
>>> @@ -25,7 +25,7 @@ namespace LangAS {
>>>  /// This uses a high starting offset so as not to conflict with any
>>> address
>>>  /// space used by a target.
>>>  enum ID {
>>> -  Offset = 0xFFFF00,
>>> +  Offset = 0x7FFF00,
>>>
>>>    opencl_global = Offset,
>>>    opencl_local,
>>>
>>> Modified: cfe/trunk/include/clang/Basic/Attr.td
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/include/clang/Basic/Attr.td (original)
>>> +++ cfe/trunk/include/clang/Basic/Attr.td Wed May 11 13:38:21 2016
>>> @@ -2157,10 +2157,6 @@ def InitSeg : Attr {
>>>    }];
>>>  }
>>>
>>> -def Unaligned : IgnoredAttr {
>>> -  let Spellings = [Keyword<"__unaligned">];
>>> -}
>>> -
>>>  def LoopHint : Attr {
>>>    /// #pragma clang loop <option> directive
>>>    /// vectorize: vectorizes loop operations if State == Enable.
>>>
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed May 11
>>> 13:38:21 2016
>>> @@ -3374,6 +3374,16 @@ def note_ovl_candidate_bad_cvr : Note<"c
>>>      "%select{const|restrict|const and restrict|volatile|const and
>>> volatile|"
>>>      "volatile and restrict|const, volatile, and restrict}3 qualifier"
>>>      "%select{||s||s|s|s}3">;
>>> +def note_ovl_candidate_bad_unaligned : Note<"candidate "
>>> +    "%select{function|function|constructor|"
>>> +    "function |function |constructor |"
>>> +    "constructor (the implicit default constructor)|"
>>> +    "constructor (the implicit copy constructor)|"
>>> +    "constructor (the implicit move constructor)|"
>>> +    "function (the implicit copy assignment operator)|"
>>> +    "function (the implicit move assignment operator)|"
>>> +    "constructor (inherited)}0%1 not viable: "
>>> +    "%ordinal4 argument (%2) would lose __unaligned qualifier">;
>>>  def note_ovl_candidate_bad_base_to_derived_conv : Note<"candidate "
>>>      "%select{function|function|constructor|"
>>>      "function |function |constructor |"
>>>
>>> Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
>>> +++ cfe/trunk/include/clang/Sema/DeclSpec.h Wed May 11 13:38:21 2016
>>> @@ -313,7 +313,10 @@ public:
>>>      TQ_volatile    = 4,
>>>      // This has no corresponding Qualifiers::TQ value, because it's not
>>> treated
>>>      // as a qualifier in our type system.
>>> -    TQ_atomic      = 8
>>> +    TQ_atomic      = 8,
>>> +    // There is no corresponding Qualifiers::TQ value, but it's kept
>>> separately
>>> +    // in a dedicated Qualifiers::Mask bit.
>>> +    TQ_unaligned   = 16
>>>    };
>>>
>>>    /// ParsedSpecifiers - Flags to query which specifiers were applied.
>>> This is
>>> @@ -344,7 +347,7 @@ private:
>>>    unsigned TypeSpecPipe : 1;
>>>
>>>    // type-qualifiers
>>> -  unsigned TypeQualifiers : 4;  // Bitwise OR of TQ.
>>> +  unsigned TypeQualifiers : 5;  // Bitwise OR of TQ.
>>>
>>>    // function-specifier
>>>    unsigned FS_inline_specified : 1;
>>> @@ -386,7 +389,8 @@ private:
>>>    /// TSTNameLoc provides source range info for tag types.
>>>    SourceLocation TSTNameLoc;
>>>    SourceRange TypeofParensRange;
>>> -  SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc,
>>> TQ_atomicLoc;
>>> +  SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc,
>>> TQ_atomicLoc,
>>> +      TQ_unalignedLoc;
>>>    SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc,
>>> FS_noreturnLoc;
>>>    SourceLocation FS_forceinlineLoc;
>>>    SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc, ConceptLoc;
>>> @@ -540,6 +544,7 @@ public:
>>>    SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
>>>    SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
>>>    SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; }
>>> +  SourceLocation getUnalignedSpecLoc() const { return TQ_unalignedLoc; }
>>>    SourceLocation getPipeLoc() const { return TQ_pipeLoc; }
>>>
>>>    /// \brief Clear out all of the type qualifiers.
>>> @@ -549,6 +554,7 @@ public:
>>>      TQ_restrictLoc = SourceLocation();
>>>      TQ_volatileLoc = SourceLocation();
>>>      TQ_atomicLoc = SourceLocation();
>>> +    TQ_unalignedLoc = SourceLocation();
>>>      TQ_pipeLoc = SourceLocation();
>>>    }
>>>
>>> @@ -1114,8 +1120,8 @@ struct DeclaratorChunk {
>>>    };
>>>
>>>    struct PointerTypeInfo : TypeInfoCommon {
>>> -    /// The type qualifiers: const/volatile/restrict/atomic.
>>> -    unsigned TypeQuals : 4;
>>> +    /// The type qualifiers: const/volatile/restrict/atomic/unaligned.
>>> +    unsigned TypeQuals : 5;
>>>
>>>      /// The location of the const-qualifier, if any.
>>>      unsigned ConstQualLoc;
>>> @@ -1129,6 +1135,9 @@ struct DeclaratorChunk {
>>>      /// The location of the _Atomic-qualifier, if any.
>>>      unsigned AtomicQualLoc;
>>>
>>> +    /// The location of the __unaligned-qualifier, if any.
>>> +    unsigned UnalignedQualLoc;
>>> +
>>>      void destroy() {
>>>      }
>>>    };
>>> @@ -1469,7 +1478,8 @@ struct DeclaratorChunk {
>>>                                      SourceLocation ConstQualLoc,
>>>                                      SourceLocation VolatileQualLoc,
>>>                                      SourceLocation RestrictQualLoc,
>>> -                                    SourceLocation AtomicQualLoc) {
>>> +                                    SourceLocation AtomicQualLoc,
>>> +                                    SourceLocation UnalignedQualLoc) {
>>>      DeclaratorChunk I;
>>>      I.Kind                = Pointer;
>>>      I.Loc                 = Loc;
>>> @@ -1478,6 +1488,7 @@ struct DeclaratorChunk {
>>>      I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding();
>>>      I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding();
>>>      I.Ptr.AtomicQualLoc   = AtomicQualLoc.getRawEncoding();
>>> +    I.Ptr.UnalignedQualLoc = UnalignedQualLoc.getRawEncoding();
>>>      I.Ptr.AttrList        = nullptr;
>>>      return I;
>>>    }
>>>
>>> Modified: cfe/trunk/include/clang/Sema/Sema.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/include/clang/Sema/Sema.h (original)
>>> +++ cfe/trunk/include/clang/Sema/Sema.h Wed May 11 13:38:21 2016
>>> @@ -1675,7 +1675,8 @@ public:
>>>                              SourceLocation ConstQualLoc =
>>> SourceLocation(),
>>>                              SourceLocation VolatileQualLoc =
>>> SourceLocation(),
>>>                              SourceLocation RestrictQualLoc =
>>> SourceLocation(),
>>> -                            SourceLocation AtomicQualLoc =
>>> SourceLocation());
>>> +                            SourceLocation AtomicQualLoc =
>>> SourceLocation(),
>>> +                            SourceLocation UnalignedQualLoc =
>>> SourceLocation());
>>>
>>>    static bool adjustContextForLocalExternDecl(DeclContext *&DC);
>>>    void DiagnoseFunctionSpecifiers(const DeclSpec &DS);
>>>
>>> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
>>> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Wed May 11 13:38:21 2016
>>> @@ -1446,6 +1446,9 @@ void MicrosoftCXXNameMangler::manglePoin
>>>
>>>    if (HasRestrict)
>>>      Out << 'I';
>>> +
>>> +  if (!PointeeType.isNull() &&
>>> PointeeType.getLocalQualifiers().hasUnaligned())
>>> +    Out << 'F';
>>>  }
>>>
>>>  void MicrosoftCXXNameMangler::manglePointerCVQualifiers(Qualifiers
>>> Quals) {
>>> @@ -1577,6 +1580,8 @@ void MicrosoftCXXNameMangler::mangleType
>>>      }
>>>      break;
>>>    case QMM_Result:
>>> +    // Presence of __unaligned qualifier shouldn't affect mangling here.
>>> +    Quals.removeUnaligned();
>>>      if ((!IsPointer && Quals) || isa<TagType>(T)) {
>>>        Out << '?';
>>>        mangleQualifiers(Quals, false);
>>>
>>> Modified: cfe/trunk/lib/AST/TypePrinter.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/AST/TypePrinter.cpp (original)
>>> +++ cfe/trunk/lib/AST/TypePrinter.cpp Wed May 11 13:38:21 2016
>>> @@ -1593,6 +1593,12 @@ void Qualifiers::print(raw_ostream &OS,
>>>      AppendTypeQualList(OS, quals, Policy.LangOpts.C99);
>>>      addSpace = true;
>>>    }
>>> +  if (hasUnaligned()) {
>>> +    if (addSpace)
>>> +      OS << ' ';
>>> +    OS << "__unaligned";
>>> +    addSpace = true;
>>> +  }
>>>    if (unsigned addrspace = getAddressSpace()) {
>>>      if (addSpace)
>>>        OS << ' ';
>>>
>>> Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
>>> +++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed May 11 13:38:21 2016
>>> @@ -609,7 +609,6 @@ void Parser::ParseMicrosoftTypeAttribute
>>>      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 @@ void Parser::ParseDeclarationSpecifiers(
>>>        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 @@ void Parser::ParseDeclarationSpecifiers(
>>>      case tok::kw___fastcall:
>>>      case tok::kw___thiscall:
>>>      case tok::kw___vectorcall:
>>> -    case tok::kw___unaligned:
>>>        ParseMicrosoftTypeAttributes(DS.getAttributes());
>>>        continue;
>>>
>>> @@ -4798,6 +4801,10 @@ void Parser::ParseTypeQualifierListOpt(D
>>>        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.
>>> @@ -4815,7 +4822,6 @@ void Parser::ParseTypeQualifierListOpt(D
>>>      case tok::kw___fastcall:
>>>      case tok::kw___thiscall:
>>>      case tok::kw___vectorcall:
>>> -    case tok::kw___unaligned:
>>>        if (AttrReqs & AR_DeclspecAttributesParsed) {
>>>          ParseMicrosoftTypeAttributes(DS.getAttributes());
>>>          continue;
>>> @@ -5038,7 +5044,8 @@ void Parser::ParseDeclaratorInternal(Dec
>>>                                                  DS.getConstSpecLoc(),
>>>                                                  DS.getVolatileSpecLoc(),
>>>                                                  DS.getRestrictSpecLoc(),
>>> -                                                DS.getAtomicSpecLoc()),
>>> +                                                DS.getAtomicSpecLoc(),
>>> +
>>> DS.getUnalignedSpecLoc()),
>>>                      DS.getAttributes(),
>>>                      SourceLocation());
>>>      else
>>>
>>> Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
>>> +++ cfe/trunk/lib/Parse/ParseTentative.cpp Wed May 11 13:38:21 2016
>>> @@ -833,7 +833,7 @@ Parser::TPResult Parser::TryParseDeclara
>>>        // '(' 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)
>>>
>>> Modified: cfe/trunk/lib/Sema/DeclSpec.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/DeclSpec.cpp (original)
>>> +++ cfe/trunk/lib/Sema/DeclSpec.cpp Wed May 11 13:38:21 2016
>>> @@ -494,6 +494,7 @@ const char *DeclSpec::getSpecifierName(T
>>>    case DeclSpec::TQ_restrict:    return "restrict";
>>>    case DeclSpec::TQ_volatile:    return "volatile";
>>>    case DeclSpec::TQ_atomic:      return "_Atomic";
>>> +  case DeclSpec::TQ_unaligned:   return "__unaligned";
>>>    }
>>>    llvm_unreachable("Unknown typespec!");
>>>  }
>>> @@ -796,6 +797,7 @@ bool DeclSpec::SetTypeQual(TQ T, SourceL
>>>    case TQ_restrict: TQ_restrictLoc = Loc; return false;
>>>    case TQ_volatile: TQ_volatileLoc = Loc; return false;
>>>    case TQ_atomic:   TQ_atomicLoc = Loc; return false;
>>> +  case TQ_unaligned: TQ_unalignedLoc = Loc; return false;
>>>    }
>>>
>>>    llvm_unreachable("Unknown type qualifier!");
>>> @@ -961,10 +963,10 @@ void DeclSpec::Finish(Sema &S, const Pri
>>>         TypeSpecSign != TSS_unspecified ||
>>>         TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||
>>>         TypeQualifiers)) {
>>> -    const unsigned NumLocs = 8;
>>> +    const unsigned NumLocs = 9;
>>>      SourceLocation ExtraLocs[NumLocs] = {
>>>        TSWLoc, TSCLoc, TSSLoc, AltiVecLoc,
>>> -      TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc
>>> +      TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc,
>>> TQ_unalignedLoc
>>>      };
>>>      FixItHint Hints[NumLocs];
>>>      SourceLocation FirstLoc;
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed May 11 13:38:21 2016
>>> @@ -3812,6 +3812,9 @@ void Sema::CodeCompleteTypeQualifiers(De
>>>    if (getLangOpts().C11 &&
>>>        !(DS.getTypeQualifiers() & DeclSpec::TQ_atomic))
>>>      Results.AddResult("_Atomic");
>>> +  if (getLangOpts().MSVCCompat &&
>>> +      !(DS.getTypeQualifiers() & DeclSpec::TQ_unaligned))
>>> +    Results.AddResult("__unaligned");
>>>    Results.ExitScope();
>>>    HandleCodeCompleteResults(this, CodeCompleter,
>>>                              Results.getCompletionContext(),
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May 11 13:38:21 2016
>>> @@ -3985,6 +3985,8 @@ Sema::ParsedFreeStandingDeclSpec(Scope *
>>>      // Restrict is covered above.
>>>      if (DS.getTypeQualifiers() & DeclSpec::TQ_atomic)
>>>        Diag(DS.getAtomicSpecLoc(), DiagID) << "_Atomic";
>>> +    if (DS.getTypeQualifiers() & DeclSpec::TQ_unaligned)
>>> +      Diag(DS.getUnalignedSpecLoc(), DiagID) << "__unaligned";
>>>    }
>>>
>>>    // Warn about ignored type attributes, for example:
>>> @@ -4242,6 +4244,11 @@ Decl *Sema::BuildAnonymousStructOrUnion(
>>>               diag::ext_anonymous_struct_union_qualified)
>>>            << Record->isUnion() << "_Atomic"
>>>            << FixItHint::CreateRemoval(DS.getAtomicSpecLoc());
>>> +      if (DS.getTypeQualifiers() & DeclSpec::TQ_unaligned)
>>> +        Diag(DS.getUnalignedSpecLoc(),
>>> +             diag::ext_anonymous_struct_union_qualified)
>>> +          << Record->isUnion() << "__unaligned"
>>> +          << FixItHint::CreateRemoval(DS.getUnalignedSpecLoc());
>>>
>>>        DS.ClearTypeQualifiers();
>>>      }
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed May 11 13:38:21 2016
>>> @@ -1503,6 +1503,7 @@ void Sema::actOnObjCTypeArgsOrProtocolQu
>>>                                                  SourceLocation(),
>>>                                                  SourceLocation(),
>>>                                                  SourceLocation(),
>>> +                                                SourceLocation(),
>>>                                                  SourceLocation()),
>>>                                                  parsedAttrs,
>>>                                                  starLoc);
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed May 11 13:38:21 2016
>>> @@ -7140,7 +7140,7 @@ checkPointerTypesForAssignment(Sema &S,
>>>      else if (lhq.getObjCLifetime() != rhq.getObjCLifetime())
>>>        ConvTy = Sema::IncompatiblePointerDiscardsQualifiers;
>>>
>>> -    // For GCC compatibility, other qualifier mismatches are treated
>>> +    // For GCC/MS compatibility, other qualifier mismatches are treated
>>>      // as still compatible in C.
>>>      else ConvTy = Sema::CompatiblePointerDiscardsQualifiers;
>>>    }
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed May 11 13:38:21 2016
>>> @@ -2951,6 +2951,10 @@ Sema::IsQualificationConversion(QualType
>>>
>>>      Qualifiers FromQuals = FromType.getQualifiers();
>>>      Qualifiers ToQuals = ToType.getQualifiers();
>>> +
>>> +    // Ignore __unaligned qualifier if this type is void.
>>> +    if (ToType.getUnqualifiedType()->isVoidType())
>>> +      FromQuals.removeUnaligned();
>>>
>>>      // Objective-C ARC:
>>>      //   Check Objective-C lifetime conversions.
>>> @@ -4159,6 +4163,10 @@ Sema::CompareReferenceRelationship(Sourc
>>>      T2Quals.removeObjCLifetime();
>>>    }
>>>
>>> +  // MS compiler ignores __unaligned qualifier for references; do the
>>> same.
>>> +  T1Quals.removeUnaligned();
>>> +  T2Quals.removeUnaligned();
>>> +
>>>    if (T1Quals == T2Quals)
>>>      return Ref_Compatible;
>>>    else if (T1Quals.compatiblyIncludes(T2Quals))
>>> @@ -4480,13 +4488,16 @@ TryReferenceInit(Sema &S, Expr *Init, Qu
>>>      // initialization fails.
>>>      //
>>>      // Note that we only want to check address spaces and
>>> cvr-qualifiers here.
>>> -    // ObjC GC and lifetime qualifiers aren't important.
>>> +    // ObjC GC, lifetime and unaligned qualifiers aren't important.
>>>      Qualifiers T1Quals = T1.getQualifiers();
>>>      Qualifiers T2Quals = T2.getQualifiers();
>>>      T1Quals.removeObjCGCAttr();
>>>      T1Quals.removeObjCLifetime();
>>>      T2Quals.removeObjCGCAttr();
>>>      T2Quals.removeObjCLifetime();
>>> +    // MS compiler ignores __unaligned qualifier for references; do the
>>> same.
>>> +    T1Quals.removeUnaligned();
>>> +    T2Quals.removeUnaligned();
>>>      if (!T1Quals.compatiblyIncludes(T2Quals))
>>>        return ICS;
>>>    }
>>> @@ -9134,6 +9145,15 @@ static void DiagnoseBadConversion(Sema &
>>>        MaybeEmitInheritedConstructorNote(S, Fn);
>>>        return;
>>>      }
>>> +
>>> +    if (FromQs.hasUnaligned() != ToQs.hasUnaligned()) {
>>> +      S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_unaligned)
>>> +        << (unsigned) FnKind << FnDesc
>>> +        << (FromExpr ? FromExpr->getSourceRange() : SourceRange())
>>> +        << FromTy << FromQs.hasUnaligned() << I+1;
>>> +      MaybeEmitInheritedConstructorNote(S, Fn);
>>> +      return;
>>> +    }
>>>
>>>      unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers();
>>>      assert(CVR && "unexpected qualifiers mismatch");
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaType.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaType.cpp Wed May 11 13:38:21 2016
>>> @@ -1785,12 +1785,13 @@ QualType Sema::BuildQualifiedType(QualTy
>>>  }
>>>
>>>  QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc,
>>> -                                  unsigned CVRA, const DeclSpec *DS) {
>>> +                                  unsigned CVRAU, const DeclSpec *DS) {
>>>    if (T.isNull())
>>>      return QualType();
>>>
>>> -  // Convert from DeclSpec::TQ to Qualifiers::TQ by just dropping
>>> TQ_atomic.
>>> -  unsigned CVR = CVRA & ~DeclSpec::TQ_atomic;
>>> +  // Convert from DeclSpec::TQ to Qualifiers::TQ by just dropping
>>> TQ_atomic and
>>> +  // TQ_unaligned;
>>> +  unsigned CVR = CVRAU & ~(DeclSpec::TQ_atomic |
>>> DeclSpec::TQ_unaligned);
>>>
>>>    // C11 6.7.3/5:
>>>    //   If the same qualifier appears more than once in the same
>>> @@ -1800,7 +1801,7 @@ QualType Sema::BuildQualifiedType(QualTy
>>>    // It's not specified what happens when the _Atomic qualifier is
>>> applied to
>>>    // a type specified with the _Atomic specifier, but we assume that
>>> this
>>>    // should be treated as if the _Atomic qualifier appeared multiple
>>> times.
>>> -  if (CVRA & DeclSpec::TQ_atomic && !T->isAtomicType()) {
>>> +  if (CVRAU & DeclSpec::TQ_atomic && !T->isAtomicType()) {
>>>      // C11 6.7.3/5:
>>>      //   If other qualifiers appear along with the _Atomic qualifier in
>>> a
>>>      //   specifier-qualifier-list, the resulting type is the
>>> so-qualified
>>> @@ -1817,7 +1818,9 @@ QualType Sema::BuildQualifiedType(QualTy
>>>      return BuildQualifiedType(T, Loc, Split.Quals);
>>>    }
>>>
>>> -  return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR), DS);
>>> +  Qualifiers Q = Qualifiers::fromCVRMask(CVR);
>>> +  Q.setUnaligned(CVRAU & DeclSpec::TQ_unaligned);
>>> +  return BuildQualifiedType(T, Loc, Q, DS);
>>>  }
>>>
>>>  /// \brief Build a paren type including \p T.
>>> @@ -2652,7 +2655,8 @@ void Sema::diagnoseIgnoredQualifiers(uns
>>>                                       SourceLocation ConstQualLoc,
>>>                                       SourceLocation VolatileQualLoc,
>>>                                       SourceLocation RestrictQualLoc,
>>> -                                     SourceLocation AtomicQualLoc) {
>>> +                                     SourceLocation AtomicQualLoc,
>>> +                                     SourceLocation UnalignedQualLoc) {
>>>    if (!Quals)
>>>      return;
>>>
>>> @@ -2660,26 +2664,27 @@ void Sema::diagnoseIgnoredQualifiers(uns
>>>      const char *Name;
>>>      unsigned Mask;
>>>      SourceLocation Loc;
>>> -  } const QualKinds[4] = {
>>> +  } const QualKinds[5] = {
>>>      { "const", DeclSpec::TQ_const, ConstQualLoc },
>>>      { "volatile", DeclSpec::TQ_volatile, VolatileQualLoc },
>>>      { "restrict", DeclSpec::TQ_restrict, RestrictQualLoc },
>>> -    { "_Atomic", DeclSpec::TQ_atomic, AtomicQualLoc }
>>> +    { "_Atomic", DeclSpec::TQ_atomic, AtomicQualLoc },
>>> +    { "__unaligned", DeclSpec::TQ_unaligned, UnalignedQualLoc }
>>>    };
>>>
>>>    SmallString<32> QualStr;
>>>    unsigned NumQuals = 0;
>>>    SourceLocation Loc;
>>> -  FixItHint FixIts[4];
>>> +  FixItHint FixIts[5];
>>>
>>>    // Build a string naming the redundant qualifiers.
>>> -  for (unsigned I = 0; I != 4; ++I) {
>>> -    if (Quals & QualKinds[I].Mask) {
>>> +  for (auto &E : QualKinds) {
>>> +    if (Quals & E.Mask) {
>>>        if (!QualStr.empty()) QualStr += ' ';
>>> -      QualStr += QualKinds[I].Name;
>>> +      QualStr += E.Name;
>>>
>>>        // If we have a location for the qualifier, offer a fixit.
>>> -      SourceLocation QualLoc = QualKinds[I].Loc;
>>> +      SourceLocation QualLoc = E.Loc;
>>>        if (QualLoc.isValid()) {
>>>          FixIts[NumQuals] = FixItHint::CreateRemoval(QualLoc);
>>>          if (Loc.isInvalid() ||
>>> @@ -2725,7 +2730,8 @@ static void diagnoseRedundantReturnTypeQ
>>>            SourceLocation::getFromRawEncoding(PTI.ConstQualLoc),
>>>            SourceLocation::getFromRawEncoding(PTI.VolatileQualLoc),
>>>            SourceLocation::getFromRawEncoding(PTI.RestrictQualLoc),
>>> -          SourceLocation::getFromRawEncoding(PTI.AtomicQualLoc));
>>> +          SourceLocation::getFromRawEncoding(PTI.AtomicQualLoc),
>>> +          SourceLocation::getFromRawEncoding(PTI.UnalignedQualLoc));
>>>        return;
>>>      }
>>>
>>> @@ -2761,7 +2767,8 @@ static void diagnoseRedundantReturnTypeQ
>>>                                D.getDeclSpec().getConstSpecLoc(),
>>>                                D.getDeclSpec().getVolatileSpecLoc(),
>>>                                D.getDeclSpec().getRestrictSpecLoc(),
>>> -                              D.getDeclSpec().getAtomicSpecLoc());
>>> +                              D.getDeclSpec().getAtomicSpecLoc(),
>>> +                              D.getDeclSpec().getUnalignedSpecLoc());
>>>  }
>>>
>>>  static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
>>>
>>> Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp (original)
>>> +++ cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp Wed May 11 13:38:21
>>> 2016
>>> @@ -293,3 +293,19 @@ int PR26105() {
>>>  }
>>>  // CHECK-DAG: @"\01??R<lambda_0>@?0??PR26105@@YAHXZ at QBE@H at Z"
>>>  // CHECK-DAG: @"\01??R<lambda_1>@?0???R<lambda_0>@?0??PR26105@
>>> @YAHXZ at QBE@H at Z@QBE at H@Z"
>>> +
>>> +int __unaligned * unaligned_foo1() { return 0; }
>>> +int __unaligned * __unaligned * unaligned_foo2() { return 0; }
>>> +__unaligned int unaligned_foo3() { return 0; }
>>> +void unaligned_foo4(int __unaligned *p1) {}
>>> +void unaligned_foo5(int __unaligned * __restrict p1) {}
>>> +template <typename T> T unaligned_foo6(T t) { return t; }
>>> +void unaligned_foo7() { unaligned_foo6<int *>(0); unaligned_foo6<int
>>> __unaligned *>(0); }
>>> +
>>> +// CHECK-DAG: @"\01?unaligned_foo1@@YAPFAHXZ"
>>> +// CHECK-DAG: @"\01?unaligned_foo2@@YAPFAPFAHXZ"
>>> +// CHECK-DAG: @"\01?unaligned_foo3@@YAHXZ"
>>> +// CHECK-DAG: @"\01?unaligned_foo4@@YAXPFAH at Z"
>>> +// CHECK-DAG: @"\01?unaligned_foo5@@YAXPIFAH at Z"
>>> +// CHECK-DAG: @"\01??$unaligned_foo6 at PAH@@YAPAHPAH at Z"
>>> +// CHECK-DAG: @"\01??$unaligned_foo6 at PFAH@@YAPFAHPFAH at Z"
>>>
>>> Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp (original)
>>> +++ cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp Wed May 11 13:38:21
>>> 2016
>>> @@ -55,3 +55,8 @@ struct Foo {};
>>>
>>>  Foo<&x<int>, &x<int>> Zoo;
>>>  // CHECK-DAG: "\01?Zoo@@3U?$Foo@$1??$x at H@@3HA$1?1 at 3HA@@A"
>>> +
>>> +template <typename T> T unaligned_x;
>>> +extern auto test_unaligned() { return unaligned_x<int __unaligned *>; }
>>> +// CHECK-DAG: "\01??$unaligned_x at PFAH@@3PFAHA"
>>> +
>>>
>>> Modified: cfe/trunk/test/Sema/MicrosoftExtensions.c
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/MicrosoftExtensions.c?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/test/Sema/MicrosoftExtensions.c (original)
>>> +++ cfe/trunk/test/Sema/MicrosoftExtensions.c Wed May 11 13:38:21 2016
>>> @@ -170,3 +170,11 @@ void myprintf(const char *f, ...) {
>>>      __va_start(ap, f); // expected-warning {{incompatible pointer types
>>> passing 'my_va_list'}}
>>>    }
>>>  }
>>> +
>>> +// __unaligned handling
>>> +void test_unaligned() {
>>> +  __unaligned int *p1 = 0;
>>> +  int *p2 = p1; // expected-warning {{initializing 'int *' with an
>>> expression of type '__unaligned int *' discards qualifiers}}
>>> +  __unaligned int *p3 = p2;
>>> +}
>>> +
>>>
>>> Modified: cfe/trunk/test/Sema/address_spaces.c
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_spaces.c?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/test/Sema/address_spaces.c (original)
>>> +++ cfe/trunk/test/Sema/address_spaces.c Wed May 11 13:38:21 2016
>>> @@ -20,7 +20,7 @@ void foo(_AS3 float *a,
>>>    _AS1 int arrarr[5][5]; // expected-error {{automatic variable
>>> qualified with an address space}}
>>>
>>>    __attribute__((address_space(-1))) int *_boundsA; // expected-error
>>> {{address space is negative}}
>>> -  __attribute__((address_space(0xFFFFFF))) int *_boundsB;
>>> +  __attribute__((address_space(0x7FFFFF))) int *_boundsB;
>>>    __attribute__((address_space(0x1000000))) int *_boundsC; //
>>> expected-error {{address space is larger than the maximum supported}}
>>>    // chosen specifically to overflow 32 bits and come out reasonable
>>>    __attribute__((address_space(4294967500))) int *_boundsD; //
>>> expected-error {{address space is larger than the maximum supported}}
>>> @@ -71,4 +71,4 @@ __attribute__((address_space("12"))) int
>>>  // Clang extension doesn't forbid operations on pointers to different
>>> address spaces.
>>>  char* cmp(_AS1 char *x,  _AS2 char *y) {
>>>    return x < y ? x : y; // expected-warning {{pointer type mismatch
>>> ('__attribute__((address_space(1))) char *' and
>>> '__attribute__((address_space(2))) char *')}}
>>> -}
>>> \ No newline at end of file
>>> +}
>>>
>>> Modified: cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c
>>> (original)
>>> +++ cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c Wed
>>> May 11 13:38:21 2016
>>> @@ -1,6 +1,6 @@
>>>  // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
>>>
>>> -#define OPENCL_CONSTANT 16776962
>>> +#define OPENCL_CONSTANT 8388354
>>>  int __attribute__((address_space(OPENCL_CONSTANT))) c[3] = {0};
>>>
>>>  void foo() {
>>>
>>> Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=269220&r1=269219&r2=269220&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
>>> +++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Wed May 11 13:38:21
>>> 2016
>>> @@ -1,5 +1,7 @@
>>> -// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft
>>> -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions
>>> -fcxx-exceptions
>>> +// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft
>>> -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions
>>> -fcxx-exceptions -DTEST1
>>> +// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft
>>> -Wc++11-extensions -Wno-long-long -verify -fexceptions -fcxx-exceptions
>>> -DTEST2
>>>
>>> +#if TEST1
>>>
>>>  // Microsoft doesn't validate exception specification.
>>>  namespace microsoft_exception_spec {
>>> @@ -80,7 +82,69 @@ struct M {
>>>  // __unaligned handling
>>>  typedef char __unaligned *aligned_type;
>>>  typedef struct UnalignedTag { int f; } __unaligned *aligned_type2;
>>> +typedef char __unaligned aligned_type3;
>>>
>>> +struct aligned_type4 {
>>> +  int i;
>>> +};
>>> +
>>> +__unaligned int aligned_type4::*p1_aligned_type4 = &aligned_type4::i;
>>> +int aligned_type4::* __unaligned p2_aligned_type4 = &aligned_type4::i;
>>> +__unaligned int aligned_type4::* __unaligned p3_aligned_type4 =
>>> &aligned_type4::i;
>>> +
>>> +// Check that __unaligned qualifier can be used for overloading
>>> +void foo_unaligned(int *arg) {}
>>> +void foo_unaligned(__unaligned int *arg) {}
>>> +void foo_unaligned(int arg) {} // expected-note {{previous definition
>>> is here}}
>>> +void foo_unaligned(__unaligned int arg) {} // expected-error
>>> {{redefinition of 'foo_unaligned'}}
>>> +class A_unaligned {};
>>> +class B_unaligned : public A_unaligned {};
>>> +int foo_unaligned(__unaligned A_unaligned *arg) { return 0; }
>>> +void *foo_unaligned(B_unaligned *arg) { return 0; }
>>> +
>>> +void test_unaligned() {
>>> +  int *p1 = 0;
>>> +  foo_unaligned(p1);
>>> +
>>> +  __unaligned int *p2 = 0;
>>> +  foo_unaligned(p2);
>>> +
>>> +  __unaligned B_unaligned *p3 = 0;
>>> +  int p4 = foo_unaligned(p3);
>>> +
>>> +  B_unaligned *p5 = p3; // expected-error {{cannot initialize a
>>> variable of type 'B_unaligned *' with an lvalue of type '__unaligned
>>> B_unaligned *'}}
>>> +
>>> +  __unaligned B_unaligned *p6 = p3;
>>> +
>>> +  p1_aligned_type4 = p2_aligned_type4;
>>> +  p2_aligned_type4 = p1_aligned_type4; // expected-error {{assigning to
>>> 'int aligned_type4::*' from incompatible type '__unaligned int
>>> aligned_type4::*'}}
>>> +  p3_aligned_type4 = p1_aligned_type4;
>>> +}
>>> +
>>> +// Test from PR27367
>>> +// We should accept assignment of an __unaligned pointer to a
>>> non-__unaligned
>>> +// pointer to void
>>> +typedef struct _ITEMIDLIST { int i; } ITEMIDLIST;
>>> +typedef ITEMIDLIST __unaligned *LPITEMIDLIST;
>>> +extern "C" __declspec(dllimport) void __stdcall CoTaskMemFree(void* pv);
>>> +__inline void FreeIDListArray(LPITEMIDLIST *ppidls) {
>>> +  CoTaskMemFree(*ppidls);
>>> +  __unaligned int *x = 0;
>>> +  void *y = x;
>>> +}
>>> +
>>> +// Test from PR27666
>>> +// We should accept type conversion of __unaligned to non-__unaligned
>>> references
>>> +typedef struct in_addr {
>>> +public:
>>> +  in_addr(in_addr &a) {} // expected-note {{candidate constructor not
>>> viable: no known conversion from '__unaligned IN_ADDR *' (aka '__unaligned
>>> in_addr *') to 'in_addr &' for 1st argument; dereference the argument with
>>> *}}
>>> +  in_addr(in_addr *a) {} // expected-note {{candidate constructor not
>>> viable: 1st argument ('__unaligned IN_ADDR *' (aka '__unaligned in_addr
>>> *')) would lose __unaligned qualifier}}
>>> +} IN_ADDR;
>>> +
>>> +void f(IN_ADDR __unaligned *a) {
>>> +  IN_ADDR local_addr = *a;
>>> +  IN_ADDR local_addr2 = a; // expected-error {{no viable conversion
>>> from '__unaligned IN_ADDR *' (aka '__unaligned in_addr *') to 'IN_ADDR'
>>> (aka 'in_addr')}}
>>> +}
>>>
>>>  template<typename T> void h1(T (__stdcall M::* const )()) { }
>>>
>>> @@ -420,3 +484,15 @@ struct S {
>>>
>>>  int S::fn() { return 0; } // expected-warning {{is missing exception
>>> specification}}
>>>  }
>>> +
>>> +#elif TEST2
>>> +
>>> +// Check that __unaligned is not recognized if MS extensions are not
>>> enabled
>>> +typedef char __unaligned *aligned_type; // expected-error {{expected
>>> ';' after top level declarator}}
>>> +
>>> +#else
>>> +
>>> +#error Unknown test mode
>>> +
>>> +#endif
>>> +
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160519/cdd71cc1/attachment-0001.html>


More information about the cfe-commits mailing list