[clang] b86bf83 - [FIX] Remove pointer in attribute to eliminate leaks (see D71830)
Johannes Doerfert via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 15 16:11:32 PST 2020
Author: Johannes Doerfert
Date: 2020-02-15T18:09:54-06:00
New Revision: b86bf83c281cbc1c42de3dfca6ae2555094abeae
URL: https://github.com/llvm/llvm-project/commit/b86bf83c281cbc1c42de3dfca6ae2555094abeae
DIFF: https://github.com/llvm/llvm-project/commit/b86bf83c281cbc1c42de3dfca6ae2555094abeae.diff
LOG: [FIX] Remove pointer in attribute to eliminate leaks (see D71830)
Added:
Modified:
clang/include/clang/Basic/Attr.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTRecordReader.h
clang/include/clang/Serialization/ASTRecordWriter.h
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index be68a9bd80c6..e1a61d0c49c1 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -181,7 +181,7 @@ class NamedArgument<string name, bit opt = 0, bit fake = 0> : Argument<name,
opt,
fake>;
-// An argument of a OMPDeclareVariantAttribute that represents the `match`
+// An argument of a OMPDeclareVariantAttr that represents the `match`
// clause of the declare variant by keeping the information (incl. nesting) in
// an OMPTraitInfo object.
//
@@ -3366,7 +3366,7 @@ def OMPDeclareVariant : InheritableAttr {
OMPTraitInfoArgument<"TraitInfos">,
];
let AdditionalMembers = [{
- ~OMPDeclareVariantAttr() { delete traitInfos; }
+ OMPTraitInfo &getTraitInfo() { return traitInfos; }
void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
const {
if (const Expr *E = getVariantFuncRef()) {
@@ -3375,7 +3375,7 @@ def OMPDeclareVariant : InheritableAttr {
OS << ")";
}
OS << " match(";
- traitInfos->print(OS, Policy);
+ traitInfos.print(OS, Policy);
OS << ")";
}
}];
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ffcacac6ebb4..a6430353b241 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10202,7 +10202,7 @@ class Sema final {
/// must be used instead of the original one, specified in \p DG.
/// \param TI The context traits associated with the function variant.
void ActOnOpenMPDeclareVariantDirective(FunctionDecl *FD, Expr *VariantRef,
- OMPTraitInfo *TI, SourceRange SR);
+ OMPTraitInfo &TI, SourceRange SR);
OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
Expr *Expr,
diff --git a/clang/include/clang/Serialization/ASTRecordReader.h b/clang/include/clang/Serialization/ASTRecordReader.h
index 362296024a97..7d4ef7c43a9d 100644
--- a/clang/include/clang/Serialization/ASTRecordReader.h
+++ b/clang/include/clang/Serialization/ASTRecordReader.h
@@ -260,7 +260,7 @@ class ASTRecordReader
}
/// Read an OMPTraitInfo object, advancing Idx.
- OMPTraitInfo *readOMPTraitInfo();
+ OMPTraitInfo readOMPTraitInfo();
/// Read an OpenMP clause, advancing Idx.
OMPClause *readOMPClause();
diff --git a/clang/include/clang/Serialization/ASTRecordWriter.h b/clang/include/clang/Serialization/ASTRecordWriter.h
index 2a35c694ccf8..924aa5d4b758 100644
--- a/clang/include/clang/Serialization/ASTRecordWriter.h
+++ b/clang/include/clang/Serialization/ASTRecordWriter.h
@@ -267,7 +267,7 @@ class ASTRecordWriter
void AddCXXDefinitionData(const CXXRecordDecl *D);
/// Write an OMPTraitInfo object.
- void writeOMPTraitInfo(OMPTraitInfo *TI);
+ void writeOMPTraitInfo(const OMPTraitInfo &TI);
void writeOMPClause(OMPClause *C);
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 60b81492f78e..9798d454cb8b 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11075,11 +11075,11 @@ static const FunctionDecl *getDeclareVariantFunction(CodeGenModule &CGM,
SmallVector<Expr *, 8> VariantExprs;
SmallVector<VariantMatchInfo, 8> VMIs;
for (const auto *A : FD->specific_attrs<OMPDeclareVariantAttr>()) {
- const OMPTraitInfo *TI = A->getTraitInfos();
- if (!TI)
- continue;
+ A->printPretty(llvm::dbgs(), PrintingPolicy(LangOptions()));
+ const OMPTraitInfo &TI = A->getTraitInfos();
+ TI.print(llvm::dbgs(), PrintingPolicy(LangOptions()));
VMIs.push_back(VariantMatchInfo());
- TI->getAsVariantMatchInfo(CGM.getContext(), VMIs.back());
+ TI.getAsVariantMatchInfo(CGM.getContext(), VMIs.back());
VariantExprs.push_back(A->getVariantFuncRef());
}
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index e1bcbdb05499..8c822ec1d0e9 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1365,26 +1365,24 @@ void Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr,
}
// Parse inner context selectors.
- OMPTraitInfo *TI = new OMPTraitInfo();
- parseOMPContextSelectors(Loc, *TI);
+ OMPTraitInfo TI;
+ parseOMPContextSelectors(Loc, TI);
// Parse ')'
(void)T.consumeClose();
Optional<std::pair<FunctionDecl *, Expr *>> DeclVarData =
Actions.checkOpenMPDeclareVariantFunction(
- Ptr, AssociatedFunction.get(), *TI,
+ Ptr, AssociatedFunction.get(), TI,
SourceRange(Loc, Tok.getLocation()));
// Skip last tokens.
while (Tok.isNot(tok::annot_pragma_openmp_end))
ConsumeAnyToken();
- if (DeclVarData.hasValue() && !TI->Sets.empty())
+ if (DeclVarData.hasValue() && !TI.Sets.empty())
Actions.ActOnOpenMPDeclareVariantDirective(
DeclVarData.getValue().first, DeclVarData.getValue().second, TI,
SourceRange(Loc, Tok.getLocation()));
- else
- delete TI;
// Skip the last annot_pragma_openmp_end.
(void)ConsumeAnnotationToken();
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index a828e85203aa..ea1011067130 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5632,7 +5632,7 @@ Sema::checkOpenMPDeclareVariantFunction(Sema::DeclGroupPtrTy DG,
void Sema::ActOnOpenMPDeclareVariantDirective(FunctionDecl *FD,
Expr *VariantRef,
- OMPTraitInfo *TI,
+ OMPTraitInfo &TI,
SourceRange SR) {
auto *NewAttr =
OMPDeclareVariantAttr::CreateImplicit(Context, VariantRef, TI, SR);
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 6571c827bbdb..2ac899a6b017 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -395,8 +395,7 @@ static void instantiateOMPDeclareVariantAttr(
// Copy the template version of the OMPTraitInfo and run substitute on all
// score and condition expressiosn.
- OMPTraitInfo *TI = new OMPTraitInfo();
- *TI = *Attr.getTraitInfos();
+ OMPTraitInfo TI = Attr.getTraitInfos();
// Try to substitute template parameters in score and condition expressions.
auto SubstScoreOrConditionExpr = [&S, Subst](Expr *&E, bool) {
@@ -411,21 +410,17 @@ static void instantiateOMPDeclareVariantAttr(
}
return false;
};
- if (TI->anyScoreOrCondition(SubstScoreOrConditionExpr)) {
- delete TI;
+ if (TI.anyScoreOrCondition(SubstScoreOrConditionExpr))
return;
- }
// Check function/variant ref.
Optional<std::pair<FunctionDecl *, Expr *>> DeclVarData =
S.checkOpenMPDeclareVariantFunction(S.ConvertDeclToDeclGroup(New),
- VariantFuncRef.get(), *TI,
+ VariantFuncRef.get(), TI,
Attr.getRange());
- if (!DeclVarData) {
- delete TI;
+ if (!DeclVarData)
return;
- }
S.ActOnOpenMPDeclareVariantDirective(DeclVarData.getValue().first,
DeclVarData.getValue().second, TI,
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index fa5b43d8315e..29abb9c65a9d 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -12612,10 +12612,10 @@ void OMPClauseReader::VisitOMPOrderClause(OMPOrderClause *C) {
C->setKindKwLoc(Record.readSourceLocation());
}
-OMPTraitInfo *ASTRecordReader::readOMPTraitInfo() {
- OMPTraitInfo *TI = new OMPTraitInfo();
- TI->Sets.resize(readUInt32());
- for (auto &Set : TI->Sets) {
+OMPTraitInfo ASTRecordReader::readOMPTraitInfo() {
+ OMPTraitInfo TI;
+ TI.Sets.resize(readUInt32());
+ for (auto &Set : TI.Sets) {
Set.Kind = readEnum<llvm::omp::TraitSet>();
Set.Selectors.resize(readUInt32());
for (auto &Selector : Set.Selectors) {
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 45c10be8add7..091bf566a670 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2756,7 +2756,7 @@ class AttrReader {
return Reader.readVersionTuple();
}
- OMPTraitInfo *readOMPTraitInfo() { return Reader.readOMPTraitInfo(); }
+ OMPTraitInfo readOMPTraitInfo() { return Reader.readOMPTraitInfo(); }
template <typename T> T *GetLocalDeclAs(uint32_t LocalID) {
return Reader.GetLocalDeclAs<T>(LocalID);
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 4ee59f79502d..159ebe1c01ac 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -6578,9 +6578,9 @@ void OMPClauseWriter::VisitOMPOrderClause(OMPOrderClause *C) {
Record.AddSourceLocation(C->getKindKwLoc());
}
-void ASTRecordWriter::writeOMPTraitInfo(OMPTraitInfo *TI) {
- writeUInt32(TI->Sets.size());
- for (const auto &Set : TI->Sets) {
+void ASTRecordWriter::writeOMPTraitInfo(const OMPTraitInfo &TI) {
+ writeUInt32(TI.Sets.size());
+ for (const auto &Set : TI.Sets) {
writeEnum(Set.Kind);
writeUInt32(Set.Selectors.size());
for (const auto &Selector : Set.Selectors) {
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index b56a050ca2eb..116c382c1e8f 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -107,7 +107,7 @@ static std::string ReadPCHRecord(StringRef type) {
.Case("IdentifierInfo *", "Record.readIdentifier()")
.Case("StringRef", "Record.readString()")
.Case("ParamIdx", "ParamIdx::deserialize(Record.readInt())")
- .Case("OMPTraitInfo *", "Record.readOMPTraitInfo()")
+ .Case("OMPTraitInfo", "Record.readOMPTraitInfo()")
.Default("Record.readInt()");
}
@@ -131,7 +131,7 @@ static std::string WritePCHRecord(StringRef type, StringRef name) {
.Case("StringRef", "AddString(" + std::string(name) + ");\n")
.Case("ParamIdx",
"push_back(" + std::string(name) + ".serialize());\n")
- .Case("OMPTraitInfo *",
+ .Case("OMPTraitInfo",
"writeOMPTraitInfo(" + std::string(name) + ");\n")
.Default("push_back(" + std::string(name) + ");\n");
}
@@ -363,8 +363,8 @@ namespace {
OS << " if (SA->get" << getUpperName() << "().isValid())\n ";
OS << " OS << \" \" << SA->get" << getUpperName()
<< "().getSourceIndex();\n";
- } else if (type == "OMPTraitInfo *") {
- OS << " OS << \" \" << *SA->get" << getUpperName() << "();\n";
+ } else if (type == "OMPTraitInfo") {
+ OS << " OS << \" \" << SA->get" << getUpperName() << "();\n";
} else {
llvm_unreachable("Unknown SimpleArgument type!");
}
@@ -1314,7 +1314,7 @@ createArgument(const Record &Arg, StringRef Attr,
else if (ArgName == "VersionArgument")
Ptr = std::make_unique<VersionArgument>(Arg, Attr);
else if (ArgName == "OMPTraitInfoArgument")
- Ptr = std::make_unique<SimpleArgument>(Arg, Attr, "OMPTraitInfo *");
+ Ptr = std::make_unique<SimpleArgument>(Arg, Attr, "OMPTraitInfo");
if (!Ptr) {
// Search in reverse order so that the most-derived type is handled first.
More information about the cfe-commits
mailing list