[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)
tbaederr wrote: I like this change, the only thing I'm a little afraid of is that the output will deteriorate for large structs https://github.com/llvm/llvm-project/pull/74852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7a0fd97 - [NFC][CLANG] Rename duplicate loop attributes diagnostic functions (#75657)
Author: smanna12 Date: 2023-12-15T22:09:19-06:00 New Revision: 7a0fd97ac1094b9b1547c8d7b35e583d7387224d URL: https://github.com/llvm/llvm-project/commit/7a0fd97ac1094b9b1547c8d7b35e583d7387224d DIFF: https://github.com/llvm/llvm-project/commit/7a0fd97ac1094b9b1547c8d7b35e583d7387224d.diff LOG: [NFC][CLANG] Rename duplicate loop attributes diagnostic functions (#75657) This patch renames CheckForDuplicateCodeAlignAttrs() to CheckForDuplicateLoopAttrs() and corresponding other functions that call it to be used for other statement attributes in future. Added: Modified: clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaStmtAttr.cpp clang/lib/Sema/TreeTransform.h Removed: diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1d7b4c729ce84e..20228da15ade8f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2102,7 +2102,7 @@ class Sema final { SourceLocation AttrLoc); CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E); - bool CheckRebuiltCodeAlignStmtAttributes(ArrayRef Attrs); + bool CheckRebuiltStmtAttributes(ArrayRef Attrs); bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index 0d0a7bcebab4e8..e6a4d3e63e4aa8 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -361,11 +361,10 @@ static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const ParsedAttr &A) { } // Diagnose non-identical duplicates as a 'conflicting' loop attributes -// and suppress duplicate errors in cases where the two match for -// [[clang::code_align()]] attribute. -static void CheckForDuplicateCodeAlignAttrs(Sema &S, -ArrayRef Attrs) { - auto FindFunc = [](const Attr *A) { return isa(A); }; +// and suppress duplicate errors in cases where the two match. +template +static void CheckForDuplicateLoopAttrs(Sema &S, ArrayRef Attrs) { + auto FindFunc = [](const Attr *A) { return isa(A); }; const auto *FirstItr = std::find_if(Attrs.begin(), Attrs.end(), FindFunc); if (FirstItr == Attrs.end()) // no attributes found @@ -375,7 +374,7 @@ static void CheckForDuplicateCodeAlignAttrs(Sema &S, std::optional FirstValue; const auto *CAFA = - dyn_cast(cast(*FirstItr)->getAlignment()); + dyn_cast(cast(*FirstItr)->getAlignment()); // Return early if first alignment expression is dependent (since we don't // know what the effective size will be), and skip the loop entirely. if (!CAFA) @@ -383,8 +382,8 @@ static void CheckForDuplicateCodeAlignAttrs(Sema &S, while (Attrs.end() != (LastFoundItr = std::find_if(LastFoundItr + 1, Attrs.end(), FindFunc))) { -const auto *CASA = dyn_cast( -cast(*LastFoundItr)->getAlignment()); +const auto *CASA = +dyn_cast(cast(*LastFoundItr)->getAlignment()); // If the value is dependent, we can not test anything. if (!CASA) return; @@ -635,10 +634,10 @@ void Sema::ProcessStmtAttributes(Stmt *S, const ParsedAttributes &InAttrs, } CheckForIncompatibleAttributes(*this, OutAttrs); - CheckForDuplicateCodeAlignAttrs(*this, OutAttrs); + CheckForDuplicateLoopAttrs(*this, OutAttrs); } -bool Sema::CheckRebuiltCodeAlignStmtAttributes(ArrayRef Attrs) { - CheckForDuplicateCodeAlignAttrs(*this, Attrs); +bool Sema::CheckRebuiltStmtAttributes(ArrayRef Attrs) { + CheckForDuplicateLoopAttrs(*this, Attrs); return false; } diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 1ad843d0bf4e0c..7df5bf0cb71370 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1378,7 +1378,7 @@ class TreeTransform { StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef Attrs, Stmt *SubStmt) { -if (SemaRef.CheckRebuiltCodeAlignStmtAttributes(Attrs)) +if (SemaRef.CheckRebuiltStmtAttributes(Attrs)) return StmtError(); return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][CLANG] Rename duplicate loop attributes diagnostic functions (PR #75657)
https://github.com/smanna12 closed https://github.com/llvm/llvm-project/pull/75657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ClangRepl] Reland Semanic Code Completion (PR #75556)
capfredf wrote: @vgvassilev Sure. https://github.com/llvm/llvm-project/pull/75556 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [mlir] [mlir][TilingInterface] Early return cloned ops if tile sizes are zeros. (PR #75410)
@@ -362,14 +362,20 @@ mlir::scf::tileUsingSCFForOp(RewriterBase &rewriter, TilingInterface op, auto clonedOp = cast( cloneOpAndUpdateDestinationArgs(rewriter, op, clonedOpDestination)); - // 5b. Tile the cloned operation. + // 5b. Early return cloned op if tiling is not happening. MaheshRavishankar wrote: This might work, but maybe we should just not clone the op if tile sizes are zero. https://github.com/llvm/llvm-project/pull/75410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [mlir] [llvm] [mlir][TilingInterface] Early return cloned ops if tile sizes are zeros. (PR #75410)
https://github.com/MaheshRavishankar requested changes to this pull request. https://github.com/llvm/llvm-project/pull/75410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [mlir] [llvm] [mlir][TilingInterface] Early return cloned ops if tile sizes are zeros. (PR #75410)
https://github.com/MaheshRavishankar edited https://github.com/llvm/llvm-project/pull/75410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9950bb9 - [ASTReader] Fix readability-inconsistent-declaration-parameter-name. NFC
Author: Fangrui Song Date: 2023-12-15T17:11:21-08:00 New Revision: 9950bb994461d6dc67ac9b33e48f549edcb44739 URL: https://github.com/llvm/llvm-project/commit/9950bb994461d6dc67ac9b33e48f549edcb44739 DIFF: https://github.com/llvm/llvm-project/commit/9950bb994461d6dc67ac9b33e48f549edcb44739.diff LOG: [ASTReader] Fix readability-inconsistent-declaration-parameter-name. NFC Added: Modified: clang/include/clang/Serialization/ASTReader.h clang/lib/Serialization/ASTReader.cpp Removed: diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index 9bb89ec9410911..59358e77edb072 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -1424,7 +1424,7 @@ class ASTReader RecordLocation TypeCursorForIndex(unsigned Index); void LoadedDecl(unsigned Index, Decl *D); Decl *ReadDeclRecord(serialization::DeclID ID); - void markIncompleteDeclChain(Decl *Canon); + void markIncompleteDeclChain(Decl *D); /// Returns the most recent declaration of a declaration (which must be /// of a redeclarable kind) that is either local or has already been loaded @@ -2093,7 +2093,7 @@ class ASTReader SmallVectorImpl> &Sels) override; void ReadWeakUndeclaredIdentifiers( - SmallVectorImpl> &WI) override; + SmallVectorImpl> &WeakIDs) override; void ReadUsedVTables(SmallVectorImpl &VTables) override; @@ -2203,7 +2203,7 @@ class ASTReader /// Retrieve the global selector ID that corresponds to this /// the local selector ID in a given module. - serialization::SelectorID getGlobalSelectorID(ModuleFile &F, + serialization::SelectorID getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const; /// Read the contents of a CXXCtorInitializer array. diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5b51ac4d7a..9effd333daccdb 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1781,26 +1781,26 @@ llvm::Error ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, } } -Token ASTReader::ReadToken(ModuleFile &F, const RecordDataImpl &Record, +Token ASTReader::ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx) { Token Tok; Tok.startToken(); - Tok.setLocation(ReadSourceLocation(F, Record, Idx)); + Tok.setLocation(ReadSourceLocation(M, Record, Idx)); Tok.setKind((tok::TokenKind)Record[Idx++]); Tok.setFlag((Token::TokenFlags)Record[Idx++]); if (Tok.isAnnotation()) { -Tok.setAnnotationEndLoc(ReadSourceLocation(F, Record, Idx)); +Tok.setAnnotationEndLoc(ReadSourceLocation(M, Record, Idx)); switch (Tok.getKind()) { case tok::annot_pragma_loop_hint: { auto *Info = new (PP.getPreprocessorAllocator()) PragmaLoopHintInfo; - Info->PragmaName = ReadToken(F, Record, Idx); - Info->Option = ReadToken(F, Record, Idx); + Info->PragmaName = ReadToken(M, Record, Idx); + Info->Option = ReadToken(M, Record, Idx); unsigned NumTokens = Record[Idx++]; SmallVector Toks; Toks.reserve(NumTokens); for (unsigned I = 0; I < NumTokens; ++I) -Toks.push_back(ReadToken(F, Record, Idx)); +Toks.push_back(ReadToken(M, Record, Idx)); Info->Toks = llvm::ArrayRef(Toks).copy(PP.getPreprocessorAllocator()); Tok.setAnnotationValue(static_cast(Info)); break; @@ -1811,7 +1811,7 @@ Token ASTReader::ReadToken(ModuleFile &F, const RecordDataImpl &Record, auto SlotLabel = ReadString(Record, Idx); Info->SlotLabel = llvm::StringRef(SlotLabel).copy(PP.getPreprocessorAllocator()); - Info->Alignment = ReadToken(F, Record, Idx); + Info->Alignment = ReadToken(M, Record, Idx); Tok.setAnnotationValue(static_cast(Info)); break; } @@ -1827,7 +1827,7 @@ Token ASTReader::ReadToken(ModuleFile &F, const RecordDataImpl &Record, } } else { Tok.setLength(Record[Idx++]); -if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++])) +if (IdentifierInfo *II = getLocalIdentifier(M, Record[Idx++])) Tok.setIdentifierInfo(II); } return Tok; @@ -1997,10 +1997,10 @@ unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) { } HeaderFileInfoTrait::internal_key_type -HeaderFileInfoTrait::GetInternalKey(external_key_type FE) { - internal_key_type ikey = {FE.getSize(), -M.HasTimestamps ? FE.getModificationTime() : 0, -FE.getName(), /*Imported*/ false}; +HeaderFileInfoTrait::GetInternalKey(external_key_type ekey) { + internal_key_type ikey = {ekey.getSize(), +M.HasTimestamps ? ekey.getModificationTime() : 0, +
[clang] [llvm] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)
@@ -216,15 +214,62 @@ void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV, assert(false && "Unsupported buffer type!"); return; } - assert(ResourceMD != nullptr && "ResourceMD must have been set by the switch above."); llvm::hlsl::FrontendResource Res( - GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space); + GV, RK, ET, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space); ResourceMD->addOperand(Res.getMetadata()); } +static llvm::hlsl::ElementType +calculateElementType(const ASTContext &Context, const clang::Type *ResourceTy) { + using llvm::hlsl::ElementType; + + // TODO: We may need to update this when we add things like ByteAddressBuffer + // that don't have a template parameter (or, indeed, an element type). + const auto *TST = ResourceTy->getAs(); + assert(TST && "Resource types must be template specializations"); + ArrayRef Args = TST->template_arguments(); + assert(!Args.empty() && "Resource has no element type"); + + // At this point we have a resource with an element type, so we can assume + // that it's valid or we would have diagnosed the error earlier. + QualType ElTy = Args[0].getAsType(); + + // We should either have a basic type or a vector of a basic type. dmpots wrote: What about matrix types? Do we need to handle them here as well? https://github.com/llvm/llvm-project/pull/75674 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)
@@ -253,35 +246,6 @@ void UAVResource::print(raw_ostream &OS) const { ResourceBase::print(OS, "U", "u"); } -// FIXME: Capture this in HLSL source. I would go do this right now, but I want -// to get this in first so that I can make sure to capture all the extra -// information we need to remove the source type string from here (See issue: -// https://github.com/llvm/llvm-project/issues/57991). dmpots wrote: Does this PR fix this issue? I did not see it was linked to this PR, but I may not be looking in the right place. https://github.com/llvm/llvm-project/pull/75674 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)
https://github.com/dmpots edited https://github.com/llvm/llvm-project/pull/75674 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)
https://github.com/dmpots approved this pull request. https://github.com/llvm/llvm-project/pull/75674 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CodeGen] Emit a more accurate alignment for non-temporal loads/stores (PR #75675)
https://github.com/rjmccall approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/75675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
https://github.com/malavikasamak edited https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [CodeGen][arm64e] Add methods and data members to Address, which are needed to authenticate signed pointers (PR #67454)
@@ -232,19 +232,19 @@ static Value *MakeBinaryAtomicValue( static Value *EmitNontemporalStore(CodeGenFunction &CGF, const CallExpr *E) { Value *Val = CGF.EmitScalarExpr(E->getArg(0)); - Value *Address = CGF.EmitScalarExpr(E->getArg(1)); + Address Addr = CGF.EmitPointerWithAlignment(E->getArg(1)); Val = CGF.EmitToMemory(Val, E->getArg(0)->getType()); - LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getArg(0)->getType()); + LValue LV = CGF.MakeAddrLValue(Addr, E->getArg(0)->getType()); LV.setNontemporal(true); CGF.EmitStoreOfScalar(Val, LV, false); return nullptr; } static Value *EmitNontemporalLoad(CodeGenFunction &CGF, const CallExpr *E) { - Value *Address = CGF.EmitScalarExpr(E->getArg(0)); + Address Addr = CGF.EmitPointerWithAlignment(E->getArg(0)); - LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getType()); + LValue LV = CGF.MakeAddrLValue(Addr, E->getType()); ahatanak wrote: The patch that fixes the alignment: https://github.com/llvm/llvm-project/pull/75675 https://github.com/llvm/llvm-project/pull/67454 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CGCUDANV] Unify PointerType members of CGNVCUDARuntime (NFC) (PR #75668)
bjope wrote: I don't know much about this code, so I can't really judge if this is good and wanted etc. When I did opaque pointer cleanups myself earlier (removing some no-op bitcasts and using PointerType::get etc) I did leave lots of things like this around on purpose, as even if the types are opaque internal to LLVM it might be nice to see which kind of types that actually are used and derefenced in the API:s. So the differently named variables helps identifying which arguments that points to what kind of data. Anyway, the type cache in CGNVCUDARuntime probably shouldn't store three copies of the same unqualified pointer type. One idea, if one still want to keep the names, is to use a union like it is done in CodeGenTypeCache.h. https://github.com/llvm/llvm-project/pull/75668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CodeGen] Emit a more accurate alignment for non-temporal loads/stores (PR #75675)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Akira Hatanaka (ahatanak) Changes Call EmitPointerWithAlignment to compute the alignment based on the underlying lvalue's alignment when it's available. --- Full diff: https://github.com/llvm/llvm-project/pull/75675.diff 2 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+4-4) - (modified) clang/test/CodeGen/Nontemporal.cpp (+14) ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 3327866d2b9623..c96f86a823a461 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -232,19 +232,19 @@ static Value *MakeBinaryAtomicValue( static Value *EmitNontemporalStore(CodeGenFunction &CGF, const CallExpr *E) { Value *Val = CGF.EmitScalarExpr(E->getArg(0)); - Value *Address = CGF.EmitScalarExpr(E->getArg(1)); + Address Addr = CGF.EmitPointerWithAlignment(E->getArg(1)); Val = CGF.EmitToMemory(Val, E->getArg(0)->getType()); - LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getArg(0)->getType()); + LValue LV = CGF.MakeAddrLValue(Addr, E->getArg(0)->getType()); LV.setNontemporal(true); CGF.EmitStoreOfScalar(Val, LV, false); return nullptr; } static Value *EmitNontemporalLoad(CodeGenFunction &CGF, const CallExpr *E) { - Value *Address = CGF.EmitScalarExpr(E->getArg(0)); + Address Addr = CGF.EmitPointerWithAlignment(E->getArg(0)); - LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getType()); + LValue LV = CGF.MakeAddrLValue(Addr, E->getType()); LV.setNontemporal(true); return CGF.EmitLoadOfScalar(LV, E->getExprLoc()); } diff --git a/clang/test/CodeGen/Nontemporal.cpp b/clang/test/CodeGen/Nontemporal.cpp index e14ca18717928d..5052cb225d4111 100644 --- a/clang/test/CodeGen/Nontemporal.cpp +++ b/clang/test/CodeGen/Nontemporal.cpp @@ -46,3 +46,17 @@ void test_all_sizes(void) // CHECK-LABEL: test_all_sizes vf2 = __builtin_nontemporal_load(&vf1); // CHECK: load <4 x float>{{.*}}align 16, !nontemporal vc2 = __builtin_nontemporal_load(&vc1); // CHECK: load <8 x i8>{{.*}}align 8, !nontemporal } + +struct S { char c[16]; }; +S x; + +typedef int v4si __attribute__ ((vector_size(16))); + +// CHECK-LABEL: define void @_Z14test_alignmentv() +// CHECK: load <4 x i32>, ptr @x, align 1, !nontemporal +// CHECK: store <4 x i32> %1, ptr @x, align 1, !nontemporal + +void test_alignment() { + auto t = __builtin_nontemporal_load((v4si*)x.c); + __builtin_nontemporal_store(t, (v4si*)x.c); +} `` https://github.com/llvm/llvm-project/pull/75675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CodeGen] Emit a more accurate alignment for non-temporal loads/stores (PR #75675)
https://github.com/ahatanak created https://github.com/llvm/llvm-project/pull/75675 Call EmitPointerWithAlignment to compute the alignment based on the underlying lvalue's alignment when it's available. >From 641aba730a38038da0d5a9ef8a56fab908131144 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Fri, 15 Dec 2023 15:52:39 -0800 Subject: [PATCH] [CodeGen] Emit a more accurate alignment for non-temporal loads/stores Call EmitPointerWithAlignment to compute the alignment based on the underlying lvalue's alignment when it's available. --- clang/lib/CodeGen/CGBuiltin.cpp| 8 clang/test/CodeGen/Nontemporal.cpp | 14 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 3327866d2b9623..c96f86a823a461 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -232,19 +232,19 @@ static Value *MakeBinaryAtomicValue( static Value *EmitNontemporalStore(CodeGenFunction &CGF, const CallExpr *E) { Value *Val = CGF.EmitScalarExpr(E->getArg(0)); - Value *Address = CGF.EmitScalarExpr(E->getArg(1)); + Address Addr = CGF.EmitPointerWithAlignment(E->getArg(1)); Val = CGF.EmitToMemory(Val, E->getArg(0)->getType()); - LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getArg(0)->getType()); + LValue LV = CGF.MakeAddrLValue(Addr, E->getArg(0)->getType()); LV.setNontemporal(true); CGF.EmitStoreOfScalar(Val, LV, false); return nullptr; } static Value *EmitNontemporalLoad(CodeGenFunction &CGF, const CallExpr *E) { - Value *Address = CGF.EmitScalarExpr(E->getArg(0)); + Address Addr = CGF.EmitPointerWithAlignment(E->getArg(0)); - LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getType()); + LValue LV = CGF.MakeAddrLValue(Addr, E->getType()); LV.setNontemporal(true); return CGF.EmitLoadOfScalar(LV, E->getExprLoc()); } diff --git a/clang/test/CodeGen/Nontemporal.cpp b/clang/test/CodeGen/Nontemporal.cpp index e14ca18717928d..5052cb225d4111 100644 --- a/clang/test/CodeGen/Nontemporal.cpp +++ b/clang/test/CodeGen/Nontemporal.cpp @@ -46,3 +46,17 @@ void test_all_sizes(void) // CHECK-LABEL: test_all_sizes vf2 = __builtin_nontemporal_load(&vf1); // CHECK: load <4 x float>{{.*}}align 16, !nontemporal vc2 = __builtin_nontemporal_load(&vc1); // CHECK: load <8 x i8>{{.*}}align 8, !nontemporal } + +struct S { char c[16]; }; +S x; + +typedef int v4si __attribute__ ((vector_size(16))); + +// CHECK-LABEL: define void @_Z14test_alignmentv() +// CHECK: load <4 x i32>, ptr @x, align 1, !nontemporal +// CHECK: store <4 x i32> %1, ptr @x, align 1, !nontemporal + +void test_alignment() { + auto t = __builtin_nontemporal_load((v4si*)x.c); + __builtin_nontemporal_store(t, (v4si*)x.c); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff b3e353d263f9d6ef061f4e6d89619c72a3553002 9d6e00bd972a563daefd67b544614e2bb609cc42 -- clang/lib/CodeGen/CGHLSLRuntime.cpp clang/lib/CodeGen/CGHLSLRuntime.h llvm/include/llvm/Frontend/HLSL/HLSLResource.h llvm/lib/Frontend/HLSL/HLSLResource.cpp llvm/lib/Target/DirectX/DXILResource.cpp llvm/lib/Target/DirectX/DXILResource.h `` View the diff from clang-format here. ``diff diff --git a/llvm/lib/Target/DirectX/DXILResource.cpp b/llvm/lib/Target/DirectX/DXILResource.cpp index b22f6d3ca4..621852f245 100644 --- a/llvm/lib/Target/DirectX/DXILResource.cpp +++ b/llvm/lib/Target/DirectX/DXILResource.cpp @@ -236,8 +236,8 @@ void UAVResource::print(raw_ostream &OS) const { OS << right_justify("UAV", 10); - printElementType( - Shape, ExtProps.ElementType.value_or(ElementType::Invalid), 8, OS); + printElementType(Shape, ExtProps.ElementType.value_or(ElementType::Invalid), + 8, OS); // FIXME: support SampleCount. // See https://github.com/llvm/llvm-project/issues/58175 `` https://github.com/llvm/llvm-project/pull/75674 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Justin Bogner (bogner) Changes Rather than shepherding a type name all the way to the backend as a string and attempting to parse it, get the element type out of the AST and store that in the resource annotation metadata directly. --- Patch is 26.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/75674.diff 11 Files Affected: - (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+54-9) - (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+1-1) - (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl (+7-7) - (added) clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl (+52) - (modified) clang/test/CodeGenHLSL/builtins/RasterizerOrderedBuffer-annotations.hlsl (+6-6) - (modified) clang/test/CodeGenHLSL/cbuf.hlsl (+2-2) - (modified) llvm/include/llvm/Frontend/HLSL/HLSLResource.h (+26-1) - (modified) llvm/lib/Frontend/HLSL/HLSLResource.cpp (+10-7) - (modified) llvm/lib/Target/DirectX/DXILResource.cpp (+28-64) - (modified) llvm/lib/Target/DirectX/DXILResource.h (+7-30) - (modified) llvm/test/CodeGen/DirectX/UAVMetadata.ll (+11-11) ``diff diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 3e8a40e7540bef..e887d35198b3c7 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -182,10 +182,8 @@ void CGHLSLRuntime::finishCodeGen() { llvm::hlsl::ResourceKind RK = Buf.IsCBuffer ? llvm::hlsl::ResourceKind::CBuffer : llvm::hlsl::ResourceKind::TBuffer; -std::string TyName = -Buf.Name.str() + (Buf.IsCBuffer ? ".cb." : ".tb.") + "ty"; -addBufferResourceAnnotation(GV, TyName, RC, RK, /*IsROV=*/false, -Buf.Binding); +addBufferResourceAnnotation(GV, RC, RK, /*IsROV=*/false, +llvm::hlsl::ElementType::Invalid, Buf.Binding); } } @@ -194,10 +192,10 @@ CGHLSLRuntime::Buffer::Buffer(const HLSLBufferDecl *D) Binding(D->getAttr()) {} void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV, -llvm::StringRef TyName, llvm::hlsl::ResourceClass RC, llvm::hlsl::ResourceKind RK, bool IsROV, +llvm::hlsl::ElementType ET, BufferResBinding &Binding) { llvm::Module &M = CGM.getModule(); @@ -216,15 +214,62 @@ void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV, assert(false && "Unsupported buffer type!"); return; } - assert(ResourceMD != nullptr && "ResourceMD must have been set by the switch above."); llvm::hlsl::FrontendResource Res( - GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space); + GV, RK, ET, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space); ResourceMD->addOperand(Res.getMetadata()); } +static llvm::hlsl::ElementType +calculateElementType(const ASTContext &Context, const clang::Type *ResourceTy) { + using llvm::hlsl::ElementType; + + // TODO: We may need to update this when we add things like ByteAddressBuffer + // that don't have a template parameter (or, indeed, an element type). + const auto *TST = ResourceTy->getAs(); + assert(TST && "Resource types must be template specializations"); + ArrayRef Args = TST->template_arguments(); + assert(!Args.empty() && "Resource has no element type"); + + // At this point we have a resource with an element type, so we can assume + // that it's valid or we would have diagnosed the error earlier. + QualType ElTy = Args[0].getAsType(); + + // We should either have a basic type or a vector of a basic type. + if (const auto *VecTy = ElTy->getAs()) +ElTy = VecTy->getElementType(); + + if (ElTy->isSignedIntegerType()) { +switch (Context.getTypeSize(ElTy)) { +case 16: + return ElementType::I16; +case 32: + return ElementType::I32; +case 64: + return ElementType::I64; +} + } else if (ElTy->isUnsignedIntegerType()) { +switch (Context.getTypeSize(ElTy)) { +case 16: + return ElementType::U16; +case 32: + return ElementType::U32; +case 64: + return ElementType::U64; +} + } else if (ElTy->isSpecificBuiltinType(BuiltinType::Half)) +return ElementType::F16; + else if (ElTy->isSpecificBuiltinType(BuiltinType::Float)) +return ElementType::F32; + else if (ElTy->isSpecificBuiltinType(BuiltinType::Double)) +return ElementType::F64; + + // TODO: We need to handle unorm/snorm float types here once we support them + llvm_unreachable("Invalid element type for resource"); +} + void CGHLSLRuntime::annotateHLSLResource(cons
[llvm] [clang] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)
https://github.com/bogner created https://github.com/llvm/llvm-project/pull/75674 Rather than shepherding a type name all the way to the backend as a string and attempting to parse it, get the element type out of the AST and store that in the resource annotation metadata directly. >From 9d6e00bd972a563daefd67b544614e2bb609cc42 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Fri, 15 Dec 2023 16:29:09 -0800 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.5-bogner --- clang/lib/CodeGen/CGHLSLRuntime.cpp | 63 +++-- clang/lib/CodeGen/CGHLSLRuntime.h | 2 +- .../builtins/RWBuffer-annotations.hlsl| 14 +-- .../builtins/RWBuffer-elementtype.hlsl| 52 +++ .../RasterizerOrderedBuffer-annotations.hlsl | 12 +-- clang/test/CodeGenHLSL/cbuf.hlsl | 4 +- .../include/llvm/Frontend/HLSL/HLSLResource.h | 27 +- llvm/lib/Frontend/HLSL/HLSLResource.cpp | 17 ++-- llvm/lib/Target/DirectX/DXILResource.cpp | 92 ++- llvm/lib/Target/DirectX/DXILResource.h| 37 ++-- llvm/test/CodeGen/DirectX/UAVMetadata.ll | 22 ++--- 11 files changed, 204 insertions(+), 138 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 3e8a40e7540bef..e887d35198b3c7 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -182,10 +182,8 @@ void CGHLSLRuntime::finishCodeGen() { llvm::hlsl::ResourceKind RK = Buf.IsCBuffer ? llvm::hlsl::ResourceKind::CBuffer : llvm::hlsl::ResourceKind::TBuffer; -std::string TyName = -Buf.Name.str() + (Buf.IsCBuffer ? ".cb." : ".tb.") + "ty"; -addBufferResourceAnnotation(GV, TyName, RC, RK, /*IsROV=*/false, -Buf.Binding); +addBufferResourceAnnotation(GV, RC, RK, /*IsROV=*/false, +llvm::hlsl::ElementType::Invalid, Buf.Binding); } } @@ -194,10 +192,10 @@ CGHLSLRuntime::Buffer::Buffer(const HLSLBufferDecl *D) Binding(D->getAttr()) {} void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV, -llvm::StringRef TyName, llvm::hlsl::ResourceClass RC, llvm::hlsl::ResourceKind RK, bool IsROV, +llvm::hlsl::ElementType ET, BufferResBinding &Binding) { llvm::Module &M = CGM.getModule(); @@ -216,15 +214,62 @@ void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV, assert(false && "Unsupported buffer type!"); return; } - assert(ResourceMD != nullptr && "ResourceMD must have been set by the switch above."); llvm::hlsl::FrontendResource Res( - GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space); + GV, RK, ET, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space); ResourceMD->addOperand(Res.getMetadata()); } +static llvm::hlsl::ElementType +calculateElementType(const ASTContext &Context, const clang::Type *ResourceTy) { + using llvm::hlsl::ElementType; + + // TODO: We may need to update this when we add things like ByteAddressBuffer + // that don't have a template parameter (or, indeed, an element type). + const auto *TST = ResourceTy->getAs(); + assert(TST && "Resource types must be template specializations"); + ArrayRef Args = TST->template_arguments(); + assert(!Args.empty() && "Resource has no element type"); + + // At this point we have a resource with an element type, so we can assume + // that it's valid or we would have diagnosed the error earlier. + QualType ElTy = Args[0].getAsType(); + + // We should either have a basic type or a vector of a basic type. + if (const auto *VecTy = ElTy->getAs()) +ElTy = VecTy->getElementType(); + + if (ElTy->isSignedIntegerType()) { +switch (Context.getTypeSize(ElTy)) { +case 16: + return ElementType::I16; +case 32: + return ElementType::I32; +case 64: + return ElementType::I64; +} + } else if (ElTy->isUnsignedIntegerType()) { +switch (Context.getTypeSize(ElTy)) { +case 16: + return ElementType::U16; +case 32: + return ElementType::U32; +case 64: + return ElementType::U64; +} + } else if (ElTy->isSpecificBuiltinType(BuiltinType::Half)) +return ElementType::F16; + else if (ElTy->isSpecificBuiltinType(BuiltinType::Float)) +return ElementType::F32; + else if (ElTy->isSpecificBuilti
[clang] [clang] Add size filter for stack auto init (PR #74777)
https://github.com/vitalybuka approved this pull request. LGTM, but please wait others feedback https://github.com/llvm/llvm-project/pull/74777 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [-Wunsafe-buffer-usage] Add a subgroup `-Wunsafe-buffer-usage-in-container` (PR #75665)
https://github.com/t-rasmud approved this pull request. https://github.com/llvm/llvm-project/pull/75665 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][CLANG] Rename duplicate loop attributes diagnostic functions (PR #75657)
smanna12 wrote: Thank you @erichkeane for reviews! https://github.com/llvm/llvm-project/pull/75657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
@@ -721,6 +721,33 @@ class UnsafeBufferUsageAttrGadget : public WarningGadget { DeclUseList getClaimedVarUseSites() const override { return {}; } }; +// Warning gadget for unsafe invocation of span::data method. +// Triggers when the pointer returned by the invocation is immediately +// cast to a larger type. + +class DataInvocationGadget : public WarningGadget { + constexpr static const char *const OpTag = "data_invocation_expr"; malavikasamak wrote: Thank you. Will fix this. https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
@@ -2261,6 +2261,21 @@ class UnsafeBufferUsageReporter : public UnsafeBufferUsageHandler { // note_unsafe_buffer_operation doesn't have this mode yet. assert(!IsRelatedToDecl && "Not implemented yet!"); MsgParam = 3; + } else if (const auto *ECE = dyn_cast(Operation)) { +QualType destType = ECE->getType(); +const uint64_t dSize = Ctx.getTypeSize(destType.getTypePtr()->getPointeeType()); +if(const auto *CE =dyn_cast(ECE->getSubExpr())) { + + if(CE->getRecordDecl()->getQualifiedNameAsString().compare("std::span")) malavikasamak wrote: Hmmm. I think it shouldn't be an issue as we are getting the qualified name. However, I will add a test case to check this. https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
https://github.com/malavikasamak edited https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
@@ -721,6 +721,33 @@ class UnsafeBufferUsageAttrGadget : public WarningGadget { DeclUseList getClaimedVarUseSites() const override { return {}; } }; +// Warning gadget for unsafe invocation of span::data method. +// Triggers when the pointer returned by the invocation is immediately +// cast to a larger type. + +class DataInvocationGadget : public WarningGadget { + constexpr static const char *const OpTag = "data_invocation_expr"; + const ExplicitCastExpr *Op; + + public: + DataInvocationGadget(const MatchFinder::MatchResult &Result) + : WarningGadget(Kind::DataInvocation), +Op(Result.Nodes.getNodeAs(OpTag)) {} + + static bool classof(const Gadget *G) { +return G->getKind() == Kind::DataInvocation; + } + + static Matcher matcher() { +return stmt( +explicitCastExpr(has(cxxMemberCallExpr(callee( + cxxMethodDecl(hasName("data")).bind(OpTag)); malavikasamak wrote: Yes. It matches all method invocations with name "data". However, we wouldn't be warning on all of them as the "handleUnsafeOperation" checks if the method belongs to std::span class. It maybe better to move it to the matcher as you point out, so there is less overlap between gadgets. https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add -fandroid-pad-segment/-fno-android-pad-segment (PR #75652)
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/75652 >From 964f9b98b389060e554e52e3c286255b4a25a7bb Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 15 Dec 2023 11:16:37 -0800 Subject: [PATCH] [Driver] Add -fandroid-pad-segment/-fno-android-pad-segment -fandroid-pad-segment is an Android-specific opt-in option that links in crt_pad_segment.o. crt_pad_segment.o contains a note section, which will be included in the linker-created PT_NOTE segment. This PT_NOTE tell Bionic that: when create a map for a PT_LOAD segment, extend the end to cover the gap so that we will have fewer kernel 'struct vm_area_struct' objects when page_size < MAXPAGESIZE. See also https://sourceware.org/bugzilla/show_bug.cgi?id=31076 --- clang/include/clang/Driver/Options.td | 5 + clang/lib/Driver/ToolChains/Gnu.cpp | 5 + .../sysroot/usr/lib/crt_pad_segment.o | 0 clang/test/Driver/linux-ld.c | 19 ++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 clang/test/Driver/Inputs/basic_android_tree/sysroot/usr/lib/crt_pad_segment.o diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 1b02087425b751..1d193dacc544b4 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6286,6 +6286,11 @@ def fno_sycl : Flag<["-"], "fno-sycl">, Visibility<[ClangOption, CLOption]>, Group, HelpText<"Disables SYCL kernels compilation for device">; +// OS-specific options +let Flags = [TargetSpecific] in { +defm android_pad_segment : BooleanFFlag<"android-pad-segment">, Group; +} // let Flags = [TargetSpecific] + //===--===// // FLangOption + NoXarchOption //===--===// diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 835215a83c4037..063f093fe432fd 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -507,6 +507,11 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, // Add crtfastmath.o if available and fast math is enabled. ToolChain.addFastMathRuntimeIfAvailable(Args, CmdArgs); + +if (isAndroid && Args.hasFlag(options::OPT_fandroid_pad_segment, + options::OPT_fno_android_pad_segment, false)) + CmdArgs.push_back( + Args.MakeArgString(ToolChain.GetFilePath("crt_pad_segment.o"))); } Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u}); diff --git a/clang/test/Driver/Inputs/basic_android_tree/sysroot/usr/lib/crt_pad_segment.o b/clang/test/Driver/Inputs/basic_android_tree/sysroot/usr/lib/crt_pad_segment.o new file mode 100644 index 00..e69de29bb2d1d6 diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c index 15643d6491ae52..49693b6a2d87e2 100644 --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -1338,7 +1338,24 @@ // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ // RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD-LINK %s // CHECK-ANDROID-PTHREAD-LINK-NOT: argument unused during compilation: '-pthread' -// + +/// Check -fandroid-pad-segment. +// RUN: %clang -### %s --target=aarch64-linux-android -rtlib=platform --unwindlib=platform \ +// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -fandroid-pad-segment 2>&1 | FileCheck --check-prefix=CHECK-ANDROID-PAD-PHDR %s +// CHECK-ANDROID-PAD-PHDR: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" +// CHECK-ANDROID-PAD-PHDR: "[[SYSROOT]]/usr/lib/crtbegin_dynamic.o" "[[SYSROOT]]/usr/lib/crt_pad_phdr.o" + +// RUN: %clang -### %s --target=aarch64-linux-android -rtlib=platform --unwindlib=platform \ +// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -fandroid-pad-segment -fno-android-pad-segment 2>&1 | FileCheck --check-prefix=CHECK-NO-ANDROID-PAD-PHDR %s +// CHECK-NO-ANDROID-PAD-PHDR: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" +// CHECK-NO-ANDROID-PAD-PHDR: "[[SYSROOT]]/usr/lib/crtbegin_dynamic.o" +// CHECK-NO-ANDROID-PAD-PHDR-NOT: crt_pad_phdr.o" + +// RUN: not %clang -### %s --target=aarch64-linux -fandroid-pad-segment 2>&1 | FileCheck --check-prefix=ERR-ANDROID-PAD-EHDR %s +// ERR-ANDROID-PAD-EHDR: error: unsupported option '-fandroid-pad-segment' for target 'aarch64-linux' + // Check linker invocation on a Debian LoongArch sysroot. // RUN: %clang -### %s -no-pie 2>&1 \ // RUN: --target=loongarch64-linux-gnu -rtlib=platform --unwindlib=platform \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Make sure ninja can clean "ClangdXPC.framework" (PR #75669)
llvmbot wrote: @llvm/pr-subscribers-clangd Author: Jan Svoboda (jansvoboda11) Changes After building the ClangdXPC target, `ninja clean` fails with the following error: ``` ninja: error: remove(lib/ClangdXPC.framework): Directory not empty ninja: error: remove(/lib/ClangdXPC.framework): Directory not empty ``` I did not find better way to make this work. I guess we could list all generated files (and directories) in `OUTPUT` of the custom command, but that seems fairly tedious/fragile. --- Full diff: https://github.com/llvm/llvm-project/pull/75669.diff 1 Files Affected: - (modified) clang-tools-extra/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake (+6) ``diff diff --git a/clang-tools-extra/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake b/clang-tools-extra/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake index 46738a204ace14..d5ba44962dd528 100644 --- a/clang-tools-extra/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake +++ b/clang-tools-extra/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake @@ -71,6 +71,12 @@ macro(create_clangd_xpc_framework target name) ${CLANGD_FRAMEWORK_LOCATION} ) + set_property( +TARGET ClangdXPC +APPEND +PROPERTY ADDITIONAL_CLEAN_FILES ${CLANGD_FRAMEWORK_LOCATION} + ) + # clangd is already signed as a standalone executable, so it must be forced. llvm_codesign(ClangdXPC BUNDLE_PATH "${CLANGD_FRAMEWORK_OUT_LOCATION}/XPCServices/${CLANGD_XPC_SERVICE_NAME}.xpc/" FORCE) # ClangdXPC library is already signed as a standalone library, so it must be forced. `` https://github.com/llvm/llvm-project/pull/75669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Make sure ninja can clean "ClangdXPC.framework" (PR #75669)
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/75669 After building the ClangdXPC target, `ninja clean` fails with the following error: ``` ninja: error: remove(lib/ClangdXPC.framework): Directory not empty ninja: error: remove(/lib/ClangdXPC.framework): Directory not empty ``` I did not find better way to make this work. I guess we could list all generated files (and directories) in `OUTPUT` of the custom command, but that seems fairly tedious/fragile. >From f1785d70c9fb9eb9d23f7aa365f3f6993ad7206c Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Fri, 15 Dec 2023 15:07:00 -0800 Subject: [PATCH] [clangd] Make sure ninja can clean "ClangdXPC.framework" After building the ClangdXPC target, `ninja clean` fails with the following error: ``` ninja: error: remove(lib/ClangdXPC.framework): Directory not empty ninja: error: remove(/lib/ClangdXPC.framework): Directory not empty ``` I did not find better way to make this work. I guess we could list all generated files (and directories) in `OUTPUT` of the custom command, but that seems fairly tedious/fragile. --- .../clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake | 6 ++ 1 file changed, 6 insertions(+) diff --git a/clang-tools-extra/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake b/clang-tools-extra/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake index 46738a204ace14..d5ba44962dd528 100644 --- a/clang-tools-extra/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake +++ b/clang-tools-extra/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake @@ -71,6 +71,12 @@ macro(create_clangd_xpc_framework target name) ${CLANGD_FRAMEWORK_LOCATION} ) + set_property( +TARGET ClangdXPC +APPEND +PROPERTY ADDITIONAL_CLEAN_FILES ${CLANGD_FRAMEWORK_LOCATION} + ) + # clangd is already signed as a standalone executable, so it must be forced. llvm_codesign(ClangdXPC BUNDLE_PATH "${CLANGD_FRAMEWORK_OUT_LOCATION}/XPCServices/${CLANGD_XPC_SERVICE_NAME}.xpc/" FORCE) # ClangdXPC library is already signed as a standalone library, so it must be forced. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add size filter for stack auto init (PR #74777)
vitalybuka wrote: As we discussed offline, it would nice to handle cases like this ``` struct Foo { int x; // we should try to make sure X is initialized. char buff[1024]; // this one is fine to skip }; void main() { Foo foo; } ``` But seems moving size check deeper does not help. If so, simpler patch is preferred. https://github.com/llvm/llvm-project/pull/74777 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CGCUDANV] Unify PointerType members of CGNVCUDARuntime (NFC) (PR #75668)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Youngsuk Kim (JOE1994) Changes Unify 3 `Pointertype *` members which all refer to the same llvm type. Opaque pointer clean-up effort. --- Full diff: https://github.com/llvm/llvm-project/pull/75668.diff 1 Files Affected: - (modified) clang/lib/CodeGen/CGCUDANV.cpp (+38-50) ``diff diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp index 520b0c4f117673..353370f1d761b9 100644 --- a/clang/lib/CodeGen/CGCUDANV.cpp +++ b/clang/lib/CodeGen/CGCUDANV.cpp @@ -39,7 +39,7 @@ class CGNVCUDARuntime : public CGCUDARuntime { private: llvm::IntegerType *IntTy, *SizeTy; llvm::Type *VoidTy; - llvm::PointerType *CharPtrTy, *VoidPtrTy, *VoidPtrPtrTy; + llvm::PointerType *PtrTy; /// Convenience reference to LLVM Context llvm::LLVMContext &Context; @@ -232,15 +232,12 @@ CGNVCUDARuntime::CGNVCUDARuntime(CodeGenModule &CGM) VoidTy = CGM.VoidTy; Zeros[0] = llvm::ConstantInt::get(SizeTy, 0); Zeros[1] = Zeros[0]; - - CharPtrTy = CGM.UnqualPtrTy; - VoidPtrTy = CGM.UnqualPtrTy; - VoidPtrPtrTy = CGM.UnqualPtrTy; + PtrTy = CGM.UnqualPtrTy; } llvm::FunctionCallee CGNVCUDARuntime::getSetupArgumentFn() const { // cudaError_t cudaSetupArgument(void *, size_t, size_t) - llvm::Type *Params[] = {VoidPtrTy, SizeTy, SizeTy}; + llvm::Type *Params[] = {PtrTy, SizeTy, SizeTy}; return CGM.CreateRuntimeFunction( llvm::FunctionType::get(IntTy, Params, false), addPrefixToName("SetupArgument")); @@ -250,24 +247,24 @@ llvm::FunctionCallee CGNVCUDARuntime::getLaunchFn() const { if (CGM.getLangOpts().HIP) { // hipError_t hipLaunchByPtr(char *); return CGM.CreateRuntimeFunction( -llvm::FunctionType::get(IntTy, CharPtrTy, false), "hipLaunchByPtr"); +llvm::FunctionType::get(IntTy, PtrTy, false), "hipLaunchByPtr"); } // cudaError_t cudaLaunch(char *); - return CGM.CreateRuntimeFunction( - llvm::FunctionType::get(IntTy, CharPtrTy, false), "cudaLaunch"); + return CGM.CreateRuntimeFunction(llvm::FunctionType::get(IntTy, PtrTy, false), + "cudaLaunch"); } llvm::FunctionType *CGNVCUDARuntime::getRegisterGlobalsFnTy() const { - return llvm::FunctionType::get(VoidTy, VoidPtrPtrTy, false); + return llvm::FunctionType::get(VoidTy, PtrTy, false); } llvm::FunctionType *CGNVCUDARuntime::getCallbackFnTy() const { - return llvm::FunctionType::get(VoidTy, VoidPtrTy, false); + return llvm::FunctionType::get(VoidTy, PtrTy, false); } llvm::FunctionType *CGNVCUDARuntime::getRegisterLinkedBinaryFnTy() const { - llvm::Type *Params[] = {llvm::PointerType::getUnqual(Context), VoidPtrTy, - VoidPtrTy, llvm::PointerType::getUnqual(Context)}; + llvm::Type *Params[] = {llvm::PointerType::getUnqual(Context), PtrTy, PtrTy, + llvm::PointerType::getUnqual(Context)}; return llvm::FunctionType::get(VoidTy, Params, false); } @@ -330,15 +327,15 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF, // args, allocate a single pointer so we still have a valid pointer to the // argument array that we can pass to runtime, even if it will be unused. Address KernelArgs = CGF.CreateTempAlloca( - VoidPtrTy, CharUnits::fromQuantity(16), "kernel_args", + PtrTy, CharUnits::fromQuantity(16), "kernel_args", llvm::ConstantInt::get(SizeTy, std::max(1, Args.size(; // Store pointers to the arguments in a locally allocated launch_args. for (unsigned i = 0; i < Args.size(); ++i) { llvm::Value* VarPtr = CGF.GetAddrOfLocalVar(Args[i]).getPointer(); -llvm::Value *VoidVarPtr = CGF.Builder.CreatePointerCast(VarPtr, VoidPtrTy); +llvm::Value *VoidVarPtr = CGF.Builder.CreatePointerCast(VarPtr, PtrTy); CGF.Builder.CreateDefaultAlignedStore( VoidVarPtr, -CGF.Builder.CreateConstGEP1_32(VoidPtrTy, KernelArgs.getPointer(), i)); +CGF.Builder.CreateConstGEP1_32(PtrTy, KernelArgs.getPointer(), i)); } llvm::BasicBlock *EndBlock = CGF.createBasicBlock("setup.end"); @@ -386,8 +383,7 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF, CGF.CreateMemTemp(Dim3Ty, CharUnits::fromQuantity(8), "block_dim"); Address ShmemSize = CGF.CreateTempAlloca(SizeTy, CGM.getSizeAlign(), "shmem_size"); - Address Stream = - CGF.CreateTempAlloca(VoidPtrTy, CGM.getPointerAlign(), "stream"); + Address Stream = CGF.CreateTempAlloca(PtrTy, CGM.getPointerAlign(), "stream"); llvm::FunctionCallee cudaPopConfigFn = CGM.CreateRuntimeFunction( llvm::FunctionType::get(IntTy, {/*gridDim=*/GridDim.getType(), @@ -402,8 +398,8 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF, ShmemSize.getPointer(), Stream.getPointer()}); // Emit the call to cudaLaunch - llvm::Value *Kernel = CGF.Builder.CreatePointerCast( - KernelHandles[CG
[clang] [clang][CGCUDANV] Unify PointerType members of CGNVCUDARuntime (NFC) (PR #75668)
https://github.com/JOE1994 created https://github.com/llvm/llvm-project/pull/75668 Unify 3 `Pointertype *` members which all refer to the same llvm type. Opaque pointer clean-up effort. >From 2f07997d202a8e845e866d0dedbfbcded0bf9518 Mon Sep 17 00:00:00 2001 From: Youngsuk Kim Date: Fri, 15 Dec 2023 16:50:02 -0600 Subject: [PATCH] [clang][CGCUDANV] Unify PointerType members of CGNVCUDARuntime (NFC) Unify 3 `Pointertype *` members which all refer to the same llvm type. Opaque pointer clean-up effort. --- clang/lib/CodeGen/CGCUDANV.cpp | 88 +++--- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp index 520b0c4f117673..353370f1d761b9 100644 --- a/clang/lib/CodeGen/CGCUDANV.cpp +++ b/clang/lib/CodeGen/CGCUDANV.cpp @@ -39,7 +39,7 @@ class CGNVCUDARuntime : public CGCUDARuntime { private: llvm::IntegerType *IntTy, *SizeTy; llvm::Type *VoidTy; - llvm::PointerType *CharPtrTy, *VoidPtrTy, *VoidPtrPtrTy; + llvm::PointerType *PtrTy; /// Convenience reference to LLVM Context llvm::LLVMContext &Context; @@ -232,15 +232,12 @@ CGNVCUDARuntime::CGNVCUDARuntime(CodeGenModule &CGM) VoidTy = CGM.VoidTy; Zeros[0] = llvm::ConstantInt::get(SizeTy, 0); Zeros[1] = Zeros[0]; - - CharPtrTy = CGM.UnqualPtrTy; - VoidPtrTy = CGM.UnqualPtrTy; - VoidPtrPtrTy = CGM.UnqualPtrTy; + PtrTy = CGM.UnqualPtrTy; } llvm::FunctionCallee CGNVCUDARuntime::getSetupArgumentFn() const { // cudaError_t cudaSetupArgument(void *, size_t, size_t) - llvm::Type *Params[] = {VoidPtrTy, SizeTy, SizeTy}; + llvm::Type *Params[] = {PtrTy, SizeTy, SizeTy}; return CGM.CreateRuntimeFunction( llvm::FunctionType::get(IntTy, Params, false), addPrefixToName("SetupArgument")); @@ -250,24 +247,24 @@ llvm::FunctionCallee CGNVCUDARuntime::getLaunchFn() const { if (CGM.getLangOpts().HIP) { // hipError_t hipLaunchByPtr(char *); return CGM.CreateRuntimeFunction( -llvm::FunctionType::get(IntTy, CharPtrTy, false), "hipLaunchByPtr"); +llvm::FunctionType::get(IntTy, PtrTy, false), "hipLaunchByPtr"); } // cudaError_t cudaLaunch(char *); - return CGM.CreateRuntimeFunction( - llvm::FunctionType::get(IntTy, CharPtrTy, false), "cudaLaunch"); + return CGM.CreateRuntimeFunction(llvm::FunctionType::get(IntTy, PtrTy, false), + "cudaLaunch"); } llvm::FunctionType *CGNVCUDARuntime::getRegisterGlobalsFnTy() const { - return llvm::FunctionType::get(VoidTy, VoidPtrPtrTy, false); + return llvm::FunctionType::get(VoidTy, PtrTy, false); } llvm::FunctionType *CGNVCUDARuntime::getCallbackFnTy() const { - return llvm::FunctionType::get(VoidTy, VoidPtrTy, false); + return llvm::FunctionType::get(VoidTy, PtrTy, false); } llvm::FunctionType *CGNVCUDARuntime::getRegisterLinkedBinaryFnTy() const { - llvm::Type *Params[] = {llvm::PointerType::getUnqual(Context), VoidPtrTy, - VoidPtrTy, llvm::PointerType::getUnqual(Context)}; + llvm::Type *Params[] = {llvm::PointerType::getUnqual(Context), PtrTy, PtrTy, + llvm::PointerType::getUnqual(Context)}; return llvm::FunctionType::get(VoidTy, Params, false); } @@ -330,15 +327,15 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF, // args, allocate a single pointer so we still have a valid pointer to the // argument array that we can pass to runtime, even if it will be unused. Address KernelArgs = CGF.CreateTempAlloca( - VoidPtrTy, CharUnits::fromQuantity(16), "kernel_args", + PtrTy, CharUnits::fromQuantity(16), "kernel_args", llvm::ConstantInt::get(SizeTy, std::max(1, Args.size(; // Store pointers to the arguments in a locally allocated launch_args. for (unsigned i = 0; i < Args.size(); ++i) { llvm::Value* VarPtr = CGF.GetAddrOfLocalVar(Args[i]).getPointer(); -llvm::Value *VoidVarPtr = CGF.Builder.CreatePointerCast(VarPtr, VoidPtrTy); +llvm::Value *VoidVarPtr = CGF.Builder.CreatePointerCast(VarPtr, PtrTy); CGF.Builder.CreateDefaultAlignedStore( VoidVarPtr, -CGF.Builder.CreateConstGEP1_32(VoidPtrTy, KernelArgs.getPointer(), i)); +CGF.Builder.CreateConstGEP1_32(PtrTy, KernelArgs.getPointer(), i)); } llvm::BasicBlock *EndBlock = CGF.createBasicBlock("setup.end"); @@ -386,8 +383,7 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF, CGF.CreateMemTemp(Dim3Ty, CharUnits::fromQuantity(8), "block_dim"); Address ShmemSize = CGF.CreateTempAlloca(SizeTy, CGM.getSizeAlign(), "shmem_size"); - Address Stream = - CGF.CreateTempAlloca(VoidPtrTy, CGM.getPointerAlign(), "stream"); + Address Stream = CGF.CreateTempAlloca(PtrTy, CGM.getPointerAlign(), "stream"); llvm::FunctionCallee cudaPopConfigFn = CGM.CreateRuntimeFunction( llvm::FunctionType::get(IntTy, {/*gridDim=*/GridDim.getTyp
[clang] eccc1cc - Revert "[NFC] [Serialization] Packing more bits and refactor AbbrevToUse"
Author: Augusto Noronha Date: 2023-12-15T14:43:25-08:00 New Revision: eccc1cca71bb704e4dcaabccc993d08fd15b46a2 URL: https://github.com/llvm/llvm-project/commit/eccc1cca71bb704e4dcaabccc993d08fd15b46a2 DIFF: https://github.com/llvm/llvm-project/commit/eccc1cca71bb704e4dcaabccc993d08fd15b46a2.diff LOG: Revert "[NFC] [Serialization] Packing more bits and refactor AbbrevToUse" This reverts commit 9cdb825a4f1bf9e75829d03879620c6144d0b7bc. Added: Modified: clang/include/clang/Serialization/ASTReader.h clang/include/clang/Serialization/ASTWriter.h clang/lib/Serialization/ASTReaderDecl.cpp clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/ASTWriterDecl.cpp clang/lib/Serialization/ASTWriterStmt.cpp Removed: diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index a6dd779386dc16..9bb89ec9410911 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -2422,8 +2422,6 @@ class BitsUnpacker { CurrentBitsIndex = 0; } - void advance(uint32_t BitsWidth) { CurrentBitsIndex += BitsWidth; } - bool getNextBit() { assert(isValid()); return Value & (1 << CurrentBitsIndex++); diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 16ab9583f8ed8e..a56929ef0245ee 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -564,25 +564,11 @@ class ASTWriter : public ASTDeserializationListener, unsigned DeclEnumAbbrev = 0; unsigned DeclObjCIvarAbbrev = 0; unsigned DeclCXXMethodAbbrev = 0; - unsigned DeclDependentNonTemplateCXXMethodAbbrev = 0; - unsigned DeclTemplateCXXMethodAbbrev = 0; - unsigned DeclMemberSpecializedCXXMethodAbbrev = 0; - unsigned DeclTemplateSpecializedCXXMethodAbbrev = 0; - unsigned DeclDependentSpecializationCXXMethodAbbrev = 0; - unsigned DeclTemplateTypeParmAbbrev = 0; - unsigned DeclUsingShadowAbbrev = 0; unsigned DeclRefExprAbbrev = 0; unsigned CharacterLiteralAbbrev = 0; unsigned IntegerLiteralAbbrev = 0; unsigned ExprImplicitCastAbbrev = 0; - unsigned BinaryOperatorAbbrev = 0; - unsigned CompoundAssignOperatorAbbrev = 0; - unsigned CallExprAbbrev = 0; - unsigned CXXOperatorCallExprAbbrev = 0; - unsigned CXXMemberCallExprAbbrev = 0; - - unsigned CompoundStmtAbbrev = 0; void WriteDeclAbbrevs(); void WriteDecl(ASTContext &Context, Decl *D); @@ -749,42 +735,12 @@ class ASTWriter : public ASTDeserializationListener, unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; } unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; } unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; } - unsigned getDeclCXXMethodAbbrev(FunctionDecl::TemplatedKind Kind) const { -switch (Kind) { -case FunctionDecl::TK_NonTemplate: - return DeclCXXMethodAbbrev; -case FunctionDecl::TK_FunctionTemplate: - return DeclTemplateCXXMethodAbbrev; -case FunctionDecl::TK_MemberSpecialization: - return DeclMemberSpecializedCXXMethodAbbrev; -case FunctionDecl::TK_FunctionTemplateSpecialization: - return DeclTemplateSpecializedCXXMethodAbbrev; -case FunctionDecl::TK_DependentNonTemplate: - return DeclDependentNonTemplateCXXMethodAbbrev; -case FunctionDecl::TK_DependentFunctionTemplateSpecialization: - return DeclDependentSpecializationCXXMethodAbbrev; -default: - llvm_unreachable("Unknwon Template Kind!"); -} - } - unsigned getDeclTemplateTypeParmAbbrev() const { -return DeclTemplateTypeParmAbbrev; - } - unsigned getDeclUsingShadowAbbrev() const { return DeclUsingShadowAbbrev; } + unsigned getDeclCXXMethodAbbrev() const { return DeclCXXMethodAbbrev; } unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; } unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; } unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; } unsigned getExprImplicitCastAbbrev() const { return ExprImplicitCastAbbrev; } - unsigned getBinaryOperatorAbbrev() const { return BinaryOperatorAbbrev; } - unsigned getCompoundAssignOperatorAbbrev() const { -return CompoundAssignOperatorAbbrev; - } - unsigned getCallExprAbbrev() const { return CallExprAbbrev; } - unsigned getCXXOperatorCallExprAbbrev() { return CXXOperatorCallExprAbbrev; } - unsigned getCXXMemberCallExprAbbrev() { return CXXMemberCallExprAbbrev; } - - unsigned getCompoundStmtAbbrev() const { return CompoundStmtAbbrev; } bool hasChain() const { return Chain; } ASTReader *getChain() const { return Chain; } @@ -885,33 +841,46 @@ class BitsPacker { BitsPacker(BitsPacker &&) = delete; BitsPacker operator=(const BitsPacker &) = delete; BitsPa
[clang] 87bd71e - Revert "[NFC] Fix the warning Wcovered-switch-default"
Author: Augusto Noronha Date: 2023-12-15T14:43:25-08:00 New Revision: 87bd71efd0af21b6663a7729317952535446f36d URL: https://github.com/llvm/llvm-project/commit/87bd71efd0af21b6663a7729317952535446f36d DIFF: https://github.com/llvm/llvm-project/commit/87bd71efd0af21b6663a7729317952535446f36d.diff LOG: Revert "[NFC] Fix the warning Wcovered-switch-default" This reverts commit e55bda06dc2bb1ef11ff4fcc43f90d8bf843f967. Added: Modified: clang/include/clang/Serialization/ASTWriter.h Removed: diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index de69f99003d827..16ab9583f8ed8e 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -763,8 +763,9 @@ class ASTWriter : public ASTDeserializationListener, return DeclDependentNonTemplateCXXMethodAbbrev; case FunctionDecl::TK_DependentFunctionTemplateSpecialization: return DeclDependentSpecializationCXXMethodAbbrev; +default: + llvm_unreachable("Unknwon Template Kind!"); } -llvm_unreachable("Unknwon Template Kind!"); } unsigned getDeclTemplateTypeParmAbbrev() const { return DeclTemplateTypeParmAbbrev; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
@@ -2261,6 +2261,21 @@ class UnsafeBufferUsageReporter : public UnsafeBufferUsageHandler { // note_unsafe_buffer_operation doesn't have this mode yet. assert(!IsRelatedToDecl && "Not implemented yet!"); MsgParam = 3; + } else if (const auto *ECE = dyn_cast(Operation)) { +QualType destType = ECE->getType(); +const uint64_t dSize = Ctx.getTypeSize(destType.getTypePtr()->getPointeeType()); +if(const auto *CE =dyn_cast(ECE->getSubExpr())) { + + if(CE->getRecordDecl()->getQualifiedNameAsString().compare("std::span")) ziqingluo-90 wrote: I'm a tiny bit skeptical that if the qualified name is always `std::span`. Maybe we can have a test like this: ``` using namespace std; void f(span buf) { BigTy *p = (BigTy *) buf.data(); } ``` https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
@@ -721,6 +721,33 @@ class UnsafeBufferUsageAttrGadget : public WarningGadget { DeclUseList getClaimedVarUseSites() const override { return {}; } }; +// Warning gadget for unsafe invocation of span::data method. +// Triggers when the pointer returned by the invocation is immediately +// cast to a larger type. + +class DataInvocationGadget : public WarningGadget { + constexpr static const char *const OpTag = "data_invocation_expr"; ziqingluo-90 wrote: a nitpick: I noticed most tag strings use camel cases. We better be consistent on this? https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][CLANG] Rename duplicate loop attributes diagnostic functions (PR #75657)
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/75657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [-Wunsafe-buffer-usage] Add a subgroup `-Wunsafe-buffer-usage-in-container` (PR #75665)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Ziqing Luo (ziqingluo-90) Changes Add a sub diagnostic group under `-Wunsafe-buffer-usage` controlled by `-Wunsafe-buffer-usage-in-container`. The subgroup will include warnings on misuses of `std::span`, `std::vector`, and `std::array`. --- Full diff: https://github.com/llvm/llvm-project/pull/75665.diff 1 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticGroups.td (+2-1) ``diff diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 80b5680b94f6ca..7cf347e92d9972 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1488,4 +1488,5 @@ def DXILValidation : DiagGroup<"dxil-validation">; def ReadOnlyPlacementChecks : DiagGroup<"read-only-types">; // Warnings and fixes to support the "safe buffers" programming model. -def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage">; +def UnsafeBufferUsageInContainer : DiagGroup<"unsafe-buffer-usage-in-container">; +def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", [UnsafeBufferUsageInContainer]>; `` https://github.com/llvm/llvm-project/pull/75665 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [-Wunsafe-buffer-usage] Add a subgroup `-Wunsafe-buffer-usage-in-container` (PR #75665)
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/75665 Add a sub diagnostic group under `-Wunsafe-buffer-usage` controlled by `-Wunsafe-buffer-usage-in-container`. The subgroup will include warnings on misuses of `std::span`, `std::vector`, and `std::array`. >From 9501ffef8db9bf52879a815ad99033f17635796b Mon Sep 17 00:00:00 2001 From: ziqingluo-90 Date: Fri, 15 Dec 2023 14:04:57 -0800 Subject: [PATCH] [-Wunsafe-buffer-usage] Add a subgroup `-Wunsafe-buffer-usage-in-container` Add a sub diagnostic group under `-Wunsafe-buffer-usage` controlled by `-Wunsafe-buffer-usage-in-container`. The subgroup will include warnings on misuses of `std::span`, `std::vector`, and `std::array`. --- clang/include/clang/Basic/DiagnosticGroups.td | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 80b5680b94f6ca..7cf347e92d9972 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1488,4 +1488,5 @@ def DXILValidation : DiagGroup<"dxil-validation">; def ReadOnlyPlacementChecks : DiagGroup<"read-only-types">; // Warnings and fixes to support the "safe buffers" programming model. -def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage">; +def UnsafeBufferUsageInContainer : DiagGroup<"unsafe-buffer-usage-in-container">; +def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", [UnsafeBufferUsageInContainer]>; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] [clang] [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) (PR #75226)
https://github.com/lei137 closed https://github.com/llvm/llvm-project/pull/75226 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] aaa3f72 - [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) (#75226)
Author: Lei Huang Date: 2023-12-15T17:23:16-05:00 New Revision: aaa3f72c1ce6e1757df79c0d02e0675201ee07a3 URL: https://github.com/llvm/llvm-project/commit/aaa3f72c1ce6e1757df79c0d02e0675201ee07a3 DIFF: https://github.com/llvm/llvm-project/commit/aaa3f72c1ce6e1757df79c0d02e0675201ee07a3.diff LOG: [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) (#75226) On Linux PPC call lib func ``frexpl`` for calls to ``frexp()`` for input of type PPCDoubleDouble. Fixes bug: https://github.com/llvm/llvm-project/issues/64426 Added: Modified: clang/lib/CodeGen/CGBuiltin.cpp clang/test/CodeGen/math-builtins-long.c libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp Removed: diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 353b7930b3c1ea..3327866d2b9623 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -3410,9 +3410,16 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, { Src0->getType(), Src1->getType() }); return RValue::get(Builder.CreateCall(F, { Src0, Src1 })); } + case Builtin::BI__builtin_frexpl: { +// Linux PPC will not be adding additional PPCDoubleDouble support. +// WIP to switch default to IEEE long double. Will emit libcall for +// frexpl instead of legalizing this type in the BE. +if (&getTarget().getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble()) + break; +LLVM_FALLTHROUGH; + } case Builtin::BI__builtin_frexp: case Builtin::BI__builtin_frexpf: - case Builtin::BI__builtin_frexpl: case Builtin::BI__builtin_frexpf128: case Builtin::BI__builtin_frexpf16: return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp)); diff --git a/clang/test/CodeGen/math-builtins-long.c b/clang/test/CodeGen/math-builtins-long.c index f3c328dcbfcd7c..ad0d2122b597fa 100644 --- a/clang/test/CodeGen/math-builtins-long.c +++ b/clang/test/CodeGen/math-builtins-long.c @@ -35,7 +35,7 @@ void foo(long double f, long double *l, int *i, const char *c) { __builtin_fabsl(f); // F80: call { x86_fp80, i32 } @llvm.frexp.f80.i32(x86_fp80 %{{.+}}) - // PPC: call { ppc_fp128, i32 } @llvm.frexp.ppcf128.i32(ppc_fp128 %{{.+}}) + // PPC: call ppc_fp128 @frexpl(ppc_fp128 noundef %{{.+}}, ptr noundef %{{.+}}) // X86F128: call { fp128, i32 } @llvm.frexp.f128.i32(fp128 %{{.+}}) // PPCF128: call { fp128, i32 } @llvm.frexp.f128.i32(fp128 %{{.+}}) __builtin_frexpl(f,i); diff --git a/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp b/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp index 31511064ce7ca5..a07260a34516f1 100644 --- a/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp +++ b/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp @@ -58,15 +58,9 @@ int main(int, char**) { ASSERT_NOT_CONSTEXPR_CXX23(std::frexp(0.0f, &DummyInt) == 0.0f); ASSERT_NOT_CONSTEXPR_CXX23(std::frexp(0.0, &DummyInt) == 0.0); -//FIXME: currently linux powerpc does not support this expansion -// since 0.0L lowers to ppcf128 and special handling is required. -#if !defined(__LONG_DOUBLE_IBM128__) ASSERT_NOT_CONSTEXPR_CXX23(std::frexp(0.0L, &DummyInt) == 0.0L); -#endif ASSERT_NOT_CONSTEXPR_CXX23(std::frexpf(0.0f, &DummyInt) == 0.0f); -#if !defined(__LONG_DOUBLE_IBM128__) ASSERT_NOT_CONSTEXPR_CXX23(std::frexpl(0.0L, &DummyInt) == 0.0L); -#endif ASSERT_NOT_CONSTEXPR_CXX23(std::ilogb(1.0f) == 0); ASSERT_NOT_CONSTEXPR_CXX23(std::ilogb(1.0) == 0); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)
@@ -0,0 +1,113 @@ +//===--- RedundantInlineSpecifierCheck.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 "RedundantInlineSpecifierCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclTemplate.h" +#include "clang/AST/ExprCXX.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Lex/Token.h" + +#include "../utils/LexerUtils.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +AST_POLYMORPHIC_MATCHER(isInlineSpecified, +AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, +VarDecl)) { + if (const auto *FD = dyn_cast(&Node)) +return FD->isInlineSpecified(); + if (const auto *VD = dyn_cast(&Node)) +return VD->isInlineSpecified(); + llvm_unreachable("Not a valid polymorphic type"); +} + +static std::optional +getInlineTokenLocation(SourceRange RangeLocation, const SourceManager &Sources, + const LangOptions &LangOpts) { + SourceLocation Loc = RangeLocation.getBegin(); + if (Loc.isMacroID()) +return std::nullopt; + + Token FirstToken; + Lexer::getRawToken(Loc, FirstToken, Sources, LangOpts, true); + std::optional CurrentToken = FirstToken; + while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() && + CurrentToken->isNot(tok::eof)) { +if (CurrentToken->is(tok::raw_identifier) && +CurrentToken->getRawIdentifier() == "inline") + return CurrentToken->getLocation(); + +CurrentToken = +Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts); + } + return std::nullopt; +} + +void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher( + functionDecl(isInlineSpecified(), + anyOf(isConstexpr(), isDeleted(), isDefaulted(), + isInAnonymousNamespace(), felix642 wrote: Adding a parameter to differentiate "implicit" from "redundant" inline declarations seems like a good idea. Some users might be using it to hint the optimizer and might want to keep it if it's not implicit. I will add the parameter "StrictMode" suggested by @PiotrZSL which will be an extra condition to flag the following cases if they are not constexpr: - templates - functions declared in an anonymous namespace - functions marked as static https://github.com/llvm/llvm-project/pull/73069 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [libcxx] [flang] [compiler-rt] [libc] [llvm] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { bwendling wrote: It started with a couple of bugs reported by someone testing the feature on Linux. I created a fix, but it wasn't super great and relied upon some assumptions about how the FAM expressions were formatted. Plus it could reload the expressions, which isn't good, especially if they have side effects. @nickdesaulniers had the good idea to generate the GEPs in a similar way to this. (That's where this code comes from.) Then several different cases were mentioned that needed to be handled at least gracefully...and the yak kept growing hair. I don't necessarily think that this is adding "new" features more than just taking care of case after case after case ..., which is legion in C. For instance, the code was meant to handle FAMs in substructures, but because it's potentially very messy, maybe I should remove that feature. That would hopefully simplify this patch. I'll update this patch removing the substructure FAM support and using your "offset" idea to get the count. Thanks for your feedback! https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [compiler-rt] [clang-tools-extra] [clang] [flang] [libc] [libcxx] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { rjmccall wrote: Well, like I said, I don't think there's a reason to use *different* rules for flexible array members one way or the other. But that's what this patch seems to be doing. How did you end up going down the rabbit hole of writing all the new code for FAMs here? If you were writing comprehensive tests for FAMs and finding that the substructure cases didn't work, I could believe that the real problem is that the common infrastructure doesn't really support that yet. If that's the case, then yeah, I think the right path forward is to just worry about the cases that the common infrastructure supports, and we should make a point of going back to the design stage and trying to decide whether the current generality makes any sense. A feature we can't actually implement doesn't do anyone any good. https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libc] [libcxx] [llvm] [flang] [clang-tools-extra] [compiler-rt] [clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { bwendling wrote: Forcing the `count` to be in the top-level struct was more-or-less a compromise in how the `__counted_by` field is specified. It might be too restrictive, or not restrictive enough (depending on your point of view). I personally would prefer a different way of specifying where the `count` is, ですけど (My idea is to use a form of the "designated initializer" syntax (maybe with a way to specify a "relative path?" ... dunno).) If supporting a FAM in a substructure is too hairy, I can remove that support until we work out the kinks. (I think GCC doesn't yet have support for this.) https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
https://github.com/t-rasmud requested changes to this pull request. https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
https://github.com/t-rasmud edited https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
@@ -721,6 +721,33 @@ class UnsafeBufferUsageAttrGadget : public WarningGadget { DeclUseList getClaimedVarUseSites() const override { return {}; } }; +// Warning gadget for unsafe invocation of span::data method. +// Triggers when the pointer returned by the invocation is immediately +// cast to a larger type. + +class DataInvocationGadget : public WarningGadget { + constexpr static const char *const OpTag = "data_invocation_expr"; + const ExplicitCastExpr *Op; + + public: + DataInvocationGadget(const MatchFinder::MatchResult &Result) + : WarningGadget(Kind::DataInvocation), +Op(Result.Nodes.getNodeAs(OpTag)) {} + + static bool classof(const Gadget *G) { +return G->getKind() == Kind::DataInvocation; + } + + static Matcher matcher() { +return stmt( +explicitCastExpr(has(cxxMemberCallExpr(callee( + cxxMethodDecl(hasName("data")).bind(OpTag)); t-rasmud wrote: Will this also match on user defined functions called "data"? I think something like `cxxMethodDecl(ofClass(hasName("span")))` might be needed to match `span.data()` alone (but I might be wrong). In any case, maybe have a test case with a user defined function called "data" which'll show the matcher matches only on `span.data()`. https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [lldb] [libcxxabi] [lld] [flang] [libunwind] [compiler-rt] [clang] [llvm] [libc] [libcxx] [mlir] [asan] Install `pthread_atfork` (PR #75290)
vitalybuka wrote: That's bad, we need to fix this. Do you see how we endup in handler, from `internal_fork`. `internal_fork` claims it will not call handlers. https://github.com/llvm/llvm-project/pull/75290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [llvm] [LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (PR #75217)
https://github.com/nikic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/75217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][CLANG] Rename duplicate loop attributes diagnostic functions (PR #75657)
https://github.com/smanna12 updated https://github.com/llvm/llvm-project/pull/75657 >From f3cfe4cbc1053162b825cc144a5f5c0f73a40b77 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Fri, 15 Dec 2023 13:15:50 -0800 Subject: [PATCH 1/2] [NFC][CLANG] Rename duplicate loop attributes diagnostic functions This patch renames CheckForDuplicateCodeAlignAttrs() to CheckForDuplicateLoopAttrs() and corresponding other functions that call it to be used for other statement attributes in future. --- clang/include/clang/Sema/Sema.h | 2 +- clang/lib/Sema/SemaStmtAttr.cpp | 18 +- clang/lib/Sema/TreeTransform.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1d7b4c729ce84e..20228da15ade8f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2102,7 +2102,7 @@ class Sema final { SourceLocation AttrLoc); CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E); - bool CheckRebuiltCodeAlignStmtAttributes(ArrayRef Attrs); + bool CheckRebuiltStmtAttributes(ArrayRef Attrs); bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index 0d0a7bcebab4e8..a7f6ba4d7abf04 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -361,11 +361,11 @@ static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const ParsedAttr &A) { } // Diagnose non-identical duplicates as a 'conflicting' loop attributes -// and suppress duplicate errors in cases where the two match for -// [[clang::code_align()]] attribute. -static void CheckForDuplicateCodeAlignAttrs(Sema &S, +// and suppress duplicate errors in cases where the two match. +template +static void CheckForDuplicateLoopAttrs(Sema &S, ArrayRef Attrs) { - auto FindFunc = [](const Attr *A) { return isa(A); }; + auto FindFunc = [](const Attr *A) { return isa(A); }; const auto *FirstItr = std::find_if(Attrs.begin(), Attrs.end(), FindFunc); if (FirstItr == Attrs.end()) // no attributes found @@ -375,7 +375,7 @@ static void CheckForDuplicateCodeAlignAttrs(Sema &S, std::optional FirstValue; const auto *CAFA = - dyn_cast(cast(*FirstItr)->getAlignment()); + dyn_cast(cast(*FirstItr)->getAlignment()); // Return early if first alignment expression is dependent (since we don't // know what the effective size will be), and skip the loop entirely. if (!CAFA) @@ -384,7 +384,7 @@ static void CheckForDuplicateCodeAlignAttrs(Sema &S, while (Attrs.end() != (LastFoundItr = std::find_if(LastFoundItr + 1, Attrs.end(), FindFunc))) { const auto *CASA = dyn_cast( -cast(*LastFoundItr)->getAlignment()); +cast(*LastFoundItr)->getAlignment()); // If the value is dependent, we can not test anything. if (!CASA) return; @@ -635,10 +635,10 @@ void Sema::ProcessStmtAttributes(Stmt *S, const ParsedAttributes &InAttrs, } CheckForIncompatibleAttributes(*this, OutAttrs); - CheckForDuplicateCodeAlignAttrs(*this, OutAttrs); + CheckForDuplicateLoopAttrs(*this, OutAttrs); } -bool Sema::CheckRebuiltCodeAlignStmtAttributes(ArrayRef Attrs) { - CheckForDuplicateCodeAlignAttrs(*this, Attrs); +bool Sema::CheckRebuiltStmtAttributes(ArrayRef Attrs) { + CheckForDuplicateLoopAttrs(*this, Attrs); return false; } diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 1ad843d0bf4e0c..7df5bf0cb71370 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1378,7 +1378,7 @@ class TreeTransform { StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef Attrs, Stmt *SubStmt) { -if (SemaRef.CheckRebuiltCodeAlignStmtAttributes(Attrs)) +if (SemaRef.CheckRebuiltStmtAttributes(Attrs)) return StmtError(); return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt); } >From ffa9536901f3f9c7ecad0f22f94efbee2233850c Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Fri, 15 Dec 2023 13:26:59 -0800 Subject: [PATCH 2/2] Fix clang-format errors --- clang/lib/Sema/SemaStmtAttr.cpp | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index a7f6ba4d7abf04..e6a4d3e63e4aa8 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -363,8 +363,7 @@ static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const ParsedAttr &A) { // Diagnose non-identical duplicates as a 'conflicting' loop attributes // and suppress duplicate errors in cases where the two match. template -static void CheckForDuplicateLoopAttrs(Sema &S, -
[libc] [libcxx] [llvm] [flang] [clang-tools-extra] [compiler-rt] [clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { rjmccall wrote: Okay, I think I'm starting to see the root of my confusion here. It looks like you *are* updating the common infrastructure for computing bounds. You are *also* adding a new bounds check for array subscripts into flexible array members, and that code seems to be quite a bit more complex than just calling into the common infrastructure. @rapidsna Is there a specification for bound expressions? I would like to understand how this works a little better, and in particular I am concerned about the idea that bound expressions can involve a path that isn't rooted in the same struct as the bounded member. https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang][nfc] Refactor linker invocation logic (PR #75648)
https://github.com/psteinfeld approved this pull request. All looks good. Thanks for the quick fix! https://github.com/llvm/llvm-project/pull/75648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][CLANG] Rename duplicate loop attributes diagnostic functions (PR #75657)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 35a003c2b21082f3c47c8b01d9d1955af5ab098e f3cfe4cbc1053162b825cc144a5f5c0f73a40b77 -- clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaStmtAttr.cpp clang/lib/Sema/TreeTransform.h `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index a7f6ba4d7a..e6a4d3e63e 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -363,8 +363,7 @@ static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const ParsedAttr &A) { // Diagnose non-identical duplicates as a 'conflicting' loop attributes // and suppress duplicate errors in cases where the two match. template -static void CheckForDuplicateLoopAttrs(Sema &S, -ArrayRef Attrs) { +static void CheckForDuplicateLoopAttrs(Sema &S, ArrayRef Attrs) { auto FindFunc = [](const Attr *A) { return isa(A); }; const auto *FirstItr = std::find_if(Attrs.begin(), Attrs.end(), FindFunc); @@ -383,8 +382,8 @@ static void CheckForDuplicateLoopAttrs(Sema &S, while (Attrs.end() != (LastFoundItr = std::find_if(LastFoundItr + 1, Attrs.end(), FindFunc))) { -const auto *CASA = dyn_cast( -cast(*LastFoundItr)->getAlignment()); +const auto *CASA = +dyn_cast(cast(*LastFoundItr)->getAlignment()); // If the value is dependent, we can not test anything. if (!CASA) return; `` https://github.com/llvm/llvm-project/pull/75657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][CLANG] Rename duplicate loop attributes diagnostic functions (PR #75657)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (smanna12) Changes This patch renames CheckForDuplicateCodeAlignAttrs() to CheckForDuplicateLoopAttrs() and corresponding other functions that call it to be used for other statement attributes in future. --- Full diff: https://github.com/llvm/llvm-project/pull/75657.diff 3 Files Affected: - (modified) clang/include/clang/Sema/Sema.h (+1-1) - (modified) clang/lib/Sema/SemaStmtAttr.cpp (+9-9) - (modified) clang/lib/Sema/TreeTransform.h (+1-1) ``diff diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1d7b4c729ce84e..20228da15ade8f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2102,7 +2102,7 @@ class Sema final { SourceLocation AttrLoc); CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E); - bool CheckRebuiltCodeAlignStmtAttributes(ArrayRef Attrs); + bool CheckRebuiltStmtAttributes(ArrayRef Attrs); bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index 0d0a7bcebab4e8..a7f6ba4d7abf04 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -361,11 +361,11 @@ static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const ParsedAttr &A) { } // Diagnose non-identical duplicates as a 'conflicting' loop attributes -// and suppress duplicate errors in cases where the two match for -// [[clang::code_align()]] attribute. -static void CheckForDuplicateCodeAlignAttrs(Sema &S, +// and suppress duplicate errors in cases where the two match. +template +static void CheckForDuplicateLoopAttrs(Sema &S, ArrayRef Attrs) { - auto FindFunc = [](const Attr *A) { return isa(A); }; + auto FindFunc = [](const Attr *A) { return isa(A); }; const auto *FirstItr = std::find_if(Attrs.begin(), Attrs.end(), FindFunc); if (FirstItr == Attrs.end()) // no attributes found @@ -375,7 +375,7 @@ static void CheckForDuplicateCodeAlignAttrs(Sema &S, std::optional FirstValue; const auto *CAFA = - dyn_cast(cast(*FirstItr)->getAlignment()); + dyn_cast(cast(*FirstItr)->getAlignment()); // Return early if first alignment expression is dependent (since we don't // know what the effective size will be), and skip the loop entirely. if (!CAFA) @@ -384,7 +384,7 @@ static void CheckForDuplicateCodeAlignAttrs(Sema &S, while (Attrs.end() != (LastFoundItr = std::find_if(LastFoundItr + 1, Attrs.end(), FindFunc))) { const auto *CASA = dyn_cast( -cast(*LastFoundItr)->getAlignment()); +cast(*LastFoundItr)->getAlignment()); // If the value is dependent, we can not test anything. if (!CASA) return; @@ -635,10 +635,10 @@ void Sema::ProcessStmtAttributes(Stmt *S, const ParsedAttributes &InAttrs, } CheckForIncompatibleAttributes(*this, OutAttrs); - CheckForDuplicateCodeAlignAttrs(*this, OutAttrs); + CheckForDuplicateLoopAttrs(*this, OutAttrs); } -bool Sema::CheckRebuiltCodeAlignStmtAttributes(ArrayRef Attrs) { - CheckForDuplicateCodeAlignAttrs(*this, Attrs); +bool Sema::CheckRebuiltStmtAttributes(ArrayRef Attrs) { + CheckForDuplicateLoopAttrs(*this, Attrs); return false; } diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 1ad843d0bf4e0c..7df5bf0cb71370 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1378,7 +1378,7 @@ class TreeTransform { StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef Attrs, Stmt *SubStmt) { -if (SemaRef.CheckRebuiltCodeAlignStmtAttributes(Attrs)) +if (SemaRef.CheckRebuiltStmtAttributes(Attrs)) return StmtError(); return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt); } `` https://github.com/llvm/llvm-project/pull/75657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][CLANG] Rename duplicate loop attributes diagnostic functions (PR #75657)
https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/75657 This patch renames CheckForDuplicateCodeAlignAttrs() to CheckForDuplicateLoopAttrs() and corresponding other functions that call it to be used for other statement attributes in future. >From f3cfe4cbc1053162b825cc144a5f5c0f73a40b77 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Fri, 15 Dec 2023 13:15:50 -0800 Subject: [PATCH] [NFC][CLANG] Rename duplicate loop attributes diagnostic functions This patch renames CheckForDuplicateCodeAlignAttrs() to CheckForDuplicateLoopAttrs() and corresponding other functions that call it to be used for other statement attributes in future. --- clang/include/clang/Sema/Sema.h | 2 +- clang/lib/Sema/SemaStmtAttr.cpp | 18 +- clang/lib/Sema/TreeTransform.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1d7b4c729ce84e..20228da15ade8f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2102,7 +2102,7 @@ class Sema final { SourceLocation AttrLoc); CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E); - bool CheckRebuiltCodeAlignStmtAttributes(ArrayRef Attrs); + bool CheckRebuiltStmtAttributes(ArrayRef Attrs); bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index 0d0a7bcebab4e8..a7f6ba4d7abf04 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -361,11 +361,11 @@ static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const ParsedAttr &A) { } // Diagnose non-identical duplicates as a 'conflicting' loop attributes -// and suppress duplicate errors in cases where the two match for -// [[clang::code_align()]] attribute. -static void CheckForDuplicateCodeAlignAttrs(Sema &S, +// and suppress duplicate errors in cases where the two match. +template +static void CheckForDuplicateLoopAttrs(Sema &S, ArrayRef Attrs) { - auto FindFunc = [](const Attr *A) { return isa(A); }; + auto FindFunc = [](const Attr *A) { return isa(A); }; const auto *FirstItr = std::find_if(Attrs.begin(), Attrs.end(), FindFunc); if (FirstItr == Attrs.end()) // no attributes found @@ -375,7 +375,7 @@ static void CheckForDuplicateCodeAlignAttrs(Sema &S, std::optional FirstValue; const auto *CAFA = - dyn_cast(cast(*FirstItr)->getAlignment()); + dyn_cast(cast(*FirstItr)->getAlignment()); // Return early if first alignment expression is dependent (since we don't // know what the effective size will be), and skip the loop entirely. if (!CAFA) @@ -384,7 +384,7 @@ static void CheckForDuplicateCodeAlignAttrs(Sema &S, while (Attrs.end() != (LastFoundItr = std::find_if(LastFoundItr + 1, Attrs.end(), FindFunc))) { const auto *CASA = dyn_cast( -cast(*LastFoundItr)->getAlignment()); +cast(*LastFoundItr)->getAlignment()); // If the value is dependent, we can not test anything. if (!CASA) return; @@ -635,10 +635,10 @@ void Sema::ProcessStmtAttributes(Stmt *S, const ParsedAttributes &InAttrs, } CheckForIncompatibleAttributes(*this, OutAttrs); - CheckForDuplicateCodeAlignAttrs(*this, OutAttrs); + CheckForDuplicateLoopAttrs(*this, OutAttrs); } -bool Sema::CheckRebuiltCodeAlignStmtAttributes(ArrayRef Attrs) { - CheckForDuplicateCodeAlignAttrs(*this, Attrs); +bool Sema::CheckRebuiltStmtAttributes(ArrayRef Attrs) { + CheckForDuplicateLoopAttrs(*this, Attrs); return false; } diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 1ad843d0bf4e0c..7df5bf0cb71370 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1378,7 +1378,7 @@ class TreeTransform { StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef Attrs, Stmt *SubStmt) { -if (SemaRef.CheckRebuiltCodeAlignStmtAttributes(Attrs)) +if (SemaRef.CheckRebuiltStmtAttributes(Attrs)) return StmtError(); return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [clang-tools-extra] [mlir][TilingInterface] Early return cloned ops if tile sizes are zeros. (PR #75410)
https://github.com/hanhanW updated https://github.com/llvm/llvm-project/pull/75410 >From c07f7e1c5c6f8bbc7189e96096004d39a0a1aa3f Mon Sep 17 00:00:00 2001 From: hanhanW Date: Wed, 13 Dec 2023 15:59:48 -0800 Subject: [PATCH 1/2] [mlir][TilingInterface] Early return cloned ops if tile sizes are zeros. It is a trivial early-return case. If the cloned ops are not returned, it will generate `extract_slice` op that extracts the whole slice. However, it is not folded away. Early-return to avoid the case. E.g., ```mlir func.func @matmul_tensors( %arg0: tensor, %arg1: tensor, %arg2: tensor) -> tensor { %0 = linalg.matmul ins(%arg0, %arg1: tensor, tensor) outs(%arg2: tensor) -> tensor return %0 : tensor } module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { %0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op %1 = transform.structured.tile_using_for %0 [0, 0, 0] : (!transform.any_op) -> (!transform.any_op) transform.yield } } ``` Apply the transforms and canonicalize the IR: ``` mlir-opt --transform-interpreter -canonicalize input.mlir ``` we will get ```mlir module { func.func @matmul_tensors(%arg0: tensor, %arg1: tensor, %arg2: tensor) -> tensor { %c1 = arith.constant 1 : index %c0 = arith.constant 0 : index %dim = tensor.dim %arg0, %c0 : tensor %dim_0 = tensor.dim %arg0, %c1 : tensor %dim_1 = tensor.dim %arg1, %c1 : tensor %extracted_slice = tensor.extract_slice %arg0[0, 0] [%dim, %dim_0] [1, 1] : tensor to tensor %extracted_slice_2 = tensor.extract_slice %arg1[0, 0] [%dim_0, %dim_1] [1, 1] : tensor to tensor %extracted_slice_3 = tensor.extract_slice %arg2[0, 0] [%dim, %dim_1] [1, 1] : tensor to tensor %0 = linalg.matmul ins(%extracted_slice, %extracted_slice_2 : tensor, tensor) outs(%extracted_slice_3 : tensor) -> tensor return %0 : tensor } } ``` --- .../SCF/Transforms/TileUsingInterface.cpp | 11 ++-- mlir/test/Dialect/Linalg/tile-tensors.mlir| 27 +++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp b/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp index 8057b3898012d4..20413aba8730be 100644 --- a/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp +++ b/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp @@ -362,14 +362,21 @@ mlir::scf::tileUsingSCFForOp(RewriterBase &rewriter, TilingInterface op, auto clonedOp = cast( cloneOpAndUpdateDestinationArgs(rewriter, op, clonedOpDestination)); - // 5b. Tile the cloned operation. + // 5b. Early return cloned op if tiling is not happenning. + if (llvm::all_of(tileSizeVector, + [](OpFoldResult v) { return isZeroIndex(v); })) { +return scf::SCFTilingResult{/*tiledOps=*/{clonedOp}, /*loops=*/{}, +clonedOp->getResults()}; + } + + // 5c. Tile the cloned operation. FailureOr tiledImplementation = clonedOp.getTiledImplementation(rewriter, offsets, sizes); if (failed(tiledImplementation)) { return rewriter.notifyMatchFailure(op, "failed to tile operation"); } - // 5c. Delete the cloned operation. + // 5d. Delete the cloned operation. rewriter.eraseOp(clonedOp); // If loops are empty, the tiled op is used as the replacement for the untiled diff --git a/mlir/test/Dialect/Linalg/tile-tensors.mlir b/mlir/test/Dialect/Linalg/tile-tensors.mlir index e0429b1f873298..e8e63302286400 100644 --- a/mlir/test/Dialect/Linalg/tile-tensors.mlir +++ b/mlir/test/Dialect/Linalg/tile-tensors.mlir @@ -37,6 +37,33 @@ module attributes {transform.with_named_sequence} { // - +// CHECK-LABEL: func @matmul_tensors_with_size_zeros( +// CHECK-SAME:%[[TA:[0-9a-z]+]]: tensor +// CHECK-SAME:%[[TB:[0-9a-z]+]]: tensor +// CHECK-SAME:%[[TC:[0-9a-z]+]]: tensor) -> tensor { +func.func @matmul_tensors_with_size_zeros( + %arg0: tensor, %arg1: tensor, %arg2: tensor) +-> tensor { + +// CHECK: %[[RES:.*]] = linalg.matmul ins(%[[TA]], %[[TB]] : tensor, tensor) +// CHECK-SAME:outs(%[[TC]] : tensor) -> tensor +// CHECK: return %[[RES]] + %0 = linalg.matmul ins(%arg0, %arg1: tensor, tensor) + outs(%arg2: tensor) +-> tensor + return %0 : tensor +} + +module attributes {transform.with_named_sequence} { + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { +%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op +%1 = transform.structured.tile_using_for %0 [0, 0, 0] : (!transform.any_op) -> (!transform.any_op) +transform.yield + } +} + +// - + func.func @generic_op_tensors( %arg0 : tensor, %arg1 : tensor) -> tensor { %c0 = arit
[clang-tools-extra] [clang] [mlir] [llvm] [mlir][TilingInterface] Early return cloned ops if tile sizes are zeros. (PR #75410)
@@ -362,14 +362,21 @@ mlir::scf::tileUsingSCFForOp(RewriterBase &rewriter, TilingInterface op, auto clonedOp = cast( cloneOpAndUpdateDestinationArgs(rewriter, op, clonedOpDestination)); - // 5b. Tile the cloned operation. + // 5b. Early return cloned op if tiling is not happenning. + if (llvm::all_of(tileSizeVector, + [](OpFoldResult v) { return isZeroIndex(v); })) { hanhanW wrote: Really good point! https://github.com/llvm/llvm-project/pull/75410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)
https://github.com/adrian-prantl commented: I think this LGTM, but it would be good if someone else also took a look. https://github.com/llvm/llvm-project/pull/75385 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)
@@ -238,6 +238,13 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc, } } +// Avoid cloning local variables of subprograms that won't be cloned. adrian-prantl wrote: Can you add a sentence explaining why some subprograms won't be cloned? Is it because they are inlined and a copy already exists? https://github.com/llvm/llvm-project/pull/75385 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) (PR #75226)
https://github.com/lei137 updated https://github.com/llvm/llvm-project/pull/75226 >From f38e709e414d1c9dae4f9d75f1decaf363bf9427 Mon Sep 17 00:00:00 2001 From: Lei Huang Date: Tue, 12 Dec 2023 10:58:34 -0600 Subject: [PATCH 1/3] [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) On Linux PPC call lib func ``frexpl`` for calls to ``frexp()`` for input of type PPCDoubleDouble. Fixes bug: https://github.com/llvm/llvm-project/issues/64426 --- clang/lib/CodeGen/CGBuiltin.cpp | 17 - .../c.math/constexpr-cxx23-clang.pass.cpp | 6 -- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 353b7930b3c1ea..e733bbf8be8b71 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -137,6 +137,10 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, {Builtin::BI__builtin_modfl, "modf"}, }; + static SmallDenseMap PPCDoubleDoubleBuiltins{ + {Builtin::BI__builtin_frexpl, "frexpl"}, + }; + // If the builtin has been declared explicitly with an assembler label, // use the mangled name. This differs from the plain label on platforms // that prefix labels. @@ -149,6 +153,11 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad() && F128Builtins.contains(BuiltinID)) Name = F128Builtins[BuiltinID]; +else if (getTriple().isPPC() && getTriple().isOSLinux() && + &getTarget().getLongDoubleFormat() == + &llvm::APFloat::PPCDoubleDouble() && + PPCDoubleDoubleBuiltins.contains(BuiltinID)) + Name = PPCDoubleDoubleBuiltins[BuiltinID]; else if (getTriple().isOSAIX() && &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEdouble() && @@ -3410,9 +3419,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, { Src0->getType(), Src1->getType() }); return RValue::get(Builder.CreateCall(F, { Src0, Src1 })); } + case Builtin::BI__builtin_frexpl: { +auto &Triple = getTarget().getTriple(); +if (Triple.isPPC() && Triple.isOSLinux() && +&getTarget().getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble()) + break; +LLVM_FALLTHROUGH; + } case Builtin::BI__builtin_frexp: case Builtin::BI__builtin_frexpf: - case Builtin::BI__builtin_frexpl: case Builtin::BI__builtin_frexpf128: case Builtin::BI__builtin_frexpf16: return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp)); diff --git a/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp b/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp index 31511064ce7ca5..a07260a34516f1 100644 --- a/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp +++ b/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp @@ -58,15 +58,9 @@ int main(int, char**) { ASSERT_NOT_CONSTEXPR_CXX23(std::frexp(0.0f, &DummyInt) == 0.0f); ASSERT_NOT_CONSTEXPR_CXX23(std::frexp(0.0, &DummyInt) == 0.0); -//FIXME: currently linux powerpc does not support this expansion -// since 0.0L lowers to ppcf128 and special handling is required. -#if !defined(__LONG_DOUBLE_IBM128__) ASSERT_NOT_CONSTEXPR_CXX23(std::frexp(0.0L, &DummyInt) == 0.0L); -#endif ASSERT_NOT_CONSTEXPR_CXX23(std::frexpf(0.0f, &DummyInt) == 0.0f); -#if !defined(__LONG_DOUBLE_IBM128__) ASSERT_NOT_CONSTEXPR_CXX23(std::frexpl(0.0L, &DummyInt) == 0.0L); -#endif ASSERT_NOT_CONSTEXPR_CXX23(std::ilogb(1.0f) == 0); ASSERT_NOT_CONSTEXPR_CXX23(std::ilogb(1.0) == 0); >From 3065e1287b5be023e8e9bf85ff2b76d6c194f58c Mon Sep 17 00:00:00 2001 From: Lei Huang Date: Thu, 14 Dec 2023 09:28:50 -0600 Subject: [PATCH 2/3] address Eli's review comments --- clang/lib/CodeGen/CGBuiltin.cpp | 15 --- clang/test/CodeGen/math-builtins-long.c | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index e733bbf8be8b71..73df0ef99f853c 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -137,10 +137,6 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, {Builtin::BI__builtin_modfl, "modf"}, }; - static SmallDenseMap PPCDoubleDoubleBuiltins{ - {Builtin::BI__builtin_frexpl, "frexpl"}, - }; - // If the builtin has been declared explicitly with an assembler label, // use the mangled name. This differs from the plain label on platforms // that prefix labels. @@ -153,11 +149,6 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad() && F128Builtins.contains(BuiltinID)) Name = F1
[clang] [llvm] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)
topperc wrote: This patch is unfortunately incorrect because Zvfbfmin implies Zfbfmin but the SiFive CPUs that implement Xsfvfwmaccqqq do not implement Zfbfmin. https://github.com/llvm/llvm-project/pull/71140 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [flang] [compiler-rt] [clang] [llvm] [libc] [libcxx] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
https://github.com/rjmccall edited https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [flang] [compiler-rt] [clang] [llvm] [libc] [libcxx] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { rjmccall wrote: I understand that this patch specifically can be thought of as trying to do something fairly modest. However, it is a part of a sequence of patches that I haven't been paying much attention to, and what it is actually doing makes me concerned about the larger sequence of patches and whether you might be implementing something that doesn't make a whole lot of sense. I am trying to understand what's going on to see if maybe I can course-correct and make sure that the overall feature is a good one. https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [flang] [compiler-rt] [clang] [llvm] [libc] [libcxx] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { bwendling wrote: No. there are only two places where we look at the `__counted_by` attribute: during bounds checking, and in a `__builtin_dynamic_object_size` statement. The former is the main focus of this patch. The latter attempts to calculate the size without introducing side-effects from the loading `count`. They both use similar paths, though I've been toying with your idea of using the offsets and it seems to work and may be more robust than trying to build the array and count accesses off of the same base pointer. https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [flang] [compiler-rt] [clang] [llvm] [libc] [libcxx] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { rjmccall wrote: We have other code that computes the value of the `__counted_by` bound when we e.g. load a pointer from a field with the attribute, yes? https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)
efriedma-quic wrote: > > Making Sema pull the TBAA info out of clang/lib/CodeGen is a layering > > violation (and probably breaks if we aren't actually generating code). If > > we need some notion of "aliasing" in Sema, we should pull the relevant code > > into clang/lib/AST. > > That's unfortunate. The code will not call the TBAA stuff if the code > generator doesn't provide that predicate -- so if not generating optimized > code the warning is inactive. This is the same as with GCC btw. To be clear > what's exposed is a new predicate allowing querying of type conversion's > TBAAness -- the representations of TBAA etc are not exposed. The CodeGen TBAA > machinery builds on llvm's aliasing MDNodes. It would seem a large task to > replicate that in AST (and I presume propagating llvm's bits further into AST > is even worse?) On the LLVM side, there's very little interesting logic; it's basically just walking the tree of metadata nodes generated by clang. See https://llvm.org/docs/LangRef.html#tbaa-node-semantics . The hard part of the refactoring would just be adding an abstraction for the underlying information. gcc has made various unfortunate decisions regarding diagnostics in the past; we've put a lot of effort into making sure our diagnostics are more consistent. https://github.com/llvm/llvm-project/pull/74155 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #73017)
egorzhdan wrote: @compnerd ping :) https://github.com/llvm/llvm-project/pull/73017 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [libcxx] [compiler-rt] [llvm] [libc] [clang-tools-extra] [clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
https://github.com/bwendling edited https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [libcxx] [compiler-rt] [llvm] [libc] [clang-tools-extra] [clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
https://github.com/bwendling edited https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add -fandroid-pad-segment/-fno-android-pad-segment (PR #75652)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff a4d1d5f5b54b2f93d7290588734f59ff24fc515c f82a3a8cf72ba4207fb2cdc04467079d51e20efa -- clang/lib/Driver/ToolChains/Gnu.cpp clang/test/Driver/linux-ld.c `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index e97470c13c..063f093fe4 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -510,7 +510,8 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (isAndroid && Args.hasFlag(options::OPT_fandroid_pad_segment, options::OPT_fno_android_pad_segment, false)) - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt_pad_segment.o"))); + CmdArgs.push_back( + Args.MakeArgString(ToolChain.GetFilePath("crt_pad_segment.o"))); } Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u}); `` https://github.com/llvm/llvm-project/pull/75652 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add -fandroid-pad-segment/-fno-android-pad-segment (PR #75652)
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/75652 -fandroid-pad-segment is an Android-specific opt-in option that links in crt_pad_segment.o. crt_pad_segment.o contains a note section, which will be included in the linker-created PT_NOTE segment. This PT_NOTE tell Bionic that: when create a map for a PT_LOAD segment, extend the end to cover the gap so that we will have fewer kernel 'struct vm_area_struct' objects when page_size < MAXPAGESIZE. See also https://sourceware.org/bugzilla/show_bug.cgi?id=31076 >From f82a3a8cf72ba4207fb2cdc04467079d51e20efa Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 15 Dec 2023 11:16:37 -0800 Subject: [PATCH] [Driver] Add -fandroid-pad-segment/-fno-android-pad-segment -fandroid-pad-segment is an Android-specific opt-in option that links in crt_pad_segment.o. crt_pad_segment.o contains a note section, which will be included in the linker-created PT_NOTE segment. This PT_NOTE tell Bionic that: when create a map for a PT_LOAD segment, extend the end to cover the gap so that we will have fewer kernel 'struct vm_area_struct' objects when page_size < MAXPAGESIZE. See also https://sourceware.org/bugzilla/show_bug.cgi?id=31076 --- clang/include/clang/Driver/Options.td | 5 + clang/lib/Driver/ToolChains/Gnu.cpp | 4 .../sysroot/usr/lib/crt_pad_segment.o | 0 clang/test/Driver/linux-ld.c | 19 ++- 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 clang/test/Driver/Inputs/basic_android_tree/sysroot/usr/lib/crt_pad_segment.o diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 1b02087425b751..1d193dacc544b4 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6286,6 +6286,11 @@ def fno_sycl : Flag<["-"], "fno-sycl">, Visibility<[ClangOption, CLOption]>, Group, HelpText<"Disables SYCL kernels compilation for device">; +// OS-specific options +let Flags = [TargetSpecific] in { +defm android_pad_segment : BooleanFFlag<"android-pad-segment">, Group; +} // let Flags = [TargetSpecific] + //===--===// // FLangOption + NoXarchOption //===--===// diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 835215a83c4037..e97470c13ce68a 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -507,6 +507,10 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, // Add crtfastmath.o if available and fast math is enabled. ToolChain.addFastMathRuntimeIfAvailable(Args, CmdArgs); + +if (isAndroid && Args.hasFlag(options::OPT_fandroid_pad_segment, + options::OPT_fno_android_pad_segment, false)) + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt_pad_segment.o"))); } Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u}); diff --git a/clang/test/Driver/Inputs/basic_android_tree/sysroot/usr/lib/crt_pad_segment.o b/clang/test/Driver/Inputs/basic_android_tree/sysroot/usr/lib/crt_pad_segment.o new file mode 100644 index 00..e69de29bb2d1d6 diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c index 15643d6491ae52..49693b6a2d87e2 100644 --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -1338,7 +1338,24 @@ // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ // RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD-LINK %s // CHECK-ANDROID-PTHREAD-LINK-NOT: argument unused during compilation: '-pthread' -// + +/// Check -fandroid-pad-segment. +// RUN: %clang -### %s --target=aarch64-linux-android -rtlib=platform --unwindlib=platform \ +// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -fandroid-pad-segment 2>&1 | FileCheck --check-prefix=CHECK-ANDROID-PAD-PHDR %s +// CHECK-ANDROID-PAD-PHDR: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" +// CHECK-ANDROID-PAD-PHDR: "[[SYSROOT]]/usr/lib/crtbegin_dynamic.o" "[[SYSROOT]]/usr/lib/crt_pad_phdr.o" + +// RUN: %clang -### %s --target=aarch64-linux-android -rtlib=platform --unwindlib=platform \ +// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -fandroid-pad-segment -fno-android-pad-segment 2>&1 | FileCheck --check-prefix=CHECK-NO-ANDROID-PAD-PHDR %s +// CHECK-NO-ANDROID-PAD-PHDR: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" +// CHECK-NO-ANDROID-PAD-PHDR: "[[SYSROOT]]/usr/lib/crtbegin_dynamic.o" +// CHECK-NO-ANDROID-PAD-PHDR-NOT: crt_pad_phdr.o" + +// RUN: not %clang -### %s --target=aarch64-linux -fandroid-pad-segment 2>&1 | FileCheck --check-prefix=ERR-ANDROID-PAD-EHDR %s +// ERR-ANDROID-PAD-EHDR: error: unsupported option '-fandroid-pad-segment' for
[flang] [libcxx] [compiler-rt] [llvm] [libc] [clang-tools-extra] [clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
https://github.com/bwendling edited https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Warning for unsafe invocation of span::data (PR #75650)
https://github.com/malavikasamak edited https://github.com/llvm/llvm-project/pull/75650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] While refactoring projects to eradicate unsafe buffer accesses using … (PR #75650)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff ec92d74a0ef89b9dd46aee6ec8aca6bfd3c66a54 809bf6f4237f634feaeb7e5b0b88be3a2e4de455 -- clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h clang/lib/Analysis/UnsafeBufferUsage.cpp clang/lib/Sema/AnalysisBasedWarnings.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index e4eca9939b..4e1c76c300 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -729,7 +729,7 @@ class DataInvocationGadget : public WarningGadget { constexpr static const char *const OpTag = "data_invocation_expr"; const ExplicitCastExpr *Op; - public: +public: DataInvocationGadget(const MatchFinder::MatchResult &Result) : WarningGadget(Kind::DataInvocation), Op(Result.Nodes.getNodeAs(OpTag)) {} @@ -737,12 +737,12 @@ class DataInvocationGadget : public WarningGadget { static bool classof(const Gadget *G) { return G->getKind() == Kind::DataInvocation; } - + static Matcher matcher() { -return stmt( -explicitCastExpr(has(cxxMemberCallExpr(callee( - cxxMethodDecl(hasName("data")).bind(OpTag)); - } +return stmt(explicitCastExpr(has(cxxMemberCallExpr( + callee(cxxMethodDecl(hasName("data")) +.bind(OpTag)); + } const Stmt *getBaseStmt() const override { return Op; } DeclUseList getClaimedVarUseSites() const override { return {}; } @@ -2684,7 +2684,7 @@ void clang::checkUnsafeBufferUsage(const Decl *D, // every problematic operation and consider it done. No need to deal // with fixable gadgets, no need to group operations by variable. for (const auto &G : WarningGadgets) { - Handler.handleUnsafeOperation(G->getBaseStmt(), /*IsRelatedToDecl=*/false, + Handler.handleUnsafeOperation(G->getBaseStmt(), /*IsRelatedToDecl=*/false, D->getASTContext()); } @@ -2920,8 +2920,8 @@ void clang::checkUnsafeBufferUsage(const Decl *D, Tracker, Handler, VarGrpMgr); for (const auto &G : UnsafeOps.noVar) { -Handler.handleUnsafeOperation(G->getBaseStmt(), /*IsRelatedToDecl=*/false - , D->getASTContext()); +Handler.handleUnsafeOperation(G->getBaseStmt(), /*IsRelatedToDecl=*/false, + D->getASTContext()); } for (const auto &[VD, WarningGadgets] : UnsafeOps.byVar) { @@ -2932,8 +2932,8 @@ void clang::checkUnsafeBufferUsage(const Decl *D, : FixItList{}, D); for (const auto &G : WarningGadgets) { - Handler.handleUnsafeOperation(G->getBaseStmt(), /*IsRelatedToDecl=*/true -, D->getASTContext()); + Handler.handleUnsafeOperation(G->getBaseStmt(), /*IsRelatedToDecl=*/true, +D->getASTContext()); } } } diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 4f8e181806..bcf3241514 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -2226,7 +2226,7 @@ public: UnsafeBufferUsageReporter(Sema &S, bool SuggestSuggestions) : S(S), SuggestSuggestions(SuggestSuggestions) {} - void handleUnsafeOperation(const Stmt *Operation, bool IsRelatedToDecl, + void handleUnsafeOperation(const Stmt *Operation, bool IsRelatedToDecl, ASTContext &Ctx) override { SourceLocation Loc; SourceRange Range; @@ -2263,19 +2263,21 @@ public: MsgParam = 3; } else if (const auto *ECE = dyn_cast(Operation)) { QualType destType = ECE->getType(); -const uint64_t dSize = Ctx.getTypeSize(destType.getTypePtr()->getPointeeType()); -if(const auto *CE =dyn_cast(ECE->getSubExpr())) { +const uint64_t dSize = +Ctx.getTypeSize(destType.getTypePtr()->getPointeeType()); +if (const auto *CE = dyn_cast(ECE->getSubExpr())) { + + if (CE->getRecordDecl()->getQualifiedNameAsString().compare( + "std::span")) +return; - if(CE->getRecordDecl()->getQualifiedNameAsString().compare("std::span")) - return; - QualType srcType = CE->getType(); - const uint64_t sSize = Ctx.getTypeSize(srcType.getTypePtr()->getPointeeType()); - if(sSize >= dSize) + const uint64_t sSize = + Ctx.getTypeSize(srcType.getTypePtr()->getPointeeType()); + if (sSize >= dSize)
[clang-tools-extra] [compiler-rt] [flang] [libcxx] [libc] [llvm] [clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { bwendling wrote: What do you mean the other uses of `__counted_by`? It's only used with FAMs and in the sanitizer. This patch doesn't add new functionality. It only some bugs and modifies how the code is created. https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] While refactoring projects to eradicate unsafe buffer accesses using … (PR #75650)
llvmbot wrote: @llvm/pr-subscribers-clang-analysis @llvm/pr-subscribers-clang Author: Malavika Samak (malavikasamak) Changes …-Wunsafe-buffer-usage, there maybe accidental re-introduction of new OutOfBound accesses into the code bases. One such case is invoking span::data() method on a span variable to retrieve a pointer, which is then cast to a larger type and dereferenced. Such dereferences can introduce OutOfBound accesses. To address this, a new WarningGadget is being introduced to warn against such invocations. --- Full diff: https://github.com/llvm/llvm-project/pull/75650.diff 6 Files Affected: - (modified) clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h (+1-1) - (modified) clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def (+1) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) - (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+33-4) - (modified) clang/lib/Sema/AnalysisBasedWarnings.cpp (+17-2) - (added) clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp (+133) ``diff diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h index 8a2d56668e32f9..b28f2c6b99c50e 100644 --- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h +++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h @@ -66,7 +66,7 @@ class UnsafeBufferUsageHandler { /// Invoked when an unsafe operation over raw pointers is found. virtual void handleUnsafeOperation(const Stmt *Operation, - bool IsRelatedToDecl) = 0; + bool IsRelatedToDecl, ASTContext &Ctx) = 0; /// Invoked when a fix is suggested against a variable. This function groups /// all variables that must be fixed together (i.e their types must be changed diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def index 757ee452ced748..c9766168836510 100644 --- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def +++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def @@ -30,6 +30,7 @@ WARNING_GADGET(Decrement) WARNING_GADGET(ArraySubscript) WARNING_GADGET(PointerArithmetic) WARNING_GADGET(UnsafeBufferUsageAttr) +WARNING_GADGET(DataInvocation) FIXABLE_GADGET(ULCArraySubscript) // `DRE[any]` in an Unspecified Lvalue Context FIXABLE_GADGET(DerefSimplePtrArithFixable) FIXABLE_GADGET(PointerDereference) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 94e97a891baedc..9038dd879f54ae 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12058,7 +12058,7 @@ def warn_unsafe_buffer_variable : Warning< InGroup, DefaultIgnore; def warn_unsafe_buffer_operation : Warning< "%select{unsafe pointer operation|unsafe pointer arithmetic|" - "unsafe buffer access|function introduces unsafe buffer manipulation}0">, + "unsafe buffer access|function introduces unsafe buffer manipulation|unsafe invocation of span::data}0">, InGroup, DefaultIgnore; def note_unsafe_buffer_operation : Note< "used%select{| in pointer arithmetic| in buffer access}0 here">; diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index 70eec1cee57f8e..e4eca9939b10d5 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -721,6 +721,33 @@ class UnsafeBufferUsageAttrGadget : public WarningGadget { DeclUseList getClaimedVarUseSites() const override { return {}; } }; +// Warning gadget for unsafe invocation of span::data method. +// Triggers when the pointer returned by the invocation is immediately +// cast to a larger type. + +class DataInvocationGadget : public WarningGadget { + constexpr static const char *const OpTag = "data_invocation_expr"; + const ExplicitCastExpr *Op; + + public: + DataInvocationGadget(const MatchFinder::MatchResult &Result) + : WarningGadget(Kind::DataInvocation), +Op(Result.Nodes.getNodeAs(OpTag)) {} + + static bool classof(const Gadget *G) { +return G->getKind() == Kind::DataInvocation; + } + + static Matcher matcher() { +return stmt( +explicitCastExpr(has(cxxMemberCallExpr(callee( + cxxMethodDecl(hasName("data")).bind(OpTag)); + } + const Stmt *getBaseStmt() const override { return Op; } + + DeclUseList getClaimedVarUseSites() const override { return {}; } +}; + // Represents expressions of the form `DRE[*]` in the Unspecified Lvalue // Context (see `isInUnspecifiedLvalueContext`). // Note here `[]` is the built-in subscript operator. @@ -2657,8 +2684,8 @@ void clang::checkUnsafeBufferUsage(const Decl *D, // every problematic operation and consider it done. No need to
[clang] While refactoring projects to eradicate unsafe buffer accesses using … (PR #75650)
https://github.com/malavikasamak created https://github.com/llvm/llvm-project/pull/75650 …-Wunsafe-buffer-usage, there maybe accidental re-introduction of new OutOfBound accesses into the code bases. One such case is invoking span::data() method on a span variable to retrieve a pointer, which is then cast to a larger type and dereferenced. Such dereferences can introduce OutOfBound accesses. To address this, a new WarningGadget is being introduced to warn against such invocations. >From 809bf6f4237f634feaeb7e5b0b88be3a2e4de455 Mon Sep 17 00:00:00 2001 From: MalavikaSamak Date: Fri, 15 Dec 2023 11:40:55 -0800 Subject: [PATCH] While refactoring projects to eradicate unsafe buffer accesses using -Wunsafe-buffer-usage, there maybe accidental re-introduction of new OutOfBound accesses into the code bases. One such case is invoking span::data() method on a span variable to retrieve a pointer, which is then cast to a larger type and dereferenced. Such dereferences can introduce OutOfBound accesses. To address this, a new WarningGadget is being introduced to warn against such invocations. --- .../Analysis/Analyses/UnsafeBufferUsage.h | 2 +- .../Analyses/UnsafeBufferUsageGadgets.def | 1 + .../clang/Basic/DiagnosticSemaKinds.td| 2 +- clang/lib/Analysis/UnsafeBufferUsage.cpp | 37 - clang/lib/Sema/AnalysisBasedWarnings.cpp | 19 ++- ...e-buffer-usage-warning-data-invocation.cpp | 133 ++ 6 files changed, 186 insertions(+), 8 deletions(-) create mode 100644 clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h index 8a2d56668e32f9..b28f2c6b99c50e 100644 --- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h +++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h @@ -66,7 +66,7 @@ class UnsafeBufferUsageHandler { /// Invoked when an unsafe operation over raw pointers is found. virtual void handleUnsafeOperation(const Stmt *Operation, - bool IsRelatedToDecl) = 0; + bool IsRelatedToDecl, ASTContext &Ctx) = 0; /// Invoked when a fix is suggested against a variable. This function groups /// all variables that must be fixed together (i.e their types must be changed diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def index 757ee452ced748..c9766168836510 100644 --- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def +++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def @@ -30,6 +30,7 @@ WARNING_GADGET(Decrement) WARNING_GADGET(ArraySubscript) WARNING_GADGET(PointerArithmetic) WARNING_GADGET(UnsafeBufferUsageAttr) +WARNING_GADGET(DataInvocation) FIXABLE_GADGET(ULCArraySubscript) // `DRE[any]` in an Unspecified Lvalue Context FIXABLE_GADGET(DerefSimplePtrArithFixable) FIXABLE_GADGET(PointerDereference) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 94e97a891baedc..9038dd879f54ae 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12058,7 +12058,7 @@ def warn_unsafe_buffer_variable : Warning< InGroup, DefaultIgnore; def warn_unsafe_buffer_operation : Warning< "%select{unsafe pointer operation|unsafe pointer arithmetic|" - "unsafe buffer access|function introduces unsafe buffer manipulation}0">, + "unsafe buffer access|function introduces unsafe buffer manipulation|unsafe invocation of span::data}0">, InGroup, DefaultIgnore; def note_unsafe_buffer_operation : Note< "used%select{| in pointer arithmetic| in buffer access}0 here">; diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index 70eec1cee57f8e..e4eca9939b10d5 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -721,6 +721,33 @@ class UnsafeBufferUsageAttrGadget : public WarningGadget { DeclUseList getClaimedVarUseSites() const override { return {}; } }; +// Warning gadget for unsafe invocation of span::data method. +// Triggers when the pointer returned by the invocation is immediately +// cast to a larger type. + +class DataInvocationGadget : public WarningGadget { + constexpr static const char *const OpTag = "data_invocation_expr"; + const ExplicitCastExpr *Op; + + public: + DataInvocationGadget(const MatchFinder::MatchResult &Result) + : WarningGadget(Kind::DataInvocation), +Op(Result.Nodes.getNodeAs(OpTag)) {} + + static bool classof(const Gadget *G) { +return G->getKind() == Kind::DataInvocation; + } + + static Matcher matcher() { +return stmt( +explicitCastExpr(has(cxxMemberCallExpr(callee( +
[libcxx] [clang] [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) (PR #75226)
https://github.com/efriedma-quic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/75226 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [flang] [libcxx] [libc] [llvm] [clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { rjmccall wrote: But *why* are you implementing a different rule here than we use for other uses of `__counted_by`? That's an actively bad thing to do. Look, if we have a use case that requires us to make `__counted_by` more flexible than it currently is, then okay, let's have a proper conversation about that and what the design ought to be. The right place to do that is an RFC, not a code review thread. Assuming we accept that proposal, though, this seems like the wrong way to implement it, because it's basically creating a bunch of ad hoc differences just for flexible array members. There's no reason that `__counted_by` should follow different rules for flexible array members than it does for pointer members, at least on the read/bounds-checking side. That means that we should be able to use common infrastructure between the two paths for getting back to the root pointer for the bound expression and evaluating it. Your code here should just be invoking that common infrastructure. So what I suggest is that you do this in three phases: 1. Make `__counted_by` work with flexible array members using the common infrastructure for `__counted_by`. 2. Get agreement on how we're going to generalize `__counted_by` and what the behavior ought to be. 3. Implement the new behavior for `__counted_by` in the common infrastructure for *all* its applications. https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang][nfc] Refactor linker invocation logic (PR #75648)
https://github.com/mjklemm approved this pull request. Looks good to me. Did touch testing with my reproducers and it worked as I would expect it. https://github.com/llvm/llvm-project/pull/75648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][lex] Fix non-portability diagnostics with absolute path (PR #74782)
jansvoboda11 wrote: Ping. https://github.com/llvm/llvm-project/pull/74782 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[lldb] [clang] [llvm] [clang] Split out DebugOptions.def into its own top-level options group. (PR #75530)
@@ -1722,6 +1738,11 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, #include "clang/Driver/Options.inc" #undef CODEGEN_OPTION_WITH_MARSHALLING +#define DEBUG_OPTION_WITH_MARSHALLING(...) \ jansvoboda11 wrote: I'd expect this to go into separate `ParseDebugArgs()` function (which is declared in the header but not defined). https://github.com/llvm/llvm-project/pull/75530 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [lldb] [clang] [clang] Split out DebugOptions.def into its own top-level options group. (PR #75530)
@@ -224,19 +233,20 @@ class CompilerInvocation : public CompilerInvocationBase { /// @{ // Note: These need to be pulled in manually. Otherwise, they get hidden by // the mutable getters with the same names. - using CompilerInvocationBase::getLangOpts; - using CompilerInvocationBase::getTargetOpts; - using CompilerInvocationBase::getDiagnosticOpts; - using CompilerInvocationBase::getHeaderSearchOpts; - using CompilerInvocationBase::getPreprocessorOpts; using CompilerInvocationBase::getAnalyzerOpts; - using CompilerInvocationBase::getMigratorOpts; using CompilerInvocationBase::getAPINotesOpts; using CompilerInvocationBase::getCodeGenOpts; + using CompilerInvocationBase::getDebugOpts; jansvoboda11 wrote: Can you undo the reordering here? Let's just add the debug options into the right place and then optionally extract this change into a separate trivially NFC commit (and maybe reorder the member variables to match). https://github.com/llvm/llvm-project/pull/75530 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[lldb] [clang] [llvm] [clang] Split out DebugOptions.def into its own top-level options group. (PR #75530)
@@ -11,6 +11,7 @@ #include "clang/APINotes/APINotesOptions.h" #include "clang/Basic/CodeGenOptions.h" +#include "clang/Basic/DebugOptions.h" jansvoboda11 wrote: Wouldn't a forward declaration be enough in this case? https://github.com/llvm/llvm-project/pull/75530 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [lldb] [clang] Split out DebugOptions.def into its own top-level options group. (PR #75530)
@@ -11,46 +11,13 @@ namespace clang { -CodeGenOptions::CodeGenOptions() { -#define CODEGENOPT(Name, Bits, Default) Name = Default; -#define ENUM_CODEGENOPT(Name, Type, Bits, Default) set##Name(Default); -#include "clang/Basic/CodeGenOptions.def" +CodeGenOptions::CodeGenOptions() { resetNonModularOptions(); } jansvoboda11 wrote: I find this confusing: why are we resetting only the non-modular options here? I'd expect all options to be set to default here. Maybe create extra helper function `resetAllOptions()` that will call to `resetNonModularOptions()` and explain how modular options are handled? https://github.com/llvm/llvm-project/pull/75530 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [llvm] [clang] Split out DebugOptions.def into its own top-level options group. (PR #75530)
https://github.com/jansvoboda11 requested changes to this pull request. This looks pretty nice, I left just a couple of notes. You might want to take a look at the CI failures. https://github.com/llvm/llvm-project/pull/75530 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [lldb] [clang] Split out DebugOptions.def into its own top-level options group. (PR #75530)
https://github.com/jansvoboda11 edited https://github.com/llvm/llvm-project/pull/75530 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [libc] [flang] [compiler-rt] [llvm] [libcxx] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { bwendling wrote: I should say that I'm not *certain* that `ptr->arr` in the middle case will see `struct A` as its most-enclosing struct. I need to check on it. https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] [clang] [clang-tools-extra] [llvm] [compiler-rt] [flang] [libc] Don't emit relax relocs like R_X86_64_REX_GOTPCRELX on X86 target for OPENMP internal vars. (PR #75564)
efriedma-quic wrote: Scattering around `setDSOLocal(false)` makes the logic hard to understand. I'd strongly prefer to fix the initial setting of dso_local when we create the global variable. We can refactor the code to make that work. https://github.com/llvm/llvm-project/pull/75564 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [AMDGPU] Adding the amdgpu-num-work-groups function attribute (PR #75647)
https://github.com/jwanggit86 updated https://github.com/llvm/llvm-project/pull/75647 >From bb15eebae9645e5383f26066093c0734ea76442d Mon Sep 17 00:00:00 2001 From: Jun Wang Date: Fri, 15 Dec 2023 13:53:54 -0600 Subject: [PATCH 1/2] [AMDGPU] Adding the amdgpu-num-work-groups function attribute A new function attribute named amdgpu-num-work-groups is added. This attribute allows programmers to let the compiler know the number of workgroups to be launched and do optimizations based on that information. --- clang/include/clang/Basic/Attr.td | 7 ++ clang/include/clang/Basic/AttrDocs.td | 23 ++ clang/lib/CodeGen/Targets/AMDGPU.cpp | 7 ++ clang/lib/Sema/SemaDeclAttr.cpp | 13 +++ ...a-attribute-supported-attributes-list.test | 1 + .../AMDGPU/AMDGPUHSAMetadataStreamer.cpp | 4 + llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp| 6 ++ llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h | 3 + .../Target/AMDGPU/SIMachineFunctionInfo.cpp | 1 + .../lib/Target/AMDGPU/SIMachineFunctionInfo.h | 9 ++ .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp| 15 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h | 8 ++ .../AMDGPU/attr-amdgpu-num-work-groups.ll | 82 +++ 13 files changed, 179 insertions(+) create mode 100644 llvm/test/CodeGen/AMDGPU/attr-amdgpu-num-work-groups.ll diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 5943583d92773a..605fcbbff027b9 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -2011,6 +2011,13 @@ def AMDGPUNumVGPR : InheritableAttr { let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">; } +def AMDGPUNumWorkGroups : InheritableAttr { + let Spellings = [Clang<"amdgpu_num_work_groups", 0>]; + let Args = [UnsignedArgument<"NumWorkGroups">]; + let Documentation = [AMDGPUNumWorkGroupsDocs]; + let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">; +} + def AMDGPUKernelCall : DeclOrTypeAttr { let Spellings = [Clang<"amdgpu_kernel">]; let Documentation = [Undocumented]; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 77950ab6d877ea..0bf3ccf367284c 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -2693,6 +2693,29 @@ An error will be given if: }]; } +def AMDGPUNumWorkGroupsDocs : Documentation { + let Category = DocCatAMDGPUAttributes; + let Content = [{ +The number of work groups specifies the number of work groups when the kernel +is dispatched. + +Clang supports the +``__attribute__((amdgpu_num_work_groups()))`` attribute for the +AMDGPU target. This attribute may be attached to a kernel function definition +and is an optimization hint. + + parameter specifies the number of work groups. + +If specified, the AMDGPU target backend might be able to produce better machine +code. + +An error will be given if: + - Specified values violate subtarget specifications; + - Specified values are not compatible with values provided through other +attributes. + }]; +} + def DocCatCallingConvs : DocumentationCategory<"Calling Conventions"> { let Content = [{ Clang supports several different calling conventions, depending on the target diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp b/clang/lib/CodeGen/Targets/AMDGPU.cpp index 03ac6b78598fc8..11a0835f37f4a9 100644 --- a/clang/lib/CodeGen/Targets/AMDGPU.cpp +++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp @@ -356,6 +356,13 @@ void AMDGPUTargetCodeGenInfo::setFunctionDeclAttributes( if (NumVGPR != 0) F->addFnAttr("amdgpu-num-vgpr", llvm::utostr(NumVGPR)); } + + if (const auto *Attr = FD->getAttr()) { +uint32_t NumWG = Attr->getNumWorkGroups(); + +if (NumWG != 0) + F->addFnAttr("amdgpu-num-work-groups", llvm::utostr(NumWG)); + } } /// Emits control constants used to change per-architecture behaviour in the diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 5b29b05dee54b3..3737dd256aff02 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -8051,6 +8051,16 @@ static void handleAMDGPUNumVGPRAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) AMDGPUNumVGPRAttr(S.Context, AL, NumVGPR)); } +static void handleAMDGPUNumWorkGroupsAttr(Sema &S, Decl *D, + const ParsedAttr &AL) { + uint32_t NumWG = 0; + Expr *NumWGExpr = AL.getArgAsExpr(0); + if (!checkUInt32Argument(S, AL, NumWGExpr, NumWG)) +return; + + D->addAttr(::new (S.Context) AMDGPUNumWorkGroupsAttr(S.Context, AL, NumWG)); +} + static void handleX86ForceAlignArgPointerAttr(Sema &S, Decl *D, const ParsedAttr &AL) { // If we try to apply it to a function pointer, don't warn, but don't @@ -9058,6 +9068,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const Parsed
[flang] [clang] [flang][nfc] Refactor linker invocation logic (PR #75534)
banach-space wrote: Updated version: https://github.com/llvm/llvm-project/pull/75648 https://github.com/llvm/llvm-project/pull/75534 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang][nfc] Refactor linker invocation logic (PR #75648)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Andrzej Warzyński (banach-space) Changes Refactor how the Fortran runtime libs are added to the linker invocation. This is a non-functional change. This is an updated version of #75534. This iteration makes sure that FortranMain.a comes before FortranRuntme.a (the former depends on the latter). --- Full diff: https://github.com/llvm/llvm-project/pull/75648.diff 1 Files Affected: - (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+82-63) ``diff diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 3d1df58190ce05..45901ee7157f77 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1116,72 +1116,91 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC, return true; } -void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args, - llvm::opt::ArgStringList &CmdArgs) { - // These are handled earlier on Windows by telling the frontend driver to add - // the correct libraries to link against as dependents in the object file. - - // if -fno-fortran-main has been passed, skip linking Fortran_main.a - bool LinkFortranMain = !Args.hasArg(options::OPT_no_fortran_main); - if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) { -if (LinkFortranMain) { - // The --whole-archive option needs to be part of the link line to - // make sure that the main() function from Fortran_main.a is pulled - // in by the linker. Determine if --whole-archive is active when - // flang will try to link Fortran_main.a. If it is, don't add the - // --whole-archive flag to the link line. If it's not, add a proper - // --whole-archive/--no-whole-archive bracket to the link line. - bool WholeArchiveActive = false; - for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA)) { -if (Arg) { - for (StringRef ArgValue : Arg->getValues()) { -if (ArgValue == "--whole-archive") - WholeArchiveActive = true; -if (ArgValue == "--no-whole-archive") - WholeArchiveActive = false; - } -} +/// Determines if --whole-archive is active in the list of arguments. +static bool isWholeArchivePresent(const ArgList &Args) { + bool WholeArchiveActive = false; + for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA)) { +if (Arg) { + for (StringRef ArgValue : Arg->getValues()) { +if (ArgValue == "--whole-archive") + WholeArchiveActive = true; +if (ArgValue == "--no-whole-archive") + WholeArchiveActive = false; } +} + } - // TODO: Find an equivalent of `--whole-archive` for Darwin. - if (!WholeArchiveActive && !TC.getTriple().isMacOSX()) { -CmdArgs.push_back("--whole-archive"); -CmdArgs.push_back("-lFortran_main"); -CmdArgs.push_back("--no-whole-archive"); - } else { -CmdArgs.push_back("-lFortran_main"); - } + return WholeArchiveActive; +} - // Perform regular linkage of the remaining runtime libraries. - CmdArgs.push_back("-lFortranRuntime"); - CmdArgs.push_back("-lFortranDecimal"); -} - } else { -if (LinkFortranMain) { - unsigned RTOptionID = options::OPT__SLASH_MT; - if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) { -RTOptionID = llvm::StringSwitch(rtl->getValue()) - .Case("static", options::OPT__SLASH_MT) - .Case("static_dbg", options::OPT__SLASH_MTd) - .Case("dll", options::OPT__SLASH_MD) - .Case("dll_dbg", options::OPT__SLASH_MDd) - .Default(options::OPT__SLASH_MT); - } - switch (RTOptionID) { - case options::OPT__SLASH_MT: -CmdArgs.push_back("/WHOLEARCHIVE:Fortran_main.static.lib"); -break; - case options::OPT__SLASH_MTd: -CmdArgs.push_back("/WHOLEARCHIVE:Fortran_main.static_dbg.lib"); -break; - case options::OPT__SLASH_MD: -CmdArgs.push_back("/WHOLEARCHIVE:Fortran_main.dynamic.lib"); -break; - case options::OPT__SLASH_MDd: -CmdArgs.push_back("/WHOLEARCHIVE:Fortran_main.dynamic_dbg.lib"); -break; - } -} +/// Add Fortran runtime libs for MSVC +static void addFortranRuntimeLibsMSVC(const ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) { + unsigned RTOptionID = options::OPT__SLASH_MT; + if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) { +RTOptionID = llvm::StringSwitch(rtl->getValue()) + .Case("static", options::OPT__SLASH_MT) + .Case("static_dbg", options::OPT__SLASH_MTd) + .Case("dll", options::OPT__SLASH_MD) + .Case("dll_dbg", options::OPT__SLASH_
[clang] [flang][nfc] Refactor linker invocation logic (PR #75648)
https://github.com/banach-space created https://github.com/llvm/llvm-project/pull/75648 Refactor how the Fortran runtime libs are added to the linker invocation. This is a non-functional change. This is an updated version of #75534. This iteration makes sure that FortranMain.a comes before FortranRuntme.a (the former depends on the latter). From 40d3a899ea1b326ef407323cf82eba35016c36d4 Mon Sep 17 00:00:00 2001 From: Andrzej Warzynski Date: Thu, 14 Dec 2023 21:34:11 + Subject: [PATCH] [flang][nfc] Refactor linker invocation logic Refactor how the Fortran runtime libs are added to the linker invocation. This is a non-functional change. This is an updated version of #75534. This iteration makes sure that FortranMain.a comes before FortranRuntme.a (the former depends on the latter). --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 145 - 1 file changed, 82 insertions(+), 63 deletions(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 3d1df58190ce05..45901ee7157f77 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1116,72 +1116,91 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC, return true; } -void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args, - llvm::opt::ArgStringList &CmdArgs) { - // These are handled earlier on Windows by telling the frontend driver to add - // the correct libraries to link against as dependents in the object file. - - // if -fno-fortran-main has been passed, skip linking Fortran_main.a - bool LinkFortranMain = !Args.hasArg(options::OPT_no_fortran_main); - if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) { -if (LinkFortranMain) { - // The --whole-archive option needs to be part of the link line to - // make sure that the main() function from Fortran_main.a is pulled - // in by the linker. Determine if --whole-archive is active when - // flang will try to link Fortran_main.a. If it is, don't add the - // --whole-archive flag to the link line. If it's not, add a proper - // --whole-archive/--no-whole-archive bracket to the link line. - bool WholeArchiveActive = false; - for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA)) { -if (Arg) { - for (StringRef ArgValue : Arg->getValues()) { -if (ArgValue == "--whole-archive") - WholeArchiveActive = true; -if (ArgValue == "--no-whole-archive") - WholeArchiveActive = false; - } -} +/// Determines if --whole-archive is active in the list of arguments. +static bool isWholeArchivePresent(const ArgList &Args) { + bool WholeArchiveActive = false; + for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA)) { +if (Arg) { + for (StringRef ArgValue : Arg->getValues()) { +if (ArgValue == "--whole-archive") + WholeArchiveActive = true; +if (ArgValue == "--no-whole-archive") + WholeArchiveActive = false; } +} + } - // TODO: Find an equivalent of `--whole-archive` for Darwin. - if (!WholeArchiveActive && !TC.getTriple().isMacOSX()) { -CmdArgs.push_back("--whole-archive"); -CmdArgs.push_back("-lFortran_main"); -CmdArgs.push_back("--no-whole-archive"); - } else { -CmdArgs.push_back("-lFortran_main"); - } + return WholeArchiveActive; +} - // Perform regular linkage of the remaining runtime libraries. - CmdArgs.push_back("-lFortranRuntime"); - CmdArgs.push_back("-lFortranDecimal"); -} - } else { -if (LinkFortranMain) { - unsigned RTOptionID = options::OPT__SLASH_MT; - if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) { -RTOptionID = llvm::StringSwitch(rtl->getValue()) - .Case("static", options::OPT__SLASH_MT) - .Case("static_dbg", options::OPT__SLASH_MTd) - .Case("dll", options::OPT__SLASH_MD) - .Case("dll_dbg", options::OPT__SLASH_MDd) - .Default(options::OPT__SLASH_MT); - } - switch (RTOptionID) { - case options::OPT__SLASH_MT: -CmdArgs.push_back("/WHOLEARCHIVE:Fortran_main.static.lib"); -break; - case options::OPT__SLASH_MTd: -CmdArgs.push_back("/WHOLEARCHIVE:Fortran_main.static_dbg.lib"); -break; - case options::OPT__SLASH_MD: -CmdArgs.push_back("/WHOLEARCHIVE:Fortran_main.dynamic.lib"); -break; - case options::OPT__SLASH_MDd: -CmdArgs.push_back("/WHOLEARCHIVE:Fortran_main.dynamic_dbg.lib"); -break; - } -} +/// Add Fortran runtime libs for MSVC +static void addFortranRuntimeLibsMSVC(const ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) { + unsigned RTOption
[llvm] [libcxx] [clang-tools-extra] [compiler-rt] [clang] [flang] [libc] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); + auto *Idx = EmitIdxAfterBase(/*Promote*/true); +if (SanOpts.has(SanitizerKind::ArrayBounds)) { bwendling wrote: I have checks in place to make sure that I can find the correct enclosing type. For instance, if I have something like: ``` struct B { int count; int arr[] __counted_by(count); }; struct A { int count; struct B *b; }; ``` when looking at `someA->b->arr[idx]`, it only cares about looking at the `count` in `struct B`. The `count` in `struct A` won't be seen. This is because we're looking for the most-enclosing struct of `arr`, which is `struct B`. Now if I have something like: ``` struct A { int count; struct B { int count; int arr[] __counted_by(count); } *ptr; }; ``` This could get hairy, because it might not see the `count` in `struct B`. BUT if it's not a pointer: ``` struct A { int count; struct B { int count; int arr[] __counted_by(count); } z; }; ``` Then I *do* want it to reference the `count` in `struct A`. Hilarious, I know! :-) The "pointer" example should work exactly as if `struct B` was defined outside of `struct A`. I'll need to make sure to document that very carefully. As for other `-fbounds-safety` checks, I haven't seen any that do quite what we're doing here. When I looked through the attributes, few of them seemed to reference other fields within structures, or even external variables. (I know some exist, but they're not quite the same as what we're doing here.) Then again, I may quite well have not noticed one of the bounds safety code paths. https://github.com/llvm/llvm-project/pull/73730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [AMDGPU] Adding the amdgpu-num-work-groups function attribute (PR #75647)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 7bc6c4abe8e8d8ab70e02e4c2025a94dda01d908 bb15eebae9645e5383f26066093c0734ea76442d -- clang/lib/CodeGen/Targets/AMDGPU.cpp clang/lib/Sema/SemaDeclAttr.cpp llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h `` View the diff from clang-format here. ``diff diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp index d7f5c45670..d69a78d366 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp @@ -,6 +,6 @@ unsigned GCNUserSGPRUsageInfo::getNumFreeUserSGPRs() { unsigned AMDGPUSubtarget::getNumWorkGroups(const Function &F) const { const unsigned Default = 0; - return AMDGPU::getUnsignedIntegerAttribute(F, "amdgpu-num-work-groups", Default); + return AMDGPU::getUnsignedIntegerAttribute(F, "amdgpu-num-work-groups", + Default); } - diff --git a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h index fc244552f4..1ab6d2bca9 100644 --- a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h +++ b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h @@ -1099,10 +1099,7 @@ public: bool usesAGPRs(const MachineFunction &MF) const; /// \returns Default/requested number of work groups for this function. - unsigned getNumWorkGroups() const { -return NumWorkGroups; - } - + unsigned getNumWorkGroups() const { return NumWorkGroups; } }; } // end namespace llvm diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp index 82e3bca7ab..1a763120e0 100644 --- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp +++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp @@ -1221,7 +1221,8 @@ getIntegerPairAttribute(const Function &F, StringRef Name, return Ints; } -unsigned getUnsignedIntegerAttribute(const Function &F, StringRef Name, unsigned Default) { +unsigned getUnsignedIntegerAttribute(const Function &F, StringRef Name, + unsigned Default) { Attribute A = F.getFnAttribute(Name); if (!A.isStringAttribute()) return Default; diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h index c54c1638fa..f395384a2e 100644 --- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h +++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h @@ -824,7 +824,8 @@ int getIntegerAttribute(const Function &F, StringRef Name, int Default); /// /// \returns \p Default and emits error if requested value cannot be converted /// to integer. -unsigned getUnsignedIntegerAttribute(const Function &F, StringRef Name, unsigned Default); +unsigned getUnsignedIntegerAttribute(const Function &F, StringRef Name, + unsigned Default); /// \returns A pair of integer values requested using \p F's \p Name attribute /// in "first[,second]" format ("second" is optional unless \p OnlyFirstRequired `` https://github.com/llvm/llvm-project/pull/75647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Adding the amdgpu-num-work-groups function attribute (PR #75647)
llvmbot wrote: @llvm/pr-subscribers-backend-amdgpu Author: Jun Wang (jwanggit86) Changes A new function attribute named amdgpu-num-work-groups is added. This attribute allows programmers to let the compiler know the number of workgroups to be launched and do optimizations based on that information. --- Full diff: https://github.com/llvm/llvm-project/pull/75647.diff 13 Files Affected: - (modified) clang/include/clang/Basic/Attr.td (+7) - (modified) clang/include/clang/Basic/AttrDocs.td (+23) - (modified) clang/lib/CodeGen/Targets/AMDGPU.cpp (+7) - (modified) clang/lib/Sema/SemaDeclAttr.cpp (+13) - (modified) clang/test/Misc/pragma-attribute-supported-attributes-list.test (+1) - (modified) llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp (+4) - (modified) llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp (+6) - (modified) llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h (+3) - (modified) llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp (+1) - (modified) llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h (+9) - (modified) llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp (+15) - (modified) llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h (+8) - (added) llvm/test/CodeGen/AMDGPU/attr-amdgpu-num-work-groups.ll (+82) ``diff diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 5943583d92773a..605fcbbff027b9 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -2011,6 +2011,13 @@ def AMDGPUNumVGPR : InheritableAttr { let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">; } +def AMDGPUNumWorkGroups : InheritableAttr { + let Spellings = [Clang<"amdgpu_num_work_groups", 0>]; + let Args = [UnsignedArgument<"NumWorkGroups">]; + let Documentation = [AMDGPUNumWorkGroupsDocs]; + let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">; +} + def AMDGPUKernelCall : DeclOrTypeAttr { let Spellings = [Clang<"amdgpu_kernel">]; let Documentation = [Undocumented]; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 77950ab6d877ea..0bf3ccf367284c 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -2693,6 +2693,29 @@ An error will be given if: }]; } +def AMDGPUNumWorkGroupsDocs : Documentation { + let Category = DocCatAMDGPUAttributes; + let Content = [{ +The number of work groups specifies the number of work groups when the kernel +is dispatched. + +Clang supports the +``__attribute__((amdgpu_num_work_groups()))`` attribute for the +AMDGPU target. This attribute may be attached to a kernel function definition +and is an optimization hint. + + parameter specifies the number of work groups. + +If specified, the AMDGPU target backend might be able to produce better machine +code. + +An error will be given if: + - Specified values violate subtarget specifications; + - Specified values are not compatible with values provided through other +attributes. + }]; +} + def DocCatCallingConvs : DocumentationCategory<"Calling Conventions"> { let Content = [{ Clang supports several different calling conventions, depending on the target diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp b/clang/lib/CodeGen/Targets/AMDGPU.cpp index 03ac6b78598fc8..11a0835f37f4a9 100644 --- a/clang/lib/CodeGen/Targets/AMDGPU.cpp +++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp @@ -356,6 +356,13 @@ void AMDGPUTargetCodeGenInfo::setFunctionDeclAttributes( if (NumVGPR != 0) F->addFnAttr("amdgpu-num-vgpr", llvm::utostr(NumVGPR)); } + + if (const auto *Attr = FD->getAttr()) { +uint32_t NumWG = Attr->getNumWorkGroups(); + +if (NumWG != 0) + F->addFnAttr("amdgpu-num-work-groups", llvm::utostr(NumWG)); + } } /// Emits control constants used to change per-architecture behaviour in the diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 5b29b05dee54b3..3737dd256aff02 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -8051,6 +8051,16 @@ static void handleAMDGPUNumVGPRAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) AMDGPUNumVGPRAttr(S.Context, AL, NumVGPR)); } +static void handleAMDGPUNumWorkGroupsAttr(Sema &S, Decl *D, + const ParsedAttr &AL) { + uint32_t NumWG = 0; + Expr *NumWGExpr = AL.getArgAsExpr(0); + if (!checkUInt32Argument(S, AL, NumWGExpr, NumWG)) +return; + + D->addAttr(::new (S.Context) AMDGPUNumWorkGroupsAttr(S.Context, AL, NumWG)); +} + static void handleX86ForceAlignArgPointerAttr(Sema &S, Decl *D, const ParsedAttr &AL) { // If we try to apply it to a function pointer, don't warn, but don't @@ -9058,6 +9068,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL, case ParsedAttr::AT_AMDGPUNumVGPR: handleAMDGPUNumVGPRAttr(S, D, AL); break; + case
[clang] [llvm] [AMDGPU] Adding the amdgpu-num-work-groups function attribute (PR #75647)
https://github.com/jwanggit86 created https://github.com/llvm/llvm-project/pull/75647 A new function attribute named amdgpu-num-work-groups is added. This attribute allows programmers to let the compiler know the number of workgroups to be launched and do optimizations based on that information. >From bb15eebae9645e5383f26066093c0734ea76442d Mon Sep 17 00:00:00 2001 From: Jun Wang Date: Fri, 15 Dec 2023 13:53:54 -0600 Subject: [PATCH] [AMDGPU] Adding the amdgpu-num-work-groups function attribute A new function attribute named amdgpu-num-work-groups is added. This attribute allows programmers to let the compiler know the number of workgroups to be launched and do optimizations based on that information. --- clang/include/clang/Basic/Attr.td | 7 ++ clang/include/clang/Basic/AttrDocs.td | 23 ++ clang/lib/CodeGen/Targets/AMDGPU.cpp | 7 ++ clang/lib/Sema/SemaDeclAttr.cpp | 13 +++ ...a-attribute-supported-attributes-list.test | 1 + .../AMDGPU/AMDGPUHSAMetadataStreamer.cpp | 4 + llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp| 6 ++ llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h | 3 + .../Target/AMDGPU/SIMachineFunctionInfo.cpp | 1 + .../lib/Target/AMDGPU/SIMachineFunctionInfo.h | 9 ++ .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp| 15 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h | 8 ++ .../AMDGPU/attr-amdgpu-num-work-groups.ll | 82 +++ 13 files changed, 179 insertions(+) create mode 100644 llvm/test/CodeGen/AMDGPU/attr-amdgpu-num-work-groups.ll diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 5943583d92773a..605fcbbff027b9 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -2011,6 +2011,13 @@ def AMDGPUNumVGPR : InheritableAttr { let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">; } +def AMDGPUNumWorkGroups : InheritableAttr { + let Spellings = [Clang<"amdgpu_num_work_groups", 0>]; + let Args = [UnsignedArgument<"NumWorkGroups">]; + let Documentation = [AMDGPUNumWorkGroupsDocs]; + let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">; +} + def AMDGPUKernelCall : DeclOrTypeAttr { let Spellings = [Clang<"amdgpu_kernel">]; let Documentation = [Undocumented]; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 77950ab6d877ea..0bf3ccf367284c 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -2693,6 +2693,29 @@ An error will be given if: }]; } +def AMDGPUNumWorkGroupsDocs : Documentation { + let Category = DocCatAMDGPUAttributes; + let Content = [{ +The number of work groups specifies the number of work groups when the kernel +is dispatched. + +Clang supports the +``__attribute__((amdgpu_num_work_groups()))`` attribute for the +AMDGPU target. This attribute may be attached to a kernel function definition +and is an optimization hint. + + parameter specifies the number of work groups. + +If specified, the AMDGPU target backend might be able to produce better machine +code. + +An error will be given if: + - Specified values violate subtarget specifications; + - Specified values are not compatible with values provided through other +attributes. + }]; +} + def DocCatCallingConvs : DocumentationCategory<"Calling Conventions"> { let Content = [{ Clang supports several different calling conventions, depending on the target diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp b/clang/lib/CodeGen/Targets/AMDGPU.cpp index 03ac6b78598fc8..11a0835f37f4a9 100644 --- a/clang/lib/CodeGen/Targets/AMDGPU.cpp +++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp @@ -356,6 +356,13 @@ void AMDGPUTargetCodeGenInfo::setFunctionDeclAttributes( if (NumVGPR != 0) F->addFnAttr("amdgpu-num-vgpr", llvm::utostr(NumVGPR)); } + + if (const auto *Attr = FD->getAttr()) { +uint32_t NumWG = Attr->getNumWorkGroups(); + +if (NumWG != 0) + F->addFnAttr("amdgpu-num-work-groups", llvm::utostr(NumWG)); + } } /// Emits control constants used to change per-architecture behaviour in the diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 5b29b05dee54b3..3737dd256aff02 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -8051,6 +8051,16 @@ static void handleAMDGPUNumVGPRAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) AMDGPUNumVGPRAttr(S.Context, AL, NumVGPR)); } +static void handleAMDGPUNumWorkGroupsAttr(Sema &S, Decl *D, + const ParsedAttr &AL) { + uint32_t NumWG = 0; + Expr *NumWGExpr = AL.getArgAsExpr(0); + if (!checkUInt32Argument(S, AL, NumWGExpr, NumWG)) +return; + + D->addAttr(::new (S.Context) AMDGPUNumWorkGroupsAttr(S.Context, AL, NumWG)); +} + static void handleX86ForceAlignArgPointerAttr(Sema &S, Decl *D,