xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/may-alias.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -Werror -triple i386-unknown-unknown -emit-llvm -O1 -no-struct-path-tbaa -disable-llvm-optzns -o - %s | FileCheck %s
2f4a2713aSLionel Sambuc // RUN: %clang_cc1 -Werror -triple i386-unknown-unknown -emit-llvm -O1 -disable-llvm-optzns -o - %s | FileCheck %s -check-prefix=PATH
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc // Types with the may_alias attribute should be considered equivalent
5f4a2713aSLionel Sambuc // to char for aliasing.
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc typedef int __attribute__((may_alias)) aliasing_int;
8f4a2713aSLionel Sambuc 
test0(aliasing_int * ai,int * i)9f4a2713aSLionel Sambuc void test0(aliasing_int *ai, int *i)
10f4a2713aSLionel Sambuc {
11f4a2713aSLionel Sambuc // CHECK: store i32 0, i32* %{{.*}}, !tbaa [[TAG_CHAR:!.*]]
12f4a2713aSLionel Sambuc // PATH: store i32 0, i32* %{{.*}}, !tbaa [[TAG_CHAR:!.*]]
13f4a2713aSLionel Sambuc   *ai = 0;
14f4a2713aSLionel Sambuc // CHECK: store i32 1, i32* %{{.*}}, !tbaa [[TAG_INT:!.*]]
15f4a2713aSLionel Sambuc // PATH: store i32 1, i32* %{{.*}}, !tbaa [[TAG_INT:!.*]]
16f4a2713aSLionel Sambuc   *i = 1;
17f4a2713aSLionel Sambuc }
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc // PR9307
20f4a2713aSLionel Sambuc struct Test1 { int x; };
21f4a2713aSLionel Sambuc struct Test1MA { int x; } __attribute__((may_alias));
test1(struct Test1MA * p1,struct Test1 * p2)22f4a2713aSLionel Sambuc void test1(struct Test1MA *p1, struct Test1 *p2) {
23f4a2713aSLionel Sambuc   // CHECK: store i32 2, i32* {{%.*}}, !tbaa [[TAG_CHAR]]
24f4a2713aSLionel Sambuc   // PATH: store i32 2, i32* {{%.*}}, !tbaa [[TAG_CHAR]]
25f4a2713aSLionel Sambuc   p1->x = 2;
26f4a2713aSLionel Sambuc   // CHECK: store i32 3, i32* {{%.*}}, !tbaa [[TAG_INT]]
27f4a2713aSLionel Sambuc   // PATH: store i32 3, i32* {{%.*}}, !tbaa [[TAG_test1_x:!.*]]
28f4a2713aSLionel Sambuc   p2->x = 3;
29f4a2713aSLionel Sambuc }
30*0a6a1f1dSLionel Sambuc // CHECK:  !"any pointer", [[TYPE_CHAR:!.*]],
31*0a6a1f1dSLionel Sambuc // CHECK: [[TYPE_CHAR]] = !{!"omnipotent char", [[TAG_CXX_TBAA:!.*]],
32*0a6a1f1dSLionel Sambuc // CHECK: [[TAG_CXX_TBAA]] = !{!"Simple C/C++ TBAA"}
33*0a6a1f1dSLionel Sambuc // CHECK: [[TAG_CHAR]] = !{[[TYPE_CHAR]], [[TYPE_CHAR]], i64 0}
34*0a6a1f1dSLionel Sambuc // CHECK: [[TAG_INT]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
35*0a6a1f1dSLionel Sambuc // CHECK: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR]]
36f4a2713aSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc // PATH: [[TYPE_CHAR:!.*]] = !{!"omnipotent char", !{{.*}}
38*0a6a1f1dSLionel Sambuc // PATH: [[TAG_CHAR]] = !{[[TYPE_CHAR]], [[TYPE_CHAR]], i64 0}
39*0a6a1f1dSLionel Sambuc // PATH: [[TAG_INT]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
40*0a6a1f1dSLionel Sambuc // PATH: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR]]
41*0a6a1f1dSLionel Sambuc // PATH: [[TAG_test1_x]] = !{[[TYPE_test1:!.*]], [[TYPE_INT]], i64 0}
42*0a6a1f1dSLionel Sambuc // PATH: [[TYPE_test1]] = !{!"Test1", [[TYPE_INT]], i64 0}
43