r260567 - [PR26550] Use a different TBAA root for C++ vs C.

Manman Ren via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 11 11:19:18 PST 2016


Author: mren
Date: Thu Feb 11 13:19:18 2016
New Revision: 260567

URL: http://llvm.org/viewvc/llvm-project?rev=260567&view=rev
Log:
[PR26550] Use a different TBAA root for C++ vs C.

This commit changes the root from "Simple C/C++ TBAA" to "Simple C++ TBAA" for
C++.

The problem is that the type name in the TBAA nodes is generated differently
for C vs C++. If we link an IR file for C with an IR file for C++, since they
have the same root and the type names are different, accesses to the two type
nodes will be considered no-alias, even though the two type nodes are from
the same type in a header file.

The fix is to use different roots for C and C++. Types from C will be treated
conservatively in respect to types from C++.

Follow-up commits will change the C root to "Simple C TBAA" plus some mangling
change for C types to make it a little more aggresive.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
    cfe/trunk/test/CodeGen/tbaa-class.cpp
    cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp
    cfe/trunk/test/CodeGen/tbaa.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=260567&r1=260566&r2=260567&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Thu Feb 11 13:19:18 2016
@@ -44,8 +44,12 @@ llvm::MDNode *CodeGenTBAA::getRoot() {
   // if our LLVM IR is linked with LLVM IR from a different front-end
   // (or a different version of this front-end), their TBAA trees will
   // remain distinct, and the optimizer will treat them conservatively.
-  if (!Root)
-    Root = MDHelper.createTBAARoot("Simple C/C++ TBAA");
+  if (!Root) {
+    if (Features.CPlusPlus)
+      Root = MDHelper.createTBAARoot("Simple C++ TBAA");
+    else
+      Root = MDHelper.createTBAARoot("Simple C/C++ TBAA");
+  }
 
   return Root;
 }

Modified: cfe/trunk/test/CodeGen/tbaa-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-class.cpp?rev=260567&r1=260566&r2=260567&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/tbaa-class.cpp (original)
+++ cfe/trunk/test/CodeGen/tbaa-class.cpp Thu Feb 11 13:19:18 2016
@@ -199,7 +199,7 @@ uint32_t g12(StructC *C, StructD *D, uin
 }
 
 // CHECK: [[TYPE_char:!.*]] = !{!"omnipotent char", [[TAG_cxx_tbaa:!.*]],
-// CHECK: [[TAG_cxx_tbaa]] = !{!"Simple C/C++ TBAA"}
+// CHECK: [[TAG_cxx_tbaa]] = !{!"Simple C++ TBAA"}
 // CHECK: [[TAG_i32]] = !{[[TYPE_i32:!.*]], [[TYPE_i32]], i64 0}
 // CHECK: [[TYPE_i32]] = !{!"int", [[TYPE_char]],
 // CHECK: [[TAG_i16]] = !{[[TYPE_i16:!.*]], [[TYPE_i16]], i64 0}

Modified: cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp?rev=260567&r1=260566&r2=260567&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp (original)
+++ cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp Thu Feb 11 13:19:18 2016
@@ -32,4 +32,4 @@ void CallFoo(A *a, int (A::*fp)() const)
 //
 // CHECK: [[NUM]] = !{[[TYPE:!.*]], [[TYPE]], i64 0}
 // CHECK: [[TYPE]] = !{!"vtable pointer", !{{.*}}
-// NOTBAA-NOT: = !{!"Simple C/C++ TBAA"}
+// NOTBAA-NOT: = !{!"Simple C++ TBAA"}

Modified: cfe/trunk/test/CodeGen/tbaa.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa.cpp?rev=260567&r1=260566&r2=260567&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/tbaa.cpp (original)
+++ cfe/trunk/test/CodeGen/tbaa.cpp Thu Feb 11 13:19:18 2016
@@ -237,7 +237,7 @@ uint32_t g15(StructS *S, StructS3 *S3, u
 }
 
 // CHECK: [[TYPE_char:!.*]] = !{!"omnipotent char", [[TAG_cxx_tbaa:!.*]],
-// CHECK: [[TAG_cxx_tbaa]] = !{!"Simple C/C++ TBAA"}
+// CHECK: [[TAG_cxx_tbaa]] = !{!"Simple C++ TBAA"}
 // CHECK: [[TAG_i32]] = !{[[TYPE_i32:!.*]], [[TYPE_i32]], i64 0}
 // CHECK: [[TYPE_i32]] = !{!"int", [[TYPE_char]],
 // CHECK: [[TAG_i16]] = !{[[TYPE_i16:!.*]], [[TYPE_i16]], i64 0}




More information about the cfe-commits mailing list