-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[alpha.webkit.ForwardDeclChecker] Ignore forward declared struct. #133804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: Ryosuke Niwa (rniwa) ChangesThere 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. Full diff: https://github.com/llvm/llvm-project/pull/133804.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
index a524593b0119b..399ae9e0a6874 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
@@ -108,17 +108,16 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
RTC.visitTypedef(TD);
auto QT = TD->getUnderlyingType().getCanonicalType();
if (BR->getSourceManager().isInSystemHeader(TD->getBeginLoc())) {
- if (auto *Type = QT.getTypePtrOrNull(); Type && QT->isPointerType())
+ if (auto *Type = QT.getTypePtrOrNull())
SystemTypes.insert(Type);
}
}
bool isUnknownType(QualType QT) const {
- auto *Type = QT.getTypePtrOrNull();
- if (!Type)
- return false;
auto *CanonicalType = QT.getCanonicalType().getTypePtrOrNull();
- auto PointeeQT = Type->getPointeeType();
+ if (!CanonicalType)
+ return false;
+ auto PointeeQT = CanonicalType->getPointeeType();
auto *PointeeType = PointeeQT.getTypePtrOrNull();
if (!PointeeType)
return false;
@@ -128,6 +127,7 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
auto Name = R->getName();
return !R->hasDefinition() && !RTC.isUnretained(QT) &&
!SystemTypes.contains(CanonicalType) &&
+ !SystemTypes.contains(PointeeType) &&
!Name.starts_with("Opaque") && Name != "_NSZone";
}
diff --git a/clang/test/Analysis/Checkers/WebKit/forward-decl-checker.mm b/clang/test/Analysis/Checkers/WebKit/forward-decl-checker.mm
index 151cbe2affa92..64100d60c4867 100644
--- a/clang/test/Analysis/Checkers/WebKit/forward-decl-checker.mm
+++ b/clang/test/Analysis/Checkers/WebKit/forward-decl-checker.mm
@@ -25,6 +25,8 @@
Obj* provide_obj_ptr();
void receive_obj_ptr(Obj* p = nullptr);
+sqlite3* open_db();
+void close_db(sqlite3*);
Obj* ptr(Obj* arg) {
receive_obj_ptr(provide_obj_ptr());
@@ -34,6 +36,8 @@
receive_obj_ptr(arg);
receive_obj_ptr(nullptr);
receive_obj_ptr();
+ auto* db = open_db();
+ close_db(db);
return obj;
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thank you! |
…vm#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.
…vm#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.
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.