brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · ab659d6 Raw
107 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c2x -verify -emit-llvm %s -o - | FileCheck %s2// expected-no-diagnostics3 4struct S { int x, y; };5struct T {6  int i;7  struct S s;8};9 10// CHECK: @[[CONST_T1:.+]] = private unnamed_addr constant %struct.T { i32 1, %struct.S zeroinitializer }11// CHECK: @[[CONST_T2:.+]] = private unnamed_addr constant %struct.T { i32 1, %struct.S { i32 2, i32 0 } }12 13void test_struct() {14  struct S s = {};15  // CHECK: define {{.*}} void @test_struct16  // CHECK-NEXT: entry:17  // CHECK-NEXT: %[[S:.+]] = alloca %struct.S18  // CHECK-NEXT: call void @llvm.memset.p0.i64({{.*}}%[[S]], i8 0, i64 8, i1 false)19}20 21void test_var() {22  int i = {};23  // CHECK: define {{.*}} void @test_var24  // CHECK-NEXT: entry:25  // CHECK-NEXT: %[[I:.+]] = alloca i3226  // CHECK-NEXT: store i32 0, ptr %[[I]]27}28 29void test_simple_compound_literal() {30  int j = (int){};31  // CHECK: define {{.*}} void @test_simple_compound_literal32  // CHECK-NEXT: entry:33  // CHECK-NEXT: %[[J:.+]] = alloca i3234  // CHECK-NEXT: %[[COMPOUND:.+]] = alloca i3235  // CHECK-NEXT: store i32 0, ptr %[[COMPOUND]]36  // CHECK-NEXT: %[[MEM:.+]] = load i32, ptr %[[COMPOUND]]37  // CHECK-NEXT: store i32 %[[MEM]], ptr %[[J]]38}39 40void test_zero_size_array() {41  int unknown_size[] = {};42  // CHECK: define {{.*}} void @test_zero_size_array43  // CHECK-NEXT: entry:44  // CHECK-NEXT: %[[UNKNOWN:.+]] = alloca [0 x i32]45}46 47void test_vla() {48  int num_elts = 12;49  int vla[num_elts] = {};50  // CHECK: define {{.*}} void @test_vla51  // CHECK-NEXT: entry:52  // CHECK-NEXT: %[[NUM_ELTS_PTR:.+]] = alloca i3253  // CHECK: %[[VLA_EXPR:.+]] = alloca i6454  // CHECK-NEXT: store i32 12, ptr %[[NUM_ELTS_PTR]]55  // CHECK-NEXT: %[[NUM_ELTS:.+]] = load i32, ptr %[[NUM_ELTS_PTR]]56  // CHECK-NEXT: %[[NUM_ELTS_EXT:.+]] = zext i32 %[[NUM_ELTS]] to i6457  // CHECK: %[[VLA:.+]] = alloca i32, i64 %[[NUM_ELTS_EXT]]58  // CHECK-NEXT: store i64 %[[NUM_ELTS_EXT]], ptr %[[VLA_EXPR]]59  // CHECK-NEXT: %[[BYTES_TO_COPY:.+]] = mul nuw i64 %[[NUM_ELTS_EXT]], 460  // CHECK-NEXT: call void @llvm.memset.p0.i64(ptr {{.*}} %[[VLA]], i8 0, i64 %[[BYTES_TO_COPY]], i1 false)61}62 63void test_zero_size_vla() {64  int num_elts = 0;65  int vla[num_elts] = {};66  // CHECK: define {{.*}} void @test_zero_size_vla67  // CHECK-NEXT: entry:68  // CHECK-NEXT: %[[NUM_ELTS_PTR:.+]] = alloca i3269  // CHECK: %[[VLA_EXPR:.+]] = alloca i6470  // CHECK-NEXT: store i32 0, ptr %[[NUM_ELTS_PTR]]71  // CHECK-NEXT: %[[NUM_ELTS:.+]] = load i32, ptr %[[NUM_ELTS_PTR]]72  // CHECK-NEXT: %[[NUM_ELTS_EXT:.+]] = zext i32 %[[NUM_ELTS]] to i6473  // CHECK: %[[VLA:.+]] = alloca i32, i64 %[[NUM_ELTS_EXT]]74  // CHECK-NEXT: store i64 %[[NUM_ELTS_EXT]], ptr %[[VLA_EXPR]]75  // CHECK-NEXT: %[[BYTES_TO_COPY:.+]] = mul nuw i64 %[[NUM_ELTS_EXT]], 476  // CHECK-NEXT: call void @llvm.memset.p0.i64(ptr {{.*}} %[[VLA]], i8 0, i64 %[[BYTES_TO_COPY]], i1 false)77}78 79void test_nested_structs() {80  struct T t1 = { 1, {} };81  struct T t2 = { 1, { 2, {} } };82  struct T t3 = { (int){}, {} };83  // CHECK: define {{.*}} void @test_nested_structs84  // CHECK-NEXT: entry:85  // CHECK-NEXT: %[[T1:.+]] = alloca %struct.T86  // CHECK-NEXT: %[[T2:.+]] = alloca %struct.T87  // CHECK-NEXT: %[[T3:.+]] = alloca %struct.T88  // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr {{.*}} %[[T1]], ptr {{.*}} @[[CONST_T1]], i64 12, i1 false)89  // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr {{.*}} %[[T2]], ptr {{.*}} @[[CONST_T2]], i64 12, i1 false)90  // CHECK-NEXT: call void @llvm.memset.p0.i64(ptr {{.*}} %[[T3]], i8 0, i64 12, i1 false)91}92 93void test_vla_of_nested_structs(int num_elts) {94  struct T t3[num_elts] = {};95  // CHECK: define {{.*}} void @test_vla_of_nested_structs(i32 noundef %[[NUM_ELTS_PARAM:.+]])96  // CHECK-NEXT: entry:97  // CHECK-NEXT: %[[NUM_ELTS_PTR:.+]] = alloca i3298  // CHECK: %[[VLA_EXPR:.+]] = alloca i6499  // CHECK-NEXT: store i32 %[[NUM_ELTS_PARAM]], ptr %[[NUM_ELTS_PTR]]100  // CHECK-NEXT: %[[NUM_ELTS_LOCAL:.+]] = load i32, ptr %[[NUM_ELTS_PTR]]101  // CHECK-NEXT: %[[NUM_ELTS_EXT:.+]] = zext i32 %[[NUM_ELTS_LOCAL]] to i64102  // CHECK: %[[VLA:.+]] = alloca %struct.T, i64 %[[NUM_ELTS_EXT]]103  // CHECK-NEXT: store i64 %[[NUM_ELTS_EXT]], ptr %[[VLA_EXPR]]104  // CHECK-NEXT: %[[COPY_BYTES:.+]] = mul nuw i64 %[[NUM_ELTS_EXT]], 12105  // CHECK-NEXT: call void @llvm.memset.p0.i64(ptr {{.*}} %[[VLA]], i8 0, i64 %[[COPY_BYTES]], i1 false)106}107