Skip to content

Commit 3189509

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:7c5c8b2f479fbed6afcd4072bdef76ea867577de into amd-gfx:e7c692dd6c2c
Local branch amd-gfx e7c692d Merged main:cf128305bdada3ffb34054813a855d80b3948025 into amd-gfx:6b7061457387 Remote branch main 7c5c8b2 [BOLT][NFC] Move BAT::fetchParentAddress to header (llvm#93061)
2 parents e7c692d + 7c5c8b2 commit 3189509

File tree

167 files changed

+7100
-1459
lines changed

Some content is hidden

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

167 files changed

+7100
-1459
lines changed

bolt/include/bolt/Profile/BoltAddressTranslation.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ class BoltAddressTranslation {
107107

108108
/// If available, fetch the address of the hot part linked to the cold part
109109
/// at \p Address. Return 0 otherwise.
110-
uint64_t fetchParentAddress(uint64_t Address) const;
110+
uint64_t fetchParentAddress(uint64_t Address) const {
111+
auto Iter = ColdPartSource.find(Address);
112+
if (Iter == ColdPartSource.end())
113+
return 0;
114+
return Iter->second;
115+
}
111116

112117
/// True if the input binary has a translation table we can use to convert
113118
/// addresses when aggregating profile

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,6 @@ BoltAddressTranslation::getFallthroughsInTrace(uint64_t FuncAddress,
547547
return Res;
548548
}
549549

550-
uint64_t BoltAddressTranslation::fetchParentAddress(uint64_t Address) const {
551-
auto Iter = ColdPartSource.find(Address);
552-
if (Iter == ColdPartSource.end())
553-
return 0;
554-
return Iter->second;
555-
}
556-
557550
bool BoltAddressTranslation::enabledFor(
558551
llvm::object::ELFObjectFileBase *InputFile) const {
559552
for (const SectionRef &Section : InputFile->sections()) {

clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,13 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
144144
unaryOperator(hasUnaryOperand(ArrayExpr), unless(hasOperatorName("*"))),
145145
binaryOperator(hasEitherOperand(ArrayExpr)),
146146
castExpr(hasSourceExpression(ArrayExpr))));
147-
const auto PointerToArrayExpr = ignoringParenImpCasts(
148-
hasType(hasCanonicalType(pointerType(pointee(arrayType())))));
147+
const auto PointerToArrayExpr =
148+
hasType(hasCanonicalType(pointerType(pointee(arrayType()))));
149149

150-
const auto StructAddrOfExpr = unaryOperator(
151-
hasOperatorName("&"), hasUnaryOperand(ignoringParenImpCasts(
152-
hasType(hasCanonicalType(recordType())))));
153150
const auto PointerToStructType =
154151
hasUnqualifiedDesugaredType(pointerType(pointee(recordType())));
155-
const auto PointerToStructExpr = ignoringParenImpCasts(expr(
156-
hasType(hasCanonicalType(PointerToStructType)), unless(cxxThisExpr())));
152+
const auto PointerToStructExpr = expr(
153+
hasType(hasCanonicalType(PointerToStructType)), unless(cxxThisExpr()));
157154

158155
const auto ArrayOfPointersExpr = ignoringParenImpCasts(
159156
hasType(hasCanonicalType(arrayType(hasElementType(pointerType()))
@@ -166,18 +163,19 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
166163
ignoringParenImpCasts(arraySubscriptExpr(
167164
hasBase(ArrayOfSamePointersExpr), hasIndex(ZeroLiteral)));
168165
const auto ArrayLengthExprDenom =
169-
expr(hasParent(expr(ignoringParenImpCasts(binaryOperator(
170-
hasOperatorName("/"), hasLHS(ignoringParenImpCasts(sizeOfExpr(
171-
has(ArrayOfPointersExpr)))))))),
166+
expr(hasParent(binaryOperator(hasOperatorName("/"),
167+
hasLHS(ignoringParenImpCasts(sizeOfExpr(
168+
has(ArrayOfPointersExpr)))))),
172169
sizeOfExpr(has(ArrayOfSamePointersZeroSubscriptExpr)));
173170

174-
Finder->addMatcher(expr(anyOf(sizeOfExpr(has(ignoringParenImpCasts(anyOf(
175-
ArrayCastExpr, PointerToArrayExpr,
176-
StructAddrOfExpr, PointerToStructExpr)))),
177-
sizeOfExpr(has(PointerToStructType))),
178-
unless(ArrayLengthExprDenom))
179-
.bind("sizeof-pointer-to-aggregate"),
180-
this);
171+
Finder->addMatcher(
172+
expr(sizeOfExpr(anyOf(
173+
has(ignoringParenImpCasts(anyOf(
174+
ArrayCastExpr, PointerToArrayExpr, PointerToStructExpr))),
175+
has(PointerToStructType))),
176+
unless(ArrayLengthExprDenom))
177+
.bind("sizeof-pointer-to-aggregate"),
178+
this);
181179
}
182180

183181
// Detect expression like: sizeof(expr) <= k for a suspicious constant 'k'.

clang-tools-extra/clangd/Hover.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ fetchTemplateParameters(const TemplateParameterList *Params,
262262
if (NTTP->hasDefaultArgument()) {
263263
P.Default.emplace();
264264
llvm::raw_string_ostream Out(*P.Default);
265-
NTTP->getDefaultArgument()->printPretty(Out, nullptr, PP);
265+
NTTP->getDefaultArgument().getArgument().print(PP, Out,
266+
/*IncludeType=*/false);
266267
}
267268
} else if (const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
268269
P.Type = printType(TTPD, PP);

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ Miscellaneous Bug Fixes
766766

767767
- Fixed an infinite recursion in ASTImporter, on return type declared inside
768768
body of C++11 lambda without trailing return (#GH68775).
769+
- Fixed declaration name source location of instantiated function definitions (GH71161).
769770

770771
Miscellaneous Clang Crashes Fixed
771772
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,9 @@ class ASTNodeTraverser
704704
if (const auto *E = D->getPlaceholderTypeConstraint())
705705
Visit(E);
706706
if (D->hasDefaultArgument())
707-
Visit(D->getDefaultArgument(), SourceRange(),
708-
D->getDefaultArgStorage().getInheritedFrom(),
709-
D->defaultArgumentWasInherited() ? "inherited from" : "previous");
707+
dumpTemplateArgumentLoc(
708+
D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(),
709+
D->defaultArgumentWasInherited() ? "inherited from" : "previous");
710710
}
711711

712712
void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) {

clang/include/clang/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,8 @@ class FunctionDecl : public DeclaratorDecl,
21882188

21892189
void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
21902190

2191+
void setDeclarationNameLoc(DeclarationNameLoc L) { DNLoc = L; }
2192+
21912193
/// Returns the location of the ellipsis of a variadic function.
21922194
SourceLocation getEllipsisLoc() const {
21932195
const auto *FPT = getType()->getAs<FunctionProtoType>();

clang/include/clang/AST/DeclTemplate.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,8 @@ class NonTypeTemplateParmDecl final
13601360

13611361
/// The default template argument, if any, and whether or not
13621362
/// it was inherited.
1363-
using DefArgStorage = DefaultArgStorage<NonTypeTemplateParmDecl, Expr *>;
1363+
using DefArgStorage =
1364+
DefaultArgStorage<NonTypeTemplateParmDecl, TemplateArgumentLoc *>;
13641365
DefArgStorage DefaultArgument;
13651366

13661367
// FIXME: Collapse this into TemplateParamPosition; or, just move depth/index
@@ -1430,7 +1431,10 @@ class NonTypeTemplateParmDecl final
14301431
bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
14311432

14321433
/// Retrieve the default argument, if any.
1433-
Expr *getDefaultArgument() const { return DefaultArgument.get(); }
1434+
const TemplateArgumentLoc &getDefaultArgument() const {
1435+
static const TemplateArgumentLoc NoneLoc;
1436+
return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc;
1437+
}
14341438

14351439
/// Retrieve the location of the default argument, if any.
14361440
SourceLocation getDefaultArgumentLoc() const;
@@ -1444,7 +1448,8 @@ class NonTypeTemplateParmDecl final
14441448
/// Set the default argument for this template parameter, and
14451449
/// whether that default argument was inherited from another
14461450
/// declaration.
1447-
void setDefaultArgument(Expr *DefArg) { DefaultArgument.set(DefArg); }
1451+
void setDefaultArgument(const ASTContext &C,
1452+
const TemplateArgumentLoc &DefArg);
14481453
void setInheritedDefaultArgument(const ASTContext &C,
14491454
NonTypeTemplateParmDecl *Parm) {
14501455
DefaultArgument.setInherited(C, Parm);

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,7 @@ DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
23202320
// A non-type template parameter, e.g. "S" in template<int S> class Foo ...
23212321
TRY_TO(TraverseDeclaratorHelper(D));
23222322
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
2323-
TRY_TO(TraverseStmt(D->getDefaultArgument()));
2323+
TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
23242324
})
23252325

23262326
DEF_TRAVERSE_DECL(ParmVarDecl, {

clang/include/clang/Basic/Attr.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,10 +1640,11 @@ def Unlikely : StmtAttr {
16401640
def : MutualExclusions<[Likely, Unlikely]>;
16411641

16421642
def CXXAssume : StmtAttr {
1643-
let Spellings = [CXX11<"", "assume", 202207>];
1643+
let Spellings = [CXX11<"", "assume", 202207>, Clang<"assume">];
16441644
let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
16451645
let Args = [ExprArgument<"Assumption">];
16461646
let Documentation = [CXXAssumeDocs];
1647+
let HasCustomParsing = 1;
16471648
}
16481649

16491650
def NoMerge : DeclOrStmtAttr {
@@ -4255,7 +4256,7 @@ def OMPDeclareVariant : InheritableAttr {
42554256
}
42564257

42574258
def OMPAssume : InheritableAttr {
4258-
let Spellings = [Clang<"assume">, CXX11<"omp", "assume">];
4259+
let Spellings = [CXX11<"omp", "assume">];
42594260
let Subjects = SubjectList<[Function, ObjCMethod]>;
42604261
let InheritEvenIfAlreadyPresent = 1;
42614262
let Documentation = [OMPAssumeDocs];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,9 +2027,6 @@ Different optimisers are likely to react differently to the presence of
20272027
this attribute; in some cases, adding ``assume`` may affect performance
20282028
negatively. It should be used with parsimony and care.
20292029

2030-
Note that `clang::assume` is a different attribute. Always write ``assume``
2031-
without a namespace if you intend to use the standard C++ attribute.
2032-
20332030
Example:
20342031

20352032
.. code-block:: c++
@@ -4740,7 +4737,7 @@ def OMPAssumeDocs : Documentation {
47404737
let Category = DocCatFunction;
47414738
let Heading = "assume";
47424739
let Content = [{
4743-
Clang supports the ``__attribute__((assume("assumption")))`` attribute to
4740+
Clang supports the ``[[omp::assume("assumption")]]`` attribute to
47444741
provide additional information to the optimizer. The string-literal, here
47454742
"assumption", will be attached to the function declaration such that later
47464743
analysis and optimization passes can assume the "assumption" to hold.
@@ -4752,7 +4749,7 @@ A function can have multiple assume attributes and they propagate from prior
47524749
declarations to later definitions. Multiple assumptions are aggregated into a
47534750
single comma separated string. Thus, one can provide multiple assumptions via
47544751
a comma separated string, i.a.,
4755-
``__attribute__((assume("assumption1,assumption2")))``.
4752+
``[[omp::assume("assumption1,assumption2")]]``.
47564753

47574754
While LLVM plugins might provide more assumption strings, the default LLVM
47584755
optimization passes are aware of the following assumptions:

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10237,9 +10237,6 @@ def err_fallthrough_attr_outside_switch : Error<
1023710237
def err_fallthrough_attr_invalid_placement : Error<
1023810238
"fallthrough annotation does not directly precede switch label">;
1023910239

10240-
def err_assume_attr_args : Error<
10241-
"attribute '%0' requires a single expression argument">;
10242-
1024310240
def warn_unreachable_default : Warning<
1024410241
"default label in switch which covers all enumeration values">,
1024510242
InGroup<CoveredSwitchDefault>, DefaultIgnore;

clang/include/clang/Parse/Parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2997,7 +2997,8 @@ class Parser : public CodeCompletionHandler {
29972997
bool ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs,
29982998
IdentifierInfo *AttrName,
29992999
SourceLocation AttrNameLoc,
3000-
SourceLocation *EndLoc);
3000+
SourceLocation *EndLoc,
3001+
ParsedAttr::Form Form);
30013002

30023003
IdentifierInfo *TryParseCXX11AttributeIdentifier(
30033004
SourceLocation &Loc,

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,9 +1390,7 @@ class SemaOpenMP : public SemaBase {
13901390
bool checkTransformableLoopNest(
13911391
OpenMPDirectiveKind Kind, Stmt *AStmt, int NumLoops,
13921392
SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
1393-
Stmt *&Body,
1394-
SmallVectorImpl<SmallVector<llvm::PointerUnion<Stmt *, Decl *>, 0>>
1395-
&OriginalInits);
1393+
Stmt *&Body, SmallVectorImpl<SmallVector<Stmt *, 0>> &OriginalInits);
13961394

13971395
/// Helper to keep information about the current `omp begin/end declare
13981396
/// variant` nesting.

clang/lib/AST/ASTContext.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6503,8 +6503,10 @@ bool ASTContext::isSameDefaultTemplateArgument(const NamedDecl *X,
65036503
if (!NTTPX->hasDefaultArgument() || !NTTPY->hasDefaultArgument())
65046504
return false;
65056505

6506-
Expr *DefaultArgumentX = NTTPX->getDefaultArgument()->IgnoreImpCasts();
6507-
Expr *DefaultArgumentY = NTTPY->getDefaultArgument()->IgnoreImpCasts();
6506+
Expr *DefaultArgumentX =
6507+
NTTPX->getDefaultArgument().getArgument().getAsExpr()->IgnoreImpCasts();
6508+
Expr *DefaultArgumentY =
6509+
NTTPY->getDefaultArgument().getArgument().getAsExpr()->IgnoreImpCasts();
65086510
llvm::FoldingSetNodeID XID, YID;
65096511
DefaultArgumentX->Profile(XID, *this, /*Canonical=*/true);
65106512
DefaultArgumentY->Profile(YID, *this, /*Canonical=*/true);

clang/lib/AST/ASTDiagnostic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ class TemplateDiff {
12381238
E = Iter->getAsExpr();
12391239
}
12401240
} else if (!Default->isParameterPack()) {
1241-
E = Default->getDefaultArgument();
1241+
E = Default->getDefaultArgument().getArgument().getAsExpr();
12421242
}
12431243

12441244
if (!Iter.hasDesugaredTA()) return;

clang/lib/AST/ASTImporter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5949,10 +5949,11 @@ ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
59495949
return ToD;
59505950

59515951
if (D->hasDefaultArgument()) {
5952-
ExpectedExpr ToDefaultArgOrErr = import(D->getDefaultArgument());
5952+
Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
5953+
import(D->getDefaultArgument());
59535954
if (!ToDefaultArgOrErr)
59545955
return ToDefaultArgOrErr.takeError();
5955-
ToD->setDefaultArgument(*ToDefaultArgOrErr);
5956+
ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
59565957
}
59575958

59585959
return ToD;

clang/lib/AST/DeclPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ void DeclPrinter::VisitNonTypeTemplateParmDecl(
18981898

18991899
if (NTTP->hasDefaultArgument()) {
19001900
Out << " = ";
1901-
NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy, Indentation,
1902-
"\n", &Context);
1901+
NTTP->getDefaultArgument().getArgument().print(Policy, Out,
1902+
/*IncludeType=*/false);
19031903
}
19041904
}

clang/lib/AST/DeclTemplate.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,14 +795,21 @@ NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID,
795795
SourceRange NonTypeTemplateParmDecl::getSourceRange() const {
796796
if (hasDefaultArgument() && !defaultArgumentWasInherited())
797797
return SourceRange(getOuterLocStart(),
798-
getDefaultArgument()->getSourceRange().getEnd());
798+
getDefaultArgument().getSourceRange().getEnd());
799799
return DeclaratorDecl::getSourceRange();
800800
}
801801

802802
SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const {
803-
return hasDefaultArgument()
804-
? getDefaultArgument()->getSourceRange().getBegin()
805-
: SourceLocation();
803+
return hasDefaultArgument() ? getDefaultArgument().getSourceRange().getBegin()
804+
: SourceLocation();
805+
}
806+
807+
void NonTypeTemplateParmDecl::setDefaultArgument(
808+
const ASTContext &C, const TemplateArgumentLoc &DefArg) {
809+
if (DefArg.getArgument().isNull())
810+
DefaultArgument.set(nullptr);
811+
else
812+
DefaultArgument.set(new (C) TemplateArgumentLoc(DefArg));
806813
}
807814

808815
//===----------------------------------------------------------------------===//

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,10 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
10611061
R->getField(InitIndex)->Decl->isUnnamedBitField())
10621062
++InitIndex;
10631063

1064+
// Potentially skip ahead. This is especially relevant in unions.
1065+
if (const auto *D = dyn_cast<CXXDefaultInitExpr>(Init))
1066+
InitIndex = D->getField()->getFieldIndex();
1067+
10641068
if (!this->emitDupPtr(E))
10651069
return false;
10661070

clang/lib/AST/Interp/Descriptor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ static void moveArrayDesc(Block *B, const std::byte *Src, std::byte *Dst,
137137
}
138138

139139
static void initField(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
140-
bool IsActive, const Descriptor *D,
140+
bool IsActive, bool IsUnion, const Descriptor *D,
141141
unsigned FieldOffset) {
142-
bool IsUnion = false; // FIXME
143142
auto *Desc = reinterpret_cast<InlineDescriptor *>(Ptr + FieldOffset) - 1;
144143
Desc->Offset = FieldOffset;
145144
Desc->Desc = D;
@@ -174,7 +173,7 @@ static void initBase(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
174173
initBase(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, V.Desc,
175174
V.Offset, false);
176175
for (const auto &F : D->ElemRecord->fields())
177-
initField(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, F.Desc,
176+
initField(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, IsUnion, F.Desc,
178177
F.Offset);
179178

180179
// If this is initializing a virtual base, we do NOT want to consider its
@@ -193,7 +192,7 @@ static void ctorRecord(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
193192
for (const auto &V : D->ElemRecord->bases())
194193
initBase(B, Ptr, IsConst, IsMutable, IsActive, V.Desc, V.Offset, false);
195194
for (const auto &F : D->ElemRecord->fields())
196-
initField(B, Ptr, IsConst, IsMutable, IsActive, F.Desc, F.Offset);
195+
initField(B, Ptr, IsConst, IsMutable, IsActive, D->ElemRecord->isUnion(), F.Desc, F.Offset);
197196
for (const auto &V : D->ElemRecord->virtual_bases())
198197
initBase(B, Ptr, IsConst, IsMutable, IsActive, V.Desc, V.Offset, true);
199198
}

clang/lib/AST/Interp/EvaluationResult.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc,
101101
Pointer FieldPtr = BasePtr.atField(F.Offset);
102102
QualType FieldType = F.Decl->getType();
103103

104+
// Don't check inactive union members.
105+
if (R->isUnion() && !FieldPtr.isActive())
106+
continue;
107+
104108
if (FieldType->isRecordType()) {
105109
Result &= CheckFieldsInitialized(S, Loc, FieldPtr, FieldPtr.getRecord());
106110
} else if (FieldType->isIncompleteArrayType()) {
@@ -115,10 +119,6 @@ static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc,
115119
DiagnoseUninitializedSubobject(S, Loc, F.Decl);
116120
Result = false;
117121
}
118-
119-
// Only the first member of a union needs to be initialized.
120-
if (R->isUnion())
121-
break;
122122
}
123123

124124
// Check Fields in all bases

clang/lib/AST/Interp/Interp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,10 @@ bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
457457
return false;
458458
if (!CheckRange(S, OpPC, Ptr, AK_Read))
459459
return false;
460-
if (!CheckInitialized(S, OpPC, Ptr, AK_Read))
461-
return false;
462460
if (!CheckActive(S, OpPC, Ptr, AK_Read))
463461
return false;
462+
if (!CheckInitialized(S, OpPC, Ptr, AK_Read))
463+
return false;
464464
if (!CheckTemporary(S, OpPC, Ptr, AK_Read))
465465
return false;
466466
if (!CheckMutable(S, OpPC, Ptr))

clang/lib/AST/Interp/Pointer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx) const {
351351
} else {
352352
Ok &= Composite(FieldTy, FP, Value);
353353
}
354+
ActiveField = FP.getFieldDesc()->asFieldDecl();
354355
break;
355356
}
356357
}

0 commit comments

Comments
 (0)