Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit db8fc31

Browse files
committed
Merge "merge main into amd-stg-open" into amd-stg-open
2 parents 72380ff + 7ba7130 commit db8fc31

File tree

334 files changed

+8490
-3691
lines changed

Some content is hidden

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

334 files changed

+8490
-3691
lines changed

clang-tools-extra/clangd/IncludeCleaner.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ class ReferencedLocationCrawler
8080
return true;
8181
}
8282

83+
// Enums may be usefully forward-declared as *complete* types by specifying
84+
// an underlying type. In this case, the definition should see the declaration
85+
// so they can be checked for compatibility.
86+
bool VisitEnumDecl(EnumDecl *D) {
87+
if (D->isThisDeclarationADefinition() && D->getIntegerTypeSourceInfo())
88+
add(D);
89+
return false;
90+
}
91+
8392
private:
8493
using Base = RecursiveASTVisitor<ReferencedLocationCrawler>;
8594

clang-tools-extra/clangd/Preamble.cpp

+19-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "Preamble.h"
1010
#include "Compiler.h"
11+
#include "Config.h"
1112
#include "Headers.h"
1213
#include "SourceCode.h"
1314
#include "support/Logger.h"
@@ -347,20 +348,24 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
347348
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> PreambleDiagsEngine =
348349
CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(),
349350
&PreambleDiagnostics, false);
350-
PreambleDiagnostics.setLevelAdjuster(
351-
[&](DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) {
352-
switch (Info.getID()) {
353-
case diag::warn_no_newline_eof:
354-
case diag::warn_cxx98_compat_no_newline_eof:
355-
case diag::ext_no_newline_eof:
356-
// If the preamble doesn't span the whole file, drop the no newline at
357-
// eof warnings.
358-
return Bounds.Size != ContentsBuffer->getBufferSize()
359-
? DiagnosticsEngine::Level::Ignored
360-
: DiagLevel;
361-
}
362-
return DiagLevel;
363-
});
351+
const Config &Cfg = Config::current();
352+
PreambleDiagnostics.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel,
353+
const clang::Diagnostic &Info) {
354+
if (Cfg.Diagnostics.SuppressAll ||
355+
isBuiltinDiagnosticSuppressed(Info.getID(), Cfg.Diagnostics.Suppress))
356+
return DiagnosticsEngine::Ignored;
357+
switch (Info.getID()) {
358+
case diag::warn_no_newline_eof:
359+
case diag::warn_cxx98_compat_no_newline_eof:
360+
case diag::ext_no_newline_eof:
361+
// If the preamble doesn't span the whole file, drop the no newline at
362+
// eof warnings.
363+
return Bounds.Size != ContentsBuffer->getBufferSize()
364+
? DiagnosticsEngine::Level::Ignored
365+
: DiagLevel;
366+
}
367+
return DiagLevel;
368+
});
364369

365370
// Skip function bodies when building the preamble to speed up building
366371
// the preamble and make it smaller.

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,21 @@ TEST(DiagnosticTest, RespectsDiagnosticConfig) {
444444
"use of undeclared identifier 'unknown'")));
445445
}
446446

447+
TEST(DiagnosticTest, RespectsDiagnosticConfigInHeader) {
448+
Annotations Header(R"cpp(
449+
int x = "42"; // error-ok
450+
)cpp");
451+
Annotations Main(R"cpp(
452+
#include "header.hpp"
453+
)cpp");
454+
auto TU = TestTU::withCode(Main.code());
455+
TU.AdditionalFiles["header.hpp"] = std::string(Header.code());
456+
Config Cfg;
457+
Cfg.Diagnostics.Suppress.insert("init_conversion_failed");
458+
WithContextValue WithCfg(Config::Key, std::move(Cfg));
459+
EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
460+
}
461+
447462
TEST(DiagnosticTest, ClangTidySuppressionComment) {
448463
Annotations Main(R"cpp(
449464
int main() {

clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,30 @@ TEST(IncludeCleaner, ReferencedLocations) {
103103
"struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
104104
"int Lang = X::CXX;",
105105
},
106+
{
107+
"enum class ^Color : int;",
108+
"enum class Color : int {};",
109+
},
110+
{
111+
"enum class Color : int {};",
112+
"enum class Color : int;",
113+
},
114+
{
115+
"enum class ^Color;",
116+
"Color c;",
117+
},
118+
{
119+
"enum class ^Color : int;",
120+
"Color c;",
121+
},
122+
{
123+
"enum class ^Color : char;",
124+
"Color *c;",
125+
},
126+
{
127+
"enum class ^Color : char {};",
128+
"Color *c;",
129+
},
106130
{
107131
// When a type is resolved via a using declaration, the
108132
// UsingShadowDecl is not referenced in the AST.

clang-tools-extra/clangd/unittests/SelectionTests.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,19 @@ TEST(SelectionTest, CommonAncestor) {
473473
[[@property(retain, nonnull) <:[My^Object2]:> *x]]; // error-ok
474474
@end
475475
)cpp",
476-
"ObjCPropertyDecl"}};
476+
"ObjCPropertyDecl"},
477+
478+
{R"cpp(
479+
typedef int Foo;
480+
enum Bar : [[Fo^o]] {};
481+
)cpp",
482+
"TypedefTypeLoc"},
483+
{R"cpp(
484+
typedef int Foo;
485+
enum Bar : [[Fo^o]];
486+
)cpp",
487+
"TypedefTypeLoc"},
488+
};
477489

