<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120932>120932</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[FuncAttrs] volatile memcpy should not be eliminated
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm::Attributor
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
Reproducer: https://godbolt.org/z/n4j66We8h
```
; bin/opt -O3 test.ll -S
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.S0 = type { i32, i32, i64, i16 }
@g_148 = constant %struct.S0 { i32 568401685, i32 -1, i64 -1, i16 -1 }
define i32 @main() {
entry:
%call2 = call i32 @func_127()
ret i32 0
}
define i32 @func_127() {
entry:
%call241 = call ptr @func_144(ptr null)
%call58 = call i32 @func_139(ptr %call241)
ret i32 0
}
define internal i32 @func_139(ptr %p_140) {
entry:
ret i32 0
}
define ptr @func_144(ptr %p_145) {
entry:
%agg.tmp.ensured = alloca %struct.S0, align 8
call void @llvm.memcpy.p0.p0.i64(ptr %agg.tmp.ensured, ptr @g_148, i64 24, i1 true)
ret ptr %p_145
}
```
Output:
```
%struct.S0 = type { i32, i32, i64, i16 }
define noundef i32 @main() local_unnamed_addr #0 {
ret i32 0
}
define noundef i32 @func_127() local_unnamed_addr #0 {
ret i32 0
}
define ptr @func_144(ptr readnone returned %p_145) local_unnamed_addr #0 {
%agg.tmp.ensured = alloca %struct.S0, align 8
call void @llvm.memcpy.p0.p0.i64(ptr nonnull %agg.tmp.ensured, ptr @g_148, i64 24, i1 true)
ret ptr %p_145
}
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1
attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
```
The memory effect of `func_144` should not be `memory(none)`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0Vl1vozgU_TXOi0XkD-LAQx7oRHkdaWelfYwcuBDPGBv5o23m16_skKbJtJ1qVishMNjn3HvPPQak92owABu0ekCr7ULGcLRu04X2-efpaXGw3WnzF0zOdrEFh3iDjyFMHvEGsR1iu8F2B6vD0roBsd1PxHam_C7EP1AdEWmQIPNBGsQf8EEZxHZ2Crj4ynEAH5Za4-IbIk2QboCAOxmklicbA0Z8ixFjUIyIN1BMbE0QbzjLp3RLb2_TSJT5VKiXAWUV4g1lVdFXZB6Z_Ehc4KIsvqVljF3zCE5NGi45PFdiL8oimh_GPplCKxOfi8HEMyQdbOWDi21YfiMZFE4TYLR-wIozxL68XESZL1RgtN7O2JIMe1pWGdda44M0Ad8ynonwSlQloaJazZS4oDPrZUQFLuiVu4NeGchLUUlGmfSvEKsTIyINmOBOqZekwSliK7Vm5zyk1hdYH027p2x9hua1DkKezY19O9gt6qOAJb2GnIK7gssSsSo9MVHrS-gZtareyZPXM-hK_6msTQBn5Adk056W5J1SPmJ-u6SZcPW-NnIYlmGclmB8dNDlcqXWtpU35khtl1oNBlcZmRV5tKpLQbV-HJcjjO10Wk4kHdmBlwzuQiSqOdvsyIu32GxaHFyE12LeFPJS-atN_zWGKYZzUTcvg_-wX2ZZjY2mg_4NbyeJ9D4aI0fo9rLrUpKczDJ_2Ks70jsP_4b4D1zgQHbGGkjQ6Ezq8itf_C7eH5vk0x4x1qS99_95JenTaungk-lIraTHxrZyCtEBfnIqgDX6dMnn1yVJ48uKFz9hNY4yfbPqJCk9pyJDcOoQA_hZ5_T2Xz_gMfowOTs48Im4d5Cc4qCNzqeRP5k2W-dJmQ4_Ka3P7cQjjNadEKtSj887fftLHPpenNSlg2x_XEN-EEG6YYT0pcz1ZlmuAV9vvb-PMKMw9D20AdseI3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