Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18544,8 +18544,14 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
if (PrevDecl)
CheckRedeclarationInModule(New, PrevDecl);

if (TUK == TagUseKind::Definition && (!SkipBody || !SkipBody->ShouldSkip))
New->startDefinition();
if (TUK == TagUseKind::Definition) {
if (!SkipBody || !SkipBody->ShouldSkip) {
New->startDefinition();
} else {
New->setCompleteDefinition();
New->demoteThisDefinitionToDeclaration();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever come here for non-enum tag types? I looked up the ShouldSkipInfo class, but I wasn't able to figure out exactly when or why we skip tag bodies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case we were hitting on this regression was from a recent improvement implemented here: 2db239a

But this skipping of parsing of bodies is built upon much older patch: d9ba224

But yes, we should come here for other tag kinds as well, based on the tests added in the first commit.

}
}

ProcessDeclAttributeList(S, New, Attrs);
AddPragmaAttributes(S, New);
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9878,7 +9878,14 @@ static QualType GetEnumUnderlyingType(Sema &S, QualType BaseType,
S.DiagnoseUseOfDecl(ED, Loc);

QualType Underlying = ED->getIntegerType();
assert(!Underlying.isNull());
if (Underlying.isNull()) {
// This is an enum without a fixed underlying type which we skipped parsing
// the body because we saw its definition previously in another module.
// Use the definition's integer type in that case.
assert(ED->isThisDeclarationADemotedDefinition());
Underlying = ED->getDefinition()->getIntegerType();
assert(!Underlying.isNull());
}

return Underlying;
}
Expand Down
17 changes: 17 additions & 0 deletions clang/test/Modules/GH155028-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %clang_cc1 -std=c++20 -verify %s
// expected-no-diagnostics

#pragma clang module build M
module "M" {
module "A" {}
module "B" {}
}
#pragma clang module contents
#pragma clang module begin M.A
enum E1 {};
#pragma clang module end
#pragma clang module begin M.B
enum E1 {};
using T = __underlying_type(E1);
#pragma clang module end
#pragma clang module endbuild