[PATCH] D95439: [clangd] Add include-fixer fixit for field_incomplete_or_sizeless diagnostic.

2021-01-28 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf25a57e248a0: [clangd] Add include-fixer fixit for 
field_incomplete_or_sizeless diagnostic. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95439

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

Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -38,8 +38,9 @@
 using ::testing::Field;
 using ::testing::IsEmpty;
 using ::testing::Pair;
-using testing::SizeIs;
+using ::testing::SizeIs;
 using ::testing::UnorderedElementsAre;
+using testing::UnorderedElementsAreArray;
 
 ::testing::Matcher WithFix(::testing::Matcher FixMatcher) {
   return Field(::Fixes, ElementsAre(FixMatcher));
@@ -770,6 +771,10 @@
 }
 
 ns::X $return[[func]]() {}
+
+class T {
+  ns::X $field[[x]];
+};
   )cpp");
   auto TU = TestTU::withCode(Test.code());
   TU.ExtraArgs.push_back("-std=c++17");
@@ -779,57 +784,64 @@
 
   EXPECT_THAT(
   TU.build().getDiagnostics(),
-  UnorderedElementsAre(
-  AllOf(Diag(Test.range("nested"),
- "incomplete type 'ns::X' named in nested name specifier"),
-DiagName("incomplete_nested_name_spec"),
-WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-"Add include \"x.h\" for symbol ns::X"))),
-  AllOf(Diag(Test.range("base"), "base class has incomplete type"),
-DiagName("incomplete_base_class"),
-WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-"Add include \"x.h\" for symbol ns::X"))),
-  AllOf(Diag(Test.range("access"),
- "member access into incomplete type 'ns::X'"),
-DiagName("incomplete_member_access"),
-WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-"Add include \"x.h\" for symbol ns::X"))),
-  AllOf(
-  Diag(Test.range("type"),
+  UnorderedElementsAreArray(
+  {AllOf(Diag(Test.range("nested"),
+  "incomplete type 'ns::X' named in nested name specifier"),
+ DiagName("incomplete_nested_name_spec"),
+ WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+ "Add include \"x.h\" for symbol ns::X"))),
+   AllOf(Diag(Test.range("base"), "base class has incomplete type"),
+ DiagName("incomplete_base_class"),
+ WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+ "Add include \"x.h\" for symbol ns::X"))),
+   AllOf(Diag(Test.range("access"),
+  "member access into incomplete type 'ns::X'"),
+ DiagName("incomplete_member_access"),
+ WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+ "Add include \"x.h\" for symbol ns::X"))),
+   AllOf(
+   Diag(
+   Test.range("type"),
"incomplete type 'ns::X' where a complete type is required"),
-  DiagName("incomplete_type"),
-  WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-  "Add include \"x.h\" for symbol ns::X"))),
-  AllOf(Diag(Test.range("incomplete"),
- "variable has incomplete type 'ns::X'"),
-DiagName("typecheck_decl_incomplete_type"),
-WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-"Add include \"x.h\" for symbol ns::X"))),
-  AllOf(
-  Diag(Test.range("tag"), "incomplete definition of type 'ns::X'"),
-  DiagName("typecheck_incomplete_tag"),
-  WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-  "Add include \"x.h\" for symbol ns::X"))),
-  AllOf(
-  Diag(Test.range("use"), "invalid use of incomplete type 'ns::X'"),
-  DiagName("invalid_incomplete_type_use"),
-  WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-  "Add include \"x.h\" for symbol ns::X"))),
-  AllOf(Diag(Test.range("sizeof"), "invalid application of 'sizeof' to "
-   "an incomplete type 'ns::X'"),
-DiagName("sizeof_alignof_incomplete_or_sizeless_type"),
-WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-"Add include \"x.h\" for symbol ns::X"))),
-  AllOf(Diag(Test.range("for"),
- "cannot use incomplete 

[clang-tools-extra] f25a57e - [clangd] Add include-fixer fixit for field_incomplete_or_sizeless diagnostic.

2021-01-28 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2021-01-29T08:22:23+01:00
New Revision: f25a57e248a095054a6088b4ffc060e87cd42bc7

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

LOG: [clangd] Add include-fixer fixit for field_incomplete_or_sizeless 
diagnostic.

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeFixer.cpp 
b/clang-tools-extra/clangd/IncludeFixer.cpp
index 690ad4e9363e..2b79c6eb4fa6 100644
--- a/clang-tools-extra/clangd/IncludeFixer.cpp
+++ b/clang-tools-extra/clangd/IncludeFixer.cpp
@@ -78,6 +78,7 @@ std::vector IncludeFixer::fix(DiagnosticsEngine::Level 
DiagLevel,
   case diag::err_sizeof_alignof_incomplete_or_sizeless_type:
   case diag::err_for_range_incomplete_type:
   case diag::err_func_def_incomplete_result:
+  case diag::err_field_incomplete_or_sizeless:
 // Incomplete type diagnostics should have a QualType argument for the
 // incomplete type.
 for (unsigned Idx = 0; Idx < Info.getNumArgs(); ++Idx) {

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index e73385dc6387..aebb231f39f9 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -38,8 +38,9 @@ using ::testing::ElementsAre;
 using ::testing::Field;
 using ::testing::IsEmpty;
 using ::testing::Pair;
-using testing::SizeIs;
+using ::testing::SizeIs;
 using ::testing::UnorderedElementsAre;
+using testing::UnorderedElementsAreArray;
 
 ::testing::Matcher WithFix(::testing::Matcher FixMatcher) {
   return Field(::Fixes, ElementsAre(FixMatcher));
@@ -770,6 +771,10 @@ void test(ns::X *x, ns::X& ref_x) {
 }
 
 ns::X $return[[func]]() {}
+
+class T {
+  ns::X $field[[x]];
+};
   )cpp");
   auto TU = TestTU::withCode(Test.code());
   TU.ExtraArgs.push_back("-std=c++17");
@@ -779,57 +784,64 @@ ns::X $return[[func]]() {}
 
   EXPECT_THAT(
   TU.build().getDiagnostics(),
-  UnorderedElementsAre(
-  AllOf(Diag(Test.range("nested"),
- "incomplete type 'ns::X' named in nested name specifier"),
-DiagName("incomplete_nested_name_spec"),
-WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-"Add include \"x.h\" for symbol ns::X"))),
-  AllOf(Diag(Test.range("base"), "base class has incomplete type"),
-DiagName("incomplete_base_class"),
-WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-"Add include \"x.h\" for symbol ns::X"))),
-  AllOf(Diag(Test.range("access"),
- "member access into incomplete type 'ns::X'"),
-DiagName("incomplete_member_access"),
-WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-"Add include \"x.h\" for symbol ns::X"))),
-  AllOf(
-  Diag(Test.range("type"),
+  UnorderedElementsAreArray(
+  {AllOf(Diag(Test.range("nested"),
+  "incomplete type 'ns::X' named in nested name 
specifier"),
+ DiagName("incomplete_nested_name_spec"),
+ WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+ "Add include \"x.h\" for symbol ns::X"))),
+   AllOf(Diag(Test.range("base"), "base class has incomplete type"),
+ DiagName("incomplete_base_class"),
+ WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+ "Add include \"x.h\" for symbol ns::X"))),
+   AllOf(Diag(Test.range("access"),
+  "member access into incomplete type 'ns::X'"),
+ DiagName("incomplete_member_access"),
+ WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+ "Add include \"x.h\" for symbol ns::X"))),
+   AllOf(
+   Diag(
+   Test.range("type"),
"incomplete type 'ns::X' where a complete type is 
required"),
-  DiagName("incomplete_type"),
-  WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-  "Add include \"x.h\" for symbol ns::X"))),
-  AllOf(Diag(Test.range("incomplete"),
- "variable has incomplete type 'ns::X'"),
-DiagName("typecheck_decl_incomplete_type"),
-WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-"Add include \"x.h\" for symbol ns::X"))),
-  AllOf(
- 

[PATCH] D95670: [clangd] Don't rely on builtin headers for document-link.test.

2021-01-28 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang.

This test seems to be failing at HEAD.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95670

Files:
  clang-tools-extra/clangd/test/document-link.test


Index: clang-tools-extra/clangd/test/document-link.test
===
--- clang-tools-extra/clangd/test/document-link.test
+++ clang-tools-extra/clangd/test/document-link.test
@@ -1,9 +1,10 @@
-# for %resource_dir: REQUIRES: clang
-# %resource_dir actually points at builtin_include_dir, go up one directory.
-# RUN: clangd -lit-test -resource-dir=%resource_dir/.. < %s | FileCheck 
-strict-whitespace %s
+
+# create a fake resource_dir so that the test can find the headers.
+# RUN: mkdir -p %t/include/ && touch %t/include/foo.h
+# RUN: clangd -lit-test -resource-dir=%t < %s | FileCheck -strict-whitespace %s
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---
-{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"#include
 \n#include "}}}
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"#include
 "}}}
 ---
 
{"jsonrpc":"2.0","id":2,"method":"textDocument/documentLink","params":{"textDocument":{"uri":"test:///main.cpp"}}}
 #  CHECK:  "id": 2,
@@ -12,7 +13,7 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
-# CHECK-NEXT:  "character": 19,
+# CHECK-NEXT:  "character": 16,
 # CHECK-NEXT:  "line": 0
 # CHECK-NEXT:},
 # CHECK-NEXT:"start": {
@@ -20,20 +21,7 @@
 # CHECK-NEXT:  "line": 0
 # CHECK-NEXT:}
 # CHECK-NEXT:  },
-# CHECK-NEXT:  "target": "file://{{.*}}/stdint.h"
-# CHECK-NEXT:},
-# CHECK-NEXT:{
-# CHECK-NEXT:  "range": {
-# CHECK-NEXT:"end": {
-# CHECK-NEXT:  "character": 19,
-# CHECK-NEXT:  "line": 1
-# CHECK-NEXT:},
-# CHECK-NEXT:"start": {
-# CHECK-NEXT:  "character": 9,
-# CHECK-NEXT:  "line": 1
-# CHECK-NEXT:}
-# CHECK-NEXT:  },
-# CHECK-NEXT:  "target": "file://{{.*}}/stddef.h"
+# CHECK-NEXT:  "target": "file://{{.*}}/foo.h"
 # CHECK-NEXT:}
 # CHECK-NEXT:  ]
 # CHECK-NEXT:}


Index: clang-tools-extra/clangd/test/document-link.test
===
--- clang-tools-extra/clangd/test/document-link.test
+++ clang-tools-extra/clangd/test/document-link.test
@@ -1,9 +1,10 @@
-# for %resource_dir: REQUIRES: clang
-# %resource_dir actually points at builtin_include_dir, go up one directory.
-# RUN: clangd -lit-test -resource-dir=%resource_dir/.. < %s | FileCheck -strict-whitespace %s
+
+# create a fake resource_dir so that the test can find the headers.
+# RUN: mkdir -p %t/include/ && touch %t/include/foo.h
+# RUN: clangd -lit-test -resource-dir=%t < %s | FileCheck -strict-whitespace %s
 {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---
-{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"#include \n#include "}}}
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"#include "}}}
 ---
 {"jsonrpc":"2.0","id":2,"method":"textDocument/documentLink","params":{"textDocument":{"uri":"test:///main.cpp"}}}
 #  CHECK:  "id": 2,
@@ -12,7 +13,7 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
-# CHECK-NEXT:  "character": 19,
+# CHECK-NEXT:  "character": 16,
 # CHECK-NEXT:  "line": 0
 # CHECK-NEXT:},
 # CHECK-NEXT:"start": {
@@ -20,20 +21,7 @@
 # CHECK-NEXT:  "line": 0
 # CHECK-NEXT:}
 # CHECK-NEXT:  },
-# CHECK-NEXT:  "target": "file://{{.*}}/stdint.h"
-# CHECK-NEXT:},
-# CHECK-NEXT:{
-# CHECK-NEXT:  "range": {
-# CHECK-NEXT:"end": {
-# CHECK-NEXT:  "character": 19,
-# CHECK-NEXT:  "line": 1
-# CHECK-NEXT:},
-# CHECK-NEXT:"start": {
-# CHECK-NEXT:  "character": 9,
-# CHECK-NEXT:  "line": 1
-# CHECK-NEXT:}
-# CHECK-NEXT:  },
-# CHECK-NEXT:  "target": "file://{{.*}}/stddef.h"
+# CHECK-NEXT:  "target": "file://{{.*}}/foo.h"
 # CHECK-NEXT:}
 # CHECK-NEXT:  ]
 # CHECK-NEXT:}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95660: [NFC] Disallow unused prefixes under clang/test/Driver

2021-01-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

Ok for the fsanitize.c bits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95660

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


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-01-28 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:10117
+TSK == TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),

nomanous wrote:
> rsmith wrote:
> > Please can you point us at an example that needs this "ignore lifetime" 
> > nuance? We should check with Apple folks what they want to happen here, and 
> > we should presumably have the same rule for all explicit instantiations of 
> > templated variables -- both in the static data member case here and the 
> > variable template case a few lines above.
> > 
> > My expectation is that we want one of these two rules:
> > 1) the declared lifetime should match exactly between the declaration and 
> > the explicit instantiation, or
> > 2) there cannot be a declared lifetime on the explicit instantiation, and a 
> > lifetime on the template declaration is ignored by the check
> > (or a combination of these rules where we accept either option). I don't 
> > think that matches what you're doing here -- in particular, I think a wrong 
> > declared lifetime on the explicit instantiation should result in an error.
> I'll do some test and give you a code snippet to trigger the lifetime 
> mismatch when lifetime specifiers are not ignored. 
With lifetime specifiers not ignored, use command

```
clang -cc1  -fobjc-arc -fblocks -fsyntax-only snippet.mm
```

to compile the obj-c++ file `snippet.mm` whose contents are as follows:

```
typedef void (^fptr)();
template struct StaticMembers {
  static fptr f;
};

template
fptr StaticMembers::f = [] {};

template fptr StaticMembers::f;
```

The compiler will give a type mismatch error, saying that `f`'s definition in 
the template class  has a type `'__strong fptr' (aka 'void (^__strong)()')` 
while its explicit instantiation has a type `'fptr' (aka 'void (^)()')`, though 
they should essentially have the same type.

This problem only happens in explicit instantiation of a static member of block 
type and doesn't affect static members of other types.

@rsmith 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90448

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


[PATCH] D93844: [clang-format] Add possibility to be based on parent directory

2021-01-28 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks updated this revision to Diff 320058.
HazardyKnusperkeks added a comment.

Rebased and Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93844

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -17914,6 +17914,111 @@
   auto StyleTd = getStyle("file", "x.td", "llvm", "", );
   ASSERT_TRUE((bool)StyleTd);
   ASSERT_EQ(*StyleTd, getLLVMStyle(FormatStyle::LK_TableGen));
+
+  // Test 9.1: overwriting a file style, when parent no file exists with no
+  // fallback style
+  ASSERT_TRUE(FS.addFile(
+  "/e/sub/.clang-format", 0,
+  llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: InheritParentConfig\n"
+   "ColumnLimit: 20")));
+  ASSERT_TRUE(FS.addFile("/e/sub/code.cpp", 0,
+ llvm::MemoryBuffer::getMemBuffer("int i;")));
+  auto Style9 = getStyle("file", "/e/sub/code.cpp", "none", "", );
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, [] {
+auto Style = getNoStyle();
+Style.ColumnLimit = 20;
+return Style;
+  }());
+
+  // Test 9.2: with LLVM fallback style
+  Style9 = getStyle("file", "/e/sub/code.cpp", "LLVM", "", );
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, [] {
+auto Style = getLLVMStyle();
+Style.ColumnLimit = 20;
+return Style;
+  }());
+
+  // Test 9.3: with a parent file
+  ASSERT_TRUE(
+  FS.addFile("/e/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: Google\n"
+  "UseTab: Always")));
+  Style9 = getStyle("file", "/e/sub/code.cpp", "none", "", );
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, [] {
+auto Style = getGoogleStyle();
+Style.ColumnLimit = 20;
+Style.UseTab = FormatStyle::UT_Always;
+return Style;
+  }());
+
+  // Test 9.4: propagate more than one level
+  ASSERT_TRUE(FS.addFile("/e/sub/sub/code.cpp", 0,
+ llvm::MemoryBuffer::getMemBuffer("int i;")));
+  ASSERT_TRUE(FS.addFile("/e/sub/sub/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer(
+ "BasedOnStyle: InheritParentConfig\n"
+ "WhitespaceSensitiveMacros: ['FOO', 'BAR']")));
+  std::vector NonDefaultWhiteSpaceMacros{"FOO", "BAR"};
+
+  const auto SubSubStyle = [] {
+auto Style = getGoogleStyle();
+Style.ColumnLimit = 20;
+Style.UseTab = FormatStyle::UT_Always;
+Style.WhitespaceSensitiveMacros = NonDefaultWhiteSpaceMacros;
+return Style;
+  }();
+
+  ASSERT_NE(Style9->WhitespaceSensitiveMacros, NonDefaultWhiteSpaceMacros);
+  Style9 = getStyle("file", "/e/sub/sub/code.cpp", "none", "", );
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, SubSubStyle);
+
+  // Test 9.5: use InheritParentConfig as style name
+  Style9 =
+  getStyle("inheritparentconfig", "/e/sub/sub/code.cpp", "none", "", );
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, SubSubStyle);
+
+  // Test 9.6: use command line style with inheritance
+  Style9 = getStyle("{BasedOnStyle: InheritParentConfig}", "/e/sub/code.cpp",
+"none", "", );
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, SubSubStyle);
+
+  // Test 9.7: use command line style with inheritance and own config
+  Style9 = getStyle("{BasedOnStyle: InheritParentConfig, "
+"WhitespaceSensitiveMacros: ['FOO', 'BAR']}",
+"/e/sub/code.cpp", "none", "", );
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, SubSubStyle);
+
+  // Test 9.8: use inheritance from a file without BasedOnStyle
+  ASSERT_TRUE(FS.addFile("/e/withoutbase/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("ColumnLimit: 123")));
+  ASSERT_TRUE(
+  FS.addFile("/e/withoutbase/sub/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer(
+ "BasedOnStyle: InheritParentConfig\nIndentWidth: 7")));
+  // Make sure we do not use the fallback style
+  Style9 = getStyle("file", "/e/withoutbase/code.cpp", "google", "", );
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, [] {
+auto Style = getLLVMStyle();
+Style.ColumnLimit = 123;
+return Style;
+  }());
+
+  Style9 = getStyle("file", "/e/withoutbase/sub/code.cpp", "google", "", );
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, [] {
+auto Style = getLLVMStyle();
+Style.ColumnLimit = 123;
+Style.IndentWidth = 7;
+return Style;
+  }());
 }
 
 TEST_F(ReplacementTest, FormatCodeAfterReplacements) {
Index: 

[PATCH] D95403: [clang-tidy][analyzer][WIP] Clang-tidy reverse integration into Static Analyzer.

2021-01-28 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:54-60
+#include "../../clang-tools-extra/clang-tidy/ClangTidyCheck.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyForceLinker.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyModule.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyModuleRegistry.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyOptions.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyProfiling.h"

alexfh wrote:
> Isn't this a layering violation, since clang-tidy depends on 
> clangStaticAnalyzerCore and clangStaticAnalyzerFrontend?
Yes, absolutely.

That said, the only purpose of clang-tidy's dependency on libStaticAnalyzer* is 
integration of static analyzer into clang tidy which is definitely not 
something we want to enable when we're baking clang-tidy back into clang. It 
never makes sense to run static analyzer through clang-tidy integration into 
static analyzer.

So ideally these two dependencies are temporally separated. I could make these 
dependencies mutually exclusive by making the upcoming option of baking 
clang-tidy into clang explicitly incompatible with 
`CLANG_TIDY_ENABLE_STATIC_ANALYZER`.

But if we want to support building both clang-tidy with static analyzer and 
static analyzer with clang-tidy from the same sources into the same build 
directory, that'll probably involve either building two variants of clang-tidy 
(one with static analyzer for standalone clang-tidy binary and one without to 
use inside clang binary only) or two variants of static analyzer (one with 
clang-tidy for the clang binary and one without to use inside clang-tidy binary 
only).

Do you have any preference on how should i untangle this?


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

https://reviews.llvm.org/D95403

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


[PATCH] D78513: [hip] Claim builtin type `__float128` supported if the host target supports it.

2021-01-28 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D78513#1993210 , @hliao wrote:

> In D78513#1993115 , @yaxunl wrote:
>
>> Currently if instructions of float128 get to amdgpu backend, are we going to 
>> crash?
>
> As `Float128Format` is re-defined as `double`, there won't be any issue in 
> the backend. But, it won't function as the developer expects. That's quite 
> similar to `long double` in clang.

I'd argue that it is quite similarly broken. Silently miscompiling the program 
is arguably the worst. Are you sure the OpenMP/Sycl way to deal with this is 
not better? Long story short,
allow the presence of a type that the aux-triple supports but do not allow the 
use of such a type. The implementation is not perfect yet, e.g., it doesn't 
allow the above typedef and sometimes a `long double` is manifested in IR, but 
for the most part it's functional: 
`clang/test/OpenMP/nvptx_unsupported_type_messages.cpp` and 
`clang/test/SemaSYCL/float128.cpp` after D74387 
. TBH, I believe an error is still better than 
treating `long double` and `fp128` on the device side different and then hope 
that it somehow works.

FWIW, I landed here after I wrote D95665  to 
address PR48923. I think the ideas there and here are contrary and we should 
pick one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78513

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


[PATCH] D95665: [Builtins][FIX] Allow targets to opt-out of `long double` builtins

2021-01-28 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert created this revision.
jdoerfert added reviewers: tra, hliao, yaxunl, ldionne, compnerd, Fznamznon, 
erichkeane, rsmith, mclow.lists.
Herald added subscribers: kerbowa, nhaehnle, jvesely, jholewinski.
Herald added a reviewer: bollu.
jdoerfert requested review of this revision.
Herald added a project: clang.

If a target doesn't support `long double`, e.g., a GPU, it should not
expose the builtins that deal with them in the first place. This patch
also adjusts `__has_builtin` to return false in those cases.

This is a first step to fix PR48923, second is to adjust libcxx and
add the `__has_builtin` guards.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95665

Files:
  clang/include/clang/Basic/Builtins.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Builtins.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Frontend/ChainedIncludesSource.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/Parser/builtin_long_double.c
  clang/test/Preprocessor/has_builtin_long_double.c

Index: clang/test/Preprocessor/has_builtin_long_double.c
===
--- /dev/null
+++ clang/test/Preprocessor/has_builtin_long_double.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple arm-unknown-linux -verify -E %s -o - | FileCheck %s --check-prefix=ARM
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify -E %s -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux -verify -E %s -o - | FileCheck %s --check-prefix=PPC
+// RUN: %clang_cc1 -triple nvptx-unknown-linux -verify -E %s -o - | FileCheck %s --check-prefix=GPU
+// RUN: %clang_cc1 -triple amdgcn-unknown-linux -verify -E %s -o - | FileCheck %s --check-prefix=GPU
+// expected-no-diagnostics
+
+// ARM: has_fabs
+// X86: has_fabs
+// PPC: has_fabs
+// PTX: has_fabs
+#if __has_builtin(fabs)
+  void has_fabs(void);
+#endif
+
+// ARM: has_fabsl
+// X86: has_fabsl
+// PPC: has_fabsl
+// GPU-NOT: has_fabsl
+#if __has_builtin(fabsl)
+  void has_fabsl(void);
+#endif
Index: clang/test/Parser/builtin_long_double.c
===
--- /dev/null
+++ clang/test/Parser/builtin_long_double.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple arm-unknown-linux -verify=CPU -fsyntax-only %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify=CPU -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux -verify=CPU -fsyntax-only %s
+// RUN: %clang_cc1 -triple nvptx-unknown-linux -verify=GPU -fsyntax-only %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-linux -verify=GPU -fsyntax-only %s
+// CPU-no-diagnostics
+
+double fn(void) {
+  double d = 0.;
+  // regular builtin
+  d += __builtin_canonicalizel(0.0); // GPU-error{{use of unknown builtin}}
+  // library builtin
+  d += __builtin_atan2l(0., 0.); // GPU-error{{use of unknown builtin}}
+  return d;
+}
Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -1638,6 +1638,12 @@
 // usual allocation and deallocation functions. Required by libc++
 return 201802;
   default:
+// If we are looking at a long double (or similar) builtin and the
+// target doesn't support long double we do not pretend we could use
+// the builtin.
+if (!getTargetInfo().hasLongDouble() &&
+getBuiltinInfo().hasLongDouble(II->getBuiltinID()))
+  return false;
 return true;
   }
   return true;
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -659,8 +659,8 @@
 CI.setSourceManager(>getSourceManager());
 CI.setPreprocessor(AST->getPreprocessorPtr());
 Preprocessor  = CI.getPreprocessor();
-PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(),
-   PP.getLangOpts());
+PP.getBuiltinInfo().initializeBuiltins(
+PP.getIdentifierTable(), PP.getLangOpts(), PP.getTargetInfo());
 CI.setASTContext(>getASTContext());
 
 setCurrentInput(Input, std::move(AST));
