[clang] [HIP][Clang][Driver] Move BC preference logic into ROCm detection (PR #149294)
jchlanda wrote: No new tests are added in this patch, but the expected behaviour should not change and existing tests cover it: * [amdgpu-openmp-toolchain.c](https://github.com/jchlanda/llvm-project/blob/jakub/rocm_detection/clang/test/Driver/amdgpu-toolchain.c#L1) * [hip-device-libs.hip](https://github.com/jchlanda/llvm-project/blob/jakub/rocm_detection/clang/test/Driver/hip-device-libs.hip#L1) * [rocm-device-libs.cl](https://github.com/jchlanda/llvm-project/blob/jakub/rocm_detection/clang/test/Driver/rocm-device-libs.cl#L1) https://github.com/llvm/llvm-project/pull/149294 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Add -march=unset to cancel and ignore a previous -march. (PR #148321)
https://github.com/asb approved this pull request. I like this solution too. https://github.com/llvm/llvm-project/pull/148321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][OpenMP] Non-contiguous strided update (PR #144635)
alexey-bataev wrote: Also, update OpenMPSupport.rst and release notes https://github.com/llvm/llvm-project/pull/144635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][OpenMP] Non-contiguous strided update (PR #144635)
@@ -4724,6 +4724,65 @@ void x() { EXPECT_TRUE(matchesWithOpenMP(Source8, Matcher)); } +TEST_P(ASTMatchersTest, OMPTargetUpdateDirective_IsStandaloneDirective) { alexey-bataev wrote: Clang tests are required https://github.com/llvm/llvm-project/pull/144635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)
https://github.com/alexey-bataev commented: Some previous comments are not addressed yet https://github.com/llvm/llvm-project/pull/139293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)
https://github.com/alexey-bataev edited https://github.com/llvm/llvm-project/pull/139293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)
@@ -1143,6 +1143,83 @@ class OMPFullClause final : public OMPNoChildClause { static OMPFullClause *CreateEmpty(const ASTContext &C); }; +/// This class represents the 'looprange' clause in the +/// '#pragma omp fuse' directive +/// +/// \code {c} +/// #pragma omp fuse looprange(1,2) +/// { +/// for(int i = 0; i < 64; ++i) +/// for(int j = 0; j < 256; j+=2) +/// for(int k = 127; k >= 0; --k) +/// \endcode +class OMPLoopRangeClause final +: public OMPClause { + friend class OMPClauseReader; + /// Location of '(' + SourceLocation LParenLoc; + + /// Location of first and count expressions + SourceLocation FirstLoc, CountLoc; + + /// Number of looprange arguments (always 2: first, count) + static constexpr unsigned NumArgs = 2; + Stmt *Args[NumArgs] = {nullptr, nullptr}; + + /// Set looprange 'first' expression + void setFirst(Expr *E) { Args[0] = E; } + + /// Set looprange 'count' expression + void setCount(Expr *E) { Args[1] = E; } + + /// Build an empty clause for deserialization. + explicit OMPLoopRangeClause() + : OMPClause(llvm::omp::OMPC_looprange, {}, {}) {} + +public: + /// Build a 'looprange' clause AST node. + static OMPLoopRangeClause * + Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, + SourceLocation FirstLoc, SourceLocation CountLoc, + SourceLocation EndLoc, Expr* First, Expr* Count); alexey-bataev wrote: Formatting? https://github.com/llvm/llvm-project/pull/139293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang] Add `__builtin_stack_address` (PR #148281)
@@ -121,6 +121,11 @@ enum NodeType { /// function calling this intrinsic. SPONENTRY, + /// STACKADDR - Represents the llvm.stackaddr intrinsic. Takes no argument + /// and returns the starting address of the stack region that may be used + /// by called functions. + STACKADDR, arsenm wrote: Names don't match the actual intrinsic https://github.com/llvm/llvm-project/pull/148281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add support for `v_exp_bf16` on gfx1250 (PR #149229)
shiltian wrote: ### Merge activity * **Jul 17, 12:41 PM UTC**: A user started a stack merge that includes this pull request via [Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/149229). https://github.com/llvm/llvm-project/pull/149229 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Do not treat Foo -> const Foo conversion sequences as perfect (PR #148613)
cor3ntin wrote: Sorry for the inconvenience. It was clearly not the right solution in hindsight. It may take me a while to figure out how to approach a fix to https://github.com/llvm/llvm-project/issues/147374 https://github.com/llvm/llvm-project/pull/148613 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Lay the basic infrastructure for pretty printing of types (PR #148701)
@@ -300,16 +640,17 @@ llvm::Expected Interpreter::ExtractValueFromExpr(Expr *E) { using namespace clang; // Temporary rvalue struct that need special care. -REPL_EXTERNAL_VISIBILITY void * +REPL_EXTERNAL_VISIBILITY extern "C" void * AaronBallman wrote: That didn't seem to work, but then why does this work already? https://github.com/llvm/llvm-project/blob/b7c14b6ded300b9190fe0b65881d04c54b2a9fbd/clang/lib/Interpreter/InterpreterValuePrinter.cpp#L311 But this one uses a different style: https://github.com/llvm/llvm-project/blob/b7c14b6ded300b9190fe0b65881d04c54b2a9fbd/clang/lib/Interpreter/InterpreterValuePrinter.cpp#L303 https://github.com/llvm/llvm-project/pull/148701 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix const-in-mutable fields (PR #149286)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/149286 For mutable and const fields, we have two bits in InlineDescriptor, which both get inherited down the hierarchy. When a field is both const and mutable, we CAN read from it if it is a mutable-in-const field, but we _can't_ read from it if it is a const-in-mutable field. We need another bit to distinguish the two cases. >From 9d4362963ca4d3c350ae7a4635f3729b5e68ec17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 17 Jul 2025 12:31:01 +0200 Subject: [PATCH] [clang][bytecode] Fix const-in-mutable fields For mutable and const fields, we have two bits in InlineDescriptor, which both get inherited down the hierarchy. When a field is both const and mutable, we CAN read from it if it is a mutable-in-const field, but we _can't_ read from it if it is a const-in-mutable field. We need another bit to distinguish the two cases. --- clang/lib/AST/ByteCode/Descriptor.cpp | 4 +- clang/lib/AST/ByteCode/Descriptor.h | 4 ++ clang/lib/AST/ByteCode/Interp.cpp | 2 +- clang/lib/AST/ByteCode/Pointer.h | 5 +++ clang/test/AST/ByteCode/mutable.cpp | 56 +++ 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp b/clang/lib/AST/ByteCode/Descriptor.cpp index c89eca9bef440..2d5334dbb46b6 100644 --- a/clang/lib/AST/ByteCode/Descriptor.cpp +++ b/clang/lib/AST/ByteCode/Descriptor.cpp @@ -160,8 +160,10 @@ static void initField(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, Desc->IsActive = IsActive && !IsUnionField; Desc->InUnion = InUnion; Desc->IsConst = IsConst || D->IsConst; - Desc->IsFieldMutable = IsMutable || D->IsMutable; + Desc->IsFieldMutable = (IsMutable || D->IsMutable); Desc->IsVolatile = IsVolatile || D->IsVolatile; + // True if this field is const AND the parent is mutable. + Desc->IsConstInMutable = Desc->IsConst && IsMutable; if (auto Fn = D->CtorFn) Fn(B, Ptr + FieldOffset, Desc->IsConst, Desc->IsFieldMutable, diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h index 4591eabb69bb4..0227e4c0c7e38 100644 --- a/clang/lib/AST/ByteCode/Descriptor.h +++ b/clang/lib/AST/ByteCode/Descriptor.h @@ -101,6 +101,10 @@ struct InlineDescriptor { /// Flag indicating if the field is mutable (if in a record). LLVM_PREFERRED_TYPE(bool) unsigned IsFieldMutable : 1; + /// Flag indicating if this field is a const field nested in + /// a mutable parent field. + LLVM_PREFERRED_TYPE(bool) + unsigned IsConstInMutable : 1; /// Flag indicating if the field is an element of a composite array. LLVM_PREFERRED_TYPE(bool) unsigned IsArrayElement : 1; diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index edb1866b5265c..709b3bb64d280 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -566,7 +566,7 @@ bool CheckDowncast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { assert(Ptr.isLive() && "Pointer is not live"); - if (!Ptr.isConst() || Ptr.isMutable()) + if (!Ptr.isConst() || !Ptr.isConstInMutable()) return true; if (!Ptr.isBlockPointer()) diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h index e6a64e6658f06..da74013cf83a6 100644 --- a/clang/lib/AST/ByteCode/Pointer.h +++ b/clang/lib/AST/ByteCode/Pointer.h @@ -576,6 +576,11 @@ class Pointer { return true; return isRoot() ? getDeclDesc()->IsConst : getInlineDesc()->IsConst; } + bool isConstInMutable() const { +if (!isBlockPointer()) + return false; +return isRoot() ? false : getInlineDesc()->IsConstInMutable; + } /// Checks if an object or a subfield is volatile. bool isVolatile() const { diff --git a/clang/test/AST/ByteCode/mutable.cpp b/clang/test/AST/ByteCode/mutable.cpp index aebbea920578c..35c5a0389921e 100644 --- a/clang/test/AST/ByteCode/mutable.cpp +++ b/clang/test/AST/ByteCode/mutable.cpp @@ -1,11 +1,7 @@ -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++11 -verify=expected,expected11,both,both11 %s -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify=expected,expected14,both %s -// RUN: %clang_cc1 -std=c++11 -verify=ref,ref11,both,both11 %s -// RUN: %clang_cc1 -std=c++14 -verify=ref,ref14,both %s - - - - +// RUN: %clang_cc1 -std=c++11 -verify=expected,expected11,both,both11 %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++14 -verify=expected,expected14,both%s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++11 -verify=ref,ref11,both,both11 %s +// RUN: %clang_cc1 -std=c++14 -verify=ref,ref14,both %s namespace Simple { struct S { @@ -26,3 +22,47 @@ namespace Simple { static_assert(s2.a2 == 12, ""); // both11-error {{not an integral const
[clang] [llvm] [Clang] Add `__builtin_stack_address` (PR #148281)
@@ -853,6 +853,7 @@ def int_addressofreturnaddress : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [], [In def int_frameaddress : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [llvm_i32_ty], [IntrNoMem, ImmArg>]>; def int_sponentry : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [], [IntrNoMem]>; +def int_stackaddress : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [], []>; moorabbit wrote: Thanks for pointing that out! I have added the documentation in a new commit. https://github.com/llvm/llvm-project/pull/148281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix const-in-mutable fields (PR #149286)
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/149286 >From 3ff796f7b6f09143de36746ea3e024a2903e26f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 17 Jul 2025 12:31:01 +0200 Subject: [PATCH] [clang][bytecode] Fix const-in-mutable fields For mutable and const fields, we have two bits in InlineDescriptor, which both get inherited down the hierarchy. When a field is both const and mutable, we CAN read from it if it is a mutable-in-const field, but we _can't_ read from it if it is a const-in-mutable field. We need another bit to distinguish the two cases. --- clang/lib/AST/ByteCode/Descriptor.cpp | 4 +- clang/lib/AST/ByteCode/Descriptor.h | 4 ++ clang/lib/AST/ByteCode/Interp.cpp | 2 +- clang/lib/AST/ByteCode/Pointer.h | 5 +++ clang/test/AST/ByteCode/mutable.cpp | 56 +++ 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp b/clang/lib/AST/ByteCode/Descriptor.cpp index c89eca9bef440..2d5334dbb46b6 100644 --- a/clang/lib/AST/ByteCode/Descriptor.cpp +++ b/clang/lib/AST/ByteCode/Descriptor.cpp @@ -160,8 +160,10 @@ static void initField(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, Desc->IsActive = IsActive && !IsUnionField; Desc->InUnion = InUnion; Desc->IsConst = IsConst || D->IsConst; - Desc->IsFieldMutable = IsMutable || D->IsMutable; + Desc->IsFieldMutable = (IsMutable || D->IsMutable); Desc->IsVolatile = IsVolatile || D->IsVolatile; + // True if this field is const AND the parent is mutable. + Desc->IsConstInMutable = Desc->IsConst && IsMutable; if (auto Fn = D->CtorFn) Fn(B, Ptr + FieldOffset, Desc->IsConst, Desc->IsFieldMutable, diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h index 4591eabb69bb4..0227e4c0c7e38 100644 --- a/clang/lib/AST/ByteCode/Descriptor.h +++ b/clang/lib/AST/ByteCode/Descriptor.h @@ -101,6 +101,10 @@ struct InlineDescriptor { /// Flag indicating if the field is mutable (if in a record). LLVM_PREFERRED_TYPE(bool) unsigned IsFieldMutable : 1; + /// Flag indicating if this field is a const field nested in + /// a mutable parent field. + LLVM_PREFERRED_TYPE(bool) + unsigned IsConstInMutable : 1; /// Flag indicating if the field is an element of a composite array. LLVM_PREFERRED_TYPE(bool) unsigned IsArrayElement : 1; diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index e8b519478c026..571c6c6ef26d6 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -566,7 +566,7 @@ bool CheckDowncast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { assert(Ptr.isLive() && "Pointer is not live"); - if (!Ptr.isConst() || Ptr.isMutable()) + if (!Ptr.isConst() || !Ptr.isConstInMutable()) return true; if (!Ptr.isBlockPointer()) diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h index e6a64e6658f06..da74013cf83a6 100644 --- a/clang/lib/AST/ByteCode/Pointer.h +++ b/clang/lib/AST/ByteCode/Pointer.h @@ -576,6 +576,11 @@ class Pointer { return true; return isRoot() ? getDeclDesc()->IsConst : getInlineDesc()->IsConst; } + bool isConstInMutable() const { +if (!isBlockPointer()) + return false; +return isRoot() ? false : getInlineDesc()->IsConstInMutable; + } /// Checks if an object or a subfield is volatile. bool isVolatile() const { diff --git a/clang/test/AST/ByteCode/mutable.cpp b/clang/test/AST/ByteCode/mutable.cpp index aebbea920578c..35c5a0389921e 100644 --- a/clang/test/AST/ByteCode/mutable.cpp +++ b/clang/test/AST/ByteCode/mutable.cpp @@ -1,11 +1,7 @@ -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++11 -verify=expected,expected11,both,both11 %s -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify=expected,expected14,both %s -// RUN: %clang_cc1 -std=c++11 -verify=ref,ref11,both,both11 %s -// RUN: %clang_cc1 -std=c++14 -verify=ref,ref14,both %s - - - - +// RUN: %clang_cc1 -std=c++11 -verify=expected,expected11,both,both11 %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++14 -verify=expected,expected14,both%s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++11 -verify=ref,ref11,both,both11 %s +// RUN: %clang_cc1 -std=c++14 -verify=ref,ref14,both %s namespace Simple { struct S { @@ -26,3 +22,47 @@ namespace Simple { static_assert(s2.a2 == 12, ""); // both11-error {{not an integral constant expression}} \ // both11-note {{initializer of 's2' is not a constant expression}} } +#if __cplusplus >= 201402L +namespace ConstInMutable { + class B { +public: + +const int f; +constexpr B() : f(12) {} + }; + class A { +public: +mutable B b; +constexpr A(
[clang] [llvm] [openmp] [clang][OpenMP] New OpenMP 6.0 threadset clause (PR #135807)
@@ -1324,6 +1324,86 @@ class OMPDefaultClause : public OMPClause { } }; +/// This represents 'threadset' clause in the '#pragma omp task ...' directive. +/// +/// \code +/// #pragma omp task threadset(omp_pool) +/// \endcode +/// In this example directive '#pragma omp task' has simple 'threadset' +/// clause with kind 'omp_pool'. +class OMPThreadsetClause : public OMPClause { alexey-bataev wrote: ```suggestion class OMPThreadsetClause final : public OMPClause { ``` https://github.com/llvm/llvm-project/pull/135807 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Do not treat Foo -> const Foo conversion sequences as perfect (PR #148613)
bgra8 wrote: Thanks for reverting @cor3ntin ! The fallout @alexfh refers too is caused by code that reduces to something similar to what @MatzeB reported. https://github.com/llvm/llvm-project/pull/148613 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang][FMV] Refactor sema checking of target_version/clones attributes. (PR #149067)
https://github.com/BeMg approved this pull request. RISC-V part LGTM. https://github.com/llvm/llvm-project/pull/149067 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC] Enable 'performance-move-const-arg' in '.clang-tidy' config (PR #148549)
vbvictor wrote: > Are they really need to "std::move" in the patch? I think `MixData` is > meaningless since it is still need to copy all field. Do you mean with `CheckTriviallyCopyableMove` set to `true`? Technically, there would probably be no performance benefit. However, from author's point of view, he intended not to use that data anymore so he used `std::move` to "semantically" flag it. I'm more in favor of preserving "semantics" so put `CheckTriviallyCopyableMove` to false. https://github.com/llvm/llvm-project/pull/148549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Report mutable reads when copying unions (PR #149320)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/149320 None >From 896c606f240e302f12a891aa9ddabba70f2e6364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 17 Jul 2025 16:28:15 +0200 Subject: [PATCH] [clang][bytecode] Report mutable reads when copying unions --- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 2 ++ clang/lib/AST/ByteCode/InterpFrame.cpp | 5 + clang/test/AST/ByteCode/unions.cpp | 14 ++ 3 files changed, 21 insertions(+) diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index de0b97fd93c76..ace7016785069 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -2906,6 +2906,8 @@ static bool copyRecord(InterpState &S, CodePtr OpPC, const Pointer &Src, if (!copyField(F, /*Activate=*/true)) return false; } else { +if (!CheckMutable(S, OpPC, Src.atField(F.Offset))) + return false; Pointer DestField = Dest.atField(F.Offset); zeroAll(DestField); } diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index a5a4bd25fe712..d62a4f6275b50 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -128,6 +128,11 @@ static bool shouldSkipInBacktrace(const Function *F) { if (FD->getDeclName().getCXXOverloadedOperator() == OO_New || FD->getDeclName().getCXXOverloadedOperator() == OO_Array_New) return true; + + if (const auto *MD = dyn_cast(FD); + MD && MD->getParent()->isAnonymousStructOrUnion()) +return true; + return false; } diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp index 0fa44a259a4ff..7cfd0d677a7b3 100644 --- a/clang/test/AST/ByteCode/unions.cpp +++ b/clang/test/AST/ByteCode/unions.cpp @@ -847,6 +847,20 @@ namespace Activation2 { } static_assert(change_member_indirectly() == 4); } + +namespace CopyCtorMutable { + struct E { +union { // expected-note {{read of mutable member 'b'}} + int a; + mutable int b; // both-note {{here}} +}; + }; + constexpr E e1 = {{1}}; + constexpr E e2 = e1; // both-error {{constant}} \ + // ref-note {{read of mutable member 'b'}} \ + // both-note {{in call}} +} + #endif namespace AddressComparison { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Report mutable reads when copying unions (PR #149320)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/149320.diff 3 Files Affected: - (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+2) - (modified) clang/lib/AST/ByteCode/InterpFrame.cpp (+5) - (modified) clang/test/AST/ByteCode/unions.cpp (+14) ``diff diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index de0b97fd93c76..ace7016785069 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -2906,6 +2906,8 @@ static bool copyRecord(InterpState &S, CodePtr OpPC, const Pointer &Src, if (!copyField(F, /*Activate=*/true)) return false; } else { +if (!CheckMutable(S, OpPC, Src.atField(F.Offset))) + return false; Pointer DestField = Dest.atField(F.Offset); zeroAll(DestField); } diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index a5a4bd25fe712..d62a4f6275b50 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -128,6 +128,11 @@ static bool shouldSkipInBacktrace(const Function *F) { if (FD->getDeclName().getCXXOverloadedOperator() == OO_New || FD->getDeclName().getCXXOverloadedOperator() == OO_Array_New) return true; + + if (const auto *MD = dyn_cast(FD); + MD && MD->getParent()->isAnonymousStructOrUnion()) +return true; + return false; } diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp index 0fa44a259a4ff..7cfd0d677a7b3 100644 --- a/clang/test/AST/ByteCode/unions.cpp +++ b/clang/test/AST/ByteCode/unions.cpp @@ -847,6 +847,20 @@ namespace Activation2 { } static_assert(change_member_indirectly() == 4); } + +namespace CopyCtorMutable { + struct E { +union { // expected-note {{read of mutable member 'b'}} + int a; + mutable int b; // both-note {{here}} +}; + }; + constexpr E e1 = {{1}}; + constexpr E e2 = e1; // both-error {{constant}} \ + // ref-note {{read of mutable member 'b'}} \ + // both-note {{in call}} +} + #endif namespace AddressComparison { `` https://github.com/llvm/llvm-project/pull/149320 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [DTLTO][Clang] Add support for Integrated Distributed ThinLTO (PR #147265)
bd1976bris wrote: @tru - would you be happy for me to backport this to the LLVM 21 release branch to complete the DTLTO feature? https://github.com/llvm/llvm-project/pull/147265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tools-extra] Bump ReleaseNotes to 22.0.0git (PR #149306)
https://github.com/jpienaar edited https://github.com/llvm/llvm-project/pull/149306 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
https://github.com/jpienaar updated https://github.com/llvm/llvm-project/pull/149148 >From b404f5390ac5684c7452e69f6fe209e5215f8929 Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Wed, 16 Jul 2025 17:37:53 + Subject: [PATCH 1/6] [clang-tidy] Add MLIR check for old op builder usage. Moving towards new create method invocation, add check to flag old usage. --- clang-tools-extra/clang-tidy/CMakeLists.txt | 2 + .../clang-tidy/ClangTidyForceLinker.h | 5 + .../clang-tidy/mlir/CMakeLists.txt| 28 + .../clang-tidy/mlir/MLIRTidyModule.cpp| 39 +++ .../clang-tidy/mlir/OpBuilderCheck.cpp| 102 ++ .../clang-tidy/mlir/OpBuilderCheck.h | 21 clang-tools-extra/docs/ReleaseNotes.rst | 5 + .../docs/clang-tidy/checks/list.rst | 2 + .../clang-tidy/checks/mlir/op-builder.rst | 22 .../clang-tidy/checkers/mlir/op_builder.cpp | 51 + 10 files changed, 277 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/mlir/CMakeLists.txt create mode 100644 clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/mlir/OpBuilderCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/mlir/op-builder.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/mlir/op_builder.cpp diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt b/clang-tools-extra/clang-tidy/CMakeLists.txt index 93117cf1d6373..b89003bf6c926 100644 --- a/clang-tools-extra/clang-tidy/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/CMakeLists.txt @@ -66,6 +66,7 @@ add_subdirectory(linuxkernel) add_subdirectory(llvm) add_subdirectory(llvmlibc) add_subdirectory(misc) +add_subdirectory(mlir) add_subdirectory(modernize) if(CLANG_TIDY_ENABLE_STATIC_ANALYZER) add_subdirectory(mpi) @@ -93,6 +94,7 @@ set(ALL_CLANG_TIDY_CHECKS clangTidyLLVMModule clangTidyLLVMLibcModule clangTidyMiscModule + clangTidyMLIRModule clangTidyModernizeModule clangTidyObjCModule clangTidyOpenMPModule diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h index adde9136ff1dd..3cde93124c6e4 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h +++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h @@ -94,6 +94,11 @@ extern volatile int MiscModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination = MiscModuleAnchorSource; +// This anchor is used to force the linker to link the MLIRModule. +extern volatile int MLIRModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED MLIRModuleAnchorDestination = +MLIRModuleAnchorSource; + // This anchor is used to force the linker to link the ModernizeModule. extern volatile int ModernizeModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination = diff --git a/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt new file mode 100644 index 0..7d0b2de1df24c --- /dev/null +++ b/clang-tools-extra/clang-tidy/mlir/CMakeLists.txt @@ -0,0 +1,28 @@ +set(LLVM_LINK_COMPONENTS + FrontendOpenMP + Support + ) + +add_clang_library(clangTidyMLIRModule STATIC + MLIRTidyModule.cpp + OpBuilderCheck.cpp + + LINK_LIBS + clangTidy + clangTidyReadabilityModule + clangTidyUtils + clangTransformer + + DEPENDS + omp_gen + ClangDriverOptions + ) + +clang_target_link_libraries(clangTidyMLIRModule + PRIVATE + clangAST + clangASTMatchers + clangBasic + clangLex + clangTooling + ) diff --git a/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp new file mode 100644 index 0..f542020a0afdd --- /dev/null +++ b/clang-tools-extra/clang-tidy/mlir/MLIRTidyModule.cpp @@ -0,0 +1,39 @@ +//===--- MLIRTidyModule.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 "../ClangTidy.h" +#include "../ClangTidyModule.h" +#include "../ClangTidyModuleRegistry.h" +#include "OpBuilderCheck.h" + +namespace clang::tidy { +namespace mlir_check { + +class MLIRModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { +CheckFactories.registerCheck("mlir-op-builder"); + } + + ClangTidyOptions getModuleOptions() override { +ClangTidyOptions Options; +return Options; + } +}; + +// Register the ModuleModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add X("mlir-module", +
[clang] [lld] [llvm] Integrated Distributed ThinLTO (DTLTO): Design Overview (PR #126654)
https://github.com/bd1976bris edited https://github.com/llvm/llvm-project/pull/126654 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add MLIR check for old op builder usage. (PR #149148)
@@ -0,0 +1,103 @@ +//===--- MLIROpBuilderCheck.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 "MLIROpBuilderCheck.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Basic/LLVM.h" +#include "clang/Lex/Lexer.h" +#include "clang/Tooling/Transformer/RangeSelector.h" +#include "clang/Tooling/Transformer/RewriteRule.h" +#include "clang/Tooling/Transformer/SourceCode.h" +#include "clang/Tooling/Transformer/Stencil.h" +#include "llvm/Support/Error.h" + +namespace clang::tidy::llvm_check { +namespace { + +using namespace ::clang::ast_matchers; // NOLINT: Too many names. +using namespace ::clang::transformer; // NOLINT: Too many names. + +class TypeAsWrittenStencil : public StencilInterface { +public: + explicit TypeAsWrittenStencil(std::string S) : id(std::move(S)) {} + std::string toString() const override { +return (llvm::Twine("TypeAsWritten(\"") + id + "\")").str(); + } + + llvm::Error eval(const MatchFinder::MatchResult &match, + std::string *result) const override { +llvm::Expected n = node(id)(match); +if (!n) + return n.takeError(); +SourceRange srcRange = n->getAsRange(); EugeneZelenko wrote: ```suggestion const SourceRange srcRange = n->getAsRange(); ``` Please also run Clang-Tidy on your files: looks like variables naming is not confirmed to LLVM coding style. https://github.com/llvm/llvm-project/pull/149148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Support parenthesized list initialization (CXXParenListInitExpr) (PR #148988)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/148988 >From 5db59d5b7f9b834762f86aa69040314e8faeb649 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Wed, 16 Jul 2025 02:09:37 +0300 Subject: [PATCH 1/6] [Analyzer] support parenthesized list initialization --- clang/docs/ReleaseNotes.rst | 2 + .../Core/PathSensitive/ExprEngine.h | 3 ++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 7 ++- .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 31 clang/test/Analysis/div-zero.cpp | 50 --- 5 files changed, 86 insertions(+), 7 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1eb3e369a302e..06a41700081a9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1199,6 +1199,8 @@ Static Analyzer --- - Fixed a crash when C++20 parenthesized initializer lists are used. This issue was causing a crash in clang-tidy. (#GH136041) +- The Clang Static Analyzer now handles parenthesized initialization. + (#GH148875) New features diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h index 6370586e218ef..79d86aef8a0c6 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h @@ -586,6 +586,9 @@ class ExprEngine { void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, ExplodedNode *Pred, ExplodedNodeSet &Dst); + void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE, + ExplodedNode *Pred, ExplodedNodeSet &Dst); + /// Create a C++ temporary object for an rvalue. void CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME, ExplodedNode *Pred, diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index c77ef26da568d..8f0cdd46045d0 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1941,7 +1941,6 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Stmt::ConceptSpecializationExprClass: case Stmt::CXXRewrittenBinaryOperatorClass: case Stmt::RequiresExprClass: -case Expr::CXXParenListInitExprClass: case Stmt::EmbedExprClass: // Fall through. @@ -2321,6 +2320,12 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, Bldr.addNodes(Dst); break; +case Expr::CXXParenListInitExprClass: + Bldr.takeNodes(Pred); + VisitCXXParenListInitExpr(cast(S), Pred, Dst); + Bldr.addNodes(Dst); + break; + case Stmt::MemberExprClass: Bldr.takeNodes(Pred); VisitMemberExpr(cast(S), Pred, Dst); diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp index 85353848aa124..059a435bd3e9e 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -1233,3 +1233,34 @@ void ExprEngine::VisitAttributedStmt(const AttributedStmt *A, getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, A, *this); } + +void ExprEngine::VisitCXXParenListInitExpr(const CXXParenListInitExpr *E, + ExplodedNode *Pred, + ExplodedNodeSet &Dst) { + StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); + + ProgramStateRef S = Pred->getState(); + QualType T = getContext().getCanonicalType(E->getType()); + + const LocationContext *LCtx = Pred->getLocationContext(); + + SmallVector ArgVals; + for (Expr *Arg : E->getInitExprs()) +ArgVals.push_back(S->getSVal(Arg, LCtx)); + + if (!E->isGLValue() && (T->isRecordType() || T->isArrayType())) { +llvm::ImmutableList ArgList = getBasicVals().getEmptySValList(); + +for (const SVal &V : llvm::reverse(ArgVals)) + ArgList = getBasicVals().prependSVal(V, ArgList); + +Bldr.generateNode( +E, Pred, S->BindExpr(E, LCtx, svalBuilder.makeCompoundVal(T, ArgList))); + } else { +Bldr.generateNode(E, Pred, + S->BindExpr(E, LCtx, + ArgVals.empty() + ? getSValBuilder().makeZeroVal(T) + : ArgVals.front())); + } +} diff --git a/clang/test/Analysis/div-zero.cpp b/clang/test/Analysis/div-zero.cpp index 063450d8883b0..2a44ad132d4a5 100644 --- a/clang/test/Analysis/div-zero.cpp +++ b/clang/test/Analysis/div-zero.cpp @@ -1,13 +1,51 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -verify %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -std=c++20 -verify %s -int fooPR10616 (int qX ) { +namespace GH10616 { +int foo(int qX) { int a, c, d; - d =
[clang] [llvm] [DTLTO][Clang] Add support for Integrated Distributed ThinLTO (PR #147265)
tru wrote: > @tru - would you be happy for me to backport this to the LLVM 21 release > branch to complete the DTLTO feature? Yes! https://github.com/llvm/llvm-project/pull/147265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix const-in-mutable fields (PR #149286)
Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/149286 >From 34201c4031f90a09f4e4d8295f7fb4a261bbb864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 17 Jul 2025 12:31:01 +0200 Subject: [PATCH 1/2] [clang][bytecode] Fix const-in-mutable fields For mutable and const fields, we have two bits in InlineDescriptor, which both get inherited down the hierarchy. When a field is both const and mutable, we CAN read from it if it is a mutable-in-const field, but we _can't_ read from it if it is a const-in-mutable field. We need another bit to distinguish the two cases. --- clang/lib/AST/ByteCode/Descriptor.cpp | 2 + clang/lib/AST/ByteCode/Descriptor.h | 4 ++ clang/lib/AST/ByteCode/Disasm.cpp | 1 + clang/lib/AST/ByteCode/Interp.cpp | 5 ++- clang/lib/AST/ByteCode/Pointer.h | 5 +++ clang/test/AST/ByteCode/mutable.cpp | 56 +++ 6 files changed, 64 insertions(+), 9 deletions(-) diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp b/clang/lib/AST/ByteCode/Descriptor.cpp index c89eca9bef440..5b9f44518fcc2 100644 --- a/clang/lib/AST/ByteCode/Descriptor.cpp +++ b/clang/lib/AST/ByteCode/Descriptor.cpp @@ -162,6 +162,8 @@ static void initField(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, Desc->IsConst = IsConst || D->IsConst; Desc->IsFieldMutable = IsMutable || D->IsMutable; Desc->IsVolatile = IsVolatile || D->IsVolatile; + // True if this field is const AND the parent is mutable. + Desc->IsConstInMutable = Desc->IsConst && IsMutable; if (auto Fn = D->CtorFn) Fn(B, Ptr + FieldOffset, Desc->IsConst, Desc->IsFieldMutable, diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h index 4591eabb69bb4..0227e4c0c7e38 100644 --- a/clang/lib/AST/ByteCode/Descriptor.h +++ b/clang/lib/AST/ByteCode/Descriptor.h @@ -101,6 +101,10 @@ struct InlineDescriptor { /// Flag indicating if the field is mutable (if in a record). LLVM_PREFERRED_TYPE(bool) unsigned IsFieldMutable : 1; + /// Flag indicating if this field is a const field nested in + /// a mutable parent field. + LLVM_PREFERRED_TYPE(bool) + unsigned IsConstInMutable : 1; /// Flag indicating if the field is an element of a composite array. LLVM_PREFERRED_TYPE(bool) unsigned IsArrayElement : 1; diff --git a/clang/lib/AST/ByteCode/Disasm.cpp b/clang/lib/AST/ByteCode/Disasm.cpp index f64501f4a31e8..74399d177b5a2 100644 --- a/clang/lib/AST/ByteCode/Disasm.cpp +++ b/clang/lib/AST/ByteCode/Disasm.cpp @@ -445,6 +445,7 @@ LLVM_DUMP_METHOD void InlineDescriptor::dump(llvm::raw_ostream &OS) const { OS << "InUnion: " << InUnion << "\n"; OS << "IsFieldMutable: " << IsFieldMutable << "\n"; OS << "IsArrayElement: " << IsArrayElement << "\n"; + OS << "IsConstInMutable: " << IsConstInMutable << '\n'; OS << "Desc: "; if (Desc) Desc->dump(OS); diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index e8b519478c026..df5e3be83d741 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -566,7 +566,10 @@ bool CheckDowncast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { assert(Ptr.isLive() && "Pointer is not live"); - if (!Ptr.isConst() || Ptr.isMutable()) + if (!Ptr.isConst()) +return true; + + if (Ptr.isMutable() && !Ptr.isConstInMutable()) return true; if (!Ptr.isBlockPointer()) diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h index e6a64e6658f06..da74013cf83a6 100644 --- a/clang/lib/AST/ByteCode/Pointer.h +++ b/clang/lib/AST/ByteCode/Pointer.h @@ -576,6 +576,11 @@ class Pointer { return true; return isRoot() ? getDeclDesc()->IsConst : getInlineDesc()->IsConst; } + bool isConstInMutable() const { +if (!isBlockPointer()) + return false; +return isRoot() ? false : getInlineDesc()->IsConstInMutable; + } /// Checks if an object or a subfield is volatile. bool isVolatile() const { diff --git a/clang/test/AST/ByteCode/mutable.cpp b/clang/test/AST/ByteCode/mutable.cpp index aebbea920578c..35c5a0389921e 100644 --- a/clang/test/AST/ByteCode/mutable.cpp +++ b/clang/test/AST/ByteCode/mutable.cpp @@ -1,11 +1,7 @@ -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++11 -verify=expected,expected11,both,both11 %s -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify=expected,expected14,both %s -// RUN: %clang_cc1 -std=c++11 -verify=ref,ref11,both,both11 %s -// RUN: %clang_cc1 -std=c++14 -verify=ref,ref14,both %s - - - - +// RUN: %clang_cc1 -std=c++11 -verify=expected,expected11,both,both11 %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++14 -verify=expected,expected14,both%s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++11 -verify=ref
[clang] Improve clarity of the implicit declaration diagnostic (PR #149314)
@@ -376,6 +376,33 @@ class Context { return getInfo(ID).Header.getName(); } + /// Returns true if a library function is declared within a C or C++ standard + /// header (like stdio.h) or POSIX header (like malloc.h), false if the + /// function is not declared within a header or is declared in a non-standard + /// header (like Microsoft or Objective-C headers). + bool isDeclaredInStandardHeader(unsigned ID) const { +switch (getInfo(ID).Header.ID) { +default: + return false; +case HeaderDesc::COMPLEX_H: // C99 +case HeaderDesc::CTYPE_H: // C89 +case HeaderDesc::MATH_H:// C89 +case HeaderDesc::MALLOC_H: // POSIX +case HeaderDesc::MEMORY:// C++98 +case HeaderDesc::PTHREAD_H: // POSIX +case HeaderDesc::SETJMP_H: // C89 +case HeaderDesc::STDARG_H: // C89 +case HeaderDesc::STDIO_H: // C89 +case HeaderDesc::STDLIB_H: // C89 +case HeaderDesc::STRING_H: // C89 +case HeaderDesc::STRINGS_H: // POSIX +case HeaderDesc::UNISTD_H: // POSIX +case HeaderDesc::UTILITY: // C++98 +case HeaderDesc::WCHAR_H: // C99 + return true; +} + } cor3ntin wrote: Can we modify the HEADER macro in BuiltinHeaders.def to generate that automatically? https://github.com/llvm/llvm-project/pull/149314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Improve clarity of the implicit declaration diagnostic (PR #149314)
@@ -716,6 +716,10 @@ Improvements to Clang's diagnostics Added a new warning in this group for the case where the attribute is missing/implicit on an override of a virtual method. + - Reworded the ``-Wimplicit-function-declaration`` diagnostic to make it more + clear that the type selected for the implicit declaration is based on the + signature of a standard (C, C++, POSIX) library function. (#GH146924) + cor3ntin wrote: Can you double check this is aligned as it should? https://github.com/llvm/llvm-project/pull/149314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Improve clarity of the implicit declaration diagnostic (PR #149314)
@@ -816,11 +816,12 @@ def warn_unreachable_association : Warning< /// Built-in functions. def ext_implicit_lib_function_decl : ExtWarn< - "implicitly declaring library function '%0' with type %1">, - InGroup; + "implicitly declaring library function '%0' with%select{| standards-mandated}2 " + "type %1">, InGroup; def ext_implicit_lib_function_decl_c99 : ExtWarn< - "call to undeclared library function '%0' with type %1; ISO C99 and later " - "do not support implicit function declarations">, + "call to undeclared library function '%0', will assume it exists with" + "%select{| standards-mandated}2 type %1; ISO C99 and later do not support " + "implicit function declarations">, InGroup, DefaultError; cor3ntin wrote: A way to simplify (ie, get rid of `isDeclaredInStandardHeader`) would be to say " will assume it exists with type %1 as if header <%2>" had been included" (where %2 is ` Context.BuiltinInfo.getName(ID)`) WDYT? https://github.com/llvm/llvm-project/pull/149314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [openmp] [Flang][OpenMP] Move builtin .mod generation into runtimes (PR #137828)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/137828 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix potential constant expression checking with constexpr-unknown. (PR #149227)
https://github.com/frederick-vs-ja milestoned https://github.com/llvm/llvm-project/pull/149227 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] Fix Windows EH IP2State tables (remove +1 bias) (PR #144745)
frobtech wrote: > Actually, thinking about it, maybe we should just do the nop insertion for > UEFI targets. The UEFI environment is very similar to Windows. CC @Prabhuk . I think that's an appropriately conservative place to start, anyway. The uefi-* targets are still nascent and heretofore the Windows targets have been used for producing UEFI binaries. So the approach we've taken is that for all miscellaneous code generation issues, we should start with the UEFI target matching the behavior of the corresponding Windows target exactly. That seems like the right thing to do for now. In the future as the uefi-* targets mature, we can reconsider things that are really only relevant to Windows ABIs and not to the UEFI ABI or the PE-COFF format. The Windows EH ABI is not an aspect of the UEFI ABI, but the support for Windows EH does not interfere with UEFI so I think it's harmless enough to emit all the same stuff. https://github.com/llvm/llvm-project/pull/144745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Upstream builtin_conj for ComplexType (PR #149170)
https://github.com/AmrDeveloper closed https://github.com/llvm/llvm-project/pull/149170 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 84d65e9 - [CIR] Upstream builtin_conj for ComplexType (#149170)
Author: Amr Hesham Date: 2025-07-17T18:00:32+02:00 New Revision: 84d65e9d19ab577027238d38d053e293ba656e32 URL: https://github.com/llvm/llvm-project/commit/84d65e9d19ab577027238d38d053e293ba656e32 DIFF: https://github.com/llvm/llvm-project/commit/84d65e9d19ab577027238d38d053e293ba656e32.diff LOG: [CIR] Upstream builtin_conj for ComplexType (#149170) This change adds support for builtin_conj for ComplexType https://github.com/llvm/llvm-project/issues/141365 Added: Modified: clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp clang/lib/CIR/CodeGen/CIRGenValue.h clang/test/CIR/CodeGen/complex-builtins.cpp Removed: diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 476f994959285..61d1c54ee9ec9 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -125,7 +125,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID, mlir::Value real = emitScalarExpr(e->getArg(0)); mlir::Value imag = emitScalarExpr(e->getArg(1)); mlir::Value complex = builder.createComplexCreate(loc, real, imag); -return RValue::get(complex); +return RValue::getComplex(complex); } case Builtin::BI__builtin_creal: @@ -150,6 +150,18 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID, return RValue::get(imag); } + case Builtin::BI__builtin_conj: + case Builtin::BI__builtin_conjf: + case Builtin::BI__builtin_conjl: + case Builtin::BIconj: + case Builtin::BIconjf: + case Builtin::BIconjl: { +mlir::Value complex = emitComplexExpr(e->getArg(0)); +mlir::Value conj = builder.createUnaryOp(getLoc(e->getExprLoc()), + cir::UnaryOpKind::Not, complex); +return RValue::getComplex(conj); + } + case Builtin::BI__builtin_clrsb: case Builtin::BI__builtin_clrsbl: case Builtin::BI__builtin_clrsbll: diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp index 6663f5ea1e758..9f36be5397ad8 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp @@ -231,8 +231,7 @@ mlir::Value ComplexExprEmitter::VisitBinComma(const BinaryOperator *e) { mlir::Value ComplexExprEmitter::VisitCallExpr(const CallExpr *e) { if (e->getCallReturnType(cgf.getContext())->isReferenceType()) return emitLoadOfLValue(e); - - return cgf.emitCallExpr(e).getValue(); + return cgf.emitCallExpr(e).getComplexValue(); } mlir::Value ComplexExprEmitter::VisitCastExpr(CastExpr *e) { diff --git a/clang/lib/CIR/CodeGen/CIRGenValue.h b/clang/lib/CIR/CodeGen/CIRGenValue.h index 0a6dba5e80a62..0832c4141a10f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenValue.h +++ b/clang/lib/CIR/CodeGen/CIRGenValue.h @@ -58,6 +58,12 @@ class RValue { return value; } + /// Return the value of this complex value. + mlir::Value getComplexValue() const { +assert(isComplex() && "Not a complex!"); +return value; + } + /// Return the value of the address of the aggregate. Address getAggregateAddress() const { assert(isAggregate() && "Not an aggregate!"); diff --git a/clang/test/CIR/CodeGen/complex-builtins.cpp b/clang/test/CIR/CodeGen/complex-builtins.cpp index f0d12d0ef6663..811af47a704f5 100644 --- a/clang/test/CIR/CodeGen/complex-builtins.cpp +++ b/clang/test/CIR/CodeGen/complex-builtins.cpp @@ -83,3 +83,39 @@ void foo3() { // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 1 // OGCG: %[[A_IMAG:.*]] = load double, ptr %[[A_IMAG_PTR]], align 8 // OGCG: store double %[[A_IMAG]], ptr %[[INIT]], align 8 + +void foo4() { + float _Complex a; + float _Complex b = __builtin_conjf(a); +} + +// CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex, !cir.ptr>, ["a"] +// CIR: %[[RESULT:.*]] = cir.alloca !cir.complex, !cir.ptr>, ["b", init] +// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr>, !cir.complex +// CIR: %[[REAL:.*]] = cir.complex.real %[[TMP]] : !cir.complex -> !cir.float +// CIR: %[[IMAG:.*]] = cir.complex.imag %[[TMP]] : !cir.complex -> !cir.float +// CIR: %[[IMAG_MINUS:.*]] = cir.unary(minus, %[[IMAG]]) : !cir.float, !cir.float +// CIR: %[[RESULT_VAL:.*]] = cir.complex.create %[[REAL]], %[[IMAG_MINUS]] : !cir.float -> !cir.complex +// CIR: cir.store{{.*}} %[[RESULT_VAL]], %[[RESULT]] : !cir.complex, !cir.ptr> + +// LLVM: %[[COMPLEX:.*]] = alloca { float, float }, i64 1, align 4 +// LLVM: %[[RESULT:.*]] = alloca { float, float }, i64 1, align 4 +// LLVM: %[[TMP:.*]] = load { float, float }, ptr %[[COMPLEX]], align 4 +// LLVM: %[[REAL:.*]] = extractvalue { float, float } %[[TMP]], 0 +// LLVM: %[[IMAG:.*]] = extractvalue { float, float } %[[TMP]], 1 +// LLVM: %[[IMAG_MINUS:.*]] = fneg float %[[IMA
[clang] Fix scope of typedefs present inside a template class (PR #146729)
ykhatav wrote: > `DW_TAG_template_alias` suffer from the same issue? It does not look like template_alias has the same issue, although I am not very familiar with template_alias types. I tried a small example where the scope is set correctly: template struct S { template using A = int; using AA = A; AA aa; }; !5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !3, line: 3, size: 32, flags: DIFlagTypePassByValue, elements: !6, templateParams: !13, identifier: "_ZTS1SILi0EE") !DIDerivedType(tag: DW_TAG_template_alias, name: "A", scope: !5, file: !3, line: 5, baseType: !10, extraData: !11) https://github.com/llvm/llvm-project/pull/146729 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CodeGen] Remove an unnecessary cast (NFC) (PR #149339)
https://github.com/shiltian approved this pull request. https://github.com/llvm/llvm-project/pull/149339 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Remove unnecessary casts (NFC) (PR #149340)
https://github.com/shiltian approved this pull request. https://github.com/llvm/llvm-project/pull/149340 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Remove an unnecessary cast (NFC) (PR #149338)
@@ -610,7 +610,7 @@ void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) { } } - if (auto *FS = static_cast(Node->getFinallyStmt())) { + if (auto *FS = Node->getFinallyStmt()) { shiltian wrote: If there is no cast, then we'd want to use the type instead of `auto` here. https://github.com/llvm/llvm-project/pull/149338 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Remove an unnecessary cast (NFC) (PR #149338)
https://github.com/shiltian approved this pull request. https://github.com/llvm/llvm-project/pull/149338 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [openmp] [Flang][OpenMP] Move builtin .mod generation into runtimes (PR #137828)
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/137828 >From 839198d61f9937b5504d5e036c67266b4b84da8e Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 17 Jul 2025 14:09:57 +0200 Subject: [PATCH 1/2] [Flang][Flang-RT][OpenMP] Move builtin .mod generation into runtimes --- clang/include/clang/Driver/Driver.h | 3 +- clang/include/clang/Driver/Options.td | 2 +- clang/include/clang/Driver/ToolChain.h| 4 + clang/lib/Driver/Driver.cpp | 10 + clang/lib/Driver/ToolChain.cpp| 6 + clang/lib/Driver/ToolChains/Flang.cpp | 7 + .../Modules}/GetToolchainDirs.cmake | 11 ++ flang-rt/CMakeLists.txt | 73 ++-- flang-rt/cmake/modules/AddFlangRT.cmake | 14 +- .../cmake/modules/AddFlangRTOffload.cmake | 14 +- flang-rt/lib/runtime/CMakeLists.txt | 109 ++- .../lib/runtime}/__cuda_builtins.f90 | 0 .../lib/runtime}/__cuda_device.f90| 0 .../lib/runtime}/__fortran_builtins.f90 | 4 +- .../runtime}/__fortran_ieee_exceptions.f90| 0 .../lib/runtime}/__fortran_type_info.f90 | 7 +- .../lib/runtime}/__ppc_intrinsics.f90 | 0 .../lib/runtime}/__ppc_types.f90 | 0 .../lib/runtime}/cooperative_groups.f90 | 1 + .../lib/runtime}/cudadevice.f90 | 0 .../lib/runtime}/ieee_arithmetic.f90 | 29 ++- .../lib/runtime}/ieee_exceptions.f90 | 0 .../lib/runtime}/ieee_features.f90| 0 .../lib/runtime}/iso_c_binding.f90| 0 .../lib/runtime}/iso_fortran_env.f90 | 0 .../lib/runtime}/iso_fortran_env_impl.f90 | 0 .../module => flang-rt/lib/runtime}/mma.f90 | 0 flang-rt/test/lit.site.cfg.py.in | 2 +- flang-rt/unittests/CMakeLists.txt | 5 +- flang/CMakeLists.txt | 2 +- .../flang/Frontend/CompilerInvocation.h | 7 + flang/lib/Frontend/CompilerInvocation.cpp | 26 +-- flang/lib/Optimizer/CodeGen/CodeGen.cpp | 8 +- flang/module/.clang-format| 1 - flang/test/CMakeLists.txt | 7 +- flang/test/Driver/intrinsic-module-path.f90 | 4 +- .../Lower/HLFIR/type-bound-call-mismatch.f90 | 2 +- flang/test/Lower/OpenMP/simd_aarch64.f90 | 7 +- .../target-enter-data-default-openmp52.f90| 4 +- flang/test/lit.cfg.py | 57 +- flang/test/lit.site.cfg.py.in | 1 + flang/tools/CMakeLists.txt| 1 - flang/tools/bbc/bbc.cpp | 16 +- flang/tools/f18/CMakeLists.txt| 176 -- flang/tools/f18/dump.cpp | 42 - llvm/runtimes/CMakeLists.txt | 21 +-- openmp/CMakeLists.txt | 4 + openmp/runtime/src/CMakeLists.txt | 62 ++ runtimes/CMakeLists.txt | 163 +++- 49 files changed, 512 insertions(+), 400 deletions(-) rename {flang-rt/cmake/modules => cmake/Modules}/GetToolchainDirs.cmake (94%) rename {flang/module => flang-rt/lib/runtime}/__cuda_builtins.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/__cuda_device.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/__fortran_builtins.f90 (98%) rename {flang/module => flang-rt/lib/runtime}/__fortran_ieee_exceptions.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/__fortran_type_info.f90 (98%) rename {flang/module => flang-rt/lib/runtime}/__ppc_intrinsics.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/__ppc_types.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/cooperative_groups.f90 (95%) rename {flang/module => flang-rt/lib/runtime}/cudadevice.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/ieee_arithmetic.f90 (95%) rename {flang/module => flang-rt/lib/runtime}/ieee_exceptions.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/ieee_features.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/iso_c_binding.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/iso_fortran_env.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/iso_fortran_env_impl.f90 (100%) rename {flang/module => flang-rt/lib/runtime}/mma.f90 (100%) delete mode 100644 flang/module/.clang-format delete mode 100644 flang/tools/f18/CMakeLists.txt delete mode 100644 flang/tools/f18/dump.cpp diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index d9e328fe918bc..9343fed36b6ac 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -403,9 +403,10 @@ class Driver { SmallString<128> &CrashDiagDir); public: - /// Takes the path to a binary that's either in bin/ or lib/ and returns /// the path to clang's resource directory. + /// Do not pas
[clang] [Clang][Driver] Revise Cygwin ToolChain to call linker directly (PR #147960)
@@ -107,3 +110,294 @@ void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs, addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/w32api"); } + +static bool getStaticPIE(const ArgList &Args, const ToolChain &TC) { + bool HasStaticPIE = Args.hasArg(options::OPT_static_pie); + if (HasStaticPIE && Args.hasArg(options::OPT_no_pie)) { +const Driver &D = TC.getDriver(); +const llvm::opt::OptTable &Opts = D.getOpts(); +StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie); +StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie); +D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName; + } + return HasStaticPIE; +} + +static bool getStatic(const ArgList &Args) { + return Args.hasArg(options::OPT_static) && + !Args.hasArg(options::OPT_static_pie); +} + +void cygwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &Args, + const char *LinkingOutput) const { + const auto &ToolChain = getToolChain(); + const Driver &D = ToolChain.getDriver(); + + const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU(); + const bool IsVE = ToolChain.getTriple().isVE(); + const bool IsStaticPIE = getStaticPIE(Args, ToolChain); + const bool IsStatic = getStatic(Args); + + ArgStringList CmdArgs; + + // Silence warning for "clang -g foo.o -o foo" + Args.ClaimAllArgs(options::OPT_g_Group); + // and "clang -emit-llvm foo.o -o foo" + Args.ClaimAllArgs(options::OPT_emit_llvm); + // and for "clang -w foo.o -o foo". Other warning options are already + // handled somewhere else. + Args.ClaimAllArgs(options::OPT_w); + + if (!D.SysRoot.empty()) +CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); + + if (Args.hasArg(options::OPT_s)) +CmdArgs.push_back("-s"); + + CmdArgs.push_back("-m"); + switch (ToolChain.getArch()) { + case llvm::Triple::x86: +CmdArgs.push_back("i386pe"); +break; + case llvm::Triple::x86_64: +CmdArgs.push_back("i386pep"); +break; + case llvm::Triple::arm: + case llvm::Triple::thumb: +// FIXME: this is incorrect for WinCE +CmdArgs.push_back("thumb2pe"); +break; + case llvm::Triple::aarch64: +if (ToolChain.getEffectiveTriple().isWindowsArm64EC()) + CmdArgs.push_back("arm64ecpe"); +else + CmdArgs.push_back("arm64pe"); +break; + default: +D.Diag(diag::err_target_unknown_triple) +<< ToolChain.getEffectiveTriple().str(); + } + + Arg *SubsysArg = + Args.getLastArg(options::OPT_mwindows, options::OPT_mconsole); + if (SubsysArg && SubsysArg->getOption().matches(options::OPT_mwindows)) { +CmdArgs.push_back("--subsystem"); +CmdArgs.push_back("windows"); + } else if (SubsysArg && + SubsysArg->getOption().matches(options::OPT_mconsole)) { +CmdArgs.push_back("--subsystem"); +CmdArgs.push_back("console"); + } + + CmdArgs.push_back("--wrap=_Znwm"); + CmdArgs.push_back("--wrap=_Znam"); + CmdArgs.push_back("--wrap=_ZdlPv"); + CmdArgs.push_back("--wrap=_ZdaPv"); + CmdArgs.push_back("--wrap=_ZnwmRKSt9nothrow_t"); + CmdArgs.push_back("--wrap=_ZnamRKSt9nothrow_t"); + CmdArgs.push_back("--wrap=_ZdlPvRKSt9nothrow_t"); + CmdArgs.push_back("--wrap=_ZdaPvRKSt9nothrow_t"); + + if (Args.hasArg(options::OPT_mdll)) +CmdArgs.push_back("--dll"); + else if (Args.hasArg(options::OPT_shared)) +CmdArgs.push_back("--shared"); + if (Args.hasArg(options::OPT_static)) +CmdArgs.push_back("-Bstatic"); + else +CmdArgs.push_back("-Bdynamic"); + + CmdArgs.push_back("--dll-search-prefix=cyg"); + + CmdArgs.push_back("-o"); + CmdArgs.push_back(Output.getFilename()); + + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, + options::OPT_r)) { +if (IsVE) { + CmdArgs.push_back("-z"); + CmdArgs.push_back("max-page-size=0x400"); +} + +const bool IsShared = Args.hasArg(options::OPT_shared); +if (IsShared) { + CmdArgs.push_back("-e"); + CmdArgs.push_back(ToolChain.getArch() == llvm::Triple::x86 +? "__cygwin_dll_entry@12" +: "_cygwin_dll_entry"); + CmdArgs.push_back("--enable-auto-image-base"); +} + +if (!IsShared) + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o"))); +if (ToolChain.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT) { + std::string crtbegin = + ToolChain.getCompilerRT(Args, "crtbegin", ToolChain::FT_Object); + if (ToolChain.getVFS().exists(crtbegin)) { +std::string P; +P = crtbegin; +CmdArgs.push_back(Args.MakeArgString(P)); + } +} +if (IsShared) + CmdArgs.push
[clang] [Clang][Driver] Revise Cygwin ToolChain to call linker directly (PR #147960)
@@ -107,3 +110,294 @@ void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs, addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/w32api"); } + +static bool getStaticPIE(const ArgList &Args, const ToolChain &TC) { + bool HasStaticPIE = Args.hasArg(options::OPT_static_pie); + if (HasStaticPIE && Args.hasArg(options::OPT_no_pie)) { +const Driver &D = TC.getDriver(); +const llvm::opt::OptTable &Opts = D.getOpts(); +StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie); +StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie); +D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName; + } + return HasStaticPIE; +} + +static bool getStatic(const ArgList &Args) { + return Args.hasArg(options::OPT_static) && + !Args.hasArg(options::OPT_static_pie); +} + +void cygwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &Args, + const char *LinkingOutput) const { + const auto &ToolChain = getToolChain(); + const Driver &D = ToolChain.getDriver(); + + const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU(); + const bool IsVE = ToolChain.getTriple().isVE(); + const bool IsStaticPIE = getStaticPIE(Args, ToolChain); + const bool IsStatic = getStatic(Args); + + ArgStringList CmdArgs; + + // Silence warning for "clang -g foo.o -o foo" + Args.ClaimAllArgs(options::OPT_g_Group); + // and "clang -emit-llvm foo.o -o foo" + Args.ClaimAllArgs(options::OPT_emit_llvm); + // and for "clang -w foo.o -o foo". Other warning options are already + // handled somewhere else. + Args.ClaimAllArgs(options::OPT_w); + + if (!D.SysRoot.empty()) +CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); + + if (Args.hasArg(options::OPT_s)) +CmdArgs.push_back("-s"); + + CmdArgs.push_back("-m"); + switch (ToolChain.getArch()) { + case llvm::Triple::x86: +CmdArgs.push_back("i386pe"); +break; + case llvm::Triple::x86_64: +CmdArgs.push_back("i386pep"); +break; + case llvm::Triple::arm: + case llvm::Triple::thumb: +// FIXME: this is incorrect for WinCE +CmdArgs.push_back("thumb2pe"); +break; + case llvm::Triple::aarch64: +if (ToolChain.getEffectiveTriple().isWindowsArm64EC()) kikairoya wrote: It would be better to list only targets that are supported by Cygwin or reflect the MinGW list. MinGW now support a new arch: https://github.com/llvm/llvm-project/blob/a102342990231f8558361da68e5df92c7b1c737d/clang/lib/Driver/ToolChains/MinGW.cpp#L134-L136 https://github.com/llvm/llvm-project/pull/147960 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [openmp] [Flang][OpenMP] Move builtin .mod generation into runtimes (PR #137828)
@@ -3979,6 +3979,16 @@ def fsyntax_only : Flag<["-"], "fsyntax-only">, Visibility<[ClangOption, CLOption, DXCOption, CC1Option, FC1Option, FlangOption]>, Group, HelpText<"Run the preprocessor, parser and semantic analysis stages">; + + +def fno_builtin_modules : Flag<["-"], "fno-builtin-modules">, + Visibility<[FC1Option]>, + HelpText<"Do not implicitly use builtin modules (for internal use only)">; Meinersbur wrote: removed https://github.com/llvm/llvm-project/pull/137828 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [openmp] [Flang][OpenMP] Move builtin .mod generation into runtimes (PR #137828)
Meinersbur wrote: > What's the main limitation here? If this is just a file dependency it should > be identical to how all the OpenMP tests depend on `omp.h` being in the > resource directory. `omp.h` is created by `configure_file` at configure time. No dependency other than `runtimes-configure` needed. > IMHO this is trivial if we do a runtimes build, since we can just require > that `openmp;flang-rt` are in the same toolchain, With toolchain you mean a bootstrapping build with `LLVM_ENABLE_RUNTIMES=openmp;flang-rt` ? Don't forget the users of a Flang-standalone build (`cmake -S /flang`). > which then gives us well defined access to `openmp`'s CMake targets so long > as it's listed before `flang-rt`. `check-flang` (LLVM_ENABLE_PROJECTS=flang) needs access to `libomp.mod` (LLVM_ENABLE_RUNTIMES=openmp) and the flang modules as well to work. https://github.com/llvm/llvm-project/pull/137828 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Reintroduce obsolete symbols in libclang.map (PR #149190)
https://github.com/AaronBallman milestoned https://github.com/llvm/llvm-project/pull/149190 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Reintroduce obsolete symbols in libclang.map (PR #149190)
AaronBallman wrote: /cherry-pick 7e0fde0c2f6b0b9d727ce9196956b36e91961ac4 https://github.com/llvm/llvm-project/pull/149190 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] [OpenMP] New OpenMP 6.0 self_maps clause - CodeGen (PR #134131)
@@ -236,6 +236,8 @@ enum class OpenMPOffloadMappingFlags : uint64_t { // dynamic. // This is an OpenMP extension for the sake of OpenACC support. OMP_MAP_OMPX_HOLD = 0x2000, + /// Self directs mapping without creating a separate device copy. + OMP_MAP_SELF = 0x4000, alexey-bataev wrote: Is this value reserved in the runtime? https://github.com/llvm/llvm-project/pull/134131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 96a7e95 - [Sema] Remove unnecessary casts (NFC) (#149253)
Author: Kazu Hirata Date: 2025-07-17T07:22:36-07:00 New Revision: 96a7e954e1501239d1fc4bd6eba60428bd6609f7 URL: https://github.com/llvm/llvm-project/commit/96a7e954e1501239d1fc4bd6eba60428bd6609f7 DIFF: https://github.com/llvm/llvm-project/commit/96a7e954e1501239d1fc4bd6eba60428bd6609f7.diff LOG: [Sema] Remove unnecessary casts (NFC) (#149253) getParam already returns NamedDecl *. Added: Modified: clang/lib/Sema/SemaTemplateDeduction.cpp Removed: diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index d09a72b71b805..e1a975bcfb3e1 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3083,8 +3083,7 @@ static TemplateDeductionResult ConvertDeducedTemplateArguments( // If there was no default argument, deduction is incomplete. if (DefArg.getArgument().isNull()) { - Info.Param = makeTemplateParameter( - const_cast(TemplateParams->getParam(I))); + Info.Param = makeTemplateParameter(TemplateParams->getParam(I)); Info.reset( TemplateArgumentList::CreateCopy(S.Context, CTAI.SugaredConverted), TemplateArgumentList::CreateCopy(S.Context, CTAI.CanonicalConverted)); @@ -3100,8 +3099,7 @@ static TemplateDeductionResult ConvertDeducedTemplateArguments( if (S.CheckTemplateArgument( Param, DefArg, TD, TD->getLocation(), TD->getSourceRange().getEnd(), /*ArgumentPackIndex=*/0, CTAI, Sema::CTAK_Specified)) { - Info.Param = makeTemplateParameter( - const_cast(TemplateParams->getParam(I))); + Info.Param = makeTemplateParameter(TemplateParams->getParam(I)); // FIXME: These template arguments are temporary. Free them! Info.reset( TemplateArgumentList::CreateCopy(S.Context, CTAI.SugaredConverted), @@ -3227,7 +3225,7 @@ static TemplateDeductionResult FinishTemplateArgumentDeduction( if (ParamIdx >= TPL->size()) ParamIdx = TPL->size() - 1; -Decl *Param = const_cast(TPL->getParam(ParamIdx)); +Decl *Param = TPL->getParam(ParamIdx); Info.Param = makeTemplateParameter(Param); Info.FirstArg = Ps[ArgIdx].getArgument(); return TemplateDeductionResult::SubstitutionFailure; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 73e8ada - [Sema] Use llvm::all_of (NFC) (#149256)
Author: Kazu Hirata Date: 2025-07-17T07:22:59-07:00 New Revision: 73e8ada540acbd60f916ef4b0a5a2b454c8ece44 URL: https://github.com/llvm/llvm-project/commit/73e8ada540acbd60f916ef4b0a5a2b454c8ece44 DIFF: https://github.com/llvm/llvm-project/commit/73e8ada540acbd60f916ef4b0a5a2b454c8ece44.diff LOG: [Sema] Use llvm::all_of (NFC) (#149256) We can pass a range to llvm::all_of. Added: Modified: clang/lib/Sema/AnalysisBasedWarnings.cpp Removed: diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 5eba024e83634..d1400cbfc884d 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -522,8 +522,7 @@ static bool areAllValuesNoReturn(const VarDecl *VD, const CFGBlock &VarBlk, } // If all checked blocks satisfy the condition, the check is finished. -if (std::all_of(BlocksToCheck.begin(), BlocksToCheck.end(), -BlockSatisfiesCondition)) +if (llvm::all_of(BlocksToCheck, BlockSatisfiesCondition)) return true; // If this block does not contain the variable definition, check ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Remove unnecessary casts (NFC) (PR #149253)
https://github.com/kazutakahirata closed https://github.com/llvm/llvm-project/pull/149253 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Ensure proper NULL macro definition for system include files. (PR #149176)
jamieschmeiser wrote: > This seems like a very complicated solution. > > If the AIX system headers want to define NULL, should we just let them? Just > `#include_next ` to ensure clang's stddef.h doesn't define NULL in > an inconsistent way. Just doing an `#include_next ` is a dangerous solution. For C, at least, the clang header `__stddef_null.h` makes it very clear that the expected definition of NULL is ((void*)0). However, if one just lets the platform decide on the definition of NULL, which the standard indicates can be 0 or ((void*)0), there can be unexpected consequences should 0 be chosen. On AIX in 64 bit mode, and I suspect on other platforms, an int is 4 bytes long while a pointer is 8 bytes long, which could lead to subtle bugs (eg sizeof(NULL) or _Alignof(NULL) may be different for int and void* on some platforms). There may be an implicit understanding within the compiler that the C null pointer constant will be type void* (I'm not saying there is, and I hope there isn't) which may be problematic for those platforms using 0. It is safer to enforce what the compiler is expecting. It may also aid in portability of code across platforms. The standard mandates that certain headers define NULL but what if the `#include_next` defines it as 0 and uses it somehow before returning? Then there is inconsistency within the header. I force the clang definition before the `#include_next` to try to ensure as much consistency as possible since it is reasonable to hope that the definition of NULL is guarded since many headers are mandated to define it but there is only so much one can do... Afterwards, it is again forced in case it was changed. This is done universally for those files that are mandated to define NULL. For those non-mandated system headers that also define it on Aix, it is conditionally forced. I would suggest other platforms to do similarly. https://github.com/llvm/llvm-project/pull/149176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Use llvm::all_of (NFC) (PR #149256)
https://github.com/kazutakahirata closed https://github.com/llvm/llvm-project/pull/149256 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 9de32d5 - [clang-tools-extra] Bump ReleaseNotes to 22.0.0git (#149306)
Author: Jacques Pienaar Date: 2025-07-17T07:25:12-07:00 New Revision: 9de32d56e4fdf08d88aca74149f5f815eb6505ec URL: https://github.com/llvm/llvm-project/commit/9de32d56e4fdf08d88aca74149f5f815eb6505ec DIFF: https://github.com/llvm/llvm-project/commit/9de32d56e4fdf08d88aca74149f5f815eb6505ec.diff LOG: [clang-tools-extra] Bump ReleaseNotes to 22.0.0git (#149306) Move over change post 21.x branch cut. Added: Modified: clang-tools-extra/docs/ReleaseNotes.rst Removed: diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 9eb3835fe8340..07ebf8008928d 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -58,9 +58,6 @@ Semantic Highlighting Compile flags ^ -- Added `BuiltinHeaders` config key which controls whether clangd's built-in - headers are used or ones extracted from the driver. - Hover ^ @@ -93,301 +90,18 @@ Improvements to clang-query arguments. So when porting a query to C++, remove all instances of trailing comma (otherwise C++ compiler will just complain about "expected expression"). -Improvements to include-cleaner -- Deprecated the ``-insert`` and ``-remove`` command line options, and added - the ``-disable-remove`` and ``-disable-insert`` command line options as - replacements. The previous command line options were confusing because they - did not imply the default state of the option (which is inserts and removes - being enabled). The new options are easier to understand the semantics of. - Improvements to clang-tidy -- -- Changed the :program:`check_clang_tidy.py` tool to use FileCheck's - ``--match-full-lines`` instead of ``strict-whitespace`` for ``CHECK-FIXES`` - clauses. Added a ``--match-partial-fixes`` option to keep previous behavior on - specific tests. This may break tests for users with custom out-of-tree checks - who use :program:`check_clang_tidy.py` as-is. - -- Improved :program:`clang-tidy- diff .py` script. Add the `-warnings-as-errors` - argument to treat warnings as errors. - -- Improved :program:`clang-tidy` to show `CheckOptions` only for checks enabled - in `Checks` when running ``--dump-config``. - -- Fixed bug in :program:`clang-tidy` by which `HeaderFilterRegex` did not take - effect when passed via the `.clang-tidy` file. - -- Fixed bug in :program:`run_clang_tidy.py` where the program would not - correctly display the checks enabled by the top-level `.clang-tidy` file. - New checks ^^ -- New :doc:`bugprone-capturing-this-in-member-variable - ` check. - - Finds lambda captures and ``bind`` function calls that capture the ``this`` - pointer and store it as class members without handle the copy and move - constructors and the assignments. - -- New :doc:`bugprone-misleading-setter-of-reference - ` check. - - Finds setter-like member functions that take a pointer parameter and set a - reference member of the same class with the pointed value. - -- New :doc:`bugprone-unintended-char-ostream-output - ` check. - - Finds unintended character output from ``unsigned char`` and ``signed char`` - to an ``ostream``. - -- New :doc:`cppcoreguidelines-use-enum-class - ` check. - - Finds unscoped (non-class) ``enum`` declarations and suggests using - ``enum class`` instead. - -- New :doc:`llvm-prefer-static-over-anonymous-namespace - ` check. - - Finds function and variable declarations inside anonymous namespace and - suggests replacing them with ``static`` declarations. - -- New :doc:`modernize-use-scoped-lock - ` check. - - Finds uses of ``std::lock_guard`` and suggests replacing them with C++17's - alternative ``std::scoped_lock``. - -- New :doc:`portability-avoid-pragma-once - ` check. - - Finds uses of ``#pragma once`` and suggests replacing them with standard - include guards (``#ifndef``/``#define``/``#endif``) for improved portability. - -- New :doc:`readability-ambiguous-smartptr-reset-call - ` check. - - Finds potentially erroneous calls to ``reset`` method on smart pointers when - the pointee type also has a ``reset`` method. - -- New :doc:`readability-use-concise-preprocessor-directives - ` check. - - Finds uses of ``#if`` that can be simplified to ``#ifdef`` or ``#ifndef`` and, - since C23 and C++23, uses of ``#elif`` that can be simplified to ``#elifdef`` - or ``#elifndef``. - New check aliases ^ Changes in existing checks ^^ -- Improved :doc:`bugprone-crtp-constructor-accessibility - ` check by fixing - false positives on deleted constructors that cannot be used to construct - objects, even if they have public or protected access. - -- Improved :doc:`bugprone-exception-escape - ` check to print stack trace - of a potentially escaped exception. - -- Added an option to :doc
[clang-tools-extra] [clang-tools-extra] Bump ReleaseNotes to 22.0.0git (PR #149306)
https://github.com/jpienaar closed https://github.com/llvm/llvm-project/pull/149306 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver] Revise Cygwin ToolChain to call linker directly (PR #147960)
@@ -107,3 +110,294 @@ void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs, addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/w32api"); } + +static bool getStaticPIE(const ArgList &Args, const ToolChain &TC) { + bool HasStaticPIE = Args.hasArg(options::OPT_static_pie); + if (HasStaticPIE && Args.hasArg(options::OPT_no_pie)) { +const Driver &D = TC.getDriver(); +const llvm::opt::OptTable &Opts = D.getOpts(); +StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie); +StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie); +D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName; + } + return HasStaticPIE; +} + +static bool getStatic(const ArgList &Args) { + return Args.hasArg(options::OPT_static) && + !Args.hasArg(options::OPT_static_pie); +} + +void cygwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &Args, + const char *LinkingOutput) const { + const auto &ToolChain = getToolChain(); + const Driver &D = ToolChain.getDriver(); + + const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU(); + const bool IsVE = ToolChain.getTriple().isVE(); + const bool IsStaticPIE = getStaticPIE(Args, ToolChain); + const bool IsStatic = getStatic(Args); + + ArgStringList CmdArgs; + + // Silence warning for "clang -g foo.o -o foo" + Args.ClaimAllArgs(options::OPT_g_Group); + // and "clang -emit-llvm foo.o -o foo" + Args.ClaimAllArgs(options::OPT_emit_llvm); + // and for "clang -w foo.o -o foo". Other warning options are already + // handled somewhere else. + Args.ClaimAllArgs(options::OPT_w); + + if (!D.SysRoot.empty()) +CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); + + if (Args.hasArg(options::OPT_s)) +CmdArgs.push_back("-s"); + + CmdArgs.push_back("-m"); + switch (ToolChain.getArch()) { + case llvm::Triple::x86: +CmdArgs.push_back("i386pe"); +break; + case llvm::Triple::x86_64: +CmdArgs.push_back("i386pep"); +break; + case llvm::Triple::arm: + case llvm::Triple::thumb: +// FIXME: this is incorrect for WinCE +CmdArgs.push_back("thumb2pe"); +break; + case llvm::Triple::aarch64: +if (ToolChain.getEffectiveTriple().isWindowsArm64EC()) + CmdArgs.push_back("arm64ecpe"); +else + CmdArgs.push_back("arm64pe"); +break; + default: +D.Diag(diag::err_target_unknown_triple) +<< ToolChain.getEffectiveTriple().str(); + } + + Arg *SubsysArg = + Args.getLastArg(options::OPT_mwindows, options::OPT_mconsole); + if (SubsysArg && SubsysArg->getOption().matches(options::OPT_mwindows)) { +CmdArgs.push_back("--subsystem"); +CmdArgs.push_back("windows"); + } else if (SubsysArg && + SubsysArg->getOption().matches(options::OPT_mconsole)) { +CmdArgs.push_back("--subsystem"); +CmdArgs.push_back("console"); + } + + CmdArgs.push_back("--wrap=_Znwm"); + CmdArgs.push_back("--wrap=_Znam"); + CmdArgs.push_back("--wrap=_ZdlPv"); + CmdArgs.push_back("--wrap=_ZdaPv"); + CmdArgs.push_back("--wrap=_ZnwmRKSt9nothrow_t"); + CmdArgs.push_back("--wrap=_ZnamRKSt9nothrow_t"); + CmdArgs.push_back("--wrap=_ZdlPvRKSt9nothrow_t"); + CmdArgs.push_back("--wrap=_ZdaPvRKSt9nothrow_t"); + + if (Args.hasArg(options::OPT_mdll)) +CmdArgs.push_back("--dll"); + else if (Args.hasArg(options::OPT_shared)) +CmdArgs.push_back("--shared"); + if (Args.hasArg(options::OPT_static)) +CmdArgs.push_back("-Bstatic"); + else +CmdArgs.push_back("-Bdynamic"); + + CmdArgs.push_back("--dll-search-prefix=cyg"); + + CmdArgs.push_back("-o"); + CmdArgs.push_back(Output.getFilename()); + + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, + options::OPT_r)) { +if (IsVE) { + CmdArgs.push_back("-z"); + CmdArgs.push_back("max-page-size=0x400"); +} + +const bool IsShared = Args.hasArg(options::OPT_shared); +if (IsShared) { + CmdArgs.push_back("-e"); + CmdArgs.push_back(ToolChain.getArch() == llvm::Triple::x86 +? "__cygwin_dll_entry@12" +: "_cygwin_dll_entry"); + CmdArgs.push_back("--enable-auto-image-base"); +} + +if (!IsShared) + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o"))); +if (ToolChain.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT) { + std::string crtbegin = + ToolChain.getCompilerRT(Args, "crtbegin", ToolChain::FT_Object); + if (ToolChain.getVFS().exists(crtbegin)) { +std::string P; +P = crtbegin; +CmdArgs.push_back(Args.MakeArgString(P)); + } +} +if (IsShared) + CmdArgs.push
[clang] [clang][Modules] Reporting Errors for Duplicating Link Declarations in `modulemap`s (PR #148959)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/148959 >From 0e8a0db8ace8fd1f450cf2364b4c975d418eddc1 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Mon, 14 Jul 2025 18:22:27 -0700 Subject: [PATCH 1/5] Initial implementation of modulemap link decl duplication check. --- .../include/clang/Basic/DiagnosticLexKinds.td | 2 ++ clang/lib/Lex/ModuleMap.cpp | 12 .../ClangScanDeps/link-libraries-diag-dup.c | 30 +++ 3 files changed, 44 insertions(+) create mode 100644 clang/test/ClangScanDeps/link-libraries-diag-dup.c diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 723f5d48b4f5f..f3c9e63a7ca61 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -909,6 +909,8 @@ def err_mmap_nested_submodule_id : Error< "qualified module name can only be used to define modules at the top level">; def err_mmap_expected_feature : Error<"expected a feature name">; def err_mmap_expected_attribute : Error<"expected an attribute name">; +def err_mmap_link_redecalration : Error<"redeclaration of link library '%0'">; +def note_mmap_prev_link_declaration : Note<"previously declared here">; def warn_mmap_unknown_attribute : Warning<"unknown attribute '%0'">, InGroup; def warn_mmap_mismatched_private_submodule : Warning< diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 637a08fe4dcdb..5f815f38a4f54 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -1570,6 +1570,10 @@ class ModuleMapLoader { /// 'textual' to match the original intent. llvm::SmallPtrSet UsesRequiresExcludedHack; + /// Tracks the link library decls in the module map. + llvm::DenseMap> + LinkLibraryLibStrMap; + void handleModuleDecl(const modulemap::ModuleDecl &MD); void handleExternModuleDecl(const modulemap::ExternModuleDecl &EMD); void handleRequiresDecl(const modulemap::RequiresDecl &RD); @@ -2067,6 +2071,14 @@ void ModuleMapLoader::handleUseDecl(const modulemap::UseDecl &UD) { } void ModuleMapLoader::handleLinkDecl(const modulemap::LinkDecl &LD) { + auto &LibStrMap = LinkLibraryLibStrMap[ActiveModule]; + auto [It, Inserted] = + LibStrMap.insert(std::make_pair(LD.Library, LD.Location)); + if (!Inserted) { +Diags.Report(LD.Location, diag::err_mmap_link_redecalration) << LD.Library; +Diags.Report(It->second, diag::note_mmap_prev_link_declaration); +return; + } ActiveModule->LinkLibraries.push_back( Module::LinkLibrary(std::string{LD.Library}, LD.Framework)); } diff --git a/clang/test/ClangScanDeps/link-libraries-diag-dup.c b/clang/test/ClangScanDeps/link-libraries-diag-dup.c new file mode 100644 index 0..c04769465fe0b --- /dev/null +++ b/clang/test/ClangScanDeps/link-libraries-diag-dup.c @@ -0,0 +1,30 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: split-file %s %t + +//--- module.modulemap +module A { + umbrella header "A.h" + + link "libraryA" + link "libraryA" +} + +//--- A.h +// empty +//--- TU.c +#include "A.h" + +//--- cdb.json.template +[{ + "file": "DIR/TU.c", + "directory": "DIR", + "command": "clang -fmodules -fmodules-cache-path=DIR/cache -I DIR -c DIR/TU.c" +}] + +// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json +// RUN: not clang-scan-deps -compilation-database %t/cdb.json -format \ +// RUN: experimental-full 2>&1 | FileCheck %s + +// CHECK: module.modulemap:5:3: error: redeclaration of link library 'libraryA' +// CHECK-NEXT: module.modulemap:4:3: note: previously declared here >From b21831f82dbc23d7ad19d8c89bbcd7eb3f777326 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Tue, 15 Jul 2025 17:00:07 -0700 Subject: [PATCH 2/5] Moving the checks to parsing time (instead of load time), and adding an error whe link declarations are used in submodules. --- .../include/clang/Basic/DiagnosticLexKinds.td | 2 ++ clang/lib/Lex/ModuleMap.cpp | 12 --- clang/lib/Lex/ModuleMapFile.cpp | 32 --- .../ClangScanDeps/link-libraries-diag-dup.c | 21 ++-- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index f3c9e63a7ca61..b4dcb35454585 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -911,6 +911,8 @@ def err_mmap_expected_feature : Error<"expected a feature name">; def err_mmap_expected_attribute : Error<"expected an attribute name">; def err_mmap_link_redecalration : Error<"redeclaration of link library '%0'">; def note_mmap_prev_link_declaration : Note<"previously declared here">; +def err_mmap_submodule_link_decl +: Error<"link declaration is not allowed in submodules">; def warn_mmap_unknown_attribute : Warning<"unknown attribute '%0'">,
[clang] [Clang][Driver] Revise Cygwin ToolChain to call linker directly (PR #147960)
jeremyd2019 wrote: > > $ clang++ -fuse-ld=lld hello.cc > > Do you have patched to LLD locally? This should fail with `unable to find > library -lkernel32`. this new driver should be passing all the necessary `-L` paths to the linker, including `/usr/lib/w32api` https://github.com/llvm/llvm-project/pull/147960 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Support parenthesized list initialization (CXXParenListInitExpr) (PR #148988)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/148988 >From 5db59d5b7f9b834762f86aa69040314e8faeb649 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Wed, 16 Jul 2025 02:09:37 +0300 Subject: [PATCH 1/7] [Analyzer] support parenthesized list initialization --- clang/docs/ReleaseNotes.rst | 2 + .../Core/PathSensitive/ExprEngine.h | 3 ++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 7 ++- .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 31 clang/test/Analysis/div-zero.cpp | 50 --- 5 files changed, 86 insertions(+), 7 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1eb3e369a302e..06a41700081a9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1199,6 +1199,8 @@ Static Analyzer --- - Fixed a crash when C++20 parenthesized initializer lists are used. This issue was causing a crash in clang-tidy. (#GH136041) +- The Clang Static Analyzer now handles parenthesized initialization. + (#GH148875) New features diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h index 6370586e218ef..79d86aef8a0c6 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h @@ -586,6 +586,9 @@ class ExprEngine { void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, ExplodedNode *Pred, ExplodedNodeSet &Dst); + void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE, + ExplodedNode *Pred, ExplodedNodeSet &Dst); + /// Create a C++ temporary object for an rvalue. void CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME, ExplodedNode *Pred, diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index c77ef26da568d..8f0cdd46045d0 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1941,7 +1941,6 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Stmt::ConceptSpecializationExprClass: case Stmt::CXXRewrittenBinaryOperatorClass: case Stmt::RequiresExprClass: -case Expr::CXXParenListInitExprClass: case Stmt::EmbedExprClass: // Fall through. @@ -2321,6 +2320,12 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, Bldr.addNodes(Dst); break; +case Expr::CXXParenListInitExprClass: + Bldr.takeNodes(Pred); + VisitCXXParenListInitExpr(cast(S), Pred, Dst); + Bldr.addNodes(Dst); + break; + case Stmt::MemberExprClass: Bldr.takeNodes(Pred); VisitMemberExpr(cast(S), Pred, Dst); diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp index 85353848aa124..059a435bd3e9e 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -1233,3 +1233,34 @@ void ExprEngine::VisitAttributedStmt(const AttributedStmt *A, getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, A, *this); } + +void ExprEngine::VisitCXXParenListInitExpr(const CXXParenListInitExpr *E, + ExplodedNode *Pred, + ExplodedNodeSet &Dst) { + StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); + + ProgramStateRef S = Pred->getState(); + QualType T = getContext().getCanonicalType(E->getType()); + + const LocationContext *LCtx = Pred->getLocationContext(); + + SmallVector ArgVals; + for (Expr *Arg : E->getInitExprs()) +ArgVals.push_back(S->getSVal(Arg, LCtx)); + + if (!E->isGLValue() && (T->isRecordType() || T->isArrayType())) { +llvm::ImmutableList ArgList = getBasicVals().getEmptySValList(); + +for (const SVal &V : llvm::reverse(ArgVals)) + ArgList = getBasicVals().prependSVal(V, ArgList); + +Bldr.generateNode( +E, Pred, S->BindExpr(E, LCtx, svalBuilder.makeCompoundVal(T, ArgList))); + } else { +Bldr.generateNode(E, Pred, + S->BindExpr(E, LCtx, + ArgVals.empty() + ? getSValBuilder().makeZeroVal(T) + : ArgVals.front())); + } +} diff --git a/clang/test/Analysis/div-zero.cpp b/clang/test/Analysis/div-zero.cpp index 063450d8883b0..2a44ad132d4a5 100644 --- a/clang/test/Analysis/div-zero.cpp +++ b/clang/test/Analysis/div-zero.cpp @@ -1,13 +1,51 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -verify %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -std=c++20 -verify %s -int fooPR10616 (int qX ) { +namespace GH10616 { +int foo(int qX) { int a, c, d; - d =
[clang] [analyzer] Support parenthesized list initialization (CXXParenListInitExpr) (PR #148988)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/148988 >From 5db59d5b7f9b834762f86aa69040314e8faeb649 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Wed, 16 Jul 2025 02:09:37 +0300 Subject: [PATCH 1/7] [Analyzer] support parenthesized list initialization --- clang/docs/ReleaseNotes.rst | 2 + .../Core/PathSensitive/ExprEngine.h | 3 ++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 7 ++- .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 31 clang/test/Analysis/div-zero.cpp | 50 --- 5 files changed, 86 insertions(+), 7 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1eb3e369a302e..06a41700081a9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1199,6 +1199,8 @@ Static Analyzer --- - Fixed a crash when C++20 parenthesized initializer lists are used. This issue was causing a crash in clang-tidy. (#GH136041) +- The Clang Static Analyzer now handles parenthesized initialization. + (#GH148875) New features diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h index 6370586e218ef..79d86aef8a0c6 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h @@ -586,6 +586,9 @@ class ExprEngine { void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, ExplodedNode *Pred, ExplodedNodeSet &Dst); + void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE, + ExplodedNode *Pred, ExplodedNodeSet &Dst); + /// Create a C++ temporary object for an rvalue. void CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME, ExplodedNode *Pred, diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index c77ef26da568d..8f0cdd46045d0 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1941,7 +1941,6 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Stmt::ConceptSpecializationExprClass: case Stmt::CXXRewrittenBinaryOperatorClass: case Stmt::RequiresExprClass: -case Expr::CXXParenListInitExprClass: case Stmt::EmbedExprClass: // Fall through. @@ -2321,6 +2320,12 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, Bldr.addNodes(Dst); break; +case Expr::CXXParenListInitExprClass: + Bldr.takeNodes(Pred); + VisitCXXParenListInitExpr(cast(S), Pred, Dst); + Bldr.addNodes(Dst); + break; + case Stmt::MemberExprClass: Bldr.takeNodes(Pred); VisitMemberExpr(cast(S), Pred, Dst); diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp index 85353848aa124..059a435bd3e9e 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -1233,3 +1233,34 @@ void ExprEngine::VisitAttributedStmt(const AttributedStmt *A, getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, A, *this); } + +void ExprEngine::VisitCXXParenListInitExpr(const CXXParenListInitExpr *E, + ExplodedNode *Pred, + ExplodedNodeSet &Dst) { + StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); + + ProgramStateRef S = Pred->getState(); + QualType T = getContext().getCanonicalType(E->getType()); + + const LocationContext *LCtx = Pred->getLocationContext(); + + SmallVector ArgVals; + for (Expr *Arg : E->getInitExprs()) +ArgVals.push_back(S->getSVal(Arg, LCtx)); + + if (!E->isGLValue() && (T->isRecordType() || T->isArrayType())) { +llvm::ImmutableList ArgList = getBasicVals().getEmptySValList(); + +for (const SVal &V : llvm::reverse(ArgVals)) + ArgList = getBasicVals().prependSVal(V, ArgList); + +Bldr.generateNode( +E, Pred, S->BindExpr(E, LCtx, svalBuilder.makeCompoundVal(T, ArgList))); + } else { +Bldr.generateNode(E, Pred, + S->BindExpr(E, LCtx, + ArgVals.empty() + ? getSValBuilder().makeZeroVal(T) + : ArgVals.front())); + } +} diff --git a/clang/test/Analysis/div-zero.cpp b/clang/test/Analysis/div-zero.cpp index 063450d8883b0..2a44ad132d4a5 100644 --- a/clang/test/Analysis/div-zero.cpp +++ b/clang/test/Analysis/div-zero.cpp @@ -1,13 +1,51 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -verify %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -std=c++20 -verify %s -int fooPR10616 (int qX ) { +namespace GH10616 { +int foo(int qX) { int a, c, d; - d =
[clang] b84f72a - [CIR] Upstream Unary Inc/Dec for ComplexType (#149162)
Author: Amr Hesham Date: 2025-07-17T19:16:04+02:00 New Revision: b84f72a7f51e2ea829feb12ecbb8be0cfc835e2c URL: https://github.com/llvm/llvm-project/commit/b84f72a7f51e2ea829feb12ecbb8be0cfc835e2c DIFF: https://github.com/llvm/llvm-project/commit/b84f72a7f51e2ea829feb12ecbb8be0cfc835e2c.diff LOG: [CIR] Upstream Unary Inc/Dec for ComplexType (#149162) This change adds support for unary inc/dec operators for ComplexType https://github.com/llvm/llvm-project/issues/141365 Added: Modified: clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp clang/lib/CIR/CodeGen/CIRGenFunction.h clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp clang/test/CIR/CodeGen/complex-unary.cpp Removed: diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp index 9f36be5397ad8..0a22771378ff1 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp @@ -56,6 +56,26 @@ class ComplexExprEmitter : public StmtVisitor { mlir::Value VisitParenExpr(ParenExpr *e); mlir::Value VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e); + + mlir::Value VisitPrePostIncDec(const UnaryOperator *e, bool isInc, + bool isPre); + + mlir::Value VisitUnaryPostDec(const UnaryOperator *e) { +return VisitPrePostIncDec(e, false, false); + } + + mlir::Value VisitUnaryPostInc(const UnaryOperator *e) { +return VisitPrePostIncDec(e, true, false); + } + + mlir::Value VisitUnaryPreDec(const UnaryOperator *e) { +return VisitPrePostIncDec(e, false, true); + } + + mlir::Value VisitUnaryPreInc(const UnaryOperator *e) { +return VisitPrePostIncDec(e, true, true); + } + mlir::Value VisitUnaryDeref(const Expr *e); mlir::Value VisitUnaryNot(const UnaryOperator *e); @@ -334,6 +354,12 @@ mlir::Value ComplexExprEmitter::VisitSubstNonTypeTemplateParmExpr( return Visit(e->getReplacement()); } +mlir::Value ComplexExprEmitter::VisitPrePostIncDec(const UnaryOperator *e, + bool isInc, bool isPre) { + LValue lv = cgf.emitLValue(e->getSubExpr()); + return cgf.emitComplexPrePostIncDec(e, lv, isInc, isPre); +} + mlir::Value ComplexExprEmitter::VisitUnaryDeref(const Expr *e) { return emitLoadOfLValue(e); } @@ -422,6 +448,29 @@ mlir::Value CIRGenFunction::emitComplexExpr(const Expr *e) { return ComplexExprEmitter(*this).Visit(const_cast(e)); } +mlir::Value CIRGenFunction::emitComplexPrePostIncDec(const UnaryOperator *e, + LValue lv, bool isInc, + bool isPre) { + mlir::Value inVal = emitLoadOfComplex(lv, e->getExprLoc()); + mlir::Location loc = getLoc(e->getExprLoc()); + auto opKind = isInc ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec; + mlir::Value incVal = builder.createUnaryOp(loc, opKind, inVal); + + // Store the updated result through the lvalue. + emitStoreOfComplex(loc, incVal, lv, /*isInit=*/false); + + if (getLangOpts().OpenMP) +cgm.errorNYI(loc, "emitComplexPrePostIncDec OpenMP"); + + // If this is a postinc, return the value read from memory, otherwise use the + // updated value. + return isPre ? incVal : inVal; +} + +mlir::Value CIRGenFunction::emitLoadOfComplex(LValue src, SourceLocation loc) { + return ComplexExprEmitter(*this).emitLoadOfLValue(src, loc); +} + void CIRGenFunction::emitStoreOfComplex(mlir::Location loc, mlir::Value v, LValue dest, bool isInit) { ComplexExprEmitter(*this).emitStoreOfComplex(loc, v, dest, isInit); diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h index 3baabba5adfe1..9541f4f0725eb 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.h +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h @@ -930,6 +930,9 @@ class CIRGenFunction : public CIRGenTypeCache { /// returning the result. mlir::Value emitComplexExpr(const Expr *e); + mlir::Value emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv, + bool isInc, bool isPre); + LValue emitComplexAssignmentLValue(const BinaryOperator *e); void emitCompoundStmt(const clang::CompoundStmt &s); @@ -980,6 +983,9 @@ class CIRGenFunction : public CIRGenTypeCache { RValue emitLoadOfBitfieldLValue(LValue lv, SourceLocation loc); + /// Load a complex number from the specified l-value. + mlir::Value emitLoadOfComplex(LValue src, SourceLocation loc); + /// Given an expression that represents a value lvalue, this method emits /// the address of the lvalue, then loads the result as an rvalue, /// returning the rvalue. diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp index c708cf9d9fa61..8f848c7345610 100644 ---
[clang] [llvm] [AMDGPU] Add support for `v_cos_bf16_e64` on gfx1250 (PR #149355)
shiltian wrote: but we do have `v_cos_bf16` in `llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s`? https://github.com/llvm/llvm-project/pull/149355 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Upstream Unary Inc/Dec for ComplexType (PR #149162)
https://github.com/AmrDeveloper closed https://github.com/llvm/llvm-project/pull/149162 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [libclang][Cygwin] Provide unversioned DLL file alongside versioned one (PR #147132)
kikairoya wrote: Thanks again. > I got pretty strong negative feedback on including these symlinks at all. I didn’t expect such a strong reaction... I'm really sorry for dragging you into it. > I've tried this with msys2 (where symlinks are really copies and > `LLVM_USE_SYMLINKS=OFF` and got some (non-fatal) errors during install The problem seems to be common to `LLVM_USE_SYMLINKS=OFF`. Each action in one component can't declare dependencies with other actions and they are executed in registration order. The installation action of `msys-LLVM-20.1.8.dll` and `msys-LLVM.dll` are registered here: https://github.com/llvm/llvm-project/blob/34359cf21b444047464d7e607686ec19bfbb25de/llvm/cmake/modules/AddLLVM.cmake#L754-L757 before registering the action of `msys-LLVM-20.dll` at here: https://github.com/llvm/llvm-project/blob/34359cf21b444047464d7e607686ec19bfbb25de/llvm/cmake/modules/AddLLVM.cmake#L983-L987 thus, the former installation actions try to copy the source before it is installed. I don't think anyone actually uses `LLVM_USE_SYMLINKS=OFF` except MSYS, so this inversion may not need to be addressed if this PR is dropped. https://github.com/llvm/llvm-project/pull/147132 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HIP][Clang][Driver] Move BC preference logic into ROCm detection (PR #149294)
https://github.com/jchlanda created https://github.com/llvm/llvm-project/pull/149294 This patch provides a single point for handling the logic behind choosing common bitcode libraries. The intention is that the users of ROCm installation detector will not have to rewrite options handling code each time the bitcode libraries are queried. This is not too distant from detectors for other architecture that encapsulate the similar decision making process, providing cleaner interface. The only flag left in `getCommonBitcodeLibs` (main point of entry) is `NeedsASanRT`, this is deliberate, as in order to calculate it we need to consult `ToolChain`. >From ee6018745b93211af716e8923ecec9a83f717f55 Mon Sep 17 00:00:00 2001 From: Jakub Chlanda Date: Mon, 14 Jul 2025 13:30:57 + Subject: [PATCH] [HIP][Clang][Driver] Move BC preference logic into ROCm detection This patch provides a single point for handling the logic behind choosing common bitcode libraries. The intention is that the users of ROCm installation detector will not have to rewrite options handling code each time the bitcode libraries are queried. This is not too distant from detectors for other architecture that encapsulate the similar decision making process, providing cleaner interface. The only flag left in `getCommonBitcodeLibs` (main point of entry) is `NeedsASanRT`, this is deliberate, as in order to calculate it we need to consult `ToolChain`. --- clang/include/clang/Driver/ToolChain.h | 3 +- clang/lib/Driver/ToolChain.cpp | 3 +- clang/lib/Driver/ToolChains/AMDGPU.cpp | 85 +-- clang/lib/Driver/ToolChains/AMDGPU.h | 2 +- clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp | 10 ++- clang/lib/Driver/ToolChains/AMDGPUOpenMP.h | 3 +- clang/lib/Driver/ToolChains/HIPAMD.cpp | 8 +- clang/lib/Driver/ToolChains/HIPAMD.h | 3 +- clang/lib/Driver/ToolChains/HIPSPV.cpp | 7 +- clang/lib/Driver/ToolChains/HIPSPV.h | 3 +- clang/lib/Driver/ToolChains/ROCm.h | 88 ++-- 11 files changed, 132 insertions(+), 83 deletions(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index b8899e78176b4..e8391d7491a3a 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -806,7 +806,8 @@ class ToolChain { /// Get paths for device libraries. virtual llvm::SmallVector - getDeviceLibs(const llvm::opt::ArgList &Args) const; + getDeviceLibs(const llvm::opt::ArgList &Args, +const Action::OffloadKind DeviceOffloadingKind) const; /// Add the system specific linker arguments to use /// for the given HIP runtime library type. diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 3f9b808b2722e..95a0e6a48d659 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -1614,7 +1614,8 @@ void ToolChain::addSYCLIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const {} llvm::SmallVector -ToolChain::getDeviceLibs(const ArgList &DriverArgs) const { +ToolChain::getDeviceLibs(const ArgList &DriverArgs, + const Action::OffloadKind DeviceOffloadingKind) const { return {}; } diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index 7fc34f451f183..63e9c2a6faa18 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -884,33 +884,14 @@ void ROCMToolChain::addClangTargetOptions( ABIVer)) return; - bool Wave64 = isWave64(DriverArgs, Kind); - // TODO: There are way too many flags that change this. Do we need to check - // them all? - bool DAZ = DriverArgs.hasArg(options::OPT_cl_denorms_are_zero) || - getDefaultDenormsAreZeroForTarget(Kind); - bool FiniteOnly = DriverArgs.hasArg(options::OPT_cl_finite_math_only); - - bool UnsafeMathOpt = - DriverArgs.hasArg(options::OPT_cl_unsafe_math_optimizations); - bool FastRelaxedMath = DriverArgs.hasArg(options::OPT_cl_fast_relaxed_math); - bool CorrectSqrt = - DriverArgs.hasArg(options::OPT_cl_fp32_correctly_rounded_divide_sqrt); - - // GPU Sanitizer currently only supports ASan and is enabled through host - // ASan. - bool GPUSan = DriverArgs.hasFlag(options::OPT_fgpu_sanitize, - options::OPT_fno_gpu_sanitize, true) && -getSanitizerArgs(DriverArgs).needsAsanRt(); - // Add the OpenCL specific bitcode library. llvm::SmallVector BCLibs; BCLibs.emplace_back(RocmInstallation->getOpenCLPath().str()); // Add the generic set of libraries. BCLibs.append(RocmInstallation->getCommonBitcodeLibs( - DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt, - FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, false)); + DriverArgs, LibDe
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); }; } // namespace -void LoweringPreparePass::runOnOp(Operation *op) {} +void LoweringPreparePass::runOnOp(Operation *op) { + if (auto arrayCtor = dyn_cast(op)) { +lowerArrayCtor(arrayCtor); + } +} + +static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder, xlauko wrote: ```suggestion static void lowerArrayDtorCtorIntoLoop(cir::CIRBaseBuilderTy &builder, ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Improve `bugprone-infinite-loop` check by adding handing for structured bindings (PR #144213)
https://github.com/flovent updated https://github.com/llvm/llvm-project/pull/144213 >From 6fce04d8484a3600f292a8bbdd8621db25be7f1d Mon Sep 17 00:00:00 2001 From: flovent Date: Sat, 14 Jun 2025 15:52:26 +0800 Subject: [PATCH 1/4] [clang-tidy] Improve `bugprone-infinite-loop` check by adding handing for strucuted bindings --- .../clang-tidy/bugprone/InfiniteLoopCheck.cpp | 33 +++- .../clang-tidy/utils/Aliasing.cpp | 14 ++-- clang-tools-extra/clang-tidy/utils/Aliasing.h | 2 +- clang-tools-extra/docs/ReleaseNotes.rst | 4 + .../checkers/bugprone/infinite-loop.cpp | 81 +++ 5 files changed, 124 insertions(+), 10 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp index 3c3024d538785..951d67ab5c21a 100644 --- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp @@ -49,7 +49,7 @@ static Matcher loopEndingStmt(Matcher Internal) { } /// Return whether `Var` was changed in `LoopStmt`. -static bool isChanged(const Stmt *LoopStmt, const VarDecl *Var, +static bool isChanged(const Stmt *LoopStmt, const ValueDecl *Var, ASTContext *Context) { if (const auto *ForLoop = dyn_cast(LoopStmt)) return (ForLoop->getInc() && @@ -82,6 +82,23 @@ static bool isVarThatIsPossiblyChanged(const Decl *Func, const Stmt *LoopStmt, isChanged(LoopStmt, Var, Context); // FIXME: Track references. } + +if (const auto *BD = dyn_cast(DRE->getDecl())) { + if (const auto *DD = + dyn_cast_if_present(BD->getDecomposedDecl())) { +if (!DD->isLocalVarDeclOrParm()) + return true; + +if (DD->getType().isVolatileQualified()) + return true; + +if (!BD->getType().getTypePtr()->isIntegerType()) + return true; + +return hasPtrOrReferenceInFunc(Func, BD) || + isChanged(LoopStmt, BD, Context); + } +} } else if (isa(Cond)) { // FIXME: Handle MemberExpr. @@ -123,6 +140,10 @@ static std::string getCondVarNames(const Stmt *Cond) { if (const auto *DRE = dyn_cast(Cond)) { if (const auto *Var = dyn_cast(DRE->getDecl())) return std::string(Var->getName()); + +if (const auto *BD = dyn_cast(DRE->getDecl())) { + return std::string(BD->getName()); +} } std::string Result; @@ -214,10 +235,18 @@ static bool overlap(ArrayRef SCC, /// returns true iff `Cond` involves at least one static local variable. static bool hasStaticLocalVariable(const Stmt *Cond) { - if (const auto *DRE = dyn_cast(Cond)) + if (const auto *DRE = dyn_cast(Cond)) { if (const auto *VD = dyn_cast(DRE->getDecl())) if (VD->isStaticLocal()) return true; + +if (const auto *BD = dyn_cast(DRE->getDecl())) + if (const auto *DD = + dyn_cast_if_present(BD->getDecomposedDecl())) +if (DD->isStaticLocal()) + return true; + } + for (const Stmt *Child : Cond->children()) if (Child && hasStaticLocalVariable(Child)) return true; diff --git a/clang-tools-extra/clang-tidy/utils/Aliasing.cpp b/clang-tools-extra/clang-tidy/utils/Aliasing.cpp index 2facf0625605e..cbe4873b5c022 100644 --- a/clang-tools-extra/clang-tidy/utils/Aliasing.cpp +++ b/clang-tools-extra/clang-tidy/utils/Aliasing.cpp @@ -14,14 +14,14 @@ namespace clang::tidy::utils { /// Return whether \p S is a reference to the declaration of \p Var. -static bool isAccessForVar(const Stmt *S, const VarDecl *Var) { +static bool isAccessForVar(const Stmt *S, const ValueDecl *Var) { if (const auto *DRE = dyn_cast(S)) return DRE->getDecl() == Var; return false; } -static bool capturesByRef(const CXXRecordDecl *RD, const VarDecl *Var) { +static bool capturesByRef(const CXXRecordDecl *RD, const ValueDecl *Var) { return llvm::any_of(RD->captures(), [Var](const LambdaCapture &C) { return C.capturesVariable() && C.getCaptureKind() == LCK_ByRef && C.getCapturedVar() == Var; @@ -29,9 +29,9 @@ static bool capturesByRef(const CXXRecordDecl *RD, const VarDecl *Var) { } /// Return whether \p Var has a pointer or reference in \p S. -static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) { +static bool isPtrOrReferenceForVar(const Stmt *S, const ValueDecl *Var) { // Treat block capture by reference as a form of taking a reference. - if (Var->isEscapingByref()) + if (const auto *VD = dyn_cast(Var); VD && VD->isEscapingByref()) return true; if (const auto *DS = dyn_cast(S)) { @@ -61,7 +61,7 @@ static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) { } /// Return whether \p Var has a pointer or reference in \p S. -static bool hasPtrOrReferenceInStmt(const Stmt *S, const VarDecl *Var) { +static bool hasPtrOrReferenceInStmt(const Stmt *S, const ValueDecl *Var) { if (isPtrOrReferenceFor
[clang-tools-extra] [clang-tidy] Improve `bugprone-infinite-loop` check by adding handing for structured bindings (PR #144213)
@@ -83,6 +83,23 @@ static bool isVarThatIsPossiblyChanged(const Decl *Func, const Stmt *LoopStmt, isChanged(LoopStmt, Var, Context); // FIXME: Track references. } + +if (const auto *BD = dyn_cast(DRE->getDecl())) { + if (const auto *DD = + dyn_cast(BD->getDecomposedDecl())) { +if (!DD->isLocalVarDeclOrParm()) + return true; + +if (DD->getType().isVolatileQualified()) + return true; + +if (!BD->getType().getTypePtr()->isIntegerType()) + return true; + +return hasPtrOrReferenceInFunc(Func, BD) || + isChanged(LoopStmt, BD, Context); flovent wrote: Done in [87a68f7](https://github.com/llvm/llvm-project/pull/144213/commits/87a68f7ca9144f05eb37a51abc537af2fcb53fb2) https://github.com/llvm/llvm-project/pull/144213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add support for `v_sin_bf16_e64` on gfx1250 (PR #149355)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Shilei Tian (shiltian) Changes Co-authored-by: Mekhanoshin, Stanislav--- Patch is 66.99 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149355.diff 23 Files Affected: - (modified) clang/include/clang/Basic/BuiltinsAMDGPU.def (+1) - (modified) clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp (+1) - (modified) clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl (+19) - (modified) llvm/lib/Target/AMDGPU/VOP1Instructions.td (+2) - (added) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.cos.bf16.ll (+33) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1-fake16.s (+45) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s (+48) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp16-fake16.s (+56) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp16.s (+60) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp8-fake16.s (+12) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp8.s (+16) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1-fake16.s (+45) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1.s (+48) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1_dpp16-fake16.s (+56) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1_dpp16.s (+60) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1_dpp8-fake16.s (+16) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1_dpp8.s (+20) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1.txt (+63) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1_dpp16.txt (+59) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1_dpp8.txt (+15) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop3_from_vop1.txt (+64) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop3_from_vop1_dpp16.txt (+60) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop3_from_vop1_dpp8.txt (+20) ``diff diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def b/clang/include/clang/Basic/BuiltinsAMDGPU.def index e7a45f0e4300d..3b6ad7d90be3c 100644 --- a/clang/include/clang/Basic/BuiltinsAMDGPU.def +++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def @@ -675,6 +675,7 @@ TARGET_BUILTIN(__builtin_amdgcn_rsq_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_log_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_exp2_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_sin_bf16, "yy", "nc", "bf16-trans-insts") +TARGET_BUILTIN(__builtin_amdgcn_cos_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_fp8, "hiIi", "nc", "gfx1250-insts") TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_bf8, "hiIi", "nc", "gfx1250-insts") diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp index 32cf622f20605..9f48149354255 100644 --- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp +++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp @@ -433,6 +433,7 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID, return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_sin); case AMDGPU::BI__builtin_amdgcn_cosf: case AMDGPU::BI__builtin_amdgcn_cosh: + case AMDGPU::BI__builtin_amdgcn_cos_bf16: return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_cos); case AMDGPU::BI__builtin_amdgcn_dispatch_ptr: return EmitAMDGPUDispatchPtr(*this, E); diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl index 748b6455103ec..a1f984c129276 100644 --- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl +++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl @@ -156,6 +156,25 @@ void test_sin_bf16(global __bf16* out, __bf16 a) *out = __builtin_amdgcn_sin_bf16(a); } +// CHECK-LABEL: @test_cos_bf16( +// CHECK-NEXT: entry: +// CHECK-NEXT:[[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5) +// CHECK-NEXT:[[A_ADDR:%.*]] = alloca bfloat, align 2, addrspace(5) +// CHECK-NEXT:[[OUT_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[OUT_ADDR]] to ptr +// CHECK-NEXT:[[A_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A_ADDR]] to ptr +// CHECK-NEXT:store ptr addrspace(1) [[OUT:%.*]], ptr [[OUT_ADDR_ASCAST]], align 8 +// CHECK-NEXT:store bfloat [[A:%.*]], ptr [[A_ADDR_ASCAST]], align 2 +// CHECK-NEXT:[[TMP0:%.*]] = load bfloat, ptr [[A_ADDR_ASCAST]], align 2 +// CHECK-NEXT:[[TMP1:%.*]] = call bfloat @llvm.amdgcn.cos.bf16(bfloat [[TMP0]]) +// CHECK-NEXT:[[TMP2:%.*]] = load ptr addrspace(1), ptr [[OUT_ADDR_ASCAST]], align 8 +// CHECK-NEXT:store bfloat [[TMP1]], ptr addrspace(1) [[TMP2]], align 2 +// CHECK-NEXT:ret void +// +void test_cos_bf16(global __bf16* out, __bf16 a) +{ + *out = __builtin_amdgcn_cos_bf16(a); +} + // CHECK-LABEL: @test_cvt_f16_fp8( // C
[clang] [Clang] Ensure correct parameters are in the scope for constraint equivalence checking (PR #149264)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/149264 >From 728de4d995079208605879a0ec30e8f76fe5220c Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Thu, 17 Jul 2025 14:17:02 +0800 Subject: [PATCH 1/2] [Clang] Ensure correct parameters are in the scope for constraint equivalence checking This is another case where untransformed constraint expressions led to inconsistent transforms. We did fix some of those issues by looking at parent scopes, however the parent instantiation scope is not always available because we could also reach here after the parents get instantiated. --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaConcept.cpp| 5 - .../test/SemaTemplate/concepts-using-decl.cpp | 21 +++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index fcd3887ec7a09..6f55d14fd0aa5 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -808,6 +808,7 @@ Bug Fixes in This Version nested scopes. (#GH147495) - Fixed a failed assertion with an operator call expression which comes from a macro expansion when performing analysis for nullability attributes. (#GH138371) +- Fixed a concept equivalent checking crash due to untransformed constraint expressions. (#GH146614) Bug Fixes to Compiler Builtins ^^ diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 834417f8e15ac..fbb2b8e650630 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -923,8 +923,11 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( std::optional ScopeForParameters; if (const NamedDecl *ND = DeclInfo.getDecl(); ND && ND->isFunctionOrFunctionTemplate()) { -ScopeForParameters.emplace(S, /*CombineWithOuterScope=*/true); +ScopeForParameters.emplace(S); const FunctionDecl *FD = ND->getAsFunction(); +if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate(); +Template && Template->getInstantiatedFromMemberTemplate()) + FD = Template->getInstantiatedFromMemberTemplate()->getTemplatedDecl(); for (auto *PVD : FD->parameters()) { if (!PVD->isParameterPack()) { ScopeForParameters->InstantiatedLocal(PVD, PVD); diff --git a/clang/test/SemaTemplate/concepts-using-decl.cpp b/clang/test/SemaTemplate/concepts-using-decl.cpp index fca69dea5c88f..41f7b6d2f8faa 100644 --- a/clang/test/SemaTemplate/concepts-using-decl.cpp +++ b/clang/test/SemaTemplate/concepts-using-decl.cpp @@ -176,3 +176,24 @@ void func() { f.foo<10, 10>(); // expected-error {{no matching member function for call to 'foo'}} } } // namespace heads_without_concepts. + +namespace GH146614 { + +template +struct base { +template +void foo(A x) +requires (requires{x;}) +{} +}; + + +struct child : base { + using base::foo; + template + void foo(A x) + requires (false) + {} +}; + +} >From f777409dce7d80a59ab348c6582ce7533939f2c3 Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Thu, 17 Jul 2025 15:08:23 +0800 Subject: [PATCH 2/2] Fix the original case - we have to look at the outer scope! --- clang/lib/Sema/SemaConcept.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index fbb2b8e650630..5205ca0bca6fa 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -923,12 +923,14 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( std::optional ScopeForParameters; if (const NamedDecl *ND = DeclInfo.getDecl(); ND && ND->isFunctionOrFunctionTemplate()) { -ScopeForParameters.emplace(S); +ScopeForParameters.emplace(S, /*CombineWithOuterScope=*/true); const FunctionDecl *FD = ND->getAsFunction(); if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate(); Template && Template->getInstantiatedFromMemberTemplate()) FD = Template->getInstantiatedFromMemberTemplate()->getTemplatedDecl(); for (auto *PVD : FD->parameters()) { + if (ScopeForParameters->getInstantiationOfIfExists(PVD)) +continue; if (!PVD->isParameterPack()) { ScopeForParameters->InstantiatedLocal(PVD, PVD); continue; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add support for `v_sin_bf16_e64` on gfx1250 (PR #149355)
shiltian wrote: * **#149355** https://app.graphite.dev/github/pr/llvm/llvm-project/149355?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149355?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149355 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LinkerWrapper] Fix -fsave-optimization-record default file (PR #149003)
@@ -5895,6 +5895,11 @@ def o : JoinedOrSeparate<["-"], "o">, Visibility<[ClangOption, CC1Option, CC1AsOption, FC1Option, FlangOption]>, HelpText<"Write output to ">, MetaVarName<"">, MarshallingInfoString>; +def foutput_file_base : Joined<["-"], "foutput-file-base=">, MaskRay wrote: Is this a new driver option? For extra output files we can use -dumpdir https://maskray.me/blog/2023-04-25-compiler-output-files https://github.com/llvm/llvm-project/pull/149003 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Docs] Mention security of libclang (PR #149357)
https://github.com/AaronBallman created https://github.com/llvm/llvm-project/pull/149357 Libclang is a wrapper around the Clang frontend, and frontends are not security-sensitive components of the LLVM project. However, libclang is often embedded in people's downstream tools, so it's best to mention that explicitly. >From 671e4080a5d1e4463f5f6323691411606bc1cf53 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 17 Jul 2025 12:49:39 -0400 Subject: [PATCH] [Docs] Mention security of libclang Libclang is a wrapper around the Clang frontend, and frontends are not security-sensitive components of the LLVM project. However, libclang is often embedded in people's downstream tools, so it's best to mention that explicitly. --- clang/docs/LibClang.rst | 6 ++ 1 file changed, 6 insertions(+) diff --git a/clang/docs/LibClang.rst b/clang/docs/LibClang.rst index 6c2b11ac7fc23..e747022b9c173 100644 --- a/clang/docs/LibClang.rst +++ b/clang/docs/LibClang.rst @@ -404,3 +404,9 @@ following situations are explicitly unsupported: compatible across library versions. * For the same reason as above, serializing objects from one version of the library and deserializing with a different version is also not supported. + +Note: because libclang is a wrapper around the compiler frontend, it is not a +`security-sensitive component`_ of the LLVM Project. Consider using a sandbox +or some other mitigation approach if processing untrusted input. + +.. _security-sensitive component: https://llvm.org/docs/Security.html#what-is-considered-a-security-issue ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Docs] Mention security of libclang (PR #149357)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Aaron Ballman (AaronBallman) Changes Libclang is a wrapper around the Clang frontend, and frontends are not security-sensitive components of the LLVM project. However, libclang is often embedded in people's downstream tools, so it's best to mention that explicitly. --- Full diff: https://github.com/llvm/llvm-project/pull/149357.diff 1 Files Affected: - (modified) clang/docs/LibClang.rst (+6) ``diff diff --git a/clang/docs/LibClang.rst b/clang/docs/LibClang.rst index 6c2b11ac7fc23..e747022b9c173 100644 --- a/clang/docs/LibClang.rst +++ b/clang/docs/LibClang.rst @@ -404,3 +404,9 @@ following situations are explicitly unsupported: compatible across library versions. * For the same reason as above, serializing objects from one version of the library and deserializing with a different version is also not supported. + +Note: because libclang is a wrapper around the compiler frontend, it is not a +`security-sensitive component`_ of the LLVM Project. Consider using a sandbox +or some other mitigation approach if processing untrusted input. + +.. _security-sensitive component: https://llvm.org/docs/Security.html#what-is-considered-a-security-issue `` https://github.com/llvm/llvm-project/pull/149357 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add support for `v_sin_bf16_e64` on gfx1250 (PR #149355)
https://github.com/shiltian created https://github.com/llvm/llvm-project/pull/149355 Co-authored-by: Mekhanoshin, Stanislav >From a6b7ccf491c4d88b18bfdba0dbf839030df189ec Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Thu, 17 Jul 2025 12:45:33 -0400 Subject: [PATCH] [AMDGPU] Add support for `v_sin_bf16_e64` on gfx1250 Co-authored-by: Mekhanoshin, Stanislav --- clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp | 1 + .../CodeGenOpenCL/builtins-amdgcn-gfx1250.cl | 19 ++ llvm/lib/Target/AMDGPU/VOP1Instructions.td| 2 + .../CodeGen/AMDGPU/llvm.amdgcn.cos.bf16.ll| 33 ++ llvm/test/MC/AMDGPU/gfx1250_asm_vop1-fake16.s | 45 + llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s| 48 ++ .../MC/AMDGPU/gfx1250_asm_vop1_dpp16-fake16.s | 56 llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp16.s | 60 + .../MC/AMDGPU/gfx1250_asm_vop1_dpp8-fake16.s | 12 llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp8.s | 16 + .../gfx1250_asm_vop3_from_vop1-fake16.s | 45 + .../MC/AMDGPU/gfx1250_asm_vop3_from_vop1.s| 48 ++ .../gfx1250_asm_vop3_from_vop1_dpp16-fake16.s | 56 .../AMDGPU/gfx1250_asm_vop3_from_vop1_dpp16.s | 60 + .../gfx1250_asm_vop3_from_vop1_dpp8-fake16.s | 16 + .../AMDGPU/gfx1250_asm_vop3_from_vop1_dpp8.s | 20 ++ .../Disassembler/AMDGPU/gfx1250_dasm_vop1.txt | 63 ++ .../AMDGPU/gfx1250_dasm_vop1_dpp16.txt| 59 + .../AMDGPU/gfx1250_dasm_vop1_dpp8.txt | 15 + .../AMDGPU/gfx1250_dasm_vop3_from_vop1.txt| 64 +++ .../gfx1250_dasm_vop3_from_vop1_dpp16.txt | 60 + .../gfx1250_dasm_vop3_from_vop1_dpp8.txt | 20 ++ 22 files changed, 818 insertions(+) create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.cos.bf16.ll diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp index 32cf622f20605..9f48149354255 100644 --- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp +++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp @@ -433,6 +433,7 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID, return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_sin); case AMDGPU::BI__builtin_amdgcn_cosf: case AMDGPU::BI__builtin_amdgcn_cosh: + case AMDGPU::BI__builtin_amdgcn_cos_bf16: return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_cos); case AMDGPU::BI__builtin_amdgcn_dispatch_ptr: return EmitAMDGPUDispatchPtr(*this, E); diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl index 748b6455103ec..a1f984c129276 100644 --- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl +++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl @@ -156,6 +156,25 @@ void test_sin_bf16(global __bf16* out, __bf16 a) *out = __builtin_amdgcn_sin_bf16(a); } +// CHECK-LABEL: @test_cos_bf16( +// CHECK-NEXT: entry: +// CHECK-NEXT:[[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5) +// CHECK-NEXT:[[A_ADDR:%.*]] = alloca bfloat, align 2, addrspace(5) +// CHECK-NEXT:[[OUT_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[OUT_ADDR]] to ptr +// CHECK-NEXT:[[A_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A_ADDR]] to ptr +// CHECK-NEXT:store ptr addrspace(1) [[OUT:%.*]], ptr [[OUT_ADDR_ASCAST]], align 8 +// CHECK-NEXT:store bfloat [[A:%.*]], ptr [[A_ADDR_ASCAST]], align 2 +// CHECK-NEXT:[[TMP0:%.*]] = load bfloat, ptr [[A_ADDR_ASCAST]], align 2 +// CHECK-NEXT:[[TMP1:%.*]] = call bfloat @llvm.amdgcn.cos.bf16(bfloat [[TMP0]]) +// CHECK-NEXT:[[TMP2:%.*]] = load ptr addrspace(1), ptr [[OUT_ADDR_ASCAST]], align 8 +// CHECK-NEXT:store bfloat [[TMP1]], ptr addrspace(1) [[TMP2]], align 2 +// CHECK-NEXT:ret void +// +void test_cos_bf16(global __bf16* out, __bf16 a) +{ + *out = __builtin_amdgcn_cos_bf16(a); +} + // CHECK-LABEL: @test_cvt_f16_fp8( // CHECK-NEXT: entry: // CHECK-NEXT:[[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5) diff --git a/llvm/lib/Target/AMDGPU/VOP1Instructions.td b/llvm/lib/Target/AMDGPU/VOP1Instructions.td index c91319eae7218..ff89b8badeed0 100644 --- a/llvm/lib/Target/AMDGPU/VOP1Instructions.td +++ b/llvm/lib/Target/AMDGPU/VOP1Instructions.td @@ -535,6 +535,7 @@ defm V_RSQ_BF16 : VOP1Inst_t16 <"v_rsq_bf16", VOP_BF16_BF16, AMDGPUrsq>; defm V_LOG_BF16 : VOP1Inst_t16 <"v_log_bf16", VOP_BF16_BF16, AMDGPUlogf16>; defm V_EXP_BF16 : VOP1Inst_t16 <"v_exp_bf16", VOP_BF16_BF16, AMDGPUexpf16>; defm V_SIN_BF16 : VOP1Inst_t16 <"v_sin_bf16", VOP_BF16_BF16, AMDGPUsin>; +defm V_COS_BF16 : VOP1Inst_t16 <"v_cos_bf16", VOP_BF16_BF16, AMDGPUcos>; } } // End TRANS = 1, SchedRW = [WriteTrans32] defm V_FREXP_MANT_F16 : VOP1Inst_t16 <"v_frexp_mant_f16", VOP_F16_F16, int_amdgcn_frexp_mant>; @@ -1149,6 +1150,7 @@ defm V_
[clang] [llvm] [AMDGPU] Add support for `v_sin_bf16_e64` on gfx1250 (PR #149355)
https://github.com/shiltian updated https://github.com/llvm/llvm-project/pull/149355 >From 29b54575b3e64372750466dfafab971697f402f1 Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Thu, 17 Jul 2025 12:45:33 -0400 Subject: [PATCH] [AMDGPU] Add support for `v_sin_bf16_e64` on gfx1250 Co-authored-by: Mekhanoshin, Stanislav --- clang/include/clang/Basic/BuiltinsAMDGPU.def | 1 + clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp | 1 + .../CodeGenOpenCL/builtins-amdgcn-gfx1250.cl | 19 ++ llvm/lib/Target/AMDGPU/VOP1Instructions.td| 2 + .../CodeGen/AMDGPU/llvm.amdgcn.cos.bf16.ll| 33 ++ llvm/test/MC/AMDGPU/gfx1250_asm_vop1-fake16.s | 45 + llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s| 48 ++ .../MC/AMDGPU/gfx1250_asm_vop1_dpp16-fake16.s | 56 llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp16.s | 60 + .../MC/AMDGPU/gfx1250_asm_vop1_dpp8-fake16.s | 12 llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp8.s | 16 + .../gfx1250_asm_vop3_from_vop1-fake16.s | 45 + .../MC/AMDGPU/gfx1250_asm_vop3_from_vop1.s| 48 ++ .../gfx1250_asm_vop3_from_vop1_dpp16-fake16.s | 56 .../AMDGPU/gfx1250_asm_vop3_from_vop1_dpp16.s | 60 + .../gfx1250_asm_vop3_from_vop1_dpp8-fake16.s | 16 + .../AMDGPU/gfx1250_asm_vop3_from_vop1_dpp8.s | 20 ++ .../Disassembler/AMDGPU/gfx1250_dasm_vop1.txt | 63 ++ .../AMDGPU/gfx1250_dasm_vop1_dpp16.txt| 59 + .../AMDGPU/gfx1250_dasm_vop1_dpp8.txt | 15 + .../AMDGPU/gfx1250_dasm_vop3_from_vop1.txt| 64 +++ .../gfx1250_dasm_vop3_from_vop1_dpp16.txt | 60 + .../gfx1250_dasm_vop3_from_vop1_dpp8.txt | 20 ++ 23 files changed, 819 insertions(+) create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.cos.bf16.ll diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def b/clang/include/clang/Basic/BuiltinsAMDGPU.def index e7a45f0e4300d..3b6ad7d90be3c 100644 --- a/clang/include/clang/Basic/BuiltinsAMDGPU.def +++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def @@ -675,6 +675,7 @@ TARGET_BUILTIN(__builtin_amdgcn_rsq_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_log_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_exp2_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_sin_bf16, "yy", "nc", "bf16-trans-insts") +TARGET_BUILTIN(__builtin_amdgcn_cos_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_fp8, "hiIi", "nc", "gfx1250-insts") TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_bf8, "hiIi", "nc", "gfx1250-insts") diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp index 32cf622f20605..9f48149354255 100644 --- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp +++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp @@ -433,6 +433,7 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID, return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_sin); case AMDGPU::BI__builtin_amdgcn_cosf: case AMDGPU::BI__builtin_amdgcn_cosh: + case AMDGPU::BI__builtin_amdgcn_cos_bf16: return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_cos); case AMDGPU::BI__builtin_amdgcn_dispatch_ptr: return EmitAMDGPUDispatchPtr(*this, E); diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl index 748b6455103ec..a1f984c129276 100644 --- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl +++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl @@ -156,6 +156,25 @@ void test_sin_bf16(global __bf16* out, __bf16 a) *out = __builtin_amdgcn_sin_bf16(a); } +// CHECK-LABEL: @test_cos_bf16( +// CHECK-NEXT: entry: +// CHECK-NEXT:[[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5) +// CHECK-NEXT:[[A_ADDR:%.*]] = alloca bfloat, align 2, addrspace(5) +// CHECK-NEXT:[[OUT_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[OUT_ADDR]] to ptr +// CHECK-NEXT:[[A_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A_ADDR]] to ptr +// CHECK-NEXT:store ptr addrspace(1) [[OUT:%.*]], ptr [[OUT_ADDR_ASCAST]], align 8 +// CHECK-NEXT:store bfloat [[A:%.*]], ptr [[A_ADDR_ASCAST]], align 2 +// CHECK-NEXT:[[TMP0:%.*]] = load bfloat, ptr [[A_ADDR_ASCAST]], align 2 +// CHECK-NEXT:[[TMP1:%.*]] = call bfloat @llvm.amdgcn.cos.bf16(bfloat [[TMP0]]) +// CHECK-NEXT:[[TMP2:%.*]] = load ptr addrspace(1), ptr [[OUT_ADDR_ASCAST]], align 8 +// CHECK-NEXT:store bfloat [[TMP1]], ptr addrspace(1) [[TMP2]], align 2 +// CHECK-NEXT:ret void +// +void test_cos_bf16(global __bf16* out, __bf16 a) +{ + *out = __builtin_amdgcn_cos_bf16(a); +} + // CHECK-LABEL: @test_cvt_f16_fp8( // CHECK-NEXT: entry: // CHECK-NEXT:[[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5) diff --g
[clang] [llvm] [AMDGPU] Add support for `v_sin_bf16_e64` on gfx1250 (PR #149355)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Shilei Tian (shiltian) Changes Co-authored-by: Mekhanoshin, Stanislav--- Patch is 66.99 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149355.diff 23 Files Affected: - (modified) clang/include/clang/Basic/BuiltinsAMDGPU.def (+1) - (modified) clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp (+1) - (modified) clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl (+19) - (modified) llvm/lib/Target/AMDGPU/VOP1Instructions.td (+2) - (added) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.cos.bf16.ll (+33) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1-fake16.s (+45) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s (+48) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp16-fake16.s (+56) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp16.s (+60) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp8-fake16.s (+12) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1_dpp8.s (+16) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1-fake16.s (+45) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1.s (+48) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1_dpp16-fake16.s (+56) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1_dpp16.s (+60) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1_dpp8-fake16.s (+16) - (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop3_from_vop1_dpp8.s (+20) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1.txt (+63) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1_dpp16.txt (+59) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1_dpp8.txt (+15) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop3_from_vop1.txt (+64) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop3_from_vop1_dpp16.txt (+60) - (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop3_from_vop1_dpp8.txt (+20) ``diff diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def b/clang/include/clang/Basic/BuiltinsAMDGPU.def index e7a45f0e4300d..3b6ad7d90be3c 100644 --- a/clang/include/clang/Basic/BuiltinsAMDGPU.def +++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def @@ -675,6 +675,7 @@ TARGET_BUILTIN(__builtin_amdgcn_rsq_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_log_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_exp2_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_sin_bf16, "yy", "nc", "bf16-trans-insts") +TARGET_BUILTIN(__builtin_amdgcn_cos_bf16, "yy", "nc", "bf16-trans-insts") TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_fp8, "hiIi", "nc", "gfx1250-insts") TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_bf8, "hiIi", "nc", "gfx1250-insts") diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp index 32cf622f20605..9f48149354255 100644 --- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp +++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp @@ -433,6 +433,7 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID, return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_sin); case AMDGPU::BI__builtin_amdgcn_cosf: case AMDGPU::BI__builtin_amdgcn_cosh: + case AMDGPU::BI__builtin_amdgcn_cos_bf16: return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_cos); case AMDGPU::BI__builtin_amdgcn_dispatch_ptr: return EmitAMDGPUDispatchPtr(*this, E); diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl index 748b6455103ec..a1f984c129276 100644 --- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl +++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl @@ -156,6 +156,25 @@ void test_sin_bf16(global __bf16* out, __bf16 a) *out = __builtin_amdgcn_sin_bf16(a); } +// CHECK-LABEL: @test_cos_bf16( +// CHECK-NEXT: entry: +// CHECK-NEXT:[[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5) +// CHECK-NEXT:[[A_ADDR:%.*]] = alloca bfloat, align 2, addrspace(5) +// CHECK-NEXT:[[OUT_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[OUT_ADDR]] to ptr +// CHECK-NEXT:[[A_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A_ADDR]] to ptr +// CHECK-NEXT:store ptr addrspace(1) [[OUT:%.*]], ptr [[OUT_ADDR_ASCAST]], align 8 +// CHECK-NEXT:store bfloat [[A:%.*]], ptr [[A_ADDR_ASCAST]], align 2 +// CHECK-NEXT:[[TMP0:%.*]] = load bfloat, ptr [[A_ADDR_ASCAST]], align 2 +// CHECK-NEXT:[[TMP1:%.*]] = call bfloat @llvm.amdgcn.cos.bf16(bfloat [[TMP0]]) +// CHECK-NEXT:[[TMP2:%.*]] = load ptr addrspace(1), ptr [[OUT_ADDR_ASCAST]], align 8 +// CHECK-NEXT:store bfloat [[TMP1]], ptr addrspace(1) [[TMP2]], align 2 +// CHECK-NEXT:ret void +// +void test_cos_bf16(global __bf16* out, __bf16 a) +{ + *out = __builtin_amdgcn_cos_bf16(a); +} + // CHECK-LABEL: @test_cvt_f16_fp
[clang] d35931c - [Clang][CodeGen][X86] don't coerce int128 into `{i64,i64}` for SysV-like ABIs (#135230)
Author: T0b1-iOS Date: 2025-07-17T09:57:32-07:00 New Revision: d35931c49e5b37243ace2b79bec87463772b6c94 URL: https://github.com/llvm/llvm-project/commit/d35931c49e5b37243ace2b79bec87463772b6c94 DIFF: https://github.com/llvm/llvm-project/commit/d35931c49e5b37243ace2b79bec87463772b6c94.diff LOG: [Clang][CodeGen][X86] don't coerce int128 into `{i64,i64}` for SysV-like ABIs (#135230) Currently, clang coerces (u)int128_t to two i64 IR parameters when they are passed in registers. This leads to broken debug info for them after applying SROA+InstCombine. SROA generates IR like this ([godbolt](https://godbolt.org/z/YrTa4chfc)): ```llvm define dso_local { i64, i64 } @add(i64 noundef %a.coerce0, i64 noundef %a.coerce1) { entry: %a.sroa.2.0.insert.ext = zext i64 %a.coerce1 to i128 %a.sroa.2.0.insert.shift = shl nuw i128 %a.sroa.2.0.insert.ext, 64 %a.sroa.0.0.insert.ext = zext i64 %a.coerce0 to i128 %a.sroa.0.0.insert.insert = or i128 %a.sroa.2.0.insert.shift, %a.sroa.0.0.insert.ext #dbg_value(i128 %a.sroa.0.0.insert.insert, !17, !DIExpression(), !18) // ... !17 = !DILocalVariable(name: "a", arg: 1, scope: !10, file: !11, line: 1, type: !14) // ... ``` and InstCombine then removes the `or`, moving it into the `DIExpression`, and the `shl` at which point the debug info salvaging in `Transforms/Local` replaces the arguments with `poison` as it does not allow constants larger than 64 bit in `DIExpression`s. I'm working under the assumption that there is interest in fixing this. If not, please tell me. By not coercing `int128_t`s into `{i64, i64}` but keeping them as `i128`, the debug info stays intact and SelectionDAG then generates two `DW_OP_LLVM_fragment` expressions for the two corresponding argument registers. Given that the ABI code for x64 seems to not coerce the argument when it is passed on the stack, it should not lead to any problems keeping it as an `i128` when it is passed in registers. Alternatively, this could be fixed by checking if a constant value fits in 64 bits in the debug info salvaging code and then extending the value on the expression stack to the necessary width. This fixes InstCombine breaking the debug info but then SelectionDAG removes the expression and that seems significantly more complex to debug. Another fix may be to generate `DW_OP_LLVM_fragment` expressions when removing the `or` as it gets marked as disjoint by InstCombine. However, I don't know if the KnownBits information is still available at the time the `or` gets removed and it would probably require refactoring of the debug info salvaging code as that currently only seems to replace single expressions and is not designed to support generating new debug records. Converting `(u)int128_t` arguments to `i128` in the IR seems like the simpler solution, if it doesn't cause any ABI issues. Added: clang/test/CodeGen/X86/i128-debuginfo.c Modified: clang/lib/CodeGen/Targets/X86.cpp clang/test/CodeGen/X86/x86_64-arguments.c clang/test/CodeGen/alloc-align-attr.c clang/test/CodeGen/builtins.c clang/test/CodeGen/ext-int-cc.c clang/test/CodeGen/extend-arg-64.c Removed: diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp index 0b712ac2dabc4..abb91486e7ee6 100644 --- a/clang/lib/CodeGen/Targets/X86.cpp +++ b/clang/lib/CodeGen/Targets/X86.cpp @@ -2470,13 +2470,12 @@ GetSSETypeAtOffset(llvm::Type *IRType, unsigned IROffset, return llvm::Type::getDoubleTy(getVMContext()); } - /// GetINTEGERTypeAtOffset - The ABI specifies that a value should be passed in -/// an 8-byte GPR. This means that we either have a scalar or we are talking -/// about the high or low part of an up-to-16-byte struct. This routine picks -/// the best LLVM IR type to represent this, which may be i64 or may be anything -/// else that the backend will pass in a GPR that works better (e.g. i8, %foo*, -/// etc). +/// one or more 8-byte GPRs. This means that we either have a scalar or we are +/// talking about the high and/or low part of an up-to-16-byte struct. This +/// routine picks the best LLVM IR type to represent this, which may be i64 or +/// may be anything else that the backend will pass in GPRs that works better +/// (e.g. i8, %foo*, etc). /// /// PrefType is an LLVM IR type that corresponds to (part of) the IR type for /// the source type. IROffset is an offset in bytes into the LLVM IR type that @@ -2534,6 +2533,13 @@ GetINTEGERTypeAtOffset(llvm::Type *IRType, unsigned IROffset, SourceOffset); } + // if we have a 128-bit integer, we can pass it safely using an i128 + // so we return that + if (IRType->isIntegerTy(128)) { +assert(IROffset == 0); +return IRType; + } + // Okay, we don't have any better idea of what to pass, so we pass this in an // integer register that isn't too big to fit the rest of the struct
[clang] [Clang][CodeGen][X86] don't coerce int128 into `{i64,i64}` for SysV-like ABIs (PR #135230)
https://github.com/efriedma-quic closed https://github.com/llvm/llvm-project/pull/135230 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -0,0 +1,70 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll +// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG + +struct S { +S(); +}; + +void foo() { +S s[42]; +} + +// CIR: cir.func dso_local @_Z3foov() +// CIR: %[[ARRAY:.*]] = cir.alloca !cir.array, !cir.ptr>, ["s", init] +// CIR: %[[CONST42:.*]] = cir.const #cir.int<42> : !u64i +// CIR: %[[DECAY:.*]] = cir.cast(array_to_ptrdecay, %[[ARRAY]] : !cir.ptr>), !cir.ptr +// CIR: %[[END_PTR:.*]] = cir.ptr_stride(%[[DECAY]] : !cir.ptr, %[[CONST42]] : !u64i), !cir.ptr +// CIR: %[[ITER:.*]] = cir.alloca !cir.ptr, !cir.ptr>, ["__array_idx"] andykaylor wrote: The alloca location determines when stack space is reserved and isn't generally concurrent with the lifetime of the variable. As a general rule, all allocas for the function are gathered at the top of the entry block, regardless of the scope of the variables they represent. Some targets aren't tolerant of allocas in the middle of a function. Classic codegen maintains a variable (AllocaInsertPt) in CodeGenFunction for this exact purpose. We don't seem to have one of those in CIR codegen yet. https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CodeGen][X86] don't coerce int128 into `{i64,i64}` for SysV-like ABIs (PR #135230)
github-actions[bot] wrote: @T0b1-iOS 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/135230 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Ensure proper NULL macro definition for system include files. (PR #149176)
@@ -0,0 +1,15 @@ +// There are at least 2 valid C null-pointer constants as defined +// by the C language standard. +// Test that the macro NULL is defined consistently for all platforms by +// those headers that the C standard mandates a macro definition for NULL. + +// RUN: %clang %s -Dheader="" -E | tail -1 | FileCheck %s +// RUN: %clang %s -Dheader="" -E | tail -1 | FileCheck %s +// RUN: %clang %s -Dheader="" -E | tail -1 | FileCheck %s +// RUN: %clang %s -Dheader="" -E | tail -1 | FileCheck %s +// RUN: %clang %s -Dheader="" -E | tail -1 | FileCheck %s +// RUN: %clang %s -Dheader="" -E | tail -1 | FileCheck %s jamieschmeiser wrote: How can that happen? According to https://clang.llvm.org/docs/CrossCompilation.html: `If you don’t specify the target, CPU names won’t match (since Clang assumes the host triple), and the compilation will go ahead, creating code for the host platform`. There is no target specified so it will not be cross-compiling. Is there something that you would suggest to alleviate your concerns? https://github.com/llvm/llvm-project/pull/149176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add support for `v_cos_bf16_e64` on gfx1250 (PR #149355)
https://github.com/changpeng edited https://github.com/llvm/llvm-project/pull/149355 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add support for `v_cos_bf16_e64` on gfx1250 (PR #149355)
https://github.com/changpeng approved this pull request. LGTM. Changed subject to "v_cos_bf16_e64" based on the contents. https://github.com/llvm/llvm-project/pull/149355 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Enable -fdiscard-value-names build flag to reduce bitcode size (PR #149016)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `premerge-monolithic-linux` running on `premerge-linux-1` while building `libclc` at step 7 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/38396 Here is the relevant piece of the build log for the reference ``` Step 7 (test-build-unified-tree-check-all) failure: test (failure) ... PASS: lld :: COFF/exclude-symbols.s (98673 of 101648) PASS: lld :: COFF/exclude-symbols-embedded.s (98674 of 101648) PASS: lld :: COFF/arm64ec-import-range-ext.test (98675 of 101648) PASS: cfi-standalone-lld-thinlto-x86_64 :: simple-fail.cpp (98676 of 101648) PASS: lit :: discovery.py (98677 of 101648) PASS: cfi-devirt-lld-thinlto-x86_64 :: cross-dso/icall/dlopen.cpp (98678 of 101648) PASS: lld :: COFF/comdat-selection-associative-largest.s (98679 of 101648) PASS: lld :: COFF/eh_frame_terminator.s (98680 of 101648) PASS: lit :: googletest-timeout.py (98681 of 101648) TIMEOUT: MLIR :: Examples/standalone/test.toy (98682 of 101648) TEST 'MLIR :: Examples/standalone/test.toy' FAILED Exit Code: 1 Timeout: Reached timeout of 60 seconds Command Output (stdout): -- # RUN: at line 1 "/etc/cmake/bin/cmake" "/build/buildbot/premerge-monolithic-linux/llvm-project/mlir/examples/standalone" -G "Ninja" -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang -DLLVM_ENABLE_LIBCXX=OFF -DMLIR_DIR=/build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir -DLLVM_USE_LINKER=lld -DPython3_EXECUTABLE="/usr/bin/python3.10" # executed command: /etc/cmake/bin/cmake /build/buildbot/premerge-monolithic-linux/llvm-project/mlir/examples/standalone -G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang -DLLVM_ENABLE_LIBCXX=OFF -DMLIR_DIR=/build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir -DLLVM_USE_LINKER=lld -DPython3_EXECUTABLE=/usr/bin/python3.10 # .---command stdout # | -- The CXX compiler identification is Clang 16.0.6 # | -- The C compiler identification is Clang 16.0.6 # | -- Detecting CXX compiler ABI info # | -- Detecting CXX compiler ABI info - done # | -- Check for working CXX compiler: /usr/bin/clang++ - skipped # | -- Detecting CXX compile features # | -- Detecting CXX compile features - done # | -- Detecting C compiler ABI info # | -- Detecting C compiler ABI info - done # | -- Check for working C compiler: /usr/bin/clang - skipped # | -- Detecting C compile features # | -- Detecting C compile features - done # | -- Looking for histedit.h # | -- Looking for histedit.h - found # | -- Found LibEdit: /usr/include (found version "2.11") # | -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") # | -- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.13") # | -- Using MLIRConfig.cmake in: /build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir # | -- Using LLVMConfig.cmake in: /build/buildbot/premerge-monolithic-linux/build/lib/cmake/llvm # | -- Linker detection: unknown # | -- Performing Test LLVM_LIBSTDCXX_MIN # | -- Performing Test LLVM_LIBSTDCXX_MIN - Success # | -- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR # | -- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR - Success # | -- Performing Test CXX_SUPPORTS_CUSTOM_LINKER # | -- Performing Test CXX_SUPPORTS_CUSTOM_LINKER - Success # | -- Performing Test C_SUPPORTS_FPIC # | -- Performing Test C_SUPPORTS_FPIC - Success # | -- Performing Test CXX_SUPPORTS_FPIC ``` https://github.com/llvm/llvm-project/pull/149016 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][OpenMP] Non-contiguous strided update (PR #144635)
@@ -8713,6 +8713,33 @@ AST_MATCHER_P(OMPExecutableDirective, hasAnyClause, Builder) != Clauses.end(); } +/// Matches any ``#pragma omp target update`` executable directive. +/// +/// Given +/// +/// \code +/// #pragma omp target update from(a) +/// #pragma omp target update to(b) +/// \endcode +/// +/// ``ompTargetUpdateDirective()`` matches both ``omp target update from(a)`` +/// and ``omp target update to(b)``. +extern const internal::VariadicDynCastAllOfMatcher +ompTargetUpdateDirective; alexey-bataev wrote: Why do you need this? https://github.com/llvm/llvm-project/pull/144635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][OpenMP] Non-contiguous strided update (PR #144635)
@@ -7378,7 +7378,31 @@ class MappableExprsHandler { // dimension. uint64_t DimSize = 1; -bool IsNonContiguous = CombinedInfo.NonContigInfo.IsNonContiguous; +// Detects non-contiguous updates due to strided accesses. +// Sets the 'IsNonContiguous' flag so that the 'MapType' bits are set +// correctly when generating information to be passed to the runtime. The +// flag is set to true if any array section has a stride not equal to 1, or +// if the stride is not a constant expression (conservatively assumed +// non-contiguous). +bool IsNonContiguous = [&]() -> bool { + for (const auto &Component : Components) { +const auto *OASE = +dyn_cast(Component.getAssociatedExpression()); +if (OASE) { + const Expr *StrideExpr = OASE->getStride(); + if (StrideExpr) { +if (const auto Constant = +StrideExpr->getIntegerConstantExpr(CGF.getContext())) { + if (!Constant->isOne()) { +return true; + } alexey-bataev wrote: Use early exits to reduce strutured complexity https://github.com/llvm/llvm-project/pull/144635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][OpenMP] Non-contiguous strided update (PR #144635)
@@ -7378,7 +7378,31 @@ class MappableExprsHandler { // dimension. uint64_t DimSize = 1; -bool IsNonContiguous = CombinedInfo.NonContigInfo.IsNonContiguous; +// Detects non-contiguous updates due to strided accesses. +// Sets the 'IsNonContiguous' flag so that the 'MapType' bits are set +// correctly when generating information to be passed to the runtime. The +// flag is set to true if any array section has a stride not equal to 1, or +// if the stride is not a constant expression (conservatively assumed +// non-contiguous). +bool IsNonContiguous = [&]() -> bool { + for (const auto &Component : Components) { +const auto *OASE = +dyn_cast(Component.getAssociatedExpression()); +if (OASE) { alexey-bataev wrote: ``` if (!OASE) continue ``` https://github.com/llvm/llvm-project/pull/144635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -311,6 +312,115 @@ void CIRGenFunction::emitInitializerForField(FieldDecl *field, LValue lhs, assert(!cir::MissingFeatures::requiresCleanups()); } +/// Emit a loop to call a particular constructor for each of several members +/// of an array. +/// +/// \param ctor the constructor to call for each element +/// \param arrayType the type of the array to initialize +/// \param arrayBegin an arrayType* +/// \param zeroInitialize true if each element should be +/// zero-initialized before it is constructed +void CIRGenFunction::emitCXXAggrConstructorCall( +const CXXConstructorDecl *ctor, const clang::ArrayType *arrayType, +Address arrayBegin, const CXXConstructExpr *e, bool newPointerIsChecked, +bool zeroInitialize) { + QualType elementType; + mlir::Value numElements = emitArrayLength(arrayType, elementType, arrayBegin); + emitCXXAggrConstructorCall(ctor, numElements, arrayBegin, e, + newPointerIsChecked, zeroInitialize); +} + +/// Emit a loop to call a particular constructor for each of several members +/// of an array. +/// +/// \param ctor the constructor to call for each element +/// \param numElements the number of elements in the array; +/// may be zero +/// \param arrayBase a T*, where T is the type constructed by ctor +/// \param zeroInitialize true if each element should be +/// zero-initialized before it is constructed +void CIRGenFunction::emitCXXAggrConstructorCall( +const CXXConstructorDecl *ctor, mlir::Value numElements, Address arrayBase, +const CXXConstructExpr *e, bool newPointerIsChecked, bool zeroInitialize) { + // It's legal for numElements to be zero. This can happen both + // dynamically, because x can be zero in 'new A[x]', and statically, + // because of GCC extensions that permit zero-length arrays. There + // are probably legitimate places where we could assume that this + // doesn't happen, but it's not clear that it's worth it. + + // Optimize for a constant count. + auto constantCount = dyn_cast(numElements.getDefiningOp()); + if (constantCount) { +auto constIntAttr = mlir::dyn_cast(constantCount.getValue()); +// Just skip out if the constant count is zero. +if (constIntAttr && constIntAttr.getUInt() == 0) + return; +// Otherwise, emit the check. + } else { +cgm.errorNYI(e->getSourceRange(), "dynamic-length array expression"); + } + + auto arrayTy = mlir::dyn_cast(arrayBase.getElementType()); xlauko wrote: Might be worth renaming `Address::getElementType()` to `Address::getPointeeType()` then? https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); }; } // namespace -void LoweringPreparePass::runOnOp(Operation *op) {} +void LoweringPreparePass::runOnOp(Operation *op) { + if (auto arrayCtor = dyn_cast(op)) { +lowerArrayCtor(arrayCtor); + } +} + +static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder, + mlir::Operation *op, mlir::Type eltTy, + mlir::Value arrayAddr, + uint64_t arrayLen) { + // Generate loop to call into ctor/dtor for every element. + Location loc = op->getLoc(); + + // TODO: instead of fixed integer size, create alias for PtrDiffTy and unify + // with CIRGen stuff. + auto ptrDiffTy = + cir::IntType::get(builder.getContext(), 64, /*isSigned=*/false); + auto numArrayElementsConst = builder.create( + loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, arrayLen)); + + auto begin = builder.create( + loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr); + mlir::Value end = builder.create(loc, eltTy, begin, + numArrayElementsConst); + + mlir::Value tmpAddr = builder.createAlloca( + loc, /*addr type*/ builder.getPointerTo(eltTy), + /*var type*/ eltTy, "__array_idx", builder.getAlignmentAttr(1)); + builder.createStore(loc, begin, tmpAddr); + + cir::DoWhileOp loop = builder.createDoWhile( + loc, + /*condBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); +mlir::Type boolTy = cir::BoolType::get(b.getContext()); +auto cmp = builder.create(loc, boolTy, cir::CmpOpKind::eq, + currentElement, end); +builder.createCondition(cmp); + }, + /*bodyBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); + +CallOp ctorCall; +op->walk([&](CallOp c) { ctorCall = c; }); xlauko wrote: ```suggestion op->walk([&](cir::CallOp c) { ctorCall = c; }); ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); }; } // namespace -void LoweringPreparePass::runOnOp(Operation *op) {} +void LoweringPreparePass::runOnOp(Operation *op) { + if (auto arrayCtor = dyn_cast(op)) { +lowerArrayCtor(arrayCtor); + } +} + +static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder, + mlir::Operation *op, mlir::Type eltTy, + mlir::Value arrayAddr, + uint64_t arrayLen) { + // Generate loop to call into ctor/dtor for every element. + Location loc = op->getLoc(); + + // TODO: instead of fixed integer size, create alias for PtrDiffTy and unify + // with CIRGen stuff. + auto ptrDiffTy = + cir::IntType::get(builder.getContext(), 64, /*isSigned=*/false); + auto numArrayElementsConst = builder.create( + loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, arrayLen)); + + auto begin = builder.create( + loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr); + mlir::Value end = builder.create(loc, eltTy, begin, + numArrayElementsConst); + + mlir::Value tmpAddr = builder.createAlloca( + loc, /*addr type*/ builder.getPointerTo(eltTy), + /*var type*/ eltTy, "__array_idx", builder.getAlignmentAttr(1)); + builder.createStore(loc, begin, tmpAddr); + + cir::DoWhileOp loop = builder.createDoWhile( + loc, + /*condBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); +mlir::Type boolTy = cir::BoolType::get(b.getContext()); +auto cmp = builder.create(loc, boolTy, cir::CmpOpKind::eq, + currentElement, end); +builder.createCondition(cmp); + }, + /*bodyBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); + +CallOp ctorCall; +op->walk([&](CallOp c) { ctorCall = c; }); +assert(ctorCall && "expected ctor call"); + +auto one = builder.create( +loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, 1)); + +ctorCall->moveAfter(one); +ctorCall->setOperand(0, currentElement); + +// Advance pointer and store them to temporary variable +auto nextElement = +builder.create(loc, eltTy, currentElement, one); +builder.createStore(loc, nextElement, tmpAddr); +builder.createYield(loc); + }); + + op->replaceAllUsesWith(loop); + op->erase(); +} + +void LoweringPreparePass::lowerArrayCtor(ArrayCtor op) { xlauko wrote: ```suggestion void LoweringPreparePass::lowerArrayCtor(cir::ArrayCtor op) { ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); }; } // namespace -void LoweringPreparePass::runOnOp(Operation *op) {} +void LoweringPreparePass::runOnOp(Operation *op) { + if (auto arrayCtor = dyn_cast(op)) { +lowerArrayCtor(arrayCtor); + } +} + +static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder, + mlir::Operation *op, mlir::Type eltTy, + mlir::Value arrayAddr, + uint64_t arrayLen) { + // Generate loop to call into ctor/dtor for every element. + Location loc = op->getLoc(); + + // TODO: instead of fixed integer size, create alias for PtrDiffTy and unify + // with CIRGen stuff. + auto ptrDiffTy = + cir::IntType::get(builder.getContext(), 64, /*isSigned=*/false); + auto numArrayElementsConst = builder.create( + loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, arrayLen)); + + auto begin = builder.create( + loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr); + mlir::Value end = builder.create(loc, eltTy, begin, + numArrayElementsConst); + + mlir::Value tmpAddr = builder.createAlloca( + loc, /*addr type*/ builder.getPointerTo(eltTy), + /*var type*/ eltTy, "__array_idx", builder.getAlignmentAttr(1)); + builder.createStore(loc, begin, tmpAddr); + + cir::DoWhileOp loop = builder.createDoWhile( + loc, + /*condBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); +mlir::Type boolTy = cir::BoolType::get(b.getContext()); +auto cmp = builder.create(loc, boolTy, cir::CmpOpKind::eq, + currentElement, end); +builder.createCondition(cmp); + }, + /*bodyBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); + +CallOp ctorCall; +op->walk([&](CallOp c) { ctorCall = c; }); +assert(ctorCall && "expected ctor call"); + +auto one = builder.create( +loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, 1)); + +ctorCall->moveAfter(one); +ctorCall->setOperand(0, currentElement); + +// Advance pointer and store them to temporary variable +auto nextElement = +builder.create(loc, eltTy, currentElement, one); +builder.createStore(loc, nextElement, tmpAddr); +builder.createYield(loc); + }); + + op->replaceAllUsesWith(loop); + op->erase(); +} + +void LoweringPreparePass::lowerArrayCtor(ArrayCtor op) { + CIRBaseBuilderTy builder(getContext()); + builder.setInsertionPointAfter(op.getOperation()); + + Type eltTy = op->getRegion(0).getArgument(0).getType(); + auto arrayLen = + mlir::cast(op.getAddr().getType().getPointee()).getSize(); + lowerArrayDtorCtorIntoLoop(builder, op, eltTy, op.getAddr(), arrayLen); +} void LoweringPreparePass::runOnOperation() { + Operation *op = getOperation(); + llvm::SmallVector opsToTransform; xlauko wrote: ```suggestion llvm::SmallVector opsToTransform; ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); }; } // namespace -void LoweringPreparePass::runOnOp(Operation *op) {} +void LoweringPreparePass::runOnOp(Operation *op) { + if (auto arrayCtor = dyn_cast(op)) { +lowerArrayCtor(arrayCtor); + } +} + +static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder, + mlir::Operation *op, mlir::Type eltTy, + mlir::Value arrayAddr, + uint64_t arrayLen) { + // Generate loop to call into ctor/dtor for every element. + Location loc = op->getLoc(); + + // TODO: instead of fixed integer size, create alias for PtrDiffTy and unify + // with CIRGen stuff. + auto ptrDiffTy = + cir::IntType::get(builder.getContext(), 64, /*isSigned=*/false); + auto numArrayElementsConst = builder.create( + loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, arrayLen)); + + auto begin = builder.create( + loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr); + mlir::Value end = builder.create(loc, eltTy, begin, + numArrayElementsConst); + + mlir::Value tmpAddr = builder.createAlloca( + loc, /*addr type*/ builder.getPointerTo(eltTy), + /*var type*/ eltTy, "__array_idx", builder.getAlignmentAttr(1)); + builder.createStore(loc, begin, tmpAddr); + + cir::DoWhileOp loop = builder.createDoWhile( + loc, + /*condBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); +mlir::Type boolTy = cir::BoolType::get(b.getContext()); +auto cmp = builder.create(loc, boolTy, cir::CmpOpKind::eq, + currentElement, end); +builder.createCondition(cmp); + }, + /*bodyBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); + +CallOp ctorCall; +op->walk([&](CallOp c) { ctorCall = c; }); +assert(ctorCall && "expected ctor call"); + +auto one = builder.create( +loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, 1)); + +ctorCall->moveAfter(one); +ctorCall->setOperand(0, currentElement); + +// Advance pointer and store them to temporary variable +auto nextElement = +builder.create(loc, eltTy, currentElement, one); +builder.createStore(loc, nextElement, tmpAddr); +builder.createYield(loc); + }); + + op->replaceAllUsesWith(loop); + op->erase(); +} + +void LoweringPreparePass::lowerArrayCtor(ArrayCtor op) { + CIRBaseBuilderTy builder(getContext()); + builder.setInsertionPointAfter(op.getOperation()); + + Type eltTy = op->getRegion(0).getArgument(0).getType(); xlauko wrote: ```suggestion mlir::Type eltTy = op->getRegion(0).getArgument(0).getType(); ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); }; } // namespace -void LoweringPreparePass::runOnOp(Operation *op) {} +void LoweringPreparePass::runOnOp(Operation *op) { xlauko wrote: ```suggestion void LoweringPreparePass::runOnOp(mlir::Operation *op) { ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); }; } // namespace -void LoweringPreparePass::runOnOp(Operation *op) {} +void LoweringPreparePass::runOnOp(Operation *op) { + if (auto arrayCtor = dyn_cast(op)) { +lowerArrayCtor(arrayCtor); + } +} + +static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder, + mlir::Operation *op, mlir::Type eltTy, + mlir::Value arrayAddr, + uint64_t arrayLen) { + // Generate loop to call into ctor/dtor for every element. + Location loc = op->getLoc(); + + // TODO: instead of fixed integer size, create alias for PtrDiffTy and unify + // with CIRGen stuff. + auto ptrDiffTy = + cir::IntType::get(builder.getContext(), 64, /*isSigned=*/false); + auto numArrayElementsConst = builder.create( + loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, arrayLen)); + + auto begin = builder.create( + loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr); + mlir::Value end = builder.create(loc, eltTy, begin, + numArrayElementsConst); + + mlir::Value tmpAddr = builder.createAlloca( + loc, /*addr type*/ builder.getPointerTo(eltTy), + /*var type*/ eltTy, "__array_idx", builder.getAlignmentAttr(1)); + builder.createStore(loc, begin, tmpAddr); + + cir::DoWhileOp loop = builder.createDoWhile( + loc, + /*condBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); +mlir::Type boolTy = cir::BoolType::get(b.getContext()); +auto cmp = builder.create(loc, boolTy, cir::CmpOpKind::eq, + currentElement, end); +builder.createCondition(cmp); + }, + /*bodyBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); + +CallOp ctorCall; +op->walk([&](CallOp c) { ctorCall = c; }); +assert(ctorCall && "expected ctor call"); + +auto one = builder.create( +loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, 1)); + +ctorCall->moveAfter(one); +ctorCall->setOperand(0, currentElement); + +// Advance pointer and store them to temporary variable +auto nextElement = +builder.create(loc, eltTy, currentElement, one); +builder.createStore(loc, nextElement, tmpAddr); +builder.createYield(loc); + }); + + op->replaceAllUsesWith(loop); + op->erase(); +} + +void LoweringPreparePass::lowerArrayCtor(ArrayCtor op) { + CIRBaseBuilderTy builder(getContext()); + builder.setInsertionPointAfter(op.getOperation()); + + Type eltTy = op->getRegion(0).getArgument(0).getType(); + auto arrayLen = + mlir::cast(op.getAddr().getType().getPointee()).getSize(); + lowerArrayDtorCtorIntoLoop(builder, op, eltTy, op.getAddr(), arrayLen); +} void LoweringPreparePass::runOnOperation() { + Operation *op = getOperation(); xlauko wrote: ```suggestion mlir::Operation *op = getOperation(); ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); xlauko wrote: ```suggestion void lowerArrayCtor(cir::ArrayCtor op); ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); }; } // namespace -void LoweringPreparePass::runOnOp(Operation *op) {} +void LoweringPreparePass::runOnOp(Operation *op) { + if (auto arrayCtor = dyn_cast(op)) { +lowerArrayCtor(arrayCtor); + } +} + +static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder, + mlir::Operation *op, mlir::Type eltTy, + mlir::Value arrayAddr, + uint64_t arrayLen) { + // Generate loop to call into ctor/dtor for every element. + Location loc = op->getLoc(); + + // TODO: instead of fixed integer size, create alias for PtrDiffTy and unify + // with CIRGen stuff. + auto ptrDiffTy = + cir::IntType::get(builder.getContext(), 64, /*isSigned=*/false); + auto numArrayElementsConst = builder.create( + loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, arrayLen)); + + auto begin = builder.create( + loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr); + mlir::Value end = builder.create(loc, eltTy, begin, + numArrayElementsConst); + + mlir::Value tmpAddr = builder.createAlloca( + loc, /*addr type*/ builder.getPointerTo(eltTy), + /*var type*/ eltTy, "__array_idx", builder.getAlignmentAttr(1)); + builder.createStore(loc, begin, tmpAddr); + + cir::DoWhileOp loop = builder.createDoWhile( + loc, + /*condBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); +mlir::Type boolTy = cir::BoolType::get(b.getContext()); +auto cmp = builder.create(loc, boolTy, cir::CmpOpKind::eq, + currentElement, end); +builder.createCondition(cmp); + }, + /*bodyBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); + +CallOp ctorCall; +op->walk([&](CallOp c) { ctorCall = c; }); +assert(ctorCall && "expected ctor call"); + +auto one = builder.create( +loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, 1)); + +ctorCall->moveAfter(one); +ctorCall->setOperand(0, currentElement); + +// Advance pointer and store them to temporary variable +auto nextElement = +builder.create(loc, eltTy, currentElement, one); +builder.createStore(loc, nextElement, tmpAddr); +builder.createYield(loc); + }); + + op->replaceAllUsesWith(loop); + op->erase(); +} + +void LoweringPreparePass::lowerArrayCtor(ArrayCtor op) { + CIRBaseBuilderTy builder(getContext()); xlauko wrote: ```suggestion cir::CIRBaseBuilderTy builder(getContext()); ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); }; } // namespace -void LoweringPreparePass::runOnOp(Operation *op) {} +void LoweringPreparePass::runOnOp(Operation *op) { + if (auto arrayCtor = dyn_cast(op)) { +lowerArrayCtor(arrayCtor); + } +} + +static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder, + mlir::Operation *op, mlir::Type eltTy, + mlir::Value arrayAddr, + uint64_t arrayLen) { + // Generate loop to call into ctor/dtor for every element. + Location loc = op->getLoc(); + + // TODO: instead of fixed integer size, create alias for PtrDiffTy and unify + // with CIRGen stuff. + auto ptrDiffTy = + cir::IntType::get(builder.getContext(), 64, /*isSigned=*/false); + auto numArrayElementsConst = builder.create( + loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, arrayLen)); + + auto begin = builder.create( + loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr); + mlir::Value end = builder.create(loc, eltTy, begin, + numArrayElementsConst); + + mlir::Value tmpAddr = builder.createAlloca( + loc, /*addr type*/ builder.getPointerTo(eltTy), + /*var type*/ eltTy, "__array_idx", builder.getAlignmentAttr(1)); + builder.createStore(loc, begin, tmpAddr); + + cir::DoWhileOp loop = builder.createDoWhile( + loc, + /*condBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); +mlir::Type boolTy = cir::BoolType::get(b.getContext()); +auto cmp = builder.create(loc, boolTy, cir::CmpOpKind::eq, + currentElement, end); +builder.createCondition(cmp); + }, + /*bodyBuilder=*/ + [&](mlir::OpBuilder &b, mlir::Location loc) { +auto currentElement = b.create(loc, eltTy, tmpAddr); + +CallOp ctorCall; xlauko wrote: ```suggestion cir::CallOp ctorCall; ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add support for array constructors (PR #149142)
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase { void runOnOperation() override; void runOnOp(Operation *op); + void lowerArrayCtor(ArrayCtor op); }; } // namespace -void LoweringPreparePass::runOnOp(Operation *op) {} +void LoweringPreparePass::runOnOp(Operation *op) { + if (auto arrayCtor = dyn_cast(op)) { +lowerArrayCtor(arrayCtor); + } +} + +static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder, + mlir::Operation *op, mlir::Type eltTy, + mlir::Value arrayAddr, + uint64_t arrayLen) { + // Generate loop to call into ctor/dtor for every element. + Location loc = op->getLoc(); + + // TODO: instead of fixed integer size, create alias for PtrDiffTy and unify + // with CIRGen stuff. + auto ptrDiffTy = + cir::IntType::get(builder.getContext(), 64, /*isSigned=*/false); + auto numArrayElementsConst = builder.create( + loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, arrayLen)); xlauko wrote: ```suggestion cir::ConstantOp numArrayElementsConst = builder.getUnsignedInt(loc, 64, arrayLen); ``` https://github.com/llvm/llvm-project/pull/149142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits