Skip to content

Commit 64b154a

Browse files
authored
Merge branch 'main' into hlsl-firstbitlow
2 parents c1b7fad + d2498af commit 64b154a

File tree

565 files changed

+87520
-59527
lines changed

Some content is hidden

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

565 files changed

+87520
-59527
lines changed

.github/workflows/hlsl-matrix.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: HLSL Tests
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
branches:
10+
- main
11+
paths:
12+
- llvm/**/DirectX/**
13+
- .github/workflows/hlsl*
14+
- clang/*HLSL*/**/*
15+
- clang/**/*HLSL*
16+
- llvm/**/Frontend/HLSL/**/*
17+
18+
jobs:
19+
HLSL-Tests:
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
runs-on:
24+
- hlsl-macos
25+
26+
uses: ./.github/workflows/hlsl-test-all.yaml
27+
with:
28+
SKU: hlsl-macos
29+
TestTarget: check-hlsl-clang-mtl # TODO: This target changes based on SKU
30+
LLVM-ref: ${{ github.ref }}

.github/workflows/hlsl-test-all.yaml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: HLSL Test
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
OffloadTest-branch:
10+
description: 'Test Suite Branch'
11+
required: false
12+
default: 'main'
13+
type: string
14+
LLVM-ref:
15+
description: 'LLVM Branch'
16+
required: false
17+
default: 'main'
18+
type: string
19+
SKU:
20+
required: true
21+
type: string
22+
TestTarget:
23+
required: false
24+
default: 'check-hlsl'
25+
type: string
26+
27+
jobs:
28+
build:
29+
runs-on: ${{ inputs.SKU }}
30+
steps:
31+
- name: Checkout DXC
32+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
33+
with:
34+
repository: Microsoft/DirectXShaderCompiler
35+
ref: main
36+
path: DXC
37+
submodules: true
38+
- name: Checkout LLVM
39+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
40+
with:
41+
ref: ${{ inputs.LLVM-branch }}
42+
path: llvm-project
43+
- name: Checkout OffloadTest
44+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
45+
with:
46+
repository: llvm-beanz/offload-test-suite
47+
ref: main
48+
path: OffloadTest
49+
- name: Checkout Golden Images
50+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
51+
with:
52+
repository: llvm-beanz/offload-golden-images
53+
ref: main
54+
path: golden-images
55+
- name: Setup Windows
56+
if: runner.os == 'Windows'
57+
uses: llvm/actions/setup-windows@main
58+
with:
59+
arch: amd64
60+
- name: Build DXC
61+
run: |
62+
cd DXC
63+
mkdir build
64+
cd build
65+
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -C ${{ github.workspace }}/DXC/cmake/caches/PredefinedParams.cmake -C ${{ github.workspace }}/OffloadTest/cmake/caches/sccache.cmake -DHLSL_DISABLE_SOURCE_GENERATION=On ${{ github.workspace }}/DXC/
66+
ninja dxv llvm-dis
67+
- name: Build LLVM
68+
run: |
69+
cd llvm-project
70+
mkdir build
71+
cd build
72+
cmake -G Ninja -DDXIL_DIS=${{ github.workspace }}/DXC/build/bin/llvm-dis -DLLVM_INCLUDE_DXIL_TESTS=On -DCMAKE_BUILD_TYPE=Release -C ${{ github.workspace }}/llvm-project/clang/cmake/caches/HLSL.cmake -C ${{ github.workspace }}/OffloadTest/cmake/caches/sccache.cmake -DDXC_DIR=${{ github.workspace }}/DXC/build/bin -DLLVM_EXTERNAL_OFFLOADTEST_SOURCE_DIR=${{ github.workspace }}/OffloadTest -DLLVM_EXTERNAL_PROJECTS="OffloadTest" -DLLVM_LIT_ARGS="--xunit-xml-output=testresults.xunit.xml -v" -DGOLDENIMAGE_DIR=${{ github.workspace }}/golden-images ${{ github.workspace }}/llvm-project/llvm/
73+
ninja hlsl-test-depends llvm-test-depends clang-test-depends
74+
- name: Run HLSL Tests
75+
run: |
76+
cd llvm-project
77+
cd build
78+
ninja check-llvm
79+
ninja check-clang
80+
ninja check-hlsl-unit
81+
ninja ${{ inputs.TestTarget }}
82+
- name: Publish Test Results
83+
uses: EnricoMi/publish-unit-test-result-action/macos@170bf24d20d201b842d7a52403b73ed297e6645b # v2
84+
if: always() && runner.os == 'macOS'
85+
with:
86+
comment_mode: off
87+
files: llvm-project/build/**/testresults.xunit.xml

clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -337,33 +337,34 @@ FileOptionsBaseProvider::FileOptionsBaseProvider(
337337
void FileOptionsBaseProvider::addRawFileOptions(
338338
llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
339339
auto CurSize = CurOptions.size();
340-
341340
// Look for a suitable configuration file in all parent directories of the
342341
// file. Start with the immediate parent directory and move up.
343-
StringRef Path = llvm::sys::path::parent_path(AbsolutePath);
344-
for (StringRef CurrentPath = Path; !CurrentPath.empty();
345-
CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
346-
std::optional<OptionsSource> Result;
347-
348-
auto Iter = CachedOptions.find(CurrentPath);
349-
if (Iter != CachedOptions.end())
350-
Result = Iter->second;
351-
352-
if (!Result)
353-
Result = tryReadConfigFile(CurrentPath);
354-
355-
if (Result) {
356-
// Store cached value for all intermediate directories.
357-
while (Path != CurrentPath) {
342+
StringRef RootPath = llvm::sys::path::parent_path(AbsolutePath);
343+
auto MemorizedConfigFile =
344+
[this, &RootPath](StringRef CurrentPath) -> std::optional<OptionsSource> {
345+
const auto Iter = CachedOptions.Memorized.find(CurrentPath);
346+
if (Iter != CachedOptions.Memorized.end())
347+
return CachedOptions.Storage[Iter->second];
348+
std::optional<OptionsSource> OptionsSource = tryReadConfigFile(CurrentPath);
349+
if (OptionsSource) {
350+
const size_t Index = CachedOptions.Storage.size();
351+
CachedOptions.Storage.emplace_back(OptionsSource.value());
352+
while (RootPath != CurrentPath) {
358353
LLVM_DEBUG(llvm::dbgs()
359-
<< "Caching configuration for path " << Path << ".\n");
360-
if (!CachedOptions.count(Path))
361-
CachedOptions[Path] = *Result;
362-
Path = llvm::sys::path::parent_path(Path);
354+
<< "Caching configuration for path " << RootPath << ".\n");
355+
CachedOptions.Memorized[RootPath] = Index;
356+
RootPath = llvm::sys::path::parent_path(RootPath);
363357
}
364-
CachedOptions[Path] = *Result;
365-
366-
CurOptions.push_back(*Result);
358+
CachedOptions.Memorized[CurrentPath] = Index;
359+
RootPath = llvm::sys::path::parent_path(CurrentPath);
360+
}
361+
return OptionsSource;
362+
};
363+
for (StringRef CurrentPath = RootPath; !CurrentPath.empty();
364+
CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
365+
if (std::optional<OptionsSource> Result =
366+
MemorizedConfigFile(CurrentPath)) {
367+
CurOptions.emplace_back(Result.value());
367368
if (!Result->first.InheritParentConfig.value_or(false))
368369
break;
369370
}

clang-tools-extra/clang-tidy/ClangTidyOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
241241
/// \c ConfigHandlers.
242242
std::optional<OptionsSource> tryReadConfigFile(llvm::StringRef Directory);
243243

244-
llvm::StringMap<OptionsSource> CachedOptions;
244+
struct OptionsCache {
245+
llvm::StringMap<size_t> Memorized;
246+
llvm::SmallVector<OptionsSource, 4U> Storage;
247+
} CachedOptions;
245248
ClangTidyOptions OverrideOptions;
246249
ConfigFileHandlers ConfigHandlers;
247250
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
#include "UnusedParametersCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/AST/ASTLambda.h"
12+
#include "clang/AST/Attr.h"
13+
#include "clang/AST/Decl.h"
1214
#include "clang/AST/RecursiveASTVisitor.h"
1315
#include "clang/ASTMatchers/ASTMatchFinder.h"
16+
#include "clang/Basic/SourceManager.h"
1417
#include "clang/Lex/Lexer.h"
1518
#include "llvm/ADT/STLExtras.h"
1619
#include <unordered_map>
@@ -26,6 +29,17 @@ bool isOverrideMethod(const FunctionDecl *Function) {
2629
return MD->size_overridden_methods() > 0 || MD->hasAttr<OverrideAttr>();
2730
return false;
2831
}
32+
33+
bool hasAttrAfterParam(const SourceManager *SourceManager,
34+
const ParmVarDecl *Param) {
35+
for (const auto *Attr : Param->attrs()) {
36+
if (SourceManager->isBeforeInTranslationUnit(Param->getLocation(),
37+
Attr->getLocation())) {
38+
return true;
39+
}
40+
}
41+
return false;
42+
}
2943
} // namespace
3044

3145
void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
@@ -189,6 +203,11 @@ void UnusedParametersCheck::check(const MatchFinder::MatchResult &Result) {
189203
if (Param->isUsed() || Param->isReferenced() || !Param->getDeclName() ||
190204
Param->hasAttr<UnusedAttr>())
191205
continue;
206+
if (hasAttrAfterParam(Result.SourceManager, Param)) {
207+
// Due to how grammar works, attributes would be wrongly applied to the
208+
// type if we remove the preceding parameter name.
209+
continue;
210+
}
192211

193212
// In non-strict mode ignore function definitions with empty bodies
194213
// (constructor initializer counts for non-empty body).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void UseInternalLinkageCheck::registerMatchers(MatchFinder *Finder) {
125125
exportDecl()))))));
126126
Finder->addMatcher(
127127
functionDecl(Common, hasBody(),
128-
unless(anyOf(cxxMethodDecl(),
128+
unless(anyOf(cxxMethodDecl(), isConsteval(),
129129
isAllocationOrDeallocationOverloadedFunction(),
130130
isMain())))
131131
.bind("fn"),

clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static bool maxCondition(const BinaryOperator::Opcode Op, const Expr *CondLhs,
5959
return false;
6060
}
6161

62-
QualType getNonTemplateAlias(QualType QT) {
62+
static QualType getNonTemplateAlias(QualType QT) {
6363
while (true) {
6464
// cast to a TypedefType
6565
if (const TypedefType *TT = dyn_cast<TypedefType>(QT)) {
@@ -92,15 +92,15 @@ static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs,
9292
const llvm::StringRef AssignLhsStr = Lexer::getSourceText(
9393
Source.getExpansionRange(AssignLhs->getSourceRange()), Source, LO);
9494

95-
clang::QualType GlobalImplicitCastType;
96-
clang::QualType LhsType = CondLhs->getType()
97-
.getCanonicalType()
98-
.getNonReferenceType()
99-
.getUnqualifiedType();
100-
clang::QualType RhsType = CondRhs->getType()
101-
.getCanonicalType()
102-
.getNonReferenceType()
103-
.getUnqualifiedType();
95+
QualType GlobalImplicitCastType;
96+
QualType LhsType = CondLhs->getType()
97+
.getCanonicalType()
98+
.getNonReferenceType()
99+
.getUnqualifiedType();
100+
QualType RhsType = CondRhs->getType()
101+
.getCanonicalType()
102+
.getNonReferenceType()
103+
.getUnqualifiedType();
104104
if (LhsType != RhsType) {
105105
GlobalImplicitCastType = getNonTemplateAlias(BO->getLHS()->getType());
106106
}

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ Changes in existing checks
286286

287287
- Improved :doc:`misc-use-internal-linkage
288288
<clang-tidy/checks/misc/use-internal-linkage>` check to insert ``static``
289-
keyword before type qualifiers such as ``const`` and ``volatile`` and fix
290-
false positives for function declaration without body and fix false positives
291-
for C++20 export declarations and fix false positives for global scoped
289+
keyword before type qualifiers such as ``const`` and ``volatile``. Also, fix
290+
false positives for function declaration without body, C++20 consteval
291+
functions, C++20 export declarations, and global scoped
292292
overloaded ``operator new`` and ``operator delete``.
293293

294294
- Improved :doc:`modernize-avoid-c-arrays

clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ void f(void (*fn)()) {;}
3333
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: parameter 'fn' is unused [misc-unused-parameters]
3434
// CHECK-FIXES: {{^}}void f(void (* /*fn*/)()) {;}{{$}}
3535

36+
int *k([[clang::lifetimebound]] int *i) {;}
37+
// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: parameter 'i' is unused [misc-unused-parameters]
38+
// CHECK-FIXES: {{^}}int *k({{\[\[clang::lifetimebound\]\]}} int * /*i*/) {;}{{$}}
39+
40+
#define ATTR_BEFORE(x) [[clang::lifetimebound]] x
41+
int* m(ATTR_BEFORE(const int *i)) { return nullptr; }
42+
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: parameter 'i' is unused [misc-unused-parameters]
43+
// CHECK-FIXES: {{^}}int* m(ATTR_BEFORE(const int * /*i*/)) { return nullptr; }{{$}}
44+
#undef ATTR_BEFORE
45+
3646
// Unchanged cases
3747
// ===============
3848
void f(int i); // Don't remove stuff in declarations
@@ -42,6 +52,12 @@ void s(int i[1]);
4252
void u(void (*fn)());
4353
void w(int i) { (void)i; } // Don't remove used parameters
4454

55+
// Don't reanchor the attribute to the type:
56+
int *x(int *i [[clang::lifetimebound]]) { return nullptr; }
57+
#define ATTR_AFTER(x) x [[clang::lifetimebound]]
58+
int* y(ATTR_AFTER(const int *i)) { return nullptr; }
59+
#undef ATTR_AFTER
60+
4561
bool useLambda(int (*fn)(int));
4662
static bool static_var = useLambda([] (int a) { return a; });
4763

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %check_clang_tidy -std=c++20 %s misc-use-internal-linkage %t -- -- -I%S/Inputs/use-internal-linkage
2+
3+
consteval void gh122096() {}
4+
5+
constexpr void cxf() {}
6+
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: function 'cxf'
7+
// CHECK-FIXES: static constexpr void cxf() {}

0 commit comments

Comments
 (0)