brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 07fd7ab Raw
48 lines · cpp
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 %s4 5#include "Inputs/llvm.h"6 7void clang_analyzer_printState();8 9namespace clang {10struct Shape {};11class Triangle : public Shape {};12class Circle : public Shape {};13class Square : public Shape {};14} // namespace clang15 16using namespace llvm;17using namespace clang;18 19void 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}}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 'const class clang::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 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 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