summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/Sema.cpp
diff options
context:
space:
mode:
authorIsmail Pazarbasi <ismail.pazarbasi@gmail.com>2015-05-14 16:14:57 +0000
committerIsmail Pazarbasi <ismail.pazarbasi@gmail.com>2015-05-14 16:14:57 +0000
commit538ef53c139d9915327960217e922b2be7e8b3fd (patch)
tree3d6a10da310f704215fff7d5b0b3cbec701f3545 /clang/lib/Sema/Sema.cpp
parent9d08232e28f6bbdfeb080d2d9f138a6dc55d7e93 (diff)
downloadbcm5719-llvm-538ef53c139d9915327960217e922b2be7e8b3fd.tar.gz
bcm5719-llvm-538ef53c139d9915327960217e922b2be7e8b3fd.zip
Detect uses of mismatching forms of 'new' and 'delete'
Emit warning when operand to `delete` is allocated with `new[]` or operand to `delete[]` is allocated with `new`. Reviewers: rtrieu, jordan_rose, rsmith Subscribers: majnemer, cfe-commits Differential Revision: http://reviews.llvm.org/D4661 llvm-svn: 237368
Diffstat (limited to 'clang/lib/Sema/Sema.cpp')
-rw-r--r--clang/lib/Sema/Sema.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 6825dfa41fa..dea01bab079 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -860,6 +860,17 @@ void Sema::ActOnEndOfTranslationUnit() {
}
}
+ if (!Diags.isIgnored(diag::warn_mismatched_delete_new, SourceLocation())) {
+ if (ExternalSource)
+ ExternalSource->ReadMismatchingDeleteExpressions(DeleteExprs);
+ for (const auto &DeletedFieldInfo : DeleteExprs) {
+ for (const auto &DeleteExprLoc : DeletedFieldInfo.second) {
+ AnalyzeDeleteExprMismatch(DeletedFieldInfo.first, DeleteExprLoc.first,
+ DeleteExprLoc.second);
+ }
+ }
+ }
+
// Check we've noticed that we're no longer parsing the initializer for every
// variable. If we miss cases, then at best we have a performance issue and
// at worst a rejects-valid bug.
@@ -1219,6 +1230,9 @@ void ExternalSemaSource::ReadUndefinedButUsed(
llvm::DenseMap<NamedDecl *, SourceLocation> &Undefined) {
}
+void ExternalSemaSource::ReadMismatchingDeleteExpressions(llvm::MapVector<
+ FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &) {}
+
void PrettyDeclStackTraceEntry::print(raw_ostream &OS) const {
SourceLocation Loc = this->Loc;
if (!Loc.isValid() && TheDecl) Loc = TheDecl->getLocation();
@@ -1467,3 +1481,8 @@ CapturedRegionScopeInfo *Sema::getCurCapturedRegion() {
return dyn_cast<CapturedRegionScopeInfo>(FunctionScopes.back());
}
+
+const llvm::MapVector<FieldDecl *, Sema::DeleteLocs> &
+Sema::getMismatchingDeleteExpressions() const {
+ return DeleteExprs;
+}
OpenPOWER on IntegriCloud