Skip to content

Commit f1e463c

Browse files
Merge from 'main' to 'sycl-web' (99 commits)
CONFLICT (content): Merge conflict in .github/workflows/pr-code-format.yml
2 parents f4a3efb + 1293ab3 commit f1e463c

File tree

344 files changed

+13170
-8945
lines changed

Some content is hidden

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

344 files changed

+13170
-8945
lines changed

.github/workflows/pr-code-format.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ jobs:
1313
code_formatter:
1414
runs-on: ubuntu-latest
1515
timeout-minutes: 30
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
18+
cancel-in-progress: true
1619
if: (github.repository == 'llvm/llvm-project' || github.repository == 'intel/llvm') && !contains(github.event.pull_request.labels.*.name, 'disable-lint')
1720
steps:
1821
- name: Fetch LLVM sources

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,10 @@ async def main() -> None:
511511
)
512512
invocation.append("-list-checks")
513513
invocation.append("-")
514-
if args.quiet:
515-
# Even with -quiet we still want to check if we can call clang-tidy.
516-
with open(os.devnull, "w") as dev_null:
517-
subprocess.check_call(invocation, stdout=dev_null)
518-
else:
519-
subprocess.check_call(invocation)
514+
# Even with -quiet we still want to check if we can call clang-tidy.
515+
subprocess.check_call(
516+
invocation, stdout=subprocess.DEVNULL if args.quiet else None
517+
)
520518
except:
521519
print("Unable to run clang-tidy.", file=sys.stderr)
522520
sys.exit(1)

clang-tools-extra/docs/clang-tidy/Contributing.rst

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,15 @@ Writing a clang-tidy Check
127127

128128
So you have an idea of a useful check for :program:`clang-tidy`.
129129

130-
First, if you're not familiar with LLVM development, read through the `Getting
131-
Started with LLVM`_ document for instructions on setting up your workflow and
130+
First, if you're not familiar with LLVM development, read through the `Getting Started
131+
with the LLVM System`_ document for instructions on setting up your workflow and
132132
the `LLVM Coding Standards`_ document to familiarize yourself with the coding
133-
style used in the project. For code reviews we mostly use `LLVM Phabricator`_.
133+
style used in the project. For code reviews we currently use `LLVM Github`_,
134+
though historically we used Phabricator.
134135

135-
.. _Getting Started with LLVM: https://llvm.org/docs/GettingStarted.html
136+
.. _Getting Started with the LLVM System: https://llvm.org/docs/GettingStarted.html
136137
.. _LLVM Coding Standards: https://llvm.org/docs/CodingStandards.html
137-
.. _LLVM Phabricator: https://llvm.org/docs/Phabricator.html
138+
.. _LLVM Github: https://github.com/llvm/llvm-project
138139

139140
Next, you need to decide which module the check belongs to. Modules
140141
are located in subdirectories of `clang-tidy/
@@ -336,13 +337,25 @@ a starting point for your test cases. A rough outline of the process looks like
336337
The quickest way to prototype your matcher is to use :program:`clang-query` to
337338
interactively build up your matcher. For complicated matchers, build up a matching
338339
expression incrementally and use :program:`clang-query`'s ``let`` command to save named
339-
matching expressions to simplify your matcher. Just like breaking up a huge function
340-
into smaller chunks with intention-revealing names can help you understand a complex
341-
algorithm, breaking up a matcher into smaller matchers with intention-revealing names
342-
can help you understand a complicated matcher. Once you have a working matcher, the
343-
C++ API will be virtually identical to your interactively constructed matcher. You can
344-
use local variables to preserve your intention-revealing names that you applied to
345-
nested matchers.
340+
matching expressions to simplify your matcher.
341+
342+
.. code-block:: console
343+
344+
clang-query> let c1 cxxRecordDecl()
345+
clang-query> match c1
346+
347+
Alternatively, pressing the tab key after a previous matcher's open parentheses would also
348+
show which matchers can be chained with the previous matcher, though some matchers that work
349+
may not be listed.
350+
351+
Just like breaking up a huge function into smaller chunks with intention-revealing names
352+
can help you understand a complex algorithm, breaking up a matcher into smaller matchers
353+
with intention-revealing names can help you understand a complicated matcher.
354+
355+
Once you have a working clang-query matcher, the C++ API matchers will be the same or similar
356+
to your interactively constructed matcher (there can be cases where they differ slightly).
357+
You can use local variables to preserve your intention-revealing names that you applied
358+
to nested matchers.
346359

