summaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2019-05-28 23:09:42 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2019-05-28 23:09:42 +0000
commit2ee14504678565a83ad74c0e85f8cb58abb9ffe3 (patch)
tree0e25ee2f5e0df06d0c4105b0a8a3f6b26359bec6 /lib/Sema/SemaExpr.cpp
parent1d6f4f1664c3a334f31d0546014a11a1f25385a7 (diff)
downloadclang-2ee14504678565a83ad74c0e85f8cb58abb9ffe3.tar.gz
Move code to mark a variable as odr-used adjacement to all the related
code. No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361890 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 3a12c2dd84..cc3dea9ead 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -15013,6 +15013,42 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
}
}
+/// Directly mark a variable odr-used. Given a choice, prefer to use
+/// MarkVariableReferenced since it does additional checks and then
+/// calls MarkVarDeclODRUsed.
+/// If the variable must be captured:
+/// - if FunctionScopeIndexToStopAt is null, capture it in the CurContext
+/// - else capture it in the DeclContext that maps to the
+/// *FunctionScopeIndexToStopAt on the FunctionScopeInfo stack.
+static void
+MarkVarDeclODRUsed(VarDecl *Var, SourceLocation Loc, Sema &SemaRef,
+ const unsigned *const FunctionScopeIndexToStopAt) {
+ // Keep track of used but undefined variables.
+ // FIXME: We shouldn't suppress this warning for static data members.
+ if (Var->hasDefinition(SemaRef.Context) == VarDecl::DeclarationOnly &&
+ (!Var->isExternallyVisible() || Var->isInline() ||
+ SemaRef.isExternalWithNoLinkageType(Var)) &&
+ !(Var->isStaticDataMember() && Var->hasInit())) {
+ SourceLocation &old = SemaRef.UndefinedButUsed[Var->getCanonicalDecl()];
+ if (old.isInvalid())
+ old = Loc;
+ }
+ QualType CaptureType, DeclRefType;
+ SemaRef.tryCaptureVariable(Var, Loc, Sema::TryCapture_Implicit,
+ /*EllipsisLoc*/ SourceLocation(),
+ /*BuildAndDiagnose*/ true,
+ CaptureType, DeclRefType,
+ FunctionScopeIndexToStopAt);
+
+ Var->markUsed(SemaRef.Context);
+}
+
+void Sema::MarkCaptureUsedInEnclosingContext(VarDecl *Capture,
+ SourceLocation Loc,
+ unsigned CapturingScopeIndex) {
+ MarkVarDeclODRUsed(Capture, Loc, *this, &CapturingScopeIndex);
+}
+
static void
diagnoseUncapturableValueReference(Sema &S, SourceLocation loc,
ValueDecl *var, DeclContext *DC) {