xref: /llvm-project/clang/test/Headers/stdckdint.c (revision 7e34ee5291b935a1e37cd1b132552187d5c784d0)
136946970Szijunzhao // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
2*7e34ee52SZijunZhaoCCK // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | FileCheck %s
3*7e34ee52SZijunZhaoCCK // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c11 %s -o - | FileCheck %s
4*7e34ee52SZijunZhaoCCK // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c17 %s -o - | FileCheck %s
536946970Szijunzhao // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | FileCheck %s
636946970Szijunzhao 
736946970Szijunzhao // expected-no-diagnostics
836946970Szijunzhao 
9*7e34ee52SZijunZhaoCCK #include <stdbool.h>
1036946970Szijunzhao #include <stdckdint.h>
1136946970Szijunzhao 
1236946970Szijunzhao // CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
1336946970Szijunzhao // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
1436946970Szijunzhao // CHECK-NEXT:  entry:
1536946970Szijunzhao // CHECK-NEXT:    [[RESULT:%.*]] = alloca i32, align 4
1636946970Szijunzhao // CHECK-NEXT:    [[TMP0:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 -1073741826, i32 -1073741826)
1736946970Szijunzhao // CHECK-NEXT:    [[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1
1836946970Szijunzhao // CHECK-NEXT:    [[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0
1936946970Szijunzhao // CHECK-NEXT:    store i32 [[TMP2]], ptr [[RESULT]], align 4
2036946970Szijunzhao // CHECK-NEXT:    ret i1 [[TMP1]]
2136946970Szijunzhao //
test_ckd_add()2236946970Szijunzhao bool test_ckd_add() {
2336946970Szijunzhao   int result;
2436946970Szijunzhao   return ckd_add(&result, -1073741826, -1073741826);
2536946970Szijunzhao }
2636946970Szijunzhao 
2736946970Szijunzhao // CHECK-LABEL: define dso_local zeroext i1 @test_ckd_sub(
2836946970Szijunzhao // CHECK-SAME: ) #[[ATTR0]] {
2936946970Szijunzhao // CHECK-NEXT:  entry:
3036946970Szijunzhao // CHECK-NEXT:    [[RESULT:%.*]] = alloca i32, align 4
3136946970Szijunzhao // CHECK-NEXT:    [[TMP0:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 -1073741826, i32 1073741826)
3236946970Szijunzhao // CHECK-NEXT:    [[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1
3336946970Szijunzhao // CHECK-NEXT:    [[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0
3436946970Szijunzhao // CHECK-NEXT:    store i32 [[TMP2]], ptr [[RESULT]], align 4
3536946970Szijunzhao // CHECK-NEXT:    ret i1 [[TMP1]]
3636946970Szijunzhao //
test_ckd_sub()3736946970Szijunzhao bool test_ckd_sub() {
3836946970Szijunzhao   int result;
3936946970Szijunzhao   return ckd_sub(&result, -1073741826, 1073741826);
4036946970Szijunzhao }
4136946970Szijunzhao 
4236946970Szijunzhao // CHECK-LABEL: define dso_local zeroext i1 @test_ckd_mul(
4336946970Szijunzhao // CHECK-SAME: ) #[[ATTR0]] {
4436946970Szijunzhao // CHECK-NEXT:  entry:
4536946970Szijunzhao // CHECK-NEXT:    [[RESULT:%.*]] = alloca i32, align 4
4636946970Szijunzhao // CHECK-NEXT:    [[TMP0:%.*]] = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 -1073741826, i32 2)
4736946970Szijunzhao // CHECK-NEXT:    [[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1
4836946970Szijunzhao // CHECK-NEXT:    [[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0
4936946970Szijunzhao // CHECK-NEXT:    store i32 [[TMP2]], ptr [[RESULT]], align 4
5036946970Szijunzhao // CHECK-NEXT:    ret i1 [[TMP1]]
5136946970Szijunzhao //
test_ckd_mul()5236946970Szijunzhao bool test_ckd_mul() {
5336946970Szijunzhao   int result;
5436946970Szijunzhao   return ckd_mul(&result, -1073741826, 2);
5536946970Szijunzhao }
56