347360
Creating private matchers
348361
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -646,10 +659,13 @@ directory. The path to this directory is available in a lit test with the varia
646659
Out-of-tree check plugins
647660
-------------------------
648661

662+
649663
Developing an out-of-tree check as a plugin largely follows the steps
650-
outlined above. The plugin is a shared library whose code lives outside
664+
outlined above, including creating a new module and doing the hacks to
665+
register the module. The plugin is a shared library whose code lives outside
651666
the clang-tidy build system. Build and link this shared library against
652-
LLVM as done for other kinds of Clang plugins.
667+
LLVM as done for other kinds of Clang plugins. If using CMake, use the keyword
668+
``MODULE`` while invoking ``add_library`` or ``llvm_add_library``.
653669

654670
The plugin can be loaded by passing `-load` to `clang-tidy` in addition to the
655671
names of the checks to enable.
@@ -664,6 +680,19 @@ compiled against the version of clang-tidy that will be loading the plugin.
664680
The plugins can use threads, TLS, or any other facilities available to in-tree
665681
code which is accessible from the external headers.
666682

683+
Note that testing out-of-tree checks might involve getting ``llvm-lit`` from an LLVM
684+
installation compiled from source. See `Getting Started with the LLVM System`_ for ways
685+
to do so.
686+
687+
Alternatively, get `lit`_ following the `test-suite guide`_ and get the `FileCheck`_ binary,
688+
and write a version of `check_clang_tidy.py`_ to suit your needs.
689+
690+
.. _Getting Started with the LLVM System: https://llvm.org/docs/GettingStarted.html
691+
.. _test-suite guide: https://llvm.org/docs/TestSuiteGuide.html
692+
.. _lit: https://llvm.org/docs/CommandGuide/lit.html
693+
.. _FileCheck: https://llvm.org/docs/CommandGuide/FileCheck.html
694+
.. _check_clang_tidy.py: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
695+
667696
Running clang-tidy on LLVM
668697
--------------------------
669698

@@ -688,10 +717,10 @@ warnings and errors. The script provides multiple configuration flags.
688717

689718
* To restrict the files examined you can provide one or more regex arguments
690719
that the file names are matched against.
691-
``run-clang-tidy.py clang-tidy/.*Check\.cpp`` will only analyze clang-tidy
720+
``run-clang-tidy.py clang-tidy/.*Check\.cpp`` will only analyze `clang-tidy`
692721
checks. It may also be necessary to restrict the header files that warnings
693-
are displayed from using the ``-header-filter`` flag. It has the same behavior
694-
as the corresponding :program:`clang-tidy` flag.
722+
are displayed from by using the ``-header-filter`` and ``-exclude-header-filter`` flags.
723+
They have the same behavior as the corresponding :program:`clang-tidy` flags.
695724

696725
* To apply suggested fixes ``-fix`` can be passed as an argument. This gathers
697726
all changes in a temporary directory and applies them. Passing ``-format``
@@ -758,4 +787,4 @@ There is only one argument that controls profile storage:
758787

759788
* If you run :program:`clang-tidy` from within ``/foo`` directory, and specify
760789
``-store-check-profile=.``, then the profile will still be saved to
761-
``/foo/<ISO8601-like timestamp>-example.cpp.json``
790+
``/foo/<ISO8601-like timestamp>-example.cpp.json``

clang/docs/HLSL/ExpectedDifferences.rst

