How to change byte alignment of string type?

How would I change the byte alignment of the string type from 1 byte to 4 bytes? I have little/no experience in that side of clang.

Thanks,

Ryan

which string type? The alignment of the char type? Its size is 1, I don’t think it’s possible/reasonable to have an alignment greater than the size of the type (because then how do you have an array of such types?)

Given a test case:

std::string test; // attribute((aligned(1)));

void foo() {
std::cout<<test<<std::endl;
return;
}

It looks like test is align 4:

@test = dso_local global %“class.std::basic_string” zeroinitializer, align 4

std::string’s alignment is necessary because of its members’ alignments - integers and pointers and such would generally have word alignment.

If you have an architecture where that’s not true (where integers and pointers don’t have word alignment) - there’s probably some clang code that computes that alignment from those fundamental alignment operations. If I were looking for that code I’d start with a small example (not std::string - that’s big and complicated) - such as a global int or pointer, and debug clang compiling that code & break on the GlobalVariable ctor - which presumably gets passed the alignment & then trace back through the code to see where the alignment value came from.