Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ git_override(
build_file_content = "# empty",
# 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 2026-06-28.
commit = "f3a69752ac184360afeb921d157ae08b89c2c091",
# HEAD as of 2026-07-07.
commit = "1a5376e062e3f3b99ffce25e24e53182202e06b9",
patch_cmds = ["echo \"module(name='llvm-raw')\" > MODULE.bazel"],
patch_strip = 1,
patches = [
Expand All @@ -93,6 +93,7 @@ git_override(
"//bazel/llvm_project:0004_Introduce_basic_sources_exporting_for_libunwind.patch",
"//bazel/llvm_project:0005_Introduce_basic_sources_exporting_for_libcxx_and_libcxxabi.patch",
"//bazel/llvm_project:0009_Introduce_starlark_exporting_compiler-rt_build_information.patch",
"//bazel/llvm_project:0010_Exclude_addtf3_cpp_from_compiler_rt_builtins.patch",
],
remote = "https://github.com/llvm/llvm-project.git",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From 1234567890abcdef1234567890abcdef12345678 Mon Sep 17 00:00:00 2001
From: Carbon Toolchain <carbon-toolchain@google.com>
Date: Fri, 10 Jul 2026 23:42:00 +0000
Subject: [PATCH] Exclude libc math C++ builtins from compiler-rt Bazel overlay

In CMake, addtf3.cpp is only compiled when COMPILER_RT_USE_LIBC_MATH is ON,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to cross-reference the upstream issue, or is the convention for the patch file to exactly match the upstream commit description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, the convention is for the patch to match the upstream change; other patches don't mention the upstream PR.

replacing addtf3.c. In the Bazel overlay, builtins_generic_srcs globbed
all lib/builtins/*.cpp without excluding addtf3.cpp, causing compile failures
when not using libc math.
---
utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel b/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel
index ae4a99d6885c..1234567890ab 100644
--- a/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel
@@ -293,6 +293,11 @@ filegroup(
srcs = glob(BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS),
)

+BUILTINS_LIBC_MATH_EXCLUDES = [
+ # Sources requiring COMPILER_RT_USE_LIBC_MATH (e.g. LIBC_NAMESPACE::shared::*).
+ "lib/builtins/addtf3.cpp",
+]
+
# Source files for portable components of the compiler builtins library.
filegroup(
name = "builtins_generic_srcs",
@@ -309,7 +314,8 @@ filegroup(
BUILTINS_TF_EXCLUDES +
BUILTINS_TF_SRCS_PATTERNS +
BUILTINS_ATOMICS_SRCS +
- BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS
+ BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS +
+ BUILTINS_LIBC_MATH_EXCLUDES
),
),
)
--
2.45.2
6 changes: 3 additions & 3 deletions common/check_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace {
// our own type-erased version of `format` here.
auto FormatvInto(
llvm::raw_ostream& out, llvm::StringRef format_str,
llvm::ArrayRef<llvm::support::detail::format_adapter*> adapters) -> void {
llvm::ArrayRef<llvm::support::detail::FormatFunctorRef> adapters) -> void {
for (const llvm::ReplacementItem& replacement :
llvm::formatv_object_base::parseFormatString(format_str, adapters.size(),
/*Validate=*/true)) {
Expand All @@ -33,7 +33,7 @@ auto FormatvInto(
out << replacement.Spec;
continue;
}
llvm::FmtAlign(*adapters[replacement.Index], replacement.Where,
llvm::FmtAlign(adapters[replacement.Index], replacement.Where,
replacement.Width, replacement.Pad)
.format(out, replacement.Options);
}
Expand All @@ -43,7 +43,7 @@ auto FormatvInto(
auto CheckFailImpl(
const char* kind, const char* file, int line, const char* condition_str,
const char* extra_format,
llvm::ArrayRef<llvm::support::detail::format_adapter*> extra_adapters)
llvm::ArrayRef<llvm::support::detail::FormatFunctorRef> extra_adapters)
-> void {
// Render the final check string directly into one stream. The extra message
// is rendered in place from its format string and type-erased adapters, so
Expand Down
28 changes: 8 additions & 20 deletions common/check_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CheckCondition(bool condition)
auto CheckFailImpl(
const char* kind, const char* file, int line, const char* condition_str,
const char* extra_format,
llvm::ArrayRef<llvm::support::detail::format_adapter*> extra_adapters)
llvm::ArrayRef<llvm::support::detail::FormatFunctorRef> extra_adapters)
-> void;

// Allow custom conversion of format values; the default behaviour is to just
Expand All @@ -74,21 +74,10 @@ auto ConvertFormatValue(T&& t) -> auto {
}
}

// Helper to compute a pointer to the base class of a given LLVM
// `format_adapter` object. This both handles converting to the base class and
// allows taking the address of temporaries within arguments to another function
// call.
template <typename T>
auto CheckFailFormatAdapterAddr(T&& adapter)
-> llvm::support::detail::format_adapter* {
return &adapter;
}

