diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-16 21:35:15 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-16 21:35:15 +0000 |
commit | a4923eb7c4b04d360cb2747641a5e92818edf804 (patch) | |
tree | 573c9d43fd0b6daf0f1d5ee02ebbffd7e3e84cfd /lib/Sema/SemaExpr.cpp | |
parent | ad35a83102683b00a7e28707eee7f2d8c994b742 (diff) |
First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:
typedef const int CInt;
typedef CInt Self;
Self.isConstQualified() currently returns false!
Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions:
- the "local" version only returns qualifiers on this particular
QualType instance
- the "normal" version that will eventually combine qualifiers from this
QualType instance with the qualifiers on the canonical type to
produce the full set of qualifiers.
This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()
expressions over to
Context.hasSameUnqualifiedType(T1, T2)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 0d4ce60913..b089ffe92f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3070,8 +3070,7 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg initlist, static CastExpr::CastKind getScalarCastKind(ASTContext &Context, QualType SrcTy, QualType DestTy) { - if (Context.getCanonicalType(SrcTy).getUnqualifiedType() == - Context.getCanonicalType(DestTy).getUnqualifiedType()) + if (Context.hasSameUnqualifiedType(SrcTy, DestTy)) return CastExpr::CK_NoOp; if (SrcTy->hasPointerRepresentation()) { @@ -3122,8 +3121,7 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr, } if (!castType->isScalarType() && !castType->isVectorType()) { - if (Context.getCanonicalType(castType).getUnqualifiedType() == - Context.getCanonicalType(castExpr->getType().getUnqualifiedType()) && + if (Context.hasSameUnqualifiedType(castType, castExpr->getType()) && (castType->isStructureType() || castType->isUnionType())) { // GCC struct/union extension: allow cast to self. // FIXME: Check that the cast destination type is complete. @@ -3139,8 +3137,8 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr, RecordDecl::field_iterator Field, FieldEnd; for (Field = RD->field_begin(), FieldEnd = RD->field_end(); Field != FieldEnd; ++Field) { - if (Context.getCanonicalType(Field->getType()).getUnqualifiedType() == - Context.getCanonicalType(castExpr->getType()).getUnqualifiedType()) { + if (Context.hasSameUnqualifiedType(Field->getType(), + castExpr->getType())) { Diag(TyR.getBegin(), diag::ext_typecheck_cast_to_union) << castExpr->getSourceRange(); break; @@ -3761,7 +3759,7 @@ Sema::CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType) { rhptee = Context.getCanonicalType(rhptee); } while (lhptee->isPointerType() && rhptee->isPointerType()); - if (lhptee.getUnqualifiedType() == rhptee.getUnqualifiedType()) + if (Context.hasSameUnqualifiedType(lhptee, rhptee)) return IncompatibleNestedPointerQualifiers; } @@ -3791,7 +3789,7 @@ Sema::CheckBlockPointerTypesForAssignment(QualType lhsType, AssignConvertType ConvTy = Compatible; // For blocks we enforce that qualifiers are identical. - if (lhptee.getCVRQualifiers() != rhptee.getCVRQualifiers()) + if (lhptee.getLocalCVRQualifiers() != rhptee.getLocalCVRQualifiers()) ConvTy = CompatiblePointerDiscardsQualifiers; if (!Context.typesAreCompatible(lhptee, rhptee)) |