llvm-project/clang/lib/Sema
Reid Kleckner b2da086103 Push a function scope when parsing function bodies without a declaration
Summary:
This is PR36536.

There are a few ways to reach Sema::ActOnStartOfFunctionDef with a null
Decl. Currently, the parser continues on to attempt to parse the
statements in the function body without pushing a function scope or
declaration context. However, lots of statement parsing logic relies on
getCurFunction() returning something reasonable. It turns out that
getCurFunction() will never return null today because of an optimization
where Sema pre-allocates one FunctionScopeInfo and reuses it when
possible. This goes wrong when something inside the function body causes
us to push another function scope, such as requiring an implicit
definition of a special member function. Reusing the state clears it
out, which will lead to bugs. In PR36536, we found that the SwitchStack
gets unbalanced, because we push a switch, clear out the stack, and then
try to pop a switch that isn't there.

As a follow-up, I plan to move the pre-allocated FunctionScopeInfo out
of the FunctionScopes stack. This means the FunctionScopes stack will
often be empty, and callers of getCurFunction() will need to check for
null.

Reviewers: thakis

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D43980

llvm-svn: 326926
2018-03-07 18:55:10 +00:00
..
AnalysisBasedWarnings.cpp [Sema] Fix -Wunused-variable 2018-02-20 07:21:56 +00:00
AttributeList.cpp [Sema] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2018-02-20 02:16:28 +00:00
CMakeLists.txt Enabling the /bigobj flag for SemaDeclAttr.cpp. 2017-05-12 14:30:49 +00:00
CodeCompleteConsumer.cpp [Sema] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2018-02-20 02:16:28 +00:00
CoroutineStmtBuilder.h [coroutines] Pass coro func args to promise ctor 2018-01-24 22:15:42 +00:00
DeclSpec.cpp Again reverting an attempt to convert the DeclSpec enums into scoped enums. 2018-01-01 18:23:28 +00:00
DelayedDiagnostic.cpp [Sema] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2018-02-21 01:45:26 +00:00
IdentifierResolver.cpp [Sema] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2018-02-21 01:45:26 +00:00
JumpDiagnostics.cpp [ObjC] Allow declaring __strong pointer fields in structs in Objective-C 2018-02-28 07:15:55 +00:00
MultiplexExternalSemaSource.cpp [modules] Correctly overload getModule in the MultiplexExternalSemaSource 2018-01-22 15:27:25 +00:00
Scope.cpp Fix Scope::dump() 2018-01-18 04:28:56 +00:00
ScopeInfo.cpp [coroutines] Pass coro func args to promise ctor 2018-01-24 22:15:42 +00:00
Sema.cpp [NFC] Move CommentOpts checks to the call sites that depend on it. (Re-applying r326501.) 2018-03-02 00:07:45 +00:00
SemaAccess.cpp Revert r325321 "[Sema] Take into account the current context when checking the" 2018-02-16 12:06:32 +00:00
SemaAttr.cpp -Wpragma-pack: add an additional note and fixit when warning 2017-07-31 13:37:50 +00:00
SemaCUDA.cpp Function with unparsed body is a definition 2017-06-21 12:46:57 +00:00
SemaCXXScopeSpec.cpp Add support for editor placeholders to Clang 2017-04-19 08:58:56 +00:00
SemaCast.cpp Allow the target field of a CK_ToUnion to be more easily recovered. 2017-08-15 21:42:47 +00:00
SemaChecking.cpp Revert r326602, it caused PR36620. 2018-03-07 02:22:41 +00:00
SemaCodeComplete.cpp Remove redundant casts. NFC 2018-03-01 05:43:23 +00:00
SemaConsumer.cpp
SemaCoroutine.cpp [Coroutines] Use allocator overload when available 2018-02-15 20:37:22 +00:00
SemaDecl.cpp Push a function scope when parsing function bodies without a declaration 2018-03-07 18:55:10 +00:00
SemaDeclAttr.cpp Revert r326602, it caused PR36620. 2018-03-07 02:22:41 +00:00
SemaDeclCXX.cpp Remove redundant casts. NFC 2018-03-01 05:43:23 +00:00
SemaDeclObjC.cpp Remove redundant casts. NFC 2018-03-01 05:43:23 +00:00
SemaExceptionSpec.cpp Remove redundant casts. NFC 2018-03-01 05:43:23 +00:00
SemaExpr.cpp Add an option to disable tail-call optimization for escaping blocks. 2018-03-02 01:53:15 +00:00
SemaExprCXX.cpp Remove redundant casts. NFC 2018-03-01 05:43:23 +00:00
SemaExprMember.cpp Fif for an issue when Clang permits assignment to vector/extvector elements in a const method. 2018-02-09 09:30:42 +00:00
SemaExprObjC.cpp Add an option to disable tail-call optimization for escaping blocks. 2018-03-02 01:53:15 +00:00
SemaFixItUtils.cpp
SemaInit.cpp PR36055: fix computation of *-dependence in nested initializer lists. 2018-02-07 22:25:16 +00:00
SemaLambda.cpp Fix and simplify handling of return type for (generic) lambda conversion function to function pointer. 2018-01-02 23:52:42 +00:00
SemaLookup.cpp [CodeComplete] only respect LoadExternal hint at namespace/tu scope 2018-01-24 17:50:20 +00:00
SemaObjCProperty.cpp Remove redundant casts. NFC 2018-03-01 05:43:23 +00:00
SemaOpenMP.cpp [OPENMP] Treat local variables in CUDA mode as thread local. 2018-03-02 17:17:12 +00:00
SemaOverload.cpp [Sema] Classify conversions from enum to float as narrowing 2018-02-21 10:08:18 +00:00
SemaPseudoObject.cpp Remove debugging code I accidentally committed in r326530. 2018-03-02 02:03:21 +00:00
SemaStmt.cpp [Debug] Annotate compiler generated range-for loop variables. 2018-02-14 21:22:11 +00:00
SemaStmtAsm.cpp [X86][MS-InlineAsm] Extended support for variables / identifiers on memory / immediate expressions 2017-09-29 07:02:49 +00:00
SemaStmtAttr.cpp Now that C++17 is official (https://www.iso.org/standard/68564.html), start changing the C++1z terminology over to C++17. NFC intended, these are all mechanical changes. 2017-12-04 20:27:34 +00:00
SemaTemplate.cpp Remove redundant casts. NFC 2018-03-01 05:43:23 +00:00
SemaTemplateDeduction.cpp [Sema] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2018-02-22 22:35:17 +00:00
SemaTemplateInstantiate.cpp Remove redundant casts. NFC 2018-03-01 05:43:23 +00:00
SemaTemplateInstantiateDecl.cpp Revert r326602, it caused PR36620. 2018-03-07 02:22:41 +00:00
SemaTemplateVariadic.cpp Fix crash when trying to pack-expand a GNU statement expression. 2018-02-03 00:44:57 +00:00
SemaType.cpp Remove redundant casts. NFC 2018-03-01 05:43:23 +00:00
TreeTransform.h Fix a couple of places where we assumed that non-type template parameters are always rvalues. 2018-02-14 02:07:53 +00:00
TypeLocBuilder.cpp [Sema] Fix bug in TypeLocBuilder::pushImpl 2016-02-18 21:05:09 +00:00
TypeLocBuilder.h Retire llvm::alignOf in favor of C++11 alignof. 2016-10-20 14:27:22 +00:00