Tedlion created this revision. Tedlion added a reviewer: clang. Tedlion added a project: clang. Herald added subscribers: steakhal, martong. Herald added a reviewer: NoQ. Herald added a project: All. Tedlion requested review of this revision. Herald added a subscriber: cfe-commits.
I found current clang reports a warning > warning: Passed-by-value struct argument contains uninitialized data (e.g., > field: '') [core.CallAndMessage] when do static analysis on the following code : // code piece 1 typedef struct{ unsigned x :3; unsigned :29; unsigned y; }A; extern void func1(A a); void func2(){ A a = {0}; func1(a); } } According C or C++ standards, "unnamed bit-fields are skipped during aggregate initialization." Unnamed bit-fields can not be explicitly initialized, and taking no explicitly initialization will not cause problems since they would not be used. With this patch, no warning will be reported on the above code. And the checker will still be effective to real warning. e.g. it will report " warning: Passed-by-value struct argument contains uninitialized data (e.g., field: 'y') [core.CallAndMessage]" on following code: typedef struct{ unsigned x :3; unsigned :29; unsigned y; }A; extern void func1(A a); void func2(){ A a; a.x = 0; func1(a); } } Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D146194 Files: clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp Index: clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp @@ -262,7 +262,9 @@ if (T->getAsStructureType()) { if (Find(FR)) return true; - } else { + } else if (!I->isUnnamedBitfield()){ + // unnamed bitfields are skipped during aggregate initialization + // Since they are not supposed to be used, warnings should not be reported const SVal &V = StoreMgr.getBinding(store, loc::MemRegionVal(FR)); if (V.isUndef()) return true;
Index: clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp @@ -262,7 +262,9 @@ if (T->getAsStructureType()) { if (Find(FR)) return true; - } else { + } else if (!I->isUnnamedBitfield()){ + // unnamed bitfields are skipped during aggregate initialization + // Since they are not supposed to be used, warnings should not be reported const SVal &V = StoreMgr.getBinding(store, loc::MemRegionVal(FR)); if (V.isUndef()) return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits