2019-10-19 08:08:17 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -std=c++14 \
|
2019-08-22 08:20:36 +08:00
|
|
|
// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
|
|
|
|
// RUN: -analyzer-output=text -verify %s 2>&1 | FileCheck %s
|
|
|
|
|
|
|
|
#include "Inputs/llvm.h"
|
|
|
|
|
|
|
|
void clang_analyzer_printState();
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
struct Shape {};
|
|
|
|
class Triangle : public Shape {};
|
|
|
|
class Circle : public Shape {};
|
|
|
|
class Square : public Shape {};
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace clang;
|
|
|
|
|
2019-08-23 11:23:58 +08:00
|
|
|
void evalNonNullParamNonNullReturn(const Shape *S) {
|
2019-08-22 08:20:36 +08:00
|
|
|
const auto *C = dyn_cast_or_null<Circle>(S);
|
|
|
|
// expected-note@-1 {{Assuming 'S' is a 'Circle'}}
|
|
|
|
// expected-note@-2 {{'C' initialized here}}
|
|
|
|
|
|
|
|
// FIXME: We assumed that 'S' is a 'Circle' therefore it is not a 'Square'.
|
|
|
|
if (dyn_cast_or_null<Square>(S)) {
|
|
|
|
// expected-note@-1 {{Assuming 'S' is not a 'Square'}}
|
|
|
|
// expected-note@-2 {{Taking false branch}}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clang_analyzer_printState();
|
|
|
|
|
|
|
|
// CHECK: "dynamic_types": [
|
2019-08-23 11:23:58 +08:00
|
|
|
// CHECK-NEXT: { "region": "SymRegion{reg_$0<const struct clang::Shape * S>}", "dyn_type": "const class clang::Circle", "sub_classable": true }
|
2019-08-22 08:20:36 +08:00
|
|
|
// CHECK-NEXT: ],
|
|
|
|
// CHECK-NEXT: "dynamic_casts": [
|
2019-08-23 11:23:58 +08:00
|
|
|
// CHECK: { "region": "SymRegion{reg_$0<const struct clang::Shape * S>}", "casts": [
|
2020-08-27 23:01:43 +08:00
|
|
|
// CHECK-NEXT: { "from": "struct clang::Shape", "to": "class clang::Circle", "kind": "success" },
|
|
|
|
// CHECK-NEXT: { "from": "struct clang::Shape", "to": "class clang::Square", "kind": "fail" }
|
2020-04-22 23:15:03 +08:00
|
|
|
// CHECK-NEXT: ] }
|
2019-08-22 08:20:36 +08:00
|
|
|
|
|
|
|
(void)(1 / !C);
|
|
|
|
// expected-note@-1 {{'C' is non-null}}
|
|
|
|
// expected-note@-2 {{Division by zero}}
|
|
|
|
// expected-warning@-3 {{Division by zero}}
|
|
|
|
}
|
|
|
|
|