Skip to content

Conversation

clubby789
Copy link
Contributor

cc #138299

rustc sets allockind("uninitialized") - if we copy the attributes as-is when creating a dummy function, Verify complains about allockind("uninitialized,zeroed") conflicting, so we need to clear the flag.

@clubby789 clubby789 changed the title Remove uninitialized from allockind when creating dummy zeroed variant function [DSE] Remove uninitialized from allockind when creating dummy zeroed variant function Jul 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 17, 2025

@llvm/pr-subscribers-llvm-transforms

Author: None (clubby789)

Changes

cc #138299

rustc sets allockind("uninitialized") - if we copy the attributes as-is when creating a dummy function, Verify complains about allockind("uninitialized,zeroed") conflicting, so we need to clear the flag.


Full diff: https://github.com/llvm/llvm-project/pull/149336.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp (+1)
  • (modified) llvm/test/Transforms/DeadStoreElimination/zeroed-missing.ll (+1-1)
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 85dd9a1bf7161..0f63ed0166cf4 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -2079,6 +2079,7 @@ struct DSEState {
       AllocFnKind AllocKind =
           Attrs.getFnAttr(Attribute::AllocKind).getAllocKind() |
           AllocFnKind::Zeroed;
+      AllocKind &= ~AllocFnKind::Uninitialized;
       Attrs =
           Attrs.addFnAttribute(Ctx, Attribute::getWithAllocKind(Ctx, AllocKind))
               .removeFnAttribute(Ctx, "alloc-variant-zeroed");
diff --git a/llvm/test/Transforms/DeadStoreElimination/zeroed-missing.ll b/llvm/test/Transforms/DeadStoreElimination/zeroed-missing.ll
index e390d4bdca632..303afc207c023 100644
--- a/llvm/test/Transforms/DeadStoreElimination/zeroed-missing.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/zeroed-missing.ll
@@ -12,6 +12,6 @@ define ptr @undeclared_customalloc(i64 %size, i64 %align) {
   ret ptr %call
 }
 
-declare ptr @customalloc2(i64, i64) allockind("alloc") "alloc-family"="customalloc2" "alloc-variant-zeroed"="customalloc2_zeroed"
+declare ptr @customalloc2(i64, i64) allockind("alloc,uninitialized") "alloc-family"="customalloc2" "alloc-variant-zeroed"="customalloc2_zeroed"
 ; CHECK-DAG: declare ptr @customalloc2_zeroed(i64, i64) #[[CA2ATTR:[0-9]+]]
 ; CHECK-DAG: attributes #[[CA2ATTR]] = { allockind("alloc,zeroed") "alloc-family"="customalloc2" }

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nikic nikic merged commit 74c396a into llvm:main Jul 18, 2025
11 checks passed
@nikic nikic added this to the LLVM 21.x Release milestone Jul 18, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Jul 18, 2025
@nikic
Copy link
Contributor

nikic commented Jul 18, 2025

/cherry-pick 74c396a

@llvmbot
Copy link
Member

llvmbot commented Jul 18, 2025

/pull-request #149468

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Jul 18, 2025
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 22, 2025
…oed variant function (llvm#149336)

cc llvm#138299

rustc sets `allockind("uninitialized")` - if we copy the attributes
as-is when creating a dummy function, Verify complains about
`allockind("uninitialized,zeroed")` conflicting, so we need to clear the
flag.

Co-authored-by: Jamie Hill-Daniel <jamie@osec.io>
(cherry picked from commit 74c396a)
bors added a commit to rust-lang/rust that referenced this pull request Aug 19, 2025
Pass `alloc-variant-zeroed` to LLVM

Makes use of llvm/llvm-project#138299 (once we pull in a version of LLVM with this attribute). ~~Unfortunately also requires llvm/llvm-project#149336 to work.~~

Closes #104847
bors added a commit to rust-lang/rust that referenced this pull request Aug 20, 2025
Pass `alloc-variant-zeroed` to LLVM

Makes use of llvm/llvm-project#138299 (once we pull in a version of LLVM with this attribute). ~~Unfortunately also requires llvm/llvm-project#149336 to work.~~

Closes #104847
bors added a commit to rust-lang/rust that referenced this pull request Aug 20, 2025
Pass `alloc-variant-zeroed` to LLVM

Makes use of llvm/llvm-project#138299 (once we pull in a version of LLVM with this attribute). ~~Unfortunately also requires llvm/llvm-project#149336 to work.~~

Closes #104847
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Aug 21, 2025
Pass `alloc-variant-zeroed` to LLVM

Makes use of llvm/llvm-project#138299 (once we pull in a version of LLVM with this attribute). ~~Unfortunately also requires llvm/llvm-project#149336 to work.~~

Closes rust-lang/rust#104847
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Aug 25, 2025
Pass `alloc-variant-zeroed` to LLVM

Makes use of llvm/llvm-project#138299 (once we pull in a version of LLVM with this attribute). ~~Unfortunately also requires llvm/llvm-project#149336 to work.~~

Closes rust-lang/rust#104847
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Aug 26, 2025
Pass `alloc-variant-zeroed` to LLVM

Makes use of llvm/llvm-project#138299 (once we pull in a version of LLVM with this attribute). ~~Unfortunately also requires llvm/llvm-project#149336 to work.~~

Closes rust-lang#104847
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

4 participants