Skip to content

Commit 5324fb5

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: I3daf0524258ea4d8f69fa11767b45505827a38ed
2 parents c5659bd + 7d3b81d commit 5324fb5

Some content is hidden

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

42 files changed

+584
-580
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,36 @@ static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
10731073
.Case("ShaderModel", "shadermodel")
10741074
.Default(Platform);
10751075
}
1076+
static std::vector<llvm::StringRef> equivalentPlatformNames(llvm::StringRef Platform) {
1077+
return llvm::StringSwitch<std::vector<llvm::StringRef>>(Platform)
1078+
.Case("ios", {"ios", "iOS"})
1079+
.Case("iOS", {"ios", "iOS"})
1080+
.Case("macos", {"macos", "macOS"})
1081+
.Case("macOS", {"macos", "macOS"})
1082+
.Case("tvos", {"tvos", "tvOS"})
1083+
.Case("tvOS", {"tvos", "tvOS"})
1084+
.Case("watchos", {"watchos", "watchOS"})
1085+
.Case("watchOS", {"watchos", "watchOS"})
1086+
.Case("ios_app_extension", {"iOSApplicationExtension", "ios_app_extension"})
1087+
.Case("iOSApplicationExtension", {"iOSApplicationExtension", "ios_app_extension"})
1088+
.Case("macos_app_extension", {"macOSApplicationExtension", "macos_app_extension"})
1089+
.Case("macOSApplicationExtension", {"macOSApplicationExtension", "macos_app_extension"})
1090+
.Case("tvos_app_extension", {"tvOSApplicationExtension", "tvos_app_extension"})
1091+
.Case("tvOSApplicationExtension", {"tvOSApplicationExtension", "tvos_app_extension"})
1092+
.Case("watchos_app_extension", {"watchOSApplicationExtension", "watchos_app_extension"})
1093+
.Case("watchOSApplicationExtension", {"watchOSApplicationExtension", "watchos_app_extension"})
1094+
.Case("maccatalyst", {"macCatalyst", "maccatalyst"})
1095+
.Case("macCatalyst", {"macCatalyst", "maccatalyst"})
1096+
.Case("maccatalyst_app_extension", {"macCatalystApplicationExtension", "maccatalyst_app_extension"})
1097+
.Case("macCatalystApplicationExtension", {"macCatalystApplicationExtension", "maccatalyst_app_extension"})
1098+
.Case("xros", {"visionos", "visionOS", "xros"})
1099+
.Case("visionOS", {"visionos", "visionOS", "xros"})
1100+
.Case("visionos", {"visionos", "visionOS", "xros"})
1101+
.Case("xros_app_extension", {"visionOSApplicationExtension", "visionos_app_extension", "xros_app_extension"})
1102+
.Case("visionOSApplicationExtension", {"visionOSApplicationExtension", "visionos_app_extension", "xros_app_extension"})
1103+
.Case("visionos_app_extension", {"visionOSApplicationExtension", "visionos_app_extension", "xros_app_extension"})
1104+
.Default({Platform});
1105+
}
10761106
static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef Environment) {
10771107
return llvm::StringSwitch<llvm::Triple::EnvironmentType>(Environment)
10781108
.Case("pixel", llvm::Triple::Pixel)

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8811,6 +8811,32 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
88118811
WantDebug = !A->getOption().matches(options::OPT_g0) &&
88128812
!A->getOption().matches(options::OPT_ggdb0);
88138813

8814+
// If a -gdwarf argument appeared, remember it.
8815+
bool EmitDwarf = false;
8816+
if (const Arg *A = getDwarfNArg(Args))
8817+
EmitDwarf = checkDebugInfoOption(A, Args, D, getToolChain());
8818+
8819+
bool EmitCodeView = false;
8820+
if (const Arg *A = Args.getLastArg(options::OPT_gcodeview))
8821+
EmitCodeView = checkDebugInfoOption(A, Args, D, getToolChain());
8822+
8823+
// If the user asked for debug info but did not explicitly specify -gcodeview
8824+
// or -gdwarf, ask the toolchain for the default format.
8825+
if (!EmitCodeView && !EmitDwarf && WantDebug) {
8826+
switch (getToolChain().getDefaultDebugFormat()) {
8827+
case llvm::codegenoptions::DIF_CodeView:
8828+
EmitCodeView = true;
8829+
break;
8830+
case llvm::codegenoptions::DIF_DWARF:
8831+
EmitDwarf = true;
8832+
break;
8833+
}
8834+
}
8835+
8836+
// If the arguments don't imply DWARF, don't emit any debug info here.
8837+
if (!EmitDwarf)
8838+
WantDebug = false;
8839+
88148840
llvm::codegenoptions::DebugInfoKind DebugInfoKind =
88158841
llvm::codegenoptions::NoDebugInfo;
88168842

clang/lib/Sema/SemaAvailability.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,22 +488,41 @@ static void DoEmitAvailabilityWarning(Sema &S, AvailabilityResult K,
488488
// Don't offer a fixit for declarations with availability attributes.
489489
if (Enclosing->hasAttr<AvailabilityAttr>())
490490
return;
491-
if (!S.getPreprocessor().isMacroDefined("API_AVAILABLE"))
491+
Preprocessor &PP = S.getPreprocessor();
492+
if (!PP.isMacroDefined("API_AVAILABLE"))
492493
return;
493494
std::optional<AttributeInsertion> Insertion = createAttributeInsertion(
494495
Enclosing, S.getSourceManager(), S.getLangOpts());
495496
if (!Insertion)
496497
return;
497-
std::string PlatformName =
498-
AvailabilityAttr::getPlatformNameSourceSpelling(
499-
S.getASTContext().getTargetInfo().getPlatformName())
500-
.lower();
498+
StringRef PlatformName =
499+
S.getASTContext().getTargetInfo().getPlatformName();
500+
501+
// Apple's API_AVAILABLE macro expands roughly like this.
502+
// API_AVAILABLE(ios(17.0))
503+
// __attribute__((availability(__API_AVAILABLE_PLATFORM_ios(17.0)))
504+
// __attribute__((availability(ios,introduced=17.0)))
505+
// In order to figure out which platform name to use in the API_AVAILABLE
506+
// macro, the associated __API_AVAILABLE_PLATFORM_ macro needs to be
507+
// found. The __API_AVAILABLE_PLATFORM_ macros aren't consistent about
508+
// using the canonical platform name, source spelling name, or one of the
509+
// other supported names (i.e. one of the keys in canonicalizePlatformName
510+
// that's neither). Check all of the supported names for a match.
511+
std::vector<StringRef> EquivalentPlatforms =
512+
AvailabilityAttr::equivalentPlatformNames(PlatformName);
513+
llvm::Twine MacroPrefix = "__API_AVAILABLE_PLATFORM_";
514+
auto AvailablePlatform =
515+
llvm::find_if(EquivalentPlatforms, [&](StringRef EquivalentPlatform) {
516+
return PP.isMacroDefined((MacroPrefix + EquivalentPlatform).str());
517+
});
518+
if (AvailablePlatform == EquivalentPlatforms.end())
519+
return;
501520
std::string Introduced =
502521
OffendingDecl->getVersionIntroduced().getAsString();
503522
FixitNoteDiag << FixItHint::CreateInsertion(
504523
Insertion->Loc,
505-
(llvm::Twine(Insertion->Prefix) + "API_AVAILABLE(" + PlatformName +
506-
"(" + Introduced + "))" + Insertion->Suffix)
524+
(llvm::Twine(Insertion->Prefix) + "API_AVAILABLE(" +
525+
*AvailablePlatform + "(" + Introduced + "))" + Insertion->Suffix)
507526
.str());
508527
}
509528
return;

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 66 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,9 @@ struct RegisterBindingFlags {
612612

613613
bool ContainsNumeric = false;
614614
bool DefaultGlobals = false;
615+
616+
// used only when Resource == true
617+
std::optional<llvm::dxil::ResourceClass> ResourceClass;
615618
};
616619

617620
static bool isDeclaredWithinCOrTBuffer(const Decl *TheDecl) {
@@ -677,65 +680,38 @@ static const T *getSpecifiedHLSLAttrFromVarDecl(VarDecl *VD) {
677680
return getSpecifiedHLSLAttrFromRecordDecl<T>(TheRecordDecl);
678681
}
679682

680-
static void updateFlagsFromType(QualType TheQualTy,
681-
RegisterBindingFlags &Flags);
682-
683-
static void updateResourceClassFlagsFromRecordDecl(RegisterBindingFlags &Flags,
684-
const RecordDecl *RD) {
685-
if (!RD)
686-
return;
687-
688-
if (RD->isCompleteDefinition()) {
689-
for (auto Field : RD->fields()) {
690-
QualType T = Field->getType();
691-
updateFlagsFromType(T, Flags);
683+
static void updateResourceClassFlagsFromRecordType(RegisterBindingFlags &Flags,
684+
const RecordType *RT) {
685+
llvm::SmallVector<const Type *> TypesToScan;
686+
TypesToScan.emplace_back(RT);
687+
688+
while (!TypesToScan.empty()) {
689+
const Type *T = TypesToScan.pop_back_val();
690+
while (T->isArrayType())
691+
T = T->getArrayElementTypeNoTypeQual();
692+
if (T->isIntegralOrEnumerationType() || T->isFloatingType()) {
693+
Flags.ContainsNumeric = true;
694+
continue;
692695
}
693-
}
694-
}
695-
696-
static void updateFlagsFromType(QualType TheQualTy,
697-
RegisterBindingFlags &Flags) {
698-
// if the member's type is a numeric type, set the ContainsNumeric flag
699-
if (TheQualTy->isIntegralOrEnumerationType() || TheQualTy->isFloatingType()) {
700-
Flags.ContainsNumeric = true;
701-
return;
702-
}
703-
704-
const clang::Type *TheBaseType = TheQualTy.getTypePtr();
705-
while (TheBaseType->isArrayType())
706-
TheBaseType = TheBaseType->getArrayElementTypeNoTypeQual();
707-
// otherwise, if the member's base type is not a record type, return
708-
const RecordType *TheRecordTy = TheBaseType->getAs<RecordType>();
709-
if (!TheRecordTy)
710-
return;
711-
712-
RecordDecl *SubRecordDecl = TheRecordTy->getDecl();
713-
const HLSLResourceClassAttr *Attr =
714-
getSpecifiedHLSLAttrFromRecordDecl<HLSLResourceClassAttr>(SubRecordDecl);
715-
// find the attr if it's on the member, or on any of the member's fields
716-
if (Attr) {
717-
llvm::hlsl::ResourceClass DeclResourceClass = Attr->getResourceClass();
718-
updateResourceClassFlagsFromDeclResourceClass(Flags, DeclResourceClass);
719-
}
696+
const RecordType *RT = T->getAs<RecordType>();
697+
if (!RT)
698+
continue;
720699

721-
// otherwise, dig deeper and recurse into the member
722-
else {
723-
updateResourceClassFlagsFromRecordDecl(Flags, SubRecordDecl);
700+
const RecordDecl *RD = RT->getDecl();
701+
for (FieldDecl *FD : RD->fields()) {
702+
if (HLSLResourceClassAttr *RCAttr =
703+
FD->getAttr<HLSLResourceClassAttr>()) {
704+
updateResourceClassFlagsFromDeclResourceClass(
705+
Flags, RCAttr->getResourceClass());
706+
continue;
707+
}
708+
TypesToScan.emplace_back(FD->getType().getTypePtr());
709+
}
724710
}
725711
}
726712

727713
static RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema &S,
728714
Decl *TheDecl) {
729-
730-
// Cbuffers and Tbuffers are HLSLBufferDecl types
731-
HLSLBufferDecl *CBufferOrTBuffer = dyn_cast<HLSLBufferDecl>(TheDecl);
732-
// Samplers, UAVs, and SRVs are VarDecl types
733-
VarDecl *TheVarDecl = dyn_cast<VarDecl>(TheDecl);
734-
735-
assert(((TheVarDecl && !CBufferOrTBuffer) ||
736-
(!TheVarDecl && CBufferOrTBuffer)) &&
737-
"either TheVarDecl or CBufferOrTBuffer should be set");
738-
739715
RegisterBindingFlags Flags;
740716

741717
// check if the decl type is groupshared
@@ -744,58 +720,60 @@ static RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema &S,
744720
return Flags;
745721
}
746722

747-
if (!isDeclaredWithinCOrTBuffer(TheDecl)) {
748-
// make sure the type is a basic / numeric type
749-
if (TheVarDecl) {
750-
QualType TheQualTy = TheVarDecl->getType();
751-
// a numeric variable or an array of numeric variables
752-
// will inevitably end up in $Globals buffer
753-
const clang::Type *TheBaseType = TheQualTy.getTypePtr();
754-
while (TheBaseType->isArrayType())
755-
TheBaseType = TheBaseType->getArrayElementTypeNoTypeQual();
756-
if (TheBaseType->isIntegralType(S.getASTContext()) ||
757-
TheBaseType->isFloatingType())
758-
Flags.DefaultGlobals = true;
759-
}
760-
}
761-
762-
if (CBufferOrTBuffer) {
723+
// Cbuffers and Tbuffers are HLSLBufferDecl types
724+
if (HLSLBufferDecl *CBufferOrTBuffer = dyn_cast<HLSLBufferDecl>(TheDecl)) {
763725
Flags.Resource = true;
764-
if (CBufferOrTBuffer->isCBuffer())
765-
Flags.CBV = true;
766-
else
767-
Flags.SRV = true;
768-
} else if (TheVarDecl) {
726+
Flags.ResourceClass = CBufferOrTBuffer->isCBuffer()
727+
? llvm::dxil::ResourceClass::CBuffer
728+
: llvm::dxil::ResourceClass::SRV;
729+
}
730+
// Samplers, UAVs, and SRVs are VarDecl types
731+
else if (VarDecl *TheVarDecl = dyn_cast<VarDecl>(TheDecl)) {
769732
const HLSLResourceClassAttr *resClassAttr =
770733
getSpecifiedHLSLAttrFromVarDecl<HLSLResourceClassAttr>(TheVarDecl);
771-
772734
if (resClassAttr) {
773-
llvm::hlsl::ResourceClass DeclResourceClass =
774-
resClassAttr->getResourceClass();
775735
Flags.Resource = true;
776-
updateResourceClassFlagsFromDeclResourceClass(Flags, DeclResourceClass);
736+
Flags.ResourceClass = resClassAttr->getResourceClass();
777737
} else {
778738
const clang::Type *TheBaseType = TheVarDecl->getType().getTypePtr();
779739
while (TheBaseType->isArrayType())
780740
TheBaseType = TheBaseType->getArrayElementTypeNoTypeQual();
781-
if (TheBaseType->isArithmeticType())
741+
742+
if (TheBaseType->isArithmeticType()) {
782743
Flags.Basic = true;
783-
else if (TheBaseType->isRecordType()) {
744+
if (!isDeclaredWithinCOrTBuffer(TheDecl) &&
745+
(TheBaseType->isIntegralType(S.getASTContext()) ||
746+
TheBaseType->isFloatingType()))
747+
Flags.DefaultGlobals = true;
748+
} else if (TheBaseType->isRecordType()) {
784749
Flags.UDT = true;
785750
const RecordType *TheRecordTy = TheBaseType->getAs<RecordType>();
786-
assert(TheRecordTy && "The Qual Type should be Record Type");
787-
const RecordDecl *TheRecordDecl = TheRecordTy->getDecl();
788-
// recurse through members, set appropriate resource class flags.
789-
updateResourceClassFlagsFromRecordDecl(Flags, TheRecordDecl);
751+
updateResourceClassFlagsFromRecordType(Flags, TheRecordTy);
790752
} else
791753
Flags.Other = true;
792754
}
755+
} else {
756+
llvm_unreachable("expected be VarDecl or HLSLBufferDecl");
793757
}
794758
return Flags;
795759
}
796760

797761
enum class RegisterType { SRV, UAV, CBuffer, Sampler, C, I, Invalid };
798762

763+
static RegisterType getRegisterType(llvm::dxil::ResourceClass RC) {
764+
switch (RC) {
765+
case llvm::dxil::ResourceClass::SRV:
766+
return RegisterType::SRV;
767+
case llvm::dxil::ResourceClass::UAV:
768+
return RegisterType::UAV;
769+
case llvm::dxil::ResourceClass::CBuffer:
770+
return RegisterType::CBuffer;
771+
case llvm::dxil::ResourceClass::Sampler:
772+
return RegisterType::Sampler;
773+
}
774+
llvm_unreachable("unexpected ResourceClass value");
775+
}
776+
799777
static RegisterType getRegisterType(StringRef Slot) {
800778
switch (Slot[0]) {
801779
case 't':
@@ -865,6 +843,8 @@ static void DiagnoseHLSLRegisterAttribute(Sema &S, SourceLocation &ArgLoc,
865843
assert(((TheVarDecl && !CBufferOrTBuffer) ||
866844
(!TheVarDecl && CBufferOrTBuffer)) &&
867845
"either TheVarDecl or CBufferOrTBuffer should be set");
846+
(void)TheVarDecl;
847+
(void)CBufferOrTBuffer;
868848

869849
RegisterBindingFlags Flags = HLSLFillRegisterBindingFlags(S, TheDecl);
870850
assert((int)Flags.Other + (int)Flags.Resource + (int)Flags.Basic +
@@ -886,34 +866,8 @@ static void DiagnoseHLSLRegisterAttribute(Sema &S, SourceLocation &ArgLoc,
886866
// next, if resource is set, make sure the register type in the register
887867
// annotation is compatible with the variable's resource type.
888868
if (Flags.Resource) {
889-
const HLSLResourceClassAttr *resClassAttr = nullptr;
890-
if (CBufferOrTBuffer) {
891-
resClassAttr = CBufferOrTBuffer->getAttr<HLSLResourceClassAttr>();
892-
} else if (TheVarDecl) {
893-
resClassAttr =
894-
getSpecifiedHLSLAttrFromVarDecl<HLSLResourceClassAttr>(TheVarDecl);
895-
}
896-
897-
assert(resClassAttr &&
898-
"any decl that set the resource flag on analysis should "
899-
"have a resource class attribute attached.");
900-
const llvm::hlsl::ResourceClass DeclResourceClass =
901-
resClassAttr->getResourceClass();
902-
903-
// confirm that the register type is bound to its expected resource class
904-
static RegisterType ExpectedRegisterTypesForResourceClass[] = {
905-
RegisterType::SRV,
906-
RegisterType::UAV,
907-
RegisterType::CBuffer,
908-
RegisterType::Sampler,
909-
};
910-
assert((size_t)DeclResourceClass <
911-
std::size(ExpectedRegisterTypesForResourceClass) &&
912-
"DeclResourceClass has unexpected value");
913-
914-
RegisterType ExpectedRegisterType =
915-
ExpectedRegisterTypesForResourceClass[(int)DeclResourceClass];
916-
if (regType != ExpectedRegisterType) {
869+
RegisterType expRegType = getRegisterType(Flags.ResourceClass.value());
870+
if (regType != expRegType) {
917871
S.Diag(TheDecl->getLocation(), diag::err_hlsl_binding_type_mismatch)
918872
<< regTypeNum;
919873
}
@@ -955,7 +909,7 @@ static void DiagnoseHLSLRegisterAttribute(Sema &S, SourceLocation &ArgLoc,
955909
}
956910

957911
void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) {
958-
if (dyn_cast<VarDecl>(TheDecl)) {
912+
if (isa<VarDecl>(TheDecl)) {
959913
if (SemaRef.RequireCompleteType(TheDecl->getBeginLoc(),
960914
cast<ValueDecl>(TheDecl)->getType(),
961915
diag::err_incomplete_type))

clang/test/Driver/debug-options-as.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,27 @@
1919
// GGDB0-NOT: -debug-info-kind=
2020

2121
// Check to make sure clang with -g on a .s file gets passed.
22-
// RUN: %clang -### -c -integrated-as -g -x assembler %s 2>&1 \
22+
// This requires a target that defaults to DWARF.
23+
// RUN: %clang -### --target=x86_64-linux-gnu -c -integrated-as -g -x assembler %s 2>&1 \
2324
// RUN: | FileCheck %s
2425
//
2526
// CHECK: "-cc1as"
2627
// CHECK: "-debug-info-kind=constructor"
2728

29+
// Check that a plain -g, without any -gdwarf, for a MSVC target, doesn't
30+
// trigger producing DWARF output.
31+
// RUN: %clang -### --target=x86_64-windows-msvc -c -integrated-as -g -x assembler %s 2>&1 \
32+
// RUN: | FileCheck -check-prefix=MSVC %s
33+
//
34+
// MSVC: "-cc1as"
35+
// MSVC-NOT: "-debug-info-kind=constructor"
36+
37+
// Check that clang-cl with the -Z7 option works the same, not triggering
38+
// any DWARF output.
39+
//
40+
// RUN: %clang_cl -### --target=x86_64-pc-windows-msvc -c -Z7 -x assembler -- %s 2>&1 \
41+
// RUN: | FileCheck -check-prefix=MSVC %s
42+
2843
// Check to make sure clang with -g on a .s file gets passed -dwarf-debug-producer.
2944
// RUN: %clang -### -c -integrated-as -g -x assembler %s 2>&1 \
3045
// RUN: | FileCheck -check-prefix=P %s

0 commit comments

Comments
 (0)