blob: fb0f62c61c4be87e9b89b75c744fbaaa75748cab [file] [log] [blame]
Saleem Abdulrasool114efe02014-06-18 20:51:10 +00001// RUN: %clang_cc1 -triple i686--windows -fms-compatibility -Oz -emit-llvm %s -o - | FileCheck %s
2// RUN: %clang_cc1 -triple thumbv7--windows -fms-compatibility -Oz -emit-llvm %s -o - | FileCheck %s
3
4void *test_InterlockedExchangePointer(void * volatile *Target, void *Value) {
5 return _InterlockedExchangePointer(Target, Value);
6}
7
8// CHECK: define{{.*}}i8* @test_InterlockedExchangePointer(i8** %Target, i8* %Value){{.*}}{
Saleem Abdulrasool11415c62014-06-18 21:48:44 +00009// CHECK: %[[TARGET:[0-9]+]] = bitcast i8** %Target to i32*
10// CHECK: %[[VALUE:[0-9]+]] = ptrtoint i8* %Value to i32
11// CHECK: %[[EXCHANGE:[0-9]+]] = atomicrmw xchg i32* %[[TARGET]], i32 %[[VALUE]] seq_cst
12// CHECK: %[[RESULT:[0-9]+]] = inttoptr i32 %[[EXCHANGE]] to i8*
13// CHECK: ret i8* %[[RESULT]]
Saleem Abdulrasool114efe02014-06-18 20:51:10 +000014// CHECK: }
15
16void *test_InterlockedCompareExchangePointer(void * volatile *Destination,
17 void *Exchange, void *Comparand) {
18 return _InterlockedCompareExchangePointer(Destination, Exchange, Comparand);
19}
20
21// CHECK: define{{.*}}i8* @test_InterlockedCompareExchangePointer(i8** %Destination, i8* %Exchange, i8* %Comparand){{.*}}{
Saleem Abdulrasool11415c62014-06-18 21:48:44 +000022// CHECK: %[[DEST:[0-9]+]] = bitcast i8** %Destination to i32*
23// CHECK: %[[EXCHANGE:[0-9]+]] = ptrtoint i8* %Exchange to i32
24// CHECK: %[[COMPARAND:[0-9]+]] = ptrtoint i8* %Comparand to i32
25// CHECK: %[[XCHG:[0-9]+]] = cmpxchg volatile i32* %[[DEST:[0-9]+]], i32 %[[COMPARAND:[0-9]+]], i32 %[[EXCHANGE:[0-9]+]] seq_cst seq_cst
26// CHECK: %[[EXTRACT:[0-9]+]] = extractvalue { i32, i1 } %[[XCHG]], 0
27// CHECK: %[[RESULT:[0-9]+]] = inttoptr i32 %[[EXTRACT]] to i8*
28// CHECK: ret i8* %[[RESULT:[0-9]+]]
Saleem Abdulrasool114efe02014-06-18 20:51:10 +000029// CHECK: }
30
31long test_InterlockedExchange(long *Target, long Value) {
32 return _InterlockedExchange(Target, Value);
33}
34
35// CHECK: define{{.*}}i32 @test_InterlockedExchange(i32* %Target, i32 %Value){{.*}}{
Saleem Abdulrasool11415c62014-06-18 21:48:44 +000036// CHECK: %[[EXCHANGE:[0-9]+]] = atomicrmw xchg i32* %Target, i32 %Value seq_cst
37// CHECK: ret i32 %[[EXCHANGE:[0-9]+]]
Saleem Abdulrasool114efe02014-06-18 20:51:10 +000038// CHECK: }