[clang] 05d52a4 - [analyzer][NFC] Add a test case to PR 70792 for Issue 59493 and 54533 (#71073)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 3 02:10:36 PDT 2023
Author: Ella Ma
Date: 2023-11-03T17:10:31+08:00
New Revision: 05d52a415b394f46e3503dd253d6a9e2701c6d4c
URL: https://github.com/llvm/llvm-project/commit/05d52a415b394f46e3503dd253d6a9e2701c6d4c
DIFF: https://github.com/llvm/llvm-project/commit/05d52a415b394f46e3503dd253d6a9e2701c6d4c.diff
LOG: [analyzer][NFC] Add a test case to PR 70792 for Issue 59493 and 54533 (#71073)
Following PR #70792 for issue #70464
Adding test cases for issue #59493 and #54533
Added:
Modified:
clang/test/Analysis/issue-70464.cpp
Removed:
################################################################################
diff --git a/clang/test/Analysis/issue-70464.cpp b/clang/test/Analysis/issue-70464.cpp
index f3b3072eb919823..a2ce9a7310e472c 100644
--- a/clang/test/Analysis/issue-70464.cpp
+++ b/clang/test/Analysis/issue-70464.cpp
@@ -66,3 +66,89 @@ struct Derived : Base {
void entry() { Derived test; }
} // namespace delegate_ctor_call
+
+// Additional test case from issue #59493
+namespace init_list_array {
+
+struct Base {
+ int foox[5];
+};
+
+class Derived1 : public Base {
+public:
+ Derived1() : Base{{1,4,5,3,2}} {
+ // The dereference to this->foox below should be initialized properly.
+ clang_analyzer_dump(this->foox[0]); // expected-warning{{1 S32b}}
+ clang_analyzer_dump(this->foox[1]); // expected-warning{{4 S32b}}
+ clang_analyzer_dump(this->foox[2]); // expected-warning{{5 S32b}}
+ clang_analyzer_dump(this->foox[3]); // expected-warning{{3 S32b}}
+ clang_analyzer_dump(this->foox[4]); // expected-warning{{2 S32b}}
+ clang_analyzer_dump(foox[0]); // expected-warning{{1 S32b}}
+ clang_analyzer_dump(foox[1]); // expected-warning{{4 S32b}}
+ clang_analyzer_dump(foox[2]); // expected-warning{{5 S32b}}
+ clang_analyzer_dump(foox[3]); // expected-warning{{3 S32b}}
+ clang_analyzer_dump(foox[4]); // expected-warning{{2 S32b}}
+ }
+};
+
+void entry1() { Derived1 test; }
+
+class Derived2 : public Base {
+public:
+ Derived2() : Base{{0}} {
+ // The dereference to this->foox below should be initialized properly.
+ clang_analyzer_dump(this->foox[0]); // expected-warning{{0 S32b}}
+ clang_analyzer_dump(this->foox[1]); // expected-warning{{0 S32b}}
+ clang_analyzer_dump(this->foox[2]); // expected-warning{{0 S32b}}
+ clang_analyzer_dump(this->foox[3]); // expected-warning{{0 S32b}}
+ clang_analyzer_dump(this->foox[4]); // expected-warning{{0 S32b}}
+ clang_analyzer_dump(foox[0]); // expected-warning{{0 S32b}}
+ clang_analyzer_dump(foox[1]); // expected-warning{{0 S32b}}
+ clang_analyzer_dump(foox[2]); // expected-warning{{0 S32b}}
+ clang_analyzer_dump(foox[3]); // expected-warning{{0 S32b}}
+ clang_analyzer_dump(foox[4]); // expected-warning{{0 S32b}}
+ }
+};
+
+void entry2() { Derived2 test; }
+
+} // namespace init_list_array
+
+namespace init_list_struct {
+
+struct Base {
+ struct { int a; int b; } foox;
+};
+
+class Derived : public Base {
+public:
+ Derived() : Base{{42, 24}} {
+ // The dereference to this->foox below should be initialized properly.
+ clang_analyzer_dump(this->foox.a); // expected-warning{{42 S32b}}
+ clang_analyzer_dump(this->foox.b); // expected-warning{{24 S32b}}
+ clang_analyzer_dump(foox.a); // expected-warning{{42 S32b}}
+ clang_analyzer_dump(foox.b); // expected-warning{{24 S32b}}
+ }
+};
+
+} // namespace init_list_struct
+
+// Additional test case from issue 54533
+namespace init_list_enum {
+
+struct Base {
+ enum : unsigned char { ZERO = 0, FORTY_TWO = 42 } foox;
+};
+
+class Derived : public Base {
+public:
+ Derived() : Base{FORTY_TWO} {
+ // The dereference to this->foox below should be initialized properly.
+ clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
+ clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
+ }
+};
+
+void entry() { Derived test; }
+
+} // namespace init_list_enum
More information about the cfe-commits
mailing list