| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s |
| 2 |
|
| 3 |
#include "mock-types.h" |
| 4 |
#include "mock-system-header.h" |
| 5 |
|
| 6 |
void WTFBreakpointTrap(); |
| 7 |
void WTFCrashWithInfo(int, const char*, const char*, int); |
| 8 |
void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion); |
| 9 |
void WTFReportBacktrace(void); |
| 10 |
|
| 11 |
void WTFCrash(void); |
| 12 |
void WTFCrashWithSecurityImplication(void); |
| 13 |
|
| 14 |
inline void compilerFenceForCrash() |
| 15 |
{ |
| 16 |
asm volatile("" ::: "memory"); |
| 17 |
} |
| 18 |
|
| 19 |
inline void isIntegralOrPointerType() { } |
| 20 |
|
| 21 |
template<typename T, typename... Types> |
| 22 |
void isIntegralOrPointerType(T, Types... types) |
| 23 |
{ |
| 24 |
static_assert(sizeof(char) < sizeof(short), "All types need to be bitwise_cast-able to integral type for logging"); |
| 25 |
isIntegralOrPointerType(types...); |
| 26 |
} |
| 27 |
|
| 28 |
#define CRASH_WITH_INFO(...) do { \ |
| 29 |
isIntegralOrPointerType(__VA_ARGS__); \ |
| 30 |
compilerFenceForCrash(); \ |
| 31 |
WTFBreakpointTrap(); \ |
| 32 |
__builtin_unreachable(); \ |
| 33 |
} while (0) |
| 34 |
|
| 35 |
#define RELEASE_ASSERT(assertion, ...) do { \ |
| 36 |
if (!(assertion)) \ |
| 37 |
CRASH_WITH_INFO(__VA_ARGS__); \ |
| 38 |
} while (0) |
| 39 |
|
| 40 |
#define ASSERT(assertion, ...) do { \ |
| 41 |
if (!(assertion)) { \ |
| 42 |
WTFReportAssertionFailure(__FILE__, __LINE__, __PRETTY_FUNCTION__, #assertion); \ |
| 43 |
CRASH_WITH_INFO(__VA_ARGS__); \ |
| 44 |
} \ |
| 45 |
} while (0) |
| 46 |
|
| 47 |
#if !defined(ALWAYS_INLINE) |
| 48 |
#define ALWAYS_INLINE inline |
| 49 |
#endif |
| 50 |
|
| 51 |
void WTFCrashWithInfoImpl(int line, const char* file, const char* function, int counter, unsigned long reason); |
| 52 |
void WTFCrashWithInfo(int line, const char* file, const char* function, int counter); |
| 53 |
|
| 54 |
template<typename T> |
| 55 |
ALWAYS_INLINE unsigned long wtfCrashArg(T* arg) { return reinterpret_cast<unsigned long>(arg); } |
| 56 |
|
| 57 |
template<typename T> |
| 58 |
ALWAYS_INLINE unsigned long wtfCrashArg(T arg) { return arg; } |
| 59 |
|
| 60 |
template<typename T> |
| 61 |
void WTFCrashWithInfo(int line, const char* file, const char* function, int counter, T reason) |
| 62 |
{ |
| 63 |
WTFCrashWithInfoImpl(line, file, function, counter, wtfCrashArg(reason)); |
| 64 |
} |
| 65 |
|
| 66 |
template<typename ToType, typename FromType> |
| 67 |
ToType bitwise_cast(FromType from); |
| 68 |
|
| 69 |
namespace std { |
| 70 |
|
| 71 |
template<typename T> |
| 72 |
T* addressof(T& arg); |
| 73 |
|
| 74 |
template<typename T> |
| 75 |
T&& forward(T& arg); |
| 76 |
|
| 77 |
template<typename ToType, typename FromType> |
| 78 |
ToType bit_cast(FromType from); |
| 79 |
|
| 80 |
#define offsetof(t, d) __builtin_offsetof(t, d) |
| 81 |
|
| 82 |
} // namespace std |
| 83 |
|
| 84 |
bool isMainThread(); |
| 85 |
bool isMainThreadOrGCThread(); |
| 86 |
bool isMainRunLoop(); |
| 87 |
bool isWebThread(); |
| 88 |
bool isUIThread(); |
| 89 |
bool mayBeGCThread(); |
| 90 |
|
| 91 |
enum class Flags : unsigned short { |
| 92 |
Flag1 = 1 << 0, |
| 93 |
Flag2 = 1 << 1, |
| 94 |
Flag3 = 1 << 2, |
| 95 |
}; |
| 96 |
|
| 97 |
template<typename E> class OptionSet { |
| 98 |
public: |
| 99 |
using StorageType = unsigned short; |
| 100 |
|
| 101 |
static constexpr OptionSet fromRaw(StorageType rawValue) { |
| 102 |
return OptionSet(static_cast<E>(rawValue), FromRawValue); |
| 103 |
} |
| 104 |
|
| 105 |
constexpr OptionSet() = default; |
| 106 |
|
| 107 |
constexpr OptionSet(E e) |
| 108 |
: m_storage(static_cast<StorageType>(e)) { |
| 109 |
} |
| 110 |
|
| 111 |
constexpr StorageType toRaw() const { return m_storage; } |
| 112 |
|
| 113 |
constexpr bool isEmpty() const { return !m_storage; } |
| 114 |
|
| 115 |
constexpr explicit operator bool() const { return !isEmpty(); } |
| 116 |
|
| 117 |
constexpr bool contains(E option) const { return containsAny(option); } |
| 118 |
constexpr bool containsAny(OptionSet optionSet) const { |
| 119 |
return !!(*this & optionSet); |
| 120 |
} |
| 121 |
|
| 122 |
constexpr bool containsAll(OptionSet optionSet) const { |
| 123 |
return (*this & optionSet) == optionSet; |
| 124 |
} |
| 125 |
|
| 126 |
constexpr void add(OptionSet optionSet) { m_storage |= optionSet.m_storage; } |
| 127 |
|
| 128 |
constexpr void remove(OptionSet optionSet) |
| 129 |
{ |
| 130 |
m_storage &= ~optionSet.m_storage; |
| 131 |
} |
| 132 |
|
| 133 |
constexpr void set(OptionSet optionSet, bool value) |
| 134 |
{ |
| 135 |
if (value) |
| 136 |
add(optionSet); |
| 137 |
else |
| 138 |
remove(optionSet); |
| 139 |
} |
| 140 |
|
| 141 |
constexpr friend OptionSet operator|(OptionSet lhs, OptionSet rhs) { |
| 142 |
return fromRaw(lhs.m_storage | rhs.m_storage); |
| 143 |
} |
| 144 |
|
| 145 |
constexpr friend OptionSet operator&(OptionSet lhs, OptionSet rhs) { |
| 146 |
return fromRaw(lhs.m_storage & rhs.m_storage); |
| 147 |
} |
| 148 |
|
| 149 |
constexpr friend OptionSet operator-(OptionSet lhs, OptionSet rhs) { |
| 150 |
return fromRaw(lhs.m_storage & ~rhs.m_storage); |
| 151 |
} |
| 152 |
|
| 153 |
constexpr friend OptionSet operator^(OptionSet lhs, OptionSet rhs) { |
| 154 |
return fromRaw(lhs.m_storage ^ rhs.m_storage); |
| 155 |
} |
| 156 |
|
| 157 |
private: |
| 158 |
enum InitializationTag { FromRawValue }; |
| 159 |
constexpr OptionSet(E e, InitializationTag) |
| 160 |
: m_storage(static_cast<StorageType>(e)) { |
| 161 |
} |
| 162 |
StorageType m_storage { 0 }; |
| 163 |
}; |
| 164 |
|
| 165 |
int atoi(const char* str); |
| 166 |
|
| 167 |
class Number { |
| 168 |
public: |
| 169 |
Number(int v) : v(v) { } |
| 170 |
Number(double); |
| 171 |
Number(const char* str) : v(atoi(str)) { } |
| 172 |
Number operator+(const Number&); |
| 173 |
Number& operator++() { ++v; return *this; } |
| 174 |
Number operator++(int) { Number returnValue(v); ++v; return returnValue; } |
| 175 |
const int& value() const { return v; } |
| 176 |
void someMethod(); |
| 177 |
|
| 178 |
private: |
| 179 |
int v; |
| 180 |
}; |
| 181 |
|
| 182 |
class DerivedNumber : public Number { |
| 183 |
public: |
| 184 |
DerivedNumber(char c) : Number(c - '0') { } |
| 185 |
DerivedNumber(const char* str) : Number(atoi(str)) { } |
| 186 |
}; |
| 187 |
|
| 188 |
class ComplexNumber { |
| 189 |
public: |
| 190 |
ComplexNumber() : realPart(0), complexPart(0) { } |
| 191 |
ComplexNumber(int real, const char* str) : realPart(real), complexPart(str) { } |
| 192 |
ComplexNumber(const ComplexNumber&); |
| 193 |
ComplexNumber& operator++() { realPart.someMethod(); return *this; } |
| 194 |
ComplexNumber operator++(int); |
| 195 |
ComplexNumber& operator<<(int); |
| 196 |
ComplexNumber& operator+(); |
| 197 |
|
| 198 |
const Number& real() const { return realPart; } |
| 199 |
const Number& complex() const; |
| 200 |
|
| 201 |
void ref() const; |
| 202 |
void deref() const; |
| 203 |
|
| 204 |
private: |
| 205 |
Number realPart; |
| 206 |
Number complexPart; |
| 207 |
}; |
| 208 |
|
| 209 |
class ObjectWithNonTrivialDestructor { |
| 210 |
public: |
| 211 |
ObjectWithNonTrivialDestructor() { } |
| 212 |
ObjectWithNonTrivialDestructor(unsigned v) : v(v) { } |
| 213 |
~ObjectWithNonTrivialDestructor() { } |
| 214 |
|
| 215 |
unsigned value() const { return v; } |
| 216 |
|
| 217 |
private: |
| 218 |
unsigned v { 0 }; |
| 219 |
}; |
| 220 |
|
| 221 |
class ObjectWithMutatingDestructor { |
| 222 |
public: |
| 223 |
ObjectWithMutatingDestructor() : n(0) { } |
| 224 |
ObjectWithMutatingDestructor(int n) : n(n) { } |
| 225 |
~ObjectWithMutatingDestructor() { n.someMethod(); } |
| 226 |
|
| 227 |
unsigned value() const { return n.value(); } |
| 228 |
|
| 229 |
private: |
| 230 |
Number n; |
| 231 |
}; |
| 232 |
|
| 233 |
class BaseType { |
| 234 |
public: |
| 235 |
BaseType() : n(0) { } |
| 236 |
BaseType(int v) : n(v) { } |
| 237 |
BaseType(const char*); |
| 238 |
private: |
| 239 |
Number n; |
| 240 |
}; |
| 241 |
|
| 242 |
class SomeType : public BaseType { |
| 243 |
public: |
| 244 |
using BaseType::BaseType; |
| 245 |
}; |
| 246 |
|
| 247 |
struct OtherObj { |
| 248 |
unsigned v { 0 }; |
| 249 |
OtherObj* children[4] { nullptr }; |
| 250 |
}; |
| 251 |
|
| 252 |
void __libcpp_verbose_abort(const char *__format, ...); |
| 253 |
|
| 254 |
class RefCounted { |
| 255 |
public: |
| 256 |
void ref() const; |
| 257 |
void deref() const; |
| 258 |
|
| 259 |
void method(); |
| 260 |
void someFunction(); |
| 261 |
int otherFunction(); |
| 262 |
unsigned recursiveTrivialFunction(int n) { return !n ? 1 : recursiveTrivialFunction(n - 1); } |
| 263 |
unsigned recursiveComplexFunction(int n) { return !n ? otherFunction() : recursiveComplexFunction(n - 1); } |
| 264 |
unsigned mutuallyRecursiveFunction1(int n) { return n < 0 ? 1 : (n % 2 ? mutuallyRecursiveFunction2(n - 2) : mutuallyRecursiveFunction1(n - 1)); } |
| 265 |
unsigned mutuallyRecursiveFunction2(int n) { return n < 0 ? 1 : (n % 3 ? mutuallyRecursiveFunction2(n - 3) : mutuallyRecursiveFunction1(n - 2)); } |
| 266 |
unsigned mutuallyRecursiveFunction3(int n) { return n < 0 ? 1 : (n % 5 ? mutuallyRecursiveFunction3(n - 5) : mutuallyRecursiveFunction4(n - 3)); } |
| 267 |
unsigned mutuallyRecursiveFunction4(int n) { return n < 0 ? 1 : (n % 7 ? otherFunction() : mutuallyRecursiveFunction3(n - 3)); } |
| 268 |
unsigned recursiveFunction5(unsigned n) { return n > 100 ? 2 : (n % 2 ? recursiveFunction5(n + 1) : recursiveFunction6(n + 2)); } |
| 269 |
unsigned recursiveFunction6(unsigned n) { return n > 100 ? 3 : (n % 2 ? recursiveFunction6(n % 7) : recursiveFunction7(n % 5)); } |
| 270 |
unsigned recursiveFunction7(unsigned n) { return n > 100 ? 5 : recursiveFunction7(n * 5); } |
| 271 |
|
| 272 |
void mutuallyRecursive8() { mutuallyRecursive9(); someFunction(); } |
| 273 |
void mutuallyRecursive9() { mutuallyRecursive8(); } |
| 274 |
|
| 275 |
int recursiveCost() { |
| 276 |
unsigned totalCost = 0; |
| 277 |
for (unsigned i = 0; i < sizeof(children)/sizeof(*children); ++i) { |
| 278 |
if (auto* child = children[i]) |
| 279 |
totalCost += child->recursiveCost(); |
| 280 |
} |
| 281 |
return totalCost; |
| 282 |
} |
| 283 |
|
| 284 |
int trivial1() { return 123; } |
| 285 |
float trivial2() { return 0.3; } |
| 286 |
float trivial3() { return (float)0.4; } |
| 287 |
float trivial4() { return 0.5f; } |
| 288 |
char trivial5() { return 'a'; } |
| 289 |
const char *trivial6() { return "abc"; } |
| 290 |
int trivial7() { return (1); } |
| 291 |
Number trivial8() { return Number { 5 }; } |
| 292 |
int trivial9() { return 3 + 4; } |
| 293 |
int trivial10() { return 0x1010 | 0x1; } |
| 294 |
int trivial11(int v) { return v + 1; } |
| 295 |
const char *trivial12(char *p) { return p ? "str" : "null"; } |
| 296 |
int trivial13(int v) { |
| 297 |
if (v) |
| 298 |
return 123; |
| 299 |
else |
| 300 |
return 0; |
| 301 |
} |
| 302 |
int trivial14(int v) { |
| 303 |
switch (v) { |
| 304 |
case 1: |
| 305 |
return 100; |
| 306 |
case 2: |
| 307 |
return 200; |
| 308 |
default: |
| 309 |
return 300; |
| 310 |
} |
| 311 |
return 0; |
| 312 |
} |
| 313 |
void *trivial15() { return static_cast<void*>(this); } |
| 314 |
unsigned long trivial16() { return *reinterpret_cast<unsigned long*>(this); } |
| 315 |
RefCounted& trivial17() const { return const_cast<RefCounted&>(*this); } |
| 316 |
RefCounted& trivial18() const { RELEASE_ASSERT(this, "this must be not null"); return const_cast<RefCounted&>(*this); } |
| 317 |
void trivial19() const { return; } |
| 318 |
|
| 319 |
static constexpr unsigned numBits = 4; |
| 320 |
int trivial20() { return v >> numBits; } |
| 321 |
|
| 322 |
const int* trivial21() { return number ? &number->value() : nullptr; } |
| 323 |
|
| 324 |
enum class Enum : unsigned short { |
| 325 |
Value1 = 1, |
| 326 |
Value2 = 2, |
| 327 |
}; |
| 328 |
bool trivial22() { return enumValue == Enum::Value1; } |
| 329 |
|
| 330 |
bool trivial23() const { return OptionSet<Flags>::fromRaw(v).contains(Flags::Flag1); } |
| 331 |
int trivial24() const { ASSERT(v); return v; } |
| 332 |
unsigned trivial25() const { return __c11_atomic_load((volatile _Atomic(unsigned) *)&v, __ATOMIC_RELAXED); } |
| 333 |
bool trivial26() { bool hasValue = v; return !hasValue; } |
| 334 |
bool trivial27(int v) { bool value; value = v ? 1 : 0; return value; } |
| 335 |
bool trivial28() { return true; } |
| 336 |
bool trivial29() { return false; } |
| 337 |
unsigned trivial30(unsigned v) { unsigned r = 0xff; r |= v; return r; } |
| 338 |
int trivial31(int* v) { return v[0]; } |
| 339 |
unsigned trivial32() { return sizeof(int); } |
| 340 |
unsigned trivial33() { return ~0xff; } |
| 341 |
template <unsigned v> unsigned trivial34() { return v; } |
| 342 |
void trivial35() { v++; } |
| 343 |
void trivial36() { ++(*number); } |
| 344 |
void trivial37() { (*number)++; } |
| 345 |
void trivial38() { v++; if (__builtin_expect(!!(number), 1)) (*number)++; } |
| 346 |
int trivial39() { return -v; } |
| 347 |
int trivial40() { return v << 2; } |
| 348 |
unsigned trivial41() { v = ++s_v; return v; } |
| 349 |
unsigned trivial42() { return bitwise_cast<unsigned long>(nullptr); } |
| 350 |
Number* trivial43() { return std::addressof(*number); } |
| 351 |
Number* trivial44() { return new Number(1); } |
| 352 |
ComplexNumber* trivial45() { return new ComplexNumber(); } |
| 353 |
void trivial46() { ASSERT(isMainThread()); } |
| 354 |
void trivial47() { ASSERT(isMainThreadOrGCThread()); } |
| 355 |
void trivial48() { ASSERT(isMainRunLoop()); } |
| 356 |
void trivial49() { ASSERT(isWebThread()); } |
| 357 |
void trivial50() { ASSERT(isUIThread()); } |
| 358 |
void trivial51() { ASSERT(mayBeGCThread()); } |
| 359 |
void trivial52() { WTFCrash(); } |
| 360 |
void trivial53() { WTFCrashWithSecurityImplication(); } |
| 361 |
unsigned trivial54() { return ComplexNumber().real().value(); } |
| 362 |
Number&& trivial55() { return std::forward(*number); } |
| 363 |
unsigned trivial56() { Number n { 5 }; return std::move(n).value(); } |
| 364 |
void trivial57() { do { break; } while (1); } |
| 365 |
void trivial58() { do { continue; } while (0); } |
| 366 |
void trivial59() { |
| 367 |
do { goto label; } |
| 368 |
while (0); |
| 369 |
label: |
| 370 |
return; |
| 371 |
} |
| 372 |
unsigned trivial60() { return ObjectWithNonTrivialDestructor { 5 }.value(); } |
| 373 |
unsigned trivial61() { return DerivedNumber('7').value(); } |
| 374 |
void trivial62() { WTFReportBacktrace(); } |
| 375 |
SomeType trivial63() { return SomeType(0); } |
| 376 |
SomeType trivial64() { return SomeType(); } |
| 377 |
void trivial65() { |
| 378 |
__libcpp_verbose_abort("%s", "aborting"); |
| 379 |
} |
| 380 |
RefPtr<RefCounted> trivial66() { return children[0]; } |
| 381 |
Ref<RefCounted> trivial67() { return *children[0]; } |
| 382 |
struct point { |
| 383 |
double x; |
| 384 |
double y; |
| 385 |
}; |
| 386 |
void trivial68() { point pt = { 1.0 }; } |
| 387 |
unsigned trivial69() { return offsetof(OtherObj, children); } |
| 388 |
DerivedNumber* trivial70() { [[clang::suppress]] return static_cast<DerivedNumber*>(number); } |
| 389 |
unsigned trivial71() { return std::bit_cast<unsigned>(nullptr); } |
| 390 |
unsigned trivial72() { Number n { 5 }; return WTF::move(n).value(); } |
| 391 |
|
| 392 |
static RefCounted& singleton() { |
| 393 |
static RefCounted s_RefCounted; |
| 394 |
s_RefCounted.ref(); |
| 395 |
return s_RefCounted; |
| 396 |
} |
| 397 |
|
| 398 |
static RefCounted& otherSingleton() { |
| 399 |
static RefCounted s_RefCounted; |
| 400 |
s_RefCounted.ref(); |
| 401 |
return s_RefCounted; |
| 402 |
} |
| 403 |
|
| 404 |
Number nonTrivial1() { return Number(3) + Number(4); } |
| 405 |
Number nonTrivial2() { return Number { 0.3 }; } |
| 406 |
int nonTrivial3() { return v ? otherFunction() : 0; } |
| 407 |
int nonTrivial4() { |
| 408 |
if (v) |
| 409 |
return 8; |
| 410 |
else |
| 411 |
return otherFunction(); |
| 412 |
} |
| 413 |
|
| 414 |
int nonTrivial5() { |
| 415 |
if (v) |
| 416 |
return otherFunction(); |
| 417 |
else |
| 418 |
return 9; |
| 419 |
} |
| 420 |
|
| 421 |
int nonTrivial6() { |
| 422 |
if (otherFunction()) |
| 423 |
return 1; |
| 424 |
else |
| 425 |
return 0; |
| 426 |
} |
| 427 |
|
| 428 |
int nonTrivial7() { |
| 429 |
switch (v) { |
| 430 |
case 1: |
| 431 |
return otherFunction(); |
| 432 |
default: |
| 433 |
return 7; |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
int nonTrivial8() { |
| 438 |
switch (v) { |
| 439 |
case 1: |
| 440 |
return 9; |
| 441 |
default: |
| 442 |
return otherFunction(); |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
int nonTrivial9() { |
| 447 |
switch (otherFunction()) { |
| 448 |
case 0: |
| 449 |
return -1; |
| 450 |
default: |
| 451 |
return 12; |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
static unsigned* another(); |
| 456 |
unsigned nonTrivial10() const { |
| 457 |
return __c11_atomic_load((volatile _Atomic(unsigned) *)another(), __ATOMIC_RELAXED); |
| 458 |
} |
| 459 |
|
| 460 |
void nonTrivial11() { |
| 461 |
Number num(0.3); |
| 462 |
} |
| 463 |
|
| 464 |
bool nonTrivial12() { |
| 465 |
bool val = otherFunction(); |
| 466 |
return val; |
| 467 |
} |
| 468 |
|
| 469 |
int nonTrivial13() { return ~otherFunction(); } |
| 470 |
int nonTrivial14() { int r = 0xff; r |= otherFunction(); return r; } |
| 471 |
void nonTrivial15() { ++complex; } |
| 472 |
void nonTrivial16() { complex++; } |
| 473 |
ComplexNumber nonTrivial17() { return complex << 2; } |
| 474 |
ComplexNumber nonTrivial18() { return +complex; } |
| 475 |
ComplexNumber* nonTrivial19() { return new ComplexNumber(complex); } |
| 476 |
unsigned nonTrivial20() { return ObjectWithMutatingDestructor { 7 }.value(); } |
| 477 |
unsigned nonTrivial21() { return Number("123").value(); } |
| 478 |
unsigned nonTrivial22() { return ComplexNumber(123, "456").real().value(); } |
| 479 |
unsigned nonTrivial23() { return DerivedNumber("123").value(); } |
| 480 |
SomeType nonTrivial24() { return SomeType("123"); } |
| 481 |
virtual void nonTrivial25() { } |
| 482 |
virtual ComplexNumber* operator->() { return nullptr; } |
| 483 |
|
| 484 |
static unsigned s_v; |
| 485 |
unsigned v { 0 }; |
| 486 |
Number* number { nullptr }; |
| 487 |
ComplexNumber complex; |
| 488 |
Enum enumValue { Enum::Value1 }; |
| 489 |
RefCounted* children[4]; |
| 490 |
}; |
| 491 |
|
| 492 |
unsigned RefCounted::s_v = 0; |
| 493 |
|
| 494 |
RefCounted* refCountedObj(); |
| 495 |
|
| 496 |
void test() |
| 497 |
{ |
| 498 |
refCountedObj()->someFunction(); |
| 499 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 500 |
} |
| 501 |
|
| 502 |
class UnrelatedClass { |
| 503 |
RefPtr<RefCounted> Field; |
| 504 |
bool value; |
| 505 |
|
| 506 |
public: |
| 507 |
RefCounted &getFieldTrivial() { return *Field.get(); } |
| 508 |
RefCounted *getFieldTernary() { return value ? Field.get() : nullptr; } |
| 509 |
|
| 510 |
void test() { |
| 511 |
getFieldTrivial().trivial1(); // no-warning |
| 512 |
getFieldTrivial().trivial2(); // no-warning |
| 513 |
getFieldTrivial().trivial3(); // no-warning |
| 514 |
getFieldTrivial().trivial4(); // no-warning |
| 515 |
getFieldTrivial().trivial5(); // no-warning |
| 516 |
getFieldTrivial().trivial6(); // no-warning |
| 517 |
getFieldTrivial().trivial7(); // no-warning |
| 518 |
getFieldTrivial().trivial8(); // no-warning |
| 519 |
getFieldTrivial().trivial9(); // no-warning |
| 520 |
getFieldTrivial().trivial10(); // no-warning |
| 521 |
getFieldTrivial().trivial11(1); // no-warning |
| 522 |
getFieldTrivial().trivial12(nullptr); // no-warning |
| 523 |
getFieldTrivial().trivial13(0); // no-warning |
| 524 |
getFieldTrivial().trivial14(3); // no-warning |
| 525 |
getFieldTrivial().trivial15(); // no-warning |
| 526 |
getFieldTrivial().trivial16(); // no-warning |
| 527 |
getFieldTrivial().trivial17(); // no-warning |
| 528 |
getFieldTrivial().trivial18(); // no-warning |
| 529 |
getFieldTrivial().trivial19(); // no-warning |
| 530 |
getFieldTrivial().trivial20(); // no-warning |
| 531 |
getFieldTrivial().trivial21(); // no-warning |
| 532 |
getFieldTrivial().trivial22(); // no-warning |
| 533 |
getFieldTrivial().trivial23(); // no-warning |
| 534 |
getFieldTrivial().trivial24(); // no-warning |
| 535 |
getFieldTrivial().trivial25(); // no-warning |
| 536 |
getFieldTrivial().trivial26(); // no-warning |
| 537 |
getFieldTrivial().trivial27(5); // no-warning |
| 538 |
getFieldTrivial().trivial28(); // no-warning |
| 539 |
getFieldTrivial().trivial29(); // no-warning |
| 540 |
getFieldTrivial().trivial30(7); // no-warning |
| 541 |
int a[] = {1, 2}; |
| 542 |
getFieldTrivial().trivial31(a); // no-warning |
| 543 |
getFieldTrivial().trivial32(); // no-warning |
| 544 |
getFieldTrivial().trivial33(); // no-warning |
| 545 |
getFieldTrivial().trivial34<7>(); // no-warning |
| 546 |
getFieldTrivial().trivial35(); // no-warning |
| 547 |
getFieldTrivial().trivial36(); // no-warning |
| 548 |
getFieldTrivial().trivial37(); // no-warning |
| 549 |
getFieldTrivial().trivial38(); // no-warning |
| 550 |
getFieldTrivial().trivial39(); // no-warning |
| 551 |
getFieldTrivial().trivial40(); // no-warning |
| 552 |
getFieldTrivial().trivial41(); // no-warning |
| 553 |
getFieldTrivial().trivial42(); // no-warning |
| 554 |
getFieldTrivial().trivial43(); // no-warning |
| 555 |
getFieldTrivial().trivial44(); // no-warning |
| 556 |
getFieldTrivial().trivial45(); // no-warning |
| 557 |
getFieldTrivial().trivial46(); // no-warning |
| 558 |
getFieldTrivial().trivial47(); // no-warning |
| 559 |
getFieldTrivial().trivial48(); // no-warning |
| 560 |
getFieldTrivial().trivial49(); // no-warning |
| 561 |
getFieldTrivial().trivial50(); // no-warning |
| 562 |
getFieldTrivial().trivial51(); // no-warning |
| 563 |
getFieldTrivial().trivial52(); // no-warning |
| 564 |
getFieldTrivial().trivial53(); // no-warning |
| 565 |
getFieldTrivial().trivial54(); // no-warning |
| 566 |
getFieldTrivial().trivial55(); // no-warning |
| 567 |
getFieldTrivial().trivial56(); // no-warning |
| 568 |
getFieldTrivial().trivial57(); // no-warning |
| 569 |
getFieldTrivial().trivial58(); // no-warning |
| 570 |
getFieldTrivial().trivial59(); // no-warning |
| 571 |
getFieldTrivial().trivial60(); // no-warning |
| 572 |
getFieldTrivial().trivial61(); // no-warning |
| 573 |
getFieldTrivial().trivial62(); // no-warning |
| 574 |
getFieldTrivial().trivial63(); // no-warning |
| 575 |
getFieldTrivial().trivial64(); // no-warning |
| 576 |
getFieldTrivial().trivial65(); // no-warning |
| 577 |
getFieldTrivial().trivial66()->trivial6(); // no-warning |
| 578 |
getFieldTrivial().trivial67()->trivial6(); // no-warning |
| 579 |
getFieldTrivial().trivial68(); // no-warning |
| 580 |
getFieldTrivial().trivial69(); // no-warning |
| 581 |
getFieldTrivial().trivial70(); // no-warning |
| 582 |
getFieldTrivial().trivial71(); // no-warning |
| 583 |
|
| 584 |
RefCounted::singleton().trivial18(); // no-warning |
| 585 |
RefCounted::singleton().someFunction(); // no-warning |
| 586 |
RefCounted::otherSingleton().trivial18(); // no-warning |
| 587 |
RefCounted::otherSingleton().someFunction(); // no-warning |
| 588 |
|
| 589 |
getFieldTrivial().recursiveTrivialFunction(7); // no-warning |
| 590 |
getFieldTrivial().recursiveComplexFunction(9); |
| 591 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 592 |
getFieldTrivial().mutuallyRecursiveFunction1(11); // no-warning |
| 593 |
getFieldTrivial().mutuallyRecursiveFunction2(13); // no-warning |
| 594 |
getFieldTrivial().mutuallyRecursiveFunction3(17); |
| 595 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 596 |
getFieldTrivial().mutuallyRecursiveFunction4(19); |
| 597 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 598 |
getFieldTrivial().recursiveFunction5(23); // no-warning |
| 599 |
getFieldTrivial().recursiveFunction6(29); // no-warning |
| 600 |
getFieldTrivial().recursiveFunction7(31); // no-warning |
| 601 |
|
| 602 |
getFieldTrivial().mutuallyRecursive8(); |
| 603 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 604 |
getFieldTrivial().mutuallyRecursive9(); |
| 605 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 606 |
|
| 607 |
getFieldTrivial().recursiveCost(); // no-warning |
| 608 |
|
| 609 |
getFieldTrivial().someFunction(); |
| 610 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 611 |
getFieldTrivial().nonTrivial1(); |
| 612 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 613 |
getFieldTrivial().nonTrivial2(); |
| 614 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 615 |
getFieldTrivial().nonTrivial3(); |
| 616 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 617 |
getFieldTrivial().nonTrivial4(); |
| 618 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 619 |
getFieldTrivial().nonTrivial5(); |
| 620 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 621 |
getFieldTrivial().nonTrivial6(); |
| 622 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 623 |
getFieldTrivial().nonTrivial7(); |
| 624 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 625 |
getFieldTrivial().nonTrivial8(); |
| 626 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 627 |
getFieldTrivial().nonTrivial9(); |
| 628 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 629 |
getFieldTrivial().nonTrivial10(); |
| 630 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 631 |
getFieldTrivial().nonTrivial11(); |
| 632 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 633 |
getFieldTrivial().nonTrivial12(); |
| 634 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 635 |
getFieldTrivial().nonTrivial13(); |
| 636 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 637 |
getFieldTrivial().nonTrivial14(); |
| 638 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 639 |
getFieldTrivial().nonTrivial15(); |
| 640 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 641 |
getFieldTrivial().nonTrivial16(); |
| 642 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 643 |
getFieldTrivial().nonTrivial17(); |
| 644 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 645 |
getFieldTrivial().nonTrivial18(); |
| 646 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 647 |
getFieldTrivial().nonTrivial19(); |
| 648 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 649 |
getFieldTrivial().nonTrivial20(); |
| 650 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 651 |
getFieldTrivial().nonTrivial21(); |
| 652 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 653 |
getFieldTrivial().nonTrivial22(); |
| 654 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 655 |
getFieldTrivial().nonTrivial23(); |
| 656 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 657 |
getFieldTrivial().nonTrivial24(); |
| 658 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 659 |
getFieldTrivial().nonTrivial25(); |
| 660 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 661 |
getFieldTrivial()->complex(); |
| 662 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 663 |
} |
| 664 |
|
| 665 |
void setField(RefCounted*); |
| 666 |
}; |
| 667 |
|
| 668 |
class UnrelatedClass2 { |
| 669 |
RefPtr<UnrelatedClass> Field; |
| 670 |
|
| 671 |
public: |
| 672 |
UnrelatedClass &getFieldTrivial() { return *Field.get(); } |
| 673 |
RefCounted &getFieldTrivialRecursively() { return getFieldTrivial().getFieldTrivial(); } |
| 674 |
RefCounted *getFieldTrivialTernary() { return Field ? Field->getFieldTernary() : nullptr; } |
| 675 |
|
| 676 |
template<typename T, typename ... AdditionalArgs> |
| 677 |
void callSetField(T&& item, AdditionalArgs&&... args) |
| 678 |
{ |
| 679 |
item.setField(std::forward<AdditionalArgs>(args)...); |
| 680 |
} |
| 681 |
|
| 682 |
template<typename T, typename ... AdditionalArgs> |
| 683 |
void callSetField2(T&& item, AdditionalArgs&&... args) |
| 684 |
{ |
| 685 |
item.setField(std::move<AdditionalArgs>(args)...); |
| 686 |
} |
| 687 |
|
| 688 |
void test() { |
| 689 |
getFieldTrivialRecursively().trivial1(); // no-warning |
| 690 |
getFieldTrivialTernary()->trivial2(); // no-warning |
| 691 |
getFieldTrivialRecursively().someFunction(); |
| 692 |
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} |
| 693 |
callSetField(getFieldTrivial(), refCountedObj()); // no-warning |
| 694 |
} |
| 695 |
}; |
| 696 |
|
| 697 |
RefPtr<RefCounted> object(); |
| 698 |
void someFunction(const RefCounted&); |
| 699 |
|
| 700 |
void test2() { |
| 701 |
someFunction(*object()); |
| 702 |
} |
| 703 |
|
| 704 |
void system_header() { |
| 705 |
callMethod<RefCountable>(object); |
| 706 |
} |
| 707 |
|
| 708 |
void log(RefCountable* obj) { |
| 709 |
os_log_msg(os_log_create("WebKit", "DOM"), OS_LOG_TYPE_INFO, "obj: %p next: %p", obj, obj->next()); |
| 710 |
} |