[clang] fb19649 - [Clang][NFCI] Remove records of unsatisfied atomic expressions in ConstraintSatisfaction (#98654)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 12 20:49:24 PDT 2024
Author: Younan Zhang
Date: 2024-07-13T11:49:21+08:00
New Revision: fb19649535d3d31a748409542947d09291643204
URL: https://github.com/llvm/llvm-project/commit/fb19649535d3d31a748409542947d09291643204
DIFF: https://github.com/llvm/llvm-project/commit/fb19649535d3d31a748409542947d09291643204.diff
LOG: [Clang][NFCI] Remove records of unsatisfied atomic expressions in ConstraintSatisfaction (#98654)
This expression doesn't appear to be ever used, so let's remove it from
the data structure.
Fixed some spelling issues as well.
Added:
Modified:
clang/include/clang/AST/ASTConcept.h
clang/lib/AST/ASTConcept.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ASTConcept.h b/clang/include/clang/AST/ASTConcept.h
index 5f9aa41d3e6cf..3c5fdf81d4b1e 100644
--- a/clang/include/clang/AST/ASTConcept.h
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -53,11 +53,10 @@ class ConstraintSatisfaction : public llvm::FoldingSetNode {
bool IsSatisfied = false;
bool ContainsErrors = false;
- /// \brief Pairs of unsatisfied atomic constraint expressions along with the
- /// substituted constraint expr, if the template arguments could be
+ /// \brief The substituted constraint expr, if the template arguments could be
/// substituted into them, or a diagnostic if substitution resulted in an
/// invalid expression.
- llvm::SmallVector<std::pair<const Expr *, Detail>, 4> Details;
+ llvm::SmallVector<Detail, 4> Details;
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) {
Profile(ID, C, ConstraintOwner, TemplateArgs);
@@ -69,7 +68,7 @@ class ConstraintSatisfaction : public llvm::FoldingSetNode {
bool HasSubstitutionFailure() {
for (const auto &Detail : Details)
- if (Detail.second.dyn_cast<SubstitutionDiagnostic *>())
+ if (Detail.dyn_cast<SubstitutionDiagnostic *>())
return true;
return false;
}
@@ -80,9 +79,7 @@ class ConstraintSatisfaction : public llvm::FoldingSetNode {
/// substituted into them, or a diagnostic if substitution resulted in
/// an invalid expression.
using UnsatisfiedConstraintRecord =
- std::pair<const Expr *,
- llvm::PointerUnion<Expr *,
- std::pair<SourceLocation, StringRef> *>>;
+ llvm::PointerUnion<Expr *, std::pair<SourceLocation, StringRef> *>;
/// \brief The result of a constraint satisfaction check, containing the
/// necessary information to diagnose an unsatisfied constraint.
diff --git a/clang/lib/AST/ASTConcept.cpp b/clang/lib/AST/ASTConcept.cpp
index 0387fc9f6aec2..95e7ac1a3d775 100644
--- a/clang/lib/AST/ASTConcept.cpp
+++ b/clang/lib/AST/ASTConcept.cpp
@@ -19,27 +19,23 @@
using namespace clang;
-namespace {
-void CreatUnsatisfiedConstraintRecord(
- const ASTContext &C, const UnsatisfiedConstraintRecord &Detail,
- UnsatisfiedConstraintRecord *TrailingObject) {
- if (Detail.second.is<Expr *>())
- new (TrailingObject) UnsatisfiedConstraintRecord{
- Detail.first,
- UnsatisfiedConstraintRecord::second_type(Detail.second.get<Expr *>())};
+static void
+CreateUnsatisfiedConstraintRecord(const ASTContext &C,
+ const UnsatisfiedConstraintRecord &Detail,
+ UnsatisfiedConstraintRecord *TrailingObject) {
+ if (Detail.is<Expr *>())
+ new (TrailingObject) UnsatisfiedConstraintRecord(Detail.get<Expr *>());
else {
auto &SubstitutionDiagnostic =
- *Detail.second.get<std::pair<SourceLocation, StringRef> *>();
+ *Detail.get<std::pair<SourceLocation, StringRef> *>();
unsigned MessageSize = SubstitutionDiagnostic.second.size();
char *Mem = new (C) char[MessageSize];
memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize);
auto *NewSubstDiag = new (C) std::pair<SourceLocation, StringRef>(
SubstitutionDiagnostic.first, StringRef(Mem, MessageSize));
- new (TrailingObject) UnsatisfiedConstraintRecord{
- Detail.first, UnsatisfiedConstraintRecord::second_type(NewSubstDiag)};
+ new (TrailingObject) UnsatisfiedConstraintRecord(NewSubstDiag);
}
}
-} // namespace
ASTConstraintSatisfaction::ASTConstraintSatisfaction(
const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
@@ -47,7 +43,7 @@ ASTConstraintSatisfaction::ASTConstraintSatisfaction(
IsSatisfied{Satisfaction.IsSatisfied}, ContainsErrors{
Satisfaction.ContainsErrors} {
for (unsigned I = 0; I < NumRecords; ++I)
- CreatUnsatisfiedConstraintRecord(
+ CreateUnsatisfiedConstraintRecord(
C, Satisfaction.Details[I],
getTrailingObjects<UnsatisfiedConstraintRecord>() + I);
}
@@ -58,7 +54,7 @@ ASTConstraintSatisfaction::ASTConstraintSatisfaction(
IsSatisfied{Satisfaction.IsSatisfied},
ContainsErrors{Satisfaction.ContainsErrors} {
for (unsigned I = 0; I < NumRecords; ++I)
- CreatUnsatisfiedConstraintRecord(
+ CreateUnsatisfiedConstraintRecord(
C, *(Satisfaction.begin() + I),
getTrailingObjects<UnsatisfiedConstraintRecord>() + I);
}
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 202dd86c67f62..54891150da20f 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -273,7 +273,6 @@ calculateConstraintSatisfaction(Sema &S, const Expr *ConstraintExpr,
char *Mem = new (S.Context) char[MessageSize];
memcpy(Mem, DiagString.c_str(), MessageSize);
Satisfaction.Details.emplace_back(
- ConstraintExpr,
new (S.Context) ConstraintSatisfaction::SubstitutionDiagnostic{
SubstitutedAtomicExpr.get()->getBeginLoc(),
StringRef(Mem, MessageSize)});
@@ -302,8 +301,7 @@ calculateConstraintSatisfaction(Sema &S, const Expr *ConstraintExpr,
"evaluating bool expression didn't produce int");
Satisfaction.IsSatisfied = EvalResult.Val.getInt().getBoolValue();
if (!Satisfaction.IsSatisfied)
- Satisfaction.Details.emplace_back(ConstraintExpr,
- SubstitutedAtomicExpr.get());
+ Satisfaction.Details.emplace_back(SubstitutedAtomicExpr.get());
return SubstitutedAtomicExpr;
}
@@ -393,9 +391,8 @@ static ExprResult calculateConstraintSatisfaction(
char *Mem = new (S.Context) char[MessageSize];
memcpy(Mem, DiagString.c_str(), MessageSize);
Satisfaction.Details.emplace_back(
- AtomicExpr,
new (S.Context) ConstraintSatisfaction::SubstitutionDiagnostic{
- SubstDiag.first, StringRef(Mem, MessageSize)});
+ SubstDiag.first, StringRef(Mem, MessageSize)});
Satisfaction.IsSatisfied = false;
return ExprEmpty();
}
@@ -1056,13 +1053,14 @@ static void diagnoseUnsatisfiedRequirement(Sema &S,
concepts::NestedRequirement *Req,
bool First) {
using SubstitutionDiagnostic = std::pair<SourceLocation, StringRef>;
- for (auto &Pair : Req->getConstraintSatisfaction()) {
- if (auto *SubstDiag = Pair.second.dyn_cast<SubstitutionDiagnostic *>())
+ for (auto &Record : Req->getConstraintSatisfaction()) {
+ if (auto *SubstDiag = Record.dyn_cast<SubstitutionDiagnostic *>())
S.Diag(SubstDiag->first, diag::note_nested_requirement_substitution_error)
- << (int)First << Req->getInvalidConstraintEntity() << SubstDiag->second;
+ << (int)First << Req->getInvalidConstraintEntity()
+ << SubstDiag->second;
else
- diagnoseWellFormedUnsatisfiedConstraintExpr(
- S, Pair.second.dyn_cast<Expr *>(), First);
+ diagnoseWellFormedUnsatisfiedConstraintExpr(S, Record.dyn_cast<Expr *>(),
+ First);
First = false;
}
}
@@ -1176,12 +1174,11 @@ static void diagnoseWellFormedUnsatisfiedConstraintExpr(Sema &S,
<< (int)First << SubstExpr;
}
-template<typename SubstitutionDiagnostic>
+template <typename SubstitutionDiagnostic>
static void diagnoseUnsatisfiedConstraintExpr(
- Sema &S, const Expr *E,
- const llvm::PointerUnion<Expr *, SubstitutionDiagnostic *> &Record,
+ Sema &S, const llvm::PointerUnion<Expr *, SubstitutionDiagnostic *> &Record,
bool First = true) {
- if (auto *Diag = Record.template dyn_cast<SubstitutionDiagnostic *>()){
+ if (auto *Diag = Record.template dyn_cast<SubstitutionDiagnostic *>()) {
S.Diag(Diag->first, diag::note_substituted_constraint_expr_is_ill_formed)
<< Diag->second;
return;
@@ -1196,8 +1193,8 @@ Sema::DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction& Satisfaction,
bool First) {
assert(!Satisfaction.IsSatisfied &&
"Attempted to diagnose a satisfied constraint");
- for (auto &Pair : Satisfaction.Details) {
- diagnoseUnsatisfiedConstraintExpr(*this, Pair.first, Pair.second, First);
+ for (auto &Record : Satisfaction.Details) {
+ diagnoseUnsatisfiedConstraintExpr(*this, Record, First);
First = false;
}
}
@@ -1207,8 +1204,8 @@ void Sema::DiagnoseUnsatisfiedConstraint(
bool First) {
assert(!Satisfaction.IsSatisfied &&
"Attempted to diagnose a satisfied constraint");
- for (auto &Pair : Satisfaction) {
- diagnoseUnsatisfiedConstraintExpr(*this, Pair.first, Pair.second, First);
+ for (auto &Record : Satisfaction) {
+ diagnoseUnsatisfiedConstraintExpr(*this, Record, First);
First = false;
}
}
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index bb36736c021b3..9296cc66d6918 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4250,10 +4250,10 @@ TemplateParameterList *Sema::MatchTemplateParametersToScopeSpecifier(
// C++ [temp.expl.spec]p16:
// In an explicit specialization declaration for a member of a class
- // template or a member template that ap- pears in namespace scope, the
+ // template or a member template that appears in namespace scope, the
// member template and some of its enclosing class templates may remain
// unspecialized, except that the declaration shall not explicitly
- // specialize a class member template if its en- closing class templates
+ // specialize a class member template if its enclosing class templates
// are not explicitly specialized as well.
if (ParamIdx < ParamLists.size()) {
if (ParamLists[ParamIdx]->size() == 0) {
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index 5a5d7be69a2c3..6ccb4b01a036a 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -793,16 +793,15 @@ readConstraintSatisfaction(ASTRecordReader &Record) {
if (!Satisfaction.IsSatisfied) {
unsigned NumDetailRecords = Record.readInt();
for (unsigned i = 0; i != NumDetailRecords; ++i) {
- Expr *ConstraintExpr = Record.readExpr();
if (/* IsDiagnostic */Record.readInt()) {
SourceLocation DiagLocation = Record.readSourceLocation();
std::string DiagMessage = Record.readString();
Satisfaction.Details.emplace_back(
- ConstraintExpr, new (Record.getContext())
- ConstraintSatisfaction::SubstitutionDiagnostic{
- DiagLocation, DiagMessage});
+ new (Record.getContext())
+ ConstraintSatisfaction::SubstitutionDiagnostic(DiagLocation,
+ DiagMessage));
} else
- Satisfaction.Details.emplace_back(ConstraintExpr, Record.readExpr());
+ Satisfaction.Details.emplace_back(Record.readExpr());
}
}
return Satisfaction;
diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 30c5b1bc56f47..98606bbf8c4a0 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -474,14 +474,12 @@ addConstraintSatisfaction(ASTRecordWriter &Record,
if (!Satisfaction.IsSatisfied) {
Record.push_back(Satisfaction.NumRecords);
for (const auto &DetailRecord : Satisfaction) {
- Record.writeStmtRef(DetailRecord.first);
- auto *E = DetailRecord.second.dyn_cast<Expr *>();
- Record.push_back(E == nullptr);
+ auto *E = DetailRecord.dyn_cast<Expr *>();
+ Record.push_back(/* IsDiagnostic */ E == nullptr);
if (E)
Record.AddStmt(E);
else {
- auto *Diag = DetailRecord.second.get<std::pair<SourceLocation,
- StringRef> *>();
+ auto *Diag = DetailRecord.get<std::pair<SourceLocation, StringRef> *>();
Record.AddSourceLocation(Diag->first);
Record.AddString(Diag->second);
}
More information about the cfe-commits
mailing list