This is an archive of the discontinued LLVM Phabricator instance.

[clang] Implement -funsigned-bitfields
Needs ReviewPublic

Authored by DavidFerencSzabo on Aug 26 2023, 7:16 AM.

Details

Reviewers
arsenm
rsmith
aaron.ballman
Group Reviewers
Restricted Project
Summary

Prototype implementation of -funsigned-bitfields flag. This solution ignores explicit signdness of bitfields and will make them unsigned (except for char) , which not align with the expected behavior of this flag. The problem is that the explicit signdess information seems to be lost at this point for typedefs. It is possible to check DeclSpec of the Declarator for signdness, but if the current Declarator is a typename, then there is a problem with this approach, since that will not have the explicit signdess information of the underlying type. I looking for help/guidance how to proceed with this to make this feature work, that is: only make unsigned those bitfields which were not explicitly made signed.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2023, 7:16 AM
DavidFerencSzabo requested review of this revision.Aug 26 2023, 7:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2023, 7:16 AM
DavidFerencSzabo edited the summary of this revision. (Show Details)Aug 26 2023, 7:29 AM
shafik added reviewers: aaron.ballman, Restricted Project.Aug 28 2023, 2:41 PM
shafik added a subscriber: shafik.

Adding more reviewers for visibility.

cor3ntin added inline comments.
clang/lib/Sema/SemaDecl.cpp
18137

The information seems preserved in BuiltinTypeLoc::getWrittenSignSpec
From TypedefType::getDecl, you can get a TypedefNameDecl, which has a getTypeSourceInfo, which gets you a TypeSourceInfo, that you can extract a TypeLoc from, and if you cast that to BuiltinTypeLoc, you might be able to find what you need. Good luck!

18146–18158

ASTContext::getCorrespondingUnsignedType is probably the better way to do that