Lines changed: 109 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ HLSL 202x based on proposal
5454
and
5555
`0008 <https://github.com/microsoft/hlsl-specs/blob/main/proposals/0008-non-member-operator-overloading.md>`_.
5656

57+
The largest difference between Clang and DXC's overload resolution is the
58+
algorithm used for identifying best-match overloads. There are more details
59+
about the algorithmic differences in the :ref:`multi_argument_overloads` section
60+
below. There are three high level differences that should be highlighted:
61+
62+
* **There should be no cases** where DXC and Clang both successfully
63+
resolve an overload where the resolved overload is different between the two.
64+
* There are cases where Clang will successfully resolve an overload that DXC
65+
wouldn't because we've trimmed the overload set in Clang to remove ambiguity.
66+
* There are cases where DXC will successfully resolve an overload that Clang
67+
will not for two reasons: (1) DXC only generates partial overload sets for
68+
builtin functions and (2) DXC resolves cases that probably should be ambiguous.
69+
5770
Clang's implementation extends standard overload resolution rules to HLSL
5871
library functionality. This causes subtle changes in overload resolution
5972
behavior between Clang and DXC. Some examples include:
@@ -71,18 +84,23 @@ behavior between Clang and DXC. Some examples include:
7184
uint U;
7285
int I;
7386
float X, Y, Z;
74-
double3 A, B;
87+
double3 R, G;
7588
}
7689

77-
void twoParams(int, int);
78-
void twoParams(float, float);
90+
void takesSingleDouble(double);
91+
void takesSingleDouble(vector<double, 1>);
92+
93+
void scalarOrVector(double);
94+
void scalarOrVector(vector<double, 2>);
7995

8096
export void call() {
81-
halfOrInt16(U); // DXC: Fails with call ambiguous between int16_t and uint16_t overloads
82-
// Clang: Resolves to halfOrInt16(uint16_t).
83-
halfOrInt16(I); // All: Resolves to halfOrInt16(int16_t).
8497
half H;
98+
halfOrInt16(I); // All: Resolves to halfOrInt16(int16_t).
99+
85100
#ifndef IGNORE_ERRORS
101+
halfOrInt16(U); // All: Fails with call ambiguous between int16_t and uint16_t
102+
// overloads
103+
86104
// asfloat16 is a builtin with overloads for half, int16_t, and uint16_t.
87105
H = asfloat16(I); // DXC: Fails to resolve overload for int.
88106
// Clang: Resolves to asfloat16(int16_t).
@@ -94,21 +112,28 @@ behavior between Clang and DXC. Some examples include:
94112

95113
takesDoubles(X, Y, Z); // Works on all compilers
96114
#ifndef IGNORE_ERRORS
97-
fma(X, Y, Z); // DXC: Fails to resolve no known conversion from float to double.
115+
fma(X, Y, Z); // DXC: Fails to resolve no known conversion from float to
116+
// double.
98117
// Clang: Resolves to fma(double,double,double).
99-
#endif
100118

101-
double D = dot(A, B); // DXC: Resolves to dot(double3, double3), fails DXIL Validation.
119+
double D = dot(R, G); // DXC: Resolves to dot(double3, double3), fails DXIL Validation.
102120
// FXC: Expands to compute double dot product with fmul/fadd
103-
// Clang: Resolves to dot(float3, float3), emits conversion warnings.
121+
// Clang: Fails to resolve as ambiguous against
122+
// dot(half, half) or dot(float, float)
123+
#endif
104124

105125
#ifndef IGNORE_ERRORS
106126
tan(B); // DXC: resolves to tan(float).
107127
// Clang: Fails to resolve, ambiguous between integer types.
108128

109-
twoParams(I, X); // DXC: resolves twoParams(int, int).
110-
// Clang: Fails to resolve ambiguous conversions.
111129
#endif
130+
131+
double D;
132+
takesSingleDouble(D); // All: Fails to resolve ambiguous conversions.
133+
takesSingleDouble(R); // All: Fails to resolve ambiguous conversions.
134+
135+
scalarOrVector(D); // All: Resolves to scalarOrVector(double).
136+
scalarOrVector(R); // All: Fails to resolve ambiguous conversions.
112137
}
113138

