Skip to content

Commit a8c4cda

Browse files
authored
Merge branch 'main' into main
2 parents c39094f + 773e88f commit a8c4cda

39 files changed

+822
-582
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 3 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
-------------------------------------------
@@ -241,6 +238,9 @@ Improvements to Clang's diagnostics
241238
as function arguments or return value respectively. Note that
242239
:doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
243240
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).
244244

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

@@ -297,6 +297,9 @@ Bug Fixes to C++ Support
297297
- Clang now uses the parameter location for abbreviated function templates in ``extern "C"``. (#GH46386)
298298
- Clang will emit an error instead of crash when use co_await or co_yield in
299299
C++26 braced-init-list template parameter initialization. (#GH78426)
300+
- Fixes matching of nested template template parameters. (#GH130362)
301+
- Correctly diagnoses template template paramters which have a pack parameter
302+
not in the last position.
300303
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
301304

302305
Bug Fixes to AST Handling

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/CodeGen/Targets/AMDGPU.cpp

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

617+
/// Return IR struct type for rtinfo struct in rocm-device-libs used for device
618+
/// enqueue.
619+
///
620+
/// ptr addrspace(1) kernel_object, i32 private_segment_size,
621+
/// i32 group_segment_size
622+
623+
static llvm::StructType *
624+
getAMDGPURuntimeHandleType(llvm::LLVMContext &C,
625+
llvm::Type *KernelDescriptorPtrTy) {
626+
llvm::Type *Int32 = llvm::Type::getInt32Ty(C);
627+
return llvm::StructType::create(C, {KernelDescriptorPtrTy, Int32, Int32},
628+
"block.runtime.handle.t");
629+
}
630+
617631
/// Create an OpenCL kernel for an enqueued block.
618632
///
619633
/// The type of the first argument (the block literal) is the struct type
@@ -653,23 +667,29 @@ llvm::Value *AMDGPUTargetCodeGenInfo::createEnqueuedBlockKernel(
653667
ArgNames.push_back(
654668
llvm::MDString::get(C, (Twine("local_arg") + Twine(I)).str()));
655669
}
656-
std::string Name = Invoke->getName().str() + "_kernel";
670+
671+
llvm::Module &Mod = CGF.CGM.getModule();
672+
const llvm::DataLayout &DL = Mod.getDataLayout();
673+
674+
llvm::Twine Name = Invoke->getName() + "_kernel";
657675
auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false);
676+
677+
// The kernel itself can be internal, the runtime does not directly access the
678+
// kernel address (only the kernel descriptor).
658679
auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, Name,
659-
&CGF.CGM.getModule());
680+
&Mod);
660681
F->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
661682

662683
llvm::AttrBuilder KernelAttrs(C);
663684
// FIXME: The invoke isn't applying the right attributes either
664685
// FIXME: This is missing setTargetAttributes
665686
CGF.CGM.addDefaultFunctionDefinitionAttributes(KernelAttrs);
666-
KernelAttrs.addAttribute("enqueued-block");
667687
F->addFnAttrs(KernelAttrs);
668688

669689
auto IP = CGF.Builder.saveIP();
670690
auto *BB = llvm::BasicBlock::Create(C, "entry", F);
671691
Builder.SetInsertPoint(BB);
672-
const auto BlockAlign = CGF.CGM.getDataLayout().getPrefTypeAlign(BlockTy);
692+
const auto BlockAlign = DL.getPrefTypeAlign(BlockTy);
673693
auto *BlockPtr = Builder.CreateAlloca(BlockTy, nullptr);
674694
BlockPtr->setAlignment(BlockAlign);
675695
Builder.CreateAlignedStore(F->arg_begin(), BlockPtr, BlockAlign);
@@ -692,7 +712,39 @@ llvm::Value *AMDGPUTargetCodeGenInfo::createEnqueuedBlockKernel(
692712
if (CGF.CGM.getCodeGenOpts().EmitOpenCLArgMetadata)
693713
F->setMetadata("kernel_arg_name", llvm::MDNode::get(C, ArgNames));
694714

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

698750
void CodeGenModule::handleAMDGPUFlatWorkGroupSizeAttr(

clang/lib/Sema/SemaChecking.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10620,6 +10620,42 @@ static std::optional<IntRange> TryGetExprRange(ASTContext &C, const Expr *E,
1062010620
case UO_AddrOf: // should be impossible
1062110621
return IntRange::forValueOfType(C, GetExprType(E));
1062210622

10623+
case UO_Minus: {
10624+
if (E->getType()->isUnsignedIntegerType()) {
10625+
return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
10626+
Approximate);
10627+
}
10628+
10629+
std::optional<IntRange> SubRange = TryGetExprRange(
10630+
C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate);
10631+
10632+
if (!SubRange)
10633+
return std::nullopt;
10634+
10635+
// If the range was previously non-negative, we need an extra bit for the
10636+
// sign bit. If the range was not non-negative, we need an extra bit
10637+
// because the negation of the most-negative value is one bit wider than
10638+
// that value.
10639+
return IntRange(SubRange->Width + 1, false);
10640+
}
10641+
10642+
case UO_Not: {
10643+
if (E->getType()->isUnsignedIntegerType()) {
10644+
return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
10645+
Approximate);
10646+
}
10647+
10648+
std::optional<IntRange> SubRange = TryGetExprRange(
10649+
C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate);
10650+
10651+
if (!SubRange)
10652+
return std::nullopt;
10653+
10654+
// The width increments by 1 if the sub-expression cannot be negative
10655+
// since it now can be.
10656+
return IntRange(SubRange->Width + (int)SubRange->NonNegative, false);
10657+
}
10658+
1062310659
default:
1062410660
return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
1062510661
Approximate);

