Skip to content

Commit 49e83c4

Browse files
authored
merge main into amd-staging (llvm#1106)
2 parents 09721b1 + 4a7d731 commit 49e83c4

File tree

107 files changed

+2088
-1030
lines changed

Some content is hidden

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

107 files changed

+2088
-1030
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ Potentially Breaking Changes
3535
============================
3636

3737
- The Objective-C ARC migrator (ARCMigrate) has been removed.
38-
- Fix missing diagnostics for uses of declarations when performing typename access,
39-
such as when performing member access on a '[[deprecated]]' type alias.
40-
(#GH58547)
4138

4239
C/C++ Language Potentially Breaking Changes
4340
-------------------------------------------
@@ -161,8 +158,8 @@ related warnings within the method body.
161158
``__attribute__((model("large")))`` on non-TLS globals in x86-64 compilations.
162159
This forces the global to be considered small or large in regards to the
163160
x86-64 code model, regardless of the code model specified for the compilation.
164-
- Clang now emits a warning ``-Wreserved-init-priority`` instead of a hard error
165-
when ``__attribute__((init_priority(n)))`` is used with values of n in the
161+
- Clang now emits a warning ``-Wreserved-init-priority`` instead of a hard error
162+
when ``__attribute__((init_priority(n)))`` is used with values of n in the
166163
reserved range [0, 100]. The warning will be treated as an error by default.
167164

168165
- There is a new ``format_matches`` attribute to complement the existing
@@ -234,12 +231,16 @@ Improvements to Clang's diagnostics
234231
- Diagnostics on chained comparisons (``a < b < c``) are now an error by default. This can be disabled with
235232
``-Wno-error=parentheses``.
236233
- The ``-Wshift-bool`` warning has been added to warn about shifting a boolean. (#GH28334)
237-
234+
- Fixed diagnostics adding a trailing ``::`` when printing some source code
235+
constructs, like base classes.
238236
- The :doc:`ThreadSafetyAnalysis` now supports ``-Wthread-safety-pointer``,
239237
which enables warning on passing or returning pointers to guarded variables
240238
as function arguments or return value respectively. Note that
241239
:doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
242240
feature will be default-enabled with ``-Wthread-safety`` in a future release.
241+
- The ``-Wsign-compare`` warning now treats expressions with bitwise not(~) and minus(-) as signed integers
242+
except for the case where the operand is an unsigned integer
243+
and throws warning if they are compared with unsigned integers (##18878).
243244

244245
- Improve the diagnostics for chained comparisons to report actual expressions and operators (#GH129069).
245246

@@ -294,6 +295,9 @@ Bug Fixes to C++ Support
294295
direct-list-initialized from an array is corrected to direct-initialization.
295296
- Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. (#GH127327)
296297
- Clang now uses the parameter location for abbreviated function templates in ``extern "C"``. (#GH46386)
298+
- Fixes matching of nested template template parameters. (#GH130362)
299+
- Correctly diagnoses template template paramters which have a pack parameter
300+
not in the last position.
297301
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
298302

299303
Bug Fixes to AST Handling

clang/include/clang/AST/NestedNameSpecifier.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ class NestedNameSpecifier : public llvm::FoldingSetNode {
223223
/// `ns::SomeTemplate<int, MyClass>` instead of
224224
/// `ns::SomeTemplate<Container::value_type, T>`.
225225
void print(raw_ostream &OS, const PrintingPolicy &Policy,
226-
bool ResolveTemplateArguments = false) const;
226+
bool ResolveTemplateArguments = false,
227+
bool PrintFinalScopeResOp = true) const;
227228

228229
void Profile(llvm::FoldingSetNodeID &ID) const {
229230
ID.AddPointer(Prefix.getOpaqueValue());

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -599,16 +599,17 @@ def err_using_typename_non_type : Error<
599599
"'typename' keyword used on a non-type">;
600600
def err_using_dependent_value_is_type : Error<
601601
"dependent using declaration resolved to type without 'typename'">;
602-
def err_using_decl_nested_name_specifier_is_not_class : Error<
603-
"using declaration in class refers into '%0', which is not a class">;
602+
def err_using_decl_nested_name_specifier_is_not_class
603+
: Error<"using declaration in class refers into %0, which is not a class">;
604604
def warn_cxx17_compat_using_decl_non_member_enumerator : Warning<
605605
"member using declaration naming non-class '%0' enumerator is "
606606
"incompatible with C++ standards before C++20">, InGroup<CXXPre20Compat>,
607607
DefaultIgnore;
608608
def err_using_decl_nested_name_specifier_is_current_class : Error<
609609
"using declaration refers to its own class">;
610-
def err_using_decl_nested_name_specifier_is_not_base_class : Error<
611-
"using declaration refers into '%0', which is not a base class of %1">;
610+
def err_using_decl_nested_name_specifier_is_not_base_class
611+
: Error<
612+
"using declaration refers into %0, which is not a base class of %1">;
612613
def err_using_decl_constructor_not_in_direct_base : Error<
613614
"%0 is not a direct base of %1, cannot inherit constructors">;
614615
def err_using_decl_can_not_refer_to_class_member : Error<
@@ -1733,8 +1734,8 @@ def err_no_matching_local_friend_suggest : Error<
17331734
"cannot define friend function %0 in a local class definition; did you mean %3?">;
17341735
def err_partial_specialization_friend : Error<
17351736
"partial specialization cannot be declared as a friend">;
1736-
def err_qualified_friend_def : Error<
1737-
"friend function definition cannot be qualified with '%0'">;
1737+
def err_qualified_friend_def
1738+
: Error<"friend function definition cannot be qualified with %0">;
17381739
def err_friend_def_in_local_class : Error<
17391740
"friend function cannot be defined in a local class">;
17401741
def err_friend_specialization_def : Error<
@@ -1743,14 +1744,16 @@ def err_friend_not_first_in_declaration : Error<
17431744
"'friend' must appear first in a non-function declaration">;
17441745
def err_using_decl_friend : Error<
17451746
"cannot befriend target of using declaration">;
1746-
def warn_template_qualified_friend_unsupported : Warning<
1747-
"dependent nested name specifier '%0' for friend class declaration is "
1748-
"not supported; turning off access control for %1">,
1749-
InGroup<UnsupportedFriend>;
1750-
def warn_template_qualified_friend_ignored : Warning<
1751-
"dependent nested name specifier '%0' for friend template declaration is "
1752-
"not supported; ignoring this friend declaration">,
1753-
InGroup<UnsupportedFriend>;
1747+
def warn_template_qualified_friend_unsupported
1748+
: Warning<
1749+
"dependent nested name specifier %0 for friend class declaration is "
1750+
"not supported; turning off access control for %1">,
1751+
InGroup<UnsupportedFriend>;
1752+
def warn_template_qualified_friend_ignored
1753+
: Warning<"dependent nested name specifier %0 for friend template "
1754+
"declaration is "
1755+
"not supported; ignoring this friend declaration">,
1756+
InGroup<UnsupportedFriend>;
17541757
def ext_friend_tag_redecl_outside_namespace : ExtWarn<
17551758
"unqualified friend declaration referring to type outside of the nearest "
17561759
"enclosing namespace is a Microsoft extension; add a nested name specifier">,
@@ -5556,9 +5559,10 @@ def ext_template_spec_extra_headers : ExtWarn<
55565559
def note_explicit_template_spec_does_not_need_header : Note<
55575560
"'template<>' header not required for explicitly-specialized class %0 "
55585561
"declared here">;
5559-
def err_template_qualified_declarator_no_match : Error<
5560-
"nested name specifier '%0' for declaration does not refer into a class, "
5561-
"class template or class template partial specialization">;
5562+
def err_template_qualified_declarator_no_match
5563+
: Error<"nested name specifier %0 for declaration does not refer into a "
5564+
"class, "
5565+
"class template or class template partial specialization">;
55625566
def err_specialize_member_of_template : Error<
55635567
"cannot specialize %select{|(with 'template<>') }0a member of an "
55645568
"unspecialized template">;
@@ -5858,13 +5862,13 @@ def note_typename_member_refers_here : Note<
58585862
"referenced member %0 is declared here">;
58595863
def note_typename_refers_here : Note<
58605864
"referenced %0 is declared here">;
5861-
def err_typename_missing : Error<
5862-
"missing 'typename' prior to dependent type name '%0%1'">;
5863-
def err_typename_missing_template : Error<
5864-
"missing 'typename' prior to dependent type template name '%0%1'">;
5865-
def ext_typename_missing : ExtWarn<
5866-
"missing 'typename' prior to dependent type name '%0%1'">,
5867-
InGroup<DiagGroup<"typename-missing">>;
5865+
def err_typename_missing
5866+
: Error<"missing 'typename' prior to dependent type name %0">;
5867+
def err_typename_missing_template
5868+
: Error<"missing 'typename' prior to dependent type template name %0">;
5869+
def ext_typename_missing
5870+
: ExtWarn<"missing 'typename' prior to dependent type name %0">,
5871+
InGroup<DiagGroup<"typename-missing">>;
58685872
def ext_typename_outside_of_template : ExtWarn<
58695873
"'typename' occurs outside of a template">, InGroup<CXX11>;
58705874
def warn_cxx98_compat_typename_outside_of_template : Warning<
@@ -5878,9 +5882,10 @@ def note_using_value_decl_missing_typename : Note<
58785882
def warn_cxx17_compat_implicit_typename : Warning<"use of implicit 'typename' is "
58795883
"incompatible with C++ standards before C++20">, InGroup<CXX20Compat>,
58805884
DefaultIgnore;
5881-
def ext_implicit_typename : ExtWarn<"missing 'typename' prior to dependent "
5882-
"type name %0%1; implicit 'typename' is a C++20 extension">,
5883-
InGroup<CXX20>;
5885+
def ext_implicit_typename
5886+
: ExtWarn<"missing 'typename' prior to dependent "
5887+
"type name %0; implicit 'typename' is a C++20 extension">,
5888+
InGroup<CXX20>;
58845889

58855890
def err_template_kw_refers_to_non_template : Error<
58865891
"%0%select{| following the 'template' keyword}1 "
@@ -5890,12 +5895,13 @@ def note_template_kw_refers_to_non_template : Note<
58905895
def err_template_kw_refers_to_dependent_non_template : Error<
58915896
"%0%select{| following the 'template' keyword}1 "
58925897
"cannot refer to a dependent template">;
5893-
def err_template_kw_refers_to_type_template : Error<
5894-
"'%0%1' is expected to be a non-type template, but instantiated to a %select{class|type alias}2 template">;
5898+
def err_template_kw_refers_to_type_template
5899+
: Error<"%0 is expected to be a non-type template, but instantiated to a "
5900+
"%select{class|type alias}1 template">;
58955901
def note_referenced_type_template : Note<
58965902
"%select{class|type alias}0 template declared here">;
5897-
def err_template_kw_missing : Error<
5898-
"missing 'template' keyword prior to dependent template name '%0%1'">;
5903+
def err_template_kw_missing
5904+
: Error<"missing 'template' keyword prior to dependent template name %0">;
58995905
def ext_template_outside_of_template : ExtWarn<
59005906
"'template' keyword outside of a template">, InGroup<CXX11>;
59015907
def warn_cxx98_compat_template_outside_of_template : Warning<
@@ -7888,8 +7894,8 @@ def err_nogetter_property_incdec : Error<
78887894
"no getter method %1 for %select{increment|decrement}0 of property">;
78897895
def err_no_subobject_property_setting : Error<
78907896
"expression is not assignable">;
7891-
def err_qualified_objc_access : Error<
7892-
"%select{property|instance variable}0 access cannot be qualified with '%1'">;
7897+
def err_qualified_objc_access : Error<"%select{property|instance variable}0 "
7898+
"access cannot be qualified with %1">;
78937899

78947900
def ext_freestanding_complex : Extension<
78957901
"complex numbers are an extension in a freestanding C99 implementation">;
@@ -9842,8 +9848,8 @@ def note_non_usual_function_declared_here : Note<
98429848
// C++ literal operators
98439849
def err_literal_operator_outside_namespace : Error<
98449850
"literal operator %0 must be in a namespace or global scope">;
9845-
def err_literal_operator_id_outside_namespace : Error<
9846-
"non-namespace scope '%0' cannot have a literal operator member">;
9851+
def err_literal_operator_id_outside_namespace
9852+
: Error<"non-namespace scope %0 cannot have a literal operator member">;
98479853
def err_literal_operator_default_argument : Error<
98489854
"literal operator cannot have a default argument">;
98499855
def err_literal_operator_bad_param_count : Error<

clang/include/clang/Sema/Sema.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,13 +3168,6 @@ class Sema final : public SemaBase {
31683168

31693169
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr);
31703170

3171-
enum class DiagCtorKind { None, Implicit, Typename };
3172-
/// Returns the TypeDeclType for the given type declaration,
3173-
/// as ASTContext::getTypeDeclType would, but
3174-
/// performs the required semantic checks for name lookup of said entity.
3175-
QualType getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
3176-
TypeDecl *TD, SourceLocation NameLoc);
3177-
31783171
/// If the identifier refers to a type name within this scope,
31793172
/// return the declaration of that type.
31803173
///
@@ -11363,14 +11356,16 @@ class Sema final : public SemaBase {
1136311356

1136411357
/// The context in which we are checking a template parameter list.
1136511358
enum TemplateParamListContext {
11366-
TPC_ClassTemplate,
11367-
TPC_VarTemplate,
11359+
// For this context, Class, Variable, TypeAlias, and non-pack Template
11360+
// Template Parameters are treated uniformly.
11361+
TPC_Other,
11362+
1136811363
TPC_FunctionTemplate,
1136911364
TPC_ClassTemplateMember,
1137011365
TPC_FriendClassTemplate,
1137111366
TPC_FriendFunctionTemplate,
1137211367
TPC_FriendFunctionTemplateDefinition,
11373-
TPC_TypeAliasTemplate
11368+
TPC_TemplateTemplateParameterPack,
1137411369
};
1137511370

1137611371
/// Checks the validity of a template parameter list, possibly

clang/lib/AST/ASTDiagnostic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,9 @@ void clang::FormatASTNodeDiagnosticArgument(
461461
}
462462
case DiagnosticsEngine::ak_nestednamespec: {
463463
NestedNameSpecifier *NNS = reinterpret_cast<NestedNameSpecifier*>(Val);
464-
NNS->print(OS, Context.getPrintingPolicy());
465-
NeedQuotes = false;
464+
NNS->print(OS, Context.getPrintingPolicy(),
465+
/*ResolveTemplateArguments=*/false,
466+
/*PrintFinalScopeResOp=*/false);
466467
break;
467468
}
468469
case DiagnosticsEngine::ak_declcontext: {

clang/lib/AST/NestedNameSpecifier.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ bool NestedNameSpecifier::containsErrors() const {
248248
/// Print this nested name specifier to the given output
249249
/// stream.
250250
void NestedNameSpecifier::print(raw_ostream &OS, const PrintingPolicy &Policy,
251-
bool ResolveTemplateArguments) const {
251+
bool ResolveTemplateArguments,
252+
bool PrintFinalScopeResOp) const {
252253
if (getPrefix())
253254
getPrefix()->print(OS, Policy);
254255

@@ -269,7 +270,8 @@ void NestedNameSpecifier::print(raw_ostream &OS, const PrintingPolicy &Policy,
269270
break;
270271

271272
case Global:
272-
break;
273+
OS << "::";
274+
return;
273275

274276
case Super:
275277
OS << "__super";
@@ -331,7 +333,8 @@ void NestedNameSpecifier::print(raw_ostream &OS, const PrintingPolicy &Policy,
331333
}
332334
}
333335

334-
OS << "::";
336+
if (PrintFinalScopeResOp)
337+
OS << "::";
335338
}
336339

337340
LLVM_DUMP_METHOD void NestedNameSpecifier::dump(const LangOptions &LO) const {

clang/lib/CodeGen/Targets/AMDGPU.cpp

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,20 @@ void AMDGPUTargetCodeGenInfo::setCUDAKernelCallingConvention(
608608
FT, FT->getExtInfo().withCallingConv(CC_OpenCLKernel));
609609
}
610610

611+
/// Return IR struct type for rtinfo struct in rocm-device-libs used for device
612+
/// enqueue.
613+
///
614+
/// ptr addrspace(1) kernel_object, i32 private_segment_size,
615+
/// i32 group_segment_size
616+
617+
static llvm::StructType *
618+
getAMDGPURuntimeHandleType(llvm::LLVMContext &C,
619+
llvm::Type *KernelDescriptorPtrTy) {
620+
llvm::Type *Int32 = llvm::Type::getInt32Ty(C);
621+
return llvm::StructType::create(C, {KernelDescriptorPtrTy, Int32, Int32},
622+
"block.runtime.handle.t");
623+
}
624+
611625
/// Create an OpenCL kernel for an enqueued block.
612626
///
613627
/// The type of the first argument (the block literal) is the struct type
@@ -647,23 +661,29 @@ llvm::Value *AMDGPUTargetCodeGenInfo::createEnqueuedBlockKernel(
647661
ArgNames.push_back(
648662
llvm::MDString::get(C, (Twine("local_arg") + Twine(I)).str()));
649663
}
650-
std::string Name = Invoke->getName().str() + "_kernel";
664+
665+
llvm::Module &Mod = CGF.CGM.getModule();
666+
const llvm::DataLayout &DL = Mod.getDataLayout();
667+
668+
llvm::Twine Name = Invoke->getName() + "_kernel";
651669
auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false);
670+
671+
// The kernel itself can be internal, the runtime does not directly access the
672+
// kernel address (only the kernel descriptor).
652673
auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, Name,
653-
&CGF.CGM.getModule());
674+
&Mod);
654675
F->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
655676

656677
llvm::AttrBuilder KernelAttrs(C);
657678
// FIXME: The invoke isn't applying the right attributes either
658679
// FIXME: This is missing setTargetAttributes
659680
CGF.CGM.addDefaultFunctionDefinitionAttributes(KernelAttrs);
660-
KernelAttrs.addAttribute("enqueued-block");
661681
F->addFnAttrs(KernelAttrs);
662682

663683
auto IP = CGF.Builder.saveIP();
664684
auto *BB = llvm::BasicBlock::Create(C, "entry", F);
665685
Builder.SetInsertPoint(BB);
666-
const auto BlockAlign = CGF.CGM.getDataLayout().getPrefTypeAlign(BlockTy);
686+
const auto BlockAlign = DL.getPrefTypeAlign(BlockTy);
667687
auto *BlockPtr = Builder.CreateAlloca(BlockTy, nullptr);
668688
BlockPtr->setAlignment(BlockAlign);
669689
Builder.CreateAlignedStore(F->arg_begin(), BlockPtr, BlockAlign);
@@ -686,7 +706,39 @@ llvm::Value *AMDGPUTargetCodeGenInfo::createEnqueuedBlockKernel(
686706
if (CGF.CGM.getCodeGenOpts().EmitOpenCLArgMetadata)
687707
F->setMetadata("kernel_arg_name", llvm::MDNode::get(C, ArgNames));
688708

689-
return F;
709+
llvm::StructType *HandleTy = getAMDGPURuntimeHandleType(
710+
C, llvm::PointerType::get(C, DL.getDefaultGlobalsAddressSpace()));
711+
llvm::Constant *RuntimeHandleInitializer =
712+
llvm::ConstantAggregateZero::get(HandleTy);
713+
714+
llvm::Twine RuntimeHandleName = F->getName() + ".runtime.handle";
715+
716+
// The runtime needs access to the runtime handle as an external symbol. The
717+
// runtime handle will need to be made external later, in
718+
// AMDGPUExportOpenCLEnqueuedBlocks. The kernel itself has a hidden reference
719+
// inside the runtime handle, and is not directly referenced.
720+
721+
// TODO: We would initialize the first field by declaring F->getName() + ".kd"
722+
// to reference the kernel descriptor. The runtime wouldn't need to bother
723+
// setting it. We would need to have a final symbol name though.
724+
// TODO: Can we directly use an external symbol with getGlobalIdentifier?
725+
auto *RuntimeHandle = new llvm::GlobalVariable(
726+
Mod, HandleTy,
727+
/*isConstant=*/true, llvm::GlobalValue::InternalLinkage,
728+
/*Initializer=*/RuntimeHandleInitializer, RuntimeHandleName,
729+
/*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
730+
DL.getDefaultGlobalsAddressSpace(),
731+
/*isExternallyInitialized=*/true);
732+
733+
llvm::MDNode *HandleAsMD =
734+
llvm::MDNode::get(C, llvm::ValueAsMetadata::get(RuntimeHandle));
735+
F->setMetadata(llvm::LLVMContext::MD_associated, HandleAsMD);
736+
737+
RuntimeHandle->setSection(".amdgpu.kernel.runtime.handle");
738+
739+
CGF.CGM.addUsedGlobal(F);
740+
CGF.CGM.addUsedGlobal(RuntimeHandle);
741+
return RuntimeHandle;
690742
}
691743

692744
void CodeGenModule::handleAMDGPUFlatWorkGroupSizeAttr(

clang/lib/Sema/SemaARM.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,16 @@ bool SemaARM::BuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall,
249249
}
250250
}
251251

252-
SmallVector<int, 5> Ranges;
252+
SmallVector<int, 5> FieldBitWidths;
253253
if (FiveFields)
254-
Ranges.append({IsAArch64Builtin ? 1 : 15, 7, 15, 15, 7});
254+
FieldBitWidths.append({IsAArch64Builtin ? 2 : 4, 3, 4, 4, 3});
255255
else
256-
Ranges.append({15, 7, 15});
256+
FieldBitWidths.append({4, 3, 4});
257257

258258
for (unsigned i = 0; i < Fields.size(); ++i) {
259259
int IntField;
260260
ValidString &= !Fields[i].getAsInteger(10, IntField);
261-
ValidString &= (IntField >= 0 && IntField <= Ranges[i]);
261+
ValidString &= (IntField >= 0 && IntField < (1 << FieldBitWidths[i]));
262262
}
263263

264264
if (!ValidString)

0 commit comments

Comments
 (0)