114139
.. note::
@@ -119,3 +144,75 @@ behavior between Clang and DXC. Some examples include:
119144
diagnostic notifying the user of the conversion rather than silently altering
120145
precision relative to the other overloads (as FXC does) or generating code
121146
that will fail validation (as DXC does).
147+
148+
.. _multi_argument_overloads:
149+
150+
Multi-Argument Overloads
151+
------------------------
152+
153+
In addition to the differences in single-element conversions, Clang and DXC
154+
differ dramatically in multi-argument overload resolution. C++ multi-argument
155+
overload resolution behavior (or something very similar) is required to
156+
implement
157+
`non-member operator overloading <https://github.com/microsoft/hlsl-specs/blob/main/proposals/0008-non-member-operator-overloading.md>`_.
158+
159+
Clang adopts the C++ inspired language from the
160+
`draft HLSL specification <https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf>`_,
161+
where an overload ``f1`` is a better candidate than ``f2`` if for all arguments the
162+
conversion sequences is not worse than the corresponding conversion sequence and
163+
for at least one argument it is better.
164+
165+
.. code-block:: c++
166+
167+
cbuffer CB {
168+
int I;
169+
float X;
170+
float4 V;
171+
}
172+
173+
void twoParams(int, int);
174+
void twoParams(float, float);
175+
void threeParams(float, float, float);
176+
void threeParams(float4, float4, float4);
177+
178+
export void call() {
179+
twoParams(I, X); // DXC: resolves twoParams(int, int).
180+
// Clang: Fails to resolve ambiguous conversions.
181+
182+
threeParams(X, V, V); // DXC: resolves threeParams(float4, float4, float4).
183+
// Clang: Fails to resolve ambiguous conversions.
184+
}
185+
186+
For the examples above since ``twoParams`` called with mixed parameters produces
187+
implicit conversion sequences that are { ExactMatch, FloatingIntegral } and {
188+
FloatingIntegral, ExactMatch }. In both cases an argument has a worse conversion
189+
in the other sequence, so the overload is ambiguous.
190+
191+
In the ``threeParams`` example the sequences are { ExactMatch, VectorTruncation,
192+
VectorTruncation } or { VectorSplat, ExactMatch, ExactMatch }, again in both
193+
cases at least one parameter has a worse conversion in the other sequence, so
194+
the overload is ambiguous.
195+
196+
.. note::
197+
198+
The behavior of DXC documented below is undocumented so this is gleaned from
199+
observation and a bit of reading the source.
200+
201+
DXC's approach for determining the best overload produces an integer score value
202+
for each implicit conversion sequence for each argument expression. Scores for
203+
casts are based on a bitmask construction that is complicated to reverse
204+
engineer. It seems that:
205+
206+
* Exact match is 0
207+
* Dimension increase is 1
208+
* Promotion is 2
209+
* Integral -> Float conversion is 4
210+
* Float -> Integral conversion is 8
211+
* Cast is 16
212+
213+
The masks are or'd against each other to produce a score for the cast.
214+
215+
The scores of each conversion sequence are then summed to generate a score for
216+
the overload candidate. The overload candidate with the lowest score is the best
217+
candidate. If more than one overload are matched for the lowest score the call
218+
is ambiguous.

