[clang] [clang] Make vector cast intrinsics constexpr (PR #156380)
https://github.com/vedantjk created https://github.com/llvm/llvm-project/pull/156380 Enable constexpr usage of vector bitcast intrinsics by changing from `__DEFAULT_FN_ATTRS*` to `__DEFAULT_FN_ATTRS*_CONSTEXPR` attributes. **Updated intrinsics:** - AVX-512 bitcast intrinsics: `_mm512_castpd_ps`, `_mm512_castps_pd`, `_mm512_cast*_si512`, `_mm512_castsi512_*` - AVX-512 truncation casts: `_mm512_cast*512_*128/256` - AVX-512 FP16 bitcast intrinsics: all `_mm*_castph_*` and `_mm*_cast*_ph` functions - AVX-512 FP16 truncation casts: `_mm*_castph*_ph*` github.com/llvm/llvm-project/issues/156348 >From a54599db951f08cbbf4f391facaeb5a874a17416 Mon Sep 17 00:00:00 2001 From: vedantjk Date: Mon, 1 Sep 2025 17:47:39 -0700 Subject: [PATCH] [clang] Make vector cast intrinsics constexpr --- clang/lib/Headers/avx512fintrin.h| 24 clang/lib/Headers/avx512fp16intrin.h | 42 ++-- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/clang/lib/Headers/avx512fintrin.h b/clang/lib/Headers/avx512fintrin.h index a525652e1e15a..c74e1087c5316 100644 --- a/clang/lib/Headers/avx512fintrin.h +++ b/clang/lib/Headers/avx512fintrin.h @@ -408,37 +408,37 @@ _mm512_castps256_ps512(__m256 __a) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); } -static __inline __m128d __DEFAULT_FN_ATTRS512 +static __inline __m128d __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castpd512_pd128(__m512d __a) { return __builtin_shufflevector(__a, __a, 0, 1); } -static __inline __m256d __DEFAULT_FN_ATTRS512 +static __inline __m256d __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castpd512_pd256 (__m512d __A) { return __builtin_shufflevector(__A, __A, 0, 1, 2, 3); } -static __inline __m128 __DEFAULT_FN_ATTRS512 +static __inline __m128 __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castps512_ps128(__m512 __a) { return __builtin_shufflevector(__a, __a, 0, 1, 2, 3); } -static __inline __m256 __DEFAULT_FN_ATTRS512 +static __inline __m256 __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castps512_ps256 (__m512 __A) { return __builtin_shufflevector(__A, __A, 0, 1, 2, 3, 4, 5, 6, 7); } -static __inline __m512 __DEFAULT_FN_ATTRS512 +static __inline __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castpd_ps (__m512d __A) { return (__m512) (__A); } -static __inline __m512i __DEFAULT_FN_ATTRS512 +static __inline __m512i __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castpd_si512 (__m512d __A) { return (__m512i) (__A); @@ -453,13 +453,13 @@ _mm512_castpd128_pd512 (__m128d __A) __B, 0, 1, 2, 3, 4, 5, 6, 7); } -static __inline __m512d __DEFAULT_FN_ATTRS512 +static __inline __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castps_pd (__m512 __A) { return (__m512d) (__A); } -static __inline __m512i __DEFAULT_FN_ATTRS512 +static __inline __m512i __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castps_si512 (__m512 __A) { return (__m512i) (__A); @@ -489,25 +489,25 @@ _mm512_castsi256_si512 (__m256i __A) return __builtin_shufflevector( __A, __builtin_nondeterministic_value(__A), 0, 1, 2, 3, 4, 5, 6, 7); } -static __inline __m512 __DEFAULT_FN_ATTRS512 +static __inline __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castsi512_ps (__m512i __A) { return (__m512) (__A); } -static __inline __m512d __DEFAULT_FN_ATTRS512 +static __inline __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castsi512_pd (__m512i __A) { return (__m512d) (__A); } -static __inline __m128i __DEFAULT_FN_ATTRS512 +static __inline __m128i __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castsi512_si128 (__m512i __A) { return (__m128i)__builtin_shufflevector(__A, __A , 0, 1); } -static __inline __m256i __DEFAULT_FN_ATTRS512 +static __inline __m256i __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castsi512_si256 (__m512i __A) { return (__m256i)__builtin_shufflevector(__A, __A , 0, 1, 2, 3); diff --git a/clang/lib/Headers/avx512fp16intrin.h b/clang/lib/Headers/avx512fp16intrin.h index 6989b86a7b68c..b8145613d06fe 100644 --- a/clang/lib/Headers/avx512fp16intrin.h +++ b/clang/lib/Headers/avx512fp16intrin.h @@ -113,93 +113,93 @@ _mm512_set1_pch(_Float16 _Complex __h) { return (__m512h)_mm512_set1_ps(__builtin_bit_cast(float, __h)); } -static __inline__ __m128 __DEFAULT_FN_ATTRS128 _mm_castph_ps(__m128h __a) { +static __inline__ __m128 __DEFAULT_FN_ATTRS128_CONSTEXPR _mm_castph_ps(__m128h __a) { return (__m128)__a; } -static __inline__ __m256 __DEFAULT_FN_ATTRS256 _mm256_castph_ps(__m256h __a) { +static __inline__ __m256 __DEFAULT_FN_ATTRS256_CONSTEXPR _mm256_castph_ps(__m256h __a) { return (__m256)__a; } -static __inline__ __m512 __DEFAULT_FN_ATTRS512 _mm512_castph_ps(__m512h __a) { +static __inline__ __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castph_ps(__m512h __a) { return (__m512)__a; } -static __inline__ __m128d __DEFAULT_FN_ATTRS128 _mm_castph_pd(__m128h __a) { +static __inline__ __m128d __DEFAULT_FN_ATTRS128_CONSTEXPR _mm_castph_pd(__m128h __
[clang] [clang] Make vector cast intrinsics constexpr (PR #156380)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/156380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove written template args from implicit var tpl spec (PR #156329)
https://github.com/zyn0217 commented: I think we need a release note, maybe 'Potential AST breaking changes' would be a good fit. https://github.com/llvm/llvm-project/pull/156329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [NFC][libclc] Define _CLC_DEF_WEAK and replace _CLC_DEF_ldexp with it (PR #156378)
https://github.com/wenju-he created https://github.com/llvm/llvm-project/pull/156378 _CLC_DEF_WEAK can be used in our downstream libclc to allow overriding generic __clc_tgamma implementation. >From cc51cd1e096794162a5f3c7be9aa160d83ba2547 Mon Sep 17 00:00:00 2001 From: Wenju He Date: Tue, 2 Sep 2025 02:26:45 +0200 Subject: [PATCH] [NFC][libclc] Define _CLC_DEF_WEAK and replace _CLC_DEF_ldexp with it _CLC_DEF_WEAK can be used in our downstream libclc to allow overriding generic __clc_tgamma implementation. --- libclc/clc/include/clc/clcfunc.h | 2 ++ libclc/clc/lib/generic/math/clc_ldexp.cl | 10 -- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libclc/clc/include/clc/clcfunc.h b/libclc/clc/include/clc/clcfunc.h index 30feaf99a4d31..29c2992b43617 100644 --- a/libclc/clc/include/clc/clcfunc.h +++ b/libclc/clc/include/clc/clcfunc.h @@ -24,6 +24,8 @@ #define _CLC_DEF __attribute__((always_inline)) #endif +#define _CLC_DEF_WEAK _CLC_DEF __attribute__((weak)) + #if __OPENCL_C_VERSION__ == CL_VERSION_2_0 || \ (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && \ defined(__opencl_c_generic_address_space)) diff --git a/libclc/clc/lib/generic/math/clc_ldexp.cl b/libclc/clc/lib/generic/math/clc_ldexp.cl index a5327c58e424a..7f565e4657e0f 100644 --- a/libclc/clc/lib/generic/math/clc_ldexp.cl +++ b/libclc/clc/lib/generic/math/clc_ldexp.cl @@ -15,9 +15,7 @@ #include #include -#define _CLC_DEF_ldexp _CLC_DEF __attribute__((weak)) - -_CLC_DEF_ldexp _CLC_OVERLOAD float __clc_ldexp(float x, int n) { +_CLC_DEF_WEAK _CLC_OVERLOAD float __clc_ldexp(float x, int n) { if (!__clc_fp32_subnormals_supported()) { // This treats subnormals as zeros @@ -90,7 +88,7 @@ _CLC_DEF_ldexp _CLC_OVERLOAD float __clc_ldexp(float x, int n) { #pragma OPENCL EXTENSION cl_khr_fp64 : enable -_CLC_DEF_ldexp _CLC_OVERLOAD double __clc_ldexp(double x, int n) { +_CLC_DEF_WEAK _CLC_OVERLOAD double __clc_ldexp(double x, int n) { long l = __clc_as_ulong(x); int e = (l >> 52) & 0x7ff; long s = l & 0x8000; @@ -125,14 +123,14 @@ _CLC_DEF_ldexp _CLC_OVERLOAD double __clc_ldexp(double x, int n) { #pragma OPENCL EXTENSION cl_khr_fp16 : enable -_CLC_OVERLOAD _CLC_DEF_ldexp half __clc_ldexp(half x, int n) { +_CLC_OVERLOAD _CLC_DEF_WEAK half __clc_ldexp(half x, int n) { return (half)__clc_ldexp((float)x, n); } #endif #define __CLC_FUNCTION __clc_ldexp -#define __CLC_DEF_SPEC _CLC_DEF_ldexp +#define __CLC_DEF_SPEC _CLC_DEF_WEAK #define __CLC_ARG2_TYPE int #define __CLC_BODY #include ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add modernize-use-span linter check (PR #140001)
jj-marr wrote: @SunBlack I'm still in favour of the check but I didn't see myself working on it until C++26 as it won't be usable for many people. I would prefer Option 2 if I was still working on this. In the example you gave, the initializer list should be in a constexpr std::array to avoid using magic numbers. > Isn't that only relevant if an at() occurs in the method that is to be > adapted? This is a footgun, because I believe `std::span` does bounds-checking dependent on `N`. Refactoring `std::array` to `std::span` could be unsafe since `N` would be defaulted to a "dynamic extent" and the size is no longer encoded in the type. [Cpp insights](https://cppinsights.io/lnk?code=I2luY2x1ZGUgPGNocm9ubz4KI2luY2x1ZGUgPGNzdGRkZWY+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHNwYW4+CiNpbmNsdWRlIDxzdGRleGNlcHQ+CiAKaW50IG1haW4oKQp7CiAgICBpbnQgeFtdezEsIDIsIDQsIDUsIDUsIDZ9OwogICAgc3RkOjpzcGFuPGludD4gZGF0YSh4KTsKIAogICAgLy8gU2V0IGVsZW1lbnQgMQogICAgZGF0YS5hdCgxKSA9IDg4OwogCiAgICAvLyBSZWFkIGVsZW1lbnQgMgogICAgc3RkOjpjb3V0IDw8ICJFbGVtZW50IGF0IGluZGV4IDIgaGFzIHZhbHVlICIgPDwgZGF0YS5hdCgyKSA8PCAnXG4nOwogCiAgICBzdGQ6OmNvdXQgPDwgImRhdGEgc2l6ZSA9ICIgPDwgZGF0YS5zaXplKCkgPDwgJ1xuJzsKIAogICAgdHJ5CiAgICB7CiAgICAgICAgLy8gVHJ5IHRvIHNldCBhbiBlbGVtZW50IGF0IHJhbmRvbSBwb3NpdGlvbiA+PSBzaXplKCkKICAgICAgICBhdXRvIG1vb25fcGhhc2UgPSBbXQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIHN0ZDo6Y2hyb25vOjpzeXN0ZW1fY2xvY2s6Om5vdygpLnRpbWVfc2luY2VfZXBvY2goKS5jb3VudCgpICUgODsKICAgICAgICB9OwogICAgICAgIGRhdGEuYXQoZGF0YS5zaXplKCkgKyBtb29uX3BoYXNlKCkpID0gMTM7CiAgICB9CiAgICBjYXRjaChjb25zdCBzdGQ6Om91dF9vZl9yYW5nZSYgZXgpCiAgICB7CiAgICAgICAgc3RkOjpjb3V0IDw8IGV4LndoYXQoKSA8PCAnXG4nOwogICAgfQogCiAgICAvLyBQcmludCBmaW5hbCB2YWx1ZXMKICAgIHN0ZDo6Y291dCA8PCAiZGF0YToiOwogICAgZm9yIChpbnQgZWxlbSA6IGRhdGEpCiAgICAgICAgc3RkOjpjb3V0IDw8ICcgJyA8PCBlbGVtOwogICAgc3RkOjpjb3V0IDw8ICdcbic7Cn0=&insightsOptions=cpp2c&std=cpp2c&rev=1.0) not sure what the full implications of this are. https://github.com/llvm/llvm-project/pull/140001 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind][test] change to use llvm-objdump (PR #156383)
https://github.com/yingcong-wu edited https://github.com/llvm/llvm-project/pull/156383 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind][test] unsupport a test in aarch64 for aarch64 has corss toolchain build (PR #156383)
https://github.com/yingcong-wu edited https://github.com/llvm/llvm-project/pull/156383 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [lldb] [llvm] [clang][modules] Serialize `CodeGenOptions` (PR #146422)
@@ -0,0 +1,15 @@ +// This test checks that under implicit modules, different optimization levels ChuanqiXu9 wrote: I feel this was caused by a typo. @jansvoboda11 can you fix this? https://github.com/llvm/llvm-project/pull/146422 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] fix pc range condition check bug (PR #154902)
yingcong-wu wrote: But I have added `// REQUIRES: linux` to the test already, why is it still running on win-x-aarch64 ? Do you have any ideas? @philnik777 https://github.com/llvm/llvm-project/pull/154902 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tidy] modernize-use-std-format: Correct replacement types when signed stdint types are used, and when enums are printed in hex. #150343 (PR #155200)
@@ -150,6 +150,9 @@ Changes to the Debug Info Changes to the LLVM tools - +* modernize-use-std-format now correctly replaces signed types, and correctly DaveBrantonCTCT wrote: Thank you, have put this in the right place. https://github.com/llvm/llvm-project/pull/155200 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Modules] Permit Link Declarations in Submodule Declarations in Module Maps (PR #156377)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/156377 >From 0cb749e2ec11cf51d2c97e935727e55aeaf65097 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Mon, 1 Sep 2025 16:09:21 -0700 Subject: [PATCH] Permit link decls in submodule declarations. --- clang/include/clang/Basic/DiagnosticLexKinds.td| 6 -- clang/lib/Lex/ModuleMapFile.cpp| 6 +- clang/test/ClangScanDeps/link-libraries-diag-dup.c | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index c03c4033cd3a6..eec19e462b84f 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -915,8 +915,10 @@ def err_mmap_expected_attribute : Error<"expected an attribute name">; def warn_mmap_link_redeclaration : Warning<"redeclaration of link library '%0'">, InGroup>, DefaultError; def note_mmap_prev_link_declaration : Note<"previously declared here">; -def err_mmap_submodule_link_decl -: Error<"link declaration is not allowed in submodules">; +def warn_mmap_submodule_link_decl +: Warning<"link declaration is not allowed in submodules">, + InGroup>, + DefaultError; def warn_mmap_unknown_attribute : Warning<"unknown attribute '%0'">, InGroup; def warn_mmap_mismatched_private_submodule : Warning< diff --git a/clang/lib/Lex/ModuleMapFile.cpp b/clang/lib/Lex/ModuleMapFile.cpp index f0cd9d2bee82a..7ceda7a0486d8 100644 --- a/clang/lib/Lex/ModuleMapFile.cpp +++ b/clang/lib/Lex/ModuleMapFile.cpp @@ -856,9 +856,7 @@ std::optional ModuleMapFileParser::parseLinkDecl( // Make sure we eat all the tokens when we report the errors so parsing // can continue. if (!Allowed) { -Diags.Report(LD.Location, diag::err_mmap_submodule_link_decl); -HadError = true; -return std::nullopt; +Diags.Report(LD.Location, diag::warn_mmap_submodule_link_decl); } auto [It, Inserted] = @@ -866,8 +864,6 @@ std::optional ModuleMapFileParser::parseLinkDecl( if (!Inserted) { Diags.Report(LD.Location, diag::warn_mmap_link_redeclaration) << Library; Diags.Report(It->second, diag::note_mmap_prev_link_declaration); -HadError = true; -return std::nullopt; } return std::move(LD); diff --git a/clang/test/ClangScanDeps/link-libraries-diag-dup.c b/clang/test/ClangScanDeps/link-libraries-diag-dup.c index e6612ca7bd216..ffb29bd15a1c8 100644 --- a/clang/test/ClangScanDeps/link-libraries-diag-dup.c +++ b/clang/test/ClangScanDeps/link-libraries-diag-dup.c @@ -51,7 +51,7 @@ module C { // Note that module D does not report an error because it is explicit. // Therefore we can use CHECK-NEXT for the redeclaration error on line 15. -// CHECK: module.modulemap:6:5: error: link declaration is not allowed in submodules +// CHECK: module.modulemap:6:5: error: link declaration is not allowed in submodules [-Wmodule-submodule-link-decl] // CHECK-NEXT: module.modulemap:15:3: error: redeclaration of link library 'libraryA' [-Wmodule-link-redeclaration] // CHECK-NEXT: module.modulemap:14:3: note: previously declared here // CHECK-NOT: module.modulemap:20:3: error: redeclaration of link library 'libraryA' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind][test] change to use llvm-objdump (PR #156383)
llvmbot wrote: @llvm/pr-subscribers-libunwind Author: Wu Yingcong (yingcong-wu) Changes In https://github.com/llvm/llvm-project/pull/154902, the test failed with llvm-clang-win-x-aarch64(it pretends to be a Linux build?), and objdump is not available there. Change the test to use llvm-objdump instead of objdump, it should be available in this case. --- Full diff: https://github.com/llvm/llvm-project/pull/156383.diff 1 Files Affected: - (modified) libunwind/test/eh_frame_fde_pc_range.pass.cpp (+2-2) ``diff diff --git a/libunwind/test/eh_frame_fde_pc_range.pass.cpp b/libunwind/test/eh_frame_fde_pc_range.pass.cpp index d8bcb3939913c..28f4ae1efed31 100644 --- a/libunwind/test/eh_frame_fde_pc_range.pass.cpp +++ b/libunwind/test/eh_frame_fde_pc_range.pass.cpp @@ -19,9 +19,9 @@ // XFAIL: msan // RUN: %{build} -// RUN: objcopy --dump-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe +// RUN: llvm-objcopy --dump-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe // RUN: echo -ne '\xFF' | dd of=%t_ehf_hdr.bin bs=1 seek=2 count=2 conv=notrunc status=none -// RUN: objcopy --update-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe +// RUN: llvm-objcopy --update-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe // RUN: %{exec} %t.exe // clang-format on `` https://github.com/llvm/llvm-project/pull/156383 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tidy] modernize-use-std-format: Correct replacement types when signed stdint types are used, and when enums are printed in hex. #150343 (PR #155200)
@@ -249,6 +249,10 @@ Changes in existing checks ` check to recognize literal suffixes added in C++23 and C23. +- Improved :doc:`modernize-use-std-format EugeneZelenko wrote: Please keep alphabetcial order (by check name) in this list. https://github.com/llvm/llvm-project/pull/155200 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tidy] modernize-use-std-format: Correct replacement types when signed stdint types are used, and when enums are printed in hex. #150343 (PR #155200)
@@ -249,6 +249,10 @@ Changes in existing checks ` check to recognize literal suffixes added in C++23 and C23. +- Improved :doc:`modernize-use-std-format + ` now correctly replaces signed types, and correctly EugeneZelenko wrote: Please follow 80 characters limit. https://github.com/llvm/llvm-project/pull/155200 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Modules] Permit Link Declarations in Submodule Declarations in Module Maps (PR #156377)
https://github.com/qiongsiwu created https://github.com/llvm/llvm-project/pull/156377 https://github.com/llvm/llvm-project/pull/148959 added two checks that restricts the uses of link declarations. It is later discovered that the Swift project uses link declarations in submodules extensively on Windows. This PR softens the error into a warning that defaults to error, and can be disabled using `-Wno-module-submodule-link-decl`. This PR also fixes a logic bug where the incorrect link decl is returned if we turn off the warnings with the `-Wno` arguments. rdar://159467837 >From 0cb749e2ec11cf51d2c97e935727e55aeaf65097 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Mon, 1 Sep 2025 16:09:21 -0700 Subject: [PATCH] Permit link decls in submodule declarations. --- clang/include/clang/Basic/DiagnosticLexKinds.td| 6 -- clang/lib/Lex/ModuleMapFile.cpp| 6 +- clang/test/ClangScanDeps/link-libraries-diag-dup.c | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index c03c4033cd3a6..eec19e462b84f 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -915,8 +915,10 @@ def err_mmap_expected_attribute : Error<"expected an attribute name">; def warn_mmap_link_redeclaration : Warning<"redeclaration of link library '%0'">, InGroup>, DefaultError; def note_mmap_prev_link_declaration : Note<"previously declared here">; -def err_mmap_submodule_link_decl -: Error<"link declaration is not allowed in submodules">; +def warn_mmap_submodule_link_decl +: Warning<"link declaration is not allowed in submodules">, + InGroup>, + DefaultError; def warn_mmap_unknown_attribute : Warning<"unknown attribute '%0'">, InGroup; def warn_mmap_mismatched_private_submodule : Warning< diff --git a/clang/lib/Lex/ModuleMapFile.cpp b/clang/lib/Lex/ModuleMapFile.cpp index f0cd9d2bee82a..7ceda7a0486d8 100644 --- a/clang/lib/Lex/ModuleMapFile.cpp +++ b/clang/lib/Lex/ModuleMapFile.cpp @@ -856,9 +856,7 @@ std::optional ModuleMapFileParser::parseLinkDecl( // Make sure we eat all the tokens when we report the errors so parsing // can continue. if (!Allowed) { -Diags.Report(LD.Location, diag::err_mmap_submodule_link_decl); -HadError = true; -return std::nullopt; +Diags.Report(LD.Location, diag::warn_mmap_submodule_link_decl); } auto [It, Inserted] = @@ -866,8 +864,6 @@ std::optional ModuleMapFileParser::parseLinkDecl( if (!Inserted) { Diags.Report(LD.Location, diag::warn_mmap_link_redeclaration) << Library; Diags.Report(It->second, diag::note_mmap_prev_link_declaration); -HadError = true; -return std::nullopt; } return std::move(LD); diff --git a/clang/test/ClangScanDeps/link-libraries-diag-dup.c b/clang/test/ClangScanDeps/link-libraries-diag-dup.c index e6612ca7bd216..ffb29bd15a1c8 100644 --- a/clang/test/ClangScanDeps/link-libraries-diag-dup.c +++ b/clang/test/ClangScanDeps/link-libraries-diag-dup.c @@ -51,7 +51,7 @@ module C { // Note that module D does not report an error because it is explicit. // Therefore we can use CHECK-NEXT for the redeclaration error on line 15. -// CHECK: module.modulemap:6:5: error: link declaration is not allowed in submodules +// CHECK: module.modulemap:6:5: error: link declaration is not allowed in submodules [-Wmodule-submodule-link-decl] // CHECK-NEXT: module.modulemap:15:3: error: redeclaration of link library 'libraryA' [-Wmodule-link-redeclaration] // CHECK-NEXT: module.modulemap:14:3: note: previously declared here // CHECK-NOT: module.modulemap:20:3: error: redeclaration of link library 'libraryA' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Make vector cast intrinsics constexpr (PR #156381)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/156381 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Make vector cast intrinsics constexpr (PR #156381)
https://github.com/vedantjk updated https://github.com/llvm/llvm-project/pull/156381 >From 9833270e2861fe77e7e8e862d81bacbd39983895 Mon Sep 17 00:00:00 2001 From: vedantjk Date: Mon, 1 Sep 2025 18:02:01 -0700 Subject: [PATCH] [clang] Make vector cast intrinsics constexpr --- clang/lib/Headers/avx512fintrin.h| 20 ++--- clang/lib/Headers/avx512fp16intrin.h | 42 ++-- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/clang/lib/Headers/avx512fintrin.h b/clang/lib/Headers/avx512fintrin.h index 0006e334022b6..317891dfb8c08 100644 --- a/clang/lib/Headers/avx512fintrin.h +++ b/clang/lib/Headers/avx512fintrin.h @@ -408,19 +408,19 @@ _mm512_castps256_ps512(__m256 __a) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); } -static __inline __m128d __DEFAULT_FN_ATTRS512 +static __inline __m128d __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castpd512_pd128(__m512d __a) { return __builtin_shufflevector(__a, __a, 0, 1); } -static __inline __m256d __DEFAULT_FN_ATTRS512 +static __inline __m256d __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castpd512_pd256 (__m512d __A) { return __builtin_shufflevector(__A, __A, 0, 1, 2, 3); } -static __inline __m128 __DEFAULT_FN_ATTRS512 +static __inline __m128 __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castps512_ps128(__m512 __a) { return __builtin_shufflevector(__a, __a, 0, 1, 2, 3); @@ -431,13 +431,13 @@ _mm512_castps512_ps256(__m512 __A) { return __builtin_shufflevector(__A, __A, 0, 1, 2, 3, 4, 5, 6, 7); } -static __inline __m512 __DEFAULT_FN_ATTRS512 +static __inline __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castpd_ps (__m512d __A) { return (__m512) (__A); } -static __inline __m512i __DEFAULT_FN_ATTRS512 +static __inline __m512i __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castpd_si512 (__m512d __A) { return (__m512i) (__A); @@ -452,13 +452,13 @@ _mm512_castpd128_pd512 (__m128d __A) __B, 0, 1, 2, 3, 4, 5, 6, 7); } -static __inline __m512d __DEFAULT_FN_ATTRS512 +static __inline __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castps_pd (__m512 __A) { return (__m512d) (__A); } -static __inline __m512i __DEFAULT_FN_ATTRS512 +static __inline __m512i __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castps_si512 (__m512 __A) { return (__m512i) (__A); @@ -488,19 +488,19 @@ _mm512_castsi256_si512 (__m256i __A) return __builtin_shufflevector( __A, __builtin_nondeterministic_value(__A), 0, 1, 2, 3, 4, 5, 6, 7); } -static __inline __m512 __DEFAULT_FN_ATTRS512 +static __inline __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castsi512_ps (__m512i __A) { return (__m512) (__A); } -static __inline __m512d __DEFAULT_FN_ATTRS512 +static __inline __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castsi512_pd (__m512i __A) { return (__m512d) (__A); } -static __inline __m128i __DEFAULT_FN_ATTRS512 +static __inline __m128i __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castsi512_si128 (__m512i __A) { return (__m128i)__builtin_shufflevector(__A, __A , 0, 1); diff --git a/clang/lib/Headers/avx512fp16intrin.h b/clang/lib/Headers/avx512fp16intrin.h index 6989b86a7b68c..b8145613d06fe 100644 --- a/clang/lib/Headers/avx512fp16intrin.h +++ b/clang/lib/Headers/avx512fp16intrin.h @@ -113,93 +113,93 @@ _mm512_set1_pch(_Float16 _Complex __h) { return (__m512h)_mm512_set1_ps(__builtin_bit_cast(float, __h)); } -static __inline__ __m128 __DEFAULT_FN_ATTRS128 _mm_castph_ps(__m128h __a) { +static __inline__ __m128 __DEFAULT_FN_ATTRS128_CONSTEXPR _mm_castph_ps(__m128h __a) { return (__m128)__a; } -static __inline__ __m256 __DEFAULT_FN_ATTRS256 _mm256_castph_ps(__m256h __a) { +static __inline__ __m256 __DEFAULT_FN_ATTRS256_CONSTEXPR _mm256_castph_ps(__m256h __a) { return (__m256)__a; } -static __inline__ __m512 __DEFAULT_FN_ATTRS512 _mm512_castph_ps(__m512h __a) { +static __inline__ __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castph_ps(__m512h __a) { return (__m512)__a; } -static __inline__ __m128d __DEFAULT_FN_ATTRS128 _mm_castph_pd(__m128h __a) { +static __inline__ __m128d __DEFAULT_FN_ATTRS128_CONSTEXPR _mm_castph_pd(__m128h __a) { return (__m128d)__a; } -static __inline__ __m256d __DEFAULT_FN_ATTRS256 _mm256_castph_pd(__m256h __a) { +static __inline__ __m256d __DEFAULT_FN_ATTRS256_CONSTEXPR _mm256_castph_pd(__m256h __a) { return (__m256d)__a; } -static __inline__ __m512d __DEFAULT_FN_ATTRS512 _mm512_castph_pd(__m512h __a) { +static __inline__ __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_castph_pd(__m512h __a) { return (__m512d)__a; } -static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_castph_si128(__m128h __a) { +static __inline__ __m128i __DEFAULT_FN_ATTRS128_CONSTEXPR _mm_castph_si128(__m128h __a) { return (__m128i)__a; } -static __inline__ __m256i __DEFAULT_FN_ATTRS256 +static __inline__ __m256i __DEFAULT_FN_ATTRS256_CONSTEXPR _mm256_castph_si256(__m256h __a) { return (__m256i)__a; } -static __inline__ __m512i
[clang] [clang-format] Add option AllowShortRecordOnASingleLine (PR #154580)
=?utf-8?q?Tom=C3=A1=C5=A1?= Slanina , =?utf-8?q?Tom=C3=A1=C5=A1?= Slanina , =?utf-8?q?Tom=C3=A1=C5=A1?= Slanina , =?utf-8?q?Tom=C3=A1=C5=A1?= Slanina , =?utf-8?q?Tom=C3=A1=C5=A1?= Slanina , =?utf-8?q?Tom=C3=A1=C5=A1?= Slanina , =?utf-8?q?Tom=C3=A1=C5=A1?= Slanina Message-ID: In-Reply-To: owenca wrote: It seems that `SRS_Always` doesn't work as expected. Config: ``` AllowShortRecordOnASingleLine: Always BreakBeforeBraces: Custom BraceWrapping: AfterClass: true ``` Expected: ```c++ class foo { }; ``` Actual: ```c++ class foo { }; ``` https://github.com/llvm/llvm-project/pull/154580 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] fix pc range condition check bug (PR #154902)
yingcong-wu wrote: > @yingcong-wu The new test fails on the Arm bots. Please fix it soon or revert > to get the precommit CI green again (finally). Sure, I will take a quick look now. https://github.com/llvm/llvm-project/pull/154902 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tidy] modernize-use-std-format: Correct replacement types when signed stdint types are used, and when enums are printed in hex. #150343 (PR #155200)
@@ -213,6 +213,11 @@ Changes in existing checks when the format string is converted to a different type by an implicit constructor call. +- Improved :doc:`modernize-use-std-format EugeneZelenko wrote: Sorry, I missed existing `modernize-use-std-format` entry. Convention is to have single entry per check. Just merge existing statement with your text. At least previous release should have such examples. https://github.com/llvm/llvm-project/pull/155200 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tidy] modernize-use-std-format: Correct replacement types when signed stdint types are used, and when enums are printed in hex. #150343 (PR #155200)
https://github.com/DaveBrantonCTCT updated https://github.com/llvm/llvm-project/pull/155200 >From 19b4ddf6a856fdbebac19d1779c6ee83f2d682b0 Mon Sep 17 00:00:00 2001 From: Dave Branton Date: Tue, 2 Sep 2025 08:59:08 +1200 Subject: [PATCH 1/5] Correct replacement code when signed stdint types are used, and when enums are printed in hex. --- .../utils/FormatStringConverter.cpp | 76 +++ 1 file changed, 63 insertions(+), 13 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp index 0df8e913100fc..104ce5eeecab7 100644 --- a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp +++ b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp @@ -42,7 +42,7 @@ static bool isRealCharType(const clang::QualType &Ty) { /// If possible, return the text name of the signed type that corresponds to the /// passed integer type. If the passed type is already signed then its name is -/// just returned. Only supports BuiltinTypes. +/// just returned. Supports BuiltinTypes and types from static std::optional getCorrespondingSignedTypeName(const clang::QualType &QT) { using namespace clang; @@ -80,6 +80,10 @@ getCorrespondingSignedTypeName(const clang::QualType &QT) { const bool InStd = SimplifiedTypeName.consume_front("std::"); const StringRef Prefix = InStd ? "std::" : ""; + if (SimplifiedTypeName.starts_with("int") && + SimplifiedTypeName.ends_with("_t")) +return (Twine(Prefix) + SimplifiedTypeName).str(); + if (SimplifiedTypeName.starts_with("uint") && SimplifiedTypeName.ends_with("_t")) return (Twine(Prefix) + SimplifiedTypeName.drop_front()).str(); @@ -453,8 +457,36 @@ bool FormatStringConverter::emitIntegerArgument( // std::format will print bool as either "true" or "false" by default, // but printf prints them as "0" or "1". Be compatible with printf by // requesting decimal output. -FormatSpec.push_back('d'); + +// In cases where `x` or `X` was specified in the format string +// these will technically have no effect, since the bool can only be zero or +// one. However, it seems best to leave them as-is anyway. +switch (ArgKind) { +case ConversionSpecifier::Kind::xArg: + FormatSpec.push_back('x'); // Not strictly needed + break; +case ConversionSpecifier::Kind::XArg: + FormatSpec.push_back('X'); + break; +default: + FormatSpec.push_back('d'); +} + } else if (ArgType->isEnumeralType()) { + +// If the format string contained `x` or `X`, then use these +// format modifiers. Otherwise the default will work. +switch (ArgKind) { +case ConversionSpecifier::Kind::xArg: + FormatSpec.push_back('x'); + break; +case ConversionSpecifier::Kind::XArg: + FormatSpec.push_back('X'); + break; +default: + break; +} + // std::format will try to find a specialization to print the enum // (and probably fail), whereas printf would have just expected it to // be passed as its underlying type. However, printf will have forced @@ -477,10 +509,21 @@ bool FormatStringConverter::emitIntegerArgument( // Even -Wformat doesn't warn for this. std::format will format as // unsigned unless we cast it. if (const std::optional MaybeCastType = -castTypeForArgument(ArgKind, ArgType)) +castTypeForArgument(ArgKind, ArgType)) { + switch (ArgKind) { + case ConversionSpecifier::Kind::xArg: +FormatSpec.push_back('x'); +break; + case ConversionSpecifier::Kind::XArg: +FormatSpec.push_back('X'); +break; + default: +break; + } + ArgFixes.emplace_back( ArgIndex, (Twine("static_cast<") + *MaybeCastType + ">(").str()); -else +} else return conversionNotPossible( (Twine("argument ") + Twine(ArgIndex) + " cannot be cast to " + Twine(ArgKind == ConversionSpecifier::Kind::uArg ? "unsigned" @@ -488,9 +531,20 @@ bool FormatStringConverter::emitIntegerArgument( " integer type to match format" " specifier and StrictMode is enabled") .str()); - } else if (isRealCharType(ArgType) || !ArgType->isIntegerType()) { -// Only specify integer if the argument is of a different type -FormatSpec.push_back('d'); + } else { +switch (ArgKind) { +case ConversionSpecifier::Kind::xArg: + FormatSpec.push_back('x'); + break; +case ConversionSpecifier::Kind::XArg: + FormatSpec.push_back('X'); + break; +default: + if (isRealCharType(ArgType) || !ArgType->isIntegerType()) { +// Only specify integer if the argument is of a different type +FormatSpec.push_back('d'); + } +} } return true; } @@ -514,6 +568,8 @@ bool FormatStringConverter::emitType(const PrintfSpecifier &FS, const Expr *Arg, case Con
[clang] [clang] Make vector cast intrinsics constexpr (PR #156381)
https://github.com/ckoparkar edited https://github.com/llvm/llvm-project/pull/156381 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Make vector cast intrinsics constexpr (PR #156381)
@@ -113,93 +113,93 @@ _mm512_set1_pch(_Float16 _Complex __h) { return (__m512h)_mm512_set1_ps(__builtin_bit_cast(float, __h)); } -static __inline__ __m128 __DEFAULT_FN_ATTRS128 _mm_castph_ps(__m128h __a) { +static __inline__ __m128 __DEFAULT_FN_ATTRS128_CONSTEXPR _mm_castph_ps(__m128h __a) { ckoparkar wrote: Could you please run [`clang-format`](https://github.com/llvm/llvm-project/blob/main/clang/tools/clang-format/git-clang-format) on this patch? Some lines here are longer than 80 chars so the code formatter check will likely fail. https://github.com/llvm/llvm-project/pull/156381 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV][MC] Add MC support of Zibi experimental extension (PR #127463)
@@ -0,0 +1,34 @@ +# RUN: not llvm-mc -triple=riscv32 --mattr=+experimental-zibi %s 2>&1 \ +# RUN:| FileCheck %s --check-prefix=CHECK-ERROR +# RUN: not llvm-mc -triple=riscv64 --mattr=+experimental-zibi %s 2>&1 \ +# RUN:| FileCheck %s --check-prefix=CHECK-ERROR +beqi a0, 0x0, 0x400 +# CHECK-ERROR: [[@LINE-1]]:10: error: immediate must be non-zero in the range [-1, 31] +# CHECK-ERROR-LABEL: beqi a0, 0x0, 0x400 +beqi a0, 0x21, 0x400 +# CHECK-ERROR: [[@LINE-1]]:10: error: immediate must be non-zero in the range [-1, 31] +# CHECK-ERROR-LABEL: beqi a0, 0x21, 0x400 +beqi a2, 0x10, -0x1f000 +# CHECK-ERROR: [[@LINE-1]]:16: error: immediate must be a multiple of 2 bytes in the range [-4096, 4094] +# CHECK-ERROR-LABEL: beqi a2, 0x10, -0x1f000 +beqi a2, 0x10, 0x1000 +# CHECK-ERROR: [[@LINE-1]]:16: error: immediate must be a multiple of 2 bytes in the range [-4096, 4094] +# CHECK-ERROR-LABEL: beqi a2, 0x10, 0x1000 +beqi a2, 0x10, 0x111 +# CHECK-ERROR: [[@LINE-1]]:16: error: immediate must be a multiple of 2 bytes in the range [-4096, 4094] +# CHECK-ERROR-LABEL: beqi a2, 0x10, 0x111 +bnei a0, 0x0, 0x400 +# CHECK-ERROR: [[@LINE-1]]:10: error: immediate must be non-zero in the range [-1, 31] +# CHECK-ERROR-LABEL: bnei a0, 0x0, 0x400 +bnei a0, 0x21, 0x400 +# CHECK-ERROR: [[@LINE-1]]:10: error: immediate must be non-zero in the range [-1, 31] +# CHECK-ERROR-LABEL: bnei a0, 0x21, 0x400 +bnei a2, 0x10, -0x1f000 +# CHECK-ERROR: [[@LINE-1]]:16: error: immediate must be a multiple of 2 bytes in the range [-4096, 4094] +# CHECK-ERROR-LABEL: bnei a2, 0x10, -0x1f000 +bnei a2, 0x10, 0x1000 +# CHECK-ERROR: [[@LINE-1]]:16: error: immediate must be a multiple of 2 bytes in the range [-4096, 4094] +# CHECK-ERROR-LABEL: bnei a2, 0x10, 0x1000 +bnei a2, 0x10, 0x111 +# CHECK-ERROR: [[@LINE-1]]:16: error: immediate must be a multiple of 2 bytes in the range [-4096, 4094] +# CHECK-ERROR-LABEL: bnei a2, 0x10, 0x111 arichardson wrote: missing newline at end https://github.com/llvm/llvm-project/pull/127463 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Simplify code gen for riscv_vector_builtin_cg.inc [NFC] (PR #156397)
https://github.com/wangpc-pp approved this pull request. https://github.com/llvm/llvm-project/pull/156397 ___ 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] Support designated initializers (PR #142150)
nikic wrote: ``` Building CXX object tools/clang/tools/extra/clang-reorder-fields/CMakeFiles/obj.clangReorderFields.dir/Designator.cpp.o FAILED: tools/clang/tools/extra/clang-reorder-fields/CMakeFiles/obj.clangReorderFields.dir/Designator.cpp.o sccache /opt/llvm/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/clang-reorder-fields -I/home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/clang-reorder-fields -I/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include -gmlt -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17 -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/tools/extra/clang-reorder-fields/CMakeFiles/obj.clangReorderFields.dir/Designator.cpp.o -MF tools/clang/tools/extra/clang-reorder-fields/CMakeFiles/obj.clangReorderFields.dir/Designator.cpp.o.d -o tools/clang/tools/extra/clang-reorder-fields/CMakeFiles/obj.clangReorderFields.dir/Designator.cpp.o -c /home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/clang-reorder-fields/Designator.cpp In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/clang-reorder-fields/Designator.cpp:15: /home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/clang-reorder-fields/Designator.h:157:23: error: private field 'ILE' is not used [-Werror,-Wunused-private-field] 157 | const InitListExpr *ILE; | ^ 1 error generated. ``` https://github.com/llvm/llvm-project/pull/142150 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] New bugprone-derived-method-shadowing-base-method (PR #154746)
@@ -0,0 +1,132 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "DerivedMethodShadowingBaseMethodCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +namespace { + +bool sameBasicType(const ParmVarDecl *Lhs, const ParmVarDecl *Rhs) { + if (Lhs && Rhs) { +return Lhs->getType() + .getCanonicalType() + .getNonReferenceType() + .getUnqualifiedType() == Rhs->getType() +.getCanonicalType() +.getNonReferenceType() +.getUnqualifiedType(); t-a-james wrote: >Nit: you can fold the nullptr check into the return: return Lhs && Rhs && ...; Ah yeah, that's slightly neater - fixed in my latest push > Interesting that the clang-format CI check is not complaining about this one. What should it be complaining about? This is the way clang-format wants to write this code https://github.com/llvm/llvm-project/pull/154746 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] New bugprone-derived-method-shadowing-base-method (PR #154746)
@@ -0,0 +1,132 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "DerivedMethodShadowingBaseMethodCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +namespace { + +bool sameBasicType(const ParmVarDecl *Lhs, const ParmVarDecl *Rhs) { + if (Lhs && Rhs) { +return Lhs->getType() + .getCanonicalType() + .getNonReferenceType() + .getUnqualifiedType() == Rhs->getType() +.getCanonicalType() +.getNonReferenceType() +.getUnqualifiedType(); + } + return false; +} + +bool namesCollide(const CXXMethodDecl &Lhs, const CXXMethodDecl &Rhs) { + if (Lhs.getNameAsString() != Rhs.getNameAsString()) +return false; + if (Lhs.isConst() != Rhs.isConst()) +return false; + if (Lhs.getNumParams() != Rhs.getNumParams()) +return false; + for (unsigned int It = 0; It < Lhs.getNumParams(); ++It) +if (!sameBasicType(Lhs.getParamDecl(It), Rhs.getParamDecl(It))) + return false; + return true; +} + +AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) { + const CXXRecordDecl *DerivedClass = Node.getParent(); + for (const auto &Base : DerivedClass->bases()) { +// SmallVector instead of std::stack, to avoid allications in most cases t-a-james wrote: Fixed in my latest push https://github.com/llvm/llvm-project/pull/154746 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] New bugprone-derived-method-shadowing-base-method (PR #154746)
https://github.com/t-a-james updated https://github.com/llvm/llvm-project/pull/154746 >From 39ad4945d05f3e88fd32dfdea585aa99c6ba985f Mon Sep 17 00:00:00 2001 From: Tom James Date: Thu, 21 Aug 2025 13:14:24 +0100 Subject: [PATCH 01/23] [clang-tidy] New bugprone-method-hiding check --- .../bugprone/BugproneTidyModule.cpp | 6 + .../clang-tidy/bugprone/CMakeLists.txt| 7 + .../clang-tidy/bugprone/MethodHidingCheck.cpp | 148 ++ .../clang-tidy/bugprone/MethodHidingCheck.h | 37 + clang-tools-extra/docs/ReleaseNotes.rst | 11 ++ .../checks/bugprone/method-hiding.rst | 15 ++ .../docs/clang-tidy/checks/list.rst | 7 + .../checkers/bugprone/method-hiding.cpp | 118 ++ 8 files changed, 349 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/bugprone/MethodHidingCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/bugprone/MethodHidingCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/method-hiding.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/method-hiding.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index 824ebdfbd00dc..d1d1979794743 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -4,6 +4,9 @@ // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// SPDX-FileCopyrightText: Portions Copyright 2025 Siemens and/or its affiliates +// May 2025 modified by Siemens and/or its affiliates by Tom James +// //===--===// #include "../ClangTidy.h" @@ -42,6 +45,7 @@ #include "LambdaFunctionNameCheck.h" #include "MacroParenthesesCheck.h" #include "MacroRepeatedSideEffectsCheck.h" +#include "MethodHidingCheck.h" #include "MisleadingSetterOfReferenceCheck.h" #include "MisplacedOperatorInStrlenInAllocCheck.h" #include "MisplacedPointerArithmeticInAllocCheck.h" @@ -153,6 +157,8 @@ class BugproneModule : public ClangTidyModule { "bugprone-incorrect-enable-if"); CheckFactories.registerCheck( "bugprone-incorrect-enable-shared-from-this"); +CheckFactories.registerCheck( +"bugprone-method-hiding"); CheckFactories.registerCheck( "bugprone-unintended-char-ostream-output"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index 59928e5e47a09..5745654855108 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -1,3 +1,9 @@ +# 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 +# SPDX-FileCopyrightText: Portions Copyright 2025 Siemens and/or its affiliates +# May 2025 modified by Siemens and/or its affiliates by Tom James + set(LLVM_LINK_COMPONENTS support FrontendOpenMP @@ -31,6 +37,7 @@ add_clang_library(clangTidyBugproneModule STATIC IncorrectEnableIfCheck.cpp IncorrectEnableSharedFromThisCheck.cpp InvalidEnumDefaultInitializationCheck.cpp + MethodHidingCheck.cpp UnintendedCharOstreamOutputCheck.cpp ReturnConstRefFromParameterCheck.cpp SuspiciousStringviewDataUsageCheck.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/MethodHidingCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MethodHidingCheck.cpp new file mode 100644 index 0..865ef115950e6 --- /dev/null +++ b/clang-tools-extra/clang-tidy/bugprone/MethodHidingCheck.cpp @@ -0,0 +1,148 @@ +//===--- MethodHidingCheck.cpp - clang-tidy ===// +// +// SPDX-FileCopyrightText: 2025 Siemens Corporation and/or its affiliates +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MethodHidingCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +namespace { + +bool sameBasicType(ParmVarDecl const *Lhs, ParmVarDecl const *Rhs) { + if (Lhs && Rhs) { +return Lhs->getType() + .getCanonicalType() + .getNonReferenceType() + .getUnqualifiedType() == Rhs->getType() +.getCanonicalType() +.getNonReferenceType() +.getUnqualifiedType(); + } +
[clang-tools-extra] c128b8c - [clang-reorder-fields] Fix unused private field warning (NFC)
Author: Nikita Popov Date: 2025-09-01T10:07:11+02:00 New Revision: c128b8c46f2a3b750c9abcba1e303f92d6531e5f URL: https://github.com/llvm/llvm-project/commit/c128b8c46f2a3b750c9abcba1e303f92d6531e5f DIFF: https://github.com/llvm/llvm-project/commit/c128b8c46f2a3b750c9abcba1e303f92d6531e5f.diff LOG: [clang-reorder-fields] Fix unused private field warning (NFC) Fixes: ``` In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/clang-reorder-fields/Designator.cpp:15: /home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/clang-reorder-fields/Designator.h:157:23: error: private field 'ILE' is not used [-Werror,-Wunused-private-field] 157 | const InitListExpr *ILE; ``` Added: Modified: clang-tools-extra/clang-reorder-fields/Designator.cpp clang-tools-extra/clang-reorder-fields/Designator.h Removed: diff --git a/clang-tools-extra/clang-reorder-fields/Designator.cpp b/clang-tools-extra/clang-reorder-fields/Designator.cpp index fc070f7f6746d..d36a080c0435f 100644 --- a/clang-tools-extra/clang-reorder-fields/Designator.cpp +++ b/clang-tools-extra/clang-reorder-fields/Designator.cpp @@ -62,7 +62,7 @@ bool Designator::isFinished() { Designators::Designators(const Expr *Init, const InitListExpr *ILE, const ASTContext *Context) -: ILE(ILE), Context(Context) { +: Context(Context) { if (ILE->getType()->isArrayType()) { const ConstantArrayType *CAT = Context->getAsConstantArrayType(ILE->getType()); @@ -90,7 +90,7 @@ Designators::Designators(const Expr *Init, const InitListExpr *ILE, Designators::Designators(const DesignatedInitExpr *DIE, const InitListExpr *ILE, const ASTContext *Context) -: ILE(ILE), Context(Context) { +: Context(Context) { for (const auto &D : DIE->designators()) { if (D.isFieldDesignator()) { RecordDecl *DesignatorRecord = D.getFieldDecl()->getParent(); diff --git a/clang-tools-extra/clang-reorder-fields/Designator.h b/clang-tools-extra/clang-reorder-fields/Designator.h index 09c0a6ce27e26..859be28e66de7 100644 --- a/clang-tools-extra/clang-reorder-fields/Designator.h +++ b/clang-tools-extra/clang-reorder-fields/Designator.h @@ -154,7 +154,6 @@ class Designators { /// expression is found. bool enterImplicitInitLists(const Expr *Init); - const InitListExpr *ILE; const ASTContext *Context; SmallVector DesignatorList; }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] New bugprone-derived-method-shadowing-base-method (PR #154746)
@@ -0,0 +1,127 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "DerivedMethodShadowingBaseMethodCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +namespace { + +bool sameBasicType(const ParmVarDecl *Lhs, const ParmVarDecl *Rhs) { + if (Lhs && Rhs) { +return Lhs->getType() + .getCanonicalType() + .getNonReferenceType() + .getUnqualifiedType() == Rhs->getType() +.getCanonicalType() +.getNonReferenceType() +.getUnqualifiedType(); + } + return false; +} + +bool namesCollide(const CXXMethodDecl &Lhs, const CXXMethodDecl &Rhs) { + if (Lhs.getNameAsString() != Rhs.getNameAsString()) +return false; + if (Lhs.isConst() != Rhs.isConst()) +return false; + if (Lhs.getNumParams() != Rhs.getNumParams()) +return false; + for (unsigned int It = 0; It < Lhs.getNumParams(); ++It) +if (!sameBasicType(Lhs.getParamDecl(It), Rhs.getParamDecl(It))) + return false; + return true; +} + +AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) { + const CXXRecordDecl *DerivedClass = Node.getParent(); + for (const auto &Base : DerivedClass->bases()) { +std::stack Stack; t-a-james wrote: I was willing to be very impressed that (a) you knew the 64-byte target for SmallVector off by heart, (b) it was possible to fit `CXXBaseSpecifier` into 8 bytes, and that (c) you knew this too. But of course, it's a pointer. https://github.com/llvm/llvm-project/pull/154746 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] New bugprone-derived-method-shadowing-base-method (PR #154746)
@@ -0,0 +1,132 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "DerivedMethodShadowingBaseMethodCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +namespace { + +bool sameBasicType(const ParmVarDecl *Lhs, const ParmVarDecl *Rhs) { + if (Lhs && Rhs) { +return Lhs->getType() + .getCanonicalType() + .getNonReferenceType() + .getUnqualifiedType() == Rhs->getType() +.getCanonicalType() +.getNonReferenceType() +.getUnqualifiedType(); + } + return false; +} + +bool namesCollide(const CXXMethodDecl &Lhs, const CXXMethodDecl &Rhs) { + if (Lhs.getNameAsString() != Rhs.getNameAsString()) +return false; + if (Lhs.isConst() != Rhs.isConst()) +return false; + if (Lhs.getNumParams() != Rhs.getNumParams()) +return false; + for (unsigned int It = 0; It < Lhs.getNumParams(); ++It) +if (!sameBasicType(Lhs.getParamDecl(It), Rhs.getParamDecl(It))) + return false; + return true; +} + +AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) { + const CXXRecordDecl *DerivedClass = Node.getParent(); + for (const auto &Base : DerivedClass->bases()) { +// SmallVector instead of std::stack, to avoid allications in most cases +llvm::SmallVector Stack; +Stack.push_back(&Base); +while (!Stack.empty()) { + const CXXBaseSpecifier *CurrentBaseSpec = Stack.back(); + Stack.pop_back(); + + if (CurrentBaseSpec->getAccessSpecifier() == + clang::AccessSpecifier::AS_private) +continue; + + const auto *CurrentRecord = + CurrentBaseSpec->getType()->getAsCXXRecordDecl(); + if (!CurrentRecord) +continue; + + // For multiple inheritance, we ignore only the bases that come from the + // std:: namespace + if (CurrentRecord->isInStdNamespace()) +continue; + + for (const auto &BaseMethod : CurrentRecord->methods()) { +if (namesCollide(*BaseMethod, Node)) { + ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder); + Builder->setBinding("base_method", + clang::DynTypedNode::create(*BaseMethod)); + return true; +} + } + + for (const auto &SubBase : CurrentRecord->bases()) +Stack.push_back(&SubBase); +} + } + return false; +} + +// Same as clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp, +// similar matchers are used elsewhere in LLVM +AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); } + +} // namespace + +DerivedMethodShadowingBaseMethodCheck::DerivedMethodShadowingBaseMethodCheck( +StringRef Name, ClangTidyContext *Context) +: ClangTidyCheck(Name, Context) {} + +void DerivedMethodShadowingBaseMethodCheck::registerMatchers( +MatchFinder *Finder) { + Finder->addMatcher( + cxxMethodDecl( + unless(anyOf(isOutOfLine(), isStaticStorageClass(), isImplicit(), + cxxConstructorDecl(), isOverride(), isPrivate(), + // isFinal(), //included with isOverride, + // Templates are not handled yet + ast_matchers::isTemplateInstantiation(), + ast_matchers::isExplicitTemplateSpecialization())), + ofClass(cxxRecordDecl(isDerivedFrom(cxxRecordDecl())) + .bind("derived_class")), + nameCollidesWithMethodInBase()) + .bind("shadowing_method"), + this); +} + +void DerivedMethodShadowingBaseMethodCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *ShadowingMethod = + Result.Nodes.getNodeAs("shadowing_method"); + const auto *DerivedClass = + Result.Nodes.getNodeAs("derived_class"); + const auto *BaseMethod = Result.Nodes.getNodeAs("base_method"); + + if (!ShadowingMethod || !DerivedClass || !BaseMethod) +llvm_unreachable("Required binding not found"); + + diag(ShadowingMethod->getBeginLoc(), "'%0' hides same method in '%1'") + << ShadowingMethod->getQualifiedNameAsString() + << BaseMethod->getParent()->getNameAsString(); + diag(BaseMethod->getBeginLoc(), "previous definition of '%0' is here", + DiagnosticIDs::Note) + << ShadowingMethod->getNameAsString(); t-a-james wrote: Nice, fixed in my latest push https://github.com/llvm/llvm-project/pull/154746 ___
[clang] [clang-tools-extra] [clang][AST] Fix source range of class template implicit instantiations. (PR #156011)
https://github.com/frederic-tingaud-sonarsource updated https://github.com/llvm/llvm-project/pull/156011 >From 56c46c1224927289e08b8627484eab51dc21a69b Mon Sep 17 00:00:00 2001 From: Fred Tingaud Date: Mon, 25 Aug 2025 20:07:04 +0200 Subject: [PATCH] [clang][AST] Fix source range of class template implicit instantiations. --- .../checkers/hicpp/exception-baseclass.cpp| 10 +-- clang/lib/AST/DeclTemplate.cpp| 7 +- clang/test/AST/ast-dump-decl.cpp | 8 +- ...penmp-begin-declare-variant_template_3.cpp | 4 +- .../test/AST/ast-dump-template-decls-json.cpp | 4 +- clang/test/AST/ast-dump-template-redecl.cpp | 88 +++ .../ParserHLSL/hlsl_resource_class_attr.hlsl | 2 +- 7 files changed, 108 insertions(+), 15 deletions(-) create mode 100644 clang/test/AST/ast-dump-template-redecl.cpp diff --git a/clang-tools-extra/test/clang-tidy/checkers/hicpp/exception-baseclass.cpp b/clang-tools-extra/test/clang-tidy/checkers/hicpp/exception-baseclass.cpp index b5e405a691848..949339d6e3f4f 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/hicpp/exception-baseclass.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/hicpp/exception-baseclass.cpp @@ -109,15 +109,15 @@ template void ThrowException() { throw T(); } // CHECK-NOTES: [[@LINE-1]]:31: warning: throwing an exception whose type 'bad_generic_exception' is not derived from 'std::exception' // CHECK-NOTES: [[@LINE-2]]:31: note: type 'bad_generic_exception' is a template instantiation of 'T' -// CHECK-NOTES: [[@LINE+25]]:1: note: type defined here +// CHECK-NOTES: [[@LINE+26]]:1: note: type defined here // CHECK-NOTES: [[@LINE-5]]:31: warning: throwing an exception whose type 'bad_generic_exception' is not derived from 'std::exception' // CHECK-NOTES: [[@LINE-6]]:31: note: type 'bad_generic_exception' is a template instantiation of 'T' -// CHECK-NOTES: [[@LINE+21]]:1: note: type defined here +// CHECK-NOTES: [[@LINE+22]]:1: note: type defined here // CHECK-NOTES: [[@LINE-9]]:31: warning: throwing an exception whose type 'exotic_exception' is not derived from 'std::exception' // CHECK-NOTES: [[@LINE-10]]:31: note: type 'exotic_exception' is a template instantiation of 'T' -// CHECK-NOTES: [[@LINE+20]]:1: note: type defined here +// CHECK-NOTES: [[@LINE+21]]:1: note: type defined here // CHECK-NOTES: [[@LINE-13]]:31: warning: throwing an exception whose type 'int' is not derived from 'std::exception' // CHECK-NOTES: [[@LINE-14]]:31: note: type 'int' is a template instantiation of 'T' @@ -158,10 +158,10 @@ void generic_exceptions() { throw bad_generic_exception(); // CHECK-NOTES: [[@LINE-1]]:9: warning: throwing an exception whose type 'bad_generic_exception' is not derived from 'std::exception' - // CHECK-NOTES: [[@LINE-24]]:1: note: type defined here + // CHECK-NOTES: [[@LINE-23]]:1: note: type defined here throw bad_generic_exception(); // CHECK-NOTES: [[@LINE-1]]:9: warning: throwing an exception whose type 'bad_generic_exception' is not derived from 'std::exception' - // CHECK-NOTES: [[@LINE-27]]:1: note: type defined here + // CHECK-NOTES: [[@LINE-26]]:1: note: type defined here THROW_EXCEPTION(bad_generic_exception); THROW_EXCEPTION(bad_generic_exception); diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 3162857aac5d0..01cc33b795308 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1050,7 +1050,12 @@ ClassTemplateSpecializationDecl::getSourceRange() const { if (const auto *CTPSD = dyn_cast(Pattern)) return CTPSD->getSourceRange(); -return cast(Pattern)->getSourceRange(); + +const auto *CTD = cast(Pattern); +if (CTD->getTemplatedDecl()->hasDefinition()) + return CTD->getTemplatedDecl()->getDefinition()->getSourceRange(); + +return CTD->getSourceRange(); } case TSK_ExplicitSpecialization: { SourceRange Range = CXXRecordDecl::getSourceRange(); diff --git a/clang/test/AST/ast-dump-decl.cpp b/clang/test/AST/ast-dump-decl.cpp index afb507833d869..54723b01d5a95 100644 --- a/clang/test/AST/ast-dump-decl.cpp +++ b/clang/test/AST/ast-dump-decl.cpp @@ -334,7 +334,7 @@ namespace testClassTemplateDecl { // CHECK-NEXT: | |-CXXDestructorDecl 0x[[#%x,TEMPLATE_DESTRUCTOR_DECL:]] col:5 ~TestClassTemplate 'void ()' not_selected{{$}} // CHECK-NEXT: | |-CXXMethodDecl 0x[[#%x,TEMPLATE_METHOD_DECL:]] col:9 j 'int ()'{{$}} // CHECK-NEXT: | `-FieldDecl 0x{{.+}} col:9 i 'int'{{$}} -// CHECK-NEXT: |-ClassTemplateSpecializationDecl 0x{{.+}} line:[[@LINE-56]]:30 class TestClassTemplate definition implicit_instantiation{{$}} +// CHECK-NEXT: |-ClassTemplateSpecializationDecl 0x{{.+}} line:[[@LINE-56]]:30 class TestClassTemplate definition implicit_instantiation{{$}} // CHECK-NEXT: | |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init{{$}} // CHECK-NEXT: | | |-DefaultConstructor exists non_trivial use
[clang] [X86] Update BMI, BMI2 and TBM constexpr tests (PR #156260)
@@ -237,85 +238,85 @@ unsigned long long test_blsr_u64(unsigned long long __X) { // Test constexpr handling. #if defined(__cplusplus) && (__cplusplus >= 201103L) -char andnu32[__andn_u32(0x01234567, 0xFECDBA98) == (~0x01234567 & 0xFECDBA98) ? 1 : -1]; -char andn2u32[_andn_u32(0x01234567, 0xFECDBA98) == (~0x01234567 & 0xFECDBA98) ? 1 : -1]; +TEST_CONSTEXPR(__andn_u32(0x01234567, 0xFECDBA98) == (~0x01234567 & 0xFECDBA98)); bursow wrote: Okey https://github.com/llvm/llvm-project/pull/156260 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Introduce -fexperimental-loop-fuse to clang and flang (PR #142686)
@@ -204,6 +205,10 @@ static cl::opt EnableLoopInterchange("enable-loopinterchange", cl::init(false), cl::Hidden, cl::desc("Enable the LoopInterchange Pass")); +static cl::opt EnableLoopFusion("enable-loopfusion", cl::init(false), madhur13490 wrote: Done. I think it is a bit of a mess. Options are not uniformly declared and checked. ANyway, for now I have moved `enable-fusion` as you suggested, and this does not recognize `-mllvm -enable-fusion` for clang. https://github.com/llvm/llvm-project/pull/142686 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Enable outline atomics for Haiku and Managarm aarch64 (PR #156299)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Brad Smith (brad0) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/156299.diff 3 Files Affected: - (modified) clang/lib/Driver/ToolChains/Haiku.h (+5) - (modified) clang/lib/Driver/ToolChains/Managarm.h (+6) - (modified) clang/test/Driver/aarch64-features.c (+6) ``diff diff --git a/clang/lib/Driver/ToolChains/Haiku.h b/clang/lib/Driver/ToolChains/Haiku.h index edebf5c49187b..b4b14cf0aeb99 100644 --- a/clang/lib/Driver/ToolChains/Haiku.h +++ b/clang/lib/Driver/ToolChains/Haiku.h @@ -56,6 +56,11 @@ class LLVM_LIBRARY_VISIBILITY Haiku : public Generic_ELF { const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + bool IsAArch64OutlineAtomicsDefault( + const llvm::opt::ArgList &Args) const override { +return true; + } + SanitizerMask getSupportedSanitizers() const override; unsigned GetDefaultDwarfVersion() const override { return 4; } diff --git a/clang/lib/Driver/ToolChains/Managarm.h b/clang/lib/Driver/ToolChains/Managarm.h index 2082e2c615f28..408c0589a3138 100644 --- a/clang/lib/Driver/ToolChains/Managarm.h +++ b/clang/lib/Driver/ToolChains/Managarm.h @@ -34,6 +34,12 @@ class LLVM_LIBRARY_VISIBILITY Managarm : public Generic_ELF { void addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + + bool IsAArch64OutlineAtomicsDefault( + const llvm::opt::ArgList &Args) const override { +return true; + } + SanitizerMask getSupportedSanitizers() const override; std::string computeSysRoot() const override; diff --git a/clang/test/Driver/aarch64-features.c b/clang/test/Driver/aarch64-features.c index 05dd3bf39fae3..11c7343544345 100644 --- a/clang/test/Driver/aarch64-features.c +++ b/clang/test/Driver/aarch64-features.c @@ -79,6 +79,12 @@ // RUN: --gcc-toolchain=%S/Inputs/aarch64-linux-gnu-tree/gcc-7.5.0 \ // RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-ON %s +// RUN: %clang --target=aarch64-unknown-haiku -rtlib=libgcc \ +// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-ON %s + +// RUN: %clang --target=aarch64-unknown-managarm-mlibc -rtlib=libgcc \ +// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-ON %s + // CHECK-OUTLINE-ATOMICS-ON: "-target-feature" "+outline-atomics" // CHECK-OUTLINE-ATOMICS-OFF-NOT: "-target-feature" "+outline-atomics" // CHECK-NO-OUTLINE-ATOMICS: "-target-feature" "-outline-atomics" `` https://github.com/llvm/llvm-project/pull/156299 ___ 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] Support designated initializers (PR #142150)
nikic wrote: Fixed by https://github.com/llvm/llvm-project/commit/c128b8c46f2a3b750c9abcba1e303f92d6531e5f. https://github.com/llvm/llvm-project/pull/142150 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Support direct initialization in modernize smart pointer (PR #154732)
https://github.com/Sockke closed https://github.com/llvm/llvm-project/pull/154732 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64][FMV] Enable PAuth and BTI hardening of resolver functions (PR #141573)
atrosinenko wrote: @labrinea I'm sorry for disappearing, I will update this PR this week. https://github.com/llvm/llvm-project/pull/141573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix clang_cmake_builddir (PR #155844)
https://github.com/Keenuts approved this pull request. Looks ok to me. So far seems like even on main, setting `-DLLVM_LIBDIR_SUFFIX` has no effect so seems like this is ok Adding @kwk in case I'm missing something https://github.com/llvm/llvm-project/pull/155844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][DirectX] Finish WaveGetLaneCount implementation (PR #156338)
https://github.com/Keenuts created https://github.com/llvm/llvm-project/pull/156338 Some testing was lacking, as well as DirectX lowering of the intrinsic. Fixes #99159 From fd5bfbba2de4ae25336487b9778d56b5292d60ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= Date: Mon, 1 Sep 2025 15:50:11 +0200 Subject: [PATCH] [HLSL][DirectX] Finish WaveGetLaneCount implementation Some testing was lacking, as well as DirectX lowering of the intrinsic. Fixes #99159 --- clang/test/SemaHLSL/WaveGetLaneCount-sm5.hlsl | 9 + clang/test/SemaHLSL/WaveGetLaneCount-sm6.hlsl | 9 + llvm/lib/Target/DirectX/DXIL.td | 9 + llvm/lib/Target/DirectX/DXILShaderFlags.cpp | 1 + llvm/test/CodeGen/DirectX/ShaderFlags/wave-ops.ll | 7 +++ llvm/test/CodeGen/DirectX/WaveGetLaneCount.ll | 13 + 6 files changed, 48 insertions(+) create mode 100644 clang/test/SemaHLSL/WaveGetLaneCount-sm5.hlsl create mode 100644 clang/test/SemaHLSL/WaveGetLaneCount-sm6.hlsl create mode 100644 llvm/test/CodeGen/DirectX/WaveGetLaneCount.ll diff --git a/clang/test/SemaHLSL/WaveGetLaneCount-sm5.hlsl b/clang/test/SemaHLSL/WaveGetLaneCount-sm5.hlsl new file mode 100644 index 0..7a12dba62367e --- /dev/null +++ b/clang/test/SemaHLSL/WaveGetLaneCount-sm5.hlsl @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel5.1-library -verify %s + +[shader("compute")] +[numthreads(8,8,1)] +unsigned foo() { +// expected-error@#site {{'WaveGetLaneCount' is only available on Shader Model 6.0 or newer}} +// expected-note@hlsl/hlsl_alias_intrinsics.h:* {{'WaveGetLaneCount' has been marked as being introduced in Shader Model 6.0 here, but the deployment target is Shader Model 5.1}} +return hlsl::WaveGetLaneCount(); // #site +} diff --git a/clang/test/SemaHLSL/WaveGetLaneCount-sm6.hlsl b/clang/test/SemaHLSL/WaveGetLaneCount-sm6.hlsl new file mode 100644 index 0..b988b1cb4ad54 --- /dev/null +++ b/clang/test/SemaHLSL/WaveGetLaneCount-sm6.hlsl @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.0-library -verify %s + +// expected-no-diagnostics +[shader("compute")] +[numthreads(8,8,1)] +unsigned foo() { +return hlsl::WaveGetLaneCount(); +} + diff --git a/llvm/lib/Target/DirectX/DXIL.td b/llvm/lib/Target/DirectX/DXIL.td index c65ead45e2c7e..c9977e3bfdbf4 100644 --- a/llvm/lib/Target/DirectX/DXIL.td +++ b/llvm/lib/Target/DirectX/DXIL.td @@ -998,6 +998,15 @@ def WaveGetLaneIndex : DXILOp<111, waveGetLaneIndex> { let attributes = [Attributes]; } +def WaveGetLaneCount : DXILOp<112, waveGetLaneCount> { + let Doc = "returns the number of lanes in a wave on this architecture"; + let intrinsics = [IntrinSelect]; + let arguments = []; + let result = Int32Ty; + let stages = [Stages]; + let attributes = [Attributes]; +} + def WaveActiveAnyTrue : DXILOp<113, waveAnyTrue> { let Doc = "returns true if the expression is true in any of the active lanes " "in the current wave"; diff --git a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp index e7e7f2ce66ae8..58a94f7b1cb9d 100644 --- a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp +++ b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp @@ -85,6 +85,7 @@ static bool checkWaveOps(Intrinsic::ID IID) { return false; case Intrinsic::dx_wave_is_first_lane: case Intrinsic::dx_wave_getlaneindex: + case Intrinsic::dx_wave_get_lane_count: case Intrinsic::dx_wave_any: case Intrinsic::dx_wave_all: case Intrinsic::dx_wave_readlane: diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/wave-ops.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/wave-ops.ll index 7a876f67615cd..fab7657f862d8 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/wave-ops.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/wave-ops.ll @@ -27,6 +27,13 @@ entry: ret i32 %ret } +define noundef i32 @wave_get_lane_count() { +entry: + ; CHECK: Function wave_get_lane_count : [[WAVE_FLAG]] + %ret = call i32 @llvm.dx.wave.get.lane.count() + ret i32 %ret +} + define noundef i1 @wave_any(i1 %x) { entry: ; CHECK: Function wave_any : [[WAVE_FLAG]] diff --git a/llvm/test/CodeGen/DirectX/WaveGetLaneCount.ll b/llvm/test/CodeGen/DirectX/WaveGetLaneCount.ll new file mode 100644 index 0..784d5781f755e --- /dev/null +++ b/llvm/test/CodeGen/DirectX/WaveGetLaneCount.ll @@ -0,0 +1,13 @@ +; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-compute %s | FileCheck %s + +define void @main() { +entry: +; CHECK: call i32 @dx.op.waveGetLaneCount(i32 112) #[[#ATTR:]] + %0 = call i32 @llvm.dx.wave.get.lane.count() + ret void +} + +; CHECK: attributes #[[#ATTR]] = {{{.*}} memory(read) {{.*}}} + +declare i32 @llvm.dx.wave.get.lane.count() + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-com
[clang] [X86] Add -fexperimental-new-constant-interpreter test coverage to the x86 scalar rotate constexpr test files (PR #156337)
https://github.com/RKSimon closed https://github.com/llvm/llvm-project/pull/156337 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules] Implement P1857R3 Modules Dependency Discovery (PR #107168)
@@ -2485,11 +2536,12 @@ class Preprocessor { } /// If we're importing a standard C++20 Named Modules. - bool isInImportingCXXNamedModules() const { -// NamedModuleImportPath will be non-empty only if we're importing -// Standard C++ named modules. -return !NamedModuleImportPath.empty() && getLangOpts().CPlusPlusModules && - !IsAtImport; + bool isImportingCXXNamedModules() const { +return getLangOpts().CPlusPlusModules && ImportingCXXNamedModules; + } + + bool isDeclaringCXXNamedModules() const { +return getLangOpts().CPlusPlusModules && DeclaringCXXNamedModules; yronglin wrote: Fixed https://github.com/llvm/llvm-project/pull/107168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules] Implement P1857R3 Modules Dependency Discovery (PR #107168)
@@ -233,6 +233,9 @@ class Token { PtrData = const_cast(Ptr); } + template T getAnnotationValueAs() const { +return static_cast(getAnnotationValue()); + } yronglin wrote: It's unecessary, removed. https://github.com/llvm/llvm-project/pull/107168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libcxx] [lldb] [llvm] [mlir] [openmp] Fix typos and spelling errors across codebase (PR #156270)
carlosgalvezp wrote: > we shouldn't discourage people from improving the codebase These are orthogonal issues. People are always welcome to improve the codebase, but small PRs are essential for a healthy codebase. And it will actually be **less* work for the author, because the patches will be able to merge sooner than a mega-patch (quicker review, less conflicts, less CI checks). Also, issues like the one that was brought up in this patch are less likely to be found on a mega-patch. Last, such a mega-patch generates a lot of review noise for everyone involved since every interaction generates a notification/email for everyone, even if it's unrelated to their subproject. Doing this in N patches is trivial and I don't think it's requiring much of the author. https://github.com/llvm/llvm-project/pull/156270 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix unique_ptr aggregate initialization false positives (PR #155131)
NagyDonat wrote: > So is it best to close this PR? Yes, I think this PR should be closed (because although it is a good approach for fixing the bug, we have that other commit which is further along the same path). https://github.com/llvm/llvm-project/pull/155131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules-driver] Add initial support for driver-managed module builds (PR #156248)
https://github.com/naveen-seth updated https://github.com/llvm/llvm-project/pull/156248 >From 9760106dbd916861d396b90cc30262a13a01c9c2 Mon Sep 17 00:00:00 2001 From: Naveen Seth Hanig Date: Mon, 25 Aug 2025 02:36:42 +0200 Subject: [PATCH 1/4] [clang][modules-driver] Move logic to enable -fmodules-driver (NFC) This patch is part of a series to support driver-managed module builds for C++ named modules and Clang modules. Commit 9403c2d introduced the entry point for the driver-managed module build logic and assumed that it would live in the BuildActions phase of the driver. That proved unnecessary: the logic can be fully implemented in the BuildJobs phase. This reverts changes to BuildActions in preparation for the upcoming patches. --- clang/include/clang/Driver/Driver.h | 25 --- clang/lib/Driver/Driver.cpp | 107 2 files changed, 47 insertions(+), 85 deletions(-) diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index b9b187ada8add..ec574f5796117 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -512,9 +512,6 @@ class Driver { /// BuildActions - Construct the list of actions to perform for the /// given arguments, which are only done for a single architecture. - /// If the compilation is an explicit module build, delegates to - /// BuildDriverManagedModuleBuildActions. Otherwise, BuildDefaultActions is - /// used. /// /// \param C - The compilation that is being built. /// \param Args - The input arguments. @@ -799,27 +796,6 @@ class Driver { /// compilation based on which -f(no-)?lto(=.*)? option occurs last. void setLTOMode(const llvm::opt::ArgList &Args); - /// BuildDefaultActions - Constructs the list of actions to perform - /// for the provided arguments, which are only done for a single architecture. - /// - /// \param C - The compilation that is being built. - /// \param Args - The input arguments. - /// \param Actions - The list to store the resulting actions onto. - void BuildDefaultActions(Compilation &C, llvm::opt::DerivedArgList &Args, - const InputList &Inputs, ActionList &Actions) const; - - /// BuildDriverManagedModuleBuildActions - Performs a dependency - /// scan and constructs the list of actions to perform for dependency order - /// and the provided arguments. This is only done for a single a architecture. - /// - /// \param C - The compilation that is being built. - /// \param Args - The input arguments. - /// \param Actions - The list to store the resulting actions onto. - void BuildDriverManagedModuleBuildActions(Compilation &C, -llvm::opt::DerivedArgList &Args, -const InputList &Inputs, -ActionList &Actions) const; - /// Scans the leading lines of the C++ source inputs to detect C++20 module /// usage. /// @@ -827,7 +803,6 @@ class Driver { /// read failure. llvm::ErrorOr ScanInputsForCXX20ModulesUsage(const InputList &Inputs) const; - /// Retrieves a ToolChain for a particular \p Target triple. /// /// Will cache ToolChains for the life of the driver object, and create them diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index f110dbab3e5a5..d69012885ad4c 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1473,6 +1473,33 @@ bool Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) { return false; } +static bool hasCXXModuleInputType(const Driver::InputList &Inputs) { + const auto IsTypeCXXModule = [](const auto &Input) -> bool { +const auto TypeID = Input.first; +return (TypeID == types::TY_CXXModule); + }; + return llvm::any_of(Inputs, IsTypeCXXModule); +} + +llvm::ErrorOr +Driver::ScanInputsForCXX20ModulesUsage(const InputList &Inputs) const { + const auto CXXInputs = llvm::make_filter_range( + Inputs, [](const auto &Input) { return types::isCXX(Input.first); }); + for (const auto &Input : CXXInputs) { +StringRef Filename = Input.second->getSpelling(); +auto ErrOrBuffer = VFS->getBufferForFile(Filename); +if (!ErrOrBuffer) + return ErrOrBuffer.getError(); +const auto Buffer = std::move(*ErrOrBuffer); + +if (scanInputForCXX20ModulesUsage(Buffer->getBuffer())) { + Diags.Report(diag::remark_found_cxx20_module_usage) << Filename; + return true; +} + } + return false; +} + Compilation *Driver::BuildCompilation(ArrayRef ArgList) { llvm::PrettyStackTraceString CrashInfo("Compilation construction"); @@ -1836,6 +1863,26 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { else BuildActions(*C, C->getArgs(), Inputs, C->getActions()); + if (C->getArgs().hasFlag(options::OPT_fmodules_driver, + options::OPT_fno_modules_driver, false)) { +// TODO: When -
[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)
5chmidti wrote: I won't have access to my machine for 2 weeks, so I can't try it out in the coming days, sorry. I'll see if I can do at least some review on mobile, but my general thoughts are in discourse. For now: I think the documentation should be extended to explain that the AST is not a fixed construct, and it will change between versions (e.g., I think there was a nested namespace change recently). Also, we should encourage users to think about upstreaming checks when it makes sense https://github.com/llvm/llvm-project/pull/131804 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libcxx] [lldb] [llvm] [mlir] [openmp] Fix typos and spelling errors across codebase (PR #156270)
https://github.com/tblah approved this pull request. Flang and flang-rt changes LGTM. https://github.com/llvm/llvm-project/pull/156270 ___ 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 'llvm-use-ranges' (PR #152047)
https://github.com/vbvictor updated https://github.com/llvm/llvm-project/pull/152047 >From bb17fb65d031190efff6a6ec1c0ca6d9c0d35abb Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 5 Aug 2025 01:15:02 +0300 Subject: [PATCH 1/7] [clang-tidy] Add new check 'llvm-use-ranges' --- .../clang-tidy/llvm/CMakeLists.txt| 1 + .../clang-tidy/llvm/LLVMTidyModule.cpp| 2 + .../clang-tidy/llvm/UseRangesCheck.cpp| 90 .../clang-tidy/llvm/UseRangesCheck.h | 33 + clang-tools-extra/docs/ReleaseNotes.rst | 6 + .../docs/clang-tidy/checks/list.rst | 3 +- .../clang-tidy/checks/llvm/use-ranges.rst | 58 .../clang-tidy/checkers/llvm/use-ranges.cpp | 128 ++ 8 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/clang-tidy/llvm/UseRangesCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/llvm/UseRangesCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/llvm/use-ranges.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/llvm/use-ranges.cpp diff --git a/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt b/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt index 41386cdb55b1f..78ef0444305ff 100644 --- a/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt @@ -12,6 +12,7 @@ add_clang_library(clangTidyLLVMModule STATIC PreferStaticOverAnonymousNamespaceCheck.cpp TwineLocalCheck.cpp UseNewMLIROpBuilderCheck.cpp + UseRangesCheck.cpp LINK_LIBS clangTidy diff --git a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp index c7c61fd1649cc..c1f78caf44d16 100644 --- a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp @@ -19,6 +19,7 @@ #include "PreferStaticOverAnonymousNamespaceCheck.h" #include "TwineLocalCheck.h" #include "UseNewMLIROpBuilderCheck.h" +#include "UseRangesCheck.h" namespace clang::tidy { namespace llvm_check { @@ -43,6 +44,7 @@ class LLVMModule : public ClangTidyModule { CheckFactories.registerCheck("llvm-twine-local"); CheckFactories.registerCheck( "llvm-use-new-mlir-op-builder"); +CheckFactories.registerCheck("llvm-use-ranges"); } ClangTidyOptions getModuleOptions() override { diff --git a/clang-tools-extra/clang-tidy/llvm/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/llvm/UseRangesCheck.cpp new file mode 100644 index 0..0e11a017c60d5 --- /dev/null +++ b/clang-tools-extra/clang-tidy/llvm/UseRangesCheck.cpp @@ -0,0 +1,90 @@ +//===--- UseRangesCheck.cpp - clang-tidy --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseRangesCheck.h" + +namespace clang::tidy::llvm_check { + +namespace { + +class StdToLLVMReplacer : public utils::UseRangesCheck::Replacer { +public: + explicit StdToLLVMReplacer( + ArrayRef Signatures) + : Signatures(Signatures) {} + + ArrayRef + getReplacementSignatures() const override { +return Signatures; + } + + std::optional + getReplaceName(const NamedDecl &OriginalName) const override { +return ("llvm::" + OriginalName.getName()).str(); + } + + std::optional + getHeaderInclusion(const NamedDecl &) const override { +return "llvm/ADT/STLExtras.h"; + } + +private: + SmallVector Signatures; +}; + +} // namespace + +utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const { + ReplacerMap Results; + + static const Signature SingleSig = {{0}}; + static const Signature TwoSig = {{0}, {2}}; + + const auto AddStdToLLVM = + [&Results](llvm::IntrusiveRefCntPtr Replacer, + std::initializer_list Names) { +for (const auto &Name : Names) { + Results.try_emplace(("::std::" + Name).str(), Replacer); +} + }; + + // Single range algorithms + AddStdToLLVM(llvm::makeIntrusiveRefCnt(SingleSig), + {"all_of", "any_of","none_of", "for_each", +"find","find_if", "find_if_not", "count", +"count_if","transform", "replace", "remove_if", +"sort","partition", "is_sorted", "min_element", +"max_element", "binary_search", "lower_bound", "upper_bound", +"unique", "copy", "copy_if", "fill"}); + + // Two range algorithms + AddStdToLLVM(llvm::makeIntrusiveRefCnt(TwoSig), + {"equal", "mismatch"}); + + return Results; +} + +UseRangesCheck::UseRangesCheck(StringRef Name, ClangTidyContext *Context) +: utils::UseRangesCheck(Name,
[clang] [clang][analyzer] Remove checker 'alpha.core.CastSize' (PR #156350)
https://github.com/balazske created https://github.com/llvm/llvm-project/pull/156350 None From 19c4f21ce4b1c79c8dd2be0a017164e500ac1b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= Date: Fri, 29 Aug 2025 09:02:39 +0200 Subject: [PATCH] [clang][analyzer] Remove checker 'alpha.core.CastSize' --- clang/docs/analyzer/checkers.rst | 12 - .../clang/StaticAnalyzer/Checkers/Checkers.td | 5 - .../StaticAnalyzer/Checkers/CMakeLists.txt| 1 - .../Checkers/CastSizeChecker.cpp | 156 clang/test/Analysis/castsize.c| 26 -- clang/test/Analysis/malloc-annotations.c | 10 - clang/test/Analysis/malloc-annotations.cpp| 1 - clang/test/Analysis/malloc.c | 226 -- clang/test/Analysis/malloc.cpp| 4 - clang/test/Analysis/misc-ps.m | 12 - clang/test/Analysis/qt_malloc.cpp | 2 +- 11 files changed, 1 insertion(+), 454 deletions(-) delete mode 100644 clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp delete mode 100644 clang/test/Analysis/castsize.c diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst index b2effadacf9f1..9350def672a6d 100644 --- a/clang/docs/analyzer/checkers.rst +++ b/clang/docs/analyzer/checkers.rst @@ -2932,18 +2932,6 @@ the locking/unlocking of ``mtx_t`` mutexes. mtx_lock(&mtx1); // warn: This lock has already been acquired } -.. _alpha-core-CastSize: - -alpha.core.CastSize (C) -""" -Check when casting a malloc'ed type ``T``, whether the size is a multiple of the size of ``T``. - -.. code-block:: c - - void test() { - int *x = (int *) malloc(11); // warn - } - .. _alpha-core-CastToStruct: alpha.core.CastToStruct (C, C++) diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td index 73f702de581d9..8905c62c01e49 100644 --- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -257,11 +257,6 @@ def BoolAssignmentChecker : Checker<"BoolAssignment">, HelpText<"Warn about assigning non-{0,1} values to Boolean variables">, Documentation; -def CastSizeChecker : Checker<"CastSize">, - HelpText<"Check when casting a malloc'ed type T, whether the size is a " - "multiple of the size of T">, - Documentation; - def CastToStructChecker : Checker<"CastToStruct">, HelpText<"Check for cast from non-struct pointer to struct pointer">, Documentation; diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt index 78360418a8b81..5ec07686ed2fe 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt +++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt @@ -17,7 +17,6 @@ add_clang_library(clangStaticAnalyzerCheckers CStringChecker.cpp CStringSyntaxChecker.cpp CallAndMessageChecker.cpp - CastSizeChecker.cpp CastToStructChecker.cpp CastValueChecker.cpp CheckObjCDealloc.cpp diff --git a/clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp deleted file mode 100644 index 90c6537d71d9d..0 --- a/clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp +++ /dev/null @@ -1,156 +0,0 @@ -//=== CastSizeChecker.cpp ---*- 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 -// -//===--===// -// -// CastSizeChecker checks when casting a malloc'ed symbolic region to type T, -// whether the size of the symbolic region is a multiple of the size of T. -// -//===--===// - -#include "clang/AST/CharUnits.h" -#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" -#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" -#include "clang/StaticAnalyzer/Core/Checker.h" -#include "clang/StaticAnalyzer/Core/CheckerManager.h" -#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" -#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h" - -using namespace clang; -using namespace ento; - -namespace { -class CastSizeChecker : public Checker< check::PreStmt > { - const BugType BT{this, "Cast region with wrong size."}; - -public: - void checkPreStmt(const CastExpr *CE, CheckerContext &C) const; -}; -} - -/// Check if we are casting to a struct with a flexible array at the end. -/// \code -/// struct foo { -/// size_t len; -/// struct bar data[]; -/// }; -/// \endcode -/// or -/// \code -/// struct foo { -/// size_t len; -/// struct bar data[0]; -/// } -/// \endcode -/// In these cases it is also valid to allocat
[clang] [clang][analyzer] Remove checker 'alpha.core.CastSize' (PR #156350)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: Balázs Kéri (balazske) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/156350.diff 11 Files Affected: - (modified) clang/docs/analyzer/checkers.rst (-12) - (modified) clang/include/clang/StaticAnalyzer/Checkers/Checkers.td (-5) - (modified) clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt (-1) - (removed) clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp (-156) - (removed) clang/test/Analysis/castsize.c (-26) - (modified) clang/test/Analysis/malloc-annotations.c (-10) - (modified) clang/test/Analysis/malloc-annotations.cpp (-1) - (modified) clang/test/Analysis/malloc.c (-226) - (modified) clang/test/Analysis/malloc.cpp (-4) - (modified) clang/test/Analysis/misc-ps.m (-12) - (modified) clang/test/Analysis/qt_malloc.cpp (+1-1) ``diff diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst index b2effadacf9f1..9350def672a6d 100644 --- a/clang/docs/analyzer/checkers.rst +++ b/clang/docs/analyzer/checkers.rst @@ -2932,18 +2932,6 @@ the locking/unlocking of ``mtx_t`` mutexes. mtx_lock(&mtx1); // warn: This lock has already been acquired } -.. _alpha-core-CastSize: - -alpha.core.CastSize (C) -""" -Check when casting a malloc'ed type ``T``, whether the size is a multiple of the size of ``T``. - -.. code-block:: c - - void test() { - int *x = (int *) malloc(11); // warn - } - .. _alpha-core-CastToStruct: alpha.core.CastToStruct (C, C++) diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td index 73f702de581d9..8905c62c01e49 100644 --- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -257,11 +257,6 @@ def BoolAssignmentChecker : Checker<"BoolAssignment">, HelpText<"Warn about assigning non-{0,1} values to Boolean variables">, Documentation; -def CastSizeChecker : Checker<"CastSize">, - HelpText<"Check when casting a malloc'ed type T, whether the size is a " - "multiple of the size of T">, - Documentation; - def CastToStructChecker : Checker<"CastToStruct">, HelpText<"Check for cast from non-struct pointer to struct pointer">, Documentation; diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt index 78360418a8b81..5ec07686ed2fe 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt +++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt @@ -17,7 +17,6 @@ add_clang_library(clangStaticAnalyzerCheckers CStringChecker.cpp CStringSyntaxChecker.cpp CallAndMessageChecker.cpp - CastSizeChecker.cpp CastToStructChecker.cpp CastValueChecker.cpp CheckObjCDealloc.cpp diff --git a/clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp deleted file mode 100644 index 90c6537d71d9d..0 --- a/clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp +++ /dev/null @@ -1,156 +0,0 @@ -//=== CastSizeChecker.cpp ---*- 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 -// -//===--===// -// -// CastSizeChecker checks when casting a malloc'ed symbolic region to type T, -// whether the size of the symbolic region is a multiple of the size of T. -// -//===--===// - -#include "clang/AST/CharUnits.h" -#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" -#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" -#include "clang/StaticAnalyzer/Core/Checker.h" -#include "clang/StaticAnalyzer/Core/CheckerManager.h" -#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" -#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h" - -using namespace clang; -using namespace ento; - -namespace { -class CastSizeChecker : public Checker< check::PreStmt > { - const BugType BT{this, "Cast region with wrong size."}; - -public: - void checkPreStmt(const CastExpr *CE, CheckerContext &C) const; -}; -} - -/// Check if we are casting to a struct with a flexible array at the end. -/// \code -/// struct foo { -/// size_t len; -/// struct bar data[]; -/// }; -/// \endcode -/// or -/// \code -/// struct foo { -/// size_t len; -/// struct bar data[0]; -/// } -/// \endcode -/// In these cases it is also valid to allocate size of struct foo + a multiple -/// of struct bar. -static bool evenFlexibleArraySize(ASTContext &Ctx, CharUnits RegionSize, - CharUnits TypeSize, QualType ToPointeeTy) { - const RecordType *RT = ToPointeeT
[clang] e932e41 - [Headers][X86] Add constexpr support for some AVX[512] intrinsics. (#156187)
Author: moorabbit Date: 2025-09-01T16:04:17Z New Revision: e932e413cfd00d42b2832c7d5fc4b3db576a1401 URL: https://github.com/llvm/llvm-project/commit/e932e413cfd00d42b2832c7d5fc4b3db576a1401 DIFF: https://github.com/llvm/llvm-project/commit/e932e413cfd00d42b2832c7d5fc4b3db576a1401.diff LOG: [Headers][X86] Add constexpr support for some AVX[512] intrinsics. (#156187) The following AVX[512] intrinsics are now constexpr: - `_mm256_cvtepi32_pd` - `_mm256_cvtepi32_ps` - `_mm256_cvtps_pd` - `_mm512_cvtepi32_ps` - `_mm512_mask_cvtepi32_ps` - `_mm512_maskz_cvtepi32_ps` - `_mm512_cvtepu32_ps` - `_mm512_mask_cvtepu32_ps` - `_mm512_maskz_cvtepu32_ps` - `_mm512_cvtepi32_pd` - `_mm512_mask_cvtepi32_pd` - `_mm512_maskz_cvtepi32_pd` - `_mm512_cvtepi32lo_pd` - `_mm512_mask_cvtepi32lo_pd` - `_mm512_cvtepu32_pd` - `_mm512_mask_cvtepu32_pd` - `_mm512_maskz_cvtepu32_pd` - `_mm512_cvtepu32lo_pd` - `_mm512_mask_cvtepu32lo_pd` - `_mm512_cvtps_pd` - `_mm512_mask_cvtps_pd` - `_mm512_maskz_cvtps_pd` - `_mm512_cvtpslo_pd` - `_mm512_mask_cvtpslo_pd` - `_mm512_castsi512_si256` - `_mm512_castps512_ps256` This PR is part 1 of a series of PRs fixing #155798 Added: Modified: clang/lib/Headers/avx512fintrin.h clang/lib/Headers/avxintrin.h clang/test/CodeGen/X86/avx-builtins.c clang/test/CodeGen/X86/avx512f-builtins.c Removed: diff --git a/clang/lib/Headers/avx512fintrin.h b/clang/lib/Headers/avx512fintrin.h index a525652e1e15a..0006e334022b6 100644 --- a/clang/lib/Headers/avx512fintrin.h +++ b/clang/lib/Headers/avx512fintrin.h @@ -426,9 +426,8 @@ _mm512_castps512_ps128(__m512 __a) return __builtin_shufflevector(__a, __a, 0, 1, 2, 3); } -static __inline __m256 __DEFAULT_FN_ATTRS512 -_mm512_castps512_ps256 (__m512 __A) -{ +static __inline __m256 __DEFAULT_FN_ATTRS512_CONSTEXPR +_mm512_castps512_ps256(__m512 __A) { return __builtin_shufflevector(__A, __A, 0, 1, 2, 3, 4, 5, 6, 7); } @@ -507,9 +506,8 @@ _mm512_castsi512_si128 (__m512i __A) return (__m128i)__builtin_shufflevector(__A, __A , 0, 1); } -static __inline __m256i __DEFAULT_FN_ATTRS512 -_mm512_castsi512_si256 (__m512i __A) -{ +static __inline __m256i __DEFAULT_FN_ATTRS512_CONSTEXPR +_mm512_castsi512_si256(__m512i __A) { return (__m256i)__builtin_shufflevector(__A, __A , 0, 1, 2, 3); } @@ -3586,115 +3584,99 @@ _mm512_maskz_cvttps_epu32 (__mmask16 __U, __m512 __A) (__v16sf)_mm512_setzero_ps(), \ (__mmask16)(U), (int)(R))) -static __inline__ __m512 __DEFAULT_FN_ATTRS512 -_mm512_cvtepu32_ps (__m512i __A) -{ +static __inline__ __m512 +__DEFAULT_FN_ATTRS512_CONSTEXPR _mm512_cvtepu32_ps(__m512i __A) { return (__m512)__builtin_convertvector((__v16su)__A, __v16sf); } -static __inline__ __m512 __DEFAULT_FN_ATTRS512 -_mm512_mask_cvtepu32_ps (__m512 __W, __mmask16 __U, __m512i __A) -{ +static __inline__ __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR +_mm512_mask_cvtepu32_ps(__m512 __W, __mmask16 __U, __m512i __A) { return (__m512)__builtin_ia32_selectps_512((__mmask16)__U, (__v16sf)_mm512_cvtepu32_ps(__A), (__v16sf)__W); } -static __inline__ __m512 __DEFAULT_FN_ATTRS512 -_mm512_maskz_cvtepu32_ps (__mmask16 __U, __m512i __A) -{ +static __inline__ __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR +_mm512_maskz_cvtepu32_ps(__mmask16 __U, __m512i __A) { return (__m512)__builtin_ia32_selectps_512((__mmask16)__U, (__v16sf)_mm512_cvtepu32_ps(__A), (__v16sf)_mm512_setzero_ps()); } -static __inline __m512d __DEFAULT_FN_ATTRS512 -_mm512_cvtepi32_pd(__m256i __A) -{ +static __inline __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR +_mm512_cvtepi32_pd(__m256i __A) { return (__m512d)__builtin_convertvector((__v8si)__A, __v8df); } -static __inline__ __m512d __DEFAULT_FN_ATTRS512 -_mm512_mask_cvtepi32_pd (__m512d __W, __mmask8 __U, __m256i __A) -{ +static __inline__ __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR +_mm512_mask_cvtepi32_pd(__m512d __W, __mmask8 __U, __m256i __A) { return (__m512d)__builtin_ia32_selectpd_512((__mmask8) __U, (__v8df)_mm512_cvtepi32_pd(__A), (__v8df)__W); } -static __inline__ __m512d __DEFAULT_FN_ATTRS512 -_mm512_maskz_cvtepi32_pd (__mmask8 __U, __m256i __A) -{ +static __inline__ __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR +_mm512_maskz_cvtepi32_pd(__mmask8 __U, __m256i __A) { return (__m512d)__builtin_ia32_selectpd_512((__mmask8) __U, (__v8df)_mm512_cvtepi32_pd(__A), (__v8df)_mm512_setzero_pd()); } -static __inline__ __m512d __DEFAULT_FN_ATTRS512 -_mm512_cvtepi32lo_pd(__m512i __A) -{
[clang] [Headers][X86] Add constexpr support for some AVX[512] intrinsics. (PR #156187)
https://github.com/RKSimon closed https://github.com/llvm/llvm-project/pull/156187 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86] Add -fexperimental-new-constant-interpreter test coverage to the x86 scalar rotate constexpr test files (PR #156337)
https://github.com/RKSimon auto_merge_enabled https://github.com/llvm/llvm-project/pull/156337 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Clean up bug types in CallAndMessageChecker (PR #156073)
@@ -728,23 +678,15 @@ void CallAndMessageChecker::HandleNilReceiver(CheckerContext &C, C.addTransition(state); } -void ento::registerCallAndMessageModeling(CheckerManager &mgr) { - mgr.registerChecker(); -} - -bool ento::shouldRegisterCallAndMessageModeling(const CheckerManager &mgr) { - return true; -} - -void ento::registerCallAndMessageChecker(CheckerManager &mgr) { - CallAndMessageChecker *checker = mgr.getChecker(); +void ento::registerCallAndMessageChecker(CheckerManager &Mgr) { + CallAndMessageChecker *Chk = Mgr.registerChecker(); - checker->OriginalName = mgr.getCurrentCheckerName(); + Chk->OriginalName = Mgr.getCurrentCheckerName(); NagyDonat wrote: Done in https://github.com/llvm/llvm-project/pull/156073/commits/eef2e2976980f025a9220a3754b0657a42f29aa4 https://github.com/llvm/llvm-project/pull/156073 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang][AST] Fix source range of class template implicit instantiations. (PR #156011)
mizvekov wrote: > OK, I understand. Could you point me to where that pattern selection happens? > I will not be able to work on that PR for two weeks but I can go back on it > afterward. In `Sema::InstantiateClass`, which is implemented in SemaTemplateInstantiate.cpp. https://github.com/llvm/llvm-project/pull/156011 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove written template args from implicit var tpl spec (PR #156329)
https://github.com/bolshakov-a created https://github.com/llvm/llvm-project/pull/156329 `VarTemplateSpecializationDecl::getTemplateArgsAsWritten()` function should return `nullptr` in the case of implicit instantiation, as its `ClassTemplateSpecializationDecl` counterpart does, and not the arguments written in `DeclRefExpr` referencing the specialization in the first place. Otherwise, for such code: ```cpp template int VarTpl; template void tplFn() { (void)VarTpl; // (1) } void fn() { tplFn(); } ``` Clang treats the `char` argument of the `VarTpl` specialization as if it were written in the line marked as (1), which is misleading and hardly makes sense. Moreover, "template args as written" are stored inside `ExplicitInfo` field of `VarTemplateSpecializationDecl`, but it is [documented](https://github.com/llvm/llvm-project/blob/13357e8a12c1a45364a0c4d3137b6d21ee6ac40c/clang/include/clang/AST/DeclTemplate.h#L2653) that it is not for implicit instantiations. Moreover, it is assumed in `TraverseVarTemplateSpecializationDecl` method of `RecursiveASTVisitor` that `getTemplateArgsAsWritten()` returns `nullptr` for implicit instantiations, as it is stated in the comment [there](https://github.com/llvm/llvm-project/blob/13357e8a12c1a45364a0c4d3137b6d21ee6ac40c/clang/include/clang/AST/RecursiveASTVisitor.h#L2196). That said, `setTemplateArgsAsWritten` should be called only for variable template explicit specializations (it is [already done inside `Sema::ActOnVarTemplateSpecialization`](https://github.com/llvm/llvm-project/blob/4c916273041ff5ed7b2af20bec787ffc42871c9f/clang/lib/Sema/SemaTemplate.cpp#L4459)) and explicit instantiations (hence `true` is passed to the new `SetWrittenArgs` parameter of `CheckVarTemplateId` function inside `Sema::ActOnExplicitInstantiation`, but not when handling expressions referencing a variable template specialization). `InstantiateVariableDefinition` function just passes the arguments from the corresponding declaration. I'm not sure about instantiating a class template containing a variable template explicit specialization and thus have tried to leave the logic of the first overload of `TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl` as it was. >From 801d872538893065507c30859b69331772549ed5 Mon Sep 17 00:00:00 2001 From: Bolshakov Date: Mon, 1 Sep 2025 12:38:24 +0300 Subject: [PATCH] [clang] Remove written template args from implicit var tpl spec VarTemplateSpecializationDecl::getTemplateArgsAsWritten() function should return nullptr in the case of implicit instantiation, as its ClassTemplateSpecializationDecl counterpart does, and not the arguments written in DeclRefExpr referencing the specialization in the first place. Otherwise, for such code: template int VarTpl; template void tplFn() { (void)VarTpl; // (1) } void fn() { tplFn(); } Clang treats the 'char' argument of the VarTpl specialization as if it were written in the line marked as (1), which is misleading and hardly makes sense. Moreover, "template args as written" are stored inside ExplicitInfo field of VarTemplateSpecializationDecl, but it is documented that it is not for implicit instantiations. Moreover, it is assumed in TraverseVarTemplateSpecializationDecl method of RecursiveASTVisitor that getTemplateArgsAsWritten() returns nullptr for implicit instantiations, as it is stated in the comment there. That said, setTemplateArgsAsWritten should be called only for variable template explicit specializations (it is already done inside Sema::ActOnVarTemplateSpecialization) and explicit instantiations (hence 'true' is passed to the new SetWrittenArgs parameter of CheckVarTemplateId function inside Sema::ActOnExplicitInstantiation, but not when handling expressions referencing a variable template specialization). InstantiateVariableDefinition function just passes the arguments from the corresponding declaration. I'm not sure about instantiating a class template containing a variable template explicit specialization and thus have tried to leave the logic of the first overload of TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl as it was. --- clang/include/clang/Sema/Sema.h | 4 +-- clang/include/clang/Sema/Template.h | 3 +- clang/lib/Sema/SemaExprMember.cpp | 5 +-- clang/lib/Sema/SemaTemplate.cpp | 16 ++ .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 31 +++ clang/unittests/AST/DeclTest.cpp | 19 6 files changed, 53 insertions(+), 25 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index c3fb57774c8dc..224095070cbe3 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -11662,7 +11662,8 @@ class Sema final : public SemaBase { DeclResult CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc,
[clang] [C++20][Modules] Implement P1857R3 Modules Dependency Discovery (PR #107168)
@@ -1776,6 +1801,22 @@ class Preprocessor { /// Lex the parameters for an #embed directive, returns nullopt on error. std::optional LexEmbedParameters(Token &Current, bool ForHasEmbed); + bool LexModuleNameContinue(Token &Tok, SourceLocation UseLoc, + SmallVectorImpl &Suffix, + SmallVectorImpl &Path, + bool AllowMacroExpansion = true); + void EnterModuleSuffixTokenStream(ArrayRef Toks); + void HandleCXXImportDirective(Token Import); + void HandleCXXModuleDirective(Token Module); + + /// Callback invoked when the lexer sees one of export, import or module token + /// at the start of a line. + /// + /// This consumes the import, module directive, modifies the yronglin wrote: Done https://github.com/llvm/llvm-project/pull/107168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules] Implement P1857R3 Modules Dependency Discovery (PR #107168)
@@ -1178,186 +1289,39 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) { // Figure out what kind of lexer we actually have. recomputeCurLexerKind(); - // Lex the next token. The header-name lexing rules are used at the start of - // a pp-import. - // - // For now, we only support header-name imports in C++20 mode. - // FIXME: Should we allow this in all language modes that support an import - // declaration as an extension? - if (NamedModuleImportPath.empty() && getLangOpts().CPlusPlusModules) { -if (LexHeaderName(Result)) - return true; - -if (Result.is(tok::colon) && ModuleDeclState.isNamedModule()) { - std::string Name = ModuleDeclState.getPrimaryName().str(); - Name += ":"; - NamedModuleImportPath.emplace_back(Result.getLocation(), - getIdentifierInfo(Name)); - CurLexerCallback = CLK_LexAfterModuleImport; - return true; -} - } else { -Lex(Result); - } - - // Allocate a holding buffer for a sequence of tokens and introduce it into - // the token stream. - auto EnterTokens = [this](ArrayRef Toks) { -auto ToksCopy = std::make_unique(Toks.size()); -std::copy(Toks.begin(), Toks.end(), ToksCopy.get()); -EnterTokenStream(std::move(ToksCopy), Toks.size(), - /*DisableMacroExpansion*/ true, /*IsReinject*/ false); - }; - - bool ImportingHeader = Result.is(tok::header_name); - // Check for a header-name. SmallVector Suffix; - if (ImportingHeader) { -// Enter the header-name token into the token stream; a Lex action cannot -// both return a token and cache tokens (doing so would corrupt the token -// cache if the call to Lex comes from CachingLex / PeekAhead). -Suffix.push_back(Result); - -// Consume the pp-import-suffix and expand any macros in it now. We'll add -// it back into the token stream later. -CollectPpImportSuffix(Suffix); -if (Suffix.back().isNot(tok::semi)) { - // This is not a pp-import after all. - EnterTokens(Suffix); - return false; -} - -// C++2a [cpp.module]p1: -// The ';' preprocessing-token terminating a pp-import shall not have -// been produced by macro replacement. -SourceLocation SemiLoc = Suffix.back().getLocation(); -if (SemiLoc.isMacroID()) - Diag(SemiLoc, diag::err_header_import_semi_in_macro); - -// Reconstitute the import token. -Token ImportTok; -ImportTok.startToken(); -ImportTok.setKind(tok::kw_import); -ImportTok.setLocation(ModuleImportLoc); -ImportTok.setIdentifierInfo(getIdentifierInfo("import")); -ImportTok.setLength(6); - -auto Action = HandleHeaderIncludeOrImport( -/*HashLoc*/ SourceLocation(), ImportTok, Suffix.front(), SemiLoc); -switch (Action.Kind) { -case ImportAction::None: - break; - -case ImportAction::ModuleBegin: - // Let the parser know we're textually entering the module. - Suffix.emplace_back(); - Suffix.back().startToken(); - Suffix.back().setKind(tok::annot_module_begin); - Suffix.back().setLocation(SemiLoc); - Suffix.back().setAnnotationEndLoc(SemiLoc); - Suffix.back().setAnnotationValue(Action.ModuleForHeader); - [[fallthrough]]; - -case ImportAction::ModuleImport: -case ImportAction::HeaderUnitImport: -case ImportAction::SkippedModuleImport: - // We chose to import (or textually enter) the file. Convert the - // header-name token into a header unit annotation token. - Suffix[0].setKind(tok::annot_header_unit); - Suffix[0].setAnnotationEndLoc(Suffix[0].getLocation()); - Suffix[0].setAnnotationValue(Action.ModuleForHeader); - // FIXME: Call the moduleImport callback? - break; -case ImportAction::Failure: - assert(TheModuleLoader.HadFatalFailure && - "This should be an early exit only to a fatal error"); - Result.setKind(tok::eof); - CurLexer->cutOffLexing(); - EnterTokens(Suffix); - return true; -} - -EnterTokens(Suffix); -return false; - } - - // The token sequence - // - // import identifier (. identifier)* - // - // indicates a module import directive. We already saw the 'import' - // contextual keyword, so now we're looking for the identifiers. - if (ModuleImportExpectsIdentifier && Result.getKind() == tok::identifier) { -// We expected to see an identifier here, and we did; continue handling -// identifiers. -NamedModuleImportPath.emplace_back(Result.getLocation(), - Result.getIdentifierInfo()); -ModuleImportExpectsIdentifier = false; -CurLexerCallback = CLK_LexAfterModuleImport; -return true; - } - - // If we're expecting a '.' or a ';', and we got a '.', then wait until we - // see the next identifier. (We can also see a '[[' that begins an - // attribute-specifier-seq here under the Standard C++ Modules.) - if (!ModuleImportExpectsId
[clang] [C++20][Modules] Implement P1857R3 Modules Dependency Discovery (PR #107168)
@@ -1119,43 +1115,158 @@ bool Preprocessor::LexHeaderName(Token &FilenameTok, bool AllowMacroExpansion) { return false; } +// We represent the primary and partition names as 'Paths' which are sections +// of the hierarchical access path for a clang module. However for C++20 +// the periods in a name are just another character, and we will need to +// flatten them into a string. +std::string ModuleLoader::getFlatNameFromPath(ModuleIdPath Path) { + std::string Name; + if (Path.empty()) +return Name; + + for (auto &Piece : Path) { +assert(Piece.getIdentifierInfo() && Piece.getLoc().isValid()); +if (!Name.empty()) + Name += "."; +Name += Piece.getIdentifierInfo()->getName(); + } + return Name; +} + +bool Preprocessor::LexModuleNameContinue(Token &Tok, SourceLocation UseLoc, + SmallVectorImpl &Suffix, + SmallVectorImpl &Path, + bool AllowMacroExpansion) { + auto ConsumeToken = [&]() { +if (AllowMacroExpansion) + Lex(Tok); +else + LexUnexpandedToken(Tok); +Suffix.push_back(Tok); + }; + + Suffix.push_back(Tok); + while (true) { +if (Tok.isNot(tok::identifier)) + return true; + +// Record this part of the module path. +Path.emplace_back(Tok.getLocation(), Tok.getIdentifierInfo()); +ConsumeToken(); + +if (Tok.isNot(tok::period)) + return false; + +ConsumeToken(); + } +} + +/// P1857R3: Modules Dependency Discovery +/// +/// At the start of phase 4 an import or module token is treated as starting a +/// directive and are converted to their respective keywords iff: +/// - After skipping horizontal whitespace are +/// - at the start of a logical line, or +/// - preceded by an 'export' at the start of the logical line. +/// - Are followed by an identifier pp token (before macro expansion), or +/// - <, ", or : (but not ::) pp tokens for 'import', or +/// - ; for 'module' +/// Otherwise the token is treated as an identifier. +bool Preprocessor::HandleModuleContextualKeyword( +Token &Result, bool TokAtPhysicalStartOfLine) { + if (!getLangOpts().CPlusPlusModules || !Result.isModuleContextualKeyword()) +return false; + + if (Result.is(tok::kw_export)) { +LastTokenWasExportKeyword = {Result, TokAtPhysicalStartOfLine}; +return false; + } + + if (LastTokenWasExportKeyword.isValid()) { +// The export keyword was not at the start of line, it's not a +// directive-introducing token. +if (!LastTokenWasExportKeyword.isAtPhysicalStartOfLine()) + return false; +// [cpp.pre]/1.4 +// export // not a preprocessing directive +// import foo; // preprocessing directive (ill-formed at phase +// 7) yronglin wrote: Fixed. https://github.com/llvm/llvm-project/pull/107168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules] Implement P1857R3 Modules Dependency Discovery (PR #107168)
@@ -2485,11 +2536,12 @@ class Preprocessor { } /// If we're importing a standard C++20 Named Modules. - bool isInImportingCXXNamedModules() const { -// NamedModuleImportPath will be non-empty only if we're importing -// Standard C++ named modules. -return !NamedModuleImportPath.empty() && getLangOpts().CPlusPlusModules && - !IsAtImport; + bool isImportingCXXNamedModules() const { +return getLangOpts().CPlusPlusModules && ImportingCXXNamedModules; yronglin wrote: SGTM, fixed. https://github.com/llvm/llvm-project/pull/107168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules] Implement P1857R3 Modules Dependency Discovery (PR #107168)
@@ -14,7 +14,9 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTMutationListener.h" #include "clang/AST/DynamicRecursiveASTVisitor.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Lex/HeaderSearch.h" +#include "clang/Lex/ModuleLoader.h" yronglin wrote: Removed this. https://github.com/llvm/llvm-project/pull/107168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86] Add -fexperimental-new-constant-interpreter test coverage to the u32/f32 u64/f64 cast constexpr test files (PR #156327)
https://github.com/RKSimon closed https://github.com/llvm/llvm-project/pull/156327 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tidy] modernize-use-std-format: Correct replacement types when signed stdint types are used, and when enums are printed in hex. #150343 (PR #155200)
@@ -150,6 +150,9 @@ Changes to the Debug Info Changes to the LLVM tools - +* modernize-use-std-format now correctly replaces signed types, and correctly EugeneZelenko wrote: Such entry should be in `clang-tools-extra/docs/ReleaseNotes.rst`. See other entries there as examples. https://github.com/llvm/llvm-project/pull/155200 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 4d9578b - [clang-reorder-fields] Support designated initializers (#142150)
Author: Vladimir Vuksanovic Date: 2025-09-01T00:26:42-07:00 New Revision: 4d9578b8ed20f293641a5917447885ab97aeefbe URL: https://github.com/llvm/llvm-project/commit/4d9578b8ed20f293641a5917447885ab97aeefbe DIFF: https://github.com/llvm/llvm-project/commit/4d9578b8ed20f293641a5917447885ab97aeefbe.diff LOG: [clang-reorder-fields] Support designated initializers (#142150) Initializer lists with designators, missing elements or omitted braces can now be rewritten. Any missing designators are added and they get sorted according to the new order. ``` struct Foo { int a; int b; int c; }; struct Foo foo = { .a = 1, 2, 3 } ``` when reordering elements to "b,a,c" becomes: ``` struct Foo { int b; int a; int c; }; struct Foo foo = { .b = 2, .a = 1, .c = 3 } ``` Added: clang-tools-extra/clang-reorder-fields/Designator.cpp clang-tools-extra/clang-reorder-fields/Designator.h clang-tools-extra/test/clang-reorder-fields/AggregatePartialInitialization.c clang-tools-extra/test/clang-reorder-fields/DesignatedInitializerList.c clang-tools-extra/test/clang-reorder-fields/DesignatedInitializerList.cpp clang-tools-extra/test/clang-reorder-fields/IdiomaticZeroInitializer.c clang-tools-extra/test/clang-reorder-fields/InitializerListExcessElements.c Modified: clang-tools-extra/clang-reorder-fields/CMakeLists.txt clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp clang-tools-extra/test/clang-reorder-fields/AggregatePartialInitialization.cpp Removed: diff --git a/clang-tools-extra/clang-reorder-fields/CMakeLists.txt b/clang-tools-extra/clang-reorder-fields/CMakeLists.txt index 2fdeb65d89767..dec0287b26873 100644 --- a/clang-tools-extra/clang-reorder-fields/CMakeLists.txt +++ b/clang-tools-extra/clang-reorder-fields/CMakeLists.txt @@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS ) add_clang_library(clangReorderFields STATIC + Designator.cpp ReorderFieldsAction.cpp DEPENDS diff --git a/clang-tools-extra/clang-reorder-fields/Designator.cpp b/clang-tools-extra/clang-reorder-fields/Designator.cpp new file mode 100644 index 0..fc070f7f6746d --- /dev/null +++ b/clang-tools-extra/clang-reorder-fields/Designator.cpp @@ -0,0 +1,219 @@ +//===-- tools/extra/clang-reorder-fields/utils/Designator.cpp ---*- 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 +// +//===--===// +/// +/// \file +/// This file contains the definition of the Designator and Designators utility +/// classes. +/// +//===--===// + +#include "Designator.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Expr.h" +#include "llvm/Support/raw_ostream.h" + +namespace clang { +namespace reorder_fields { + +void Designator::advanceToNextField() { + assert(!isFinished() && "Iterator is already finished"); + switch (Tag) { + case STRUCT: +if (StructIt.Record->isUnion()) { + // Union always finishes on first increment. + StructIt.Field = StructIt.Record->field_end(); + Type = QualType(); + break; +} +++StructIt.Field; +if (StructIt.Field != StructIt.Record->field_end()) { + Type = StructIt.Field->getType(); +} else { + Type = QualType(); +} +break; + case ARRAY: +++ArrayIt.Index; +break; + case ARRAY_RANGE: +ArrayIt.Index = ArrayRangeIt.End + 1; +ArrayIt.Size = ArrayRangeIt.Size; +Tag = ARRAY; +break; + } +} + +bool Designator::isFinished() { + switch (Tag) { + case STRUCT: +return StructIt.Field == StructIt.Record->field_end(); + case ARRAY: +return ArrayIt.Index == ArrayIt.Size; + case ARRAY_RANGE: +return ArrayRangeIt.End == ArrayRangeIt.Size; + } + return false; +} + +Designators::Designators(const Expr *Init, const InitListExpr *ILE, + const ASTContext *Context) +: ILE(ILE), Context(Context) { + if (ILE->getType()->isArrayType()) { +const ConstantArrayType *CAT = +Context->getAsConstantArrayType(ILE->getType()); +// Only constant size arrays are supported. +if (!CAT) { + DesignatorList.clear(); + return; +} +DesignatorList.push_back( +{CAT->getElementType(), 0, CAT->getSize().getZExtValue()}); + } else { +const RecordDecl *DesignatorRD = ILE->getType()->getAsRecordDecl(); +DesignatorList.push_back({DesignatorRD->field_begin()->getType(), + DesignatorRD->field_begin(), DesignatorRD}); + } + + // If the designator list is empty at this point, then there must be excess + // elements in the initializer list. They are not currently supported. + if (DesignatorList.empty())
[clang-tools-extra] [clang-reorder-fields] Support designated initializers (PR #142150)
https://github.com/alexander-shaposhnikov closed https://github.com/llvm/llvm-project/pull/142150 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix crash 'Cannot get layout of forward declarations' during CTU static analysis (PR #156056)
@@ -0,0 +1,43 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -emit-pch -o %t/import.c.ast %t/import.c + +// RUN: %clang_extdef_map -- -x c %t/import.c >> %t/externalDefMap.txt +// RUN: sed -i'' 's/$/.ast/' %t/externalDefMap.txt balazske wrote: Is it better to use the `perl` command from that page? https://github.com/llvm/llvm-project/pull/156056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WIP][AMDGPU] Support for type inferring image load/store builtins for AMDGPU (PR #140210)
ranapratap55 wrote: @shiltian @arsenm ping. https://github.com/llvm/llvm-project/pull/140210 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [Clangd] Add AST search capabilities from clang-query (PR #156090)
https://github.com/Febbe edited https://github.com/llvm/llvm-project/pull/156090 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [Clangd] Add AST search capabilities from clang-query (PR #156090)
https://github.com/Febbe edited https://github.com/llvm/llvm-project/pull/156090 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Introduce -fexperimental-loop-fuse to clang and flang (PR #142686)
https://github.com/madhur13490 updated https://github.com/llvm/llvm-project/pull/142686 >From be9eb6a39906fac945ea206eec80f4cc18bd4896 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Thu, 22 May 2025 13:50:38 + Subject: [PATCH 01/10] add -floop-fuse to clang and flang --- clang/include/clang/Basic/CodeGenOptions.def| 1 + clang/include/clang/Driver/Options.td | 4 clang/lib/CodeGen/BackendUtil.cpp | 2 ++ clang/lib/Driver/ToolChains/Clang.cpp | 1 + clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 ++ clang/lib/Frontend/CompilerInvocation.cpp | 6 ++ clang/test/Driver/clang_f_opts.c| 7 +++ flang/docs/ReleaseNotes.md | 4 flang/include/flang/Frontend/CodeGenOptions.def | 1 + flang/lib/Frontend/CompilerInvocation.cpp | 3 +++ flang/lib/Frontend/FrontendActions.cpp | 1 + flang/test/Driver/loop-fuse.f90 | 17 + llvm/include/llvm/Passes/PassBuilder.h | 3 +++ llvm/lib/Passes/PassBuilderPipelines.cpp| 13 - 15 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 flang/test/Driver/loop-fuse.f90 diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 423b696785500..84af1ba6662b4 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -322,6 +322,7 @@ CODEGENOPT(TimeTrace , 1, 0, Benign) ///< Set when -ftime-trace is enabl VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500, Benign) ///< Minimum time granularity (in microseconds), ///< traced by time profiler CODEGENOPT(InterchangeLoops , 1, 0, Benign) ///< Run loop-interchange. +CODEGENOPT(FuseLoops , 1, 0, Benign) ///< Run loop-fuse. CODEGENOPT(UnrollLoops , 1, 0, Benign) ///< Control whether loops are unrolled. CODEGENOPT(RerollLoops , 1, 0, Benign) ///< Control whether loops are rerolled. CODEGENOPT(NoUseJumpTables , 1, 0, Benign) ///< Set when -fno-jump-tables is enabled. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 6aab43c9ed57f..184f9d9188fd6 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4268,6 +4268,10 @@ def floop_interchange : Flag<["-"], "floop-interchange">, Group, HelpText<"Enable the loop interchange pass">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>; def fno_loop_interchange: Flag<["-"], "fno-loop-interchange">, Group, HelpText<"Disable the loop interchange pass">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>; +def floop_fuse : Flag<["-"], "floop-fuse">, Group, + HelpText<"Enable the loop fuse pass">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>; +def fno_loop_fuse: Flag<["-"], "fno-loop-fuse">, Group, + HelpText<"Disable the loop fuse pass">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>; def funroll_loops : Flag<["-"], "funroll-loops">, Group, HelpText<"Turn on loop unroller">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>; def fno_unroll_loops : Flag<["-"], "fno-unroll-loops">, Group, diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 0b8b824fbcd5a..7b1b1480da213 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -897,6 +897,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline( PipelineTuningOptions PTO; PTO.LoopUnrolling = CodeGenOpts.UnrollLoops; PTO.LoopInterchange = CodeGenOpts.InterchangeLoops; + PTO.LoopFuse = CodeGenOpts.FuseLoops; // For historical reasons, loop interleaving is set to mirror setting for loop // unrolling. PTO.LoopInterleaving = CodeGenOpts.UnrollLoops; @@ -1332,6 +1333,7 @@ runThinLTOBackend(CompilerInstance &CI, ModuleSummaryIndex *CombinedIndex, Conf.SampleProfile = std::move(SampleProfile); Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops; Conf.PTO.LoopInterchange = CGOpts.InterchangeLoops; + Conf.PTO.LoopFuse = CGOpts.FuseLoops; // For historical reasons, loop interleaving is set to mirror setting for loop // unrolling. Conf.PTO.LoopInterleaving = CGOpts.UnrollLoops; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 6eb77610079b7..6731f8c948b96 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6870,6 +6870,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_unroll_loops); Args.AddLastArg(CmdArgs, options::OPT_floop_interchange, options::OPT_fno_loop_interchange); + Args.AddLastArg(CmdArgs, options::OPT_floop_fuse, options::OPT_fno_loop_fuse); Args.AddLas
[clang] [Driver][LoongArch] Enable linker relaxation by default for loongarch64 (PR #156315)
https://github.com/zhaoqi5 created https://github.com/llvm/llvm-project/pull/156315 None >From 3e7ee8d89f636af50c595476dd953a5f624160eb Mon Sep 17 00:00:00 2001 From: Qi Zhao Date: Mon, 1 Sep 2025 19:11:09 +0800 Subject: [PATCH] [Driver][LoongArch] Enable linker relaxation by default for loongarch64 --- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 29 +-- clang/test/Driver/loongarch-features.c| 2 +- clang/test/Driver/loongarch-march.c | 20 ++--- clang/test/Driver/loongarch-relax-features.c | 2 +- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp index ee7b0d10c24ba..156ea03045569 100644 --- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp @@ -134,22 +134,19 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, (!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ))) Features.push_back("+lsx"); - // FIXME: Now we must use -mrelax to enable relax, maybe -mrelax will be set - // as default in the future. - if (const Arg *A = - Args.getLastArg(options::OPT_mrelax, options::OPT_mno_relax)) { -if (A->getOption().matches(options::OPT_mrelax)) { - Features.push_back("+relax"); - // -gsplit-dwarf -mrelax requires DW_AT_high_pc/DW_AT_ranges/... indexing - // into .debug_addr, which is currently not implemented. - Arg *A; - if (getDebugFissionKind(D, Args, A) != DwarfFissionKind::None) -D.Diag( -clang::diag::err_drv_loongarch_unsupported_with_linker_relaxation) -<< A->getAsString(Args); -} else { - Features.push_back("-relax"); -} + // -mrelax is default, unless -mno-relax is specified. + // FIXME: Only for loongarch64, loongarch32 has not been fully verified. + if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, + Triple.isLoongArch64() ? true : false)) { +Features.push_back("+relax"); +// -gsplit-dwarf -mrelax requires DW_AT_high_pc/DW_AT_ranges/... indexing +// into .debug_addr, which is currently not implemented. +Arg *A; +if (getDebugFissionKind(D, Args, A) != DwarfFissionKind::None) + D.Diag(clang::diag::err_drv_loongarch_unsupported_with_linker_relaxation) + << A->getAsString(Args); + } else if (Args.getLastArg(options::OPT_mno_relax)) { +Features.push_back("-relax"); } std::string ArchName; diff --git a/clang/test/Driver/loongarch-features.c b/clang/test/Driver/loongarch-features.c index 90634bbcf0035..6f40ed71c2c0e 100644 --- a/clang/test/Driver/loongarch-features.c +++ b/clang/test/Driver/loongarch-features.c @@ -2,7 +2,7 @@ // RUN: %clang --target=loongarch64 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA64 // LA32: "target-features"="+32bit" -// LA64: "target-features"="+64bit,+d,+f,+lsx,+ual" +// LA64: "target-features"="+64bit,+d,+f,+lsx,+relax,+ual" int foo(void) { return 3; diff --git a/clang/test/Driver/loongarch-march.c b/clang/test/Driver/loongarch-march.c index b52cdb330716f..87cdffd8d3a02 100644 --- a/clang/test/Driver/loongarch-march.c +++ b/clang/test/Driver/loongarch-march.c @@ -21,39 +21,39 @@ // CC1-LOONGARCH64: "-target-cpu" "loongarch64" // CC1-LOONGARCH64-NOT: "-target-feature" -// CC1-LOONGARCH64: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual" +// CC1-LOONGARCH64: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual" // CC1-LOONGARCH64-NOT: "-target-feature" // CC1-LOONGARCH64: "-target-abi" "lp64d" // CC1-LA464: "-target-cpu" "la464" // CC1-LA464-NOT: "-target-feature" -// CC1-LA464: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual" +// CC1-LA464: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual" // CC1-LA464-NOT: "-target-feature" // CC1-LA464: "-target-abi" "lp64d" // CC1-LA64V1P0: "-target-cpu" "loongarch64" // CC1-LA64V1P0-NOT: "-target-feature" -// CC1-LA64V1P0: "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual" +// CC1-LA64V1P0: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual" // CC1-LA64V1P0-NOT: "-target-feature" // CC1-LA64V1P0: "-target-abi" "lp64d" // CC1-LA64V1P1: "-target-cpu" "loongarch64" // CC1-LA64V1P1-NOT: "-target-feature" -// CC1-LA64V1P1: "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual" "-target-feature" "+frecipe" "-target-feature" "+lam-bh" "-target-feature" "+lamcas" "-target-feature" "+
[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libcxx] [lldb] [llvm] [mlir] [openmp] Fix typos and spelling errors across codebase (PR #156270)
eugeneepshteyn wrote: flang and flang-rt changes could be one PR. (The changes look fine, but they need to be in the separate PR.) https://github.com/llvm/llvm-project/pull/156270 ___ 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)
@@ -0,0 +1,500 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; Test Flag Output Operands with 14 combinations of CCMASK and optimizations +; for AND for 3 three different functions, including two test cases from heiko. + +; RUN: llc < %s -verify-machineinstrs -mtriple=s390x-linux-gnu -O2 | FileCheck %s + +; Test CC == 0 && CC == 1. uweigand wrote: This test seems a bit pointless. `CC == 0 && CC == 1` is tautologically false, and that was apparently already recognized by common optimizers when you generated the test: see the `ret i32 0` IL statement. So there's nothing left for this test to actually verify. The same seems to hold for all the tests in this file. 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)
@@ -0,0 +1,5272 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; Test Flag Output Operands with 14 combinations of CCMASK and optimizations. +; Different ways of parenthesizing with mix of == and != operator for +; AND/OR/XOR combinations. + +; RUN: llc < %s -verify-machineinstrs -mtriple=s390x-linux-gnu -O3 | FileCheck %s + +; Test ((cc == 0) || (cc != 1)) ^ (cc != 2) uweigand wrote: And the same comment here ... and looks like most of the remaining tests. These don't actually verify what you apparently want to verify. 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)
https://github.com/uweigand edited 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)
@@ -0,0 +1,786 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; Test Flag Output Operands with 14 combinations of CCMASK and optimizations. +; This test negate of flag_output_operand_ccand, e.g +; CC != 0 && cc != 1 && cc != 2 for AND for three different functions, +; including two test cases from heiko. + +; RUN: llc < %s -verify-machineinstrs -mtriple=s390x-linux-gnu -O2 | FileCheck %s + +; Test CC != 0 && CC != 1. uweigand wrote: Now, these tests are not tautological. However, you still should make clear that you're not actually testing this code sequence in IL, but rather you're testing the IL that is currently being generated by common optimizers from that source code. In those cases, it might be better to have a clang-level test that verifies which IL we get, and then have IL-level tests here where necessary. 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] [clang][DebugInfo] Emit unified (Itanium) mangled name to structor declarations (PR #154142)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/154142 >From a4ec01a37825ac1a2fd910ad1357b7bbe403046e Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 18 Aug 2025 15:12:45 +0100 Subject: [PATCH 01/12] [llvm][DebugInfo] Support DW_AT_linkage_names that are different between declaration and definition (cherry picked from commit 62641a7cc6b439c747be0a9ae91b9b266d67816e) --- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 7 +- .../structor-declaration-linkage-names.ll | 68 +++ 2 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 llvm/test/DebugInfo/Generic/structor-declaration-linkage-names.ll diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index b03fac2d22a52..4904ad03199c7 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1403,11 +1403,8 @@ bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP, // Add the linkage name if we have one and it isn't in the Decl. StringRef LinkageName = SP->getLinkageName(); - assert(((LinkageName.empty() || DeclLinkageName.empty()) || - LinkageName == DeclLinkageName) && - "decl has a linkage name and it is different"); - if (DeclLinkageName.empty() && - // Always emit it for abstract subprograms. + // Always emit linkage name for abstract subprograms. + if (DeclLinkageName != LinkageName && (DD->useAllLinkageNames() || DU->getAbstractScopeDIEs().lookup(SP))) addLinkageName(SPDie, LinkageName); diff --git a/llvm/test/DebugInfo/Generic/structor-declaration-linkage-names.ll b/llvm/test/DebugInfo/Generic/structor-declaration-linkage-names.ll new file mode 100644 index 0..9b1f2a5b2a186 --- /dev/null +++ b/llvm/test/DebugInfo/Generic/structor-declaration-linkage-names.ll @@ -0,0 +1,68 @@ +; RUN: %llc_dwarf < %s -filetype=obj | llvm-dwarfdump -debug-info - | FileCheck %s + +; Make sure we attach DW_AT_linkage_name on function declarations but only +; attach it on definitions if the value is different than on the declaration. + +target triple = "arm64-apple-macosx" + +define void @_Z11SameLinkagev() !dbg !4 { +entry: + ret void +} + +; CHECK: DW_AT_linkage_name ("_Z11SameLinkagev") +; CHECK: DW_AT_declaration (true) +; CHECK-NOT: DW_AT_linkage_name ("_Z11SameLinkagev") + +define void @_Z11DiffLinkagev() !dbg !8 { +entry: + ret void +} + +; CHECK: DW_AT_linkage_name ("SomeName") +; CHECK: DW_AT_declaration (true) +; CHECK: DW_AT_linkage_name ("_Z11DiffLinkagev") + +define void @_Z15EmptyDefLinkagev() !dbg !10 { +entry: + ret void +} + +; CHECK: DW_AT_linkage_name ("_Z15EmptyDefLinkagev") +; CHECK: DW_AT_declaration (true) +; CHECK-NOT: DW_AT_linkage_name + +define void @_Z16EmptyDeclLinkagev() !dbg !12 { +entry: + ret void +} + +; CHECK: DW_AT_declaration (true) +; CHECK: DW_AT_linkage_name ("_Z16EmptyDeclLinkagev") + +define void @_Z13EmptyLinkagesv() !dbg !14 { +entry: + ret void +} + +; CHECK-NOT: DW_AT_linkage_name + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/") +!1 = !DIFile(filename: "foo.cpp", directory: "/tmp") +!2 = !{i32 7, !"Dwarf Version", i32 5} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = distinct !DISubprogram(name: "SameLinkage", linkageName: "_Z11SameLinkagev", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !7) +!5 = !DISubroutineType(types: !6) +!6 = !{null} +!7 = !DISubprogram(name: "SameLinkage", linkageName: "_Z11SameLinkagev", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0) +!8 = distinct !DISubprogram(name: "DiffLinkage", linkageName: "_Z11DiffLinkagev", scope: !1, file: !1, line: 5, type: !5, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !9) +!9 = !DISubprogram(name: "DiffLinkage", linkageName: "SomeName", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0) +!10 = distinct !DISubprogram(name: "EmptyDefLinkage", linkageName: "", scope: !1, file: !1, line: 5, type: !5, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !11) +!11 = !DISubprogram(name: "EmptyDefLinkage", linkageName: "_Z15EmptyDefLinkagev", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0) +!12 = distinct !DISubprogram(name: "EmptyDeclLinkage", linkageName: "_Z16EmptyDeclLinkagev", scope: !1, file: !1, line: 5, type: !5, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !13) +!13 = !DISubprogram(name: "EmptyDeclLinkage", linkageNam
[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libcxx] [lldb] [llvm] [mlir] [openmp] Fix typos and spelling errors across codebase (PR #156270)
https://github.com/joker-eph edited https://github.com/llvm/llvm-project/pull/156270 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libcxx] [lldb] [llvm] [mlir] [openmp] Fix typos and spelling errors across codebase (PR #156270)
joker-eph wrote: > > I don't understand why this happens again and again though. > > Seems pretty obvious to me: it's much easier for the author to submit one PR. The fact that it is easier for the author is why I would object any policy preventing it: we shouldn't discourage people from improving the codebase. I've been sending patches that spans subprojects before we even moved to git, I don't quite see the problem with this really. On some more consequent changes there is the argument of revert: if a revert is needed we don't want to revert things that could have landed cleanly. But that argument applies to any kind of changes where we push for things that can be decoupled to be landed independently. Applied to a PR like this one, this argument means that each individual hunk in the whole diff could land independently (oh well, that could be scripted, but there is low value here). So much for trivial changes ultimately! https://github.com/llvm/llvm-project/pull/156270 ___ 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)
@@ -0,0 +1,786 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; Test Flag Output Operands with 14 combinations of CCMASK and optimizations. +; This test negate of flag_output_operand_ccand, e.g +; CC != 0 && cc != 1 && cc != 2 for AND for three different functions, +; including two test cases from heiko. + +; RUN: llc < %s -verify-machineinstrs -mtriple=s390x-linux-gnu -O2 | FileCheck %s + +; Test CC != 0 && CC != 1. +define signext range(i32 0, 43) i32 @foo_01(i32 noundef signext %x) { +; CHECK-LABEL: foo_01: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:bnler %r14 +; CHECK-NEXT: .LBB0_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %2 = icmp samesign ugt i32 %asmresult1, 1 + %cond = select i1 %2, i32 42, i32 0 + ret i32 %cond +} + +declare void @llvm.assume(i1 noundef) #1 + +; Test CC != 0 && CC != 2. +define signext range(i32 0, 43) i32 @foo_02(i32 noundef signext %x) { +; CHECK-LABEL: foo_02: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:bher %r14 +; CHECK-NEXT: .LBB1_1: # %entry +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %2 = and i32 %asmresult1, 1 + %.not = icmp eq i32 %2, 0 + %cond = select i1 %.not, i32 0, i32 42 + ret i32 %cond +} + +; Test CC != 0 && CC != 3. +define signext range(i32 0, 43) i32 @foo_03(i32 noundef signext %x) { +; CHECK-LABEL: foo_03: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:blhr %r14 +; CHECK-NEXT: .LBB2_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %cmp = icmp ne i32 %asmresult1, 0 + %cmp2 = icmp ne i32 %asmresult1, 3 + %2 = and i1 %cmp, %cmp2 + %cond = select i1 %2, i32 42, i32 0 + ret i32 %cond +} + +; Test CC != 1 && CC != 2. +define signext range(i32 0, 43) i32 @foo_12(i32 noundef signext %x) { +; CHECK-LABEL: foo_12: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:bnlhr %r14 +; CHECK-NEXT: .LBB3_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %2 = add nsw i32 %asmresult1, -3 + %3 = icmp ult i32 %2, -2 + %cond = select i1 %3, i32 42, i32 0 + ret i32 %cond +} + +; Test CC != 1 && CC != 3. +define signext range(i32 0, 43) i32 @foo_13(i32 noundef signext %x) { +; CHECK-LABEL: foo_13: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:bher %r14 +; CHECK-NEXT: .LBB4_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %2 = and i32 %asmresult1, 1 + %.not.not = icmp eq i32 %2, 0 + %cond = select i1 %.not.not, i32 42, i32 0 + ret i32 %cond +} + +; Test CC != 2 && CC != 3. +define signext range(i32 0, 43) i32 @foo_23(i32 noundef signext %x) { +; CHECK-LABEL: foo_23: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:bler %r14 +; CHECK-NEXT: .LBB5_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %2 = or disjoint i32 %asmresult1, -4 + %3 = icmp samesign ult i32 %2, -2 + %cond = select i1 %3, i32 42, i32 0 + ret i32 %cond +} + +; Test CC != 0 && CC != 1 && CC != 2 +define
[clang] [llvm] Add support for flag output operand "=@cc" for SystemZ. (PR #125970)
@@ -0,0 +1,786 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; Test Flag Output Operands with 14 combinations of CCMASK and optimizations. +; This test negate of flag_output_operand_ccand, e.g +; CC != 0 && cc != 1 && cc != 2 for AND for three different functions, +; including two test cases from heiko. uweigand wrote: No point in including this name 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)
@@ -0,0 +1,939 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; Test Flag Output Operands with 14 combinations of CCMASK and optimizations +; for AND for 3 three different functions, including two tests from heiko. +; This test checks combinations of EQUAL(==) and NOT EQUAL (!=) operator. e.g. +; CC == 0 && CC != 1 && CC != 2 and CC == 0 && CC == 2 && CC != 3. uweigand wrote: Again, common optimizers will recognize that `CC == 0 && CC != 1` is just the same as `CC == 0`. This doesn't do anything in this file. 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] [clang-tools-extra] [compiler-rt] [flang] [libc] [libcxx] [lldb] [llvm] [mlir] [openmp] Fix typos and spelling errors across codebase (PR #156270)
https://github.com/joker-eph approved this pull request. Checked MLIR, LGTM. https://github.com/llvm/llvm-project/pull/156270 ___ 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)
@@ -0,0 +1,2427 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; Test Flag Output Operands with 14 combinations of CCMASK and optimizations. +; This tests mixing XOR wirh OR, XOR with AND and OR with AND with +; different ways of parenthesizing with == operator. + +; RUN: llc < %s -verify-machineinstrs -mtriple=s390x-linux-gnu -O3 | FileCheck %s + +declare void @llvm.assume(i1 noundef) + +@a = dso_local global i32 0, align 4 + +; Test ((cc == 0) || (cc == 1)) ^ (cc == 2) uweigand wrote: Once again it looks like the interesting parts have already happened when you generated this test - what actually interesting thing does *this* test (IL -> assembler) still verify? 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] [Clang](NFC) Add coverage for VTable debug info (PR #151818)
https://github.com/kikairoya updated https://github.com/llvm/llvm-project/pull/151818 >From ed08f7d66816d4adb58e3edf3b49a614ee5c28aa Mon Sep 17 00:00:00 2001 From: kikairoya Date: Sat, 2 Aug 2025 18:13:01 +0900 Subject: [PATCH 1/4] [Clang] Add coverage for VTable debug info Add test for: - shows effect of inlining member functions - shows effect of template instantiation methods Make cleaner a bit: - drops unnecessary REQUIRES clause - uses %clang_cc1 instead of %clang -Xclang - uses simply -O1 instead of -disable-O0-optnone -disable-llvm-passes * LTO test remains unchanged since replacing by -O1 changes output even if variables are anchored --- clang/test/DebugInfo/CXX/vtable-external.cpp | 93 +++ .../CXX/vtable-inheritance-diamond.cpp| 15 +-- .../CXX/vtable-inheritance-multiple.cpp | 12 +-- .../CXX/vtable-inheritance-simple-main.cpp| 2 - .../CXX/vtable-inheritance-simple.cpp | 15 +-- .../CXX/vtable-inheritance-virtual.cpp| 15 +-- .../CXX/vtable-template-instantiation.cpp | 87 + 7 files changed, 211 insertions(+), 28 deletions(-) create mode 100644 clang/test/DebugInfo/CXX/vtable-external.cpp create mode 100644 clang/test/DebugInfo/CXX/vtable-template-instantiation.cpp diff --git a/clang/test/DebugInfo/CXX/vtable-external.cpp b/clang/test/DebugInfo/CXX/vtable-external.cpp new file mode 100644 index 0..c4138e720ccae --- /dev/null +++ b/clang/test/DebugInfo/CXX/vtable-external.cpp @@ -0,0 +1,93 @@ +// The debug info of vtable is attached conditionally to whether +// - Member functions are inlined or not +// - Definition of destructor is visible or not + +struct CInlined { + virtual void f1() noexcept {} + virtual void f2() noexcept {} + virtual ~CInlined() noexcept; +}; +#ifndef NO_DTOR_BODY +inline CInlined::~CInlined() noexcept {} +#endif + +struct CNoInline { + virtual void g1() noexcept; + virtual void g2() noexcept; + virtual ~CNoInline() noexcept; +}; + +void CNoInline::g1() noexcept {} +void CNoInline::g2() noexcept {} +#ifndef NO_DTOR_BODY +CNoInline::~CNoInline() noexcept {} +#endif + +struct CNoFnDef { + virtual void h1() noexcept; + virtual void h2() noexcept; + virtual ~CNoFnDef() noexcept; +}; + +#ifndef NO_DTOR_BODY +CNoFnDef::~CNoFnDef() noexcept {} +#endif + +void use(void *, ...); + +int main() { + CInlined Inlined; + CNoInline NoInline; + CNoFnDef NoFnDef; + use(&Inlined, &NoInline, &NoFnDef); + + return 0; +} + +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -debug-info-kind=limited -dwarf-version=5 -O1 %s -o - | FileCheck %s -check-prefix CHECK-HAS-DTOR +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -debug-info-kind=limited -dwarf-version=5 -O1 -DNO_DTOR_BODY %s -o - | FileCheck %s -check-prefixes CHECK-NO-DTOR + +// CHECK-HAS-DTOR: $_ZTV8CInlined = comdat any +// CHECK-HAS-DTOR-NOT: $_ZTV9CNoInline +// CHECK-HAS-DTOR-NOT: $_ZTV8CNoFnDef + +// CHECK-HAS-DTOR-DAG: @_ZTV8CInlined = linkonce_odr {{.*}}constant {{{ \[[^]]*\] } { \[[^]]*\] \[[^]]*\] }}}, comdat, align 8, !dbg [[INLINED_VTABLE_VAR:![0-9]+]] +// CHECK-HAS-DTOR-DAG: @_ZTV9CNoInline = {{.*}}constant {{{ \[[^]]*\] } { \[[^]]*\] \[[^]]*\] }}}, align 8, !dbg [[NOINLINE_VTABLE_VAR:![0-9]+]] +// CHECK-HAS-DTOR-DAG: @_ZTV8CNoFnDef = external {{.*}}constant {{{ \[[^]]*\] }}}, align 8 + +// CHECK-HAS-DTOR: !llvm.dbg.cu + +// CHECK-HAS-DTOR-DAG: [[INLINED_VTABLE:![0-9]+]] = distinct !DIGlobalVariable(name: "_vtable$", linkageName: "_ZTV8CInlined" +// CHECK-HAS-DTOR-DAG: [[INLINED_VTABLE_VAR]] = !DIGlobalVariableExpression(var: [[INLINED_VTABLE]], expr: !DIExpression()) +// CHECK-HAS-DTOR-DAG: [[INLINED:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "CInlined" +// CHECK-HAS-DTOR-DAG: !DIDerivedType(tag: DW_TAG_variable, name: "_vtable$", scope: [[INLINED]], file: {{.*}}, baseType: {{![0-9]+}}, flags: DIFlagPrivate | DIFlagArtificial | DIFlagStaticMember) + +// CHECK-HAS-DTOR-DAG: [[NOINLINE_VTABLE:![0-9]+]] = distinct !DIGlobalVariable(name: "_vtable$", linkageName: "_ZTV9CNoInline" +// CHECK-HAS-DTOR-DAG: [[NOINLINE_VTABLE_VAR]] = !DIGlobalVariableExpression(var: [[NOINLINE_VTABLE]], expr: !DIExpression()) +// CHECK-HAS-DTOR-DAG: [[NOINLINE:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "CNoInline" +// CHECK-HAS-DTOR-DAG: !DIDerivedType(tag: DW_TAG_variable, name: "_vtable$", scope: [[NOINLINE]], file: {{.*}}, baseType: {{![0-9]+}}, flags: DIFlagPrivate | DIFlagArtificial | DIFlagStaticMember) + +// CHECK-HAS-DTOR-DAG: !llvm.ident + +// CHECK-HAS-DTOR-NOT: !DIGlobalVariable(name: "_vtable$", linkageName: "_ZTV8CNoFnDef" + + +// CHECK-NO-DTOR-NOT: $_ZTV8CInlined +// CHECK-NO-DTOR-NOT: $_ZTV9CNoInline +// CHECK-NO-DTOR-NOT: $_ZTV8CNoFnDef + +// CHECK-NO-DTOR-DAG: @_ZTV8CInlined = external {{.*}}constant {{.*}}, align 8{{$}} +// CHECK-NO-DTOR-DAG: @_ZTV9CNoInline = {{.*}}constant {{{ \[[^]]*\] } { \[[^]]*\] \[[^]]*\] }}}, align 8, !dbg [[NOINLINE_
[clang] [lldb] [llvm] [lldb][Expression] Add structor variant to LLDB's function call labels (PR #149827)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/149827 >From 5d75d1679d492df1a72c4013afde052f7b6195dd Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 18 Aug 2025 15:12:45 +0100 Subject: [PATCH 1/6] [llvm][DebugInfo] Support DW_AT_linkage_names that are different between declaration and definition (cherry picked from commit 62641a7cc6b439c747be0a9ae91b9b266d67816e) --- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 7 +- .../structor-declaration-linkage-names.ll | 68 +++ 2 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 llvm/test/DebugInfo/Generic/structor-declaration-linkage-names.ll diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index b03fac2d22a52..4904ad03199c7 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1403,11 +1403,8 @@ bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP, // Add the linkage name if we have one and it isn't in the Decl. StringRef LinkageName = SP->getLinkageName(); - assert(((LinkageName.empty() || DeclLinkageName.empty()) || - LinkageName == DeclLinkageName) && - "decl has a linkage name and it is different"); - if (DeclLinkageName.empty() && - // Always emit it for abstract subprograms. + // Always emit linkage name for abstract subprograms. + if (DeclLinkageName != LinkageName && (DD->useAllLinkageNames() || DU->getAbstractScopeDIEs().lookup(SP))) addLinkageName(SPDie, LinkageName); diff --git a/llvm/test/DebugInfo/Generic/structor-declaration-linkage-names.ll b/llvm/test/DebugInfo/Generic/structor-declaration-linkage-names.ll new file mode 100644 index 0..9b1f2a5b2a186 --- /dev/null +++ b/llvm/test/DebugInfo/Generic/structor-declaration-linkage-names.ll @@ -0,0 +1,68 @@ +; RUN: %llc_dwarf < %s -filetype=obj | llvm-dwarfdump -debug-info - | FileCheck %s + +; Make sure we attach DW_AT_linkage_name on function declarations but only +; attach it on definitions if the value is different than on the declaration. + +target triple = "arm64-apple-macosx" + +define void @_Z11SameLinkagev() !dbg !4 { +entry: + ret void +} + +; CHECK: DW_AT_linkage_name ("_Z11SameLinkagev") +; CHECK: DW_AT_declaration (true) +; CHECK-NOT: DW_AT_linkage_name ("_Z11SameLinkagev") + +define void @_Z11DiffLinkagev() !dbg !8 { +entry: + ret void +} + +; CHECK: DW_AT_linkage_name ("SomeName") +; CHECK: DW_AT_declaration (true) +; CHECK: DW_AT_linkage_name ("_Z11DiffLinkagev") + +define void @_Z15EmptyDefLinkagev() !dbg !10 { +entry: + ret void +} + +; CHECK: DW_AT_linkage_name ("_Z15EmptyDefLinkagev") +; CHECK: DW_AT_declaration (true) +; CHECK-NOT: DW_AT_linkage_name + +define void @_Z16EmptyDeclLinkagev() !dbg !12 { +entry: + ret void +} + +; CHECK: DW_AT_declaration (true) +; CHECK: DW_AT_linkage_name ("_Z16EmptyDeclLinkagev") + +define void @_Z13EmptyLinkagesv() !dbg !14 { +entry: + ret void +} + +; CHECK-NOT: DW_AT_linkage_name + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/") +!1 = !DIFile(filename: "foo.cpp", directory: "/tmp") +!2 = !{i32 7, !"Dwarf Version", i32 5} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = distinct !DISubprogram(name: "SameLinkage", linkageName: "_Z11SameLinkagev", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !7) +!5 = !DISubroutineType(types: !6) +!6 = !{null} +!7 = !DISubprogram(name: "SameLinkage", linkageName: "_Z11SameLinkagev", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0) +!8 = distinct !DISubprogram(name: "DiffLinkage", linkageName: "_Z11DiffLinkagev", scope: !1, file: !1, line: 5, type: !5, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !9) +!9 = !DISubprogram(name: "DiffLinkage", linkageName: "SomeName", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0) +!10 = distinct !DISubprogram(name: "EmptyDefLinkage", linkageName: "", scope: !1, file: !1, line: 5, type: !5, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !11) +!11 = !DISubprogram(name: "EmptyDefLinkage", linkageName: "_Z15EmptyDefLinkagev", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0) +!12 = distinct !DISubprogram(name: "EmptyDeclLinkage", linkageName: "_Z16EmptyDeclLinkagev", scope: !1, file: !1, line: 5, type: !5, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !13) +!13 = !DISubprogram(name: "EmptyDeclLinkage", linkageName:
[clang] [llvm] Add support for flag output operand "=@cc" for SystemZ. (PR #125970)
@@ -0,0 +1,939 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; Test Flag Output Operands with 14 combinations of CCMASK and optimizations +; for AND for 3 three different functions, including two tests from heiko. +; This test checks combinations of EQUAL(==) and NOT EQUAL (!=) operator. e.g. +; CC == 0 && CC != 1 && CC != 2 and CC == 0 && CC == 2 && CC != 3. + +; RUN: llc < %s -verify-machineinstrs -mtriple=s390x-linux-gnu -O2 | FileCheck %s + +; Test CC == 0 && CC != 1. +define signext range(i32 0, 43) i32 @foo_01(i32 noundef signext %x) { +; CHECK-LABEL: foo_01: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:ber %r14 +; CHECK-NEXT: .LBB0_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %cmp = icmp eq i32 %asmresult1, 0 + %cond = select i1 %cmp, i32 42, i32 0 + ret i32 %cond +} + +declare void @llvm.assume(i1 noundef) #1 + +; Test CC == 0 && CC != 2 +define signext range(i32 0, 43) i32 @foo_02(i32 noundef signext %x) { +; CHECK-LABEL: foo_02: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:ber %r14 +; CHECK-NEXT: .LBB1_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %cmp = icmp eq i32 %asmresult1, 0 + %cond = select i1 %cmp, i32 42, i32 0 + ret i32 %cond +} + +; Test CC == 0 && CC != 3. +define signext range(i32 0, 43) i32 @foo_03(i32 noundef signext %x) { +; CHECK-LABEL: foo_03: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:ber %r14 +; CHECK-NEXT: .LBB2_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %cmp = icmp eq i32 %asmresult1, 0 + %cond = select i1 %cmp, i32 42, i32 0 + ret i32 %cond +} + +; Test CC == 1 && CC != 2 +define signext range(i32 0, 43) i32 @foo_12(i32 noundef signext %x) { +; CHECK-LABEL: foo_12: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:blr %r14 +; CHECK-NEXT: .LBB3_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %cmp = icmp eq i32 %asmresult1, 1 + %cond = select i1 %cmp, i32 42, i32 0 + ret i32 %cond +} + +; Test CC == 1 && CC != 3 +define signext range(i32 0, 43) i32 @foo_13(i32 noundef signext %x) { +; CHECK-LABEL: foo_13: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:blr %r14 +; CHECK-NEXT: .LBB4_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %cmp = icmp eq i32 %asmresult1, 1 + %cond = select i1 %cmp, i32 42, i32 0 + ret i32 %cond +} + +; Test CC == 2 && CC != 3. +define signext range(i32 0, 43) i32 @foo_23(i32 noundef signext %x) { +; CHECK-LABEL: foo_23: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:#APP +; CHECK-NEXT:ahi %r2, 42 +; CHECK-EMPTY: +; CHECK-NEXT:#NO_APP +; CHECK-NEXT:lghi %r2, 42 +; CHECK-NEXT:bhr %r14 +; CHECK-NEXT: .LBB5_1: # %entry +; CHECK-NEXT:lghi %r2, 0 +; CHECK-NEXT:br %r14 +entry: + %0 = tail call { i32, i32 } asm "ahi $0,42\0A", "=d,={@cc},0"(i32 %x) #2 + %asmresult1 = extractvalue { i32, i32 } %0, 1 + %1 = icmp ult i32 %asmresult1, 4 + tail call void @llvm.assume(i1 %1) + %cmp = icmp eq i32 %asmresult1, 2 + %cond = select i1 %cmp, i32 42, i32 0 + ret i32 %cond +} + +; Test CC == 0 && CC != 1 && CC != 2. +define signext range(i32 0, 43) i32 @foo_012(i32 noundef signext %x) { +; CHECK-LABEL: foo_012: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT:
[clang] [llvm] Add support for flag output operand "=@cc" for SystemZ. (PR #125970)
@@ -1514,10 +1516,21 @@ SystemZTargetLowering::getConstraintType(StringRef Constraint) const { default: break; } + } else if (Constraint.size() == 5 && Constraint.starts_with("{")) { +if (StringRef("{@cc}").compare(Constraint) == 0) + return C_Other; } return TargetLowering::getConstraintType(Constraint); } +// Convert condition code in CCReg to an i32 value. +static SDValue getCCResult(SelectionDAG &DAG, SDValue CCReg) { uweigand wrote: Just a minor nit, but this ended up in a weird place now. Why not just move it to directly before the `LowerAsmOutputForConstraint` routine? 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] [clang-tools-extra] [compiler-rt] [flang] [libc] [libcxx] [lldb] [llvm] [mlir] [openmp] Fix typos and spelling errors across codebase (PR #156270)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff origin/main HEAD --extensions c,h,cpp,inc -- bolt/lib/Core/DebugNames.cpp clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/index/FileIndex.cpp clang-tools-extra/test/clang-tidy/checkers/abseil/faster-strsplit-delimiter.cpp clang-tools-extra/test/clang-tidy/checkers/readability/function-cognitive-complexity.cpp clang/include/clang/Sema/Sema.h clang/lib/APINotes/APINotesYAMLCompiler.cpp clang/lib/Analysis/FlowSensitive/Transfer.cpp clang/lib/Basic/OpenMPKinds.cpp clang/lib/CrossTU/CrossTranslationUnit.cpp clang/lib/Parse/ParseHLSLRootSignature.cpp clang/lib/Sema/CheckExprLifetime.cpp clang/lib/Sema/SemaCUDA.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/TreeTransform.h clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp clang/test/Analysis/cxx-uninitialized-object.cpp clang/test/CXX/except/except.spec/p13-friend.cpp clang/test/CodeGenCXX/ctor-empty-nounique.cpp clang/unittests/Format/FormatTestCSharp.cpp compiler-rt/lib/builtins/fp_add_impl.inc compiler-rt/lib/gwp_asan/tests/backtrace.cpp flang-rt/unittests/Runtime/NumericalFormatTest.cpp flang/lib/Lower/ConvertConstant.cpp flang/lib/Semantics/check-omp-structure.cpp libc/src/__support/RPC/rpc_server.h libc/src/__support/math/cbrt.h libc/src/__support/str_to_float.h libc/src/stdio/generic/fgets.cpp libc/src/stdlib/strfroml.cpp libc/test/integration/startup/gpu/rpc_interface_test.cpp libcxx/include/__math/special_functions.h lldb/include/lldb/API/SBCommandInterpreter.h lldb/include/lldb/Target/Platform.h lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/source/Plugins/TraceExporter/common/TraceHTR.cpp lldb/source/Plugins/TraceExporter/common/TraceHTR.h lldb/source/ValueObject/DILEval.cpp lldb/test/Shell/SymbolFile/DWARF/split-dwarf-expression-eval-bug.cpp lldb/unittests/Utility/StreamTest.cpp llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h llvm/include/llvm/Support/LEB128.h llvm/include/llvm/Support/raw_socket_stream.h llvm/lib/CodeGen/RegisterPressure.cpp llvm/lib/DebugInfo/DWARF/DWARFContext.cpp llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp llvm/lib/Support/TextEncoding.cpp llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp llvm/lib/Transforms/IPO/AttributorAttributes.cpp llvm/lib/Transforms/Scalar/LICM.cpp llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp llvm/lib/Transforms/Utils/IRNormalizer.cpp mlir/include/mlir/Analysis/DataFlowFramework.h mlir/include/mlir/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.h mlir/lib/Dialect/Arith/IR/ArithOps.cpp mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp mlir/test/lib/Analysis/TestDataFlowFramework.cpp openmp/libompd/gdb-plugin/ompdModule.c openmp/runtime/src/kmp_runtime.cpp openmp/runtime/test/api/omp60_memory_routines.c `` :warning: The reproduction instructions above might return results for more than one PR in a stack if you are using a stacked PR workflow. You can limit the results by changing `origin/main` to the base branch/commit you want to compare against. :warning: View the diff from clang-format here. ``diff diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index f9f1a9b45..06c4c4fc8 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -10989,7 +10989,7 @@ static void checkMethodTypeQualifiers(Sema &S, Declarator &D, unsigned DiagID) { bool DiagOccurred = false; FTI.MethodQualifiers->forEachQualifier( [DiagID, &S, &DiagOccurred](DeclSpec::TQ, StringRef QualName, - SourceLocation SL) { +SourceLocation SL) { // This diagnostic should be emitted on any qualifier except an addr // space qualifier. However, forEachQualifier currently doesn't visit // addr space qualifiers, so there's no way to write this condition diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp index b39431209..0264d88c4 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp @@ -367,10 +367,10 @@ bool AMDGPUPostLe
[clang] [clang][OpenMP] 6.0: detect privatization of array section/assumed-size array (PR #152786)
alexey-bataev wrote: Update OpenMPSupport.rst and common clang document https://github.com/llvm/llvm-project/pull/152786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] fix pc range condition check bug (PR #154902)
philnik777 wrote: @yingcong-wu The new test fails on the Arm bots. Please fix it soon or revert to get the precommit CI green again (finally). https://github.com/llvm/llvm-project/pull/154902 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [lldb][Expression] Add structor variant to LLDB's function call labels (PR #149827)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/149827 >From bb71b69ea69fe4046a3f93e30f82dfb1d4d59b69 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 18 Aug 2025 15:14:40 +0100 Subject: [PATCH 1/3] [clang][DebugInfo] Emit unified (Itanium) mangled name to structor declarations --- clang/include/clang/Basic/ABI.h | 10 ++- clang/include/clang/Basic/DebugOptions.def| 6 ++ clang/include/clang/Driver/Options.td | 12 +++ clang/lib/AST/ItaniumMangle.cpp | 10 +++ clang/lib/AST/MicrosoftMangle.cpp | 2 + clang/lib/CodeGen/CGClass.cpp | 2 + clang/lib/CodeGen/CGDebugInfo.cpp | 35 ++-- clang/lib/CodeGen/CGDebugInfo.h | 4 + clang/lib/CodeGen/ItaniumCXXABI.cpp | 5 ++ clang/lib/CodeGen/MicrosoftCXXABI.cpp | 4 + clang/lib/Driver/ToolChains/Clang.cpp | 4 + clang/test/DebugInfo/CXX/artificial-arg.cpp | 3 +- .../CXX/debug-info-structor-linkage-names.cpp | 89 +++ clang/test/DebugInfo/ObjCXX/cyclic.mm | 5 +- 14 files changed, 178 insertions(+), 13 deletions(-) create mode 100644 clang/test/DebugInfo/CXX/debug-info-structor-linkage-names.cpp diff --git a/clang/include/clang/Basic/ABI.h b/clang/include/clang/Basic/ABI.h index 231bad799a42c..8279529c316cf 100644 --- a/clang/include/clang/Basic/ABI.h +++ b/clang/include/clang/Basic/ABI.h @@ -27,14 +27,16 @@ enum CXXCtorType { Ctor_Comdat, ///< The COMDAT used for ctors Ctor_CopyingClosure, ///< Copying closure variant of a ctor Ctor_DefaultClosure, ///< Default closure variant of a ctor + Ctor_Unified,///< GCC-style unified dtor }; /// C++ destructor types. enum CXXDtorType { -Dtor_Deleting, ///< Deleting dtor -Dtor_Complete, ///< Complete object dtor -Dtor_Base, ///< Base object dtor -Dtor_Comdat///< The COMDAT used for dtors + Dtor_Deleting, ///< Deleting dtor + Dtor_Complete, ///< Complete object dtor + Dtor_Base, ///< Base object dtor + Dtor_Comdat, ///< The COMDAT used for dtors + Dtor_Unified, ///< GCC-style unified dtor }; } // end namespace clang diff --git a/clang/include/clang/Basic/DebugOptions.def b/clang/include/clang/Basic/DebugOptions.def index c6e736e92744c..a768b12fa4e0d 100644 --- a/clang/include/clang/Basic/DebugOptions.def +++ b/clang/include/clang/Basic/DebugOptions.def @@ -125,6 +125,12 @@ DEBUGOPT(DebugNameTable, 2, 0, Compatible) /// Whether to use DWARF base address specifiers in .debug_ranges. DEBUGOPT(DebugRangesBaseAddress, 1, 0, Compatible) +/// Whether to add linkage names to constructor/destructor declarations. +/// This is an escape hatch for cases where attaching the additional linkage +/// names would increase debug-info size (particularly the .debug_str section) +/// too much. +DEBUGOPT(DebugStructorDeclLinkageNames, 1, 0, Benign) + /// Whether to embed source in DWARF debug line section. DEBUGOPT(EmbedSource, 1, 0, Compatible) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index f507968d30670..ed467c055a270 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4778,6 +4778,18 @@ def gembed_source : Flag<["-"], "gembed-source">, Group, def gno_embed_source : Flag<["-"], "gno-embed-source">, Group, Flags<[NoXarchOption]>, HelpText<"Restore the default behavior of not embedding source text in DWARF debug sections">; +defm structor_decl_linkage_names +: BoolGOption<"structor-decl-linkage-names", + CodeGenOpts<"DebugStructorDeclLinkageNames">, DefaultTrue, + NegFlag, + PosFlag, + BothFlags<[], [ClangOption, CLOption, CC1Option]>>, + DocBrief<[{On some ABIs (e.g., Itanium), constructors and destructors may have multiple variants. Historically, when generating DWARF, Clang did not attach ``DW_AT_linkage_name``s to structor DIEs because there were multiple possible manglings (depending on the structor variant) that could be used. With ``-gstructor-decl-linkage-names``, for ABIs with structor variants, we attach a "unified" mangled name to structor declarations DIEs which debuggers can use to look up all the definitions for a structor declaration. E.g., a "unified" mangled name ``_ZN3FooC4Ev`` may have multiple definitions associated with it such as ``_ZN3FooC1Ev`` and ``_ZN3FooC2Ev``. + +Enabling this flag results in a better interactive debugging experience (both GDB and LLDB have support for understanding these "unified" linkage names). However, it comes with a significant increase in debug-info size (particularly the `.debug_str` section). As an escape hatch, users can disable this feature using ``-gno-structor-decl-linkage-names``.}]>; defm key_instructions : BoolGOption<"key-instructions", CodeGenOpts<"DebugKeyInstructions">, DefaultFalse, Ne
[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)
@@ -955,31 +960,69 @@ class OMPLoopBasedDirective : public OMPExecutableDirective { } }; -/// The base class for all loop transformation directives. -class OMPLoopTransformationDirective : public OMPLoopBasedDirective { +/// Common class of data shared between +/// OMPCanonicalLoopNestTransformationDirective and +/// OMPCanonicalLoopSequenceTransformationDirective +class OMPLoopTransformationDirective { friend class ASTStmtReader; - /// Number of loops generated by this loop transformation. - unsigned NumGeneratedLoops = 0; + /// Number of (top-level) generated loops. + /// This value is 1 for most transformations as they only map one loop nest + /// into another. + /// Some loop transformations (like a non-partial 'unroll') may not generate + /// a loop nest, so this would be 0. + /// Some loop transformations (like 'fuse' with looprange and 'split') may + /// generate more than one loop nest, so the value would be >= 1. + unsigned NumGeneratedLoops = 1; + + /// We need this because we cannot easily make OMPLoopTransformationDirective + /// a proper Stmt. + Stmt *S; protected: - explicit OMPLoopTransformationDirective(StmtClass SC, - OpenMPDirectiveKind Kind, - SourceLocation StartLoc, - SourceLocation EndLoc, - unsigned NumAssociatedLoops) - : OMPLoopBasedDirective(SC, Kind, StartLoc, EndLoc, NumAssociatedLoops) {} + void setNumGeneratedLoops(unsigned N) { NumGeneratedLoops = N; } - /// Set the number of loops generated by this loop transformation. - void setNumGeneratedLoops(unsigned Num) { NumGeneratedLoops = Num; } + explicit OMPLoopTransformationDirective(Stmt *S) : S(S) {} + +public: + unsigned getNumGeneratedLoops() const { return NumGeneratedLoops; } + + /// Returns the specific directive related to this loop transformation. + Stmt *getDirective() const { return S; } + + /// Get the de-sugared statements after the loop transformation. + /// + /// Might be nullptr if either the directive generates no loops and is handled + /// directly in CodeGen, or resolving a template-dependence context is + /// required. + Stmt *getTransformedStmt() const; + + /// Return preinits statement. + Stmt *getPreInits() const; + + static bool classof(const Stmt *T) { +return isa(T) || + isa(T); alexey-bataev wrote: ```suggestion return isa(T); ``` https://github.com/llvm/llvm-project/pull/139293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)
@@ -6582,4 +6740,40 @@ class OMPAssumeDirective final : public OMPExecutableDirective { } // end namespace clang +namespace llvm { +// Allow a Stmt* be casted correctly to an OMPLoopTransformationDirective*. +// The default routines would just use a C-style cast which won't work well +// for the multiple inheritance here. We have to use a static cast from the +// corresponding subclass. +template <> +struct CastInfo +: public NullableValueCastFailed, + public DefaultDoCastIfPossible< + clang::OMPLoopTransformationDirective *, clang::Stmt *, + CastInfo> { + static bool isPossible(const clang::Stmt *T) { +return clang::OMPLoopTransformationDirective::classof(T); + } + + static clang::OMPLoopTransformationDirective *doCast(clang::Stmt *T) { +if (auto *D = +dyn_cast(T)) { + return static_cast(D); +} alexey-bataev wrote: Drop braces https://github.com/llvm/llvm-project/pull/139293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)
@@ -955,31 +960,69 @@ class OMPLoopBasedDirective : public OMPExecutableDirective { } }; -/// The base class for all loop transformation directives. -class OMPLoopTransformationDirective : public OMPLoopBasedDirective { +/// Common class of data shared between +/// OMPCanonicalLoopNestTransformationDirective and +/// OMPCanonicalLoopSequenceTransformationDirective +class OMPLoopTransformationDirective { friend class ASTStmtReader; - /// Number of loops generated by this loop transformation. - unsigned NumGeneratedLoops = 0; + /// Number of (top-level) generated loops. + /// This value is 1 for most transformations as they only map one loop nest + /// into another. + /// Some loop transformations (like a non-partial 'unroll') may not generate + /// a loop nest, so this would be 0. + /// Some loop transformations (like 'fuse' with looprange and 'split') may + /// generate more than one loop nest, so the value would be >= 1. + unsigned NumGeneratedLoops = 1; + + /// We need this because we cannot easily make OMPLoopTransformationDirective + /// a proper Stmt. + Stmt *S; alexey-bataev wrote: ```suggestion Stmt *S = nullptr; ``` https://github.com/llvm/llvm-project/pull/139293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang]: Support `analyzer_noreturn` attribute in `CFG` (PR #150952)
https://github.com/Xazax-hun closed https://github.com/llvm/llvm-project/pull/150952 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] df95dfc - [clang]: Support `analyzer_noreturn` attribute in `CFG` (#150952)
Author: Andrey Karlov Date: 2025-09-01T16:02:09+01:00 New Revision: df95dfcf5a1e900801fdaa50daa63df16ca86fc3 URL: https://github.com/llvm/llvm-project/commit/df95dfcf5a1e900801fdaa50daa63df16ca86fc3 DIFF: https://github.com/llvm/llvm-project/commit/df95dfcf5a1e900801fdaa50daa63df16ca86fc3.diff LOG: [clang]: Support `analyzer_noreturn` attribute in `CFG` (#150952) ## Problem Currently, functions with `analyzer_noreturn` attribute aren't recognized as `no-return` by `CFG`: ```cpp void assertion_handler() __attribute__((analyzer_noreturn)) { log(...); } void handle_error(const std::optional opt) { if (!opt) { fatal_error(); // Static analyzer doesn't know this never returns } *opt = 1; // False-positive `unchecked-optional-access` warning as analyzer thinks this is reachable } ``` ## Solution 1. Extend the `FunctionDecl` class by adding an `isAnalyzerNoReturn()` function 2. Update `CFGBuilder::VisitCallExpr` to check both `FD->isNoReturn()` and `FD->isAnalyzerNoReturn()` properties ## Comments This PR incorporates part of the work done in https://github.com/llvm/llvm-project/pull/146355 Added: Modified: clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp clang/include/clang/AST/Decl.h clang/lib/AST/Decl.cpp clang/lib/Analysis/CFG.cpp clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp Removed: diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp index 3167b85f0e024..4911157828765 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp @@ -141,6 +141,17 @@ void nullable_value_after_swap(BloombergLP::bdlb::NullableValue &opt1, Bloo } } +void assertion_handler() __attribute__((analyzer_noreturn)); + +void function_calling_analyzer_noreturn(const bsl::optional& opt) +{ + if (!opt) { + assertion_handler(); + } + + *opt; // no-warning: The previous condition guards this dereference. +} + template void function_template_without_user(const absl::optional &opt) { opt.value(); // no-warning diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 7c9245d8298a2..c24d4124d9fc5 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -2668,6 +2668,10 @@ class FunctionDecl : public DeclaratorDecl, /// an attribute on its declaration or its type. bool isNoReturn() const; + /// Determines whether this function is known to be 'noreturn' for analyzer, + /// through an `analyzer_noreturn` attribute on its declaration. + bool isAnalyzerNoReturn() const; + /// True if the function was a definition but its body was skipped. bool hasSkippedBody() const { return FunctionDeclBits.HasSkippedBody; } void setHasSkippedBody(bool Skipped = true) { diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 343673069e15e..d8dffb7f5dc43 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -3600,6 +3600,10 @@ bool FunctionDecl::isNoReturn() const { return false; } +bool FunctionDecl::isAnalyzerNoReturn() const { + return hasAttr(); +} + bool FunctionDecl::isMemberLikeConstrainedFriend() const { // C++20 [temp.friend]p9: // A non-template friend declaration with a requires-clause [or] diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index d960d5130332b..60a2d113c08e2 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -2833,7 +2833,8 @@ CFGBlock *CFGBuilder::VisitCallExpr(CallExpr *C, AddStmtChoice asc) { if (!FD->isVariadic()) findConstructionContextsForArguments(C); -if (FD->isNoReturn() || C->isBuiltinAssumeFalse(*Context)) +if (FD->isNoReturn() || FD->isAnalyzerNoReturn() || +C->isBuiltinAssumeFalse(*Context)) NoReturn = true; if (FD->hasAttr()) AddEHEdge = false; diff --git a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp index 9fb7bebdbe41e..d1dd4ff3ea33e 100644 --- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp @@ -693,6 +693,80 @@ TEST_F(NoreturnDestructorTest, ConditionalOperatorNestedBranchReturns) { // FIXME: Called functions at point `p` should contain only "foo". } +class AnalyzerNoreturnTest : public Test { +protected: + template + void runDataflow(llvm::StringRef Code, Matcher Expectations) { +tooling::FileContentMappings FilesContents; +FilesContents.push_back( +std::make_pair("noreturn_test_def
[clang] [compiler-rt] [llvm] coverage-capabilities (PR #156307)
Dorian =?utf-8?q?Péron?= , Dorian =?utf-8?q?Péron?= , Dorian =?utf-8?q?Péron?= Message-ID: In-Reply-To: llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Dorian Péron (RenjiSann) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/156307.diff 8 Files Affected: - (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+9) - (modified) compiler-rt/include/profile/InstrProfData.inc (+3-1) - (modified) llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h (+56-2) - (modified) llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h (+12-1) - (modified) llvm/include/llvm/ProfileData/InstrProfData.inc (+3-1) - (modified) llvm/lib/ProfileData/Coverage/CoverageMapping.cpp (+15-4) - (modified) llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp (+26-6) - (modified) llvm/tools/llvm-cov/CodeCoverage.cpp (+12-3) ``diff diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 05fb137ca0575..441d537e1f33f 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -2604,6 +2604,15 @@ void CoverageMappingModuleGen::emit() { }; auto CovDataHeaderTy = llvm::StructType::get(Ctx, ArrayRef(CovDataHeaderTypes)); + + // By default, clang instruments the code for "statement" and "branch" + // coverage, and can instrument for MCDC when `-fcoverage-mcdc` is passed. + uint32_t CovInstrLevels = CoverageCapabilities::CovInstrLevel::Statement | +CoverageCapabilities::CovInstrLevel::Branch; + if (CGM.getCodeGenOpts().hasProfileClangInstr() && + CGM.getCodeGenOpts().MCDCCoverage) +CovInstrLevels |= CoverageCapabilities::CovInstrLevel::MCDC; + llvm::Constant *CovDataHeaderVals[] = { #define COVMAP_HEADER(Type, LLVMType, Name, Init) Init, #include "llvm/ProfileData/InstrProfData.inc" diff --git a/compiler-rt/include/profile/InstrProfData.inc b/compiler-rt/include/profile/InstrProfData.inc index 0496f240dc823..a2af7cfa8cbe1 100644 --- a/compiler-rt/include/profile/InstrProfData.inc +++ b/compiler-rt/include/profile/InstrProfData.inc @@ -300,6 +300,8 @@ COVMAP_HEADER(uint32_t, Int32Ty, CoverageSize, \ llvm::ConstantInt::get(Int32Ty, CoverageMappingSize)) COVMAP_HEADER(uint32_t, Int32Ty, Version, \ llvm::ConstantInt::get(Int32Ty, CovMapVersion::CurrentVersion)) +COVMAP_HEADER(uint32_t, Int32Ty, CovInstrLevels, \ + llvm::ConstantInt::get(Int32Ty, CovInstrLevels)) #undef COVMAP_HEADER /* COVMAP_HEADER end. */ @@ -724,7 +726,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure, /* Indexed profile format version (start from 1). */ #define INSTR_PROF_INDEX_VERSION 12 /* Coverage mapping format version (start from 0). */ -#define INSTR_PROF_COVMAP_VERSION 6 +#define INSTR_PROF_COVMAP_VERSION 7 /* Profile version is always of type uint64_t. Reserve the upper 32 bits in the * version for other variants of profile. We set the 8th most significant bit diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h index 7d1a85ba528fc..64e9a138815f5 100644 --- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h +++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h @@ -984,6 +984,47 @@ class CoverageData { ArrayRef getMCDCRecords() const { return MCDCRecords; } }; +/// TODO: Document +/// Represents a set of available capabilities +class CoverageCapabilities { + uint32_t Capabilities; + +public: + enum CovInstrLevel { +Statement = (1 << 0), +Branch = (1 << 1), +MCDC = (1 << 2), + }; + + CoverageCapabilities(uint32_t Capabilities) : Capabilities(Capabilities){}; + + static CoverageCapabilities all() { +return CoverageCapabilities(Statement | Branch | MCDC); + } + + static CoverageCapabilities none() { +return CoverageCapabilities(0); + } + + bool hasCapability(CovInstrLevel Lvl) const { +return (this->Capabilities & Lvl) != 0; + } + + /// Returns true if this includes all the capabilities of Other. + bool includes(const CoverageCapabilities &Other) const { +return (this->Capabilities & Other.Capabilities) == Other.Capabilities; + } + + CoverageCapabilities& operator |= (const CoverageCapabilities &Rhs) { +this->Capabilities |= Rhs.Capabilities; +return *this; + } + + CoverageCapabilities operator | (const CoverageCapabilities &Rhs) const { +return CoverageCapabilities(this->Capabilities | Rhs.Capabilities); + } +}; + /// The mapping of profile information to coverage data. /// /// This is the main interface to get coverage information, using a profile to @@ -994,6 +1035,10 @@ class CoverageMapping { DenseMap> FilenameHash2RecordIndices; std::vector> FuncHashMismatches; + /// Keep track of the coverage capabilities of the loaded object file, + /// which depends on the parameters used to compile it. + CoverageCapabiliti