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

Steven Wu via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 28 11:55:31 PST 2023


================
@@ -0,0 +1,39 @@
+; REQUIRES: x86-registered-target
+; Checks that calloc function is not stripped by LTO DCE, otherwise
+; we may get into trouble during final link in case DSEPass folds
+; subsequent calls to malloc/memset into a single call to calloc.
+; Also see builtin-notstrip.ll which is similar to this test.
+
+; RUN: opt -module-summary %s -o %t1.bc
+; RUN: opt -module-summary %p/Inputs/calloc.ll -o %t2.bc
+; RUN: llvm-lto2 run -save-temps -o %t.out \
+; RUN:   %t1.bc -r=%t1.bc,_Z7DoStuffv,px \
+; RUN:          -r=%t1.bc,malloc,l -r=%t1.bc,__p,px \
+; RUN:   %t2.bc -r=%t2.bc,malloc,pl -r=%t2.bc,calloc,pl
+; RUN: llvm-dis %t.out.2.5.precodegen.bc -o - | FileCheck %s --check-prefix=CALLOC-DEF
+; RUN: llvm-dis %t.out.1.5.precodegen.bc -o - | FileCheck %s --check-prefix=CALLOC-USE
+
+; CALLOC-DEF: define {{.*}} @malloc
+; CALLOC-DEF: define {{.*}} @calloc
+
+; CALLOC-USE:      define void @_Z7DoStuffv()
+; CALLOC-USE-NEXT: entry:
+; CALLOC-USE-NEXT:   tail call {{.*}} ptr @calloc
----------------
cachemeifyoucan wrote:

I might even remove the use for `calloc` here since you just want to test that `calloc` is dead-stripped, and don't want to test that `calloc` optimization is happening. `calloc` should be preserved with or without optimization is happening or not.

That said, maybe just merge this test into `builtin-nostrip.ll`

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


More information about the llvm-commits mailing list