Skip to content

Commit cecd30e

Browse files
committed
merge main into amd-staging
Change-Id: I6f0980189cbefce18064e7b6b85f3fb80b7e8a35
2 parents 4947049 + 88cc7ac commit cecd30e

File tree

133 files changed

+2788
-602
lines changed

Some content is hidden

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

133 files changed

+2788
-602
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ C++ Specific Potentially Breaking Changes
133133
// Fixed version:
134134
unsigned operator""_udl_name(unsigned long long);
135135

136+
- Clang will now produce an error diagnostic when [[clang::lifetimebound]] is
137+
applied on a parameter of a function that returns void. This was previously
138+
ignored and had no effect. (#GH107556)
139+
140+
.. code-block:: c++
141+
142+
// Now diagnoses with an error.
143+
void f(int& i [[clang::lifetimebound]]);
144+
136145
ABI Changes in This Version
137146
---------------------------
138147

@@ -326,6 +335,10 @@ Modified Compiler Flags
326335
f3 *c = (f3 *)x;
327336
}
328337
338+
- The ``-fveclib`` option has been updated to enable ``-fno-math-errno`` for
339+
``-fveclib=ArmPL`` and ``-fveclib=SLEEF``. This gives Clang more opportunities
340+
to utilize these vector libraries. The behavior for all other vector function
341+
libraries remains unchanged.
329342

330343
Removed Compiler Flags
331344
-------------------------

clang/include/clang/Analysis/FlowSensitive/NoopLattice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_NOOP_LATTICE_H
1515

1616
#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
17+
#include "clang/Support/Compiler.h"
1718
#include "llvm/ADT/Any.h"
1819
#include <ostream>
1920

clang/include/clang/Basic/AArch64SVEACLETypes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
AARCH64_VECTOR_TYPE(Name, MangledName, Id, SingletonId)
108108
#endif
109109

110-
111110
//===- Vector point types -----------------------------------------------===//
112111

113112
SVE_VECTOR_TYPE_INT("__SVInt8_t", "__SVInt8_t", SveInt8, SveInt8Ty, 16, 8, 1, true)
@@ -201,6 +200,7 @@ SVE_PREDICATE_TYPE_ALL("__clang_svboolx4_t", "svboolx4_t", SveBoolx4, SveBoolx4T
201200

202201
SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, SveCountTy)
203202

203+
AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8_t", "__MFloat8_t", MFloat8, MFloat8Ty, 1, 8, 1)
204204
AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x8_t", "__MFloat8x8_t", MFloat8x8, MFloat8x8Ty, 8, 8, 1)
205205
AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x16_t", "__MFloat8x16_t", MFloat8x16, MFloat8x16Ty, 16, 8, 1)
206206

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10097,6 +10097,9 @@ def err_lifetimebound_no_object_param : Error<
1009710097
def err_lifetimebound_ctor_dtor : Error<
1009810098
"'lifetimebound' attribute cannot be applied to a "
1009910099
"%select{constructor|destructor}0">;
10100+
def err_lifetimebound_void_return_type : Error<
10101+
"'lifetimebound' attribute cannot be applied to a parameter of a function "
10102+
"that returns void">;
1010010103

1010110104
// CHECK: returning address/reference of stack memory
1010210105
def warn_ret_stack_addr_ref : Warning<

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ enum PredefinedTypeIDs {
11491149
///
11501150
/// Type IDs for non-predefined types will start at
11511151
/// NUM_PREDEF_TYPE_IDs.
1152-
const unsigned NUM_PREDEF_TYPE_IDS = 511;
1152+
const unsigned NUM_PREDEF_TYPE_IDS = 512;
11531153

11541154
// Ensure we do not overrun the predefined types we reserved
11551155
// in the enum PredefinedTypeIDs above.

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,13 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
833833
#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
834834
#include "clang/Basic/AArch64SVEACLETypes.def"
835835
{
836+
if (BT->getKind() == BuiltinType::MFloat8) {
837+
Encoding = llvm::dwarf::DW_ATE_unsigned_char;
838+
BTName = BT->getName(CGM.getLangOpts());
839+
// Bit size and offset of the type.
840+
uint64_t Size = CGM.getContext().getTypeSize(BT);
841+
return DBuilder.createBasicType(BTName, Size, Encoding);
842+
}
836843
ASTContext::BuiltinVectorTypeInfo Info =
837844
// For svcount_t, only the lower 2 bytes are relevant.
838845
BT->getKind() == BuiltinType::SveCount

clang/lib/Sema/SemaDecl.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6940,7 +6940,7 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
69406940
}
69416941
}
69426942

6943-
// Check the attributes on the function type, if any.
6943+
// Check the attributes on the function type and function params, if any.
69446944
if (const auto *FD = dyn_cast<FunctionDecl>(&ND)) {
69456945
// Don't declare this variable in the second operand of the for-statement;
69466946
// GCC miscompiles that by ending its lifetime before evaluating the
@@ -6970,6 +6970,18 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
69706970
}
69716971
}
69726972
}
6973+
6974+
for (unsigned int I = 0; I < FD->getNumParams(); ++I) {
6975+
const ParmVarDecl *P = FD->getParamDecl(I);
6976+
6977+
// The [[lifetimebound]] attribute can be applied to a function parameter
6978+
// only if the function returns a value.
6979+
if (auto *A = P->getAttr<LifetimeBoundAttr>()) {
6980+
if (!isa<CXXConstructorDecl>(FD) && FD->getReturnType()->isVoidType()) {
6981+
S.Diag(A->getLocation(), diag::err_lifetimebound_void_return_type);
6982+
}
6983+
}
6984+
}
69736985
}
69746986
}
69756987

clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
namespace clang {
1919

20+
bool isSafePtr(clang::CXXRecordDecl *Decl) {
21+
return isRefCounted(Decl) || isCheckedPtr(Decl);
22+
}
23+
2024
bool tryToFindPtrOrigin(
2125
const Expr *E, bool StopAtFirstRefCountedObj,
2226
std::function<bool(const clang::Expr *, bool)> callback) {
@@ -31,7 +35,7 @@ bool tryToFindPtrOrigin(
3135
}
3236
if (auto *tempExpr = dyn_cast<CXXTemporaryObjectExpr>(E)) {
3337
if (auto *C = tempExpr->getConstructor()) {
34-
if (auto *Class = C->getParent(); Class && isRefCounted(Class))
38+
if (auto *Class = C->getParent(); Class && isSafePtr(Class))
3539
return callback(E, true);
3640
break;
3741
}
@@ -56,7 +60,7 @@ bool tryToFindPtrOrigin(
5660
if (StopAtFirstRefCountedObj) {
5761
if (auto *ConversionFunc =
5862
dyn_cast_or_null<FunctionDecl>(cast->getConversionFunction())) {
59-
if (isCtorOfRefCounted(ConversionFunc))
63+
if (isCtorOfSafePtr(ConversionFunc))
6064
return callback(E, true);
6165
}
6266
}
@@ -68,7 +72,7 @@ bool tryToFindPtrOrigin(
6872
if (auto *call = dyn_cast<CallExpr>(E)) {
6973
if (auto *memberCall = dyn_cast<CXXMemberCallExpr>(call)) {
7074
if (auto *decl = memberCall->getMethodDecl()) {
71-
std::optional<bool> IsGetterOfRefCt = isGetterOfRefCounted(decl);
75+
std::optional<bool> IsGetterOfRefCt = isGetterOfSafePtr(decl);
7276
if (IsGetterOfRefCt && *IsGetterOfRefCt) {
7377
E = memberCall->getImplicitObjectArgument();
7478
if (StopAtFirstRefCountedObj) {
@@ -87,15 +91,15 @@ bool tryToFindPtrOrigin(
8791
}
8892

8993
if (auto *callee = call->getDirectCallee()) {
90-
if (isCtorOfRefCounted(callee)) {
94+
if (isCtorOfRefCounted(callee) || isCtorOfCheckedPtr(callee)) {
9195
if (StopAtFirstRefCountedObj)
9296
return callback(E, true);
9397

9498
E = call->getArg(0);
9599
continue;
96100
}
97101

98-
if (isRefType(callee->getReturnType()))
102+
if (isSafePtrType(callee->getReturnType()))
99103
return callback(E, true);
100104

101105
if (isSingleton(callee))
@@ -114,7 +118,7 @@ bool tryToFindPtrOrigin(
114118
}
115119
if (auto *ObjCMsgExpr = dyn_cast<ObjCMessageExpr>(E)) {
116120
if (auto *Method = ObjCMsgExpr->getMethodDecl()) {
117-
if (isRefType(Method->getReturnType()))
121+
if (isSafePtrType(Method->getReturnType()))
118122
return callback(E, true);
119123
}
120124
}

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,16 @@ bool isCtorOfRefCounted(const clang::FunctionDecl *F) {
135135
|| FunctionName == "Identifier";
136136
}
137137

138-
bool isRefType(const clang::QualType T) {
138+
bool isCtorOfCheckedPtr(const clang::FunctionDecl *F) {
139+
assert(F);
140+
return isCheckedPtr(safeGetName(F));
141+
}
142+
143+
bool isCtorOfSafePtr(const clang::FunctionDecl *F) {
144+
return isCtorOfRefCounted(F) || isCtorOfCheckedPtr(F);
145+
}
146+
147+
bool isSafePtrType(const clang::QualType T) {
139148
QualType type = T;
140149
while (!type.isNull()) {
141150
if (auto *elaboratedT = type->getAs<ElaboratedType>()) {
@@ -145,7 +154,7 @@ bool isRefType(const clang::QualType T) {
145154
if (auto *specialT = type->getAs<TemplateSpecializationType>()) {
146155
if (auto *decl = specialT->getTemplateName().getAsTemplateDecl()) {
147156
auto name = decl->getNameAsString();
148-
return isRefType(name);
157+
return isRefType(name) || isCheckedPtr(name);
149158
}
150159
return false;
151160
}
@@ -177,6 +186,12 @@ std::optional<bool> isUncounted(const CXXRecordDecl* Class)
177186
return (*IsRefCountable);
178187
}
179188

189+
std::optional<bool> isUnchecked(const CXXRecordDecl *Class) {
190+
if (isCheckedPtr(Class))
191+
return false; // Cheaper than below
192+
return isCheckedPtrCapable(Class);
193+
}
194+
180195
std::optional<bool> isUncountedPtr(const QualType T) {
181196
if (T->isPointerType() || T->isReferenceType()) {
182197
if (auto *CXXRD = T->getPointeeCXXRecordDecl())
@@ -185,15 +200,26 @@ std::optional<bool> isUncountedPtr(const QualType T) {
185200
return false;
186201
}
187202

188-
std::optional<bool> isGetterOfRefCounted(const CXXMethodDecl* M)
189-
{
203+
std::optional<bool> isUnsafePtr(const QualType T) {
204+
if (T->isPointerType() || T->isReferenceType()) {
205+
if (auto *CXXRD = T->getPointeeCXXRecordDecl()) {
206+
return isUncounted(CXXRD) || isUnchecked(CXXRD);
207+
}
208+
}
209+
return false;
210+
}
211+
212+
std::optional<bool> isGetterOfSafePtr(const CXXMethodDecl *M) {
190213
assert(M);
191214

192215
if (isa<CXXMethodDecl>(M)) {
193216
const CXXRecordDecl *calleeMethodsClass = M->getParent();
194217
auto className = safeGetName(calleeMethodsClass);
195218
auto method = safeGetName(M);
196219

220+
if (isCheckedPtr(className) && (method == "get" || method == "ptr"))
221+
return true;
222+
197223
if ((isRefType(className) && (method == "get" || method == "ptr")) ||
198224
((className == "String" || className == "AtomString" ||
199225
className == "AtomStringImpl" || className == "UniqueString" ||
@@ -205,7 +231,12 @@ std::optional<bool> isGetterOfRefCounted(const CXXMethodDecl* M)
205231
// FIXME: Currently allowing any Ref<T> -> whatever cast.
206232
if (isRefType(className)) {
207233
if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M))
208-
return isUncountedPtr(maybeRefToRawOperator->getConversionType());
234+
return isUnsafePtr(maybeRefToRawOperator->getConversionType());
235+
}
236+
237+
if (isCheckedPtr(className)) {
238+
if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M))
239+
return isUnsafePtr(maybeRefToRawOperator->getConversionType());
209240
}
210241
}
211242
return false;
@@ -448,7 +479,7 @@ class TrivialFunctionAnalysisVisitor
448479
if (!Callee)
449480
return false;
450481

451-
std::optional<bool> IsGetterOfRefCounted = isGetterOfRefCounted(Callee);
482+
std::optional<bool> IsGetterOfRefCounted = isGetterOfSafePtr(Callee);
452483
if (IsGetterOfRefCounted && *IsGetterOfRefCounted)
453484
return true;
454485

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,30 @@ std::optional<bool> isUncounted(const clang::CXXRecordDecl* Class);
6363
/// class, false if not, std::nullopt if inconclusive.
6464
std::optional<bool> isUncountedPtr(const clang::QualType T);
6565

66-
/// \returns true if Name is a RefPtr, Ref, or its variant, false if not.
67-
bool isRefType(const std::string &Name);
66+
/// \returns true if \p T is a RefPtr, Ref, CheckedPtr, CheckedRef, or its
67+
/// variant, false if not.
68+
bool isSafePtrType(const clang::QualType T);
6869

6970
/// \returns true if \p F creates ref-countable object from uncounted parameter,
7071
/// false if not.
7172
bool isCtorOfRefCounted(const clang::FunctionDecl *F);
7273

73-
/// \returns true if \p T is RefPtr, Ref, or its variant, false if not.
74-
bool isRefType(const clang::QualType T);
74+
/// \returns true if \p F creates checked ptr object from uncounted parameter,
75+
/// false if not.
76+
bool isCtorOfCheckedPtr(const clang::FunctionDecl *F);
77+
78+
/// \returns true if \p F creates ref-countable or checked ptr object from
79+
/// uncounted parameter, false if not.
80+
bool isCtorOfSafePtr(const clang::FunctionDecl *F);
81+
82+
/// \returns true if \p Name is RefPtr, Ref, or its variant, false if not.
83+
bool isRefType(const std::string &Name);
84+
85+
/// \returns true if \p Name is CheckedRef or CheckedPtr, false if not.
86+
bool isCheckedPtr(const std::string &Name);
7587

7688
/// \returns true if \p M is getter of a ref-counted class, false if not.
77-
std::optional<bool> isGetterOfRefCounted(const clang::CXXMethodDecl* Method);
89+
std::optional<bool> isGetterOfSafePtr(const clang::CXXMethodDecl *Method);
7890

7991
/// \returns true if \p F is a conversion between ref-countable or ref-counted
8092
/// pointer types.

0 commit comments

Comments
 (0)