// Builds one type-erased format adapter per value -- forwarding each value
// through the conversion machinery. The address of the base classes of each of
// these are then collected into an init list that can be accessed with an
// `ArrayRef`. All of this is then passed to the out-of-line rendering function
// `CheckFailImpl`.
// Builds one type-erased format functor per value -- forwarding each value
// through the conversion machinery. References to each of these functors are
// then collected into an init list that can be accessed with an `ArrayRef`. All
// of this is then passed to the out-of-line rendering function `CheckFailImpl`.
//
// This is templated only on the value types, not on the per-check-site
// metadata (file, line, etc., which are passed as ordinary arguments), so the
Expand All @@ -101,10 +90,9 @@ template <typename... Ts>
auto CheckFailFormat(const char* kind, const char* file, int line,
const char* condition_str, const char* extra_format,
Ts&&... values) -> void {
CheckFailImpl(
kind, file, line, condition_str, extra_format,
{CheckFailFormatAdapterAddr(llvm::support::detail::build_format_adapter(
ConvertFormatValue(std::forward<Ts>(values))))...});
CheckFailImpl(kind, file, line, condition_str, extra_format,
{llvm::support::detail::FormatFunctor(
ConvertFormatValue(std::forward<Ts>(values)))...});
}

// Prints a check failure, including rendering any user-provided message using
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/cpp/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static auto BuildTemplateId(Context& context, SemIR::LocId loc_id,
dyn_cast<clang::VarTemplateDecl>(template_decl)) {
auto decl_result = context.clang_sema().CheckVarTemplateId(
var_template_decl, /*TemplateLoc=*/clang::SourceLocation(), loc,
arg_list, /*SetWrittenArgs=*/false);
arg_list);
return decl_result.isInvalid()
? SemIR::ErrorInst::InstId
: ImportCppDecl(context, loc_id,
Expand Down
7 changes: 5 additions & 2 deletions toolchain/check/cpp/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,11 @@ auto ExportFunctionSpecializationToCpp(
auto* template_arg_list = clang::TemplateArgumentList::CreateCopy(
context.ast_context(), template_args);
function_decl->setFunctionTemplateSpecialization(
function_template_decl, template_arg_list,
/*InsertPos=*/nullptr, clang::TSK_ExplicitSpecialization);
context.ast_context(), function_template_decl, template_arg_list,
/*InsertPos=*/nullptr, clang::TSK_ExplicitSpecialization,
/*TemplateParams=*/nullptr, /*TemplateArgsAsWritten=*/nullptr,
/*PointOfInstantiation=*/clang::SourceLocation(),
/*AddSpecialization=*/true);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ fn Call() -> i32 {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: noinline nounwind optnone
// CHECK:STDOUT: define i32 @_CCall.Main() #2 !dbg !11 {
// CHECK:STDOUT: define i32 @_CCall.Main() #2 !dbg !12 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %g.call = call i32 @_Z1gv(), !dbg !15
// CHECK:STDOUT: ret i32 %g.call, !dbg !16
// CHECK:STDOUT: %g.call = call i32 @_Z1gv(), !dbg !16
// CHECK:STDOUT: ret i32 %g.call, !dbg !17
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
Expand All @@ -69,14 +69,15 @@ fn Call() -> i32 {
// CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !5 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !6 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !7 = !{!8, !8, i64 0}
// CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
// CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
// CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !11 = distinct !DISubprogram(name: "Call", linkageName: "_CCall.Main", scope: null, file: !1, line: 12, type: !12, spFlags: DISPFlagDefinition, unit: !0)
// CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
// CHECK:STDOUT: !13 = !{!14}
// CHECK:STDOUT: !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !15 = !DILocation(line: 13, column: 10, scope: !11)
// CHECK:STDOUT: !16 = !DILocation(line: 13, column: 3, scope: !11)
// CHECK:STDOUT: !7 = !{!8, !9, i64 0}
// CHECK:STDOUT: !8 = !{!"__libc_errno", !9, i64 0}
// CHECK:STDOUT: !9 = !{!"int", !10, i64 0}
// CHECK:STDOUT: !10 = !{!"omnipotent char", !11, i64 0}
// CHECK:STDOUT: !11 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !12 = distinct !DISubprogram(name: "Call", linkageName: "_CCall.Main", scope: null, file: !1, line: 12, type: !13, spFlags: DISPFlagDefinition, unit: !0)
// CHECK:STDOUT: !13 = !DISubroutineType(types: !14)
// CHECK:STDOUT: !14 = !{!15}
// CHECK:STDOUT: !15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !16 = !DILocation(line: 13, column: 10, scope: !12)
// CHECK:STDOUT: !17 = !DILocation(line: 13, column: 3, scope: !12)
// CHECK:STDOUT:
Loading
Loading