1*184c6242SDominic Chen // RUN: %clang_analyze_cc1 -analyzer-checker=optin.mpi.MPI-Checker -analyzer-output=text -verify %s
2160f19cdSDevin Coughlin 
3160f19cdSDevin Coughlin // MPI-Checker test file to test note diagnostics.
4160f19cdSDevin Coughlin 
5160f19cdSDevin Coughlin #include "MPIMock.h"
6160f19cdSDevin Coughlin 
doubleNonblocking()7160f19cdSDevin Coughlin void doubleNonblocking() {
8160f19cdSDevin Coughlin   double buf = 0;
9160f19cdSDevin Coughlin   MPI_Request sendReq;
10160f19cdSDevin Coughlin   MPI_Isend(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // expected-note{{Request is previously used by nonblocking call here.}}
11160f19cdSDevin Coughlin   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'.}}
12160f19cdSDevin Coughlin   MPI_Wait(&sendReq, MPI_STATUS_IGNORE);
13160f19cdSDevin Coughlin }
14160f19cdSDevin Coughlin 
missingWait()15160f19cdSDevin Coughlin void missingWait() {
16160f19cdSDevin Coughlin   double buf = 0;
17160f19cdSDevin Coughlin   MPI_Request sendReq;
18160f19cdSDevin Coughlin   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.}}
19160f19cdSDevin Coughlin } // expected-warning{{Request 'sendReq' has no matching wait.}} expected-note{{Request 'sendReq' has no matching wait.}}
20160f19cdSDevin Coughlin 
21160f19cdSDevin Coughlin // If more than 2 nonblocking calls are using a request in a sequence, they all
22160f19cdSDevin Coughlin // point to the first call as the 'previous' call. This is because the
23160f19cdSDevin Coughlin // BugReporterVisitor only checks for differences in state or existence of an
24160f19cdSDevin Coughlin // entity.
tripleNonblocking()25160f19cdSDevin Coughlin void tripleNonblocking() {
26160f19cdSDevin Coughlin   double buf = 0;
27160f19cdSDevin Coughlin   MPI_Request sendReq;
28160f19cdSDevin Coughlin   MPI_Isend(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // expected-note 2{{Request is previously used by nonblocking call here.}}
29160f19cdSDevin Coughlin   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'.}}
30160f19cdSDevin Coughlin 
31160f19cdSDevin Coughlin   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'.}}
32160f19cdSDevin Coughlin 
33160f19cdSDevin Coughlin   MPI_Wait(&sendReq, MPI_STATUS_IGNORE);
34160f19cdSDevin Coughlin }
35