[PATCH] D44221: Avoid including ScopeInfo.h from Sema.h

2018-03-07 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326957: Avoid including ScopeInfo.h from Sema.h (authored by 
rnk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44221?vs=137487=137488#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44221

Files:
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  include/clang/Sema/SemaLambda.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaCoroutine.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprMember.cpp
  lib/Sema/SemaLambda.cpp
  lib/Sema/SemaPseudoObject.cpp
  lib/Sema/SemaStmt.cpp

Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -6930,7 +6930,7 @@
 /// variable \p VD, or an invalid source location otherwise.
 static SourceLocation getCaptureLocation(const LambdaScopeInfo *LSI,
  const VarDecl *VD) {
-  for (const LambdaScopeInfo::Capture  : LSI->Captures) {
+  for (const Capture  : LSI->Captures) {
 if (Capture.isVariableCapture() && Capture.getVariable() == VD)
   return Capture.getLocation();
   }
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -31,6 +31,7 @@
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Scope.h"
+#include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1426,6 +1426,18 @@
   return CurBSI;
 }
 
+FunctionScopeInfo *Sema::getEnclosingFunction() const {
+  if (FunctionScopes.empty())
+return nullptr;
+
+  for (int e = FunctionScopes.size() - 1; e >= 0; --e) {
+if (isa(FunctionScopes[e]))
+  continue;
+return FunctionScopes[e];
+  }
+  return nullptr;
+}
+
 LambdaScopeInfo *Sema::getCurLambda(bool IgnoreNonLambdaCapturingScope) {
   if (FunctionScopes.empty())
 return nullptr;
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -1679,9 +1679,9 @@
   MarkDeclRefReferenced(E);
 
   if (getLangOpts().ObjCWeak && isa(D) &&
-  Ty.getObjCLifetime() == Qualifiers::OCL_Weak &&
+  Ty.getObjCLifetime() == Qualifiers::OCL_Weak && !isUnevaluatedContext() &&
   !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->getLocStart()))
-  recordUseOfEvaluatedWeak(E);
+getCurFunction()->recordUseOfWeak(E);
 
   FieldDecl *FD = dyn_cast(D);
   if (IndirectFieldDecl *IFD = dyn_cast(D))
@@ -2431,8 +2431,9 @@
   IV->getLocation(), SelfExpr.get(), true, true);
 
   if (IV->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
-if (!Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, Loc))
-  recordUseOfEvaluatedWeak(Result);
+if (!isUnevaluatedContext() &&
+!Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, Loc))
+  getCurFunction()->recordUseOfWeak(Result);
   }
   if (getLangOpts().ObjCAutoRefCount) {
 if (CurContext->isClosure())
@@ -13045,7 +13046,7 @@
   // Set the captured variables on the block.
   // FIXME: Share capture structure between BlockDecl and CapturingScopeInfo!
   SmallVector Captures;
-  for (CapturingScopeInfo::Capture  : BSI->Captures) {
+  for (Capture  : BSI->Captures) {
 if (Cap.isThisCapture())
   continue;
 BlockDecl::Capture NewCap(Cap.getVariable(), Cap.isBlockCapture(),
@@ -14144,7 +14145,7 @@
 // Similarly to mutable captures in lambda, all the OpenMP captures by copy
 // are mutable in the sense that user can change their value - they are
 // private instances of the captured declarations.
-const CapturingScopeInfo::Capture  = CSI->getCapture(Var);
+const Capture  = CSI->getCapture(Var);
 if (Cap.isCopyCapture() &&
 !(isa(CSI) && cast(CSI)->Mutable) &&
 !(isa(CSI) &&
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -19,6 +19,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Overload.h"
+#include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaInternal.h"
 
 using namespace clang;
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -1479,8 +1479,9 @@
 IsArrow);
 
 if (IV->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
-  if 

[PATCH] D44221: Avoid including ScopeInfo.h from Sema.h

2018-03-07 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326957: Avoid including ScopeInfo.h from Sema.h (authored by 
rnk, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44221?vs=137487=137489#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44221

Files:
  cfe/trunk/include/clang/Sema/ScopeInfo.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/include/clang/Sema/SemaLambda.h
  cfe/trunk/lib/Sema/Sema.cpp
  cfe/trunk/lib/Sema/SemaCoroutine.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaExprMember.cpp
  cfe/trunk/lib/Sema/SemaLambda.cpp
  cfe/trunk/lib/Sema/SemaPseudoObject.cpp
  cfe/trunk/lib/Sema/SemaStmt.cpp

Index: cfe/trunk/include/clang/Sema/SemaLambda.h
===
--- cfe/trunk/include/clang/Sema/SemaLambda.h
+++ cfe/trunk/include/clang/Sema/SemaLambda.h
@@ -15,9 +15,13 @@
 
 #ifndef LLVM_CLANG_SEMA_SEMALAMBDA_H
 #define LLVM_CLANG_SEMA_SEMALAMBDA_H
+
 #include "clang/AST/ASTLambda.h"
-#include "clang/Sema/ScopeInfo.h"
+
 namespace clang {
+namespace sema {
+class FunctionScopeInfo;
+}
 class Sema;
 
 /// \brief Examines the FunctionScopeInfo stack to determine the nearest
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -30,7 +30,6 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeOrdering.h"
 #include "clang/Basic/ExpressionTraits.h"
-#include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Module.h"
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Basic/PragmaKinds.h"
@@ -45,7 +44,6 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Ownership.h"
 #include "clang/Sema/Scope.h"
-#include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/TypoCorrection.h"
 #include "clang/Sema/Weak.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -201,6 +199,7 @@
 namespace sema {
   class AccessedEntity;
   class BlockScopeInfo;
+  class Capture;
   class CapturedRegionScopeInfo;
   class CapturingScopeInfo;
   class CompoundScopeInfo;
@@ -1322,23 +1321,7 @@
 return FunctionScopes.back();
   }
 
-  sema::FunctionScopeInfo *getEnclosingFunction() const {
-if (FunctionScopes.empty())
-  return nullptr;
-
-for (int e = FunctionScopes.size()-1; e >= 0; --e) {
-  if (isa(FunctionScopes[e]))
-continue;
-  return FunctionScopes[e];
-}
-return nullptr;
-  }
-
-  template 
-  void recordUseOfEvaluatedWeak(const ExprT *E, bool IsRead=true) {
-if (!isUnevaluatedContext())
-  getCurFunction()->recordUseOfWeak(E, IsRead);
-  }
+  sema::FunctionScopeInfo *getEnclosingFunction() const;
 
   void PushCompoundScope(bool IsStmtExpr);
   void PopCompoundScope();
@@ -5553,10 +5536,10 @@
  Scope *CurScope);
 
   /// \brief Does copying/destroying the captured variable have side effects?
-  bool CaptureHasSideEffects(const sema::LambdaScopeInfo::Capture );
+  bool CaptureHasSideEffects(const sema::Capture );
 
   /// \brief Diagnose if an explicit lambda capture is unused.
-  void DiagnoseUnusedLambdaCapture(const sema::LambdaScopeInfo::Capture );
+  void DiagnoseUnusedLambdaCapture(const sema::Capture );
 
   /// \brief Complete a lambda-expression having processed and attached the
   /// lambda body.
Index: cfe/trunk/include/clang/Sema/ScopeInfo.h
===
--- cfe/trunk/include/clang/Sema/ScopeInfo.h
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h
@@ -469,144 +469,144 @@
   void Clear();
 };
 
-class CapturingScopeInfo : public FunctionScopeInfo {
-protected:
-  CapturingScopeInfo(const CapturingScopeInfo&) = default;
+class Capture {
+  // There are three categories of capture: capturing 'this', capturing
+  // local variables, and C++1y initialized captures (which can have an
+  // arbitrary initializer, and don't really capture in the traditional
+  // sense at all).
+  //
+  // There are three ways to capture a local variable:
+  //  - capture by copy in the C++11 sense,
+  //  - capture by reference in the C++11 sense, and
+  //  - __block capture.
+  // Lambdas explicitly specify capture by copy or capture by reference.
+  // For blocks, __block capture applies to variables with that annotation,
+  // variables of reference type are captured by reference, and other
+  // variables are captured by copy.
+  enum CaptureKind {
+Cap_ByCopy, Cap_ByRef, Cap_Block, Cap_VLA
+  };
+  enum {
+IsNestedCapture = 0x1,
+IsThisCaptured = 0x2
+  };
+
+  /// The variable being captured (if we are not capturing 'this') and whether
+  /// this is a nested capture, and whether we are capturing 'this'
+  llvm::PointerIntPair VarAndNestedAndThis;
+
+  /// Expression to initialize a field 

[PATCH] D44221: Avoid including ScopeInfo.h from Sema.h

2018-03-07 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 137487.
rnk added a comment.

- remove Sema::recordEvaluatedWeakUse to fix Linux build


https://reviews.llvm.org/D44221

Files:
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaLambda.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaPseudoObject.cpp
  clang/lib/Sema/SemaStmt.cpp

Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -4040,32 +4040,29 @@
   return RD;
 }
 
-static void buildCapturedStmtCaptureList(
-SmallVectorImpl ,
-SmallVectorImpl ,
-ArrayRef Candidates) {
-
-  typedef ArrayRef::const_iterator CaptureIter;
-  for (CaptureIter Cap = Candidates.begin(); Cap != Candidates.end(); ++Cap) {
-
-if (Cap->isThisCapture()) {
-  Captures.push_back(CapturedStmt::Capture(Cap->getLocation(),
+static void
+buildCapturedStmtCaptureList(SmallVectorImpl ,
+ SmallVectorImpl ,
+ ArrayRef Candidates) {
+  for (const sema::Capture  : Candidates) {
+if (Cap.isThisCapture()) {
+  Captures.push_back(CapturedStmt::Capture(Cap.getLocation(),
CapturedStmt::VCK_This));
-  CaptureInits.push_back(Cap->getInitExpr());
+  CaptureInits.push_back(Cap.getInitExpr());
   continue;
-} else if (Cap->isVLATypeCapture()) {
+} else if (Cap.isVLATypeCapture()) {
   Captures.push_back(
-  CapturedStmt::Capture(Cap->getLocation(), CapturedStmt::VCK_VLAType));
+  CapturedStmt::Capture(Cap.getLocation(), CapturedStmt::VCK_VLAType));
   CaptureInits.push_back(nullptr);
   continue;
 }
 
-Captures.push_back(CapturedStmt::Capture(Cap->getLocation(),
- Cap->isReferenceCapture()
+Captures.push_back(CapturedStmt::Capture(Cap.getLocation(),
+ Cap.isReferenceCapture()
  ? CapturedStmt::VCK_ByRef
  : CapturedStmt::VCK_ByCopy,
- Cap->getVariable()));
-CaptureInits.push_back(Cap->getInitExpr());
+ Cap.getVariable()));
+CaptureInits.push_back(Cap.getInitExpr());
   }
 }
 
Index: clang/lib/Sema/SemaPseudoObject.cpp
===
--- clang/lib/Sema/SemaPseudoObject.cpp
+++ clang/lib/Sema/SemaPseudoObject.cpp
@@ -965,11 +965,11 @@
 }
 
 ExprResult ObjCPropertyOpBuilder::complete(Expr *SyntacticForm) {
-  if (isWeakProperty() &&
+  if (isWeakProperty() && !S.isUnevaluatedContext() &&
   !S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
  SyntacticForm->getLocStart()))
-S.recordUseOfEvaluatedWeak(SyntacticRefExpr,
-   SyntacticRefExpr->isMessagingGetter());
+S.getCurFunction()->recordUseOfWeak(SyntacticRefExpr,
+SyntacticRefExpr->isMessagingGetter());
 
   return PseudoOpBuilder::complete(SyntacticForm);
 }
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1388,8 +1388,9 @@
   Class->addDecl(Conversion);
 }
 
-static ExprResult performLambdaVarCaptureInitialization(
-Sema , const LambdaScopeInfo::Capture , FieldDecl *Field) {
+static ExprResult performLambdaVarCaptureInitialization(Sema ,
+const Capture ,
+FieldDecl *Field) {
   assert(Capture.isVariableCapture() && "not a variable capture");
 
   auto *Var = Capture.getVariable();
@@ -1443,7 +1444,7 @@
   llvm_unreachable("Unknown implicit capture style");
 }
 
-bool Sema::CaptureHasSideEffects(const LambdaScopeInfo::Capture ) {
+bool Sema::CaptureHasSideEffects(const Capture ) {
   if (!From.isVLATypeCapture()) {
 Expr *Init = From.getInitExpr();
 if (Init && Init->HasSideEffects(Context))
@@ -1468,7 +1469,7 @@
   return false;
 }
 
-void Sema::DiagnoseUnusedLambdaCapture(const LambdaScopeInfo::Capture ) {
+void Sema::DiagnoseUnusedLambdaCapture(const Capture ) {
   if (CaptureHasSideEffects(From))
 return;
 
@@ -1523,7 +1524,7 @@
 // Translate captures.
 auto CurField = Class->field_begin();
 for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I, ++CurField) {
-  const LambdaScopeInfo::Capture  = LSI->Captures[I];
+  const Capture  = LSI->Captures[I];
   assert(!From.isBlockCapture() && "Cannot 

[PATCH] D44221: Avoid including ScopeInfo.h from Sema.h

2018-03-07 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D44221



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44221: Avoid including ScopeInfo.h from Sema.h

2018-03-07 Thread Reid Kleckner via Phabricator via cfe-commits
rnk created this revision.
rnk added a reviewer: rjmccall.

This provides no measurable build speedup, but it reinstates an
optimization from r112038 that was lost in r179618.  It requires moving
CapturedScopeInfo::Capture out to clang::sema, which might be too
general since we have plenty of other Capture records in BlockDecl and
other AST nodes.


https://reviews.llvm.org/D44221

Files:
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaLambda.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaStmt.cpp

Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -4040,32 +4040,29 @@
   return RD;
 }
 
-static void buildCapturedStmtCaptureList(
-SmallVectorImpl ,
-SmallVectorImpl ,
-ArrayRef Candidates) {
-
-  typedef ArrayRef::const_iterator CaptureIter;
-  for (CaptureIter Cap = Candidates.begin(); Cap != Candidates.end(); ++Cap) {
-
-if (Cap->isThisCapture()) {
-  Captures.push_back(CapturedStmt::Capture(Cap->getLocation(),
+static void
+buildCapturedStmtCaptureList(SmallVectorImpl ,
+ SmallVectorImpl ,
+ ArrayRef Candidates) {
+  for (const sema::Capture  : Candidates) {
+if (Cap.isThisCapture()) {
+  Captures.push_back(CapturedStmt::Capture(Cap.getLocation(),
CapturedStmt::VCK_This));
-  CaptureInits.push_back(Cap->getInitExpr());
+  CaptureInits.push_back(Cap.getInitExpr());
   continue;
-} else if (Cap->isVLATypeCapture()) {
+} else if (Cap.isVLATypeCapture()) {
   Captures.push_back(
-  CapturedStmt::Capture(Cap->getLocation(), CapturedStmt::VCK_VLAType));
+  CapturedStmt::Capture(Cap.getLocation(), CapturedStmt::VCK_VLAType));
   CaptureInits.push_back(nullptr);
   continue;
 }
 
-Captures.push_back(CapturedStmt::Capture(Cap->getLocation(),
- Cap->isReferenceCapture()
+Captures.push_back(CapturedStmt::Capture(Cap.getLocation(),
+ Cap.isReferenceCapture()
  ? CapturedStmt::VCK_ByRef
  : CapturedStmt::VCK_ByCopy,
- Cap->getVariable()));
-CaptureInits.push_back(Cap->getInitExpr());
+ Cap.getVariable()));
+CaptureInits.push_back(Cap.getInitExpr());
   }
 }
 
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1388,8 +1388,9 @@
   Class->addDecl(Conversion);
 }
 
-static ExprResult performLambdaVarCaptureInitialization(
-Sema , const LambdaScopeInfo::Capture , FieldDecl *Field) {
+static ExprResult performLambdaVarCaptureInitialization(Sema ,
+const Capture ,
+FieldDecl *Field) {
   assert(Capture.isVariableCapture() && "not a variable capture");
 
   auto *Var = Capture.getVariable();
@@ -1443,7 +1444,7 @@
   llvm_unreachable("Unknown implicit capture style");
 }
 
-bool Sema::CaptureHasSideEffects(const LambdaScopeInfo::Capture ) {
+bool Sema::CaptureHasSideEffects(const Capture ) {
   if (!From.isVLATypeCapture()) {
 Expr *Init = From.getInitExpr();
 if (Init && Init->HasSideEffects(Context))
@@ -1468,7 +1469,7 @@
   return false;
 }
 
-void Sema::DiagnoseUnusedLambdaCapture(const LambdaScopeInfo::Capture ) {
+void Sema::DiagnoseUnusedLambdaCapture(const Capture ) {
   if (CaptureHasSideEffects(From))
 return;
 
@@ -1523,7 +1524,7 @@
 // Translate captures.
 auto CurField = Class->field_begin();
 for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I, ++CurField) {
-  const LambdaScopeInfo::Capture  = LSI->Captures[I];
+  const Capture  = LSI->Captures[I];
   assert(!From.isBlockCapture() && "Cannot capture __block variables");
   bool IsImplicit = I >= LSI->NumExplicitCaptures;
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -13045,7 +13045,7 @@
   // Set the captured variables on the block.
   // FIXME: Share capture structure between BlockDecl and CapturingScopeInfo!
   SmallVector Captures;
-  for (CapturingScopeInfo::Capture  : BSI->Captures) {
+  for (Capture  : BSI->Captures) {
 if (Cap.isThisCapture())
   continue;
 BlockDecl::Capture NewCap(Cap.getVariable(),