Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit f611897

Browse files
committed
Revert accidential "[MSVC] Late parsing of in-class defined member functions in template"
This reverts commit 0253605. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272776 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 32c03b7 commit f611897

22 files changed

+12
-315
lines changed

include/clang-c/Index.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -2305,11 +2305,7 @@ enum CXCursorKind {
23052305
*/
23062306
CXCursor_OMPTargetUpdateDirective = 265,
23072307

2308-
/** \brief A MS-specific late parsed compound statement.
2309-
*/
2310-
CXCursor_MSLateParsedCompoundStmt = 266,
2311-
2312-
CXCursor_LastStmt = CXCursor_MSLateParsedCompoundStmt,
2308+
CXCursor_LastStmt = CXCursor_OMPTargetUpdateDirective,
23132309

23142310
/**
23152311
* \brief Cursor that represents the translation unit itself.

include/clang/AST/RecursiveASTVisitor.h

-1
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,6 @@ DEF_TRAVERSE_STMT(SEHExceptStmt, {})
23322332
DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
23332333
DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
23342334
DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
2335-
DEF_TRAVERSE_STMT(MSLateParsedCompoundStmt, {})
23362335

23372336
DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
23382337
DEF_TRAVERSE_STMT(OpaqueValueExpr, {})

include/clang/AST/StmtCXX.h

-46
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "clang/AST/Expr.h"
1919
#include "clang/AST/NestedNameSpecifier.h"
2020
#include "clang/AST/Stmt.h"
21-
#include "clang/Lex/Token.h"
2221
#include "llvm/Support/Compiler.h"
2322

2423
namespace clang {
@@ -418,51 +417,6 @@ class CoreturnStmt : public Stmt {
418417
}
419418
};
420419

421-
/// This represents a group of statements like { stmt stmt } that must be parsed
422-
/// only during instantiation. Required for better MSVC compatibility.
423-
class MSLateParsedCompoundStmt final
424-
: public Stmt,
425-
private llvm::TrailingObjects<MSLateParsedCompoundStmt, Token> {
426-
friend class TrailingObjects;
427-
friend class ASTStmtReader;
428-
SourceLocation LBraceLoc, RBraceLoc;
429-
StringRef StringRep;
430-
unsigned NumToks;
431-
432-
MSLateParsedCompoundStmt()
433-
: Stmt(MSLateParsedCompoundStmtClass), NumToks(0) {}
434-
435-
/// Set tokens for the statement.
436-
void init(ASTContext &C, SourceLocation LB, SourceLocation RB,
437-
ArrayRef<Token> Tokens, StringRef Rep);
438-
439-
public:
440-
static MSLateParsedCompoundStmt *Create(ASTContext &C, SourceLocation LB,
441-
SourceLocation RB,
442-
ArrayRef<Token> Tokens,
443-
StringRef Rep);
444-
/// Build an empty statement.
445-
static MSLateParsedCompoundStmt *CreateEmpty(ASTContext &C,
446-
unsigned NumTokens);
447-
448-
SourceLocation getLocStart() const LLVM_READONLY { return LBraceLoc; }
449-
SourceLocation getLocEnd() const LLVM_READONLY { return RBraceLoc; }
450-
451-
/// Returns representation of the statement as a string.
452-
StringRef getStringRepresentation() const { return StringRep; }
453-
454-
/// Get list of tokens associated with the statement.
455-
ArrayRef<Token> tokens() const;
456-
457-
child_range children() {
458-
return child_range(child_iterator(), child_iterator());
459-
}
460-
461-
static bool classof(const Stmt *S) {
462-
return S->getStmtClass() == MSLateParsedCompoundStmtClass;
463-
}
464-
};
465-
466420
} // end namespace clang
467421

468422
#endif

include/clang/Basic/StmtNodes.td

-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ def SEHExceptStmt : Stmt;
187187
def SEHFinallyStmt : Stmt;
188188
def SEHLeaveStmt : Stmt;
189189
def MSDependentExistsStmt : Stmt;
190-
def MSLateParsedCompoundStmt : Stmt;
191190

192191
// OpenCL Extensions.
193192
def AsTypeExpr : DStmt<Expr>;

include/clang/Parse/Parser.h

-2
Original file line numberDiff line numberDiff line change
@@ -1181,11 +1181,9 @@ class Parser : public CodeCompletionHandler {
11811181

11821182
void LexTemplateFunctionForLateParsing(CachedTokens &Toks);
11831183
void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
1184-
void ParseMSVCTemplatedFuncDef(LateParsedTemplate &LPT);
11851184

11861185
static void LateTemplateParserCallback(void *P, LateParsedTemplate &LPT);
11871186
static void LateTemplateParserCleanupCallback(void *P);
1188-
static void MSVCTemplateParserCallback(void *P, LateParsedTemplate &LPT);
11891187

11901188
Sema::ParsingClassState
11911189
PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface);

include/clang/Sema/Sema.h

-5
Original file line numberDiff line numberDiff line change
@@ -3507,11 +3507,6 @@ class Sema {
35073507
LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
35083508
SourceLocation Location,
35093509
bool AlwaysCreate);
3510-
/// Builds late parsed compound statement or just compound statement in MSVC
3511-
/// compatibility mode.
3512-
StmtResult ActOnMSLateParsedCompoundStmt(SourceLocation LB, SourceLocation RB,
3513-
ArrayRef<Token> Tokens,
3514-
StringRef Rep);
35153510

35163511
VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
35173512
SourceLocation StartLoc,

include/clang/Serialization/ASTBitCodes.h

-2
Original file line numberDiff line numberDiff line change
@@ -1220,8 +1220,6 @@ namespace clang {
12201220
STMT_GCCASM,
12211221
/// \brief A MS-style AsmStmt record.
12221222
STMT_MSASM,
1223-
/// \brief A MS-specific late parsed compound statement.
1224-
STMT_MS_LATE_PARSED_COMPOUND,
12251223
/// \brief A PredefinedExpr record.
12261224
EXPR_PREDEFINED,
12271225
/// \brief A DeclRefExpr record.

lib/AST/StmtCXX.cpp

-35
Original file line numberDiff line numberDiff line change
@@ -86,38 +86,3 @@ VarDecl *CXXForRangeStmt::getLoopVariable() {
8686
const VarDecl *CXXForRangeStmt::getLoopVariable() const {
8787
return const_cast<CXXForRangeStmt *>(this)->getLoopVariable();
8888
}
89-
90-
MSLateParsedCompoundStmt *
91-
MSLateParsedCompoundStmt::Create(ASTContext &C, SourceLocation LB,
92-
SourceLocation RB, ArrayRef<Token> Tokens,
93-
StringRef Rep) {
94-
// Allocate space for private variables and initializer expressions.
95-
void *Mem = C.Allocate(totalSizeToAlloc<Token>(Tokens.size()),
96-
llvm::alignOf<MSLateParsedCompoundStmt>());
97-
auto *S = new (Mem) MSLateParsedCompoundStmt();
98-
S->init(C, LB, RB, Tokens, Rep);
99-
return S;
100-
}
101-
102-
MSLateParsedCompoundStmt *
103-
MSLateParsedCompoundStmt::CreateEmpty(ASTContext &C, unsigned NumTokens) {
104-
// Allocate space for private variables and initializer expressions.
105-
void *Mem = C.Allocate(totalSizeToAlloc<Token>(NumTokens),
106-
llvm::alignOf<MSLateParsedCompoundStmt>());
107-
return new (Mem) MSLateParsedCompoundStmt();
108-
}
109-
110-
void MSLateParsedCompoundStmt::init(ASTContext &C, SourceLocation LB,
111-
SourceLocation RB, ArrayRef<Token> Tokens,
112-
StringRef Rep) {
113-
LBraceLoc = LB;
114-
RBraceLoc = RB;
115-
std::copy(Tokens.begin(), Tokens.end(), getTrailingObjects<Token>());
116-
StringRep = Rep.copy(C);
117-
NumToks = Tokens.size();
118-
}
119-
120-
ArrayRef<Token> MSLateParsedCompoundStmt::tokens() const {
121-
return llvm::makeArrayRef(getTrailingObjects<Token>(), NumToks);
122-
}
123-

lib/AST/StmtPrinter.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -2352,10 +2352,6 @@ void StmtPrinter::VisitCoreturnStmt(CoreturnStmt *S) {
23522352
OS << ";";
23532353
}
23542354

2355-
void StmtPrinter::VisitMSLateParsedCompoundStmt(MSLateParsedCompoundStmt *S) {
2356-
OS << S->getStringRepresentation();
2357-
}
2358-
23592355
void StmtPrinter::VisitCoawaitExpr(CoawaitExpr *S) {
23602356
OS << "co_await ";
23612357
PrintExpr(S->getOperand());

lib/AST/StmtProfile.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -1499,11 +1499,6 @@ void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
14991499
VisitStmt(S);
15001500
}
15011501

1502-
void StmtProfiler::VisitMSLateParsedCompoundStmt(
1503-
const MSLateParsedCompoundStmt *S) {
1504-
VisitStmt(S);
1505-
}
1506-
15071502
void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
15081503
VisitExpr(S);
15091504
}

lib/CodeGen/CGStmt.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ void CodeGenFunction::EmitStmt(const Stmt *S) {
8080
case Stmt::SEHExceptStmtClass:
8181
case Stmt::SEHFinallyStmtClass:
8282
case Stmt::MSDependentExistsStmtClass:
83-
case Stmt::MSLateParsedCompoundStmtClass:
8483
llvm_unreachable("invalid statement class to emit generically");
8584
case Stmt::NullStmtClass:
8685
case Stmt::CompoundStmtClass:

lib/Parse/ParseTemplate.cpp

-84
Original file line numberDiff line numberDiff line change
@@ -1417,90 +1417,6 @@ void Parser::ParseLateTemplatedFuncDef(LateParsedTemplate &LPT) {
14171417
delete *I;
14181418
}
14191419

1420-
void Parser::MSVCTemplateParserCallback(void *P, LateParsedTemplate &LPT) {
1421-
((Parser *)P)->ParseMSVCTemplatedFuncDef(LPT);
1422-
}
1423-
1424-
/// \brief Late parse a C++ function template in Microsoft mode.
1425-
void Parser::ParseMSVCTemplatedFuncDef(LateParsedTemplate &LPT) {
1426-
if (!LPT.D)
1427-
return;
1428-
1429-
// Get the FunctionDecl.
1430-
FunctionDecl *FunD = LPT.D->getAsFunction();
1431-
// Track template parameter depth.
1432-
TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1433-
1434-
SmallVector<ParseScope*, 4> TemplateParamScopeStack;
1435-
1436-
// Get the list of DeclContexts to reenter.
1437-
SmallVector<DeclContext*, 4> DeclContextsToReenter;
1438-
DeclContext *DD = FunD;
1439-
while (DD && !DD->isTranslationUnit()) {
1440-
DeclContextsToReenter.push_back(DD);
1441-
DD = DD->getLexicalParent();
1442-
}
1443-
1444-
// Reenter template scopes from outermost to innermost.
1445-
SmallVectorImpl<DeclContext *>::reverse_iterator II =
1446-
DeclContextsToReenter.rbegin();
1447-
for (; II != DeclContextsToReenter.rend(); ++II) {
1448-
TemplateParamScopeStack.push_back(new ParseScope(this,
1449-
Scope::TemplateParamScope));
1450-
unsigned NumParamLists =
1451-
Actions.ActOnReenterTemplateScope(getCurScope(), cast<Decl>(*II));
1452-
CurTemplateDepthTracker.addDepth(NumParamLists);
1453-
if (*II != FunD) {
1454-
TemplateParamScopeStack.push_back(new ParseScope(this, Scope::DeclScope));
1455-
Actions.PushDeclContext(Actions.getCurScope(), *II);
1456-
}
1457-
}
1458-
1459-
assert(!LPT.Toks.empty() && "Empty body!");
1460-
1461-
// Append the current token at the end of the new token stream so that it
1462-
// doesn't get lost.
1463-
LPT.Toks.push_back(Tok);
1464-
PP.EnterTokenStream(LPT.Toks, true);
1465-
1466-
// Consume the previously pushed token.
1467-
ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
1468-
assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try) &&
1469-
"Inline method not starting with '{', ':' or 'try'");
1470-
1471-
// Parse the method body. Function body parsing code is similar enough
1472-
// to be re-used for method bodies as well.
1473-
ParseScope FnScope(this, Scope::FnScope|Scope::DeclScope);
1474-
1475-
if (Tok.is(tok::kw_try)) {
1476-
ParseFunctionTryBlock(LPT.D, FnScope);
1477-
} else {
1478-
if (Tok.is(tok::colon))
1479-
ParseConstructorInitializer(LPT.D);
1480-
else
1481-
Actions.ActOnDefaultCtorInitializers(LPT.D);
1482-
1483-
if (Tok.is(tok::l_brace)) {
1484-
assert((!isa<FunctionTemplateDecl>(LPT.D) ||
1485-
cast<FunctionTemplateDecl>(LPT.D)
1486-
->getTemplateParameters()
1487-
->getDepth() == TemplateParameterDepth - 1) &&
1488-
"TemplateParameterDepth should be greater than the depth of "
1489-
"current template being instantiated!");
1490-
ParseFunctionStatementBody(LPT.D, FnScope);
1491-
Actions.UnmarkAsLateParsedTemplate(FunD);
1492-
} else
1493-
Actions.ActOnFinishFunctionBody(LPT.D, nullptr);
1494-
}
1495-
1496-
// Exit scopes.
1497-
FnScope.Exit();
1498-
SmallVectorImpl<ParseScope *>::reverse_iterator I =
1499-
TemplateParamScopeStack.rbegin();
1500-
for (; I != TemplateParamScopeStack.rend(); ++I)
1501-
delete *I;
1502-
}
1503-
15041420
/// \brief Lex a delayed template function for late parsing.
15051421
void Parser::LexTemplateFunctionForLateParsing(CachedTokens &Toks) {
15061422
tok::TokenKind kind = Tok.getKind();

lib/Parse/Parser.cpp

+6-31
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies)
8989
PP.addCommentHandler(CommentSemaHandler.get());
9090

9191
PP.setCodeCompletionHandler(*this);
92-
if (getLangOpts().MSVCCompat)
93-
Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, this);
9492
}
9593

9694
DiagnosticBuilder Parser::Diag(SourceLocation Loc, unsigned DiagID) {
@@ -1055,35 +1053,12 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
10551053
Actions.MarkAsLateParsedTemplate(FnD, DP, Toks);
10561054
}
10571055
return DP;
1058-
} else if (getLangOpts().MSVCCompat && Tok.isNot(tok::equal) &&
1059-
TemplateInfo.Kind == ParsedTemplateInfo::Template &&
1060-
Actions.canDelayFunctionBody(D)) {
1061-
// In delayed template parsing mode, for function template we consume the
1062-
// tokens and store them for late parsing at the end of the translation
1063-
// unit.
1064-
MultiTemplateParamsArg TemplateParameterLists(*TemplateInfo.TemplateParams);
1065-
1066-
ParseScope BodyScope(this, Scope::FnScope | Scope::DeclScope);
1067-
1068-
CachedTokens Toks;
1069-
LexTemplateFunctionForLateParsing(Toks);
1070-
1071-
Decl *Res = Actions.ActOnStartOfFunctionDef(getCurScope(), D,
1072-
*TemplateInfo.TemplateParams);
1073-
D.complete(Res);
1074-
D.getMutableDeclSpec().abort();
1075-
StmtResult Body = Actions.ActOnMSLateParsedCompoundStmt(
1076-
Toks.begin()->getLocation(), Tok.getLocation(), Toks,
1077-
Lexer::getSourceText(
1078-
{{Toks.begin()->getLocation(), Tok.getLocation()}, false},
1079-
Actions.getASTContext().getSourceManager(), getLangOpts()));
1080-
BodyScope.Exit();
1081-
1082-
return Actions.ActOnFinishFunctionBody(Res, Body.get());
1083-
} else if (CurParsedObjCImpl && !TemplateInfo.TemplateParams &&
1084-
(Tok.is(tok::l_brace) || Tok.is(tok::kw_try) ||
1085-
Tok.is(tok::colon)) &&
1086-
Actions.CurContext->isTranslationUnit()) {
1056+
}
1057+
else if (CurParsedObjCImpl &&
1058+
!TemplateInfo.TemplateParams &&
1059+
(Tok.is(tok::l_brace) || Tok.is(tok::kw_try) ||
1060+
Tok.is(tok::colon)) &&
1061+
Actions.CurContext->isTranslationUnit()) {
10871062
ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);
10881063
Scope *ParentScope = getCurScope()->getParent();
10891064

lib/Sema/SemaExpr.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2213,11 +2213,11 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
22132213
bool ADL = UseArgumentDependentLookup(SS, R, HasTrailingLParen);
22142214

22152215
if (R.empty() && !ADL) {
2216-
// if (SS.isEmpty() && getLangOpts().MSVCCompat) {
2217-
// if (Expr *E = recoverFromMSUnqualifiedLookup(*this, Context, NameInfo,
2218-
// TemplateKWLoc, TemplateArgs))
2219-
// return E;
2220-
// }
2216+
if (SS.isEmpty() && getLangOpts().MSVCCompat) {
2217+
if (Expr *E = recoverFromMSUnqualifiedLookup(*this, Context, NameInfo,
2218+
TemplateKWLoc, TemplateArgs))
2219+
return E;
2220+
}
22212221

22222222
// Don't diagnose an empty lookup for inline assembly.
22232223
if (IsInlineAsmIdentifier)

lib/Sema/SemaStmt.cpp

-27
Original file line numberDiff line numberDiff line change
@@ -3978,30 +3978,3 @@ StmtResult Sema::ActOnCapturedRegionEnd(Stmt *S) {
39783978

39793979
return Res;
39803980
}
3981-
3982-
StmtResult Sema::ActOnMSLateParsedCompoundStmt(SourceLocation LB,
3983-
SourceLocation RB,
3984-
ArrayRef<Token> Tokens,
3985-
StringRef Rep) {
3986-
if (CurContext->isDependentContext())
3987-
return MSLateParsedCompoundStmt::Create(getASTContext(), LB, RB, Tokens,
3988-
Rep);
3989-
3990-
QualType CXXThisTy = getCurrentThisType();
3991-
assert(!CXXThisTy.isNull());
3992-
auto *CXXThisRD = CXXThisTy->castAs<PointerType>()
3993-
->getPointeeCXXRecordDecl()
3994-
->getCanonicalDecl();
3995-
DeclContext *DC = getFunctionLevelDeclContext();
3996-
while (auto *PCXXRD = dyn_cast<CXXRecordDecl>(DC)) {
3997-
if (PCXXRD->getCanonicalDecl() == CXXThisRD)
3998-
break;
3999-
DC = DC->getParent();
4000-
}
4001-
auto *MD = dyn_cast<CXXMethodDecl>(DC);
4002-
LateParsedTemplate LPT;
4003-
LPT.Toks.append(Tokens.begin(), Tokens.end());
4004-
LPT.D = MD;
4005-
LateTemplateParser(OpaqueParser, LPT);
4006-
return MD->getBody();
4007-
}

0 commit comments

Comments
 (0)