@@ -337,6 +337,10 @@ class MicrosoftCXXNameMangler {
337
337
338
338
const bool PointersAre64Bit;
339
339
340
+ DiagnosticBuilder Error (SourceLocation, StringRef, StringRef);
341
+ DiagnosticBuilder Error (SourceLocation, StringRef);
342
+ DiagnosticBuilder Error (StringRef);
343
+
340
344
public:
341
345
enum QualifierMangleMode { QMM_Drop, QMM_Mangle, QMM_Escape, QMM_Result };
342
346
enum class TplArgKind { ClassNTTP, StructuralValue };
@@ -564,6 +568,31 @@ MicrosoftMangleContextImpl::shouldMangleStringLiteral(const StringLiteral *SL) {
564
568
return true ;
565
569
}
566
570
571
+ DiagnosticBuilder MicrosoftCXXNameMangler::Error (SourceLocation loc,
572
+ StringRef thing1,
573
+ StringRef thing2) {
574
+ DiagnosticsEngine &Diags = Context.getDiags ();
575
+ unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
576
+ " cannot mangle this %0 %1 yet" );
577
+ return Diags.Report (loc, DiagID) << thing1 << thing2;
578
+ }
579
+
580
+ DiagnosticBuilder MicrosoftCXXNameMangler::Error (SourceLocation loc,
581
+ StringRef thingy) {
582
+ DiagnosticsEngine &Diags = Context.getDiags ();
583
+ unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
584
+ " cannot mangle this %0 yet" );
585
+ return Diags.Report (loc, DiagID) << thingy;
586
+ }
587
+
588
+ DiagnosticBuilder MicrosoftCXXNameMangler::Error (StringRef thingy) {
589
+ DiagnosticsEngine &Diags = Context.getDiags ();
590
+ // extra placeholders are ignored quietly when not used
591
+ unsigned DiagID = Diags.getCustomDiagID (DiagnosticsEngine::Error,
592
+ " cannot mangle this %0 yet" );
593
+ return Diags.Report (DiagID) << thingy;
594
+ }
595
+
567
596
void MicrosoftCXXNameMangler::mangle (GlobalDecl GD, StringRef Prefix) {
568
597
const NamedDecl *D = cast<NamedDecl>(GD.getDecl ());
569
598
// MSVC doesn't mangle C++ names the same way it mangles extern "C" names.
@@ -1578,10 +1607,7 @@ void MicrosoftCXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO,
1578
1607
case OO_Spaceship: Out << " ?__M" ; break ;
1579
1608
1580
1609
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);
1610
+ Error (Loc, " conditional operator" );
1585
1611
break ;
1586
1612
}
1587
1613
@@ -1673,11 +1699,8 @@ void MicrosoftCXXNameMangler::mangleExpression(
1673
1699
}
1674
1700
1675
1701
// 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 ();
1702
+ Error (E->getExprLoc (), " expression type: " , E->getStmtClassName ())
1703
+ << E->getSourceRange ();
1681
1704
}
1682
1705
1683
1706
void MicrosoftCXXNameMangler::mangleTemplateArgs (
@@ -1923,11 +1946,19 @@ void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
1923
1946
if (WithScalarType)
1924
1947
mangleType (T, SourceRange (), QMM_Escape);
1925
1948
1926
- // We don't know how to mangle past-the-end pointers yet.
1927
- if (V.isLValueOnePastTheEnd ())
1928
- break ;
1929
-
1930
1949
APValue::LValueBase Base = V.getLValueBase ();
1950
+
1951
+ // this might not cover every case but did cover issue 97756
1952
+ // see test CodeGen/ms_mangler_templatearg_opte
1953
+ if (V.isLValueOnePastTheEnd ()) {
1954
+ Out << " 5E" ;
1955
+ auto *VD = Base.dyn_cast <const ValueDecl *>();
1956
+ if (VD)
1957
+ mangle (VD);
1958
+ Out << " @" ;
1959
+ return ;
1960
+ }
1961
+
1931
1962
if (!V.hasLValuePath () || V.getLValuePath ().empty ()) {
1932
1963
// Taking the address of a complete object has a special-case mangling.
1933
1964
if (Base.isNull ()) {
@@ -1939,12 +1970,14 @@ void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
1939
1970
mangleNumber (V.getLValueOffset ().getQuantity ());
1940
1971
} else if (!V.hasLValuePath ()) {
1941
1972
// FIXME: This can only happen as an extension. Invent a mangling.
1942
- break ;
1973
+ Error (" template argument (extension not comaptible with ms mangler)" );
1974
+ return ;
1943
1975
} else if (auto *VD = Base.dyn_cast <const ValueDecl*>()) {
1944
1976
Out << " E" ;
1945
1977
mangle (VD);
1946
1978
} else {
1947
- break ;
1979
+ Error (" template argument (undeclared base)" );
1980
+ return ;
1948
1981
}
1949
1982
} else {
1950
1983
if (TAK == TplArgKind::ClassNTTP && T->isPointerType ())
@@ -1989,8 +2022,10 @@ void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
1989
2022
Out << *I;
1990
2023
1991
2024
auto *VD = Base.dyn_cast <const ValueDecl*>();
1992
- if (!VD)
1993
- break ;
2025
+ if (!VD) {
2026
+ Error (" template argument (null value decl)" );
2027
+ return ;
2028
+ }
1994
2029
Out << (TAK == TplArgKind::ClassNTTP ? ' E' : ' 1' );
1995
2030
mangle (VD);
1996
2031
@@ -2105,15 +2140,16 @@ void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
2105
2140
return ;
2106
2141
}
2107
2142
2108
- case APValue::AddrLabelDiff:
2109
- case APValue::FixedPoint:
2110
- break ;
2143
+ case APValue::AddrLabelDiff: {
2144
+ Error ( " template argument (value type: address label diff) " );
2145
+ return ;
2111
2146
}
2112
2147
2113
- DiagnosticsEngine &Diags = Context.getDiags ();
2114
- unsigned DiagID = Diags.getCustomDiagID (
2115
- DiagnosticsEngine::Error, " cannot mangle this template argument yet" );
2116
- Diags.Report (DiagID);
2148
+ case APValue::FixedPoint: {
2149
+ Error (" template argument (value type: fixed point)" );
2150
+ return ;
2151
+ }
2152
+ }
2117
2153
}
2118
2154
2119
2155
void MicrosoftCXXNameMangler::mangleObjCProtocol (const ObjCProtocolDecl *PD) {
@@ -2740,11 +2776,9 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
2740
2776
case BuiltinType::SatULongFract:
2741
2777
case BuiltinType::Ibm128:
2742
2778
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;
2779
+ Error (Range.getBegin (), " built-in type: " ,
2780
+ T->getName (Context.getASTContext ().getPrintingPolicy ()))
2781
+ << Range;
2748
2782
break ;
2749
2783
}
2750
2784
}
@@ -3062,10 +3096,7 @@ void MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC,
3062
3096
return ;
3063
3097
}
3064
3098
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;
3099
+ Error (Range.getBegin (), " calling convention" ) << Range;
3069
3100
}
3070
3101
void MicrosoftCXXNameMangler::mangleCallingConvention (const FunctionType *T,
3071
3102
SourceRange Range) {
@@ -3086,11 +3117,7 @@ void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T,
3086
3117
Qualifiers, SourceRange Range) {
3087
3118
// Probably should be mangled as a template instantiation; need to see what
3088
3119
// 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;
3120
+ Error (Range.getBegin (), " unresolved dependent type" ) << Range;
3094
3121
}
3095
3122
3096
3123
// <type> ::= <union-type> | <struct-type> | <class-type> | <enum-type>
@@ -3197,11 +3224,8 @@ void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) {
3197
3224
// The dependent expression has to be folded into a constant (TODO).
3198
3225
const DependentSizedArrayType *DSAT =
3199
3226
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 ();
3227
+ Error (DSAT->getSizeExpr ()->getExprLoc (), " dependent-length" )
3228
+ << DSAT->getBracketsRange ();
3205
3229
return ;
3206
3230
} else {
3207
3231
break ;
@@ -3241,20 +3265,12 @@ void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T,
3241
3265
3242
3266
void MicrosoftCXXNameMangler::mangleType (const TemplateTypeParmType *T,
3243
3267
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;
3268
+ Error (Range.getBegin (), " template type parameter type" ) << Range;
3249
3269
}
3250
3270
3251
3271
void MicrosoftCXXNameMangler::mangleType (const SubstTemplateTypeParmPackType *T,
3252
3272
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;
3273
+ Error (Range.getBegin (), " substituted parameter pack" ) << Range;
3258
3274
}
3259
3275
3260
3276
// <type> ::= <pointer-type>
@@ -3405,46 +3421,27 @@ void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T,
3405
3421
3406
3422
void MicrosoftCXXNameMangler::mangleType (const DependentVectorType *T,
3407
3423
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;
3424
+ Error (Range.getBegin (), " dependent-sized vector type" ) << Range;
3413
3425
}
3414
3426
3415
3427
void MicrosoftCXXNameMangler::mangleType (const DependentSizedExtVectorType *T,
3416
3428
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;
3429
+ Error (Range.getBegin (), " dependent-sized extended vector type" ) << Range;
3422
3430
}
3423
3431
3424
3432
void MicrosoftCXXNameMangler::mangleType (const ConstantMatrixType *T,
3425
3433
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;
3434
+ Error (Range.getBegin (), " matrix type" ) << Range;
3430
3435
}
3431
3436
3432
3437
void MicrosoftCXXNameMangler::mangleType (const DependentSizedMatrixType *T,
3433
3438
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;
3439
+ Error (Range.getBegin (), " dependent-sized matrix type" ) << Range;
3439
3440
}
3440
3441
3441
3442
void MicrosoftCXXNameMangler::mangleType (const DependentAddressSpaceType *T,
3442
3443
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;
3444
+ Error (Range.getBegin (), " dependent address space type" ) << Range;
3448
3445
}
3449
3446
3450
3447
void MicrosoftCXXNameMangler::mangleType (const ObjCInterfaceType *T, Qualifiers,
@@ -3514,39 +3511,23 @@ void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *,
3514
3511
3515
3512
void MicrosoftCXXNameMangler::mangleType (const TemplateSpecializationType *T,
3516
3513
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;
3514
+ Error (Range.getBegin (), " template specialization type" ) << Range;
3522
3515
}
3523
3516
3524
3517
void MicrosoftCXXNameMangler::mangleType (const DependentNameType *T, Qualifiers,
3525
3518
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;
3519
+ Error (Range.getBegin (), " dependent name type" ) << Range;
3531
3520
}
3532
3521
3533
3522
void MicrosoftCXXNameMangler::mangleType (
3534
3523
const DependentTemplateSpecializationType *T, Qualifiers,
3535
3524
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;
3525
+ Error (Range.getBegin (), " dependent template specialization type" ) << Range;
3541
3526
}
3542
3527
3543
3528
void MicrosoftCXXNameMangler::mangleType (const PackExpansionType *T, Qualifiers,
3544
3529
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;
3530
+ Error (Range.getBegin (), " pack expansion" ) << Range;
3550
3531
}
3551
3532
3552
3533
void MicrosoftCXXNameMangler::mangleType (const PackIndexingType *T,
@@ -3557,60 +3538,37 @@ void MicrosoftCXXNameMangler::mangleType(const PackIndexingType *T,
3557
3538
3558
3539
void MicrosoftCXXNameMangler::mangleType (const TypeOfType *T, Qualifiers,
3559
3540
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;
3541
+ Error (Range.getBegin (), " typeof(type)" ) << Range;
3565
3542
}
3566
3543
3567
3544
void MicrosoftCXXNameMangler::mangleType (const TypeOfExprType *T, Qualifiers,
3568
3545
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;
3546
+ Error (Range.getBegin (), " typeof(expression)" ) << Range;
3574
3547
}
3575
3548
3576
3549
void MicrosoftCXXNameMangler::mangleType (const DecltypeType *T, Qualifiers,
3577
3550
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;
3551
+ Error (Range.getBegin (), " decltype()" ) << Range;
3583
3552
}
3584
3553
3585
3554
void MicrosoftCXXNameMangler::mangleType (const UnaryTransformType *T,
3586
3555
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;
3556
+ Error (Range.getBegin (), " unary transform type" ) << Range;
3592
3557
}
3593
3558
3594
3559
void MicrosoftCXXNameMangler::mangleType (const AutoType *T, Qualifiers,
3595
3560
SourceRange Range) {
3596
3561
assert (T->getDeducedType ().isNull () && " expecting a dependent type!" );
3597
3562
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;
3563
+ Error (Range.getBegin (), " 'auto' type" ) << Range;
3603
3564
}
3604
3565
3605
3566
void MicrosoftCXXNameMangler::mangleType (
3606
3567
const DeducedTemplateSpecializationType *T, Qualifiers, SourceRange Range) {
3607
3568
assert (T->getDeducedType ().isNull () && " expecting a dependent type!" );
3608
3569
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;
3570
+ Error (Range.getBegin (), " deduced class template specialization type" )
3571
+ << Range;
3614
3572
}
3615
3573
3616
3574
void MicrosoftCXXNameMangler::mangleType (const AtomicType *T, Qualifiers,
@@ -3684,10 +3642,7 @@ void MicrosoftCXXNameMangler::mangleType(const BitIntType *T, Qualifiers,
3684
3642
3685
3643
void MicrosoftCXXNameMangler::mangleType (const DependentBitIntType *T,
3686
3644
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;
3645
+ Error (Range.getBegin (), " DependentBitInt type" ) << Range;
3691
3646
}
3692
3647
3693
3648
// <this-adjustment> ::= <no-adjustment> | <static-adjustment> |
0 commit comments