summaryrefslogtreecommitdiff
path: root/lib/Sema/SemaAttr.cpp
diff options
context:
space:
mode:
authorMatthias Gehre <M.Gehre@gmx.de>2019-09-06 08:56:30 +0000
committerMatthias Gehre <M.Gehre@gmx.de>2019-09-06 08:56:30 +0000
commit38c89049e401e32738bf4ca40e8253c9186e8bf4 (patch)
tree496ba29510cb5b80222eabfba3011b49330c2f3a /lib/Sema/SemaAttr.cpp
parent0482c264287f5604fb11f78737f2df1bd4f67e0b (diff)
downloadclang-38c89049e401e32738bf4ca40e8253c9186e8bf4.tar.gz
Reland [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)
Reland after https://reviews.llvm.org/D66806 fixed the false-positive diagnostics. Summary: This fixes inference of gsl::Pointer on std::set::iterator with libstdc++ (the typedef for iterator on the template is a DependentNameType - we can only put the gsl::Pointer attribute on the underlaying record after instantiation) inference of gsl::Pointer on std::vector::iterator with libc++ (the class was forward-declared, we added the gsl::Pointer on the canonical decl (the forward decl), and later when the template was instantiated, there was no attribute on the definition so it was not instantiated). and a duplicate gsl::Pointer on some class with libstdc++ (we first added an attribute to a incomplete instantiation, and then another was copied from the template definition when the instantiation was completed). We now add the attributes to all redeclarations to fix thos issues and make their usage easier. Reviewers: gribozavr Subscribers: Szelethus, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66179 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@371182 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaAttr.cpp')
-rw-r--r--lib/Sema/SemaAttr.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/Sema/SemaAttr.cpp b/lib/Sema/SemaAttr.cpp
index e2542edf6e..23cb47481f 100644
--- a/lib/Sema/SemaAttr.cpp
+++ b/lib/Sema/SemaAttr.cpp
@@ -88,13 +88,11 @@ void Sema::AddMsStructLayoutForRecord(RecordDecl *RD) {
template <typename Attribute>
static void addGslOwnerPointerAttributeIfNotExisting(ASTContext &Context,
CXXRecordDecl *Record) {
- CXXRecordDecl *Canonical = Record->getCanonicalDecl();
- if (Canonical->hasAttr<OwnerAttr>() || Canonical->hasAttr<PointerAttr>())
+ if (Record->hasAttr<OwnerAttr>() || Record->hasAttr<PointerAttr>())
return;
- Canonical->addAttr(::new (Context) Attribute(SourceRange{}, Context,
- /*DerefType*/ nullptr,
- /*Spelling=*/0));
+ for (Decl *Redecl : Record->redecls())
+ Redecl->addAttr(Attribute::CreateImplicit(Context, /*DerefType=*/nullptr));
}
void Sema::inferGslPointerAttribute(NamedDecl *ND,
@@ -189,8 +187,7 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl *Record) {
// Handle classes that directly appear in std namespace.
if (Record->isInStdNamespace()) {
- CXXRecordDecl *Canonical = Record->getCanonicalDecl();
- if (Canonical->hasAttr<OwnerAttr>() || Canonical->hasAttr<PointerAttr>())
+ if (Record->hasAttr<OwnerAttr>() || Record->hasAttr<PointerAttr>())
return;
if (StdOwners.count(Record->getName()))