Skip to content

Commit 45eb496

Browse files
authored
merge main into amd-staging (llvm#4564)
2 parents 8362f36 + 75afed1 commit 45eb496

File tree

20 files changed

+756
-517
lines changed

20 files changed

+756
-517
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ AST Dumping Potentially Breaking Changes
128128

129129
- Default arguments of template template parameters are pretty-printed now.
130130

131+
- Pretty-printing of ``asm`` attributes are now always the first attribute
132+
on the right side of the declaration. Before we had, e.g.:
133+
134+
``__attribute__(("visibility")) asm("string")``
135+
136+
Now we have:
137+
138+
``asm("string") __attribute__(("visibility"))``
139+
140+
Which is accepted by both clang and gcc parsers.
141+
131142
Clang Frontend Potentially Breaking Changes
132143
-------------------------------------------
133144
- Members of anonymous unions/structs are now injected as ``IndirectFieldDecl``
@@ -726,6 +737,7 @@ Bug Fixes to C++ Support
726737
- Fix a crash when attempting to deduce a deduction guide from a non deducible template template parameter. (#130604)
727738
- Fix for clang incorrectly rejecting the default construction of a union with
728739
nontrivial member when another member has an initializer. (#GH81774)
740+
- Fixed a template depth issue when parsing lambdas inside a type constraint. (#GH162092)
729741
- Diagnose unresolved overload sets in non-dependent compound requirements. (#GH51246) (#GH97753)
730742

731743
Bug Fixes to AST Handling

clang/include/clang/Sema/Sema.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3961,6 +3961,13 @@ class Sema final : public SemaBase {
39613961
bool &AddToScope,
39623962
ArrayRef<BindingDecl *> Bindings = {});
39633963

3964+
private:
3965+
// Perform a check on an AsmLabel to verify its consistency and emit
3966+
// diagnostics in case of an error.
3967+
void CheckAsmLabel(Scope *S, Expr *AsmLabelExpr, StorageClass SC,
3968+
TypeSourceInfo *TInfo, VarDecl *);
3969+
3970+
public:
39643971
/// Perform semantic checking on a newly-created variable
39653972
/// declaration.
39663973
///

clang/lib/Parse/ParseTemplate.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,12 @@ bool Parser::isTypeConstraintAnnotation() {
533533
bool Parser::TryAnnotateTypeConstraint() {
534534
if (!getLangOpts().CPlusPlus20)
535535
return false;
536+
// The type constraint may declare template parameters, notably
537+
// if it contains a generic lambda, so we need to increment
538+
// the template depth as these parameters would not be instantiated
539+
// at the current depth.
540+
TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
541+
++CurTemplateDepthTracker;
536542
CXXScopeSpec SS;
537543
bool WasScopeAnnotation = Tok.is(tok::annot_cxxscope);
538544
if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,

clang/lib/Sema/SemaDecl.cpp

Lines changed: 77 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7640,6 +7640,58 @@ static bool isMainVar(DeclarationName Name, VarDecl *VD) {
76407640
VD->isExternC());
76417641
}
76427642

7643+
void Sema::CheckAsmLabel(Scope *S, Expr *E, StorageClass SC,
7644+
TypeSourceInfo *TInfo, VarDecl *NewVD) {
7645+
7646+
// Quickly return if the function does not have an `asm` attribute.
7647+
if (E == nullptr)
7648+
return;
7649+
7650+
// The parser guarantees this is a string.
7651+
StringLiteral *SE = cast<StringLiteral>(E);
7652+
StringRef Label = SE->getString();
7653+
QualType R = TInfo->getType();
7654+
if (S->getFnParent() != nullptr) {
7655+
switch (SC) {
7656+
case SC_None:
7657+
case SC_Auto:
7658+
Diag(E->getExprLoc(), diag::warn_asm_label_on_auto_decl) << Label;
7659+
break;
7660+
case SC_Register:
7661+
// Local Named register
7662+
if (!Context.getTargetInfo().isValidGCCRegisterName(Label) &&
7663+
DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl()))
7664+
Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
7665+
break;
7666+
case SC_Static:
7667+
case SC_Extern:
7668+
case SC_PrivateExtern:
7669+
break;
7670+
}
7671+
} else if (SC == SC_Register) {
7672+
// Global Named register
7673+
if (DeclAttrsMatchCUDAMode(getLangOpts(), NewVD)) {
7674+
const auto &TI = Context.getTargetInfo();
7675+
bool HasSizeMismatch;
7676+
7677+
if (!TI.isValidGCCRegisterName(Label))
7678+
Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
7679+
else if (!TI.validateGlobalRegisterVariable(Label, Context.getTypeSize(R),
7680+
HasSizeMismatch))
7681+
Diag(E->getExprLoc(), diag::err_asm_invalid_global_var_reg) << Label;
7682+
else if (HasSizeMismatch)
7683+
Diag(E->getExprLoc(), diag::err_asm_register_size_mismatch) << Label;
7684+
}
7685+
7686+
if (!R->isIntegralType(Context) && !R->isPointerType()) {
7687+
Diag(TInfo->getTypeLoc().getBeginLoc(),
7688+
diag::err_asm_unsupported_register_type)
7689+
<< TInfo->getTypeLoc().getSourceRange();
7690+
NewVD->setInvalidDecl(true);
7691+
}
7692+
}
7693+
}
7694+
76437695
NamedDecl *Sema::ActOnVariableDeclarator(
76447696
Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo,
76457697
LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists,
@@ -8124,6 +8176,26 @@ NamedDecl *Sema::ActOnVariableDeclarator(
81248176
}
81258177
}
81268178

8179+
if (Expr *E = D.getAsmLabel()) {
8180+
// The parser guarantees this is a string.
8181+
StringLiteral *SE = cast<StringLiteral>(E);
8182+
StringRef Label = SE->getString();
8183+
8184+
// Insert the asm attribute.
8185+
NewVD->addAttr(AsmLabelAttr::Create(Context, Label, SE->getStrTokenLoc(0)));
8186+
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
8187+
llvm::DenseMap<IdentifierInfo *, AsmLabelAttr *>::iterator I =
8188+
ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
8189+
if (I != ExtnameUndeclaredIdentifiers.end()) {
8190+
if (isDeclExternC(NewVD)) {
8191+
NewVD->addAttr(I->second);
8192+
ExtnameUndeclaredIdentifiers.erase(I);
8193+
} else
8194+
Diag(NewVD->getLocation(), diag::warn_redefine_extname_not_applied)
8195+
<< /*Variable*/ 1 << NewVD;
8196+
}
8197+
}
8198+
81278199
// Handle attributes prior to checking for duplicates in MergeVarDecl
81288200
ProcessDeclAttributes(S, NewVD, D);
81298201

@@ -8174,65 +8246,11 @@ NamedDecl *Sema::ActOnVariableDeclarator(
81748246
if (getLangOpts().ObjCAutoRefCount && ObjC().inferObjCARCLifetime(NewVD))
81758247
NewVD->setInvalidDecl();
81768248

8177-
// Handle GNU asm-label extension (encoded as an attribute).
8178-
if (Expr *E = D.getAsmLabel()) {
8179-
// The parser guarantees this is a string.
8180-
StringLiteral *SE = cast<StringLiteral>(E);
8181-
StringRef Label = SE->getString();
8182-
if (S->getFnParent() != nullptr) {
8183-
switch (SC) {
8184-
case SC_None:
8185-
case SC_Auto:
8186-
Diag(E->getExprLoc(), diag::warn_asm_label_on_auto_decl) << Label;
8187-
break;
8188-
case SC_Register:
8189-
// Local Named register
8190-
if (!Context.getTargetInfo().isValidGCCRegisterName(Label) &&
8191-
DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl()))
8192-
Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
8193-
break;
8194-
case SC_Static:
8195-
case SC_Extern:
8196-
case SC_PrivateExtern:
8197-
break;
8198-
}
8199-
} else if (SC == SC_Register) {
8200-
// Global Named register
8201-
if (DeclAttrsMatchCUDAMode(getLangOpts(), NewVD)) {
8202-
const auto &TI = Context.getTargetInfo();
8203-
bool HasSizeMismatch;
8204-
8205-
if (!TI.isValidGCCRegisterName(Label))
8206-
Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
8207-
else if (!TI.validateGlobalRegisterVariable(Label,
8208-
Context.getTypeSize(R),
8209-
HasSizeMismatch))
8210-
Diag(E->getExprLoc(), diag::err_asm_invalid_global_var_reg) << Label;
8211-
else if (HasSizeMismatch)
8212-
Diag(E->getExprLoc(), diag::err_asm_register_size_mismatch) << Label;
8213-
}
8214-
8215-
if (!R->isIntegralType(Context) && !R->isPointerType()) {
8216-
Diag(TInfo->getTypeLoc().getBeginLoc(),
8217-
diag::err_asm_unsupported_register_type)
8218-
<< TInfo->getTypeLoc().getSourceRange();
8219-
NewVD->setInvalidDecl(true);
8220-
}
8221-
}
8222-
8223-
NewVD->addAttr(AsmLabelAttr::Create(Context, Label, SE->getStrTokenLoc(0)));
8224-
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
8225-
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
8226-
ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
8227-
if (I != ExtnameUndeclaredIdentifiers.end()) {
8228-
if (isDeclExternC(NewVD)) {
8229-
NewVD->addAttr(I->second);
8230-
ExtnameUndeclaredIdentifiers.erase(I);
8231-
} else
8232-
Diag(NewVD->getLocation(), diag::warn_redefine_extname_not_applied)
8233-
<< /*Variable*/1 << NewVD;
8234-
}
8235-
}
8249+
// Check the ASM label here, as we need to know all other attributes of the
8250+
// Decl first. Otherwise, we can't know if the asm label refers to the
8251+
// host or device in a CUDA context. The device has other registers than
8252+
// host and we must know where the function will be placed.
8253+
CheckAsmLabel(S, D.getAsmLabel(), SC, TInfo, NewVD);
82368254

82378255
// Find the shadowed declaration before filtering for scope.
82388256
NamedDecl *ShadowedDecl = D.getCXXScopeSpec().isEmpty()

clang/test/Sema/attr-print.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ int * __sptr * __ptr32 ppsp32;
3535

3636
// CHECK: __attribute__((availability(macos, strict, introduced=10.6)));
3737
void f6(int) __attribute__((availability(macosx,strict,introduced=10.6)));
38+
39+
// CHECK: _libc_intl_domainname asm("__gi__libc_intl_domainname") __attribute__((visibility("hidden")));
40+
extern const char _libc_intl_domainname[]; extern typeof (_libc_intl_domainname) _libc_intl_domainname asm("__gi__libc_intl_domainname") __attribute__((visibility("hidden")));

clang/test/SemaTemplate/concepts.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,31 @@ static_assert( requires {{ &f } -> C;} ); // expected-error {{reference to overl
15141514

15151515
}
15161516

1517+
namespace GH162092 {
1518+
1519+
template <typename T>
1520+
struct vector;
1521+
1522+
template <typename T, typename U>
1523+
concept C = __is_same_as(T, U);
1524+
1525+
template<class T, auto Cpt>
1526+
concept generic_range_value = requires {
1527+
Cpt.template operator()<int>();
1528+
};
1529+
1530+
1531+
template<generic_range_value<[]<
1532+
C<int>
1533+
>() {}> T>
1534+
void x() {}
1535+
1536+
void foo() {
1537+
x<vector<int>>();
1538+
}
1539+
1540+
}
1541+
15171542
namespace GH162770 {
15181543
enum e {};
15191544
template<e> struct s {};

llvm/include/llvm/ADT/APFloat.h

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,16 @@ enum lostFraction { // Example of truncated bits:
138138
/// New operations: sqrt, IEEE remainder, C90 fmod, nexttoward.
139139
///
140140

141+
namespace detail {
142+
class IEEEFloat;
143+
class DoubleAPFloat;
144+
} // namespace detail
145+
141146
// This is the common type definitions shared by APFloat and its internal
142147
// implementation classes. This struct should not define any non-static data
143148
// members.
144-
struct APFloatBase {
149+
class APFloatBase {
150+
public:
145151
typedef APInt::WordType integerPart;
146152
static constexpr unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD;
147153

@@ -257,30 +263,64 @@ struct APFloatBase {
257263
LLVM_ABI static const llvm::fltSemantics &EnumToSemantics(Semantics S);
258264
LLVM_ABI static Semantics SemanticsToEnum(const llvm::fltSemantics &Sem);
259265

260-
LLVM_ABI static const fltSemantics &IEEEhalf() LLVM_READNONE;
261-
LLVM_ABI static const fltSemantics &BFloat() LLVM_READNONE;
262-
LLVM_ABI static const fltSemantics &IEEEsingle() LLVM_READNONE;
263-
LLVM_ABI static const fltSemantics &IEEEdouble() LLVM_READNONE;
264-
LLVM_ABI static const fltSemantics &IEEEquad() LLVM_READNONE;
265-
LLVM_ABI static const fltSemantics &PPCDoubleDouble() LLVM_READNONE;
266-
LLVM_ABI static const fltSemantics &PPCDoubleDoubleLegacy() LLVM_READNONE;
267-
LLVM_ABI static const fltSemantics &Float8E5M2() LLVM_READNONE;
268-
LLVM_ABI static const fltSemantics &Float8E5M2FNUZ() LLVM_READNONE;
269-
LLVM_ABI static const fltSemantics &Float8E4M3() LLVM_READNONE;
270-
LLVM_ABI static const fltSemantics &Float8E4M3FN() LLVM_READNONE;
271-
LLVM_ABI static const fltSemantics &Float8E4M3FNUZ() LLVM_READNONE;
272-
LLVM_ABI static const fltSemantics &Float8E4M3B11FNUZ() LLVM_READNONE;
273-
LLVM_ABI static const fltSemantics &Float8E3M4() LLVM_READNONE;
274-
LLVM_ABI static const fltSemantics &FloatTF32() LLVM_READNONE;
275-
LLVM_ABI static const fltSemantics &Float8E8M0FNU() LLVM_READNONE;
276-
LLVM_ABI static const fltSemantics &Float6E3M2FN() LLVM_READNONE;
277-
LLVM_ABI static const fltSemantics &Float6E2M3FN() LLVM_READNONE;
278-
LLVM_ABI static const fltSemantics &Float4E2M1FN() LLVM_READNONE;
279-
LLVM_ABI static const fltSemantics &x87DoubleExtended() LLVM_READNONE;
266+
private:
267+
LLVM_ABI static const fltSemantics semIEEEhalf;
268+
LLVM_ABI static const fltSemantics semBFloat;
269+
LLVM_ABI static const fltSemantics semIEEEsingle;
270+
LLVM_ABI static const fltSemantics semIEEEdouble;
271+
LLVM_ABI static const fltSemantics semIEEEquad;
272+
LLVM_ABI static const fltSemantics semFloat8E5M2;
273+
LLVM_ABI static const fltSemantics semFloat8E5M2FNUZ;
274+
LLVM_ABI static const fltSemantics semFloat8E4M3;
275+
LLVM_ABI static const fltSemantics semFloat8E4M3FN;
276+
LLVM_ABI static const fltSemantics semFloat8E4M3FNUZ;
277+
LLVM_ABI static const fltSemantics semFloat8E4M3B11FNUZ;
278+
LLVM_ABI static const fltSemantics semFloat8E3M4;
279+
LLVM_ABI static const fltSemantics semFloatTF32;
280+
LLVM_ABI static const fltSemantics semFloat8E8M0FNU;
281+
LLVM_ABI static const fltSemantics semFloat6E3M2FN;
282+
LLVM_ABI static const fltSemantics semFloat6E2M3FN;
283+
LLVM_ABI static const fltSemantics semFloat4E2M1FN;
284+
LLVM_ABI static const fltSemantics semX87DoubleExtended;
285+
LLVM_ABI static const fltSemantics semBogus;
286+
LLVM_ABI static const fltSemantics semPPCDoubleDouble;
287+
LLVM_ABI static const fltSemantics semPPCDoubleDoubleLegacy;
288+
289+
friend class detail::IEEEFloat;
290+
friend class detail::DoubleAPFloat;
291+
friend class APFloat;
292+
293+
public:
294+
static const fltSemantics &IEEEhalf() { return semIEEEhalf; }
295+
static const fltSemantics &BFloat() { return semBFloat; }
296+
static const fltSemantics &IEEEsingle() { return semIEEEsingle; }
297+
static const fltSemantics &IEEEdouble() { return semIEEEdouble; }
298+
static const fltSemantics &IEEEquad() { return semIEEEquad; }
299+
static const fltSemantics &PPCDoubleDouble() { return semPPCDoubleDouble; }
300+
static const fltSemantics &PPCDoubleDoubleLegacy() {
301+
return semPPCDoubleDoubleLegacy;
302+
}
303+
static const fltSemantics &Float8E5M2() { return semFloat8E5M2; }
304+
static const fltSemantics &Float8E5M2FNUZ() { return semFloat8E5M2FNUZ; }
305+
static const fltSemantics &Float8E4M3() { return semFloat8E4M3; }
306+
static const fltSemantics &Float8E4M3FN() { return semFloat8E4M3FN; }
307+
static const fltSemantics &Float8E4M3FNUZ() { return semFloat8E4M3FNUZ; }
308+
static const fltSemantics &Float8E4M3B11FNUZ() {
309+
return semFloat8E4M3B11FNUZ;
310+
}
311+
static const fltSemantics &Float8E3M4() { return semFloat8E3M4; }
312+
static const fltSemantics &FloatTF32() { return semFloatTF32; }
313+
static const fltSemantics &Float8E8M0FNU() { return semFloat8E8M0FNU; }
314+
static const fltSemantics &Float6E3M2FN() { return semFloat6E3M2FN; }
315+
static const fltSemantics &Float6E2M3FN() { return semFloat6E2M3FN; }
316+
static const fltSemantics &Float4E2M1FN() { return semFloat4E2M1FN; }
317+
static const fltSemantics &x87DoubleExtended() {
318+
return semX87DoubleExtended;
319+
}
280320

281321
/// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
282322
/// anything real.
283-
LLVM_ABI static const fltSemantics &Bogus() LLVM_READNONE;
323+
static const fltSemantics &Bogus() { return semBogus; }
284324

285325
// Returns true if any number described by this semantics can be precisely
286326
// represented by the specified semantics. Does not take into account

0 commit comments

Comments
 (0)