<div dir="ltr">This very likely caused <a href="https://llvm.org/bugs/show_bug.cgi?id=27367">https://llvm.org/bugs/show_bug.cgi?id=27367</a></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 15, 2016 at 4:03 AM, Andrey Bokhanko via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: asbokhan<br>
Date: Fri Apr 15 03:03:51 2016<br>
New Revision: 266415<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=266415&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=266415&view=rev</a><br>
Log:<br>
[MSVC Compat] Implementation of __unaligned (MS extension) as a type qualifier<br>
<br>
This patch implements __unaligned as a type qualifier; before that, it was<br>
modeled as an attribute. Proper mangling of __unaligned is implemented as well.<br>
Some OpenCL code/tests are tangenially affected, as they relied on existing<br>
number and sizes of type qualifiers.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D18596" rel="noreferrer" target="_blank">http://reviews.llvm.org/D18596</a><br>
<br>
Modified:<br>
cfe/trunk/include/clang/AST/Type.h<br>
cfe/trunk/include/clang/Basic/AddressSpaces.h<br>
cfe/trunk/include/clang/Basic/Attr.td<br>
cfe/trunk/include/clang/Sema/DeclSpec.h<br>
cfe/trunk/include/clang/Sema/Sema.h<br>
cfe/trunk/lib/AST/MicrosoftMangle.cpp<br>
cfe/trunk/lib/AST/TypePrinter.cpp<br>
cfe/trunk/lib/Parse/ParseDecl.cpp<br>
cfe/trunk/lib/Parse/ParseTentative.cpp<br>
cfe/trunk/lib/Sema/DeclSpec.cpp<br>
cfe/trunk/lib/Sema/SemaCodeComplete.cpp<br>
cfe/trunk/lib/Sema/SemaDecl.cpp<br>
cfe/trunk/lib/Sema/SemaDeclObjC.cpp<br>
cfe/trunk/lib/Sema/SemaExpr.cpp<br>
cfe/trunk/lib/Sema/SemaType.cpp<br>
cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp<br>
cfe/trunk/test/Sema/MicrosoftExtensions.c<br>
cfe/trunk/test/Sema/address_spaces.c<br>
cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c<br>
cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/Type.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/Type.h (original)<br>
+++ cfe/trunk/include/clang/AST/Type.h Fri Apr 15 03:03:51 2016<br>
@@ -152,8 +152,8 @@ public:<br>
<br>
enum {<br>
/// The maximum supported address space number.<br>
- /// 24 bits should be enough for anyone.<br>
- MaxAddressSpace = 0xffffffu,<br>
+ /// 23 bits should be enough for anyone.<br>
+ MaxAddressSpace = 0x7fffffu,<br>
<br>
/// The width of the "fast" qualifier mask.<br>
FastWidth = 3,<br>
@@ -265,6 +265,13 @@ public:<br>
Mask |= mask;<br>
}<br>
<br>
+ bool hasUnaligned() const { return Mask & UMask; }<br>
+ void setUnaligned(bool flag) {<br>
+ Mask = (Mask & ~UMask) | (flag ? UMask : 0);<br>
+ }<br>
+ void removeUnaligned() { Mask &= ~UMask; }<br>
+ void addUnaligned() { Mask |= UMask; }<br>
+<br>
bool hasObjCGCAttr() const { return Mask & GCAttrMask; }<br>
GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }<br>
void setObjCGCAttr(GC type) {<br>
@@ -433,7 +440,9 @@ public:<br>
// ObjC lifetime qualifiers must match exactly.<br>
getObjCLifetime() == other.getObjCLifetime() &&<br>
// CVR qualifiers may subset.<br>
- (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));<br>
+ (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&<br>
+ // U qualifier may superset.<br>
+ (!(other.Mask & UMask) || (Mask & UMask));<br>
}<br>
<br>
/// \brief Determines if these qualifiers compatibly include another set of<br>
@@ -501,16 +510,19 @@ public:<br>
<br>
private:<br>
<br>
- // bits: |0 1 2|3 .. 4|5 .. 7|8 ... 31|<br>
- // |C R V|GCAttr|Lifetime|AddressSpace|<br>
+ // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31|<br>
+ // |C R V|U|GCAttr|Lifetime|AddressSpace|<br>
uint32_t Mask;<br>
<br>
- static const uint32_t GCAttrMask = 0x18;<br>
- static const uint32_t GCAttrShift = 3;<br>
- static const uint32_t LifetimeMask = 0xE0;<br>
- static const uint32_t LifetimeShift = 5;<br>
- static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask);<br>
- static const uint32_t AddressSpaceShift = 8;<br>
+ static const uint32_t UMask = 0x8;<br>
+ static const uint32_t UShift = 3;<br>
+ static const uint32_t GCAttrMask = 0x30;<br>
+ static const uint32_t GCAttrShift = 4;<br>
+ static const uint32_t LifetimeMask = 0x1C0;<br>
+ static const uint32_t LifetimeShift = 6;<br>
+ static const uint32_t AddressSpaceMask =<br>
+ ~(CVRMask | UMask | GCAttrMask | LifetimeMask);<br>
+ static const uint32_t AddressSpaceShift = 9;<br>
};<br>
<br>
/// A std::pair-like structure for storing a qualified type split<br>
<br>
Modified: cfe/trunk/include/clang/Basic/AddressSpaces.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AddressSpaces.h?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AddressSpaces.h?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/AddressSpaces.h (original)<br>
+++ cfe/trunk/include/clang/Basic/AddressSpaces.h Fri Apr 15 03:03:51 2016<br>
@@ -25,7 +25,7 @@ namespace LangAS {<br>
/// This uses a high starting offset so as not to conflict with any address<br>
/// space used by a target.<br>
enum ID {<br>
- Offset = 0xFFFF00,<br>
+ Offset = 0x7FFF00,<br>
<br>
opencl_global = Offset,<br>
opencl_local,<br>
<br>
Modified: cfe/trunk/include/clang/Basic/Attr.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/Attr.td (original)<br>
+++ cfe/trunk/include/clang/Basic/Attr.td Fri Apr 15 03:03:51 2016<br>
@@ -2149,10 +2149,6 @@ def InitSeg : Attr {<br>
}];<br>
}<br>
<br>
-def Unaligned : IgnoredAttr {<br>
- let Spellings = [Keyword<"__unaligned">];<br>
-}<br>
-<br>
def LoopHint : Attr {<br>
/// #pragma clang loop <option> directive<br>
/// vectorize: vectorizes loop operations if State == Enable.<br>
<br>
Modified: cfe/trunk/include/clang/Sema/DeclSpec.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)<br>
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Fri Apr 15 03:03:51 2016<br>
@@ -313,8 +313,10 @@ public:<br>
TQ_volatile = 4,<br>
// This has no corresponding Qualifiers::TQ value, because it's not treated<br>
// as a qualifier in our type system.<br>
- TQ_atomic = 8<br>
- };<br>
+ TQ_atomic = 8,<br>
+ // There is no corresponding Qualifiers::TQ value, but it's kept separately<br>
+ // in a dedicated Qualifiers::Mask bit.<br>
+ TQ_unaligned = 16 };<br>
<br>
/// ParsedSpecifiers - Flags to query which specifiers were applied. This is<br>
/// returned by getParsedSpecifiers.<br>
@@ -344,7 +346,7 @@ private:<br>
unsigned TypeSpecPipe : 1;<br>
<br>
// type-qualifiers<br>
- unsigned TypeQualifiers : 4; // Bitwise OR of TQ.<br>
+ unsigned TypeQualifiers : 5; // Bitwise OR of TQ.<br>
<br>
// function-specifier<br>
unsigned FS_inline_specified : 1;<br>
@@ -386,7 +388,8 @@ private:<br>
/// TSTNameLoc provides source range info for tag types.<br>
SourceLocation TSTNameLoc;<br>
SourceRange TypeofParensRange;<br>
- SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc;<br>
+ SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc,<br>
+ TQ_unalignedLoc;<br>
SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc;<br>
SourceLocation FS_forceinlineLoc;<br>
SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc, ConceptLoc;<br>
@@ -540,6 +543,7 @@ public:<br>
SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }<br>
SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }<br>
SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; }<br>
+ SourceLocation getUnalignedSpecLoc() const { return TQ_unalignedLoc; }<br>
SourceLocation getPipeLoc() const { return TQ_pipeLoc; }<br>
<br>
/// \brief Clear out all of the type qualifiers.<br>
@@ -549,6 +553,7 @@ public:<br>
TQ_restrictLoc = SourceLocation();<br>
TQ_volatileLoc = SourceLocation();<br>
TQ_atomicLoc = SourceLocation();<br>
+ TQ_unalignedLoc = SourceLocation();<br>
TQ_pipeLoc = SourceLocation();<br>
}<br>
<br>
@@ -1114,8 +1119,8 @@ struct DeclaratorChunk {<br>
};<br>
<br>
struct PointerTypeInfo : TypeInfoCommon {<br>
- /// The type qualifiers: const/volatile/restrict/atomic.<br>
- unsigned TypeQuals : 4;<br>
+ /// The type qualifiers: const/volatile/restrict/atomic/unaligned.<br>
+ unsigned TypeQuals : 5;<br>
<br>
/// The location of the const-qualifier, if any.<br>
unsigned ConstQualLoc;<br>
@@ -1129,6 +1134,9 @@ struct DeclaratorChunk {<br>
/// The location of the _Atomic-qualifier, if any.<br>
unsigned AtomicQualLoc;<br>
<br>
+ /// The location of the __unaligned-qualifier, if any.<br>
+ unsigned UnalignedQualLoc;<br>
+<br>
void destroy() {<br>
}<br>
};<br>
@@ -1469,7 +1477,8 @@ struct DeclaratorChunk {<br>
SourceLocation ConstQualLoc,<br>
SourceLocation VolatileQualLoc,<br>
SourceLocation RestrictQualLoc,<br>
- SourceLocation AtomicQualLoc) {<br>
+ SourceLocation AtomicQualLoc,<br>
+ SourceLocation UnalignedQualLoc) {<br>
DeclaratorChunk I;<br>
I.Kind = Pointer;<br>
I.Loc = Loc;<br>
@@ -1478,6 +1487,7 @@ struct DeclaratorChunk {<br>
I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding();<br>
I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding();<br>
I.Ptr.AtomicQualLoc = AtomicQualLoc.getRawEncoding();<br>
+ I.Ptr.UnalignedQualLoc = UnalignedQualLoc.getRawEncoding();<br>
I.Ptr.AttrList = nullptr;<br>
return I;<br>
}<br>
<br>
Modified: cfe/trunk/include/clang/Sema/Sema.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Sema/Sema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Apr 15 03:03:51 2016<br>
@@ -1647,7 +1647,8 @@ public:<br>
SourceLocation ConstQualLoc = SourceLocation(),<br>
SourceLocation VolatileQualLoc = SourceLocation(),<br>
SourceLocation RestrictQualLoc = SourceLocation(),<br>
- SourceLocation AtomicQualLoc = SourceLocation());<br>
+ SourceLocation AtomicQualLoc = SourceLocation(),<br>
+ SourceLocation UnalignedQualLoc = SourceLocation());<br>
<br>
static bool adjustContextForLocalExternDecl(DeclContext *&DC);<br>
void DiagnoseFunctionSpecifiers(const DeclSpec &DS);<br>
<br>
Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)<br>
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Apr 15 03:03:51 2016<br>
@@ -1444,6 +1444,9 @@ void MicrosoftCXXNameMangler::manglePoin<br>
(PointeeType.isNull() || !PointeeType->isFunctionType()))<br>
Out << 'E';<br>
<br>
+ if (!PointeeType.isNull() && PointeeType.getLocalQualifiers().hasUnaligned())<br>
+ Out << 'F';<br>
+<br>
if (HasRestrict)<br>
Out << 'I';<br>
}<br>
@@ -1577,6 +1580,8 @@ void MicrosoftCXXNameMangler::mangleType<br>
}<br>
break;<br>
case QMM_Result:<br>
+ // Presence of __unaligned qualifier shouldn't affect mangling here.<br>
+ Quals.removeUnaligned();<br>
if ((!IsPointer && Quals) || isa<TagType>(T)) {<br>
Out << '?';<br>
mangleQualifiers(Quals, false);<br>
<br>
Modified: cfe/trunk/lib/AST/TypePrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)<br>
+++ cfe/trunk/lib/AST/TypePrinter.cpp Fri Apr 15 03:03:51 2016<br>
@@ -1592,6 +1592,12 @@ void Qualifiers::print(raw_ostream &OS,<br>
AppendTypeQualList(OS, quals, Policy.LangOpts.C99);<br>
addSpace = true;<br>
}<br>
+ if (hasUnaligned()) {<br>
+ if (addSpace)<br>
+ OS << ' ';<br>
+ OS << "__unaligned";<br>
+ addSpace = true;<br>
+ }<br>
if (unsigned addrspace = getAddressSpace()) {<br>
if (addSpace)<br>
OS << ' ';<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Apr 15 03:03:51 2016<br>
@@ -609,7 +609,6 @@ void Parser::ParseMicrosoftTypeAttribute<br>
case tok::kw___ptr64:<br>
case tok::kw___w64:<br>
case tok::kw___ptr32:<br>
- case tok::kw___unaligned:<br>
case tok::kw___sptr:<br>
case tok::kw___uptr: {<br>
IdentifierInfo *AttrName = Tok.getIdentifierInfo();<br>
@@ -3087,6 +3086,11 @@ void Parser::ParseDeclarationSpecifiers(<br>
break;<br>
}<br>
<br>
+ case tok::kw___unaligned:<br>
+ isInvalid = DS.SetTypeQual(DeclSpec::TQ_unaligned, Loc, PrevSpec, DiagID,<br>
+ getLangOpts());<br>
+ break;<br>
+<br>
case tok::kw___sptr:<br>
case tok::kw___uptr:<br>
case tok::kw___ptr64:<br>
@@ -3097,7 +3101,6 @@ void Parser::ParseDeclarationSpecifiers(<br>
case tok::kw___fastcall:<br>
case tok::kw___thiscall:<br>
case tok::kw___vectorcall:<br>
- case tok::kw___unaligned:<br>
ParseMicrosoftTypeAttributes(DS.getAttributes());<br>
continue;<br>
<br>
@@ -4819,6 +4822,10 @@ void Parser::ParseTypeQualifierListOpt(D<br>
ParseOpenCLQualifiers(DS.getAttributes());<br>
break;<br>
<br>
+ case tok::kw___unaligned:<br>
+ isInvalid = DS.SetTypeQual(DeclSpec::TQ_unaligned, Loc, PrevSpec, DiagID,<br>
+ getLangOpts());<br>
+ break;<br>
case tok::kw___uptr:<br>
// GNU libc headers in C mode use '__uptr' as an identifer which conflicts<br>
// with the MS modifier keyword.<br>
@@ -4836,7 +4843,6 @@ void Parser::ParseTypeQualifierListOpt(D<br>
case tok::kw___fastcall:<br>
case tok::kw___thiscall:<br>
case tok::kw___vectorcall:<br>
- case tok::kw___unaligned:<br>
if (AttrReqs & AR_DeclspecAttributesParsed) {<br>
ParseMicrosoftTypeAttributes(DS.getAttributes());<br>
continue;<br>
@@ -5059,7 +5065,8 @@ void Parser::ParseDeclaratorInternal(Dec<br>
DS.getConstSpecLoc(),<br>
DS.getVolatileSpecLoc(),<br>
DS.getRestrictSpecLoc(),<br>
- DS.getAtomicSpecLoc()),<br>
+ DS.getAtomicSpecLoc(),<br>
+ DS.getUnalignedSpecLoc()),<br>
DS.getAttributes(),<br>
SourceLocation());<br>
else<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Fri Apr 15 03:03:51 2016<br>
@@ -833,7 +833,7 @@ Parser::TPResult Parser::TryParseDeclara<br>
// '(' abstract-declarator ')'<br>
if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,<br>
tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,<br>
- tok::kw___vectorcall, tok::kw___unaligned))<br>
+ tok::kw___vectorcall))<br>
return TPResult::True; // attributes indicate declaration<br>
TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);<br>
if (TPR != TPResult::Ambiguous)<br>
<br>
Modified: cfe/trunk/lib/Sema/DeclSpec.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/DeclSpec.cpp (original)<br>
+++ cfe/trunk/lib/Sema/DeclSpec.cpp Fri Apr 15 03:03:51 2016<br>
@@ -494,6 +494,7 @@ const char *DeclSpec::getSpecifierName(T<br>
case DeclSpec::TQ_restrict: return "restrict";<br>
case DeclSpec::TQ_volatile: return "volatile";<br>
case DeclSpec::TQ_atomic: return "_Atomic";<br>
+ case DeclSpec::TQ_unaligned: return "__unaligned";<br>
}<br>
llvm_unreachable("Unknown typespec!");<br>
}<br>
@@ -796,6 +797,7 @@ bool DeclSpec::SetTypeQual(TQ T, SourceL<br>
case TQ_restrict: TQ_restrictLoc = Loc; return false;<br>
case TQ_volatile: TQ_volatileLoc = Loc; return false;<br>
case TQ_atomic: TQ_atomicLoc = Loc; return false;<br>
+ case TQ_unaligned: TQ_unalignedLoc = Loc; return false;<br>
}<br>
<br>
llvm_unreachable("Unknown type qualifier!");<br>
@@ -961,10 +963,10 @@ void DeclSpec::Finish(Sema &S, const Pri<br>
TypeSpecSign != TSS_unspecified ||<br>
TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||<br>
TypeQualifiers)) {<br>
- const unsigned NumLocs = 8;<br>
+ const unsigned NumLocs = 9;<br>
SourceLocation ExtraLocs[NumLocs] = {<br>
TSWLoc, TSCLoc, TSSLoc, AltiVecLoc,<br>
- TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc<br>
+ TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc, TQ_unalignedLoc<br>
};<br>
FixItHint Hints[NumLocs];<br>
SourceLocation FirstLoc;<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Apr 15 03:03:51 2016<br>
@@ -3812,6 +3812,9 @@ void Sema::CodeCompleteTypeQualifiers(De<br>
if (getLangOpts().C11 &&<br>
!(DS.getTypeQualifiers() & DeclSpec::TQ_atomic))<br>
Results.AddResult("_Atomic");<br>
+ if (getLangOpts().MSVCCompat &&<br>
+ !(DS.getTypeQualifiers() & DeclSpec::TQ_unaligned))<br>
+ Results.AddResult("__unaligned");<br>
Results.ExitScope();<br>
HandleCodeCompleteResults(this, CodeCompleter,<br>
Results.getCompletionContext(),<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Apr 15 03:03:51 2016<br>
@@ -3974,6 +3974,8 @@ Sema::ParsedFreeStandingDeclSpec(Scope *<br>
// Restrict is covered above.<br>
if (DS.getTypeQualifiers() & DeclSpec::TQ_atomic)<br>
Diag(DS.getAtomicSpecLoc(), DiagID) << "_Atomic";<br>
+ if (DS.getTypeQualifiers() & DeclSpec::TQ_unaligned)<br>
+ Diag(DS.getUnalignedSpecLoc(), DiagID) << "__unaligned";<br>
}<br>
<br>
// Warn about ignored type attributes, for example:<br>
@@ -4231,6 +4233,11 @@ Decl *Sema::BuildAnonymousStructOrUnion(<br>
diag::ext_anonymous_struct_union_qualified)<br>
<< Record->isUnion() << "_Atomic"<br>
<< FixItHint::CreateRemoval(DS.getAtomicSpecLoc());<br>
+ if (DS.getTypeQualifiers() & DeclSpec::TQ_unaligned)<br>
+ Diag(DS.getUnalignedSpecLoc(),<br>
+ diag::ext_anonymous_struct_union_qualified)<br>
+ << Record->isUnion() << "__unaligned"<br>
+ << FixItHint::CreateRemoval(DS.getUnalignedSpecLoc());<br>
<br>
DS.ClearTypeQualifiers();<br>
}<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Apr 15 03:03:51 2016<br>
@@ -1503,6 +1503,7 @@ void Sema::actOnObjCTypeArgsOrProtocolQu<br>
SourceLocation(),<br>
SourceLocation(),<br>
SourceLocation(),<br>
+ SourceLocation(),<br>
SourceLocation()),<br>
parsedAttrs,<br>
starLoc);<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Apr 15 03:03:51 2016<br>
@@ -7138,7 +7138,7 @@ checkPointerTypesForAssignment(Sema &S,<br>
else if (lhq.getObjCLifetime() != rhq.getObjCLifetime())<br>
ConvTy = Sema::IncompatiblePointerDiscardsQualifiers;<br>
<br>
- // For GCC compatibility, other qualifier mismatches are treated<br>
+ // For GCC/MS compatibility, other qualifier mismatches are treated<br>
// as still compatible in C.<br>
else ConvTy = Sema::CompatiblePointerDiscardsQualifiers;<br>
}<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaType.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaType.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Apr 15 03:03:51 2016<br>
@@ -1743,12 +1743,13 @@ QualType Sema::BuildQualifiedType(QualTy<br>
}<br>
<br>
QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc,<br>
- unsigned CVRA, const DeclSpec *DS) {<br>
+ unsigned CVRAU, const DeclSpec *DS) {<br>
if (T.isNull())<br>
return QualType();<br>
<br>
- // Convert from DeclSpec::TQ to Qualifiers::TQ by just dropping TQ_atomic.<br>
- unsigned CVR = CVRA & ~DeclSpec::TQ_atomic;<br>
+ // Convert from DeclSpec::TQ to Qualifiers::TQ by just dropping TQ_atomic and<br>
+ // TQ_unaligned;<br>
+ unsigned CVR = CVRAU & ~DeclSpec::TQ_atomic & ~DeclSpec::TQ_unaligned;<br>
<br>
// C11 6.7.3/5:<br>
// If the same qualifier appears more than once in the same<br>
@@ -1758,7 +1759,7 @@ QualType Sema::BuildQualifiedType(QualTy<br>
// It's not specified what happens when the _Atomic qualifier is applied to<br>
// a type specified with the _Atomic specifier, but we assume that this<br>
// should be treated as if the _Atomic qualifier appeared multiple times.<br>
- if (CVRA & DeclSpec::TQ_atomic && !T->isAtomicType()) {<br>
+ if (CVRAU & DeclSpec::TQ_atomic && !T->isAtomicType()) {<br>
// C11 6.7.3/5:<br>
// If other qualifiers appear along with the _Atomic qualifier in a<br>
// specifier-qualifier-list, the resulting type is the so-qualified<br>
@@ -1775,7 +1776,9 @@ QualType Sema::BuildQualifiedType(QualTy<br>
return BuildQualifiedType(T, Loc, Split.Quals);<br>
}<br>
<br>
- return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR), DS);<br>
+ Qualifiers Q = Qualifiers::fromCVRMask(CVR);<br>
+ Q.setUnaligned(CVRAU & DeclSpec::TQ_unaligned);<br>
+ return BuildQualifiedType(T, Loc, Q, DS);<br>
}<br>
<br>
/// \brief Build a paren type including \p T.<br>
@@ -2617,7 +2620,8 @@ void Sema::diagnoseIgnoredQualifiers(uns<br>
SourceLocation ConstQualLoc,<br>
SourceLocation VolatileQualLoc,<br>
SourceLocation RestrictQualLoc,<br>
- SourceLocation AtomicQualLoc) {<br>
+ SourceLocation AtomicQualLoc,<br>
+ SourceLocation UnalignedQualLoc) {<br>
if (!Quals)<br>
return;<br>
<br>
@@ -2625,20 +2629,21 @@ void Sema::diagnoseIgnoredQualifiers(uns<br>
const char *Name;<br>
unsigned Mask;<br>
SourceLocation Loc;<br>
- } const QualKinds[4] = {<br>
+ } const QualKinds[5] = {<br>
{ "const", DeclSpec::TQ_const, ConstQualLoc },<br>
{ "volatile", DeclSpec::TQ_volatile, VolatileQualLoc },<br>
{ "restrict", DeclSpec::TQ_restrict, RestrictQualLoc },<br>
- { "_Atomic", DeclSpec::TQ_atomic, AtomicQualLoc }<br>
+ { "_Atomic", DeclSpec::TQ_atomic, AtomicQualLoc },<br>
+ { "__unaligned", DeclSpec::TQ_unaligned, UnalignedQualLoc }<br>
};<br>
<br>
SmallString<32> QualStr;<br>
unsigned NumQuals = 0;<br>
SourceLocation Loc;<br>
- FixItHint FixIts[4];<br>
+ FixItHint FixIts[5];<br>
<br>
// Build a string naming the redundant qualifiers.<br>
- for (unsigned I = 0; I != 4; ++I) {<br>
+ for (unsigned I = 0; I != 5; ++I) {<br>
if (Quals & QualKinds[I].Mask) {<br>
if (!QualStr.empty()) QualStr += ' ';<br>
QualStr += QualKinds[I].Name;<br>
@@ -2690,7 +2695,8 @@ static void diagnoseRedundantReturnTypeQ<br>
SourceLocation::getFromRawEncoding(PTI.ConstQualLoc),<br>
SourceLocation::getFromRawEncoding(PTI.VolatileQualLoc),<br>
SourceLocation::getFromRawEncoding(PTI.RestrictQualLoc),<br>
- SourceLocation::getFromRawEncoding(PTI.AtomicQualLoc));<br>
+ SourceLocation::getFromRawEncoding(PTI.AtomicQualLoc),<br>
+ SourceLocation::getFromRawEncoding(PTI.UnalignedQualLoc));<br>
return;<br>
}<br>
<br>
@@ -2726,7 +2732,8 @@ static void diagnoseRedundantReturnTypeQ<br>
D.getDeclSpec().getConstSpecLoc(),<br>
D.getDeclSpec().getVolatileSpecLoc(),<br>
D.getDeclSpec().getRestrictSpecLoc(),<br>
- D.getDeclSpec().getAtomicSpecLoc());<br>
+ D.getDeclSpec().getAtomicSpecLoc(),<br>
+ D.getDeclSpec().getUnalignedSpecLoc());<br>
}<br>
<br>
static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp Fri Apr 15 03:03:51 2016<br>
@@ -293,3 +293,14 @@ int PR26105() {<br>
}<br>
// CHECK-DAG: @"\01??R<lambda_0>@?0??PR26105@@YAHXZ@QBE@H@Z"<br>
// CHECK-DAG: @"\01??R<lambda_1>@?0???R<lambda_0>@?0??PR26105@@YAHXZ@QBE@H@Z@QBE@H@Z"<br>
+<br>
+int __unaligned * unaligned_foo1() { return 0; }<br>
+int __unaligned * __unaligned * unaligned_foo2() { return 0; }<br>
+__unaligned int unaligned_foo3() { return 0; }<br>
+void unaligned_foo4(int __unaligned *p1) {}<br>
+<br>
+// CHECK-DAG: @"\01?unaligned_foo1@@YAPFAHXZ"<br>
+// CHECK-DAG: @"\01?unaligned_foo2@@YAPFAPFAHXZ"<br>
+// CHECK-DAG: @"\01?unaligned_foo3@@YAHXZ"<br>
+// CHECK-DAG: @"\01?unaligned_foo4@@YAXPFAH@Z"<br>
+<br>
<br>
Modified: cfe/trunk/test/Sema/MicrosoftExtensions.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/MicrosoftExtensions.c?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/MicrosoftExtensions.c?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/MicrosoftExtensions.c (original)<br>
+++ cfe/trunk/test/Sema/MicrosoftExtensions.c Fri Apr 15 03:03:51 2016<br>
@@ -170,3 +170,11 @@ void myprintf(const char *f, ...) {<br>
__va_start(ap, f); // expected-warning {{incompatible pointer types passing 'my_va_list'}}<br>
}<br>
}<br>
+<br>
+// __unaligned handling<br>
+void test_unaligned() {<br>
+ __unaligned int *p1 = 0;<br>
+ int *p2 = p1; // expected-warning {{initializing 'int *' with an expression of type '__unaligned int *' discards qualifiers}}<br>
+ __unaligned int *p3 = p2;<br>
+}<br>
+<br>
<br>
Modified: cfe/trunk/test/Sema/address_spaces.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_spaces.c?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_spaces.c?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/address_spaces.c (original)<br>
+++ cfe/trunk/test/Sema/address_spaces.c Fri Apr 15 03:03:51 2016<br>
@@ -20,7 +20,7 @@ void foo(_AS3 float *a,<br>
_AS1 int arrarr[5][5]; // expected-error {{automatic variable qualified with an address space}}<br>
<br>
__attribute__((address_space(-1))) int *_boundsA; // expected-error {{address space is negative}}<br>
- __attribute__((address_space(0xFFFFFF))) int *_boundsB;<br>
+ __attribute__((address_space(0x7FFFFF))) int *_boundsB;<br>
__attribute__((address_space(0x1000000))) int *_boundsC; // expected-error {{address space is larger than the maximum supported}}<br>
// chosen specifically to overflow 32 bits and come out reasonable<br>
__attribute__((address_space(4294967500))) int *_boundsD; // expected-error {{address space is larger than the maximum supported}}<br>
@@ -71,4 +71,4 @@ __attribute__((address_space("12"))) int<br>
// Clang extension doesn't forbid operations on pointers to different address spaces.<br>
char* cmp(_AS1 char *x, _AS2 char *y) {<br>
return x < y ? x : y; // expected-warning {{pointer type mismatch ('__attribute__((address_space(1))) char *' and '__attribute__((address_space(2))) char *')}}<br>
-}<br>
\ No newline at end of file<br>
+}<br>
<br>
Modified: cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c (original)<br>
+++ cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c Fri Apr 15 03:03:51 2016<br>
@@ -1,6 +1,6 @@<br>
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only<br>
<br>
-#define OPENCL_CONSTANT 16776962<br>
+#define OPENCL_CONSTANT 8388354<br>
int __attribute__((address_space(OPENCL_CONSTANT))) c[3] = {0};<br>
<br>
void foo() {<br>
<br>
Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=266415&r1=266414&r2=266415&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=266415&r1=266414&r2=266415&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Fri Apr 15 03:03:51 2016<br>
@@ -1,5 +1,7 @@<br>
-// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions -fcxx-exceptions<br>
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions -fcxx-exceptions -DTEST1<br>
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fexceptions -fcxx-exceptions -DTEST2<br>
<br>
+#if TEST1<br>
<br>
// Microsoft doesn't validate exception specification.<br>
namespace microsoft_exception_spec {<br>
@@ -80,7 +82,32 @@ struct M {<br>
// __unaligned handling<br>
typedef char __unaligned *aligned_type;<br>
typedef struct UnalignedTag { int f; } __unaligned *aligned_type2;<br>
+typedef char __unaligned aligned_type3;<br>
<br>
+// Check that __unaligned qualifier can be used for overloading<br>
+void foo_unaligned(int *arg) {}<br>
+void foo_unaligned(__unaligned int *arg) {}<br>
+void foo_unaligned(int arg) {} // expected-note {{previous definition is here}}<br>
+void foo_unaligned(__unaligned int arg) {} // expected-error {{redefinition of 'foo_unaligned'}}<br>
+class A_unaligned {};<br>
+class B_unaligned : public A_unaligned {};<br>
+int foo_unaligned(__unaligned A_unaligned *arg) { return 0; }<br>
+void *foo_unaligned(B_unaligned *arg) { return 0; }<br>
+<br>
+void test_unaligned() {<br>
+ int *p1 = 0;<br>
+ foo_unaligned(p1);<br>
+<br>
+ __unaligned int *p2 = 0;<br>
+ foo_unaligned(p2);<br>
+<br>
+ __unaligned B_unaligned *p3 = 0;<br>
+ int p4 = foo_unaligned(p3);<br>
+<br>
+ B_unaligned *p5 = p3; // expected-error {{cannot initialize a variable of type 'B_unaligned *' with an lvalue of type '__unaligned B_unaligned *'}}<br>
+<br>
+ __unaligned B_unaligned *p6 = p3;<br>
+}<br>
<br>
template<typename T> void h1(T (__stdcall M::* const )()) { }<br>
<br>
@@ -420,3 +447,15 @@ struct S {<br>
<br>
int S::fn() { return 0; } // expected-warning {{is missing exception specification}}<br>
}<br>
+<br>
+#elif TEST2<br>
+<br>
+// Check that __unaligned is not recognized if MS extensions are not enabled<br>
+typedef char __unaligned *aligned_type; // expected-error {{expected ';' after top level declarator}}<br>
+<br>
+#else<br>
+<br>
+#error Unknown test mode<br>
+<br>
+#endif<br>
+<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>