Skip to content

Commit b4b6446

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.7 [skip ci]
1 parent 9ef87bb commit b4b6446

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

clang/include/clang/Analysis/FlowSensitive/Models/UncheckedStatusOrAccessModel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ clang::ast_matchers::DeclarationMatcher statusOrClass();
3535
clang::ast_matchers::DeclarationMatcher statusClass();
3636
// Match declaration of `absl::internal_statusor::OperatorBase`.
3737
clang::ast_matchers::DeclarationMatcher statusOrOperatorBaseClass();
38-
clang::ast_matchers::TypeMatcher possiblyAliasedStatusType();
39-
clang::ast_matchers::TypeMatcher possiblyAliasedStatusOrType();
4038
clang::ast_matchers::TypeMatcher statusOrType();
4139

4240
// Get RecordStorageLocation for the `Status` contained in the `StatusOr`

clang/lib/Analysis/FlowSensitive/Models/UncheckedStatusOrAccessModel.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,30 @@ using ::clang::ast_matchers::StatementMatcher;
3939

4040
} // namespace
4141

42-
static bool isStatusOrOperatorBaseType(QualType type) {
43-
return isRecordTypeWithName(type, "absl::internal_statusor::OperatorBase");
42+
static bool namespaceEquals(const NamespaceDecl *NS,
43+
clang::ArrayRef<clang::StringRef> NamespaceNames) {
44+
while (!NamespaceNames.empty() && NS) {
45+
if (NS->getName() != NamespaceNames.consume_back())
46+
return false;
47+
NS = dyn_cast_or_null<NamespaceDecl>(NS->getParent());
48+
}
49+
return NamespaceNames.empty() && !NS;
50+
}
51+
52+
// TODO: move this to a proper place to share with the rest of clang
53+
static bool isTypeNamed(QualType Type, clang::ArrayRef<clang::StringRef> NS,
54+
StringRef Name) {
55+
if (Type.isNull())
56+
return false;
57+
if (auto *RD = Type->getAsRecordDecl())
58+
if (RD->getName() == Name)
59+
if (const auto *N = dyn_cast_or_null<NamespaceDecl>(RD->getDeclContext()))
60+
return namespaceEquals(N, NS);
61+
return false;
62+
}
63+
64+
static bool isStatusOrOperatorBaseType(QualType Type) {
65+
return isTypeNamed(Type, {"absl", "internal_statusor"}, "OperatorBase");
4466
}
4567

4668
static bool isSafeUnwrap(RecordStorageLocation *StatusOrLoc,
@@ -217,17 +239,6 @@ clang::ast_matchers::DeclarationMatcher statusOrOperatorBaseClass() {
217239
hasName("absl::internal_statusor::OperatorBase"));
218240
}
219241

220-
clang::ast_matchers::TypeMatcher possiblyAliasedStatusOrType() {
221-
using namespace ::clang::ast_matchers; // NOLINT: Too many names
222-
return hasUnqualifiedDesugaredType(
223-
recordType(hasDeclaration(statusOrClass())));
224-
}
225-
226-
clang::ast_matchers::TypeMatcher possiblyAliasedStatusType() {
227-
using namespace ::clang::ast_matchers; // NOLINT: Too many names
228-
return hasUnqualifiedDesugaredType(recordType(hasDeclaration(statusClass())));
229-
}
230-
231242
clang::ast_matchers::TypeMatcher statusOrType() {
232243
using namespace ::clang::ast_matchers; // NOLINT: Too many names
233244
return hasCanonicalType(qualType(hasDeclaration(statusOrClass())));
@@ -239,11 +250,11 @@ bool isRecordTypeWithName(QualType Type, llvm::StringRef TypeName) {
239250
}
240251

241252
bool isStatusOrType(QualType Type) {
242-
return isRecordTypeWithName(Type, "absl::StatusOr");
253+
return isTypeNamed(Type, {"absl"}, "StatusOr");
243254
}
244255

245256
bool isStatusType(QualType Type) {
246-
return isRecordTypeWithName(Type, "absl::Status");
257+
return isTypeNamed(Type, {"absl"}, "Status");
247258
}
248259

249260
llvm::StringMap<QualType> getSyntheticFields(QualType Ty, QualType StatusType,

0 commit comments

Comments
 (0)