https://github.com/Snape3058 updated https://github.com/llvm/llvm-project/pull/71073
>From 90d72a1f1036d2486e66c5ec16c3a8dc4241fc00 Mon Sep 17 00:00:00 2001 From: Ella Ma <alansnape3...@gmail.com> Date: Thu, 2 Nov 2023 23:14:15 +0800 Subject: [PATCH 1/2] [clang][analyzer] Add a test case to PR-70792 for Issue-59493 --- clang/test/Analysis/issue-70464.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/clang/test/Analysis/issue-70464.cpp b/clang/test/Analysis/issue-70464.cpp index f3b3072eb919823..331068775821e7e 100644 --- a/clang/test/Analysis/issue-70464.cpp +++ b/clang/test/Analysis/issue-70464.cpp @@ -66,3 +66,23 @@ 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[1]; +}; + +class Derived : public Base { +public: + Derived() : Base{{42}} { + // The dereference to this->foox below should be initialized properly. + clang_analyzer_dump(this->foox[0]); // expected-warning{{42 S32b}} + clang_analyzer_dump(foox[0]); // expected-warning{{42 S32b}} + } +}; + +void entry() { Derived test; } + +} // namespace init_list_array >From 34e909e5bb31fa766114f6dc7bf43818932861a2 Mon Sep 17 00:00:00 2001 From: Ella Ma <alansnape3...@gmail.com> Date: Fri, 3 Nov 2023 14:05:21 +0800 Subject: [PATCH 2/2] [pr71073] update as revision, add a test case also for #54533 --- clang/test/Analysis/issue-70464.cpp | 76 +++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/clang/test/Analysis/issue-70464.cpp b/clang/test/Analysis/issue-70464.cpp index 331068775821e7e..a2ce9a7310e472c 100644 --- a/clang/test/Analysis/issue-70464.cpp +++ b/clang/test/Analysis/issue-70464.cpp @@ -71,18 +71,84 @@ void entry() { Derived test; } namespace init_list_array { struct Base { - int foox[1]; + 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{{42}} { + Derived() : Base{FORTY_TWO} { // The dereference to this->foox below should be initialized properly. - clang_analyzer_dump(this->foox[0]); // expected-warning{{42 S32b}} - clang_analyzer_dump(foox[0]); // expected-warning{{42 S32b}} + clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}} + clang_analyzer_dump(foox); // expected-warning{{42 S32b}} } }; void entry() { Derived test; } -} // namespace init_list_array +} // namespace init_list_enum _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits