rust/tests/assembly/cstring-merging.rs
Eddy (Eduard) Stefes 1ac3d6bba7 Let CStrings be either 1 or 2 byte aligned.
Some architectures (like s390x) require strings to be 2 byte aligned.
Therefor the section name will be marked with a .2  postfix on this
architectures.

Allowing a section name with a .1 or .2 postfix will make the test pass
on either platform.
2025-04-14 10:03:31 +02:00

29 lines
585 B
Rust

//@ only-linux
//@ assembly-output: emit-asm
//@ compile-flags: --crate-type=lib -Copt-level=3
//@ edition: 2024
use std::ffi::CStr;
// CHECK: .section .rodata.str1.{{[12]}},"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"
}