Files
TheRock/compiler/amd-llvm/clang/test/Analysis/issue-70464.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

155 lines
4.4 KiB
C++

// RUN: %clang_analyze_cc1 %s -verify -analyzer-checker=core,debug.ExprInspection
// Refer to https://github.com/llvm/llvm-project/issues/70464 for more details.
//
// When the base class does not have a declared constructor, the base
// initializer in the constructor of the derived class should use the given
// initializer list to finish the initialization of the base class.
//
// Also testing base constructor and delegate constructor to make sure this
// change will not break these two cases when a CXXConstructExpr is available.
void clang_analyzer_dump(int);
namespace init_list {
struct Base {
int foox;
};
class Derived : public Base {
public:
Derived() : Base{42} {
// 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
namespace base_ctor_call {
struct Base {
int foox;
Base(int x) : foox(x) {}
};
class Derived : public Base {
public:
Derived() : Base{42} {
clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
}
};
void entry() { Derived test; }
} // namespace base_ctor_call
namespace delegate_ctor_call {
struct Base {
int foox;
};
struct Derived : Base {
Derived(int parx) { this->foox = parx; }
Derived() : Derived{42} {
clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
}
};
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