From 0d59356b7d3be96e15402369dc172227965bc87f Mon Sep 17 00:00:00 2001 From: Matthias Gehre Date: Wed, 21 Aug 2019 23:54:19 +0200 Subject: [PATCH] clang/lib/Analysis/LifetimeTypeCategory.cpp: Only infer implicit Owner/Pointer when DerefType can be deduced --- clang/lib/Analysis/LifetimeTypeCategory.cpp | 56 ++++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/clang/lib/Analysis/LifetimeTypeCategory.cpp b/clang/lib/Analysis/LifetimeTypeCategory.cpp index 2fe7a9c77a360d..d20c365f7de0ec 100644 --- a/clang/lib/Analysis/LifetimeTypeCategory.cpp +++ b/clang/lib/Analysis/LifetimeTypeCategory.cpp @@ -227,31 +227,37 @@ static TypeClassification classifyTypeCategoryImpl(const Type *T) { return {TypeCategory::Pointer, Pointee}; } - if (auto Cat = classifyStd(T)) - return {*Cat, Pointee}; - - // Every type that satisfies the standard Container requirements. - if (satisfiesContainerRequirements(R)) - return {TypeCategory::Owner, Pointee}; - - // Every type that provides unary * or -> and has a user-provided destructor. - // (Example: unique_ptr.) - if (hasDerefOperations(R) && !R->hasTrivialDestructor()) - return {TypeCategory::Owner, Pointee}; - - // Every type that satisfies the Ranges TS Range concept. - if (satisfiesRangeConcept(R)) - return {TypeCategory::Pointer, Pointee}; - - // Every type that satisfies the standard Iterator requirements. (Example: - // regex_iterator.), see https://en.cppreference.com/w/cpp/named_req/Iterator - if (satisfiesIteratorRequirements(R)) - return {TypeCategory::Pointer, Pointee}; - - // Every type that provides unary * or -> and does not have a user-provided - // destructor. (Example: span.) - if (hasDerefOperations(R) && R->hasTrivialDestructor()) - return {TypeCategory::Pointer, Pointee}; + // Do not attempt to infer implicit Pointer/Owner if we cannot deduce + // the DerefType. + if (!Pointee.isNull()) { + + if (auto Cat = classifyStd(T)) + return {*Cat, Pointee}; + + // Every type that satisfies the standard Container requirements. + if (satisfiesContainerRequirements(R)) + return {TypeCategory::Owner, Pointee}; + + // Every type that provides unary * or -> and has a user-provided + // destructor. (Example: unique_ptr.) + if (hasDerefOperations(R) && !R->hasTrivialDestructor()) + return {TypeCategory::Owner, Pointee}; + + // Every type that satisfies the Ranges TS Range concept. + if (satisfiesRangeConcept(R)) + return {TypeCategory::Pointer, Pointee}; + + // Every type that satisfies the standard Iterator requirements. (Example: + // regex_iterator.), see + // https://en.cppreference.com/w/cpp/named_req/Iterator + if (satisfiesIteratorRequirements(R)) + return {TypeCategory::Pointer, Pointee}; + + // Every type that provides unary * or -> and does not have a user-provided + // destructor. (Example: span.) + if (hasDerefOperations(R) && R->hasTrivialDestructor()) + return {TypeCategory::Pointer, Pointee}; + } // Every closure type of a lambda that captures by reference. if (R->isLambda()) {