Skip to content

Commit a3915ed

Browse files
authored
Merge branch 'main' into fix-invalid-base-ice
2 parents 5398419 + 9293b65 commit a3915ed

File tree

129 files changed

+2941
-609
lines changed

Some content is hidden

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

129 files changed

+2941
-609
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,9 @@ Bug Fixes to C++ Support
920920
- Correctly handle allocations in the condition of a ``if constexpr``.(#GH120197) (#GH134820)
921921
- Fixed a crash when handling invalid member using-declaration in C++20+ mode. (#GH63254)
922922
- Fix a crash when trying to instantiate an ambiguous specialization. (#GH51866)
923+
- Improved handling of variables with ``consteval`` constructors, to
924+
consistently treat the initializer as manifestly constant-evaluated.
925+
(#GH135281)
923926
- Switch `ParseBaseClause` to use `BaseResult::isUsable()` instead of `isInvalid()`, fixing dropped or mis-parsed base specifiers in C++ classes. (#GH147186)
924927

925928
Bug Fixes to AST Handling

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x32_fp8_fp8, "V16fV2iV4iV16fiIiI
429429

430430
TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_bf8, "fiIi", "nc", "fp8-conversion-insts")
431431
TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_fp8, "fiIi", "nc", "fp8-conversion-insts")
432+
TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_fp8_e5m3, "fiIi", "nc", "fp8e5m3-insts")
432433
TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f32_bf8, "V2fiIb", "nc", "fp8-conversion-insts")
433434
TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f32_fp8, "V2fiIb", "nc", "fp8-conversion-insts")
434435
TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_bf8_f32, "iffiIb", "nc", "fp8-conversion-insts")

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6761,6 +6761,7 @@ class Sema final : public SemaBase {
67616761
EK_Decltype,
67626762
EK_TemplateArgument,
67636763
EK_AttrArgument,
6764+
EK_VariableInit,
67646765
EK_Other
67656766
} ExprContext;
67666767

clang/lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
27102710
break;
27112711
}
27122712
case InitKind::Uninitialized: {
2713+
InitializerScopeRAII InitScope(*this, D, ThisDecl);
27132714
Actions.ActOnUninitializedDecl(ThisDecl);
27142715
break;
27152716
}

clang/lib/Sema/SemaCoroutine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ static bool checkSuspensionContext(Sema &S, SourceLocation Loc,
783783
const auto ExprContext = S.currentEvaluationContext().ExprContext;
784784
const bool BadContext =
785785
S.isUnevaluatedContext() ||
786-
ExprContext != Sema::ExpressionEvaluationContextRecord::EK_Other;
786+
(ExprContext != Sema::ExpressionEvaluationContextRecord::EK_Other &&
787+
ExprContext != Sema::ExpressionEvaluationContextRecord::EK_VariableInit);
787788
if (BadContext) {
788789
S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword;
789790
return false;

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18892,7 +18892,8 @@ void Sema::ActOnCXXEnterDeclInitializer(Scope *S, Decl *D) {
1889218892
EnterDeclaratorContext(S, D->getDeclContext());
1889318893

1889418894
PushExpressionEvaluationContext(
18895-
ExpressionEvaluationContext::PotentiallyEvaluated, D);
18895+
ExpressionEvaluationContext::PotentiallyEvaluated, D,
18896+
ExpressionEvaluationContextRecord::EK_VariableInit);
1889618897
}
1889718898

1889818899
void Sema::ActOnCXXExitDeclInitializer(Scope *S, Decl *D) {
@@ -18901,29 +18902,6 @@ void Sema::ActOnCXXExitDeclInitializer(Scope *S, Decl *D) {
1890118902
if (S && D->isOutOfLine())
1890218903
ExitDeclaratorContext(S);
1890318904

18904-
if (getLangOpts().CPlusPlus23) {
18905-
// An expression or conversion is 'manifestly constant-evaluated' if it is:
18906-
// [...]
18907-
// - the initializer of a variable that is usable in constant expressions or
18908-
// has constant initialization.
18909-
if (auto *VD = dyn_cast<VarDecl>(D);
18910-
VD && (VD->isUsableInConstantExpressions(Context) ||
18911-
VD->hasConstantInitialization())) {
18912-
// An expression or conversion is in an 'immediate function context' if it
18913-
// is potentially evaluated and either:
18914-
// [...]
18915-
// - it is a subexpression of a manifestly constant-evaluated expression
18916-
// or conversion.
18917-
ExprEvalContexts.back().InImmediateFunctionContext = true;
18918-
}
18919-
}
18920-
18921-
// Unless the initializer is in an immediate function context (as determined
18922-
// above), this will evaluate all contained immediate function calls as
18923-
// constant expressions. If the initializer IS an immediate function context,
18924-
// the initializer has been determined to be a constant expression, and all
18925-
// such evaluations will be elided (i.e., as if we "knew the whole time" that
18926-
// it was a constant expression).
1892718905
PopExpressionEvaluationContext();
1892818906
}
1892918907

clang/lib/Sema/SemaExpr.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17934,6 +17934,25 @@ HandleImmediateInvocations(Sema &SemaRef,
1793417934
Rec.isImmediateFunctionContext() || SemaRef.RebuildingImmediateInvocation)
1793517935
return;
1793617936

17937+
// An expression or conversion is 'manifestly constant-evaluated' if it is:
17938+
// [...]
17939+
// - the initializer of a variable that is usable in constant expressions or
17940+
// has constant initialization.
17941+
if (SemaRef.getLangOpts().CPlusPlus23 &&
17942+
Rec.ExprContext ==
17943+
Sema::ExpressionEvaluationContextRecord::EK_VariableInit) {
17944+
auto *VD = cast<VarDecl>(Rec.ManglingContextDecl);
17945+
if (VD->isUsableInConstantExpressions(SemaRef.Context) ||
17946+
VD->hasConstantInitialization()) {
17947+
// An expression or conversion is in an 'immediate function context' if it
17948+
// is potentially evaluated and either:
17949+
// [...]
17950+
// - it is a subexpression of a manifestly constant-evaluated expression
17951+
// or conversion.
17952+
return;
17953+
}
17954+
}
17955+
1793717956
/// When we have more than 1 ImmediateInvocationCandidates or previously
1793817957
/// failed immediate invocations, we need to check for nested
1793917958
/// ImmediateInvocationCandidates in order to avoid duplicate diagnostics.

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,7 +3029,7 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
30293029
LocalInstantiationScope Scope(SemaRef, MergeWithParentScope);
30303030

30313031
Sema::LambdaScopeForCallOperatorInstantiationRAII LambdaScope(
3032-
SemaRef, const_cast<CXXMethodDecl *>(D), TemplateArgs, Scope);
3032+
SemaRef, D, TemplateArgs, Scope);
30333033

30343034
// Instantiate enclosing template arguments for friends.
30353035
SmallVector<TemplateParameterList *, 4> TempParamLists;
@@ -6103,7 +6103,8 @@ void Sema::InstantiateVariableInitializer(
61036103
ContextRAII SwitchContext(*this, Var->getDeclContext());
61046104

61056105
EnterExpressionEvaluationContext Evaluated(
6106-
*this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated, Var);
6106+
*this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated, Var,
6107+
ExpressionEvaluationContextRecord::EK_VariableInit);
61076108
currentEvaluationContext().InLifetimeExtendingContext =
61086109
parentEvaluationContext().InLifetimeExtendingContext;
61096110
currentEvaluationContext().RebuildDefaultArgOrDefaultInit =

clang/test/CodeGenOpenCL/amdgpu-features.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
// GFX1153: "target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot12-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
109109
// GFX1200: "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-buffer-pk-add-bf16-inst,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot11-insts,+dot12-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+fp8-conversion-insts,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
110110
// GFX1201: "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-buffer-pk-add-bf16-inst,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot11-insts,+dot12-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+fp8-conversion-insts,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
111-
// GFX1250: "target-features"="+16-bit-insts,+ashr-pk-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-buffer-pk-add-bf16-inst,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+bitop3-insts,+ci-insts,+dl-insts,+dot7-insts,+dot8-insts,+dpp,+fp8-conversion-insts,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx1250-insts,+gfx8-insts,+gfx9-insts,+permlane16-swap,+prng-inst,+setprio-inc-wg-inst,+transpose-load-f4f6-insts,+wavefrontsize32"
111+
// GFX1250: "target-features"="+16-bit-insts,+ashr-pk-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-buffer-pk-add-bf16-inst,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+bitop3-insts,+ci-insts,+dl-insts,+dot7-insts,+dot8-insts,+dpp,+fp8-conversion-insts,+fp8e5m3-insts,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx1250-insts,+gfx8-insts,+gfx9-insts,+permlane16-swap,+prng-inst,+setprio-inc-wg-inst,+transpose-load-f4f6-insts,+wavefrontsize32"
112112

113113
// GFX1103-W64: "target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot12-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize64"
114114

clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,41 @@ void test_cvt_pk_f16_bf8(global half2* out, short a)
139139
{
140140
out[0] = __builtin_amdgcn_cvt_pk_f16_bf8(a);
141141
}
142+
143+
// CHECK-LABEL: @test_cvt_f32_fp8_e5m3(
144+
// CHECK-NEXT: entry:
145+
// CHECK-NEXT: [[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5)
146+
// CHECK-NEXT: [[A_ADDR:%.*]] = alloca i32, align 4, addrspace(5)
147+
// CHECK-NEXT: [[OUT_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[OUT_ADDR]] to ptr
148+
// CHECK-NEXT: [[A_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A_ADDR]] to ptr
149+
// CHECK-NEXT: store ptr addrspace(1) [[OUT:%.*]], ptr [[OUT_ADDR_ASCAST]], align 8
150+
// CHECK-NEXT: store i32 [[A:%.*]], ptr [[A_ADDR_ASCAST]], align 4
151+
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[A_ADDR_ASCAST]], align 4
152+
// CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.amdgcn.cvt.f32.fp8.e5m3(i32 [[TMP0]], i32 0)
153+
// CHECK-NEXT: [[CONV:%.*]] = fptosi float [[TMP1]] to i32
154+
// CHECK-NEXT: [[TMP2:%.*]] = load ptr addrspace(1), ptr [[OUT_ADDR_ASCAST]], align 8
155+
// CHECK-NEXT: store i32 [[CONV]], ptr addrspace(1) [[TMP2]], align 4
156+
// CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[A_ADDR_ASCAST]], align 4
157+
// CHECK-NEXT: [[TMP4:%.*]] = call float @llvm.amdgcn.cvt.f32.fp8.e5m3(i32 [[TMP3]], i32 1)
158+
// CHECK-NEXT: [[CONV1:%.*]] = fptosi float [[TMP4]] to i32
159+
// CHECK-NEXT: [[TMP5:%.*]] = load ptr addrspace(1), ptr [[OUT_ADDR_ASCAST]], align 8
160+
// CHECK-NEXT: store i32 [[CONV1]], ptr addrspace(1) [[TMP5]], align 4
161+
// CHECK-NEXT: [[TMP6:%.*]] = load i32, ptr [[A_ADDR_ASCAST]], align 4
162+
// CHECK-NEXT: [[TMP7:%.*]] = call float @llvm.amdgcn.cvt.f32.fp8.e5m3(i32 [[TMP6]], i32 2)
163+
// CHECK-NEXT: [[CONV2:%.*]] = fptosi float [[TMP7]] to i32
164+
// CHECK-NEXT: [[TMP8:%.*]] = load ptr addrspace(1), ptr [[OUT_ADDR_ASCAST]], align 8
165+
// CHECK-NEXT: store i32 [[CONV2]], ptr addrspace(1) [[TMP8]], align 4
166+
// CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[A_ADDR_ASCAST]], align 4
167+
// CHECK-NEXT: [[TMP10:%.*]] = call float @llvm.amdgcn.cvt.f32.fp8.e5m3(i32 [[TMP9]], i32 3)
168+
// CHECK-NEXT: [[CONV3:%.*]] = fptosi float [[TMP10]] to i32
169+
// CHECK-NEXT: [[TMP11:%.*]] = load ptr addrspace(1), ptr [[OUT_ADDR_ASCAST]], align 8
170+
// CHECK-NEXT: store i32 [[CONV3]], ptr addrspace(1) [[TMP11]], align 4
171+
// CHECK-NEXT: ret void
172+
//
173+
void test_cvt_f32_fp8_e5m3(global int* out, int a)
174+
{
175+
*out = __builtin_amdgcn_cvt_f32_fp8_e5m3(a, 0);
176+
*out = __builtin_amdgcn_cvt_f32_fp8_e5m3(a, 1);
177+
*out = __builtin_amdgcn_cvt_f32_fp8_e5m3(a, 2);
178+
*out = __builtin_amdgcn_cvt_f32_fp8_e5m3(a, 3);
179+
}

0 commit comments

Comments
 (0)