[clang] [llvm] [AArch64] Enable FEAT_SVE2p1 by default for Armv9.4-A and later (PR #120753)
https://github.com/tmatheson-arm approved this pull request. Makes sense to me. https://github.com/llvm/llvm-project/pull/120753 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Enable FEAT_SVE2p1 by default for Armv9.4-A and later (PR #120753)
https://github.com/jthackray updated https://github.com/llvm/llvm-project/pull/120753 >From 519bcca2359ee9c89b12bac6e58eb955c79cd7bc Mon Sep 17 00:00:00 2001 From: Jonathan Thackray Date: Fri, 20 Dec 2024 14:50:37 + Subject: [PATCH 1/2] [AArch64] Enable FEAT_SVE2p1 by default for Armv9.4-A and later. The ArmARM says: ``` "In an Armv9.4 implementation, if FEAT_SVE2 is implemented, FEAT_SVE2p1 is implemented." ``` Since FEAT_SVE2 is already enabled for Armv9.0-A and later, then FEAT_SVE2p1 should also be enabled by default. --- clang/test/Driver/print-enabled-extensions/aarch64-armv9.4-a.c | 1 + clang/test/Driver/print-enabled-extensions/aarch64-armv9.5-a.c | 1 + llvm/lib/Target/AArch64/AArch64Features.td | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/test/Driver/print-enabled-extensions/aarch64-armv9.4-a.c b/clang/test/Driver/print-enabled-extensions/aarch64-armv9.4-a.c index 0032c926c22d96..1cfda6c996b9e3 100644 --- a/clang/test/Driver/print-enabled-extensions/aarch64-armv9.4-a.c +++ b/clang/test/Driver/print-enabled-extensions/aarch64-armv9.4-a.c @@ -58,6 +58,7 @@ // CHECK-NEXT: FEAT_SSBS, FEAT_SSBS2 Enable Speculative Store Bypass Safe bit // CHECK-NEXT: FEAT_SVE Enable Scalable Vector Extension (SVE) instructions // CHECK-NEXT: FEAT_SVE2 Enable Scalable Vector Extension 2 (SVE2) instructions +// CHECK-NEXT: FEAT_SVE2p1 Enable Scalable Vector Extension 2.1 instructions // CHECK-NEXT: FEAT_TLBIOS, FEAT_TLBIRANGE Enable Armv8.4-A TLB Range and Maintenance instructions // CHECK-NEXT: FEAT_TRBE Enable Trace Buffer Extension // CHECK-NEXT: FEAT_TRF Enable Armv8.4-A Trace extension diff --git a/clang/test/Driver/print-enabled-extensions/aarch64-armv9.5-a.c b/clang/test/Driver/print-enabled-extensions/aarch64-armv9.5-a.c index be24bd0bbddb68..76c8b34a56b75b 100644 --- a/clang/test/Driver/print-enabled-extensions/aarch64-armv9.5-a.c +++ b/clang/test/Driver/print-enabled-extensions/aarch64-armv9.5-a.c @@ -61,6 +61,7 @@ // CHECK-NEXT: FEAT_SSBS, FEAT_SSBS2 Enable Speculative Store Bypass Safe bit // CHECK-NEXT: FEAT_SVE Enable Scalable Vector Extension (SVE) instructions // CHECK-NEXT: FEAT_SVE2 Enable Scalable Vector Extension 2 (SVE2) instructions +// CHECK-NEXT: FEAT_SVE2p1 Enable Scalable Vector Extension 2.1 instructions // CHECK-NEXT: FEAT_TLBIOS, FEAT_TLBIRANGE Enable Armv8.4-A TLB Range and Maintenance instructions // CHECK-NEXT: FEAT_TRBE Enable Trace Buffer Extension // CHECK-NEXT: FEAT_TRF Enable Armv8.4-A Trace extension diff --git a/llvm/lib/Target/AArch64/AArch64Features.td b/llvm/lib/Target/AArch64/AArch64Features.td index 3a6bef81f4a0d8..96473e55f01d8e 100644 --- a/llvm/lib/Target/AArch64/AArch64Features.td +++ b/llvm/lib/Target/AArch64/AArch64Features.td @@ -872,7 +872,7 @@ def HasV9_3aOps : Architecture64<9, 3, "a", "v9.3a", [HasV8_8aOps, HasV9_2aOps], !listconcat(HasV9_2aOps.DefaultExts, [FeatureMOPS, FeatureHBC])>; def HasV9_4aOps : Architecture64<9, 4, "a", "v9.4a", - [HasV8_9aOps, HasV9_3aOps], + [HasV8_9aOps, HasV9_3aOps, FeatureSVE2p1], !listconcat(HasV9_3aOps.DefaultExts, [FeatureSPECRES2, FeatureCSSC, FeatureRASv2])>; def HasV9_5aOps : Architecture64<9, 5, "a", "v9.5a", >From 15a2f3922bec4ccc6472f3eb2029c66f9ef6d834 Mon Sep 17 00:00:00 2001 From: Jonathan Thackray Date: Fri, 20 Dec 2024 16:13:53 + Subject: [PATCH 2/2] fixup! [AArch64] Enable FEAT_SVE2p1 by default for Armv9.4-A and later. --- llvm/lib/Target/AArch64/AArch64Features.td | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/AArch64/AArch64Features.td b/llvm/lib/Target/AArch64/AArch64Features.td index 96473e55f01d8e..41eb9a73bd013d 100644 --- a/llvm/lib/Target/AArch64/AArch64Features.td +++ b/llvm/lib/Target/AArch64/AArch64Features.td @@ -872,9 +872,9 @@ def HasV9_3aOps : Architecture64<9, 3, "a", "v9.3a", [HasV8_8aOps, HasV9_2aOps], !listconcat(HasV9_2aOps.DefaultExts, [FeatureMOPS, FeatureHBC])>; def HasV9_4aOps : Architecture64<9, 4, "a", "v9.4a", - [HasV8_9aOps, HasV9_3aOps, FeatureSVE2p1], + [HasV8_9aOps, HasV9_3aOps], !listconcat(HasV9_3aOps.DefaultExts, [FeatureSPECRES2, FeatureCSSC, -FeatureRASv2])>; +FeatureRASv2, FeatureSVE2p1])>; def HasV9_5aOps : Architecture64<9, 5, "a", "v9.5a", [HasV9_4aOps, FeatureCPA], !listco
[clang] [llvm] [AArch64] Enable FEAT_SVE2p1 by default for Armv9.4-A and later (PR #120753)
tmatheson-arm wrote: Actually this is being added as a mandatory dependency of 9.4, should it not be added as one of the default features instead? https://github.com/llvm/llvm-project/pull/120753 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Codegen for `cbuffer` declarations without embedded arrays or structs (PR #119755)
https://github.com/llvm-beanz requested changes to this pull request. https://github.com/llvm/llvm-project/pull/119755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Codegen for `cbuffer` declarations without embedded arrays or structs (PR #119755)
@@ -54,78 +54,108 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) { auto *DXILValMD = M.getOrInsertNamedMetadata(DXILValKey); DXILValMD->addOperand(Val); } + void addDisableOptimizations(llvm::Module &M) { StringRef Key = "dx.disable_optimizations"; M.addModuleFlag(llvm::Module::ModFlagBehavior::Override, Key, 1); } -// cbuffer will be translated into global variable in special address space. -// If translate into C, -// cbuffer A { -// float a; -// float b; -// } -// float foo() { return a + b; } + +// Creates resource handle representing the constant buffer. +// For cbuffer declaration: // -// will be translated into +// cbuffer MyConstants { +// float a; +// } // -// struct A { -// float a; -// float b; -// } cbuffer_A __attribute__((address_space(4))); -// float foo() { return cbuffer_A.a + cbuffer_A.b; } +// creates a structure type MyConstants and then returns the resource handle +// that would be spelled as: // -// layoutBuffer will create the struct A type. -// replaceBuffer will replace use of global variable a and b with cbuffer_A.a -// and cbuffer_A.b. +// __hlsl_resource_t [[hlsl::resource_class(CBuffer)]] +// [[contained_type(MyConstants)]] // -void layoutBuffer(CGHLSLRuntime::Buffer &Buf, const DataLayout &DL) { - if (Buf.Constants.empty()) -return; - - std::vector EltTys; - for (auto &Const : Buf.Constants) { -GlobalVariable *GV = Const.first; -Const.second = EltTys.size(); -llvm::Type *Ty = GV->getValueType(); -EltTys.emplace_back(Ty); +static const clang::Type *getBufferHandleType(CGHLSLRuntime::Buffer &Buf) { + HLSLBufferDecl *BD = Buf.Decl; + ASTContext &AST = BD->getASTContext(); + + // create struct type for the constant buffer; filter out any declarations + // that are not a VarDecls or that are static + CXXRecordDecl *StructDecl = CXXRecordDecl::Create( + BD->getASTContext(), TagDecl::TagKind::Class, BD->getDeclContext(), + BD->getLocation(), BD->getLocation(), BD->getIdentifier()); + StructDecl->startDefinition(); + for (Decl *it : Buf.Decl->decls()) { +const VarDecl *VD = dyn_cast(it); +if (!VD || VD->getStorageClass() == SC_Static) + continue; +auto *Field = FieldDecl::Create( +AST, StructDecl, VD->getLocation(), VD->getLocation(), +VD->getIdentifier(), VD->getType(), VD->getTypeSourceInfo(), nullptr, +false, InClassInitStyle::ICIS_NoInit); +Field->setAccess(AccessSpecifier::AS_private); +StructDecl->addDecl(Field); } - Buf.LayoutStruct = llvm::StructType::get(EltTys[0]->getContext(), EltTys); + StructDecl->completeDefinition(); + assert(!StructDecl->fields().empty() && "empty cbuffer should not get here"); + + // create the resource handle type + HLSLAttributedResourceType::Attributes ResAttrs(dxil::ResourceClass::CBuffer, + false, false); + QualType ContainedTy = QualType(StructDecl->getTypeForDecl(), 0); + return AST + .getHLSLAttributedResourceType(AST.HLSLResourceTy, ContainedTy, ResAttrs) + .getTypePtr(); } -GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) { - // Create global variable for CB. - GlobalVariable *CBGV = new GlobalVariable( - Buf.LayoutStruct, /*isConstant*/ true, - GlobalValue::LinkageTypes::ExternalLinkage, nullptr, - llvm::formatv("{0}{1}", Buf.Name, Buf.IsCBuffer ? ".cb." : ".tb."), - GlobalValue::NotThreadLocal); - - IRBuilder<> B(CBGV->getContext()); - Value *ZeroIdx = B.getInt32(0); - // Replace Const use with CB use. - for (auto &[GV, Offset] : Buf.Constants) { -Value *GEP = -B.CreateGEP(Buf.LayoutStruct, CBGV, {ZeroIdx, B.getInt32(Offset)}); - -assert(Buf.LayoutStruct->getElementType(Offset) == GV->getValueType() && - "constant type mismatch"); - -// Replace. -GV->replaceAllUsesWith(GEP); -// Erase GV. -GV->removeDeadConstantUsers(); -GV->eraseFromParent(); +// Replaces all uses of the temporary constant buffer global variables with +// buffer access intrinsic resource.getpointer and GEP. +static void replaceBufferGlobals(CodeGenModule &CGM, + CGHLSLRuntime::Buffer &Buf) { + assert(Buf.IsCBuffer && "tbuffer codegen is not yet supported"); + + GlobalVariable *BufGV = Buf.GlobalVar; + llvm::Type *TargetTy = BufGV->getValueType(); + llvm::Type *BufStructTy = cast(TargetTy)->getTypeParameter(0); + unsigned Index = 0; + for (auto ConstIt = Buf.Constants.begin(); ConstIt != Buf.Constants.end(); + ++ConstIt, ++Index) { +GlobalVariable *ConstGV = *ConstIt; + +// TODO: Map to an hlsl_device address space. llvm-beanz wrote: ```suggestion // TODO: Map to an hlsl_device address space (#109877). ``` https://github.com/llvm/llvm-project/pull/119755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/m
[clang] [llvm] [AArch64] Enable FEAT_SVE2p1 by default for Armv9.4-A and later (PR #120753)
jthackray wrote: > Actually this is being added as a mandatory dependency of 9.4, should it not > be added as one of the default features instead? Good point. I'll amend. https://github.com/llvm/llvm-project/pull/120753 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Codegen for `cbuffer` declarations without embedded arrays or structs (PR #119755)
@@ -54,78 +54,108 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) { auto *DXILValMD = M.getOrInsertNamedMetadata(DXILValKey); DXILValMD->addOperand(Val); } + void addDisableOptimizations(llvm::Module &M) { StringRef Key = "dx.disable_optimizations"; M.addModuleFlag(llvm::Module::ModFlagBehavior::Override, Key, 1); } -// cbuffer will be translated into global variable in special address space. -// If translate into C, -// cbuffer A { -// float a; -// float b; -// } -// float foo() { return a + b; } + +// Creates resource handle representing the constant buffer. +// For cbuffer declaration: // -// will be translated into +// cbuffer MyConstants { +// float a; +// } // -// struct A { -// float a; -// float b; -// } cbuffer_A __attribute__((address_space(4))); -// float foo() { return cbuffer_A.a + cbuffer_A.b; } +// creates a structure type MyConstants and then returns the resource handle +// that would be spelled as: // -// layoutBuffer will create the struct A type. -// replaceBuffer will replace use of global variable a and b with cbuffer_A.a -// and cbuffer_A.b. +// __hlsl_resource_t [[hlsl::resource_class(CBuffer)]] +// [[contained_type(MyConstants)]] // -void layoutBuffer(CGHLSLRuntime::Buffer &Buf, const DataLayout &DL) { - if (Buf.Constants.empty()) -return; - - std::vector EltTys; - for (auto &Const : Buf.Constants) { -GlobalVariable *GV = Const.first; -Const.second = EltTys.size(); -llvm::Type *Ty = GV->getValueType(); -EltTys.emplace_back(Ty); +static const clang::Type *getBufferHandleType(CGHLSLRuntime::Buffer &Buf) { + HLSLBufferDecl *BD = Buf.Decl; + ASTContext &AST = BD->getASTContext(); + + // create struct type for the constant buffer; filter out any declarations + // that are not a VarDecls or that are static + CXXRecordDecl *StructDecl = CXXRecordDecl::Create( + BD->getASTContext(), TagDecl::TagKind::Class, BD->getDeclContext(), + BD->getLocation(), BD->getLocation(), BD->getIdentifier()); + StructDecl->startDefinition(); + for (Decl *it : Buf.Decl->decls()) { +const VarDecl *VD = dyn_cast(it); +if (!VD || VD->getStorageClass() == SC_Static) + continue; +auto *Field = FieldDecl::Create( +AST, StructDecl, VD->getLocation(), VD->getLocation(), +VD->getIdentifier(), VD->getType(), VD->getTypeSourceInfo(), nullptr, +false, InClassInitStyle::ICIS_NoInit); +Field->setAccess(AccessSpecifier::AS_private); +StructDecl->addDecl(Field); } - Buf.LayoutStruct = llvm::StructType::get(EltTys[0]->getContext(), EltTys); + StructDecl->completeDefinition(); + assert(!StructDecl->fields().empty() && "empty cbuffer should not get here"); + + // create the resource handle type + HLSLAttributedResourceType::Attributes ResAttrs(dxil::ResourceClass::CBuffer, + false, false); + QualType ContainedTy = QualType(StructDecl->getTypeForDecl(), 0); + return AST + .getHLSLAttributedResourceType(AST.HLSLResourceTy, ContainedTy, ResAttrs) + .getTypePtr(); } -GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) { - // Create global variable for CB. - GlobalVariable *CBGV = new GlobalVariable( - Buf.LayoutStruct, /*isConstant*/ true, - GlobalValue::LinkageTypes::ExternalLinkage, nullptr, - llvm::formatv("{0}{1}", Buf.Name, Buf.IsCBuffer ? ".cb." : ".tb."), - GlobalValue::NotThreadLocal); - - IRBuilder<> B(CBGV->getContext()); - Value *ZeroIdx = B.getInt32(0); - // Replace Const use with CB use. - for (auto &[GV, Offset] : Buf.Constants) { -Value *GEP = -B.CreateGEP(Buf.LayoutStruct, CBGV, {ZeroIdx, B.getInt32(Offset)}); - -assert(Buf.LayoutStruct->getElementType(Offset) == GV->getValueType() && - "constant type mismatch"); - -// Replace. -GV->replaceAllUsesWith(GEP); -// Erase GV. -GV->removeDeadConstantUsers(); -GV->eraseFromParent(); +// Replaces all uses of the temporary constant buffer global variables with +// buffer access intrinsic resource.getpointer and GEP. +static void replaceBufferGlobals(CodeGenModule &CGM, llvm-beanz wrote: This is a big no. This is falling into the mess that was CGHLSLMSFinishCodeGen in DXC. We should not be manipulating IR in Clang CodeGen. We should be able to inspect and dump the post-codegen IR, and test every IR transformation independently. https://github.com/llvm/llvm-project/pull/119755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Codegen for `cbuffer` declarations without embedded arrays or structs (PR #119755)
@@ -54,78 +54,108 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) { auto *DXILValMD = M.getOrInsertNamedMetadata(DXILValKey); DXILValMD->addOperand(Val); } + void addDisableOptimizations(llvm::Module &M) { StringRef Key = "dx.disable_optimizations"; M.addModuleFlag(llvm::Module::ModFlagBehavior::Override, Key, 1); } -// cbuffer will be translated into global variable in special address space. -// If translate into C, -// cbuffer A { -// float a; -// float b; -// } -// float foo() { return a + b; } + +// Creates resource handle representing the constant buffer. +// For cbuffer declaration: // -// will be translated into +// cbuffer MyConstants { +// float a; +// } // -// struct A { -// float a; -// float b; -// } cbuffer_A __attribute__((address_space(4))); -// float foo() { return cbuffer_A.a + cbuffer_A.b; } +// creates a structure type MyConstants and then returns the resource handle +// that would be spelled as: // -// layoutBuffer will create the struct A type. -// replaceBuffer will replace use of global variable a and b with cbuffer_A.a -// and cbuffer_A.b. +// __hlsl_resource_t [[hlsl::resource_class(CBuffer)]] +// [[contained_type(MyConstants)]] // -void layoutBuffer(CGHLSLRuntime::Buffer &Buf, const DataLayout &DL) { - if (Buf.Constants.empty()) -return; - - std::vector EltTys; - for (auto &Const : Buf.Constants) { -GlobalVariable *GV = Const.first; -Const.second = EltTys.size(); -llvm::Type *Ty = GV->getValueType(); -EltTys.emplace_back(Ty); +static const clang::Type *getBufferHandleType(CGHLSLRuntime::Buffer &Buf) { + HLSLBufferDecl *BD = Buf.Decl; + ASTContext &AST = BD->getASTContext(); + + // create struct type for the constant buffer; filter out any declarations + // that are not a VarDecls or that are static + CXXRecordDecl *StructDecl = CXXRecordDecl::Create( + BD->getASTContext(), TagDecl::TagKind::Class, BD->getDeclContext(), + BD->getLocation(), BD->getLocation(), BD->getIdentifier()); + StructDecl->startDefinition(); llvm-beanz wrote: This concerns me. We really shouldn't be generating AST types during CodeGen. We should generate the struct decl during Sema and attach it to the buffer decl so that we can dump and inspect the AST. https://github.com/llvm/llvm-project/pull/119755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Codegen for `cbuffer` declarations without embedded arrays or structs (PR #119755)
@@ -164,18 +164,18 @@ Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool CBuffer, return Result; } -// Calculate the size of a legacy cbuffer type based on +// Calculate the size of a legacy cbuffer type in bytes based on // https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-packing-rules static unsigned calculateLegacyCbufferSize(const ASTContext &Context, QualType T) { unsigned Size = 0; - constexpr unsigned CBufferAlign = 128; + constexpr unsigned CBufferAlign = 16; if (const RecordType *RT = T->getAs()) { const RecordDecl *RD = RT->getDecl(); for (const FieldDecl *Field : RD->fields()) { QualType Ty = Field->getType(); unsigned FieldSize = calculateLegacyCbufferSize(Context, Ty); - unsigned FieldAlign = 32; + unsigned FieldAlign = 4; if (Ty->isAggregateType()) llvm-beanz wrote: Can you put a comment there and reference the issue just to make it easier to keep track? https://github.com/llvm/llvm-project/pull/119755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Codegen for `cbuffer` declarations without embedded arrays or structs (PR #119755)
@@ -890,6 +890,10 @@ CodeGenModule::EmitCXXGlobalInitFunc() { ModuleInits.push_back(Fn); } + if (getLangOpts().HLSL && getHLSLRuntime().needsResourceBindingInitFn()) { +CXXGlobalInits.push_back(getHLSLRuntime().createResourceBindingInitFn()); + } llvm-beanz wrote: You probably haven't seen this, but I filed an issue yesterday about how we were connecting initializers in the wrong place (https://github.com/llvm/llvm-project/issues/120636). This is definitely better. I do wonder if we should be generating one binding function for all bindings (which would require collecting them and generating them late), or if we should be generating an initializer per binding and appending them to the `CXXGlobalInits` list as we process each binding. While the later produces more functions that need to be inlined, I'm inclined to prefer it because it is simpler and aligns more with a traditional RAII-model for resource initialization. The issue I filed is probably redundant since you're still reworking all of this. https://github.com/llvm/llvm-project/pull/119755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Hexagon] Add V75 support to compiler and assembler (PR #120773)
https://github.com/iajbar created https://github.com/llvm/llvm-project/pull/120773 This patch introduces support for the Hexagon V75 architecture. It includes instruction formats, definitions, encodings, scheduling classes, and builtins/intrinsics. >From 1d3ac02da5bfb00d86b123334e3a75628e47ef42 Mon Sep 17 00:00:00 2001 From: Ikhlas Ajbar Date: Fri, 13 Dec 2024 14:54:44 -0800 Subject: [PATCH] Add V75 support to compiler and assembler This patch introduces support for the Hexagon V75 architecture. It includes instruction formats, definitions, encodings, scheduling classes, and builtins/intrinsics. --- clang/include/clang/Basic/BuiltinsHexagon.def | 10 +- clang/include/clang/Driver/Options.td | 2 + clang/lib/Basic/Targets/Hexagon.cpp | 7 +- clang/test/Driver/hexagon-toolchain-elf.c | 7 + .../Misc/target-invalid-cpu-note/hexagon.c| 1 + clang/test/Preprocessor/hexagon-predefines.c | 16 + llvm/include/llvm/BinaryFormat/ELF.h | 1 + llvm/lib/Object/ELFObjectFile.cpp | 2 + llvm/lib/ObjectYAML/ELFYAML.cpp | 2 + llvm/lib/Target/Hexagon/Hexagon.td| 14 + llvm/lib/Target/Hexagon/HexagonDepArch.h | 4 +- llvm/lib/Target/Hexagon/HexagonDepArch.td | 2 + llvm/lib/Target/Hexagon/HexagonDepIICHVX.td | 592 .../lib/Target/Hexagon/HexagonDepIICScalar.td | 888 ++ llvm/lib/Target/Hexagon/HexagonSchedule.td| 1 + llvm/lib/Target/Hexagon/HexagonScheduleV75.td | 39 + llvm/lib/Target/Hexagon/HexagonSubtarget.h| 6 + .../MCTargetDesc/HexagonMCELFStreamer.cpp | 3 + .../MCTargetDesc/HexagonMCTargetDesc.cpp | 41 +- llvm/test/MC/Hexagon/arch-support.s | 9 + llvm/test/MC/Hexagon/v75_arch.s | 10 + 21 files changed, 1638 insertions(+), 19 deletions(-) create mode 100644 llvm/lib/Target/Hexagon/HexagonScheduleV75.td create mode 100644 llvm/test/MC/Hexagon/v75_arch.s diff --git a/clang/include/clang/Basic/BuiltinsHexagon.def b/clang/include/clang/Basic/BuiltinsHexagon.def index 0dc0f4567dd413..ca3f99176110e3 100644 --- a/clang/include/clang/Basic/BuiltinsHexagon.def +++ b/clang/include/clang/Basic/BuiltinsHexagon.def @@ -17,8 +17,10 @@ # define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS) #endif +#pragma push_macro("V75") +#define V75 "v75" #pragma push_macro("V73") -#define V73 "v73" +#define V73 "v73|" V75 #pragma push_macro("V71") #define V71 "v71|" V73 #pragma push_macro("V69") @@ -40,8 +42,10 @@ #pragma push_macro("V5") #define V5 "v5|" V55 +#pragma push_macro("HVXV75") +#define HVXV75 "hvxv75" #pragma push_macro("HVXV73") -#define HVXV73 "hvxv73" +#define HVXV73 "hvxv73|" HVXV75 #pragma push_macro("HVXV71") #define HVXV71 "hvxv71|" HVXV73 #pragma push_macro("HVXV69") @@ -143,6 +147,7 @@ TARGET_BUILTIN(__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B,"V64iV64iV32iLLi","", " #pragma pop_macro("HVXV69") #pragma pop_macro("HVXV71") #pragma pop_macro("HVXV73") +#pragma pop_macro("HVXV75") #pragma pop_macro("V5") #pragma pop_macro("V55") @@ -155,6 +160,7 @@ TARGET_BUILTIN(__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B,"V64iV64iV32iLLi","", " #pragma pop_macro("V69") #pragma pop_macro("V71") #pragma pop_macro("V73") +#pragma pop_macro("V75") #undef BUILTIN #undef TARGET_BUILTIN diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 638f8c52053ec5..9edf308cc685ea 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6224,6 +6224,8 @@ def mv71t : Flag<["-"], "mv71t">, Group, Alias, AliasArgs<["hexagonv71t"]>; def mv73 : Flag<["-"], "mv73">, Group, Alias, AliasArgs<["hexagonv73"]>; +def mv75 : Flag<["-"], "mv75">, Group, + Alias, AliasArgs<["hexagonv75"]>; def mhexagon_hvx : Flag<["-"], "mhvx">, Group, HelpText<"Enable Hexagon Vector eXtensions">; def mhexagon_hvx_EQ : Joined<["-"], "mhvx=">, diff --git a/clang/lib/Basic/Targets/Hexagon.cpp b/clang/lib/Basic/Targets/Hexagon.cpp index 0282ac812c306f..1fce0d0ed006ec 100644 --- a/clang/lib/Basic/Targets/Hexagon.cpp +++ b/clang/lib/Basic/Targets/Hexagon.cpp @@ -78,6 +78,9 @@ void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts, } else if (CPU == "hexagonv73") { Builder.defineMacro("__HEXAGON_V73__"); Builder.defineMacro("__HEXAGON_ARCH__", "73"); + } else if (CPU == "hexagonv75") { +Builder.defineMacro("__HEXAGON_V75__"); +Builder.defineMacro("__HEXAGON_ARCH__", "75"); } if (hasFeature("hvx-length64b")) { @@ -234,8 +237,8 @@ static constexpr CPUSuffix Suffixes[] = { {{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}}, {{"hexagonv67"}, {"67"}}, {{"hexagonv67t"}, {"67t"}}, {{"hexagonv68"}, {"68"}}, {{"hexagonv69"}, {"69"}}, -{{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}}, -{{"hexagonv73"}, {"73"}}, +{{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}}, +{{"hexagonv73
[clang] [llvm] [Hexagon] Add V75 support to compiler and assembler (PR #120773)
llvmbot wrote: @llvm/pr-subscribers-backend-hexagon Author: Ikhlas Ajbar (iajbar) Changes This patch introduces support for the Hexagon V75 architecture. It includes instruction formats, definitions, encodings, scheduling classes, and builtins/intrinsics. --- Patch is 74.75 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/120773.diff 21 Files Affected: - (modified) clang/include/clang/Basic/BuiltinsHexagon.def (+8-2) - (modified) clang/include/clang/Driver/Options.td (+2) - (modified) clang/lib/Basic/Targets/Hexagon.cpp (+5-2) - (modified) clang/test/Driver/hexagon-toolchain-elf.c (+7) - (modified) clang/test/Misc/target-invalid-cpu-note/hexagon.c (+1) - (modified) clang/test/Preprocessor/hexagon-predefines.c (+16) - (modified) llvm/include/llvm/BinaryFormat/ELF.h (+1) - (modified) llvm/lib/Object/ELFObjectFile.cpp (+2) - (modified) llvm/lib/ObjectYAML/ELFYAML.cpp (+2) - (modified) llvm/lib/Target/Hexagon/Hexagon.td (+14) - (modified) llvm/lib/Target/Hexagon/HexagonDepArch.h (+3-1) - (modified) llvm/lib/Target/Hexagon/HexagonDepArch.td (+2) - (modified) llvm/lib/Target/Hexagon/HexagonDepIICHVX.td (+592) - (modified) llvm/lib/Target/Hexagon/HexagonDepIICScalar.td (+888) - (modified) llvm/lib/Target/Hexagon/HexagonSchedule.td (+1) - (added) llvm/lib/Target/Hexagon/HexagonScheduleV75.td (+39) - (modified) llvm/lib/Target/Hexagon/HexagonSubtarget.h (+6) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp (+3) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp (+27-14) - (modified) llvm/test/MC/Hexagon/arch-support.s (+9) - (added) llvm/test/MC/Hexagon/v75_arch.s (+10) ``diff diff --git a/clang/include/clang/Basic/BuiltinsHexagon.def b/clang/include/clang/Basic/BuiltinsHexagon.def index 0dc0f4567dd413..ca3f99176110e3 100644 --- a/clang/include/clang/Basic/BuiltinsHexagon.def +++ b/clang/include/clang/Basic/BuiltinsHexagon.def @@ -17,8 +17,10 @@ # define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS) #endif +#pragma push_macro("V75") +#define V75 "v75" #pragma push_macro("V73") -#define V73 "v73" +#define V73 "v73|" V75 #pragma push_macro("V71") #define V71 "v71|" V73 #pragma push_macro("V69") @@ -40,8 +42,10 @@ #pragma push_macro("V5") #define V5 "v5|" V55 +#pragma push_macro("HVXV75") +#define HVXV75 "hvxv75" #pragma push_macro("HVXV73") -#define HVXV73 "hvxv73" +#define HVXV73 "hvxv73|" HVXV75 #pragma push_macro("HVXV71") #define HVXV71 "hvxv71|" HVXV73 #pragma push_macro("HVXV69") @@ -143,6 +147,7 @@ TARGET_BUILTIN(__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B,"V64iV64iV32iLLi","", " #pragma pop_macro("HVXV69") #pragma pop_macro("HVXV71") #pragma pop_macro("HVXV73") +#pragma pop_macro("HVXV75") #pragma pop_macro("V5") #pragma pop_macro("V55") @@ -155,6 +160,7 @@ TARGET_BUILTIN(__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B,"V64iV64iV32iLLi","", " #pragma pop_macro("V69") #pragma pop_macro("V71") #pragma pop_macro("V73") +#pragma pop_macro("V75") #undef BUILTIN #undef TARGET_BUILTIN diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 638f8c52053ec5..9edf308cc685ea 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6224,6 +6224,8 @@ def mv71t : Flag<["-"], "mv71t">, Group, Alias, AliasArgs<["hexagonv71t"]>; def mv73 : Flag<["-"], "mv73">, Group, Alias, AliasArgs<["hexagonv73"]>; +def mv75 : Flag<["-"], "mv75">, Group, + Alias, AliasArgs<["hexagonv75"]>; def mhexagon_hvx : Flag<["-"], "mhvx">, Group, HelpText<"Enable Hexagon Vector eXtensions">; def mhexagon_hvx_EQ : Joined<["-"], "mhvx=">, diff --git a/clang/lib/Basic/Targets/Hexagon.cpp b/clang/lib/Basic/Targets/Hexagon.cpp index 0282ac812c306f..1fce0d0ed006ec 100644 --- a/clang/lib/Basic/Targets/Hexagon.cpp +++ b/clang/lib/Basic/Targets/Hexagon.cpp @@ -78,6 +78,9 @@ void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts, } else if (CPU == "hexagonv73") { Builder.defineMacro("__HEXAGON_V73__"); Builder.defineMacro("__HEXAGON_ARCH__", "73"); + } else if (CPU == "hexagonv75") { +Builder.defineMacro("__HEXAGON_V75__"); +Builder.defineMacro("__HEXAGON_ARCH__", "75"); } if (hasFeature("hvx-length64b")) { @@ -234,8 +237,8 @@ static constexpr CPUSuffix Suffixes[] = { {{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}}, {{"hexagonv67"}, {"67"}}, {{"hexagonv67t"}, {"67t"}}, {{"hexagonv68"}, {"68"}}, {{"hexagonv69"}, {"69"}}, -{{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}}, -{{"hexagonv73"}, {"73"}}, +{{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}}, +{{"hexagonv73"}, {"73"}}, {{"hexagonv75"}, {"75"}}, }; std::optional HexagonTargetInfo::getHexagonCPURev(StringRef Name) { diff --git a/clang/test/Driver/hexagon-toolchain-elf.c b/clang/test/Driver/hexagon-toolchain-elf.c index 716d82bcf316b5..37d2
[clang] [llvm] [Hexagon] Add V75 support to compiler and assembler (PR #120773)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Ikhlas Ajbar (iajbar) Changes This patch introduces support for the Hexagon V75 architecture. It includes instruction formats, definitions, encodings, scheduling classes, and builtins/intrinsics. --- Patch is 74.75 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/120773.diff 21 Files Affected: - (modified) clang/include/clang/Basic/BuiltinsHexagon.def (+8-2) - (modified) clang/include/clang/Driver/Options.td (+2) - (modified) clang/lib/Basic/Targets/Hexagon.cpp (+5-2) - (modified) clang/test/Driver/hexagon-toolchain-elf.c (+7) - (modified) clang/test/Misc/target-invalid-cpu-note/hexagon.c (+1) - (modified) clang/test/Preprocessor/hexagon-predefines.c (+16) - (modified) llvm/include/llvm/BinaryFormat/ELF.h (+1) - (modified) llvm/lib/Object/ELFObjectFile.cpp (+2) - (modified) llvm/lib/ObjectYAML/ELFYAML.cpp (+2) - (modified) llvm/lib/Target/Hexagon/Hexagon.td (+14) - (modified) llvm/lib/Target/Hexagon/HexagonDepArch.h (+3-1) - (modified) llvm/lib/Target/Hexagon/HexagonDepArch.td (+2) - (modified) llvm/lib/Target/Hexagon/HexagonDepIICHVX.td (+592) - (modified) llvm/lib/Target/Hexagon/HexagonDepIICScalar.td (+888) - (modified) llvm/lib/Target/Hexagon/HexagonSchedule.td (+1) - (added) llvm/lib/Target/Hexagon/HexagonScheduleV75.td (+39) - (modified) llvm/lib/Target/Hexagon/HexagonSubtarget.h (+6) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp (+3) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp (+27-14) - (modified) llvm/test/MC/Hexagon/arch-support.s (+9) - (added) llvm/test/MC/Hexagon/v75_arch.s (+10) ``diff diff --git a/clang/include/clang/Basic/BuiltinsHexagon.def b/clang/include/clang/Basic/BuiltinsHexagon.def index 0dc0f4567dd413..ca3f99176110e3 100644 --- a/clang/include/clang/Basic/BuiltinsHexagon.def +++ b/clang/include/clang/Basic/BuiltinsHexagon.def @@ -17,8 +17,10 @@ # define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS) #endif +#pragma push_macro("V75") +#define V75 "v75" #pragma push_macro("V73") -#define V73 "v73" +#define V73 "v73|" V75 #pragma push_macro("V71") #define V71 "v71|" V73 #pragma push_macro("V69") @@ -40,8 +42,10 @@ #pragma push_macro("V5") #define V5 "v5|" V55 +#pragma push_macro("HVXV75") +#define HVXV75 "hvxv75" #pragma push_macro("HVXV73") -#define HVXV73 "hvxv73" +#define HVXV73 "hvxv73|" HVXV75 #pragma push_macro("HVXV71") #define HVXV71 "hvxv71|" HVXV73 #pragma push_macro("HVXV69") @@ -143,6 +147,7 @@ TARGET_BUILTIN(__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B,"V64iV64iV32iLLi","", " #pragma pop_macro("HVXV69") #pragma pop_macro("HVXV71") #pragma pop_macro("HVXV73") +#pragma pop_macro("HVXV75") #pragma pop_macro("V5") #pragma pop_macro("V55") @@ -155,6 +160,7 @@ TARGET_BUILTIN(__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B,"V64iV64iV32iLLi","", " #pragma pop_macro("V69") #pragma pop_macro("V71") #pragma pop_macro("V73") +#pragma pop_macro("V75") #undef BUILTIN #undef TARGET_BUILTIN diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 638f8c52053ec5..9edf308cc685ea 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6224,6 +6224,8 @@ def mv71t : Flag<["-"], "mv71t">, Group, Alias, AliasArgs<["hexagonv71t"]>; def mv73 : Flag<["-"], "mv73">, Group, Alias, AliasArgs<["hexagonv73"]>; +def mv75 : Flag<["-"], "mv75">, Group, + Alias, AliasArgs<["hexagonv75"]>; def mhexagon_hvx : Flag<["-"], "mhvx">, Group, HelpText<"Enable Hexagon Vector eXtensions">; def mhexagon_hvx_EQ : Joined<["-"], "mhvx=">, diff --git a/clang/lib/Basic/Targets/Hexagon.cpp b/clang/lib/Basic/Targets/Hexagon.cpp index 0282ac812c306f..1fce0d0ed006ec 100644 --- a/clang/lib/Basic/Targets/Hexagon.cpp +++ b/clang/lib/Basic/Targets/Hexagon.cpp @@ -78,6 +78,9 @@ void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts, } else if (CPU == "hexagonv73") { Builder.defineMacro("__HEXAGON_V73__"); Builder.defineMacro("__HEXAGON_ARCH__", "73"); + } else if (CPU == "hexagonv75") { +Builder.defineMacro("__HEXAGON_V75__"); +Builder.defineMacro("__HEXAGON_ARCH__", "75"); } if (hasFeature("hvx-length64b")) { @@ -234,8 +237,8 @@ static constexpr CPUSuffix Suffixes[] = { {{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}}, {{"hexagonv67"}, {"67"}}, {{"hexagonv67t"}, {"67t"}}, {{"hexagonv68"}, {"68"}}, {{"hexagonv69"}, {"69"}}, -{{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}}, -{{"hexagonv73"}, {"73"}}, +{{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}}, +{{"hexagonv73"}, {"73"}}, {{"hexagonv75"}, {"75"}}, }; std::optional HexagonTargetInfo::getHexagonCPURev(StringRef Name) { diff --git a/clang/test/Driver/hexagon-toolchain-elf.c b/clang/test/Driver/hexagon-toolchain-elf.c index 716d82bcf316b5..37d24d4b2b99dc
[clang] [llvm] [Hexagon] Add V75 support to compiler and assembler (PR #120773)
llvmbot wrote: @llvm/pr-subscribers-objectyaml @llvm/pr-subscribers-clang-driver Author: Ikhlas Ajbar (iajbar) Changes This patch introduces support for the Hexagon V75 architecture. It includes instruction formats, definitions, encodings, scheduling classes, and builtins/intrinsics. --- Patch is 74.75 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/120773.diff 21 Files Affected: - (modified) clang/include/clang/Basic/BuiltinsHexagon.def (+8-2) - (modified) clang/include/clang/Driver/Options.td (+2) - (modified) clang/lib/Basic/Targets/Hexagon.cpp (+5-2) - (modified) clang/test/Driver/hexagon-toolchain-elf.c (+7) - (modified) clang/test/Misc/target-invalid-cpu-note/hexagon.c (+1) - (modified) clang/test/Preprocessor/hexagon-predefines.c (+16) - (modified) llvm/include/llvm/BinaryFormat/ELF.h (+1) - (modified) llvm/lib/Object/ELFObjectFile.cpp (+2) - (modified) llvm/lib/ObjectYAML/ELFYAML.cpp (+2) - (modified) llvm/lib/Target/Hexagon/Hexagon.td (+14) - (modified) llvm/lib/Target/Hexagon/HexagonDepArch.h (+3-1) - (modified) llvm/lib/Target/Hexagon/HexagonDepArch.td (+2) - (modified) llvm/lib/Target/Hexagon/HexagonDepIICHVX.td (+592) - (modified) llvm/lib/Target/Hexagon/HexagonDepIICScalar.td (+888) - (modified) llvm/lib/Target/Hexagon/HexagonSchedule.td (+1) - (added) llvm/lib/Target/Hexagon/HexagonScheduleV75.td (+39) - (modified) llvm/lib/Target/Hexagon/HexagonSubtarget.h (+6) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp (+3) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp (+27-14) - (modified) llvm/test/MC/Hexagon/arch-support.s (+9) - (added) llvm/test/MC/Hexagon/v75_arch.s (+10) ``diff diff --git a/clang/include/clang/Basic/BuiltinsHexagon.def b/clang/include/clang/Basic/BuiltinsHexagon.def index 0dc0f4567dd413..ca3f99176110e3 100644 --- a/clang/include/clang/Basic/BuiltinsHexagon.def +++ b/clang/include/clang/Basic/BuiltinsHexagon.def @@ -17,8 +17,10 @@ # define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS) #endif +#pragma push_macro("V75") +#define V75 "v75" #pragma push_macro("V73") -#define V73 "v73" +#define V73 "v73|" V75 #pragma push_macro("V71") #define V71 "v71|" V73 #pragma push_macro("V69") @@ -40,8 +42,10 @@ #pragma push_macro("V5") #define V5 "v5|" V55 +#pragma push_macro("HVXV75") +#define HVXV75 "hvxv75" #pragma push_macro("HVXV73") -#define HVXV73 "hvxv73" +#define HVXV73 "hvxv73|" HVXV75 #pragma push_macro("HVXV71") #define HVXV71 "hvxv71|" HVXV73 #pragma push_macro("HVXV69") @@ -143,6 +147,7 @@ TARGET_BUILTIN(__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B,"V64iV64iV32iLLi","", " #pragma pop_macro("HVXV69") #pragma pop_macro("HVXV71") #pragma pop_macro("HVXV73") +#pragma pop_macro("HVXV75") #pragma pop_macro("V5") #pragma pop_macro("V55") @@ -155,6 +160,7 @@ TARGET_BUILTIN(__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B,"V64iV64iV32iLLi","", " #pragma pop_macro("V69") #pragma pop_macro("V71") #pragma pop_macro("V73") +#pragma pop_macro("V75") #undef BUILTIN #undef TARGET_BUILTIN diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 638f8c52053ec5..9edf308cc685ea 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6224,6 +6224,8 @@ def mv71t : Flag<["-"], "mv71t">, Group, Alias, AliasArgs<["hexagonv71t"]>; def mv73 : Flag<["-"], "mv73">, Group, Alias, AliasArgs<["hexagonv73"]>; +def mv75 : Flag<["-"], "mv75">, Group, + Alias, AliasArgs<["hexagonv75"]>; def mhexagon_hvx : Flag<["-"], "mhvx">, Group, HelpText<"Enable Hexagon Vector eXtensions">; def mhexagon_hvx_EQ : Joined<["-"], "mhvx=">, diff --git a/clang/lib/Basic/Targets/Hexagon.cpp b/clang/lib/Basic/Targets/Hexagon.cpp index 0282ac812c306f..1fce0d0ed006ec 100644 --- a/clang/lib/Basic/Targets/Hexagon.cpp +++ b/clang/lib/Basic/Targets/Hexagon.cpp @@ -78,6 +78,9 @@ void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts, } else if (CPU == "hexagonv73") { Builder.defineMacro("__HEXAGON_V73__"); Builder.defineMacro("__HEXAGON_ARCH__", "73"); + } else if (CPU == "hexagonv75") { +Builder.defineMacro("__HEXAGON_V75__"); +Builder.defineMacro("__HEXAGON_ARCH__", "75"); } if (hasFeature("hvx-length64b")) { @@ -234,8 +237,8 @@ static constexpr CPUSuffix Suffixes[] = { {{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}}, {{"hexagonv67"}, {"67"}}, {{"hexagonv67t"}, {"67t"}}, {{"hexagonv68"}, {"68"}}, {{"hexagonv69"}, {"69"}}, -{{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}}, -{{"hexagonv73"}, {"73"}}, +{{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}}, +{{"hexagonv73"}, {"73"}}, {{"hexagonv75"}, {"75"}}, }; std::optional HexagonTargetInfo::getHexagonCPURev(StringRef Name) { diff --git a/clang/test/Driver/hexagon-toolchain-elf.c b/clang/test/Driver/hexagon-toolchain-elf
[clang] [llvm] [Hexagon] Add V75 support to compiler and assembler (PR #120773)
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 7739380643718bc912bc05b969e4be525a85c0d2 1d3ac02da5bfb00d86b123334e3a75628e47ef42 --extensions h,c,cpp -- clang/lib/Basic/Targets/Hexagon.cpp clang/test/Driver/hexagon-toolchain-elf.c clang/test/Misc/target-invalid-cpu-note/hexagon.c clang/test/Preprocessor/hexagon-predefines.c llvm/include/llvm/BinaryFormat/ELF.h llvm/lib/Object/ELFObjectFile.cpp llvm/lib/ObjectYAML/ELFYAML.cpp llvm/lib/Target/Hexagon/HexagonDepArch.h llvm/lib/Target/Hexagon/HexagonSubtarget.h llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Basic/Targets/Hexagon.cpp b/clang/lib/Basic/Targets/Hexagon.cpp index 1fce0d0ed0..931327bd86 100644 --- a/clang/lib/Basic/Targets/Hexagon.cpp +++ b/clang/lib/Basic/Targets/Hexagon.cpp @@ -232,13 +232,13 @@ struct CPUSuffix { }; static constexpr CPUSuffix Suffixes[] = { -{{"hexagonv5"}, {"5"}}, {{"hexagonv55"}, {"55"}}, -{{"hexagonv60"}, {"60"}}, {{"hexagonv62"}, {"62"}}, -{{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}}, +{{"hexagonv5"}, {"5"}}, {{"hexagonv55"}, {"55"}}, +{{"hexagonv60"}, {"60"}}, {{"hexagonv62"}, {"62"}}, +{{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}}, {{"hexagonv67"}, {"67"}}, {{"hexagonv67t"}, {"67t"}}, -{{"hexagonv68"}, {"68"}}, {{"hexagonv69"}, {"69"}}, +{{"hexagonv68"}, {"68"}}, {{"hexagonv69"}, {"69"}}, {{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}}, -{{"hexagonv73"}, {"73"}}, {{"hexagonv75"}, {"75"}}, +{{"hexagonv73"}, {"73"}}, {{"hexagonv75"}, {"75"}}, }; std::optional HexagonTargetInfo::getHexagonCPURev(StringRef Name) { diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp index 40d2b122d4..dfa1f5471a 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp @@ -453,18 +453,18 @@ std::string selectHexagonFS(StringRef CPU, StringRef FS) { break; case Hexagon::ArchEnum::Generic: { Result.push_back(StringSwitch(CPU) - .Case("hexagonv60", "+hvxv60") - .Case("hexagonv62", "+hvxv62") - .Case("hexagonv65", "+hvxv65") - .Case("hexagonv66", "+hvxv66") - .Case("hexagonv67", "+hvxv67") - .Case("hexagonv67t", "+hvxv67") - .Case("hexagonv68", "+hvxv68") - .Case("hexagonv69", "+hvxv69") - .Case("hexagonv71", "+hvxv71") - .Case("hexagonv71t", "+hvxv71") - .Case("hexagonv73", "+hvxv73") - .Case("hexagonv75", "+hvxv75")); + .Case("hexagonv60", "+hvxv60") + .Case("hexagonv62", "+hvxv62") + .Case("hexagonv65", "+hvxv65") + .Case("hexagonv66", "+hvxv66") + .Case("hexagonv67", "+hvxv67") + .Case("hexagonv67t", "+hvxv67") + .Case("hexagonv68", "+hvxv68") + .Case("hexagonv69", "+hvxv69") + .Case("hexagonv71", "+hvxv71") + .Case("hexagonv71t", "+hvxv71") + .Case("hexagonv73", "+hvxv73") + .Case("hexagonv75", "+hvxv75")); break; } case Hexagon::ArchEnum::NoArch: @@ -512,8 +512,8 @@ FeatureBitset Hexagon_MC::completeHVXFeatures(const FeatureBitset &S) { // turns on hvxvNN, corresponding to the existing ArchVNN. FeatureBitset FB = S; unsigned CpuArch = ArchV5; - for (unsigned F : {ArchV75, ArchV73, ArchV71, ArchV69, ArchV68, ArchV67, ArchV66, - ArchV65, ArchV62, ArchV60, ArchV55, ArchV5}) { + for (unsigned F : {ArchV75, ArchV73, ArchV71, ArchV69, ArchV68, ArchV67, + ArchV66, ArchV65, ArchV62, ArchV60, ArchV55, ArchV5}) { if (!FB.test(F)) continue; CpuArch = F; @@ -527,9 +527,10 @@ FeatureBitset Hexagon_MC::completeHVXFeatures(const FeatureBitset &S) { break; } bool HasHvxVer = false; - for (unsigned F : {ExtensionHVXV60, ExtensionHVXV62, ExtensionHVXV65, - ExtensionHVXV66, ExtensionHVXV67, ExtensionHVXV68, -ExtensionHVXV69, ExtensionHVXV71, ExtensionHVXV73, ExtensionHVXV75}) { + for (unsigned F : + {ExtensionHVXV60, ExtensionHVXV62, ExtensionHVXV65, ExtensionHVXV66, +ExtensionHVXV67, ExtensionHVXV68, ExtensionHVXV69, ExtensionHVXV71, +ExtensionHVXV73, ExtensionHVXV75}) { if (!FB.test(F)) continue; HasHvxVer = true; `` https://github.com/llvm/llvm-project/pull/120773
[clang] [clang][ObjectiveC] Fix Parsing Types with the `::` Optional Scope Specifier (PR #119908)
qiongsiwu wrote: Gentle ping for review. Thanks so much! https://github.com/llvm/llvm-project/pull/119908 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ObjectiveC] Fix Parsing the `::` Optional Scope Specifier (PR #119908)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/119908 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix non-deterministic infinite recursion... (PR #118288)
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID: In-Reply-To: hubert-reinterpretcast wrote: > LLVM patch releases cannot break API or ABI compatibility Thanks @nikic for the explanation. I thought you meant ABI compatibility in the "user program" sense. https://github.com/llvm/llvm-project/pull/118288 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Enable FEAT_SVE2p1 by default for Armv9.4-A and later (PR #120753)
https://github.com/paulwalker-arm approved this pull request. https://github.com/llvm/llvm-project/pull/120753 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Mikołaj Piróg (mikolaj-pirog) Changes As in title. I will create a sibling pr with comments to the 512 in a separate PR. --- Patch is 111.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/120766.diff 1 Files Affected: - (modified) clang/lib/Headers/avx10_2convertintrin.h (+2696) ``diff diff --git a/clang/lib/Headers/avx10_2convertintrin.h b/clang/lib/Headers/avx10_2convertintrin.h index 134adb2850c8de..52a64a5309763d 100644 --- a/clang/lib/Headers/avx10_2convertintrin.h +++ b/clang/lib/Headers/avx10_2convertintrin.h @@ -24,24 +24,146 @@ __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"), \ __min_vector_width__(256))) +/// Convert two 128-bit vectors, \a __A and \a __B, containing packed +/// single-precision (32-bit) floating-point elements to a 128-bit vector +/// containing FP16 elements. +/// +/// \code{.operation} +/// FOR i := 0 to 7 +///IF i < 4 +///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i]) +///ELSE +///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4]) +///FI +/// ENDFOR +/// \endcode +/// +/// \headerfile +/// +/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction. +/// +/// \param __A +///A 128-bit vector of [4 x float]. +/// \param __B +///A 128-bit vector of [4 x float]. +/// \returns +///A 128-bit vector of [8 x fp16]. Lower elements correspond to the +///(converted) elements from \a __B; higher order elements correspond to the +///(converted) elements from \a __A. static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A, __m128 __B) { return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask( (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1)); } +/// Convert two 128-bit vectors, \a __A and \a __B, containing packed +/// single-precision (32-bit) floating-point elements to a 128-bit vector +/// containing FP16 elements. Merging mask \a __U is used to determine if given +/// element should be taken from \a __W instead. +/// +/// \code{.operation} +/// FOR i := 0 to 7 +///IF mask[i] +///dst.fp16[i] := __W[i] +///ELSE +///IF i < 4 +///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i]) +///ELSE +///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4]) +///FI +///FI +/// ENDFOR +/// \endcode +/// +/// \headerfile +/// +/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction. +/// +/// \param __W +///A 128-bit vector of [8 x fp16]. +/// \param __U +///A 8-bit merging mask. +/// \param __A +///A 128-bit vector of [4 x float]. +/// \param __B +///A 128-bit vector of [4 x float]. +/// \returns +///A 128-bit vector of [8 x fp16]. Lower elements correspond to the +///(converted) elements from \a __B; higher order elements correspond to the +///(converted) elements from \a __A. If corresponding mask bit is set, then +///element from \a __W is taken instead. static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) { return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask( (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U); } +/// Convert two 128-bit vectors, \a __A and \a __B, containing packed +/// single-precision (32-bit) floating-point elements to a 128-bit vector +/// containing FP16 elements. Zeroing mask \a __U is used to determine if given +/// element should be zeroed instead. +/// +/// \code{.operation} +/// FOR i := 0 to 7 +///IF mask[i] +///IF i < 4 +///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i]) +///ELSE +///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4]) +///FI +///ELSE +///dst.fp16[i] := 0 +///FI +/// ENDFOR +/// \endcode +/// +/// \headerfile +/// +/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction. +/// +/// \param __U +///A 8-bit zeroing mask. +/// \param __A +///A 128-bit vector of [4 x float]. +/// \param __B +///A 128-bit vector of [4 x float]. +/// \returns +///A 128-bit vector of [8 x fp16]. Lower elements correspond to the +///(converted) elements from \a __B; higher order elements correspond to the +///(converted) elements from \a __A. If corresponding mask bit is not set, +///then zero is taken instead. static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) { return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask( (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U); } +/// Convert two 256-bit vectors, \a __A and \a __B, containing packed +/// single-precision (32-bit) floating-point elements to a
[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)
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 d5fe6332c9f25590b9878ad31d6461ea581e0fa5 b069337d461da42883093aedeb00c019131d3559 --extensions h -- clang/lib/Headers/avx10_2convertintrin.h `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Headers/avx10_2convertintrin.h b/clang/lib/Headers/avx10_2convertintrin.h index 52a64a5309..38d9f1982b 100644 --- a/clang/lib/Headers/avx10_2convertintrin.h +++ b/clang/lib/Headers/avx10_2convertintrin.h @@ -143,7 +143,7 @@ _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) { /// containing FP16 elements. /// /// \code{.operation} -/// FOR i := 0 to 15 +/// FOR i := 0 to 15 ///IF i < 8 ///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i]) ///ELSE @@ -220,7 +220,7 @@ _mm256_mask_cvtx2ps_ph(__m256h __W, __mmask16 __U, __m256 __A, __m256 __B) { /// element should be zeroed instead. /// /// \code{.operation} -/// FOR i := 0 to 15 +/// FOR i := 0 to 15 ///IF mask[i] ///IF i < 8 ///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i]) @@ -260,7 +260,7 @@ _mm256_maskz_cvtx2ps_ph(__mmask16 __U, __m256 __A, __m256 __B) { /// containing FP16 elements. Rounding mode \a __R needs to be provided. /// /// \code{.operation} -/// FOR i := 0 to 15 +/// FOR i := 0 to 15 ///IF i < 8 ///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i]) ///ELSE @@ -279,9 +279,9 @@ _mm256_maskz_cvtx2ps_ph(__mmask16 __U, __m256 __A, __m256 __B) { ///A 256-bit vector of [8 x float]. /// \param __R ///Rounding mode. Valid inputs are: _MM_FROUND_CUR_DIRECTION or -///result of bitwise or of _MM_FROUND_NO_EXC with at most one of the following: -///_MM_FROUND_TO_NEAREST_INT, _MM_FROUND_TO_NEG_INF, _MM_FROUND_TO_POS_INF, -///_MM_FROUND_TO_ZERO. +///result of bitwise or of _MM_FROUND_NO_EXC with at most one of the +///following: _MM_FROUND_TO_NEAREST_INT, _MM_FROUND_TO_NEG_INF, +///_MM_FROUND_TO_POS_INF, _MM_FROUND_TO_ZERO. /// \returns ///A 256-bit vector of [16 x fp16]. Lower elements correspond to the ///(converted) elements from \a __B; higher order elements correspond to the @@ -325,9 +325,9 @@ _mm256_maskz_cvtx2ps_ph(__mmask16 __U, __m256 __A, __m256 __B) { ///A 256-bit vector of [8 x float]. /// \param __R ///Rounding mode. Valid inputs are: _MM_FROUND_CUR_DIRECTION or -///result of bitwise or of _MM_FROUND_NO_EXC with at most one of the following: -///_MM_FROUND_TO_NEAREST_INT, _MM_FROUND_TO_NEG_INF, _MM_FROUND_TO_POS_INF, -///_MM_FROUND_TO_ZERO. +///result of bitwise or of _MM_FROUND_NO_EXC with at most one of the +///following: _MM_FROUND_TO_NEAREST_INT, _MM_FROUND_TO_NEG_INF, +///_MM_FROUND_TO_POS_INF, _MM_FROUND_TO_ZERO. /// \returns ///A 256-bit vector of [16 x fp16]. Lower elements correspond to the ///(converted) elements from \a __B; higher order elements correspond to the @@ -343,7 +343,7 @@ _mm256_maskz_cvtx2ps_ph(__mmask16 __U, __m256 __A, __m256 __B) { /// element should be zeroed instead. Rounding mode \a __R needs to be provided. /// /// \code{.operation} -/// FOR i := 0 to 15 +/// FOR i := 0 to 15 ///IF mask[i] ///IF i < 8 ///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i]) @@ -368,9 +368,9 @@ _mm256_maskz_cvtx2ps_ph(__mmask16 __U, __m256 __A, __m256 __B) { ///A 256-bit vector of [8 x float]. /// \param __R ///Rounding mode. Valid inputs are: _MM_FROUND_CUR_DIRECTION or -///result of bitwise or of _MM_FROUND_NO_EXC with at most one of the following: -///_MM_FROUND_TO_NEAREST_INT, _MM_FROUND_TO_NEG_INF, _MM_FROUND_TO_POS_INF, -///_MM_FROUND_TO_ZERO. +///result of bitwise or of _MM_FROUND_NO_EXC with at most one of the +///following: _MM_FROUND_TO_NEAREST_INT, _MM_FROUND_TO_NEG_INF, +///_MM_FROUND_TO_POS_INF, _MM_FROUND_TO_ZERO. /// \returns ///A 256-bit vector of [16 x fp16]. Lower elements correspond to the ///(converted) elements from \a __B; higher order elements correspond to the @@ -421,9 +421,8 @@ _mm_cvtbiasph_pbf8(__m128i __A, __m128h __B) { ///IF __U[i] ///dst.fp8[i] := _W[i] ///ELSE -///dst.fp8[i] := add_convert_fp16_to_fp8_bias(__A.fp16[i], __B.int8[2i]) -///FI -/// ENDFOR +///dst.fp8[i] := add_convert_fp16_to_fp8_bias(__A.fp16[i], +/// __B.int8[2i]) FI ENDFOR /// /// dst[127:64] := 0 /// \endcode @@ -459,10 +458,8 @@ _mm_mask_cvtbiasph_pbf8(__m128i __W, __mmask8 __U, __m128i __A, __m128h __B) { /// \code{.operation} /// FOR i := 0 to 7 ///IF __U[i] -///dst.fp8[i] := add_convert_fp16_to_fp8_bias(__A.fp16[i], __B.int8[2i]) -/// ELSE -///dst.fp8[i] := 0 -/// FI +///dst.fp8[i] := add_c
[clang-tools-extra] [clang-tidy][NFC] extract options verify to sperately function (PR #120768)
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/120768 None >From 0543d52cd0af5ff645bfef0f41d4c1ffcd4b4962 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Sat, 21 Dec 2024 00:25:00 +0800 Subject: [PATCH] [clang-tidy][NFC] extract options verify to sperately function --- clang-tools-extra/clang-tidy/ClangTidy.cpp| 8 ++--- clang-tools-extra/clang-tidy/ClangTidy.h | 6 ++-- .../clang-tidy/tool/ClangTidyMain.cpp | 36 +++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index 9c8c93c5d16c72..959b11777e88d4 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -646,9 +646,9 @@ void exportReplacements(const llvm::StringRef MainFilePath, YAML << TUD; } -NamesAndOptions +ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) { - NamesAndOptions Result; + ChecksAndOptions Result; ClangTidyOptions Opts; Opts.Checks = "*"; clang::tidy::ClangTidyContext Context( @@ -661,7 +661,7 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) { } for (const auto &Factory : Factories) -Result.Names.insert(Factory.getKey()); +Result.Checks.insert(Factory.getKey()); #if CLANG_TIDY_ENABLE_STATIC_ANALYZER SmallString<64> Buffer(AnalyzerCheckNamePrefix); @@ -670,7 +670,7 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) { AllowEnablingAnalyzerAlphaCheckers)) { Buffer.truncate(DefSize); Buffer.append(AnalyzerCheck); -Result.Names.insert(Buffer); +Result.Checks.insert(Buffer); } for (std::string OptionName : { #define GET_CHECKER_OPTIONS diff --git a/clang-tools-extra/clang-tidy/ClangTidy.h b/clang-tools-extra/clang-tidy/ClangTidy.h index 51d9e226c79465..4ffd49f6ebf50f 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.h +++ b/clang-tools-extra/clang-tidy/ClangTidy.h @@ -58,12 +58,12 @@ class ClangTidyASTConsumerFactory { std::vector getCheckNames(const ClangTidyOptions &Options, bool AllowEnablingAnalyzerAlphaCheckers); -struct NamesAndOptions { - llvm::StringSet<> Names; +struct ChecksAndOptions { + llvm::StringSet<> Checks; llvm::StringSet<> Options; }; -NamesAndOptions +ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers = true); /// Returns the effective check-specific options. diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index d42dafa8ffc362..b8d843cba71330 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -526,6 +526,24 @@ static bool verifyFileExtensions( return AnyInvalid; } +static bool verifyOptions(const llvm::StringSet<> &ValidOptions, + const ClangTidyOptions::OptionMap &OptionMap, + StringRef Source) { + bool AnyInvalid = false; + for (auto Key : OptionMap.keys()) { +if (ValidOptions.contains(Key)) + continue; +AnyInvalid = true; +auto &Output = llvm::WithColor::warning(llvm::errs(), Source) + << "unknown check option '" << Key << '\''; +llvm::StringRef Closest = closest(Key, ValidOptions); +if (!Closest.empty()) + Output << "; did you mean '" << Closest << '\''; +Output << VerifyConfigWarningEnd; + } + return AnyInvalid; +} + static SmallString<256> makeAbsolute(llvm::StringRef Input) { if (Input.empty()) return {}; @@ -629,29 +647,17 @@ int clangTidyMain(int argc, const char **argv) { if (VerifyConfig) { std::vector RawOptions = OptionsProvider->getRawOptions(FileName); -NamesAndOptions Valid = +ChecksAndOptions Valid = getAllChecksAndOptions(AllowEnablingAnalyzerAlphaCheckers); bool AnyInvalid = false; for (const auto &[Opts, Source] : RawOptions) { if (Opts.Checks) -AnyInvalid |= verifyChecks(Valid.Names, *Opts.Checks, Source); - +AnyInvalid |= verifyChecks(Valid.Checks, *Opts.Checks, Source); if (Opts.HeaderFileExtensions && Opts.ImplementationFileExtensions) AnyInvalid |= verifyFileExtensions(*Opts.HeaderFileExtensions, *Opts.ImplementationFileExtensions, Source); - - for (auto Key : Opts.CheckOptions.keys()) { -if (Valid.Options.contains(Key)) - continue; -AnyInvalid = true; -auto &Output = llvm::WithColor::warning(llvm::errs(), Source) - << "unknown check option '" << Key << '\''; -llvm::StringRef Closest = closest(Key, Valid.Options); -if (!Closest.empty()) - Output << "; did you mean '" << Closest << '\''; -Output << VerifyConfigWarningEnd; - } + AnyInvalid |= verify
[clang-tools-extra] [clang-tidy][NFC] extract options verify to sperately function (PR #120768)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Congcong Cai (HerrCai0907) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/120768.diff 3 Files Affected: - (modified) clang-tools-extra/clang-tidy/ClangTidy.cpp (+4-4) - (modified) clang-tools-extra/clang-tidy/ClangTidy.h (+3-3) - (modified) clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp (+21-15) ``diff diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index 9c8c93c5d16c72..959b11777e88d4 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -646,9 +646,9 @@ void exportReplacements(const llvm::StringRef MainFilePath, YAML << TUD; } -NamesAndOptions +ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) { - NamesAndOptions Result; + ChecksAndOptions Result; ClangTidyOptions Opts; Opts.Checks = "*"; clang::tidy::ClangTidyContext Context( @@ -661,7 +661,7 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) { } for (const auto &Factory : Factories) -Result.Names.insert(Factory.getKey()); +Result.Checks.insert(Factory.getKey()); #if CLANG_TIDY_ENABLE_STATIC_ANALYZER SmallString<64> Buffer(AnalyzerCheckNamePrefix); @@ -670,7 +670,7 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) { AllowEnablingAnalyzerAlphaCheckers)) { Buffer.truncate(DefSize); Buffer.append(AnalyzerCheck); -Result.Names.insert(Buffer); +Result.Checks.insert(Buffer); } for (std::string OptionName : { #define GET_CHECKER_OPTIONS diff --git a/clang-tools-extra/clang-tidy/ClangTidy.h b/clang-tools-extra/clang-tidy/ClangTidy.h index 51d9e226c79465..4ffd49f6ebf50f 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.h +++ b/clang-tools-extra/clang-tidy/ClangTidy.h @@ -58,12 +58,12 @@ class ClangTidyASTConsumerFactory { std::vector getCheckNames(const ClangTidyOptions &Options, bool AllowEnablingAnalyzerAlphaCheckers); -struct NamesAndOptions { - llvm::StringSet<> Names; +struct ChecksAndOptions { + llvm::StringSet<> Checks; llvm::StringSet<> Options; }; -NamesAndOptions +ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers = true); /// Returns the effective check-specific options. diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index d42dafa8ffc362..b8d843cba71330 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -526,6 +526,24 @@ static bool verifyFileExtensions( return AnyInvalid; } +static bool verifyOptions(const llvm::StringSet<> &ValidOptions, + const ClangTidyOptions::OptionMap &OptionMap, + StringRef Source) { + bool AnyInvalid = false; + for (auto Key : OptionMap.keys()) { +if (ValidOptions.contains(Key)) + continue; +AnyInvalid = true; +auto &Output = llvm::WithColor::warning(llvm::errs(), Source) + << "unknown check option '" << Key << '\''; +llvm::StringRef Closest = closest(Key, ValidOptions); +if (!Closest.empty()) + Output << "; did you mean '" << Closest << '\''; +Output << VerifyConfigWarningEnd; + } + return AnyInvalid; +} + static SmallString<256> makeAbsolute(llvm::StringRef Input) { if (Input.empty()) return {}; @@ -629,29 +647,17 @@ int clangTidyMain(int argc, const char **argv) { if (VerifyConfig) { std::vector RawOptions = OptionsProvider->getRawOptions(FileName); -NamesAndOptions Valid = +ChecksAndOptions Valid = getAllChecksAndOptions(AllowEnablingAnalyzerAlphaCheckers); bool AnyInvalid = false; for (const auto &[Opts, Source] : RawOptions) { if (Opts.Checks) -AnyInvalid |= verifyChecks(Valid.Names, *Opts.Checks, Source); - +AnyInvalid |= verifyChecks(Valid.Checks, *Opts.Checks, Source); if (Opts.HeaderFileExtensions && Opts.ImplementationFileExtensions) AnyInvalid |= verifyFileExtensions(*Opts.HeaderFileExtensions, *Opts.ImplementationFileExtensions, Source); - - for (auto Key : Opts.CheckOptions.keys()) { -if (Valid.Options.contains(Key)) - continue; -AnyInvalid = true; -auto &Output = llvm::WithColor::warning(llvm::errs(), Source) - << "unknown check option '" << Key << '\''; -llvm::StringRef Closest = closest(Key, Valid.Options); -if (!Closest.empty()) - Output << "; did you mean '" << Closest << '\''; -Output << VerifyConfigWarningEnd; - } + AnyInvalid |= verifyOptions(Valid.Options, Opts.CheckOptions, Source); } if (AnyInvalid) return 1; `` https://github.com/llvm/l
[clang-tools-extra] [clang-tidy][NFC] extract options verify to sperately function (PR #120768)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy Author: Congcong Cai (HerrCai0907) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/120768.diff 3 Files Affected: - (modified) clang-tools-extra/clang-tidy/ClangTidy.cpp (+4-4) - (modified) clang-tools-extra/clang-tidy/ClangTidy.h (+3-3) - (modified) clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp (+21-15) ``diff diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index 9c8c93c5d16c72..959b11777e88d4 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -646,9 +646,9 @@ void exportReplacements(const llvm::StringRef MainFilePath, YAML << TUD; } -NamesAndOptions +ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) { - NamesAndOptions Result; + ChecksAndOptions Result; ClangTidyOptions Opts; Opts.Checks = "*"; clang::tidy::ClangTidyContext Context( @@ -661,7 +661,7 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) { } for (const auto &Factory : Factories) -Result.Names.insert(Factory.getKey()); +Result.Checks.insert(Factory.getKey()); #if CLANG_TIDY_ENABLE_STATIC_ANALYZER SmallString<64> Buffer(AnalyzerCheckNamePrefix); @@ -670,7 +670,7 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) { AllowEnablingAnalyzerAlphaCheckers)) { Buffer.truncate(DefSize); Buffer.append(AnalyzerCheck); -Result.Names.insert(Buffer); +Result.Checks.insert(Buffer); } for (std::string OptionName : { #define GET_CHECKER_OPTIONS diff --git a/clang-tools-extra/clang-tidy/ClangTidy.h b/clang-tools-extra/clang-tidy/ClangTidy.h index 51d9e226c79465..4ffd49f6ebf50f 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.h +++ b/clang-tools-extra/clang-tidy/ClangTidy.h @@ -58,12 +58,12 @@ class ClangTidyASTConsumerFactory { std::vector getCheckNames(const ClangTidyOptions &Options, bool AllowEnablingAnalyzerAlphaCheckers); -struct NamesAndOptions { - llvm::StringSet<> Names; +struct ChecksAndOptions { + llvm::StringSet<> Checks; llvm::StringSet<> Options; }; -NamesAndOptions +ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers = true); /// Returns the effective check-specific options. diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index d42dafa8ffc362..b8d843cba71330 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -526,6 +526,24 @@ static bool verifyFileExtensions( return AnyInvalid; } +static bool verifyOptions(const llvm::StringSet<> &ValidOptions, + const ClangTidyOptions::OptionMap &OptionMap, + StringRef Source) { + bool AnyInvalid = false; + for (auto Key : OptionMap.keys()) { +if (ValidOptions.contains(Key)) + continue; +AnyInvalid = true; +auto &Output = llvm::WithColor::warning(llvm::errs(), Source) + << "unknown check option '" << Key << '\''; +llvm::StringRef Closest = closest(Key, ValidOptions); +if (!Closest.empty()) + Output << "; did you mean '" << Closest << '\''; +Output << VerifyConfigWarningEnd; + } + return AnyInvalid; +} + static SmallString<256> makeAbsolute(llvm::StringRef Input) { if (Input.empty()) return {}; @@ -629,29 +647,17 @@ int clangTidyMain(int argc, const char **argv) { if (VerifyConfig) { std::vector RawOptions = OptionsProvider->getRawOptions(FileName); -NamesAndOptions Valid = +ChecksAndOptions Valid = getAllChecksAndOptions(AllowEnablingAnalyzerAlphaCheckers); bool AnyInvalid = false; for (const auto &[Opts, Source] : RawOptions) { if (Opts.Checks) -AnyInvalid |= verifyChecks(Valid.Names, *Opts.Checks, Source); - +AnyInvalid |= verifyChecks(Valid.Checks, *Opts.Checks, Source); if (Opts.HeaderFileExtensions && Opts.ImplementationFileExtensions) AnyInvalid |= verifyFileExtensions(*Opts.HeaderFileExtensions, *Opts.ImplementationFileExtensions, Source); - - for (auto Key : Opts.CheckOptions.keys()) { -if (Valid.Options.contains(Key)) - continue; -AnyInvalid = true; -auto &Output = llvm::WithColor::warning(llvm::errs(), Source) - << "unknown check option '" << Key << '\''; -llvm::StringRef Closest = closest(Key, Valid.Options); -if (!Closest.empty()) - Output << "; did you mean '" << Closest << '\''; -Output << VerifyConfigWarningEnd; - } + AnyInvalid |= verifyOptions(Valid.Options, Opts.CheckOptions, Source); } if (AnyInvalid) return 1; `` https://github.com/llvm/llvm-pro
[clang] [clang][ObjectiveC] Fix Parsing the `::` Optional Scope Specifier (PR #119908)
https://github.com/cyndyishida approved this pull request. https://github.com/llvm/llvm-project/pull/119908 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Don't assume third iteration in loops (PR #119388)
NagyDonat wrote: > > [...] To fix this problem, it would be sufficient to e.g. ensure that > > evalEagerlyAssumeBifurcation sets LastEagerlyAssumeBifurcationAt to nullptr > > [...] > > Sounds good to me. Let's zero it out after it's "used"/"consumed". I took a different approach (which was already mostly implemented when I've seen this suggestion): I'm setting the stored `Expr *` to nullpointer when I encounter an `EagerlyAssume` which does not succeed (i.e. at most one branch is feasible). I also added a dedicated test file which shows that this change works (and demonstrates other features and limitations of the commit). > > [...] there might be better solutions to implement this "did EagerlyAssume > > split the state right now directly before this processBranch callback?" > > check that I need. (E.g. perhaps we could walk a few steps backwards on the > > ExplodedGraph -- but I don't know what kinds of nodes should I expect and > > I'm afraid that what I could write would run into pitfalls in unusual > > cases.) > > Yes, it could get messy. For instance if we have multiple parent nodes due to > a merge. Let's not do traversals. OK, if you say so, I'm very happy to avoid it :grinning: > I'm good with the change once the last remark is fixed. BTW have you measured > the running time implications of this patch? How much we spare? I don't expect running _time_ implications, because as we discard these execution paths, the analyzer will traverse other execution paths instead of them -- so the performance gains should appear as "more results" instead of "faster analysis". Unfortunately the improvements that I hoped didn't appear in the experimental results: the "final" version of this commit doesn't produce significantly more results compared to the "intermediate" version which just suppresses the results (after "wasting time" on traversing the unjustified paths). I think we don't see visible performance improvements because my observation that "difference between 2 or 3 iterations is irrelevant on the later parts of the execution path" does not imply that we can save a significant amount of calculations by driving each of those paths through 2 iterations (instead of roughly half 2 iterations, half 3 iterations) -- because those paths differ in many assumptions, so we cannot merge them even if we ignore the iteration count in that particular loop. Additionally, my measurements are on stable open source projects, where real results are much rarer than false positives (even on stable checkers), so the number of results that we get is an imperfect and somewhat noisy proxy of the actual improvements. https://github.com/llvm/llvm-project/pull/119388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC] extract options verify to separately function (PR #120768)
https://github.com/HerrCai0907 edited https://github.com/llvm/llvm-project/pull/120768 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ObjectiveC] Fix Parsing the `::` Optional Scope Specifier (PR #119908)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/119908 >From 63c424414c1814ec9b4c3c5a459bfe1be684586d Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Fri, 13 Dec 2024 09:41:41 -0800 Subject: [PATCH 1/4] Fix parsing :: in method parameter type. --- clang/lib/Parse/Parser.cpp | 8 +++- clang/test/Parser/objc-coloncolon.m | 5 + 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 clang/test/Parser/objc-coloncolon.m diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 36e56a92c3092e..aa78d702553172 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -,8 +,14 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec( } } - if (SS.isEmpty()) + if (SS.isEmpty()) { +if (getLangOpts().ObjC && Tok.is(tok::coloncolon)) { + // ObjectiveC does not allow :: as as a scope token. + Diag(ConsumeToken(), diag::err_expected_type); + return true; +} return false; + } // A C++ scope specifier that isn't followed by a typename. AnnotateScopeToken(SS, IsNewScope); diff --git a/clang/test/Parser/objc-coloncolon.m b/clang/test/Parser/objc-coloncolon.m new file mode 100644 index 00..e8a09898263bb3 --- /dev/null +++ b/clang/test/Parser/objc-coloncolon.m @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s + +@interface A +- (instancetype)init:(::A *) foo; // expected-error {{expected a type}} +@end >From ec903eb3fcd18ba53af901582060bd61b13cf324 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Mon, 16 Dec 2024 09:34:52 -0800 Subject: [PATCH 2/4] Fix ObjectiveC++ --- clang/lib/Parse/Parser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index aa78d702553172..8ba6a5dce8a994 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -2223,7 +2223,8 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec( } if (SS.isEmpty()) { -if (getLangOpts().ObjC && Tok.is(tok::coloncolon)) { +if (getLangOpts().ObjC && !getLangOpts().CPlusPlus && +Tok.is(tok::coloncolon)) { // ObjectiveC does not allow :: as as a scope token. Diag(ConsumeToken(), diag::err_expected_type); return true; >From 66c3b0b874f5a962ff902c43d33fbb22c658780c Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 18 Dec 2024 09:49:15 -0800 Subject: [PATCH 3/4] Address code review. --- clang/docs/ReleaseNotes.rst| 3 +++ clang/test/Parser/objc-coloncolon.m| 12 ++-- clang/test/Parser/objcxx-coloncolon.mm | 9 + 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 clang/test/Parser/objcxx-coloncolon.mm diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 26fa986810a4b8..d6d3149df07d87 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -675,6 +675,9 @@ Improvements to Clang's diagnostics views.push_back(std::string("123")); // warning } +- Fixed a bug where Clang hangs on unsupported optional scope specifier ``::`` when parsing + Objective-C. Clang now emits a diagnostic message instead of hanging. + Improvements to Clang's time-trace -- diff --git a/clang/test/Parser/objc-coloncolon.m b/clang/test/Parser/objc-coloncolon.m index e8a09898263bb3..68b54ef5229af5 100644 --- a/clang/test/Parser/objc-coloncolon.m +++ b/clang/test/Parser/objc-coloncolon.m @@ -1,5 +1,13 @@ -// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s +// RUN: %clang_cc1 -x objective-c -fsyntax-only -Wno-objc-root-class -verify %s + +int GV = 42; @interface A -- (instancetype)init:(::A *) foo; // expected-error {{expected a type}} ++ (int) getGV; +- (instancetype)init:(::A *) foo; // expected-error {{expected a type}} +@end + +@implementation A ++ (int) getGV { return ::GV; } // expected-error {{expected a type}} +- (instancetype)init:(::A *) foo { return self; } // expected-error {{expected a type}} @end diff --git a/clang/test/Parser/objcxx-coloncolon.mm b/clang/test/Parser/objcxx-coloncolon.mm new file mode 100644 index 00..864a7df8400c1c --- /dev/null +++ b/clang/test/Parser/objcxx-coloncolon.mm @@ -0,0 +1,9 @@ +// Test to make sure the parser does not get stuck on the optional +// scope specifier on the type B. +// RUN: %clang_cc1 -fsyntax-only %s + +class B; + +@interface A +- (void) init:(::B *) foo; +@end >From 2e0667d1f21f406be8c9ae1f10eb12f60296ddd8 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 18 Dec 2024 11:10:16 -0800 Subject: [PATCH 4/4] Modifying the test to include valid Objective-C with --- clang/test/Parser/objc-coloncolon.m | 6 ++ 1 file changed, 6 insertions(+) diff --git a/clang/test/Parser/objc-coloncolon.m b/clang/test/Parser/objc-coloncolon.m index 68b54ef5229af5..04a24fd81ec08f 100644 --- a/clang/test/Parser/objc-coloncolon.m +++ b/clang/t
[clang-tools-extra] [clang-tidy][NFC][doc] mention some range algorithms do not work for `vector` in C++20 (PR #120774)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy Author: Congcong Cai (HerrCai0907) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/120774.diff 1 Files Affected: - (modified) clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst (+3) ``diff diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst index 1ce866ca1f66a0..912b42b33f9194 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst @@ -104,6 +104,9 @@ Calls to the following std library algorithms are checked: ``std::unique``, ``std::upper_bound``. +Note: some range algorithms for ``vector`` require C++23 because it uses +proxy iterators. + Reverse Iteration - `` https://github.com/llvm/llvm-project/pull/120774 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC][doc] mention some range algorithms do not work for `vector` in C++20 (PR #120774)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Congcong Cai (HerrCai0907) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/120774.diff 1 Files Affected: - (modified) clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst (+3) ``diff diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst index 1ce866ca1f66a0..912b42b33f9194 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst @@ -104,6 +104,9 @@ Calls to the following std library algorithms are checked: ``std::unique``, ``std::upper_bound``. +Note: some range algorithms for ``vector`` require C++23 because it uses +proxy iterators. + Reverse Iteration - `` https://github.com/llvm/llvm-project/pull/120774 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC][doc] mention some range algorithms do not work for `vector` in C++20 (PR #120774)
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/120774 None >From b8f686aa8fa45ab50c45c16d6b4eeea99de64bcb Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Sat, 21 Dec 2024 01:01:14 +0800 Subject: [PATCH] [clang-tidy][NFC][doc] mention some range algorithms do not work for `vector` in C++20 --- .../docs/clang-tidy/checks/modernize/use-ranges.rst| 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst index 1ce866ca1f66a0..912b42b33f9194 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst @@ -104,6 +104,9 @@ Calls to the following std library algorithms are checked: ``std::unique``, ``std::upper_bound``. +Note: some range algorithms for ``vector`` require C++23 because it uses +proxy iterators. + Reverse Iteration - ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Re-write codegen for atomic_test_and_set and atomic_clear (PR #120449)
metaflow wrote: @ostannard :christmas_tree: :santa: happy holidays https://github.com/llvm/llvm-project/pull/120449 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [webkit.UncountedLambdaCapturesChecker] Fix a nullptr deference. (PR #120702)
https://github.com/Xazax-hun approved this pull request. https://github.com/llvm/llvm-project/pull/120702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Patch series to reapply #118734 and substantially improve it (PR #120534)
h-vetinari wrote: I've [tested](https://github.com/conda-forge/clangdev-feedstock/pull/333) this PR (as of 2bcc4e5f7043dab1ef673dd20b38009363db51db) in our infrastructure and can confirm that things run fine with VS2019 again. Thanks a lot for reworking this! 🙏 https://github.com/llvm/llvm-project/pull/120534 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cf7b3f8 - Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (#118186)
Author: William Tran-Viet Date: 2024-12-20T13:40:17+01:00 New Revision: cf7b3f8d827abba49930202e51702714349c716d URL: https://github.com/llvm/llvm-project/commit/cf7b3f8d827abba49930202e51702714349c716d DIFF: https://github.com/llvm/llvm-project/commit/cf7b3f8d827abba49930202e51702714349c716d.diff LOG: Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (#118186) Fixes #116932 - Remove the quotation marks in the diagnostic message for err_ext_vector_component_name_illegal - Pass in the quotation marks directly when reporting an illegal vector component name inside `CheckExtVectorComponent` - Add an offset to the `OpLoc` passed into `S.Diag` so the error message arrow points directly to the offending illegal component rather than to the '.' at the start of the component identifier. - Modify the `vector-bool.cpp` element-wise access test case so it (correctly) now only expects a single set of quotes. Added: Modified: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaExprMember.cpp clang/test/SemaCXX/vector-bool.cpp Removed: diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8d19e9030ac2e3..491bc83c1e1297 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3423,7 +3423,7 @@ def warn_typecheck_vector_element_sizes_not_equal : Warning< def err_ext_vector_component_exceeds_length : Error< "vector component access exceeds type %0">; def err_ext_vector_component_name_illegal : Error< - "illegal vector component name '%0'">; + "illegal vector component name %0">; def err_attribute_address_space_negative : Error< "address space is negative">; def err_attribute_address_space_too_high : Error< diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index bcc1b92ffdec73..d130e8b86bc56d 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -434,8 +434,11 @@ CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK, if (!HalvingSwizzle && *compStr) { // We didn't get to the end of the string. This means the component names // didn't come from the same set *or* we encountered an illegal name. -S.Diag(OpLoc, diag::err_ext_vector_component_name_illegal) - << StringRef(compStr, 1) << SourceRange(CompLoc); +size_t Offset = compStr - CompName->getNameStart() + 1; +char Fmt[3] = {'\'', *compStr, '\''}; +S.Diag(OpLoc.getLocWithOffset(Offset), + diag::err_ext_vector_component_name_illegal) +<< StringRef(Fmt, 3) << SourceRange(CompLoc); return QualType(); } diff --git a/clang/test/SemaCXX/vector-bool.cpp b/clang/test/SemaCXX/vector-bool.cpp index e99d420e73fab2..cd638056f348b0 100644 --- a/clang/test/SemaCXX/vector-bool.cpp +++ b/clang/test/SemaCXX/vector-bool.cpp @@ -85,10 +85,10 @@ void foo(const bool& X); // Disallow element-wise access. bool* ElementRefs() { - eight_bools.y = false; // expected-error@88 {{illegal vector component name ''y''}} - &eight_bools.z;// expected-error@89 {{illegal vector component name ''z''}} - foo(eight_bools.w);// expected-error@90 {{illegal vector component name ''w''}} - foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name ''wyx''}} + eight_bools.y = false; // expected-error@88 {{illegal vector component name 'y'}} + &eight_bools.z;// expected-error@89 {{illegal vector component name 'z'}} + foo(eight_bools.w);// expected-error@90 {{illegal vector component name 'w'}} + foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name 'wyx'}} } void Sizeof() { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (PR #118186)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/118186 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ConstantRange] Estimate tighter lower (upper) bounds for masked binary and (or) (PR #120352)
@@ -1520,15 +1520,101 @@ ConstantRange ConstantRange::binaryNot() const { return ConstantRange(APInt::getAllOnes(getBitWidth())).sub(*this); } +/// Estimate the 'bit-masked AND' operation's lower bound. +/// +/// E.g., given two ranges as follows (single quotes are separators and +/// have no meaning here), +/// +/// LHS = [10'001'010, ; LLo +/// 10'100'000] ; LHi +/// RHS = [10'111'010, ; RLo +/// 10'111'100] ; RHi +/// +/// we know that the higher 2 bits of the result is always '10'; and note that +/// there's at least one bit is 1 in LHS[3:6] (since the range is continuous), +/// and all bits in RHS[3:6] are 1, so we know the lower bound of the result is +/// 10'001'000. +/// +/// The algorithm is as follows, +/// 1. we first calculate a mask to mask out the higher common bits by +/// Mask = (LLo ^ LHi) | (LLo ^ LHi) | (LLo ^ RLo); +/// Mask = set all non-leading-zero bits to 1 for Mask; +/// 2. find the bit field with at least 1 in LHS (i.e., bit 3:6 in the example) +///after applying the mask, with +/// StartBit = BitWidth - (LLo & Mask).clz() - 1; +/// EndBit = BitWidth - (LHi & Mask).clz(); +/// 3. check if all bits in [StartBit:EndBit] in RHS are 1, and all bits of +///RLo and RHi in [StartBit:BitWidth] are same, and if so, the lower bound +///can be updated to +/// LowerBound = LLo & Keep; +///where Keep is a mask to mask out trailing bits (the lower 3 bits in the +///example); +/// 4. repeat the step 2 and 3 with LHS and RHS swapped, and update the lower +///bound with the larger one. +static APInt estimateBitMaskedAndLowerBound(const ConstantRange &LHS, +const ConstantRange &RHS) { + auto BitWidth = LHS.getBitWidth(); + // If either is full set or unsigned wrapped, then the range must contain '0' + // which leads the lower bound to 0. + if ((LHS.isFullSet() || RHS.isFullSet()) || + (LHS.isWrappedSet() || RHS.isWrappedSet())) +return APInt::getZero(BitWidth); + + auto LLo = LHS.getLower(); + auto LHi = LHS.getUpper() - 1; + auto RLo = RHS.getLower(); + auto RHi = RHS.getUpper() - 1; + + // Calculate the mask that mask out the higher common bits. + auto Mask = (LLo ^ LHi) | (RLo ^ RHi) | (LLo ^ RLo); + unsigned LeadingZeros = Mask.countLeadingZeros(); + Mask.setLowBits(BitWidth - LeadingZeros); + + auto estimateBound = + [BitWidth, &Mask](const APInt &ALo, const APInt &AHi, const APInt &BLo, +const APInt &BHi) -> std::optional { +unsigned LeadingZeros = (ALo & Mask).countLeadingZeros(); +if (LeadingZeros == BitWidth) + return std::nullopt; + +unsigned StartBit = BitWidth - LeadingZeros - 1; dtcxzyw wrote: Can we extend this algorithm to make the result optimal for all non-wrapped ranges? An example: `[7, 14) & [-1, 0)` should produce `[7, 14)`. But currently it gives `[4, 14)`. You can apply the following patch to get more sub-optimal cases :) ``` diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp index e1d9b3e387b2..1a616269e3b7 100644 --- a/llvm/unittests/IR/ConstantRangeTest.cpp +++ b/llvm/unittests/IR/ConstantRangeTest.cpp @@ -2725,7 +2725,7 @@ TEST_F(ConstantRangeTest, binaryAnd) { return CR1.binaryAnd(CR2); }, [](const APInt &N1, const APInt &N2) { return N1 & N2; }, PreferSmallest, - CheckSingleElementsOnly); + CheckNonWrappedOnly); } TEST_F(ConstantRangeTest, binaryOr) { ``` https://github.com/llvm/llvm-project/pull/120352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang-CL][DXC] Expose -fdiagnostic-color= to clang-cl and clang-dxc (PR #120644)
https://github.com/Maetveis requested changes to this pull request. Thank you, mostly looks good, I think the tests can be made simpler. And I think adding release notes would benefit users. You can add a new point to "New Compiler Flags" in the clang release notes that clang-cl and clang-dxc now also accept`-fdiagnostics-color=[auto|never|always]` in addition to `-f[no-]color-diagnostics`. https://github.com/llvm/llvm-project/pull/120644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang-CL][DXC] Expose -fdiagnostic-color= to clang-cl and clang-dxc (PR #120644)
https://github.com/Maetveis edited https://github.com/llvm/llvm-project/pull/120644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang-CL][DXC] Expose -fdiagnostic-color= to clang-cl and clang-dxc (PR #120644)
@@ -0,0 +1,8 @@ +// The test doesn't run in a PTY, so "auto" defaults to off. Maetveis wrote: Similarly here I think its enough to check that the option is accepted, no real need to verify what it does. ```c // RUN: %clang_dxc \ // RUN: -fcolor-diagnostics \ // RUN: -fno-color-diagnostics \ // RUN: -fdiagnostics-color \ // RUN: -fno-diagnostics-color \ // RUN: -fdiagnostics-color=auto \ // RUN: -Tlib_6_7 -Vd -fdriver-only -- %s 2>&1 | count 0 ``` (Might as well test all the other color flags while at it too). (`-fdriver-only` and `count 0` should make sure we don't get any warnings not just errors). Also NIT: Make sure to have a final newline in the file. https://github.com/llvm/llvm-project/pull/120644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang-CL][DXC] Expose -fdiagnostic-color= to clang-cl and clang-dxc (PR #120644)
@@ -664,6 +664,15 @@ // RUN: not %clang_cl /guard:foo -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARDINVALID %s // CFGUARDINVALID: invalid value 'foo' in '/guard:' +// The test doesn't run in a PTY, so "auto" defaults to off. +// RUN: %clang_cl -fdiagnostics-color=auto -### -- %s 2>&1 | FileCheck -check-prefix=NO_COLOR %s + +// RUN: %clang_cl -fdiagnostics-color -### -- %s 2>&1 | FileCheck -check-prefix=COLOR %s +// RUN: %clang_cl -fdiagnostics-color=always -### -- %s 2>&1 | FileCheck -check-prefix=COLOR %s +// RUN: %clang_cl -fdiagnostics-color=never -### -- %s 2>&1 | FileCheck -check-prefix=NO_COLOR %s +// COLOR: "-fcolor-diagnostics" Maetveis wrote: I think you should instead add `-fcolor-diagnostics=auto` to the list below, no need to check the functionality again in clang-cl, it is already sufficiently tested IMO by [clang/test/Driver/color-diagnostics.c](https://github.com/llvm/llvm-project/blob/2405c5fb3ed49b928bb2816ace7b67c8979cd9d7/clang/test/Driver/color-diagnostics.c) ```diff // RUN: -fno-coverage-mapping \ // RUN: -fdiagnostics-color \ +// RUN: -fdiagnostics-color=auto \ // RUN: -fno-diagnostics-color \ // RUN: -fdebug-compilation-dir . \ // RUN: -fdebug-compilation-dir=. \ // RUN: -ffile-compilation-dir=. \ ``` https://github.com/llvm/llvm-project/pull/120644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Adjust pointer-overflow sanitizer for N3322 (PR #120719)
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/120719 >From bd7a8273d07725d898188df00c708b5a52d68ac7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 20 Dec 2024 12:41:01 +0100 Subject: [PATCH 1/2] [Clang] Adjust pointer-overflow sanitizer for N3322 N3322 makes NULL + 0 well-defined in C, matching the C++ semantics. Adjust the pointer-overflow sanitizer to no longer report NULL + 0 as a pointer overflow in any language mode. NULL + nonzero will of course continue to be reported. As N3322 is part of https://www.open-std.org/jtc1/sc22/wg14/www/previous.html, and we never performed any optimizations based on NULL + 0 being undefined in the first place, I'm applying this change to all C versions. --- clang/lib/CodeGen/CGExprScalar.cpp| 16 +--- ...d-nonzero-offset-when-nullptr-is-defined.c | 15 ++- .../catch-nullptr-and-nonzero-offset.c| 95 --- .../CodeGen/catch-pointer-overflow-volatile.c | 15 ++- clang/test/CodeGen/catch-pointer-overflow.c | 36 +++ clang/test/CodeGen/ubsan-pointer-overflow.c | 7 +- 6 files changed, 54 insertions(+), 130 deletions(-) diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 4b71bd730ce12c..0724b4265e96b2 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -5839,9 +5839,8 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *ElemTy, Value *Ptr, auto *Zero = llvm::ConstantInt::getNullValue(IntPtrTy); - // Common case: if the total offset is zero, and we are using C++ semantics, - // where nullptr+0 is defined, don't emit a check. - if (EvaluatedGEP.TotalOffset == Zero && CGM.getLangOpts().CPlusPlus) + // Common case: if the total offset is zero, don't emit a check. + if (EvaluatedGEP.TotalOffset == Zero) return GEPVal; // Now that we've computed the total offset, add it to the base pointer (with @@ -5852,23 +5851,16 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *ElemTy, Value *Ptr, llvm::SmallVector, 2> Checks; if (PerformNullCheck) { -// In C++, if the base pointer evaluates to a null pointer value, +// If the base pointer evaluates to a null pointer value, // the only valid pointer this inbounds GEP can produce is also // a null pointer, so the offset must also evaluate to zero. // Likewise, if we have non-zero base pointer, we can not get null pointer // as a result, so the offset can not be -intptr_t(BasePtr). // In other words, both pointers are either null, or both are non-null, // or the behaviour is undefined. -// -// C, however, is more strict in this regard, and gives more -// optimization opportunities: in C, additionally, nullptr+0 is undefined. -// So both the input to the 'gep inbounds' AND the output must not be null. auto *BaseIsNotNullptr = Builder.CreateIsNotNull(Ptr); auto *ResultIsNotNullptr = Builder.CreateIsNotNull(ComputedGEP); -auto *Valid = -CGM.getLangOpts().CPlusPlus -? Builder.CreateICmpEQ(BaseIsNotNullptr, ResultIsNotNullptr) -: Builder.CreateAnd(BaseIsNotNullptr, ResultIsNotNullptr); +auto *Valid = Builder.CreateICmpEQ(BaseIsNotNullptr, ResultIsNotNullptr); Checks.emplace_back(Valid, SanitizerKind::PointerOverflow); } diff --git a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c index 8a560a47ad1e10..00198b4faf8bcc 100644 --- a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c +++ b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -x c -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fno-sanitize-recover=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_pointer_overflow" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-NULLNOTOK,CHECK-SANITIZE-NULLNOTOK-C,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE -// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fsanitize-recover=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_pointer_overflow" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-NULLNOTOK,CHECK-SANITIZE-NULLNOTOK-C,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER -// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fsanitize-trap=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_pointer_overflow" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-NULLNOTOK,CHECK-SANITIZE-NULLNOTOK-C,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE +// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fno-saniti
[clang] [lld] [llvm] Remove `urllib2` and `SocketServer` (PR #120723)
@@ -39,7 +36,6 @@ def url_is_up(url): def start_browser(port, options): -import webbrowser vinay-deshmukh wrote: Due to this import, the import on L17 is unused. let me know if keeping this one and removing the import from L17 is more preferable. https://github.com/llvm/llvm-project/pull/120723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] Remove `urllib2` and `SocketServer` (PR #120723)
github-actions[bot] wrote: ⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo. Please turn off [Keep my email addresses private](https://github.com/settings/emails) setting in your account. See [LLVM Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it) for more information. https://github.com/llvm/llvm-project/pull/120723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Adjust pointer-overflow sanitizer for N3322 (PR #120719)
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/120719 >From bd7a8273d07725d898188df00c708b5a52d68ac7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 20 Dec 2024 12:41:01 +0100 Subject: [PATCH 1/3] [Clang] Adjust pointer-overflow sanitizer for N3322 N3322 makes NULL + 0 well-defined in C, matching the C++ semantics. Adjust the pointer-overflow sanitizer to no longer report NULL + 0 as a pointer overflow in any language mode. NULL + nonzero will of course continue to be reported. As N3322 is part of https://www.open-std.org/jtc1/sc22/wg14/www/previous.html, and we never performed any optimizations based on NULL + 0 being undefined in the first place, I'm applying this change to all C versions. --- clang/lib/CodeGen/CGExprScalar.cpp| 16 +--- ...d-nonzero-offset-when-nullptr-is-defined.c | 15 ++- .../catch-nullptr-and-nonzero-offset.c| 95 --- .../CodeGen/catch-pointer-overflow-volatile.c | 15 ++- clang/test/CodeGen/catch-pointer-overflow.c | 36 +++ clang/test/CodeGen/ubsan-pointer-overflow.c | 7 +- 6 files changed, 54 insertions(+), 130 deletions(-) diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 4b71bd730ce12c..0724b4265e96b2 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -5839,9 +5839,8 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *ElemTy, Value *Ptr, auto *Zero = llvm::ConstantInt::getNullValue(IntPtrTy); - // Common case: if the total offset is zero, and we are using C++ semantics, - // where nullptr+0 is defined, don't emit a check. - if (EvaluatedGEP.TotalOffset == Zero && CGM.getLangOpts().CPlusPlus) + // Common case: if the total offset is zero, don't emit a check. + if (EvaluatedGEP.TotalOffset == Zero) return GEPVal; // Now that we've computed the total offset, add it to the base pointer (with @@ -5852,23 +5851,16 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *ElemTy, Value *Ptr, llvm::SmallVector, 2> Checks; if (PerformNullCheck) { -// In C++, if the base pointer evaluates to a null pointer value, +// If the base pointer evaluates to a null pointer value, // the only valid pointer this inbounds GEP can produce is also // a null pointer, so the offset must also evaluate to zero. // Likewise, if we have non-zero base pointer, we can not get null pointer // as a result, so the offset can not be -intptr_t(BasePtr). // In other words, both pointers are either null, or both are non-null, // or the behaviour is undefined. -// -// C, however, is more strict in this regard, and gives more -// optimization opportunities: in C, additionally, nullptr+0 is undefined. -// So both the input to the 'gep inbounds' AND the output must not be null. auto *BaseIsNotNullptr = Builder.CreateIsNotNull(Ptr); auto *ResultIsNotNullptr = Builder.CreateIsNotNull(ComputedGEP); -auto *Valid = -CGM.getLangOpts().CPlusPlus -? Builder.CreateICmpEQ(BaseIsNotNullptr, ResultIsNotNullptr) -: Builder.CreateAnd(BaseIsNotNullptr, ResultIsNotNullptr); +auto *Valid = Builder.CreateICmpEQ(BaseIsNotNullptr, ResultIsNotNullptr); Checks.emplace_back(Valid, SanitizerKind::PointerOverflow); } diff --git a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c index 8a560a47ad1e10..00198b4faf8bcc 100644 --- a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c +++ b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -x c -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fno-sanitize-recover=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_pointer_overflow" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-NULLNOTOK,CHECK-SANITIZE-NULLNOTOK-C,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE -// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fsanitize-recover=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_pointer_overflow" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-NULLNOTOK,CHECK-SANITIZE-NULLNOTOK-C,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER -// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fsanitize-trap=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_pointer_overflow" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-NULLNOTOK,CHECK-SANITIZE-NULLNOTOK-C,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE +// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fno-saniti
[clang] [lld] [llvm] Remove `urllib2` and `SocketServer` (PR #120723)
https://github.com/vinay-deshmukh created https://github.com/llvm/llvm-project/pull/120723 Resolves #120299 1. Testing in CI >From 5f7a46d117053b582b8ee4c91a46e5edd84fbad2 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:56:26 +0530 Subject: [PATCH 1/3] Remove `urllib2` --- clang/docs/tools/dump_ast_matchers.py | 5 + clang/tools/scan-view/bin/scan-view | 5 + lld/utils/benchmark.py| 8 ++-- llvm/utils/unicode-case-fold.py | 5 + 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/clang/docs/tools/dump_ast_matchers.py b/clang/docs/tools/dump_ast_matchers.py index b6f00657ec914c..4c4a2bd1e9d5a7 100755 --- a/clang/docs/tools/dump_ast_matchers.py +++ b/clang/docs/tools/dump_ast_matchers.py @@ -7,10 +7,7 @@ import re import os -try: -from urllib.request import urlopen -except ImportError: -from urllib2 import urlopen +from urllib.request import urlopen CLASS_INDEX_PAGE_URL = "https://clang.llvm.org/doxygen/classes.html"; try: diff --git a/clang/tools/scan-view/bin/scan-view b/clang/tools/scan-view/bin/scan-view index d01aebb4029a75..f8dc6c18018de1 100755 --- a/clang/tools/scan-view/bin/scan-view +++ b/clang/tools/scan-view/bin/scan-view @@ -10,10 +10,7 @@ import os import posixpath import threading import time -try: -from urllib.request import urlopen -except ImportError: -from urllib2 import urlopen +from urllib.request import urlopen import webbrowser # How long to wait for server to start. diff --git a/lld/utils/benchmark.py b/lld/utils/benchmark.py index 7202e07ec438d2..4257f6bb160565 100755 --- a/lld/utils/benchmark.py +++ b/lld/utils/benchmark.py @@ -14,12 +14,8 @@ import datetime import argparse -try: -from urllib.parse import urlencode -from urllib.request import urlopen, Request -except ImportError: -from urllib import urlencode -from urllib2 import urlopen, Request +from urllib.parse import urlencode +from urllib.request import urlopen, Request parser = argparse.ArgumentParser() diff --git a/llvm/utils/unicode-case-fold.py b/llvm/utils/unicode-case-fold.py index 9639aa0dc44b41..3ef12a0ef881a8 100755 --- a/llvm/utils/unicode-case-fold.py +++ b/llvm/utils/unicode-case-fold.py @@ -22,10 +22,7 @@ import sys import re -try: -from urllib.request import urlopen -except ImportError: -from urllib2 import urlopen +from urllib.request import urlopen # This variable will body of the mappings function >From d73faddf37c8d880f9f44a02a4df4290aac0f916 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:00:30 +0530 Subject: [PATCH 2/3] Cleanup import --- clang/tools/scan-view/bin/scan-view | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/tools/scan-view/bin/scan-view b/clang/tools/scan-view/bin/scan-view index f8dc6c18018de1..d6b8c446ccfe8a 100755 --- a/clang/tools/scan-view/bin/scan-view +++ b/clang/tools/scan-view/bin/scan-view @@ -36,7 +36,6 @@ def url_is_up(url): def start_browser(port, options): -import webbrowser url = 'http://%s:%d' % (options.host, port) >From d377097e7df5a4933112e69cd49d1fe8f8980d05 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:01:30 +0530 Subject: [PATCH 3/3] Update socketserver to python3 --- clang/tools/scan-view/bin/scan-view | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clang/tools/scan-view/bin/scan-view b/clang/tools/scan-view/bin/scan-view index d6b8c446ccfe8a..b63f494adfbe76 100755 --- a/clang/tools/scan-view/bin/scan-view +++ b/clang/tools/scan-view/bin/scan-view @@ -79,10 +79,7 @@ def run(port, options, root): def port_is_open(port): -try: -import socketserver -except ImportError: -import SocketServer as socketserver +import socketserver try: t = socketserver.TCPServer((kDefaultHost, port), None) except: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU][True16][MC] true16 for v_alignbyte_b32 (PR #119750)
@@ -2353,8 +2353,8 @@ def int_amdgcn_writelane : [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree] >; -def int_amdgcn_alignbyte : ClangBuiltin<"__builtin_amdgcn_alignbyte">, - DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty], +def int_amdgcn_alignbyte : DefaultAttrsIntrinsic<[llvm_i32_ty], + [llvm_i32_ty, llvm_i32_ty, llvm_anyint_ty], arsenm wrote: This should be done separately https://github.com/llvm/llvm-project/pull/119750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU][True16][MC] true16 for v_alignbyte_b32 (PR #119750)
@@ -2353,8 +2353,8 @@ def int_amdgcn_writelane : [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree] >; -def int_amdgcn_alignbyte : ClangBuiltin<"__builtin_amdgcn_alignbyte">, - DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty], +def int_amdgcn_alignbyte : DefaultAttrsIntrinsic<[llvm_i32_ty], + [llvm_i32_ty, llvm_i32_ty, llvm_anyint_ty], arsenm wrote: Does this even really need to be done? Only the low bits are read anyway, so we could just truncate https://github.com/llvm/llvm-project/pull/119750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [Clang] Adjust pointer-overflow sanitizer for N3322 (PR #120719)
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/120719 >From bd7a8273d07725d898188df00c708b5a52d68ac7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 20 Dec 2024 12:41:01 +0100 Subject: [PATCH 1/4] [Clang] Adjust pointer-overflow sanitizer for N3322 N3322 makes NULL + 0 well-defined in C, matching the C++ semantics. Adjust the pointer-overflow sanitizer to no longer report NULL + 0 as a pointer overflow in any language mode. NULL + nonzero will of course continue to be reported. As N3322 is part of https://www.open-std.org/jtc1/sc22/wg14/www/previous.html, and we never performed any optimizations based on NULL + 0 being undefined in the first place, I'm applying this change to all C versions. --- clang/lib/CodeGen/CGExprScalar.cpp| 16 +--- ...d-nonzero-offset-when-nullptr-is-defined.c | 15 ++- .../catch-nullptr-and-nonzero-offset.c| 95 --- .../CodeGen/catch-pointer-overflow-volatile.c | 15 ++- clang/test/CodeGen/catch-pointer-overflow.c | 36 +++ clang/test/CodeGen/ubsan-pointer-overflow.c | 7 +- 6 files changed, 54 insertions(+), 130 deletions(-) diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 4b71bd730ce12c..0724b4265e96b2 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -5839,9 +5839,8 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *ElemTy, Value *Ptr, auto *Zero = llvm::ConstantInt::getNullValue(IntPtrTy); - // Common case: if the total offset is zero, and we are using C++ semantics, - // where nullptr+0 is defined, don't emit a check. - if (EvaluatedGEP.TotalOffset == Zero && CGM.getLangOpts().CPlusPlus) + // Common case: if the total offset is zero, don't emit a check. + if (EvaluatedGEP.TotalOffset == Zero) return GEPVal; // Now that we've computed the total offset, add it to the base pointer (with @@ -5852,23 +5851,16 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *ElemTy, Value *Ptr, llvm::SmallVector, 2> Checks; if (PerformNullCheck) { -// In C++, if the base pointer evaluates to a null pointer value, +// If the base pointer evaluates to a null pointer value, // the only valid pointer this inbounds GEP can produce is also // a null pointer, so the offset must also evaluate to zero. // Likewise, if we have non-zero base pointer, we can not get null pointer // as a result, so the offset can not be -intptr_t(BasePtr). // In other words, both pointers are either null, or both are non-null, // or the behaviour is undefined. -// -// C, however, is more strict in this regard, and gives more -// optimization opportunities: in C, additionally, nullptr+0 is undefined. -// So both the input to the 'gep inbounds' AND the output must not be null. auto *BaseIsNotNullptr = Builder.CreateIsNotNull(Ptr); auto *ResultIsNotNullptr = Builder.CreateIsNotNull(ComputedGEP); -auto *Valid = -CGM.getLangOpts().CPlusPlus -? Builder.CreateICmpEQ(BaseIsNotNullptr, ResultIsNotNullptr) -: Builder.CreateAnd(BaseIsNotNullptr, ResultIsNotNullptr); +auto *Valid = Builder.CreateICmpEQ(BaseIsNotNullptr, ResultIsNotNullptr); Checks.emplace_back(Valid, SanitizerKind::PointerOverflow); } diff --git a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c index 8a560a47ad1e10..00198b4faf8bcc 100644 --- a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c +++ b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -x c -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fno-sanitize-recover=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_pointer_overflow" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-NULLNOTOK,CHECK-SANITIZE-NULLNOTOK-C,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE -// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fsanitize-recover=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_pointer_overflow" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-NULLNOTOK,CHECK-SANITIZE-NULLNOTOK-C,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER -// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fsanitize-trap=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_pointer_overflow" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-NULLNOTOK,CHECK-SANITIZE-NULLNOTOK-C,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE +// RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fno-saniti
[clang] [compiler-rt] [Clang] Adjust pointer-overflow sanitizer for N3322 (PR #120719)
nikic wrote: @vitalybuka Should I also be dropping checks like https://github.com/llvm/llvm-project/blob/5f0db7c11264fa235d73730b2b93a31407dfbef3/compiler-rt/lib/ubsan/ubsan_handlers.cpp#L817-L818 from the ubsan runtime? (Not sure whether the runtime is supposed to also be compatible with older clang versions or something like that.) https://github.com/llvm/llvm-project/pull/120719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Enable FEAT_SVE2p1 by default for Armv9.4-A and later (PR #120753)
https://github.com/jthackray closed https://github.com/llvm/llvm-project/pull/120753 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 952c8d3 - [AArch64] Enable FEAT_SVE2p1 by default for Armv9.4-A and later (#120753)
Author: Jonathan Thackray Date: 2024-12-20T17:27:08Z New Revision: 952c8d305459d3f1218d1ce12c7f20b6a10ba046 URL: https://github.com/llvm/llvm-project/commit/952c8d305459d3f1218d1ce12c7f20b6a10ba046 DIFF: https://github.com/llvm/llvm-project/commit/952c8d305459d3f1218d1ce12c7f20b6a10ba046.diff LOG: [AArch64] Enable FEAT_SVE2p1 by default for Armv9.4-A and later (#120753) The ArmARM says: ``` "In an Armv9.4 implementation, if FEAT_SVE2 is implemented, FEAT_SVE2p1 is implemented." ``` Since FEAT_SVE2 is already enabled for Armv9.0-A and later, then FEAT_SVE2p1 should also be enabled by default. Added: Modified: clang/test/Driver/print-enabled-extensions/aarch64-armv9.4-a.c clang/test/Driver/print-enabled-extensions/aarch64-armv9.5-a.c llvm/lib/Target/AArch64/AArch64Features.td Removed: diff --git a/clang/test/Driver/print-enabled-extensions/aarch64-armv9.4-a.c b/clang/test/Driver/print-enabled-extensions/aarch64-armv9.4-a.c index 0032c926c22d96..1cfda6c996b9e3 100644 --- a/clang/test/Driver/print-enabled-extensions/aarch64-armv9.4-a.c +++ b/clang/test/Driver/print-enabled-extensions/aarch64-armv9.4-a.c @@ -58,6 +58,7 @@ // CHECK-NEXT: FEAT_SSBS, FEAT_SSBS2 Enable Speculative Store Bypass Safe bit // CHECK-NEXT: FEAT_SVE Enable Scalable Vector Extension (SVE) instructions // CHECK-NEXT: FEAT_SVE2 Enable Scalable Vector Extension 2 (SVE2) instructions +// CHECK-NEXT: FEAT_SVE2p1 Enable Scalable Vector Extension 2.1 instructions // CHECK-NEXT: FEAT_TLBIOS, FEAT_TLBIRANGE Enable Armv8.4-A TLB Range and Maintenance instructions // CHECK-NEXT: FEAT_TRBE Enable Trace Buffer Extension // CHECK-NEXT: FEAT_TRF Enable Armv8.4-A Trace extension diff --git a/clang/test/Driver/print-enabled-extensions/aarch64-armv9.5-a.c b/clang/test/Driver/print-enabled-extensions/aarch64-armv9.5-a.c index be24bd0bbddb68..76c8b34a56b75b 100644 --- a/clang/test/Driver/print-enabled-extensions/aarch64-armv9.5-a.c +++ b/clang/test/Driver/print-enabled-extensions/aarch64-armv9.5-a.c @@ -61,6 +61,7 @@ // CHECK-NEXT: FEAT_SSBS, FEAT_SSBS2 Enable Speculative Store Bypass Safe bit // CHECK-NEXT: FEAT_SVE Enable Scalable Vector Extension (SVE) instructions // CHECK-NEXT: FEAT_SVE2 Enable Scalable Vector Extension 2 (SVE2) instructions +// CHECK-NEXT: FEAT_SVE2p1 Enable Scalable Vector Extension 2.1 instructions // CHECK-NEXT: FEAT_TLBIOS, FEAT_TLBIRANGE Enable Armv8.4-A TLB Range and Maintenance instructions // CHECK-NEXT: FEAT_TRBE Enable Trace Buffer Extension // CHECK-NEXT: FEAT_TRF Enable Armv8.4-A Trace extension diff --git a/llvm/lib/Target/AArch64/AArch64Features.td b/llvm/lib/Target/AArch64/AArch64Features.td index 3a6bef81f4a0d8..41eb9a73bd013d 100644 --- a/llvm/lib/Target/AArch64/AArch64Features.td +++ b/llvm/lib/Target/AArch64/AArch64Features.td @@ -874,7 +874,7 @@ def HasV9_3aOps : Architecture64<9, 3, "a", "v9.3a", def HasV9_4aOps : Architecture64<9, 4, "a", "v9.4a", [HasV8_9aOps, HasV9_3aOps], !listconcat(HasV9_3aOps.DefaultExts, [FeatureSPECRES2, FeatureCSSC, -FeatureRASv2])>; +FeatureRASv2, FeatureSVE2p1])>; def HasV9_5aOps : Architecture64<9, 5, "a", "v9.5a", [HasV9_4aOps, FeatureCPA], !listconcat(HasV9_4aOps.DefaultExts, [FeatureCPA, FeatureLUT, FeatureFAMINMAX])>; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Use smart pointer caching in unchecked optional accessor (PR #120249)
https://github.com/jvoung updated https://github.com/llvm/llvm-project/pull/120249 >From c526263a7accc434dbf6e93c2995ceb2f95873b8 Mon Sep 17 00:00:00 2001 From: Jan Voung Date: Tue, 17 Dec 2024 15:38:19 + Subject: [PATCH] [clang][dataflow] Use smart pointer caching in unchecked optional accessor Part 2 (and final part) following https://github.com/llvm/llvm-project/pull/120102 Allows users to do things like: ``` if (o->x.has_value()) { ((*o).x).value(); } ``` where the `->` and `*` are operator overload calls. A user could instead extract the nested optional into a local variable once instead of doing two accessor calls back to back, but currently they are unsure why the code is flagged. --- .../CachedConstAccessorsLattice.h | 41 .../SmartPointerAccessorCaching.h | 168 +++ .../lib/Analysis/FlowSensitive/CMakeLists.txt | 1 + .../Models/UncheckedOptionalAccessModel.cpp | 58 +- .../SmartPointerAccessorCaching.cpp | 153 ++ .../Analysis/FlowSensitive/CMakeLists.txt | 1 + .../CachedConstAccessorsLatticeTest.cpp | 32 +++ .../SmartPointerAccessorCachingTest.cpp | 194 ++ .../UncheckedOptionalAccessModelTest.cpp | 50 + 9 files changed, 692 insertions(+), 6 deletions(-) create mode 100644 clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h create mode 100644 clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp create mode 100644 clang/unittests/Analysis/FlowSensitive/SmartPointerAccessorCachingTest.cpp diff --git a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h index 48c5287367739a..6b5dacf9f66d2d 100644 --- a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h +++ b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h @@ -13,7 +13,9 @@ #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H +#include "clang/AST/Decl.h" #include "clang/AST/Expr.h" +#include "clang/AST/Type.h" #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h" #include "clang/Analysis/FlowSensitive/DataflowLattice.h" #include "clang/Analysis/FlowSensitive/StorageLocation.h" @@ -71,10 +73,28 @@ template class CachedConstAccessorsLattice : public Base { /// Requirements: /// /// - `CE` should return a location (GLValue or a record type). + /// + /// DEPRECATED: switch users to the below overload which takes Callee and Type + /// directly. StorageLocation *getOrCreateConstMethodReturnStorageLocation( const RecordStorageLocation &RecordLoc, const CallExpr *CE, Environment &Env, llvm::function_ref Initialize); + /// Creates or returns a previously created `StorageLocation` associated with + /// a const method call `obj.getFoo()` where `RecordLoc` is the + /// `RecordStorageLocation` of `obj`, `Callee` is the decl for `getFoo`, + /// and `Type` is the return type of `getFoo`. + /// + /// The callback `Initialize` runs on the storage location if newly created. + /// + /// Requirements: + /// + /// - `Type` should return a location (GLValue or a record type). + StorageLocation &getOrCreateConstMethodReturnStorageLocation( + const RecordStorageLocation &RecordLoc, const FunctionDecl *Callee, + QualType Type, Environment &Env, + llvm::function_ref Initialize); + void clearConstMethodReturnValues(const RecordStorageLocation &RecordLoc) { ConstMethodReturnValues.erase(&RecordLoc); } @@ -212,6 +232,27 @@ CachedConstAccessorsLattice::getOrCreateConstMethodReturnStorageLocation( return &Loc; } +template +StorageLocation & +CachedConstAccessorsLattice::getOrCreateConstMethodReturnStorageLocation( +const RecordStorageLocation &RecordLoc, const FunctionDecl *Callee, +QualType Type, Environment &Env, +llvm::function_ref Initialize) { + assert(Callee != nullptr); + assert(!Type.isNull()); + assert(Type->isReferenceType() || Type->isRecordType()); + auto &ObjMap = ConstMethodReturnStorageLocations[&RecordLoc]; + auto it = ObjMap.find(Callee); + if (it != ObjMap.end()) +return *it->second; + + StorageLocation &Loc = Env.createStorageLocation(Type.getNonReferenceType()); + Initialize(Loc); + + ObjMap.insert({Callee, &Loc}); + return Loc; +} + } // namespace dataflow } // namespace clang diff --git a/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h b/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h new file mode 100644 index 00..e89e82c893d8cb --- /dev/null +++ b/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h @@ -0,0 +1,168 @@ +//===-- SmartPointerAccessorCaching.h ---*- C++ -*-===// +// +// Part of the LLVM Project, under
[clang] [llvm] Remove -bounds-checking-unique-traps (replace with -fno-sanitize-merge=local-bounds) (PR #120682)
@@ -1208,6 +1202,11 @@ Sanitizers - Implemented ``-f[no-]sanitize-trap=local-bounds``, and ``-f[no-]sanitize-recover=local-bounds``. +- ``-fsanitize-merge`` (default) and ``-fno-sanitize-merge`` have been added for + fine-grained, unified control of which UBSan checks can potentially be merged + by the compiler (for example, vitalybuka wrote: Please mention on https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#stack-traces-and-report-symbolization as well https://github.com/llvm/llvm-project/pull/120682 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1418018 - [clang][ObjectiveC] Fix Parsing the `::` Optional Scope Specifier (#119908)
Author: Qiongsi Wu Date: 2024-12-20T09:47:26-08:00 New Revision: 14180185026b8ed793cc7dfd037620e5150ccc35 URL: https://github.com/llvm/llvm-project/commit/14180185026b8ed793cc7dfd037620e5150ccc35 DIFF: https://github.com/llvm/llvm-project/commit/14180185026b8ed793cc7dfd037620e5150ccc35.diff LOG: [clang][ObjectiveC] Fix Parsing the `::` Optional Scope Specifier (#119908) The parser hangs when processing types/variables prefixed by `::` as an optional scope specifier. For example, ``` - (instancetype)init:(::A *) foo; ``` The parser should not hang, and it should emit an error. This PR implements the error check. rdar://140885078 Added: clang/test/Parser/objc-coloncolon.m clang/test/Parser/objcxx-coloncolon.mm Modified: clang/docs/ReleaseNotes.rst clang/lib/Parse/Parser.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index a85ef60b7b58ba..38c35aea3cf220 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -708,6 +708,9 @@ Improvements to Clang's diagnostics - Fix -Wdangling false positives on conditional operators (#120206). +- Fixed a bug where Clang hung on an unsupported optional scope specifier ``::`` when parsing + Objective-C. Clang now emits a diagnostic message instead of hanging. + Improvements to Clang's time-trace -- diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 36e56a92c3092e..8ba6a5dce8a994 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -,8 +,15 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec( } } - if (SS.isEmpty()) + if (SS.isEmpty()) { +if (getLangOpts().ObjC && !getLangOpts().CPlusPlus && +Tok.is(tok::coloncolon)) { + // ObjectiveC does not allow :: as as a scope token. + Diag(ConsumeToken(), diag::err_expected_type); + return true; +} return false; + } // A C++ scope specifier that isn't followed by a typename. AnnotateScopeToken(SS, IsNewScope); diff --git a/clang/test/Parser/objc-coloncolon.m b/clang/test/Parser/objc-coloncolon.m new file mode 100644 index 00..04a24fd81ec08f --- /dev/null +++ b/clang/test/Parser/objc-coloncolon.m @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -x objective-c -fsyntax-only -Wno-objc-root-class -verify %s + +int GV = 42; + +@interface A ++ (int) getGV; +- (instancetype)init:(::A *) foo; // expected-error {{expected a type}} +@end + +@implementation A +- (void)performSelector:(SEL)selector {} +- (void)double:(int)firstArg :(int)secondArg colon:(int)thirdArg {} +- (void)test { + // The `::` below should not trigger an error. + [self performSelector:@selector(double::colon:)]; +} ++ (int) getGV { return ::GV; } // expected-error {{expected a type}} +- (instancetype)init:(::A *) foo { return self; } // expected-error {{expected a type}} +@end diff --git a/clang/test/Parser/objcxx-coloncolon.mm b/clang/test/Parser/objcxx-coloncolon.mm new file mode 100644 index 00..864a7df8400c1c --- /dev/null +++ b/clang/test/Parser/objcxx-coloncolon.mm @@ -0,0 +1,9 @@ +// Test to make sure the parser does not get stuck on the optional +// scope specifier on the type B. +// RUN: %clang_cc1 -fsyntax-only %s + +class B; + +@interface A +- (void) init:(::B *) foo; +@end ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ObjectiveC] Fix Parsing the `::` Optional Scope Specifier (PR #119908)
https://github.com/qiongsiwu closed https://github.com/llvm/llvm-project/pull/119908 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Remove -bounds-checking-unique-traps (replace with -fno-sanitize-merge=local-bounds) (PR #120682)
https://github.com/vitalybuka approved this pull request. https://github.com/llvm/llvm-project/pull/120682 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ObjectiveC] Fix Parsing the `::` Optional Scope Specifier (PR #119908)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/119908 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC] extract options verify to separately function (PR #120768)
https://github.com/5chmidti approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/120768 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Fix the static assertion in 4797437 (PR #120643)
jroelofs wrote: may as well address @nikic's post-commit suggestion to move this out of the header, and into a source file, while you're here: https://github.com/llvm/llvm-project/pull/120341#discussion_r1893822845 https://github.com/llvm/llvm-project/pull/120643 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Use smart pointer caching in unchecked optional accessor (PR #120249)
https://github.com/jvoung updated https://github.com/llvm/llvm-project/pull/120249 >From c526263a7accc434dbf6e93c2995ceb2f95873b8 Mon Sep 17 00:00:00 2001 From: Jan Voung Date: Tue, 17 Dec 2024 15:38:19 + Subject: [PATCH 1/2] [clang][dataflow] Use smart pointer caching in unchecked optional accessor Part 2 (and final part) following https://github.com/llvm/llvm-project/pull/120102 Allows users to do things like: ``` if (o->x.has_value()) { ((*o).x).value(); } ``` where the `->` and `*` are operator overload calls. A user could instead extract the nested optional into a local variable once instead of doing two accessor calls back to back, but currently they are unsure why the code is flagged. --- .../CachedConstAccessorsLattice.h | 41 .../SmartPointerAccessorCaching.h | 168 +++ .../lib/Analysis/FlowSensitive/CMakeLists.txt | 1 + .../Models/UncheckedOptionalAccessModel.cpp | 58 +- .../SmartPointerAccessorCaching.cpp | 153 ++ .../Analysis/FlowSensitive/CMakeLists.txt | 1 + .../CachedConstAccessorsLatticeTest.cpp | 32 +++ .../SmartPointerAccessorCachingTest.cpp | 194 ++ .../UncheckedOptionalAccessModelTest.cpp | 50 + 9 files changed, 692 insertions(+), 6 deletions(-) create mode 100644 clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h create mode 100644 clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp create mode 100644 clang/unittests/Analysis/FlowSensitive/SmartPointerAccessorCachingTest.cpp diff --git a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h index 48c5287367739a..6b5dacf9f66d2d 100644 --- a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h +++ b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h @@ -13,7 +13,9 @@ #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H +#include "clang/AST/Decl.h" #include "clang/AST/Expr.h" +#include "clang/AST/Type.h" #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h" #include "clang/Analysis/FlowSensitive/DataflowLattice.h" #include "clang/Analysis/FlowSensitive/StorageLocation.h" @@ -71,10 +73,28 @@ template class CachedConstAccessorsLattice : public Base { /// Requirements: /// /// - `CE` should return a location (GLValue or a record type). + /// + /// DEPRECATED: switch users to the below overload which takes Callee and Type + /// directly. StorageLocation *getOrCreateConstMethodReturnStorageLocation( const RecordStorageLocation &RecordLoc, const CallExpr *CE, Environment &Env, llvm::function_ref Initialize); + /// Creates or returns a previously created `StorageLocation` associated with + /// a const method call `obj.getFoo()` where `RecordLoc` is the + /// `RecordStorageLocation` of `obj`, `Callee` is the decl for `getFoo`, + /// and `Type` is the return type of `getFoo`. + /// + /// The callback `Initialize` runs on the storage location if newly created. + /// + /// Requirements: + /// + /// - `Type` should return a location (GLValue or a record type). + StorageLocation &getOrCreateConstMethodReturnStorageLocation( + const RecordStorageLocation &RecordLoc, const FunctionDecl *Callee, + QualType Type, Environment &Env, + llvm::function_ref Initialize); + void clearConstMethodReturnValues(const RecordStorageLocation &RecordLoc) { ConstMethodReturnValues.erase(&RecordLoc); } @@ -212,6 +232,27 @@ CachedConstAccessorsLattice::getOrCreateConstMethodReturnStorageLocation( return &Loc; } +template +StorageLocation & +CachedConstAccessorsLattice::getOrCreateConstMethodReturnStorageLocation( +const RecordStorageLocation &RecordLoc, const FunctionDecl *Callee, +QualType Type, Environment &Env, +llvm::function_ref Initialize) { + assert(Callee != nullptr); + assert(!Type.isNull()); + assert(Type->isReferenceType() || Type->isRecordType()); + auto &ObjMap = ConstMethodReturnStorageLocations[&RecordLoc]; + auto it = ObjMap.find(Callee); + if (it != ObjMap.end()) +return *it->second; + + StorageLocation &Loc = Env.createStorageLocation(Type.getNonReferenceType()); + Initialize(Loc); + + ObjMap.insert({Callee, &Loc}); + return Loc; +} + } // namespace dataflow } // namespace clang diff --git a/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h b/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h new file mode 100644 index 00..e89e82c893d8cb --- /dev/null +++ b/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h @@ -0,0 +1,168 @@ +//===-- SmartPointerAccessorCaching.h ---*- C++ -*-===// +// +// Part of the LLVM Project, u
[clang] [llvm] [LLVM][Clang][AArch64] Implement AArch64 build attributes (PR #118771)
sivan-shani wrote: - Fixed according to comments above - Fixed some errors - Ability to add attributes numerically added - Tests for pauthabi platform/version in codegen - Tests for assembly parser errors - Not added: Tests for attributes with NTBS values - currently all attributes takes only ULEB128 as values. https://github.com/llvm/llvm-project/pull/118771 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix a cmake error when using the Xcode generator. (PR #119403)
fsfod wrote: I guess I must of broke build for the MSVC MSBuild/vcxproj CMake generator as well, maybe it can use the same kind checks as earlier code like this ``` cmake if(NOT XCODE AND NOT MSVC_IDE) target_compile_definitions("obj.${name}" PUBLIC CLANG_EXPORTS) else() target_compile_definitions("${name}" PUBLIC CLANG_EXPORTS) endif() ``` https://github.com/llvm/llvm-project/pull/119403 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64] Fix argument passing for SVE tuples (PR #118961)
https://github.com/efriedma-quic approved this pull request. LGTM I somehow thought you could use arm_sve_vector_bits with tuples, but I guess not. https://github.com/llvm/llvm-project/pull/118961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Remove -bounds-checking-unique-traps (replace with -fno-sanitize-merge=local-bounds) (PR #120682)
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/120682 >From ee51ed7bd68df7b2dae3f1426471b34d0388a42f Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Fri, 20 Dec 2024 04:11:36 + Subject: [PATCH 1/5] Remove -bounds-checking-unique-traps (replace with -fno-sanitize-merge=local-bounds) -fno-sanitize-merge (introduced in #120511) combines the functionality of -ubsan-unique-traps and -bounds-checking-unique-traps, while allowing fine-grained control of which UBSan checks to prevent merging. #120613 removed -ubsan-unique-traps. This patch removes -bound-checking-unique-traps, which can be controlled via -fno-sanitize-merge=local-bounds. Note: this patch subtly changes -fsanitize-merge (the default) to also include -fsanitize-merge=local-bounds. This is different from the previous behavior, where -fsanitize-merge (or the old -ubsan-unique-traps) did not affect local-bounds (requiring the separate -bounds-checking-unique-traps). However, we argue that the new behavior is more intuitive. Removing -bounds-checking-unique-traps and merging its functionality into -fsanitize-merge breaks backwards compatibility; we hope that this is acceptable since '-mllvm -bounds-checking-unique-traps' was an experimental flag. --- clang/docs/ReleaseNotes.rst | 14 ++- clang/lib/CodeGen/BackendUtil.cpp | 5 +- clang/test/CodeGen/bounds-checking.c | 14 ++- .../Instrumentation/BoundsChecking.h | 15 ++- llvm/lib/Passes/PassBuilder.cpp | 29 +++-- llvm/lib/Passes/PassRegistry.def | 4 +- .../Instrumentation/BoundsChecking.cpp| 24 ++-- .../BoundsChecking/runtimes.ll| 107 ++ .../BoundsChecking/ubsan-unique-traps.ll | 5 +- 9 files changed, 178 insertions(+), 39 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b8d92a6c881c68..0c6c894e17416a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -445,9 +445,10 @@ New Compiler Flags - The ``-Warray-compare-cxx26`` warning has been added to warn about array comparison starting from C++26, this warning is enabled as an error by default. -- '-fsanitize-merge' (default) and '-fno-sanitize-merge' have been added for - fine-grained control of which UBSan checks are allowed to be merged by the - backend (for example, -fno-sanitize-merge=bool,enum). +- ``-fsanitize-merge`` (default) and ``-fno-sanitize-merge`` have been added for + fine-grained, unified control of which UBSan checks can potentially be merged + by the compiler (for example, + ``-fno-sanitize-merge=bool,enum,array-bounds,local-bounds``). Deprecated Compiler Flags - @@ -488,8 +489,11 @@ Removed Compiler Flags derivatives) is now removed, since it's no longer possible to suppress the diagnostic (see above). Users can expect an `unknown warning` diagnostic if it's still in use. -- The experimental flag '-ubsan-unique-traps' has been removed. It is - superseded by '-fno-sanitize-merge'. +- The experimental flags '-ubsan-unique-traps' and + '-bounds-checking-unique-traps' have been removed. The combination of the + two flags is equivalent to '-fno-sanitize-merge' with no parameters. + '-bounds-checking-unique-traps' can be selectively controlled via + '-f(no-)sanitize-merge=local-bounds'. Attribute Changes in Clang -- diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index e6c9d77d29f6f1..bfb73aa51b9b5b 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1030,6 +1030,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline( PB.registerScalarOptimizerLateEPCallback( [this](FunctionPassManager &FPM, OptimizationLevel Level) { BoundsCheckingPass::ReportingMode Mode; +bool Merge = CodeGenOpts.SanitizeMergeHandlers.has(SanitizerKind::LocalBounds); + if (CodeGenOpts.SanitizeTrap.has(SanitizerKind::LocalBounds)) { Mode = BoundsCheckingPass::ReportingMode::Trap; } else if (CodeGenOpts.SanitizeMinimalRuntime) { @@ -1041,7 +1043,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline( ? BoundsCheckingPass::ReportingMode::FullRuntime : BoundsCheckingPass::ReportingMode::FullRuntimeAbort; } -FPM.addPass(BoundsCheckingPass(Mode)); +BoundsCheckingPass::BoundsCheckingOptions Options(Mode, Merge); +FPM.addPass(BoundsCheckingPass(Options)); }); // Don't add sanitizers if we are here from ThinLTO PostLink. That already diff --git a/clang/test/CodeGen/bounds-checking.c b/clang/test/CodeGen/bounds-checking.c index f9319ca61670c3..5e6b317a99969e 100644 --- a/clang/test/CodeGen/bounds-checking.c +++ b/clang/test/CodeGen/bounds-checking.c @@ -1,12 +1,14 @@ -// RUN: %c
[clang] 5bb6503 - Remove -bounds-checking-unique-traps (replace with -fno-sanitize-merge=local-bounds) (#120682)
Author: Thurston Dang Date: 2024-12-20T10:07:44-08:00 New Revision: 5bb650345d83669434713146aaa431c1f7ad43d6 URL: https://github.com/llvm/llvm-project/commit/5bb650345d83669434713146aaa431c1f7ad43d6 DIFF: https://github.com/llvm/llvm-project/commit/5bb650345d83669434713146aaa431c1f7ad43d6.diff LOG: Remove -bounds-checking-unique-traps (replace with -fno-sanitize-merge=local-bounds) (#120682) #120613 removed -ubsan-unique-traps and replaced it with -fno-sanitize-merge (introduced in #120511), which allows fine-grained control of which UBSan checks to prevent merging. This analogous patch removes -bound-checking-unique-traps, and allows it to be controlled via -fno-sanitize-merge=local-bounds. Most of this patch is simply plumbing through the compiler flags into the bounds checking pass. Note: this patch subtly changes -fsanitize-merge (the default) to also include -fsanitize-merge=local-bounds. This is different from the previous behavior, where -fsanitize-merge (or the old -ubsan-unique-traps) did not affect local-bounds (requiring the separate -bounds-checking-unique-traps). However, we argue that the new behavior is more intuitive. Removing -bounds-checking-unique-traps and merging its functionality into -fsanitize-merge breaks backwards compatibility; we hope that this is acceptable since '-mllvm -bounds-checking-unique-traps' was an experimental flag. Added: Modified: clang/docs/ReleaseNotes.rst clang/docs/UndefinedBehaviorSanitizer.rst clang/lib/CodeGen/BackendUtil.cpp clang/test/CodeGen/bounds-checking.c llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h llvm/lib/Passes/PassBuilder.cpp llvm/lib/Passes/PassRegistry.def llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp llvm/test/Instrumentation/BoundsChecking/many-trap.ll llvm/test/Instrumentation/BoundsChecking/runtimes.ll llvm/test/Instrumentation/BoundsChecking/simple-32.ll llvm/test/Instrumentation/BoundsChecking/simple.ll llvm/test/Instrumentation/BoundsChecking/ubsan-unique-traps.ll Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 38c35aea3cf220..d9d016b30f93d6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -445,10 +445,6 @@ New Compiler Flags - The ``-Warray-compare-cxx26`` warning has been added to warn about array comparison starting from C++26, this warning is enabled as an error by default. -- '-fsanitize-merge' (default) and '-fno-sanitize-merge' have been added for - fine-grained control of which UBSan checks are allowed to be merged by the - backend (for example, -fno-sanitize-merge=bool,enum). - Deprecated Compiler Flags - @@ -488,8 +484,6 @@ Removed Compiler Flags derivatives) is now removed, since it's no longer possible to suppress the diagnostic (see above). Users can expect an `unknown warning` diagnostic if it's still in use. -- The experimental flag '-ubsan-unique-traps' has been removed. It is - superseded by '-fno-sanitize-merge'. Attribute Changes in Clang -- @@ -1213,6 +1207,11 @@ Sanitizers - Implemented ``-f[no-]sanitize-trap=local-bounds``, and ``-f[no-]sanitize-recover=local-bounds``. +- ``-fsanitize-merge`` (default) and ``-fno-sanitize-merge`` have been added for + fine-grained, unified control of which UBSan checks can potentially be merged + by the compiler (for example, + ``-fno-sanitize-merge=bool,enum,array-bounds,local-bounds``). + Python Binding Changes -- - Fixed an issue that led to crashes when calling ``Type.get_exception_specification_kind``. diff --git a/clang/docs/UndefinedBehaviorSanitizer.rst b/clang/docs/UndefinedBehaviorSanitizer.rst index 671db7f9f36714..b9ee4484fb9aec 100644 --- a/clang/docs/UndefinedBehaviorSanitizer.rst +++ b/clang/docs/UndefinedBehaviorSanitizer.rst @@ -276,8 +276,8 @@ Stack traces and report symbolization If you want UBSan to print symbolized stack trace for each error report, you will need to: -#. Compile with ``-g`` and ``-fno-omit-frame-pointer`` to get proper debug - information in your binary. +#. Compile with ``-g``, ``-fno-sanitize-merge`` and ``-fno-omit-frame-pointer`` + to get proper debug information in your binary. #. Run your program with environment variable ``UBSAN_OPTIONS=print_stacktrace=1``. #. Make sure ``llvm-symbolizer`` binary is in ``PATH``. diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index e6c9d77d29f6f1..04358cd6d7c232 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1030,6 +1030,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline( PB.registerScalarOptimizerLateEPCallback( [this](FunctionPassManager &FPM, OptimizationLevel Level) { BoundsCheckingPass::ReportingMode Mode; +
[clang] [llvm] Remove -bounds-checking-unique-traps (replace with -fno-sanitize-merge=local-bounds) (PR #120682)
https://github.com/thurstond closed https://github.com/llvm/llvm-project/pull/120682 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64] Fix argument passing for SVE tuples (PR #118961)
momchil-velikov wrote: Thanks! https://github.com/llvm/llvm-project/pull/118961 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Hexagon] Add V75 support to compiler and assembler (PR #120773)
androm3da wrote: LGTM (after the `clang-format` fix) https://github.com/llvm/llvm-project/pull/120773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 5162fde - [webkit.UncountedLambdaCapturesChecker] Fix a nullptr deference. (#120702)
Author: Ryosuke Niwa Date: 2024-12-20T10:18:08-08:00 New Revision: 5162fde6ee6565d39511e451c04865e7b53bcdcc URL: https://github.com/llvm/llvm-project/commit/5162fde6ee6565d39511e451c04865e7b53bcdcc DIFF: https://github.com/llvm/llvm-project/commit/5162fde6ee6565d39511e451c04865e7b53bcdcc.diff LOG: [webkit.UncountedLambdaCapturesChecker] Fix a nullptr deference. (#120702) Added a nullptr check. Added: clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp Modified: clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index da9698e327562e..a57499d52acd0c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -155,6 +155,8 @@ class UncountedLambdaCapturesChecker if (!Init) return nullptr; TempExpr = dyn_cast(Init->IgnoreParenCasts()); +if (!TempExpr) + return nullptr; return dyn_cast_or_null(TempExpr->getSubExpr()); } diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp new file mode 100644 index 00..4d9edb75b7ff36 --- /dev/null +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s +// expected-no-diagnostics + +struct Foo { + int x; + int y; + Foo(int x, int y) : x(x) , y(y) { } + ~Foo() { } +}; + +Foo bar(const Foo&); +void foo() { + int x = 7; + int y = 5; + bar(Foo(x, y)); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [webkit.UncountedLambdaCapturesChecker] Fix a nullptr deference. (PR #120702)
https://github.com/rniwa closed https://github.com/llvm/llvm-project/pull/120702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Return larger CXX records in memory (PR #120670)
efriedma-quic wrote: Missing regression test in clang/test/CodeGen. We probably want a release note for this (clang/docs/ReleaseNotes.rst). (If you're interested, there's another x86-64 ABI bug which nobody got around to fixing: #76017.) https://github.com/llvm/llvm-project/pull/120670 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/111719 >From 05eab970b59c61b22e8afa1ed9381906ae925c03 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Wed, 9 Oct 2024 10:16:58 -0700 Subject: [PATCH 1/4] [clang] Introduce a new UEFI target predefine. --- clang/lib/Basic/Targets/OSTargets.h | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index a83d6464e789d6..92c76b303def65 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -783,7 +783,10 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +Builder.defineMacro("__UEFI__"); +Builder.defineMacro("__PECOFF__"); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) >From 4ef8bcd3a9019299145b59d4f26cd4307171bed5 Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Wed, 13 Nov 2024 10:30:50 -0800 Subject: [PATCH 2/4] Update OSTargets.h Remove PE_COFF --- clang/lib/Basic/Targets/OSTargets.h | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 92c76b303def65..5a23eef0117294 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -785,7 +785,6 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override { Builder.defineMacro("__UEFI__"); -Builder.defineMacro("__PECOFF__"); } public: >From bcccf1f86609a828130c1a9474d10b78c8f212c9 Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Wed, 13 Nov 2024 10:36:15 -0800 Subject: [PATCH 3/4] add __UEFI__ to windows predefines Updating the PE COFF generating windows code path to predefine the new __UEFI__ macro. --- clang/lib/Basic/Targets/OSTargets.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp index b56e2c7ca9c494..b9edeefa60148e 100644 --- a/clang/lib/Basic/Targets/OSTargets.cpp +++ b/clang/lib/Basic/Targets/OSTargets.cpp @@ -259,6 +259,7 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) { void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder) { + Builder.defineMacro("__UEFI__"); Builder.defineMacro("_WIN32"); if (Triple.isArch64Bit()) Builder.defineMacro("_WIN64"); >From 2f6af5664bbd6f3cc01dfb7b46f67190dc4efba4 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Fri, 20 Dec 2024 10:18:18 -0800 Subject: [PATCH 4/4] Removing the predefine from Windows targets. Keeping it only on UEFI. --- clang/lib/Basic/Targets/OSTargets.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp index b9edeefa60148e..b56e2c7ca9c494 100644 --- a/clang/lib/Basic/Targets/OSTargets.cpp +++ b/clang/lib/Basic/Targets/OSTargets.cpp @@ -259,7 +259,6 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) { void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder) { - Builder.defineMacro("__UEFI__"); Builder.defineMacro("_WIN32"); if (Triple.isArch64Bit()) Builder.defineMacro("_WIN64"); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)
https://github.com/Prabhuk edited https://github.com/llvm/llvm-project/pull/111719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)
https://github.com/Prabhuk edited https://github.com/llvm/llvm-project/pull/111719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)
@@ -259,6 +259,7 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) { void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder) { + Builder.defineMacro("__UEFI__"); Prabhuk wrote: Removed it from Windows target. https://github.com/llvm/llvm-project/pull/111719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Hexagon] Add V75 support to compiler and assembler (PR #120773)
https://github.com/iajbar updated https://github.com/llvm/llvm-project/pull/120773 >From a57f928e545e4bd398fe0ae3fca8702c83a79516 Mon Sep 17 00:00:00 2001 From: Ikhlas Ajbar Date: Fri, 13 Dec 2024 14:54:44 -0800 Subject: [PATCH] [Hexagon] Add V75 support to compiler and assembler This patch introduces support for the Hexagon V75 architecture. It includes instruction formats, definitions, encodings, scheduling classes, and builtins/intrinsics. --- clang/include/clang/Basic/BuiltinsHexagon.def | 10 +- clang/include/clang/Driver/Options.td | 2 + clang/lib/Basic/Targets/Hexagon.cpp | 15 +- clang/test/Driver/hexagon-toolchain-elf.c | 7 + .../Misc/target-invalid-cpu-note/hexagon.c| 1 + clang/test/Preprocessor/hexagon-predefines.c | 16 + llvm/include/llvm/BinaryFormat/ELF.h | 1 + llvm/lib/Object/ELFObjectFile.cpp | 2 + llvm/lib/ObjectYAML/ELFYAML.cpp | 2 + llvm/lib/Target/Hexagon/Hexagon.td| 14 + llvm/lib/Target/Hexagon/HexagonDepArch.h | 4 +- llvm/lib/Target/Hexagon/HexagonDepArch.td | 2 + llvm/lib/Target/Hexagon/HexagonDepIICHVX.td | 592 .../lib/Target/Hexagon/HexagonDepIICScalar.td | 888 ++ llvm/lib/Target/Hexagon/HexagonSchedule.td| 1 + llvm/lib/Target/Hexagon/HexagonScheduleV75.td | 39 + llvm/lib/Target/Hexagon/HexagonSubtarget.h| 6 + .../MCTargetDesc/HexagonMCELFStreamer.cpp | 3 + .../MCTargetDesc/HexagonMCTargetDesc.cpp | 68 +- llvm/test/MC/Hexagon/arch-support.s | 9 + llvm/test/MC/Hexagon/v75_arch.s | 10 + 21 files changed, 1656 insertions(+), 36 deletions(-) create mode 100644 llvm/lib/Target/Hexagon/HexagonScheduleV75.td create mode 100644 llvm/test/MC/Hexagon/v75_arch.s diff --git a/clang/include/clang/Basic/BuiltinsHexagon.def b/clang/include/clang/Basic/BuiltinsHexagon.def index 0dc0f4567dd413..ca3f99176110e3 100644 --- a/clang/include/clang/Basic/BuiltinsHexagon.def +++ b/clang/include/clang/Basic/BuiltinsHexagon.def @@ -17,8 +17,10 @@ # define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS) #endif +#pragma push_macro("V75") +#define V75 "v75" #pragma push_macro("V73") -#define V73 "v73" +#define V73 "v73|" V75 #pragma push_macro("V71") #define V71 "v71|" V73 #pragma push_macro("V69") @@ -40,8 +42,10 @@ #pragma push_macro("V5") #define V5 "v5|" V55 +#pragma push_macro("HVXV75") +#define HVXV75 "hvxv75" #pragma push_macro("HVXV73") -#define HVXV73 "hvxv73" +#define HVXV73 "hvxv73|" HVXV75 #pragma push_macro("HVXV71") #define HVXV71 "hvxv71|" HVXV73 #pragma push_macro("HVXV69") @@ -143,6 +147,7 @@ TARGET_BUILTIN(__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B,"V64iV64iV32iLLi","", " #pragma pop_macro("HVXV69") #pragma pop_macro("HVXV71") #pragma pop_macro("HVXV73") +#pragma pop_macro("HVXV75") #pragma pop_macro("V5") #pragma pop_macro("V55") @@ -155,6 +160,7 @@ TARGET_BUILTIN(__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B,"V64iV64iV32iLLi","", " #pragma pop_macro("V69") #pragma pop_macro("V71") #pragma pop_macro("V73") +#pragma pop_macro("V75") #undef BUILTIN #undef TARGET_BUILTIN diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 638f8c52053ec5..9edf308cc685ea 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6224,6 +6224,8 @@ def mv71t : Flag<["-"], "mv71t">, Group, Alias, AliasArgs<["hexagonv71t"]>; def mv73 : Flag<["-"], "mv73">, Group, Alias, AliasArgs<["hexagonv73"]>; +def mv75 : Flag<["-"], "mv75">, Group, + Alias, AliasArgs<["hexagonv75"]>; def mhexagon_hvx : Flag<["-"], "mhvx">, Group, HelpText<"Enable Hexagon Vector eXtensions">; def mhexagon_hvx_EQ : Joined<["-"], "mhvx=">, diff --git a/clang/lib/Basic/Targets/Hexagon.cpp b/clang/lib/Basic/Targets/Hexagon.cpp index 0282ac812c306f..931327bd8657b0 100644 --- a/clang/lib/Basic/Targets/Hexagon.cpp +++ b/clang/lib/Basic/Targets/Hexagon.cpp @@ -78,6 +78,9 @@ void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts, } else if (CPU == "hexagonv73") { Builder.defineMacro("__HEXAGON_V73__"); Builder.defineMacro("__HEXAGON_ARCH__", "73"); + } else if (CPU == "hexagonv75") { +Builder.defineMacro("__HEXAGON_V75__"); +Builder.defineMacro("__HEXAGON_ARCH__", "75"); } if (hasFeature("hvx-length64b")) { @@ -229,13 +232,13 @@ struct CPUSuffix { }; static constexpr CPUSuffix Suffixes[] = { -{{"hexagonv5"}, {"5"}}, {{"hexagonv55"}, {"55"}}, -{{"hexagonv60"}, {"60"}}, {{"hexagonv62"}, {"62"}}, -{{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}}, +{{"hexagonv5"}, {"5"}}, {{"hexagonv55"}, {"55"}}, +{{"hexagonv60"}, {"60"}}, {{"hexagonv62"}, {"62"}}, +{{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}}, {{"hexagonv67"}, {"67"}}, {{"hexagonv67t"}, {"67t"}}, -{{"hexagonv68"}, {"68"}}, {{"hexagonv69"}, {"69"}}, -{{"hexa
[clang] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)
@@ -1018,13 +1018,19 @@ bool Darwin::hasBlocksRuntime() const { } } -void Darwin::AddCudaIncludeArgs(const ArgList &DriverArgs, -ArgStringList &CC1Args) const { +void MachO::AddCudaIncludeArgs(const ArgList &DriverArgs, + ArgStringList &CC1Args) const { + if (!isTargetAppleBased()) +return ToolChain::AddCudaIncludeArgs(DriverArgs, CC1Args); ian-twilightcoder wrote: >From `Driver::getToolChain` you get it for these arch-vendor-win32-macho arch-vendor-windows-macho arch-vendor-none-macho The only one I really want to change is arch-apple-none-macho, I don't want to disturb any of the others. But that's a good point, it would probably be cleaner to make an AppleMachO toolchain in between the existing MachO and Darwin ones https://github.com/llvm/llvm-project/pull/120507 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] floating-point, pointer, and function types (PR #120484)
@@ -18,6 +21,87 @@ mlir::MLIRContext &CIRGenTypes::getMLIRContext() const { return *builder.getContext(); } +/// Return true if the specified type in a function parameter or result position +/// can be converted to a CIR type at this point. This boils down to being +/// whether it is complete, as well as whether we've temporarily deferred +/// expanding the type because we're in a recursive context. +bool CIRGenTypes::isFuncParamTypeConvertible(clang::QualType type) { + // Some ABIs cannot have their member pointers represented in LLVM IR unless + // certain circumstances have been reached. + assert(!type->getAs() && "NYI"); + + // If this isn't a tagged type, we can convert it! bcardosolopes wrote: I don't remember the details on why it was necessary at the time to deviate - so I just made this be equivalent to traditional codegen and everything passes: https://github.com/llvm/clangir/commit/04d7dcfb2582753f3eccbf01ec900d60297cbf4b That said, I don't think we need to introduce any asserts here, can't get better than OG for the sake of completeness. Not supported types will crash given the other mechanisms David mentioned, but the recursive logic is sound with pre-existing work. Unless Erich has any other concerns, this LGTM to land. https://github.com/llvm/llvm-project/pull/120484 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] floating-point, pointer, and function types (PR #120484)
@@ -18,6 +21,87 @@ mlir::MLIRContext &CIRGenTypes::getMLIRContext() const { return *builder.getContext(); } +/// Return true if the specified type in a function parameter or result position +/// can be converted to a CIR type at this point. This boils down to being +/// whether it is complete, as well as whether we've temporarily deferred +/// expanding the type because we're in a recursive context. +bool CIRGenTypes::isFuncParamTypeConvertible(clang::QualType type) { + // Some ABIs cannot have their member pointers represented in LLVM IR unless + // certain circumstances have been reached. + assert(!type->getAs() && "NYI"); + + // If this isn't a tagged type, we can convert it! erichkeane wrote: If this includes llvm/clangir@04d7dcf in it, rather than the current implementation, I think I'm OK without any asserts. I'll Approve, but conditional on that patch being included in this one. https://github.com/llvm/llvm-project/pull/120484 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] floating-point, pointer, and function types (PR #120484)
https://github.com/erichkeane approved this pull request. Approve, conditional on isFuncParamTypeConvertible change being pulled from the incubator. https://github.com/llvm/llvm-project/pull/120484 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Fixes for %b printf extension handling (PR #120689)
https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/120689 >From 1da99c0d32e996219a4b4dcad67b0321cab753e3 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Thu, 19 Dec 2024 21:35:57 -0500 Subject: [PATCH] [clang][Sema] Fixes for %b printf extension handling The %b printf extension in the kernel is not fixed to a int type. On sparc64 there are various %llb formats. Adjust the code to handle the length specifiers and type check like it is used by the regular case. --- clang/include/clang/AST/FormatString.h | 6 ++-- clang/lib/Sema/SemaChecking.cpp | 38 +--- clang/test/Sema/format-strings-freebsd.c | 8 - 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/clang/include/clang/AST/FormatString.h b/clang/include/clang/AST/FormatString.h index a074dd23e2ad4c..1ff0d036b70d1a 100644 --- a/clang/include/clang/AST/FormatString.h +++ b/clang/include/clang/AST/FormatString.h @@ -240,8 +240,10 @@ class ConversionSpecifier { bool isIntArg() const { return (kind >= IntArgBeg && kind <= IntArgEnd) || kind == FreeBSDrArg || kind == FreeBSDyArg; } - bool isUIntArg() const { return kind >= UIntArgBeg && kind <= UIntArgEnd; } - bool isAnyIntArg() const { return kind >= IntArgBeg && kind <= UIntArgEnd; } + bool isUIntArg() const { return (kind >= UIntArgBeg && kind <= UIntArgEnd) || +kind == FreeBSDbArg; } + bool isAnyIntArg() const { return (kind >= IntArgBeg && kind <= UIntArgEnd) || +kind == FreeBSDbArg; } bool isDoubleArg() const { return kind >= DoubleArgBeg && kind <= DoubleArgEnd; } diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e703a62ff9cf18..e50118762fff32 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7170,18 +7170,34 @@ bool CheckPrintfHandler::HandlePrintfSpecifier( // Claim the second argument. CoveredArgs.set(argIndex + 1); -// Type check the first argument (int for %b, pointer for %D) const Expr *Ex = getDataArg(argIndex); -const analyze_printf::ArgType &AT = - (CS.getKind() == ConversionSpecifier::FreeBSDbArg) ? -ArgType(S.Context.IntTy) : ArgType::CPointerTy; -if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType())) - EmitFormatDiagnostic( - S.PDiag(diag::warn_format_conversion_argument_type_mismatch) - << AT.getRepresentativeTypeName(S.Context) << Ex->getType() - << false << Ex->getSourceRange(), - Ex->getBeginLoc(), /*IsStringLocation*/ false, - getSpecifierRange(startSpecifier, specifierLen)); +if (CS.getKind() == ConversionSpecifier::FreeBSDDArg) { + // Type check the first argument (pointer for %D) + const analyze_printf::ArgType &AT = ArgType::CPointerTy; + if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType())) +EmitFormatDiagnostic( +S.PDiag(diag::warn_format_conversion_argument_type_mismatch) +<< AT.getRepresentativeTypeName(S.Context) << Ex->getType() +<< false << Ex->getSourceRange(), +Ex->getBeginLoc(), /*IsStringLocation*/ false, +getSpecifierRange(startSpecifier, specifierLen)); +} else { + // Check the length modifier for %b + if (!FS.hasValidLengthModifier(S.getASTContext().getTargetInfo(), + S.getLangOpts())) +HandleInvalidLengthModifier(FS, CS, startSpecifier, specifierLen, +diag::warn_format_nonsensical_length); + else if (!FS.hasStandardLengthModifier()) +HandleNonStandardLengthModifier(FS, startSpecifier, specifierLen); + else if (!FS.hasStandardLengthConversionCombination()) +HandleInvalidLengthModifier( +FS, CS, startSpecifier, specifierLen, +diag::warn_format_non_standard_conversion_spec); + + // Type check the first argument of %b + if (!checkFormatExpr(FS, startSpecifier, specifierLen, Ex)) +return false; +} // Type check the second argument (char * for both %b and %D) Ex = getDataArg(argIndex + 1); diff --git a/clang/test/Sema/format-strings-freebsd.c b/clang/test/Sema/format-strings-freebsd.c index 3d3ed6b40f48dc..3540dca2cfabcd 100644 --- a/clang/test/Sema/format-strings-freebsd.c +++ b/clang/test/Sema/format-strings-freebsd.c @@ -8,13 +8,19 @@ int freebsd_kernel_printf(const char *, ...) __attribute__((__format__(__freebsd void check_freebsd_kernel_extensions(int i, long l, char *s, short h) { - // %b expects an int and a char * + // %b expects a char * freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning freebsd_kernel_printf("reg=%b\n", l, "\10\2BITTWO\1BITONE\n"); // expected-warning{{format specifies type 'int' but the argument has type 'long'}} freebsd_kernel_printf("reg=%b\n", i, l); // expected-warning{{format specifies type 'char *' but the argument has type 'long
[clang] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (PR #118186)
tbaederr wrote: Do you need someone to push this? https://github.com/llvm/llvm-project/pull/118186 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Patch series to reapply #118734 and substantially improve it (PR #120534)
dyung wrote: > @dyung -- Could you try out > https://github.com/chandlerc/llvm-project/tree/shard-loongarch and see if > that works? > > Notably, it includes one additional patch on top of this series: > [chandlerc@2d59328](https://github.com/chandlerc/llvm-project/commit/2d593288dc18c55307779ae82a18d024761356ad) > > This won't be enough to fully resolve the issue, but if the LoongArch errors > go away with this patch, then it gives me a strong theory about what is still > going wrong and I can likely find a workaround for the rest as well. Sorry for the delay, here are the results of running the branch shard-loongarch. Main takeaway is that the loongarch failures seem to have been fixed with the patch at the HEAD of that branch. I have uploaded the test logfile here (another 300MB file when expanded): https://www.dropbox.com/scl/fi/8v8toveo8h45c4iuwjgo8/log_test.f6426abc224b140bfb3b6fdc45443bc4e16057aa.zip?rlkey=6rj3vygil705ddd63vk4ykqdl&dl=0 https://github.com/llvm/llvm-project/pull/120534 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [webkit.UncountedLambdaCapturesChecker] Fix a nullptr deference. (PR #120702)
https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/120702 Added a nullptr check. >From 527fd23a6bd58cada036fe4a47c13ca93eabf507 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Fri, 20 Dec 2024 01:32:40 -0800 Subject: [PATCH] [webkit.UncountedLambdaCapturesChecker] Fix a nullptr deference. Added a nullptr check. --- .../WebKit/UncountedLambdaCapturesChecker.cpp| 2 ++ ...counted-lambda-captures-find-lambda-crash.cpp | 16 2 files changed, 18 insertions(+) create mode 100644 clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index da9698e327562e..a57499d52acd0c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -155,6 +155,8 @@ class UncountedLambdaCapturesChecker if (!Init) return nullptr; TempExpr = dyn_cast(Init->IgnoreParenCasts()); +if (!TempExpr) + return nullptr; return dyn_cast_or_null(TempExpr->getSubExpr()); } diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp new file mode 100644 index 00..4d9edb75b7ff36 --- /dev/null +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s +// expected-no-diagnostics + +struct Foo { + int x; + int y; + Foo(int x, int y) : x(x) , y(y) { } + ~Foo() { } +}; + +Foo bar(const Foo&); +void foo() { + int x = 7; + int y = 5; + bar(Foo(x, y)); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Mention std::forward_list in container-size-empty doc (PR #120701)
https://github.com/N-Dekker created https://github.com/llvm/llvm-project/pull/120701 Mentioned `std::forward_list` as example of a container without `size()`. >From e58124c491f46238538bb06f14de31f4d5f25d2a Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 20 Dec 2024 10:30:54 +0100 Subject: [PATCH] [clang-tidy] Mention std::forward_list in container-size-empty doc Mentioned `std::forward_list` as example of a container without `size()`. --- .../clang-tidy/readability/ContainerSizeEmptyCheck.h | 8 .../checks/readability/container-size-empty.rst | 7 --- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h index 3aa4bdc496194b..e449686f77566d 100644 --- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h +++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h @@ -19,10 +19,10 @@ namespace clang::tidy::readability { /// /// The emptiness of a container should be checked using the `empty()` method /// instead of the `size()`/`length()` method. It shows clearer intent to use -/// `empty()`. Furthermore some containers may implement the `empty()` method -/// but not implement the `size()` or `length()` method. Using `empty()` -/// whenever possible makes it easier to switch to another container in the -/// future. +/// `empty()`. Furthermore some containers (for example, a `std::forward_list`) +/// may implement the `empty()` method but not implement the `size()` or +/// `length()` method. Using `empty()` whenever possible makes it easier to +/// switch to another container in the future. class ContainerSizeEmptyCheck : public ClangTidyCheck { public: ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context); diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst index 6a007f69767abe..43ad74f60dbe57 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst @@ -9,9 +9,10 @@ with a call to ``empty()``. The emptiness of a container should be checked using the ``empty()`` method instead of the ``size()``/``length()`` method. It shows clearer intent to use -``empty()``. Furthermore some containers may implement the ``empty()`` method -but not implement the ``size()`` or ``length()`` method. Using ``empty()`` -whenever possible makes it easier to switch to another container in the future. +``empty()``. Furthermore some containers (for example, a ``std::forward_list``) +may implement the ``empty()`` method but not implement the ``size()`` or +``length()`` method. Using ``empty()`` whenever possible makes it easier to +switch to another container in the future. The check issues warning if a container has ``empty()`` and ``size()`` or ``length()`` methods matching following signatures: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen][SPIRV] Translate `amdgpu_flat_work_group_size` into `reqd_work_group_size`. (PR #116820)
@@ -245,6 +247,41 @@ SPIRVTargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM, return DefaultGlobalAS; } +void SPIRVTargetCodeGenInfo::setTargetAttributes( +const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const { + if (!M.getLangOpts().HIP || + M.getTarget().getTriple().getVendor() != llvm::Triple::AMD) +return; + if (GV->isDeclaration()) +return; + + auto F = dyn_cast(GV); + if (!F) +return; + + auto FD = dyn_cast_or_null(D); + if (!FD) +return; + if (!FD->hasAttr()) +return; + + unsigned N = M.getLangOpts().GPUMaxThreadsPerBlock; + if (auto FlatWGS = FD->getAttr()) +N = FlatWGS->getMax()->EvaluateKnownConstInt(M.getContext()).getExtValue(); + + // We encode the maximum flat WG size in the first component of the 3D + // max_work_group_size attribute, which will get reverse translated into the + // original AMDGPU attribute when targeting AMDGPU. AlexVlx wrote: We are talking across eachother. I am saying that the SPIR-V attribute cannot be generated via Clang, i.e. that you cannot write `__attribute__((foo))` in your source and obtain `max_work_group_size` metadata, at the moment. Furthermore, from the implementation of Clang's `__launch_bounds__`: ```cpp // An AST node is created for this attribute, but is not used by other parts // of the compiler. However, this node needs to exist in the AST because // non-LLVM backends may be relying on the attribute's presence. ``` So this is a glorified annotation / we'd still have to decide on how to lower it into IR, which would likely end up atop flat workgroup size, unless we choose to spam yet another attribute. We also use flat workgroup size implicitly to control / implement `--gpu-max-threads-per-block`, which is important for correctness, and is in a fairly similar place with `__launch_bounds__` (it's always 1D, doesn't have a minimum etc.). It's also not handled by this patch, so I'll have to add it:) That being said, the idea in #91468 is sound, but it will require a bit of work to get done; I think we'd still have to choose a way to pass the info through SPIR-V (what this PR tries to do). https://github.com/llvm/llvm-project/pull/116820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [webkit.UncountedLambdaCapturesChecker] Fix a nullptr deference. (PR #120702)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: Ryosuke Niwa (rniwa) Changes Added a nullptr check. --- Full diff: https://github.com/llvm/llvm-project/pull/120702.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp (+2) - (added) clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp (+16) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index da9698e327562e..a57499d52acd0c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -155,6 +155,8 @@ class UncountedLambdaCapturesChecker if (!Init) return nullptr; TempExpr = dyn_cast(Init->IgnoreParenCasts()); +if (!TempExpr) + return nullptr; return dyn_cast_or_null(TempExpr->getSubExpr()); } diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp new file mode 100644 index 00..4d9edb75b7ff36 --- /dev/null +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-find-lambda-crash.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s +// expected-no-diagnostics + +struct Foo { + int x; + int y; + Foo(int x, int y) : x(x) , y(y) { } + ~Foo() { } +}; + +Foo bar(const Foo&); +void foo() { + int x = 7; + int y = 5; + bar(Foo(x, y)); +} `` https://github.com/llvm/llvm-project/pull/120702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Mention std::forward_list in container-size-empty doc (PR #120701)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy Author: Niels Dekker (N-Dekker) Changes Mentioned `std::forward_list` as example of a container without `size()`. --- Full diff: https://github.com/llvm/llvm-project/pull/120701.diff 2 Files Affected: - (modified) clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h (+4-4) - (modified) clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst (+4-3) ``diff diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h index 3aa4bdc496194b..e449686f77566d 100644 --- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h +++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h @@ -19,10 +19,10 @@ namespace clang::tidy::readability { /// /// The emptiness of a container should be checked using the `empty()` method /// instead of the `size()`/`length()` method. It shows clearer intent to use -/// `empty()`. Furthermore some containers may implement the `empty()` method -/// but not implement the `size()` or `length()` method. Using `empty()` -/// whenever possible makes it easier to switch to another container in the -/// future. +/// `empty()`. Furthermore some containers (for example, a `std::forward_list`) +/// may implement the `empty()` method but not implement the `size()` or +/// `length()` method. Using `empty()` whenever possible makes it easier to +/// switch to another container in the future. class ContainerSizeEmptyCheck : public ClangTidyCheck { public: ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context); diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst index 6a007f69767abe..43ad74f60dbe57 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst @@ -9,9 +9,10 @@ with a call to ``empty()``. The emptiness of a container should be checked using the ``empty()`` method instead of the ``size()``/``length()`` method. It shows clearer intent to use -``empty()``. Furthermore some containers may implement the ``empty()`` method -but not implement the ``size()`` or ``length()`` method. Using ``empty()`` -whenever possible makes it easier to switch to another container in the future. +``empty()``. Furthermore some containers (for example, a ``std::forward_list``) +may implement the ``empty()`` method but not implement the ``size()`` or +``length()`` method. Using ``empty()`` whenever possible makes it easier to +switch to another container in the future. The check issues warning if a container has ``empty()`` and ``size()`` or ``length()`` methods matching following signatures: `` https://github.com/llvm/llvm-project/pull/120701 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Mention std::forward_list in container-size-empty doc (PR #120701)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Niels Dekker (N-Dekker) Changes Mentioned `std::forward_list` as example of a container without `size()`. --- Full diff: https://github.com/llvm/llvm-project/pull/120701.diff 2 Files Affected: - (modified) clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h (+4-4) - (modified) clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst (+4-3) ``diff diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h index 3aa4bdc496194b..e449686f77566d 100644 --- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h +++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h @@ -19,10 +19,10 @@ namespace clang::tidy::readability { /// /// The emptiness of a container should be checked using the `empty()` method /// instead of the `size()`/`length()` method. It shows clearer intent to use -/// `empty()`. Furthermore some containers may implement the `empty()` method -/// but not implement the `size()` or `length()` method. Using `empty()` -/// whenever possible makes it easier to switch to another container in the -/// future. +/// `empty()`. Furthermore some containers (for example, a `std::forward_list`) +/// may implement the `empty()` method but not implement the `size()` or +/// `length()` method. Using `empty()` whenever possible makes it easier to +/// switch to another container in the future. class ContainerSizeEmptyCheck : public ClangTidyCheck { public: ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context); diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst index 6a007f69767abe..43ad74f60dbe57 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst @@ -9,9 +9,10 @@ with a call to ``empty()``. The emptiness of a container should be checked using the ``empty()`` method instead of the ``size()``/``length()`` method. It shows clearer intent to use -``empty()``. Furthermore some containers may implement the ``empty()`` method -but not implement the ``size()`` or ``length()`` method. Using ``empty()`` -whenever possible makes it easier to switch to another container in the future. +``empty()``. Furthermore some containers (for example, a ``std::forward_list``) +may implement the ``empty()`` method but not implement the ``size()`` or +``length()`` method. Using ``empty()`` whenever possible makes it easier to +switch to another container in the future. The check issues warning if a container has ``empty()`` and ``size()`` or ``length()`` methods matching following signatures: `` https://github.com/llvm/llvm-project/pull/120701 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Patch series to reapply #118734 and substantially improve it (PR #120534)
chandlerc wrote: No worries about delay, this gives me a credible target to resolve the rest of the issues. I'll update this PR both to address review comments but also to try and address the rest of the failures. Appreciate runs to validate these updates. =] https://github.com/llvm/llvm-project/pull/120534 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Mention std::forward_list in container-size-empty doc (PR #120701)
https://github.com/N-Dekker ready_for_review https://github.com/llvm/llvm-project/pull/120701 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix non-deterministic infinite recursion... (PR #118288)
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID: In-Reply-To: nikic wrote: @hubert-reinterpretcast This patch modifies structure layout in exported headers, changing the libclang-cpp ABI. LLVM patch releases cannot break API or ABI compatibility, see the last point in https://llvm.org/docs/HowToReleaseLLVM.html#release-patch-rules. https://github.com/llvm/llvm-project/pull/118288 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix dangling false positives for conditional operators. (PR #120233)
https://github.com/hokein edited https://github.com/llvm/llvm-project/pull/120233 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] a6d26c5 - [clang] Fix dangling false positives for conditional operators. (#120233)
Author: Haojian Wu Date: 2024-12-20T09:26:38+01:00 New Revision: a6d26c56ff066c8e8f92f4ca169fcf40ae0db537 URL: https://github.com/llvm/llvm-project/commit/a6d26c56ff066c8e8f92f4ca169fcf40ae0db537 DIFF: https://github.com/llvm/llvm-project/commit/a6d26c56ff066c8e8f92f4ca169fcf40ae0db537.diff LOG: [clang] Fix dangling false positives for conditional operators. (#120233) When analyzing a dangling gsl pointer, we currently filter out all field access `MemberExpr` to avoid common false positives (`string_view sv = Temp().sv`), However, this filter only applies to direct MemberExpr instances, leaving the conditional operator as an escaping example (`GSLPointer pointer(Cond ? Owner().ptr : GSLPointer());`). This patch extends the MemberExpr logic to handle the conditional operator. The heuristic is intentionally simple, which may result in some false negatives. However, it effectively covers common cases like `std::string_view sv = cond ? "123" : std::string();`, which is a reasonable trade-off. Fixes https://github.com/llvm/llvm-project/issues/120206 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/CheckExprLifetime.cpp clang/test/Sema/warn-lifetime-analysis-nocfg.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b8d92a6c881c68..a85ef60b7b58ba 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -706,6 +706,8 @@ Improvements to Clang's diagnostics return ptr + index < ptr; // warning } +- Fix -Wdangling false positives on conditional operators (#120206). + Improvements to Clang's time-trace -- diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp index add6d7506bd6f0..7109de03cadd12 100644 --- a/clang/lib/Sema/CheckExprLifetime.cpp +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -582,6 +582,15 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call, // Temp().ptr; // Here ptr might not dangle. if (isa(Arg->IgnoreImpCasts())) return; +// Avoid false positives when the object is constructed from a conditional +// operator argument. A common case is: +// // 'ptr' might not be owned by the Owner object. +// std::string_view s = cond() ? Owner().ptr : sv; +if (const auto *Cond = +dyn_cast(Arg->IgnoreImpCasts()); +Cond && isPointerLikeType(Cond->getType())) + return; + auto ReturnType = Callee->getReturnType(); // Once we initialized a value with a non gsl-owner reference, it can no diff --git a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp index 45b4dc838f44ed..4c19367bb7f3dd 100644 --- a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp +++ b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp @@ -777,3 +777,32 @@ void test4() { } } // namespace LifetimeboundInterleave + +namespace GH120206 { +struct S { + std::string_view s; +}; + +struct [[gsl::Owner]] Q1 { + const S* get() const [[clang::lifetimebound]]; +}; +std::string_view test1(int c, std::string_view sv) { + std::string_view k = c > 1 ? Q1().get()->s : sv; + if (c == 1) +return c > 1 ? Q1().get()->s : sv; + Q1 q; + return c > 1 ? q.get()->s : sv; +} + +struct Q2 { + const S* get() const [[clang::lifetimebound]]; +}; +std::string_view test2(int c, std::string_view sv) { + std::string_view k = c > 1 ? Q2().get()->s : sv; + if (c == 1) +return c > 1 ? Q2().get()->s : sv; + Q2 q; + return c > 1 ? q.get()->s : sv; +} + +} // namespace GH120206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix dangling false positives for conditional operators. (PR #120233)
https://github.com/hokein closed https://github.com/llvm/llvm-project/pull/120233 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix dangling false positives for conditional operators. (PR #120233)
hokein wrote: > Please add more details to the summary, especially a note that there > theoretically could be false negatives but it fixes the overall issue and the > tradeoff good. Done. https://github.com/llvm/llvm-project/pull/120233 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Fixes for %b printf extension handling (PR #120689)
https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/120689 >From 3c205ebace308c6d37dff289fab38f93bcb76309 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Thu, 19 Dec 2024 21:35:57 -0500 Subject: [PATCH] [clang][Sema] Fixes for %b printf extension handling The %b printf extension in the kernel is not fixed to a int type. On sparc64 there are various %llb formats. Adjust the code to handle the length specifiers and type check like it is used by the regular case. --- clang/include/clang/AST/FormatString.h | 6 ++-- clang/lib/AST/FormatString.cpp | 9 ++ clang/lib/Sema/SemaChecking.cpp | 38 +--- clang/test/Sema/format-strings-freebsd.c | 8 - 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/clang/include/clang/AST/FormatString.h b/clang/include/clang/AST/FormatString.h index a074dd23e2ad4c..1ff0d036b70d1a 100644 --- a/clang/include/clang/AST/FormatString.h +++ b/clang/include/clang/AST/FormatString.h @@ -240,8 +240,10 @@ class ConversionSpecifier { bool isIntArg() const { return (kind >= IntArgBeg && kind <= IntArgEnd) || kind == FreeBSDrArg || kind == FreeBSDyArg; } - bool isUIntArg() const { return kind >= UIntArgBeg && kind <= UIntArgEnd; } - bool isAnyIntArg() const { return kind >= IntArgBeg && kind <= UIntArgEnd; } + bool isUIntArg() const { return (kind >= UIntArgBeg && kind <= UIntArgEnd) || +kind == FreeBSDbArg; } + bool isAnyIntArg() const { return (kind >= IntArgBeg && kind <= UIntArgEnd) || +kind == FreeBSDbArg; } bool isDoubleArg() const { return kind >= DoubleArgBeg && kind <= DoubleArgEnd; } diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp index e892c1592df986..6ccc0c91c025f6 100644 --- a/clang/lib/AST/FormatString.cpp +++ b/clang/lib/AST/FormatString.cpp @@ -879,6 +879,10 @@ bool FormatSpecifier::hasValidLengthModifier(const TargetInfo &Target, case ConversionSpecifier::XArg: case ConversionSpecifier::nArg: return true; +case ConversionSpecifier::FreeBSDbArg: + return Target.getTriple().isOSFreeBSD() || + Target.getTriple().isPS() || + Target.getTriple().isOSOpenBSD(); case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS(); @@ -919,6 +923,10 @@ bool FormatSpecifier::hasValidLengthModifier(const TargetInfo &Target, case ConversionSpecifier::ScanListArg: case ConversionSpecifier::ZArg: return true; +case ConversionSecifier::FreeBSDbArg: + return Target.getTriple().isOSFreeBSD() || + Target.getTriple().isPS() || + Target.getTriple().isOSOpenBSD(); case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS(); @@ -1085,6 +1093,7 @@ bool FormatSpecifier::hasStandardLengthConversionCombination() const { case ConversionSpecifier::uArg: case ConversionSpecifier::xArg: case ConversionSpecifier::XArg: +case ConversionSpecifier::FreeBSDbArg: return false; default: return true; diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e703a62ff9cf18..e50118762fff32 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7170,18 +7170,34 @@ bool CheckPrintfHandler::HandlePrintfSpecifier( // Claim the second argument. CoveredArgs.set(argIndex + 1); -// Type check the first argument (int for %b, pointer for %D) const Expr *Ex = getDataArg(argIndex); -const analyze_printf::ArgType &AT = - (CS.getKind() == ConversionSpecifier::FreeBSDbArg) ? -ArgType(S.Context.IntTy) : ArgType::CPointerTy; -if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType())) - EmitFormatDiagnostic( - S.PDiag(diag::warn_format_conversion_argument_type_mismatch) - << AT.getRepresentativeTypeName(S.Context) << Ex->getType() - << false << Ex->getSourceRange(), - Ex->getBeginLoc(), /*IsStringLocation*/ false, - getSpecifierRange(startSpecifier, specifierLen)); +if (CS.getKind() == ConversionSpecifier::FreeBSDDArg) { + // Type check the first argument (pointer for %D) + const analyze_printf::ArgType &AT = ArgType::CPointerTy; + if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType())) +EmitFormatDiagnostic( +S.PDiag(diag::warn_format_conversion_argument_type_mismatch) +<< AT.getRepresentativeTypeName(S.Context) << Ex->getType() +<< false << Ex->getSourceRange(), +Ex->getBeginLoc(), /*IsStringLocation*/ false, +getSpecifierRange(startSpecifier, specifierLen)); +} else { +
[clang] [clang][Sema] Fixes for %b printf extension handling (PR #120689)
https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/120689 >From 67a87a492c0b84f4d76ae4818658969cd11a379e Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Thu, 19 Dec 2024 21:35:57 -0500 Subject: [PATCH] [clang][Sema] Fixes for %b printf extension handling The %b printf extension in the kernel is not fixed to a int type. On sparc64 there are various %llb formats. Adjust the code to handle the length specifiers and type check like it is used by the regular case. --- clang/include/clang/AST/FormatString.h | 6 ++-- clang/lib/AST/FormatString.cpp | 9 ++ clang/lib/Sema/SemaChecking.cpp | 38 +--- clang/test/Sema/format-strings-freebsd.c | 8 - 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/clang/include/clang/AST/FormatString.h b/clang/include/clang/AST/FormatString.h index a074dd23e2ad4c..1ff0d036b70d1a 100644 --- a/clang/include/clang/AST/FormatString.h +++ b/clang/include/clang/AST/FormatString.h @@ -240,8 +240,10 @@ class ConversionSpecifier { bool isIntArg() const { return (kind >= IntArgBeg && kind <= IntArgEnd) || kind == FreeBSDrArg || kind == FreeBSDyArg; } - bool isUIntArg() const { return kind >= UIntArgBeg && kind <= UIntArgEnd; } - bool isAnyIntArg() const { return kind >= IntArgBeg && kind <= UIntArgEnd; } + bool isUIntArg() const { return (kind >= UIntArgBeg && kind <= UIntArgEnd) || +kind == FreeBSDbArg; } + bool isAnyIntArg() const { return (kind >= IntArgBeg && kind <= UIntArgEnd) || +kind == FreeBSDbArg; } bool isDoubleArg() const { return kind >= DoubleArgBeg && kind <= DoubleArgEnd; } diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp index e892c1592df986..422fee7ab5d857 100644 --- a/clang/lib/AST/FormatString.cpp +++ b/clang/lib/AST/FormatString.cpp @@ -879,6 +879,10 @@ bool FormatSpecifier::hasValidLengthModifier(const TargetInfo &Target, case ConversionSpecifier::XArg: case ConversionSpecifier::nArg: return true; +case ConversionSpecifier::FreeBSDbArg: + return Target.getTriple().isOSFreeBSD() || + Target.getTriple().isPS() || + Target.getTriple().isOSOpenBSD(); case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS(); @@ -919,6 +923,10 @@ bool FormatSpecifier::hasValidLengthModifier(const TargetInfo &Target, case ConversionSpecifier::ScanListArg: case ConversionSpecifier::ZArg: return true; +case ConversionSpecifier::FreeBSDbArg: + return Target.getTriple().isOSFreeBSD() || + Target.getTriple().isPS() || + Target.getTriple().isOSOpenBSD(); case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS(); @@ -1085,6 +1093,7 @@ bool FormatSpecifier::hasStandardLengthConversionCombination() const { case ConversionSpecifier::uArg: case ConversionSpecifier::xArg: case ConversionSpecifier::XArg: +case ConversionSpecifier::FreeBSDbArg: return false; default: return true; diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e703a62ff9cf18..e50118762fff32 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7170,18 +7170,34 @@ bool CheckPrintfHandler::HandlePrintfSpecifier( // Claim the second argument. CoveredArgs.set(argIndex + 1); -// Type check the first argument (int for %b, pointer for %D) const Expr *Ex = getDataArg(argIndex); -const analyze_printf::ArgType &AT = - (CS.getKind() == ConversionSpecifier::FreeBSDbArg) ? -ArgType(S.Context.IntTy) : ArgType::CPointerTy; -if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType())) - EmitFormatDiagnostic( - S.PDiag(diag::warn_format_conversion_argument_type_mismatch) - << AT.getRepresentativeTypeName(S.Context) << Ex->getType() - << false << Ex->getSourceRange(), - Ex->getBeginLoc(), /*IsStringLocation*/ false, - getSpecifierRange(startSpecifier, specifierLen)); +if (CS.getKind() == ConversionSpecifier::FreeBSDDArg) { + // Type check the first argument (pointer for %D) + const analyze_printf::ArgType &AT = ArgType::CPointerTy; + if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType())) +EmitFormatDiagnostic( +S.PDiag(diag::warn_format_conversion_argument_type_mismatch) +<< AT.getRepresentativeTypeName(S.Context) << Ex->getType() +<< false << Ex->getSourceRange(), +Ex->getBeginLoc(), /*IsStringLocation*/ false, +getSpecifierRange(startSpecifier, specifierLen)); +} else { +
[clang] [llvm] [TargetLibraryInfo] Add libmvec support for risc-v (PR #119844)
@@ -236,6 +236,79 @@ TLI_DEFINE_VECFUNC("llvm.log.f64", "_ZGVdN4v_log", FIXED(4), "_ZGV_LLVM_N4v") TLI_DEFINE_VECFUNC("llvm.log.f32", "_ZGVbN4v_logf", FIXED(4), "_ZGV_LLVM_N4v") TLI_DEFINE_VECFUNC("llvm.log.f32", "_ZGVdN8v_logf", FIXED(8), "_ZGV_LLVM_N8v") +#elif defined(TLI_DEFINE_LIBMVEC_RVV_VECFUNCS) +// GLIBC Vector math Functions for RISC-V + +TLI_DEFINE_VECFUNC("sin", "_ZGV1Nxv_sin", SCALABLE(1), "_ZGVr1Nxv") mga-sc wrote: You have missed `r` letter in mangled vector name`after ZGV according to [mention MR](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/455/files) https://github.com/llvm/llvm-project/pull/119844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits