|
1 |
| -// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s -Wno-undefined-bool-conversion |
| 1 | +// RUN: %clang_analyze_cc1 \ |
| 2 | +// RUN: -analyzer-checker=core,debug.ExprInspection \ |
| 3 | +// RUN: -verify %s \ |
| 4 | +// RUN: -Wno-undefined-bool-conversion |
| 5 | +// RUN: %clang_analyze_cc1 \ |
| 6 | +// RUN: -analyzer-checker=core,debug.ExprInspection,unix.Malloc \ |
| 7 | +// RUN: -verify %s \ |
| 8 | +// RUN: -Wno-undefined-bool-conversion |
| 9 | +// unix.Malloc is necessary to model __builtin_alloca, |
| 10 | +// which could trigger an "unexpected region" bug in StackAddrEscapeChecker. |
2 | 11 |
|
3 | 12 | typedef __INTPTR_TYPE__ intptr_t;
|
4 | 13 |
|
5 | 14 | template <typename T>
|
6 | 15 | void clang_analyzer_dump(T x);
|
7 | 16 |
|
| 17 | +using size_t = decltype(sizeof(int)); |
| 18 | +void * malloc(size_t size); |
| 19 | +void free(void*); |
| 20 | + |
8 | 21 | const int& g() {
|
9 | 22 | int s;
|
10 | 23 | return s; // expected-warning{{Address of stack memory associated with local variable 's' returned}} expected-warning{{reference to stack memory associated with local variable 's' returned}}
|
@@ -846,3 +859,21 @@ void top(char **p) {
|
846 | 859 | foo(); // no-warning FIXME: p binding is reclaimed before the function end
|
847 | 860 | }
|
848 | 861 | } // namespace early_reclaim_dead_limitation
|
| 862 | + |
| 863 | +namespace alloca_region_pointer { |
| 864 | +void callee(char **pptr) { |
| 865 | + char local; |
| 866 | + *pptr = &local; |
| 867 | +} // no crash |
| 868 | + |
| 869 | +void top_alloca_no_crash_fn() { |
| 870 | + char **pptr = (char**)__builtin_alloca(sizeof(char*)); |
| 871 | + callee(pptr); |
| 872 | +} |
| 873 | + |
| 874 | +void top_malloc_no_crash_fn() { |
| 875 | + char **pptr = (char**)malloc(sizeof(char*)); |
| 876 | + callee(pptr); |
| 877 | + free(pptr); |
| 878 | +} |
| 879 | +} // namespace alloca_region_pointer |
0 commit comments