Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
ce6369e
Fix build break when building RISCVInstrInfo.cpp with MSVC (#110342)
dpaoliello Sep 30, 2024
3e5e48a
[flang][cuda] Fix buildbot failure (#110540)
clementval Sep 30, 2024
5d45815
[docs][amdgpu] Update kernarg documentation for gfx90a (#109690)
kuhar Sep 30, 2024
8518178
[clang][bytecode] Implement ia32_bextr builitns (#110513)
tbaederr Sep 30, 2024
bbdca53
[KnownBitsTest] Add optimality tests to some optimal impls; NFC
goldsteinn Sep 30, 2024
607c525
[ARM64] [Windows] Mark block address as taken when expanding catchret…
momo5502 Sep 30, 2024
41145fe
[libc++][modules] Rewrite the modulemap to have fewer top-level modul…
ldionne Sep 30, 2024
8ab50da
Include <cstdlib> in Toy Lexer examples. (#110449)
vonosmas Sep 30, 2024
9e85937
[SandboxIR][NFC] Rename SandboxIRValues.def to Values.def (#110538)
Sep 30, 2024
18fa9fa
[LLD][COFF] Add support for ARM64EC delay-load imports (#110042)
cjacek Sep 30, 2024
ab393ce
[RISCV] Take known minimum vlen into account when calculating alignme…
topperc Sep 30, 2024
92a8b81
[LegalizeVectorOps] Enable ExpandFABS/COPYSIGN to use integer ops for…
topperc Sep 30, 2024
df3f291
[TBAA] Add tests with pointers to structs to tbaa-pointers.c.
fhahn Sep 30, 2024
023f7c9
[mlir][Transforms][NFC] Dialect Conversion: Update docs for `remapVal…
matthias-springer Sep 30, 2024
49df12c
[mlir][NFC] Minor cleanup around `ModuleOp` usage (#110498)
matthias-springer Sep 30, 2024
1094ee7
[flang][debug] Better handle array lower bound of assumed shape array…
abidh Sep 30, 2024
b5aea32
[flang] Improve error recovery for bad statement after CONTAINS (#109…
klausler Sep 30, 2024
1759f3b
[flang] Improve error messages about overflowed integer conversions (…
klausler Sep 30, 2024
9b3818e
[flang] Downgrade specific format error to warning (#110314)
klausler Sep 30, 2024
4dfed69
[flang][preprocessor] Don't expand INCLUDE under -E by default (#110333)
klausler Sep 30, 2024
f8ba021
[mlir][spirv] Add gpu printf op lowering to spirv.CL.printf op (#78510)
drprajap Sep 30, 2024
53943de
[GlobalISel] Import extract/insert subvector (#110287)
tschuett Sep 30, 2024
6c5277b
[X86] Decode VPTERNLOG truth tables when disassembling
majnemer Sep 30, 2024
b8e79b3
[NFC][AMDGPU] Pre-commit tests for buffer contents legalization (#110…
krzysz00 Sep 30, 2024
0547e57
[runtimes] Run backdeployment CI on Github hosted runners (#109984)
ldionne Sep 30, 2024
725eb6b
[VPlan] Move createVPIRBasicBlock helper to VPIRBasicBlock (NFC).
fhahn Sep 30, 2024
78ccffc
[flang] Add MALLOC and FREE intrinsics for Cray pointers (#110018)
DavidTruby Sep 30, 2024
4980f21
CMake: Remove unnecessary dependencies on LLVM/MLIR (#110362)
Adnios Sep 30, 2024
96f37ae
[NFC] Use initial-stack-allocations for more data structures (#110544)
jmorse Sep 30, 2024
c214af8
[SandboxVec][Interval] Implement intersection and difference operatio…
Sep 30, 2024
27a8f00
[Bazel] Fixup for #110538, Rename SandboxIRValues.def to Values.def
chapuni Sep 30, 2024
7b23468
[WebAssembly] Use 'any' type in more cases in AsmTypeCheck (#110403)
aheejin Sep 30, 2024
8b47711
Revert "CMake: Remove unnecessary dependencies on LLVM/MLIR" (#110594)
joker-eph Sep 30, 2024
f3a4def
[libcxx][ios] initialize __fill_val_ in _FillHelper (#110279)
daltenty Sep 30, 2024
915df1a
[Clang] Implement CWG 2707 "Deduction guides cannot have a trailing r…
zyn0217 Sep 30, 2024
a5cd5d3
[lld][WebAssembly] Avoid emitting empty __wasm_apply_data_relocs func…
yamt Oct 1, 2024
50e5411
[Clang][Sema] Retain the expanding index for unevaluated type constra…
zyn0217 Oct 1, 2024
78ff340
[LLDB][Minidump] Fix bug where we were using the wrong collection for…
Jlalond Oct 1, 2024
45e1a38
[PGO] use -fprofile-update=atomic instead of mllvm option in Continuo…
Oct 1, 2024
4852374
[llvm][opt][Transforms] Replacement `calloc` should match replaced `m…
AlexVlx Oct 1, 2024
75fad47
[llvm][AMDGPU] Avoid Type::getPointerTo() (NFC)
JOE1994 Sep 30, 2024
00128a2
[RISCV] Implement Clang Builtins for XCValu Extension in CV32E40P (#1…
realqhc Oct 1, 2024
f86526c
[gn build] Port 00128a20eec2
llvmgnsyncbot Oct 1, 2024
f2f9cdd
[MLIR] Add test fort #110518 `cast`-to-`dyn_cast` fix (#110563)
bjacob Oct 1, 2024
47d42cf
[mlir][OpenMP] - MLIR to LLVMIR translation support for delayed priva…
bhandarkar-pranav Oct 1, 2024
463a4f1
[Clang][Concepts] Normalize SizeOfPackExpr's pack declaration (#110238)
zyn0217 Oct 1, 2024
eea5e7e
[libc++][string] Add regression test for sized new/delete bug (#110210)
vitalybuka Oct 1, 2024
570871e
[X86] Don't convert local function foo in the same section to foo(%ri…
MaskRay Oct 1, 2024
9ad5573
[bazel] Fix build past 00128a20eec27246719d73ba427bf821883b00b4 (#110…
dklimkin Oct 1, 2024
a81902f
[RISCV] Fold vfmv.f.s of f16 into load from stack (#110214)
lukel97 Oct 1, 2024
9e45e7f
[RISCV][GISel] Remove unused isel patterns for s32 shifts with s64 sh…
topperc Oct 1, 2024
b609163
[RISCV] Update stack-folding.ll test
lukel97 Oct 1, 2024
23c0850
[RISCV][VCIX] Add vcix_state to GNU inline assembly register set (#10…
4vtomat Oct 1, 2024
c26a522
[compiler-rt] Fix C and C++ compilers being switched when compiling t…
tambry Oct 1, 2024
8897dd6
[mlir][Transforms][NFC] Dialect Conversion: Simplify `finalize` signa…
matthias-springer Oct 1, 2024
2da417e
[mlir][GPU] gpu.printf: Do not emit duplicate format strings (#110504)
matthias-springer Oct 1, 2024
ec61311
[LLVM][TableGen] Support type casts of nodes with multiple results (#…
stephenchouca Oct 1, 2024
0089f39
[ProfileData] Avoid repeated hash lookups (NFC) (#110619)
kazutakahirata Oct 1, 2024
d50d961
[MCA] Avoid repeated hash lookups (NFC) (#110622)
kazutakahirata Oct 1, 2024
36235ce
Add a testcase for the -Wdangling-assignment-gsl warning, NFC.
hokein Oct 1, 2024
257707b
[Clang][NFC] Add a test for CWG 2913 (#110614)
zyn0217 Oct 1, 2024
cc3cc5e
[flang][NFC] simplify dispatching of reduction runtime calls (#110479)
jeanPerier Oct 1, 2024
0cf4cb4
Revert "[clang] Fix FIXME in dynamic initializer emission, NFCI"
mstorsjo Oct 1, 2024
3ba4092
[AMDGPU] Check vector sizes for physical register constraints in inli…
ritter-x2a Oct 1, 2024
8bc8b84
[SPIR-V] Fix inconsistency between previously deduced element type of…
VyacheslavLevytskyy Oct 1, 2024
3e79c7f
[SPIR-V] Implement OpSpecConstantOp with ptr-cast operation (#109979)
VyacheslavLevytskyy Oct 1, 2024
c538d5c
[SPIR-V] Discard some llvm intrinsics which we do not expect to actua…
VyacheslavLevytskyy Oct 1, 2024
0e34766
[SPIR-V] Implement support of the SPV_EXT_arithmetic_fence SPIRV exte…
VyacheslavLevytskyy Oct 1, 2024
670a98a
[AArch64] Consistently use EmitToStreamer across the AArch64AsmPrinte…
atrosinenko Oct 1, 2024
1f5e826
[mlir][vector] Add a new TD Op for patterns leveraging ShapeCastOp (#…
banach-space Oct 1, 2024
308c9a9
[Clang][LLVM][AArch64] Add intrinsic for MOVT SME2 instruction (#97602)
CarolineConcatto Oct 1, 2024
09b8dbf
[analyzer] Add optin.taint.TaintedDiv checker (#106389)
dkrupp Oct 1, 2024
271dc4a
[clang][x86] Add constexpr support for PDEP/PEXT intrinsics (#110535)
RKSimon Oct 1, 2024
091dc23
BasicAA: update comments in a routine (NFC) (#110492)
artagnon Oct 1, 2024
e2a855d
[InstCombine] Fix SimplifyDemandedBits recursion cutoff for Arguments
nikic Oct 1, 2024
39b2e35
[RISCV][test] Precommit tests showing codegen for unaligned load/stor…
asb Oct 1, 2024
520562c
Revert 412d59f0a510a05c08ed45545943dfd2f901bc5d "[DAG] combineShiftTo…
RKSimon Oct 1, 2024
47861fa
AMDGPU: Mark ds append/consume intrinsics with align 4 (#110533)
arsenm Oct 1, 2024
a5f3a2a
[lldb][TypeSystemClang] Add warning and defensive checks when ASTCont…
Michael137 Oct 1, 2024
7147e88
[clang][bytecode] Implement lzcnt/tzcnt/bzhi builtins (#110639)
tbaederr Oct 1, 2024
8a8e7f3
[clang][x86] Add constexpr support for all remaining BMI1 intrinsics …
RKSimon Oct 1, 2024
be9461c
[LLVM][InstCombine][SVE] fcvtnt(a,all_active,b) != fcvtnt(undef,all_a…
paulwalker-arm Oct 1, 2024
e96f778
[clang][x86] Fix bad merge in #110581
RKSimon Oct 1, 2024
79ecb81
[libc][math] Fix exceptional cases pow(-0, 1/2) and pow(-inf, 1/2). (…
lntue Oct 1, 2024
cc01112
[SLP][REVEC] getTypeSizeInBits should apply to scalar type instead of…
HanKuanChen Oct 1, 2024
7b8f7be
[clang-tidy] Add new check bugprone-tagged-union-member-count (#89925)
tigbr Oct 1, 2024
574e2dc
[gn build] Port 7b8f7beadcf1
llvmgnsyncbot Oct 1, 2024
a889018
[APFloat] Correct semantics of minimum/maximum for signaling NaN argu…
asb Oct 1, 2024
91ef1f7
A few tweaks to the MLIR .pyi files (#110488)
superbobry Oct 1, 2024
c4d9cd8
[LLD][ELF][AArch64] Add BTI Aware long branch thunks (#108989)
smithp35 Oct 1, 2024
0344123
[VPlan] Manage FMFs for VPWidenCall via VPRecipeWithIRFlags. (NFC)
fhahn Oct 1, 2024
4b3ba64
[SCEVExpander] Clear flags when reusing GEP (#109293)
nikic Oct 1, 2024
b2a6814
[AArch64][NEON][SVE] Lower i8 to i64 partial reduction to a dot produ…
JamesChesterman Oct 1, 2024
ba340b2
[LLD][COFF] Define remaining ARM64EC builtin symbols (#110640)
cjacek Oct 1, 2024
b8b036a
[HLSL] Treat `main` as any other function (#110546)
llvm-beanz Oct 1, 2024
a57a83f
Add missing extendhfxf2 in compiler rt (#109090)
biabbas Oct 1, 2024
cab8c87
[libc] Fix race conditions in sprintf_test. (#110624)
lntue Oct 1, 2024
14c4f28
[RISCV] Enable load clustering by default (#73789)
asb Oct 1, 2024
9f81acf
[Mips] Regenerate test checks (NFC)
nikic Oct 1, 2024
a59e5d8
[ConstantFold][RFC] Add AllowLHSConstant parameter in getBinOpAbsorbe…
Oct 1, 2024
2e559c3
[NFC] Correct the misuse of the API in the Clang test-report script (…
c8ef Oct 1, 2024
f3d58f4
Revert "[libc++] LWG3870: Remove `voidify` (#110355)" (#110587)
Michael137 Oct 1, 2024
007780f
Revert "Add missing extendhfxf2 in compiler rt" (#110662)
lntue Oct 1, 2024
8f2aa9d
workflow/release-binaries: Checkout sources before downloading artifa…
tstellar Oct 1, 2024
9cd289f
workflows/release-documentation: Submit a pull request with changes (…
tstellar Oct 1, 2024
fe61dbf
[AMDGPU] Specify width and align for all AMDGPU builtin types. NFC. (…
jayfoad Oct 1, 2024
936142e
[flang] IEEE_RINT, IEEE_INT (#110509)
vdonaldson Oct 1, 2024
2672037
[AMDGPU][True16][MC] Support VOP3 only instructions with true16 and f…
broxigarchen Oct 1, 2024
be6b4f6
[HLSL][SPIRV] Fix calling convention for call in entry function. (#11…
s-perron Oct 1, 2024
bb78a0b
[clang] Fix the local parameter of void type inside the `Requires` ex…
c8ef Oct 1, 2024
677e8cd
[libc++] Avoid re-exporting a few specific symbols from libc++abi (#1…
ldionne Oct 1, 2024
97da34e
[OpenACC] Add 'collapse' clause AST/basic Sema implementation (#109461)
erichkeane Oct 1, 2024
d6d3d2f
[libc++] Run additional LLDB data formatters tests as part of libc++'…
ldionne Oct 1, 2024
bea1c90
[NFC] Fix line width to fit in 80 columns (#110605)
jurahul Oct 1, 2024
a86e966
[TableGen] Change TableGenMain to use const RecordKeeper (#110578)
jurahul Oct 1, 2024
017c2ab
[Clang][TableGen] Change ClangAttrEmitter to use const Record * (#110…
jurahul Oct 1, 2024
52e7c69
[Clang][TableGen] Change ClangDiagnosticEmitter to use const Record *…
jurahul Oct 1, 2024
5831eed
[Clang][TableGen] Change Opcodes Emitter to use const Record * (#110588)
jurahul Oct 1, 2024
fdfd326
[Clang][LLVM] Change OpenCL Emitter to use const Record * (#110590)
jurahul Oct 1, 2024
9d95e26
[TableGen] Change all type pointers to const (#110602)
jurahul Oct 1, 2024
2469d7e
[NFC] Add a new Intrinsics.cpp file for intrinsic code (#110078)
jurahul Oct 1, 2024
60b604a
[libc++][z/OS] Fix shared_ptr control block test when aligned allocat…
zibi2 Oct 1, 2024
2026501
[MLIR] Make `OneShotModuleBufferize` use `OpInterface` (#110322)
tzunghanjuang Oct 1, 2024
28be39f
[Flang][Driver] Enable the -B option (#109965)
kiranchandramohan Oct 1, 2024
d0f6777
[MLIR][OpenMP] Normalize handling of entry block arguments (#109808)
skatrak Oct 1, 2024
cb52e8e
[clang][x86] Add constexpr support for MULX intrinsics (#110654)
RKSimon Oct 1, 2024
2a2c35a
[InstCombine] Fold `icmp spred (mul nsw X, Z), (mul nsw Y, Z)` into `…
dtcxzyw Oct 1, 2024
616d1d2
[gn build] Port 2469d7e361a2
llvmgnsyncbot Oct 1, 2024
f01d45c
[DebugInfo] Avoid repeated hash lookups (NFC) (#110620)
kazutakahirata Oct 1, 2024
ede866d
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#110621)
kazutakahirata Oct 1, 2024
8395b3f
AMDGPU: Mark scc dead when materialized frame base registers
arsenm Oct 1, 2024
dc98482
AMDGPU: Fix executable permissions on file
arsenm Oct 1, 2024
7ca4128
[AArch64] Generalize the instruction size checking in AsmPrinter (#11…
atrosinenko Oct 1, 2024
e565a4f
[IR] Extract helper for GEPNoWrapFlags intersection (NFC)
nikic Oct 1, 2024
16ba126
[AMDGPU][GlobalISel][NFC] Use amdhsa target for flat/private tests (#…
ritter-x2a Oct 1, 2024
55c70f6
[clang][bytecode] Check GetPtrBase ops for null pointers (#110673)
tbaederr Oct 1, 2024
cd40070
[RegisterPressure] NFC: Clean up RP handling for instructions with ov…
jrbyrnes Oct 1, 2024
f3baa73
[clang][bytecode] Implement ia32_{pdep,pext} builtins (#110675)
tbaederr Oct 1, 2024
cdb3ebf
[MLIR][OpenMP] Normalize representation of entry block arg-defining c…
skatrak Oct 1, 2024
9f6f6af
LoopSimplify: strip dependency on DA (NFC) (#107379)
artagnon Oct 1, 2024
c66dee4
[AMDGPU] Refactor several functions for merging with downstream work.…
cmc-rep Oct 1, 2024
5894d4e
[MLIR][OpenMP] Use map format to represent use_device_{addr,ptr} (#10…
skatrak Oct 1, 2024
d071fda
[llvm][OMPIRBuilder] Avoid Type::getPointerTo() (NFC) (#110678)
JOE1994 Oct 1, 2024
c63112a
[libc][stdio] Use proxy headers of stdio.h in src and test folders. (…
lntue Oct 1, 2024
4e52e6a
[MLIR][OpenMP] Document entry block argument-defining clauses (NFC) (…
skatrak Oct 1, 2024
f61abee
AMDGPU: Add missing tests for local stack alloc s_add_i32 handling
arsenm Oct 1, 2024
54a4965
[MLIR][OpenMP] Improve omp.section block arguments handling (#110266)
skatrak Oct 1, 2024
0eb2602
[libc++] Remove potential 0-sized array in __compressed_pair_padding …
serge-sans-paille Oct 1, 2024
0de0354
[LLVM][TableGen] Decrease code size of `Intrinsic::getAttributes` (#1…
jurahul Oct 1, 2024
0dab022
[SLP][NFC]Add a test with external cast and extracted operand, NFC
alexey-bataev Oct 1, 2024
afc0557
[IR][Attribute] Add support for intersecting AttributeLists; NFC (#10…
goldsteinn Oct 1, 2024
a3b7199
[AutoBump] Merge with afc0557a (Oct 01)
mgehre-amd Jan 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 15 additions & 8 deletions .github/workflows/libcxx-build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,24 @@ jobs:
**/crash_diagnostics/*

macos:
runs-on: macos-14
needs: [ stage1 ]
strategy:
fail-fast: true
fail-fast: false
matrix:
config: [
generic-cxx03,
generic-cxx23,
generic-modules,
apple-configuration
]
include:
- config: generic-cxx03
os: macos-latest
- config: generic-cxx23
os: macos-latest
- config: generic-modules
os: macos-latest
- config: apple-configuration
os: macos-latest
- config: apple-system
os: macos-13
- config: apple-system-hardened
os: macos-13
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: maxim-lobanov/setup-xcode@v1
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ jobs:
attestations: write # For artifact attestations

steps:
- name: Checkout Release Scripts
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
sparse-checkout: |
llvm/utils/release/github-upload-release.py
llvm/utils/git/requirements.txt
sparse-checkout-cone-mode: false

- name: 'Download artifact'
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4.1.1
with:
Expand All @@ -442,14 +450,6 @@ jobs:
name: ${{ needs.prepare.outputs.release-binary-filename }}-attestation
path: ${{ needs.prepare.outputs.release-binary-filename }}.jsonl

- name: Checkout Release Scripts
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
sparse-checkout: |
llvm/utils/release/github-upload-release.py
llvm/utils/git/requirements.txt
sparse-checkout-cone-mode: false

- name: Install Python Requirements
run: |
pip install --require-hashes -r ./llvm/utils/git/requirements.txt
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/release-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,20 @@ jobs:
ref: main
fetch-depth: 0
path: www-releases
persist-credentials: false

- name: Upload Release Notes
if: env.upload
env:
WWW_RELEASES_TOKEN: ${{ secrets.WWW_RELEASES_TOKEN }}
GH_TOKEN: ${{ secrets.WWW_RELEASES_TOKEN }}
run: |
mkdir -p ../www-releases/${{ inputs.release-version }}
mv ./docs-build/html-export/* ../www-releases/${{ inputs.release-version }}
cd ../www-releases
mkdir -p www-releases/${{ inputs.release-version }}
mv ./docs-build/html-export/* www-releases/${{ inputs.release-version }}
cd www-releases
git checkout -b ${{ inputs.release-version }}
git add ${{ inputs.release-version }}
git config user.email "llvmbot@llvm.org"
git config user.name "llvmbot"
git commit -a -m "Add ${{ inputs.release-version }} documentation"
git push "https://$WWW_RELEASES_TOKEN@github.com/${{ github.repository_owner }}/www-releases" main:main
git push --force "https://$GH_TOKEN@github.com/llvmbot/www-releases.git" HEAD:refs/heads/${{ inputs.release-version }}
gh pr create -f -B main -H ${{ inputs.release-version }} -R llvmbot/www-releases
3 changes: 3 additions & 0 deletions clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#include "SuspiciousStringviewDataUsageCheck.h"
#include "SwappedArgumentsCheck.h"
#include "SwitchMissingDefaultCaseCheck.h"
#include "TaggedUnionMemberCountCheck.h"
#include "TerminatingContinueCheck.h"
#include "ThrowKeywordMissingCheck.h"
#include "TooSmallLoopVariableCheck.h"
Expand Down Expand Up @@ -229,6 +230,8 @@ class BugproneModule : public ClangTidyModule {
"bugprone-suspicious-stringview-data-usage");
CheckFactories.registerCheck<SwappedArgumentsCheck>(
"bugprone-swapped-arguments");
CheckFactories.registerCheck<TaggedUnionMemberCountCheck>(
"bugprone-tagged-union-member-count");
CheckFactories.registerCheck<TerminatingContinueCheck>(
"bugprone-terminating-continue");
CheckFactories.registerCheck<ThrowKeywordMissingCheck>(
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ add_clang_library(clangTidyBugproneModule
SuspiciousSemicolonCheck.cpp
SuspiciousStringCompareCheck.cpp
SwappedArgumentsCheck.cpp
TaggedUnionMemberCountCheck.cpp
TerminatingContinueCheck.cpp
ThrowKeywordMissingCheck.cpp
TooSmallLoopVariableCheck.cpp
Expand Down
199 changes: 199 additions & 0 deletions clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
//===--- TaggedUnionMemberCountCheck.cpp - clang-tidy ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "TaggedUnionMemberCountCheck.h"
#include "../utils/OptionsUtils.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"

using namespace clang::ast_matchers;

namespace clang::tidy::bugprone {

static constexpr llvm::StringLiteral StrictModeOptionName = "StrictMode";
static constexpr llvm::StringLiteral EnableCountingEnumHeuristicOptionName =
"EnableCountingEnumHeuristic";
static constexpr llvm::StringLiteral CountingEnumPrefixesOptionName =
"CountingEnumPrefixes";
static constexpr llvm::StringLiteral CountingEnumSuffixesOptionName =
"CountingEnumSuffixes";

static constexpr bool StrictModeOptionDefaultValue = false;
static constexpr bool EnableCountingEnumHeuristicOptionDefaultValue = true;
static constexpr llvm::StringLiteral CountingEnumPrefixesOptionDefaultValue =
"";
static constexpr llvm::StringLiteral CountingEnumSuffixesOptionDefaultValue =
"count";

static constexpr llvm::StringLiteral RootMatchBindName = "root";
static constexpr llvm::StringLiteral UnionMatchBindName = "union";
static constexpr llvm::StringLiteral TagMatchBindName = "tags";

namespace {

AST_MATCHER_P2(RecordDecl, fieldCountOfKindIsOne,
ast_matchers::internal::Matcher<FieldDecl>, InnerMatcher,
StringRef, BindName) {
// BoundNodesTreeBuilder resets itself when a match occurs.
// So to avoid losing previously saved binds, a temporary instance
// is used for matching.
//
// For precedence, see commit: 5b07de1a5faf4a22ae6fd982b877c5e7e3a76559
clang::ast_matchers::internal::BoundNodesTreeBuilder TempBuilder;

const FieldDecl *FirstMatch = nullptr;
for (const FieldDecl *Field : Node.fields()) {
if (InnerMatcher.matches(*Field, Finder, &TempBuilder)) {
if (FirstMatch) {
return false;
} else {
FirstMatch = Field;
}
}
}

if (FirstMatch) {
Builder->setBinding(BindName, clang::DynTypedNode::create(*FirstMatch));
return true;
}
return false;
}

} // namespace

TaggedUnionMemberCountCheck::TaggedUnionMemberCountCheck(
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
StrictMode(
Options.get(StrictModeOptionName, StrictModeOptionDefaultValue)),
EnableCountingEnumHeuristic(
Options.get(EnableCountingEnumHeuristicOptionName,
EnableCountingEnumHeuristicOptionDefaultValue)),
CountingEnumPrefixes(utils::options::parseStringList(
Options.get(CountingEnumPrefixesOptionName,
CountingEnumPrefixesOptionDefaultValue))),
CountingEnumSuffixes(utils::options::parseStringList(
Options.get(CountingEnumSuffixesOptionName,
CountingEnumSuffixesOptionDefaultValue))) {
if (!EnableCountingEnumHeuristic) {
if (Options.get(CountingEnumPrefixesOptionName))
configurationDiag("%0: Counting enum heuristic is disabled but "
"%1 is set")
<< Name << CountingEnumPrefixesOptionName;
if (Options.get(CountingEnumSuffixesOptionName))
configurationDiag("%0: Counting enum heuristic is disabled but "
"%1 is set")
<< Name << CountingEnumSuffixesOptionName;
}
}

void TaggedUnionMemberCountCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, StrictModeOptionName, StrictMode);
Options.store(Opts, EnableCountingEnumHeuristicOptionName,
EnableCountingEnumHeuristic);
Options.store(Opts, CountingEnumPrefixesOptionName,
utils::options::serializeStringList(CountingEnumPrefixes));
Options.store(Opts, CountingEnumSuffixesOptionName,
utils::options::serializeStringList(CountingEnumSuffixes));
}

void TaggedUnionMemberCountCheck::registerMatchers(MatchFinder *Finder) {

auto UnionField = fieldDecl(hasType(qualType(
hasCanonicalType(recordType(hasDeclaration(recordDecl(isUnion())))))));

auto EnumField = fieldDecl(hasType(
qualType(hasCanonicalType(enumType(hasDeclaration(enumDecl()))))));

auto hasOneUnionField = fieldCountOfKindIsOne(UnionField, UnionMatchBindName);
auto hasOneEnumField = fieldCountOfKindIsOne(EnumField, TagMatchBindName);

Finder->addMatcher(recordDecl(anyOf(isStruct(), isClass()), hasOneUnionField,
hasOneEnumField, unless(isImplicit()))
.bind(RootMatchBindName),
this);
}

bool TaggedUnionMemberCountCheck::isCountingEnumLikeName(StringRef Name) const {
if (llvm::any_of(CountingEnumPrefixes, [Name](StringRef Prefix) -> bool {
return Name.starts_with_insensitive(Prefix);
}))
return true;
if (llvm::any_of(CountingEnumSuffixes, [Name](StringRef Suffix) -> bool {
return Name.ends_with_insensitive(Suffix);
}))
return true;
return false;
}

std::pair<const std::size_t, const EnumConstantDecl *>
TaggedUnionMemberCountCheck::getNumberOfEnumValues(const EnumDecl *ED) {
llvm::SmallSet<llvm::APSInt, 16> EnumValues;

const EnumConstantDecl *LastEnumConstant = nullptr;
for (const EnumConstantDecl *Enumerator : ED->enumerators()) {
EnumValues.insert(Enumerator->getInitVal());
LastEnumConstant = Enumerator;
}

if (EnableCountingEnumHeuristic && LastEnumConstant &&
isCountingEnumLikeName(LastEnumConstant->getName()) &&
(LastEnumConstant->getInitVal() == (EnumValues.size() - 1))) {
return {EnumValues.size() - 1, LastEnumConstant};
}

return {EnumValues.size(), nullptr};
}

void TaggedUnionMemberCountCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *Root = Result.Nodes.getNodeAs<RecordDecl>(RootMatchBindName);
const auto *UnionField =
Result.Nodes.getNodeAs<FieldDecl>(UnionMatchBindName);
const auto *TagField = Result.Nodes.getNodeAs<FieldDecl>(TagMatchBindName);

assert(Root && "Root is missing!");
assert(UnionField && "UnionField is missing!");
assert(TagField && "TagField is missing!");
if (!Root || !UnionField || !TagField)
return;

const auto *UnionDef =
UnionField->getType().getCanonicalType().getTypePtr()->getAsRecordDecl();
const auto *EnumDef = llvm::dyn_cast<EnumDecl>(
TagField->getType().getCanonicalType().getTypePtr()->getAsTagDecl());

assert(UnionDef && "UnionDef is missing!");
assert(EnumDef && "EnumDef is missing!");
if (!UnionDef || !EnumDef)
return;

const std::size_t UnionMemberCount = llvm::range_size(UnionDef->fields());
auto [TagCount, CountingEnumConstantDecl] = getNumberOfEnumValues(EnumDef);

if (UnionMemberCount > TagCount) {
diag(Root->getLocation(),
"tagged union has more data members (%0) than tags (%1)!")
<< UnionMemberCount << TagCount;
} else if (StrictMode && UnionMemberCount < TagCount) {
diag(Root->getLocation(),
"tagged union has fewer data members (%0) than tags (%1)!")
<< UnionMemberCount << TagCount;
}

if (CountingEnumConstantDecl) {
diag(CountingEnumConstantDecl->getLocation(),
"assuming that this constant is just an auxiliary value and not "
"used for indicating a valid union data member",
DiagnosticIDs::Note);
}
}

} // namespace clang::tidy::bugprone
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===--- TaggedUnionMemberCountCheck.h - clang-tidy -------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TAGGEDUNIONMEMBERCOUNTCHECK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TAGGEDUNIONMEMBERCOUNTCHECK_H

#include "../ClangTidyCheck.h"

namespace clang::tidy::bugprone {

/// Gives warnings for tagged unions, where the number of tags is
/// different from the number of data members inside the union.
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/tagged-union-member-count.html
class TaggedUnionMemberCountCheck : public ClangTidyCheck {
public:
TaggedUnionMemberCountCheck(StringRef Name, ClangTidyContext *Context);
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

private:
const bool StrictMode;
const bool EnableCountingEnumHeuristic;
const std::vector<StringRef> CountingEnumPrefixes;
const std::vector<StringRef> CountingEnumSuffixes;

std::pair<const std::size_t, const EnumConstantDecl *>
getNumberOfEnumValues(const EnumDecl *ED);
bool isCountingEnumLikeName(StringRef Name) const;
};

} // namespace clang::tidy::bugprone

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TAGGEDUNIONMEMBERCOUNTCHECK_H
6 changes: 6 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ Improvements to clang-tidy
New checks
^^^^^^^^^^

- New :doc:`bugprone-tagged-union-member-count
<clang-tidy/checks/bugprone/tagged-union-member-count>` check.

Gives warnings for tagged unions, where the number of tags is
different from the number of data members inside the union.

New check aliases
^^^^^^^^^^^^^^^^^

Expand Down
Loading
Loading