Skip to content

Commit aad70c1

Browse files
author
z1.cciauto
committed
merge main into amd-staging
2 parents e638133 + 163935a commit aad70c1

File tree

123 files changed

+3237
-1529
lines changed

Some content is hidden

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

123 files changed

+3237
-1529
lines changed

.github/workflows/release-binaries.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
prepare:
5050
name: Prepare to build binaries
5151
runs-on: ${{ inputs.runs-on }}
52-
if: github.repository == 'llvm/llvm-project'
52+
if: github.repository_owner == 'llvm'
5353
outputs:
5454
release-version: ${{ steps.vars.outputs.release-version }}
5555
ref: ${{ steps.vars.outputs.ref }}
@@ -177,7 +177,7 @@ jobs:
177177
build-release-package:
178178
name: "Build Release Package"
179179
needs: prepare
180-
if: github.repository == 'llvm/llvm-project'
180+
if: github.repository_owner == 'llvm'
181181
runs-on: ${{ needs.prepare.outputs.build-runs-on }}
182182
steps:
183183

@@ -327,7 +327,7 @@ jobs:
327327
- prepare
328328
- build-release-package
329329
if: >-
330-
github.repository == 'llvm/llvm-project'
330+
github.repository_owner == 'llvm'
331331
runs-on: ${{ needs.prepare.outputs.test-runs-on }}
332332
steps:
333333
- name: Checkout Actions

clang/docs/BoundsSafety.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,4 +996,11 @@ and the soundness of the type system. This may incur significant code size
996996
overhead in unoptimized builds and leaving some of the adoption mistakes to be
997997
caught only at run time. This is not a fundamental limitation, however, because
998998
incrementally adding necessary static analysis will allow us to catch issues
999-
early on and remove unnecessary bounds checks in unoptimized builds.
999+
early on and remove unnecessary bounds checks in unoptimized builds.
1000+
1001+
Try it out
1002+
==========
1003+
1004+
Your feedback on the programming model is valuable. You may want to follow the
1005+
instruction in :doc:`BoundsSafetyAdoptionGuide` to play with ``-fbounds-safety``
1006+
and please send your feedback to `Yeoul Na <mailto:[email protected]>`_.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
======================================
2+
Adoption Guide for ``-fbounds-safety``
3+
======================================
4+
5+
.. contents::
6+
:local:
7+
8+
Where to get ``-fbounds-safety``
9+
================================
10+
11+
The open sourcing to llvm.org's ``llvm-project`` is still on going and the
12+
feature is not available yet. In the mean time, the preview implementation is
13+
available
14+
`here <https://github.com/swiftlang/llvm-project/tree/stable/20240723>`_ in a
15+
fork of ``llvm-project``. Please follow
16+
`Building LLVM with CMake <https://llvm.org/docs/CMake.html>`_ to build the
17+
compiler.
18+
19+
Feature flag
20+
============
21+
22+
Pass ``-fbounds-safety`` as a Clang compilation flag for the C file that you
23+
want to adopt. We recommend adopting the model file by file, because adoption
24+
requires some effort to add bounds annotations and fix compiler diagnostics.
25+
26+
Include ``ptrcheck.h``
27+
======================
28+
29+
``ptrcheck.h`` is a Clang toolchain header to provide definition of the bounds
30+
annotations such as ``__counted_by``, ``__counted_by_or_null``, ``__sized_by``,
31+
etc. In the LLVM source tree, the header is located in
32+
``llvm-project/clang/lib/Headers/ptrcheck.h``.
33+
34+
35+
Add bounds annotations on pointers as necessary
36+
===============================================
37+
38+
Annotate pointers on struct fields and function parameters if they are pointing
39+
to an array of object, with appropriate bounds annotations. Please see
40+
:doc:`BoundsSafety` to learn what kind of bounds annotations are available and
41+
their semantics. Note that local pointer variables typically don't need bounds
42+
annotations because they are implicitely a wide pointer (``__bidi_indexable``)
43+
that automatically carries the bounds information.
44+
45+
Address compiler diagnostics
46+
============================
47+
48+
Once you pass ``-fbounds-safety`` to compiler a C file, you will see some new
49+
compiler warnings and errors, which guide adoption of ``-fbounds-safety``.
50+
Consider the following example:
51+
52+
.. code-block:: c
53+
54+
#include <ptrcheck.h>
55+
56+
void init_buf(int *p, int n) {
57+
for (int i = 0; i < n; ++i)
58+
p[i] = 0; // error: array subscript on single pointer 'p' must use a constant index of 0 to be in bounds
59+
}
60+
61+
The parameter ``int *p`` doesn't have a bounds annotation, so the compiler will
62+
complain about the code indexing into it (``p[i]``) as it assumes that ``p`` is
63+
pointing to a single ``int`` object or null. To address the diagnostics, you
64+
should add a bounds annotation on ``int *p`` so that the compiler can reason
65+
about the safety of the array subscript. In the following example, ``p`` is now
66+
``int *__counted_by(n)``, so the compiler will allow the array subscript with
67+
additional run-time checks as necessary.
68+
69+
.. code-block:: c
70+
71+
#include <ptrcheck.h>
72+
73+
void init_buf(int *__counted_by(n) p, int n) {
74+
for (int i = 0; i < n; ++i)
75+
p[i] = 0; // ok; `p` is now has a type with bounds annotation.
76+
}
77+
78+
Run test suites to fix new run-time traps
79+
=========================================
80+
81+
Adopting ``-fbounds-safety`` may cause your program to trap if it violates
82+
bounds safety or it has incorrect adoption. Thus, it is necessary to perform
83+
run-time testing of your program to gain confidence that it won't trap at
84+
run time.
85+
86+
Repeat the process for each remaining file
87+
==========================================
88+
89+
Once you've done with adopting a single C file, please repeat the same process
90+
for each remaining C file that you want to adopt.

