Skip to content
Draft
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
16 changes: 14 additions & 2 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -8756,7 +8756,8 @@ class Sema final : public SemaBase {

ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,
SourceLocation OpLoc,
const CXXScopeSpec &SS, FieldDecl *Field,
const NestedNameSpecifierLoc &NNS,
FieldDecl *Field, QualType FieldType,
DeclAccessPair FoundDecl,
const DeclarationNameInfo &MemberNameInfo);

Expand All @@ -8767,7 +8768,8 @@ class Sema final : public SemaBase {
const CXXScopeSpec &SS, SourceLocation nameLoc,
IndirectFieldDecl *indirectField,
DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none),
Expr *baseObjectExpr = nullptr, SourceLocation opLoc = SourceLocation());
Expr *baseObjectExpr = nullptr, const Type *BaseType = nullptr,
SourceLocation opLoc = SourceLocation());

private:
void CheckMemberAccessOfNoDeref(const MemberExpr *E);
Expand Down Expand Up @@ -13999,6 +14001,16 @@ class Sema final : public SemaBase {
FunctionDecl *Spaceship);

QualType resugar(const NestedNameSpecifier *NNS, QualType T);
QualType resugar(const NestedNameSpecifier *NNS, NamedDecl *ND,
ArrayRef<TemplateArgument> Args, QualType T);
QualType resugar(NamedDecl *ND, ArrayRef<TemplateArgument> Args, QualType T);
QualType resugar(const Type *Base, const NestedNameSpecifier *FieldNNS,
QualType T);
QualType resugar(const Type *Base, const NestedNameSpecifier *FieldNNS,
NamedDecl *ND, ArrayRef<TemplateArgument> Args, QualType T);
QualType resugar(const Type *Base, QualType T);
QualType resugar(const Type *Base, NamedDecl *ND,
ArrayRef<TemplateArgument> Args, QualType T);

