brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 5c540a5 Raw
78 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s2 3#include "mock-types.h"4 5class Base {6public:7    void ref();8    void deref();9    void doWork();10};11 12class Derived : public Base {13public:14  virtual ~Derived();15 16  void ref() const;17  void deref() const;18};19 20class SubDerived final : public Derived {21};22 23class OtherObject {24public:25    Derived* obj();26    Base* base();27};28 29class String {30};31 32template<typename Target, typename Source>33inline Target* dynamicDowncast(Source* source)34{35    return static_cast<Target*>(source);36}37 38template<typename Target, typename Source>39inline Target* checkedDowncast(Source* source)40{41    return static_cast<Target*>(source);42}43 44template<typename Target, typename Source>45inline Target* uncheckedDowncast(Source* source)46{47    return static_cast<Target*>(source);48}49 50template<typename Target, typename Source>51Target* [[clang::annotate_type("webkit.pointerconversion")]] newCastFunction(Source*);52 53template<typename Target, typename Source>54Target* [[clang::annotate_type("unrelated-annotation")]] badCastFunction(Source*);55 56template<typename... Types>57String toString(const Types&... values);58 59void foo(OtherObject* other)60{61    dynamicDowncast<SubDerived>(other->obj());62    checkedDowncast<SubDerived>(other->obj());63    uncheckedDowncast<SubDerived>(other->obj());64    newCastFunction<SubDerived>(other->obj());65    badCastFunction<SubDerived>(other->obj());66    // expected-warning@-1{{Call argument is uncounted and unsafe}}67    toString(other->obj());68}69 70struct SomeStruct {71  Derived* [[clang::annotate_type("webkit.pointerconversion")]] ptrConversion(Base*);72 73  void foo(OtherObject& otherObj) {74    RefPtr ptr = otherObj.base();75    ptrConversion(ptr.get())->doWork();76  }77};78