Skip to content

Commit 414c0c9

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:d102ee63e849cdaa586fd1aaae900c1399bf2b76 into amd-gfx:4b601c68e317
Local branch amd-gfx 4b601c6 Merged main:7273ad123850a7b44c0625d098ebb49153bf855a into amd-gfx:319b068967d9 Remote branch main d102ee6 [clang] Use operator==(StringRef, StringRef) (NFC) (llvm#92708)
2 parents 4b601c6 + d102ee6 commit 414c0c9

File tree

115 files changed

+2676
-2745
lines changed

Some content is hidden

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

115 files changed

+2676
-2745
lines changed

.github/workflows/llvm-bugs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
if: github.repository == 'llvm/llvm-project'
1616
steps:
17-
- uses: actions/setup-node@v3
17+
- uses: actions/setup-node@v4
1818
with:
1919
node-version: 18
2020
check-latest: true

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,8 @@ static uint64_t fixDoubleJumps(BinaryFunction &Function, bool MarkInvalid) {
674674
MCPlusBuilder *MIB = Function.getBinaryContext().MIB.get();
675675
for (BinaryBasicBlock &BB : Function) {
676676
auto checkAndPatch = [&](BinaryBasicBlock *Pred, BinaryBasicBlock *Succ,
677-
const MCSymbol *SuccSym) {
677+
const MCSymbol *SuccSym,
678+
std::optional<uint32_t> Offset) {
678679
// Ignore infinite loop jumps or fallthrough tail jumps.
679680
if (Pred == Succ || Succ == &BB)
680681
return false;
@@ -715,9 +716,11 @@ static uint64_t fixDoubleJumps(BinaryFunction &Function, bool MarkInvalid) {
715716
Pred->removeSuccessor(&BB);
716717
Pred->eraseInstruction(Pred->findInstruction(Branch));
717718
Pred->addTailCallInstruction(SuccSym);
718-
MCInst *TailCall = Pred->getLastNonPseudoInstr();
719-
assert(TailCall);
720-
MIB->setOffset(*TailCall, BB.getOffset());
719+
if (Offset) {
720+
MCInst *TailCall = Pred->getLastNonPseudoInstr();
721+
assert(TailCall);
722+
MIB->setOffset(*TailCall, *Offset);
723+
}
721724
} else {
722725
return false;
723726
}
@@ -760,7 +763,8 @@ static uint64_t fixDoubleJumps(BinaryFunction &Function, bool MarkInvalid) {
760763
if (Pred->getSuccessor() == &BB ||
761764
(Pred->getConditionalSuccessor(true) == &BB && !IsTailCall) ||
762765
Pred->getConditionalSuccessor(false) == &BB)
763-
if (checkAndPatch(Pred, Succ, SuccSym) && MarkInvalid)
766+
if (checkAndPatch(Pred, Succ, SuccSym, MIB->getOffset(*Inst)) &&
767+
MarkInvalid)
764768
BB.markValid(BB.pred_size() != 0 || BB.isLandingPad() ||
765769
BB.isEntryPoint());
766770
}

bolt/test/X86/bb-with-two-tail-calls.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# This reproduces a bug with dynostats when trying to compute branch stats
22
# at a block with two tails calls (one conditional and one unconditional).
33

4-
# REQUIRES: system-linux
5-
64
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \
75
# RUN: %s -o %t.o
86
# RUN: link_fdata %s %t.o %t.fdata
@@ -13,7 +11,7 @@
1311
# CHECK-NOT: Assertion `BranchInfo.size() == 2 && "could only be called for blocks with 2 successors"' failed.
1412
# Two tail calls in the same basic block after SCTC:
1513
# CHECK: {{.*}}: ja {{.*}} # TAILCALL # Offset: 7 # CTCTakenCount: 4
16-
# CHECK-NEXT: {{.*}}: jmp {{.*}} # TAILCALL # Offset: 12
14+
# CHECK-NEXT: {{.*}}: jmp {{.*}} # TAILCALL # Offset: 13
1715

1816
.globl _start
1917
_start:
@@ -23,7 +21,9 @@ a: ja b
2321
x: ret
2422
# FDATA: 1 _start #a# 1 _start #b# 2 4
2523
b: jmp e
26-
c: jmp f
24+
c:
25+
.nops 1
26+
jmp f
2727

2828
.globl e
2929
e:

clang-tools-extra/modularize/ModularizeUtilities.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,9 @@ static std::string replaceDotDot(StringRef Path) {
435435
llvm::sys::path::const_iterator B = llvm::sys::path::begin(Path),
436436
E = llvm::sys::path::end(Path);
437437
while (B != E) {
438-
if (B->compare(".") == 0) {
439-
}
440-
else if (B->compare("..") == 0)
438+
if (*B == "..")
441439
llvm::sys::path::remove_filename(Buffer);
442-
else
440+
else if (*B != ".")
443441
llvm::sys::path::append(Buffer, *B);
444442
++B;
445443
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
=============================
2+
HLSL Availability Diagnostics
3+
=============================
4+
5+
.. contents::
6+
:local:
7+
8+
Introduction
9+
============
10+
11+
HLSL availability diagnostics emits errors or warning when unavailable shader APIs are used. Unavailable shader APIs are APIs that are exposed in HLSL code but are not available in the target shader stage or shader model version.
12+
13+
There are three modes of HLSL availability diagnostic:
14+
15+
#. **Default mode** - compiler emits an error when an unavailable API is found in a code that is reachable from the shader entry point function or from an exported library function (when compiling a shader library)
16+
17+
#. **Relaxed mode** - same as default mode except the compiler emits a warning. This mode is enabled by ``-Wno-error=hlsl-availability``.
18+
19+
#. **Strict mode** - compiler emits an error when an unavailable API is found in parsed code regardless of whether it can be reached from the shader entry point or exported functions, or not. This mode is enabled by ``-fhlsl-strict-availability``.
20+
21+
Implementation Details
22+
======================
23+
24+
Environment Parameter
25+
---------------------
26+
27+
In order to encode API availability based on the shader model version and shader model stage a new ``environment`` parameter was added to the existing Clang ``availability`` attribute.
28+
29+
The values allowed for this parameter are a subset of values allowed as the ``llvm::Triple`` environment component. If the environment parameters is present, the declared availability attribute applies only to targets with the same platform and environment.
30+
31+
Default and Relaxed Diagnostic Modes
32+
------------------------------------
33+
34+
This mode is implemented in ``DiagnoseHLSLAvailability`` class in ``SemaHLSL.cpp`` and it is invoked after the whole translation unit is parsed (from ``Sema::ActOnEndOfTranslationUnit``). The implementation iterates over all shader entry points and exported library functions in the translation unit and performs an AST traversal of each function body.
35+
36+
When a reference to another function or member method is found (``DeclRefExpr`` or ``MemberExpr``) and it has a body, the AST of the referenced function is also scanned. This chain of AST traversals will reach all of the code that is reachable from the initial shader entry point or exported library function and avoids the need to generate a call graph.
37+
38+
All shader APIs have an availability attribute that specifies the shader model version (and environment, if applicable) when this API was first introduced.When a reference to a function without a definition is found and it has an availability attribute, the version of the attribute is checked against the target shader model version and shader stage (if shader stage context is known), and an appropriate diagnostic is generated as needed.
39+
40+
All shader entry functions have ``HLSLShaderAttr`` attribute that specifies what type of shader this function represents. However, for exported library functions the target shader stage is unknown, so in this case the HLSL API availability will be only checked against the shader model version. It means that for exported library functions the diagnostic of APIs with availability specific to shader stage will be deferred until DXIL linking time.
41+
42+
A list of functions that were already scanned is kept in order to avoid duplicate scans and diagnostics (see ``DiagnoseHLSLAvailability::ScannedDecls``). It might happen that a shader library has multiple shader entry points for different shader stages that all call into the same shared function. It is therefore important to record not just that a function has been scanned, but also in which shader stage context. This is done by using ``llvm::DenseMap`` that maps ``FunctionDecl *`` to a ``unsigned`` bitmap that represents a set of shader stages (or environments) the function has been scanned for. The ``N``'th bit in the set is set if the function has been scanned in shader environment whose ``HLSLShaderAttr::ShaderType`` integer value equals ``N``.
43+
44+
The emitted diagnostic messages belong to ``hlsl-availability`` diagnostic group and are reported as errors by default. With ``-Wno-error=hlsl-availability`` flag they become warning, making it relaxed HLSL diagnostics mode.
45+
46+
Strict Diagnostic Mode
47+
----------------------
48+
49+
When strict HLSL availability diagnostic mode is enabled the compiler must report all HLSL API availability issues regardless of code reachability. The implementation of this mode takes advantage of an existing diagnostic scan in ``DiagnoseUnguardedAvailability`` class which is already traversing AST of each function as soon as the function body has been parsed. For HLSL, this pass was only slightly modified, such as making sure diagnostic messages are in the ``hlsl-availability`` group and that availability checks based on shader stage are not included if the shader stage context is unknown.
50+
51+
If the compilation target is a shader library, only availability based on shader model version can be diagnosed during this scan. To diagnose availability based on shader stage, the compiler needs to run the AST traversals implementated in ``DiagnoseHLSLAvailability`` at the end of the translation unit as described above.
52+
53+
As a result, availability based on specific shader stage will only be diagnosed in code that is reachable from a shader entry point or library export function. It also means that function bodies might be scanned multiple time. When that happens, care should be taken not to produce duplicated diagnostics.
54+
55+
========
56+
Examples
57+
========
58+
59+
**Note**
60+
For the example below, the ``WaveActiveCountBits`` API function became available in shader model 6.0 and ``WaveMultiPrefixSum`` in shader model 6.5.
61+
62+
The availability of ``ddx`` function depends on a shader stage. It is available for pixel shaders in shader model 2.1 and higher, for compute, mesh and amplification shaders in shader model 6.6 and higher. For any other shader stages it is not available.
63+
64+
Compute shader example
65+
======================
66+
67+
.. code-block:: c++
68+
69+
float unusedFunction(float f) {
70+
return ddx(f);
71+
}
72+
73+
[numthreads(4, 4, 1)]
74+
void main(uint3 threadId : SV_DispatchThreadId) {
75+
float f1 = ddx(threadId.x);
76+
float f2 = WaveActiveCountBits(threadId.y == 1.0);
77+
}
78+
79+
When compiled as compute shader for shader model version 5.0, Clang will emit the following error by default:
80+
81+
.. code-block:: console
82+
83+
<>:7:13: error: 'ddx' is only available in compute shader environment on Shader Model 6.6 or newer
84+
<>:8:13: error: 'WaveActiveCountBits' is only available on Shader Model 6.5 or newer
85+
86+
With relaxed diagnostic mode this errors will become warnings.
87+
88+
With strict diagnostic mode, in addition to the 2 errors above Clang will also emit error for the ``ddx`` call in ``unusedFunction``.:
89+
90+
.. code-block:: console
91+
92+
<>:2:9: error: 'ddx' is only available in compute shader environment on Shader Model 6.5 or newer
93+
<>:7:13: error: 'ddx' is only available in compute shader environment on Shader Model 6.5 or newer
94+
<>:7:13: error: 'WaveActiveCountBits' is only available on Shader Model 6.5 or newer
95+
96+
Shader library example
97+
======================
98+
99+
.. code-block:: c++
100+
101+
float myFunction(float f) {
102+
return ddx(f);
103+
}
104+
105+
float unusedFunction(float f) {
106+
return WaveMultiPrefixSum(f, 1.0);
107+
}
108+
109+
[shader("compute")]
110+
[numthreads(4, 4, 1)]
111+
void main(uint3 threadId : SV_DispatchThreadId) {
112+
float f = 3;
113+
float e = myFunction(f);
114+
}
115+
116+
[shader("pixel")]
117+
void main() {
118+
float f = 3;
119+
float e = myFunction(f);
120+
}
121+
122+
When compiled as shader library vshader model version 6.4, Clang will emit the following error by default:
123+
124+
.. code-block:: console
125+
126+
<>:2:9: error: 'ddx' is only available in compute shader environment on Shader Model 6.5 or newer
127+
128+
With relaxed diagnostic mode this errors will become warnings.
129+
130+
With strict diagnostic mode Clang will also emit errors for availability issues in code that is not used by any of the entry points:
131+
132+
.. code-block:: console
133+
134+
<>2:9: error: 'ddx' is only available in compute shader environment on Shader Model 6.6 or newer
135+
<>:6:9: error: 'WaveActiveCountBits' is only available on Shader Model 6.5 or newer
136+
137+
Note that ``myFunction`` is reachable from both pixel and compute shader entry points is therefore scanned twice - once for each context. The diagnostic is emitted only for the compute shader context.

clang/docs/HLSL/HLSLDocs.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ HLSL Design and Implementation
1616
ResourceTypes
1717
EntryFunctions
1818
FunctionCalls
19+
AvailabilityDiagnostics

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ New Compiler Flags
317317

318318
- ``-fexperimental-late-parse-attributes`` enables an experimental feature to
319319
allow late parsing certain attributes in specific contexts where they would
320-
not normally be late parsed. Currently this allows late parsing the
321-
`counted_by` attribute in C. See `Attribute Changes in Clang`_.
320+
not normally be late parsed.
322321

323322
- ``-fseparate-named-sections`` uses separate unique sections for global
324323
symbols in named special sections (i.e. symbols annotated with
@@ -407,24 +406,6 @@ Attribute Changes in Clang
407406
- The ``clspv_libclc_builtin`` attribute has been added to allow clspv
408407
(`OpenCL-C to Vulkan SPIR-V compiler <https://github.com/google/clspv>`_) to identify functions coming from libclc
409408
(`OpenCL-C builtin library <https://libclc.llvm.org>`_).
410-
- The ``counted_by`` attribute is now allowed on pointers that are members of a
411-
struct in C.
412-
413-
- The ``counted_by`` attribute can now be late parsed in C when
414-
``-fexperimental-late-parse-attributes`` is passed but only when attribute is
415-
used in the declaration attribute position. This allows using the
416-
attribute on existing code where it previously impossible to do so without
417-
re-ordering struct field declarations would break ABI as shown below.
418-
419-
.. code-block:: c
420-
421-
struct BufferTy {
422-
/* Refering to `count` requires late parsing */
423-
char* buffer __counted_by(count);
424-
/* Swapping `buffer` and `count` to avoid late parsing would break ABI */
425-
size_t count;
426-
};
427-
428409

429410
Improvements to Clang's diagnostics
430411
-----------------------------------

clang/include/clang/AST/Type.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2515,7 +2515,6 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
25152515
bool isRecordType() const;
25162516
bool isClassType() const;
25172517
bool isStructureType() const;
2518-
bool isStructureTypeWithFlexibleArrayMember() const;
25192518
bool isObjCBoxableRecordType() const;
25202519
bool isInterfaceType() const;
25212520
bool isStructureOrClassType() const;

clang/include/clang/Basic/Attr.td

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ def Availability : InheritableAttr {
999999
VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
10001000
BoolArgument<"unavailable">, StringArgument<"message">,
10011001
BoolArgument<"strict">, StringArgument<"replacement">,
1002-
IntArgument<"priority">];
1002+
IntArgument<"priority">, IdentifierArgument<"environment">];
10031003
let AdditionalMembers =
10041004
[{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
10051005
return llvm::StringSwitch<llvm::StringRef>(Platform)
@@ -1019,7 +1019,7 @@ def Availability : InheritableAttr {
10191019
.Case("xros", "visionOS")
10201020
.Case("xros_app_extension", "visionOS (App Extension)")
10211021
.Case("swift", "Swift")
1022-
.Case("shadermodel", "HLSL ShaderModel")
1022+
.Case("shadermodel", "Shader Model")
10231023
.Case("ohos", "OpenHarmony OS")
10241024
.Default(llvm::StringRef());
10251025
}
@@ -1059,7 +1059,34 @@ static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
10591059
.Case("visionos_app_extension", "xros_app_extension")
10601060
.Case("ShaderModel", "shadermodel")
10611061
.Default(Platform);
1062-
} }];
1062+
}
1063+
static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
1064+
return llvm::StringSwitch<llvm::StringRef>(Environment)
1065+
.Case("pixel", "pixel shader")
1066+
.Case("vertex", "vertex shader")
1067+
.Case("geometry", "geometry shader")
1068+
.Case("hull", "hull shader")
1069+
.Case("domain", "domain shader")
1070+
.Case("compute", "compute shader")
1071+
.Case("mesh", "mesh shader")
1072+
.Case("amplification", "amplification shader")
1073+
.Case("library", "shader library")
1074+
.Default(Environment);
1075+
}
1076+
static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef Environment) {
1077+
return llvm::StringSwitch<llvm::Triple::EnvironmentType>(Environment)
1078+
.Case("pixel", llvm::Triple::Pixel)
1079+
.Case("vertex", llvm::Triple::Vertex)
1080+
.Case("geometry", llvm::Triple::Geometry)
1081+
.Case("hull", llvm::Triple::Hull)
1082+
.Case("domain", llvm::Triple::Domain)
1083+
.Case("compute", llvm::Triple::Compute)
1084+
.Case("mesh", llvm::Triple::Mesh)
1085+
.Case("amplification", llvm::Triple::Amplification)
1086+
.Case("library", llvm::Triple::Library)
1087+
.Default(llvm::Triple::UnknownEnvironment);
1088+
}
1089+
}];
10631090
let HasCustomParsing = 1;
10641091
let InheritEvenIfAlreadyPresent = 1;
10651092
let Subjects = SubjectList<[Named]>;
@@ -2229,8 +2256,7 @@ def TypeNullUnspecified : TypeAttr {
22292256
def CountedBy : DeclOrTypeAttr {
22302257
let Spellings = [Clang<"counted_by">];
22312258
let Subjects = SubjectList<[Field], ErrorDiag>;
2232-
let Args = [ExprArgument<"Count">, IntArgument<"NestedLevel", 1>];
2233-
let LateParsed = LateAttrParseExperimentalExt;
2259+
let Args = [ExprArgument<"Count">, IntArgument<"NestedLevel">];
22342260
let ParseArgumentsAsUnevaluated = 1;
22352261
let Documentation = [CountedByDocs];
22362262
let LangOpts = [COnly];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,11 @@ replacement=\ *string-literal*
15931593
a warning about use of a deprecated declaration. The Fix-It will replace
15941594
the deprecated declaration with the new declaration specified.
15951595

1596+
environment=\ *identifier*
1597+
Target environment in which this declaration is available. If present,
1598+
the availability attribute applies only to targets with the same platform
1599+
and environment. The parameter is currently supported only in HLSL.
1600+
15961601
Multiple availability attributes can be placed on a declaration, which may
15971602
correspond to different platforms. For most platforms, the availability
15981603
attribute with the platform corresponding to the target platform will be used;

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,10 +1447,6 @@ def FunctionMultiVersioning
14471447

14481448
def NoDeref : DiagGroup<"noderef">;
14491449

1450-
// -fbounds-safety and bounds annotation related warnings
1451-
def BoundsSafetyCountedByEltTyUnknownSize :
1452-
DiagGroup<"bounds-safety-counted-by-elt-type-unknown-size">;
1453-
14541450
// A group for cross translation unit static analysis related warnings.
14551451
def CrossTU : DiagGroup<"ctu">;
14561452

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,8 @@ def err_zero_version : Error<
11121112
"version number must have non-zero major, minor, or sub-minor version">;
11131113
def err_availability_expected_platform : Error<
11141114
"expected a platform name, e.g., 'macos'">;
1115+
def err_availability_expected_environment : Error<
1116+
"expected an environment name, e.g., 'compute'">;
11151117

11161118
// objc_bridge_related attribute
11171119
def err_objcbridge_related_expected_related_class : Error<

0 commit comments

Comments
 (0)