push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp
index 34640b3c450d..93c4a4f4ec5c 100644
--- a/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/lib/Driver/ToolChains/CommonArgs.cpp
@@ -589,8 +589,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
#endif
SmallString<1024> Plugin;
- llvm::sys::path::native(Twine(D.Dir) +
- "/../" CLANG_INSTALL_LIBDIR_BASENAME +
+ llvm::sys::path::native(Twine("@libllvmLibdir@") +
PluginName + Suffix,
Plugin);
CmdArgs.push_back(Args.MakeArgString(Twine(PluginPrefix) + Plugin));

View File

@@ -0,0 +1,75 @@
From 7ef5ed98cc6666f64db2f155ded2077ce038e1e4 Mon Sep 17 00:00:00 2001
From: Reno Dakota <paparodeo@proton.me>
Date: Sat, 16 Nov 2024 05:57:40 +0000
Subject: [PATCH] [Clang][Driver] report unsupported option error regardless of
argument order
This change updates clang to report unsupported option errors regardless
of the command line argument order.
When clang with a source file and without `-c` it will both compile and
link. When an unsupported option is also part of the command line clang
should generated an error. However, if the source file name comes before
an object file, eg: `-lc`, the error is ignored.
```
$ clang --target=x86_64 -lc hello.c -mhtm
clang: error: unsupported option '-mhtm' for target 'x86_64'
$ echo $?
1
```
but if `-lc` comes after `hello.c` the error is dropped
```
$ clang --target=x86_64 hello.c -mhtm -lc
$ echo $?
0
```
after this change clang will report the error regardless of the command
line argument order.
---
clang/lib/Driver/Driver.cpp | 13 ++++++-------
clang/test/Driver/unsupported-option.c | 10 ++++++++++
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 93e85f7dffe35a..8e784a7b130ac3 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -4064,17 +4064,18 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
YcArg = YuArg = nullptr;
}
- unsigned LastPLSize = 0;
+ bool LinkOnly = phases::Link == FinalPhase && Inputs.size() > 0;
for (auto &I : Inputs) {
types::ID InputType = I.first;
const Arg *InputArg = I.second;
auto PL = types::getCompilationPhases(InputType);
- LastPLSize = PL.size();
+
+ phases::ID InitialPhase = PL[0];
+ LinkOnly = LinkOnly && phases::Link == InitialPhase && PL.size() == 1;
// If the first step comes after the final phase we are doing as part of
// this compilation, warn the user about it.
- phases::ID InitialPhase = PL[0];
if (InitialPhase > FinalPhase) {
if (InputArg->isClaimed())
continue;
@@ -4129,10 +4130,8 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
}
}
- // If we are linking, claim any options which are obviously only used for
- // compilation.
- // FIXME: Understand why the last Phase List length is used here.
- if (FinalPhase == phases::Link && LastPLSize == 1) {
+ // claim any options which are obviously only used for compilation.
+ if (LinkOnly) {
Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
Args.ClaimAllArgs(options::OPT_cl_compile_Group);
}

View File

@@ -0,0 +1,261 @@
{
lib,
stdenv,
llvm_meta,
src ? null,
monorepoSrc ? null,
runCommand,
cmake,
ninja,
libxml2,
libllvm,
release_version,
version,
python3,
buildLlvmTools,
fixDarwinDylibNames,
enableManpages ? false,
enableClangToolsExtra ? true,
devExtraCmakeFlags ? [ ],
replaceVars,
getVersionFile,
fetchpatch,
# for tests
libclang,
}:
stdenv.mkDerivation (
finalAttrs:
{
pname = "clang";
inherit version;
src =
if monorepoSrc != null then
runCommand "clang-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/clang "$out"
${lib.optionalString enableClangToolsExtra "cp -r ${monorepoSrc}/clang-tools-extra \"$out\""}
''
else
src;
sourceRoot = "${finalAttrs.src.name}/clang";
patches = [
(getVersionFile "clang/purity.patch")
# Remove extraneous ".a" suffix from baremetal clang_rt.builtins when compiling for baremetal.
# https://reviews.llvm.org/D51899
(getVersionFile "clang/gnu-install-dirs.patch")
]
++ lib.optionals (lib.versionOlder release_version "20") [
# https://github.com/llvm/llvm-project/pull/116476
# prevent clang ignoring warnings / errors for unsuppored
# options when building & linking a source file with trailing
# libraries. eg: `clang -munsupported hello.c -lc`
./clang-unsupported-option.patch
]
# Pass the correct path to libllvm
++ [
(replaceVars ./clang-at-least-16-LLVMgold-path.patch {
libllvmLibdir = "${libllvm.lib}/lib";
})
]
# Fixes a bunch of lambda-related crashes
# https://github.com/llvm/llvm-project/pull/93206
++ lib.optional (lib.versions.major release_version == "18") (fetchpatch {
name = "tweak-tryCaptureVariable-for-unevaluated-lambdas.patch";
url = "https://github.com/llvm/llvm-project/commit/3d361b225fe89ce1d8c93639f27d689082bd8dad.patch";
# TreeTransform.h is not affected in LLVM 18.
excludes = [
"docs/ReleaseNotes.rst"
"lib/Sema/TreeTransform.h"
];
stripLen = 1;
hash = "sha256-1NKej08R9SPlbDY/5b0OKUsHjX07i9brR84yXiPwi7E=";
});
nativeBuildInputs = [
cmake
python3
ninja
]
++ lib.optionals enableManpages [
python3.pkgs.myst-parser
python3.pkgs.sphinx
]
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
buildInputs = [
libxml2
libllvm
];
cmakeFlags = [
(lib.cmakeFeature "CLANG_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/clang")
(lib.cmakeBool "CLANGD_BUILD_XPC" false)
(lib.cmakeBool "LLVM_ENABLE_RTTI" true)
(lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
(lib.cmakeFeature "CLANG_TABLEGEN" "${buildLlvmTools.tblgen}/bin/clang-tblgen")
]
++ lib.optionals (lib.versionAtLeast release_version "21") [
(lib.cmakeFeature "CLANG_RESOURCE_DIR" "${placeholder "lib"}/lib/clang/${lib.versions.major release_version}")
]
# TODO: Clean up on `staging`.
++ [
(lib.cmakeBool "LLVM_INCLUDE_TESTS" false)
]
++ lib.optionals enableManpages [
(lib.cmakeBool "CLANG_INCLUDE_DOCS" true)
(lib.cmakeBool "LLVM_ENABLE_SPHINX" true)
(lib.cmakeBool "SPHINX_OUTPUT_MAN" true)
(lib.cmakeBool "SPHINX_OUTPUT_HTML" false)
(lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
]
# TODO: Clean up on `staging`.
++ [
# Added in LLVM15:
# `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb
# `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7
(lib.cmakeFeature "CLANG_TIDY_CONFUSABLE_CHARS_GEN" "${buildLlvmTools.tblgen}/bin/clang-tidy-confusable-chars-gen")
]
++ lib.optionals (lib.versionOlder release_version "20") [
# clang-pseudo removed in LLVM20: https://github.com/llvm/llvm-project/commit/ed8f78827895050442f544edef2933a60d4a7935
(lib.cmakeFeature "CLANG_PSEUDO_GEN" "${buildLlvmTools.tblgen}/bin/clang-pseudo-gen")
]
++ lib.optional (lib.versionAtLeast release_version "20") (
lib.cmakeFeature "LLVM_DIR" "${libllvm.dev}/lib/cmake/llvm"
)
++ devExtraCmakeFlags;
postPatch = ''
# Make sure clang passes the correct location of libLTO to ld64
substituteInPlace lib/Driver/ToolChains/Darwin.cpp \
--replace-fail 'StringRef P = llvm::sys::path::parent_path(D.Dir);' 'StringRef P = "${lib.getLib libllvm}";'
(cd tools && ln -s ../../clang-tools-extra extra)
''
+ lib.optionalString stdenv.hostPlatform.isMusl ''
sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp
'';
outputs = [
"out"
"lib"
"dev"
"python"
];
separateDebugInfo = stdenv.buildPlatform.is64bit; # OOMs on 32 bit
postInstall = ''
ln -sv $out/bin/clang $out/bin/cpp
''
+ (lib.optionalString
((lib.versionAtLeast release_version "19") && !(lib.versionAtLeast release_version "21"))
''
mv $out/lib/clang $lib/lib/clang
''
)
+ ''
# Move libclang to 'lib' output
moveToOutput "lib/libclang.*" "$lib"
moveToOutput "lib/libclang-cpp.*" "$lib"
mkdir -p $python/bin $python/share/clang/
''
+ ''
mv $out/bin/{git-clang-format,scan-view} $python/bin
if [ -e $out/bin/set-xcode-analyzer ]; then
mv $out/bin/set-xcode-analyzer $python/bin
fi
mv $out/share/clang/*.py $python/share/clang
rm $out/bin/c-index-test
patchShebangs $python/bin
mkdir -p $dev/bin
''
# TODO(@LunNova): Clean up this rebuild avoidance in staging
+ lib.optionalString enableClangToolsExtra (
if lib.versionOlder release_version "20" then
''
cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin
''
else
''
cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen} $dev/bin
''
)
+ lib.optionalString (!enableClangToolsExtra) ''
cp bin/clang-tblgen $dev/bin
'';
env =
lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform && !stdenv.hostPlatform.useLLVM)
{
# The following warning is triggered with (at least) gcc >=
# 12, but appears to occur only for cross compiles.
NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized";
};
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlagsByTargetPlatform =
targetPlatform:
[ "fortify3" ]
++ lib.optional (!targetPlatform.isLinux || !targetPlatform.isx86_64) "shadowstack"
++ lib.optional (!targetPlatform.isAarch64 || !targetPlatform.isLinux) "pacret"
++ lib.optional (
!(targetPlatform.isLinux || targetPlatform.isFreeBSD)
|| !(
targetPlatform.isx86
|| targetPlatform.isPower64
|| targetPlatform.isS390x
|| targetPlatform.isAarch64
)
) "stackclashprotection"
++ lib.optional (!(targetPlatform.isx86_64 || targetPlatform.isAarch64)) "zerocallusedregs"
++ (finalAttrs.passthru.hardeningUnsupportedFlags or [ ]);
tests.withoutOptionalFeatures = libclang.override {
enableClangToolsExtra = false;
};
};
requiredSystemFeatures = [ "big-parallel" ];
meta = llvm_meta // {
homepage = "https://clang.llvm.org/";
description = "C language family frontend for LLVM";
longDescription = ''
The Clang project provides a language front-end and tooling
infrastructure for languages in the C language family (C, C++, Objective
C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project.
It aims to deliver amazingly fast compiles, extremely useful error and
warning messages and to provide a platform for building great source
level tools. The Clang Static Analyzer and clang-tidy are tools that
automatically find bugs in your code, and are great examples of the sort
of tools that can be built using the Clang frontend as a library to
parse C/C++ code.
'';
mainProgram = "clang";
};
}
// lib.optionalAttrs enableManpages {
pname = "clang-manpages";
ninjaFlags = [ "docs-clang-man" ];
installPhase = ''
mkdir -p $out/share/man/man1
# Manually install clang manpage
cp docs/man/*.1 $out/share/man/man1/
'';
outputs = [ "out" ];
doCheck = false;
meta = llvm_meta // {
description = "man page for Clang ${version}";
};
}
)