478490
for (const Case &C : Cases) {
479491
trace::TestTracer Tracer;

clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,16 @@ sizeof...($TemplateParameter[[Elements]]);
780780
$LocalVariable_decl[[d]]($LocalVariable[[b]]) ]() {}();
781781
}
782782
)cpp",
783+
// Enum base specifier
784+
R"cpp(
785+
using $Primitive_decl[[MyTypedef]] = int;
786+
enum $Enum_decl[[MyEnum]] : $Primitive[[MyTypedef]] {};
787+
)cpp",
788+
// Enum base specifier
789+
R"cpp(
790+
typedef int $Primitive_decl[[MyTypedef]];
791+
enum $Enum_decl[[MyEnum]] : $Primitive[[MyTypedef]] {};
792+
)cpp",
783793
};
784794
for (const auto &TestCase : TestCases)
785795
// Mask off scope modifiers to keep the tests manageable.

clang-tools-extra/clangd/unittests/XRefsTests.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,19 @@ TEST(LocateSymbol, All) {
880880
};
881881
)cpp",
882882

883+
R"cpp(// Enum base
884+
typedef int $decl[[MyTypeDef]];
885+
enum Foo : My^TypeDef {};
886+
)cpp",
887+
R"cpp(// Enum base
888+
typedef int $decl[[MyTypeDef]];
889+
enum Foo : My^TypeDef;
890+
)cpp",
891+
R"cpp(// Enum base
892+
using $decl[[MyTypeDef]] = int;
893+
enum Foo : My^TypeDef {};
894+
)cpp",
895+
883896
R"objc(
884897
@protocol Dog;
885898
@protocol $decl[[Dog]]
@@ -1953,6 +1966,20 @@ TEST(FindReferences, WithinAST) {
19531966
[[f^oo]](s);
19541967
}
19551968
)cpp",
1969+
1970+
// Enum base
1971+
R"cpp(
1972+
typedef int $def[[MyTypeD^ef]];
1973+
enum MyEnum : [[MyTy^peDef]] { };
1974+
)cpp",
1975+
R"cpp(
1976+
typedef int $def[[MyType^Def]];
1977+
enum MyEnum : [[MyTypeD^ef]];
1978+
)cpp",
1979+
R"cpp(
1980+
using $def[[MyTypeD^ef]] = int;
1981+
enum MyEnum : [[MyTy^peDef]] { };
1982+
)cpp",
19561983
};
19571984
for (const char *Test : Tests)
19581985
checkFindRefs(Test);

clang/include/clang/AST/Decl.h

+4
Original file line numberDiff line numberDiff line change
@@ -3701,6 +3701,10 @@ class EnumDecl : public TagDecl {
37013701
bool IsFixed);
37023702
static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
37033703

3704+
/// Overrides to provide correct range when there's an enum-base specifier
3705+
/// with forward declarations.
3706+
SourceRange getSourceRange() const override LLVM_READONLY;
3707+
37043708
/// When created, the EnumDecl corresponds to a
37053709
/// forward-declared enum. This method is used to mark the
37063710
/// declaration as being defined; its enumerators have already been

clang/include/clang/AST/RecursiveASTVisitor.h

+2
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,8 @@ DEF_TRAVERSE_DECL(EnumDecl, {
18671867
TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
18681868

18691869
TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1870+
if (auto *TSI = D->getIntegerTypeSourceInfo())
1871+
TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
18701872
// The enumerators are already traversed by
18711873
// decls_begin()/decls_end().
18721874
})

