59 lines · cpp
1// RUN: %clang_cc1 -std=c++17 -triple x86_64-pc-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s3// RUN: %clang_cc1 -std=c++17 -triple x86_64-pc-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s5// RUN: %clang_cc1 -std=c++17 -triple x86_64-pc-linux-gnu -emit-llvm %s -o %t.ll6// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s7 8struct some_struct {9 int a;10 float b;11};12 13float function() {14 auto[a, b] = some_struct{1, 2.f};15 16 return a + b;17}18 19// CIR-LABEL: cir.func dso_local @_Z8functionv() -> !cir.float20// CIR: %[[RETVAL:.+]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["__retval"]21// CIR: %[[STRUCT:.+]] = cir.alloca !rec_some_struct, !cir.ptr<!rec_some_struct>, ["", init]22// CIR: %[[CONST:.+]] = cir.const #cir.const_record<{#cir.int<1> : !s32i, #cir.fp<2.000000e+00> : !cir.float}> : !rec_some_struct23// CIR: cir.store{{.*}} %[[CONST]], %[[STRUCT]]24// CIR: %[[MEMBER_A:.+]] = cir.get_member %[[STRUCT]][0] {name = "a"} : !cir.ptr<!rec_some_struct> -> !cir.ptr<!s32i>25// CIR: %[[LOAD_A:.+]] = cir.load align(4) %[[MEMBER_A]] : !cir.ptr<!s32i>, !s32i26// CIR: %[[CAST_A:.+]] = cir.cast int_to_float %[[LOAD_A]] : !s32i -> !cir.float27// CIR: %[[MEMBER_B:.+]] = cir.get_member %[[STRUCT]][1] {name = "b"} : !cir.ptr<!rec_some_struct> -> !cir.ptr<!cir.float>28// CIR: %[[LOAD_B:.+]] = cir.load align(4) %[[MEMBER_B]] : !cir.ptr<!cir.float>, !cir.float29// CIR: %[[ADD:.+]] = cir.binop(add, %[[CAST_A]], %[[LOAD_B]]) : !cir.float30// CIR: cir.store %[[ADD]], %[[RETVAL]] : !cir.float, !cir.ptr<!cir.float>31// CIR: %[[RET:.+]] = cir.load %[[RETVAL]] : !cir.ptr<!cir.float>, !cir.float32// CIR: cir.return %[[RET]] : !cir.float33 34// LLVM-LABEL: define dso_local float @_Z8functionv()35// LLVM: %[[RETVAL:.+]] = alloca float, i64 136// LLVM: %[[STRUCT:.+]] = alloca %struct.some_struct, i64 137// LLVM: store %struct.some_struct { i32 1, float 2.000000e+00 }, ptr %[[STRUCT]]38// LLVM: %[[GEP_A:.+]] = getelementptr %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 039// LLVM: %[[LOAD_A:.+]] = load i32, ptr %[[GEP_A]]40// LLVM: %[[CAST_A:.+]] = sitofp i32 %[[LOAD_A]] to float41// LLVM: %[[GEP_B:.+]] = getelementptr %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 142// LLVM: %[[LOAD_B:.+]] = load float, ptr %[[GEP_B]]43// LLVM: %[[ADD:.+]] = fadd float %[[CAST_A]], %[[LOAD_B]]44// LLVM: store float %[[ADD]], ptr %[[RETVAL]]45// LLVM: %[[RET:.+]] = load float, ptr %[[RETVAL]]46// LLVM: ret float %[[RET]]47 48// OGCG: @__const._Z8functionv.{{.*}} = private unnamed_addr constant %struct.some_struct { i32 1, float 2.000000e+00 }49// OGCG-LABEL: define dso_local noundef float @_Z8functionv()50// OGCG: %[[STRUCT:.+]] = alloca %struct.some_struct51// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[STRUCT]], ptr align 4 @__const._Z8functionv.{{.*}}, i64 8, i1 false)52// OGCG: %[[GEP_A:.+]] = getelementptr inbounds nuw %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 053// OGCG: %[[LOAD_A:.+]] = load i32, ptr %[[GEP_A]]54// OGCG: %[[CAST_A:.+]] = sitofp i32 %[[LOAD_A]] to float55// OGCG: %[[GEP_B:.+]] = getelementptr inbounds nuw %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 156// OGCG: %[[LOAD_B:.+]] = load float, ptr %[[GEP_B]]57// OGCG: %[[ADD:.+]] = fadd float %[[CAST_A]], %[[LOAD_B]]58// OGCG: ret float %[[ADD]]59