[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D76262#1930297 , @thakis wrote:

> Could you add a clang-side test for the check-mlir fix? Having to run mlir 
> tests to verify clang changes seems suboptimal, so we should try to improve 
> coverage of clang's tests.


test added by b58f6bb1207521cdf6a856004525d7bffa5f2153 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76262/new/

https://reviews.llvm.org/D76262



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


[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D76262#1930297 , @thakis wrote:

> Could you add a clang-side test for the check-mlir fix? Having to run mlir 
> tests to verify clang changes seems suboptimal, so we should try to improve 
> coverage of clang's tests.


sure. will do.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76262/new/

https://reviews.llvm.org/D76262



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


[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-18 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Could you add a clang-side test for the check-mlir fix? Having to run mlir 
tests to verify clang changes seems suboptimal, so we should try to improve 
coverage of clang's tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76262/new/

https://reviews.llvm.org/D76262



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


[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D76262#1929918 , @jpienaar wrote:

> This does not appear to be NFC:
>
>   git checkout 704cd4d5d0754904361823588f203369c309deca ; ninja check-mlir 
> passes
>   git checkout 08ab8c9af4dd27cb306b449edc9a9c50ed11194a ; ninja check-mlir 
> fails with:
>   
>
>   0.  Program arguments: Compiles/build_clang/bin/clang++ 
> -DBUILD_EXAMPLES -DGTEST_HAS_RTTI=0 -DMLIR_CUDA_CONVERSIONS_ENABLED=0 
> -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
> -D__STDC_LIMIT_MACROS -Itools/mlir/lib/Transforms 
> -Illvm-project/mlir/lib/Transforms -Iinclude -Illvm-project/llvm/include 
> -Illvm-project/mlir/include -Itools/mlir/include -fPIC -fvisibility-inl
>   ines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall 
> -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
> -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough 
> -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
> -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color 
> -ffunction-sections -fdata-sections -O3 -fno-exceptions -fno-rtti -UNDEBUG 
> -std=c++14 -MD -MT 
> tools/mlir/lib/Transforms/CMakeFiles/MLIRTransforms.dir/AffineDataCopyGeneration.cpp.o
>  -MF 
> tools/mlir/lib/Transforms/CMakeFiles/MLIRTransforms.dir/AffineDataCopyGeneration.cpp.o.d
>  -o 
> tools/mlir/lib/Transforms/CMakeFiles/MLIRTransforms.dir/AffineDataCopyGeneration.cpp.o
>  -c llvm-project/mlir/lib/Transforms/AffineDataCopyGeneration.cpp
>   1.   parser at end of file
>   2.  Per-file LLVM IR generation
>   3.  
> /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unique_ptr.h:848:5:
>  Generating code for declaration 'std::make_unique'
>   
> build_clang/bin/clang++(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x1a)[0x55796bf8436a]
>   
> build_clang/bin/clang++(_ZN4llvm3sys17RunSignalHandlersEv+0x34)[0x55796bf82204]
>   
> build_clang/bin/clang++(_ZN4llvm3sys15CleanupOnSignalEm+0xf8)[0x55796bf82708]
>   build_clang/bin/clang++(+0x1a58a08)[0x55796bf07a08]
>   /lib/x86_64-linux-gnu/libpthread.so.0(+0x13520)[0x7f1b727f7520]
>   /lib/x86_64-linux-gnu/libc.so.6(abort+0x121)[0x7f1b722bd535]
>   /lib/x86_64-linux-gnu/libc.so.6(+0x2540f)[0x7f1b722bd40f]
>   /lib/x86_64-linux-gnu/libc.so.6(+0x32b92)[0x7f1b722cab92]
>   
> build_clang/bin/clang++(_ZN5clang7CodeGen15CodeGenFunction17EmitDeclRefLValueEPKNS_11DeclRefExprE+0x358)[0x55796c4cb138]
>   
> build_clang/bin/clang++(_ZN5clang7CodeGen15CodeGenFunction10EmitLValueEPKNS_4ExprE+0x2f9)[0x55796c4ca6d9]
>   
> build_clang/bin/clang++(_ZN5clang7CodeGen15CodeGenFunction14EmitCastLValueEPKNS_8CastExprE+0x103)[0x55796c4d4033]


Fixed by 62201763c54166a3ee5552975cc3fc06db2d5c6f 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76262/new/

https://reviews.llvm.org/D76262



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


RE: [PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-18 Thread Liu, Yaxun (Sam) via cfe-commits
[AMD Official Use Only - Internal Distribution Only]

I am taking a look. Thanks.

Sam

-Original Message-
From: Jacques Pienaar via Phabricator  
Sent: Wednesday, March 18, 2020 6:14 PM
To: Liu, Yaxun (Sam) ; rjmcc...@gmail.com
Cc: jpien...@google.com; cfe-commits@lists.llvm.org; mlek...@skidmore.edu; 
blitzrak...@gmail.com; shen...@google.com
Subject: [PATCH] D76262: [NFC] Add UsedDeclVisitor

[CAUTION: External Email]

jpienaar added a comment.

This does not appear to be NFC:
 git checkout 704cd4d5d0754904361823588f203369c309deca 
<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Freviews.llvm.org%2FrG704cd4d5d0754904361823588f203369c309decadata=02%7C01%7Cyaxun.liu%40amd.com%7Cc0896d5c9d714310dc4808d7cb89a135%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637201664290055700sdata=8BcaFKoqT0gGlOi67UkgPCca5LIZSPHCoP%2FJCOkoG9U%3Dreserved=0>
 ; ninja check-mlir passes  git checkout 
08ab8c9af4dd27cb306b449edc9a9c50ed11194a 
<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Freviews.llvm.org%2FrG08ab8c9af4dd27cb306b449edc9a9c50ed11194adata=02%7C01%7Cyaxun.liu%40amd.com%7Cc0896d5c9d714310dc4808d7cb89a135%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637201664290055700sdata=3VNtvfMjHhMoNtkzdXeV8%2FXJmR%2Bsqq5L7299ulSpVjQ%3Dreserved=0>
 ; ninja check-mlir fails with:

  0.  Program arguments: Compiles/build_clang/bin/clang++ -DBUILD_EXAMPLES 
-DGTEST_HAS_RTTI=0 -DMLIR_CUDA_CONVERSIONS_ENABLED=0 -D_DEBUG -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-Itools/mlir/lib/Transforms -Illvm-project/mlir/lib/Transforms -Iinclude 
-Illvm-project/llvm/include -Illvm-project/mlir/include -Itools/mlir/include 
-fPIC -fvisibility-inl
  ines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall 
-Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color 
-ffunction-sections -fdata-sections -O3 -fno-exceptions -fno-rtti -UNDEBUG 
-std=c++14 -MD -MT 
tools/mlir/lib/Transforms/CMakeFiles/MLIRTransforms.dir/AffineDataCopyGeneration.cpp.o
 -MF 
tools/mlir/lib/Transforms/CMakeFiles/MLIRTransforms.dir/AffineDataCopyGeneration.cpp.o.d
 -o 
tools/mlir/lib/Transforms/CMakeFiles/MLIRTransforms.dir/AffineDataCopyGeneration.cpp.o
 -c llvm-project/mlir/lib/Transforms/AffineDataCopyGeneration.cpp
  1.   parser at end of file
  2.  Per-file LLVM IR generation
  3.  
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unique_ptr.h:848:5:
 Generating code for declaration 'std::make_unique'
  
build_clang/bin/clang++(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x1a)[0x55796bf8436a]
  
build_clang/bin/clang++(_ZN4llvm3sys17RunSignalHandlersEv+0x34)[0x55796bf82204]
  build_clang/bin/clang++(_ZN4llvm3sys15CleanupOnSignalEm+0xf8)[0x55796bf82708]
  build_clang/bin/clang++(+0x1a58a08)[0x55796bf07a08]
  /lib/x86_64-linux-gnu/libpthread.so.0(+0x13520)[0x7f1b727f7520]
  /lib/x86_64-linux-gnu/libc.so.6(abort+0x121)[0x7f1b722bd535]
  /lib/x86_64-linux-gnu/libc.so.6(+0x2540f)[0x7f1b722bd40f]
  /lib/x86_64-linux-gnu/libc.so.6(+0x32b92)[0x7f1b722cab92]
  
build_clang/bin/clang++(_ZN5clang7CodeGen15CodeGenFunction17EmitDeclRefLValueEPKNS_11DeclRefExprE+0x358)[0x55796c4cb138]
  
build_clang/bin/clang++(_ZN5clang7CodeGen15CodeGenFunction10EmitLValueEPKNS_4ExprE+0x2f9)[0x55796c4ca6d9]
  
build_clang/bin/clang++(_ZN5clang7CodeGen15CodeGenFunction14EmitCastLValueEPKNS_8CastExprE+0x103)[0x55796c4d4033]


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Freviews.llvm.org%2FD76262%2Fnew%2Fdata=02%7C01%7Cyaxun.liu%40amd.com%7Cc0896d5c9d714310dc4808d7cb89a135%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637201664290055700sdata=sioR1S3m471EXAI17oUWgqmOeX26gk81APYiWOINl4M%3Dreserved=0

https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Freviews.llvm.org%2FD76262data=02%7C01%7Cyaxun.liu%40amd.com%7Cc0896d5c9d714310dc4808d7cb89a135%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637201664290055700sdata=bPmzDOZM%2FHIO9hyIP0YIV5NLhpjF3luLTC%2Bw6BQYLd8%3Dreserved=0


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


[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-18 Thread Jacques Pienaar via Phabricator via cfe-commits
jpienaar added a comment.

This does not appear to be NFC: 
 git checkout 704cd4d5d0754904361823588f203369c309deca 
 ; ninja 
check-mlir passes
 git checkout 08ab8c9af4dd27cb306b449edc9a9c50ed11194a 
 ; ninja 
check-mlir fails with:

  0.  Program arguments: Compiles/build_clang/bin/clang++ -DBUILD_EXAMPLES 
-DGTEST_HAS_RTTI=0 -DMLIR_CUDA_CONVERSIONS_ENABLED=0 -D_DEBUG -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-Itools/mlir/lib/Transforms -Illvm-project/mlir/lib/Transforms -Iinclude 
-Illvm-project/llvm/include -Illvm-project/mlir/include -Itools/mlir/include 
-fPIC -fvisibility-inl
  ines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall 
-Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color 
-ffunction-sections -fdata-sections -O3 -fno-exceptions -fno-rtti -UNDEBUG 
-std=c++14 -MD -MT 
tools/mlir/lib/Transforms/CMakeFiles/MLIRTransforms.dir/AffineDataCopyGeneration.cpp.o
 -MF 
tools/mlir/lib/Transforms/CMakeFiles/MLIRTransforms.dir/AffineDataCopyGeneration.cpp.o.d
 -o 
tools/mlir/lib/Transforms/CMakeFiles/MLIRTransforms.dir/AffineDataCopyGeneration.cpp.o
 -c llvm-project/mlir/lib/Transforms/AffineDataCopyGeneration.cpp
  1.   parser at end of file
  2.  Per-file LLVM IR generation
  3.  
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unique_ptr.h:848:5:
 Generating code for declaration 'std::make_unique'
  
build_clang/bin/clang++(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x1a)[0x55796bf8436a]
  
build_clang/bin/clang++(_ZN4llvm3sys17RunSignalHandlersEv+0x34)[0x55796bf82204]
  build_clang/bin/clang++(_ZN4llvm3sys15CleanupOnSignalEm+0xf8)[0x55796bf82708]
  build_clang/bin/clang++(+0x1a58a08)[0x55796bf07a08]
  /lib/x86_64-linux-gnu/libpthread.so.0(+0x13520)[0x7f1b727f7520]
  /lib/x86_64-linux-gnu/libc.so.6(abort+0x121)[0x7f1b722bd535]
  /lib/x86_64-linux-gnu/libc.so.6(+0x2540f)[0x7f1b722bd40f]
  /lib/x86_64-linux-gnu/libc.so.6(+0x32b92)[0x7f1b722cab92]
  
build_clang/bin/clang++(_ZN5clang7CodeGen15CodeGenFunction17EmitDeclRefLValueEPKNS_11DeclRefExprE+0x358)[0x55796c4cb138]
  
build_clang/bin/clang++(_ZN5clang7CodeGen15CodeGenFunction10EmitLValueEPKNS_4ExprE+0x2f9)[0x55796c4ca6d9]
  
build_clang/bin/clang++(_ZN5clang7CodeGen15CodeGenFunction14EmitCastLValueEPKNS_8CastExprE+0x103)[0x55796c4d4033]


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76262/new/

https://reviews.llvm.org/D76262



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


[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-17 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG08ab8c9af4dd: [NFC] Add UsedDeclVisitor (authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76262/new/

https://reviews.llvm.org/D76262

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/UsedDeclVisitor.h

Index: clang/lib/Sema/UsedDeclVisitor.h
===
--- /dev/null
+++ clang/lib/Sema/UsedDeclVisitor.h
@@ -0,0 +1,90 @@
+//===- UsedDeclVisitor.h - ODR-used declarations visitor *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//===--===//
+//
+//  This file defines UsedDeclVisitor, a CRTP class which visits all the
+//  declarations that are ODR-used by an expression or statement.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
+#define LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
+
+#include "clang/AST/EvaluatedExprVisitor.h"
+#include "clang/Sema/SemaInternal.h"
+
+namespace clang {
+template 
+class UsedDeclVisitor : public EvaluatedExprVisitor {
+protected:
+  Sema 
+
+public:
+  typedef EvaluatedExprVisitor Inherited;
+
+  UsedDeclVisitor(Sema ) : Inherited(S.Context), S(S) {}
+
+  Derived () { return *static_cast(this); }
+
+  void VisitDeclRefExpr(DeclRefExpr *E) {
+auto *D = E->getDecl();
+if (isa(D) || isa(D)) {
+  asImpl().visitUsedDecl(E->getLocation(), D);
+}
+  }
+
+  void VisitMemberExpr(MemberExpr *E) {
+auto *D = E->getMemberDecl();
+if (isa(D) || isa(D)) {
+  asImpl().visitUsedDecl(E->getMemberLoc(), D);
+}
+asImpl().Visit(E->getBase());
+  }
+
+  void VisitCapturedStmt(CapturedStmt *Node) {
+asImpl().visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
+Inherited::VisitCapturedStmt(Node);
+  }
+
+  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+asImpl().visitUsedDecl(
+E->getBeginLoc(),
+const_cast(E->getTemporary()->getDestructor()));
+asImpl().Visit(E->getSubExpr());
+  }
+
+  void VisitCXXNewExpr(CXXNewExpr *E) {
+if (E->getOperatorNew())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
+if (E->getOperatorDelete())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
+Inherited::VisitCXXNewExpr(E);
+  }
+
+  void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+if (E->getOperatorDelete())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
+QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType());
+if (const RecordType *DestroyedRec = Destroyed->getAs()) {
+  CXXRecordDecl *Record = cast(DestroyedRec->getDecl());
+  asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
+}
+
+Inherited::VisitCXXDeleteExpr(E);
+  }
+
+  void VisitCXXConstructExpr(CXXConstructExpr *E) {
+asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
+Inherited::VisitCXXConstructExpr(E);
+  }
+
+  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
+asImpl().Visit(E->getExpr());
+  }
+};
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "TreeTransform.h"
+#include "UsedDeclVisitor.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
@@ -17400,71 +17401,33 @@
 }
 
 namespace {
-  /// Helper class that marks all of the declarations referenced by
-  /// potentially-evaluated subexpressions as "referenced".
-  class EvaluatedExprMarker : public EvaluatedExprVisitor {
-Sema 
-bool SkipLocalVariables;
-
-  public:
-typedef EvaluatedExprVisitor Inherited;
-
-EvaluatedExprMarker(Sema , bool SkipLocalVariables)
-  : Inherited(S.Context), S(S), SkipLocalVariables(SkipLocalVariables) { }
-
-void VisitDeclRefExpr(DeclRefExpr *E) {
-  // If we were asked not to visit local variables, don't.
-  if (SkipLocalVariables) {
-if (VarDecl *VD = dyn_cast(E->getDecl()))
-  if (VD->hasLocalStorage())
-return;
-  }
-
-  S.MarkDeclRefReferenced(E);
-}
-
-void VisitMemberExpr(MemberExpr *E) {
-  S.MarkMemberReferenced(E);
-  Inherited::VisitMemberExpr(E);
-}
-
-void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
-  S.MarkFunctionReferenced(
-  E->getBeginLoc(),
-  

[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-16 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.

Thanks, LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76262/new/

https://reviews.llvm.org/D76262



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


[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/Sema/UsedDeclVisitor.h:43
+  asImpl().visitUsedDecl(E->getMemberLoc(), D);
+}
+  }

rjmccall wrote:
> You need to recurse on the base expression here.  (And that's a good test 
> case for your own patch!)
fixed


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76262/new/

https://reviews.llvm.org/D76262



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


[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 250688.
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

visit base expr of member expr.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76262/new/

https://reviews.llvm.org/D76262

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/UsedDeclVisitor.h

Index: clang/lib/Sema/UsedDeclVisitor.h
===
--- /dev/null
+++ clang/lib/Sema/UsedDeclVisitor.h
@@ -0,0 +1,90 @@
+//===- UsedDeclVisitor.h - ODR-used declarations visitor *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//===--===//
+//
+//  This file defines UsedDeclVisitor, a CRTP class which visits all the
+//  declarations that are ODR-used by an expression or statement.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
+#define LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
+
+#include "clang/AST/EvaluatedExprVisitor.h"
+#include "clang/Sema/SemaInternal.h"
+
+namespace clang {
+template 
+class UsedDeclVisitor : public EvaluatedExprVisitor {
+protected:
+  Sema 
+
+public:
+  typedef EvaluatedExprVisitor Inherited;
+
+  UsedDeclVisitor(Sema ) : Inherited(S.Context), S(S) {}
+
+  Derived () { return *static_cast(this); }
+
+  void VisitDeclRefExpr(DeclRefExpr *E) {
+auto *D = E->getDecl();
+if (isa(D) || isa(D)) {
+  asImpl().visitUsedDecl(E->getLocation(), D);
+}
+  }
+
+  void VisitMemberExpr(MemberExpr *E) {
+auto *D = E->getMemberDecl();
+if (isa(D) || isa(D)) {
+  asImpl().visitUsedDecl(E->getMemberLoc(), D);
+}
+asImpl().Visit(E->getBase());
+  }
+
+  void VisitCapturedStmt(CapturedStmt *Node) {
+asImpl().visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
+Inherited::VisitCapturedStmt(Node);
+  }
+
+  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+asImpl().visitUsedDecl(
+E->getBeginLoc(),
+const_cast(E->getTemporary()->getDestructor()));
+asImpl().Visit(E->getSubExpr());
+  }
+
+  void VisitCXXNewExpr(CXXNewExpr *E) {
+if (E->getOperatorNew())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
+if (E->getOperatorDelete())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
+Inherited::VisitCXXNewExpr(E);
+  }
+
+  void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+if (E->getOperatorDelete())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
+QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType());
+if (const RecordType *DestroyedRec = Destroyed->getAs()) {
+  CXXRecordDecl *Record = cast(DestroyedRec->getDecl());
+  asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
+}
+
+Inherited::VisitCXXDeleteExpr(E);
+  }
+
+  void VisitCXXConstructExpr(CXXConstructExpr *E) {
+asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
+Inherited::VisitCXXConstructExpr(E);
+  }
+
+  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
+asImpl().Visit(E->getExpr());
+  }
+};
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "TreeTransform.h"
+#include "UsedDeclVisitor.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
@@ -17373,71 +17374,33 @@
 }
 
 namespace {
-  /// Helper class that marks all of the declarations referenced by
-  /// potentially-evaluated subexpressions as "referenced".
-  class EvaluatedExprMarker : public EvaluatedExprVisitor {
-Sema 
-bool SkipLocalVariables;
-
-  public:
-typedef EvaluatedExprVisitor Inherited;
-
-EvaluatedExprMarker(Sema , bool SkipLocalVariables)
-  : Inherited(S.Context), S(S), SkipLocalVariables(SkipLocalVariables) { }
-
-void VisitDeclRefExpr(DeclRefExpr *E) {
-  // If we were asked not to visit local variables, don't.
-  if (SkipLocalVariables) {
-if (VarDecl *VD = dyn_cast(E->getDecl()))
-  if (VD->hasLocalStorage())
-return;
-  }
-
-  S.MarkDeclRefReferenced(E);
-}
-
-void VisitMemberExpr(MemberExpr *E) {
-  S.MarkMemberReferenced(E);
-  Inherited::VisitMemberExpr(E);
-}
-
-void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
-  S.MarkFunctionReferenced(
-  E->getBeginLoc(),
-  const_cast(E->getTemporary()->getDestructor()));
-  Visit(E->getSubExpr());
-

[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thanks, looks good except for one oversight.




Comment at: clang/lib/Sema/UsedDeclVisitor.h:43
+  asImpl().visitUsedDecl(E->getMemberLoc(), D);
+}
+  }

You need to recurse on the base expression here.  (And that's a good test case 
for your own patch!)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76262/new/

https://reviews.llvm.org/D76262



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


[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: rjmccall.

This patch is extracted from https://reviews.llvm.org/D70172


https://reviews.llvm.org/D76262

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/UsedDeclVisitor.h

Index: clang/lib/Sema/UsedDeclVisitor.h
===
--- /dev/null
+++ clang/lib/Sema/UsedDeclVisitor.h
@@ -0,0 +1,89 @@
+//===- UsedDeclVisitor.h - ODR-used declarations visitor *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//===--===//
+//
+//  This file defines UsedDeclVisitor, a CRTP class which visits all the
+//  declarations that are ODR-used by an expression or statement.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
+#define LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
+
+#include "clang/AST/EvaluatedExprVisitor.h"
+#include "clang/Sema/SemaInternal.h"
+
+namespace clang {
+template 
+class UsedDeclVisitor : public EvaluatedExprVisitor {
+protected:
+  Sema 
+
+public:
+  typedef EvaluatedExprVisitor Inherited;
+
+  UsedDeclVisitor(Sema ) : Inherited(S.Context), S(S) {}
+
+  Derived () { return *static_cast(this); }
+
+  void VisitDeclRefExpr(DeclRefExpr *E) {
+auto *D = E->getDecl();
+if (isa(D) || isa(D)) {
+  asImpl().visitUsedDecl(E->getLocation(), D);
+}
+  }
+
+  void VisitMemberExpr(MemberExpr *E) {
+auto *D = E->getMemberDecl();
+if (isa(D) || isa(D)) {
+  asImpl().visitUsedDecl(E->getMemberLoc(), D);
+}
+  }
+
+  void VisitCapturedStmt(CapturedStmt *Node) {
+asImpl().visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
+Inherited::VisitCapturedStmt(Node);
+  }
+
+  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+asImpl().visitUsedDecl(
+E->getBeginLoc(),
+const_cast(E->getTemporary()->getDestructor()));
+asImpl().Visit(E->getSubExpr());
+  }
+
+  void VisitCXXNewExpr(CXXNewExpr *E) {
+if (E->getOperatorNew())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
+if (E->getOperatorDelete())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
+Inherited::VisitCXXNewExpr(E);
+  }
+
+  void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+if (E->getOperatorDelete())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
+QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType());
+if (const RecordType *DestroyedRec = Destroyed->getAs()) {
+  CXXRecordDecl *Record = cast(DestroyedRec->getDecl());
+  asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
+}
+
+Inherited::VisitCXXDeleteExpr(E);
+  }
+
+  void VisitCXXConstructExpr(CXXConstructExpr *E) {
+asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
+Inherited::VisitCXXConstructExpr(E);
+  }
+
+  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
+asImpl().Visit(E->getExpr());
+  }
+};
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "TreeTransform.h"
+#include "UsedDeclVisitor.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
@@ -17373,71 +17374,33 @@
 }
 
 namespace {
-  /// Helper class that marks all of the declarations referenced by
-  /// potentially-evaluated subexpressions as "referenced".
-  class EvaluatedExprMarker : public EvaluatedExprVisitor {
-Sema 
-bool SkipLocalVariables;
-
-  public:
-typedef EvaluatedExprVisitor Inherited;
-
-EvaluatedExprMarker(Sema , bool SkipLocalVariables)
-  : Inherited(S.Context), S(S), SkipLocalVariables(SkipLocalVariables) { }
-
-void VisitDeclRefExpr(DeclRefExpr *E) {
-  // If we were asked not to visit local variables, don't.
-  if (SkipLocalVariables) {
-if (VarDecl *VD = dyn_cast(E->getDecl()))
-  if (VD->hasLocalStorage())
-return;
-  }
-
-  S.MarkDeclRefReferenced(E);
-}
-
-void VisitMemberExpr(MemberExpr *E) {
-  S.MarkMemberReferenced(E);
-  Inherited::VisitMemberExpr(E);
-}
-
-void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
-  S.MarkFunctionReferenced(
-  E->getBeginLoc(),
-  const_cast(E->getTemporary()->getDestructor()));
-  Visit(E->getSubExpr());
-}
+/// Helper class that marks all of the declarations referenced by
+/// potentially-evaluated subexpressions as