@@ -337,6 +337,9 @@ class MicrosoftCXXNameMangler {
337
337
338
338
const bool PointersAre64Bit;
339
339
340
+ DiagnosticBuilder Error (SourceLocation, StringRef);
341
+ DiagnosticBuilder Error (StringRef);
342
+
340
343
public:
341
344
enum QualifierMangleMode { QMM_Drop, QMM_Mangle, QMM_Escape, QMM_Result };
342
345
enum class TplArgKind { ClassNTTP, StructuralValue };
@@ -564,6 +567,23 @@ MicrosoftMangleContextImpl::shouldMangleStringLiteral(const StringLiteral *SL) {
564
567
return true ;
565
568
}
566
569
570
+ DiagnosticBuilder MicrosoftCXXNameMangler::Error (SourceLocation loc,
571
+ StringRef thingy) {
572
+ DiagnosticsEngine &Diags = Context.getDiags ();
573
+ // extra placeholders are ignored quietly when not used
574
+ unsigned DiagID = Diags.getCustomDiagID (
575
+ DiagnosticsEngine::Error, " cannot mangle this %0 %1 %2 %3 %4 yet" );
576
+ return Diags.Report (loc, DiagID) << thingy;
577
+ }
578
+
579
+ DiagnosticBuilder MicrosoftCXXNameMangler::Error (StringRef thingy) {
580
+ DiagnosticsEngine &Diags = Context.getDiags ();
581
+ // extra placeholders are ignored quietly when not used
582
+ unsigned DiagID = Diags.getCustomDiagID (
583
+ DiagnosticsEngine::Error, " cannot mangle this %0 %1 %2 %3 %4 yet" );
584
+ return Diags.Report (DiagID) << thingy;
585
+ }
586
+
567
587
void MicrosoftCXXNameMangler::mangle (GlobalDecl GD, StringRef Prefix) {
568
588
const NamedDecl *D = cast<NamedDecl>(GD.getDecl ());
569
589
// MSVC doesn't mangle C++ names the same way it mangles extern "C" names.
@@ -1577,10 +1597,7 @@ void MicrosoftCXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO,
1577
1597
case OO_Spaceship: Out << " ?__M" ; break ;
1578
1598
1579
1599
case OO_Conditional: {
1580
- DiagnosticsEngine &Diags = Context.getDiags ();
1581
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
1582
- " cannot mangle this conditional operator yet" );
1583
- Diags.Report (Loc, DiagID);
1600
+ Error (Loc, " conditional operator" );
1584
1601
break ;
1585
1602
}
1586
1603
@@ -1672,11 +1689,8 @@ void MicrosoftCXXNameMangler::mangleExpression(
1672
1689
}
1673
1690
1674
1691
// As bad as this diagnostic is, it's better than crashing.
1675
- DiagnosticsEngine &Diags = Context.getDiags ();
1676
- unsigned DiagID = Diags.getCustomDiagID (
1677
- DiagnosticsEngine::Error, " cannot yet mangle expression type %0" );
1678
- Diags.Report (E->getExprLoc (), DiagID) << E->getStmtClassName ()
1679
- << E->getSourceRange ();
1692
+ Error (E->getExprLoc (), " expression type: " )
1693
+ << E->getStmtClassName () << E->getSourceRange ();
1680
1694
}
1681
1695
1682
1696
void MicrosoftCXXNameMangler::mangleTemplateArgs (
@@ -1922,11 +1936,19 @@ void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
1922
1936
if (WithScalarType)
1923
1937
mangleType (T, SourceRange (), QMM_Escape);
1924
1938
1925
- // We don't know how to mangle past-the-end pointers yet.
1926
- if (V.isLValueOnePastTheEnd ())
1927
- break ;
1928
-
1929
1939
APValue::LValueBase Base = V.getLValueBase ();
1940
+
1941
+ // this might not cover every case but did cover issue 97756
1942
+ // see test CodeGen/ms_mangler_templatearg_opte
1943
+ if (V.isLValueOnePastTheEnd ()) {
1944
+ Out << " 5E" ;
1945
+ auto *VD = Base.dyn_cast <const ValueDecl *>();
1946
+ if (VD)
1947
+ mangle (VD);
1948
+ Out << " @" ;
1949
+ return ;
1950
+ }
1951
+
1930
1952
if (!V.hasLValuePath () || V.getLValuePath ().empty ()) {
1931
1953
// Taking the address of a complete object has a special-case mangling.
1932
1954
if (Base.isNull ()) {
@@ -1938,12 +1960,14 @@ void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
1938
1960
mangleNumber (V.getLValueOffset ().getQuantity ());
1939
1961
} else if (!V.hasLValuePath ()) {
1940
1962
// FIXME: This can only happen as an extension. Invent a mangling.
1941
- break ;
1963
+ Error (" template argument (extension not comaptible with ms mangler)" );
1964
+ return ;
1942
1965
} else if (auto *VD = Base.dyn_cast <const ValueDecl*>()) {
1943
1966
Out << " E" ;
1944
1967
mangle (VD);
1945
1968
} else {
1946
- break ;
1969
+ Error (" template argument (undeclared base)" );
1970
+ return ;
1947
1971
}
1948
1972
} else {
1949
1973
if (TAK == TplArgKind::ClassNTTP && T->isPointerType ())
@@ -1988,8 +2012,10 @@ void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
1988
2012
Out << *I;
1989
2013
1990
2014
auto *VD = Base.dyn_cast <const ValueDecl*>();
1991
- if (!VD)
1992
- break ;
2015
+ if (!VD) {
2016
+ Error (" template argument (null value decl)" );
2017
+ return ;
2018
+ }
1993
2019
Out << (TAK == TplArgKind::ClassNTTP ? ' E' : ' 1' );
1994
2020
mangle (VD);
1995
2021
@@ -2104,15 +2130,16 @@ void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
2104
2130
return ;
2105
2131
}
2106
2132
2107
- case APValue::AddrLabelDiff:
2108
- case APValue::FixedPoint:
2109
- break ;
2133
+ case APValue::AddrLabelDiff: {
2134
+ Error ( " template argument (value type: address label diff) " );
2135
+ return ;
2110
2136
}
2111
2137
2112
- DiagnosticsEngine &Diags = Context.getDiags ();
2113
- unsigned DiagID = Diags.getCustomDiagID (
2114
- DiagnosticsEngine::Error, " cannot mangle this template argument yet" );
2115
- Diags.Report (DiagID);
2138
+ case APValue::FixedPoint: {
2139
+ Error (" template argument (value type: fixed point)" );
2140
+ return ;
2141
+ }
2142
+ }
2116
2143
}
2117
2144
2118
2145
void MicrosoftCXXNameMangler::mangleObjCProtocol (const ObjCProtocolDecl *PD) {
@@ -2739,11 +2766,9 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
2739
2766
case BuiltinType::SatULongFract:
2740
2767
case BuiltinType::Ibm128:
2741
2768
case BuiltinType::Float128: {
2742
- DiagnosticsEngine &Diags = Context.getDiags ();
2743
- unsigned DiagID = Diags.getCustomDiagID (
2744
- DiagnosticsEngine::Error, " cannot mangle this built-in %0 type yet" );
2745
- Diags.Report (Range.getBegin (), DiagID)
2746
- << T->getName (Context.getASTContext ().getPrintingPolicy ()) << Range;
2769
+ Error (Range.getBegin (), " built-in " )
2770
+ << T->getName (Context.getASTContext ().getPrintingPolicy ()) << " type"
2771
+ << Range;
2747
2772
break ;
2748
2773
}
2749
2774
}
@@ -3061,10 +3086,7 @@ void MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC,
3061
3086
return ;
3062
3087
}
3063
3088
3064
- DiagnosticsEngine &Diags = Context.getDiags ();
3065
- unsigned DiagID = Diags.getCustomDiagID (
3066
- DiagnosticsEngine::Error, " cannot mangle this calling convention yet" );
3067
- Diags.Report (Range.getBegin (), DiagID) << Range;
3089
+ Error (Range.getBegin (), " calling convention" ) << Range;
3068
3090
}
3069
3091
void MicrosoftCXXNameMangler::mangleCallingConvention (const FunctionType *T,
3070
3092
SourceRange Range) {
@@ -3085,11 +3107,7 @@ void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T,
3085
3107
Qualifiers, SourceRange Range) {
3086
3108
// Probably should be mangled as a template instantiation; need to see what
3087
3109
// VC does first.
3088
- DiagnosticsEngine &Diags = Context.getDiags ();
3089
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3090
- " cannot mangle this unresolved dependent type yet" );
3091
- Diags.Report (Range.getBegin (), DiagID)
3092
- << Range;
3110
+ Error (Range.getBegin (), " unresolved dependent type" ) << Range;
3093
3111
}
3094
3112
3095
3113
// <type> ::= <union-type> | <struct-type> | <class-type> | <enum-type>
@@ -3196,11 +3214,8 @@ void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) {
3196
3214
// The dependent expression has to be folded into a constant (TODO).
3197
3215
const DependentSizedArrayType *DSAT =
3198
3216
getASTContext ().getAsDependentSizedArrayType (ElementTy);
3199
- DiagnosticsEngine &Diags = Context.getDiags ();
3200
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3201
- " cannot mangle this dependent-length array yet" );
3202
- Diags.Report (DSAT->getSizeExpr ()->getExprLoc (), DiagID)
3203
- << DSAT->getBracketsRange ();
3217
+ Error (DSAT->getSizeExpr ()->getExprLoc (), " dependent-length" )
3218
+ << DSAT->getBracketsRange ();
3204
3219
return ;
3205
3220
} else {
3206
3221
break ;
@@ -3240,20 +3255,12 @@ void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T,
3240
3255
3241
3256
void MicrosoftCXXNameMangler::mangleType (const TemplateTypeParmType *T,
3242
3257
Qualifiers, SourceRange Range) {
3243
- DiagnosticsEngine &Diags = Context.getDiags ();
3244
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3245
- " cannot mangle this template type parameter type yet" );
3246
- Diags.Report (Range.getBegin (), DiagID)
3247
- << Range;
3258
+ Error (Range.getBegin (), " template type parameter type" ) << Range;
3248
3259
}
3249
3260
3250
3261
void MicrosoftCXXNameMangler::mangleType (const SubstTemplateTypeParmPackType *T,
3251
3262
Qualifiers, SourceRange Range) {
3252
- DiagnosticsEngine &Diags = Context.getDiags ();
3253
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3254
- " cannot mangle this substituted parameter pack yet" );
3255
- Diags.Report (Range.getBegin (), DiagID)
3256
- << Range;
3263
+ Error (Range.getBegin (), " substituted parameter pack" ) << Range;
3257
3264
}
3258
3265
3259
3266
// <type> ::= <pointer-type>
@@ -3404,46 +3411,27 @@ void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T,
3404
3411
3405
3412
void MicrosoftCXXNameMangler::mangleType (const DependentVectorType *T,
3406
3413
Qualifiers, SourceRange Range) {
3407
- DiagnosticsEngine &Diags = Context.getDiags ();
3408
- unsigned DiagID = Diags.getCustomDiagID (
3409
- DiagnosticsEngine::Error,
3410
- " cannot mangle this dependent-sized vector type yet" );
3411
- Diags.Report (Range.getBegin (), DiagID) << Range;
3414
+ Error (Range.getBegin (), " dependent-sized vector type" ) << Range;
3412
3415
}
3413
3416
3414
3417
void MicrosoftCXXNameMangler::mangleType (const DependentSizedExtVectorType *T,
3415
3418
Qualifiers, SourceRange Range) {
3416
- DiagnosticsEngine &Diags = Context.getDiags ();
3417
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3418
- " cannot mangle this dependent-sized extended vector type yet" );
3419
- Diags.Report (Range.getBegin (), DiagID)
3420
- << Range;
3419
+ Error (Range.getBegin (), " dependent-sized extended vector type" ) << Range;
3421
3420
}
3422
3421
3423
3422
void MicrosoftCXXNameMangler::mangleType (const ConstantMatrixType *T,
3424
3423
Qualifiers quals, SourceRange Range) {
3425
- DiagnosticsEngine &Diags = Context.getDiags ();
3426
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3427
- " Cannot mangle this matrix type yet" );
3428
- Diags.Report (Range.getBegin (), DiagID) << Range;
3424
+ Error (Range.getBegin (), " matrix type" ) << Range;
3429
3425
}
3430
3426
3431
3427
void MicrosoftCXXNameMangler::mangleType (const DependentSizedMatrixType *T,
3432
3428
Qualifiers quals, SourceRange Range) {
3433
- DiagnosticsEngine &Diags = Context.getDiags ();
3434
- unsigned DiagID = Diags.getCustomDiagID (
3435
- DiagnosticsEngine::Error,
3436
- " Cannot mangle this dependent-sized matrix type yet" );
3437
- Diags.Report (Range.getBegin (), DiagID) << Range;
3429
+ Error (Range.getBegin (), " dependent-sized matrix type" ) << Range;
3438
3430
}
3439
3431
3440
3432
void MicrosoftCXXNameMangler::mangleType (const DependentAddressSpaceType *T,
3441
3433
Qualifiers, SourceRange Range) {
3442
- DiagnosticsEngine &Diags = Context.getDiags ();
3443
- unsigned DiagID = Diags.getCustomDiagID (
3444
- DiagnosticsEngine::Error,
3445
- " cannot mangle this dependent address space type yet" );
3446
- Diags.Report (Range.getBegin (), DiagID) << Range;
3434
+ Error (Range.getBegin (), " dependent address space type" ) << Range;
3447
3435
}
3448
3436
3449
3437
void MicrosoftCXXNameMangler::mangleType (const ObjCInterfaceType *T, Qualifiers,
@@ -3513,39 +3501,23 @@ void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *,
3513
3501
3514
3502
void MicrosoftCXXNameMangler::mangleType (const TemplateSpecializationType *T,
3515
3503
Qualifiers, SourceRange Range) {
3516
- DiagnosticsEngine &Diags = Context.getDiags ();
3517
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3518
- " cannot mangle this template specialization type yet" );
3519
- Diags.Report (Range.getBegin (), DiagID)
3520
- << Range;
3504
+ Error (Range.getBegin (), " template specialization type" ) << Range;
3521
3505
}
3522
3506
3523
3507
void MicrosoftCXXNameMangler::mangleType (const DependentNameType *T, Qualifiers,
3524
3508
SourceRange Range) {
3525
- DiagnosticsEngine &Diags = Context.getDiags ();
3526
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3527
- " cannot mangle this dependent name type yet" );
3528
- Diags.Report (Range.getBegin (), DiagID)
3529
- << Range;
3509
+ Error (Range.getBegin (), " dependent name type" ) << Range;
3530
3510
}
3531
3511
3532
3512
void MicrosoftCXXNameMangler::mangleType (
3533
3513
const DependentTemplateSpecializationType *T, Qualifiers,
3534
3514
SourceRange Range) {
3535
- DiagnosticsEngine &Diags = Context.getDiags ();
3536
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3537
- " cannot mangle this dependent template specialization type yet" );
3538
- Diags.Report (Range.getBegin (), DiagID)
3539
- << Range;
3515
+ Error (Range.getBegin (), " dependent template specialization type" ) << Range;
3540
3516
}
3541
3517
3542
3518
void MicrosoftCXXNameMangler::mangleType (const PackExpansionType *T, Qualifiers,
3543
3519
SourceRange Range) {
3544
- DiagnosticsEngine &Diags = Context.getDiags ();
3545
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3546
- " cannot mangle this pack expansion yet" );
3547
- Diags.Report (Range.getBegin (), DiagID)
3548
- << Range;
3520
+ Error (Range.getBegin (), " pack expansion" ) << Range;
3549
3521
}
3550
3522
3551
3523
void MicrosoftCXXNameMangler::mangleType (const PackIndexingType *T,
@@ -3556,60 +3528,37 @@ void MicrosoftCXXNameMangler::mangleType(const PackIndexingType *T,
3556
3528
3557
3529
void MicrosoftCXXNameMangler::mangleType (const TypeOfType *T, Qualifiers,
3558
3530
SourceRange Range) {
3559
- DiagnosticsEngine &Diags = Context.getDiags ();
3560
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3561
- " cannot mangle this typeof(type) yet" );
3562
- Diags.Report (Range.getBegin (), DiagID)
3563
- << Range;
3531
+ Error (Range.getBegin (), " typeof(type)" ) << Range;
3564
3532
}
3565
3533
3566
3534
void MicrosoftCXXNameMangler::mangleType (const TypeOfExprType *T, Qualifiers,
3567
3535
SourceRange Range) {
3568
- DiagnosticsEngine &Diags = Context.getDiags ();
3569
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3570
- " cannot mangle this typeof(expression) yet" );
3571
- Diags.Report (Range.getBegin (), DiagID)
3572
- << Range;
3536
+ Error (Range.getBegin (), " typeof(expression)" ) << Range;
3573
3537
}
3574
3538
3575
3539
void MicrosoftCXXNameMangler::mangleType (const DecltypeType *T, Qualifiers,
3576
3540
SourceRange Range) {
3577
- DiagnosticsEngine &Diags = Context.getDiags ();
3578
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3579
- " cannot mangle this decltype() yet" );
3580
- Diags.Report (Range.getBegin (), DiagID)
3581
- << Range;
3541
+ Error (Range.getBegin (), " decltype()" ) << Range;
3582
3542
}
3583
3543
3584
3544
void MicrosoftCXXNameMangler::mangleType (const UnaryTransformType *T,
3585
3545
Qualifiers, SourceRange Range) {
3586
- DiagnosticsEngine &Diags = Context.getDiags ();
3587
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3588
- " cannot mangle this unary transform type yet" );
3589
- Diags.Report (Range.getBegin (), DiagID)
3590
- << Range;
3546
+ Error (Range.getBegin (), " unary transform type" ) << Range;
3591
3547
}
3592
3548
3593
3549
void MicrosoftCXXNameMangler::mangleType (const AutoType *T, Qualifiers,
3594
3550
SourceRange Range) {
3595
3551
assert (T->getDeducedType ().isNull () && " expecting a dependent type!" );
3596
3552
3597
- DiagnosticsEngine &Diags = Context.getDiags ();
3598
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3599
- " cannot mangle this 'auto' type yet" );
3600
- Diags.Report (Range.getBegin (), DiagID)
3601
- << Range;
3553
+ Error (Range.getBegin (), " 'auto' type" ) << Range;
3602
3554
}
3603
3555
3604
3556
void MicrosoftCXXNameMangler::mangleType (
3605
3557
const DeducedTemplateSpecializationType *T, Qualifiers, SourceRange Range) {
3606
3558
assert (T->getDeducedType ().isNull () && " expecting a dependent type!" );
3607
3559
3608
- DiagnosticsEngine &Diags = Context.getDiags ();
3609
- unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
3610
- " cannot mangle this deduced class template specialization type yet" );
3611
- Diags.Report (Range.getBegin (), DiagID)
3612
- << Range;
3560
+ Error (Range.getBegin (), " deduced class template specialization type" )
3561
+ << Range;
3613
3562
}
3614
3563
3615
3564
void MicrosoftCXXNameMangler::mangleType (const AtomicType *T, Qualifiers,
@@ -3683,10 +3632,7 @@ void MicrosoftCXXNameMangler::mangleType(const BitIntType *T, Qualifiers,
3683
3632
3684
3633
void MicrosoftCXXNameMangler::mangleType (const DependentBitIntType *T,
3685
3634
Qualifiers, SourceRange Range) {
3686
- DiagnosticsEngine &Diags = Context.getDiags ();
3687
- unsigned DiagID = Diags.getCustomDiagID (
3688
- DiagnosticsEngine::Error, " cannot mangle this DependentBitInt type yet" );
3689
- Diags.Report (Range.getBegin (), DiagID) << Range;
3635
+ Error (Range.getBegin (), " DependentBitInt type" ) << Range;
3690
3636
}
3691
3637
3692
3638
// <this-adjustment> ::= <no-adjustment> | <static-adjustment> |
0 commit comments