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