From 8c369eb4965a1799960872cd65e85b284b97784c Mon Sep 17 00:00:00 2001 From: Chen Zheng Date: Wed, 18 Oct 2023 04:45:24 -0400 Subject: [PATCH 1/6] nfc, address post commit comments related to code format for 581c64a --- llvm/include/llvm/Object/XCOFFObjectFile.h | 1 + llvm/lib/Object/SymbolSize.cpp | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h index be468e888aa5c..63064abb4d3c3 100644 --- a/llvm/include/llvm/Object/XCOFFObjectFile.h +++ b/llvm/include/llvm/Object/XCOFFObjectFile.h @@ -783,6 +783,7 @@ class XCOFFSymbolRef : public SymbolRef { const XCOFFSymbolEntry32 *getSymbol32() const { return reinterpret_cast(getRawDataRefImpl().p); } + const XCOFFSymbolEntry64 *getSymbol64() const { return reinterpret_cast(getRawDataRefImpl().p); } diff --git a/llvm/lib/Object/SymbolSize.cpp b/llvm/lib/Object/SymbolSize.cpp index c4f30b1072d52..cb20feffb710b 100644 --- a/llvm/lib/Object/SymbolSize.cpp +++ b/llvm/lib/Object/SymbolSize.cpp @@ -60,8 +60,7 @@ llvm::object::computeSymbolSizes(const ObjectFile &O) { } if (const auto *E = dyn_cast(&O)) { - auto Syms = E->symbols(); - for (XCOFFSymbolRef Sym : Syms) + for (XCOFFSymbolRef Sym : E->symbols()) Ret.push_back({Sym, Sym.getSize()}); return Ret; } From 48a53509e851c93f352c967da1feb1c8fb2abd9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kadir=20=C3=A7etinkaya?= Date: Wed, 18 Oct 2023 10:51:31 +0200 Subject: [PATCH 2/6] [clang][USR] Encode full decl-context also for anon namespaces (#68325) Otherwise we create collisions, e.g. a struct named Foo inside an anonymous namespace will get the same USR no matter what the surrounding decl-context is. --- clang/lib/Index/USRGeneration.cpp | 9 +++++---- clang/test/Index/USR/decl-context.cpp | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 clang/test/Index/USR/decl-context.cpp diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp index f778a6208d512..614f5d8d2cad5 100644 --- a/clang/lib/Index/USRGeneration.cpp +++ b/clang/lib/Index/USRGeneration.cpp @@ -9,6 +9,7 @@ #include "clang/Index/USRGeneration.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/DeclVisitor.h" #include "clang/Basic/FileManager.h" @@ -368,14 +369,14 @@ void USRGenerator::VisitTemplateTemplateParmDecl( } void USRGenerator::VisitNamespaceDecl(const NamespaceDecl *D) { + if (IgnoreResults) + return; + VisitDeclContext(D->getDeclContext()); if (D->isAnonymousNamespace()) { Out << "@aN"; return; } - - VisitDeclContext(D->getDeclContext()); - if (!IgnoreResults) - Out << "@N@" << D->getName(); + Out << "@N@" << D->getName(); } void USRGenerator::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { diff --git a/clang/test/Index/USR/decl-context.cpp b/clang/test/Index/USR/decl-context.cpp new file mode 100644 index 0000000000000..a57137a5c89b5 --- /dev/null +++ b/clang/test/Index/USR/decl-context.cpp @@ -0,0 +1,14 @@ +// RUN: c-index-test core -print-source-symbols -- -std=c++20 %s | FileCheck %s + +namespace ns { +namespace { +struct Foo {}; +// CHECK: [[@LINE-1]]:8 | struct/C | Foo | c:decl-context.cpp@N@ns@aN@S@Foo +} +} +namespace ns2 { +namespace { +struct Foo {}; +// CHECK: [[@LINE-1]]:8 | struct/C | Foo | c:decl-context.cpp@N@ns2@aN@S@Foo +} +} From b4b35a5d2b4ee26bf79b8a92715dd200f3f9cc49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 18 Oct 2023 12:36:27 +0300 Subject: [PATCH 3/6] [clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (#69078) This adds actual test cases for all the cases that are listed in a code comment in the implementation of this function; having such test coverage eases doing further modifications to the function. --- clang/unittests/Driver/CMakeLists.txt | 1 + clang/unittests/Driver/GCCVersionTest.cpp | 52 +++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 clang/unittests/Driver/GCCVersionTest.cpp diff --git a/clang/unittests/Driver/CMakeLists.txt b/clang/unittests/Driver/CMakeLists.txt index e37c158d7137a..752037f78fb14 100644 --- a/clang/unittests/Driver/CMakeLists.txt +++ b/clang/unittests/Driver/CMakeLists.txt @@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS add_clang_unittest(ClangDriverTests DistroTest.cpp DXCModeTest.cpp + GCCVersionTest.cpp ToolChainTest.cpp ModuleCacheTest.cpp MultilibBuilderTest.cpp diff --git a/clang/unittests/Driver/GCCVersionTest.cpp b/clang/unittests/Driver/GCCVersionTest.cpp new file mode 100644 index 0000000000000..9ae335bca77dc --- /dev/null +++ b/clang/unittests/Driver/GCCVersionTest.cpp @@ -0,0 +1,52 @@ +//===- unittests/Driver/GCCVersionTest.cpp --- GCCVersion parser tests ----===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Unit tests for Generic_GCC::GCCVersion +// +//===----------------------------------------------------------------------===// + +#include "../../lib/Driver/ToolChains/Gnu.h" +#include "gtest/gtest.h" + +using namespace clang; +using namespace clang::driver; + +namespace { + +struct VersionParseTest { + std::string Text; + + int Major, Minor, Patch; + std::string MajorStr, MinorStr, PatchSuffix; +}; + +const VersionParseTest TestCases[] = { + {"5", 5, -1, -1, "5", "", ""}, + {"4.4", 4, 4, -1, "4", "4", ""}, + {"4.4-patched", 4, 4, -1, "4", "4", "-patched"}, + {"4.4.0", 4, 4, 0, "4", "4", ""}, + {"4.4.x", 4, 4, -1, "4", "4", ""}, + {"4.4.2-rc4", 4, 4, 2, "4", "4", "-rc4"}, + {"4.4.x-patched", 4, 4, -1, "4", "4", ""}, + {"not-a-version", -1, -1, -1, "", "", ""}, +}; + +TEST(GCCVersionTest, Parse) { + for (const auto &TC : TestCases) { + auto V = toolchains::Generic_GCC::GCCVersion::Parse(TC.Text); + EXPECT_EQ(V.Text, TC.Text); + EXPECT_EQ(V.Major, TC.Major); + EXPECT_EQ(V.Minor, TC.Minor); + EXPECT_EQ(V.Patch, TC.Patch); + EXPECT_EQ(V.MajorStr, TC.MajorStr); + EXPECT_EQ(V.MinorStr, TC.MinorStr); + EXPECT_EQ(V.PatchSuffix, TC.PatchSuffix); + } +} + +} // end anonymous namespace From d7246c1ab523ad1ca8bc375a1a080a6ce021f243 Mon Sep 17 00:00:00 2001 From: LLVM GN Syncbot Date: Wed, 18 Oct 2023 09:36:46 +0000 Subject: [PATCH 4/6] [gn build] Port b4b35a5d2b4e --- llvm/utils/gn/secondary/clang/unittests/Driver/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/utils/gn/secondary/clang/unittests/Driver/BUILD.gn b/llvm/utils/gn/secondary/clang/unittests/Driver/BUILD.gn index 14900e2254cb3..4c7e3c110b2d1 100644 --- a/llvm/utils/gn/secondary/clang/unittests/Driver/BUILD.gn +++ b/llvm/utils/gn/secondary/clang/unittests/Driver/BUILD.gn @@ -14,6 +14,7 @@ unittest("ClangDriverTests") { sources = [ "DXCModeTest.cpp", "DistroTest.cpp", + "GCCVersionTest.cpp", "ModuleCacheTest.cpp", "MultilibBuilderTest.cpp", "MultilibTest.cpp", From 975ec8368fcb3f9157481e78f10e589a38915116 Mon Sep 17 00:00:00 2001 From: Sander de Smalen Date: Wed, 18 Oct 2023 10:39:43 +0100 Subject: [PATCH 5/6] [compiler-rt] Only build SME ABI routines for baremetal or platforms that have sys/auxv.h (#69423) This avoids link failures on other platorms that don't (yet) have an implementation of __aarch64_sme_accessible. --- compiler-rt/lib/builtins/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt index 4f210a5c0fef9..cf2648233b0cf 100644 --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -555,8 +555,9 @@ set(aarch64_SOURCES aarch64/fp_mode.c ) -if(COMPILER_RT_HAS_ASM_SME) +if(COMPILER_RT_HAS_ASM_SME AND (COMPILER_RT_HAS_AUXV OR COMPILER_RT_BAREMETAL_BUILD)) list(APPEND aarch64_SOURCES aarch64/sme-abi.S aarch64/sme-abi-init.c) + message(STATUS "AArch64 SME ABI routines enabled") else() message(STATUS "AArch64 SME ABI routines disabled") endif() From 675231eb09ca37a8b76f748c0b73a1e26604ff20 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Wed, 18 Oct 2023 10:40:07 +0100 Subject: [PATCH 6/6] [SVE ACLE] Allow default zero initialisation for svcount_t. (#69321) This matches the behaviour of the other SVE ACLE types. --- .../CodeGenCXX/aarch64-sve-vector-init.cpp | 18 ++++++++++++++++++ .../SelectionDAG/SelectionDAGBuilder.cpp | 6 ++++++ llvm/lib/IR/Type.cpp | 3 ++- llvm/test/CodeGen/AArch64/sve-zeroinit.ll | 7 +++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp index 2088e80acfc80..464275f164c2a 100644 --- a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp +++ b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp @@ -55,6 +55,7 @@ // CHECK-NEXT: [[B8:%.*]] = alloca , align 2 // CHECK-NEXT: [[B8X2:%.*]] = alloca , align 2 // CHECK-NEXT: [[B8X4:%.*]] = alloca , align 2 +// CHECK-NEXT: [[CNT:%.*]] = alloca target("aarch64.svcount"), align 2 // CHECK-NEXT: store zeroinitializer, ptr [[S8]], align 16 // CHECK-NEXT: store zeroinitializer, ptr [[S16]], align 16 // CHECK-NEXT: store zeroinitializer, ptr [[S32]], align 16 @@ -106,6 +107,7 @@ // CHECK-NEXT: store zeroinitializer, ptr [[B8]], align 2 // CHECK-NEXT: store zeroinitializer, ptr [[B8X2]], align 2 // CHECK-NEXT: store zeroinitializer, ptr [[B8X4]], align 2 +// CHECK-NEXT: store target("aarch64.svcount") zeroinitializer, ptr [[CNT]], align 2 // CHECK-NEXT: ret void // void test_locals(void) { @@ -164,6 +166,8 @@ void test_locals(void) { __SVBool_t b8{}; __clang_svboolx2_t b8x2{}; __clang_svboolx4_t b8x4{}; + + __SVCount_t cnt{}; } // CHECK-LABEL: define dso_local void @_Z12test_copy_s8u10__SVInt8_t @@ -879,3 +883,17 @@ void test_copy_b8x2(__clang_svboolx2_t a) { void test_copy_b8x4(__clang_svboolx4_t a) { __clang_svboolx4_t b{a}; } + +// CHECK-LABEL: define dso_local void @_Z13test_copy_cntu11__SVCount_t +// CHECK-SAME: (target("aarch64.svcount") [[A:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT: [[A_ADDR:%.*]] = alloca target("aarch64.svcount"), align 2 +// CHECK-NEXT: [[B:%.*]] = alloca target("aarch64.svcount"), align 2 +// CHECK-NEXT: store target("aarch64.svcount") [[A]], ptr [[A_ADDR]], align 2 +// CHECK-NEXT: [[TMP0:%.*]] = load target("aarch64.svcount"), ptr [[A_ADDR]], align 2 +// CHECK-NEXT: store target("aarch64.svcount") [[TMP0]], ptr [[B]], align 2 +// CHECK-NEXT: ret void +// +void test_copy_cnt(__SVCount_t a) { + __SVCount_t b{a}; +} diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 4bb0ba6f08310..eabc76334fae1 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1738,6 +1738,12 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) { if (const auto *NC = dyn_cast(C)) return getValue(NC->getGlobalValue()); + if (VT == MVT::aarch64svcount) { + assert(C->isNullValue() && "Can only zero this target type!"); + return DAG.getNode(ISD::BITCAST, getCurSDLoc(), VT, + DAG.getConstant(0, getCurSDLoc(), MVT::nxv16i1)); + } + VectorType *VecTy = cast(V->getType()); // Now that we know the number and type of the elements, get that number of diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp index 97febcd99b411..006278d16484c 100644 --- a/llvm/lib/IR/Type.cpp +++ b/llvm/lib/IR/Type.cpp @@ -841,7 +841,8 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) { // Opaque types in the AArch64 name space. if (Name == "aarch64.svcount") - return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16)); + return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16), + TargetExtType::HasZeroInit); return TargetTypeInfo(Type::getVoidTy(C)); } diff --git a/llvm/test/CodeGen/AArch64/sve-zeroinit.ll b/llvm/test/CodeGen/AArch64/sve-zeroinit.ll index c436bb7f822b7..eab39d0ef4025 100644 --- a/llvm/test/CodeGen/AArch64/sve-zeroinit.ll +++ b/llvm/test/CodeGen/AArch64/sve-zeroinit.ll @@ -86,3 +86,10 @@ define @test_zeroinit_16xi1() { ; CHECK-NEXT: ret ret zeroinitializer } + +define target("aarch64.svcount") @test_zeroinit_svcount() "target-features"="+sme2" { +; CHECK-LABEL: test_zeroinit_svcount +; CHECK: pfalse p0.b +; CHECK-NEXT: ret + ret target("aarch64.svcount") zeroinitializer +}