1 // RUN: %clang_analyze_cc1 -std=c++14 \
2 // RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
3 // RUN: -analyzer-output=text -verify %s 2>&1 | FileCheck %s
5 #include "Inputs/llvm.h"
7 void clang_analyzer_printState();
11 class Triangle
: public Shape
{};
12 class Circle
: public Shape
{};
13 class Square
: public Shape
{};
17 using namespace clang
;
19 void evalNonNullParamNonNullReturn(const Shape
*S
) {
20 const auto *C
= dyn_cast_or_null
<Circle
>(S
);
21 // expected-note@-1 {{Assuming 'S' is a 'const class clang::Circle *'}}
22 // expected-note@-2 {{'C' initialized here}}
24 // FIXME: We assumed that 'S' is a 'Circle' therefore it is not a 'Square'.
25 if (dyn_cast_or_null
<Square
>(S
)) {
26 // expected-note@-1 {{Assuming 'S' is not a 'const class clang::Square *'}}
27 // expected-note@-2 {{Taking false branch}}
31 clang_analyzer_printState();
33 // CHECK: "dynamic_types": [
34 // CHECK-NEXT: { "region": "SymRegion{reg_$0<const Shape * S>}", "dyn_type": "const class clang::Circle", "sub_classable": true }
36 // CHECK-NEXT: "dynamic_casts": [
37 // CHECK: { "region": "SymRegion{reg_$0<const Shape * S>}", "casts": [
38 // CHECK-NEXT: { "from": "struct clang::Shape", "to": "class clang::Circle", "kind": "success" },
39 // CHECK-NEXT: { "from": "struct clang::Shape", "to": "class clang::Square", "kind": "fail" }
43 // expected-note@-1 {{'C' is non-null}}
44 // expected-note@-2 {{Division by zero}}
45 // expected-warning@-3 {{Division by zero}}