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

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 27 06:52:27 PST 2023


================
@@ -0,0 +1,50 @@
+; 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 -r=%t1.bc,_ZnwmRKSt9nothrow_t,px \
+; RUN:          -r=%t1.bc,_ZSt7nothrow -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
+
+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"
+
+%"struct.std::nothrow_t" = type { i8 }
+
+ at _ZSt7nothrow = external global %"struct.std::nothrow_t", align 1
+
+declare ptr @malloc(i64)
+
+ at __p = dso_local local_unnamed_addr global ptr null, align 8
+
+define ptr @_ZnwmRKSt9nothrow_t(i64 %size, ptr %0) {
----------------
teresajohnson wrote:

Following up from an earlier comment - is this separate function needed - can the test be simplified by just having DoStuff call malloc followed by memset? It would be nice to have the test as simple as possible for testing the specific issue.

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


More information about the llvm-commits mailing list