Skip to content

Commit 31efa25

Browse files
committed
merge main into amd-staging
merged up to : bfb12ef [LLD][COFF] Allow additional attributes in Change-Id: Ic1f3f60185dae112675fd343fa52ebcc6b9411af
2 parents 2e4e9d5 + 421085f commit 31efa25

File tree

355 files changed

+7995
-4325
lines changed

Some content is hidden

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

355 files changed

+7995
-4325
lines changed

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
persist-credentials: false
3737

3838
- name: "Run analysis"
39-
uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # v2.1.2
39+
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
4040
with:
4141
results_file: results.sarif
4242
results_format: sarif

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ Bug Fixes to C++ Support
439439
- Fix a crash when instantiating a lambda that captures ``this`` outside of its context. Fixes (#GH85343).
440440
- Fix an issue where a namespace alias could be defined using a qualified name (all name components
441441
following the first `::` were ignored).
442+
- Fix an out-of-bounds crash when checking the validity of template partial specializations. (part of #GH86757).
442443

443444
Bug Fixes to AST Handling
444445
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/analyzer/checkers.rst

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,89 @@ Check for performance anti-patterns when using Grand Central Dispatch.
849849
850850
.. _optin-performance-Padding:
851851
852-
optin.performance.Padding
853-
"""""""""""""""""""""""""
852+
optin.performance.Padding (C, C++, ObjC)
853+
""""""""""""""""""""""""""""""""""""""""
854854
Check for excessively padded structs.
855855
856+
This checker detects structs with excessive padding, which can lead to wasted
857+
memory thus decreased performance by reducing the effectiveness of the
858+
processor cache. Padding bytes are added by compilers to align data accesses
859+
as some processors require data to be aligned to certain boundaries. On others,
860+
unaligned data access are possible, but impose significantly larger latencies.
861+
862+
To avoid padding bytes, the fields of a struct should be ordered by decreasing
863+
by alignment. Usually, its easier to think of the ``sizeof`` of the fields, and
864+
ordering the fields by ``sizeof`` would usually also lead to the same optimal
865+
layout.
866+
867+
In rare cases, one can use the ``#pragma pack(1)`` directive to enforce a packed
868+
layout too, but it can significantly increase the access times, so reordering the
869+
fields is usually a better solution.
870+
871+
872+
.. code-block:: cpp
873+
874+
// warn: Excessive padding in 'struct NonOptimal' (35 padding bytes, where 3 is optimal)
875+
struct NonOptimal {
876+
char c1;
877+
// 7 bytes of padding
878+
std::int64_t big1; // 8 bytes
879+
char c2;
880+
// 7 bytes of padding
881+
std::int64_t big2; // 8 bytes
882+
char c3;
883+
// 7 bytes of padding
884+
std::int64_t big3; // 8 bytes
885+
char c4;
886+
// 7 bytes of padding
887+
std::int64_t big4; // 8 bytes
888+
char c5;
889+
// 7 bytes of padding
890+
};
891+
static_assert(sizeof(NonOptimal) == 4*8+5+5*7);
892+
893+
// no-warning: The fields are nicely aligned to have the minimal amount of padding bytes.
894+
struct Optimal {
895+
std::int64_t big1; // 8 bytes
896+
std::int64_t big2; // 8 bytes
897+
std::int64_t big3; // 8 bytes
898+
std::int64_t big4; // 8 bytes
899+
char c1;
900+
char c2;
901+
char c3;
902+
char c4;
903+
char c5;
904+
// 3 bytes of padding
905+
};
906+
static_assert(sizeof(Optimal) == 4*8+5+3);
907+
908+
// no-warning: Bit packing representation is also accepted by this checker, but
909+
// it can significantly increase access times, so prefer reordering the fields.
910+
#pragma pack(1)
911+
struct BitPacked {
912+
char c1;
913+
std::int64_t big1; // 8 bytes
914+
char c2;
915+
std::int64_t big2; // 8 bytes
916+
char c3;
917+
std::int64_t big3; // 8 bytes
918+
char c4;
919+
std::int64_t big4; // 8 bytes
920+
char c5;
921+
};
922+
static_assert(sizeof(BitPacked) == 4*8+5);
923+
924+
The ``AllowedPad`` option can be used to specify a threshold for the number
925+
padding bytes raising the warning. If the number of padding bytes of the struct
926+
and the optimal number of padding bytes differ by more than the threshold value,
927+
a warning will be raised.
928+
929+
By default, the ``AllowedPad`` threshold is 24 bytes.
930+
931+
To override this threshold to e.g. 4 bytes, use the
932+
``-analyzer-config optin.performance.Padding:AllowedPad=4`` option.
933+
934+
856935
.. _optin-portability-UnixAPI:
857936
858937
optin.portability.UnixAPI

clang/include/clang-c/Index.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,6 +2991,7 @@ enum CXCallingConv {
29912991
CXCallingConv_AArch64SVEPCS = 18,
29922992
CXCallingConv_M68kRTD = 19,
29932993
CXCallingConv_PreserveNone = 20,
2994+
CXCallingConv_RISCVVectorCall = 21,
29942995

29952996
CXCallingConv_Invalid = 100,
29962997
CXCallingConv_Unexposed = 200

clang/include/clang/Basic/Attr.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,6 +3011,13 @@ def PreserveNone : DeclOrTypeAttr, TargetSpecificAttr<TargetAnyX86> {
30113011
let Documentation = [PreserveNoneDocs];
30123012
}
30133013

3014+
def RISCVVectorCC: DeclOrTypeAttr, TargetSpecificAttr<TargetRISCV> {
3015+
let Spellings = [CXX11<"riscv", "vector_cc">,
3016+
C23<"riscv", "vector_cc">,
3017+
Clang<"riscv_vector_cc">];
3018+
let Documentation = [RISCVVectorCCDocs];
3019+
}
3020+
30143021
def Target : InheritableAttr {
30153022
let Spellings = [GCC<"target">];
30163023
let Args = [StringArgument<"featuresStr">];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5494,6 +5494,17 @@ for clang builtin functions.
54945494
}];
54955495
}
54965496

5497+
def RISCVVectorCCDocs : Documentation {
5498+
let Category = DocCatCallingConvs;
5499+
let Heading = "riscv::vector_cc, riscv_vector_cc, clang::riscv_vector_cc";
5500+
let Content = [{
5501+
The ``riscv_vector_cc`` attribute can be applied to a function. It preserves 15
5502+
registers namely, v1-v7 and v24-v31 as callee-saved. Callers thus don't need
5503+
to save these registers before function calls, and callees only need to save
5504+
them if they use them.
5505+
}];
5506+
}
5507+
54975508
def PreferredNameDocs : Documentation {
54985509
let Category = DocCatDecl;
54995510
let Content = [{

clang/include/clang/Basic/DiagnosticInstallAPIKinds.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def err_no_output_file: Error<"no output file specified">;
1818
def err_no_such_header_file : Error<"no such %select{public|private|project}1 header file: '%0'">;
1919
def warn_no_such_excluded_header_file : Warning<"no such excluded %select{public|private}0 header file: '%1'">, InGroup<InstallAPIViolation>;
2020
def warn_glob_did_not_match: Warning<"glob '%0' did not match any header file">, InGroup<InstallAPIViolation>;
21+
def err_no_such_umbrella_header_file : Error<"%select{public|private|project}1 umbrella header file not found in input: '%0'">;
2122
} // end of command line category.
2223

2324
let CategoryName = "Verification" in {

clang/include/clang/Basic/Specifiers.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -273,29 +273,30 @@ namespace clang {
273273

274274
/// CallingConv - Specifies the calling convention that a function uses.
275275
enum CallingConv {
276-
CC_C, // __attribute__((cdecl))
277-
CC_X86StdCall, // __attribute__((stdcall))
278-
CC_X86FastCall, // __attribute__((fastcall))
279-
CC_X86ThisCall, // __attribute__((thiscall))
280-
CC_X86VectorCall, // __attribute__((vectorcall))
281-
CC_X86Pascal, // __attribute__((pascal))
282-
CC_Win64, // __attribute__((ms_abi))
283-
CC_X86_64SysV, // __attribute__((sysv_abi))
284-
CC_X86RegCall, // __attribute__((regcall))
285-
CC_AAPCS, // __attribute__((pcs("aapcs")))
286-
CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp")))
287-
CC_IntelOclBicc, // __attribute__((intel_ocl_bicc))
288-
CC_SpirFunction, // default for OpenCL functions on SPIR target
289-
CC_OpenCLKernel, // inferred for OpenCL kernels
290-
CC_Swift, // __attribute__((swiftcall))
276+
CC_C, // __attribute__((cdecl))
277+
CC_X86StdCall, // __attribute__((stdcall))
278+
CC_X86FastCall, // __attribute__((fastcall))
279+
CC_X86ThisCall, // __attribute__((thiscall))
280+
CC_X86VectorCall, // __attribute__((vectorcall))
281+
CC_X86Pascal, // __attribute__((pascal))
282+
CC_Win64, // __attribute__((ms_abi))
283+
CC_X86_64SysV, // __attribute__((sysv_abi))
284+
CC_X86RegCall, // __attribute__((regcall))
285+
CC_AAPCS, // __attribute__((pcs("aapcs")))
286+
CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp")))
287+
CC_IntelOclBicc, // __attribute__((intel_ocl_bicc))
288+
CC_SpirFunction, // default for OpenCL functions on SPIR target
289+
CC_OpenCLKernel, // inferred for OpenCL kernels
290+
CC_Swift, // __attribute__((swiftcall))
291291
CC_SwiftAsync, // __attribute__((swiftasynccall))
292-
CC_PreserveMost, // __attribute__((preserve_most))
293-
CC_PreserveAll, // __attribute__((preserve_all))
292+
CC_PreserveMost, // __attribute__((preserve_most))
293+
CC_PreserveAll, // __attribute__((preserve_all))
294294
CC_AArch64VectorCall, // __attribute__((aarch64_vector_pcs))
295-
CC_AArch64SVEPCS, // __attribute__((aarch64_sve_pcs))
296-
CC_AMDGPUKernelCall, // __attribute__((amdgpu_kernel))
297-
CC_M68kRTD, // __attribute__((m68k_rtd))
298-
CC_PreserveNone, // __attribute__((preserve_none))
295+
CC_AArch64SVEPCS, // __attribute__((aarch64_sve_pcs))
296+
CC_AMDGPUKernelCall, // __attribute__((amdgpu_kernel))
297+
CC_M68kRTD, // __attribute__((m68k_rtd))
298+
CC_PreserveNone, // __attribute__((preserve_none))
299+
CC_RISCVVectorCall, // __attribute__((riscv_vector_cc))
299300
};
300301

301302
/// Checks whether the given calling convention supports variadic

clang/include/clang/InstallAPI/HeaderFile.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
namespace clang::installapi {
2626
enum class HeaderType {
27-
/// Unset or unknown type.
28-
Unknown,
2927
/// Represents declarations accessible to all clients.
3028
Public,
3129
/// Represents declarations accessible to a disclosed set of clients.
3230
Private,
3331
/// Represents declarations only accessible as implementation details to the
3432
/// input library.
3533
Project,
34+
/// Unset or unknown type.
35+
Unknown,
3636
};
3737

3838
inline StringRef getName(const HeaderType T) {
@@ -62,6 +62,8 @@ class HeaderFile {
6262
bool Excluded{false};
6363
/// Add header file to processing.
6464
bool Extra{false};
65+
/// Specify that header file is the umbrella header for library.
66+
bool Umbrella{false};
6567

6668
public:
6769
HeaderFile() = delete;
@@ -79,17 +81,21 @@ class HeaderFile {
7981

8082
void setExtra(bool V = true) { Extra = V; }
8183
void setExcluded(bool V = true) { Excluded = V; }
84+
void setUmbrellaHeader(bool V = true) { Umbrella = V; }
8285
bool isExtra() const { return Extra; }
8386
bool isExcluded() const { return Excluded; }
87+
bool isUmbrellaHeader() const { return Umbrella; }
8488

8589
bool useIncludeName() const {
8690
return Type != HeaderType::Project && !IncludeName.empty();
8791
}
8892

8993
bool operator==(const HeaderFile &Other) const {
90-
return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra) ==
91-
std::tie(Other.Type, Other.FullPath, Other.IncludeName,
92-
Other.Language, Other.Excluded, Other.Extra);
94+
return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra,
95+
Umbrella) == std::tie(Other.Type, Other.FullPath,
96+
Other.IncludeName, Other.Language,
97+
Other.Excluded, Other.Extra,
98+
Other.Umbrella);
9399
}
94100
};
95101

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,8 @@ class Sema final {
22342234
bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
22352235
bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
22362236
CallExpr *TheCall);
2237-
void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D);
2237+
void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D,
2238+
const llvm::StringMap<bool> &FeatureMap);
22382239
bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI,
22392240
unsigned BuiltinID, CallExpr *TheCall);
22402241
bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI,

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ def PaddingChecker : Checker<"Padding">,
908908
"24",
909909
Released>
910910
]>,
911-
Documentation<NotDocumented>;
911+
Documentation<HasDocumentation>;
912912

913913
} // end: "padding"
914914

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,6 +3445,7 @@ StringRef CXXNameMangler::getCallingConvQualifierName(CallingConv CC) {
34453445
case CC_PreserveAll:
34463446
case CC_M68kRTD:
34473447
case CC_PreserveNone:
3448+
case CC_RISCVVectorCall:
34483449
// FIXME: we should be mangling all of the above.
34493450
return "";
34503451

clang/lib/AST/Type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3484,6 +3484,9 @@ StringRef FunctionType::getNameForCallConv(CallingConv CC) {
34843484
case CC_PreserveAll: return "preserve_all";
34853485
case CC_M68kRTD: return "m68k_rtd";
34863486
case CC_PreserveNone: return "preserve_none";
3487+
// clang-format off
3488+
case CC_RISCVVectorCall: return "riscv_vector_cc";
3489+
// clang-format on
34873490
}
34883491

34893492
llvm_unreachable("Invalid calling convention.");
@@ -4074,6 +4077,7 @@ bool AttributedType::isCallingConv() const {
40744077
case attr::PreserveAll:
40754078
case attr::M68kRTD:
40764079
case attr::PreserveNone:
4080+
case attr::RISCVVectorCC:
40774081
return true;
40784082
}
40794083
llvm_unreachable("invalid attr kind");

clang/lib/AST/TypePrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,9 @@ void TypePrinter::printFunctionAfter(const FunctionType::ExtInfo &Info,
10711071
case CC_PreserveNone:
10721072
OS << " __attribute__((preserve_none))";
10731073
break;
1074+
case CC_RISCVVectorCall:
1075+
OS << "__attribute__((riscv_vector_cc))";
1076+
break;
10741077
}
10751078
}
10761079

@@ -1960,6 +1963,9 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
19601963
case attr::PreserveNone:
19611964
OS << "preserve_none";
19621965
break;
1966+
case attr::RISCVVectorCC:
1967+
OS << "riscv_vector_cc";
1968+
break;
19631969
case attr::NoDeref:
19641970
OS << "noderef";
19651971
break;

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,14 @@ ParsedTargetAttr RISCVTargetInfo::parseTargetAttr(StringRef Features) const {
467467
}
468468
return Ret;
469469
}
470+
471+
TargetInfo::CallingConvCheckResult
472+
RISCVTargetInfo::checkCallingConvention(CallingConv CC) const {
473+
switch (CC) {
474+
default:
475+
return CCCR_Warning;
476+
case CC_C:
477+
case CC_RISCVVectorCall:
478+
return CCCR_OK;
479+
}
480+
}

clang/lib/Basic/Targets/RISCV.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class RISCVTargetInfo : public TargetInfo {
110110

111111
bool hasBFloat16Type() const override { return true; }
112112

113+
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
114+
113115
bool useFP16ConversionIntrinsics() const override {
114116
return false;
115117
}

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,8 @@ EncompassingIntegerType(ArrayRef<struct WidthAndSignedness> Types) {
792792

793793
Value *CodeGenFunction::EmitVAStartEnd(Value *ArgValue, bool IsStart) {
794794
Intrinsic::ID inst = IsStart ? Intrinsic::vastart : Intrinsic::vaend;
795-
return Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue);
795+
return Builder.CreateCall(CGM.getIntrinsic(inst, {ArgValue->getType()}),
796+
ArgValue);
796797
}
797798

798799
/// Checks if using the result of __builtin_object_size(p, @p From) in place of
@@ -3018,7 +3019,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
30183019
case Builtin::BI__builtin_va_copy: {
30193020
Value *DstPtr = EmitVAListRef(E->getArg(0)).getPointer();
30203021
Value *SrcPtr = EmitVAListRef(E->getArg(1)).getPointer();
3021-
Builder.CreateCall(CGM.getIntrinsic(Intrinsic::vacopy), {DstPtr, SrcPtr});
3022+
Builder.CreateCall(CGM.getIntrinsic(Intrinsic::vacopy, {DstPtr->getType()}),
3023+
{DstPtr, SrcPtr});
30223024
return RValue::get(nullptr);
30233025
}
30243026
case Builtin::BIabs:

clang/lib/CodeGen/CGCall.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ unsigned CodeGenTypes::ClangCallConvToLLVMCallConv(CallingConv CC) {
7474
case CC_SwiftAsync: return llvm::CallingConv::SwiftTail;
7575
case CC_M68kRTD: return llvm::CallingConv::M68k_RTD;
7676
case CC_PreserveNone: return llvm::CallingConv::PreserveNone;
77+
// clang-format off
78+
case CC_RISCVVectorCall: return llvm::CallingConv::RISCV_VectorCall;
79+
// clang-format on
7780
}
7881
}
7982

@@ -260,6 +263,9 @@ static CallingConv getCallingConventionForDecl(const ObjCMethodDecl *D,
260263
if (D->hasAttr<PreserveNoneAttr>())
261264
return CC_PreserveNone;
262265

266+
if (D->hasAttr<RISCVVectorCCAttr>())
267+
return CC_RISCVVectorCall;
268+
263269
return CC_C;
264270
}
265271

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,8 @@ static unsigned getDwarfCC(CallingConv CC) {
15031503
return llvm::dwarf::DW_CC_LLVM_M68kRTD;
15041504
case CC_PreserveNone:
15051505
return llvm::dwarf::DW_CC_LLVM_PreserveNone;
1506+
case CC_RISCVVectorCall:
1507+
return llvm::dwarf::DW_CC_LLVM_RISCVVectorCall;
15061508
}
15071509
return 0;
15081510
}

0 commit comments

Comments
 (0)