Debian Codegraph @

clang/test/CodeGen/attr-counted-by-pr88931.c

raw
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4
2 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -Wno-missing-declarations -emit-llvm -o - %s | FileCheck %s
3
4 struct foo {
5 int x,y,z;
6 struct bar {
7 int count;
8 int array[] __attribute__((counted_by(count)));
9 };
10 };
11
12 void init(void * __attribute__((pass_dynamic_object_size(0))));
13
14 // CHECK-LABEL: define dso_local void @test1(
15 // CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
16 // CHECK-NEXT: entry:
17 // CHECK-NEXT: [[ARRAY:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 4
18 // CHECK-NEXT: [[COUNTED_BY_LOAD:%.*]] = load i32, ptr [[P]], align 4
19 // CHECK-NEXT: [[COUNT:%.*]] = sext i32 [[COUNTED_BY_LOAD]] to i64
20 // CHECK-NEXT: [[FLEXIBLE_ARRAY_MEMBER_SIZE:%.*]] = shl nsw i64 [[COUNT]], 2
21 // CHECK-NEXT: [[TMP0:%.*]] = icmp sgt i32 [[COUNTED_BY_LOAD]], -1
22 // CHECK-NEXT: [[TMP1:%.*]] = select i1 [[TMP0]], i64 [[FLEXIBLE_ARRAY_MEMBER_SIZE]], i64 0
23 // CHECK-NEXT: tail call void @init(ptr noundef nonnull [[ARRAY]], i64 noundef [[TMP1]]) #[[ATTR2:[0-9]+]]
24 // CHECK-NEXT: ret void
25 //
26 void test1(struct bar *p) {
27 init(p->array);
28 }
29
30 struct mux {
31 int count;
32 int array[] __attribute__((counted_by(count)));
33 };
34
35 struct bux { struct mux x; };
36
37 // CHECK-LABEL: define dso_local void @test2(
38 // CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0]] {
39 // CHECK-NEXT: entry:
40 // CHECK-NEXT: tail call void @init(ptr noundef [[P]], i64 noundef -1) #[[ATTR2]]
41 // CHECK-NEXT: ret void
42 //
43 void test2(struct bux *p) {
44 init(p);
45 }