diff options
| author | Andrey Bokhanko <andreybokhanko@gmail.com> | 2016-04-15 08:03:51 +0000 |
|---|---|---|
| committer | Andrey Bokhanko <andreybokhanko@gmail.com> | 2016-04-15 08:03:51 +0000 |
| commit | f7fa634887cf327ebca2a71327631ee00f0057a8 (patch) | |
| tree | 6115bdd74d32215b36ca02a348f2eb780a95b716 /clang/lib/Sema | |
| parent | 18e69f4f635434eefadb35caffef71d2b429933c (diff) | |
| download | bcm5719-llvm-f7fa634887cf327ebca2a71327631ee00f0057a8.tar.gz bcm5719-llvm-f7fa634887cf327ebca2a71327631ee00f0057a8.zip | |
[MSVC Compat] Implementation of __unaligned (MS extension) as a type qualifier
This patch implements __unaligned as a type qualifier; before that, it was
modeled as an attribute. Proper mangling of __unaligned is implemented as well.
Some OpenCL code/tests are tangenially affected, as they relied on existing
number and sizes of type qualifiers.
Differential Revision: http://reviews.llvm.org/D18596
llvm-svn: 266415
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/DeclSpec.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDeclObjC.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 31 |
6 files changed, 35 insertions, 15 deletions
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 13002ba19a5..2f0de7afb5f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3974,6 +3974,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: @@ -4231,6 +4233,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 8090bec4fab..36e65b40d64 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 bd56596446e..9a2f10a9fa5 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -7138,7 +7138,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/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 4d68f4c1cfb..d1d052d6223 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1743,12 +1743,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 @@ -1758,7 +1759,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 @@ -1775,7 +1776,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. @@ -2617,7 +2620,8 @@ void Sema::diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, SourceLocation ConstQualLoc, SourceLocation VolatileQualLoc, SourceLocation RestrictQualLoc, - SourceLocation AtomicQualLoc) { + SourceLocation AtomicQualLoc, + SourceLocation UnalignedQualLoc) { if (!Quals) return; @@ -2625,20 +2629,21 @@ 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) { + for (unsigned I = 0; I != 5; ++I) { if (Quals & QualKinds[I].Mask) { if (!QualStr.empty()) QualStr += ' '; QualStr += QualKinds[I].Name; @@ -2690,7 +2695,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; } @@ -2726,7 +2732,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, |

