Skip to content

Commit 6bf8046

Browse files
authored
[clang] MicrosoftMangle: pick correct tagdecl for mangling tagkind (#155662)
This fixes a regression reported here: #147835 (comment) Since this regression was never released, there are no release notes.
1 parent 8e24e03 commit 6bf8046

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,13 +3246,17 @@ void MicrosoftCXXNameMangler::mangleTagTypeKind(TagTypeKind TTK) {
32463246
}
32473247
void MicrosoftCXXNameMangler::mangleType(const EnumType *T, Qualifiers,
32483248
SourceRange) {
3249-
mangleType(cast<TagType>(T)->getOriginalDecl()->getDefinitionOrSelf());
3249+
mangleType(cast<TagType>(T)->getOriginalDecl());
32503250
}
32513251
void MicrosoftCXXNameMangler::mangleType(const RecordType *T, Qualifiers,
32523252
SourceRange) {
3253-
mangleType(cast<TagType>(T)->getOriginalDecl()->getDefinitionOrSelf());
3253+
mangleType(cast<TagType>(T)->getOriginalDecl());
32543254
}
32553255
void MicrosoftCXXNameMangler::mangleType(const TagDecl *TD) {
3256+
// MSVC chooses the tag kind of the definition if it exists, otherwise it
3257+
// always picks the first declaration.
3258+
const auto *Def = TD->getDefinition();
3259+
TD = Def ? Def : TD->getFirstDecl();
32563260
mangleTagTypeKind(TD->getTagKind());
32573261
mangleName(TD);
32583262
}

clang/test/CodeGenCXX/mangle-ms-cxx11.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,42 @@ struct s { enum {}; enum {}; };
358358
// DBG-DAG: DW_TAG_enumeration_type{{.*}}identifier: ".?AW4<unnamed-type-$S3>@s@pr37723@@"
359359
s x;
360360
}
361+
362+
namespace InconsistentTagKinds {
363+
namespace t1 {
364+
class A;
365+
struct A;
366+
void f(A*) {}
367+
// CHECK-DAG: @"?f@t1@InconsistentTagKinds@@YAXPAVA@12@@Z"
368+
} // namespace t1
369+
namespace t2 {
370+
struct A;
371+
class A;
372+
void f(A*) {}
373+
// CHECK-DAG: @"?f@t2@InconsistentTagKinds@@YAXPAUA@12@@Z"
374+
} // namespace t2
375+
namespace t3 {
376+
class A {};
377+
struct A;
378+
void f(A*) {}
379+
// CHECK-DAG: @"?f@t3@InconsistentTagKinds@@YAXPAVA@12@@Z"
380+
} // namespace t3
381+
namespace t4 {
382+
struct A {};
383+
class A;
384+
void f(A*) {}
385+
// CHECK-DAG: @"?f@t4@InconsistentTagKinds@@YAXPAUA@12@@Z"
386+
} // namespace t4
387+
namespace t5 {
388+
class A;
389+
struct A {};
390+
void f(A*) {}
391+
// CHECK-DAG: @"?f@t5@InconsistentTagKinds@@YAXPAUA@12@@Z"
392+
} // namespace t5
393+
namespace t6 {
394+
struct A;
395+
class A {};
396+
void f(A*) {}
397+
// CHECK-DAG: @"?f@t6@InconsistentTagKinds@@YAXPAVA@12@@Z"
398+
} // namespace t6
399+
} // namespace InconsistentTagKinds

0 commit comments

Comments
 (0)