xref: /llvm-project/clang/test/CodeGen/constantexpr-fneg.c (revision 63dc31b68b78bc0e5deef21b98cab72de997c471)
1 // RUN: %clang_cc1 -emit-llvm-bc -disable-llvm-passes -o %t.bc %s
2 // RUN: llvm-dis %t.bc -o - | FileCheck %s
3 
4 // Test case for PR45426. Make sure we do not crash while writing bitcode
5 // containing a simplify-able fneg constant expression.
6 //
7 // CHECK-LABEL define i32 @main()
8 // CHECK:      entry:
9 // CHECK-NEXT:   %retval = alloca i32
10 // CHECK-NEXT:   store i32 0, ptr %retval
11 // CHECK-NEXT:   [[CMP:%.*]] = icmp ne ptr @b, @a
12 // CHECK-NEXT:   [[ZEXT:%.*]] = zext i1 [[CMP]] to i32
13 // CHECK-NEXT:   [[SITOFP:%.*]] = sitofp i32 [[ZEXT]] to float
14 // CHECK-NEXT:   [[LV:%.*]] = load ptr, ptr @c
15 // CHECK-NEXT:   store float [[SITOFP]], ptr [[LV]], align 4
16 // CHECK-NEXT:   [[FNEG:%.*]] = fneg float [[SITOFP]]
17 // CHECK-NEXT:   [[CONV:%.*]] = fptosi float [[FNEG]] to i32
18 // CHECK-NEXT:   ret i32 [[CONV]]
19 
20 int a[], b;
21 float *c;
main(void)22 int main(void) {
23   return -(*c = &b != a);
24 }
25