@@ -1111,6 +1111,45 @@ WalkTemplateSpecializationKind(clang::TemplateSpecializationKind Kind)
1111
1111
llvm_unreachable (" Unknown template specialization kind" );
1112
1112
}
1113
1113
1114
+ // -----------------------------------//
1115
+
1116
+ struct Diagnostic
1117
+ {
1118
+ clang::SourceLocation Location;
1119
+ llvm::SmallString<100 > Message;
1120
+ clang::DiagnosticsEngine::Level Level;
1121
+ };
1122
+
1123
+ struct DiagnosticConsumer : public clang ::DiagnosticConsumer
1124
+ {
1125
+ virtual void HandleDiagnostic (clang::DiagnosticsEngine::Level Level,
1126
+ const clang::Diagnostic& Info) override {
1127
+ // Update the base type NumWarnings and NumErrors variables.
1128
+ if (Level == clang::DiagnosticsEngine::Warning)
1129
+ NumWarnings++;
1130
+
1131
+ if (Level == clang::DiagnosticsEngine::Error ||
1132
+ Level == clang::DiagnosticsEngine::Fatal)
1133
+ {
1134
+ NumErrors++;
1135
+ if (Decl)
1136
+ {
1137
+ Decl->setInvalidDecl ();
1138
+ Decl = 0 ;
1139
+ }
1140
+ }
1141
+
1142
+ auto Diag = Diagnostic ();
1143
+ Diag.Location = Info.getLocation ();
1144
+ Diag.Level = Level;
1145
+ Info.FormatDiagnostic (Diag.Message );
1146
+ Diagnostics.push_back (Diag);
1147
+ }
1148
+
1149
+ std::vector<Diagnostic> Diagnostics;
1150
+ clang::Decl* Decl;
1151
+ };
1152
+
1114
1153
ClassTemplateSpecialization*
1115
1154
Parser::WalkClassTemplateSpecialization (const clang::ClassTemplateSpecializationDecl* CTS)
1116
1155
{
@@ -2110,39 +2149,6 @@ static const clang::Type* GetFinalType(const clang::Type* Ty)
2110
2149
}
2111
2150
}
2112
2151
2113
- bool Parser::ShouldCompleteType (const clang::QualType& QualType, bool LocValid)
2114
- {
2115
- auto FinalType = GetFinalType (QualType.getTypePtr ());
2116
- if (auto Tag = FinalType->getAsTagDecl ())
2117
- {
2118
- if (auto CTS = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(Tag))
2119
- {
2120
- // we cannot get a location in some cases of template arguments
2121
- if (!LocValid || CTS->isCompleteDefinition ())
2122
- return false ;
2123
-
2124
- auto TAL = &CTS->getTemplateArgs ();
2125
- for (size_t i = 0 ; i < TAL->size (); i++)
2126
- {
2127
- auto TA = TAL->get (i);
2128
- if (TA.getKind () == clang::TemplateArgument::ArgKind::Type)
2129
- {
2130
- auto Type = TA.getAsType ();
2131
- if (Type->isVoidType ())
2132
- return false ;
2133
- }
2134
- }
2135
- auto Unit = GetTranslationUnit (Tag);
2136
- // HACK: completing all system types overflows the managed stack
2137
- // while running the AST converter since the latter is a giant indirect recursion
2138
- // this solution is a hack because we might need to complete system template specialisations
2139
- // such as std:string or std::vector in order to represent them in the target language
2140
- return !Unit->isSystemHeader ;
2141
- }
2142
- }
2143
- return false ;
2144
- }
2145
-
2146
2152
Type* Parser::WalkType (clang::QualType QualType, const clang::TypeLoc* TL,
2147
2153
bool DesugarType)
2148
2154
{
@@ -2153,11 +2159,6 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
2153
2159
2154
2160
auto LocValid = TL && !TL->isNull ();
2155
2161
2156
- auto CompleteType = ShouldCompleteType (QualType, LocValid);
2157
- if (CompleteType)
2158
- c->getSema ().RequireCompleteType (
2159
- LocValid ? TL->getLocStart () : clang::SourceLocation (), QualType, 1 );
2160
-
2161
2162
const clang::Type* Type = QualType.getTypePtr ();
2162
2163
2163
2164
if (DesugarType)
@@ -2857,8 +2858,8 @@ bool Parser::CanCheckCodeGenInfo(clang::Sema& S, const clang::Type* Ty)
2857
2858
{
2858
2859
auto FinalType = GetFinalType (Ty);
2859
2860
2860
- if (Ty-> isDependentType () || FinalType->isDependentType () ||
2861
- FinalType->isInstantiationDependentType ())
2861
+ if (FinalType->isDependentType () ||
2862
+ FinalType->isInstantiationDependentType () || FinalType-> isUndeducedType () )
2862
2863
return false ;
2863
2864
2864
2865
if (auto RT = FinalType->getAs <clang::RecordType>())
@@ -2899,6 +2900,27 @@ static clang::TypeLoc DesugarTypeLoc(const clang::TypeLoc& Loc)
2899
2900
return Loc;
2900
2901
}
2901
2902
2903
+ void Parser::CompleteIfSpecializationType (const clang::QualType& QualType)
2904
+ {
2905
+ using namespace clang ;
2906
+
2907
+ auto Type = QualType->getUnqualifiedDesugaredType ();
2908
+ auto RD = Type->getAsCXXRecordDecl ();
2909
+ if (!RD)
2910
+ RD = const_cast <CXXRecordDecl*>(Type->getPointeeCXXRecordDecl ());
2911
+ ClassTemplateSpecializationDecl* CTS;
2912
+ if (!RD ||
2913
+ !(CTS = llvm::dyn_cast<ClassTemplateSpecializationDecl>(RD)) ||
2914
+ CTS->isCompleteDefinition ())
2915
+ return ;
2916
+
2917
+ auto Diagnostics = c->getSema ().getDiagnostics ().getClient ();
2918
+ auto SemaDiagnostics = static_cast <::DiagnosticConsumer*>(Diagnostics);
2919
+ SemaDiagnostics->Decl = CTS;
2920
+ c->getSema ().InstantiateClassTemplateSpecialization (CTS->getLocStart (),
2921
+ CTS, TSK_ImplicitInstantiation, false );
2922
+ }
2923
+
2902
2924
Parameter* Parser::WalkParameter (const clang::ParmVarDecl* PVD,
2903
2925
const clang::SourceLocation& ParamStartLoc)
2904
2926
{
@@ -2913,14 +2935,18 @@ Parameter* Parser::WalkParameter(const clang::ParmVarDecl* PVD,
2913
2935
2914
2936
TypeLoc PTL;
2915
2937
if (auto TSI = PVD->getTypeSourceInfo ())
2916
- PTL = PVD-> getTypeSourceInfo () ->getTypeLoc ();
2938
+ PTL = TSI ->getTypeLoc ();
2917
2939
2918
2940
auto paramRange = PVD->getSourceRange ();
2919
2941
paramRange.setBegin (ParamStartLoc);
2920
2942
2921
2943
HandlePreprocessedEntities (P, paramRange, MacroLocation::FunctionParameters);
2922
2944
2923
- P->qualifiedType = GetQualifiedType (PVD->getOriginalType (), &PTL);
2945
+ const auto & Type = PVD->getOriginalType ();
2946
+ auto Function = PVD->getParentFunctionOrMethod ();
2947
+ if (Function && cast<NamedDecl>(Function)->isExternallyVisible ())
2948
+ CompleteIfSpecializationType (Type);
2949
+ P->qualifiedType = GetQualifiedType (Type, &PTL);
2924
2950
P->hasDefaultValue = PVD->hasDefaultArg ();
2925
2951
P->index = PVD->getFunctionScopeIndex ();
2926
2952
if (PVD->hasDefaultArg () && !PVD->hasUnparsedDefaultArg ())
@@ -3008,8 +3034,11 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
3008
3034
}
3009
3035
else
3010
3036
F->qualifiedType = GetQualifiedType (FD->getType ());
3011
-
3012
- F->returnType = GetQualifiedType (FD->getReturnType (), &RTL);
3037
+
3038
+ auto ReturnType = FD->getReturnType ();
3039
+ if (FD->isExternallyVisible ())
3040
+ CompleteIfSpecializationType (ReturnType);
3041
+ F->returnType = GetQualifiedType (ReturnType, &RTL);
3013
3042
3014
3043
const auto & Mangled = GetDeclMangledName (FD);
3015
3044
F->mangled = Mangled;
@@ -3047,7 +3076,7 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
3047
3076
if (GetDeclText (Range, Sig))
3048
3077
F->signature = Sig;
3049
3078
3050
- for (const auto & VD : FD->parameters ())
3079
+ for (auto VD : FD->parameters ())
3051
3080
{
3052
3081
auto P = WalkParameter (VD, ParamStartLoc);
3053
3082
F->Parameters .push_back (P);
@@ -3069,6 +3098,9 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
3069
3098
if (auto FTSI = FD->getTemplateSpecializationInfo ())
3070
3099
F->specializationInfo = WalkFunctionTemplateSpec (FTSI, F);
3071
3100
3101
+ if (F->isDependent )
3102
+ return ;
3103
+
3072
3104
const CXXMethodDecl* MD;
3073
3105
if ((MD = dyn_cast<CXXMethodDecl>(FD)) && !MD->isStatic () &&
3074
3106
!HasLayout (cast<CXXRecordDecl>(MD->getDeclContext ())))
@@ -3874,39 +3906,6 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D)
3874
3906
return Decl;
3875
3907
}
3876
3908
3877
- // -----------------------------------//
3878
-
3879
- struct Diagnostic
3880
- {
3881
- clang::SourceLocation Location;
3882
- llvm::SmallString<100 > Message;
3883
- clang::DiagnosticsEngine::Level Level;
3884
- };
3885
-
3886
- struct DiagnosticConsumer : public clang ::DiagnosticConsumer
3887
- {
3888
- virtual ~DiagnosticConsumer () { }
3889
-
3890
- virtual void HandleDiagnostic (clang::DiagnosticsEngine::Level Level,
3891
- const clang::Diagnostic& Info) override {
3892
- // Update the base type NumWarnings and NumErrors variables.
3893
- if (Level == clang::DiagnosticsEngine::Warning)
3894
- NumWarnings++;
3895
-
3896
- if (Level == clang::DiagnosticsEngine::Error ||
3897
- Level == clang::DiagnosticsEngine::Fatal)
3898
- NumErrors++;
3899
-
3900
- auto Diag = Diagnostic ();
3901
- Diag.Location = Info.getLocation ();
3902
- Diag.Level = Level;
3903
- Info.FormatDiagnostic (Diag.Message );
3904
- Diagnostics.push_back (Diag);
3905
- }
3906
-
3907
- std::vector<Diagnostic> Diagnostics;
3908
- };
3909
-
3910
3909
void Parser::HandleDiagnostics (ParserResult* res)
3911
3910
{
3912
3911
auto DiagClient = (DiagnosticConsumer&) c->getDiagnosticClient ();
0 commit comments