Skip to content

Commit 88462e1

Browse files
committed
merge main into amd-staging
Revert for now, work it later 6d01a350ce9 [lldb] Encode operands and arity in Dwarf.def and use them in LLDB. (llvm#94679) Change-Id: I6fb991b11e7afd53e66090c3ba2c487e509786e7
2 parents 98c94da + cac7821 commit 88462e1

File tree

131 files changed

+2550
-1407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+2550
-1407
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import json
2+
import multiprocessing
3+
import os
4+
import re
5+
import subprocess
6+
import sys
7+
8+
9+
def run_analyzer(data):
10+
os.chdir(data["directory"])
11+
command = (
12+
data["command"]
13+
+ f" --analyze --analyzer-output html -o analyzer-results -Xclang -analyzer-config -Xclang max-nodes=75000"
14+
)
15+
print(command)
16+
subprocess.run(command, shell=True, check=True)
17+
18+
19+
def pool_error(e):
20+
print("Error analyzing file:", e)
21+
22+
23+
def main():
24+
db_path = sys.argv[1]
25+
database = json.load(open(db_path))
26+
27+
with multiprocessing.Pool() as pool:
28+
pool.map_async(run_analyzer, [k for k in database], error_callback=pool_error)
29+
pool.close()
30+
pool.join()
31+
32+
33+
if __name__ == "__main__":
34+
main()
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Post-Commit Static Analyzer
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- 'release/**'
10+
paths:
11+
- 'clang/**'
12+
- 'llvm/**'
13+
- '.github/workflows/ci-post-commit-analyzer.yml'
14+
pull_request:
15+
types:
16+
- opened
17+
- synchronize
18+
- reopened
19+
- closed
20+
paths:
21+
- '.github/workflows/ci-post-commit-analyzer.yml'
22+
- '.github/workflows/ci-post-commit-analyzer-run.py'
23+
schedule:
24+
- cron: '30 0 * * *'
25+
26+
concurrency:
27+
group: >-
28+
llvm-project-${{ github.workflow }}-${{ github.event_name == 'pull_request' &&
29+
( github.event.pull_request.number || github.ref) }}
30+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
31+
32+
jobs:
33+
post-commit-analyzer:
34+
if: >-
35+
github.repository_owner == 'llvm' &&
36+
github.event.action != 'closed'
37+
runs-on: ubuntu-22.04
38+
container:
39+
image: 'ghcr.io/llvm/ci-ubuntu-22.04:latest'
40+
env:
41+
LLVM_VERSION: 18
42+
steps:
43+
- name: Checkout Source
44+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
45+
46+
- name: Setup ccache
47+
uses: hendrikmuhs/ccache-action@v1
48+
with:
49+
# A full build of llvm, clang, lld, and lldb takes about 250MB
50+
# of ccache space. There's not much reason to have more than this,
51+
# because we usually won't need to save cache entries from older
52+
# builds. Also, there is an overall 10GB cache limit, and each
53+
# run creates a new cache entry so we want to ensure that we have
54+
# enough cache space for all the tests to run at once and still
55+
# fit under the 10 GB limit.
56+
# Default to 2G to workaround: https://github.com/hendrikmuhs/ccache-action/issues/174
57+
max-size: 2G
58+
key: post-commit-analyzer
59+
variant: sccache
60+
61+
- name: Configure
62+
run: |
63+
cmake -B build -S llvm -G Ninja \
64+
-DLLVM_ENABLE_ASSERTIONS=ON \
65+
-DLLVM_ENABLE_PROJECTS=clang \
66+
-DLLVM_BUILD_LLVM_DYLIB=ON \
67+
-DLLVM_LINK_LLVM_DYLIB=ON \
68+
-DCMAKE_CXX_COMPILER=clang++ \
69+
-DCMAKE_C_COMPILER=clang \
70+
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
71+
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
72+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
73+
-DLLVM_INCLUDE_TESTS=OFF \
74+
-DCLANG_INCLUDE_TESTS=OFF \
75+
-DCMAKE_BUILD_TYPE=Release
76+
77+
- name: Build
78+
run: |
79+
# FIXME: We need to build all the generated header files in order to be able to run
80+
# the analyzer on every file. Building libLLVM and libclang is probably overkill for
81+
# this, but it's better than building every target.
82+
ninja -v -C build libLLVM.so libclang.so
83+
84+
# Run the analyzer.
85+
python3 .github/workflows/ci-post-commit-analyzer-run.py build/compile_commands.json
86+
87+
scan-build --generate-index-only build/analyzer-results
88+
89+
- name: Upload Results
90+
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
91+
if: always()
92+
with:
93+
name: analyzer-results
94+
path: 'build/analyzer-results/*'
95+

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class BinaryEmitter {
194194

195195
void BinaryEmitter::emitAll(StringRef OrgSecPrefix) {
196196
Streamer.initSections(false, *BC.STI);
197+
Streamer.setUseAssemblerInfoForParsing(false);
197198

198199
if (opts::UpdateDebugSections && BC.isELF()) {
199200
// Force the emission of debug line info into allocatable section to ensure
@@ -226,6 +227,7 @@ void BinaryEmitter::emitAll(StringRef OrgSecPrefix) {
226227
// TODO Enable for Mach-O once BinaryContext::getDataSection supports it.
227228
if (BC.isELF())
228229
AddressMap::emit(Streamer, BC);
230+
Streamer.setUseAssemblerInfoForParsing(true);
229231
}
230232

231233
void BinaryEmitter::emitFunctions() {

clang-tools-extra/clang-tidy/misc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ add_clang_library(clangTidyMiscModule
4141
UnusedParametersCheck.cpp
4242
UnusedUsingDeclsCheck.cpp
4343
UseAnonymousNamespaceCheck.cpp
44+
UseInternalLinkageCheck.cpp
4445

4546
LINK_LIBS
4647
clangTidy

clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "UnusedParametersCheck.h"
3232
#include "UnusedUsingDeclsCheck.h"
3333
#include "UseAnonymousNamespaceCheck.h"
34+
#include "UseInternalLinkageCheck.h"
3435

3536
namespace clang::tidy {
3637
namespace misc {
@@ -78,6 +79,8 @@ class MiscModule : public ClangTidyModule {
7879
"misc-unused-using-decls");
7980
CheckFactories.registerCheck<UseAnonymousNamespaceCheck>(
8081
"misc-use-anonymous-namespace");
82+
CheckFactories.registerCheck<UseInternalLinkageCheck>(
83+
"misc-use-internal-linkage");
8184
}
8285
};
8386

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//===--- UseInternalLinkageCheck.cpp - clang-tidy--------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "UseInternalLinkageCheck.h"
10+
#include "../utils/FileExtensionsUtils.h"
11+
#include "clang/AST/Decl.h"
12+
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
14+
#include "clang/ASTMatchers/ASTMatchersMacros.h"
15+
#include "clang/Basic/SourceLocation.h"
16+
#include "clang/Basic/Specifiers.h"
17+
#include "llvm/ADT/STLExtras.h"
18+
19+
using namespace clang::ast_matchers;
20+
21+
namespace clang::tidy::misc {
22+
23+
namespace {
24+
25+
AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
26+
27+
static bool isInMainFile(SourceLocation L, SourceManager &SM,
28+
const FileExtensionsSet &HeaderFileExtensions) {
29+
for (;;) {
30+
if (utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions))
31+
return false;
32+
if (SM.isInMainFile(L))
33+
return true;
34+
// not in header file but not in main file
35+
L = SM.getIncludeLoc(SM.getFileID(L));
36+
if (L.isValid())
37+
continue;
38+
// Conservative about the unknown
39+
return false;
40+
}
41+
}
42+
43+
AST_MATCHER_P(Decl, isAllRedeclsInMainFile, FileExtensionsSet,
44+
HeaderFileExtensions) {
45+
return llvm::all_of(Node.redecls(), [&](const Decl *D) {
46+
return isInMainFile(D->getLocation(),
47+
Finder->getASTContext().getSourceManager(),
48+
HeaderFileExtensions);
49+
});
50+
}
51+
52+
AST_POLYMORPHIC_MATCHER(isExternStorageClass,
53+
AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
54+
VarDecl)) {
55+
return Node.getStorageClass() == SC_Extern;
56+
}
57+
58+
} // namespace
59+
60+
void UseInternalLinkageCheck::registerMatchers(MatchFinder *Finder) {
61+
auto Common =
62+
allOf(isFirstDecl(), isAllRedeclsInMainFile(HeaderFileExtensions),
63+
unless(anyOf(
64+
// 1. internal linkage
65+
isStaticStorageClass(), isInAnonymousNamespace(),
66+
// 2. explicit external linkage
67+
isExternStorageClass(), isExternC(),
68+
// 3. template
69+
isExplicitTemplateSpecialization(),
70+
// 4. friend
71+
hasAncestor(friendDecl()))));
72+
Finder->addMatcher(
73+
functionDecl(Common, unless(cxxMethodDecl()), unless(isMain()))
74+
.bind("fn"),
75+
this);
76+
Finder->addMatcher(varDecl(Common, hasGlobalStorage()).bind("var"), this);
77+
}
78+
79+
static constexpr StringRef Message =
80+
"%0 %1 can be made static or moved into an anonymous namespace "
81+
"to enforce internal linkage";
82+
83+
void UseInternalLinkageCheck::check(const MatchFinder::MatchResult &Result) {
84+
if (const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("fn")) {
85+
diag(FD->getLocation(), Message) << "function" << FD;
86+
return;
87+
}
88+
if (const auto *VD = Result.Nodes.getNodeAs<VarDecl>("var")) {
89+
diag(VD->getLocation(), Message) << "variable" << VD;
90+
return;
91+
}
92+
llvm_unreachable("");
93+
}
94+
95+
} // namespace clang::tidy::misc
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===--- UseInternalLinkageCheck.h - clang-tidy -----------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_USEINTERNALLINKAGECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_USEINTERNALLINKAGECHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::misc {
15+
16+
/// Detects variables and functions that can be marked as static or moved into
17+
/// an anonymous namespace to enforce internal linkage.
18+
///
19+
/// For the user-facing documentation see:
20+
/// http://clang.llvm.org/extra/clang-tidy/checks/misc/use-internal-linkage.html
21+
class UseInternalLinkageCheck : public ClangTidyCheck {
22+
public:
23+
UseInternalLinkageCheck(StringRef Name, ClangTidyContext *Context)
24+
: ClangTidyCheck(Name, Context),
25+
HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
26+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
27+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
28+
std::optional<TraversalKind> getCheckTraversalKind() const override {
29+
return TK_IgnoreUnlessSpelledInSource;
30+
}
31+
32+
private:
33+
FileExtensionsSet HeaderFileExtensions;
34+
};
35+
36+
} // namespace clang::tidy::misc
37+
38+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_USEINTERNALLINKAGECHECK_H

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ New checks
148148
to reading out-of-bounds data due to inadequate or incorrect string null
149149
termination.
150150

151+
- New :doc:`misc-use-internal-linkage
152+
<clang-tidy/checks/misc/use-internal-linkage>` check.
153+
154+
Detects variables and functions that can be marked as static or moved into
155+
an anonymous namespace to enforce internal linkage.
156+
151157
- New :doc:`modernize-min-max-use-initializer-list
152158
<clang-tidy/checks/modernize/min-max-use-initializer-list>` check.
153159

clang-tools-extra/docs/clang-tidy/checks/list.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ Clang-Tidy Checks
267267
:doc:`misc-unused-parameters <misc/unused-parameters>`, "Yes"
268268
:doc:`misc-unused-using-decls <misc/unused-using-decls>`, "Yes"
269269
:doc:`misc-use-anonymous-namespace <misc/use-anonymous-namespace>`,
270+
:doc:`misc-use-internal-linkage <misc/use-internal-linkage>`,
270271
:doc:`modernize-avoid-bind <modernize/avoid-bind>`, "Yes"
271272
:doc:`modernize-avoid-c-arrays <modernize/avoid-c-arrays>`,
272273
:doc:`modernize-concat-nested-namespaces <modernize/concat-nested-namespaces>`, "Yes"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. title:: clang-tidy - misc-use-internal-linkage
2+
3+
misc-use-internal-linkage
4+
=========================
5+
6+
Detects variables and functions that can be marked as static or moved into
7+
an anonymous namespace to enforce internal linkage.
8+
9+
Static functions and variables are scoped to a single file. Marking functions
10+
and variables as static helps to better remove dead code. In addition, it gives
11+
the compiler more information and allows for more aggressive optimizations.
12+
13+
Example:
14+
15+
.. code-block:: c++
16+
17+
int v1; // can be marked as static
18+
19+
void fn1(); // can be marked as static
20+
21+
namespace {
22+
// already in anonymous namespace
23+
int v2;
24+
void fn2();
25+
}
26+
// already declared as extern
27+
extern int v2;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
void func_header();
4+
5+
#include "func_h.inc"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void func_cpp_inc();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void func_h_inc();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
extern int gloabl_header;

0 commit comments

Comments
 (0)