Skip to content

Commit 0511e32

Browse files
run 'git merge main'
2 parents 27c96db + dcfa147 commit 0511e32

File tree

122 files changed

+3351
-1348
lines changed

Some content is hidden

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

122 files changed

+3351
-1348
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ static bool canAdvanceAssignment(AssignedLevel Level) {
6767
static void updateAssignmentLevel(
6868
const FieldDecl *Field, const Expr *Init, const CXXConstructorDecl *Ctor,
6969
llvm::DenseMap<const FieldDecl *, AssignedLevel> &AssignedFields) {
70-
auto It = AssignedFields.find(Field);
71-
if (It == AssignedFields.end())
72-
It = AssignedFields.insert({Field, AssignedLevel::None}).first;
70+
auto It = AssignedFields.try_emplace(Field, AssignedLevel::None).first;
7371

7472
if (!canAdvanceAssignment(It->second))
7573
// fast path for already decided field.

clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ This check implements detection of local variables which could be declared as
77
``const`` but are not. Declaring variables as ``const`` is required or recommended by many
88
coding guidelines, such as:
99
`ES.25 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es25-declare-an-object-const-or-constexpr-unless-you-want-to-modify-its-value-later-on>`_
10-
from the C++ Core Guidelines and `AUTOSAR C++14 Rule A7-1-1 (6.7.1 Specifiers)
11-
<https://www.autosar.org/fileadmin/standards/R22-11/AP/AUTOSAR_RS_CPP14Guidelines.pdf>`_.
10+
from the C++ Core Guidelines.
1211

1312
Please note that this check's analysis is type-based only. Variables that are not modified
1413
but used to create a non-const handle that might escape the scope are not diagnosed

clang-tools-extra/docs/clang-tidy/checks/misc/unconventional-assign-operator.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,3 @@ types and definitions with good return type but wrong ``return`` statements.
1313
type (e.g. ``int``).
1414
* Private and deleted operators are ignored.
1515
* The operator must always return ``*this``.
16-
17-
This check implements `AUTOSAR C++14 Rule A13-2-1
18-
<https://www.autosar.org/fileadmin/standards/R22-11/AP/AUTOSAR_RS_CPP14Guidelines.pdf>`_.

clang-tools-extra/docs/clang-tidy/checks/readability/avoid-nested-conditional-operator.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,3 @@ Examples:
1616
int NestInConditional = (condition1 ? true1 : false1) ? true2 : false2;
1717
int NestInTrue = condition1 ? (condition2 ? true1 : false1) : false2;
1818
int NestInFalse = condition1 ? true1 : condition2 ? true2 : false1;
19-
20-
This check implements part of `AUTOSAR C++14 Rule A5-16-1
21-
<https://www.autosar.org/fileadmin/standards/R22-11/AP/AUTOSAR_RS_CPP14Guidelines.pdf>`_.

clang/include/clang/AST/TypeLoc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,12 +951,20 @@ class HLSLAttributedResourceTypeLoc
951951
HLSLAttributedResourceLocInfo> {
952952
public:
953953
TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
954+
955+
TypeLoc getContainedLoc() const {
956+
return TypeLoc(getTypePtr()->getContainedType(), getNonLocalData());
957+
}
958+
954959
void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
955960
SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
956961
void initializeLocal(ASTContext &Context, SourceLocation loc) {
957962
setSourceRange(SourceRange());
958963
}
959964
QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
965+
unsigned getLocalDataSize() const {
966+
return sizeof(HLSLAttributedResourceLocInfo);
967+
}
960968
};
961969

962970
struct ObjCObjectTypeLocInfo {

clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LLVM_CLANG_ANALYSIS_ANALYSES_UNSAFEBUFFERUSAGE_H
1616

1717
#include "clang/AST/Decl.h"
18+
#include "clang/AST/Expr.h"
1819
#include "clang/AST/Stmt.h"
1920
#include "clang/Basic/SourceLocation.h"
2021
#include "llvm/Support/Debug.h"
@@ -106,6 +107,20 @@ class UnsafeBufferUsageHandler {
106107
virtual void handleUnsafeOperation(const Stmt *Operation,
107108
bool IsRelatedToDecl, ASTContext &Ctx) = 0;
108109

110+
/// Invoked when a call to an unsafe libc function is found.
111+
/// \param PrintfInfo
112+
/// is 0 if the callee function is not a member of the printf family;
113+
/// is 1 if the callee is `sprintf`;
114+
/// is 2 if arguments of the call have `__size_by` relation but are not in a
115+
/// safe pattern;
116+
/// is 3 if string arguments do not guarantee null-termination
117+
/// is 4 if the callee takes va_list
118+
/// \param UnsafeArg one of the actual arguments that is unsafe, non-null
119+
/// only when `2 <= PrintfInfo <= 3`
120+
virtual void handleUnsafeLibcCall(const CallExpr *Call, unsigned PrintfInfo,
121+
ASTContext &Ctx,
122+
const Expr *UnsafeArg = nullptr) = 0;
123+
109124
/// Invoked when an unsafe operation with a std container is found.
110125
virtual void handleUnsafeOperationInContainer(const Stmt *Operation,
111126
bool IsRelatedToDecl,
@@ -151,6 +166,10 @@ class UnsafeBufferUsageHandler {
151166
virtual bool
152167
ignoreUnsafeBufferInContainer(const SourceLocation &Loc) const = 0;
153168

169+
/// \return true iff unsafe libc call should NOT be reported at `Loc`
170+
virtual bool
171+
ignoreUnsafeBufferInLibcCall(const SourceLocation &Loc) const = 0;
172+
154173
virtual std::string
155174
getUnsafeBufferUsageAttributeTextAt(SourceLocation Loc,
156175
StringRef WSSuffix = "") const = 0;

clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
#define WARNING_GADGET(name) GADGET(name)
1919
#endif
2020

21-
/// A `WARNING_GADGET` subset, where the code pattern of each gadget
22-
/// corresponds uses of a (possibly hardened) contatiner (e.g., `std::span`).
23-
#ifndef WARNING_CONTAINER_GADGET
24-
#define WARNING_CONTAINER_GADGET(name) WARNING_GADGET(name)
21+
/// A `WARNING_GADGET` subset, each of which may be enable/disable separately
22+
/// with different flags
23+
#ifndef WARNING_OPTIONAL_GADGET
24+
#define WARNING_OPTIONAL_GADGET(name) WARNING_GADGET(name)
2525
#endif
2626

2727
/// Safe gadgets correspond to code patterns that aren't unsafe but need to be
@@ -38,7 +38,8 @@ WARNING_GADGET(PointerArithmetic)
3838
WARNING_GADGET(UnsafeBufferUsageAttr)
3939
WARNING_GADGET(UnsafeBufferUsageCtorAttr)
4040
WARNING_GADGET(DataInvocation)
41-
WARNING_CONTAINER_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, arg1)`
41+
WARNING_OPTIONAL_GADGET(UnsafeLibcFunctionCall)
42+
WARNING_OPTIONAL_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, arg1)`
4243
FIXABLE_GADGET(ULCArraySubscript) // `DRE[any]` in an Unspecified Lvalue Context
4344
FIXABLE_GADGET(DerefSimplePtrArithFixable)
4445
FIXABLE_GADGET(PointerDereference)
@@ -52,5 +53,5 @@ FIXABLE_GADGET(PointerInit)
5253

5354
#undef FIXABLE_GADGET
5455
#undef WARNING_GADGET
55-
#undef WARNING_CONTAINER_GADGET
56+
#undef WARNING_OPTIONAL_GADGET
5657
#undef GADGET

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4643,16 +4643,14 @@ def HLSLResource : InheritableAttr {
46434643
let Documentation = [InternalOnly];
46444644
}
46454645

4646-
def HLSLROV : InheritableAttr {
4646+
def HLSLROV : TypeAttr {
46474647
let Spellings = [CXX11<"hlsl", "is_rov">];
4648-
let Subjects = SubjectList<[Struct]>;
46494648
let LangOpts = [HLSL];
46504649
let Documentation = [InternalOnly];
46514650
}
46524651

4653-
def HLSLResourceClass : InheritableAttr {
4652+
def HLSLResourceClass : TypeAttr {
46544653
let Spellings = [CXX11<"hlsl", "resource_class">];
4655-
let Subjects = SubjectList<[Field]>;
46564654
let LangOpts = [HLSL];
46574655
let Args = [
46584656
EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ TARGET_BUILTIN(__builtin_amdgcn_s_barrier_join, "vi", "n", "gfx12-insts")
448448
TARGET_BUILTIN(__builtin_amdgcn_s_wakeup_barrier, "vi", "n", "gfx12-insts")
449449
TARGET_BUILTIN(__builtin_amdgcn_s_barrier_leave, "b", "n", "gfx12-insts")
450450
TARGET_BUILTIN(__builtin_amdgcn_s_get_barrier_state, "Uii", "n", "gfx12-insts")
451+
TARGET_BUILTIN(__builtin_amdgcn_s_prefetch_data, "vvC*Ui", "nc", "gfx12-insts")
451452

452453
TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_v2i32, "V2iV2i*1", "nc", "gfx12-insts,wavefrontsize32")
453454
TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8i16, "V8sV8s*1", "nc", "gfx12-insts,wavefrontsize32")

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,8 @@ def ReadOnlyPlacementChecks : DiagGroup<"read-only-types">;
15581558

15591559
// Warnings and fixes to support the "safe buffers" programming model.
15601560
def UnsafeBufferUsageInContainer : DiagGroup<"unsafe-buffer-usage-in-container">;
1561-
def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", [UnsafeBufferUsageInContainer]>;
1561+
def UnsafeBufferUsageInLibcCall : DiagGroup<"unsafe-buffer-usage-in-libc-call">;
1562+
def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", [UnsafeBufferUsageInContainer, UnsafeBufferUsageInLibcCall]>;
15621563

15631564
// Warnings and notes related to the function effects system underlying
15641565
// the nonblocking and nonallocating attributes.

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12368,6 +12368,7 @@ def err_hlsl_packoffset_cross_reg_boundary : Error<"packoffset cannot cross regi
1236812368
def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not match alignment %0 required by %1">;
1236912369
def err_hlsl_pointers_unsupported : Error<
1237012370
"%select{pointers|references}0 are unsupported in HLSL">;
12371+
def err_hlsl_missing_resource_class : Error<"HLSL resource needs to have [[hlsl::resource_class()]] attribute">;
1237112372

1237212373
def err_hlsl_operator_unsupported : Error<
1237312374
"the '%select{&|*|->}0' operator is unsupported in HLSL">;
@@ -12416,6 +12417,13 @@ def warn_unsafe_buffer_operation : Warning<
1241612417
"unsafe buffer access|function introduces unsafe buffer manipulation|unsafe invocation of span::data|"
1241712418
"field %1 prone to unsafe buffer manipulation}0">,
1241812419
InGroup<UnsafeBufferUsage>, DefaultIgnore;
12420+
def warn_unsafe_buffer_libc_call : Warning<
12421+
"function %0 is unsafe">,
12422+
InGroup<UnsafeBufferUsageInLibcCall>, DefaultIgnore;
12423+
def note_unsafe_buffer_printf_call : Note<
12424+
"%select{|change to 'snprintf' for explicit bounds checking | buffer pointer and size may not match"
12425+
"|string argument is not guaranteed to be null-terminated"
12426+
"|'va_list' is unsafe}0">;
1241912427
def note_unsafe_buffer_operation : Note<
1242012428
"used%select{| in pointer arithmetic| in buffer access}0 here">;
1242112429
def note_unsafe_buffer_variable_fixit_group : Note<

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
#include "clang/AST/ASTFwd.h"
1717
#include "clang/AST/Attr.h"
18+
#include "clang/AST/Type.h"
1819
#include "clang/Basic/SourceLocation.h"
1920
#include "clang/Sema/SemaBase.h"
21+
#include "llvm/ADT/SmallVector.h"
2022
#include "llvm/TargetParser/Triple.h"
2123
#include <initializer_list>
2224

@@ -26,6 +28,12 @@ class IdentifierInfo;
2628
class ParsedAttr;
2729
class Scope;
2830

31+
// FIXME: This can be hidden (as static function in SemaHLSL.cpp) once we no
32+
// longer need to create builtin buffer types in HLSLExternalSemaSource.
33+
bool CreateHLSLAttributedResourceType(Sema &S, QualType Wrapped,
34+
ArrayRef<const Attr *> AttrList,
35+
QualType &ResType);
36+
2937
class SemaHLSL : public SemaBase {
3038
public:
3139
SemaHLSL(Sema &S);
@@ -59,8 +67,6 @@ class SemaHLSL : public SemaBase {
5967
void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
6068
void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
6169
void handleShaderAttr(Decl *D, const ParsedAttr &AL);
62-
void handleROVAttr(Decl *D, const ParsedAttr &AL);
63-
void handleResourceClassAttr(Decl *D, const ParsedAttr &AL);
6470
void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL);
6571
void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
6672
bool handleResourceTypeAttr(const ParsedAttr &AL);
@@ -78,6 +84,16 @@ class SemaHLSL : public SemaBase {
7884
ExprResult ActOnOutParamExpr(ParmVarDecl *Param, Expr *Arg);
7985

8086
QualType getInoutParameterType(QualType Ty);
87+
88+
private:
89+
// HLSL resource type attributes need to be processed all at once.
90+
// This is a list to collect them.
91+
llvm::SmallVector<const Attr *> HLSLResourcesTypeAttrs;
92+
93+
/// SourceLocation corresponding to HLSLAttributedResourceTypeLocs that we
94+
/// have not yet populated.
95+
llvm::DenseMap<const HLSLAttributedResourceType *, SourceLocation>
96+
LocsForHLSLAttributedResources;
8197
};
8298

8399
} // namespace clang

clang/lib/AST/TypePrinter.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,10 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
19421942
case attr::BTFTypeTag:
19431943
llvm_unreachable("BTFTypeTag attribute handled separately");
19441944

1945+
case attr::HLSLResourceClass:
1946+
case attr::HLSLROV:
1947+
llvm_unreachable("HLSL resource type attributes handled separately");
1948+
19451949
case attr::OpenCLPrivateAddressSpace:
19461950
case attr::OpenCLGlobalAddressSpace:
19471951
case attr::OpenCLGlobalDeviceAddressSpace:
@@ -2062,7 +2066,11 @@ void TypePrinter::printBTFTagAttributedAfter(const BTFTagAttributedType *T,
20622066
void TypePrinter::printHLSLAttributedResourceBefore(
20632067
const HLSLAttributedResourceType *T, raw_ostream &OS) {
20642068
printBefore(T->getWrappedType(), OS);
2069+
}
20652070

2071+
void TypePrinter::printHLSLAttributedResourceAfter(
2072+
const HLSLAttributedResourceType *T, raw_ostream &OS) {
2073+
printAfter(T->getWrappedType(), OS);
20662074
const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
20672075
OS << " [[hlsl::resource_class("
20682076
<< HLSLResourceClassAttr::ConvertResourceClassToStr(Attrs.ResourceClass)
@@ -2071,11 +2079,6 @@ void TypePrinter::printHLSLAttributedResourceBefore(
20712079
OS << " [[hlsl::is_rov()]]";
20722080
}
20732081

2074-
void TypePrinter::printHLSLAttributedResourceAfter(
2075-
const HLSLAttributedResourceType *T, raw_ostream &OS) {
2076-
printAfter(T->getWrappedType(), OS);
2077-
}
2078-
20792082
void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T,
20802083
raw_ostream &OS) {
20812084
OS << T->getDecl()->getName();

0 commit comments

Comments
 (0)