xref: /aosp_15_r20/external/clang/test/Analysis/mpicheckernotes.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -analyze -analyzer-checker=optin.mpi.MPI-Checker -analyzer-output=text -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li // MPI-Checker test file to test note diagnostics.
4*67e74705SXin Li 
5*67e74705SXin Li #include "MPIMock.h"
6*67e74705SXin Li 
doubleNonblocking()7*67e74705SXin Li void doubleNonblocking() {
8*67e74705SXin Li   double buf = 0;
9*67e74705SXin Li   MPI_Request sendReq;
10*67e74705SXin Li   MPI_Isend(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // expected-note{{Request is previously used by nonblocking call here.}}
11*67e74705SXin Li   MPI_Irecv(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // expected-warning{{Double nonblocking on request 'sendReq'.}} expected-note{{Double nonblocking on request 'sendReq'.}}
12*67e74705SXin Li   MPI_Wait(&sendReq, MPI_STATUS_IGNORE);
13*67e74705SXin Li }
14*67e74705SXin Li 
missingWait()15*67e74705SXin Li void missingWait() {
16*67e74705SXin Li   double buf = 0;
17*67e74705SXin Li   MPI_Request sendReq;
18*67e74705SXin Li   MPI_Ireduce(MPI_IN_PLACE, &buf, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD, &sendReq); // expected-note{{Request is previously used by nonblocking call here.}}
19*67e74705SXin Li } // expected-warning{{Request 'sendReq' has no matching wait.}} expected-note{{Request 'sendReq' has no matching wait.}}
20*67e74705SXin Li 
21*67e74705SXin Li // If more than 2 nonblocking calls are using a request in a sequence, they all
22*67e74705SXin Li // point to the first call as the 'previous' call. This is because the
23*67e74705SXin Li // BugReporterVisitor only checks for differences in state or existence of an
24*67e74705SXin Li // entity.
tripleNonblocking()25*67e74705SXin Li void tripleNonblocking() {
26*67e74705SXin Li   double buf = 0;
27*67e74705SXin Li   MPI_Request sendReq;
28*67e74705SXin Li   MPI_Isend(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // expected-note 2{{Request is previously used by nonblocking call here.}}
29*67e74705SXin Li   MPI_Irecv(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // expected-warning{{Double nonblocking on request 'sendReq'.}} expected-note{{Double nonblocking on request 'sendReq'.}}
30*67e74705SXin Li 
31*67e74705SXin Li   MPI_Isend(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // expected-warning{{Double nonblocking on request 'sendReq'.}} expected-note{{Double nonblocking on request 'sendReq'.}}
32*67e74705SXin Li 
33*67e74705SXin Li   MPI_Wait(&sendReq, MPI_STATUS_IGNORE);
34*67e74705SXin Li }
35