clang/docs/ReleaseNotes.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ Resolutions to C++ Defect Reports
371371
- Clang now allows trailing requires clause on explicit deduction guides.
372372
(`CWG2707: Deduction guides cannot have a trailing requires-clause <https://cplusplus.github.io/CWG/issues/2707.html>`_).
373373

374+
- Respect constructor constraints during CTAD.
375+
(`CWG2628: Implicit deduction guides should propagate constraints <https://cplusplus.github.io/CWG/issues/2628.html>`_).
376+
374377
- Clang now diagnoses a space in the first production of a ``literal-operator-id``
375378
by default.
376379
(`CWG2521: User-defined literals and reserved identifiers <https://cplusplus.github.io/CWG/issues/2521.html>`_).
@@ -1166,6 +1169,20 @@ Windows Support
11661169
LoongArch Support
11671170
^^^^^^^^^^^^^^^^^
11681171

1172+
- Types of parameters and return value of ``__builtin_lsx_vorn_v`` and ``__builtin_lasx_xvorn_v``
1173+
are changed from ``signed char`` to ``unsigned char``. (#GH114514)
1174+
1175+
- ``-mrelax`` and ``-mno-relax`` are supported now on LoongArch that can be used
1176+
to enable / disable the linker relaxation optimization. (#GH123587)
1177+
1178+
- Fine-grained la64v1.1 options are added including ``-m{no-,}frecipe``, ``-m{no-,}lam-bh``,
1179+
``-m{no-,}ld-seq-sa``, ``-m{no-,}div32``, ``-m{no-,}lamcas`` and ``-m{no-,}scq``.
1180+
1181+
- Two options ``-m{no-,}annotate-tablejump`` are added to enable / disable
1182+
annotating table jump instruction to correlate it with the jump table. (#GH102411)
1183+
1184+
- FreeBSD support is added for LoongArch64 and has been tested by building kernel-toolchain. (#GH119191)
1185+
11691186
RISC-V Support
11701187
^^^^^^^^^^^^^^
11711188

clang/docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Using Clang as a Compiler
4040
SanitizerStats
4141
SanitizerSpecialCaseList
4242
BoundsSafety
43+
BoundsSafetyAdoptionGuide
4344
BoundsSafetyImplPlans
4445
ControlFlowIntegrity
4546
LTOVisibility

clang/include/clang/AST/UnresolvedSet.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ class UnresolvedSetImpl {
7171
UnresolvedSetImpl(const UnresolvedSetImpl &) = default;
7272
UnresolvedSetImpl &operator=(const UnresolvedSetImpl &) = default;
7373

74-
// FIXME: Switch these to "= default" once MSVC supports generating move ops
75-
UnresolvedSetImpl(UnresolvedSetImpl &&) {}
76-
UnresolvedSetImpl &operator=(UnresolvedSetImpl &&) { return *this; }
74+
UnresolvedSetImpl(UnresolvedSetImpl &&) = default;
75+
UnresolvedSetImpl &operator=(UnresolvedSetImpl &&) = default;
7776

7877
public:
7978
// We don't currently support assignment through this iterator, so we might

clang/include/clang/Basic/BuiltinsSPIRV.td

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,3 @@ def SPIRVLength : Builtin {
1919
let Attributes = [NoThrow, Const];
2020
let Prototype = "void(...)";
2121
}
22-
23-
def SPIRVReflect : Builtin {
24-
let Spellings = ["__builtin_spirv_reflect"];
25-
let Attributes = [NoThrow, Const];
26-
let Prototype = "void(...)";
27-
}

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,9 @@ def err_drv_loongarch_invalid_simd_option_combination : Error<
822822
def err_drv_loongarch_invalid_msimd_EQ : Error<
823823
"invalid argument '%0' to -msimd=; must be one of: none, lsx, lasx">;
824824

825+
def err_drv_loongarch_unsupported_with_linker_relaxation : Error<
826+
"%0 is unsupported with LoongArch linker relaxation (-mrelax)">;
827+
825828
def err_drv_expand_response_file : Error<
826829
"failed to expand response file: %0">;
827830

clang/include/clang/CodeGen/BackendUtil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ enum BackendAction {
3939
Backend_EmitObj ///< Emit native object files
4040
};
4141

42-
void emitBackendOutput(CompilerInstance &CI, StringRef TDesc, llvm::Module *M,
43-
BackendAction Action,
42+
void emitBackendOutput(CompilerInstance &CI, CodeGenOptions &CGOpts,
43+
StringRef TDesc, llvm::Module *M, BackendAction Action,
4444
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
4545
std::unique_ptr<raw_pwrite_stream> OS,
4646
BackendConsumer *BC = nullptr);

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5602,6 +5602,10 @@ def mdiv32 : Flag<["-"], "mdiv32">, Group<m_loongarch_Features_Group>,
56025602
HelpText<"Use div.w[u] and mod.w[u] instructions with input not sign-extended.">;
56035603
def mno_div32 : Flag<["-"], "mno-div32">, Group<m_loongarch_Features_Group>,
56045604
HelpText<"Do not use div.w[u] and mod.w[u] instructions with input not sign-extended.">;
5605+
def mscq : Flag<["-"], "mscq">, Group<m_loongarch_Features_Group>,
5606+
HelpText<"Enable sc.q instruction.">;
5607+
def mno_scq : Flag<["-"], "mno-scq">, Group<m_loongarch_Features_Group>,
5608+
HelpText<"Disable sc.q instruction.">;
56055609
def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, Group<m_loongarch_Features_Group>,
56065610
HelpText<"Enable annotate table jump instruction to correlate it with the jump table.">;
56075611
def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, Group<m_loongarch_Features_Group>,

clang/lib/Basic/Targets/LoongArch.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,
206206
// arch feature set will be used to include all sub-features belonging to
207207
// the V1.1 ISA version.
208208
if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLAMCAS &&
209-
HasFeatureLD_SEQ_SA && HasFeatureDiv32)
209+
HasFeatureLD_SEQ_SA && HasFeatureDiv32 && HasFeatureSCQ)
210210
Builder.defineMacro("__loongarch_arch",
211211
Twine('"') + "la64v1.1" + Twine('"'));
212212
else
@@ -249,6 +249,9 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,
249249
if (HasFeatureDiv32)
250250
Builder.defineMacro("__loongarch_div32", Twine(1));
251251

252+
if (HasFeatureSCQ)
253+
Builder.defineMacro("__loongarch_scq", Twine(1));
254+
252255
StringRef ABI = getABI();
253256
if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
254257
Builder.defineMacro("__loongarch_lp64");
@@ -333,6 +336,8 @@ bool LoongArchTargetInfo::handleTargetFeatures(
333336
HasFeatureLD_SEQ_SA = true;
334337
else if (Feature == "+div32")
335338
HasFeatureDiv32 = true;
339+
else if (Feature == "+scq")
340+
HasFeatureSCQ = true;
336341
}
337342
return true;
338343
}

clang/lib/Basic/Targets/LoongArch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
3434
bool HasFeatureLAMCAS;
3535
bool HasFeatureLD_SEQ_SA;
3636
bool HasFeatureDiv32;
37+
bool HasFeatureSCQ;
3738

3839
public:
3940
LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
@@ -47,6 +48,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
4748
HasFeatureLAMCAS = false;
4849
HasFeatureLD_SEQ_SA = false;
4950
HasFeatureDiv32 = false;
51+
HasFeatureSCQ = false;
5052
LongDoubleWidth = 128;
5153
LongDoubleAlign = 128;
5254
LongDoubleFormat = &llvm::APFloat::IEEEquad();

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ class EmitAssemblyHelper {
206206
}
207207

208208
public:
209-
EmitAssemblyHelper(CompilerInstance &CI, llvm::Module *M,
209+
EmitAssemblyHelper(CompilerInstance &CI, CodeGenOptions &CGOpts,
210+
llvm::Module *M,
210211
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
211-
: CI(CI), Diags(CI.getDiagnostics()), CodeGenOpts(CI.getCodeGenOpts()),
212+
: CI(CI), Diags(CI.getDiagnostics()), CodeGenOpts(CGOpts),
212213
TargetOpts(CI.getTargetOpts()), LangOpts(CI.getLangOpts()),
213214
TheModule(M), VFS(std::move(VFS)),
214215
TargetTriple(TheModule->getTargetTriple()) {}
@@ -1364,14 +1365,14 @@ runThinLTOBackend(CompilerInstance &CI, ModuleSummaryIndex *CombinedIndex,
13641365
}
13651366
}
13661367

1367-
void clang::emitBackendOutput(CompilerInstance &CI, StringRef TDesc,
1368-
llvm::Module *M, BackendAction Action,
1368+
void clang::emitBackendOutput(CompilerInstance &CI, CodeGenOptions &CGOpts,
1369+
StringRef TDesc, llvm::Module *M,
1370+
BackendAction Action,
13691371
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
13701372
std::unique_ptr<raw_pwrite_stream> OS,
13711373
BackendConsumer *BC) {
13721374
llvm::TimeTraceScope TimeScope("Backend");
13731375
DiagnosticsEngine &Diags = CI.getDiagnostics();
1374-
const auto &CGOpts = CI.getCodeGenOpts();
13751376

13761377
std::unique_ptr<llvm::Module> EmptyModule;
13771378
if (!CGOpts.ThinLTOIndexFile.empty()) {
@@ -1411,7 +1412,7 @@ void clang::emitBackendOutput(CompilerInstance &CI, StringRef TDesc,
14111412
}
14121413
}
14131414

1414-
EmitAssemblyHelper AsmHelper(CI, M, VFS);
1415+
EmitAssemblyHelper AsmHelper(CI, CGOpts, M, VFS);
14151416
AsmHelper.emitAssembly(Action, std::move(OS), BC);
14161417

14171418
// Verify clang's TargetInfo DataLayout against the LLVM TargetMachine's

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20430,19 +20430,6 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned BuiltinID,
2043020430
/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_length,
2043120431
ArrayRef<Value *>{X}, nullptr, "spv.length");
2043220432
}
20433-
case SPIRV::BI__builtin_spirv_reflect: {
20434-
Value *I = EmitScalarExpr(E->getArg(0));
20435-
Value *N = EmitScalarExpr(E->getArg(1));
20436-
assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
20437-
E->getArg(1)->getType()->hasFloatingRepresentation() &&
20438-
"Reflect operands must have a float representation");
20439-
assert(E->getArg(0)->getType()->isVectorType() &&
20440-
E->getArg(1)->getType()->isVectorType() &&
20441-
"Reflect operands must be a vector");
20442-
return Builder.CreateIntrinsic(
20443-
/*ReturnType=*/I->getType(), Intrinsic::spv_reflect,
20444-
ArrayRef<Value *>{I, N}, nullptr, "spv.reflect");
20445-
}
2044620433
}
2044720434
return nullptr;
2044820435
}

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ void BackendConsumer::HandleTranslationUnit(ASTContext &C) {
313313

314314
EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
315315

316-
emitBackendOutput(CI, C.getTargetInfo().getDataLayoutString(), getModule(),
316+
emitBackendOutput(CI, CI.getCodeGenOpts(),
317+
C.getTargetInfo().getDataLayoutString(), getModule(),
317318
Action, FS, std::move(AsmOutStream), this);
318319

319320
Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
@@ -1245,8 +1246,9 @@ void CodeGenAction::ExecuteAction() {
12451246
std::unique_ptr<llvm::ToolOutputFile> OptRecordFile =
12461247
std::move(*OptRecordFileOrErr);
12471248

1248-
emitBackendOutput(CI, CI.getTarget().getDataLayoutString(), TheModule.get(),
1249-
BA, CI.getFileManager().getVirtualFileSystemPtr(),
1249+
emitBackendOutput(CI, CI.getCodeGenOpts(),
1250+
CI.getTarget().getDataLayoutString(), TheModule.get(), BA,
1251+
CI.getFileManager().getVirtualFileSystemPtr(),
12501252
std::move(OS));
12511253
if (OptRecordFile)
12521254
OptRecordFile->keep();

clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,16 @@ class PCHContainerGenerator : public ASTConsumer {
322322
// Print the IR for the PCH container to the debug output.
323323
llvm::SmallString<0> Buffer;
324324
clang::emitBackendOutput(
325-
CI, Ctx.getTargetInfo().getDataLayoutString(), M.get(),
325+
CI, CodeGenOpts, Ctx.getTargetInfo().getDataLayoutString(), M.get(),
326326
BackendAction::Backend_EmitLL, FS,
327327
std::make_unique<llvm::raw_svector_ostream>(Buffer));
328328
llvm::dbgs() << Buffer;
329329
});
330330

331331
// Use the LLVM backend to emit the pch container.
332-
clang::emitBackendOutput(CI, Ctx.getTargetInfo().getDataLayoutString(),
333-
M.get(), BackendAction::Backend_EmitObj, FS,
334-
std::move(OS));
332+
clang::emitBackendOutput(CI, CodeGenOpts,
333+
Ctx.getTargetInfo().getDataLayoutString(), M.get(),
334+
BackendAction::Backend_EmitObj, FS, std::move(OS));
335335

336336
// Free the memory for the temporary buffer.
337337
llvm::SmallVector<char, 0> Empty;

0 commit comments

Comments
 (0)