clang/lib/Sema/SemaDecl.cpp

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -139,26 +139,6 @@ class TypeNameValidatorCCC final : public CorrectionCandidateCallback {
139139

140140
} // end anonymous namespace
141141

142-
QualType Sema::getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
143-
TypeDecl *TD, SourceLocation NameLoc) {
144-
auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
145-
auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
146-
if (DCK != DiagCtorKind::None && LookupRD && FoundRD &&
147-
FoundRD->isInjectedClassName() &&
148-
declaresSameEntity(LookupRD, cast<Decl>(FoundRD->getParent()))) {
149-
Diag(NameLoc,
150-
DCK == DiagCtorKind::Typename
151-
? diag::ext_out_of_line_qualified_id_type_names_constructor
152-
: diag::err_out_of_line_qualified_id_type_names_constructor)
153-
<< TD->getIdentifier() << /*Type=*/1
154-
<< 0 /*if any keyword was present, it was 'typename'*/;
155-
}
156-
157-
DiagnoseUseOfDecl(TD, NameLoc);
158-
MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
159-
return Context.getTypeDeclType(TD);
160-
}
161-
162142
namespace {
163143
enum class UnqualifiedTypeNameLookupResult {
164144
NotFound,
@@ -315,11 +295,10 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
315295
bool IsClassTemplateDeductionContext,
316296
ImplicitTypenameContext AllowImplicitTypename,
317297
IdentifierInfo **CorrectedII) {
318-
bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
319298
// FIXME: Consider allowing this outside C++1z mode as an extension.
320299
bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
321-
getLangOpts().CPlusPlus17 && IsImplicitTypename &&
322-
!HasTrailingDot;
300+
getLangOpts().CPlusPlus17 && !IsCtorOrDtorName &&
301+
!isClassName && !HasTrailingDot;
323302

324303
// Determine where we will perform name lookup.
325304
DeclContext *LookupCtx = nullptr;
@@ -343,9 +322,11 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
343322
// refer to a member of an unknown specialization.
344323
// In C++2a, in several contexts a 'typename' is not required. Also
345324
// allow this as an extension.
325+
if (AllowImplicitTypename == ImplicitTypenameContext::No &&
326+
!isClassName && !IsCtorOrDtorName)
327+
return nullptr;
328+
bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
346329
if (IsImplicitTypename) {
347-
if (AllowImplicitTypename == ImplicitTypenameContext::No)
348-
return nullptr;
349330
SourceLocation QualifiedLoc = SS->getRange().getBegin();
350331
if (getLangOpts().CPlusPlus20)
351332
Diag(QualifiedLoc, diag::warn_cxx17_compat_implicit_typename);
@@ -534,10 +515,18 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
534515
// C++ [class.qual]p2: A lookup that would find the injected-class-name
535516
// instead names the constructors of the class, except when naming a class.
536517
// This is ill-formed when we're not actually forming a ctor or dtor name.
537-
T = getTypeDeclType(LookupCtx,
538-
IsImplicitTypename ? DiagCtorKind::Implicit
539-
: DiagCtorKind::None,
540-
TD, NameLoc);
518+
auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
519+
auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
520+
if (!isClassName && !IsCtorOrDtorName && LookupRD && FoundRD &&
521+
FoundRD->isInjectedClassName() &&
522+
declaresSameEntity(LookupRD, cast<Decl>(FoundRD->getParent())))
523+
Diag(NameLoc, diag::err_out_of_line_qualified_id_type_names_constructor)
524+
<< &II << /*Type*/1;
525+
526+
DiagnoseUseOfDecl(IIDecl, NameLoc);
527+
528+
T = Context.getTypeDeclType(TD);
529+
MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
541530
} else if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(IIDecl)) {
542531
(void)DiagnoseUseOfDecl(IDecl, NameLoc);
543532
if (!HasTrailingDot)
@@ -8165,7 +8154,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
81658154
(D.getCXXScopeSpec().isSet() && DC && DC->isRecord() &&
81668155
DC->isDependentContext())
81678156
? TPC_ClassTemplateMember
8168-
: TPC_VarTemplate))
8157+
: TPC_Other))
81698158
NewVD->setInvalidDecl();
81708159

81718160
// If we are providing an explicit specialization of a static variable

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13586,7 +13586,7 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S, AccessSpecifier AS,
1358613586
// Merge any previous default template arguments into our parameters,
1358713587
// and check the parameter list.
1358813588
if (CheckTemplateParameterList(TemplateParams, OldTemplateParams,
13589-
TPC_TypeAliasTemplate))
13589+
TPC_Other))
1359013590
return nullptr;
1359113591

1359213592
TypeAliasTemplateDecl *NewDecl =

0 commit comments

Comments
 (0)