/// Performs template instantiation for all implicit template
/// instantiations we have seen until this point.
Expand Down
15 changes: 9 additions & 6 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,11 @@ struct BuiltinDumpStructGenerator {
if (!FD || FD->isUnnamedBitField() || FD->isAnonymousStructOrUnion())
continue;

QualType FieldType = FD->getType();

llvm::SmallString<20> Format = llvm::StringRef("%s%s %s ");
llvm::SmallVector<Expr *, 5> Args = {FieldIndentArg,
getTypeString(FD->getType()),
getTypeString(FieldType),
getStringLiteral(FD->getName())};

if (FD->isBitField()) {
Expand All @@ -667,15 +669,16 @@ struct BuiltinDumpStructGenerator {
ExprResult Field =
IFD ? S.BuildAnonymousStructUnionMemberReference(
CXXScopeSpec(), Loc, IFD,
DeclAccessPair::make(IFD, AS_public), RecordArg, Loc)
DeclAccessPair::make(IFD, AS_public), RecordArg, nullptr,
Loc)
: S.BuildFieldReferenceExpr(
RecordArg, RecordArgIsPtr, Loc, CXXScopeSpec(), FD,
DeclAccessPair::make(FD, AS_public),
RecordArg, RecordArgIsPtr, Loc, NestedNameSpecifierLoc(),
FD, FieldType, DeclAccessPair::make(FD, AS_public),
DeclarationNameInfo(FD->getDeclName(), Loc));
if (Field.isInvalid())
return true;

auto *InnerRD = FD->getType()->getAsRecordDecl();
auto *InnerRD = FieldType->getAsRecordDecl();
auto *InnerCXXRD = dyn_cast_or_null<CXXRecordDecl>(InnerRD);
if (InnerRD && (!InnerCXXRD || InnerCXXRD->isAggregate())) {
// Recursively print the values of members of aggregate record type.
Expand All @@ -684,7 +687,7 @@ struct BuiltinDumpStructGenerator {
return true;
} else {
Format += " ";
if (appendFormatSpecifier(FD->getType(), Format)) {
if (appendFormatSpecifier(FieldType, Format)) {
// We know how to print this field.
Args.push_back(Field.get());
} else {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaCoroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static ExprResult buildCoroutineHandle(Sema &S, QualType PromiseType,
S.BuildDeclarationNameExpr(SS, Found, /*NeedsADL=*/false);
if (FromAddr.isInvalid())
return ExprError();

// FIXME: resugar
return S.BuildCallExpr(nullptr, FromAddr.get(), Loc, FramePtr, Loc);
}

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13122,6 +13122,7 @@ bool Sema::DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit,
return true;
}

// FIXME: Set TypeSourceInfo?
VDecl->setType(DeducedType);
assert(VDecl->isLinkageValid());

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3640,6 +3640,7 @@ static void handleCleanupAttr(Sema &S, Decl *D, const ParsedAttr &AL) {

// We're currently more strict than GCC about what function types we accept.
// If this ever proves to be a problem it should be easy to fix.
// FIXME: resugar
QualType Ty = S.Context.getPointerType(cast<VarDecl>(D)->getType());
QualType ParamTy = FD->getParamDecl(0)->getType();
if (S.CheckAssignmentConstraints(FD->getParamDecl(0)->getLocation(),
Expand Down
14 changes: 10 additions & 4 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,9 @@ static bool checkMemberDecomposition(Sema &S, ArrayRef<BindingDecl*> Bindings,
if (FD->isUnnamedBitField())
continue;

// FIXME: Avoid having to recreate the naming context for every field.
QualType FieldType = S.resugar(DecompType.getTypePtr(), FD->getType());

// We have a real field to bind.
assert(FlatBindingsItr != FlatBindings.end());
BindingDecl *B = *(FlatBindingsItr++);
Expand All @@ -1568,7 +1571,7 @@ static bool checkMemberDecomposition(Sema &S, ArrayRef<BindingDecl*> Bindings,
if (E.isInvalid())
return true;
E = S.BuildFieldReferenceExpr(E.get(), /*IsArrow*/ false, Loc,
CXXScopeSpec(), FD,
NestedNameSpecifierLoc(), FD, FieldType,
DeclAccessPair::make(FD, FD->getAccess()),
DeclarationNameInfo(FD->getDeclName(), Loc));
if (E.isInvalid())
Expand All @@ -1582,7 +1585,7 @@ static bool checkMemberDecomposition(Sema &S, ArrayRef<BindingDecl*> Bindings,
Qualifiers Q = DecompType.getQualifiers();
if (FD->isMutable())
Q.removeConst();
B->setBinding(S.BuildQualifiedType(FD->getType(), Loc, Q), E.get());
B->setBinding(S.BuildQualifiedType(FieldType, Loc, Q), E.get());
}

return false;
Expand Down Expand Up @@ -8606,10 +8609,13 @@ class DefaultedComparisonSynthesizer

DeclAccessPair Found = DeclAccessPair::make(Field, Field->getAccess());
DeclarationNameInfo NameInfo(Field->getDeclName(), Loc);
QualType FieldType = Field->getType();
return {S.BuildFieldReferenceExpr(Obj.first.get(), /*IsArrow=*/false, Loc,
CXXScopeSpec(), Field, Found, NameInfo),
NestedNameSpecifierLoc(), Field,
FieldType, Found, NameInfo),
S.BuildFieldReferenceExpr(Obj.second.get(), /*IsArrow=*/false, Loc,
CXXScopeSpec(), Field, Found, NameInfo)};
NestedNameSpecifierLoc(), Field,
FieldType, Found, NameInfo)};
}

// FIXME: When expanding a subobject, register a note in the code synthesis
Expand Down
30 changes: 28 additions & 2 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3224,6 +3224,7 @@ ExprResult Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
if (!NeedsADL && R.isSingleResult() &&
!R.getAsSingle<FunctionTemplateDecl>() &&
!ShouldLookupResultBeMultiVersionOverload(R))
// FIXME: get ConvertedArgs
return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), R.getFoundDecl(),
R.getRepresentativeDecl(), nullptr, nullptr,
AcceptInvalidDecl);
Expand Down Expand Up @@ -3308,6 +3309,10 @@ ExprResult Sema::BuildDeclarationNameExpr(
QualType type = VD->getType();
if (type.isNull())
return ExprError();
assert(!TemplateArgs || ConvertedArgs);
type = ConvertedArgs
? resugar(SS.getScopeRep(), VD, ConvertedArgs->asArray(), type)
: resugar(SS.getScopeRep(), type);
ExprValueKind valueKind = VK_PRValue;

// In 'T ...V;', the type of the declaration 'V' is 'T...', but the type of
Expand Down Expand Up @@ -19895,10 +19900,30 @@ static void DoMarkVarDeclReferenced(

// Re-set the member to trigger a recomputation of the dependence bits
// for the expression.
if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E))
CXXScopeSpec SS;
if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) {
DRE->setDecl(DRE->getDecl());
else if (auto *ME = dyn_cast_or_null<MemberExpr>(E))
SS.Adopt(DRE->getQualifierLoc());
assert(DRE->template_arguments().size() == 0 ||
DRE->getConvertedArgs() != nullptr);
QualType T = DRE->getConvertedArgs()
? SemaRef.resugar(SS.getScopeRep(), DRE->getDecl(),
DRE->getConvertedArgs()->asArray(),
DRE->getType())
: SemaRef.resugar(SS.getScopeRep(), DRE->getType());
DRE->setType(T);
} else if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) {
ME->setMemberDecl(ME->getMemberDecl());
SS.Adopt(ME->getQualifierLoc());
assert(ME->template_arguments().size() == 0 ||
ME->getDeduced() != nullptr);
QualType T =
ME->getDeduced()
? SemaRef.resugar(SS.getScopeRep(), ME->getMemberDecl(),
ME->getDeduced()->asArray(), ME->getType())
: SemaRef.resugar(SS.getScopeRep(), ME->getType());
ME->setType(T);
}
} else if (FirstInstantiation) {
SemaRef.PendingInstantiations
.push_back(std::make_pair(Var, PointOfInstantiation));
Expand Down Expand Up @@ -21200,6 +21225,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
SS.Adopt(DRE->getQualifierLoc());
TemplateArgumentListInfo TemplateArgs;
DRE->copyTemplateArgumentsInto(TemplateArgs);
// FIXME: resugar
return BuildDeclRefExpr(
FD, FD->getType(), VK_LValue, DRE->getNameInfo(),
DRE->hasQualifier() ? &SS : nullptr, DRE->getFoundDecl(),
Expand Down
Loading
Loading