Skip to content

Commit 6cb982b

Browse files
Merge branch 'main' into submit
2 parents 50c3b02 + 0732693 commit 6cb982b

Some content is hidden

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

41 files changed

+601
-202
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ Bug Fixes to C++ Support
225225
- Diagnose binding a reference to ``*nullptr`` during constant evaluation. (#GH48665)
226226
- Suppress ``-Wdeprecated-declarations`` in implicitly generated functions. (#GH147293)
227227
- Fix a crash when deleting a pointer to an incomplete array (#GH150359).
228-
- Fixed a mismatched lambda scope bug when propagating up ``consteval`` within nested lambdas. (#GH145776)
229228
- Fix an assertion failure when expression in assumption attribute
230229
(``[[assume(expr)]]``) creates temporary objects.
231230
- Fix the dynamic_cast to final class optimization to correctly handle

clang/include/clang/Sema/Sema.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4176,15 +4176,8 @@ class Sema final : public SemaBase {
41764176
/// return statement in the scope of a variable has the same NRVO candidate,
41774177
/// that candidate is an NRVO variable.
41784178
void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
4179-
4180-
/// Performs semantic analysis at the end of a function body.
4181-
///
4182-
/// \param RetainFunctionScopeInfo If \c true, the client is responsible for
4183-
/// releasing the associated \p FunctionScopeInfo. This is useful when
4184-
/// building e.g. LambdaExprs.
4185-
Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body,
4186-
bool IsInstantiation = false,
4187-
bool RetainFunctionScopeInfo = false);
4179+
Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
4180+
Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
41884181
Decl *ActOnSkippedFunctionBody(Decl *Decl);
41894182
void ActOnFinishInlineFunctionDef(FunctionDecl *D);
41904183

@@ -6881,23 +6874,23 @@ class Sema final : public SemaBase {
68816874
assert(!ExprEvalContexts.empty() &&
68826875
"Must be in an expression evaluation context");
68836876
return ExprEvalContexts.back();
6884-
}
6877+
};
68856878

68866879
ExpressionEvaluationContextRecord &currentEvaluationContext() {
68876880
assert(!ExprEvalContexts.empty() &&
68886881
"Must be in an expression evaluation context");
68896882
return ExprEvalContexts.back();
6890-
}
6883+
};
68916884

68926885
ExpressionEvaluationContextRecord &parentEvaluationContext() {
68936886
assert(ExprEvalContexts.size() >= 2 &&
68946887
"Must be in an expression evaluation context");
68956888
return ExprEvalContexts[ExprEvalContexts.size() - 2];
6896-
}
6889+
};
68976890

68986891
const ExpressionEvaluationContextRecord &parentEvaluationContext() const {
68996892
return const_cast<Sema *>(this)->parentEvaluationContext();
6900-
}
6893+
};
69016894

69026895
bool isAttrContext() const {
69036896
return ExprEvalContexts.back().ExprContext ==
@@ -9147,7 +9140,8 @@ class Sema final : public SemaBase {
91479140

91489141
/// Complete a lambda-expression having processed and attached the
91499142
/// lambda body.
9150-
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc);
9143+
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
9144+
sema::LambdaScopeInfo *LSI);
91519145

91529146
/// Get the return type to use for a lambda's conversion function(s) to
91539147
/// function pointer type, given the type of the call operator.

clang/lib/Sema/SemaDecl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16228,6 +16228,10 @@ Decl *Sema::ActOnSkippedFunctionBody(Decl *Decl) {
1622816228
return Decl;
1622916229
}
1623016230

