Skip to content

Commit

Permalink
Auto merge of #123918 - DianQK:clang-format, r=Kobzol
Browse files Browse the repository at this point in the history
Use `clang-format` in `tidy` to check the C++ code style under `llvm-wrapper`

Fixes #123510.

Based on the discussion at https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Enable.20.60clang-format.60.20for.20.60rustc.60.20compiler-team.23756/near/443562800, we can use clang-format from pip to achieve the code formatting.

r? `@Kobzol`
  • Loading branch information
bors committed Jun 27, 2024
2 parents 4bc39f0 + c163d5c commit 7033f9b
Show file tree
Hide file tree
Showing 14 changed files with 909 additions and 834 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: LLVM
1 change: 1 addition & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Files: compiler/*
x
x.ps1
x.py
.clang-format
.editorconfig
.git-blame-ignore-revs
.gitattributes
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5627,6 +5627,7 @@ dependencies = [
"regex",
"rustc-hash",
"semver",
"similar",
"termcolor",
"walkdir",
]
Expand Down
33 changes: 14 additions & 19 deletions compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ struct RustArchiveMember {
Archive::Child Child;

RustArchiveMember()
: Filename(nullptr), Name(nullptr),
Child(nullptr, nullptr, nullptr)
{
}
: Filename(nullptr), Name(nullptr), Child(nullptr, nullptr, nullptr) {}
~RustArchiveMember() {}
};

Expand All @@ -27,11 +24,8 @@ struct RustArchiveIterator {
std::unique_ptr<Error> Err;

RustArchiveIterator(Archive::child_iterator Cur, Archive::child_iterator End,
std::unique_ptr<Error> Err)
: First(true),
Cur(Cur),
End(End),
Err(std::move(Err)) {}
std::unique_ptr<Error> Err)
: First(true), Cur(Cur), End(End), Err(std::move(Err)) {}
};

enum class LLVMRustArchiveKind {
Expand Down Expand Up @@ -66,8 +60,8 @@ typedef Archive::Child const *LLVMRustArchiveChildConstRef;
typedef RustArchiveIterator *LLVMRustArchiveIteratorRef;

extern "C" LLVMRustArchiveRef LLVMRustOpenArchive(char *Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOr =
MemoryBuffer::getFile(Path, /*IsText*/false, /*RequiresNullTerminator=*/false);
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOr = MemoryBuffer::getFile(
Path, /*IsText*/ false, /*RequiresNullTerminator=*/false);
if (!BufOr) {
LLVMRustSetLastError(BufOr.getError().message().c_str());
return nullptr;
Expand Down Expand Up @@ -146,8 +140,8 @@ extern "C" const char *
LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef Child, size_t *Size) {
Expected<StringRef> NameOrErr = Child->getName();
if (!NameOrErr) {
// rustc_codegen_llvm currently doesn't use this error string, but it might be
// useful in the future, and in the meantime this tells LLVM that the
// rustc_codegen_llvm currently doesn't use this error string, but it might
// be useful in the future, and in the meantime this tells LLVM that the
// error was not ignored and that it shouldn't abort the process.
LLVMRustSetLastError(toString(NameOrErr.takeError()).c_str());
return nullptr;
Expand All @@ -172,10 +166,9 @@ extern "C" void LLVMRustArchiveMemberFree(LLVMRustArchiveMemberRef Member) {
delete Member;
}

extern "C" LLVMRustResult
LLVMRustWriteArchive(char *Dst, size_t NumMembers,
const LLVMRustArchiveMemberRef *NewMembers,
bool WriteSymbtab, LLVMRustArchiveKind RustKind, bool isEC) {
extern "C" LLVMRustResult LLVMRustWriteArchive(
char *Dst, size_t NumMembers, const LLVMRustArchiveMemberRef *NewMembers,
bool WriteSymbtab, LLVMRustArchiveKind RustKind, bool isEC) {

std::vector<NewArchiveMember> Members;
auto Kind = fromRust(RustKind);
Expand Down Expand Up @@ -206,8 +199,10 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
#if LLVM_VERSION_LT(18, 0)
auto Result = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false);
#else
auto SymtabMode = WriteSymbtab ? SymtabWritingMode::NormalSymtab : SymtabWritingMode::NoSymtab;
auto Result = writeArchive(Dst, Members, SymtabMode, Kind, true, false, nullptr, isEC);
auto SymtabMode = WriteSymbtab ? SymtabWritingMode::NormalSymtab
: SymtabWritingMode::NoSymtab;
auto Result =
writeArchive(Dst, Members, SymtabMode, Kind, true, false, nullptr, isEC);
#endif
if (!Result)
return LLVMRustResult::Success;
Expand Down
18 changes: 5 additions & 13 deletions compiler/rustc_llvm/llvm-wrapper/Linker.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "SuppressLLVMWarnings.h"
#include "llvm/Linker/Linker.h"
#include "SuppressLLVMWarnings.h"

#include "LLVMWrapper.h"

Expand All @@ -9,26 +9,18 @@ struct RustLinker {
Linker L;
LLVMContext &Ctx;

RustLinker(Module &M) :
L(M),
Ctx(M.getContext())
{}
RustLinker(Module &M) : L(M), Ctx(M.getContext()) {}
};

extern "C" RustLinker*
LLVMRustLinkerNew(LLVMModuleRef DstRef) {
extern "C" RustLinker *LLVMRustLinkerNew(LLVMModuleRef DstRef) {
Module *Dst = unwrap(DstRef);

return new RustLinker(*Dst);
}

extern "C" void
LLVMRustLinkerFree(RustLinker *L) {
delete L;
}
extern "C" void LLVMRustLinkerFree(RustLinker *L) { delete L; }

extern "C" bool
LLVMRustLinkerAdd(RustLinker *L, char *BC, size_t Len) {
extern "C" bool LLVMRustLinkerAdd(RustLinker *L, char *BC, size_t Len) {
std::unique_ptr<MemoryBuffer> Buf =
MemoryBuffer::getMemBufferCopy(StringRef(BC, Len));

Expand Down
Loading

0 comments on commit 7033f9b

Please sign in to comment.