[PATCH] D80198: [clangd] locateMacroAt handles patched macros

2020-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 266111.
kadircet marked 10 inline comments as done.
kadircet added a comment.

- Extract preamble-patch location translation to a helper:
  - Migrate usage in include collector
  - Make preamble patch header name part of the check.
- Handle macro ids in spellDirective
- Tweak comments/names


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80198

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  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
@@ -9,14 +9,19 @@
 #include "Annotations.h"
 #include "Compiler.h"
 #include "Headers.h"
+#include "Hover.h"
 #include "Preamble.h"
+#include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "XRefs.h"
+#include "clang/Format/Format.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "gmock/gmock.h"
@@ -28,6 +33,7 @@
 
 using testing::Contains;
 using testing::Field;
+using testing::Matcher;
 using testing::MatchesRegex;
 
 namespace clang {
@@ -199,7 +205,7 @@
 ADD_FAILURE() << "Failed to build compiler invocation";
 return llvm::None;
   }
-  return ParsedAST::build(testPath("main.cpp"), TU.inputs(), std::move(CI), {},
+  return ParsedAST::build(testPath(TU.Filename), TU.inputs(), std::move(CI), {},
   BaselinePreamble);
 }
 
@@ -228,7 +234,8 @@
 #define BAR
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 2
+#define BAR
 )cpp",
   },
   // multiline macro
@@ -238,7 +245,8 @@
 
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 2
+#define BAR
 )cpp",
   },
   // multiline macro
@@ -248,7 +256,8 @@
 BAR
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 3
+#define BAR
 )cpp",
   },
   };
@@ -275,8 +284,10 @@
   )cpp");
 
   llvm::StringLiteral ExpectedPatch(R"cpp(#line 0 ".*main.cpp"
-#define BAR\(X, Y\) X Y
-#define BAR\(X\) X
+#line 2
+#define BAR\(X, Y\) X Y
+#line 3
+#define BAR\(X\) X
 )cpp");
   EXPECT_THAT(getPreamblePatch(Baseline, Modified.code()),
   MatchesRegex(ExpectedPatch.str()));
