switch (Kind) {
case CallKind::Function: {
- // We need to obtain the record type of the call's parameter to model it.
- if (!getRecordType(Call.parameters()[0]->getType())->isRecordType())
+ // We only model casts from pointers to pointers or from references
+ // to references. Other casts are most likely specialized and we
+ // cannot model them.
+ QualType ParamT = Call.parameters()[0]->getType();
+ QualType ResultT = Call.getResultType();
+ if (!(ParamT->isPointerType() && ResultT->isPointerType()) &&
+ !(ParamT->isReferenceType() && ResultT->isReferenceType()))
return false;
DV = Call.getArgSVal(0).getAs<DefinedOrUnknownSVal>();
#pragma clang system_header
+#include "system-header-simulator-cxx.h"
+
namespace llvm {
template <class X, class Y>
const X *cast(Y Value);
template <class X, class Y>
bool isa_and_nonnull(Y Value);
+
+template <typename X, typename Y>
+std::unique_ptr<X> cast(std::unique_ptr<Y> &&Value);
} // namespace llvm
void test_non_reference_null_region_crash(Shape s) {
cast<Circle>(s); // no-crash
}
+
+void test_non_reference_temporary_crash() {
+ extern std::unique_ptr<Shape> foo();
+ auto P = foo();
+ auto Q = cast<Circle>(std::move(P)); // no-crash
+}
} // namespace crashes
}
void evalNonNullParamNonNullReturnReference(const Shape &S) {
+ // Unmodeled cast from reference to pointer.
const auto *C = dyn_cast_or_null<Circle>(S);
- // expected-note@-1 {{Assuming 'S' is a 'Circle'}}
- // expected-note@-2 {{'C' initialized here}}
+ // expected-note@-1 {{'C' initialized here}}
if (!dyn_cast_or_null<Circle>(C)) {
// expected-note@-1 {{'C' is a 'Circle'}}
// expected-warning@-3 {{Division by zero}}
}
-void evalZeroParamNullReturn(const Shape &S) {
- const auto *C = S.getAs<Circle>();
+void evalZeroParamNullReturn(const Shape *S) {
+ const auto &C = S->getAs<Circle>();
// expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
- // expected-note@-2 {{'C' initialized to a null pointer value}}
+ // expected-note@-2 {{Storing null pointer value}}
+ // expected-note@-3 {{'C' initialized here}}
if (!dyn_cast_or_null<Triangle>(S)) {
// expected-note@-1 {{Assuming 'S' is a 'Triangle'}}
using namespace llvm;
using namespace clang;
-void evalNonNullParamNonNullReturnReference(const Shape &S) {
+void evalNonNullParamNonNullReturn(const Shape *S) {
const auto *C = dyn_cast_or_null<Circle>(S);
// expected-note@-1 {{Assuming 'S' is a 'Circle'}}
// expected-note@-2 {{'C' initialized here}}
clang_analyzer_printState();
// CHECK: "dynamic_types": [
- // CHECK-NEXT: { "region": "SymRegion{reg_$0<const struct clang::Shape & S>}", "dyn_type": "const class clang::Circle", "sub_classable": true }
+ // CHECK-NEXT: { "region": "SymRegion{reg_$0<const struct clang::Shape * S>}", "dyn_type": "const class clang::Circle", "sub_classable": true }
// CHECK-NEXT: ],
// CHECK-NEXT: "dynamic_casts": [
- // CHECK: { "region": "SymRegion{reg_$0<const struct clang::Shape & S>}", "casts": [
+ // CHECK: { "region": "SymRegion{reg_$0<const struct clang::Shape * S>}", "casts": [
// CHECK-NEXT: { "from": "struct clang::Shape", "to": "class clang::Circle", "kind": "success" },
// CHECK-NEXT: { "from": "struct clang::Shape", "to": "class clang::Square", "kind": "fail" }
// CHECK-NEXT: ]}