summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorAndrey Bokhanko <andreybokhanko@gmail.com>2016-05-11 18:38:21 +0000
committerAndrey Bokhanko <andreybokhanko@gmail.com>2016-05-11 18:38:21 +0000
commit45d413260e82b57db8a3fc55bb2d90ce48ad0d45 (patch)
tree8d4f3f712258cdfa4468168e00eb111f6e6f8a31 /clang/lib
parent5da4dab0fc6f387c02fcb062fb5feea3a6407e8e (diff)
downloadbcm5719-llvm-45d413260e82b57db8a3fc55bb2d90ce48ad0d45.tar.gz
bcm5719-llvm-45d413260e82b57db8a3fc55bb2d90ce48ad0d45.zip
[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 llvm-svn: 269220
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/MicrosoftMangle.cpp5
-rw-r--r--clang/lib/AST/TypePrinter.cpp6
-rw-r--r--clang/lib/Parse/ParseDecl.cpp15
-rw-r--r--clang/lib/Parse/ParseTentative.cpp2
-rw-r--r--clang/lib/Sema/DeclSpec.cpp6
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp3
-rw-r--r--clang/lib/Sema/SemaDecl.cpp7
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp1
-rw-r--r--clang/lib/Sema/SemaExpr.cpp2
-rw-r--r--clang/lib/Sema/SemaOverload.cpp22
-rw-r--r--clang/lib/Sema/SemaType.cpp37
11 files changed, 82 insertions, 24 deletions
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index c9caddbb6fc..774dab05728 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1446,6 +1446,9 @@ void MicrosoftCXXNameMangler::manglePointerExtQualifiers(Qualifiers Quals,
if (HasRestrict)
Out << 'I';
+
+ if (!PointeeType.isNull() && PointeeType.getLocalQualifiers().hasUnaligned())
+ Out << 'F';
}
void MicrosoftCXXNameMangler::manglePointerCVQualifiers(Qualifiers Quals) {
@@ -1577,6 +1580,8 @@ void MicrosoftCXXNameMangler::mangleType(QualType T, SourceRange Range,
}
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);
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 0356dc515f4..7e04e81e8d1 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1593,6 +1593,12 @@ void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
AppendTypeQualList(OS, quals, Policy.LangOpts.C99);
addSpace = true;
}
+ if (hasUnaligned()) {
+ if (addSpace)
+ OS << ' ';
+ OS << "__unaligned";
+ addSpace = true;
+ }
if (unsigned addrspace = getAddressSpace()) {
if (addSpace)
OS << ' ';
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 2171e5cfc3d..1c93c08f718 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -609,7 +609,6 @@ void Parser::ParseMicrosoftTypeAttributes(ParsedAttributes &attrs) {
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(DeclSpec &DS,
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(DeclSpec &DS,
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(DeclSpec &DS, unsigned AttrReqs,
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(DeclSpec &DS, unsigned AttrReqs,
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(Declarator &D,
DS.getConstSpecLoc(),
DS.getVolatileSpecLoc(),
DS.getRestrictSpecLoc(),
- DS.getAtomicSpecLoc()),
+ DS.getAtomicSpecLoc(),
+ DS.getUnalignedSpecLoc()),
DS.getAttributes(),
SourceLocation());
else
diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index 4d4bd806f3c..cde558196db 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -833,7 +833,7 @@ Parser::TPResult Parser::TryParseDeclarator(bool mayBeAbstract,
// '(' 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)
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index ddfe6257cf4..de013afa14d 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -494,6 +494,7 @@ const char *DeclSpec::getSpecifierName(TQ 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, SourceLocation Loc, const char *&PrevSpec,
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 PrintingPolicy &Policy) {
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;
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index ab2e718c851..739d70288c5 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -3812,6 +3812,9 @@ void Sema::CodeCompleteTypeQualifiers(DeclSpec &DS) {
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(),
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 020b474c187..75aca834d2c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3985,6 +3985,8 @@ Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS,
// 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(Scope *S, DeclSpec &DS,
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();
}
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 400dc637754..3fb29d46cf4 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -1503,6 +1503,7 @@ void Sema::actOnObjCTypeArgsOrProtocolQualifiers(
SourceLocation(),
SourceLocation(),
SourceLocation(),
+ SourceLocation(),
SourceLocation()),
parsedAttrs,
starLoc);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index a5ee8bebae7..68fd92fbe1a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7140,7 +7140,7 @@ checkPointerTypesForAssignment(Sema &S, QualType LHSType, QualType RHSType) {
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;
}
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 481c245bdd8..415eda02ec6 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2951,6 +2951,10 @@ Sema::IsQualificationConversion(QualType FromType, QualType ToType,
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(SourceLocation Loc,
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, QualType DeclType,
// 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;
}
@@ -9135,6 +9146,15 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
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");
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 7fd43a87a81..57295fde0b4 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1785,12 +1785,13 @@ QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc,
}
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(QualType T, SourceLocation Loc,
// 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(QualType T, SourceLocation Loc,
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(unsigned DiagID, unsigned Quals,
SourceLocation ConstQualLoc,
SourceLocation VolatileQualLoc,
SourceLocation RestrictQualLoc,
- SourceLocation AtomicQualLoc) {
+ SourceLocation AtomicQualLoc,
+ SourceLocation UnalignedQualLoc) {
if (!Quals)
return;
@@ -2660,26 +2664,27 @@ void Sema::diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals,
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 diagnoseRedundantReturnTypeQualifiers(Sema &S, QualType RetTy,
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 diagnoseRedundantReturnTypeQualifiers(Sema &S, QualType RetTy,
D.getDeclSpec().getConstSpecLoc(),
D.getDeclSpec().getVolatileSpecLoc(),
D.getDeclSpec().getRestrictSpecLoc(),
- D.getDeclSpec().getAtomicSpecLoc());
+ D.getDeclSpec().getAtomicSpecLoc(),
+ D.getDeclSpec().getUnalignedSpecLoc());
}
static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
OpenPOWER on IntegriCloud