Skip to content

Commit d8fd665

Browse files
authored
[alpha.webkit.ForwardDeclChecker] Ignore forward declared struct. (#133804)
There are some system libraries such as sqlite3 which forward declare a struct then use a pointer to that forward declared type in various APIs. Ignore these types ForwardDeclChecker like other pointer types.
1 parent a2d983c commit d8fd665

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,16 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
108108
RTC.visitTypedef(TD);
109109
auto QT = TD->getUnderlyingType().getCanonicalType();
110110
if (BR->getSourceManager().isInSystemHeader(TD->getBeginLoc())) {
111-
if (auto *Type = QT.getTypePtrOrNull(); Type && QT->isPointerType())
111+
if (auto *Type = QT.getTypePtrOrNull())
112112
SystemTypes.insert(Type);
113113
}
114114
}
115115

116116
bool isUnknownType(QualType QT) const {
117-
auto *Type = QT.getTypePtrOrNull();
118-
if (!Type)
119-
return false;
120117
auto *CanonicalType = QT.getCanonicalType().getTypePtrOrNull();
121-
auto PointeeQT = Type->getPointeeType();
118+
if (!CanonicalType)
119+
return false;
120+
auto PointeeQT = CanonicalType->getPointeeType();
122121
auto *PointeeType = PointeeQT.getTypePtrOrNull();
123122
if (!PointeeType)
124123
return false;
@@ -128,7 +127,8 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
128127
auto Name = R->getName();
129128
return !R->hasDefinition() && !RTC.isUnretained(QT) &&
130129
!SystemTypes.contains(CanonicalType) &&
131-
!Name.starts_with("Opaque") && Name != "_NSZone";
130+
!SystemTypes.contains(PointeeType) && !Name.starts_with("Opaque") &&
131+
Name != "_NSZone";
132132
}
133133

134134
void visitRecordDecl(const RecordDecl *RD, const Decl *DeclWithIssue) const {

clang/test/Analysis/Checkers/WebKit/forward-decl-checker.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
Obj* provide_obj_ptr();
2727
void receive_obj_ptr(Obj* p = nullptr);
28+
sqlite3* open_db();
29+
void close_db(sqlite3*);
2830

2931
Obj* ptr(Obj* arg) {
3032
receive_obj_ptr(provide_obj_ptr());
@@ -34,6 +36,8 @@
3436
receive_obj_ptr(arg);
3537
receive_obj_ptr(nullptr);
3638
receive_obj_ptr();
39+
auto* db = open_db();
40+
close_db(db);
3741
return obj;
3842
}
3943

clang/test/Analysis/Checkers/WebKit/mock-system-header.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ struct MemberVariable {
1616
T* obj { nullptr };
1717
};
1818

19+
typedef struct sqlite3 sqlite3;
20+
1921
typedef unsigned char uint8_t;
2022

2123
enum os_log_type_t : uint8_t {

0 commit comments

Comments
 (0)