This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix misuses of char width to char align
Needs ReviewPublic

Authored by amalykh on Mar 1 2019, 12:52 AM.

Details

Summary

This patch replaces getCharWidth with getCharAlign where it is used incorrectly

Diff Detail

Event Timeline

amalykh created this revision.Mar 1 2019, 12:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2019, 12:52 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Can you be more specific?
Is there some bugreport this fixes?
Is there some test?

amalykh added a comment.EditedMar 1 2019, 2:11 AM

Currently getCharWidth and getCharAlign functions are hard coded to return 8 in clang with no way to change it for target.
This can be seen in TargetInfo.h file:

unsigned getCharWidth() const { return 8; } // FIXME
unsigned getCharAlign() const { return 8; } // FIXME

It means that these functions can be used interchangeably and there will be no test failures because of this, until custom alignment will be supported.
Nevertheless, it will not be possible to support custom alignment until all incorrect usages of getCharWidth will be replaced with getCharAlign. This patch fixes some of them

Currently getCharWidth and getCharAlign functions are hard coded to return 8 in clang with no way to change it for target.
This can be seen in TargetInfo.h file:

unsigned getCharWidth() const { return 8; } // FIXME
unsigned getCharAlign() const { return 8; } // FIXME

It means that these functions can be used interchangeably and there will be no test failures because of this, until custom alignment will be supported.
Nevertheless, it will not be possible to support custom alignment until all incorrect usages of getCharWidth will be replaced with getCharAlign. This patch fixes some of them

Likewise, LLVM hardcodes that byte is 8 bits and does not want to change that
since there is no official LLVM target with that characteristics,
and thus it is impossible to test it, and it would quickly regress.

Which target will be affected by this patch?
I suspect the situation is the same here.
If there is no way to test this upstream...

momchil.velikov resigned from this revision.Mar 1 2019, 2:48 AM
momchil.velikov added a reviewer: chill.

Thank you for your comments, Roman.
Despite the fact, that there are no official LLVM targets that will be influenced by this patch, there are architectures which support only word addressing mode, for which the assumption of char align equals to 8 is not true.
The patch have been tested for a proprietary architecture, where there is a difference between align and width of char. As for the official targets, it's more like a style improvement.

lebedev.ri requested changes to this revision.Mar 4 2019, 11:09 PM

Thank you for your comments, Roman.
Despite the fact, that there are no official LLVM targets that will be influenced by this patch, there are architectures which support only word addressing mode, for which the assumption of char align equals to 8 is not true.
The patch have been tested for a proprietary architecture, where there is a difference between align and width of char. As for the official targets, it's more like a style improvement.

Thank you for working on this!

So in other words this will sadly indeed not have any test coverage in LLVM proper, correct?
If so, i think you want to submit an RFC (mentioning this fact) to cfe-dev (maybe CC llvm-dev).

This revision now requires changes to proceed.Mar 4 2019, 11:09 PM

The patch have been tested for a proprietary architecture, where there is a difference between align and width of char.

The C standard requires that both alignof(char) and sizeof(char) must equal 1, and therefore must equal each other. Could you clarify the characteristics of your target?

Could you clarify the characteristics of your target?

Yeah, sure.
The target supports only word addressing when it comes to loading from memory or storing to memory, that's why types shorter than 4 bytes need to be aligned by at least 4.
In order to achieve this, getCharAlign and getShortAlign functions and some llvm passes have been modified to work with such kind of layout.

The C standard requires that both alignof(char) and sizeof(char) must equal 1, and therefore must equal each other

Currently we are targeting C99 language standard, which, as far as I know, says nothing about alignof keyword. Anyway, thanks for pointing that out.

chill resigned from this revision.Jul 9 2019, 5:42 AM
lebedev.ri resigned from this revision.Jan 12 2023, 4:42 PM

This review seems to be stuck/dead, consider abandoning if no longer relevant.

This revision now requires review to proceed.Jan 12 2023, 4:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 4:42 PM
Herald added a subscriber: StephenFan. · View Herald Transcript