[cfe-dev] How to change byte alignment of string type?

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Tue Jul 6 11:00:50 PDT 2021


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.

On Tue, Jul 6, 2021 at 10:50 AM Ryan Taylor <ryta1203 at gmail.com> wrote:

> 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
>
>
>
>
>
> On Tue, Jul 6, 2021 at 12:56 PM David Blaikie <dblaikie at gmail.com> wrote:
>
>> 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?)
>>
>> On Tue, Jul 6, 2021 at 9:03 AM Ryan Taylor via cfe-dev <
>> cfe-dev at lists.llvm.org> wrote:
>>
>>> 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
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210706/d514f7df/attachment.html>


More information about the cfe-dev mailing list