[clang-tools-extra] [tool] Remove legacy argument `-ignore-insert-conflict` from `run-clang-tidy.py` (PR #127066)
https://github.com/loumalouomega updated https://github.com/llvm/llvm-project/pull/127066 From 6c210298a5aab4eeb0d155534d739e21ba315469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Thu, 13 Feb 2025 15:28:30 +0100 Subject: [PATCH 1/2] [tool] Remove legacy argument `-ignore-insert-conflict` from `run-clang-tidy.py` --- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py index f1b934f7139e9..acee87c860aa0 100755 --- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py +++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py @@ -200,7 +200,6 @@ def apply_fixes( ) -> None: """Calls clang-apply-fixes on a given directory.""" invocation = [clang_apply_replacements_binary] -invocation.append("-ignore-insert-conflict") if args.format: invocation.append("-format") if args.style: From 65adc60c634d93eb2186ddb18ada0131698bcabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Fri, 14 Feb 2025 09:35:47 +0100 Subject: [PATCH 2/2] Optional --- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py index acee87c860aa0..3301cf5a84a93 100755 --- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py +++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py @@ -198,8 +198,12 @@ def find_binary(arg: str, name: str, build_path: str) -> str: def apply_fixes( args: argparse.Namespace, clang_apply_replacements_binary: str, tmpdir: str ) -> None: -"""Calls clang-apply-fixes on a given directory.""" +"""Calls clang-apply-replacements on a given directory.""" invocation = [clang_apply_replacements_binary] + +if args.ignore_insert_conflict: # Only append if the user specified it +invocation.append("-ignore-insert-conflict") + if args.format: invocation.append("-format") if args.style: @@ -445,6 +449,11 @@ async def main() -> None: action="store_true", help="Allow empty enabled checks.", ) +parser.add_argument( +"-ignore-insert-conflict", +action="store_true", +help="Ignore insert conflict when applying fixes.", +) args = parser.parse_args() db_path = "compile_commands.json" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [tool] Add support for `-ignore-insert-conflict` option in `clang-apply-replacements` (PR #127066)
https://github.com/loumalouomega edited https://github.com/llvm/llvm-project/pull/127066 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [tool] Remove legacy argument `-ignore-insert-conflict` from `run-clang-tidy.py` (PR #127066)
https://github.com/loumalouomega edited https://github.com/llvm/llvm-project/pull/127066 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-reorder-fields] Avoid repeated hash lookups (NFC) (PR #127165)
https://github.com/nikic approved this pull request. https://github.com/llvm/llvm-project/pull/127165 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][docs] Fix DR status for P2280R4 (PR #127166)
https://github.com/frederick-vs-ja edited https://github.com/llvm/llvm-project/pull/127166 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid repeated map lookups (NFC) (PR #127167)
https://github.com/PiotrZSL approved this pull request. https://github.com/llvm/llvm-project/pull/127167 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][docs] Fix DR status for P2280R4 (PR #127166)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/127166 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][docs] Fix DR status for P2280R4 (PR #127166)
https://github.com/Endilll commented: I'd like to see a test that checks that it's available in C++23 but not C++20 (with a fixme on this). You can also point me out to an existing one. https://github.com/llvm/llvm-project/pull/127166 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][docs] Fix DR status for P2280R4 (PR #127166)
@@ -510,6 +510,12 @@ C++23 implementation status Yes + + +(12): In Clang 20, this change is not yet retroactively Endilll wrote: ```suggestion (12): This feature is not yet available in C++20 and earlier modes. ``` https://github.com/llvm/llvm-project/pull/127166 ___ 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: modernize-use-scoped-lock (PR #126434)
vbvictor wrote: @PiotrZSL, I fixed all your comments and improved check by adding new `WarnOnUsingAndTypedef` option. I am still not sure whether It is good to have this option or not. https://github.com/llvm/llvm-project/pull/126434 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analysis] Fix flaky clang/test/Analysis/live-stmts.cpp test (PR #126913)
metaflow wrote: > > For what it worth this change made it persistently failing in my setup. > > I'm not sure I follow you. The test is disabled on all platforms > unconditionally on main. Since #127034 yea, I know it was disabled. I meant that this very 55f3df875d3a266c566f593357e2290879f49321 made it constantly failing. https://github.com/llvm/llvm-project/pull/126913 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add hack in ArrayBound to cover up missing casts (PR #127117)
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/127117 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 5be4536 - [clang-reorder-fields] Avoid repeated hash lookups (NFC) (#127165)
Author: Kazu Hirata Date: 2025-02-14T01:33:17-08:00 New Revision: 5be4536d091d7b927ceaa30a263ab5629f9008cc URL: https://github.com/llvm/llvm-project/commit/5be4536d091d7b927ceaa30a263ab5629f9008cc DIFF: https://github.com/llvm/llvm-project/commit/5be4536d091d7b927ceaa30a263ab5629f9008cc.diff LOG: [clang-reorder-fields] Avoid repeated hash lookups (NFC) (#127165) Added: Modified: clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp Removed: diff --git a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp index aeb7fe90f2175..ea0207619fb2b 100644 --- a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp +++ b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp @@ -70,11 +70,12 @@ getNewFieldsOrder(const RecordDecl *Definition, } SmallVector NewFieldsOrder; for (const auto &Name : DesiredFieldsOrder) { -if (!NameToIndex.count(Name)) { +auto It = NameToIndex.find(Name); +if (It == NameToIndex.end()) { llvm::errs() << "Field " << Name << " not found in definition.\n"; return {}; } -NewFieldsOrder.push_back(NameToIndex[Name]); +NewFieldsOrder.push_back(It->second); } assert(NewFieldsOrder.size() == NameToIndex.size()); return NewFieldsOrder; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-reorder-fields] Avoid repeated hash lookups (NFC) (PR #127165)
https://github.com/kazutakahirata closed https://github.com/llvm/llvm-project/pull/127165 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 1bc2f1c - [clang-tidy] Avoid repeated map lookups (NFC) (#127167)
Author: Kazu Hirata Date: 2025-02-14T01:33:51-08:00 New Revision: 1bc2f1c83f417cdbc11d9cfde780d96aa429ca9f URL: https://github.com/llvm/llvm-project/commit/1bc2f1c83f417cdbc11d9cfde780d96aa429ca9f DIFF: https://github.com/llvm/llvm-project/commit/1bc2f1c83f417cdbc11d9cfde780d96aa429ca9f.diff LOG: [clang-tidy] Avoid repeated map lookups (NFC) (#127167) Added: Modified: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp Removed: diff --git a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp index 43b69a24bdb16..07071a1f6d2fe 100644 --- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp @@ -119,13 +119,12 @@ void NonConstParameterCheck::addParm(const ParmVarDecl *Parm) { T->getPointeeType()->isFloatingType())) return; - if (Parameters.find(Parm) != Parameters.end()) + auto [It, Inserted] = Parameters.try_emplace(Parm); + if (!Inserted) return; - ParmInfo PI; - PI.IsReferenced = false; - PI.CanBeConst = true; - Parameters[Parm] = PI; + It->second.IsReferenced = false; + It->second.CanBeConst = true; } void NonConstParameterCheck::setReferenced(const DeclRefExpr *Ref) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid repeated map lookups (NFC) (PR #127167)
https://github.com/kazutakahirata closed https://github.com/llvm/llvm-project/pull/127167 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add partial-inlining options (PR #73210)
TiborGY wrote: @Jolyon0202 Your patch looks valid at first glance, but there is a merge conflict. Could you resolve that please? https://github.com/llvm/llvm-project/pull/73210 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add hack in ArrayBound to cover up missing casts (PR #127117)
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/127117 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7eadc19 - [RISCV] Add a generic OOO CPU (#120712)
Author: Pengcheng Wang Date: 2025-02-14T17:35:02+08:00 New Revision: 7eadc1960d199676f04add402bb0aa6f65b7b234 URL: https://github.com/llvm/llvm-project/commit/7eadc1960d199676f04add402bb0aa6f65b7b234 DIFF: https://github.com/llvm/llvm-project/commit/7eadc1960d199676f04add402bb0aa6f65b7b234.diff LOG: [RISCV] Add a generic OOO CPU (#120712) We add a generic out-of-order CPU model here just like what GCC has done. People may use this model to evaluate some optimizations, and more importantly, people can use this model as a template to customize their own CPU models. The design (units, cycles, ...) of this model is random so don't take it seriously. Added: llvm/lib/Target/RISCV/RISCVSchedGenericOOO.td llvm/test/tools/llvm-mca/RISCV/GenericOOO/atomic.s llvm/test/tools/llvm-mca/RISCV/GenericOOO/floating-point.s llvm/test/tools/llvm-mca/RISCV/GenericOOO/integer.s Modified: clang/docs/ReleaseNotes.rst clang/test/Misc/target-invalid-cpu-note/riscv.c llvm/lib/Target/RISCV/RISCV.td llvm/lib/Target/RISCV/RISCVProcessors.td Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 03bddbe3e983a..5c69415d16489 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -217,6 +217,8 @@ LoongArch Support RISC-V Support ^^ +- Add support for `-mtune=generic-ooo` (a generic out-of-order model). + CUDA/HIP Language Changes ^ diff --git a/clang/test/Misc/target-invalid-cpu-note/riscv.c b/clang/test/Misc/target-invalid-cpu-note/riscv.c index fb54dcb5b3a93..6e4323958957a 100644 --- a/clang/test/Misc/target-invalid-cpu-note/riscv.c +++ b/clang/test/Misc/target-invalid-cpu-note/riscv.c @@ -66,6 +66,7 @@ // TUNE-RISCV32-SAME: {{^}}, syntacore-scr4-rv32 // TUNE-RISCV32-SAME: {{^}}, syntacore-scr5-rv32 // TUNE-RISCV32-SAME: {{^}}, generic +// TUNE-RISCV32-SAME: {{^}}, generic-ooo // TUNE-RISCV32-SAME: {{^}}, rocket // TUNE-RISCV32-SAME: {{^}}, sifive-7-series // TUNE-RISCV32-SAME: {{$}} @@ -96,6 +97,7 @@ // TUNE-RISCV64-SAME: {{^}}, veyron-v1 // TUNE-RISCV64-SAME: {{^}}, xiangshan-nanhu // TUNE-RISCV64-SAME: {{^}}, generic +// TUNE-RISCV64-SAME: {{^}}, generic-ooo // TUNE-RISCV64-SAME: {{^}}, rocket // TUNE-RISCV64-SAME: {{^}}, sifive-7-series // TUNE-RISCV64-SAME: {{$}} diff --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td index 87c07c3cd505f..2c2271e486a84 100644 --- a/llvm/lib/Target/RISCV/RISCV.td +++ b/llvm/lib/Target/RISCV/RISCV.td @@ -45,7 +45,7 @@ include "RISCVMacroFusion.td" //===--===// // RISC-V Scheduling Models //===--===// - +include "RISCVSchedGenericOOO.td" include "RISCVSchedMIPSP8700.td" include "RISCVSchedRocket.td" include "RISCVSchedSiFive7.td" diff --git a/llvm/lib/Target/RISCV/RISCVProcessors.td b/llvm/lib/Target/RISCV/RISCVProcessors.td index b5eea138732a5..c2d98c2180299 100644 --- a/llvm/lib/Target/RISCV/RISCVProcessors.td +++ b/llvm/lib/Target/RISCV/RISCVProcessors.td @@ -103,6 +103,8 @@ def GENERIC_RV64 : RISCVProcessorModel<"generic-rv64", // Support generic for compatibility with other targets. The triple will be used // to change to the appropriate rv32/rv64 version. def GENERIC : RISCVTuneProcessorModel<"generic", NoSchedModel>, GenericTuneInfo; +def GENERIC_OOO : RISCVTuneProcessorModel<"generic-ooo", GenericOOOModel>, + GenericTuneInfo; def MIPS_P8700 : RISCVProcessorModel<"mips-p8700", MIPSP8700Model, diff --git a/llvm/lib/Target/RISCV/RISCVSchedGenericOOO.td b/llvm/lib/Target/RISCV/RISCVSchedGenericOOO.td new file mode 100644 index 0..be9c4ddf7cf48 --- /dev/null +++ b/llvm/lib/Target/RISCV/RISCVSchedGenericOOO.td @@ -0,0 +1,499 @@ +//===-- RISCVSchedGenericOOO.td - Generic OOO Processor *- tablegen -*-===// +// +// 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 +// +//===--===// + +//===--===// +// We assume that: +// * 6-issue out-of-order CPU with 192 ROB entries. +// * Units: +// * IXU (Integer ALU Unit): 4 units, only one can execute mul/div. +// * FXU (Floating-point Unit): 2 units. +// * LSU (Load/Store Unit): 2 units. +// * Latency: +// * Integer instructions: 1 cycle. +// * Multiplication instructions: 4 cycles. +// * Division instructions: 13-21 cycles. +// * Floating-point instructions: 2-6 cycles. +// * Floating-point fdiv/fsqrt instructions: 9-21 cycles. +// * Load/Store: +// * IXU: 4
[clang] [llvm] [RISCV] Add a generic OOO CPU (PR #120712)
https://github.com/wangpc-pp closed https://github.com/llvm/llvm-project/pull/120712 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules][Serialization] Delay marking pending incomplete decl chains until the end of `finishPendingActions`. (PR #121245)
ChuanqiXu9 wrote: > @zixu-w and @ChuanqiXu9 Just want to clarify policies about changes > reversion. As far as I understand it was one example in some private codebase > with no reproducer publicly available. I can understand and completely agree > if it breaks any existing test or llvm-build bot. But in this case I think it > would be good to at least wait for the review. Such reversion without > providing a reproducer does not allow to fix the issues or even verify that > it is related to this PR. This PR fixes another crash with clear reproducers. > > Sorry, didn't notice that it is LLVM bootstrap build but still, no still I > don't see steps to reproduce in #126973. CC @AaronBallman for the policy related things. And my point in the above post is, **if** we revert it in the trunk and it was backported to the release branch, we should revert it in the release branch too. My point is majorly the **if**. https://github.com/llvm/llvm-project/pull/121245 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix UEFI Target info (PR #127290)
Prabhuk wrote: More smaller fixes based on @RossComputerGuy's patch: https://github.com/llvm/llvm-project/pull/120632 https://github.com/llvm/llvm-project/pull/127290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] [DXIL] Implement the AddUint64 HLSL function and the UAddc DXIL op (PR #127137)
https://github.com/Icohedron updated https://github.com/llvm/llvm-project/pull/127137 >From 4fae5642c6e8e305cdc687b4968ba5eabaa44b50 Mon Sep 17 00:00:00 2001 From: Icohedron Date: Mon, 27 Jan 2025 11:18:09 -0800 Subject: [PATCH 1/4] Add the AddUint64 HLSL builtin function - Defines the AddUint64 HLSL builtin function - Implements the UAddc DXIL op to lower AddUint64 to DXIL --- clang/include/clang/Basic/Builtins.td | 6 ++ .../clang/Basic/DiagnosticSemaKinds.td| 2 + clang/lib/CodeGen/CGBuiltin.cpp | 45 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 21 ++ clang/lib/Sema/SemaHLSL.cpp | 47 .../test/CodeGenHLSL/builtins/AddUint64.hlsl | 71 +++ .../SemaHLSL/BuiltIns/AddUint64-errors.hlsl | 41 +++ llvm/lib/Target/DirectX/DXIL.td | 13 llvm/lib/Target/DirectX/DXILOpBuilder.cpp | 14 llvm/lib/Target/DirectX/DXILOpBuilder.h | 3 + llvm/lib/Target/DirectX/DXILOpLowering.cpp| 22 -- llvm/test/CodeGen/DirectX/UAddc.ll| 40 +++ llvm/test/CodeGen/DirectX/UAddc_errors.ll | 30 13 files changed, 348 insertions(+), 7 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/AddUint64.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/AddUint64-errors.hlsl create mode 100644 llvm/test/CodeGen/DirectX/UAddc.ll create mode 100644 llvm/test/CodeGen/DirectX/UAddc_errors.ll diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 29939242596ba..2433427a89429 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4753,6 +4753,12 @@ def GetDeviceSideMangledName : LangBuiltin<"CUDA_LANG"> { } // HLSL +def HLSLAddUint64: LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_adduint64"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + def HLSLResourceGetPointer : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_resource_getpointer"]; let Attributes = [NoThrow]; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 2fce5e88ba8a0..e78339ee924ff 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10655,6 +10655,8 @@ def err_second_argument_to_cwsc_not_pointer : Error< def err_vector_incorrect_num_elements : Error< "%select{too many|too few}0 elements in vector %select{initialization|operand}3 (expected %1 elements, have %2)">; +def err_invalid_even_odd_vector_element_count : Error< + "invalid element count of %0 in vector %select{initialization|operand}4 (expected an %select{even|odd}3 element count in the range of %1 and %2)">; def err_altivec_empty_initializer : Error<"expected initializer">; def err_invalid_neon_type_code : Error< diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 361e4c4bf2e2e..5322b38458b26 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -19445,6 +19445,51 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, return nullptr; switch (BuiltinID) { + case Builtin::BI__builtin_hlsl_adduint64: { +Value *OpA = EmitScalarExpr(E->getArg(0)); +Value *OpB = EmitScalarExpr(E->getArg(1)); +assert(E->getArg(0)->getType()->hasIntegerRepresentation() && + E->getArg(1)->getType()->hasIntegerRepresentation() && + "AddUint64 operands must have an integer representation"); +assert(((E->getArg(0)->getType()->castAs()->getNumElements() == + 2 && + E->getArg(1)->getType()->castAs()->getNumElements() == + 2) || +(E->getArg(0)->getType()->castAs()->getNumElements() == + 4 && + E->getArg(1)->getType()->castAs()->getNumElements() == + 4)) && + "input vectors must have 2 or 4 elements each"); + +llvm::Value *Result = PoisonValue::get(OpA->getType()); +uint64_t NumElements = +E->getArg(0)->getType()->castAs()->getNumElements(); +for (uint64_t i = 0; i < NumElements / 2; ++i) { + + // Obtain low and high words of inputs A and B + llvm::Value *LowA = Builder.CreateExtractElement(OpA, 2 * i + 0); + llvm::Value *HighA = Builder.CreateExtractElement(OpA, 2 * i + 1); + llvm::Value *LowB = Builder.CreateExtractElement(OpB, 2 * i + 0); + llvm::Value *HighB = Builder.CreateExtractElement(OpB, 2 * i + 1); + + // Use an uadd_with_overflow to compute the sum of low words and obtain a + // carry value + llvm::Value *Carry; + llvm::Value *LowSum = EmitOverflowIntrinsic( + *this, llvm::Intrinsic::uadd_with_overflow, LowA, LowB, Carry); + llvm::Value *ZExtCarry = Builder.CreateZExt(Carry, HighA->getType()); + + // Sum the high words and the carry
[clang] 28c52ed - [clang][X86] Support __attribute__((model("small"/"large"))) (#124834)
Author: Arthur Eubanks Date: 2025-02-14T16:35:16-08:00 New Revision: 28c52edbe33e671ace58309e60598f3342e9ca73 URL: https://github.com/llvm/llvm-project/commit/28c52edbe33e671ace58309e60598f3342e9ca73 DIFF: https://github.com/llvm/llvm-project/commit/28c52edbe33e671ace58309e60598f3342e9ca73.diff LOG: [clang][X86] Support __attribute__((model("small"/"large"))) (#124834) Following up #72078, on x86-64 this allows a global to be considered small or large regardless of the code model. For example, x86-64's medium code model by default classifies globals as small or large depending on their size relative to -mlarge-data-threshold. GPU compilations compile the same TU for both the host and device, but only codegen the host or device portions of it depending on attributes. However, we still Sema the TU, and will warn on an unknown attribute for the device compilation since this attribute is target-specific. Since they're intended for the host, accept but ignore this attribute for device compilations where the host is either unknown or known to support the attribute. Co-authored-by: @pranavk Added: clang/test/CodeGen/X86/codemodel.cpp Modified: clang/docs/ReleaseNotes.rst clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/lib/Sema/SemaDeclAttr.cpp clang/test/Sema/attr-model.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6056a6964fbcc..efaacdf18d50a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -125,6 +125,10 @@ Attribute Changes in Clang - The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names. - Clang now diagnoses use of declaration attributes on void parameters. (#GH108819) +- Clang now allows ``__attribute__((model("small")))`` and + ``__attribute__((model("large")))`` on non-TLS globals in x86-64 compilations. + This forces the global to be considered small or large in regards to the + x86-64 code model, regardless of the code model specified for the compilation. Improvements to Clang's diagnostics --- diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 4384a98d63eb3..65c91ccd75ecc 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -459,6 +459,7 @@ class TargetArch arches> : TargetSpec { } def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>; def TargetAArch64 : TargetArch<["aarch64", "aarch64_be", "aarch64_32"]>; +def TargetAMDGPU : TargetArch<["amdgcn", "r600"]>; def TargetAnyArm : TargetArch; def TargetAVR : TargetArch<["avr"]>; def TargetBPF : TargetArch<["bpfel", "bpfeb"]>; @@ -469,7 +470,9 @@ def TargetMSP430 : TargetArch<["msp430"]>; def TargetM68k : TargetArch<["m68k"]>; def TargetRISCV : TargetArch<["riscv32", "riscv64"]>; def TargetX86 : TargetArch<["x86"]>; +def TargetX86_64 : TargetArch<["x86_64"]>; def TargetAnyX86 : TargetArch<["x86", "x86_64"]>; +def TargetSPIRV : TargetArch<["spirv", "spirv32", "spirv64"]>; def TargetWebAssembly : TargetArch<["wasm32", "wasm64"]>; def TargetNVPTX : TargetArch<["nvptx", "nvptx64"]>; def TargetWindows : TargetSpec { @@ -3124,11 +3127,20 @@ def PragmaClangTextSection : InheritableAttr { let Documentation = [InternalOnly]; } -def CodeModel : InheritableAttr, TargetSpecificAttr { +// The code model attribute only applies to LoongArch and x86-64, but for NVPTX +// compilations that share code with the host, we want to ignore the attribute +// rather than warn on it. +def CodeModel +: InheritableAttr, + TargetSpecificAttr> { let Spellings = [GCC<"model">]; - let Args = [EnumArgument<"Model", "llvm::CodeModel::Model", /*is_string=*/1, - ["normal", "medium", "extreme"], ["Small", "Medium", "Large"], - /*opt=*/0, /*fake=*/0, /*isExternalType=*/1, /*isCovered=*/0>]; + let Args = [EnumArgument< + "Model", "llvm::CodeModel::Model", + /*is_string=*/1, ["small", "normal", "medium", "large", "extreme"], + ["Small", "Small", "Medium", "Large", "Large"], + /*opt=*/0, /*fake=*/0, /*isExternalType=*/1, /*isCovered=*/0>]; let Subjects = SubjectList<[NonTLSGlobalVar], ErrorDiag>; let Documentation = [CodeModelDocs]; } diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 8ab20774de034..f5362b4d59142 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -62,6 +62,16 @@ def CodeModelDocs : Documentation { let Content = [{ The ``model`` attribute allows overriding the translation unit's code model (specified by ``-mcmodel``) for a specific global variable. + +On LoongArch, allowed values are "normal", "medium", "extreme". + +On x86-64, allowed values are ``"small"`` and ``"large"``. ``"small"`` is +roughly equivalent to ``-mcmod
[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)
rniwa wrote: Thanks for the review! https://github.com/llvm/llvm-project/pull/126443 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][X86] Support __attribute__((model("small"/"large"))) (PR #124834)
aeubanks wrote: I believe all concerns have been addressed, will merge now with the approvals. Happy to follow up on any other concerns. https://github.com/llvm/llvm-project/pull/124834 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][X86] Support __attribute__((model("small"/"large"))) (PR #124834)
https://github.com/aeubanks closed https://github.com/llvm/llvm-project/pull/124834 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
https://github.com/Icohedron updated https://github.com/llvm/llvm-project/pull/127098 >From 5b093ca42fdc24f89bfccac25e6f2e17155432f6 Mon Sep 17 00:00:00 2001 From: Icohedron Date: Wed, 12 Feb 2025 21:24:00 + Subject: [PATCH 1/4] Implement the 'and' HLSL function --- clang/include/clang/Basic/Builtins.td| 6 +++ clang/lib/CodeGen/CGBuiltin.cpp | 5 +++ clang/lib/Headers/hlsl/hlsl_intrinsics.h | 16 +++ clang/lib/Sema/SemaHLSL.cpp | 11 + clang/test/CodeGenHLSL/builtins/and.hlsl | 45 clang/test/SemaHLSL/BuiltIns/and-errors.hlsl | 27 6 files changed, 110 insertions(+) create mode 100644 clang/test/CodeGenHLSL/builtins/and.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/and-errors.hlsl diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 29939242596ba..de758d88f8f92 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4765,6 +4765,12 @@ def HLSLAll : LangBuiltin<"HLSL_LANG"> { let Prototype = "bool(...)"; } +def HLSLAnd : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_and"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + def HLSLAny : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_any"]; let Attributes = [NoThrow, Const]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 361e4c4bf2e2e..82527cb5e1f7a 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -19463,6 +19463,11 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, CGM.getHLSLRuntime().getAllIntrinsic(), ArrayRef{Op0}, nullptr, "hlsl.all"); } + case Builtin::BI__builtin_hlsl_and: { +Value *Op0 = EmitScalarExpr(E->getArg(0)); +Value *Op1 = EmitScalarExpr(E->getArg(1)); +return Builder.CreateAnd(Op0, Op1, "hlsl.and"); + } case Builtin::BI__builtin_hlsl_any: { Value *Op0 = EmitScalarExpr(E->getArg(0)); return Builder.CreateIntrinsic( diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index d1f5fdff8b600..7016b45d1c641 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -249,6 +249,22 @@ bool all(double3); _HLSL_BUILTIN_ALIAS(__builtin_hlsl_all) bool all(double4); +//===--===// +// and builtins +//===--===// + +// \fn bool and(bool x, bool y) +// \brief Logically ands two boolean vectors elementwise and produces a bool vector output. + +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_and) +bool and(bool x, bool y); +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_and) +bool2 and(bool2 x, bool2 y); +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_and) +bool3 and(bool3 x, bool3 y); +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_and) +bool4 and(bool4 x, bool4 y); + //===--===// // any builtins //===--===// diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 4abd870ad6aaa..7297fb3a9e4d0 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -2245,6 +2245,17 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { break; } + case Builtin::BI__builtin_hlsl_and: { +if (SemaRef.checkArgCount(TheCall, 2)) + return true; +if (CheckVectorElementCallArgs(&SemaRef, TheCall)) + return true; +ExprResult A = TheCall->getArg(0); +QualType ArgTyA = A.get()->getType(); +// return type is the same as the input type +TheCall->setType(ArgTyA); +break; + } case Builtin::BI__builtin_hlsl_all: case Builtin::BI__builtin_hlsl_any: { if (SemaRef.checkArgCount(TheCall, 1)) diff --git a/clang/test/CodeGenHLSL/builtins/and.hlsl b/clang/test/CodeGenHLSL/builtins/and.hlsl new file mode 100644 index 0..60295f192f5cc --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/and.hlsl @@ -0,0 +1,45 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s \ +// RUN: -emit-llvm -O1 -o - | FileCheck %s + +// CHECK-LABEL: define noundef i1 @_Z15test_and_scalarbb( +// CHECK-SAME: i1 noundef [[X:%.*]], i1 noundef [[Y:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[HLSL_AND:%.*]] = and i1 [[X]], [[Y]] +// CHECK-NEXT:ret i1 [[HLSL_AND]] +// +bool test_and_scalar(bool x, bool y) { + return and(x, y); +} + +// CHECK-LABEL: define noundef <2 x i1> @_Z14test_and_bool2Dv2_bS_( +// CHECK-SAME: <2 x i1> noundef [[X:%.*]], <2 x i1> noundef [[Y:%.
[clang] [WebKit Checkers] Treat attributes as trivial (PR #127289)
https://github.com/t-rasmud approved this pull request. LGTM. https://github.com/llvm/llvm-project/pull/127289 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebKit Checkers] Treat attributes as trivial (PR #127289)
https://github.com/rniwa closed https://github.com/llvm/llvm-project/pull/127289 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e9fb239 - [WebKit Checkers] Treat attributes as trivial (#127289)
Author: Ryosuke Niwa Date: 2025-02-14T17:43:43-08:00 New Revision: e9fb2391210e20d1d4dcf8bbe37085df902ed028 URL: https://github.com/llvm/llvm-project/commit/e9fb2391210e20d1d4dcf8bbe37085df902ed028 DIFF: https://github.com/llvm/llvm-project/commit/e9fb2391210e20d1d4dcf8bbe37085df902ed028.diff LOG: [WebKit Checkers] Treat attributes as trivial (#127289) For the purpose of determining triviality, ignore all attributes. Added: Modified: clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 5b8d1184050e9..8340de9e5a7a9 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -392,6 +392,11 @@ class TrivialFunctionAnalysisVisitor return false; } + bool VisitAttributedStmt(const AttributedStmt *AS) { +// Ignore attributes. +return Visit(AS->getSubStmt()); + } + bool VisitCompoundStmt(const CompoundStmt *CS) { // A compound statement is allowed as long each individual sub-statement // is trivial. diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp index cf403851b74fd..fe7ce158eb8ba 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp @@ -376,6 +376,7 @@ class RefCounted { }; void trivial68() { point pt = { 1.0 }; } unsigned trivial69() { return offsetof(RefCounted, children); } + DerivedNumber* trivial70() { [[clang::suppress]] return static_cast(number); } static RefCounted& singleton() { static RefCounted s_RefCounted; @@ -564,6 +565,7 @@ class UnrelatedClass { getFieldTrivial().trivial67()->trivial6(); // no-warning getFieldTrivial().trivial68(); // no-warning getFieldTrivial().trivial69(); // no-warning +getFieldTrivial().trivial70(); // no-warning RefCounted::singleton().trivial18(); // no-warning RefCounted::singleton().someFunction(); // no-warning ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebKit Checkers] Treat attributes as trivial (PR #127289)
rniwa wrote: Thanks for the quick review! https://github.com/llvm/llvm-project/pull/127289 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
@@ -2079,6 +2079,14 @@ static bool CheckFloatingOrIntRepresentation(Sema *S, CallExpr *TheCall) { checkAllSignedTypes); } +static bool CheckBoolRepresentation(Sema *S, CallExpr *TheCall) { + auto checkAllBoolTypes = [](clang::QualType PassedType) -> bool { +return !PassedType->hasIntegerRepresentation(); Icohedron wrote: `clang::QualType` does not have a `hasBooleanRepresentation();` function. I assume `hasIntegerRepresentation()` should work just fine. https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add __has_target_builtin macro (PR #126324)
Artem-B wrote: > why there's a __has_builtin that's different from __can_use_builtin (or > whatever we name it), and I don't know that any of us have an answer for that my $.02 IMO it's a side effect of heterogeneous compilation, where compiler has to parse source code for multiple targets (and thus has to see each target's builtins), but can generate code only for the target we're currently compiling for. `__can_use_builtin` will give us a way to distinguish the two. It's not a perfect tool, because usability of a builtin depends on the context, but it's better than nothing. For the classic compilation, `__has_builtin` is unambiguous. On the other hand, AFAICT, there's currently only one known case where we've seen this distinction causing a problem (so far). We can fix [arm_acle.h](https://github.com/llvm/llvm-project/blob/48c92dda0086d0ec2e8c1032ec53edec743c85f3/clang/lib/Headers/arm_acle.h#L44) and postpone addition of `__can_use_builtin` until it becomes a problem, again. https://github.com/llvm/llvm-project/blob/48c92dda0086d0ec2e8c1032ec53edec743c85f3/clang/lib/Headers/arm_acle.h#L44-L48 https://github.com/llvm/llvm-project/pull/126324 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Support constexpr alignment of __builtin_assume_aligned. (PR #127223)
https://github.com/efriedma-quic commented: This is not the right fix. After we check the constant expression in Sema, we should create a ConstantExpr containing the the evaluated value, so we don't need to re-evaluate it later. https://github.com/llvm/llvm-project/pull/127223 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "[C++20][Modules][Serialization] Delay marking pending incompl… (PR #127136)
zixu-w wrote: /cherry-pick https://github.com/llvm/llvm-project/commit/912b154f3a3f8c3cebf5cc5731fd8b0749762da5 https://github.com/llvm/llvm-project/pull/127136 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Add support for flag output operand "=@cc" for SystemZ. (PR #125970)
@@ -119,6 +119,12 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo { TargetInfo::ConstraintInfo &info) const override; std::string convertConstraint(const char *&Constraint) const override { +if (llvm::StringRef(Constraint) == "@cc") { + auto Len = llvm::StringRef("@cc").size(); uweigand wrote: This is a compile-time constant. Again, in SystemZ.cpp that is hard-coded; why do we need this expression here? https://github.com/llvm/llvm-project/pull/125970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Add support for flag output operand "=@cc" for SystemZ. (PR #125970)
@@ -119,6 +119,12 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo { TargetInfo::ConstraintInfo &info) const override; std::string convertConstraint(const char *&Constraint) const override { +if (llvm::StringRef(Constraint) == "@cc") { uweigand wrote: This should read the same as the check in SystemZ.cpp above. Why do we have `llvm::StringRef(Constraint) == "@cc"` here and `!StringRef("@cc").compare(Name)` above? Decide which form is preferable and use that consistently. https://github.com/llvm/llvm-project/pull/125970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Add support for flag output operand "=@cc" for SystemZ. (PR #125970)
@@ -12112,18 +12138,36 @@ void SelectionDAGBuilder::lowerWorkItem(SwitchWorkListItem W, Value *Cond, const APInt &SmallValue = Small.Low->getValue(); const APInt &BigValue = Big.Low->getValue(); + // Incoming IR is switch table.Identify SRL/IPM/CC sequence for SystemZ + // and we want to avoid splitting condition code sequence across basic + // block for cases like (CC == 0) || (CC == 2) || (CC == 3), or + // (CC == 0) || (CC == 1) ^ (CC == 3), there could potentially be + // more cases like this. + const TargetLowering &TLI = DAG.getTargetLoweringInfo(); + bool IsSrlIPM = false; + if (NodeMap.count(Cond) && NodeMap[Cond].getNode()) +IsSrlIPM = TLI.canLowerSRL_IPM_Switch(getValue(Cond)); // Check that there is only one bit different. APInt CommonBit = BigValue ^ SmallValue; - if (CommonBit.isPowerOf2()) { + if (CommonBit.isPowerOf2() || IsSrlIPM) { SDValue CondLHS = getValue(Cond); EVT VT = CondLHS.getValueType(); SDLoc DL = getCurSDLoc(); - -SDValue Or = DAG.getNode(ISD::OR, DL, VT, CondLHS, - DAG.getConstant(CommonBit, DL, VT)); -SDValue Cond = DAG.getSetCC( -DL, MVT::i1, Or, DAG.getConstant(BigValue | SmallValue, DL, VT), -ISD::SETEQ); +SDValue Cond; + +if (CommonBit.isPowerOf2()) { + SDValue Or = DAG.getNode(ISD::OR, DL, VT, CondLHS, + DAG.getConstant(CommonBit, DL, VT)); + Cond = DAG.getSetCC(DL, MVT::i1, Or, + DAG.getConstant(BigValue | SmallValue, DL, VT), + ISD::SETEQ); +} else if (IsSrlIPM && BigValue == 3 && SmallValue == 0) { + SDValue SetCC = + DAG.getSetCC(DL, MVT::i32, CondLHS, + DAG.getConstant(SmallValue, DL, VT), ISD::SETEQ); + Cond = DAG.getSetCC(DL, MVT::i32, SetCC, + DAG.getConstant(BigValue, DL, VT), ISD::SETEQ); +} uweigand wrote: Again, this very SystemZ specific optimization shouldn't really be here. Doesn't this just revert the decision to introduce a switch statement that was made above? Could this not handled either by the `visitBr` above via the `getJumpConditionMergingParams` callback; or else fully in SystemZ DAGCombine code? https://github.com/llvm/llvm-project/pull/125970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Add support for flag output operand "=@cc" for SystemZ. (PR #125970)
@@ -2837,8 +2837,34 @@ void SelectionDAGBuilder::visitBr(const BranchInst &I) { Opcode = Instruction::And; else if (match(BOp, m_LogicalOr(m_Value(BOp0), m_Value(BOp1 Opcode = Instruction::Or; - -if (Opcode && +auto &TLI = DAG.getTargetLoweringInfo(); +const auto checkSRLIPM = [&TLI](const SDValue &Op) { + if (!Op.getNumOperands()) +return false; + SDValue OpVal = Op.getOperand(0); + SDNode *N = OpVal.getNode(); + if (N && N->getOpcode() == ISD::SRL) +return TLI.canLowerSRL_IPM_Switch(OpVal); + else if (N && OpVal.getNumOperands() && + (N->getOpcode() == ISD::AND || N->getOpcode() == ISD::OR)) { +SDValue OpVal1 = OpVal.getOperand(0); +SDNode *N1 = OpVal1.getNode(); +if (N1 && N1->getOpcode() == ISD::SRL) + return TLI.canLowerSRL_IPM_Switch(OpVal1); + } + return false; +}; +// Incoming IR here is straight line code, FindMergedConditions splits +// condition code sequence across Basic Block. DAGCombiner can't combine +// across Basic Block. Identify SRL/IPM/CC sequence for SystemZ and avoid +// transformation in FindMergedConditions. +bool BrSrlIPM = false; +if (NodeMap.count(BOp0) && NodeMap[BOp0].getNode()) { + BrSrlIPM |= checkSRLIPM(getValue(BOp0)); + if (NodeMap.count(BOp1) && NodeMap[BOp1].getNode()) +BrSrlIPM &= checkSRLIPM(getValue(BOp1)); +} uweigand wrote: This is already better than a target check, but there's still a whole lot of implicitly target-specific code here. There really shouldn't be a generic callback `canLowerSRL_IPM_Switch` - that even explicitly refers to SystemZ instruction names! If there's target-specific behavior needed here, this should be better abstracted. Note that I see there's already a target hook to guide whether or not this transformation should be performed: the `getJumpConditionMergingParams` callback that provides input to the `shouldKeepJumpConditionsTogether`. I think you should investigate whether we can create a SystemZ-specific implementation of that callback that has the desired effect of inhibiting this transformation in the cases we care about. That should then work without any common-code change to this function. https://github.com/llvm/llvm-project/pull/125970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Add support for flag output operand "=@cc" for SystemZ. (PR #125970)
@@ -2621,9 +2621,25 @@ EmitAsmStores(CodeGenFunction &CGF, const AsmStmt &S, if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) { // Target must guarantee the Value `Tmp` here is lowered to a boolean // value. - llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2); + // Lowering 'Tmp' as - 'icmp ult %Tmp , CCUpperBound'. On some targets + // CCUpperBound is not binary. CCUpperBound is 4 for SystemZ, + // interval [0, 4). With this range known, llvm.assume intrinsic guides + // optimizer to generate more optimized IR in most of the cases as + // observed for select_cc on SystemZ unit tests for flag output operands. + // For some cases for br_cc, generated IR was weird. e.g. switch table + // for simple simple comparison terms for br_cc. + StringRef Name; + if (const GCCAsmStmt *GAS = dyn_cast(&S)) +Name = GAS->getOutputName(i); + TargetInfo::ConstraintInfo Info(S.getOutputConstraint(i), Name); + bool IsValid = CGF.getTarget().validateOutputConstraint(Info); + (void)IsValid; + assert(IsValid && "Failed to parse flag output operand constraint"); uweigand wrote: All this parsing was done in the caller of this routine (`EmitAsmStmt`) already - we shouldn't do that again here. I think instead of passing the `ResultRegIsFlagReg` array down into this routine, the caller should already compute the appropriate bounds and pass an array of those bounds into this function. This might even allow us to remove the hard-coded `llvm::StringRef(OutputConstraint).starts_with("{@cc")` test in `EmitAsmStmt` and defer to the target the decision which output operands may be assumed to fall within a certain range of values. https://github.com/llvm/llvm-project/pull/125970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)
@@ -0,0 +1,114 @@ +//===--- Mustache.h -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Implementation of the Mustache templating language supports version 1.4.2 +// currently relies on llvm::json::Value for data input +// See the Mustache spec for more information +// (https://mustache.github.io/mustache.5.html). +// +// Current Features Supported: +// - Variables +// - Sections +// - Inverted Sections +// - Partials +// - Comments +// - Lambdas +// - Unescaped Variables +// +// Features Not Supported: +// - Set Delimiter +// - Blocks +// - Parents +// - Dynamic Names +// +// The Template class is container class outputs the Mustache template string +// and is main class for users. It stores all the lambdas and the ASTNode Tree. +// When the Template is instantiated it tokenize the Template String and +// creates a vector of Tokens. Then it calls a basic recursive descent parser +// to construct the ASTNode Tree. The ASTNodes are all stored in an arena +// allocator which is freed once the template class goes out of scope +// +// Usage: +// \code +// // Creating a simple template and rendering it +// auto Template = Template("Hello, {{name}}!"); +// Value Data = {{"name", "World"}}; +// StringRef Rendered = Template.render(Data); +// // Rendered == "Hello, World!" +// +// // Creating a template with a partial and rendering it +// auto Template = Template("{{>partial}}"); +// Template.registerPartial("partial", "Hello, {{name}}!"); +// Value Data = {{"name", "World"}}; +// StringRef Rendered = Template.render(Data); +// // Rendered == "Hello, World!" +// +// // Creating a template with a lambda and rendering it +// auto Template = Template("{{#lambda}}Hello, {{name}}!{{/lambda}}"); +// Template.registerLambda("lambda", []() { return true; }); +// Value Data = {{"name", "World"}}; +// StringRef Rendered = Template.render(Data); +// // Rendered == "Hello, World!" +// \endcode +// +//===--===// + +#ifndef LLVM_SUPPORT_MUSTACHE +#define LLVM_SUPPORT_MUSTACHE + +#include "Error.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/JSON.h" +#include "llvm/Support/StringSaver.h" +#include + +namespace llvm { +namespace mustache { + +using Accessor = SmallVector; +using Lambda = std::function; +using SectionLambda = std::function; + +class ASTNode; + +// A Template represents the container for the AST and the partials +// and Lambdas that are registered with it. +class Template { +public: + Template(std::string TemplateStr); + + void render(llvm::json::Value &Data, llvm::raw_ostream &OS); + + void registerPartial(std::string Name, std::string Partial); + + void registerLambda(std::string Name, Lambda Lambda); + + void registerLambda(std::string Name, SectionLambda Lambda); + + // By default the Mustache Spec Specifies that HTML special characters + // should be escaped. This function allows the user to specify which + // characters should be escaped. + void registerEscape(DenseMap Escapes); + +private: + std::string Output; + StringMap Partials; + StringMap Lambdas; + StringMap SectionLambdas; + DenseMap Escapes; + // The allocator for the ASTNode Tree + llvm::BumpPtrAllocator AstAllocator; PeterChou1 wrote: Yea it makes sense since bumpptrallocator can't be copied https://github.com/llvm/llvm-project/pull/105893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 947695a - [HLSL] Update target test to use `-cc1` rather than the clang driver (#127262)
Author: Justin Bogner Date: 2025-02-14T13:16:59-08:00 New Revision: 947695a37f1f95505826f170598e1ec126914ba1 URL: https://github.com/llvm/llvm-project/commit/947695a37f1f95505826f170598e1ec126914ba1 DIFF: https://github.com/llvm/llvm-project/commit/947695a37f1f95505826f170598e1ec126914ba1.diff LOG: [HLSL] Update target test to use `-cc1` rather than the clang driver (#127262) This test was unnecessarily invoking `dxv` if it was in your path since it used the driver rather than the `-cc1` command. Added: Modified: clang/test/CodeGenHLSL/basic-target.c Removed: diff --git a/clang/test/CodeGenHLSL/basic-target.c b/clang/test/CodeGenHLSL/basic-target.c index b97ebf90a7a10..c700e06bd5850 100644 --- a/clang/test/CodeGenHLSL/basic-target.c +++ b/clang/test/CodeGenHLSL/basic-target.c @@ -1,10 +1,10 @@ -// RUN: %clang -target dxil-pc-shadermodel6.0-pixel -S -emit-llvm -o - %s | FileCheck %s -// RUN: %clang -target dxil-pc-shadermodel6.0-vertex -S -emit-llvm -o - %s | FileCheck %s -// RUN: %clang -target dxil-pc-shadermodel6.0-compute -S -emit-llvm -o - %s | FileCheck %s -// RUN: %clang -target dxil-pc-shadermodel6.0-library -S -emit-llvm -o - %s | FileCheck %s -// RUN: %clang -target dxil-pc-shadermodel6.0-hull -S -emit-llvm -o - %s | FileCheck %s -// RUN: %clang -target dxil-pc-shadermodel6.0-domain -S -emit-llvm -o - %s | FileCheck %s -// RUN: %clang -target dxil-pc-shadermodel6.0-geometry -S -emit-llvm -o - %s | FileCheck %s +// RUN: %clang -cc1 -triple dxil-pc-shadermodel6.0-pixel -emit-llvm -o - %s | FileCheck %s +// RUN: %clang -cc1 -triple dxil-pc-shadermodel6.0-vertex -emit-llvm -o - %s | FileCheck %s +// RUN: %clang -cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -o - %s | FileCheck %s +// RUN: %clang -cc1 -triple dxil-pc-shadermodel6.0-library -emit-llvm -o - %s | FileCheck %s +// RUN: %clang -cc1 -triple dxil-pc-shadermodel6.0-hull -emit-llvm -o - %s | FileCheck %s +// RUN: %clang -cc1 -triple dxil-pc-shadermodel6.0-domain -emit-llvm -o - %s | FileCheck %s +// RUN: %clang -cc1 -triple dxil-pc-shadermodel6.0-geometry -emit-llvm -o - %s | FileCheck %s // CHECK: target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64" // CHECK: target triple = "dxilv1.0-pc-shadermodel6.0-{{[a-z]+}}" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Update target test to use `-cc1` rather than the clang driver (PR #127262)
https://github.com/bogner closed https://github.com/llvm/llvm-project/pull/127262 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CMake][Release] Statically link clang with stage1 runtimes (PR #127268)
https://github.com/tstellar created https://github.com/llvm/llvm-project/pull/127268 This change will cause clang and the other tools to statically link against the runtimes built in stage1. This will make the built binaries more portable by eliminating dependencies on system libraries like libgcc and libstdc++. >From a705acfd439e6310648b0ed1ad612eaffc408ad5 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Fri, 14 Feb 2025 17:46:25 + Subject: [PATCH] [CMake][Release] Statically link clang with stage1 runtimes This change will cause clang and the other tools to statically link against the runtimes built in stage1. This will make the built binaries more portable by eliminating dependencies on system libraries like libgcc and libstdc++. --- clang/cmake/caches/Release.cmake | 20 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake index 23e99493087ff..290e186baf6fe 100644 --- a/clang/cmake/caches/Release.cmake +++ b/clang/cmake/caches/Release.cmake @@ -48,10 +48,8 @@ set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "") set(STAGE1_PROJECTS "clang") -# Building Flang on Windows requires compiler-rt, so we need to build it in -# stage1. compiler-rt is also required for building the Flang tests on -# macOS. -set(STAGE1_RUNTIMES "compiler-rt") +# Build all runtimes so we can statically link them into the stage2 compiler. +set(STAGE1_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind") if (LLVM_RELEASE_ENABLE_PGO) list(APPEND STAGE1_PROJECTS "lld") @@ -90,9 +88,18 @@ else() set(CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING "") endif() +if (LLVM_RELEASE_ENABLE_LTO) + # Enable LTO for the runtimes. We need to configure stage1 clang to default + # to using lld as the linker because the stage1 toolchain will be used to + # build and link the runtimes. + set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON" CACHE STRING "") + set(LLVM_ENABLE_LLD ON CACHE STRING "") +endif() + # Stage 1 Common Config set(LLVM_ENABLE_RUNTIMES ${STAGE1_RUNTIMES} CACHE STRING "") set(LLVM_ENABLE_PROJECTS ${STAGE1_PROJECTS} CACHE STRING "") +set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE STRING "") # stage2-instrumented and Final Stage Config: # Options that need to be set in both the instrumented stage (if we are doing @@ -102,6 +109,11 @@ set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}" if (LLVM_RELEASE_ENABLE_LTO) set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL) endif() +set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL) +set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL) +set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING) +set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING) +set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING) # Final Stage Config (stage2) set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)
@@ -162,5 +219,371 @@ std::optional RootSignatureLexer::PeekNextToken() { return Result; } +// Parser Definitions + +RootSignatureParser::RootSignatureParser(SmallVector &Elements, + RootSignatureLexer &Lexer, + DiagnosticsEngine &Diags) +: Elements(Elements), Lexer(Lexer), Diags(Diags) {} + +bool RootSignatureParser::Parse() { + // Handle edge-case of empty RootSignature() + if (Lexer.EndOfBuffer()) +return false; + + // Iterate as many RootElements as possible + while (!ParseRootElement()) { +if (Lexer.EndOfBuffer()) + return false; +if (ConsumeExpectedToken(TokenKind::pu_comma)) + return true; + } + + return true; +} + +bool RootSignatureParser::ParseRootElement() { + if (ConsumeExpectedToken(TokenKind::kw_DescriptorTable)) +return true; + + // Dispatch onto the correct parse method + switch (CurToken.Kind) { + case TokenKind::kw_DescriptorTable: +return ParseDescriptorTable(); + default: +llvm_unreachable("Switch for an expected token was not provided"); inbelic wrote: At the moment, we follow the pattern of `ConsumeExpectedToken({TokenKind1, ..., TokenKindN})` and then switch on the token kinds that were in that statement. `ConsumeExpectedToken` guards against any other token kind. So any new token kind is added we will never reach the default here, unless it is also added to the `ConsumeExpectedToken` statement. Maybe there is a way we could define the macros to generate sub-sets of tokens? Although, I am of the opinion the current method guards against this sufficiently. https://github.com/llvm/llvm-project/pull/122982 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)
@@ -306,4 +307,254 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexRegNumberTest) { ASSERT_FALSE(Consumer->IsSatisfied()); } +// Valid Parser Tests + +TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) { + const llvm::StringLiteral Source = R"cc()cc"; + + TrivialModuleLoader ModLoader; + auto PP = CreatePP(Source, ModLoader); + auto TokLoc = SourceLocation(); + + hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP); + SmallVector Elements; + hlsl::RootSignatureParser Parser(Elements, Lexer, Diags); + + // Test no diagnostics produced + Consumer->SetNoDiag(); + + ASSERT_FALSE(Parser.Parse()); + ASSERT_EQ((int)Elements.size(), 0); inbelic wrote: Updated this and other casting to use the `u` notation on the literals https://github.com/llvm/llvm-project/pull/122982 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)
@@ -93,6 +96,108 @@ class RootSignatureLexer { } }; +class RootSignatureParser { +public: + RootSignatureParser(SmallVector &Elements, + RootSignatureLexer &Lexer, DiagnosticsEngine &Diags); + + /// Iterates over the provided tokens and constructs the in-memory + /// representations of the RootElements. + /// + /// The return value denotes if there was a failure and the method will + /// return on the first encountered failure, or, return false if it + /// can sucessfully reach the end of the tokens. + bool Parse(); + +private: + // Root Element helpers + bool ParseRootElement(); + bool ParseDescriptorTable(); + bool ParseDescriptorTableClause(); + + /// Helper dispatch method + /// + /// These will switch on the Variant kind to dispatch to the respective Parse + /// method and store the parsed value back into Ref. + /// + /// It is helpful to have a generalized dispatch method so that when we need + /// to parse multiple optional parameters in any order, we can invoke this + /// method + bool ParseParam(llvm::hlsl::rootsig::ParamType Ref); + + // Parse as many optional parameters as possible in any order + bool ParseOptionalParams( + llvm::SmallDenseMap &RefMap); + + // Common parsing helpers inbelic wrote: I restructured the comments a bit so I don't think this applies anymore. https://github.com/llvm/llvm-project/pull/122982 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)
@@ -299,6 +300,29 @@ struct RefCountableWithLambdaCapturingThis { return obj->next(); }); } + + void callAsyncNoescape([[clang::noescape]] WTF::Function&&); + void method_temp_lambda(RefCountable* obj) { +callAsyncNoescape([this, otherObj = RefPtr { obj }](auto& obj) { + return otherObj == &obj; +}); + } + + void method_nested_lambda() { +callAsync([this, protectedThis = Ref { *this }] { + callAsync([this, protectedThis = static_cast&&>(protectedThis)] { +nonTrivial(); + }); +}); + } + + void method_nested_lambda2() { +callAsync([this, protectedThis = RefPtr { this }] { + callAsync([this, protectedThis = static_cast&&>(*protectedThis)] { +nonTrivial(); + }); +}); + } rniwa wrote: Oh, we have such a test case. See method_captures_this_unsafe around line 217 :) https://github.com/llvm/llvm-project/pull/126443 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebKit Checkers] Treat offsetof as a trivial expression. (PR #126996)
rniwa wrote: Thanks for the review! https://github.com/llvm/llvm-project/pull/126996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
@@ -2245,6 +2245,17 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { break; } + case Builtin::BI__builtin_hlsl_and: { +if (SemaRef.checkArgCount(TheCall, 2)) + return true; +if (CheckVectorElementCallArgs(&SemaRef, TheCall)) + return true; +ExprResult A = TheCall->getArg(0); llvm-beanz wrote: I think you're misunderstanding how this works. `__builtin_hlsl_and` should only accept bools. The `hlsl::and` function takes bools. When the function is called with something that isn't a bool, implicit conversions covert it to bool. You can write `__builtin_hlsl_and(...)` in source and get all sorts of strange thing passed in without conversions happening. https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CUDA] Add support for sm101 and sm120 target architectures (PR #127187)
@@ -21,6 +21,10 @@ class SM newer_list> : SMFeatures { !strconcat(f, "|", newer.Features)); } +let Features = "sm_101a" in def SM_101a : SMFeatures; + +def SM_101 : SM<"101", [SM_101a]>; jodelek wrote: Added sm120 and sm120a. Thanks for the clarification with the other part - I was completely lost there. I hope I got it right. https://github.com/llvm/llvm-project/pull/127187 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CUDA] Add support for sm101 and sm120 target architectures (PR #127187)
https://github.com/jodelek edited https://github.com/llvm/llvm-project/pull/127187 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] [DXIL] Implement the AddUint64 HLSL function and the UAddc DXIL op (PR #127137)
@@ -2229,6 +2241,41 @@ static bool CheckResourceHandle( // returning an ExprError bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { switch (BuiltinID) { + case Builtin::BI__builtin_hlsl_adduint64: { +if (SemaRef.checkArgCount(TheCall, 2)) + return true; +if (CheckVectorElementCallArgs(&SemaRef, TheCall)) + return true; +if (CheckUnsignedIntRepresentations(&SemaRef, TheCall)) + return true; + +// CheckVectorElementCallArgs(...) guarantees both args are the same type. +assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() && + "Both args must be of the same type"); + +// ensure both args are vectors +auto *VTy = TheCall->getArg(0)->getType()->getAs(); +if (!VTy) { + SemaRef.Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector) + << "AddUint64" << /*all*/ 1; + return true; +} + +// ensure both args have 2 elements, or both args have 4 elements +int NumElementsArg = VTy->getNumElements(); +if (NumElementsArg != 2 && NumElementsArg != 4) { + SemaRef.Diag(TheCall->getBeginLoc(), + diag::err_invalid_even_odd_vector_element_count) + << NumElementsArg << 2 << 4 << /*even*/ 0 << /*operand*/ 1; + return true; +} + Icohedron wrote: Nevermind. I found a way thanks to @bob80905 ```c++ // ensure arg integers are 32-bits CharUnits CharSize = SemaRef.getASTContext().getTypeSizeInChars(VTy->getElementType()); if (CharSize.getQuantity() != 4) { SemaRef.Diag(...); return true; } ``` https://github.com/llvm/llvm-project/pull/127137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/126443 >From a40e782b866ec4756ddf3f04cc09caff31845ebf Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Sun, 9 Feb 2025 13:50:26 -0800 Subject: [PATCH 1/3] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern In WebKit, it's pretty common to capture "this" and "protectedThis" where "protectedThis" is a guardian variable of type Ref or RefPtr for "this". Furthermore, it's common for this "protectedThis" variable from being passed to an inner lambda by std::move. Recognize this pattern so that we don't emit warnings for nested inner lambdas. To recognize this pattern, we introduce a new DenseSet, ProtectedThisDecls, which contains every "protectedThis" we've recognized to our subclass of DynamicRecursiveASTVisitor. This set is now populated in "hasProtectedThis" and "declProtectsThis" uses this DenseSet to determine a given value declaration constitutes a "protectedThis" pattern or not. Because hasProtectedThis and declProtectsThis had to be moved from the checker class to the visitor class, it's now a responsibility of each caller of visitLambdaExpr to check whether a given lambda captures "this" without a "protectedThis" or not. Finally, this PR improves the code to recognize "protectedThis" pattern by allowing more nested CXXBindTemporaryExpr, CXXOperatorCallExpr, and UnaryOperator expressions. --- .../WebKit/UncountedLambdaCapturesChecker.cpp | 118 +++--- .../WebKit/uncounted-lambda-captures.cpp | 24 2 files changed, 95 insertions(+), 47 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index a56f48c83c660..c0a9e38b6aab4 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -41,6 +41,7 @@ class UncountedLambdaCapturesChecker const UncountedLambdaCapturesChecker *Checker; llvm::DenseSet DeclRefExprsToIgnore; llvm::DenseSet LambdasToIgnore; + llvm::DenseSet ProtectedThisDecls; QualType ClsType; explicit LocalVisitor(const UncountedLambdaCapturesChecker *Checker) @@ -65,7 +66,7 @@ class UncountedLambdaCapturesChecker bool VisitLambdaExpr(LambdaExpr *L) override { if (LambdasToIgnore.contains(L)) return true; -Checker->visitLambdaExpr(L, shouldCheckThis()); +Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L)); return true; } @@ -93,7 +94,7 @@ class UncountedLambdaCapturesChecker if (!L) return true; LambdasToIgnore.insert(L); -Checker->visitLambdaExpr(L, shouldCheckThis()); +Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L)); return true; } @@ -118,7 +119,8 @@ class UncountedLambdaCapturesChecker if (auto *L = findLambdaInArg(Arg)) { LambdasToIgnore.insert(L); if (!Param->hasAttr() && !TreatAllArgsAsNoEscape) -Checker->visitLambdaExpr(L, shouldCheckThis()); +Checker->visitLambdaExpr(L, shouldCheckThis() && +!hasProtectedThis(L)); } ++ArgIndex; } @@ -145,6 +147,11 @@ class UncountedLambdaCapturesChecker return nullptr; if (auto *Lambda = dyn_cast(CtorArg)) return Lambda; +if (auto *TempExpr = dyn_cast(CtorArg)) { + E = TempExpr->getSubExpr()->IgnoreParenCasts(); + if (auto *Lambda = dyn_cast(E)) +return Lambda; +} auto *DRE = dyn_cast(CtorArg); if (!DRE) return nullptr; @@ -189,9 +196,68 @@ class UncountedLambdaCapturesChecker return; DeclRefExprsToIgnore.insert(ArgRef); LambdasToIgnore.insert(L); -Checker->visitLambdaExpr(L, shouldCheckThis(), +Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L), /* ignoreParamVarDecl */ true); } + + bool hasProtectedThis(LambdaExpr *L) { +for (const LambdaCapture &OtherCapture : L->captures()) { + if (!OtherCapture.capturesVariable()) +continue; + if (auto *ValueDecl = OtherCapture.getCapturedVar()) { +if (declProtectsThis(ValueDecl)) { + ProtectedThisDecls.insert(ValueDecl); + return true; +} + } +} +return false; + } + + bool declProtectsThis(const ValueDecl *ValueDecl) const { +auto *VD = dyn_cast(ValueDecl); +if (!VD) + return false; +auto *Init = VD->getInit()->IgnoreParenCasts(); +if (!Init) + return false; +const Expr *Arg = Init;
[clang] [CUDA] Add support for sm101 and sm120 target architectures (PR #127187)
https://github.com/jodelek edited https://github.com/llvm/llvm-project/pull/127187 ___ 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 support for `-ignore-insert-conflict` in `run-clang-tidy.py` (PR #127066)
Vicente Mataix =?utf-8?q?Ferrándiz?= , Vicente Mataix =?utf-8?q?Ferrándiz?= , Vicente Mataix =?utf-8?q?Ferrándiz?= Message-ID: In-Reply-To: github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r 39ec9de7c23063b87f5c56f4e80c8d0f8b511a4b...e8165bc2a8db2f4101d8e65f5d93cdb2c4a272d5 clang-tools-extra/clang-tidy/tool/run-clang-tidy.py `` View the diff from darker here. ``diff --- run-clang-tidy.py 2025-02-14 11:25:07.00 + +++ run-clang-tidy.py 2025-02-14 23:33:40.485943 + @@ -198,11 +198,11 @@ def apply_fixes( args: argparse.Namespace, clang_apply_replacements_binary: str, tmpdir: str ) -> None: """Calls clang-apply-replacements on a given directory.""" invocation = [clang_apply_replacements_binary] - + if args.ignore_insert_conflict: invocation.append("-ignore-insert-conflict") if args.format: invocation.append("-format") if args.style: `` https://github.com/llvm/llvm-project/pull/127066 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
@@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s \ +// RUN: -emit-llvm -O1 -verify + +bool test_too_few_arg(bool a) { + return __builtin_hlsl_and(a); + // expected-error@-1 {{too few arguments to function call, expected 2, have 1}} +} + +bool test_too_many_arg(bool a) { + return __builtin_hlsl_and(a, a, a); + // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} +} + +bool2 test_mismatched_args(bool2 a, bool3 b) { + return __builtin_hlsl_and(a, b); + // expected-error@-1 {{all arguments to '__builtin_hlsl_and' must have the same type}} +} + +struct S { + bool a; +}; + +bool test_invalid_type_conversion(S s) { + return __builtin_hlsl_and(s, s); llvm-beanz wrote: This call should be failing because `s` isn't a bool, not because you can't cast `S` back to bool in the return type. https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d9b55b7 - [CIR] Fix extra `; ` warning, and replace `new` with emplaceBlock (NFC) (#127207)
Author: Henrich Lauko Date: 2025-02-15T00:29:18+01:00 New Revision: d9b55b72103f7d2b35cdc7a6311f217016308d9c URL: https://github.com/llvm/llvm-project/commit/d9b55b72103f7d2b35cdc7a6311f217016308d9c DIFF: https://github.com/llvm/llvm-project/commit/d9b55b72103f7d2b35cdc7a6311f217016308d9c.diff LOG: [CIR] Fix extra `;` warning, and replace `new` with emplaceBlock (NFC) (#127207) Added: Modified: clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp Removed: diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index d60a6b38b0c12..74ff89346f3c4 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -157,9 +157,9 @@ void CIRToLLVMGlobalOpLowering::setupRegionInitializedLLVMGlobalOp( op, llvmType, isConst, linkage, symbol, nullptr, alignment, addrSpace, isDsoLocal, isThreadLocal, /*comdat=*/mlir::SymbolRefAttr(), attributes); - newGlobalOp.getRegion().push_back(new mlir::Block()); + newGlobalOp.getRegion().emplaceBlock(); rewriter.setInsertionPointToEnd(newGlobalOp.getInitializerBlock()); -}; +} mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewriteRegionInitializedGlobal( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Fix extra `;` warning, and replace `new` with emplaceBlock (NFC) (PR #127207)
https://github.com/xlauko closed https://github.com/llvm/llvm-project/pull/127207 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
@@ -2245,6 +2245,17 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { break; } + case Builtin::BI__builtin_hlsl_and: { +if (SemaRef.checkArgCount(TheCall, 2)) + return true; +if (CheckVectorElementCallArgs(&SemaRef, TheCall)) + return true; +ExprResult A = TheCall->getArg(0); Icohedron wrote: I think it's just difference in wording. I'm pretty sure we are talking about the same thing? If you pass a non-bool type into `__builtin_hlsl_and` then it will be implicitly converted to a bool. Hence "any type that can be implicitly cast to a bool (vector) are allowed to be passed" into it. https://github.com/llvm/llvm-project/pull/127098 ___ 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 support for `-ignore-insert-conflict` in `run-clang-tidy.py` (PR #127066)
Vicente Mataix =?utf-8?q?Ferr=C3=A1ndiz?= , Vicente Mataix =?utf-8?q?Ferr=C3=A1ndiz?= , Vicente Mataix =?utf-8?q?Ferr=C3=A1ndiz?= Message-ID: In-Reply-To: https://github.com/HerrCai0907 approved this pull request. LGTM. Please update release note also. After that, feel free to ping me to merge it if you do not have permission. https://github.com/llvm/llvm-project/pull/127066 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
@@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s \ +// RUN: -emit-llvm -O1 -verify + +bool test_too_few_arg(bool a) { + return __builtin_hlsl_and(a); + // expected-error@-1 {{too few arguments to function call, expected 2, have 1}} +} + +bool test_too_many_arg(bool a) { + return __builtin_hlsl_and(a, a, a); + // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} +} + +bool2 test_mismatched_args(bool2 a, bool3 b) { + return __builtin_hlsl_and(a, b); + // expected-error@-1 {{all arguments to '__builtin_hlsl_and' must have the same type}} +} + +struct S { + bool a; +}; + +bool test_invalid_type_conversion(S s) { + return __builtin_hlsl_and(s, s); Icohedron wrote: Actually this is a good catch. The error message is worded strangely-- it implies that `__builtin_hlsl_and` is trying to return a struct of type `S` and is failing because `S` can't be converted to a bool. I will fix this by adding a check to SemaHLSL that the argument type has a bool representation, and emitting a better error message. https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
@@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s \ +// RUN: -emit-llvm -O1 -verify + +bool test_too_few_arg(bool a) { + return __builtin_hlsl_and(a); + // expected-error@-1 {{too few arguments to function call, expected 2, have 1}} +} + +bool test_too_many_arg(bool a) { + return __builtin_hlsl_and(a, a, a); + // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} +} + +bool2 test_mismatched_args(bool2 a, bool3 b) { + return __builtin_hlsl_and(a, b); + // expected-error@-1 {{all arguments to '__builtin_hlsl_and' must have the same type}} +} + +struct S { + bool a; +}; + +bool test_invalid_type_conversion(S s) { + return __builtin_hlsl_and(s, s); Icohedron wrote: Though I thought there would be something to catch errors like this when the argument type doesn't match any of the ones declared in `hlsl_intrinsics.h` https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CaptureTracking][FunctionAttrs] Add support for CaptureInfo (PR #125880)
joaosaffran wrote: @Prabhuk I committed it to my fork of llvm. So it shouldn't be related to your build issues. https://github.com/llvm/llvm-project/pull/125880 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] [DXIL] Implement the AddUint64 HLSL function and the UAddc DXIL op (PR #127137)
@@ -2229,6 +2241,41 @@ static bool CheckResourceHandle( // returning an ExprError bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { switch (BuiltinID) { + case Builtin::BI__builtin_hlsl_adduint64: { +if (SemaRef.checkArgCount(TheCall, 2)) + return true; +if (CheckVectorElementCallArgs(&SemaRef, TheCall)) + return true; +if (CheckUnsignedIntRepresentations(&SemaRef, TheCall)) + return true; + +// CheckVectorElementCallArgs(...) guarantees both args are the same type. +assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() && + "Both args must be of the same type"); + +// ensure both args are vectors +auto *VTy = TheCall->getArg(0)->getType()->getAs(); +if (!VTy) { + SemaRef.Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector) + << "AddUint64" << /*all*/ 1; + return true; +} + +// ensure both args have 2 elements, or both args have 4 elements +int NumElementsArg = VTy->getNumElements(); +if (NumElementsArg != 2 && NumElementsArg != 4) { + SemaRef.Diag(TheCall->getBeginLoc(), + diag::err_invalid_even_odd_vector_element_count) + << NumElementsArg << 2 << 4 << /*even*/ 0 << /*operand*/ 1; + return true; +} + bob80905 wrote: I'm a bit lost. Here in sema, you are verifying that the vec element type is 32 bits, regardless if it's 2 or 4 elements in size. However, in CGBuiltin.cpp, you are allowing for an arg to be a vector of 4 elements, and possibly constructing a 64 bit value by combining 4 16-bit parts. Which means you are throwing away the top 16 bits of each part. Is my understanding correct? If we are confident with this assertion, then that means you're constructing 128 bit integers in CGBuiltin no? https://github.com/llvm/llvm-project/pull/127137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Update the undefined assignment checker diagnostics to not use the term 'garbage' (PR #126596)
dtarditi wrote: @haoNoQ thanks for the explanation! Yes, this makes sense. I agree that the right long-term approach is that the ArrayBoundChecker issues warnings about out-of-bounds accesses. In general, I think it is desirable to report a problem about undefined behavior as close to its cause as possible, using a logical explanation where possible. https://github.com/llvm/llvm-project/pull/126596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/126443 >From a40e782b866ec4756ddf3f04cc09caff31845ebf Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Sun, 9 Feb 2025 13:50:26 -0800 Subject: [PATCH 1/4] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern In WebKit, it's pretty common to capture "this" and "protectedThis" where "protectedThis" is a guardian variable of type Ref or RefPtr for "this". Furthermore, it's common for this "protectedThis" variable from being passed to an inner lambda by std::move. Recognize this pattern so that we don't emit warnings for nested inner lambdas. To recognize this pattern, we introduce a new DenseSet, ProtectedThisDecls, which contains every "protectedThis" we've recognized to our subclass of DynamicRecursiveASTVisitor. This set is now populated in "hasProtectedThis" and "declProtectsThis" uses this DenseSet to determine a given value declaration constitutes a "protectedThis" pattern or not. Because hasProtectedThis and declProtectsThis had to be moved from the checker class to the visitor class, it's now a responsibility of each caller of visitLambdaExpr to check whether a given lambda captures "this" without a "protectedThis" or not. Finally, this PR improves the code to recognize "protectedThis" pattern by allowing more nested CXXBindTemporaryExpr, CXXOperatorCallExpr, and UnaryOperator expressions. --- .../WebKit/UncountedLambdaCapturesChecker.cpp | 118 +++--- .../WebKit/uncounted-lambda-captures.cpp | 24 2 files changed, 95 insertions(+), 47 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index a56f48c83c660..c0a9e38b6aab4 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -41,6 +41,7 @@ class UncountedLambdaCapturesChecker const UncountedLambdaCapturesChecker *Checker; llvm::DenseSet DeclRefExprsToIgnore; llvm::DenseSet LambdasToIgnore; + llvm::DenseSet ProtectedThisDecls; QualType ClsType; explicit LocalVisitor(const UncountedLambdaCapturesChecker *Checker) @@ -65,7 +66,7 @@ class UncountedLambdaCapturesChecker bool VisitLambdaExpr(LambdaExpr *L) override { if (LambdasToIgnore.contains(L)) return true; -Checker->visitLambdaExpr(L, shouldCheckThis()); +Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L)); return true; } @@ -93,7 +94,7 @@ class UncountedLambdaCapturesChecker if (!L) return true; LambdasToIgnore.insert(L); -Checker->visitLambdaExpr(L, shouldCheckThis()); +Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L)); return true; } @@ -118,7 +119,8 @@ class UncountedLambdaCapturesChecker if (auto *L = findLambdaInArg(Arg)) { LambdasToIgnore.insert(L); if (!Param->hasAttr() && !TreatAllArgsAsNoEscape) -Checker->visitLambdaExpr(L, shouldCheckThis()); +Checker->visitLambdaExpr(L, shouldCheckThis() && +!hasProtectedThis(L)); } ++ArgIndex; } @@ -145,6 +147,11 @@ class UncountedLambdaCapturesChecker return nullptr; if (auto *Lambda = dyn_cast(CtorArg)) return Lambda; +if (auto *TempExpr = dyn_cast(CtorArg)) { + E = TempExpr->getSubExpr()->IgnoreParenCasts(); + if (auto *Lambda = dyn_cast(E)) +return Lambda; +} auto *DRE = dyn_cast(CtorArg); if (!DRE) return nullptr; @@ -189,9 +196,68 @@ class UncountedLambdaCapturesChecker return; DeclRefExprsToIgnore.insert(ArgRef); LambdasToIgnore.insert(L); -Checker->visitLambdaExpr(L, shouldCheckThis(), +Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L), /* ignoreParamVarDecl */ true); } + + bool hasProtectedThis(LambdaExpr *L) { +for (const LambdaCapture &OtherCapture : L->captures()) { + if (!OtherCapture.capturesVariable()) +continue; + if (auto *ValueDecl = OtherCapture.getCapturedVar()) { +if (declProtectsThis(ValueDecl)) { + ProtectedThisDecls.insert(ValueDecl); + return true; +} + } +} +return false; + } + + bool declProtectsThis(const ValueDecl *ValueDecl) const { +auto *VD = dyn_cast(ValueDecl); +if (!VD) + return false; +auto *Init = VD->getInit()->IgnoreParenCasts(); +if (!Init) + return false; +const Expr *Arg = Init;
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
@@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s \ +// RUN: -emit-llvm -O1 -verify + +bool test_too_few_arg(bool a) { + return __builtin_hlsl_and(a); + // expected-error@-1 {{too few arguments to function call, expected 2, have 1}} +} + +bool test_too_many_arg(bool a) { + return __builtin_hlsl_and(a, a, a); + // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} +} + +bool2 test_mismatched_args(bool2 a, bool3 b) { + return __builtin_hlsl_and(a, b); + // expected-error@-1 {{all arguments to '__builtin_hlsl_and' must have the same type}} +} + +struct S { + bool a; +}; + +bool test_invalid_type_conversion(S s) { + return __builtin_hlsl_and(s, s); Icohedron wrote: Actually, there is something like that, but it seems `__builtin_hlsl_and` is triggering something else. The `D3DCOLORtoUBYTE` function doesn't have any SemaHLSL and [yet has a similar test which emits a more accurate error message](https://github.com/llvm/llvm-project/blob/main/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl#L28). Perhaps this is just because `D3DCOLORtoUBYTE` is a header-only implementation? https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/127098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] [DXIL] Implement the AddUint64 HLSL function and the UAddc DXIL op (PR #127137)
@@ -2229,6 +2241,41 @@ static bool CheckResourceHandle( // returning an ExprError bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { switch (BuiltinID) { + case Builtin::BI__builtin_hlsl_adduint64: { +if (SemaRef.checkArgCount(TheCall, 2)) + return true; +if (CheckVectorElementCallArgs(&SemaRef, TheCall)) + return true; +if (CheckUnsignedIntRepresentations(&SemaRef, TheCall)) + return true; + +// CheckVectorElementCallArgs(...) guarantees both args are the same type. +assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() && + "Both args must be of the same type"); + +// ensure both args are vectors +auto *VTy = TheCall->getArg(0)->getType()->getAs(); +if (!VTy) { + SemaRef.Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector) + << "AddUint64" << /*all*/ 1; + return true; +} + +// ensure both args have 2 elements, or both args have 4 elements +int NumElementsArg = VTy->getNumElements(); +if (NumElementsArg != 2 && NumElementsArg != 4) { + SemaRef.Diag(TheCall->getBeginLoc(), + diag::err_invalid_even_odd_vector_element_count) + << NumElementsArg << 2 << 4 << /*even*/ 0 << /*operand*/ 1; + return true; +} + Icohedron wrote: uint2: `AddUint64( A:{low, high}, B:{low, high} )` and the result is one pair of 32-bit integers (low, high) uint4: `AddUint64( A:{low0, high0, low1, high1}, B:{low0, high0, low1, high1} )` is equivalent to ``` AddUint64( A:{low0, high0}, B{low0, high0} ) AddUint64( A:{low1, high1}, B{low1, high1} ) ``` so the result would be two pairs of 32-bit integers, (low0, high0) and (low1, high1), stored as a uint4: (low0, high0, low1, high1) https://github.com/llvm/llvm-project/pull/127137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CUDA] Add support for sm101 and sm120 target architectures (PR #127187)
@@ -21,9 +21,17 @@ class SM newer_list> : SMFeatures { !strconcat(f, "|", newer.Features)); } +let Features = "sm_120a" in def SM_120a : SMFeatures; + +def SM_120 : SM<"120", [SM_120a]>; + +let Features = "sm_101a" in def SM_101a : SMFeatures; + +def SM_101 : SM<"101", [SM_101a, SM_120]>; + let Features = "sm_100a" in def SM_100a : SMFeatures; -def SM_100 : SM<"100", [SM_100a]>; +def SM_100 : SM<"100", [SM_100a, SM_101]>; Artem-B wrote: Almost there. Now move all SM_xxx records down to where we define the rest of them, and group `let Features...` ones together above them. https://github.com/llvm/llvm-project/pull/127187 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] [DXIL] Implement the AddUint64 HLSL function and the UAddc DXIL op (PR #127137)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/127137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] [DXIL] Implement the AddUint64 HLSL function and the UAddc DXIL op (PR #127137)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/127137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 77041da - [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (#126443)
Author: Ryosuke Niwa Date: 2025-02-14T16:33:34-08:00 New Revision: 77041da98932f77896d48366703d956ae7a82036 URL: https://github.com/llvm/llvm-project/commit/77041da98932f77896d48366703d956ae7a82036 DIFF: https://github.com/llvm/llvm-project/commit/77041da98932f77896d48366703d956ae7a82036.diff LOG: [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (#126443) In WebKit, it's pretty common to capture "this" and "protectedThis" where "protectedThis" is a guardian variable of type Ref or RefPtr for "this". Furthermore, it's common for this "protectedThis" variable from being passed to an inner lambda by std::move. Recognize this pattern so that we don't emit warnings for nested inner lambdas. To recognize this pattern, we introduce a new DenseSet, ProtectedThisDecls, which contains every "protectedThis" we've recognized to our subclass of DynamicRecursiveASTVisitor. This set is now populated in "hasProtectedThis" and "declProtectsThis" uses this DenseSet to determine a given value declaration constitutes a "protectedThis" pattern or not. Because hasProtectedThis and declProtectsThis had to be moved from the checker class to the visitor class, it's now a responsibility of each caller of visitLambdaExpr to check whether a given lambda captures "this" without a "protectedThis" or not. Finally, this PR improves the code to recognize "protectedThis" pattern by allowing more nested CXXBindTemporaryExpr, CXXOperatorCallExpr, and UnaryOperator expressions. Added: Modified: clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index 972364a855eb4..4ffdac5ca4873 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -41,7 +41,9 @@ class UncountedLambdaCapturesChecker const UncountedLambdaCapturesChecker *Checker; llvm::DenseSet DeclRefExprsToIgnore; llvm::DenseSet LambdasToIgnore; + llvm::DenseSet ProtectedThisDecls; llvm::DenseSet ConstructToIgnore; + QualType ClsType; explicit LocalVisitor(const UncountedLambdaCapturesChecker *Checker) @@ -66,7 +68,7 @@ class UncountedLambdaCapturesChecker bool VisitLambdaExpr(LambdaExpr *L) override { if (LambdasToIgnore.contains(L)) return true; -Checker->visitLambdaExpr(L, shouldCheckThis()); +Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L)); return true; } @@ -94,7 +96,7 @@ class UncountedLambdaCapturesChecker if (!L) return true; LambdasToIgnore.insert(L); -Checker->visitLambdaExpr(L, shouldCheckThis()); +Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L)); return true; } @@ -119,7 +121,8 @@ class UncountedLambdaCapturesChecker if (auto *L = findLambdaInArg(Arg)) { LambdasToIgnore.insert(L); if (!Param->hasAttr()) -Checker->visitLambdaExpr(L, shouldCheckThis()); +Checker->visitLambdaExpr(L, shouldCheckThis() && +!hasProtectedThis(L)); } ++ArgIndex; } @@ -139,7 +142,8 @@ class UncountedLambdaCapturesChecker if (auto *L = findLambdaInArg(Arg)) { LambdasToIgnore.insert(L); if (!Param->hasAttr() && !TreatAllArgsAsNoEscape) -Checker->visitLambdaExpr(L, shouldCheckThis()); +Checker->visitLambdaExpr(L, shouldCheckThis() && +!hasProtectedThis(L)); } ++ArgIndex; } @@ -168,6 +172,13 @@ class UncountedLambdaCapturesChecker ConstructToIgnore.insert(CE); return Lambda; } +if (auto *TempExpr = dyn_cast(CtorArg)) { + E = TempExpr->getSubExpr()->IgnoreParenCasts(); + if (auto *Lambda = dyn_cast(E)) { +ConstructToIgnore.insert(CE); +return Lambda; + } +} auto *DRE = dyn_cast(CtorArg); if (!DRE) return nullptr; @@ -213,9 +224,68 @@ class UncountedLambdaCapturesChecker return; DeclRefExprsToIgnore.insert(ArgRef); LambdasToIgnore.insert(L); -Checker->visitLambdaExpr(L, shouldCheckThis(), +Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L), /* ignoreParamVarDecl */ true); } + + bool hasProtectedThis(LambdaExpr *L) { +
[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)
https://github.com/rniwa closed https://github.com/llvm/llvm-project/pull/126443 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CUDA] Add support for sm101 and sm120 target architectures (PR #127187)
https://github.com/jodelek edited https://github.com/llvm/llvm-project/pull/127187 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebKit Checkers] Treat attributes as trivial (PR #127289)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) Changes For the purpose of determining triviality, ignore all attributes. --- Full diff: https://github.com/llvm/llvm-project/pull/127289.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp (+5) - (modified) clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp (+2) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 5b8d1184050e9..8340de9e5a7a9 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -392,6 +392,11 @@ class TrivialFunctionAnalysisVisitor return false; } + bool VisitAttributedStmt(const AttributedStmt *AS) { +// Ignore attributes. +return Visit(AS->getSubStmt()); + } + bool VisitCompoundStmt(const CompoundStmt *CS) { // A compound statement is allowed as long each individual sub-statement // is trivial. diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp index cf403851b74fd..fe7ce158eb8ba 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp @@ -376,6 +376,7 @@ class RefCounted { }; void trivial68() { point pt = { 1.0 }; } unsigned trivial69() { return offsetof(RefCounted, children); } + DerivedNumber* trivial70() { [[clang::suppress]] return static_cast(number); } static RefCounted& singleton() { static RefCounted s_RefCounted; @@ -564,6 +565,7 @@ class UnrelatedClass { getFieldTrivial().trivial67()->trivial6(); // no-warning getFieldTrivial().trivial68(); // no-warning getFieldTrivial().trivial69(); // no-warning +getFieldTrivial().trivial70(); // no-warning RefCounted::singleton().trivial18(); // no-warning RefCounted::singleton().someFunction(); // no-warning `` https://github.com/llvm/llvm-project/pull/127289 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebKit Checkers] Treat attributes as trivial (PR #127289)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Ryosuke Niwa (rniwa) Changes For the purpose of determining triviality, ignore all attributes. --- Full diff: https://github.com/llvm/llvm-project/pull/127289.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp (+5) - (modified) clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp (+2) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 5b8d1184050e9..8340de9e5a7a9 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -392,6 +392,11 @@ class TrivialFunctionAnalysisVisitor return false; } + bool VisitAttributedStmt(const AttributedStmt *AS) { +// Ignore attributes. +return Visit(AS->getSubStmt()); + } + bool VisitCompoundStmt(const CompoundStmt *CS) { // A compound statement is allowed as long each individual sub-statement // is trivial. diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp index cf403851b74fd..fe7ce158eb8ba 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp @@ -376,6 +376,7 @@ class RefCounted { }; void trivial68() { point pt = { 1.0 }; } unsigned trivial69() { return offsetof(RefCounted, children); } + DerivedNumber* trivial70() { [[clang::suppress]] return static_cast(number); } static RefCounted& singleton() { static RefCounted s_RefCounted; @@ -564,6 +565,7 @@ class UnrelatedClass { getFieldTrivial().trivial67()->trivial6(); // no-warning getFieldTrivial().trivial68(); // no-warning getFieldTrivial().trivial69(); // no-warning +getFieldTrivial().trivial70(); // no-warning RefCounted::singleton().trivial18(); // no-warning RefCounted::singleton().someFunction(); // no-warning `` https://github.com/llvm/llvm-project/pull/127289 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix UEFI Target info (PR #127290)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Prabhuk (Prabhuk) Changes For X64 UEFI targets, making the integer size and va_list kind fixes. --- Full diff: https://github.com/llvm/llvm-project/pull/127290.diff 2 Files Affected: - (modified) clang/include/clang/Basic/TargetOSMacros.def (+3) - (modified) clang/lib/Basic/Targets/X86.h (+11-5) ``diff diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def index 58dce330f9c8f..f4f3276ad1c25 100644 --- a/clang/include/clang/Basic/TargetOSMacros.def +++ b/clang/include/clang/Basic/TargetOSMacros.def @@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS()) TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment()) TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment()) +// UEFI target. +TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI()) + #undef TARGET_OS diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 205edcab9ccb3..20fcb25defba2 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -835,16 +835,22 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo public: UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : UEFITargetInfo(Triple, Opts) { +LongWidth = LongAlign = 32; +DoubleAlign = LongLongAlign = 64; +IntMaxType = SignedLongLong; +Int64Type = SignedLongLong; +SizeType = UnsignedLongLong; +PtrDiffType = SignedLongLong; +IntPtrType = SignedLongLong; +LongDoubleWidth = LongDoubleAlign = 64; +LongDoubleFormat = &llvm::APFloat::IEEEdouble(); +WCharType = UnsignedShort; +WIntType = UnsignedShort; this->TheCXXABI.set(TargetCXXABI::Microsoft); -this->MaxTLSAlign = 8192u * this->getCharWidth(); this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" "i64:64-i128:128-f80:128-n8:16:32:64-S128"); } - BuiltinVaListKind getBuiltinVaListKind() const override { -return TargetInfo::CharPtrBuiltinVaList; - } - CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { switch (CC) { case CC_C: `` https://github.com/llvm/llvm-project/pull/127290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix UEFI Target info (PR #127290)
https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/127290 For X64 UEFI targets, making the integer size and va_list kind fixes. >From 3e6122744f355954edb6a5450ae4220ba39bc9c1 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Fri, 14 Feb 2025 16:53:33 -0800 Subject: [PATCH] [clang] Fix UEFI Target info For X64 UEFI targets, making the integer size and va_list kind fixes. --- clang/include/clang/Basic/TargetOSMacros.def | 3 +++ clang/lib/Basic/Targets/X86.h| 16 +++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def index 58dce330f9c8f..f4f3276ad1c25 100644 --- a/clang/include/clang/Basic/TargetOSMacros.def +++ b/clang/include/clang/Basic/TargetOSMacros.def @@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS()) TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment()) TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment()) +// UEFI target. +TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI()) + #undef TARGET_OS diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 205edcab9ccb3..20fcb25defba2 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -835,16 +835,22 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo public: UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : UEFITargetInfo(Triple, Opts) { +LongWidth = LongAlign = 32; +DoubleAlign = LongLongAlign = 64; +IntMaxType = SignedLongLong; +Int64Type = SignedLongLong; +SizeType = UnsignedLongLong; +PtrDiffType = SignedLongLong; +IntPtrType = SignedLongLong; +LongDoubleWidth = LongDoubleAlign = 64; +LongDoubleFormat = &llvm::APFloat::IEEEdouble(); +WCharType = UnsignedShort; +WIntType = UnsignedShort; this->TheCXXABI.set(TargetCXXABI::Microsoft); -this->MaxTLSAlign = 8192u * this->getCharWidth(); this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" "i64:64-i128:128-f80:128-n8:16:32:64-S128"); } - BuiltinVaListKind getBuiltinVaListKind() const override { -return TargetInfo::CharPtrBuiltinVaList; - } - CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { switch (CC) { case CC_C: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebKit Checkers] Treat attributes as trivial (PR #127289)
https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/127289 For the purpose of determining triviality, ignore all attributes. >From 31e0fcbf7f8bf4d2244c863041df3716a598db3f Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Wed, 12 Feb 2025 22:16:11 -0800 Subject: [PATCH] [WebKit Checkers] Treat attributes as trivial For the purpose of determining triviality, ignore all attributes. --- .../lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp | 5 + clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp| 2 ++ 2 files changed, 7 insertions(+) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 5b8d1184050e9..8340de9e5a7a9 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -392,6 +392,11 @@ class TrivialFunctionAnalysisVisitor return false; } + bool VisitAttributedStmt(const AttributedStmt *AS) { +// Ignore attributes. +return Visit(AS->getSubStmt()); + } + bool VisitCompoundStmt(const CompoundStmt *CS) { // A compound statement is allowed as long each individual sub-statement // is trivial. diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp index cf403851b74fd..fe7ce158eb8ba 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp @@ -376,6 +376,7 @@ class RefCounted { }; void trivial68() { point pt = { 1.0 }; } unsigned trivial69() { return offsetof(RefCounted, children); } + DerivedNumber* trivial70() { [[clang::suppress]] return static_cast(number); } static RefCounted& singleton() { static RefCounted s_RefCounted; @@ -564,6 +565,7 @@ class UnrelatedClass { getFieldTrivial().trivial67()->trivial6(); // no-warning getFieldTrivial().trivial68(); // no-warning getFieldTrivial().trivial69(); // no-warning +getFieldTrivial().trivial70(); // no-warning RefCounted::singleton().trivial18(); // no-warning RefCounted::singleton().someFunction(); // no-warning ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CUDA] Add support for sm101 and sm120 target architectures (PR #127187)
@@ -300,6 +306,10 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__CUDA_ARCH_FEAT_SM90_ALL", "1"); if (GPU == OffloadArch::SM_100a) Builder.defineMacro("__CUDA_ARCH_FEAT_SM100_ALL", "1"); +if (GPU == OffloadArch::SM_101a) + Builder.defineMacro("__CUDA_ARCH_FEAT_SM101_ALL", "1"); +if (GPU == OffloadArch::SM_120a) + Builder.defineMacro("__CUDA_ARCH_FEAT_SM120_ALL", "1"); Artem-B wrote: I think we can simplify all of that with just ``` Builder.defineMacro("__CUDA_ARCH_FEAT_SM" + CudaArchCode.substr(0,3) +"_ALL", "1"); ``` https://github.com/llvm/llvm-project/pull/127187 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
https://github.com/Icohedron updated https://github.com/llvm/llvm-project/pull/127098 >From 5b093ca42fdc24f89bfccac25e6f2e17155432f6 Mon Sep 17 00:00:00 2001 From: Icohedron Date: Wed, 12 Feb 2025 21:24:00 + Subject: [PATCH 1/4] Implement the 'and' HLSL function --- clang/include/clang/Basic/Builtins.td| 6 +++ clang/lib/CodeGen/CGBuiltin.cpp | 5 +++ clang/lib/Headers/hlsl/hlsl_intrinsics.h | 16 +++ clang/lib/Sema/SemaHLSL.cpp | 11 + clang/test/CodeGenHLSL/builtins/and.hlsl | 45 clang/test/SemaHLSL/BuiltIns/and-errors.hlsl | 27 6 files changed, 110 insertions(+) create mode 100644 clang/test/CodeGenHLSL/builtins/and.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/and-errors.hlsl diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 29939242596ba..de758d88f8f92 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4765,6 +4765,12 @@ def HLSLAll : LangBuiltin<"HLSL_LANG"> { let Prototype = "bool(...)"; } +def HLSLAnd : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_and"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + def HLSLAny : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_any"]; let Attributes = [NoThrow, Const]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 361e4c4bf2e2e..82527cb5e1f7a 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -19463,6 +19463,11 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, CGM.getHLSLRuntime().getAllIntrinsic(), ArrayRef{Op0}, nullptr, "hlsl.all"); } + case Builtin::BI__builtin_hlsl_and: { +Value *Op0 = EmitScalarExpr(E->getArg(0)); +Value *Op1 = EmitScalarExpr(E->getArg(1)); +return Builder.CreateAnd(Op0, Op1, "hlsl.and"); + } case Builtin::BI__builtin_hlsl_any: { Value *Op0 = EmitScalarExpr(E->getArg(0)); return Builder.CreateIntrinsic( diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index d1f5fdff8b600..7016b45d1c641 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -249,6 +249,22 @@ bool all(double3); _HLSL_BUILTIN_ALIAS(__builtin_hlsl_all) bool all(double4); +//===--===// +// and builtins +//===--===// + +// \fn bool and(bool x, bool y) +// \brief Logically ands two boolean vectors elementwise and produces a bool vector output. + +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_and) +bool and(bool x, bool y); +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_and) +bool2 and(bool2 x, bool2 y); +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_and) +bool3 and(bool3 x, bool3 y); +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_and) +bool4 and(bool4 x, bool4 y); + //===--===// // any builtins //===--===// diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 4abd870ad6aaa..7297fb3a9e4d0 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -2245,6 +2245,17 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { break; } + case Builtin::BI__builtin_hlsl_and: { +if (SemaRef.checkArgCount(TheCall, 2)) + return true; +if (CheckVectorElementCallArgs(&SemaRef, TheCall)) + return true; +ExprResult A = TheCall->getArg(0); +QualType ArgTyA = A.get()->getType(); +// return type is the same as the input type +TheCall->setType(ArgTyA); +break; + } case Builtin::BI__builtin_hlsl_all: case Builtin::BI__builtin_hlsl_any: { if (SemaRef.checkArgCount(TheCall, 1)) diff --git a/clang/test/CodeGenHLSL/builtins/and.hlsl b/clang/test/CodeGenHLSL/builtins/and.hlsl new file mode 100644 index 0..60295f192f5cc --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/and.hlsl @@ -0,0 +1,45 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s \ +// RUN: -emit-llvm -O1 -o - | FileCheck %s + +// CHECK-LABEL: define noundef i1 @_Z15test_and_scalarbb( +// CHECK-SAME: i1 noundef [[X:%.*]], i1 noundef [[Y:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[HLSL_AND:%.*]] = and i1 [[X]], [[Y]] +// CHECK-NEXT:ret i1 [[HLSL_AND]] +// +bool test_and_scalar(bool x, bool y) { + return and(x, y); +} + +// CHECK-LABEL: define noundef <2 x i1> @_Z14test_and_bool2Dv2_bS_( +// CHECK-SAME: <2 x i1> noundef [[X:%.*]], <2 x i1> noundef [[Y:%.
[clang] [CUDA] Add support for sm101 and sm120 target architectures (PR #127187)
@@ -300,6 +306,10 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__CUDA_ARCH_FEAT_SM90_ALL", "1"); if (GPU == OffloadArch::SM_100a) Builder.defineMacro("__CUDA_ARCH_FEAT_SM100_ALL", "1"); +if (GPU == OffloadArch::SM_101a) + Builder.defineMacro("__CUDA_ARCH_FEAT_SM101_ALL", "1"); +if (GPU == OffloadArch::SM_120a) + Builder.defineMacro("__CUDA_ARCH_FEAT_SM120_ALL", "1"); jodelek wrote: I think handling variable length is necessary: ``` switch(GPU) { case OffloadArch::SM_90a: case OffloadArch::SM_100a: case OffloadArch::SM_101a: case OffloadArch::SM_120a: Builder.defineMacro("__CUDA_ARCH_FEAT_SM" + CUDAArchCode.substr(0, CUDAArchCode.length()-1) + "_ALL", "1"); break; } ``` https://github.com/llvm/llvm-project/pull/127187 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clangd-ubuntu-tsan` running on `clangd-ubuntu-clang` while building `clang` at step 6 "test-build-clangd-clangd-index-server-clangd-in...". Full details are available at: https://lab.llvm.org/buildbot/#/builders/134/builds/13474 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-clangd-clangd-index-server-clangd-in...) failure: test (failure) TEST 'Clangd :: target_info.test' FAILED Exit Code: 66 Command Output (stderr): -- RUN: at line 5: rm -rf /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir && mkdir -p /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir + rm -rf /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir + mkdir -p /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir RUN: at line 7: echo '[{"directory": "/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir", "command": "/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir/armv7-clang -x c++ the-file.cpp -v", "file": "the-file.cpp"}]' > /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir/compile_commands.json + echo '[{"directory": "/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir", "command": "/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir/armv7-clang -x c++ the-file.cpp -v", "file": "the-file.cpp"}]' RUN: at line 9: sed -e "s|INPUT_DIR|/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir|g" /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/target_info.test > /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.test.1 + sed -e 's|INPUT_DIR|/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.dir|g' /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/target_info.test RUN: at line 12: sed -E -e 's|"file://([A-Z]):/|"file:///\1:/|g' /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.test.1 > /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.test + sed -E -e 's|"file://([A-Z]):/|"file:///\1:/|g' /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.test.1 RUN: at line 14: clangd -lit-test < /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.test 2>&1 | /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/bin/FileCheck -strict-whitespace /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.test + clangd -lit-test + /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/bin/FileCheck -strict-whitespace /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/Output/target_info.test.tmp.test -- ``` https://github.com/llvm/llvm-project/pull/126443 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Diagnose the code with trailing comma in the function call. (PR #125232)
https://github.com/hokein closed https://github.com/llvm/llvm-project/pull/125232 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 922f339 - Diagnose the code with trailing comma in the function call. (#125232)
Author: Haojian Wu Date: 2025-02-14T16:21:53+01:00 New Revision: 922f339c4ef3631f66dc4b8caa4c356103dbf69d URL: https://github.com/llvm/llvm-project/commit/922f339c4ef3631f66dc4b8caa4c356103dbf69d DIFF: https://github.com/llvm/llvm-project/commit/922f339c4ef3631f66dc4b8caa4c356103dbf69d.diff LOG: Diagnose the code with trailing comma in the function call. (#125232) This patch fixes a regression caused by https://github.com/llvm/llvm-project/pull/114684 where clang accepts trailing commas for function calls. Fixes #125225 Added: Modified: clang/lib/Parse/ParseExpr.cpp clang/test/Parser/recovery.cpp Removed: diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index da5f2ccf3a0c6..0c28972d6ed8f 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -2236,6 +2236,8 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { if (PP.isCodeCompletionReached() && !CalledSignatureHelp) RunSignatureHelp(); LHS = ExprError(); + } else if (!HasError && HasTrailingComma) { +Diag(Tok, diag::err_expected_expression); } else if (LHS.isInvalid()) { for (auto &E : ArgExprs) Actions.CorrectDelayedTyposInExpr(E); diff --git a/clang/test/Parser/recovery.cpp b/clang/test/Parser/recovery.cpp index 4e2811c4cac92..2fce67a52c6b6 100644 --- a/clang/test/Parser/recovery.cpp +++ b/clang/test/Parser/recovery.cpp @@ -215,3 +215,10 @@ struct ::template foo, struct ::template bar; // expected-error 2 {{expected ide struct ::foo struct::; // expected-error {{no struct named 'foo' in the global namespace}} expected-error {{expected identifier}} class :: : {} a; // expected-error {{expected identifier}} expected-error {{expected class name}} } + +namespace GH125225 { +void func(int); +void k() { + func(1, ); // expected-error {{expected expression}} +} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Diagnose the code with trailing comma in the function call. (PR #125232)
https://github.com/hokein milestoned https://github.com/llvm/llvm-project/pull/125232 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Fix false positive of BlockInCriticalSectionChecker (PR #127049)
@@ -315,16 +342,54 @@ bool BlockInCriticalSectionChecker::isBlockingInCritSection( void BlockInCriticalSectionChecker::checkPostCall(const CallEvent &Call, CheckerContext &C) const { if (isBlockingInCritSection(Call, C)) { +// for 'read' and 'recv' call, check whether it's file descriptor(first +// argument) is +// created by 'open' API with O_NONBLOCK flag or is equal to -1, they will +// not cause block in these situations, don't report +StringRef FuncName = Call.getCalleeIdentifier()->getName(); +if (FuncName == "read" || FuncName == "recv") { + const auto *Arg = Call.getArgExpr(0); + if (!Arg) +return; + + SVal SV = C.getSVal(Arg); + if (const auto *IntValue = SV.getAsInteger()) { +if (*IntValue == -1) + return; + } + + SymbolRef SR = C.getSVal(Arg).getAsSymbol(); + if (SR && C.getState()->contains(SR)) { +return; + } +} reportBlockInCritSection(Call, C); } else if (std::optional LockDesc = checkDescriptorMatch(Call, C, /*IsLock=*/true)) { handleLock(*LockDesc, Call, C); } else if (std::optional UnlockDesc = checkDescriptorMatch(Call, C, /*IsLock=*/false)) { handleUnlock(*UnlockDesc, Call, C); + } else if (OpenFunction.matches(Call)) { +handleOpen(Call, C); } } +void BlockInCriticalSectionChecker::checkDeadSymbols(SymbolReaper &SymReaper, + CheckerContext &C) const { + ProgramStateRef State = C.getState(); + + // Remove the dead symbols from the NonBlockFileDescriptor set. + NonBlockFileDescriptorTy Tracked = State->get(); + for (SymbolRef SR : Tracked) { +if (SymReaper.isDead(SR)) { + State = State->remove(SR); +} + } + + C.addTransition(State); +} + flovent wrote: the implementaion way is updated to BugReporterVisitor in latest commit, please take another look https://github.com/llvm/llvm-project/pull/127049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Fix false positive of BlockInCriticalSectionChecker (PR #127049)
https://github.com/flovent edited https://github.com/llvm/llvm-project/pull/127049 ___ 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 invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)
https://github.com/Andrewyuan34 updated https://github.com/llvm/llvm-project/pull/127162 >From 78d04102fc6d6ead4ab1153a82ed2ab9d8437bed Mon Sep 17 00:00:00 2001 From: Andrewyuan34 Date: Thu, 13 Feb 2025 22:35:36 -0500 Subject: [PATCH 1/4] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr --- .../clang-tidy/utils/UseRangesCheck.cpp | 10 .../checkers/modernize/use-ranges.cpp | 25 --- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp index aba4d17ccd035..4c5db488dce7f 100644 --- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp @@ -215,6 +215,16 @@ void UseRangesCheck::check(const MatchFinder::MatchResult &Result) { const auto *Call = Result.Nodes.getNodeAs(Buffer); if (!Call) continue; +if (Function->getName() == "find") { + unsigned ValueArgIndex = 2; + if (Call->getNumArgs() <= ValueArgIndex) +continue; + const Expr *ValueExpr = + Call->getArg(ValueArgIndex)->IgnoreParenImpCasts(); + if (isa(ValueExpr)) { +return; + } +} auto Diag = createDiag(*Call); if (auto ReplaceName = Replacer->getReplaceName(*Function)) Diag << FixItHint::CreateReplacement(Call->getCallee()->getSourceRange(), diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp index b022efebfdf4d..57ca038f64511 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp @@ -1,14 +1,24 @@ -// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I %S/Inputs/use-ranges/ -// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t -check-suffixes=,CPP23 -- -I %S/Inputs/use-ranges/ +// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I %S/Inputs/ +// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t -check-suffixes=,CPP23 -- -I %S/Inputs/ +// Example: ./check_clang_tidy.py -std=c++20 checkers/modernize/use-ranges.cpp modernize-use-ranges temp.txt -- -- -I ~/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/ // CHECK-FIXES: #include // CHECK-FIXES-CPP23: #include // CHECK-FIXES: #include -#include "fake_std.h" +#include "use-ranges/fake_std.h" +#include "smart-ptr/unique_ptr.h" void Positives() { std::vector I, J; + + // Expect to have no check messages + std::find(I.begin(), I.end(), nullptr); + + std::find(I.begin(), I.end(), std::unique_ptr()); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm + // CHECK-FIXES: std::ranges::find(I, std::unique_ptr()); + std::find(I.begin(), I.end(), 0); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm // CHECK-FIXES: std::ranges::find(I, 0); @@ -76,6 +86,14 @@ void Positives() { void Reverse(){ std::vector I, J; + + // Expect to have no check messages + std::find(I.rbegin(), I.rend(), nullptr); + + std::find(I.rbegin(), I.rend(), std::unique_ptr()); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm + // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), std::unique_ptr()); + std::find(I.rbegin(), I.rend(), 0); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), 0); @@ -112,3 +130,4 @@ void Negatives() { // Pathological, but probably shouldn't diagnose this std::rotate(I.begin(), I.end(), I.end() + 0); } + >From 6d83f551843603cd76dafb0de48577385aad58a6 Mon Sep 17 00:00:00 2001 From: Andrewyuan34 Date: Fri, 14 Feb 2025 01:15:46 -0500 Subject: [PATCH 2/4] Based on PR reviews, improve code quality by making sure const correctness and modifying code format Co-authored-by: Piotr Zegar --- .../clang-tidy/utils/UseRangesCheck.cpp | 5 ++--- clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ .../clang-tidy/checkers/modernize/use-ranges.cpp | 15 --- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp index 4c5db488dce7f..ce86a27ad69b2 100644 --- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp @@ -216,14 +216,13 @@ void UseRangesCheck::check(const MatchFinder::MatchResult &Result) { if (!Call) continue; if (Function->getName() == "find") { - unsigned ValueArgIndex = 2; + const unsigned ValueArgIndex = 2; if (Call->getNumArgs() <= ValueArgIndex) continue
[clang-tools-extra] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)
https://github.com/Andrewyuan34 updated https://github.com/llvm/llvm-project/pull/127162 >From 78d04102fc6d6ead4ab1153a82ed2ab9d8437bed Mon Sep 17 00:00:00 2001 From: Andrewyuan34 Date: Thu, 13 Feb 2025 22:35:36 -0500 Subject: [PATCH 1/5] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr --- .../clang-tidy/utils/UseRangesCheck.cpp | 10 .../checkers/modernize/use-ranges.cpp | 25 --- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp index aba4d17ccd035..4c5db488dce7f 100644 --- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp @@ -215,6 +215,16 @@ void UseRangesCheck::check(const MatchFinder::MatchResult &Result) { const auto *Call = Result.Nodes.getNodeAs(Buffer); if (!Call) continue; +if (Function->getName() == "find") { + unsigned ValueArgIndex = 2; + if (Call->getNumArgs() <= ValueArgIndex) +continue; + const Expr *ValueExpr = + Call->getArg(ValueArgIndex)->IgnoreParenImpCasts(); + if (isa(ValueExpr)) { +return; + } +} auto Diag = createDiag(*Call); if (auto ReplaceName = Replacer->getReplaceName(*Function)) Diag << FixItHint::CreateReplacement(Call->getCallee()->getSourceRange(), diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp index b022efebfdf4d..57ca038f64511 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp @@ -1,14 +1,24 @@ -// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I %S/Inputs/use-ranges/ -// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t -check-suffixes=,CPP23 -- -I %S/Inputs/use-ranges/ +// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I %S/Inputs/ +// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t -check-suffixes=,CPP23 -- -I %S/Inputs/ +// Example: ./check_clang_tidy.py -std=c++20 checkers/modernize/use-ranges.cpp modernize-use-ranges temp.txt -- -- -I ~/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/ // CHECK-FIXES: #include // CHECK-FIXES-CPP23: #include // CHECK-FIXES: #include -#include "fake_std.h" +#include "use-ranges/fake_std.h" +#include "smart-ptr/unique_ptr.h" void Positives() { std::vector I, J; + + // Expect to have no check messages + std::find(I.begin(), I.end(), nullptr); + + std::find(I.begin(), I.end(), std::unique_ptr()); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm + // CHECK-FIXES: std::ranges::find(I, std::unique_ptr()); + std::find(I.begin(), I.end(), 0); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm // CHECK-FIXES: std::ranges::find(I, 0); @@ -76,6 +86,14 @@ void Positives() { void Reverse(){ std::vector I, J; + + // Expect to have no check messages + std::find(I.rbegin(), I.rend(), nullptr); + + std::find(I.rbegin(), I.rend(), std::unique_ptr()); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm + // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), std::unique_ptr()); + std::find(I.rbegin(), I.rend(), 0); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), 0); @@ -112,3 +130,4 @@ void Negatives() { // Pathological, but probably shouldn't diagnose this std::rotate(I.begin(), I.end(), I.end() + 0); } + >From 6d83f551843603cd76dafb0de48577385aad58a6 Mon Sep 17 00:00:00 2001 From: Andrewyuan34 Date: Fri, 14 Feb 2025 01:15:46 -0500 Subject: [PATCH 2/5] Based on PR reviews, improve code quality by making sure const correctness and modifying code format Co-authored-by: Piotr Zegar --- .../clang-tidy/utils/UseRangesCheck.cpp | 5 ++--- clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ .../clang-tidy/checkers/modernize/use-ranges.cpp | 15 --- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp index 4c5db488dce7f..ce86a27ad69b2 100644 --- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp @@ -216,14 +216,13 @@ void UseRangesCheck::check(const MatchFinder::MatchResult &Result) { if (!Call) continue; if (Function->getName() == "find") { - unsigned ValueArgIndex = 2; + const unsigned ValueArgIndex = 2; if (Call->getNumArgs() <= ValueArgIndex) continue
[clang] Fixing the logic issue in TransformTypos::TransformDesignatedInitExpr… (PR #127211)
https://github.com/GS-GOAT updated https://github.com/llvm/llvm-project/pull/127211 >From 5f46f9c8e29dde7d6096f4e00094b4e615874ed4 Mon Sep 17 00:00:00 2001 From: GS-GOAT <86884129+gs-g...@users.noreply.github.com> Date: Fri, 14 Feb 2025 14:58:50 +0530 Subject: [PATCH] Fixing the logic issue in TransformTypos::TransformDesignatedInitExpr #126113 -Transforming Indices: For array designators, transform the index expression and update ExprChanged if it's modified. -Correct Initializer Check: Compare the transformed initializer against the original to accurately track changes. -Single Initializer Transformation: The initializer is processed once, not per designator, as each DesignatedInitExpr has one initializer. Fixes #126113 --- clang/lib/Sema/TreeTransform.h | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index fc1e3f7d58f4d..479ff1da7e76c 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -13665,15 +13665,15 @@ TreeTransform::TransformDesignatedInitExpr(DesignatedInitExpr *E) { } if (D.isArrayDesignator()) { - ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D)); - if (Index.isInvalid()) + ExprResult NewIndex = getDerived().TransformExpr(E->getArrayIndex(D)); + if (NewIndex.isInvalid()) return ExprError(); - Desig.AddDesignator( - Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc())); + Desig.AddDesignator(Designator::CreateArrayDesignator( + NewIndex.get(), D.getLBracketLoc())); - ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D); - ArrayExprs.push_back(Index.get()); + ExprChanged = ExprChanged || NewIndex.get() != E->getArrayIndex(D); + ArrayExprs.push_back(NewIndex.get()); continue; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules][Serialization] Delay marking pending incomplete decl chains until the end of `finishPendingActions`. (PR #121245)
AaronBallman wrote: > > @zixu-w and @ChuanqiXu9 Just want to clarify policies about changes > > reversion. As far as I understand it was one example in some private > > codebase with no reproducer publicly available. I can understand and > > completely agree if it breaks any existing test or llvm-build bot. But in > > this case I think it would be good to at least wait for the review. Such > > reversion without providing a reproducer does not allow to fix the issues > > or even verify that it is related to this PR. This PR fixes another crash > > with clear reproducers. > > Sorry, didn't notice that it is LLVM bootstrap build but still, no still I > > don't see steps to reproduce in #126973. > > CC @AaronBallman for the policy related things. Our documented policy is at https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy The promise for a public reproducer is in line with our policy, but reverting a change after it's been in the tree for two weeks is not particularly timely (but not unreasonable either, sometimes it takes a while to churn through downstream team suites). However, it's not clear to me why the revert couldn't have been handled in the downstream given the lack of details on the problem and the fact that upstream does not seem to be obviously broken. For example, the issue could ultimately boil down to interactions with changes carried in the downstream. That said, I don't think anyone's doing anything wrong (certainly nobody is acting in bad faith), and there was more than a day for reviewers or the patch author to have questioned the revert before the revert was committed. > Personally I do agree it is frustrating if the patch gets reverted without > being able to reproduce it. > > And my point in the above post is, **if** we revert it in the trunk and it > was backported to the release branch, we should revert it in the release > branch too. My point is majorly the **if**. I think the rule of thumb should be to revert in the release branch if the revert happens in trunk. CC @tstellar @tru in case they have a different opinion. https://github.com/llvm/llvm-project/pull/121245 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits