This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix a Wbitfield-enum-conversion warning in DirectoryLookup.h
ClosedPublic

Authored by xgupta on Jan 22 2023, 4:48 AM.

Details

Summary

When compiling clang/Lex/DirectoryLookup.h with option -Wbitfield-enum-conversion, we get the following warning:

DirectoryLookup.h:77:17: warning:

bit-field 'DirCharacteristic' is not wide enough to store all enumerators of
'CharacteristicKind' [-Wbitfield-enum-conversion]
: u(Map), DirCharacteristic(DT), LookupType(LT_HeaderMap),

DirCharacteristic is a bitfield with 2 bits (4 values)

/// DirCharacteristic - The type of directory this is: this is an instance of
/// SrcMgr::CharacteristicKind.
unsigned DirCharacteristic : 2;

Whereas SrcMgr::CharacterKind is an enum with 5 values:
enum CharacteristicKind {

C_User,
C_System,
C_ExternCSystem,
C_User_ModuleMap,
C_System_ModuleMap

};

Solution is to increase DirCharacteristic bitfield from 2 to 3.
Patch by Dimitri van Heesch

Diff Detail

Event Timeline

xgupta created this revision.Jan 22 2023, 4:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 22 2023, 4:48 AM
xgupta requested review of this revision.Jan 22 2023, 4:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 22 2023, 4:48 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman accepted this revision.Jan 23 2023, 7:10 AM

LGTM but can you find a test case that would show we don't regress this in the future?

This revision is now accepted and ready to land.Jan 23 2023, 7:10 AM

LGTM but can you find a test case that would show we don't regress this in the future?

I haven't found the test case, but I found a commit that increases CharacteristicKind enum's values from 3 to 5. Seems they missed updating DirCharacteristic. Do you have suggestions on where/how to add a test case for this?

I looked through the code base and I think this fix is good but benign (it doesn't look like it'll impact anything that I can see). So LGTM without tests.

This revision was landed with ongoing or failed builds.Jan 23 2023, 10:18 AM
This revision was automatically updated to reflect the committed changes.

I looked through the code base and I think this fix is good but benign (it doesn't look like it'll impact anything that I can see). So LGTM without tests.

Thank you for reviewing the change.