[clang-tidy] Fix bugprone-tagged-union-member-count false-positive (#135831) This patch implements a fix for the false-positive case described in [issue #134840](https://github.com/llvm/llvm-project/issues/134840) for the [bugprone-tagged-union-member-count](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/tagged-union-member-count.html) clang-tidy check. The example given in the linked issue was the following: ```C #include <pthread.h> typedef enum { MYENUM_ONE, MYENUM_TWO, } myEnumT; typedef struct { pthread_mutex_t mtx; myEnumT my_enum; } myTypeT; ``` The [bugprone-tagged-union-member-count](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/tagged-union-member-count.html) check emits the following a warning for this struct: ``` <source>:8:9: warning: tagged union has more data members (3) than tags (2)! [bugprone-tagged-union-member-count] 8 | typedef struct { | ^ 1 warning generated. ``` The issue is that `pthread_mutex_t` can be a union behind a typedef like the following: ```C typedef union { struct __pthread_mutex_s __data; char __size[__SIZEOF_PTHREAD_MUTEX_T]; long int __align; } pthread_mutex_t; ``` From the checker's point of view therefore `myTypeT` contains a data member with an enum type and another data member with a union type and starts analyzing it like a user-defined tagged union. The proposed solution is that the types from system headers and the std namespace are no longer candidates to be the enum part or the union part of a user-defined tagged union. This filtering for enums and the std namespace may not be strictly necessary in this example, however I added it preemptively out of (perhaps unnecessary) caution. Fixes https://github.com/llvm/llvm-project/issues/134840.
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.