]> granicus.if.org Git - clang/commitdiff
Don't use mangleCXXRTTIName in TBAA for C code.
authorManman Ren <manman.ren@gmail.com>
Wed, 21 Aug 2013 20:58:45 +0000 (20:58 +0000)
committerManman Ren <manman.ren@gmail.com>
Wed, 21 Aug 2013 20:58:45 +0000 (20:58 +0000)
With r185721, calling mangleCXXRTTIName on C code will cause crashes.
This commit fixes crashes on C testing cases when turning on struct-path TBAA.

For C code, we simply use the Decl name without the context. This can
cause two different structs having the same name, and may cause inaccurate but
conservative alias results.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188930 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenTBAA.cpp
test/CodeGen/bitfield.c
test/CodeGen/may-alias.c

index 0a8c293cb70cd103458083df7f73a939644582d4..f104c2f2f575f10269e101fe1a3f5cf565314630 100644 (file)
@@ -277,9 +277,14 @@ CodeGenTBAA::getTBAAStructTypeInfo(QualType QTy) {
     // TODO: This is using the RTTI name. Is there a better way to get
     // a unique string for a type?
     SmallString<256> OutName;
-    llvm::raw_svector_ostream Out(OutName);
-    MContext.mangleCXXRTTIName(QualType(Ty, 0), Out);
-    Out.flush();
+    if (Features.CPlusPlus) {
+      // Don't use mangleCXXRTTIName for C code.
+      llvm::raw_svector_ostream Out(OutName);
+      MContext.mangleCXXRTTIName(QualType(Ty, 0), Out);
+      Out.flush();
+    } else {
+      OutName = RD->getName();
+    }
     // Create the struct type node with a vector of pairs (offset, type).
     return StructTypeMetadataCache[Ty] =
       MDHelper.createTBAAStructTypeNode(OutName, Fields);
index 03748a067b15fc973eda5d5f0c1272f109f29a9b..41befe7c176623ab408611f998e37e52eef2efae 100644 (file)
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - -O3 | FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - -O3 -struct-path-tbaa | FileCheck %s --check-prefix=PATH
 
 static int f0(int n) {
   struct s0 {
@@ -17,6 +18,8 @@ static int f0(int n) {
 int g0(void) {
 // CHECK-LABEL: @g0()
 // CHECK: ret i32 1
+// PATH-LABEL: @g0()
+// PATH: ret i32 1
   return f0(-1) + 44335655;
 }
 
@@ -37,6 +40,8 @@ static int f1(void) {
 int g1(void) {
 // CHECK-LABEL: @g1()
 // CHECK: ret i32 1
+// PATH-LABEL: @g1()
+// PATH: ret i32 1
   return f1() + 16;
 }
 
@@ -55,6 +60,8 @@ static int f2(void) {
 int g2(void) {
 // CHECK-LABEL: @g2()
 // CHECK: ret i32 1
+// PATH-LABEL: @g2()
+// PATH: ret i32 1
   return f2() - 9;
 }
 
@@ -76,5 +83,7 @@ static int f3(int n) {
 int g3(void) {
 // CHECK-LABEL: @g3()
 // CHECK: ret i32 1
+// PATH-LABEL: @g3()
+// PATH: ret i32 1
   return f3(20) + 130725747;
 }
index 10339a57d30407c215be3c07d1eca0e00514b00a..8b30c608516fe02ce3a7a990f32d43011d6ecd5e 100644 (file)
@@ -37,4 +37,4 @@ void test1(struct Test1MA *p1, struct Test1 *p2) {
 // PATH: [[TAG_INT]] = metadata !{metadata [[TYPE_INT:!.*]], metadata [[TYPE_INT]], i64 0}
 // PATH: [[TYPE_INT]] = metadata !{metadata !"int", metadata [[TYPE_CHAR]]
 // PATH: [[TAG_test1_x]] = metadata !{metadata [[TYPE_test1:!.*]], metadata [[TYPE_INT]], i64 0}
-// PATH: [[TYPE_test1]] = metadata !{metadata !"_ZTS5Test1", metadata [[TYPE_INT]], i64 0}
+// PATH: [[TYPE_test1]] = metadata !{metadata !"Test1", metadata [[TYPE_INT]], i64 0}