@@ -900,8 +900,8 @@
   if (CI.getLangOpts().Modules || !CI.hasASTContext() ||
   !CI.getASTContext().getExternalSource()) {
 Preprocessor  = CI.getPreprocessor();
-PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(),
-   PP.getLangOpts());
+PP.getBuiltinInfo().initializeBuiltins(
+PP.getIdentifierTable(), PP.getLangOpts(), PP.getTargetInfo());
   } else {
 // FIXME: If this is a problem, recover from it by creating a multiplex
 // source.

[PATCH] D95519: [clang-tidy] bugprone-assert-side-effect: Warn on NSAssert by default.

2021-01-28 Thread Artem Dergachev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb92a39ac1319: [clang-tidy] bugprone-assert-side-effect: Warn 
on NSAssert by default. (authored by dergachev.a).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95519

Files:
  clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.m


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.m
@@ -0,0 +1,53 @@
+// RUN: %check_clang_tidy %s bugprone-assert-side-effect %t
+
+int abort();
+
+@interface NSObject
+@end
+
+@interface NSString
+@end
+
+@interface NSAssertionHandler
++ (NSAssertionHandler *)currentHandler;
+- handleFailureInMethod:(SEL)cmd object:(NSObject *)obj desc:(NSString *)desc;
+- handleFailureInFunction:(NSString *)desc;
+@end
+
+#ifndef NDEBUG
+#define NSAssert(condition, description, ...)  
  \
+  do { 
  \
+if (__builtin_expect(!(condition), 0)) {   
  \
+  [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd  
  \
+  object:self  
  \
+
desc:(description)]; \
+}  
  \
+  } while (0);
+#define NSCAssert(condition, description, ...) 
\
+  do { 
\
+if (__builtin_expect(!(condition), 0)) {   
\
+  [[NSAssertionHandler currentHandler] 
handleFailureInFunction:(description)]; \
+}  
\
+  } while (0);
+#else
+#define NSAssert(condition, description, ...) do {} while (0)
+#define NSCAssert(condition, description, ...) do {} while (0)
+#endif
+
+@interface I : NSObject
+- (void)foo;
+@end
+
+@implementation I
+- (void)foo {
+  int x = 0;
+  NSAssert((++x) == 1, @"Ugh.");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in NSAssert() 
condition discarded in release builds [bugprone-assert-side-effect]
+}
+@end
+
+void foo() {
+  int x = 0;
+  NSCAssert((++x) == 1, @"Ugh.");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in NSCAssert() 
condition discarded in release builds [bugprone-assert-side-effect]
+}
Index: clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -72,7 +72,8 @@
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   CheckFunctionCalls(Options.get("CheckFunctionCalls", false)),
-  RawAssertList(Options.get("AssertMacros", "assert")) {
+  RawAssertList(Options.get("AssertMacros",
+"assert,NSAssert,NSCAssert")) {
   StringRef(RawAssertList).split(AssertMacros, ",", -1, false);
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.m
@@ -0,0 +1,53 @@
+// RUN: %check_clang_tidy %s bugprone-assert-side-effect %t
+
+int abort();
+
+@interface NSObject
+@end
+
+@interface NSString
+@end
+
+@interface NSAssertionHandler
++ (NSAssertionHandler *)currentHandler;
+- handleFailureInMethod:(SEL)cmd object:(NSObject *)obj desc:(NSString *)desc;
+- handleFailureInFunction:(NSString *)desc;
+@end
+
+#ifndef NDEBUG
+#define NSAssert(condition, description, ...)\
+  do {   \
+if (__builtin_expect(!(condition), 0)) { \
+  [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd\
+  object:self\
+desc:(description)]; \
+}\
+  } while (0);
+#define NSCAssert(condition, description, ...) \
+  do { \
+if (__builtin_expect(!(condition), 0)) {  

[PATCH] D95515: [clang-tidy] bugprone-assert-side-effect: Improve warning message.

2021-01-28 Thread Artem Dergachev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec8128983180: [clang-tidy] bugprone-assert-side-effect: 
Improve warning message. (authored by dergachev.a).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95515

Files:
  clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
@@ -68,47 +68,47 @@
   assert(X == 1);
 
   assert(X = 1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect 
[bugprone-assert-side-effect]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds [bugprone-assert-side-effect]
   my_assert(X = 1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found my_assert() with side 
effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in my_assert() 
condition discarded in release builds
   convoluted_assert(X = 1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found convoluted_assert() with 
side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in 
convoluted_assert() condition discarded in release builds
   not_my_assert(X = 1);
 
   assert(++X);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
   assert(!B);
 
   assert(B || true);
 
   assert(freeFunction());
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
 
   MyClass mc;
   assert(mc.badFunc(0, 1));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
   assert(mc.goodFunc(0, 1));
 
   MyClass mc2;
   assert(mc2 = mc);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
 
   assert(-mc > 0);
 
   MyClass *mcp;
   assert(mcp = new MyClass);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
 
   assert((delete mcp, false));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
 
   assert((throw 1, false));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
 
   assert2(1 == 2 - 1);
 
   msvc_assert(mc2 = mc);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found msvc_assert() with side 
effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in msvc_assert() 
condition discarded in release builds
 
   return 0;
 }
Index: clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -117,7 +117,8 @@
   if (AssertMacroName.empty())
 return;
 
-  diag(Loc, "found %0() with side effect") << AssertMacroName;
+  diag(Loc, "side effect in %0() condition discarded in release builds")
+  << AssertMacroName;
 }
 
 } // namespace bugprone


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
@@ -68,47 +68,47 @@
   assert(X == 1);
 
   assert(X = 1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect [bugprone-assert-side-effect]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds [bugprone-assert-side-effect]
   my_assert(X = 1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found my_assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in my_assert() condition discarded in release builds
   convoluted_assert(X = 1);
-  

[clang-tools-extra] b92a39a - [clang-tidy] bugprone-assert-side-effect: Warn on NSAssert by default.

2021-01-28 Thread Artem Dergachev via cfe-commits

Author: Artem Dergachev
Date: 2021-01-28T22:31:49-08:00
New Revision: b92a39ac1319c796777bca19a3af2856acbc69c1

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

LOG: [clang-tidy] bugprone-assert-side-effect: Warn on NSAssert by default.

NSAssert and NSCAssert are Objective-C Foundation's standard assert macros.

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

Added: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.m

Modified: 
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 0d8834e4135f..4e2359ff4f67 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -72,7 +72,8 @@ AssertSideEffectCheck::AssertSideEffectCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   CheckFunctionCalls(Options.get("CheckFunctionCalls", false)),
-  RawAssertList(Options.get("AssertMacros", "assert")) {
+  RawAssertList(Options.get("AssertMacros",
+"assert,NSAssert,NSCAssert")) {
   StringRef(RawAssertList).split(AssertMacros, ",", -1, false);
 }
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.m 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.m
new file mode 100644
index ..bca79565cea0
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.m
@@ -0,0 +1,53 @@
+// RUN: %check_clang_tidy %s bugprone-assert-side-effect %t
+
+int abort();
+
+@interface NSObject
+@end
+
+@interface NSString
+@end
+
+@interface NSAssertionHandler
++ (NSAssertionHandler *)currentHandler;
+- handleFailureInMethod:(SEL)cmd object:(NSObject *)obj desc:(NSString *)desc;
+- handleFailureInFunction:(NSString *)desc;
+@end
+
+#ifndef NDEBUG
+#define NSAssert(condition, description, ...)  
  \
+  do { 
  \
+if (__builtin_expect(!(condition), 0)) {   
  \
+  [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd  
  \
+  object:self  
  \
+
desc:(description)]; \
+}  
  \
+  } while (0);
+#define NSCAssert(condition, description, ...) 
\
+  do { 
\
+if (__builtin_expect(!(condition), 0)) {   
\
+  [[NSAssertionHandler currentHandler] 
handleFailureInFunction:(description)]; \
+}  
\
+  } while (0);
+#else
+#define NSAssert(condition, description, ...) do {} while (0)
+#define NSCAssert(condition, description, ...) do {} while (0)
+#endif
+
+@interface I : NSObject
+- (void)foo;
+@end
+
+@implementation I
+- (void)foo {
+  int x = 0;
+  NSAssert((++x) == 1, @"Ugh.");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in NSAssert() 
condition discarded in release builds [bugprone-assert-side-effect]
+}
+@end
+
+void foo() {
+  int x = 0;
+  NSCAssert((++x) == 1, @"Ugh.");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in NSCAssert() 
condition discarded in release builds [bugprone-assert-side-effect]
+}



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


[clang-tools-extra] ec81289 - [clang-tidy] bugprone-assert-side-effect: Improve warning message.

2021-01-28 Thread Artem Dergachev via cfe-commits

Author: Artem Dergachev
Date: 2021-01-28T22:31:49-08:00
New Revision: ec812898318036f6c33579b1d35c1a7f83cf112f

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

LOG: [clang-tidy] bugprone-assert-side-effect: Improve warning message.

Drop redundant "found", specify what exactly is wrong with side effects
in assert conditions.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 8f7d1d1237e9..0d8834e4135f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -117,7 +117,8 @@ void AssertSideEffectCheck::check(const 
MatchFinder::MatchResult ) {
   if (AssertMacroName.empty())
 return;
 
-  diag(Loc, "found %0() with side effect") << AssertMacroName;
+  diag(Loc, "side effect in %0() condition discarded in release builds")
+  << AssertMacroName;
 }
 
 } // namespace bugprone

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
index 0933402e90c4..bf368cda5e17 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
@@ -68,47 +68,47 @@ int main() {
   assert(X == 1);
 
   assert(X = 1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect 
[bugprone-assert-side-effect]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds [bugprone-assert-side-effect]
   my_assert(X = 1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found my_assert() with side 
effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in my_assert() 
condition discarded in release builds
   convoluted_assert(X = 1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found convoluted_assert() with 
side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in 
convoluted_assert() condition discarded in release builds
   not_my_assert(X = 1);
 
   assert(++X);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
   assert(!B);
 
   assert(B || true);
 
   assert(freeFunction());
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
 
   MyClass mc;
   assert(mc.badFunc(0, 1));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
   assert(mc.goodFunc(0, 1));
 
   MyClass mc2;
   assert(mc2 = mc);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
 
   assert(-mc > 0);
 
   MyClass *mcp;
   assert(mcp = new MyClass);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
 
   assert((delete mcp, false));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
 
   assert((throw 1, false));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
 
   assert2(1 == 2 - 1);
 
   msvc_assert(mc2 = mc);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found msvc_assert() with side 
effect
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in msvc_assert() 
condition discarded in release builds
 
   return 0;
 }



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


[PATCH] D93110: [analyzer] Implement fine-grained suppressions via attributes

2021-01-28 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

> What I want to avoid is having a static analyzer-specific suppression 
> attribute, and a different one for clang-tidy, and a third one for the 
> frontend.

Given that there are already multiple suppression mechanisms circulating around 
(clang-tidy's `// NOLINT`, frontend pragmas, static analyzer's `#ifdef 
__clang_analyzer__`, now also attribute), i guess a path forward would be to 
eventually add support for multiple mechanisms everywhere. This may be tedious 
to implement but benefits may be well worth it. Consistency across tools is 
important when tools are used together; for instance, when clang-tidy 
integrates static analyzer, static analyzer automatically starts supporting `// 
NOLINT` through clang-tidy's diagnostic consumer magic. This would also be 
amazing for discoverability: users can keep using their preferred mechanism and 
it'd just work out of the box when they add a new tool to their arsenal.




Comment at: clang/include/clang/Basic/Attr.td:2396
+  let Args = [VariadicStringArgument<"DiagnosticIdentifiers">];
+  let Subjects = SubjectList<[Var]>;
+  let Documentation = [AnalyzerSuppressDocs];

[evil mode]
What's the expected behavior when the same variable (esp. global) has multiple 
redeclarations and only some of them wear the attribute?
[/evil mode]

I guess this mostly applies to globals and we don't have much checkers that 
would warn on globals (maybe some of those WebKit checkers by @jkorous may be 
affected).



Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:592-593
 
+  /// User-provided in-code suppressions.
+  BugSuppression UserSuppressions;
+

Even though the attribute is specific to the static analyzer and from that 
point of view it's appropriate to keep this info in the `BugReporter` object 
(that will always be specific to the static analyzer), i believe we should 
ultimately move this into a higher-level entity in `libAnalysis` such as 
`AnalysisConsumer`. This would allow other tools such as clang-tidy to access 
that information when integrated into the static analyzer (eg., a-la D95403) 
and the user treats the entire conglomerate of tools as just "the static 
analyzer" and expects consistency across checks. That, of course, relies on our 
ability to look up attributes by source locations.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugSuppression.h:30-31
+public:
+  /// Return true if the given bug report was explicitly suppressed by the 
user.
+  bool isSuppressed(const BugReport &);
+  /// Return true if the bug reported at the given location was explicitly

So, like, i wish this could be replaced with `bool isSuppressed(const 
PathDiagnostic &);` so that to untie this from Static Analyzer-specific 
`BugReport` object.

There's no straightforward way to jump from `BugReport` to its specific 
`PathDiagnostic`, especially given that the same bug report may produce 
different `PathDiagnostic`s for different consumers. But by the time 
suppressions kick in we can be certain that `PathDiagnostic` objects are fully 
constructed.

It's an interesting question whether different `PathDiagnostic`s for the same 
bug report may interact with suppressions differently. For now this can't 
happen because all of them will have the same location and the same uniqueing 
location. We should obviously avoid such differences, probably protect 
ourselves against them with an assertion.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugSuppression.h:38
+private:
+  // Overly pessimistic number, to be honest.
+  static constexpr unsigned EXPECTED_NUMBER_OF_SUPPRESSIONS = 8;

Depression fuel! :D



Comment at: clang/lib/StaticAnalyzer/Core/BugSuppression.cpp:70
+
+class CacheInitializer : public RecursiveASTVisitor {
+public:

A recursive visitor would cause you to visit nested declarations (eg., lambdas, 
or methods of nested classes) multiple times. Is this necessary? A plain old 
`ConstStmtVisitor` that's taught to visit child statements recursively could 
easily avoid that. That's probably cheap though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93110

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


[PATCH] D95128: [clang-format] [NFC] Remove unused arguments

2021-01-28 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Could you please note here the git hash please? For the record.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95128

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


[PATCH] D92257: [clang-format] Add option to control the space at the front of a line comment

2021-01-28 Thread Björn Schäpers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG078f30e04d1f: [clang-format] Add option to control the 
spaces in a line comment (authored by HazardyKnusperkeks).

Changed prior to commit:
  https://reviews.llvm.org/D92257?vs=317294=320046#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92257

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/BreakableToken.cpp
  clang/lib/Format/BreakableToken.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/NamespaceEndCommentsFixer.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestComments.cpp

Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -3144,7 +3144,7 @@
 "  # commen6\n"
 "  # commen7",
 format("k:val#commen1 commen2\n"
-   " # commen3\n"
+   " #commen3\n"
"# commen4\n"
"a:1#commen5 commen6\n"
" #commen7",
@@ -3275,6 +3275,506 @@
JSStyle20));
 }
 
+TEST_F(FormatTestComments, SpaceAtLineCommentBegin) {
+  FormatStyle Style = getLLVMStyle();
+  StringRef NoTextInComment = " //   \n"
+  "\n"
+  "void foo() {// \n"
+  "// \n"
+  "}";
+
+  EXPECT_EQ("//\n"
+"\n"
+"void foo() { //\n"
+"  //\n"
+"}",
+format(NoTextInComment, Style));
+
+  Style.SpacesInLineCommentPrefix.Minimum = 0;
+  EXPECT_EQ("//\n"
+"\n"
+"void foo() { //\n"
+"  //\n"
+"}",
+format(NoTextInComment, Style));
+
+  Style.SpacesInLineCommentPrefix.Minimum = 5;
+  EXPECT_EQ("//\n"
+"\n"
+"void foo() { //\n"
+"  //\n"
+"}",
+format(NoTextInComment, Style));
+
+  Style = getLLVMStyle();
+  StringRef Code =
+  "//Free comment without space\n"
+  "\n"
+  "//   Free comment with 3 spaces\n"
+  "\n"
+  "///Free Doxygen without space\n"
+  "\n"
+  "///   Free Doxygen with 3 spaces\n"
+  "\n"
+  "/// A Doxygen Comment with a nested list:\n"
+  "/// - Foo\n"
+  "/// - Bar\n"
+  "///   - Baz\n"
+  "///   - End\n"
+  "/// of the inner list\n"
+  "///   .\n"
+  "/// .\n"
+  "\n"
+  "namespace Foo {\n"
+  "bool bar(bool b) {\n"
+  "  bool ret1 = true; ///TokenText;
   if (NamespaceTok->is(TT_NamespaceMacro))
 text += "(";
@@ -278,7 +280,8 @@
   EndCommentNextTok->NewlinesBefore == 0 &&
   EndCommentNextTok->isNot(tok::eof);
 const std::string EndCommentText =
-computeEndCommentText(NamespaceName, AddNewline, NamespaceTok);
+computeEndCommentText(NamespaceName, AddNewline, NamespaceTok,
+  Style.SpacesInLineCommentPrefix.Minimum);
 if (!hasEndComment(EndCommentPrevTok)) {
   bool isShort = I - StartLineIndex <= kShortNamespaceMaxLines + 1;
   if (!isShort)
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -661,6 +661,8 @@
Style.SpacesInContainerLiterals);
 IO.mapOptional("SpacesInCStyleCastParentheses",
Style.SpacesInCStyleCastParentheses);
+IO.mapOptional("SpacesInLineCommentPrefix",
+   Style.SpacesInLineCommentPrefix);
 IO.mapOptional("SpacesInParentheses", Style.SpacesInParentheses);
 IO.mapOptional("SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
 IO.mapOptional("SpaceBeforeSquareBrackets",
@@ -710,6 +712,20 @@
   }
 };
 
+template <> struct MappingTraits {
+  static void mapping(IO , FormatStyle::SpacesInLineComment ) {
+// Transform the maximum to signed, to parse "-1" correctly
+int signedMaximum = static_cast(Space.Maximum);
+IO.mapOptional("Minimum", Space.Minimum);
+IO.mapOptional("Maximum", signedMaximum);
+Space.Maximum = static_cast(signedMaximum);
+
+if (Space.Maximum != -1u) {
+  Space.Minimum = std::min(Space.Minimum, Space.Maximum);
+}
+  }
+};
+
 // Allows to read vector while keeping default values.
 // IO.getContext() should contain a pointer to the FormatStyle structure, that
 // will be used to get default values for missing keys.
@@ -986,6 +1002,7 @@
   LLVMStyle.SpaceInEmptyParentheses = false;
   LLVMStyle.SpacesInContainerLiterals = true;
   LLVMStyle.SpacesInCStyleCastParentheses = false;
+  

[clang] 078f30e - [clang-format] Add option to control the spaces in a line comment

2021-01-28 Thread Björn Schäpers via cfe-commits

Author: Björn Schäpers
Date: 2021-01-29T07:00:08+01:00
New Revision: 078f30e04d1fcb5a05d8e340f3178f3478075541

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

LOG: [clang-format] Add option to control the spaces in a line comment

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/BreakableToken.cpp
clang/lib/Format/BreakableToken.h
clang/lib/Format/Format.cpp
clang/lib/Format/NamespaceEndCommentsFixer.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestComments.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 3458575119e2..a28efa5dad04 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3335,6 +3335,43 @@ the configuration (without a prefix: ``Auto``).
  var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
  f({a : 1, b : 2, c : 3});  f({a: 1, b: 2, c: 3});
 
+**SpacesInLineCommentPrefix** (``SpacesInLineComment``)
+  How many spaces are allowed at the start of a line comment. To disable the
+  maximum set it to ``-1``, apart from that the maximum takes precedence
+  over the minimum.
+  Minimum = 1 Maximum = -1
+  // One space is forced
+
+  //  but more spaces are possible
+
+  Minimum = 0
+  Maximum = 0
+  //Forces to start every comment directly after the slashes
+
+  Note that in line comment sections the relative indent of the subsequent
+  lines is kept, that means the following:
+
+  .. code-block:: c++
+
+  before:   after:
+  Minimum: 1
+  //if (b) {// if (b) {
+  //  return true;  //   return true;
+  //}   // }
+
+  Maximum: 0
+  /// List: ///List:
+  ///  - Foo/// - Foo
+  ///- Bar  ///   - Bar
+
+  Nested configuration flags:
+
+
+  * ``unsigned Minimum`` The minimum number of spaces at the start of the 
comment.
+
+  * ``unsigned Maximum`` The maximum number of spaces at the start of the 
comment.
+
+
 **SpacesInParentheses** (``bool``)
   If ``true``, spaces will be inserted after ``(`` and before ``)``.
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b0c6c66e992e..c5b93718b0a1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -158,6 +158,10 @@ clang-format
 
 - ...
 
+- Option ``SpacesInLineCommentPrefix`` has been added to control the
+  number of spaces in a line comments prefix.
+
+
 libclang
 
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 96c2a74e97db..269707fedaac 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2894,6 +2894,43 @@ struct FormatStyle {
   /// \endcode
   bool SpacesInCStyleCastParentheses;
 
+  /// Control of spaces within a single line comment
+  struct SpacesInLineComment {
+/// The minimum number of spaces at the start of the comment.
+unsigned Minimum;
+/// The maximum number of spaces at the start of the comment.
+unsigned Maximum;
+  };
+
+  /// How many spaces are allowed at the start of a line comment. To disable 
the
+  /// maximum set it to ``-1``, apart from that the maximum takes precedence
+  /// over the minimum.
+  /// \code Minimum = 1 Maximum = -1
+  /// // One space is forced
+  ///
+  /// //  but more spaces are possible
+  ///
+  /// Minimum = 0
+  /// Maximum = 0
+  /// //Forces to start every comment directly after the slashes
+  /// \endcode
+  ///
+  /// Note that in line comment sections the relative indent of the subsequent
+  /// lines is kept, that means the following:
+  /// \code
+  /// before:   after:
+  /// Minimum: 1
+  /// //if (b) {// if (b) {
+  /// //  return true;  //   return true;
+  /// //}   // }
+  ///
+  /// Maximum: 0
+  /// /// List: ///List:
+  /// ///  - Foo/// - Foo
+  /// ///- Bar  ///   - Bar
+  /// \endcode
+  SpacesInLineComment SpacesInLineCommentPrefix;
+
   /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
   /// \code
   ///true:  false:
@@ -3145,6 +3182,10 @@ struct FormatStyle {
SpacesInConditionalStatement == R.SpacesInConditionalStatement &&

[PATCH] D95128: [clang-format] [NFC] Remove unused arguments

2021-01-28 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks closed this revision.
HazardyKnusperkeks added a comment.

Commited but forgot the Differential Link in the Message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95128

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


[PATCH] D93630: [Attr] Apply GNU-style attributes to expression statements

2021-01-28 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/include/clang/Basic/Features.def:256
 EXTENSION(pragma_clang_attribute_external_declaration, true)
+EXTENSION(statement_attributes_with_gnu_syntax, true)
 EXTENSION(gnu_asm, LangOpts.GNUAsm)

People seem to occasionally write lit tests for those. There isn't much room 
for error there but i guess a tiny test wouldn't hurt.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93630

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


[PATCH] D95660: [NFC] Disallow unused prefixes under clang/test/Driver

2021-01-28 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin created this revision.
Herald added subscribers: kerbowa, mstorsjo, nhaehnle, jvesely.
mtrofin 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/D95660

Files:
  clang/test/Driver/amdgpu-macros.cl
  clang/test/Driver/cuda-detect.cu
  clang/test/Driver/fsanitize.c
  clang/test/Driver/lit.local.cfg
  clang/test/Driver/ps4-visibility-dllstorageclass.c
  clang/test/Driver/rocm-device-libs.cl

Index: clang/test/Driver/rocm-device-libs.cl
===
--- clang/test/Driver/rocm-device-libs.cl
+++ clang/test/Driver/rocm-device-libs.cl
@@ -79,45 +79,45 @@
 // RUN:   -cl-unsafe-math-optimizations \
 // RUN:   --rocm-path=%S/Inputs/rocm \
 // RUN:   %s \
-// RUN: 2>&1 | FileCheck  --check-prefixes=COMMON,COMMON-UNSAFE,GFX803,WAVE64 %s
+// RUN: 2>&1 | FileCheck  --check-prefixes=COMMON,GFX803,WAVE64 %s
 
 // RUN: %clang -### -target amdgcn-amd-amdhsa\
 // RUN:   -x cl -mcpu=gfx1010\
 // RUN:   --rocm-path=%S/Inputs/rocm \
 // RUN:   %s \
-// RUN: 2>&1 | FileCheck  --check-prefixes=COMMMON,GFX1010,WAVE32 %s
+// RUN: 2>&1 | FileCheck  --check-prefix=WAVE32 %s
 
 // RUN: %clang -### -target amdgcn-amd-amdhsa\
 // RUN:   -x cl -mcpu=gfx1011\
 // RUN:   --rocm-path=%S/Inputs/rocm \
 // RUN:   %s \
-// RUN: 2>&1 | FileCheck  --check-prefixes=COMMMON,GFX1011,WAVE32 %s
+// RUN: 2>&1 | FileCheck  --check-prefix=WAVE32 %s
 
 // RUN: %clang -### -target amdgcn-amd-amdhsa\
 // RUN:   -x cl -mcpu=gfx1012\
 // RUN:   --rocm-path=%S/Inputs/rocm \
 // RUN:   %s \
-// RUN: 2>&1 | FileCheck  --check-prefixes=COMMMON,GFX1012,WAVE32 %s
+// RUN: 2>&1 | FileCheck  --check-prefix=WAVE32 %s
 
 
 // RUN: %clang -### -target amdgcn-amd-amdhsa\
 // RUN:   -x cl -mcpu=gfx1010 -mwavefrontsize64  \
 // RUN:   --rocm-path=%S/Inputs/rocm \
 // RUN:   %s \
-// RUN: 2>&1 | FileCheck  --check-prefixes=COMMMON,GFX1010,WAVE64 %s
+// RUN: 2>&1 | FileCheck  --check-prefix=WAVE64 %s
 
 // RUN: %clang -### -target amdgcn-amd-amdhsa\
 // RUN:   -x cl -mcpu=gfx1010 -mwavefrontsize64 -mno-wavefrontsize64  \
 // RUN:   --rocm-path=%S/Inputs/rocm \
 // RUN:   %s \
-// RUN: 2>&1 | FileCheck  --check-prefixes=COMMMON,GFX1010,WAVE32 %s
+// RUN: 2>&1 | FileCheck  --check-prefix=WAVE32 %s
 
 // Ignore -mno-wavefrontsize64 without wave32 support
 // RUN: %clang -### -target amdgcn-amd-amdhsa   \
 // RUN:   -x cl -mcpu=gfx803  -mno-wavefrontsize64  \
 // RUN:   --rocm-path=%S/Inputs/rocm\
 // RUN:   %s \
-// RUN: 2>&1 | FileCheck  --check-prefixes=COMMMON,GFX803,WAVE64 %s
+// RUN: 2>&1 | FileCheck  --check-prefixes=GFX803,WAVE64 %s
 
 
 
Index: clang/test/Driver/ps4-visibility-dllstorageclass.c
===
--- clang/test/Driver/ps4-visibility-dllstorageclass.c
+++ clang/test/Driver/ps4-visibility-dllstorageclass.c
@@ -1,7 +1,7 @@
 // Check behaviour of -fvisibility-from-dllstorageclass options for PS4
 
 // RUN: %clang -### -target x86_64-scei-ps4 %s -Werror -o - 2>&1 | \
-// RUN:   FileCheck %s -check-prefixes=DEFAULTS,DEFAULTS1 \
+// RUN:   FileCheck %s --check-prefix=DEFAULTS \
 // RUN: --implicit-check-not=-fvisibility-from-dllstorageclass \
 // RUN: --implicit-check-not=-fvisibility-dllexport \
 // RUN: --implicit-check-not=-fvisibility-nodllstorageclass \
@@ -13,7 +13,7 @@
 // RUN: -fvisibility-from-dllstorageclass \
 // RUN: -Werror \
 // RUN: %s -o - 2>&1 | \
-// RUN:   FileCheck %s -check-prefixes=DEFAULTS,DEFAULTS2 \
+// RUN:   FileCheck %s --check-prefix=DEFAULTS \
 // RUN: --implicit-check-not=-fvisibility-from-dllstorageclass \
 // RUN: --implicit-check-not=-fvisibility-dllexport \
 // RUN: --implicit-check-not=-fvisibility-nodllstorageclass \
Index: clang/test/Driver/lit.local.cfg
===
--- clang/test/Driver/lit.local.cfg
+++ clang/test/Driver/lit.local.cfg
@@ -1,3 +1,11 @@
+from lit.llvm.subst import ToolSubst
+
+fc = ToolSubst('FileCheck', unresolved='fatal')
+# Insert this first. Then, we'll first update the blank FileCheck command; then,
+# the default substitution of FileCheck will replace it to its full path.
+config.substitutions.insert(0, (fc.regex,
+'FileCheck --allow-unused-prefixes=false'))
+
 config.suffixes = ['.c', '.cpp', '.h', '.m', '.mm', '.S', '.s', '.f90', '.F90', '.f95',
'.cu', '.rs', '.cl', '.hip']
 config.substitutions = list(config.substitutions)
Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -15,11 +15,11 @@
 // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN
 // 

[PATCH] D95653: [cte] [clang-tidy] Fix linking tests to LLVMTestingSupport

2021-01-28 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

I think I introduced this failure due to my abysmal knowledge of CMake and 
LLVM's library structure, So I'm definitely not qualified to say if this is a 
good fix, but seeing as it fixes the linker error I'll give it a tentative LG.


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

https://reviews.llvm.org/D95653

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


[clang] 7ef79bb - Fix typo in "[DebugInfo][CodeView] Use as the display name for lambdas."

2021-01-28 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-01-28T19:03:41-08:00
New Revision: 7ef79bb8e240aafab265107b8b7d63d3e32ddb93

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

LOG: Fix typo in "[DebugInfo][CodeView] Use  as the display name for 
lambdas."
(Commited in d5f5deee9ee996f078fb40ee20795539409523e4)

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp 
b/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
index ad781c8ed952..6b9c9a243dec 100644
--- a/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
+++ b/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -triple x86_64-windows-msvc -gcodeview
-// RUN: -debug-info-kind=line-tables-only -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-windows-msvc -gcodeview \
+// RUN:   -debug-info-kind=line-tables-only -emit-llvm -o - | FileCheck %s
 // Checks that clang with "-gline-tables-only" with CodeView emits some debug
 // info for variables and types when they appear in function scopes.
 



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


[PATCH] D94355: [SimplifyCFG] Add relative switch lookup tables

2021-01-28 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem marked 9 inline comments as done.
gulfem added inline comments.



Comment at: clang/test/CodeGen/switch-to-lookup-table.c:2
+// Check switch to lookup optimization in fPIC and fno-PIC mode
+// RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -O2 -fno-PIC -S 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=FNOPIC
+// RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -O2 -fPIC -S -emit-llvm 
-o - | FileCheck %s --check-prefix=CHECK --check-prefix=FPIC

hans wrote:
> Clang codegen tests are not normally used to test LLVM optimizations. I think 
> the tests for this should all live in LLVM, not Clang.
> 
> (Also aarch64 is not guaranteed to be included as a target in the LLVM build, 
> so this test would not necessarily run.)
I'm not able to use -fPIC and -fno-PIC options in the `opt` tool.
I am setting the `PIC Level` flag to enable -fPIC in `opt.
I thought that testing -fPIC and -fno-PIC in the same file seems easier and 
more readable  in CodeGen tests.
Please let me know if you have a good suggestion how to do that with `opt`.

I changed the target to `x86_64-linux` in this test.



Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:5709
+  return llvm::ConstantExpr::getTrunc(RelOffset,
+  Type::getInt32Ty(M.getContext()));
 }

hans wrote:
> I do worry about hard-coding this to 32 bits. As someone pointed out, it 
> would not necessary hold in all code models for x86.
> 
> Similarly to the PIC check in ShouldBuildRelLookupTable(), is there some 
> check we could do to make sure 32 bits is appropriate?
I added `x86_64` and `aarch64` target check and tiny or small code mode check 
to ensure 32 offsets.
Please let me know if you have any other concerns about that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94355

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


[PATCH] D95658: Make the profile-filter.c test compatible with 32-bit systems

2021-01-28 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: mgorny, davidxl, vsk.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This addresses PR48930.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95658

Files:
  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
@@ -28,11 +28,11 @@
 // EXCLUDE: noprofile
 // EXCLUDE: @test1
 unsigned test1() {
-  // CHECK: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x 
i64]* @__profc_test1, i64 0, i64 0), align 8
-  // FUNC: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x 
i64]* @__profc_test1, i64 0, i64 0), align 8
-  // FILE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x 
i64]* @__profc_test1, i64 0, i64 0), align 8
-  // SECTION-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x 
i64], [1 x i64]* @__profc_test1, i64 0, i64 0), align 8
-  // EXCLUDE-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x 
i64], [1 x i64]* @__profc_test1, i64 0, i64 0), align 8
+  // CHECK: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x 
i64]* @__profc_test1, i64 0, i64 0)
+  // FUNC: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x 
i64]* @__profc_test1, i64 0, i64 0)
+  // FILE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x 
i64]* @__profc_test1, i64 0, i64 0)
+  // SECTION-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x 
i64], [1 x i64]* @__profc_test1, i64 0, i64 0)
+  // EXCLUDE-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x 
i64], [1 x i64]* @__profc_test1, i64 0, i64 0)
   return i + 1;
 }
 
@@ -47,10 +47,10 @@
 // EXCLUDE-NOT: noprofile
 // EXCLUDE: @test2
 unsigned test2() {
-  // CHECK: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x 
i64]* @__profc_test2, i64 0, i64 0), align 8
-  // FUNC-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], 
[1 x i64]* @__profc_test2, i64 0, i64 0), align 8
-  // FILE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x 
i64]* @__profc_test2, i64 0, i64 0), align 8
-  // SECTION: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 
x i64]* @__profc_test2, i64 0, i64 0), align 8
-  // EXCLUDE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 
x i64]* @__profc_test2, i64 0, i64 0), align 8
+  // CHECK: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x 
i64]* @__profc_test2, i64 0, i64 0)
+  // FUNC-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], 
[1 x i64]* @__profc_test2, i64 0, i64 0)
+  // FILE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x 
i64]* @__profc_test2, i64 0, i64 0)
+  // SECTION: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 
x i64]* @__profc_test2, i64 0, i64 0)
+  // EXCLUDE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 
x i64]* @__profc_test2, i64 0, i64 0)
   return i - 1;
 }


Index: clang/test/CodeGen/profile-filter.c
===
--- clang/test/CodeGen/profile-filter.c
+++ clang/test/CodeGen/profile-filter.c
@@ -28,11 +28,11 @@
 // EXCLUDE: noprofile
 // EXCLUDE: @test1
 unsigned test1() {
-  // CHECK: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0), align 8
-  // FUNC: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0), align 8
-  // FILE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0), align 8
-  // SECTION-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0), align 8
-  // EXCLUDE-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0), align 8
+  // CHECK: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0)
+  // FUNC: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0)
+  // FILE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0)
+  // SECTION-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0)
+  // EXCLUDE-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0)
   return i + 1;
 }
 
@@ -47,10 +47,10 @@
 // EXCLUDE-NOT: noprofile
 // EXCLUDE: @test2
 unsigned test2() {
-  // CHECK: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test2, i64 0, i64 0), align 8
-  // FUNC-NOT: %pgocount = load i64, i64* getelementptr 

[PATCH] D95655: Adding Neon Sm3 & Sm4 Intrinsics

2021-01-28 Thread Ryan Santhirarajan via Phabricator via cfe-commits
rsanthir.quic added a comment.

This is the first in a series of patches that will address the following:
https://bugs.llvm.org/show_bug.cgi?id=47828


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95655

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


[PATCH] D94355: [SimplifyCFG] Add relative switch lookup tables

2021-01-28 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem updated this revision to Diff 320025.
gulfem added a comment.

1. Simplified test cases and increased readibility of the tables
2. Added x86_64 and aarch64 check and tiny or small code modes check to ensure 
32 offsets
3. Modified single value test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94355

Files:
  clang/test/CodeGen/switch-to-lookup-table.c
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/X86/switch_to_relative_lookup_table.ll

Index: llvm/test/Transforms/SimplifyCFG/X86/switch_to_relative_lookup_table.ll
===
--- /dev/null
+++ llvm/test/Transforms/SimplifyCFG/X86/switch_to_relative_lookup_table.ll
@@ -0,0 +1,211 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -simplifycfg -switch-to-lookup=true -keep-loops=false -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+; RUN: opt < %s -passes='simplify-cfg' -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@.str = private unnamed_addr constant [5 x i8] c"zero\00", align 1
+@.str.1 = private unnamed_addr constant [4 x i8] c"one\00", align 1
+@.str.2 = private unnamed_addr constant [4 x i8] c"two\00", align 1
+@.str.3 = private unnamed_addr constant [8 x i8] c"default\00", align 1
+@.str.4 = private unnamed_addr constant [6 x i8] c"three\00", align 1
+@.str.5 = private unnamed_addr constant [5 x i8] c"str1\00", align 1
+@.str.6 = private unnamed_addr constant [5 x i8] c"str2\00", align 1
+@.str.7 = private unnamed_addr constant [12 x i8] c"singlevalue\00", align 1
+
+; Relative string table lookup
+; CHECK: @switch.reltable.string_table = private unnamed_addr constant [3 x i32]
+; CHECK-SAME: [
+; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @switch.reltable.string_table to i64)) to i32),
+; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @switch.reltable.string_table to i64)) to i32),
+; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @switch.reltable.string_table to i64)) to i32)
+; CHECK-SAME: ], align 4
+
+; Relative string table lookup that holes are filled with relative offset to default values
+; CHECK: @switch.reltable.string_table_holes = private unnamed_addr constant [4 x i32]
+; CHECK-SAME: [
+; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @switch.reltable.string_table_holes to i64)) to i32),
+; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @switch.reltable.string_table_holes to i64)) to i32),
+; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @switch.reltable.string_table_holes to i64)) to i32),
+; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @switch.reltable.string_table_holes to i64)) to i32)
+; CHECK-SAME: ], align 4
+
+; Integer pointer table lookup
+; CHECK: @switch.table.no_dso_local = private unnamed_addr constant [7 x i32*] [i32* @a, i32* @b, i32* @c, i32* @d, i32* @e, i32* @f, i32* @g], align 8
+
+; Single value check
+; CHECK: @switch.reltable.single_value = private unnamed_addr constant [3 x i32]
+; CHECK-SAME: [
+; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @switch.reltable.single_value to i64)) to i32),
+; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @switch.reltable.single_value to i64)) to i32),
+; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @switch.reltable.single_value to i64)) to i32)
+; CHECK-SAME: ], align 4
+
+; Switch used to return a string.
+; Relative lookup table should be generated.
+define i8* @string_table(i32 %cond) {
+  ; CHECK-LABEL: @string_table(
+  ; CHECK-NEXT:  entry:
+  ; CHECK-NEXT:[[TMP0:%.*]] = icmp ult i32 [[COND:%.*]], 3
+  ; CHECK-NEXT:br i1 [[TMP0]], label [[SWITCH_LOOKUP:%.*]], label [[RETURN:%.*]]
+  ; CHECK:   switch.lookup:
+  ; CHECK-NEXT:[[SWITCH_RELTABLE_SHIFT:%.*]] = lshr i32 %cond, 2
+  ; CHECK-NEXT:[[SWITCH_RELTABLE_INTRINSIC:%.*]] = call i8* @llvm.load.relative.i32(i8* bitcast ([3 x i32]* @switch.reltable.string_table to i8*), i32 [[SWITCH_RELTABLE_SHIFT]])
+  ; CHECK-NEXT:ret i8* [[SWITCH_RELTABLE_INTRINSIC]]
+  ; CHECK:   return:
+  ; CHECK-NEXT:ret i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
+entry:
+  switch i32 %cond, label %sw.default [
+i32 0, label %return
+ 

[PATCH] D95403: [clang-tidy][analyzer][WIP] Clang-tidy reverse integration into Static Analyzer.

2021-01-28 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:54-60
+#include "../../clang-tools-extra/clang-tidy/ClangTidyCheck.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyForceLinker.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyModule.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyModuleRegistry.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyOptions.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyProfiling.h"

Isn't this a layering violation, since clang-tidy depends on 
clangStaticAnalyzerCore and clangStaticAnalyzerFrontend?


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

https://reviews.llvm.org/D95403

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


[PATCH] D95187: [DebugInfo][CodeView] Use as the display name for lambdas.

2021-01-28 Thread Amy Huang 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 rGd5f5deee9ee9: Reland [DebugInfo][CodeView] Use 
lambda_n as the display name for lambdas (authored by akhuang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95187

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
  clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Index: clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
===
--- clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
+++ clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
@@ -1,17 +1,26 @@
-// RUN: %clang_cc1 %s -gcodeview -debug-info-kind=line-tables-only -S \
-// RUN:   -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-windows-msvc -gcodeview
+// RUN: -debug-info-kind=line-tables-only -emit-llvm -o - | FileCheck %s
 // Checks that clang with "-gline-tables-only" with CodeView emits some debug
 // info for variables and types when they appear in function scopes.
 
 namespace NS {
 struct C {
   void m() {}
+  // Test externally visible lambda.
+  void lambda2() { []() {}(); }
+ 
+  // Test naming for function parameters.
+  void lambda_params(int x = [](){ return 0; }(), int y = [](){ return 1; }()) {}
 };
 void f() {}
 }
 
+// Test non- externally visible lambda.
+auto lambda1 = []() { return 1; };
+
 NS::C c;
 
+
 void test() {
   // CHECK: !DISubprogram(name: "f", scope: ![[NS:[0-9]+]],
   // CHECK-SAME:  type: ![[F:[0-9]+]]
@@ -21,10 +30,30 @@
   NS::f();
 
   // CHECK: ![[M:[0-9]+]] = distinct !DISubprogram(name: "m", scope: ![[C:[0-9]+]],
-  // CHECK-SAME:   type: ![[MTYPE:[0-9]+]]
+  // CHECK-SAME:   type: ![[MTYPE:[0-9]+]],
   // CHECK: ![[C]] = !DICompositeType(tag: DW_TAG_structure_type, name: "C",
   // CHECK-SAME:  flags: DIFlagFwdDecl
   // CHECK-NOT: identifier
   // CHECK: ![[MTYPE]] = !DISubroutineType({{.*}}types: !{{.*}})
   c.m();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA0:[0-9]+]],
+  // CHECK: ![[LAMBDA0]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:name: "",
+  // CHECK-SAME:flags: DIFlagFwdDecl
+  lambda1();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1_1:[0-9]+]],
+  // CHECK: ![[LAMBDA1_1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:  name: "",
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA2_1:[0-9]+]],
+  // CHECK: ![[LAMBDA2_1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:  name: "",
+  c.lambda_params();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1:[0-9]+]],
+  // CHECK: ![[LAMBDA1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:name: "",
+  // CHECK-SAME:flags: DIFlagFwdDecl
+  c.lambda2();
 }
Index: clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
===
--- clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
+++ clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
@@ -100,7 +100,7 @@
   // MSVC-SAME:  )
   // MSVC:   [[TYPE_OF_FOUR]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_class_type
-  // MSVC-NOT:   name:
+  // MSVC-SAME:  name: ""
   // MSVC-SAME:  identifier: ".?AV@?0??main@@9@"
   // MSVC-SAME:  )
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -317,8 +317,9 @@
   if (const IdentifierInfo *II = RD->getIdentifier())
 return II->getName();
 
-  // The CodeView printer in LLVM wants to see the names of unnamed types: it is
-  // used to reconstruct the fully qualified type names.
+  // The CodeView printer in LLVM wants to see the names of unnamed types
+  // because they need to have a unique identifier.
+  // These names are used to reconstruct the fully qualified type names.
   if (CGM.getCodeGenOpts().EmitCodeView) {
 if (const TypedefNameDecl *D = RD->getTypedefNameForAnonDecl()) {
   assert(RD->getDeclContext() == D->getDeclContext() &&
@@ -342,6 +343,12 @@
 // associate typedef mangled in if they have one.
 Name = TND->getName();
 
+  // Give lambdas a display name based on their name mangling.
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+if (CXXRD->isLambda())
+  return 

[PATCH] D95187: [DebugInfo][CodeView] Use as the display name for lambdas.

2021-01-28 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 320020.
akhuang added a comment.

Fix test / string code after test failures


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95187

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
  clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Index: clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
===
--- clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
+++ clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
@@ -1,17 +1,26 @@
-// RUN: %clang_cc1 %s -gcodeview -debug-info-kind=line-tables-only -S \
-// RUN:   -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-windows-msvc -gcodeview
+// RUN: -debug-info-kind=line-tables-only -emit-llvm -o - | FileCheck %s
 // Checks that clang with "-gline-tables-only" with CodeView emits some debug
 // info for variables and types when they appear in function scopes.
 
 namespace NS {
 struct C {
   void m() {}
+  // Test externally visible lambda.
+  void lambda2() { []() {}(); }
+ 
+  // Test naming for function parameters.
+  void lambda_params(int x = [](){ return 0; }(), int y = [](){ return 1; }()) {}
 };
 void f() {}
 }
 
+// Test non- externally visible lambda.
+auto lambda1 = []() { return 1; };
+
 NS::C c;
 
+
 void test() {
   // CHECK: !DISubprogram(name: "f", scope: ![[NS:[0-9]+]],
   // CHECK-SAME:  type: ![[F:[0-9]+]]
@@ -21,10 +30,30 @@
   NS::f();
 
   // CHECK: ![[M:[0-9]+]] = distinct !DISubprogram(name: "m", scope: ![[C:[0-9]+]],
-  // CHECK-SAME:   type: ![[MTYPE:[0-9]+]]
+  // CHECK-SAME:   type: ![[MTYPE:[0-9]+]],
   // CHECK: ![[C]] = !DICompositeType(tag: DW_TAG_structure_type, name: "C",
   // CHECK-SAME:  flags: DIFlagFwdDecl
   // CHECK-NOT: identifier
   // CHECK: ![[MTYPE]] = !DISubroutineType({{.*}}types: !{{.*}})
   c.m();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA0:[0-9]+]],
+  // CHECK: ![[LAMBDA0]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:name: "",
+  // CHECK-SAME:flags: DIFlagFwdDecl
+  lambda1();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1_1:[0-9]+]],
+  // CHECK: ![[LAMBDA1_1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:  name: "",
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA2_1:[0-9]+]],
+  // CHECK: ![[LAMBDA2_1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:  name: "",
+  c.lambda_params();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1:[0-9]+]],
+  // CHECK: ![[LAMBDA1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:name: "",
+  // CHECK-SAME:flags: DIFlagFwdDecl
+  c.lambda2();
 }
Index: clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
===
--- clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
+++ clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
@@ -100,7 +100,7 @@
   // MSVC-SAME:  )
   // MSVC:   [[TYPE_OF_FOUR]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_class_type
-  // MSVC-NOT:   name:
+  // MSVC-SAME:  name: ""
   // MSVC-SAME:  identifier: ".?AV@?0??main@@9@"
   // MSVC-SAME:  )
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -317,8 +317,9 @@
   if (const IdentifierInfo *II = RD->getIdentifier())
 return II->getName();
 
-  // The CodeView printer in LLVM wants to see the names of unnamed types: it is
-  // used to reconstruct the fully qualified type names.
+  // The CodeView printer in LLVM wants to see the names of unnamed types
+  // because they need to have a unique identifier.
+  // These names are used to reconstruct the fully qualified type names.
   if (CGM.getCodeGenOpts().EmitCodeView) {
 if (const TypedefNameDecl *D = RD->getTypedefNameForAnonDecl()) {
   assert(RD->getDeclContext() == D->getDeclContext() &&
@@ -342,6 +343,12 @@
 // associate typedef mangled in if they have one.
 Name = TND->getName();
 
+  // Give lambdas a display name based on their name mangling.
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+if (CXXRD->isLambda())
+  return internString(
+  CGM.getCXXABI().getMangleContext().getLambdaString(CXXRD));
+
   if (!Name.empty()) {
 SmallString<256> 

[PATCH] D95655: Adding Neon Sm3 & Sm4 Intrinsics

2021-01-28 Thread Ryan Santhirarajan via Phabricator via cfe-commits
rsanthir.quic created this revision.
rsanthir.quic added reviewers: t.p.northover, pbarrio.
Herald added subscribers: hiraditya, kristof.beyls.
rsanthir.quic requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This adds SM3 and SM4 Intrinsics support for AArch64, specifically:

  vsm3ss1q_u32
  vsm3tt1aq_u32
  vsm3tt1bq_u32
  vsm3tt2aq_u32
  vsm3tt2bq_u32
  vsm3partw1q_u32
  vsm3partw2q_u32
  vsm4eq_u32
  vsm4ekeyq_u32


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95655

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-sm4-sm3-invalid.c
  clang/test/CodeGen/aarch64-neon-sm4-sm3.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/test/CodeGen/AArch64/neon-sm4-sm3.ll

Index: llvm/test/CodeGen/AArch64/neon-sm4-sm3.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/neon-sm4-sm3.ll
@@ -0,0 +1,103 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc %s -mtriple=aarch64 -mattr=+v8.3a,+sm4 -o - | FileCheck %s
+
+define <4 x i32> @test_vsm3partw1(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
+; CHECK-LABEL: test_vsm3partw1:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sm3partw1 v0.4s, v1.4s, v2.4s
+; CHECK-NEXT:ret
+entry:
+  %vsm3partw1.i = tail call <4 x i32> @llvm.aarch64.crypto.sm3partw1(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c)
+  ret <4 x i32> %vsm3partw1.i
+}
+
+define <4 x i32> @test_vsm3partw2(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
+; CHECK-LABEL: test_vsm3partw2:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sm3partw2 v0.4s, v1.4s, v2.4s
+; CHECK-NEXT:ret
+entry:
+  %vsm3partw2.i = tail call <4 x i32> @llvm.aarch64.crypto.sm3partw2(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c)
+  ret <4 x i32> %vsm3partw2.i
+}
+
+define <4 x i32> @test_vsm3ss1(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, <4 x i32> %d) {
+; CHECK-LABEL: test_vsm3ss1:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sm3ss1 v0.4s, v0.4s, v1.4s, v2.4s
+; CHECK-NEXT:ret
+entry:
+  %vsm3ss1.i = tail call <4 x i32> @llvm.aarch64.crypto.sm3ss1(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c)
+  ret <4 x i32> %vsm3ss1.i
+}
+
+define <4 x i32> @test_vsm3tt1a(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
+; CHECK-LABEL: test_vsm3tt1a:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sm3tt1a v0.4s, v1.4s, v2.s[2]
+; CHECK-NEXT:ret
+entry:
+  %vsm3tt1a.i = tail call <4 x i32> @llvm.aarch64.crypto.sm3tt1a(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, i64 2)
+  ret <4 x i32> %vsm3tt1a.i
+}
+
+define <4 x i32> @test_vsm3tt1b(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
+; CHECK-LABEL: test_vsm3tt1b:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sm3tt1b v0.4s, v1.4s, v2.s[2]
+; CHECK-NEXT:ret
+entry:
+  %vsm3tt1b.i = tail call <4 x i32> @llvm.aarch64.crypto.sm3tt1b(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, i64 2)
+  ret <4 x i32> %vsm3tt1b.i
+}
+
+define <4 x i32> @test_vsm3tt2a(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
+; CHECK-LABEL: test_vsm3tt2a:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sm3tt2a v0.4s, v1.4s, v2.s[2]
+; CHECK-NEXT:ret
+entry:
+  %vsm3tt2a.i = tail call <4 x i32> @llvm.aarch64.crypto.sm3tt2a(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, i64 2)
+  ret <4 x i32> %vsm3tt2a.i
+}
+
+define <4 x i32> @test_vsm3tt2b(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
+; CHECK-LABEL: test_vsm3tt2b:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sm3tt2b v0.4s, v1.4s, v2.s[2]
+; CHECK-NEXT:ret
+entry:
+  %vsm3tt2b.i = tail call <4 x i32> @llvm.aarch64.crypto.sm3tt2b(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, i64 2)
+  ret <4 x i32> %vsm3tt2b.i
+}
+
+define <4 x i32> @test_vsm4e(<4 x i32> %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vsm4e:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sm4e v1.4s, v0.4s
+; CHECK-NEXT:mov v0.16b, v1.16b
+; CHECK-NEXT:ret
+entry:
+  %vsm4e.i = tail call <4 x i32> @llvm.aarch64.crypto.sm4e(<4 x i32> %a, <4 x i32> %b)
+  ret <4 x i32> %vsm4e.i
+}
+
+define <4 x i32> @test_vsm4ekey(<4 x i32> %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vsm4ekey:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sm4ekey v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+entry:
+  %vsm4ekey.i = tail call <4 x i32> @llvm.aarch64.crypto.sm4ekey(<4 x i32> %a, <4 x i32> %b)
+  ret <4 x i32> %vsm4ekey.i
+}
+
+declare <4 x i32> @llvm.aarch64.crypto.sm3partw1(<4 x i32>, <4 x i32>, <4 x i32>)
+declare <4 x i32> @llvm.aarch64.crypto.sm3partw2(<4 x i32>, <4 x i32>, <4 x i32>)
+declare <4 x i32> @llvm.aarch64.crypto.sm3ss1(<4 x i32>, <4 x i32>, <4 x i32>)
+declare <4 x i32> @llvm.aarch64.crypto.sm3tt1a(<4 x i32>, <4 x i32>, <4 x i32>, i64 immarg)
+declare <4 x i32> @llvm.aarch64.crypto.sm3tt2b(<4 x i32>, <4 x i32>, <4 x i32>, i64 immarg)
+declare <4 x i32> 

[PATCH] D95166: Disable rosegment for old Android versions.

2021-01-28 Thread Dan Albert via Phabricator via cfe-commits
danalbert added a comment.

In D95166#2529412 , @dmajor wrote:

> It does feel kind of awkward to me that _this_ is the patch that ends up 
> breaking the builds, versus something at the cmake level that says "you are 
> explicitly unsupported".

If you're using our CMake toolchain file you're automatically migrated to LLD 
unless you pass `-DANDROID_LD=deprecated` starting with NDK r22. If you're not 
using our toolchain file there unfortunately was no way for us to have any kind 
of input to that process.

r22 is fairly new, but this patch isn't expected to be in a stable NDK until 
several months from now. It takes us quite a while to move from a patch being 
submitted to clang to being shipped in a stable NDK, so that's why we're doing 
this now. We do try pretty hard to adhere to a deprecation window so people 
have time to adapt, but we're now working on Clang features that are beyond the 
end of the window (features we'd have preferred to land last summer, but didn't 
specifically to avoid breaking binutils compatibility). Clang is the //last// 
place that migration changes land, so using TOT clang but an older NDK means 
you started getting incompatible features before you got any of the warnings 
from the tools.

> Also it's unfortunate that this landed just hours before 12.0.0 branched. Had 
> it landed slightly later, release users could have six months to plan for the 
> change. You say that the next NDK compiler is based on ToT, in that case 
> would it make sense to revert this on the 12.x branch, and add a warning to 
> the 12.0.0 release notes that lld will be assumed in 13?

Would have waited if I'd known :( No objection to reverting in the 12.x release 
branch. We don't ship from the release branches anyway so reverting in 12.x 
keeps your next release the way you want it keeps ours the way we want it. Feel 
free to do that, or I can do it tomorrow.

FWIW, we gave //much// more than six months notice that Android was dropping 
support for binutils: https://github.com/android/ndk/wiki/Changelog-r19-beta1. 
We did even communicate it specifically to Firefox, I believe: 
https://github.com/android/ndk/issues/1063.

In D95166#2529432 , @glandium wrote:

> If clang _really_ wants to assume lld as the linker for android, then it 
> should make using -fuse-ld=somethingelse an error and invoke ld.lld rather 
> than ld, if it doesn't already do that.

The other patch I linked  does the second part 
of that and would make it possible to continue working with gold/bfd (even if 
Android has no intention to support that workflow). I'll rebase that and 
restore the review to try again. I'd also much prefer to be able to do this in 
a way that doesn't so forcibly break compatibility but that wasn't an option 
without that patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95166

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


[PATCH] D49864: [clang-tidy] The script clang-tidy-diff.py doesn't accept 'pass by' options (--)

2021-01-28 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

Apologies again for the long delay.

A diff with full context would still be appreciated. Please read 
https://llvm.org/docs/Phabricator.html for instructions.

The clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp test 
needs to be updated accordingly. See Diff Detail -> Build Status for the build 
results after uploading a patch to Phabricator.




Comment at: clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py:128
+  parser.add_argument('-strip', metavar='NUM', default=0,
+  help='strip the smallest prefix containing N slashes')
   parser.add_argument('-regex', metavar='PATTERN', default=None,

s/N/NUM/ ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D49864

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


[PATCH] D89380: [clang-tidy] Fix for cppcoreguidelines-prefer-member-initializer to handle classes declared in macros

2021-01-28 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.
Herald added a subscriber: shchenz.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:6
+//of this test file) is the macro itself and the spelling location is
+//:6:1 for some strange reason. This results this 
warning
+//to be placed at the very beginning of the message list.

"results in ..."



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:6
+//of this test file) is the macro itself and the spelling location is
+//:6:1 for some strange reason. This results this 
warning
+//to be placed at the very beginning of the message list.

alexfh wrote:
> "results in ..."
The reason is that token pasting is used in the macro. There is no place in any 
of the existing source files where the text of the token that is created by 
token pasting exists (verbatim and contiguously).



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:7
+//:6:1 for some strange reason. This results this 
warning
+//to be placed at the very beginning of the message list.
+

"being"?



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:500
+// CHECK-MESSAGES: :[[@LINE-1]]:54: warning: 'i' should be initialized in a 
member initializer of the constructor 
[cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: #define MACRO1 struct InMacro1 { int i; InMacro1() : i(0) { } 
};
+MACRO1

Please add CHECK-FIXES: for the macro usage (unchanged, I suppose?). Same below.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:514-515
+#define MACRO4(field) struct InMacro4 { int field; InMacro4() { field = 0; } };
+// C_HECK-MESSAGES: :[[@LINE-1]]:65: warning: 'field' should be initialized in 
a member initializer of the constructor 
[cppcoreguidelines-prefer-member-initializer]
+// C_HECK-FIXES: #define MACRO4(field) struct InMacro4 { int field; InMacro4() 
: field(0) { } };
+MACRO4(q)

Do we need these disabled check lines? If so, please mention the reason in a 
comment.

Same below.


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

https://reviews.llvm.org/D89380

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


[PATCH] D95562: [ASTMatchers] Fix traversal below range-for elements

2021-01-28 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95562

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


[PATCH] D95607: Fix traversal with hasDescendant into lambdas

2021-01-28 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95607

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


[PATCH] D95653: [cte] [clang-tidy] Fix linking tests to LLVMTestingSupport

2021-01-28 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: njames93, aaron.ballman.
Herald added subscribers: usaxena95, kadircet, xazax.hun.
mgorny requested review of this revision.
Herald added a subscriber: ilya-biryukov.

LLVMTestingSupport is not part of libLLVM, and therefore can not
be linked to via LLVM_LINK_COMPONENTS.  Instead, it needs to be
specified explicitly to ensure that it is linked explicitly
even if LLVM_LINK_LLVM_DYLIB is used.  This is consistent with handling
in clangd.

Fixes PR#48931


https://reviews.llvm.org/D95653

Files:
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt


Index: clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
===
--- clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
+++ clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
@@ -1,7 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   FrontendOpenMP
   Support
-  TestingSupport
   )
 
 get_filename_component(CLANG_LINT_SOURCE_DIR
@@ -46,4 +45,5 @@
   clangTidyObjCModule
   clangTidyReadabilityModule
   clangTidyUtils
+  LLVMTestingSupport
   )


Index: clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
===
--- clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
+++ clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
@@ -1,7 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   FrontendOpenMP
   Support
-  TestingSupport
   )
 
 get_filename_component(CLANG_LINT_SOURCE_DIR
@@ -46,4 +45,5 @@
   clangTidyObjCModule
   clangTidyReadabilityModule
   clangTidyUtils
+  LLVMTestingSupport
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95017: [clang-format] Add case aware include sorting.

2021-01-28 Thread Kent Sommer via Phabricator via cfe-commits
kentsommer updated this revision to Diff 320007.
kentsommer added a comment.

NFC rebase to fix CI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95017

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/SortImportsTestJava.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -269,7 +269,7 @@
 }
 
 TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) {
-  FmtStyle.SortIncludes = false;
+  FmtStyle.SortIncludes = FormatStyle::SI_Never;
   EXPECT_EQ("#include \"a.h\"\n"
 "#include \"c.h\"\n"
 "#include \"b.h\"\n",
@@ -598,6 +598,49 @@
  "a.cc"));
 }
 
+TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveSorting) {
+  EXPECT_FALSE(FmtStyle.SortIncludes == FormatStyle::SI_CaseSensitive);
+
+  FmtStyle.SortIncludes = FormatStyle::SI_CaseSensitive;
+
+  EXPECT_EQ("#include \"A/B.h\"\n"
+"#include \"A/b.h\"\n"
+"#include \"a/b.h\"\n"
+"#include \"B/A.h\"\n"
+"#include \"B/a.h\"\n",
+sort("#include \"B/a.h\"\n"
+ "#include \"B/A.h\"\n"
+ "#include \"A/B.h\"\n"
+ "#include \"a/b.h\"\n"
+ "#include \"A/b.h\"\n",
+ "a.h"));
+
+  Style.IncludeBlocks = clang::tooling::IncludeStyle::IBS_Regroup;
+  Style.IncludeCategories = {
+  {"^\"", 1, 0, false}, {"^<.*\\.h>$", 2, 0, false}, {"^<", 3, 0, false}};
+
+  StringRef UnsortedCode = "#include \"qt.h\"\n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \"vlib.h\"\n"
+   "#include \"Vlib.h\"\n"
+   "#include \"AST.h\"\n";
+
+  EXPECT_EQ("#include \"AST.h\"\n"
+"#include \"qt.h\"\n"
+"#include \"Vlib.h\"\n"
+"#include \"vlib.h\"\n"
+"\n"
+"#include \n"
+"#include \n"
+"\n"
+"#include \n"
+"#include \n",
+sort(UnsortedCode));
+}
+
 TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) {
   // Setup an regex for main includes so we can cover those as well.
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
Index: clang/unittests/Format/SortImportsTestJava.cpp
===
--- clang/unittests/Format/SortImportsTestJava.cpp
+++ clang/unittests/Format/SortImportsTestJava.cpp
@@ -32,7 +32,7 @@
   SortImportsTestJava() {
 FmtStyle = getGoogleStyle(FormatStyle::LK_Java);
 FmtStyle.JavaImportGroups = {"com.test", "org", "com"};
-FmtStyle.SortIncludes = true;
+FmtStyle.SortIncludes = FormatStyle::SI_CaseInsensitive;
   }
 };
 
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15463,7 +15463,6 @@
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
   CHECK_PARSE_BOOL(Cpp11BracedListStyle);
   CHECK_PARSE_BOOL(ReflowComments);
-  CHECK_PARSE_BOOL(SortIncludes);
   CHECK_PARSE_BOOL(SortUsingDeclarations);
   CHECK_PARSE_BOOL(SpacesInParentheses);
   CHECK_PARSE_BOOL(SpacesInSquareBrackets);
@@ -15959,6 +15958,16 @@
   CHECK_PARSE("IncludeIsMainSourceRegex: 'abc$'",
   IncludeStyle.IncludeIsMainSourceRegex, "abc$");
 
+  Style.SortIncludes = FormatStyle::SI_Never;
+  CHECK_PARSE("SortIncludes: true", SortIncludes,
+  FormatStyle::SI_CaseInsensitive);
+  CHECK_PARSE("SortIncludes: false", SortIncludes, FormatStyle::SI_Never);
+  CHECK_PARSE("SortIncludes: CaseInsensitive", SortIncludes,
+  FormatStyle::SI_CaseInsensitive);
+  CHECK_PARSE("SortIncludes: CaseSensitive", SortIncludes,
+  FormatStyle::SI_CaseSensitive);
+  CHECK_PARSE("SortIncludes: Never", SortIncludes, FormatStyle::SI_Never);
+
   Style.RawStringFormats.clear();
   std::vector ExpectedRawStringFormats = {
   {
@@ -17950,7 +17959,7 @@
 "#include \"b.h\"\n")});
 
   format::FormatStyle Style = format::getLLVMStyle();
-  Style.SortIncludes = true;
+  Style.SortIncludes = FormatStyle::SI_CaseInsensitive;
   auto FormattedReplaces = formatReplacements(Code, Replaces, Style);
   EXPECT_TRUE(static_cast(FormattedReplaces))
   << llvm::toString(FormattedReplaces.takeError()) << "\n";
Index: 

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

2021-01-28 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 320001.
ahatanak added a comment.
Herald added a subscriber: laytonio.

Teach `markTails` to ignore operand bundle `clang.arc.rv` when determining 
whether a call can be marked as tail. `ObjCARCOpt::OptimizeReturn` cannot 
eliminate the retainRV/autoreleaseRV pair if the call isn't marked as tail.


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/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(

[PATCH] D95396: Improve static_assert/_Static_assert diagnostics

2021-01-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:874-876
+if (!getLangOpts().CPlusPlus)
+  Diag(Tok, diag::warn_cxx_static_assert_in_c)
+  << FixItHint::CreateReplacement(Tok.getLocation(), "_Static_assert");

I don't think this diagnostic is useful as-is: on Windows, including 
`` doesn't help because it doesn't `#define static_assert`. And 
people hitting this also can't switch to using `_Static_assert`, because MSVC 
doesn't provide it, only `static_assert`.

If we want to warn here, we could perhaps check whether `` has been 
included, but getting that check correct across PCH / modules is not 
straightforward. (If we knew what include guard the CRT's `assert.h` used (if 
any), I guess we could check whether that's defined, but that'd be a bit of a 
hack.) But I'm somewhat inclined to think we don't have a good way to 
distinguish between the good cases and the bad ones, so we shouldn't warn. 
Hopefully MS will fix their CRT at some point and we can stop providing this 
compatibility hack entirely (or start warning on it by default).


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

https://reviews.llvm.org/D95396

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


[PATCH] D95644: Ensure that we traverse non-op() method bodys of lambdas

2021-01-28 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 rG43cc4f15008f: Ensure that we traverse non-op() method bodys 
of lambdas (authored by stephenkelly).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95644

Files:
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -474,6 +474,42 @@
   EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureThis));
 }
 
+TEST(Matcher, MatchesMethodsOnLambda) {
+  StringRef Code = R"cpp(
+struct A {
+  ~A() {}
+};
+void foo()
+{
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;
+  auto lPtrDecay = +[] { };
+  (void)lPtrDecay;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isCopyConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isMoveConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxDestructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l";
+  EXPECT_TRUE(matches(
+  Code, cxxConversionDecl(hasBody(compoundStmt(has(returnStmt(
+  hasReturnValue(implicitCastExpr()),
+  hasAncestor(lambdaExpr(hasAncestor(
+  varDecl(hasName("lPtrDecay";
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2062,7 +2062,8 @@
 
   if (const auto *MD = dyn_cast(D)) {
 if (const CXXRecordDecl *RD = MD->getParent()) {
-  if (RD->isLambda()) {
+  if (RD->isLambda() &&
+  declaresSameEntity(RD->getLambdaCallOperator(), MD)) {
 VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
   }
 }


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -474,6 +474,42 @@
   EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureThis));
 }
 
+TEST(Matcher, MatchesMethodsOnLambda) {
+  StringRef Code = R"cpp(
+struct A {
+  ~A() {}
+};
+void foo()
+{
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;
+  auto lPtrDecay = +[] { };
+  (void)lPtrDecay;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isCopyConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isMoveConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxDestructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l";
+  EXPECT_TRUE(matches(
+  Code, cxxConversionDecl(hasBody(compoundStmt(has(returnStmt(
+  hasReturnValue(implicitCastExpr()),
+  hasAncestor(lambdaExpr(hasAncestor(
+  varDecl(hasName("lPtrDecay";
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2062,7 +2062,8 @@
 
   if (const auto *MD = dyn_cast(D)) {
 if (const CXXRecordDecl *RD = MD->getParent()) {
-  if (RD->isLambda()) {
+  if (RD->isLambda() &&
+  declaresSameEntity(RD->getLambdaCallOperator(), MD)) {
 VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] 43cc4f1 - Ensure that we traverse non-op() method bodys of lambdas

2021-01-28 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-01-29T00:49:28Z
New Revision: 43cc4f15008f8c700497d3d2b7020bfd29f5750f

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

LOG: Ensure that we traverse non-op() method bodys of lambdas

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

Added: 


Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index db2ef21f4364..7870cea198a7 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2062,7 +2062,8 @@ bool 
RecursiveASTVisitor::TraverseFunctionHelper(FunctionDecl *D) {
 
   if (const auto *MD = dyn_cast(D)) {
 if (const CXXRecordDecl *RD = MD->getParent()) {
-  if (RD->isLambda()) {
+  if (RD->isLambda() &&
+  declaresSameEntity(RD->getLambdaCallOperator(), MD)) {
 VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
   }
 }

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 8004599e01a2..a3a09c426673 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -474,6 +474,42 @@ TEST(Matcher, CapturesThis) {
   EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureThis));
 }
 
+TEST(Matcher, MatchesMethodsOnLambda) {
+  StringRef Code = R"cpp(
+struct A {
+  ~A() {}
+};
+void foo()
+{
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;
+  auto lPtrDecay = +[] { };
+  (void)lPtrDecay;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isCopyConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isMoveConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxDestructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l";
+  EXPECT_TRUE(matches(
+  Code, cxxConversionDecl(hasBody(compoundStmt(has(returnStmt(
+  hasReturnValue(implicitCastExpr()),
+  hasAncestor(lambdaExpr(hasAncestor(
+  varDecl(hasName("lPtrDecay";
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "



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


Re: [clang] 9b21d4b - Revert "[DebugInfo][CodeView] Use as the display name for lambdas."

2021-01-28 Thread Richard Smith via cfe-commits
On Thu, 28 Jan 2021 at 16:41, Amy Huang via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Amy Huang
> Date: 2021-01-28T16:41:26-08:00
> New Revision: 9b21d4b9434d2d4796b0d60d64f6ded9bac95441
>
> URL:
> https://github.com/llvm/llvm-project/commit/9b21d4b9434d2d4796b0d60d64f6ded9bac95441
> DIFF:
> https://github.com/llvm/llvm-project/commit/9b21d4b9434d2d4796b0d60d64f6ded9bac95441.diff
>
> LOG: Revert "[DebugInfo][CodeView] Use  as the display name for
> lambdas."
> for test failures.
>
> This reverts commit d73564c510036b2d4f5858effdcd23fe54fc1063.
>

Please include a reason for the revert in the commit message in future
reverts -- this helps people looking back over the history to understand
what happened and why. Thanks!


> Added:
>
>
> Modified:
> clang/include/clang/AST/Mangle.h
> clang/lib/AST/ItaniumMangle.cpp
> clang/lib/AST/MicrosoftMangle.cpp
> clang/lib/CodeGen/CGDebugInfo.cpp
> clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
> clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/include/clang/AST/Mangle.h
> b/clang/include/clang/AST/Mangle.h
> index f8f44853567f..0e8d6dd53d8a 100644
> --- a/clang/include/clang/AST/Mangle.h
> +++ b/clang/include/clang/AST/Mangle.h
> @@ -89,17 +89,6 @@ class MangleContext {
>  return Result.first->second;
>}
>
> -  uint64_t getAnonymousStructIdForDebugInfo(const NamedDecl *D) {
> -llvm::DenseMap::iterator Result =
> -AnonStructIds.find(D);
> -// The decl should already be inserted, but return 0 in case it is
> not.
> -if (Result == AnonStructIds.end())
> -  return 0;
> -return Result->second;
> -  }
> -
> -  virtual StringRef getLambdaString(const CXXRecordDecl *Lambda) = 0;
> -
>/// @name Mangler Entry Points
>/// @{
>
>
> diff  --git a/clang/lib/AST/ItaniumMangle.cpp
> b/clang/lib/AST/ItaniumMangle.cpp
> index 265c2172801c..4420f6a2c1c3 100644
> --- a/clang/lib/AST/ItaniumMangle.cpp
> +++ b/clang/lib/AST/ItaniumMangle.cpp
> @@ -203,36 +203,6 @@ class ItaniumMangleContextImpl : public
> ItaniumMangleContext {
>  disc = discriminator-2;
>  return true;
>}
> -
> -  StringRef getLambdaString(const CXXRecordDecl *Lambda) override {
> -// This function matches the one in MicrosoftMangle, which returns
> -// the string that is used in lambda mangled names.
> -assert(Lambda->isLambda() && "RD must be a lambda!");
> -llvm::SmallString<10> Name(" -Decl *LambdaContextDecl = Lambda->getLambdaContextDecl();
> -unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
> -unsigned LambdaId;
> -const ParmVarDecl *Parm =
> dyn_cast_or_null(LambdaContextDecl);
> -const FunctionDecl *Func =
> -Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
> -
> -if (Func) {
> -  unsigned DefaultArgNo =
> -  Func->getNumParams() - Parm->getFunctionScopeIndex();
> -  Name += llvm::utostr(DefaultArgNo);
> -  Name += "_";
> -}
> -
> -if (LambdaManglingNumber)
> -  LambdaId = LambdaManglingNumber;
> -else
> -  LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
> -
> -Name += llvm::utostr(LambdaId);
> -Name += '>';
> -return StringRef(Name);
> -  }
> -
>/// @}
>  };
>
>
> diff  --git a/clang/lib/AST/MicrosoftMangle.cpp
> b/clang/lib/AST/MicrosoftMangle.cpp
> index aaaba62a0fd4..9eac3586c871 100644
> --- a/clang/lib/AST/MicrosoftMangle.cpp
> +++ b/clang/lib/AST/MicrosoftMangle.cpp
> @@ -228,34 +228,6 @@ class MicrosoftMangleContextImpl : public
> MicrosoftMangleContext {
>  return true;
>}
>
> -  StringRef getLambdaString(const CXXRecordDecl *Lambda) override {
> -assert(Lambda->isLambda() && "RD must be a lambda!");
> -llvm::SmallString<10> Name(" -
> -Decl *LambdaContextDecl = Lambda->getLambdaContextDecl();
> -unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
> -unsigned LambdaId;
> -const ParmVarDecl *Parm =
> dyn_cast_or_null(LambdaContextDecl);
> -const FunctionDecl *Func =
> -Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
> -
> -if (Func) {
> -  unsigned DefaultArgNo =
> -  Func->getNumParams() - Parm->getFunctionScopeIndex();
> -  Name += llvm::utostr(DefaultArgNo);
> -  Name += "_";
> -}
> -
> -if (LambdaManglingNumber)
> -  LambdaId = LambdaManglingNumber;
> -else
> -  LambdaId = getLambdaIdForDebugInfo(Lambda);
> -
> -Name += llvm::utostr(LambdaId);
> -Name += ">";
> -return StringRef(Name);
> -  }
> -
>unsigned getLambdaId(const CXXRecordDecl *RD) {
>  assert(RD->isLambda() && "RD must be a lambda!");
>  assert(!RD->isExternallyVisible() && "RD must not be visible!");
> @@ -266,19 +238,6 @@ class MicrosoftMangleContextImpl : public
> MicrosoftMangleContext {
>  return Result.first->second;
>}
>
> -  

[clang] 9b21d4b - Revert "[DebugInfo][CodeView] Use as the display name for lambdas."

2021-01-28 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-01-28T16:41:26-08:00
New Revision: 9b21d4b9434d2d4796b0d60d64f6ded9bac95441

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

LOG: Revert "[DebugInfo][CodeView] Use  as the display name for 
lambdas."
for test failures.

This reverts commit d73564c510036b2d4f5858effdcd23fe54fc1063.

Added: 


Modified: 
clang/include/clang/AST/Mangle.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Mangle.h 
b/clang/include/clang/AST/Mangle.h
index f8f44853567f..0e8d6dd53d8a 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST/Mangle.h
@@ -89,17 +89,6 @@ class MangleContext {
 return Result.first->second;
   }
 
-  uint64_t getAnonymousStructIdForDebugInfo(const NamedDecl *D) {
-llvm::DenseMap::iterator Result =
-AnonStructIds.find(D);
-// The decl should already be inserted, but return 0 in case it is not.
-if (Result == AnonStructIds.end())
-  return 0;
-return Result->second;
-  }
-
-  virtual StringRef getLambdaString(const CXXRecordDecl *Lambda) = 0;
-
   /// @name Mangler Entry Points
   /// @{
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 265c2172801c..4420f6a2c1c3 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -203,36 +203,6 @@ class ItaniumMangleContextImpl : public 
ItaniumMangleContext {
 disc = discriminator-2;
 return true;
   }
-
-  StringRef getLambdaString(const CXXRecordDecl *Lambda) override {
-// This function matches the one in MicrosoftMangle, which returns
-// the string that is used in lambda mangled names.
-assert(Lambda->isLambda() && "RD must be a lambda!");
-llvm::SmallString<10> Name("getLambdaContextDecl();
-unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
-unsigned LambdaId;
-const ParmVarDecl *Parm = dyn_cast_or_null(LambdaContextDecl);
-const FunctionDecl *Func =
-Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
-
-if (Func) {
-  unsigned DefaultArgNo =
-  Func->getNumParams() - Parm->getFunctionScopeIndex();
-  Name += llvm::utostr(DefaultArgNo);
-  Name += "_";
-}
-
-if (LambdaManglingNumber)
-  LambdaId = LambdaManglingNumber;
-else
-  LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
-
-Name += llvm::utostr(LambdaId);
-Name += '>';
-return StringRef(Name);
-  }
-
   /// @}
 };
 

diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index aaaba62a0fd4..9eac3586c871 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -228,34 +228,6 @@ class MicrosoftMangleContextImpl : public 
MicrosoftMangleContext {
 return true;
   }
 
-  StringRef getLambdaString(const CXXRecordDecl *Lambda) override {
-assert(Lambda->isLambda() && "RD must be a lambda!");
-llvm::SmallString<10> Name("getLambdaContextDecl();
-unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
-unsigned LambdaId;
-const ParmVarDecl *Parm = dyn_cast_or_null(LambdaContextDecl);
-const FunctionDecl *Func =
-Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
-
-if (Func) {
-  unsigned DefaultArgNo =
-  Func->getNumParams() - Parm->getFunctionScopeIndex();
-  Name += llvm::utostr(DefaultArgNo);
-  Name += "_";
-}
-
-if (LambdaManglingNumber)
-  LambdaId = LambdaManglingNumber;
-else
-  LambdaId = getLambdaIdForDebugInfo(Lambda);
-
-Name += llvm::utostr(LambdaId);
-Name += ">";
-return StringRef(Name);
-  }
-
   unsigned getLambdaId(const CXXRecordDecl *RD) {
 assert(RD->isLambda() && "RD must be a lambda!");
 assert(!RD->isExternallyVisible() && "RD must not be visible!");
@@ -266,19 +238,6 @@ class MicrosoftMangleContextImpl : public 
MicrosoftMangleContext {
 return Result.first->second;
   }
 
-  unsigned getLambdaIdForDebugInfo(const CXXRecordDecl *RD) {
-assert(RD->isLambda() && "RD must be a lambda!");
-assert(!RD->isExternallyVisible() && "RD must not be visible!");
-assert(RD->getLambdaManglingNumber() == 0 &&
-   "RD must not have a mangling number!");
-llvm::DenseMap::iterator Result =
-LambdaIds.find(RD);
-// The lambda should exist, but return 0 in case it doesn't.
-if (Result == LambdaIds.end())
-  return 0;
-return Result->second;
-  }
-
   /// Return a character sequence that is (somewhat) unique to the TU suitable
   /// for mangling 

[PATCH] D95644: Ensure that we traverse non-op() method bodys of lambdas

2021-01-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:485
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;

steveire wrote:
> rsmith wrote:
> > steveire wrote:
> > > I don't know how to create a lambda with a default ctor body.
> > I think that's probably not actually possible, sorry for misleading you on 
> > that! You can introduce a copy constructor with a body (by giving `A` a 
> > non-trivial copy constructor), though, if you want to test that.
> Thanks! I think I have the copy-ctor case covered already. Is something 
> missing?
Oh, right you are. Looks good :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95644

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


[PATCH] D95644: Ensure that we traverse non-op() method bodys of lambdas

2021-01-28 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 319992.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95644

Files:
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -474,6 +474,42 @@
   EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureThis));
 }
 
+TEST(Matcher, MatchesMethodsOnLambda) {
+  StringRef Code = R"cpp(
+struct A {
+  ~A() {}
+};
+void foo()
+{
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;
+  auto lPtrDecay = +[] { };
+  (void)lPtrDecay;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isCopyConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isMoveConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxDestructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l";
+  EXPECT_TRUE(matches(
+  Code, cxxConversionDecl(hasBody(compoundStmt(has(returnStmt(
+  hasReturnValue(implicitCastExpr()),
+  hasAncestor(lambdaExpr(hasAncestor(
+  varDecl(hasName("lPtrDecay";
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2062,7 +2062,8 @@
 
   if (const auto *MD = dyn_cast(D)) {
 if (const CXXRecordDecl *RD = MD->getParent()) {
-  if (RD->isLambda()) {
+  if (RD->isLambda() &&
+  declaresSameEntity(RD->getLambdaCallOperator(), MD)) {
 VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
   }
 }


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -474,6 +474,42 @@
   EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureThis));
 }
 
+TEST(Matcher, MatchesMethodsOnLambda) {
+  StringRef Code = R"cpp(
+struct A {
+  ~A() {}
+};
+void foo()
+{
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;
+  auto lPtrDecay = +[] { };
+  (void)lPtrDecay;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isCopyConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isMoveConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxDestructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l";
+  EXPECT_TRUE(matches(
+  Code, cxxConversionDecl(hasBody(compoundStmt(has(returnStmt(
+  hasReturnValue(implicitCastExpr()),
+  hasAncestor(lambdaExpr(hasAncestor(
+  varDecl(hasName("lPtrDecay";
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2062,7 +2062,8 @@
 
   if (const auto *MD = dyn_cast(D)) {
 if (const CXXRecordDecl *RD = MD->getParent()) {
-  if (RD->isLambda()) {
+  if (RD->isLambda() &&
+  declaresSameEntity(RD->getLambdaCallOperator(), MD)) {
 VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95187: [DebugInfo][CodeView] Use as the display name for lambdas.

2021-01-28 Thread Amy Huang 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 rGd73564c51003: [DebugInfo][CodeView] Use lambda_n as 
the display name for lambdas. (authored by akhuang).

Changed prior to commit:
  https://reviews.llvm.org/D95187?vs=319668=319991#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95187

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
  clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Index: clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
===
--- clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
+++ clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
@@ -1,17 +1,26 @@
-// RUN: %clang_cc1 %s -gcodeview -debug-info-kind=line-tables-only -S \
-// RUN:   -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -gcodeview -debug-info-kind=line-tables-only -emit-llvm \
+// RUN:   -o - | FileCheck %s
 // Checks that clang with "-gline-tables-only" with CodeView emits some debug
 // info for variables and types when they appear in function scopes.
 
 namespace NS {
 struct C {
   void m() {}
+  // Test externally visible lambda.
+  void lambda2() { []() {}(); }
+ 
+  // Test naming for function parameters.
+  void lambda_params(int x = [](){ return 0; }(), int y = [](){ return 1; }()) {}
 };
 void f() {}
 }
 
+// Test non- externally visible lambda.
+auto lambda1 = []() { return 1; };
+
 NS::C c;
 
+
 void test() {
   // CHECK: !DISubprogram(name: "f", scope: ![[NS:[0-9]+]],
   // CHECK-SAME:  type: ![[F:[0-9]+]]
@@ -21,10 +30,30 @@
   NS::f();
 
   // CHECK: ![[M:[0-9]+]] = distinct !DISubprogram(name: "m", scope: ![[C:[0-9]+]],
-  // CHECK-SAME:   type: ![[MTYPE:[0-9]+]]
+  // CHECK-SAME:   type: ![[MTYPE:[0-9]+]],
   // CHECK: ![[C]] = !DICompositeType(tag: DW_TAG_structure_type, name: "C",
   // CHECK-SAME:  flags: DIFlagFwdDecl
   // CHECK-NOT: identifier
   // CHECK: ![[MTYPE]] = !DISubroutineType({{.*}}types: !{{.*}})
   c.m();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA0:[0-9]+]],
+  // CHECK: ![[LAMBDA0]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:name: "",
+  // CHECK-SAME:flags: DIFlagFwdDecl
+  lambda1();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1_1:[0-9]+]],
+  // CHECK: ![[LAMBDA1_1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:  name: "",
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA2_1:[0-9]+]],
+  // CHECK: ![[LAMBDA2_1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:  name: "",
+  c.lambda_params();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1:[0-9]+]],
+  // CHECK: ![[LAMBDA1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:name: "",
+  // CHECK-SAME:flags: DIFlagFwdDecl
+  c.lambda2();
 }
Index: clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
===
--- clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
+++ clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
@@ -100,7 +100,7 @@
   // MSVC-SAME:  )
   // MSVC:   [[TYPE_OF_FOUR]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_class_type
-  // MSVC-NOT:   name:
+  // MSVC-SAME:  name: ""
   // MSVC-SAME:  identifier: ".?AV@?0??main@@9@"
   // MSVC-SAME:  )
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -317,8 +317,9 @@
   if (const IdentifierInfo *II = RD->getIdentifier())
 return II->getName();
 
-  // The CodeView printer in LLVM wants to see the names of unnamed types: it is
-  // used to reconstruct the fully qualified type names.
+  // The CodeView printer in LLVM wants to see the names of unnamed types
+  // because they need to have a unique identifier.
+  // These names are used to reconstruct the fully qualified type names.
   if (CGM.getCodeGenOpts().EmitCodeView) {
 if (const TypedefNameDecl *D = RD->getTypedefNameForAnonDecl()) {
   assert(RD->getDeclContext() == D->getDeclContext() &&
@@ -342,6 +343,14 @@
 // associate typedef mangled in if they have one.
 Name = TND->getName();
 
+  // Give lambdas a display name based on their name mangling.
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  

[PATCH] D95644: Ensure that we traverse non-op() method bodys of lambdas

2021-01-28 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:2065
 if (const CXXRecordDecl *RD = MD->getParent()) {
-  if (RD->isLambda()) {
+  if (RD->isLambda() && RD->getLambdaCallOperator() == MD) {
 VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();

rsmith wrote:
> In principle there can be multiple declarations of the lambda call operator 
> if we merge multiple lambdas from different modules; we should check for any 
> declaration of the `operator()` here rather than the exact one that 
> `getLambdaCallOperator` returns.
> 
> I'd previously thought we could use `isLambdaCallOperator` here, but I think 
> that's wrong: for a generic lambda, that would skip instantiations of the 
> templated `operator()`, whereas I think you only want to skip the body of the 
> primary template in that case, and still visit the instantiations, right? Eg, 
> given:
> 
> ```
> auto x = [](auto n) { return n; };
> int n = x(0);
> ```
> ... you'd want to skip the body of the template `::operator()(T)`, 
> but you'd still want to visit the body of `::operator()(int)`, 
> right?
Yes, the instantiations should still be visited here. 



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:485
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;

rsmith wrote:
> steveire wrote:
> > I don't know how to create a lambda with a default ctor body.
> I think that's probably not actually possible, sorry for misleading you on 
> that! You can introduce a copy constructor with a body (by giving `A` a 
> non-trivial copy constructor), though, if you want to test that.
Thanks! I think I have the copy-ctor case covered already. Is something missing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95644

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


[clang] d73564c - [DebugInfo][CodeView] Use as the display name for lambdas.

2021-01-28 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-01-28T16:30:38-08:00
New Revision: d73564c510036b2d4f5858effdcd23fe54fc1063

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

LOG: [DebugInfo][CodeView] Use  as the display name for lambdas.

Currently (for codeview) lambdas have a string like `` in
their mangled name, and don't have any display name. This change uses the
`` as the display name, which helps distinguish between lambdas
in -gline-tables-only, since there are no linkage names there.
It also changes how we display lambda names; previously we used
``; now it will show ``.

I added a function to the mangling context code to create this string;
for Itanium it just returns an empty string.

Bug: https://bugs.llvm.org/show_bug.cgi?id=48432

Reviewed By: rnk

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

Added: 


Modified: 
clang/include/clang/AST/Mangle.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Mangle.h 
b/clang/include/clang/AST/Mangle.h
index 0e8d6dd53d8a6..f8f44853567fd 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST/Mangle.h
@@ -89,6 +89,17 @@ class MangleContext {
 return Result.first->second;
   }
 
+  uint64_t getAnonymousStructIdForDebugInfo(const NamedDecl *D) {
+llvm::DenseMap::iterator Result =
+AnonStructIds.find(D);
+// The decl should already be inserted, but return 0 in case it is not.
+if (Result == AnonStructIds.end())
+  return 0;
+return Result->second;
+  }
+
+  virtual StringRef getLambdaString(const CXXRecordDecl *Lambda) = 0;
+
   /// @name Mangler Entry Points
   /// @{
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 4420f6a2c1c38..265c2172801c4 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -203,6 +203,36 @@ class ItaniumMangleContextImpl : public 
ItaniumMangleContext {
 disc = discriminator-2;
 return true;
   }
+
+  StringRef getLambdaString(const CXXRecordDecl *Lambda) override {
+// This function matches the one in MicrosoftMangle, which returns
+// the string that is used in lambda mangled names.
+assert(Lambda->isLambda() && "RD must be a lambda!");
+llvm::SmallString<10> Name("getLambdaContextDecl();
+unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
+unsigned LambdaId;
+const ParmVarDecl *Parm = dyn_cast_or_null(LambdaContextDecl);
+const FunctionDecl *Func =
+Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
+
+if (Func) {
+  unsigned DefaultArgNo =
+  Func->getNumParams() - Parm->getFunctionScopeIndex();
+  Name += llvm::utostr(DefaultArgNo);
+  Name += "_";
+}
+
+if (LambdaManglingNumber)
+  LambdaId = LambdaManglingNumber;
+else
+  LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
+
+Name += llvm::utostr(LambdaId);
+Name += '>';
+return StringRef(Name);
+  }
+
   /// @}
 };
 

diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 9eac3586c8715..aaaba62a0fd4e 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -228,6 +228,34 @@ class MicrosoftMangleContextImpl : public 
MicrosoftMangleContext {
 return true;
   }
 
+  StringRef getLambdaString(const CXXRecordDecl *Lambda) override {
+assert(Lambda->isLambda() && "RD must be a lambda!");
+llvm::SmallString<10> Name("getLambdaContextDecl();
+unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
+unsigned LambdaId;
+const ParmVarDecl *Parm = dyn_cast_or_null(LambdaContextDecl);
+const FunctionDecl *Func =
+Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
+
+if (Func) {
+  unsigned DefaultArgNo =
+  Func->getNumParams() - Parm->getFunctionScopeIndex();
+  Name += llvm::utostr(DefaultArgNo);
+  Name += "_";
+}
+
+if (LambdaManglingNumber)
+  LambdaId = LambdaManglingNumber;
+else
+  LambdaId = getLambdaIdForDebugInfo(Lambda);
+
+Name += llvm::utostr(LambdaId);
+Name += ">";
+return StringRef(Name);
+  }
+
   unsigned getLambdaId(const CXXRecordDecl *RD) {
 assert(RD->isLambda() && "RD must be a lambda!");
 assert(!RD->isExternallyVisible() && "RD must not be visible!");
@@ -238,6 +266,19 @@ class MicrosoftMangleContextImpl : public 
MicrosoftMangleContext {
 return Result.first->second;
   }
 
+  unsigned getLambdaIdForDebugInfo(const CXXRecordDecl *RD) {
+assert(RD->isLambda() && "RD must be a 

[PATCH] D95166: Disable rosegment for old Android versions.

2021-01-28 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

Firefox CI is using a custom clang, but uses a NDK otherwise (an old-ish one, 
clearly older than r22 which is the first that defaults to lld). And we do pass 
-fuse-ld=bfd at the moment for $reasons.
If clang _really_ wants to assume lld as the linker for android, then it should 
make using -fuse-ld=somethingelse an error and invoke ld.lld rather than ld, if 
it doesn't already do that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95166

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


[PATCH] D95644: Ensure that we traverse non-op() method bodys of lambdas

2021-01-28 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 319987.
steveire added a comment.

Use helper method


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95644

Files:
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -474,6 +474,42 @@
   EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureThis));
 }
 
+TEST(Matcher, MatchesMethodsOnLambda) {
+  StringRef Code = R"cpp(
+struct A {
+  ~A() {}
+};
+void foo()
+{
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;
+  auto lPtrDecay = +[] { };
+  (void)lPtrDecay;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isCopyConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isMoveConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxDestructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l";
+  EXPECT_TRUE(matches(
+  Code, cxxConversionDecl(hasBody(compoundStmt(has(returnStmt(
+  hasReturnValue(implicitCastExpr()),
+  hasAncestor(lambdaExpr(hasAncestor(
+  varDecl(hasName("lPtrDecay";
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -13,18 +13,19 @@
 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
 
+#include "clang/AST/ASTLambda.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
-#include "clang/AST/DeclarationName.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclOpenMP.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
-#include "clang/AST/ExprConcepts.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
 #include "clang/AST/LambdaCapture.h"
@@ -2061,10 +2062,8 @@
   (!D->isDefaulted() || getDerived().shouldVisitImplicitCode());
 
   if (const auto *MD = dyn_cast(D)) {
-if (const CXXRecordDecl *RD = MD->getParent()) {
-  if (RD->isLambda()) {
-VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
-  }
+if (isLambdaCallOperator(MD)) {
+  VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
 }
   }
 


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -474,6 +474,42 @@
   EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureThis));
 }
 
+TEST(Matcher, MatchesMethodsOnLambda) {
+  StringRef Code = R"cpp(
+struct A {
+  ~A() {}
+};
+void foo()
+{
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;
+  auto lPtrDecay = +[] { };
+  (void)lPtrDecay;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isCopyConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isMoveConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxDestructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l";
+  EXPECT_TRUE(matches(
+  Code, cxxConversionDecl(hasBody(compoundStmt(has(returnStmt(
+  hasReturnValue(implicitCastExpr()),
+  hasAncestor(lambdaExpr(hasAncestor(
+  varDecl(hasName("lPtrDecay";
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "
Index: 

[PATCH] D95166: Disable rosegment for old Android versions.

2021-01-28 Thread dmajor via Phabricator via cfe-commits
dmajor added a comment.

It does feel kind of awkward to me that _this_ is the patch that ends up 
breaking the builds, versus something at the cmake level that says "you are 
explicitly unsupported".

Also it's unfortunate that this landed just hours before 12.0.0 branched. Had 
it landed slightly later, release users could have six months to plan for the 
change. You say that the next NDK compiler is based on ToT, in that case would 
it make sense to revert this on the 12.x branch, and add a warning to the 
12.0.0 release notes that lld will be assumed in 13?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95166

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


[PATCH] D95644: Ensure that we traverse non-op() method bodys of lambdas

2021-01-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:2065
 if (const CXXRecordDecl *RD = MD->getParent()) {
-  if (RD->isLambda()) {
+  if (RD->isLambda() && RD->getLambdaCallOperator() == MD) {
 VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();

In principle there can be multiple declarations of the lambda call operator if 
we merge multiple lambdas from different modules; we should check for any 
declaration of the `operator()` here rather than the exact one that 
`getLambdaCallOperator` returns.

I'd previously thought we could use `isLambdaCallOperator` here, but I think 
that's wrong: for a generic lambda, that would skip instantiations of the 
templated `operator()`, whereas I think you only want to skip the body of the 
primary template in that case, and still visit the instantiations, right? Eg, 
given:

```
auto x = [](auto n) { return n; };
int n = x(0);
```
... you'd want to skip the body of the template `::operator()(T)`, but 
you'd still want to visit the body of `::operator()(int)`, right?



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:485
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;

steveire wrote:
> I don't know how to create a lambda with a default ctor body.
I think that's probably not actually possible, sorry for misleading you on 
that! You can introduce a copy constructor with a body (by giving `A` a 
non-trivial copy constructor), though, if you want to test that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95644

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


[PATCH] D71714: [Sema] Fix -Warray-bounds false negative when casting an out-of-bounds array item

2021-01-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaChecking.cpp:13384
   case Stmt::MemberExprClass: {
 expr = cast(expr)->getBase();
 break;

ilya wrote:
> ebevhan wrote:
> > ilya wrote:
> > > rsmith wrote:
> > > > ilya wrote:
> > > > > rsmith wrote:
> > > > > > Hmm, don't we need to do different things for dot and arrow in this 
> > > > > > case?
> > > > > There are several test cases for an out of bounds access on an array 
> > > > > member using dot and arrow operators in array-bounds.cpp. Do you have 
> > > > > a specific test case for which you think the code is broken?
> > > > > There are several test cases for an out of bounds access on an array 
> > > > > member using dot and arrow operators in array-bounds.cpp. Do you have 
> > > > > a specific test case for which you think the code is broken?
> > > > 
> > > > Sure. There's a false negative for this:
> > > > 
> > > > ```
> > > > struct A { int n; };
> > > > A *a[4];
> > > > int *n = [4]->n;
> > > > ```
> > > > 
> > > > ... because we incorrectly visit the left-hand side of the `->` with 
> > > > `AllowOnePastEnd == 1`. The left-hand side of `->` is subject to 
> > > > lvalue-to-rvalue conversion, so can't be one-past-the-end regardless of 
> > > > the context in which the `->` appears.
> > > > ... because we incorrectly visit the left-hand side of the -> with 
> > > > AllowOnePastEnd == 1. The left-hand side of -> is subject to 
> > > > lvalue-to-rvalue conversion, so can't be one-past-the-end regardless of 
> > > > the context in which the -> appears.
> > > 
> > > Thanks for clarifying. So basically we don't want to allow one-past-end 
> > > for MemberExpr?
> > > Thanks for clarifying. So basically we don't want to allow one-past-end 
> > > for MemberExpr?
> > 
> > I think the point is rather that when the MemberExpr isArrow, we want to 
> > think of it as performing an implicit dereference first, and thus we should 
> > do `AllowOnePastEnd--` before recursing if that is the case.
> > I think the point is rather that when the MemberExpr isArrow, we want to 
> > think of it as performing an implicit dereference first, and thus we should 
> > do AllowOnePastEnd-- before recursing if that is the case.
> 
> @ebevhan and I have discussed this offline, and we believe that there's no 
> reason to allow an //address-of// of a member of a one past-the-end value, 
> using either '.' or '->' operators, regardless of the fact that referencing a 
> member of a one past-the-end value using '.' is merely a pointer arithmetic 
> and doesn't imply dereferencing, as with operator '->'.
> 
> We couldn't find any reference in the [[ 
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf| C++ 2017 
> N4659 ]] regarding member access of a one past-the-end value. Only mentions 
> of one past-the-end in the context of iterators (27.2.1 p. 7) and pointer 
> arithmetic (8.3.1 p. 3).
> 
> [[ http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf | ISO C99 ]] 
> describes in 6.5.3.2 p. 3 that if the operand to the '&' operator is the 
> result of an unary '*' operator (or array subscript, implictly), the two 
> operators "cancel" each other, but it says nothing about the case when 
> there's a member expression "in-between", (the member expression section, 
> 6.5.2.3, says nothing about that either).
> 
> @rsmith, what do you think?
Let's give this a go. I'm a little concerned that people might write things 
like:

```
struct X { int n; };
X x[32];
int *end = [32].n;
```

I don't think that has defined behavior in C++, because there isn't an `X` 
object so there isn't an `n` member to refer to, but I think it's probably OK 
in C (hard to say in both cases, though, due to underspecification in both 
standards). Nonetheless, such code is at least questionable. I don't think we 
have a good way to determine how well this warning will work other than trying 
it, so let's do that.

Please be prepared to revert and do something more conservative if we find this 
fires a lot on somewhat-reasonable code :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71714

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


[PATCH] D95614: [clang-tidy] Applied clang-tidy fixes. NFC

2021-01-28 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp:96
 void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) {
-  for (auto ScaleName :
+  for (const auto *ScaleName :
{"Hours", "Minutes", "Seconds", "Millis", "Micros", "Nanos"}) {

Changing this to `const char *`.



Comment at: clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp:283
   continue;
-if (auto Template = Callee->getTemplateInstantiationPattern()) {
+if (auto *Template = Callee->getTemplateInstantiationPattern()) {
   // Don't warn on arguments for parameters instantiated from template

Changing this to `FunctionDecl *`.



Comment at: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp:191-194
+auto *End = Branches.end();
+auto *BeginCurrent = Branches.begin();
 while (BeginCurrent < End) {
+  auto *EndCurrent = BeginCurrent + 1;

This comes from llvm-qualified-auto. Iterator being a pointer is an 
implementation detail, thus the fix is not helpful. Reverting it.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp:113
   Diag << FixItHint::CreateInsertion(FixItLoc, FixItMsg);
-} // namespace misc
 

Removed this manually.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp:109-110
   const auto *Ctor = Result.Nodes.getNodeAs("ctor");
-  for (auto Iter = Ctor->param_begin() + 1; Iter != Ctor->param_end(); ++Iter) 
{
+  for (const auto *Iter = Ctor->param_begin() + 1; Iter != Ctor->param_end();
+   ++Iter) {
 if (!(*Iter)->hasDefaultArg())

This comes from llvm-qualified-auto. Iterator being a pointer is an 
implementation detail, thus the fix is not helpful. Reverting it.

For the context:
using param_iterator = MutableArrayRef::iterator;
...
param_iterator param_begin() ...



Comment at: 
clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp:923
   const auto *FunctionExpr = 
Result.Nodes.getNodeAs(FunctionExprName);
-  if (const auto GivenCL = dyn_cast(FunctionExpr->getArg(1)))
+  if (const auto *const GivenCL =
+  dyn_cast(FunctionExpr->getArg(1)))

Removing this const, since it doesn't bring anything here.



Comment at: clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp:42
 return M.matches(*UE->getSubExpr(), Finder, Builder);
   } else if (const auto *BE = dyn_cast(E)) {
 const auto LHS = hasSizeOfDescendant(Depth - 1, InnerMatcher);

Removing this one too. The check outputs just one diagnostic per if - else if - 
else if chain for some reason.



Comment at: clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:88
 return twoPow(Context.getTypeSize(T));
   else
 return 1;

Removing this one too. The llvm-else-after-return check outputs just one 
diagnostic per if - else if - else if chain for some reason.



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp:337
 
-  auto MaxPlaceholderIt =
+  const auto *MaxPlaceholderIt =
   std::max_element(Args.begin(), Args.end(),

Iterator being a pointer is an implementation detail. Reverting.



Comment at: 
clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp:62
   if (Replacement) {
-auto FixName = *Replacement;
+const auto *FixName = *Replacement;
 auto Builder = diag(IoStateLoc, "'std::ios_base::%0' is deprecated; use "

Changing to `const char *`.



Comment at: clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp:390-400
+  } // Direct initialization with ordinary constructors.
 //   struct S { S(int x); S(); };
 //   smart_ptr(new S{5});
 //   smart_ptr(new S{}); // use default constructor
 // The arguments in the initialization list are going to be forwarded 
to
 // the constructor, so this has to be replaced with:
 //   std::make_smart_ptr(5);

Fixing indentation.



Comment at: clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp:175
   ReplacementText = " " + OverrideSpelling;
-  auto LastTokenIter = std::prev(Tokens.end());
+  auto *LastTokenIter = std::prev(Tokens.end());
   // When try statement is used instead of compound statement as

Reverting this (iterator doesn't have to be a pointer).



Comment at: clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp:61
 
-  auto printPolicy = PrintingPolicy(getLangOpts());
-  printPolicy.SuppressScope = true;
-  printPolicy.ConstantArraySizeAsWritten = true;
-  printPolicy.UseVoidForZeroParams = false;
-  

[PATCH] D95614: [clang-tidy] Applied clang-tidy fixes. NFC

2021-01-28 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh updated this revision to Diff 319979.
alexfh added a comment.

Manually cleaned up suboptimal fixes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95614

Files:
  clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
  clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
  
clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
  clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
  
clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
  clang-tools-extra/clang-tidy/utils/ASTUtils.cpp

Index: clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
@@ -26,13 +26,11 @@
 
 bool IsBinaryOrTernary(const Expr *E) {
   const Expr *EBase = E->IgnoreImpCasts();
-  if (clang::isa(EBase) ||
-  clang::isa(EBase)) {
+  if (isa(EBase) || isa(EBase)) {
 return true;
   }
 
-  if (const auto *Operator =
-  clang::dyn_cast(EBase)) {
+  if (const auto *Operator = dyn_cast(EBase)) {
 return Operator->isInfixBinaryOp();
   }
 
@@ -56,7 +54,7 @@
   }
   // If it's a binary OR operation.
   if (const auto *BO = dyn_cast(Flags))
-if (BO->getOpcode() == clang::BinaryOperatorKind::BO_Or)
+if (BO->getOpcode() == BinaryOperatorKind::BO_Or)
   return exprHasBitFlagWithSpelling(BO->getLHS()->IgnoreParenCasts(), SM,
 LangOpts, FlagName) ||
  exprHasBitFlagWithSpelling(BO->getRHS()->IgnoreParenCasts(), SM,
Index: clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
@@ -68,7 +68,7 @@
   bool MultiVar = false;
   if (const auto *VD = dyn_cast(D)) {
 // Is this a multivariable declaration?
-for (auto *const Other : VD->getDeclContext()->decls()) {
+for (const auto *Other : VD->getDeclContext()->decls()) {
   if (Other != D && Other->getBeginLoc() == VD->getBeginLoc()) {
 MultiVar = true;
 break;
Index: clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
@@ -105,8 +105,8 @@
  bool Strict) {
   DifferingParamsContainer DifferingParams;
 
-  const auto *SourceParamIt = ParameterSourceDeclaration->param_begin();
-  const auto *OtherParamIt = OtherDeclaration->param_begin();
+  auto SourceParamIt = ParameterSourceDeclaration->param_begin();
+  auto OtherParamIt = OtherDeclaration->param_begin();
 
   while (SourceParamIt != ParameterSourceDeclaration->param_end() &&
  OtherParamIt != OtherDeclaration->param_end()) {
Index: clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
===
--- clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
+++ clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
@@ -39,9 +39,8 @@
   std::unique_ptr CreateASTConsumer(CompilerInstance ,
  StringRef File) override {
 // Create and set diagnostics engine
-auto *ExternalDiagEngine = ();
 auto *DiagConsumer =
-new ClangTidyDiagnosticConsumer(*Context, ExternalDiagEngine);
+new ClangTidyDiagnosticConsumer(*Context, ());
 auto DiagEngine = std::make_unique(
 new DiagnosticIDs, new DiagnosticOptions, DiagConsumer);
 Context->setDiagnosticsEngine(DiagEngine.get());
Index: clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp

[PATCH] D95573: [ASTMatchers] Avoid pathological traversal over nested lambdas

2021-01-28 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:2063-2065
+  if (const auto *MD = dyn_cast(D)) {
+if (const CXXRecordDecl *RD = MD->getParent()) {
+  if (RD->isLambda()) {

rsmith wrote:
> This is incorrectly skipping the bodies of all other lambda member functions 
> (default ctor, copy ctor, destructor, implicit conversion to function pointer 
> type), not only the "body" of the lambda itself (the definition of the 
> `operator()`).
Please see https://reviews.llvm.org/D95644.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95573

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


[PATCH] D95644: Ensure that we traverse non-op() method bodys of lambdas

2021-01-28 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:485
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;

I don't know how to create a lambda with a default ctor body.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95644

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


[PATCH] D95644: Ensure that we traverse non-op() method bodys of lambdas

2021-01-28 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: rsmith.
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/D95644

Files:
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -474,6 +474,42 @@
   EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureThis));
 }
 
+TEST(Matcher, MatchesMethodsOnLambda) {
+  StringRef Code = R"cpp(
+struct A {
+  ~A() {}
+};
+void foo()
+{
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;
+  auto lPtrDecay = +[] { };
+  (void)lPtrDecay;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isCopyConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isMoveConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxDestructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l";
+  EXPECT_TRUE(matches(
+  Code, cxxConversionDecl(hasBody(compoundStmt(has(returnStmt(
+  hasReturnValue(implicitCastExpr()),
+  hasAncestor(lambdaExpr(hasAncestor(
+  varDecl(hasName("lPtrDecay";
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2062,7 +2062,7 @@
 
   if (const auto *MD = dyn_cast(D)) {
 if (const CXXRecordDecl *RD = MD->getParent()) {
-  if (RD->isLambda()) {
+  if (RD->isLambda() && RD->getLambdaCallOperator() == MD) {
 VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
   }
 }


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -474,6 +474,42 @@
   EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureThis));
 }
 
+TEST(Matcher, MatchesMethodsOnLambda) {
+  StringRef Code = R"cpp(
+struct A {
+  ~A() {}
+};
+void foo()
+{
+  A a;
+  auto l = [a] { };
+  auto lCopy = l;
+  auto lPtrDecay = +[] { };
+  (void)lPtrDecay;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isCopyConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxConstructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"),
+isMoveConstructor(;
+  EXPECT_TRUE(matches(
+  Code, cxxDestructorDecl(
+hasBody(compoundStmt()),
+hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l";
+  EXPECT_TRUE(matches(
+  Code, cxxConversionDecl(hasBody(compoundStmt(has(returnStmt(
+  hasReturnValue(implicitCastExpr()),
+  hasAncestor(lambdaExpr(hasAncestor(
+  varDecl(hasName("lPtrDecay";
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2062,7 +2062,7 @@
 
   if (const auto *MD = dyn_cast(D)) {
 if (const CXXRecordDecl *RD = MD->getParent()) {
-  if (RD->isLambda()) {
+  if (RD->isLambda() && RD->getLambdaCallOperator() == MD) {
 VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80344: [Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 1

2021-01-28 Thread Ten Tzen via Phabricator via cfe-commits
tentzen added a comment.
Herald added a reviewer: jansvoboda11.

Hi, John,
sorry for the delay.  I'm still in the middle of something.
will context-switch a little bit latter. thanks,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80344

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


[PATCH] D95573: [ASTMatchers] Avoid pathological traversal over nested lambdas

2021-01-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:2063-2065
+  if (const auto *MD = dyn_cast(D)) {
+if (const CXXRecordDecl *RD = MD->getParent()) {
+  if (RD->isLambda()) {

This is incorrectly skipping the bodies of all other lambda member functions 
(default ctor, copy ctor, destructor, implicit conversion to function pointer 
type), not only the "body" of the lambda itself (the definition of the 
`operator()`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95573

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


[PATCH] D93585: [AArch64][Clang][Linux] Enable out-of-line atomics by default.

2021-01-28 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv updated this revision to Diff 319951.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93585

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  
clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-10/lib/gcc/aarch64-unknown-linux-gnu/10/crtbegin.o
  
clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-10/lib/gcc/aarch64-unknown-linux-gnu/10/libgcc.a
  
clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-7.5.0/lib/gcc/aarch64-unknown-linux-gnu/7.5.0/crtbegin.o
  
clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-7.5.0/lib/gcc/aarch64-unknown-linux-gnu/7.5.0/libgcc.a
  
clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-9.3.0/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/crtbegin.o
  
clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-9.3.0/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/libgcc.a
  
clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-9.3.1/lib/gcc/aarch64-unknown-linux-gnu/9.3.1/crtbegin.o
  
clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-9.3.1/lib/gcc/aarch64-unknown-linux-gnu/9.3.1/libgcc.a
  clang/test/Driver/aarch64-features.c

Index: clang/test/Driver/aarch64-features.c
===
--- clang/test/Driver/aarch64-features.c
+++ clang/test/Driver/aarch64-features.c
@@ -6,3 +6,32 @@
 // The AArch64 PCS states that chars should be unsigned.
 // CHECK: fno-signed-char
 
+// Check for AArch64 out-of-line atomics default settings.
+// RUN: %clang -target aarch64-linux-android -rtlib=compiler-rt \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-ON %s
+// RUN: %clang -target aarch64-linux-gnu -rtlib=compiler-rt \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-ON %s
+// RUN: %clang -target arm64-unknown-linux -rtlib=compiler-rt \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-ON %s
+// RUN: %clang -target aarch64--none-eabi -rtlib=compiler-rt \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-OFF %s
+// RUN: %clang -target aarch64-apple-darwin -rtlib=compiler-rt \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-OFF %s
+// RUN: %clang -target aarch64-windows-gnu -rtlib=compiler-rt \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-OFF %s
+// RUN: %clang -target aarch64-unknown-openbsd -rtlib=compiler-rt \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-OFF %s
+// RUN: %clang -target aarch64-linux-gnu -rtlib=libgcc \
+// RUN: --gcc-toolchain=%S/Inputs/aarch64-linux-gnu-tree/gcc-10 \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-ON %s
+// RUN: %clang -target aarch64-linux-gnu -rtlib=libgcc \
+// RUN: --gcc-toolchain=%S/Inputs/aarch64-linux-gnu-tree/gcc-7.5.0 \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-OFF %s
+// RUN: %clang -target aarch64-linux-gnu -rtlib=libgcc \
+// RUN: --gcc-toolchain=%S/Inputs/aarch64-linux-gnu-tree/gcc-9.3.1 \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-ON %s
+// RUN: %clang -target aarch64-linux-gnu -rtlib=libgcc \
+// RUN: --gcc-toolchain=%S/Inputs/aarch64-linux-gnu-tree/gcc-9.3.0 \
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-OUTLINE-ATOMICS-OFF %s
+// CHECK-OUTLINE-ATOMICS-ON: "-target-feature" "+outline-atomics"
+// CHECK-OUTLINE-ATOMICS-OFF-NOT: "-target-feature" "+outline-atomics"
Index: clang/lib/Driver/ToolChains/Linux.h
===
--- clang/lib/Driver/ToolChains/Linux.h
+++ clang/lib/Driver/ToolChains/Linux.h
@@ -36,6 +36,8 @@
   void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
   CXXStdlibType GetDefaultCXXStdlibType() const override;
+  bool
+  IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList ) const override;
   bool isPIEDefault() const override;
   bool isNoExecStackDefault() const override;
   bool IsMathErrnoDefault() const override;
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -845,6 +845,19 @@
   getTriple().isMusl() || getSanitizerArgs().requiresPIE();
 }
 
+bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList ) const {
+  // Outline atomics for AArch64 are supported by compiler-rt
+  // and libgcc since 9.3.1
+  assert(getTriple().isAArch64() && "expected AArch64 target!");
+  ToolChain::RuntimeLibType RtLib = GetRuntimeLibType(Args);
+  if (RtLib == ToolChain::RLT_CompilerRT)
+return true;
+  assert(RtLib == ToolChain::RLT_Libgcc && "unexpected runtime library type!");
+  if (GCCInstallation.getVersion().isOlderThan(9, 3, 1))
+  

[PATCH] D95166: Disable rosegment for old Android versions.

2021-01-28 Thread Dan Albert via Phabricator via cfe-commits
danalbert added a comment.

In D95166#2527437 , @vitalybuka wrote:

> Our Android build bot is broken after this patch 
> http://lab.llvm.org:8011/#/builders/77/builds/3234

Shouldn't that build be using lld?

In D95166#2526839 , @glandium wrote:

> "Android only supports lld" might be true now, but it hasn't always been 
> true, which means the change is not backwards compatible with versions of the 
> NDK that don't use lld.

If I'm understanding correctly, Firefox is building a custom toolchain for use 
with the NDK sysroot? That works as long as you're building the whole toolchain 
(though we can't guarantee that even that will work out of the box, because 
these things are developed in tandem and other configurations are not tested), 
but you'll need to build lld, llvm-ar, etc and use those as well.

> Also, `-fuse-ld` is still a valid flag that can allow to use a different 
> linker than lld.

We could check `-fuse-ld` for something other than `ld` or `lld` and not pass 
these flags in those cases. Would that be suitable? I see Clang did recently 
gain a `LinkerIsLLD` out param for `Toolchain::GetLinkerPath`. It's wrong for 
Android toolchains (because it assumes `ld` is not `lld`), but we could fix 
that. It'd be wrong whenever someone is using any toolchain other than the 
default NDK configuration (which would include Firefox), but at least it'd work 
for the common case.

A better solution IMO would be to let each target have its own default linker. 
We currently have this at the OS level, but that means that Android and GNU 
systems are assumed to have the same default linker. That's false. I'd tried 
fixing this with https://reviews.llvm.org/D76452 but the patch was not 
accepted. I'd be happy to revive and submit that if folks agree that it is the 
better choice.

Though TBH my favorite solution is still to make it clear that Android no 
longer supports anything but lld and skip all the special cases that will never 
get tested in practice. gold and bfd just barely worked for Android even when 
they were our defaults. One of the other fixes I suggest might fix your build 
today, but it's doubtful to me that it'd help you for long.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95166

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


[PATCH] D71714: [Sema] Fix -Warray-bounds false negative when casting an out-of-bounds array item

2021-01-28 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a subscriber: lattner.
vabridgers added a comment.

Gentle and polite ping :)  Could someone have a look at this? @rsmith , or 
@lattner ? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71714

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


[PATCH] D95534: clang-cl: Invent a /winsysroot concept

2021-01-28 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/lib/Driver/ToolChains/MSVC.cpp:75
+  for (llvm::sys::fs::directory_iterator DirIt(Directory, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))

hans wrote:
> for being defensive, would it be safer to check !EC before comparing the 
> iterators, in case DirIt is in a bad state because of an error?
Done (but this code is just moved up from below)



Comment at: clang/lib/Driver/ToolChains/MSVC.cpp:88
+
+  return !Highest.empty();
+}

hans wrote:
> Since the success of the function is directly tied to whether the string is 
> empty, maybe just return the string directly to simplify the API?
> 
> Oh I see, this comes from getWindows10SDKVersionFromPath(). Either way is 
> fine I suppose.
Thanks, that's much nicer.



Comment at: clang/test/Driver/cl-sysroot.cpp:4
+
+// RUN: %clang_cl /winsysroot %t /c -- %t/foo.cpp
+// RUN: %clang_cl /vctoolsdir %t/VC/Tools/MSVC/14.26.28801 \

hans wrote:
> Driver/ tests don't usually run the actual compiler. Any reason not to just 
> check the -### output?
I had that at first, but it felt a bit brittle to me. But sure, moved back to 
that.


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

https://reviews.llvm.org/D95534

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


[PATCH] D95534: clang-cl: Invent a /winsysroot concept

2021-01-28 Thread Nico Weber via Phabricator via cfe-commits
thakis updated this revision to Diff 319949.
thakis marked an inline comment as done.
thakis added a comment.

address comments


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

https://reviews.llvm.org/D95534

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/cl-sysroot.cpp

Index: clang/test/Driver/cl-sysroot.cpp
===
--- /dev/null
+++ clang/test/Driver/cl-sysroot.cpp
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cl /winsysroot %t -### -- %t/foo.cpp 2>&1 | \
+// RUN: FileCheck -DROOT=%t %s
+// RUN: %clang_cl /vctoolsdir %t/VC/Tools/MSVC/14.26.28801 \
+// RUN:   /winsdkdir "%t/Windows Kits/10" \
+// RUN:   -### -- %t/foo.cpp 2>&1 | FileCheck -DROOT=%t %s
+
+// CHECK: "-internal-isystem" "[[ROOT]]/VC/Tools/MSVC/14.26.28801/include"
+// CHECK: "-internal-isystem" "[[ROOT]]/VC/Tools/MSVC/14.26.28801/atlmfc/include"
+// CHECK: "-internal-isystem" "[[ROOT]]/Windows Kits/10/Include/10.0.19041.0/ucrt"
+// CHECK: "-internal-isystem" "[[ROOT]]/Windows Kits/10/Include/10.0.19041.0/shared"
+// CHECK: "-internal-isystem" "[[ROOT]]/Windows Kits/10/Include/10.0.19041.0/um"
+// CHECK: "-internal-isystem" "[[ROOT]]/Windows Kits/10/Include/10.0.19041.0/winrt"
+
+#--- VC/Tools/MSVC/14.26.28801/include/string
+namespace std {
+class mystring {
+public:
+  bool empty();
+};
+}
+
+#--- Windows Kits/10/Include/10.0.19041.0/ucrt/assert.h
+#define myassert(X)
+
+#--- foo.cpp
+#include 
+#include 
+
+void f() {
+  std::mystring s;
+  myassert(s.empty());
+}
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -66,14 +66,49 @@
 static bool getSystemRegistryString(const char *keyPath, const char *valueName,
 std::string , std::string *phValue);
 
+static std::string getHighestNumericTupleInDirectory(StringRef Directory) {
+  std::string Highest;
+  llvm::VersionTuple HighestTuple;
+
+  std::error_code EC;
+  for (llvm::sys::fs::directory_iterator DirIt(Directory, EC), DirEnd;
+   !EC && DirIt != DirEnd; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+llvm::VersionTuple Tuple;
+if (Tuple.tryParse(CandidateName)) // tryParse() returns true on error.
+  continue;
+if (Tuple > HighestTuple) {
+  HighestTuple = Tuple;
+  Highest = CandidateName.str();
+}
+  }
+
+  return Highest;
+}
+
 // Check command line arguments to try and find a toolchain.
 static bool
 findVCToolChainViaCommandLine(const ArgList , std::string ,
   MSVCToolChain::ToolsetLayout ) {
   // Don't validate the input; trust the value supplied by the user.
   // The primary motivation is to prevent unnecessary file and registry access.
-  if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsdir)) {
-Path = A->getValue();
+  if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsdir,
+   options::OPT__SLASH_winsysroot)) {
+if (A->getOption().getID() == options::OPT__SLASH_winsysroot) {
+  llvm::SmallString<128> ToolsPath(A->getValue());
+  llvm::sys::path::append(ToolsPath, "VC", "Tools", "MSVC");
+  std::string VCToolsVersion;
+  if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsversion))
+VCToolsVersion = A->getValue();
+  else
+VCToolsVersion = getHighestNumericTupleInDirectory(ToolsPath);
+  llvm::sys::path::append(ToolsPath, VCToolsVersion);
+  Path = std::string(ToolsPath.str());
+} else {
+  Path = A->getValue();
+}
 VSLayout = MSVCToolChain::ToolsetLayout::VS2017OrNewer;
 return true;
   }
@@ -345,7 +380,8 @@
   // they're doing. If the user passes /vctoolsdir or /winsdkdir, trust that
   // over env vars.
   if (!llvm::sys::Process::GetEnv("LIB") ||
-  Args.getLastArg(options::OPT__SLASH_vctoolsdir)) {
+  Args.getLastArg(options::OPT__SLASH_vctoolsdir,
+  options::OPT__SLASH_winsysroot)) {
 CmdArgs.push_back(Args.MakeArgString(
 Twine("-libpath:") +
 TC.getSubDirectoryPath(
@@ -356,7 +392,8 @@
"atlmfc")));
   }
   if (!llvm::sys::Process::GetEnv("LIB") ||
-  Args.getLastArg(options::OPT__SLASH_winsdkdir)) {
+  Args.getLastArg(options::OPT__SLASH_winsdkdir,
+  options::OPT__SLASH_winsysroot)) {
 if (TC.useUniversalCRT()) {
   std::string UniversalCRTLibPath;
   if (TC.getUniversalCRTLibraryPath(Args, UniversalCRTLibPath))
@@ -1069,42 +1106,38 @@
 // So we compare entry names lexicographically to find the greatest one.
 static bool getWindows10SDKVersionFromPath(const std::string ,
 

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

2021-01-28 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

@aaron.ballman Please review this again as I've merged some more needed changes 
into it.


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] D95635: [CMake] Actually require python 3.6 or greater

2021-01-28 Thread Christopher Tetreault via Phabricator via cfe-commits
ctetreau added a comment.

In D95635#2528851 , @JDevlieghere 
wrote:

>> However, the project claims to require 3.6 or greater, and 3.6 features are 
>> being used.
>
> Can you link to where it says that? I'm not opposed to making 3.6 the 
> minimally required version, but at least for LLDB we don't have that 
> requirement and we have documentation mentioning Python 3.5.



In D95635#2528883 , @yln wrote:

> In D95635#2528851 , @JDevlieghere 
> wrote:
>
>>> However, the project claims to require 3.6 or greater, and 3.6 features are 
>>> being used.
>>
>> Can you link to where it says that? I'm not opposed to making 3.6 the 
>> minimally required version, but at least for LLDB we don't have that 
>> requirement and we have documentation mentioning Python 3.5.
>
> For LLVM: https://llvm.org/docs/GettingStarted.html#software

This is where I saw it. I got bit by @yln's cleanup patch. I can reduce the 
minimum version for LLDB if that's the officially required version, but llvm at 
the very least advertises 3.6


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95635

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


[PATCH] D95534: clang-cl: Invent a /winsysroot concept

2021-01-28 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: clang/lib/Driver/ToolChains/MSVC.cpp:75
+  for (llvm::sys::fs::directory_iterator DirIt(Directory, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))

for being defensive, would it be safer to check !EC before comparing the 
iterators, in case DirIt is in a bad state because of an error?



Comment at: clang/lib/Driver/ToolChains/MSVC.cpp:88
+
+  return !Highest.empty();
+}

Since the success of the function is directly tied to whether the string is 
empty, maybe just return the string directly to simplify the API?

Oh I see, this comes from getWindows10SDKVersionFromPath(). Either way is fine 
I suppose.



Comment at: clang/lib/Driver/ToolChains/MSVC.cpp:
 
   std::error_code EC;
   llvm::SmallString<128> IncludePath(SDKPath);

EC is unused now



Comment at: clang/test/Driver/cl-sysroot.cpp:2
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+

fancy :)



Comment at: clang/test/Driver/cl-sysroot.cpp:4
+
+// RUN: %clang_cl /winsysroot %t /c -- %t/foo.cpp
+// RUN: %clang_cl /vctoolsdir %t/VC/Tools/MSVC/14.26.28801 \

Driver/ tests don't usually run the actual compiler. Any reason not to just 
check the -### output?


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

https://reviews.llvm.org/D95534

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


[PATCH] D93095: Introduce -Wreserved-identifier

2021-01-28 Thread serge via Phabricator via cfe-commits
serge-sans-paille marked an inline comment as done.
serge-sans-paille added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:2421-2428
+// Perform a lookup at TUScope. If it succeeds, we're at global scope and a
+// single '_' is enough to be reserved.
+LookupResult IdentifierLookup(*this, II, SourceLocation(),
+  Sema::LookupAnyName,
+  Sema::ForExternalRedeclaration);
+IdentifierLookup.suppressDiagnostics();
+if (LookupName(IdentifierLookup, TUScope))

rsmith wrote:
> I don't understand why name lookup is involved here. Whether an identifier is 
> reserved doesn't depend on whether it's already been declared in the global 
> namespace or not. It's valid to declare `_foo` in some user-defined namespace 
> regardless of whether there's already a `_foo` in the global namespace, and 
> it's invalid to declare `_foo` in the global namespace regardless of whether 
> there's already a `_foo` in the global namespace.
> 
> If you're trying to detect whether the name is being introduced in the global 
> namespace scope, per C++ [lex.name]/3.2, you can't do that like this; you'll 
> need to look at the `DeclContext` of the declaration instead of just the 
> identifier.
> If you're trying to detect whether the name is being introduced in the global 
> namespace scope,
That's indeed the goal

> you'll need to look at the DeclContext of the declaration instead of just the 
> identifier.



Comment at: clang/lib/Sema/SemaDecl.cpp:13640
 
+  warnOnReservedIdentifier(New);
+

rsmith wrote:
> Is there somewhere more central you can do this, rather than repeating it 
> once for each kind of declaration? (Eg, `PushOnScopeChains`)
That would be sane. I'll check that.



Comment at: clang/lib/Sema/SemaDecl.cpp:16296
   } else {
+if (TUK == TUK_Definition)
+  warnOnReservedIdentifier(New);

rsmith wrote:
> Why do we not diagnose the other possible `TagUseKind`s? `struct _foo;` and 
> `struct _foo *p;` both use reserved identifiers too.
We have a test case for `struct _foo` and its correctly diagnosed. I'll double 
check for pointer / reference too.


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

https://reviews.llvm.org/D93095

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


[PATCH] D94865: [ASTMatchers] Add callOrConstruct matcher

2021-01-28 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3c79734f2928: [ASTMatchers] Add invocation matcher (authored 
by stephenkelly).

Changed prior to commit:
  https://reviews.llvm.org/D94865?vs=319672=319943#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94865

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -863,6 +863,47 @@
  mapAnyOf(unaryOperator, cxxOperatorCallExpr)
  .with(hasAnyOperatorName("+", "!"),
forFunction(functionDecl(hasName("opFree")));
+
+  Code = R"cpp(
+struct ConstructorTakesInt
+{
+  ConstructorTakesInt(int i) {}
+};
+
+void callTakesInt(int i)
+{
+
+}
+
+void doCall()
+{
+  callTakesInt(42);
+}
+
+void doConstruct()
+{
+  ConstructorTakesInt cti(42);
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, traverse(TK_IgnoreUnlessSpelledInSource,
+ invocation(forFunction(functionDecl(hasName("doCall"))),
+hasArgument(0, integerLiteral(equals(42))),
+hasAnyArgument(integerLiteral(equals(42))),
+forEachArgumentWithParam(
+integerLiteral(equals(42)),
+parmVarDecl(hasName("i")));
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(
+  TK_IgnoreUnlessSpelledInSource,
+  invocation(forFunction(functionDecl(hasName("doConstruct"))),
+ hasArgument(0, integerLiteral(equals(42))),
+ hasAnyArgument(integerLiteral(equals(42))),
+ forEachArgumentWithParam(integerLiteral(equals(42)),
+  parmVarDecl(hasName("i")));
 }
 
 TEST_P(ASTMatchersTest, IsDerivedFrom) {
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -358,6 +358,7 @@
   REGISTER_MATCHER(injectedClassNameType);
   REGISTER_MATCHER(innerType);
   REGISTER_MATCHER(integerLiteral);
+  REGISTER_MATCHER(invocation);
   REGISTER_MATCHER(isAllowedToContainClauseKind);
   REGISTER_MATCHER(isAnonymous);
   REGISTER_MATCHER(isAnyCharacter);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -924,6 +924,7 @@
 const internal::MapAnyOfMatcher
 binaryOperation;
+const internal::MapAnyOfMatcher invocation;
 const internal::VariadicDynCastAllOfMatcher unaryOperator;
 const internal::VariadicDynCastAllOfMatcher
 conditionalOperator;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2829,6 +2829,42 @@
CXXRewrittenBinaryOperator>
 binaryOperation;
 
+/// Matches function calls and constructor calls
+///
+/// Because CallExpr and CXXConstructExpr do not share a common
+/// base class with API accessing arguments etc, AST Matchers for code
+/// which should match both are typically duplicated. This matcher
+/// removes the need for duplication.
+///
+/// Given code
+/// \code
+/// struct ConstructorTakesInt
+/// {
+///   ConstructorTakesInt(int i) {}
+/// };
+///
+/// void callTakesInt(int i)
+/// {
+/// }
+///
+/// void doCall()
+/// {
+///   callTakesInt(42);
+/// }
+///
+/// void doConstruct()
+/// {
+///   ConstructorTakesInt cti(42);
+/// }
+/// \endcode
+///
+/// The matcher
+/// \code
+/// invocation(hasArgument(0, integerLiteral(equals(42
+/// \endcode
+/// matches the expression in both doCall and doConstruct
+extern const internal::MapAnyOfMatcher invocation;
+
 /// Matches unary expressions that have a specific type of argument.
 ///
 /// Given
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -5613,6 +5613,40 @@
 
 
 
+Matcher*invocationMatcher*...Matcher*
+Matches function calls and constructor calls
+
+Because CallExpr and CXXConstructExpr do not share a common
+base 

[clang] 3c79734 - [ASTMatchers] Add invocation matcher

2021-01-28 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-01-28T20:47:09Z
New Revision: 3c79734f29284d6b54f1867a03428a3d9fd338d9

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

LOG: [ASTMatchers] Add invocation matcher

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 912da6e62c2f..ffad8acbeab6 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -5613,6 +5613,40 @@ AST Traversal Matchers
 
 
 
+Matcher*invocationMatcher*...Matcher*
+Matches function calls 
and constructor calls
+
+Because CallExpr and CXXConstructExpr do not share a common
+base class with API accessing arguments etc, AST Matchers for code
+which should match both are typically duplicated. This matcher
+removes the need for duplication.
+
+Given code
+struct ConstructorTakesInt
+{
+  ConstructorTakesInt(int i) {}
+};
+
+void callTakesInt(int i)
+{
+}
+
+void doCall()
+{
+  callTakesInt(42);
+}
+
+void doConstruct()
+{
+  ConstructorTakesInt cti(42);
+}
+
+The matcher
+invocation(hasArgument(0, integerLiteral(equals(42
+matches the expression in both doCall and doConstruct
+
+
+
 Matcher*eachOfMatcher*, ..., 
Matcher*
 Matches if any of the given 
matchers matches.
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 6f6dfab59a39..10532b3da209 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2829,6 +2829,42 @@ extern const internal::MapAnyOfMatcher
 binaryOperation;
 
+/// Matches function calls and constructor calls
+///
+/// Because CallExpr and CXXConstructExpr do not share a common
+/// base class with API accessing arguments etc, AST Matchers for code
+/// which should match both are typically duplicated. This matcher
+/// removes the need for duplication.
+///
+/// Given code
+/// \code
+/// struct ConstructorTakesInt
+/// {
+///   ConstructorTakesInt(int i) {}
+/// };
+///
+/// void callTakesInt(int i)
+/// {
+/// }
+///
+/// void doCall()
+/// {
+///   callTakesInt(42);
+/// }
+///
+/// void doConstruct()
+/// {
+///   ConstructorTakesInt cti(42);
+/// }
+/// \endcode
+///
+/// The matcher
+/// \code
+/// invocation(hasArgument(0, integerLiteral(equals(42
+/// \endcode
+/// matches the expression in both doCall and doConstruct
+extern const internal::MapAnyOfMatcher invocation;
+
 /// Matches unary expressions that have a specific type of argument.
 ///
 /// Given

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 6c7e14e3499a..6e36842d0660 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -924,6 +924,7 @@ const internal::VariadicDynCastAllOfMatcher
 const internal::MapAnyOfMatcher
 binaryOperation;
+const internal::MapAnyOfMatcher invocation;
 const internal::VariadicDynCastAllOfMatcher unaryOperator;
 const internal::VariadicDynCastAllOfMatcher
 conditionalOperator;

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 00a7c74a0b90..9ac9593e042b 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -358,6 +358,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(injectedClassNameType);
   REGISTER_MATCHER(innerType);
   REGISTER_MATCHER(integerLiteral);
+  REGISTER_MATCHER(invocation);
   REGISTER_MATCHER(isAllowedToContainClauseKind);
   REGISTER_MATCHER(isAnonymous);
   REGISTER_MATCHER(isAnyCharacter);

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index d681620cf548..1c6947acf0ab 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -863,6 +863,47 @@ void opFree()
  mapAnyOf(unaryOperator, cxxOperatorCallExpr)
  .with(hasAnyOperatorName("+", "!"),

forFunction(functionDecl(hasName("opFree")));
+
+  Code = R"cpp(
+struct ConstructorTakesInt
+{
+  ConstructorTakesInt(int i) {}
+};
+
+void callTakesInt(int i)
+{
+
+}
+
+void doCall()
+{
+  callTakesInt(42);
+}
+
+void doConstruct()
+{
+  ConstructorTakesInt cti(42);
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  

[PATCH] D95573: [ASTMatchers] Avoid pathological traversal over nested lambdas

2021-01-28 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 rG6f0df3cddb3e: [ASTMatchers] Avoid pathological traversal 
over nested lambdas (authored by stephenkelly).

Changed prior to commit:
  https://reviews.llvm.org/D95573?vs=319702=319941#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95573

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

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -3853,6 +3853,78 @@
   }
 }
 
+TEST(IgnoringImpCasts, PathologicalLambda) {
+
+  // Test that deeply nested lambdas are not a performance penalty
+  StringRef Code = R"cpp(
+void f() {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+int i = 42;
+(void)i;
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+}
+  )cpp";
+
+  EXPECT_TRUE(matches(Code, integerLiteral(equals(42;
+  EXPECT_TRUE(matches(Code, functionDecl(hasDescendant(integerLiteral(equals(42));
+}
+
 TEST(IgnoringImpCasts, MatchesImpCasts) {
   // This test checks that ignoringImpCasts matches when implicit casts are
   // present and its inner matcher alone does not match.
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -556,9 +556,9 @@
 if (LE->hasExplicitResultType())
   TraverseTypeLoc(Proto.getReturnLoc());
 TraverseStmt(LE->getTrailingRequiresClause());
-
-TraverseStmt(LE->getBody());
   }
+
+  TraverseStmt(LE->getBody());
   return true;
 }
 return RecursiveASTVisitor::dataTraverseNode(S, Queue);
@@ -697,6 +697,10 @@
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return true; }
 
+  // We visit the lambda body explicitly, so instruct the RAV
+  // to not visit it on our behalf too.
+  bool shouldVisitLambdaBody() const { return false; }
+
   bool IsMatchingInASTNodeNotSpelledInSource() const override {
 return TraversingASTNodeNotSpelledInSource;
   }
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -186,6 +186,9 @@
   /// code, e.g., implicit constructors and destructors.
   bool shouldVisitImplicitCode() const { return false; }
 
+  /// Return whether this visitor should recurse into lambda body
+  bool shouldVisitLambdaBody() const { return true; }
+
   /// Return whether this visitor should traverse post-order.
   bool shouldTraversePostOrder() const { return false; }
 
@@ -2057,6 +2060,14 @@
   // by clang.
   (!D->isDefaulted() || getDerived().shouldVisitImplicitCode());
 
+  if (const auto *MD = dyn_cast(D)) {
+if (const CXXRecordDecl *RD = MD->getParent()) {
+  if (RD->isLambda()) {
+VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
+  }
+}
+  }
+
   if (VisitBody) {
 TRY_TO(TraverseStmt(D->getBody())); // Function body.
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6f0df3c - [ASTMatchers] Avoid pathological traversal over nested lambdas

2021-01-28 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-01-28T20:45:45Z
New Revision: 6f0df3cddb3e3f38df1baa7aa4d743a74bb46688

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

LOG: [ASTMatchers] Avoid pathological traversal over nested lambdas

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

Added: 


Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 505ea700fd0e..db2ef21f4364 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -186,6 +186,9 @@ template  class RecursiveASTVisitor {
   /// code, e.g., implicit constructors and destructors.
   bool shouldVisitImplicitCode() const { return false; }
 
+  /// Return whether this visitor should recurse into lambda body
+  bool shouldVisitLambdaBody() const { return true; }
+
   /// Return whether this visitor should traverse post-order.
   bool shouldTraversePostOrder() const { return false; }
 
@@ -2057,6 +2060,14 @@ bool 
RecursiveASTVisitor::TraverseFunctionHelper(FunctionDecl *D) {
   // by clang.
   (!D->isDefaulted() || getDerived().shouldVisitImplicitCode());
 
+  if (const auto *MD = dyn_cast(D)) {
+if (const CXXRecordDecl *RD = MD->getParent()) {
+  if (RD->isLambda()) {
+VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
+  }
+}
+  }
+
   if (VisitBody) {
 TRY_TO(TraverseStmt(D->getBody())); // Function body.
   }

diff  --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp 
b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index 8ddd3c87e09d..5034203840fc 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -556,9 +556,9 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
 if (LE->hasExplicitResultType())
   TraverseTypeLoc(Proto.getReturnLoc());
 TraverseStmt(LE->getTrailingRequiresClause());
-
-TraverseStmt(LE->getBody());
   }
+
+  TraverseStmt(LE->getBody());
   return true;
 }
 return RecursiveASTVisitor::dataTraverseNode(S, Queue);
@@ -697,6 +697,10 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return true; }
 
+  // We visit the lambda body explicitly, so instruct the RAV
+  // to not visit it on our behalf too.
+  bool shouldVisitLambdaBody() const { return false; }
+
   bool IsMatchingInASTNodeNotSpelledInSource() const override {
 return TraversingASTNodeNotSpelledInSource;
   }

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 92bf244b0e4a..8004599e01a2 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -3853,6 +3853,78 @@ void binop()
   }
 }
 
+TEST(IgnoringImpCasts, PathologicalLambda) {
+
+  // Test that deeply nested lambdas are not a performance penalty
+  StringRef Code = R"cpp(
+void f() {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+  [] {
+int i = 42;
+(void)i;
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+  }();
+}
+  )cpp";
+
+  EXPECT_TRUE(matches(Code, integerLiteral(equals(42;
+  EXPECT_TRUE(matches(Code, 
functionDecl(hasDescendant(integerLiteral(equals(42));
+}
+
 TEST(IgnoringImpCasts, MatchesImpCasts) {
   // This test checks that ignoringImpCasts matches when implicit casts are
   // present and its inner matcher alone does not match.



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


[PATCH] D69726: [analyzer] DynamicSize: Store the dynamic size

2021-01-28 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a reviewer: vsavchenko.
Charusso added a comment.

Hey, I am back.




Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h:41-44
+/// Set the dynamic size of a CXXNewExpr \p NE by its region \p MR.
+ProgramStateRef setDynamicSize(ProgramStateRef State, const MemRegion *MR,
+   const CXXNewExpr *NE,
+   const LocationContext *LCtx, SValBuilder );

Charusso wrote:
> NoQ wrote:
> > This function is probably going to be used exactly once in the whole code. 
> > There's no need to turn it into a public API.
> It is being used 3 times already, so I believe it is a cool API.
Let us remove the `setDynamicSize(CXXNewExpr)` API from now on (was not that 
cool). This function will reside inside `ExprEngine::bindReturnValue()` which 
is the second phase of evaluating operator new: 
https://reviews.llvm.org/D40560#961694



Comment at: clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp:310-311
+
+  QualType Ty = TVR ? TVR->getDesugaredValueType(C.getASTContext())
+: CE->getArg(0)->IgnoreParenImpCasts()->getType();
+

Charusso wrote:
> NoQ wrote:
> > How is this better than `getValueType()`? Are you sure you're not getting a 
> > pointer type instead in the `!TVR` case? I.e., can you test this on a 
> > non-heap `SymRegion`?
> > How is this better than getValueType()?
> Consistency. We get the static ~~size~~ extent by getting the desugared type 
> which most likely just an extra overhead.
> 
> > Are you sure you're not getting a pointer type instead in the !TVR case? 
> > I.e., can you test this on a non-heap SymRegion?
> The issue was the `var_region_simple_ptr` test: we need to use regex for 
> checking after the `}}` token where `/ 4` is the correct result. I did not 
> really get why the test pass.
Added a conjured `SymbolicRegion` test called `user_defined_new` and an 
assertion.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1388
- ->castAs()
- ->StripCasts()
- ->castAs();

NoQ wrote:
> What happened to this `StripCasts()`? I don't see it in the after-code and I 
> vaguely remember having to be very careful with it.
I have reimplemented it by a mistake with the `getSuperRegion(MR)` helper 
routine. From now I will use `StripCasts()` instead. Nice catch!



Comment at: clang/lib/StaticAnalyzer/Core/DynamicSize.cpp:29
+/// Helper to bypass the top-level ElementRegion of \p MR.
+static const MemRegion *getSuperRegion(const MemRegion *MR) {
+  assert(MR);

Szelethus wrote:
> `getSuperRegionIfElementRegion`?
`getSuperRegion(MR)` was just a plain helper routine not restricted to return 
iff `MR` is an `ElementRegion`. It obtains the immediate region which we can 
measure in size, but it turns out the same idea as `MemRegion::StripCasts()`, 
so I have removed it.



Comment at: clang/lib/StaticAnalyzer/Core/DynamicSize.cpp:36-44
 DefinedOrUnknownSVal getDynamicSize(ProgramStateRef State, const MemRegion *MR,
 SValBuilder ) {
+  MR = getSuperRegion(MR);
+
+  if (const DefinedOrUnknownSVal *Size = State->get(MR))
+return *Size;
+

Szelethus wrote:
> Well hold on for a second. Does this mean that we legit resolved 
> `getDynamicSize` to `getStaticSize`??? That's crazy! I've been looking around 
> in the code for how does your patch interact with our current dynamic size 
> modeling, but I guess I never really realized that there is no such a thing. 
> Odd to not even see a FIXME around.
I wanted to upstream both of the patches, but this one became dead:

[analyzer] DynamicSize: Remove 'getExtent()' from regions
Oct 29 2019, 01:43

[analyzer] DynamicSize: Store the dynamic size
Nov 1 2019, 19:57

Sorry for the inconvenience.



Comment at: clang/lib/StaticAnalyzer/Core/DynamicSize.cpp:80-82
+  /* FIXME: Make this work.
+  if (const auto CI = Size.getAs())
+assert(CI->getValue().isUnsigned());*/

Szelethus wrote:
> Make this work as is "make sure that checkers actually obey this 
> precondition" or does the assert just not work as-is? Could you specify this 
> comment?
This assertion was about the signedness, because I have seen something like 
`unsigned(42) == signed(42)` did not evaluate to true, and I really wanted to 
make the size equality to be true in such value-equality cases. I have added a 
test (signedness_equality) instead, which is working fine now (I hope, because 
I am not sure what was the original behavior).



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:779-780
 
   bool IsStandardGlobalOpNewFunction =
   FD->isReplaceableGlobalAllocationFunction();
 

Szelethus wrote:
> I wonder what the rationale was here. Why do we explicitly 

[PATCH] D69726: [analyzer] DynamicSize: Store the dynamic size

2021-01-28 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 319940.
Charusso marked 6 inline comments as done.
Charusso added a comment.

- Fix everything.


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

https://reviews.llvm.org/D69726

Files:
  clang/docs/analyzer/developer-docs/DebugChecks.rst
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
  clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/explain-svals.cpp
  clang/test/Analysis/expr-inspection.cpp
  clang/test/Analysis/memory-model.cpp

Index: clang/test/Analysis/memory-model.cpp
===
--- /dev/null
+++ clang/test/Analysis/memory-model.cpp
@@ -0,0 +1,157 @@
+// RUN: %clang_analyze_cc1 -std=c++20 \
+// RUN:  -analyzer-checker=core,unix,cplusplus,debug.ExprInspection \
+// RUN:  -triple x86_64-unknown-linux-gnu \
+// RUN:  -verify %s
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+typedef __SIZE_TYPE__ size_t;
+void *malloc(size_t);
+void *alloca(size_t);
+void *realloc(void *ptr, size_t size);
+void *calloc(size_t number, size_t size);
+void free(void *);
+
+struct S {
+  int f;
+};
+
+void clang_analyzer_dump(int);
+void clang_analyzer_dump(const void *);
+void clang_analyzer_dumpExtent(int);
+void clang_analyzer_dumpExtent(const void *);
+void clang_analyzer_dumpElementCount(int);
+void clang_analyzer_dumpElementCount(const void *);
+
+int clang_analyzer_getExtent(void *);
+void clang_analyzer_eval(bool);
+
+void var_simple_ref() {
+  int a = 13;
+  clang_analyzer_dump(); // expected-warning {{a}}
+  clang_analyzer_dumpExtent();   // expected-warning {{4 S64b}}
+  clang_analyzer_dumpElementCount(); // expected-warning {{1 S64b}}
+}
+
+void var_simple_ptr(int *a) {
+  clang_analyzer_dump(a); // expected-warning {{SymRegion{reg_$0}}}
+  clang_analyzer_dumpExtent(a);   // expected-warning {{extent_$1{SymRegion{reg_$0
+  clang_analyzer_dumpElementCount(a); // expected-warning {{(extent_$1{SymRegion{reg_$0}}) / 4}}
+}
+
+void var_array() {
+  int a[] = {1, 2, 3};
+  clang_analyzer_dump(a); // expected-warning {{Element{a,0 S64b,int}}}
+  clang_analyzer_dumpExtent(a);   // expected-warning {{12 S64b}}
+  clang_analyzer_dumpElementCount(a); // expected-warning {{3 S64b}}
+}
+
+void string() {
+  clang_analyzer_dump("foo"); // expected-warning {{Element{"foo",0 S64b,char}}}
+  clang_analyzer_dumpExtent("foo");   // expected-warning {{4 S64b}}
+  clang_analyzer_dumpElementCount("foo"); // expected-warning {{4 S64b}}
+}
+
+void struct_simple_ptr(S *a) {
+  clang_analyzer_dump(a); // expected-warning {{SymRegion{reg_$0}}}
+  clang_analyzer_dumpExtent(a);   // expected-warning {{extent_$1{SymRegion{reg_$0
+  clang_analyzer_dumpElementCount(a); // expected-warning {{(extent_$1{SymRegion{reg_$0}}) / 4}}
+}
+
+void field_ref(S a) {
+  clang_analyzer_dump(); // expected-warning {{a.f}}
+  clang_analyzer_dumpExtent();   // expected-warning {{4 S64b}}
+  clang_analyzer_dumpElementCount(); // expected-warning {{1 S64b}}
+}
+
+void field_ptr(S *a) {
+  clang_analyzer_dump(>f); // expected-warning {{SymRegion{reg_$0}.f}}
+  clang_analyzer_dumpExtent(>f);   // expected-warning {{4 S64b}}
+  clang_analyzer_dumpElementCount(>f); // expected-warning {{1 S64b}}
+}
+
+void symbolic_array() {
+  int *a = new int[3];
+  clang_analyzer_dump(a); // expected-warning {{Element{HeapSymRegion{conj}}
+  clang_analyzer_dumpExtent(a);   // expected-warning {{12 S64b}}
+  clang_analyzer_dumpElementCount(a); // expected-warning {{3 S64b}}
+  delete[] a;
+}
+
+void symbolic_placement_new() {
+  char *buf = new char[sizeof(int) * 3];
+  int *a = new (buf) int(12);
+  clang_analyzer_dump(a); // expected-warning {{Element{HeapSymRegion{conj}}
+  clang_analyzer_dumpExtent(a);   // expected-warning {{12 S64b}}
+  clang_analyzer_dumpElementCount(a); // expected-warning {{3 S64b}}
+  delete[] buf;
+}
+
+void symbolic_malloc() {
+  int *a = (int *)malloc(12);
+  clang_analyzer_dump(a); // expected-warning {{Element{HeapSymRegion{conj}}
+  clang_analyzer_dumpExtent(a);   // expected-warning {{12 U64b}}
+  clang_analyzer_dumpElementCount(a); // expected-warning {{3 S64b}}
+  free(a);
+}
+
+void symbolic_alloca() {
+  int *a = (int *)alloca(12);
+  clang_analyzer_dump(a); // expected-warning {{Element{HeapSymRegion{conj}}
+  clang_analyzer_dumpExtent(a);   // expected-warning {{12 U64b}}
+  clang_analyzer_dumpElementCount(a); // expected-warning {{3 S64b}}
+}
+
+void 

[PATCH] D95534: clang-cl: Invent a /winsysroot concept

2021-01-28 Thread Nico Weber via Phabricator via cfe-commits
thakis updated this revision to Diff 319938.
thakis added a comment.

add test


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

https://reviews.llvm.org/D95534

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/cl-sysroot.cpp

Index: clang/test/Driver/cl-sysroot.cpp
===
--- /dev/null
+++ clang/test/Driver/cl-sysroot.cpp
@@ -0,0 +1,27 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cl /winsysroot %t /c -- %t/foo.cpp
+// RUN: %clang_cl /vctoolsdir %t/VC/Tools/MSVC/14.26.28801 \
+// RUN:   /winsdkdir "%t/Windows Kits/10" \
+// RUN:   /c -- %t/foo.cpp
+
+#--- VC/Tools/MSVC/14.26.28801/include/string
+namespace std {
+class mystring {
+public:
+  bool empty();
+};
+}
+
+#--- Windows Kits/10/Include/10.0.19041.0/ucrt/assert.h
+#define myassert(X)
+
+#--- foo.cpp
+#include 
+#include 
+
+void f() {
+  std::mystring s;
+  myassert(s.empty());
+}
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -66,14 +66,49 @@
 static bool getSystemRegistryString(const char *keyPath, const char *valueName,
 std::string , std::string *phValue);
 
+static bool getHighestNumericTupleInDirectory(StringRef Directory, std::string ) {
+  Highest.clear();
+  llvm::VersionTuple HighestTuple;
+
+  std::error_code EC;
+  for (llvm::sys::fs::directory_iterator DirIt(Directory, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+llvm::VersionTuple Tuple;
+if (Tuple.tryParse(CandidateName)) // tryParse() returns true on error.
+  continue;
+if (Tuple > HighestTuple) {
+  HighestTuple = Tuple;
+  Highest = CandidateName.str();
+}
+  }
+
+  return !Highest.empty();
+}
+
 // Check command line arguments to try and find a toolchain.
 static bool
 findVCToolChainViaCommandLine(const ArgList , std::string ,
   MSVCToolChain::ToolsetLayout ) {
   // Don't validate the input; trust the value supplied by the user.
   // The primary motivation is to prevent unnecessary file and registry access.
-  if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsdir)) {
-Path = A->getValue();
+  if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsdir,
+   options::OPT__SLASH_winsysroot)) {
+if (A->getOption().getID() == options::OPT__SLASH_winsysroot) {
+  llvm::SmallString<128> ToolsPath(A->getValue());
+  llvm::sys::path::append(ToolsPath, "VC", "Tools", "MSVC");
+  std::string VCToolsVersion;
+  if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsversion))
+VCToolsVersion = A->getValue();
+  else
+getHighestNumericTupleInDirectory(ToolsPath, VCToolsVersion);
+  llvm::sys::path::append(ToolsPath, VCToolsVersion);
+  Path = std::string(ToolsPath.str());
+} else {
+  Path = A->getValue();
+}
 VSLayout = MSVCToolChain::ToolsetLayout::VS2017OrNewer;
 return true;
   }
@@ -345,7 +380,8 @@
   // they're doing. If the user passes /vctoolsdir or /winsdkdir, trust that
   // over env vars.
   if (!llvm::sys::Process::GetEnv("LIB") ||
-  Args.getLastArg(options::OPT__SLASH_vctoolsdir)) {
+  Args.getLastArg(options::OPT__SLASH_vctoolsdir,
+  options::OPT__SLASH_winsysroot)) {
 CmdArgs.push_back(Args.MakeArgString(
 Twine("-libpath:") +
 TC.getSubDirectoryPath(
@@ -356,7 +392,8 @@
"atlmfc")));
   }
   if (!llvm::sys::Process::GetEnv("LIB") ||
-  Args.getLastArg(options::OPT__SLASH_winsdkdir)) {
+  Args.getLastArg(options::OPT__SLASH_winsdkdir,
+  options::OPT__SLASH_winsysroot)) {
 if (TC.useUniversalCRT()) {
   std::string UniversalCRTLibPath;
   if (TC.getUniversalCRTLibraryPath(Args, UniversalCRTLibPath))
@@ -1074,37 +,38 @@
   std::error_code EC;
   llvm::SmallString<128> IncludePath(SDKPath);
   llvm::sys::path::append(IncludePath, "Include");
-  for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
-   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
-if (!llvm::sys::fs::is_directory(DirIt->path()))
-  continue;
-StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
-// If WDK is installed, there could be subfolders like "wdf" in the
-// "Include" directory.
-// Allow only directories which names start with "10.".
-if (!CandidateName.startswith("10."))
-  continue;
-if (CandidateName > SDKVersion)
-  SDKVersion = std::string(CandidateName);
-  }
-
-  return !SDKVersion.empty();
+  return 

[PATCH] D93095: Introduce -Wreserved-identifier

2021-01-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:2421-2428
+// Perform a lookup at TUScope. If it succeeds, we're at global scope and a
+// single '_' is enough to be reserved.
+LookupResult IdentifierLookup(*this, II, SourceLocation(),
+  Sema::LookupAnyName,
+  Sema::ForExternalRedeclaration);
+IdentifierLookup.suppressDiagnostics();
+if (LookupName(IdentifierLookup, TUScope))

aaron.ballman wrote:
> rsmith wrote:
> > I don't understand why name lookup is involved here. Whether an identifier 
> > is reserved doesn't depend on whether it's already been declared in the 
> > global namespace or not. It's valid to declare `_foo` in some user-defined 
> > namespace regardless of whether there's already a `_foo` in the global 
> > namespace, and it's invalid to declare `_foo` in the global namespace 
> > regardless of whether there's already a `_foo` in the global namespace.
> > 
> > If you're trying to detect whether the name is being introduced in the 
> > global namespace scope, per C++ [lex.name]/3.2, you can't do that like 
> > this; you'll need to look at the `DeclContext` of the declaration instead 
> > of just the identifier.
> Sorry @serge-sans-paille for my think-o, Richard is right.
> 
> My thinking was "if the declaration can be found at the global namespace, 
> then it's reserved", but.. that's a hypothetical declaration, not an actual 
> one, so of course the name lookup won't find it. Derp.
> 
> I guess we really do have to look at the `DeclContext`.
> 
> @rsmith -- just to be clear, from http://eel.is/c++draft/lex.name#3.2, does 
> "for use as a name in the global namespace" imply macros as well? e.g., can 
> an implementation decide to use this reservation to `#define _foo 12`, which 
> would cause problems with a `_foo` declared in a user-defined namespace? If 
> so, then we can ignore what the declaration context is because the name could 
> be snatched out from under the user via a macro anyway.
Regarding macros, I think it depends what you mean.

The implementation is permitted to declare additional `_foo` names in the 
global namespace, and I think the intent is that these can be either 
predeclared or declared in headers. The user is permitted to declare `_foo` 
names in other (non-reserved) namespaces.

As a result, neither party should define an `_foo` macro, because doing so 
would step on the other party's namespace (though it would be OK for user code 
to do so after all of their standard library includes, I suppose). 
Specifically, I think it would be non-conforming for the implementation to 
`#define` such a macro (because the name is not reserved to the implementation 
in all contexts), and I think it would be UB via [macro.names]/1 for user code 
to `#define` such a macro that actually collided with a name that happened to 
be declared in the global namespace by a standard library header.

We can probably warn on `#define _foo` if we want to, but I don't think we can 
produce a `-pedantic-error` for that case, because I think it's (sometimes) 
valid for user code to do that.


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

https://reviews.llvm.org/D93095

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


[PATCH] D95634: [PowerPC][Power10] Fix XXSPLI32DX not correctly exploiting specific cases

2021-01-28 Thread Albion Fung via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Conanap marked 4 inline comments as done.
Closed by commit rG2e470e03b49f: [PowerPC][Power10] Fix XXSPLI32DX not 
correctly exploiting specific cases (authored by Conanap).

Changed prior to commit:
  https://reviews.llvm.org/D95634?vs=319916=319937#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95634

Files:
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/p10-splatImm32.ll


Index: llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
===
--- llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
+++ llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
@@ -101,23 +101,11 @@
   ret <8 x i16> 
 }
 
-define dso_local <16 x i8> @test_xxsplti32dx_10() {
-; CHECK-LABEL: test_xxsplti32dx_10:
-; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:xxlxor vs34, vs34, vs34
-; CHECK-NEXT:xxsplti32dx vs34, 0, 1207959552
-; CHECK-NEXT:blr
-entry:
-  ret <16 x i8> 
-}
-
-; FIXME: It appears that there is something wrong with the computation
-;of the 64-bit constant to splat so we cannot emit xxsplti32dx for
-;this test case for now.
 define dso_local <16 x i8> @constSplatBug() {
 ; CHECK-LABEL: constSplatBug:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:plxv vs34, .LCPI10_0@PCREL(0), 1
+; CHECK-NEXT:xxlxor vs34, vs34, vs34
+; CHECK-NEXT:xxsplti32dx vs34, 0, 1191182336
 ; CHECK-NEXT:blr
 entry:
   ret <16 x i8> 
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -8604,16 +8604,19 @@
 
   // If it is a splat of a double, check if we can shrink it to a 32 bit
   // non-denormal float which when converted back to double gives us the same
-  // double. This is to exploit the XXSPLTIDP instruction.+  // If we lose 
precision, we use XXSPLTI32DX.
+  // double. This is to exploit the XXSPLTIDP instruction.
+  // If we lose precision, we use XXSPLTI32DX.
   if (BVNIsConstantSplat && (SplatBitSize == 64) &&
   Subtarget.hasPrefixInstrs()) {
-if (convertToNonDenormSingle(APSplatBits) &&
-(Op->getValueType(0) == MVT::v2f64)) {
+// Check the type first to short-circuit so we don't modify APSplatBits if
+// this block isn't executed.
+if ((Op->getValueType(0) == MVT::v2f64) &&
+convertToNonDenormSingle(APSplatBits)) {
   SDValue SplatNode = DAG.getNode(
   PPCISD::XXSPLTI_SP_TO_DP, dl, MVT::v2f64,
   DAG.getTargetConstant(APSplatBits.getZExtValue(), dl, MVT::i32));
   return DAG.getBitcast(Op.getValueType(), SplatNode);
-} else if (APSplatBits.getBitWidth() == 64) {
+} else {
   // We may lose precision, so we have to use XXSPLTI32DX.
 
   uint32_t Hi =


Index: llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
===
--- llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
+++ llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
@@ -101,23 +101,11 @@
   ret <8 x i16> 
 }
 
-define dso_local <16 x i8> @test_xxsplti32dx_10() {
-; CHECK-LABEL: test_xxsplti32dx_10:
-; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:xxlxor vs34, vs34, vs34
-; CHECK-NEXT:xxsplti32dx vs34, 0, 1207959552
-; CHECK-NEXT:blr
-entry:
-  ret <16 x i8> 
-}
-
-; FIXME: It appears that there is something wrong with the computation
-;of the 64-bit constant to splat so we cannot emit xxsplti32dx for
-;this test case for now.
 define dso_local <16 x i8> @constSplatBug() {
 ; CHECK-LABEL: constSplatBug:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:plxv vs34, .LCPI10_0@PCREL(0), 1
+; CHECK-NEXT:xxlxor vs34, vs34, vs34
+; CHECK-NEXT:xxsplti32dx vs34, 0, 1191182336
 ; CHECK-NEXT:blr
 entry:
   ret <16 x i8> 
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -8604,16 +8604,19 @@
 
   // If it is a splat of a double, check if we can shrink it to a 32 bit
   // non-denormal float which when converted back to double gives us the same
-  // double. This is to exploit the XXSPLTIDP instruction.+  // If we lose precision, we use XXSPLTI32DX.
+  // double. This is to exploit the XXSPLTIDP instruction.
+  // If we lose precision, we use XXSPLTI32DX.
   if (BVNIsConstantSplat && (SplatBitSize == 64) &&
   Subtarget.hasPrefixInstrs()) {
-if (convertToNonDenormSingle(APSplatBits) &&
-(Op->getValueType(0) == MVT::v2f64)) {
+// Check the type first to short-circuit so we don't modify APSplatBits if
+// this block isn't executed.
+if ((Op->getValueType(0) == 

[PATCH] D95534: clang-cl: Invent a /winsysroot concept

2021-01-28 Thread Nico Weber via Phabricator via cfe-commits
thakis updated this revision to Diff 319936.
thakis edited the summary of this revision.
thakis added a comment.

Seems like there are no strong opinions, so now with actual code. I went with 
"VC/Tools/MSVC/XXX" and "Windows Kits/10" since that seems like the obvious 
thing.


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

https://reviews.llvm.org/D95534

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/MSVC.cpp

Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -66,14 +66,49 @@
 static bool getSystemRegistryString(const char *keyPath, const char *valueName,
 std::string , std::string *phValue);
 
+static bool getHighestNumericTupleInDirectory(StringRef Directory, std::string ) {
+  Highest.clear();
+  llvm::VersionTuple HighestTuple;
+
+  std::error_code EC;
+  for (llvm::sys::fs::directory_iterator DirIt(Directory, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+llvm::VersionTuple Tuple;
+if (Tuple.tryParse(CandidateName)) // tryParse() returns true on error.
+  continue;
+if (Tuple > HighestTuple) {
+  HighestTuple = Tuple;
+  Highest = CandidateName.str();
+}
+  }
+
+  return !Highest.empty();
+}
+
 // Check command line arguments to try and find a toolchain.
 static bool
 findVCToolChainViaCommandLine(const ArgList , std::string ,
   MSVCToolChain::ToolsetLayout ) {
   // Don't validate the input; trust the value supplied by the user.
   // The primary motivation is to prevent unnecessary file and registry access.
-  if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsdir)) {
-Path = A->getValue();
+  if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsdir,
+   options::OPT__SLASH_winsysroot)) {
+if (A->getOption().getID() == options::OPT__SLASH_winsysroot) {
+  llvm::SmallString<128> ToolsPath(A->getValue());
+  llvm::sys::path::append(ToolsPath, "VC", "Tools", "MSVC");
+  std::string VCToolsVersion;
+  if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsversion))
+VCToolsVersion = A->getValue();
+  else
+getHighestNumericTupleInDirectory(ToolsPath, VCToolsVersion);
+  llvm::sys::path::append(ToolsPath, VCToolsVersion);
+  Path = std::string(ToolsPath.str());
+} else {
+  Path = A->getValue();
+}
 VSLayout = MSVCToolChain::ToolsetLayout::VS2017OrNewer;
 return true;
   }
@@ -345,7 +380,8 @@
   // they're doing. If the user passes /vctoolsdir or /winsdkdir, trust that
   // over env vars.
   if (!llvm::sys::Process::GetEnv("LIB") ||
-  Args.getLastArg(options::OPT__SLASH_vctoolsdir)) {
+  Args.getLastArg(options::OPT__SLASH_vctoolsdir,
+  options::OPT__SLASH_winsysroot)) {
 CmdArgs.push_back(Args.MakeArgString(
 Twine("-libpath:") +
 TC.getSubDirectoryPath(
@@ -356,7 +392,8 @@
"atlmfc")));
   }
   if (!llvm::sys::Process::GetEnv("LIB") ||
-  Args.getLastArg(options::OPT__SLASH_winsdkdir)) {
+  Args.getLastArg(options::OPT__SLASH_winsdkdir,
+  options::OPT__SLASH_winsysroot)) {
 if (TC.useUniversalCRT()) {
   std::string UniversalCRTLibPath;
   if (TC.getUniversalCRTLibraryPath(Args, UniversalCRTLibPath))
@@ -1074,37 +,38 @@
   std::error_code EC;
   llvm::SmallString<128> IncludePath(SDKPath);
   llvm::sys::path::append(IncludePath, "Include");
-  for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
-   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
-if (!llvm::sys::fs::is_directory(DirIt->path()))
-  continue;
-StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
-// If WDK is installed, there could be subfolders like "wdf" in the
-// "Include" directory.
-// Allow only directories which names start with "10.".
-if (!CandidateName.startswith("10."))
-  continue;
-if (CandidateName > SDKVersion)
-  SDKVersion = std::string(CandidateName);
-  }
-
-  return !SDKVersion.empty();
+  return getHighestNumericTupleInDirectory(IncludePath, SDKVersion);
 }
 
 static bool getWindowsSDKDirViaCommandLine(const ArgList ,
std::string , int ,
std::string ) {
-  if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsdkdir)) {
+  if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsdkdir,
+   options::OPT__SLASH_winsysroot)) {
 // Don't validate the input; trust the value supplied by the user.
 // The motivation is to prevent unnecessary file and 

[PATCH] D95369: [clang][cli] Generate and round-trip analyzer options

2021-01-28 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: clang/lib/Frontend/CompilerInvocation.cpp:822
+
 static bool ParseAnalyzerArgs(AnalyzerOptions , ArgList ,
   DiagnosticsEngine ) {

Can you rename this `ParseAnalyzerArgsImpl` for better readability?



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1002
+
+  return RoundTrip(Parse, Generate, Swap, Res, Args, Diags, "AnalyzerOptions");
+}

I wonder if these lambdas could/should just be defined inline in the call to 
`RoundTrip`, but up to you to decide.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95369

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


[PATCH] D95629: [clang][analyzer] Own string keys in AnalyzerOptions::ConfigTable

2021-01-28 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith requested changes to this revision.
dexonsmith added a comment.
This revision now requires changes to proceed.

> This patch replaces StringMap<...> with std::map in 
> AnalyzerOptions::ConfigTable. It seems to be the only non-owning reference to 
> command line arguments in the whole CompilerInvocation, which would introduce 
> a lot of complexity with round-tripping arguments (D94472 
> ).

I think this patch can be skipped. `StringMap` owns its own strings. 
`StringMapEntry` uses tail allocation to include a null-terminated string 
inline. For details, have a look at `StringMapEntry::Create` in 
llvm/ADT/StringMapEntry.h.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95629

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


[PATCH] D93095: Introduce -Wreserved-identifier

2021-01-28 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 319929.
serge-sans-paille added a comment.

Back to the previous version, as suggested by @rsmith . I made a few updates to 
`NamedDecl::isReserved` which get me close to the expected result, without too 
much overhead.


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

https://reviews.llvm.org/D93095

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/Sema/reserved-identifier.c
  clang/test/Sema/reserved-identifier.cpp

Index: clang/test/Sema/reserved-identifier.cpp
===
--- /dev/null
+++ clang/test/Sema/reserved-identifier.cpp
@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify -Wreserved-identifier %s
+
+int foo__bar() { return 0; }// expected-warning {{'foo__bar' is a reserved identifier}}
+static int _bar() { return 0; } // expected-warning {{'_bar' is a reserved identifier}}
+static int _Bar() { return 0; } // expected-warning {{'_Bar' is a reserved identifier}}
+int _barbouille() { return 0; } // expected-warning {{'_barbouille' is a reserved identifier}}
+
+void foo(unsigned int _Reserved) { // expected-warning {{'_Reserved' is a reserved identifier}}
+  unsigned int __1 =   // expected-warning {{'__1' is a reserved identifier}}
+  _Reserved;   // no-warning
+}
+
+// This one is explicitly skipped by -Wreserved-identifier
+void *_; // no-warning
+
+template  constexpr bool __toucan = true; // expected-warning {{'__toucan' is a reserved identifier}}
+
+template 
+concept _Barbotine = __toucan; // expected-warning {{'_Barbotine' is a reserved identifier}}
+
+template  // expected-warning {{'__' is a reserved identifier}}
+struct BarbeNoire {};
+
+template  // expected-warning {{'__' is a reserved identifier}}
+void BarbeRousse() {}
+
+namespace _Barbidur { // expected-warning {{'_Barbidur' is a reserved identifier}}
+
+struct __barbidou {}; // expected-warning {{'__barbidou' is a reserved identifier}}
+struct _barbidou {};  // no-warning
+
+int __barbouille; // expected-warning {{'__barbouille' is a reserved identifier}}
+int _barbouille;  // no-warning
+
+int __babar() { return 0; } // expected-warning {{'__babar' is a reserved identifier}}
+int _babar() { return 0; }  // no-warning
+
+} // namespace _Barbidur
+
+class __barbapapa { // expected-warning {{'__barbapapa' is a reserved identifier}}
+  void _barbabelle() {} // no-warning
+  int _Barbalala;   // expected-warning {{'_Barbalala' is a reserved identifier}}
+};
+
+enum class __menu { // expected-warning {{'__menu' is a reserved identifier}}
+  __some,   // expected-warning {{'__some' is a reserved identifier}}
+  _Other,   // expected-warning {{'_Other' is a reserved identifier}}
+  _other// no-warning
+};
+
+enum _Menu { // expected-warning {{'_Menu' is a reserved identifier}}
+  _OtheR_,   // expected-warning {{'_OtheR_' is a reserved identifier}}
+  _other_// expected-warning {{'_other_' is a reserved identifier}}
+};
+
+enum {
+  __some, // expected-warning {{'__some' is a reserved identifier}}
+  _Other, // expected-warning {{'_Other' is a reserved identifier}}
+  _other  // expected-warning {{'_other' is a reserved identifier}}
+};
+
+static union {
+  int _barbeFleurie; // no-warning
+};
+
+using _Barbamama = __barbapapa; // expected-warning {{'_Barbamama' is a reserved identifier}}
+
+int foobar() {
+  return foo__bar(); // no-warning
+}
+
+namespace {
+int _barbatruc; // no-warning
+}
+
+long double operator"" _BarbeBleue(long double) // no-warning
+{
+  return 0.;
+}
Index: clang/test/Sema/reserved-identifier.c
===
--- /dev/null
+++ clang/test/Sema/reserved-identifier.c
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wreserved-identifier -Wno-visibility %s
+
+#define __oof foo__ // expected-warning {{macro name is a reserved identifier}}
+
+int foo__bar() { return 0; }// no-warning
+static int _bar() { return 0; } // expected-warning {{'_bar' is a reserved identifier}}
+static int _Bar() { return 0; } // expected-warning {{'_Bar' is a reserved identifier}}
+int _foo() { return 0; }// expected-warning {{'_foo' is a reserved identifier}}
+
+// This one is explicitly skipped by -Wreserved-identifier
+void *_; // no-warning
+
+void foo(unsigned int _Reserved) { // expected-warning {{'_Reserved' is a reserved identifier}}
+  unsigned int __1 =   // expected-warning {{'__1' is a reserved identifier}}
+  _Reserved;   // no-warning
+  goto __reserved;
+__reserved: // expected-warning {{'__reserved' is a reserved 

[PATCH] D95366: [clang][cli] Generate and round-trip preprocessor options

2021-01-28 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3093
+
+static bool ParsePreprocessorArgs(PreprocessorOptions , ArgList ,
   DiagnosticsEngine ,

Can we name this differently, so it's obvious which is being called without 
looking at the argument list? I suggest `ParsePreprocessorArgsImpl` for this 
one, since it's doing the actual parsing.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3215-3216
+
+  return RoundTrip(Parse, Generate, Swap, Res, Args, Diags,
+   "PreprocessorOptions");
 }

Have you considered just defining the lambdas inline in the call to 
`RoundTrip`? I'm fine either way, but the way clang-format tends to clean this 
up seems pretty readable to me, and the names don't really add much value since 
they match the functions being called. Up to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95366

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


[PATCH] D94472: [clang][cli] Command line round-trip for HeaderSearch options

2021-01-28 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith requested changes to this revision.
dexonsmith added a comment.
This revision now requires changes to proceed.

This is getting close! A few more comments inline.




Comment at: clang/lib/Frontend/CompilerInvocation.cpp:584-589
+static bool Equal(const ArgStringList , const ArgStringList ) {
+  auto StrEq = [](const char *AElem, const char *BElem) {
+return StringRef(AElem) == StringRef(BElem);
+  };
+  return std::equal(A.begin(), A.end(), B.begin(), B.end(), StrEq);
+}

I suggest inlining `Equal` and defining the lambda directly in the call to 
`std::equal`; I think that'll be easier to read than having this up here. (Nice 
to have it split out fo rcompile-time if `RoundTrip` is templated, but I have a 
suggestion about that below.)



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:591-596
+static void Print(ArgStringList , const llvm::Twine ) {
+  llvm::dbgs() << Description;
+  for (const char *Arg : Args)
+llvm::dbgs() << " " << Arg;
+  llvm::dbgs() << "\n";
+}

- I think this would be more clear as a local lambda too.
- I don't think this is the best destination, since `llvm::dbgs()` goes nowhere 
when `NDEBUG`. Should this go in `errs()`? Or should `-round-trip-args-debug=` 
take a filename for where to write extra stuff?
- The arguments won't be correctly formatted for copy-paste if there are any 
characters that should be escaped. Is the logic from `-###` reusable?



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:604-608
+template 
+static bool RoundTrip(ParseFn &, GenerateFn &,
+  SwapOptsFn &, CompilerInvocation ,
+  ArgList , DiagnosticsEngine ,
+  StringRef OptsName) {

Instead of templating this, can we take `llvm::function_ref`s to type-erase the 
functions?



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:633
+SwapOpts(Res);
+return Parse(Res, OriginalArgs, Diags);
+  }

I suggest double-checking that the second parse also fails, and reporting that 
as an error somehow.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:654-656
+  InputArgList GeneratedArgs1 =
+  getDriverOptTable().ParseArgs(GeneratedStrings1, MissingArgIndex1,
+MissingArgCount1, options::CC1Option);

Does this need to be checked for success / error conditions in any way?



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:663
+  SwapOpts(Res);
+  bool Success2 = Parse(Res, GeneratedArgs1, Diags);
+

Might be better to error here if the second parse fails. We'd want to debug the 
generated args too.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:684-685
+  if (!GeneratedStringsEqual)
+llvm::report_fatal_error("Mismatch between arguments generated during "
+ "round-trip");
+

Another option vs. report_fatal_error would be to create (fatal) clang error 
diagnostics. That applies here, and to my previous comments. WDYT? (@Bigcheese, 
any thoughts?)

Also, I think `-round-trip-args-debug` might not be super discoverable. Maybe 
we can add a comment in the code where the errors are reported suggesting 
adding that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94472

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


[PATCH] D95635: [CMake] Actually require python 3.6 or greater

2021-01-28 Thread Julian Lettner via Phabricator via cfe-commits
yln added a comment.

In D95635#2528851 , @JDevlieghere 
wrote:

>> However, the project claims to require 3.6 or greater, and 3.6 features are 
>> being used.
>
> Can you link to where it says that? I'm not opposed to making 3.6 the 
> minimally required version, but at least for LLDB we don't have that 
> requirement and we have documentation mentioning Python 3.5.

For LLVM: https://llvm.org/docs/GettingStarted.html#software


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95635

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


[PATCH] D95119: Prefer /usr/bin/env xxx over /usr/bin/xxx where xxx = perl, python, awk

2021-01-28 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM, unless @MaskRay has any other concerns.


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

https://reviews.llvm.org/D95119

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


[PATCH] D95514: [clang][cli] Teach CompilerInvocation to allocate strings on its own

2021-01-28 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D95514#2528407 , @Bigcheese wrote:

> In D95514#2528324 , @jansvoboda11 
> wrote:
>
>> I've looked through all option classes in `CompilerInvocation`, and 
>> `AnalyzerOptions::Config` seems to be the only member that stores non-owning 
>> references to command line arguments.
>> I think the best path forward is to change `AnalyzerOptions` to take 
>> ownership and avoid dealing with complicated lifetimes. We can look into 
>> removing allocations later, as an optional optimization.
>> What do you think?
>
> I think that makes sense given the rest of `CompilerInvocation` is owning.

+1, let's just simplify this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95514

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


[PATCH] D95635: [CMake] Actually require python 3.6 or greater

2021-01-28 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

> However, the project claims to require 3.6 or greater, and 3.6 features are 
> being used.

Can you link to where it says that? I'm not opposed to making 3.6 minimally 
required version, but at least for LLDB we don't have that requirement and we 
have documentation mentioning Python 3.5.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95635

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


[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-01-28 Thread Alex Orlov via Phabricator via cfe-commits
aorlov added a comment.

One more ping. Please, pay attention to this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

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


[PATCH] D95635: [CMake] Actually require python 3.6 or greater

2021-01-28 Thread Julian Lettner via Phabricator via cfe-commits
yln added a comment.

LGTM, thanks!  (I got bitten by this.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95635

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


[PATCH] D69322: [hip][cuda] Enable extended lambda support on Windows.

2021-01-28 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/include/clang/AST/DeclCXX.h:395-400
 /// The number used to indicate this lambda expression for name
 /// mangling in the Itanium C++ ABI.
 unsigned ManglingNumber : 31;
 
+/// The device side mangling number.
+unsigned DeviceManglingNumber = 0;

hliao wrote:
> rnk wrote:
> > It seems a shame to grow LambdaDefinitionData by a pointer for all users of 
> > C++ that do not use CUDA. Optimizing bitfields may be worth the time, but 
> > I'll leave it to @rjmccall or @rsmith to give guidance on whether that's 
> > worth it.
> > 
> > An alternative would be to store the device numbers in the mangling context 
> > and look them up when needed, since they are so rarely needed.
> I like the alternative way by storing all numbering into the mangle/numbering 
> context instead of AST itself. But, it needs additional numbering 
> post-processing after AST importing. Sound to me a major refactoring work 
> likely to be addressed later.
Generally, I don't think we can count on contributors to come back later and 
optimize memory usage, so it seems reasonable to ask to avoid the regression in 
the first place. Above I see the bitfield usage optimizing memory usage of the 
number of captures, and then here we spent lots of memory storing device 
mangling numbers that are only used for CUDA. I think the memory usage concern 
still stands. I don't think it's unreasonable to maintain these numbers on the 
side in a DenseMap.

@rsmith or @rjmccall, do you agree with that reasoning?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69322

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


[PATCH] D95635: [CMake] Actually require python 3.6 or greater

2021-01-28 Thread Christopher Tetreault via Phabricator via cfe-commits
ctetreau created this revision.
Herald added subscribers: teijeong, rdzhabarov, tatianashp, msifontes, jurahul, 
Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini, mgorny.
ctetreau requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, stephenneuendorffer, 
nicolasvasilache.
Herald added projects: clang, MLIR, LLVM.

Previously, CMake would find any version of Python3. However, the project
claims to require 3.6 or greater, and 3.6 features are being used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95635

Files:
  clang/CMakeLists.txt
  lld/CMakeLists.txt
  llvm/CMakeLists.txt
  mlir/CMakeLists.txt


Index: mlir/CMakeLists.txt
===
--- mlir/CMakeLists.txt
+++ mlir/CMakeLists.txt
@@ -79,7 +79,7 @@
 
 if(MLIR_BINDINGS_PYTHON_ENABLED)
   include(MLIRDetectPythonEnv)
-  find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
+  find_package(Python3 3.6 COMPONENTS Interpreter Development NumPy REQUIRED)
   message(STATUS "Found python include dirs: ${Python3_INCLUDE_DIRS}")
   message(STATUS "Found python libraries: ${Python3_LIBRARIES}")
   message(STATUS "Found numpy v${Python3_NumPy_VERSION}: 
${Python3_NumPy_INCLUDE_DIRS}")
Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -697,7 +697,7 @@
 
 include(HandleLLVMOptions)
 
-find_package(Python3 REQUIRED COMPONENTS Interpreter)
+find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter)
 
 ##
 
Index: lld/CMakeLists.txt
===
--- lld/CMakeLists.txt
+++ lld/CMakeLists.txt
@@ -57,7 +57,7 @@
   include(CheckAtomic)
 
   if(LLVM_INCLUDE_TESTS)
-find_package(Python3 REQUIRED COMPONENTS Interpreter)
+find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter)
 
 # Check prebuilt llvm/utils.
 if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -131,7 +131,7 @@
   set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY 
${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
 
   if(LLVM_INCLUDE_TESTS)
-find_package(Python3 REQUIRED COMPONENTS Interpreter)
+find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter)
 
 # Check prebuilt llvm/utils.
 if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}


Index: mlir/CMakeLists.txt
===
--- mlir/CMakeLists.txt
+++ mlir/CMakeLists.txt
@@ -79,7 +79,7 @@
 
 if(MLIR_BINDINGS_PYTHON_ENABLED)
   include(MLIRDetectPythonEnv)
-  find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
+  find_package(Python3 3.6 COMPONENTS Interpreter Development NumPy REQUIRED)
   message(STATUS "Found python include dirs: ${Python3_INCLUDE_DIRS}")
   message(STATUS "Found python libraries: ${Python3_LIBRARIES}")
   message(STATUS "Found numpy v${Python3_NumPy_VERSION}: ${Python3_NumPy_INCLUDE_DIRS}")
Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -697,7 +697,7 @@
 
 include(HandleLLVMOptions)
 
-find_package(Python3 REQUIRED COMPONENTS Interpreter)
+find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter)
 
 ##
 
Index: lld/CMakeLists.txt
===
--- lld/CMakeLists.txt
+++ lld/CMakeLists.txt
@@ -57,7 +57,7 @@
   include(CheckAtomic)
 
   if(LLVM_INCLUDE_TESTS)
-find_package(Python3 REQUIRED COMPONENTS Interpreter)
+find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter)
 
 # Check prebuilt llvm/utils.
 if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -131,7 +131,7 @@
   set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
 
   if(LLVM_INCLUDE_TESTS)
-find_package(Python3 REQUIRED COMPONENTS Interpreter)
+find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter)
 
 # Check prebuilt llvm/utils.
 if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4b68b64 - [WebAssembly] Prototype i8x16 to i32x4 widening instructions

2021-01-28 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2021-01-28T10:59:32-08:00
New Revision: 4b68b64dcc5bcd6f29779b820791611c60438385

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

LOG: [WebAssembly] Prototype i8x16 to i32x4 widening instructions

As proposed in https://github.com/WebAssembly/simd/pull/395 and matching the
opcodes used in V8:
https://chromium-review.googlesource.com/c/v8/v8/+/2617385/4/src/wasm/wasm-opcodes.h

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-wasm.c
llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
llvm/test/MC/WebAssembly/simd-encodings.s

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index bb7d6d379e58..84f346bcb928 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -206,6 +206,9 @@ TARGET_BUILTIN(__builtin_wasm_widen_high_s_i32x4_i64x2, 
"V2LLiV4i", "nc", "simd1
 TARGET_BUILTIN(__builtin_wasm_widen_low_u_i32x4_i64x2, "V2LLUiV4Ui", "nc", 
"simd128")
 TARGET_BUILTIN(__builtin_wasm_widen_high_u_i32x4_i64x2, "V2LLUiV4Ui", "nc", 
"simd128")
 
+TARGET_BUILTIN(__builtin_wasm_widen_s_i8x16_i32x4, "V4iV16ScIi", "nc", 
"simd128")
+TARGET_BUILTIN(__builtin_wasm_widen_u_i8x16_i32x4, "V4UiV16UcIi", "nc", 
"simd128")
+
 TARGET_BUILTIN(__builtin_wasm_convert_low_s_i32x4_f64x2, "V2dV4i", "nc", 
"simd128")
 TARGET_BUILTIN(__builtin_wasm_convert_low_u_i32x4_f64x2, "V2dV4Ui", "nc", 
"simd128")
 TARGET_BUILTIN(__builtin_wasm_trunc_saturate_zero_s_f64x2_i32x4, "V4iV2d", 
"nc", "simd128")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 113541bd5024..973a20f2f58c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17220,6 +17220,24 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 Function *Callee = CGM.getIntrinsic(IntNo);
 return Builder.CreateCall(Callee, Vec);
   }
+  case WebAssembly::BI__builtin_wasm_widen_s_i8x16_i32x4:
+  case WebAssembly::BI__builtin_wasm_widen_u_i8x16_i32x4: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+llvm::APSInt SubVecConst =
+*E->getArg(1)->getIntegerConstantExpr(getContext());
+Value *SubVec = llvm::ConstantInt::get(getLLVMContext(), SubVecConst);
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_widen_s_i8x16_i32x4:
+  IntNo = Intrinsic::wasm_widen_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_widen_u_i8x16_i32x4:
+  IntNo = Intrinsic::wasm_widen_unsigned;
+  break;
+}
+Function *Callee = CGM.getIntrinsic(IntNo);
+return Builder.CreateCall(Callee, {Vec, SubVec});
+  }
   case WebAssembly::BI__builtin_wasm_convert_low_s_i32x4_f64x2:
   case WebAssembly::BI__builtin_wasm_convert_low_u_i32x4_f64x2: {
 Value *Vec = EmitScalarExpr(E->getArg(0));

diff  --git a/clang/test/CodeGen/builtins-wasm.c 
b/clang/test/CodeGen/builtins-wasm.c
index 61fc76cd1873..771764c85d6b 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -976,6 +976,18 @@ u64x2 widen_high_u_i32x4_i64x2(u32x4 x) {
   // WEBASSEMBLY: ret
 }
 
+i32x4 widen_s_i8x16_i32x4(i8x16 x) {
+  return __builtin_wasm_widen_s_i8x16_i32x4(x, 3);
+  // WEBASSEMBLY: call <4 x i32> @llvm.wasm.widen.signed(<16 x i8> %x, i32 3)
+  // WEBASSEMBLY: ret
+}
+
+u32x4 widen_u_i8x16_i32x4(u8x16 x) {
+  return __builtin_wasm_widen_u_i8x16_i32x4(x, 3);
+  // WEBASSEMBLY: call <4 x i32> @llvm.wasm.widen.unsigned(<16 x i8> %x, i32 3)
+  // WEBASSEMBLY: ret
+}
+
 f64x2 convert_low_s_i32x4_f64x2(i32x4 x) {
   return __builtin_wasm_convert_low_s_i32x4_f64x2(x);
   // WEBASSEMBLY: call <2 x double> @llvm.wasm.convert.low.signed(<4 x i32> %x)

diff  --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td 
b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
index d306d0ccb90d..323b9a770c05 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -348,6 +348,14 @@ def int_wasm_promote_low :
   Intrinsic<[llvm_v2f64_ty], [llvm_v4f32_ty],
 [IntrNoMem, IntrSpeculatable]>;
 
+// TODO: Remove these if possible if they are merged to the spec.
+def int_wasm_widen_signed :
+  Intrinsic<[llvm_v4i32_ty], [llvm_v16i8_ty, llvm_i32_ty],
+[IntrNoMem, IntrSpeculatable, ImmArg>]>;
+def int_wasm_widen_unsigned :
+  Intrinsic<[llvm_v4i32_ty], [llvm_v16i8_ty, llvm_i32_ty],
+[IntrNoMem, IntrSpeculatable, ImmArg>]>;
+
 

[PATCH] D95557: [WebAssembly] Prototype i8x16 to i32x4 widening instructions

2021-01-28 Thread Thomas Lively 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 rG4b68b64dcc5b: [WebAssembly] Prototype i8x16 to i32x4 
widening instructions (authored by tlively).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95557

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
  llvm/test/MC/WebAssembly/simd-encodings.s

Index: llvm/test/MC/WebAssembly/simd-encodings.s
===
--- llvm/test/MC/WebAssembly/simd-encodings.s
+++ llvm/test/MC/WebAssembly/simd-encodings.s
@@ -760,4 +760,10 @@
 # CHECK: f64x2.promote_low_f32x4 # encoding: [0xfd,0x69]
 f64x2.promote_low_f32x4
 
+# CHECK: i32x4.widen_i8x16_s 3 # encoding: [0xfd,0x67,0x03]
+i32x4.widen_i8x16_s 3
+
+# CHECK: i32x4.widen_i8x16_u 3 # encoding: [0xfd,0x68,0x03]
+i32x4.widen_i8x16_u 3
+
 end_function
Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -586,6 +586,27 @@
   ret <4 x i32> %v
 }
 
+
+; CHECK-LABEL: widen_signed_v4i32:
+; SIMD128-NEXT: .functype widen_signed_v4i32 (v128) -> (v128){{$}}
+; SIMD128-NEXT: i32x4.widen_i8x16_s $push[[R:[0-9]+]]=, $0, 1{{$}}
+; SIMD128-NEXT: return $pop[[R]]{{$}}
+declare <4 x i32> @llvm.wasm.widen.signed(<16 x i8>, i32 immarg)
+define <4 x i32> @widen_signed_v4i32(<16 x i8> %x) {
+  %v = call <4 x i32> @llvm.wasm.widen.signed(<16 x i8> %x, i32 1)
+  ret <4 x i32> %v
+}
+
+; CHECK-LABEL: widen_unsigned_v4i32:
+; SIMD128-NEXT: .functype widen_unsigned_v4i32 (v128) -> (v128){{$}}
+; SIMD128-NEXT: i32x4.widen_i8x16_u $push[[R:[0-9]+]]=, $0, 1{{$}}
+; SIMD128-NEXT: return $pop[[R]]{{$}}
+declare <4 x i32> @llvm.wasm.widen.unsigned(<16 x i8>, i32 immarg)
+define <4 x i32> @widen_unsigned_v4i32(<16 x i8> %x) {
+  %v = call <4 x i32> @llvm.wasm.widen.unsigned(<16 x i8> %x, i32 1)
+  ret <4 x i32> %v
+}
+
 ; ==
 ; 2 x i64
 ; ==
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
===
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
@@ -1256,7 +1256,6 @@
 defm "" : SIMDConvert;
 
-
 // Prototype f64x2 conversions
 defm "" : SIMDConvert;
@@ -1271,6 +1270,25 @@
 defm "" : SIMDConvert;
 
+// Prototype i8x16 to i32x4 widening
+defm WIDEN_I8x16_TO_I32x4_S :
+  SIMD_I<(outs V128:$dst), (ins V128:$vec, vec_i8imm_op:$idx),
+ (outs), (ins vec_i8imm_op:$idx),
+ [(set (I32x4.vt V128:$dst),
+(I32x4.vt (int_wasm_widen_signed
+  (I8x16.vt V128:$vec), (i32 timm:$idx],
+ "i32x4.widen_i8x16_s\t$dst, $vec, $idx",
+ "i32x4.widen_i8x16_s\t$idx", 0x67>;
+defm WIDEN_I8x16_TO_I32x4_U :
+  SIMD_I<(outs V128:$dst), (ins V128:$vec, vec_i8imm_op:$idx),
+ (outs), (ins vec_i8imm_op:$idx),
+ [(set (I32x4.vt V128:$dst),
+(I32x4.vt (int_wasm_widen_unsigned
+  (I8x16.vt V128:$vec), (i32 timm:$idx],
+ "i32x4.widen_i8x16_u\t$dst, $vec, $idx",
+ "i32x4.widen_i8x16_u\t$idx", 0x68>;
+
+
 //===--===//
 // Quasi-Fused Multiply- Add and Subtract (QFMA/QFMS)
 //===--===//
Index: llvm/include/llvm/IR/IntrinsicsWebAssembly.td
===
--- llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -348,6 +348,14 @@
   Intrinsic<[llvm_v2f64_ty], [llvm_v4f32_ty],
 [IntrNoMem, IntrSpeculatable]>;
 
+// TODO: Remove these if possible if they are merged to the spec.
+def int_wasm_widen_signed :
+  Intrinsic<[llvm_v4i32_ty], [llvm_v16i8_ty, llvm_i32_ty],
+[IntrNoMem, IntrSpeculatable, ImmArg>]>;
+def int_wasm_widen_unsigned :
+  Intrinsic<[llvm_v4i32_ty], [llvm_v16i8_ty, llvm_i32_ty],
+[IntrNoMem, IntrSpeculatable, ImmArg>]>;
+
 //===--===//
 // Thread-local storage intrinsics
 //===--===//
Index: clang/test/CodeGen/builtins-wasm.c
===
--- 

[PATCH] D95557: [WebAssembly] Prototype i8x16 to i32x4 widening instructions

2021-01-28 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In D95557#2527731 , @aheejin wrote:

> This does not yet have i64x2 version of the instructions in 
> https://github.com/WebAssembly/simd/pull/395 yet, right?

Yes, that's intentional. These are the only versions implemented in V8 as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95557

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


[PATCH] D95557: [WebAssembly] Prototype i8x16 to i32x4 widening instructions

2021-01-28 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td:1279
+(I32x4.vt (int_wasm_widen_signed
+  (I8x16.vt V128:$vec), (i32 timm:$idx],
+ "i32x4.widen_i8x16_s\t$dst, $vec, $idx",

aheejin wrote:
> I think this is the first time we use `timm` in this file... Haven't we used 
> `LaneIdxN` for these? The same for `WIDEN_I8x16_TO_I32x4_U`.
Yes, this is the first use of `timm`. I needed to use `timm` instead of `imm` 
(or a `LaneIdxN`, which is just a restricted `imm`) because `immarg` arguments 
are apparently lowered to TargetConstant nodes rather than Constant nodes. This 
is also the first time I've used an `immarg` arument in one of the intrinsics, 
but I should definitely use them for many other intrinsics as well, and 
probably change `LaneIdxN` to be based on `timm` rather than `imm`. Since these 
are just prototype instructions, I am ok with them working differently from 
other instructions for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95557

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


[PATCH] D95634: [PowerPC][Power10] Fix XXSPLI32DX not correctly exploiting specific cases

2021-01-28 Thread Lei Huang via Phabricator via cfe-commits
lei accepted this revision.
lei added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95634

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


[PATCH] D95634: [PowerPC][Power10] Fix XXSPLI32DX not correctly exploiting specific cases

2021-01-28 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.
This revision is now accepted and ready to land.

LGTM as long as the nits are addressed on the commit.




Comment at: llvm/lib/Target/PowerPC/PPCISelLowering.cpp:8611
   Subtarget.hasPrefixInstrs()) {
-if (convertToNonDenormSingle(APSplatBits) &&
-(Op->getValueType(0) == MVT::v2f64)) {
+if ((Op->getValueType(0) == MVT::v2f64) &&
+convertToNonDenormSingle(APSplatBits)) {

```
// Check the type first to short-circuit so we don't modify APSplatBits if
// this block isn't executed.
```



Comment at: llvm/lib/Target/PowerPC/PPCISelLowering.cpp:8617
   return DAG.getBitcast(Op.getValueType(), SplatNode);
 } else if (APSplatBits.getBitWidth() == 64) {
   // We may lose precision, so we have to use XXSPLTI32DX.

We can get rid of this now that the problem is fixed (i.e. this can go back to 
just being an `else`).



Comment at: llvm/test/CodeGen/PowerPC/p10-splatImm32.ll:104
 
 define dso_local <16 x i8> @test_xxsplti32dx_10() {
 ; CHECK-LABEL: test_xxsplti32dx_10:

Get rid of this test case now. It is redundant.



Comment at: llvm/test/CodeGen/PowerPC/p10-splatImm32.ll:114
 
 ; FIXME: It appears that there is something wrong with the computation
 ;of the 64-bit constant to splat so we cannot emit xxsplti32dx for

Get rid of this comment now, the FIXME has been addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95634

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


[PATCH] D94500: Rework Whitesmiths mode to use line-level values in UnwrappedLineParser

2021-01-28 Thread Tim Wojtulewicz via Phabricator via cfe-commits
timwoj marked 8 inline comments as done.
timwoj added a comment.

No problem, sorry it took a bit of back-and-forth there. Is there any way this 
can sneak into 12.0?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94500

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


[PATCH] D95634: [PowerPC][Power10] Fix XXSPLI32DX not correctly exploiting specific cases

2021-01-28 Thread Albion Fung via Phabricator via cfe-commits
Conanap created this revision.
Conanap added reviewers: nemanjai, saghir, PowerPC.
Conanap added projects: LLVM, clang, PowerPC.
Herald added a subscriber: kbarton.
Conanap requested review of this revision.

Some cases may be transformed into 32 bit splats before hitting the boolean 
statement, which may cause incorrect behaviour and provide XXSPLTI32DX with the 
incorrect values of splat. The condition was reversed so that the shortcut 
prevents this problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95634

Files:
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/p10-splatImm32.ll


Index: llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
===
--- llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
+++ llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
@@ -117,7 +117,8 @@
 define dso_local <16 x i8> @constSplatBug() {
 ; CHECK-LABEL: constSplatBug:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:plxv vs34, .LCPI10_0@PCREL(0), 1
+; CHECK-NEXT:xxlxor vs34, vs34, vs34
+; CHECK-NEXT:xxsplti32dx vs34, 0, 1191182336
 ; CHECK-NEXT:blr
 entry:
   ret <16 x i8> 
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -8604,11 +8604,12 @@
 
   // If it is a splat of a double, check if we can shrink it to a 32 bit
   // non-denormal float which when converted back to double gives us the same
-  // double. This is to exploit the XXSPLTIDP instruction.+  // If we lose 
precision, we use XXSPLTI32DX.
+  // double. This is to exploit the XXSPLTIDP instruction.
+  // If we lose precision, we use XXSPLTI32DX.
   if (BVNIsConstantSplat && (SplatBitSize == 64) &&
   Subtarget.hasPrefixInstrs()) {
-if (convertToNonDenormSingle(APSplatBits) &&
-(Op->getValueType(0) == MVT::v2f64)) {
+if ((Op->getValueType(0) == MVT::v2f64) &&
+convertToNonDenormSingle(APSplatBits)) {
   SDValue SplatNode = DAG.getNode(
   PPCISD::XXSPLTI_SP_TO_DP, dl, MVT::v2f64,
   DAG.getTargetConstant(APSplatBits.getZExtValue(), dl, MVT::i32));


Index: llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
===
--- llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
+++ llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
@@ -117,7 +117,8 @@
 define dso_local <16 x i8> @constSplatBug() {
 ; CHECK-LABEL: constSplatBug:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:plxv vs34, .LCPI10_0@PCREL(0), 1
+; CHECK-NEXT:xxlxor vs34, vs34, vs34
+; CHECK-NEXT:xxsplti32dx vs34, 0, 1191182336
 ; CHECK-NEXT:blr
 entry:
   ret <16 x i8> 
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -8604,11 +8604,12 @@
 
   // If it is a splat of a double, check if we can shrink it to a 32 bit
   // non-denormal float which when converted back to double gives us the same
-  // double. This is to exploit the XXSPLTIDP instruction.+  // If we lose precision, we use XXSPLTI32DX.
+  // double. This is to exploit the XXSPLTIDP instruction.
+  // If we lose precision, we use XXSPLTI32DX.
   if (BVNIsConstantSplat && (SplatBitSize == 64) &&
   Subtarget.hasPrefixInstrs()) {
-if (convertToNonDenormSingle(APSplatBits) &&
-(Op->getValueType(0) == MVT::v2f64)) {
+if ((Op->getValueType(0) == MVT::v2f64) &&
+convertToNonDenormSingle(APSplatBits)) {
   SDValue SplatNode = DAG.getNode(
   PPCISD::XXSPLTI_SP_TO_DP, dl, MVT::v2f64,
   DAG.getTargetConstant(APSplatBits.getZExtValue(), dl, MVT::i32));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >