[PATCH] D83548: [clangd] Fix tests build for GCC5

2020-07-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG07c4c7e7959b: [clangd] Fix tests build for GCC5 (authored by 
ArcsinX, committed by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83548

Files:
  clang-tools-extra/clangd/unittests/PreambleTests.cpp


Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -230,8 +230,8 @@
 TEST(PreamblePatchTest, Define) {
   // BAR should be defined while parsing the AST.
   struct {
-llvm::StringLiteral Contents;
-llvm::StringLiteral ExpectedPatch;
+const char *const Contents;
+const char *const ExpectedPatch;
   } Cases[] = {
   {
   R"cpp(
@@ -270,7 +270,7 @@
 SCOPED_TRACE(Case.Contents);
 Annotations Modified(Case.Contents);
 EXPECT_THAT(getPreamblePatch("", Modified.code()),
-MatchesRegex(Case.ExpectedPatch.str()));
+MatchesRegex(Case.ExpectedPatch));
 
 auto AST = createPatchedAST("", Modified.code());
 ASSERT_TRUE(AST);
@@ -304,8 +304,8 @@
 
 TEST(PreamblePatchTest, LocateMacroAtWorks) {
   struct {
-llvm::StringLiteral Baseline;
-llvm::StringLiteral Modified;
+const char *const Baseline;
+const char *const Modified;
   } Cases[] = {
   // Addition of new directive
   {
@@ -417,8 +417,8 @@
 
 TEST(PreamblePatchTest, RefsToMacros) {
   struct {
-llvm::StringLiteral Baseline;
-llvm::StringLiteral Modified;
+const char *const Baseline;
+const char *const Modified;
   } Cases[] = {
   // Newly added
   {
@@ -491,8 +491,8 @@
 
 TEST(PreamblePatch, ModifiedBounds) {
   struct {
-llvm::StringLiteral Baseline;
-llvm::StringLiteral Modified;
+const char *const Baseline;
+const char *const Modified;
   } Cases[] = {
   // Size increased
   {


Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -230,8 +230,8 @@
 TEST(PreamblePatchTest, Define) {
   // BAR should be defined while parsing the AST.
   struct {
-llvm::StringLiteral Contents;
-llvm::StringLiteral ExpectedPatch;
+const char *const Contents;
+const char *const ExpectedPatch;
   } Cases[] = {
   {
   R"cpp(
@@ -270,7 +270,7 @@
 SCOPED_TRACE(Case.Contents);
 Annotations Modified(Case.Contents);
 EXPECT_THAT(getPreamblePatch("", Modified.code()),
-MatchesRegex(Case.ExpectedPatch.str()));
+MatchesRegex(Case.ExpectedPatch));
 
 auto AST = createPatchedAST("", Modified.code());
 ASSERT_TRUE(AST);
@@ -304,8 +304,8 @@
 
 TEST(PreamblePatchTest, LocateMacroAtWorks) {
   struct {
-llvm::StringLiteral Baseline;
-llvm::StringLiteral Modified;
+const char *const Baseline;
+const char *const Modified;
   } Cases[] = {
   // Addition of new directive
   {
@@ -417,8 +417,8 @@
 
 TEST(PreamblePatchTest, RefsToMacros) {
   struct {
-llvm::StringLiteral Baseline;
-llvm::StringLiteral Modified;
+const char *const Baseline;
+const char *const Modified;
   } Cases[] = {
   // Newly added
   {
@@ -491,8 +491,8 @@
 
 TEST(PreamblePatch, ModifiedBounds) {
   struct {
-llvm::StringLiteral Baseline;
-llvm::StringLiteral Modified;
+const char *const Baseline;
+const char *const Modified;
   } Cases[] = {
   // Size increased
   {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83657: [clangd] Add metrics for recovery-expr type propagation.

2020-07-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83657

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -453,6 +453,8 @@
   auto T = makeSelectionTree(Code, AST);
   EXPECT_THAT(Tracer.takeMetric("selection_recovery"),
   testing::ElementsAreArray({1}));
+  EXPECT_THAT(Tracer.takeMetric("selection_recovery_type"),
+  testing::ElementsAreArray({1}));
 }
 
 // FIXME: Doesn't select the binary operator node in
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -41,10 +41,13 @@
 void recordMetrics(const SelectionTree ) {
   static constexpr trace::Metric SelectionUsedRecovery(
   "selection_recovery", trace::Metric::Distribution);
+  static constexpr trace::Metric RecoveryType("selection_recovery_type",
+  trace::Metric::Distribution);
   const auto *Common = S.commonAncestor();
   for (const auto *N = Common; N; N = N->Parent) {
-if (N->ASTNode.get()) {
+if (const auto *RE = N->ASTNode.get()) {
   SelectionUsedRecovery.record(1); // used recovery ast.
+  RecoveryType.record(RE->isTypeDependent() ? 0 : 1);
   return;
 }
   }


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -453,6 +453,8 @@
   auto T = makeSelectionTree(Code, AST);
   EXPECT_THAT(Tracer.takeMetric("selection_recovery"),
   testing::ElementsAreArray({1}));
+  EXPECT_THAT(Tracer.takeMetric("selection_recovery_type"),
+  testing::ElementsAreArray({1}));
 }
 
 // FIXME: Doesn't select the binary operator node in
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -41,10 +41,13 @@
 void recordMetrics(const SelectionTree ) {
   static constexpr trace::Metric SelectionUsedRecovery(
   "selection_recovery", trace::Metric::Distribution);
+  static constexpr trace::Metric RecoveryType("selection_recovery_type",
+  trace::Metric::Distribution);
   const auto *Common = S.commonAncestor();
   for (const auto *N = Common; N; N = N->Parent) {
-if (N->ASTNode.get()) {
+if (const auto *RE = N->ASTNode.get()) {
   SelectionUsedRecovery.record(1); // used recovery ast.
+  RecoveryType.record(RE->isTypeDependent() ? 0 : 1);
   return;
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83621: [clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a subscriber: klimek.
sammccall added a comment.

Wow, yeah, this seems pretty bad! I'm not very familiar with this code. I'm 
curious, for "it tooks more than 1 second" - what OS is this on?

My guess is that way back when, the performance of looking up a CDB entry that 
didn't exist wasn't a big deal, or windows support wasn't a big thing, or this 
was just an oversight.

My reading of the code is that any TrieNode is a set of candidates that match a 
suffix of the path equally well, and we're trying to walk down the tree making 
the suffix longer and the candidate set more restrictive.
When we reach the node whether the path stops matching, we scan all the 
candidates to see if they're symlink-equivalent.
This is expensive if the set is too large, which is trivially the case if the 
filename is unique in the project (so we never get past the root node, and stat 
every file in the project).

I think it would be slightly cleaner to fix this in the trie itself, either:

- don't scan for equivalences if the set of candidates exceeds some size 
threshold (10 or so)
- don't scan for equivalences if the node we'd scan under is the root

@klimek In case you have context or thoughts here. Always fun to find a 9 year 
old bug :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83621



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


[PATCH] D83621: [clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json

2020-07-13 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added a comment.

In D83621#2146706 , @sammccall wrote:

> Wow, yeah, this seems pretty bad! I'm not very familiar with this code. I'm 
> curious, for "it tooks more than 1 second" - what OS is this on?


Windows.
I faced this problem on a huge project and it takes 7 seconds for 
`MatchTrie.findEquivalent()` to return.

> My guess is that way back when, the performance of looking up a CDB entry 
> that didn't exist wasn't a big deal, or windows support wasn't a big thing, 
> or this was just an oversight.
> 
> I think it would be slightly cleaner to fix this in the trie itself, either:

Firstly, I wanted to fix this problem in `FileMatchTrie`, but for caching 
solution we need to update cache at every `instert()` call, but for caching 
solution inside `JSONCompilationDatabase` we can avoid this, because all 
inserts already done at `JSONCompilationDatabase::parse()`.

> - don't scan for equivalences if the set of candidates exceeds some size 
> threshold (10 or so)
> - don't scan for equivalences if the node we'd scan under is the root

After such fixes `JSONCompilationDatabase::getCompileCommands()` will return 
other results than before in some cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83621



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


[PATCH] D82739: [clangd] Improve heuristic resolution of dependent types in TargetFinder

2020-07-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:76
   if (const auto *ICNT = T->getAs()) {
 T = ICNT->getInjectedSpecializationType().getTypePtrOrNull();
   }

an off-topic comment: I don't have a reproduce case, but I think we might get a 
nullptr, and get a null-access crash below,



Comment at: clang-tools-extra/clangd/FindTarget.cpp:101
+
 // Given a dependent type and a member name, heuristically resolve the
 // name to one or more declarations.

nit: the "a dependent type" doesn't seem to be correct, the type is not always 
dependent, I'd use `a tag-decl type`.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:119
 std::vector getMembersReferencedViaDependentName(
-const Type *T,
+Expr *E, const Type *T,
 llvm::function_ref NameFactory,

this function was pretty clear prior to the patch -- given a tag-decl type, and 
a member name, it tries to perform a lookup in the tag-decl, and returns the 
result.

Now we add an extra `E` which seems making it tangled, there is only 
one caller passing the actual `E`, so I think we should keep this helper 
function as-is, and handle the builtin-dependent type in the caller.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:214
   }
+  if (const auto *CE = dyn_cast(E)) {
+const auto *CalleeType = resolveDependentExprToType(CE->getCallee());

btw, could you try the case below? it doesn't seem to work.

```
struct Bar {
  int ;
};
template  struct Foo {
  Bar func(int);
  void test() {
func(1).aa^aa;
  }
};
```



Comment at: clang-tools-extra/clangd/FindTarget.cpp:215
+  if (const auto *CE = dyn_cast(E)) {
+const auto *CalleeType = resolveDependentExprToType(CE->getCallee());
+if (const auto *FnTypePtr = CalleeType->getAs()) {

we need to check whether the type is null, otherwise we get a crash below.

see:

```
   template
   struct Foo {
 int func(int);
 void test() {
   func().a;
 }
   };

```





Comment at: clang-tools-extra/clangd/FindTarget.cpp:216
+const auto *CalleeType = resolveDependentExprToType(CE->getCallee());
+if (const auto *FnTypePtr = CalleeType->getAs()) {
+  CalleeType = FnTypePtr->getPointeeType().getTypePtr();

could you add a unittest for this case?

nit: I'd remove the extra `{}` if the if body just contains a single statement. 



Comment at: clang-tools-extra/clangd/FindTarget.cpp:287
 //
 // FIXME: improve common dependent scope using name lookup in primary 
templates.
 // e.g. template int foo() { return std::vector().size(); }

this FIXME looks stale now, could you please update it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82739



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


[PATCH] D83652: Merge some of the PCH object support with modular codegen

2020-07-13 Thread Luboš Luňák via Phabricator via cfe-commits
llunak added a comment.

The patch is incomplete, isn't it? It removes DeclIsFromPCHWithObjectFile(), 
but it's still called from ASTContext::DeclMustBeEmitted(). The description 
also mentions updating of the pch-codegen test, but that's not included.

But assuming this is intended to replace the D48426 
 functionality with modular codegen, I 
mentioned already in D69778  (starting with 
'Mar 17 2020, 10:59 PM') that it's a question if this is possible. Modular 
codegen is a much bigger hammer than  D48426  
and it has also bigger possible problems: Possibly making compilation actually 
slower (even f63556d8b44b209e741833b0e6be3f8e72a1d91a mentions this), and 
possibly causing build problems because of referencing private symbols.  D48426 
 is much smaller both in gains and in problems 
(=safer).

> Do either of you know if it'd be practical to move to something more similar 
> to .pcm handling, where the pch itself is passed to the compilation, rather 
> than homed as a side effect of compiling some other source file?

Do you mean dropping compatibility with 'cl.exe /Yc'?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83652



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


[PATCH] D82657: [AST][RecoveryAST] Preserve the type by default for recovery expression.

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

As you said, we can't land this before the branch cut, and we shouldn't land 
this until we've run internal experiments to show it's not horribly crashy.




Comment at: 
clang/test/CXX/temp/temp.constr/temp.constr.order/function-templates.cpp:71
+// expected-error@-1 {{call to 'f' is ambiguous}} \
+   expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 
'void'}}
 

this is really nice :-)



Comment at: clang/test/CXX/temp/temp.decls/temp.variadic/fixed-expansion.cpp:129
+  S  = f({}, 0, 0.0); // expected-error {{no matching 
function}} \
+  expected-error {{non-const 
lvalue reference to type 'S' cannot bind to a value of 
unrelated type 'int'}}
 }

hokein wrote:
> the secondary diagnostic is technically correct, but I don't quite like it, 
> it is confusing, ok to leave it as-is? or fix that before landing this patch?
I don't think it's technically correct (the `int` fallback is an implementation 
artifact, albeit one that leaks quite often).
This example looks pretty obscure though, it'd be nice to fix it at some point 
but I don't think it's severe enough to block on the fix.

Fix ideas:
 - the instantiation of `f` should be invalid, right? Maybe we avoid 
considering return types for invalid decls when computing recovery type (or 
always give up in this case).
 - we could eventually try to replace the use of `int` for these cases
 - we could special-case `int`, and don't allow RecoveryExprs to have type 
`int`, reflecting the fact that it's used for these cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82657



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


[PATCH] D82436: [clangd] Implement textDocument/foldingRange

2020-07-13 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 277359.
kbobyrev added a comment.

Updated a couple of comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82436

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang-tools-extra/clangd/SemanticSelection.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -17,15 +17,19 @@
 #include "TestTU.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+
 namespace clang {
 namespace clangd {
 namespace {
+
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
+using ::testing::UnorderedElementsAreArray;
 
 // front() is SR.range, back() is outermost range.
 std::vector gatherRanges(const SelectionRange ) {
@@ -35,6 +39,22 @@
   return Ranges;
 }
 
+std::vector
+gatherFoldingRanges(llvm::ArrayRef FoldingRanges) {
+  std::vector Ranges;
+  Range NextRange;
+  for (const auto  : FoldingRanges) {
+NextRange.start.line = R.startLine;
+EXPECT_TRUE(R.startCharacter);
+NextRange.start.character = *R.startCharacter;
+NextRange.end.line = R.endLine;
+EXPECT_TRUE(R.endCharacter);
+NextRange.end.character = *R.endCharacter;
+Ranges.push_back(NextRange);
+  }
+  return Ranges;
+}
+
 TEST(SemanticSelection, All) {
   const char *Tests[] = {
   R"cpp( // Single statement in a function body.
@@ -118,16 +138,16 @@
   )cpp",
   R"cpp( // Inside struct.
 struct A { static int a(); };
-[[struct B { 
+[[struct B {
   [[static int b() [[{
 [[return 1^1]] + 2;
   }
 }]];
   )cpp",
   // Namespaces.
-  R"cpp( 
-[[namespace nsa { 
-  [[namespace nsb { 
+  R"cpp(
+[[namespace nsa {
+  [[namespace nsb {
 static int ccc();
 [[void func() [[{
   // int x = nsa::nsb::ccc();
@@ -181,6 +201,41 @@
   EXPECT_THAT(gatherRanges(Ranges->back()),
   ElementsAre(SourceAnnotations.range("empty")));
 }
+
+TEST(SemanticSelection, FoldingRanges) {
+  const char *Tests[] = {
+  R"cpp(
+int [[global_variable]];
+
+[[void func() {
+  int v = 100;
+}]]
+  )cpp",
+  R"cpp(
+[[class Foo {
+public:
+  [[Foo() {
+int X = 1;
+  }]]
+
+private:
+  [[int getBar() {
+return 42;
+  }]]
+
+  [[void getFooBar() { }]]
+}]];
+  )cpp",
+  };
+  for (const char *Test : Tests) {
+auto T = Annotations(Test);
+auto AST = TestTU::withCode(T.code()).build();
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(AST))),
+UnorderedElementsAreArray(T.ranges()))
+<< Test;
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -8,6 +8,7 @@
 #include "Annotations.h"
 #include "ClangdServer.h"
 #include "FindSymbols.h"
+#include "Protocol.h"
 #include "SyncAPI.h"
 #include "TestFS.h"
 #include "gmock/gmock.h"
@@ -33,7 +34,7 @@
 }
 MATCHER_P(WithName, N, "") { return arg.name == N; }
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
-MATCHER_P(SymRange, Range, "") { return arg.location.range == Range; }
+MATCHER_P(SymRange, Range, "") { return arg.range == Range; }
 
 // GMock helpers for matching DocumentSymbol.
 MATCHER_P(SymNameRange, Range, "") { return arg.selectionRange == Range; }
@@ -746,5 +747,71 @@
WithName("Foo_type::method3")));
 }
 
+TEST_F(DocumentSymbolsTest, Ranges) {
+  std::string FilePath = testPath("foo.cpp");
+  Annotations Main(R"(
+  $foo[[int foo(bool Argument) {
+return 42;
+  }]]
+
+  char $variable[[GLOBAL_VARIABLE]];
+
+  $ns[[namespace ns {
+  $bar[[class Bar {
+  public:
+$ctor[[Bar() {}]]
+$dtor[[~Bar()]];
+
+  private:
+

Re: [PATCH] D82085: [TRE] allow TRE for non-capturing calls.

2020-07-13 Thread Alexey Lapshin via cfe-commits


Hi David,
 
Thank you for the information. I would revert that commit and work on the fix.
 
Thank you, Alexey. 
>Воскресенье, 12 июля 2020, 12:44 +03:00 от David Zarzycki via Phabricator 
>:
> 
>davezarzycki added a comment.
>
>Hello. I have an auto-bisecting multi-stage bot that is failing on two after 
>this change. Can we please revert this or commit a quick fix?
>
>  FAIL: Clang :: CXX/class/class.compare/class.spaceship/p1.cpp (6232 of 64222)
>   TEST 'Clang :: 
>CXX/class/class.compare/class.spaceship/p1.cpp' FAILED 
>  Script:
>  --
>  : 'RUN: at line 1'; /tmp/_update_lc/t/bin/clang -cc1 -internal-isystem 
>/tmp/_update_lc/t/lib/clang/11.0.0/include -nostdsysteminc -std=c++2a -verify 
>/home/dave/s/lp/clang/test/CXX/class/class.compare/class.spaceship/p1.cpp 
>-fcxx-exceptions
>  --
>  Exit Code: 134
>  
>  Command Output (stderr):
>  --
>  clang: /home/dave/s/lp/clang/lib/Basic/SourceManager.cpp:917: clang::FileID 
>clang::SourceManager::getFileIDLoaded(unsigned int) const: Assertion `0 && 
>"Invalid SLocOffset or bad function choice"' failed.
>  PLEASE submit a bug report to  https://bugs.llvm.org/ and include the crash 
>backtrace, preprocessed source, and associated run script.
>  Stack dump:
>  0. Program arguments: /tmp/_update_lc/t/bin/clang -cc1 -internal-isystem 
>/tmp/_update_lc/t/lib/clang/11.0.0/include -nostdsysteminc -std=c++2a -verify 
>/home/dave/s/lp/clang/test/CXX/class/class.compare/class.spaceship/p1.cpp 
>-fcxx-exceptions
>  1. 
>/home/dave/s/lp/clang/test/CXX/class/class.compare/class.spaceship/p1.cpp:127:38:
> current parser token ','
>  2. 
>/home/dave/s/lp/clang/test/CXX/class/class.compare/class.spaceship/p1.cpp:39:1:
> parsing namespace 'Deletedness'
>  3. 
>/home/dave/s/lp/clang/test/CXX/class/class.compare/class.spaceship/p1.cpp:123:12:
> parsing function body 'Deletedness::g'
>  4. 
>/home/dave/s/lp/clang/test/CXX/class/class.compare/class.spaceship/p1.cpp:123:12:
> in compound statement ('{}')
>   #0 0x0359273f llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
>(/tmp/_update_lc/t/bin/clang+0x359273f)
>   #1 0x03590912 llvm::sys::RunSignalHandlers() 
>(/tmp/_update_lc/t/bin/clang+0x3590912)
>   #2 0x03592bb5 SignalHandler(int) 
>(/tmp/_update_lc/t/bin/clang+0x3592bb5)
>   #3 0x77fa6a90 __restore_rt (/lib64/libpthread.so.0+0x14a90)
>   #4 0x77b3da25 raise (/lib64/libc.so.6+0x3ca25)
>   #5 0x77b26895 abort (/lib64/libc.so.6+0x25895)
>   #6 0x77b26769 _nl_load_domain.cold (/lib64/libc.so.6+0x25769)
>   #7 0x77b35e86 (/lib64/libc.so.6+0x34e86)
>   #8 0x0375636c clang::SourceManager::getFileIDLoaded(unsigned int) 
>const (/tmp/_update_lc/t/bin/clang+0x375636c)
>   #9 0x03ee0bbb 
>clang::VerifyDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level,
> clang::Diagnostic const&) (/tmp/_update_lc/t/bin/clang+0x3ee0bbb)
>  #10 0x037501ab 
>clang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&) const 
>(/tmp/_update_lc/t/bin/clang+0x37501ab)
>  #11 0x03749fca clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) 
>(/tmp/_update_lc/t/bin/clang+0x3749fca)
>  #12 0x04df0c60 clang::Sema::EmitCurrentDiagnostic(unsigned int) 
>(/tmp/_update_lc/t/bin/clang+0x4df0c60)
>  #13 0x05092783 (anonymous 
>namespace)::DefaultedComparisonAnalyzer::visitBinaryOperator(clang::OverloadedOperatorKind,
> llvm::ArrayRef, (anonymous 
>namespace)::DefaultedComparisonSubobject, clang::OverloadCandidateSet*) 
>(/tmp/_update_lc/t/bin/clang+0x5092783)
>  #14 0x05091dba (anonymous 
>namespace)::DefaultedComparisonAnalyzer::visitExpandedSubobject(clang::QualType,
> (anonymous namespace)::DefaultedComparisonSubobject) 
>(/tmp/_update_lc/t/bin/clang+0x5091dba)
>  #15 0x05091b86 (anonymous 
>namespace)::DefaultedComparisonVisitor<(anonymous 
>namespace)::DefaultedComparisonAnalyzer, (anonymous 
>namespace)::DefaultedComparisonInfo, (anonymous 
>namespace)::DefaultedComparisonInfo, (anonymous 
>namespace)::DefaultedComparisonSubobject>::visitSubobjects((anonymous 
>namespace)::DefaultedComparisonInfo&, clang::CXXRecordDecl*, 
>clang::Qualifiers) (/tmp/_update_lc/t/bin/clang+0x5091b86)
>  #16 0x05058c8c (anonymous 
>namespace)::DefaultedComparisonAnalyzer::visit() 
>(/tmp/_update_lc/t/bin/clang+0x5058c8c)
>  #17 0x0505ab22 
>clang::Sema::DiagnoseDeletedDefaultedFunction(clang::FunctionDecl*) 
>(/tmp/_update_lc/t/bin/clang+0x505ab22)
>  #18 0x053e60ed 
>clang::Sema::CreateOverloadedBinOp(clang::SourceLocation, 
>clang::BinaryOperatorKind, clang::UnresolvedSetImpl const&, clang::Expr*, 
>clang::Expr*, bool, bool, clang::FunctionDecl*) 
>(/tmp/_update_lc/t/bin/clang+0x53e60ed)
>  #19 0x0514270a BuildOverloadedBinOp(clang::Sema&, clang::Scope*, 
>clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) 
>(/tmp/_update_lc/t/bin/clang+0x514270a)
>  #20 0x050fbf49 

[PATCH] D81728: [InstCombine] Add target-specific inst combining

2020-07-13 Thread Sebastian Neubauer via Phabricator via cfe-commits
Flakebi marked an inline comment as done.
Flakebi added inline comments.



Comment at: llvm/include/llvm/Analysis/TargetTransformInfo.h:542
+  bool simplifyDemandedUseBitsIntrinsic(InstCombiner , IntrinsicInst ,
+APInt DemandedMask, KnownBits ,
+bool ,

nikic wrote:
> `const APInt `?
I tried to change it it to to `const APInt ` but the x86 
simplifyDemandedVectorEltsIntrinsic changes `DemandedMask`, so this function 
would have to copy it or take a non-const reference.
Looking more into it, `SimplifyAndSetOp` takes `DemandedElts` by value too.
An `APInt` consists of a `uint64_t` and an `unsigned`, so it should be 16 Byte 
in most cases. Only if the represented int is larger than 64 bit, it comes with 
an allocation. I guess copying should be fine.
If you think it should be a reference anyway, let me know and I’ll change it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81728



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


[PATCH] D81728: [InstCombine] Add target-specific inst combining

2020-07-13 Thread Chris Lattner via Phabricator via cfe-commits
lattner resigned from this revision.
lattner added a comment.

Please don't consider me a blocker on this patch, thank you for pushing on it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81728



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


[PATCH] D83668: [clangd] Fix DocumentSymbol ranges

2020-07-13 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 277387.
kbobyrev added a comment.

Use open half ranges for all symbol kinds, adjust variable ranges in tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83668

Files:
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -35,7 +35,7 @@
 }
 MATCHER_P(WithName, N, "") { return arg.name == N; }
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
-MATCHER_P(SymRange, Range, "") { return arg.location.range == Range; }
+MATCHER_P(SymRange, Range, "") { return arg.range == Range; }
 
 // GMock helpers for matching DocumentSymbol.
 MATCHER_P(SymNameRange, Range, "") { return arg.selectionRange == Range; }
@@ -712,6 +712,72 @@
WithName("Foo_type::method3")));
 }
 
+TEST(DocumentSymbolsTest, Ranges) {
+  TestTU TU;
+  Annotations Main(R"(
+  $foo[[int foo(bool Argument) {
+return 42;
+  }]]
+
+  $variable[[char GLOBAL_VARIABLE]];
+
+  $ns[[namespace ns {
+  $bar[[class Bar {
+  public:
+$ctor[[Bar() {}]]
+$dtor[[~Bar()]];
+
+  private:
+$field[[unsigned Baz]];
+
+$getbaz[[unsigned getBaz() { return Baz; }]]
+  }]];
+  }]] // namespace ns
+
+  $forwardclass[[class ForwardClassDecl]];
+
+  $struct[[struct StructDefinition {
+$structfield[[int *Pointer = nullptr]];
+  }]];
+  $forwardstruct[[struct StructDeclaration]];
+
+  $forwardfunc[[void forwardFunctionDecl(int Something)]];
+)");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  UnorderedElementsAre(
+  AllOf(WithName("foo"), WithKind(SymbolKind::Function),
+SymRange(Main.range("foo"))),
+  AllOf(WithName("GLOBAL_VARIABLE"), WithKind(SymbolKind::Variable),
+SymRange(Main.range("variable"))),
+  AllOf(
+  WithName("ns"), WithKind(SymbolKind::Namespace),
+  SymRange(Main.range("ns")),
+  Children(AllOf(
+  WithName("Bar"), WithKind(SymbolKind::Class),
+  SymRange(Main.range("bar")),
+  Children(
+  AllOf(WithName("Bar"), WithKind(SymbolKind::Constructor),
+SymRange(Main.range("ctor"))),
+  AllOf(WithName("~Bar"), WithKind(SymbolKind::Constructor),
+SymRange(Main.range("dtor"))),
+  AllOf(WithName("Baz"), WithKind(SymbolKind::Field),
+SymRange(Main.range("field"))),
+  AllOf(WithName("getBaz"), WithKind(SymbolKind::Method),
+SymRange(Main.range("getbaz"))),
+  AllOf(WithName("ForwardClassDecl"), WithKind(SymbolKind::Class),
+SymRange(Main.range("forwardclass"))),
+  AllOf(WithName("StructDefinition"), WithKind(SymbolKind::Struct),
+SymRange(Main.range("struct")),
+Children(AllOf(WithName("Pointer"), WithKind(SymbolKind::Field),
+   SymRange(Main.range("structfield"),
+  AllOf(WithName("StructDeclaration"), WithKind(SymbolKind::Struct),
+SymRange(Main.range("forwardstruct"))),
+  AllOf(WithName("forwardFunctionDecl"), WithKind(SymbolKind::Function),
+SymRange(Main.range("forwardfunc");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/FindSymbols.cpp
===
--- clang-tools-extra/clangd/FindSymbols.cpp
+++ clang-tools-extra/clangd/FindSymbols.cpp
@@ -136,17 +136,11 @@
   auto  = Ctx.getSourceManager();
 
   SourceLocation NameLoc = nameLocation(ND, SM);
-  // getFileLoc is a good choice for us, but we also need to make sure
-  // sourceLocToPosition won't switch files, so we call getSpellingLoc on top of
-  // that to make sure it does not switch files.
-  // FIXME: sourceLocToPosition should not switch files!
   SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
   SourceLocation EndLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getEndLoc()));
-  if (NameLoc.isInvalid() || BeginLoc.isInvalid() || EndLoc.isInvalid())
-return llvm::None;
-
-  if (!SM.isWrittenInMainFile(NameLoc) || !SM.isWrittenInMainFile(BeginLoc) ||
-  !SM.isWrittenInMainFile(EndLoc))
+  const auto SymbolRange =
+  toHalfOpenFileRange(SM, Ctx.getLangOpts(), {BeginLoc, EndLoc});
+  if (!SymbolRange)
 return llvm::None;
 
   Position NameBegin = sourceLocToPosition(SM, NameLoc);
@@ 

[PATCH] D83079: [clang][aarch64] Generate preprocessor macros for -march=armv8.6a+sve.

2020-07-13 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/AArch64.cpp:370
+  if (V8_6Pos != std::end(Features)) {
+V8_6Pos = Features.insert(std::next(V8_6Pos), "+i8mm");
+V8_6Pos = Features.insert(V8_6Pos, "+bf16");

Both `+i8mm` and `+bf16` should be added at iterator `V8_6Pos`, because I 
believe that `std::next(V8_6Pos)` inserts it after the item that follows 
`v8.6a`, rather than after `v8.6a` directly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83079



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


[PATCH] D83501: [clangd][ObjC] Improve xrefs for protocols and classes

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:83
+return PD->getDefinition();
+  // Objective-C classes can have three types of declarations:
+  //

sammccall wrote:
> This is a really useful comment, thanks!
... and it's gone.
I think some comment is useful here, as this line is doing something subtly 
different than all the other lines - returning a decl that isn't equivalent to 
its input.



Comment at: clang-tools-extra/clangd/XRefs.cpp:276
getDeclAtPosition(AST, CurLoc, Relations, NodeKind)) {
 // Special case: void foo() ^override: jump to the overridden method.
 if (const auto *CMD = llvm::dyn_cast(D)) {

dgoldman wrote:
> sammccall wrote:
> > dgoldman wrote:
> > > Think it would make sense to special case ObjCInterfaceDecl here to get 
> > > at both the interface definition + implementation if available?
> > Rather than returning both results, I think it's more consistent to return 
> > them as a declaration/definition pair.
> > 
> > (This means special-casing ObjCImplDecl in namedDecl or at least 
> > getDeclAsPosition, so you always end up with the ObjCInterfaceDecl instead)
> Whoops, meant to comment here but it was lost. I'm not sure what you meant 
> here. Should this be done here inside the for loop or in getDeclAtPosition?
> 
> Are you saying that given:
> 
> ```
> @interface Foo // A
> @end
> @implementation Foo // B
> @end
> ```
> B --> A here
> 
> and similarly
> 
> ```
> @interface Foo // A
> @end
> @interface Foo (Ext) // B
> @end
> @implementation Foo (Ext) // C
> @end
> ```
> B --> A
> C --> B (and A? it's unclear how this should map over, e.g. maybe Foo loc --> 
> A, Ext --> B)
In the first example, selecting either A or B should yield one LocatedSymbol 
with {Decl=A, Def=B}. This shouldn't require any special-casing.

The second example is very similar to template specialization, with exceptions:
 - there's always a Decl/Def pair you may want to navigate between, whereas in 
templates there rarely is, so we have ambiguity
 - there's no AST like there is for template names and args, just a bag of 
tokens

I'd suggest, given `@interface Foo (Ext)`:
 - we produce a LocatedSymbol with {Decl=@interface Foo(Ext), 
Def=@implementation  Foo(Ext)} - this is the default behavior
 - if the cursor is exactly on the token `Foo`, we also produce a LocatedSymbol 
with {Decl=@interface Foo, Def=@implementation Foo} - this is similar to the 
template special case
 - if the cursor is exactly on the token Ext... are categories 
explicitly/separately declared anywhere? I guess not. If they are, we could 
special case this too.
And `@implementation Foo(Ext)` should behave in exactly the same way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83501



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


[PATCH] D83213: [AST][RecoveryExpr] Don't set the instantiation-bit.

2020-07-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 277332.
hokein marked 12 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83213

Files:
  clang/include/clang/AST/DependenceFlags.h
  clang/include/clang/AST/Expr.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/Sema/SemaExpr.cpp

Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -19180,9 +19180,6 @@
 
 ExprResult Sema::CreateRecoveryExpr(SourceLocation Begin, SourceLocation End,
 ArrayRef SubExprs, QualType T) {
-  // FIXME: enable it for C++, RecoveryExpr is type-dependent to suppress
-  // bogus diagnostics and this trick does not work in C.
-  // FIXME: use containsErrors() to suppress unwanted diags in C.
   if (!Context.getLangOpts().RecoveryAST)
 return ExprError();
 
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -495,13 +495,16 @@
 }
 
 ExprDependence clang::computeDependence(RecoveryExpr *E) {
-  // Mark the expression as value- and instantiation- dependent to reuse
-  // existing suppressions for dependent code, e.g. avoiding
-  // constant-evaluation.
-  // FIXME: drop type+value+instantiation once Error is sufficient to suppress
-  // bogus dianostics.
+  // RecoveryExpr is
+  //   - always value-dependent, and therefore instantiation dependent
+  //   - contains errors (ExprDependence::Error), by definition
+  //   - type-dependent if we don't know the type (fallback to an opaque
+  // dependent type), or the type is known and dependent, or it has
+  // type-dependent subexpressions.
   auto D = toExprDependence(E->getType()->getDependence()) |
ExprDependence::ValueInstantiation | ExprDependence::Error;
+  // FIXME: remove the type-dependent bit from any subexpressions, if the
+  // RecoveryExpr has a non-dependent type.
   for (auto *S : E->subExpressions())
 D |= S->getDependence();
   return D;
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -157,9 +157,11 @@
 return static_cast(ExprBits.Dependent);
   }
 
-  /// isValueDependent - Determines whether this expression is
-  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
-  /// array bound of "Chars" in the following example is
+  /// Determines whether the value of this expression depends on
+  ///   - a template parameter (C++ [temp.dep.constexpr])
+  ///   - or an error, whose resolution is unknown
+  ///
+  /// For example, the array bound of "Chars" in the following example is
   /// value-dependent.
   /// @code
   /// template struct meta_string;
@@ -168,10 +170,12 @@
 return static_cast(getDependence() & ExprDependence::Value);
   }
 
-  /// isTypeDependent - Determines whether this expression is
-  /// type-dependent (C++ [temp.dep.expr]), which means that its type
-  /// could change from one template instantiation to the next. For
-  /// example, the expressions "x" and "x + y" are type-dependent in
+  /// Determines whether the type of this expression depends on
+  ///   - a template paramter (C++ [temp.dep.expr], which means that its type
+  /// could change from one template instantiation to the next)
+  ///   - or an error
+  ///
+  /// For example, the expressions "x" and "x + y" are type-dependent in
   /// the following code, but "y" is not type-dependent:
   /// @code
   /// template
@@ -184,8 +188,10 @@
   }
 
   /// Whether this expression is instantiation-dependent, meaning that
-  /// it depends in some way on a template parameter, even if neither its type
-  /// nor (constant) value can change due to the template instantiation.
+  /// it depends in some way on
+  ///- a template parameter (even if neither its type nor (constant) value
+  ///  can change due to the template instantiation)
+  ///- or an error
   ///
   /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
   /// instantiation-dependent (since it involves a template parameter \c T), but
@@ -200,6 +206,12 @@
   /// }
   /// \endcode
   ///
+  /// \code
+  /// void func(int) {
+  ///   func(); // the expression is instantiation-dependent, because it depends
+  ///   // on an error.
+  /// }
+  /// \endcode
   bool isInstantiationDependent() const {
 return static_cast(getDependence() & ExprDependence::Instantiation);
   }
@@ -6212,19 +6224,25 @@
 /// subexpressions of some expression that we could not construct and source
 /// range covered by the expression.
 ///
-/// By default, RecoveryExpr is type-, value- and instantiation-dependent 

[PATCH] D83621: [clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

> But I am not sure, is it safe to completely remove FileMatchTrie?

Missed this... honestly I don't know. It does seem a little overly defensive to 
me, but any change in symlink behaviour tends to break *someone*.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83621



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


[PATCH] D83286: [analyzer][solver] Track symbol disequalities

2020-07-13 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Introduction


I have some test results with execution times.  Because the execution time 
varies from one execution to another, I've measured performance on master twice 
(I know that it's not very conclusive) to show that equivalence tracking 
doesn't affect performance of the analyzer.  So, please, let's treat it more 
like a smoke test that everything stayed the same with a new functionality 
rather than a full-blown performance benchmarking.

Raw results
---

| project| master run#1 | master run#2 | patch run#1 |
| -- |  |  | --- |
| box2d  | 137.57s  | 156.36s  | 142.46s |
| cxxopts| 26.74s   | 29.31s   | 27.01s  |
| drogon | 257.43s  | 265.88s  | 263.00s |
| duckdb | 2251.08s | 2297.60s | 2258.06s|
| fmt| 266.96s  | 293.06s  | 279.26s |
| libsoundio | 33.89s   | 35.37s   | 36.48s  |
| oatpp  | 171.58s  | 175.25s  | 172.92s |
| re2| 84.12s   | 133.46s  | 87.24s  |
| simbody| 1405.25s | 1374.38s | 1365.58s|
| symengine  | 455.94s  | 487.50s  | 466.28s |
| termbox| 20.91s   | 20.28s   | 20.88s  |
| tinyexpr   | 11.91s   | 13.53s   | 12.58s  |
| tinyspline | 48.61s   | 49.01s   | 48.90s  |
| tinyvm | 27.77s   | 29.32s   | 28.70s  |
| zstd   | 150.28s  | 152.86s  | 154.21s |
|



Processed results
-

| project| min delta | max delta | within range |
| -- | - | - |  |
| box2d  | -8.9% | 3.6%  | {icon check-circle color=green}  |
| cxxopts| -7.8% | 1.0%  | {icon check-circle color=green}  |
| drogon | -1.1% | 2.2%  | {icon check-circle color=green}  |
| duckdb | -1.7% | 0.3%  | {icon check-circle color=green}  |
| fmt| -4.7% | 4.6%  | {icon check-circle color=green}  |
| libsoundio | 3.1%  | 7.6%  | {icon arrow-circle-up color=red} |
| oatpp  | -1.3% | 0.8%  | {icon check-circle color=green}  |
| re2| -34.6%| 3.7%  | {icon check-circle color=green}  |
| simbody| -2.8% | -0.6% | {icon arrow-circle-down color=green} |
| symengine  | -4.4% | 2.3%  | {icon check-circle color=green}  |
| termbox| -0.1% | 3.0%  | {icon check-circle color=green}  |
| tinyexpr   | -7.0% | 5.6%  | {icon check-circle color=green}  |
| tinyspline | -0.2% | 0.6%  | {icon check-circle color=green}  |
| tinyvm | -2.1% | 3.3%  | {icon check-circle color=green}  |
| zstd   | 0.9%  | 2.6%  | {icon arrow-circle-up color=red} |
|


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83286



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


[PATCH] D83657: [clangd] Add metrics for recovery-expr type propagation.

2020-07-13 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG26cf6c1513f9: [clangd] Add metrics for recovery-expr type 
propagation. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83657

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -453,6 +453,8 @@
   auto T = makeSelectionTree(Code, AST);
   EXPECT_THAT(Tracer.takeMetric("selection_recovery"),
   testing::ElementsAreArray({1}));
+  EXPECT_THAT(Tracer.takeMetric("selection_recovery_type"),
+  testing::ElementsAreArray({1}));
 }
 
 // FIXME: Doesn't select the binary operator node in
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -41,10 +41,13 @@
 void recordMetrics(const SelectionTree ) {
   static constexpr trace::Metric SelectionUsedRecovery(
   "selection_recovery", trace::Metric::Distribution);
+  static constexpr trace::Metric RecoveryType("selection_recovery_type",
+  trace::Metric::Distribution);
   const auto *Common = S.commonAncestor();
   for (const auto *N = Common; N; N = N->Parent) {
-if (N->ASTNode.get()) {
+if (const auto *RE = N->ASTNode.get()) {
   SelectionUsedRecovery.record(1); // used recovery ast.
+  RecoveryType.record(RE->isTypeDependent() ? 0 : 1);
   return;
 }
   }


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -453,6 +453,8 @@
   auto T = makeSelectionTree(Code, AST);
   EXPECT_THAT(Tracer.takeMetric("selection_recovery"),
   testing::ElementsAreArray({1}));
+  EXPECT_THAT(Tracer.takeMetric("selection_recovery_type"),
+  testing::ElementsAreArray({1}));
 }
 
 // FIXME: Doesn't select the binary operator node in
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -41,10 +41,13 @@
 void recordMetrics(const SelectionTree ) {
   static constexpr trace::Metric SelectionUsedRecovery(
   "selection_recovery", trace::Metric::Distribution);
+  static constexpr trace::Metric RecoveryType("selection_recovery_type",
+  trace::Metric::Distribution);
   const auto *Common = S.commonAncestor();
   for (const auto *N = Common; N; N = N->Parent) {
-if (N->ASTNode.get()) {
+if (const auto *RE = N->ASTNode.get()) {
   SelectionUsedRecovery.record(1); // used recovery ast.
+  RecoveryType.record(RE->isTypeDependent() ? 0 : 1);
   return;
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 26cf6c1 - [clangd] Add metrics for recovery-expr type propagation.

2020-07-13 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-07-13T11:26:45+02:00
New Revision: 26cf6c1513f95082cedd4f2acf0881dd9ab56461

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

LOG: [clangd] Add metrics for recovery-expr type propagation.

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

Added: 


Modified: 
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index 1db15ba6699a..e94a3ca5a0c3 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -41,10 +41,13 @@ using ast_type_traits::DynTypedNode;
 void recordMetrics(const SelectionTree ) {
   static constexpr trace::Metric SelectionUsedRecovery(
   "selection_recovery", trace::Metric::Distribution);
+  static constexpr trace::Metric RecoveryType("selection_recovery_type",
+  trace::Metric::Distribution);
   const auto *Common = S.commonAncestor();
   for (const auto *N = Common; N; N = N->Parent) {
-if (N->ASTNode.get()) {
+if (const auto *RE = N->ASTNode.get()) {
   SelectionUsedRecovery.record(1); // used recovery ast.
+  RecoveryType.record(RE->isTypeDependent() ? 0 : 1);
   return;
 }
   }

diff  --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp 
b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 6f8c10e966a8..051580ba6e49 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -453,6 +453,8 @@ TEST(SelectionTree, Metrics) {
   auto T = makeSelectionTree(Code, AST);
   EXPECT_THAT(Tracer.takeMetric("selection_recovery"),
   testing::ElementsAreArray({1}));
+  EXPECT_THAT(Tracer.takeMetric("selection_recovery_type"),
+  testing::ElementsAreArray({1}));
 }
 
 // FIXME: Doesn't select the binary operator node in



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


[PATCH] D83665: [OpenCL] Fixed missing address space for templated copy constructor

2020-07-13 Thread Ole Strohm via Phabricator via cfe-commits
olestrohm created this revision.
olestrohm added reviewers: Anastasia, rjmccall.
olestrohm added a project: clang.
Herald added subscribers: cfe-commits, yaxunl.

When you have a templated constructor with an R-value reference the compiler 
implicitly creates a copy and move constructor through the template 
constructor, and the copy constructor created this way was missing an address 
space in the reference parameter. I've come up with this fix that deduces the 
address space for the reference parameter right before it's created, and a 
corresponding test.

The test is quite big, but rep_outer is necessary to force the compiler to 
create the copy constructor, and the two template structs are partly for 
readability.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83665

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaOpenCLCXX/address-space-templates.cl

Index: clang/test/SemaOpenCLCXX/address-space-templates.cl
===
--- clang/test/SemaOpenCLCXX/address-space-templates.cl
+++ clang/test/SemaOpenCLCXX/address-space-templates.cl
@@ -22,10 +22,28 @@
   __private T ii; // expected-error{{conflicting address space qualifiers are provided between types '__private T' and '__global int'}}
 }
 
+template  struct remove_reference { typedef _Tp type; };
+template  struct remove_reference<_Tp &>  { typedef _Tp type; };
+template  struct as_pointer {
+typedef typename remove_reference<_Tp>::type* type;
+};
+
+struct rep {
+	// CHECK |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep &__private) __generic'
+	template::type>
+	rep(U&& v) {}
+};
+
+struct rep_outer : private rep {
+	rep_outer()
+		: rep(0) {}
+};
+
 void bar() {
   S sintgl; // expected-note{{in instantiation of template class 'S' requested here}}
 
   foo1<__local int>(1); // expected-error{{no matching function for call to 'foo1'}}
   foo2<__global int>(0);
   foo3<__global int>(); // expected-note{{in instantiation of function template specialization 'foo3<__global int>' requested here}}
+  rep_outer r;
 }
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2036,13 +2036,13 @@
 }
 
 // Helper to deduce addr space of a pointee type in OpenCL mode.
-static QualType deduceOpenCLPointeeAddrSpace(Sema , QualType PointeeType) {
+QualType Sema::deduceOpenCLPointeeAddrSpace(QualType PointeeType) {
   if (!PointeeType->isUndeducedAutoType() && !PointeeType->isDependentType() &&
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
-PointeeType = S.getASTContext().getAddrSpaceQualType(
+PointeeType = getASTContext().getAddrSpaceQualType(
 PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
+getLangOpts().OpenCLCPlusPlus || getLangOpts().OpenCLVersion == 200
 ? LangAS::opencl_generic
 : LangAS::opencl_private);
   return PointeeType;
@@ -2085,7 +2085,7 @@
 T = inferARCLifetimeForPointee(*this, T, Loc, /*reference*/ false);
 
   if (getLangOpts().OpenCL)
-T = deduceOpenCLPointeeAddrSpace(*this, T);
+T = deduceOpenCLPointeeAddrSpace(T);
 
   // Build the pointer type.
   return Context.getPointerType(T);
@@ -2148,7 +2148,7 @@
 T = inferARCLifetimeForPointee(*this, T, Loc, /*reference*/ true);
 
   if (getLangOpts().OpenCL)
-T = deduceOpenCLPointeeAddrSpace(*this, T);
+T = deduceOpenCLPointeeAddrSpace(T);
 
   // Handle restrict on references.
   if (LValueRef)
@@ -2862,7 +2862,7 @@
 return QualType();
 
   if (getLangOpts().OpenCL)
-T = deduceOpenCLPointeeAddrSpace(*this, T);
+T = deduceOpenCLPointeeAddrSpace(T);
 
   return Context.getBlockPointerType(T);
 }
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3806,8 +3806,11 @@
 //   If P is a forwarding reference and the argument is an lvalue, the type
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
-Arg->isLValue())
+Arg->isLValue()) {
+  if(S.getLangOpts().OpenCL)
+ArgType = S.deduceOpenCLPointeeAddrSpace(ArgType);
   ArgType = S.Context.getLValueReferenceType(ArgType);
+}
   } else {
 // C++ [temp.deduct.call]p2:
 //   If P is not a reference type:
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -9364,6 +9364,7 @@
   bool inferObjCARCLifetime(ValueDecl *decl);
 
   void deduceOpenCLAddressSpace(ValueDecl *decl);
+  QualType 

[PATCH] D82436: [clangd] Implement textDocument/foldingRange

2020-07-13 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 277381.
kbobyrev marked 5 inline comments as done.
kbobyrev added a comment.

Isolate DocumentSymbol range changes into D83668 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82436

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang-tools-extra/clangd/SemanticSelection.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -17,15 +17,19 @@
 #include "TestTU.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+
 namespace clang {
 namespace clangd {
 namespace {
+
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
+using ::testing::UnorderedElementsAreArray;
 
 // front() is SR.range, back() is outermost range.
 std::vector gatherRanges(const SelectionRange ) {
@@ -35,6 +39,22 @@
   return Ranges;
 }
 
+std::vector
+gatherFoldingRanges(llvm::ArrayRef FoldingRanges) {
+  std::vector Ranges;
+  Range NextRange;
+  for (const auto  : FoldingRanges) {
+NextRange.start.line = R.startLine;
+EXPECT_TRUE(R.startCharacter);
+NextRange.start.character = *R.startCharacter;
+NextRange.end.line = R.endLine;
+EXPECT_TRUE(R.endCharacter);
+NextRange.end.character = *R.endCharacter;
+Ranges.push_back(NextRange);
+  }
+  return Ranges;
+}
+
 TEST(SemanticSelection, All) {
   const char *Tests[] = {
   R"cpp( // Single statement in a function body.
@@ -118,16 +138,16 @@
   )cpp",
   R"cpp( // Inside struct.
 struct A { static int a(); };
-[[struct B { 
+[[struct B {
   [[static int b() [[{
 [[return 1^1]] + 2;
   }
 }]];
   )cpp",
   // Namespaces.
-  R"cpp( 
-[[namespace nsa { 
-  [[namespace nsb { 
+  R"cpp(
+[[namespace nsa {
+  [[namespace nsb {
 static int ccc();
 [[void func() [[{
   // int x = nsa::nsb::ccc();
@@ -181,6 +201,41 @@
   EXPECT_THAT(gatherRanges(Ranges->back()),
   ElementsAre(SourceAnnotations.range("empty")));
 }
+
+TEST(FoldingRanges, All) {
+  const char *Tests[] = {
+  R"cpp(
+int [[global_variable]];
+
+[[void func() {
+  int v = 100;
+}]]
+  )cpp",
+  R"cpp(
+[[class Foo {
+public:
+  [[Foo() {
+int X = 1;
+  }]]
+
+private:
+  [[int getBar() {
+return 42;
+  }]]
+
+  [[void getFooBar() { }]]
+}]];
+  )cpp",
+  };
+  for (const char *Test : Tests) {
+auto T = Annotations(Test);
+auto AST = TestTU::withCode(T.code()).build();
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(AST))),
+UnorderedElementsAreArray(T.ranges()))
+<< Test;
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -296,6 +296,14 @@
 Hidden,
 };
 
+opt FoldingRanges{
+"folding-ranges",
+cat(Features),
+desc("Enable preview of FoldingRanges feature"),
+init(false),
+Hidden,
+};
+
 opt WorkerThreadsCount{
 "j",
 cat(Misc),
@@ -659,6 +667,7 @@
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.BuildRecoveryAST = RecoveryAST;
   Opts.PreserveRecoveryASTType = RecoveryASTType;
+  Opts.FoldingRanges = FoldingRanges;
 
   clangd::CodeCompleteOptions CCOpts;
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
Index: clang-tools-extra/clangd/SemanticSelection.h
===
--- clang-tools-extra/clangd/SemanticSelection.h
+++ clang-tools-extra/clangd/SemanticSelection.h
@@ -25,6 +25,10 @@
 /// If pos is not in any interesting range, return [Pos, Pos).
 llvm::Expected getSemanticRanges(ParsedAST , Position Pos);
 
+/// Returns a list of ranges whose contents might be collapsible in an editor.
+/// This should include large scopes, preprocessor blocks etc.
+llvm::Expected> 

[PATCH] D82436: [clangd] Implement textDocument/foldingRange

2020-07-13 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 277382.
kbobyrev added a comment.

Rebase on top of master.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82436

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang-tools-extra/clangd/SemanticSelection.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -17,15 +17,19 @@
 #include "TestTU.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+
 namespace clang {
 namespace clangd {
 namespace {
+
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
+using ::testing::UnorderedElementsAreArray;
 
 // front() is SR.range, back() is outermost range.
 std::vector gatherRanges(const SelectionRange ) {
@@ -35,6 +39,22 @@
   return Ranges;
 }
 
+std::vector
+gatherFoldingRanges(llvm::ArrayRef FoldingRanges) {
+  std::vector Ranges;
+  Range NextRange;
+  for (const auto  : FoldingRanges) {
+NextRange.start.line = R.startLine;
+EXPECT_TRUE(R.startCharacter);
+NextRange.start.character = *R.startCharacter;
+NextRange.end.line = R.endLine;
+EXPECT_TRUE(R.endCharacter);
+NextRange.end.character = *R.endCharacter;
+Ranges.push_back(NextRange);
+  }
+  return Ranges;
+}
+
 TEST(SemanticSelection, All) {
   const char *Tests[] = {
   R"cpp( // Single statement in a function body.
@@ -118,16 +138,16 @@
   )cpp",
   R"cpp( // Inside struct.
 struct A { static int a(); };
-[[struct B { 
+[[struct B {
   [[static int b() [[{
 [[return 1^1]] + 2;
   }
 }]];
   )cpp",
   // Namespaces.
-  R"cpp( 
-[[namespace nsa { 
-  [[namespace nsb { 
+  R"cpp(
+[[namespace nsa {
+  [[namespace nsb {
 static int ccc();
 [[void func() [[{
   // int x = nsa::nsb::ccc();
@@ -181,6 +201,41 @@
   EXPECT_THAT(gatherRanges(Ranges->back()),
   ElementsAre(SourceAnnotations.range("empty")));
 }
+
+TEST(FoldingRanges, All) {
+  const char *Tests[] = {
+  R"cpp(
+int [[global_variable]];
+
+[[void func() {
+  int v = 100;
+}]]
+  )cpp",
+  R"cpp(
+[[class Foo {
+public:
+  [[Foo() {
+int X = 1;
+  }]]
+
+private:
+  [[int getBar() {
+return 42;
+  }]]
+
+  [[void getFooBar() { }]]
+}]];
+  )cpp",
+  };
+  for (const char *Test : Tests) {
+auto T = Annotations(Test);
+auto AST = TestTU::withCode(T.code()).build();
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(AST))),
+UnorderedElementsAreArray(T.ranges()))
+<< Test;
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -296,6 +296,14 @@
 Hidden,
 };
 
+opt FoldingRanges{
+"folding-ranges",
+cat(Features),
+desc("Enable preview of FoldingRanges feature"),
+init(false),
+Hidden,
+};
+
 opt WorkerThreadsCount{
 "j",
 cat(Misc),
@@ -676,6 +684,7 @@
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.BuildRecoveryAST = RecoveryAST;
   Opts.PreserveRecoveryASTType = RecoveryASTType;
+  Opts.FoldingRanges = FoldingRanges;
 
   clangd::CodeCompleteOptions CCOpts;
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
Index: clang-tools-extra/clangd/SemanticSelection.h
===
--- clang-tools-extra/clangd/SemanticSelection.h
+++ clang-tools-extra/clangd/SemanticSelection.h
@@ -25,6 +25,10 @@
 /// If pos is not in any interesting range, return [Pos, Pos).
 llvm::Expected getSemanticRanges(ParsedAST , Position Pos);
 
+/// Returns a list of ranges whose contents might be collapsible in an editor.
+/// This should include large scopes, preprocessor blocks etc.
+llvm::Expected> getFoldingRanges(ParsedAST );
+
 } // namespace clangd
 } // namespace clang
 
Index: 

[PATCH] D83025: [clang] Include type specifiers in typo correction when checking isCXXDeclarationSpecifiers.

2020-07-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 277363.
hokein marked 2 inline comments as done.
hokein added a comment.

rebase and address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83025

Files:
  clang/lib/Parse/ParseTentative.cpp
  clang/test/Parser/cxx-template-decl.cpp
  clang/test/SemaCXX/typo-correction.cpp


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -611,6 +611,41 @@
 }
 }
 
+namespace testIncludeTypeInTemplateArgument {
+template 
+void foo(T t = {}, U = {}); // expected-note {{candidate template ignored}}
+
+class AddObservation {}; // expected-note {{declared here}}
+int bar1() {
+  // should resolve to a class.
+  foo(); // expected-error {{unknown type name 
'AddObservationFn'; did you mean 'AddObservation'?}}
+
+  // should not resolve to a class.
+  foo(AddObservationFn, 1);// expected-error-re {{use of undeclared 
identifier 'AddObservationFn'{{$
+  int a = AddObservationFn, b; // expected-error-re {{use of undeclared 
identifier 'AddObservationFn'{{$
+
+  int AddObservation; // expected-note 3{{declared here}}
+  // should resolve to a local variable.
+  foo(AddObservationFn, 1);// expected-error {{use of undeclared 
identifier 'AddObservationFn'; did you mean}}
+  int c = AddObservationFn, d; // expected-error {{use of undeclared 
identifier 'AddObservationFn'; did you mean}}
+
+  // FIXME: would be nice to not resolve to a variable.
+  foo(); // expected-error {{use of undeclared 
identifier 'AddObservationFn'; did you mean}} \
+   expected-error {{no matching function for 
call}}
+}
+} // namespace testIncludeTypeInTemplateArgument
+
+namespace testNoCrashOnNullNNSTypoCorrection {
+int AddObservation();
+template 
+class UsingImpl {};
+class AddObservation { // expected-note {{declared here}}
+  using Using =
+  // should resolve to a class.
+  UsingImpl; // expected-error {{unknown type 
name 'AddObservationFn'; did you mean}}
+};
+} // namespace testNoCrashOnNullNNSTypoCorrection
+
 namespace testNonStaticMemberHandling {
 struct Foo {
   bool usesMetadata;  // expected-note {{'usesMetadata' declared here}}
Index: clang/test/Parser/cxx-template-decl.cpp
===
--- clang/test/Parser/cxx-template-decl.cpp
+++ clang/test/Parser/cxx-template-decl.cpp
@@ -286,17 +286,3 @@
   template int b;
   template auto f() -> b<0>; // expected-error +{{}}
 }
-
-namespace NoCrashOnNullNNSTypoCorrection {
-
-int AddObservation(); // expected-note {{declared here}}
-
-template  // expected-note {{template parameter 
is declared here}}
-class UsingImpl {};
-class AddObservation {
-  using Using =
-UsingImpl; // expected-error {{use of 
undeclared identifier 'AddObservationFn'; did you mean}} \
-   expected-error {{template 
argument for template type parameter must be a type}}
-};
-
-}
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -1110,8 +1110,9 @@
 public:
   TentativeParseCCC(const Token ) {
 WantRemainingKeywords = false;
-WantTypeSpecifiers = Next.isOneOf(tok::l_paren, tok::r_paren, tok::greater,
-  tok::l_brace, tok::identifier);
+WantTypeSpecifiers =
+Next.isOneOf(tok::l_paren, tok::r_paren, tok::greater, tok::l_brace,
+ tok::identifier, tok::comma);
   }
 
   bool ValidateCandidate(const TypoCorrection ) override {


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -611,6 +611,41 @@
 }
 }
 
+namespace testIncludeTypeInTemplateArgument {
+template 
+void foo(T t = {}, U = {}); // expected-note {{candidate template ignored}}
+
+class AddObservation {}; // expected-note {{declared here}}
+int bar1() {
+  // should resolve to a class.
+  foo(); // expected-error {{unknown type name 'AddObservationFn'; did you mean 'AddObservation'?}}
+
+  // should not resolve to a class.
+  foo(AddObservationFn, 1);// expected-error-re {{use of undeclared identifier 'AddObservationFn'{{$
+  int a = AddObservationFn, b; // expected-error-re {{use of undeclared identifier 'AddObservationFn'{{$
+
+  int AddObservation; // expected-note 3{{declared here}}
+  // should resolve to a local variable.
+  foo(AddObservationFn, 1);// expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}}
+  int c = AddObservationFn, d; // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}}
+
+  // 

[PATCH] D83296: [clang-format] Add a MacroExpander.

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D83296#2146870 , @klimek wrote:

> Monday-morning ping.


Thanks for the reminder here... however this is taking me a bit to get my head 
around, and we've got a release branch cut scheduled for a couple of days that 
we're trying to polish for.
AFAICT there's significant followup work still needed to make use of this - are 
you wanting this to land in the 11 release? Else i'd probably come back to this 
after the cut...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83296



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


[PATCH] D82436: [clangd] Implement textDocument/foldingRange

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I'd suggest splitting out the DocumentSymbol changes into a separate patch from 
the FoldingRanges patches.




Comment at: clang-tools-extra/clangd/FindSymbols.cpp:140
   SourceLocation NameLoc = nameLocation(ND, SM);
   // getFileLoc is a good choice for us, but we also need to make sure
   // sourceLocToPosition won't switch files, so we call getSpellingLoc on top 
of

this whole block seems likely to be obsolete if you switch to 
toHalfOpenFileRange



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:167
   SI.range =
   Range{sourceLocToPosition(SM, BeginLoc), sourceLocToPosition(SM, 
EndLoc)};
+  // Include trailing '}' token for most symbol kinds.

As far as I can tell, this line is just always wrong: EndLoc points at the 
*start* of the last token in the range, so the last token will be omitted from 
the range in all cases.



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:168
   Range{sourceLocToPosition(SM, BeginLoc), sourceLocToPosition(SM, 
EndLoc)};
+  // Include trailing '}' token for most symbol kinds.
+  if (SK == SymbolKind::Class || SK == SymbolKind::Struct ||

I can't see any conceptual reason for this to be conditional.



Comment at: clang-tools-extra/clangd/SemanticSelection.h:28
 
+llvm::Expected> getFoldingRanges(ParsedAST );
+

Can we still have a high-level description of what this function does?

```
Returns a list of ranges whose contents might be collapsible in an editor.
This should include large scopes, preprocessor blocks etc.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82436



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


[PATCH] D81385: Fix libdl linking for libclang in standalone mode

2020-07-13 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

Ping @beanz - I think people would like this to be included before the 11 
branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81385



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


[PATCH] D83055: [clang][Driver] Fix tool path priority test failures

2020-07-13 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett updated this revision to Diff 277344.
DavidSpickett marked an inline comment as done.
DavidSpickett added a comment.

- Use more standard 'test -f' command before 'mv's


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83055

Files:
  clang/test/Driver/program-path-priority.c
  clang/test/lit.cfg.py

Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -46,6 +46,8 @@
 config.substitutions.append(
 ('%src_include_dir', config.clang_src_dir + '/include'))
 
+config.substitutions.append(
+('%target_triple', config.target_triple))
 
 # Propagate path to symbolizer for ASan/MSan.
 llvm_config.with_system_environment(
Index: clang/test/Driver/program-path-priority.c
===
--- clang/test/Driver/program-path-priority.c
+++ clang/test/Driver/program-path-priority.c
@@ -13,6 +13,11 @@
 /// so only name priority is accounted for, unless we fail to find
 /// anything at all in the prefix.
 
+/// Note: All matches are expected to be at the end of file paths.
+/// So we match " on the end to account for build systems that
+/// put the name of the compiler in the build path.
+/// E.g. /build/gcc_X.Y.Z/0/...
+
 /// Symlink clang to a new dir which will be its
 /// "program path" for these tests
 // RUN: rm -rf %t && mkdir -p %t
@@ -21,14 +26,18 @@
 /// No gccs at all, nothing is found
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NO_NOTREAL_GCC %s
-// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc
-// NO_NOTREAL_GCC-NOT: /gcc
+// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc"
+/// Some systems will have "gcc-x.y.z" so for this first check
+/// make sure we don't find "gcc" or "gcc-x.y.z". If we do find either
+/// then there is no point continuing as this copy of clang is not
+/// isolated as we expected.
+// NO_NOTREAL_GCC-NOT: {{/gcc[^/]*"}}
 
 /// -gcc in program path is found
 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=PROG_PATH_NOTREAL_GCC %s
-// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc
+// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc"
 
 /// -gcc on the PATH is found
 // RUN: mkdir -p %t/env
@@ -36,74 +45,89 @@
 // RUN: touch %t/env/notreal-none-elf-gcc && chmod +x %t/env/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=ENV_PATH_NOTREAL_GCC %s
-// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc
+// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc"
 
 /// -gcc in program path is preferred to one on the PATH
 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=BOTH_NOTREAL_GCC %s
-// BOTH_NOTREAL_GCC: notreal-none-elf-gcc
-// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc
+// BOTH_NOTREAL_GCC: notreal-none-elf-gcc"
+// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc"
 
 /// On program path, -gcc is preferred to plain gcc
 // RUN: touch %t/gcc && chmod +x %t/gcc
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_GCC_PREFERRED %s
-// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc
-// NOTREAL_GCC_PREFERRED-NOT: /gcc
+// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc"
+// NOTREAL_GCC_PREFERRED-NOT: /gcc"
 
 /// -gcc on the PATH is preferred to gcc in program path
 // RUN: rm %t/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PROG %s
-// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc
-// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc
+// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc"
+// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc"
 
 /// -gcc on the PATH is preferred to gcc on the PATH
 // RUN: rm %t/gcc
 // RUN: touch %t/env/gcc && chmod +x %t/env/gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PATH %s
-// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc
-// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc
+// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc"
+// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc"
+
+/// We cannot trust clang --version, or cmake's LLVM_DEFAULT_TARGET_TRIPLE
+/// to give us the one and only default triple.
+/// Can't trust cmake because on Darwin, triples have a verison appended to them.
+/// (and clang uses the versioned string to search)
+/// Can't trust --version because it will pad 3 item triples to 4 e.g.
+/// powerpc64le-linux-gnu -> powerpc64le-unknown-linux-gnu
+/// (and clang 

[PATCH] D83223: [clang-tidy] Header guard check can skip past license comment

2020-07-13 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 277348.
njames93 added a comment.

Added /**/ style license comment test cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83223

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
@@ -221,6 +221,123 @@
 "", "/llvm-project/clang-tools-extra/clangd/foo.h",
 StringRef("header is missing header guard")));
 }
+
+TEST(LLVMHeaderGuardCheckTest, FixHeaderGuardsWithComments) {
+  EXPECT_EQ("// LicenseText //\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// LicenseText //", "include/clang/bar.h",
+StringRef("header is missing header guard")));
+
+  EXPECT_EQ("// LicenseText //\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// LicenseText //\n", "include/clang/bar.h",
+StringRef("header is missing header guard")));
+  EXPECT_EQ("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //\n",
+"include/clang/bar.h",
+StringRef("header is missing header guard")));
+  EXPECT_EQ("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //",
+"include/clang/bar.h",
+StringRef("header is missing header guard")));
+
+  EXPECT_EQ("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"// FunctionDoc\n"
+"void Foo();\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //\n"
+"\n"
+"// FunctionDoc\n"
+"void Foo();\n",
+"include/clang/bar.h",
+StringRef("header is missing header guard")));
+
+  EXPECT_EQ("#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"// Function Doc\n"
+"void foo();\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// Function Doc\n"
+"void foo();\n",
+"include/clang/bar.h",
+StringRef("header is missing header guard")));
+
+  EXPECT_EQ("/* LicenseText \n"
+"   SecondLine  \n"
+"   ThirdLine */\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("/* LicenseText \n"
+"   SecondLine  \n"
+"   ThirdLine */\n",
+"include/clang/bar.h",
+StringRef("header is missing header guard")));
+
+  EXPECT_EQ("/* LicenseText \n"
+"   SecondLine  \n"
+"   ThirdLine */\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"// FunctionDoc\n"
+"void Foo();\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("/* LicenseText \n"
+  

[PATCH] D83025: [clang] Include type specifiers in typo correction when checking isCXXDeclarationSpecifiers.

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/SemaCXX/typo-correction.cpp:614
 
+namespace testIncludeTypeInTemplateArgument {
+template 

are these one testcase or two?
If they're independent, please use different identifiers to avoid confusion



Comment at: clang/test/SemaCXX/typo-correction.cpp:623
+
+  // should not reslove to a class.
+  foo(AddObservationFn, 1);// expected-error-re {{use of undeclared 
identifier 'AddObservationFn'{{$

"resolve" and 5 lines below


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83025



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


[PATCH] D83025: [clang] Include type specifiers in typo correction when checking isCXXDeclarationSpecifiers.

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/test/SemaCXX/typo-correction.cpp:614
 
+namespace testIncludeTypeInTemplateArgument {
+template 

sammccall wrote:
> are these one testcase or two?
> If they're independent, please use different identifiers to avoid confusion
I'm not sure this comment was addressed?
both testIncludeTypeInTemplateArgument and testNoCrashOnNullNNSTypoCorrection 
use the name "AddObservation", which seems like something very specific but in 
fact these tests are unrelated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83025



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


[clang] 6050c15 - [OpenCL] Defer addr space deduction for dependent type.

2020-07-13 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-07-13T11:44:38+01:00
New Revision: 6050c156ab4f13a3c54ca6ec297a72ece95966d7

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

LOG: [OpenCL] Defer addr space deduction for dependent type.

This patch removes deduction of address spaces in parsing
for types that depend on template parameter even if an
address space is already known. Deducing it early interferes
with template instantiation/specialization logic that uses
source address space where address space is not present.

Address space deduction for templates is therefore fully
moved to the template instantiation/specialization phase.

Patch by Ole Strohm (olestrohm)!

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaOpenCLCXX/address-space-deduction.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f5e375134c29..3e2b61ae8cdf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6290,6 +6290,8 @@ bool Sema::inferObjCARCLifetime(ValueDecl *decl) {
 void Sema::deduceOpenCLAddressSpace(ValueDecl *Decl) {
   if (Decl->getType().hasAddressSpace())
 return;
+  if (Decl->getType()->isDependentType())
+return;
   if (VarDecl *Var = dyn_cast(Decl)) {
 QualType Type = Var->getType();
 if (Type->isSamplerT() || Type->isVoidType())
@@ -7859,6 +7861,7 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
 if (NewVD->isFileVarDecl() || NewVD->isStaticLocal() ||
 NewVD->hasExternalStorage()) {
   if (!T->isSamplerT() &&
+  !T->isDependentType() &&
   !(T.getAddressSpace() == LangAS::opencl_constant ||
 (T.getAddressSpace() == LangAS::opencl_global &&
  (getLangOpts().OpenCLVersion == 200 ||

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 85adc4ef2dbd..2efb7acb9724 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3625,6 +3625,9 @@ Decl 
*TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
   if (InsertPos)
 VarTemplate->AddSpecialization(Var, InsertPos);
 
+  if (SemaRef.getLangOpts().OpenCL)
+SemaRef.deduceOpenCLAddressSpace(Var);
+
   // Substitute the nested name specifier, if any.
   if (SubstQualifier(D, Var))
 return nullptr;
@@ -4895,6 +4898,9 @@ VarTemplateSpecializationDecl 
*Sema::CompleteVarTemplateSpecializationDecl(
   // Instantiate the initializer.
   InstantiateVariableInitializer(VarSpec, PatternDecl, TemplateArgs);
 
+  if (getLangOpts().OpenCL)
+deduceOpenCLAddressSpace(VarSpec);
+
   return VarSpec;
 }
 

diff  --git a/clang/test/SemaOpenCLCXX/address-space-deduction.cl 
b/clang/test/SemaOpenCLCXX/address-space-deduction.cl
index 6a81a8b2d7c7..ddfdb6da4347 100644
--- a/clang/test/SemaOpenCLCXX/address-space-deduction.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-deduction.cl
@@ -5,6 +5,11 @@
 //CHECK: |-VarDecl {{.*}} foo 'const __global int'
 constexpr int foo = 0;
 
+//CHECK: |-VarDecl {{.*}} foo1 'T' cinit
+//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global 
long':'__global long' cinit
+template 
+T foo1 = 0;
+
 class c {
 public:
   //CHECK: `-VarDecl {{.*}} foo2 'const __global int'
@@ -30,7 +35,7 @@ struct c2 {
 
 template 
 struct x1 {
-//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &__private){{( 
__attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &){{( 
__attribute__.*)?}} __generic'
 //CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic 
x1 &__private){{( __attribute__.*)?}} __generic'
   x1& operator=(const x1& xx) {
 y = xx.y;
@@ -41,7 +46,7 @@ struct x1 {
 
 template 
 struct x2 {
-//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *__private){{( 
__attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *){{( __attribute__.*)?}} 
__generic'
 //CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *__private){{( 
__attribute__.*)?}} __generic'
   void foo(x1* xx) {
 m[0] = *xx;
@@ -57,10 +62,10 @@ void bar(__global x1 *xx, __global x2 *bar) {
 template 
 class x3 : public T {
 public:
-  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &__private){{( 
__attribute__.*)?}} __generic'
+  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( 
__attribute__.*)?}} __generic'
   x3(const x3 );
 };
-//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &__private){{( 
__attribute__.*)?}} __generic'
+//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( 
__attribute__.*)?}} __generic'
 template 
 x3::x3(const x3 

[PATCH] D82781: [OpenCL] Fix missing address space deduction in template variables

2020-07-13 Thread Anastasia Stulova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6050c156ab4f: [OpenCL] Defer addr space deduction for 
dependent type. (authored by Anastasia).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82781

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaOpenCLCXX/address-space-deduction.cl

Index: clang/test/SemaOpenCLCXX/address-space-deduction.cl
===
--- clang/test/SemaOpenCLCXX/address-space-deduction.cl
+++ clang/test/SemaOpenCLCXX/address-space-deduction.cl
@@ -5,6 +5,11 @@
 //CHECK: |-VarDecl {{.*}} foo 'const __global int'
 constexpr int foo = 0;
 
+//CHECK: |-VarDecl {{.*}} foo1 'T' cinit
+//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long':'__global long' cinit
+template 
+T foo1 = 0;
+
 class c {
 public:
   //CHECK: `-VarDecl {{.*}} foo2 'const __global int'
@@ -30,7 +35,7 @@
 
 template 
 struct x1 {
-//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &__private){{( __attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &){{( __attribute__.*)?}} __generic'
 //CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic x1 &__private){{( __attribute__.*)?}} __generic'
   x1& operator=(const x1& xx) {
 y = xx.y;
@@ -41,7 +46,7 @@
 
 template 
 struct x2 {
-//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *__private){{( __attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *){{( __attribute__.*)?}} __generic'
 //CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *__private){{( __attribute__.*)?}} __generic'
   void foo(x1* xx) {
 m[0] = *xx;
@@ -57,10 +62,10 @@
 template 
 class x3 : public T {
 public:
-  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &__private){{( __attribute__.*)?}} __generic'
+  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( __attribute__.*)?}} __generic'
   x3(const x3 );
 };
-//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &__private){{( __attribute__.*)?}} __generic'
+//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( __attribute__.*)?}} __generic'
 template 
 x3::x3(const x3 ) {}
 
@@ -68,7 +73,8 @@
 T xxx(T *in1, T in2) {
   // This pointer can't be deduced to generic because addr space
   // will be taken from the template argument.
-  //CHECK: `-VarDecl {{.*}} '__private T *__private' cinit
+  //CHECK: `-VarDecl {{.*}} 'T *' cinit
+  //CHECK: `-VarDecl {{.*}} i '__private int *__private' cinit
   T *i = in1;
   T ii;
   __private T *ptr = 
@@ -111,4 +117,5 @@
   t3();
   t4();
   t5();
+  long f1 = foo1;
 }
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3625,6 +3625,9 @@
   if (InsertPos)
 VarTemplate->AddSpecialization(Var, InsertPos);
 
+  if (SemaRef.getLangOpts().OpenCL)
+SemaRef.deduceOpenCLAddressSpace(Var);
+
   // Substitute the nested name specifier, if any.
   if (SubstQualifier(D, Var))
 return nullptr;
@@ -4895,6 +4898,9 @@
   // Instantiate the initializer.
   InstantiateVariableInitializer(VarSpec, PatternDecl, TemplateArgs);
 
+  if (getLangOpts().OpenCL)
+deduceOpenCLAddressSpace(VarSpec);
+
   return VarSpec;
 }
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -6290,6 +6290,8 @@
 void Sema::deduceOpenCLAddressSpace(ValueDecl *Decl) {
   if (Decl->getType().hasAddressSpace())
 return;
+  if (Decl->getType()->isDependentType())
+return;
   if (VarDecl *Var = dyn_cast(Decl)) {
 QualType Type = Var->getType();
 if (Type->isSamplerT() || Type->isVoidType())
@@ -7859,6 +7861,7 @@
 if (NewVD->isFileVarDecl() || NewVD->isStaticLocal() ||
 NewVD->hasExternalStorage()) {
   if (!T->isSamplerT() &&
+  !T->isDependentType() &&
   !(T.getAddressSpace() == LangAS::opencl_constant ||
 (T.getAddressSpace() == LangAS::opencl_global &&
  (getLangOpts().OpenCLVersion == 200 ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83536: [clangd] Index refs to main-file symbols as well

2020-07-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D83536#2144282 , @nridge wrote:

> I can do that.
>
> Another thing we could consider, if the space increase is a concern, is to 
> limit which references we store, e.g. to functions only (not variables or 
> classes).


Yes, that's an option too, but I think putting it behind a flag is the safest 
for now, as we are cutting close to 11 release.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83536



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


[PATCH] D83660: [analyzer] Fix a crash for dereferencing an empty llvm::Optional variable in SMTConstraintManager.h.

2020-07-13 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie created this revision.
OikawaKirie added reviewers: NoQ, dcoughlin.
OikawaKirie added a project: clang.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.

The first crash reported in the bug report 44338 
.

> Condition `!isSat.hasValue() || isNotSat.getValue()` here should be 
> `!isNotSat.hasValue() || isNotSat.getValue()`.
>  `getValue` here crashed when we used the static analyzer to analyze 
> postgresql-12.0.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83660

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h


Index: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -147,7 +147,7 @@
   Solver->addConstraint(NotExp);
 
   Optional isNotSat = Solver->check();
-  if (!isSat.hasValue() || isNotSat.getValue())
+  if (!isNotSat.hasValue() || isNotSat.getValue())
 return nullptr;
 
   // This is the only solution, store it


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -147,7 +147,7 @@
   Solver->addConstraint(NotExp);
 
   Optional isNotSat = Solver->check();
-  if (!isSat.hasValue() || isNotSat.getValue())
+  if (!isNotSat.hasValue() || isNotSat.getValue())
 return nullptr;
 
   // This is the only solution, store it
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83295: [Analyzer] Hotfix for various crashes in iterator checkers

2020-07-13 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 277340.
baloghadamsoftware edited the summary of this revision.
baloghadamsoftware added a comment.

Two more crashes detected, fixes for them added.


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

https://reviews.llvm.org/D83295

Files:
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
  clang/test/Analysis/iterator-modeling.cpp
  clang/test/Analysis/iterator-range.cpp

Index: clang/test/Analysis/iterator-range.cpp
===
--- clang/test/Analysis/iterator-range.cpp
+++ clang/test/Analysis/iterator-range.cpp
@@ -935,3 +935,7 @@
   // expected-note@-1{{Iterator decremented ahead of its valid range}}
 }
 
+void ptr_iter_diff(cont_with_ptr_iterator ) {
+  auto i0 = c.begin(), i1 = c.end();
+  ptrdiff_t len = i1 - i0; // no-crash
+}
Index: clang/test/Analysis/iterator-modeling.cpp
===
--- clang/test/Analysis/iterator-modeling.cpp
+++ clang/test/Analysis/iterator-modeling.cpp
@@ -1948,6 +1948,13 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.end() - 2}}
 }
 
+void minus_equal_ptr_iterator_variable(const cont_with_ptr_iterator ,
+   int n) {
+  auto i = c.end();
+
+  i -= n; // no-crash
+}
+
 void plus_ptr_iterator(const cont_with_ptr_iterator ) {
   auto i1 = c.begin();
 
@@ -1972,6 +1979,17 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$c.end() - 2}}
 }
 
+void ptr_iter_diff(cont_with_ptr_iterator ) {
+  auto i0 = c.begin(), i1 = c.end();
+  ptrdiff_t len = i1 - i0; // no-crash
+}
+
+void ptr_iter_cmp_nullptr(cont_with_ptr_iterator ) {
+  auto i0 = c.begin();
+  if (i0 != nullptr) // no-crash
+++i0;
+}
+
 void clang_analyzer_printState();
 
 void print_state(std::vector ) {
Index: clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
@@ -169,6 +169,8 @@
 verifyDereference(C, LVal);
   } else if (isRandomIncrOrDecrOperator(OK)) {
 SVal RVal = State->getSVal(BO->getRHS(), C.getLocationContext());
+if (!BO->getRHS()->getType()->isIntegralOrEnumerationType())
+  return;
 verifyRandomIncrOrDecr(C, BinaryOperator::getOverloadedOperator(OK), LVal,
RVal);
   }
Index: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
@@ -272,6 +272,8 @@
 handleComparison(C, BO, Result, LVal, RVal,
  BinaryOperator::getOverloadedOperator(OK));
   } else if (isRandomIncrOrDecrOperator(OK)) {
+if (!BO->getRHS()->getType()->isIntegralOrEnumerationType())
+  return;
 handlePtrIncrOrDecr(C, BO->getLHS(),
 BinaryOperator::getOverloadedOperator(OK), RVal);
   }
@@ -461,6 +463,12 @@
 RPos = getIteratorPosition(State, RVal);
   }
 
+  // If the value for which we just tried to set a new iterator position is
+  // an `SVal`for which no iterator position can be set then the setting was
+  // unsuccessful. We cannot handle the comparison in this case.
+  if (!LPos || !RPos)
+return;
+
   // We cannot make assumptions on `UnknownVal`. Let us conjure a symbol
   // instead.
   if (RetVal.isUnknown()) {
@@ -615,10 +623,8 @@
   if (OK == OO_Plus || OK == OO_PlusEqual)
 NewVal = State->getLValue(ElementType, Offset, OldVal);
   else {
-const llvm::APSInt  =
-  Offset.castAs().getValue();
-auto  = C.getSymbolManager().getBasicVals();
-SVal NegatedOffset = nonloc::ConcreteInt(BVF.getValue(-OffsetInt));
+auto  = C.getSValBuilder();
+SVal NegatedOffset = SVB.evalMinus(Offset.castAs());
 NewVal = State->getLValue(ElementType, NegatedOffset, OldVal);
   }
 
@@ -684,9 +690,14 @@
 
   const auto StateBefore = N->getState();
   const auto *PosBefore = getIteratorPosition(StateBefore, Iter);
-
-  assert(PosBefore && "`std::advance() should not create new iterator "
- "position but change existing ones");
+  // FIXME: `std::advance()` should not create a new iterator position but
+  //change existing ones. However, in case of iterators implemented as
+  //pointers the handling of parameters in `std::advance()`-like
+  //functions is still incomplete which may result in cases where
+  //the new position is assigned to the wrong pointer. This causes
+  //crash if we use an assertion here.
+  if (!PosBefore)
+return false;
 
   return PosBefore->getOffset() == PosAfter->getOffset();
 }

[PATCH] D83621: [clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json

2020-07-13 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added a comment.

In D83621#2146746 , @klimek wrote:

> IIRC the symlink checking was there because some part of the system on linux 
> tends to give us realpaths (with CMake builds), and that leads to not finding 
> anything if there are symlinks involved.


That was before `InterpolatingCompilationDatabase` introduction in 
https://reviews.llvm.org/D45006.
For my experience `InterpolatingCompilationDatabase` works pretty well for 
symlinks cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83621



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


[clang] 1d3d9c7 - [clang] Include type specifiers in typo correction when checking isCXXDeclarationSpecifiers.

2020-07-13 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-07-13T12:05:09+02:00
New Revision: 1d3d9c7b589e6471edc0d8a2272c399d2ce6a13c

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

LOG: [clang] Include type specifiers in typo correction when checking 
isCXXDeclarationSpecifiers.

- add more tests (the test added in 
https://github.com/llvm/llvm-project/commit/2f448467e4254ddc3191136c968e6054bc009b88
 is weak);
- improve the `MyTemplate();` case, with this patch, typo 
correction
  suggests the type decl, and no regressions found.

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

Added: 


Modified: 
clang/lib/Parse/ParseTentative.cpp
clang/test/Parser/cxx-template-decl.cpp
clang/test/SemaCXX/typo-correction.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseTentative.cpp 
b/clang/lib/Parse/ParseTentative.cpp
index 948162c11b3f..f026f3a1bfb2 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1110,8 +1110,9 @@ class TentativeParseCCC final : public 
CorrectionCandidateCallback {
 public:
   TentativeParseCCC(const Token ) {
 WantRemainingKeywords = false;
-WantTypeSpecifiers = Next.isOneOf(tok::l_paren, tok::r_paren, tok::greater,
-  tok::l_brace, tok::identifier);
+WantTypeSpecifiers =
+Next.isOneOf(tok::l_paren, tok::r_paren, tok::greater, tok::l_brace,
+ tok::identifier, tok::comma);
   }
 
   bool ValidateCandidate(const TypoCorrection ) override {

diff  --git a/clang/test/Parser/cxx-template-decl.cpp 
b/clang/test/Parser/cxx-template-decl.cpp
index 24cc13cde91f..64e7ca921f57 100644
--- a/clang/test/Parser/cxx-template-decl.cpp
+++ b/clang/test/Parser/cxx-template-decl.cpp
@@ -286,17 +286,3 @@ namespace PR45239 {
   template int b;
   template auto f() -> b<0>; // expected-error +{{}}
 }
-
-namespace NoCrashOnNullNNSTypoCorrection {
-
-int AddObservation(); // expected-note {{declared here}}
-
-template  // expected-note {{template parameter 
is declared here}}
-class UsingImpl {};
-class AddObservation {
-  using Using =
-UsingImpl; // expected-error {{use of 
undeclared identifier 'AddObservationFn'; did you mean}} \
-   expected-error {{template 
argument for template type parameter must be a type}}
-};
-
-}

diff  --git a/clang/test/SemaCXX/typo-correction.cpp 
b/clang/test/SemaCXX/typo-correction.cpp
index 92a145074e72..e0325b3ba09b 100644
--- a/clang/test/SemaCXX/typo-correction.cpp
+++ b/clang/test/SemaCXX/typo-correction.cpp
@@ -611,6 +611,41 @@ int bar() {
 }
 }
 
+namespace testIncludeTypeInTemplateArgument {
+template 
+void foo(T t = {}, U = {}); // expected-note {{candidate template ignored}}
+
+class AddObservation {}; // expected-note {{declared here}}
+int bar1() {
+  // should resolve to a class.
+  foo(); // expected-error {{unknown type name 
'AddObservationFn'; did you mean 'AddObservation'?}}
+
+  // should not resolve to a class.
+  foo(AddObservationFn, 1);// expected-error-re {{use of undeclared 
identifier 'AddObservationFn'{{$
+  int a = AddObservationFn, b; // expected-error-re {{use of undeclared 
identifier 'AddObservationFn'{{$
+
+  int AddObservation; // expected-note 3{{declared here}}
+  // should resolve to a local variable.
+  foo(AddObservationFn, 1);// expected-error {{use of undeclared 
identifier 'AddObservationFn'; did you mean}}
+  int c = AddObservationFn, d; // expected-error {{use of undeclared 
identifier 'AddObservationFn'; did you mean}}
+
+  // FIXME: would be nice to not resolve to a variable.
+  foo(); // expected-error {{use of undeclared 
identifier 'AddObservationFn'; did you mean}} \
+   expected-error {{no matching function for 
call}}
+}
+} // namespace testIncludeTypeInTemplateArgument
+
+namespace testNoCrashOnNullNNSTypoCorrection {
+int AddObservation();
+template 
+class UsingImpl {};
+class AddObservation { // expected-note {{declared here}}
+  using Using =
+  // should resolve to a class.
+  UsingImpl; // expected-error {{unknown type 
name 'AddObservationFn'; did you mean}}
+};
+} // namespace testNoCrashOnNullNNSTypoCorrection
+
 namespace testNonStaticMemberHandling {
 struct Foo {
   bool usesMetadata;  // expected-note {{'usesMetadata' declared here}}



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


[PATCH] D83025: [clang] Include type specifiers in typo correction when checking isCXXDeclarationSpecifiers.

2020-07-13 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d3d9c7b589e: [clang] Include type specifiers in typo 
correction when checking… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83025

Files:
  clang/lib/Parse/ParseTentative.cpp
  clang/test/Parser/cxx-template-decl.cpp
  clang/test/SemaCXX/typo-correction.cpp


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -611,6 +611,41 @@
 }
 }
 
+namespace testIncludeTypeInTemplateArgument {
+template 
+void foo(T t = {}, U = {}); // expected-note {{candidate template ignored}}
+
+class AddObservation {}; // expected-note {{declared here}}
+int bar1() {
+  // should resolve to a class.
+  foo(); // expected-error {{unknown type name 
'AddObservationFn'; did you mean 'AddObservation'?}}
+
+  // should not resolve to a class.
+  foo(AddObservationFn, 1);// expected-error-re {{use of undeclared 
identifier 'AddObservationFn'{{$
+  int a = AddObservationFn, b; // expected-error-re {{use of undeclared 
identifier 'AddObservationFn'{{$
+
+  int AddObservation; // expected-note 3{{declared here}}
+  // should resolve to a local variable.
+  foo(AddObservationFn, 1);// expected-error {{use of undeclared 
identifier 'AddObservationFn'; did you mean}}
+  int c = AddObservationFn, d; // expected-error {{use of undeclared 
identifier 'AddObservationFn'; did you mean}}
+
+  // FIXME: would be nice to not resolve to a variable.
+  foo(); // expected-error {{use of undeclared 
identifier 'AddObservationFn'; did you mean}} \
+   expected-error {{no matching function for 
call}}
+}
+} // namespace testIncludeTypeInTemplateArgument
+
+namespace testNoCrashOnNullNNSTypoCorrection {
+int AddObservation();
+template 
+class UsingImpl {};
+class AddObservation { // expected-note {{declared here}}
+  using Using =
+  // should resolve to a class.
+  UsingImpl; // expected-error {{unknown type 
name 'AddObservationFn'; did you mean}}
+};
+} // namespace testNoCrashOnNullNNSTypoCorrection
+
 namespace testNonStaticMemberHandling {
 struct Foo {
   bool usesMetadata;  // expected-note {{'usesMetadata' declared here}}
Index: clang/test/Parser/cxx-template-decl.cpp
===
--- clang/test/Parser/cxx-template-decl.cpp
+++ clang/test/Parser/cxx-template-decl.cpp
@@ -286,17 +286,3 @@
   template int b;
   template auto f() -> b<0>; // expected-error +{{}}
 }
-
-namespace NoCrashOnNullNNSTypoCorrection {
-
-int AddObservation(); // expected-note {{declared here}}
-
-template  // expected-note {{template parameter 
is declared here}}
-class UsingImpl {};
-class AddObservation {
-  using Using =
-UsingImpl; // expected-error {{use of 
undeclared identifier 'AddObservationFn'; did you mean}} \
-   expected-error {{template 
argument for template type parameter must be a type}}
-};
-
-}
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -1110,8 +1110,9 @@
 public:
   TentativeParseCCC(const Token ) {
 WantRemainingKeywords = false;
-WantTypeSpecifiers = Next.isOneOf(tok::l_paren, tok::r_paren, tok::greater,
-  tok::l_brace, tok::identifier);
+WantTypeSpecifiers =
+Next.isOneOf(tok::l_paren, tok::r_paren, tok::greater, tok::l_brace,
+ tok::identifier, tok::comma);
   }
 
   bool ValidateCandidate(const TypoCorrection ) override {


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -611,6 +611,41 @@
 }
 }
 
+namespace testIncludeTypeInTemplateArgument {
+template 
+void foo(T t = {}, U = {}); // expected-note {{candidate template ignored}}
+
+class AddObservation {}; // expected-note {{declared here}}
+int bar1() {
+  // should resolve to a class.
+  foo(); // expected-error {{unknown type name 'AddObservationFn'; did you mean 'AddObservation'?}}
+
+  // should not resolve to a class.
+  foo(AddObservationFn, 1);// expected-error-re {{use of undeclared identifier 'AddObservationFn'{{$
+  int a = AddObservationFn, b; // expected-error-re {{use of undeclared identifier 'AddObservationFn'{{$
+
+  int AddObservation; // expected-note 3{{declared here}}
+  // should resolve to a local variable.
+  foo(AddObservationFn, 1);// expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}}
+  int c = AddObservationFn, d; // expected-error {{use of 

[PATCH] D83501: [clangd][ObjC] Improve xrefs for protocols and classes

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D83501#2144283 , @dgoldman wrote:

> Looking further into the indexing support, I've questions:
>
> - How `targetDecl` should behave for these objc container types


(Hmm, targetDecl doesn't seem to canonicalize decls anywhere, which might be a 
bug, but it's unrelated to objc)

The main thing is that AIUI @implementation is one thing, as far as clang's 
concerned, while @class+@interface are another.
i.e. getCanonicalDecl() and USR generation both split them into equivalence 
classes {@implementation} and {@class, @interface}. Is that right?

In that case the thing targetDecl needs to do is "jump" from the implementation 
to the interface, because we're pretending they're the same decl.
It doesn't need to jump from the @class to the @interface, semantic 
canonicalization doesn't belong there. (In fact it may need to do the opposite, 
since targetDecl might be relying on implicitly canonicalizing with clang's 
semantics).

> - Similarly for SymbolCollector (guessing in 
> `SymbolCollector::handleDeclOccurrence` ?)

Right - this is where most of the real canonicalization happens.
You need to ensure that:

- isPreferred is true for @interface, so that when we see both @class and 
@interface we'll take the latter as our preferred declaration
- addDefinition gets called for @implementation, so that the definition 
location is set correctly. Also the SymbolID used in this case must be based on 
the USR of the interface, so we're considering them a single symbol. (Either 
addDeclaration should not be called in this case, or it should be called with 
the @implementation again somehow).

I think that should be enough...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83501



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


[PATCH] D83296: [clang-format] Add a MacroExpander.

2020-07-13 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In D83296#2146970 , @sammccall wrote:

> In D83296#2146870 , @klimek wrote:
>
> > Monday-morning ping.
>
>
> Thanks for the reminder here... however this is taking me a bit to get my 
> head around, and we've got a release branch cut scheduled for a couple of 
> days that we're trying to polish for.
>  AFAICT there's significant followup work still needed to make use of this - 
> are you wanting this to land in the 11 release? Else i'd probably come back 
> to this after the cut...


Sorry, this is not urgent - the 11 cut has clear priority. My default is to 
ping stuff every week unless somebody tells me they prefer me not doing that :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83296



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


[PATCH] D83648: [Driver] Fix integrated_as definition by setting it as a DriverOption

2020-07-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Created http://lists.llvm.org/pipermail/cfe-dev/2020-July/066245.html [cfe-dev] 
Usage of clang::driver::options::DriverOption (-Xarch_ & gcc toolchain)
to ask about the use case.

When I get time, I'll work on a patch fixing the whole class of options instead 
of just -fintegrated-as. I will call the class `GCCLinkOption`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83648



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


[PATCH] D83055: [clang][Driver] Fix tool path priority test failures

2020-07-13 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett marked 2 inline comments as done.
DavidSpickett added inline comments.



Comment at: clang/test/Driver/program-path-priority.c:117
+/// Check file exists first in case $DEFAULT_TRIPLE == %target_triple
+// RUN: file -E %t/$DEFAULT_TRIPLE-gcc 2>&1 > /dev/null && \
+// RUN:   mv %t/$DEFAULT_TRIPLE-gcc  %t/prefix || true

stevewan wrote:
> DavidSpickett wrote:
> > stevewan wrote:
> > > Maybe I'm not seeing something obvious here, but I'm not aware of the 
> > > `file -E` usage, and on Linux I got `file: invalid option -- 'E'`.
> > I was looking for a way to mimic [! -f ], which worked on the command 
> > line but not in a test. From my system's file:
> > -E  On filesystem errors (file not found etc), instead of handling 
> > the error as regu‐
> >  lar output as POSIX mandates and keep going, issue an error 
> > message and exit.
> > 
> > I didn't realise it was non-standard, so I've switched to mv || true with 
> > the error redirected so it won't confuse the verbose output.
> I believe having just `mv || true` works, but I did like the idea of 
> pre-checking for the existence of the file, and the test is more robust with 
> the check. Is there a reason we wouldn't use `test -f` here?
Honestly it slipped my mind that  [ ] was the same as test. Updated to test && 
move || true which you're right is clearer.
(one will always fail if the two triples are the same but at least we're only 
hiding the error we expect, rather than all errors mv could have)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83055



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


[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-13 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes added a comment.

FYI InstSimplify doing distribution of undef is a known bug: 
https://bugs.llvm.org/show_bug.cgi?id=33165


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[PATCH] D82356: Fix bad doxygen result for class clang::ento::CallEvent and its derived classes

2020-07-13 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe124062bf387: Fix bad doxygen result for class 
clang::ento::CallEvent and its derived classes (authored by OikawaKirie, 
committed by vsavchenko).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82356

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -554,7 +554,7 @@
 
 /// Represents a call to a block.
 ///
-/// Example: ^{ /* ... */ }()
+/// Example: ^{ statement-body }()
 class BlockCall : public CallEvent {
   friend class CallEventManager;
 


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -554,7 +554,7 @@
 
 /// Represents a call to a block.
 ///
-/// Example: ^{ /* ... */ }()
+/// Example: ^{ statement-body }()
 class BlockCall : public CallEvent {
   friend class CallEventManager;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e124062 - Fix bad doxygen result for class clang::ento::CallEvent and its derived classes

2020-07-13 Thread Valeriy Savchenko via cfe-commits

Author: Ella Ma
Date: 2020-07-13T12:25:26+03:00
New Revision: e124062bf3874e1ce7ddad407b35e95ec3d3ac13

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

LOG: Fix bad doxygen result for class clang::ento::CallEvent and its derived 
classes

Summary: Fix bug https://bugs.llvm.org/show_bug.cgi?id=44753. This
patch is a workaround of a Doxygen bug, so that it can correctly
generate documents for class clang::ento::CallEvent and its derived
classes.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index d75f9f63286d..a2a98c558a4b 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -554,7 +554,7 @@ class SimpleFunctionCall : public AnyFunctionCall {
 
 /// Represents a call to a block.
 ///
-/// Example: ^{ /* ... */ }()
+/// Example: ^{ statement-body }()
 class BlockCall : public CallEvent {
   friend class CallEventManager;
 



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


[PATCH] D83296: [clang-format] Add a MacroExpander.

2020-07-13 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Monday-morning ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83296



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


[PATCH] D82436: [clangd] Implement textDocument/foldingRange

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp:205
+
+TEST(SemanticSelection, FoldingRanges) {
+  const char *Tests[] = {

nit, the test is usually named after the API/feature, so this should be 
TEST(FoldingRanges, All) or so


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82436



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


[PATCH] D83668: [clangd] Fix DocumentSymbol ranges

2020-07-13 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay, ilya-biryukov.
Herald added a project: clang.

DocumentSymbol ranges were not previously tested and, as a result, had invalid
end location. This patch addresses the issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83668

Files:
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -35,7 +35,7 @@
 }
 MATCHER_P(WithName, N, "") { return arg.name == N; }
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
-MATCHER_P(SymRange, Range, "") { return arg.location.range == Range; }
+MATCHER_P(SymRange, Range, "") { return arg.range == Range; }
 
 // GMock helpers for matching DocumentSymbol.
 MATCHER_P(SymNameRange, Range, "") { return arg.selectionRange == Range; }
@@ -712,6 +712,72 @@
WithName("Foo_type::method3")));
 }
 
+TEST(DocumentSymbolsTest, Ranges) {
+  TestTU TU;
+  Annotations Main(R"(
+  $foo[[int foo(bool Argument) {
+return 42;
+  }]]
+
+  char $variable[[GLOBAL_VARIABLE]];
+
+  $ns[[namespace ns {
+  $bar[[class Bar {
+  public:
+$ctor[[Bar() {}]]
+$dtor[[~Bar()]];
+
+  private:
+unsigned $field[[Baz]];
+
+$getbaz[[unsigned getBaz() { return Baz; }]]
+  }]];
+  }]] // namespace ns
+
+  $forwardclass[[class ForwardClassDecl]];
+
+  $struct[[struct StructDefinition {
+int *$structfield[[Pointer]];
+  }]];
+  $forwardstruct[[struct StructDeclaration]];
+
+  $forwardfunc[[void forwardFunctionDecl(int Something)]];
+)");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  UnorderedElementsAre(
+  AllOf(WithName("foo"), WithKind(SymbolKind::Function),
+SymRange(Main.range("foo"))),
+  AllOf(WithName("GLOBAL_VARIABLE"), WithKind(SymbolKind::Variable),
+SymRange(Main.range("variable"))),
+  AllOf(
+  WithName("ns"), WithKind(SymbolKind::Namespace),
+  SymRange(Main.range("ns")),
+  Children(AllOf(
+  WithName("Bar"), WithKind(SymbolKind::Class),
+  SymRange(Main.range("bar")),
+  Children(
+  AllOf(WithName("Bar"), WithKind(SymbolKind::Constructor),
+SymRange(Main.range("ctor"))),
+  AllOf(WithName("~Bar"), WithKind(SymbolKind::Constructor),
+SymRange(Main.range("dtor"))),
+  AllOf(WithName("Baz"), WithKind(SymbolKind::Field),
+SymRange(Main.range("field"))),
+  AllOf(WithName("getBaz"), WithKind(SymbolKind::Method),
+SymRange(Main.range("getbaz"))),
+  AllOf(WithName("ForwardClassDecl"), WithKind(SymbolKind::Class),
+SymRange(Main.range("forwardclass"))),
+  AllOf(WithName("StructDefinition"), WithKind(SymbolKind::Struct),
+SymRange(Main.range("struct")),
+Children(AllOf(WithName("Pointer"), WithKind(SymbolKind::Field),
+   SymRange(Main.range("structfield"),
+  AllOf(WithName("StructDeclaration"), WithKind(SymbolKind::Struct),
+SymRange(Main.range("forwardstruct"))),
+  AllOf(WithName("forwardFunctionDecl"), WithKind(SymbolKind::Function),
+SymRange(Main.range("forwardfunc");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/FindSymbols.cpp
===
--- clang-tools-extra/clangd/FindSymbols.cpp
+++ clang-tools-extra/clangd/FindSymbols.cpp
@@ -162,8 +162,20 @@
   SI.name = printName(Ctx, ND);
   SI.kind = SK;
   SI.deprecated = ND.isDeprecated();
-  SI.range =
-  Range{sourceLocToPosition(SM, BeginLoc), sourceLocToPosition(SM, EndLoc)};
+  if (SK == SymbolKind::Class || SK == SymbolKind::Struct ||
+  SK == SymbolKind::Function || SK == SymbolKind::Method ||
+  SK == SymbolKind::Constructor || SK == SymbolKind::Enum ||
+  SK == SymbolKind::Operator || SK == SymbolKind::Namespace) {
+const auto HalfOpenRange =
+toHalfOpenFileRange(SM, Ctx.getLangOpts(), {BeginLoc, EndLoc});
+if (!HalfOpenRange)
+  return llvm::None;
+SI.range = Range{sourceLocToPosition(SM, HalfOpenRange->getBegin()),
+ sourceLocToPosition(SM, HalfOpenRange->getEnd())};
+  } else {
+SI.range = Range{sourceLocToPosition(SM, BeginLoc),
+  

[PATCH] D83213: [clang][RecoveryExpr] Clarify the dependence-bits documentation.

2020-07-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/AST/ComputeDependence.cpp:502
+  // dependent type), or the type is known and dependent, or it has
+  // type-dependent subexpressions
   auto D = toExprDependence(E->getType()->getDependence()) |

sammccall wrote:
> hmm, I'd missed the type-dependent subexpressions question.
> If there are type-dependent subexpressions, but a non-dependent type was 
> specified for the RecoveryExpr, is the expr type-dependent?
> 
> This is the part that I think we have discretion over.
> The definition of type-dependent does say "any type-dependent subexpression" 
> but then lays out a list of exceptions such as casts, which are not 
> type-dependent even if their argument is. What these have in common is that 
> the type is known.
> 
> So I think this comes down to whether it's the caller's job to work this out, 
> or we want to conservatively call these expressions dependent.
> 
> I think the former is probably better - marking the expression as 
> type-dependent but not having its actual type be dependent doesn't serve any 
> purpose I'm aware of. It's also inconsistent with the informal definition of 
> type-dependence described earlier in this patch.
> 
> So the comment should describe the current state, but maybe a FIXME to remove 
> the type-dependent subexpressions clause?
yeah, I think we should respect to actual type of RecoveryExpr, added a fixme.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83213



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


[PATCH] D83621: [clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json

2020-07-13 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a subscriber: djasper.
klimek added a comment.

@djasper wrote this iirc, but I doubt he'll have much time to look into this :)

IIRC the symlink checking was there because some part of the system on linux 
tends to give us realpaths (with CMake builds), and that leads to not finding 
anything if there are symlinks involved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83621



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


[PATCH] D82436: [clangd] Implement textDocument/foldingRange

2020-07-13 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 277357.
kbobyrev marked 4 inline comments as done.
kbobyrev added a comment.

Add tests and fix DocumentSymbol ranges.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82436

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang-tools-extra/clangd/SemanticSelection.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -17,15 +17,19 @@
 #include "TestTU.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+
 namespace clang {
 namespace clangd {
 namespace {
+
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
+using ::testing::UnorderedElementsAreArray;
 
 // front() is SR.range, back() is outermost range.
 std::vector gatherRanges(const SelectionRange ) {
@@ -35,6 +39,23 @@
   return Ranges;
 }
 
+// front() is SR.range, back() is outermost range.
+std::vector
+gatherFoldingRanges(llvm::ArrayRef FoldingRanges) {
+  std::vector Ranges;
+  Range NextRange;
+  for (const auto  : FoldingRanges) {
+NextRange.start.line = R.startLine;
+EXPECT_TRUE(R.startCharacter);
+NextRange.start.character = *R.startCharacter;
+NextRange.end.line = R.endLine;
+EXPECT_TRUE(R.endCharacter);
+NextRange.end.character = *R.endCharacter;
+Ranges.push_back(NextRange);
+  }
+  return Ranges;
+}
+
 TEST(SemanticSelection, All) {
   const char *Tests[] = {
   R"cpp( // Single statement in a function body.
@@ -118,16 +139,16 @@
   )cpp",
   R"cpp( // Inside struct.
 struct A { static int a(); };
-[[struct B { 
+[[struct B {
   [[static int b() [[{
 [[return 1^1]] + 2;
   }
 }]];
   )cpp",
   // Namespaces.
-  R"cpp( 
-[[namespace nsa { 
-  [[namespace nsb { 
+  R"cpp(
+[[namespace nsa {
+  [[namespace nsb {
 static int ccc();
 [[void func() [[{
   // int x = nsa::nsb::ccc();
@@ -181,6 +202,41 @@
   EXPECT_THAT(gatherRanges(Ranges->back()),
   ElementsAre(SourceAnnotations.range("empty")));
 }
+
+TEST(SemanticSelection, FoldingRanges) {
+  const char *Tests[] = {
+  R"cpp(
+int [[global_variable]];
+
+[[void func() {
+  int v = 100;
+}]]
+  )cpp",
+  R"cpp(
+[[class Foo {
+public:
+  [[Foo() {
+int X = 1;
+  }]]
+
+private:
+  [[int getBar() {
+return 42;
+  }]]
+
+  [[void getFooBar() { }]]
+}]];
+  )cpp",
+  };
+  for (const char *Test : Tests) {
+auto T = Annotations(Test);
+auto AST = TestTU::withCode(T.code()).build();
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(AST))),
+UnorderedElementsAreArray(T.ranges()))
+<< Test;
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -8,6 +8,7 @@
 #include "Annotations.h"
 #include "ClangdServer.h"
 #include "FindSymbols.h"
+#include "Protocol.h"
 #include "SyncAPI.h"
 #include "TestFS.h"
 #include "gmock/gmock.h"
@@ -33,7 +34,7 @@
 }
 MATCHER_P(WithName, N, "") { return arg.name == N; }
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
-MATCHER_P(SymRange, Range, "") { return arg.location.range == Range; }
+MATCHER_P(SymRange, Range, "") { return arg.range == Range; }
 
 // GMock helpers for matching DocumentSymbol.
 MATCHER_P(SymNameRange, Range, "") { return arg.selectionRange == Range; }
@@ -746,5 +747,71 @@
WithName("Foo_type::method3")));
 }
 
+TEST_F(DocumentSymbolsTest, Ranges) {
+  std::string FilePath = testPath("foo.cpp");
+  Annotations Main(R"(
+  $foo[[int foo(bool Argument) {
+return 42;
+  }]]
+
+  char $variable[[GLOBAL_VARIABLE]];
+
+  $ns[[namespace ns {
+  

[PATCH] D83213: [clang][RecoveryExpr] Clarify the dependence-bits documentation.

2020-07-13 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6ac9e589f869: [clang][RecoveryExpr] Clarify the 
dependence-bits documentation. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D83213?vs=277332=277358#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83213

Files:
  clang/include/clang/AST/DependenceFlags.h
  clang/include/clang/AST/Expr.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/Sema/SemaExpr.cpp

Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -19180,9 +19180,6 @@
 
 ExprResult Sema::CreateRecoveryExpr(SourceLocation Begin, SourceLocation End,
 ArrayRef SubExprs, QualType T) {
-  // FIXME: enable it for C++, RecoveryExpr is type-dependent to suppress
-  // bogus diagnostics and this trick does not work in C.
-  // FIXME: use containsErrors() to suppress unwanted diags in C.
   if (!Context.getLangOpts().RecoveryAST)
 return ExprError();
 
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -495,13 +495,16 @@
 }
 
 ExprDependence clang::computeDependence(RecoveryExpr *E) {
-  // Mark the expression as value- and instantiation- dependent to reuse
-  // existing suppressions for dependent code, e.g. avoiding
-  // constant-evaluation.
-  // FIXME: drop type+value+instantiation once Error is sufficient to suppress
-  // bogus dianostics.
+  // RecoveryExpr is
+  //   - always value-dependent, and therefore instantiation dependent
+  //   - contains errors (ExprDependence::Error), by definition
+  //   - type-dependent if we don't know the type (fallback to an opaque
+  // dependent type), or the type is known and dependent, or it has
+  // type-dependent subexpressions.
   auto D = toExprDependence(E->getType()->getDependence()) |
ExprDependence::ValueInstantiation | ExprDependence::Error;
+  // FIXME: remove the type-dependent bit from subexpressions, if the
+  // RecoveryExpr has a non-dependent type.
   for (auto *S : E->subExpressions())
 D |= S->getDependence();
   return D;
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -157,9 +157,11 @@
 return static_cast(ExprBits.Dependent);
   }
 
-  /// isValueDependent - Determines whether this expression is
-  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
-  /// array bound of "Chars" in the following example is
+  /// Determines whether the value of this expression depends on
+  ///   - a template parameter (C++ [temp.dep.constexpr])
+  ///   - or an error, whose resolution is unknown
+  ///
+  /// For example, the array bound of "Chars" in the following example is
   /// value-dependent.
   /// @code
   /// template struct meta_string;
@@ -168,10 +170,12 @@
 return static_cast(getDependence() & ExprDependence::Value);
   }
 
-  /// isTypeDependent - Determines whether this expression is
-  /// type-dependent (C++ [temp.dep.expr]), which means that its type
-  /// could change from one template instantiation to the next. For
-  /// example, the expressions "x" and "x + y" are type-dependent in
+  /// Determines whether the type of this expression depends on
+  ///   - a template paramter (C++ [temp.dep.expr], which means that its type
+  /// could change from one template instantiation to the next)
+  ///   - or an error
+  ///
+  /// For example, the expressions "x" and "x + y" are type-dependent in
   /// the following code, but "y" is not type-dependent:
   /// @code
   /// template
@@ -184,8 +188,10 @@
   }
 
   /// Whether this expression is instantiation-dependent, meaning that
-  /// it depends in some way on a template parameter, even if neither its type
-  /// nor (constant) value can change due to the template instantiation.
+  /// it depends in some way on
+  ///- a template parameter (even if neither its type nor (constant) value
+  ///  can change due to the template instantiation)
+  ///- or an error
   ///
   /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
   /// instantiation-dependent (since it involves a template parameter \c T), but
@@ -200,6 +206,12 @@
   /// }
   /// \endcode
   ///
+  /// \code
+  /// void func(int) {
+  ///   func(); // the expression is instantiation-dependent, because it depends
+  ///   // on an error.
+  /// }
+  /// \endcode
   bool isInstantiationDependent() const {
 return static_cast(getDependence() & ExprDependence::Instantiation);
   }
@@ -6212,19 +6224,25 @@
 /// subexpressions of some expression that we could not 

[clang] 6ac9e58 - [clang][RecoveryExpr] Clarify the dependence-bits documentation.

2020-07-13 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-07-13T11:32:32+02:00
New Revision: 6ac9e589f869b6a63c9966e7c7ec7cc8207cf2f2

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

LOG: [clang][RecoveryExpr] Clarify the dependence-bits documentation.

The expr dependent-bits described that the expression somehow
depends on a template paramter.

With RecoveryExpr, we have generalized it to "the expression depends on
a template parameter, or an error".  This patch updates/cleanups all related
comments of dependence-bits.

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

Added: 


Modified: 
clang/include/clang/AST/DependenceFlags.h
clang/include/clang/AST/Expr.h
clang/lib/AST/ComputeDependence.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DependenceFlags.h 
b/clang/include/clang/AST/DependenceFlags.h
index 3601cb90bb76..14a7ffaecb2b 100644
--- a/clang/include/clang/AST/DependenceFlags.h
+++ b/clang/include/clang/AST/DependenceFlags.h
@@ -16,8 +16,18 @@ namespace clang {
 struct ExprDependenceScope {
   enum ExprDependence : uint8_t {
 UnexpandedPack = 1,
+// This expr depends in any way on
+//   - a template parameter, it implies that the resolution of this expr 
may
+// cause instantiation to fail
+//   - or an error (often in a non-template context)
+//
+// Note that C++ standard doesn't define the instantiation-dependent term,
+// we follow the formal definition coming from the Itanium C++ ABI, and
+// extend it to errors.
 Instantiation = 2,
+// The type of this expr depends on a template parameter, or an error.
 Type = 4,
+// The value of this expr depends on a template parameter, or an error.
 Value = 8,
 
 // clang extension: this expr contains or references an error, and is
@@ -42,10 +52,14 @@ struct TypeDependenceScope {
 /// Whether this type contains an unexpanded parameter pack
 /// (for C++11 variadic templates)
 UnexpandedPack = 1,
-/// Whether this type somehow involves a template parameter, even
-/// if the resolution of the type does not depend on a template parameter.
+/// Whether this type somehow involves
+///   - a template parameter, even if the resolution of the type does not
+/// depend on a template parameter.
+///   - or an error.
 Instantiation = 2,
-/// Whether this type is a dependent type (C++ [temp.dep.type]).
+/// Whether this type
+///   - is a dependent type (C++ [temp.dep.type])
+///   - or it somehow involves an error, e.g. decltype(recovery-expr)
 Dependent = 4,
 /// Whether this type is a variably-modified type (C99 6.7.5).
 VariablyModified = 8,
@@ -95,16 +109,17 @@ class Dependence {
 
 // Contains a template parameter pack that wasn't expanded.
 UnexpandedPack = 1,
-// Uses a template parameter, even if it doesn't affect the result.
-// Validity depends on the template parameter.
+// Depends on a template parameter or an error in some way.
+// Validity depends on how the template is instantiated or the error is
+// resolved.
 Instantiation = 2,
-// Expression type depends on template context.
+// Expression type depends on template context, or an error.
 // Value and Instantiation should also be set.
 Type = 4,
-// Expression value depends on template context.
+// Expression value depends on template context, or an error.
 // Instantiation should also be set.
 Value = 8,
-// Depends on template context.
+// Depends on template context, or an error.
 // The type/value distinction is only meaningful for expressions.
 Dependent = Type | Value,
 // Includes an error, and depends on how it is resolved.

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 66eafaaab715..c13b97119285 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -157,9 +157,11 @@ class Expr : public ValueStmt {
 return static_cast(ExprBits.Dependent);
   }
 
-  /// isValueDependent - Determines whether this expression is
-  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
-  /// array bound of "Chars" in the following example is
+  /// Determines whether the value of this expression depends on
+  ///   - a template parameter (C++ [temp.dep.constexpr])
+  ///   - or an error, whose resolution is unknown
+  ///
+  /// For example, the array bound of "Chars" in the following example is
   /// value-dependent.
   /// @code
   /// template struct meta_string;
@@ -168,10 +170,12 @@ class Expr : public ValueStmt {
 return static_cast(getDependence() & ExprDependence::Value);
   }
 
-  /// isTypeDependent - Determines whether this expression is
-  

[PATCH] D83223: [clang-tidy] Header guard check can skip past license comment

2020-07-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

>   // This is not identified as a license comment as the
>   // block is followed by code.
>   void foo();

FWIW: 
https://github.com/GrammaTech/gtirb-pprinter/blob/master/include/gtirb_pprinter/AttPrettyPrinter.hpp
 or https://github.com/GrammaTech/gtirb/blob/master/include/gtirb/AuxData.hpp 
(so there are projects which do not put a newline between the license and code).




Comment at: clang-tools-extra/clang-tidy/ClangTidyCheck.h:48
   explicit MissingOptionError(std::string OptionName)
-  : OptionName(OptionName) {}
+  : OptionName(std::move(OptionName)) {}
 

It makes me sad how much we're having to sprinkle `std::move()` calls around (I 
find the calls to `move()` to be more distracting that declaring the parameter 
types to be `const std::string&`.) Were these found mechanically?



Comment at: clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp:313
 continue;
-
+  StringRef Opening = AddNewLine == NewLineInsertions::None ? "#ifndef "
+  : AddNewLine == NewLineInsertions::One

njames93 wrote:
> clang-format(trunk) says what I submitted was correct, clang-format-10 is 
> suggesting the change. Which do I trust??
Either is defensible, I'm fine with using what trunk says.



Comment at: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp:12
 
 // FIXME: It seems this might be incompatible to dos path. Investigating.
 #if !defined(_WIN32)

Unrelated to this patch, but neat to know that there is zero testing of this on 
Windows.



Comment at: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp:224
 }
+
+TEST(LLVMHeaderGuardCheckTest, FixHeaderGuardsWithComments) {

You seem to be missing tests that show the license and header guards are both 
correct and found no issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83223



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


[PATCH] D77150: [Analyzer] New Option for ContainerModeling: AggressiveEraseModeling

2020-07-13 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

There is a parallel discussion in this patch on how we should cater to user 
requests, I wrote a lengthy comment about my opinion, but I just don't think it 
adds much -- at the end of the day, it is fair that if we implement an feature 
for a small subset of users that is known to cause unpleasant side effects, we 
shouldn't make it a part of the default user interface, because among many 
other things it inevitably forces other contributors to maintain it, even if 
they weren't enthusiastic about the idea, but its also fair to prioritize 
direct users within reason.

Since this is in the same bullpark as D32905 , 
I think this should land in some way or another.

> (@baloghadamsoftware) So you both are saying that I should tell the user that 
> we cannot help, the community does not support that he catches this bug in 
> early phase with the analyzer. He must catch it in the testing phase for 
> higher costs. This is not the best way to build confidence in the analyzer. 
> [...]

Nobody said we cannot help. What I say, is that we should not task the broad 
analyzer community with the maintenance of an option that is known to make 
state splits that we might not be untitled to. In fact,

> (@NoQ) [...] But you guys basically vend your own tool to your own customers 
> and bear your own responsibility and i therefore can't tell you what to do in 
> your realm, and i'm ok with having options that allow you to disagree with my 
> choices.

I don't see how this option shouldn't be alpha -- it creates paths of execution 
that might be impossible. If I understand this correctly, we would emit a false 
positive here:

  std::vector V = get(); // constructs this const vector every time: { 1, 
2, 3 }
  auto i = V.erase(std::find(V.begin(), V.end(), 1)); // state split is creater 
where i is v.end()
  *i;

As of now, the only way to fine-tune the analyzer through CodeChecker (edit 
`saargs.txt`, add the flag `--saargs saargs.txt` or something like that) is a 
quite a jarring interface, and is also buggy (like this thing 
). Eventually, it would be 
great to make the `-analyzer-checker-option-help` list visible and easily 
configurable. I wonder however, if I was a newcomer to CodeChecker, what my 
reaction would be an option that says "Enables exploration of the past-the-end 
branch for the return value of the erase() method of containers". Like, why 
wouldn't I enable that? Lets say we add a disclaimer that it could emit false 
positives. Lets say I stumble across one. Am I supposed to create a bug report, 
or is this intended behavior? Not the mention that CodeChecker might not be the 
only tool to have plans to support `-analyzer-checker-option-help`.

To be honest, I probably shouldn't even see these options straight away. Since 
this option creates state splits we might not be entitled to, we need more 
testing and data to get to a point where we could safely put in the default 
interface -- these are literally the traits of what we call alpha 
checkers/options. Its just simply not finished, and no amount of documentation 
will change that. Once I have a better feel for how the analyzer behaves or I'm 
really stuck, I may wanna go and tick a few alpha stuff as a last resort. This 
is why we should categorize such option under a different flag.

But, as you said in D77150#inline-707863 
, there is value in these 
forsaken options after all. They have on occasion found real bugs that saved a 
lot of time, and we have gotten a lot of feedback on alpha checkers that also 
helped us fix a lot of issues. But those are still users that decided to opt-in 
to in-development features. In retrospect, D32905 
 should've been alpha for this very reason as 
well.


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

https://reviews.llvm.org/D77150



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


[PATCH] D82436: [clangd] Implement textDocument/foldingRange

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Nice, thanks!




Comment at: clang-tools-extra/clangd/Protocol.h:1523
+  unsigned startLine = 0;
+  llvm::Optional startCharacter;
+  unsigned endLine = 0;

for outgoing fields that are optional in the protocol but we always set, we 
tend to omit `Optional`. The protocol is worded in a way that suggests servers 
may continue to set the character fields even for line-oriented editors, and I 
think we should do this, dropping `Optional` here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82436



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


[PATCH] D83223: [clang-tidy] Header guard check can skip past license comment

2020-07-13 Thread Nathan James via Phabricator via cfe-commits
njames93 marked 2 inline comments as done.
njames93 added a comment.

In D83223#2147072 , @aaron.ballman 
wrote:

> >   // This is not identified as a license comment as the
> >   // block is followed by code.
> >   void foo();
>
> FWIW: 
> https://github.com/GrammaTech/gtirb-pprinter/blob/master/include/gtirb_pprinter/AttPrettyPrinter.hpp
>  or https://github.com/GrammaTech/gtirb/blob/master/include/gtirb/AuxData.hpp 
> (so there are projects which do not put a newline between the license and 
> code).


Short of creating an AI that understands context it won't be possible to 
determine the difference between license and general documentation, in any case 
I feel this heuristic is the safest way to ensure good coverage with minimised 
risk of inserting the guard in the middle of documentation,




Comment at: clang-tools-extra/clang-tidy/ClangTidyCheck.h:48
   explicit MissingOptionError(std::string OptionName)
-  : OptionName(OptionName) {}
+  : OptionName(std::move(OptionName)) {}
 

aaron.ballman wrote:
> It makes me sad how much we're having to sprinkle `std::move()` calls around 
> (I find the calls to `move()` to be more distracting that declaring the 
> parameter types to be `const std::string&`.) Were these found mechanically?
These are me screwing around with my branches and will be removed



Comment at: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp:224
 }
+
+TEST(LLVMHeaderGuardCheckTest, FixHeaderGuardsWithComments) {

aaron.ballman wrote:
> You seem to be missing tests that show the license and header guards are both 
> correct and found no issues.
That wouldn't be testing new behaviour added here. The check can already find 
header guards when there is a license, The code I have added only affects when 
no guard is found and it needs to add one.  I can still add those cases for 
piece of mind.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83223



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


[PATCH] D83551: [PATCH 2/4][Sema][AArch64] Add semantics for arm_sve_vector_bits attribute

2020-07-13 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1541
 
+def ArmSveVectorBits128 : TypeAttr {
+  let Spellings = [];

nit: Can you add a comment saying why these are undocumented (and have no 
spellings)



Comment at: clang/lib/AST/ASTContext.cpp:1872
 
+bool getSveVectorWidth(const Type *T, unsigned ) {
+  if (T->hasAttr(attr::ArmSveVectorBits128))

Should this function just return `unsigned` and error when it doesn't have any 
of the ArmSveVectorBits attributes?
i.e. if `isVLST()` returns true, then it is an error if it doesn't have any of 
the attributes handled below.



Comment at: clang/lib/AST/ASTContext.cpp:1897
+
+bool ASTContext::getArmSveVectorBits(const Type *T, unsigned ) const {
+  if (!T->isVLST())

nit: I find this name a bit misleading, because I would expect the 
(ARM_SVE_VECTOR_) bits to be the same regardless of the type. Maybe rename this 
to `getBitwidthForAttributedSveType` ?



Comment at: clang/lib/Sema/SemaType.cpp:7754
 /// the ACLE, such as svint32_t and svbool_t.
-static void HandleArmSveVectorBitsTypeAttr(QualType ,
-   const ParsedAttr , Sema ) {
+static void HandleArmSveVectorBitsTypeAttr(TypeProcessingState ,
+   QualType ,

Unrelated changes?



Comment at: clang/lib/Sema/SemaType.cpp:7839
+  default:
+llvm_unreachable("unsupported vector size!");
+  case 128:

If we only support power-of-two for now, we should only have an 
`llvm_unreachable` if we prevent parsing any of the other widths (and give an 
appropriate diagnostic saying those widths are not yet supported).



Comment at: clang/test/Sema/attr-arm-sve-vector-bits.c:45
+
+fixed_int8_t global_int8;
+fixed_bfloat16_t global_bfloat16;

nit: For the tests that you've added below, can you add more elaborate comments 
explaining what you're trying to test?
e.g. here I assume that sizeless globals are otherwise not allowed, but they 
are when attributed with arm_sve_vector_bits. It would be good to have that 
explained a bit.



Comment at: clang/test/Sema/attr-arm-sve-vector-bits.c:80
+  void *sel __attribute__((unused));
+  sel = c ? ss8 : fs8; // expected-error {{incompatible operand types 
('svint8_t' (aka '__SVInt8_t') and 'fixed_int8_t' (aka '__SVInt8_t'))}}
+  sel = c ? fs8 : ss8; // expected-error {{incompatible operand types 
('fixed_int8_t' (aka '__SVInt8_t') and 'svint8_t' (aka '__SVInt8_t'))}}

Is this diagnostic produced because of any code-changes in this patch?



Comment at: clang/test/Sema/attr-arm-sve-vector-bits.c:136
+
+struct struct_int8 { fixed_int8_t x, y[5]; };
+struct struct_int16 { fixed_int16_t x, y[5]; };

nit: Is it necessary to test this for all the types?



Comment at: clang/test/Sema/attr-arm-sve-vector-bits.c:206
+// --//
+// Test call
+

nit: s/Test call/Test the scalable and fixed-width annotated types can be used 
interchangeably/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83551



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


[clang] 7075c05 - [OPENMP]Fix compiler crash for target data directive without actual target codegen.

2020-07-13 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-07-13T10:52:24-04:00
New Revision: 7075c056e91bf95b111716a9722d10e1a61253bb

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

LOG: [OPENMP]Fix compiler crash for target data directive without actual target 
codegen.

Summary:
Need to privatize addresses of the captured variables when trying to
emit the body of the target data directive in no target codegen mode.

Reviewers: jdoerfert

Subscribers: yaxunl, guansong, cfe-commits, sstefan1, caomhin

Tags: #clang

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/target_data_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 7135135d2a41..cfd5eda8cc80 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -6077,6 +6077,7 @@ void CodeGenFunction::EmitOMPTargetDataDirective(
 (void)PrivateScope.Privatize();
 RCG(CGF);
   } else {
+OMPLexicalScope Scope(CGF, S, OMPD_unknown);
 RCG(CGF);
   }
 };

diff  --git a/clang/test/OpenMP/target_data_codegen.cpp 
b/clang/test/OpenMP/target_data_codegen.cpp
index f1c9f621bf74..f9257615ce40 100644
--- a/clang/test/OpenMP/target_data_codegen.cpp
+++ b/clang/test/OpenMP/target_data_codegen.cpp
@@ -491,4 +491,23 @@ void test_close_modifier(int arg) {
   {++arg;}
 }
 #endif
+///==///
+// RUN: %clang_cc1 -DCK7 -verify -fopenmp -x c++ -triple 
powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefix 
CK7 --check-prefix CK7-64
+// RUN: %clang_cc1 -DCK7 -fopenmp -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s  
--check-prefix CK7 --check-prefix CK7-64
+
+// RUN: %clang_cc1 -DCK7 -verify -fopenmp-simd -x c++ -triple 
powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix 
SIMD-ONLY7 %s
+// RUN: %clang_cc1 -DCK7 -fopenmp-simd -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
--check-prefix SIMD-ONLY7 %s
+// SIMD-ONLY7-NOT: {{__kmpc|__tgt}}
+#ifdef CK7
+// CK7: test_device_ptr_addr
+void test_device_ptr_addr(int arg) {
+  int *p;
+  // CK7: add nsw i32
+  // CK7: add nsw i32
+  #pragma omp target data use_device_ptr(p) use_device_addr(arg)
+  { ++arg, ++(*p); }
+}
+#endif
 #endif



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


[PATCH] D83478: [OPENMP]Fix compiler crash for target data directive without actual target codegen.

2020-07-13 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7075c056e91b: [OPENMP]Fix compiler crash for target data 
directive without actual target… (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83478

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/target_data_codegen.cpp


Index: clang/test/OpenMP/target_data_codegen.cpp
===
--- clang/test/OpenMP/target_data_codegen.cpp
+++ clang/test/OpenMP/target_data_codegen.cpp
@@ -491,4 +491,23 @@
   {++arg;}
 }
 #endif
+///==///
+// RUN: %clang_cc1 -DCK7 -verify -fopenmp -x c++ -triple 
powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefix 
CK7 --check-prefix CK7-64
+// RUN: %clang_cc1 -DCK7 -fopenmp -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s  
--check-prefix CK7 --check-prefix CK7-64
+
+// RUN: %clang_cc1 -DCK7 -verify -fopenmp-simd -x c++ -triple 
powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix 
SIMD-ONLY7 %s
+// RUN: %clang_cc1 -DCK7 -fopenmp-simd -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
--check-prefix SIMD-ONLY7 %s
+// SIMD-ONLY7-NOT: {{__kmpc|__tgt}}
+#ifdef CK7
+// CK7: test_device_ptr_addr
+void test_device_ptr_addr(int arg) {
+  int *p;
+  // CK7: add nsw i32
+  // CK7: add nsw i32
+  #pragma omp target data use_device_ptr(p) use_device_addr(arg)
+  { ++arg, ++(*p); }
+}
+#endif
 #endif
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -6077,6 +6077,7 @@
 (void)PrivateScope.Privatize();
 RCG(CGF);
   } else {
+OMPLexicalScope Scope(CGF, S, OMPD_unknown);
 RCG(CGF);
   }
 };


Index: clang/test/OpenMP/target_data_codegen.cpp
===
--- clang/test/OpenMP/target_data_codegen.cpp
+++ clang/test/OpenMP/target_data_codegen.cpp
@@ -491,4 +491,23 @@
   {++arg;}
 }
 #endif
+///==///
+// RUN: %clang_cc1 -DCK7 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefix CK7 --check-prefix CK7-64
+// RUN: %clang_cc1 -DCK7 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s  --check-prefix CK7 --check-prefix CK7-64
+
+// RUN: %clang_cc1 -DCK7 -verify -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY7 %s
+// RUN: %clang_cc1 -DCK7 -fopenmp-simd -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY7 %s
+// SIMD-ONLY7-NOT: {{__kmpc|__tgt}}
+#ifdef CK7
+// CK7: test_device_ptr_addr
+void test_device_ptr_addr(int arg) {
+  int *p;
+  // CK7: add nsw i32
+  // CK7: add nsw i32
+  #pragma omp target data use_device_ptr(p) use_device_addr(arg)
+  { ++arg, ++(*p); }
+}
+#endif
 #endif
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -6077,6 +6077,7 @@
 (void)PrivateScope.Privatize();
 RCG(CGF);
   } else {
+OMPLexicalScope Scope(CGF, S, OMPD_unknown);
 RCG(CGF);
   }
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83398: [OPENMP50]Perform data mapping analysis only for explicitly mapped data.

2020-07-13 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 277446.
ABataev added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83398

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_map_messages.cpp


Index: clang/test/OpenMP/target_map_messages.cpp
===
--- clang/test/OpenMP/target_map_messages.cpp
+++ clang/test/OpenMP/target_map_messages.cpp
@@ -604,6 +604,7 @@
   const int ()[5] = da;
   SC1 s;
   SC1 *p;
+  int Arr[10];
 #pragma omp target data map // expected-error {{expected '(' after 'map'}} 
le45-error {{expected at least one 'map' or 'use_device_ptr' clause for 
'#pragma omp target data'}} le50-error {{expected at least one 'map', 
'use_device_ptr', or 'use_device_addr' clause for '#pragma omp target data'}}
 #pragma omp target data map( // expected-error {{expected ')'}} expected-note 
{{to match this '('}} expected-error {{expected expression}}
 #pragma omp target data map() // expected-error {{expected expression}}
@@ -750,6 +751,12 @@
 #pragma omp target map(iarr[:2:d]) // expected-error {{expected ']'}} 
expected-note {{to match this '['}}
   {}
 
+#pragma omp target data map(Arr[0:4]) // le45-note {{used here}}
+  {
+#pragma omp target
+Arr[0] = 2; // le45-error {{original storage of expression in data 
environment is shared but data environment do not fully contain mapped 
expression storage}}
+  }
+
   return tmain(argc)+tmain(argc); // expected-note {{in 
instantiation of function template specialization 'tmain' requested 
here}} expected-note {{in instantiation of function template specialization 
'tmain' requested here}}
 }
 #endif
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -17478,6 +17478,7 @@
   /*CurrentRegionOnly=*/true, CurComponents, CKind))
   break;
 if (CKind == OMPC_map &&
+(SemaRef.getLangOpts().OpenMP <= 45 || StartLoc.isValid()) &&
 checkMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr,
   /*CurrentRegionOnly=*/false, CurComponents, CKind))
   break;


Index: clang/test/OpenMP/target_map_messages.cpp
===
--- clang/test/OpenMP/target_map_messages.cpp
+++ clang/test/OpenMP/target_map_messages.cpp
@@ -604,6 +604,7 @@
   const int ()[5] = da;
   SC1 s;
   SC1 *p;
+  int Arr[10];
 #pragma omp target data map // expected-error {{expected '(' after 'map'}} le45-error {{expected at least one 'map' or 'use_device_ptr' clause for '#pragma omp target data'}} le50-error {{expected at least one 'map', 'use_device_ptr', or 'use_device_addr' clause for '#pragma omp target data'}}
 #pragma omp target data map( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
 #pragma omp target data map() // expected-error {{expected expression}}
@@ -750,6 +751,12 @@
 #pragma omp target map(iarr[:2:d]) // expected-error {{expected ']'}} expected-note {{to match this '['}}
   {}
 
+#pragma omp target data map(Arr[0:4]) // le45-note {{used here}}
+  {
+#pragma omp target
+Arr[0] = 2; // le45-error {{original storage of expression in data environment is shared but data environment do not fully contain mapped expression storage}}
+  }
+
   return tmain(argc)+tmain(argc); // expected-note {{in instantiation of function template specialization 'tmain' requested here}} expected-note {{in instantiation of function template specialization 'tmain' requested here}}
 }
 #endif
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -17478,6 +17478,7 @@
   /*CurrentRegionOnly=*/true, CurComponents, CKind))
   break;
 if (CKind == OMPC_map &&
+(SemaRef.getLangOpts().OpenMP <= 45 || StartLoc.isValid()) &&
 checkMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr,
   /*CurrentRegionOnly=*/false, CurComponents, CKind))
   break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d96a47c - [analyzer] ctu-on-demand-parsing tests: replace linux -> system-linux

2020-07-13 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2020-07-13T14:29:47+02:00
New Revision: d96a47c61625f853ec42a151ae3783e30a3943f3

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

LOG: [analyzer] ctu-on-demand-parsing tests: replace linux -> system-linux

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

Added: 


Modified: 
clang/test/Analysis/ctu-on-demand-parsing.c
clang/test/Analysis/ctu-on-demand-parsing.cpp

Removed: 




diff  --git a/clang/test/Analysis/ctu-on-demand-parsing.c 
b/clang/test/Analysis/ctu-on-demand-parsing.c
index 5adce7f36963..07a72a104646 100644
--- a/clang/test/Analysis/ctu-on-demand-parsing.c
+++ b/clang/test/Analysis/ctu-on-demand-parsing.c
@@ -19,7 +19,7 @@
 // RUN:   -verify ctu-on-demand-parsing.c
 //
 // FIXME: Path handling should work on all platforms.
-// REQUIRES: linux
+// REQUIRES: system-linux
 
 void clang_analyzer_eval(int);
 

diff  --git a/clang/test/Analysis/ctu-on-demand-parsing.cpp 
b/clang/test/Analysis/ctu-on-demand-parsing.cpp
index 058269662fb3..e4e998c8f64c 100644
--- a/clang/test/Analysis/ctu-on-demand-parsing.cpp
+++ b/clang/test/Analysis/ctu-on-demand-parsing.cpp
@@ -30,7 +30,7 @@
 // CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp
 //
 // FIXME: Path handling should work on all platforms.
-// REQUIRES: linux
+// REQUIRES: system-linux
 
 #include "ctu-hdr.h"
 



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


[PATCH] D83555: [analyzer] Fix ctu-on-demand-parsing: REQUIRES: linux -> REQUIRES: system-linux

2020-07-13 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd96a47c61625: [analyzer] ctu-on-demand-parsing tests: 
replace linux - system-linux (authored by steakhal).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83555

Files:
  clang/test/Analysis/ctu-on-demand-parsing.c
  clang/test/Analysis/ctu-on-demand-parsing.cpp


Index: clang/test/Analysis/ctu-on-demand-parsing.cpp
===
--- clang/test/Analysis/ctu-on-demand-parsing.cpp
+++ clang/test/Analysis/ctu-on-demand-parsing.cpp
@@ -30,7 +30,7 @@
 // CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp
 //
 // FIXME: Path handling should work on all platforms.
-// REQUIRES: linux
+// REQUIRES: system-linux
 
 #include "ctu-hdr.h"
 
Index: clang/test/Analysis/ctu-on-demand-parsing.c
===
--- clang/test/Analysis/ctu-on-demand-parsing.c
+++ clang/test/Analysis/ctu-on-demand-parsing.c
@@ -19,7 +19,7 @@
 // RUN:   -verify ctu-on-demand-parsing.c
 //
 // FIXME: Path handling should work on all platforms.
-// REQUIRES: linux
+// REQUIRES: system-linux
 
 void clang_analyzer_eval(int);
 


Index: clang/test/Analysis/ctu-on-demand-parsing.cpp
===
--- clang/test/Analysis/ctu-on-demand-parsing.cpp
+++ clang/test/Analysis/ctu-on-demand-parsing.cpp
@@ -30,7 +30,7 @@
 // CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp
 //
 // FIXME: Path handling should work on all platforms.
-// REQUIRES: linux
+// REQUIRES: system-linux
 
 #include "ctu-hdr.h"
 
Index: clang/test/Analysis/ctu-on-demand-parsing.c
===
--- clang/test/Analysis/ctu-on-demand-parsing.c
+++ clang/test/Analysis/ctu-on-demand-parsing.c
@@ -19,7 +19,7 @@
 // RUN:   -verify ctu-on-demand-parsing.c
 //
 // FIXME: Path handling should work on all platforms.
-// REQUIRES: linux
+// REQUIRES: system-linux
 
 void clang_analyzer_eval(int);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] d7d1af3 - [clangd] Fix DocumentSymbol ranges

2020-07-13 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2020-07-13T15:02:53+02:00
New Revision: d7d1af39168ce8afd041f3ae8db1d1fd3d4f70ac

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

LOG: [clangd] Fix DocumentSymbol ranges

Summary:
DocumentSymbol ranges were not previously tested and, as a result, had invalid
end location. This patch addresses the issue.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, 
cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindSymbols.cpp 
b/clang-tools-extra/clangd/FindSymbols.cpp
index 58e2ee1e21c7..f5d6a95aa713 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -136,17 +136,11 @@ llvm::Optional declToSym(ASTContext , 
const NamedDecl ) {
   auto  = Ctx.getSourceManager();
 
   SourceLocation NameLoc = nameLocation(ND, SM);
-  // getFileLoc is a good choice for us, but we also need to make sure
-  // sourceLocToPosition won't switch files, so we call getSpellingLoc on top 
of
-  // that to make sure it does not switch files.
-  // FIXME: sourceLocToPosition should not switch files!
   SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
   SourceLocation EndLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getEndLoc()));
-  if (NameLoc.isInvalid() || BeginLoc.isInvalid() || EndLoc.isInvalid())
-return llvm::None;
-
-  if (!SM.isWrittenInMainFile(NameLoc) || !SM.isWrittenInMainFile(BeginLoc) ||
-  !SM.isWrittenInMainFile(EndLoc))
+  const auto SymbolRange =
+  toHalfOpenFileRange(SM, Ctx.getLangOpts(), {BeginLoc, EndLoc});
+  if (!SymbolRange)
 return llvm::None;
 
   Position NameBegin = sourceLocToPosition(SM, NameLoc);
@@ -162,8 +156,8 @@ llvm::Optional declToSym(ASTContext , 
const NamedDecl ) {
   SI.name = printName(Ctx, ND);
   SI.kind = SK;
   SI.deprecated = ND.isDeprecated();
-  SI.range =
-  Range{sourceLocToPosition(SM, BeginLoc), sourceLocToPosition(SM, 
EndLoc)};
+  SI.range = Range{sourceLocToPosition(SM, SymbolRange->getBegin()),
+   sourceLocToPosition(SM, SymbolRange->getEnd())};
   SI.selectionRange = Range{NameBegin, NameEnd};
   if (!SI.range.contains(SI.selectionRange)) {
 // 'selectionRange' must be contained in 'range', so in cases where clang

diff  --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp 
b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
index 31879e356ce0..07c42fcf2030 100644
--- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -35,7 +35,7 @@ MATCHER_P(QName, Name, "") {
 }
 MATCHER_P(WithName, N, "") { return arg.name == N; }
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
-MATCHER_P(SymRange, Range, "") { return arg.location.range == Range; }
+MATCHER_P(SymRange, Range, "") { return arg.range == Range; }
 
 // GMock helpers for matching DocumentSymbol.
 MATCHER_P(SymNameRange, Range, "") { return arg.selectionRange == Range; }
@@ -712,6 +712,72 @@ TEST(DocumentSymbols, QualifiersWithTemplateArgs) {
WithName("Foo_type::method3")));
 }
 
+TEST(DocumentSymbolsTest, Ranges) {
+  TestTU TU;
+  Annotations Main(R"(
+  $foo[[int foo(bool Argument) {
+return 42;
+  }]]
+
+  $variable[[char GLOBAL_VARIABLE]];
+
+  $ns[[namespace ns {
+  $bar[[class Bar {
+  public:
+$ctor[[Bar() {}]]
+$dtor[[~Bar()]];
+
+  private:
+$field[[unsigned Baz]];
+
+$getbaz[[unsigned getBaz() { return Baz; }]]
+  }]];
+  }]] // namespace ns
+
+  $forwardclass[[class ForwardClassDecl]];
+
+  $struct[[struct StructDefinition {
+$structfield[[int *Pointer = nullptr]];
+  }]];
+  $forwardstruct[[struct StructDeclaration]];
+
+  $forwardfunc[[void forwardFunctionDecl(int Something)]];
+)");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  UnorderedElementsAre(
+  AllOf(WithName("foo"), WithKind(SymbolKind::Function),
+SymRange(Main.range("foo"))),
+  AllOf(WithName("GLOBAL_VARIABLE"), WithKind(SymbolKind::Variable),
+SymRange(Main.range("variable"))),
+  AllOf(
+  WithName("ns"), WithKind(SymbolKind::Namespace),
+  SymRange(Main.range("ns")),
+  Children(AllOf(
+  WithName("Bar"), WithKind(SymbolKind::Class),
+  SymRange(Main.range("bar")),
+  Children(
+   

[PATCH] D83668: [clangd] Fix DocumentSymbol ranges

2020-07-13 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd7d1af39168c: [clangd] Fix DocumentSymbol ranges (authored 
by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83668

Files:
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -35,7 +35,7 @@
 }
 MATCHER_P(WithName, N, "") { return arg.name == N; }
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
-MATCHER_P(SymRange, Range, "") { return arg.location.range == Range; }
+MATCHER_P(SymRange, Range, "") { return arg.range == Range; }
 
 // GMock helpers for matching DocumentSymbol.
 MATCHER_P(SymNameRange, Range, "") { return arg.selectionRange == Range; }
@@ -712,6 +712,72 @@
WithName("Foo_type::method3")));
 }
 
+TEST(DocumentSymbolsTest, Ranges) {
+  TestTU TU;
+  Annotations Main(R"(
+  $foo[[int foo(bool Argument) {
+return 42;
+  }]]
+
+  $variable[[char GLOBAL_VARIABLE]];
+
+  $ns[[namespace ns {
+  $bar[[class Bar {
+  public:
+$ctor[[Bar() {}]]
+$dtor[[~Bar()]];
+
+  private:
+$field[[unsigned Baz]];
+
+$getbaz[[unsigned getBaz() { return Baz; }]]
+  }]];
+  }]] // namespace ns
+
+  $forwardclass[[class ForwardClassDecl]];
+
+  $struct[[struct StructDefinition {
+$structfield[[int *Pointer = nullptr]];
+  }]];
+  $forwardstruct[[struct StructDeclaration]];
+
+  $forwardfunc[[void forwardFunctionDecl(int Something)]];
+)");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  UnorderedElementsAre(
+  AllOf(WithName("foo"), WithKind(SymbolKind::Function),
+SymRange(Main.range("foo"))),
+  AllOf(WithName("GLOBAL_VARIABLE"), WithKind(SymbolKind::Variable),
+SymRange(Main.range("variable"))),
+  AllOf(
+  WithName("ns"), WithKind(SymbolKind::Namespace),
+  SymRange(Main.range("ns")),
+  Children(AllOf(
+  WithName("Bar"), WithKind(SymbolKind::Class),
+  SymRange(Main.range("bar")),
+  Children(
+  AllOf(WithName("Bar"), WithKind(SymbolKind::Constructor),
+SymRange(Main.range("ctor"))),
+  AllOf(WithName("~Bar"), WithKind(SymbolKind::Constructor),
+SymRange(Main.range("dtor"))),
+  AllOf(WithName("Baz"), WithKind(SymbolKind::Field),
+SymRange(Main.range("field"))),
+  AllOf(WithName("getBaz"), WithKind(SymbolKind::Method),
+SymRange(Main.range("getbaz"))),
+  AllOf(WithName("ForwardClassDecl"), WithKind(SymbolKind::Class),
+SymRange(Main.range("forwardclass"))),
+  AllOf(WithName("StructDefinition"), WithKind(SymbolKind::Struct),
+SymRange(Main.range("struct")),
+Children(AllOf(WithName("Pointer"), WithKind(SymbolKind::Field),
+   SymRange(Main.range("structfield"),
+  AllOf(WithName("StructDeclaration"), WithKind(SymbolKind::Struct),
+SymRange(Main.range("forwardstruct"))),
+  AllOf(WithName("forwardFunctionDecl"), WithKind(SymbolKind::Function),
+SymRange(Main.range("forwardfunc");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/FindSymbols.cpp
===
--- clang-tools-extra/clangd/FindSymbols.cpp
+++ clang-tools-extra/clangd/FindSymbols.cpp
@@ -136,17 +136,11 @@
   auto  = Ctx.getSourceManager();
 
   SourceLocation NameLoc = nameLocation(ND, SM);
-  // getFileLoc is a good choice for us, but we also need to make sure
-  // sourceLocToPosition won't switch files, so we call getSpellingLoc on top of
-  // that to make sure it does not switch files.
-  // FIXME: sourceLocToPosition should not switch files!
   SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
   SourceLocation EndLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getEndLoc()));
-  if (NameLoc.isInvalid() || BeginLoc.isInvalid() || EndLoc.isInvalid())
-return llvm::None;
-
-  if (!SM.isWrittenInMainFile(NameLoc) || !SM.isWrittenInMainFile(BeginLoc) ||
-  !SM.isWrittenInMainFile(EndLoc))
+  const auto SymbolRange =
+  toHalfOpenFileRange(SM, Ctx.getLangOpts(), {BeginLoc, EndLoc});
+  if (!SymbolRange)
 return llvm::None;
 
   Position NameBegin = 

[PATCH] D83553: [PATCH 3/4][Sema][AArch64] Add codegen for arm_sve_vector_bits attribute

2020-07-13 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added a comment.

In D83553#2145227 , @efriedma wrote:

> What's the tradeoff of representing these in IR as vscale'ed vector types, as 
> opposed to fixed-wdith vector types?


If you mean alloca's for single vectors, then that's partly to do with better 
test coverage of the stackframe layout with scalable vectors until we can start 
testing that with auto-vectorized code. Also, currently LLVM only implements 
the VL-scaled addressing modes for the scalable IR type and would otherwise 
always use base addressing mode if the type is fixed-width (`basereg = sp/fp + 
byteoffset; ld1 dstreg, [basereg, #0 mul VL]`), so until we add those smarts, 
code quality will probably be better.




Comment at: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp:135
   llvm::Type *getStorageType(const FieldDecl *FD) {
-llvm::Type *Type = Types.ConvertTypeForMem(FD->getType());
+llvm::Type *Type = Types.ConvertTypeForMem(FD->getType(), false, true);
 if (!FD->isBitField()) return Type;

Can you add comments for the `false` and `true` parameters, e.g. 
`/*ForBitField*/ false, /*EnforceFixedLengthSVEAttribute*/ true`



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:3731
   if (!Ty)
-Ty = getTypes().ConvertTypeForMem(ASTTy);
+Ty = getTypes().ConvertTypeForMem(ASTTy, false, true);
 

same here.



Comment at: clang/lib/CodeGen/CodeGenTypes.cpp:81
+llvm::Optional
+CodeGenTypes::getFixedSVETypeForMemory(const Type *T) {
+  unsigned VectorSize;

nit: `s/getFixedSVETypeForMemory/getFixedLengthSVETypeForMemory/`



Comment at: clang/lib/CodeGen/CodeGenTypes.cpp:94
+  case BuiltinType::SveUint8:
+  case BuiltinType::SveBool:
+MemEltTy = llvm::Type::getInt8Ty(Context);

Can you add a comment explaining why `SveBool` gets an `i8` element type for 
it's memory type?



Comment at: clang/lib/CodeGen/CodeGenTypes.h:137
   /// memory representation is usually i8 or i32, depending on the target.
-  llvm::Type *ConvertTypeForMem(QualType T, bool ForBitField = false);
+  llvm::Type *ConvertTypeForMem(QualType T, bool ForBitField = false,
+bool EnforceFixedLengthSVEAttribute = false);

Can you add a comment here to explain what EnforceFixedLengthSVEAttribute does?


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

https://reviews.llvm.org/D83553



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


[PATCH] D83079: [clang][aarch64] Generate preprocessor macros for -march=armv8.6a+sve.

2020-07-13 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/AArch64.cpp:370
+  if (V8_6Pos != std::end(Features)) {
+V8_6Pos = Features.insert(std::next(V8_6Pos), "+i8mm");
+V8_6Pos = Features.insert(V8_6Pos, "+bf16");

sdesmalen wrote:
> Both `+i8mm` and `+bf16` should be added at iterator `V8_6Pos`, because I 
> believe that `std::next(V8_6Pos)` inserts it after the item that follows 
> `v8.6a`, rather than after `v8.6a` directly.
Never mind the above comment, you pointed out offline that `std::next` is 
correct because `insert` inserts the value before V8_6Pos, my bad!

Looking at the documentation for `std::vector::insert`, it seems you can write:
```if (V8_6Pos != std::end(Features))
  Features.insert(std::next(V8_6Pos), {"+bf16", "+i8mm"});```
which avoids having to update V8_6Pos.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83079



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


[PATCH] D82502: [PowerPC][Power10] Implement Load VSX Vector and Sign Extend and Zero Extend

2020-07-13 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 277415.
Conanap marked 2 inline comments as done.
Conanap added a comment.

Removed unecessary comments and unintended changes.


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

https://reviews.llvm.org/D82502

Files:
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt
  llvm/test/MC/PowerPC/ppc64-encoding-ISA31.s

Index: llvm/test/MC/PowerPC/ppc64-encoding-ISA31.s
===
--- llvm/test/MC/PowerPC/ppc64-encoding-ISA31.s
+++ llvm/test/MC/PowerPC/ppc64-encoding-ISA31.s
@@ -429,3 +429,15 @@
 # CHECK-BE: stxvrdx 35, 3, 1  # encoding: [0x7c,0x63,0x09,0xdb]
 # CHECK-LE: stxvrdx 35, 3, 1  # encoding: [0xdb,0x09,0x63,0x7c]
 stxvrdx 35, 3, 1
+# CHECK-BE: lxvrbx 32, 1, 2   # encoding: [0x7c,0x01,0x10,0x1b]
+# CHECK-LE: lxvrbx 32, 1, 2   # encoding: [0x1b,0x10,0x01,0x7c]
+lxvrbx 32, 1, 2
+# CHECK-BE: lxvrhx 33, 1, 2   # encoding: [0x7c,0x21,0x10,0x5b]
+# CHECK-LE: lxvrhx 33, 1, 2   # encoding: [0x5b,0x10,0x21,0x7c]
+lxvrhx 33, 1, 2
+# CHECK-BE: lxvrdx 34, 1, 2   # encoding: [0x7c,0x41,0x10,0xdb]
+# CHECK-LE: lxvrdx 34, 1, 2   # encoding: [0xdb,0x10,0x41,0x7c]
+lxvrdx 34, 1, 2
+# CHECK-BE: lxvrwx 35, 1, 2   # encoding: [0x7c,0x61,0x10,0x9b]
+# CHECK-LE: lxvrwx 35, 1, 2   # encoding: [0x9b,0x10,0x61,0x7c]
+lxvrwx 35, 1, 2
Index: llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt
===
--- llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt
+++ llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt
@@ -302,3 +302,15 @@
 
 # CHECK: stxvrdx 35, 3, 1
 0x7c 0x63 0x09 0xdb
+
+# CHECK: lxvrbx 32, 1, 2
+0x7c 0x01 0x10 0x1b
+
+# CHECK: lxvrhx 33, 1, 2
+0x7c 0x21 0x10 0x5b
+
+# CHECK: lxvrdx 34, 1, 2
+0x7c 0x41 0x10 0xdb
+
+# CHECK: lxvrwx 35, 1, 2
+0x7c 0x61 0x10 0x9b
Index: llvm/lib/Target/PowerPC/PPCInstrPrefix.td
===
--- llvm/lib/Target/PowerPC/PPCInstrPrefix.td
+++ llvm/lib/Target/PowerPC/PPCInstrPrefix.td
@@ -18,6 +18,15 @@
 // address computations).
 class isPCRel { bit PCRel = 1; }
 
+// PowerPC specific type constraints.
+def SDT_PPCLXVRZX : SDTypeProfile<1, 2, [
+  SDTCisVT<0, v1i128>, SDTCisPtrTy<1>, SDTCisPtrTy<2>
+]>;
+
+// PPC Specific DAG Nodes.
+def PPClxvrzx : SDNode<"PPCISD::LXVRZX", SDT_PPCLXVRZX,
+   [SDNPHasChain, SDNPMayLoad]>;
+
 // Top-level class for prefixed instructions.
 class PI pref, bits<6> opcode, dag OOL, dag IOL, string asmstr,
  InstrItinClass itin> : Instruction {
Index: llvm/lib/Target/PowerPC/PPCISelLowering.h
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.h
+++ llvm/lib/Target/PowerPC/PPCISelLowering.h
@@ -493,6 +493,12 @@
 /// an xxswapd.
 LXVD2X,
 
+/// LXVRZX - Load VSX Vector Rightmost and Zero Extend
+/// This node represents v1i128 BUILD_VECTOR of a zero extending load
+/// instruction from  to i128.
+/// Allows utilization of the Load VSX Vector Rightmost Instructions.
+LXVRZX,
+
 /// VSRC, CHAIN = LOAD_VEC_BE CHAIN, Ptr - Occurs only for little endian.
 /// Maps directly to one of lxvd2x/lxvw4x/lxvh8x/lxvb16x depending on
 /// the vector type to load vector in big-endian element order.
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -1572,6 +1572,7 @@
   case PPCISD::MAT_PCREL_ADDR:  return "PPCISD::MAT_PCREL_ADDR";
   case PPCISD::LD_SPLAT:return "PPCISD::LD_SPLAT";
   case PPCISD::FNMSUB:  return "PPCISD::FNMSUB";
+  case PPCISD::LXVRZX:  return "PPCISD::LXVRZX";
   }
   return nullptr;
 }
@@ -14125,6 +14126,44 @@
   return SDValue();
 }
 
+// Look for the pattern of a load from a narrow width to i128, feeding
+// into a BUILD_VECTOR of v1i128. Replace this sequence with a PPCISD node
+// (LXVRZX). This node represents a zero extending load that will be matched
+// to the Load VSX Vector Rightmost instructions.
+static SDValue combineBVZEXTLOAD(SDNode *N, SelectionDAG ) {
+  SDLoc dl(N);
+
+  // This combine is only eligible for a BUILD_VECTOR of v1i128.
+  // Other return types are not valid for the LXVRZX replacement.
+  if (N->getValueType(0) != MVT::v1i128)
+return SDValue();
+
+  SDValue Operand = N->getOperand(0);
+  // 

[PATCH] D83120: [Analyzer][StreamChecker] Using BugType::SuppressOnSink at resource leak report.

2020-07-13 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: clang/test/Analysis/stream.c:274-284
 // Check that "location uniqueing" works.
 // This results in reporting only one occurence of resource leak for a stream.
 void check_leak_noreturn_2() {
   FILE *F1 = tmpfile();
   if (!F1)
 return;
   if (Test == 1) {

Szelethus wrote:
> Szelethus wrote:
> > balazske wrote:
> > > NoQ wrote:
> > > > balazske wrote:
> > > > > Szelethus wrote:
> > > > > > Why did this change? Is there a sink in the return branch?
> > > > > The change is probably because D83115. Because the "uniqueing" one 
> > > > > resource leak is reported from the two possible, and the order 
> > > > > changes somehow (probably not the shortest is found first).
> > > > The shortest should still be found first. I strongly suggest debugging 
> > > > this. Looks like a bug in suppress-on-sink.
> > > There is no code that ensures that the shortest path is reported. In this 
> > > case one equivalence class is created with both bug reports. If 
> > > `SuppressOnSink` is false the last one is returned from the list, 
> > > otherwise the first one 
> > > (`PathSensitiveBugReporter::findReportInEquivalenceClass`), this causes 
> > > the difference (seems to be unrelated to D83115).
> > > There is no code that ensures that the shortest path is reported.
> > 
> > There absolutely should be -- See the summary of D65379 for more info, 
> > CTRL+F "shortest" helps quite a bit as well. For each bug report, we create 
> > a bug path (a path in the exploded graph from the root to the sepcific bug 
> > reports error node), and sort them by length.
> > 
> > It all feels super awkward -- 
> > `PathSensitiveBugReporter::findReportInEquivalenceClass` picks out a bug 
> > report from an equivalence class as you described, but that will only be 
> > reported if it is a `BasicBugReport` (as implemented by 
> > `PathSensitiveBugReporter::generateDiagnosticForConsumerMap`), otherwise it 
> > should go through the graph cutting process etc.
> > 
> > So at the end of the day, the shortest path should appear still? 
> > 
> @balazske I spent a lot of my GSoC rewriting some especially miserable code 
> in `BugReporter.cpp`, please hunt me down if you need any help there.
Can we say that the one path in this case is shorter than the other? The 
difference is only at the "taking true/false branch" at the `if` in line 280. 
Maybe both have equal length. The notes are taken always from the single picked 
report that is returned from `findReportInEquivalenceClass` and these notes can 
contain different source locations (reports in a single equivalence class can 
have different locations, really this makes the difference between them?).  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83120



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


[PATCH] D83516: [PowerPC][Power10] 128-bit Binary Integer Operation instruction definitions and MC Tests

2020-07-13 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 277442.
Conanap marked an inline comment as done.
Conanap added a comment.

Some formatting changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83516

Files:
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt
  llvm/test/MC/PowerPC/ppc64-encoding-ISA31.s

Index: llvm/test/MC/PowerPC/ppc64-encoding-ISA31.s
===
--- llvm/test/MC/PowerPC/ppc64-encoding-ISA31.s
+++ llvm/test/MC/PowerPC/ppc64-encoding-ISA31.s
@@ -429,3 +429,84 @@
 # CHECK-BE: stxvrdx 35, 3, 1  # encoding: [0x7c,0x63,0x09,0xdb]
 # CHECK-LE: stxvrdx 35, 3, 1  # encoding: [0xdb,0x09,0x63,0x7c]
 stxvrdx 35, 3, 1
+# CHECK-BE: vmulesd 1, 2, 3   # encoding: [0x10,0x22,0x1b,0xc8]
+# CHECK-LE: vmulesd 1, 2, 3   # encoding: [0xc8,0x1b,0x22,0x10]
+vmulesd 1, 2, 3
+# CHECK-BE: vmulosd 1, 2, 3   # encoding: [0x10,0x22,0x19,0xc8]
+# CHECK-LE: vmulosd 1, 2, 3   # encoding: [0xc8,0x19,0x22,0x10]
+vmulosd 1, 2, 3
+# CHECK-BE: vmuleud 1, 2, 3   # encoding: [0x10,0x22,0x1a,0xc8]
+# CHECK-LE: vmuleud 1, 2, 3   # encoding: [0xc8,0x1a,0x22,0x10]
+vmuleud 1, 2, 3
+# CHECK-BE: vmuloud 1, 2, 3   # encoding: [0x10,0x22,0x18,0xc8]
+# CHECK-LE: vmuloud 1, 2, 3   # encoding: [0xc8,0x18,0x22,0x10]
+vmuloud 1, 2, 3
+# CHECK-BE: vmsumcud 1, 2, 3, 4   # encoding: [0x10,0x22,0x19,0x17]
+# CHECK-LE: vmsumcud 1, 2, 3, 4   # encoding: [0x17,0x19,0x22,0x10]
+vmsumcud 1, 2, 3, 4
+# CHECK-BE: vdivsq 3, 4, 5# encoding: [0x10,0x64,0x29,0x0b]
+# CHECK-LE: vdivsq 3, 4, 5# encoding: [0x0b,0x29,0x64,0x10]
+vdivsq 3, 4, 5
+# CHECK-BE: vdivuq 3, 4, 5# encoding: [0x10,0x64,0x28,0x0b]
+# CHECK-LE: vdivuq 3, 4, 5# encoding: [0x0b,0x28,0x64,0x10]
+vdivuq 3, 4, 5
+# CHECK-BE: vdivesq 3, 4, 5   # encoding: [0x10,0x64,0x2b,0x0b]
+# CHECK-LE: vdivesq 3, 4, 5   # encoding: [0x0b,0x2b,0x64,0x10]
+vdivesq 3, 4, 5
+# CHECK-BE: vdiveuq 3, 4, 5   # encoding: [0x10,0x64,0x2a,0x0b]
+# CHECK-LE: vdiveuq 3, 4, 5   # encoding: [0x0b,0x2a,0x64,0x10]
+vdiveuq 3, 4, 5
+# CHECK-BE: vcmpequq 4, 5, 6  # encoding: [0x10,0x85,0x31,0xc7]
+# CHECK-LE: vcmpequq 4, 5, 6  # encoding: [0xc7,0x31,0x85,0x10]
+vcmpequq 4, 5, 6
+# CHECK-BE: vcmpequq. 4, 5, 6 # encoding: [0x10,0x85,0x35,0xc7]
+# CHECK-LE: vcmpequq. 4, 5, 6 # encoding: [0xc7,0x35,0x85,0x10]
+vcmpequq. 4, 5, 6
+# CHECK-BE: vcmpgtsq 4, 5, 6  # encoding: [0x10,0x85,0x33,0x87]
+# CHECK-LE: vcmpgtsq 4, 5, 6  # encoding: [0x87,0x33,0x85,0x10]
+vcmpgtsq 4, 5, 6
+# CHECK-BE: vcmpgtsq. 4, 5, 6 # encoding: [0x10,0x85,0x37,0x87]
+# CHECK-LE: vcmpgtsq. 4, 5, 6 # encoding: [0x87,0x37,0x85,0x10]
+vcmpgtsq. 4, 5, 6
+# CHECK-BE: vcmpgtuq 4, 5, 6  # encoding: [0x10,0x85,0x32,0x87]
+# CHECK-LE: vcmpgtuq 4, 5, 6  # encoding: [0x87,0x32,0x85,0x10]
+vcmpgtuq 4, 5, 6
+# CHECK-BE: vcmpgtuq. 4, 5, 6 # encoding: [0x10,0x85,0x36,0x87]
+# CHECK-LE: vcmpgtuq. 4, 5, 6 # encoding: [0x87,0x36,0x85,0x10]
+vcmpgtuq. 4, 5, 6
+# CHECK-BE: vmoduq 3, 4, 5# encoding: [0x10,0x64,0x2e,0x0b]
+# CHECK-LE: vmoduq 3, 4, 5# encoding: [0x0b,0x2e,0x64,0x10]
+vmoduq 3, 4, 5
+# CHECK-BE: vextsd2q 20, 25   # encoding: [0x12,0x9b,0xce,0x02]
+# CHECK-LE: vextsd2q 20, 25   # encoding: [0x02,0xce,0x9b,0x12]
+vextsd2q 20, 25
+# CHECK-BE: vrlq 4, 5, 6  # encoding: [0x10,0x85,0x30,0x05]
+# CHECK-LE: vrlq 4, 5, 6  # encoding: [0x05,0x30,0x85,0x10]
+vrlq 4, 5, 6
+# CHECK-BE: vrlqnm 4, 5, 6# encoding: [0x10,0x85,0x31,0x45]
+# CHECK-LE: vrlqnm 4, 5, 6# encoding: [0x45,0x31,0x85,0x10]
+vrlqnm 4, 5, 6
+# CHECK-BE: vrlqmi 4, 5, 6# encoding: [0x10,0x85,0x30,0x45]
+# CHECK-LE: vrlqmi 4, 5, 6# encoding: [0x45,0x30,0x85,0x10]
+vrlqmi 4, 5, 6
+# CHECK-BE: vslq 4, 5, 6  # encoding: [0x10,0x85,0x31,0x05]
+# CHECK-LE: vslq 4, 5, 6  # 

[PATCH] D81958: [clangd] Add library to semantically strip flags by name.

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 277444.
sammccall marked 13 inline comments as done.
sammccall added a comment.

Address the easy comments, add a test for order-dependency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81958

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -207,6 +207,120 @@
   EXPECT_THAT(Cmd, ElementsAre(_, "FOO.CC", "--hello", "-fsyntax-only"));
 }
 
+static std::string strip(llvm::StringRef Arg, llvm::StringRef Argv) {
+  llvm::SmallVector Parts;
+  llvm::SplitString(Argv, Parts);
+  std::vector Args = {Parts.begin(), Parts.end()};
+  ArgStripper S;
+  S.strip(Arg);
+  S.process(Args);
+  return llvm::join(Args, " ");
+}
+
+TEST(ArgStripperTest, Spellings) {
+  // May use alternate prefixes.
+  EXPECT_EQ(strip("-pedantic", "clang -pedantic foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-pedantic", "clang --pedantic foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--pedantic", "clang -pedantic foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--pedantic", "clang --pedantic foo.cc"), "clang foo.cc");
+  // May use alternate names.
+  EXPECT_EQ(strip("-x", "clang -x c++ foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-x", "clang --language=c++ foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--language=", "clang -x c++ foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--language=", "clang --language=c++ foo.cc"),
+"clang foo.cc");
+}
+
+TEST(ArgStripperTest, UnknownFlag) {
+  EXPECT_EQ(strip("-xyzzy", "clang -xyzzy foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-xyz*", "clang -xyzzy foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-xyzzy", "clang -Xclang -xyzzy foo.cc"), "clang foo.cc");
+}
+
+TEST(ArgStripperTest, Xclang) {
+  // Flags may be -Xclang escaped.
+  EXPECT_EQ(strip("-ast-dump", "clang -Xclang -ast-dump foo.cc"),
+"clang foo.cc");
+  // Args may be -Xclang escaped.
+  EXPECT_EQ(strip("-add-plugin", "clang -Xclang -add-plugin -Xclang z foo.cc"),
+"clang foo.cc");
+}
+
+TEST(ArgStripperTest, ClangCL) {
+  // /I is a synonym for -I in clang-cl mode only.
+  // Not stripped by default.
+  EXPECT_EQ(strip("-I", "clang -I /usr/inc /Interesting/file.cc"),
+"clang /Interesting/file.cc");
+  // Stripped when invoked as clang-cl.
+  EXPECT_EQ(strip("-I", "clang-cl -I /usr/inc /Interesting/file.cc"),
+"clang-cl");
+  // Stripped when invoked as CL.EXE
+  EXPECT_EQ(strip("-I", "CL.EXE -I /usr/inc /Interesting/file.cc"), "CL.EXE");
+  // Stripped when passed --driver-mode=cl.
+  EXPECT_EQ(strip("-I", "cc -I /usr/inc /Interesting/file.cc --driver-mode=cl"),
+"cc --driver-mode=cl");
+}
+
+TEST(ArgStripperTest, ArgStyles) {
+  // Flag
+  EXPECT_EQ(strip("-Qn", "clang -Qn foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-Qn", "clang -QnZ foo.cc"), "clang -QnZ foo.cc");
+  // Joined
+  EXPECT_EQ(strip("-std=", "clang -std= foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-std=", "clang -std=c++11 foo.cc"), "clang foo.cc");
+  // Separate
+  EXPECT_EQ(strip("-mllvm", "clang -mllvm X foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-mllvm", "clang -mllvmX foo.cc"), "clang -mllvmX foo.cc");
+  // RemainingArgsJoined
+  EXPECT_EQ(strip("/link", "clang-cl /link b c d foo.cc"), "clang-cl");
+  EXPECT_EQ(strip("/link", "clang-cl /linka b c d foo.cc"), "clang-cl");
+  // CommaJoined
+  EXPECT_EQ(strip("-Wl,", "clang -Wl,x,y foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-Wl,", "clang -Wl, foo.cc"), "clang foo.cc");
+  // MultiArg
+  EXPECT_EQ(strip("-segaddr", "clang -segaddr a b foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-segaddr", "clang -segaddra b foo.cc"),
+"clang -segaddra b foo.cc");
+  // JoinedOrSeparate
+  EXPECT_EQ(strip("-G", "clang -GX foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-G", "clang -G X foo.cc"), "clang foo.cc");
+  // JoinedAndSeparate
+  EXPECT_EQ(strip("-plugin-arg-", "clang -cc1 -plugin-arg-X Y foo.cc"),
+"clang -cc1 foo.cc");
+  EXPECT_EQ(strip("-plugin-arg-", "clang -cc1 -plugin-arg- Y foo.cc"),
+"clang -cc1 foo.cc");
+}
+
+TEST(ArgStripperTest, EndOfList) {
+  // When we hit the end-of-args prematurely, we don't crash.
+  // We consume the incomplete args if we've matched the target option.
+  EXPECT_EQ(strip("-I", "clang -Xclang"), "clang -Xclang");
+  EXPECT_EQ(strip("-I", "clang -Xclang -I"), "clang");
+  EXPECT_EQ(strip("-I", "clang -I -Xclang"), "clang");
+  EXPECT_EQ(strip("-I", "clang -I"), "clang");
+}
+
+TEST(ArgStripperTest, Multiple) {
+  ArgStripper S;
+  S.strip("-o");
+  S.strip("-c");
+  

[PATCH] D83079: [clang][aarch64] Generate preprocessor macros for -march=armv8.6a+sve.

2020-07-13 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 277445.
fpetrogalli added a comment.

Update the `insert` invocation to use initializer list instead of calling it 
twice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83079

Files:
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Preprocessor/aarch64-target-features.c


Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -112,6 +112,60 @@
 // CHECK-SVE-F64MM: __ARM_FEATURE_SVE 1
 // CHECK-SVE-F64MM: __ARM_FEATURE_SVE_MATMUL_FP64 1
 
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.5-a+sve -x c -E -dM 
%s -o - | FileCheck --check-prefix=CHECK-SVE-8_5 %s
+// CHECK-SVE-8_5-NOT: __ARM_FEATURE_SVE_BF16 1
+// CHECK-SVE-8_5-NOT: __ARM_FEATURE_SVE_MATMUL_FP32 1
+// CHECK-SVE-8_5-NOT: __ARM_FEATURE_SVE_MATMUL_INT8 1
+// CHECK-SVE-8_5: __ARM_FEATURE_SVE 1
+
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.6-a+sve -x c -E -dM 
%s -o - | FileCheck --check-prefix=CHECK-SVE-8_6 %s
+// CHECK-SVE-8_6: __ARM_FEATURE_SVE 1
+// CHECK-SVE-8_6: __ARM_FEATURE_SVE_BF16 1
+// CHECK-SVE-8_6: __ARM_FEATURE_SVE_MATMUL_FP32 1
+// CHECK-SVE-8_6: __ARM_FEATURE_SVE_MATMUL_INT8 1
+
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.6-a+sve+noi8mm -x c 
-E -dM %s -o - | FileCheck --check-prefix=CHECK-SVE-8_6-NOI8MM %s
+// CHECK-SVE-8_6-NOI8MM-NOT: __ARM_FEATURE_SVE_MATMUL_INT8 1
+// CHECK-SVE-8_6-NOI8MM: __ARM_FEATURE_SVE 1
+// CHECK-SVE-8_6-NOI8MM: __ARM_FEATURE_SVE_BF16 1
+// CHECK-SVE-8_6-NOI8MM: __ARM_FEATURE_SVE_MATMUL_FP32 1
+
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.6-a+sve+nobf16 -x c 
-E -dM %s -o - | FileCheck --check-prefix=CHECK-SVE-8_6-NOBF16 %s
+// CHECK-SVE-8_6-NOBF16-NOT: __ARM_FEATURE_SVE_BF16 1
+// CHECK-SVE-8_6-NOBF16: __ARM_FEATURE_SVE 1
+// CHECK-SVE-8_6-NOBF16: __ARM_FEATURE_SVE_MATMUL_FP32 1
+// CHECK-SVE-8_6-NOBF16: __ARM_FEATURE_SVE_MATMUL_INT8 1
+
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.6-a+sve+nof32mm -x 
c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SVE-8_6-NOF32MM %s
+// CHECK-SVE-8_6-NOF32MM-NOT: __ARM_FEATURE_SVE_MATMUL_FP32 1
+// CHECK-SVE-8_6-NOF32MM: __ARM_FEATURE_SVE 1
+// CHECK-SVE-8_6-NOF32MM: __ARM_FEATURE_SVE_BF16 1
+// CHECK-SVE-8_6-NOF32MM: __ARM_FEATURE_SVE_MATMUL_INT8 1
+
+// RUN: %clang -target aarch64-none-linux-gnu 
-march=armv8.6-a+sve+noi8mm+nobf16 -x c -E -dM %s -o - | FileCheck 
--check-prefix=CHECK-SVE-8_6-NOI8MMNOBF16 %s
+// CHECK-SVE-8_6-NOI8MMNOBF16-NOT: __ARM_FEATURE_SVE_BF16 1
+// CHECK-SVE-8_6-NOI8MMNOBF16-NOT: __ARM_FEATURE_SVE_MATMUL_INT8 1
+// CHECK-SVE-8_6-NOI8MMNOBF16: __ARM_FEATURE_SVE 1
+// CHECK-SVE-8_6-NOI8MMNOBF16: __ARM_FEATURE_SVE_MATMUL_FP32 1
+
+// RUN: %clang -target aarch64-none-linux-gnu 
-march=armv8.6-a+sve+noi8mm+nof32mm -x c -E -dM %s -o - | FileCheck 
--check-prefix=CHECK-SVE-8_6-NOI8MMNOF32MM %s
+// CHECK-SVE-8_6-NOI8MMNOF32MM-NOT: __ARM_FEATURE_SVE_MATMUL_FP32 1
+// CHECK-SVE-8_6-NOI8MMNOF32MM-NOT: __ARM_FEATURE_SVE_MATMUL_INT8 1
+// CHECK-SVE-8_6-NOI8MMNOF32MM: __ARM_FEATURE_SVE 1
+// CHECK-SVE-8_6-NOI8MMNOF32MM: __ARM_FEATURE_SVE_BF16 1
+
+// RUN: %clang -target aarch64-none-linux-gnu 
-march=armv8.6-a+sve+nobf16+nof32mm -x c -E -dM %s -o - | FileCheck 
--check-prefix=CHECK-SVE-8_6-NOBF16NOF32MM %s
+// CHECK-SVE-8_6-NOBF16NOF32MM-NOT: __ARM_FEATURE_SVE_BF16 1
+// CHECK-SVE-8_6-NOBF16NOF32MM-NOT: __ARM_FEATURE_SVE_MATMUL_FP32 1
+// CHECK-SVE-8_6-NOBF16NOF32MM: __ARM_FEATURE_SVE 1
+// CHECK-SVE-8_6-NOBF16NOF32MM: __ARM_FEATURE_SVE_MATMUL_INT8 1
+
+// RUN: %clang -target aarch64-none-linux-gnu 
-march=armv8.6-a+sve+noi8mm+nobf16+nof32mm -x c -E -dM %s -o - | FileCheck 
--check-prefix=CHECK-SVE-8_6-NOI8MMNOBF16NOF32MM %s
+// CHECK-SVE-8_6-NOI8MMNOBF16NOF32MM-NOT: __ARM_FEATURE_SVE_BF16 1
+// CHECK-SVE-8_6-NOI8MMNOBF16NOF32MM-NOT: __ARM_FEATURE_SVE_MATMUL_FP32 1
+// CHECK-SVE-8_6-NOI8MMNOBF16NOF32MM-NOT: __ARM_FEATURE_SVE_MATMUL_INT8 1
+// CHECK-SVE-8_6-NOI8MMNOBF16NOF32MM: __ARM_FEATURE_SVE 1
+
 // The following tests may need to be revised in the future since
 // SVE2 is currently still part of Future Architecture Technologies
 // (https://developer.arm.com/docs/ddi0602/latest)
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -365,6 +365,10 @@
 }
   }
 
+  auto V8_6Pos = llvm::find(Features, "+v8.6a");
+  if (V8_6Pos != std::end(Features))
+V8_6Pos = Features.insert(std::next(V8_6Pos), {"+i8mm", "+bf16"});
+
   if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,

[PATCH] D83055: [clang][Driver] Fix tool path priority test failures

2020-07-13 Thread Steven Wan via Phabricator via cfe-commits
stevewan accepted this revision.
stevewan added a comment.
This revision is now accepted and ready to land.

This LGTM, but since I'm not most familiar with the type 1 failure in 
description, let's see if other reviewers have further comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83055



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


[PATCH] D83120: [Analyzer][StreamChecker] Using BugType::SuppressOnSink at resource leak report.

2020-07-13 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/test/Analysis/stream.c:274-284
 // Check that "location uniqueing" works.
 // This results in reporting only one occurence of resource leak for a stream.
 void check_leak_noreturn_2() {
   FILE *F1 = tmpfile();
   if (!F1)
 return;
   if (Test == 1) {

balazske wrote:
> NoQ wrote:
> > balazske wrote:
> > > Szelethus wrote:
> > > > Why did this change? Is there a sink in the return branch?
> > > The change is probably because D83115. Because the "uniqueing" one 
> > > resource leak is reported from the two possible, and the order changes 
> > > somehow (probably not the shortest is found first).
> > The shortest should still be found first. I strongly suggest debugging 
> > this. Looks like a bug in suppress-on-sink.
> There is no code that ensures that the shortest path is reported. In this 
> case one equivalence class is created with both bug reports. If 
> `SuppressOnSink` is false the last one is returned from the list, otherwise 
> the first one (`PathSensitiveBugReporter::findReportInEquivalenceClass`), 
> this causes the difference (seems to be unrelated to D83115).
> There is no code that ensures that the shortest path is reported.

There absolutely should be -- See the summary of D65379 for more info, CTRL+F 
"shortest" helps quite a bit as well. For each bug report, we create a bug path 
(a path in the exploded graph from the root to the sepcific bug reports error 
node), and sort them by length.

It all feels super awkward -- 
`PathSensitiveBugReporter::findReportInEquivalenceClass` picks out a bug report 
from an equivalence class as you described, but that will only be reported if 
it is a `BasicBugReport` (as implemented by 
`PathSensitiveBugReporter::generateDiagnosticForConsumerMap`), otherwise it 
should go through the graph cutting process etc.

So at the end of the day, the shortest path should appear still? 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83120



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


[PATCH] D83120: [Analyzer][StreamChecker] Using BugType::SuppressOnSink at resource leak report.

2020-07-13 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/test/Analysis/stream.c:274-284
 // Check that "location uniqueing" works.
 // This results in reporting only one occurence of resource leak for a stream.
 void check_leak_noreturn_2() {
   FILE *F1 = tmpfile();
   if (!F1)
 return;
   if (Test == 1) {

Szelethus wrote:
> balazske wrote:
> > NoQ wrote:
> > > balazske wrote:
> > > > Szelethus wrote:
> > > > > Why did this change? Is there a sink in the return branch?
> > > > The change is probably because D83115. Because the "uniqueing" one 
> > > > resource leak is reported from the two possible, and the order changes 
> > > > somehow (probably not the shortest is found first).
> > > The shortest should still be found first. I strongly suggest debugging 
> > > this. Looks like a bug in suppress-on-sink.
> > There is no code that ensures that the shortest path is reported. In this 
> > case one equivalence class is created with both bug reports. If 
> > `SuppressOnSink` is false the last one is returned from the list, otherwise 
> > the first one (`PathSensitiveBugReporter::findReportInEquivalenceClass`), 
> > this causes the difference (seems to be unrelated to D83115).
> > There is no code that ensures that the shortest path is reported.
> 
> There absolutely should be -- See the summary of D65379 for more info, CTRL+F 
> "shortest" helps quite a bit as well. For each bug report, we create a bug 
> path (a path in the exploded graph from the root to the sepcific bug reports 
> error node), and sort them by length.
> 
> It all feels super awkward -- 
> `PathSensitiveBugReporter::findReportInEquivalenceClass` picks out a bug 
> report from an equivalence class as you described, but that will only be 
> reported if it is a `BasicBugReport` (as implemented by 
> `PathSensitiveBugReporter::generateDiagnosticForConsumerMap`), otherwise it 
> should go through the graph cutting process etc.
> 
> So at the end of the day, the shortest path should appear still? 
> 
@balazske I spent a lot of my GSoC rewriting some especially miserable code in 
`BugReporter.cpp`, please hunt me down if you need any help there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83120



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


[PATCH] D83223: [clang-tidy] Header guard check can skip past license comment

2020-07-13 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 277411.
njames93 added a comment.

- Added expect no changes test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83223

Files:
  clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
@@ -221,6 +221,171 @@
 "", "/llvm-project/clang-tools-extra/clangd/foo.h",
 StringRef("header is missing header guard")));
 }
+
+TEST(LLVMHeaderGuardCheckTest, FixHeaderGuardsWithComments) {
+  EXPECT_EQ("// LicenseText //\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// LicenseText //", "include/clang/bar.h",
+StringRef("header is missing header guard")));
+
+  EXPECT_EQ("// LicenseText //\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// LicenseText //\n", "include/clang/bar.h",
+StringRef("header is missing header guard")));
+  EXPECT_EQ("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //\n",
+"include/clang/bar.h",
+StringRef("header is missing header guard")));
+  EXPECT_EQ("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //",
+"include/clang/bar.h",
+StringRef("header is missing header guard")));
+
+  EXPECT_EQ("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"// FunctionDoc\n"
+"void Foo();\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// LicenseText //\n"
+"// SecondLine  //\n"
+"// ThirdLine   //\n"
+"\n"
+"// FunctionDoc\n"
+"void Foo();\n",
+"include/clang/bar.h",
+StringRef("header is missing header guard")));
+
+  EXPECT_EQ("#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"// Function Doc\n"
+"void foo();\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("// Function Doc\n"
+"void foo();\n",
+"include/clang/bar.h",
+StringRef("header is missing header guard")));
+
+  EXPECT_EQ("/* LicenseText \n"
+"   SecondLine  \n"
+"   ThirdLine */\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("/* LicenseText \n"
+"   SecondLine  \n"
+"   ThirdLine */\n",
+"include/clang/bar.h",
+StringRef("header is missing header guard")));
+
+  EXPECT_EQ("/* LicenseText \n"
+"   SecondLine  \n"
+"   ThirdLine */\n"
+"\n"
+"#ifndef LLVM_CLANG_BAR_H\n"
+"#define LLVM_CLANG_BAR_H\n"
+"\n"
+"// FunctionDoc\n"
+"void Foo();\n"
+"\n"
+"#endif\n",
+runHeaderGuardCheck("/* LicenseText \n"
+"   SecondLine  \n"
+"   

[PATCH] D83652: Merge some of the PCH object support with modular codegen

2020-07-13 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 277449.
dblaikie added a comment.

Include all the commits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83652

Files:
  clang/include/clang/AST/ExternalASTSource.h
  clang/include/clang/Sema/MultiplexExternalSemaSource.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/MultiplexExternalSemaSource.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CodeGen/pch-dllexport.cpp

Index: clang/test/CodeGen/pch-dllexport.cpp
===
--- clang/test/CodeGen/pch-dllexport.cpp
+++ clang/test/CodeGen/pch-dllexport.cpp
@@ -3,13 +3,20 @@
 // RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-obj -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCH %s
 
 // Build PCH with object file, then use it.
-// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-pch -building-pch-with-obj -o %t %s
-// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-obj -emit-llvm -include-pch %t -building-pch-with-obj -o - %s | FileCheck -check-prefix=OBJ %s
-// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-obj -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJ %s
+// RUN: %clang_cc1 -triple i686-pc-win32 -O1 -fms-extensions -emit-pch -building-pch-with-obj -o %t %s
+// RUN: %clang_cc1 -triple i686-pc-win32 -O1 -disable-llvm-optzns -fms-extensions -emit-obj -emit-llvm -include-pch %t -building-pch-with-obj -o - %s | FileCheck -check-prefix=OBJ %s
+// RUN: %clang_cc1 -triple i686-pc-win32 -O1 -disable-llvm-optzns -fms-extensions -emit-obj -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJ -check-prefix=PCHWITHOBJ-O1 %s
 
 // Check for vars separately to avoid having to reorder the check statements.
+// RUN: %clang_cc1 -triple i686-pc-win32 -O1 -disable-llvm-optzns -fms-extensions -emit-obj -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJVARS %s
+
+// Test the PCHWITHOBJ at -O0 where available_externally definitions are not
+// provided:
+// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-pch -building-pch-with-obj -o %t %s
+// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-obj -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJ -check-prefix=PCHWITHOBJ-O0 %s
 // RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-obj -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJVARS %s
 
+
 #ifndef IN_HEADER
 #define IN_HEADER
 
@@ -23,7 +30,8 @@
 inline void __declspec(dllexport) baz() {}
 // OBJ: define weak_odr dso_local dllexport void @"?baz@@YAXXZ"
 // PCH: define weak_odr dso_local dllexport void @"?baz@@YAXXZ"
-// PCHWITHOBJ: define weak_odr dso_local dllexport void @"?baz@@YAXXZ"
+// PCHWITHOBJ-O1: define available_externally dso_local void @"?baz@@YAXXZ"
+// PCHWITHOBJ-O0-NOT: define {{.*}}"?baz@@YAXXZ"
 
 
 struct __declspec(dllexport) S {
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1031,8 +1031,10 @@
   // that module interface unit, not by its users. (Inline variables are
   // still emitted in module users.)
   ModulesCodegen =
-  (Writer.WritingModule->Kind == Module::ModuleInterfaceUnit &&
-   Writer.Context->GetGVALinkageForVariable(D) == GVA_StrongExternal);
+  (Writer.WritingModule->Kind == Module::ModuleInterfaceUnit ||
+   (D->hasAttr() &&
+Writer.Context->getLangOpts().BuildingPCHWithObjectFile)) &&
+  Writer.Context->GetGVALinkageForVariable(D) == GVA_StrongExternal;
 }
 Record.push_back(ModulesCodegen);
 if (ModulesCodegen)
@@ -2469,7 +2471,10 @@
   Linkage = Writer->Context->GetGVALinkageForFunction(FD);
   ModulesCodegen = *Linkage == GVA_StrongExternal;
 }
-if (Writer->Context->getLangOpts().ModulesCodegen) {
+if (Writer->Context->getLangOpts().ModulesCodegen ||
+(FD->hasAttr() &&
+ Writer->Context->getLangOpts().BuildingPCHWithObjectFile)) {
+
   // Under -fmodules-codegen, codegen is performed for all non-internal,
   // non-always_inline functions, unless they are available elsewhere.
   if (!FD->hasAttr()) {
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1119,7 +1119,6 @@
   MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min.
   

[PATCH] D80514: [clang-tidy] modernize-use-trailing-return-type support for C++20 concepts and decltype

2020-07-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp:293
+StringRef File = SM.getBufferData(Loc.first);
+const char *TokenBegin = File.data() + Loc.second;
+Lexer Lexer(SM.getLocForStartOfFile(Loc.first), LangOpts, File.begin(),

Should we verify that `End` is valid before doing this pointer arithmetic with 
a value derived from it? For instance, what if `End` points into the scratch 
buffer because it relies on a macro defined on the command line -- will the 
logic still work?



Comment at: 
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp:430
+  AT->getKeyword() == AutoTypeKeyword::Auto &&
+  !hasAnyNestedLocalQualifiers(F->getDeclaredReturnType()))
+return;

Why do we need to check that there aren't any nested local qualifiers?



Comment at: 
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp:285-302
+SourceLocation End =
+expandIfMacroId(ReturnLoc.getSourceRange().getEnd(), SM);
+SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
+
+// Extend the ReturnTypeRange until the last token before the function
+// name.
+std::pair Loc = SM.getDecomposedLoc(End);

bernhardmgruber wrote:
> Is there an easier way to get the token previous to the function name?
There isn't, but if you find you're missing source location information for 
something, you can also consider modifying Clang to add that source location 
information and mark this as a dependent patch. It's not clear to me whether 
that would be worth the effort for this patch or not, but my preference is to 
avoid these little hacks whenever possible.


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

https://reviews.llvm.org/D80514



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


[PATCH] D83680: [clang-tidy] Refactor IncludeInserter

2020-07-13 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, klimek.
Herald added subscribers: cfe-commits, arphaman, kbarton, xazax.hun, nemanjai.
Herald added a project: clang.

Simplified how `IncludeInserter` is used in Checks by abstracting away the 
SourceManager and PPCallbacks inside the method `registerPreprocessor`.
Changed checks that use `IncludeInserter` to no longer use a `std::unique_ptr`, 
instead the IncludeInserter is just a member of the class thats initialized 
with an `IncludeStyle`.
Saving an unnecessary allocation.

This results in the removal of the field `IncludeSorter::IncludeStyle` from the 
checks, as its wrapped in the `IncludeInserter`.
No longer need to create an instance of the `IncludeInserter` in the 
registerPPCallbacks, now that method only needs to contain:

  Inserter.registerPreprocessor(PP);

Also added a helper method to `IncludeInserter` called 
`createMainFileInclusionInsertion`, purely sugar but does better express 
intentions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83680

Files:
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.h
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
  clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.h
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.h
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
  clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -33,9 +33,7 @@
 
   void registerPPCallbacks(const SourceManager , Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
-Inserter = std::make_unique(
-SM, getLangOpts(), utils::IncludeSorter::IS_Google);
-PP->addPPCallbacks(Inserter->CreatePPCallbacks());
+Inserter.registerPreprocessor(PP);
   }
 
   void registerMatchers(ast_matchers::MatchFinder *Finder) override {
@@ -46,15 +44,15 @@
 auto Diag = diag(Result.Nodes.getNodeAs("stmt")->getBeginLoc(),
  "foo, bar");
 for (StringRef Header : HeadersToInclude()) {
-  Diag << Inserter->CreateIncludeInsertion(
-  Result.SourceManager->getMainFileID(), Header, IsAngledInclude());
+  Diag << Inserter.createMainFileIncludeInsertion(Header,
+  IsAngledInclude());
 }
   }
 
   virtual std::vector HeadersToInclude() const = 0;
   virtual bool IsAngledInclude() const = 0;
 
-  std::unique_ptr Inserter;
+  utils::IncludeInserter Inserter{utils::IncludeSorter::IS_Google};
 };
 
 class NonSystemHeaderInserterCheck : public IncludeInserterCheckBase {
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -70,8 +70,7 @@
 
 private:
   Optional Rule;
-  const IncludeSorter::IncludeStyle IncludeStyle;
-  std::unique_ptr Inserter;
+  IncludeInserter Inserter;
 };
 
 } // namespace utils
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -32,8 +32,8 @@
 MakeRule,
   

[PATCH] D83223: [clang-tidy] Header guard check can skip past license comment

2020-07-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D83223#2147247 , @njames93 wrote:

> In D83223#2147072 , @aaron.ballman 
> wrote:
>
> > >   // This is not identified as a license comment as the
> > >   // block is followed by code.
> > >   void foo();
> >
> > FWIW: 
> > https://github.com/GrammaTech/gtirb-pprinter/blob/master/include/gtirb_pprinter/AttPrettyPrinter.hpp
> >  or 
> > https://github.com/GrammaTech/gtirb/blob/master/include/gtirb/AuxData.hpp 
> > (so there are projects which do not put a newline between the license and 
> > code).
>
>
> Short of creating an AI that understands context it won't be possible to 
> determine the difference between license and general documentation, in any 
> case I feel this heuristic is the safest way to ensure good coverage with 
> minimised risk of inserting the guard in the middle of documentation,


My instinct is that we shouldn't be trying to play those games in the first 
place and should consider *all* leading comments and empty (whitespace-only) 
lines as part of the "license" and expect the first significant token to be the 
header guard. e.g., this isn't about the license at all, it's about whether you 
can have prose before the header guard or not. It's not uncommon for projects 
to put prose before header guards, nor is it uncommon for it to go after the 
header guards. tbh, that feels a bit like an option for the feature rather than 
an automatic behavior because I could also see a project wanting to enforce a 
consistent style.




Comment at: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp:224
 }
+
+TEST(LLVMHeaderGuardCheckTest, FixHeaderGuardsWithComments) {

njames93 wrote:
> aaron.ballman wrote:
> > You seem to be missing tests that show the license and header guards are 
> > both correct and found no issues.
> That wouldn't be testing new behaviour added here. The check can already find 
> header guards when there is a license, The code I have added only affects 
> when no guard is found and it needs to add one.  I can still add those cases 
> for piece of mind.
I'd appreciate the test coverage because it's not always immediately clear why 
some of the new tests are expected to fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83223



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


[PATCH] D83334: [OPENMP]Fix PR46593: Reduction initializer missing construnctor call.

2020-07-13 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 277448.
ABataev added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83334

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/for_reduction_codegen_UDR.cpp

Index: clang/test/OpenMP/for_reduction_codegen_UDR.cpp
===
--- clang/test/OpenMP/for_reduction_codegen_UDR.cpp
+++ clang/test/OpenMP/for_reduction_codegen_UDR.cpp
@@ -203,9 +203,11 @@
 // For + reduction operation initial value of private variable is -1.
 // CHECK: call void [[RED_INIT1:@.+]](float* %{{.+}}, float* %{{.+}})
 
+// CHECK: call void @_ZN1SIfEC1Ev([[S_FLOAT_TY]]* [[VAR_PRIV]]
 // For & reduction operation initial value of private variable is defined by call of 'init()' function.
 // CHECK: call void [[RED_INIT2:@.+]](
 
+// CHECK: call void @_ZN1SIfEC1Ev([[S_FLOAT_TY]]* [[VAR1_PRIV]]
 // For && reduction operation initial value of private variable is 1.0.
 // CHECK: call void [[RED_INIT3:@.+]](
 
@@ -599,6 +601,17 @@
 
 // Check initialization of private copy.
 // CHECK: [[BEGIN:%.+]] = getelementptr inbounds [10 x [4 x [[S_FLOAT_TY, [10 x [4 x [[S_FLOAT_TY* [[ARRS_PRIV]], i32 0, i32 0, i32 0
+// CHECK: [[END:%.+]] = getelementptr inbounds [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[BEGIN]], i64 40
+// CHECK: br label %[[CTOR:[^,]+]]
+// CHECK: [[CTOR]]:
+// CHECK: [[CUR:%.+]] = phi [[S_FLOAT_TY]]* [ [[BEGIN]], %{{.+}} ], [ [[NEXT:%.+]], %[[CTOR]] ]
+// CHECK: call void @_ZN1SIfEC1Ev([[S_FLOAT_TY]]* [[CUR]])
+// CHECK: [[NEXT:%.+]] = getelementptr inbounds [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[CUR]], i64 1
+// CHECK: [[IS_DONE:%.+]] = icmp eq [[S_FLOAT_TY]]* [[NEXT]], [[END]]
+// CHECK: br i1 [[IS_DONE]], label %[[DONE:[^,]+]], label %[[CTOR]]
+// CHECK: [[DONE]]:
+
+// CHECK: [[BEGIN:%.+]] = getelementptr inbounds [10 x [4 x [[S_FLOAT_TY, [10 x [4 x [[S_FLOAT_TY* [[ARRS_PRIV]], i32 0, i32 0, i32 0
 // CHECK: [[LHS_BEGIN:%.+]] = bitcast [10 x [4 x [[S_FLOAT_TY* %{{.+}} to [[S_FLOAT_TY]]*
 // CHECK: [[END:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[BEGIN]], i64 40
 // CHECK: [[ISEMPTY:%.+]] = icmp eq [[S_FLOAT_TY]]* [[BEGIN]], [[END]]
@@ -901,9 +914,11 @@
 // For + reduction operation initial value of private variable is 0.
 // CHECK: call void [[RED_INIT6:@.+]](
 
+// CHECK: call void @_ZN1SIiEC1Ev([[S_INT_TY]]* [[VAR_PRIV]]
 // For & reduction operation initial value of private variable is ones in all bits.
 // CHECK: call void [[RED_INIT2:@.+]](
 
+// CHECK: call void @_ZN1SIiEC1Ev([[S_INT_TY]]* [[VAR1_PRIV]]
 // For && reduction operation initial value of private variable is 1.0.
 // CHECK: call void [[RED_INIT7:@.+]](
 
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -15153,6 +15153,7 @@
   auto *DRDRef = DeclareReductionRef.getAs();
   auto *DRD = cast(DRDRef->getDecl());
   if (DRD->getInitializer()) {
+S.ActOnUninitializedDecl(PrivateVD);
 Init = DRDRef;
 RHSVD->setInit(DRDRef);
 RHSVD->setInitStyle(VarDecl::CallInit);
@@ -15259,10 +15260,19 @@
 llvm_unreachable("Unexpected reduction operation");
   }
 }
-if (Init && DeclareReductionRef.isUnset())
+if (Init && DeclareReductionRef.isUnset()) {
   S.AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false);
-else if (!Init)
+  // Store initializer for single element in private copy. Will be used
+  // during codegen.
+  PrivateVD->setInit(RHSVD->getInit());
+  PrivateVD->setInitStyle(RHSVD->getInitStyle());
+} else if (!Init) {
   S.ActOnUninitializedDecl(RHSVD);
+  // Store initializer for single element in private copy. Will be used
+  // during codegen.
+  PrivateVD->setInit(RHSVD->getInit());
+  PrivateVD->setInitStyle(RHSVD->getInitStyle());
+}
 if (RHSVD->isInvalidDecl())
   continue;
 if (!RHSVD->hasInit() &&
@@ -15276,10 +15286,6 @@
   << D;
   continue;
 }
-// Store initializer for single element in private copy. Will be used during
-// codegen.
-PrivateVD->setInit(RHSVD->getInit());
-PrivateVD->setInitStyle(RHSVD->getInitStyle());
 DeclRefExpr *PrivateDRE = buildDeclRefExpr(S, PrivateVD, PrivateTy, ELoc);
 ExprResult ReductionOp;
 if (DeclareReductionRef.isUsable()) {
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -886,8 +886,11 @@
   SharedType, SharedAddresses[N].first.getBaseInfo(),
   CGF.CGM.getTBAAInfoForSubobject(SharedAddresses[N].first, SharedType));
   if (CGF.getContext().getAsArrayType(PrivateVD->getType())) {
+if (DRD && 

[PATCH] D83652: Merge some of the PCH object support with modular codegen

2020-07-13 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D83652#2146732 , @llunak wrote:

> The patch is incomplete, isn't it? It removes DeclIsFromPCHWithObjectFile(), 
> but it's still called from ASTContext::DeclMustBeEmitted(). The description 
> also mentions updating of the pch-codegen test, but that's not included.


Ah, right you are - arc diff only took the last commit on this branch. I've 
updated it/used arc correctly to get the whole branch worth of changes.

> But assuming this is intended to replace the D48426 
>  functionality with modular codegen,

Not quite - it's intended to implement the D48426 
 functionality using an implementation 
strategy that is closer to modular code generation. Removing the need for the 
module flag, using the MODULAR_CODEGEN_DECLS list, etc. But only putting the 
dllexported entities in there (when using only building-pch-with-obj without 
-fmodules-codegen).

The intent is not to change the behavior of D48426 
, but to simplify the implementation a bit by 
reducing the divergence between the two features.

>> Do either of you know if it'd be practical to move to something more similar 
>> to .pcm handling, where the pch itself is passed to the compilation, rather 
>> than homed as a side effect of compiling some other source file?
> 
> Do you mean dropping compatibility with 'cl.exe /Yc'?

Yep, that was essentially what I was wondering - since you were proposing a 
build mode/flags that would not be /Yc compatible, adding an explicit pch build 
and pch object build step - was wondering if the build system support for that 
was sufficiently available that it would be practical for users (like Chromium) 
to migrate to that kind of model and no longer need /Yc compatibility. That 
would further reduce some of the divergence between the two features (then it'd 
come down to only a "what entities do we want to home" question - the mechanics 
of homing them, building their object file, etc, would all be the same).

In D83652#2147097 , @hans wrote:

> In D83652#2146732 , @llunak wrote:
>
> > > Do either of you know if it'd be practical to move to something more 
> > > similar to .pcm handling, where the pch itself is passed to the 
> > > compilation, rather than homed as a side effect of compiling some other 
> > > source file?
> >
> > Do you mean dropping compatibility with 'cl.exe /Yc'?
>
>
> I don't think we can change the interface, because we want cl.exe 
> compatibility.


Fair enough - I guess the only other way to get the cl.exe behavior from the 
Clang driver using modular codegen-type functionality would be to use 4 steps:

- build PCH (with dllexport modular codegen)
- build PCH object file using PCH
- build source object using PCH
- ld -r the two objects together

But I guess the added driver complexity isn't worth the simplification inside 
Clang proper, probably. I guess we already have the "build PCH then use PCH to 
build object" part so /maybe/ it'd be feasible to extend it in this way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83652



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


[PATCH] D83652: Merge some of the PCH object support with modular codegen

2020-07-13 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D83652#2146732 , @llunak wrote:

> > Do either of you know if it'd be practical to move to something more 
> > similar to .pcm handling, where the pch itself is passed to the 
> > compilation, rather than homed as a side effect of compiling some other 
> > source file?
>
> Do you mean dropping compatibility with 'cl.exe /Yc'?


I don't think we can change the interface, because we want cl.exe compatibility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83652



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


[PATCH] D83296: [clang-format] Add a MacroExpander.

2020-07-13 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/MacroExpander.cpp:150
+Tok->MacroCtx.ExpandedFrom.push_back(ID);
+if (First) {
+  Tok->MacroCtx.StartOfExpansion = true;

elide braces?



Comment at: clang/unittests/Format/MacroExpanderTest.cpp:5
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"

are you using this?



Comment at: clang/unittests/Format/MacroExpanderTest.cpp:55
+  .str();
+  EXPECT_TRUE(Tokens[I]->is(Attributes[I].Kind))
+  << Context << " in " << text(Tokens);

when these assertions fail you have no idea which of the various calls is 
actually failing how about passing in __FILE__,__LINE__ then adding that to the 
output


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83296



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


[PATCH] D83681: [clang] Diagnose a misplaced lambda capture-default.

2020-07-13 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno created this revision.
riccibruno added reviewers: rsmith, aaron.ballman.
riccibruno added a project: clang.
Herald added a subscriber: cfe-commits.

Currently a capture-default which is not the first element in the 
lambda-capture is diagnosed with a generic `expected variable name or 'this' in 
lambda capture list`, which is true but not very helpful.

If we don't have already parsed a capture-default then a lone "&" or "=" is 
likely to be a misplaced capture-default, so diagnose it as such.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83681

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/lambda-misplaced-capture-default.cpp


Index: clang/test/Parser/lambda-misplaced-capture-default.cpp
===
--- /dev/null
+++ clang/test/Parser/lambda-misplaced-capture-default.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace misplaced_capture_default {
+void Test() {
+  int i = 0;
+  [&, i, &] {};   // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [&, i, = ] {};  // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [=, , &] {};  // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [=, , = ] {}; // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+
+  [i, &] {};  // expected-error {{misplaced capture default}}
+  // expected-note@-1 {{capture default must be first}}
+
+  [i, = ] {}; // expected-error {{misplaced capture default}}
+  // expected-note@-1 {{capture default must be first}}
+
+  [i, = x] {};// expected-error {{expected variable name or 'this' in 
lambda capture list}}
+
+  [i, &, x = 2] {}; // expected-error {{misplaced capture default}}
+// expected-note@-1 {{capture default must be first}}
+
+  [i, =, x = 2] {}; // expected-error {{misplaced capture default}}
+// expected-note@-1 {{capture default must be first}}
+}
+} // namespace misplaced_capture_default
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -926,6 +926,17 @@
 } else if (Tok.is(tok::kw_this)) {
   Kind = LCK_This;
   Loc = ConsumeToken();
+} else if (Tok.isOneOf(tok::amp, tok::equal) &&
+   NextToken().isOneOf(tok::comma, tok::r_square) &&
+   Intro.Default == LCD_None) {
+  // We have a lone "&" or "=" which is either a misplaced capture-default
+  // or the start of a capture (in the "&" case) with the rest of the
+  // capture missing. Both are an error but a misplaced capture-default
+  // is more likely if we don't already have a capture default.
+  return Invalid([&] {
+Diag(Tok.getLocation(), diag::err_misplaced_capture_default);
+Diag(T.getOpenLocation(), diag::note_capture_default_first);
+  });
 } else {
   TryConsumeToken(tok::ellipsis, EllipsisLocs[0]);
 
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -934,6 +934,10 @@
   "the name of the capture">;
 def err_lambda_capture_multiple_ellipses : Error<
   "multiple ellipses in pack capture">;
+def err_misplaced_capture_default : Error<
+  "misplaced capture default">;
+def note_capture_default_first : Note<
+  "capture default must be first">;
 // C++17 lambda expressions
 def err_expected_star_this_capture : Error<
   "expected 'this' following '*' in lambda capture list">;


Index: clang/test/Parser/lambda-misplaced-capture-default.cpp
===
--- /dev/null
+++ clang/test/Parser/lambda-misplaced-capture-default.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace misplaced_capture_default {
+void Test() {
+  int i = 0;
+  [&, i, &] {};   // expected-error {{expected variable name or 'this' in lambda capture list}}
+  [&, i, = ] {};  // expected-error {{expected variable name or 'this' in lambda capture list}}
+  [=, , &] {};  // expected-error {{expected variable name or 'this' in lambda capture list}}
+  [=, , = ] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
+
+  [i, &] {};  // expected-error {{misplaced capture default}}
+  // expected-note@-1 {{capture default must be first}}
+
+  [i, = ] {}; // expected-error {{misplaced capture default}}
+  // expected-note@-1 {{capture default must be first}}
+
+  [i, = x] {};// expected-error {{expected variable name or 'this' 

[PATCH] D82502: [PowerPC][Power10] Implement Load VSX Vector and Sign Extend and Zero Extend

2020-07-13 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 277418.
Conanap added a comment.

Removed duplicate test code found in the instructions and MC Test 
implementation of VSX Vector store and load with sign extend or zero extend; 
re-added a test file that was omitted in the last diff update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82502

Files:
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/ISA31-vsx-builtins.ll
  llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt

Index: llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt
===
--- llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt
+++ llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt
@@ -302,3 +302,15 @@
 
 # CHECK: stxvrdx 35, 3, 1
 0x7c 0x63 0x09 0xdb
+
+# CHECK: lxvrbx 32, 1, 2
+0x7c 0x01 0x10 0x1b
+
+# CHECK: lxvrhx 33, 1, 2
+0x7c 0x21 0x10 0x5b
+
+# CHECK: lxvrdx 34, 1, 2
+0x7c 0x41 0x10 0xdb
+
+# CHECK: lxvrwx 35, 1, 2
+0x7c 0x61 0x10 0x9b
Index: llvm/test/CodeGen/PowerPC/ISA31-vsx-builtins.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/ISA31-vsx-builtins.ll
@@ -0,0 +1,65 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; These test cases tests that zero extending loads utilize the Load VSX Vector Rightmost
+; (lxvr[b|h|w|d]x) instructions in Power10.
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | \
+; RUN:   FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | \
+; RUN:   FileCheck %s
+
+define dso_local <1 x i128> @vec_xl_zext(i64 %__offset, i8* nocapture readonly %__pointer) {
+; CHECK-LABEL: vec_xl_zext:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:lxvrbx v2, r4, r3
+; CHECK-NEXT:blr
+entry:
+  %add.ptr = getelementptr inbounds i8, i8* %__pointer, i64 %__offset
+  %0 = load i8, i8* %add.ptr, align 1
+  %conv = zext i8 %0 to i128
+  %splat.splatinsert = insertelement <1 x i128> undef, i128 %conv, i32 0
+  ret <1 x i128> %splat.splatinsert
+}
+
+define dso_local <1 x i128> @vec_xl_zext_short(i64 %__offset, i16* nocapture readonly %__pointer) {
+; CHECK-LABEL: vec_xl_zext_short:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:sldi r3, r3, 1
+; CHECK-NEXT:lxvrhx v2, r4, r3
+; CHECK-NEXT:blr
+entry:
+  %add.ptr = getelementptr inbounds i16, i16* %__pointer, i64 %__offset
+  %0 = load i16, i16* %add.ptr, align 2
+  %conv = zext i16 %0 to i128
+  %splat.splatinsert = insertelement <1 x i128> undef, i128 %conv, i32 0
+  ret <1 x i128> %splat.splatinsert
+}
+
+define dso_local <1 x i128> @vec_xl_zext_word(i64 %__offset, i32* nocapture readonly %__pointer) {
+; CHECK-LABEL: vec_xl_zext_word:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:sldi r3, r3, 2
+; CHECK-NEXT:lxvrwx v2, r4, r3
+; CHECK-NEXT:blr
+entry:
+  %add.ptr = getelementptr inbounds i32, i32* %__pointer, i64 %__offset
+  %0 = load i32, i32* %add.ptr, align 4
+  %conv = zext i32 %0 to i128
+  %splat.splatinsert = insertelement <1 x i128> undef, i128 %conv, i32 0
+  ret <1 x i128> %splat.splatinsert
+}
+
+define dso_local <1 x i128> @vec_xl_zext_dw(i64 %__offset, i64* nocapture readonly %__pointer) {
+; CHECK-LABEL: vec_xl_zext_dw:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:sldi r3, r3, 3
+; CHECK-NEXT:lxvrdx v2, r4, r3
+; CHECK-NEXT:blr
+entry:
+  %add.ptr = getelementptr inbounds i64, i64* %__pointer, i64 %__offset
+  %0 = load i64, i64* %add.ptr, align 8
+  %conv = zext i64 %0 to i128
+  %splat.splatinsert = insertelement <1 x i128> undef, i128 %conv, i32 0
+  ret <1 x i128> %splat.splatinsert
+}
+
Index: llvm/lib/Target/PowerPC/PPCInstrPrefix.td
===
--- llvm/lib/Target/PowerPC/PPCInstrPrefix.td
+++ llvm/lib/Target/PowerPC/PPCInstrPrefix.td
@@ -18,6 +18,15 @@
 // address computations).
 class isPCRel { bit PCRel = 1; }
 
+// PowerPC specific type constraints.
+def SDT_PPCLXVRZX : SDTypeProfile<1, 2, [
+  SDTCisVT<0, v1i128>, SDTCisPtrTy<1>, SDTCisPtrTy<2>
+]>;
+
+// PPC Specific DAG Nodes.
+def PPClxvrzx : SDNode<"PPCISD::LXVRZX", SDT_PPCLXVRZX,
+   [SDNPHasChain, SDNPMayLoad]>;
+
 // Top-level class for prefixed instructions.
 class PI pref, bits<6> opcode, dag OOL, dag IOL, string asmstr,
  InstrItinClass itin> : Instruction {
Index: llvm/lib/Target/PowerPC/PPCISelLowering.h
===
--- 

[PATCH] D79719: [AIX] Implement AIX special alignment rule about double/long double

2020-07-13 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L added inline comments.



Comment at: clang/test/Layout/aix-Wpacked-no-diagnostics.cpp:15
+
+int a = sizeof(QQ);

hubert.reinterpretcast wrote:
> Is there a reason to drop the `FileCheck` checking for the layout?
I dropped the `FileCheck` because the layout of `QQ` and `Q` are fairly simple 
and wanted the test focus more on `no-diagnostics` side. But I can add it back 
if that helps.


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

https://reviews.llvm.org/D79719



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


[PATCH] D83120: [Analyzer][StreamChecker] Using BugType::SuppressOnSink at resource leak report.

2020-07-13 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: clang/test/Analysis/stream.c:274-284
 // Check that "location uniqueing" works.
 // This results in reporting only one occurence of resource leak for a stream.
 void check_leak_noreturn_2() {
   FILE *F1 = tmpfile();
   if (!F1)
 return;
   if (Test == 1) {

NoQ wrote:
> balazske wrote:
> > Szelethus wrote:
> > > Why did this change? Is there a sink in the return branch?
> > The change is probably because D83115. Because the "uniqueing" one resource 
> > leak is reported from the two possible, and the order changes somehow 
> > (probably not the shortest is found first).
> The shortest should still be found first. I strongly suggest debugging this. 
> Looks like a bug in suppress-on-sink.
There is no code that ensures that the shortest path is reported. In this case 
one equivalence class is created with both bug reports. If `SuppressOnSink` is 
false the last one is returned from the list, otherwise the first one 
(`PathSensitiveBugReporter::findReportInEquivalenceClass`), this causes the 
difference (seems to be unrelated to D83115).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83120



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


[PATCH] D83550: [PATCH 1/4][Sema][AArch64] Add parsing support for arm_sve_vector_bits attribute

2020-07-13 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2806
+def err_attribute_bad_sve_vector_size : Error<
+  "unsupported SVE vector size '%0'">;
+def err_attribute_arm_feature_sve_bits_macro_not_defined : Error<

Do you want to be more specific in the wording here by saying that it doesn't 
match the value set by -msve-vector-bits?



Comment at: clang/lib/Sema/SemaType.cpp:7784
+  // The __ARM_FEATURE_SVE_BITS macro must be defined when using this 
attribute.
+  auto  = S.getPreprocessor();
+  if (!PP.isMacroDefined("__ARM_FEATURE_SVE_BITS")) {

I think that the code that checks if the value of the attribute matches the 
value set by -msve-vector-bits should be part of Sema, not the parser. Also I'm 
tempted to suggest decoupling the value of the macro from the code that checks 
the attribute-value matches -msve-vector-bits.

If the arm_sve.h header file defines a constant value like this:
```#if defined(__ARM_SVE_FEATURE_BITS)
const unsigned __arm_sve_feature_bits = __ARM_SVE_FEATURE_BITS
#endif```
You can check for the availability and value of this constant in the AST during 
semantic analysis. That way, if for whatever reason the value of the macro is 
redefined, the compiler can issue a diagnostic. Ideally we would insert a 
`__arm_sve_feature_bits` constant into the compilation unit directly when 
-msve-vector-bits is passed, but I don't know Clang enough to suggest where or 
at which point to add that.



Comment at: clang/lib/Sema/SemaType.cpp:7795
+  if (!MI)
+llvm_unreachable("Bad macro!");
+

Should this just be an `assert` instead? `MI` should never be nullptr if 
`isMacrodefined(..)` returns `true`.



Comment at: clang/lib/Sema/SemaType.cpp:7809
+S.Diag(Attr.getLoc(),
+   diag::err_attribute_arm_feature_sve_bits_macro_argument_type);
+Attr.setInvalid();

__ARM_FEATURE_SVE_BITS is never supposed to be set by the user, so the parsing 
and diagnostic can be simplified, e.g.
```if(MI->getNumTokens() != 1 || 
MI->tokens().front().isNot(tok::numeric_constant)) {
  S.Diag(Attr.getLoc(), diag::err_arm_feature_sve_bits_macro_broken)
  Attr.setInvalid();
  return;
}```
but this is probably no longer relevant if you implement the suggestion above 
on line 7784.



Comment at: clang/lib/Sema/SemaType.cpp:7815
+  // The attribute vector size must equal __ARM_FEATURE_SVE_BITS.
+  ExprResult ExprRes = S.ActOnNumericConstant(ArmFeatureSveBitsTok);
+  const auto *ArmSveFeatureBits = dyn_cast(ExprRes.get());

nit: `ExprRes` is not very descriptive, how about 
`ArmFeatureSveBitsMacroExprRes` ?



Comment at: clang/lib/Sema/SemaType.cpp:7818
+  unsigned VecSize = static_cast(SveVectorSizeInBits.getZExtValue());
+  if (ArmSveFeatureBits->getValue() != VecSize) {
+S.Diag(Attr.getLoc(), diag::err_attribute_bad_sve_vector_size) << VecSize;

`ArmSveFeatureBits` can be `nullptr`. Or it shouldn't use `dyn_cast`.



Comment at: clang/test/Sema/arm-feature-sve-bits-macro.c:1
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sve -fsyntax-only -verify 
-D__ARM_FEATURE_SVE_BITS=512 -D__ARM_FEATURE_SVE 
-fallow-half-arguments-and-returns %s
+

nit: `-D__ARM_FEATURE_SVE` is no longer necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83550



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


[PATCH] D79719: [AIX] Implement AIX special alignment rule about double/long double

2020-07-13 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L updated this revision to Diff 277417.
Xiangling_L added a comment.

Removed unused var;


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

https://reviews.llvm.org/D79719

Files:
  clang/include/clang/AST/RecordLayout.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/RecordLayout.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/PPC.h
  clang/test/Layout/aix-Wpacked-expecting-diagnostics.cpp
  clang/test/Layout/aix-Wpacked-no-diagnostics.cpp
  clang/test/Layout/aix-double-struct-member.cpp
  clang/test/Layout/aix-no-unique-address-with-double.cpp
  clang/test/Layout/aix-pack-attr-on-base.cpp
  clang/test/Layout/aix-power-alignment-typedef.cpp
  clang/test/Layout/aix-virtual-function-and-base-with-double.cpp

Index: clang/test/Layout/aix-virtual-function-and-base-with-double.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-virtual-function-and-base-with-double.cpp
@@ -0,0 +1,112 @@
+// RUN: %clang_cc1 -emit-llvm-only -triple powerpc-ibm-aix-xcoff \
+// RUN: -fdump-record-layouts -fsyntax-only %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK32 %s
+
+// RUN: %clang_cc1 -emit-llvm-only -triple powerpc64-ibm-aix-xcoff \
+// RUN: -fdump-record-layouts -fsyntax-only %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+
+namespace test1 {
+struct A {
+  double d1;
+  virtual void boo() {}
+};
+
+struct B {
+  double d2;
+  A a;
+};
+
+struct C : public A {
+  double d3;
+};
+
+int i = sizeof(B);
+int j = sizeof(C);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:0 | struct test1::A
+// CHECK-NEXT:0 |   (A vtable pointer)
+// CHECK32-NEXT:  4 |   double d1
+// CHECK32-NEXT:| [sizeof=12, dsize=12, align=4, preferredalign=4,
+// CHECK32-NEXT:|  nvsize=12, nvalign=4, preferrednvalign=4]
+// CHECK64-NEXT:  8 |   double d1
+// CHECK64-NEXT:| [sizeof=16, dsize=16, align=8, preferredalign=8,
+// CHECK64-NEXT:|  nvsize=16, nvalign=8, preferrednvalign=8]
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:0 | struct test1::B
+// CHECK-NEXT:0 |   double d2
+// CHECK-NEXT:8 |   struct test1::A a
+// CHECK-NEXT:8 | (A vtable pointer)
+// CHECK32-NEXT: 12 | double d1
+// CHECK32-NEXT:| [sizeof=24, dsize=20, align=4, preferredalign=8,
+// CHECK32-NEXT:|  nvsize=20, nvalign=4, preferrednvalign=8]
+// CHECK64-NEXT: 16 | double d1
+// CHECK64-NEXT:| [sizeof=24, dsize=24, align=8, preferredalign=8,
+// CHECK64-NEXT:|  nvsize=24, nvalign=8, preferrednvalign=8]
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:0 | struct test1::C
+// CHECK-NEXT:0 |   struct test1::A (primary base)
+// CHECK-NEXT:0 | (A vtable pointer)
+// CHECK32-NEXT:  4 | double d1
+// CHECK32-NEXT: 12 |   double d3
+// CHECK32-NEXT:| [sizeof=20, dsize=20, align=4, preferredalign=4,
+// CHECK32-NEXT:|  nvsize=20, nvalign=4, preferrednvalign=4]
+// CHECK64-NEXT:  8 | double d1
+// CHECK64-NEXT: 16 |   double d3
+// CHECK64-NEXT:| [sizeof=24, dsize=24, align=8, preferredalign=8,
+// CHECK64-NEXT:|  nvsize=24, nvalign=8, preferrednvalign=8]
+
+} // namespace test1
+
+namespace test2 {
+struct A {
+  long long l1;
+};
+
+struct B : public virtual A {
+  double d2;
+};
+
+#pragma pack(2)
+struct C : public virtual A {
+  double __attribute__((aligned(4))) d3;
+};
+
+int i = sizeof(B);
+int j = sizeof(C);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:0 | struct test2::A
+// CHECK-NEXT:0 |   long long l1
+// CHECK-NEXT:  | [sizeof=8, dsize=8, align=8, preferredalign=8,
+// CHECK-NEXT:  |  nvsize=8, nvalign=8, preferrednvalign=8]
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:0 | struct test2::B
+// CHECK-NEXT:0 |   (B vtable pointer)
+// CHECK32-NEXT:  4 |   double d2
+// CHECK64-NEXT:  8 |   double d2
+// CHECK-NEXT:   16 |   struct test2::A (virtual base)
+// CHECK-NEXT:   16 | long long l1
+// CHECK-NEXT:  | [sizeof=24, dsize=24, align=8, preferredalign=8,
+// CHECK32-NEXT:|  nvsize=12, nvalign=4, preferrednvalign=4]
+// CHECK64-NEXT:|  nvsize=16, nvalign=8, preferrednvalign=8]
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:0 | struct test2::C
+// CHECK-NEXT:0 |   (C vtable pointer)
+// CHECK32-NEXT:  4 |   double d3
+// CHECK32-NEXT: 12 |   struct test2::A (virtual base)
+// CHECK32-NEXT: 12 | long long l1
+// CHECK32-NEXT:| 

[PATCH] D81958: [clangd] Add library to semantically strip flags by name.

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall planned changes to this revision.
sammccall added a comment.

Need to work out how to address the order-dependency comment.




Comment at: clang-tools-extra/clangd/CompileCommands.cpp:431
+continue; // current arg doesn't match the prefix string
+  bool PrefixMatch = Arg.size() > R.Text.size();
+  unsigned ArgCount = PrefixMatch ? R.PrefixArgs : R.ExactArgs;

adamcz wrote:
> Correct me if I'm wrong, but this is relying on the fact that Rules are 
> sorted, right? Or, to be more specific, on the fact that -foo comes before 
> -foobar.
> 
> Consider two rules in config file, one to remove -include, another to remove 
> -include-pch, in that order. -include will do a prefix match on Arg == 
> -include-pch and attempt to remove exactly one arg (-include is 
> JoinedOrSeparate, which has 1 for PrefixArgs), when in reality that was 
> "--include-pch foo.pch", an exact match on a different option.
> 
> So a config like:
> Remove: [-include, -include-pch]
> and command line:
> [-include-pch, foo.pch]
> should be [], but ends up being [foo.pch]
> 
> It looks like Options.inc is sorted in the correct way (include-pch will 
> always be before -include). I don't know if that's guaranteed, but it looks 
> to be the case. However, since you are adding these options to Rules on each 
> strip() call, you end up depending on the order of strip() calls. That seems 
> like a bug.
This is a really good point, I hadn't realized the option table was 
order-dependent (e.g. I figured -include wasn't a Joined option).

The real option parser processes the options in the order they appear in the 
file, so that should definitely be correct.
I think processing them longest-to-shortest is probably also correct, since a 
spelling that's always shadowed by a prefix isn't that useful, I'd hope they 
don't actually exist.



Comment at: clang-tools-extra/clangd/CompileCommands.h:60
+// Args that are not recognized as flags are still removed as literal strings,
+// and strip("ABC*") will remove any arg with an ABC prefix.
+//

hokein wrote:
> Is the glob `*` supported when the Arg (in `strip` API) is recognized as an 
> option flag? My reading of the code implies it is not.
> 
> Maybe consider moving the above two lines to `strip` API comment, it is more 
> discoverable.
Yeah you're right, thought I'd phrase more as "-foo*" is never a recognized 
flag :-)
I've moved the comment as you suggest and regrouped to be clearer.



Comment at: clang-tools-extra/clangd/CompileCommands.h:72
+  // Remove the targets from Args, in-place.
+  void process(std::vector ) const;
+

hokein wrote:
> The `Args` is expected to be a standard compile command? if so, might be name 
> it `CompileCommand`.
We have this annoying clang-tidy check that wants the impl and decl to have the 
same arg names, and CompileCommand is too long for the impl.

Updated the doc though.



Comment at: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp:197
+}
+
+TEST(ArgStripperTest, Spellings) {

hokein wrote:
> add tests for stripping the diagnostic flags, `-Wfoo` etc.
Those aren't actually separate flags: "-W" is a Joined flag and foo is an arg.
Do you want a test specifically for such a string anyway?
Or do you want special behavior for them? (Like interaction between -Wfoo and 
-Wno-foo)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81958



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


[PATCH] D71760: [POC][SVE] Allow code generation for fixed length vectorised loops [Patch 1/2].

2020-07-13 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm updated this revision to Diff 277452.
paulwalker-arm removed reviewers: rengolin, efriedma.
paulwalker-arm added a subscriber: efriedma.
paulwalker-arm added a comment.
Herald added a reviewer: rengolin.
Herald added a reviewer: efriedma.
Herald added subscribers: cfe-commits, dang.
Herald added a project: clang.

Rebasing to reflect the majority of the functionality is now in master.  What 
remains is likely to be abandoned in favour of function attributes but it's 
here for those who want to experiment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71760

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/lib/Target/AArch64/AArch64FrameLowering.cpp


Index: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -1819,7 +1819,7 @@
 if (FPOffsetFits && CanUseBP) // Both are ok. Pick the best.
   UseFP = PreferFP;
 else if (!CanUseBP) { // Can't use BP. Forced to use FP.
-  assert(!SVEStackSize && "Expected BP to be available");
+  // assert(!SVEStackSize && "Expected BP to be available");
   UseFP = true;
 }
 // else we can use BP and FP, but the offset from FP won't fit.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -1715,6 +1715,22 @@
 if (IndirectBranches)
   CmdArgs.push_back("-mbranch-target-enforce");
   }
+
+  if (any_of(CmdArgs, [](const char *Arg) {
+return (strcmp(Arg, "+sve") == 0 || strcmp(Arg, "+sve2") == 0);
+  })) {
+if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits)) {
+  StringRef Bits = A->getValue();
+  if (Bits != "scalable") {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(
+Args.MakeArgString("-aarch64-sve-vector-bits-min=" + Bits));
+// CmdArgs.push_back("-mllvm");
+// CmdArgs.push_back(
+//Args.MakeArgString("-aarch64-sve-vector-bits-max=" + Bits));
+  }
+}
+  }
 }
 
 void Clang::AddMIPSTargetArgs(const ArgList ,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2351,6 +2351,10 @@
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,
   HelpText<"Select straight-line speculation hardening scope">;
+def msve_vector_bits : Joined<["-"], "msve-vector-bits=">,
+  Group,
+  HelpText<"Specify the size in bits of an SVE vector register."
+   " Has no effect unless SVE is enabled. (Default is \"scalable\")">;
 
 def msimd128 : Flag<["-"], "msimd128">, Group;
 def munimplemented_simd128 : Flag<["-"], "munimplemented-simd128">, 
Group;


Index: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -1819,7 +1819,7 @@
 if (FPOffsetFits && CanUseBP) // Both are ok. Pick the best.
   UseFP = PreferFP;
 else if (!CanUseBP) { // Can't use BP. Forced to use FP.
-  assert(!SVEStackSize && "Expected BP to be available");
+  // assert(!SVEStackSize && "Expected BP to be available");
   UseFP = true;
 }
 // else we can use BP and FP, but the offset from FP won't fit.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -1715,6 +1715,22 @@
 if (IndirectBranches)
   CmdArgs.push_back("-mbranch-target-enforce");
   }
+
+  if (any_of(CmdArgs, [](const char *Arg) {
+return (strcmp(Arg, "+sve") == 0 || strcmp(Arg, "+sve2") == 0);
+  })) {
+if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits)) {
+  StringRef Bits = A->getValue();
+  if (Bits != "scalable") {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(
+Args.MakeArgString("-aarch64-sve-vector-bits-min=" + Bits));
+// CmdArgs.push_back("-mllvm");
+// CmdArgs.push_back(
+//Args.MakeArgString("-aarch64-sve-vector-bits-max=" + Bits));
+  }
+}
+  }
 }
 
 void Clang::AddMIPSTargetArgs(const ArgList ,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2351,6 +2351,10 @@
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,
   HelpText<"Select 

[PATCH] D80802: [RISCV] Upgrade RVV MC to v0.9.

2020-07-13 Thread Ferran Pallarès Roca via Phabricator via cfe-commits
fpallares added inline comments.



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2386
+CheckReg = Inst.getOperand(3).getReg();
 }
+if (DestReg == CheckReg)

fpallares wrote:
> With the suggestion above, this could be further simplified to:
> 
> ```
> ​if ((TargetFlags & RISCV::OneInput && Inst.getNumOperands() == 3) || 
> Inst.getNumOperands() == 4)
> ​  return Error(Loc, "The destination vector register group cannot 
> overlap"
>   ​" the mask register.");
> ```
I see you have updated the patch and removed the `if` that checked whether we 
were dealing with the masked versions of the instructions (by checking the 
number of operands). IIUC that check is still necessary so we don't report an 
error for unmasked instruction.

For example, from my understanding the following instruction is correct, but we 
will be reporting an error.
```
viota.m v0, v2
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80802



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


[PATCH] D83494: [libFuzzer] Link libFuzzer's own interceptors when other compiler runtimes are not linked.

2020-07-13 Thread Dokyung Song via Phabricator via cfe-commits
dokyungs updated this revision to Diff 277462.
dokyungs added a comment.

Add interceptors for all the functions libFuzzer has a weak interceptor for, 
and duplicate existing interceptor test cases with new compiler flags 
(-fno-sanitize=address).

Builtin libfunc optimizations may transform memcmp and strcmp-like functions. 
To disable such optimizations, -fno-builtin= flag was additionally added in 
compiling new test cases. FWIW, the original test cases didn't require such 
flags since other sanitizers including ASan disables those optimizations in 
their LLVM pass by dropping libfunc attribute in the call instructions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83494

Files:
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  compiler-rt/lib/fuzzer/CMakeLists.txt
  compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
  compiler-rt/test/fuzzer/no-asan-memcmp.test
  compiler-rt/test/fuzzer/no-asan-strcmp.test
  compiler-rt/test/fuzzer/no-asan-strncmp.test
  compiler-rt/test/fuzzer/no-asan-strstr.test

Index: compiler-rt/test/fuzzer/no-asan-strstr.test
===
--- /dev/null
+++ compiler-rt/test/fuzzer/no-asan-strstr.test
@@ -0,0 +1,5 @@
+UNSUPPORTED: freebsd
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-strstr %S/StrstrTest.cpp -o %t-StrstrTest
+RUN: not %run %t-StrstrTest   -seed=1 -runs=200   2>&1 | FileCheck %s
+CHECK: BINGO
+
Index: compiler-rt/test/fuzzer/no-asan-strncmp.test
===
--- /dev/null
+++ compiler-rt/test/fuzzer/no-asan-strncmp.test
@@ -0,0 +1,4 @@
+UNSUPPORTED: freebsd
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-strncmp  %S/StrncmpTest.cpp -o %t-StrncmpTest
+RUN: not %run %t-StrncmpTest  -seed=2 -runs=1000   2>&1 | FileCheck %s
+CHECK: BINGO
Index: compiler-rt/test/fuzzer/no-asan-strcmp.test
===
--- /dev/null
+++ compiler-rt/test/fuzzer/no-asan-strcmp.test
@@ -0,0 +1,5 @@
+UNSUPPORTED: freebsd
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-strcmp %S/StrcmpTest.cpp -o %t-StrcmpTest
+RUN: not %run %t-StrcmpTest   -seed=1 -runs=200   2>&1 | FileCheck %s
+CHECK: BINGO
+
Index: compiler-rt/test/fuzzer/no-asan-memcmp.test
===
--- /dev/null
+++ compiler-rt/test/fuzzer/no-asan-memcmp.test
@@ -0,0 +1,4 @@
+UNSUPPORTED: freebsd
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-memcmp %S/MemcmpTest.cpp -o %t-MemcmpTest
+RUN: not %run %t-MemcmpTest   -seed=1 -runs=1000   2>&1 | FileCheck %s
+CHECK: BINGO
Index: compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
===
--- /dev/null
+++ compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
@@ -0,0 +1,157 @@
+//===-- FuzzerInterceptors.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+// Intercept certain libc functions to aid fuzzing.
+// Linked only when other RTs that define their own interceptors are not linked.
+//===--===//
+
+#include "FuzzerBuiltins.h"
+
+#if LIBFUZZER_LINUX
+
+typedef unsigned long uptr;
+
+#include  // for dlsym()
+
+static void *GetFuncAddr(const char *name, uptr wrapper_addr) {
+  void *addr = dlsym(RTLD_NEXT, name);
+  if (!addr) {
+// If the lookup using RTLD_NEXT failed, the sanitizer runtime library is
+// later in the library search order than the DSO that we are trying to
+// intercept, which means that we cannot intercept this function. We still
+// want the address of the real definition, though, so look it up using
+// RTLD_DEFAULT.
+addr = dlsym(RTLD_DEFAULT, name);
+
+// In case `name' is not loaded, dlsym ends up finding the actual wrapper.
+// We don't want to intercept the wrapper and have it point to itself.
+if ((uptr)addr == wrapper_addr)
+  addr = nullptr;
+  }
+  return addr;
+}
+
+extern "C" {
+
+void __sanitizer_weak_hook_memcmp(void *, const void *, const void *, size_t,
+  int);
+void __sanitizer_weak_hook_strncmp(void *, const char *, const char *, size_t,
+   int);
+void __sanitizer_weak_hook_strcmp(void *, const char *, const char *, int);
+void __sanitizer_weak_hook_strncasecmp(void *, const char *, const char *,
+   size_t, int);
+void 

[clang] fdb6953 - [AST] Fix potential nullptr dereference in Expr::HasSideEffects

2020-07-13 Thread Jan Korous via cfe-commits

Author: Jan Korous
Date: 2020-07-13T11:08:51-07:00
New Revision: fdb69539bcd250f6e4f49197c9b8149a7542e3ff

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

LOG: [AST] Fix potential nullptr dereference in Expr::HasSideEffects

Array returned by LambdaExpr::capture_inits() can contain nullptrs.

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

Added: 
clang/unittests/AST/HasSideEffectsTest.cpp

Modified: 
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/Expr.cpp
clang/unittests/AST/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 178f4db77061..6f0b68479b9d 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1931,6 +1931,7 @@ class LambdaExpr final : public Expr,
 
   /// Const iterator that walks over the capture initialization
   /// arguments.
+  /// FIXME: This interface is prone to being used incorrectly.
   using const_capture_init_iterator = Expr *const *;
 
   /// Retrieve the initialization expressions for this lambda's captures.

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 343a271c3394..399e7e13c445 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3629,7 +3629,7 @@ bool Expr::HasSideEffects(const ASTContext ,
   case LambdaExprClass: {
 const LambdaExpr *LE = cast(this);
 for (Expr *E : LE->capture_inits())
-  if (E->HasSideEffects(Ctx, IncludePossibleEffects))
+  if (E && E->HasSideEffects(Ctx, IncludePossibleEffects))
 return true;
 return false;
   }

diff  --git a/clang/unittests/AST/CMakeLists.txt 
b/clang/unittests/AST/CMakeLists.txt
index 2e750ac9ea92..185995d5b5a2 100644
--- a/clang/unittests/AST/CMakeLists.txt
+++ b/clang/unittests/AST/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_unittest(ASTTests
   DeclTest.cpp
   EvaluateAsRValueTest.cpp
   ExternalASTSourceTest.cpp
+  HasSideEffectsTest.cpp
   NamedDeclPrinterTest.cpp
   RecursiveASTVisitorTest.cpp
   SizelessTypesTest.cpp

diff  --git a/clang/unittests/AST/HasSideEffectsTest.cpp 
b/clang/unittests/AST/HasSideEffectsTest.cpp
new file mode 100644
index ..842afd8d7a9c
--- /dev/null
+++ b/clang/unittests/AST/HasSideEffectsTest.cpp
@@ -0,0 +1,86 @@
+//===- unittest/AST/HasSideEffectsTest.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/FunctionExtras.h"
+#include "llvm/ADT/STLExtras.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace clang;
+
+namespace {
+class ProcessASTAction : public clang::ASTFrontendAction {
+public:
+  ProcessASTAction(llvm::unique_function Process)
+  : Process(std::move(Process)) {
+assert(this->Process);
+  }
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance ,
+ StringRef InFile) {
+class Consumer : public ASTConsumer {
+public:
+  Consumer(llvm::function_ref Process)
+  : Process(Process) {}
+
+  void HandleTranslationUnit(ASTContext ) override { Process(Ctx); }
+
+private:
+  llvm::function_ref Process;
+};
+
+return std::make_unique(Process);
+  }
+
+private:
+  llvm::unique_function Process;
+};
+
+class RunHasSideEffects
+: public RecursiveASTVisitor {
+public:
+  RunHasSideEffects(ASTContext& Ctx)
+  : Ctx(Ctx) {}
+
+  bool VisitLambdaExpr(LambdaExpr *LE) {
+LE->HasSideEffects(Ctx);
+return true;
+  }
+
+  ASTContext& Ctx;
+};
+} // namespace
+
+TEST(HasSideEffectsTest, All) {
+  llvm::StringRef Code = R"cpp(
+void Test() {
+  int msize = 4;
+  float arr[msize];
+  [] {};
+}
+  )cpp";
+
+  ASSERT_NO_FATAL_FAILURE(
+clang::tooling::runToolOnCode(
+  std::make_unique(
+  [&](clang::ASTContext ) {
+  RunHasSideEffects Visitor(Ctx);
+  Visitor.TraverseAST(Ctx);
+  }
+  ),
+  Code)
+  );
+
+}



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


[PATCH] D83438: [AST] Fix potential nullptr dereference in Expr::HasSideEffects

2020-07-13 Thread Jan Korous via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfdb69539bcd2: [AST] Fix potential nullptr dereference in 
Expr::HasSideEffects (authored by jkorous).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83438

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/Expr.cpp
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/HasSideEffectsTest.cpp

Index: clang/unittests/AST/HasSideEffectsTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/HasSideEffectsTest.cpp
@@ -0,0 +1,86 @@
+//===- unittest/AST/HasSideEffectsTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/FunctionExtras.h"
+#include "llvm/ADT/STLExtras.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace clang;
+
+namespace {
+class ProcessASTAction : public clang::ASTFrontendAction {
+public:
+  ProcessASTAction(llvm::unique_function Process)
+  : Process(std::move(Process)) {
+assert(this->Process);
+  }
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance ,
+ StringRef InFile) {
+class Consumer : public ASTConsumer {
+public:
+  Consumer(llvm::function_ref Process)
+  : Process(Process) {}
+
+  void HandleTranslationUnit(ASTContext ) override { Process(Ctx); }
+
+private:
+  llvm::function_ref Process;
+};
+
+return std::make_unique(Process);
+  }
+
+private:
+  llvm::unique_function Process;
+};
+
+class RunHasSideEffects
+: public RecursiveASTVisitor {
+public:
+  RunHasSideEffects(ASTContext& Ctx)
+  : Ctx(Ctx) {}
+
+  bool VisitLambdaExpr(LambdaExpr *LE) {
+LE->HasSideEffects(Ctx);
+return true;
+  }
+
+  ASTContext& Ctx;
+};
+} // namespace
+
+TEST(HasSideEffectsTest, All) {
+  llvm::StringRef Code = R"cpp(
+void Test() {
+  int msize = 4;
+  float arr[msize];
+  [] {};
+}
+  )cpp";
+
+  ASSERT_NO_FATAL_FAILURE(
+clang::tooling::runToolOnCode(
+  std::make_unique(
+  [&](clang::ASTContext ) {
+  RunHasSideEffects Visitor(Ctx);
+  Visitor.TraverseAST(Ctx);
+  }
+  ),
+  Code)
+  );
+
+}
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -26,6 +26,7 @@
   DeclTest.cpp
   EvaluateAsRValueTest.cpp
   ExternalASTSourceTest.cpp
+  HasSideEffectsTest.cpp
   NamedDeclPrinterTest.cpp
   RecursiveASTVisitorTest.cpp
   SizelessTypesTest.cpp
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -3629,7 +3629,7 @@
   case LambdaExprClass: {
 const LambdaExpr *LE = cast(this);
 for (Expr *E : LE->capture_inits())
-  if (E->HasSideEffects(Ctx, IncludePossibleEffects))
+  if (E && E->HasSideEffects(Ctx, IncludePossibleEffects))
 return true;
 return false;
   }
Index: clang/include/clang/AST/ExprCXX.h
===
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -1931,6 +1931,7 @@
 
   /// Const iterator that walks over the capture initialization
   /// arguments.
+  /// FIXME: This interface is prone to being used incorrectly.
   using const_capture_init_iterator = Expr *const *;
 
   /// Retrieve the initialization expressions for this lambda's captures.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81958: [clangd] Add library to semantically strip flags by name.

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 277507.
sammccall added a comment.

[clangd] Config: CompileFlags.Remove

While here, add documentation to CompileFlags and CompileFlags.Add.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81958

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp

Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -91,10 +91,12 @@
 
 TEST_F(ConfigCompileTests, CompileCommands) {
   Frag.CompileFlags.Add.emplace_back("-foo");
-  std::vector Argv = {"clang", "a.cc"};
+  Frag.CompileFlags.Remove.emplace_back("--include-directory=");
+  std::vector Argv = {"clang", "-I", "bar/", "a.cc"};
   EXPECT_TRUE(compileAndApply());
-  EXPECT_THAT(Conf.CompileFlags.Edits, SizeIs(1));
-  Conf.CompileFlags.Edits.front()(Argv);
+  EXPECT_THAT(Conf.CompileFlags.Edits, SizeIs(2));
+  for (auto  : Conf.CompileFlags.Edits)
+Edit(Argv);
   EXPECT_THAT(Argv, ElementsAre("clang", "a.cc", "-foo"));
 }
 
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -207,6 +207,120 @@
   EXPECT_THAT(Cmd, ElementsAre(_, "FOO.CC", "--hello", "-fsyntax-only"));
 }
 
+static std::string strip(llvm::StringRef Arg, llvm::StringRef Argv) {
+  llvm::SmallVector Parts;
+  llvm::SplitString(Argv, Parts);
+  std::vector Args = {Parts.begin(), Parts.end()};
+  ArgStripper S;
+  S.strip(Arg);
+  S.process(Args);
+  return llvm::join(Args, " ");
+}
+
+TEST(ArgStripperTest, Spellings) {
+  // May use alternate prefixes.
+  EXPECT_EQ(strip("-pedantic", "clang -pedantic foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-pedantic", "clang --pedantic foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--pedantic", "clang -pedantic foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--pedantic", "clang --pedantic foo.cc"), "clang foo.cc");
+  // May use alternate names.
+  EXPECT_EQ(strip("-x", "clang -x c++ foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-x", "clang --language=c++ foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--language=", "clang -x c++ foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--language=", "clang --language=c++ foo.cc"),
+"clang foo.cc");
+}
+
+TEST(ArgStripperTest, UnknownFlag) {
+  EXPECT_EQ(strip("-xyzzy", "clang -xyzzy foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-xyz*", "clang -xyzzy foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-xyzzy", "clang -Xclang -xyzzy foo.cc"), "clang foo.cc");
+}
+
+TEST(ArgStripperTest, Xclang) {
+  // Flags may be -Xclang escaped.
+  EXPECT_EQ(strip("-ast-dump", "clang -Xclang -ast-dump foo.cc"),
+"clang foo.cc");
+  // Args may be -Xclang escaped.
+  EXPECT_EQ(strip("-add-plugin", "clang -Xclang -add-plugin -Xclang z foo.cc"),
+"clang foo.cc");
+}
+
+TEST(ArgStripperTest, ClangCL) {
+  // /I is a synonym for -I in clang-cl mode only.
+  // Not stripped by default.
+  EXPECT_EQ(strip("-I", "clang -I /usr/inc /Interesting/file.cc"),
+"clang /Interesting/file.cc");
+  // Stripped when invoked as clang-cl.
+  EXPECT_EQ(strip("-I", "clang-cl -I /usr/inc /Interesting/file.cc"),
+"clang-cl");
+  // Stripped when invoked as CL.EXE
+  EXPECT_EQ(strip("-I", "CL.EXE -I /usr/inc /Interesting/file.cc"), "CL.EXE");
+  // Stripped when passed --driver-mode=cl.
+  EXPECT_EQ(strip("-I", "cc -I /usr/inc /Interesting/file.cc --driver-mode=cl"),
+"cc --driver-mode=cl");
+}
+
+TEST(ArgStripperTest, ArgStyles) {
+  // Flag
+  EXPECT_EQ(strip("-Qn", "clang -Qn foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-Qn", "clang -QnZ foo.cc"), "clang -QnZ foo.cc");
+  // Joined
+  EXPECT_EQ(strip("-std=", "clang -std= foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-std=", "clang -std=c++11 foo.cc"), "clang foo.cc");
+  // Separate
+  EXPECT_EQ(strip("-mllvm", "clang -mllvm X foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-mllvm", "clang -mllvmX foo.cc"), "clang -mllvmX foo.cc");
+  // RemainingArgsJoined
+  EXPECT_EQ(strip("/link", "clang-cl /link b c d foo.cc"), "clang-cl");
+  EXPECT_EQ(strip("/link", "clang-cl /linka b c d foo.cc"), "clang-cl");
+  // CommaJoined
+  EXPECT_EQ(strip("-Wl,", "clang -Wl,x,y foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-Wl,", "clang -Wl, foo.cc"), "clang foo.cc");
+  // MultiArg
+  EXPECT_EQ(strip("-segaddr", "clang 

[PATCH] D81958: [clangd] Add library to semantically strip flags by name.

2020-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 277508.
sammccall added a comment.

Sigh, last upload was supposed to be a new patch, not clobber this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81958

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -207,6 +207,120 @@
   EXPECT_THAT(Cmd, ElementsAre(_, "FOO.CC", "--hello", "-fsyntax-only"));
 }
 
+static std::string strip(llvm::StringRef Arg, llvm::StringRef Argv) {
+  llvm::SmallVector Parts;
+  llvm::SplitString(Argv, Parts);
+  std::vector Args = {Parts.begin(), Parts.end()};
+  ArgStripper S;
+  S.strip(Arg);
+  S.process(Args);
+  return llvm::join(Args, " ");
+}
+
+TEST(ArgStripperTest, Spellings) {
+  // May use alternate prefixes.
+  EXPECT_EQ(strip("-pedantic", "clang -pedantic foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-pedantic", "clang --pedantic foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--pedantic", "clang -pedantic foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--pedantic", "clang --pedantic foo.cc"), "clang foo.cc");
+  // May use alternate names.
+  EXPECT_EQ(strip("-x", "clang -x c++ foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-x", "clang --language=c++ foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--language=", "clang -x c++ foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("--language=", "clang --language=c++ foo.cc"),
+"clang foo.cc");
+}
+
+TEST(ArgStripperTest, UnknownFlag) {
+  EXPECT_EQ(strip("-xyzzy", "clang -xyzzy foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-xyz*", "clang -xyzzy foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-xyzzy", "clang -Xclang -xyzzy foo.cc"), "clang foo.cc");
+}
+
+TEST(ArgStripperTest, Xclang) {
+  // Flags may be -Xclang escaped.
+  EXPECT_EQ(strip("-ast-dump", "clang -Xclang -ast-dump foo.cc"),
+"clang foo.cc");
+  // Args may be -Xclang escaped.
+  EXPECT_EQ(strip("-add-plugin", "clang -Xclang -add-plugin -Xclang z foo.cc"),
+"clang foo.cc");
+}
+
+TEST(ArgStripperTest, ClangCL) {
+  // /I is a synonym for -I in clang-cl mode only.
+  // Not stripped by default.
+  EXPECT_EQ(strip("-I", "clang -I /usr/inc /Interesting/file.cc"),
+"clang /Interesting/file.cc");
+  // Stripped when invoked as clang-cl.
+  EXPECT_EQ(strip("-I", "clang-cl -I /usr/inc /Interesting/file.cc"),
+"clang-cl");
+  // Stripped when invoked as CL.EXE
+  EXPECT_EQ(strip("-I", "CL.EXE -I /usr/inc /Interesting/file.cc"), "CL.EXE");
+  // Stripped when passed --driver-mode=cl.
+  EXPECT_EQ(strip("-I", "cc -I /usr/inc /Interesting/file.cc --driver-mode=cl"),
+"cc --driver-mode=cl");
+}
+
+TEST(ArgStripperTest, ArgStyles) {
+  // Flag
+  EXPECT_EQ(strip("-Qn", "clang -Qn foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-Qn", "clang -QnZ foo.cc"), "clang -QnZ foo.cc");
+  // Joined
+  EXPECT_EQ(strip("-std=", "clang -std= foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-std=", "clang -std=c++11 foo.cc"), "clang foo.cc");
+  // Separate
+  EXPECT_EQ(strip("-mllvm", "clang -mllvm X foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-mllvm", "clang -mllvmX foo.cc"), "clang -mllvmX foo.cc");
+  // RemainingArgsJoined
+  EXPECT_EQ(strip("/link", "clang-cl /link b c d foo.cc"), "clang-cl");
+  EXPECT_EQ(strip("/link", "clang-cl /linka b c d foo.cc"), "clang-cl");
+  // CommaJoined
+  EXPECT_EQ(strip("-Wl,", "clang -Wl,x,y foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-Wl,", "clang -Wl, foo.cc"), "clang foo.cc");
+  // MultiArg
+  EXPECT_EQ(strip("-segaddr", "clang -segaddr a b foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-segaddr", "clang -segaddra b foo.cc"),
+"clang -segaddra b foo.cc");
+  // JoinedOrSeparate
+  EXPECT_EQ(strip("-G", "clang -GX foo.cc"), "clang foo.cc");
+  EXPECT_EQ(strip("-G", "clang -G X foo.cc"), "clang foo.cc");
+  // JoinedAndSeparate
+  EXPECT_EQ(strip("-plugin-arg-", "clang -cc1 -plugin-arg-X Y foo.cc"),
+"clang -cc1 foo.cc");
+  EXPECT_EQ(strip("-plugin-arg-", "clang -cc1 -plugin-arg- Y foo.cc"),
+"clang -cc1 foo.cc");
+}
+
+TEST(ArgStripperTest, EndOfList) {
+  // When we hit the end-of-args prematurely, we don't crash.
+  // We consume the incomplete args if we've matched the target option.
+  EXPECT_EQ(strip("-I", "clang -Xclang"), "clang -Xclang");
+  EXPECT_EQ(strip("-I", "clang -Xclang -I"), "clang");
+  EXPECT_EQ(strip("-I", "clang -I -Xclang"), "clang");
+  EXPECT_EQ(strip("-I", "clang -I"), "clang");
+}
+
+TEST(ArgStripperTest, Multiple) {
+  ArgStripper S;
+  S.strip("-o");
+  S.strip("-c");
+  std::vector Args = {"clang", "-o", 

[PATCH] D83707: [OpenMP][NFC] Emit remarks during GPU state machine optimization

2020-07-13 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 277524.
jdoerfert added a comment.

simplify test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83707

Files:
  clang/test/OpenMP/remarks_parallel_in_target_state_machine.c
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Index: llvm/lib/Transforms/IPO/OpenMPOpt.cpp
===
--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -1033,6 +1033,7 @@
 // Check if the function is uses in a __kmpc_kernel_prepare_parallel call at
 // all.
 bool UnknownUse = false;
+bool KernelPrepareUse = false;
 unsigned NumDirectCalls = 0;
 
 SmallVector ToBeReplacedStateMachineUses;
@@ -1049,31 +1050,81 @@
   }
   if (OpenMPOpt::getCallIfRegularCall(*U.getUser(),
   )) {
+KernelPrepareUse = true;
 ToBeReplacedStateMachineUses.push_back();
 return;
   }
   UnknownUse = true;
 });
 
-// If this ever hits, we should investigate.
-if (UnknownUse || NumDirectCalls != 1)
+// Do not emit a remark if we haven't seen a __kmpc_kernel_prepare_parallel
+// use.
+if (!KernelPrepareUse)
   continue;
 
-// TODO: This is not a necessary restriction and should be lifted.
-if (ToBeReplacedStateMachineUses.size() != 2)
+{
+  auto Remark = [&](OptimizationRemark OR) {
+return OR
+   << "Found parallel region that is called through a state machine"
+   << ore::NV("OpenMPParallelRegion", F->getName())
+   << " in non-SPMD target region. This can lead to excessive "
+  "register usage in unrelated kernels in the same translation "
+  "unit due to spurious call edges assumed by ptxas.";
+  };
+  emitRemarkOnFunction(F, "OpenMPParallelRegionInNonSPMD", Remark);
+}
+
+// If this ever hits, we should investigate.
+// TODO: Checking the number of uses is not a necessary restriction and
+// should be lifted.
+if (UnknownUse || NumDirectCalls != 1 ||
+ToBeReplacedStateMachineUses.size() != 2) {
+  {
+auto Remark = [&](OptimizationRemark OR) {
+  return OR << "Parallel region "
+<< ore::NV("OpenMPParallelRegion", F->getName()) << " has "
+<< (UnknownUse ? "unknown" : "unexpected")
+<< " uses; will not attempt to rewrite the state machine.";
+};
+emitRemarkOnFunction(F, "OpenMPParallelRegionInNonSPMD", Remark);
+  }
   continue;
+}
 
 // Even if we have __kmpc_kernel_prepare_parallel calls, we (for now) give
 // up if the function is not called from a unique kernel.
 Kernel K = getUniqueKernelFor(*F);
-if (!K)
+if (!K) {
+  {
+auto Remark = [&](OptimizationRemark OR) {
+  return OR << "Parallel region "
+<< ore::NV("OpenMPParallelRegion", F->getName())
+<< " is not known to be called from a single target region "
+   "only, maybe the surrounding function has external "
+   "linkage?; "
+   "will not attempt to rewrite the state machine use.";
+};
+emitRemarkOnFunction(F, "OpenMPParallelRegionInMultipleKernesl",
+ Remark);
+  }
   continue;
+}
 
 // We now know F is a parallel body function called only from the kernel K.
 // We also identified the state machine uses in which we replace the
 // function pointer by a new global symbol for identification purposes. This
 // ensures only direct calls to the function are left.
 
+{
+  auto Remark = [&](OptimizationRemark OR) {
+return OR << "Replace state machine uses of parallel region "
+  << ore::NV("OpenMPParallelRegion", F->getName())
+  << " called from kernel "
+  << ore::NV("OpenMPParallelRegionKernel", K->getName()) << ".";
+  };
+  emitRemarkOnFunction(F, "OpenMPParallelRegionInNonSPMD", Remark);
+}
+
 Module  = *F->getParent();
 Type *Int8Ty = Type::getInt8Ty(M.getContext());
 
Index: clang/test/OpenMP/remarks_parallel_in_target_state_machine.c
===
--- /dev/null
+++ clang/test/OpenMP/remarks_parallel_in_target_state_machine.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -verify=host -Rpass=openmp -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify  -Rpass=openmp -fopenmp -O2 -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o 

[PATCH] D83494: [libFuzzer] Link libFuzzer's own interceptors when other compiler runtimes are not linked.

2020-07-13 Thread Dokyung Song via Phabricator via cfe-commits
dokyungs updated this revision to Diff 277530.
dokyungs added a comment.

Fixed a few LINT warnings by defining some macros that resemble the ones used 
in other sanitizer interception code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83494

Files:
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  compiler-rt/lib/fuzzer/CMakeLists.txt
  compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
  compiler-rt/test/fuzzer/no-asan-memcmp.test
  compiler-rt/test/fuzzer/no-asan-strcmp.test
  compiler-rt/test/fuzzer/no-asan-strncmp.test
  compiler-rt/test/fuzzer/no-asan-strstr.test

Index: compiler-rt/test/fuzzer/no-asan-strstr.test
===
--- /dev/null
+++ compiler-rt/test/fuzzer/no-asan-strstr.test
@@ -0,0 +1,5 @@
+UNSUPPORTED: freebsd
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-strstr %S/StrstrTest.cpp -o %t-StrstrTest
+RUN: not %run %t-StrstrTest   -seed=1 -runs=200   2>&1 | FileCheck %s
+CHECK: BINGO
+
Index: compiler-rt/test/fuzzer/no-asan-strncmp.test
===
--- /dev/null
+++ compiler-rt/test/fuzzer/no-asan-strncmp.test
@@ -0,0 +1,4 @@
+UNSUPPORTED: freebsd
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-strncmp  %S/StrncmpTest.cpp -o %t-StrncmpTest
+RUN: not %run %t-StrncmpTest  -seed=2 -runs=1000   2>&1 | FileCheck %s
+CHECK: BINGO
Index: compiler-rt/test/fuzzer/no-asan-strcmp.test
===
--- /dev/null
+++ compiler-rt/test/fuzzer/no-asan-strcmp.test
@@ -0,0 +1,5 @@
+UNSUPPORTED: freebsd
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-strcmp %S/StrcmpTest.cpp -o %t-StrcmpTest
+RUN: not %run %t-StrcmpTest   -seed=1 -runs=200   2>&1 | FileCheck %s
+CHECK: BINGO
+
Index: compiler-rt/test/fuzzer/no-asan-memcmp.test
===
--- /dev/null
+++ compiler-rt/test/fuzzer/no-asan-memcmp.test
@@ -0,0 +1,4 @@
+UNSUPPORTED: freebsd
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-memcmp %S/MemcmpTest.cpp -o %t-MemcmpTest
+RUN: not %run %t-MemcmpTest   -seed=1 -runs=1000   2>&1 | FileCheck %s
+CHECK: BINGO
Index: compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
===
--- /dev/null
+++ compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
@@ -0,0 +1,161 @@
+//===-- FuzzerInterceptors.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+// Intercept certain libc functions to aid fuzzing.
+// Linked only when other RTs that define their own interceptors are not linked.
+//===--===//
+
+#include "FuzzerBuiltins.h"
+
+#if LIBFUZZER_LINUX
+
+#define PTR_TO_REAL(x) real_##x
+#define REAL(x) __interception::PTR_TO_REAL(x)
+#define FUNC_TYPE(x) x##_type
+#define DEFINE_REAL(ret_type, func, ...)   \
+  typedef ret_type (*FUNC_TYPE(func))(__VA_ARGS__);\
+  namespace __interception {   \
+  FUNC_TYPE(func) PTR_TO_REAL(func);   \
+  }
+
+typedef unsigned long uptr;
+
+#include  // for dlsym()
+
+static void *GetFuncAddr(const char *name, uptr wrapper_addr) {
+  void *addr = dlsym(RTLD_NEXT, name);
+  if (!addr) {
+// If the lookup using RTLD_NEXT failed, the sanitizer runtime library is
+// later in the library search order than the DSO that we are trying to
+// intercept, which means that we cannot intercept this function. We still
+// want the address of the real definition, though, so look it up using
+// RTLD_DEFAULT.
+addr = dlsym(RTLD_DEFAULT, name);
+
+// In case `name' is not loaded, dlsym ends up finding the actual wrapper.
+// We don't want to intercept the wrapper and have it point to itself.
+if ((uptr)addr == wrapper_addr)
+  addr = nullptr;
+  }
+  return addr;
+}
+
+extern "C" {
+
+// NOLINTNEXTLINE
+void __sanitizer_weak_hook_memcmp(void *, const void *, const void *, size_t,
+  int);
+// NOLINTNEXTLINE
+void __sanitizer_weak_hook_strncmp(void *, const char *, const char *, size_t,
+   int);
+// NOLINTNEXTLINE
+void __sanitizer_weak_hook_strcmp(void *, const char *, const char *, int);
+// NOLINTNEXTLINE
+void __sanitizer_weak_hook_strncasecmp(void *, const char *, const 

  1   2   3   >