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
4 
5 #include "Inputs/llvm.h"
6 
7 void clang_analyzer_printState();
8 
9 namespace clang {
10 struct Shape {};
11 class Triangle : public Shape {};
12 class Circle : public Shape {};
13 class Square : public Shape {};
14 } // namespace clang
15 
16 using namespace llvm;
17 using namespace clang;
18 
evalNonNullParamNonNullReturn(const Shape * S)19 void evalNonNullParamNonNullReturn(const Shape *S) {
20   const auto *C = dyn_cast_or_null<Circle>(S);
21   // expected-note@-1 {{Assuming 'S' is a 'Circle'}}
22   // expected-note@-2 {{'C' initialized here}}
23 
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 'Square'}}
27     // expected-note@-2 {{Taking false branch}}
28     return;
29   }
30 
31   clang_analyzer_printState();
32 
33   // CHECK:      "dynamic_types": [
34   // CHECK-NEXT:   { "region": "SymRegion{reg_$0<const struct clang::Shape * S>}", "dyn_type": "const class clang::Circle", "sub_classable": true }
35   // CHECK-NEXT: ],
36   // CHECK-NEXT: "dynamic_casts": [
37   // CHECK:        { "region": "SymRegion{reg_$0<const struct clang::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" }
40   // CHECK-NEXT:   ] }
41 
42   (void)(1 / !C);
43   // expected-note@-1 {{'C' is non-null}}
44   // expected-note@-2 {{Division by zero}}
45   // expected-warning@-3 {{Division by zero}}
46 }
47 
48