Skip to content

Commit 5d0d34a

Browse files
committed
rebase
Created using spr 1.3.4
2 parents b188eb2 + 9c2de99 commit 5d0d34a

File tree

139 files changed

+3915
-752
lines changed

Some content is hidden

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

139 files changed

+3915
-752
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 }}
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/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/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/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

clang/bindings/python/clang/cindex.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,16 @@ def spelling(self):
17701770

17711771
return self._spelling
17721772

1773+
def pretty_printed(self, policy):
1774+
"""
1775+
Pretty print declarations.
1776+
Parameters:
1777+
policy -- The policy to control the entities being printed.
1778+
"""
1779+
return _CXString.from_result(
1780+
conf.lib.clang_getCursorPrettyPrinted(self, policy)
1781+
)
1782+
17731783
@property
17741784
def displayname(self):
17751785
"""
@@ -3699,6 +3709,72 @@ def write_main_file_to_stdout(self):
36993709
conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
37003710

37013711

3712+
class PrintingPolicyProperty(BaseEnumeration):
3713+
3714+
"""
3715+
A PrintingPolicyProperty identifies a property of a PrintingPolicy.
3716+
"""
3717+
3718+
Indentation = 0
3719+
SuppressSpecifiers = 1
3720+
SuppressTagKeyword = 2
3721+
IncludeTagDefinition = 3
3722+
SuppressScope = 4
3723+
SuppressUnwrittenScope = 5
3724+
SuppressInitializers = 6
3725+
ConstantArraySizeAsWritten = 7
3726+
AnonymousTagLocations = 8
3727+
SuppressStrongLifetime = 9
3728+
SuppressLifetimeQualifiers = 10
3729+
SuppressTemplateArgsInCXXConstructors = 11
3730+
Bool = 12
3731+
Restrict = 13
3732+
Alignof = 14
3733+
UnderscoreAlignof = 15
3734+
UseVoidForZeroParams = 16
3735+
TerseOutput = 17
3736+
PolishForDeclaration = 18
3737+
Half = 19
3738+
MSWChar = 20
3739+
IncludeNewlines = 21
3740+
MSVCFormatting = 22
3741+
ConstantsAsWritten = 23
3742+
SuppressImplicitBase = 24
3743+
FullyQualifiedName = 25
3744+
3745+
3746+
class PrintingPolicy(ClangObject):
3747+
"""
3748+
The PrintingPolicy is a wrapper class around clang::PrintingPolicy
3749+
3750+
It allows specifying how declarations, expressions, and types should be
3751+
pretty-printed.
3752+
"""
3753+
3754+
@staticmethod
3755+
def create(cursor):
3756+
"""
3757+
Creates a new PrintingPolicy
3758+
Parameters:
3759+
cursor -- Any cursor for a translation unit.
3760+
"""
3761+
return PrintingPolicy(conf.lib.clang_getCursorPrintingPolicy(cursor))
3762+
3763+
def __init__(self, ptr):
3764+
ClangObject.__init__(self, ptr)
3765+
3766+
def __del__(self):
3767+
conf.lib.clang_PrintingPolicy_dispose(self)
3768+
3769+
def get_property(self, property):
3770+
"""Get a property value for the given printing policy."""
3771+
return conf.lib.clang_PrintingPolicy_getProperty(self, property.value)
3772+
3773+
def set_property(self, property, value):
3774+
"""Set a property value for the given printing policy."""
3775+
conf.lib.clang_PrintingPolicy_setProperty(self, property.value, value)
3776+
3777+
37023778
# Now comes the plumbing to hook up the C library.
37033779

37043780
# Register callback types
@@ -3801,6 +3877,8 @@ def write_main_file_to_stdout(self):
38013877
("clang_getCursorExtent", [Cursor], SourceRange),
38023878
("clang_getCursorLexicalParent", [Cursor], Cursor),
38033879
("clang_getCursorLocation", [Cursor], SourceLocation),
3880+
("clang_getCursorPrettyPrinted", [Cursor, PrintingPolicy], _CXString),
3881+
("clang_getCursorPrintingPolicy", [Cursor], c_object_p),
38043882
("clang_getCursorReferenced", [Cursor], Cursor),
38053883
("clang_getCursorReferenceNameRange", [Cursor, c_uint, c_uint], SourceRange),
38063884
("clang_getCursorResultType", [Cursor], Type),
@@ -3924,6 +4002,9 @@ def write_main_file_to_stdout(self):
39244002
("clang_Cursor_isAnonymousRecordDecl", [Cursor], bool),
39254003
("clang_Cursor_isBitField", [Cursor], bool),
39264004
("clang_Location_isInSystemHeader", [SourceLocation], bool),
4005+
("clang_PrintingPolicy_dispose", [PrintingPolicy]),
4006+
("clang_PrintingPolicy_getProperty", [PrintingPolicy, c_int], c_uint),
4007+
("clang_PrintingPolicy_setProperty", [PrintingPolicy, c_int, c_uint]),
39274008
("clang_Type_getAlignOf", [Type], c_longlong),
39284009
("clang_Type_getClassType", [Type], Type),
39294010
("clang_Type_getNumTemplateArguments", [Type], c_int),
@@ -4104,6 +4185,8 @@ def function_exists(self, name: str) -> bool:
41044185
"FixIt",
41054186
"Index",
41064187
"LinkageKind",
4188+
"PrintingPolicy",
4189+
"PrintingPolicyProperty",
41074190
"RefQualifierKind",
41084191
"SourceLocation",
41094192
"SourceRange",

clang/bindings/python/tests/cindex/test_cursor.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
BinaryOperator,
66
Config,
77
CursorKind,
8+
PrintingPolicy,
9+
PrintingPolicyProperty,
810
StorageClass,
911
TemplateArgumentKind,
1012
TranslationUnit,
@@ -981,3 +983,15 @@ def test_from_result_null(self):
981983
def test_from_cursor_result_null(self):
982984
tu = get_tu("")
983985
self.assertEqual(tu.cursor.semantic_parent, None)
986+
987+
def test_pretty_print(self):
988+
tu = get_tu("struct X { int x; }; void f(bool x) { }", lang="cpp")
989+
f = get_cursor(tu, "f")
990+
991+
self.assertEqual(f.displayname, "f(bool)")
992+
pp = PrintingPolicy.create(f)
993+
self.assertEqual(pp.get_property(PrintingPolicyProperty.Bool), True)
994+
self.assertEqual(f.pretty_printed(pp), "void f(bool x) {\n}\n")
995+
pp.set_property(PrintingPolicyProperty.Bool, False)
996+
self.assertEqual(pp.get_property(PrintingPolicyProperty.Bool), False)
997+
self.assertEqual(f.pretty_printed(pp), "void f(_Bool x) {\n}\n")

clang/cmake/modules/AddClang.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ macro(add_clang_library name)
109109
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
110110

111111
if(MSVC AND NOT CLANG_LINK_CLANG_DYLIB)
112-
# Make sure all consumers also turn off visibility macros so there not trying to dllimport symbols.
112+
# Make sure all consumers also turn off visibility macros so they're not
113+
# trying to dllimport symbols.
113114
target_compile_definitions(${name} PUBLIC CLANG_BUILD_STATIC)
114115
if(TARGET "obj.${name}")
115116
target_compile_definitions("obj.${name}" PUBLIC CLANG_BUILD_STATIC)
116117
endif()
117-
elseif(NOT ARG_SHARED AND NOT ARG_STATIC)
118-
# Clang component libraries linked in to clang-cpp are declared without SHARED or STATIC
118+
elseif(TARGET "obj.${name}" AND NOT ARG_SHARED AND NOT ARG_STATIC)
119+
# Clang component libraries linked to clang-cpp are declared without SHARED or STATIC
119120
target_compile_definitions("obj.${name}" PUBLIC CLANG_EXPORTS)
120121
endif()
121122

0 commit comments

Comments
 (0)