[llvm] [ThinLTO] Don't mark calloc function dead (PR #72673)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 22 14:00:01 PST 2023


================
@@ -0,0 +1,20 @@
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at _ZZ6mallocE3buf = internal global [2000 x i8] zeroinitializer, align 1
+
+define hidden ptr @malloc(i64 %a) {
+entry:
+  ret ptr @_ZZ6mallocE3buf
+}
+
+define hidden ptr @calloc(i64 noundef %num, i64 noundef %size) {
+entry:
+  %mul = mul i64 %size, %num
+  %call = tail call noalias ptr @malloc(i64 poison)
+  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 @_ZZ6mallocE3buf, i8 0, i64 %mul, i1 false)
----------------
MaskRay wrote:

Call memset on `%call` and return `%call`, to make the stub implementation more authentic.

https://github.com/llvm/llvm-project/pull/72673


More information about the llvm-commits mailing list