Skip to content

Commit 6231f33

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.7 [skip ci]
1 parent c5f05cf commit 6231f33

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,
@@ -252,17 +274,6 @@ clang::ast_matchers::DeclarationMatcher statusOrOperatorBaseClass() {
252274
hasName("absl::internal_statusor::OperatorBase"));
253275
}
254276

255-
clang::ast_matchers::TypeMatcher possiblyAliasedStatusOrType() {
256-
using namespace ::clang::ast_matchers; // NOLINT: Too many names
257-
return hasUnqualifiedDesugaredType(
258-
recordType(hasDeclaration(statusOrClass())));
259-
}
260-
261-
clang::ast_matchers::TypeMatcher possiblyAliasedStatusType() {
262-
using namespace ::clang::ast_matchers; // NOLINT: Too many names
263-
return hasUnqualifiedDesugaredType(recordType(hasDeclaration(statusClass())));
264-
}
265-
266277
clang::ast_matchers::TypeMatcher statusOrType() {
267278
using namespace ::clang::ast_matchers; // NOLINT: Too many names
268279
return hasCanonicalType(qualType(hasDeclaration(statusOrClass())));
@@ -274,11 +285,11 @@ bool isRecordTypeWithName(QualType Type, llvm::StringRef TypeName) {
274285
}
275286

276287
bool isStatusOrType(QualType Type) {
277-
return isRecordTypeWithName(Type, "absl::StatusOr");
288+
return isTypeNamed(Type, {"absl"}, "StatusOr");
278289
}
279290

280291
bool isStatusType(QualType Type) {
281-
return isRecordTypeWithName(Type, "absl::Status");
292+
return isTypeNamed(Type, {"absl"}, "Status");
282293
}
283294

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

0 commit comments

Comments
 (0)