[clang] [libclang/python] Fix get_exception_specification_kind (PR #101548)
https://github.com/DeinAlptraum updated https://github.com/llvm/llvm-project/pull/101548 >From e7e66f0f90d7fb9adf3d3f546becd87c7527fa4c Mon Sep 17 00:00:00 2001 From: Jannick Kremer Date: Thu, 1 Aug 2024 20:01:34 +0100 Subject: [PATCH 1/2] [libclang/python] Fix get_exception_specification_kind --- clang/bindings/python/clang/cindex.py| 2 +- .../cindex/test_exception_specification_kind.py | 12 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 2038ef6045c7d..c251c46a04adf 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2654,7 +2654,7 @@ def get_exception_specification_kind(self): the ExceptionSpecificationKind enumeration. """ return ExceptionSpecificationKind.from_id( -conf.lib.clang.getExceptionSpecificationType(self) +conf.lib.clang_getExceptionSpecificationType(self) ) @property diff --git a/clang/bindings/python/tests/cindex/test_exception_specification_kind.py b/clang/bindings/python/tests/cindex/test_exception_specification_kind.py index 8e2a6b5c50223..e4742db31adbe 100644 --- a/clang/bindings/python/tests/cindex/test_exception_specification_kind.py +++ b/clang/bindings/python/tests/cindex/test_exception_specification_kind.py @@ -13,7 +13,7 @@ def find_function_declarations(node, declarations=[]): if node.kind == clang.cindex.CursorKind.FUNCTION_DECL: -declarations.append((node.spelling, node.exception_specification_kind)) +declarations.append(node) for child in node.get_children(): declarations = find_function_declarations(child, declarations) return declarations @@ -33,4 +33,12 @@ def test_exception_specification_kind(self): ("square2", ExceptionSpecificationKind.BASIC_NOEXCEPT), ("square3", ExceptionSpecificationKind.COMPUTED_NOEXCEPT), ] -self.assertListEqual(declarations, expected) +from_cursor = [ +(node.spelling, node.exception_specification_kind) for node in declarations +] +from_type = [ +(node.spelling, node.type.get_exception_specification_kind()) +for node in declarations +] +self.assertListEqual(from_cursor, expected) +self.assertListEqual(from_type, expected) >From 446507880b0204a7b7941826c1fcaab467c36109 Mon Sep 17 00:00:00 2001 From: Jannick Kremer Date: Fri, 2 Aug 2024 08:06:49 +0100 Subject: [PATCH 2/2] Add release note --- clang/docs/ReleaseNotes.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ba70b138a04c4..8101d4327cd47 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -299,6 +299,7 @@ Sanitizers Python Binding Changes -- +- Fixed an issue that led to crashes when calling ``Type.get_exception_specification_kind``. OpenMP Support -- ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python] Fix get_exception_specification_kind (PR #101548)
DeinAlptraum wrote: I can't think of any more genereal approach that prevents this sort of problem. Type checking would help with this (e.g. giving an error when an unknown attribute is called on an object) though it wouldn't have worked in this specific case... otherwise nothing to do but add more tests I guess. https://github.com/llvm/llvm-project/pull/101548 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] Reland "[X86][AVX10.2] Support AVX10.2 option and VMPSADBW/VADDP[D,H,S] new instructions (#101452)" (PR #101616)
@@ -223,6 +227,10 @@ InstructionContext RecognizableInstr::insnContext() const { insnContext = EVEX_KB_U(IC_EVEX_XD); else if (OpPrefix == X86Local::PS) insnContext = EVEX_KB_U(IC_EVEX); +else { + errs() << "Instruction does not use a prefix: " << Name << "\n"; + llvm_unreachable("Invalid prefix"); KanRobert wrote: I meant there is always a default prefix opcode `PS` for EVEX prefix, so `does not use a prefix` is misleading. Yes, I suggest merging the `errs() << ` into `llvm_unreachable`. https://github.com/llvm/llvm-project/pull/101616 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)
@@ -5337,7 +5337,9 @@ def mmadd4 : Flag<["-"], "mmadd4">, Group, def mno_madd4 : Flag<["-"], "mno-madd4">, Group, HelpText<"Disable the generation of 4-operand madd.s, madd.d and related instructions.">; def mmsa : Flag<["-"], "mmsa">, Group, - HelpText<"Enable MSA ASE (MIPS only)">; + Visibility<[ClangOption, CC1Option, CC1AsOption]>, + HelpText<"Enable MSA ASE (MIPS only)">, + MarshallingInfoFlag>; yingopq wrote: Yes, OK. https://github.com/llvm/llvm-project/pull/99615 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)
yingopq wrote: > Can you add driver tests? `#97378` `-Wa,--crel` is a good example. OK, Thanks. https://github.com/llvm/llvm-project/pull/99615 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fixing Clang HIP inconsistent order for template functions (PR #101627)
https://github.com/Ritanya-B-Bharadwaj created https://github.com/llvm/llvm-project/pull/101627 Fixing the issue - [#101458 ](https://github.com/llvm/llvm-project/issues/101458) As mentioned in the issue, the order of the functions in the asm output from clang is non-deterministic. Here is the reproducer: ``` #include "hip/hip_runtime.h" #define CHECK(cmd) \ { \ hipError_t error = cmd; \ if (error != hipSuccess) { \ fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error,\ __FILE__, __LINE__); \ exit(EXIT_FAILURE); \ } \ } template __global__ void kernel() { printf("Hello from kernel %d\n", i); } template __global__ void kernel<1>(); template __global__ void kernel<2>(); template __global__ void kernel<3>(); int main(int argc, char* argv[]) { hipLaunchKernelGGL(kernel<1>, dim3(1), dim3(1), 0, 0); CHECK(hipDeviceSynchronize()); hipLaunchKernelGGL(kernel<2>, dim3(1), dim3(1), 0, 0); CHECK(hipDeviceSynchronize()); hipLaunchKernelGGL(kernel<3>, dim3(1), dim3(1), 0, 0); CHECK(hipDeviceSynchronize()); } ``` ``` for i in $(seq 5); do clang -x hip --offload-arch=gfx908 -save-temps -fgpu-rdc -Ofast test_hip.cpp md5sum test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc llvm-dis test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc cp test_hip-hip-amdgcn-amd-amdhsa-gfx908.ll test_hip-hip-amdgcn-amd-amdhsa-gfx908.$i.ll done 75be8654e3a6c39e1e83f5c8b7dda364 test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc bde823a75c56e9af933be309d8e433f3 test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc e18bbc2e4768556c52864c716cba9c02 test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc e18bbc2e4768556c52864c716cba9c02 test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc 75be8654e3a6c39e1e83f5c8b7dda364 test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc ``` The order of functions referenced in `__clang_gpu_used_external` changes each time: ``` diff --git a/test_hip-hip-amdgcn-amd-amdhsa-gfx908.1.ll b/test_hip-hip-amdgcn-amd-amdhsa-gfx908.2.ll index 91c0453..abd2b01 100644 --- a/test_hip-hip-amdgcn-amd-amdhsa-gfx908.1.ll +++ b/test_hip-hip-amdgcn-amd-amdhsa-gfx908.2.ll @@ -17,7 +17,7 @@ $_Z6kernelILi2EEvv = comdat any $_Z6kernelILi3EEvv = comdat any @.str = private unnamed_addr addrspace(4) constant [22 x i8] c"Hello from kernel %d\0A\00", align 1 -@__clang_gpu_used_external = internal addrspace(1) global [3 x ptr] [ptr @_Z6kernelILi1EEvv, ptr @_Z6kernelILi2EEvv, ptr @_Z6kernelILi3EEvv] +@__clang_gpu_used_external = internal addrspace(1) global [3 x ptr] [ptr @_Z6kernelILi2EEvv, ptr @_Z6kernelILi3EEvv, ptr @_Z6kernelILi1EEvv] @__oclc_ABI_version = weak_odr hidden local_unnamed_addr addrspace(4) constant i32 500 @llvm.compiler.used = appending addrspace(1) global [1 x ptr] [ptr addrspacecast (ptr addrspace(1) @__clang_gpu_used_external to ptr)], section "llvm.metadata" ``` The order is determined by the order the functions are stored in the `DenseSet` `CUDAExternalDeviceDeclODRUsedByHost `(which is non-deterministic). Hence changing `CUDAExternalDeviceDeclODRUsedByHost` from `llvm::DenseSet` to `llvm::SetVector` for a deterministic behaviour. >From d2d3fb3ca20d9a56d01026d0febc9892e0889031 Mon Sep 17 00:00:00 2001 From: Ritanya B Bharadwaj Date: Fri, 2 Aug 2024 02:14:03 -0500 Subject: [PATCH] Fixing Clang HIP inconsistent order for template functions --- clang/include/clang/AST/ASTContext.h | 3 ++- clang/test/CodeGenHIP/hip-checksum.cpp | 27 ++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenHIP/hip-checksum.cpp diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index ec8b32533eca8..9368a35818a92 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -34,6 +34,7 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" @@ -1193,7 +1194,7 @@ class ASTContext : public RefCountedBase { /// Keep track of CUDA/HIP external kernels or device variables ODR-used by /// host code. - llvm::DenseSet CUDAExternalDeviceDeclODRUsedByHost; + llvm::SetVector CUDAExternalDeviceDeclODRUsedByHost; /// Keep track of CUDA/HIP implicit host device functions used on device side /// in device compilation. diff --git a/c
[clang] Fixing Clang HIP inconsistent order for template functions (PR #101627)
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/101627 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fixing Clang HIP inconsistent order for template functions (PR #101627)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (Ritanya-B-Bharadwaj) Changes Fixing the issue - [#101458 ](https://github.com/llvm/llvm-project/issues/101458) As mentioned in the issue, the order of the functions in the asm output from clang is non-deterministic. Here is the reproducer: ``` #include "hip/hip_runtime.h" #define CHECK(cmd) \ { \ hipError_t error = cmd; \ if (error != hipSuccess) { \ fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error,\ __FILE__, __LINE__); \ exit(EXIT_FAILURE); \ } \ } template__global__ void kernel() { printf("Hello from kernel %d\n", i); } template __global__ void kernel<1>(); template __global__ void kernel<2>(); template __global__ void kernel<3>(); int main(int argc, char* argv[]) { hipLaunchKernelGGL(kernel<1>, dim3(1), dim3(1), 0, 0); CHECK(hipDeviceSynchronize()); hipLaunchKernelGGL(kernel<2>, dim3(1), dim3(1), 0, 0); CHECK(hipDeviceSynchronize()); hipLaunchKernelGGL(kernel<3>, dim3(1), dim3(1), 0, 0); CHECK(hipDeviceSynchronize()); } ``` ``` for i in $(seq 5); do clang -x hip --offload-arch=gfx908 -save-temps -fgpu-rdc -Ofast test_hip.cpp md5sum test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc llvm-dis test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc cp test_hip-hip-amdgcn-amd-amdhsa-gfx908.ll test_hip-hip-amdgcn-amd-amdhsa-gfx908.$i.ll done 75be8654e3a6c39e1e83f5c8b7dda364 test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc bde823a75c56e9af933be309d8e433f3 test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc e18bbc2e4768556c52864c716cba9c02 test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc e18bbc2e4768556c52864c716cba9c02 test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc 75be8654e3a6c39e1e83f5c8b7dda364 test_hip-hip-amdgcn-amd-amdhsa-gfx908.bc ``` The order of functions referenced in `__clang_gpu_used_external` changes each time: ``` diff --git a/test_hip-hip-amdgcn-amd-amdhsa-gfx908.1.ll b/test_hip-hip-amdgcn-amd-amdhsa-gfx908.2.ll index 91c0453..abd2b01 100644 --- a/test_hip-hip-amdgcn-amd-amdhsa-gfx908.1.ll +++ b/test_hip-hip-amdgcn-amd-amdhsa-gfx908.2.ll @@ -17,7 +17,7 @@ $_Z6kernelILi2EEvv = comdat any $_Z6kernelILi3EEvv = comdat any @.str = private unnamed_addr addrspace(4) constant [22 x i8] c"Hello from kernel %d\0A\00", align 1 -@__clang_gpu_used_external = internal addrspace(1) global [3 x ptr] [ptr @_Z6kernelILi1EEvv, ptr @_Z6kernelILi2EEvv, ptr @_Z6kernelILi3EEvv] +@__clang_gpu_used_external = internal addrspace(1) global [3 x ptr] [ptr @_Z6kernelILi2EEvv, ptr @_Z6kernelILi3EEvv, ptr @_Z6kernelILi1EEvv] @__oclc_ABI_version = weak_odr hidden local_unnamed_addr addrspace(4) constant i32 500 @llvm.compiler.used = appending addrspace(1) global [1 x ptr] [ptr addrspacecast (ptr addrspace(1) @__clang_gpu_used_external to ptr)], section "llvm.metadata" ``` The order is determined by the order the functions are stored in the `DenseSet` `CUDAExternalDeviceDeclODRUsedByHost `(which is non-deterministic). Hence changing `CUDAExternalDeviceDeclODRUsedByHost` from `llvm::DenseSet` to `llvm::SetVector` for a deterministic behaviour. --- Full diff: https://github.com/llvm/llvm-project/pull/101627.diff 2 Files Affected: - (modified) clang/include/clang/AST/ASTContext.h (+2-1) - (added) clang/test/CodeGenHIP/hip-checksum.cpp (+27) ``diff diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index ec8b32533eca8..9368a35818a92 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -34,6 +34,7 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" @@ -1193,7 +1194,7 @@ class ASTContext : public RefCountedBase { /// Keep track of CUDA/HIP external kernels or device variables ODR-used by /// host code. - llvm::DenseSet CUDAExternalDeviceDeclODRUsedByHost; + llvm::SetVector CUDAExternalDeviceDeclODRUsedByHost; /// Keep track of CUDA/HIP implicit host device functions used on device side /// in device compilation. diff --git a/clang/test/CodeGenHIP/hip-checksum.cpp b/clang/test/CodeGenHIP/hip-checksum.cpp new file mode 100644 index 0..e56bd6f33a97f --- /dev/null +++ b/clang/test/CodeGenHIP/hip-checksum.cpp @@ -0,0 +1,27 @@ +// RUN: x=$(
[clang] [clang] Fixing Clang HIP inconsistent order for template functions (PR #101627)
https://github.com/Ritanya-B-Bharadwaj edited https://github.com/llvm/llvm-project/pull/101627 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle parenthesized list in RemoveParentheses (PR #100852)
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/100852 >From f06f3ab5e59217348e72179c9581be338efa8789 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 26 Jul 2024 19:17:33 -0700 Subject: [PATCH] [clang-format] Handle parenthesized list in RemoveParentheses Also, reformat clang-format source to remove redundant parentheses enclosing single list items. Fixes #100768. --- clang/lib/Format/UnwrappedLineParser.cpp | 12 +++- clang/tools/clang-format/ClangFormat.cpp | 2 +- clang/unittests/Format/FormatTest.cpp| 4 clang/unittests/Format/MatchFilePathTest.cpp | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index d406a531a5c0c..3ebf8a44acc0f 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2534,6 +2534,7 @@ bool UnwrappedLineParser::parseBracedList(bool IsAngleBracket, bool IsEnum) { bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) { assert(FormatTok->is(tok::l_paren) && "'(' expected."); auto *LeftParen = FormatTok; + bool SeenComma = false; bool SeenEqual = false; bool MightBeFoldExpr = false; const bool MightBeStmtExpr = Tokens->peekNextToken()->is(tok::l_brace); @@ -2553,10 +2554,14 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) { const auto *Next = Tokens->peekNextToken(); const bool DoubleParens = Prev && Prev->is(tok::l_paren) && Next && Next->is(tok::r_paren); +const bool CommaSeparated = +!DoubleParens && Prev && Prev->isOneOf(tok::l_paren, tok::comma) && +Next && Next->isOneOf(tok::comma, tok::r_paren); const auto *PrevPrev = Prev ? Prev->getPreviousNonComment() : nullptr; const bool Blacklisted = PrevPrev && (PrevPrev->isOneOf(tok::kw___attribute, tok::kw_decltype) || + SeenComma || (SeenEqual && (PrevPrev->isOneOf(tok::kw_if, tok::kw_while) || PrevPrev->endsSequence(tok::kw_constexpr, tok::kw_if; @@ -2566,7 +2571,8 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) { (!NestedLambdas.empty() && !NestedLambdas.back())) && Prev && Prev->isOneOf(tok::kw_return, tok::kw_co_return) && Next && Next->is(tok::semi); -if ((DoubleParens && !Blacklisted) || ReturnParens) { +if ((DoubleParens && !Blacklisted) || (CommaSeparated && !SeenComma) || +ReturnParens) { LeftParen->Optional = true; FormatTok->Optional = true; } @@ -2595,6 +2601,10 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) { parseBracedList(); } break; +case tok::comma: + SeenComma = true; + nextToken(); + break; case tok::ellipsis: MightBeFoldExpr = true; nextToken(); diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index 6cba1267f3b0d..6582d73eae40e 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -364,7 +364,7 @@ emitReplacementWarnings(const Replacements &Replaces, StringRef AssumedFileName, : SourceMgr::DiagKind::DK_Warning, "code should be clang-formatted [-Wclang-format-violations]"); - Diag.print(nullptr, llvm::errs(), (ShowColors && !NoShowColors)); + Diag.print(nullptr, llvm::errs(), ShowColors && !NoShowColors); if (ErrorLimit && ++Errors >= ErrorLimit) break; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d7f81813835fa..2a754a29e81e7 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -27445,6 +27445,10 @@ TEST_F(FormatTest, RemoveParentheses) { verifyFormat("static_assert((std::is_constructible_v && ...));", "static_assert(((std::is_constructible_v && ...)));", Style); + verifyFormat("foo((a, b));", "foo(((a, b)));", Style); + verifyFormat("foo((a, b));", "foo(((a), b));", Style); + verifyFormat("foo((a, b));", "foo((a, (b)));", Style); + verifyFormat("foo((a, b, c));", "foo((a, ((b)), c));", Style); verifyFormat("return (0);", "return (((0)));", Style); verifyFormat("return (({ 0; }));", "return ((({ 0; })));", Style); verifyFormat("return ((... && std::is_convertible_v));", diff --git a/clang/unittests/Format/MatchFilePathTest.cpp b/clang/unittests/Format/MatchFilePathTest.cpp index f41cf7f971596..28f665635718e 100644 --- a/clang/unittests/Format/MatchFilePathTest.cpp +++ b/clang/unittests/Format/MatchFilePathTest.cpp @@ -53,7 +53,7 @@ TEST_F(MatchFilePathTest, Newline) { TEST_F(MatchFilePathTest, Star) { EXPECT_TRUE(match(std::string(50, 'a'), "*a*a*a*a*a*a*a*a*a*a"
[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
@@ -2196,6 +2196,58 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) { return V; } +static bool isDeclRefKnownNonNull(CodeGenFunction &CGF, const ValueDecl *D) { + return !D->isWeak(); +} + +static bool isLValueKnownNonNull(CodeGenFunction &CGF, const Expr *E) { + E = E->IgnoreParens(); + + if (auto *UO = dyn_cast(E)) { +if (UO->getOpcode() == UO_Deref) { + return CGF.isPointerKnownNonNull(UO->getSubExpr()); +} + } + + if (auto *DRE = dyn_cast(E)) { +return isDeclRefKnownNonNull(CGF, DRE->getDecl()); + } else if (auto *ME = dyn_cast(E)) { +if (isa(ME->getMemberDecl())) + return true; +return isDeclRefKnownNonNull(CGF, ME->getMemberDecl()); + } + + // Array subscripts? Anything else? + + return false; +} + +bool CodeGenFunction::isPointerKnownNonNull(const Expr *E) { + assert(E->getType()->isSignableType()); + + E = E->IgnoreParens(); + + if (isa(E)) +return true; + + if (auto *UO = dyn_cast(E)) { kovdan01 wrote: Nit ```suggestion if (const auto *UO = dyn_cast(E)) ``` https://github.com/llvm/llvm-project/pull/100830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
@@ -956,6 +956,25 @@ def err_ptrauth_indirect_goto_addrlabel_arithmetic : Error< "%select{subtraction|addition}0 of address-of-label expressions is not " "supported with ptrauth indirect gotos">; +// __ptrauth qualifier +def err_ptrauth_qualifier_invalid : Error< + "%select{return types|parameter types|properties}2 may not be qualified with %select{__ptrauth|__ptrauth_restricted_intptr}1; type is %0">; +def err_ptrauth_qualifier_cast : Error< + "cast types may not be qualified with __ptrauth; type is %0">; +def err_ptrauth_qualifier_nonpointer : Error< + "__ptrauth qualifier may only be applied to pointer types; type here is %0">; +def err_ptrauth_qualifier_redundant : Error< + "type %0 is already %1-qualified">; +def err_ptrauth_qualifier_bad_arg_count : Error< kovdan01 wrote: Is there a test for this error message? https://github.com/llvm/llvm-project/pull/100830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
@@ -166,6 +193,92 @@ CGPointerAuthInfo CodeGenModule::getPointerAuthInfoForType(QualType T) { return ::getPointerAuthInfoForType(*this, T); } +static std::pair +emitLoadOfOrigPointerRValue(CodeGenFunction &CGF, const LValue &LV, +SourceLocation Loc) { + auto *Value = CGF.EmitLoadOfScalar(LV, Loc); + CGPointerAuthInfo AuthInfo; + if (PointerAuthQualifier PtrAuth = LV.getQuals().getPointerAuth()) { kovdan01 wrote: Nit: you can probably omit braces in this if/else chain https://github.com/llvm/llvm-project/pull/100830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
@@ -2190,6 +2198,15 @@ RValue CodeGenFunction::EmitLoadOfAnyValue(LValue LV, AggValueSlot Slot, /// method emits the address of the lvalue, then loads the result as an rvalue, /// returning the rvalue. RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, SourceLocation Loc) { + // Load from __ptrauth. + if (PointerAuthQualifier PtrAuth = LV.getQuals().getPointerAuth()) { +LV.getQuals().removePointerAuth(); +auto value = EmitLoadOfLValue(LV, Loc).getScalarVal(); kovdan01 wrote: Nit ```suggestion auto Value = EmitLoadOfLValue(LV, Loc).getScalarVal(); ``` https://github.com/llvm/llvm-project/pull/100830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
@@ -2196,6 +2196,58 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) { return V; } +static bool isDeclRefKnownNonNull(CodeGenFunction &CGF, const ValueDecl *D) { + return !D->isWeak(); +} + +static bool isLValueKnownNonNull(CodeGenFunction &CGF, const Expr *E) { + E = E->IgnoreParens(); + + if (auto *UO = dyn_cast(E)) { +if (UO->getOpcode() == UO_Deref) { + return CGF.isPointerKnownNonNull(UO->getSubExpr()); +} + } + + if (auto *DRE = dyn_cast(E)) { +return isDeclRefKnownNonNull(CGF, DRE->getDecl()); + } else if (auto *ME = dyn_cast(E)) { +if (isa(ME->getMemberDecl())) + return true; +return isDeclRefKnownNonNull(CGF, ME->getMemberDecl()); + } + + // Array subscripts? Anything else? + + return false; +} + +bool CodeGenFunction::isPointerKnownNonNull(const Expr *E) { + assert(E->getType()->isSignableType()); + + E = E->IgnoreParens(); + + if (isa(E)) +return true; + + if (auto *UO = dyn_cast(E)) { kovdan01 wrote: Nit: you can probably omit braces in this if and in the if inside. https://github.com/llvm/llvm-project/pull/100830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
@@ -166,6 +193,92 @@ CGPointerAuthInfo CodeGenModule::getPointerAuthInfoForType(QualType T) { return ::getPointerAuthInfoForType(*this, T); } +static std::pair +emitLoadOfOrigPointerRValue(CodeGenFunction &CGF, const LValue &LV, +SourceLocation Loc) { + auto *Value = CGF.EmitLoadOfScalar(LV, Loc); + CGPointerAuthInfo AuthInfo; + if (PointerAuthQualifier PtrAuth = LV.getQuals().getPointerAuth()) { +AuthInfo = CGF.EmitPointerAuthInfo(PtrAuth, LV.getAddress()); + } else { +AuthInfo = getPointerAuthInfoForType(CGF.CGM, LV.getType()); + } + return {Value, AuthInfo}; +} + +/// Retrieve a pointer rvalue and its ptrauth info. When possible, avoid +/// needlessly resigning the pointer. +std::pair +CodeGenFunction::EmitOrigPointerRValue(const Expr *E) { + assert(E->getType()->isSignableType()); + + E = E->IgnoreParens(); + if (auto *Load = dyn_cast(E)) { +if (Load->getCastKind() == CK_LValueToRValue) { + E = Load->getSubExpr()->IgnoreParens(); + + // We're semantically required to not emit loads of certain DREs naively. + if (auto *RefExpr = dyn_cast(const_cast(E))) { kovdan01 wrote: I do not think that having a `const_cast` here is a good idea. I was able to transform this into ```suggestion if (const auto *RefExpr = dyn_cast(E)) { ``` by introducing the following changes: - `CodeGenFunction::tryEmitAsConstant`: add `const` qualifier for `DeclRefExpr *` argument (and also add `const` inside the function where needed) - `getReferenceLValue`: add `const` qualifier for `Expr *` argument https://github.com/llvm/llvm-project/pull/100830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
@@ -2196,6 +2196,58 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) { return V; } +static bool isDeclRefKnownNonNull(CodeGenFunction &CGF, const ValueDecl *D) { + return !D->isWeak(); +} + +static bool isLValueKnownNonNull(CodeGenFunction &CGF, const Expr *E) { + E = E->IgnoreParens(); + + if (auto *UO = dyn_cast(E)) { +if (UO->getOpcode() == UO_Deref) { + return CGF.isPointerKnownNonNull(UO->getSubExpr()); +} + } + + if (auto *DRE = dyn_cast(E)) { +return isDeclRefKnownNonNull(CGF, DRE->getDecl()); + } else if (auto *ME = dyn_cast(E)) { +if (isa(ME->getMemberDecl())) + return true; +return isDeclRefKnownNonNull(CGF, ME->getMemberDecl()); + } + + // Array subscripts? Anything else? + + return false; +} + +bool CodeGenFunction::isPointerKnownNonNull(const Expr *E) { + assert(E->getType()->isSignableType()); + + E = E->IgnoreParens(); + + if (isa(E)) +return true; + + if (auto *UO = dyn_cast(E)) { +if (UO->getOpcode() == UO_AddrOf) { + return isLValueKnownNonNull(*this, UO->getSubExpr()); +} + } + + if (auto *CE = dyn_cast(E)) { kovdan01 wrote: Nit ```suggestion if (const auto *CE = dyn_cast(E)) { ``` https://github.com/llvm/llvm-project/pull/100830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
@@ -1460,6 +1467,12 @@ class QualType { return getQualifiers().getPointerAuth(); } + bool hasAddressDiscriminatedPointerAuth() const { +if (PointerAuthQualifier ptrauth = getPointerAuth()) kovdan01 wrote: Nit ```suggestion if (PointerAuthQualifier PtrAuth = getPointerAuth()) ``` https://github.com/llvm/llvm-project/pull/100830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
@@ -166,6 +193,92 @@ CGPointerAuthInfo CodeGenModule::getPointerAuthInfoForType(QualType T) { return ::getPointerAuthInfoForType(*this, T); } +static std::pair +emitLoadOfOrigPointerRValue(CodeGenFunction &CGF, const LValue &LV, +SourceLocation Loc) { + auto *Value = CGF.EmitLoadOfScalar(LV, Loc); + CGPointerAuthInfo AuthInfo; + if (PointerAuthQualifier PtrAuth = LV.getQuals().getPointerAuth()) { +AuthInfo = CGF.EmitPointerAuthInfo(PtrAuth, LV.getAddress()); + } else { +AuthInfo = getPointerAuthInfoForType(CGF.CGM, LV.getType()); + } + return {Value, AuthInfo}; +} + +/// Retrieve a pointer rvalue and its ptrauth info. When possible, avoid +/// needlessly resigning the pointer. +std::pair +CodeGenFunction::EmitOrigPointerRValue(const Expr *E) { + assert(E->getType()->isSignableType()); + + E = E->IgnoreParens(); + if (auto *Load = dyn_cast(E)) { kovdan01 wrote: Nit ```suggestion if (const auto *Load = dyn_cast(E)) { ``` https://github.com/llvm/llvm-project/pull/100830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
@@ -166,6 +193,92 @@ CGPointerAuthInfo CodeGenModule::getPointerAuthInfoForType(QualType T) { return ::getPointerAuthInfoForType(*this, T); } +static std::pair +emitLoadOfOrigPointerRValue(CodeGenFunction &CGF, const LValue &LV, +SourceLocation Loc) { + auto *Value = CGF.EmitLoadOfScalar(LV, Loc); + CGPointerAuthInfo AuthInfo; + if (PointerAuthQualifier PtrAuth = LV.getQuals().getPointerAuth()) { +AuthInfo = CGF.EmitPointerAuthInfo(PtrAuth, LV.getAddress()); + } else { +AuthInfo = getPointerAuthInfoForType(CGF.CGM, LV.getType()); + } + return {Value, AuthInfo}; +} + +/// Retrieve a pointer rvalue and its ptrauth info. When possible, avoid +/// needlessly resigning the pointer. +std::pair +CodeGenFunction::EmitOrigPointerRValue(const Expr *E) { + assert(E->getType()->isSignableType()); + + E = E->IgnoreParens(); + if (auto *Load = dyn_cast(E)) { +if (Load->getCastKind() == CK_LValueToRValue) { + E = Load->getSubExpr()->IgnoreParens(); + + // We're semantically required to not emit loads of certain DREs naively. + if (auto *RefExpr = dyn_cast(const_cast(E))) { +if (auto Result = tryEmitAsConstant(RefExpr)) { + // Fold away a use of an intermediate variable. + if (!Result.isReference()) +return {Result.getValue(), +getPointerAuthInfoForType(CGM, RefExpr->getType())}; + + // Fold away a use of an intermediate reference. + auto LV = Result.getReferenceLValue(*this, RefExpr); + return emitLoadOfOrigPointerRValue(*this, LV, RefExpr->getLocation()); +} + } + + // Otherwise, load and use the pointer + auto LV = EmitCheckedLValue(E, CodeGenFunction::TCK_Load); + return emitLoadOfOrigPointerRValue(*this, LV, E->getExprLoc()); +} + } + + // Fallback: just use the normal rules for the type. + auto *Value = EmitScalarExpr(E); + return {Value, getPointerAuthInfoForType(CGM, E->getType())}; +} + +llvm::Value * +CodeGenFunction::EmitPointerAuthQualify(PointerAuthQualifier DestQualifier, +const Expr *E, +Address DestStorageAddress) { + assert(DestQualifier); + + auto Src = EmitOrigPointerRValue(E); + auto *Value = Src.first; + auto CurAuthInfo = Src.second; kovdan01 wrote: Nit: you could probably just you structured bindings https://github.com/llvm/llvm-project/pull/100830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Implement Clang Builtins for XCValu Extension in CV32E40P (PR #100684)
@@ -59,16 +59,26 @@ let TargetPrefix = "riscv" in { [IntrNoMem, IntrWillReturn, IntrSpeculatable, ImmArg>, ImmArg>]>; + def int_riscv_cv_alu_slet : ScalarCoreVAluGprGprIntrinsic; jeremybennett wrote: Hi @topperc There are a few things going on here. 1. The naming of the corresponding instructions in the CORE-V ISA extension was changed from `slet` to `sle`, and `sletu` to `sleu`. The CORE-V [standard for builtins](https://github.com/openhwgroup/core-v-sw/blob/master/specifications/corev-builtin-spec.md) has not yet been updated to reflect this change. This needs to be fixed through OpenHW group's standardization processes (@PaoloS02 is leading this inside OpenHW Group). 2. These instructions only exist for "less than or equal", there are no equivalents for other comparison predicates, hence just these two builtins mapping to the instructions. 3. LLVM and GCC for CORE-V are intended to be equivalent, and in GCC, having the builtin to generate the instruction is more efficient than using inline assembler. First the dataflow through the instruction is explicit, secondly the pattern for the functionality is exposed to GCC, potentially allowing the instruction to be generated automatically in other circumstances. So in summary i) it's there because the CORE-V standard for builtins says it should be and ii) it's there to match GCC behavior. Hope this is helpful. https://github.com/llvm/llvm-project/pull/100684 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [RISCV] Support new groupid/bitmask for cpu_model (PR #101632)
https://github.com/BeMg created https://github.com/llvm/llvm-project/pull/101632 1. Add the new extension GroupID/Bitmask with latest hwprobe key. 2. Update the `initRISCVFeature ` 3. Update `EmitRISCVCpuSupports` due to not only group0 now. >From 91ebb0568f28015006e3443221ae51f92c159dfb Mon Sep 17 00:00:00 2001 From: Piyou Chen Date: Fri, 2 Aug 2024 01:07:04 -0700 Subject: [PATCH] [RISCV] Suuport new bitmask for cpu_model --- clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/test/CodeGen/builtin-cpu-supports.c | 50 ++ compiler-rt/lib/builtins/cpu_model/riscv.c| 50 +- llvm/include/llvm/TargetParser/RISCVISAInfo.h | 6 +- llvm/lib/TargetParser/RISCVISAInfo.cpp| 69 --- 5 files changed, 135 insertions(+), 43 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 0c2ee446aa303..c903064b12cba 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -14391,9 +14391,10 @@ Value *CodeGenFunction::EmitRISCVCpuSupports(const CallExpr *E) { }; int BitPos = RISCVISAInfo::getRISCVFeaturesBitPosition(FeatureStr); + int GroupID = RISCVISAInfo::getRISCVFeaturesGroupID(FeatureStr); assert(BitPos != -1 && "validation should have rejected this feature"); Value *MaskV = Builder.getInt64(1ULL << BitPos); - Value *Bitset = Builder.CreateAnd(LoadFeatureBit(0), MaskV); + Value *Bitset = Builder.CreateAnd(LoadFeatureBit(GroupID), MaskV); return Builder.CreateICmpEQ(Bitset, MaskV); } diff --git a/clang/test/CodeGen/builtin-cpu-supports.c b/clang/test/CodeGen/builtin-cpu-supports.c index 92c407653e660..461e49d0fc7fa 100644 --- a/clang/test/CodeGen/builtin-cpu-supports.c +++ b/clang/test/CodeGen/builtin-cpu-supports.c @@ -270,20 +270,30 @@ int test_ppc(int a) { // CHECK-RV32-NEXT:[[TMP6:%.*]] = load i64, ptr getelementptr inbounds ({ i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 0), align 8 // CHECK-RV32-NEXT:[[TMP7:%.*]] = and i64 [[TMP6]], 2097152 // CHECK-RV32-NEXT:[[TMP8:%.*]] = icmp eq i64 [[TMP7]], 2097152 -// CHECK-RV32-NEXT:br i1 [[TMP8]], label [[IF_THEN3:%.*]], label [[IF_END:%.*]] +// CHECK-RV32-NEXT:br i1 [[TMP8]], label [[IF_THEN3:%.*]], label [[IF_ELSE4:%.*]] // CHECK-RV32: if.then3: // CHECK-RV32-NEXT:store i32 11, ptr [[RETVAL]], align 4 // CHECK-RV32-NEXT:br label [[RETURN]] +// CHECK-RV32: if.else4: +// CHECK-RV32-NEXT:[[TMP9:%.*]] = load i64, ptr getelementptr inbounds ({ i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 1), align 8 +// CHECK-RV32-NEXT:[[TMP10:%.*]] = and i64 [[TMP9]], 8 +// CHECK-RV32-NEXT:[[TMP11:%.*]] = icmp eq i64 [[TMP10]], 8 +// CHECK-RV32-NEXT:br i1 [[TMP11]], label [[IF_THEN5:%.*]], label [[IF_END:%.*]] +// CHECK-RV32: if.then5: +// CHECK-RV32-NEXT:store i32 11, ptr [[RETVAL]], align 4 +// CHECK-RV32-NEXT:br label [[RETURN]] // CHECK-RV32: if.end: -// CHECK-RV32-NEXT:br label [[IF_END4:%.*]] -// CHECK-RV32: if.end4: -// CHECK-RV32-NEXT:br label [[IF_END5:%.*]] -// CHECK-RV32: if.end5: +// CHECK-RV32-NEXT:br label [[IF_END6:%.*]] +// CHECK-RV32: if.end6: +// CHECK-RV32-NEXT:br label [[IF_END7:%.*]] +// CHECK-RV32: if.end7: +// CHECK-RV32-NEXT:br label [[IF_END8:%.*]] +// CHECK-RV32: if.end8: // CHECK-RV32-NEXT:store i32 0, ptr [[RETVAL]], align 4 // CHECK-RV32-NEXT:br label [[RETURN]] // CHECK-RV32: return: -// CHECK-RV32-NEXT:[[TMP9:%.*]] = load i32, ptr [[RETVAL]], align 4 -// CHECK-RV32-NEXT:ret i32 [[TMP9]] +// CHECK-RV32-NEXT:[[TMP12:%.*]] = load i32, ptr [[RETVAL]], align 4 +// CHECK-RV32-NEXT:ret i32 [[TMP12]] // // CHECK-RV64-LABEL: define dso_local signext i32 @test_riscv( // CHECK-RV64-SAME: i32 noundef signext [[A:%.*]]) #[[ATTR0:[0-9]+]] { @@ -311,20 +321,30 @@ int test_ppc(int a) { // CHECK-RV64-NEXT:[[TMP6:%.*]] = load i64, ptr getelementptr inbounds ({ i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 0), align 8 // CHECK-RV64-NEXT:[[TMP7:%.*]] = and i64 [[TMP6]], 2097152 // CHECK-RV64-NEXT:[[TMP8:%.*]] = icmp eq i64 [[TMP7]], 2097152 -// CHECK-RV64-NEXT:br i1 [[TMP8]], label [[IF_THEN3:%.*]], label [[IF_END:%.*]] +// CHECK-RV64-NEXT:br i1 [[TMP8]], label [[IF_THEN3:%.*]], label [[IF_ELSE4:%.*]] // CHECK-RV64: if.then3: // CHECK-RV64-NEXT:store i32 11, ptr [[RETVAL]], align 4 // CHECK-RV64-NEXT:br label [[RETURN]] +// CHECK-RV64: if.else4: +// CHECK-RV64-NEXT:[[TMP9:%.*]] = load i64, ptr getelementptr inbounds ({ i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 1), align 8 +// CHECK-RV64-NEXT:[[TMP10:%.*]] = and i64 [[TMP9]], 8 +// CHECK-RV64-NEXT:[[TMP11:%.*]] = icmp eq i64 [[TMP10]], 8 +// CHECK-RV64-NEXT:br i1 [[TMP11]], label [[IF_THEN5:%.*]], label [[IF_END:%.*]] +// CHECK-RV64: if.then5: +// CHECK-R
[clang] [compiler-rt] [llvm] [RISCV] Support new groupid/bitmask for cpu_model (PR #101632)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Piyou Chen (BeMg) Changes 1. Add the new extension GroupID/Bitmask with latest hwprobe key. 2. Update the `initRISCVFeature ` 3. Update `EmitRISCVCpuSupports` due to not only group0 now. --- Full diff: https://github.com/llvm/llvm-project/pull/101632.diff 5 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+2-1) - (modified) clang/test/CodeGen/builtin-cpu-supports.c (+36-14) - (modified) compiler-rt/lib/builtins/cpu_model/riscv.c (+49-1) - (modified) llvm/include/llvm/TargetParser/RISCVISAInfo.h (+5-1) - (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+43-26) ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 0c2ee446aa303..c903064b12cba 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -14391,9 +14391,10 @@ Value *CodeGenFunction::EmitRISCVCpuSupports(const CallExpr *E) { }; int BitPos = RISCVISAInfo::getRISCVFeaturesBitPosition(FeatureStr); + int GroupID = RISCVISAInfo::getRISCVFeaturesGroupID(FeatureStr); assert(BitPos != -1 && "validation should have rejected this feature"); Value *MaskV = Builder.getInt64(1ULL << BitPos); - Value *Bitset = Builder.CreateAnd(LoadFeatureBit(0), MaskV); + Value *Bitset = Builder.CreateAnd(LoadFeatureBit(GroupID), MaskV); return Builder.CreateICmpEQ(Bitset, MaskV); } diff --git a/clang/test/CodeGen/builtin-cpu-supports.c b/clang/test/CodeGen/builtin-cpu-supports.c index 92c407653e660..461e49d0fc7fa 100644 --- a/clang/test/CodeGen/builtin-cpu-supports.c +++ b/clang/test/CodeGen/builtin-cpu-supports.c @@ -270,20 +270,30 @@ int test_ppc(int a) { // CHECK-RV32-NEXT:[[TMP6:%.*]] = load i64, ptr getelementptr inbounds ({ i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 0), align 8 // CHECK-RV32-NEXT:[[TMP7:%.*]] = and i64 [[TMP6]], 2097152 // CHECK-RV32-NEXT:[[TMP8:%.*]] = icmp eq i64 [[TMP7]], 2097152 -// CHECK-RV32-NEXT:br i1 [[TMP8]], label [[IF_THEN3:%.*]], label [[IF_END:%.*]] +// CHECK-RV32-NEXT:br i1 [[TMP8]], label [[IF_THEN3:%.*]], label [[IF_ELSE4:%.*]] // CHECK-RV32: if.then3: // CHECK-RV32-NEXT:store i32 11, ptr [[RETVAL]], align 4 // CHECK-RV32-NEXT:br label [[RETURN]] +// CHECK-RV32: if.else4: +// CHECK-RV32-NEXT:[[TMP9:%.*]] = load i64, ptr getelementptr inbounds ({ i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 1), align 8 +// CHECK-RV32-NEXT:[[TMP10:%.*]] = and i64 [[TMP9]], 8 +// CHECK-RV32-NEXT:[[TMP11:%.*]] = icmp eq i64 [[TMP10]], 8 +// CHECK-RV32-NEXT:br i1 [[TMP11]], label [[IF_THEN5:%.*]], label [[IF_END:%.*]] +// CHECK-RV32: if.then5: +// CHECK-RV32-NEXT:store i32 11, ptr [[RETVAL]], align 4 +// CHECK-RV32-NEXT:br label [[RETURN]] // CHECK-RV32: if.end: -// CHECK-RV32-NEXT:br label [[IF_END4:%.*]] -// CHECK-RV32: if.end4: -// CHECK-RV32-NEXT:br label [[IF_END5:%.*]] -// CHECK-RV32: if.end5: +// CHECK-RV32-NEXT:br label [[IF_END6:%.*]] +// CHECK-RV32: if.end6: +// CHECK-RV32-NEXT:br label [[IF_END7:%.*]] +// CHECK-RV32: if.end7: +// CHECK-RV32-NEXT:br label [[IF_END8:%.*]] +// CHECK-RV32: if.end8: // CHECK-RV32-NEXT:store i32 0, ptr [[RETVAL]], align 4 // CHECK-RV32-NEXT:br label [[RETURN]] // CHECK-RV32: return: -// CHECK-RV32-NEXT:[[TMP9:%.*]] = load i32, ptr [[RETVAL]], align 4 -// CHECK-RV32-NEXT:ret i32 [[TMP9]] +// CHECK-RV32-NEXT:[[TMP12:%.*]] = load i32, ptr [[RETVAL]], align 4 +// CHECK-RV32-NEXT:ret i32 [[TMP12]] // // CHECK-RV64-LABEL: define dso_local signext i32 @test_riscv( // CHECK-RV64-SAME: i32 noundef signext [[A:%.*]]) #[[ATTR0:[0-9]+]] { @@ -311,20 +321,30 @@ int test_ppc(int a) { // CHECK-RV64-NEXT:[[TMP6:%.*]] = load i64, ptr getelementptr inbounds ({ i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 0), align 8 // CHECK-RV64-NEXT:[[TMP7:%.*]] = and i64 [[TMP6]], 2097152 // CHECK-RV64-NEXT:[[TMP8:%.*]] = icmp eq i64 [[TMP7]], 2097152 -// CHECK-RV64-NEXT:br i1 [[TMP8]], label [[IF_THEN3:%.*]], label [[IF_END:%.*]] +// CHECK-RV64-NEXT:br i1 [[TMP8]], label [[IF_THEN3:%.*]], label [[IF_ELSE4:%.*]] // CHECK-RV64: if.then3: // CHECK-RV64-NEXT:store i32 11, ptr [[RETVAL]], align 4 // CHECK-RV64-NEXT:br label [[RETURN]] +// CHECK-RV64: if.else4: +// CHECK-RV64-NEXT:[[TMP9:%.*]] = load i64, ptr getelementptr inbounds ({ i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 1), align 8 +// CHECK-RV64-NEXT:[[TMP10:%.*]] = and i64 [[TMP9]], 8 +// CHECK-RV64-NEXT:[[TMP11:%.*]] = icmp eq i64 [[TMP10]], 8 +// CHECK-RV64-NEXT:br i1 [[TMP11]], label [[IF_THEN5:%.*]], label [[IF_END:%.*]] +// CHECK-RV64: if.then5: +// CHECK-RV64-NEXT:store i32 11, ptr [[RETVAL]], align 4 +// CHECK-RV64-NEXT:br label [[RETURN]] // CHECK-RV64: if.end: -// CHE
[clang] [compiler-rt] [llvm] [RISCV] Support new groupid/bitmask for cpu_model (PR #101632)
https://github.com/BeMg edited https://github.com/llvm/llvm-project/pull/101632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Support `vrgather` and `vcompress` for `zvfhmin` and `zvfbfmin` (PR #101633)
https://github.com/4vtomat edited https://github.com/llvm/llvm-project/pull/101633 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86_64] Fix empty field error in vaarg of C++. (PR #90389)
https://github.com/CoTinker closed https://github.com/llvm/llvm-project/pull/90389 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle parenthesized list in RemoveParentheses (PR #100852)
llvmbot wrote: Failed to cherry-pick: 9fa17fea3c2edb5903250b0da8f67861b81527b3 https://github.com/llvm/llvm-project/actions/runs/10212708496 Please manually backport the fix and push it to your github fork. Once this is done, please create a [pull request](https://github.com/llvm/llvm-project/compare) https://github.com/llvm/llvm-project/pull/100852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2351 `void{}` (PR #78060)
MitalAshok wrote: Ping @cor3ntin (This missed Clang 19 but could you merge it for Clang 20?) https://github.com/llvm/llvm-project/pull/78060 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86_64] Fix empty field error in vaarg of C++. (PR #101639)
https://github.com/CoTinker created https://github.com/llvm/llvm-project/pull/101639 Such struct types: ``` struct { struct{} a; long long b; }; stuct { struct{} a; double b; }; ``` For such structures, Lo is NoClass and Hi is Integer/SSE. And when this structure argument is passed, the high part is passed at offset 8 in memory. So we should do special handling for these types in EmitVAArg.Fix https://github.com/llvm/llvm-project/issues/79790 and https://github.com/llvm/llvm-project/issues/86371. >From fa8f47190badba495d4ca9c90f0bbeba6ac545a3 Mon Sep 17 00:00:00 2001 From: Longsheng Mou Date: Fri, 2 Aug 2024 16:36:31 +0800 Subject: [PATCH] [X86_64] Fix empty field error in vaarg of C++. Such struct types: ``` struct { struct{} a; long long b; }; stuct { struct{} a; double b; }; ``` For such structures, Lo is NoClass and Hi is Integer/SSE. And when this structure argument is passed, the high part is passed at offset 8 in memory. So we should do special handling for these types in EmitVAArg. --- clang/lib/CodeGen/Targets/X86.cpp | 30 +++- clang/test/CodeGenCXX/x86_64-vaarg.cpp | 211 - 2 files changed, 227 insertions(+), 14 deletions(-) diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp index 26ff4e4ac0a3b..c7e84f70ae15f 100644 --- a/clang/lib/CodeGen/Targets/X86.cpp +++ b/clang/lib/CodeGen/Targets/X86.cpp @@ -3124,26 +3124,40 @@ RValue X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1)); RegAddr = Tmp.withElementType(LTy); - } else if (neededInt) { -RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, gp_offset), - LTy, CharUnits::fromQuantity(8)); - + } else if (neededInt || neededSSE == 1) { // Copy to a temporary if necessary to ensure the appropriate alignment. auto TInfo = getContext().getTypeInfoInChars(Ty); uint64_t TySize = TInfo.Width.getQuantity(); CharUnits TyAlign = TInfo.Align; +llvm::Value *GpOrFpOffset = neededInt ? gp_offset : fp_offset; +uint64_t Alignment = neededInt ? 8 : 16; +if (auto Offset = AI.getDirectOffset()) { + Address Tmp = CGF.CreateMemTemp(Ty); + llvm::Type *TyHi = AI.getCoerceToType(); + llvm::Value *Addr = + CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, GpOrFpOffset); + llvm::Value *Src = CGF.Builder.CreateAlignedLoad(TyHi, Addr, TyAlign); + llvm::Value *PtrOffset = llvm::ConstantInt::get(CGF.Int32Ty, Offset); + Address Dst = Address( + CGF.Builder.CreateGEP(CGF.Int8Ty, Tmp.getBasePointer(), PtrOffset), + LTy, TyAlign); + CGF.Builder.CreateStore(Src, Dst); + RegAddr = Tmp.withElementType(LTy); +} else { + RegAddr = + Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, GpOrFpOffset), + LTy, CharUnits::fromQuantity(Alignment)); +} + // Copy into a temporary if the type is more aligned than the // register save area. -if (TyAlign.getQuantity() > 8) { +if (neededInt && TyAlign.getQuantity() > 8) { Address Tmp = CGF.CreateMemTemp(Ty); CGF.Builder.CreateMemCpy(Tmp, RegAddr, TySize, false); RegAddr = Tmp; } - } else if (neededSSE == 1) { -RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, fp_offset), - LTy, CharUnits::fromQuantity(16)); } else { assert(neededSSE == 2 && "Invalid number of needed registers!"); // SSE registers are spaced 16 bytes apart in the register save diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp b/clang/test/CodeGenCXX/x86_64-vaarg.cpp index c4616a97e2055..1703b74ad10a2 100644 --- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp +++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp @@ -29,6 +29,7 @@ typedef struct { // CHECK-NEXT:[[RETVAL:%.*]] = alloca [[STRUCT_S1:%.*]], align 8 // CHECK-NEXT:[[Z_ADDR:%.*]] = alloca i32, align 4 // CHECK-NEXT:[[LIST:%.*]] = alloca [1 x %struct.__va_list_tag], align 16 +// CHECK-NEXT:[[TMP:%.*]] = alloca [[STRUCT_S1]], align 8 // CHECK-NEXT:store i32 [[Z:%.*]], ptr [[Z_ADDR]], align 4 // CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0 // CHECK-NEXT:call void @llvm.va_start.p0(ptr [[ARRAYDECAY]]) @@ -41,8 +42,11 @@ typedef struct { // CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds [[STRUCT___VA_LIST_TAG]], ptr [[ARRAYDECAY1]], i32 0, i32 3 // CHECK-NEXT:[[REG_SAVE_AREA:%.*]] = load ptr, ptr [[TMP0]], align 16 // CHECK-NEXT:[[TMP1:%.*]] = getelementptr i8, ptr [[REG_SAVE_AREA]], i32 [[FP_OFFSET]] -// CHECK-NEXT:[[TMP2:%.*]] = add i32 [[FP_OFFSET]], 16 -// CHECK-NEXT:store i32 [[TMP2]], ptr [[FP_OFFSET_P]], align 4 +// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[TMP1]], align 8 +// CHECK-NEXT:[[TMP3:%.*]] = getelementptr i8, ptr [[TMP]], i32 8 +//
[clang] [X86_64] Fix empty field error in vaarg of C++. (PR #101639)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-x86 Author: Longsheng Mou (CoTinker) Changes Such struct types: ``` struct { struct{} a; long long b; }; stuct { struct{} a; double b; }; ``` For such structures, Lo is NoClass and Hi is Integer/SSE. And when this structure argument is passed, the high part is passed at offset 8 in memory. So we should do special handling for these types in EmitVAArg.Fix https://github.com/llvm/llvm-project/issues/79790 and https://github.com/llvm/llvm-project/issues/86371. --- Full diff: https://github.com/llvm/llvm-project/pull/101639.diff 2 Files Affected: - (modified) clang/lib/CodeGen/Targets/X86.cpp (+22-8) - (modified) clang/test/CodeGenCXX/x86_64-vaarg.cpp (+205-6) ``diff diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp index 26ff4e4ac0a3b..c7e84f70ae15f 100644 --- a/clang/lib/CodeGen/Targets/X86.cpp +++ b/clang/lib/CodeGen/Targets/X86.cpp @@ -3124,26 +3124,40 @@ RValue X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1)); RegAddr = Tmp.withElementType(LTy); - } else if (neededInt) { -RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, gp_offset), - LTy, CharUnits::fromQuantity(8)); - + } else if (neededInt || neededSSE == 1) { // Copy to a temporary if necessary to ensure the appropriate alignment. auto TInfo = getContext().getTypeInfoInChars(Ty); uint64_t TySize = TInfo.Width.getQuantity(); CharUnits TyAlign = TInfo.Align; +llvm::Value *GpOrFpOffset = neededInt ? gp_offset : fp_offset; +uint64_t Alignment = neededInt ? 8 : 16; +if (auto Offset = AI.getDirectOffset()) { + Address Tmp = CGF.CreateMemTemp(Ty); + llvm::Type *TyHi = AI.getCoerceToType(); + llvm::Value *Addr = + CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, GpOrFpOffset); + llvm::Value *Src = CGF.Builder.CreateAlignedLoad(TyHi, Addr, TyAlign); + llvm::Value *PtrOffset = llvm::ConstantInt::get(CGF.Int32Ty, Offset); + Address Dst = Address( + CGF.Builder.CreateGEP(CGF.Int8Ty, Tmp.getBasePointer(), PtrOffset), + LTy, TyAlign); + CGF.Builder.CreateStore(Src, Dst); + RegAddr = Tmp.withElementType(LTy); +} else { + RegAddr = + Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, GpOrFpOffset), + LTy, CharUnits::fromQuantity(Alignment)); +} + // Copy into a temporary if the type is more aligned than the // register save area. -if (TyAlign.getQuantity() > 8) { +if (neededInt && TyAlign.getQuantity() > 8) { Address Tmp = CGF.CreateMemTemp(Ty); CGF.Builder.CreateMemCpy(Tmp, RegAddr, TySize, false); RegAddr = Tmp; } - } else if (neededSSE == 1) { -RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, fp_offset), - LTy, CharUnits::fromQuantity(16)); } else { assert(neededSSE == 2 && "Invalid number of needed registers!"); // SSE registers are spaced 16 bytes apart in the register save diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp b/clang/test/CodeGenCXX/x86_64-vaarg.cpp index c4616a97e2055..1703b74ad10a2 100644 --- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp +++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp @@ -29,6 +29,7 @@ typedef struct { // CHECK-NEXT:[[RETVAL:%.*]] = alloca [[STRUCT_S1:%.*]], align 8 // CHECK-NEXT:[[Z_ADDR:%.*]] = alloca i32, align 4 // CHECK-NEXT:[[LIST:%.*]] = alloca [1 x %struct.__va_list_tag], align 16 +// CHECK-NEXT:[[TMP:%.*]] = alloca [[STRUCT_S1]], align 8 // CHECK-NEXT:store i32 [[Z:%.*]], ptr [[Z_ADDR]], align 4 // CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0 // CHECK-NEXT:call void @llvm.va_start.p0(ptr [[ARRAYDECAY]]) @@ -41,8 +42,11 @@ typedef struct { // CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds [[STRUCT___VA_LIST_TAG]], ptr [[ARRAYDECAY1]], i32 0, i32 3 // CHECK-NEXT:[[REG_SAVE_AREA:%.*]] = load ptr, ptr [[TMP0]], align 16 // CHECK-NEXT:[[TMP1:%.*]] = getelementptr i8, ptr [[REG_SAVE_AREA]], i32 [[FP_OFFSET]] -// CHECK-NEXT:[[TMP2:%.*]] = add i32 [[FP_OFFSET]], 16 -// CHECK-NEXT:store i32 [[TMP2]], ptr [[FP_OFFSET_P]], align 4 +// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[TMP1]], align 8 +// CHECK-NEXT:[[TMP3:%.*]] = getelementptr i8, ptr [[TMP]], i32 8 +// CHECK-NEXT:store double [[TMP2]], ptr [[TMP3]], align 8 +// CHECK-NEXT:[[TMP4:%.*]] = add i32 [[FP_OFFSET]], 16 +// CHECK-NEXT:store i32 [[TMP4]], ptr [[FP_OFFSET_P]], align 4 // CHECK-NEXT:br label [[VAARG_END:%.*]] // CHECK: vaarg.in_mem: // CHECK-NEXT:[[OVERFLOW_ARG_AREA_P:%.*]] = getelementptr inbounds [[STRUCT___VA_LIST_TAG]], ptr [[ARRAYDECAY1]], i32 0, i32 2 @@ -51,14 +55,209 @@ typedef struc
[clang] [clang][dataflow] Fix casting in `ChromiumCheckModel`. (PR #101640)
https://github.com/Pask00 created https://github.com/llvm/llvm-project/pull/101640 `getDirectCallee()` may return a null pointer if the callee is not a `FunctionDecl` (for example when using function pointers), this requires to use `dyn_cast_or_null` instead of `dyn_cast`. >From 7d1263ad9c72b638d4624173b128d24b1a4317a1 Mon Sep 17 00:00:00 2001 From: Pasquale Riello Date: Fri, 2 Aug 2024 08:59:07 + Subject: [PATCH] [clang][dataflow] Fix casting in `ChromiumCheckModel`. `getDirectCallee()` may return a null pointer if the callee is not a `FunctionDecl` (for example when using function pointers), this requires to use `dyn_cast_or_null` instead of `dyn_cast`. --- clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp index 5ac71e1d6bf64..27a624c61c7f2 100644 --- a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp +++ b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp @@ -56,7 +56,7 @@ bool ChromiumCheckModel::transfer(const CFGElement &Element, Environment &Env) { return false; auto Stmt = CS->getStmt(); if (const auto *Call = dyn_cast(Stmt)) { -if (const auto *M = dyn_cast(Call->getDirectCallee())) { +if (const auto *M = dyn_cast_or_null(Call->getDirectCallee())) { if (isCheckLikeMethod(CheckDecls, *M)) { // Mark this branch as unreachable. Env.assume(Env.arena().makeLiteral(false)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Fix casting in `ChromiumCheckModel`. (PR #101640)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Pasquale Riello (Pask00) Changes `getDirectCallee()` may return a null pointer if the callee is not a `FunctionDecl` (for example when using function pointers), this requires to use `dyn_cast_or_null` instead of `dyn_cast`. --- Full diff: https://github.com/llvm/llvm-project/pull/101640.diff 1 Files Affected: - (modified) clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp (+1-1) ``diff diff --git a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp index 5ac71e1d6bf64..27a624c61c7f2 100644 --- a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp +++ b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp @@ -56,7 +56,7 @@ bool ChromiumCheckModel::transfer(const CFGElement &Element, Environment &Env) { return false; auto Stmt = CS->getStmt(); if (const auto *Call = dyn_cast(Stmt)) { -if (const auto *M = dyn_cast(Call->getDirectCallee())) { +if (const auto *M = dyn_cast_or_null(Call->getDirectCallee())) { if (isCheckLikeMethod(CheckDecls, *M)) { // Mark this branch as unreachable. Env.assume(Env.arena().makeLiteral(false)); `` https://github.com/llvm/llvm-project/pull/101640 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Restore recognition of mutex methods (PR #101511)
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/101511 From 8700f803c5191e5bb266797e0d130ea27776101f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Thu, 1 Aug 2024 18:07:53 +0200 Subject: [PATCH 1/2] [analyzer] Restore recognition of mutex methods Before commit 705788c the checker alpha.unix.BlockInCriticalSection "recognized" the methods `std::mutex::lock` and `std::mutex::unlock` with an extremely trivial check that accepted any function (or method) named lock/unlock. To avoid matching unrelated user-defined function, this was refined to a check that also requires the presence of "std" and "mutex" as distinct parts of the qualified name. However, as #99628 reported, there are standard library implementations where some methods of `std::mutex` are inherited from an implementation detail base class and the new code wasn't able to recognize these methods, which led to emitting false positive reports. As a workaround, this commit partially restores the old behavior by omitting the check for the class name. In the future, it would be good to replace this hack with a solution which ensures that `CallDescription` understands inherited methods. --- .../Checkers/BlockInCriticalSectionChecker.cpp | 16 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp index 40f7e9cede1f1..4cd2f2802f30c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp @@ -147,10 +147,18 @@ using MutexDescriptor = class BlockInCriticalSectionChecker : public Checker { private: const std::array MutexDescriptors{ - MemberMutexDescriptor({/*MatchAs=*/CDM::CXXMethod, - /*QualifiedName=*/{"std", "mutex", "lock"}, - /*RequiredArgs=*/0}, -{CDM::CXXMethod, {"std", "mutex", "unlock"}, 0}), + // NOTE: There are standard library implementations where some methods + // of `std::mutex` are inherited from an implementation detail base + // class, and those aren't matched by the name specification {"std", + // "mutex", "lock"}. + // As a workaround here we omit the class name and only require the + // presence of the name parts "std" and "lock"/"unlock". + // TODO: Ensure that CallDescription understands inherited methods. + MemberMutexDescriptor( + {/*MatchAs=*/CDM::CXXMethod, + /*QualifiedName=*/{"std", /*"mutex",*/ "lock"}, + /*RequiredArgs=*/0}, + {CDM::CXXMethod, {"std", /*"mutex",*/ "unlock"}, 0}), FirstArgMutexDescriptor({CDM::CLibrary, {"pthread_mutex_lock"}, 1}, {CDM::CLibrary, {"pthread_mutex_unlock"}, 1}), FirstArgMutexDescriptor({CDM::CLibrary, {"mtx_lock"}, 1}, From 25204bb287e0b05f8e2bbd76a1989d5c5cfa5c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Fri, 2 Aug 2024 10:57:47 +0200 Subject: [PATCH 2/2] Add a testcase to prevent regressions --- .../block-in-critical-section-inheritance.cpp | 31 +++ 1 file changed, 31 insertions(+) create mode 100644 clang/test/Analysis/block-in-critical-section-inheritance.cpp diff --git a/clang/test/Analysis/block-in-critical-section-inheritance.cpp b/clang/test/Analysis/block-in-critical-section-inheritance.cpp new file mode 100644 index 0..db20df8c60a5c --- /dev/null +++ b/clang/test/Analysis/block-in-critical-section-inheritance.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_analyze_cc1 \ +// RUN: -analyzer-checker=unix.BlockInCriticalSection \ +// RUN: -std=c++11 \ +// RUN: -analyzer-output text \ +// RUN: -verify %s + +unsigned int sleep(unsigned int seconds) {return 0;} +namespace std { +// There are some standard library implementations where some mutex methods +// come from an implementation detail base class. We need to ensure that these +// are matched correctly. +class __mutex_base { +public: + void lock(); +}; +class mutex : public __mutex_base{ +public: + void unlock(); + bool try_lock(); +}; +} // namespace std + +void gh_99628() { + std::mutex m; + m.lock(); + // expected-note@-1 {{Entering critical section here}} + sleep(10); + // expected-warning@-1 {{Call to blocking function 'sleep' inside of critical section}} + // expected-note@-2 {{Call to blocking function 'sleep' inside of critical section}} + m.unlock(); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Fix casting in `ChromiumCheckModel`. (PR #101640)
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 270f5e42b8daab586ffcd2b46ff41486199f6626 7d1263ad9c72b638d4624173b128d24b1a4317a1 --extensions cpp -- clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp index 27a624c61c..77d817dafe 100644 --- a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp +++ b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp @@ -56,7 +56,8 @@ bool ChromiumCheckModel::transfer(const CFGElement &Element, Environment &Env) { return false; auto Stmt = CS->getStmt(); if (const auto *Call = dyn_cast(Stmt)) { -if (const auto *M = dyn_cast_or_null(Call->getDirectCallee())) { +if (const auto *M = +dyn_cast_or_null(Call->getDirectCallee())) { if (isCheckLikeMethod(CheckDecls, *M)) { // Mark this branch as unreachable. Env.assume(Env.arena().makeLiteral(false)); `` https://github.com/llvm/llvm-project/pull/101640 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2351 `void{}` (PR #78060)
cor3ntin wrote: @AaronBallman https://github.com/llvm/llvm-project/pull/78060 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent assertion failure by avoiding required literal type checking in C context (PR #101426)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/101426 >From 314766a02c096bd5c867383b55e75451961af231 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 1 Aug 2024 13:00:04 +0300 Subject: [PATCH] [Clang] prevent assertion failure by avoiding required literal type checking in C context --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaDecl.cpp | 3 ++- clang/test/Sema/constexpr.c | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3c2e0282d1c72..1a25d270e9509 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -156,6 +156,7 @@ Bug Fixes in This Version - Fixed the definition of ``ATOMIC_FLAG_INIT`` in so it can be used in C++. +- Fixed a failed assertion when checking required literal types in C context. (#GH101304). Bug Fixes to Compiler Builtins ^^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index a3f8126a9f915..4fea38d1b02a9 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -8756,7 +8756,8 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) { return; } - if (NewVD->isConstexpr() && !T->isDependentType() && + if (getLangOpts().CPlusPlus && NewVD->isConstexpr() && + !T->isDependentType() && RequireLiteralType(NewVD->getLocation(), T, diag::err_constexpr_var_non_literal)) { NewVD->setInvalidDecl(); diff --git a/clang/test/Sema/constexpr.c b/clang/test/Sema/constexpr.c index 8286cd2107d2f..5ea2ac24a503a 100644 --- a/clang/test/Sema/constexpr.c +++ b/clang/test/Sema/constexpr.c @@ -357,3 +357,6 @@ void infsNaNs() { constexpr double db5 = LD_SNAN; // expected-error {{constexpr initializer evaluates to nan which is not exactly representable in type 'const double'}} constexpr double db6 = INF; } + +constexpr struct S9 s9 = { }; // expected-error {{variable has incomplete type 'const struct S9'}} \ + // expected-note {{forward declaration of 'struct S9'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Fix casting in `ChromiumCheckModel`. (PR #101640)
https://github.com/Xazax-hun approved this pull request. https://github.com/llvm/llvm-project/pull/101640 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent assertion failure by avoiding required literal type checking in C context (PR #101426)
https://github.com/a-tarasyuk deleted https://github.com/llvm/llvm-project/pull/101426 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent assertion failure by avoiding required literal type checking in C context (PR #101426)
@@ -9267,14 +9267,14 @@ bool Sema::RequireLiteralType(SourceLocation Loc, QualType T, if (!RT) return true; - const CXXRecordDecl *RD = cast(RT->getDecl()); - // A partially-defined class type can't be a literal type, because a literal // class type must have a trivial destructor (which can't be checked until // the class definition is complete). if (RequireCompleteType(Loc, ElemType, diag::note_non_literal_incomplete, T)) return true; + const CXXRecordDecl *RD = cast(RT->getDecl()); a-tarasyuk wrote: @shafik @MitalAshok Could you review the latest changes? If there are no further comments, could you please proceed with the merge as I don't have access to do so? Thank you! https://github.com/llvm/llvm-project/pull/101426 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Fix casting in `ChromiumCheckModel`. (PR #101640)
https://github.com/Pask00 updated https://github.com/llvm/llvm-project/pull/101640 >From 7d1263ad9c72b638d4624173b128d24b1a4317a1 Mon Sep 17 00:00:00 2001 From: Pasquale Riello Date: Fri, 2 Aug 2024 08:59:07 + Subject: [PATCH 1/2] [clang][dataflow] Fix casting in `ChromiumCheckModel`. `getDirectCallee()` may return a null pointer if the callee is not a `FunctionDecl` (for example when using function pointers), this requires to use `dyn_cast_or_null` instead of `dyn_cast`. --- clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp index 5ac71e1d6bf64..27a624c61c7f2 100644 --- a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp +++ b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp @@ -56,7 +56,7 @@ bool ChromiumCheckModel::transfer(const CFGElement &Element, Environment &Env) { return false; auto Stmt = CS->getStmt(); if (const auto *Call = dyn_cast(Stmt)) { -if (const auto *M = dyn_cast(Call->getDirectCallee())) { +if (const auto *M = dyn_cast_or_null(Call->getDirectCallee())) { if (isCheckLikeMethod(CheckDecls, *M)) { // Mark this branch as unreachable. Env.assume(Env.arena().makeLiteral(false)); >From d12bfaa9a9e217ada43f5e6f74a20c2dce5b77e7 Mon Sep 17 00:00:00 2001 From: Pasquale Riello Date: Fri, 2 Aug 2024 09:13:23 + Subject: [PATCH 2/2] Apply clang-format. --- clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp index 27a624c61c7f2..77d817dafe837 100644 --- a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp +++ b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp @@ -56,7 +56,8 @@ bool ChromiumCheckModel::transfer(const CFGElement &Element, Environment &Env) { return false; auto Stmt = CS->getStmt(); if (const auto *Call = dyn_cast(Stmt)) { -if (const auto *M = dyn_cast_or_null(Call->getDirectCallee())) { +if (const auto *M = +dyn_cast_or_null(Call->getDirectCallee())) { if (isCheckLikeMethod(CheckDecls, *M)) { // Mark this branch as unreachable. Env.assume(Env.arena().makeLiteral(false)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][NFC] Remove unneeded defining name of `vundefined` (PR #101643)
https://github.com/4vtomat created https://github.com/llvm/llvm-project/pull/101643 `vundefined` doesn't have corresponding named IR, instead it generates `poison` value, we already define the `Name` for C intrinsics, so we don't need the defining name at all. >From df6b40a85ca89259751583b66429d59e92f4fe6d Mon Sep 17 00:00:00 2001 From: Brandon Wu Date: Fri, 2 Aug 2024 02:15:33 -0700 Subject: [PATCH] [RISCV][NFC] Remove unneeded defining name of `vundefined` `vundefined` doesn't have corresponding named IR, instead it generates `poison` value, we already define the `Name` for C intrinsics, so we don't need the defining name at all. --- clang/include/clang/Basic/riscv_vector.td | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/riscv_vector.td b/clang/include/clang/Basic/riscv_vector.td index a0820e2093bc2..13d2efb4e6109 100644 --- a/clang/include/clang/Basic/riscv_vector.td +++ b/clang/include/clang/Basic/riscv_vector.td @@ -2407,10 +2407,10 @@ let HasMasked = false, HasVL = false, IRName = "" in { ManualCodegen = [{ return llvm::PoisonValue::get(ResultType); }] in { -def vundefined : RVVBuiltin<"v", "v", "csilxfd">; +def : RVVBuiltin<"v", "v", "csilxfd">; let RequiredFeatures = ["Zvfbfmin"] in - def vundefined_bf16 : RVVBuiltin<"v", "v", "y">; -def vundefined_u : RVVBuiltin<"Uv", "Uv", "csil">; + def : RVVBuiltin<"v", "v", "y">; +def : RVVBuiltin<"Uv", "Uv", "csil">; foreach nf = NFList in { let NF = nf in { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][NFC] Remove unneeded defining name of `vundefined` (PR #101643)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Brandon Wu (4vtomat) Changes `vundefined` doesn't have corresponding named IR, instead it generates `poison` value, we already define the `Name` for C intrinsics, so we don't need the defining name at all. --- Full diff: https://github.com/llvm/llvm-project/pull/101643.diff 1 Files Affected: - (modified) clang/include/clang/Basic/riscv_vector.td (+3-3) ``diff diff --git a/clang/include/clang/Basic/riscv_vector.td b/clang/include/clang/Basic/riscv_vector.td index a0820e2093bc2..13d2efb4e6109 100644 --- a/clang/include/clang/Basic/riscv_vector.td +++ b/clang/include/clang/Basic/riscv_vector.td @@ -2407,10 +2407,10 @@ let HasMasked = false, HasVL = false, IRName = "" in { ManualCodegen = [{ return llvm::PoisonValue::get(ResultType); }] in { -def vundefined : RVVBuiltin<"v", "v", "csilxfd">; +def : RVVBuiltin<"v", "v", "csilxfd">; let RequiredFeatures = ["Zvfbfmin"] in - def vundefined_bf16 : RVVBuiltin<"v", "v", "y">; -def vundefined_u : RVVBuiltin<"Uv", "Uv", "csil">; + def : RVVBuiltin<"v", "v", "y">; +def : RVVBuiltin<"Uv", "Uv", "csil">; foreach nf = NFList in { let NF = nf in { `` https://github.com/llvm/llvm-project/pull/101643 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)
https://github.com/SpencerAbson deleted https://github.com/llvm/llvm-project/pull/100278 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CLANG][AArch64]Add Neon vectors for mfloat8_t (PR #99865)
https://github.com/CarolineConcatto edited https://github.com/llvm/llvm-project/pull/99865 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python] Fix `get_exception_specification_kind` (PR #101548)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/101548 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python] Fix `get_exception_specification_kind` (PR #101548)
https://github.com/Endilll approved this pull request. https://github.com/llvm/llvm-project/pull/101548 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CLANG]Add Scalable vectors for mfloat8_t (PR #101644)
https://github.com/CarolineConcatto created https://github.com/llvm/llvm-project/pull/101644 This patch adds these new vector sizes for sve: svmfloat8_t According to the ARM ACLE PR#323[1]. [1] ARM-software/acle#323 >From de397fb733bfbbe6d8ca14773c02768239bf0a48 Mon Sep 17 00:00:00 2001 From: Caroline Concatto Date: Mon, 24 Jun 2024 09:59:24 + Subject: [PATCH 1/3] [WIP][CLANG][AArch64] Add the modal 8 bit floating-point scalar type ARM ACLE PR#323[1] adds new modal types for 8-bit floating point intrinsic. >From the PR#323: ``` ACLE defines the `__mfp8` type, which can be used for the E5M2 and E4M3 8-bit floating-point formats. It is a storage and interchange only type with no arithmetic operations other than intrinsic calls. `mfloat8_t` | equivalent to `__mfp8` | The type should be an opaque type and its format in undefined in Clang. Only defined in the backend by a status/format register, for AArch64 the FPMR. This patch is an attempt to the add the fpm8_t scalar type. It has a parser and codegen for the new scalar type. The patch it is lowering to and 8bit unsigned as it has no format. But maybe we should add another opaque type. According to ACLE[1] proposal [1] https://github.com/ARM-software/acle/pull/323 --- clang/include/clang/AST/ASTContext.h | 1 + clang/include/clang/AST/BuiltinTypes.def | 4 + clang/include/clang/AST/Type.h| 5 + .../clang/Basic/DiagnosticSemaKinds.td| 2 + clang/include/clang/Basic/Specifiers.h| 1 + clang/include/clang/Basic/TargetBuiltins.h| 3 +- clang/include/clang/Basic/TargetInfo.h| 4 + clang/include/clang/Basic/TokenKinds.def | 1 + clang/include/clang/Sema/DeclSpec.h | 1 + .../include/clang/Serialization/ASTBitCodes.h | 5 +- clang/lib/AST/ASTContext.cpp | 7 ++ clang/lib/AST/ItaniumMangle.cpp | 4 + clang/lib/AST/PrintfFormatString.cpp | 1 + clang/lib/AST/Type.cpp| 2 + clang/lib/AST/TypeLoc.cpp | 1 + clang/lib/Basic/TargetInfo.cpp| 1 + clang/lib/Basic/Targets/AArch64.cpp | 6 ++ clang/lib/Basic/Targets/AArch64.h | 3 + clang/lib/CodeGen/CGDebugInfo.cpp | 1 + clang/lib/CodeGen/CodeGenModule.cpp | 1 + clang/lib/CodeGen/CodeGenTypeCache.h | 3 + clang/lib/CodeGen/CodeGenTypes.cpp| 4 +- clang/lib/CodeGen/ItaniumCXXABI.cpp | 1 + clang/lib/Index/USRGeneration.cpp | 1 + clang/lib/Lex/Lexer.cpp | 1 + clang/lib/Parse/ParseDecl.cpp | 7 ++ clang/lib/Parse/ParseExpr.cpp | 1 + clang/lib/Parse/ParseExprCXX.cpp | 3 + clang/lib/Parse/ParseTentative.cpp| 2 + clang/lib/Sema/DeclSpec.cpp | 2 + clang/lib/Sema/SemaCast.cpp | 7 ++ clang/lib/Sema/SemaExpr.cpp | 6 ++ clang/lib/Sema/SemaTemplateVariadic.cpp | 1 + clang/lib/Sema/SemaType.cpp | 8 +- clang/lib/Serialization/ASTCommon.cpp | 3 + clang/lib/Serialization/ASTReader.cpp | 3 + clang/test/AST/arm-mfp8.cpp | 94 +++ clang/test/CodeGen/arm-mfp8.c | 26 + clang/test/Sema/arm-mfp8.c| 11 +++ clang/test/Sema/arm-mfp8.cpp | 35 +++ 40 files changed, 269 insertions(+), 4 deletions(-) create mode 100644 clang/test/AST/arm-mfp8.cpp create mode 100644 clang/test/CodeGen/arm-mfp8.c create mode 100644 clang/test/Sema/arm-mfp8.c create mode 100644 clang/test/Sema/arm-mfp8.cpp diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 53ece996769a8..a5f558c735906 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1115,6 +1115,7 @@ class ASTContext : public RefCountedBase { CanQualType SatShortFractTy, SatFractTy, SatLongFractTy; CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy, SatUnsignedLongFractTy; + CanQualType MFloat8Ty; CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON CanQualType BFloat16Ty; CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3 diff --git a/clang/include/clang/AST/BuiltinTypes.def b/clang/include/clang/AST/BuiltinTypes.def index 444be4311a743..3c49852e3f255 100644 --- a/clang/include/clang/AST/BuiltinTypes.def +++ b/clang/include/clang/AST/BuiltinTypes.def @@ -221,6 +221,10 @@ FLOATING_TYPE(Float128, Float128Ty) // '__ibm128' FLOATING_TYPE(Ibm128, Ibm128Ty) + +// '__fpm8' +UNSIGNED_TYPE(MFloat8, MFloat8Ty) + //===- Language-specific types ===// // This is the type of C++0x 'nullptr'. diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index fab233b62d8d1..3073391e88cb7 100644 --- a/clang/include/clang/AST/Type.h +++ b/
[clang-tools-extra] Create a new check to look for mis-use in calls that take iterators (PR #99917)
https://github.com/njames93 updated https://github.com/llvm/llvm-project/pull/99917 >From d0cf6a5250f78d03eaf793035c58e3afc37e0788 Mon Sep 17 00:00:00 2001 From: Nathan James Date: Tue, 23 Jul 2024 10:59:45 +0100 Subject: [PATCH] Create a new check to look for mis-use in calls that take iterators Looks for various patterns of functions that take arguments calling begin/end or similar for common mistakes --- .../bugprone/BugproneTidyModule.cpp |3 + .../clang-tidy/bugprone/CMakeLists.txt|1 + .../bugprone/IncorrectIteratorsCheck.cpp | 1214 + .../bugprone/IncorrectIteratorsCheck.h| 45 + clang-tools-extra/docs/ReleaseNotes.rst |6 + .../checks/bugprone/incorrect-iterators.rst | 144 ++ .../docs/clang-tidy/checks/list.rst |1 + .../checkers/bugprone/incorrect-iterators.cpp | 437 ++ 8 files changed, 1851 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/bugprone/IncorrectIteratorsCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/bugprone/IncorrectIteratorsCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-iterators.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-iterators.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index 689eb92a3d8d1..cea040b81878a 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -33,6 +33,7 @@ #include "InaccurateEraseCheck.h" #include "IncDecInConditionsCheck.h" #include "IncorrectEnableIfCheck.h" +#include "IncorrectIteratorsCheck.h" #include "IncorrectRoundingsCheck.h" #include "InfiniteLoopCheck.h" #include "IntegerDivisionCheck.h" @@ -139,6 +140,8 @@ class BugproneModule : public ClangTidyModule { "bugprone-inaccurate-erase"); CheckFactories.registerCheck( "bugprone-incorrect-enable-if"); +CheckFactories.registerCheck( +"bugprone-incorrect-iterators"); CheckFactories.registerCheck( "bugprone-return-const-ref-from-parameter"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index cb0d8ae98bac5..8425dbed0505a 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule ImplicitWideningOfMultiplicationResultCheck.cpp InaccurateEraseCheck.cpp IncorrectEnableIfCheck.cpp + IncorrectIteratorsCheck.cpp ReturnConstRefFromParameterCheck.cpp SuspiciousStringviewDataUsageCheck.cpp SwitchMissingDefaultCaseCheck.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/IncorrectIteratorsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/IncorrectIteratorsCheck.cpp new file mode 100644 index 0..611fb70728eda --- /dev/null +++ b/clang-tools-extra/clang-tidy/bugprone/IncorrectIteratorsCheck.cpp @@ -0,0 +1,1214 @@ +//===--- IncorrectIteratorsCheck.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 "IncorrectIteratorsCheck.h" +#include "../utils/Matchers.h" +#include "../utils/OptionsUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/ASTTypeTraits.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/ASTMatchers/ASTMatchersInternal.h" +#include "clang/ASTMatchers/ASTMatchersMacros.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Support/ErrorHandling.h" +#include +#include + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +namespace { +using SVU = llvm::SmallVector; +/// Checks to see if a all the parameters of a template function with a given +/// index refer to the same type. +AST_MATCHER_P(FunctionDecl, areParametersSameTemplateType, SVU, Indexes) { + const FunctionTemplateDecl *TemplateDecl = Node.getPrimaryTemplate(); + if (!TemplateDecl) +return false; + const FunctionDecl *FuncDecl = TemplateDecl->getTemplatedDecl(); + if (!FuncDecl) +return false; + assert(!Indexes.empty()); + if (llvm::any_of(Indexes, [Count(FuncDecl->getN
[clang] [CLANG]Add Scalable vectors for mfloat8_t (PR #101644)
llvmbot wrote: @llvm/pr-subscribers-clang-modules Author: None (CarolineConcatto) Changes This patch adds these new vector sizes for sve: svmfloat8_t According to the ARM ACLE PR#323[1]. [1] ARM-software/acle#323 --- Patch is 57.30 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/101644.diff 53 Files Affected: - (modified) clang/include/clang/AST/ASTContext.h (+1) - (modified) clang/include/clang/AST/BuiltinTypes.def (+4) - (modified) clang/include/clang/AST/Type.h (+5) - (modified) clang/include/clang/Basic/AArch64SVEACLETypes.def (+1) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) - (modified) clang/include/clang/Basic/Specifiers.h (+1) - (modified) clang/include/clang/Basic/TargetBuiltins.h (+2-1) - (modified) clang/include/clang/Basic/TargetInfo.h (+4) - (modified) clang/include/clang/Basic/TokenKinds.def (+1) - (added) clang/include/clang/Basic/arm_mfp8.td (+14) - (modified) clang/include/clang/Basic/arm_neon_incl.td (+2) - (modified) clang/include/clang/Basic/arm_sve_sme_incl.td (+1) - (modified) clang/include/clang/Sema/DeclSpec.h (+1) - (modified) clang/include/clang/Serialization/ASTBitCodes.h (+4-1) - (modified) clang/lib/AST/ASTContext.cpp (+8) - (modified) clang/lib/AST/ItaniumMangle.cpp (+4) - (modified) clang/lib/AST/PrintfFormatString.cpp (+1) - (modified) clang/lib/AST/Type.cpp (+2) - (modified) clang/lib/AST/TypeLoc.cpp (+1) - (modified) clang/lib/Basic/TargetInfo.cpp (+1) - (modified) clang/lib/Basic/Targets/AArch64.cpp (+9) - (modified) clang/lib/Basic/Targets/AArch64.h (+3) - (modified) clang/lib/Basic/Targets/ARM.cpp (+2) - (modified) clang/lib/Basic/Targets/ARM.h (+2) - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+2) - (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+1) - (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1) - (modified) clang/lib/CodeGen/CodeGenTypeCache.h (+3) - (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+5-2) - (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+1) - (modified) clang/lib/Headers/CMakeLists.txt (+3) - (modified) clang/lib/Index/USRGeneration.cpp (+1) - (modified) clang/lib/Lex/Lexer.cpp (+1) - (modified) clang/lib/Parse/ParseDecl.cpp (+7) - (modified) clang/lib/Parse/ParseExpr.cpp (+1) - (modified) clang/lib/Parse/ParseExprCXX.cpp (+3) - (modified) clang/lib/Parse/ParseTentative.cpp (+2) - (modified) clang/lib/Sema/DeclSpec.cpp (+2) - (modified) clang/lib/Sema/SemaARM.cpp (+2) - (modified) clang/lib/Sema/SemaCast.cpp (+7) - (modified) clang/lib/Sema/SemaExpr.cpp (+11) - (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+1) - (modified) clang/lib/Sema/SemaType.cpp (+7-1) - (modified) clang/lib/Serialization/ASTCommon.cpp (+3) - (modified) clang/lib/Serialization/ASTReader.cpp (+3) - (added) clang/test/AST/arm-mfp8.cpp (+94) - (added) clang/test/CodeGen/arm-mfp8.c (+103) - (added) clang/test/Sema/arm-mfp8.c (+11) - (added) clang/test/Sema/arm-mfp8.cpp (+62) - (modified) clang/utils/TableGen/NeonEmitter.cpp (+56-2) - (modified) clang/utils/TableGen/SveEmitter.cpp (+29-5) - (modified) clang/utils/TableGen/TableGen.cpp (+5) - (modified) clang/utils/TableGen/TableGenBackends.h (+1) ``diff diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 53ece996769a8..a5f558c735906 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1115,6 +1115,7 @@ class ASTContext : public RefCountedBase { CanQualType SatShortFractTy, SatFractTy, SatLongFractTy; CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy, SatUnsignedLongFractTy; + CanQualType MFloat8Ty; CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON CanQualType BFloat16Ty; CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3 diff --git a/clang/include/clang/AST/BuiltinTypes.def b/clang/include/clang/AST/BuiltinTypes.def index 444be4311a743..3c49852e3f255 100644 --- a/clang/include/clang/AST/BuiltinTypes.def +++ b/clang/include/clang/AST/BuiltinTypes.def @@ -221,6 +221,10 @@ FLOATING_TYPE(Float128, Float128Ty) // '__ibm128' FLOATING_TYPE(Ibm128, Ibm128Ty) + +// '__fpm8' +UNSIGNED_TYPE(MFloat8, MFloat8Ty) + //===- Language-specific types ===// // This is the type of C++0x 'nullptr'. diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index fab233b62d8d1..3073391e88cb7 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -2492,6 +2492,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { bool isDoubleType() const; bool isBFloat16Type() const; bool isFloat128Type() const; + bool isMFloat8Type() const; bool isIbm128Type() const; bool isRealType() const; // C99 6.2.5p17 (real floating + integer) bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) @@ -7944,6 +7945,10 @@ inline bool Type::isBFl
[clang] [CLANG]Add Scalable vectors for mfloat8_t (PR #101644)
llvmbot wrote: @llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-clang Author: None (CarolineConcatto) Changes This patch adds these new vector sizes for sve: svmfloat8_t According to the ARM ACLE PR#323[1]. [1] ARM-software/acle#323 --- Patch is 57.30 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/101644.diff 53 Files Affected: - (modified) clang/include/clang/AST/ASTContext.h (+1) - (modified) clang/include/clang/AST/BuiltinTypes.def (+4) - (modified) clang/include/clang/AST/Type.h (+5) - (modified) clang/include/clang/Basic/AArch64SVEACLETypes.def (+1) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) - (modified) clang/include/clang/Basic/Specifiers.h (+1) - (modified) clang/include/clang/Basic/TargetBuiltins.h (+2-1) - (modified) clang/include/clang/Basic/TargetInfo.h (+4) - (modified) clang/include/clang/Basic/TokenKinds.def (+1) - (added) clang/include/clang/Basic/arm_mfp8.td (+14) - (modified) clang/include/clang/Basic/arm_neon_incl.td (+2) - (modified) clang/include/clang/Basic/arm_sve_sme_incl.td (+1) - (modified) clang/include/clang/Sema/DeclSpec.h (+1) - (modified) clang/include/clang/Serialization/ASTBitCodes.h (+4-1) - (modified) clang/lib/AST/ASTContext.cpp (+8) - (modified) clang/lib/AST/ItaniumMangle.cpp (+4) - (modified) clang/lib/AST/PrintfFormatString.cpp (+1) - (modified) clang/lib/AST/Type.cpp (+2) - (modified) clang/lib/AST/TypeLoc.cpp (+1) - (modified) clang/lib/Basic/TargetInfo.cpp (+1) - (modified) clang/lib/Basic/Targets/AArch64.cpp (+9) - (modified) clang/lib/Basic/Targets/AArch64.h (+3) - (modified) clang/lib/Basic/Targets/ARM.cpp (+2) - (modified) clang/lib/Basic/Targets/ARM.h (+2) - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+2) - (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+1) - (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1) - (modified) clang/lib/CodeGen/CodeGenTypeCache.h (+3) - (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+5-2) - (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+1) - (modified) clang/lib/Headers/CMakeLists.txt (+3) - (modified) clang/lib/Index/USRGeneration.cpp (+1) - (modified) clang/lib/Lex/Lexer.cpp (+1) - (modified) clang/lib/Parse/ParseDecl.cpp (+7) - (modified) clang/lib/Parse/ParseExpr.cpp (+1) - (modified) clang/lib/Parse/ParseExprCXX.cpp (+3) - (modified) clang/lib/Parse/ParseTentative.cpp (+2) - (modified) clang/lib/Sema/DeclSpec.cpp (+2) - (modified) clang/lib/Sema/SemaARM.cpp (+2) - (modified) clang/lib/Sema/SemaCast.cpp (+7) - (modified) clang/lib/Sema/SemaExpr.cpp (+11) - (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+1) - (modified) clang/lib/Sema/SemaType.cpp (+7-1) - (modified) clang/lib/Serialization/ASTCommon.cpp (+3) - (modified) clang/lib/Serialization/ASTReader.cpp (+3) - (added) clang/test/AST/arm-mfp8.cpp (+94) - (added) clang/test/CodeGen/arm-mfp8.c (+103) - (added) clang/test/Sema/arm-mfp8.c (+11) - (added) clang/test/Sema/arm-mfp8.cpp (+62) - (modified) clang/utils/TableGen/NeonEmitter.cpp (+56-2) - (modified) clang/utils/TableGen/SveEmitter.cpp (+29-5) - (modified) clang/utils/TableGen/TableGen.cpp (+5) - (modified) clang/utils/TableGen/TableGenBackends.h (+1) ``diff diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 53ece996769a8..a5f558c735906 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1115,6 +1115,7 @@ class ASTContext : public RefCountedBase { CanQualType SatShortFractTy, SatFractTy, SatLongFractTy; CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy, SatUnsignedLongFractTy; + CanQualType MFloat8Ty; CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON CanQualType BFloat16Ty; CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3 diff --git a/clang/include/clang/AST/BuiltinTypes.def b/clang/include/clang/AST/BuiltinTypes.def index 444be4311a743..3c49852e3f255 100644 --- a/clang/include/clang/AST/BuiltinTypes.def +++ b/clang/include/clang/AST/BuiltinTypes.def @@ -221,6 +221,10 @@ FLOATING_TYPE(Float128, Float128Ty) // '__ibm128' FLOATING_TYPE(Ibm128, Ibm128Ty) + +// '__fpm8' +UNSIGNED_TYPE(MFloat8, MFloat8Ty) + //===- Language-specific types ===// // This is the type of C++0x 'nullptr'. diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index fab233b62d8d1..3073391e88cb7 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -2492,6 +2492,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { bool isDoubleType() const; bool isBFloat16Type() const; bool isFloat128Type() const; + bool isMFloat8Type() const; bool isIbm128Type() const; bool isRealType() const; // C99 6.2.5p17 (real floating + integer) bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) @@ -7944,6 +7945,10 @@
[clang] [clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) (PR #101305)
https://github.com/jtb20 updated https://github.com/llvm/llvm-project/pull/101305 >From 0d9ee78eb214135b10ecb5258358728e0fc626e1 Mon Sep 17 00:00:00 2001 From: Julian Brown Date: Wed, 26 Jun 2024 11:21:01 -0500 Subject: [PATCH] [clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) This patch fixes a couple of cases where Clang aborts with loop nests that are being collapsed (via the relevant OpenMP clause) into a new, combined loop. The problematic cases happen when a variable declared within the loop nest is used in the (init, condition, iter) statement of a more deeply-nested loop. I don't think these cases (generally?) fall under the non-rectangular loop nest rules as defined in OpenMP 5.0+, but I could be wrong (and anyway, emitting an error is better than crashing). In terms of implementation: the crash happens because (to a first approximation) all the loop bounds calculations are pulled out to the start of the new, combined loop, but variables declared in the loop nest "haven't been seen yet". I believe there is special handling for iteration variables declared in "for" init statements, but not for variables declared elsewhere in the "imperfect" parts of a loop nest. So, this patch tries to diagnose the troublesome cases before they can cause a crash. This is slightly awkward because at the point where we want to do the diagnosis (SemaOpenMP.cpp), we don't have scope information readily available. Instead we "manually" scan through the AST of the loop nest looking for var decls (ForVarDeclFinder), then we ensure we're not using any of those in loop control subexprs (ForSubExprChecker). All that is only done when we have a "collapse" clause. Range-for loops can also cause crashes at present without this patch, so are handled too. --- .../clang/Basic/DiagnosticSemaKinds.td| 2 + clang/lib/Sema/SemaOpenMP.cpp | 141 +- clang/test/OpenMP/loop_collapse_1.c | 40 + clang/test/OpenMP/loop_collapse_2.cpp | 80 ++ 4 files changed, 255 insertions(+), 8 deletions(-) create mode 100644 clang/test/OpenMP/loop_collapse_1.c create mode 100644 clang/test/OpenMP/loop_collapse_2.cpp diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 581434d33c5c9..beb78eb0a4ef4 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11152,6 +11152,8 @@ def err_omp_loop_diff_cxx : Error< "upper and lower loop bounds">; def err_omp_loop_cannot_use_stmt : Error< "'%0' statement cannot be used in OpenMP for loop">; +def err_omp_loop_bad_collapse_var : Error< + "cannot use variable %1 in collapsed imperfectly-nested loop %select{init|condition|increment}0 statement">; def err_omp_simd_region_cannot_use_stmt : Error< "'%0' statement cannot be used in OpenMP simd region">; def warn_omp_loop_64_bit_var : Warning< diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 4f50efda155fb..f52a5715aa19e 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -21,6 +21,7 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclOpenMP.h" #include "clang/AST/OpenMPClause.h" +#include "clang/AST/RecursiveASTVisitor.h" #include "clang/AST/StmtCXX.h" #include "clang/AST/StmtOpenMP.h" #include "clang/AST/StmtVisitor.h" @@ -7668,6 +7669,52 @@ struct LoopIterationSpace final { Expr *FinalCondition = nullptr; }; +/// Scan an AST subtree, checking that no decls in the CollapsedLoopVarDecls +/// set are referenced. Used for verifying loop nest structure before +/// performing a loop collapse operation. +class ForSubExprChecker final : public RecursiveASTVisitor { + const llvm::SmallPtrSetImpl &CollapsedLoopVarDecls; + VarDecl *ForbiddenVar = nullptr; + SourceRange ErrLoc; + +public: + explicit ForSubExprChecker( + const llvm::SmallPtrSetImpl &CollapsedLoopVarDecls) + : CollapsedLoopVarDecls(CollapsedLoopVarDecls) {} + + // We want to visit implicit code, i.e. synthetic initialisation statements + // created during range-for lowering. + bool shouldVisitImplicitCode() const { return true; } + + bool VisitDeclRefExpr(DeclRefExpr *E) { +ValueDecl *VD = E->getDecl(); +if (!isa(VD)) + return true; +VarDecl *V = VD->getPotentiallyDecomposedVarDecl(); +if (V->getType()->isReferenceType()) { + VarDecl *VD = V->getDefinition(); + if (VD->hasInit()) { +Expr *I = VD->getInit(); +DeclRefExpr *DRE = dyn_cast(I); +if (!DRE) + return true; +V = DRE->getDecl()->getPotentiallyDecomposedVarDecl(); + } +} +Decl *Canon = V->getCanonicalDecl(); +if (CollapsedLoopVarDecls.contains(Canon)) { + ForbiddenVar = V; + ErrLoc = E->getSourceRange(); + return false; +} + +return true; + } + + VarDecl *getForbiddenVar() const { return Forbi
[clang] [RISCV][clang] Remove unused base type in `vfncvt` (PR #101646)
https://github.com/4vtomat created https://github.com/llvm/llvm-project/pull/101646 We don't have `fp8` type supported yet. >From ff5083431d41d22c50725638b084bfb2532dad74 Mon Sep 17 00:00:00 2001 From: Brandon Wu Date: Fri, 2 Aug 2024 03:04:18 -0700 Subject: [PATCH] [RISCV][clang] Remove unused base type in `vfncvt` We don't have `fp8` type supported yet. --- clang/include/clang/Basic/riscv_vector.td | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/riscv_vector.td b/clang/include/clang/Basic/riscv_vector.td index a0820e2093bc2..4841792c91d4a 100644 --- a/clang/include/clang/Basic/riscv_vector.td +++ b/clang/include/clang/Basic/riscv_vector.td @@ -2011,9 +2011,9 @@ let ManualCodegen = [{ RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFwu"]]>; let OverloadedName = "vfncvt_f" in { defm : - RVVConvBuiltinSet<"vfncvt_f_x_w", "csi", [["Fv", "Fvwu"]]>; + RVVConvBuiltinSet<"vfncvt_f_x_w", "si", [["Fv", "Fvwu"]]>; defm : - RVVConvBuiltinSet<"vfncvt_f_xu_w", "csi", [["Fv", "FvUwu"]]>; + RVVConvBuiltinSet<"vfncvt_f_xu_w", "si", [["Fv", "FvUwu"]]>; } let OverloadedName = "vfncvt_f" in { defm : RVVConvBuiltinSet<"vfncvt_f_f_w", "f", [["v", "vwu"]]>; @@ -2061,9 +2061,9 @@ let ManualCodegen = [{ RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFw"]]>; let OverloadedName = "vfncvt_f" in { defm : -RVVConvBuiltinSet<"vfncvt_f_x_w", "csi", [["Fv", "Fvw"]]>; +RVVConvBuiltinSet<"vfncvt_f_x_w", "si", [["Fv", "Fvw"]]>; defm : -RVVConvBuiltinSet<"vfncvt_f_xu_w", "csi", [["Fv", "FvUw"]]>; +RVVConvBuiltinSet<"vfncvt_f_xu_w", "si", [["Fv", "FvUw"]]>; } let OverloadedName = "vfncvt_f" in { defm : RVVConvBuiltinSet<"vfncvt_f_f_w", "f", [["v", "vw"]]>; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][clang] Remove unused base type in `vfncvt` (PR #101646)
llvmbot wrote: @llvm/pr-subscribers-backend-risc-v @llvm/pr-subscribers-clang Author: Brandon Wu (4vtomat) Changes We don't have `fp8` type supported yet. --- Full diff: https://github.com/llvm/llvm-project/pull/101646.diff 1 Files Affected: - (modified) clang/include/clang/Basic/riscv_vector.td (+4-4) ``diff diff --git a/clang/include/clang/Basic/riscv_vector.td b/clang/include/clang/Basic/riscv_vector.td index a0820e2093bc2..4841792c91d4a 100644 --- a/clang/include/clang/Basic/riscv_vector.td +++ b/clang/include/clang/Basic/riscv_vector.td @@ -2011,9 +2011,9 @@ let ManualCodegen = [{ RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFwu"]]>; let OverloadedName = "vfncvt_f" in { defm : - RVVConvBuiltinSet<"vfncvt_f_x_w", "csi", [["Fv", "Fvwu"]]>; + RVVConvBuiltinSet<"vfncvt_f_x_w", "si", [["Fv", "Fvwu"]]>; defm : - RVVConvBuiltinSet<"vfncvt_f_xu_w", "csi", [["Fv", "FvUwu"]]>; + RVVConvBuiltinSet<"vfncvt_f_xu_w", "si", [["Fv", "FvUwu"]]>; } let OverloadedName = "vfncvt_f" in { defm : RVVConvBuiltinSet<"vfncvt_f_f_w", "f", [["v", "vwu"]]>; @@ -2061,9 +2061,9 @@ let ManualCodegen = [{ RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFw"]]>; let OverloadedName = "vfncvt_f" in { defm : -RVVConvBuiltinSet<"vfncvt_f_x_w", "csi", [["Fv", "Fvw"]]>; +RVVConvBuiltinSet<"vfncvt_f_x_w", "si", [["Fv", "Fvw"]]>; defm : -RVVConvBuiltinSet<"vfncvt_f_xu_w", "csi", [["Fv", "FvUw"]]>; +RVVConvBuiltinSet<"vfncvt_f_xu_w", "si", [["Fv", "FvUw"]]>; } let OverloadedName = "vfncvt_f" in { defm : RVVConvBuiltinSet<"vfncvt_f_f_w", "f", [["v", "vw"]]>; `` https://github.com/llvm/llvm-project/pull/101646 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
https://github.com/pskrgag created https://github.com/llvm/llvm-project/pull/101647 Current CSA logic does not expect `LazyCompoundValKind` as array index. This may happen if array is used as subscript to another, in case of bitcast to integer type. Catch such cases and return `UnknownVal`, since CSA cannot model array -> int casts. Closes #94496 >From d94748f76ca793bf40cb57dd904d487c51bdcd40 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin Date: Fri, 2 Aug 2024 12:02:11 +0300 Subject: [PATCH 1/2] clang/csa: fix crash on using bitcast(, ) as array subscript --- clang/lib/StaticAnalyzer/Core/Store.cpp | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Core/Store.cpp b/clang/lib/StaticAnalyzer/Core/Store.cpp index 67ca61bb56ba2..72587ef31a17c 100644 --- a/clang/lib/StaticAnalyzer/Core/Store.cpp +++ b/clang/lib/StaticAnalyzer/Core/Store.cpp @@ -472,7 +472,19 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset, const auto *ElemR = dyn_cast(BaseRegion); // Convert the offset to the appropriate size and signedness. - Offset = svalBuilder.convertToArrayIndex(Offset).castAs(); + auto Off = svalBuilder.convertToArrayIndex(Offset).getAs(); + if (!Off) { +// Handle cases when LazyCompoundVal is used for an array index. +// Such case is possible if code does: +// +// char b[4]; +// a[__builtin_bitcast(int, b)]; +// +// Return UnknownVal, since we cannot model it. +return UnknownVal(); + } + + Offset = Off.value(); if (!ElemR) { // If the base region is not an ElementRegion, create one. >From 515520dde7eb4d0365b0eed4627b19d4dedde5d7 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin Date: Fri, 2 Aug 2024 12:14:11 +0300 Subject: [PATCH 2/2] clang/csa: add test case for array[bitcast(, )] --- clang/test/Analysis/exercise-ps.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/clang/test/Analysis/exercise-ps.c b/clang/test/Analysis/exercise-ps.c index d1e1771afddb5..9bba16c282967 100644 --- a/clang/test/Analysis/exercise-ps.c +++ b/clang/test/Analysis/exercise-ps.c @@ -30,3 +30,10 @@ void f3(void *dest) { void *src = __builtin_alloca(5); memcpy(dest, src, 1); // expected-warning{{2nd function call argument is a pointer to uninitialized value}} } + +// Reproduce crash from GH#94496. When array is used as subcript to another array, CSA cannot model it +// and should just assume it's unknown and do not crash. +void f4(char *array) { + char b[4] = {0}; + array[__builtin_bit_cast(int, b)] = 0x10; // no crash +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Pavel Skripkin (pskrgag) Changes Current CSA logic does not expect `LazyCompoundValKind` as array index. This may happen if array is used as subscript to another, in case of bitcast to integer type. Catch such cases and return `UnknownVal`, since CSA cannot model array -> int casts. Closes #94496 --- Full diff: https://github.com/llvm/llvm-project/pull/101647.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/Store.cpp (+13-1) - (modified) clang/test/Analysis/exercise-ps.c (+7) ``diff diff --git a/clang/lib/StaticAnalyzer/Core/Store.cpp b/clang/lib/StaticAnalyzer/Core/Store.cpp index 67ca61bb56ba2..72587ef31a17c 100644 --- a/clang/lib/StaticAnalyzer/Core/Store.cpp +++ b/clang/lib/StaticAnalyzer/Core/Store.cpp @@ -472,7 +472,19 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset, const auto *ElemR = dyn_cast(BaseRegion); // Convert the offset to the appropriate size and signedness. - Offset = svalBuilder.convertToArrayIndex(Offset).castAs(); + auto Off = svalBuilder.convertToArrayIndex(Offset).getAs(); + if (!Off) { +// Handle cases when LazyCompoundVal is used for an array index. +// Such case is possible if code does: +// +// char b[4]; +// a[__builtin_bitcast(int, b)]; +// +// Return UnknownVal, since we cannot model it. +return UnknownVal(); + } + + Offset = Off.value(); if (!ElemR) { // If the base region is not an ElementRegion, create one. diff --git a/clang/test/Analysis/exercise-ps.c b/clang/test/Analysis/exercise-ps.c index d1e1771afddb5..9bba16c282967 100644 --- a/clang/test/Analysis/exercise-ps.c +++ b/clang/test/Analysis/exercise-ps.c @@ -30,3 +30,10 @@ void f3(void *dest) { void *src = __builtin_alloca(5); memcpy(dest, src, 1); // expected-warning{{2nd function call argument is a pointer to uninitialized value}} } + +// Reproduce crash from GH#94496. When array is used as subcript to another array, CSA cannot model it +// and should just assume it's unknown and do not crash. +void f4(char *array) { + char b[4] = {0}; + array[__builtin_bit_cast(int, b)] = 0x10; // no crash +} `` https://github.com/llvm/llvm-project/pull/101647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Pavel Skripkin (pskrgag) Changes Current CSA logic does not expect `LazyCompoundValKind` as array index. This may happen if array is used as subscript to another, in case of bitcast to integer type. Catch such cases and return `UnknownVal`, since CSA cannot model array -> int casts. Closes #94496 --- Full diff: https://github.com/llvm/llvm-project/pull/101647.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/Store.cpp (+13-1) - (modified) clang/test/Analysis/exercise-ps.c (+7) ``diff diff --git a/clang/lib/StaticAnalyzer/Core/Store.cpp b/clang/lib/StaticAnalyzer/Core/Store.cpp index 67ca61bb56ba2..72587ef31a17c 100644 --- a/clang/lib/StaticAnalyzer/Core/Store.cpp +++ b/clang/lib/StaticAnalyzer/Core/Store.cpp @@ -472,7 +472,19 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset, const auto *ElemR = dyn_cast(BaseRegion); // Convert the offset to the appropriate size and signedness. - Offset = svalBuilder.convertToArrayIndex(Offset).castAs(); + auto Off = svalBuilder.convertToArrayIndex(Offset).getAs(); + if (!Off) { +// Handle cases when LazyCompoundVal is used for an array index. +// Such case is possible if code does: +// +// char b[4]; +// a[__builtin_bitcast(int, b)]; +// +// Return UnknownVal, since we cannot model it. +return UnknownVal(); + } + + Offset = Off.value(); if (!ElemR) { // If the base region is not an ElementRegion, create one. diff --git a/clang/test/Analysis/exercise-ps.c b/clang/test/Analysis/exercise-ps.c index d1e1771afddb5..9bba16c282967 100644 --- a/clang/test/Analysis/exercise-ps.c +++ b/clang/test/Analysis/exercise-ps.c @@ -30,3 +30,10 @@ void f3(void *dest) { void *src = __builtin_alloca(5); memcpy(dest, src, 1); // expected-warning{{2nd function call argument is a pointer to uninitialized value}} } + +// Reproduce crash from GH#94496. When array is used as subcript to another array, CSA cannot model it +// and should just assume it's unknown and do not crash. +void f4(char *array) { + char b[4] = {0}; + array[__builtin_bit_cast(int, b)] = 0x10; // no crash +} `` https://github.com/llvm/llvm-project/pull/101647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [NVPTX] Support __usAtomicCAS builtin (PR #99646)
https://github.com/DenisGZM updated https://github.com/llvm/llvm-project/pull/99646 >From 0786e5bf48a5b638b99a666c282a5191e4a3c956 Mon Sep 17 00:00:00 2001 From: Denis Gerasimov Date: Fri, 19 Jul 2024 15:47:57 +0300 Subject: [PATCH 1/6] [NVPTX] Support __usAtomicCAS builtin --- clang/include/clang/Basic/BuiltinsNVPTX.def | 3 +++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +++ clang/lib/Headers/__clang_cuda_device_functions.h | 12 clang/test/CodeGen/builtins-nvptx.c | 3 +++ llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp | 2 +- llvm/lib/Target/NVPTX/NVPTXIntrinsics.td | 15 +++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/BuiltinsNVPTX.def b/clang/include/clang/Basic/BuiltinsNVPTX.def index 504314d8d96e9..3cf683a2f2129 100644 --- a/clang/include/clang/Basic/BuiltinsNVPTX.def +++ b/clang/include/clang/Basic/BuiltinsNVPTX.def @@ -829,6 +829,9 @@ BUILTIN(__nvvm_atom_xor_gen_ll, "LLiLLiD*LLi", "n") TARGET_BUILTIN(__nvvm_atom_cta_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60) TARGET_BUILTIN(__nvvm_atom_sys_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60) +TARGET_BUILTIN(__nvvm_atom_cas_gen_us, "UsUsD*UsUs", "n", SM_70) +TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_us, "UsUsD*UsUs", "n", SM_70) +TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_us, "UsUsD*UsUs", "n", SM_70) BUILTIN(__nvvm_atom_cas_gen_i, "iiD*ii", "n") TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_i, "iiD*ii", "n", SM_60) TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_i, "iiD*ii", "n", SM_60) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 0c4d0efb70ea5..af37960b4a191 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -20209,6 +20209,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, case NVPTX::BI__nvvm_atom_min_gen_ull: return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMin, E); + case NVPTX::BI__nvvm_atom_cas_gen_us: case NVPTX::BI__nvvm_atom_cas_gen_i: case NVPTX::BI__nvvm_atom_cas_gen_l: case NVPTX::BI__nvvm_atom_cas_gen_ll: @@ -20400,6 +20401,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, case NVPTX::BI__nvvm_atom_sys_xor_gen_l: case NVPTX::BI__nvvm_atom_sys_xor_gen_ll: return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys, *this, E); + case NVPTX::BI__nvvm_atom_cta_cas_gen_us: case NVPTX::BI__nvvm_atom_cta_cas_gen_i: case NVPTX::BI__nvvm_atom_cta_cas_gen_l: case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: { @@ -20411,6 +20413,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, Intrinsic::nvvm_atomic_cas_gen_i_cta, {ElemTy, Ptr->getType()}), {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))}); } + case NVPTX::BI__nvvm_atom_sys_cas_gen_us: case NVPTX::BI__nvvm_atom_sys_cas_gen_i: case NVPTX::BI__nvvm_atom_sys_cas_gen_l: case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: { diff --git a/clang/lib/Headers/__clang_cuda_device_functions.h b/clang/lib/Headers/__clang_cuda_device_functions.h index f8a12cefdb81b..f66fe625a3967 100644 --- a/clang/lib/Headers/__clang_cuda_device_functions.h +++ b/clang/lib/Headers/__clang_cuda_device_functions.h @@ -529,6 +529,18 @@ __DEVICE__ void __threadfence(void) { __nvvm_membar_gl(); } __DEVICE__ void __threadfence_block(void) { __nvvm_membar_cta(); }; __DEVICE__ void __threadfence_system(void) { __nvvm_membar_sys(); }; __DEVICE__ void __trap(void) { __asm__ __volatile__("trap;"); } +__DEVICE__ unsigned short __usAtomicCAS(unsigned short *__p, unsigned short __cmp, +unsigned short __v) { + return __nvvm_atom_cas_gen_us(__p, __cmp, __v); +} +__DEVICE__ unsigned short __usAtomicCAS_block(unsigned short *__p, unsigned short __cmp, + unsigned short __v) { + return __nvvm_atom_cta_cas_gen_us(__p, __cmp, __v); +} +__DEVICE__ unsigned short __usAtomicCAS_system(unsigned short *__p, unsigned short __cmp, + unsigned short __v) { + return __nvvm_atom_sys_cas_gen_us(__p, __cmp, __v); +} __DEVICE__ unsigned int __uAtomicAdd(unsigned int *__p, unsigned int __v) { return __nvvm_atom_add_gen_i((int *)__p, __v); } diff --git a/clang/test/CodeGen/builtins-nvptx.c b/clang/test/CodeGen/builtins-nvptx.c index 75b9d6d1fe190..3ba1fabd05335 100644 --- a/clang/test/CodeGen/builtins-nvptx.c +++ b/clang/test/CodeGen/builtins-nvptx.c @@ -306,6 +306,9 @@ __device__ void nvvm_atom(float *fp, float f, double *dfp, double df, int *ip, // CHECK: atomicrmw umin ptr {{.*}} seq_cst, align 8 __nvvm_atom_min_gen_ull((unsigned long long *)&sll, ll); + // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 2 + // CHECK-NEXT: extractvalue { i16, i1 } {{%[0-9]+}}, 0 + __nvvm_atom_cas_gen_us(ip, 0, i); // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 4 // CHECK-NEXT: extractvalue { i32, i1
[clang] [clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) (PR #101305)
https://github.com/alexey-bataev approved this pull request. LG https://github.com/llvm/llvm-project/pull/101305 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][NFC] Remove unneeded defining name of `vundefined` (PR #101643)
https://github.com/wangpc-pp commented: I don't think this will be better. We may keep these names so that these code can be self-explanatory. https://github.com/llvm/llvm-project/pull/101643 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][clang] Remove unused base type in `vfncvt` (PR #101646)
https://github.com/wangpc-pp approved this pull request. Make sense to me. (Do we have a way to test these generated builtins?) https://github.com/llvm/llvm-project/pull/101646 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
https://github.com/steakhal requested changes to this pull request. https://github.com/llvm/llvm-project/pull/101647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
@@ -30,3 +30,10 @@ void f3(void *dest) { void *src = __builtin_alloca(5); memcpy(dest, src, 1); // expected-warning{{2nd function call argument is a pointer to uninitialized value}} } + +// Reproduce crash from GH#94496. When array is used as subcript to another array, CSA cannot model it +// and should just assume it's unknown and do not crash. +void f4(char *array) { + char b[4] = {0}; + array[__builtin_bit_cast(int, b)] = 0x10; // no crash steakhal wrote: Please enable the `debug.ExprInspection` checker too, and then forward declare (but not define) the `void clang_analyzer_dump_int(int); ```suggestion clang_analyzer_dump_int(__builtin_bit_cast(int, b)); // expected-warning {{Unknown}} array[__builtin_bit_cast(int, b)] = 0x10; // no crash ``` Hold on. Shouldn't we pin the target triple to be able to safely assume that a sizeof `int` is 4 chars? Consider pinning the target using `-triple xxx` in the RUN line. https://github.com/llvm/llvm-project/pull/101647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
@@ -472,7 +472,19 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset, const auto *ElemR = dyn_cast(BaseRegion); // Convert the offset to the appropriate size and signedness. - Offset = svalBuilder.convertToArrayIndex(Offset).castAs(); + auto Off = svalBuilder.convertToArrayIndex(Offset).getAs(); steakhal wrote: ```suggestion Offset = svalBuilder.convertToArrayIndex(Offset).getAs().value_or(UnknownVal()); ``` https://github.com/llvm/llvm-project/pull/101647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
@@ -472,7 +472,19 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset, const auto *ElemR = dyn_cast(BaseRegion); // Convert the offset to the appropriate size and signedness. - Offset = svalBuilder.convertToArrayIndex(Offset).castAs(); + auto Off = svalBuilder.convertToArrayIndex(Offset).getAs(); + if (!Off) { +// Handle cases when LazyCompoundVal is used for an array index. +// Such case is possible if code does: +// +// char b[4]; +// a[__builtin_bitcast(int, b)]; +// steakhal wrote: ```suggestion // char b[4]; // a[__builtin_bitcast(int, b)]; ``` https://github.com/llvm/llvm-project/pull/101647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Restore recognition of mutex methods (PR #101511)
=?utf-8?q?Don=C3=A1t?= Nagy Message-ID: In-Reply-To: https://github.com/steakhal approved this pull request. Let's merge this, and backport it into clang-19. I'll deal with that. https://github.com/llvm/llvm-project/pull/101511 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) (PR #101305)
jtb20 wrote: Thank you! I don't have commit access, so do you mind committing it for me please? https://github.com/llvm/llvm-project/pull/101305 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python] Fix `get_exception_specification_kind` (PR #101548)
DeinAlptraum wrote: Could you merge this for me? On related note, do you think my contributions would count for "a track record of submitting high quality patches", i.e. should I apply for commit access? https://github.com/llvm/llvm-project/pull/101548 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 99ae2ed - [analyzer] Restore recognition of mutex methods (#101511)
Author: Donát Nagy Date: 2024-08-02T12:43:06+02:00 New Revision: 99ae2edc2592e602b0eb5a287f4d003aa3902440 URL: https://github.com/llvm/llvm-project/commit/99ae2edc2592e602b0eb5a287f4d003aa3902440 DIFF: https://github.com/llvm/llvm-project/commit/99ae2edc2592e602b0eb5a287f4d003aa3902440.diff LOG: [analyzer] Restore recognition of mutex methods (#101511) Before commit 705788c the checker alpha.unix.BlockInCriticalSection "recognized" the methods `std::mutex::lock` and `std::mutex::unlock` with an extremely trivial check that accepted any function (or method) named lock/unlock. To avoid matching unrelated user-defined function, this was refined to a check that also requires the presence of "std" and "mutex" as distinct parts of the qualified name. However, as #99628 reported, there are standard library implementations where some methods of `std::mutex` are inherited from an implementation detail base class and the new code wasn't able to recognize these methods, which led to emitting false positive reports. As a workaround, this commit partially restores the old behavior by omitting the check for the class name. In the future, it would be good to replace this hack with a solution which ensures that `CallDescription` understands inherited methods. Added: clang/test/Analysis/block-in-critical-section-inheritance.cpp Modified: clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp index 40f7e9cede1f1..4cd2f2802f30c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp @@ -147,10 +147,18 @@ using MutexDescriptor = class BlockInCriticalSectionChecker : public Checker { private: const std::array MutexDescriptors{ - MemberMutexDescriptor({/*MatchAs=*/CDM::CXXMethod, - /*QualifiedName=*/{"std", "mutex", "lock"}, - /*RequiredArgs=*/0}, -{CDM::CXXMethod, {"std", "mutex", "unlock"}, 0}), + // NOTE: There are standard library implementations where some methods + // of `std::mutex` are inherited from an implementation detail base + // class, and those aren't matched by the name specification {"std", + // "mutex", "lock"}. + // As a workaround here we omit the class name and only require the + // presence of the name parts "std" and "lock"/"unlock". + // TODO: Ensure that CallDescription understands inherited methods. + MemberMutexDescriptor( + {/*MatchAs=*/CDM::CXXMethod, + /*QualifiedName=*/{"std", /*"mutex",*/ "lock"}, + /*RequiredArgs=*/0}, + {CDM::CXXMethod, {"std", /*"mutex",*/ "unlock"}, 0}), FirstArgMutexDescriptor({CDM::CLibrary, {"pthread_mutex_lock"}, 1}, {CDM::CLibrary, {"pthread_mutex_unlock"}, 1}), FirstArgMutexDescriptor({CDM::CLibrary, {"mtx_lock"}, 1}, diff --git a/clang/test/Analysis/block-in-critical-section-inheritance.cpp b/clang/test/Analysis/block-in-critical-section-inheritance.cpp new file mode 100644 index 0..db20df8c60a5c --- /dev/null +++ b/clang/test/Analysis/block-in-critical-section-inheritance.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_analyze_cc1 \ +// RUN: -analyzer-checker=unix.BlockInCriticalSection \ +// RUN: -std=c++11 \ +// RUN: -analyzer-output text \ +// RUN: -verify %s + +unsigned int sleep(unsigned int seconds) {return 0;} +namespace std { +// There are some standard library implementations where some mutex methods +// come from an implementation detail base class. We need to ensure that these +// are matched correctly. +class __mutex_base { +public: + void lock(); +}; +class mutex : public __mutex_base{ +public: + void unlock(); + bool try_lock(); +}; +} // namespace std + +void gh_99628() { + std::mutex m; + m.lock(); + // expected-note@-1 {{Entering critical section here}} + sleep(10); + // expected-warning@-1 {{Call to blocking function 'sleep' inside of critical section}} + // expected-note@-2 {{Call to blocking function 'sleep' inside of critical section}} + m.unlock(); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Restore recognition of mutex methods (PR #101511)
=?utf-8?q?Donát?= Nagy Message-ID: In-Reply-To: https://github.com/steakhal closed https://github.com/llvm/llvm-project/pull/101511 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Remove unused arg (PR #101650)
https://github.com/chestnykh created https://github.com/llvm/llvm-project/pull/101650 `BuiltinID` is not used inside `CheckBuiltinTargetInSupported` >From 0f724e3aacde40f5d3d06c3e1082667dec36656b Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 2 Aug 2024 13:44:00 +0300 Subject: [PATCH] [NFC][Clang] Remove unused arg BuiltinID is not used inside `CheckBuiltinTargetInSupported` --- clang/lib/Sema/SemaChecking.cpp | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index bb30b1e289a1c..eb816816d2d07 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1862,7 +1862,7 @@ static bool CheckBuiltinTargetNotInUnsupported( // Emit an error and return true if the current architecture is not in the list // of supported architectures. static bool -CheckBuiltinTargetInSupported(Sema &S, unsigned BuiltinID, CallExpr *TheCall, +CheckBuiltinTargetInSupported(Sema &S, CallExpr *TheCall, ArrayRef SupportedArchs) { llvm::Triple::ArchType CurArch = S.getASTContext().getTargetInfo().getTriple().getArch(); @@ -2095,6 +2095,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, } FPOptions FPO; + switch (BuiltinID) { case Builtin::BI__builtin_cpu_supports: case Builtin::BI__builtin_cpu_is: @@ -2151,7 +2152,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI_interlockedbittestandreset_rel: case Builtin::BI_interlockedbittestandreset_nf: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64})) return ExprError(); break; @@ -2164,7 +2165,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI_interlockedbittestandreset64: case Builtin::BI_interlockedbittestandset64: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::x86_64, llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64, llvm::Triple::amdgcn})) return ExprError(); @@ -2172,7 +2173,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI__builtin_set_flt_rounds: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::x86, llvm::Triple::x86_64, llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64, llvm::Triple::amdgcn})) return ExprError(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Remove unused arg (PR #101650)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Dmitry Chestnykh (chestnykh) Changes `BuiltinID` is not used inside `CheckBuiltinTargetInSupported` --- Full diff: https://github.com/llvm/llvm-project/pull/101650.diff 1 Files Affected: - (modified) clang/lib/Sema/SemaChecking.cpp (+5-4) ``diff diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index bb30b1e289a1c..eb816816d2d07 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1862,7 +1862,7 @@ static bool CheckBuiltinTargetNotInUnsupported( // Emit an error and return true if the current architecture is not in the list // of supported architectures. static bool -CheckBuiltinTargetInSupported(Sema &S, unsigned BuiltinID, CallExpr *TheCall, +CheckBuiltinTargetInSupported(Sema &S, CallExpr *TheCall, ArrayRef SupportedArchs) { llvm::Triple::ArchType CurArch = S.getASTContext().getTargetInfo().getTriple().getArch(); @@ -2095,6 +2095,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, } FPOptions FPO; + switch (BuiltinID) { case Builtin::BI__builtin_cpu_supports: case Builtin::BI__builtin_cpu_is: @@ -2151,7 +2152,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI_interlockedbittestandreset_rel: case Builtin::BI_interlockedbittestandreset_nf: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64})) return ExprError(); break; @@ -2164,7 +2165,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI_interlockedbittestandreset64: case Builtin::BI_interlockedbittestandset64: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::x86_64, llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64, llvm::Triple::amdgcn})) return ExprError(); @@ -2172,7 +2173,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI__builtin_set_flt_rounds: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::x86, llvm::Triple::x86_64, llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64, llvm::Triple::amdgcn})) return ExprError(); `` https://github.com/llvm/llvm-project/pull/101650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Remove unused arg (PR #101650)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/101650 >From 0f724e3aacde40f5d3d06c3e1082667dec36656b Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 2 Aug 2024 13:44:00 +0300 Subject: [PATCH 1/2] [NFC][Clang] Remove unused arg BuiltinID is not used inside `CheckBuiltinTargetInSupported` --- clang/lib/Sema/SemaChecking.cpp | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index bb30b1e289a1c..eb816816d2d07 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1862,7 +1862,7 @@ static bool CheckBuiltinTargetNotInUnsupported( // Emit an error and return true if the current architecture is not in the list // of supported architectures. static bool -CheckBuiltinTargetInSupported(Sema &S, unsigned BuiltinID, CallExpr *TheCall, +CheckBuiltinTargetInSupported(Sema &S, CallExpr *TheCall, ArrayRef SupportedArchs) { llvm::Triple::ArchType CurArch = S.getASTContext().getTargetInfo().getTriple().getArch(); @@ -2095,6 +2095,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, } FPOptions FPO; + switch (BuiltinID) { case Builtin::BI__builtin_cpu_supports: case Builtin::BI__builtin_cpu_is: @@ -2151,7 +2152,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI_interlockedbittestandreset_rel: case Builtin::BI_interlockedbittestandreset_nf: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64})) return ExprError(); break; @@ -2164,7 +2165,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI_interlockedbittestandreset64: case Builtin::BI_interlockedbittestandset64: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::x86_64, llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64, llvm::Triple::amdgcn})) return ExprError(); @@ -2172,7 +2173,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI__builtin_set_flt_rounds: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::x86, llvm::Triple::x86_64, llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64, llvm::Triple::amdgcn})) return ExprError(); >From 00158bc570838cff376af2794fb7fff07a4f31f6 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 2 Aug 2024 13:47:24 +0300 Subject: [PATCH 2/2] [clang] Remove unneeded newline --- clang/lib/Sema/SemaChecking.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index eb816816d2d07..ed0eea9763b2a 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -2095,7 +2095,6 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, } FPOptions FPO; - switch (BuiltinID) { case Builtin::BI__builtin_cpu_supports: case Builtin::BI__builtin_cpu_is: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
@@ -472,7 +472,19 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset, const auto *ElemR = dyn_cast(BaseRegion); // Convert the offset to the appropriate size and signedness. - Offset = svalBuilder.convertToArrayIndex(Offset).castAs(); + auto Off = svalBuilder.convertToArrayIndex(Offset).getAs(); pskrgag wrote: This does not work, since it is not possible to cast `UnknownVal` to `NoLoc` https://github.com/llvm/llvm-project/pull/101647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Restore recognition of mutex methods (PR #101511)
NagyDonat wrote: > Let's merge this, and backport it into clang-19. I'll deal with that. Thanks! https://github.com/llvm/llvm-project/pull/101511 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Restore recognition of mutex methods (PR #101511)
=?utf-8?q?Don=C3=A1t?= Nagy Message-ID: In-Reply-To: steakhal wrote: Backport PR in https://github.com/llvm/llvm-project/pull/101651 https://github.com/llvm/llvm-project/pull/101511 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #101126)
https://github.com/vikramRH updated https://github.com/llvm/llvm-project/pull/101126 >From 690901f2370381285afa7cf7c2f7401d89e568f6 Mon Sep 17 00:00:00 2001 From: Vikram Date: Mon, 29 Jul 2024 08:56:07 -0400 Subject: [PATCH 1/2] [clang][ExprConst] allow single element access of vector object to be constant expression --- clang/docs/ReleaseNotes.rst | 3 + clang/lib/AST/ExprConstant.cpp| 102 +- clang/lib/AST/Interp/State.h | 3 +- clang/test/AST/Interp/builtin-functions.cpp | 26 ++--- clang/test/AST/Interp/vectors.cpp | 50 - clang/test/CodeGenCXX/temporaries.cpp | 41 --- .../constexpr-vectors-access-elements.cpp | 29 + 7 files changed, 190 insertions(+), 64 deletions(-) create mode 100644 clang/test/SemaCXX/constexpr-vectors-access-elements.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ddad083571eb1..2179aaea12387 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -64,6 +64,9 @@ sections with improvements to Clang's support for those languages. C++ Language Changes +- Allow single element access of vector object to be constant expression. + Supports the `V.xyzw` syntax and other tidbits as seen in OpenCL. + Selecting multiple elements is left as a future work. C++17 Feature Support ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 558e20ed3e423..08f49ac896153 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -222,6 +222,11 @@ namespace { ArraySize = 2; MostDerivedLength = I + 1; IsArray = true; + } else if (const auto *VT = Type->getAs()) { +Type = VT->getElementType(); +ArraySize = VT->getNumElements(); +MostDerivedLength = I + 1; +IsArray = true; } else if (const FieldDecl *FD = getAsField(Path[I])) { Type = FD->getType(); ArraySize = 0; @@ -268,7 +273,6 @@ namespace { /// If the current array is an unsized array, the value of this is /// undefined. uint64_t MostDerivedArraySize; - /// The type of the most derived object referred to by this address. QualType MostDerivedType; @@ -442,6 +446,16 @@ namespace { MostDerivedArraySize = 2; MostDerivedPathLength = Entries.size(); } + +void addVectorElementUnchecked(QualType EltTy, uint64_t Size, + uint64_t Idx) { + Entries.push_back(PathEntry::ArrayIndex(Idx)); + MostDerivedType = EltTy; + MostDerivedPathLength = Entries.size(); + MostDerivedArraySize = 0; + MostDerivedIsArrayElement = false; +} + void diagnoseUnsizedArrayPointerArithmetic(EvalInfo &Info, const Expr *E); void diagnosePointerArithmetic(EvalInfo &Info, const Expr *E, const APSInt &N); @@ -1737,6 +1751,11 @@ namespace { if (checkSubobject(Info, E, Imag ? CSK_Imag : CSK_Real)) Designator.addComplexUnchecked(EltTy, Imag); } +void addVectorElement(EvalInfo &Info, const Expr *E, QualType EltTy, + uint64_t Size, uint64_t Idx) { + if (checkSubobject(Info, E, CSK_VectorElement)) +Designator.addVectorElementUnchecked(EltTy, Size, Idx); +} void clearIsNullPointer() { IsNullPtr = false; } @@ -3310,6 +3329,19 @@ static bool HandleLValueComplexElement(EvalInfo &Info, const Expr *E, return true; } +static bool HandleLValueVectorElement(EvalInfo &Info, const Expr *E, + LValue &LVal, QualType EltTy, + uint64_t Size, uint64_t Idx) { + if (Idx) { +CharUnits SizeOfElement; +if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfElement)) + return false; +LVal.Offset += SizeOfElement * Idx; + } + LVal.addVectorElement(Info, E, EltTy, Size, Idx); + return true; +} + /// Try to evaluate the initializer for a variable declaration. /// /// \param Info Information about the ongoing evaluation. @@ -3855,6 +3887,19 @@ findSubobject(EvalInfo &Info, const Expr *E, const CompleteObject &Obj, return handler.found(Index ? O->getComplexFloatImag() : O->getComplexFloatReal(), ObjType); } +} else if (const auto *VT = ObjType->getAs()) { + uint64_t Index = Sub.Entries[I].getAsArrayIndex(); + if (Index >= VT->getNumElements()) { +if (Info.getLangOpts().CPlusPlus11) + Info.FFDiag(E, diag::note_constexpr_access_past_end) + << handler.AccessKind; +else + Info.FFDiag(E); +return handler.failed(); + } + ObjType = VT->getElementType(); + assert(I == N - 1 && "extracting subobject of scalar?"); + return handler.found(O->getVectorElt(Index), ObjType); } else if
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
@@ -30,3 +30,10 @@ void f3(void *dest) { void *src = __builtin_alloca(5); memcpy(dest, src, 1); // expected-warning{{2nd function call argument is a pointer to uninitialized value}} } + +// Reproduce crash from GH#94496. When array is used as subcript to another array, CSA cannot model it +// and should just assume it's unknown and do not crash. +void f4(char *array) { + char b[4] = {0}; + array[__builtin_bit_cast(int, b)] = 0x10; // no crash pskrgag wrote: Indeed, I forgot about the that! Also added static_assert to make error a bit more understandable just in case smth gets broken. Thank you, fixed! https://github.com/llvm/llvm-project/pull/101647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
https://github.com/pskrgag updated https://github.com/llvm/llvm-project/pull/101647 >From d94748f76ca793bf40cb57dd904d487c51bdcd40 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin Date: Fri, 2 Aug 2024 12:02:11 +0300 Subject: [PATCH 1/3] clang/csa: fix crash on using bitcast(, ) as array subscript --- clang/lib/StaticAnalyzer/Core/Store.cpp | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Core/Store.cpp b/clang/lib/StaticAnalyzer/Core/Store.cpp index 67ca61bb56ba2..72587ef31a17c 100644 --- a/clang/lib/StaticAnalyzer/Core/Store.cpp +++ b/clang/lib/StaticAnalyzer/Core/Store.cpp @@ -472,7 +472,19 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset, const auto *ElemR = dyn_cast(BaseRegion); // Convert the offset to the appropriate size and signedness. - Offset = svalBuilder.convertToArrayIndex(Offset).castAs(); + auto Off = svalBuilder.convertToArrayIndex(Offset).getAs(); + if (!Off) { +// Handle cases when LazyCompoundVal is used for an array index. +// Such case is possible if code does: +// +// char b[4]; +// a[__builtin_bitcast(int, b)]; +// +// Return UnknownVal, since we cannot model it. +return UnknownVal(); + } + + Offset = Off.value(); if (!ElemR) { // If the base region is not an ElementRegion, create one. >From 515520dde7eb4d0365b0eed4627b19d4dedde5d7 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin Date: Fri, 2 Aug 2024 12:14:11 +0300 Subject: [PATCH 2/3] clang/csa: add test case for array[bitcast(, )] --- clang/test/Analysis/exercise-ps.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/clang/test/Analysis/exercise-ps.c b/clang/test/Analysis/exercise-ps.c index d1e1771afddb5..9bba16c282967 100644 --- a/clang/test/Analysis/exercise-ps.c +++ b/clang/test/Analysis/exercise-ps.c @@ -30,3 +30,10 @@ void f3(void *dest) { void *src = __builtin_alloca(5); memcpy(dest, src, 1); // expected-warning{{2nd function call argument is a pointer to uninitialized value}} } + +// Reproduce crash from GH#94496. When array is used as subcript to another array, CSA cannot model it +// and should just assume it's unknown and do not crash. +void f4(char *array) { + char b[4] = {0}; + array[__builtin_bit_cast(int, b)] = 0x10; // no crash +} >From 514d89e411285451625a4adad55eedea0e850cdc Mon Sep 17 00:00:00 2001 From: Pavel Skripkin Date: Fri, 2 Aug 2024 13:56:10 +0300 Subject: [PATCH 3/3] clang/csa: pin triple with sizeof(int) == 4 in exercise-ps and fix style --- clang/lib/StaticAnalyzer/Core/Store.cpp | 2 -- clang/test/Analysis/exercise-ps.c | 8 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/Store.cpp b/clang/lib/StaticAnalyzer/Core/Store.cpp index 72587ef31a17c..b436dd746d21f 100644 --- a/clang/lib/StaticAnalyzer/Core/Store.cpp +++ b/clang/lib/StaticAnalyzer/Core/Store.cpp @@ -476,10 +476,8 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset, if (!Off) { // Handle cases when LazyCompoundVal is used for an array index. // Such case is possible if code does: -// // char b[4]; // a[__builtin_bitcast(int, b)]; -// // Return UnknownVal, since we cannot model it. return UnknownVal(); } diff --git a/clang/test/Analysis/exercise-ps.c b/clang/test/Analysis/exercise-ps.c index 9bba16c282967..4b483b1a88a2f 100644 --- a/clang/test/Analysis/exercise-ps.c +++ b/clang/test/Analysis/exercise-ps.c @@ -1,5 +1,6 @@ -// RUN: %clang_analyze_cc1 %s -verify -Wno-error=implicit-function-declaration \ -// RUN: -analyzer-checker=core,unix.Malloc \ +// RUN: %clang_analyze_cc1 %s -triple=x86_64-unknown-linux \ +// RUN: -verify -Wno-error=implicit-function-declaration \ +// RUN: -analyzer-checker=core,unix.Malloc,debug.ExprInspection \ // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=true // // Just exercise the analyzer on code that has at one point caused issues @@ -35,5 +36,8 @@ void f3(void *dest) { // and should just assume it's unknown and do not crash. void f4(char *array) { char b[4] = {0}; + + _Static_assert(sizeof(int) == 4, "Wrong triple for the test"); + array[__builtin_bit_cast(int, b)] = 0x10; // no crash } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Static analyzer] fix crash on using `bitcast(, )` as array subscript (PR #101647)
@@ -30,3 +30,10 @@ void f3(void *dest) { void *src = __builtin_alloca(5); memcpy(dest, src, 1); // expected-warning{{2nd function call argument is a pointer to uninitialized value}} } + +// Reproduce crash from GH#94496. When array is used as subcript to another array, CSA cannot model it +// and should just assume it's unknown and do not crash. +void f4(char *array) { + char b[4] = {0}; + array[__builtin_bit_cast(int, b)] = 0x10; // no crash pskrgag wrote: Also `clang_analyzer_dump_int(__builtin_bit_cast(int, b));` ends up with `lazyCompoundVal{0x18602338,b}` . I guess, you meant `clang_analyzer_dump_int(array[__builtin_bit_cast(int, b)]);` ? https://github.com/llvm/llvm-project/pull/101647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Surface error for plain return statement in coroutine earlier (PR #100985)
https://github.com/ivanaivanovska updated https://github.com/llvm/llvm-project/pull/100985 >From d35544d971f073f98fba047cfcbe3cfe92dd78c4 Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Mon, 29 Jul 2024 08:08:00 + Subject: [PATCH 1/4] Surface error for plain return statement in coroutine earlier --- clang/lib/Sema/SemaCoroutine.cpp | 2 +- clang/lib/Sema/SemaStmt.cpp | 10 + clang/test/SemaCXX/coroutines.cpp | 35 +++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp index 81334c817b2af..87d0d44c5af66 100644 --- a/clang/lib/Sema/SemaCoroutine.cpp +++ b/clang/lib/Sema/SemaCoroutine.cpp @@ -1120,7 +1120,7 @@ void Sema::CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body) { // [stmt.return.coroutine]p1: // A coroutine shall not enclose a return statement ([stmt.return]). - if (Fn->FirstReturnLoc.isValid()) { + if (Fn->FirstReturnLoc.isValid() && Fn->FirstReturnLoc < Fn->FirstCoroutineStmtLoc) { assert(Fn->FirstCoroutineStmtLoc.isValid() && "first coroutine location not set"); Diag(Fn->FirstReturnLoc, diag::err_return_in_coroutine); diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 34d2d398f244d..3909892ef0a6f 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3747,6 +3747,16 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Diag(ReturnLoc, diag::err_acc_branch_in_out_compute_construct) << /*return*/ 1 << /*out of */ 0); + // using plain return in a coroutine is not allowed. + FunctionScopeInfo *FSI = getCurFunction(); + if (getLangOpts().Coroutines && FSI->isCoroutine()) { +assert(FSI->FirstCoroutineStmtLoc.isValid() && + "first coroutine location not set"); +Diag(ReturnLoc, diag::err_return_in_coroutine); +Diag(FSI->FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) +<< FSI->getFirstCoroutineStmtKeyword(); + } + StmtResult R = BuildReturnStmt(ReturnLoc, RetVal.get(), /*AllowRecovery=*/true); if (R.isInvalid() || ExprEvalContexts.back().isDiscardedStatementContext()) diff --git a/clang/test/SemaCXX/coroutines.cpp b/clang/test/SemaCXX/coroutines.cpp index 2292932583fff..b4f362c621929 100644 --- a/clang/test/SemaCXX/coroutines.cpp +++ b/clang/test/SemaCXX/coroutines.cpp @@ -154,12 +154,15 @@ namespace std { template struct coroutine_handle { static coroutine_handle from_address(void *) noexcept; + static coroutine_handle from_promise(PromiseType &promise); }; template <> struct coroutine_handle { template coroutine_handle(coroutine_handle) noexcept; static coroutine_handle from_address(void *) noexcept; + template + static coroutine_handle from_promise(PromiseType &promise); }; } // namespace std @@ -291,6 +294,38 @@ void mixed_coreturn_template2(bool b, T) { return; // expected-error {{not allowed in coroutine}} } +struct promise_handle; + +struct Handle : std::coroutine_handle { // expected-note 2{{candidate constructor (the implicit copy constructor) not viable}} +// expected-note@-1 2{{candidate constructor (the implicit move constructor) not viable}} +using promise_type = promise_handle; +}; + +struct promise_handle { +Handle get_return_object() noexcept { + { return Handle(std::coroutine_handle::from_promise(*this)); } +} +suspend_never initial_suspend() const noexcept { return {}; } +suspend_never final_suspend() const noexcept { return {}; } +void return_void() const noexcept {} +void unhandled_exception() const noexcept {} +}; + +Handle mixed_return_value() { + co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}} + return 0; // expected-error {{return statement not allowed in coroutine}} + // expected-error@-1 {{no viable conversion from returned value of type}} +} + +Handle mixed_return_value_return_first(bool b) { + if (b) { +return 0; // expected-error {{no viable conversion from returned value of type}} +// expected-error@-1 {{return statement not allowed in coroutine}} +} +co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}} +co_return 0; // expected-error {{no member named 'return_value' in 'promise_handle'}} +} + struct CtorDtor { CtorDtor() { co_yield 0; // expected-error {{'co_yield' cannot be used in a constructor}} >From f0f6a1a089ec10fae0010dd93456a844df5693af Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Thu, 1 Aug 2024 08:34:36 + Subject: [PATCH 2/4] Applied fixes related to the comments in the PR. --- clang/lib/Sema/SemaCoroutine.cpp | 27 + clang/lib/Sema/SemaStmt.cpp | 2 +- clang/test/SemaCXX/coroutines.cpp | 40 +-- 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/cl
[clang] Surface error for plain return statement in coroutine earlier (PR #100985)
@@ -684,6 +684,19 @@ bool Sema::checkFinalSuspendNoThrow(const Stmt *FinalSuspend) { return ThrowingDecls.empty(); } +// [stmt.return.coroutine]p1: +// A coroutine shall not enclose a return statement ([stmt.return]). +static void checkReturnStmtInCoroutine(Sema &S, FunctionScopeInfo *FSI) { + assert (!FSI && "FunctionScopeInfo is null"); ivanaivanovska wrote: Right. No, assertions were off, so I missed it. I fixed that now. Thanks. https://github.com/llvm/llvm-project/pull/100985 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Surface error for plain return statement in coroutine earlier (PR #100985)
@@ -694,6 +707,9 @@ bool Sema::ActOnCoroutineBodyStart(Scope *SC, SourceLocation KWLoc, auto *ScopeInfo = getCurFunction(); assert(ScopeInfo->CoroutinePromise); + if (ScopeInfo->FirstCoroutineStmtLoc == KWLoc) ivanaivanovska wrote: Done. https://github.com/llvm/llvm-project/pull/100985 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Surface error for plain return statement in coroutine earlier (PR #100985)
https://github.com/ilya-biryukov approved this pull request. Thanks! The changes LG, I'll wait until premerge checks finish and merge it into mainline. https://github.com/llvm/llvm-project/pull/100985 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [OpenMP] OpenMP 5.1 "assume" directive parsing support (PR #92731)
https://github.com/jtb20 updated https://github.com/llvm/llvm-project/pull/92731 >From b3d00ab3f6457094a8ccf4df03b72976e96cd307 Mon Sep 17 00:00:00 2001 From: Julian Brown Date: Thu, 1 Aug 2024 14:49:28 -0500 Subject: [PATCH 1/8] [OpenMP][clang] Add 'holds' clause for 'omp assume' directive --- clang/include/clang/AST/OpenMPClause.h| 27 +++ clang/include/clang/AST/RecursiveASTVisitor.h | 5 clang/include/clang/Sema/SemaOpenMP.h | 4 +++ clang/lib/AST/OpenMPClause.cpp| 6 + clang/lib/AST/StmtProfile.cpp | 2 ++ clang/lib/Parse/ParseOpenMP.cpp | 6 + clang/lib/Sema/SemaOpenMP.cpp | 9 +++ clang/lib/Sema/TreeTransform.h| 17 clang/lib/Serialization/ASTReader.cpp | 8 ++ clang/lib/Serialization/ASTWriter.cpp | 5 clang/tools/libclang/CIndex.cpp | 2 ++ llvm/include/llvm/Frontend/OpenMP/OMP.td | 10 +++ 12 files changed, 101 insertions(+) diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index b029c72fa7d8f..47c2fd4400d52 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -2013,6 +2013,33 @@ class OMPMergeableClause : public OMPClause { } }; +/// This represents the 'holds' clause in the '#pragma omp assume' +/// directive. +/// +/// \code +/// #pragma omp assume holds() +/// \endcode +/// In this example directive '#pragma omp assume' has a 'holds' clause. +class OMPHoldsClause final +: public OMPOneStmtClause { + friend class OMPClauseReader; + +public: + /// Build 'holds' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + OMPHoldsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc, + SourceLocation EndLoc) + : OMPOneStmtClause(E, StartLoc, LParenLoc, EndLoc) {} + + /// Build an empty clause. + OMPHoldsClause() : OMPOneStmtClause() {} + + Expr *getExpr() const { return getStmtAs(); } + void setExpr(Expr *E) { setStmt(E); } +}; + /// This represents 'read' clause in the '#pragma omp atomic' directive. /// /// \code diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index dcf5dbf449f8b..73ece1e72bbf1 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -3480,6 +3480,11 @@ bool RecursiveASTVisitor::VisitOMPAcqRelClause(OMPAcqRelClause *) { return true; } +template +bool RecursiveASTVisitor::VisitOMPHoldsClause(OMPHoldsClause *) { + return true; +} + template bool RecursiveASTVisitor::VisitOMPAcquireClause(OMPAcquireClause *) { return true; diff --git a/clang/include/clang/Sema/SemaOpenMP.h b/clang/include/clang/Sema/SemaOpenMP.h index aa61dae9415e2..7c793cf3077a6 100644 --- a/clang/include/clang/Sema/SemaOpenMP.h +++ b/clang/include/clang/Sema/SemaOpenMP.h @@ -940,6 +940,10 @@ class SemaOpenMP : public SemaBase { SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); + /// Called on well-formed 'holds' clause. + OMPClause *ActOnOpenMPHoldsClause(Expr *E, SourceLocation StartLoc, +SourceLocation LParenLoc, +SourceLocation EndLoc); OMPClause *ActOnOpenMPSingleExprWithArgClause( OpenMPClauseKind Kind, ArrayRef Arguments, Expr *Expr, diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp index 042a5df5906ca..e83c81136c34b 100644 --- a/clang/lib/AST/OpenMPClause.cpp +++ b/clang/lib/AST/OpenMPClause.cpp @@ -1937,6 +1937,12 @@ void OMPClausePrinter::VisitOMPFailClause(OMPFailClause *Node) { } } +void OMPClausePrinter::VisitOMPHoldsClause(OMPHoldsClause *Node) { + OS << "holds("; + Node->getExpr()->printPretty(OS, nullptr, Policy, 0); + OS << ")"; +} + void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) { OS << "seq_cst"; } diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index f1e723b4242ee..97e4b3749f94c 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -584,6 +584,8 @@ void OMPClauseProfiler::VisitOMPCompareClause(const OMPCompareClause *) {} void OMPClauseProfiler::VisitOMPFailClause(const OMPFailClause *) {} +void OMPClauseProfiler::VisitOMPHoldsClause(const OMPHoldsClause *) {} + void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {} void OMPClauseProfiler::VisitOMPAcqRelClause(const OMPAcqRelClause *) {} diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index e975e96c5c7e4..afcbc93696de2 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -3206,6 +3206,9
[clang] Surface error for plain return statement in coroutine earlier (PR #100985)
https://github.com/ilya-biryukov updated https://github.com/llvm/llvm-project/pull/100985 >From d35544d971f073f98fba047cfcbe3cfe92dd78c4 Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Mon, 29 Jul 2024 08:08:00 + Subject: [PATCH 1/4] Surface error for plain return statement in coroutine earlier --- clang/lib/Sema/SemaCoroutine.cpp | 2 +- clang/lib/Sema/SemaStmt.cpp | 10 + clang/test/SemaCXX/coroutines.cpp | 35 +++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp index 81334c817b2af..87d0d44c5af66 100644 --- a/clang/lib/Sema/SemaCoroutine.cpp +++ b/clang/lib/Sema/SemaCoroutine.cpp @@ -1120,7 +1120,7 @@ void Sema::CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body) { // [stmt.return.coroutine]p1: // A coroutine shall not enclose a return statement ([stmt.return]). - if (Fn->FirstReturnLoc.isValid()) { + if (Fn->FirstReturnLoc.isValid() && Fn->FirstReturnLoc < Fn->FirstCoroutineStmtLoc) { assert(Fn->FirstCoroutineStmtLoc.isValid() && "first coroutine location not set"); Diag(Fn->FirstReturnLoc, diag::err_return_in_coroutine); diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 34d2d398f244d..3909892ef0a6f 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3747,6 +3747,16 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Diag(ReturnLoc, diag::err_acc_branch_in_out_compute_construct) << /*return*/ 1 << /*out of */ 0); + // using plain return in a coroutine is not allowed. + FunctionScopeInfo *FSI = getCurFunction(); + if (getLangOpts().Coroutines && FSI->isCoroutine()) { +assert(FSI->FirstCoroutineStmtLoc.isValid() && + "first coroutine location not set"); +Diag(ReturnLoc, diag::err_return_in_coroutine); +Diag(FSI->FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) +<< FSI->getFirstCoroutineStmtKeyword(); + } + StmtResult R = BuildReturnStmt(ReturnLoc, RetVal.get(), /*AllowRecovery=*/true); if (R.isInvalid() || ExprEvalContexts.back().isDiscardedStatementContext()) diff --git a/clang/test/SemaCXX/coroutines.cpp b/clang/test/SemaCXX/coroutines.cpp index 2292932583fff..b4f362c621929 100644 --- a/clang/test/SemaCXX/coroutines.cpp +++ b/clang/test/SemaCXX/coroutines.cpp @@ -154,12 +154,15 @@ namespace std { template struct coroutine_handle { static coroutine_handle from_address(void *) noexcept; + static coroutine_handle from_promise(PromiseType &promise); }; template <> struct coroutine_handle { template coroutine_handle(coroutine_handle) noexcept; static coroutine_handle from_address(void *) noexcept; + template + static coroutine_handle from_promise(PromiseType &promise); }; } // namespace std @@ -291,6 +294,38 @@ void mixed_coreturn_template2(bool b, T) { return; // expected-error {{not allowed in coroutine}} } +struct promise_handle; + +struct Handle : std::coroutine_handle { // expected-note 2{{candidate constructor (the implicit copy constructor) not viable}} +// expected-note@-1 2{{candidate constructor (the implicit move constructor) not viable}} +using promise_type = promise_handle; +}; + +struct promise_handle { +Handle get_return_object() noexcept { + { return Handle(std::coroutine_handle::from_promise(*this)); } +} +suspend_never initial_suspend() const noexcept { return {}; } +suspend_never final_suspend() const noexcept { return {}; } +void return_void() const noexcept {} +void unhandled_exception() const noexcept {} +}; + +Handle mixed_return_value() { + co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}} + return 0; // expected-error {{return statement not allowed in coroutine}} + // expected-error@-1 {{no viable conversion from returned value of type}} +} + +Handle mixed_return_value_return_first(bool b) { + if (b) { +return 0; // expected-error {{no viable conversion from returned value of type}} +// expected-error@-1 {{return statement not allowed in coroutine}} +} +co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}} +co_return 0; // expected-error {{no member named 'return_value' in 'promise_handle'}} +} + struct CtorDtor { CtorDtor() { co_yield 0; // expected-error {{'co_yield' cannot be used in a constructor}} >From f0f6a1a089ec10fae0010dd93456a844df5693af Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Thu, 1 Aug 2024 08:34:36 + Subject: [PATCH 2/4] Applied fixes related to the comments in the PR. --- clang/lib/Sema/SemaCoroutine.cpp | 27 + clang/lib/Sema/SemaStmt.cpp | 2 +- clang/test/SemaCXX/coroutines.cpp | 40 +-- 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/cla
[clang] db1375f - Surface error for plain return statement in coroutine earlier (#100985)
Author: ivanaivanovska Date: 2024-08-02T13:49:11+02:00 New Revision: db1375f6d907f1af34c03b5174b7e0432f615d21 URL: https://github.com/llvm/llvm-project/commit/db1375f6d907f1af34c03b5174b7e0432f615d21 DIFF: https://github.com/llvm/llvm-project/commit/db1375f6d907f1af34c03b5174b7e0432f615d21.diff LOG: Surface error for plain return statement in coroutine earlier (#100985) When a plain return statement was used in a coroutine, the error "return statement not allowed in coroutine" was surfaced too late (e.g. after other errors in the return statement). Surfacing it earlier now, to make the issue more obvious. Added: Modified: clang/lib/Sema/SemaCoroutine.cpp clang/lib/Sema/SemaStmt.cpp clang/test/SemaCXX/coroutines.cpp Removed: diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp index 81334c817b2af..68ad6e3fd6414 100644 --- a/clang/lib/Sema/SemaCoroutine.cpp +++ b/clang/lib/Sema/SemaCoroutine.cpp @@ -684,6 +684,19 @@ bool Sema::checkFinalSuspendNoThrow(const Stmt *FinalSuspend) { return ThrowingDecls.empty(); } +// [stmt.return.coroutine]p1: +// A coroutine shall not enclose a return statement ([stmt.return]). +static void checkReturnStmtInCoroutine(Sema &S, FunctionScopeInfo *FSI) { + assert(FSI && "FunctionScopeInfo is null"); + assert(FSI->FirstCoroutineStmtLoc.isValid() && + "first coroutine location not set"); + if (FSI->FirstReturnLoc.isInvalid()) +return; + S.Diag(FSI->FirstReturnLoc, diag::err_return_in_coroutine); + S.Diag(FSI->FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) + << FSI->getFirstCoroutineStmtKeyword(); +} + bool Sema::ActOnCoroutineBodyStart(Scope *SC, SourceLocation KWLoc, StringRef Keyword) { // Ignore previous expr evaluation contexts. @@ -694,6 +707,10 @@ bool Sema::ActOnCoroutineBodyStart(Scope *SC, SourceLocation KWLoc, auto *ScopeInfo = getCurFunction(); assert(ScopeInfo->CoroutinePromise); + // Avoid duplicate errors, report only on first keyword. + if (ScopeInfo->FirstCoroutineStmtLoc == KWLoc) +checkReturnStmtInCoroutine(*this, ScopeInfo); + // If we have existing coroutine statements then we have already built // the initial and final suspend points. if (!ScopeInfo->NeedsCoroutineSuspends) @@ -801,6 +818,7 @@ ExprResult Sema::ActOnCoawaitExpr(Scope *S, SourceLocation Loc, Expr *E) { if (R.isInvalid()) return ExprError(); E = R.get(); } + ExprResult Lookup = BuildOperatorCoawaitLookupExpr(S, Loc); if (Lookup.isInvalid()) return ExprError(); @@ -1118,16 +1136,6 @@ void Sema::CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body) { if (Fn->FirstVLALoc.isValid()) Diag(Fn->FirstVLALoc, diag::err_vla_in_coroutine_unsupported); - // [stmt.return.coroutine]p1: - // A coroutine shall not enclose a return statement ([stmt.return]). - if (Fn->FirstReturnLoc.isValid()) { -assert(Fn->FirstCoroutineStmtLoc.isValid() && - "first coroutine location not set"); -Diag(Fn->FirstReturnLoc, diag::err_return_in_coroutine); -Diag(Fn->FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) -<< Fn->getFirstCoroutineStmtKeyword(); - } - // Coroutines will get splitted into pieces. The GNU address of label // extension wouldn't be meaningful in coroutines. for (AddrLabelExpr *ALE : Fn->AddrLabels) diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 34d2d398f244d..d283eaa511011 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3747,6 +3747,16 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Diag(ReturnLoc, diag::err_acc_branch_in_out_compute_construct) << /*return*/ 1 << /*out of */ 0); + // using plain return in a coroutine is not allowed. + FunctionScopeInfo *FSI = getCurFunction(); + if (FSI->FirstReturnLoc.isInvalid() && FSI->isCoroutine()) { +assert(FSI->FirstCoroutineStmtLoc.isValid() && + "first coroutine location not set"); +Diag(ReturnLoc, diag::err_return_in_coroutine); +Diag(FSI->FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) +<< FSI->getFirstCoroutineStmtKeyword(); + } + StmtResult R = BuildReturnStmt(ReturnLoc, RetVal.get(), /*AllowRecovery=*/true); if (R.isInvalid() || ExprEvalContexts.back().isDiscardedStatementContext()) diff --git a/clang/test/SemaCXX/coroutines.cpp b/clang/test/SemaCXX/coroutines.cpp index 2292932583fff..068fdab4bfe38 100644 --- a/clang/test/SemaCXX/coroutines.cpp +++ b/clang/test/SemaCXX/coroutines.cpp @@ -4,6 +4,9 @@ // RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23 %s -fcxx-exceptions -fexceptions -Wunused-result // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx14_20,cxx20_23 %s -fcxx-exceptions -fexceptions -Wunused-r
[clang] Surface error for plain return statement in coroutine earlier (PR #100985)
https://github.com/ilya-biryukov closed https://github.com/llvm/llvm-project/pull/100985 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Surface error for plain return statement in coroutine earlier (PR #100985)
github-actions[bot] wrote: @ivanaivanovska Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/100985 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [NVPTX] Support __usAtomicCAS builtin (PR #99646)
https://github.com/DenisGZM updated https://github.com/llvm/llvm-project/pull/99646 >From e2a39138a1e8a38a5c3f5c2a58cc8d009826c9a7 Mon Sep 17 00:00:00 2001 From: Denis Gerasimov Date: Fri, 19 Jul 2024 15:47:57 +0300 Subject: [PATCH 1/6] [NVPTX] Support __usAtomicCAS builtin --- clang/include/clang/Basic/BuiltinsNVPTX.def | 3 +++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +++ clang/lib/Headers/__clang_cuda_device_functions.h | 12 clang/test/CodeGen/builtins-nvptx.c | 3 +++ llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp | 2 +- llvm/lib/Target/NVPTX/NVPTXIntrinsics.td | 15 +++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/BuiltinsNVPTX.def b/clang/include/clang/Basic/BuiltinsNVPTX.def index 504314d8d96e9..3cf683a2f2129 100644 --- a/clang/include/clang/Basic/BuiltinsNVPTX.def +++ b/clang/include/clang/Basic/BuiltinsNVPTX.def @@ -829,6 +829,9 @@ BUILTIN(__nvvm_atom_xor_gen_ll, "LLiLLiD*LLi", "n") TARGET_BUILTIN(__nvvm_atom_cta_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60) TARGET_BUILTIN(__nvvm_atom_sys_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60) +TARGET_BUILTIN(__nvvm_atom_cas_gen_us, "UsUsD*UsUs", "n", SM_70) +TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_us, "UsUsD*UsUs", "n", SM_70) +TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_us, "UsUsD*UsUs", "n", SM_70) BUILTIN(__nvvm_atom_cas_gen_i, "iiD*ii", "n") TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_i, "iiD*ii", "n", SM_60) TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_i, "iiD*ii", "n", SM_60) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 3221989e14351..7dcfc2564aa6b 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -20199,6 +20199,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, case NVPTX::BI__nvvm_atom_min_gen_ull: return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMin, E); + case NVPTX::BI__nvvm_atom_cas_gen_us: case NVPTX::BI__nvvm_atom_cas_gen_i: case NVPTX::BI__nvvm_atom_cas_gen_l: case NVPTX::BI__nvvm_atom_cas_gen_ll: @@ -20390,6 +20391,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, case NVPTX::BI__nvvm_atom_sys_xor_gen_l: case NVPTX::BI__nvvm_atom_sys_xor_gen_ll: return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys, *this, E); + case NVPTX::BI__nvvm_atom_cta_cas_gen_us: case NVPTX::BI__nvvm_atom_cta_cas_gen_i: case NVPTX::BI__nvvm_atom_cta_cas_gen_l: case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: { @@ -20401,6 +20403,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, Intrinsic::nvvm_atomic_cas_gen_i_cta, {ElemTy, Ptr->getType()}), {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))}); } + case NVPTX::BI__nvvm_atom_sys_cas_gen_us: case NVPTX::BI__nvvm_atom_sys_cas_gen_i: case NVPTX::BI__nvvm_atom_sys_cas_gen_l: case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: { diff --git a/clang/lib/Headers/__clang_cuda_device_functions.h b/clang/lib/Headers/__clang_cuda_device_functions.h index f8a12cefdb81b..f66fe625a3967 100644 --- a/clang/lib/Headers/__clang_cuda_device_functions.h +++ b/clang/lib/Headers/__clang_cuda_device_functions.h @@ -529,6 +529,18 @@ __DEVICE__ void __threadfence(void) { __nvvm_membar_gl(); } __DEVICE__ void __threadfence_block(void) { __nvvm_membar_cta(); }; __DEVICE__ void __threadfence_system(void) { __nvvm_membar_sys(); }; __DEVICE__ void __trap(void) { __asm__ __volatile__("trap;"); } +__DEVICE__ unsigned short __usAtomicCAS(unsigned short *__p, unsigned short __cmp, +unsigned short __v) { + return __nvvm_atom_cas_gen_us(__p, __cmp, __v); +} +__DEVICE__ unsigned short __usAtomicCAS_block(unsigned short *__p, unsigned short __cmp, + unsigned short __v) { + return __nvvm_atom_cta_cas_gen_us(__p, __cmp, __v); +} +__DEVICE__ unsigned short __usAtomicCAS_system(unsigned short *__p, unsigned short __cmp, + unsigned short __v) { + return __nvvm_atom_sys_cas_gen_us(__p, __cmp, __v); +} __DEVICE__ unsigned int __uAtomicAdd(unsigned int *__p, unsigned int __v) { return __nvvm_atom_add_gen_i((int *)__p, __v); } diff --git a/clang/test/CodeGen/builtins-nvptx.c b/clang/test/CodeGen/builtins-nvptx.c index 75b9d6d1fe190..3ba1fabd05335 100644 --- a/clang/test/CodeGen/builtins-nvptx.c +++ b/clang/test/CodeGen/builtins-nvptx.c @@ -306,6 +306,9 @@ __device__ void nvvm_atom(float *fp, float f, double *dfp, double df, int *ip, // CHECK: atomicrmw umin ptr {{.*}} seq_cst, align 8 __nvvm_atom_min_gen_ull((unsigned long long *)&sll, ll); + // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 2 + // CHECK-NEXT: extractvalue { i16, i1 } {{%[0-9]+}}, 0 + __nvvm_atom_cas_gen_us(ip, 0, i); // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 4 // CHECK-NEXT: extractvalue { i32, i1
[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)
https://github.com/john-brawn-arm milestoned https://github.com/llvm/llvm-project/pull/99335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)
john-brawn-arm wrote: Sorry to pester you about this, but would it be possible to get this approved in time for LLVM19 RC2 on Monday? This is the last piece of GCS work and it would be nice to have it all in a single LLVM release. https://github.com/llvm/llvm-project/pull/99335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Remove unused arg (PR #101650)
https://github.com/s-barannikov approved this pull request. https://github.com/llvm/llvm-project/pull/101650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [OpenMP] Diagnostic check for imperfect loop collapse (PR #96087)
jtb20 wrote: ping? https://github.com/llvm/llvm-project/pull/96087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Ofast deprecation clarifications (PR #101005)
https://github.com/AaronBallman approved this pull request. LGTM, let's go ahead and merge this and get it backported to 19.x, thank you! https://github.com/llvm/llvm-project/pull/101005 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cb58294 - [C11] Claim conformance to WG14 N1396 (#101214)
Author: Aaron Ballman Date: 2024-08-02T08:17:40-04:00 New Revision: cb58294f86212aeff45f4a303767fcf4ac7d82ba URL: https://github.com/llvm/llvm-project/commit/cb58294f86212aeff45f4a303767fcf4ac7d82ba DIFF: https://github.com/llvm/llvm-project/commit/cb58294f86212aeff45f4a303767fcf4ac7d82ba.diff LOG: [C11] Claim conformance to WG14 N1396 (#101214) The crux of this paper is that floating point expressions can be evaluated in a wider format, but the return statement in a function should still return a value of the function's return type rather than the wider format type. Note, this is an Annex F conformance requirement and we do not currently claim conformance to Annex F, so technically we conform either way. Added: clang/test/C/C11/n1396.c Modified: clang/www/c_status.html Removed: diff --git a/clang/test/C/C11/n1396.c b/clang/test/C/C11/n1396.c new file mode 100644 index 0..6f76cfe959496 --- /dev/null +++ b/clang/test/C/C11/n1396.c @@ -0,0 +1,569 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK-X64 %s +// RUN: %clang_cc1 -triple=aarch64 -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK-AARCH64 %s +// RUN: %clang_cc1 -triple=arm -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK-ARM %s +// RUN: %clang_cc1 -triple=ppc32 -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK-PPC32 %s +// RUN: %clang_cc1 -triple=ppc64 -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK-PPC64 %s +// RUN: %clang_cc1 -triple=sparcv9 -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK-SPARCV9 %s + +/* WG14 N1396: Partial + * Wide function returns (alternate proposal) + * + * This only applies if attempting to conform to Annex F. Clang is not claiming + * conformance to Annex F, but we do aim for conformance. This means that the + * return statement converts the value to the return type of the function + * rather than return the result in a wider evaluation format. We test this by + * using a return statement without a cast and ensure it produces the same IR + * as a return statement with an explicit cast. + * + * Clang conforms on targets other than 32-bit x86 (without SSE2), which is why + * support is only partial. Once support for that target is dropped, Clang + * should be conforming to this paper on all targets. See + * https://github.com/llvm/llvm-project/issues/44218 and other linked issues + * for further details. + * + */ + +// CHECK-X64-LABEL: define dso_local float @extended_float_func( +// CHECK-X64-SAME: float noundef [[X:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK-X64-NEXT: [[ENTRY:.*:]] +// CHECK-X64-NEXT:[[X_ADDR:%.*]] = alloca float, align 4 +// CHECK-X64-NEXT:store float [[X]], ptr [[X_ADDR]], align 4 +// CHECK-X64-NEXT:[[TMP0:%.*]] = load float, ptr [[X_ADDR]], align 4 +// CHECK-X64-NEXT:[[CONV:%.*]] = fpext float [[TMP0]] to x86_fp80 +// CHECK-X64-NEXT:[[MUL:%.*]] = fmul x86_fp80 [[CONV]], 0xK3FFF8000 +// CHECK-X64-NEXT:[[CONV1:%.*]] = fptrunc x86_fp80 [[MUL]] to float +// CHECK-X64-NEXT:ret float [[CONV1]] +// +// CHECK-AARCH64-LABEL: define dso_local float @extended_float_func( +// CHECK-AARCH64-SAME: float noundef [[X:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK-AARCH64-NEXT: [[ENTRY:.*:]] +// CHECK-AARCH64-NEXT:[[X_ADDR:%.*]] = alloca float, align 4 +// CHECK-AARCH64-NEXT:store float [[X]], ptr [[X_ADDR]], align 4 +// CHECK-AARCH64-NEXT:[[TMP0:%.*]] = load float, ptr [[X_ADDR]], align 4 +// CHECK-AARCH64-NEXT:[[CONV:%.*]] = fpext float [[TMP0]] to fp128 +// CHECK-AARCH64-NEXT:[[MUL:%.*]] = fmul fp128 [[CONV]], 0xL3FFF +// CHECK-AARCH64-NEXT:[[CONV1:%.*]] = fptrunc fp128 [[MUL]] to float +// CHECK-AARCH64-NEXT:ret float [[CONV1]] +// +// CHECK-ARM-LABEL: define dso_local arm_aapcscc float @extended_float_func( +// CHECK-ARM-SAME: float noundef [[X:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK-ARM-NEXT: [[ENTRY:.*:]] +// CHECK-ARM-NEXT:[[X_ADDR:%.*]] = alloca float, align 4 +// CHECK-ARM-NEXT:store float [[X]], ptr [[X_ADDR]], align 4 +// CHECK-ARM-NEXT:[[TMP0:%.*]] = load float, ptr [[X_ADDR]], align 4 +// CHECK-ARM-NEXT:[[CONV:%.*]] = fpext float [[TMP0]] to double +// CHECK-ARM-NEXT:[[MUL:%.*]] = fmul double [[CONV]], 1.00e+00 +// CHECK-ARM-NEXT:[[CONV1:%.*]] = fptrunc double [[MUL]] to float +// CHECK-ARM-NEXT:ret float [[CONV1]] +// +// CHECK-PPC32-LABEL: define dso_local float @extended_float_func( +// CHECK-PPC32-SAME: float noundef [[X:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK-PPC32-NEXT: [[ENTRY:.*:]] +// CHECK-PPC32-NEXT:[[X_ADDR:%.*]] = alloca float, align 4 +// CHECK-PPC32-NEXT:store float [[X]], ptr [[X_ADDR]], align 4 +// CHECK-PPC32-NEXT:[[TMP0:%.*]] = load float, ptr [[X_ADDR]], align 4 +// CHECK-PPC32-
[clang] [C11] Claim conformance to WG14 N1396 (PR #101214)
https://github.com/AaronBallman closed https://github.com/llvm/llvm-project/pull/101214 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 0fd980e - [NFC][Clang] Remove unused arg (#101650)
Author: Dmitry Chestnykh Date: 2024-08-02T15:24:49+03:00 New Revision: 0fd980e1dbed1018c77e7c7c258a08a5bca61955 URL: https://github.com/llvm/llvm-project/commit/0fd980e1dbed1018c77e7c7c258a08a5bca61955 DIFF: https://github.com/llvm/llvm-project/commit/0fd980e1dbed1018c77e7c7c258a08a5bca61955.diff LOG: [NFC][Clang] Remove unused arg (#101650) `BuiltinID` is not used inside `CheckBuiltinTargetInSupported` Added: Modified: clang/lib/Sema/SemaChecking.cpp Removed: diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e35d91e810dd9..ee143381cf4f7 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1862,7 +1862,7 @@ static bool CheckBuiltinTargetNotInUnsupported( // Emit an error and return true if the current architecture is not in the list // of supported architectures. static bool -CheckBuiltinTargetInSupported(Sema &S, unsigned BuiltinID, CallExpr *TheCall, +CheckBuiltinTargetInSupported(Sema &S, CallExpr *TheCall, ArrayRef SupportedArchs) { llvm::Triple::ArchType CurArch = S.getASTContext().getTargetInfo().getTriple().getArch(); @@ -2151,7 +2151,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI_interlockedbittestandreset_rel: case Builtin::BI_interlockedbittestandreset_nf: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64})) return ExprError(); break; @@ -2164,7 +2164,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI_interlockedbittestandreset64: case Builtin::BI_interlockedbittestandset64: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::x86_64, llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64, llvm::Triple::amdgcn})) return ExprError(); @@ -2172,7 +2172,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI__builtin_set_flt_rounds: if (CheckBuiltinTargetInSupported( -*this, BuiltinID, TheCall, +*this, TheCall, {llvm::Triple::x86, llvm::Triple::x86_64, llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64, llvm::Triple::amdgcn})) return ExprError(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Remove unused arg (PR #101650)
https://github.com/chestnykh closed https://github.com/llvm/llvm-project/pull/101650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Ofast deprecation clarifications (PR #101005)
https://github.com/sjoerdmeijer closed https://github.com/llvm/llvm-project/pull/101005 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Ofast deprecation clarifications (PR #101005)
sjoerdmeijer wrote: > LGTM, let's go ahead and merge this and get it backported to 19.x, thank you! Thanks for your help with this. I am mostly unfamiliar with the release process. Do you know how we can achieve this? Do we suggest this commit to the release manager for a backport and cherry pick? Or do we prepare a patch? We could add similar clarifications to the release notes, which were initially included in an earlier version of this patch. So same question how we would need to approach that. https://github.com/llvm/llvm-project/pull/101005 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits