Skip to content

[GlobalOpt] Incorrect handling of memset in global ctor evaluation #55859

@nikic

Description

@nikic
@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [
  { i32, ptr, ptr } { i32 65535, ptr @ctor, ptr null }
]

@g = global { i32, i32 } { i32 0, i32 1 }

define internal void @ctor() {
  call void @llvm.memset.p0.i64(ptr @g, i8 0, i64 8, i1 false)
  ret void
}

declare void @llvm.memset.p0.i64(ptr, i8, i64, i1)

; RUN: opt -globalopt < %s

@llvm.global_ctors = appending global [0 x { i32, ptr, ptr }] zeroinitializer
@g = local_unnamed_addr global { i32, i32 } { i32 0, i32 1 }

The memset is removed, but the global is not zeroed. This is because

Constant *DestVal =
ComputeLoadResult(getVal(Ptr), MSI->getValue()->getType());
only checks whether the first byte is zero, not all bytes that are being set.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions