89 lines · c
1// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 52// RUN: %clang_cc1 -std=c23 -Wno-error=odr -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s3 4// This tests the codegen behavior of redefined tag types to ensure the5// generated code looks reasonable.6 7enum E {8 One = 1,9 Zero = 0,10 Two = 211};12 13struct S {14 int x;15 int y;16};17 18struct S func(struct S s, enum E e);19 20struct S {21 int x, y;22} what();23 24// CHECK-LABEL: define dso_local i64 @func(25// CHECK-SAME: i64 [[S_COERCE:%.*]], i32 noundef [[E:%.*]]) #[[ATTR0:[0-9]+]] {26// CHECK-NEXT: [[ENTRY:.*:]]27// CHECK-NEXT: [[RETVAL:%.*]] = alloca [[STRUCT_S:%.*]], align 428// CHECK-NEXT: [[S:%.*]] = alloca [[STRUCT_S]], align 429// CHECK-NEXT: [[E_ADDR:%.*]] = alloca i32, align 430// CHECK-NEXT: store i64 [[S_COERCE]], ptr [[S]], align 431// CHECK-NEXT: store i32 [[E]], ptr [[E_ADDR]], align 432// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[E_ADDR]], align 433// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[S]], i32 0, i32 034// CHECK-NEXT: store i32 [[TMP0]], ptr [[X]], align 435// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[RETVAL]], ptr align 4 [[S]], i64 8, i1 false)36// CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[RETVAL]], align 437// CHECK-NEXT: ret i64 [[TMP1]]38//39struct S func(struct S s, enum E e) {40 s.x = (int)e;41 return s;42}43 44enum E {45 Zero,46 One,47 Two48};49 50// Ensure that ignoring the incompatibility due to attributes does not cause a51// crash. Note, this is undefined behavior in Clang until we implement52// attribute structural compatibility logic, so this is not intended to verify53// any particular behavior beyond "don't crash."54struct T {55 _Alignas(double) int x;56};57 58// CHECK-LABEL: define dso_local i32 @foo(59// CHECK-SAME: i32 [[T_COERCE:%.*]]) #[[ATTR0]] {60// CHECK-NEXT: [[ENTRY:.*:]]61// CHECK-NEXT: [[T:%.*]] = alloca [[STRUCT_T:%.*]], align 862// CHECK-NEXT: [[COERCE_DIVE:%.*]] = getelementptr inbounds nuw [[STRUCT_T]], ptr [[T]], i32 0, i32 063// CHECK-NEXT: store i32 [[T_COERCE]], ptr [[COERCE_DIVE]], align 864// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds nuw [[STRUCT_T]], ptr [[T]], i32 0, i32 065// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X]], align 866// CHECK-NEXT: ret i32 [[TMP0]]67//68int foo(struct T t) {69 return t.x;70}71 72struct T {73 int x;74};75 76// CHECK-LABEL: define dso_local i32 @bar(77// CHECK-SAME: i32 [[T_COERCE:%.*]]) #[[ATTR0]] {78// CHECK-NEXT: [[ENTRY:.*:]]79// CHECK-NEXT: [[T:%.*]] = alloca [[STRUCT_T:%.*]], align 880// CHECK-NEXT: [[COERCE_DIVE:%.*]] = getelementptr inbounds nuw [[STRUCT_T]], ptr [[T]], i32 0, i32 081// CHECK-NEXT: store i32 [[T_COERCE]], ptr [[COERCE_DIVE]], align 882// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds nuw [[STRUCT_T]], ptr [[T]], i32 0, i32 083// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X]], align 884// CHECK-NEXT: ret i32 [[TMP0]]85//86int bar(struct T t) {87 return t.x;88}89