Skip to content

[IR] Fix incorrect writeonly on llvm.allow.ubsan/runtime.check #145492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Jun 24, 2025

These intrinsics introduced in #84850 are currently marked as memory(inaccessiblemem: write). This is not correct for the intended purpose of allowing per-block decisions, as such calls may get DCEd across control-flow boundaries (which will start actually happening with #145474).

Use memory(inaccessiblemem: readwrite) instead, just like all the other control-flow sensitive intrinsics.

These intrinsics introduced in llvm#84850 are currently marked as
`memory(inaccessiblemem: write)`. This is not correct for the
intended purpose of allowing per-block decisions, as such calls
may get DCEd across control-flow boundaries (which will start
actually happening with llvm#145474).

Use `memory(inaccessiblemem: readwrite)` instead, just like all
the other control-flow sensitive intrinsics.
@llvmbot
Copy link
Member

llvmbot commented Jun 24, 2025

@llvm/pr-subscribers-llvm-ir

Author: Nikita Popov (nikic)

Changes

These intrinsics introduced in #84850 are currently marked as memory(inaccessiblemem: write). This is not correct for the intended purpose of allowing per-block decisions, as such calls may get DCEd across control-flow boundaries (which will start actually happening with #145474).

Use memory(inaccessiblemem: readwrite) instead, just like all the other control-flow sensitive intrinsics.


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

2 Files Affected:

  • (modified) llvm/include/llvm/IR/Intrinsics.td (+2-2)
  • (modified) llvm/test/Instrumentation/BoundsChecking/runtimes.ll (+1-1)
diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 7add4a27ce9e9..bd6f94ac1286c 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1842,11 +1842,11 @@ def int_ubsantrap : Intrinsic<[], [llvm_i8_ty],
 
 // Return true if ubsan check is allowed.
 def int_allow_ubsan_check : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i8_ty],
-    [IntrInaccessibleMemOnly, IntrWriteMem, ImmArg<ArgIndex<0>>, NoUndef<RetIndex>]>;
+    [IntrInaccessibleMemOnly, ImmArg<ArgIndex<0>>, NoUndef<RetIndex>]>;
 
 // Return true if runtime check is allowed.
 def int_allow_runtime_check : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_metadata_ty],
-    [IntrInaccessibleMemOnly, IntrWriteMem, NoUndef<RetIndex>]>,
+    [IntrInaccessibleMemOnly, NoUndef<RetIndex>]>,
     ClangBuiltin<"__builtin_allow_runtime_check">;
 
 // Support for dynamic deoptimization (or de-specialization)
diff --git a/llvm/test/Instrumentation/BoundsChecking/runtimes.ll b/llvm/test/Instrumentation/BoundsChecking/runtimes.ll
index 6c1acf6d13775..2006a6db2ef40 100644
--- a/llvm/test/Instrumentation/BoundsChecking/runtimes.ll
+++ b/llvm/test/Instrumentation/BoundsChecking/runtimes.ll
@@ -205,7 +205,7 @@ define void @f1(i64 %x) nounwind {
 ; TR-GUARD: attributes #[[ATTR3]] = { nomerge noreturn nounwind }
 ;.
 ; RT-GUARD: attributes #[[ATTR0]] = { nounwind }
-; RT-GUARD: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
+; RT-GUARD: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
 ; RT-GUARD: attributes #[[ATTR2]] = { nomerge nounwind }
 ;.
 ; TR: [[META0]] = !{}

Copy link
Collaborator

@preames preames 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 d95f46c into llvm:main Jun 25, 2025
9 checks passed
@nikic nikic deleted the fix-ubsan-check branch June 25, 2025 07:12
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…145492)

These intrinsics introduced in llvm#84850 are currently marked as
`memory(inaccessiblemem: write)`. This is not correct for the intended
purpose of allowing per-block decisions, as such calls may get DCEd
across control-flow boundaries (which will start actually happening with
llvm#145474).

Use `memory(inaccessiblemem: readwrite)` instead, just like all the
other control-flow sensitive intrinsics.
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
…145492)

These intrinsics introduced in llvm#84850 are currently marked as
`memory(inaccessiblemem: write)`. This is not correct for the intended
purpose of allowing per-block decisions, as such calls may get DCEd
across control-flow boundaries (which will start actually happening with
llvm#145474).

Use `memory(inaccessiblemem: readwrite)` instead, just like all the
other control-flow sensitive intrinsics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants