Skip to content

Commit 7973d80

Browse files
committed
Merge from 'main' to 'sycl-web' (105 commits)
CONFLICT (content): Merge conflict in libclc/clc/include/clc/clcfunc.h
2 parents 63084b5 + 111cdaa commit 7973d80

File tree

451 files changed

+27054
-7113
lines changed

Some content is hidden

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

451 files changed

+27054
-7113
lines changed

.ci/utils.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ function at-exit {
2626
mkdir -p artifacts
2727
sccache --show-stats >> artifacts/sccache_stats.txt
2828
cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
29+
cp "${MONOREPO_ROOT}"/*.log artifacts/ || :
2930
cp "${BUILD_DIR}"/test-results.*.xml artifacts/ || :
3031

3132
# If building fails there will be no results files.
3233
shopt -s nullglob
3334

3435
if [[ "$GITHUB_STEP_SUMMARY" != "" ]]; then
3536
python "${MONOREPO_ROOT}"/.ci/generate_test_report_github.py \
36-
$retcode "${BUILD_DIR}"/test-results.*.xml "${BUILD_DIR}"/ninja*.log \
37+
$retcode "${BUILD_DIR}"/test-results.*.xml "${MONOREPO_ROOT}"/ninja*.log \
3738
>> $GITHUB_STEP_SUMMARY
3839
fi
3940
}

clang/bindings/python/clang/cindex.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,15 @@ def linkage(self) -> LinkageKind:
19071907

19081908
return LinkageKind.from_id(self._linkage)
19091909

1910+
@property
1911+
@cursor_null_guard
1912+
def language(self) -> LanguageKind:
1913+
"""Determine the "language" of the entity referred to by a given cursor."""
1914+
if not hasattr(self, "_language"):
1915+
self._language = conf.lib.clang_getCursorLanguage(self)
1916+
1917+
return LanguageKind.from_id(self._language)
1918+
19101919
@property
19111920
@cursor_null_guard
19121921
def tls_kind(self) -> TLSKind:
@@ -2584,6 +2593,17 @@ class LinkageKind(BaseEnumeration):
25842593
EXTERNAL = 4
25852594

25862595

2596+
class LanguageKind(BaseEnumeration):
2597+
"""
2598+
Describe the "language" of the entity referred to by a cursor.
2599+
"""
2600+
2601+
INVALID = 0
2602+
C = 1
2603+
OBJ_C = 2
2604+
C_PLUS_PLUS = 3
2605+
2606+
25872607
class TLSKind(BaseEnumeration):
25882608
"""Describes the kind of thread-local storage (TLS) of a cursor."""
25892609

@@ -4084,6 +4104,7 @@ def set_property(self, property, value):
40844104
("clang_getCursorDisplayName", [Cursor], _CXString),
40854105
("clang_getCursorExceptionSpecificationType", [Cursor], c_int),
40864106
("clang_getCursorExtent", [Cursor], SourceRange),
4107+
("clang_getCursorLanguage", [Cursor], c_int),
40874108
("clang_getCursorLexicalParent", [Cursor], Cursor),
40884109
("clang_getCursorLinkage", [Cursor], c_int),
40894110
("clang_getCursorLocation", [Cursor], SourceLocation),
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
from clang.cindex import Config, LanguageKind
4+
5+
if "CLANG_LIBRARY_PATH" in os.environ:
6+
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
7+
8+
import unittest
9+
10+
from .util import get_cursor, get_tu
11+
12+
13+
class TestCursorLanguage(unittest.TestCase):
14+
def test_c(self):
15+
tu = get_tu("int a;", lang="c")
16+
main_func = get_cursor(tu.cursor, "a")
17+
self.assertEqual(main_func.language, LanguageKind.C)
18+
19+
def test_c(self):
20+
tu = get_tu("class Cls {};", lang="cpp")
21+
main_func = get_cursor(tu.cursor, "Cls")
22+
self.assertEqual(main_func.language, LanguageKind.C_PLUS_PLUS)
23+
24+
def test_obj_c(self):
25+
tu = get_tu("@interface If : NSObject", lang="objc")
26+
main_func = get_cursor(tu.cursor, "If")
27+
self.assertEqual(main_func.language, LanguageKind.OBJ_C)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
BinaryOperator,
77
CursorKind,
88
ExceptionSpecificationKind,
9+
LanguageKind,
910
LinkageKind,
1011
RefQualifierKind,
1112
StorageClass,
@@ -26,6 +27,7 @@ class TestEnums(unittest.TestCase):
2627
AccessSpecifier,
2728
TypeKind,
2829
RefQualifierKind,
30+
LanguageKind,
2931
LinkageKind,
3032
TLSKind,
3133
StorageClass,

clang/docs/LanguageExtensions.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in
759759

760760
The integer elementwise intrinsics, including ``__builtin_elementwise_popcount``,
761761
``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``,
762-
``__builtin_elementwise_sub_sat`` can be called in a ``constexpr`` context.
762+
``__builtin_elementwise_sub_sat``, ``__builtin_elementwise_max``,
763+
``__builtin_elementwise_min`` can be called in a ``constexpr`` context.
763764

764765
No implicit promotion of integer types takes place. The mixing of integer types
765766
of different sizes and signs is forbidden in binary and ternary builtins.

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ Non-comprehensive list of changes in this release
124124
This feature is enabled by default but can be disabled by compiling with
125125
``-fno-sanitize-annotate-debug-info-traps``.
126126

127+
- ``__builtin_elementwise_max`` and ``__builtin_elementwise_min`` functions for integer types can
128+
now be used in constant expressions.
129+
127130
New Compiler Flags
128131
------------------
129132
- New option ``-fno-sanitize-annotate-debug-info-traps`` added to disable emitting trap reasons into the debug info when compiling with trapping UBSan (e.g. ``-fsanitize-trap=undefined``).
@@ -295,6 +298,7 @@ Crash and bug fixes
295298
^^^^^^^^^^^^^^^^^^^
296299
- Fixed a crash in the static analyzer that when the expression in an
297300
``[[assume(expr)]]`` attribute was enclosed in parentheses. (#GH151529)
301+
- Fixed a crash when parsing ``#embed`` parameters with unmatched closing brackets. (#GH152829)
298302

299303
Improvements
300304
^^^^^^^^^^^^
@@ -309,6 +313,7 @@ Sanitizers
309313

310314
Python Binding Changes
311315
----------------------
316+
- Exposed `clang_getCursorLanguage` via `Cursor.language`.
312317

313318
OpenMP Support
314319
--------------

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5982,6 +5982,7 @@ def HLSLResourceBinding: InheritableAttr {
59825982
return SpaceNumber;
59835983
}
59845984
void setImplicitBindingOrderID(uint32_t Value) {
5985+
assert(!hasImplicitBindingOrderID() && "attribute already has implicit binding order id");
59855986
ImplicitBindingOrderID = Value;
59865987
}
59875988
bool hasImplicitBindingOrderID() const {

clang/include/clang/Basic/Builtins.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,13 +1300,13 @@ def ElementwiseBitreverse : Builtin {
13001300

13011301
def ElementwiseMax : Builtin {
13021302
let Spellings = ["__builtin_elementwise_max"];
1303-
let Attributes = [NoThrow, Const, CustomTypeChecking];
1303+
let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
13041304
let Prototype = "void(...)";
13051305
}
13061306

13071307
def ElementwiseMin : Builtin {
13081308
let Spellings = ["__builtin_elementwise_min"];
1309-
let Attributes = [NoThrow, Const, CustomTypeChecking];
1309+
let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
13101310
let Prototype = "void(...)";
13111311
}
13121312

clang/include/clang/Driver/CommonArgs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ const char *RelocationModelName(llvm::Reloc::Model Model);
9090
std::tuple<llvm::Reloc::Model, unsigned, bool>
9191
ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
9292

93+
bool getStaticPIE(const llvm::opt::ArgList &Args, const ToolChain &TC);
94+
9395
unsigned ParseFunctionAlignment(const ToolChain &TC,
9496
const llvm::opt::ArgList &Args);
9597

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,6 @@ static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
22592259
static bool interp__builtin_elementwise_sat(InterpState &S, CodePtr OpPC,
22602260
const CallExpr *Call,
22612261
unsigned BuiltinID) {
2262-
Call->dumpColor();
22632262
assert(Call->getNumArgs() == 2);
22642263

22652264
// Single integer case.
@@ -2326,6 +2325,80 @@ static bool interp__builtin_elementwise_sat(InterpState &S, CodePtr OpPC,
23262325
return true;
23272326
}
23282327

2328+
static bool interp__builtin_elementwise_maxmin(InterpState &S, CodePtr OpPC,
2329+
const CallExpr *Call,
2330+
unsigned BuiltinID) {
2331+
assert(Call->getNumArgs() == 2);
2332+
2333+
QualType Arg0Type = Call->getArg(0)->getType();
2334+
2335+
// TODO: Support floating-point types.
2336+
if (!(Arg0Type->isIntegerType() ||
2337+
(Arg0Type->isVectorType() &&
2338+
Arg0Type->castAs<VectorType>()->getElementType()->isIntegerType())))
2339+
return false;
2340+
2341+
if (!Arg0Type->isVectorType()) {
2342+
assert(!Call->getArg(1)->getType()->isVectorType());
2343+
APSInt RHS = popToAPSInt(
2344+
S.Stk, *S.getContext().classify(Call->getArg(1)->getType()));
2345+
APSInt LHS = popToAPSInt(
2346+
S.Stk, *S.getContext().classify(Call->getArg(0)->getType()));
2347+
APInt Result;
2348+
if (BuiltinID == Builtin::BI__builtin_elementwise_max) {
2349+
Result = std::max(LHS, RHS);
2350+
} else if (BuiltinID == Builtin::BI__builtin_elementwise_min) {
2351+
Result = std::min(LHS, RHS);
2352+
} else {
2353+
llvm_unreachable("Wrong builtin ID");
2354+
}
2355+
2356+
pushInteger(S, APSInt(Result, !LHS.isSigned()), Call->getType());
2357+
return true;
2358+
}
2359+
2360+
// Vector case.
2361+
assert(Call->getArg(0)->getType()->isVectorType() &&
2362+
Call->getArg(1)->getType()->isVectorType());
2363+
const auto *VT = Call->getArg(0)->getType()->castAs<VectorType>();
2364+
assert(VT->getElementType() ==
2365+
Call->getArg(1)->getType()->castAs<VectorType>()->getElementType());
2366+
assert(VT->getNumElements() ==
2367+
Call->getArg(1)->getType()->castAs<VectorType>()->getNumElements());
2368+
assert(VT->getElementType()->isIntegralOrEnumerationType());
2369+
2370+
const Pointer &RHS = S.Stk.pop<Pointer>();
2371+
const Pointer &LHS = S.Stk.pop<Pointer>();
2372+
const Pointer &Dst = S.Stk.peek<Pointer>();
2373+
PrimType ElemT = *S.getContext().classify(VT->getElementType());
2374+
unsigned NumElems = VT->getNumElements();
2375+
for (unsigned I = 0; I != NumElems; ++I) {
2376+
APSInt Elem1;
2377+
APSInt Elem2;
2378+
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
2379+
Elem1 = LHS.elem<T>(I).toAPSInt();
2380+
Elem2 = RHS.elem<T>(I).toAPSInt();
2381+
});
2382+
2383+
APSInt Result;
2384+
if (BuiltinID == Builtin::BI__builtin_elementwise_max) {
2385+
Result = APSInt(std::max(Elem1, Elem2),
2386+
Call->getType()->isUnsignedIntegerOrEnumerationType());
2387+
} else if (BuiltinID == Builtin::BI__builtin_elementwise_min) {
2388+
Result = APSInt(std::min(Elem1, Elem2),
2389+
Call->getType()->isUnsignedIntegerOrEnumerationType());
2390+
} else {
2391+
llvm_unreachable("Wrong builtin ID");
2392+
}
2393+
2394+
INT_TYPE_SWITCH_NO_BOOL(ElemT,
2395+
{ Dst.elem<T>(I) = static_cast<T>(Result); });
2396+
}
2397+
Dst.initializeAllElements();
2398+
2399+
return true;
2400+
}
2401+
23292402
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
23302403
uint32_t BuiltinID) {
23312404
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -2733,6 +2806,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
27332806
case Builtin::BI__builtin_elementwise_sub_sat:
27342807
return interp__builtin_elementwise_sat(S, OpPC, Call, BuiltinID);
27352808

2809+
case Builtin::BI__builtin_elementwise_max:
2810+
case Builtin::BI__builtin_elementwise_min:
2811+
return interp__builtin_elementwise_maxmin(S, OpPC, Call, BuiltinID);
2812+
27362813
default:
27372814
S.FFDiag(S.Current->getLocation(OpPC),
27382815
diag::note_invalid_subexpr_in_const_expr)

0 commit comments

Comments
 (0)