[Sema] Make getCurFunction() return null outside function parsing
authorReid Kleckner <rnk@google.com>
Thu, 8 Mar 2018 00:14:34 +0000 (00:14 +0000)
committerReid Kleckner <rnk@google.com>
Thu, 8 Mar 2018 00:14:34 +0000 (00:14 +0000)
commitc2fd3529630d24e3b561f8d6dd5fca282616ad34
treea6205b2ebc5e05721ab89ca9ab401ccc90655fa6
parentc4a13015fd6b83b802cd830f8adc9693d6392c48
[Sema] Make getCurFunction() return null outside function parsing

Summary:
Before this patch, Sema pre-allocated a FunctionScopeInfo and kept it in
the first, always present element of the FunctionScopes stack. This
meant that Sema::getCurFunction would return a pointer to this
pre-allocated object when parsing code outside a function body. This is
pretty much always a bug, so this patch moves the pre-allocated object
into a separate unique_ptr. This should make bugs like PR36536 a lot
more obvious.

As you can see from this patch, there were a number of places that
unconditionally assumed they were always called inside a function.
However, there are also many places that null checked the result of
getCurFunction(), so I think this is a reasonable direction.

Reviewers: rsmith

Subscribers: cfe-commits

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

llvm-svn: 326965
clang/include/clang/Sema/Sema.h
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaStmtAsm.cpp