From 1c7b98b83939e064e2dc867a252a8b5e6126a796 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 26 Sep 2025 20:03:19 -0700 Subject: [PATCH 1/4] Update LLVM and update APIs This also updates the patch file for compiler-rt as upstream has changed a bit. No functional change. --- MODULE.bazel | 5 ++--- ...2_Added_Bazel_build_for_compiler_rt_fuzzer.patch | 13 ++++++++----- common/raw_hashtable_benchmark_helpers.cpp | 4 ++-- common/raw_hashtable_metadata_group.h | 2 +- toolchain/base/llvm_tools.bzl | 1 - toolchain/check/cpp/import.cpp | 4 ++-- .../testdata/interop/cpp/function/thunk_ast.carbon | 2 +- toolchain/driver/clang_runner.cpp | 7 +++++-- toolchain/driver/llvm_runner_test.cpp | 1 - 9 files changed, 21 insertions(+), 18 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 476bf970586a9..1d11046e861b8 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -103,14 +103,13 @@ bazel_dep(name = "zstd", version = "1.5.7", repo_name = "llvm_zstd") # We pin to specific upstream commits and try to track top-of-tree reasonably # closely rather than pinning to a specific release. -# HEAD as of 2025-09-07. -llvm_project_version = "c000c9e4bf737c1cc0e5c7b435b24ea73d21ee05" +# HEAD as of 2025-11-14. +llvm_project_version = "b2a81888f55735e9249ef25b6014a989e7f03969" # Load a repository for the raw llvm-project, pre-overlay. http_archive( name = "llvm-raw", build_file_content = "# empty", - integrity = "sha256-6URudXFgqoCuQI4hbb7AlN4Wj7WzLHFB4AWGjUV0UAI=", patch_args = ["-p1"], patches = [ "@carbon//bazel/llvm_project:0001_Patch_for_mallinfo2_when_using_Bazel_build_system.patch", diff --git a/bazel/llvm_project/0002_Added_Bazel_build_for_compiler_rt_fuzzer.patch b/bazel/llvm_project/0002_Added_Bazel_build_for_compiler_rt_fuzzer.patch index 7c55f4d48c1d1..39d22fde195ae 100644 --- a/bazel/llvm_project/0002_Added_Bazel_build_for_compiler_rt_fuzzer.patch +++ b/bazel/llvm_project/0002_Added_Bazel_build_for_compiler_rt_fuzzer.patch @@ -8,14 +8,13 @@ Subject: [PATCH] Add libfuzzer target to compiler-rt. 1 file changed, 17 insertions(+) diff --git a/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel b/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel -index 9bdd454e1e36..0f30c21f63dc 100644 +index 90264449de76..115da4cb77f6 100644 --- a/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel -@@ -50,3 +50,20 @@ cc_library( - ":config", +@@ -57,6 +57,23 @@ cc_library( ], ) -+ + +cc_library( + name = "FuzzerMain", + srcs = glob( @@ -32,5 +31,9 @@ index 9bdd454e1e36..0f30c21f63dc 100644 + ], + includes = ["lib/fuzzer"], +) ++ + cc_library( + name = "orc_rt_common_headers", + hdrs = [ -- -2.42.0 \ No newline at end of file +2.42.0 diff --git a/common/raw_hashtable_benchmark_helpers.cpp b/common/raw_hashtable_benchmark_helpers.cpp index 11f431beae16e..6e4b5ab7cfd38 100644 --- a/common/raw_hashtable_benchmark_helpers.cpp +++ b/common/raw_hashtable_benchmark_helpers.cpp @@ -61,7 +61,7 @@ static_assert(llvm::isPowerOf2_64(NumFourCharStrs)); static auto MakeFourCharStrs(llvm::ArrayRef characters, absl::BitGen& gen) -> llvm::OwningArrayRef> { constexpr ssize_t NumCharsMask = NumChars - 1; - constexpr ssize_t NumCharsShift = llvm::CTLog2(); + constexpr ssize_t NumCharsShift = llvm::ConstantLog2(); llvm::OwningArrayRef> four_char_strs(NumFourCharStrs); for (auto [i, str] : llvm::enumerate(four_char_strs)) { str[0] = characters[i & NumCharsMask]; @@ -372,7 +372,7 @@ auto DumpHashStatistics(llvm::ArrayRef keys) -> void { ssize_t expected_size = llvm::NextPowerOf2(keys.size() + (keys.size() / 7) - 1); - constexpr int GroupShift = llvm::CTLog2(); + constexpr int GroupShift = llvm::ConstantLog2(); size_t mask = ComputeProbeMaskFromSize(expected_size); uint64_t salt = ComputeSeed(); diff --git a/common/raw_hashtable_metadata_group.h b/common/raw_hashtable_metadata_group.h index 48bd11fb9a16d..3715fa05753c6 100644 --- a/common/raw_hashtable_metadata_group.h +++ b/common/raw_hashtable_metadata_group.h @@ -124,7 +124,7 @@ class BitIndex return reinterpret_cast( &reinterpret_cast(pointer)[index]); } else if constexpr (llvm::isPowerOf2_64(sizeof(T))) { - constexpr size_t ScaleShift = llvm::CTLog2(); + constexpr size_t ScaleShift = llvm::ConstantLog2(); static_assert(ScaleShift <= ByteEncodingShift, "Scaling by >=8 should be handled above!"); constexpr size_t FoldedShift = ByteEncodingShift - ScaleShift; diff --git a/toolchain/base/llvm_tools.bzl b/toolchain/base/llvm_tools.bzl index 45b52192e6a6f..476f9ba86bda7 100644 --- a/toolchain/base/llvm_tools.bzl +++ b/toolchain/base/llvm_tools.bzl @@ -24,7 +24,6 @@ LLVM_MAIN_TOOLS = { "nm": struct(bin_name = "llvm-nm", lib = "@llvm-project//llvm:llvm-nm-lib"), "objcopy": struct(bin_name = "llvm-objcopy", lib = "@llvm-project//llvm:llvm-objcopy-lib"), "objdump": struct(bin_name = "llvm-objdump", lib = "@llvm-project//llvm:llvm-objdump-lib"), - "profdata": struct(bin_name = "llvm-profdata", lib = "@llvm-project//llvm:llvm-profdata-lib"), "rc": struct(bin_name = "llvm-rc", lib = "@llvm-project//llvm:llvm-rc-lib"), "readobj": struct(bin_name = "llvm-readobj", lib = "@llvm-project//llvm:llvm-readobj-lib"), "sancov": struct(bin_name = "sancov", lib = "@llvm-project//llvm:sancov-lib"), diff --git a/toolchain/check/cpp/import.cpp b/toolchain/check/cpp/import.cpp index 8956726c50ec1..88b4497e077cf 100644 --- a/toolchain/check/cpp/import.cpp +++ b/toolchain/check/cpp/import.cpp @@ -1181,7 +1181,7 @@ static auto LookupCustomRecordType(Context& context, // Maps a C++ tag type (class, struct, union, enum) to a Carbon type. static auto MapTagType(Context& context, const clang::TagType& type) -> TypeExpr { - auto* tag_decl = type.getOriginalDecl(); + auto* tag_decl = type.getDecl(); CARBON_CHECK(tag_decl); // Check if the declaration is already mapped. @@ -1833,7 +1833,7 @@ static auto AddDependentUnimportedTypeDecls(Context& context, } if (const auto* tag_type = type->getAs()) { - AddDependentDecl(context, SemIR::ClangDeclKey(tag_type->getOriginalDecl()), + AddDependentDecl(context, SemIR::ClangDeclKey(tag_type->getDecl()), worklist); } } diff --git a/toolchain/check/testdata/interop/cpp/function/thunk_ast.carbon b/toolchain/check/testdata/interop/cpp/function/thunk_ast.carbon index 9b5b3511fab89..87203d57c1473 100644 --- a/toolchain/check/testdata/interop/cpp/function/thunk_ast.carbon +++ b/toolchain/check/testdata/interop/cpp/function/thunk_ast.carbon @@ -64,7 +64,7 @@ auto foo(short a) -> void; // CHECK:STDOUT: | |-ParmVarDecl {{0x[a-f0-9]+}} <> implicit 'std::align_val_t' // CHECK:STDOUT: | `-VisibilityAttr {{0x[a-f0-9]+}} <> Implicit Default // CHECK:STDOUT: |-FunctionDecl {{0x[a-f0-9]+}} <:8:1, line:14:1> line:8:7 operator new 'void *(unsigned long, void *) noexcept' -// CHECK:STDOUT: | |-ParmVarDecl {{0x[a-f0-9]+}} <:174:23, col:37> :8:33 'unsigned long' +// CHECK:STDOUT: | |-ParmVarDecl {{0x[a-f0-9]+}} <:176:23, col:37> :8:33 'unsigned long' // CHECK:STDOUT: | `-ParmVarDecl {{0x[a-f0-9]+}} col:40 'void *' // CHECK:STDOUT: `-FunctionDecl {{0x[a-f0-9]+}} <./thunk_required.h:[[@LINE-51]]:6> col:6 foo__carbon_thunk 'void (short * _Nonnull)' extern // CHECK:STDOUT: |-ParmVarDecl {{0x[a-f0-9]+}} col:6 used a 'short * _Nonnull':'short *' diff --git a/toolchain/driver/clang_runner.cpp b/toolchain/driver/clang_runner.cpp index 37ea7280318c5..472ec9a1e0994 100644 --- a/toolchain/driver/clang_runner.cpp +++ b/toolchain/driver/clang_runner.cpp @@ -326,8 +326,11 @@ auto ClangRunner::RunCC1(llvm::SmallVectorImpl& cc1_args) -> int { installation_->clang_resource_path(); } + // Create the filesystem. + clang_instance->createVirtualFileSystem(fs_, &diag_buffer); + // Create the actual diagnostics engine. - clang_instance->createDiagnostics(*fs_); + clang_instance->createDiagnostics(); if (!clang_instance->hasDiagnostics()) { return EXIT_FAILURE; } @@ -374,7 +377,7 @@ auto ClangRunner::RunCC1(llvm::SmallVectorImpl& cc1_args) -> int { // options are stored in the compiler invocation and we can recreate the VFS // from the compiler invocation. if (!clang_instance->hasFileManager()) { - clang_instance->createFileManager(fs_); + clang_instance->createFileManager(); } if (auto profiler_output = clang_instance->createOutputFile( diff --git a/toolchain/driver/llvm_runner_test.cpp b/toolchain/driver/llvm_runner_test.cpp index d15b90d20f426..87a678d187e36 100644 --- a/toolchain/driver/llvm_runner_test.cpp +++ b/toolchain/driver/llvm_runner_test.cpp @@ -47,7 +47,6 @@ TEST(LLVMRunnerTest, Version) { case LLVMTool::InstallNameTool: case LLVMTool::Lipo: case LLVMTool::Objcopy: - case LLVMTool::Profdata: case LLVMTool::Sancov: case LLVMTool::Strip: case LLVMTool::Symbolizer: From c9d3e9670dc0e70ba6656c80fd23b0fbd0c45a6f Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 14 Nov 2025 20:07:32 +0000 Subject: [PATCH 2/4] Fix clang-tidy. --- toolchain/check/cpp/import.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain/check/cpp/import.cpp b/toolchain/check/cpp/import.cpp index 88b4497e077cf..247bfb7f85319 100644 --- a/toolchain/check/cpp/import.cpp +++ b/toolchain/check/cpp/import.cpp @@ -1095,7 +1095,7 @@ static auto MapBuiltinIntegerType(Context& context, SemIR::LocId loc_id, unsigned width = ast_context.getIntWidth(qual_type); bool is_signed = type.isSignedInteger(); auto int_n_type = ast_context.getIntTypeForBitwidth(width, is_signed); - if (ast_context.hasSameType(qual_type, int_n_type)) { + if (clang::ASTContext::hasSameType(qual_type, int_n_type)) { TypeExpr type_expr = MakeIntType(context, context.ints().Add(width), is_signed); // Try to make sure integer types of 32 or 64 bits are complete so we can @@ -1108,7 +1108,7 @@ static auto MapBuiltinIntegerType(Context& context, SemIR::LocId loc_id, } return type_expr; } - if (ast_context.hasSameType(qual_type, ast_context.CharTy)) { + if (clang::ASTContext::hasSameType(qual_type, ast_context.CharTy)) { return ExprAsType(context, Parse::NodeId::None, MakeCharTypeLiteral(context, Parse::NodeId::None)); } From 5a3ea4614eac28189ddee842e245ca33eb23d9ae Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 14 Nov 2025 20:48:19 +0000 Subject: [PATCH 3/4] Add back integrity with new hash. --- MODULE.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/MODULE.bazel b/MODULE.bazel index 1d11046e861b8..94bb4864acc3e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -110,6 +110,7 @@ llvm_project_version = "b2a81888f55735e9249ef25b6014a989e7f03969" http_archive( name = "llvm-raw", build_file_content = "# empty", + integrity = "sha256-PkRNmo5RZgP0RecsLW8kbg7SIS84OPX+StuNL4omIhw=", patch_args = ["-p1"], patches = [ "@carbon//bazel/llvm_project:0001_Patch_for_mallinfo2_when_using_Bazel_build_system.patch", From 0b8bbef037283266736f0285c1d2b6b7795ff9b4 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 15 Nov 2025 01:25:56 +0000 Subject: [PATCH 4/4] More clang-tidy --- toolchain/check/cpp/import.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/toolchain/check/cpp/import.cpp b/toolchain/check/cpp/import.cpp index 247bfb7f85319..082b165ed534b 100644 --- a/toolchain/check/cpp/import.cpp +++ b/toolchain/check/cpp/import.cpp @@ -1112,7 +1112,8 @@ static auto MapBuiltinIntegerType(Context& context, SemIR::LocId loc_id, return ExprAsType(context, Parse::NodeId::None, MakeCharTypeLiteral(context, Parse::NodeId::None)); } - if (ast_context.hasSameType(qual_type, ast_context.LongTy) && width == 32) { + if (clang::ASTContext::hasSameType(qual_type, ast_context.LongTy) && + width == 32) { return ExprAsType(context, Parse::NodeId::None, LookupNameInCore(context, Parse::NodeId::None, {"CppCompat", "Long32"}));