diff options
| author | bors <bors@rust-lang.org> | 2025-03-28 10:18:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-03-28 10:18:32 +0000 |
| commit | 2a06022951893fe5b5384f8dbd75b4e6e3b5cee0 (patch) | |
| tree | c03e2eb1cf5ee8a760a01e53b150b74c033bc4b6 /tests/assembly | |
| parent | e77a8f439cc87c5d67b007e9811578533de1de91 (diff) | |
| parent | 5c82a59bd30815a942b64fa09e22dbe442edf56d (diff) | |
Auto merge of #138503 - bjorn3:string_merging, r=tmiasko
Avoid wrapping constant allocations in packed structs when not necessary This way LLVM will set the string merging flag if the alloc is a nul terminated string, reducing binary sizes. try-job: armhf-gnu
Diffstat (limited to 'tests/assembly')
| -rw-r--r-- | tests/assembly/cstring-merging.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/assembly/cstring-merging.rs b/tests/assembly/cstring-merging.rs new file mode 100644 index 00000000000..7436e241823 --- /dev/null +++ b/tests/assembly/cstring-merging.rs @@ -0,0 +1,27 @@ +//@ only-linux +//@ assembly-output: emit-asm +//@ compile-flags: --crate-type=lib -Copt-level=3 --edition 2024 + +use std::ffi::CStr; + +// CHECK: .section .rodata.str1.1,"aMS" +// CHECK: .Lanon.{{.+}}: +// CHECK-NEXT: .asciz "foo" +#[unsafe(no_mangle)] +static CSTR: &[u8; 4] = b"foo\0"; + +// CHECK-NOT: .section +// CHECK: .Lanon.{{.+}}: +// CHECK-NEXT: .asciz "bar" +#[unsafe(no_mangle)] +pub fn cstr() -> &'static CStr { + c"bar" +} + +// CHECK-NOT: .section +// CHECK: .Lanon.{{.+}}: +// CHECK-NEXT: .asciz "baz" +#[unsafe(no_mangle)] +pub fn manual_cstr() -> &'static str { + "baz\0" +} |