16231+
Decl *Sema::ActOnFinishFunctionBody(Decl *D, Stmt *BodyArg) {
16232+
return ActOnFinishFunctionBody(D, BodyArg, /*IsInstantiation=*/false);
16233+
}
16234+
1623116235
/// RAII object that pops an ExpressionEvaluationContext when exiting a function
1623216236
/// body.
1623316237
class ExitFunctionBodyRAII {
@@ -16298,8 +16302,8 @@ void Sema::CheckCoroutineWrapper(FunctionDecl *FD) {
1629816302
Diag(FD->getLocation(), diag::err_coroutine_return_type) << RD;
1629916303
}
1630016304

16301-
Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, bool IsInstantiation,
16302-
bool RetainFunctionScopeInfo) {
16305+
Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
16306+
bool IsInstantiation) {
1630316307
FunctionScopeInfo *FSI = getCurFunction();
1630416308
FunctionDecl *FD = dcl ? dcl->getAsFunction() : nullptr;
1630516309

@@ -16756,8 +16760,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, bool IsInstantiation,
1675616760
if (!IsInstantiation)
1675716761
PopDeclContext();
1675816762

16759-
if (!RetainFunctionScopeInfo)
16760-
PopFunctionScopeInfo(ActivePolicy, dcl);
16763+
PopFunctionScopeInfo(ActivePolicy, dcl);
1676116764
// If any errors have occurred, clear out any temporaries that may have
1676216765
// been leftover. This ensures that these temporaries won't be picked up for
1676316766
// deletion in some later function.

clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9317,14 +9317,14 @@ AssignConvertType Sema::CheckAssignmentConstraints(QualType LHSType,
93179317
// If we have an atomic type, try a non-atomic assignment, then just add an
93189318
// atomic qualification step.
93199319
if (const AtomicType *AtomicTy = dyn_cast<AtomicType>(LHSType)) {
9320-
AssignConvertType result =
9320+
AssignConvertType Result =
93219321
CheckAssignmentConstraints(AtomicTy->getValueType(), RHS, Kind);
9322-
if (result != AssignConvertType::Compatible)
9323-
return result;
9322+
if (!IsAssignConvertCompatible(Result))
9323+
return Result;
93249324
if (Kind != CK_NoOp && ConvertRHS)
93259325
RHS = ImpCastExprToType(RHS.get(), AtomicTy->getValueType(), Kind);
93269326
Kind = CK_NonAtomicToAtomic;
9327-
return AssignConvertType::Compatible;
9327+
return Result;
93289328
}
93299329

93309330
// If the left-hand side is a reference type, then we are in a

clang/lib/Sema/SemaLambda.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,15 +1968,14 @@ ExprResult Sema::BuildCaptureInit(const Capture &Cap,
19681968
}
19691969

19701970
ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body) {
1971-
LambdaScopeInfo &LSI = *cast<LambdaScopeInfo>(FunctionScopes.back());
1971+
LambdaScopeInfo LSI = *cast<LambdaScopeInfo>(FunctionScopes.back());
19721972

19731973
if (LSI.CallOperator->hasAttr<SYCLKernelEntryPointAttr>())
19741974
SYCL().CheckSYCLEntryPointFunctionDecl(LSI.CallOperator);
19751975

1976-
ActOnFinishFunctionBody(LSI.CallOperator, Body, /*IsInstantiation=*/false,
1977-
/*RetainFunctionScopeInfo=*/true);
1976+
ActOnFinishFunctionBody(LSI.CallOperator, Body);
19781977

1979-
return BuildLambdaExpr(StartLoc, Body->getEndLoc());
1978+
return BuildLambdaExpr(StartLoc, Body->getEndLoc(), &LSI);
19801979
}
19811980

19821981
static LambdaCaptureDefault
@@ -2133,9 +2132,8 @@ ConstructFixItRangeForUnusedCapture(Sema &S, SourceRange CaptureRange,
21332132
return SourceRange(FixItStart, FixItEnd);
21342133
}
21352134

2136-
ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc,
2137-
SourceLocation EndLoc) {
2138-
LambdaScopeInfo *LSI = cast<LambdaScopeInfo>(FunctionScopes.back());
2135+
ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
2136+
LambdaScopeInfo *LSI) {
21392137
// Collect information from the lambda scope.
21402138
SmallVector<LambdaCapture, 4> Captures;
21412139
SmallVector<Expr *, 4> CaptureInits;
@@ -2172,12 +2170,6 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc,
21722170

21732171
PopExpressionEvaluationContext();
21742172

2175-
sema::AnalysisBasedWarnings::Policy WP =
2176-
AnalysisWarnings.getPolicyInEffectAt(EndLoc);
2177-
// We cannot release LSI until we finish computing captures, which
2178-
// requires the scope to be popped.
2179-
PoppedFunctionScopePtr _ = PopFunctionScopeInfo(&WP, LSI->CallOperator);
2180-
21812173
// True if the current capture has a used capture or default before it.
21822174
bool CurHasPreviousCapture = CaptureDefault != LCD_None;
21832175
SourceLocation PrevCaptureLoc = CurHasPreviousCapture ?

clang/lib/Sema/TreeTransform.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4051,7 +4051,7 @@ class TreeTransform {
40514051
PVD->getUninstantiatedDefaultArg()
40524052
->containsUnexpandedParameterPack();
40534053
}
4054-
return getSema().BuildLambdaExpr(StartLoc, EndLoc);
4054+
return getSema().BuildLambdaExpr(StartLoc, EndLoc, LSI);
40554055
}
40564056

40574057
/// Build an empty C++1z fold-expression with the given operator.
@@ -15712,9 +15712,12 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
1571215712
return ExprError();
1571315713
}
1571415714

