[PATCH] D142304: [Clang] Fix a Wbitfield-enum-conversion warning in DirectoryLookup.h

Shivam Gupta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 22 04:48:34 PST 2023


xgupta created this revision.
xgupta added reviewers: aaron.ballman, fahadnayyar.
Herald added a project: All.
xgupta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142304

Files:
  clang/include/clang/Lex/DirectoryLookup.h


Index: clang/include/clang/Lex/DirectoryLookup.h
===================================================================
--- clang/include/clang/Lex/DirectoryLookup.h
+++ clang/include/clang/Lex/DirectoryLookup.h
@@ -50,7 +50,7 @@
 
   /// DirCharacteristic - The type of directory this is: this is an instance of
   /// SrcMgr::CharacteristicKind.
-  unsigned DirCharacteristic : 2;
+  unsigned DirCharacteristic : 3;
 
   /// LookupType - This indicates whether this DirectoryLookup object is a
   /// normal directory, a framework, or a headermap.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142304.491150.patch
Type: text/x-patch
Size: 547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230122/8ff93c61/attachment.bin>


More information about the cfe-commits mailing list