xref: /aosp_15_r20/external/clang/test/Analysis/diagnostics/text-diagnostics.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang --analyze -Xanalyzer -analyzer-output=text -fno-caret-diagnostics %s 2>&1 | FileCheck %s
2*67e74705SXin Li 
testA()3*67e74705SXin Li void testA() {
4*67e74705SXin Li   int *p = 0;
5*67e74705SXin Li   *p = 1;
6*67e74705SXin Li 
7*67e74705SXin Li   // CHECK-LABEL: text-diagnostics.c:{{.*}}:6: warning: Dereference of null pointer (loaded from variable 'p')
8*67e74705SXin Li   // CHECK-NEXT: text-diagnostics.c:[[@LINE-4]]:3: note: 'p' initialized to a null pointer value
9*67e74705SXin Li   // CHECK-NEXT: text-diagnostics.c:[[@LINE-4]]:6: note: Dereference of null pointer (loaded from variable 'p')
10*67e74705SXin Li }
11*67e74705SXin Li 
testB(int * q)12*67e74705SXin Li void testB(int *q) {
13*67e74705SXin Li   if (q)
14*67e74705SXin Li     return;
15*67e74705SXin Li   *q = 1;
16*67e74705SXin Li 
17*67e74705SXin Li   // CHECK-LABEL: text-diagnostics.c:{{.*}}:6: warning: Dereference of null pointer (loaded from variable 'q')
18*67e74705SXin Li   // CHECK-NEXT: text-diagnostics.c:[[@LINE-5]]:7: note: Assuming 'q' is null
19*67e74705SXin Li   // CHECK-NEXT: text-diagnostics.c:[[@LINE-6]]:3: note: Taking false branch
20*67e74705SXin Li   // CHECK-NEXT: text-diagnostics.c:[[@LINE-5]]:6: note: Dereference of null pointer (loaded from variable 'q')
21*67e74705SXin Li }
22