Skip to content

[clang] Template Specialization Resugaring - TypeDecl #132441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: users/mizvekov/clang-sugar-sugared-converted-tst
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void QualifiedAutoCheck::registerMatchers(MatchFinder *Finder) {
auto UnlessFunctionType = unless(hasUnqualifiedDesugaredType(functionType()));
auto IsAutoDeducedToPointer = [](const auto &...InnerMatchers) {
return autoType(hasDeducedType(
hasUnqualifiedDesugaredType(pointerType(pointee(InnerMatchers...)))));
hasCanonicalType(pointerType(pointee(InnerMatchers...)))));
};

Finder->addMatcher(
Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,6 @@ class ASTContext : public RefCountedBase<ASTContext> {

QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const;

QualType getPipeType(QualType T, bool ReadOnly) const;

public:
/// Return the uniqued reference to the type for an address space
/// qualified type with the specified type and address space.
Expand Down Expand Up @@ -1500,6 +1498,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// blocks.
QualType getBlockDescriptorType() const;

// Return a pipe type for the specified type.
QualType getPipeType(QualType T, bool ReadOnly) const;

/// Return a read_only pipe type for the specified type.
QualType getReadPipeType(QualType T) const;

Expand Down
11 changes: 6 additions & 5 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,10 @@ class Qualifiers {
void addQualifiers(Qualifiers Q) {
// If the other set doesn't have any non-boolean qualifiers, just
// bit-or it in.
if (!(Q.Mask & ~CVRMask))
if (!(Q.Mask & ~CVRUMask))
Mask |= Q.Mask;
else {
Mask |= (Q.Mask & CVRMask);
Mask |= (Q.Mask & CVRUMask);
if (Q.hasAddressSpace())
addAddressSpace(Q.getAddressSpace());
if (Q.hasObjCGCAttr())
Expand All @@ -662,10 +662,10 @@ class Qualifiers {
void removeQualifiers(Qualifiers Q) {
// If the other set doesn't have any non-boolean qualifiers, just
// bit-and the inverse in.
if (!(Q.Mask & ~CVRMask))
if (!(Q.Mask & ~CVRUMask))
Mask &= ~Q.Mask;
else {
Mask &= ~(Q.Mask & CVRMask);
Mask &= ~(Q.Mask & CVRUMask);
if (getObjCGCAttr() == Q.getObjCGCAttr())
removeObjCGCAttr();
if (getObjCLifetime() == Q.getObjCLifetime())
Expand Down Expand Up @@ -805,12 +805,13 @@ class Qualifiers {

static constexpr uint64_t UMask = 0x8;
static constexpr uint64_t UShift = 3;
static constexpr uint64_t CVRUMask = CVRMask | UMask;
static constexpr uint64_t GCAttrMask = 0x30;
static constexpr uint64_t GCAttrShift = 4;
static constexpr uint64_t LifetimeMask = 0x1C0;
static constexpr uint64_t LifetimeShift = 6;
static constexpr uint64_t AddressSpaceMask =
~(CVRMask | UMask | GCAttrMask | LifetimeMask);
~(CVRUMask | GCAttrMask | LifetimeMask);
static constexpr uint64_t AddressSpaceShift = 9;
static constexpr uint64_t PtrAuthShift = 32;
static constexpr uint64_t PtrAuthMask = uint64_t(0xffffffff) << PtrAuthShift;
Expand Down
8 changes: 6 additions & 2 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -3193,7 +3193,8 @@ class Sema final : public SemaBase {
/// Returns the TypeDeclType for the given type declaration,
/// as ASTContext::getTypeDeclType would, but
/// performs the required semantic checks for name lookup of said entity.
QualType getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
QualType getTypeDeclType(const NestedNameSpecifier *NNS,
DeclContext *LookupCtx, DiagCtorKind DCK,
TypeDecl *TD, SourceLocation NameLoc);

/// If the identifier refers to a type name within this scope,
Expand Down Expand Up @@ -13985,6 +13986,8 @@ class Sema final : public SemaBase {
FunctionDecl *SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD,
FunctionDecl *Spaceship);

QualType resugar(const NestedNameSpecifier *NNS, QualType T);

/// Performs template instantiation for all implicit template
/// instantiations we have seen until this point.
void PerformPendingInstantiations(bool LocalOnly = false,
Expand Down Expand Up @@ -14985,7 +14988,8 @@ class Sema final : public SemaBase {
/// wasn't specified explicitly. This handles method types formed from
/// function type typedefs and typename template arguments.
void adjustMemberFunctionCC(QualType &T, bool HasThisPointer,
bool IsCtorOrDtor, SourceLocation Loc);
bool IsCtorOrDtor, bool IsDeduced,
SourceLocation Loc);

// Check if there is an explicit attribute, but only look through parens.
// The intent is to look for an attribute on the current declarator, but not
Expand Down
4 changes: 1 addition & 3 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14075,9 +14075,7 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
case Type::Pipe: {
const auto *PX = cast<PipeType>(X), *PY = cast<PipeType>(Y);
assert(PX->isReadOnly() == PY->isReadOnly());
auto MP = PX->isReadOnly() ? &ASTContext::getReadPipeType
: &ASTContext::getWritePipeType;
return (Ctx.*MP)(getCommonElementType(Ctx, PX, PY));
return Ctx.getPipeType(getCommonElementType(Ctx, PX, PY), PX->isReadOnly());
}
case Type::TemplateTypeParm: {
const auto *TX = cast<TemplateTypeParmType>(X),
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Sema/SemaCXXScopeSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,9 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo,
return false;
}

QualType T =
Context.getTypeDeclType(cast<TypeDecl>(SD->getUnderlyingDecl()));
QualType T = resugar(
SS.getScopeRep(),
Context.getTypeDeclType(cast<TypeDecl>(SD->getUnderlyingDecl())));

if (T->isEnumeralType())
Diag(IdInfo.IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Sema/SemaCoroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ static QualType lookupPromiseType(Sema &S, const FunctionDecl *FD,
}
// The promise type is required to be a class type.
QualType PromiseType = S.Context.getTypeDeclType(Promise);
// FIXME: resugar PromiseType.

auto buildElaboratedType = [&]() {
auto *NNS = NestedNameSpecifier::Create(S.Context, nullptr, S.getStdNamespace());
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class TypeNameValidatorCCC final : public CorrectionCandidateCallback {

} // end anonymous namespace

QualType Sema::getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
QualType Sema::getTypeDeclType(const NestedNameSpecifier *NNS,
DeclContext *LookupCtx, DiagCtorKind DCK,
TypeDecl *TD, SourceLocation NameLoc) {
auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
Expand All @@ -156,7 +157,7 @@ QualType Sema::getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,

DiagnoseUseOfDecl(TD, NameLoc);
MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
return Context.getTypeDeclType(TD);
return resugar(NNS, Context.getTypeDeclType(TD));
}

namespace {
Expand Down Expand Up @@ -534,7 +535,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
// C++ [class.qual]p2: A lookup that would find the injected-class-name
// instead names the constructors of the class, except when naming a class.
// This is ill-formed when we're not actually forming a ctor or dtor name.
T = getTypeDeclType(LookupCtx,
T = getTypeDeclType(SS ? SS->getScopeRep() : nullptr, LookupCtx,
IsImplicitTypename ? DiagCtorKind::Implicit
: DiagCtorKind::None,
TD, NameLoc);
Expand Down Expand Up @@ -9865,7 +9866,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
if (D.isFirstDeclarationOfMember())
adjustMemberFunctionCC(
R, !(D.isStaticMember() || D.isExplicitObjectMemberFunction()),
D.isCtorOrDtor(), D.getIdentifierLoc());
D.isCtorOrDtor(), /*IsDeduced=*/false, D.getIdentifierLoc());

bool isFriend = false;
FunctionTemplateDecl *FunctionTemplate = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ static QualType getTupleLikeElementType(Sema &S, SourceLocation Loc,
S.Diag(R.getRepresentativeDecl()->getLocation(), diag::note_declared_at);
return QualType();
}

// FIXME: resugar
return S.Context.getTypeDeclType(TD);
}

Expand Down
Loading
Loading