Skip to content

Commit 622b697

Browse files
committed
Merge ccd35e5 into cheriot-upstream
2 parents 7c1c96a + ccd35e5 commit 622b697

File tree

387 files changed

+6771
-4036
lines changed

Some content is hidden

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

387 files changed

+6771
-4036
lines changed

.git-blame-ignore-revs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,3 @@ a3a007ad5fa20abc90ead4e1030b481bf109b4cf
145145
b7e332d3f59f567b1999fbcc660d7837cba8e406
146146
6056f942abe83b05406df8b04e95ec37a3d160b5
147147
906295b8a31c8dac5aa845864c0bca9f02f86184
148-
149-
# [mlir][tensor][linalg] Move Pack/UnPack Ops to Linalg
150-
517800e37e8d3a4ee84214bef65e227612c2a98b

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/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ Sanitizers
309309

310310
Python Binding Changes
311311
----------------------
312+
- Exposed `clang_getCursorLanguage` via `Cursor.language`.
312313

313314
OpenMP Support
314315
--------------

clang/include/clang/AST/ExprCXX.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,19 @@ class CXXConstructExpr : public Expr {
17181718
CXXConstructExprBits.IsImmediateEscalating = Set;
17191719
}
17201720

1721+
/// Returns the WarnUnusedResultAttr that is declared on the callee
1722+
/// or its return type declaration, together with a NamedDecl that
1723+
/// refers to the declaration the attribute is attached to.
1724+
std::pair<const NamedDecl *, const WarnUnusedResultAttr *>
1725+
getUnusedResultAttr(const ASTContext &Ctx) const {
1726+
return getUnusedResultAttrImpl(getConstructor(), getType());
1727+
}
1728+
1729+
/// Returns true if this call expression should warn on unused results.
1730+
bool hasUnusedResultAttr(const ASTContext &Ctx) const {
1731+
return getUnusedResultAttr(Ctx).second != nullptr;
1732+
}
1733+
17211734
SourceLocation getBeginLoc() const LLVM_READONLY;
17221735
SourceLocation getEndLoc() const LLVM_READONLY;
17231736
SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,15 +1932,10 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
19321932
dyn_cast<EmbedExpr>(Init->IgnoreParenImpCasts())) {
19331933
PrimType TargetT = classifyPrim(Init->getType());
19341934

1935-
auto Eval = [&](const Expr *Init, unsigned ElemIndex) {
1936-
PrimType InitT = classifyPrim(Init->getType());
1937-
if (!this->visit(Init))
1935+
auto Eval = [&](const IntegerLiteral *IL, unsigned ElemIndex) {
1936+
if (!this->emitConst(IL->getValue(), Init))
19381937
return false;
1939-
if (InitT != TargetT) {
1940-
if (!this->emitCast(InitT, TargetT, E))
1941-
return false;
1942-
}
1943-
return this->emitInitElem(TargetT, ElemIndex, Init);
1938+
return this->emitInitElem(TargetT, ElemIndex, IL);
19441939
};
19451940
if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
19461941
return false;
@@ -2062,21 +2057,36 @@ bool Compiler<Emitter>::visitArrayElemInit(unsigned ElemIndex, const Expr *Init,
20622057
template <class Emitter>
20632058
bool Compiler<Emitter>::visitCallArgs(ArrayRef<const Expr *> Args,
20642059
const FunctionDecl *FuncDecl,
2065-
bool Activate) {
2060+
bool Activate, bool IsOperatorCall) {
20662061
assert(VarScope->getKind() == ScopeKind::Call);
20672062
llvm::BitVector NonNullArgs;
20682063
if (FuncDecl && FuncDecl->hasAttr<NonNullAttr>())
20692064
NonNullArgs = collectNonNullArgs(FuncDecl, Args);
20702065

2066+
bool ExplicitMemberFn = false;
2067+
if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2068+
ExplicitMemberFn = MD->isExplicitObjectMemberFunction();
2069+
20712070
unsigned ArgIndex = 0;
20722071
for (const Expr *Arg : Args) {
20732072
if (canClassify(Arg)) {
20742073
if (!this->visit(Arg))
20752074
return false;
20762075
} else {
20772076

2078-
std::optional<unsigned> LocalIndex = allocateLocal(
2079-
Arg, Arg->getType(), /*ExtendingDecl=*/nullptr, ScopeKind::Call);
2077+
DeclTy Source = Arg;
2078+
if (FuncDecl) {
2079+
// Try to use the parameter declaration instead of the argument
2080+
// expression as a source.
2081+
unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2082+
if (DeclIndex < FuncDecl->getNumParams())
2083+
Source = FuncDecl->getParamDecl(ArgIndex - IsOperatorCall +
2084+
ExplicitMemberFn);
2085+
}
2086+
2087+
std::optional<unsigned> LocalIndex =
2088+
allocateLocal(std::move(Source), Arg->getType(),
2089+
/*ExtendingDecl=*/nullptr, ScopeKind::Call);
20802090
if (!LocalIndex)
20812091
return false;
20822092

@@ -4489,14 +4499,6 @@ template <class Emitter>
44894499
unsigned Compiler<Emitter>::allocateLocalPrimitive(
44904500
DeclTy &&Src, PrimType Ty, bool IsConst, const ValueDecl *ExtendingDecl,
44914501
ScopeKind SC, bool IsConstexprUnknown) {
4492-
// Make sure we don't accidentally register the same decl twice.
4493-
if (const auto *VD =
4494-
dyn_cast_if_present<ValueDecl>(Src.dyn_cast<const Decl *>())) {
4495-
assert(!P.getGlobal(VD));
4496-
assert(!Locals.contains(VD));
4497-
(void)VD;
4498-
}
4499-
45004502
// FIXME: There are cases where Src.is<Expr*>() is wrong, e.g.
45014503
// (int){12} in C. Consider using Expr::isTemporaryObject() instead
45024504
// or isa<MaterializeTemporaryExpr>().
@@ -4518,19 +4520,11 @@ std::optional<unsigned>
45184520
Compiler<Emitter>::allocateLocal(DeclTy &&Src, QualType Ty,
45194521
const ValueDecl *ExtendingDecl, ScopeKind SC,
45204522
bool IsConstexprUnknown) {
4521-
// Make sure we don't accidentally register the same decl twice.
4522-
if ([[maybe_unused]] const auto *VD =
4523-
dyn_cast_if_present<ValueDecl>(Src.dyn_cast<const Decl *>())) {
4524-
assert(!P.getGlobal(VD));
4525-
assert(!Locals.contains(VD));
4526-
}
4527-
45284523
const ValueDecl *Key = nullptr;
45294524
const Expr *Init = nullptr;
45304525
bool IsTemporary = false;
45314526
if (auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast<const Decl *>())) {
45324527
Key = VD;
4533-
Ty = VD->getType();
45344528

45354529
if (const auto *VarD = dyn_cast<VarDecl>(VD))
45364530
Init = VarD->getInit();
@@ -5167,7 +5161,8 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
51675161
return false;
51685162
}
51695163

5170-
if (!this->visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall))
5164+
if (!this->visitCallArgs(Args, FuncDecl, IsAssignmentOperatorCall,
5165+
isa<CXXOperatorCallExpr>(E)))
51715166
return false;
51725167

51735168
// Undo the argument reversal we did earlier.

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
306306
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init,
307307
OptPrimType InitT);
308308
bool visitCallArgs(ArrayRef<const Expr *> Args, const FunctionDecl *FuncDecl,
309-
bool Activate);
309+
bool Activate, bool IsOperatorCall);
310310

311311
/// Creates a local primitive value.
312312
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst,

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,12 +885,12 @@ bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
885885
if (!Ptr.block()->isAccessible()) {
886886
if (!CheckLive(S, OpPC, Ptr, AK_Assign))
887887
return false;
888+
if (!CheckExtern(S, OpPC, Ptr))
889+
return false;
888890
return CheckDummy(S, OpPC, Ptr.block(), AK_Assign);
889891
}
890892
if (!CheckLifetime(S, OpPC, Ptr.getLifetime(), AK_Assign))
891893
return false;
892-
if (!CheckExtern(S, OpPC, Ptr))
893-
return false;
894894
if (!CheckRange(S, OpPC, Ptr, AK_Assign))
895895
return false;
896896
if (!CheckActive(S, OpPC, Ptr, AK_Assign))

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,13 @@ static bool interp__builtin_isinf(InterpState &S, CodePtr OpPC,
459459
const InterpFrame *Frame, bool CheckSign,
460460
const CallExpr *Call) {
461461
const Floating &Arg = S.Stk.pop<Floating>();
462-
bool IsInf = Arg.isInf();
462+
APFloat F = Arg.getAPFloat();
463+
bool IsInf = F.isInfinity();
463464

464465
if (CheckSign)
465-
pushInteger(S, IsInf ? (Arg.isNegative() ? -1 : 1) : 0, Call->getType());
466+
pushInteger(S, IsInf ? (F.isNegative() ? -1 : 1) : 0, Call->getType());
466467
else
467-
pushInteger(S, Arg.isInf(), Call->getType());
468+
pushInteger(S, IsInf, Call->getType());
468469
return true;
469470
}
470471

0 commit comments

Comments
 (0)