[clang] [llvm] Reapply "Reland "[HLSL] Implement the `reflect` HLSL function"" (#124046) (PR #128386)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/128386 This reverts commit 0fe8e70c6609ff86cd40fbb45a85a8ed04c153c2. >From 37bc44832ab10781b467c9b4a9e62af594305534 Mon Sep 17 00:00:00 2001 From: Icohedron Date: Sat, 22 Feb 2025 17:38:18 -0800 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/include/clang/Basic/BuiltinsSPIRV.td| 6 + clang/lib/CodeGen/CGBuiltin.cpp | 13 ++ clang/lib/Headers/hlsl/hlsl_detail.h | 16 ++ clang/lib/Headers/hlsl/hlsl_intrinsics.h | 43 + clang/lib/Sema/SemaSPIRV.cpp | 32 clang/test/CodeGenHLSL/builtins/reflect.hlsl | 177 ++ clang/test/CodeGenSPIRV/Builtins/reflect.c| 32 .../SemaHLSL/BuiltIns/reflect-errors.hlsl | 33 .../test/SemaSPIRV/BuiltIns/reflect-errors.c | 23 +++ llvm/include/llvm/IR/IntrinsicsSPIRV.td | 1 + .../Target/SPIRV/SPIRVInstructionSelector.cpp | 16 +- .../CodeGen/SPIRV/hlsl-intrinsics/reflect.ll | 33 .../CodeGen/SPIRV/opencl/reflect-error.ll | 13 ++ 13 files changed, 434 insertions(+), 4 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/reflect.hlsl create mode 100644 clang/test/CodeGenSPIRV/Builtins/reflect.c create mode 100644 clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl create mode 100644 clang/test/SemaSPIRV/BuiltIns/reflect-errors.c create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll create mode 100644 llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td b/clang/include/clang/Basic/BuiltinsSPIRV.td index f72c555921dfe..34933e889ba31 100644 --- a/clang/include/clang/Basic/BuiltinsSPIRV.td +++ b/clang/include/clang/Basic/BuiltinsSPIRV.td @@ -19,3 +19,9 @@ def SPIRVLength : Builtin { let Attributes = [NoThrow, Const]; let Prototype = "void(...)"; } + +def SPIRVReflect : Builtin { + let Spellings = ["__builtin_spirv_reflect"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index a4df7275f18dc..96d4e9732ed0e 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -20829,6 +20829,19 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned BuiltinID, /*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_length, ArrayRef{X}, nullptr, "spv.length"); } + case SPIRV::BI__builtin_spirv_reflect: { +Value *I = EmitScalarExpr(E->getArg(0)); +Value *N = EmitScalarExpr(E->getArg(1)); +assert(E->getArg(0)->getType()->hasFloatingRepresentation() && + E->getArg(1)->getType()->hasFloatingRepresentation() && + "Reflect operands must have a float representation"); +assert(E->getArg(0)->getType()->isVectorType() && + E->getArg(1)->getType()->isVectorType() && + "Reflect operands must be a vector"); +return Builder.CreateIntrinsic( +/*ReturnType=*/I->getType(), Intrinsic::spv_reflect, +ArrayRef{I, N}, nullptr, "spv.reflect"); + } } return nullptr; } diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h b/clang/lib/Headers/hlsl/hlsl_detail.h index b2c8cc6c5c3db..0d568539cd66a 100644 --- a/clang/lib/Headers/hlsl/hlsl_detail.h +++ b/clang/lib/Headers/hlsl/hlsl_detail.h @@ -79,6 +79,22 @@ constexpr enable_if_t::value || is_same::value, T> distance_vec_impl(vector X, vector Y) { return length_vec_impl(X - Y); } + +template +constexpr enable_if_t::value || is_same::value, T> +reflect_impl(T I, T N) { + return I - 2 * N * I * N; +} + +template +constexpr vector reflect_vec_impl(vector I, vector N) { +#if (__has_builtin(__builtin_spirv_reflect)) + return __builtin_spirv_reflect(I, N); +#else + return I - 2 * N * __builtin_hlsl_dot(I, N); +#endif +} + } // namespace __detail } // namespace hlsl #endif //_HLSL_HLSL_DETAILS_H_ diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index f03b620eee142..8a98dc2e515e2 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -2030,6 +2030,49 @@ double3 rcp(double3); _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp) double4 rcp(double4); +//===--===// +// reflect builtin +//===--===// + +/// \fn T reflect(T I, T N) +/// \brief Returns a reflection using an incident ray, \a I, and a surface +/// normal, \a N. +/// \param I The incident ray. +/// \param N The surface normal. +/// +/// The return value is a floating-point vector that represents the reflection +/// of the incident ray, \a I, off a surface with the normal \a
[clang] [llvm] Reapply "Reland "[HLSL] Implement the `reflect` HLSL function"" (#124046) (PR #128386)
llvmbot wrote: @llvm/pr-subscribers-hlsl @llvm/pr-subscribers-clang Author: Vitaly Buka (vitalybuka) Changes This reverts commit 0fe8e70c6609ff86cd40fbb45a85a8ed04c153c2. --- Patch is 30.02 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/128386.diff 13 Files Affected: - (modified) clang/include/clang/Basic/BuiltinsSPIRV.td (+6) - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+13) - (modified) clang/lib/Headers/hlsl/hlsl_detail.h (+16) - (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+43) - (modified) clang/lib/Sema/SemaSPIRV.cpp (+32) - (added) clang/test/CodeGenHLSL/builtins/reflect.hlsl (+177) - (added) clang/test/CodeGenSPIRV/Builtins/reflect.c (+32) - (added) clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl (+33) - (added) clang/test/SemaSPIRV/BuiltIns/reflect-errors.c (+23) - (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+1) - (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+12-4) - (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll (+33) - (added) llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll (+13) ``diff diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td b/clang/include/clang/Basic/BuiltinsSPIRV.td index f72c555921dfe..34933e889ba31 100644 --- a/clang/include/clang/Basic/BuiltinsSPIRV.td +++ b/clang/include/clang/Basic/BuiltinsSPIRV.td @@ -19,3 +19,9 @@ def SPIRVLength : Builtin { let Attributes = [NoThrow, Const]; let Prototype = "void(...)"; } + +def SPIRVReflect : Builtin { + let Spellings = ["__builtin_spirv_reflect"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index a4df7275f18dc..96d4e9732ed0e 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -20829,6 +20829,19 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned BuiltinID, /*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_length, ArrayRef{X}, nullptr, "spv.length"); } + case SPIRV::BI__builtin_spirv_reflect: { +Value *I = EmitScalarExpr(E->getArg(0)); +Value *N = EmitScalarExpr(E->getArg(1)); +assert(E->getArg(0)->getType()->hasFloatingRepresentation() && + E->getArg(1)->getType()->hasFloatingRepresentation() && + "Reflect operands must have a float representation"); +assert(E->getArg(0)->getType()->isVectorType() && + E->getArg(1)->getType()->isVectorType() && + "Reflect operands must be a vector"); +return Builder.CreateIntrinsic( +/*ReturnType=*/I->getType(), Intrinsic::spv_reflect, +ArrayRef{I, N}, nullptr, "spv.reflect"); + } } return nullptr; } diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h b/clang/lib/Headers/hlsl/hlsl_detail.h index b2c8cc6c5c3db..0d568539cd66a 100644 --- a/clang/lib/Headers/hlsl/hlsl_detail.h +++ b/clang/lib/Headers/hlsl/hlsl_detail.h @@ -79,6 +79,22 @@ constexpr enable_if_t::value || is_same::value, T> distance_vec_impl(vector X, vector Y) { return length_vec_impl(X - Y); } + +template +constexpr enable_if_t::value || is_same::value, T> +reflect_impl(T I, T N) { + return I - 2 * N * I * N; +} + +template +constexpr vector reflect_vec_impl(vector I, vector N) { +#if (__has_builtin(__builtin_spirv_reflect)) + return __builtin_spirv_reflect(I, N); +#else + return I - 2 * N * __builtin_hlsl_dot(I, N); +#endif +} + } // namespace __detail } // namespace hlsl #endif //_HLSL_HLSL_DETAILS_H_ diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index f03b620eee142..8a98dc2e515e2 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -2030,6 +2030,49 @@ double3 rcp(double3); _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp) double4 rcp(double4); +//===--===// +// reflect builtin +//===--===// + +/// \fn T reflect(T I, T N) +/// \brief Returns a reflection using an incident ray, \a I, and a surface +/// normal, \a N. +/// \param I The incident ray. +/// \param N The surface normal. +/// +/// The return value is a floating-point vector that represents the reflection +/// of the incident ray, \a I, off a surface with the normal \a N. +/// +/// This function calculates the reflection vector using the following formula: +/// V = I - 2 * N * dot(I N) . +/// +/// N must already be normalized in order to achieve the desired result. +/// +/// The operands must all be a scalar or vector whose component type is +/// floating-point. +/// +/// Result type and the type of all operands must be the same type. + +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +const inline half reflect(half I, half N) { + return __detail::reflect_impl(I, N); +} + +const inline float reflect(float I, float N) { + return __
[clang] [llvm] Reland "[HLSL] Implement the reflect HLSL function" (PR #125599)
@@ -1,6 +1,5 @@ -; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s -; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s -; UNSUPPORTED: hwasan +; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - 2>&1 | FileCheck %s vitalybuka wrote: you don't need this patch https://github.com/llvm/llvm-project/pull/128386/files passes: https://lab.llvm.org/buildbot/#/builders/55/builds/7459 https://github.com/llvm/llvm-project/pull/125599 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Reapply "Reland "[HLSL] Implement the `reflect` HLSL function"" (#124046) (PR #128386)
https://github.com/vitalybuka converted_to_draft https://github.com/llvm/llvm-project/pull/128386 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Reland "[HLSL] Implement the reflect HLSL function" (PR #125599)
https://github.com/vitalybuka approved this pull request. LGTM regarding previous HWASAN crash, which is gone https://github.com/llvm/llvm-project/pull/125599 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy][NFC] Expose HeuristicResolver::lookupDependentName() and use it in StandaloneEmptyCheck (PR #128391)
HighCommander4 wrote: > I take a look briefly about `HeuristicResolver`, it looks like not related to > other Sema parts. Is it possible to move the whole `HeuristicResolver` out of > `Sema` lib to `AST`? In future enhancements to `HeuristicResolver`, I would like to implement optional heuristics that make use of `Sema`. I envisioned the dependency on `Sema` being optional, such that clients who do have have one can continue to construct a `HeursiticResolver` without passing in a `Sema`. https://github.com/llvm/llvm-project/pull/128391 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix performance-move-const-arg false negative in ternary… (PR #128402)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: David Rivera (RiverDave) Changes This PR aims to fix `performance-move-const-arg` #126515 ## Changes Enhanced the `performance-move-arg` check in Clang-Tidy to detect cases where std::move is used in **ternary expressions which was not being detected before** ## Testing - A new mock class has been where the changes have been tested & all tests pass --- Full diff: https://github.com/llvm/llvm-project/pull/128402.diff 3 Files Affected: - (modified) clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp (+11-2) - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) - (modified) clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp (+23) ``diff diff --git a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp index 421ce003975bc..3de41e707cfd7 100644 --- a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp @@ -44,6 +44,12 @@ void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) { unless(isInTemplateInstantiation())) .bind("call-move"); + // Match ternary expressions where either branch contains std::move + auto TernaryWithMoveMatcher = + conditionalOperator( +hasDescendant(MoveCallMatcher) + ).bind("ternary-move"); + Finder->addMatcher( expr(anyOf( castExpr(hasSourceExpression(MoveCallMatcher)), @@ -58,13 +64,16 @@ void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) { qualType(rValueReferenceType()).bind("invocation-parm-type"); // Matches respective ParmVarDecl for a CallExpr or CXXConstructExpr. auto ArgumentWithParamMatcher = forEachArgumentWithParam( - MoveCallMatcher, parmVarDecl(anyOf(hasType(ConstTypeParmMatcher), + anyOf(MoveCallMatcher, TernaryWithMoveMatcher), + parmVarDecl(anyOf(hasType(ConstTypeParmMatcher), hasType(RValueTypeParmMatcher))) .bind("invocation-parm")); // Matches respective types of arguments for a CallExpr or CXXConstructExpr // and it works on calls through function pointers as well. auto ArgumentWithParamTypeMatcher = forEachArgumentWithParamType( - MoveCallMatcher, anyOf(ConstTypeParmMatcher, RValueTypeParmMatcher)); + anyOf(MoveCallMatcher, TernaryWithMoveMatcher), + anyOf(ConstTypeParmMatcher, RValueTypeParmMatcher)); + Finder->addMatcher( invocation(anyOf(ArgumentWithParamMatcher, ArgumentWithParamTypeMatcher)) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 41ff1c1016f25..2eb65d61f5e78 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -115,6 +115,10 @@ Changes in existing checks ` check by providing additional examples and fixing some macro related false positives. +- Improved :doc:`performance-move-const-arg + ` check by fixing false negatives + on ternary operators calling ``std::move``. + Removed checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp index 8e325b0ae6ca3..e616cbe78bc3a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp @@ -560,3 +560,26 @@ struct Result { // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] }; } // namespace GH111450 + +namespace GH126515 { + +struct TernaryMoveCall { +TernaryMoveCall(); +TernaryMoveCall(const TernaryMoveCall&); +TernaryMoveCall operator=(const TernaryMoveCall&); + +void TernaryCheckTriviallyCopyable(const char * c) {} + +void testTernaryMove() { + TernaryMoveCall t1; + TernaryMoveCall other(false ? TernaryMoveCall() : TernaryMoveCall(std::move(t1)) ); + // CHECK-MESSAGES: :[[@LINE-1]]:69: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] + // CHECK-MESSAGES: :[[@LINE-11]]:8: note: 'TernaryMoveCall' is not move assignable/constructible + + const char* a = "a"; + TernaryCheckTriviallyCopyable(true ? std::move(a) : "" ); + // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: std::move of the variable 'a' of the trivially-copyable type 'const char *' has no effect; remove std::move() [performance-move-const-arg] +} + +}; +} // namespace GH126515 `` https://github.com/llvm/llvm-project/pull/128402 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cf
[clang-tools-extra] [clang-tidy] Fix performance-move-const-arg false negative in ternary… (PR #128402)
https://github.com/RiverDave created https://github.com/llvm/llvm-project/pull/128402 This PR aims to fix `performance-move-const-arg` #126515 ## Changes Enhanced the `performance-move-arg` check in Clang-Tidy to detect cases where std::move is used in **ternary expressions which was not being detected before** ## Testing - A new mock class has been where the changes have been tested & all tests pass >From d9dbf1b67ec6f249656c0b4af35ea48ef29cc095 Mon Sep 17 00:00:00 2001 From: Riverdave Date: Sat, 22 Feb 2025 03:57:35 -0500 Subject: [PATCH] [clang-tidy] Fix performance-move-const-arg false negative in ternary operators --- .../performance/MoveConstArgCheck.cpp | 13 +-- clang-tools-extra/docs/ReleaseNotes.rst | 4 .../checkers/performance/move-const-arg.cpp | 23 +++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp index 421ce003975bc..3de41e707cfd7 100644 --- a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp @@ -44,6 +44,12 @@ void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) { unless(isInTemplateInstantiation())) .bind("call-move"); + // Match ternary expressions where either branch contains std::move + auto TernaryWithMoveMatcher = + conditionalOperator( +hasDescendant(MoveCallMatcher) + ).bind("ternary-move"); + Finder->addMatcher( expr(anyOf( castExpr(hasSourceExpression(MoveCallMatcher)), @@ -58,13 +64,16 @@ void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) { qualType(rValueReferenceType()).bind("invocation-parm-type"); // Matches respective ParmVarDecl for a CallExpr or CXXConstructExpr. auto ArgumentWithParamMatcher = forEachArgumentWithParam( - MoveCallMatcher, parmVarDecl(anyOf(hasType(ConstTypeParmMatcher), + anyOf(MoveCallMatcher, TernaryWithMoveMatcher), + parmVarDecl(anyOf(hasType(ConstTypeParmMatcher), hasType(RValueTypeParmMatcher))) .bind("invocation-parm")); // Matches respective types of arguments for a CallExpr or CXXConstructExpr // and it works on calls through function pointers as well. auto ArgumentWithParamTypeMatcher = forEachArgumentWithParamType( - MoveCallMatcher, anyOf(ConstTypeParmMatcher, RValueTypeParmMatcher)); + anyOf(MoveCallMatcher, TernaryWithMoveMatcher), + anyOf(ConstTypeParmMatcher, RValueTypeParmMatcher)); + Finder->addMatcher( invocation(anyOf(ArgumentWithParamMatcher, ArgumentWithParamTypeMatcher)) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 41ff1c1016f25..2eb65d61f5e78 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -115,6 +115,10 @@ Changes in existing checks ` check by providing additional examples and fixing some macro related false positives. +- Improved :doc:`performance-move-const-arg + ` check by fixing false negatives + on ternary operators calling ``std::move``. + Removed checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp index 8e325b0ae6ca3..e616cbe78bc3a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp @@ -560,3 +560,26 @@ struct Result { // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] }; } // namespace GH111450 + +namespace GH126515 { + +struct TernaryMoveCall { +TernaryMoveCall(); +TernaryMoveCall(const TernaryMoveCall&); +TernaryMoveCall operator=(const TernaryMoveCall&); + +void TernaryCheckTriviallyCopyable(const char * c) {} + +void testTernaryMove() { + TernaryMoveCall t1; + TernaryMoveCall other(false ? TernaryMoveCall() : TernaryMoveCall(std::move(t1)) ); + // CHECK-MESSAGES: :[[@LINE-1]]:69: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] + // CHECK-MESSAGES: :[[@LINE-11]]:8: note: 'TernaryMoveCall' is not move assignable/constructible + + const char* a = "a"; + TernaryCheckTriviallyCopyable(true ? std::move(a) : "" ); + // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: std::move of the variable 'a' of the trivially-copyable type 'const char *' has no effect; remove std::move() [performance-move-const-arg] +} + +}; +} // namespace GH126515 ___ cfe-commits mailing list cfe-commits@lists.llvm.org ht
[clang-tools-extra] [clang-tidy] Fix performance-move-const-arg false negative in ternary… (PR #128402)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/128402 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix performance-move-const-arg false negative in ternary… (PR #128402)
https://github.com/RiverDave edited https://github.com/llvm/llvm-project/pull/128402 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix performance-move-const-arg false negative in ternary… (PR #128402)
https://github.com/RiverDave edited https://github.com/llvm/llvm-project/pull/128402 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [polly] [DAG] shouldReduceLoadWidth - hasOneUse should check just the loaded value - not the chain (PR #128167)
@@ -1817,7 +1817,7 @@ class TargetLoweringBase { EVT NewVT) const { topperc wrote: Why not move this definition to TargetLowering.cpp? inlining the body of a virtual function is kind of silly. https://github.com/llvm/llvm-project/pull/128167 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)
https://github.com/isuckatcs updated https://github.com/llvm/llvm-project/pull/128265 >From c13cf10fe9f63c4fa361985388ab1ab6c7e55514 Mon Sep 17 00:00:00 2001 From: isuckatcs <65320245+isucka...@users.noreply.github.com> Date: Mon, 17 Feb 2025 22:50:49 +0100 Subject: [PATCH 1/5] add new check --- .../bugprone/BugproneTidyModule.cpp | 3 + .../clang-tidy/bugprone/CMakeLists.txt| 1 + .../clang-tidy/bugprone/TrueMacroCheck.cpp| 97 +++ .../clang-tidy/bugprone/TrueMacroCheck.h | 29 ++ clang-tools-extra/docs/ReleaseNotes.rst | 5 + .../clang-tidy/checks/bugprone/true-macro.rst | 6 ++ .../docs/clang-tidy/checks/list.rst | 1 + .../clang-tidy/checkers/bugprone/true-macro.c | 14 +++ 8 files changed, 156 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/true-macro.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/true-macro.c diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index c5f0b5b28418f..2893d7871a710 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -85,6 +85,7 @@ #include "TerminatingContinueCheck.h" #include "ThrowKeywordMissingCheck.h" #include "TooSmallLoopVariableCheck.h" +#include "TrueMacroCheck.h" #include "UncheckedOptionalAccessCheck.h" #include "UndefinedMemoryManipulationCheck.h" #include "UndelegatedConstructorCheck.h" @@ -247,6 +248,8 @@ class BugproneModule : public ClangTidyModule { "bugprone-throw-keyword-missing"); CheckFactories.registerCheck( "bugprone-too-small-loop-variable"); +CheckFactories.registerCheck( +"bugprone-true-macro"); CheckFactories.registerCheck( "bugprone-unchecked-optional-access"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index e8309c68b7fca..e479c3c137809 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -86,6 +86,7 @@ add_clang_library(clangTidyBugproneModule STATIC TerminatingContinueCheck.cpp ThrowKeywordMissingCheck.cpp TooSmallLoopVariableCheck.cpp + TrueMacroCheck.cpp UncheckedOptionalAccessCheck.cpp UndefinedMemoryManipulationCheck.cpp UndelegatedConstructorCheck.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp new file mode 100644 index 0..a1940a1015af1 --- /dev/null +++ b/clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp @@ -0,0 +1,97 @@ +//===--- TrueMacroCheck.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 "TrueMacroCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/MacroInfo.h" +#include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" +#include + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { +namespace { + +class MacroCallback : public PPCallbacks { + static constexpr const char *TrueMacroSpelling = "true"; + +public: + MacroCallback(TrueMacroCheck *Check, const SourceManager &SM, +Preprocessor *PP) + : Check(Check), SM(&SM), PP(PP) {} + void MacroDefined(const Token &MacroNameTok, +const MacroDirective *MD) override { +if (PP->getSpelling(MacroNameTok) == TrueMacroSpelling) + TrueDefined = true; + } + + virtual void MacroUndefined(const Token &MacroNameTok, + const MacroDefinition &MD, + const MacroDirective *Undef) override { +if (PP->getSpelling(MacroNameTok) == TrueMacroSpelling) + TrueDefined = false; + } + + virtual void If(SourceLocation Loc, SourceRange ConditionRange, + ConditionValueKind ConditionValue) override { +StringRef Condition = +Lexer::getSourceText(CharSourceRange::getTokenRange(ConditionRange), + PP->getSourceManager(), PP->getLangOpts()); + +for (auto &&Identifier : identifiersInCondition(Condition)) + std::cout << Identifier.str() << ' ' << Identifier.size() << '\n'; + } + +private: + void emitDiagnostic() {} + + std::vector identifiersInCondition(StringRef Condition) { +const static auto Start = [](char C) { + return C ==
[clang-tools-extra] [clang-tidy]improve performance-unnecessary-value-param performance (PR #128383)
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/128383 Tolerate fix-it breaking compilation when functions is used as pointers. `isReferencedOutsideOfCallExpr` will visit the whole translate unit for each matched function decls. It will waste lots of cpu time in some big cpp files. But the benefits of this validation are limited. Lots of function usage are out of current translation unit. After removing this validation step, the check profiling changes from 5.7 to 1.1 in SemaExprCXX.cpp, which is similar to version 18. >From 721393e8f1a464931884be95fef48518f8c351f1 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Sun, 23 Feb 2025 08:36:53 +0800 Subject: [PATCH] [clang-tidy]improve performance-unnecessary-value-param performance Tolerate fix-it breaking compilation when functions is used as pointers. `isReferencedOutsideOfCallExpr` will visit the whole translate unit for each matched function decls. It will waste lots of cpu time in some big cpp files. But the benefits of this validation are limited. Lots of function usage are out of current translation unit. After removing this validation step, the check profiling changes from 5.7 to 1.1 in SemaExprCXX.cpp, which is similar to version 18. --- .../performance/UnnecessaryValueParamCheck.cpp | 14 +- clang-tools-extra/docs/ReleaseNotes.rst| 5 + .../performance/unnecessary-value-param.cpp| 6 +- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp index d356f866a8804..a877f9a7ee912 100644 --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp @@ -7,7 +7,6 @@ //===--===// #include "UnnecessaryValueParamCheck.h" - #include "../utils/DeclRefExprUtils.h" #include "../utils/FixItHintUtils.h" #include "../utils/Matchers.h" @@ -30,14 +29,6 @@ std::string paramNameOrIndex(StringRef Name, size_t Index) { .str(); } -bool isReferencedOutsideOfCallExpr(const FunctionDecl &Function, - ASTContext &Context) { - auto Matches = match(declRefExpr(to(functionDecl(equalsNode(&Function))), - unless(hasAncestor(callExpr(, - Context); - return !Matches.empty(); -} - bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Decl &Decl, ASTContext &Context) { auto Matches = match( @@ -155,12 +146,9 @@ void UnnecessaryValueParamCheck::handleConstRefFix(const FunctionDecl &Function, // Do not propose fixes when: // 1. the ParmVarDecl is in a macro, since we cannot place them correctly // 2. the function is virtual as it might break overrides - // 3. the function is referenced outside of a call expression within the - //compilation unit as the signature change could introduce build errors. - // 4. the function is an explicit template/ specialization. + // 3. the function is an explicit template/ specialization. const auto *Method = llvm::dyn_cast(&Function); if (Param.getBeginLoc().isMacroID() || (Method && Method->isVirtual()) || - isReferencedOutsideOfCallExpr(Function, Context) || Function.getTemplateSpecializationKind() == TSK_ExplicitSpecialization) return; for (const auto *FunctionDecl = &Function; FunctionDecl != nullptr; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6b8fe22242417..22ed7fe07fff9 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -110,6 +110,11 @@ Changes in existing checks ` check by providing additional examples and fixing some macro related false positives. +- Improved :doc:`performance/unnecessary-value-param + ` check performance by + tolerating fix-it breaking compilation when functions is used as pointers + to avoid matching usage of functions within the current compilation unit. + Removed checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp index 7c7ae43698929..60ba7d01420b8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp @@ -332,11 +332,7 @@ void PositiveNonConstDeclaration(const ExpensiveToCopyType A) { void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) { // CHECK-MESSAGES: [[@LINE-1]]:75: warning: the parameter 'A' is copied - // CHECK-FIXES: void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCop
[clang-tools-extra] [clang-tidy]improve performance-unnecessary-value-param performance (PR #128383)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Congcong Cai (HerrCai0907) Changes Tolerate fix-it breaking compilation when functions is used as pointers. `isReferencedOutsideOfCallExpr` will visit the whole translate unit for each matched function decls. It will waste lots of cpu time in some big cpp files. But the benefits of this validation are limited. Lots of function usage are out of current translation unit. After removing this validation step, the check profiling changes from 5.7 to 1.1 in SemaExprCXX.cpp, which is similar to version 18. --- Full diff: https://github.com/llvm/llvm-project/pull/128383.diff 3 Files Affected: - (modified) clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp (+1-13) - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5) - (modified) clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp (+1-5) ``diff diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp index d356f866a8804..a877f9a7ee912 100644 --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp @@ -7,7 +7,6 @@ //===--===// #include "UnnecessaryValueParamCheck.h" - #include "../utils/DeclRefExprUtils.h" #include "../utils/FixItHintUtils.h" #include "../utils/Matchers.h" @@ -30,14 +29,6 @@ std::string paramNameOrIndex(StringRef Name, size_t Index) { .str(); } -bool isReferencedOutsideOfCallExpr(const FunctionDecl &Function, - ASTContext &Context) { - auto Matches = match(declRefExpr(to(functionDecl(equalsNode(&Function))), - unless(hasAncestor(callExpr(, - Context); - return !Matches.empty(); -} - bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Decl &Decl, ASTContext &Context) { auto Matches = match( @@ -155,12 +146,9 @@ void UnnecessaryValueParamCheck::handleConstRefFix(const FunctionDecl &Function, // Do not propose fixes when: // 1. the ParmVarDecl is in a macro, since we cannot place them correctly // 2. the function is virtual as it might break overrides - // 3. the function is referenced outside of a call expression within the - //compilation unit as the signature change could introduce build errors. - // 4. the function is an explicit template/ specialization. + // 3. the function is an explicit template/ specialization. const auto *Method = llvm::dyn_cast(&Function); if (Param.getBeginLoc().isMacroID() || (Method && Method->isVirtual()) || - isReferencedOutsideOfCallExpr(Function, Context) || Function.getTemplateSpecializationKind() == TSK_ExplicitSpecialization) return; for (const auto *FunctionDecl = &Function; FunctionDecl != nullptr; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6b8fe22242417..22ed7fe07fff9 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -110,6 +110,11 @@ Changes in existing checks ` check by providing additional examples and fixing some macro related false positives. +- Improved :doc:`performance/unnecessary-value-param + ` check performance by + tolerating fix-it breaking compilation when functions is used as pointers + to avoid matching usage of functions within the current compilation unit. + Removed checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp index 7c7ae43698929..60ba7d01420b8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp @@ -332,11 +332,7 @@ void PositiveNonConstDeclaration(const ExpensiveToCopyType A) { void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) { // CHECK-MESSAGES: [[@LINE-1]]:75: warning: the parameter 'A' is copied - // CHECK-FIXES: void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) { -} - -void ReferenceFunctionOutsideOfCallExpr() { - void (*ptr)(ExpensiveToCopyType) = &PositiveOnlyMessageAsReferencedInCompilationUnit; + // CHECK-FIXES: void PositiveOnlyMessageAsReferencedInCompilationUnit(const ExpensiveToCopyType& A) { } void PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType A) { `` https://github.com/llvm/llvm-project/pull/128383 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy][NFC] Expose HeuristicResolver::lookupDependentName() and use it in StandaloneEmptyCheck (PR #128391)
HighCommander4 wrote: > Note: this is the last remaining use of > `CXXRecordDecl::lookupDependentName()`. I plan to remove it in a follow-up > patch. The follow-up patch is https://github.com/llvm/llvm-project/pull/128392. https://github.com/llvm/llvm-project/pull/128391 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy][NFC] Expose HeuristicResolver::lookupDependentName() and use it in StandaloneEmptyCheck (PR #128391)
https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/128391 The use replaces CXXRecordDecl::lookupDependentName() which HeuristicResolver aims to supersede. >From b44bc0bb4772ff503c8d93430331606d2f2356e3 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Sat, 22 Feb 2025 22:40:01 -0500 Subject: [PATCH] [clang-tidy][NFC] Expose HeuristicResolver::lookupDependentName() and use it in StandaloneEmptyCheck The use replaces CXXRecordDecl::lookupDependentName() which HeuristicResolver aims to supersede. --- .../clang-tidy/bugprone/CMakeLists.txt | 1 + .../bugprone/StandaloneEmptyCheck.cpp | 9 + clang/include/clang/Sema/HeuristicResolver.h | 7 +++ clang/lib/Sema/HeuristicResolver.cpp | 18 -- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index e8309c68b7fca..cad6b456fc268 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -117,6 +117,7 @@ clang_target_link_libraries(clangTidyBugproneModule clangASTMatchers clangBasic clangLex + clangSema clangTooling clangTransformer ) diff --git a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp index 2bce72cca98c6..a1d7b9931e419 100644 --- a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp @@ -20,6 +20,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceLocation.h" #include "clang/Lex/Lexer.h" +#include "clang/Sema/HeuristicResolver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Casting.h" @@ -125,8 +126,8 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) { DeclarationName Name = Context.DeclarationNames.getIdentifier(&Context.Idents.get("clear")); -auto Candidates = MemberCall->getRecordDecl()->lookupDependentName( -Name, [](const NamedDecl *ND) { +auto Candidates = HeuristicResolver(Context).lookupDependentName( +MemberCall->getRecordDecl(), Name, [](const NamedDecl *ND) { return isa(ND) && llvm::cast(ND)->getMinRequiredArguments() == 0 && @@ -174,8 +175,8 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) { DeclarationName Name = Context.DeclarationNames.getIdentifier(&Context.Idents.get("clear")); -auto Candidates = -ArgRecordDecl->lookupDependentName(Name, [](const NamedDecl *ND) { +auto Candidates = HeuristicResolver(Context).lookupDependentName( +ArgRecordDecl, Name, [](const NamedDecl *ND) { return isa(ND) && llvm::cast(ND)->getMinRequiredArguments() == 0 && diff --git a/clang/include/clang/Sema/HeuristicResolver.h b/clang/include/clang/Sema/HeuristicResolver.h index 3760003aab89f..f511815b40199 100644 --- a/clang/include/clang/Sema/HeuristicResolver.h +++ b/clang/include/clang/Sema/HeuristicResolver.h @@ -69,6 +69,13 @@ class HeuristicResolver { QualType resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS) const; + // Perform an imprecise lookup of a dependent name in `RD`. + // This function does not follow strict semantic rules and should be used + // only when lookup rules can be relaxed, e.g. indexing. + std::vector + lookupDependentName(CXXRecordDecl *RD, DeclarationName Name, + llvm::function_ref Filter); + // Given the type T of a dependent expression that appears of the LHS of a // "->", heuristically find a corresponding pointee type in whose scope we // could look up the name appearing on the RHS. diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp index 3af4d001d6c1a..7aecd2a73b539 100644 --- a/clang/lib/Sema/HeuristicResolver.cpp +++ b/clang/lib/Sema/HeuristicResolver.cpp @@ -44,6 +44,9 @@ class HeuristicResolverImpl { const DependentTemplateSpecializationType *DTST); QualType resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS); QualType getPointeeType(QualType T); + std::vector + lookupDependentName(CXXRecordDecl *RD, DeclarationName Name, + llvm::function_ref Filter); private: ASTContext &Ctx; @@ -83,16 +86,6 @@ class HeuristicResolverImpl { // during simplification, and the operation fails if no pointer type is found. QualType simplifyType(QualType Type, const Expr *E, bool UnwrapPointer); - // This is a reimplementation of CXXRecordDecl::lookupDependentName() - // so that the implementation can call into other HeuristicResolver helpers. - // FIXME: Once HeuristicResolver is upstreamed to the clang libraries - // (https
[clang] [clang-tools-extra] [clang-tidy][NFC] Expose HeuristicResolver::lookupDependentName() and use it in StandaloneEmptyCheck (PR #128391)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Nathan Ridge (HighCommander4) Changes The use replaces CXXRecordDecl::lookupDependentName() which HeuristicResolver aims to supersede. --- Full diff: https://github.com/llvm/llvm-project/pull/128391.diff 4 Files Affected: - (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1) - (modified) clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp (+5-4) - (modified) clang/include/clang/Sema/HeuristicResolver.h (+7) - (modified) clang/lib/Sema/HeuristicResolver.cpp (+8-10) ``diff diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index e8309c68b7fca..cad6b456fc268 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -117,6 +117,7 @@ clang_target_link_libraries(clangTidyBugproneModule clangASTMatchers clangBasic clangLex + clangSema clangTooling clangTransformer ) diff --git a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp index 2bce72cca98c6..a1d7b9931e419 100644 --- a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp @@ -20,6 +20,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceLocation.h" #include "clang/Lex/Lexer.h" +#include "clang/Sema/HeuristicResolver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Casting.h" @@ -125,8 +126,8 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) { DeclarationName Name = Context.DeclarationNames.getIdentifier(&Context.Idents.get("clear")); -auto Candidates = MemberCall->getRecordDecl()->lookupDependentName( -Name, [](const NamedDecl *ND) { +auto Candidates = HeuristicResolver(Context).lookupDependentName( +MemberCall->getRecordDecl(), Name, [](const NamedDecl *ND) { return isa(ND) && llvm::cast(ND)->getMinRequiredArguments() == 0 && @@ -174,8 +175,8 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) { DeclarationName Name = Context.DeclarationNames.getIdentifier(&Context.Idents.get("clear")); -auto Candidates = -ArgRecordDecl->lookupDependentName(Name, [](const NamedDecl *ND) { +auto Candidates = HeuristicResolver(Context).lookupDependentName( +ArgRecordDecl, Name, [](const NamedDecl *ND) { return isa(ND) && llvm::cast(ND)->getMinRequiredArguments() == 0 && diff --git a/clang/include/clang/Sema/HeuristicResolver.h b/clang/include/clang/Sema/HeuristicResolver.h index 3760003aab89f..f511815b40199 100644 --- a/clang/include/clang/Sema/HeuristicResolver.h +++ b/clang/include/clang/Sema/HeuristicResolver.h @@ -69,6 +69,13 @@ class HeuristicResolver { QualType resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS) const; + // Perform an imprecise lookup of a dependent name in `RD`. + // This function does not follow strict semantic rules and should be used + // only when lookup rules can be relaxed, e.g. indexing. + std::vector + lookupDependentName(CXXRecordDecl *RD, DeclarationName Name, + llvm::function_ref Filter); + // Given the type T of a dependent expression that appears of the LHS of a // "->", heuristically find a corresponding pointee type in whose scope we // could look up the name appearing on the RHS. diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp index 3af4d001d6c1a..7aecd2a73b539 100644 --- a/clang/lib/Sema/HeuristicResolver.cpp +++ b/clang/lib/Sema/HeuristicResolver.cpp @@ -44,6 +44,9 @@ class HeuristicResolverImpl { const DependentTemplateSpecializationType *DTST); QualType resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS); QualType getPointeeType(QualType T); + std::vector + lookupDependentName(CXXRecordDecl *RD, DeclarationName Name, + llvm::function_ref Filter); private: ASTContext &Ctx; @@ -83,16 +86,6 @@ class HeuristicResolverImpl { // during simplification, and the operation fails if no pointer type is found. QualType simplifyType(QualType Type, const Expr *E, bool UnwrapPointer); - // This is a reimplementation of CXXRecordDecl::lookupDependentName() - // so that the implementation can call into other HeuristicResolver helpers. - // FIXME: Once HeuristicResolver is upstreamed to the clang libraries - // (https://github.com/clangd/clangd/discussions/1662), - // CXXRecordDecl::lookupDepenedentName() can be removed, and its call sites - // can be modified to benefit from the more comprehensive heuristics offered - // by HeuristicResolver instead. - std::vector - looku
[clang] [clang-tools-extra] [clang-tidy][NFC] Expose HeuristicResolver::lookupDependentName() and use it in StandaloneEmptyCheck (PR #128391)
HighCommander4 wrote: Note: this is the last remaining use of `CXXRecordDecl::lookupDependentName()`. I plan to remove it in a follow-up patch. https://github.com/llvm/llvm-project/pull/128391 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-offload-packager] Avoid repeated hash lookups (NFC) (PR #128297)
https://github.com/nikic approved this pull request. https://github.com/llvm/llvm-project/pull/128297 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)
vbvictor wrote: @PiotrZSL, @denzor200 I think we should provide 100% valid fix-its for default `SmartPointers`. That will be `std::shared_ptr`, `std::unique_ptr`, `boost::shared_ptr`. I created a note in docs that warns users about inconvenience that can happen when non-default smart pointers are specified. May you please review one more time. If everything is good i'd need help in merging this pr since i don't have write access to main https://github.com/llvm/llvm-project/pull/121291 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FatLTO] Detect LLD linker more reliably (PR #128285)
@@ -862,13 +862,12 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, const llvm::Triple &Triple = ToolChain.getTriple(); thevinster wrote: I can restore the original behavior on the linker path plus the additional check on -fuse-ld=. This would at least solve our use case if that's what you're suggesting here. https://github.com/llvm/llvm-project/pull/128285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CMake] Fix some breakages when using ninja multi config (PR #65451)
https://github.com/ur4t updated https://github.com/llvm/llvm-project/pull/65451 >From 1555d9e1af70b87885e2ae060bf7215f12cbdf89 Mon Sep 17 00:00:00 2001 From: ur4t Date: Sat, 22 Feb 2025 17:34:22 +0800 Subject: [PATCH 1/2] [llvm][CMake] Fix llvm shared library when using ninja multi config --- llvm/tools/llvm-shlib/CMakeLists.txt | 25 + 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt index ede3c5034e045..a5b0cab0f1ce5 100644 --- a/llvm/tools/llvm-shlib/CMakeLists.txt +++ b/llvm/tools/llvm-shlib/CMakeLists.txt @@ -45,10 +45,19 @@ if(LLVM_BUILD_LLVM_DYLIB) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") set(LIB_NAMES -Wl,-all_load ${LIB_NAMES}) else() -configure_file( -${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in -${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map) - +if("${CMAKE_CFG_INTDIR}" STREQUAL ".") + configure_file( +${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in +${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map) +else() + foreach(BUILD_MODE ${CMAKE_CONFIGURATION_TYPES}) +# Replace the special string with a per config directory. +string(REPLACE ${CMAKE_CFG_INTDIR} ${BUILD_MODE} PER_CONF_LIBRARY_DIR ${LLVM_LIBRARY_DIR}) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in + ${PER_CONF_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map) + endforeach() +endif() if(MSVC) target_link_directories(LLVM PRIVATE ${LLVM_LIBRARY_DIR}) foreach(library ${LIB_NAMES}) @@ -156,7 +165,10 @@ if(LLVM_BUILD_LLVM_C_DYLIB AND MSVC) # Need to separate lib names with newlines. string(REPLACE ";" "\n" FILE_CONTENT "${FULL_LIB_NAMES}") - if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") + if("${CMAKE_CFG_INTDIR}" STREQUAL ".") +# Write out the full lib names into file to be read by the python script. +file(WRITE ${LIBSFILE} "${FILE_CONTENT}") + else() foreach(BUILD_MODE ${CMAKE_CONFIGURATION_TYPES}) # Replace the special string with a per config directory. string(REPLACE ${CMAKE_CFG_INTDIR} ${BUILD_MODE} PER_CONF_CONTENT "${FILE_CONTENT}") @@ -166,9 +178,6 @@ if(LLVM_BUILD_LLVM_C_DYLIB AND MSVC) # ${CMAKE_CFG_INTDIR} correctly and select the right one. file(WRITE ${LLVM_BINARY_DIR}/${BUILD_MODE}/libllvm-c.args "${PER_CONF_CONTENT}") endforeach() - else() -# Write out the full lib names into file to be read by the python script. -file(WRITE ${LIBSFILE} "${FILE_CONTENT}") endif() # Generate the exports file dynamically. >From a14d24744ecdd2d948d80a51f026618e381589ff Mon Sep 17 00:00:00 2001 From: ur4t Date: Sat, 22 Feb 2025 17:34:34 +0800 Subject: [PATCH 2/2] [clang][CMake] Fix clang headers when using ninja multi config --- clang/lib/Headers/CMakeLists.txt | 25 +++-- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt index 43124111b7ba5..a3a505bcb7f88 100644 --- a/clang/lib/Headers/CMakeLists.txt +++ b/clang/lib/Headers/CMakeLists.txt @@ -395,12 +395,25 @@ set(riscv_generated_files) function(copy_header_to_output_dir src_dir file) set(src ${src_dir}/${file}) - set(dst ${output_dir}/${file}) - add_custom_command(OUTPUT ${dst} -DEPENDS ${src} -COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} -COMMENT "Copying clang's ${file}...") - list(APPEND out_files ${dst}) + if("${CMAKE_CFG_INTDIR}" STREQUAL ".") +set(dst ${output_dir}/${file}) +add_custom_command(OUTPUT ${dst} + DEPENDS ${src} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} + COMMENT "Copying clang's ${file}...") +list(APPEND out_files ${dst}) + else() +foreach(BUILD_MODE ${CMAKE_CONFIGURATION_TYPES}) + # Replace the special string with a per config directory. + string(REPLACE ${CMAKE_CFG_INTDIR} ${BUILD_MODE} per_conf_output_dir ${output_dir}) + set(dst ${per_conf_output_dir}/${file}) + add_custom_command(OUTPUT ${dst} +DEPENDS ${src} +COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} +COMMENT "Copying clang's ${file}...") + list(APPEND out_files ${dst}) +endforeach() + endif() set(out_files ${out_files} PARENT_SCOPE) endfunction(copy_header_to_output_dir) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CMake] Fix some breakages when using ninja multi config (PR #65451)
ur4t wrote: @MaskRay I have unselected the hidden email feature and updated the branch. Is it necessary to reset email of my old commits? https://github.com/llvm/llvm-project/pull/65451 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86] Allow using the lzcnt intrinsics for non-LZCNT targets (PR #128284)
@@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +lzcnt -emit-llvm -o - | FileCheck %s -// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +lzcnt -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s RKSimon wrote: Add a comment explaining that these will lower correctly with/without lzcnt https://github.com/llvm/llvm-project/pull/128284 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] bac4171 - Remove xbegin and _xend (#126952)
Author: Devon Loehr Date: 2025-02-22T16:46:08+08:00 New Revision: bac4171073399352e5bd0ba541820e2a9b3f37d7 URL: https://github.com/llvm/llvm-project/commit/bac4171073399352e5bd0ba541820e2a9b3f37d7 DIFF: https://github.com/llvm/llvm-project/commit/bac4171073399352e5bd0ba541820e2a9b3f37d7.diff LOG: Remove xbegin and _xend (#126952) `intrin.h` contains declarations for both `xbegin` and `_xend`, but they should already be included transitively from `rtmintrin.h` via `immintrin.h` and/or `x86intrin.h`. Having them in both places causes problems if both headers are included. Furthermore, the `intrin.h` declaration of `xbegin` seems to be bugged anyway, since it's missing its leading underscore. Fixes #95133 Added: clang/test/Headers/no-xend.cpp Modified: clang/lib/Headers/intrin.h Removed: diff --git a/clang/lib/Headers/intrin.h b/clang/lib/Headers/intrin.h index 376046aeeaf5e..3dd1eb45817d4 100644 --- a/clang/lib/Headers/intrin.h +++ b/clang/lib/Headers/intrin.h @@ -162,8 +162,6 @@ void _Store_HLERelease(long volatile *, long); void _Store64_HLERelease(__int64 volatile *, __int64); void _StorePointer_HLERelease(void *volatile *, void *); void _WriteBarrier(void); -unsigned __int32 xbegin(void); -void _xend(void); /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */ #if defined(__x86_64__) && !defined(__arm64ec__) diff --git a/clang/test/Headers/no-xend.cpp b/clang/test/Headers/no-xend.cpp new file mode 100644 index 0..b2fb1de011557 --- /dev/null +++ b/clang/test/Headers/no-xend.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-pc-win32 \ +// RUN: -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ +// RUN: -ffreestanding -fsyntax-only -Werror -Wsystem-headers \ +// RUN: -isystem %S/Inputs/include %s + +#include + +#pragma clang attribute push(__attribute__((target("avx"))), apply_to=function) +#include +#pragma clang attribute pop ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refine TimeTrace name for dispatchWorkItem (PR #128352)
https://github.com/steakhal created https://github.com/llvm/llvm-project/pull/128352 Fixes https://github.com/llvm/llvm-project/pull/125508#discussion_r1965038954 >From ff647449a2eb0c5ac4930e86e53c02a04ac78ec3 Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Sat, 22 Feb 2025 12:40:31 +0100 Subject: [PATCH] [analyzer] Refine TimeTrace name for dispatchWorkItem Fixes https://github.com/llvm/llvm-project/pull/125508#discussion_r1965038954 --- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp | 2 +- clang/test/Analysis/ftime-trace.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp index bf1fd7c2356dc..d96211c3a6635 100644 --- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -183,7 +183,7 @@ bool CoreEngine::ExecuteWorkList(const LocationContext *L, unsigned MaxSteps, static std::string timeTraceScopeName(const ProgramPoint &Loc) { if (llvm::timeTraceProfilerEnabled()) { -return llvm::formatv("Loc {0}", +return llvm::formatv("dispatchWorkItem {0}", ProgramPoint::getProgramPointKindName(Loc.getKind())) .str(); } diff --git a/clang/test/Analysis/ftime-trace.cpp b/clang/test/Analysis/ftime-trace.cpp index 2c369a9bf781e..2940ff2e02891 100644 --- a/clang/test/Analysis/ftime-trace.cpp +++ b/clang/test/Analysis/ftime-trace.cpp @@ -23,7 +23,7 @@ // The trace also contains durations of each step, but they are so short that they are not reliably present // in each run. However, they are also aggregated into Total *, for example: // -// CHECK: "name": "Total Loc PostStmt", +// CHECK: "name": "Total dispatchWorkItem PostStmt", // CHECK-NEXT: "args": { // CHECK-NEXT: "count": {{[0-9]+}}, // CHECK-NEXT: "avg ms": {{[0-9]+}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refine TimeTrace name for dispatchWorkItem (PR #128352)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Balazs Benics (steakhal) Changes Fixes https://github.com/llvm/llvm-project/pull/125508#discussion_r1965038954 --- Full diff: https://github.com/llvm/llvm-project/pull/128352.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/CoreEngine.cpp (+1-1) - (modified) clang/test/Analysis/ftime-trace.cpp (+1-1) ``diff diff --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp index bf1fd7c2356dc..d96211c3a6635 100644 --- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -183,7 +183,7 @@ bool CoreEngine::ExecuteWorkList(const LocationContext *L, unsigned MaxSteps, static std::string timeTraceScopeName(const ProgramPoint &Loc) { if (llvm::timeTraceProfilerEnabled()) { -return llvm::formatv("Loc {0}", +return llvm::formatv("dispatchWorkItem {0}", ProgramPoint::getProgramPointKindName(Loc.getKind())) .str(); } diff --git a/clang/test/Analysis/ftime-trace.cpp b/clang/test/Analysis/ftime-trace.cpp index 2c369a9bf781e..2940ff2e02891 100644 --- a/clang/test/Analysis/ftime-trace.cpp +++ b/clang/test/Analysis/ftime-trace.cpp @@ -23,7 +23,7 @@ // The trace also contains durations of each step, but they are so short that they are not reliably present // in each run. However, they are also aggregated into Total *, for example: // -// CHECK: "name": "Total Loc PostStmt", +// CHECK: "name": "Total dispatchWorkItem PostStmt", // CHECK-NEXT: "args": { // CHECK-NEXT: "count": {{[0-9]+}}, // CHECK-NEXT: "avg ms": {{[0-9]+}} `` https://github.com/llvm/llvm-project/pull/128352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refine TimeTrace name for dispatchWorkItem (PR #128352)
steakhal wrote: @necto https://github.com/llvm/llvm-project/pull/128352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][HIP] Make some math not not work with AMDGCN SPIR-V (PR #128360)
@@ -14,6 +14,12 @@ #include "hip/hip_version.h" #endif // __has_include("hip/hip_version.h") +#ifdef __SPIRV__ +#define __PRIVATE_AS __attribute__((address_space(0))) arsenm wrote: Using opencl_private is the simpler fix. You are calling code declared and defined in OpenCL, with the private address. Without a specific example of why this does not work out of the box, I insist you just go straight to using it https://github.com/llvm/llvm-project/pull/128360 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC][docs] Use single tick for 'false' and 'true' values in options (PR #128362)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Baranov Victor (vbvictor) Changes Unify doc style for options that use `true` or `false` as default values. --- Full diff: https://github.com/llvm/llvm-project/pull/128362.diff 3 Files Affected: - (modified) clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst (+3-3) - (modified) clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst (+1-1) - (modified) clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst (+1-1) ``diff diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst index 117310d404f6f..efa77925a3fe6 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst @@ -37,20 +37,20 @@ Options .. option:: UseCXXStaticCastsInCppSources When suggesting fix-its for C++ code, should C++-style ``static_cast<>()``'s - be suggested, or C-style casts. Defaults to ``true``. + be suggested, or C-style casts. Defaults to `true`. .. option:: UseCXXHeadersInCppSources When suggesting to include the appropriate header in C++ code, should header be suggested, or . - Defaults to ``true``. + Defaults to `true`. .. option:: IgnoreConstantIntExpr If the multiplication operands are compile-time constants (like literals or are ``constexpr``) and fit within the source expression type, do not emit a diagnostic or suggested fix. Only considers expressions where the source - expression is a signed integer type. Defaults to ``false``. + expression is a signed integer type. Defaults to `false`. Examples: diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst index c1414ec5e086d..9bcc5f9c3823c 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst @@ -190,7 +190,7 @@ This check is an alias of check :doc:`bugprone-unused-return-value <../bugprone/ with a fixed set of functions. Suppressing issues by casting to ``void`` is enabled by default and can be -disabled by setting `AllowCastToVoid` option to ``false``. +disabled by setting `AllowCastToVoid` option to `false`. The check corresponds to a part of CERT C Coding Standard rule `ERR33-C. Detect and handle standard library errors diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst index 9aa655feb5338..0c423edca1822 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst @@ -144,7 +144,7 @@ lives. When set to true convert loops when in C++20 or later mode using ``std::ranges::reverse_view``. - Default value is ``true``. + Default value is `true`. .. option:: MakeReverseRangeFunction `` https://github.com/llvm/llvm-project/pull/128362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC][docs] Use single tick for 'false' and 'true' values in options (PR #128362)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy Author: Baranov Victor (vbvictor) Changes Unify doc style for options that use `true` or `false` as default values. --- Full diff: https://github.com/llvm/llvm-project/pull/128362.diff 3 Files Affected: - (modified) clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst (+3-3) - (modified) clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst (+1-1) - (modified) clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst (+1-1) ``diff diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst index 117310d404f6f..efa77925a3fe6 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst @@ -37,20 +37,20 @@ Options .. option:: UseCXXStaticCastsInCppSources When suggesting fix-its for C++ code, should C++-style ``static_cast<>()``'s - be suggested, or C-style casts. Defaults to ``true``. + be suggested, or C-style casts. Defaults to `true`. .. option:: UseCXXHeadersInCppSources When suggesting to include the appropriate header in C++ code, should header be suggested, or . - Defaults to ``true``. + Defaults to `true`. .. option:: IgnoreConstantIntExpr If the multiplication operands are compile-time constants (like literals or are ``constexpr``) and fit within the source expression type, do not emit a diagnostic or suggested fix. Only considers expressions where the source - expression is a signed integer type. Defaults to ``false``. + expression is a signed integer type. Defaults to `false`. Examples: diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst index c1414ec5e086d..9bcc5f9c3823c 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst @@ -190,7 +190,7 @@ This check is an alias of check :doc:`bugprone-unused-return-value <../bugprone/ with a fixed set of functions. Suppressing issues by casting to ``void`` is enabled by default and can be -disabled by setting `AllowCastToVoid` option to ``false``. +disabled by setting `AllowCastToVoid` option to `false`. The check corresponds to a part of CERT C Coding Standard rule `ERR33-C. Detect and handle standard library errors diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst index 9aa655feb5338..0c423edca1822 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst @@ -144,7 +144,7 @@ lives. When set to true convert loops when in C++20 or later mode using ``std::ranges::reverse_view``. - Default value is ``true``. + Default value is `true`. .. option:: MakeReverseRangeFunction `` https://github.com/llvm/llvm-project/pull/128362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC][docs] Use single tick for 'false' and 'true' values in options (PR #128362)
https://github.com/vbvictor created https://github.com/llvm/llvm-project/pull/128362 Unify doc style for options that use `true` or `false` as default values. >From 41807b8f379a19714fb89b2f13bc3af389c44ac0 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Sat, 22 Feb 2025 17:26:52 +0300 Subject: [PATCH] [clang-tidy][NFC][docs] use single tics instead of double for default values --- .../bugprone/implicit-widening-of-multiplication-result.rst | 6 +++--- clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst | 2 +- .../docs/clang-tidy/checks/modernize/loop-convert.rst | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst index 117310d404f6f..efa77925a3fe6 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst @@ -37,20 +37,20 @@ Options .. option:: UseCXXStaticCastsInCppSources When suggesting fix-its for C++ code, should C++-style ``static_cast<>()``'s - be suggested, or C-style casts. Defaults to ``true``. + be suggested, or C-style casts. Defaults to `true`. .. option:: UseCXXHeadersInCppSources When suggesting to include the appropriate header in C++ code, should header be suggested, or . - Defaults to ``true``. + Defaults to `true`. .. option:: IgnoreConstantIntExpr If the multiplication operands are compile-time constants (like literals or are ``constexpr``) and fit within the source expression type, do not emit a diagnostic or suggested fix. Only considers expressions where the source - expression is a signed integer type. Defaults to ``false``. + expression is a signed integer type. Defaults to `false`. Examples: diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst index c1414ec5e086d..9bcc5f9c3823c 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst @@ -190,7 +190,7 @@ This check is an alias of check :doc:`bugprone-unused-return-value <../bugprone/ with a fixed set of functions. Suppressing issues by casting to ``void`` is enabled by default and can be -disabled by setting `AllowCastToVoid` option to ``false``. +disabled by setting `AllowCastToVoid` option to `false`. The check corresponds to a part of CERT C Coding Standard rule `ERR33-C. Detect and handle standard library errors diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst index 9aa655feb5338..0c423edca1822 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst @@ -144,7 +144,7 @@ lives. When set to true convert loops when in C++20 or later mode using ``std::ranges::reverse_view``. - Default value is ``true``. + Default value is `true`. .. option:: MakeReverseRangeFunction ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC][docs] Use single tick for 'false' and 'true' values in options (PR #128362)
vbvictor wrote: @EugeneZelenko @HerrCai0907, Small change to docs of some checks. https://github.com/llvm/llvm-project/pull/128362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add new check `readability-use-numeric-limits` (PR #127430)
@@ -0,0 +1,84 @@ +// RUN: %check_clang_tidy %s readability-use-numeric-limits %t +#include + +void constants() { + // CHECK-MESSAGES: :[[@LINE+2]]:14: warning: The constant -128 is being utilized. Consider using std::numeric_limits::min() instead [readability-use-numeric-limits] + // CHECK-FIXES: int8_t a = std::numeric_limits::min(); + int8_t a = -128; + + // CHECK-MESSAGES: :[[@LINE+2]]:14: warning: The constant 127 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int8_t b = std::numeric_limits::max(); + int8_t b = +127; + + // CHECK-MESSAGES: :[[@LINE+2]]:14: warning: The constant 127 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int8_t c = std::numeric_limits::max(); + int8_t c = 127; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant -32768 is being utilized. Consider using std::numeric_limits::min() instead [readability-use-numeric-limits] + // CHECK-FIXES: int16_t d = std::numeric_limits::min(); + int16_t d = -32768; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 32767 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int16_t e = std::numeric_limits::max(); + int16_t e = +32767; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 32767 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int16_t f = std::numeric_limits::max(); + int16_t f = 32767; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant -2147483648 is being utilized. Consider using std::numeric_limits::min() instead [readability-use-numeric-limits] + // CHECK-FIXES: int32_t g = std::numeric_limits::min(); + int32_t g = -2147483648; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 2147483647 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int32_t h = std::numeric_limits::max(); + int32_t h = +2147483647; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 2147483647 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int32_t i = std::numeric_limits::max(); + int32_t i = 2147483647; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant -9223372036854775808 is being utilized. Consider using std::numeric_limits::min() instead [readability-use-numeric-limits] + // CHECK-FIXES: int64_t j = std::numeric_limits::min(); + int64_t j = -9223372036854775808; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 9223372036854775807 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int64_t k = std::numeric_limits::max(); + int64_t k = +9223372036854775807; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 9223372036854775807 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int64_t l = std::numeric_limits::max(); + int64_t l = 9223372036854775807; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 255 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint8_t m = std::numeric_limits::max(); + uint8_t m = 255; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 255 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint8_t n = std::numeric_limits::max(); + uint8_t n = +255; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 65535 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint16_t o = std::numeric_limits::max(); + uint16_t o = 65535; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 65535 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint16_t p = std::numeric_limits::max(); + uint16_t p = +65535; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 4294967295 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint32_t q = std::numeric_limits::max(); + uint32_t q = 4294967295; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 4294967295 is being utilized. Consider using std::numeric_limits::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint32_t r = std::numeric_limits::max(); + uint32_t r = +4294967295; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 18446744073709551615 is being utilized. Consider using std::numeric_limits::max() instead [readabilit
[clang-tools-extra] [clang-tidy][NFC][docs] Use single tick for 'false' and 'true' values in options (PR #128362)
https://github.com/EugeneZelenko approved this pull request. https://github.com/llvm/llvm-project/pull/128362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [emacs] Check for a 'buffer' type instead of 'buffer-live' (PR #128385)
https://github.com/jroimartin created https://github.com/llvm/llvm-project/pull/128385 This is a follow-up to commit f69110dcc973 ("Check for a 'buffer' type instead of 'buffer-live'."). In Emacs 29, 'buffer-live' is no longer recognized as a type and generates a compilation warning. Every function that requires a live buffer already checks whether the buffer is live, so we don't need to check ourselves. >From 0c53396e1d1f5e21aa56b69ec87cf3c81cc02b0d Mon Sep 17 00:00:00 2001 From: Roi Martin Date: Sun, 23 Feb 2025 02:02:29 +0100 Subject: [PATCH] [emacs] Check for a 'buffer' type instead of 'buffer-live' This is a follow-up to commit f69110dcc973 ("Check for a 'buffer' type instead of 'buffer-live'."). In Emacs 29, 'buffer-live' is no longer recognized as a type and generates a compilation warning. Every function that requires a live buffer already checks whether the buffer is live, so we don't need to check ourselves. --- .../clang-include-fixer/tool/clang-include-fixer.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el b/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el index f3a949f8c1b55..1cb9a0340b5e3 100644 --- a/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el +++ b/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el @@ -249,7 +249,7 @@ Add a missing header if there is any. If there are multiple possible headers the user can select one of them to be included. Temporarily highlight the affected symbols. Asynchronously call clang-include-fixer to insert the selected header." - (cl-check-type stdout buffer-live) + (cl-check-type stdout buffer) (let ((context (clang-include-fixer--parse-json stdout))) (let-alist context (cond ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add clang atomic control options and attribute (PR #114841)
@@ -1101,6 +1107,187 @@ inline void FPOptions::applyChanges(FPOptionsOverride FPO) { *this = FPO.applyOverrides(*this); } +// The three atomic code-generation options. +// The canonical (positive) names are: +// "remote_memory", "fine_grained_memory", and "ignore_denormal_mode". +// In attribute or command-line parsing, a token prefixed with "no_" inverts its +// value. +enum class AtomicOptionKind { + RemoteMemory, // true means remote memory is enabled. + FineGrainedMemory, // true means fine-grained memory is enabled. + IgnoreDenormalMode, // true means ignore floating-point denormals. + LANGOPT_ATOMIC_OPTION_LAST +}; + +struct AtomicOptions { + // Bitfields for each option. + unsigned remote_memory : 1; + unsigned fine_grained_memory : 1; + unsigned ignore_denormal_mode : 1; + + AtomicOptions() + : remote_memory(0), fine_grained_memory(0), ignore_denormal_mode(0) {} + + bool getOption(AtomicOptionKind Kind) const { +switch (Kind) { +case AtomicOptionKind::RemoteMemory: + return remote_memory; +case AtomicOptionKind::FineGrainedMemory: + return fine_grained_memory; +case AtomicOptionKind::IgnoreDenormalMode: + return ignore_denormal_mode; +default: + llvm_unreachable("Invalid AtomicOptionKind"); +} + } + + void setOption(AtomicOptionKind Kind, bool Value) { +switch (Kind) { +case AtomicOptionKind::RemoteMemory: + remote_memory = Value; + break; +case AtomicOptionKind::FineGrainedMemory: + fine_grained_memory = Value; + break; +case AtomicOptionKind::IgnoreDenormalMode: + ignore_denormal_mode = Value; + break; +default: + llvm_unreachable("Invalid AtomicOptionKind"); +} + } + + LLVM_DUMP_METHOD void dump() const { +llvm::errs() << "\n remote_memory: " << remote_memory + << "\n fine_grained_memory: " << fine_grained_memory + << "\n ignore_denormal_mode: " << ignore_denormal_mode << "\n"; + } + + // The canonical names for each option. + static constexpr const char *OptionNames[] = { yxsamliu wrote: yes. will do https://github.com/llvm/llvm-project/pull/114841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy][NFC] Expose HeuristicResolver::lookupDependentName() and use it in StandaloneEmptyCheck (PR #128391)
https://github.com/HerrCai0907 approved this pull request. LGTM as temporary solution But clang-tidy actually do not want to reply on `Sema`. I take a look briefly about `HeuristicResolver`, it looks like not related to other Sema parts. Is it possible to move the whole `HeuristicResolver` out of `Sema` lib to `AST`? https://github.com/llvm/llvm-project/pull/128391 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)
https://github.com/isuckatcs updated https://github.com/llvm/llvm-project/pull/128265 >From c13cf10fe9f63c4fa361985388ab1ab6c7e55514 Mon Sep 17 00:00:00 2001 From: isuckatcs <65320245+isucka...@users.noreply.github.com> Date: Mon, 17 Feb 2025 22:50:49 +0100 Subject: [PATCH 1/5] add new check --- .../bugprone/BugproneTidyModule.cpp | 3 + .../clang-tidy/bugprone/CMakeLists.txt| 1 + .../clang-tidy/bugprone/TrueMacroCheck.cpp| 97 +++ .../clang-tidy/bugprone/TrueMacroCheck.h | 29 ++ clang-tools-extra/docs/ReleaseNotes.rst | 5 + .../clang-tidy/checks/bugprone/true-macro.rst | 6 ++ .../docs/clang-tidy/checks/list.rst | 1 + .../clang-tidy/checkers/bugprone/true-macro.c | 14 +++ 8 files changed, 156 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/true-macro.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/true-macro.c diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index c5f0b5b28418f..2893d7871a710 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -85,6 +85,7 @@ #include "TerminatingContinueCheck.h" #include "ThrowKeywordMissingCheck.h" #include "TooSmallLoopVariableCheck.h" +#include "TrueMacroCheck.h" #include "UncheckedOptionalAccessCheck.h" #include "UndefinedMemoryManipulationCheck.h" #include "UndelegatedConstructorCheck.h" @@ -247,6 +248,8 @@ class BugproneModule : public ClangTidyModule { "bugprone-throw-keyword-missing"); CheckFactories.registerCheck( "bugprone-too-small-loop-variable"); +CheckFactories.registerCheck( +"bugprone-true-macro"); CheckFactories.registerCheck( "bugprone-unchecked-optional-access"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index e8309c68b7fca..e479c3c137809 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -86,6 +86,7 @@ add_clang_library(clangTidyBugproneModule STATIC TerminatingContinueCheck.cpp ThrowKeywordMissingCheck.cpp TooSmallLoopVariableCheck.cpp + TrueMacroCheck.cpp UncheckedOptionalAccessCheck.cpp UndefinedMemoryManipulationCheck.cpp UndelegatedConstructorCheck.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp new file mode 100644 index 0..a1940a1015af1 --- /dev/null +++ b/clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp @@ -0,0 +1,97 @@ +//===--- TrueMacroCheck.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 "TrueMacroCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/MacroInfo.h" +#include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" +#include + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { +namespace { + +class MacroCallback : public PPCallbacks { + static constexpr const char *TrueMacroSpelling = "true"; + +public: + MacroCallback(TrueMacroCheck *Check, const SourceManager &SM, +Preprocessor *PP) + : Check(Check), SM(&SM), PP(PP) {} + void MacroDefined(const Token &MacroNameTok, +const MacroDirective *MD) override { +if (PP->getSpelling(MacroNameTok) == TrueMacroSpelling) + TrueDefined = true; + } + + virtual void MacroUndefined(const Token &MacroNameTok, + const MacroDefinition &MD, + const MacroDirective *Undef) override { +if (PP->getSpelling(MacroNameTok) == TrueMacroSpelling) + TrueDefined = false; + } + + virtual void If(SourceLocation Loc, SourceRange ConditionRange, + ConditionValueKind ConditionValue) override { +StringRef Condition = +Lexer::getSourceText(CharSourceRange::getTokenRange(ConditionRange), + PP->getSourceManager(), PP->getLangOpts()); + +for (auto &&Identifier : identifiersInCondition(Condition)) + std::cout << Identifier.str() << ' ' << Identifier.size() << '\n'; + } + +private: + void emitDiagnostic() {} + + std::vector identifiersInCondition(StringRef Condition) { +const static auto Start = [](char C) { + return C ==
[clang] [analyzer] Fix use after scope after #123003 (PR #128372)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-cmake-x86_64-avx512-win` running on `avx512-intel64-win` while building `clang` at step 6 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/81/builds/5023 Here is the relevant piece of the build log for the reference ``` Step 6 (ninja check 1) failure: stage 1 checked (failure) TEST 'Clang :: Driver/offload-Xarch.c' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 3 d:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\clang.exe --target=x86_64-unknown-linux-gnu -x cuda D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c -Xarch_nvptx64 -O3 -S -nogpulib -nogpuinc -### 2>&1 | d:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\filecheck.exe -check-prefix=O3ONCE D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c # executed command: 'd:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\clang.exe' --target=x86_64-unknown-linux-gnu -x cuda 'D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c' -Xarch_nvptx64 -O3 -S -nogpulib -nogpuinc '-###' # executed command: 'd:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\filecheck.exe' -check-prefix=O3ONCE 'D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c' # RUN: at line 4 d:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\clang.exe -x cuda D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c -Xarch_device -O3 -S -nogpulib -nogpuinc -### 2>&1 | d:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\filecheck.exe -check-prefix=O3ONCE D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c # executed command: 'd:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\clang.exe' -x cuda 'D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c' -Xarch_device -O3 -S -nogpulib -nogpuinc '-###' # executed command: 'd:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\filecheck.exe' -check-prefix=O3ONCE 'D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c' # RUN: at line 5 d:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\clang.exe -x hip D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c -Xarch_amdgcn -O3 -S -nogpulib -nogpuinc -### 2>&1 | d:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\filecheck.exe -check-prefix=O3ONCE D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c # executed command: 'd:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\clang.exe' -x hip 'D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c' -Xarch_amdgcn -O3 -S -nogpulib -nogpuinc '-###' # executed command: 'd:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\filecheck.exe' -check-prefix=O3ONCE 'D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c' # RUN: at line 6 d:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\clang.exe -fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib -nogpuinc -Xarch_amdgcn -march=gfx90a -Xarch_amdgcn -O3 -S -### D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c 2>&1 | d:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\filecheck.exe -check-prefix=O3ONCE D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c # executed command: 'd:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\clang.exe' -fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib -nogpuinc -Xarch_amdgcn -march=gfx90a -Xarch_amdgcn -O3 -S '-###' 'D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c' # executed command: 'd:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\filecheck.exe' -check-prefix=O3ONCE 'D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c' # RUN: at line 9 d:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\clang.exe -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -nogpulib -nogpuinc -Xarch_nvptx64 -march=sm_52 -Xarch_nvptx64 -O3 -S -### D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c 2>&1 | d:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\stage1\bin\filecheck.exe -check-prefix=O3ONCE D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\clang\test\Driver\offload-Xarch.c # executed command: 'd:\buildbot\llvm-worker\clang-cmake-x8
[clang] [Clang][analyzer] replace Stmt* with ConstCFGElementRef in SymbolConjured (PR #128251)
@@ -867,18 +868,18 @@ ProgramStateRef createContainerBegin(ProgramStateRef State, return setContainerData(State, Cont, CData); } -ProgramStateRef createContainerEnd(ProgramStateRef State, const MemRegion *Cont, - const Expr *E, QualType T, - const LocationContext *LCtx, +ProgramStateRef createContainerEnd(CheckerContext &C, ProgramStateRef State, + const MemRegion *Cont, const Expr *E, + QualType T, const LocationContext *LCtx, fangyi-zhou wrote: Fixed in new commits. https://github.com/llvm/llvm-project/pull/128251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][analyzer] replace Stmt* with ConstCFGElementRef in SymbolConjured (PR #128251)
@@ -844,7 +845,7 @@ SymbolRef getContainerEnd(ProgramStateRef State, const MemRegion *Cont) { return CDataPtr->getEnd(); } -ProgramStateRef createContainerBegin(ProgramStateRef State, +ProgramStateRef createContainerBegin(CheckerContext &C, ProgramStateRef State, const MemRegion *Cont, const Expr *E, QualType T, const LocationContext *LCtx, unsigned BlockCount) { fangyi-zhou wrote: Fixed in new commits. https://github.com/llvm/llvm-project/pull/128251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [alpha.webkit.UnretainedLocalVarsChecker] Add a checker for local variables to NS and CF types. (PR #127554)
@@ -3668,6 +3668,12 @@ Here are some examples of situations that we warn about as they *might* be poten RefCountable* uncounted = counted.get(); // warn } +alpha.webkit.UnretainedLocalVarsChecker +""" +The goal of this rule is to make sure that any NS or CF local variable is backed by a RetainPtr with lifetime that is strictly larger than the scope of the unretained local variable. To be on the safe side we require the scope of an unretained variable to be embedded in the scope of Retainptr object that backs it. + +The rules of when to use and not to use RetainPtr are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects. + rniwa wrote: Sure, will add. https://github.com/llvm/llvm-project/pull/127554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [emacs] Check for a 'buffer' type instead of 'buffer-live' (PR #128385)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/128385 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [alpha.webkit.UnretainedLocalVarsChecker] Add a checker for local variables to NS and CF types. (PR #127554)
@@ -332,6 +345,14 @@ class UncheckedCallArgsChecker final : public RawPtrRefCallArgsChecker { return isUncheckedPtr(QT); } + bool isSafePtr(const CXXRecordDecl *Record) const final { +return isRefCounted(Record) || isCheckedPtr(Record); + } + + bool isSafePtrType(const QualType type) const final { +return isRefOrCheckedPtrType(type); + } + rniwa wrote: These are declared as pure virtual functions in `RawPtrRefCallArgsChecker`. Do you mean move one of the definitions to the base class so that some of these concrete subclasses won't have to define them?? https://github.com/llvm/llvm-project/pull/127554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][analyzer] replace Stmt* with ConstCFGElementRef in SymbolConjured (PR #128251)
@@ -111,8 +111,13 @@ class SValExplainer : public FullSValVisitor { } std::string VisitSymbolConjured(const SymbolConjured *S) { -return "symbol of type '" + S->getType().getAsString() + - "' conjured at statement '" + printStmt(S->getStmt()) + "'"; +std::string Str; +llvm::raw_string_ostream OS(Str); +OS << "symbol of type '" + S->getType().getAsString() + + "' conjured at statement '"; +S->getCFGElementRef()->dumpToStream(OS); fangyi-zhou wrote: `printStmt()` delegates to `Stmt::printPretty()`, but I don't immediately see any equivalent for `CFGElementRef`. The slightly annoying thing about `dumpToStream` for `CFGElementRef` is that it has an newline character in the end... https://github.com/llvm/llvm-project/pull/128251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [emacs] Check for a 'buffer' type instead of 'buffer-live' (PR #128385)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Roi Martin (jroimartin) Changes This is a follow-up to commit f69110dcc973 ("Check for a 'buffer' type instead of 'buffer-live'."). In Emacs 29, 'buffer-live' is no longer recognized as a type and generates a compilation warning. Every function that requires a live buffer already checks whether the buffer is live, so we don't need to check ourselves. --- Full diff: https://github.com/llvm/llvm-project/pull/128385.diff 1 Files Affected: - (modified) clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el (+1-1) ``diff diff --git a/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el b/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el index f3a949f8c1b55..1cb9a0340b5e3 100644 --- a/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el +++ b/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el @@ -249,7 +249,7 @@ Add a missing header if there is any. If there are multiple possible headers the user can select one of them to be included. Temporarily highlight the affected symbols. Asynchronously call clang-include-fixer to insert the selected header." - (cl-check-type stdout buffer-live) + (cl-check-type stdout buffer) (let ((context (clang-include-fixer--parse-json stdout))) (let-alist context (cond `` https://github.com/llvm/llvm-project/pull/128385 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC][docs] Use single tick for 'false' and 'true' values in options (PR #128362)
https://github.com/HerrCai0907 approved this pull request. https://github.com/llvm/llvm-project/pull/128362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Reland "[HLSL] Implement the reflect HLSL function" (PR #125599)
Icohedron wrote: > LGTM regarding previous HWASAN crash, which is gone Thank you for fixing the issue! I will revert the patches then. https://github.com/llvm/llvm-project/pull/125599 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FatLTO] Detect LLD linker more reliably (PR #128285)
https://github.com/thevinster updated https://github.com/llvm/llvm-project/pull/128285 >From b8d961acfa2bf17486d63de9481ff46445d6b38f Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Fri, 21 Feb 2025 20:33:25 -0800 Subject: [PATCH 1/3] [FatLTO] Detect LLD linker more reliably --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 5 ++--- .../usr/x86_64-unknown-linux-gnu/bin/lld-wrapper | 0 clang/test/Driver/fat-lto-objects.c | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100755 clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 360754bdb3161..4f60287a1142b 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -862,13 +862,12 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, const llvm::Triple &Triple = ToolChain.getTriple(); const bool IsOSAIX = Triple.isOSAIX(); const bool IsAMDGCN = Triple.isAMDGCN(); - const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath()); + StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ); const Driver &D = ToolChain.getDriver(); const bool IsFatLTO = Args.hasFlag(options::OPT_ffat_lto_objects, options::OPT_fno_fat_lto_objects, false); const bool IsUnifiedLTO = Args.hasArg(options::OPT_funified_lto); - if (llvm::sys::path::filename(Linker) != "ld.lld" && - llvm::sys::path::stem(Linker) != "ld.lld" && !Triple.isOSOpenBSD()) { + if (Linker != "lld" && Linker != "lld-link" && !Triple.isOSOpenBSD()) { // Tell the linker to load the plugin. This has to come before // AddLinkerInputs as gold requires -plugin and AIX ld requires -bplugin to // come before any -plugin-opt/-bplugin_opt that -Wl might forward. diff --git a/clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper b/clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper new file mode 100755 index 0..e69de29bb2d1d diff --git a/clang/test/Driver/fat-lto-objects.c b/clang/test/Driver/fat-lto-objects.c index fae64ea7fd1a1..7b87e2b468886 100644 --- a/clang/test/Driver/fat-lto-objects.c +++ b/clang/test/Driver/fat-lto-objects.c @@ -49,5 +49,8 @@ // RUN: -fuse-ld=lld -flto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=LTO %s // RUN: %clang --target=x86_64-unknown-linux-gnu --sysroot=%S/Inputs/basic_cross_linux_tree %s \ // RUN: -fuse-ld=lld -fno-lto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=NOLTO %s +// RUN: %clang --target=x86_64-unknown-linux-gnu --sysroot=%S/Inputs/basic_cross_linux_tree %s \ +// RUN: -fuse-ld=lld --ld-path=%S/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper \ +// RUN: -flto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=LTO %s // LTO: "--fat-lto-objects" // NOLTO-NOT: "--fat-lto-objects" >From da36ced7d82588da99d6348cde24062a7efa3c54 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Fri, 21 Feb 2025 20:50:05 -0800 Subject: [PATCH 2/3] Make lld-wrapper a symlink to ld.lld --- .../usr/x86_64-unknown-linux-gnu/bin/lld-wrapper | 1 + 1 file changed, 1 insertion(+) mode change 100755 => 12 clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper diff --git a/clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper b/clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper deleted file mode 100755 index e69de29bb2d1d..0 diff --git a/clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper b/clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper new file mode 12 index 0..9b032ee3b3f1d --- /dev/null +++ b/clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper @@ -0,0 +1 @@ +ld.lld \ No newline at end of file >From b03056a9b7737557e4e5fac6333a93d9c4ff67ec Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sat, 22 Feb 2025 23:18:20 -0800 Subject: [PATCH 3/3] Recover original lld check --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 4f60287a1142b..b43472a52038b 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -863,11 +863,14 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, const bool IsOSAIX = Triple.isOSAIX(); const bool IsAMDGCN = Triple.isAMDGCN(); StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_E
[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)
@@ -0,0 +1,45 @@ +// RUN: %check_clang_tidy -std=c99 %s bugprone-true-macro %t +// RUN: %check_clang_tidy -std=c11 %s bugprone-true-macro %t +// RUN: %check_clang_tidy -std=c17 %s bugprone-true-macro %t steakhal wrote: I think you should have a RUN line for a case when "true" is a keyword. https://github.com/llvm/llvm-project/pull/128265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC][docs] Use single tick for 'false' and 'true' values in options (PR #128362)
vbvictor wrote: Thanks for fast approval! @HerrCai0907, Could you merge, please. https://github.com/llvm/llvm-project/pull/128362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy] fix fp when modifying variant by ``operator[]`` with template in parameters (PR #128407)
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/128407 `ArraySubscriptExpr` can switch base and idx. For dependent array subscript access, we should check both base and idx conservatively. >From ff265c9f01d68b8657d217ba4ea62b77a5775bb5 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Sun, 23 Feb 2025 15:24:52 +0800 Subject: [PATCH 1/2] wip --- clang/lib/Analysis/ExprMutationAnalyzer.cpp | 18 ++--- .../Analysis/ExprMutationAnalyzerTest.cpp | 20 +++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp b/clang/lib/Analysis/ExprMutationAnalyzer.cpp index 8944343484e58..823d7543f085f 100644 --- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp +++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp @@ -80,6 +80,17 @@ static bool canExprResolveTo(const Expr *Source, const Expr *Target) { namespace { +// `ArraySubscriptExpr` can switch base and idx, e.g. `a[4]` is the same as +// `4[a]`. When type is dependent, we conservatively assume both sides are base. +AST_MATCHER_P(ArraySubscriptExpr, hasBaseConservative, + ast_matchers::internal::Matcher, InnerMatcher) { + if (Node.isTypeDependent()) { +return InnerMatcher.matches(*Node.getLHS(), Finder, Builder) || + InnerMatcher.matches(*Node.getRHS(), Finder, Builder); + } + return InnerMatcher.matches(*Node.getBase(), Finder, Builder); +} + AST_MATCHER(Type, isDependentType) { return Node.isDependentType(); } AST_MATCHER_P(LambdaExpr, hasCaptureInit, const Expr *, E) { @@ -513,8 +524,8 @@ ExprMutationAnalyzer::Analyzer::findArrayElementMutation(const Expr *Exp) { // Check whether any element of an array is mutated. const auto SubscriptExprs = match( findAll(arraySubscriptExpr( - anyOf(hasBase(canResolveToExpr(Exp)), -hasBase(implicitCastExpr(allOf( + anyOf(hasBaseConservative(canResolveToExpr(Exp)), +hasBaseConservative(implicitCastExpr(allOf( hasCastKind(CK_ArrayToPointerDecay), hasSourceExpression(canResolveToExpr(Exp))) .bind(NodeID::value)), @@ -716,7 +727,8 @@ ExprMutationAnalyzer::Analyzer::findPointeeValueMutation(const Expr *Exp) { unaryOperator(hasOperatorName("*"), hasUnaryOperand(canResolveToExprPointee(Exp))), // deref by [] - arraySubscriptExpr(hasBase(canResolveToExprPointee(Exp) + arraySubscriptExpr( + hasBaseConservative(canResolveToExprPointee(Exp) .bind(NodeID::value))), Stm, Context); return findExprMutation(Matches); diff --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp index cc277d56b37a2..d237aaa9616f8 100644 --- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp +++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp @@ -870,6 +870,26 @@ TEST(ExprMutationAnalyzerTest, TemplateWithArrayToPointerDecay) { EXPECT_THAT(mutatedBy(ResultsY, AST.get()), ElementsAre("y")); } +TEST(ExprMutationAnalyzerTest, T1) { + const auto AST = buildASTFromCodeWithArgs( + R"( + +template class unordered_map { +public: + V &operator[](T t); +}; + +template void func() { + unordered_map x; + x[T{}] = 3; +} + )", + {"-fno-delayed-template-parsing"}); + const auto Results = + match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); + EXPECT_TRUE(isMutated(Results, AST.get())); +} + // section: special case: all created references are non-mutating themself // and therefore all become 'const'/the value is not modified! >From 6f464d8420426731ff9c2b1165c28224ac872dd5 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Sun, 23 Feb 2025 15:29:00 +0800 Subject: [PATCH 2/2] add test --- clang-tools-extra/docs/ReleaseNotes.rst | 4 .../checkers/misc/const-correctness-values.cpp | 8 .../Analysis/ExprMutationAnalyzerTest.cpp | 17 + 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6b8fe22242417..dc367b6b476f5 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -106,6 +106,10 @@ Changes in existing checks ` check to allow specifying additional C++ member functions to match. +- Improved :doc:`misc-const-correctness + ` check by fixing false positives when + modify variant by ``operator[]`` with template in parameters. + - Improved :doc:`misc-redundant-expression ` check by providing additional examples and fixing some macro related false positives. diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-
[clang] [clang-tools-extra] [clang-tidy] fix fp when modifying variant by ``operator[]`` with template in parameters (PR #128407)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy Author: Congcong Cai (HerrCai0907) Changes `ArraySubscriptExpr` can switch base and idx. For dependent array subscript access, we should check both base and idx conservatively. --- Full diff: https://github.com/llvm/llvm-project/pull/128407.diff 4 Files Affected: - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) - (modified) clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp (+8) - (modified) clang/lib/Analysis/ExprMutationAnalyzer.cpp (+15-3) - (modified) clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp (+13) ``diff diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6b8fe22242417..dc367b6b476f5 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -106,6 +106,10 @@ Changes in existing checks ` check to allow specifying additional C++ member functions to match. +- Improved :doc:`misc-const-correctness + ` check by fixing false positives when + modify variant by ``operator[]`` with template in parameters. + - Improved :doc:`misc-redundant-expression ` check by providing additional examples and fixing some macro related false positives. diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp index 0d1ff0db58371..e598cf9e64373 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp @@ -998,3 +998,11 @@ void member_pointer_const(Value &x, PointerToConstMemberFunction m) { // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'member_pointer_tmp' of type 'Value &' can be declared 'const' (member_pointer_tmp.*m)(); } + +namespace gh127776_false_positive { +template struct vector { T &operator[](int t); }; +template void f() { + vector x; + x[T{}] = 3; +} +} // namespace gh127776_false_positive diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp b/clang/lib/Analysis/ExprMutationAnalyzer.cpp index 8944343484e58..823d7543f085f 100644 --- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp +++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp @@ -80,6 +80,17 @@ static bool canExprResolveTo(const Expr *Source, const Expr *Target) { namespace { +// `ArraySubscriptExpr` can switch base and idx, e.g. `a[4]` is the same as +// `4[a]`. When type is dependent, we conservatively assume both sides are base. +AST_MATCHER_P(ArraySubscriptExpr, hasBaseConservative, + ast_matchers::internal::Matcher, InnerMatcher) { + if (Node.isTypeDependent()) { +return InnerMatcher.matches(*Node.getLHS(), Finder, Builder) || + InnerMatcher.matches(*Node.getRHS(), Finder, Builder); + } + return InnerMatcher.matches(*Node.getBase(), Finder, Builder); +} + AST_MATCHER(Type, isDependentType) { return Node.isDependentType(); } AST_MATCHER_P(LambdaExpr, hasCaptureInit, const Expr *, E) { @@ -513,8 +524,8 @@ ExprMutationAnalyzer::Analyzer::findArrayElementMutation(const Expr *Exp) { // Check whether any element of an array is mutated. const auto SubscriptExprs = match( findAll(arraySubscriptExpr( - anyOf(hasBase(canResolveToExpr(Exp)), -hasBase(implicitCastExpr(allOf( + anyOf(hasBaseConservative(canResolveToExpr(Exp)), +hasBaseConservative(implicitCastExpr(allOf( hasCastKind(CK_ArrayToPointerDecay), hasSourceExpression(canResolveToExpr(Exp))) .bind(NodeID::value)), @@ -716,7 +727,8 @@ ExprMutationAnalyzer::Analyzer::findPointeeValueMutation(const Expr *Exp) { unaryOperator(hasOperatorName("*"), hasUnaryOperand(canResolveToExprPointee(Exp))), // deref by [] - arraySubscriptExpr(hasBase(canResolveToExprPointee(Exp) + arraySubscriptExpr( + hasBaseConservative(canResolveToExprPointee(Exp) .bind(NodeID::value))), Stm, Context); return findExprMutation(Matches); diff --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp index cc277d56b37a2..720999207083d 100644 --- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp +++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp @@ -870,6 +870,19 @@ TEST(ExprMutationAnalyzerTest, TemplateWithArrayToPointerDecay) { EXPECT_THAT(mutatedBy(ResultsY, AST.get()), ElementsAre("y")); } +TEST(ExprMutationAnalyzerTest, T1) { + const auto AST = buildASTFromCodeWithArgs( + "template struct vector { T &operator[](int t); };" + "template void func() {" + " vector x;" + " x[T{}] = 3;"
[clang] [clang][HIP] Make some math not not work with AMDGCN SPIR-V (PR #128360)
@@ -14,6 +14,12 @@ #include "hip/hip_version.h" #endif // __has_include("hip/hip_version.h") +#ifdef __SPIRV__ +#define __PRIVATE_AS __attribute__((address_space(0))) arsenm wrote: Never use numbered address spaces. Unconditionally use __attribute__((opencl_private)) https://github.com/llvm/llvm-project/pull/128360 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add the C language instead of treating it like C++ (PR #128287)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/128287 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Better handling of `void` function return (PR #128089)
dkolsen-pgi wrote: I like the idea of changing the assembly format for function types from `!cir.func` to `!cir.func<(!argType) -> !returnType>`. That is 1. Easier to parse. 2. Consistent with function types in other MLIR dialects. 3. Consistent with the assembly format for function definitions in ClangIR. Making a change like this really needs to happen in the incubator first, not as part of upstreaming. So my current plan is to 1. abandon this PR, 2. create a new PR in the incubator to make this change (including fixing lots of tests), 3. and then create a new upstream PR with the new behavior. https://github.com/llvm/llvm-project/pull/128089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Bb/reland expose astcontext to checker ctors (PR #128369)
https://github.com/steakhal created https://github.com/llvm/llvm-project/pull/128369 Reapply "[analyzer] Delay the checker constructions after parsing" (#128350) This reverts commit db836edf47f36ed04cab919a7a2c4414f4d0d7e6, as-is. Depends on #128368 >From 6fd30233a570ace5ccf3f04f649ddd37bd4149b2 Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Sat, 22 Feb 2025 20:50:31 +0100 Subject: [PATCH 1/2] [analyzer] Clean up slightly the messed up ownership model of the analyzer Well, yes. It's not pretty. At least after this we would have a bit more unique pointers than before. This is for fixing the memory leak diagnosed by: https://lab.llvm.org/buildbot/#/builders/24/builds/5580 And that caused the revert of #127409. After these uptrs that patch can re-land finally. --- .../clang/Analysis/AnalysisDeclContext.h | 2 +- .../Core/BugReporter/BugReporter.h| 24 +++ .../Core/PathDiagnosticConsumers.h| 3 ++- .../Core/PathSensitive/AnalysisManager.h | 7 +++--- .../Frontend/AnalysisConsumer.h | 3 ++- clang/lib/Analysis/AnalysisDeclContext.cpp| 4 ++-- .../StaticAnalyzer/Core/AnalysisManager.cpp | 23 +++--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp | 22 - .../StaticAnalyzer/Core/HTMLDiagnostics.cpp | 6 +++-- .../StaticAnalyzer/Core/PlistDiagnostics.cpp | 12 +- .../StaticAnalyzer/Core/SarifDiagnostics.cpp | 5 ++-- .../Frontend/AnalysisConsumer.cpp | 21 .../BugReportInterestingnessTest.cpp | 6 +++-- .../StaticAnalyzer/CheckerRegistration.h | 4 ++-- clang/unittests/StaticAnalyzer/Reusables.h| 7 +++--- 15 files changed, 77 insertions(+), 72 deletions(-) diff --git a/clang/include/clang/Analysis/AnalysisDeclContext.h b/clang/include/clang/Analysis/AnalysisDeclContext.h index a517a4e757c9f..ced4bb8595bea 100644 --- a/clang/include/clang/Analysis/AnalysisDeclContext.h +++ b/clang/include/clang/Analysis/AnalysisDeclContext.h @@ -451,7 +451,7 @@ class AnalysisDeclContextManager { bool synthesizeBodies = false, bool addStaticInitBranches = false, bool addCXXNewAllocator = true, bool addRichCXXConstructors = true, bool markElidedCXXConstructors = true, bool addVirtualBaseBranches = true, - CodeInjector *injector = nullptr); + std::unique_ptr injector = nullptr); AnalysisDeclContext *getContext(const Decl *D); diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index 7563d8bbd1d27..8e1d25b3eefa1 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -570,7 +570,8 @@ class BugReporterData { public: virtual ~BugReporterData() = default; - virtual ArrayRef getPathDiagnosticConsumers() = 0; + virtual ArrayRef> + getPathDiagnosticConsumers() = 0; virtual ASTContext &getASTContext() = 0; virtual SourceManager &getSourceManager() = 0; virtual AnalyzerOptions &getAnalyzerOptions() = 0; @@ -608,7 +609,8 @@ class BugReporter { /// Generate and flush diagnostics for all bug reports. void FlushReports(); - ArrayRef getPathDiagnosticConsumers() { + ArrayRef> + getPathDiagnosticConsumers() { return D.getPathDiagnosticConsumers(); } @@ -670,9 +672,10 @@ class BugReporter { protected: /// Generate the diagnostics for the given bug report. virtual std::unique_ptr - generateDiagnosticForConsumerMap(BugReport *exampleReport, - ArrayRef consumers, - ArrayRef bugReports); + generateDiagnosticForConsumerMap( + BugReport *exampleReport, + ArrayRef> consumers, + ArrayRef bugReports); }; /// GRBugReporter is used for generating path-sensitive reports. @@ -684,10 +687,11 @@ class PathSensitiveBugReporter final : public BugReporter { SmallVectorImpl &bugReports) override; /// Generate the diagnostics for the given bug report. - std::unique_ptr - generateDiagnosticForConsumerMap(BugReport *exampleReport, - ArrayRef consumers, - ArrayRef bugReports) override; + std::unique_ptr generateDiagnosticForConsumerMap( + BugReport *exampleReport, + ArrayRef> consumers, + ArrayRef bugReports) override; + public: PathSensitiveBugReporter(BugReporterData& d, ExprEngine& eng) : BugReporter(d), Eng(eng) {} @@ -706,7 +710,7 @@ class PathSensitiveBugReporter final : public BugReporter { /// Iterates through the bug reports within a single equivalence class, /// stops at a first non-invalidated report. std::unique_ptr generatePathDiagnostics( - ArrayRef consumers, + ArrayRef> consumers, ArrayRef &bugReports); void emitReport(std::unique_ptr R) override; diff --git a/clang/incl
[clang] [X86] Allow using the lzcnt intrinsics for non-LZCNT targets (PR #128284)
https://github.com/RKSimon approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/128284 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [polly] [DAG] shouldReduceLoadWidth - hasOneUse should check just the loaded value - not the chain (PR #128167)
https://github.com/topperc edited https://github.com/llvm/llvm-project/pull/128167 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [alpha.webkit.UnretainedLocalVarsChecker] Add a checker for local variables to NS and CF types. (PR #127554)
@@ -3668,6 +3668,12 @@ Here are some examples of situations that we warn about as they *might* be poten RefCountable* uncounted = counted.get(); // warn } +alpha.webkit.UnretainedLocalVarsChecker +""" +The goal of this rule is to make sure that any NS or CF local variable is backed by a RetainPtr with lifetime that is strictly larger than the scope of the unretained local variable. To be on the safe side we require the scope of an unretained variable to be embedded in the scope of Retainptr object that backs it. + +The rules of when to use and not to use RetainPtr are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects. + t-rasmud wrote: It would be nice to have a code example here. https://github.com/llvm/llvm-project/pull/127554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [alpha.webkit.UnretainedLocalVarsChecker] Add a checker for local variables to NS and CF types. (PR #127554)
https://github.com/t-rasmud approved this pull request. Left some nitpicks. otherwise LGTM. https://github.com/llvm/llvm-project/pull/127554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FatLTO] Detect LLD linker more reliably (PR #128285)
@@ -862,13 +862,12 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, const llvm::Triple &Triple = ToolChain.getTriple(); smeenai wrote: Yeah, I think it's best to keep the old check as well as adding the new one. https://github.com/llvm/llvm-project/pull/128285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)
steakhal wrote: FYI C23 introduced the `true` and `false` keywords. https://github.com/llvm/llvm-project/pull/128265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Clean up slightly the messed up ownership model of the analyzer (PR #128368)
https://github.com/steakhal created https://github.com/llvm/llvm-project/pull/128368 Well, yes. It's not pretty. At least after this we would have a bit more unique pointers than before. This is for fixing the memory leak diagnosed by: https://lab.llvm.org/buildbot/#/builders/24/builds/5580 And that caused the revert of #127409. After these uptrs that patch can re-land finally. >From 6fd30233a570ace5ccf3f04f649ddd37bd4149b2 Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Sat, 22 Feb 2025 20:50:31 +0100 Subject: [PATCH] [analyzer] Clean up slightly the messed up ownership model of the analyzer Well, yes. It's not pretty. At least after this we would have a bit more unique pointers than before. This is for fixing the memory leak diagnosed by: https://lab.llvm.org/buildbot/#/builders/24/builds/5580 And that caused the revert of #127409. After these uptrs that patch can re-land finally. --- .../clang/Analysis/AnalysisDeclContext.h | 2 +- .../Core/BugReporter/BugReporter.h| 24 +++ .../Core/PathDiagnosticConsumers.h| 3 ++- .../Core/PathSensitive/AnalysisManager.h | 7 +++--- .../Frontend/AnalysisConsumer.h | 3 ++- clang/lib/Analysis/AnalysisDeclContext.cpp| 4 ++-- .../StaticAnalyzer/Core/AnalysisManager.cpp | 23 +++--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp | 22 - .../StaticAnalyzer/Core/HTMLDiagnostics.cpp | 6 +++-- .../StaticAnalyzer/Core/PlistDiagnostics.cpp | 12 +- .../StaticAnalyzer/Core/SarifDiagnostics.cpp | 5 ++-- .../Frontend/AnalysisConsumer.cpp | 21 .../BugReportInterestingnessTest.cpp | 6 +++-- .../StaticAnalyzer/CheckerRegistration.h | 4 ++-- clang/unittests/StaticAnalyzer/Reusables.h| 7 +++--- 15 files changed, 77 insertions(+), 72 deletions(-) diff --git a/clang/include/clang/Analysis/AnalysisDeclContext.h b/clang/include/clang/Analysis/AnalysisDeclContext.h index a517a4e757c9f..ced4bb8595bea 100644 --- a/clang/include/clang/Analysis/AnalysisDeclContext.h +++ b/clang/include/clang/Analysis/AnalysisDeclContext.h @@ -451,7 +451,7 @@ class AnalysisDeclContextManager { bool synthesizeBodies = false, bool addStaticInitBranches = false, bool addCXXNewAllocator = true, bool addRichCXXConstructors = true, bool markElidedCXXConstructors = true, bool addVirtualBaseBranches = true, - CodeInjector *injector = nullptr); + std::unique_ptr injector = nullptr); AnalysisDeclContext *getContext(const Decl *D); diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index 7563d8bbd1d27..8e1d25b3eefa1 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -570,7 +570,8 @@ class BugReporterData { public: virtual ~BugReporterData() = default; - virtual ArrayRef getPathDiagnosticConsumers() = 0; + virtual ArrayRef> + getPathDiagnosticConsumers() = 0; virtual ASTContext &getASTContext() = 0; virtual SourceManager &getSourceManager() = 0; virtual AnalyzerOptions &getAnalyzerOptions() = 0; @@ -608,7 +609,8 @@ class BugReporter { /// Generate and flush diagnostics for all bug reports. void FlushReports(); - ArrayRef getPathDiagnosticConsumers() { + ArrayRef> + getPathDiagnosticConsumers() { return D.getPathDiagnosticConsumers(); } @@ -670,9 +672,10 @@ class BugReporter { protected: /// Generate the diagnostics for the given bug report. virtual std::unique_ptr - generateDiagnosticForConsumerMap(BugReport *exampleReport, - ArrayRef consumers, - ArrayRef bugReports); + generateDiagnosticForConsumerMap( + BugReport *exampleReport, + ArrayRef> consumers, + ArrayRef bugReports); }; /// GRBugReporter is used for generating path-sensitive reports. @@ -684,10 +687,11 @@ class PathSensitiveBugReporter final : public BugReporter { SmallVectorImpl &bugReports) override; /// Generate the diagnostics for the given bug report. - std::unique_ptr - generateDiagnosticForConsumerMap(BugReport *exampleReport, - ArrayRef consumers, - ArrayRef bugReports) override; + std::unique_ptr generateDiagnosticForConsumerMap( + BugReport *exampleReport, + ArrayRef> consumers, + ArrayRef bugReports) override; + public: PathSensitiveBugReporter(BugReporterData& d, ExprEngine& eng) : BugReporter(d), Eng(eng) {} @@ -706,7 +710,7 @@ class PathSensitiveBugReporter final : public BugReporter { /// Iterates through the bug reports within a single equivalence class, /// stops at a first non-invalidated report. std::unique_ptr generatePathDiagnostics( - ArrayRef consumers, +
[clang] Bb/reland expose astcontext to checker ctors (PR #128369)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Balazs Benics (steakhal) Changes Reapply "[analyzer] Delay the checker constructions after parsing" (#128350) This reverts commit db836edf47f36ed04cab919a7a2c4414f4d0d7e6, as-is. Depends on #128368 --- Patch is 27.75 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/128369.diff 16 Files Affected: - (modified) clang/include/clang/Analysis/AnalysisDeclContext.h (+1-1) - (modified) clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h (+14-10) - (modified) clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h (+2-1) - (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h (+4-3) - (modified) clang/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h (+2-1) - (modified) clang/lib/Analysis/AnalysisDeclContext.cpp (+2-2) - (modified) clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp (+32-29) - (modified) clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp (+8-15) - (modified) clang/lib/StaticAnalyzer/Core/BugReporter.cpp (+11-11) - (modified) clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (+4-2) - (modified) clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp (+6-6) - (modified) clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (+3-2) - (modified) clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (+16-17) - (modified) clang/unittests/StaticAnalyzer/BugReportInterestingnessTest.cpp (+4-2) - (modified) clang/unittests/StaticAnalyzer/CheckerRegistration.h (+2-2) - (modified) clang/unittests/StaticAnalyzer/Reusables.h (+3-4) ``diff diff --git a/clang/include/clang/Analysis/AnalysisDeclContext.h b/clang/include/clang/Analysis/AnalysisDeclContext.h index a517a4e757c9f..ced4bb8595bea 100644 --- a/clang/include/clang/Analysis/AnalysisDeclContext.h +++ b/clang/include/clang/Analysis/AnalysisDeclContext.h @@ -451,7 +451,7 @@ class AnalysisDeclContextManager { bool synthesizeBodies = false, bool addStaticInitBranches = false, bool addCXXNewAllocator = true, bool addRichCXXConstructors = true, bool markElidedCXXConstructors = true, bool addVirtualBaseBranches = true, - CodeInjector *injector = nullptr); + std::unique_ptr injector = nullptr); AnalysisDeclContext *getContext(const Decl *D); diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index 7563d8bbd1d27..8e1d25b3eefa1 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -570,7 +570,8 @@ class BugReporterData { public: virtual ~BugReporterData() = default; - virtual ArrayRef getPathDiagnosticConsumers() = 0; + virtual ArrayRef> + getPathDiagnosticConsumers() = 0; virtual ASTContext &getASTContext() = 0; virtual SourceManager &getSourceManager() = 0; virtual AnalyzerOptions &getAnalyzerOptions() = 0; @@ -608,7 +609,8 @@ class BugReporter { /// Generate and flush diagnostics for all bug reports. void FlushReports(); - ArrayRef getPathDiagnosticConsumers() { + ArrayRef> + getPathDiagnosticConsumers() { return D.getPathDiagnosticConsumers(); } @@ -670,9 +672,10 @@ class BugReporter { protected: /// Generate the diagnostics for the given bug report. virtual std::unique_ptr - generateDiagnosticForConsumerMap(BugReport *exampleReport, - ArrayRef consumers, - ArrayRef bugReports); + generateDiagnosticForConsumerMap( + BugReport *exampleReport, + ArrayRef> consumers, + ArrayRef bugReports); }; /// GRBugReporter is used for generating path-sensitive reports. @@ -684,10 +687,11 @@ class PathSensitiveBugReporter final : public BugReporter { SmallVectorImpl &bugReports) override; /// Generate the diagnostics for the given bug report. - std::unique_ptr - generateDiagnosticForConsumerMap(BugReport *exampleReport, - ArrayRef consumers, - ArrayRef bugReports) override; + std::unique_ptr generateDiagnosticForConsumerMap( + BugReport *exampleReport, + ArrayRef> consumers, + ArrayRef bugReports) override; + public: PathSensitiveBugReporter(BugReporterData& d, ExprEngine& eng) : BugReporter(d), Eng(eng) {} @@ -706,7 +710,7 @@ class PathSensitiveBugReporter final : public BugReporter { /// Iterates through the bug reports within a single equivalence class, /// stops at a first non-invalidated report. std::unique_ptr generatePathDiagnostics( - ArrayRef consumers, + ArrayRef> consumers, ArrayRef &bugReports); void emitReport(std::unique_ptr R) override; diff --git a/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h b/clang/include/clang/StaticAnalyz
[clang] [analyzer] Clean up slightly the messed up ownership model of the analyzer (PR #128368)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Balazs Benics (steakhal) Changes Well, yes. It's not pretty. At least after this we would have a bit more unique pointers than before. This is for fixing the memory leak diagnosed by: https://lab.llvm.org/buildbot/#/builders/24/builds/5580 And that caused the revert of #127409. After these uptrs that patch can re-land finally. --- Patch is 22.23 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/128368.diff 15 Files Affected: - (modified) clang/include/clang/Analysis/AnalysisDeclContext.h (+1-1) - (modified) clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h (+14-10) - (modified) clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h (+2-1) - (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h (+4-3) - (modified) clang/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h (+2-1) - (modified) clang/lib/Analysis/AnalysisDeclContext.cpp (+2-2) - (modified) clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp (+8-15) - (modified) clang/lib/StaticAnalyzer/Core/BugReporter.cpp (+11-11) - (modified) clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (+4-2) - (modified) clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp (+6-6) - (modified) clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (+3-2) - (modified) clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (+11-10) - (modified) clang/unittests/StaticAnalyzer/BugReportInterestingnessTest.cpp (+4-2) - (modified) clang/unittests/StaticAnalyzer/CheckerRegistration.h (+2-2) - (modified) clang/unittests/StaticAnalyzer/Reusables.h (+3-4) ``diff diff --git a/clang/include/clang/Analysis/AnalysisDeclContext.h b/clang/include/clang/Analysis/AnalysisDeclContext.h index a517a4e757c9f..ced4bb8595bea 100644 --- a/clang/include/clang/Analysis/AnalysisDeclContext.h +++ b/clang/include/clang/Analysis/AnalysisDeclContext.h @@ -451,7 +451,7 @@ class AnalysisDeclContextManager { bool synthesizeBodies = false, bool addStaticInitBranches = false, bool addCXXNewAllocator = true, bool addRichCXXConstructors = true, bool markElidedCXXConstructors = true, bool addVirtualBaseBranches = true, - CodeInjector *injector = nullptr); + std::unique_ptr injector = nullptr); AnalysisDeclContext *getContext(const Decl *D); diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index 7563d8bbd1d27..8e1d25b3eefa1 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -570,7 +570,8 @@ class BugReporterData { public: virtual ~BugReporterData() = default; - virtual ArrayRef getPathDiagnosticConsumers() = 0; + virtual ArrayRef> + getPathDiagnosticConsumers() = 0; virtual ASTContext &getASTContext() = 0; virtual SourceManager &getSourceManager() = 0; virtual AnalyzerOptions &getAnalyzerOptions() = 0; @@ -608,7 +609,8 @@ class BugReporter { /// Generate and flush diagnostics for all bug reports. void FlushReports(); - ArrayRef getPathDiagnosticConsumers() { + ArrayRef> + getPathDiagnosticConsumers() { return D.getPathDiagnosticConsumers(); } @@ -670,9 +672,10 @@ class BugReporter { protected: /// Generate the diagnostics for the given bug report. virtual std::unique_ptr - generateDiagnosticForConsumerMap(BugReport *exampleReport, - ArrayRef consumers, - ArrayRef bugReports); + generateDiagnosticForConsumerMap( + BugReport *exampleReport, + ArrayRef> consumers, + ArrayRef bugReports); }; /// GRBugReporter is used for generating path-sensitive reports. @@ -684,10 +687,11 @@ class PathSensitiveBugReporter final : public BugReporter { SmallVectorImpl &bugReports) override; /// Generate the diagnostics for the given bug report. - std::unique_ptr - generateDiagnosticForConsumerMap(BugReport *exampleReport, - ArrayRef consumers, - ArrayRef bugReports) override; + std::unique_ptr generateDiagnosticForConsumerMap( + BugReport *exampleReport, + ArrayRef> consumers, + ArrayRef bugReports) override; + public: PathSensitiveBugReporter(BugReporterData& d, ExprEngine& eng) : BugReporter(d), Eng(eng) {} @@ -706,7 +710,7 @@ class PathSensitiveBugReporter final : public BugReporter { /// Iterates through the bug reports within a single equivalence class, /// stops at a first non-invalidated report. std::unique_ptr generatePathDiagnostics( - ArrayRef consumers, + ArrayRef> consumers, ArrayRef &bugReports); void emitReport(std::unique_ptr R) override; diff --git a/clang/include/clang/StaticAnalyzer/Core/PathDiagn
[clang] Reapply "[analyzer] Delay the checker constructions after parsing" (PR #128369)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff db836edf47f36ed04cab919a7a2c4414f4d0d7e6 ea932d93a47e6747f50768fc232d2c9e9375b6da --extensions h,cpp -- clang/include/clang/Analysis/AnalysisDeclContext.h clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h clang/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h clang/lib/Analysis/AnalysisDeclContext.cpp clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp clang/lib/StaticAnalyzer/Core/BugReporter.cpp clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp clang/unittests/StaticAnalyzer/BugReportInterestingnessTest.cpp clang/unittests/StaticAnalyzer/CheckerRegistration.h clang/unittests/StaticAnalyzer/Reusables.h `` View the diff from clang-format here. ``diff diff --git a/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp b/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp index 8a16716f95..283b796ab2 100644 --- a/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp @@ -44,9 +44,7 @@ AnalysisManager::AnalysisManager(ASTContext &ASTCtx, Preprocessor &PP, Options.ShouldIncludeDefaultInitForAggregates; } -AnalysisManager::~AnalysisManager() { - FlushDiagnostics(); -} +AnalysisManager::~AnalysisManager() { FlushDiagnostics(); } void AnalysisManager::FlushDiagnostics() { PathDiagnosticConsumer::FilesMade filesMade; `` https://github.com/llvm/llvm-project/pull/128369 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Clean up slightly the messed up ownership model of the analyzer (PR #128368)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff db836edf47f36ed04cab919a7a2c4414f4d0d7e6 6fd30233a570ace5ccf3f04f649ddd37bd4149b2 --extensions h,cpp -- clang/include/clang/Analysis/AnalysisDeclContext.h clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h clang/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h clang/lib/Analysis/AnalysisDeclContext.cpp clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp clang/lib/StaticAnalyzer/Core/BugReporter.cpp clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp clang/unittests/StaticAnalyzer/BugReportInterestingnessTest.cpp clang/unittests/StaticAnalyzer/CheckerRegistration.h clang/unittests/StaticAnalyzer/Reusables.h `` View the diff from clang-format here. ``diff diff --git a/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp b/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp index 8a16716f95..283b796ab2 100644 --- a/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp @@ -44,9 +44,7 @@ AnalysisManager::AnalysisManager(ASTContext &ASTCtx, Preprocessor &PP, Options.ShouldIncludeDefaultInitForAggregates; } -AnalysisManager::~AnalysisManager() { - FlushDiagnostics(); -} +AnalysisManager::~AnalysisManager() { FlushDiagnostics(); } void AnalysisManager::FlushDiagnostics() { PathDiagnosticConsumer::FilesMade filesMade; `` https://github.com/llvm/llvm-project/pull/128368 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[analyzer] Delay the checker constructions after parsing" (PR #128369)
https://github.com/steakhal edited https://github.com/llvm/llvm-project/pull/128369 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Allow overriding Unknown memspaces using a ProgramState trait (PR #123003)
vitalybuka wrote: Use after scope: https://lab.llvm.org/buildbot/#/builders/169/builds/8735 https://lab.llvm.org/buildbot/#/builders/94/builds/4653/steps/17/logs/stdio https://github.com/llvm/llvm-project/pull/123003 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6db96c9 - [clang][bytecode] Always reject ctors of invalid parent decls (#128295)
Author: Timm Baeder Date: 2025-02-22T22:04:44+01:00 New Revision: 6db96c9ecc781c742f546d2863632d44e9c9b435 URL: https://github.com/llvm/llvm-project/commit/6db96c9ecc781c742f546d2863632d44e9c9b435 DIFF: https://github.com/llvm/llvm-project/commit/6db96c9ecc781c742f546d2863632d44e9c9b435.diff LOG: [clang][bytecode] Always reject ctors of invalid parent decls (#128295) The copy constructor of an invalid declaration might still be perfectly valid, but we still need to reject it. Added: Modified: clang/lib/AST/ByteCode/Interp.cpp clang/test/AST/ByteCode/records.cpp Removed: diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index dfa59a50b2711..e383828cd676d 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1238,8 +1238,10 @@ static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func, const Pointer &ThisPtr) { assert(Func->isConstructor()); - const Descriptor *D = ThisPtr.getFieldDesc(); + if (Func->getParentDecl()->isInvalidDecl()) +return false; + const Descriptor *D = ThisPtr.getFieldDesc(); // FIXME: I think this case is not 100% correct. E.g. a pointer into a // subobject of a composite array. if (!D->ElemRecord) diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp index 608b94e55560a..cb3d6111fd2bf 100644 --- a/clang/test/AST/ByteCode/records.cpp +++ b/clang/test/AST/ByteCode/records.cpp @@ -1738,4 +1738,12 @@ namespace DeadUpcast { namespace CtorOfInvalidClass { constexpr struct { Unknown U; } InvalidCtor; // both-error {{unknown type name 'Unknown'}} \ // both-error {{must be initialized by a constant expression}} + +#if __cplusplus >= 202002L + template + concept ReferenceOf = Q; + /// This calls a valid and constexpr copy constructor of InvalidCtor, + /// but should still be rejected. + template auto R, typename Rep> int F; // both-error {{non-type template argument is not a constant expression}} +#endif } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Allow overriding Unknown memspaces using a ProgramState trait (PR #123003)
steakhal wrote: > Use after scope: > https://lab.llvm.org/buildbot/#/builders/169/builds/8735 > https://lab.llvm.org/buildbot/#/builders/94/builds/4653/steps/17/logs/stdio > Yeey, could you please revert this for me? @vitalybuka https://github.com/llvm/llvm-project/pull/123003 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Always reject ctors of invalid parent decls (PR #128295)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/128295 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Allow overriding Unknown memspaces using a ProgramState trait (PR #123003)
vitalybuka wrote: Should be fixed with #128372 https://github.com/llvm/llvm-project/pull/123003 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix use after scope after #123003 (PR #128372)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Vitaly Buka (vitalybuka) Changes In #123003 make_first_range was applied to temporarily. --- Full diff: https://github.com/llvm/llvm-project/pull/128372.diff 1 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp (+2-2) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp index 48fa0ebbfc609..3aafb5384b3a6 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp @@ -203,8 +203,8 @@ void StackAddrEscapeChecker::checkAsyncExecutedBlockCaptures( // a variable of the type "dispatch_semaphore_t". if (isSemaphoreCaptured(*B.getDecl())) return; - for (const MemRegion *Region : - llvm::make_first_range(getCapturedStackRegions(B, C))) { + auto Regions = getCapturedStackRegions(B, C); + for (const MemRegion *Region : llvm::make_first_range(Regions)) { // The block passed to dispatch_async may capture another block // created on the stack. However, there is no leak in this situaton, // no matter if ARC or no ARC is enabled: `` https://github.com/llvm/llvm-project/pull/128372 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix use after scope after #123003 (PR #128372)
https://github.com/vitalybuka closed https://github.com/llvm/llvm-project/pull/128372 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix use after scope after #123003 (PR #128372)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/128372 In #123003 make_first_range was applied to temporarily. >From d3384dec3f6aa0e3d9d6585f8b2553dfcff2d579 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Sat, 22 Feb 2025 13:32:12 -0800 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp index 48fa0ebbfc609..3aafb5384b3a6 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp @@ -203,8 +203,8 @@ void StackAddrEscapeChecker::checkAsyncExecutedBlockCaptures( // a variable of the type "dispatch_semaphore_t". if (isSemaphoreCaptured(*B.getDecl())) return; - for (const MemRegion *Region : - llvm::make_first_range(getCapturedStackRegions(B, C))) { + auto Regions = getCapturedStackRegions(B, C); + for (const MemRegion *Region : llvm::make_first_range(Regions)) { // The block passed to dispatch_async may capture another block // created on the stack. However, there is no leak in this situaton, // no matter if ARC or no ARC is enabled: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d2616cc - [analyzer] Fix use after scope after #123003 (#128372)
Author: Vitaly Buka Date: 2025-02-22T13:33:15-08:00 New Revision: d2616cc3926ec0ac73ec547e04b64e045035bd3c URL: https://github.com/llvm/llvm-project/commit/d2616cc3926ec0ac73ec547e04b64e045035bd3c DIFF: https://github.com/llvm/llvm-project/commit/d2616cc3926ec0ac73ec547e04b64e045035bd3c.diff LOG: [analyzer] Fix use after scope after #123003 (#128372) In #123003 make_first_range was applied to temporarily. Added: Modified: clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp index 48fa0ebbfc609..3aafb5384b3a6 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp @@ -203,8 +203,8 @@ void StackAddrEscapeChecker::checkAsyncExecutedBlockCaptures( // a variable of the type "dispatch_semaphore_t". if (isSemaphoreCaptured(*B.getDecl())) return; - for (const MemRegion *Region : - llvm::make_first_range(getCapturedStackRegions(B, C))) { + auto Regions = getCapturedStackRegions(B, C); + for (const MemRegion *Region : llvm::make_first_range(Regions)) { // The block passed to dispatch_async may capture another block // created on the stack. However, there is no leak in this situaton, // no matter if ARC or no ARC is enabled: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix use after scope after #123003 (PR #128372)
steakhal wrote: Ah, I wish we had C++23 already. That would have fixed this too. Thanks! https://github.com/llvm/llvm-project/pull/128372 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Remove xbegin and _xend (PR #126952)
https://github.com/phoebewang closed https://github.com/llvm/llvm-project/pull/126952 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)
https://github.com/vbvictor updated https://github.com/llvm/llvm-project/pull/121291 >From 42e03bb9cc9bd815476b0a3f06ac5f58826e3708 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 31 Jan 2025 19:29:05 +0300 Subject: [PATCH 1/8] [clang-tidy] add new check bugprone-reset-ambiguous-call --- .../bugprone/BugproneTidyModule.cpp | 3 + .../clang-tidy/bugprone/CMakeLists.txt| 1 + .../SmartptrResetAmbiguousCallCheck.cpp | 146 +++ .../SmartptrResetAmbiguousCallCheck.h | 37 +++ clang-tools-extra/docs/ReleaseNotes.rst | 6 + .../smartptr-reset-ambiguous-call.rst | 47 .../docs/clang-tidy/checks/list.rst | 1 + ...r-reset-ambiguous-call-custom-pointers.cpp | 72 ++ .../smartptr-reset-ambiguous-call.cpp | 239 ++ 9 files changed, 552 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/bugprone/SmartptrResetAmbiguousCallCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/bugprone/SmartptrResetAmbiguousCallCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/smartptr-reset-ambiguous-call.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/smartptr-reset-ambiguous-call-custom-pointers.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/smartptr-reset-ambiguous-call.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index c5f0b5b28418f..a01d0e384ab73 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -64,6 +64,7 @@ #include "SignedCharMisuseCheck.h" #include "SizeofContainerCheck.h" #include "SizeofExpressionCheck.h" +#include "SmartptrResetAmbiguousCallCheck.h" #include "SpuriouslyWakeUpFunctionsCheck.h" #include "StandaloneEmptyCheck.h" #include "StringConstructorCheck.h" @@ -207,6 +208,8 @@ class BugproneModule : public ClangTidyModule { "bugprone-sizeof-container"); CheckFactories.registerCheck( "bugprone-sizeof-expression"); +CheckFactories.registerCheck( +"bugprone-smartptr-reset-ambiguous-call"); CheckFactories.registerCheck( "bugprone-spuriously-wake-up-functions"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index e8309c68b7fca..7fd6f4994f537 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -65,6 +65,7 @@ add_clang_library(clangTidyBugproneModule STATIC SizeofContainerCheck.cpp SizeofExpressionCheck.cpp SmartPtrArrayMismatchCheck.cpp + SmartptrResetAmbiguousCallCheck.cpp SpuriouslyWakeUpFunctionsCheck.cpp StandaloneEmptyCheck.cpp StringConstructorCheck.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/SmartptrResetAmbiguousCallCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SmartptrResetAmbiguousCallCheck.cpp new file mode 100644 index 0..326a5665179d7 --- /dev/null +++ b/clang-tools-extra/clang-tidy/bugprone/SmartptrResetAmbiguousCallCheck.cpp @@ -0,0 +1,146 @@ +//===--- SmartptrResetAmbiguousCallCheck.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 "SmartptrResetAmbiguousCallCheck.h" +#include "../utils/OptionsUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +namespace { + +AST_MATCHER_P(CallExpr, everyArgumentMatches, + ast_matchers::internal::Matcher, InnerMatcher) { + for (const auto *Arg : Node.arguments()) { +if (!InnerMatcher.matches(*Arg, Finder, Builder)) + return false; + } + + return true; +} + +AST_MATCHER(CXXMethodDecl, hasOnlyDefaultParameters) { + for (const auto *Param : Node.parameters()) { +if (!Param->hasDefaultArg()) + return false; + } + + return true; +} + +const auto DefaultSmartPointers = "::std::shared_ptr;::std::unique_ptr"; +} // namespace + +SmartptrResetAmbiguousCallCheck::SmartptrResetAmbiguousCallCheck( +StringRef Name, ClangTidyContext *Context) +: ClangTidyCheck(Name, Context), + SmartPointers(utils::options::parseStringList( + Options.get("SmartPointers", DefaultSmartPointers))) {} + +void SmartptrResetAmbiguousCallCheck::storeOptions( +ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, "SmartPointers", +utils::options::seriali
[clang] 8f7e34b - [clang-offload-packager] Avoid repeated hash lookups (NFC) (#128297)
Author: Kazu Hirata Date: 2025-02-22T02:09:27-08:00 New Revision: 8f7e34b0af5f15219b9369f6430fc091dbadff6c URL: https://github.com/llvm/llvm-project/commit/8f7e34b0af5f15219b9369f6430fc091dbadff6c DIFF: https://github.com/llvm/llvm-project/commit/8f7e34b0af5f15219b9369f6430fc091dbadff6c.diff LOG: [clang-offload-packager] Avoid repeated hash lookups (NFC) (#128297) Added: Modified: clang/tools/clang-offload-packager/ClangOffloadPackager.cpp Removed: diff --git a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp index 49cb0d70f492b..8cd9691c30ada 100644 --- a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp +++ b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp @@ -198,12 +198,12 @@ static Error unbundleImages() { Args["file"], Members, SymtabWritingMode::NormalSymtab, Archive::getDefaultKind(), true, false, nullptr)) return E; -} else if (Args.count("file")) { +} else if (auto It = Args.find("file"); It != Args.end()) { if (Extracted.size() > 1) WithColor::warning(errs(), PackagerExecutable) -<< "Multiple inputs match to a single file, '" << Args["file"] +<< "Multiple inputs match to a single file, '" << It->second << "'\n"; - if (Error E = writeFile(Args["file"], Extracted.back()->getImage())) + if (Error E = writeFile(It->second, Extracted.back()->getImage())) return E; } else { uint64_t Idx = 0; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-offload-packager] Avoid repeated hash lookups (NFC) (PR #128297)
https://github.com/kazutakahirata closed https://github.com/llvm/llvm-project/pull/128297 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Allow overriding Unknown memspaces using a ProgramState trait (PR #123003)
https://github.com/steakhal updated https://github.com/llvm/llvm-project/pull/123003 >From b59b7c783b0d84dfe41cf22875875cde015c1971 Mon Sep 17 00:00:00 2001 From: Michael Flanders Date: Mon, 13 Jan 2025 12:34:50 -0600 Subject: [PATCH] [analyzer] Allow overriding Unknown memspaces using a ProgramState trait In general, if we see an allocation, we associate the immutable memory space with the constructed memory region. This works fine if we see the allocation. However, with symbolic regions it's not great because there we don't know anything about their memory spaces, thus put them into the Unknown space. The unfortunate consequence is that once we learn about some aliasing with this Symbolic Region, we can't change the memory space to the deduced one. In this patch, we open up the memory spaces as a trait, basically allowing associating a better memory space with a memregion that was created with the Unknown memory space. As a side effect, this means that now queriing the memory space of a region depends on the State, but many places in the analyzer, such as the Store, doesn't have (and cannot have) access to the State by design. This means that some uses must solely rely on the memspaces of the region, but any other users should use the getter taking a State. --- .../StaticAnalyzer/Checkers/SValExplainer.h | 6 +- .../Core/PathSensitive/MemRegion.h| 42 -- .../Checkers/ArrayBoundChecker.cpp| 41 +- .../StaticAnalyzer/Checkers/ErrnoChecker.cpp | 2 +- .../Checkers/ExprInspectionChecker.cpp| 2 +- .../StaticAnalyzer/Checkers/MIGChecker.cpp| 4 +- .../Checkers/MacOSXAPIChecker.cpp | 11 ++- .../StaticAnalyzer/Checkers/MallocChecker.cpp | 15 ++-- .../StaticAnalyzer/Checkers/MoveChecker.cpp | 40 +- .../Checkers/NSErrorChecker.cpp | 6 +- .../Checkers/PutenvStackArrayChecker.cpp | 5 +- .../RetainCountChecker/RetainCountChecker.cpp | 8 +- .../RetainCountDiagnostics.cpp| 2 +- .../Checkers/StackAddrEscapeChecker.cpp | 79 +++ .../Checkers/UnixAPIChecker.cpp | 4 +- .../Core/BugReporterVisitors.cpp | 5 +- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 7 +- clang/lib/StaticAnalyzer/Core/MemRegion.cpp | 38 ++--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp | 12 +-- .../StaticAnalyzer/Core/SimpleSValBuilder.cpp | 4 +- 20 files changed, 201 insertions(+), 132 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h b/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h index 43a70f596a4da..519d2d5b3676b 100644 --- a/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h +++ b/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h @@ -27,6 +27,7 @@ namespace ento { class SValExplainer : public FullSValVisitor { private: ASTContext &ACtx; + ProgramStateRef State; std::string printStmt(const Stmt *S) { std::string Str; @@ -55,7 +56,8 @@ class SValExplainer : public FullSValVisitor { } public: - SValExplainer(ASTContext &Ctx) : ACtx(Ctx) {} + SValExplainer(ASTContext &Ctx, ProgramStateRef State) + : ACtx(Ctx), State(State) {} std::string VisitUnknownVal(UnknownVal V) { return "unknown value"; @@ -166,7 +168,7 @@ class SValExplainer : public FullSValVisitor { .getCanonicalType()->getAs()) return "object at " + Visit(R->getSymbol()); // Other heap-based symbolic regions are also special. -if (isa(R->getMemorySpace())) +if (R->hasMemorySpace(State)) return "heap segment that starts at " + Visit(R->getSymbol()); return "pointee of " + Visit(R->getSymbol()); } diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h index 796fb43a2fc66..89d306fb94046 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -26,6 +26,7 @@ #include "clang/Analysis/AnalysisDeclContext.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceLocation.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h" #include "llvm/ADT/DenseMap.h" @@ -119,7 +120,40 @@ class MemRegion : public llvm::FoldingSetNode { virtual MemRegionManager &getMemRegionManager() const = 0; - LLVM_ATTRIBUTE_RETURNS_NONNULL const MemSpaceRegion *getMemorySpace() const; + /// Deprecated. Gets the 'raw' memory space of a memory region's base region. + /// If the MemRegion is originally associated with Unknown memspace, then the + /// State may have a more accurate memspace for this region. + /// Use getMemorySpace(ProgramStateRef) instead. + [[nodiscard]] LLVM_ATTRIBUTE_RETURNS_NONNULL const MemSpaceRegion *
[clang] [clang][Sema] Propagate `volatile` during derived-to-base conversion (PR #127824)
@@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-dump %s | FileCheck %s antoniofrighetto wrote: Added a test in CodeGen too, thanks! https://github.com/llvm/llvm-project/pull/127824 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Propagate qualifiers during derived-to-base conversion (PR #127824)
https://github.com/antoniofrighetto edited https://github.com/llvm/llvm-project/pull/127824 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Propagate qualifiers during derived-to-base conversion (PR #127824)
https://github.com/antoniofrighetto edited https://github.com/llvm/llvm-project/pull/127824 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Propagate qualifiers during derived-to-base conversion (PR #127824)
https://github.com/antoniofrighetto updated https://github.com/llvm/llvm-project/pull/127824 >From aebd5455e9cf583b9f5a29c68d5217f49c7a49b5 Mon Sep 17 00:00:00 2001 From: Antonio Frighetto Date: Wed, 19 Feb 2025 16:47:18 +0100 Subject: [PATCH 1/2] [clang][Sema] Propagate qualifiers during derived-to-base conversion When accessing a field member through a derived-to-base conversion, ensure qualifiers are propagated to the base class subobject. Fixes: https://github.com/llvm/llvm-project/issues/127683. --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaExpr.cpp | 6 ++-- clang/test/CodeGenCXX/derived-to-base.cpp | 25 ++ .../SemaCXX/derived-to-base-cv-qualifiers.cpp | 34 +++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 clang/test/SemaCXX/derived-to-base-cv-qualifiers.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 62a64ff57599d..c96c79c8e6d6c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -171,6 +171,8 @@ Bug Fixes to C++ Support - The initialization kind of elements of structured bindings direct-list-initialized from an array is corrected to direct-initialization. - Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. (#GH127327) +- Clang was previously coalescing volatile writes to members of volatile base class subobjects. + The issue has been addressed by propagating qualifiers during derived-to-base conversions in the AST. (#GH127824) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index fad15bf95c415..c4d18609316ab 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3107,8 +3107,10 @@ Sema::PerformObjectMemberConversion(Expr *From, /*IgnoreAccess=*/true)) return ExprError(); - return ImpCastExprToType(From, DestType, CK_UncheckedDerivedToBase, - VK, &BasePath); + DestType = Context.getQualifiedType(DestType, FromType.getQualifiers()); + + return ImpCastExprToType(From, DestType, CK_UncheckedDerivedToBase, VK, + &BasePath); } bool Sema::UseArgumentDependentLookup(const CXXScopeSpec &SS, diff --git a/clang/test/CodeGenCXX/derived-to-base.cpp b/clang/test/CodeGenCXX/derived-to-base.cpp index c8dbd5bf5cb05..c09a12b728bbb 100644 --- a/clang/test/CodeGenCXX/derived-to-base.cpp +++ b/clang/test/CodeGenCXX/derived-to-base.cpp @@ -46,4 +46,29 @@ namespace test3 { } } +// Ensure volatile is preserved during derived-to-base conversion. +namespace PR127683 { + +struct Base { + int Val; +}; + +struct Derived : Base { }; + +volatile Derived Obj; + +// CHECK-LABEL: define void @_ZN8PR12768319test_volatile_storeEv() +// CHECK: store volatile i32 0, ptr @_ZN8PR1276833ObjE, align 4 +void test_volatile_store() { + Obj.Val = 0; +} + +// CHECK-LABEL: define void @_ZN8PR12768318test_volatile_loadEv() +// CHECK: %0 = load volatile i32, ptr @_ZN8PR1276833ObjE, align 4 +void test_volatile_load() { + [[maybe_unused]] int Val = Obj.Val; +} + +} + // CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} } diff --git a/clang/test/SemaCXX/derived-to-base-cv-qualifiers.cpp b/clang/test/SemaCXX/derived-to-base-cv-qualifiers.cpp new file mode 100644 index 0..02a5bf8f6cecf --- /dev/null +++ b/clang/test/SemaCXX/derived-to-base-cv-qualifiers.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-dump %s | FileCheck %s + +// Ensure volatile is preserved during derived-to-base conversion. +namespace PR127683 { + +struct Base { + int Val; +}; + +struct Derived : Base { }; + +volatile Derived Obj; + +// CHECK: |-FunctionDecl {{.*}} test_volatile_store 'void ()' +// CHECK-NEXT: `-CompoundStmt {{.*}} +// CHECK-NEXT: `-BinaryOperator {{.*}} 'volatile int' lvalue '=' +// CHECK-NEXT: |-MemberExpr {{.*}} 'volatile int' lvalue .Val +// CHECK-NEXT: | `-ImplicitCastExpr {{.*}} 'volatile PR127683::Base' lvalue +void test_volatile_store() { + Obj.Val = 0; +} + +// CHECK: `-FunctionDecl {{.*}} test_volatile_load 'void ()' +// CHECK-NEXT: `-CompoundStmt {{.*}} +// CHECK-NEXT: `-DeclStmt {{.*}} +// CHECK-NEXT: `-VarDecl {{.*}} Val 'int' cinit +// CHECK-NEXT: |-ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: | `-MemberExpr {{.*}} 'volatile int' lvalue .Val +// CHECK-NEXT: | `-ImplicitCastExpr {{.*}} 'volatile PR127683::Base' lvalue +void test_volatile_load() { + [[maybe_unused]] int Val = Obj.Val; +} + +} >From 6b49fd9dd1ada060385b2f07c34227602bf81655 Mon Sep 17 00:00:00 2001 From: Antonio Frighetto Date: Sat, 22 Feb 2025 16:42:36 +0100 Subject: [PATCH 2/2] !fixup fix ci issue --- clang/lib/Sema/SemaExpr.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaExpr.cp
[clang] [clang][Sema] Propagate qualifiers during derived-to-base conversion (PR #127824)
https://github.com/antoniofrighetto updated https://github.com/llvm/llvm-project/pull/127824 >From aebd5455e9cf583b9f5a29c68d5217f49c7a49b5 Mon Sep 17 00:00:00 2001 From: Antonio Frighetto Date: Wed, 19 Feb 2025 16:47:18 +0100 Subject: [PATCH 1/2] [clang][Sema] Propagate qualifiers during derived-to-base conversion When accessing a field member through a derived-to-base conversion, ensure qualifiers are propagated to the base class subobject. Fixes: https://github.com/llvm/llvm-project/issues/127683. --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaExpr.cpp | 6 ++-- clang/test/CodeGenCXX/derived-to-base.cpp | 25 ++ .../SemaCXX/derived-to-base-cv-qualifiers.cpp | 34 +++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 clang/test/SemaCXX/derived-to-base-cv-qualifiers.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 62a64ff57599d..c96c79c8e6d6c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -171,6 +171,8 @@ Bug Fixes to C++ Support - The initialization kind of elements of structured bindings direct-list-initialized from an array is corrected to direct-initialization. - Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. (#GH127327) +- Clang was previously coalescing volatile writes to members of volatile base class subobjects. + The issue has been addressed by propagating qualifiers during derived-to-base conversions in the AST. (#GH127824) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index fad15bf95c415..c4d18609316ab 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3107,8 +3107,10 @@ Sema::PerformObjectMemberConversion(Expr *From, /*IgnoreAccess=*/true)) return ExprError(); - return ImpCastExprToType(From, DestType, CK_UncheckedDerivedToBase, - VK, &BasePath); + DestType = Context.getQualifiedType(DestType, FromType.getQualifiers()); + + return ImpCastExprToType(From, DestType, CK_UncheckedDerivedToBase, VK, + &BasePath); } bool Sema::UseArgumentDependentLookup(const CXXScopeSpec &SS, diff --git a/clang/test/CodeGenCXX/derived-to-base.cpp b/clang/test/CodeGenCXX/derived-to-base.cpp index c8dbd5bf5cb05..c09a12b728bbb 100644 --- a/clang/test/CodeGenCXX/derived-to-base.cpp +++ b/clang/test/CodeGenCXX/derived-to-base.cpp @@ -46,4 +46,29 @@ namespace test3 { } } +// Ensure volatile is preserved during derived-to-base conversion. +namespace PR127683 { + +struct Base { + int Val; +}; + +struct Derived : Base { }; + +volatile Derived Obj; + +// CHECK-LABEL: define void @_ZN8PR12768319test_volatile_storeEv() +// CHECK: store volatile i32 0, ptr @_ZN8PR1276833ObjE, align 4 +void test_volatile_store() { + Obj.Val = 0; +} + +// CHECK-LABEL: define void @_ZN8PR12768318test_volatile_loadEv() +// CHECK: %0 = load volatile i32, ptr @_ZN8PR1276833ObjE, align 4 +void test_volatile_load() { + [[maybe_unused]] int Val = Obj.Val; +} + +} + // CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} } diff --git a/clang/test/SemaCXX/derived-to-base-cv-qualifiers.cpp b/clang/test/SemaCXX/derived-to-base-cv-qualifiers.cpp new file mode 100644 index 0..02a5bf8f6cecf --- /dev/null +++ b/clang/test/SemaCXX/derived-to-base-cv-qualifiers.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-dump %s | FileCheck %s + +// Ensure volatile is preserved during derived-to-base conversion. +namespace PR127683 { + +struct Base { + int Val; +}; + +struct Derived : Base { }; + +volatile Derived Obj; + +// CHECK: |-FunctionDecl {{.*}} test_volatile_store 'void ()' +// CHECK-NEXT: `-CompoundStmt {{.*}} +// CHECK-NEXT: `-BinaryOperator {{.*}} 'volatile int' lvalue '=' +// CHECK-NEXT: |-MemberExpr {{.*}} 'volatile int' lvalue .Val +// CHECK-NEXT: | `-ImplicitCastExpr {{.*}} 'volatile PR127683::Base' lvalue +void test_volatile_store() { + Obj.Val = 0; +} + +// CHECK: `-FunctionDecl {{.*}} test_volatile_load 'void ()' +// CHECK-NEXT: `-CompoundStmt {{.*}} +// CHECK-NEXT: `-DeclStmt {{.*}} +// CHECK-NEXT: `-VarDecl {{.*}} Val 'int' cinit +// CHECK-NEXT: |-ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: | `-MemberExpr {{.*}} 'volatile int' lvalue .Val +// CHECK-NEXT: | `-ImplicitCastExpr {{.*}} 'volatile PR127683::Base' lvalue +void test_volatile_load() { + [[maybe_unused]] int Val = Obj.Val; +} + +} >From da6e4602f7381946d8a0c0d0d41b89ffc951de6a Mon Sep 17 00:00:00 2001 From: Antonio Frighetto Date: Sat, 22 Feb 2025 16:42:36 +0100 Subject: [PATCH 2/2] !fixup fix ci issue --- clang/lib/Sema/SemaExpr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaExpr.cpp
[clang] [clang][Sema] Propagate qualifiers during derived-to-base conversion (PR #127824)
@@ -3107,8 +3107,11 @@ Sema::PerformObjectMemberConversion(Expr *From, /*IgnoreAccess=*/true)) return ExprError(); - return ImpCastExprToType(From, DestType, CK_UncheckedDerivedToBase, - VK, &BasePath); + if (FromType.isVolatileQualified()) +DestType.addVolatile(); antoniofrighetto wrote: EDIT: Moving from: ```cpp DestType = Context.getQualifiedType(DestType, FromType.getQualifiers()); ``` To CVR ones for now: ```cpp DestType.withCVRQualifiers(FromType.getCVRQualifiers()); ``` Per CI failure [here](https://buildkite.com/llvm-project/github-pull-requests/builds/149797#01952e46-e199-450d-978b-2f763cd9b9c0), due to incompatibility between address spaces. Not completely sure if we should setAddressSpace of DestType AS one to the one of FromType, before getQualifiedType. https://github.com/llvm/llvm-project/pull/127824 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add cir-opt tool to exercise CIR dialect parsing (PR #128254)
@@ -0,0 +1,32 @@ +get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) +get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) + +include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include) +include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) + +add_clang_tool(cir-opt + cir-opt.cpp +) + +clang_target_link_libraries(cir-opt + PRIVATE + clangCIR + clangCIRLoweringDirectToLLVM + MLIRCIR xlauko wrote: nit: `MLIRCIR` comes transitively from `clangCIR` no need for it here https://github.com/llvm/llvm-project/pull/128254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add cir-opt tool to exercise CIR dialect parsing (PR #128254)
@@ -0,0 +1,46 @@ +//===--===// +// +// 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 +// +//===--===// +// +// Similar to MLIR/LLVM's "opt" tools but also deals with analysis and custom +// arguments. TODO: this is basically a copy from MlirOptMain.cpp, but capable +// of module emission as specified by the user. +// +//===--===// + +#include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" +#include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/InitAllPasses.h" +#include "mlir/Pass/PassManager.h" +#include "mlir/Pass/PassOptions.h" +#include "mlir/Pass/PassRegistry.h" +#include "mlir/Tools/mlir-opt/MlirOptMain.h" +#include "clang/CIR/Dialect/IR/CIRDialect.h" +#include "clang/CIR/Passes.h" + +struct CIRToLLVMPipelineOptions +: public mlir::PassPipelineOptions {}; + +int main(int argc, char **argv) { + // TODO: register needed MLIR passes for CIR? + mlir::DialectRegistry registry; + registry.insert(); + + mlir::PassPipelineRegistration pipeline( + "cir-to-llvm", "", + [](mlir::OpPassManager &pm, const CIRToLLVMPipelineOptions &options) { +cir::direct::populateCIRToLLVMPasses(pm); + }); + + mlir::registerTransformsPasses(); + + return failed(MlirOptMain( xlauko wrote: ```suggestion return mlir::asMainReturnCode(MlirOptMain( ``` https://github.com/llvm/llvm-project/pull/128254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add cir-opt tool to exercise CIR dialect parsing (PR #128254)
https://github.com/xlauko commented: LGTM https://github.com/llvm/llvm-project/pull/128254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add cir-opt tool to exercise CIR dialect parsing (PR #128254)
https://github.com/xlauko edited https://github.com/llvm/llvm-project/pull/128254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f0088ee - [analyzer] Delay the checker constructions after parsing (#127409)
Author: Balazs Benics Date: 2025-02-22T10:52:31+01:00 New Revision: f0088ee87cecfb442921251b4a70f96cf3474a15 URL: https://github.com/llvm/llvm-project/commit/f0088ee87cecfb442921251b4a70f96cf3474a15 DIFF: https://github.com/llvm/llvm-project/commit/f0088ee87cecfb442921251b4a70f96cf3474a15.diff LOG: [analyzer] Delay the checker constructions after parsing (#127409) If we were to delay checker constructions after we have a filled ASTContext, then we could get rid of a bunch of "lazy initializers" in checkers. Turns out in the register functions of the checkers we could transfer the ASTContext and all other things to checkers, so those could benefit from in-class initializers and const fields. For example, if a checker would take the ASTContext as the first field, then the rest of the fields could use it in their in-class initializers, so the ctor of the checker would only need to set a single field! This would open uup countless opportunities for cleaning up the asthetics of our checkers. I attached a single use-case for the AST and the PP as demonstrating purposes. You can imagine the rest. **FYI: This may be a breaking change** to some downstream users that may had some means to attach different listeners and what not to e.g. the Preprocessor inside their checker register functions. Since we delay the calls to these register fns after parsing is already done, they would of course miss the parsing Preprocessor events. Added: Modified: clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp index da2d16ca9b5dd..10dfa73cc522d 100644 --- a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp @@ -40,17 +40,28 @@ enum class OpenVariant { OpenAt }; +static std::optional getCreateFlagValue(const ASTContext &Ctx, + const Preprocessor &PP) { + std::optional MacroVal = tryExpandAsInteger("O_CREAT", PP); + if (MacroVal.has_value()) +return MacroVal; + + // If we failed, fall-back to known values. + if (Ctx.getTargetInfo().getTriple().getVendor() == llvm::Triple::Apple) +return {0x0200}; + return MacroVal; +} + namespace { -class UnixAPIMisuseChecker -: public Checker> { +class UnixAPIMisuseChecker : public Checker { const BugType BT_open{this, "Improper use of 'open'", categories::UnixAPI}; const BugType BT_getline{this, "Improper use of getdelim", categories::UnixAPI}; const BugType BT_pthreadOnce{this, "Improper use of 'pthread_once'", categories::UnixAPI}; const BugType BT_ArgumentNull{this, "NULL pointer", categories::UnixAPI}; - mutable std::optional Val_O_CREAT; + const std::optional Val_O_CREAT; ProgramStateRef EnsurePtrNotNull(SVal PtrVal, const Expr *PtrExpr, CheckerContext &C, @@ -63,6 +74,9 @@ class UnixAPIMisuseChecker const Expr *SizePtrExpr, CheckerContext &C, ProgramStateRef State) const; public: + UnixAPIMisuseChecker(const ASTContext &Ctx, const Preprocessor &PP) + : Val_O_CREAT(getCreateFlagValue(Ctx, PP)) {} + void checkASTDecl(const TranslationUnitDecl *TU, AnalysisManager &Mgr, BugReporter &BR) const; @@ -134,20 +148,6 @@ ProgramStateRef UnixAPIMisuseChecker::EnsurePtrNotNull( return PtrNotNull; } -void UnixAPIMisuseChecker::checkASTDecl(const TranslationUnitDecl *TU, -AnalysisManager &Mgr, -BugReporter &) const { - // The definition of O_CREAT is platform specific. - // Try to get the macro value from the preprocessor. - Val_O_CREAT = tryExpandAsInteger("O_CREAT", Mgr.getPreprocessor()); - // If we failed, fall-back to known values. - if (!Val_O_CREAT) { -if (TU->getASTContext().getTargetInfo().getTriple().getVendor() == -llvm::Triple::Apple) - Val_O_CREAT = 0x0200; - } -} - //===--===// // "open" (man 2 open) //===--===/ @@ -262,7 +262,7 @@ void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C, return; } - if (!Val_O_CREAT) { + if (!Val_O_CREAT.has_value()) { return; } @@ -276,7 +276,7 @@ void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C, } NonLoc oflags = V.castAs(); NonLoc ocreateFlag = C.getSValBuilder() - .makeIntVal(*Val_O_CREAT, oflagsEx->getType()) + .makeIntVal(Val_O_CREAT.value(), oflagsEx->getType()) .castAs(); SVal maskedFlagsUC = C.getSValBuilder().evalBinOpNN(
[clang] [analyzer] Delay the checker constructions after parsing (PR #127409)
https://github.com/steakhal closed https://github.com/llvm/llvm-project/pull/127409 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy Author: None (isuckatcs) Changes In C++, `true` is considered a keyword by the preprocessor so an `#if true` enters the true branch, while in C, ``true`` is not treated as a special keyword by the preprocessor, so the false branch is entered. The following snippet returns `1` in C++, but `0` in C. ```c++ int main() { #if true return 1; #else return 0; #endif } ``` The check identifies such cases, when `true` is used without being defined first and also offers fix-its in some cases. --- Full diff: https://github.com/llvm/llvm-project/pull/128265.diff 8 Files Affected: - (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+2) - (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1) - (added) clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp (+123) - (added) clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.h (+34) - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5) - (added) clang-tools-extra/docs/clang-tidy/checks/bugprone/true-macro.rst (+22) - (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) - (added) clang-tools-extra/test/clang-tidy/checkers/bugprone/true-macro-defintion.c (+43) ``diff diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index c5f0b5b28418f..6d993669f2303 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -85,6 +85,7 @@ #include "TerminatingContinueCheck.h" #include "ThrowKeywordMissingCheck.h" #include "TooSmallLoopVariableCheck.h" +#include "TrueMacroCheck.h" #include "UncheckedOptionalAccessCheck.h" #include "UndefinedMemoryManipulationCheck.h" #include "UndelegatedConstructorCheck.h" @@ -247,6 +248,7 @@ class BugproneModule : public ClangTidyModule { "bugprone-throw-keyword-missing"); CheckFactories.registerCheck( "bugprone-too-small-loop-variable"); +CheckFactories.registerCheck("bugprone-true-macro"); CheckFactories.registerCheck( "bugprone-unchecked-optional-access"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index e8309c68b7fca..e479c3c137809 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -86,6 +86,7 @@ add_clang_library(clangTidyBugproneModule STATIC TerminatingContinueCheck.cpp ThrowKeywordMissingCheck.cpp TooSmallLoopVariableCheck.cpp + TrueMacroCheck.cpp UncheckedOptionalAccessCheck.cpp UndefinedMemoryManipulationCheck.cpp UndelegatedConstructorCheck.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp new file mode 100644 index 0..4b1375db34039 --- /dev/null +++ b/clang-tools-extra/clang-tidy/bugprone/TrueMacroCheck.cpp @@ -0,0 +1,123 @@ +//===--- TrueMacroCheck.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 "TrueMacroCheck.h" +#include "clang/Lex/MacroInfo.h" +#include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { +namespace { + +class MacroCallback : public PPCallbacks { + static constexpr const char *TrueMacroSpelling = "true"; + +public: + MacroCallback(TrueMacroCheck *Check, Preprocessor *PP) + : Check(Check), PP(PP) {} + void MacroDefined(const Token &MacroNameTok, +const MacroDirective *MD) override { +if (TrueDefined) + return; + +const MacroInfo *MI = MD->getMacroInfo(); +for (const Token &Tok : MI->tokens()) { + if (PP->getSpelling(Tok) == TrueMacroSpelling) +emitDiagnostics(Tok.getLocation(), +{Tok.getLocation(), Tok.getEndLoc()}); +} + +if (PP->getSpelling(MacroNameTok) == TrueMacroSpelling) + TrueDefined = true; + } + + virtual void MacroUndefined(const Token &MacroNameTok, + const MacroDefinition &MD, + const MacroDirective *Undef) override { +if (PP->getSpelling(MacroNameTok) == TrueMacroSpelling) + TrueDefined = false; + } + + virtual void If(SourceLocation Loc, SourceRange ConditionRange, + ConditionValueKind ConditionValue) override { +StringRef Condition = +Lexer::getSourceText(CharSourceRange::getTokenRange(ConditionRange), + PP->getSourceManager(), PP-
[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)
https://github.com/isuckatcs ready_for_review https://github.com/llvm/llvm-project/pull/128265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits