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