15715+
// Copy the LSI before ActOnFinishFunctionBody removes it.
15716+
// FIXME: This is dumb. Store the lambda information somewhere that outlives
15717+
// the call operator.
15718+
auto LSICopy = *LSI;
1571515719
getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
15716-
/*IsInstantiation=*/true,
15717-
/*RetainFunctionScopeInfo=*/true);
15720+
/*IsInstantiation*/ true);
1571815721
SavedContext.pop();
1571915722

1572015723
// Recompute the dependency of the lambda so that we can defer the lambda call
@@ -15750,11 +15753,11 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
1575015753
// *after* the substitution in case we can't decide the dependency
1575115754
// so early, e.g. because we want to see if any of the *substituted*
1575215755
// parameters are dependent.
15753-
DependencyKind = getDerived().ComputeLambdaDependency(LSI);
15756+
DependencyKind = getDerived().ComputeLambdaDependency(&LSICopy);
1575415757
Class->setLambdaDependencyKind(DependencyKind);
1575515758

1575615759
return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
15757-
Body.get()->getEndLoc(), LSI);
15760+
Body.get()->getEndLoc(), &LSICopy);
1575815761
}
1575915762

1576015763
template<typename Derived>

clang/test/Sema/implicit-void-ptr-cast.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,15 @@ void more(void) {
8282
ptr3 = SOMETHING_THAT_IS_NOT_NULL; // c-warning {{implicit conversion when assigning to 'char *' from type 'void *' is not permitted in C++}} \
8383
cxx-error {{assigning to 'char *' from incompatible type 'void *'}}
8484
}
85+
86+
void gh154157(void) {
87+
#define ATOMIC_VAR_INIT(value) (value)
88+
89+
typedef const struct T * T_Ref;
90+
static T_Ref _Atomic x = ATOMIC_VAR_INIT((void*)NULL); // c-warning {{implicit conversion when initializing '_Atomic(T_Ref)' with an expression of type 'void *' is not permitted in C++}} \
91+
cxx-error {{cannot initialize a variable of type '_Atomic(T_Ref)' with an rvalue of type 'void *'}}
92+
static T_Ref const y = ATOMIC_VAR_INIT((void*)NULL); // c-warning {{implicit conversion when initializing 'const T_Ref' (aka 'const struct T *const') with an expression of type 'void *' is not permitted in C++}} \
93+
cxx-error {{cannot initialize a variable of type 'const T_Ref' (aka 'const struct T *const') with an rvalue of type 'void *'}}
94+
static T_Ref z = ATOMIC_VAR_INIT((void*)NULL); // c-warning {{implicit conversion when initializing 'T_Ref' (aka 'const struct T *') with an expression of type 'void *' is not permitted in C++}} \
95+
cxx-error {{cannot initialize a variable of type 'T_Ref' (aka 'const struct T *') with an rvalue of type 'void *'}}
96+
}

clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -610,19 +610,3 @@ namespace GH135281 {
610610
void (*ff)() = f2<B>; // expected-note {{instantiation of function template specialization}}
611611
}
612612
#endif
613-
614-
namespace GH145776 {
615-
616-
void runtime_only() {}
617-
consteval void comptime_only() {}
618-
619-
void fn() {
620-
[]() {
621-
runtime_only();
622-
[]() {
623-
&comptime_only;
624-
}();
625-
}();
626-
}
627-
628-
}

libc/config/baremetal/aarch64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
785785
libc.src.math.fminimum_magbf16
786786
libc.src.math.fminimum_mag_numbf16
787787
libc.src.math.fminimum_numbf16
788+
libc.src.math.fromfpbf16
789+
libc.src.math.fromfpxbf16
788790
libc.src.math.roundbf16
789791
libc.src.math.roundevenbf16
790792
libc.src.math.truncbf16
793+
libc.src.math.ufromfpbf16
794+
libc.src.math.ufromfpxbf16
791795
)
792796

793797
if(LIBC_TYPES_HAS_FLOAT128)

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
788788
libc.src.math.fminimum_magbf16
789789
libc.src.math.fminimum_mag_numbf16
790790
libc.src.math.fminimum_numbf16
791+
libc.src.math.fromfpbf16
792+
libc.src.math.fromfpxbf16
791793
libc.src.math.roundbf16
792794
libc.src.math.roundevenbf16
793795
libc.src.math.truncbf16
796+
libc.src.math.ufromfpbf16
797+
libc.src.math.ufromfpxbf16
794798
)
795799

796800
if(LIBC_TYPES_HAS_FLOAT128)

0 commit comments

Comments
 (0)