Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / C / C2x / n2683_2.c
blob247f6de8fe4bfe1efb9d67d78ba61812ad0f01b9
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
2 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
4 #include <stdckdint.h>
5 #include <stdint.h>
7 // CHECK-LABEL: define dso_local void @test_add_overflow_to64(
8 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
9 // CHECK-NEXT: entry:
10 // CHECK-NEXT: [[RESULT64:%.*]] = alloca i64, align 8
11 // CHECK-NEXT: [[FLAG_ADD:%.*]] = alloca i8, align 1
12 // CHECK-NEXT: store i64 0, ptr [[RESULT64]], align 8
13 // CHECK-NEXT: [[TMP0:%.*]] = call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 2147483647, i64 1)
14 // CHECK-NEXT: [[TMP1:%.*]] = extractvalue { i64, i1 } [[TMP0]], 1
15 // CHECK-NEXT: [[TMP2:%.*]] = extractvalue { i64, i1 } [[TMP0]], 0
16 // CHECK-NEXT: store i64 [[TMP2]], ptr [[RESULT64]], align 8
17 // CHECK-NEXT: [[FROMBOOL:%.*]] = zext i1 [[TMP1]] to i8
18 // CHECK-NEXT: store i8 [[FROMBOOL]], ptr [[FLAG_ADD]], align 1
19 // CHECK-NEXT: ret void
21 void test_add_overflow_to64() {
22 int64_t result64 = 0;
23 bool flag_add = ckd_add(&result64, INT32_MAX, 1);
26 // CHECK-LABEL: define dso_local void @test_sub_overflow(
27 // CHECK-SAME: ) #[[ATTR0]] {
28 // CHECK-NEXT: entry:
29 // CHECK-NEXT: [[RESULT32:%.*]] = alloca i32, align 4
30 // CHECK-NEXT: [[FLAG_SUB:%.*]] = alloca i8, align 1
31 // CHECK-NEXT: store i32 0, ptr [[RESULT32]], align 4
32 // CHECK-NEXT: [[TMP0:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 2147483647, i32 -1)
33 // CHECK-NEXT: [[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1
34 // CHECK-NEXT: [[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0
35 // CHECK-NEXT: store i32 [[TMP2]], ptr [[RESULT32]], align 4
36 // CHECK-NEXT: [[FROMBOOL:%.*]] = zext i1 [[TMP1]] to i8
37 // CHECK-NEXT: store i8 [[FROMBOOL]], ptr [[FLAG_SUB]], align 1
38 // CHECK-NEXT: ret void
40 void test_sub_overflow() {
41 int32_t result32 = 0;
42 bool flag_sub = ckd_sub(&result32, INT32_MAX, -1);
45 // CHECK-LABEL: define dso_local void @test_mul_normal(
46 // CHECK-SAME: ) #[[ATTR0]] {
47 // CHECK-NEXT: entry:
48 // CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
49 // CHECK-NEXT: [[RESULT:%.*]] = alloca i32, align 4
50 // CHECK-NEXT: [[FLAG_MUL:%.*]] = alloca i8, align 1
51 // CHECK-NEXT: store i32 3, ptr [[A]], align 4
52 // CHECK-NEXT: store i32 0, ptr [[RESULT]], align 4
53 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[A]], align 4
54 // CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 [[TMP0]], i32 2)
55 // CHECK-NEXT: [[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP1]], 1
56 // CHECK-NEXT: [[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP1]], 0
57 // CHECK-NEXT: store i32 [[TMP3]], ptr [[RESULT]], align 4
58 // CHECK-NEXT: [[FROMBOOL:%.*]] = zext i1 [[TMP2]] to i8
59 // CHECK-NEXT: store i8 [[FROMBOOL]], ptr [[FLAG_MUL]], align 1
60 // CHECK-NEXT: ret void
62 void test_mul_normal() {
63 int a = 3;
64 int result = 0;
65 bool flag_mul = ckd_mul(&result, a, 2);