[PATCH] D65314: CodeGen: Don't follow aliases when extracting type info.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 19:03:18 PDT 2019


pcc created this revision.
pcc added reviewers: hfinkel, tejohnson.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

This fixes a crash in the case where the type info object is an alias
pointing to a non-zero offset within a global or is otherwise unanalyzable
by the stripPointerCasts() function. Looking through the alias is not the
right thing to do anyway for similar reasons as D65118 <https://reviews.llvm.org/D65118>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65314

Files:
  llvm/lib/CodeGen/Analysis.cpp
  llvm/test/CodeGen/X86/typeid-alias.ll


Index: llvm/test/CodeGen/X86/typeid-alias.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/typeid-alias.ll
@@ -0,0 +1,14 @@
+; RUN: llc < %s
+
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.exception = type { i8, i8, i32, i8*, i8*, i32, i8* }
+ at g = global %struct.exception zeroinitializer
+ at a = alias %struct.exception, %struct.exception* inttoptr (i64 add (i64 ptrtoint (%struct.exception* @g to i64), i64 1297036692682702848) to %struct.exception*)
+
+define i32 @typeid() {
+  %eh_typeid = tail call i32 @llvm.eh.typeid.for( i8* getelementptr (%struct.exception, %struct.exception* @a, i32 0, i32 0))
+  ret i32 %eh_typeid
+}
+
+declare i32 @llvm.eh.typeid.for(i8*)
Index: llvm/lib/CodeGen/Analysis.cpp
===================================================================
--- llvm/lib/CodeGen/Analysis.cpp
+++ llvm/lib/CodeGen/Analysis.cpp
@@ -156,7 +156,7 @@
 
 /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
 GlobalValue *llvm::ExtractTypeInfo(Value *V) {
-  V = V->stripPointerCasts();
+  V = V->stripPointerCastsNoFollowAliases();
   GlobalValue *GV = dyn_cast<GlobalValue>(V);
   GlobalVariable *Var = dyn_cast<GlobalVariable>(V);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65314.211868.patch
Type: text/x-patch
Size: 1241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190726/6f42de15/attachment.bin>


More information about the llvm-commits mailing list