@@ -286,6 +297,169 @@
   EXPECT_THAT(AST->getDiagnostics(),
   Not(Contains(Field(&Diag::Range, Modified.range();
 }
+
+TEST(PreamblePatchTest, LocateMacroAtWorks) {
+  struct {
+llvm::StringLiteral Baseline;
+llvm::StringLiteral Modified;
+  } Cases[] = {
+  // Addition of new directive
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+$use^FOO)cpp",
+  },
+  // Available inside preamble section
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+#undef $use^FOO)cpp",
+  },
+  // Available after undef, as we don't patch those
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+#undef FOO
+$use^FOO)cpp",
+  },
+  // Identifier on a different line
+  {
+  "",
+  R"cpp(
+#define \
+  $def^FOO
+$use^FOO)cpp",
+  },
+  // In presence of comment tokens
+  {
+  "",
+  R"cpp(
+#\
+  define /* FOO */\
+  /* FOO */ $def^FOO
+$use^FOO)cpp",
+  },
+  // Moved around
+  {
+  "#define FOO",
+  R"cpp(
+#define BAR
+#define $def^FOO
+$use^FOO)cpp",
+  },
+  };
+  for (const auto &Case : Cases) {
+SCOPED_TRACE(Case.Modified);
+llvm::Annotations Modified(Case.Modified);
+auto AST = createPatchedAST(Case.Baseline, Modified.code());
+ASSERT_TRUE(AST);
+
+const auto &SM = AST->getSourceManager();
+auto *MacroTok = AST->getTokens().spelledTokenAt(
+SM.getComposedLoc(SM.getMainFileID(), Modified.point("use")));
+ASSERT_TRUE(MacroTok);
+
+auto FoundMacro = locateMacroAt(*MacroTok, AST->getPreprocessor());
+ASSERT_TRUE(FoundMacro);
+EXPECT_THAT(FoundMacro->Name, "FOO");
+
+auto MacroLoc = FoundMacro->NameLoc;
+EXPECT_EQ(SM.getFileID(MacroLoc), SM.get

[PATCH] D80018: [Analyzer][StreamChecker] Added check for "indeterminate file position".

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



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:107
+  /// This value applies to all error states in ErrorState except FEOF.
+  /// An EOF+indeterminate state is the same as EOF state.
+  bool FilePositionIndeterminate = false;

Szelethus wrote:
> balazske wrote:
> > Szelethus wrote:
> > > Szelethus wrote:
> > > > What does this mean? "An EOF+indeterminate state is the same as EOF 
> > > > state." I don't understand the message you want to convey here -- is it 
> > > > that we cannot have an indeterminate file position indicator if we hit 
> > > > EOF, hence we regard a stream that is **known** to be EOF to have its 
> > > > file position indicator determinate?
> > > > 
> > > > A good followup question for the uninitiated would be that "Well why is 
> > > > it ever legal to construct a `StreamState` object that can both have 
> > > > the `FilePositionIndeterminate` set to true and the `ErrorState` 
> > > > indicate that the steam is **known** to be in EOF?" Well, the answer is 
> > > > that we may only realize later that the error state can only be EOF, 
> > > > like in here:
> > > > ```lang=c++
> > > > void f() {
> > > >  FILE *F = fopen(...);
> > > >  if (fseek(F, ...)) {
> > > > // Could be either EOF, ERROR, and ofc indeterminate
> > > > if (eof(F)) {
> > > >   // This is where we have a seemingly impossible stream state, but 
> > > > its not a programming error, its a design decision.
> > > > }
> > > > }
> > > > ```
> > > > This might warrant a bit on explanation either here, or in 
> > > > `ensureNoFilePositionIndeterminate`. Probably the latter.
> > > > 
> > > > With that said, can `SteamState`'s constructor ensure that we do not 
> > > > create a known to be EOF stream that is indeterminate?
> > > Actually, not enforcing this could leave to false positives:
> > > 
> > > ```
> > > void f() {
> > >  FILE *F = fopen(...);
> > >  if (fseek(F, ...)) {
> > > // Could be either EOF, ERROR, and ofc indeterminate
> > > if (eof(F)) {
> > >   clearerr(F);
> > >   fseek(F, ...); // false positive warning
> > > }
> > > }
> > > ```
> > The comment wants to say only that if the **ErrorState** contains the 
> > **ErrorFEof** the value of `filePositionIndeterminate` is to be ignored for 
> > the EOF case. If the file is in EOF it does not matter what value 
> > `filePositionIndeterminate` has. The cause for this handling is that 
> > ErrorState handles multiple possible errors together but the indeterminate 
> > position does not apply to all. If **ErrorState** contains **ErrorFEof** 
> > and **ErrorFError** together and the `filePositionIndeterminate` is set, 
> > the position is not indeterminate in the EOF case. For EOF case we should 
> > know that the position is at the end of the file, not indeterminate.
> > 
> > Another solution for this problem can be to have a 
> > "ErrorFErrorIndeterminate" and "ErrorNoneIndeterminate" error type but this 
> > makes things more difficult to handle.
> What do you mean under the term "the EOF case"? When we **know** the stream 
> to only be in the EOF state? The overall modeling seems correct, its just 
> that little corner case that if we **know** that the stream hit EOF, the file 
> position must be determinate.
The "difficult" case is when we do not know if the stream is in error or EOF 
state. We know only that it is in one of these. And the 
`FilePositionIndeterminate` is set to true. In this state `FEof` and `FError` 
are true in `ErrorState`. If the program should know what the error is, it 
needs to generate 2 new states, one with only `FEof` true and other with 
`FError`. And how to set the `FilePositionIndeterminate` for the new states? 
For `FError` it must be set to true because it was true before, for `FEof` it 
is set to false because by definition it is not applied to `FEof` case. (This 
last is //the EOF case// above.)

This table shows what (real) stream state is represented (values at right) by 
what values in `StreamState` (values at left side):
| FEof | FError | FilePositionIndeterminate | stream feof? | stream ferror? | 
position indeterminate? |
| false | false | true | false | false | true |
| true | false | true | true | false | false |
| false | true | true | false | true | true |
| true | true | true | - | - | - |


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80018



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


[PATCH] D80198: [clangd] locateMacroAt handles patched macros

2020-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Preamble.cpp:133
+  auto DecompLoc = SM.getDecomposedLoc(DirectiveRange.getBegin());
+  DirectiveLine = SM.getLineNumber(DecompLoc.first, DecompLoc.second);
+  auto SpaceBefore = SM.getColumnNumber(DecompLoc.first, DecompLoc.second) - 1;

sammccall wrote:
> This is only going to give you something useful for file IDs, not macro 
> expansions. Whose responsibility is it to make sure there's no macro IDs here?
For `define` directives this is already true as `MacroInfo`'s definition range 
is a file range(as macro bodies are lexed without macro expansions).

For any other directive with macro expansions, we only care about the expansion 
locations as we want to spell out the directive as written. So we can just map 
back to expansion locs here.



Comment at: clang-tools-extra/clangd/Preamble.cpp:136
+
+  // Pad with spaces before DirectiveRange to make sure it will be on right
+  // column when patched.

sammccall wrote:
> again this comment only applyes to one branch
why ? we pad in both cases, starting from the beginning of the line in first 
branch and starting after Prefix in the second.



Comment at: clang-tools-extra/clangd/SourceCode.cpp:975
+
+  // Macro definitions could be injected through preamble patch. These contain
+  // line directives to hint their original location in main file.

sammccall wrote:
> OK, this is fairly horrible...
> 
> I want to say the preamble patch location translation should be a separate 
> function rather than coupled to macro-specific stuff.
> (Then we don't even need the extra struct member, but we can still keep it to 
> "remind" people the translation is needed, if we like).
> 
> But of course we didn't preserve the formatting in the preamble patch, so 
> `getPresumedLoc()` doesn't give us the right location, it just gives us 
> something on the right line that we then need to re-parse...
> 
> This really isn't looking like a great tradeoff to me anymore (and I know I 
> suggested it).
> How much work do you think it is (compared to say, the logic here plus doing 
> it in ~2 more places) to give the preamblepatch the invariant that the 
> PresumedLoc has a usable col as well.
> The original implementation did padding with spaces, but I guess we could as 
> well have the preamble patching stuff splice the actual source code...
as discussed offline, changed patching logic to put directive in correct column 
in addition to line. Now we can just make use of presumedloc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80198



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


[clang-tools-extra] 1abb883 - [clangd] Don't traverse the AST within uninteresting files during indexing

2020-05-26 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-05-26T10:27:28+02:00
New Revision: 1abb883a048153c83a4e11070219d23f362e7377

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

LOG: [clangd] Don't traverse the AST within uninteresting files during indexing

Summary:
We already skip function bodies from these files while parsing, and drop symbols
found in them. However, traversing their ASTs still takes a substantial amount
of time.

Non-scientific benchmark on my machine:
  background-indexing llvm-project (llvm+clang+clang-tools-extra), wall time
  before: 7:46
  after: 5:13
  change: -33%

Indexer.cpp libclang should be updated too, I'm less familiar with that code,
and it's doing tricky things with the ShouldSkipFunctionBody callback, so it
needs to be done separately.

Reviewers: kadircet

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/index/IndexAction.cpp
clang-tools-extra/clangd/unittests/IndexActionTests.cpp
clang/include/clang/Index/IndexingAction.h
clang/include/clang/Index/IndexingOptions.h
clang/lib/Index/IndexDecl.cpp
clang/lib/Index/IndexingAction.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/IndexAction.cpp 
b/clang-tools-extra/clangd/index/IndexAction.cpp
index 9f294d4ab925..aa65008b51c0 100644
--- a/clang-tools-extra/clangd/index/IndexAction.cpp
+++ b/clang-tools-extra/clangd/index/IndexAction.cpp
@@ -132,11 +132,19 @@ class IndexAction : public ASTFrontendAction {
   std::function RefsCallback,
   std::function RelationsCallback,
   std::function IncludeGraphCallback)
-  : SymbolsCallback(SymbolsCallback),
-RefsCallback(RefsCallback), RelationsCallback(RelationsCallback),
+  : SymbolsCallback(SymbolsCallback), RefsCallback(RefsCallback),
+RelationsCallback(RelationsCallback),
 IncludeGraphCallback(IncludeGraphCallback), Collector(C),
 Includes(std::move(Includes)), Opts(Opts),
-PragmaHandler(collectIWYUHeaderMaps(this->Includes.get())) {}
+PragmaHandler(collectIWYUHeaderMaps(this->Includes.get())) {
+this->Opts.ShouldTraverseDecl = [this](const Decl *D) {
+  auto &SM = D->getASTContext().getSourceManager();
+  auto FID = SM.getFileID(SM.getExpansionLoc(D->getLocation()));
+  if (!FID.isValid())
+return true;
+  return Collector->shouldIndexFile(FID);
+};
+  }
 
   std::unique_ptr
   CreateASTConsumer(CompilerInstance &CI, llvm::StringRef InFile) override {
@@ -146,15 +154,8 @@ class IndexAction : public ASTFrontendAction {
   CI.getPreprocessor().addPPCallbacks(
   std::make_unique(CI.getSourceManager(), IG));
 
-return index::createIndexingASTConsumer(
-Collector, Opts, CI.getPreprocessorPtr(),
-/*ShouldSkipFunctionBody=*/[this](const Decl *D) {
-  auto &SM = D->getASTContext().getSourceManager();
-  auto FID = SM.getFileID(SM.getExpansionLoc(D->getLocation()));
-  if (!FID.isValid())
-return false;
-  return !Collector->shouldIndexFile(FID);
-});
+return index::createIndexingASTConsumer(Collector, Opts,
+CI.getPreprocessorPtr());
   }
 
   bool BeginInvocation(CompilerInstance &CI) override {

diff  --git a/clang-tools-extra/clangd/unittests/IndexActionTests.cpp 
b/clang-tools-extra/clangd/unittests/IndexActionTests.cpp
index 6441d019c7e1..31e1bc573290 100644
--- a/clang-tools-extra/clangd/unittests/IndexActionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IndexActionTests.cpp
@@ -19,6 +19,7 @@ namespace {
 
 using ::testing::AllOf;
 using ::testing::ElementsAre;
+using ::testing::EndsWith;
 using ::testing::Not;
 using ::testing::Pair;
 using ::testing::UnorderedElementsAre;
@@ -75,8 +76,7 @@ class IndexActionTest : public ::testing::Test {
 new FileManager(FileSystemOptions(), InMemoryFileSystem));
 
 auto Action = createStaticIndexingAction(
-SymbolCollector::Options(),
-[&](SymbolSlab S) { IndexFile.Symbols = std::move(S); },
+Opts, [&](SymbolSlab S) { IndexFile.Symbols = std::move(S); },
 [&](RefSlab R) { IndexFile.Refs = std::move(R); },
 [&](RelationSlab R) { IndexFile.Relations = std::move(R); },
 [&](IncludeGraph IG) { IndexFile.Sources = std::move(IG); });
@@ -99,11 +99,12 @@ class IndexActionTest : public ::testing::Test {
 
   void addFile(llvm::StringRef Path, llvm::StringRef Content) {
 InMemoryFileSystem->addFile(Path, 0,
-llvm::MemoryBuffer::getMemBuffer(Content));
+llvm::MemoryBuffer::getMemBufferC

[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-05-26 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked 7 inline comments as done.
baloghadamsoftware added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:126-128
+  const auto *Body = dyn_cast_or_null(Ctor->getBody());
+  if (!Body)
+return;

aaron.ballman wrote:
> This can be hoisted into the matcher with `hasBody(anything())` I believe. 
> One interesting test case that's somewhat related are constructors that use a 
> function-try-block instead of a compound statement. e.g.,
> ```
> class C {
>   int i;
> 
> public:
>   C() try {
> i = 12;
>   } catch (...) {
>   }
> };
> ```
I think we should skip these cases similarly to initialization inside a try 
block in a body that is compound statement. Maybe the initialization throws 
thus it is inappropriate to convert it to member initializer. I also added a 
test case for this.


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

https://reviews.llvm.org/D71199



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


[PATCH] D80296: [clangd] Don't traverse the AST within uninteresting files during indexing

2020-05-26 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1abb883a0481: [clangd] Don't traverse the AST within 
uninteresting files during indexing (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80296

Files:
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/unittests/IndexActionTests.cpp
  clang/include/clang/Index/IndexingAction.h
  clang/include/clang/Index/IndexingOptions.h
  clang/lib/Index/IndexDecl.cpp
  clang/lib/Index/IndexingAction.cpp

Index: clang/lib/Index/IndexingAction.cpp
===
--- clang/lib/Index/IndexingAction.cpp
+++ clang/lib/Index/IndexingAction.cpp
@@ -131,6 +131,21 @@
 ShouldSkipFunctionBody);
 }
 
+std::unique_ptr clang::index::createIndexingASTConsumer(
+std::shared_ptr DataConsumer,
+const IndexingOptions &Opts, std::shared_ptr PP) {
+  std::function ShouldSkipFunctionBody = [](const Decl *) {
+return false;
+  };
+  if (Opts.ShouldTraverseDecl)
+ShouldSkipFunctionBody =
+[ShouldTraverseDecl(Opts.ShouldTraverseDecl)](const Decl *D) {
+  return !ShouldTraverseDecl(D);
+};
+  return createIndexingASTConsumer(std::move(DataConsumer), Opts, std::move(PP),
+   std::move(ShouldSkipFunctionBody));
+}
+
 std::unique_ptr
 index::createIndexingAction(std::shared_ptr DataConsumer,
 const IndexingOptions &Opts) {
Index: clang/lib/Index/IndexDecl.cpp
===
--- clang/lib/Index/IndexDecl.cpp
+++ clang/lib/Index/IndexDecl.cpp
@@ -765,6 +765,9 @@
   if (isa(D))
 return true; // Wait for the objc container.
 
+  if (IndexOpts.ShouldTraverseDecl && !IndexOpts.ShouldTraverseDecl(D))
+return true; // skip
+
   return indexDecl(D);
 }
 
Index: clang/include/clang/Index/IndexingOptions.h
===
--- clang/include/clang/Index/IndexingOptions.h
+++ clang/include/clang/Index/IndexingOptions.h
@@ -34,6 +34,12 @@
   // Has no effect if IndexFunctionLocals are false.
   bool IndexParametersInDeclarations = false;
   bool IndexTemplateParameters = false;
+
+  // If set, skip indexing inside some declarations for performance.
+  // This prevents traversal, so skipping a struct means its declaration an
+  // members won't be indexed, but references elsewhere to that struct will be.
+  // Currently this is only checked for top-level declarations.
+  std::function ShouldTraverseDecl;
 };
 
 } // namespace index
Index: clang/include/clang/Index/IndexingAction.h
===
--- clang/include/clang/Index/IndexingAction.h
+++ clang/include/clang/Index/IndexingAction.h
@@ -30,22 +30,21 @@
 }
 
 namespace index {
-  class IndexDataConsumer;
+class IndexDataConsumer;
 
 /// Creates an ASTConsumer that indexes all symbols (macros and AST decls).
+std::unique_ptr
+createIndexingASTConsumer(std::shared_ptr DataConsumer,
+  const IndexingOptions &Opts,
+  std::shared_ptr PP);
+
 std::unique_ptr createIndexingASTConsumer(
 std::shared_ptr DataConsumer,
 const IndexingOptions &Opts, std::shared_ptr PP,
+// Prefer to set Opts.ShouldTraverseDecl and use the above overload.
+// This version is only needed if used to *track* function body parsing.
 std::function ShouldSkipFunctionBody);
 
-inline std::unique_ptr createIndexingASTConsumer(
-std::shared_ptr DataConsumer,
-const IndexingOptions &Opts, std::shared_ptr PP) {
-  return createIndexingASTConsumer(
-  std::move(DataConsumer), Opts, std::move(PP),
-  /*ShouldSkipFunctionBody=*/[](const Decl *) { return false; });
-}
-
 /// Creates a frontend action that indexes all symbols (macros and AST decls).
 std::unique_ptr
 createIndexingAction(std::shared_ptr DataConsumer,
Index: clang-tools-extra/clangd/unittests/IndexActionTests.cpp
===
--- clang-tools-extra/clangd/unittests/IndexActionTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexActionTests.cpp
@@ -19,6 +19,7 @@
 
 using ::testing::AllOf;
 using ::testing::ElementsAre;
+using ::testing::EndsWith;
 using ::testing::Not;
 using ::testing::Pair;
 using ::testing::UnorderedElementsAre;
@@ -75,8 +76,7 @@
 new FileManager(FileSystemOptions(), InMemoryFileSystem));
 
 auto Action = createStaticIndexingAction(
-SymbolCollector::Options(),
-[&](SymbolSlab S) { IndexFile.Symbols = std::move(S); },
+Opts, [&](SymbolSlab S) { IndexFile.Symbols = std::move(S); },
 [&](RefSlab R) { IndexFile.Refs = std::move(R); },
 [&](RelationSlab R) { IndexFile.Relations = std::move(R); },
 [

[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-05-26 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 266117.
baloghadamsoftware added a comment.

Updated according to the comments.


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

https://reviews.llvm.org/D71199

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
@@ -0,0 +1,435 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-prefer-member-initializer %t
+
+class Simple1 {
+  int n;
+  // CHECK-FIXES: int n{0};
+  double x;
+  // CHECK-FIXES: double x{0.0};
+
+public:
+  Simple1() {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple1(int nn, double xx) {
+// CHECK-FIXES: Simple1(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple1() = default;
+};
+
+class Simple2 {
+  int n;
+  double x;
+  // CHECK-FIXES: double x{0.0};
+
+public:
+  Simple2() : n (0) {
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple2(int nn, double xx) : n(nn) {
+// CHECK-FIXES: Simple2(int nn, double xx) : n(nn), x(xx) {
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple2() = default;
+};
+
+class Simple3 {
+  int n;
+  // CHECK-FIXES: int n{0};
+  double x;
+
+public:
+  Simple3() : x (0.0) {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple3(int nn, double xx) : x(xx) {
+// CHECK-FIXES: Simple3(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple3() = default;
+};
+
+int something_int();
+double something_double();
+
+class Simple4 {
+  int n;
+
+public:
+  Simple4() {
+// CHECK-FIXES: Simple4() : n(something_int()) {
+n = something_int();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple4() = default;
+};
+
+static bool dice();
+
+class Complex1 {
+  int n;
+  int m;
+
+public:
+  Complex1() : n(0) {
+if (dice())
+  m = 1;
+// NO-MESSAGES: initialization of 'm' is nested in a conditional expression
+  }
+
+  ~Complex1() = default;
+};
+
+class Complex2 {
+  int n;
+  int m;
+
+public:
+  Complex2() : n(0) {
+if (!dice())
+  return;
+m = 1;
+// NO-MESSAGES: initialization of 'm' follows a conditional expression
+  }
+
+  ~Complex2() = default;
+};
+
+class Complex3 {
+  int n;
+  int m;
+
+public:
+  Complex3() : n(0) {
+while (dice())
+  m = 1;
+// NO-MESSAGES: initialization of 'm' is nested in a conditional loop
+  }
+
+  ~Complex3() = default;
+};
+
+class Complex4 {
+  int n;
+  int m;
+
+public:
+  Complex4() : n(0) {
+while (!dice())
+  return;
+m = 1;
+// NO-MESSAGES:

[PATCH] D80198: [clangd] locateMacroAt handles patched macros

2020-05-26 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.

Looks great, ship it!




Comment at: clang-tools-extra/clangd/Preamble.cpp:154
+OS << "\\\n" << std::string(TargetColumn, ' ');
+// Decrement because returned string has a line break before directive now.
+--DirectiveLine;

nit: not "before the directive", just before the DirectiveRange.begin()



Comment at: clang-tools-extra/clangd/Preamble.cpp:157
+  } else {
+// There is enough space for Prefix and space before directive, use it.
+// We try to squeeze the Prefix into the same line whenever we can, as

nit: I think it'd be easier to understand the other case if this one came 
first, as it's the fallback



Comment at: clang-tools-extra/clangd/Preamble.h:136
+/// using presumed locations. Returns \p Loc if it isn't inside preamble patch.
+SourceLocation translatePreamblePatchLocation(SourceLocation Loc,
+  const SourceManager &SM);

Can we have a unit-test for this function?
I think the minimal thing (least entangled with PreamblePatch construction) is 
to manually write a snippet that looks like a preamble patch like
```
# line 3 main.cpp
int foo();
```
 map it into a TestTU with AdditionalFiles, set `ExtraArgs = 
{"-include","patch.h"}` and then get the location with `findDecl`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80198



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


[PATCH] D79961: [PGO] Fix computation of fuction Hash

2020-05-26 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D79961#2053806 , @serge-sans-paille 
wrote:

> Bump the version number to be compatible with existing profdata, in a similar 
> fashion to v1/v2 transition.


Did you forget to include some files? I don't see the bump anywhere.




Comment at: clang/lib/CodeGen/CodeGenPGO.cpp:754
+if (HashVersion == PGO_HASH_V1) {
+  MD5.update(Working);
+} else {

Maybe explicitly show the conversion to array of uint8_t here, to make it more 
clear what's going on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79961



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


[PATCH] D80540: Add support for binary operators in Syntax Trees

2020-05-26 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas added a reviewer: gribozavr2.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80540

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -564,7 +564,8 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-test
+| | |-UnknownExpression
+| | | `-test
 | | |-(
 | | `-)
 | `-;
@@ -576,14 +577,16 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-test
+| | | |-UnknownExpression
+| | | | `-test
 | | | |-(
 | | | `-)
 | | `-;
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-test
+|   | |-UnknownExpression
+|   | | `-test
 |   | |-(
 |   | `-)
 |   `-;
@@ -591,6 +594,237 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, BinaryOperator) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a) {
+  1 - 2;
+  1 == 2;
+  a = 1;
+  a <<= 1;
+
+  true || false;
+  true or false;
+
+  1 & 2;
+  1 bitand 2;
+
+  a ^= 3;
+  a xor_eq 3;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |--
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-==
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-=
+| | `-UnknownExpression
+| |   `-1
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-<<=
+| | `-UnknownExpression
+| |   `-1
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-true
+| | |-||
+| | `-UnknownExpression
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-true
+| | |-or
+| | `-UnknownExpression
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-&
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-bitand
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-^=
+| | `-UnknownExpression
+| |   `-3
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-xor_eq
+| | `-UnknownExpression
+| |   `-3
+| `-;
+`-}
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, NestedBinaryOperator) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a, int b) {
+  (1 + 2) * (4 / 2);
+  a + b + 42;
+  a = b = 42;
+  a + b * 4 + 2;
+  a % 2 + b * 42;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | |-(
+| | | |-BinaryOperatorExpression
+| | | | |-UnknownExpression
+| | | | | `-1
+| | | | |-+
+| | | | `-UnknownExpression
+| | | |   `-2
+| | | `-)
+| | |-*
+| | `-UnknownExpression
+| |   |-(
+| |   |-BinaryOperatorExpression
+| |   | |-UnknownExpression
+| |   | | `-4
+| |   | |-/
+| |   | `-UnknownExpression
+| |   |   `-2
+| |   `-)
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-BinaryOperatorExpression
+| | | |-UnknownExpression
+| | | | `-a
+| | | |-+
+| | | `-UnknownExpression
+| | |   `-b
+| | |-+
+| | `-UnknownExpression
+| |   `-42
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | 

[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D80531#2053969 , @kwk wrote:

> @Eugene.Zelenko thank you for the review. I've fixed all places that you've 
> mentioned. And have a question about one thing in particular. See inline.
>
> Do you by any chance know why `llvm-lit` keeps complaining when I use 
> `[[@LINE-1]]` in my tests as so many other tests do?


It's complaining because your check lines are 2 lines after the diagnostic so 
you should use `[[@LINE-2]]`




Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:28
+SourceRange Range, const MacroArgs *Args) override {
+IdentifierInfo *identifierInfo = MacroNameTok.getIdentifierInfo();
+if (!identifierInfo)

clang-tidy fail on the variables, please rename them to use `CamelCase` format.



Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:51
+// pre-written code snippet. But for now, this is okay.
+std::string Replacement =
+className + "(const " + className + " &) = delete;";

nit:
```
std::string Replacement = llvm::formatv(
R"cpp({0}(const {0} &) = delete;
const {0} &operator=(const {0} &) = delete{1})cpp",
classIdent->getNameStart(), FinalizeWithSemicolon ? ";" : "");```



Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:66
+
+  ClangTidyCheck &Check;
+  Preprocessor &PP;

nit: Shouldn't this be a reference to a 
`ReplaceDisallowCopyAndAssignMacroCheck`? Doing so will allow you to use a 
getter in the Check for the `MacroName` option to save storing a copy of that 
as well inside the callback.



Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h:52-53
+
+  std::string MacroName;
+  bool FinalizeWithSemicolon;
+};

These can both be marked `const`



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst:41
+
+.. option:: FinalizeWithSemicolon
+

This option should be removed and instead infer the value dynamically by 
checking the token directly after the macro use to see if its a semi-colon.

Something like this in the PPCallback should get you there
```
  bool shouldAppendSemi(SourceRange MacroLoc) {
llvm::Optional Next =
Lexer::findNextToken(MacroLoc.getEnd(), SM, PP.getLangOpts());
return !(Next && Next->is(tok::semi));
  }```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80531



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


[clang] 98cad55 - [Clang][AArch64] Capturing proper pointer alignment for Neon vld1 intrinsicts

2020-05-26 Thread Lucas Prates via cfe-commits

Author: Lucas Prates
Date: 2020-05-26T10:09:35+01:00
New Revision: 98cad555e29187a03e2bc3db5780762981913902

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

LOG: [Clang][AArch64] Capturing proper pointer alignment for Neon vld1 
intrinsicts

Summary:
During CodeGen for AArch64 Neon intrinsics, Clang was incorrectly
assuming all the pointers from which loads were being generated for vld1
intrinsics were aligned according to the intrinsics result type, causing
alignment faults on the code generated by the backend.

This patch updates vld1 intrinsics' CodeGen to properly capture the
correct load alignment based on the type of the pointer provided as
input for the intrinsic.

Reviewers: t.p.northover, ostannard, pcc

Reviewed By: ostannard

Subscribers: kristof.beyls, danielkiss, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/aarch64-neon-intrinsics.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1adae1a7ea42..ddd9a68a8edb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10327,9 +10327,9 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
   }
   case NEON::BI__builtin_neon_vld1_v:
   case NEON::BI__builtin_neon_vld1q_v: {
+auto Alignment = CGM.getNaturalPointeeTypeAlignment(
+E->getArg(0)->IgnoreParenCasts()->getType());
 Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy));
-auto Alignment = CharUnits::fromQuantity(
-BuiltinID == NEON::BI__builtin_neon_vld1_v ? 8 : 16);
 return Builder.CreateAlignedLoad(VTy, Ops[0], Alignment);
   }
   case NEON::BI__builtin_neon_vst1_v:
@@ -10342,8 +10342,8 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
 Ty = llvm::PointerType::getUnqual(VTy->getElementType());
 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
-auto Alignment = CharUnits::fromQuantity(
-BuiltinID == NEON::BI__builtin_neon_vld1_lane_v ? 8 : 16);
+auto Alignment = CGM.getNaturalPointeeTypeAlignment(
+E->getArg(0)->IgnoreParenCasts()->getType());
 Ops[0] =
 Builder.CreateAlignedLoad(VTy->getElementType(), Ops[0], Alignment);
 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vld1_lane");
@@ -10353,8 +10353,8 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
 Value *V = UndefValue::get(Ty);
 Ty = llvm::PointerType::getUnqual(VTy->getElementType());
 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
-auto Alignment = CharUnits::fromQuantity(
-BuiltinID == NEON::BI__builtin_neon_vld1_dup_v ? 8 : 16);
+auto Alignment = CGM.getNaturalPointeeTypeAlignment(
+E->getArg(0)->IgnoreParenCasts()->getType());
 Ops[0] =
 Builder.CreateAlignedLoad(VTy->getElementType(), Ops[0], Alignment);
 llvm::Constant *CI = ConstantInt::get(Int32Ty, 0);

diff  --git a/clang/test/CodeGen/aarch64-neon-intrinsics.c 
b/clang/test/CodeGen/aarch64-neon-intrinsics.c
index 7744b4f4a159..1fb245f3d342 100644
--- a/clang/test/CodeGen/aarch64-neon-intrinsics.c
+++ b/clang/test/CodeGen/aarch64-neon-intrinsics.c
@@ -8956,7 +8956,7 @@ float64_t test_vrsqrted_f64(float64_t a) {
 
 // CHECK-LABEL: @test_vld1q_u8(
 // CHECK:   [[TMP0:%.*]] = bitcast i8* %a to <16 x i8>*
-// CHECK:   [[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[TMP0]]
+// CHECK:   [[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[TMP0]], align 1
 // CHECK:   ret <16 x i8> [[TMP1]]
 uint8x16_t test_vld1q_u8(uint8_t const *a) {
   return vld1q_u8(a);
@@ -8965,7 +8965,7 @@ uint8x16_t test_vld1q_u8(uint8_t const *a) {
 // CHECK-LABEL: @test_vld1q_u16(
 // CHECK:   [[TMP0:%.*]] = bitcast i16* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x i16>*
-// CHECK:   [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]], align 2
 // CHECK:   ret <8 x i16> [[TMP2]]
 uint16x8_t test_vld1q_u16(uint16_t const *a) {
   return vld1q_u16(a);
@@ -8974,7 +8974,7 @@ uint16x8_t test_vld1q_u16(uint16_t const *a) {
 // CHECK-LABEL: @test_vld1q_u32(
 // CHECK:   [[TMP0:%.*]] = bitcast i32* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x i32>*
-// CHECK:   [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]], align 4
 // CHECK:   ret <4 x i32> [[TMP2]]
 uint32x4_t test_vld1q_u32(uint32_t const *a) {
   return vld1q_u32(a);
@@ -8983,7 +8983,7 @@ uint32x4_t test_vld1q_u32(uint32_t const *a) {
 // CHECK-LABEL: @test_vld1q_u64(
 // CHECK:   [[TMP0:%.*]] = bitcast i64* %a to i8*
 /

[PATCH] D78933: [analyzer] RangeConstraintManager optimizations in comparison expressions

2020-05-26 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@xazax.hun, any thoughts?


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

https://reviews.llvm.org/D78933



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


[PATCH] D80198: [clangd] locateMacroAt handles patched macros

2020-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 266128.
kadircet marked 4 inline comments as done.
kadircet added a comment.

- Add tests for preamble-patch translation logic


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80198

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  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
@@ -9,14 +9,19 @@
 #include "Annotations.h"
 #include "Compiler.h"
 #include "Headers.h"
+#include "Hover.h"
 #include "Preamble.h"
+#include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "XRefs.h"
+#include "clang/Format/Format.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "gmock/gmock.h"
@@ -28,6 +33,7 @@
 
 using testing::Contains;
 using testing::Field;
+using testing::Matcher;
 using testing::MatchesRegex;
 
 namespace clang {
@@ -199,7 +205,7 @@
 ADD_FAILURE() << "Failed to build compiler invocation";
 return llvm::None;
   }
-  return ParsedAST::build(testPath("main.cpp"), TU.inputs(), std::move(CI), {},
+  return ParsedAST::build(testPath(TU.Filename), TU.inputs(), std::move(CI), {},
   BaselinePreamble);
 }
 
@@ -228,7 +234,8 @@
 #define BAR
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 2
+#define BAR
 )cpp",
   },
   // multiline macro
@@ -238,7 +245,8 @@
 
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 2
+#define BAR
 )cpp",
   },
   // multiline macro
@@ -248,7 +256,8 @@
 BAR
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 3
+#define BAR
 )cpp",
   },
   };
@@ -275,8 +284,10 @@
   )cpp");
 
   llvm::StringLiteral ExpectedPatch(R"cpp(#line 0 ".*main.cpp"
-#define BAR\(X, Y\) X Y
-#define BAR\(X\) X
+#line 2
+#define BAR\(X, Y\) X Y
+#line 3
+#define BAR\(X\) X
 )cpp");
   EXPECT_THAT(getPreamblePatch(Baseline, Modified.code()),
   MatchesRegex(ExpectedPatch.str()));
@@ -286,6 +297,193 @@
   EXPECT_THAT(AST->getDiagnostics(),
   Not(Contains(Field(&Diag::Range, Modified.range();
 }
+
+TEST(PreamblePatchTest, LocateMacroAtWorks) {
+  struct {
+llvm::StringLiteral Baseline;
+llvm::StringLiteral Modified;
+  } Cases[] = {
+  // Addition of new directive
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+$use^FOO)cpp",
+  },
+  // Available inside preamble section
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+#undef $use^FOO)cpp",
+  },
+  // Available after undef, as we don't patch those
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+#undef FOO
+$use^FOO)cpp",
+  },
+  // Identifier on a different line
+  {
+  "",
+  R"cpp(
+#define \
+  $def^FOO
+$use^FOO)cpp",
+  },
+  // In presence of comment tokens
+  {
+  "",
+  R"cpp(
+#\
+  define /* FOO */\
+  /* FOO */ $def^FOO
+$use^FOO)cpp",
+  },
+  // Moved around
+  {
+  "#define FOO",
+  R"cpp(
+#define BAR
+#define $def^FOO
+$use^FOO)cpp",
+  },
+  };
+  for (const auto &Case : Cases) {
+SCOPED_TRACE(Case.Modified);
+llvm::Annotations Modified(Case.Modified);
+auto AST = createPatchedAST(Case.Baseline, Modified.code());
+ASSERT_TRUE(AST);
+
+const auto &SM = AST->getSourceManager();
+auto *MacroTok = AST->getTokens().spelledTokenAt(
+SM.getComposedLoc(SM.getMainFileID(), Modified.point("use")));
+ASSERT_TRUE(MacroTok);
+
+auto FoundMacro = locateMacroAt(*MacroTok, AST->getPreprocessor());
+ASSERT_TRUE(FoundMacro);
+EXPECT_THAT(FoundMacro->Name, "FOO");
+
+auto MacroLoc = FoundMacro->NameLoc;
+EXPECT_EQ(SM.getFileID(MacroLoc), SM.getMainFileID());
+EXPECT_EQ(SM.getFileOffset(MacroLoc), Modified.point("def"));
+  }
+}
+
+TEST(PreamblePatchTest, LocateMacroAtDeletion) {
+  {
+// We don't p

[PATCH] D80541: Terminate early for DS_Error

2020-05-26 Thread Yi Kong via Phabricator via cfe-commits
kongyi created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Otherwise clang will continue running after printing the diagnostic, causing 
failures later in other modes, or maybe even finish successfully.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80541

Files:
  clang/lib/CodeGen/CodeGenAction.cpp


Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -899,6 +899,9 @@
   // Report the backend message using the usual diagnostic mechanism.
   FullSourceLoc Loc;
   Diags.Report(Loc, DiagID).AddString(MsgStorage);
+
+  if (Severity == DS_Error)
+exit(1);
 }
 #undef ComputeDiagID
 


Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -899,6 +899,9 @@
   // Report the backend message using the usual diagnostic mechanism.
   FullSourceLoc Loc;
   Diags.Report(Loc, DiagID).AddString(MsgStorage);
+
+  if (Severity == DS_Error)
+exit(1);
 }
 #undef ComputeDiagID
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk planned changes to this revision.
kwk added a comment.

Thank you @njames93 for the review. I'm implementing what you wrote.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80531



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


[PATCH] D79961: [PGO] Fix computation of fuction Hash

2020-05-26 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 266133.
serge-sans-paille added a comment.

With v3 version + Make cast explicit


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

https://reviews.llvm.org/D79961

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/Profile/Inputs/c-counter-overflows.proftext
  clang/test/Profile/Inputs/c-general.profdata.v2
  clang/test/Profile/Inputs/c-general.profdata.v3
  clang/test/Profile/Inputs/c-general.proftext
  clang/test/Profile/Inputs/c-unprofiled-blocks.proftext
  clang/test/Profile/Inputs/cxx-rangefor.proftext
  clang/test/Profile/Inputs/cxx-throws.proftext
  clang/test/Profile/Inputs/misexpect-switch-default.proftext
  clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
  clang/test/Profile/Inputs/misexpect-switch.proftext
  clang/test/Profile/c-collision.c
  clang/test/Profile/c-general.c

Index: clang/test/Profile/c-general.c
===
--- clang/test/Profile/c-general.c
+++ clang/test/Profile/c-general.c
@@ -5,6 +5,7 @@
 // RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v2 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
 // Also check compatibility with older profiles.
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v1 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
 
Index: clang/test/Profile/c-collision.c
===
--- /dev/null
+++ clang/test/Profile/c-collision.c
@@ -0,0 +1,22 @@
+// Test that a slight change in the code leads to a different hash.
+// RUN: %clang_cc1 -UEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s --check-prefix=CHECK-NOEXTRA
+// RUN: %clang_cc1 -DEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s --check-prefix=CHECK-EXTRA
+
+// CHECK-NOEXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 7156072912471487002,
+// CHECK-EXTRA:   @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 -4383447408116050035,
+
+extern int bar;
+void foo() {
+  if (bar) {
+  }
+  if (bar) {
+  }
+  if (bar) {
+if (bar) {
+#ifdef EXTRA
+  if (bar) {
+  }
+#endif
+}
+  }
+}
Index: clang/test/Profile/Inputs/misexpect-switch.proftext
===
--- clang/test/Profile/Inputs/misexpect-switch.proftext
+++ clang/test/Profile/Inputs/misexpect-switch.proftext
@@ -1,6 +1,6 @@
 main
 # Func Hash:
-1965403898329309329
+872687477373597607
 # Num Counters:
 9
 # Counter Values:
Index: clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
===
--- clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
+++ clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
@@ -1,6 +1,6 @@
 main
 # Func Hash:
-1965403898329309329
+3721743393642630379
 # Num Counters:
 10
 # Counter Values:
Index: clang/test/Profile/Inputs/misexpect-switch-default.proftext
===
--- clang/test/Profile/Inputs/misexpect-switch-default.proftext
+++ clang/test/Profile/Inputs/misexpect-switch-default.proftext
@@ -1,6 +1,6 @@
 main
 # Func Hash:
-8712453512413296413
+8734802134600123338
 # Num Counters:
 9
 # Counter Values:
Index: clang/test/Profile/Inputs/cxx-throws.proftext
===
--- clang/test/Profile/Inputs/cxx-throws.proftext
+++ clang/test/Profile/Inputs/cxx-throws.proftext
@@ -1,5 +1,5 @@
 _Z6throwsv
-340120998528097520
+18172607911962830854
 9
 1
 100
Index: clang/test/Profile/Inputs/cxx-rangefor.proftext
===
--- clang/test/Profile/Inputs/cxx-rangefor.proftext
+++ clang/test/Profile/Inputs/cxx-rangefor.proftext
@@ -1,5 +1,5 @@
 _Z9range_forv
-6169071350249721981
+8789831523895825398
 5
 1
 4
Index: clang/test/Profile/Inputs/c-unprofiled-blocks.proftext
===
--- clang/test/Profile/I

[PATCH] D79961: [PGO] Fix computation of fuction Hash

2020-05-26 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

@hans updated!


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

https://reviews.llvm.org/D79961



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


[PATCH] D79721: [Clang][AArch64] Capturing proper pointer alignment for Neon vld1 intrinsicts

2020-05-26 Thread Lucas Prates via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG98cad555e291: [Clang][AArch64] Capturing proper pointer 
alignment for Neon vld1 intrinsicts (authored by pratlucas).

Changed prior to commit:
  https://reviews.llvm.org/D79721?vs=263188&id=266138#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79721

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics.c

Index: clang/test/CodeGen/aarch64-neon-intrinsics.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics.c
@@ -8956,7 +8956,7 @@
 
 // CHECK-LABEL: @test_vld1q_u8(
 // CHECK:   [[TMP0:%.*]] = bitcast i8* %a to <16 x i8>*
-// CHECK:   [[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[TMP0]]
+// CHECK:   [[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[TMP0]], align 1
 // CHECK:   ret <16 x i8> [[TMP1]]
 uint8x16_t test_vld1q_u8(uint8_t const *a) {
   return vld1q_u8(a);
@@ -8965,7 +8965,7 @@
 // CHECK-LABEL: @test_vld1q_u16(
 // CHECK:   [[TMP0:%.*]] = bitcast i16* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x i16>*
-// CHECK:   [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]], align 2
 // CHECK:   ret <8 x i16> [[TMP2]]
 uint16x8_t test_vld1q_u16(uint16_t const *a) {
   return vld1q_u16(a);
@@ -8974,7 +8974,7 @@
 // CHECK-LABEL: @test_vld1q_u32(
 // CHECK:   [[TMP0:%.*]] = bitcast i32* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x i32>*
-// CHECK:   [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]], align 4
 // CHECK:   ret <4 x i32> [[TMP2]]
 uint32x4_t test_vld1q_u32(uint32_t const *a) {
   return vld1q_u32(a);
@@ -8983,7 +8983,7 @@
 // CHECK-LABEL: @test_vld1q_u64(
 // CHECK:   [[TMP0:%.*]] = bitcast i64* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <2 x i64>*
-// CHECK:   [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* [[TMP1]], align 8
 // CHECK:   ret <2 x i64> [[TMP2]]
 uint64x2_t test_vld1q_u64(uint64_t const *a) {
   return vld1q_u64(a);
@@ -8991,7 +8991,7 @@
 
 // CHECK-LABEL: @test_vld1q_s8(
 // CHECK:   [[TMP0:%.*]] = bitcast i8* %a to <16 x i8>*
-// CHECK:   [[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[TMP0]]
+// CHECK:   [[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[TMP0]], align 1
 // CHECK:   ret <16 x i8> [[TMP1]]
 int8x16_t test_vld1q_s8(int8_t const *a) {
   return vld1q_s8(a);
@@ -9000,7 +9000,7 @@
 // CHECK-LABEL: @test_vld1q_s16(
 // CHECK:   [[TMP0:%.*]] = bitcast i16* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x i16>*
-// CHECK:   [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]], align 2
 // CHECK:   ret <8 x i16> [[TMP2]]
 int16x8_t test_vld1q_s16(int16_t const *a) {
   return vld1q_s16(a);
@@ -9009,7 +9009,7 @@
 // CHECK-LABEL: @test_vld1q_s32(
 // CHECK:   [[TMP0:%.*]] = bitcast i32* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x i32>*
-// CHECK:   [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]], align 4
 // CHECK:   ret <4 x i32> [[TMP2]]
 int32x4_t test_vld1q_s32(int32_t const *a) {
   return vld1q_s32(a);
@@ -9018,7 +9018,7 @@
 // CHECK-LABEL: @test_vld1q_s64(
 // CHECK:   [[TMP0:%.*]] = bitcast i64* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <2 x i64>*
-// CHECK:   [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* [[TMP1]], align 8
 // CHECK:   ret <2 x i64> [[TMP2]]
 int64x2_t test_vld1q_s64(int64_t const *a) {
   return vld1q_s64(a);
@@ -9027,7 +9027,7 @@
 // CHECK-LABEL: @test_vld1q_f16(
 // CHECK:   [[TMP0:%.*]] = bitcast half* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x half>*
-// CHECK:   [[TMP2:%.*]] = load <8 x half>, <8 x half>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <8 x half>, <8 x half>* [[TMP1]], align 2
 // CHECK:   ret <8 x half> [[TMP2]]
 float16x8_t test_vld1q_f16(float16_t const *a) {
   return vld1q_f16(a);
@@ -9036,7 +9036,7 @@
 // CHECK-LABEL: @test_vld1q_f32(
 // CHECK:   [[TMP0:%.*]] = bitcast float* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x float>*
-// CHECK:   [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]]
+// CHECK:   [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
 // CHECK:   ret <4 x float> [[TMP2]]
 float32x4_t test_vld1q_f32(float32_t const *a) {
   return vld1q_f32(a);
@@ -9045,7 +9045,7 @@
 // CHECK-LABEL: @test_vld1q_f64(
 // CHECK:   [[TMP0:%.*]] = bitcast double* %a to i8*
 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <2 x double>*
-// CHECK:   [[TMP2:%.*]] = load 

[PATCH] D80018: [Analyzer][StreamChecker] Added check for "indeterminate file position".

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



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:107
+  /// This value applies to all error states in ErrorState except FEOF.
+  /// An EOF+indeterminate state is the same as EOF state.
+  bool FilePositionIndeterminate = false;

balazske wrote:
> Szelethus wrote:
> > balazske wrote:
> > > Szelethus wrote:
> > > > Szelethus wrote:
> > > > > What does this mean? "An EOF+indeterminate state is the same as EOF 
> > > > > state." I don't understand the message you want to convey here -- is 
> > > > > it that we cannot have an indeterminate file position indicator if we 
> > > > > hit EOF, hence we regard a stream that is **known** to be EOF to have 
> > > > > its file position indicator determinate?
> > > > > 
> > > > > A good followup question for the uninitiated would be that "Well why 
> > > > > is it ever legal to construct a `StreamState` object that can both 
> > > > > have the `FilePositionIndeterminate` set to true and the `ErrorState` 
> > > > > indicate that the steam is **known** to be in EOF?" Well, the answer 
> > > > > is that we may only realize later that the error state can only be 
> > > > > EOF, like in here:
> > > > > ```lang=c++
> > > > > void f() {
> > > > >  FILE *F = fopen(...);
> > > > >  if (fseek(F, ...)) {
> > > > > // Could be either EOF, ERROR, and ofc indeterminate
> > > > > if (eof(F)) {
> > > > >   // This is where we have a seemingly impossible stream state, 
> > > > > but its not a programming error, its a design decision.
> > > > > }
> > > > > }
> > > > > ```
> > > > > This might warrant a bit on explanation either here, or in 
> > > > > `ensureNoFilePositionIndeterminate`. Probably the latter.
> > > > > 
> > > > > With that said, can `SteamState`'s constructor ensure that we do not 
> > > > > create a known to be EOF stream that is indeterminate?
> > > > Actually, not enforcing this could leave to false positives:
> > > > 
> > > > ```
> > > > void f() {
> > > >  FILE *F = fopen(...);
> > > >  if (fseek(F, ...)) {
> > > > // Could be either EOF, ERROR, and ofc indeterminate
> > > > if (eof(F)) {
> > > >   clearerr(F);
> > > >   fseek(F, ...); // false positive warning
> > > > }
> > > > }
> > > > ```
> > > The comment wants to say only that if the **ErrorState** contains the 
> > > **ErrorFEof** the value of `filePositionIndeterminate` is to be ignored 
> > > for the EOF case. If the file is in EOF it does not matter what value 
> > > `filePositionIndeterminate` has. The cause for this handling is that 
> > > ErrorState handles multiple possible errors together but the 
> > > indeterminate position does not apply to all. If **ErrorState** contains 
> > > **ErrorFEof** and **ErrorFError** together and the 
> > > `filePositionIndeterminate` is set, the position is not indeterminate in 
> > > the EOF case. For EOF case we should know that the position is at the end 
> > > of the file, not indeterminate.
> > > 
> > > Another solution for this problem can be to have a 
> > > "ErrorFErrorIndeterminate" and "ErrorNoneIndeterminate" error type but 
> > > this makes things more difficult to handle.
> > What do you mean under the term "the EOF case"? When we **know** the stream 
> > to only be in the EOF state? The overall modeling seems correct, its just 
> > that little corner case that if we **know** that the stream hit EOF, the 
> > file position must be determinate.
> The "difficult" case is when we do not know if the stream is in error or EOF 
> state. We know only that it is in one of these. And the 
> `FilePositionIndeterminate` is set to true. In this state `FEof` and `FError` 
> are true in `ErrorState`. If the program should know what the error is, it 
> needs to generate 2 new states, one with only `FEof` true and other with 
> `FError`. And how to set the `FilePositionIndeterminate` for the new states? 
> For `FError` it must be set to true because it was true before, for `FEof` it 
> is set to false because by definition it is not applied to `FEof` case. (This 
> last is //the EOF case// above.)
> 
> This table shows what (real) stream state is represented (values at right) by 
> what values in `StreamState` (values at left side):
> | FEof | FError | FilePositionIndeterminate | stream feof? | stream ferror? | 
> position indeterminate? |
> | false | false | true | false | false | true |
> | true | false | true | true | false | false |
> | false | true | true | false | true | true |
> | true | true | true | - | - | - |
Right. How about we make this field private and create a an 
`isFilePositionIndeterminate()` method that ensures that for the second row of 
that table we always return false? That would take some responsibility off of 
this interface's users.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:841-842
+// FEof is ignored).
+if (SS->ErrorState.isFEof())
+  return State->set(Sym, NewState);
+
---

[PATCH] D79995: [clang] [MinGW] Fix libunwind extension

2020-05-26 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 added a comment.

@mstorsjo @rnk will away since June


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

https://reviews.llvm.org/D79995



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


[PATCH] D80144: [clang-format] @lefticus just taught the world how to use [[unlikely]] but we forgot to teach clang-format

2020-05-26 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

In D80144#2053543 , @MyDeveloperDay 
wrote:

> maybe for now we just do
>
>   if (FormatTok->is(tok::l_square) && !Style.isObjC())
>   parseSquare();
>


I tried this, however FormatTest.cpp's verifyFormat is picky and explicitly 
checks both Cpp and ObjC styles return the same output (because ObjC++ is a 
thing):
https://github.com/llvm/llvm-project/blob/6f802ec4333cc1227bb37e258a81e9a588f964dc/clang/unittests/Format/FormatTest.cpp#L74
We can of course not use verifyFormat for these test cases, but this is a 
symptom that this may be the wrong approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80144



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


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 266148.
kwk marked 4 inline comments as done.
kwk added a comment.

- Wrap RUN lines
- Use CamelCase variable name
- Simplify access to options
- Make check options const
- Use two-line placeholder
- Automate placement of semicolon at the end


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80531

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
@@ -0,0 +1,82 @@
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DEFAULT %s \
+// RUN:   modernize-replace-disallow-copy-and-assign-macro %t
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DIFFERENT-NAME %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: MY_MACRO_NAME}]}"
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=FINALIZE %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: DISALLOW_COPY_AND_ASSIGN_FINALIZE}]}"
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS}]}" | count 0
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION}]}" | count 0
+
+// Note: the last two tests expect no diagnostics, but FileCheck cannot handle
+// that, hence the use of | count 0.
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+class TestClass1 {
+private:
+  DISALLOW_COPY_AND_ASSIGN(TestClass1);
+};
+// CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  DISALLOW_COPY_AND_ASSIGN(TestClass1);{{$}}
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  ^{{$}}
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  TestClass1(const TestClass1 &) = delete;const TestClass1 &operator=(const TestClass1 &) = delete{{$}}
+// CHECK-FIXES-DEFAULT:  {{^}}  TestClass1(const TestClass1 &) = delete;{{$}}
+// CHECK-FIXES-DEFAULT-NEXT: {{^}}  const TestClass1 &operator=(const TestClass1 &) = delete;{{$}}
+
+#define MY_MACRO_NAME(TypeName)
+
+class TestClass2 {
+private:
+  MY_MACRO_NAME(TestClass2);
+};
+// CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: using copy and assign macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DIFFERENT-NAME:  {{^}}  TestClass2(const TestClass2 &) = delete;{{$}}
+// CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}}  const TestClass2 &operator=(const TestClass2 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \
+  TypeName(const TypeName &) = delete;  \
+  const TypeName &operator=(const TypeName &) = delete;
+
+class TestClass3 {
+private:
+  // Notice, that the macro allows to be used without a semicolon because the
+  // macro definition already contains one above. Therefore our replacement must
+  // contain a semicolon at the end.
+  DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3)
+};
+// CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-FINALIZE:  {{^}}  TestClass3(const TestClass3 &) = delete;{{$}}
+// CHECK-FIXES-FINALIZE-NEXT: {{^}}  const TestClass3 &operator=(const TestClass3 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B)
+
+class TestClass4 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(TestClass4, TestClass4);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: using copy and assign ma

[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked 2 inline comments as done.
kwk added a comment.

@njames93 I've implemented everything you've mentioned. This simplified a lot.




Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst:41
+
+.. option:: FinalizeWithSemicolon
+

njames93 wrote:
> This option should be removed and instead infer the value dynamically by 
> checking the token directly after the macro use to see if its a semi-colon.
> 
> Something like this in the PPCallback should get you there
> ```
>   bool shouldAppendSemi(SourceRange MacroLoc) {
> llvm::Optional Next =
> Lexer::findNextToken(MacroLoc.getEnd(), SM, PP.getLangOpts());
> return !(Next && Next->is(tok::semi));
>   }```
Thank you so much for this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80531



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


[clang] 3785eb8 - Add support for binary operators in Syntax Trees

2020-05-26 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-05-26T12:25:58+02:00
New Revision: 3785eb83af4161bd52ed993ef3a2184c998071e6

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

LOG: Add support for binary operators in Syntax Trees

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Nodes.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index f4d482bb848c..5db99d4b9e35 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -40,6 +40,7 @@ enum class NodeKind : uint16_t {
 
   // Expressions.
   UnknownExpression,
+  BinaryOperatorExpression,
 
   // Statements.
   UnknownStatement,
@@ -104,6 +105,9 @@ enum class NodeRole : uint8_t {
   BodyStatement,
 
   // Roles specific to particular node kinds.
+  BinaryOperatorExpression_leftHandSide,
+  BinaryOperatorExpression_operatorToken,
+  BinaryOperatorExpression_rightHandSide,
   CaseStatement_value,
   IfStatement_thenStatement,
   IfStatement_elseKeyword,
@@ -158,6 +162,24 @@ class UnknownExpression final : public Expression {
   }
 };
 
+///   
+///
+/// For example:
+///   a + b
+///   a bitor 1
+///   a |= b
+///   a and_eq b
+class BinaryOperatorExpression final : public Expression {
+public:
+  BinaryOperatorExpression() : Expression(NodeKind::BinaryOperatorExpression) 
{}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::BinaryOperatorExpression;
+  }
+  syntax::Expression *lhs();
+  syntax::Leaf *operatorToken();
+  syntax::Expression *rhs();
+};
+
 /// An abstract node for C++ statements, e.g. 'while', 'if', etc.
 /// FIXME: add accessors for semicolon of statements that have it.
 class Statement : public Tree {

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 11058edec615..8fee44cdbf10 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TypeLoc.h"
@@ -594,10 +595,7 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   for (auto *D : DS->decls())
 Builder.noticeDeclWithoutSemicolon(D);
 } else if (auto *E = llvm::dyn_cast_or_null(S)) {
-  // Do not recurse into subexpressions.
-  // We do not have syntax trees for expressions yet, so we only want to 
see
-  // the first top-level expression.
-  return WalkUpFromExpr(E->IgnoreImplicit());
+  return RecursiveASTVisitor::TraverseStmt(E->IgnoreImplicit());
 }
 return RecursiveASTVisitor::TraverseStmt(S);
   }
@@ -610,6 +608,19 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool WalkUpFromBinaryOperator(BinaryOperator *S) {
+Builder.markExprChild(
+S->getLHS(), syntax::NodeRole::BinaryOperatorExpression_leftHandSide);
+Builder.markChildToken(
+S->getOperatorLoc(),
+syntax::NodeRole::BinaryOperatorExpression_operatorToken);
+Builder.markExprChild(
+S->getRHS(), syntax::NodeRole::BinaryOperatorExpression_rightHandSide);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::BinaryOperatorExpression, S);
+return true;
+  }
+
   bool WalkUpFromNamespaceDecl(NamespaceDecl *S) {
 auto Tokens = Builder.getDeclarationRange(S);
 if (Tokens.front().kind() == tok::coloncolon) {

diff  --git a/clang/lib/Tooling/Syntax/Nodes.cpp 
b/clang/lib/Tooling/Syntax/Nodes.cpp
index 75f025e5f853..84c0143db81d 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,8 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream &OS, 
NodeKind K) {
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::BinaryOperatorExpression:
+return OS << "BinaryOperatorExpression";
   case NodeKind::UnknownStatement:
 return OS << "UnknownStatement";
   case NodeKind::DeclarationStatement:
@@ -110,6 +112,12 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream 
&OS, NodeRole R) {
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
+  case syntax::NodeRole::BinaryOperatorEx

[PATCH] D74387: [OpenMP][SYCL] Improve diagnosing of unsupported types usage

2020-05-26 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

The tests are failing because calling function with unsupported type in 
arguments/return value is diagnosed as well, i.e. :

  double math(float f, double d, long double ld) { ... } // `ld` is not used 
inside the `math` function
  #pragma omp target map(r)
{ r += math(f, d, ld); } // error: 'math' requires 128 bit size 'long 
double' type support, but device 'nvptx64-nvidia-cuda' does not support it

Should we diagnose calls to such functions even if those arguments/return value 
aren't used?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74387



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


[PATCH] D80428: [clang] Optimize SourceManager::getFileIDLocal [WIP]

2020-05-26 Thread Marco Elver via Phabricator via cfe-commits
melver abandoned this revision.
melver added a comment.

More background: https://github.com/ClangBuiltLinux/linux/issues/1032

This approach likely doesn't yield too much benefit. Too much variability is 
observed when compiling Clang with either Clang or GCC.

Since Nick has a better proposal at the above link, let's abandon this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80428



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


[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-05-26 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 266151.
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added a comment.

Fix from `CPlusPlus2a` to `CPlusPlus20` after rebase.


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

https://reviews.llvm.org/D71199

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
@@ -0,0 +1,435 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-prefer-member-initializer %t
+
+class Simple1 {
+  int n;
+  // CHECK-FIXES: int n{0};
+  double x;
+  // CHECK-FIXES: double x{0.0};
+
+public:
+  Simple1() {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple1(int nn, double xx) {
+// CHECK-FIXES: Simple1(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple1() = default;
+};
+
+class Simple2 {
+  int n;
+  double x;
+  // CHECK-FIXES: double x{0.0};
+
+public:
+  Simple2() : n (0) {
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple2(int nn, double xx) : n(nn) {
+// CHECK-FIXES: Simple2(int nn, double xx) : n(nn), x(xx) {
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple2() = default;
+};
+
+class Simple3 {
+  int n;
+  // CHECK-FIXES: int n{0};
+  double x;
+
+public:
+  Simple3() : x (0.0) {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple3(int nn, double xx) : x(xx) {
+// CHECK-FIXES: Simple3(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple3() = default;
+};
+
+int something_int();
+double something_double();
+
+class Simple4 {
+  int n;
+
+public:
+  Simple4() {
+// CHECK-FIXES: Simple4() : n(something_int()) {
+n = something_int();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple4() = default;
+};
+
+static bool dice();
+
+class Complex1 {
+  int n;
+  int m;
+
+public:
+  Complex1() : n(0) {
+if (dice())
+  m = 1;
+// NO-MESSAGES: initialization of 'm' is nested in a conditional expression
+  }
+
+  ~Complex1() = default;
+};
+
+class Complex2 {
+  int n;
+  int m;
+
+public:
+  Complex2() : n(0) {
+if (!dice())
+  return;
+m = 1;
+// NO-MESSAGES: initialization of 'm' follows a conditional expression
+  }
+
+  ~Complex2() = default;
+};
+
+class Complex3 {
+  int n;
+  int m;
+
+public:
+  Complex3() : n(0) {
+while (dice())
+  m = 1;
+// NO-MESSAGES: initialization of 'm' is nested in a conditional loop
+  }
+
+  ~Complex3() = default;
+};
+
+class Complex4 {
+  int n;
+  int m;
+
+public:
+  Complex4() : n(0

[PATCH] D80540: Add support for binary operators in Syntax Trees

2020-05-26 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3785eb83af41: Add support for binary operators in Syntax 
Trees (authored by eduucaldas, committed by gribozavr).

Changed prior to commit:
  https://reviews.llvm.org/D80540?vs=266121&id=266155#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80540

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -564,7 +564,8 @@
 |-{
 |-ExpressionStatement
 | |-UnknownExpression
-| | |-test
+| | |-UnknownExpression
+| | | `-test
 | | |-(
 | | `-)
 | `-;
@@ -576,14 +577,16 @@
 | |-)
 | |-ExpressionStatement
 | | |-UnknownExpression
-| | | |-test
+| | | |-UnknownExpression
+| | | | `-test
 | | | |-(
 | | | `-)
 | | `-;
 | |-else
 | `-ExpressionStatement
 |   |-UnknownExpression
-|   | |-test
+|   | |-UnknownExpression
+|   | | `-test
 |   | |-(
 |   | `-)
 |   `-;
@@ -591,6 +594,237 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, BinaryOperator) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a) {
+  1 - 2;
+  1 == 2;
+  a = 1;
+  a <<= 1;
+
+  true || false;
+  true or false;
+
+  1 & 2;
+  1 bitand 2;
+
+  a ^= 3;
+  a xor_eq 3;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |--
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-==
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-=
+| | `-UnknownExpression
+| |   `-1
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-<<=
+| | `-UnknownExpression
+| |   `-1
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-true
+| | |-||
+| | `-UnknownExpression
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-true
+| | |-or
+| | `-UnknownExpression
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-&
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-bitand
+| | `-UnknownExpression
+| |   `-2
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-^=
+| | `-UnknownExpression
+| |   `-3
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-a
+| | |-xor_eq
+| | `-UnknownExpression
+| |   `-3
+| `-;
+`-}
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, NestedBinaryOperator) {
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a, int b) {
+  (1 + 2) * (4 / 2);
+  a + b + 42;
+  a = b = 42;
+  a + b * 4 + 2;
+  a % 2 + b * 42;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | |-(
+| | | |-BinaryOperatorExpression
+| | | | |-UnknownExpression
+| | | | | `-1
+| | | | |-+
+| | | | `-UnknownExpression
+| | | |   `-2
+| | | `-)
+| | |-*
+| | `-UnknownExpression
+| |   |-(
+| |   |-BinaryOperatorExpression
+| |   | |-UnknownExpression
+| |   | | `-4
+| |   | |-/
+| |   | `-UnknownExpression
+| |   |   `-2
+| |   `-)
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-BinaryOperatorExpression
+| | | |-UnknownExpression
+| | | | `-a
+| | | |-+
+

[PATCH] D80144: [clang-format] @lefticus just taught the world how to use [[unlikely]] but we forgot to teach clang-format

2020-05-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Will this help? D80547: [clang-format] Fix an ObjC regression introduced with 
new [[likely]][[unlikely]] support in if/else clauses 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80144



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


[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: krasimir, JakeMerdichAMD.
MyDeveloperDay added projects: clang, clang-format.

D80144: [clang-format] @lefticus just taught the world how to use [[unlikely]] 
but we forgot to teach clang-format  introduce 
an ObjC regression

Only parse the `[]` if what follows is really an attribute


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80547

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1434,6 +1434,18 @@
   "   }]");
 }
 
+TEST_F(FormatTestObjC, IfNotUnlikely) {
+  Style = getGoogleStyle(FormatStyle::LK_ObjC);
+  Style.ObjCBreakBeforeNestedBlockParam = false;
+
+  verifyFormat("if (argc < 5) [obj func:arg];");
+
+  verifyFormat("if (argc < 5)\n"
+   "  [obj func:arg];\n"
+   "else\n"
+   "  [obj func:arg2];");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -134,6 +134,7 @@
   bool tryToParseLambdaIntroducer();
   bool tryToParsePropertyAccessor();
   void tryToParseJSFunction();
+  bool tryToParseAttribute();
   void addUnwrappedLine();
   bool eof() const;
   // LevelDifference is the difference of levels after and before the current
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1962,7 +1962,7 @@
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   // handle [[likely]] / [[unlikely]]
-  if (FormatTok->is(tok::l_square))
+  if (FormatTok->is(tok::l_square) && tryToParseAttribute())
 parseSquare();
   bool NeedsUnwrappedLine = false;
   if (FormatTok->Tok.is(tok::l_brace)) {
@@ -1981,7 +1981,7 @@
   if (FormatTok->Tok.is(tok::kw_else)) {
 nextToken();
 // handle [[likely]] / [[unlikely]]
-if (FormatTok->is(tok::l_square))
+if (FormatTok->Tok.is(tok::l_square) && tryToParseAttribute())
   parseSquare();
 if (FormatTok->Tok.is(tok::l_brace)) {
   CompoundStatementIndenter Indenter(this, Style, Line->Level);
@@ -2343,6 +2343,18 @@
   // "} n, m;" will end up in one unwrapped line.
 }
 
+// look to see if we have [[ by looking ahead if
+// its not then rewind to the original position
+bool UnwrappedLineParser::tryToParseAttribute() {
+  unsigned StoredPosition = Tokens->getPosition();
+  FormatToken *Tok = Tokens->getNextToken();
+  FormatTok = Tokens->setPosition(StoredPosition);
+  if (Tok->is(tok::l_square)) {
+return true;
+  }
+  return false;
+}
+
 void UnwrappedLineParser::parseJavaEnumBody() {
   // Determine whether the enum is simple, i.e. does not have a semicolon or
   // constants with class bodies. Simple enums can be formatted like braced


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1434,6 +1434,18 @@
   "   }]");
 }
 
+TEST_F(FormatTestObjC, IfNotUnlikely) {
+  Style = getGoogleStyle(FormatStyle::LK_ObjC);
+  Style.ObjCBreakBeforeNestedBlockParam = false;
+
+  verifyFormat("if (argc < 5) [obj func:arg];");
+
+  verifyFormat("if (argc < 5)\n"
+   "  [obj func:arg];\n"
+   "else\n"
+   "  [obj func:arg2];");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -134,6 +134,7 @@
   bool tryToParseLambdaIntroducer();
   bool tryToParsePropertyAccessor();
   void tryToParseJSFunction();
+  bool tryToParseAttribute();
   void addUnwrappedLine();
   bool eof() const;
   // LevelDifference is the difference of levels after and before the current
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1962,7 +1962,7 @@
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   // handle [[likely]] / [[unlikely]]
-  if (FormatTok->is(tok::l_square))
+  if (FormatTok->is(tok::l_square) && tryToParseAttribute())
 parseSquare();
   bool NeedsUnwrappedLine = false;
   if (FormatTok->Tok.is(tok::l_brace)) {
@@ -1981,

[clang] 6f54318 - [analyzer][RetainCount] Remove the CheckOSObject option

2020-05-26 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-05-26T13:22:58+02:00
New Revision: 6f5431846bbf3270d8fc605324e8843c5aaf579b

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

LOG: [analyzer][RetainCount] Remove the CheckOSObject option

As per http://lists.llvm.org/pipermail/cfe-dev/2019-August/063215.html, lets 
get rid of this option.

It presents 2 issues that have bugged me for years now:

* OSObject is NOT a boolean option. It in fact has 3 states:
  * osx.OSObjectRetainCount is enabled but OSObject it set to false: RetainCount
regards the option as disabled.
  * sx.OSObjectRetainCount is enabled and OSObject it set to true: RetainCount
regards the option as enabled.
  * osx.OSObjectRetainCount is disabled: RetainCount regards the option as
disabled.
* The hack involves directly modifying AnalyzerOptions::ConfigTable, which
  shouldn't even be public in the first place.

This still isn't really ideal, because it would be better to preserve the option
and remove the checker (we want visible checkers to be associated with
diagnostics, and hidden options like this one to be associated with changing how
the modeling is done), but backwards compatibility is an issue.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/test-separate-retaincount.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index f0ad8326929e..bc4b7d00e2d4 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1094,15 +1094,6 @@ def NSErrorChecker : Checker<"NSError">,
 def RetainCountChecker : Checker<"RetainCount">,
   HelpText<"Check for leaks and improper reference count management">,
   CheckerOptions<[
-CmdLineOption,
 CmdLineOptiongetValue() == Value;
-  return false;
-}
-
 void ento::registerRetainCountChecker(CheckerManager &Mgr) {
   auto *Chk = Mgr.getChecker();
   Chk->TrackObjCAndCFObjects = true;
-  Chk->TrackNSCFStartParam = getOption(Mgr.getAnalyzerOptions(),
-   "TrackNSCFStartParam",
-   "true");
+  Chk->TrackNSCFStartParam = Mgr.getAnalyzerOptions().getCheckerBooleanOption(
+  Mgr.getCurrentCheckerName(), "TrackNSCFStartParam");
 }
 
 bool ento::shouldRegisterRetainCountChecker(const CheckerManager &mgr) {
@@ -1509,10 +1494,7 @@ bool ento::shouldRegisterRetainCountChecker(const 
CheckerManager &mgr) {
 
 void ento::registerOSObjectRetainCountChecker(CheckerManager &Mgr) {
   auto *Chk = Mgr.getChecker();
-  if (!getOption(Mgr.getAnalyzerOptions(),
- "CheckOSObject",
- "false"))
-Chk->TrackOSObjects = true;
+  Chk->TrackOSObjects = true;
 }
 
 bool ento::shouldRegisterOSObjectRetainCountChecker(const CheckerManager &mgr) 
{

diff  --git a/clang/test/Analysis/analyzer-config.c 
b/clang/test/Analysis/analyzer-config.c
index 778467387382..cb3d40688e91 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -99,7 +99,6 @@
 // CHECK-NEXT: 
optin.osx.cocoa.localizability.NonLocalizedStringChecker:AggressiveReport = 
false
 // CHECK-NEXT: optin.performance.Padding:AllowedPad = 24
 // CHECK-NEXT: osx.NumberObjectConversion:Pedantic = false
-// CHECK-NEXT: osx.cocoa.RetainCount:CheckOSObject = true
 // CHECK-NEXT: osx.cocoa.RetainCount:TrackNSCFStartParam = false
 // CHECK-NEXT: prune-paths = true
 // CHECK-NEXT: region-store-small-struct-limit = 2

diff  --git a/clang/test/Analysis/test-separate-retaincount.cpp 
b/clang/test/Analysis/test-separate-retaincount.cpp
index 621e1d120bbb..41efad452e5a 100644
--- a/clang/test/Analysis/test-separate-retaincount.cpp
+++ b/clang/test/Analysis/test-separate-retaincount.cpp
@@ -5,10 +5,6 @@
 // RUN: %clang_analyze_cc1 -std=c++14 -DNO_OS_OBJECT -verify %s \
 // RUN:   -analyzer-checker=core,osx \
 // RUN:   -analyzer-disable-checker osx.OSObjectRetainCount
-//
-// RUN: %clang_analyze_cc1 -std=c++14 -DNO_OS_OBJECT -verify %s \
-// RUN:   -analyzer-checker=core,osx \
-// RUN:   -analyzer-config "osx.cocoa.RetainCount:CheckOSObject=false"
 
 #include "os_object_base.h"
 



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


[PATCH] D79961: [PGO] Fix computation of fuction Hash

2020-05-26 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

I worry that the hash version bump isn't complete. Doesn't the hash version 
used need to be read/written with the profile data file somewhere?




Comment at: clang/lib/CodeGen/CodeGenPGO.cpp:148
 return PGO_HASH_V1;
   return PGO_HASH_V2;
 }

I guess this needs an update now?



Comment at: clang/lib/CodeGen/CodeGenPGO.cpp:292
 return PGOHash::BinaryOperatorLOr;
   if (HashVersion == PGO_HASH_V2) {
 switch (BO->getOpcode()) {

Should this be >= PGO_HASH_V2 now? And similarly below?



Comment at: clang/lib/CodeGen/CodeGenPGO.cpp:754
+// is buggy because it converts a uint64_t into an array of uint8_t.
+if (HashVersion == PGO_HASH_V1 or HashVersion == PGO_HASH_V2) {
+  MD5.update({(uint8_t)Working});

Maybe just "HashVersion < PGO_HASH_V3" would be simpler?


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

https://reviews.llvm.org/D79961



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


[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked an inline comment as done.
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2348
+// its not then rewind to the original position
+bool UnwrappedLineParser::tryToParseAttribute() {
+  unsigned StoredPosition = Tokens->getPosition();

This so makes me feel like we need a peekNextToken()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80547



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


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:32
+  return;
+if (std::string(Info->getNameStart()) != Check.MacroName)
+  return;

```
if (Info->getName() != Check.MacroName)```
Avoid constructing the string if you don't have to.



Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:36
+// be the class name.
+const Token *classNameTok = Args->getUnexpArgument(0);
+if (Args->ArgNeedsPreexpansion(classNameTok, PP))

s/classNameTok/ClassNameTok



Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:41
+  return;
+clang::IdentifierInfo *classIdent = classNameTok->getIdentifierInfo();
+if (!classIdent)

s/classIndent/ClassIndent



Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:49
+R"cpp({0}(const {0} &) = delete;
+const {0} &operator=(const {0} &) = delete{1})cpp",
+classIdent->getNameStart(), shouldAppendSemi(Range) ? ";" : "");

if you wanted to, you could format this quite easily to avoid the need of 
specifying a formatter in the checks
```{2}const {0} &operator=(const {0} &) = delete{1})cpp",...
Lexer::getIndentationForLine(Range.getBegin(), SM))```



Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h:52
+
+  const std::string MacroName;
+};

I'd prefer this to be private with a getter function



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp:36-38
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  
DISALLOW_COPY_AND_ASSIGN(TestClass1);{{$}}
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  ^{{$}}
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  TestClass1(const TestClass1 &) = 
delete;const TestClass1 &operator=(const TestClass1 &) = delete{{$}}

These really aren't important to test for, so long as the diagnostic and fix it 
are checked, that's all you need to worry about. Like how you have it for 
`TestClass2`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80531



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


[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked an inline comment as done.
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2348
+// its not then rewind to the original position
+bool UnwrappedLineParser::tryToParseAttribute() {
+  unsigned StoredPosition = Tokens->getPosition();

MyDeveloperDay wrote:
> This so makes me feel like we need a peekNextToken()
which is like all the time I have to write

```
Tok->Next && Tok->Next->is(tok::XXX)
Tok->Previous && Tok->Previous ->is(tok::XXX)
```

would be so much smaller code if we had

```
Tok->isNext(tok::XXX)
Tok->isPrevious(tok::XXX)
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80547



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


[PATCH] D78097: [analyzer][RetainCount] Remove the CheckOSObject option

2020-05-26 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f5431846bbf: [analyzer][RetainCount] Remove the 
CheckOSObject option (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D78097?vs=257272&id=266166#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78097

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/test-separate-retaincount.cpp


Index: clang/test/Analysis/test-separate-retaincount.cpp
===
--- clang/test/Analysis/test-separate-retaincount.cpp
+++ clang/test/Analysis/test-separate-retaincount.cpp
@@ -5,10 +5,6 @@
 // RUN: %clang_analyze_cc1 -std=c++14 -DNO_OS_OBJECT -verify %s \
 // RUN:   -analyzer-checker=core,osx \
 // RUN:   -analyzer-disable-checker osx.OSObjectRetainCount
-//
-// RUN: %clang_analyze_cc1 -std=c++14 -DNO_OS_OBJECT -verify %s \
-// RUN:   -analyzer-checker=core,osx \
-// RUN:   -analyzer-config "osx.cocoa.RetainCount:CheckOSObject=false"
 
 #include "os_object_base.h"
 
Index: clang/test/Analysis/analyzer-config.c
===
--- clang/test/Analysis/analyzer-config.c
+++ clang/test/Analysis/analyzer-config.c
@@ -99,7 +99,6 @@
 // CHECK-NEXT: 
optin.osx.cocoa.localizability.NonLocalizedStringChecker:AggressiveReport = 
false
 // CHECK-NEXT: optin.performance.Padding:AllowedPad = 24
 // CHECK-NEXT: osx.NumberObjectConversion:Pedantic = false
-// CHECK-NEXT: osx.cocoa.RetainCount:CheckOSObject = true
 // CHECK-NEXT: osx.cocoa.RetainCount:TrackNSCFStartParam = false
 // CHECK-NEXT: prune-paths = true
 // CHECK-NEXT: region-store-small-struct-limit = 2
Index: 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -1481,26 +1481,11 @@
   return true;
 }
 
-// FIXME: remove this, hack for backwards compatibility:
-// it should be possible to enable the NS/CF retain count checker as
-// osx.cocoa.RetainCount, and it should be possible to disable
-// osx.OSObjectRetainCount using osx.cocoa.RetainCount:CheckOSObject=false.
-static bool getOption(const AnalyzerOptions &Options,
-  StringRef Postfix,
-  StringRef Value) {
-  auto I = Options.Config.find(
-(StringRef("osx.cocoa.RetainCount:") + Postfix).str());
-  if (I != Options.Config.end())
-return I->getValue() == Value;
-  return false;
-}
-
 void ento::registerRetainCountChecker(CheckerManager &Mgr) {
   auto *Chk = Mgr.getChecker();
   Chk->TrackObjCAndCFObjects = true;
-  Chk->TrackNSCFStartParam = getOption(Mgr.getAnalyzerOptions(),
-   "TrackNSCFStartParam",
-   "true");
+  Chk->TrackNSCFStartParam = Mgr.getAnalyzerOptions().getCheckerBooleanOption(
+  Mgr.getCurrentCheckerName(), "TrackNSCFStartParam");
 }
 
 bool ento::shouldRegisterRetainCountChecker(const CheckerManager &mgr) {
@@ -1509,10 +1494,7 @@
 
 void ento::registerOSObjectRetainCountChecker(CheckerManager &Mgr) {
   auto *Chk = Mgr.getChecker();
-  if (!getOption(Mgr.getAnalyzerOptions(),
- "CheckOSObject",
- "false"))
-Chk->TrackOSObjects = true;
+  Chk->TrackOSObjects = true;
 }
 
 bool ento::shouldRegisterOSObjectRetainCountChecker(const CheckerManager &mgr) 
{
Index: clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1095,15 +1095,6 @@
   HelpText<"Check for leaks and improper reference count management">,
   CheckerOptions<[
 CmdLineOption,
-CmdLineOptionIndex: clang/test/Analysis/test-separate-retaincount.cpp
===
--- clang/test/Analysis/test-separate-retaincount.cpp
+++ clang/test/Analysis/test-separate-retaincount.cpp
@@ -5,10 +5,6 @@
 // RUN: %clang_analyze_cc1 -std=c++14 -DNO_OS_OBJECT -verify %s \
 // RUN:   -analyzer-checker=core,osx \
 // RUN:   -analyzer-disable-checker osx.OSObjectRetainCount
-//
-// RUN: %clang_analyze_cc1 -std=c++14 -DNO_OS_OBJECT -verify %s \
-// RUN:   -analyzer-checker=core,osx \
-// RUN:   -analyzer-config "osx.cocoa.RetainCount:CheckOSObject=false"
 
 #include "os_object_base.h"
 
Index: clang/test/Analysis/analyzer-config.c
===
--- clang/test/Analysis/analyzer-config.c
+++ clang/

[PATCH] D79400: [CMAKE] Fix build failure when source directory is read only

2020-05-26 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal added a comment.

Hi,

Sorry for late reply.

> If that is not feasible for some reason, I would lean towards your option 
> (2), but I think more is needed in this patch to ensure the generation script 
> is always run, right?

I think you are right. As of now, just removing the dependency on 
`.git/logs/HEAD` is not triggering the cmake script for even when branch is 
changed. One way I tried to solve this was to retain the dependency on 
`.git/logs/HEAD` if it is present and fallback to `.git/HEAD` if it is missing. 
Basically, `.git/HEAD` will ensure the retrigger on every branch-to-branch 
change or headless checkouts but will not retrigger in case of changes on same 
branch. Not sure if it is a good idea.

Another solution that I found was to use the logic mentioned here: 
https://stackoverflow.com/questions/13920072/how-to-always-run-command-when-building-regardless-of-any-dependency.
 This requires a bit more code, but ensures all the required cases are handled. 
I think this should be used only in case of branchless checkouts and keep the 
old behaviour if `.git/logs/HEAD` is present. I will test this and update here 
if it is able to solve the problem.

> We also don't need to check Clang or LLD source tree separately from LLVM now 
> that everything is in one repo, but the logic for determining Git revision 
> should be still correct.

I will submit this as a separate patch once this gets resolved.

Let me know if your thoughts.

Thanks,
Dhaliwal


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79400



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


Re: [PATCH] D80144: [clang-format] @lefticus just taught the world how to use [[unlikely]] but we forgot to teach clang-format

2020-05-26 Thread Marcus Johnson via cfe-commits
Why objective C?

C++ has attributes and so does C2x, and I believe they’re both getting /have 
the unlikely attribute.

> On May 25, 2020, at 1:10 PM, MyDeveloperDay via Phabricator 
>  wrote:
> 
> MyDeveloperDay added a comment.
> 
> 
> 
>> I know that we didn't have a test for this in ObjC land, but the regression 
>> seems severe enough to revert this
> 
> Sure go ahead, that's the process.
> 
> 
> Repository:
>  rG LLVM Github Monorepo
> 
> CHANGES SINCE LAST ACTION
>  https://reviews.llvm.org/D80144/new/
> 
> https://reviews.llvm.org/D80144
> 
> 
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80548: [Analyzer][NFC] Remove the SubEngine interface

2020-05-26 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: NoQ, Szelethus, martong, balazske.
baloghadamsoftware added a project: clang.
Herald added subscribers: ASDenysPetrov, steakhal, Charusso, gamesh411, dkrupp, 
donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, xazax.hun, 
whisperity, mgorny.

The `SubEngine` interface is an interface with only one implementation 
`EpxrEngine`. Adding other implementations are difficult and very unlikely in 
the near future. Currently, if anything from `ExprEngine` is to be exposed to 
other classes it is moved to `SubEngine` which restricts the alternative 
implementations. The virtual methods are have a slight perofrmance impact. 
Furthermore, instead of the `LLVM`-style inheritance a native inheritance is 
used here, which renders `LLVM` functions like e.g. `cast()` unusable here. 
This patch removes this interface and allows usage of `ExprEngine` directly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80548

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SimpleConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/CMakeLists.txt
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ProgramState.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/lib/StaticAnalyzer/Core/SMTConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SubEngine.cpp

Index: clang/lib/StaticAnalyzer/Core/SubEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/SubEngine.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//== SubEngine.cpp - Interface of the subengine of CoreEngine --*- C++ -*-//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
-
-using namespace clang::ento;
-
-void SubEngine::anchor() { }
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -13,8 +13,8 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValVisitor.h"
 
 using namespace clang;
Index: clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -44,8 +44,8 @@
 ProgramStateRef SimpleConstraintManager::assume(ProgramStateRef State,
 NonLoc Cond, bool Assumption) {
   State = assumeAux(State, Cond, Assumption);
-  if (NotifyAssumeClients && SU)
-return SU->processAssume(State, Cond, Assumption);
+  if (NotifyAssumeClients && EE)
+return EE->processAssume(State, Cond, Assumption);
   return State;
 }
 
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -24,12 +24,12 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
 #include "

[PATCH] D79711: [ARM] Add poly64_t on AArch32.

2020-05-26 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard added a comment.

Should `poly128_t` be available on AArch32 too? I don't see anything in the 
ACLE version you linked restricting it to AArch64 only, and the intrinsics 
reference has a number of intrinsics available for both ISAs using it.




Comment at: clang/include/clang/Basic/TargetBuiltins.h:160
   EltType ET = getEltType();
-  return ET == Poly8 || ET == Poly16;
+  return ET == Poly8 || ET == Poly16 || ET == Poly64;
 }

Should `Poly128` be in this list too?



Comment at: clang/lib/Sema/SemaType.cpp:7658
 } else {
-  // AArch32 polynomial vector are signed.
+  // AArch32 polynomial vectors are signed.
   return BTy->getKind() == BuiltinType::SChar ||

The version of the ACLE you linked says all polynomial types are unsigned, not 
mentioning any difference between AArch32 and AArch64:

  poly8_t, poly16_t, poly64_t and poly128_t are defined as unsigned integer 
types. It is unspecified whether these are the same type as uint8_t, uint16_t, 
uint64_t and uint128_t for overloading and mangling purposes.

Maybe this is something left over from an old version of the ACLE which needs 
updating now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79711



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


[PATCH] D79754: [OpenMP][AMDGCN] Support OpenMP offloading for AMDGCN architecture - Part 1

2020-05-26 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam updated this revision to Diff 266171.
saiislam marked 2 inline comments as done.
saiislam added a comment.

Shifted test cases in openmp-offload-gpu.c for better visual segmentation.
Updated device function test case to be more accurate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79754

Files:
  clang/lib/AST/Decl.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/openmp-offload-gpu.c
  clang/test/OpenMP/amdgcn_device_function_call.cpp
  clang/test/OpenMP/target_parallel_no_exceptions.cpp
  llvm/include/llvm/ADT/Triple.h

Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -692,6 +692,9 @@
 return getArch() == Triple::nvptx || getArch() == Triple::nvptx64;
   }
 
+  /// Tests whether the target is AMDGCN
+  bool isAMDGCN() const { return getArch() == Triple::amdgcn; }
+
   bool isAMDGPU() const {
 return getArch() == Triple::r600 || getArch() == Triple::amdgcn;
   }
Index: clang/test/OpenMP/target_parallel_no_exceptions.cpp
===
--- clang/test/OpenMP/target_parallel_no_exceptions.cpp
+++ clang/test/OpenMP/target_parallel_no_exceptions.cpp
@@ -1,6 +1,7 @@
 /// Make sure no exception messages are inclided in the llvm output.
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -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 - | FileCheck %s --check-prefix CHK-EXCEPTION
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHK-EXCEPTION
 
 void test_increment() {
 #pragma omp target
Index: clang/test/OpenMP/amdgcn_device_function_call.cpp
===
--- /dev/null
+++ clang/test/OpenMP/amdgcn_device_function_call.cpp
@@ -0,0 +1,27 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// RUN: llvm-dis < %t-ppc-host.bc | FileCheck %s -check-prefix=HOST
+
+// device side declarations
+#pragma omp declare target
+extern "C" float cosf(float __x);
+#pragma omp end declare target
+
+// host side declaration
+extern "C" float cosf(float __x);
+
+void test_amdgcn_openmp_device(float __x) {
+  // the default case where predefined library functions are treated as
+  // builtins on the host
+  // HOST: call float @llvm.cos.f32(float
+  __x = cosf(__x);
+
+#pragma omp target
+  {
+// cosf should not be treated as builtin on device
+// CHECK-NOT: call float @llvm.cos.f32(float
+__x = cosf(__x);
+  }
+}
Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -6,6 +6,7 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: powerpc-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 /// ###
 
@@ -254,24 +255,40 @@
 // RUN:   | FileCheck -check-prefix=CUDA_MODE %s
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -fno-openmp-cuda-mode -fopenmp-cuda-mode 2>&1 \
 // RUN:   | FileCheck -check-prefix=CUDA_MODE %s
-// CUDA_MODE: clang{{.*}}"-cc1"{{.*}}"-triple" "nvptx64-nvidia-cuda"
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target -march=gfx906 %s -fopenmp-cuda-mode 2>&1 \
+// RUN:   | FileCheck -check-prefix=CUDA_MODE %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target -march=gfx906 %s -fno-openmp-cuda-mode -fopenmp-cuda-mode 2>&1 \
+// RUN:   | FileCheck -check-prefix=CUDA_MODE %s
+// CUDA_MODE: clang{{.*}}"-cc1"{{.*}}"-triple" "{{nvptx64-nvidia-cuda|amdgcn-amd-amdhsa}}"
 // CUDA_MODE-SAME: "-fopenmp-cuda-mode"
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -fno-openmp-cuda-mode 2>&1 \
 // RUN:   | FileCheck -check-prefix=NO_CUDA_MODE %s
 // RUN:   %clang -### -no-

[PATCH] D79400: [CMAKE] Fix build failure when source directory is read only

2020-05-26 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal added a comment.

> 3. Another way is to gracefully handle the file write error, for which I 
> don't think there is a portable way. (which @scott.linder also suggested)

I have found the portable way to do this. So cmake provides a command-line tool 
`touch` (doc 
) 
which can be used with `execute_process` 
. 
`execute_process` provides a way to suppress the failure using `ERROR_QUIET` 
option. Coming back to `touch`, it behaves similar to `file(WRITE ..)` command  
however, additionally the exit code can be used to check if file was created 
successfully. This retains the old behaviour while still solving the original 
problem. I will update the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79400



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


[clang] 6c906f7 - [Sema] Diagnose more cases of static data members in local or unnamed classes

2020-05-26 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-05-26T13:29:59+01:00
New Revision: 6c906f7785dad3a1dea5357cfde0762952c2a2bd

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

LOG: [Sema] Diagnose more cases of static data members in local or unnamed 
classes

We currently diagnose static data members directly contained in unnamed classes,
but we should also diagnose when they're in a class that is nested (directly or
indirectly) in an unnamed class. Do this by iterating up the list of parent
DeclContexts and checking if any is an unnamed class.

Similarly also check for function or method DeclContexts (which includes things
like blocks and openmp captured statements) as then the class is considered to
be a local class, which means static data members aren't allowed.

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/OpenMP/for_loop_messages.cpp
clang/test/SemaCXX/anonymous-struct.cpp
clang/test/SemaCXX/blocks.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 74a4fd8a06de..6fe48c860864 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6885,18 +6885,34 @@ NamedDecl *Sema::ActOnVariableDeclarator(
 
 if (SC == SC_Static && CurContext->isRecord()) {
   if (const CXXRecordDecl *RD = dyn_cast(DC)) {
-// C++ [class.static.data]p2:
-//   A static data member shall not be a direct member of an unnamed
-//   or local class
-// FIXME: or of a (possibly indirectly) nested class thereof.
-if (RD->isLocalClass()) {
+// Walk up the enclosing DeclContexts to check for any that are
+// incompatible with static data members.
+const DeclContext *FunctionOrMethod = nullptr;
+const CXXRecordDecl *AnonStruct = nullptr;
+for (DeclContext *Ctxt = DC; Ctxt; Ctxt = Ctxt->getParent()) {
+  if (Ctxt->isFunctionOrMethod()) {
+FunctionOrMethod = Ctxt;
+break;
+  }
+  const CXXRecordDecl *ParentDecl = dyn_cast(Ctxt);
+  if (ParentDecl && !ParentDecl->getDeclName()) {
+AnonStruct = ParentDecl;
+break;
+  }
+}
+if (FunctionOrMethod) {
+  // C++ [class.static.data]p5: A local class shall not have static 
data
+  // members.
   Diag(D.getIdentifierLoc(),
diag::err_static_data_member_not_allowed_in_local_class)
 << Name << RD->getDeclName() << RD->getTagKind();
-} else if (!RD->getDeclName()) {
+} else if (AnonStruct) {
+  // C++ [class.static.data]p4: Unnamed classes and classes contained
+  // directly or indirectly within unnamed classes shall not contain
+  // static data members.
   Diag(D.getIdentifierLoc(),
diag::err_static_data_member_not_allowed_in_anon_struct)
-<< Name << RD->getTagKind();
+<< Name << AnonStruct->getTagKind();
   Invalid = true;
 } else if (RD->isUnion()) {
   // C++98 [class.union]p1: If a union contains a static data member,

diff  --git a/clang/test/OpenMP/for_loop_messages.cpp 
b/clang/test/OpenMP/for_loop_messages.cpp
index 73c69ede6d12..087db755273a 100644
--- a/clang/test/OpenMP/for_loop_messages.cpp
+++ b/clang/test/OpenMP/for_loop_messages.cpp
@@ -831,3 +831,13 @@ void test_nowait() {
   for (int i = 0; i < 16; ++i)
 ;
 }
+
+void test_static_data_member() {
+#pragma omp parallel
+#pragma omp for
+  for (int i = 0; i < 16; ++i) {
+class X {
+  static int x; // expected-error {{static data member 'x' not allowed in 
local class 'X'}}
+};
+  }
+}

diff  --git a/clang/test/SemaCXX/anonymous-struct.cpp 
b/clang/test/SemaCXX/anonymous-struct.cpp
index 10f6711dd340..333b8f724f4e 100644
--- a/clang/test/SemaCXX/anonymous-struct.cpp
+++ b/clang/test/SemaCXX/anonymous-struct.cpp
@@ -153,3 +153,21 @@ typedef struct {
   const Empty E;
 } C;
 } // namespace ImplicitDecls
+
+struct {
+  static int x; // expected-error {{static data member 'x' not allowed in 
anonymous struct}}
+} static_member_1;
+
+class {
+  struct A {
+static int x; // expected-error {{static data member 'x' not allowed in 
anonymous class}}
+  } x;
+} static_member_2;
+
+union {
+  struct A {
+struct B {
+  static int x; // expected-error {{static data member 'x' not allowed in 
anonymous union}}
+} x;
+  } x;
+} static_member_3;

diff  --git a/clang/test/SemaCXX/blocks.cpp b/clang/test/SemaCXX/blocks.cpp
index aacf63cfab42..5d0aa2af7360 100644
--- a/clang/test/SemaCXX/blocks.cpp
+++ b/clang/test/SemaCXX/blocks.cpp
@@ -153,3 +153,16 @@ void f() {
   auto some_block = ^{ (void)s; };
 }
 }
+
+void static_data

[PATCH] D77644: [clangd] Handle additional includes while parsing ASTs

2020-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 266174.
kadircet added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77644

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  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
@@ -8,6 +8,7 @@
 
 #include "Annotations.h"
 #include "Compiler.h"
+#include "Headers.h"
 #include "Preamble.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -21,6 +22,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -30,51 +32,56 @@
 namespace clangd {
 namespace {
 
+MATCHER_P2(Distance, File, D, "") {
+  return arg.first() == File && arg.second == D;
+}
+
+std::shared_ptr
+createPreamble(llvm::StringRef Contents = "") {
+  auto TU = TestTU::withCode(Contents);
+  // ms-compatibility changes meaning of #import, make sure it is turned off.
+  TU.ExtraArgs = {"-fno-ms-compatibility"};
+  TU.Filename = "preamble.cpp";
+  auto PI = TU.inputs();
+  IgnoreDiagnostics Diags;
+  auto CI = buildCompilerInvocation(PI, Diags);
+  if (!CI) {
+ADD_FAILURE() << "failed to build compiler invocation";
+return nullptr;
+  }
+  if (auto Preamble = buildPreamble(TU.Filename, *CI, PI, true, nullptr))
+return Preamble;
+  ADD_FAILURE() << "failed to build preamble";
+  return nullptr;
+}
+
 // Builds a preamble for BaselineContents, patches it for ModifiedContents and
 // returns the includes in the patch.
 IncludeStructure
 collectPatchedIncludes(llvm::StringRef ModifiedContents,
llvm::StringRef BaselineContents,
llvm::StringRef MainFileName = "main.cpp") {
-  std::string MainFile = testPath(MainFileName);
-  ParseInputs PI;
-  PI.FS = new llvm::vfs::InMemoryFileSystem;
-  MockCompilationDatabase CDB;
-  // ms-compatibility changes meaning of #import, make sure it is turned off.
-  CDB.ExtraClangFlags.push_back("-fno-ms-compatibility");
-  PI.CompileCommand = CDB.getCompileCommand(MainFile).getValue();
-  // Create invocation
-  IgnoreDiagnostics Diags;
-  auto CI = buildCompilerInvocation(PI, Diags);
-  assert(CI && "failed to create compiler invocation");
-  // Build baseline preamble.
-  PI.Contents = BaselineContents.str();
-  PI.Version = "baseline preamble";
-  auto BaselinePreamble = buildPreamble(MainFile, *CI, PI, true, nullptr);
-  assert(BaselinePreamble && "failed to build baseline preamble");
+  auto BaselinePreamble = createPreamble(BaselineContents);
   // Create the patch.
-  PI.Contents = ModifiedContents.str();
-  PI.Version = "modified contents";
-  auto PP = PreamblePatch::create(MainFile, PI, *BaselinePreamble);
+  auto TU = TestTU::withCode(ModifiedContents);
+  TU.Filename = MainFileName.str();
+  auto PI = TU.inputs();
+  auto PP = PreamblePatch::create(testPath(TU.Filename), PI, *BaselinePreamble);
   // Collect patch contents.
+  IgnoreDiagnostics Diags;
+  auto CI = buildCompilerInvocation(PI, Diags);
   PP.apply(*CI);
-  llvm::StringRef PatchContents;
-  for (const auto &Rempaped : CI->getPreprocessorOpts().RemappedFileBuffers) {
-if (Rempaped.first == testPath("__preamble_patch__.h")) {
-  PatchContents = Rempaped.second->getBuffer();
-  break;
-}
-  }
-  // Run preprocessor over the modified contents with patched Invocation to and
-  // BaselinePreamble to collect includes in the patch. We trim the input to
-  // only preamble section to not collect includes in the mainfile.
+  // Run preprocessor over the modified contents with patched Invocation. We
+  // provide a preamble and trim contents to ensure only the implicit header
+  // introduced by the patch is parsed and nothing else.
+  // We don't run PP directly over the patch cotents to test production
+  // behaviour.
   auto Bounds = Lexer::ComputePreamble(ModifiedContents, *CI->getLangOpts());
   auto Clang =
   prepareCompilerInstance(std::move(CI), &BaselinePreamble->Preamble,
   llvm::MemoryBuffer::getMemBufferCopy(
   ModifiedContents.slice(0, Bounds.Size).str()),
   PI.FS, Diags);
-  Clang->getPreprocessorOpts().ImplicitPCHInclude.clear();
   PreprocessOnlyAction Action;
   if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) {
 ADD_FAILURE() << "failed begin source file";
@@ -163,6 +170,33 @@
   EXPECT_THAT(Includes, ElementsAre(AllOf(Field(&Inclusion::Written, ""),
 

[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Minor remarks.




Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2346
 
+// look to see if we have [[ by looking ahead if
+// its not then rewind to the original position

Nit: shouldn't comments be "Full phrases."?



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2348
+// its not then rewind to the original position
+bool UnwrappedLineParser::tryToParseAttribute() {
+  unsigned StoredPosition = Tokens->getPosition();

MyDeveloperDay wrote:
> MyDeveloperDay wrote:
> > This so makes me feel like we need a peekNextToken()
> which is like all the time I have to write
> 
> ```
> Tok->Next && Tok->Next->is(tok::XXX)
> Tok->Previous && Tok->Previous ->is(tok::XXX)
> ```
> 
> would be so much smaller code if we had
> 
> ```
> Tok->isNext(tok::XXX)
> Tok->isPrevious(tok::XXX)
> ```
`peekNextToken()` probably should be done in a separate revision, nope?
It would be good to have it IMO.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2351
+  FormatToken *Tok = Tokens->getNextToken();
+  FormatTok = Tokens->setPosition(StoredPosition);
+  if (Tok->is(tok::l_square)) {

Maybe add `assert(Tok);`. How can you be know for sure that there's a next 
token?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80547



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


[PATCH] D80295: [Sema] Diagnose more cases of static data members in local or unnamed classes

2020-05-26 Thread John Brawn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6c906f7785da: [Sema] Diagnose more cases of static data 
members in local or unnamed classes (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80295

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/OpenMP/for_loop_messages.cpp
  clang/test/SemaCXX/anonymous-struct.cpp
  clang/test/SemaCXX/blocks.cpp

Index: clang/test/SemaCXX/blocks.cpp
===
--- clang/test/SemaCXX/blocks.cpp
+++ clang/test/SemaCXX/blocks.cpp
@@ -153,3 +153,16 @@
   auto some_block = ^{ (void)s; };
 }
 }
+
+void static_data_member() {
+  auto block = ^{
+class X {
+  static int x; // expected-error {{static data member 'x' not allowed in local class 'X'}}
+};
+class Y {
+  struct Z {
+static int z; // expected-error {{static data member 'z' not allowed in local struct 'Z'}}
+  };
+};
+  };
+}
Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -153,3 +153,21 @@
   const Empty E;
 } C;
 } // namespace ImplicitDecls
+
+struct {
+  static int x; // expected-error {{static data member 'x' not allowed in anonymous struct}}
+} static_member_1;
+
+class {
+  struct A {
+static int x; // expected-error {{static data member 'x' not allowed in anonymous class}}
+  } x;
+} static_member_2;
+
+union {
+  struct A {
+struct B {
+  static int x; // expected-error {{static data member 'x' not allowed in anonymous union}}
+} x;
+  } x;
+} static_member_3;
Index: clang/test/OpenMP/for_loop_messages.cpp
===
--- clang/test/OpenMP/for_loop_messages.cpp
+++ clang/test/OpenMP/for_loop_messages.cpp
@@ -831,3 +831,13 @@
   for (int i = 0; i < 16; ++i)
 ;
 }
+
+void test_static_data_member() {
+#pragma omp parallel
+#pragma omp for
+  for (int i = 0; i < 16; ++i) {
+class X {
+  static int x; // expected-error {{static data member 'x' not allowed in local class 'X'}}
+};
+  }
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -6885,18 +6885,34 @@
 
 if (SC == SC_Static && CurContext->isRecord()) {
   if (const CXXRecordDecl *RD = dyn_cast(DC)) {
-// C++ [class.static.data]p2:
-//   A static data member shall not be a direct member of an unnamed
-//   or local class
-// FIXME: or of a (possibly indirectly) nested class thereof.
-if (RD->isLocalClass()) {
+// Walk up the enclosing DeclContexts to check for any that are
+// incompatible with static data members.
+const DeclContext *FunctionOrMethod = nullptr;
+const CXXRecordDecl *AnonStruct = nullptr;
+for (DeclContext *Ctxt = DC; Ctxt; Ctxt = Ctxt->getParent()) {
+  if (Ctxt->isFunctionOrMethod()) {
+FunctionOrMethod = Ctxt;
+break;
+  }
+  const CXXRecordDecl *ParentDecl = dyn_cast(Ctxt);
+  if (ParentDecl && !ParentDecl->getDeclName()) {
+AnonStruct = ParentDecl;
+break;
+  }
+}
+if (FunctionOrMethod) {
+  // C++ [class.static.data]p5: A local class shall not have static data
+  // members.
   Diag(D.getIdentifierLoc(),
diag::err_static_data_member_not_allowed_in_local_class)
 << Name << RD->getDeclName() << RD->getTagKind();
-} else if (!RD->getDeclName()) {
+} else if (AnonStruct) {
+  // C++ [class.static.data]p4: Unnamed classes and classes contained
+  // directly or indirectly within unnamed classes shall not contain
+  // static data members.
   Diag(D.getIdentifierLoc(),
diag::err_static_data_member_not_allowed_in_anon_struct)
-<< Name << RD->getTagKind();
+<< Name << AnonStruct->getTagKind();
   Invalid = true;
 } else if (RD->isUnion()) {
   // C++98 [class.union]p1: If a union contains a static data member,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69764: [clang-format] Add East/West Const fixer capability

2020-05-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks @MyDeveloperDay for hammering on on these bugs and @steveire for finding 
them! There's still obviously some risk here but as long as this is opt-in for 
a major release or two (i.e. not turned on in built-in styles, any remaining 
bugs should get flushed out.

Regarding option naming, I did think East/West (only) was the way to go but 
have reluctantly changed my mind after rereading the discussion. My conclusions 
were:

- C++ people who have read discussions on this from 2018 on are likely familiar 
with "east const" terminology
- there are people who care about style who aren't familiar with it and 
wouldn't be happy to have to learn/adopt it (this was the main surprise for me)
- 5 years from now, this naming may have spread to ~everyone, may remain 
partially-adopted, or possibly even die out as a fad
- for people familiar with the terminology: "ConstStyle: East" is clearer than 
"ConstStyle: Right" (less ambiguous)
- for people unfamiliar with the terminology, the opposite is certainly true
- asymmetry 1: it's probably harder to work out east=right than to to work out 
that "ConstStyle: right" means const is written on the right of the type
- asymmetry 2: the new terminology is objectively better: terse, memorable, 
doesn't collide with other terms. Some dislike it, which is true of any 
distinctive name (I hate "namespace", for instance).
- there's clearly a cultural tension between reading like a meme-infested 
subreddit and like an IBM technical manual :-)

It's a tough call, but I'd propose a compromise: make Left/Right canonical as 
it's more accessible (don't have to learn new things) and in case East/West 
dies out.
But to have East/West as aliases: to let the community decide over time, and 
because I don't think we should be in the business of hindering adoption of 
better names.

("reluctantly" changed my mind because I do think east/west are better names. 
But meeting users where they are is important too - otherwise we'd just 
hardcode the One True Style :-))


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

https://reviews.llvm.org/D69764



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


[PATCH] D79400: [CMAKE] Fix build failure when source directory is read only

2020-05-26 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal updated this revision to Diff 266172.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79400

Files:
  llvm/cmake/modules/AddLLVM.cmake


Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1937,7 +1937,13 @@
 get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
 # Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
 if (NOT EXISTS "${git_dir}/logs/HEAD")
-  file(WRITE "${git_dir}/logs/HEAD" "")
+  execute_process(COMMAND ${CMAKE_COMMAND} -E touch HEAD
+WORKING_DIRECTORY "${git_dir}/logs"
+RESULT_VARIABLE touch_head_result
+ERROR_QUIET)
+  if (NOT touch_head_result EQUAL 0)
+return()
+  endif()
 endif()
 set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
   endif()


Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1937,7 +1937,13 @@
 get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
 # Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
 if (NOT EXISTS "${git_dir}/logs/HEAD")
-  file(WRITE "${git_dir}/logs/HEAD" "")
+  execute_process(COMMAND ${CMAKE_COMMAND} -E touch HEAD
+WORKING_DIRECTORY "${git_dir}/logs"
+RESULT_VARIABLE touch_head_result
+ERROR_QUIET)
+  if (NOT touch_head_result EQUAL 0)
+return()
+  endif()
 endif()
 set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
   endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D69764: [clang-format] Add East/West Const fixer capability

2020-05-26 Thread Gašper Ažman via cfe-commits
I prefer east/west, but I think there's a terminology that is
uncontroversial (left/right) and one that is controversial. It's also clear
to me that it's better to have only one set of terms (aliases are only fine
for backwards compatibility). Left/Right won, I think.

On Tue, May 26, 2020 at 1:55 PM Sam McCall via Phabricator <
revi...@reviews.llvm.org> wrote:

> sammccall added a comment.
>
> Thanks @MyDeveloperDay for hammering on on these bugs and @steveire for
> finding them! There's still obviously some risk here but as long as this is
> opt-in for a major release or two (i.e. not turned on in built-in styles,
> any remaining bugs should get flushed out.
>
> Regarding option naming, I did think East/West (only) was the way to go
> but have reluctantly changed my mind after rereading the discussion. My
> conclusions were:
>
> - C++ people who have read discussions on this from 2018 on are likely
> familiar with "east const" terminology
> - there are people who care about style who aren't familiar with it and
> wouldn't be happy to have to learn/adopt it (this was the main surprise for
> me)
> - 5 years from now, this naming may have spread to ~everyone, may remain
> partially-adopted, or possibly even die out as a fad
> - for people familiar with the terminology: "ConstStyle: East" is clearer
> than "ConstStyle: Right" (less ambiguous)
> - for people unfamiliar with the terminology, the opposite is certainly
> true
> - asymmetry 1: it's probably harder to work out east=right than to to work
> out that "ConstStyle: right" means const is written on the right of the type
> - asymmetry 2: the new terminology is objectively better: terse,
> memorable, doesn't collide with other terms. Some dislike it, which is true
> of any distinctive name (I hate "namespace", for instance).
> - there's clearly a cultural tension between reading like a meme-infested
> subreddit and like an IBM technical manual :-)
>
> It's a tough call, but I'd propose a compromise: make Left/Right canonical
> as it's more accessible (don't have to learn new things) and in case
> East/West dies out.
> But to have East/West as aliases: to let the community decide over time,
> and because I don't think we should be in the business of hindering
> adoption of better names.
>
> ("reluctantly" changed my mind because I do think east/west are better
> names. But meeting users where they are is important too - otherwise we'd
> just hardcode the One True Style :-))
>
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D69764/new/
>
> https://reviews.llvm.org/D69764
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ff2743b - [libTooling] In Transformer, allow atomic changes to span multiple files.

2020-05-26 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2020-05-26T09:17:35-04:00
New Revision: ff2743bf047deac7ef6cc6c3efd30ff05e55b2ad

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

LOG: [libTooling] In Transformer, allow atomic changes to span multiple files.

Summary:
Currently, all changes returned by a single application of a rule must fit in
one atomic change and therefore must apply to one file. However, there are
patterns in which a single rule will want to modify multiple files; for example,
a header and implementation to change a declaration and its definition. This
patch relaxes Transformer, libTooling's interpreter of RewriteRules, to support
multiple changes.

Reviewers: gribozavr

Subscribers: mgrang, jfb, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Tooling/Transformer/Transformer.cpp
clang/unittests/Tooling/TransformerTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Transformer/Transformer.cpp 
b/clang/lib/Tooling/Transformer/Transformer.cpp
index 93c2c0912d21..71340bf2f676 100644
--- a/clang/lib/Tooling/Transformer/Transformer.cpp
+++ b/clang/lib/Tooling/Transformer/Transformer.cpp
@@ -12,6 +12,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Refactoring/AtomicChange.h"
 #include "llvm/Support/Error.h"
+#include 
 #include 
 #include 
 
@@ -45,28 +46,39 @@ void Transformer::run(const MatchFinder::MatchResult 
&Result) {
 return;
   }
 
-  // Record the results in the AtomicChange, anchored at the location of the
-  // first change.
-  AtomicChange AC(*Result.SourceManager,
-  (*Transformations)[0].Range.getBegin());
+  // Group the transformations, by file, into AtomicChanges, each anchored by
+  // the location of the first change in that file.
+  std::map ChangesByFileID;
   for (const auto &T : *Transformations) {
+auto ID = Result.SourceManager->getFileID(T.Range.getBegin());
+auto Iter = ChangesByFileID
+.emplace(ID, AtomicChange(*Result.SourceManager,
+  T.Range.getBegin()))
+.first;
+auto &AC = Iter->second;
 if (auto Err = AC.replace(*Result.SourceManager, T.Range, T.Replacement)) {
   Consumer(std::move(Err));
   return;
 }
   }
 
-  for (const auto &I : Case.AddedIncludes) {
-auto &Header = I.first;
-switch (I.second) {
-case transformer::IncludeFormat::Quoted:
-  AC.addHeader(Header);
-  break;
-case transformer::IncludeFormat::Angled:
-  AC.addHeader((llvm::Twine("<") + Header + ">").str());
-  break;
+  for (auto &IDChangePair : ChangesByFileID) {
+auto &AC = IDChangePair.second;
+// FIXME: this will add includes to *all* changed files, which may not be
+// the intent. We should upgrade the representation to allow associating
+// headers with specific edits.
+for (const auto &I : Case.AddedIncludes) {
+  auto &Header = I.first;
+  switch (I.second) {
+  case transformer::IncludeFormat::Quoted:
+AC.addHeader(Header);
+break;
+  case transformer::IncludeFormat::Angled:
+AC.addHeader((llvm::Twine("<") + Header + ">").str());
+break;
+  }
 }
-  }
 
-  Consumer(std::move(AC));
+Consumer(std::move(AC));
+  }
 }

diff  --git a/clang/unittests/Tooling/TransformerTest.cpp 
b/clang/unittests/Tooling/TransformerTest.cpp
index 1d955cf5e9b8..c8c6db059fed 100644
--- a/clang/unittests/Tooling/TransformerTest.cpp
+++ b/clang/unittests/Tooling/TransformerTest.cpp
@@ -817,4 +817,46 @@ TEST(TransformerDeathTest, OrderedRuleTypes) {
"Matcher must be.*node matcher");
 }
 #endif
+
+// Edits are able to span multiple files; in this case, a header and an
+// implementation file.
+TEST_F(TransformerTest, MultipleFiles) {
+  std::string Header = R"cc(void RemoveThisFunction();)cc";
+  std::string Source = R"cc(#include "input.h"
+void RemoveThisFunction();)cc";
+  Transformer T(
+  makeRule(functionDecl(hasName("RemoveThisFunction")), changeTo(cat(""))),
+  consumer());
+  T.registerMatchers(&MatchFinder);
+  auto Factory = newFrontendActionFactory(&MatchFinder);
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+  Factory->create(), Source, std::vector(), "input.cc",
+  "clang-tool", std::make_shared(),
+  {{"input.h", Header}}));
+
+  std::sort(Changes.begin(), Changes.end(),
+[](const AtomicChange &L, const AtomicChange &R) {
+  return L.getFilePath() < R.getFilePath();
+});
+
+  ASSERT_EQ(Changes[0].getFilePath(), "./input.h");
+  EXPECT_THAT(Changes[0].getInsertedHeaders(), IsEmpty());
+  EXPECT_THAT(Changes[0].getRemovedHeaders(), IsEmpty());
+  llvm::Expected 

[PATCH] D80239: [libTooling] In Transformer, allow atomic changes to span multiple files.

2020-05-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked 2 inline comments as done.
ymandel added a comment.

Thanks for the review.




Comment at: clang/lib/Tooling/Transformer/Transformer.cpp:65
 
-  for (const auto &I : Case.AddedIncludes) {
-auto &Header = I.first;
-switch (I.second) {
-case transformer::IncludeFormat::Quoted:
-  AC.addHeader(Header);
-  break;
-case transformer::IncludeFormat::Angled:
-  AC.addHeader((llvm::Twine("<") + Header + ">").str());
-  break;
+  for (auto &IDChangePair : ChangesByFileID) {
+auto &AC = IDChangePair.second;

gribozavr2 wrote:
> The test shows an example transformer that removes code, so the header 
> insertion logic is not triggered there. However, for a change that would be 
> adding code, is it correct to insert the header into every file being edited? 
> I think not necessarily. Or do you prefer to deal with this issue when we 
> have a sample use case?
You're right -- these two features don't mix well. Once we support multiple 
files per transformation, we should change the header manipluation to be 
change-specific rather than apply to the whole rule.  That will require some 
re-factoring of the APIs.

For now, I'll put in a FIXME, since this is not (yet) a high demand feature and 
we'll just note the limitations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80239



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


[PATCH] D80198: [clangd] locateMacroAt handles patched macros

2020-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 266187.
kadircet added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80198

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  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
@@ -9,14 +9,19 @@
 #include "Annotations.h"
 #include "Compiler.h"
 #include "Headers.h"
+#include "Hover.h"
 #include "Preamble.h"
+#include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "XRefs.h"
+#include "clang/Format/Format.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "gmock/gmock.h"
@@ -28,6 +33,7 @@
 
 using testing::Contains;
 using testing::Field;
+using testing::Matcher;
 using testing::MatchesRegex;
 
 namespace clang {
@@ -199,7 +205,7 @@
 ADD_FAILURE() << "Failed to build compiler invocation";
 return llvm::None;
   }
-  return ParsedAST::build(testPath("main.cpp"), TU.inputs(), std::move(CI), {},
+  return ParsedAST::build(testPath(TU.Filename), TU.inputs(), std::move(CI), {},
   BaselinePreamble);
 }
 
@@ -228,7 +234,8 @@
 #define BAR
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 2
+#define BAR
 )cpp",
   },
   // multiline macro
@@ -238,7 +245,8 @@
 
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 2
+#define BAR
 )cpp",
   },
   // multiline macro
@@ -248,7 +256,8 @@
 BAR
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 3
+#define BAR
 )cpp",
   },
   };
@@ -275,8 +284,10 @@
   )cpp");
 
   llvm::StringLiteral ExpectedPatch(R"cpp(#line 0 ".*main.cpp"
-#define BAR\(X, Y\) X Y
-#define BAR\(X\) X
+#line 2
+#define BAR\(X, Y\) X Y
+#line 3
+#define BAR\(X\) X
 )cpp");
   EXPECT_THAT(getPreamblePatch(Baseline, Modified.code()),
   MatchesRegex(ExpectedPatch.str()));
@@ -286,6 +297,193 @@
   EXPECT_THAT(AST->getDiagnostics(),
   Not(Contains(Field(&Diag::Range, Modified.range();
 }
+
+TEST(PreamblePatchTest, LocateMacroAtWorks) {
+  struct {
+llvm::StringLiteral Baseline;
+llvm::StringLiteral Modified;
+  } Cases[] = {
+  // Addition of new directive
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+$use^FOO)cpp",
+  },
+  // Available inside preamble section
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+#undef $use^FOO)cpp",
+  },
+  // Available after undef, as we don't patch those
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+#undef FOO
+$use^FOO)cpp",
+  },
+  // Identifier on a different line
+  {
+  "",
+  R"cpp(
+#define \
+  $def^FOO
+$use^FOO)cpp",
+  },
+  // In presence of comment tokens
+  {
+  "",
+  R"cpp(
+#\
+  define /* FOO */\
+  /* FOO */ $def^FOO
+$use^FOO)cpp",
+  },
+  // Moved around
+  {
+  "#define FOO",
+  R"cpp(
+#define BAR
+#define $def^FOO
+$use^FOO)cpp",
+  },
+  };
+  for (const auto &Case : Cases) {
+SCOPED_TRACE(Case.Modified);
+llvm::Annotations Modified(Case.Modified);
+auto AST = createPatchedAST(Case.Baseline, Modified.code());
+ASSERT_TRUE(AST);
+
+const auto &SM = AST->getSourceManager();
+auto *MacroTok = AST->getTokens().spelledTokenAt(
+SM.getComposedLoc(SM.getMainFileID(), Modified.point("use")));
+ASSERT_TRUE(MacroTok);
+
+auto FoundMacro = locateMacroAt(*MacroTok, AST->getPreprocessor());
+ASSERT_TRUE(FoundMacro);
+EXPECT_THAT(FoundMacro->Name, "FOO");
+
+auto MacroLoc = FoundMacro->NameLoc;
+EXPECT_EQ(SM.getFileID(MacroLoc), SM.getMainFileID());
+EXPECT_EQ(SM.getFileOffset(MacroLoc), Modified.point("def"));
+  }
+}
+
+TEST(PreamblePatchTest, LocateMacroAtDeletion) {
+  {
+// We don't patch deleted define directives, make sure we don't crash.
+llvm::StringLiteral 

[PATCH] D80144: [clang-format] @lefticus just taught the world how to use [[unlikely]] but we forgot to teach clang-format

2020-05-26 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

In D80144#2054451 , @MyDeveloperDay 
wrote:

> Will this help? D80547: [clang-format] Fix an ObjC regression introduced with 
> new [[likely]][[unlikely]] support in if/else clauses 
> 


This is awesome! Thank you! I'll switch to commenting there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80144



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


[PATCH] D79961: [PGO] Fix computation of fuction Hash

2020-05-26 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 266184.

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

https://reviews.llvm.org/D79961

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/Profile/Inputs/c-counter-overflows.proftext
  clang/test/Profile/Inputs/c-general.profdata.v2
  clang/test/Profile/Inputs/c-general.profdata.v3
  clang/test/Profile/Inputs/c-general.proftext
  clang/test/Profile/Inputs/c-unprofiled-blocks.proftext
  clang/test/Profile/Inputs/cxx-rangefor.proftext
  clang/test/Profile/Inputs/cxx-throws.proftext
  clang/test/Profile/Inputs/misexpect-switch-default.proftext
  clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
  clang/test/Profile/Inputs/misexpect-switch.proftext
  clang/test/Profile/c-collision.c
  clang/test/Profile/c-general.c

Index: clang/test/Profile/c-general.c
===
--- clang/test/Profile/c-general.c
+++ clang/test/Profile/c-general.c
@@ -5,6 +5,7 @@
 // RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v2 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
 // Also check compatibility with older profiles.
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v1 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
 
Index: clang/test/Profile/c-collision.c
===
--- /dev/null
+++ clang/test/Profile/c-collision.c
@@ -0,0 +1,22 @@
+// Test that a slight change in the code leads to a different hash.
+// RUN: %clang_cc1 -UEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s --check-prefix=CHECK-NOEXTRA
+// RUN: %clang_cc1 -DEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s --check-prefix=CHECK-EXTRA
+
+// CHECK-NOEXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 7156072912471487002,
+// CHECK-EXTRA:   @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 -4383447408116050035,
+
+extern int bar;
+void foo() {
+  if (bar) {
+  }
+  if (bar) {
+  }
+  if (bar) {
+if (bar) {
+#ifdef EXTRA
+  if (bar) {
+  }
+#endif
+}
+  }
+}
Index: clang/test/Profile/Inputs/misexpect-switch.proftext
===
--- clang/test/Profile/Inputs/misexpect-switch.proftext
+++ clang/test/Profile/Inputs/misexpect-switch.proftext
@@ -1,6 +1,6 @@
 main
 # Func Hash:
-1965403898329309329
+872687477373597607
 # Num Counters:
 9
 # Counter Values:
Index: clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
===
--- clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
+++ clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
@@ -1,6 +1,6 @@
 main
 # Func Hash:
-1965403898329309329
+3721743393642630379
 # Num Counters:
 10
 # Counter Values:
Index: clang/test/Profile/Inputs/misexpect-switch-default.proftext
===
--- clang/test/Profile/Inputs/misexpect-switch-default.proftext
+++ clang/test/Profile/Inputs/misexpect-switch-default.proftext
@@ -1,6 +1,6 @@
 main
 # Func Hash:
-8712453512413296413
+8734802134600123338
 # Num Counters:
 9
 # Counter Values:
Index: clang/test/Profile/Inputs/cxx-throws.proftext
===
--- clang/test/Profile/Inputs/cxx-throws.proftext
+++ clang/test/Profile/Inputs/cxx-throws.proftext
@@ -1,5 +1,5 @@
 _Z6throwsv
-340120998528097520
+18172607911962830854
 9
 1
 100
Index: clang/test/Profile/Inputs/cxx-rangefor.proftext
===
--- clang/test/Profile/Inputs/cxx-rangefor.proftext
+++ clang/test/Profile/Inputs/cxx-rangefor.proftext
@@ -1,5 +1,5 @@
 _Z9range_forv
-6169071350249721981
+8789831523895825398
 5
 1
 4
Index: clang/test/Profile/Inputs/c-unprofiled-blocks.proftext
===
--- clang/test/Profile/Inputs/c-unprofiled-blocks.proftext
+++ clang/test/Profile/Inputs/c-unprofi

[PATCH] D79992: [clangd] Patch PP directives to use stale preambles while building ASTs

2020-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 266186.
kadircet added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79992

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  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
@@ -26,7 +26,9 @@
 #include 
 #include 
 
+using testing::Contains;
 using testing::Field;
+using testing::MatchesRegex;
 
 namespace clang {
 namespace clangd {
@@ -181,6 +183,109 @@
   ElementsAre(AllOf(Field(&Inclusion::Written, "\"a.h\""),
 Field(&Inclusion::Resolved, testPath("a.h");
 }
+
+llvm::Optional createPatchedAST(llvm::StringRef Baseline,
+   llvm::StringRef Modified) {
+  auto BaselinePreamble = TestTU::withCode(Baseline).preamble();
+  if (!BaselinePreamble) {
+ADD_FAILURE() << "Failed to build baseline preamble";
+return llvm::None;
+  }
+
+  IgnoreDiagnostics Diags;
+  auto TU = TestTU::withCode(Modified);
+  auto CI = buildCompilerInvocation(TU.inputs(), Diags);
+  if (!CI) {
+ADD_FAILURE() << "Failed to build compiler invocation";
+return llvm::None;
+  }
+  return ParsedAST::build(testPath("main.cpp"), TU.inputs(), std::move(CI), {},
+  BaselinePreamble);
+}
+
+std::string getPreamblePatch(llvm::StringRef Baseline,
+ llvm::StringRef Modified) {
+  auto BaselinePreamble = TestTU::withCode(Baseline).preamble();
+  if (!BaselinePreamble) {
+ADD_FAILURE() << "Failed to build baseline preamble";
+return "";
+  }
+  auto TU = TestTU::withCode(Modified);
+  return PreamblePatch::create(testPath("main.cpp"), TU.inputs(),
+   *BaselinePreamble)
+  .text()
+  .str();
+}
+
+TEST(PreamblePatchTest, Define) {
+  // BAR should be defined while parsing the AST.
+  struct {
+llvm::StringLiteral Contents;
+llvm::StringLiteral ExpectedPatch;
+  } Cases[] = {
+  {
+  R"cpp(
+#define BAR
+[[BAR]])cpp",
+  R"cpp(#line 0 ".*main.cpp"
+#define BAR
+)cpp",
+  },
+  // multiline macro
+  {
+  R"cpp(
+#define BAR \
+
+[[BAR]])cpp",
+  R"cpp(#line 0 ".*main.cpp"
+#define BAR
+)cpp",
+  },
+  // multiline macro
+  {
+  R"cpp(
+#define \
+BAR
+[[BAR]])cpp",
+  R"cpp(#line 0 ".*main.cpp"
+#define BAR
+)cpp",
+  },
+  };
+
+  for (const auto &Case : Cases) {
+SCOPED_TRACE(Case.Contents);
+Annotations Modified(Case.Contents);
+EXPECT_THAT(getPreamblePatch("", Modified.code()),
+MatchesRegex(Case.ExpectedPatch.str()));
+
+auto AST = createPatchedAST("", Modified.code());
+ASSERT_TRUE(AST);
+EXPECT_THAT(AST->getDiagnostics(),
+Not(Contains(Field(&Diag::Range, Modified.range();
+  }
+}
+
+TEST(PreamblePatchTest, OrderingPreserved) {
+  llvm::StringLiteral Baseline = "#define BAR(X) X";
+  Annotations Modified(R"cpp(
+#define BAR(X, Y) X Y
+#define BAR(X) X
+[[BAR]](int y);
+  )cpp");
+
+  llvm::StringLiteral ExpectedPatch(R"cpp(#line 0 ".*main.cpp"
+#define BAR\(X, Y\) X Y
+#define BAR\(X\) X
+)cpp");
+  EXPECT_THAT(getPreamblePatch(Baseline, Modified.code()),
+  MatchesRegex(ExpectedPatch.str()));
+
+  auto AST = createPatchedAST(Baseline, Modified.code());
+  ASSERT_TRUE(AST);
+  EXPECT_THAT(AST->getDiagnostics(),
+  Not(Contains(Field(&Diag::Range, Modified.range();
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Preamble.h
===
--- clang-tools-extra/clangd/Preamble.h
+++ clang-tools-extra/clangd/Preamble.h
@@ -119,6 +119,9 @@
   /// using the presumed-location mechanism.
   std::vector preambleIncludes() const;
 
+  /// Returns textual patch contents.
+  llvm::StringRef text() const { return PatchContents; }
+
 private:
   PreamblePatch() = default;
   std::string PatchContents;
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -106,14 +107,70 @@
   const SourceManager *SourceMgr = nullptr;
 };
 
-/// Gets the includes in the

[PATCH] D79961: [PGO] Fix computation of fuction Hash

2020-05-26 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 266188.
serge-sans-paille marked an inline comment as done.
serge-sans-paille added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Update version bump parts


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

https://reviews.llvm.org/D79961

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/Profile/Inputs/c-counter-overflows.proftext
  clang/test/Profile/Inputs/c-general.profdata.v5
  clang/test/Profile/Inputs/c-general.proftext
  clang/test/Profile/Inputs/c-unprofiled-blocks.proftext
  clang/test/Profile/Inputs/cxx-rangefor.proftext
  clang/test/Profile/Inputs/cxx-throws.proftext
  clang/test/Profile/Inputs/misexpect-switch-default.proftext
  clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
  clang/test/Profile/Inputs/misexpect-switch.proftext
  clang/test/Profile/c-collision.c
  clang/test/Profile/c-general.c
  llvm/include/llvm/ProfileData/InstrProfData.inc

Index: llvm/include/llvm/ProfileData/InstrProfData.inc
===
--- llvm/include/llvm/ProfileData/InstrProfData.inc
+++ llvm/include/llvm/ProfileData/InstrProfData.inc
@@ -655,9 +655,9 @@
 (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
 
 /* Raw profile format version (start from 1). */
-#define INSTR_PROF_RAW_VERSION 5
+#define INSTR_PROF_RAW_VERSION 6
 /* Indexed profile format version (start from 1). */
-#define INSTR_PROF_INDEX_VERSION 5
+#define INSTR_PROF_INDEX_VERSION 6
 /* Coverage mapping format version (start from 0). */
 #define INSTR_PROF_COVMAP_VERSION 3
 
Index: clang/test/Profile/c-general.c
===
--- clang/test/Profile/c-general.c
+++ clang/test/Profile/c-general.c
@@ -4,6 +4,7 @@
 
 // RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v5 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
 // Also check compatibility with older profiles.
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v1 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
Index: clang/test/Profile/c-collision.c
===
--- /dev/null
+++ clang/test/Profile/c-collision.c
@@ -0,0 +1,22 @@
+// Test that a slight change in the code leads to a different hash.
+// RUN: %clang_cc1 -UEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s --check-prefix=CHECK-NOEXTRA
+// RUN: %clang_cc1 -DEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s --check-prefix=CHECK-EXTRA
+
+// CHECK-NOEXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 7156072912471487002,
+// CHECK-EXTRA:   @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 -4383447408116050035,
+
+extern int bar;
+void foo() {
+  if (bar) {
+  }
+  if (bar) {
+  }
+  if (bar) {
+if (bar) {
+#ifdef EXTRA
+  if (bar) {
+  }
+#endif
+}
+  }
+}
Index: clang/test/Profile/Inputs/misexpect-switch.proftext
===
--- clang/test/Profile/Inputs/misexpect-switch.proftext
+++ clang/test/Profile/Inputs/misexpect-switch.proftext
@@ -1,6 +1,6 @@
 main
 # Func Hash:
-1965403898329309329
+872687477373597607
 # Num Counters:
 9
 # Counter Values:
Index: clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
===
--- clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
+++ clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
@@ -1,6 +1,6 @@
 main
 # Func Hash:
-1965403898329309329
+3721743393642630379
 # Num Counters:
 10
 # Counter Values:
Index: clang/test/Profile/Inputs/misexpect-switch-default.proftext
===
--- clang/test/Profile/Inputs/misexpect-switch-default.proftext
+++ clang/test/Profile/Inputs/misexpect-switch-default.proftext
@@ -1,6 +1,6 @@
 main
 # Func Hash:
-8712453512413296413
+8734802134600123338
 # Num Counters:
 9
 # Counter Values:

[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked an inline comment as done.
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2348
+// its not then rewind to the original position
+bool UnwrappedLineParser::tryToParseAttribute() {
+  unsigned StoredPosition = Tokens->getPosition();

curdeius wrote:
> MyDeveloperDay wrote:
> > MyDeveloperDay wrote:
> > > This so makes me feel like we need a peekNextToken()
> > which is like all the time I have to write
> > 
> > ```
> > Tok->Next && Tok->Next->is(tok::XXX)
> > Tok->Previous && Tok->Previous ->is(tok::XXX)
> > ```
> > 
> > would be so much smaller code if we had
> > 
> > ```
> > Tok->isNext(tok::XXX)
> > Tok->isPrevious(tok::XXX)
> > ```
> `peekNextToken()` probably should be done in a separate revision, nope?
> It would be good to have it IMO.
yes I was just thinking out loud..


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

https://reviews.llvm.org/D80547



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


[PATCH] D80239: [libTooling] In Transformer, allow atomic changes to span multiple files.

2020-05-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 266190.
ymandel marked an inline comment as done.
ymandel added a comment.
Herald added subscribers: llvm-commits, dmgreen.
Herald added a project: LLVM.

adds fixme comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80239

Files:
  clang/lib/Tooling/Transformer/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp
  llvm/test/CodeGen/Thumb2/mve-vmaxv.ll

Index: llvm/test/CodeGen/Thumb2/mve-vmaxv.ll
===
--- llvm/test/CodeGen/Thumb2/mve-vmaxv.ll
+++ llvm/test/CodeGen/Thumb2/mve-vmaxv.ll
@@ -14,8 +14,8 @@
 declare i16 @llvm.experimental.vector.reduce.umin.v8i16(<8 x i16>)
 declare i32 @llvm.experimental.vector.reduce.umin.v4i32(<4 x i32>)
 
-define arm_aapcs_vfpcc i8 @vmaxv_s_v16i8_i32(<16 x i8> %s1) {
-; CHECK-LABEL: vmaxv_s_v16i8_i32:
+define arm_aapcs_vfpcc i8 @vmaxv_s_v16i8(<16 x i8> %s1) {
+; CHECK-LABEL: vmaxv_s_v16i8:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:mvn r0, #127
 ; CHECK-NEXT:vmaxv.s8 r0, q0
@@ -24,8 +24,8 @@
   ret i8 %r
 }
 
-define arm_aapcs_vfpcc i16 @vmaxv_s_v8i16_i32(<8 x i16> %s1) {
-; CHECK-LABEL: vmaxv_s_v8i16_i32:
+define arm_aapcs_vfpcc i16 @vmaxv_s_v8i16(<8 x i16> %s1) {
+; CHECK-LABEL: vmaxv_s_v8i16:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:movw r0, #32768
 ; CHECK-NEXT:movt r0, #65535
@@ -35,8 +35,8 @@
   ret i16 %r
 }
 
-define arm_aapcs_vfpcc i32 @vmaxv_s_v4i32_i32(<4 x i32> %s1) {
-; CHECK-LABEL: vmaxv_s_v4i32_i32:
+define arm_aapcs_vfpcc i32 @vmaxv_s_v4i32(<4 x i32> %s1) {
+; CHECK-LABEL: vmaxv_s_v4i32:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:mov.w r0, #-2147483648
 ; CHECK-NEXT:vmaxv.s32 r0, q0
@@ -45,8 +45,8 @@
   ret i32 %r
 }
 
-define arm_aapcs_vfpcc i8 @vmaxv_u_v16i8_i32(<16 x i8> %s1) {
-; CHECK-LABEL: vmaxv_u_v16i8_i32:
+define arm_aapcs_vfpcc i8 @vmaxv_u_v16i8(<16 x i8> %s1) {
+; CHECK-LABEL: vmaxv_u_v16i8:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:movs r0, #0
 ; CHECK-NEXT:vmaxv.u8 r0, q0
@@ -55,8 +55,8 @@
   ret i8 %r
 }
 
-define arm_aapcs_vfpcc i16 @vmaxv_u_v8i16_i32(<8 x i16> %s1) {
-; CHECK-LABEL: vmaxv_u_v8i16_i32:
+define arm_aapcs_vfpcc i16 @vmaxv_u_v8i16(<8 x i16> %s1) {
+; CHECK-LABEL: vmaxv_u_v8i16:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:movs r0, #0
 ; CHECK-NEXT:vmaxv.u16 r0, q0
@@ -65,8 +65,8 @@
   ret i16 %r
 }
 
-define arm_aapcs_vfpcc i32 @vmaxv_u_v4i32_i32(<4 x i32> %s1) {
-; CHECK-LABEL: vmaxv_u_v4i32_i32:
+define arm_aapcs_vfpcc i32 @vmaxv_u_v4i32(<4 x i32> %s1) {
+; CHECK-LABEL: vmaxv_u_v4i32:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:movs r0, #0
 ; CHECK-NEXT:vmaxv.u32 r0, q0
@@ -75,8 +75,8 @@
   ret i32 %r
 }
 
-define arm_aapcs_vfpcc i8 @vminv_s_v16i8_i32(<16 x i8> %s1) {
-; CHECK-LABEL: vminv_s_v16i8_i32:
+define arm_aapcs_vfpcc i8 @vminv_s_v16i8(<16 x i8> %s1) {
+; CHECK-LABEL: vminv_s_v16i8:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:movs r0, #127
 ; CHECK-NEXT:vminv.s8 r0, q0
@@ -85,8 +85,8 @@
   ret i8 %r
 }
 
-define arm_aapcs_vfpcc i16 @vminv_s_v8i16_i32(<8 x i16> %s1) {
-; CHECK-LABEL: vminv_s_v8i16_i32:
+define arm_aapcs_vfpcc i16 @vminv_s_v8i16(<8 x i16> %s1) {
+; CHECK-LABEL: vminv_s_v8i16:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:movw r0, #32767
 ; CHECK-NEXT:vminv.s16 r0, q0
@@ -95,8 +95,8 @@
   ret i16 %r
 }
 
-define arm_aapcs_vfpcc i32 @vminv_s_v4i32_i32(<4 x i32> %s1) {
-; CHECK-LABEL: vminv_s_v4i32_i32:
+define arm_aapcs_vfpcc i32 @vminv_s_v4i32(<4 x i32> %s1) {
+; CHECK-LABEL: vminv_s_v4i32:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:mvn r0, #-2147483648
 ; CHECK-NEXT:vminv.s32 r0, q0
@@ -105,8 +105,8 @@
   ret i32 %r
 }
 
-define arm_aapcs_vfpcc i8 @vminv_u_v16i8_i32(<16 x i8> %s1) {
-; CHECK-LABEL: vminv_u_v16i8_i32:
+define arm_aapcs_vfpcc i8 @vminv_u_v16i8(<16 x i8> %s1) {
+; CHECK-LABEL: vminv_u_v16i8:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:movs r0, #255
 ; CHECK-NEXT:vminv.u8 r0, q0
@@ -115,8 +115,8 @@
   ret i8 %r
 }
 
-define arm_aapcs_vfpcc i16 @vminv_u_v8i16_i32(<8 x i16> %s1) {
-; CHECK-LABEL: vminv_u_v8i16_i32:
+define arm_aapcs_vfpcc i16 @vminv_u_v8i16(<8 x i16> %s1) {
+; CHECK-LABEL: vminv_u_v8i16:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:movw r0, #65535
 ; CHECK-NEXT:vminv.u16 r0, q0
@@ -125,8 +125,8 @@
   ret i16 %r
 }
 
-define arm_aapcs_vfpcc i32 @vminv_u_v4i32_i32(<4 x i32> %s1) {
-; CHECK-LABEL: vminv_u_v4i32_i32:
+define arm_aapcs_vfpcc i32 @vminv_u_v4i32(<4 x i32> %s1) {
+; CHECK-LABEL: vminv_u_v4i32:
 ; CHECK:   @ %bb.0:
 ; CHECK-NEXT:mov.w r0, #-1
 ; CHECK-NEXT:vminv.u32 r0, q0
@@ -134,3 +134,339 @@
   %r = call i32 @llvm.experimental.vector.reduce.umin.v4i32(<4 x i32> %s1)
   ret i32 %r
 }
+
+
+
+define arm_aapcs_vfpcc i8 @vmaxv_s_v16i8_i8(<16 x i8> %s1, i8 %s2) {
+; CHECK-LABEL: vmaxv_s_v16i8_i8:
+; CHECK:   @ %bb.0:
+; CHECK-NEXT:mvn r1, #127
+; CHECK-NEXT:sxtb r3, r0
+; CHECK-NEXT:vmaxv.s8 r1, q0
+; CHECK-NEX

[PATCH] D80239: [libTooling] In Transformer, allow atomic changes to span multiple files.

2020-05-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 266191.
ymandel added a comment.

fixes rebase mistake in previous diff


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80239

Files:
  clang/lib/Tooling/Transformer/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -817,4 +817,46 @@
"Matcher must be.*node matcher");
 }
 #endif
+
+// Edits are able to span multiple files; in this case, a header and an
+// implementation file.
+TEST_F(TransformerTest, MultipleFiles) {
+  std::string Header = R"cc(void RemoveThisFunction();)cc";
+  std::string Source = R"cc(#include "input.h"
+void RemoveThisFunction();)cc";
+  Transformer T(
+  makeRule(functionDecl(hasName("RemoveThisFunction")), changeTo(cat(""))),
+  consumer());
+  T.registerMatchers(&MatchFinder);
+  auto Factory = newFrontendActionFactory(&MatchFinder);
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+  Factory->create(), Source, std::vector(), "input.cc",
+  "clang-tool", std::make_shared(),
+  {{"input.h", Header}}));
+
+  std::sort(Changes.begin(), Changes.end(),
+[](const AtomicChange &L, const AtomicChange &R) {
+  return L.getFilePath() < R.getFilePath();
+});
+
+  ASSERT_EQ(Changes[0].getFilePath(), "./input.h");
+  EXPECT_THAT(Changes[0].getInsertedHeaders(), IsEmpty());
+  EXPECT_THAT(Changes[0].getRemovedHeaders(), IsEmpty());
+  llvm::Expected UpdatedCode =
+  clang::tooling::applyAllReplacements(Header,
+   Changes[0].getReplacements());
+  ASSERT_TRUE(static_cast(UpdatedCode))
+  << "Could not update code: " << llvm::toString(UpdatedCode.takeError());
+  EXPECT_EQ(format(*UpdatedCode), format(R"cc(;)cc"));
+
+  ASSERT_EQ(Changes[1].getFilePath(), "input.cc");
+  EXPECT_THAT(Changes[1].getInsertedHeaders(), IsEmpty());
+  EXPECT_THAT(Changes[1].getRemovedHeaders(), IsEmpty());
+  UpdatedCode = clang::tooling::applyAllReplacements(
+  Source, Changes[1].getReplacements());
+  ASSERT_TRUE(static_cast(UpdatedCode))
+  << "Could not update code: " << llvm::toString(UpdatedCode.takeError());
+  EXPECT_EQ(format(*UpdatedCode), format(R"cc(#include "input.h"
+;)cc"));
+}
 } // namespace
Index: clang/lib/Tooling/Transformer/Transformer.cpp
===
--- clang/lib/Tooling/Transformer/Transformer.cpp
+++ clang/lib/Tooling/Transformer/Transformer.cpp
@@ -12,6 +12,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Refactoring/AtomicChange.h"
 #include "llvm/Support/Error.h"
+#include 
 #include 
 #include 
 
@@ -45,28 +46,39 @@
 return;
   }
 
-  // Record the results in the AtomicChange, anchored at the location of the
-  // first change.
-  AtomicChange AC(*Result.SourceManager,
-  (*Transformations)[0].Range.getBegin());
+  // Group the transformations, by file, into AtomicChanges, each anchored by
+  // the location of the first change in that file.
+  std::map ChangesByFileID;
   for (const auto &T : *Transformations) {
+auto ID = Result.SourceManager->getFileID(T.Range.getBegin());
+auto Iter = ChangesByFileID
+.emplace(ID, AtomicChange(*Result.SourceManager,
+  T.Range.getBegin()))
+.first;
+auto &AC = Iter->second;
 if (auto Err = AC.replace(*Result.SourceManager, T.Range, T.Replacement)) {
   Consumer(std::move(Err));
   return;
 }
   }
 
-  for (const auto &I : Case.AddedIncludes) {
-auto &Header = I.first;
-switch (I.second) {
-case transformer::IncludeFormat::Quoted:
-  AC.addHeader(Header);
-  break;
-case transformer::IncludeFormat::Angled:
-  AC.addHeader((llvm::Twine("<") + Header + ">").str());
-  break;
+  for (auto &IDChangePair : ChangesByFileID) {
+auto &AC = IDChangePair.second;
+// FIXME: this will add includes to *all* changed files, which may not be
+// the intent. We should upgrade the representation to allow associating
+// headers with specific edits.
+for (const auto &I : Case.AddedIncludes) {
+  auto &Header = I.first;
+  switch (I.second) {
+  case transformer::IncludeFormat::Quoted:
+AC.addHeader(Header);
+break;
+  case transformer::IncludeFormat::Angled:
+AC.addHeader((llvm::Twine("<") + Header + ">").str());
+break;
+  }
 }
-  }
 
-  Consumer(std::move(AC));
+Consumer(std::move(AC));
+  }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/

[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 266192.
MyDeveloperDay added a comment.

Check for null Tok
Fix up comments


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

https://reviews.llvm.org/D80547

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1434,6 +1434,22 @@
   "   }]");
 }
 
+TEST_F(FormatTestObjC, IfNotUnlikely) {
+  Style = getGoogleStyle(FormatStyle::LK_ObjC);
+
+  verifyFormat("if (argc < 5) [obj func:arg];");
+
+  verifyFormat("if (argc < 5)\n"
+   "  [obj func:arg];\n"
+   "else\n"
+   "  [obj func:arg2];");
+
+  verifyFormat("if (argc < 5) [[unlikely]]\n"
+   "  [obj func:arg];\n"
+   "else [[likely]]\n"
+   "  [obj func:arg2];");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -134,6 +134,7 @@
   bool tryToParseLambdaIntroducer();
   bool tryToParsePropertyAccessor();
   void tryToParseJSFunction();
+  bool tryToParseAttribute();
   void addUnwrappedLine();
   bool eof() const;
   // LevelDifference is the difference of levels after and before the current
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1962,7 +1962,7 @@
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   // handle [[likely]] / [[unlikely]]
-  if (FormatTok->is(tok::l_square))
+  if (FormatTok->is(tok::l_square) && tryToParseAttribute())
 parseSquare();
   bool NeedsUnwrappedLine = false;
   if (FormatTok->Tok.is(tok::l_brace)) {
@@ -1981,7 +1981,7 @@
   if (FormatTok->Tok.is(tok::kw_else)) {
 nextToken();
 // handle [[likely]] / [[unlikely]]
-if (FormatTok->is(tok::l_square))
+if (FormatTok->Tok.is(tok::l_square) && tryToParseAttribute())
   parseSquare();
 if (FormatTok->Tok.is(tok::l_brace)) {
   CompoundStatementIndenter Indenter(this, Style, Line->Level);
@@ -2343,6 +2343,18 @@
   // "} n, m;" will end up in one unwrapped line.
 }
 
+// Look to see if we have [[ by looking ahead, if
+// its not then rewind to the original position.
+bool UnwrappedLineParser::tryToParseAttribute() {
+  unsigned StoredPosition = Tokens->getPosition();
+  FormatToken *Tok = Tokens->getNextToken();
+  FormatTok = Tokens->setPosition(StoredPosition);
+  if (Tok && Tok->is(tok::l_square)) {
+return true;
+  }
+  return false;
+}
+
 void UnwrappedLineParser::parseJavaEnumBody() {
   // Determine whether the enum is simple, i.e. does not have a semicolon or
   // constants with class bodies. Simple enums can be formatted like braced


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1434,6 +1434,22 @@
   "   }]");
 }
 
+TEST_F(FormatTestObjC, IfNotUnlikely) {
+  Style = getGoogleStyle(FormatStyle::LK_ObjC);
+
+  verifyFormat("if (argc < 5) [obj func:arg];");
+
+  verifyFormat("if (argc < 5)\n"
+   "  [obj func:arg];\n"
+   "else\n"
+   "  [obj func:arg2];");
+
+  verifyFormat("if (argc < 5) [[unlikely]]\n"
+   "  [obj func:arg];\n"
+   "else [[likely]]\n"
+   "  [obj func:arg2];");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -134,6 +134,7 @@
   bool tryToParseLambdaIntroducer();
   bool tryToParsePropertyAccessor();
   void tryToParseJSFunction();
+  bool tryToParseAttribute();
   void addUnwrappedLine();
   bool eof() const;
   // LevelDifference is the difference of levels after and before the current
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1962,7 +1962,7 @@
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   // handle [[likely]] / [[unlikely]]
-  if (FormatTok->is(tok::l_square))
+  if (FormatTok->is(tok::l_square) && tryToParseAttribute())
 parseSquare();
   bool NeedsUnwrappedLine = false;
   if (FormatTok->Tok.is(tok::l_brace)) {
@@ -1981,7 +1981,

[PATCH] D80239: [libTooling] In Transformer, allow atomic changes to span multiple files.

2020-05-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGff2743bf047d: [libTooling] In Transformer, allow atomic 
changes to span multiple files. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80239

Files:
  clang/lib/Tooling/Transformer/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -817,4 +817,46 @@
"Matcher must be.*node matcher");
 }
 #endif
+
+// Edits are able to span multiple files; in this case, a header and an
+// implementation file.
+TEST_F(TransformerTest, MultipleFiles) {
+  std::string Header = R"cc(void RemoveThisFunction();)cc";
+  std::string Source = R"cc(#include "input.h"
+void RemoveThisFunction();)cc";
+  Transformer T(
+  makeRule(functionDecl(hasName("RemoveThisFunction")), changeTo(cat(""))),
+  consumer());
+  T.registerMatchers(&MatchFinder);
+  auto Factory = newFrontendActionFactory(&MatchFinder);
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+  Factory->create(), Source, std::vector(), "input.cc",
+  "clang-tool", std::make_shared(),
+  {{"input.h", Header}}));
+
+  std::sort(Changes.begin(), Changes.end(),
+[](const AtomicChange &L, const AtomicChange &R) {
+  return L.getFilePath() < R.getFilePath();
+});
+
+  ASSERT_EQ(Changes[0].getFilePath(), "./input.h");
+  EXPECT_THAT(Changes[0].getInsertedHeaders(), IsEmpty());
+  EXPECT_THAT(Changes[0].getRemovedHeaders(), IsEmpty());
+  llvm::Expected UpdatedCode =
+  clang::tooling::applyAllReplacements(Header,
+   Changes[0].getReplacements());
+  ASSERT_TRUE(static_cast(UpdatedCode))
+  << "Could not update code: " << llvm::toString(UpdatedCode.takeError());
+  EXPECT_EQ(format(*UpdatedCode), format(R"cc(;)cc"));
+
+  ASSERT_EQ(Changes[1].getFilePath(), "input.cc");
+  EXPECT_THAT(Changes[1].getInsertedHeaders(), IsEmpty());
+  EXPECT_THAT(Changes[1].getRemovedHeaders(), IsEmpty());
+  UpdatedCode = clang::tooling::applyAllReplacements(
+  Source, Changes[1].getReplacements());
+  ASSERT_TRUE(static_cast(UpdatedCode))
+  << "Could not update code: " << llvm::toString(UpdatedCode.takeError());
+  EXPECT_EQ(format(*UpdatedCode), format(R"cc(#include "input.h"
+;)cc"));
+}
 } // namespace
Index: clang/lib/Tooling/Transformer/Transformer.cpp
===
--- clang/lib/Tooling/Transformer/Transformer.cpp
+++ clang/lib/Tooling/Transformer/Transformer.cpp
@@ -12,6 +12,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Refactoring/AtomicChange.h"
 #include "llvm/Support/Error.h"
+#include 
 #include 
 #include 
 
@@ -45,28 +46,39 @@
 return;
   }
 
-  // Record the results in the AtomicChange, anchored at the location of the
-  // first change.
-  AtomicChange AC(*Result.SourceManager,
-  (*Transformations)[0].Range.getBegin());
+  // Group the transformations, by file, into AtomicChanges, each anchored by
+  // the location of the first change in that file.
+  std::map ChangesByFileID;
   for (const auto &T : *Transformations) {
+auto ID = Result.SourceManager->getFileID(T.Range.getBegin());
+auto Iter = ChangesByFileID
+.emplace(ID, AtomicChange(*Result.SourceManager,
+  T.Range.getBegin()))
+.first;
+auto &AC = Iter->second;
 if (auto Err = AC.replace(*Result.SourceManager, T.Range, T.Replacement)) {
   Consumer(std::move(Err));
   return;
 }
   }
 
-  for (const auto &I : Case.AddedIncludes) {
-auto &Header = I.first;
-switch (I.second) {
-case transformer::IncludeFormat::Quoted:
-  AC.addHeader(Header);
-  break;
-case transformer::IncludeFormat::Angled:
-  AC.addHeader((llvm::Twine("<") + Header + ">").str());
-  break;
+  for (auto &IDChangePair : ChangesByFileID) {
+auto &AC = IDChangePair.second;
+// FIXME: this will add includes to *all* changed files, which may not be
+// the intent. We should upgrade the representation to allow associating
+// headers with specific edits.
+for (const auto &I : Case.AddedIncludes) {
+  auto &Header = I.first;
+  switch (I.second) {
+  case transformer::IncludeFormat::Quoted:
+AC.addHeader(Header);
+break;
+  case transformer::IncludeFormat::Angled:
+AC.addHeader((llvm::Twine("<") + Header + ">").str());
+break;
+  }
 }
-  }
 
-  Consumer(std::move(AC));
+Consumer(std::move(AC));
+  }
 }
___
cfe-co

[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2348
+// its not then rewind to the original position
+bool UnwrappedLineParser::tryToParseAttribute() {
+  unsigned StoredPosition = Tokens->getPosition();

MyDeveloperDay wrote:
> curdeius wrote:
> > MyDeveloperDay wrote:
> > > MyDeveloperDay wrote:
> > > > This so makes me feel like we need a peekNextToken()
> > > which is like all the time I have to write
> > > 
> > > ```
> > > Tok->Next && Tok->Next->is(tok::XXX)
> > > Tok->Previous && Tok->Previous ->is(tok::XXX)
> > > ```
> > > 
> > > would be so much smaller code if we had
> > > 
> > > ```
> > > Tok->isNext(tok::XXX)
> > > Tok->isPrevious(tok::XXX)
> > > ```
> > `peekNextToken()` probably should be done in a separate revision, nope?
> > It would be good to have it IMO.
> yes I was just thinking out loud..
I think this should be more strict and check for the sequence of 5 tokens: 
```
tok::l_square, tok::l_square, tok::identifier, tok::r_square, tok::r_square
```

Unfortunately `[[` may start a nested Objective-C-style method call, e.g., 
```
[[obj1 method1:arg1] method2:arg2]
```
(I'm not super familiar with Objective-C-syntax, please correct me if I'm wrong 
about that.)

(Only checking for the last `]]`, or a combination of `[[` and `]]` that 
doesn't examine //the meat in-between// would suffer from similar ambiguities.)

Of course, attributes can be more complicated and can have a rich internal 
structure (looking at https://en.cppreference.com/w/cpp/language/attributes). 
Consider renaming this to `tryToParseSimpleAttribute` to not give folks false 
hopes that this deals with the general problem for now (we can rename this 
later as we improve this C++ attribute parsing to handle more of the 
interesting cases).



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2351
+  FormatToken *Tok = Tokens->getNextToken();
+  FormatTok = Tokens->setPosition(StoredPosition);
+  if (Tok->is(tok::l_square)) {

curdeius wrote:
> Maybe add `assert(Tok);`. How can you be know for sure that there's a next 
> token?
+1, but instead of `assert`-ing which may/will crash clang-format on weird 
inputs and may lead to UB below in release builds, just `return false` and move 
on.


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

https://reviews.llvm.org/D80547



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


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst:23
+  private:
+  -  DISALLOW_COPY_AND_ASSIGN(Foo);
+  +  Foo(const Foo &) = delete;

I think two code snippets would be more readable.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst:29
+Known Limitations
+-
+* Notice that the migration example above leaves the ``private`` access

Please insert empty line below.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst:31
+* Notice that the migration example above leaves the ``private`` access
+  specification untouched. This opens room for improvement, yes I know.
+

Please refer to //modernize-use-equals-delete// instead of second statement.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80531



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


[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-05-26 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 266195.
dang added a comment.

Address some code review comments and sketch support for options that take a 
single value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -9,6 +9,7 @@
 #include "OptEmitter.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
@@ -33,6 +34,22 @@
   return OS;
 }
 
+static void emitMarshallingInfoFlag(raw_ostream &OS, const Record *R) {
+  OS << R->getValueAsBit("IsPositive");
+  OS << ",";
+  OS << R->getValueAsString("DefaultValue");
+}
+
+static void emitMarshallingInfoString(raw_ostream &OS, const Record *R) {
+  OS << R->getValueAsString("DefaultValue");
+  OS << ", ";
+  OS << R->getValueAsString("Normalizer");
+  OS << ", ";
+  OS << R->getValueAsString("Denormalizer");
+}
+
+static void emitMarshallingInfoEnum(raw_ostream &OS, const Record *R) {}
+
 /// OptParserEmitter - This tablegen backend takes an input .td file
 /// describing a list of options and emits a data structure for parsing and
 /// working with those options when given an input command line.
@@ -135,12 +152,8 @@
 
   OS << "//\n";
   OS << "// Options\n\n";
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-const Record &R = *Opts[i];
-
-// Start a single option entry.
-OS << "OPTION(";
 
+  auto WriteOptRecordFields = [&](raw_ostream &OS, const Record &R) {
 // The option prefix;
 std::vector prf = R.getValueAsListOfStrings("Prefixes");
 OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", ";
@@ -149,7 +162,7 @@
 write_cstring(OS, R.getValueAsString("Name"));
 
 // The option identifier name.
-OS  << ", "<< getOptionName(R);
+OS << ", " << getOptionName(R);
 
 // The option kind.
 OS << ", " << R.getValueAsDef("Kind")->getValueAsString("Name");
@@ -190,8 +203,7 @@
 int NumFlags = 0;
 const ListInit *LI = R.getValueAsListInit("Flags");
 for (Init *I : *LI)
-  OS << (NumFlags++ ? " | " : "")
- << cast(I)->getDef()->getName();
+  OS << (NumFlags++ ? " | " : "") << cast(I)->getDef()->getName();
 if (GroupFlags) {
   for (Init *I : *GroupFlags)
 OS << (NumFlags++ ? " | " : "")
@@ -224,11 +236,50 @@
   write_cstring(OS, R.getValueAsString("Values"));
 else
   OS << "nullptr";
+  };
 
+  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
+const Record &R = *Opts[i];
+
+// Start a single option entry.
+OS << "OPTION(";
+WriteOptRecordFields(OS, R);
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
 
+  OS << "#ifdef OPTION_WITH_MARSHALLING\n";
+  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
+const Record &R = *Opts[I];
+
+if (!isa(R.getValueInit("MarshallingInfo"))) {
+  Record *MarshallingInfoRecord =
+  cast(R.getValueInit("MarshallingInfo"))->getDef();
+  StringRef KindStr = MarshallingInfoRecord->getValueAsString("Kind");
+  auto KindInfoPair =
+  StringSwitch>>(
+  KindStr)
+  .Case("flag", std::make_pair("OPTION_WITH_MARSHALLING_FLAG",
+   &emitMarshallingInfoFlag))
+  .Case("string", std::make_pair("OPTION_WITH_MARSHALLING_STRING",
+ &emitMarshallingInfoString))
+  .Case("enum", std::make_pair("OPTION_WITH_MARSHALLING_ENUM",
+   &emitMarshallingInfoEnum))
+  .Default(std::make_pair("", nullptr));
+  OS << KindInfoPair.first << "(";
+  WriteOptRecordFields(OS, R);
+  OS << ", ";
+  OS << MarshallingInfoRecord->getValueAsBit("ShouldAlwaysEmit");
+  OS << ", ";
+  OS << MarshallingInfoRecord->getValueAsString("KeyPath");
+  OS << ", ";
+  KindInfoPair.second(OS, MarshallingInfoRecord);
+  OS << ")\n";
+}
+  }
+  OS << "#endif // OPTION_WITH_MARSHALLING\n";
+
   OS << "\n";
   OS << "#ifdef OPTTABLE_ARG_INIT\n";
   OS << "//\n";
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -80,6 +80,19 @@
   list Flags = [];
 }
 
+// Add support for g

[PATCH] D80554: [DebugInfo] Use SplitTemplateClosers (foo >) in DWARF too

2020-05-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: dblaikie, labath.
Herald added subscribers: cfe-commits, aprantl.
Herald added a project: clang.

D76801  caused some regressions in debuginfo 
compatibility by changing how
certain functions were named.

For CodeView we try to mirror MSVC exactly: this was fixed in a549c0d00486 

For DWARF the situation is murkier. Per David Blaikie:

> In general DWARF doesn't specify this at all.
>  [...]
>  This isn't the only naming divergence between GCC and Clang

Nevertheless, including the space seems to provide better compatibility with
GCC and GDB. E.g. cpexprs.cc in the GDB testsuite requires this formatting.
And there was no particular desire to change the printing of names in debug
info in the first place (just in diagnostics and other more user-facing text).

Fixes PR46052


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80554

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
  clang/test/Modules/ExtDebugInfo.cpp
  clang/test/Modules/ModuleDebugInfo.cpp


Index: clang/test/Modules/ModuleDebugInfo.cpp
===
--- clang/test/Modules/ModuleDebugInfo.cpp
+++ clang/test/Modules/ModuleDebugInfo.cpp
@@ -65,7 +65,7 @@
 
 // This type is anchored by an explicit template instantiation.
 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
-// CHECK-SAME: name: "Template>"
+// CHECK-SAME: name: "Template >"
 // CHECK-SAME: elements:
 // CHECK-SAME: templateParams:
 // CHECK-SAME: identifier: 
"_ZTSN8DebugCXX8TemplateIiNS_6traitsIi")
@@ -80,7 +80,7 @@
 // CHECK-SAME: identifier: "_ZTSN8DebugCXX6traitsIfEE")
 
 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
-// CHECK-SAME: name: "Template>"
+// CHECK-SAME: name: "Template >"
 // CHECK-SAME: elements:
 // CHECK-SAME: templateParams:
 // CHECK-SAME: identifier: 
"_ZTSN8DebugCXX8TemplateIlNS_6traitsIl")
@@ -89,7 +89,7 @@
 // no mangled name here yet.
 
 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
-// CHECK-SAME: name: "Template>"
+// CHECK-SAME: name: "Template >"
 // CHECK-SAME: flags: DIFlagFwdDecl
 // CHECK-SAME: identifier: 
"_ZTSN8DebugCXX8TemplateIfNS_6traitsIf")
 
Index: clang/test/Modules/ExtDebugInfo.cpp
===
--- clang/test/Modules/ExtDebugInfo.cpp
+++ clang/test/Modules/ExtDebugInfo.cpp
@@ -85,14 +85,14 @@
 
 // This type is not anchored in the module by an explicit template 
instantiation.
 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
-// CHECK-SAME: name: "Template>",
+// CHECK-SAME: name: "Template >",
 // CHECK-SAME: scope: ![[NS]],
 // CHECK-SAME: elements:
 // CHECK-SAME: identifier: 
"_ZTSN8DebugCXX8TemplateIlNS_6traitsIl")
 
 // This type is anchored in the module by an explicit template instantiation.
 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
-// CHECK-SAME: name: "Template>",
+// CHECK-SAME: name: "Template >",
 // CHECK-SAME: scope: ![[NS]],
 // CHECK-SAME: flags: DIFlagFwdDecl
 // CHECK-SAME: identifier: 
"_ZTSN8DebugCXX8TemplateIiNS_6traitsIi")
@@ -103,7 +103,7 @@
 
 // This one isn't.
 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
-// CHECK-SAME: name: "Template>",
+// CHECK-SAME: name: "Template >",
 // CHECK-SAME: scope: ![[NS]],
 // CHECK-SAME: elements:
 // CHECK-SAME: templateParams:
Index: clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
+++ clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
@@ -110,7 +110,7 @@
 };
 j_wrap> j_wrap_j;
 // CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "j"
-// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "j_wrap>"
+// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "j_wrap >"
 
 template 
 struct k {
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -236,6 +236,10 @@
   if (CGM.getCodeGenOpts().EmitCodeView) {
 PP.MSVCFormatting = true;
 PP.SplitTemplateClosers = true;
+  } else {
+// For DWARF, printing rules are underspecified.
+// SplitTemplateClosers yields better interop with GCC and GDB (PR46052).
+PP.SplitTemplateClosers = true;
   }
 
   // Apply -fdebug-prefix-map.


Index: cl

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-05-26 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 5 inline comments as done.
dang added inline comments.



Comment at: clang/include/clang/Frontend/CompilerInvocation.h:156
   /// \param [out] Res - The resulting invocation.
+  /// \param [in] CommandLineArgs - Array of argument strings, this should not
+  /// contain "-cc1".

Bigcheese wrote:
> Is this really a should not, or is it must not?
You're right updated the wording to be more accurate



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3607
+VALUES, KEYPATH, IS_POSITIVE, DEFAULT_VALUE)   
\
+  if (Option::KIND##Class == Option::FlagClass)
\
+Res.KEYPATH = Args.hasArg(OPT_##ID) && IS_POSITIVE;

Bigcheese wrote:
> How would this handle other option classes? I think it would be good to 
> include a few different types of options in the first patch.
I updated the patch to handle options that take a value. This doesn't show how 
to handle everything yet (it is missing how to handle options that take 
multiple values notably) although there are not that many of them (a quick skim 
of the code seems to indicate there are less than 100)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796



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


[PATCH] D69764: [clang-format] Add East/West Const fixer capability

2020-05-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Format/EastWestConstFixer.cpp:139
+  return (Tok->isSimpleTypeSpecifier() ||
+  Tok->isOneOf(tok::kw_volatile, tok::kw_auto));
+}

Do you need to look for `restrict` here as well as `volatile`?



Comment at: clang/lib/Format/EastWestConstFixer.cpp:150
+  }
+  // don't concern youself if nothing follows const
+  if (!Tok->Next) {

Comments should start with a capital letter and end with punctuation per the 
coding standard (same applies to other comments in the patch).



Comment at: clang/lib/Format/EastWestConstFixer.cpp:157-158
+  IsCVQualifierOrType(Tok->Next->Next)) {
+// The unsigned/signed case  `const unsigned int` -> `unsigned int
+// const`
+swapFirstThreeTokens(SourceMgr, Fixes, Tok, Tok->Next, Tok->Next->Next,

What about something like `const unsigned long long` or the 
less-common-but-equally-valid `long const long unsigned`? Or multiple 
qualifiers like `unsigned volatile long const long * restrict`



Comment at: clang/lib/Format/Format.cpp:2547
 
+  if (Style.isCpp() || Style.Language == FormatStyle::LK_ObjC) {
+if (Style.ConstStyle != FormatStyle::CS_Leave)

MyDeveloperDay wrote:
> aaron.ballman wrote:
> > This prevents us from using this in C code despite C having qualifiers that 
> > can go to the left or right of the base type but still allows you to use if 
> > from Objective-C. That seems incorrect.
> clang-format's isCpp() covers C and C++ (and ObjectiveC and ObjectiveC++)
> 
> but you did highlight that I don't need the extra LK_ObjC check
> clang-format's isCpp() covers C and C++ (and ObjectiveC and ObjectiveC++)

Wow, that's a really poorly named function then! Thank you for the 
clarification.


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

https://reviews.llvm.org/D69764



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


[PATCH] D76801: [AST] Print a> without extra spaces in C++11 or later.

2020-05-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D76801#2052270 , @dyung wrote:

> Hi, we noticed an issue with the GDB test suite that was bisected back to 
> this change and I have put the details in PR46052. Can you take a look?


Sorry this never got clearly resolved.
I think the conclusion is while this is all best-effort, we might as well undo 
the debuginfo changes here. Sent D80554 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76801



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


[PATCH] D79711: [ARM] Add poly64_t on AArch32.

2020-05-26 Thread Alexandros Lamprineas via Phabricator via cfe-commits
labrinea added a comment.

> Should poly128_t be available on AArch32 too? I don't see anything in the 
> ACLE version you linked restricting it to AArch64 only, and the intrinsics 
> reference has a number of intrinsics available for both ISAs using it.

It should but it is not that simple. The reason it is not available is that 
__int128_t is not supported in AArch32. I think that is future work, since this 
patch unblocks the bfloat reinterpret_cast patch, which btw is annotated with 
TODO comments regarding the poly128_t type for AArch32.




Comment at: clang/lib/Sema/SemaType.cpp:7645
 
   // Signed poly is mathematically wrong, but has been baked into some ABIs by
   // now.

@ostannard according to this comment it seems there has been some divergence 
between AArch64 and AArch32 and now is too late to change. If the ACLE doesn't 
say so, maybe it should.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79711



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


[PATCH] D79961: [PGO] Fix computation of fuction Hash

2020-05-26 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.

lgtm


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

https://reviews.llvm.org/D79961



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


[PATCH] D79930: [clangd] Add buildPreamble to TestTU

2020-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 266202.
kadircet added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79930

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


Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -68,6 +68,7 @@
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   ParsedAST build() const;
+  std::shared_ptr preamble() const;
   ParseInputs inputs() const;
   SymbolSlab headerSymbols() const;
   RefSlab headerRefs() const;
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -66,14 +66,24 @@
   return Inputs;
 }
 
+std::shared_ptr TestTU::preamble() const {
+  auto Inputs = inputs();
+  IgnoreDiagnostics Diags;
+  auto CI = buildCompilerInvocation(Inputs, Diags);
+  assert(CI && "Failed to build compilation invocation.");
+  return clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
+  /*StoreInMemory=*/true,
+  /*PreambleCallback=*/nullptr);
+}
+
 ParsedAST TestTU::build() const {
   auto Inputs = inputs();
   StoreDiags Diags;
   auto CI = buildCompilerInvocation(Inputs, Diags);
   assert(CI && "Failed to build compilation invocation.");
-  auto Preamble =
-  buildPreamble(testPath(Filename), *CI, Inputs,
-/*StoreInMemory=*/true, /*PreambleCallback=*/nullptr);
+  auto Preamble = clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
+   /*StoreInMemory=*/true,
+   /*PreambleCallback=*/nullptr);
   auto AST = ParsedAST::build(testPath(Filename), Inputs, std::move(CI),
   Diags.take(), Preamble);
   if (!AST.hasValue()) {
Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -36,35 +36,19 @@
   return arg.first() == File && arg.second == D;
 }
 
-std::shared_ptr
-createPreamble(llvm::StringRef Contents = "") {
-  auto TU = TestTU::withCode(Contents);
-  // ms-compatibility changes meaning of #import, make sure it is turned off.
-  TU.ExtraArgs = {"-fno-ms-compatibility"};
-  TU.Filename = "preamble.cpp";
-  auto PI = TU.inputs();
-  IgnoreDiagnostics Diags;
-  auto CI = buildCompilerInvocation(PI, Diags);
-  if (!CI) {
-ADD_FAILURE() << "failed to build compiler invocation";
-return nullptr;
-  }
-  if (auto Preamble = buildPreamble(TU.Filename, *CI, PI, true, nullptr))
-return Preamble;
-  ADD_FAILURE() << "failed to build preamble";
-  return nullptr;
-}
-
 // Builds a preamble for BaselineContents, patches it for ModifiedContents and
 // returns the includes in the patch.
 IncludeStructure
 collectPatchedIncludes(llvm::StringRef ModifiedContents,
llvm::StringRef BaselineContents,
llvm::StringRef MainFileName = "main.cpp") {
-  auto BaselinePreamble = createPreamble(BaselineContents);
-  // Create the patch.
-  auto TU = TestTU::withCode(ModifiedContents);
+  auto TU = TestTU::withCode(BaselineContents);
   TU.Filename = MainFileName.str();
+  // ms-compatibility changes meaning of #import, make sure it is turned off.
+  TU.ExtraArgs = {"-fno-ms-compatibility"};
+  auto BaselinePreamble = TU.preamble();
+  // Create the patch.
+  TU = TestTU::withCode(ModifiedContents);
   auto PI = TU.inputs();
   auto PP = PreamblePatch::create(testPath(TU.Filename), PI, 
*BaselinePreamble);
   // Collect patch contents.


Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -68,6 +68,7 @@
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   ParsedAST build() const;
+  std::shared_ptr preamble() const;
   ParseInputs inputs() const;
   SymbolSlab headerSymbols() const;
   RefSlab headerRefs() const;
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -66,14 +66,24 @@

[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 266204.
MyDeveloperDay added a comment.

Handle more complex nested ObjC calls
Rename function to tryParseSimpleAttributes (not supporting full capability as 
yet)
Use RAII object to reset the TokenPosition
utilize the fact that Objective calls shouldn't end with "]]" I think... this 
should allow Attributes at least of the form `[[identifier::identifier]]`
I feel if this isn't a good enough perhaps we also check for the `;` after the 
second `]`


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

https://reviews.llvm.org/D80547

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestObjC.cpp

Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1434,6 +1434,23 @@
   "   }]");
 }
 
+TEST_F(FormatTestObjC, IfNotUnlikely) {
+  Style = getGoogleStyle(FormatStyle::LK_ObjC);
+
+  verifyFormat("if (argc < 5) [obj func:arg];");
+  verifyFormat("if (argc < 5) [[obj1 method1:arg1] method2:arg2];");
+
+  verifyFormat("if (argc < 5)\n"
+   "  [obj func:arg];\n"
+   "else\n"
+   "  [obj func:arg2];");
+
+  verifyFormat("if (argc < 5) [[unlikely]]\n"
+   "  [obj func:arg];\n"
+   "else [[likely]]\n"
+   "  [obj func:arg2];");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16513,6 +16513,11 @@
"  return 42;\n"
"}\n",
Style);
+
+  verifyFormat("if (argc > 5) [[gnu::unused]] {\n"
+   "  return 29;\n"
+   "}",
+   Style);
 }
 
 TEST_F(FormatTest, LLVMDefaultStyle) {
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -134,6 +134,7 @@
   bool tryToParseLambdaIntroducer();
   bool tryToParsePropertyAccessor();
   void tryToParseJSFunction();
+  bool tryToParseSimpleAttribute();
   void addUnwrappedLine();
   bool eof() const;
   // LevelDifference is the difference of levels after and before the current
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1962,7 +1962,7 @@
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   // handle [[likely]] / [[unlikely]]
-  if (FormatTok->is(tok::l_square))
+  if (FormatTok->is(tok::l_square) && tryToParseSimpleAttribute())
 parseSquare();
   bool NeedsUnwrappedLine = false;
   if (FormatTok->Tok.is(tok::l_brace)) {
@@ -1981,7 +1981,7 @@
   if (FormatTok->Tok.is(tok::kw_else)) {
 nextToken();
 // handle [[likely]] / [[unlikely]]
-if (FormatTok->is(tok::l_square))
+if (FormatTok->Tok.is(tok::l_square) && tryToParseSimpleAttribute())
   parseSquare();
 if (FormatTok->Tok.is(tok::l_brace)) {
   CompoundStatementIndenter Indenter(this, Style, Line->Level);
@@ -2343,6 +2343,47 @@
   // "} n, m;" will end up in one unwrapped line.
 }
 
+namespace {
+// A class used to set and restore the Token position when peeking
+// ahead in the token source.
+class AutoTokenPosition {
+  unsigned StoredPosition;
+  FormatTokenSource *Tokens;
+
+public:
+  AutoTokenPosition(FormatTokenSource *Tokens) : Tokens(Tokens) {
+assert(Tokens && "Tokens expected to not be null");
+StoredPosition = Tokens->getPosition();
+  }
+
+  ~AutoTokenPosition() { Tokens->setPosition(StoredPosition); }
+};
+} // namespace
+
+// Look to see if we have [[ by looking ahead, if
+// its not then rewind to the original position.
+bool UnwrappedLineParser::tryToParseSimpleAttribute() {
+  AutoTokenPosition AutoPosition(Tokens);
+  FormatToken *Tok = Tokens->getNextToken();
+  // We already read the first [ check for the second
+  if (Tok && !Tok->is(tok::l_square)) {
+return false;
+  }
+  // Double check  that the attribute is just something
+  // fairly simple.
+  while (Tok) {
+if (Tok->is(tok::r_square)) {
+  break;
+}
+Tok = Tokens->getNextToken();
+  }
+  Tok = Tokens->getNextToken();
+  if (Tok && !Tok->is(tok::r_square)) {
+return false;
+  }
+  return true;
+}
+
 void UnwrappedLineParser::parseJavaEnumBody() {
   // Determine whether the enum is simple, i.e. does not have a semicolon or
   // constants with class bodies. Simple enums can be formatted like braced
___
cfe-commits mailing li

[PATCH] D80293: [clangd] Run PreambleThread in async mode behind a flag

2020-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 266201.
kadircet edited the summary of this revision.
kadircet added a comment.

- Rebase and update comments on block until idle.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80293

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -21,6 +21,7 @@
 #include "support/Threading.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "gmock/gmock.h"
@@ -29,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -90,6 +92,24 @@
   static Key)>>
   DiagsCallbackKey;
 
+  using PreambleCallback = llvm::unique_function;
+  static std::unique_ptr
+  capturePreamble(PreambleCallback CB) {
+class CapturePreamble : public ParsingCallbacks {
+public:
+  CapturePreamble(PreambleCallback CB) : CB(std::move(CB)) {}
+  void onPreambleAST(PathRef Path, llvm::StringRef Version, ASTContext &Ctx,
+ std::shared_ptr PP,
+ const CanonicalIncludes &) override {
+CB();
+  }
+
+private:
+  PreambleCallback CB;
+};
+return std::make_unique(std::move(CB));
+  }
+
   /// A diagnostics callback that should be passed to TUScheduler when it's used
   /// in updateWithDiags.
   static std::unique_ptr captureDiags() {
@@ -443,7 +463,7 @@
   WithContextValue WithNonce(NonceKey, ++Nonce);
   Inputs.Version = std::to_string(Nonce);
   updateWithDiags(
-  S, File, Inputs, WantDiagnostics::Auto,
+  S, File, Inputs, WantDiagnostics::Yes,
   [File, Nonce, &Mut, &TotalUpdates](std::vector) {
 EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce));
 
@@ -972,6 +992,40 @@
   EXPECT_NEAR(25, Compute({}), 0.01) << "no history -> max";
 }
 
+TEST_F(TUSchedulerTests, AsyncPreambleThread) {
+  Notification Ready;
+  std::atomic PreambleBuildCount{0};
+  TUScheduler S(CDB, optsForTest(), capturePreamble([&] {
+  if (PreambleBuildCount > 0)
+Ready.wait();
+  ++PreambleBuildCount;
+}));
+
+  Path File = testPath("foo.cpp");
+  auto PI = getInputs(File, "");
+  PI.Version = "initial";
+  S.update(File, PI, WantDiagnostics::Auto);
+  S.blockUntilIdle(timeoutSeconds(10));
+
+  // Block preamble builds.
+  PI.Version = "blocking";
+  // Issue second update which will block preamble thread.
+  S.update(File, PI, WantDiagnostics::Auto);
+
+  Notification RunASTAction;
+  // Issue an AST read, which shouldn't be blocked and see latest version of the
+  // file.
+  S.runWithAST("test", File, [&](Expected AST) {
+ASSERT_TRUE(bool(AST));
+EXPECT_THAT(AST->Inputs.Version, PI.Version);
+RunASTAction.notify();
+  });
+  RunASTAction.wait();
+  // Make sure second preamble hasn't been built yet.
+  EXPECT_THAT(PreambleBuildCount.load(), 1U);
+  Ready.notify();
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -211,18 +211,18 @@
   FS.Files[FooCpp] = SourceContents;
 
   Server.addDocument(FooCpp, SourceContents);
-  auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
   ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for diagnostics";
+  auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   Server.addDocument(FooCpp, "");
-  auto DumpParseEmpty = dumpASTWithoutMemoryLocs(Server, FooCpp);
   ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for diagnostics";
+  auto DumpParseEmpty = dumpASTWithoutMemoryLocs(Server, FooCpp);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   Server.addDocument(FooCpp, SourceContents);
-  auto DumpParse2 = dumpASTWithoutMemoryLocs(Server, FooCpp);
   ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for diagnostics";
+  auto DumpParse2 = dumpASTWithoutMemoryLocs(Server, FooCpp);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   EXPECT_EQ(DumpParse1, DumpParse2);
@@ -247,20 +247,20 @@
   FS.Files[FooCpp] = Sourc

[PATCH] D76791: [Matrix] Implement matrix index expressions ([][]).

2020-05-26 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added inline comments.



Comment at: clang/include/clang/AST/Expr.h:2648
+/// MatrixSubscriptExpr - Matrix subscript expression for the MatrixType
+/// extension.
+class MatrixSubscriptExpr : public Expr {

rjmccall wrote:
> Oh, that's interesting.  So you've changed this to flatten the component 
> expressions?  I think that might be inconsistent with our usual 
> source-preservation goals unless you intend to restrict the intermediate base 
> expression to be an immediate subscript.  That is, this is okay if you're 
> going to require the user to write `matrix[i][j]` and forbid 
> `(matrix[i])[j]`, but if you intend to allow the latter, you should preserve 
> that structure here.  You can do that while still providing this API; you 
> just have to implement `getBase()` etc. by looking through parens, and you 
> should have an accessor which returns the syntactic base expression.
> 
> What expression node do you use for the intermediate subscript expression?  
> You should talk about this in the doc comment.
> Oh, that's interesting. So you've changed this to flatten the component 
> expressions? I think that might be inconsistent with our usual 
> source-preservation goals unless you intend to restrict the intermediate base 
> expression to be an immediate subscript. That is, this is okay if you're 
> going to require the user to write matrix[i][j] and forbid (matrix[i])[j], 
> but if you intend to allow the latter, you should preserve that structure 
> here. You can do that while still providing this API; you just have to 
> implement getBase() etc. by looking through parens, and you should have an 
> accessor which returns the syntactic base expression.

My intuition was that the matrix subscript operator would be a single operator 
with 3 arguments. Allowing things like (matrix[I])[j] has potential for 
confusion I think, as there is no way to create an expression just referencing 
a row/column on its own. (responded in more details at the SemaExpr.cpp 
comment).

> What expression node do you use for the intermediate subscript expression? 
> You should talk about this in the doc comment.

Intermediate subscript expressions are represented as 'incomplete' 
MatrixSubscriptExpr (type is MatrixIncompleteIdx, ColumnIdx is nullptr). I've 
updated the comment.



Comment at: clang/include/clang/Basic/Specifiers.h:159
+
+/// A single matrix element of a matrix.
+OK_MatrixElement

rjmccall wrote:
> redundancy
I suppose no comment is sufficient?



Comment at: clang/include/clang/Sema/Sema.h:4907
+  ExprResult ActOnMatrixSubscriptExpr(Scope *S, Expr *Base, Expr *RowIdx,
+  Expr *ColumnIdx, SourceLocation RBLoc);
+

rjmccall wrote:
> It'd be more conventional to call it `BuildMatrixSubscriptExpr`.  You can do 
> all the semantic checks here and make `ActOnArraySubscriptExpr` handle the 
> syntactic checks.  This is all assuming that you intend to impose the 
> syntactic restriction discussed above.
Thanks, I wasn't sure about the actual distinction. I've renamed it to 
BuildMatrixSubscriptExpr now.



Comment at: clang/lib/AST/ItaniumMangle.cpp:4238
+  case Expr::MatrixSubscriptExprClass:
+llvm_unreachable("matrix subscript expressions not supported yet");
+

rjmccall wrote:
> This is simple, you should just mangle them syntactically.  `'ixix'  expression>  `.  Test case is
> 
> ```
> using double4x4 = double __attribute__((matrix_type(4,4)));
> 
> template 
> auto matrix_subscript(double4x4 m, R r, C c) -> decltype(m[r][c]) {}
> 
> double test_matrix_subscript(double 4x4 m) { return m[3][2]; }
> ```
Thanks, I've updated the code as suggested and added the test.  I had to adjust 
the test slightly (adding a call to matrix_subscript).

This test is quite interesting, because it accidentally another issue. Matrix 
element subscripts are treated as Lvalues currently, but the code currently 
does not support taking the address of matrix elements. `decltype(m[r][c])` 
will be `& double` and if you add `return m[r][c];` the issue is exposed.

I am not sure how to best address this, short of computing the address of the 
element in memory directly. Do you have any suggestions?

I think for some vector types, we currently mis-compile here as well. For 
example,

```
using double4 = double __attribute__((ext_vector_type(4)));

template 
auto matrix_subscript(const double4 m, R r) -> decltype(m[r]) { return m[r]; }
```

produces the IR below. Note the `  ret double* %ref.tmp`, where `%ref.tmp` is 
an alloca.

```
define linkonce_odr nonnull align 8 dereferenceable(8) double* 
@_Z16matrix_subscriptIiEDTixfpK_fp0_EDv4_dT_(<4 x double>* byval(<4 x double>) 
align 16 %0, i32 %r) #0 {
entry:
  %m.addr = alloca <4 x double>, align 16
  %r.addr = alloca i32, align 4
  %ref.tmp = alloca double, align 8
  %m = load <4 x double>, <4 x double>* %0, ali

[PATCH] D76791: [Matrix] Implement matrix index expressions ([][]).

2020-05-26 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 266205.
fhahn marked 7 inline comments as done.
fhahn added a comment.

Address John's latest comments, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76791

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/BuiltinTypes.def
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGValue.h
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CodeGen/matrix-type-operators.c
  clang/test/CodeGenCXX/matrix-type-operators.cpp
  clang/test/Sema/matrix-type-operators.c
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/tools/libclang/CXCursor.cpp
  llvm/include/llvm/IR/MatrixBuilder.h

Index: llvm/include/llvm/IR/MatrixBuilder.h
===
--- llvm/include/llvm/IR/MatrixBuilder.h
+++ llvm/include/llvm/IR/MatrixBuilder.h
@@ -155,15 +155,19 @@
 return B.CreateMul(LHS, ScalarVector);
   }
 
-  /// Extracts the element at (\p Row, \p Column) from \p Matrix.
-  Value *CreateExtractMatrix(Value *Matrix, Value *Row, Value *Column,
- unsigned NumRows, Twine const &Name = "") {
-
+  /// Extracts the element at (\p RowIdx, \p ColumnIdx) from \p Matrix.
+  Value *CreateExtractElement(Value *Matrix, Value *RowIdx, Value *ColumnIdx,
+  unsigned NumRows, Twine const &Name = "") {
+
+unsigned MaxWidth = std::max(RowIdx->getType()->getScalarSizeInBits(),
+ ColumnIdx->getType()->getScalarSizeInBits());
+Type *IntTy = IntegerType::get(RowIdx->getType()->getContext(), MaxWidth);
+RowIdx = B.CreateZExt(RowIdx, IntTy);
+ColumnIdx = B.CreateZExt(ColumnIdx, IntTy);
+Value *NumRowsV = B.getIntN(MaxWidth, NumRows);
 return B.CreateExtractElement(
-Matrix,
-B.CreateAdd(
-B.CreateMul(Column, ConstantInt::get(Column->getType(), NumRows)),
-Row));
+Matrix, B.CreateAdd(B.CreateMul(ColumnIdx, NumRowsV), RowIdx),
+"matext");
   }
 };
 
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -419,6 +419,11 @@
 K = CXCursor_ArraySubscriptExpr;
 break;
 
+  case Stmt::MatrixSubscriptExprClass:
+// TODO: add support for MatrixSubscriptExpr.
+K = CXCursor_UnexposedExpr;
+break;
+
   case Stmt::OMPArraySectionExprClass:
 K = CXCursor_OMPArraySectionExpr;
 break;
Index: clang/test/SemaCXX/matrix-type-operators.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-type-operators.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 %s -fenable-matrix -pedantic -std=c++11 -verify -triple=x86_64-apple-darwin9
+
+typedef float sx5x10_t __attribute__((matrix_type(5, 10)));
+
+sx5x10_t get_matrix();
+
+void insert(sx5x10_t a, float f) {
+  // Non integer indexes.
+  a[3][f] = 0;
+  // expected-error@-1 {{matrix column index is not an integer}}
+  a[f][9] = 0;
+  // expected-error@-1 {{matrix row index is not an integer}}
+  a[f][f] = 0;
+  // expected-error@-1 {{matrix row index is not an integer}}
+  a[0][f] = 0;
+  // expected-error@-1 {{matrix column index is not an integer}}
+
+  // Invalid element type.
+  a[3][4] = &f;
+  // expected-error@-1 {{assigning to 'float' from incompatible type 'float *'; remove &}}
+
+  // Indexes outside allowed dimensions.
+  a[-1][3] = 10.0;
+  // expected-error@-1 {{matrix row index is outside the allowed range [0, 5)}}
+  a[3][-1] = 10.0;
+  // expected-error@-1 {{matrix column index is outside the allowed range [0, 10)}}
+  a[3][-1u] = 10.0;
+  // expected-error@-1 {{matrix column index is ou

[PATCH] D80023: [clang-tidy] Add abseil-string-find-str-contains checker.

2020-05-26 Thread Tom Lokovic via Phabricator via cfe-commits
tdl-g updated this revision to Diff 266207.
tdl-g added a comment.

Fixed length of visual separator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80023

Files:
  clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
  clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/abseil-string-find-str-contains.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
@@ -0,0 +1,290 @@
+// RUN: %check_clang_tidy %s abseil-string-find-str-contains %t -- \
+// RUN:   -config="{CheckOptions: []}"
+
+using size_t = decltype(sizeof(int));
+
+namespace std {
+
+// Lightweight standin for std::string.
+template 
+class basic_string {
+public:
+  basic_string();
+  basic_string(const basic_string &);
+  basic_string(const C *);
+  ~basic_string();
+  int find(basic_string s, int pos = 0);
+  int find(const C *s, int pos = 0);
+  int find(char c, int pos = 0);
+  static constexpr size_t npos = -1;
+};
+typedef basic_string string;
+
+// Lightweight standin for std::string_view.
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const basic_string_view &);
+  basic_string_view(const C *);
+  ~basic_string_view();
+  int find(basic_string_view s, int pos = 0);
+  int find(const C *s, int pos = 0);
+  int find(char c, int pos = 0);
+  static constexpr size_t npos = -1;
+};
+typedef basic_string_view string_view;
+
+} // namespace std
+
+namespace absl {
+
+// Lightweight standin for absl::string_view.
+class string_view {
+public:
+  string_view();
+  string_view(const string_view &);
+  string_view(const char *);
+  ~string_view();
+  int find(string_view s, int pos = 0);
+  int find(const char *s, int pos = 0);
+  int find(char c, int pos = 0);
+  static constexpr size_t npos = -1;
+};
+
+} // namespace absl
+
+// Functions that take and return our various string-like types.
+std::string foo_ss(std::string);
+std::string_view foo_ssv(std::string_view);
+absl::string_view foo_asv(absl::string_view);
+std::string bar_ss();
+std::string_view bar_ssv();
+absl::string_view bar_asv();
+
+// Confirms that find==npos and find!=npos work for each supported type, when
+// npos comes from the correct type.
+void basic_tests() {
+  std::string ss;
+  ss.find("a") == std::string::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of find() == npos
+  // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ss, "a");{{$}}
+
+  ss.find("a") != std::string::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of find() != npos
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ss, "a");{{$}}
+
+  std::string::npos != ss.find("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ss, "a");{{$}}
+
+  std::string_view ssv;
+  ssv.find("a") == std::string_view::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ssv, "a");{{$}}
+
+  ssv.find("a") != std::string_view::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ssv, "a");{{$}}
+
+  std::string_view::npos != ssv.find("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ssv, "a");{{$}}
+
+  absl::string_view asv;
+  asv.find("a") == absl::string_view::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(asv, "a");{{$}}
+
+  asv.find("a") != absl::string_view::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(asv, "a");{{$}}
+
+  absl::string_view::npos != asv.find("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(asv, "a");{{$}}
+}
+
+// Confirms that it works even if you mix-and-match the type for find and for
+// npos.  (One of the reasons for this checker is to clean up cases that
+// accidentally mix-and-match like this.  absl::StrContains is less
+// error-prone.)
+void mismatched_npos() {
+  std::string ss;
+  ss.find("a") == std::string_view::npos

[PATCH] D80023: [clang-tidy] Add abseil-string-find-str-contains checker.

2020-05-26 Thread Tom Lokovic via Phabricator via cfe-commits
tdl-g marked 4 inline comments as done.
tdl-g added a comment.

Thanks again, addressed all comments.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp:2
+// RUN: %check_clang_tidy %s abseil-string-find-str-contains %t -- \
+// RUN:   -config="{CheckOptions: []}"
+

tdl-g wrote:
> ymandel wrote:
> > I'm not sure what's standard practice, but consider whether its worth 
> > adding another test file that tests the check options. It wouldn't have to 
> > be comprehensive like this one, just some basic tests that the options are 
> > being honored.
> I'm open to it, but note that two of the three options (IncludeStyle, 
> inherited from TransformerClangTidy) and AbseilStringsMatchHeader, only 
> manifest in the header-inclusion.
> 
> So if I had a separate test it would be easy to confirm that 
> StringLikeClasses was being honored.  But I'm not sure how I'd confirm that 
> IncludeStyle or AbseilStringsMatchHeader are being honored.  Suggestions?
Discussed with ymandel offline, we'll add more option-specific tests when we 
clean up transformer's options handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80023



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


[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D80547#2054763 , @MyDeveloperDay 
wrote:

> Handle more complex nested ObjC calls
>  Rename function to tryParseSimpleAttributes (not supporting full capability 
> as yet)
>  Use RAII object to reset the TokenPosition
>  utilize the fact that Objective calls shouldn't end with "]]" I think... 
> this should allow Attributes at least of the form `[[identifier::identifier]]`
>  I feel if this isn't a good enough perhaps we also check for the `;` after 
> the second `]`


I'm not an ObjC expert, but I am pretty sure you can do something like: `[[foo 
bar] baz: i[0]];` and `[[foo bar] baz: i[0]][1];`


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

https://reviews.llvm.org/D80547



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


[PATCH] D79945: [Sema] Comparison of pointers to complete and incomplete types

2020-05-26 Thread Benson Chu via Phabricator via cfe-commits
pestctrl updated this revision to Diff 266214.
pestctrl added a comment.

Forgot to add a comma >_<


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79945

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/c89.c


Index: clang/test/Sema/c89.c
===
--- clang/test/Sema/c89.c
+++ clang/test/Sema/c89.c
@@ -127,3 +127,11 @@
   struct Test17 t1 = test17_aux(); /* this is allowed */
 }
 
+int incomplete[]; /* expected-warning {{tentative array definition assumed to 
have one element}} */
+int complete[5];
+
+void test18() {
+  if (&incomplete < &complete) { /* expected-warning {{ordered comparison of 
complete and incomplete pointers}} */
+return;
+  }
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -11422,11 +11422,23 @@
 // C99 6.5.9p2 and C99 6.5.8p2
 if (Context.typesAreCompatible(LCanPointeeTy.getUnqualifiedType(),
RCanPointeeTy.getUnqualifiedType())) {
-  // Valid unless a relational comparison of function pointers
-  if (IsRelational && LCanPointeeTy->isFunctionType()) {
-Diag(Loc, diag::ext_typecheck_ordered_comparison_of_function_pointers)
-  << LHSType << RHSType << LHS.get()->getSourceRange()
-  << RHS.get()->getSourceRange();
+  if (IsRelational) {
+// Pointers both need to point to complete or incomplete types
+if (LCanPointeeTy->isIncompleteType() !=
+RCanPointeeTy->isIncompleteType()) {
+  Diag(Loc,
+   getLangOpts().C11
+   ? diag::ext_typecheck_compare_complete_incomplete_pointers
+   : diag::warn_typecheck_compare_complete_incomplete_pointers)
+  << LHSType << RHSType << LHS.get()->getSourceRange()
+  << RHS.get()->getSourceRange();
+}
+if (LCanPointeeTy->isFunctionType()) {
+  // Valid unless a relational comparison of function pointers
+  Diag(Loc, 
diag::ext_typecheck_ordered_comparison_of_function_pointers)
+  << LHSType << RHSType << LHS.get()->getSourceRange()
+  << RHS.get()->getSourceRange();
+}
   }
 } else if (!IsRelational &&
(LCanPointeeTy->isVoidType() || RCanPointeeTy->isVoidType())) {
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6441,6 +6441,12 @@
   "ordered comparison between pointer and zero (%0 and %1)">;
 def err_typecheck_three_way_comparison_of_pointer_and_zero : Error<
   "three-way comparison between pointer and zero">;
+def ext_typecheck_compare_complete_incomplete_pointers : Extension<
+  "ordered comparison of complete and incomplete pointers (%0 and %1)">,
+  InGroup;
+def warn_typecheck_compare_complete_incomplete_pointers : ExtWarn<
+  "ordered comparison of complete and incomplete pointers (%0 and %1)">,
+  InGroup;
 def ext_typecheck_ordered_comparison_of_function_pointers : ExtWarn<
   "ordered comparison of function pointers (%0 and %1)">,
   InGroup>;


Index: clang/test/Sema/c89.c
===
--- clang/test/Sema/c89.c
+++ clang/test/Sema/c89.c
@@ -127,3 +127,11 @@
   struct Test17 t1 = test17_aux(); /* this is allowed */
 }
 
+int incomplete[]; /* expected-warning {{tentative array definition assumed to have one element}} */
+int complete[5];
+
+void test18() {
+  if (&incomplete < &complete) { /* expected-warning {{ordered comparison of complete and incomplete pointers}} */
+return;
+  }
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -11422,11 +11422,23 @@
 // C99 6.5.9p2 and C99 6.5.8p2
 if (Context.typesAreCompatible(LCanPointeeTy.getUnqualifiedType(),
RCanPointeeTy.getUnqualifiedType())) {
-  // Valid unless a relational comparison of function pointers
-  if (IsRelational && LCanPointeeTy->isFunctionType()) {
-Diag(Loc, diag::ext_typecheck_ordered_comparison_of_function_pointers)
-  << LHSType << RHSType << LHS.get()->getSourceRange()
-  << RHS.get()->getSourceRange();
+  if (IsRelational) {
+// Pointers both need to point to complete or incomplete types
+if (LCanPointeeTy->isIncompleteType() !=
+RCanPointeeTy->isIncompleteType()) {
+  Diag(Loc,
+   getLangOpts().C11
+   ? diag::ext_typecheck_compare_complete_incomplete_pointers
+   : diag

[PATCH] D80300: [Driver] Add DEFAULT_DYLD_PREFIX and DEFAULT_RPATH to complement DEFAULT_SYSROOT

2020-05-26 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

@joerg, are you okay with this patch landing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80300



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


[PATCH] D80018: [Analyzer][StreamChecker] Added check for "indeterminate file position".

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



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:857-868
+// FEof and other states are possible.
+// The path with FEof is the one that can continue.
+// For this reason a non-fatal error is generated to continue the analysis
+// with only FEof state set.
+ExplodedNode *N = C.generateNonFatalErrorNode(State);
+if (N) {
+  C.emitReport(std::make_unique(

Szelethus wrote:
> Szelethus wrote:
> > Ugh, tough one. I think this just isn't really *the* error to highlight 
> > here, but rather that its bad practice to not check on the stream after an 
> > operation. But I'm willing to accept I might be wrong here.
> Actually, I take this back. If we had `NoteTag`s to explain that "this stream 
> operation failed and left the stream file position indication in an 
> indeterminate state", this would be great.
Adding of `NoteTag` and other bug path improvements are planned in the next 
changes. (The message text could mention that error check was probably 
forgotten. But the faulty function can be called despite the error check was 
done.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80018



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


[PATCH] D77644: [clangd] Handle additional includes while parsing ASTs

2020-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 266215.
kadircet added a comment.

- Fix windows build bots in the face of `#import` directives


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77644

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  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
@@ -8,6 +8,7 @@
 
 #include "Annotations.h"
 #include "Compiler.h"
+#include "Headers.h"
 #include "Preamble.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -21,6 +22,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -30,51 +32,58 @@
 namespace clangd {
 namespace {
 
+MATCHER_P2(Distance, File, D, "") {
+  return arg.first() == File && arg.second == D;
+}
+
+std::shared_ptr
+createPreamble(llvm::StringRef Contents = "") {
+  auto TU = TestTU::withCode(Contents);
+  // ms-compatibility changes meaning of #import, make sure it is turned off.
+  TU.ExtraArgs = {"-fno-ms-compatibility"};
+  TU.Filename = "preamble.cpp";
+  auto PI = TU.inputs();
+  IgnoreDiagnostics Diags;
+  auto CI = buildCompilerInvocation(PI, Diags);
+  if (!CI) {
+ADD_FAILURE() << "failed to build compiler invocation";
+return nullptr;
+  }
+  if (auto Preamble = buildPreamble(TU.Filename, *CI, PI, true, nullptr))
+return Preamble;
+  ADD_FAILURE() << "failed to build preamble";
+  return nullptr;
+}
+
 // Builds a preamble for BaselineContents, patches it for ModifiedContents and
 // returns the includes in the patch.
 IncludeStructure
 collectPatchedIncludes(llvm::StringRef ModifiedContents,
llvm::StringRef BaselineContents,
llvm::StringRef MainFileName = "main.cpp") {
-  std::string MainFile = testPath(MainFileName);
-  ParseInputs PI;
-  PI.FS = new llvm::vfs::InMemoryFileSystem;
-  MockCompilationDatabase CDB;
+  auto BaselinePreamble = createPreamble(BaselineContents);
+  // Create the patch.
+  auto TU = TestTU::withCode(ModifiedContents);
+  TU.Filename = MainFileName.str();
   // ms-compatibility changes meaning of #import, make sure it is turned off.
-  CDB.ExtraClangFlags.push_back("-fno-ms-compatibility");
-  PI.CompileCommand = CDB.getCompileCommand(MainFile).getValue();
-  // Create invocation
+  TU.ExtraArgs = {"-fno-ms-compatibility"};
+  auto PI = TU.inputs();
+  auto PP = PreamblePatch::create(testPath(TU.Filename), PI, *BaselinePreamble);
+  // Collect patch contents.
   IgnoreDiagnostics Diags;
   auto CI = buildCompilerInvocation(PI, Diags);
-  assert(CI && "failed to create compiler invocation");
-  // Build baseline preamble.
-  PI.Contents = BaselineContents.str();
-  PI.Version = "baseline preamble";
-  auto BaselinePreamble = buildPreamble(MainFile, *CI, PI, true, nullptr);
-  assert(BaselinePreamble && "failed to build baseline preamble");
-  // Create the patch.
-  PI.Contents = ModifiedContents.str();
-  PI.Version = "modified contents";
-  auto PP = PreamblePatch::create(MainFile, PI, *BaselinePreamble);
-  // Collect patch contents.
   PP.apply(*CI);
-  llvm::StringRef PatchContents;
-  for (const auto &Rempaped : CI->getPreprocessorOpts().RemappedFileBuffers) {
-if (Rempaped.first == testPath("__preamble_patch__.h")) {
-  PatchContents = Rempaped.second->getBuffer();
-  break;
-}
-  }
-  // Run preprocessor over the modified contents with patched Invocation to and
-  // BaselinePreamble to collect includes in the patch. We trim the input to
-  // only preamble section to not collect includes in the mainfile.
+  // Run preprocessor over the modified contents with patched Invocation. We
+  // provide a preamble and trim contents to ensure only the implicit header
+  // introduced by the patch is parsed and nothing else.
+  // We don't run PP directly over the patch cotents to test production
+  // behaviour.
   auto Bounds = Lexer::ComputePreamble(ModifiedContents, *CI->getLangOpts());
   auto Clang =
   prepareCompilerInstance(std::move(CI), &BaselinePreamble->Preamble,
   llvm::MemoryBuffer::getMemBufferCopy(
   ModifiedContents.slice(0, Bounds.Size).str()),
   PI.FS, Diags);
-  Clang->getPreprocessorOpts().ImplicitPCHInclude.clear();
   PreprocessOnlyAction Action;
   if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) {
 ADD_FAILURE() << "failed begin source file";
@@ -163,6 +172,33 @@
   EXPECT_THAT(Includes, ElementsA

[PATCH] D80548: [Analyzer][NFC] Remove the SubEngine interface

2020-05-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

I absolutely buy this. If somebody is to ever implement another `ExprEngine`, 
dealing with the lack of a convenient virtual interface will definitely be a 
negligible problem for them.




Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h:650
+
+protected:
+  /// evalBind - Handle the semantics of binding a value to a specific 
location.

What's the point of `protected` if we don't expect anybody to ever inherit from 
us?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80548



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


[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 266231.
MyDeveloperDay added a comment.

Add more tests and check if a ';' follows the final ]]


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

https://reviews.llvm.org/D80547

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestObjC.cpp

Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1434,6 +1434,25 @@
   "   }]");
 }
 
+TEST_F(FormatTestObjC, IfNotUnlikely) {
+  Style = getGoogleStyle(FormatStyle::LK_ObjC);
+
+  verifyFormat("if (argc < 5) [obj func:arg];");
+  verifyFormat("if (argc < 5) [[obj1 method1:arg1] method2:arg2];");
+  verifyFormat("if (argc < 5) [[foo bar] baz:i[0]];");
+  verifyFormat("if (argc < 5) [[foo bar] baz:i[0]][1];");
+
+  verifyFormat("if (argc < 5)\n"
+   "  [obj func:arg];\n"
+   "else\n"
+   "  [obj func:arg2];");
+
+  verifyFormat("if (argc < 5) [[unlikely]]\n"
+   "  [obj func:arg];\n"
+   "else [[likely]]\n"
+   "  [obj func:arg2];");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16513,6 +16513,11 @@
"  return 42;\n"
"}\n",
Style);
+
+  verifyFormat("if (argc > 5) [[gnu::unused]] {\n"
+   "  return 29;\n"
+   "}",
+   Style);
 }
 
 TEST_F(FormatTest, LLVMDefaultStyle) {
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -134,6 +134,7 @@
   bool tryToParseLambdaIntroducer();
   bool tryToParsePropertyAccessor();
   void tryToParseJSFunction();
+  bool tryToParseSimpleAttribute();
   void addUnwrappedLine();
   bool eof() const;
   // LevelDifference is the difference of levels after and before the current
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1962,7 +1962,7 @@
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   // handle [[likely]] / [[unlikely]]
-  if (FormatTok->is(tok::l_square))
+  if (FormatTok->is(tok::l_square) && tryToParseSimpleAttribute())
 parseSquare();
   bool NeedsUnwrappedLine = false;
   if (FormatTok->Tok.is(tok::l_brace)) {
@@ -1981,7 +1981,7 @@
   if (FormatTok->Tok.is(tok::kw_else)) {
 nextToken();
 // handle [[likely]] / [[unlikely]]
-if (FormatTok->is(tok::l_square))
+if (FormatTok->Tok.is(tok::l_square) && tryToParseSimpleAttribute())
   parseSquare();
 if (FormatTok->Tok.is(tok::l_brace)) {
   CompoundStatementIndenter Indenter(this, Style, Line->Level);
@@ -2343,6 +2343,51 @@
   // "} n, m;" will end up in one unwrapped line.
 }
 
+namespace {
+// A class used to set and restore the Token position when peeking
+// ahead in the token source.
+class AutoTokenPosition {
+  unsigned StoredPosition;
+  FormatTokenSource *Tokens;
+
+public:
+  AutoTokenPosition(FormatTokenSource *Tokens) : Tokens(Tokens) {
+assert(Tokens && "Tokens expected to not be null");
+StoredPosition = Tokens->getPosition();
+  }
+
+  ~AutoTokenPosition() { Tokens->setPosition(StoredPosition); }
+};
+} // namespace
+
+// Look to see if we have [[ by looking ahead, if
+// its not then rewind to the original position.
+bool UnwrappedLineParser::tryToParseSimpleAttribute() {
+  AutoTokenPosition AutoPosition(Tokens);
+  FormatToken *Tok = Tokens->getNextToken();
+  // We already read the first [ check for the second
+  if (Tok && !Tok->is(tok::l_square)) {
+return false;
+  }
+  // Double check  that the attribute is just something
+  // fairly simple.
+  while (Tok) {
+if (Tok->is(tok::r_square)) {
+  break;
+}
+Tok = Tokens->getNextToken();
+  }
+  Tok = Tokens->getNextToken();
+  if (Tok && !Tok->is(tok::r_square)) {
+return false;
+  }
+  Tok = Tokens->getNextToken();
+  if (Tok && Tok->is(tok::semi)) {
+return false;
+  }
+  return true;
+}
+
 void UnwrappedLineParser::parseJavaEnumBody() {
   // Determine whether the enum is simple, i.e. does not have a semicolon or
   // constants with class bodies. Simple enums can be formatted like braced
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69778: Make -fmodules-codegen and -fmodules-debuginfo work also with precompiled headers

2020-05-26 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

In D69778#2035805 , @llunak wrote:

> @aganea Have you tried how this version of the patch affects PR44953? If not, 
> could you please try?


I've applied the patch, I don't see the issue raised in PR44953 anymore.

However as discussed offline with @llunak I'm just raising a concern: when 
building with this patch + D69585  
(`-fpch-instantiate-templates`) + `-fmodules-debuginfo -fmodules-codegen` as 
instructed, the PCH compilation in one of games crashes with the callstack 
below. On another game, the compilation succeeds, but I can see link errors for 
a few symbols referenced from the .PCH.OBJ.

This patch may be fine on its own, because `-fmodules-debuginfo 
-fmodules-codegen` are not enabled by default with `/Yc`, but more work is 
needed to make this feature the default. This could be done in a subsequent 
patch.

  Unknown code
  UNREACHABLE executed at 
D:\llvm-project\llvm\lib\CodeGen\SelectionDAG\TargetLowering.cpp:5726!
  Stack dump:
  0.Program arguments: -cc1 -triple x86_64-pc-windows-msvc19.20.0 -emit-obj 
(edited) -building-pch-with-obj -fpch-instantiate-templates -fmodules-codegen 
-fmodules-debuginfo -include-pch D:\(edited)\MyProject.pch 
-pch-through-header=(edited)\precomp.h -include (edited)\precomp.h (edited) 
-fms-compatibility-version=19.20 -std=c++17 -fdelayed-template-parsing 
-finline-functions -fobjc-runtime=gcc -fdiagnostics-show-option 
-fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -O3 -faddrsig -o 
D:\(edited)\MyProject.pch.obj -x c++ D:\(edited)\precomp.cpp
  1. parser at end of file
  2.Code generation
  3.Running pass 'Function Pass Manager' on module '(edited)\precomp.cpp'.
  4.Running pass 'X86 DAG->DAG Instruction Selection' on function 
'@"?GetDeterminant@Matrix44f@MyNamespace@@QEBAMXZ"'
  #0 0x7ff6bada1c06 HandleAbort 
D:\llvm-project\llvm\lib\Support\Windows\Signals.inc:408:0
  #1 0x7ff6beb4b0e1 raise 
D:\llvm-project\build64_stage0\minkernel\crts\ucrt\src\appcrt\misc\signal.cpp:547:0
  #2 0x7ff6beb40e5c abort 
D:\llvm-project\build64_stage0\minkernel\crts\ucrt\src\appcrt\startup\abort.cpp:71:0
  #3 0x7ff6bad58207 llvm::llvm_unreachable_internal(char const *, char 
const *, unsigned int) D:\llvm-project\llvm\lib\Support\ErrorHandling.cpp:210:0
  #4 0x7ff6bbb14d2e llvm::TargetLowering::getNegatedExpression(class 
llvm::SDValue, class llvm::SelectionDAG &, bool, bool, unsigned int) const 
D:\llvm-project\llvm\lib\CodeGen\SelectionDAG\TargetLowering.cpp:5726:0
  #5 0x7ff6bba1dd26 llvm::X86TargetLowering::getNegatedExpression(class 
llvm::SDValue, class llvm::SelectionDAG &, bool, bool, unsigned int) const 
D:\llvm-project\llvm\lib\Target\X86\X86ISelLowering.cpp:42707:0
  #6 0x7ff6bbb140b3 llvm::TargetLowering::getNegatedExpression(class 
llvm::SDValue, class llvm::SelectionDAG &, bool, bool, unsigned int) const 
D:\llvm-project\llvm\lib\CodeGen\SelectionDAG\TargetLowering.cpp:5671:0
  #7 0x7ff6bba1dd26 llvm::X86TargetLowering::getNegatedExpression(class 
llvm::SDValue, class llvm::SelectionDAG &, bool, bool, unsigned int) const 
D:\llvm-project\llvm\lib\Target\X86\X86ISelLowering.cpp:42707:0
  #8 0x7ff6bbb1496c llvm::TargetLowering::getNegatedExpression(class 
llvm::SDValue, class llvm::SelectionDAG &, bool, bool, unsigned int) const 
D:\llvm-project\llvm\lib\CodeGen\SelectionDAG\TargetLowering.cpp:5643:0
  #9 0x7ff6bba1dd26 llvm::X86TargetLowering::getNegatedExpression(class 
llvm::SDValue, class llvm::SelectionDAG &, bool, bool, unsigned int) const 
D:\llvm-project\llvm\lib\Target\X86\X86ISelLowering.cpp:42707:0
  #10 0x7ff6bbb1496c llvm::TargetLowering::getNegatedExpression(class 
llvm::SDValue, class llvm::SelectionDAG &, bool, bool, unsigned int) const 
D:\llvm-project\llvm\lib\CodeGen\SelectionDAG\TargetLowering.cpp:5643:0
  #11 0x7ff6bba1dd26 llvm::X86TargetLowering::getNegatedExpression(class 
llvm::SDValue, class llvm::SelectionDAG &, bool, bool, unsigned int) const 
D:\llvm-project\llvm\lib\Target\X86\X86ISelLowering.cpp:42707:0
  #12 0x7ff6bbb14538 llvm::TargetLowering::getNegatedExpression(class 
llvm::SDValue, class llvm::SelectionDAG &, bool, bool, unsigned int) const 
D:\llvm-project\llvm\lib\CodeGen\SelectionDAG\TargetLowering.cpp:5708:0
  #13 0x7ff6bba1dd26 llvm::X86TargetLowering::getNegatedExpression(class 
llvm::SDValue, class llvm::SelectionDAG &, bool, bool, unsigned int) const 
D:\llvm-project\llvm\lib\Target\X86\X86ISelLowering.cpp:42707:0
  #14 0x7ff6bca4c6fb `anonymous namespace'::DAGCombiner::visit 
D:\llvm-project\llvm\lib\CodeGen\SelectionDAG\DAGCombiner.cpp:1573:0
  #15 0x7ff6bca30e4b `anonymous namespace'::DAGCombiner::combine 
D:\llvm-project\llvm\lib\CodeGen\SelectionDAG\DAGCombiner.cpp:1634:0
  #16 0x7ff6bca3052f llvm::SelectionDAG::Combine(enum llvm::CombineLevel, 
class llvm::AAResults *, enum llvm::CodeGenOpt::Level) 
D:\llvm-projec

[PATCH] D79830: Add support of __builtin_expect_with_probability

2020-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Additionally, it seems you're missing SEMA tests.  Please add those.  Those 
tests should also make sure that the diagnostics still work with dependent 
values.




Comment at: clang/include/clang/Basic/Builtins.def:567
 BUILTIN(__builtin_expect, "LiLiLi"   , "nc")
+BUILTIN(__builtin_expect_with_probability, "LiLiLid"   , "nc")
 BUILTIN(__builtin_prefetch, "vvC*.", "nc")

The spaces after the first parameter are odd/unnecessary.  I suspect it is in 
the line above because it was used to do alignment in the past.  Please don't 
bother putting them in this new line.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:2197
+const Expr *ProbArg = E->getArg(2);
+bool EvalSucceed = ProbArg->EvaluateAsFloat(Probability,
+CGM.getContext(), Expr::SideEffectsKind::SE_AllowSideEffects);

This is going to give an unused variable warning in release mode, since assert 
is a macro. You'll have to cast EvalSucceeded to void after the assert.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:2199
+CGM.getContext(), Expr::SideEffectsKind::SE_AllowSideEffects);
+assert(EvalSucceed == true);
+llvm::Type *Ty = ConvertType(ProbArg->getType());

First, don't do ==true here.  Second, add a string to the assert (see other 
assert uses).


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

https://reviews.llvm.org/D79830



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


[clang] 6b7d51a - Add missing forward decl to unbreak the modular build

2020-05-26 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2020-05-26T09:08:27-07:00
New Revision: 6b7d51ad4a16579b0a7d41c77715be4d9e266d8c

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

LOG: Add missing forward decl to unbreak the modular build

Added: 


Modified: 
clang/include/clang/Index/IndexingOptions.h

Removed: 




diff  --git a/clang/include/clang/Index/IndexingOptions.h 
b/clang/include/clang/Index/IndexingOptions.h
index 2dd276998abf..9f5c03d1b3b9 100644
--- a/clang/include/clang/Index/IndexingOptions.h
+++ b/clang/include/clang/Index/IndexingOptions.h
@@ -14,6 +14,7 @@
 #include 
 
 namespace clang {
+class Decl;
 namespace index {
 
 struct IndexingOptions {



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


[clang] b59b364 - Debug Info: Mark os_log helper functions as artificial

2020-05-26 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2020-05-26T09:08:27-07:00
New Revision: b59b3640bcbdfc6cf4b35ff3a6ad5f524a073b45

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

LOG: Debug Info: Mark os_log helper functions as artificial

The os_log helper functions are linkonce_odr and supposed to be
uniqued across TUs, so attachine a DW_AT_decl_line on it is highly
misleading. By setting the function decl to implicit, CGDebugInfo
properly marks the functions as artificial and uses a default file /
line 0 location for the function.

rdar://problem/63450824

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

Added: 
clang/test/CodeGen/debug-info-oslog.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ddd9a68a8edb..bef0ad27145f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1271,6 +1271,8 @@ llvm::Function 
*CodeGenFunction::generateBuiltinOSLogHelperFunction(
   FunctionDecl *FD = FunctionDecl::Create(
   Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), 
II,
   FuncionTy, nullptr, SC_PrivateExtern, false, false);
+  // Avoid generating debug location info for the function.
+  FD->setImplicit();
 
   StartFunction(FD, ReturnTy, Fn, FI, Args);
 

diff  --git a/clang/test/CodeGen/debug-info-oslog.c 
b/clang/test/CodeGen/debug-info-oslog.c
new file mode 100644
index ..c32c79eb8a6f
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-oslog.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-darwin-apple -debug-info-kind=limited \
+// RUN:   %s -emit-llvm -o -  | FileCheck %s
+void test_builtin_os_log(void *buf, int i, const char *data) {
+  __builtin_os_log_format(buf, "%d", i);
+}
+
+// CHECK: define linkonce_odr {{.*}}@__os_log_helper_1_0_1_4_0(
+// CHECK-SAME:   !dbg ![[OS_LOG_HELPER:[0-9]+]]
+
+// This helper is going to be uniqued, so it should not have a line
+// number between file and type.
+
+// CHECK: distinct !DISubprogram(name: "__os_log_helper_1_0_1_4_0",
+// CHECK-SAME:   file: !{{[0-9+]}}, type
+// CHECK-SAME:   flags: DIFlagArtificial



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


[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread Ronald Wampler via Phabricator via cfe-commits
rdwampler added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1965
   // handle [[likely]] / [[unlikely]]
-  if (FormatTok->is(tok::l_square))
+  if (FormatTok->is(tok::l_square) && tryToParseSimpleAttribute())
 parseSquare();

From the peanut gallery, would checking `TT_AttributeSquare` here work (that 
should handle ambiguities around ObjC method calls)?  


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

https://reviews.llvm.org/D80547



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


[PATCH] D80522: [Analyzer] [NFC] Parameter Regions -- Alternative Approach

2020-05-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Nice, looks like you managed to reuse most of the code. I still feel like we 
should ditch `DeclRegion` entirely (forcing its ~5 current users consider its 
specific variants separately) but i don't insist.




Comment at: clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h:232-233
+OS << Index;
+if (Index % 10 == 1 && Index != 11)
+  OS << "st ";
+else if (Index % 10 == 2 && Index != 12)

There's a standard function for that. I never remember what it's called, 
something something numeric something plural something suffix, but it's there.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp:539-540
   (void)VV;
-  assert(cast(VV.castAs().getRegion())
- ->getStackFrame()->getParent()
- ->getStackFrame() == LC->getStackFrame());
+  if (const auto *VR =
+  dyn_cast(VV.castAs().getRegion())) {
+assert(VR->getStackFrame()->getParent()

Why did you relax this `cast<>` to `dyn_cast<>`?



Comment at: clang/lib/StaticAnalyzer/Core/MemRegion.cpp:183
+  assert (getDecl() &&
+  "`ParamVarRegion` does not support functions without `Decl`");
+  return getDecl()->getType();

It will eventually have to. Maybe `"...not implemented yet"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80522



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


[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2349
+// ahead in the token source.
+class AutoTokenPosition {
+  unsigned StoredPosition;

nit: I've seen similar RAII idioms in lib/Format use names like [[ 
https://github.com/llvm/llvm-project/blob/6ef45b0426a8c7b9764e102fb1a49561a3a2c118/clang/lib/Format/UnwrappedLineParser.cpp#L139
 | **Scoped**LineState ]] - just wanted to mention that naming alternative.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2372
+  }
+  // Double check  that the attribute is just something
+  // fairly simple.

nit: `check  that` has a double space


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

https://reviews.llvm.org/D80547



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


[PATCH] D77148: [analyzer] ApiModeling: Add buffer size arg constraint with multiplier involved

2020-05-26 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 3 inline comments as done.
martong added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1013
+addToFunctionSummaryMap(
+"__buf_size_arg_constraint_mul",
+Summary(ArgTypes{ConstVoidPtrTy, SizeTy, SizeTy}, RetType{IntTy},

xazax.hun wrote:
> Why do we need these test functions? Above I saw `fread` as an example that 
> requires this capability. Wouldn't it be better to make its summary utilize 
> the new feature and use `fread` in tests? Do I miss something?
Yeah, we could test that with `fread`. However, in `fread` there are multiple 
argument constraints for the different args. I wanted a test function which has 
this arg constraint in an isolation. In my opinion it is good to have small 
isolated unit tests that test only one functionality. Also if we decide to 
remove or modify `fread`s summary for any reason, then we should modify this 
test too, on the other hand, with this test function it is not a problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77148



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


[PATCH] D80016: [analyzer] StdLibraryFunctionsChecker: Add support to lookup types

2020-05-26 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 2 inline comments as done.
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:747
+  : *FilePtrTy)
+: None;
+

balazske wrote:
> The `Optional` can be left out from the right side expressions (in 
> the `?` operator part). (A `QualType` should be assignable to 
> `Optional`.)
No that cannot be left out. Implicit conversion does not play when trying to 
determine the common type for the 2nd and 3rd argument of the ternary op. 
https://stackoverflow.com/questions/32251419/c-ternary-operator-conditional-operator-and-its-implicit-type-conversion-r
So, removing the explicit type I get a compile error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80016



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


[PATCH] D80463: Debug Info: Mark os_log helper functions as artificial

2020-05-26 Thread Adrian Prantl via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb59b3640bcbd: Debug Info: Mark os_log helper functions as 
artificial (authored by aprantl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80463

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/debug-info-oslog.c


Index: clang/test/CodeGen/debug-info-oslog.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-oslog.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-darwin-apple -debug-info-kind=limited \
+// RUN:   %s -emit-llvm -o -  | FileCheck %s
+void test_builtin_os_log(void *buf, int i, const char *data) {
+  __builtin_os_log_format(buf, "%d", i);
+}
+
+// CHECK: define linkonce_odr {{.*}}@__os_log_helper_1_0_1_4_0(
+// CHECK-SAME:   !dbg ![[OS_LOG_HELPER:[0-9]+]]
+
+// This helper is going to be uniqued, so it should not have a line
+// number between file and type.
+
+// CHECK: distinct !DISubprogram(name: "__os_log_helper_1_0_1_4_0",
+// CHECK-SAME:   file: !{{[0-9+]}}, type
+// CHECK-SAME:   flags: DIFlagArtificial
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1271,6 +1271,8 @@
   FunctionDecl *FD = FunctionDecl::Create(
   Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), 
II,
   FuncionTy, nullptr, SC_PrivateExtern, false, false);
+  // Avoid generating debug location info for the function.
+  FD->setImplicit();
 
   StartFunction(FD, ReturnTy, Fn, FI, Args);
 


Index: clang/test/CodeGen/debug-info-oslog.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-oslog.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-darwin-apple -debug-info-kind=limited \
+// RUN:   %s -emit-llvm -o -  | FileCheck %s
+void test_builtin_os_log(void *buf, int i, const char *data) {
+  __builtin_os_log_format(buf, "%d", i);
+}
+
+// CHECK: define linkonce_odr {{.*}}@__os_log_helper_1_0_1_4_0(
+// CHECK-SAME:   !dbg ![[OS_LOG_HELPER:[0-9]+]]
+
+// This helper is going to be uniqued, so it should not have a line
+// number between file and type.
+
+// CHECK: distinct !DISubprogram(name: "__os_log_helper_1_0_1_4_0",
+// CHECK-SAME:   file: !{{[0-9+]}}, type
+// CHECK-SAME:   flags: DIFlagArtificial
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1271,6 +1271,8 @@
   FunctionDecl *FD = FunctionDecl::Create(
   Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), II,
   FuncionTy, nullptr, SC_PrivateExtern, false, false);
+  // Avoid generating debug location info for the function.
+  FD->setImplicit();
 
   StartFunction(FD, ReturnTy, Fn, FI, Args);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80366: [Analyzer] Add `getReturnValueUnderConstruction()` to `CallEvent`

2020-05-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:112
 
+Optional ExprEngine::retrieveFromConstructionContext(
+ProgramStateRef State, const LocationContext *LCtx,

baloghadamsoftware wrote:
> NoQ wrote:
> > Please instead re-use the code that computes the object under construction. 
> > That'll save you ~50 lines of code and will be more future-proof (eg., 
> > standalone temporaries without destructor technically have a construction 
> > context with 0 items so when we implement them correctly your procedure 
> > will stop working).
> That was so my first thought. However, `handleConstructionContext()` is 
> private and non-static. Now I tried to merge the two methods: if the value is 
> already in the construction context, we return it, if not then we add it. Is 
> this what you suggest? Or did I misunderstand you? At the very beginning I 
> tried to simply use `handleConstructionContext()`, but it asserted because 
> the value was already in the map.
I'd like to preserve the assertion that objects-under-construction are never 
filled twice; it's a very useful sanity check. What you need in your checker is 
a function that computes object-under-construction but doesn't put it into the 
objects-under-construction map. So you have to separate the computation from 
filling in the state.


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

https://reviews.llvm.org/D80366



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


[PATCH] D80525: [clangd] Fix crash-bug in preamble indexing when using modules.

2020-05-26 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz updated this revision to Diff 266240.
adamcz marked 3 inline comments as done.
adamcz added a comment.

Addressed review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80525

Files:
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Index/IndexingAction.cpp

Index: clang/lib/Index/IndexingAction.cpp
===
--- clang/lib/Index/IndexingAction.cpp
+++ clang/lib/Index/IndexingAction.cpp
@@ -147,14 +147,24 @@
   Unit.visitLocalTopLevelDecls(&IndexCtx, topLevelDeclVisitor);
 }
 
-static void indexPreprocessorMacros(const Preprocessor &PP,
+static void indexPreprocessorMacros(Preprocessor &PP,
 IndexDataConsumer &DataConsumer) {
-  for (const auto &M : PP.macros())
-if (MacroDirective *MD = M.second.getLatest())
+  for (const auto &M : PP.macros()) {
+if (MacroDirective *MD = M.second.getLatest()) {
+  auto *MI = MD->getMacroInfo();
+  if (!MI) {
+// It is possible for MI to be nullptr if we our translation unit had
+// only #undef of a macro defined in a module. In that case, dig deeper
+// and use the definition from the module to yield the same indexing
+// result whether we are using modules or not.
+MI = PP.getMacroInfoFromModules(M.first);
+  }
+
   DataConsumer.handleMacroOccurrence(
-  M.first, MD->getMacroInfo(),
-  static_cast(index::SymbolRole::Definition),
+  M.first, MI, static_cast(index::SymbolRole::Definition),
   MD->getLocation());
+}
+  }
 }
 
 void index::indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -1115,6 +1115,28 @@
 return nullptr;
   }
 
+  // Returns MacroInfo for the latest definition of II within a module, nullptr
+  // if this macro was never defined in a module. The return MacroInfo may refer
+  // to definition that was overridden locally.
+  MacroInfo *getMacroInfoFromModules(const IdentifierInfo *II) {
+if (!II->hasMacroDefinition())
+  return nullptr;
+MacroState &S = CurSubmoduleState->Macros[II];
+auto ActiveModuleMacros = S.getActiveModuleMacros(*this, II);
+for (auto MM = ActiveModuleMacros.rbegin(); MM != ActiveModuleMacros.rend();
+ MM++) {
+  if (auto *MI = (*MM)->getMacroInfo())
+return MI;
+}
+auto OverriddenMacros = S.getOverriddenMacros();
+for (auto MM = OverriddenMacros.rbegin(); MM != OverriddenMacros.rend();
+ MM++) {
+  if (auto *MI = (*MM)->getMacroInfo())
+return MI;
+}
+return nullptr;
+  }
+
   /// Given an identifier, return the latest non-imported macro
   /// directive for that identifier.
   ///
Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -65,6 +65,10 @@
   // Simulate a header guard of the header (using an #import directive).
   bool ImplicitHeaderGuard = true;
 
+  // Whether to use overlay the TestFS over the real filesystem. This is
+  // required for use of modules.
+  bool OverlayRealFileSystem = false;
+
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   ParsedAST build() const;
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -54,7 +54,14 @@
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;
-  Inputs.FS = buildTestFS(Files);
+  if (OverlayRealFileSystem) {
+IntrusiveRefCntPtr OverlayFileSystem =
+new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem());
+OverlayFileSystem->pushOverlay(buildTestFS(Files));
+Inputs.FS = OverlayFileSystem;
+  } else {
+Inputs.FS = buildTestFS(Files);
+  }
   Inputs.Opts = ParseOptions();
   Inputs.Opts.BuildRecoveryAST = true;
   Inputs.Opts.PreserveRecoveryASTType = true;
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1490,6 +1490,29 @@
   EXPECT_THAT(Symbols, Contains(QName("operator delete")));
 }
 
+TEST_F(

[PATCH] D80547: [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses

2020-05-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked 2 inline comments as done.
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1965
   // handle [[likely]] / [[unlikely]]
-  if (FormatTok->is(tok::l_square))
+  if (FormatTok->is(tok::l_square) && tryToParseSimpleAttribute())
 parseSquare();

rdwampler wrote:
> From the peanut gallery, would checking `TT_AttributeSquare` here work (that 
> should handle ambiguities around ObjC method calls)?  
unfortunately the TT_AttributeSquare hasn't been determined at this stage


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

https://reviews.llvm.org/D80547



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


[PATCH] D80020: [PowerPC] Add support for -mcpu=pwr10 in both clang and llvm

2020-05-26 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp accepted this revision.
stefanp added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80020



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


[PATCH] D79754: [OpenMP][AMDGCN] Support OpenMP offloading for AMDGCN architecture - Part 1

2020-05-26 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

I'm generally fine with this, don't wait for my approval.




Comment at: clang/test/OpenMP/amdgcn_device_function_call.cpp:27
+  }
+}

Not for this patch:
FWIW, we will need to make math functions work inside target regions. The way 
aomp does it is afaik different from the way we do it. We can however adopt our 
way for this target though. Feel free to ping me on this later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79754



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


  1   2   3   >