Skip to content

Commit 7d3afaf

Browse files
committed
merge main into amd-staging
Change-Id: I9d96c76f23785eb0333d336278811f6e41072960
2 parents 53fcb94 + 6b149f7 commit 7d3afaf

File tree

290 files changed

+7535
-3060
lines changed

Some content is hidden

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

290 files changed

+7535
-3060
lines changed

bolt/lib/Rewrite/LinuxKernelRewriter.cpp

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ class LinuxKernelRewriter final : public MetadataRewriter {
212212
/// Size of bug_entry struct.
213213
static constexpr size_t BUG_TABLE_ENTRY_SIZE = 12;
214214

215+
/// List of bug entries per function.
216+
using FunctionBugListType =
217+
DenseMap<BinaryFunction *, SmallVector<uint32_t, 2>>;
218+
FunctionBugListType FunctionBugList;
219+
215220
/// .pci_fixup section.
216221
ErrorOr<BinarySection &> PCIFixupSection = std::errc::bad_address;
217222
static constexpr size_t PCI_FIXUP_ENTRY_SIZE = 16;
@@ -254,7 +259,9 @@ class LinuxKernelRewriter final : public MetadataRewriter {
254259
Error readParaInstructions();
255260
Error rewriteParaInstructions();
256261

262+
/// __bug_table section handling.
257263
Error readBugTable();
264+
Error rewriteBugTable();
258265

259266
/// Do no process functions containing instruction annotated with
260267
/// \p Annotation.
@@ -339,6 +346,9 @@ class LinuxKernelRewriter final : public MetadataRewriter {
339346
if (Error E = rewriteStaticKeysJumpTable())
340347
return E;
341348

349+
if (Error E = rewriteBugTable())
350+
return E;
351+
342352
return Error::success();
343353
}
344354

@@ -1164,15 +1174,17 @@ Error LinuxKernelRewriter::rewriteParaInstructions() {
11641174
}
11651175

11661176
/// Process __bug_table section.
1167-
/// This section contains information useful for kernel debugging.
1177+
/// This section contains information useful for kernel debugging, mostly
1178+
/// utilized by WARN()/WARN_ON() macros and deprecated BUG()/BUG_ON().
1179+
///
11681180
/// Each entry in the section is a struct bug_entry that contains a pointer to
11691181
/// the ud2 instruction corresponding to the bug, corresponding file name (both
11701182
/// pointers use PC relative offset addressing), line number, and flags.
11711183
/// The definition of the struct bug_entry can be found in
1172-
/// `include/asm-generic/bug.h`
1173-
///
1174-
/// NB: find_bug() uses linear search to match an address to an entry in the bug
1175-
/// table. Hence there is no need to sort entries when rewriting the table.
1184+
/// `include/asm-generic/bug.h`. The first entry in the struct is an instruction
1185+
/// address encoded as a PC-relative offset. In theory, it could be an absolute
1186+
/// address if CONFIG_GENERIC_BUG_RELATIVE_POINTERS is not set, but in practice
1187+
/// the kernel code relies on it being a relative offset on x86-64.
11761188
Error LinuxKernelRewriter::readBugTable() {
11771189
BugTableSection = BC.getUniqueSectionByName("__bug_table");
11781190
if (!BugTableSection)
@@ -1215,6 +1227,8 @@ Error LinuxKernelRewriter::readBugTable() {
12151227
" referenced by bug table entry %d",
12161228
InstAddress, EntryID);
12171229
BC.MIB->addAnnotation(*Inst, "BugEntry", EntryID);
1230+
1231+
FunctionBugList[BF].push_back(EntryID);
12181232
}
12191233
}
12201234

@@ -1223,6 +1237,52 @@ Error LinuxKernelRewriter::readBugTable() {
12231237
return Error::success();
12241238
}
12251239

1240+
/// find_bug() uses linear search to match an address to an entry in the bug
1241+
/// table. Hence, there is no need to sort entries when rewriting the table.
1242+
/// When we need to erase an entry, we set its instruction address to zero.
1243+
Error LinuxKernelRewriter::rewriteBugTable() {
1244+
if (!BugTableSection)
1245+
return Error::success();
1246+
1247+
for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
1248+
if (!BC.shouldEmit(BF))
1249+
continue;
1250+
1251+
if (!FunctionBugList.count(&BF))
1252+
continue;
1253+
1254+
// Bugs that will be emitted for this function.
1255+
DenseSet<uint32_t> EmittedIDs;
1256+
for (BinaryBasicBlock &BB : BF) {
1257+
for (MCInst &Inst : BB) {
1258+
if (!BC.MIB->hasAnnotation(Inst, "BugEntry"))
1259+
continue;
1260+
const uint32_t ID = BC.MIB->getAnnotationAs<uint32_t>(Inst, "BugEntry");
1261+
EmittedIDs.insert(ID);
1262+
1263+
// Create a relocation entry for this bug entry.
1264+
MCSymbol *Label =
1265+
BC.MIB->getOrCreateInstLabel(Inst, "__BUG_", BC.Ctx.get());
1266+
const uint64_t EntryOffset = (ID - 1) * BUG_TABLE_ENTRY_SIZE;
1267+
BugTableSection->addRelocation(EntryOffset, Label, ELF::R_X86_64_PC32,
1268+
/*Addend*/ 0);
1269+
}
1270+
}
1271+
1272+
// Clear bug entries that were not emitted for this function, e.g. as a
1273+
// result of DCE, but setting their instruction address to zero.
1274+
for (const uint32_t ID : FunctionBugList[&BF]) {
1275+
if (!EmittedIDs.count(ID)) {
1276+
const uint64_t EntryOffset = (ID - 1) * BUG_TABLE_ENTRY_SIZE;
1277+
BugTableSection->addRelocation(EntryOffset, nullptr, ELF::R_X86_64_PC32,
1278+
/*Addend*/ 0);
1279+
}
1280+
}
1281+
}
1282+
1283+
return Error::success();
1284+
}
1285+
12261286
/// The kernel can replace certain instruction sequences depending on hardware
12271287
/// it is running on and features specified during boot time. The information
12281288
/// about alternative instruction sequences is stored in .altinstructions

bolt/test/X86/linux-bug-table.s

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
# REQUIRES: system-linux
22

3-
## Check that BOLT correctly parses the Linux kernel __bug_table section.
3+
## Check that BOLT correctly parses and updates the Linux kernel __bug_table
4+
## section.
45

56
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
67
# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \
78
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr,--no-pie
89

910
## Verify bug entry bindings to instructions.
1011

11-
# RUN: llvm-bolt %t.exe --print-normalized -o %t.out | FileCheck %s
12+
# RUN: llvm-bolt %t.exe --print-normalized --print-only=_start -o %t.out \
13+
# RUN: --eliminate-unreachable=1 --bolt-info=0 | FileCheck %s
14+
15+
## Verify bug entry bindings again after unreachable code elimination.
16+
17+
# RUN: llvm-bolt %t.out -o %t.out.1 --print-only=_start --print-normalized \
18+
# RUN: |& FileCheck --check-prefix=CHECK-REOPT %s
1219

1320
# CHECK: BOLT-INFO: Linux kernel binary detected
1421
# CHECK: BOLT-INFO: parsed 2 bug table entries
@@ -17,17 +24,21 @@
1724
.globl _start
1825
.type _start, %function
1926
_start:
20-
# CHECK: Binary Function "_start"
21-
nop
27+
jmp .L1
2228
.L0:
2329
ud2
2430
# CHECK: ud2
2531
# CHECK-SAME: BugEntry: 1
26-
nop
2732
.L1:
2833
ud2
2934
# CHECK: ud2
3035
# CHECK-SAME: BugEntry: 2
36+
37+
## Only the second entry should remain after the first pass.
38+
39+
# CHECK-REOPT: ud2
40+
# CHECK-REOPT-SAME: BugEntry: 2
41+
3142
ret
3243
.size _start, .-_start
3344

clang-tools-extra/clangd/support/Trace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ bool enabled();
143143
class Span {
144144
public:
145145
Span(llvm::Twine Name);
146-
/// Records span's duration in seconds to \p LatencyMetric with \p Name as the
147-
/// label.
146+
/// Records span's duration in milliseconds to \p LatencyMetric with \p Name
147+
/// as the label.
148148
Span(llvm::Twine Name, const Metric &LatencyMetric);
149149
~Span();
150150

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ Bug Fixes to C++ Support
443443
- Fix an issue where a namespace alias could be defined using a qualified name (all name components
444444
following the first `::` were ignored).
445445
- Fix an out-of-bounds crash when checking the validity of template partial specializations. (part of #GH86757).
446+
- Fix an issue caused by not handling invalid cases when substituting into the parameter mapping of a constraint. Fixes (#GH86757).
446447

447448
Bug Fixes to AST Handling
448449
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/analyzer/checkers.rst

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,44 +3120,82 @@ Check for misuses of stream APIs. Check for misuses of stream APIs: ``fopen, fcl
31203120
31213121
alpha.unix.Stream (C)
31223122
"""""""""""""""""""""
3123-
Check stream handling functions: ``fopen, tmpfile, fclose, fread, fwrite, fseek, ftell, rewind, fgetpos,``
3124-
``fsetpos, clearerr, feof, ferror, fileno``.
3123+
Check C stream handling functions:
3124+
``fopen, fdopen, freopen, tmpfile, fclose, fread, fwrite, fgetc, fgets, fputc, fputs, fprintf, fscanf, ungetc, getdelim, getline, fseek, fseeko, ftell, ftello, fflush, rewind, fgetpos, fsetpos, clearerr, feof, ferror, fileno``.
3125+
3126+
The checker maintains information about the C stream objects (``FILE *``) and
3127+
can detect error conditions related to use of streams. The following conditions
3128+
are detected:
3129+
3130+
* The ``FILE *`` pointer passed to the function is NULL (the single exception is
3131+
``fflush`` where NULL is allowed).
3132+
* Use of stream after close.
3133+
* Opened stream is not closed.
3134+
* Read from a stream after end-of-file. (This is not a fatal error but reported
3135+
by the checker. Stream remains in EOF state and the read operation fails.)
3136+
* Use of stream when the file position is indeterminate after a previous failed
3137+
operation. Some functions (like ``ferror``, ``clearerr``, ``fseek``) are
3138+
allowed in this state.
3139+
* Invalid 3rd ("``whence``") argument to ``fseek``.
3140+
3141+
The checker does not track the correspondence between integer file descriptors
3142+
and ``FILE *`` pointers. Operations on standard streams like ``stdin`` are not
3143+
treated specially and are therefore often not recognized (because these streams
3144+
are usually not opened explicitly by the program, and are global variables).
31253145
31263146
.. code-block:: c
31273147
3128-
void test() {
3148+
void test1() {
31293149
FILE *p = fopen("foo", "r");
31303150
} // warn: opened file is never closed
31313151
3132-
void test() {
3152+
void test2() {
31333153
FILE *p = fopen("foo", "r");
31343154
fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL
31353155
fclose(p);
31363156
}
31373157
3138-
void test() {
3158+
void test3() {
31393159
FILE *p = fopen("foo", "r");
3160+
if (p) {
3161+
fseek(p, 1, 3); // warn: third arg should be SEEK_SET, SEEK_END, or SEEK_CUR
3162+
fclose(p);
3163+
}
3164+
}
31403165
3141-
if (p)
3142-
fseek(p, 1, 3);
3143-
// warn: third arg should be SEEK_SET, SEEK_END, or SEEK_CUR
3166+
void test4() {
3167+
FILE *p = fopen("foo", "r");
3168+
if (!p)
3169+
return;
31443170
31453171
fclose(p);
3172+
fclose(p); // warn: stream already closed
31463173
}
31473174
3148-
void test() {
3175+
void test5() {
31493176
FILE *p = fopen("foo", "r");
3177+
if (!p)
3178+
return;
3179+
3180+
fgetc(p);
3181+
if (!ferror(p))
3182+
fgetc(p); // warn: possible read after end-of-file
3183+
31503184
fclose(p);
3151-
fclose(p); // warn: already closed
31523185
}
31533186
3154-
void test() {
3155-
FILE *p = tmpfile();
3156-
ftell(p); // warn: stream pointer might be NULL
3187+
void test6() {
3188+
FILE *p = fopen("foo", "r");
3189+
if (!p)
3190+
return;
3191+
3192+
fgetc(p);
3193+
if (!feof(p))
3194+
fgetc(p); // warn: file position may be indeterminate after I/O error
3195+
31573196
fclose(p);
31583197
}
31593198
3160-
31613199
.. _alpha-unix-cstring-BufferOverlap:
31623200
31633201
alpha.unix.cstring.BufferOverlap (C)

clang/include/clang/AST/TextNodeDumper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ class TextNodeDumper
352352
void VisitEnumConstantDecl(const EnumConstantDecl *D);
353353
void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
354354
void VisitFunctionDecl(const FunctionDecl *D);
355+
void VisitCXXDeductionGuideDecl(const CXXDeductionGuideDecl *D);
355356
void VisitFieldDecl(const FieldDecl *D);
356357
void VisitVarDecl(const VarDecl *D);
357358
void VisitBindingDecl(const BindingDecl *D);

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4599,6 +4599,12 @@ def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
45994599
let Prototype = "unsigned int(bool)";
46004600
}
46014601

4602+
def HLSLWaveGetLaneIndex : LangBuiltin<"HLSL_LANG"> {
4603+
let Spellings = ["__builtin_hlsl_wave_get_lane_index"];
4604+
let Attributes = [NoThrow, Const];
4605+
let Prototype = "unsigned int()";
4606+
}
4607+
46024608
def HLSLClamp : LangBuiltin<"HLSL_LANG"> {
46034609
let Spellings = ["__builtin_hlsl_elementwise_clamp"];
46044610
let Attributes = [NoThrow, Const];

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,8 @@ def err_drv_hlsl_unsupported_target : Error<
770770
"HLSL code generation is unsupported for target '%0'">;
771771
def err_drv_hlsl_bad_shader_required_in_target : Error<
772772
"%select{shader model|Vulkan environment|shader stage}0 is required as %select{OS|environment}1 in target '%2' for HLSL code generation">;
773-
773+
def err_drv_hlsl_16bit_types_unsupported: Error<
774+
"'%0' option requires target HLSL Version >= 2018%select{| and shader model >= 6.2}1, but HLSL Version is '%2'%select{| and shader model is '%3'}1">;
774775
def err_drv_hlsl_bad_shader_unsupported : Error<
775776
"%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' is invalid for HLSL code generation">;
776777
def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "

clang/include/clang/Lex/ModuleMap.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ class ModuleMap {
263263
Attributes Attrs;
264264

265265
/// If \c InferModules is non-zero, the module map file that allowed
266-
/// inferred modules. Otherwise, nullopt.
267-
OptionalFileEntryRef ModuleMapFile;
266+
/// inferred modules. Otherwise, invalid.
267+
FileID ModuleMapFID;
268268

269269
/// The names of modules that cannot be inferred within this
270270
/// directory.
@@ -279,8 +279,7 @@ class ModuleMap {
279279

280280
/// A mapping from an inferred module to the module map that allowed the
281281
/// inference.
282-
// FIXME: Consider making the values non-optional.
283-
llvm::DenseMap<const Module *, OptionalFileEntryRef> InferredModuleAllowedBy;
282+
llvm::DenseMap<const Module *, FileID> InferredModuleAllowedBy;
284283

285284
llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;
286285

@@ -618,8 +617,9 @@ class ModuleMap {
618617
///
619618
/// \param Module The module whose module map file will be returned, if known.
620619
///
621-
/// \returns The file entry for the module map file containing the given
622-
/// module, or nullptr if the module definition was inferred.
620+
/// \returns The FileID for the module map file containing the given module,
621+
/// invalid if the module definition was inferred.
622+
FileID getContainingModuleMapFileID(const Module *Module) const;
623623
OptionalFileEntryRef getContainingModuleMapFile(const Module *Module) const;
624624

625625
/// Get the module map file that (along with the module name) uniquely
@@ -631,9 +631,10 @@ class ModuleMap {
631631
/// of inferred modules, returns the module map that allowed the inference
632632
/// (e.g. contained 'module *'). Otherwise, returns
633633
/// getContainingModuleMapFile().
634+
FileID getModuleMapFileIDForUniquing(const Module *M) const;
634635
OptionalFileEntryRef getModuleMapFileForUniquing(const Module *M) const;
635636

636-
void setInferredModuleAllowedBy(Module *M, OptionalFileEntryRef ModMap);
637+
void setInferredModuleAllowedBy(Module *M, FileID ModMapFID);
637638

638639
/// Canonicalize \p Path in a manner suitable for a module map file. In
639640
/// particular, this canonicalizes the parent directory separately from the

clang/lib/APINotes/APINotesManager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ APINotesManager::getCurrentModuleAPINotes(Module *M, bool LookInModule,
221221
ArrayRef<std::string> SearchPaths) {
222222
FileManager &FM = SM.getFileManager();
223223
auto ModuleName = M->getTopLevelModuleName();
224+
auto ExportedModuleName = M->getTopLevelModule()->ExportAsModule;
224225
llvm::SmallVector<FileEntryRef, 2> APINotes;
225226

226227
// First, look relative to the module itself.
@@ -233,6 +234,10 @@ APINotesManager::getCurrentModuleAPINotes(Module *M, bool LookInModule,
233234

234235
APINotes.push_back(*File);
235236
}
237+
// If module FooCore is re-exported through module Foo, try Foo.apinotes.
238+
if (!ExportedModuleName.empty())
239+
if (auto File = findAPINotesFile(Dir, ExportedModuleName, WantPublic))
240+
APINotes.push_back(*File);
236241
};
237242

238243
if (M->IsFramework) {

0 commit comments

Comments
 (0)