clang/include/clang/Basic/Attr.td

+4-1
Original file line numberDiff line numberDiff line change
@@ -3692,7 +3692,10 @@ def OMPDeclareVariant : InheritableAttr {
36923692
ExprArgument<"VariantFuncRef">,
36933693
OMPTraitInfoArgument<"TraitInfos">,
36943694
VariadicExprArgument<"AdjustArgsNothing">,
3695-
VariadicExprArgument<"AdjustArgsNeedDevicePtr">
3695+
VariadicExprArgument<"AdjustArgsNeedDevicePtr">,
3696+
VariadicEnumArgument<"AppendArgs", "InteropType",
3697+
["target", "targetsync", "target,targetsync"],
3698+
["Target", "TargetSync", "Target_TargetSync"]>
36963699
];
36973700
let AdditionalMembers = [{
36983701
OMPTraitInfo &getTraitInfo() { return *traitInfos; }

clang/include/clang/Basic/DiagnosticParseKinds.td

+4-2
Original file line numberDiff line numberDiff line change
@@ -1359,9 +1359,11 @@ def err_omp_mapper_illegal_identifier : Error<
13591359
"illegal OpenMP user-defined mapper identifier">;
13601360
def err_omp_mapper_expected_declarator : Error<
13611361
"expected declarator on 'omp declare mapper' directive">;
1362+
def err_omp_unexpected_append_op : Error<
1363+
"unexpected operation specified in 'append_args' clause, expected 'interop'">;
13621364
def err_omp_declare_variant_wrong_clause : Error<
1363-
"expected %select{'match'|'match' or 'adjust_args'}0 clause on "
1364-
"'omp declare variant' directive">;
1365+
"expected %select{'match'|'match', 'adjust_args', or 'append_args'}0 clause "
1366+
"on 'omp declare variant' directive">;
13651367
def err_omp_declare_variant_duplicate_nested_trait : Error<
13661368
"nested OpenMP context selector contains duplicated trait '%0'"
13671369
" in selector '%1' and set '%2' with different score">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

+9-2
Original file line numberDiff line numberDiff line change
@@ -10738,9 +10738,14 @@ def err_omp_declare_variant_diff : Error<
1073810738
"function with '#pragma omp declare variant' has a different %select{calling convention"
1073910739
"|return type|constexpr specification|inline specification|storage class|"
1074010740
"linkage}0">;
10741+
def err_omp_declare_variant_prototype_required : Error<
10742+
"function with '#pragma omp declare variant' must have a prototype when "
10743+
"'append_args' is used">;
10744+
def err_omp_interop_type_not_found : Error<
10745+
"'omp_interop_t' must be defined when 'append_args' clause is used; include <omp.h>">;
1074110746
def err_omp_declare_variant_incompat_types : Error<
10742-
"variant in '#pragma omp declare variant' with type %0 is incompatible with type %1"
10743-
>;
10747+
"variant in '#pragma omp declare variant' with type %0 is incompatible with"
10748+
" type %1%select{| with appended arguments}2">;
1074410749
def warn_omp_declare_variant_marked_as_declare_variant : Warning<
1074510750
"variant function in '#pragma omp declare variant' is itself marked as '#pragma omp declare variant'"
1074610751
>, InGroup<SourceUsesOpenMP>;
@@ -10809,6 +10814,8 @@ def err_omp_adjust_arg_multiple_clauses : Error<
1080910814
"'adjust_arg' argument %0 used in multiple clauses">;
1081010815
def err_omp_clause_requires_dispatch_construct : Error<
1081110816
"'%0' clause requires 'dispatch' context selector">;
10817+
def err_omp_append_args_with_varargs : Error<
10818+
"'append_args' is not allowed with varargs functions">;
1081210819
} // end of OpenMP category
1081310820

1081410821
let CategoryName = "Related Result Type Issue" in {

clang/include/clang/Basic/LangOptions.def

+2-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ LANGOPT(SpeculativeLoadHardening, 1, 0, "Speculative load hardening enabled")
425425
LANGOPT(RelativeCXXABIVTables, 1, 0,
426426
"Use an ABI-incompatible v-table layout that uses relative references")
427427

428-
LANGOPT(ArmSveVectorBits, 32, 0, "SVE vector size in bits")
428+
LANGOPT(VScaleMin, 32, 0, "Minimum vscale value")
429+
LANGOPT(VScaleMax, 32, 0, "Maximum vscale value")
429430

430431
ENUM_LANGOPT(ExtendIntArgs, ExtendArgsKind, 1, ExtendArgsKind::ExtendTo32,
431432
"Controls how scalar integer arguments are extended in calls "

clang/include/clang/Basic/riscv_vector.td

+13-3
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ let HasMask = false, HasPolicy = false,
18381838
std::rotate(Ops.begin(), Ops.begin() + 1, Ops.begin() + 3);
18391839
IntrinsicTypes = {ResultType, Ops[1]->getType(), Ops[3]->getType()};
18401840
}] in {
1841-
defm vmerge : RVVOutOp1BuiltinSet<"vfmerge", "xfd",
1841+
defm vmerge : RVVOutOp1BuiltinSet<"vmerge", "xfd",
18421842
[["vvm", "v", "vmvv"]]>;
18431843
defm vfmerge : RVVOutOp1BuiltinSet<"vfmerge", "xfd",
18441844
[["vfm", "v", "vmve"]]>;
@@ -2098,7 +2098,12 @@ let HasMask = false, HasVL = false, IRName = "" in {
20982098
ManualCodegen = [{
20992099
{
21002100
ID = Intrinsic::experimental_vector_extract;
2101-
ScalableVectorType *VecTy = cast<ScalableVectorType>(ResultType);
2101+
auto *VecTy = cast<ScalableVectorType>(ResultType);
2102+
auto *OpVecTy = cast<ScalableVectorType>(Ops[0]->getType());
2103+
// Mask to only valid indices.
2104+
unsigned MaxIndex = OpVecTy->getMinNumElements() / VecTy->getMinNumElements();
2105+
assert(isPowerOf2_32(MaxIndex));
2106+
Ops[1] = Builder.CreateAnd(Ops[1], MaxIndex - 1);
21022107
Ops[1] = Builder.CreateMul(Ops[1],
21032108
ConstantInt::get(Ops[1]->getType(),
21042109
VecTy->getMinNumElements()));
@@ -2117,7 +2122,12 @@ let HasMask = false, HasVL = false, IRName = "" in {
21172122
{
21182123
ID = Intrinsic::experimental_vector_insert;
21192124
IntrinsicTypes = {ResultType, Ops[2]->getType()};
2120-
ScalableVectorType *VecTy = cast<ScalableVectorType>(Ops[2]->getType());
2125+
auto *ResVecTy = cast<ScalableVectorType>(ResultType);
2126+
auto *VecTy = cast<ScalableVectorType>(Ops[2]->getType());
2127+
// Mask to only valid indices.
2128+
unsigned MaxIndex = ResVecTy->getMinNumElements() / VecTy->getMinNumElements();
2129+
assert(isPowerOf2_32(MaxIndex));
2130+
Ops[1] = Builder.CreateAnd(Ops[1], MaxIndex - 1);
21212131
Ops[1] = Builder.CreateMul(Ops[1],
21222132
ConstantInt::get(Ops[1]->getType(),
21232133
VecTy->getMinNumElements()));

clang/include/clang/Driver/Options.td

+13-6
Original file line numberDiff line numberDiff line change
@@ -3342,13 +3342,20 @@ foreach i = {8-15,18} in
33423342
def fcall_saved_x#i : Flag<["-"], "fcall-saved-x"#i>, Group<m_aarch64_Features_Group>,
33433343
HelpText<"Make the x"#i#" register call-saved (AArch64 only)">;
33443344

3345-
def msve_vector_bits_EQ : Joined<["-"], "msve-vector-bits=">,
3346-
Group<m_aarch64_Features_Group>, Flags<[NoXarchOption,CC1Option]>,
3345+
def msve_vector_bits_EQ : Joined<["-"], "msve-vector-bits=">, Group<m_aarch64_Features_Group>,
33473346
HelpText<"Specify the size in bits of an SVE vector register. Defaults to the"
3348-
" vector length agnostic value of \"scalable\". (AArch64 only)">,
3349-
Values<"128,256,512,1024,2048,scalable">,
3350-
NormalizedValues<["128", "256", "512", "1024", "2048", "0"]>,
3351-
MarshallingInfoEnum<LangOpts<"ArmSveVectorBits">, "0">;
3347+
" vector length agnostic value of \"scalable\". (AArch64 only)">;
3348+
3349+
def mvscale_min_EQ : Joined<["-"], "mvscale-min=">,
3350+
Group<m_aarch64_Features_Group>, Flags<[NoXarchOption,CC1Option]>,
3351+
HelpText<"Specify the vscale minimum. Defaults to the"
3352+
" vector length agnostic value of \"0\". (AArch64 only)">,
3353+
MarshallingInfoInt<LangOpts<"VScaleMin">>;
3354+
def mvscale_max_EQ : Joined<["-"], "mvscale-max=">,
3355+
Group<m_aarch64_Features_Group>, Flags<[NoXarchOption,CC1Option]>,
3356+
HelpText<"Specify the vscale maximum. Defaults to the"
3357+
" vector length agnostic value of \"0\". (AArch64 only)">,
3358+
MarshallingInfoInt<LangOpts<"VScaleMax">>;
33523359

33533360
def msign_return_address_EQ : Joined<["-"], "msign-return-address=">,
33543361
Flags<[CC1Option]>, Group<m_Group>, Values<"none,all,non-leaf">,

clang/include/clang/Parse/Parser.h

+4
Original file line numberDiff line numberDiff line change
@@ -3205,6 +3205,10 @@ class Parser : public CodeCompletionHandler {
32053205
/// Parses OpenMP context selectors.
32063206
bool parseOMPContextSelectors(SourceLocation Loc, OMPTraitInfo &TI);
32073207

3208+
/// Parse an 'append_args' clause for '#pragma omp declare variant'.
3209+
bool parseOpenMPAppendArgs(
3210+
SmallVectorImpl<OMPDeclareVariantAttr::InteropType> &InterOpTypes);
3211+
32083212
/// Parse a `match` clause for an '#pragma omp declare variant'. Return true
32093213
/// if there was an error.
32103214
bool parseOMPDeclareVariantMatchClause(SourceLocation Loc, OMPTraitInfo &TI,

clang/include/clang/Sema/Sema.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -10964,11 +10964,14 @@ class Sema final {
1096410964
/// \param VariantRef Expression that references the variant function, which
1096510965
/// must be used instead of the original one, specified in \p DG.
1096610966
/// \param TI The trait info object representing the match clause.
10967+
/// \param NumAppendArgs The number of omp_interop_t arguments to account for
10968+
/// in checking.
1096710969
/// \returns None, if the function/variant function are not compatible with
1096810970
/// the pragma, pair of original function/variant ref expression otherwise.
1096910971
Optional<std::pair<FunctionDecl *, Expr *>>
1097010972
checkOpenMPDeclareVariantFunction(DeclGroupPtrTy DG, Expr *VariantRef,
10971-
OMPTraitInfo &TI, SourceRange SR);
10973+
OMPTraitInfo &TI, unsigned NumAppendArgs,
10974+
SourceRange SR);
1097210975

1097310976
/// Called on well-formed '\#pragma omp declare variant' after parsing of
1097410977
/// the associated method/function.
@@ -10977,10 +10980,19 @@ class Sema final {
1097710980
/// \param VariantRef Expression that references the variant function, which
1097810981
/// must be used instead of the original one, specified in \p DG.
1097910982
/// \param TI The context traits associated with the function variant.
10983+
/// \param AdjustArgsNothing The list of 'nothing' arguments.
10984+
/// \param AdjustArgsNeedDevicePtr The list of 'need_device_ptr' arguments.
10985+
/// \param AppendArgs The list of 'append_args' arguments.
10986+
/// \param AdjustArgsLoc The Location of an 'adjust_args' clause.
10987+
/// \param AppendArgsLoc The Location of an 'append_args' clause.
10988+
/// \param SR The SourceRange of the 'declare variant' directive.
1098010989
void ActOnOpenMPDeclareVariantDirective(
1098110990
FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI,
1098210991
ArrayRef<Expr *> AdjustArgsNothing,
10983-
ArrayRef<Expr *> AdjustArgsNeedDevicePtr, SourceRange SR);
10992+
ArrayRef<Expr *> AdjustArgsNeedDevicePtr,
10993+
ArrayRef<OMPDeclareVariantAttr::InteropType> AppendArgs,
10994+
SourceLocation AdjustArgsLoc, SourceLocation AppendArgsLoc,
10995+
SourceRange SR);
1098410996

1098510997
OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
1098610998
Expr *Expr,

0 commit comments

Comments
 (0)