brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 41c0d56 Raw
45 lines · c
1// Check that omp atomic compare handles signedness of integer comparisons2// correctly.3//4// At one time, a bug sometimes reversed the signedness.5 6// RUN: %libomp-compile7// RUN: %libomp-run | FileCheck %s8 9// This test uses -fopenmp-version, which is not a compiler flag that GCC10// supports.11// UNSUPPORTED: gcc12 13// High parallelism increases our chances of detecting a lack of atomicity.14#define NUM_THREADS_TRY 25615 16#include <limits.h>17#include <omp.h>18#include <stdio.h>19 20int main() {21  //      CHECK: signed: num_threads=[[#NUM_THREADS:]]{{$}}22  // CHECK-NEXT: signed: xs=[[#NUM_THREADS-1]]{{$}}23  int xs = -1;24  int numThreads;25  #pragma omp parallel for num_threads(NUM_THREADS_TRY)26  for (int i = 0; i < omp_get_num_threads(); ++i) {27    #pragma omp atomic compare28    if (xs < i) { xs = i; }29    if (i == 0)30      numThreads = omp_get_num_threads();31  }32  printf("signed: num_threads=%d\n", numThreads);33  printf("signed: xs=%d\n", xs);34 35  // CHECK-NEXT: unsigned: xu=0x0{{$}}36  unsigned xu = UINT_MAX;37  #pragma omp parallel for num_threads(NUM_THREADS_TRY)38  for (int i = 0; i < omp_get_num_threads(); ++i) {39    #pragma omp atomic compare40    if (xu > i) { xu = i; }41  }42  printf("unsigned: xu=0x%x\n", xu);43  return 0;44}45