Skip to content

Commit

Permalink
Revert "[GH54588]Fix ItaniumMangler for NTTP unnamed unions w/ unname…
Browse files Browse the repository at this point in the history
…d structs"

This reverts commit 4cf98f9.
The test fails on mac bots, see comments on https://reviews.llvm.org/D122820

Also reverts follow-ups eb92098 and
861c189.
  • Loading branch information
nico committed Apr 3, 2022
1 parent 3c88ff4 commit 50186b6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 158 deletions.
46 changes: 1 addition & 45 deletions clang/lib/AST/ItaniumMangle.cpp
Expand Up @@ -5545,47 +5545,6 @@ static QualType getLValueType(ASTContext &Ctx, const APValue &LV) {
return T;
}

static IdentifierInfo *getUnionInitName(SourceLocation UnionLoc,
DiagnosticsEngine &Diags,
const FieldDecl *FD) {
// According to:
// http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling.anonymous
// For the purposes of mangling, the name of an anonymous union is considered
// to be the name of the first named data member found by a pre-order,
// depth-first, declaration-order walk of the data members of the anonymous
// union.

if (FD->getIdentifier())
return FD->getIdentifier();

// The only cases where the identifer of a FieldDecl would be blank is if the
// field represents an anonymous record type or if it is an unnamed bitfield.
// There is no type to descend into in the case of a bitfield, so we can just
// return nullptr in that case.
if (FD->isBitField())
return nullptr;
const CXXRecordDecl *RD = FD->getType()->getAsCXXRecordDecl();

// Consider only the fields in declaration order, searched depth-first. We
// don't care about the active member of the union, as all we are doing is
// looking for a valid name. We also don't check bases, due to guidance from
// the Itanium ABI folks.
for (const FieldDecl *RDField : RD->fields()) {
if (IdentifierInfo *II = getUnionInitName(UnionLoc, Diags, RDField))
return II;
}

// According to the Itanium ABI: If there is no such data member (i.e., if all
// of the data members in the union are unnamed), then there is no way for a
// program to refer to the anonymous union, and there is therefore no need to
// mangle its name. However, we should diagnose this anyway.
unsigned DiagID = Diags.getCustomDiagID(
DiagnosticsEngine::Error, "cannot mangle this unnamed union NTTP yet");
Diags.Report(UnionLoc, DiagID);

return nullptr;
}

void CXXNameMangler::mangleValueInTemplateArg(QualType T, const APValue &V,
bool TopLevel,
bool NeedExactType) {
Expand Down Expand Up @@ -5669,10 +5628,7 @@ void CXXNameMangler::mangleValueInTemplateArg(QualType T, const APValue &V,
mangleType(T);
if (!isZeroInitialized(T, V)) {
Out << "di";
IdentifierInfo *II = (getUnionInitName(
T->getAsCXXRecordDecl()->getLocation(), Context.getDiags(), FD));
if (II)
mangleSourceName(II);
mangleSourceName(FD->getIdentifier());
mangleValueInTemplateArg(FD->getType(), V.getUnionValue(), false);
}
Out << 'E';
Expand Down
113 changes: 0 additions & 113 deletions clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp

This file was deleted.

0 comments on commit 50186b6

Please sign in to comment.