xref: /minix3/external/bsd/llvm/dist/clang/test/Analysis/exceptions.mm (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -analyze -fexceptions -fobjc-exceptions -fcxx-exceptions -analyzer-checker=core,unix.Malloc,debug.ExprInspection -verify %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambucvoid clang_analyzer_checkInlined(bool);
4*f4a2713aSLionel Sambuc
5*f4a2713aSLionel Sambuctypedef typeof(sizeof(int)) size_t;
6*f4a2713aSLionel Sambucvoid *malloc(size_t);
7*f4a2713aSLionel Sambucvoid free(void *);
8*f4a2713aSLionel Sambuc
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambucid getException();
11*f4a2713aSLionel Sambucvoid inlinedObjC() {
12*f4a2713aSLionel Sambuc  clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
13*f4a2713aSLionel Sambuc  @throw getException();
14*f4a2713aSLionel Sambuc}
15*f4a2713aSLionel Sambuc
16*f4a2713aSLionel Sambucint testObjC() {
17*f4a2713aSLionel Sambuc  int a; // uninitialized
18*f4a2713aSLionel Sambuc  void *mem = malloc(4); // no-warning (ObjC exceptions are usually fatal)
19*f4a2713aSLionel Sambuc  inlinedObjC();
20*f4a2713aSLionel Sambuc  free(mem);
21*f4a2713aSLionel Sambuc  return a; // no-warning
22*f4a2713aSLionel Sambuc}
23*f4a2713aSLionel Sambuc
24*f4a2713aSLionel Sambuc
25*f4a2713aSLionel Sambucvoid inlinedCXX() {
26*f4a2713aSLionel Sambuc  clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
27*f4a2713aSLionel Sambuc  throw -1;
28*f4a2713aSLionel Sambuc}
29*f4a2713aSLionel Sambuc
30*f4a2713aSLionel Sambucint testCXX() {
31*f4a2713aSLionel Sambuc  int a; // uninitialized
32*f4a2713aSLionel Sambuc  // FIXME: this should be reported as a leak, because C++ exceptions are
33*f4a2713aSLionel Sambuc  // often not fatal.
34*f4a2713aSLionel Sambuc  void *mem = malloc(4);
35*f4a2713aSLionel Sambuc  inlinedCXX();
36*f4a2713aSLionel Sambuc  free(mem);
37*f4a2713aSLionel Sambuc  return a; // no-warning
38*f4a2713aSLionel Sambuc}
39