clang/docs/tools/generate_formatted_state.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ def get_style(count, passed):
7878
- {style2}`{percent}%`
7979
"""
8080

81-
FNULL = open(os.devnull, "w")
82-
8381

8482
with open(DOC_FILE, "wb") as output:
8583
cleanfiles = open(CLEAN_FILE, "wb")
@@ -101,8 +99,8 @@ def get_style(count, passed):
10199
# interested in it, just the return code.
102100
git_check = subprocess.Popen(
103101
["git", "ls-files", "--error-unmatch", act_sub_dir],
104-
stdout=FNULL,
105-
stderr=FNULL,
102+
stdout=subprocess.DEVNULL,
103+
stderr=subprocess.DEVNULL,
106104
)
107105
if git_check.wait() != 0:
108106
print("Skipping directory: ", act_sub_dir)

clang/include/clang/Basic/BuiltinsWebAssembly.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ TARGET_BUILTIN(__builtin_wasm_bitmask_i16x8, "UiV8s", "nc", "simd128")
124124
TARGET_BUILTIN(__builtin_wasm_bitmask_i32x4, "UiV4i", "nc", "simd128")
125125
TARGET_BUILTIN(__builtin_wasm_bitmask_i64x2, "UiV2LLi", "nc", "simd128")
126126

127+
TARGET_BUILTIN(__builtin_wasm_abs_f16x8, "V8hV8h", "nc", "fp16")
127128
TARGET_BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc", "simd128")
128129
TARGET_BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc", "simd128")
129130

@@ -140,6 +141,10 @@ TARGET_BUILTIN(__builtin_wasm_max_f16x8, "V8hV8hV8h", "nc", "fp16")
140141
TARGET_BUILTIN(__builtin_wasm_pmin_f16x8, "V8hV8hV8h", "nc", "fp16")
141142
TARGET_BUILTIN(__builtin_wasm_pmax_f16x8, "V8hV8hV8h", "nc", "fp16")
142143

144+
TARGET_BUILTIN(__builtin_wasm_ceil_f16x8, "V8hV8h", "nc", "fp16")
145+
TARGET_BUILTIN(__builtin_wasm_floor_f16x8, "V8hV8h", "nc", "fp16")
146+
TARGET_BUILTIN(__builtin_wasm_trunc_f16x8, "V8hV8h", "nc", "fp16")
147+
TARGET_BUILTIN(__builtin_wasm_nearest_f16x8, "V8hV8h", "nc", "fp16")
143148
TARGET_BUILTIN(__builtin_wasm_ceil_f32x4, "V4fV4f", "nc", "simd128")
144149
TARGET_BUILTIN(__builtin_wasm_floor_f32x4, "V4fV4f", "nc", "simd128")
145150
TARGET_BUILTIN(__builtin_wasm_trunc_f32x4, "V4fV4f", "nc", "simd128")
@@ -151,9 +156,13 @@ TARGET_BUILTIN(__builtin_wasm_nearest_f64x2, "V2dV2d", "nc", "simd128")
151156

152157
TARGET_BUILTIN(__builtin_wasm_dot_s_i32x4_i16x8, "V4iV8sV8s", "nc", "simd128")
153158

159+
TARGET_BUILTIN(__builtin_wasm_sqrt_f16x8, "V8hV8h", "nc", "fp16")
154160
TARGET_BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc", "simd128")
155161
TARGET_BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc", "simd128")
156162

163+
TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i16x8_f16x8, "V8sV8h", "nc", "simd128")
164+
TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i16x8_f16x8, "V8sV8h", "nc", "simd128")
165+
157166
TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i32x4_f32x4, "V4iV4f", "nc", "simd128")
158167
TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i32x4_f32x4, "V4iV4f", "nc", "simd128")
159168

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5324,11 +5324,11 @@ bool Compiler<Emitter>::VisitVectorUnaryOperator(const UnaryOperator *E) {
53245324

53255325
auto UnaryOp = E->getOpcode();
53265326
if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
5327-
UnaryOp != UO_Not)
5327+
UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
53285328
return this->emitInvalid(E);
53295329

53305330
// Nothing to do here.
5331-
if (UnaryOp == UO_Plus)
5331+
if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
53325332
return this->delegate(SubExpr);
53335333

53345334
if (!Initializing) {

clang/lib/Basic/SourceManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ void SourceManager::clearIDTables() {
350350
LastLineNoContentCache = nullptr;
351351
LastFileIDLookup = FileID();
352352

353+
IncludedLocMap.clear();
353354
if (LineTable)
354355
LineTable->clear();
355356

0 commit comments

Comments
 (0)