kosarev updated this revision to Diff 116325. kosarev added a comment. Added a check for the initialization of the reference member in B::B(S&). (That in fact was my original intent; thanks for catching it.)
As to reference loads, we generate them with CodeGenFunction::EmitLoadOfReference() that, in contrast to CodeGenFunction::EmitLoadOfScalar(), is not TBAA-ready yet and looks to be a subject to a separate patch. So, what if we land https://reviews.llvm.org/D38126 first and then eventually re-consider the issue? Thanks again. https://reviews.llvm.org/D38074 Files: lib/CodeGen/CodeGenTBAA.cpp test/CodeGen/tbaa-reference.cpp Index: test/CodeGen/tbaa-reference.cpp =================================================================== --- test/CodeGen/tbaa-reference.cpp +++ test/CodeGen/tbaa-reference.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s +// +// Check that we generate correct TBAA information for reference accesses. + +struct S; + +struct B { + S &s; + B(S &s) : s(s) {} + void bar(); +}; + +void foo(S &s) { + B b(s); + b.bar(); +} + +// CHECK-LABEL: _Z3fooR1S +// Check initialization of the reference parameter in foo(). +// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer:!.*]] +// +// CHECK-LABEL: _ZN1BC2ER1S +// TODO: Check initialization of the parameter s in B::B(S&). +// Check initialization of B::s in B::B(S&). +// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]] +// +// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0} +// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0} +// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0} Index: lib/CodeGen/CodeGenTBAA.cpp =================================================================== --- lib/CodeGen/CodeGenTBAA.cpp +++ lib/CodeGen/CodeGenTBAA.cpp @@ -145,10 +145,10 @@ if (Ty->isStdByteType()) return MetadataCache[Ty] = getChar(); - // Handle pointers. + // Handle pointers and references. // TODO: Implement C++'s type "similarity" and consider dis-"similar" // pointers distinct. - if (Ty->isPointerType()) + if (Ty->isPointerType() || Ty->isReferenceType()) return MetadataCache[Ty] = createTBAAScalarType("any pointer", getChar());
Index: test/CodeGen/tbaa-reference.cpp =================================================================== --- test/CodeGen/tbaa-reference.cpp +++ test/CodeGen/tbaa-reference.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s +// +// Check that we generate correct TBAA information for reference accesses. + +struct S; + +struct B { + S &s; + B(S &s) : s(s) {} + void bar(); +}; + +void foo(S &s) { + B b(s); + b.bar(); +} + +// CHECK-LABEL: _Z3fooR1S +// Check initialization of the reference parameter in foo(). +// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer:!.*]] +// +// CHECK-LABEL: _ZN1BC2ER1S +// TODO: Check initialization of the parameter s in B::B(S&). +// Check initialization of B::s in B::B(S&). +// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]] +// +// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0} +// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0} +// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0} Index: lib/CodeGen/CodeGenTBAA.cpp =================================================================== --- lib/CodeGen/CodeGenTBAA.cpp +++ lib/CodeGen/CodeGenTBAA.cpp @@ -145,10 +145,10 @@ if (Ty->isStdByteType()) return MetadataCache[Ty] = getChar(); - // Handle pointers. + // Handle pointers and references. // TODO: Implement C++'s type "similarity" and consider dis-"similar" // pointers distinct. - if (Ty->isPointerType()) + if (Ty->isPointerType() || Ty->isReferenceType()) return MetadataCache[Ty] = createTBAAScalarType("any pointer", getChar());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits