[PATCH] D95877: [analyzer] Fix static_cast on pointer-to-member handling

2021-02-05 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

In D95877#2542578 , @RedDocMD wrote:

> @vsavchenko, after some experimentation, I found out that handling 
> reinterpret_cast will be a real pain. Consider the following:
>
>   struct Base {
>   int field;
>   };
>   
>   struct Derived : public Base {};
>   
>   struct DoubleDerived : public Derived {};
>   
>   struct Some {};
>   
>   void f() {
>   int DoubleDerived::* ddf = &Base::field;
>   int Base::* bf = reinterpret_cast(reinterpret_cast Derived::*>(reinterpret_cast(ddf)));
>   int Some::* sf = reinterpret_cast(ddf);
>   Base base;
>   base.*bf;
>   }
>
> The definition of `bf` can be handled I guess by manually discovering when to 
> insert a sub-class or when to remove. It will require a bit of code but I 
> guess is doable.
> As for the next one, also it has to be manually worked out whether it makes 
> sense to process this statement further and add a node to the Exploded Graph. 
> For the example I gave I don't think it makes a lot of sense. Multiple 
> inheritance will make the task a lot worse as far as I can tell.
> Should I try to achieve this in another commit? What are your thoughts on 
> this?

Yes, another commit is fine.  However, I'd say that it is still good to add 
test cases with TODOs with this commit.




Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:27
 #include 
+#include 
 #include 

We don't need this anymore :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95877

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


[PATCH] D96000: Don't emit coverage mapping for excluded functions

2021-02-05 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 321670.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96000

Files:
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/CodeGen/profile-filter.c


Index: clang/test/CodeGen/profile-filter.c
===
--- clang/test/CodeGen/profile-filter.c
+++ clang/test/CodeGen/profile-filter.c
@@ -1,22 +1,31 @@
-// RUN: %clang_cc1 -fprofile-instrument=clang -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm %s -o - | FileCheck %s
 
 // RUN: echo "fun:test1" > %t-func.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-func.list 
-emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-func.list -emit-llvm %s -o - | 
FileCheck %s --check-prefix=FUNC
 
 // RUN: echo "src:%s" | sed -e 's/\\//g' > %t-file.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-file.list 
-emit-llvm %s -o - | FileCheck %s --check-prefix=FILE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-file.list -emit-llvm %s -o - | 
FileCheck %s --check-prefix=FILE
 
 // RUN: echo -e "[clang]\nfun:test1\n[llvm]\nfun:test2" > %t-section.list
 // RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t-section.list 
-emit-llvm %s -o - | FileCheck %s --check-prefix=SECTION
 
 // RUN: echo -e "fun:test*\n!fun:test1" > %t-exclude.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-exclude.list 
-emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-exclude.list -emit-llvm %s -o - | 
FileCheck %s --check-prefix=EXCLUDE
 
 // RUN: echo "!fun:test1" > %t-exclude-only.list
-// RUN: %clang_cc1 -fprofile-instrument=clang 
-fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s 
--check-prefix=EXCLUDE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | 
FileCheck %s --check-prefix=EXCLUDE
 
 unsigned i;
 
+// CHECK: test1
+// CHECK: test2
+// FUNC: test1
+// FUNC-NOT: test2
+// FILE: test1
+// FILE: test2
+// EXCLUDE-NOT: test1
+// EXCLUDE: test2
+
 // CHECK-NOT: noprofile
 // CHECK: @test1
 // FUNC-NOT: noprofile
Index: clang/lib/CodeGen/CodeGenPGO.cpp
===
--- clang/lib/CodeGen/CodeGenPGO.cpp
+++ clang/lib/CodeGen/CodeGenPGO.cpp
@@ -811,10 +811,10 @@
   if (isa(D) && GD.getDtorType() != Dtor_Base)
 return;
 
+  CGM.ClearUnusedCoverageMapping(D);
   if (Fn->hasFnAttribute(llvm::Attribute::NoProfile))
 return;
 
-  CGM.ClearUnusedCoverageMapping(D);
   setFuncName(Fn);
 
   mapRegionCounters(D);


Index: clang/test/CodeGen/profile-filter.c
===
--- clang/test/CodeGen/profile-filter.c
+++ clang/test/CodeGen/profile-filter.c
@@ -1,22 +1,31 @@
-// RUN: %clang_cc1 -fprofile-instrument=clang -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm %s -o - | FileCheck %s
 
 // RUN: echo "fun:test1" > %t-func.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-func.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fprofile-list=%t-func.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
 
 // RUN: echo "src:%s" | sed -e 's/\\//g' > %t-file.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-file.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FILE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fprofile-list=%t-file.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FILE
 
 // RUN: echo -e "[clang]\nfun:test1\n[llvm]\nfun:test2" > %t-section.list
 // RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t-section.list -emit-llvm %s -o - | FileCheck %s --check-prefix=SECTION
 
 // RUN: echo -e "fun:test*\n!fun:test1" > %t-exclude.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-exclude.list -emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fprofile-list=%t-exclude.list -emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE
 
 // RUN: echo "!fun:test1" > %t-exclude-only.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcover

[PATCH] D96000: Don't emit coverage mapping for excluded functions

2021-02-05 Thread Petr Hosek via Phabricator via cfe-commits
phosek marked an inline comment as done.
phosek added inline comments.



Comment at: clang/test/CodeGen/profile-filter.c:27
+// EXCLUDE: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, 
i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// EXCLUDE-NOT: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ 
i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+

vsk wrote:
> This is somewhat difficult to interpret. Would you be open to specifying 
> -dump-coverage-mapping (e.g. https://godbolt.org/z/5PvvEv), in a separate cc1 
> invocation if needed, and checking that instead?
Thanks for the suggestion, this is definitely cleaner.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96000

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


[clang] a5b627a - [OpenCL] Introduce new language options for OpenCL keywords.

2021-02-05 Thread Anton Zabaznov via cfe-commits

Author: Anton Zabaznov
Date: 2021-02-05T11:18:48+03:00
New Revision: a5b627aa4fe749f8df0a27fcb1f6fe3b59a21e09

URL: 
https://github.com/llvm/llvm-project/commit/a5b627aa4fe749f8df0a27fcb1f6fe3b59a21e09
DIFF: 
https://github.com/llvm/llvm-project/commit/a5b627aa4fe749f8df0a27fcb1f6fe3b59a21e09.diff

LOG: [OpenCL] Introduce new language options for OpenCL keywords.

OpenCL keywords 'pipe' and 'generic' are unconditionally
supported for OpenCL C 2.0 or in OpenCL C++ mode. In OpenCL C 3.0
these keywords are available if corresponding optional core
feature is supported.

Reviewed By: Anastasia, svenvh

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

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index c01f0cca9c9c..1a9f8048bc17 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -215,6 +215,8 @@ LANGOPT(OpenCL, 1, 0, "OpenCL")
 LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
 LANGOPT(OpenCLCPlusPlus   , 1, 0, "C++ for OpenCL")
 LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
+LANGOPT(OpenCLGenericAddressSpace, 1, 0, "OpenCL generic keyword")
+LANGOPT(OpenCLPipe   , 1, 0, "OpenCL pipe keyword")
 LANGOPT(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
 LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index ddc16faf26dd..0a12705a9261 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2391,6 +2391,9 @@ void CompilerInvocation::setLangDefaults(LangOptions 
&Opts, InputKind IK,
 Opts.ZVector = 0;
 Opts.setDefaultFPContractMode(LangOptions::FPM_On);
 Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
+Opts.OpenCLPipe = Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
+Opts.OpenCLGenericAddressSpace =
+Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
 
 // Include default header file for OpenCL.
 if (Opts.IncludeDefaultHeader) {

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 55a0c6a082aa..3d5c984033fa 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3896,8 +3896,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
 case tok::kw_pipe:
   if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200 &&
 !getLangOpts().OpenCLCPlusPlus)) {
-// OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should
-// support the "pipe" word as identifier.
+// OpenCL 2.0 and later define this keyword. OpenCL 1.2 and earlier
+// should support the "pipe" word as identifier.
 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
 goto DoneWithDeclSpec;
   }
@@ -4017,8 +4017,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
 case tok::kw___generic:
   // generic address space is introduced only in OpenCL v2.0
   // see OpenCL C Spec v2.0 s6.5.5
-  if (Actions.getLangOpts().OpenCLVersion < 200 &&
-  !Actions.getLangOpts().OpenCLCPlusPlus) {
+  if (!Actions.getLangOpts().OpenCLGenericAddressSpace) {
 DiagID = diag::err_opencl_unknown_type_specifier;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
@@ -5070,8 +5069,7 @@ bool Parser::isDeclarationSpecifier(bool 
DisambiguatingWithExpression) {
   default: return false;
 
   case tok::kw_pipe:
-return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
-   getLangOpts().OpenCLCPlusPlus;
+return getLangOpts().OpenCLPipe;
 
   case tok::identifier:   // foo::bar
 // Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5599,8 +5597,7 @@ static bool isPtrOperatorToken(tok::TokenKind Kind, const 
LangOptions &Lang,
   if (Kind == tok::star || Kind == tok::caret)
 return true;
 
-  if (Kind == tok::kw_pipe &&
-  ((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus))
+  if (Kind == tok::kw_pipe && Lang.OpenCLPipe)
 return true;
 
   if (!Lang.CPlusPlus)

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index e24eb266dd5f..0016c1aa541c 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@ static QualType deduceOpenCLPointeeAddrSpace(Sema &S, 
QualType PointeeType) {
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType

[PATCH] D95778: [OpenCL] Introduce new language options for OpenCL keywords.

2021-02-05 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa5b627aa4fe7: [OpenCL] Introduce new language options for 
OpenCL keywords. (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95778

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
-? LangAS::opencl_generic
-: LangAS::opencl_private);
+PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
+ ? LangAS::opencl_generic
+ : LangAS::opencl_private);
   return PointeeType;
 }
 
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3896,8 +3896,8 @@
 case tok::kw_pipe:
   if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200 &&
 !getLangOpts().OpenCLCPlusPlus)) {
-// OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should
-// support the "pipe" word as identifier.
+// OpenCL 2.0 and later define this keyword. OpenCL 1.2 and earlier
+// should support the "pipe" word as identifier.
 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
 goto DoneWithDeclSpec;
   }
@@ -4017,8 +4017,7 @@
 case tok::kw___generic:
   // generic address space is introduced only in OpenCL v2.0
   // see OpenCL C Spec v2.0 s6.5.5
-  if (Actions.getLangOpts().OpenCLVersion < 200 &&
-  !Actions.getLangOpts().OpenCLCPlusPlus) {
+  if (!Actions.getLangOpts().OpenCLGenericAddressSpace) {
 DiagID = diag::err_opencl_unknown_type_specifier;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
@@ -5070,8 +5069,7 @@
   default: return false;
 
   case tok::kw_pipe:
-return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
-   getLangOpts().OpenCLCPlusPlus;
+return getLangOpts().OpenCLPipe;
 
   case tok::identifier:   // foo::bar
 // Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5599,8 +5597,7 @@
   if (Kind == tok::star || Kind == tok::caret)
 return true;
 
-  if (Kind == tok::kw_pipe &&
-  ((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus))
+  if (Kind == tok::kw_pipe && Lang.OpenCLPipe)
 return true;
 
   if (!Lang.CPlusPlus)
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2391,6 +2391,9 @@
 Opts.ZVector = 0;
 Opts.setDefaultFPContractMode(LangOptions::FPM_On);
 Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
+Opts.OpenCLPipe = Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
+Opts.OpenCLGenericAddressSpace =
+Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
 
 // Include default header file for OpenCL.
 if (Opts.IncludeDefaultHeader) {
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -215,6 +215,8 @@
 LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
 LANGOPT(OpenCLCPlusPlus   , 1, 0, "C++ for OpenCL")
 LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
+LANGOPT(OpenCLGenericAddressSpace, 1, 0, "OpenCL generic keyword")
+LANGOPT(OpenCLPipe   , 1, 0, "OpenCL pipe keyword")
 LANGOPT(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
 LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
-? LangAS::opencl_generic
-: LangAS::opencl_private);
+PointeeType, S.getLangOpts().OpenCLGenericAdd

[PATCH] D94661: [clang-format] [PR19056] Add support for access modifiers indentation

2021-02-05 Thread Jakub Budiský via Phabricator via cfe-commits
Budovi planned changes to this revision.
Budovi added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:19056
+TEST_F(FormatTest, IndentAccessModifiers) {
+  FormatStyle Style = getLLVMStyle();
+  Style.AllowShortEnumsOnASingleLine = false;

curdeius wrote:
> Please add an assertion that IndentWidth == 2 to make the test easier to 
> understand.
The written tests rely on several other "defaults" from the LLVM style. If 
somebody changes those defaults these unit tests (along with many others) will 
fail. This will also be true if an assertion is present to test this condition. 
It would be possible to reassign those values but this goes against how the 
rest of the tests are implemented.

But I agree that I could improve the readability by adding brief comments that 
point out important settings and the purpose of the included tests.


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

https://reviews.llvm.org/D94661

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


[PATCH] D95877: [analyzer] Fix static_cast on pointer-to-member handling

2021-02-05 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:210
+   "repeated elements");
+BaseSpecSeen.insert(BaseType);
   }

Containers like `map` and `set` usually return a pair for `insert`, where the 
second element tells us whether that element was inserted or was already there. 
It is usually a bad practice to use `find` in the vicinity of `insert` for this 
very reason, you double the work.

Also, a not about this whole part of the code, if it's done only for 
assertions, none of this code should be executed in the build without 
assertions.  You'll need to extract this into a function that you call from 
assert. It means that in release builds it will be unused and should be marked 
with `LLVM_MAYBE_UNUSED`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95877

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


[PATCH] D96070: [clang] [driver] Enable static linking to libc++

2021-02-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D96070#2543172 , @mstorsjo wrote:

> In particular, if libcxx is built with `LIBCXX_ENABLE_STATIC_ABI_LIBRARY` 
> enabled, the libcxxabi static library is merged into libc++.a, making static 
> linking work just fine.

I can't test this right now, but it is manually specifying pthread not needed 
in that case?

In D96070#2543334 , @MaskRay wrote:

> Persoanlly 
> (https://maskray.me/blog/2020-12-12-c++-exception-handling-abi#use-libc-and-libcabi)
>  I use:
>
> `clang++ -stdlib=libc++ -static-libstdc++ -nostdlib++ a.cc 
> -Wl,--push-state,-Bstatic -lc++ -lc++abi -Wl,--pop-state -pthread`
>
> This is still a bit inferior because there is a duplicate -lc++ passed by the 
> driver.
>
> Dynamically link against libc++.so (which depends on libc++abi.so) 
> (additionally specify -pthread if threads are used):
> `clang++ -stdlib=libc++ -nostdlib++ a.cc -lc++ -lc++abi` (clang 
> -stdlib=libc++ a.cc -lc++ -lc++abi does not pass -lm to the linker.)
> Omitting `-lc++abi` most works, but can fail if your program reference some 
> definitions in ` ` directly and you are using gold or 
> LLD.

Are you suggesting clang should do the same?

Or should clang just not do anything here and people should be aware they need 
to pass additional flags when using libc++ (on Linux)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96070

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


[PATCH] D96070: [clang] [driver] Enable static linking to libc++

2021-02-05 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D96070#2544297 , @tbaeder wrote:

> In D96070#2543172 , @mstorsjo wrote:
>
>> In particular, if libcxx is built with `LIBCXX_ENABLE_STATIC_ABI_LIBRARY` 
>> enabled, the libcxxabi static library is merged into libc++.a, making static 
>> linking work just fine.
>
> I can't test this right now, but it is manually specifying pthread not needed 
> in that case?

That would only bundle libcxxabi, not pthreads, so that'd still be required.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96070

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


[PATCH] D93594: [X86] Pass to transform amx intrinsics to scalar operation.

2021-02-05 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added a comment.

Would you rebase to see if the lit test failure is related to this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93594

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


[PATCH] D77811: [clangd] Implement semanticTokens modifiers

2021-02-05 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:476
+  if (!Kind || (Result && Kind != Result))
+continue;
+  Result = Kind;

nridge wrote:
> This is a change of behaviour from before, in the case where the 
> `ReferenceLoc` has multiple targets.
> 
> Before, we would produce at most one highlighting token for the 
> `ReferenceLoc`. In the case where different target decls had different 
> highlighting kinds, we wouldn't produce any.
> 
> Now, it looks like we produce a separate token for every target whose kind 
> matches the kind of the first target (and skip targets with a conflicting 
> kind).
> 
> Is that the intention?
> 
> It seems a bit strange: if we allow multiple tokens, why couldn't they have 
> different kinds?
Thinking more about this, the behaviour may actually be reasonable as written.

  * Tokens with different kinds would get discarded via `resolveConflict()`.
  * Multiple tokens with the same kind are potentially useful because they may 
have different modifiers, and the modifiers are then merged in 
`resolveConflict()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77811

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


[PATCH] D77811: [clangd] Implement semanticTokens modifiers

2021-02-05 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

I think this patch is in pretty good shape, the outstanding comments are either 
minor or thoughts about future changes.

I am curious what you think of the extension idea for readonly 
, though obviously it 
wouldn't be something to do in this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77811

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


[PATCH] D93594: [X86] Pass to transform amx intrinsics to scalar operation.

2021-02-05 Thread Bing Yu via Phabricator via cfe-commits
yubing updated this revision to Diff 321673.
yubing added a comment.

Rebase and fix the bug in amx_api.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93594

Files:
  llvm/include/llvm/CodeGen/Passes.h
  llvm/lib/Target/X86/CMakeLists.txt
  llvm/lib/Target/X86/X86.h
  llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll

Index: llvm/test/CodeGen/X86/O0-pipeline.ll
===
--- llvm/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -18,7 +18,9 @@
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   Expand Atomic instructions
-; CHECK-NEXT:   Lower AMX type for load/store
+; CHECK-NEXT:   Dominator Tree Construction
+; CHECK-NEXT:   Natural Loop Information
+; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Module Verifier
 ; CHECK-NEXT:   Lower Garbage Collection Instructions
 ; CHECK-NEXT:   Shadow Stack GC Lowering
Index: llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
@@ -0,0 +1,198 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -lower-amx-intrinsics %s -S | FileCheck %s
+
+define dso_local void @test_amx_load_non_O0(i16 signext %row, i16 signext %col, i8 *%ptr, i64 %stride, <256 x i32>* %vptr) {
+; CHECK-LABEL: @test_amx_load_non_O0(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[AMX:%.*]] = call x86_amx @llvm.x86.tileloadd64.internal(i16 [[ROW:%.*]], i16 [[COL:%.*]], i8* [[PTR:%.*]], i64 [[STRIDE:%.*]])
+; CHECK-NEXT:[[VEC:%.*]] = bitcast x86_amx [[AMX]] to <256 x i32>
+; CHECK-NEXT:store <256 x i32> [[VEC]], <256 x i32>* [[VPTR:%.*]], align 64
+; CHECK-NEXT:ret void
+;
+entry:
+  %amx = call x86_amx @llvm.x86.tileloadd64.internal(i16 %row, i16 %col, i8* %ptr, i64 %stride)
+  %vec = bitcast x86_amx %amx to <256 x i32>
+  store <256 x i32> %vec, <256 x i32>* %vptr, align 64
+  ret void
+}
+
+define dso_local void @test_amx_load(i16 signext %row, i16 signext %col, i8 *%ptr, i64 %stride, <256 x i32>* %vptr) #0 {
+; CHECK-LABEL: @test_amx_load(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[TMP0:%.*]] = udiv i16 [[COL:%.*]], 4
+; CHECK-NEXT:[[TMP1:%.*]] = udiv i64 [[STRIDE:%.*]], 4
+; CHECK-NEXT:br label [[TILELOAD_UNROLL_ROWS_HEADER:%.*]]
+; CHECK:   tileload.unroll.rows.header:
+; CHECK-NEXT:[[TILELOAD_UNROLL_ROWS_IV:%.*]] = phi i16 [ 0, [[ENTRY:%.*]] ], [ [[TILELOAD_UNROLL_ROWS_STEP:%.*]], [[TILELOAD_UNROLL_ROWS_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_PHI_ROW:%.*]] = phi <256 x i32> [ zeroinitializer, [[ENTRY]] ], [ [[TMP11:%.*]], [[TILELOAD_UNROLL_ROWS_LATCH]] ]
+; CHECK-NEXT:br label [[TILELOAD_UNROLL_ROWS_BODY:%.*]]
+; CHECK:   tileload.unroll.rows.body:
+; CHECK-NEXT:br label [[TILELOAD_UNROLL_COLS_HEADER:%.*]]
+; CHECK:   tileload.unroll.cols.header:
+; CHECK-NEXT:[[TILELOAD_UNROLL_COLS_IV:%.*]] = phi i16 [ 0, [[TILELOAD_UNROLL_ROWS_BODY]] ], [ [[TILELOAD_UNROLL_COLS_STEP:%.*]], [[TILELOAD_UNROLL_COLS_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_PHI:%.*]] = phi <256 x i32> [ [[VEC_PHI_ROW]], [[TILELOAD_UNROLL_ROWS_BODY]] ], [ [[TMP11]], [[TILELOAD_UNROLL_COLS_LATCH]] ]
+; CHECK-NEXT:br label [[TILELOAD_UNROLL_COLS_BODY:%.*]]
+; CHECK:   tileload.unroll.cols.body:
+; CHECK-NEXT:[[TMP2:%.*]] = zext i16 [[TILELOAD_UNROLL_ROWS_IV]] to i64
+; CHECK-NEXT:[[TMP3:%.*]] = zext i16 [[TILELOAD_UNROLL_COLS_IV]] to i64
+; CHECK-NEXT:[[TMP4:%.*]] = mul i64 [[TMP2]], [[TMP1]]
+; CHECK-NEXT:[[TMP5:%.*]] = add i64 [[TMP4]], [[TMP3]]
+; CHECK-NEXT:[[TMP6:%.*]] = bitcast i8* [[PTR:%.*]] to i32*
+; CHECK-NEXT:[[TMP7:%.*]] = getelementptr i32, i32* [[TMP6]], i64 [[TMP5]]
+; CHECK-NEXT:[[TMP8:%.*]] = load i32, i32* [[TMP7]], align 4
+; CHECK-NEXT:[[TMP9:%.*]] = mul i16 [[TILELOAD_UNROLL_ROWS_IV]], 16
+; CHECK-NEXT:[[TMP10:%.*]] = add i16 [[TMP9]], [[TILELOAD_UNROLL_COLS_IV]]
+; CHECK-NEXT:[[TMP11]] = insertelement <256 x i32> [[VEC_PHI]], i32 [[TMP8]], i16 [[TMP10]]
+; CHECK-NEXT:br label [[TILELOAD_UNROLL_COLS_LATCH]]
+; CHECK:   tileload.unroll.cols.latch:
+; CHECK-NEXT:[[TILELOAD_UNROLL_COLS_STEP]] = add i16 [[TILELOAD_UNROLL_COLS_IV]], 1
+; CHECK-NEXT:[[TILELOAD_UNROLL_COLS_COND:%.*]] = icmp ne i16 [[TILELOAD_UNROLL_COLS_STEP]], [[TMP0]]
+; CHECK-NEXT:br i1 [[TILELOAD_UNROLL_COLS_COND]], label [[TILELOAD_UNROLL_COLS_HEADER]], label [[TILELOAD_UNROLL_ROWS_LATCH]]
+; CHECK:   tileload.unroll.rows.latch:
+; CHECK-NEXT:[[TILELOAD_UNROLL_ROWS_STEP]] = add i16 [[TILELOAD_UNROLL_ROWS_IV]], 1
+; CHECK-NEXT:[[TILELOAD_UNROLL_ROWS_COND:%.*]] = icmp ne i16 [[TILELOAD

[PATCH] D89055: [analyzer] Wrong type cast occures during pointer dereferencing after type punning

2021-02-05 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@NoQ

> Ugh, sorry, no, that's `evalCast()`. Like `evalBinOp()` etc. My bad. Can we 
> also use `evalCast()`?

Finally :-) Now we can use `evalCast()` instead of `CastRetrievedVal()`. It 
would be nice if you could look at D96090 .

I made a stack of four patches to resolve bugs of this revision.


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

https://reviews.llvm.org/D89055

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


[PATCH] D92639: [analyzer] Add control flow arrows to the analyzer's HTML reports

2021-02-05 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.
Herald added a subscriber: nullptr.cpp.

In D92639#2505163 , @ASDenysPetrov 
wrote:

> @vsavchenko
>
>> F14534708: report-6ea17d.html 
>
> I checked it in IE. It doesn't draw arrows. Investigate this, please.

Oh, I checked it (using a bunch of weird websites to host html and then to see 
it in IE).  It doesn't show it and I have no idea why.  I don't have easy 
access to IE and I couldn't fix it unfortunately :-(
If you know any good way I can run it on Mac, I'd be happy to test it.




Comment at: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp:147
+bool isArrowPiece(const PathDiagnosticPiece &P) {
+  return isa(P) && P.getString().empty();
+}

ASDenysPetrov wrote:
> Are you sure that **non-arrow** piece **always** has **non-empty** string 
> representation? Can this give us a false positive result?
I haven't seen empty grey bubbles.  If there are pieces like this, it'd be a 
bug in event generation.



Comment at: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp:458
   }
   if (event.key == "S") {
 var checked = document.getElementsByName("showCounterexample")[0].checked;

ASDenysPetrov wrote:
> Seems like this shortcut works only with the capital **S** aka //shift+s//
> Should we support any **s** state?
As far as I understand, that matches the original intention because the help 
message mentions exactly "Shift+S"
{F15355624}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92639

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


[PATCH] D96110: [X86] Pass to transform tdpbf16ps intrinsics to scalar operation.

2021-02-05 Thread Bing Yu via Phabricator via cfe-commits
yubing updated this revision to Diff 321675.
yubing added a comment.

Rebase and add a testcase for dpbf16ps intrinsic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96110

Files:
  clang/include/clang/Basic/BuiltinsX86_64.def
  clang/lib/Headers/amxintrin.h
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/lib/Target/X86/X86ExpandPseudo.cpp
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86InstrAMX.td
  llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp
  llvm/lib/Target/X86/X86LowerAMXType.cpp
  llvm/lib/Target/X86/X86PreTileConfig.cpp
  llvm/lib/Target/X86/X86RegisterInfo.cpp
  llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll

Index: llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
===
--- llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
+++ llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
@@ -63,8 +63,8 @@
   ret void
 }
 
-define dso_local void @test_amx_dp(i16 signext %row, i16 signext %col, i16 signext %k, <256 x i32> %c, <256 x i32> %a, <256 x i32> %b, <256 x i32>* %vptr) #0 {
-; CHECK-LABEL: @test_amx_dp(
+define dso_local void @test_amx_dpbssd(i16 signext %row, i16 signext %col, i16 signext %k, <256 x i32> %c, <256 x i32> %a, <256 x i32> %b, <256 x i32>* %vptr) #0 {
+; CHECK-LABEL: @test_amx_dpbssd(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[A_AMX:%.*]] = bitcast <256 x i32> [[A:%.*]] to x86_amx
 ; CHECK-NEXT:[[B_AMX:%.*]] = bitcast <256 x i32> [[B:%.*]] to x86_amx
@@ -133,6 +133,81 @@
   ret void
 }
 
+define dso_local void @test_amx_dpbf16ps(i16 signext %row, i16 signext %col, i16 signext %k, <256 x i32> %c, <256 x i32> %a, <256 x i32> %b, <256 x i32>* %vptr) #0 {
+; CHECK-LABEL: @test_amx_dpbf16ps(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[A_AMX:%.*]] = bitcast <256 x i32> [[A:%.*]] to x86_amx
+; CHECK-NEXT:[[B_AMX:%.*]] = bitcast <256 x i32> [[B:%.*]] to x86_amx
+; CHECK-NEXT:[[C_AMX:%.*]] = bitcast <256 x i32> [[C:%.*]] to x86_amx
+; CHECK-NEXT:[[TMP0:%.*]] = udiv i16 [[COL:%.*]], 4
+; CHECK-NEXT:[[TMP1:%.*]] = udiv i16 [[K:%.*]], 4
+; CHECK-NEXT:br label [[TILEDPBF16PS_UNROLL_ROWS_HEADER:%.*]]
+; CHECK:   tiledpbf16ps.unroll.rows.header:
+; CHECK-NEXT:[[TILEDPBF16PS_UNROLL_ROWS_IV:%.*]] = phi i16 [ 0, [[ENTRY:%.*]] ], [ [[TILEDPBF16PS_UNROLL_ROWS_STEP:%.*]], [[TILEDPBF16PS_UNROLL_ROWS_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_PHI_ROW:%.*]] = phi <256 x i32> [ [[C]], [[ENTRY]] ], [ [[TMP23:%.*]], [[TILEDPBF16PS_UNROLL_ROWS_LATCH]] ]
+; CHECK-NEXT:br label [[TILEDPBF16PS_UNROLL_ROWS_BODY:%.*]]
+; CHECK:   tiledpbf16ps.unroll.rows.body:
+; CHECK-NEXT:br label [[TILEDPBF16PS_UNROLL_COLS_HEADER:%.*]]
+; CHECK:   tiledpbf16ps.unroll.cols.header:
+; CHECK-NEXT:[[TILEDPBF16PS_UNROLL_COLS_IV:%.*]] = phi i16 [ 0, [[TILEDPBF16PS_UNROLL_ROWS_BODY]] ], [ [[TILEDPBF16PS_UNROLL_COLS_STEP:%.*]], [[TILEDPBF16PS_UNROLL_COLS_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_PHI_COL:%.*]] = phi <256 x i32> [ [[VEC_PHI_ROW]], [[TILEDPBF16PS_UNROLL_ROWS_BODY]] ], [ [[TMP23]], [[TILEDPBF16PS_UNROLL_COLS_LATCH]] ]
+; CHECK-NEXT:br label [[TILEDPBF16PS_UNROLL_COLS_BODY:%.*]]
+; CHECK:   tiledpbf16ps.unroll.cols.body:
+; CHECK-NEXT:br label [[TILEDPBF16PS_UNROLL_INNER_HEADER:%.*]]
+; CHECK:   tiledpbf16ps.unroll.inner.header:
+; CHECK-NEXT:[[TILEDPBF16PS_UNROLL_INNER_IV:%.*]] = phi i16 [ 0, [[TILEDPBF16PS_UNROLL_COLS_BODY]] ], [ [[TILEDPBF16PS_UNROLL_INNER_STEP:%.*]], [[TILEDPBF16PS_UNROLL_INNER_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_PHI:%.*]] = phi <256 x i32> [ [[VEC_PHI_COL]], [[TILEDPBF16PS_UNROLL_COLS_BODY]] ], [ [[TMP23]], [[TILEDPBF16PS_UNROLL_INNER_LATCH]] ]
+; CHECK-NEXT:br label [[TILEDPBF16PS_UNROLL_INNER_BODY:%.*]]
+; CHECK:   tiledpbf16ps.unroll.inner.body:
+; CHECK-NEXT:[[TMP2:%.*]] = mul i16 [[TILEDPBF16PS_UNROLL_ROWS_IV]], 16
+; CHECK-NEXT:[[TMP3:%.*]] = add i16 [[TMP2]], [[TILEDPBF16PS_UNROLL_COLS_IV]]
+; CHECK-NEXT:[[TMP4:%.*]] = mul i16 [[TILEDPBF16PS_UNROLL_ROWS_IV]], 16
+; CHECK-NEXT:[[TMP5:%.*]] = add i16 [[TMP4]], [[TILEDPBF16PS_UNROLL_INNER_IV]]
+; CHECK-NEXT:[[TMP6:%.*]] = mul i16 [[TILEDPBF16PS_UNROLL_INNER_IV]], 16
+; CHECK-NEXT:[[TMP7:%.*]] = add i16 [[TMP6]], [[TILEDPBF16PS_UNROLL_COLS_IV]]
+; CHECK-NEXT:[[TMP8:%.*]] = extractelement <256 x i32> [[VEC_PHI]], i16 [[TMP3]]
+; CHECK-NEXT:[[TMP9:%.*]] = bitcast i32 [[TMP8]] to float
+; CHECK-NEXT:[[TMP10:%.*]] = extractelement <256 x i32> [[A]], i16 [[TMP5]]
+; CHECK-NEXT:[[TMP11:%.*]] = bitcast i32 [[TMP10]] to <2 x i16>
+; CHECK-NEXT:[[TMP12:%.*]] = extractelement <256 x i32> [[B]], i16 [[TMP7]]
+; CHECK-NEXT:[[TMP13:%.*]] = bitcast i32 [[TMP12]] to <2 x i16>
+; CHECK-NEXT:[[TMP14:%.*]] = zext <2 x i16> [[TMP11]] to <2 x i32>
+; CHECK-NEXT:[[TMP15:%.*]] = shl <2 x i32> [[TMP14]], 
+; CHECK-NEXT:[[TMP16:%.*]] = bitcast <2 x i32> [[TMP15]] to <2 x float>
+; CHECK-NEX

[PATCH] D92928: [analyzer] Highlight arrows for currently selected event

2021-02-05 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp:166
+  ArrowMap(unsigned Size) : Base(Size, 0) {}
+  unsigned getTotalNumberOfArrows() const { return at(0); }
+};

ASDenysPetrov wrote:
>   # Whether `size()` is not an aim?
>   # It can fail in case of empty container.
> 
> 
`size()` doesn't mean the same semantically. This structure is at least of size 
1.  Please, consider the following code on how this data structure is 
constructed and used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92928

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


[PATCH] D75903: [AArch64][CodeGen] Fixing stack alignment of HFA arguments on AArch64 PCS

2021-02-05 Thread Momchil Velikov via Phabricator via cfe-commits
chill added inline comments.



Comment at: llvm/docs/LangRef.rst:1220
+``alignstack()``
+This indicates the alignment that should be considered by the backend when
+assigning this parameter to a stack slot during calling convention

rnk wrote:
> This seems like you are introducing a new meaning to `alignstack`, which 
> according to the comments, only affects function SP alignment, not parameter 
> alignment.
> 
> I'm assuming the reason you can't use the regular `align` attribute is that 
> it is overloaded to mean two things: the alignment of the pointer when 
> applied to a pointer, and the alignment of the argument memory when that 
> pointer argument is marked `byval`. If you want to resolve this ambiguity, it 
> seems like something that should be discussed on llvm-dev with a wider 
> audience.
Sorry, I couldn't quite get it, do you suggest we should be using the `align` 
attribute instead of `alignstack`, if there  are no
(major) objections on the llvm-dev list?

It certainly makes sense to me to use `align` as it already pertains to 
individual argument alignment (even though it's for pointers only now).



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75903

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


[PATCH] D96070: [clang] [driver] Enable static linking to libc++

2021-02-05 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

I can't speak for other systems, but forcing libpthread to be linked is in 
general not desirable as it creates a non-trivial runtime cost, especially when 
 is not used. That's still a pretty common use case of C++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96070

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


[PATCH] D93594: [X86] Pass to transform amx intrinsics to scalar operation.

2021-02-05 Thread Bing Yu via Phabricator via cfe-commits
yubing added a comment.

Strange. llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll can pass in my local 
machine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93594

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


[PATCH] D95776: [OpenCL] Add macro definitions of OpenCL C 3.0 features

2021-02-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95776

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


[PATCH] D96112: [Syntax] No crash on OpaqueValueExpr.

2021-02-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kbobyrev.
hokein requested review of this revision.
Herald added a project: clang.

OpaqueValueExpr doesn't correspond to the concrete syntax, it has
invalid source location, ignore them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96112

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp


Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -503,6 +503,25 @@
 )txt"));
 }
 
+TEST_P(BuildSyntaxTreeTest, ConditionalOperator) {
+  // FIXME: conditional expression is not modeled yet.
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+void test() {
+  [[1?:2]];
+}
+)cpp",
+  {R"txt(
+UnknownExpression Expression
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-'?'
+|-':'
+`-IntegerLiteralExpression
+  `-'2' LiteralToken
+)txt"}));
+}
+
 TEST_P(BuildSyntaxTreeTest, UnqualifiedId_Identifier) {
   EXPECT_TRUE(treeDumpEqualOnAnnotations(
   R"cpp(
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -855,6 +855,11 @@
 return RecursiveASTVisitor::TraverseStmt(S);
   }
 
+  bool TraverseOpaqueValueExpr(OpaqueValueExpr *VE) {
+// OpaqueValue doesn't correspond to concrete syntax, ignore it.
+return true;
+  }
+
   // Some expressions are not yet handled by syntax trees.
   bool WalkUpFromExpr(Expr *E) {
 assert(!isImplicitExpr(E) && "should be handled by TraverseStmt");


Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -503,6 +503,25 @@
 )txt"));
 }
 
+TEST_P(BuildSyntaxTreeTest, ConditionalOperator) {
+  // FIXME: conditional expression is not modeled yet.
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+void test() {
+  [[1?:2]];
+}
+)cpp",
+  {R"txt(
+UnknownExpression Expression
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-'?'
+|-':'
+`-IntegerLiteralExpression
+  `-'2' LiteralToken
+)txt"}));
+}
+
 TEST_P(BuildSyntaxTreeTest, UnqualifiedId_Identifier) {
   EXPECT_TRUE(treeDumpEqualOnAnnotations(
   R"cpp(
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -855,6 +855,11 @@
 return RecursiveASTVisitor::TraverseStmt(S);
   }
 
+  bool TraverseOpaqueValueExpr(OpaqueValueExpr *VE) {
+// OpaqueValue doesn't correspond to concrete syntax, ignore it.
+return true;
+  }
+
   // Some expressions are not yet handled by syntax trees.
   bool WalkUpFromExpr(Expr *E) {
 assert(!isImplicitExpr(E) && "should be handled by TraverseStmt");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2021-02-05 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

I started reviewing this alongside the specification in 
https://github.com/riscv/riscv-zfinx/blob/master/Zfinx_spec.adoc. At the time 
of writing, it seems to define "zfinx" but not "zfhinx" and "zfdinx" as seem to 
be used in this patch. I think intent is that rv32ifd_zfinx is the equivalent 
of "zfdinx" in this patch. Is there a reason to go for different naming, or a 
different version of the spec I should be looking at?


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

https://reviews.llvm.org/D93298

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


[PATCH] D95860: [clang][Frontend] Fix a crash in DiagnosticRenderer.

2021-02-05 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 321685.
balazske added a comment.

Added explanation to source code.
Added more test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95860

Files:
  clang/lib/Frontend/DiagnosticRenderer.cpp
  
clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-begin-1.inc
  
clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-begin-2.inc
  
clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-begin-macro-1.inc
  
clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-begin-macro-2.inc
  
clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-end-macro.inc
  clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-end.inc
  clang/test/Analysis/copypaste/clone-begin-end-different-file.cpp
  clang/test/Frontend/crash-diagnostic-renderer.cpp

Index: clang/test/Frontend/crash-diagnostic-renderer.cpp
===
--- /dev/null
+++ clang/test/Frontend/crash-diagnostic-renderer.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify %s
+
+// This case reproduces a problem that is shown here:
+// https://bugs.llvm.org/show_bug.cgi?id=46540
+// No assertion should happen during printing of diagnostic messages.
+
+// expected-error@13{{'b' does not refer to a type name in pseudo-destructor expression; expected the name of type 'volatile long'}}
+// expected-error@13{{expected ')'}}
+// expected-note@13{{to match this '('}}
+// expected-error@13{{reference to pseudo-destructor must be called; did you mean to call it with no arguments?}}
+// expected-error@13{{cannot initialize a variable of type 'volatile long' with an rvalue of type 'void'}}
+// expected-error@13{{expected ';' after top level declarator}}
+volatile long a ( a .~b
Index: clang/test/Analysis/copypaste/clone-begin-end-different-file.cpp
===
--- /dev/null
+++ clang/test/Analysis/copypaste/clone-begin-end-different-file.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:MinimumCloneComplexity=5 -verify %s
+
+// This test should verify that there is no crash if the detected clone range
+// starts in a file and ends in a different file.
+
+void f_end(int i) {
+  if (i == 10) // expected-warning{{Duplicate code detected}}
+#include "Inputs/clone-begin-end-different-file-end.inc"
+  if (i == 10) // expected-note{{Similar code here}}
+#include "Inputs/clone-begin-end-different-file-end.inc"
+}
+
+void f_begin(int i) {
+#include "Inputs/clone-begin-end-different-file-begin-1.inc"
+if (true) {}
+#include "Inputs/clone-begin-end-different-file-begin-2.inc"
+if (true) {}
+}
+
+#define X while (true) {}
+
+void f1m(int i) {
+  if (i == 10) // expected-warning{{Duplicate code detected}}
+#include "Inputs/clone-begin-end-different-file-end-macro.inc"
+  if (i == 10) // expected-note{{Similar code here}}
+#include "Inputs/clone-begin-end-different-file-end-macro.inc"
+}
+
+#undef X
+#define X if (i == 10)
+
+void f2m(int i) {
+#include "Inputs/clone-begin-end-different-file-begin-macro-1.inc"
+while (true) { i = 1; }
+#include "Inputs/clone-begin-end-different-file-begin-macro-2.inc"
+while (true) { i = 1; }
+}
Index: clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-end.inc
===
--- /dev/null
+++ clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-end.inc
@@ -0,0 +1 @@
+while (true) {}
Index: clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-end-macro.inc
===
--- /dev/null
+++ clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-end-macro.inc
@@ -0,0 +1 @@
+X
Index: clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-begin-macro-2.inc
===
--- /dev/null
+++ clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-begin-macro-2.inc
@@ -0,0 +1 @@
+X // expected-note{{Similar code here}}
Index: clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-begin-macro-1.inc
===
--- /dev/null
+++ clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-begin-macro-1.inc
@@ -0,0 +1 @@
+X // expected-warning{{Duplicate code detected}}
Index: clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-begin-2.inc
===
--- /dev/null
+++ clang/test/Analysis/copypaste/Inputs/clone-begin-end-different-file-begin-2.inc
@@ -0,0 +1 @@
+while (i == 10) // expected-note{{Similar code here}}
Index: clang/test/Analysis/copypaste/Inputs/clone-begin-end-dif

[clang-tools-extra] 91698fe - [clangd] Take into account what is in the index (symbols, references, etc.) at indexes merge

2021-02-05 Thread Aleksandr Platonov via cfe-commits

Author: Aleksandr Platonov
Date: 2021-02-05T13:35:07+03:00
New Revision: 91698fe45f6068c5a6f8284e5e8e19a8d89dfea8

URL: 
https://github.com/llvm/llvm-project/commit/91698fe45f6068c5a6f8284e5e8e19a8d89dfea8
DIFF: 
https://github.com/llvm/llvm-project/commit/91698fe45f6068c5a6f8284e5e8e19a8d89dfea8.diff

LOG: [clangd] Take into account what is in the index (symbols, references, 
etc.) at indexes merge

Current indexes merge logic skip data from the static index if the file is in 
the dynamic index, but sometimes the dynamic index does not contain references 
(e.g. preamble (dynamic) index vs background (static) index).
This problem is masked with the fact, that the preamble index file list 
consists of file URI's and other indexes file lists consist of file paths.
This patch introduces the index contents (symbols, references, etc.), which 
makes indexes merge more flexible and makes it able to use URI's for the index 
file list.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/index/Background.cpp
clang-tools-extra/clangd/index/FileIndex.cpp
clang-tools-extra/clangd/index/FileIndex.h
clang-tools-extra/clangd/index/Index.cpp
clang-tools-extra/clangd/index/Index.h
clang-tools-extra/clangd/index/MemIndex.cpp
clang-tools-extra/clangd/index/MemIndex.h
clang-tools-extra/clangd/index/Merge.cpp
clang-tools-extra/clangd/index/Merge.h
clang-tools-extra/clangd/index/ProjectAware.cpp
clang-tools-extra/clangd/index/dex/Dex.cpp
clang-tools-extra/clangd/index/dex/Dex.h
clang-tools-extra/clangd/index/remote/Client.cpp
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang-tools-extra/clangd/unittests/DexTests.cpp
clang-tools-extra/clangd/unittests/FileIndexTests.cpp
clang-tools-extra/clangd/unittests/IndexTests.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/Background.cpp 
b/clang-tools-extra/clangd/index/Background.cpp
index d122d8aa2776..f97f13d8dabe 100644
--- a/clang-tools-extra/clangd/index/Background.cpp
+++ b/clang-tools-extra/clangd/index/Background.cpp
@@ -97,6 +97,7 @@ BackgroundIndex::BackgroundIndex(
 BackgroundIndexStorage::Factory IndexStorageFactory, Options Opts)
 : SwapIndex(std::make_unique()), TFS(TFS), CDB(CDB),
   ContextProvider(std::move(Opts.ContextProvider)),
+  IndexedSymbols(IndexContents::All),
   Rebuilder(this, &IndexedSymbols, Opts.ThreadPoolSize),
   IndexStorageFactory(std::move(IndexStorageFactory)),
   Queue(std::move(Opts.OnProgress)),

diff  --git a/clang-tools-extra/clangd/index/FileIndex.cpp 
b/clang-tools-extra/clangd/index/FileIndex.cpp
index 9f05968020b0..f497f845b42d 100644
--- a/clang-tools-extra/clangd/index/FileIndex.cpp
+++ b/clang-tools-extra/clangd/index/FileIndex.cpp
@@ -236,6 +236,9 @@ SlabTuple indexHeaderSymbols(llvm::StringRef Version, 
ASTContext &AST,
   /*CollectMainFileRefs=*/false);
 }
 
+FileSymbols::FileSymbols(IndexContents IdxContents)
+: IdxContents(IdxContents) {}
+
 void FileSymbols::update(llvm::StringRef Key,
  std::unique_ptr Symbols,
  std::unique_ptr Refs,
@@ -376,14 +379,14 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling 
DuplicateHandle,
   case IndexType::Light:
 return std::make_unique(
 llvm::make_pointee_range(AllSymbols), std::move(AllRefs),
-std::move(AllRelations), std::move(Files),
+std::move(AllRelations), std::move(Files), IdxContents,
 std::make_tuple(std::move(SymbolSlabs), std::move(RefSlabs),
 std::move(RefsStorage), std::move(SymsStorage)),
 StorageSize);
   case IndexType::Heavy:
 return std::make_unique(
 llvm::make_pointee_range(AllSymbols), std::move(AllRefs),
-std::move(AllRelations), std::move(Files),
+std::move(AllRelations), std::move(Files), IdxContents,
 std::make_tuple(std::move(SymbolSlabs), std::move(RefSlabs),
 std::move(RefsStorage), std::move(SymsStorage)),
 StorageSize);
@@ -412,7 +415,9 @@ void FileSymbols::profile(MemoryTree &MT) const {
 
 FileIndex::FileIndex()
 : MergedIndex(&MainFileIndex, &PreambleIndex),
+  PreambleSymbols(IndexContents::Symbols | IndexContents::Relations),
   PreambleIndex(std::make_unique()),
+  MainFileSymbols(IndexContents::All),
   MainFileIndex(std::make_unique()) {}
 
 void FileIndex::updatePreamble(PathRef Path, llvm::StringRef Version,

diff  --git a/clang-tools-extra/clangd/index/FileIndex.h 
b/clang-tools-extra/clangd/index/FileIndex.h
index 29958ca30be2..d46a87464568 100644
--- a/clang-tools-extra/clangd/index/FileIndex.h
+++ b/clang-tools-extra/cla

[PATCH] D94952: [clangd] Take into account what is in the index (symbols, references, etc.) at indexes merge

2021-02-05 Thread Aleksandr Platonov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91698fe45f60: [clangd] Take into account what is in the 
index (symbols, references, etc.) at… (authored by ArcsinX).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94952

Files:
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/index/Index.cpp
  clang-tools-extra/clangd/index/Index.h
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/MemIndex.h
  clang-tools-extra/clangd/index/Merge.cpp
  clang-tools-extra/clangd/index/Merge.h
  clang-tools-extra/clangd/index/ProjectAware.cpp
  clang-tools-extra/clangd/index/dex/Dex.cpp
  clang-tools-extra/clangd/index/dex/Dex.h
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/DexTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/IndexTests.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1290,7 +1290,7 @@
   std::string BarPath = testPath("bar.cc");
   // Build the index, the index has "Foo" references from foo.cc and "Bar"
   // references from bar.cc.
-  FileSymbols FSymbols;
+  FileSymbols FSymbols(IndexContents::All);
   FSymbols.update(FooPath, nullptr, buildRefSlab(FooCode, "Foo", FooPath),
   nullptr, false);
   FSymbols.update(BarPath, nullptr, buildRefSlab(BarCode, "Bar", BarPath),
@@ -1367,9 +1367,9 @@
llvm::function_ref
Callback) const override {}
 
-llvm::unique_function
+llvm::unique_function
 indexedFiles() const override {
-  return [](llvm::StringRef) { return false; };
+  return [](llvm::StringRef) { return IndexContents::None; };
 }
 
 size_t estimateMemoryUsage() const override { return 0; }
@@ -1421,9 +1421,9 @@
llvm::function_ref)
 const override {}
 
-llvm::unique_function
+llvm::unique_function
 indexedFiles() const override {
-  return [](llvm::StringRef) { return false; };
+  return [](llvm::StringRef) { return IndexContents::None; };
 }
 
 size_t estimateMemoryUsage() const override { return 0; }
Index: clang-tools-extra/clangd/unittests/IndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexTests.cpp
@@ -231,11 +231,11 @@
   auto Data = std::make_pair(std::move(Symbols), std::move(Refs));
   llvm::StringSet<> Files = {testPath("foo.cc"), testPath("bar.cc")};
   MemIndex I(std::move(Data.first), std::move(Data.second), RelationSlab(),
- std::move(Files), std::move(Data), Size);
+ std::move(Files), IndexContents::All, std::move(Data), Size);
   auto ContainsFile = I.indexedFiles();
-  EXPECT_TRUE(ContainsFile("unittest:///foo.cc"));
-  EXPECT_TRUE(ContainsFile("unittest:///bar.cc"));
-  EXPECT_FALSE(ContainsFile("unittest:///foobar.cc"));
+  EXPECT_EQ(ContainsFile("unittest:///foo.cc"), IndexContents::All);
+  EXPECT_EQ(ContainsFile("unittest:///bar.cc"), IndexContents::All);
+  EXPECT_EQ(ContainsFile("unittest:///foobar.cc"), IndexContents::None);
 }
 
 TEST(MemIndexTest, TemplateSpecialization) {
@@ -508,23 +508,24 @@
   auto DynData = std::make_pair(std::move(DynSymbols), std::move(DynRefs));
   llvm::StringSet<> DynFiles = {testPath("foo.cc")};
   MemIndex DynIndex(std::move(DynData.first), std::move(DynData.second),
-RelationSlab(), std::move(DynFiles), std::move(DynData),
-DynSize);
+RelationSlab(), std::move(DynFiles), IndexContents::Symbols,
+std::move(DynData), DynSize);
   SymbolSlab StaticSymbols;
   RefSlab StaticRefs;
   auto StaticData =
   std::make_pair(std::move(StaticSymbols), std::move(StaticRefs));
-  llvm::StringSet<> StaticFiles = {testPath("bar.cc")};
-  MemIndex StaticIndex(std::move(StaticData.first),
-   std::move(StaticData.second), RelationSlab(),
-   std::move(StaticFiles), std::move(StaticData),
-   StaticSymbols.bytes() + StaticRefs.bytes());
+  llvm::StringSet<> StaticFiles = {testPath("foo.cc"), testPath("bar.cc")};
+  MemIndex StaticIndex(
+  std::move(StaticData.first), std::move(StaticData.second), RelationSlab(),
+  std::move(StaticFiles), IndexCont

[PATCH] D96007: [AArch64] Enable stack clash protection for AArch64 linux in clang

2021-02-05 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard updated this revision to Diff 321689.

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

https://reviews.llvm.org/D96007

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/stack-clash-protection.c
  clang/test/Driver/stack-clash-protection.c


Index: clang/test/Driver/stack-clash-protection.c
===
--- clang/test/Driver/stack-clash-protection.c
+++ clang/test/Driver/stack-clash-protection.c
@@ -21,12 +21,20 @@
 // SCP-ll-win64-NOT: attributes {{.*}} "probe-stack"="inline-asm"
 // SCP-ll-win64: argument unused during compilation: '-fstack-clash-protection'
 
+// RUN: %clang -target aarch64-unknown-linux -fstack-clash-protection -S 
-emit-llvm -o- %s | FileCheck %s -check-prefix=SCP-aarch64
+// SCP-aarch64: attributes {{.*}} "probe-stack"="inline-asm"
+// SCP-aarch64-SAME: "stack-probe-size"="65536"
+
 int foo(int c) {
   int r;
   __asm__("sub %0, %%rsp"
   :
   : "rm"(c)
+#ifdef __aarch64__
+  : "sp");
+#else
   : "rsp");
+#endif
   __asm__("mov %%rsp, %0"
   : "=rm"(r)::);
   return r;
Index: clang/test/CodeGen/stack-clash-protection.c
===
--- clang/test/CodeGen/stack-clash-protection.c
+++ clang/test/CodeGen/stack-clash-protection.c
@@ -3,6 +3,9 @@
 // RUN: %clang_cc1 -triple s390x-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
 // RUN: %clang_cc1 -triple powerpc64le-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
 // RUN: %clang_cc1 -triple powerpc64-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64_be-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection -mstack-probe-size=65536 | FileCheck %s 
--check-prefix=CHECK --check-prefix=LARGE-GUARD
 
 // CHECK: define{{.*}} void @large_stack() #[[A:.*]] {
 void large_stack() {
@@ -23,3 +26,5 @@
 }
 
 // CHECK: attributes #[[A]] = {{.*}} "probe-stack"="inline-asm"
+// LARGE-GUARD-SAME: "stack-probe-size"="65536"
+// CHECK-NOT: "stack-probe-size"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3091,12 +3091,20 @@
 return;
 
   if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
-  !EffectiveTriple.isPPC64())
+  !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64())
 return;
 
   if (Args.hasFlag(options::OPT_fstack_clash_protection,
-   options::OPT_fno_stack_clash_protection, false))
+   options::OPT_fno_stack_clash_protection, false)) {
 CmdArgs.push_back("-fstack-clash-protection");
+
+if (Args.hasArg(options::OPT_mstack_probe_size)) {
+  StringRef Size = Args.getLastArgValue(options::OPT_mstack_probe_size);
+  CmdArgs.push_back(Args.MakeArgString("-mstack-probe-size=" + Size));
+} else if (EffectiveTriple.isAArch64()) {
+  CmdArgs.push_back("-mstack-probe-size=65536");
+}
+  }
 }
 
 static void RenderTrivialAutoVarInitOptions(const Driver &D,
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1664,8 +1664,12 @@
   if (CodeGenOpts.UnwindTables)
 B.addAttribute(llvm::Attribute::UWTable);
 
-  if (CodeGenOpts.StackClashProtector)
+  if (CodeGenOpts.StackClashProtector) {
 B.addAttribute("probe-stack", "inline-asm");
+if (CodeGenOpts.StackProbeSize != 4096)
+  B.addAttribute("stack-probe-size",
+ llvm::utostr(CodeGenOpts.StackProbeSize));
+  }
 
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);


Index: clang/test/Driver/stack-clash-protection.c
===
--- clang/test/Driver/stack-clash-protection.c
+++ clang/test/Driver/stack-clash-protection.c
@@ -21,12 +21,20 @@
 // SCP-ll-win64-NOT: attributes {{.*}} "probe-stack"="inline-asm"
 // SCP-ll-win64: argument unused during compilation: '-fstack-clash-protection'
 
+// RUN: %clang -target aarch64-unknown-linux -fstack-clash-protection -S -emit-llvm -o- %s | FileCheck %s -check-prefix=SCP-aarch64
+// SCP-aarch64: attributes {{.*}} "probe-stack"="inline-asm"
+// SCP-aarch64-SAME: "stack-probe-size"="65536"
+
 int foo(int c) {
   int r;
   __asm__("sub %0, %%rsp"
   :
   : "rm"(c)
+#ifdef __aarch64__
+  : "sp");
+#else
   : "rsp");
+#endif
   __asm__("mov %%rsp, %0"
   : "=rm"(r

[PATCH] D96043: Treat opencl_unroll_hint subject errors as semantic rather than parse errors

2021-02-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks for fixing this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96043

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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2021-02-05 Thread luxufan via Phabricator via cfe-commits
StephenFan added a comment.

In D93298#253 , @asb wrote:

> I started reviewing this alongside the specification in 
> https://github.com/riscv/riscv-zfinx/blob/master/Zfinx_spec.adoc. At the time 
> of writing, it seems to define "zfinx" but not "zfhinx" and "zfdinx" as seem 
> to be used in this patch. I think intent is that rv32ifd_zfinx is the 
> equivalent of "zfdinx" in this patch. Is there a reason to go for different 
> naming, or a different version of the spec I should be looking at?

According to  @jrtc27 's review that is 
"As for Zfinx itself, well, the idea is fine, but I really detest the way it's 
being done as an extension to F/D/Zfh. Running F code on an FZfh core _does not 
work_ so it is not an _extension_. Instead it should really be a set of 
separate extensions to I/E that conflict with F/D/Zfh, i.e. Zfinx, Zdinx and 
Zfhinx, but apparently asking code that complies with a ratified standard to 
change itself in order to not break when a new extension is introduced is a-ok 
in the RISC-V world.". 
We split the Zfinx into 3 separate extensions which is Zfinx, Zdinx, and Zfhinx.


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

https://reviews.llvm.org/D93298

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


[PATCH] D96050: [OpenCL] Do not enforce ASTContext for OCL2Qual

2021-02-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

Cool! Makes sense, LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96050

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


[PATCH] D95799: [analyzer] Symbolicate float values with integral casting

2021-02-05 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

  void clang_analyzer_dumpi(int);
  void clang_analyzer_dumpf(float);
  void clang_analyzer_dumpip(int*);
  void clang_analyzer_dumpfp(float*);
  
  void SymbolCast_of_float_type_aux(int *p) {
*p += 1;
clang_analyzer_dumpi(*p); // (Previously): Unknown  ->  (Now): (float) 
(conj_$1{int, LC2, S790, #1})
clang_analyzer_dumpf(*p); // (Previously): Unknown  ->  (Now): (float) 
(conj_$1{int, LC2, S790, #1})
clang_analyzer_dumpip(p); // &Element{x1,1 S64b,float}
clang_analyzer_dumpfp(p); // &Element{x1,1 S64b,float}
  }
  
  void SymbolCast_of_float_type() {
extern float x1;
extern double x2;
extern long double x3;
  
void (*f)() = SymbolCast_of_float_type_aux;
  
clang_analyzer_dumpi(*(&x1 + 1));  // Unknown
clang_analyzer_dumpf(*(&x1 + 1));  // Unknown
clang_analyzer_dumpip(&x1 + 1);// &Element{x1,1 S64b,int}
clang_analyzer_dumpfp(&x1 + 1);// &Element{x1,1 S64b,float}
  
f(&x1 + 1);
// f(&x2 + 1);
// f(&x3 + 1);
  }

Only lines 8-9 have changed. But IMO, in a bad way.
We should have just `(conj_$1{float, LC2, S790, #1})` there, because the object 
you read from that location is of type `float`.
Reading an `int` and casting it to `float` means a different thing.

Before the patch - saying `Unknown`, it was not accurate, but at least correct.


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

https://reviews.llvm.org/D95799

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


[PATCH] D96090: [analyzer] Replace StoreManager::CastRetrievedVal with SValBuilder::evalCast

2021-02-05 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Please, consider removing D95799  from the 
parent revisions if that is not a hard requirement of this patch.
It would be awesome to land your patches on dealing with cast problems in the 
close future.
Dealing with floating-point values is a plus, but maybe not a necessity.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96090

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


[PATCH] D89055: [analyzer] Wrong type cast occures during pointer dereferencing after type punning

2021-02-05 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 321693.
ASDenysPetrov added a comment.

Updated. Rolled the fix over the evalCast refactoring.


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

https://reviews.llvm.org/D89055

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/casts.c
  clang/test/Analysis/string.c


Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -363,6 +363,20 @@
 strcpy(x, y); // no-warning
 }
 
+// PR37503
+void *get_void_ptr();
+char ***type_punned_ptr;
+void strcpy_no_assertion(char c) {
+  *(unsigned char **)type_punned_ptr = (unsigned char *)(get_void_ptr());
+  strcpy(**type_punned_ptr, &c); // no-crash
+}
+
+// PR49007
+char f(char ***c, int *i) {
+  *(void **)c = i + 1;
+  return (**c)[0]; // no-crash
+}
+
 //===--===
 // stpcpy()
 //===--===
Index: clang/test/Analysis/casts.c
===
--- clang/test/Analysis/casts.c
+++ clang/test/Analysis/casts.c
@@ -245,3 +245,8 @@
   return a * a;
 }
 
+void no_crash_reinterpret_char_as_uchar(char ***a, int *b) {
+  *(unsigned char **)a = (unsigned char *)b;
+  if (**a == 0) // no-crash
+;
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -731,8 +731,8 @@
   // pointers as well.
   // FIXME: We really need a single good function to perform casts for us
   // correctly every time we need it.
+  const MemRegion *R = V.getRegion();
   if (CastTy->isPointerType() && !CastTy->isVoidPointerType()) {
-const MemRegion *R = V.getRegion();
 if (const auto *SR = dyn_cast(R)) {
   QualType SRTy = SR->getSymbol()->getType();
   if (!hasSameUnqualifiedPointeeType(SRTy, CastTy)) {
@@ -741,6 +741,13 @@
   }
 }
   }
+  // Next fixes pointer dereference using type different from its initial
+  // one. See PR37503 and PR49007 for details.
+  if (const auto *ER = dyn_cast(R)) {
+R = StateMgr.getStoreManager().castRegion(ER, CastTy);
+return loc::MemRegionVal(R);
+  }
+
   return V;
 }
 


Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -363,6 +363,20 @@
 strcpy(x, y); // no-warning
 }
 
+// PR37503
+void *get_void_ptr();
+char ***type_punned_ptr;
+void strcpy_no_assertion(char c) {
+  *(unsigned char **)type_punned_ptr = (unsigned char *)(get_void_ptr());
+  strcpy(**type_punned_ptr, &c); // no-crash
+}
+
+// PR49007
+char f(char ***c, int *i) {
+  *(void **)c = i + 1;
+  return (**c)[0]; // no-crash
+}
+
 //===--===
 // stpcpy()
 //===--===
Index: clang/test/Analysis/casts.c
===
--- clang/test/Analysis/casts.c
+++ clang/test/Analysis/casts.c
@@ -245,3 +245,8 @@
   return a * a;
 }
 
+void no_crash_reinterpret_char_as_uchar(char ***a, int *b) {
+  *(unsigned char **)a = (unsigned char *)b;
+  if (**a == 0) // no-crash
+;
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -731,8 +731,8 @@
   // pointers as well.
   // FIXME: We really need a single good function to perform casts for us
   // correctly every time we need it.
+  const MemRegion *R = V.getRegion();
   if (CastTy->isPointerType() && !CastTy->isVoidPointerType()) {
-const MemRegion *R = V.getRegion();
 if (const auto *SR = dyn_cast(R)) {
   QualType SRTy = SR->getSymbol()->getType();
   if (!hasSameUnqualifiedPointeeType(SRTy, CastTy)) {
@@ -741,6 +741,13 @@
   }
 }
   }
+  // Next fixes pointer dereference using type different from its initial
+  // one. See PR37503 and PR49007 for details.
+  if (const auto *ER = dyn_cast(R)) {
+R = StateMgr.getStoreManager().castRegion(ER, CastTy);
+return loc::MemRegionVal(R);
+  }
+
   return V;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] edc8f0b - TypeMismatchCheck.cpp - fix Wdocumentation warning. NFCI.

2021-02-05 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2021-02-05T10:57:39Z
New Revision: edc8f0b407a1ca5373f72af6a5ed658929603be9

URL: 
https://github.com/llvm/llvm-project/commit/edc8f0b407a1ca5373f72af6a5ed658929603be9
DIFF: 
https://github.com/llvm/llvm-project/commit/edc8f0b407a1ca5373f72af6a5ed658929603be9.diff

LOG: TypeMismatchCheck.cpp - fix Wdocumentation warning. NFCI.

Added: 


Modified: 
clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp 
b/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
index 2d8da68cd6a7..cc60ea365c2f 100644
--- a/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
@@ -228,7 +228,7 @@ static bool isTypedefTypeMatching(const TypedefType *const 
Typedef,
 /// Get the unqualified, dereferenced type of an argument.
 ///
 /// \param CE call expression
-/// \param idx argument index
+/// \param Idx argument index
 ///
 /// \returns type of the argument
 static const Type *argumentType(const CallExpr *const CE, const size_t Idx) {



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


[PATCH] D96113: Add test coverage for hasParent() usage

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96113

Files:
  clang/lib/AST/ParentMapContext.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2933,6 +2933,37 @@
 EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
 EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
   }
+  {
+auto M = ifStmt(hasParent(compoundStmt(hasParent(cxxForRangeStmt();
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = cxxForRangeStmt(
+has(varDecl(hasName("i"), hasParent(cxxForRangeStmt();
+EXPECT_FALSE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = cxxForRangeStmt(hasDescendant(varDecl(
+hasName("i"), hasParent(declStmt(hasParent(cxxForRangeStmt()));
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = cxxForRangeStmt(hasRangeInit(declRefExpr(
+to(varDecl(hasName("arr"))), hasParent(cxxForRangeStmt();
+EXPECT_FALSE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+
+  {
+auto M = cxxForRangeStmt(hasRangeInit(declRefExpr(
+to(varDecl(hasName("arr"))), hasParent(varDecl(hasParent(declStmt(
+ hasParent(cxxForRangeStmt();
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
 
   Code = R"cpp(
   struct Range {
@@ -3035,6 +3066,15 @@
 matchesConditionally(Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
  true, {"-std=c++20"}));
   }
+  {
+auto M = cxxForRangeStmt(hasInitStatement(declStmt(
+hasSingleDecl(varDecl(hasName("a"))), hasParent(cxxForRangeStmt();
+EXPECT_TRUE(
+matchesConditionally(Code, traverse(TK_AsIs, M), true, {"-std=c++20"}));
+EXPECT_TRUE(
+matchesConditionally(Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
+ true, {"-std=c++20"}));
+  }
 
   Code = R"cpp(
   struct Range {
@@ -3511,6 +3551,20 @@
forFunction(functionDecl(hasName("func13"))),
   langCxx20OrLater()));
 
+  EXPECT_TRUE(matches(Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   compoundStmt(hasParent(lambdaExpr(forFunction(
+   functionDecl(hasName("func13"))),
+  langCxx20OrLater()));
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   templateTypeParmDecl(hasName("TemplateType"),
+hasParent(lambdaExpr(forFunction(
+functionDecl(hasName("func14"))),
+  langCxx20OrLater()));
+
   EXPECT_TRUE(matches(
   Code,
   traverse(TK_IgnoreUnlessSpelledInSource,
@@ -3635,6 +3689,16 @@
 matchesConditionally(Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
  true, {"-std=c++20"}));
   }
+  {
+auto M = cxxRewrittenBinaryOperator(
+hasLHS(expr(hasParent(cxxRewrittenBinaryOperator(,
+hasRHS(expr(hasParent(cxxRewrittenBinaryOperator();
+EXPECT_FALSE(
+matchesConditionally(Code, traverse(TK_AsIs, M), true, {"-std=c++20"}));
+EXPECT_TRUE(
+matchesConditionally(Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
+ true, {"-std=c++20"}));
+  }
   {
 EXPECT_TRUE(matchesConditionally(
 Code,
Index: clang/lib/AST/ParentMapContext.cpp
===
--- clang/lib/AST/ParentMapContext.cpp
+++ clang/lib/AST/ParentMapContext.cpp
@@ -49,7 +49,17 @@
   return N;
 }
 
+template 
+std::tuple
+matchParents(const DynTypedNodeList &NodeList,
+ ParentMapContext::ParentMap *ParentMap);
+
+template  struct MatchParents;
+
 class ParentMapContext::ParentMap {
+
+  template  friend struct ::MatchParents;
+
   /// Contains parents of a node.
   using ParentVector = llvm::SmallVector;
 
@@ -117,11 +127,75 @@
 if (Node.getNodeKind().hasPointerIdentity()) {
   auto ParentList =
   getDynNodeFromMap(Node.getMemoizationData(), PointerParents

[PATCH] D95168: [clang-format] Add InsertBraces option

2021-02-05 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:17996
+format(ForSourceLong, Style));
+}
+

tiagoma wrote:
> tiagoma wrote:
> > njames93 wrote:
> > > MyDeveloperDay wrote:
> > > > MyDeveloperDay wrote:
> > > > > MyDeveloperDay wrote:
> > > > > > are you testing do/while? 
> > > > > whilst people discuss the ethics of modifying the code ;-) 
> > > > > 
> > > > > Can you add some comment based examples
> > > > > 
> > > > > ```
> > > > > if (condition) // my test
> > > > >   you_do_you();
> > > > > 
> > > > > if (condition)
> > > > >   you_do_you(); // my test
> > > > > ```
> > > > bonus points..
> > > > 
> > > > ```
> > > > if /*condition*/ (condition) /*condition*/
> > > > /*condition*/  you_do_you(); /*condition*/
> > > > ```
> > > Should also add test for chained conditionals just to make sure the 
> > > semantics of the code doesn't change.
> > > ```lang=c
> > > if (A)
> > >   if (B)
> > > callAB();
> > >   else
> > > callA();
> > > else if (B)
> > >   callB();
> > > else
> > >   call();```
> > do/while are not supported in it's current form. We would need to change 
> > the logic to add more state. I can have a look at it after this patch is 
> > accepted.
> This specific test will fail by itself, ie:
> 
> ```
> StringRef Test = "if /*condition*/ (condition)  /*condition*/\n"
>  "  /*condition*/ you_do_you(); /*condition*/";
> 
> verifyFormat(Test);
> ```
> 
> AFAICT it is because test::messUp causes the 2nd and 3rd comment to stay on 
> the same line. I added a variation of the test.
The problem with this statement is as soon as you commit, we'd get that defect 
raised, that is ok its just are you going to stay around long enough to finish 
it completely? ;-) if not then this puts burden on those who hang out here all 
the time.

Ideally its probably worth following through with a complete implementation 
before landing (or as best you can), there is no rush right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95168

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


[PATCH] D96114: [ASTMatchers] Fix parent-child traversal between functions and parms

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added a subscriber: kristof.beyls.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Having to match on the typeLoc in AsIs mode is undesirable, but keep it
for now for compatbility.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96114

Files:
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/lib/AST/ParentMapContext.cpp
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -3551,6 +3551,14 @@
forFunction(functionDecl(hasName("func13"))),
   langCxx20OrLater()));
 
+  EXPECT_TRUE(
+  matches(Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   parmVarDecl(hasName("d"),
+   hasParent(lambdaExpr(forFunction(
+   functionDecl(hasName("func13"))),
+  langCxx20OrLater()));
+
   EXPECT_TRUE(matches(Code,
   traverse(TK_IgnoreUnlessSpelledInSource,
compoundStmt(hasParent(lambdaExpr(forFunction(
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2068,6 +2068,41 @@
  Constructor1Arg));
 }
 
+TEST(ASTMatchersTest, has_parmVarDecl) {
+
+  auto Code = R"cpp(
+void f(int ii)
+{
+
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_AsIs,
+   functionDecl(hasName("f"),
+has(typeLoc(has(parmVarDecl(hasName("ii"))),
+  langCxx20OrLater()));
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   functionDecl(hasName("f"), has(parmVarDecl(hasName("ii"),
+  langCxx20OrLater()));
+
+  EXPECT_TRUE(
+  matches(Code,
+  traverse(TK_AsIs, parmVarDecl(hasName("ii"),
+hasParent(typeLoc(hasParent(
+functionDecl(hasName("f"))),
+  langCxx20OrLater()));
+  EXPECT_TRUE(
+  matches(Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   parmVarDecl(hasName("ii"),
+   hasParent(functionDecl(hasName("f"),
+  langCxx20OrLater()));
+}
+
 TEST(ASTMatchersTest, NamesMember_CXXDependentScopeMemberExpr) {
 
   // Member functions:
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -143,6 +143,17 @@
 return Matches;
   }
 
+  bool TraverseFunctionHelper(FunctionDecl *FD) {
+if (Finder->isTraversalIgnoringImplicitNodes()) {
+  for (auto *P : FD->parameters())
+if (!TraverseDecl(P)) {
+  return false;
+}
+}
+return RecursiveASTVisitor::TraverseFunctionHelper(
+FD);
+  }
+
   // The following are overriding methods from the base visitor class.
   // They are public only to allow CRTP to work. They are *not *part
   // of the public API of this class.
Index: clang/lib/AST/ParentMapContext.cpp
===
--- clang/lib/AST/ParentMapContext.cpp
+++ clang/lib/AST/ParentMapContext.cpp
@@ -345,7 +345,7 @@
 class ParentMapContext::ParentMap::ASTVisitor
 : public RecursiveASTVisitor {
 public:
-  ASTVisitor(ParentMap &Map) : Map(Map) {}
+  ASTVisitor(ParentMap &Map, ASTContext &Ctx) : Map(Map), Ctx(Ctx) {}
 
 private:
   friend class RecursiveASTVisitor;
@@ -422,6 +422,19 @@
 &Map.PointerParents);
   }
   bool TraverseTypeLoc(TypeLoc TypeLocNode) {
+if (Ctx.getParentMapContext().getTraversalKind() ==
+TK_IgnoreUnlessSpelledInSource) {
+  if (auto FPTL = TypeLocNode.getAs()) {
+for (unsigned I = 0, E = FPTL.getNumParams(); I != E; ++I) {
+  if (auto *P = FPTL.getParam(I)) {
+if (!TraverseDecl(P))
+  return false;
+  }
+}
+return true;
+  }
+}
+
 return TraverseNode(
 TypeLocNode, DynTypedNode::create(TypeLocNode),
 [&] { return VisitorBase::TraverseTypeLoc(TypeLocNode); },
@@ -446,11 +459,12 @@
   }
 
   ParentMap ⤅
+  ASTContext &Ctx;
   llvm::SmallVector ParentStack;
 };
 
 ParentMapContext::ParentM

[PATCH] D96051: [OpenCL] Support enum and typedef args in TableGen BIFs

2021-02-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl:38
+typedef uint cl_mem_fence_flags;
+#define CLK_GLOBAL_MEM_FENCE   0x02
+

Should we add this conditionally if the base header is not included?

In the subsequent patches where you will add other functions, we should make 
sure that the base header indeed contains the declarations we use in tablegen.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:727
+  }
+  return S.Context.getEnumType(Result.getAsSingle());
+}

I think we should add an assert that Result.getAsSingle() indeed 
holds. Consider if instead of using base header the types are defined manually 
and they are regular integers, not enums.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:739
+  }
+  return S.Context.getTypedefType(Result.getAsSingle());
+}

Same here, let's add an assert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96051

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


[PATCH] D93003: [libunwind] LIBUNWIND_HERMETIC_STATIC_LIBRARY fixes

2021-02-05 Thread Ryan Prichard via Phabricator via cfe-commits
rprichard updated this revision to Diff 321701.
rprichard added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Just fix ELF and leave Mach-O as-is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93003

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  libunwind/CMakeLists.txt
  libunwind/src/CMakeLists.txt
  libunwind/src/assembly.h
  libunwind/src/config.h

Index: libunwind/src/config.h
===
--- libunwind/src/config.h
+++ libunwind/src/config.h
@@ -52,7 +52,7 @@
   #endif
 #endif
 
-#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
+#if defined(_LIBUNWIND_HIDE_SYMBOLS)
   #define _LIBUNWIND_EXPORT
   #define _LIBUNWIND_HIDDEN
 #else
Index: libunwind/src/assembly.h
===
--- libunwind/src/assembly.h
+++ libunwind/src/assembly.h
@@ -87,17 +87,23 @@
 #else
 #define SYMBOL_IS_FUNC(name) .type name,@function
 #endif
+#if defined(_LIBUNWIND_HIDE_SYMBOLS)
+#define EXPORT_SYMBOL(name) .hidden name
+#else
 #define EXPORT_SYMBOL(name)
+#endif
 #define HIDDEN_SYMBOL(name) .hidden name
 #define WEAK_SYMBOL(name) .weak name
 
 #if defined(__hexagon__)
-#define WEAK_ALIAS(name, aliasname) \
-  WEAK_SYMBOL(aliasname) SEPARATOR \
+#define WEAK_ALIAS(name, aliasname)\
+  EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR  \
+  WEAK_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR\
   .equiv SYMBOL_NAME(aliasname), SYMBOL_NAME(name)
 #else
 #define WEAK_ALIAS(name, aliasname)\
-  WEAK_SYMBOL(aliasname) SEPARATOR \
+  EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR  \
+  WEAK_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR\
   SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
 #endif
 
@@ -119,7 +125,7 @@
   .section .drectve,"yn" SEPARATOR \
   .ascii "-export:", #name, "\0" SEPARATOR \
   .text
-#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
+#if defined(_LIBUNWIND_HIDE_SYMBOLS)
 #define EXPORT_SYMBOL(name)
 #else
 #define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
Index: libunwind/src/CMakeLists.txt
===
--- libunwind/src/CMakeLists.txt
+++ libunwind/src/CMakeLists.txt
@@ -160,11 +160,11 @@
 LINKER_LANGUAGE C
 OUTPUT_NAME "unwind")
 
-  if(LIBUNWIND_HERMETIC_STATIC_LIBRARY)
+  if(LIBUNWIND_HIDE_SYMBOLS)
 append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility=hidden)
 append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden)
 target_compile_options(unwind_static PRIVATE ${UNWIND_STATIC_LIBRARY_FLAGS})
-target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
+target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
   endif()
 
   list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
Index: libunwind/CMakeLists.txt
===
--- libunwind/CMakeLists.txt
+++ libunwind/CMakeLists.txt
@@ -101,7 +101,7 @@
   message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS=ON is not supported on this platform.")
 endif()
 
-option(LIBUNWIND_HERMETIC_STATIC_LIBRARY
+option(LIBUNWIND_HIDE_SYMBOLS
   "Do not export any symbols from the static library." OFF)
 
 #===
@@ -320,7 +320,7 @@
 
 # Disable DLL annotations on Windows for static builds.
 if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED)
-  add_definitions(-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
+  add_definitions(-D_LIBUNWIND_HIDE_SYMBOLS)
 endif()
 
 if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -179,7 +179,7 @@
 set(RUNTIMES_${target}-unknown-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} CACHE PATH "")
 set(RUNTIMES_${target}-unknown-fuchsia_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
 set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
-set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
+set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_HIDE_SYMBOLS ON CACHE BOOL "")
 set(RUNTIMES_${target}-unknown-fuchsia_LIBUNWIND_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "")
 set(RUNTIMES_${target}-unknown-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set

[PATCH] D93003: [libunwind] LIBUNWIND_HERMETIC_STATIC_LIBRARY fixes

2021-02-05 Thread Ryan Prichard via Phabricator via cfe-commits
rprichard added a comment.

After renaming the CMake option, CMake prints a warning if I set the old option:

  CMake Warning:
Manually-specified variables were not used by the project:
  
  LIBUNWIND_HERMETIC_STATIC_LIBRARY


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93003

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


[clang] 45ccfd9 - Treat opencl_unroll_hint subject errors as semantic rather than parse errors

2021-02-05 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-02-05T07:20:41-05:00
New Revision: 45ccfd9c9d0311371a8217c15c2ef3ba969a0aff

URL: 
https://github.com/llvm/llvm-project/commit/45ccfd9c9d0311371a8217c15c2ef3ba969a0aff
DIFF: 
https://github.com/llvm/llvm-project/commit/45ccfd9c9d0311371a8217c15c2ef3ba969a0aff.diff

LOG: Treat opencl_unroll_hint subject errors as semantic rather than parse 
errors

The attribute definition claimed the attribute was inheritable (which
only applies to declaration attributes) and not a statement attribute.
Further, it treats subject appertainment errors as being parse errors
rather than semantic errors, which leads to us accepting invalid code.
For instance, we currently fail to reject:

void foo() {
  int i = 1000;
  __attribute__((nomerge, opencl_unroll_hint(8)))
  if (i) { foo(); }
}

This addresses the issues by clarifying that opencl_unroll_hint is a
statement attribute and handles its appertainment checks in the
semantic layer instead of the parsing layer. This changes the output of
the diagnostic text to be more consistent with other appertainment
errors.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/Parser/opencl-unroll-hint.cl

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index bfd50f6a6779..5eb8db516305 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1178,8 +1178,10 @@ def OpenCLKernel : InheritableAttr {
   let SimpleHandler = 1;
 }
 
-def OpenCLUnrollHint : InheritableAttr {
+def OpenCLUnrollHint : StmtAttr {
   let Spellings = [GNU<"opencl_unroll_hint">];
+//  let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
+// ErrorDiag, "'for', 'while', and 'do' 
statements">;
   let Args = [UnsignedArgument<"UnrollHint">];
   let Documentation = [OpenCLUnrollHintDocs];
 }

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 0ed80a481e78..da228cc4be7a 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1220,9 +1220,6 @@ def note_pragma_attribute_namespace_on_attribute : Note<
   "omit the namespace to add attributes to the most-recently"
   " pushed attribute group">;
 
-def err_opencl_unroll_hint_on_non_loop : Error<
-  "OpenCL only supports 'opencl_unroll_hint' attribute on for, while, and do 
statements">;
-
 // OpenCL EXTENSION pragma (OpenCL 1.1 [9.1])
 def warn_pragma_expected_colon : Warning<
   "missing ':' after %0 - ignoring">, InGroup;

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index f8b746446e7e..7c2f14cd83b9 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2821,17 +2821,6 @@ class Parser : public CodeCompletionHandler {
   void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
   void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
   void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
-  /// Parses opencl_unroll_hint attribute if language is OpenCL v2.0
-  /// or higher.
-  /// \return false if error happens.
-  bool MaybeParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs) {
-if (getLangOpts().OpenCL)
-  return ParseOpenCLUnrollHintAttribute(Attrs);
-return true;
-  }
-  /// Parses opencl_unroll_hint attribute.
-  /// \return false if error happens.
-  bool ParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs);
   void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
 
   VersionTuple ParseVersionTuple(SourceRange &Range);

diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 26a02575010c..71344ff10155 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -98,10 +98,15 @@ Parser::ParseStatementOrDeclaration(StmtVector &Stmts,
 
   ParenBraceBracketBalancer BalancerRAIIObj(*this);
 
+  // Because we're parsing either a statement or a declaration, the order of
+  // attribute parsing is important. [[]] attributes at the start of a
+  // statement are 
diff erent from [[]] attributes that follow an __attribute__
+  // at the start of the statement. Thus, we're not using MaybeParseAttributes
+  // here because we don't want to allow arbitrary orderings.
   ParsedAttributesWithRange Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs, nullptr, /*MightBeObjCMessageSend*/ true);
-  if (!MaybeParseOpenCLUnrollHintAttribute(Attrs))
-return StmtError();
+  if (getLangOpts().OpenCL)
+MaybeParseGNUAttributes(Attrs);
 
   StmtResult Res = ParseStatementOrDeclarationAfterAttributes(
   Stmts, StmtCtx, TrailingElseLoc, Attrs);
@@ -2548,19 +2

[PATCH] D96043: Treat opencl_unroll_hint subject errors as semantic rather than parse errors

2021-02-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Thanks for the review! I've commit in 45ccfd9c9d0311371a8217c15c2ef3ba969a0aff 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96043

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


[PATCH] D81678: Introduce noundef attribute at call sites for stricter poison analysis

2021-02-05 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.
Herald added a reviewer: jansvoboda11.

@guiand Do you plan to continue working on this patch? If not, I would try to 
finalize it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81678

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


[PATCH] D81678: Introduce noundef attribute at call sites for stricter poison analysis

2021-02-05 Thread Gui Andrade via Phabricator via cfe-commits
guiand added a comment.

Changing the mechanism to explicit opt-in seems like a good idea, and bypasses 
the test issues.

If everyone agrees about proceeding with this, I can fix up this patch within 
the next couple days and we can hopefully wrap this up!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81678

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


[PATCH] D92715: [Clang][RISCV] Define RISC-V V builtin types

2021-02-05 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added a comment.
Herald added subscribers: StephenFan, vkmr.

In D92715#2520925 , @craig.topper 
wrote:

> I wonder if these types should be prefixed with "__clang_" like AArch64 tuple 
> types?

It seems only AArch64 tuple types have "__clang_" prefix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92715

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


[PATCH] D92715: [Clang][RISCV] Define RISC-V V builtin types

2021-02-05 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D92715#2544178 , @HsiangKai wrote:

> In D92715#2520925 , @craig.topper 
> wrote:
>
>> I wonder if these types should be prefixed with "__clang_" like AArch64 
>> tuple types?
>
> It seems only AArch64 tuple types have "__clang_" prefix.

I think the other types don't have it because they are defined by an ARM 
standard. See the description for https://reviews.llvm.org/D81721


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92715

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


[PATCH] D95935: [clang][CodeComplete] Fix crash on ParenListExprs

2021-02-05 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95935

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


[PATCH] D96027: [clangd] Trace queue state for each TUScheduler action.

2021-02-05 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang-tools-extra/clangd/TUScheduler.cpp:1054
 Requests.push_back({std::move(Task), std::string(Name), 
steady_clock::now(),
-std::move(Ctx), Update, Invalidation,
-std::move(Invalidate)});
+std::move(Ctx), std::move(QueueCtx), Update,
+Invalidation, std::move(Invalidate)});

sammccall wrote:
> kadircet wrote:
> > what if we just pushed the span here and kept it alive in the queue? it is 
> > move-able at the moment.
> > 
> > our tracing contract seem to be saying beginSpan/endSpan calls would always 
> > form a proper stack, i am not sure about its importance to the jsontracer, 
> > but I don't think rest of our tracers cares (and i think it would be nice 
> > for that trace to actually span the whole time in queue).
> > what if we just pushed the span here and kept it alive in the queue?
> Mechanically it's a little more complicated than that, but I get what you're 
> saying - unfortunately it doesn't quite work.
> 
> > it is move-able at the moment.
> (in fact not: it has a WithContext member whose move operators are deleted)
> 
> > our tracing contract seem to be saying beginSpan/endSpan calls would always 
> > form a proper stack
> Yes - this is in fact documented as the *only* point of endSpan - it marks 
> the strictly-stacking lifetimes of stack-allocated trace::Spans objects 
> themselves. Tracers that don't need this strict stacking are supposed to 
> watch for the destruction of the context frames created by beginSpan instead. 
> This extends the span over context-propagation, at the cost of no longer 
> strictly stacking.
> 
> > i am not sure about its importance to the jsontracer
> The chrome trace viewer (which jsontracer targets) really does require strict 
> stacking. I'm not 100% sure, but I think the behavior was just to silently 
> discard events that don't nest properly.
> 
> > I don't think rest of our tracers cares (and i think it would be nice for 
> > that trace to actually span the whole time in queue).
> Right, so our private out-of-tree tracer follows request/context timelines 
> rather than thread ones, and doesn't require strict nesting. It completely 
> ignores endSpan(), and ends events when the context gets destroyed instead. 
> That's why we bundle up the QueueCtx into the request and then destroy it as 
> soon as we dequeue - it makes that trace actually span the whole time in 
> queue :-)
> 
> (Happy to chat more about this or add some comments/diagrams/something if we 
> should make this more clear)
thanks makes sense.

> The chrome trace viewer (which jsontracer targets) really does require strict 
> stacking. I'm not 100% sure, but I think the behavior was just to silently 
> discard events that don't nest properly.

I was expecting this to be the case, but wanted to be sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96027

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


[PATCH] D96120: [scudo] Port scudo sanitizer to Windows

2021-02-05 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop created this revision.
russell.gallop added reviewers: cryptoad, aganea.
Herald added subscribers: phosek, mgorny.
russell.gallop requested review of this revision.
Herald added projects: clang, Sanitizers.
Herald added subscribers: Sanitizers, cfe-commits.

Based on https://reviews.llvm.org/D42519, this ports the sanitizer version of 
scudo to Windows.

Passes lit tests and when used as the allocator for LLVM, that passes 
check-all. Have noticed that on LLVM with Scudo, 
https://bugs.llvm.org/show_bug.cgi?id=24978 does intermittently occur when 
running lli tests.

For more details of evaluation see https://reviews.llvm.org/D86694

A separate review will allow hooking this in as the memory allocator for LLVM.

I'm aware that scudo sanitizer version is not under active development. This is 
intended as a step to porting scudo standalone.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96120

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
  compiler-rt/lib/scudo/CMakeLists.txt
  compiler-rt/lib/scudo/scudo_allocator.cpp
  compiler-rt/lib/scudo/scudo_crc32.cpp
  compiler-rt/lib/scudo/scudo_new_delete.cpp
  compiler-rt/lib/scudo/scudo_platform.h
  compiler-rt/lib/scudo/scudo_tsd.h
  compiler-rt/lib/scudo/scudo_tsd_shared.cpp
  compiler-rt/lib/scudo/scudo_tsd_shared.inc
  compiler-rt/test/scudo/cxx_threads.cpp
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/valloc.c
===
--- compiler-rt/test/scudo/valloc.c
+++ compiler-rt/test/scudo/valloc.c
@@ -2,7 +2,7 @@
 // RUN: %run %t valid   2>&1
 // RUN: not %run %t invalid 2>&1 | FileCheck %s
 // RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t invalid 2>&1
-// UNSUPPORTED: android
+// UNSUPPORTED: android, windows
 
 // Tests that valloc and pvalloc work as intended.
 
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- compiler-rt/test/scudo/tsd_destruction.c
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,5 +1,6 @@
 // RUN: %clang_scudo %s -o %t
 // RUN: %run %t 2>&1
+// UNSUPPORTED: windows
 
 #include 
 #include 
Index: compiler-rt/test/scudo/threads.c
===
--- compiler-rt/test/scudo/threads.c
+++ compiler-rt/test/scudo/threads.c
@@ -1,6 +1,7 @@
 // RUN: %clang_scudo %s -o %t
 // RUN: %env_scudo_opts="QuarantineSizeKb=0:ThreadLocalQuarantineSizeKb=0" %run %t 5 100 2>&1
 // RUN: %env_scudo_opts="QuarantineSizeKb=1024:ThreadLocalQuarantineSizeKb=64" %run %t 5 100 2>&1
+// UNSUPPORTED: windows
 
 // Tests parallel allocations and deallocations of memory chunks from a number
 // of concurrent threads, with and without quarantine.
Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ compiler-rt/test/scudo/symbols.test
@@ -1,4 +1,4 @@
-UNSUPPORTED: android
+UNSUPPORTED: android, windows
 
 Verify that various functions are *not* present in the minimal binary. Presence
 of those symbols in the minimal runtime would mean that the split code made it
Index: compiler-rt/test/scudo/secondary.c
===
--- compiler-rt/test/scudo/secondary.c
+++ compiler-rt/test/scudo/secondary.c
@@ -6,37 +6,60 @@
 // allocated by the Secondary allocator, or writing too far in front of it.
 
 #include 
-#include 
-#include 
+#include 
 #include 
 #include 
+#ifdef _WIN32
+#include 
+#else
+#include 
 #include 
+#endif
 
+#ifdef _WIN32
+DWORD getsystempagesize() {
+  SYSTEM_INFO si;
+  GetSystemInfo(&si);
+  return si.dwPageSize;
+}
+LONG WINAPI handler(EXCEPTION_POINTERS *ExceptionInfo) {
+  fprintf(stderr, "AccessViolation\n");
+  ExitProcess(0);
+}
+#else
 void handler(int signo, siginfo_t *info, void *uctx) {
   if (info->si_code == SEGV_ACCERR) {
-fprintf(stderr, "SCUDO SIGSEGV\n");
+fprintf(stderr, "AccessViolation\n");
 exit(0);
   }
   exit(1);
 }
+long getsystempagesize() {
+  return sysconf(_SC_PAGESIZE);
+}
+#endif
 
 int main(int argc, char **argv)
 {
   // The size must be large enough to be serviced by the secondary allocator.
-  long page_size = sysconf(_S

[clang] 447dc85 - Revert "[PowerPC] [Clang] Enable float128 feature on P9 by default"

2021-02-05 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2021-02-05T20:33:56+08:00
New Revision: 447dc856b243b99ce70019ba1187c39746f4e0e9

URL: 
https://github.com/llvm/llvm-project/commit/447dc856b243b99ce70019ba1187c39746f4e0e9
DIFF: 
https://github.com/llvm/llvm-project/commit/447dc856b243b99ce70019ba1187c39746f4e0e9.diff

LOG: Revert "[PowerPC] [Clang] Enable float128 feature on P9 by default"

Commit 6bf29dbb enables float128 feature by default for Power9 targets.
But float128 may cause build failure in libcxx testing. Revert this
commit first to unblock LLVM 12 release.

Added: 


Modified: 
clang/lib/Basic/Targets/PPC.cpp
clang/test/Driver/ppc-f128-support-check.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index cfede6e6e756..ff09c0fa2a23 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -318,9 +318,6 @@ bool PPCTargetInfo::initFeatureMap(
 .Case("pwr9", true)
 .Case("pwr8", true)
 .Default(false);
-  Features["float128"] = llvm::StringSwitch(CPU)
-.Case("pwr9", true)
-.Default(false);
 
   Features["spe"] = llvm::StringSwitch(CPU)
 .Case("8548", true)

diff  --git a/clang/test/Driver/ppc-f128-support-check.c 
b/clang/test/Driver/ppc-f128-support-check.c
index 2e4b7a7ae09c..24748905612f 100644
--- a/clang/test/Driver/ppc-f128-support-check.c
+++ b/clang/test/Driver/ppc-f128-support-check.c
@@ -1,7 +1,7 @@
 // RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
-// RUN:   -mcpu=pwr9 %s 2>&1 | FileCheck %s --check-prefix=HASF128
+// RUN:   -mcpu=pwr9 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=HASF128
 // RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
-// RUN:   -mcpu=power9 %s 2>&1 | FileCheck %s --check-prefix=HASF128
+// RUN:   -mcpu=power9 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=HASF128
 
 // RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
 // RUN:   -mcpu=pwr8 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=NOF128



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


[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-02-05 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a reviewer: sgraenitz.
teemperor added a comment.

Another round of comments.

Also a general note that applies to a bunch of places, if you specify the 
function names in comments when calling a function, you have to add a trailing 
`=` so that clang-tidy can actually check this for us 
::

  SomeFunction(/*ArgName*/ 0); // wrong
  SomeFunction(/*ArgName=*/ 0); // right

I think someone who knows more about the JIT should review the JIT-related code 
(I'm just gonna add Stefan too). And the changes related to the FrontendActions 
should also be signed off by someone else as I rarely touch that code. Not sure 
who though.

Beside that I think we're getting there, thanks!




Comment at: clang/include/clang/Frontend/FrontendAction.h:238
   /// objects, and run statistics and output file cleanup code.
-  void EndSourceFile();
+  virtual void EndSourceFile();
 

I think this and the change above requires updating `WrapperFrontendAction` to 
also forward these functions to the wrapped action. Otherwise wrapping actions 
would change their behaviour. See the other virtual functions there.



Comment at: clang/include/clang/Interpreter/Transaction.h:1
+//===--- Transaction.h - Incremental Compilation and Execution---*- C++ 
-*-===//
+//

v.g.vassilev wrote:
> teemperor wrote:
> > Could this whole file just be part of `IncrementalParser.h` which is the 
> > only user ? `clang::Transaction` seems anyway a bit of a generic name, so 
> > maybe this could become `clang::IncrementalParser::Transaction` then.
> The intent is to expose the Transaction class and if I move it in the 
> `IncrementalParser` I will have to expose the `IncrementalParser.h`. Would it 
> make sense to move it as part of the Interpreter object? Eg. 
> `clang::Interpreter::Transaction`?
Makes sense. I guess moving this into the Interpreter would create some strange 
dependencies, so I would say we keep it in its own file. Maybe we could put it 
into a `interpreter` namespace or give it a more unique name 
`InterpreterTransaction`?

I also think this should have some documentation.



Comment at: clang/lib/Interpreter/IncrementalExecutor.h:36
+  llvm::Error addModule(std::unique_ptr M);
+  llvm::Error runCtors() const;
+};

Should we maybe merge `runCtors` and `addModule`? Not sure if there is a use 
case for adding a Module but not running Ctors. Also documentation.



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:63
+if (CI.hasCodeCompletionConsumer())
+  CompletionConsumer = &CI.getCodeCompletionConsumer();
+

Can this completion code even be used? It doesn't look like it can (and I'm not 
sure if using the `CodeCompletionAt` flag is really useful in a REPL as you can 
only specify it once during startup). IMHO this can be left out until we 
actually can hook up this into the LineEditor (and we have a way to test this).



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:69
+Preprocessor &PP = CI.getPreprocessor();
+PP.enableIncrementalProcessing();
+PP.EnterMainSourceFile();

Could we do that before creating the Sema? Sema's constructor is doing quite a 
few things and some of them might depend on this setting in the future.



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:73
+
+  void EndSourceFile() override {
+if (IsTerminating) {

I assume this function intercepts all EndSourceFile calls so that the 
preprocessor is 'stuck' in the main file even if it reaches the end of the user 
input so far? Might be worth a comment.



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:74
+  void EndSourceFile() override {
+if (IsTerminating) {
+  WrapperFrontendAction::EndSourceFile();

No `{ .. }` 



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:101
+  // later errors use the default handling behavior instead.
+  llvm::remove_fatal_error_handler();
+}

I think this should be in ClangRepl.cpp where we actually install the handler 
(I wouldn't expect that creating an `IncrementalParser` object would touch the 
global error handler).



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:136
+Consumer->HandleTopLevelDecl(DGR);
+  }
+

Could we test this?



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:165
+  std::ostringstream SourceName;
+  SourceName << "input_line_" << InputCount++;
+

I think this is OK for this patch, but if the file is called "input_line_" then 
Clang would still emit the actual line information (which is 1) and we get 
`input_line_1:1:9: error: ...` diagnostics. Since D83038 Clang can hide line 
numbers in diagnostics, so we could 

[clang-tools-extra] d1978fa - [clangd] Deduplicate scopes in IncludeFixer queries

2021-02-05 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-02-05T14:02:50+01:00
New Revision: d1978fa4bf0d7da0b3cd88879e9411467edcb01f

URL: 
https://github.com/llvm/llvm-project/commit/d1978fa4bf0d7da0b3cd88879e9411467edcb01f
DIFF: 
https://github.com/llvm/llvm-project/commit/d1978fa4bf0d7da0b3cd88879e9411467edcb01f.diff

LOG: [clangd] Deduplicate scopes in IncludeFixer queries

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

Added: 


Modified: 
clang-tools-extra/clangd/IncludeFixer.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeFixer.cpp 
b/clang-tools-extra/clangd/IncludeFixer.cpp
index 2b79c6eb4fa6..babc3426b868 100644
--- a/clang-tools-extra/clangd/IncludeFixer.cpp
+++ b/clang-tools-extra/clangd/IncludeFixer.cpp
@@ -40,31 +40,14 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
+#include 
+#include 
+#include 
 #include 
 
 namespace clang {
 namespace clangd {
 
-namespace {
-
-// Collects contexts visited during a Sema name lookup.
-class VisitedContextCollector : public VisibleDeclConsumer {
-public:
-  void EnteredContext(DeclContext *Ctx) override { Visited.push_back(Ctx); }
-
-  void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
- bool InBaseClass) override {}
-
-  std::vector takeVisitedContexts() {
-return std::move(Visited);
-  }
-
-private:
-  std::vector Visited;
-};
-
-} // namespace
-
 std::vector IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) const {
   switch (Info.getID()) {
@@ -313,17 +296,26 @@ llvm::Optional 
extractUnresolvedNameCheaply(
 std::vector
 collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo, Scope *S,
 Sema::LookupNameKind LookupKind) {
+  // Collects contexts visited during a Sema name lookup.
+  struct VisitedContextCollector : public VisibleDeclConsumer {
+VisitedContextCollector(std::vector &Out) : Out(Out) {}
+void EnteredContext(DeclContext *Ctx) override {
+  if (llvm::isa(Ctx))
+Out.push_back(printNamespaceScope(*Ctx));
+}
+void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
+   bool InBaseClass) override {}
+std::vector &Out;
+  };
+
   std::vector Scopes;
-  VisitedContextCollector Collector;
+  Scopes.push_back("");
+  VisitedContextCollector Collector(Scopes);
   Sem.LookupVisibleDecls(S, LookupKind, Collector,
  /*IncludeGlobalScope=*/false,
  /*LoadExternal=*/false);
-
-  Scopes.push_back("");
-  for (const auto *Ctx : Collector.takeVisitedContexts()) {
-if (isa(Ctx))
-  Scopes.push_back(printNamespaceScope(*Ctx));
-  }
+  std::sort(Scopes.begin(), Scopes.end());
+  Scopes.erase(std::unique(Scopes.begin(), Scopes.end()), Scopes.end());
   return Scopes;
 }
 



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


[PATCH] D95942: [clangd] Deduplicate scopes in IncludeFixer queries

2021-02-05 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd1978fa4bf0d: [clangd] Deduplicate scopes in IncludeFixer 
queries (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95942

Files:
  clang-tools-extra/clangd/IncludeFixer.cpp


Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -40,31 +40,14 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
+#include 
+#include 
+#include 
 #include 
 
 namespace clang {
 namespace clangd {
 
-namespace {
-
-// Collects contexts visited during a Sema name lookup.
-class VisitedContextCollector : public VisibleDeclConsumer {
-public:
-  void EnteredContext(DeclContext *Ctx) override { Visited.push_back(Ctx); }
-
-  void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
- bool InBaseClass) override {}
-
-  std::vector takeVisitedContexts() {
-return std::move(Visited);
-  }
-
-private:
-  std::vector Visited;
-};
-
-} // namespace
-
 std::vector IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) const {
   switch (Info.getID()) {
@@ -313,17 +296,26 @@
 std::vector
 collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo, Scope *S,
 Sema::LookupNameKind LookupKind) {
+  // Collects contexts visited during a Sema name lookup.
+  struct VisitedContextCollector : public VisibleDeclConsumer {
+VisitedContextCollector(std::vector &Out) : Out(Out) {}
+void EnteredContext(DeclContext *Ctx) override {
+  if (llvm::isa(Ctx))
+Out.push_back(printNamespaceScope(*Ctx));
+}
+void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
+   bool InBaseClass) override {}
+std::vector &Out;
+  };
+
   std::vector Scopes;
-  VisitedContextCollector Collector;
+  Scopes.push_back("");
+  VisitedContextCollector Collector(Scopes);
   Sem.LookupVisibleDecls(S, LookupKind, Collector,
  /*IncludeGlobalScope=*/false,
  /*LoadExternal=*/false);
-
-  Scopes.push_back("");
-  for (const auto *Ctx : Collector.takeVisitedContexts()) {
-if (isa(Ctx))
-  Scopes.push_back(printNamespaceScope(*Ctx));
-  }
+  std::sort(Scopes.begin(), Scopes.end());
+  Scopes.erase(std::unique(Scopes.begin(), Scopes.end()), Scopes.end());
   return Scopes;
 }
 


Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -40,31 +40,14 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
+#include 
+#include 
+#include 
 #include 
 
 namespace clang {
 namespace clangd {
 
-namespace {
-
-// Collects contexts visited during a Sema name lookup.
-class VisitedContextCollector : public VisibleDeclConsumer {
-public:
-  void EnteredContext(DeclContext *Ctx) override { Visited.push_back(Ctx); }
-
-  void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
- bool InBaseClass) override {}
-
-  std::vector takeVisitedContexts() {
-return std::move(Visited);
-  }
-
-private:
-  std::vector Visited;
-};
-
-} // namespace
-
 std::vector IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) const {
   switch (Info.getID()) {
@@ -313,17 +296,26 @@
 std::vector
 collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo, Scope *S,
 Sema::LookupNameKind LookupKind) {
+  // Collects contexts visited during a Sema name lookup.
+  struct VisitedContextCollector : public VisibleDeclConsumer {
+VisitedContextCollector(std::vector &Out) : Out(Out) {}
+void EnteredContext(DeclContext *Ctx) override {
+  if (llvm::isa(Ctx))
+Out.push_back(printNamespaceScope(*Ctx));
+}
+void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
+   bool InBaseClass) override {}
+std::vector &Out;
+  };
+
   std::vector Scopes;
-  VisitedContextCollector Collector;
+  Scopes.push_back("");
+  VisitedContextCollector Collector(Scopes);
   Sem.LookupVisibleDecls(S, LookupKind, Collector,
  /*IncludeGlobalScope=*/false,
  /*LoadExternal=*/false);
-
-  Scopes.push_back("");
-  for (const auto *Ctx : Collector.takeVisitedContexts()) {
-if (isa(Ctx))
-  Scopes.push_back(printNamespaceScope(*Ctx));
-  }
+  std::sort(Scopes.begin(), Scopes.end());
+  Scopes.erase(std::unique(Scopes.begin(), Scopes.end()), Scopes.end());
   ret

[PATCH] D95877: [analyzer] Fix static_cast on pointer-to-member handling

2021-02-05 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 321714.
RedDocMD marked an inline comment as done.
RedDocMD added a comment.

Added TODO for reinterpret_cast, moved assertion code to its own block


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95877

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/Analysis/pointer-to-member.cpp

Index: clang/test/Analysis/pointer-to-member.cpp
===
--- clang/test/Analysis/pointer-to-member.cpp
+++ clang/test/Analysis/pointer-to-member.cpp
@@ -287,3 +287,47 @@
   clang_analyzer_eval(a.*ep == 5); // expected-warning{{TRUE}}
 }
 } // namespace testAnonymousMember
+
+namespace testStaticCasting {
+// From bug #48739
+struct Grandfather {
+  int field;
+};
+
+struct Father : public Grandfather {};
+struct Son : public Father {};
+
+void test() {
+  int Son::*sf = &Son::field;
+  Grandfather grandpa;
+  grandpa.field = 10;
+  int Grandfather::*gpf1 = static_cast(sf);
+  int Grandfather::*gpf2 = static_cast(static_cast(sf));
+  int Grandfather::*gpf3 = static_cast(static_cast(static_cast(sf)));
+  clang_analyzer_eval(grandpa.*gpf1 == 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(grandpa.*gpf2 == 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(grandpa.*gpf3 == 10); // expected-warning{{TRUE}}
+}
+} // namespace testStaticCasting
+
+// TODO: The following test will work properly once reinterpret_cast on pointer to member is handled properly
+// namespace testReinterpretCasting {
+// struct Base {
+//   int field;
+// };
+//
+// struct Derived : public Base {};
+//
+// struct DoubleDerived : public Derived {};
+//
+// struct Some {};
+//
+// void f() {
+//   int DoubleDerived::*ddf = &Base::field;
+//   int Base::*bf = reinterpret_cast(reinterpret_cast(reinterpret_cast(ddf)));
+//   int Some::*sf = reinterpret_cast(ddf);
+//   Base base;
+//   base.field = 13;
+//   clang_analyzer_eval(base.*bf == 13); // expected-warning{{TRUE}}
+// }
+// } // namespace testReinterpretCasting
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -526,10 +526,9 @@
   case CK_ReinterpretMemberPointer: {
 SVal V = state->getSVal(Ex, LCtx);
 if (auto PTMSV = V.getAs()) {
-  SVal CastedPTMSV = svalBuilder.makePointerToMember(
-  getBasicVals().accumCXXBase(
-  llvm::make_range(
-  CastE->path_begin(), CastE->path_end()), *PTMSV));
+  SVal CastedPTMSV =
+  svalBuilder.makePointerToMember(getBasicVals().accumCXXBase(
+  CastE->path(), *PTMSV, CastE->getCastKind()));
   state = state->BindExpr(CastE, LCtx, CastedPTMSV);
   Bldr.generateNode(CastE, Pred, state);
   continue;
Index: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
===
--- clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
+++ clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
@@ -21,6 +21,7 @@
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/ImmutableList.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include 
 #include 
 #include 
@@ -176,28 +177,74 @@
   return D;
 }
 
+bool noRepeatedElements(
+const llvm::ImmutableList &BaseSpecList) {
+  // First we need to make sure that there are no-repetitions in BaseSpecList
+  llvm::SmallPtrSet BaseSpecSeen;
+  for (const auto &BaseSpec : BaseSpecList) {
+auto BaseType = BaseSpec->getType();
+auto Stat = BaseSpecSeen.insert(BaseType);
+if (!Stat.second)
+  return false;
+  }
+  return true;
+}
+
 const PointerToMemberData *BasicValueFactory::accumCXXBase(
 llvm::iterator_range PathRange,
-const nonloc::PointerToMember &PTM) {
+const nonloc::PointerToMember &PTM, const CastKind &kind) {
+  assert((kind == CK_DerivedToBaseMemberPointer ||
+  kind == CK_BaseToDerivedMemberPointer ||
+  kind == CK_ReinterpretMemberPointer) &&
+ "accumCXXBase called with wrong CastKind");
   nonloc::PointerToMember::PTMDataType PTMDT = PTM.getPTMData();
   const NamedDecl *ND = nullptr;
-  llvm::ImmutableList PathList;
+  llvm::ImmutableList BaseSpecList;
 
   if (PTMDT.isNull() || PTMDT.is()) {
 if (PTMDT.is())
   ND = PTMDT.get();
 
-PathList = CXXBaseListFactory.getEmptyList();
-  } else { // const PointerToMemberData *
+BaseSpecList = CXXBaseListFactory.getEmptyList();
+  } else {
 const PointerToMemberData *PTMD = PTMDT.get();
 ND = PTMD->getDeclaratorDecl();
 
-PathLis

[PATCH] D96082: [clang-tidy] Add 'readability-useless-return-value' check

2021-02-05 Thread Lukas Hänel via Phabricator via cfe-commits
LukasHanel updated this revision to Diff 321715.
LukasHanel added a comment.

Address review comments, fix C++ unit tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96082

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/UselessReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/readability/UselessReturnValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-useless-return-value.rst
  clang-tools-extra/test/clang-tidy/checkers/readability-useless-return-value.c
  
clang-tools-extra/test/clang-tidy/checkers/readability-useless-return-value.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-useless-return-value.h

Index: clang-tools-extra/test/clang-tidy/checkers/readability-useless-return-value.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-useless-return-value.h
@@ -0,0 +1,3 @@
+int f11(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f11' returns always the same value [readability-useless-return-value]
+// CHECK-FIXES: {{^}}void f11(void);{{$}}
Index: clang-tools-extra/test/clang-tidy/checkers/readability-useless-return-value.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-useless-return-value.cpp
@@ -0,0 +1,32 @@
+// RUN: %check_clang_tidy %s readability-useless-return-value %t
+
+int f() {
+  return 0;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: function 'f' returns always the same value [readability-useless-return-value]
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: returns 0 here [readability-useless-return-value]
+
+// CHECK-FIXES: {{^}}void f() {{{$}}
+// CHECK-FIXES: {{^}}  return;{{$}}
+
+struct Foo {
+  Foo(int i);
+  Foo &operator=(int &&other);
+};
+Foo tie(int i) {
+  return Foo(i);
+}
+
+int demangleUnsigned() {
+  int Number = 0;
+  tie(Number) = 1;
+  return Number;
+}
+
+class Foo1 {
+  virtual unsigned g(void) const;
+};
+
+unsigned Foo1::g(void) const {
+  return 0;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/readability-useless-return-value.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-useless-return-value.c
@@ -0,0 +1,247 @@
+// RUN: %check_clang_tidy %s readability-useless-return-value %t
+
+int f() {
+  return 0;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: function 'f' returns always the same value [readability-useless-return-value]
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: returns 0 here [readability-useless-return-value]
+
+// CHECK-FIXES: {{^}}void f() {{{$}}
+// CHECK-FIXES: {{^}}  return;{{$}}
+
+unsigned int f2() {
+  return 0U;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:14: warning: function 'f2' returns always the same value [readability-useless-return-value]
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: returns 0 here [readability-useless-return-value]
+
+// CHECK-FIXES: {{^}}void f2() {{{$}}
+// CHECK-FIXES: {{^}}  return;{{$}}
+
+typedef unsigned int mytype_t;
+mytype_t f3() {
+  return 0U;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:10: warning: function 'f3' returns always the same value [readability-useless-return-value]
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: returns 0 here [readability-useless-return-value]
+
+// CHECK-FIXES: {{^}}void f3() {{{$}}
+// CHECK-FIXES: {{^}}  return;{{$}}
+
+const int f4() {
+  return 0;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:11: warning: function 'f4' returns always the same value [readability-useless-return-value]
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: returns 0 here [readability-useless-return-value]
+
+// CHECK-FIXES: {{^}}const void f4() {{{$}}
+// CHECK-FIXES: {{^}}  return;{{$}}
+
+static int f5() {
+  return 0;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:12: warning: function 'f5' returns always the same value [readability-useless-return-value]
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: returns 0 here [readability-useless-return-value]
+
+// CHECK-FIXES: {{^}}static void f5() {{{$}}
+// CHECK-FIXES: {{^}}  return;{{$}}
+
+#define EXIT_SUCCESS 0
+
+int f6() {
+  return EXIT_SUCCESS; //EXIT_SUCCESS
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: function 'f6' returns always the same value [readability-useless-return-value]
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: returns 0 here [readability-useless-return-value]
+
+// CHECK-FIXES: {{^}}void f6() {{{$}}
+// CHECK-FIXES: {{^}}  return; //EXIT_SUCCESS{{$}}
+
+#define NULL 0
+
+int f7() {
+  return NULL; //NULL
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: function 'f7' returns always the same value [readability-useless-return-value]
+// CHECK-MESSAGES

[PATCH] D95877: [analyzer] Fix static_cast on pointer-to-member handling

2021-02-05 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD marked 2 inline comments as done.
RedDocMD added a comment.

@vsavchenko , does it look okay now?




Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:27
 #include 
+#include 
 #include 

vsavchenko wrote:
> We don't need this anymore :)
Wow, sharp eyes!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95877

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


[PATCH] D96123: [clangd] Expose actOnAllPArentDirectories helper

2021-02-05 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Will be used in other components that need ancestor traversal.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96123

Files:
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/support/Path.cpp
  clang-tools-extra/clangd/support/Path.h


Index: clang-tools-extra/clangd/support/Path.h
===
--- clang-tools-extra/clangd/support/Path.h
+++ clang-tools-extra/clangd/support/Path.h
@@ -28,6 +28,10 @@
 std::string maybeCaseFoldPath(PathRef Path);
 bool pathEqual(PathRef, PathRef);
 
+// Runs the given action on all parent directories of filename, starting from
+// deepest directory and going up to root. Stops whenever action succeeds.
+void actOnAllParentDirectories(PathRef FileName,
+   llvm::function_ref Action);
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/support/Path.cpp
===
--- clang-tools-extra/clangd/support/Path.cpp
+++ clang-tools-extra/clangd/support/Path.cpp
@@ -7,8 +7,27 @@
 
//===--===//
 
 #include "support/Path.h"
+#include "llvm/Support/Path.h"
+
 namespace clang {
 namespace clangd {
+namespace {
+// Variant of parent_path that operates only on absolute paths.
+PathRef absoluteParent(PathRef Path) {
+  assert(llvm::sys::path::is_absolute(Path));
+#if defined(_WIN32)
+  // llvm::sys says "C:\" is absolute, and its parent is "C:" which is 
relative.
+  // This unhelpful behavior seems to have been inherited from boost.
+  if (llvm::sys::path::relative_path(Path).empty()) {
+return PathRef();
+  }
+#endif
+  PathRef Result = llvm::sys::path::parent_path(Path);
+  assert(Result.empty() || llvm::sys::path::is_absolute(Result));
+  return Result;
+}
+
+} // namespace
 
 std::string maybeCaseFoldPath(PathRef Path) {
 #if defined(_WIN32) || defined(__APPLE__)
@@ -26,5 +45,11 @@
 #endif
 }
 
+void actOnAllParentDirectories(PathRef FileName,
+   llvm::function_ref Action) {
+  for (auto Path = absoluteParent(FileName); !Path.empty() && !Action(Path);
+   Path = absoluteParent(Path))
+;
+}
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -41,34 +41,6 @@
 
 namespace clang {
 namespace clangd {
-namespace {
-
-// Variant of parent_path that operates only on absolute paths.
-PathRef absoluteParent(PathRef Path) {
-  assert(llvm::sys::path::is_absolute(Path));
-#if defined(_WIN32)
-  // llvm::sys says "C:\" is absolute, and its parent is "C:" which is 
relative.
-  // This unhelpful behavior seems to have been inherited from boost.
-  if (llvm::sys::path::relative_path(Path).empty()) {
-return PathRef();
-  }
-#endif
-  PathRef Result = llvm::sys::path::parent_path(Path);
-  assert(Result.empty() || llvm::sys::path::is_absolute(Result));
-  return Result;
-}
-
-// Runs the given action on all parent directories of filename, starting from
-// deepest directory and going up to root. Stops whenever action succeeds.
-void actOnAllParentDirectories(PathRef FileName,
-   llvm::function_ref Action) {
-  for (auto Path = absoluteParent(FileName); !Path.empty() && !Action(Path);
-   Path = absoluteParent(Path))
-;
-}
-
-} // namespace
-
 tooling::CompileCommand
 GlobalCompilationDatabase::getFallbackCommand(PathRef File) const {
   std::vector Argv = {"clang"};


Index: clang-tools-extra/clangd/support/Path.h
===
--- clang-tools-extra/clangd/support/Path.h
+++ clang-tools-extra/clangd/support/Path.h
@@ -28,6 +28,10 @@
 std::string maybeCaseFoldPath(PathRef Path);
 bool pathEqual(PathRef, PathRef);
 
+// Runs the given action on all parent directories of filename, starting from
+// deepest directory and going up to root. Stops whenever action succeeds.
+void actOnAllParentDirectories(PathRef FileName,
+   llvm::function_ref Action);
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/support/Path.cpp
===
--- clang-tools-extra/clangd/support/Path.cpp
+++ clang-tools-extra/clangd/support/Path.cpp
@@ -7,8 +7,27 @@
 //===--===//
 
 #include "support/Path.h"
+#include "llvm/Support/Path.h"
+
 namespace cl

[PATCH] D96124: [clangd] Introduce BuildSystem

2021-02-05 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman, mgorny.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Interface for BuildSystem integration to enable generation of build
file edits.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96124

Files:
  clang-tools-extra/clangd/BuildSystem.cpp
  clang-tools-extra/clangd/BuildSystem.h
  clang-tools-extra/clangd/CMakeLists.txt

Index: clang-tools-extra/clangd/CMakeLists.txt
===
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -47,6 +47,7 @@
 add_clang_library(clangDaemon
   AST.cpp
   ASTSignals.cpp
+  BuildSystem.cpp
   ClangdLSPServer.cpp
   ClangdServer.cpp
   CodeComplete.cpp
Index: clang-tools-extra/clangd/BuildSystem.h
===
--- /dev/null
+++ clang-tools-extra/clangd/BuildSystem.h
@@ -0,0 +1,55 @@
+//===--- BuildSystem.h ---*- 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
+//
+//===--===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_BUILD_SYSTEM_H_
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_BUILD_SYSTEM_H_
+
+#include "Protocol.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+class BuildSystem {
+public:
+  virtual ~BuildSystem() = default;
+
+  virtual llvm::Expected>
+  getOwningTarget(llvm::StringRef FilePath) const = 0;
+
+  virtual llvm::Expected
+  addDependency(llvm::StringRef FromTarget, llvm::StringRef ToTarget) const = 0;
+};
+
+class BuildSystemPlugin {
+public:
+  virtual ~BuildSystemPlugin() = default;
+
+  virtual std::unique_ptr
+  createForDirectory(llvm::StringRef Dir) const = 0;
+};
+using BuildSystemRegistry = llvm::Registry;
+
+class BuildSystemProvider {
+public:
+  const BuildSystem *get(llvm::StringRef Path);
+
+private:
+  // Keyed by absolute paths.
+  // We can hand out pointers as they're stable and entries are never removed.
+  mutable llvm::StringMap> DirCaches;
+  mutable std::mutex DirCachesMutex;
+};
+} // namespace clangd
+} // namespace clang
+#endif
Index: clang-tools-extra/clangd/BuildSystem.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/BuildSystem.cpp
@@ -0,0 +1,43 @@
+//===--- BuildSystem.cpp -*- 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
+//
+//===--===//
+#include "BuildSystem.h"
+#include "support/Path.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+const BuildSystem *BuildSystemProvider::get(llvm::StringRef Path) {
+  std::vector SearchDirs;
+  actOnAllParentDirectories(Path, [&](PathRef Dir) {
+SearchDirs.push_back(Dir);
+return false;
+  });
+  std::lock_guard Lock(DirCachesMutex);
+  for (PathRef Dir : SearchDirs) {
+auto Entry = DirCaches.try_emplace(Dir, nullptr);
+auto &Value = Entry.first->getValue();
+if (Entry.second) {
+  for (const auto &BSP : BuildSystemRegistry::entries()) {
+Value = BSP.instantiate()->createForDirectory(Dir);
+if (Value)
+  break;
+  }
+}
+if (Value)
+  return Value.get();
+  }
+  return nullptr;
+}
+
+} // namespace clangd
+} // namespace clang
+
+LLVM_INSTANTIATE_REGISTRY(clang::clangd::BuildSystemRegistry);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96125: [clangd] Diagfixer for layering violations

2021-02-05 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Introduce a diagfixer that can update build system files in the face of
layering violation warnings.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96125

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h


Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H
 
+#include "BuildSystem.h"
 #include "Protocol.h"
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
@@ -76,6 +77,7 @@
   std::string Message;
   /// TextEdits from clang's fix-its. Must be non-empty.
   llvm::SmallVector Edits;
+  llvm::Optional Cmd;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Fix &F);
 
@@ -168,6 +170,8 @@
 /// (This strips err_ and -W prefix so we can match with or without them.)
 llvm::StringRef normalizeSuppressedCode(llvm::StringRef);
 
+StoreDiags::DiagFixer missingDependencyFixer(const BuildSystem *BS);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -29,6 +29,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Capacity.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/Signals.h"
@@ -368,12 +369,17 @@
 }
 
 CodeAction toCodeAction(const Fix &F, const URIForFile &File) {
+  assert(!F.Edits.empty() || F.Cmd.hasValue());
   CodeAction Action;
   Action.title = F.Message;
   Action.kind = std::string(CodeAction::QUICKFIX_KIND);
-  Action.edit.emplace();
-  Action.edit->changes.emplace();
-  (*Action.edit->changes)[File.uri()] = {F.Edits.begin(), F.Edits.end()};
+  if (!F.Edits.empty()) {
+Action.edit.emplace();
+Action.edit->changes.emplace();
+(*Action.edit->changes)[File.uri()] = {F.Edits.begin(), F.Edits.end()};
+  }
+  if (F.Cmd)
+Action.command = *F.Cmd;
   return Action;
 }
 
@@ -819,5 +825,37 @@
   return Code;
 }
 
+StoreDiags::DiagFixer missingDependencyFixer(const BuildSystem *BS) {
+  return [BS](DiagnosticsEngine::Level,
+  const clang::Diagnostic &D) -> std::vector {
+if (D.getID() != clang::diag::err_undeclared_use_of_module)
+  return {};
+clang::clangd::trace::Span Span("DiagFixerDependencyInserter");
+auto FromModule = D.getArgStdStr(0);
+auto ToModule = BS->getOwningTarget(D.getArgStdStr(1));
+if (!ToModule) {
+  clang::clangd::elog("Couldn't find owning module for {0}: {1}",
+  D.getArgStdStr(1), ToModule.takeError());
+  return {};
+}
+// Rather than generating the edit here, we can defer that to diagnostic
+// resolve time (at the cost of false positives, when BUILD file can't be
+// edited).
+auto Edit = BS->addDependency(FromModule, ToModule->front());
+if (!Edit) {
+  clang::clangd::elog("Couldn't insert dep from {0} to {1}: {2}",
+  FromModule, ToModule->front(), Edit.takeError());
+  return {};
+}
+Fix F;
+F.Cmd.emplace();
+F.Cmd->title =
+llvm::formatv("Add deps {0} to {1}", ToModule->front(), FromModule);
+F.Cmd->workspaceEdit = std::move(*Edit);
+F.Cmd->command = Command::CLANGD_APPLY_FIX_COMMAND.str();
+F.Message = F.Cmd->title;
+return {std::move(F)};
+  };
+}
 } // namespace clangd
 } // namespace clang


Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H
 
+#include "BuildSystem.h"
 #include "Protocol.h"
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
@@ -76,6 +77,7 @@
   std::string Message;
   /// TextEdits from clang's fix-its. Must be non-empty.
   llvm::SmallVector Edits;
+  llvm::Optional Cmd;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Fix &F);
 
@@ -168,6 +170,8 @@
 /// (This strips err_ and -W prefix so we can match with or without them.)
 llvm::StringRef normalizeSuppressedCode(llvm::StringRef);
 
+StoreDiags::DiagFixer missingDependencyFixer(const BuildSystem *BS);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/Diagnostics.cpp
===

[PATCH] D96126: [clangd] Integrate BSP with ClangdServer

2021-02-05 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96126

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/Preamble.cpp


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -326,6 +326,8 @@
   trace::Span Tracer("BuildPreamble");
   SPAN_ATTACH(Tracer, "File", FileName);
   StoreDiags PreambleDiagnostics;
+  if (Inputs.BS)
+PreambleDiagnostics.contributeFixes(missingDependencyFixer(Inputs.BS));
   llvm::IntrusiveRefCntPtr PreambleDiagsEngine =
   CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(),
   &PreambleDiagnostics, false);
Index: clang-tools-extra/clangd/Compiler.h
===
--- clang-tools-extra/clangd/Compiler.h
+++ clang-tools-extra/clangd/Compiler.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
 
+#include "BuildSystem.h"
 #include "GlobalCompilationDatabase.h"
 #include "TidyProvider.h"
 #include "index/Index.h"
@@ -54,6 +55,7 @@
   const SymbolIndex *Index = nullptr;
   ParseOptions Opts = ParseOptions();
   TidyProviderRef ClangTidyProvider = {};
+  const BuildSystem *BS = nullptr;
 };
 
 /// Builds compiler invocation that could be used to build AST or preamble.
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -359,6 +359,7 @@
   std::unique_ptr BackgroundIdx;
   // Storage for merged views of the various indexes.
   std::vector> MergedIdx;
+  BuildSystemProvider BSP;
 
   // When set, provides clang-tidy options for a specific file.
   TidyProviderRef ClangTidyProvider;
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -195,6 +195,7 @@
   Inputs.Opts = std::move(Opts);
   Inputs.Index = Index;
   Inputs.ClangTidyProvider = ClangTidyProvider;
+  Inputs.BS = BSP.get(File);
   bool NewFile = WorkScheduler.update(File, Inputs, WantDiags);
   // If we loaded Foo.h, we want to make sure Foo.cpp is indexed.
   if (NewFile && BackgroundIdx)


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -326,6 +326,8 @@
   trace::Span Tracer("BuildPreamble");
   SPAN_ATTACH(Tracer, "File", FileName);
   StoreDiags PreambleDiagnostics;
+  if (Inputs.BS)
+PreambleDiagnostics.contributeFixes(missingDependencyFixer(Inputs.BS));
   llvm::IntrusiveRefCntPtr PreambleDiagsEngine =
   CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(),
   &PreambleDiagnostics, false);
Index: clang-tools-extra/clangd/Compiler.h
===
--- clang-tools-extra/clangd/Compiler.h
+++ clang-tools-extra/clangd/Compiler.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
 
+#include "BuildSystem.h"
 #include "GlobalCompilationDatabase.h"
 #include "TidyProvider.h"
 #include "index/Index.h"
@@ -54,6 +55,7 @@
   const SymbolIndex *Index = nullptr;
   ParseOptions Opts = ParseOptions();
   TidyProviderRef ClangTidyProvider = {};
+  const BuildSystem *BS = nullptr;
 };
 
 /// Builds compiler invocation that could be used to build AST or preamble.
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -359,6 +359,7 @@
   std::unique_ptr BackgroundIdx;
   // Storage for merged views of the various indexes.
   std::vector> MergedIdx;
+  BuildSystemProvider BSP;
 
   // When set, provides clang-tidy options for a specific file.
   TidyProviderRef ClangTidyProvider;
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -195,6 +195,7 @@
   Inputs.Opts = std::move(Opts);
   Inputs.Index = Index;
   Inputs.ClangTidyProvider = ClangTidyProvider;
+  Inputs.BS = BSP.get(File);
   bool NewFile = WorkScheduler.updat

[PATCH] D96082: [clang-tidy] Add 'readability-useless-return-value' check

2021-02-05 Thread Lukas Hänel via Phabricator via cfe-commits
LukasHanel marked 9 inline comments as done.
LukasHanel added a comment.

Thanks for the review!




Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability-useless-return-value.rst:43
+int ret = 0;
+return;
+  }

Eugene.Zelenko wrote:
> Return is redundant. See readability-redundant-control-flow.
My new checker will not remove the return statement. I added a new comment to 
the readme to recommend usage of the other checker as well.
Should I extend the fix-it to remove also the `return` statement?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96082

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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2021-02-05 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

In D93298#2544459 , @StephenFan wrote:

> According to  @jrtc27 's review that is 
> "As for Zfinx itself, well, the idea is fine, but I really detest the way 
> it's being done as an extension to F/D/Zfh. Running F code on an FZfh core 
> _does not work_ so it is not an _extension_. Instead it should really be a 
> set of separate extensions to I/E that conflict with F/D/Zfh, i.e. Zfinx, 
> Zdinx and Zfhinx, but apparently asking code that complies with a ratified 
> standard to change itself in order to not break when a new extension is 
> introduced is a-ok in the RISC-V world.". 
> We split the Zfinx into 3 separate extensions which is Zfinx, Zdinx, and 
> Zfhinx.

Ah I see. I interpreted jrtc27's comment as a general gripe about the spec 
(which perhaps could be relayed to those working on the zfinx spec) rather as a 
direction for changing this patch in particular. Anyway, it's a detail that 
shouldn't affect an initial review. Thanks for clarifying.


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

https://reviews.llvm.org/D93298

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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2021-02-05 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D93298#2544775 , @asb wrote:

> In D93298#2544459 , @StephenFan 
> wrote:
>
>> According to  @jrtc27 's review that is 
>> "As for Zfinx itself, well, the idea is fine, but I really detest the way 
>> it's being done as an extension to F/D/Zfh. Running F code on an FZfh core 
>> _does not work_ so it is not an _extension_. Instead it should really be a 
>> set of separate extensions to I/E that conflict with F/D/Zfh, i.e. Zfinx, 
>> Zdinx and Zfhinx, but apparently asking code that complies with a ratified 
>> standard to change itself in order to not break when a new extension is 
>> introduced is a-ok in the RISC-V world.". 
>> We split the Zfinx into 3 separate extensions which is Zfinx, Zdinx, and 
>> Zfhinx.
>
> Ah I see. I interpreted jrtc27's comment as a general gripe about the spec 
> (which perhaps could be relayed to those working on the zfinx spec) rather as 
> a direction for changing this patch in particular. Anyway, it's a detail that 
> shouldn't affect an initial review. Thanks for clarifying.

Well, it was "I'm uneasy about accepting a patch adding an extension that is 
fundamentally flawed in its current form" (unlike some of the others where 
they're subject to change but don't _break_ anything).


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

https://reviews.llvm.org/D93298

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


[PATCH] D96082: [clang-tidy] Add 'readability-useless-return-value' check

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

@Eugene.Zelenko Why did you remove me from the reviewers list?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96082

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


[PATCH] D96016: Release notes: Deprecate the clang-cl /fallback flag (patch for the release/12.x branch)

2021-02-05 Thread Hans Wennborg via Phabricator via cfe-commits
hans closed this revision.
hans added a comment.

Pushed as 72f12467ded52160d52025e13a6217f00fe25f68 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96016

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


[PATCH] D94880: Add clang-query support for mapAnyOf

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

@aaron.ballman Any further comments?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94880

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


[PATCH] D95951: [OpenCL] Add cl_khr_subgroup_non_uniform_arithmetic to TableGen BIFs

2021-02-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks




Comment at: clang/lib/Sema/OpenCLBuiltins.td:1529
+  foreach name = ["reduce_", "scan_exclusive_", "scan_inclusive_"] in {
+foreach op = ["add", "min", "max", "mul"] in {
+  def : Builtin<"sub_group_non_uniform_" # name # op, [AGenType1, 
AGenType1]>;

There is a bit of repetition with FuncExtKhrSubgroups but I guess it's not 
worth creating common patterns?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95951

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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2021-02-05 Thread luxufan via Phabricator via cfe-commits
StephenFan added a comment.

In D93298#2544775 , @asb wrote:

> In D93298#2544459 , @StephenFan 
> wrote:
>
>> According to  @jrtc27 's review that is 
>> "As for Zfinx itself, well, the idea is fine, but I really detest the way 
>> it's being done as an extension to F/D/Zfh. Running F code on an FZfh core 
>> _does not work_ so it is not an _extension_. Instead it should really be a 
>> set of separate extensions to I/E that conflict with F/D/Zfh, i.e. Zfinx, 
>> Zdinx and Zfhinx, but apparently asking code that complies with a ratified 
>> standard to change itself in order to not break when a new extension is 
>> introduced is a-ok in the RISC-V world.". 
>> We split the Zfinx into 3 separate extensions which is Zfinx, Zdinx, and 
>> Zfhinx.
>
> Ah I see. I interpreted jrtc27's comment as a general gripe about the spec 
> (which perhaps could be relayed to those working on the zfinx spec) rather as 
> a direction for changing this patch in particular. Anyway, it's a detail that 
> shouldn't affect an initial review. Thanks for clarifying.

Oh, I'm sorry. It seems that I misunderstood @jrtc27 's comment. I will merge 
the Zfinx, Zdinx, Zfhinx into Zfinx if this patch is ready for accepting.


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

https://reviews.llvm.org/D93298

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


[PATCH] D94880: Add clang-query support for mapAnyOf

2021-02-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D94880#2544782 , @steveire wrote:

> @aaron.ballman Any further comments?

Thank you for pinging, this fell off my queue! The only further comments I have 
about about my confusion with `with`.

In D94880#2536485 , @steveire wrote:

> In D94880#2536399 , @aaron.ballman 
> wrote:
>
>> I think there should be some documentation change for the new `with` 
>> functionality.
>
> It's already documented in 
> https://clang.llvm.org/docs/LibASTMatchersReference.html , just like all the 
> other functionality.

Perhaps I'm blind, but when I search for "with" on that page, I get 21 hits and 
none of them are about the `with()` function. I am not finding evidence of 
`with` being supported on ToT, can you point me to the existing implementation? 
(If the functionality isn't being introduced in this patch, you don't need to 
document as part of this work. However, I was under the impression you were 
adding this functionality, so I'd like to understand this situation better 
before approving.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94880

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


[PATCH] D95951: [OpenCL] Add cl_khr_subgroup_non_uniform_arithmetic to TableGen BIFs

2021-02-05 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:1529
+  foreach name = ["reduce_", "scan_exclusive_", "scan_inclusive_"] in {
+foreach op = ["add", "min", "max", "mul"] in {
+  def : Builtin<"sub_group_non_uniform_" # name # op, [AGenType1, 
AGenType1]>;

Anastasia wrote:
> There is a bit of repetition with FuncExtKhrSubgroups but I guess it's not 
> worth creating common patterns?
Indeed there is some overlap, but factoring out commonality would increase 
complexity.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95951

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


[PATCH] D96082: [clang-tidy] Add 'readability-useless-return-value' check

2021-02-05 Thread Nathan James via Phabricator via cfe-commits
njames93 requested changes to this revision.
njames93 added a comment.
This revision now requires changes to proceed.

This check, more specifically the fixes, seem quite dangerous. Changing 
function signatures is highly likely to cause compilation issues. 
For a starters this check doesn't appear to examine call sites of the function 
to ensure they don't use the return value.
There's also the case where the function is used as a callback, this can't 
change the signature as the callback type would then mismatch.
From these 2 issues, this shouldn't trigger on functions with external linkage.

There's the case where the return value is based on some preprocessor constant. 
You are showing how it handles NULL and EXIT_SUCCESS, however what if the macro 
is called BUILT_WITH_FEATURE_X, that's likely a build setting and shouldn't be 
triggered upon. Obviously there's no hard and fast way to determine what's a 
dependent macro and what isn't, so either never trigger on returns where the 
value is a macro, or have a list of allowed macros, defaulted to containing the 
likes of NULL.

With all being said, I feel that while the diagnosing of these functions can 
have some value, an automated fix probably isn't a good idea.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96082

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


[clang] 3fe3946 - [ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitly

2021-02-05 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2021-02-05T05:55:18-08:00
New Revision: 3fe3946d9a958b7af6130241996d9cfcecf559d4

URL: 
https://github.com/llvm/llvm-project/commit/3fe3946d9a958b7af6130241996d9cfcecf559d4
DIFF: 
https://github.com/llvm/llvm-project/commit/3fe3946d9a958b7af6130241996d9cfcecf559d4.diff

LOG: [ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitly
emitting retainRV or claimRV calls in the IR

Background:

This patch makes changes to the front-end and middle-end that are
needed to fix a longstanding problem where llvm breaks ARC's autorelease
optimization (see the link below) by separating calls from the marker
instructions or retainRV/claimRV calls. The backend changes are in
https://reviews.llvm.org/D92569.

https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue

What this patch does to fix the problem:

- The front-end adds operand bundle "clang.arc.rv" to calls, which
  indicates the call is implicitly followed by a marker instruction and
  an implicit retainRV/claimRV call that consumes the call result. In
  addition, it emits a call to @llvm.objc.clang.arc.noop.use, which
  consumes the call result, to prevent the middle-end passes from changing
  the return type of the called function. This is currently done only when
  the target is arm64 and the optimization level is higher than -O0.

- ARC optimizer temporarily emits retainRV/claimRV calls after the calls
  with the operand bundle in the IR and removes the inserted calls after
  processing the function.

- ARC contract pass emits retainRV/claimRV calls after the call with the
  operand bundle. It doesn't remove the operand bundle on the call since
  the backend needs it to emit the marker instruction. The retainRV and
  claimRV calls are emitted late in the pipeline to prevent optimization
  passes from transforming the IR in a way that makes it harder for the
  ARC middle-end passes to figure out the def-use relationship between
  the call and the retainRV/claimRV calls (which is the cause of
  PR31925).

- The function inliner removes an autoreleaseRV call in the callee if
  nothing in the callee prevents it from being paired up with the
  retainRV/claimRV call in the caller. It then inserts a release call if
  the call is annotated with claimRV since autoreleaseRV+claimRV is
  equivalent to a release. If it cannot find an autoreleaseRV call, it
  tries to transfer the operand bundle to a function call in the callee.
  This is important since ARC optimizer can remove the autoreleaseRV
  returning the callee result, which makes it impossible to pair it up
  with the retainRV/claimRV call in the caller. If that fails, it simply
  emits a retain call in the IR if the implicit call is a call to
  retainRV and does nothing if it's a call to claimRV.

Future work:

- Use the operand bundle on x86-64.

- Fix the auto upgrader to convert call+retainRV/claimRV pairs into
  calls annotated with the operand bundles.

rdar://71443534

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

Added: 
clang/test/CodeGenObjC/arc-rv-attr.m
llvm/include/llvm/Analysis/ObjCARCUtil.h
llvm/test/Transforms/Inline/inline-retainRV-call.ll
llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
llvm/test/Transforms/TailCallElim/operand-bundles.ll

Modified: 
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGenObjC/arc-unsafeclaim.m
llvm/docs/LangRef.rst
llvm/include/llvm/IR/InstrTypes.h
llvm/include/llvm/IR/Intrinsics.td
llvm/include/llvm/IR/LLVMContext.h
llvm/lib/Analysis/ObjCARCInstKind.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/IR/LLVMContext.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
llvm/lib/Transforms/ObjCARC/ObjCARC.h
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
llvm/lib/Transforms/ObjCARC/PtrState.cpp
llvm/lib/Transforms/ObjCARC/PtrState.h
llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Bitcode/operand-bundles-bc-analyzer.ll
llvm/test/CodeGen/AArch64/call-rv-marker.ll
llvm/test/Transforms/DeadArgElim/deadretval.ll
llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
llvm/test/Transforms/ObjCARC/contract.ll
llvm/test/Transforms/ObjCARC/intrinsic-use.ll
llvm/test/Transforms/ObjCARC/rv.ll

Removed: 
llvm/test/Transforms/TailCallElim/deopt-bundle.ll



diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 3f930c76fe0a..ab3fba615335 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@

[PATCH] D92808: [ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitly emitting retainRV or claimRV calls in the IR

2021-02-05 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3fe3946d9a95: [ObjC][ARC] Use operand bundle 
'clang.arc.rv' instead of explicitly (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGenObjC/arc-rv-attr.m
  clang/test/CodeGenObjC/arc-unsafeclaim.m
  llvm/docs/LangRef.rst
  llvm/include/llvm/Analysis/ObjCARCUtil.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/LLVMContext.h
  llvm/lib/Analysis/ObjCARCInstKind.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/LLVMContext.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
  llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
  llvm/lib/Transforms/ObjCARC/ObjCARC.h
  llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
  llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
  llvm/lib/Transforms/ObjCARC/PtrState.cpp
  llvm/lib/Transforms/ObjCARC/PtrState.h
  llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/Bitcode/operand-bundles-bc-analyzer.ll
  llvm/test/CodeGen/AArch64/call-rv-marker.ll
  llvm/test/Transforms/DeadArgElim/deadretval.ll
  llvm/test/Transforms/Inline/inline-retainRV-call.ll
  llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
  llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
  llvm/test/Transforms/ObjCARC/contract.ll
  llvm/test/Transforms/ObjCARC/intrinsic-use.ll
  llvm/test/Transforms/ObjCARC/rv.ll
  llvm/test/Transforms/TailCallElim/deopt-bundle.ll
  llvm/test/Transforms/TailCallElim/operand-bundles.ll

Index: llvm/test/Transforms/TailCallElim/operand-bundles.ll
===
--- llvm/test/Transforms/TailCallElim/operand-bundles.ll
+++ llvm/test/Transforms/TailCallElim/operand-bundles.ll
@@ -55,3 +55,13 @@
 exit:
   ret void
 }
+
+; CHECK-LABEL: @test_clang_arc_rv(
+; CHECK: tail call i8* @getObj(
+
+declare i8* @getObj()
+
+define i8* @test_clang_arc_rv() {
+  %r = call i8* @getObj() [ "clang.arc.rv"(i64 0) ]
+  ret i8* %r
+}
Index: llvm/test/Transforms/ObjCARC/rv.ll
===
--- llvm/test/Transforms/ObjCARC/rv.ll
+++ llvm/test/Transforms/ObjCARC/rv.ll
@@ -452,6 +452,29 @@
   ret i8* %v3
 }
 
+; Remove operand bundle "clang.arc.rv" and the autoreleaseRV call if the call
+; is a tail call.
+
+; CHECK-LABEL: define i8* @test31(
+; CHECK: %[[CALL:.*]] = tail call i8* @returner()
+; CHECK: ret i8* %[[CALL]]
+
+define i8* @test31() {
+  %call = tail call i8* @returner() [ "clang.arc.rv"(i64 0) ]
+  %1 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %1
+}
+
+; CHECK-LABEL: define i8* @test32(
+; CHECK: %[[CALL:.*]] = call i8* @returner() [ "clang.arc.rv"(i64 0) ]
+; CHECK: call i8* @llvm.objc.autoreleaseReturnValue(i8* %[[CALL]])
+
+define i8* @test32() {
+  %call = call i8* @returner() [ "clang.arc.rv"(i64 0) ]
+  %1 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %1
+}
+
 !0 = !{}
 
 ; CHECK: attributes [[NUW]] = { nounwind }
Index: llvm/test/Transforms/ObjCARC/intrinsic-use.ll
===
--- llvm/test/Transforms/ObjCARC/intrinsic-use.ll
+++ llvm/test/Transforms/ObjCARC/intrinsic-use.ll
@@ -8,8 +8,10 @@
 declare i8* @llvm.objc.autorelease(i8*)
 
 declare void @llvm.objc.clang.arc.use(...)
+declare void @llvm.objc.clang.arc.noop.use(...)
 
 declare void @test0_helper(i8*, i8**)
+declare void @can_release(i8*)
 
 ; Ensure that we honor clang.arc.use as a use and don't miscompile
 ; the reduced test case from .
@@ -108,6 +110,21 @@
   ret void
 }
 
+; ARC optimizer should be able to safely remove the retain/release pair as the
+; call to @llvm.objc.clang.arc.noop.use is a no-op.
+
+; CHECK-LABEL: define void @test_arc_noop_use(
+; CHECK-NEXT:call void @can_release(i8* %x)
+; CHECK-NEXT:call void (...) @llvm.objc.clang.arc.noop.use(
+; CHECK-NEXT:ret void
+
+define void @test_arc_noop_use(i8** %out, i8* %x) {
+  call i8* @llvm.objc.retain(i8* %x)
+  call void @can_release(i8* %x)
+  call void (...) @llvm.objc.clang.arc.noop.use(i8* %x)
+  call void @llvm.objc.release(i8* %x), !clang.imprecise_release !0
+  ret void
+}
 
 !0 = !{}
 
Index: llvm/test/Transforms/ObjCARC/contract.ll
===
--- llvm/test/Transforms/ObjCARC/contract.ll
+++ llvm/test/Transforms/ObjCARC/contract.ll
@@ -227,7 +227,15 @@
   ret void
 }
 
+; CHECK-LABEL: define void @test14(
+; CHECK-NOT: clang.arc.noop.use
+; CHECK: ret void
+define

[PATCH] D96130: Correct swift_bridge duplicate attribute warning logic

2021-02-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added a reviewer: compnerd.
aaron.ballman requested review of this revision.
Herald added a project: clang.

The `swift_bridge` attribute warns when the attribute is applied multiple times 
to the same declaration. However, it warns about the arguments being different 
to the attribute without ever checking if the arguments actually are different. 
If the arguments are different, diagnose, otherwise silently accept the code. 
Either way, drop the duplicated attribute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96130

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/attr-swift_bridge.m


Index: clang/test/SemaObjC/attr-swift_bridge.m
===
--- clang/test/SemaObjC/attr-swift_bridge.m
+++ clang/test/SemaObjC/attr-swift_bridge.m
@@ -31,3 +31,8 @@
 typedef NSArray *NSArrayAlias __attribute__((__swift_bridge__("ArrayAlias")));
 
 struct __attribute__((__swift_bridge__("StructT"))) T {};
+
+// Duplicate attributes with the same arguments are fine.
+struct __attribute__((swift_bridge("foo"), swift_bridge("foo"))) S;
+// Duplicate attributes with different arguments are not.
+struct __attribute__((swift_bridge("foo"), swift_bridge("bar"))) S; // 
expected-warning {{attribute 'swift_bridge' is already applied with different 
arguments}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5751,9 +5751,11 @@
   if (!S.checkStringLiteralArgumentAttr(AL, 0, BT))
 return;
 
-  // Don't duplicate annotations that are already set.
-  if (D->hasAttr()) {
-S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
+  // Warn about duplicate attributes if they have different arguments, but drop
+  // any duplicate attributes regardless.
+  if (const auto *Other = D->getAttr()) {
+if (Other->getSwiftType() != BT)
+  S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
 return;
   }
 


Index: clang/test/SemaObjC/attr-swift_bridge.m
===
--- clang/test/SemaObjC/attr-swift_bridge.m
+++ clang/test/SemaObjC/attr-swift_bridge.m
@@ -31,3 +31,8 @@
 typedef NSArray *NSArrayAlias __attribute__((__swift_bridge__("ArrayAlias")));
 
 struct __attribute__((__swift_bridge__("StructT"))) T {};
+
+// Duplicate attributes with the same arguments are fine.
+struct __attribute__((swift_bridge("foo"), swift_bridge("foo"))) S;
+// Duplicate attributes with different arguments are not.
+struct __attribute__((swift_bridge("foo"), swift_bridge("bar"))) S; // expected-warning {{attribute 'swift_bridge' is already applied with different arguments}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5751,9 +5751,11 @@
   if (!S.checkStringLiteralArgumentAttr(AL, 0, BT))
 return;
 
-  // Don't duplicate annotations that are already set.
-  if (D->hasAttr()) {
-S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
+  // Warn about duplicate attributes if they have different arguments, but drop
+  // any duplicate attributes regardless.
+  if (const auto *Other = D->getAttr()) {
+if (Other->getSwiftType() != BT)
+  S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
 return;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96051: [OpenCL] Support enum and typedef args in TableGen BIFs

2021-02-05 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl:38
+typedef uint cl_mem_fence_flags;
+#define CLK_GLOBAL_MEM_FENCE   0x02
+

Anastasia wrote:
> Should we add this conditionally if the base header is not included?
> 
> In the subsequent patches where you will add other functions, we should make 
> sure that the base header indeed contains the declarations we use in tablegen.
> Should we add this conditionally if the base header is not included?

It is already inside an `#ifdef NO_HEADER`, see line 21.

> In the subsequent patches where you will add other functions, we should make 
> sure that the base header indeed contains the declarations we use in tablegen.

Not sure what you mean...  When we test a builtin function that relies on an 
enum or typedef from the base header, Sema won't succeed if the enum or typedef 
isn't available.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:727
+  }
+  return S.Context.getEnumType(Result.getAsSingle());
+}

Anastasia wrote:
> I think we should add an assert that Result.getAsSingle() indeed 
> holds. Consider if instead of using base header the types are defined 
> manually and they are regular integers, not enums.
That is a good point.  I think it would be even better to handle such a case 
properly with a diagnostic, and not rely on just an assert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96051

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


[PATCH] D94661: [clang-format] [PR19056] Add support for access modifiers indentation

2021-02-05 Thread Jakub Budiský via Phabricator via cfe-commits
Budovi updated this revision to Diff 321724.
Budovi added a comment.

Changes:

- Added a unit test with a different `IndentWidth`
- Removed a unit test that contained a class nested in function; didn't add 
much IMHO
- Added brief comments about potentially non-obvious behaviour to some tests


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

https://reviews.llvm.org/D94661

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15453,6 +15453,7 @@
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
+  CHECK_PARSE_BOOL(IndentAccessModifiers);
   CHECK_PARSE_BOOL(IndentCaseLabels);
   CHECK_PARSE_BOOL(IndentCaseBlocks);
   CHECK_PARSE_BOOL(IndentGotoLabels);
@@ -19050,6 +19051,57 @@
 "}",
 format(Source, Style));
 }
+
+TEST_F(FormatTest, IndentAccessModifiers) {
+  FormatStyle Style = getLLVMStyle();
+  Style.IndentAccessModifiers = true;
+  // Members are *two* levels below the record;
+  // Style.IndentWidth == 2, thus yielding a 4 spaces wide indentation
+  verifyFormat("class C {\n"
+   "int i;\n"
+   "};\n",
+   Style);
+  verifyFormat("union C {\n"
+   "int i;\n"
+   "unsigned u;\n"
+   "};\n",
+   Style);
+  // Access modifiers should be indented one level below the record
+  verifyFormat("class C {\n"
+   "  public:\n"
+   "int i;\n"
+   "};\n",
+   Style);
+  verifyFormat("struct S {\n"
+   "  private:\n"
+   "class C {\n"
+   "int j;\n"
+   "\n"
+   "  public:\n"
+   "C();\n"
+   "};\n"
+   "\n"
+   "  public:\n"
+   "int i;\n"
+   "};\n",
+   Style);
+  // Enumerations are not records and should be unaffected
+  Style.AllowShortEnumsOnASingleLine = false;
+  verifyFormat("enum class E\n"
+   "{\n"
+   "  A,\n"
+   "  B\n"
+   "};\n",
+   Style);
+  // Test with a different indentation width;
+  // also proves that the result is Style.AccessModifierOffset agonistic
+  Style.IndentWidth = 3;
+  verifyFormat("class C {\n"
+   "   public:\n"
+   "  int i;\n"
+   "};\n",
+   Style);
+}
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -85,7 +85,7 @@
   void reset();
   void parseFile();
   void parseLevel(bool HasOpeningBrace);
-  void parseBlock(bool MustBeDeclaration, bool AddLevel = true,
+  void parseBlock(bool MustBeDeclaration, unsigned AddLevels = 1u,
   bool MunchSemi = true);
   void parseChildBlock();
   void parsePPDirective();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -579,7 +579,7 @@
   return h;
 }
 
-void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
+void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, unsigned AddLevels,
  bool MunchSemi) {
   assert(FormatTok->isOneOf(tok::l_brace, TT_MacroBlockBegin) &&
  "'{' or macro block token expected");
@@ -589,7 +589,7 @@
   size_t PPStartHash = computePPHash();
 
   unsigned InitialLevel = Line->Level;
-  nextToken(/*LevelDifference=*/AddLevel ? 1 : 0);
+  nextToken(/*LevelDifference=*/AddLevels);
 
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
@@ -604,8 +604,7 @@
 
   ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
   MustBeDeclaration);
-  if (AddLevel)
-++Line->Level;
+  Line->Level += AddLevels;
   parseLevel(/*HasOpeningBrace=*/true);
 
   if (eof())
@@ -621,7 +620,7 @@
   size_t PPEndHash = computePPHash();
 
   // Munch the closing brace.
-  nextToken(/*LevelDifference=*/AddLevel ? -1 : 0);
+  nextToken(/*LevelDifference=*/-AddLevels);
 
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
@@ -1125,12 +1124,12 @@
   if (Style.BraceW

[PATCH] D95935: [clang][CodeComplete] Fix crash on ParenListExprs

2021-02-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5173
+  if (auto *PLE = llvm::dyn_cast(Base))
+Base = PLE->getExpr(PLE->getNumExprs() - 1);
+  if (OtherOpBase) {

mention that why we specialize `ParentListExpr` -- ParenListExprs don't have a 
predefined type

I think we won't (hopefully) have a 0-children `ParenListExpr`. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95935

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


[PATCH] D94880: Add clang-query support for mapAnyOf

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

That page collapses the documentation for each matcher, as you know.

You need to expand the docs for `mapAnyOf`, as you know.

You seem to know all this. What's the remaining issue?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94880

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


[clang] 2fbbb18 - Revert "[ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitly"

2021-02-05 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2021-02-05T06:00:05-08:00
New Revision: 2fbbb18c1dbeb124dfc3c2aebae97d4780ff9bd6

URL: 
https://github.com/llvm/llvm-project/commit/2fbbb18c1dbeb124dfc3c2aebae97d4780ff9bd6
DIFF: 
https://github.com/llvm/llvm-project/commit/2fbbb18c1dbeb124dfc3c2aebae97d4780ff9bd6.diff

LOG: Revert "[ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of 
explicitly"

This reverts commit 3fe3946d9a958b7af6130241996d9cfcecf559d4.

The commit violates layering by including a header from Analysis in
lib/IR/AutoUpgrade.cpp.

Added: 
llvm/test/Transforms/TailCallElim/deopt-bundle.ll

Modified: 
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGenObjC/arc-unsafeclaim.m
llvm/docs/LangRef.rst
llvm/include/llvm/IR/InstrTypes.h
llvm/include/llvm/IR/Intrinsics.td
llvm/include/llvm/IR/LLVMContext.h
llvm/lib/Analysis/ObjCARCInstKind.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/IR/LLVMContext.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
llvm/lib/Transforms/ObjCARC/ObjCARC.h
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
llvm/lib/Transforms/ObjCARC/PtrState.cpp
llvm/lib/Transforms/ObjCARC/PtrState.h
llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Bitcode/operand-bundles-bc-analyzer.ll
llvm/test/CodeGen/AArch64/call-rv-marker.ll
llvm/test/Transforms/DeadArgElim/deadretval.ll
llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
llvm/test/Transforms/ObjCARC/contract.ll
llvm/test/Transforms/ObjCARC/intrinsic-use.ll
llvm/test/Transforms/ObjCARC/rv.ll

Removed: 
clang/test/CodeGenObjC/arc-rv-attr.m
llvm/include/llvm/Analysis/ObjCARCUtil.h
llvm/test/Transforms/Inline/inline-retainRV-call.ll
llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
llvm/test/Transforms/TailCallElim/operand-bundles.ll



diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index ab3fba615335..3f930c76fe0a 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -23,7 +23,6 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Analysis/ObjCARCUtil.h"
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/InlineAsm.h"
@@ -2079,15 +2078,6 @@ void 
CodeGenFunction::EmitARCIntrinsicUse(ArrayRef values) {
   EmitNounwindRuntimeCall(fn, values);
 }
 
-/// Emit a call to "clang.arc.noop.use", which consumes the result of a call
-/// that has operand bundle "clang.arc.rv".
-void CodeGenFunction::EmitARCNoopIntrinsicUse(ArrayRef values) {
-  llvm::Function *&fn = CGM.getObjCEntrypoints().clang_arc_noop_use;
-  if (!fn)
-fn = CGM.getIntrinsic(llvm::Intrinsic::objc_clang_arc_noop_use);
-  EmitNounwindRuntimeCall(fn, values);
-}
-
 static void setARCRuntimeFunctionLinkage(CodeGenModule &CGM, llvm::Value *RTF) 
{
   if (auto *F = dyn_cast(RTF)) {
 // If the target runtime doesn't naturally support ARC, emit weak
@@ -2314,11 +2304,10 @@ static void 
emitAutoreleasedReturnValueMarker(CodeGenFunction &CGF) {
 // with this marker yet, so leave a breadcrumb for the ARC
 // optimizer to pick up.
 } else {
-  const char *retainRVMarkerKey = 
llvm::objcarc::getRVMarkerModuleFlagStr();
-  if (!CGF.CGM.getModule().getModuleFlag(retainRVMarkerKey)) {
+  const char *markerKey = "clang.arc.retainAutoreleasedReturnValueMarker";
+  if (!CGF.CGM.getModule().getModuleFlag(markerKey)) {
 auto *str = llvm::MDString::get(CGF.getLLVMContext(), assembly);
-CGF.CGM.getModule().addModuleFlag(llvm::Module::Error,
-  retainRVMarkerKey, str);
+CGF.CGM.getModule().addModuleFlag(llvm::Module::Error, markerKey, str);
   }
 }
   }
@@ -2328,46 +2317,6 @@ static void 
emitAutoreleasedReturnValueMarker(CodeGenFunction &CGF) {
 CGF.Builder.CreateCall(marker, None, CGF.getBundlesForFunclet(marker));
 }
 
-static llvm::Value *emitOptimizedARCReturnCall(llvm::Value *value,
-   bool IsRetainRV,
-   CodeGenFunction &CGF) {
-  emitAutoreleasedReturnValueMarker(CGF);
-
-  // Add operand bundle "clang.arc.rv" to the call instead of emitting retainRV
-  // or claimRV calls in the IR. We currently do this only when the 
optimization
-  // level isn't -O0 since global-isel, which is currently run at -O0, doesn't
-  // know about the operand bundle.
-
-  // FIXME: Do this when the tar

[clang-tools-extra] 2cba22c - [clang-tidy] Simplify implementation of container-size-empty

2021-02-05 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-05T14:03:41Z
New Revision: 2cba22c23a769103f4f0c31968620a488f13b625

URL: 
https://github.com/llvm/llvm-project/commit/2cba22c23a769103f4f0c31968620a488f13b625
DIFF: 
https://github.com/llvm/llvm-project/commit/2cba22c23a769103f4f0c31968620a488f13b625.diff

LOG: [clang-tidy] Simplify implementation of container-size-empty

Use IgnoreUnlessSpelledInSource to make the matcher code smaller and
more visibly-related to the code.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h

clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index cd5e18913214..a1d8064d23a0 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -83,6 +83,9 @@ AST_MATCHER(Expr, usedInBooleanContext) {
   });
   return Result;
 }
+AST_MATCHER(CXXConstructExpr, isDefaultConstruction) {
+  return Node.getConstructor()->isDefaultConstructor();
+}
 } // namespace ast_matchers
 namespace tidy {
 namespace readability {
@@ -116,24 +119,16 @@ void 
ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
   const auto ValidContainer = qualType(
   anyOf(ValidContainerNonTemplateType, ValidContainerTemplateType));
 
-  const auto WrongUse = traverse(
-  TK_AsIs,
-  anyOf(
-  hasParent(binaryOperator(isComparisonOperator(),
-   hasEitherOperand(ignoringImpCasts(
-   anyOf(integerLiteral(equals(1)),
- integerLiteral(equals(0))
-.bind("SizeBinaryOp")),
-  hasParent(implicitCastExpr(
-  hasImplicitDestinationType(booleanType()),
-  anyOf(hasParent(
-unaryOperator(hasOperatorName("!")).bind("NegOnSize")),
-anything(,
-  usedInBooleanContext()));
+  const auto WrongUse =
+  anyOf(hasParent(binaryOperator(
+  isComparisonOperator(),
+  hasEitherOperand(anyOf(integerLiteral(equals(1)),
+ integerLiteral(equals(0)
+  .bind("SizeBinaryOp")),
+usedInBooleanContext());
 
   Finder->addMatcher(
-  cxxMemberCallExpr(unless(isInTemplateInstantiation()),
-on(expr(anyOf(hasType(ValidContainer),
+  cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer),
   hasType(pointsTo(ValidContainer)),
   hasType(references(ValidContainer
.bind("MemberCallObject")),
@@ -157,18 +152,9 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder 
*Finder) {
   .bind("SizeCallExpr"),
   this);
 
-  // Empty constructor matcher.
-  const auto DefaultConstructor = cxxConstructExpr(
-  hasDeclaration(cxxConstructorDecl(isDefaultConstructor(;
   // Comparison to empty string or empty constructor.
   const auto WrongComparend = anyOf(
-  ignoringImpCasts(stringLiteral(hasSize(0))),
-  ignoringImpCasts(cxxBindTemporaryExpr(has(DefaultConstructor))),
-  ignoringImplicit(DefaultConstructor),
-  cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
-   has(expr(ignoringImpCasts(DefaultConstructor,
-  cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isMoveConstructor())),
-   has(expr(ignoringImpCasts(DefaultConstructor,
+  stringLiteral(hasSize(0)), cxxConstructExpr(isDefaultConstruction()),
   cxxUnresolvedConstructExpr(argumentCountIs(0)));
   // Match the object being compared.
   const auto STLArg =
@@ -178,12 +164,11 @@ void 
ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
 expr(hasType(pointsTo(ValidContainer))).bind("Pointee"))),
 expr(hasType(ValidContainer)).bind("STLObject"));
   Finder->addMatcher(
-  binaryOperation(unless(isInTemplateInstantiation()),
-  hasAnyOperatorName("==", "!="),
-  hasOperands(ignoringParenImpCasts(WrongComparend),
-  ignoringParenImpCasts(STLArg)),
-  unless(hasAncestor(cxxMethodDecl(
-  ofClass(equalsBoundNode("container"))
+  binaryOperation(hasAnyOperatorName("==", "!="),
+  hasOperands(WrongComparend,
+  

[PATCH] D91303: [clang-tidy] readability-container-size-empty: simplify implementation

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2cba22c23a76: [clang-tidy] Simplify implementation of 
container-size-empty (authored by stephenkelly).
Herald added a subscriber: nullptr.cpp.

Changed prior to commit:
  https://reviews.llvm.org/D91303?vs=313381&id=321730#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91303

Files:
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp
@@ -477,9 +477,6 @@
 
 struct StructWithLazyNoexcept {
   void func() noexcept(L.size());
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :101:18: note: method 'Lazy'::empty() defined here
-// CHECK-FIXES: {{^  }}void func() noexcept(!L.empty());
 };
 
 #define CHECKSIZE(x) if (x.size()) {}
Index: clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
===
--- clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
+++ clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
@@ -33,6 +33,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace readability
Index: clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -83,6 +83,9 @@
   });
   return Result;
 }
+AST_MATCHER(CXXConstructExpr, isDefaultConstruction) {
+  return Node.getConstructor()->isDefaultConstructor();
+}
 } // namespace ast_matchers
 namespace tidy {
 namespace readability {
@@ -116,24 +119,16 @@
   const auto ValidContainer = qualType(
   anyOf(ValidContainerNonTemplateType, ValidContainerTemplateType));
 
-  const auto WrongUse = traverse(
-  TK_AsIs,
-  anyOf(
-  hasParent(binaryOperator(isComparisonOperator(),
-   hasEitherOperand(ignoringImpCasts(
-   anyOf(integerLiteral(equals(1)),
- integerLiteral(equals(0))
-.bind("SizeBinaryOp")),
-  hasParent(implicitCastExpr(
-  hasImplicitDestinationType(booleanType()),
-  anyOf(hasParent(
-unaryOperator(hasOperatorName("!")).bind("NegOnSize")),
-anything(,
-  usedInBooleanContext()));
+  const auto WrongUse =
+  anyOf(hasParent(binaryOperator(
+  isComparisonOperator(),
+  hasEitherOperand(anyOf(integerLiteral(equals(1)),
+ integerLiteral(equals(0)
+  .bind("SizeBinaryOp")),
+usedInBooleanContext());
 
   Finder->addMatcher(
-  cxxMemberCallExpr(unless(isInTemplateInstantiation()),
-on(expr(anyOf(hasType(ValidContainer),
+  cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer),
   hasType(pointsTo(ValidContainer)),
   hasType(references(ValidContainer
.bind("MemberCallObject")),
@@ -157,18 +152,9 @@
   .bind("SizeCallExpr"),
   this);
 
-  // Empty constructor matcher.
-  const auto DefaultConstructor = cxxConstructExpr(
-  hasDeclaration(cxxConstructorDecl(isDefaultConstructor(;
   // Comparison to empty string or empty constructor.
   const auto WrongComparend = anyOf(
-  ignoringImpCasts(stringLiteral(hasSize(0))),
-  ignoringImpCasts(cxxBindTemporaryExpr(has(DefaultConstructor))),
-  ignoringImplicit(DefaultConstructor),
-  cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
-   has(expr(ignoringImpCasts(DefaultConstructor,
-  cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isMoveConstructor())),
-   has(expr(ignoringImpCasts(DefaultConstructor,
+  stringLiteral(hasSize(0)), cxxConstructExpr(isDefaultC

[PATCH] D80623: WIP: Add an API to simplify setting TraversalKind in clang-tidy matchers

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG538677abbde4: Add an API to simplify setting TraversalKind 
in clang-tidy matchers (authored by stephenkelly).

Changed prior to commit:
  https://reviews.llvm.org/D80623?vs=313386&id=321729#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80623

Files:
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp


Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1036,6 +1036,7 @@
 Callback(Callback) {}
 
 void visitMatch(const BoundNodes& BoundNodesView) override {
+  TraversalKindScope RAII(*Context, Callback->getCheckTraversalKind());
   Callback->run(MatchFinder::MatchResult(BoundNodesView, Context));
 }
 
@@ -1335,7 +1336,10 @@
 
 void MatchFinder::addMatcher(const DeclarationMatcher &NodeMatch,
  MatchCallback *Action) {
-  Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  if (auto TK = Action->getCheckTraversalKind())
+Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+  else
+Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
   Matchers.AllCallbacks.insert(Action);
 }
 
@@ -1347,7 +1351,10 @@
 
 void MatchFinder::addMatcher(const StatementMatcher &NodeMatch,
  MatchCallback *Action) {
-  Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  if (auto TK = Action->getCheckTraversalKind())
+Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+  else
+Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
   Matchers.AllCallbacks.insert(Action);
 }
 
@@ -1436,5 +1443,10 @@
 
 StringRef MatchFinder::MatchCallback::getID() const { return ""; }
 
+llvm::Optional
+MatchFinder::MatchCallback::getCheckTraversalKind() const {
+  return llvm::None;
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -110,6 +110,12 @@
 /// This id is used, for example, for the profiling output.
 /// It defaults to "".
 virtual StringRef getID() const;
+
+/// TraversalKind to use while matching and processing
+/// the result nodes. This API is temporary to facilitate
+/// third parties porting existing code to the default
+/// behavior of clang-tidy.
+virtual llvm::Optional getCheckTraversalKind() const;
   };
 
   /// Called when parsing is finished. Intended for testing only.
@@ -280,6 +286,11 @@
   void run(const MatchFinder::MatchResult &Result) override {
 Nodes.push_back(Result.Nodes);
   }
+
+  llvm::Optional getCheckTraversalKind() const override {
+return llvm::None;
+  }
+
   SmallVector Nodes;
 };
 }


Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1036,6 +1036,7 @@
 Callback(Callback) {}
 
 void visitMatch(const BoundNodes& BoundNodesView) override {
+  TraversalKindScope RAII(*Context, Callback->getCheckTraversalKind());
   Callback->run(MatchFinder::MatchResult(BoundNodesView, Context));
 }
 
@@ -1335,7 +1336,10 @@
 
 void MatchFinder::addMatcher(const DeclarationMatcher &NodeMatch,
  MatchCallback *Action) {
-  Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  if (auto TK = Action->getCheckTraversalKind())
+Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+  else
+Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
   Matchers.AllCallbacks.insert(Action);
 }
 
@@ -1347,7 +1351,10 @@
 
 void MatchFinder::addMatcher(const StatementMatcher &NodeMatch,
  MatchCallback *Action) {
-  Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  if (auto TK = Action->getCheckTraversalKind())
+Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+  else
+Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
   Matchers.AllCallbacks.insert(Action);
 }
 
@@ -1436,5 +1443,10 @@
 
 StringRef MatchFinder::MatchCallback::getID() const { return ""; }
 
+llvm::Optional
+MatchFinder::MatchCallback::getCheckTraversalKind() const {
+  return llvm::None;
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/

[clang] 538677a - Add an API to simplify setting TraversalKind in clang-tidy matchers

2021-02-05 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-05T14:03:40Z
New Revision: 538677abbde4e74795d0bc21a77a3d263893c37d

URL: 
https://github.com/llvm/llvm-project/commit/538677abbde4e74795d0bc21a77a3d263893c37d
DIFF: 
https://github.com/llvm/llvm-project/commit/538677abbde4e74795d0bc21a77a3d263893c37d.diff

LOG: Add an API to simplify setting TraversalKind in clang-tidy matchers

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchFinder.h
clang/lib/ASTMatchers/ASTMatchFinder.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchFinder.h 
b/clang/include/clang/ASTMatchers/ASTMatchFinder.h
index 81125ad8d96d..91024f9425e0 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -110,6 +110,12 @@ class MatchFinder {
 /// This id is used, for example, for the profiling output.
 /// It defaults to "".
 virtual StringRef getID() const;
+
+/// TraversalKind to use while matching and processing
+/// the result nodes. This API is temporary to facilitate
+/// third parties porting existing code to the default
+/// behavior of clang-tidy.
+virtual llvm::Optional getCheckTraversalKind() const;
   };
 
   /// Called when parsing is finished. Intended for testing only.
@@ -280,6 +286,11 @@ class CollectMatchesCallback : public 
MatchFinder::MatchCallback {
   void run(const MatchFinder::MatchResult &Result) override {
 Nodes.push_back(Result.Nodes);
   }
+
+  llvm::Optional getCheckTraversalKind() const override {
+return llvm::None;
+  }
+
   SmallVector Nodes;
 };
 }

diff  --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp 
b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index 58e69bb29df6..9be275a528eb 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1036,6 +1036,7 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
 Callback(Callback) {}
 
 void visitMatch(const BoundNodes& BoundNodesView) override {
+  TraversalKindScope RAII(*Context, Callback->getCheckTraversalKind());
   Callback->run(MatchFinder::MatchResult(BoundNodesView, Context));
 }
 
@@ -1335,7 +1336,10 @@ MatchFinder::~MatchFinder() {}
 
 void MatchFinder::addMatcher(const DeclarationMatcher &NodeMatch,
  MatchCallback *Action) {
-  Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  if (auto TK = Action->getCheckTraversalKind())
+Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+  else
+Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
   Matchers.AllCallbacks.insert(Action);
 }
 
@@ -1347,7 +1351,10 @@ void MatchFinder::addMatcher(const TypeMatcher 
&NodeMatch,
 
 void MatchFinder::addMatcher(const StatementMatcher &NodeMatch,
  MatchCallback *Action) {
-  Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  if (auto TK = Action->getCheckTraversalKind())
+Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+  else
+Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
   Matchers.AllCallbacks.insert(Action);
 }
 
@@ -1436,5 +1443,10 @@ void MatchFinder::registerTestCallbackAfterParsing(
 
 StringRef MatchFinder::MatchCallback::getID() const { return ""; }
 
+llvm::Optional
+MatchFinder::MatchCallback::getCheckTraversalKind() const {
+  return llvm::None;
+}
+
 } // end namespace ast_matchers
 } // end namespace clang



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


[PATCH] D95877: [analyzer] Fix static_cast on pointer-to-member handling

2021-02-05 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:180
 
+bool noRepeatedElements(
+const llvm::ImmutableList &BaseSpecList) {

nit: functions represent actions, in languages verbs act the same way, so it's 
recommended to use verbs in functions (`hasNoRepeatedElements`)

+ `LLVM_MAYBE_UNUSED` because in the build without assertions it would be a 
warning otherwise.



Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:181
+bool noRepeatedElements(
+const llvm::ImmutableList &BaseSpecList) {
+  // First we need to make sure that there are no-repetitions in BaseSpecList

`ImmutableList` is one of those value types that prefers copying for clarity.



Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:184
+  llvm::SmallPtrSet BaseSpecSeen;
+  for (const auto &BaseSpec : BaseSpecList) {
+auto BaseType = BaseSpec->getType();

LLVM Coding Style calls for very limited use of `auto`, so here and the next 
line would be better with actual types.



Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:184
+  llvm::SmallPtrSet BaseSpecSeen;
+  for (const auto &BaseSpec : BaseSpecList) {
+auto BaseType = BaseSpec->getType();

vsavchenko wrote:
> LLVM Coding Style calls for very limited use of `auto`, so here and the next 
> line would be better with actual types.
Let's also reiterate on using functional-style predicates and reimplement it in 
terms of `llvm::all_of` or `llvm::none_of`.



Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:232
+auto ReducedBaseSpecList = CXXBaseListFactory.getEmptyList();
+for (const auto &BaseSpec : BaseSpecList)
+  if (llvm::none_of(

The same thing about `auto`



Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:234
+  if (llvm::none_of(
+  PathRange, [&BaseSpec](const auto &I) -> auto {
+return BaseSpec->getType() == I->getType();

No need



Comment at: clang/test/Analysis/pointer-to-member.cpp:314-333
+// namespace testReinterpretCasting {
+// struct Base {
+//   int field;
+// };
+//
+// struct Derived : public Base {};
+//

Uncomment it, and expect the actual current result.  This is where `TODO` will 
come in handy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95877

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


[PATCH] D94880: Add clang-query support for mapAnyOf

2021-02-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

In D94880#2544873 , @steveire wrote:

> That page collapses the documentation for each matcher, as you know.
>
> You need to expand the docs for `mapAnyOf`, as you know.
>
> You seem to know all this. What's the remaining issue?

The issue was that this was not at all obvious to me as a code reviewer, so I 
was asking you for help. Your response comes across as patronizing, but thank 
you for giving me the information I was looking for. FWIW, I did not know this 
was under the `mapAnyOf` matcher and I was assuming this was going to be 
documented at the top level, just like `bind()`.

LG.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94880

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


[clang] 4a64d8f - [ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitly

2021-02-05 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2021-02-05T06:09:42-08:00
New Revision: 4a64d8fe392449b205e59031aad5424968cf7446

URL: 
https://github.com/llvm/llvm-project/commit/4a64d8fe392449b205e59031aad5424968cf7446
DIFF: 
https://github.com/llvm/llvm-project/commit/4a64d8fe392449b205e59031aad5424968cf7446.diff

LOG: [ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitly
emitting retainRV or claimRV calls in the IR

This reapplies 3fe3946d9a958b7af6130241996d9cfcecf559d4 without the
changes made to lib/IR/AutoUpgrade.cpp, which was violating layering.

Original commit message:

Background:

This patch makes changes to the front-end and middle-end that are
needed to fix a longstanding problem where llvm breaks ARC's autorelease
optimization (see the link below) by separating calls from the marker
instructions or retainRV/claimRV calls. The backend changes are in
https://reviews.llvm.org/D92569.

https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue

What this patch does to fix the problem:

- The front-end adds operand bundle "clang.arc.rv" to calls, which
  indicates the call is implicitly followed by a marker instruction and
  an implicit retainRV/claimRV call that consumes the call result. In
  addition, it emits a call to @llvm.objc.clang.arc.noop.use, which
  consumes the call result, to prevent the middle-end passes from changing
  the return type of the called function. This is currently done only when
  the target is arm64 and the optimization level is higher than -O0.

- ARC optimizer temporarily emits retainRV/claimRV calls after the calls
  with the operand bundle in the IR and removes the inserted calls after
  processing the function.

- ARC contract pass emits retainRV/claimRV calls after the call with the
  operand bundle. It doesn't remove the operand bundle on the call since
  the backend needs it to emit the marker instruction. The retainRV and
  claimRV calls are emitted late in the pipeline to prevent optimization
  passes from transforming the IR in a way that makes it harder for the
  ARC middle-end passes to figure out the def-use relationship between
  the call and the retainRV/claimRV calls (which is the cause of
  PR31925).

- The function inliner removes an autoreleaseRV call in the callee if
  nothing in the callee prevents it from being paired up with the
  retainRV/claimRV call in the caller. It then inserts a release call if
  the call is annotated with claimRV since autoreleaseRV+claimRV is
  equivalent to a release. If it cannot find an autoreleaseRV call, it
  tries to transfer the operand bundle to a function call in the callee.
  This is important since ARC optimizer can remove the autoreleaseRV
  returning the callee result, which makes it impossible to pair it up
  with the retainRV/claimRV call in the caller. If that fails, it simply
  emits a retain call in the IR if the implicit call is a call to
  retainRV and does nothing if it's a call to claimRV.

Future work:

- Use the operand bundle on x86-64.

- Fix the auto upgrader to convert call+retainRV/claimRV pairs into
  calls annotated with the operand bundles.

rdar://71443534

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

Added: 
clang/test/CodeGenObjC/arc-rv-attr.m
llvm/include/llvm/Analysis/ObjCARCUtil.h
llvm/test/Transforms/Inline/inline-retainRV-call.ll
llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
llvm/test/Transforms/TailCallElim/operand-bundles.ll

Modified: 
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGenObjC/arc-unsafeclaim.m
llvm/docs/LangRef.rst
llvm/include/llvm/IR/InstrTypes.h
llvm/include/llvm/IR/Intrinsics.td
llvm/include/llvm/IR/LLVMContext.h
llvm/lib/Analysis/ObjCARCInstKind.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/IR/LLVMContext.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
llvm/lib/Transforms/ObjCARC/ObjCARC.h
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
llvm/lib/Transforms/ObjCARC/PtrState.cpp
llvm/lib/Transforms/ObjCARC/PtrState.h
llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Bitcode/operand-bundles-bc-analyzer.ll
llvm/test/CodeGen/AArch64/call-rv-marker.ll
llvm/test/Transforms/DeadArgElim/deadretval.ll
llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
llvm/test/Transforms/ObjCARC/contract.ll
llvm/test/Transforms/ObjCARC/intrinsic-use.ll
llvm/test/Transforms/ObjCARC/rv.ll

Removed: 
llvm/test/Transforms/TailCallElim/deopt-bundle.ll



diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/l

[PATCH] D94880: Add clang-query support for mapAnyOf

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

In D94880#2544895 , @aaron.ballman 
wrote:

> In D94880#2544873 , @steveire wrote:
>
>> That page collapses the documentation for each matcher, as you know.
>>
>> You need to expand the docs for `mapAnyOf`, as you know.
>>
>> You seem to know all this. What's the remaining issue?
>
> The issue was that this was not at all obvious to me as a code reviewer, so I 
> was asking you for help. Your response comes across as patronizing, but thank 
> you for giving me the information I was looking for. FWIW, I did not know 
> this was under the `mapAnyOf` matcher and I was assuming this was going to be 
> documented at the top level, just like `bind()`.
>
> LG.

You reviewed the patches for `mapAnyOf` up to now and you reviewed this change 
which has unit tests using `with`. I didn't know what was unclear to you.  
Sorry for being terse.

Thanks for the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94880

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


[PATCH] D96131: [clang-tidy] Simplify function complexity check

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, lebedev.ri, xazax.hun.
Herald added a reviewer: lebedev.ri.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update test to note use of lambda instead of the invisible operator().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96131

Files:
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -666,8 +666,8 @@
 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, 
nesting level increased to 2{{$}}
 }
   };
-// CHECK-NOTES: :[[@LINE-6]]:14: warning: function 'operator()' has cognitive 
complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
-// CHECK-NOTES: :[[@LINE-5]]:5: note: +1, including nesting penalty of 0, 
nesting level increased to 1{{$}}
+  // CHECK-NOTES: :[[@LINE-6]]:14: warning: lambda has cognitive complexity of 
1 (threshold 0) [readability-function-cognitive-complexity]
+  // CHECK-NOTES: :[[@LINE-5]]:5: note: +1, including nesting penalty of 0, 
nesting level increased to 1{{$}}
 }
 
 void unittest_b2_09() {
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
===
--- clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
+++ clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
@@ -31,6 +31,9 @@
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   const unsigned Threshold;
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,28 +501,38 @@
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(isDefinition(),
-   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
-isInstantiated(), isWeak(
-  .bind("func"),
-  this);
+  functionDecl(isDefinition(), unless(isWeak())).bind("func"), this);
+  Finder->addMatcher(lambdaExpr().bind("lambda"), this);
 }
 
 void FunctionCognitiveComplexityCheck::check(
 const MatchFinder::MatchResult &Result) {
-  const auto *Func = Result.Nodes.getNodeAs("func");
-  assert(Func->hasBody() && "The matchers should only match the functions that 
"
-"have user-provided body.");
 
   FunctionASTVisitor Visitor;
-  Visitor.TraverseDecl(const_cast(Func), true);
+  SourceLocation Loc;
+
+  const auto *TheDecl = Result.Nodes.getNodeAs("func");
+  const auto *TheLambdaExpr = Result.Nodes.getNodeAs("lambda");
+  if (TheDecl) {
+assert(TheDecl->hasBody() &&
+   "The matchers should only match the functions that "
+   "have user-provided body.");
+Loc = TheDecl->getLocation();
+Visitor.TraverseDecl(const_cast(TheDecl), true);
+  } else {
+Loc = TheLambdaExpr->getBeginLoc();
+Visitor.TraverseLambdaExpr(const_cast(TheLambdaExpr));
+  }
 
   if (Visitor.CC.Total <= Threshold)
 return;
 
-  diag(Func->getLocation(),
-   "function %0 has cognitive complexity of %1 (threshold %2)")
-  << Func << Visitor.CC.Total << Threshold;
+  if (TheDecl)
+diag(Loc, "function %0 has cognitive complexity of %1 (threshold %2)")
+<< TheDecl << Visitor.CC.Total << Threshold;
+  else
+diag(Loc, "lambda has cognitive complexity of %0 (threshold %1)")
+<< Visitor.CC.Total << Threshold;
 
   // Output all the basic increments of complexity.
   for (const auto &Detail : Visitor.CC.Details) {


Index: clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ clang-tools-extra/test/clang-tidy/checke

[PATCH] D96132: [clang-tidy] Simplify throw keyword missing check

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96132

Files:
  clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -94,8 +94,17 @@
 template 
 void f(int i, Exception excToBeThrown) {}
 
+template 
+void templ(int i) {
+  if (i > 0)
+SomeType();
+}
+
 void funcCallWithTempExcTest() {
   f(5, RegularException());
+
+  templ(4);
+  templ(4);
 }
 
 // Global variable initialization test.
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
@@ -29,6 +29,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -21,17 +21,16 @@
   cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
 
   Finder->addMatcher(
-  expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
- cxxTemporaryObjectExpr()),
-   hasType(cxxRecordDecl(
-   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
-   unless(anyOf(hasAncestor(stmt(
-anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-hasAncestor(varDecl()),
-allOf(hasAncestor(CtorInitializerList),
-  unless(hasAncestor(cxxCatchStmt()))
+  cxxConstructExpr(
+  hasType(cxxRecordDecl(
+  isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
+  unless(anyOf(hasAncestor(stmt(
+   anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
+   hasAncestor(varDecl()),
+   allOf(hasAncestor(CtorInitializerList),
+ unless(hasAncestor(cxxCatchStmt()))
   .bind("temporary-exception-not-thrown"),
-  this); 
+  this);
 }
 
 void ThrowKeywordMissingCheck::check(const MatchFinder::MatchResult &Result) {


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -94,8 +94,17 @@
 template 
 void f(int i, Exception excToBeThrown) {}
 
+template 
+void templ(int i) {
+  if (i > 0)
+SomeType();
+}
+
 void funcCallWithTempExcTest() {
   f(5, RegularException());
+
+  templ(4);
+  templ(4);
 }
 
 // Global variable initialization test.
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
@@ -29,6 +29,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -21,17 +21,16 @@
   cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
 
   Finder->addMatcher(
-  expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
- cxxTemporaryObjectExpr()),
-   hasType(cxxRecordDec

[clang] 42e0189 - [OpenCL] Add cl_khr_subgroup_shuffle* to TableGen BIFs

2021-02-05 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-02-05T14:16:13Z
New Revision: 42e018997b23af74eee4acdc0388ae44b36d69f9

URL: 
https://github.com/llvm/llvm-project/commit/42e018997b23af74eee4acdc0388ae44b36d69f9
DIFF: 
https://github.com/llvm/llvm-project/commit/42e018997b23af74eee4acdc0388ae44b36d69f9.diff

LOG: [OpenCL] Add cl_khr_subgroup_shuffle* to TableGen BIFs

Add the builtin functions brought by the cl_khr_subgroup_shuffle and
cl_khr_subgroup_shuffle_relative extensions to
`-fdeclare-opencl-builtins`.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index cad0f57e8051..7c4b81967695 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -55,6 +55,8 @@ def FuncExtNone  : 
FunctionExtension<"">;
 def FuncExtKhrSubgroups  : 
FunctionExtension<"cl_khr_subgroups">;
 def FuncExtKhrSubgroupNonUniformVote : 
FunctionExtension<"cl_khr_subgroup_non_uniform_vote">;
 def FuncExtKhrSubgroupBallot : 
FunctionExtension<"cl_khr_subgroup_ballot">;
+def FuncExtKhrSubgroupShuffle: 
FunctionExtension<"cl_khr_subgroup_shuffle">;
+def FuncExtKhrSubgroupShuffleRelative: 
FunctionExtension<"cl_khr_subgroup_shuffle_relative">;
 def FuncExtKhrGlobalInt32BaseAtomics : 
FunctionExtension<"cl_khr_global_int32_base_atomics">;
 def FuncExtKhrGlobalInt32ExtendedAtomics : 
FunctionExtension<"cl_khr_global_int32_extended_atomics">;
 def FuncExtKhrLocalInt32BaseAtomics  : 
FunctionExtension<"cl_khr_local_int32_base_atomics">;
@@ -1524,10 +1526,16 @@ let Extension = FuncExtKhrSubgroupBallot in {
 // TODO
 
 // Section 38.8.1 - cl_khr_subgroup_shuffle
-// TODO
+let Extension = FuncExtKhrSubgroupShuffle in {
+  def : Builtin<"sub_group_shuffle", [AGenType1, AGenType1, UInt]>;
+  def : Builtin<"sub_group_shuffle_xor", [AGenType1, AGenType1, UInt]>;
+}
 
 // Section 38.9.1 - cl_khr_subgroup_shuffle_relative
-// TODO
+let Extension = FuncExtKhrSubgroupShuffleRelative in {
+  def : Builtin<"sub_group_shuffle_up", [AGenType1, AGenType1, UInt]>;
+  def : Builtin<"sub_group_shuffle_down", [AGenType1, AGenType1, UInt]>;
+}
 
 // Section 38.10.1 - cl_khr_subgroup_clustered_reduce
 // TODO



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


[PATCH] D96135: [clang-tidy] Simplify braced init check

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The normalization of matchers means that this now works in all language
modes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96135

Files:
  clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++14 %s modernize-return-braced-init-list %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++14-or-later %s 
modernize-return-braced-init-list %t
 
 namespace std {
 typedef decltype(sizeof(int)) size_t;
Index: clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
@@ -29,6 +29,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace modernize
Index: clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
@@ -23,21 +23,14 @@
   auto ConstructExpr =
   cxxConstructExpr(
   unless(anyOf(hasDeclaration(cxxConstructorDecl(isExplicit())),
-   isListInitialization(), hasDescendant(initListExpr()),
-   isInTemplateInstantiation(
+   isListInitialization(), hasDescendant(initListExpr()
   .bind("ctor");
 
-  auto CtorAsArgument = materializeTemporaryExpr(anyOf(
-  has(ConstructExpr), has(cxxFunctionalCastExpr(has(ConstructExpr);
-
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   functionDecl(
-   isDefinition(), // Declarations don't have return 
statements.
-   returns(unless(anyOf(builtinType(), autoType(,
-   hasDescendant(returnStmt(hasReturnValue(
-   has(cxxConstructExpr(has(CtorAsArgument)))
-   .bind("fn")),
+  returnStmt(hasReturnValue(ConstructExpr),
+ forFunction(functionDecl(returns(unless(anyOf(builtinType(),
+   autoType()
+ .bind("fn"))),
   this);
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++14 %s modernize-return-braced-init-list %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-return-braced-init-list %t
 
 namespace std {
 typedef decltype(sizeof(int)) size_t;
Index: clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
@@ -29,6 +29,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace modernize
Index: clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
@@ -23,21 +23,14 @@
   auto ConstructExpr =
   cxxConstructExpr(
   unless(anyOf(hasDeclaration(cxxConstructorDecl(isExplicit())),
-   

[PATCH] D86694: [scudo] Allow -fsanitize=scudo on Linux and Windows (WIP, don't land as is)

2021-02-05 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop added a comment.

I believe that the MCJIT failures are due to bug 
https:/bugs.llvm.org/show_bug.cgi?id=24978 rather than a problem in the Scudo 
port so I have added details of how I hit it to that bugzilla and opened two 
reviews to get this landed:
https://reviews.llvm.org/D96120 - [scudo] Port scudo sanitizer to Windows
https://reviews.llvm.org/D96133 - Allow building with scudo memory allocator on 
Windows

Please can you take a look?

I have not added the LLVM_USE_SANITIZER support for scudo from this review. 
-fsanitize adds scudo libraries when the linker is driven from clang, and the 
LLVM cmake build on Windows uses link.exe directly so this doesn't help. And 
scudo sanitizer is planned to go away so I didn't think it made sense to add 
that support on Linux either.


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

https://reviews.llvm.org/D86694

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


[PATCH] D96138: [clang-tidy] Simplify delete null ptr check

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Because it no longer relies on finding implicit casts, this check now
works on templates which are not instantiated in the translation unit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96138

Files:
  clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
  clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.h
  clang-tools-extra/test/clang-tidy/checkers/readability-delete-null-pointer.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-delete-null-pointer.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-delete-null-pointer.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-delete-null-pointer.cpp
@@ -37,6 +37,34 @@
   ti3.foo();
 }
 
+template 
+struct NeverInstantiated {
+  void foo() {
+// t1
+if (mem) // t2
+  delete mem;
+// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 'if' statement is unnecessary;
+// CHECK-FIXES: // t1
+// CHECK-FIXES-NEXT: {{^}}// t2
+// CHECK-FIXES-NEXT: delete mem;
+  }
+  T mem;
+};
+
+template 
+struct NeverInstantiatedPtr {
+  void foo() {
+// t3
+if (mem) // t4
+  delete mem;
+// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 'if' statement is unnecessary;
+// CHECK-FIXES: // t3
+// CHECK-FIXES-NEXT: {{^}}// t4
+// CHECK-FIXES-NEXT: delete mem;
+  }
+  T *mem;
+};
+
 void f() {
   int *ps = 0;
   if (ps /**/) // #0
Index: clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.h
===
--- clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.h
+++ clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.h
@@ -26,6 +26,9 @@
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace readability
Index: clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
@@ -20,34 +20,30 @@
 
 void DeleteNullPointerCheck::registerMatchers(MatchFinder *Finder) {
   const auto DeleteExpr =
-  cxxDeleteExpr(has(castExpr(has(declRefExpr(
-to(decl(equalsBoundNode("deletedPointer"
+  cxxDeleteExpr(
+  has(declRefExpr(to(decl(equalsBoundNode("deletedPointer"))
   .bind("deleteExpr");
 
   const auto DeleteMemberExpr =
-  cxxDeleteExpr(has(castExpr(has(memberExpr(hasDeclaration(
-fieldDecl(equalsBoundNode("deletedMemberPointer"
+  cxxDeleteExpr(has(memberExpr(hasDeclaration(
+fieldDecl(equalsBoundNode("deletedMemberPointer"))
   .bind("deleteMemberExpr");
 
-  const auto PointerExpr = ignoringImpCasts(anyOf(
+  const auto PointerExpr = anyOf(
   declRefExpr(to(decl().bind("deletedPointer"))),
-  memberExpr(hasDeclaration(fieldDecl().bind("deletedMemberPointer");
+  memberExpr(hasDeclaration(fieldDecl().bind("deletedMemberPointer";
 
-  const auto PointerCondition = castExpr(hasCastKind(CK_PointerToBoolean),
- hasSourceExpression(PointerExpr));
-  const auto BinaryPointerCheckCondition = binaryOperator(
-  hasOperands(castExpr(hasCastKind(CK_NullToPointer)), PointerExpr));
+  const auto BinaryPointerCheckCondition = binaryOperator(hasOperands(
+  anyOf(cxxNullPtrLiteralExpr(), integerLiteral(equals(0))), PointerExpr));
 
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   ifStmt(hasCondition(
-  anyOf(PointerCondition, BinaryPointerCheckCondition)),
-  hasThen(anyOf(DeleteExpr, DeleteMemberExpr,
-compoundStmt(anyOf(has(DeleteExpr),
-   has(DeleteMemberExpr)),
- statementCountIs(1))
-.bind("compound"
-   .bind("ifWithDelete")),
+  ifStmt(hasCondition(anyOf(PointerExpr, BinaryPointerCheckCondition)),
+ hasThen(anyOf(
+ DeleteExpr, DeleteMemberExpr,
+ compoundStmt(anyOf(has(DeleteExpr), has(DeleteMemberExpr)),
+  statementCountIs(1))
+ .bind("compoun

[PATCH] D95691: Implement P2173 for attributes on lambdas

2021-02-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticGroups.td:269
+def CXXPre2BCompatPedantic :
+  DiagGroup<"c++98-c++11-c++14-c++17-c++20-compat-pedantic", [CXXPre2BCompat]>;
 

rsmith wrote:
> rjmccall wrote:
> > rsmith wrote:
> > > rjmccall wrote:
> > > > Quuxplusone wrote:
> > > > > aaron.ballman wrote:
> > > > > > rjmccall wrote:
> > > > > > > Uh, I think we're a couple standard releases past the point at 
> > > > > > > which we should have reconsidered this schema.  I guess the 
> > > > > > > problem is that we can't say `-Wpre-c++23-compat` without jumping 
> > > > > > > the gun.  Is there a problem with `-Wc++20-compat` and then 
> > > > > > > having the earlier warning groups imply the later ones?  That 
> > > > > > > seems to be what we do with `-Wc++98-compat`; did we abandon that 
> > > > > > > approach intentionally?
> > > > > > @rsmith may have more background here. I was following the pattern 
> > > > > > already in the file, but I tend to agree that this pattern is not 
> > > > > > leading us somewhere good. FWIW, I ran into a similar situation 
> > > > > > with this on the C side of things in D95396, so we should probably 
> > > > > > be consistent there too.
> > > > > My understanding is that the //command-line user// is expected to pass
> > > > > - `clang++ -std=c++20 -Wc++11-compat` to indicate "I want 
> > > > > //actually// to compile in C++20 mode, but give me warnings about 
> > > > > anything that would prevent compiling in C++11 mode"
> > > > > - `clang++ -std=c++17 -Wc++14-compat` to indicate "I want 
> > > > > //actually// to compile in C++17 mode, but give me warnings about 
> > > > > anything that would prevent compiling in C++14 mode"
> > > > > - `clang++ -std=c++14 -Wc++20-compat` to indicate "I want 
> > > > > //actually// to compile in C++14 mode, but give me warnings about 
> > > > > anything that would prevent compiling in C++20 mode" — EXCEPT that I 
> > > > > think this is not supported. My impression is that 
> > > > > forward-compatibility warnings are generally just rolled into `-Wall` 
> > > > > and not handled separately beyond that?
> > > > > 
> > > > > I don't think any human user is expected to pass 
> > > > > `-Wc++98-c++11-c++14-c++17-c++20-compat` by hand; it's just an 
> > > > > internal name for a particular subset of `-Wc++98-compat`.
> > > > > 
> > > > > IOW, we could choose a new naming scheme for it, but that would be a 
> > > > > purely internal change that won't affect how command-line users 
> > > > > interact with Clang at all (for better and for worse).
> > > > Diagnostic groups can both directly contain diagnostics and imply other 
> > > > diagnostic groups, so I don't think there's any reason to make a 
> > > > dedicated group just to contain the new diagnostics in e.g. 
> > > > `-Wc++14-compat` except to allow someone turn on those warnings 
> > > > separately.  And it does show up to users as the warning group under 
> > > > `-fdiagnostics-show-option` (which is the default).
> > > @Quuxplusone's comment describes the intent. `-std=c++20 -Wc++14-compat` 
> > > should give a more or less complete list of reasons why the code would 
> > > not compile in C++14 (at least on the language side; we don't check for 
> > > stdlib compatibility). The other direction -- `-std=c++11 -Wc++14-compat` 
> > > -- is more of a best-effort check for things that we've seen cause 
> > > problems in practice and can easily detect. (As a consequence, I don't 
> > > think there's any subset/superset relation between `-Wc++X-compat` and 
> > > `-Wc++Y-compat`.)
> > > 
> > > I'd be happy to see these groups renamed to `-Wpre-c++20-compat` or 
> > > similar. Warning group synonyms are relatively cheap, so I wouldn't be 
> > > worried about adding a `-Wpre-c++2b-compat` now and renaming it to 
> > > `-Wpre-c++23-compat` flag later.
> > > 
> > > (As an aside, it'd be handy if there were some way to mark a `DiagGroup` 
> > > as existing only for grouping purposes, so that we could avoid exposing a 
> > > `-W` flag for cases where groups are added for internal reasons.)
> > Okay.  It looks like `-Wc++X-compat` is consistently (1) all the 
> > this-feature-used-not-to-exist diagnostics from C++X and later plus (2) 
> > warnings about deprecation and semantic changes introduced by exactly 
> > version X.  This seems like an unfortunate pairing, basically caused by the 
> > option names not being very clear about what kind of compatibility they 
> > mean.  If we want @Quuxplusone's interpretation, which I agree is a natural 
> > human interpretation of those command lines, we'll need special support for 
> > it in diagnostic-option handling, so that we include specific diagnostics 
> > based on the relationship between the option and the language version.
> > 
> > There is a natural subset relationship between the 
> > this-feature-used-not-to-exist groups; we're just not taking advantage of 
> > it at all.
>

[PATCH] D95877: [analyzer] Fix static_cast on pointer-to-member handling

2021-02-05 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD marked an inline comment as done.
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:180
 
+bool noRepeatedElements(
+const llvm::ImmutableList &BaseSpecList) {

vsavchenko wrote:
> nit: functions represent actions, in languages verbs act the same way, so 
> it's recommended to use verbs in functions (`hasNoRepeatedElements`)
> 
> + `LLVM_MAYBE_UNUSED` because in the build without assertions it would be a 
> warning otherwise.
> nit: functions represent actions, in languages verbs act the same way, so 
> it's recommended to use verbs in functions (`hasNoRepeatedElements`)
> 
> + `LLVM_MAYBE_UNUSED` because in the build without assertions it would be a 
> warning otherwise.

How do I put in the LLVM_MAYBE_UNUSED? Sorry for being annoying, but 
ripgrepping or Googling didn't return anything.



Comment at: clang/test/Analysis/pointer-to-member.cpp:314-333
+// namespace testReinterpretCasting {
+// struct Base {
+//   int field;
+// };
+//
+// struct Derived : public Base {};
+//

vsavchenko wrote:
> Uncomment it, and expect the actual current result.  This is where `TODO` 
> will come in handy.
> Uncomment it, and expect the actual current result.  This is where `TODO` 
> will come in handy.
Will do it.
Just one clarification: the static analyzer tests only serve to check whether 
the Static Analyzer crashes or hits an assertion error, or is it something more?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95877

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


[PATCH] D96139: [clang-tidy] Simplify inaccurate erase check

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The normalization of matchers means that this now works in all language
modes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96139

Files:
  clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-inaccurate-erase %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy %s bugprone-inaccurate-erase %t
 
 namespace std {
 template  struct vec_iterator {
Index: clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h
@@ -31,6 +31,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
@@ -22,25 +22,19 @@
   callExpr(
   callee(functionDecl(hasAnyName("remove", "remove_if", "unique"))),
   hasArgument(
-  1,
-  anyOf(cxxConstructExpr(has(ignoringImplicit(
-
cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"
-.bind("end",
-anything(
+  1, anyOf(cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"
+   .bind("end"),
+   anything(
   .bind("alg");
 
   const auto DeclInStd = type(hasUnqualifiedDesugaredType(
   tagType(hasDeclaration(decl(isInStdNamespace());
   Finder->addMatcher(
-  traverse(
-  TK_AsIs,
-  cxxMemberCallExpr(
-  on(anyOf(hasType(DeclInStd), hasType(pointsTo(DeclInStd,
-  callee(cxxMethodDecl(hasName("erase"))), argumentCountIs(1),
-  hasArgument(0, has(ignoringImplicit(anyOf(
- EndCall, has(ignoringImplicit(EndCall)),
-  unless(isInTemplateInstantiation()))
-  .bind("erase")),
+  cxxMemberCallExpr(
+  on(anyOf(hasType(DeclInStd), hasType(pointsTo(DeclInStd,
+  callee(cxxMethodDecl(hasName("erase"))), argumentCountIs(1),
+  hasArgument(0, EndCall))
+  .bind("erase"),
   this);
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-inaccurate-erase %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy %s bugprone-inaccurate-erase %t
 
 namespace std {
 template  struct vec_iterator {
Index: clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h
@@ -31,6 +31,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
@@ -22,25 +22,19 @@
   callExpr(
   callee(functionDecl(hasAnyName("remove", "remove_if", "unique"))),
   hasArgument(
-  1,
-  a

[PATCH] D96140: [clang-tidy] Simplify inefficient algorithm check

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The normalization of matchers means that this now works in all language
modes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96140

Files:
  clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
  clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s 
performance-inefficient-algorithm %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy %s performance-inefficient-algorithm %t
 
 namespace std {
 template  struct less {
Index: clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
===
--- clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
+++ clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
@@ -29,6 +29,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace performance
Index: clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
@@ -35,27 +35,24 @@
   "::std::unordered_set", "::std::unordered_map",
   "::std::unordered_multiset", "::std::unordered_multimap"));
 
-  const auto Matcher = traverse(
-  TK_AsIs,
+  const auto Matcher =
   callExpr(
   callee(functionDecl(Algorithms)),
   hasArgument(
-  0, cxxConstructExpr(has(ignoringParenImpCasts(cxxMemberCallExpr(
+  0, cxxMemberCallExpr(
  callee(cxxMethodDecl(hasName("begin"))),
  on(declRefExpr(
 hasDeclaration(decl().bind("IneffContObj")),
 anyOf(hasType(ContainerMatcher.bind("IneffCont")),
   hasType(pointsTo(
   ContainerMatcher.bind("IneffContPtr")
-.bind("IneffContExpr"))),
+.bind("IneffContExpr",
   hasArgument(
-  1, cxxConstructExpr(has(ignoringParenImpCasts(cxxMemberCallExpr(
- callee(cxxMethodDecl(hasName("end"))),
- on(declRefExpr(
- 
hasDeclaration(equalsBoundNode("IneffContObj"),
-  hasArgument(2, expr().bind("AlgParam")),
-  unless(isInTemplateInstantiation()))
-  .bind("IneffAlg"));
+  1, cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"))),
+   on(declRefExpr(hasDeclaration(
+   equalsBoundNode("IneffContObj")),
+  hasArgument(2, expr().bind("AlgParam")))
+  .bind("IneffAlg");
 
   Finder->addMatcher(Matcher, this);
 }


Index: clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s performance-inefficient-algorithm %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy %s performance-inefficient-algorithm %t
 
 namespace std {
 template  struct less {
Index: clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
===
--- clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
+++ clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
@@ -29,6 +29,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace per

[PATCH] D80623: WIP: Add an API to simplify setting TraversalKind in clang-tidy matchers

2021-02-05 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This breaks check-clang everywhere: http://45.33.8.238/linux/38812/step_7.txt

Please run tests before landing.

Please take a look, and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80623

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


[PATCH] D96141: [clang-tidy] Simplify const params check

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96141

Files:
  clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
  clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h


Index: clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h
===
--- clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h
+++ clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h
@@ -24,6 +24,9 @@
 
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace readability
Index: clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
===
--- clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -33,14 +33,6 @@
   parmVarDecl(hasType(qualType(isConstQualified(.bind("param");
   Finder->addMatcher(
   functionDecl(unless(isDefinition()),
-   // Lambdas are always their own definition, but they
-   // generate a non-definition FunctionDecl too. Ignore those.
-   // Class template instantiations have a non-definition
-   // CXXMethodDecl for methods that aren't used in this
-   // translation unit. Ignore those, as the template will have
-   // already been checked.
-   unless(cxxMethodDecl(ofClass(cxxRecordDecl(anyOf(
-   isLambda(), 
ast_matchers::isTemplateInstantiation()),
has(typeLoc(forEach(ConstParamDecl
   .bind("func"),
   this);


Index: clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h
===
--- clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h
+++ clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h
@@ -24,6 +24,9 @@
 
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace readability
Index: clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
===
--- clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -33,14 +33,6 @@
   parmVarDecl(hasType(qualType(isConstQualified(.bind("param");
   Finder->addMatcher(
   functionDecl(unless(isDefinition()),
-   // Lambdas are always their own definition, but they
-   // generate a non-definition FunctionDecl too. Ignore those.
-   // Class template instantiations have a non-definition
-   // CXXMethodDecl for methods that aren't used in this
-   // translation unit. Ignore those, as the template will have
-   // already been checked.
-   unless(cxxMethodDecl(ofClass(cxxRecordDecl(anyOf(
-   isLambda(), ast_matchers::isTemplateInstantiation()),
has(typeLoc(forEach(ConstParamDecl
   .bind("func"),
   this);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96142: [clang-tidy] Simplify too-small loop variable check

2021-02-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Don't issue a warning from within a template declaration which is most
likely not actionable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96142

Files:
  clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-too-small-loop-variable.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-too-small-loop-variable.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-too-small-loop-variable.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-too-small-loop-variable.cpp
@@ -65,7 +65,6 @@
 template 
 void doSomething() {
   for (T i = 0; i < size(); ++i) {
-// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop variable has narrower 
type 'short' than iteration's upper bound 'long' 
[bugprone-too-small-loop-variable]
   }
 }
 
Index: clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
@@ -34,6 +34,9 @@
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   const unsigned MagnitudeBitsUpperLimit;
Index: clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -52,9 +52,7 @@
 ///
 void TooSmallLoopVariableCheck::registerMatchers(MatchFinder *Finder) {
   StatementMatcher LoopVarMatcher =
-  expr(
-  
ignoringParenImpCasts(declRefExpr(to(varDecl(hasType(isInteger()))
-  .bind(LoopVarName);
+  declRefExpr(to(varDecl(hasType(isInteger().bind(LoopVarName);
 
   // We need to catch only those comparisons which contain any integer cast.
   StatementMatcher LoopVarConversionMatcher = traverse(
@@ -64,17 +62,15 @@
 
   // We are interested in only those cases when the loop bound is a variable
   // value (not const, enum, etc.).
-  StatementMatcher LoopBoundMatcher =
-  expr(ignoringParenImpCasts(allOf(hasType(isInteger()),
-   unless(integerLiteral()),
-   unless(hasType(isConstQualified())),
-   unless(hasType(enumType())
+  auto LoopBoundMatcher =
+  expr(allOf(hasType(isInteger()), unless(integerLiteral()),
+ unless(hasType(isConstQualified())),
+ unless(hasType(enumType()
   .bind(LoopUpperBoundName);
 
   // We use the loop increment expression only to make sure we found the right
   // loop variable.
-  StatementMatcher IncrementMatcher =
-  
expr(ignoringParenImpCasts(hasType(isInteger(.bind(LoopIncrementName);
+  auto IncrementMatcher = expr(hasType(isInteger())).bind(LoopIncrementName);
 
   Finder->addMatcher(
   forStmt(


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-too-small-loop-variable.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-too-small-loop-variable.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-too-small-loop-variable.cpp
@@ -65,7 +65,6 @@
 template 
 void doSomething() {
   for (T i = 0; i < size(); ++i) {
-// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop variable has narrower type 'short' than iteration's upper bound 'long' [bugprone-too-small-loop-variable]
   }
 }
 
Index: clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
@@ -34,6 +34,9 @@
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   const unsigned MagnitudeBitsUpperLimit;
Index: clang-tools-extra/clang-tidy/bugpron

  1   2   >