[clang] da236f2 - Strip preceeding -Xclang when stripping -fcolor-diagnostics or -fdiagnostics-color

2020-02-26 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-02-26T09:05:05+01:00
New Revision: da236f235028c82c2f0e00eea1f6f9c689bcae4a

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

LOG: Strip preceeding -Xclang when stripping -fcolor-diagnostics or 
-fdiagnostics-color

Summary: Fixes https://github.com/clangd/clangd/issues/279. We were removing 
the color options but not the preceeding -Xclang which causes errors since the 
-Xclang would now apply to the next option in the list of options. Now, when 
removing a color option, we check if there was a preceeding -Xclang and remove 
it as well.

Patch By @DaanDeMeyer !

Reviewers: sammccall, kadircet

Reviewed By: sammccall

Subscribers: ilya-biryukov, usaxena95

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

Added: 


Modified: 
clang/lib/Tooling/ArgumentsAdjusters.cpp

Removed: 




diff  --git a/clang/lib/Tooling/ArgumentsAdjusters.cpp 
b/clang/lib/Tooling/ArgumentsAdjusters.cpp
index 5869377a03c9..62ee954e3096 100644
--- a/clang/lib/Tooling/ArgumentsAdjusters.cpp
+++ b/clang/lib/Tooling/ArgumentsAdjusters.cpp
@@ -42,6 +42,12 @@ ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
   if (!Arg.startswith("-fcolor-diagnostics") &&
   !Arg.startswith("-fdiagnostics-color"))
 AdjustedArgs.push_back(Args[i]);
+  // If we strip a color option, make sure we strip any preceeding 
`-Xclang`
+  // option as well.
+  // FIXME: This should be added to most argument adjusters!
+  else if (!AdjustedArgs.empty() && AdjustedArgs.back() == "-Xclang")
+AdjustedArgs.pop_back();
+
   if (Arg == "-fsyntax-only")
 HasSyntaxOnly = true;
 }



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


[PATCH] D75019: Strip preceeding -Xclang when stripping -fcolor-diagnostics or -fdiagnostics-color

2020-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGda236f235028: Strip preceeding -Xclang when stripping 
-fcolor-diagnostics or -fdiagnostics… (authored by kadircet).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D75019?vs=246526&id=246638#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75019

Files:
  clang/lib/Tooling/ArgumentsAdjusters.cpp


Index: clang/lib/Tooling/ArgumentsAdjusters.cpp
===
--- clang/lib/Tooling/ArgumentsAdjusters.cpp
+++ clang/lib/Tooling/ArgumentsAdjusters.cpp
@@ -42,6 +42,12 @@
   if (!Arg.startswith("-fcolor-diagnostics") &&
   !Arg.startswith("-fdiagnostics-color"))
 AdjustedArgs.push_back(Args[i]);
+  // If we strip a color option, make sure we strip any preceeding 
`-Xclang`
+  // option as well.
+  // FIXME: This should be added to most argument adjusters!
+  else if (!AdjustedArgs.empty() && AdjustedArgs.back() == "-Xclang")
+AdjustedArgs.pop_back();
+
   if (Arg == "-fsyntax-only")
 HasSyntaxOnly = true;
 }


Index: clang/lib/Tooling/ArgumentsAdjusters.cpp
===
--- clang/lib/Tooling/ArgumentsAdjusters.cpp
+++ clang/lib/Tooling/ArgumentsAdjusters.cpp
@@ -42,6 +42,12 @@
   if (!Arg.startswith("-fcolor-diagnostics") &&
   !Arg.startswith("-fdiagnostics-color"))
 AdjustedArgs.push_back(Args[i]);
+  // If we strip a color option, make sure we strip any preceeding `-Xclang`
+  // option as well.
+  // FIXME: This should be added to most argument adjusters!
+  else if (!AdjustedArgs.empty() && AdjustedArgs.back() == "-Xclang")
+AdjustedArgs.pop_back();
+
   if (Arg == "-fsyntax-only")
 HasSyntaxOnly = true;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75048: [ASTImporter] Improved import of AlignedAttr.

2020-02-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/AST/ASTImporter.cpp:7944
+  if (auto ToEOrErr = Import(From->getAlignmentExpr()))
+To = AlignedAttr::Create(ToContext, true, *ToEOrErr, ToRange,
+ FromAttr->getSyntax(),

shafik wrote:
> shafik wrote:
> > This call to `Create` and the one below look identical can we please 
> > refactor to avoid code duplication.
> How about something more like, maybe I am missing a detail but hopefully not:
> 
> ```
> bool IsAlignmentExpr=From->isAlignmentExpr();
> auto ToEOrErr = [IsAlignmentExpr]() {
>   if (IsAlignmentExpr)
> return Import(From->getAlignmentExpr());
> 
>   return  Import(From->getAlignmentType());
> }();
> 
> if (!ToTOrErr)
>   return ToTOrErr.takeError();
> 
> To = AlignedAttr::Create(ToContext, IsAlignmentExpr, *ToEOrErr, ToRange,
>  
> From->getSyntax(),From->getSemanticSpelling());
> ```
It is only possible by using a template. Importing of AlignmentExpr returns 
`Expected` and importing the AlignmentType returns 
`Expected`. The `ToTOrErr` and `ToEOrErr` are of different 
types. (The create function expects a `void *` that can be a pointer to Expr or 
TypeSourceInfo).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75048



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


[PATCH] D74834: [clangd] Expose the rename LimitFiles option to the C++ API, NFC.

2020-02-26 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 246640.
hokein added a comment.

keep the old clangdServer::rename around temporarily to make internal 
integration life easier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74834

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/refactor/Rename.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.h

Index: clang-tools-extra/clangd/unittests/SyncAPI.h
===
--- clang-tools-extra/clangd/unittests/SyncAPI.h
+++ clang-tools-extra/clangd/unittests/SyncAPI.h
@@ -39,7 +39,8 @@
 runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos);
 
 llvm::Expected runRename(ClangdServer &Server, PathRef File,
-Position Pos, StringRef NewName);
+Position Pos, StringRef NewName,
+const clangd::RenameOptions &RenameOpts);
 
 std::string runDumpAST(ClangdServer &Server, PathRef File);
 
Index: clang-tools-extra/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -97,9 +97,10 @@
 }
 
 llvm::Expected runRename(ClangdServer &Server, PathRef File,
-Position Pos, llvm::StringRef NewName) {
+Position Pos, llvm::StringRef NewName,
+const RenameOptions &RenameOpts) {
   llvm::Optional> Result;
-  Server.rename(File, Pos, NewName, /*WantFormat=*/false, capture(Result));
+  Server.rename(File, Pos, NewName, RenameOpts, capture(Result));
   return std::move(*Result);
 }
 
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -721,8 +721,13 @@
   TestTU TU = TestTU::withCode(MainCode.code());
   auto AST = TU.build();
   llvm::StringRef NewName = "newName";
-  auto Results = rename({MainCode.point(), NewName, AST, MainFilePath,
- Index.get(), /*CrossFile=*/true, GetDirtyBuffer});
+  auto Results = rename({MainCode.point(),
+ NewName,
+ AST,
+ MainFilePath,
+ Index.get(),
+ {/*CrossFile=*/true},
+ GetDirtyBuffer});
   ASSERT_TRUE(bool(Results)) << Results.takeError();
   EXPECT_THAT(
   applyEdits(std::move(*Results)),
@@ -737,8 +742,13 @@
   // Set a file "bar.cc" on disk.
   TU.AdditionalFiles["bar.cc"] = std::string(BarCode.code());
   AST = TU.build();
-  Results = rename({MainCode.point(), NewName, AST, MainFilePath, Index.get(),
-/*CrossFile=*/true, GetDirtyBuffer});
+  Results = rename({MainCode.point(),
+NewName,
+AST,
+MainFilePath,
+Index.get(),
+{/*CrossFile=*/true},
+GetDirtyBuffer});
   ASSERT_TRUE(bool(Results)) << Results.takeError();
   EXPECT_THAT(
   applyEdits(std::move(*Results)),
@@ -768,8 +778,13 @@
Callback) const override {}
 size_t estimateMemoryUsage() const override { return 0; }
   } PIndex;
-  Results = rename({MainCode.point(), NewName, AST, MainFilePath, &PIndex,
-/*CrossFile=*/true, GetDirtyBuffer});
+  Results = rename({MainCode.point(),
+NewName,
+AST,
+MainFilePath,
+&PIndex,
+{/*CrossFile=*/true},
+GetDirtyBuffer});
   EXPECT_FALSE(Results);
   EXPECT_THAT(llvm::toString(Results.takeError()),
   testing::HasSubstr("too many occurrences"));
@@ -810,9 +825,12 @@
 
 RefsRequest *Out;
   } RIndex(&Req);
-  auto Results =
-  rename({MainCode.point(), "NewName", AST, testPath("main.cc"), &RIndex,
-  /*CrossFile=*/true});
+  auto Results = rename({MainCode.point(),
+ "NewName",
+ AST,
+ testPath("main.cc"),
+ &RIndex,
+ {/*CrossFile=*/true}});
   ASSERT_TRUE(bool(Results)) << Results.takeError();
   const auto HeaderSymbols = TU.headerSymbols();
  

[clang-tools-extra] 34d0e1b - [clangd] Expose the rename LimitFiles option to the C++ API, NFC.

2020-02-26 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-02-26T09:33:58+01:00
New Revision: 34d0e1bd6d05ee11f638ca085f4755e75e18adfc

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

LOG: [clangd] Expose the rename LimitFiles option to the C++ API, NFC.

Reviewers: sammccall

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/refactor/Rename.h
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/ClangdTests.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp
clang-tools-extra/clangd/unittests/SyncAPI.cpp
clang-tools-extra/clangd/unittests/SyncAPI.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index c31a0a417ebe..55e63c71b23e 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -761,7 +761,7 @@ void ClangdLSPServer::onWorkspaceSymbol(
 void ClangdLSPServer::onPrepareRename(const TextDocumentPositionParams &Params,
   Callback> Reply) {
   Server->prepareRename(Params.textDocument.uri.file(), Params.position,
-std::move(Reply));
+RenameOpts, std::move(Reply));
 }
 
 void ClangdLSPServer::onRename(const RenameParams &Params,
@@ -772,8 +772,7 @@ void ClangdLSPServer::onRename(const RenameParams &Params,
 return Reply(llvm::make_error(
 "onRename called for non-added file", ErrorCode::InvalidParams));
   Server->rename(
-  File, Params.position, Params.newName,
-  /*WantFormat=*/true,
+  File, Params.position, Params.newName, RenameOpts,
   [File, Params, Reply = std::move(Reply),
this](llvm::Expected Edits) mutable {
 if (!Edits)
@@ -1230,12 +1229,14 @@ void ClangdLSPServer::onDocumentLink(
 ClangdLSPServer::ClangdLSPServer(
 class Transport &Transp, const FileSystemProvider &FSProvider,
 const clangd::CodeCompleteOptions &CCOpts,
+const clangd::RenameOptions &RenameOpts,
 llvm::Optional CompileCommandsDir, bool UseDirBasedCDB,
 llvm::Optional ForcedOffsetEncoding,
 const ClangdServer::Options &Opts)
 : BackgroundContext(Context::current().clone()), Transp(Transp),
   MsgHandler(new MessageHandler(*this)), FSProvider(FSProvider),
-  CCOpts(CCOpts), SupportedSymbolKinds(defaultSymbolKinds()),
+  CCOpts(CCOpts), RenameOpts(RenameOpts),
+  SupportedSymbolKinds(defaultSymbolKinds()),
   SupportedCompletionItemKinds(defaultCompletionItemKinds()),
   UseDirBasedCDB(UseDirBasedCDB),
   CompileCommandsDir(std::move(CompileCommandsDir)), 
ClangdServerOpts(Opts),

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index a186d05f08f9..f30fbf6b5149 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -42,6 +42,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
   // FIXME: Clean up signature around CDBs.
   ClangdLSPServer(Transport &Transp, const FileSystemProvider &FSProvider,
   const clangd::CodeCompleteOptions &CCOpts,
+  const clangd::RenameOptions &RenameOpts,
   llvm::Optional CompileCommandsDir, bool UseDirBasedCDB,
   llvm::Optional ForcedOffsetEncoding,
   const ClangdServer::Options &Opts);
@@ -197,6 +198,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
   const FileSystemProvider &FSProvider;
   /// Options used for code completion
   clangd::CodeCompleteOptions CCOpts;
+  /// Options used for rename.
+  clangd::RenameOptions RenameOpts;
   /// Options used for diagnostics.
   ClangdDiagnosticOptions DiagOpts;
   /// The supported kinds of the client.

diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 6e37a7b441cb..92dcf841331a 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -131,8 +131,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase 
&CDB,
  : nullptr),
   GetClangTidyOptions(Opts.GetClangTidyOptions),
   SuggestMissingIncludes(Opts.SuggestMissingIncludes),
-  CrossFileRename(Opts.CrossFileRename), TweakFilter(Opts.TweakFilter),
-  WorkspaceRoot(Opts.WorkspaceRoot),
+  TweakFilter(Op

[PATCH] D74834: [clangd] Expose the rename LimitFiles option to the C++ API, NFC.

2020-02-26 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG34d0e1bd6d05: [clangd] Expose the rename LimitFiles option 
to the C++ API, NFC. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D74834?vs=246640&id=246641#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74834

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/refactor/Rename.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.h

Index: clang-tools-extra/clangd/unittests/SyncAPI.h
===
--- clang-tools-extra/clangd/unittests/SyncAPI.h
+++ clang-tools-extra/clangd/unittests/SyncAPI.h
@@ -39,7 +39,8 @@
 runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos);
 
 llvm::Expected runRename(ClangdServer &Server, PathRef File,
-Position Pos, StringRef NewName);
+Position Pos, StringRef NewName,
+const clangd::RenameOptions &RenameOpts);
 
 std::string runDumpAST(ClangdServer &Server, PathRef File);
 
Index: clang-tools-extra/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -97,9 +97,10 @@
 }
 
 llvm::Expected runRename(ClangdServer &Server, PathRef File,
-Position Pos, llvm::StringRef NewName) {
+Position Pos, llvm::StringRef NewName,
+const RenameOptions &RenameOpts) {
   llvm::Optional> Result;
-  Server.rename(File, Pos, NewName, /*WantFormat=*/false, capture(Result));
+  Server.rename(File, Pos, NewName, RenameOpts, capture(Result));
   return std::move(*Result);
 }
 
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -721,8 +721,13 @@
   TestTU TU = TestTU::withCode(MainCode.code());
   auto AST = TU.build();
   llvm::StringRef NewName = "newName";
-  auto Results = rename({MainCode.point(), NewName, AST, MainFilePath,
- Index.get(), /*CrossFile=*/true, GetDirtyBuffer});
+  auto Results = rename({MainCode.point(),
+ NewName,
+ AST,
+ MainFilePath,
+ Index.get(),
+ {/*CrossFile=*/true},
+ GetDirtyBuffer});
   ASSERT_TRUE(bool(Results)) << Results.takeError();
   EXPECT_THAT(
   applyEdits(std::move(*Results)),
@@ -737,8 +742,13 @@
   // Set a file "bar.cc" on disk.
   TU.AdditionalFiles["bar.cc"] = std::string(BarCode.code());
   AST = TU.build();
-  Results = rename({MainCode.point(), NewName, AST, MainFilePath, Index.get(),
-/*CrossFile=*/true, GetDirtyBuffer});
+  Results = rename({MainCode.point(),
+NewName,
+AST,
+MainFilePath,
+Index.get(),
+{/*CrossFile=*/true},
+GetDirtyBuffer});
   ASSERT_TRUE(bool(Results)) << Results.takeError();
   EXPECT_THAT(
   applyEdits(std::move(*Results)),
@@ -768,8 +778,13 @@
Callback) const override {}
 size_t estimateMemoryUsage() const override { return 0; }
   } PIndex;
-  Results = rename({MainCode.point(), NewName, AST, MainFilePath, &PIndex,
-/*CrossFile=*/true, GetDirtyBuffer});
+  Results = rename({MainCode.point(),
+NewName,
+AST,
+MainFilePath,
+&PIndex,
+{/*CrossFile=*/true},
+GetDirtyBuffer});
   EXPECT_FALSE(Results);
   EXPECT_THAT(llvm::toString(Results.takeError()),
   testing::HasSubstr("too many occurrences"));
@@ -810,9 +825,12 @@
 
 RefsRequest *Out;
   } RIndex(&Req);
-  auto Results =
-  rename({MainCode.point(), "NewName", AST, testPath("main.cc"), &RIndex,
-  /*CrossFile=*/true});
+  auto Results = rename({MainCode.point(),
+ "NewName",
+ AST,
+ testPath("main.cc"),
+ &RIndex,
+ {/*CrossFile=*/tr

[PATCH] D75125: [Docs][OpenCL] Release 10.0 notes for OpenCL

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

Thanks for writing notes! Go ahead and push directly to the branch when you're 
ready.




Comment at: clang/docs/ReleaseNotes.rst:288
+OpenCL Kernel Language Changes in Clang
 --
 

For the formatting to work, I think the number of dashes need to match the 
length of the previous line here.


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

https://reviews.llvm.org/D75125



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


[PATCH] D75158: [analyzer][StreamChecker] Using function description objects - NFC.

2020-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, martong, Charusso, gamesh411, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: clang.

Have a description object for the stream functions
that can store different aspects of a single stream operation.

I plan to extend the structure with other members,
for example pre-callback and index of the stream argument.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75158

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -49,6 +49,15 @@
   }
 };
 
+class StreamChecker;
+
+using FnCheck = std::function;
+
+struct FnDescription {
+  FnCheck EvalFn;
+};
+
 class StreamChecker : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
@@ -59,35 +68,33 @@
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
 
 private:
-  using FnCheck = std::function;
-
-  CallDescriptionMap Callbacks = {
-  {{"fopen"}, &StreamChecker::evalFopen},
-  {{"freopen", 3}, &StreamChecker::evalFreopen},
-  {{"tmpfile"}, &StreamChecker::evalFopen},
-  {{"fclose", 1}, &StreamChecker::evalFclose},
+
+  CallDescriptionMap FnDescriptions = {
+  {{"fopen"}, {&StreamChecker::evalFopen}},
+  {{"freopen", 3}, {&StreamChecker::evalFreopen}},
+  {{"tmpfile"}, {&StreamChecker::evalFopen}},
+  {{"fclose", 1}, {&StreamChecker::evalFclose}},
   {{"fread", 4},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
   {{"fwrite", 4},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
-  {{"fseek", 3}, &StreamChecker::evalFseek},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
+  {{"fseek", 3}, {&StreamChecker::evalFseek}},
   {{"ftell", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"rewind", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"fgetpos", 2},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"fsetpos", 2},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"clearerr", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"feof", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"ferror", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"fileno", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   };
 
   void evalFopen(const CallEvent &Call, CheckerContext &C) const;
@@ -125,11 +132,11 @@
   return false;
   }
 
-  const FnCheck *Callback = Callbacks.lookup(Call);
-  if (!Callback)
+  const FnDescription *Description = FnDescriptions.lookup(Call);
+  if (!Description)
 return false;
 
-  (*Callback)(this, Call, C);
+  (Description->EvalFn)(this, Call, C);
 
   return C.isDifferent();
 }


Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -49,6 +49,15 @@
   }
 };
 
+class StreamChecker;
+
+using FnCheck = std::function;
+
+struct FnDescription {
+  FnCheck EvalFn;
+};
+
 class StreamChecker : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
@@ -59,35 +68,33 @@
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
 
 private:
-  using FnCheck = std::function;
-
-  CallDescriptionMap Callbacks = {
-  {{"fopen"}, &StreamChecker::evalFopen},
-  {{"freopen", 3}, &StreamChecker::evalFreopen},
-  {{"tmpfile"}, &StreamChecker::evalFopen},
-  {{"fclose", 1}, &StreamChecker::evalFclose},
+
+  CallDescriptionMap FnDescriptions = {
+  {{"fopen"}, {&StreamChecker::evalFopen}},
+  {{"freopen", 3}, {&StreamChecker::evalFreopen}},
+  {{"tmpfile"}, {&StreamChecker::evalFopen}},
+  {{"fclose", 1}, {&

[clang-tools-extra] 4feca71 - Fix the clangd-fuzzer build error.

2020-02-26 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-02-26T10:13:13+01:00
New Revision: 4feca71df0ca96237342d0e3ef41e3cdbfa0e27c

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

LOG: Fix the clangd-fuzzer build error.

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp 
b/clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp
index 4e5d8d7a6ff9..9776b0585e2b 100644
--- a/clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp
+++ b/clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp
@@ -16,6 +16,7 @@
 #include "ClangdServer.h"
 #include "CodeComplete.h"
 #include "FSProvider.h"
+#include "refactor/Rename.h"
 #include 
 #include 
 
@@ -36,8 +37,8 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t 
size) {
   ClangdServer::Options Opts;
 
   // Initialize and run ClangdLSPServer.
-  ClangdLSPServer LSPServer(*Transport, FS, CCOpts, llvm::None, false,
-llvm::None, Opts);
+  ClangdLSPServer LSPServer(*Transport, FS, CCOpts, RenameOptions(), 
llvm::None,
+false, llvm::None, Opts);
   LSPServer.run();
   return 0;
 }



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


[PATCH] D74962: [clang][Tooling] Add a way to tokenize a FileRange

2020-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 2 inline comments as done.
kadircet added inline comments.



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:335
   clang::Token T;
-  while (!L.LexFromRawLexer(T))
+  while (!L.LexFromRawLexer(T) && L.getCurrentBufferOffset() < FR.endOffset())
 AddToken(T);

sammccall wrote:
> Discussed offline, this loop includes an extra token if the truncation is at 
> whitespace between tokens. (Please test this case)
> 
> Also the eof comment is confusing.
> 
> I think the loop should be rewritten.
instead of re-writing the loop I just changed the after-the-loop check to 
verify latest lexed token to be in range.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74962



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


[PATCH] D74962: [clang][Tooling] Add a way to tokenize a FileRange

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

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74962

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -153,11 +153,17 @@
 }
   }
 
-  /// Add a new file, run syntax::tokenize() on it and return the results.
+  /// Add a new file, run syntax::tokenize() on the range if any, run it on the
+  /// whole file otherwise and return the results.
   std::vector tokenize(llvm::StringRef Text) {
+llvm::Annotations Annot(Text);
+auto FID = SourceMgr->createFileID(
+llvm::MemoryBuffer::getMemBufferCopy(Annot.code()));
 // FIXME: pass proper LangOptions.
+if (Annot.ranges().empty())
+  return syntax::tokenize(FID, *SourceMgr, LangOptions());
 return syntax::tokenize(
-SourceMgr->createFileID(llvm::MemoryBuffer::getMemBufferCopy(Text)),
+syntax::FileRange(FID, Annot.range().Begin, Annot.range().End),
 *SourceMgr, LangOptions());
   }
 
@@ -258,6 +264,20 @@
   ElementsAre(Kind(tok::kw_int),
   AllOf(HasText("a"), Kind(tok::identifier)),
   Kind(tok::semi)));
+  EXPECT_THAT(tokenize("int [[main() {]]}"),
+  ElementsAre(AllOf(HasText("main"), Kind(tok::identifier)),
+  Kind(tok::l_paren), Kind(tok::r_paren),
+  Kind(tok::l_brace)));
+  EXPECT_THAT(tokenize("int [[main() {   ]]}"),
+  ElementsAre(AllOf(HasText("main"), Kind(tok::identifier)),
+  Kind(tok::l_paren), Kind(tok::r_paren),
+  Kind(tok::l_brace)));
+  // First token is partially parsed, last token is fully included even though
+  // only a part of it is contained in the range.
+  EXPECT_THAT(tokenize("int m[[ain() {ret]]urn 0;}"),
+  ElementsAre(AllOf(HasText("ain"), Kind(tok::identifier)),
+  Kind(tok::l_paren), Kind(tok::r_paren),
+  Kind(tok::l_brace), Kind(tok::kw_return)));
 }
 
 TEST_F(TokenCollectorTest, Basic) {
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -67,7 +67,8 @@
   auto F = First.range(SM);
   auto L = Last.range(SM);
   assert(F.file() == L.file() && "tokens from different files");
-  assert((F == L || F.endOffset() <= L.beginOffset()) && "wrong order of tokens");
+  assert((F == L || F.endOffset() <= L.beginOffset()) &&
+ "wrong order of tokens");
   return FileRange(F.file(), F.beginOffset(), L.endOffset());
 }
 
@@ -307,7 +308,8 @@
   return Expansions;
 }
 
-std::vector syntax::tokenize(FileID FID, const SourceManager &SM,
+std::vector syntax::tokenize(const FileRange &FR,
+const SourceManager &SM,
 const LangOptions &LO) {
   std::vector Tokens;
   IdentifierTable Identifiers(LO);
@@ -322,18 +324,28 @@
 Tokens.push_back(syntax::Token(T));
   };
 
-  Lexer L(FID, SM.getBuffer(FID), SM, LO);
+  auto SrcBuffer = SM.getBufferData(FR.file());
+  Lexer L(SM.getLocForStartOfFile(FR.file()), LO, SrcBuffer.data(),
+  SrcBuffer.data() + FR.beginOffset(),
+  // We can't make BufEnd point to FR.endOffset, as Lexer requires a
+  // null terminated buffer.
+  SrcBuffer.data() + SrcBuffer.size());
 
   clang::Token T;
-  while (!L.LexFromRawLexer(T))
+  while (!L.LexFromRawLexer(T) && L.getCurrentBufferOffset() < FR.endOffset())
 AddToken(T);
-  // 'eof' is only the last token if the input is null-terminated. Never store
-  // it, for consistency.
-  if (T.getKind() != tok::eof)
+  // LexFromRawLexer returns true when it parses the last token of the file, add
+  // it iff it starts within the range we are interested in.
+  if (SM.getFileOffset(T.getLocation()) < FR.endOffset())
 AddToken(T);
   return Tokens;
 }
 
+std::vector syntax::tokenize(FileID FID, const SourceManager &SM,
+const LangOptions &LO) {
+  return tokenize(syntax::FileRange(FID, 0, SM.getFileIDSize(FID)), SM, LO);
+}
+
 /// Records information reqired to construct mappings for the token buffer that
 /// we are collecting.
 class TokenCollector::CollectPPExpansions : public PPCallbacks {
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/

[clang] e058667 - Support -fuse-ld=lld for riscv

2020-02-26 Thread via cfe-commits

Author: serge-sans-paille
Date: 2020-02-26T10:20:20+01:00
New Revision: e058667a2e017d3225a9bb067dbac7f2159576f7

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

LOG: Support -fuse-ld=lld for riscv

Add a configure feature test to filter out tests that explicitly depend on 
platform linker.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/RISCVToolchain.cpp
clang/test/Driver/riscv32-toolchain.c
clang/test/Driver/riscv64-toolchain.c
clang/test/lit.site.cfg.py.in

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index 24c2b37c4b77..21106d003859 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -142,7 +142,7 @@ void RISCV::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back("elf32lriscv");
   }
 
-  std::string Linker = getToolChain().GetProgramPath(getShortName());
+  std::string Linker = getToolChain().GetLinkerPath();
 
   bool WantCRTs =
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);

diff  --git a/clang/test/Driver/riscv32-toolchain.c 
b/clang/test/Driver/riscv32-toolchain.c
index 2ff3a585bda3..b83c9aafcbfc 100644
--- a/clang/test/Driver/riscv32-toolchain.c
+++ b/clang/test/Driver/riscv32-toolchain.c
@@ -1,8 +1,13 @@
 // A basic clang -cc1 command-line, and simple environment check.
+// REQUIRES: platform-linker
 
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv32 2>&1 | FileCheck 
-check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "riscv32"
 
+// Test interaction with -fuse-ld=lld, if lld is available.
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 -fuse-ld=lld 
2>&1 | FileCheck -check-prefix=LLD %s
+// LLD: {{(error: invalid linker name in argument '-fuse-ld=lld')|(ld.lld)}}
+
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
 

diff  --git a/clang/test/Driver/riscv64-toolchain.c 
b/clang/test/Driver/riscv64-toolchain.c
index 42cac51de59e..a5cfc1242db7 100644
--- a/clang/test/Driver/riscv64-toolchain.c
+++ b/clang/test/Driver/riscv64-toolchain.c
@@ -1,8 +1,13 @@
 // A basic clang -cc1 command-line, and simple environment check.
+// REQUIRES: platform-linker
 
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv64 2>&1 | FileCheck 
-check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "riscv64"
 
+// Test interaction with -fuse-ld=lld, if lld is available.
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 -fuse-ld=lld 
2>&1 | FileCheck -check-prefix=LLD %s
+// LLD: {{(error: invalid linker name in argument '-fuse-ld=lld')|(ld.lld)}}
+
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
 

diff  --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index e9b35ac01771..1f37ad935bd4 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -46,5 +46,8 @@ except KeyError:
 import lit.llvm
 lit.llvm.initialize(lit_config, config)
 
+if not "@CLANG_DEFAULT_LINKER@":
+config.available_features('platform-linker')
+
 # Let the main config do the real work.
 lit_config.load_config(config, "@CLANG_SOURCE_DIR@/test/lit.cfg.py")



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


[PATCH] D74704: Support -fuse-ld=lld for riscv

2020-02-26 Thread serge via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe058667a2e01: Support -fuse-ld=lld for riscv (authored by 
serge-sans-paille).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74704

Files:
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/test/Driver/riscv32-toolchain.c
  clang/test/Driver/riscv64-toolchain.c
  clang/test/lit.site.cfg.py.in


Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -46,5 +46,8 @@
 import lit.llvm
 lit.llvm.initialize(lit_config, config)
 
+if not "@CLANG_DEFAULT_LINKER@":
+config.available_features('platform-linker')
+
 # Let the main config do the real work.
 lit_config.load_config(config, "@CLANG_SOURCE_DIR@/test/lit.cfg.py")
Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -1,8 +1,13 @@
 // A basic clang -cc1 command-line, and simple environment check.
+// REQUIRES: platform-linker
 
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv64 2>&1 | FileCheck 
-check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "riscv64"
 
+// Test interaction with -fuse-ld=lld, if lld is available.
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 -fuse-ld=lld 
2>&1 | FileCheck -check-prefix=LLD %s
+// LLD: {{(error: invalid linker name in argument '-fuse-ld=lld')|(ld.lld)}}
+
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
 
Index: clang/test/Driver/riscv32-toolchain.c
===
--- clang/test/Driver/riscv32-toolchain.c
+++ clang/test/Driver/riscv32-toolchain.c
@@ -1,8 +1,13 @@
 // A basic clang -cc1 command-line, and simple environment check.
+// REQUIRES: platform-linker
 
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv32 2>&1 | FileCheck 
-check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "riscv32"
 
+// Test interaction with -fuse-ld=lld, if lld is available.
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 -fuse-ld=lld 
2>&1 | FileCheck -check-prefix=LLD %s
+// LLD: {{(error: invalid linker name in argument '-fuse-ld=lld')|(ld.lld)}}
+
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
 
Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -142,7 +142,7 @@
 CmdArgs.push_back("elf32lriscv");
   }
 
-  std::string Linker = getToolChain().GetProgramPath(getShortName());
+  std::string Linker = getToolChain().GetLinkerPath();
 
   bool WantCRTs =
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);


Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -46,5 +46,8 @@
 import lit.llvm
 lit.llvm.initialize(lit_config, config)
 
+if not "@CLANG_DEFAULT_LINKER@":
+config.available_features('platform-linker')
+
 # Let the main config do the real work.
 lit_config.load_config(config, "@CLANG_SOURCE_DIR@/test/lit.cfg.py")
Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -1,8 +1,13 @@
 // A basic clang -cc1 command-line, and simple environment check.
+// REQUIRES: platform-linker
 
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv64 2>&1 | FileCheck -check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "riscv64"
 
+// Test interaction with -fuse-ld=lld, if lld is available.
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 -fuse-ld=lld 2>&1 | FileCheck -check-prefix=LLD %s
+// LLD: {{(error: invalid linker name in argument '-fuse-ld=lld')|(ld.lld)}}
+
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
 
Index: clang/test/Driver/riscv32-toolchain.c
===
--- clang/test/Driver/riscv32-toolchain.c
+++ clang/test/Driver/riscv32-toolchain.c
@@ -1,8 +1,13 @@
 // A basic clang -cc1 command-line, and simple environment check.
+// REQUIRES: platform-linker
 
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv32 2>&1 | FileCheck 

[PATCH] D74871: Fix interaction between -fdiscard-value-names and LLVM Bitcode

2020-02-26 Thread serge via Phabricator via cfe-commits
serge-sans-paille abandoned this revision.
serge-sans-paille added a comment.

Obsoleted by https://reviews.llvm.org/D74878


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74871



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


[clang] 19c664f - Fix typo in clang lit config

2020-02-26 Thread via cfe-commits

Author: serge-sans-paille
Date: 2020-02-26T10:37:04+01:00
New Revision: 19c664f71e887111298e49e416511f8be7b2b15f

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

LOG: Fix typo in clang lit config

Typo introduced in e058667a2e017d3225a9bb067dbac7f2159576f7

Added: 


Modified: 
clang/test/lit.site.cfg.py.in

Removed: 




diff  --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index 1f37ad935bd4..39c8b47adf92 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -47,7 +47,7 @@ import lit.llvm
 lit.llvm.initialize(lit_config, config)
 
 if not "@CLANG_DEFAULT_LINKER@":
-config.available_features('platform-linker')
+config.available_features.add('platform-linker')
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@CLANG_SOURCE_DIR@/test/lit.cfg.py")



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


[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

2020-02-26 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/AST/DependencyFlags.h:57
+  struct NAME##Scope { 
\
+enum NAME {
\
+  UnexpandedPack = 1,  
\

should we make the enum as `uint8_t`  as the other `ExprDependence` above?



Comment at: clang/include/clang/AST/DependencyFlags.h:81
+  auto E =
+  static_cast(TA & ~TemplateArgumentDependence::Dependent);
+  if (TA & TemplateArgumentDependence::Dependent)

nit: I think we can get rid of the `static_cast`, sine we already use 
`LLVM_MARK_AS_BITMASK_ENUM`.



Comment at: clang/include/clang/AST/Type.h:1468
 
-/// Whether this type is a dependent type (C++ [temp.dep.type]).
-unsigned Dependent : 1;

would be nice to keep this comments in the new `TypeDependence` struct.



Comment at: clang/lib/AST/TemplateName.cpp:173
+TemplateNameDependence TemplateName::getDependence() const {
+  auto F = TemplateNameDependence::None;
+  if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) {

This part of refactoring seems a little scary to me,  I think it is correct by 
comparing with the previous version. but the getDependence() now is very 
**complicated**, I have no idea what it is doing.

instead of merging three different non-trivial if branches into a single 
function, maybe keep them as it-is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920



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


[PATCH] D75134: [clang-tidy] Improved renamer check logic

2020-02-26 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 246650.
njames93 added a comment.

- Changed naming to what appears to be llvm python style


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75134

Files:
  clang-tools-extra/clang-tidy/add_new_check.py
  clang-tools-extra/clang-tidy/rename_check.py
  clang-tools-extra/clang-tidy/utils/__init__.py
  clang-tools-extra/clang-tidy/utils/modify_check.py

Index: clang-tools-extra/clang-tidy/utils/modify_check.py
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/utils/modify_check.py
@@ -0,0 +1,159 @@
+#!/usr/bin/env python
+#
+# ===- modify_check.py - clang-tidy check generator --*- python -*--===#
+#
+# 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
+#
+# ===---===#
+
+import os
+import re
+
+
+def get_camel_name(check_name):
+  return ''.join(map(lambda elem: elem.capitalize(),
+ check_name.split('-'))) + 'Check'
+
+
+# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
+# and 'False' if the entry already existed.
+def adapt_cmake(module_path, check_name_camel):
+  filename = os.path.join(module_path, 'CMakeLists.txt')
+  with open(filename, 'r') as f:
+lines = f.readlines()
+
+  cpp_file = check_name_camel + '.cpp'
+
+  # Figure out whether this check already exists.
+  for line in lines:
+if line.strip() == cpp_file:
+  return False
+
+  print('Updating %s...' % filename)
+  with open(filename, 'w') as f:
+cpp_found = False
+file_added = False
+for line in lines:
+  cpp_line = line.strip().endswith('.cpp')
+  if (not file_added) and (cpp_line or cpp_found):
+cpp_found = True
+if (line.strip() > cpp_file) or (not cpp_line):
+  f.write('  ' + cpp_file + '\n')
+  file_added = True
+  f.write(line)
+
+  return True
+
+
+# Recreates the list of checks in the docs/clang-tidy/checks directory.
+def update_checks_list(clang_tidy_path):
+  docs_dir = os.path.join(clang_tidy_path, '../docs/clang-tidy/checks')
+  filename = os.path.normpath(os.path.join(docs_dir, 'list.rst'))
+  # Read the content of the current list.rst file
+  with open(filename, 'r') as f:
+lies = f.readlines()
+  # Get all existing docs
+  doc_files = list(
+  filter(lambda s: s.endswith('.rst') and s != 'list.rst',
+ os.listdir(docs_dir)))
+  doc_files.sort()
+
+  def has_autofix(check_name):
+dir_name, _, check_name = check_name.partition("-")
+
+checker_code = os.path.join(dir_name, get_camel_name(check_name)) + ".cpp"
+
+if not os.path.isfile(checker_code):
+  return ""
+
+with open(checker_code) as f:
+  code = f.read()
+  if 'FixItHint' in code or "ReplacementText" in code or "fixit" in code:
+# Some simple heuristics to figure out if a checker has an autofix.
+return ' "Yes"'
+return ""
+
+  def process_doc(doc_file):
+check_name = doc_file.replace('.rst', '')
+
+with open(os.path.join(docs_dir, doc_file), 'r') as doc:
+  content = doc.read()
+  match = re.search('.*:orphan:.*', content)
+
+  if match:
+# Orphan page, don't list it.
+return '', ''
+
+  match = re.search(r'.*:http-equiv=refresh: \d+;URL=(.*).html.*', content)
+  # Is it a redirect?
+  return check_name, match
+
+  def format_link(doc_file):
+check_name, match = process_doc(doc_file)
+if not match and check_name:
+  return '   `%(check)s <%(check)s.html>`_,%(autofix)s\n' % {
+  'check': check_name,
+  'autofix': has_autofix(check_name)
+  }
+else:
+  return ''
+
+  def format_link_alias(doc_file):
+check_name, match = process_doc(doc_file)
+if match and check_name:
+  if match.group(1) == 'https://clang.llvm.org/docs/analyzer/checkers':
+title_redirect = 'Clang Static Analyzer'
+  else:
+title_redirect = match.group(1)
+  # The checker is just a redirect.
+  return '   `%(check)s <%(check)s.html>`_, \
+`%(title)s <%(target)s.html>`_,%(autofix)s\n' % {
+  'check': check_name,
+  'target': match.group(1),
+  'title': title_redirect,
+  'autofix': has_autofix(match.group(1))
+  }
+return ''
+
+  checks = map(format_link, doc_files)
+  checks_alias = map(format_link_alias, doc_files)
+
+  print('Updating %s...' % filename)
+  with open(filename, 'w') as f:
+for line in lies:
+  f.write(line)
+  if line.strip() == ".. csv-table::":
+# We dump the checkers
+f.write('   :header: "Name", "Offers fixes"\n\n')
+f.writelines(checks)
+# and the aliases
+f.write('\n\n')
+f.writ

[PATCH] D75158: [analyzer][StreamChecker] Using function description objects - NFC.

2020-02-26 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added reviewers: baloghadamsoftware, NoQ, martong, Charusso, 
xazax.hun.
Szelethus added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: rnkovacs.

Cool! Though this patch says little without followups, so maybe we should see 
how those look like before commiting? :) I don't insist.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75158



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


[PATCH] D75134: [clang-tidy] Improved renamer check logic

2020-02-26 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 246653.
njames93 added a comment.

- Moved shared code into __init__


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75134

Files:
  clang-tools-extra/clang-tidy/add_new_check.py
  clang-tools-extra/clang-tidy/rename_check.py
  clang-tools-extra/clang-tidy/utils/__init__.py

Index: clang-tools-extra/clang-tidy/utils/__init__.py
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/utils/__init__.py
@@ -0,0 +1,159 @@
+#!/usr/bin/env python
+#
+# ===- __init__.py - clang-tidy check generator utils *- python -*--===#
+#
+# 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
+#
+# ===---===#
+
+import os
+import re
+
+
+def get_camel_name(check_name):
+  return ''.join(map(lambda elem: elem.capitalize(),
+ check_name.split('-'))) + 'Check'
+
+
+# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
+# and 'False' if the entry already existed.
+def adapt_cmake(module_path, check_name_camel):
+  filename = os.path.join(module_path, 'CMakeLists.txt')
+  with open(filename, 'r') as f:
+lines = f.readlines()
+
+  cpp_file = check_name_camel + '.cpp'
+
+  # Figure out whether this check already exists.
+  for line in lines:
+if line.strip() == cpp_file:
+  return False
+
+  print('Updating %s...' % filename)
+  with open(filename, 'w') as f:
+cpp_found = False
+file_added = False
+for line in lines:
+  cpp_line = line.strip().endswith('.cpp')
+  if (not file_added) and (cpp_line or cpp_found):
+cpp_found = True
+if (line.strip() > cpp_file) or (not cpp_line):
+  f.write('  ' + cpp_file + '\n')
+  file_added = True
+  f.write(line)
+
+  return True
+
+
+# Recreates the list of checks in the docs/clang-tidy/checks directory.
+def update_checks_list(clang_tidy_path):
+  docs_dir = os.path.join(clang_tidy_path, '../docs/clang-tidy/checks')
+  filename = os.path.normpath(os.path.join(docs_dir, 'list.rst'))
+  # Read the content of the current list.rst file
+  with open(filename, 'r') as f:
+lies = f.readlines()
+  # Get all existing docs
+  doc_files = list(
+  filter(lambda s: s.endswith('.rst') and s != 'list.rst',
+ os.listdir(docs_dir)))
+  doc_files.sort()
+
+  def has_autofix(check_name):
+dir_name, _, check_name = check_name.partition("-")
+
+checker_code = os.path.join(dir_name, get_camel_name(check_name)) + ".cpp"
+
+if not os.path.isfile(checker_code):
+  return ""
+
+with open(checker_code) as f:
+  code = f.read()
+  if 'FixItHint' in code or "ReplacementText" in code or "fixit" in code:
+# Some simple heuristics to figure out if a checker has an autofix.
+return ' "Yes"'
+return ""
+
+  def process_doc(doc_file):
+check_name = doc_file.replace('.rst', '')
+
+with open(os.path.join(docs_dir, doc_file), 'r') as doc:
+  content = doc.read()
+  match = re.search('.*:orphan:.*', content)
+
+  if match:
+# Orphan page, don't list it.
+return '', ''
+
+  match = re.search(r'.*:http-equiv=refresh: \d+;URL=(.*).html.*', content)
+  # Is it a redirect?
+  return check_name, match
+
+  def format_link(doc_file):
+check_name, match = process_doc(doc_file)
+if not match and check_name:
+  return '   `%(check)s <%(check)s.html>`_,%(autofix)s\n' % {
+  'check': check_name,
+  'autofix': has_autofix(check_name)
+  }
+else:
+  return ''
+
+  def format_link_alias(doc_file):
+check_name, match = process_doc(doc_file)
+if match and check_name:
+  if match.group(1) == 'https://clang.llvm.org/docs/analyzer/checkers':
+title_redirect = 'Clang Static Analyzer'
+  else:
+title_redirect = match.group(1)
+  # The checker is just a redirect.
+  return '   `%(check)s <%(check)s.html>`_, \
+`%(title)s <%(target)s.html>`_,%(autofix)s\n' % {
+  'check': check_name,
+  'target': match.group(1),
+  'title': title_redirect,
+  'autofix': has_autofix(match.group(1))
+  }
+return ''
+
+  checks = map(format_link, doc_files)
+  checks_alias = map(format_link_alias, doc_files)
+
+  print('Updating %s...' % filename)
+  with open(filename, 'w') as f:
+for line in lies:
+  f.write(line)
+  if line.strip() == ".. csv-table::":
+# We dump the checkers
+f.write('   :header: "Name", "Offers fixes"\n\n')
+f.writelines(checks)
+# and the aliases
+f.write('\n\n')
+f.write('.. csv-table:: Aliases..\n')
+f.write('   :header: "Name", "Redirect", "O

[PATCH] D75159: [clang-tidy] Fix PR#37210 'Out-of-class template constructor only half-fixed with modernize-pass-by-value'

2020-02-26 Thread Karasev Nikita via Phabricator via cfe-commits
f00kat created this revision.
f00kat added reviewers: aaron.ballman, alexfh.
f00kat added projects: clang, clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.

Existing 'modernize-pass-by-value' check works only with non template values in 
initializers.
Now we also skip cases when the value has type 'TemplateSpecializedType' inside 
'cxxConstructExpr'.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75159

Files:
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp
@@ -118,6 +118,26 @@
 J j1(Movable());
 J j2(NotMovable());
 
+template
+struct MovableTemplateT
+{
+  MovableTemplateT() {}
+  MovableTemplateT(const MovableTemplateT& o) { }
+  MovableTemplateT(MovableTemplateT&& o) { }
+};
+
+template 
+struct J2 {
+  J2(const MovableTemplateT& A);
+  // CHECK-FIXES: J2(const MovableTemplateT& A);
+  MovableTemplateT M;
+};
+
+template 
+J2::J2(const MovableTemplateT& A) : M(A) {}
+// CHECK-FIXES: J2::J2(const MovableTemplateT& A) : M(A) {}
+J2 j3(MovableTemplateT{});
+
 struct K_Movable {
   K_Movable() = default;
   K_Movable(const K_Movable &) = default;
Index: clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -46,8 +46,9 @@
 }
 } // namespace
 
-static TypeMatcher constRefType() {
-  return lValueReferenceType(pointee(isConstQualified()));
+static TypeMatcher notTemplateSpecConstRefType() {
+  return lValueReferenceType(
+  pointee(unless(templateSpecializationType()), isConstQualified()));
 }
 
 static TypeMatcher nonConstValueType() {
@@ -145,16 +146,18 @@
   // ParenListExpr is generated instead of a CXXConstructExpr,
   // filtering out templates automatically for us.
   withInitializer(cxxConstructExpr(
-  has(ignoringParenImpCasts(declRefExpr(to(
-  parmVarDecl(
-  hasType(qualType(
-  // Match only const-ref or a non-const value
-  // parameters. Rvalues and const-values
-  // shouldn't be modified.
-  ValuesOnly ? nonConstValueType()
- : anyOf(constRefType(),
- nonConstValueType()
-  .bind("Param"),
+  has(ignoringParenImpCasts(declRefExpr(
+  to(parmVarDecl(
+ hasType(qualType(
+ // Match only const-ref or a non-const
+ // value parameters. Rvalues,
+ // TemplateSpecializationValues and
+ // const-values shouldn't be modified.
+ ValuesOnly
+ ? nonConstValueType()
+ : anyOf(notTemplateSpecConstRefType(),
+ nonConstValueType()
+ .bind("Param"),
   hasDeclaration(cxxConstructorDecl(
   isCopyConstructor(), unless(isDeleted()),
   hasDeclContext(


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp
@@ -118,6 +118,26 @@
 J j1(Movable());
 J j2(NotMovable());
 
+template
+struct MovableTemplateT
+{
+  MovableTemplateT() {}
+  MovableTemplateT(const MovableTemplateT& o) { }
+  MovableTemplateT(MovableTemplateT&& o) { }
+};
+
+template 
+struct J2 {
+  J2(const MovableTemplateT& A);
+  // CHECK-FIXES: J2(const MovableTemplateT& A);
+  MovableTemplateT M;
+};
+
+template 
+J2::J2(const MovableTemplateT& A) : M(A) {}
+// CHECK-FIXES: J2::J2(const MovableTemplateT& A) : M(A) {}
+J2 j3(MovableTemplateT{});
+
 struct K_Movable {
   K_Movable() = default;
   K_Movable(const K_Movable &) = default;
Index: clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ 

[PATCH] D75160: [AArch64][SVE] Add SVE2 intrinsic for xar

2020-02-26 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin created this revision.
kmclaughlin added reviewers: andwar, c-rhodes, dancgr, efriedma.
Herald added subscribers: psnobl, rkruppe, hiraditya, kristof.beyls, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: LLVM.

Implements the @llvm.aarch64.sve.xar intrinsic


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75160

Files:
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/lib/Target/AArch64/SVEInstrFormats.td
  llvm/test/CodeGen/AArch64/sve2-bitwise-ternary.ll

Index: llvm/test/CodeGen/AArch64/sve2-bitwise-ternary.ll
===
--- llvm/test/CodeGen/AArch64/sve2-bitwise-ternary.ll
+++ llvm/test/CodeGen/AArch64/sve2-bitwise-ternary.ll
@@ -258,6 +258,50 @@
   ret  %res
 }
 
+;
+; XAR (vector, bitwise, unpredicated)
+;
+
+define  @xar_b( %a,  %b) {
+; CHECK-LABEL: xar_b:
+; CHECK: xar z0.b, z0.b, z1.b, #1
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.xar.nxv16i8( %a,
+%b,
+   i32 1)
+  ret  %out
+}
+
+define  @xar_h( %a,  %b) {
+; CHECK-LABEL: xar_h:
+; CHECK: xar z0.h, z0.h, z1.h, #2
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.xar.nxv8i16( %a,
+%b,
+   i32 2)
+  ret  %out
+}
+
+define  @xar_s( %a,  %b) {
+; CHECK-LABEL: xar_s:
+; CHECK: xar z0.s, z0.s, z1.s, #3
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.xar.nxv4i32( %a,
+%b,
+   i32 3)
+  ret  %out
+}
+
+define  @xar_d( %a,  %b) {
+; CHECK-LABEL: xar_d:
+; CHECK: xar z0.d, z0.d, z1.d, #4
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.xar.nxv2i64( %a,
+%b,
+   i32 4)
+  ret  %out
+}
+
 declare  @llvm.aarch64.sve.eor3.nxv16i8(,,)
 declare  @llvm.aarch64.sve.eor3.nxv8i16(,,)
 declare  @llvm.aarch64.sve.eor3.nxv4i32(,,)
@@ -282,3 +326,7 @@
 declare  @llvm.aarch64.sve.nbsl.nxv8i16(,,)
 declare  @llvm.aarch64.sve.nbsl.nxv4i32(,,)
 declare  @llvm.aarch64.sve.nbsl.nxv2i64(,,)
+declare  @llvm.aarch64.sve.xar.nxv16i8(, , i32)
+declare  @llvm.aarch64.sve.xar.nxv8i16(, , i32)
+declare  @llvm.aarch64.sve.xar.nxv4i32(, , i32)
+declare  @llvm.aarch64.sve.xar.nxv2i64(, , i32)
Index: llvm/lib/Target/AArch64/SVEInstrFormats.td
===
--- llvm/lib/Target/AArch64/SVEInstrFormats.td
+++ llvm/lib/Target/AArch64/SVEInstrFormats.td
@@ -3878,7 +3878,7 @@
   let ElementSize = ElementSizeNone;
 }
 
-multiclass sve2_int_rotate_right_imm {
+multiclass sve2_int_rotate_right_imm {
   def _B : sve2_int_rotate_right_imm<{0,0,0,1}, asm, ZPR8, vecshiftR8>;
   def _H : sve2_int_rotate_right_imm<{0,0,1,?}, asm, ZPR16, vecshiftR16> {
 let Inst{19} = imm{3};
@@ -3890,6 +3890,10 @@
 let Inst{22}= imm{5};
 let Inst{20-19} = imm{4-3};
   }
+  def : SVE_3_Op_Imm_Pat(NAME # _B)>;
+  def : SVE_3_Op_Imm_Pat(NAME # _H)>;
+  def : SVE_3_Op_Imm_Pat(NAME # _S)>;
+  def : SVE_3_Op_Imm_Pat(NAME # _D)>;
 }
 
 //===--===//
Index: llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
===
--- llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
+++ llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
@@ -1862,7 +1862,7 @@
   defm NBSL_  : sve2_int_bitwise_ternary_op<0b111, "nbsl",  int_aarch64_sve_nbsl>;
 
   // SVE2 bitwise xor and rotate right by immediate
-  defm XAR_ZZZI : sve2_int_rotate_right_imm<"xar">;
+  defm XAR_ZZZI : sve2_int_rotate_right_imm<"xar", int_aarch64_sve_xar>;
 
   // SVE2 extract vector (immediate offset, constructive)
   def EXT_ZZI_B : sve2_int_perm_extract_i_cons<"ext">;
Index: llvm/include/llvm/IR/IntrinsicsAArch64.td
===
--- llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -2021,13 +2021,16 @@
 def int_aarch64_sve_pmullb_pair : AdvSIMD_2VectorArg_Intrinsic;
 def int_aarch64_sve_pmullt_pair : AdvSIMD_2VectorArg_Intrinsic;
 
+//
 // SVE2 bitwise ternary operations.
+//
 def int_aarch64_sve_eor3   : AdvSIMD_3VectorArg_Intrinsic;
 def int_aarch64_sve_bcax   : AdvSIMD_3VectorArg_Intrinsic;
 def int_aarch64_sve_bsl: AdvSIMD_3VectorArg_Intrinsic;
 def int_aarch64_sve_bsl1n  : AdvSIMD_3VectorArg_Intrinsic;
 def int_aarch64_sve_bsl2n  : AdvSIMD_3VectorArg_Intrinsic;
 def int_aarch64_sve_nbsl   : AdvSIMD_3VectorArg_Intrinsic;
+def int_aarch64_sve_xar: AdvSIMD_2VectorArgIndexed_Intrinsic;
 
 //
 // SVE2 - Optional AES, SHA-

[PATCH] D74878: [remark][diagnostics] [codegen] Fix PR44896

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

Thanks! Cherry-picked to 10.x as 6f4f4f2c8ce1ad17bdec9fe2071d3fe439eca9eb 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74878



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


[PATCH] D74912: [AArch64][SVE] Add SVE2 intrinsics for bit permutation & table lookup

2020-02-26 Thread Kerry McLaughlin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9c859fc54d92: [AArch64][SVE] Add SVE2 intrinsics for bit 
permutation & table lookup (authored by kmclaughlin).

Changed prior to commit:
  https://reviews.llvm.org/D74912?vs=246487&id=246661#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74912

Files:
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/lib/Target/AArch64/SVEInstrFormats.td
  llvm/test/CodeGen/AArch64/sve2-intrinsics-bit-permutation.ll
  llvm/test/CodeGen/AArch64/sve2-intrinsics-perm-tb.ll

Index: llvm/test/CodeGen/AArch64/sve2-intrinsics-perm-tb.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sve2-intrinsics-perm-tb.ll
@@ -0,0 +1,181 @@
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve2 < %s | FileCheck %s
+
+;
+; TBL2
+;
+
+define  @tbl2_b( %a,  %unused,
+   %b,  %c) {
+; CHECK-LABEL: tbl2_b:
+; CHECK: mov z1.d, z0.d
+; CHECK-NEXT: tbl z0.b, { z1.b, z2.b }, z3.b
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbl2.nxv16i8( %a,
+ %b,
+ %c)
+  ret  %out
+}
+
+define  @tbl2_h( %a,  %unused,
+   %b,  %c) {
+; CHECK-LABEL: tbl2_h:
+; CHECK: mov z1.d, z0.d
+; CHECK-NEXT: tbl z0.h, { z1.h, z2.h }, z3.h
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbl2.nxv8i16( %a,
+ %b,
+ %c)
+  ret  %out
+}
+
+define  @tbl2_s( %a,  %unused,
+   %b,  %c) {
+; CHECK-LABEL: tbl2_s:
+; CHECK: mov z1.d, z0.d
+; CHECK-NEXT: tbl z0.s, { z1.s, z2.s }, z3.s
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbl2.nxv4i32( %a,
+ %b,
+ %c)
+  ret  %out
+}
+
+define  @tbl2_d( %a,  %unused,
+   %b,  %c) {
+; CHECK-LABEL: tbl2_d:
+; CHECK: mov z1.d, z0.d
+; CHECK-NEXT: tbl z0.d, { z1.d, z2.d }, z3.d
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbl2.nxv2i64( %a,
+ %b,
+ %c)
+  ret  %out
+}
+
+define  @tbl2_fh( %a,  %unused,
+ %b,  %c) {
+; CHECK-LABEL: tbl2_fh:
+; CHECK: mov z1.d, z0.d
+; CHECK-NEXT: tbl z0.h, { z1.h, z2.h }, z3.h
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbl2.nxv8f16( %a,
+  %b,
+  %c)
+  ret  %out
+}
+
+define  @tbl2_fs( %a,  %unused,
+  %b,  %c) {
+; CHECK-LABEL: tbl2_fs:
+; CHECK: mov z1.d, z0.d
+; CHECK-NEXT: tbl z0.s, { z1.s, z2.s }, z3.s
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbl2.nxv4f32( %a,
+   %b,
+   %c)
+  ret  %out
+}
+
+define  @tbl2_fd( %a,  %unused,
+   %b,  %c) {
+; CHECK-LABEL: tbl2_fd:
+; CHECK: mov z1.d, z0.d
+; CHECK-NEXT: tbl z0.d, { z1.d, z2.d }, z3.d
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbl2.nxv2f64( %a,
+%b,
+%c)
+  ret  %out
+}
+
+;
+; TBX
+;
+
+define  @tbx_b( %a,  %b,  %c) {
+; CHECK-LABEL: tbx_b:
+; CHECK: tbx z0.b, z1.b, z2.b
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbx.nxv16i8( %a,
+%b,
+%c)
+  ret  %out
+}
+
+define  @tbx_h( %a,  %b,  %c) {
+; CHECK-LABEL: tbx_h:
+; CHECK: tbx z0.h, z1.h, z2.h
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbx.nxv8i16( %a,
+%b,
+%c)
+  ret  %out
+}
+
+define  @ftbx_h( %a,  %b,  %c) {
+; CHECK-LABEL: ftbx_h:
+; CHECK: tbx z0.h, z1.h, z2.h
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbx.nxv8f16( %a,
+ %b,
+ %c)
+  ret  %out
+}
+
+define  @tbx_s( %a,  %b,  %c) {
+; CHECK-LABEL: tbx_s:
+; CHECK: tbx z0.s, z1.s, z2.s
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.tbx.nxv4i32( %a,
+

[PATCH] D75125: [Docs][OpenCL] Release 10.0 notes for OpenCL

2020-02-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:293
+- Allowed ``__private`` to be printed explicitly in diagnostics, AST, etc 
+- Fixed declaration of ``enqueue_marker``, c11 atomic fetch max/min in the
+  standard header.

Suggesting to move this item into the new section I suggested below.



Comment at: clang/docs/ReleaseNotes.rst:305
+- Added support for function attributes.
+FIXME: Add a sentence explaining current state?
+

Anastasia wrote:
> @svenvh Do you think we should add a sentence to summarize what is the 
> current situation with this in rel 10?
Maybe rewrite the whole section (starting from "Changes to builtin-function 
inclusion with TableGen") as follows:

```
OpenCL builtin functions:
- The majority of the OpenCL builtin functions are now available through the 
experimental `-fdeclare-opencl-builtins` option.
- Align the `enqueue_marker` declaration in `opencl-c.h` to the OpenCL spec.
- Avoid a void pointer cast in the `CLK_NULL_EVENT` definition.
```


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

https://reviews.llvm.org/D75125



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


[PATCH] D74912: [AArch64][SVE] Add SVE2 intrinsics for bit permutation & table lookup

2020-02-26 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin added a comment.

Thanks for reviewing this, @sdesmalen & @efriedma!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74912



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


[PATCH] D75162: [X86][F16C] Remove cvtph2ps intrinsics and use generic half2float conversion (PR37554)

2020-02-26 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon created this revision.
RKSimon added reviewers: craig.topper, spatel.
Herald added subscribers: cfe-commits, hiraditya.
Herald added projects: clang, LLVM.

This removes everything but int_x86_avx512_mask_vcvtph2ps_512 which provides 
the SAE variant, but even this can use the fpext generic if the rounding 
control is the default.

I have a new f16c-intrinsics-upgrade.ll file as well but for some reason git 
diff is going weird when I try to include it, basically all the ph2ps tests are 
cut+paste from f16c-intrinsics.ll


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75162

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/avx512f-builtins.c
  clang/test/CodeGen/avx512vl-builtins.c
  clang/test/CodeGen/f16c-builtins.c
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/X86/X86IntrinsicsInfo.h
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/CodeGen/X86/avx512-intrinsics-fast-isel.ll
  llvm/test/CodeGen/X86/avx512-intrinsics-upgrade.ll
  llvm/test/CodeGen/X86/avx512-intrinsics.ll
  llvm/test/CodeGen/X86/avx512vl-intrinsics-fast-isel.ll
  llvm/test/CodeGen/X86/avx512vl-intrinsics-upgrade.ll
  llvm/test/CodeGen/X86/avx512vl-intrinsics.ll
  llvm/test/CodeGen/X86/f16c-intrinsics-fast-isel.ll
  llvm/test/Transforms/InstCombine/X86/x86-f16c.ll

Index: llvm/test/Transforms/InstCombine/X86/x86-f16c.ll
===
--- llvm/test/Transforms/InstCombine/X86/x86-f16c.ll
+++ llvm/test/Transforms/InstCombine/X86/x86-f16c.ll
@@ -5,14 +5,16 @@
 declare <8 x float> @llvm.x86.vcvtph2ps.256(<8 x i16>)
 
 ;
-; Vector Demanded Bits
+; Vector Demanded Elts
 ;
 
 ; Only bottom 4 elements required.
 define <4 x float> @demand_vcvtph2ps_128(<8 x i16> %A) {
 ; CHECK-LABEL: @demand_vcvtph2ps_128(
-; CHECK-NEXT:[[TMP1:%.*]] = tail call <4 x float> @llvm.x86.vcvtph2ps.128(<8 x i16> [[A:%.*]])
-; CHECK-NEXT:ret <4 x float> [[TMP1]]
+; CHECK-NEXT:[[TMP1:%.*]] = shufflevector <8 x i16> [[A:%.*]], <8 x i16> undef, <4 x i32> 
+; CHECK-NEXT:[[TMP2:%.*]] = bitcast <4 x i16> [[TMP1]] to <4 x half>
+; CHECK-NEXT:[[CVTPH2PS:%.*]] = fpext <4 x half> [[TMP2]] to <4 x float>
+; CHECK-NEXT:ret <4 x float> [[CVTPH2PS]]
 ;
   %1 = shufflevector <8 x i16> %A, <8 x i16> undef, <8 x i32> 
   %2 = tail call <4 x float> @llvm.x86.vcvtph2ps.128(<8 x i16> %1)
@@ -23,8 +25,9 @@
 define <8 x float> @demand_vcvtph2ps_256(<8 x i16> %A) {
 ; CHECK-LABEL: @demand_vcvtph2ps_256(
 ; CHECK-NEXT:[[TMP1:%.*]] = shufflevector <8 x i16> [[A:%.*]], <8 x i16> undef, <8 x i32> 
-; CHECK-NEXT:[[TMP2:%.*]] = tail call <8 x float> @llvm.x86.vcvtph2ps.256(<8 x i16> [[TMP1]])
-; CHECK-NEXT:ret <8 x float> [[TMP2]]
+; CHECK-NEXT:[[TMP2:%.*]] = bitcast <8 x i16> [[TMP1]] to <8 x half>
+; CHECK-NEXT:[[CVTPH2PS:%.*]] = fpext <8 x half> [[TMP2]] to <8 x float>
+; CHECK-NEXT:ret <8 x float> [[CVTPH2PS]]
 ;
   %1 = shufflevector <8 x i16> %A, <8 x i16> undef, <8 x i32> 
   %2 = tail call <8 x float> @llvm.x86.vcvtph2ps.256(<8 x i16> %1)
Index: llvm/test/CodeGen/X86/f16c-intrinsics-fast-isel.ll
===
--- llvm/test/CodeGen/X86/f16c-intrinsics-fast-isel.ll
+++ llvm/test/CodeGen/X86/f16c-intrinsics-fast-isel.ll
@@ -30,7 +30,9 @@
   %ins5 = insertelement <8 x i16> %ins4, i16 0, i32 5
   %ins6 = insertelement <8 x i16> %ins5, i16 0, i32 6
   %ins7 = insertelement <8 x i16> %ins6, i16 0, i32 7
-  %cvt = call <4 x float> @llvm.x86.vcvtph2ps.128(<8 x i16> %ins7)
+  %shuffle = shufflevector <8 x i16> %ins7, <8 x i16> undef, <4 x i32> 
+  %bc = bitcast <4 x i16> %shuffle to <4 x half>
+  %cvt = fpext <4 x half> %bc to <4 x float>
   %res = extractelement <4 x float> %cvt, i32 0
   ret float %res
 }
@@ -74,7 +76,9 @@
 ; X64-NEXT:vcvtph2ps %xmm0, %xmm0
 ; X64-NEXT:retq
   %arg0 = bitcast <2 x i64> %a0 to <8 x i16>
-  %res = call <4 x float> @llvm.x86.vcvtph2ps.128(<8 x i16> %arg0)
+  %shuffle = shufflevector <8 x i16> %arg0, <8 x i16> undef, <4 x i32> 
+  %bc = bitcast <4 x i16> %shuffle to <4 x half>
+  %res = fpext <4 x half> %bc to <4 x float>
   ret <4 x float> %res
 }
 
@@ -89,7 +93,8 @@
 ; X64-NEXT:vcvtph2ps %xmm0, %ymm0
 ; X64-NEXT:retq
   %arg0 = bitcast <2 x i64> %a0 to <8 x i16>
-  %res = call <8 x float> @llvm.x86.vcvtph2ps.256(<8 x i16> %arg0)
+  %bc = bitcast <8 x i16> %arg0 to <8 x half>
+  %res = fpext <8 x half> %bc to <8 x float>
   ret <8 x float> %res
 }
 
Index: llvm/test/CodeGen/X86/avx512vl-intrinsics.ll
===
--- llvm/test/CodeGen/X86/avx512vl-intrinsics.ll
+++ llvm/test/CodeGen/X86/avx512vl-intrinsics.ll
@@ -4214,101 +4214,6 @@
   ret <4 x i64> %res2
 }
 
-define <4 x float> @test_x86_vcvtph2ps_128(<8 x i16> %a0) {
-; CHECK-LABEL: test_x86_vcvtph2ps_128:
-; CHECK:   # %bb.0:
-; CHECK-NEXT:vcvtph2ps %xmm0, %xmm0 # EVEX TO VEX Compression

[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

2020-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, martong, Charusso, gamesh411, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: clang.

The validity checks are performed in precall callback.

Semantic of checking for opened stream has changed:
It is not allowed at all to use the stream after 'fclose'.
This is what cppreference.com says at fclose.
So the double-close error changes to use-after-close.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75163

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -34,7 +34,7 @@
 
   bool isOpened() const { return K == Opened; }
   bool isClosed() const { return K == Closed; }
-  //bool isOpenFailed() const { return K == OpenFailed; }
+  bool isOpenFailed() const { return K == OpenFailed; }
   //bool isEscaped() const { return K == Escaped; }
 
   bool operator==(const StreamState &X) const { return K == X.K; }
@@ -50,66 +50,77 @@
 };
 
 class StreamChecker;
-
-using FnCheck = std::function;
 
 struct FnDescription {
+  FnCheck PreFn;
   FnCheck EvalFn;
+  unsigned int StreamArgI;
 };
 
-class StreamChecker : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
-  BT_doubleclose, BT_ResourceLeak;
+  BT_UseAfterClose, BT_UseAfterOpenFailed, BT_ResourceLeak;
 
 public:
+  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
 
 private:
 
   CallDescriptionMap FnDescriptions = {
-  {{"fopen"}, {&StreamChecker::evalFopen}},
-  {{"freopen", 3}, {&StreamChecker::evalFreopen}},
-  {{"tmpfile"}, {&StreamChecker::evalFopen}},
-  {{"fclose", 1}, {&StreamChecker::evalFclose}},
-  {{"fread", 4},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
-  {{"fwrite", 4},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
-  {{"fseek", 3}, {&StreamChecker::evalFseek}},
-  {{"ftell", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"rewind", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"fgetpos", 2},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"fsetpos", 2},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"clearerr", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"feof", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"ferror", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"fileno", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
+  {{"fopen"}, {{}, &StreamChecker::evalFopen, -1}},
+  {{"freopen", 3}, {&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}},
+  {{"tmpfile"}, {{}, &StreamChecker::evalFopen, -1}},
+  {{"fclose", 1}, {&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}},
+  {{"fread", 4}, {&StreamChecker::preDefault, {}, 3}},
+  {{"fwrite", 4}, {&StreamChecker::preDefault, {}, 3}},
+  {{"fseek", 3}, {&StreamChecker::preFseek, {}}},
+  {{"ftell", 1}, {&StreamChecker::preDefault, {}, 0}},
+  {{"rewind", 1}, {&StreamChecker::preDefault, {}, 0}},
+  {{"fgetpos", 2}, {&StreamChecker::preDefault, {}, 0}},
+  {{"fsetpos", 2}, {&StreamChecker::preDefault, {}, 0}},
+  {{"clearerr", 1}, {&StreamChecker::preDefault, {}, 0}},
+  {{"feof", 1}, {&StreamChecker::preDefault, {}, 0}},
+  {{"ferror", 1}, {&StreamChecker::preDefault, {}, 0}},
+  {{"fileno", 1}, {&StreamChecker::preDefault, {}, 0}},
   };
 
-  void evalFopen(const CallEvent &Call, CheckerContext &C) const;
-  void evalFreopen(const CallEvent &Call, CheckerContext &C) const;
-  void evalFclose(const CallEvent &Call, CheckerContext &C) const;
-  void evalFseek(const CallEvent &Call, CheckerContext &C) const;
-  void checkArgNullStream(const CallEvent &Call, CheckerContext &C,
-  unsigned ArgI) const;
-
-  ProgramStateRef checkNullStream(SVal SV, CheckerContext &C,
-  ProgramStateRef State) const;
-  ProgramStateRef checkFseekWhence(SVal SV, CheckerContext &C,
-   ProgramStateRef State) const;
-  ProgramStateRef checkDoubleClose(const CallEvent &Call, CheckerContext &C,
-   ProgramStateRef State) const;
+  void preDefault(const FnDescription *Desc, const CallEvent &Call, CheckerContext &C) const;
+ 

[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

2020-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Code is not reformatted and tests are to be added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163



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


[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

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

Aha, so we're moving every check as to whether the stream is closed to 
`preCall`? Makes sense, if not much else changed. Could you please run 
`clang-format-diff.py` after adding the tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163



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


[clang] 546918c - Revert "[compiler-rt] Add a critical section when flushing gcov counters"

2020-02-26 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-02-26T13:27:44+01:00
New Revision: 546918cbb4b2231c65cf91fceb738a59d03af7bf

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

LOG: Revert "[compiler-rt] Add a critical section when flushing gcov counters"

See discussion on PR44792.

This reverts commit 02ce9d8ef5a84bc884de4105eae5f8736ef67634.

It also reverts the follow-up commits
8f46269f0 "[profile] Don't dump counters when forking and don't reset when 
calling exec** functions"
62c7d8402 "[profile] gcov_mutex must be static"

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
compiler-rt/lib/profile/GCDAProfiling.c
llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index c9f87e0e4355..b32fad791bd3 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1144,10 +1144,8 @@ void Darwin::addProfileRTLibs(const ArgList &Args,
   if (hasExportSymbolDirective(Args)) {
 if (ForGCOV) {
   addExportedSymbol(CmdArgs, "___gcov_flush");
-  addExportedSymbol(CmdArgs, "___gcov_fork");
   addExportedSymbol(CmdArgs, "_flush_fn_list");
   addExportedSymbol(CmdArgs, "_writeout_fn_list");
-  addExportedSymbol(CmdArgs, "_reset_fn_list");
 } else {
   addExportedSymbol(CmdArgs, "___llvm_profile_filename");
   addExportedSymbol(CmdArgs, "___llvm_profile_raw_version");

diff  --git a/compiler-rt/lib/profile/GCDAProfiling.c 
b/compiler-rt/lib/profile/GCDAProfiling.c
index 98815dab541b..498c05900bf2 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -32,9 +32,8 @@
 #include 
 #include "WindowsMMap.h"
 #else
-#include 
 #include 
-#include 
+#include 
 #endif
 
 #if defined(__FreeBSD__) && defined(__i386__)
@@ -65,18 +64,6 @@ typedef unsigned long long uint64_t;
 
 /* #define DEBUG_GCDAPROFILING */
 
-#ifndef _WIN32
-#include 
-static pthread_mutex_t gcov_mutex = PTHREAD_MUTEX_INITIALIZER;
-static __inline void gcov_lock() { pthread_mutex_lock(&gcov_mutex); }
-static __inline void gcov_unlock() { pthread_mutex_unlock(&gcov_mutex); }
-#else
-#include 
-static SRWLOCK gcov_mutex = SRWLOCK_INIT;
-static __inline void gcov_lock() { AcquireSRWLockExclusive(&gcov_mutex); }
-static __inline void gcov_unlock() { ReleaseSRWLockExclusive(&gcov_mutex); }
-#endif
-
 /*
  * --- GCOV file format I/O primitives ---
  */
@@ -132,12 +119,6 @@ struct fn_list writeout_fn_list;
  */
 struct fn_list flush_fn_list;
 
-/*
- *  A list of reset functions that our __gcov_reset() function should call,
- * shared between all dynamic objects.
- */
-struct fn_list reset_fn_list;
-
 static void fn_list_insert(struct fn_list* list, fn_ptr fn) {
   struct fn_node* new_node = malloc(sizeof(struct fn_node));
   new_node->fn = fn;
@@ -638,96 +619,36 @@ void llvm_register_flush_function(fn_ptr fn) {
   fn_list_insert(&flush_fn_list, fn);
 }
 
-COMPILER_RT_VISIBILITY
-void llvm_register_reset_function(fn_ptr fn) {
-  fn_list_insert(&reset_fn_list, fn);
-}
-
-COMPILER_RT_VISIBILITY
-void llvm_reset_counters(void) {
-  struct fn_node *curr = reset_fn_list.head;
-
-  while (curr) {
-if (curr->id == CURRENT_ID) {
-  curr->fn();
-}
-curr = curr->next;
-  }
-}
-
 void __gcov_flush() {
-  gcov_lock();
-
   struct fn_node* curr = flush_fn_list.head;
 
   while (curr) {
 curr->fn();
 curr = curr->next;
   }
-
-  gcov_unlock();
 }
 
-#if !defined(_WIN32)
-pid_t __gcov_fork() {
-  pid_t parent_pid = getpid();
-  pid_t pid;
-
-  gcov_lock();
-  // Avoid a concurrent modification of the lists during the fork.
-  // For example, a thread is making a fork while another one is
-  // loading a CU and so executing global initializer in this case
-  // the child process could inherit a bad list (e.g. bad tail)
-  // or could have the malloc in a wrong state.
-  pid = fork();
-  gcov_unlock();
-
-  if (pid == 0) {
-pid_t child_pid = getpid();
-if (child_pid != parent_pid) {
-  // The pid changed so we've a fork (one could have its own fork function)
-  // Just reset the counters for this child process
-  // No need to lock here since we just forked and cannot have any other
-  // threads.
-  llvm_reset_counters();
-}
-  }
-  return pid;
-}
-#endif
-
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   fn_list_remove(&flush_fn_list);
 }
 
 COMPILER_RT_VISIBILITY
-void llvm_delete_reset_function_list(void) { fn_list_remove(&reset_fn_list); }
-
-COMPILER_RT_VISIBILITY
-void llvm_gcov_init(fn_ptr wfn, fn_ptr ffn, fn_ptr rfn) {
+void llvm_gcov_init(fn_ptr wfn, fn_ptr ffn) {
   static int atexit_ran = 0;
 
-  gcov_lock();
-
   if (wfn)
 llvm_re

[clang-tools-extra] 5560a78 - [clangd] Bump index version number.

2020-02-26 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-02-26T13:43:16+01:00
New Revision: 5560a78820ee7cecd1ad14f5a96889459dd36766

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

LOG: [clangd] Bump index version number.

Summary:
Though we don't have new changes to the index format, we have changes to
symbol collector, e.g. collect marcos, spelled references. Bump the
version to force background-index to rebuild.

Reviewers: kadircet

Reviewed By: kadircet

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/index/Serialization.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/Serialization.cpp 
b/clang-tools-extra/clangd/index/Serialization.cpp
index 440fdc670816..91e946ca9f2f 100644
--- a/clang-tools-extra/clangd/index/Serialization.cpp
+++ b/clang-tools-extra/clangd/index/Serialization.cpp
@@ -419,7 +419,7 @@ readCompileCommand(Reader CmdReader, 
llvm::ArrayRef Strings) {
 // The current versioning scheme is simple - non-current versions are rejected.
 // If you make a breaking change, bump this version number to invalidate stored
 // data. Later we may want to support some backward compatibility.
-constexpr static uint32_t Version = 12;
+constexpr static uint32_t Version = 13;
 
 llvm::Expected readRIFF(llvm::StringRef Data) {
   auto RIFF = riff::readFile(Data);



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


[PATCH] D75166: [clangd] Clean-up locateSymbolAt

2020-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Get rid of calls to lexer and unnecessary source location
transformations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75166

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

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -214,24 +214,35 @@
 }
   }
 
+  auto CurLoc = sourceLocationInMainFile(SM, Pos);
+  if (!CurLoc) {
+elog("locateSymbolAt failed to convert position to source location: {0}",
+ CurLoc.takeError());
+return {};
+  }
+
+  const auto &TB = AST.getTokens();
   // Macros are simple: there's no declaration/definition distinction.
   // As a consequence, there's no need to look them up in the index either.
-  SourceLocation IdentStartLoc = SM.getMacroArgExpandedLocation(
-  getBeginningOfIdentifier(Pos, AST.getSourceManager(), AST.getLangOpts()));
   std::vector Result;
-  if (auto M = locateMacroAt(IdentStartLoc, AST.getPreprocessor())) {
-if (auto Loc = makeLocation(AST.getASTContext(),
-M->Info->getDefinitionLoc(), *MainFilePath)) {
-  LocatedSymbol Macro;
-  Macro.Name = std::string(M->Name);
-  Macro.PreferredDeclaration = *Loc;
-  Macro.Definition = Loc;
-  Result.push_back(std::move(Macro));
-
-  // Don't look at the AST or index if we have a macro result.
-  // (We'd just return declarations referenced from the macro's
-  // expansion.)
-  return Result;
+  const auto *IdentifierCoveringCursor =
+  syntax::spelledIdentifierTouching(*CurLoc, TB);
+  if (IdentifierCoveringCursor) {
+if (auto M = locateMacroAt(IdentifierCoveringCursor->location(),
+   AST.getPreprocessor())) {
+  if (auto Loc = makeLocation(AST.getASTContext(),
+  M->Info->getDefinitionLoc(), *MainFilePath)) {
+LocatedSymbol Macro;
+Macro.Name = std::string(M->Name);
+Macro.PreferredDeclaration = *Loc;
+Macro.Definition = Loc;
+Result.push_back(std::move(Macro));
+
+// Don't look at the AST or index if we have a macro result.
+// (We'd just return declarations referenced from the macro's
+// expansion.)
+return Result;
+  }
 }
   }
 
@@ -244,15 +255,6 @@
   // Keep track of SymbolID -> index mapping, to fill in index data later.
   llvm::DenseMap ResultIndex;
 
-  SourceLocation SourceLoc;
-  if (auto L = sourceLocationInMainFile(SM, Pos)) {
-SourceLoc = *L;
-  } else {
-elog("locateSymbolAt failed to convert position to source location: {0}",
- L.takeError());
-return Result;
-  }
-
   auto AddResultDecl = [&](const NamedDecl *D) {
 const NamedDecl *Def = getDefinition(D);
 const NamedDecl *Preferred = Def ? Def : D;
@@ -277,16 +279,15 @@
   // Emit all symbol locations (declaration or definition) from AST.
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
-  for (const NamedDecl *D : getDeclAtPosition(AST, SourceLoc, Relations)) {
+  for (const NamedDecl *D : getDeclAtPosition(AST, *CurLoc, Relations)) {
 // Special case: void foo() ^override: jump to the overridden method.
 if (const auto *CMD = llvm::dyn_cast(D)) {
-  const InheritableAttr* Attr = D->getAttr();
+  const InheritableAttr *Attr = D->getAttr();
   if (!Attr)
 Attr = D->getAttr();
-  const syntax::Token *Tok =
-  spelledIdentifierTouching(SourceLoc, AST.getTokens());
-  if (Attr && Tok &&
-  SM.getSpellingLoc(Attr->getLocation()) == Tok->location()) {
+  if (Attr && IdentifierCoveringCursor &&
+  SM.getSpellingLoc(Attr->getLocation()) ==
+  IdentifierCoveringCursor->location()) {
 // We may be overridding multiple methods - offer them all.
 for (const NamedDecl *ND : CMD->overridden_methods())
   AddResultDecl(ND);
@@ -296,8 +297,9 @@
 
 // Special case: the point of declaration of a template specialization,
 // it's more useful to navigate to the template declaration.
-if (SM.getMacroArgExpandedLocation(D->getLocation()) == IdentStartLoc) {
-  if (auto *CTSD = dyn_cast(D)) {
+if (auto *CTSD = dyn_cast(D)) {
+  if (IdentifierCoveringCursor &&
+  D->getLocation() == IdentifierCoveringCursor->location()) {
 AddResultDecl(CTSD->getSpecializedTemplate());
 continue;
   }
@@ -757,7 +759,6 @@
   return Result != nullptr;
 });
   return Result;
-
 }
 
 std::vector typeParents(const CXXRecordDecl *CXXRD) {
___
cfe-commits mailing list
cfe-commits@lists.llvm

[PATCH] D74127: [clangd] Bump index version number.

2020-02-26 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5560a78820ee: [clangd] Bump index version number. (authored 
by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74127

Files:
  clang-tools-extra/clangd/index/Serialization.cpp


Index: clang-tools-extra/clangd/index/Serialization.cpp
===
--- clang-tools-extra/clangd/index/Serialization.cpp
+++ clang-tools-extra/clangd/index/Serialization.cpp
@@ -419,7 +419,7 @@
 // The current versioning scheme is simple - non-current versions are rejected.
 // If you make a breaking change, bump this version number to invalidate stored
 // data. Later we may want to support some backward compatibility.
-constexpr static uint32_t Version = 12;
+constexpr static uint32_t Version = 13;
 
 llvm::Expected readRIFF(llvm::StringRef Data) {
   auto RIFF = riff::readFile(Data);


Index: clang-tools-extra/clangd/index/Serialization.cpp
===
--- clang-tools-extra/clangd/index/Serialization.cpp
+++ clang-tools-extra/clangd/index/Serialization.cpp
@@ -419,7 +419,7 @@
 // The current versioning scheme is simple - non-current versions are rejected.
 // If you make a breaking change, bump this version number to invalidate stored
 // data. Later we may want to support some backward compatibility.
-constexpr static uint32_t Version = 12;
+constexpr static uint32_t Version = 13;
 
 llvm::Expected readRIFF(llvm::StringRef Data) {
   auto RIFF = riff::readFile(Data);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8c2cf49 - [clang][Tooling] Add a way to tokenize a FileRange

2020-02-26 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-02-26T13:50:41+01:00
New Revision: 8c2cf499e6119be8f3f1a0d42c4bb7e45b0d615d

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

LOG: [clang][Tooling] Add a way to tokenize a FileRange

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Tokens.h
clang/lib/Tooling/Syntax/Tokens.cpp
clang/unittests/Tooling/Syntax/TokensTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Tokens.h 
b/clang/include/clang/Tooling/Syntax/Tokens.h
index fc0fabb40658..19d120ebbc9f 100644
--- a/clang/include/clang/Tooling/Syntax/Tokens.h
+++ b/clang/include/clang/Tooling/Syntax/Tokens.h
@@ -339,6 +339,12 @@ spelledIdentifierTouching(SourceLocation Loc,
 /// The result will *not* have a 'eof' token at the end.
 std::vector tokenize(FileID FID, const SourceManager &SM,
 const LangOptions &LO);
+/// Similar to one above, instead of whole file tokenizes a part of it. Note
+/// that, the first token might be incomplete if FR.startOffset is not at the
+/// beginning of a token, and the last token returned will start before the
+/// FR.endOffset but might end after it.
+std::vector
+tokenize(const FileRange &FR, const SourceManager &SM, const LangOptions &LO);
 
 /// Collects tokens for the main file while running the frontend action. An
 /// instance of this object should be created on

diff  --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index 9f51ab787ad1..ae5bc687553b 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -67,7 +67,8 @@ FileRange syntax::Token::range(const SourceManager &SM,
   auto F = First.range(SM);
   auto L = Last.range(SM);
   assert(F.file() == L.file() && "tokens from 
diff erent files");
-  assert((F == L || F.endOffset() <= L.beginOffset()) && "wrong order of 
tokens");
+  assert((F == L || F.endOffset() <= L.beginOffset()) &&
+ "wrong order of tokens");
   return FileRange(F.file(), F.beginOffset(), L.endOffset());
 }
 
@@ -307,7 +308,8 @@ TokenBuffer::macroExpansions(FileID FID) const {
   return Expansions;
 }
 
-std::vector syntax::tokenize(FileID FID, const SourceManager 
&SM,
+std::vector syntax::tokenize(const FileRange &FR,
+const SourceManager &SM,
 const LangOptions &LO) {
   std::vector Tokens;
   IdentifierTable Identifiers(LO);
@@ -322,18 +324,28 @@ std::vector syntax::tokenize(FileID FID, 
const SourceManager &SM,
 Tokens.push_back(syntax::Token(T));
   };
 
-  Lexer L(FID, SM.getBuffer(FID), SM, LO);
+  auto SrcBuffer = SM.getBufferData(FR.file());
+  Lexer L(SM.getLocForStartOfFile(FR.file()), LO, SrcBuffer.data(),
+  SrcBuffer.data() + FR.beginOffset(),
+  // We can't make BufEnd point to FR.endOffset, as Lexer requires a
+  // null terminated buffer.
+  SrcBuffer.data() + SrcBuffer.size());
 
   clang::Token T;
-  while (!L.LexFromRawLexer(T))
+  while (!L.LexFromRawLexer(T) && L.getCurrentBufferOffset() < FR.endOffset())
 AddToken(T);
-  // 'eof' is only the last token if the input is null-terminated. Never store
-  // it, for consistency.
-  if (T.getKind() != tok::eof)
+  // LexFromRawLexer returns true when it parses the last token of the file, 
add
+  // it iff it starts within the range we are interested in.
+  if (SM.getFileOffset(T.getLocation()) < FR.endOffset())
 AddToken(T);
   return Tokens;
 }
 
+std::vector syntax::tokenize(FileID FID, const SourceManager 
&SM,
+const LangOptions &LO) {
+  return tokenize(syntax::FileRange(FID, 0, SM.getFileIDSize(FID)), SM, LO);
+}
+
 /// Records information reqired to construct mappings for the token buffer that
 /// we are collecting.
 class TokenCollector::CollectPPExpansions : public PPCallbacks {

diff  --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp 
b/clang/unittests/Tooling/Syntax/TokensTest.cpp
index b2ad3859104a..ad0293bc3e07 100644
--- a/clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -153,11 +153,17 @@ class TokenCollectorTest : public ::testing::Test {
 }
   }
 
-  /// Add a new file, run syntax::tokenize() on it and return the results.
+  /// Add a new file, run syntax::tokenize() on the range if any, run it on the
+  /// whole file otherwise and return the results.
   std::vector tokenize(llvm::StringRef Text) {
+llvm::Annotations Annot(Text);
+auto FID = SourceMgr->createFileID(
+llvm::MemoryBuffer::getMemBufferCopy(Annot.code()));
 // FIXME: pass

[PATCH] D74962: [clang][Tooling] Add a way to tokenize a FileRange

2020-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8c2cf499e611: [clang][Tooling] Add a way to tokenize a 
FileRange (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74962

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -153,11 +153,17 @@
 }
   }
 
-  /// Add a new file, run syntax::tokenize() on it and return the results.
+  /// Add a new file, run syntax::tokenize() on the range if any, run it on the
+  /// whole file otherwise and return the results.
   std::vector tokenize(llvm::StringRef Text) {
+llvm::Annotations Annot(Text);
+auto FID = SourceMgr->createFileID(
+llvm::MemoryBuffer::getMemBufferCopy(Annot.code()));
 // FIXME: pass proper LangOptions.
+if (Annot.ranges().empty())
+  return syntax::tokenize(FID, *SourceMgr, LangOptions());
 return syntax::tokenize(
-SourceMgr->createFileID(llvm::MemoryBuffer::getMemBufferCopy(Text)),
+syntax::FileRange(FID, Annot.range().Begin, Annot.range().End),
 *SourceMgr, LangOptions());
   }
 
@@ -258,6 +264,20 @@
   ElementsAre(Kind(tok::kw_int),
   AllOf(HasText("a"), Kind(tok::identifier)),
   Kind(tok::semi)));
+  EXPECT_THAT(tokenize("int [[main() {]]}"),
+  ElementsAre(AllOf(HasText("main"), Kind(tok::identifier)),
+  Kind(tok::l_paren), Kind(tok::r_paren),
+  Kind(tok::l_brace)));
+  EXPECT_THAT(tokenize("int [[main() {   ]]}"),
+  ElementsAre(AllOf(HasText("main"), Kind(tok::identifier)),
+  Kind(tok::l_paren), Kind(tok::r_paren),
+  Kind(tok::l_brace)));
+  // First token is partially parsed, last token is fully included even though
+  // only a part of it is contained in the range.
+  EXPECT_THAT(tokenize("int m[[ain() {ret]]urn 0;}"),
+  ElementsAre(AllOf(HasText("ain"), Kind(tok::identifier)),
+  Kind(tok::l_paren), Kind(tok::r_paren),
+  Kind(tok::l_brace), Kind(tok::kw_return)));
 }
 
 TEST_F(TokenCollectorTest, Basic) {
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -67,7 +67,8 @@
   auto F = First.range(SM);
   auto L = Last.range(SM);
   assert(F.file() == L.file() && "tokens from different files");
-  assert((F == L || F.endOffset() <= L.beginOffset()) && "wrong order of tokens");
+  assert((F == L || F.endOffset() <= L.beginOffset()) &&
+ "wrong order of tokens");
   return FileRange(F.file(), F.beginOffset(), L.endOffset());
 }
 
@@ -307,7 +308,8 @@
   return Expansions;
 }
 
-std::vector syntax::tokenize(FileID FID, const SourceManager &SM,
+std::vector syntax::tokenize(const FileRange &FR,
+const SourceManager &SM,
 const LangOptions &LO) {
   std::vector Tokens;
   IdentifierTable Identifiers(LO);
@@ -322,18 +324,28 @@
 Tokens.push_back(syntax::Token(T));
   };
 
-  Lexer L(FID, SM.getBuffer(FID), SM, LO);
+  auto SrcBuffer = SM.getBufferData(FR.file());
+  Lexer L(SM.getLocForStartOfFile(FR.file()), LO, SrcBuffer.data(),
+  SrcBuffer.data() + FR.beginOffset(),
+  // We can't make BufEnd point to FR.endOffset, as Lexer requires a
+  // null terminated buffer.
+  SrcBuffer.data() + SrcBuffer.size());
 
   clang::Token T;
-  while (!L.LexFromRawLexer(T))
+  while (!L.LexFromRawLexer(T) && L.getCurrentBufferOffset() < FR.endOffset())
 AddToken(T);
-  // 'eof' is only the last token if the input is null-terminated. Never store
-  // it, for consistency.
-  if (T.getKind() != tok::eof)
+  // LexFromRawLexer returns true when it parses the last token of the file, add
+  // it iff it starts within the range we are interested in.
+  if (SM.getFileOffset(T.getLocation()) < FR.endOffset())
 AddToken(T);
   return Tokens;
 }
 
+std::vector syntax::tokenize(FileID FID, const SourceManager &SM,
+const LangOptions &LO) {
+  return tokenize(syntax::FileRange(FID, 0, SM.getFileIDSize(FID)), SM, LO);
+}
+
 /// Records information reqired to construct mappings for the token buffer that
 /// we are collecting.
 class TokenCollector::CollectPPExpansions : public PPCallbacks {
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===

[clang] 6e34a9a - [OpenMP] Fix the test by generating output file in temporary directory

2020-02-26 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2020-02-26T14:07:13+01:00
New Revision: 6e34a9a838c150b968b05b76d545969d1ddeee90

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

LOG: [OpenMP] Fix the test by generating output file in temporary directory

Related Revison: D74925
Commit: 396b7253944e927878dff2f6321efabb3aaa0f45

Added: 


Modified: 
clang/test/OpenMP/PR44893.c

Removed: 




diff  --git a/clang/test/OpenMP/PR44893.c b/clang/test/OpenMP/PR44893.c
index 12e43da2c9de..1ba1127e874b 100644
--- a/clang/test/OpenMP/PR44893.c
+++ b/clang/test/OpenMP/PR44893.c
@@ -1,4 +1,4 @@
-// RUN: %clang -fopenmp -O -g -x c %s -c -disable-output
+// RUN: %clang -fopenmp -O -g -x c %s -c -disable-output -o %t
 
 // Do not crash ;)
 



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


[PATCH] D71775: [ThreadPool] On Windows, extend usage to all CPU sockets and all NUMA groups

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

@thakis I think this is a side-effect of implementing 
`computeHostNumPhysicalCores()` for Windows, which previously returned -1, 
which in turn made `llvm::heavyweight_hardware_concurrency()` previously behave 
like `llvm::hardware_concurrency()` (on Windows only).
At first sight, Linux seems to report the same thing as Windows (2 cores per 
"module"). If I read this 
 
correctly, the behavior on Linux for a AMD Opteron is/was the same as it is 
currently on Windows after this patch, that is, only one core out of two would 
be used for `llvm::heavyweight_hardware_concurrency()`.

I think this is a wider problem outside the scope of this patch, which is, some 
users want to use 100% of the cores/hyper-threads when using ThinLTO. Currently 
there's no way. An algorithm using `llvm::heavyweight_hardware_concurrency()` 
explicitly states "I only want one core out of two". It'd be nice if we had a 
cmd-line flag to override this, to say "I want to use all 
hyper-threads/cores/modules". `/opt:lldltojobs=all`? The impact is small on a 
modern Intel Skylake CPU, but it might be better depending on the CPU (AMD 
Bulldozer).

F11420112: image.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71775



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


[PATCH] D71775: [ThreadPool] On Windows, extend usage to all CPU sockets and all NUMA groups

2020-02-26 Thread Robert Richmond via Phabricator via cfe-commits
RobRich999 added a comment.

I too can see how SMT might not afford much performance difference for LTO 
codegen.

CMT appears to be more significant. I do not have exact numbers right now as my 
build box is busy, but the change added like an hour to locally building the 
Chromium browser with ThinLTO optimizations enabled. Win10 running on a 32-core 
Opteron Piledriver (bdver2) system.

Definitely agree something like "/opt:lldltojobs=all" in a separate patch would 
be a good solution if possible for this particular (corner) case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71775



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


[PATCH] D71775: [ThreadPool] On Windows, extend usage to all CPU sockets and all NUMA groups

2020-02-26 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

There is something puzzling to me in this patch in the way the ThreadPool was 
modified: the client of the thread pool cannot request a number of threads 
anymore, but only a *maximum* number of threads. I don't really understand why? 
Using the OS reported concurrency was always a "default", isn't this change 
orthogonal / unrelated to the stated goal of this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71775



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


[PATCH] D75169: [ARM] Enforcing calling convention for half-precision FP arguments and returns for big-endian AArch32

2020-02-26 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas created this revision.
Herald added subscribers: cfe-commits, kristof.beyls.
Herald added a project: clang.

Half-precision floating point arguments and returns are currently
promoted to either float or int32 in clang's CodeGen. As such promotions
are implemented as coercion through memory in clang, aruments and
returns of those types end up stored on the wrong bits on big-endian
AArch32 - MSBs instead of LSBs.

This patch enforces AAPCS' directions, making sure clang stores those
types on the proper bits during coercion through memory for bit-endian
targets.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75169

Files:
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/arm-fp16-arguments.c

Index: clang/test/CodeGen/arm-fp16-arguments.c
===
--- clang/test/CodeGen/arm-fp16-arguments.c
+++ clang/test/CodeGen/arm-fp16-arguments.c
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -triple armv7a--none-eabi -target-abi aapcs -mfloat-abi soft -fallow-half-arguments-and-returns -emit-llvm -o - -O2 %s | FileCheck %s --check-prefix=CHECK --check-prefix=SOFT
 // RUN: %clang_cc1 -triple armv7a--none-eabi -target-abi aapcs -mfloat-abi hard -fallow-half-arguments-and-returns -emit-llvm -o - -O2 %s | FileCheck %s --check-prefix=CHECK --check-prefix=HARD
 // RUN: %clang_cc1 -triple armv7a--none-eabi -target-abi aapcs -mfloat-abi soft -fnative-half-arguments-and-returns -emit-llvm -o - -O2 %s | FileCheck %s --check-prefix=NATIVE
+// RUN: %clang_cc1 -triple armebv7a--none-eabi -target-abi aapcs -mfloat-abi soft -fallow-half-arguments-and-returns -emit-llvm -o - -O2 %s | FileCheck %s --check-prefix=CHECK --check-prefix=SOFT
+// RUN: %clang_cc1 -triple armebv7a--none-eabi -target-abi aapcs -mfloat-abi hard -fallow-half-arguments-and-returns -emit-llvm -o - -O2 %s | FileCheck %s --check-prefix=CHECK --check-prefix=HARD
+// RUN: %clang_cc1 -triple armebv7a--none-eabi -target-abi aapcs -mfloat-abi soft -fnative-half-arguments-and-returns -emit-llvm -o - -O2 %s | FileCheck %s --check-prefix=NATIVE
 
 __fp16 g;
 
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5934,7 +5934,8 @@
 llvm::Type *ResType = IsAAPCS_VFP ?
   llvm::Type::getFloatTy(getVMContext()) :
   llvm::Type::getInt32Ty(getVMContext());
-return ABIArgInfo::getDirect(ResType);
+return ABIArgInfo::getDirect(ResType, /*Offset=*/0, /*Padding=*/nullptr,
+ /*CanBeFlattened=*/true, /*EndianAlign=*/true);
   }
 
   if (!isAggregateTypeForABI(Ty)) {
@@ -6141,7 +6142,8 @@
 llvm::Type *ResType = IsAAPCS_VFP ?
   llvm::Type::getFloatTy(getVMContext()) :
   llvm::Type::getInt32Ty(getVMContext());
-return ABIArgInfo::getDirect(ResType);
+return ABIArgInfo::getDirect(ResType, /*Offset=*/0, /*Padding=*/nullptr,
+/*CanBeFlattened=*/true, /*EndianAlign=*/true);
   }
 
   if (!isAggregateTypeForABI(RetTy)) {
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1221,6 +1221,7 @@
 /// destination type; in this situation the values of bits which not
 /// present in the src are undefined.
 static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,
+  bool EndianAlign,
   CodeGenFunction &CGF) {
   llvm::Type *SrcTy = Src.getElementType();
 
@@ -1261,6 +1262,11 @@
   // Otherwise do coercion through memory. This is stupid, but simple.
   Address Tmp = CreateTempAllocaForCoercion(CGF, Ty, Src.getAlignment());
   Address Casted = CGF.Builder.CreateElementBitCast(Tmp,CGF.Int8Ty);
+  if (EndianAlign && CGF.CGM.getDataLayout().isBigEndian()) {
+// Offset address to match LSBs if endian alignment is required
+auto Offset = CharUnits::fromQuantity(DstSize - SrcSize);
+Casted = CGF.Builder.CreateConstInBoundsByteGEP(Casted, Offset);
+  }
   Address SrcCasted = CGF.Builder.CreateElementBitCast(Src,CGF.Int8Ty);
   CGF.Builder.CreateMemCpy(Casted, SrcCasted,
   llvm::ConstantInt::get(CGF.IntPtrTy, SrcSize),
@@ -1296,6 +1302,7 @@
 static void CreateCoercedStore(llvm::Value *Src,
Address Dst,
bool DstIsVolatile,
+   bool EndianAlign,
CodeGenFunction &CGF) {
   llvm::Type *SrcTy = Src->getType();
   llvm::Type *DstTy = Dst.getType()->getElementType();
@@ -1348,6 +1355,11 @@
 Address Tmp = CreateTempAllocaForCoercion(CGF, SrcTy, Dst.getAlignment());
 CGF.Builder.CreateStore(Src, Tmp);
 Address Casted = CGF.Builder.CreateElementBitCast(Tmp,CGF.Int8Ty);
+if (EndianAlign && CGF.CGM.get

[PATCH] D75166: [clangd] Clean-up locateSymbolAt

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

Add more cleaning.

getDeclAtPosition builds a SelectionTree underneath and it only operates on
spelling locations inside main file. So it is invalid to pass any expansion
locations to it.

There is no need to call getBeginningOfIdentifier for offsets being thrown at
SelectionTrees.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75166

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

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -214,24 +214,35 @@
 }
   }
 
+  auto CurLoc = sourceLocationInMainFile(SM, Pos);
+  if (!CurLoc) {
+elog("locateSymbolAt failed to convert position to source location: {0}",
+ CurLoc.takeError());
+return {};
+  }
+
+  const auto &TB = AST.getTokens();
   // Macros are simple: there's no declaration/definition distinction.
   // As a consequence, there's no need to look them up in the index either.
-  SourceLocation IdentStartLoc = SM.getMacroArgExpandedLocation(
-  getBeginningOfIdentifier(Pos, AST.getSourceManager(), AST.getLangOpts()));
   std::vector Result;
-  if (auto M = locateMacroAt(IdentStartLoc, AST.getPreprocessor())) {
-if (auto Loc = makeLocation(AST.getASTContext(),
-M->Info->getDefinitionLoc(), *MainFilePath)) {
-  LocatedSymbol Macro;
-  Macro.Name = std::string(M->Name);
-  Macro.PreferredDeclaration = *Loc;
-  Macro.Definition = Loc;
-  Result.push_back(std::move(Macro));
-
-  // Don't look at the AST or index if we have a macro result.
-  // (We'd just return declarations referenced from the macro's
-  // expansion.)
-  return Result;
+  const auto *IdentifierCoveringCursor =
+  syntax::spelledIdentifierTouching(*CurLoc, TB);
+  if (IdentifierCoveringCursor) {
+if (auto M = locateMacroAt(IdentifierCoveringCursor->location(),
+   AST.getPreprocessor())) {
+  if (auto Loc = makeLocation(AST.getASTContext(),
+  M->Info->getDefinitionLoc(), *MainFilePath)) {
+LocatedSymbol Macro;
+Macro.Name = std::string(M->Name);
+Macro.PreferredDeclaration = *Loc;
+Macro.Definition = Loc;
+Result.push_back(std::move(Macro));
+
+// Don't look at the AST or index if we have a macro result.
+// (We'd just return declarations referenced from the macro's
+// expansion.)
+return Result;
+  }
 }
   }
 
@@ -244,15 +255,6 @@
   // Keep track of SymbolID -> index mapping, to fill in index data later.
   llvm::DenseMap ResultIndex;
 
-  SourceLocation SourceLoc;
-  if (auto L = sourceLocationInMainFile(SM, Pos)) {
-SourceLoc = *L;
-  } else {
-elog("locateSymbolAt failed to convert position to source location: {0}",
- L.takeError());
-return Result;
-  }
-
   auto AddResultDecl = [&](const NamedDecl *D) {
 const NamedDecl *Def = getDefinition(D);
 const NamedDecl *Preferred = Def ? Def : D;
@@ -277,16 +279,15 @@
   // Emit all symbol locations (declaration or definition) from AST.
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
-  for (const NamedDecl *D : getDeclAtPosition(AST, SourceLoc, Relations)) {
+  for (const NamedDecl *D : getDeclAtPosition(AST, *CurLoc, Relations)) {
 // Special case: void foo() ^override: jump to the overridden method.
 if (const auto *CMD = llvm::dyn_cast(D)) {
-  const InheritableAttr* Attr = D->getAttr();
+  const InheritableAttr *Attr = D->getAttr();
   if (!Attr)
 Attr = D->getAttr();
-  const syntax::Token *Tok =
-  spelledIdentifierTouching(SourceLoc, AST.getTokens());
-  if (Attr && Tok &&
-  SM.getSpellingLoc(Attr->getLocation()) == Tok->location()) {
+  if (Attr && IdentifierCoveringCursor &&
+  SM.getSpellingLoc(Attr->getLocation()) ==
+  IdentifierCoveringCursor->location()) {
 // We may be overridding multiple methods - offer them all.
 for (const NamedDecl *ND : CMD->overridden_methods())
   AddResultDecl(ND);
@@ -296,8 +297,9 @@
 
 // Special case: the point of declaration of a template specialization,
 // it's more useful to navigate to the template declaration.
-if (SM.getMacroArgExpandedLocation(D->getLocation()) == IdentStartLoc) {
-  if (auto *CTSD = dyn_cast(D)) {
+if (auto *CTSD = dyn_cast(D)) {
+  if (IdentifierCoveringCursor &&
+  D->getLocation() == IdentifierCoveringCursor->location()) {
 AddResultDecl(CTSD->getSpecializedTemplate());
 continue;
   }
@@ -416,12 +418,15 @@
   // FIXME: show references to macro within file?
   DeclRelationSet Relations =
   DeclRelation::Templat

[PATCH] D75044: [AArch64] __builtin_extract_return_addr for PAuth.

2020-02-26 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss updated this revision to Diff 246685.
danielkiss added a reviewer: olista01.
danielkiss added a comment.

rebased and test is updated.


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

https://reviews.llvm.org/D75044

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/arm64-extractreturnaddress.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/CodeGen/ISDOpcodes.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/test/CodeGen/AArch64/aarch64-extractreturnaddress.ll

Index: llvm/test/CodeGen/AArch64/aarch64-extractreturnaddress.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/aarch64-extractreturnaddress.ll
@@ -0,0 +1,29 @@
+; RUN: llc < %s -mtriple=arm64-eabi -asm-verbose=false -mattr=v8.2a | FileCheck %s
+; RUN: llc < %s -mtriple=arm64-eabi -asm-verbose=false -mattr=v8.3a | FileCheck %s --check-prefix=CHECKV83
+
+; Armv8.3-A Pointer Authetication requires a special intsruction to strip the
+; pointer authentication code from the pointer.
+; The XPACLRI instruction assembles to a hint-space instruction before Armv8.3-A
+; therefore this instruction can be safely used for any pre Armv8.3-A architectures.
+; On Armv8.3-A and onwards XPACI is available so use that instead.
+
+define i8* @era0(i8* %x) nounwind readnone #0 {
+entry:
+; CHECK-LABEL: era0:
+; CHECK:  hint #25
+; CHECK-NEXT: str x30, [sp, #-16]!
+; CHECK-NEXT: mov x30, x0
+; CHECK-NEXT: hint #7
+; CHECK-NEXT: mov x0, x30
+; CHECK-NEXT: ldr x30, [sp], #16
+; CHECK-NEXT: hint #29
+; CHECK-NEXT: ret
+; CHECKV83:   paciasp
+; CHECKV83-NEXT:  xpaci   x0
+; CHECKV83-NEXT:  retaa
+  %0 = tail call i8* @llvm.extractreturnaddress(i8* %x)
+  ret i8* %0
+}
+attributes #0 = { "sign-return-address"="all" }
+
+declare i8* @llvm.extractreturnaddress(i8*) nounwind readnone
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.h
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.h
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.h
@@ -740,6 +740,7 @@
   SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
   SDValue LowerSPONENTRY(SDValue Op, SelectionDAG &DAG) const;
   SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
+  SDValue LowerEXTRACTRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
   SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
   SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
   SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -3276,6 +3276,8 @@
 return LowerSPONENTRY(Op, DAG);
   case ISD::RETURNADDR:
 return LowerRETURNADDR(Op, DAG);
+  case ISD::EXTRACTRETURNADDR:
+return LowerEXTRACTRETURNADDR(Op, DAG);
   case ISD::ADDROFRETURNADDR:
 return LowerADDROFRETURNADDR(Op, DAG);
   case ISD::INSERT_VECTOR_ELT:
@@ -5980,6 +5982,29 @@
   return DAG.getCopyFromReg(DAG.getEntryNode(), DL, Reg, VT);
 }
 
+SDValue AArch64TargetLowering::LowerEXTRACTRETURNADDR(SDValue Op,
+  SelectionDAG &DAG) const {
+  SDLoc DL(Op);
+  EVT VT = Op.getValueType();
+
+  // The XPACLRI instruction assembles to a hint-space instruction before
+  // Armv8.3-A therefore this instruction can be safely used for any pre
+  // Armv8.3-A architectures. On Armv8.3-A and onwards XPACI is available so use
+  // that instead.
+  if (Subtarget->hasV8_3aOps()) {
+SDValue Reg =
+DAG.getCopyToReg(DAG.getEntryNode(), DL, AArch64::X0, Op.getOperand(0));
+SDNode *St = DAG.getMachineNode(AArch64::XPACI, DL, VT, Reg);
+return SDValue(St, 0);
+  } else {
+// XPACLRI operates on LR therefore we must move the operand accordingly.
+SDValue Reg =
+DAG.getCopyToReg(DAG.getEntryNode(), DL, AArch64::LR, Op.getOperand(0));
+SDNode *St = DAG.getMachineNode(AArch64::XPACLRI, DL, VT, Reg);
+return SDValue(St, 0);
+  }
+}
+
 /// LowerShiftRightParts - Lower SRA_PARTS, which returns two
 /// i64 values and take a 2 x i64 value to shift plus a shift amount.
 SDValue AArch64TargetLowering::LowerShiftRightParts(SDValue Op,
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -5817,6 +5817,11 @@
  TLI.getPointerTy(DAG.getDataLayout()),
  getValue(I.

[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

2020-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 246687.
balazske added a comment.

Reformat code and fixed errors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -34,7 +34,7 @@
 
   bool isOpened() const { return K == Opened; }
   bool isClosed() const { return K == Closed; }
-  //bool isOpenFailed() const { return K == OpenFailed; }
+  bool isOpenFailed() const { return K == OpenFailed; }
   //bool isEscaped() const { return K == Escaped; }
 
   bool operator==(const StreamState &X) const { return K == X.K; }
@@ -50,66 +50,81 @@
 };
 
 class StreamChecker;
-
-using FnCheck = std::function;
 
+using ArgNoTy = unsigned int;
+static const ArgNoTy ArgNone = std::numeric_limits::max();
+
 struct FnDescription {
+  FnCheck PreFn;
   FnCheck EvalFn;
+  ArgNoTy StreamArgNo;
 };
 
-class StreamChecker : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
-  BT_doubleclose, BT_ResourceLeak;
+  BT_UseAfterClose, BT_UseAfterOpenFailed, BT_ResourceLeak;
 
 public:
+  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
 
 private:
-
   CallDescriptionMap FnDescriptions = {
-  {{"fopen"}, {&StreamChecker::evalFopen}},
-  {{"freopen", 3}, {&StreamChecker::evalFreopen}},
-  {{"tmpfile"}, {&StreamChecker::evalFopen}},
-  {{"fclose", 1}, {&StreamChecker::evalFclose}},
-  {{"fread", 4},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
-  {{"fwrite", 4},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
-  {{"fseek", 3}, {&StreamChecker::evalFseek}},
-  {{"ftell", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"rewind", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"fgetpos", 2},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"fsetpos", 2},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"clearerr", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"feof", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"ferror", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
-  {{"fileno", 1},
-   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
+  {{"fopen"}, {{}, &StreamChecker::evalFopen, ArgNone}},
+  {{"freopen", 3},
+   {&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}},
+  {{"tmpfile"}, {{}, &StreamChecker::evalFopen, ArgNone}},
+  {{"fclose", 1},
+   {&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}},
+  {{"fread", 4}, {&StreamChecker::preDefault, {}, 3}},
+  {{"fwrite", 4}, {&StreamChecker::preDefault, {}, 3}},
+  {{"fseek", 3}, {&StreamChecker::preFseek, {}}},
+  {{"ftell", 1}, {&StreamChecker::preDefault, {}, 0}},
+  {{"rewind", 1}, {&StreamChecker::preDefault, {}, 0}},
+  {{"fgetpos", 2}, {&StreamChecker::preDefault, {}, 0}},
+  {{"fsetpos", 2}, {&StreamChecker::preDefault, {}, 0}},
+  {{"clearerr", 1}, {&StreamChecker::preDefault, {}, 0}},
+  {{"feof", 1}, {&StreamChecker::preDefault, {}, 0}},
+  {{"ferror", 1}, {&StreamChecker::preDefault, {}, 0}},
+  {{"fileno", 1}, {&StreamChecker::preDefault, {}, 0}},
   };
 
-  void evalFopen(const CallEvent &Call, CheckerContext &C) const;
-  void evalFreopen(const CallEvent &Call, CheckerContext &C) const;
-  void evalFclose(const CallEvent &Call, CheckerContext &C) const;
-  void evalFseek(const CallEvent &Call, CheckerContext &C) const;
-  void checkArgNullStream(const CallEvent &Call, CheckerContext &C,
-  unsigned ArgI) const;
-
-  ProgramStateRef checkNullStream(SVal SV, CheckerContext &C,
-  ProgramStateRef State) const;
-  ProgramStateRef checkFseekWhence(SVal SV, CheckerContext &C,
-   ProgramStateRef State) const;
-  ProgramStateRef checkDoubleClose(const CallEvent &Call, CheckerContext &C,
-   ProgramStateRef State) const;
+  void preDefault(const FnDescription *Desc, const CallEvent &Call, CheckerContext &C) const;
+  void preFseek(const FnDescription *Desc, const CallEvent &Call, CheckerContext &C) const;
+  void preFreopen(const FnDescription *Desc, const CallEvent &Call, CheckerContext &C) const;
+
+  void evalFopen(const FnDescription *Desc, const CallEvent 

[PATCH] D75165: [ARM,MVE] Add predicated intrinsics for many unary functions.

2020-02-26 Thread Mark Murray via Phabricator via cfe-commits
MarkMurrayARM accepted this revision.
MarkMurrayARM added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75165



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


[PATCH] D75166: [clangd] Clean-up locateSymbolAt

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

- Also clean usage in getSymbolInfo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75166

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

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -214,24 +214,35 @@
 }
   }
 
+  auto CurLoc = sourceLocationInMainFile(SM, Pos);
+  if (!CurLoc) {
+elog("locateSymbolAt failed to convert position to source location: {0}",
+ CurLoc.takeError());
+return {};
+  }
+
+  const auto &TB = AST.getTokens();
   // Macros are simple: there's no declaration/definition distinction.
   // As a consequence, there's no need to look them up in the index either.
-  SourceLocation IdentStartLoc = SM.getMacroArgExpandedLocation(
-  getBeginningOfIdentifier(Pos, AST.getSourceManager(), AST.getLangOpts()));
   std::vector Result;
-  if (auto M = locateMacroAt(IdentStartLoc, AST.getPreprocessor())) {
-if (auto Loc = makeLocation(AST.getASTContext(),
-M->Info->getDefinitionLoc(), *MainFilePath)) {
-  LocatedSymbol Macro;
-  Macro.Name = std::string(M->Name);
-  Macro.PreferredDeclaration = *Loc;
-  Macro.Definition = Loc;
-  Result.push_back(std::move(Macro));
-
-  // Don't look at the AST or index if we have a macro result.
-  // (We'd just return declarations referenced from the macro's
-  // expansion.)
-  return Result;
+  const auto *IdentifierCoveringCursor =
+  syntax::spelledIdentifierTouching(*CurLoc, TB);
+  if (IdentifierCoveringCursor) {
+if (auto M = locateMacroAt(IdentifierCoveringCursor->location(),
+   AST.getPreprocessor())) {
+  if (auto Loc = makeLocation(AST.getASTContext(),
+  M->Info->getDefinitionLoc(), *MainFilePath)) {
+LocatedSymbol Macro;
+Macro.Name = std::string(M->Name);
+Macro.PreferredDeclaration = *Loc;
+Macro.Definition = Loc;
+Result.push_back(std::move(Macro));
+
+// Don't look at the AST or index if we have a macro result.
+// (We'd just return declarations referenced from the macro's
+// expansion.)
+return Result;
+  }
 }
   }
 
@@ -244,15 +255,6 @@
   // Keep track of SymbolID -> index mapping, to fill in index data later.
   llvm::DenseMap ResultIndex;
 
-  SourceLocation SourceLoc;
-  if (auto L = sourceLocationInMainFile(SM, Pos)) {
-SourceLoc = *L;
-  } else {
-elog("locateSymbolAt failed to convert position to source location: {0}",
- L.takeError());
-return Result;
-  }
-
   auto AddResultDecl = [&](const NamedDecl *D) {
 const NamedDecl *Def = getDefinition(D);
 const NamedDecl *Preferred = Def ? Def : D;
@@ -277,16 +279,15 @@
   // Emit all symbol locations (declaration or definition) from AST.
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
-  for (const NamedDecl *D : getDeclAtPosition(AST, SourceLoc, Relations)) {
+  for (const NamedDecl *D : getDeclAtPosition(AST, *CurLoc, Relations)) {
 // Special case: void foo() ^override: jump to the overridden method.
 if (const auto *CMD = llvm::dyn_cast(D)) {
-  const InheritableAttr* Attr = D->getAttr();
+  const InheritableAttr *Attr = D->getAttr();
   if (!Attr)
 Attr = D->getAttr();
-  const syntax::Token *Tok =
-  spelledIdentifierTouching(SourceLoc, AST.getTokens());
-  if (Attr && Tok &&
-  SM.getSpellingLoc(Attr->getLocation()) == Tok->location()) {
+  if (Attr && IdentifierCoveringCursor &&
+  SM.getSpellingLoc(Attr->getLocation()) ==
+  IdentifierCoveringCursor->location()) {
 // We may be overridding multiple methods - offer them all.
 for (const NamedDecl *ND : CMD->overridden_methods())
   AddResultDecl(ND);
@@ -296,8 +297,9 @@
 
 // Special case: the point of declaration of a template specialization,
 // it's more useful to navigate to the template declaration.
-if (SM.getMacroArgExpandedLocation(D->getLocation()) == IdentStartLoc) {
-  if (auto *CTSD = dyn_cast(D)) {
+if (auto *CTSD = dyn_cast(D)) {
+  if (IdentifierCoveringCursor &&
+  D->getLocation() == IdentifierCoveringCursor->location()) {
 AddResultDecl(CTSD->getSpecializedTemplate());
 continue;
   }
@@ -416,12 +418,15 @@
   // FIXME: show references to macro within file?
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
+  auto CurLoc = sourceLocationInMainFile(SM, Pos);
+  if (!CurLoc)
+return {};
+  const auto *IdentifierAtCursor =
+  syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
+  if (!IdentifierAtCursor)

[clang] 319ea2d - [OpenCL] Add atomic type builtins

2020-02-26 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2020-02-26T14:08:23Z
New Revision: 319ea2dd9e32cd10415e1f5060e84febf7c606c6

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

LOG: [OpenCL] Add atomic type builtins

Add atomic types and builtins operating on those atomic types to
`-fdeclare-opencl-builtins`.  The _explicit variants are left out of
this commit, as these take enum arguments that are not yet supported
by the `-fdeclare-opencl-builtins` machinery.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index f79bb54a8143..4ccb6b5fd49d 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -265,7 +265,7 @@ def Half  : Type<"half",  QualType<"HalfTy">>;
 def Size  : Type<"size_t",QualType<"getSizeType()">>;
 def PtrDiff   : Type<"ptr
diff _t", QualType<"getPointerDiffType()">>;
 def IntPtr: Type<"intptr_t",  QualType<"getIntPtrType()">>;
-def UIntPtr   : Type<"uintPtr_t", QualType<"getUIntPtrType()">>;
+def UIntPtr   : Type<"uintptr_t", QualType<"getUIntPtrType()">>;
 def Void  : Type<"void",  QualType<"VoidTy">>;
 
 // OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
@@ -290,6 +290,18 @@ def Image2dArrayMsaaDepth : 
Type<"image2d_array_msaa_depth_t", QualType<"OCLImag
 def Sampler   : Type<"sampler_t", QualType<"OCLSamplerTy">>;
 def Event : Type<"event_t", QualType<"OCLEventTy">>;
 
+// OpenCL v2.0 s6.13.11: Atomic integer and floating-point types.
+def AtomicInt : Type<"atomic_int", 
QualType<"getAtomicType(Context.IntTy)">>;
+def AtomicUInt: Type<"atomic_uint", 
QualType<"getAtomicType(Context.UnsignedIntTy)">>;
+def AtomicLong: Type<"atomic_long", 
QualType<"getAtomicType(Context.LongTy)">>;
+def AtomicULong   : Type<"atomic_ulong", 
QualType<"getAtomicType(Context.UnsignedLongTy)">>;
+def AtomicFloat   : Type<"atomic_float", 
QualType<"getAtomicType(Context.FloatTy)">>;
+def AtomicDouble  : Type<"atomic_double", 
QualType<"getAtomicType(Context.DoubleTy)">>;
+def AtomicIntPtr  : Type<"atomic_intptr_t", 
QualType<"getAtomicType(Context.getIntPtrType())">>;
+def AtomicUIntPtr : Type<"atomic_uintptr_t", 
QualType<"getAtomicType(Context.getUIntPtrType())">>;
+def AtomicSize: Type<"atomic_size_t", 
QualType<"getAtomicType(Context.getSizeType())">>;
+def AtomicPtrDiff : Type<"atomic_ptr
diff _t", QualType<"getAtomicType(Context.getPointerDiffType())">>;
+
 
//===--===//
 // Definitions of OpenCL gentype variants
 
//===--===//
@@ -984,6 +996,45 @@ foreach AS = [GlobalAS, LocalAS] in {
 }
   }
 }
+// OpenCL v2.0 s6.13.11 - Atomic Functions.
+let MinVersion = CL20 in {
+  foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
+  [AtomicLong, Long], [AtomicULong, ULong],
+  [AtomicFloat, Float], [AtomicDouble, Double]] in {
+def : Builtin<"atomic_init",
+[Void, PointerType, GenericAS>, 
TypePair[1]]>;
+def : Builtin<"atomic_store",
+[Void, PointerType, GenericAS>, 
TypePair[1]]>;
+def : Builtin<"atomic_load",
+[TypePair[1], PointerType, GenericAS>]>;
+def : Builtin<"atomic_exchange",
+[TypePair[1], PointerType, GenericAS>, 
TypePair[1]]>;
+foreach Variant = ["weak", "strong"] in {
+  def : Builtin<"atomic_compare_exchange_" # Variant,
+  [Bool, PointerType, GenericAS>,
+   PointerType, TypePair[1]]>;
+}
+  }
+
+  foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
+  [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],
+  [AtomicIntPtr, IntPtr, PtrDiff],
+  [AtomicUIntPtr, UIntPtr, PtrDiff]] in {
+foreach ModOp = ["add", "sub"] in {
+  def : Builtin<"atomic_fetch_" # ModOp,
+  [TypePair[1], PointerType, GenericAS>, 
TypePair[2]]>;
+}
+  }
+  foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
+  [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],
+  [AtomicIntPtr, IntPtr, IntPtr],
+  [AtomicUIntPtr, UIntPtr, UIntPtr]] in {
+foreach ModOp = ["or", "xor", "and", "min", "max"] in {
+  def : Builtin<"atomic_fetch_" # ModOp,
+  [TypePair[1], PointerType, GenericAS>, 
TypePair[2]]>;
+}
+  }
+}
 
 //
 // OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector 

[PATCH] D75171: [Analyzer] Fix for incorrect use of container and iterator checkers

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

Iterator checkers (and planned container checkers) need the option 
`aggressive-binary-operation-simplification` to be enabled. Without this option 
they may cause assertions. To prevent such misuse, this patch adds a preventive 
check which issues a warning and denies the registartion of the checker if this 
option is disabled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75171

Files:
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  
clang/test/Analysis/container-modeling-no-aggressive-binary-operation-simplification-warn.cpp
  
clang/test/Analysis/iterator-modeling-no-aggressive-binary-operation-simplification-no-crash.cpp


Index: 
clang/test/Analysis/iterator-modeling-no-aggressive-binary-operation-simplification-no-crash.cpp
===
--- /dev/null
+++ 
clang/test/Analysis/iterator-modeling-no-aggressive-binary-operation-simplification-no-crash.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_analyze_cc1 -std=c++11\
+// RUN: 
-analyzer-checker=core,cplusplus,debug.DebugIteratorModeling,debug.ExprInspection\
+// RUN: -analyzer-config c++-container-inlining=false %s 2>&1 | FileCheck %s
+
+// RUN: %clang_analyze_cc1 -std=c++11\
+// RUN: 
-analyzer-checker=core,cplusplus,debug.DebugIteratorModeling,debug.ExprInspection\
+// RUN: -analyzer-config c++-container-inlining=true -DINLINE=1 %s 2>&1 |\
+// RUN: FileCheck %s
+
+// CHECK: [ERROR] Checker alpha.cplusplus.ContainerModeling cannot be enabled 
without analyzer option aggressive-binary-operation-simplification.
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+template 
+long clang_analyzer_container_end(const Container&);
+template 
+long clang_analyzer_iterator_position(const Iterator&);
+
+void clang_analyzer_eval(bool);
+
+
+template 
+InputIterator nonStdFind(InputIterator first, InputIterator last,
+ const T &val) {
+  for (auto i = first; i != last; ++i) {
+if (*i == val) {
+  return i;
+}
+  }
+  return last;
+}
+
+void non_std_find(std::vector &V, int e) {
+  auto first = nonStdFind(V.begin(), V.end(), e);
+  clang_analyzer_eval(clang_analyzer_container_end(V) ==
+  clang_analyzer_iterator_position(first));
+  if (V.end() != first) {
+clang_analyzer_eval(clang_analyzer_container_end(V) ==
+clang_analyzer_iterator_position(first));
+  }
+}
Index: 
clang/test/Analysis/container-modeling-no-aggressive-binary-operation-simplification-warn.cpp
===
--- /dev/null
+++ 
clang/test/Analysis/container-modeling-no-aggressive-binary-operation-simplification-warn.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -std=c++11\
+// RUN: -analyzer-checker=core,cplusplus,alpha.cplusplus.ContainerModeling\
+// RUN: -analyzer-config c++-container-inlining=false %s 2>&1 | FileCheck %s
+
+// RUN: %clang_analyze_cc1 -std=c++11\
+// RUN: -analyzer-checker=core,cplusplus,alpha.cplusplus.ContainerModeling\
+// RUN: -analyzer-config c++-container-inlining=true -DINLINE=1 %s 2>&1 |\
+// RUN: FileCheck %s
+
+// CHECK: [ERROR] Checker alpha.cplusplus.ContainerModeling cannot be enabled 
without analyzer option aggressive-binary-operation-simplification.
Index: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
@@ -1031,10 +1031,23 @@
 
 } // namespace
 
+static bool checkAggressiveSimplificationEnabled(CheckerManager &mgr) {
+  if (!mgr.getAnalyzerOptions().ShouldAggressivelySimplifyBinaryOperation) {
+llvm::errs() << "[ERROR] Checker " << mgr.getCurrentCheckerName().getName()
+ << " cannot be enabled without analyzer option aggressive-"
+"binary-operation-simplification.\n";
+return false;
+  }
+  return true;
+}
+
 void ento::registerContainerModeling(CheckerManager &mgr) {
+  if (!checkAggressiveSimplificationEnabled(mgr))
+return;
+
   mgr.registerChecker();
 }
 
 bool ento::shouldRegisterContainerModeling(const LangOptions &LO) {
-  return true;
+  return LO.CPlusPlus;
 }


Index: clang/test/Analysis/iterator-modeling-no-aggressive-binary-operation-simplification-no-crash.cpp
===
--- /dev/null
+++ clang/test/Analysis/iterator-modeling-no-aggressive-binary-operation-simplification-no-crash.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_analyze_cc1 -std=c++11\
+// RUN: -analyzer-checker=core,cplusplus,debug.DebugIteratorModeling,debug.ExprInspection\
+// RUN: -analyzer-config c++-containe

[PATCH] D75022: clang-format: Extend AllowShortLoopsOnASingleLine to do ... while loops.

2020-02-26 Thread Mitchell via Phabricator via cfe-commits
mitchell-stellar accepted this revision.
mitchell-stellar added a comment.

Assuming this passes all existing tests, LGTM.


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

https://reviews.llvm.org/D75022



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


[PATCH] D75174: [clangd] use printQualifiedName to skip the inlinenamespace qualifiers.

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

symbols in libcpp are inside the inline namespace, printQualifierAsString will
print the inline namespace, which is unexpected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75174

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -593,6 +593,14 @@
  }
)cpp",
"not a supported kind", !HeaderFile, Index},
+   {R"cpp(// disallow rename on blacklisted symbols (e.g. std symbols)
+ namespace std {
+ inline namespace __u {
+ class str^ing {};
+ }
+ }
+   )cpp",
+   "not a supported kind", !HeaderFile, Index},
 
   {R"cpp(
  void foo(int);
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -110,7 +110,7 @@
 #include "StdSymbolMap.inc"
 #undef SYMBOL
   });
-  return StdSymbols->count(RenameDecl.getQualifiedNameAsString());
+  return StdSymbols->count(printQualifiedName(RenameDecl));
 }
 
 enum ReasonToReject {


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -593,6 +593,14 @@
  }
)cpp",
"not a supported kind", !HeaderFile, Index},
+   {R"cpp(// disallow rename on blacklisted symbols (e.g. std symbols)
+ namespace std {
+ inline namespace __u {
+ class str^ing {};
+ }
+ }
+   )cpp",
+   "not a supported kind", !HeaderFile, Index},
 
   {R"cpp(
  void foo(int);
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -110,7 +110,7 @@
 #include "StdSymbolMap.inc"
 #undef SYMBOL
   });
-  return StdSymbols->count(RenameDecl.getQualifiedNameAsString());
+  return StdSymbols->count(printQualifiedName(RenameDecl));
 }
 
 enum ReasonToReject {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75166: [clangd] Clean-up XRefs.cpp from Lexer usages and unnecessary SourceLoc transformations

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

- Handle llvm::Expected failures


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75166

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

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -43,6 +43,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -214,24 +215,35 @@
 }
   }
 
+  auto CurLoc = sourceLocationInMainFile(SM, Pos);
+  if (!CurLoc) {
+elog("locateSymbolAt failed to convert position to source location: {0}",
+ CurLoc.takeError());
+return {};
+  }
+
+  const auto &TB = AST.getTokens();
   // Macros are simple: there's no declaration/definition distinction.
   // As a consequence, there's no need to look them up in the index either.
-  SourceLocation IdentStartLoc = SM.getMacroArgExpandedLocation(
-  getBeginningOfIdentifier(Pos, AST.getSourceManager(), AST.getLangOpts()));
   std::vector Result;
-  if (auto M = locateMacroAt(IdentStartLoc, AST.getPreprocessor())) {
-if (auto Loc = makeLocation(AST.getASTContext(),
-M->Info->getDefinitionLoc(), *MainFilePath)) {
-  LocatedSymbol Macro;
-  Macro.Name = std::string(M->Name);
-  Macro.PreferredDeclaration = *Loc;
-  Macro.Definition = Loc;
-  Result.push_back(std::move(Macro));
-
-  // Don't look at the AST or index if we have a macro result.
-  // (We'd just return declarations referenced from the macro's
-  // expansion.)
-  return Result;
+  const auto *IdentifierCoveringCursor =
+  syntax::spelledIdentifierTouching(*CurLoc, TB);
+  if (IdentifierCoveringCursor) {
+if (auto M = locateMacroAt(IdentifierCoveringCursor->location(),
+   AST.getPreprocessor())) {
+  if (auto Loc = makeLocation(AST.getASTContext(),
+  M->Info->getDefinitionLoc(), *MainFilePath)) {
+LocatedSymbol Macro;
+Macro.Name = std::string(M->Name);
+Macro.PreferredDeclaration = *Loc;
+Macro.Definition = Loc;
+Result.push_back(std::move(Macro));
+
+// Don't look at the AST or index if we have a macro result.
+// (We'd just return declarations referenced from the macro's
+// expansion.)
+return Result;
+  }
 }
   }
 
@@ -244,15 +256,6 @@
   // Keep track of SymbolID -> index mapping, to fill in index data later.
   llvm::DenseMap ResultIndex;
 
-  SourceLocation SourceLoc;
-  if (auto L = sourceLocationInMainFile(SM, Pos)) {
-SourceLoc = *L;
-  } else {
-elog("locateSymbolAt failed to convert position to source location: {0}",
- L.takeError());
-return Result;
-  }
-
   auto AddResultDecl = [&](const NamedDecl *D) {
 const NamedDecl *Def = getDefinition(D);
 const NamedDecl *Preferred = Def ? Def : D;
@@ -277,16 +280,15 @@
   // Emit all symbol locations (declaration or definition) from AST.
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
-  for (const NamedDecl *D : getDeclAtPosition(AST, SourceLoc, Relations)) {
+  for (const NamedDecl *D : getDeclAtPosition(AST, *CurLoc, Relations)) {
 // Special case: void foo() ^override: jump to the overridden method.
 if (const auto *CMD = llvm::dyn_cast(D)) {
-  const InheritableAttr* Attr = D->getAttr();
+  const InheritableAttr *Attr = D->getAttr();
   if (!Attr)
 Attr = D->getAttr();
-  const syntax::Token *Tok =
-  spelledIdentifierTouching(SourceLoc, AST.getTokens());
-  if (Attr && Tok &&
-  SM.getSpellingLoc(Attr->getLocation()) == Tok->location()) {
+  if (Attr && IdentifierCoveringCursor &&
+  SM.getSpellingLoc(Attr->getLocation()) ==
+  IdentifierCoveringCursor->location()) {
 // We may be overridding multiple methods - offer them all.
 for (const NamedDecl *ND : CMD->overridden_methods())
   AddResultDecl(ND);
@@ -296,8 +298,9 @@
 
 // Special case: the point of declaration of a template specialization,
 // it's more useful to navigate to the template declaration.
-if (SM.getMacroArgExpandedLocation(D->getLocation()) == IdentStartLoc) {
-  if (auto *CTSD = dyn_cast(D)) {
+if (auto *CTSD = dyn_cast(D)) {
+  if (IdentifierCoveringCursor &&
+  D->getLocation() == IdentifierCoveringCursor->location()) {
 AddResultDecl(CTSD->getSpecializedTemplate());
 continue;
   }
@@ -416,12 +419,17 @@
   // FIXME: show references to macro within file?
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation

[PATCH] D31337: Use virtual functions in ParsedAttrInfo instead of function pointers

2020-02-26 Thread John Brawn via Phabricator via cfe-commits
john.brawn marked 2 inline comments as done.
john.brawn added inline comments.



Comment at: clang/lib/Sema/ParsedAttr.cpp:144
+  // otherwise return a default ParsedAttrInfo.
+  if (A.getKind() < sizeof(AttrInfoMap)/sizeof(AttrInfoMap[0]))
+return *AttrInfoMap[A.getKind()];

aaron.ballman wrote:
> You can use `llvm::array_lengthof()` here instead.
Will do.



Comment at: clang/utils/TableGen/ClangAttrEmitter.cpp:3646
+OS << "};\n";
+OS << "ParsedAttrInfo" << I->first << " ParsedAttrInfo" << I->first << 
"::Instance;\n";
   }

aaron.ballman wrote:
> Would it make sense for this object to be `const` under the assumption that 
> once we've generated a `ParsedAttrInfo` object, we don't want to modify its 
> properties? I'm not certain if trying to be const-correct here would be a 
> burden or not, so I don't insist on a change unless it's trivial to support.
Making this const actually is trivial, so I'll do that.


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

https://reviews.llvm.org/D31337



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


[PATCH] D75034: [clang-format] use spaces for alignment with UT_ForContinuationAndIndentation

2020-02-26 Thread Mitchell via Phabricator via cfe-commits
mitchell-stellar added a subscriber: mxbOctasic.
mitchell-stellar added a comment.

Digging through the history, it seems this behavior was explicitly desired: 
https://reviews.llvm.org/D19028. @mxbOctasic was the original author and 
perhaps could comment. Regardless, I think there should be a new option.


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

https://reviews.llvm.org/D75034



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


[PATCH] D75176: [clangd] Get rid of getBeginningOfIdentifier helper

2020-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.
kadircet added a parent revision: D75166: [clangd] Clean-up XRefs.cpp from 
Lexer usages and unnecessary SourceLoc transformations.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75176

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
  clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -312,60 +312,6 @@
   }
 }
 
-TEST(SourceCodeTests, GetBeginningOfIdentifier) {
-  std::string Preamble = R"cpp(
-struct Bar { int func(); };
-#define MACRO(X) void f() { X; }
-Bar* bar;
-  )cpp";
-  // First ^ is the expected beginning, last is the search position.
-  for (const std::string &Text : std::vector{
-   "int ^f^oo();", // inside identifier
-   "int ^foo();",  // beginning of identifier
-   "int ^foo^();", // end of identifier
-   "int foo(^);",  // non-identifier
-   "^int foo();",  // beginning of file (can't back up)
-   "int ^f0^0();", // after a digit (lexing at N-1 is wrong)
-   "/^/ comments", // non-interesting token
-   "void f(int abc) { abc ^ ++; }",// whitespace
-   "void f(int abc) { ^abc^++; }", // range of identifier
-   "void f(int abc) { ++^abc^; }", // range of identifier
-   "void f(int abc) { ++^abc; }",  // range of identifier
-   "void f(int abc) { ^+^+abc; }", // range of operator
-   "void f(int abc) { ^abc^ ++; }",// range of identifier
-   "void f(int abc) { abc ^++^; }",// range of operator
-   "void f(int abc) { ^++^ abc; }",// range of operator
-   "void f(int abc) { ++ ^abc^; }",// range of identifier
-   "void f(int abc) { ^++^/**/abc; }", // range of operator
-   "void f(int abc) { ++/**/^abc; }",  // range of identifier
-   "void f(int abc) { ^abc^/**/++; }", // range of identifier
-   "void f(int abc) { abc/**/^++; }",  // range of operator
-   "void f() {^ }", // outside of identifier and operator
-   "int ^λλ^λ();",  // UTF-8 handled properly when backing up
-
-   // identifier in macro arg
-   "MACRO(bar->^func())",  // beginning of identifier
-   "MACRO(bar->^fun^c())", // inside identifier
-   "MACRO(bar->^func^())", // end of identifier
-   "MACRO(^bar->func())",  // begin identifier
-   "MACRO(^bar^->func())", // end identifier
-   "^MACRO(bar->func())",  // beginning of macro name
-   "^MAC^RO(bar->func())", // inside macro name
-   "^MACRO^(bar->func())", // end of macro name
-   }) {
-std::string WithPreamble = Preamble + Text;
-Annotations TestCase(WithPreamble);
-auto AST = TestTU::withCode(TestCase.code()).build();
-const auto &SourceMgr = AST.getSourceManager();
-SourceLocation Actual = getBeginningOfIdentifier(
-TestCase.points().back(), SourceMgr, AST.getLangOpts());
-Position ActualPos = offsetToPosition(
-TestCase.code(),
-SourceMgr.getFileOffset(SourceMgr.getSpellingLoc(Actual)));
-EXPECT_EQ(TestCase.points().front(), ActualPos) << Text;
-  }
-}
-
 TEST(SourceCodeTests, CollectIdentifiers) {
   auto Style = format::getLLVMStyle();
   auto IDs = collectIdentifiers(R"cpp(
@@ -481,9 +427,11 @@
)cpp");
   TestTU TU = TestTU::withCode(Code.code());
   auto AST = TU.build();
-  auto Loc = getBeginningOfIdentifier(Code.point(), AST.getSourceManager(),
-  AST.getLangOpts());
-  auto Result = locateMacroAt(Loc, AST.getPreprocessor());
+  auto CurLoc = sourceLocationInMainFile(AST.getSourceManager(), Code.point());
+  ASSERT_TRUE(bool(CurLoc));
+  const auto *Id = syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
+  ASSERT_TRUE(Id);
+  auto Result = locateMacroAt(Id->location(), AST.getPreprocessor());
   ASSERT_TRUE(Result);
   EXPECT_THAT(*Result, MacroName("MACRO"));
 }
Index: clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
===
--- clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
+++ clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
@@ -87,9 +87,9 @@
   if (ExpectedRefs.empty())
 break;
 
-  auto Loc = getBeginningOfIdentifier(ExpectedRefs.begin()->start, SM,
-  AST.getLangOpts());
-  auto Macro = locateMacroAt(Loc, PP);
+  auto Loc = so

[PATCH] D74692: [clang-tidy][bugprone-use-after-move] Warn on std::move for consts

2020-02-26 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:329
   // CHECK-NOTES: [[@LINE-3]]:7: note: move occurred here
+  // CHECK-NOTES: [[@LINE-6]]:7: note: std::move of the const expression 
{{.*}}
 };

It continues to seem silly to me that you give an extra note here saying that 
line 325 doesn't do anything, when of course line 336 doesn't do anything 
either (and you don't give any extra note there).

This clang-tidy warning isn't supposed to be about what //physically happens// 
in the machine code during any particular compilation run; it's supposed to be 
about helping the user avoid //semantic// bugs by cleaning up their codebase's 
//logical// behavior. The rule is "don't use things after moving from them," 
period.

Analogously, if there were a clang-tidy warning to say "always indent four 
spaces after an `if`," and you proposed to add a note to some cases that said 
"...but here a three-space indent is OK, because C++ is whitespace-insensitive" 
— I'd also find //that// note to be mildly objectionable. We want to train 
people to do the right thing, not to do the right thing "except in this case 
because hey, it doesn't matter to the machine."


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

https://reviews.llvm.org/D74692



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


[PATCH] D72153: [libTooling] Add function to determine associated text of a declaration.

2020-02-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel reopened this revision.
ymandel added a comment.
This revision is now accepted and ready to land.

Reopening for fix to failing tests that resulted in revert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72153



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


[PATCH] D72153: [libTooling] Add function to determine associated text of a declaration.

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

Fix failing test under msvc compatibility.

Adds -fno-delayed-template-parsing to compilation arguments in tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72153

Files:
  clang/include/clang/Tooling/Transformer/SourceCode.h
  clang/lib/Tooling/Transformer/SourceCode.cpp
  clang/unittests/Tooling/SourceCodeTest.cpp

Index: clang/unittests/Tooling/SourceCodeTest.cpp
===
--- clang/unittests/Tooling/SourceCodeTest.cpp
+++ clang/unittests/Tooling/SourceCodeTest.cpp
@@ -20,6 +20,7 @@
 using llvm::Failed;
 using llvm::Succeeded;
 using llvm::ValueIs;
+using tooling::getAssociatedRange;
 using tooling::getExtendedText;
 using tooling::getRangeForEdit;
 using tooling::getText;
@@ -51,6 +52,28 @@
  arg.getBegin() == R.getBegin() && arg.getEnd() == R.getEnd();
 }
 
+MATCHER_P2(EqualsAnnotatedRange, SM, R, "") {
+  if (arg.getBegin().isMacroID()) {
+*result_listener << "which starts in a macro";
+return false;
+  }
+  if (arg.getEnd().isMacroID()) {
+*result_listener << "which ends in a macro";
+return false;
+  }
+
+  unsigned Begin = SM->getFileOffset(arg.getBegin());
+  unsigned End = SM->getFileOffset(arg.getEnd());
+
+  *result_listener << "which is [" << Begin << ",";
+  if (arg.isTokenRange()) {
+*result_listener << End << "]";
+return Begin == R.Begin && End + 1 == R.End;
+  }
+  *result_listener << End << ")";
+  return Begin == R.Begin && End == R.End;
+}
+
 static ::testing::Matcher AsRange(const SourceManager &SM,
llvm::Annotations::Range R) {
   return EqualsRange(CharSourceRange::getCharRange(
@@ -58,6 +81,40 @@
   SM.getLocForStartOfFile(SM.getMainFileID()).getLocWithOffset(R.End)));
 }
 
+// Base class for visitors that expect a single match corresponding to a
+// specific annotated range.
+template  class AnnotatedCodeVisitor : public TestVisitor {
+  llvm::Annotations Code;
+  int MatchCount = 0;
+
+public:
+  AnnotatedCodeVisitor() : Code("$r[[]]") {}
+  bool VisitDeclHelper(Decl *Decl) {
+// Only consider explicit declarations.
+if (Decl->isImplicit())
+  return true;
+
+++MatchCount;
+EXPECT_THAT(getAssociatedRange(*Decl, *this->Context),
+EqualsAnnotatedRange(&this->Context->getSourceManager(),
+ Code.range("r")))
+<< Code.code();
+return true;
+  }
+
+  bool runOverAnnotated(llvm::StringRef AnnotatedCode,
+std::vector Args = {}) {
+Code = llvm::Annotations(AnnotatedCode);
+MatchCount = 0;
+Args.push_back("-std=c++11");
+Args.push_back("-fno-delayed-template-parsing");
+bool result = tooling::runToolOnCodeWithArgs(this->CreateTestAction(),
+ Code.code(), Args);
+EXPECT_EQ(MatchCount, 1) << AnnotatedCode;
+return result;
+  }
+};
+
 TEST(SourceCodeTest, getText) {
   CallsVisitor Visitor;
 
@@ -126,6 +183,212 @@
   Visitor.runOver("int foo() { return foo() + 3; }");
 }
 
+TEST(SourceCodeTest, getAssociatedRange) {
+  struct VarDeclsVisitor : AnnotatedCodeVisitor {
+bool VisitVarDecl(VarDecl *Decl) { return VisitDeclHelper(Decl); }
+  };
+  VarDeclsVisitor Visitor;
+
+  // Includes semicolon.
+  Visitor.runOverAnnotated("$r[[int x = 4;]]");
+
+  // Includes newline and semicolon.
+  Visitor.runOverAnnotated("$r[[int x = 4;\n]]");
+
+  // Includes trailing comments.
+  Visitor.runOverAnnotated("$r[[int x = 4; // Comment\n]]");
+  Visitor.runOverAnnotated("$r[[int x = 4; /* Comment */\n]]");
+
+  // Does *not* include trailing comments when another entity appears between
+  // the decl and the comment.
+  Visitor.runOverAnnotated("$r[[int x = 4;]] class C {}; // Comment\n");
+
+  // Includes attributes.
+  Visitor.runOverAnnotated(R"cpp(
+  #define ATTR __attribute__((deprecated("message")))
+  $r[[ATTR
+  int x;]])cpp");
+
+  // Includes attributes and comments together.
+  Visitor.runOverAnnotated(R"cpp(
+  #define ATTR __attribute__((deprecated("message")))
+  $r[[ATTR
+  // Commment.
+  int x;]])cpp");
+}
+
+TEST(SourceCodeTest, getAssociatedRangeClasses) {
+  struct RecordDeclsVisitor : AnnotatedCodeVisitor {
+bool VisitRecordDecl(RecordDecl *Decl) { return VisitDeclHelper(Decl); }
+  };
+  RecordDeclsVisitor Visitor;
+
+  Visitor.runOverAnnotated("$r[[class A;]]");
+  Visitor.runOverAnnotated("$r[[class A {};]]");
+
+  // Includes leading template annotation.
+  Visitor.runOverAnnotated("$r[[template  class A;]]");
+  Visitor.runOverAnnotated("$r[[template  class A {};]]");
+}
+
+TEST(SourceCodeTest, getAssociatedRangeClassTemplateSpecializations) {
+  struct CXXRecordDeclsVisitor : AnnotatedCodeVisitor {
+bool VisitCXXRecordDecl(CXXRecordDecl *Decl) {
+  retur

[clang] 38b4516 - [libTooling] Add function to determine associated text of a declaration.

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

Author: Yitzhak Mandelbaum
Date: 2020-02-26T09:56:48-05:00
New Revision: 38b4516de8a4a791d17085d37f95e3cc15c359f9

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

LOG: [libTooling] Add function to determine associated text of a declaration.

Summary:
Second attempt -- the first was reverted in commit 
0e480b39c66143ad142f9a30d8d40e49d7d7b0ce, because of test breakages. This 
revision fixes the cause of the test breakages.

Original description follows:
This patch adds `getAssociatedRange` which, for a given decl, computes preceding
and trailing text that would conceptually be associated with the decl by the
reader. This includes comments, whitespace, and separators like ';'.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Transformer/SourceCode.h
clang/lib/Tooling/Transformer/SourceCode.cpp
clang/unittests/Tooling/SourceCodeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Transformer/SourceCode.h 
b/clang/include/clang/Tooling/Transformer/SourceCode.h
index 1b92a117f44c..2c7eb65371cf 100644
--- a/clang/include/clang/Tooling/Transformer/SourceCode.h
+++ b/clang/include/clang/Tooling/Transformer/SourceCode.h
@@ -20,9 +20,10 @@
 namespace clang {
 namespace tooling {
 
-/// Extends \p Range to include the token \p Next, if it immediately follows 
the
-/// end of the range. Otherwise, returns \p Range unchanged.
-CharSourceRange maybeExtendRange(CharSourceRange Range, tok::TokenKind Next,
+/// Extends \p Range to include the token \p Terminator, if it immediately
+/// follows the end of the range. Otherwise, returns \p Range unchanged.
+CharSourceRange maybeExtendRange(CharSourceRange Range,
+ tok::TokenKind Terminator,
  ASTContext &Context);
 
 /// Returns the source range spanning the node, extended to include \p Next, if
@@ -35,6 +36,13 @@ CharSourceRange getExtendedRange(const T &Node, 
tok::TokenKind Next,
   Next, Context);
 }
 
+/// Returns the logical source range of the node extended to include associated
+/// comments and whitespace before and after the node, and associated
+/// terminators. The returned range consists of file locations, if valid file
+/// locations can be found for the associated content; otherwise, an invalid
+/// range is returned.
+CharSourceRange getAssociatedRange(const Decl &D, ASTContext &Context);
+
 /// Returns the source-code text in the specified range.
 StringRef getText(CharSourceRange Range, const ASTContext &Context);
 

diff  --git a/clang/lib/Tooling/Transformer/SourceCode.cpp 
b/clang/lib/Tooling/Transformer/SourceCode.cpp
index 5c1f8b46fe42..8d59487ea7ae 100644
--- a/clang/lib/Tooling/Transformer/SourceCode.cpp
+++ b/clang/lib/Tooling/Transformer/SourceCode.cpp
@@ -10,6 +10,13 @@
 //
 
//===--===//
 #include "clang/Tooling/Transformer/SourceCode.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
+#include "clang/AST/Comment.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Expr.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/Support/Errc.h"
 
@@ -84,3 +91,302 @@ clang::tooling::getRangeForEdit(const CharSourceRange 
&EditRange,
   return Range;
 
 }
+
+static bool startsWithNewline(const SourceManager &SM, const Token &Tok) {
+  return isVerticalWhitespace(SM.getCharacterData(Tok.getLocation())[0]);
+}
+
+static bool contains(const std::set &Terminators,
+ const Token &Tok) {
+  return Terminators.count(Tok.getKind()) > 0;
+}
+
+// Returns the exclusive, *file* end location of the entity whose last token is
+// at location 'EntityLast'. That is, it returns the location one past the last
+// relevant character.
+//
+// Associated tokens include comments, horizontal whitespace and 'Terminators'
+// -- optional tokens, which, if any are found, will be included; if
+// 'Terminators' is empty, we will not include any extra tokens beyond comments
+// and horizontal whitespace.
+static SourceLocation
+getEntityEndLoc(const SourceManager &SM, SourceLocation EntityLast,
+const std::set &Terminators,
+const LangOptions &LangOpts) {
+  assert(EntityLast.isValid() && "Invalid end location found.");
+
+  // We remember the last location of a non-horizontal-whitespace token we have
+  // lexed; this is the location up to which we will want to delete.
+  // FIXME: Support using the spelling loc here for cases where we want to
+  // analyze the macro text.
+
+  CharSourceRange ExpansionRange = SM.getExpansionRange(E

[PATCH] D44609: [clang-format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2020-02-26 Thread Christophe Calmejane via Phabricator via cfe-commits
christophe-calmejane added a comment.

In D44609#1875172 , @Wawha wrote:

> In D44609#1871612 , @MyDeveloperDay 
> wrote:
>
> > Correct follow that description on how to request commit access
>
>
> It's done. I have the commit right, and push that change on github : 
> https://github.com/llvm/llvm-project/commit/fa0118e6e588fe303b08e7e06ba28ac1f8d50c68
>
> Thank you for the review and advices!


Nice to finally see this patch integrated!

But, it looks like you didn't include all the test case I posted 1.5y ago in 
this post, that are still problematic and not formatting correctly with your 
patch:
For example, this simple case do not format correctly:

  paramBeforeAndAfterLambda(8,[](int x){call();},5);

The output is:

  paramBeforeAndAfterLambda(
  8,
  [](int x)
  {
  call();
  },
  5);

although I would expect to see

  paramBeforeAndAfterLambda(8,
  [](int x)
  {
  call();
  },
  5);

See my proposed fix in the discussion, but note that I don't think it's clean 
enough to be accepted :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D44609



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


[PATCH] D72153: [libTooling] Add function to determine associated text of a declaration.

2020-02-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG38b4516de8a4: [libTooling] Add function to determine 
associated text of a declaration. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72153

Files:
  clang/include/clang/Tooling/Transformer/SourceCode.h
  clang/lib/Tooling/Transformer/SourceCode.cpp
  clang/unittests/Tooling/SourceCodeTest.cpp

Index: clang/unittests/Tooling/SourceCodeTest.cpp
===
--- clang/unittests/Tooling/SourceCodeTest.cpp
+++ clang/unittests/Tooling/SourceCodeTest.cpp
@@ -20,6 +20,7 @@
 using llvm::Failed;
 using llvm::Succeeded;
 using llvm::ValueIs;
+using tooling::getAssociatedRange;
 using tooling::getExtendedText;
 using tooling::getRangeForEdit;
 using tooling::getText;
@@ -51,6 +52,28 @@
  arg.getBegin() == R.getBegin() && arg.getEnd() == R.getEnd();
 }
 
+MATCHER_P2(EqualsAnnotatedRange, SM, R, "") {
+  if (arg.getBegin().isMacroID()) {
+*result_listener << "which starts in a macro";
+return false;
+  }
+  if (arg.getEnd().isMacroID()) {
+*result_listener << "which ends in a macro";
+return false;
+  }
+
+  unsigned Begin = SM->getFileOffset(arg.getBegin());
+  unsigned End = SM->getFileOffset(arg.getEnd());
+
+  *result_listener << "which is [" << Begin << ",";
+  if (arg.isTokenRange()) {
+*result_listener << End << "]";
+return Begin == R.Begin && End + 1 == R.End;
+  }
+  *result_listener << End << ")";
+  return Begin == R.Begin && End == R.End;
+}
+
 static ::testing::Matcher AsRange(const SourceManager &SM,
llvm::Annotations::Range R) {
   return EqualsRange(CharSourceRange::getCharRange(
@@ -58,6 +81,40 @@
   SM.getLocForStartOfFile(SM.getMainFileID()).getLocWithOffset(R.End)));
 }
 
+// Base class for visitors that expect a single match corresponding to a
+// specific annotated range.
+template  class AnnotatedCodeVisitor : public TestVisitor {
+  llvm::Annotations Code;
+  int MatchCount = 0;
+
+public:
+  AnnotatedCodeVisitor() : Code("$r[[]]") {}
+  bool VisitDeclHelper(Decl *Decl) {
+// Only consider explicit declarations.
+if (Decl->isImplicit())
+  return true;
+
+++MatchCount;
+EXPECT_THAT(getAssociatedRange(*Decl, *this->Context),
+EqualsAnnotatedRange(&this->Context->getSourceManager(),
+ Code.range("r")))
+<< Code.code();
+return true;
+  }
+
+  bool runOverAnnotated(llvm::StringRef AnnotatedCode,
+std::vector Args = {}) {
+Code = llvm::Annotations(AnnotatedCode);
+MatchCount = 0;
+Args.push_back("-std=c++11");
+Args.push_back("-fno-delayed-template-parsing");
+bool result = tooling::runToolOnCodeWithArgs(this->CreateTestAction(),
+ Code.code(), Args);
+EXPECT_EQ(MatchCount, 1) << AnnotatedCode;
+return result;
+  }
+};
+
 TEST(SourceCodeTest, getText) {
   CallsVisitor Visitor;
 
@@ -126,6 +183,212 @@
   Visitor.runOver("int foo() { return foo() + 3; }");
 }
 
+TEST(SourceCodeTest, getAssociatedRange) {
+  struct VarDeclsVisitor : AnnotatedCodeVisitor {
+bool VisitVarDecl(VarDecl *Decl) { return VisitDeclHelper(Decl); }
+  };
+  VarDeclsVisitor Visitor;
+
+  // Includes semicolon.
+  Visitor.runOverAnnotated("$r[[int x = 4;]]");
+
+  // Includes newline and semicolon.
+  Visitor.runOverAnnotated("$r[[int x = 4;\n]]");
+
+  // Includes trailing comments.
+  Visitor.runOverAnnotated("$r[[int x = 4; // Comment\n]]");
+  Visitor.runOverAnnotated("$r[[int x = 4; /* Comment */\n]]");
+
+  // Does *not* include trailing comments when another entity appears between
+  // the decl and the comment.
+  Visitor.runOverAnnotated("$r[[int x = 4;]] class C {}; // Comment\n");
+
+  // Includes attributes.
+  Visitor.runOverAnnotated(R"cpp(
+  #define ATTR __attribute__((deprecated("message")))
+  $r[[ATTR
+  int x;]])cpp");
+
+  // Includes attributes and comments together.
+  Visitor.runOverAnnotated(R"cpp(
+  #define ATTR __attribute__((deprecated("message")))
+  $r[[ATTR
+  // Commment.
+  int x;]])cpp");
+}
+
+TEST(SourceCodeTest, getAssociatedRangeClasses) {
+  struct RecordDeclsVisitor : AnnotatedCodeVisitor {
+bool VisitRecordDecl(RecordDecl *Decl) { return VisitDeclHelper(Decl); }
+  };
+  RecordDeclsVisitor Visitor;
+
+  Visitor.runOverAnnotated("$r[[class A;]]");
+  Visitor.runOverAnnotated("$r[[class A {};]]");
+
+  // Includes leading template annotation.
+  Visitor.runOverAnnotated("$r[[template  class A;]]");
+  Visitor.runOverAnnotated("$r[[template  class A {};]]");
+}
+
+TEST(SourceCodeTest, getAssociatedRangeClassTemplateSpecializations) {
+  struct CXXRecordDeclsVisitor : AnnotatedCodeVisitor {
+bool VisitCXXRecordDecl(CXXRecordDecl *Dec

[clang] 41a6612 - Put microsoft template parameter shadow warning behind separate flag (PR44794)

2020-02-26 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-02-26T16:04:40+01:00
New Revision: 41a6612ea8afc5254e4de3aca55628d37f0be433

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

LOG: Put microsoft template parameter shadow warning behind separate flag 
(PR44794)

Differential revision: https://reviews.llvm.org/D75121

Added: 
clang/test/SemaCXX/microsoft-template-shadow.cpp

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 77db3db09cdb..6c79ea591734 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1018,7 +1018,8 @@ def MicrosoftExplicitConstructorCall : DiagGroup<
 def MicrosoftEnumValue : DiagGroup<"microsoft-enum-value">;
 def MicrosoftDefaultArgRedefinition :
 DiagGroup<"microsoft-default-arg-redefinition">;
-def MicrosoftTemplate : DiagGroup<"microsoft-template">;
+def MicrosoftTemplateShadow : DiagGroup<"microsoft-template-shadow">;
+def MicrosoftTemplate : DiagGroup<"microsoft-template", 
[MicrosoftTemplateShadow]>;
 def MicrosoftInconsistentDllImport : DiagGroup<"inconsistent-dllimport">;
 def MicrosoftRedeclareStatic : DiagGroup<"microsoft-redeclare-static">;
 def MicrosoftEnumForwardReference :

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 91688cf99f9c..5cfb12967f14 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4273,7 +4273,7 @@ def err_ovl_no_viable_literal_operator : Error<
 def err_template_param_shadow : Error<
   "declaration of %0 shadows template parameter">;
 def ext_template_param_shadow : ExtWarn<
-  err_template_param_shadow.Text>, InGroup;
+  err_template_param_shadow.Text>, InGroup;
 def note_template_param_here : Note<"template parameter is declared here">;
 def warn_template_export_unsupported : Warning<
   "exported templates are unsupported">;

diff  --git a/clang/test/SemaCXX/microsoft-template-shadow.cpp 
b/clang/test/SemaCXX/microsoft-template-shadow.cpp
new file mode 100644
index ..ab2ffdefdd8f
--- /dev/null
+++ b/clang/test/SemaCXX/microsoft-template-shadow.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify 
-fms-compatibility -Wno-microsoft -Wmicrosoft-template-shadow
+
+template  // expected-note {{template parameter is declared here}}
+struct Outmost {
+  template  // expected-warning {{declaration of 'T' shadows 
template parameter}}
+  struct Inner {
+void f() {
+  T *var;
+}
+  };
+};



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


[PATCH] D75121: Put microsoft template parameter shadow warning behind separate flag (PR44794)

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

In D75121#1891879 , @rnk wrote:

> code lgtm
>
> Should we have a standalone test for this? Something that compiles with 
> `clang -cc1 -Wno-microsoft -Wmicrosoft-template-shadow` and looks for the 
> shadowing warnings?


Adding one before committing.


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

https://reviews.llvm.org/D75121



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


[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

2020-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 246711.
balazske added a comment.

Really reformat, bugfixes, and updated tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream.c

Index: clang/test/Analysis/stream.c
===
--- clang/test/Analysis/stream.c
+++ clang/test/Analysis/stream.c
@@ -108,19 +108,56 @@
 
 void f_double_close(void) {
   FILE *p = fopen("foo", "r");
-  fclose(p); 
-  fclose(p); // expected-warning {{Try to close a file Descriptor already closed. Cause undefined behaviour}}
+  if (!p)
+return;
+  fclose(p);
+  fclose(p); // expected-warning {{File descriptor is used after it was closed}}
 }
 
 void f_double_close_alias(void) {
   FILE *p1 = fopen("foo", "r");
+  if (!p1)
+return;
   FILE *p2 = p1;
   fclose(p1);
-  fclose(p2); // expected-warning {{Try to close a file Descriptor already closed. Cause undefined behaviour}}
+  fclose(p2); // expected-warning {{File descriptor is used after it was closed}}
+}
+
+void f_use_after_close(void) {
+  FILE *p = fopen("foo", "r");
+  if (!p)
+return;
+  fclose(p);
+  clearerr(p); // expected-warning {{File descriptor is used after it was closed}}
+}
+
+void f_open_after_close(void) {
+  FILE *p = fopen("foo", "r");
+  if (!p)
+return;
+  fclose(p);
+  p = fopen("foo", "r");
+  if (!p)
+return;
+  fclose(p);
+}
+
+void f_reopen_after_close(void) {
+  FILE *p = fopen("foo", "r");
+  if (!p)
+return;
+  fclose(p);
+  // Allow reopen after close.
+  p = freopen("foo", "w", p);
+  if (!p)
+return;
+  fclose(p);
 }
 
 void f_leak(int c) {
   FILE *p = fopen("foo.c", "r");
+  if (!p)
+return;
   if(c)
 return; // expected-warning {{Opened File never closed. Potential Resource leak}}
   fclose(p);
@@ -155,13 +192,13 @@
 if (f2) {
   // Check if f1 and f2 point to the same stream.
   fclose(f1);
-  fclose(f2); // expected-warning {{Try to close a file Descriptor already closed. Cause undefined behaviour}}
+  fclose(f2); // expected-warning {{File descriptor is used after it was closed}}
 } else {
   // Reopen failed.
-  // f1 points now to a possibly invalid stream but this condition is currently not checked.
-  // f2 is NULL.
-  rewind(f1);
-  rewind(f2); // expected-warning {{Stream pointer might be NULL}}
+  // f1 is non-NULL but points to a possibly invalid stream.
+  rewind(f1); // expected-warning {{(Re-)Opening the file descriptor has failed}}
+  // f2 is NULL but the previous error stops the checker.
+  rewind(f2);
 }
   }
 }
@@ -170,9 +207,9 @@
   FILE *f1 = fopen("foo.c", "r");
   if (f1) {
 // Unchecked result of freopen.
-// The f1 may be invalid after this call (not checked by the checker).
+// The f1 may be invalid after this call.
 freopen(0, "w", f1);
-rewind(f1);
+rewind(f1); // expected-warning {{(Re-)Opening the file descriptor has failed}}
 fclose(f1);
   }
 }
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -34,8 +34,8 @@
 
   bool isOpened() const { return K == Opened; }
   bool isClosed() const { return K == Closed; }
-  //bool isOpenFailed() const { return K == OpenFailed; }
-  //bool isEscaped() const { return K == Escaped; }
+  bool isOpenFailed() const { return K == OpenFailed; }
+  // bool isEscaped() const { return K == Escaped; }
 
   bool operator==(const StreamState &X) const { return K == X.K; }
 
@@ -44,104 +44,163 @@
   static StreamState getOpenFailed() { return StreamState(OpenFailed); }
   static StreamState getEscaped() { return StreamState(Escaped); }
 
-  void Profile(llvm::FoldingSetNodeID &ID) const {
-ID.AddInteger(K);
-  }
+  void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(K); }
 };
 
 class StreamChecker;
+struct FnDescription;
+using FnCheck = std::function;
 
-using FnCheck = std::function;
+using ArgNoTy = unsigned int;
+static const ArgNoTy ArgNone = std::numeric_limits::max();
 
 struct FnDescription {
+  FnCheck PreFn;
   FnCheck EvalFn;
+  ArgNoTy StreamArgNo;
 };
 
-class StreamChecker : public Checker {
+class StreamChecker
+: public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
-  BT_doubleclose, BT_ResourceLeak;
+  BT_UseAfterClose, BT_UseAfterOpenFailed, BT_ResourceLeak;
 
 public:
+  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
 
 private:
-
   CallDescriptionMap FnDescriptions = {
-  {{"fopen"}, {&StreamChecker::evalFopen}},
-  {{"f

[PATCH] D75176: [clangd] Get rid of getBeginningOfIdentifier helper

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

Hooray!




Comment at: clang-tools-extra/clangd/Hover.cpp:537
 
+  // We prefer the identifiers if any, otherwise make use of the first token.
+  SourceLocation SourceLocationBeg = TokensAroundCursor.front().location();

first -> last I think, better explained as rightmost. See 
SelectionTree::create().



Comment at: clang-tools-extra/clangd/Hover.cpp:537
 
+  // We prefer the identifiers if any, otherwise make use of the first token.
+  SourceLocation SourceLocationBeg = TokensAroundCursor.front().location();

sammccall wrote:
> first -> last I think, better explained as rightmost. See 
> SelectionTree::create().
actually, if this is really only used for macros and auto, you could pull out 
those specific cases (define AutoLoc and IdentifierLoc and initialize them by 
looping over the touching tokens). Seems a bit simpler/more direct/less risk of 
reuse for other things?



Comment at: clang-tools-extra/clangd/Hover.cpp:540
+  for (const auto &Tok : TokensAroundCursor) {
+if (Tok.kind() != tok::identifier)
+  continue;

This deserves a comment, it's a different strategy than SelectionTree that 
should yield the same result.

("In general we prefer the touching token that works over the one that doesn't, 
see SelectionTree::create(). This location is used only for triggering on 
macros and auto, so simply choosing the lone identifier-or-keyword token is 
equivalent")



Comment at: clang-tools-extra/clangd/Hover.cpp:540
+  for (const auto &Tok : TokensAroundCursor) {
+if (Tok.kind() != tok::identifier)
+  continue;

sammccall wrote:
> This deserves a comment, it's a different strategy than SelectionTree that 
> should yield the same result.
> 
> ("In general we prefer the touching token that works over the one that 
> doesn't, see SelectionTree::create(). This location is used only for 
> triggering on macros and auto, so simply choosing the lone 
> identifier-or-keyword token is equivalent")
you also need to check for keyword (or specifically kw auto)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75176



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


[PATCH] D75121: Put microsoft template parameter shadow warning behind separate flag (PR44794)

2020-02-26 Thread Hans Wennborg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG41a6612ea8af: Put microsoft template parameter shadow 
warning behind separate flag (PR44794) (authored by hans).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D75121?vs=246471&id=246713#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75121

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/test/SemaCXX/microsoft-template-shadow.cpp


Index: clang/test/SemaCXX/microsoft-template-shadow.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/microsoft-template-shadow.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify 
-fms-compatibility -Wno-microsoft -Wmicrosoft-template-shadow
+
+template  // expected-note {{template parameter is declared here}}
+struct Outmost {
+  template  // expected-warning {{declaration of 'T' shadows 
template parameter}}
+  struct Inner {
+void f() {
+  T *var;
+}
+  };
+};
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4273,7 +4273,7 @@
 def err_template_param_shadow : Error<
   "declaration of %0 shadows template parameter">;
 def ext_template_param_shadow : ExtWarn<
-  err_template_param_shadow.Text>, InGroup;
+  err_template_param_shadow.Text>, InGroup;
 def note_template_param_here : Note<"template parameter is declared here">;
 def warn_template_export_unsupported : Warning<
   "exported templates are unsupported">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1018,7 +1018,8 @@
 def MicrosoftEnumValue : DiagGroup<"microsoft-enum-value">;
 def MicrosoftDefaultArgRedefinition :
 DiagGroup<"microsoft-default-arg-redefinition">;
-def MicrosoftTemplate : DiagGroup<"microsoft-template">;
+def MicrosoftTemplateShadow : DiagGroup<"microsoft-template-shadow">;
+def MicrosoftTemplate : DiagGroup<"microsoft-template", 
[MicrosoftTemplateShadow]>;
 def MicrosoftInconsistentDllImport : DiagGroup<"inconsistent-dllimport">;
 def MicrosoftRedeclareStatic : DiagGroup<"microsoft-redeclare-static">;
 def MicrosoftEnumForwardReference :


Index: clang/test/SemaCXX/microsoft-template-shadow.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/microsoft-template-shadow.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify -fms-compatibility -Wno-microsoft -Wmicrosoft-template-shadow
+
+template  // expected-note {{template parameter is declared here}}
+struct Outmost {
+  template  // expected-warning {{declaration of 'T' shadows template parameter}}
+  struct Inner {
+void f() {
+  T *var;
+}
+  };
+};
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4273,7 +4273,7 @@
 def err_template_param_shadow : Error<
   "declaration of %0 shadows template parameter">;
 def ext_template_param_shadow : ExtWarn<
-  err_template_param_shadow.Text>, InGroup;
+  err_template_param_shadow.Text>, InGroup;
 def note_template_param_here : Note<"template parameter is declared here">;
 def warn_template_export_unsupported : Warning<
   "exported templates are unsupported">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1018,7 +1018,8 @@
 def MicrosoftEnumValue : DiagGroup<"microsoft-enum-value">;
 def MicrosoftDefaultArgRedefinition :
 DiagGroup<"microsoft-default-arg-redefinition">;
-def MicrosoftTemplate : DiagGroup<"microsoft-template">;
+def MicrosoftTemplateShadow : DiagGroup<"microsoft-template-shadow">;
+def MicrosoftTemplate : DiagGroup<"microsoft-template", [MicrosoftTemplateShadow]>;
 def MicrosoftInconsistentDllImport : DiagGroup<"inconsistent-dllimport">;
 def MicrosoftRedeclareStatic : DiagGroup<"microsoft-redeclare-static">;
 def MicrosoftEnumForwardReference :
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 02323a3 - [clangd] use printQualifiedName to skip the inlinenamespace qualifiers.

2020-02-26 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-02-26T16:22:45+01:00
New Revision: 02323a3d5f9ea676865f78d603e68fa4b4b62608

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

LOG: [clangd] use printQualifiedName to skip the inlinenamespace qualifiers.

Summary:
symbols in libcpp are inside the inline namespace, printQualifierAsString will
print the inline namespace, which is unexpected.

Reviewers: kadircet

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/Rename.cpp 
b/clang-tools-extra/clangd/refactor/Rename.cpp
index ec33f16eac05..fd2146eb4fb7 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -110,7 +110,7 @@ bool isBlacklisted(const NamedDecl &RenameDecl) {
 #include "StdSymbolMap.inc"
 #undef SYMBOL
   });
-  return StdSymbols->count(RenameDecl.getQualifiedNameAsString());
+  return StdSymbols->count(printQualifiedName(RenameDecl));
 }
 
 enum ReasonToReject {

diff  --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp 
b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index 3b2b96e51dd1..9906d6b3c29d 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -593,6 +593,14 @@ TEST(RenameTest, Renameable) {
  }
)cpp",
"not a supported kind", !HeaderFile, Index},
+  {R"cpp(// disallow rename on blacklisted symbols (e.g. std symbols)
+ namespace std {
+ inline namespace __u {
+ class str^ing {};
+ }
+ }
+   )cpp",
+   "not a supported kind", !HeaderFile, Index},
 
   {R"cpp(
  void foo(int);



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


[PATCH] D75174: [clangd] use printQualifiedName to skip the inlinenamespace qualifiers.

2020-02-26 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG02323a3d5f9e: [clangd] use printQualifiedName to skip the 
inlinenamespace qualifiers. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D75174?vs=246699&id=246720#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75174

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -593,6 +593,14 @@
  }
)cpp",
"not a supported kind", !HeaderFile, Index},
+  {R"cpp(// disallow rename on blacklisted symbols (e.g. std symbols)
+ namespace std {
+ inline namespace __u {
+ class str^ing {};
+ }
+ }
+   )cpp",
+   "not a supported kind", !HeaderFile, Index},
 
   {R"cpp(
  void foo(int);
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -110,7 +110,7 @@
 #include "StdSymbolMap.inc"
 #undef SYMBOL
   });
-  return StdSymbols->count(RenameDecl.getQualifiedNameAsString());
+  return StdSymbols->count(printQualifiedName(RenameDecl));
 }
 
 enum ReasonToReject {


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -593,6 +593,14 @@
  }
)cpp",
"not a supported kind", !HeaderFile, Index},
+  {R"cpp(// disallow rename on blacklisted symbols (e.g. std symbols)
+ namespace std {
+ inline namespace __u {
+ class str^ing {};
+ }
+ }
+   )cpp",
+   "not a supported kind", !HeaderFile, Index},
 
   {R"cpp(
  void foo(int);
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -110,7 +110,7 @@
 #include "StdSymbolMap.inc"
 #undef SYMBOL
   });
-  return StdSymbols->count(RenameDecl.getQualifiedNameAsString());
+  return StdSymbols->count(printQualifiedName(RenameDecl));
 }
 
 enum ReasonToReject {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e8c5fea - [clang-format] Special handling of spaces for C# code

2020-02-26 Thread Jonathan Coe via cfe-commits

Author: Jonathan Coe
Date: 2020-02-26T15:27:03Z
New Revision: e8c5fea243ce30640ec9707fabdb635a49b3153c

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

LOG: [clang-format] Special handling of spaces for C# code

Summary:
Ensure that there are spaces around braces '{', '}'.

Ensure that there is a space before and after '=>'.

Ensure that 'async' and 'when' are considered as keywords when inserting spaces.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Tags: #clang-format

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

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index dc68cbc79734..6bbfdcf37f93 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -771,6 +771,7 @@ struct AdditionalKeywords {
 kw_unchecked = &IdentTable.get("unchecked");
 kw_unsafe = &IdentTable.get("unsafe");
 kw_ushort = &IdentTable.get("ushort");
+kw_when = &IdentTable.get("when");
 
 // Keep this at the end of the constructor to make sure everything here
 // is
@@ -787,7 +788,7 @@ struct AdditionalKeywords {
  kw_fixed, kw_foreach, kw_implicit, kw_in, kw_interface, kw_internal,
  kw_is, kw_lock, kw_null, kw_object, kw_out, kw_override, kw_params,
  kw_readonly, kw_ref, kw_string, kw_stackalloc, kw_sbyte, kw_sealed,
- kw_uint, kw_ulong, kw_unchecked, kw_unsafe, kw_ushort,
+ kw_uint, kw_ulong, kw_unchecked, kw_unsafe, kw_ushort, kw_when,
  // Keywords from the JavaScript section.
  kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
  kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_readonly,
@@ -891,6 +892,7 @@ struct AdditionalKeywords {
   IdentifierInfo *kw_unchecked;
   IdentifierInfo *kw_unsafe;
   IdentifierInfo *kw_ushort;
+  IdentifierInfo *kw_when;
 
   /// Returns \c true if \p Tok is a true JavaScript identifier, returns
   /// \c false if it is a keyword or a pseudo keyword.

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d71c4f470378..04b20599638d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2870,21 +2870,34 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 if (Left.is(tok::numeric_constant) && Right.is(tok::percent))
   return Right.WhitespaceRange.getEnd() != 
Right.WhitespaceRange.getBegin();
   } else if (Style.isCSharp()) {
+// Require spaces around '{' and  before '}' unless they appear in
+// interpolated strings. Interpolated strings are merged into a single 
token
+// so cannot have spaces inserted by this function.
+
+// Space before { (including space within '{ {').
+if (Right.is(tok::l_brace))
+  return true;
+
+// Spaces inside braces.
+if (Left.is(tok::l_brace) && Right.isNot(tok::r_brace))
+  return true;
+
+if (Left.isNot(tok::l_brace) && Right.is(tok::r_brace))
+  return true;
+
+// Spaces around '=>'.
+if (Left.is(TT_JsFatArrow) || Right.is(TT_JsFatArrow))
+  return true;
+
 // space between type and variable e.g. Dictionary foo;
 if (Left.is(TT_TemplateCloser) && Right.is(TT_StartOfName))
   return true;
+
 // space between keywords and paren e.g. "using ("
 if (Right.is(tok::l_paren))
-  if (Left.is(tok::kw_using))
+  if (Left.isOneOf(tok::kw_using, Keywords.kw_async, Keywords.kw_when))
 return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements 
||
spaceRequiredBeforeParens(Right);
-// space between ']' and '{'
-if (Left.is(tok::r_square) && Right.is(tok::l_brace))
-  return true;
-// space before '{' in "new MyType {"
-if (Right.is(tok::l_brace) && Left.Previous &&
-Left.Previous->is(tok::kw_new))
-  return true;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index 68a8e9fefe2d..3bdaf3d5a9f3 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -525,11 +525,11 @@ Shape[] shapes = new[] {
 
   // Omitted final `,`s will change the formatting.
   verifyFormat(R"(//
-Shape[] shapes = new[] {new Circle {Radius = 2.7281, Colour = Colours.Red},
-new Square {
-Side = 101.1,
-Colour = Colours.Yellow,
-}};)",
+Shape[] shapes = new[] { new

[PATCH] D75129: [clang-format] Special handling of spaces for C# code

2020-02-26 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe8c5fea243ce: [clang-format] Special handling of spaces for 
C# code (authored by Jonathan Coe ).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75129

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -525,11 +525,11 @@
 
   // Omitted final `,`s will change the formatting.
   verifyFormat(R"(//
-Shape[] shapes = new[] {new Circle {Radius = 2.7281, Colour = Colours.Red},
-new Square {
-Side = 101.1,
-Colour = Colours.Yellow,
-}};)",
+Shape[] shapes = new[] { new Circle { Radius = 2.7281, Colour = Colours.Red },
+ new Square {
+ Side = 101.1,
+ Colour = Colours.Yellow,
+ } };)",
Style);
 }
 
@@ -575,5 +575,27 @@
Style);
 }
 
+TEST_F(FormatTestCSharp, CSharpSpaces) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+  Style.SpaceBeforeSquareBrackets = false;
+  Style.SpacesInSquareBrackets = false;
+  Style.SpaceBeforeCpp11BracedList = true;
+  Style.Cpp11BracedListStyle = false;
+  Style.SpacesInContainerLiterals = false;
+
+  verifyFormat(R"(new Car { "Door", 0.1 })", Style);
+  verifyFormat(R"(new Car { 0.1, "Door" })", Style);
+  verifyFormat(R"(new string[] { "A" })", Style);
+  verifyFormat(R"(new string[] {})", Style);
+  verifyFormat(R"(new Car { someVariableName })", Style);
+  verifyFormat(R"(new Car { someVariableName })", Style);
+  verifyFormat(R"(new Dictionary { ["Key"] = "Value" };)",
+   Style);
+  verifyFormat(R"(Apply(x => x.Name, x => () => x.ID);)", Style);
+  verifyFormat(R"(bool[] xs = { true, true };)", Style);
+  verifyFormat(R"(taskContext.Factory.Run(async () => doThing(args);)", Style);
+  verifyFormat(R"(catch (TestException) when (innerFinallyExecuted))", Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2870,21 +2870,34 @@
 if (Left.is(tok::numeric_constant) && Right.is(tok::percent))
   return Right.WhitespaceRange.getEnd() != Right.WhitespaceRange.getBegin();
   } else if (Style.isCSharp()) {
+// Require spaces around '{' and  before '}' unless they appear in
+// interpolated strings. Interpolated strings are merged into a single token
+// so cannot have spaces inserted by this function.
+
+// Space before { (including space within '{ {').
+if (Right.is(tok::l_brace))
+  return true;
+
+// Spaces inside braces.
+if (Left.is(tok::l_brace) && Right.isNot(tok::r_brace))
+  return true;
+
+if (Left.isNot(tok::l_brace) && Right.is(tok::r_brace))
+  return true;
+
+// Spaces around '=>'.
+if (Left.is(TT_JsFatArrow) || Right.is(TT_JsFatArrow))
+  return true;
+
 // space between type and variable e.g. Dictionary foo;
 if (Left.is(TT_TemplateCloser) && Right.is(TT_StartOfName))
   return true;
+
 // space between keywords and paren e.g. "using ("
 if (Right.is(tok::l_paren))
-  if (Left.is(tok::kw_using))
+  if (Left.isOneOf(tok::kw_using, Keywords.kw_async, Keywords.kw_when))
 return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements ||
spaceRequiredBeforeParens(Right);
-// space between ']' and '{'
-if (Left.is(tok::r_square) && Right.is(tok::l_brace))
-  return true;
-// space before '{' in "new MyType {"
-if (Right.is(tok::l_brace) && Left.Previous &&
-Left.Previous->is(tok::kw_new))
-  return true;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -771,6 +771,7 @@
 kw_unchecked = &IdentTable.get("unchecked");
 kw_unsafe = &IdentTable.get("unsafe");
 kw_ushort = &IdentTable.get("ushort");
+kw_when = &IdentTable.get("when");
 
 // Keep this at the end of the constructor to make sure everything here
 // is
@@ -787,7 +788,7 @@
  kw_fixed, kw_foreach, kw_implicit, kw_in, kw_interface, kw_internal,
  kw_is, kw_lock, kw_null, kw_object,

[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

2020-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Plan:

- Add an error state to `StreamState`.
- Model every stream function that can fail. Split the state into failed and 
non-failed and set the return value accordingly (as done at //fopen// now, but 
not only for stream return values). This is needed here to have a correlation 
between the return value and the stream state.

Probably the check for null stream pointer can be removed from here if the 
StdLibraryFunctionsChecker will do this job.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163



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


[PATCH] D75130: Remove BinaryOperator::CreateFNeg

2020-02-26 Thread Cameron McInally via Phabricator via cfe-commits
cameron.mcinally accepted this revision.
cameron.mcinally added a comment.
This revision is now accepted and ready to land.

LGTM, with the TODO to be handled under a separate patch.

Thank you for taking care of this, Simon.




Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:341
 Value *NewSel = Builder.CreateSelect(Cond, X, Y, SI.getName() + ".v", &SI);
 // TODO: Remove the hack for the binop form when the unary op is optimized
 //   properly with all IR passes.

xbolva00 wrote:
> simoll wrote:
> > xbolva00 wrote:
> > > What about this TODO?
> > Ok. So this seems to be a hack to update the FSub idiom on the fly.
> > How about we get rid of the TODO and the code below in a separate patch?
> I agree
+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75130



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D73242#1888295 , @tejohnson wrote:

> FYI I have reproduced the failure, and am starting to debug.


I see what is going on and have a simple fix, just need to create a test case. 
Expect to send a patch to fix this today, hopefully this morning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73242



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


[PATCH] D75166: [clangd] Clean-up XRefs.cpp from Lexer usages and unnecessary SourceLoc transformations

2020-02-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:225
+
+  const auto &TB = AST.getTokens();
   // Macros are simple: there's no declaration/definition distinction.

used only once - inline?



Comment at: clang-tools-extra/clangd/XRefs.cpp:229
   std::vector Result;
-  if (auto M = locateMacroAt(IdentStartLoc, AST.getPreprocessor())) {
-if (auto Loc = makeLocation(AST.getASTContext(),
-M->Info->getDefinitionLoc(), *MainFilePath)) {
-  LocatedSymbol Macro;
-  Macro.Name = std::string(M->Name);
-  Macro.PreferredDeclaration = *Loc;
-  Macro.Definition = Loc;
-  Result.push_back(std::move(Macro));
-
-  // Don't look at the AST or index if we have a macro result.
-  // (We'd just return declarations referenced from the macro's
-  // expansion.)
-  return Result;
+  const auto *IdentifierCoveringCursor =
+  syntax::spelledIdentifierTouching(*CurLoc, TB);

covering->touching

or just TouchedIdentifier for brevity



Comment at: clang-tools-extra/clangd/XRefs.cpp:432
   auto References = findRefs(
-  getDeclAtPosition(AST,
-
SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
-Pos, SM, AST.getLangOpts())),
-Relations),
-  AST);
+  getDeclAtPosition(AST, IdentifierAtCursor->location(), Relations), AST);
 

apparently we don't have tests for non-identifier cases, but they did work. 
let's keep them working for now :) CurLoc here



Comment at: clang-tools-extra/clangd/XRefs.cpp:503
+auto Decls =
+getDeclAtPosition(AST, IdentifierAtCursor->location(), Relations);
 

again, CurLoc?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75166



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


[PATCH] D75181: [Clang][AArch64] Add default arguments to runtime functions.

2020-02-26 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss created this revision.
danielkiss added reviewers: chill, pcc, olista01, asl.
Herald added subscribers: cfe-commits, aheejin, kristof.beyls, sbc100.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

A runtime function needs the same arguments as normal function. 
Attributes of PAuth and BTI are added to the default arguments.
Function level attribute handling is adopted.
After this change the all runtime created functions like _clang_call_terminate
will get the default arguments including PAC/BTI if applicable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75181

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/ignore-exceptions.cpp
  clang/test/CodeGenCXX/aarch64-branch-target_clang_call_terminate.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/dynamic-cast.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/runtimecc.cpp
  clang/test/CodeGenCXX/wasm-eh.cpp
  clang/test/CodeGenObjC/arc.m
  clang/test/CodeGenObjC/attr-objc-runtime-visible.m
  clang/test/CodeGenObjC/class-stubs.m
  clang/test/CodeGenObjC/nonlazy-msgSend.m
  clang/test/CodeGenObjC/objc-literal-debugger-test.m
  clang/test/OpenMP/barrier_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/openmp_win_codegen.cpp
  clang/test/PCH/objc_container.m

Index: clang/test/PCH/objc_container.m
===
--- clang/test/PCH/objc_container.m
+++ clang/test/PCH/objc_container.m
@@ -22,4 +22,4 @@
 // CHECK-IR: ret void
 
 // CHECK-IR: attributes #0 = { noinline nounwind {{.*}} }
-// CHECK-IR: attributes #1 = { nonlazybind }
+// CHECK-IR: attributes #1 = { nonlazybind {{.*}} }
Index: clang/test/OpenMP/openmp_win_codegen.cpp
===
--- clang/test/OpenMP/openmp_win_codegen.cpp
+++ clang/test/OpenMP/openmp_win_codegen.cpp
@@ -61,9 +61,9 @@
 // CHECK-NEXT: call void @__kmpc_end_critical(%struct.ident_t* {{.*}}@0, i32 [[GID]],
 // CHECK-NEXT: cleanupret from {{.*}} unwind label %[[CATCHTERM:[^ ]+]]
 // CHECK:  cleanuppad within none []
-// CHECK-NEXT: call void @"?terminate@@YAXXZ"() #5 [ "funclet"(token %{{.*}}) ]
+// CHECK-NEXT: call void @"?terminate@@YAXXZ"() #6 [ "funclet"(token %{{.*}}) ]
 // CHECK-NEXT: unreachable
 // CHECK:  [[CATCHTERM]]
 // CHECK-NEXT: cleanuppad within [[CATCHPAD]] []
-// CHECK-NEXT: call void @"?terminate@@YAXXZ"() #5 [ "funclet"(token %{{.*}}) ]
+// CHECK-NEXT: call void @"?terminate@@YAXXZ"() #6 [ "funclet"(token %{{.*}}) ]
 // CHECK-NEXT: unreachable
Index: clang/test/OpenMP/nvptx_parallel_codegen.cpp
===
--- clang/test/OpenMP/nvptx_parallel_codegen.cpp
+++ clang/test/OpenMP/nvptx_parallel_codegen.cpp
@@ -321,7 +321,7 @@
 // CHECK: call void @__kmpc_barrier(%struct.ident_t* @{{.+}}, i32 %{{.+}}) #[[#CONVERGENT:]]
 // CHECK: ret void
 
-// CHECK: declare void @__kmpc_barrier(%struct.ident_t*, i32) #[[#CONVERGENT]]
+// CHECK: declare void @__kmpc_barrier(%struct.ident_t*, i32) #[[#CONVERGENT_DEC:]]
 
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l55}}_worker()
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l55}}(
@@ -369,9 +369,11 @@
 // CHECK:  br label
 
 
-// CHECK: declare i32 @__kmpc_warp_active_thread_mask() #[[#CONVERGENT:]]
-// CHECK: declare void @__kmpc_syncwarp(i32) #[[#CONVERGENT:]]
+// CHECK: declare i32 @__kmpc_warp_active_thread_mask() #
+// CHECK: declare void @__kmpc_syncwarp(i32) #
+
+// CHECK: attributes #[[#CONVERGENT_DEC]] = { convergent {{.*}} }
+// CHECK: attributes #[[#CONVERGENT]] = { convergent }
 
-// CHECK: attributes #[[#CONVERGENT]] = {{.*}} convergent {{.*}}
 
 #endif
Index: clang/test/OpenMP/barrier_codegen.cpp
===
--- clang/test/OpenMP/barrier_codegen.cpp
+++ clang/test/OpenMP/barrier_codegen.cpp
@@ -42,8 +42,7 @@
   return tmain(argc) + tmain(argv[0][0]) + a;
 }
 
-// CLANGCG:declare i32 @__kmpc_global_thread_num(%struct.ident_t*)
-// CLANGCG-NOT:#
+// CLANGCG:declare i32 @__kmpc_global_thread_num(%struct.ident_t*) #
 // IRBUILDER:  ; Function Attrs: nounwind
 // IRBUILDER-NEXT: declare i32 @__kmpc_global_thread_num(%struct.ident_t*) #
 // IRBUILDER_OPT:  ; Function Attrs: nofree nosync nounwind readonly
Index: clang/test/CodeGenObjC/objc-literal-debugger-test.m
===
--- clang/test/CodeGenObjC/objc-literal-debugger-test.m
+++ clang/test/CodeGenObjC/objc-literal-debugger-test.m
@@ -52,4 +52,4 @@
 
 // CHECK: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB:#[0-9]+]]
 
-// CHECK: attributes [[NLB]] = { nonlazybind }
+// CHECK: attributes [[NLB]] = { nonlazybind {{.*}} }
Index: clang/test/CodeGenObjC/

Re: [clang] abd0905 - Revert "Revert "Change clang option -ffp-model=precise to select ffp-contract=on""

2020-02-26 Thread Blower, Melanie I via cfe-commits
Rumeet, Thanks for the additional info.  At some point we'd like to re-commit 
this patch.  LNT testing showed execution time regressions on arch including 
x86 and aarch.  I didn't capture the test names each time but it appeared to be 
approximately the same tests regressing everywhere.  Andy Kaylor took a quick 
look at the x86 regressions and he said it looked like the loop unroller was 
making a bad decision.  We are working out what to do now.  FYI these are the 
x86 tests that failed on the LNT bot:
/home/ssglocal/clang-cmake-x86_64-sde-avx512-linux/clang-cmake-x86_64-sde-avx512-linux/test/sandbox/build/report.simple.csv
Importing 'report.json'
Import succeeded.

--- Tested: 2560 tests --
FAIL: MultiSource/Applications/oggenc/oggenc.execution_time (513 of 2560)
FAIL: MultiSource/Benchmarks/DOE-ProxyApps-C++/CLAMR/CLAMR.execution_time (514 
of 2560)
FAIL: MultiSource/Benchmarks/DOE-ProxyApps-C++/HPCCG/HPCCG.execution_time (515 
of 2560)
FAIL: MultiSource/Benchmarks/DOE-ProxyApps-C++/miniFE/miniFE.execution_time 
(516 of 2560)
FAIL: SingleSource/Benchmarks/Linpack/linpack-pc.execution_time (517 of 2560)
FAIL: SingleSource/Benchmarks/Misc-C++/Large/sphereflake.execution_time (518 of 
2560)
FAIL: 
SingleSource/Benchmarks/Polybench/datamining/correlation/correlation.execution_time
 (519 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/datamining/covariance/covariance.execution_time
 (520 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/linear-algebra/kernels/2mm/2mm.execution_time 
(521 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/linear-algebra/kernels/3mm/3mm.execution_time 
(522 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/linear-algebra/kernels/atax/atax.execution_time
 (523 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/linear-algebra/kernels/bicg/bicg.execution_time
 (524 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gemver/gemver.execution_time
 (525 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gesummv/gesummv.execution_time
 (526 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/linear-algebra/kernels/symm/symm.execution_time
 (527 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/linear-algebra/kernels/trisolv/trisolv.execution_time
 (528 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/linear-algebra/kernels/trmm/trmm.execution_time
 (529 of 2560)
FAIL: 
SingleSource/Benchmarks/Polybench/linear-algebra/solvers/gramschmidt/gramschmidt.execution_time
 (530 of 2560)
FAIL: SingleSource/Benchmarks/Polybench/stencils/adi/adi.execution_time (531 of 
2560)
FAIL: SingleSource/UnitTests/Vector/SSE/sse_expandfft.execution_time (532 of 
2560)
FAIL: SingleSource/UnitTests/Vector/SSE/sse_stepfft.execution_time (533 of 2560)


> -Original Message-
> From: cfe-commits  On Behalf Of via cfe-
> commits
> Sent: Tuesday, February 25, 2020 6:24 PM
> To: cfe-commits@lists.llvm.org
> Subject: cfe-commits Digest, Vol 152, Issue 938
> 
> Send cfe-commits mailing list submissions to
>   cfe-commits@lists.llvm.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>   https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> or, via email, send a message with subject or body 'help' to
>   cfe-commits-requ...@lists.llvm.org
> 
> You can reach the person managing the list at
>   cfe-commits-ow...@lists.llvm.org
> 
> When replying, please edit your Subject line so it is more specific than "Re:
> Contents of cfe-commits digest..."
> 
> 
> Today's Topics:
> 
>1. [PATCH] D74912: [AArch64][SVE] Add SVE2 intrinsics for bit
>   permutation & table lookup
>   (Eli Friedman via Phabricator via cfe-commits)
>2. Re: [clang] abd0905 - Revert "Revert "Change clang option
>   -ffp-model=precise to select ffp-contract=on""
>   (Rumeet Dhindsa via cfe-commits)
> 
> 
> --
> 
> Message: 1
> Date: Tue, 25 Feb 2020 23:14:47 + (UTC)
> From: Eli Friedman via Phabricator via cfe-commits
>   
> To: kerry.mclaugh...@arm.com, sander.desma...@arm.com,
>   andrzej.warzyn...@arm.com, dan...@gmail.com,
> cameron.mcina...@nyu.edu,
>   efrie...@quicinc.com, rengo...@gmail.com
> Cc: hanna.kru...@gmail.com, schu...@gmail.com, ju...@samsung.com,
>   llvm-comm...@lists.llvm.org, kanh...@a-bix.com,
>   cfe-commits@lists.llvm.org, sn...@codasip.com,
> simon.m...@emea.nec.com
> Subject: [PATCH] D74912: [AArch64][SVE] Add SVE2 intrinsics for bit
>   permutation & table lookup
> Message-ID: <8ad204f6f5d906623adfa37862e78ee3@localhost.localdomain>
> Content-Type: text/plain; charset=us-ascii
> 
> efriedma accepted this revision.
> efriedma added a comment.
> This revision is now accepted and ready to land.
> 
> LGTM
> 
> 
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D74912/new/
> 
> https://reviews.llvm.org/D74912
> 
> 
> 
> 
> 
> --
> 
> Message: 2
> Date: Tue, 25 Feb 2020 15:21:39 -0800
> From: R

[PATCH] D69662: [Checkers] Avoid using evalCall in StreamChecker.

2020-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske abandoned this revision.
balazske added a comment.

StreamChecker will be updated in other changes, see:
https://reviews.llvm.org/D75158


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69662



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


[PATCH] D75176: [clangd] Get rid of getBeginningOfIdentifier helper

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

- Only use special locations for deducedtype and macros.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75176

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
  clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -312,60 +312,6 @@
   }
 }
 
-TEST(SourceCodeTests, GetBeginningOfIdentifier) {
-  std::string Preamble = R"cpp(
-struct Bar { int func(); };
-#define MACRO(X) void f() { X; }
-Bar* bar;
-  )cpp";
-  // First ^ is the expected beginning, last is the search position.
-  for (const std::string &Text : std::vector{
-   "int ^f^oo();", // inside identifier
-   "int ^foo();",  // beginning of identifier
-   "int ^foo^();", // end of identifier
-   "int foo(^);",  // non-identifier
-   "^int foo();",  // beginning of file (can't back up)
-   "int ^f0^0();", // after a digit (lexing at N-1 is wrong)
-   "/^/ comments", // non-interesting token
-   "void f(int abc) { abc ^ ++; }",// whitespace
-   "void f(int abc) { ^abc^++; }", // range of identifier
-   "void f(int abc) { ++^abc^; }", // range of identifier
-   "void f(int abc) { ++^abc; }",  // range of identifier
-   "void f(int abc) { ^+^+abc; }", // range of operator
-   "void f(int abc) { ^abc^ ++; }",// range of identifier
-   "void f(int abc) { abc ^++^; }",// range of operator
-   "void f(int abc) { ^++^ abc; }",// range of operator
-   "void f(int abc) { ++ ^abc^; }",// range of identifier
-   "void f(int abc) { ^++^/**/abc; }", // range of operator
-   "void f(int abc) { ++/**/^abc; }",  // range of identifier
-   "void f(int abc) { ^abc^/**/++; }", // range of identifier
-   "void f(int abc) { abc/**/^++; }",  // range of operator
-   "void f() {^ }", // outside of identifier and operator
-   "int ^λλ^λ();",  // UTF-8 handled properly when backing up
-
-   // identifier in macro arg
-   "MACRO(bar->^func())",  // beginning of identifier
-   "MACRO(bar->^fun^c())", // inside identifier
-   "MACRO(bar->^func^())", // end of identifier
-   "MACRO(^bar->func())",  // begin identifier
-   "MACRO(^bar^->func())", // end identifier
-   "^MACRO(bar->func())",  // beginning of macro name
-   "^MAC^RO(bar->func())", // inside macro name
-   "^MACRO^(bar->func())", // end of macro name
-   }) {
-std::string WithPreamble = Preamble + Text;
-Annotations TestCase(WithPreamble);
-auto AST = TestTU::withCode(TestCase.code()).build();
-const auto &SourceMgr = AST.getSourceManager();
-SourceLocation Actual = getBeginningOfIdentifier(
-TestCase.points().back(), SourceMgr, AST.getLangOpts());
-Position ActualPos = offsetToPosition(
-TestCase.code(),
-SourceMgr.getFileOffset(SourceMgr.getSpellingLoc(Actual)));
-EXPECT_EQ(TestCase.points().front(), ActualPos) << Text;
-  }
-}
-
 TEST(SourceCodeTests, CollectIdentifiers) {
   auto Style = format::getLLVMStyle();
   auto IDs = collectIdentifiers(R"cpp(
@@ -481,9 +427,11 @@
)cpp");
   TestTU TU = TestTU::withCode(Code.code());
   auto AST = TU.build();
-  auto Loc = getBeginningOfIdentifier(Code.point(), AST.getSourceManager(),
-  AST.getLangOpts());
-  auto Result = locateMacroAt(Loc, AST.getPreprocessor());
+  auto CurLoc = sourceLocationInMainFile(AST.getSourceManager(), Code.point());
+  ASSERT_TRUE(bool(CurLoc));
+  const auto *Id = syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
+  ASSERT_TRUE(Id);
+  auto Result = locateMacroAt(Id->location(), AST.getPreprocessor());
   ASSERT_TRUE(Result);
   EXPECT_THAT(*Result, MacroName("MACRO"));
 }
Index: clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
===
--- clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
+++ clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
@@ -87,9 +87,9 @@
   if (ExpectedRefs.empty())
 break;
 
-  auto Loc = getBeginningOfIdentifier(ExpectedRefs.begin()->start, SM,
-  AST.getLangOpts());
-  auto Macro = locateMacroAt(Loc, PP);
+  auto Loc = sourceLocationInMainFile(SM, ExpectedRefs.begin()->start);
+  ASSERT_TRUE(bool(Loc))

[PATCH] D75171: [Analyzer] Fix for incorrect use of container and iterator checkers

2020-02-26 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

Do you have access to the `Driver` somehow? Instead of a `cerr` (-ish) output, 
something that is formatted like a "true" error diagnostic (or warning), such 
as `"no such file or directory"` would be much better, I fear this `[ERROR]` 
will simply be flooded away with the usual diagnostic output on screen, 
especially if multiple files are concerned.

Are you trying to land this before `10.0` goes out? In this case, it could be 
okay, but for the long term, this seems a very crude solution.




Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:1037-1038
+llvm::errs() << "[ERROR] Checker " << mgr.getCurrentCheckerName().getName()
+ << " cannot be enabled without analyzer option aggressive-"
+"binary-operation-simplification.\n";
+return false;

In Clang diagnostics, "identifiers" are put between apostrophes:

'aggressive-binary-operation-simplification'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75171



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


[PATCH] D74692: [clang-tidy][bugprone-use-after-move] Warn on std::move for consts

2020-02-26 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis marked an inline comment as done.
zinovy.nis added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:329
   // CHECK-NOTES: [[@LINE-3]]:7: note: move occurred here
+  // CHECK-NOTES: [[@LINE-6]]:7: note: std::move of the const expression 
{{.*}}
 };

Quuxplusone wrote:
> It continues to seem silly to me that you give an extra note here saying that 
> line 325 doesn't do anything, when of course line 336 doesn't do anything 
> either (and you don't give any extra note there).
> 
> This clang-tidy warning isn't supposed to be about what //physically 
> happens// in the machine code during any particular compilation run; it's 
> supposed to be about helping the user avoid //semantic// bugs by cleaning up 
> their codebase's //logical// behavior. The rule is "don't use things after 
> moving from them," period.
> 
> Analogously, if there were a clang-tidy warning to say "always indent four 
> spaces after an `if`," and you proposed to add a note to some cases that said 
> "...but here a three-space indent is OK, because C++ is 
> whitespace-insensitive" — I'd also find //that// note to be mildly 
> objectionable. We want to train people to do the right thing, not to do the 
> right thing "except in this case because hey, it doesn't matter to the 
> machine."
Thanks for the feedback. I got your point. But my note (may be expressed with 
wrong words) is about that there're 2 ways to fix the issue: either get rid of 
'std::move' or somehow remove 'const'. That was the main purpose of my commit.


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

https://reviews.llvm.org/D74692



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


[PATCH] D75171: [Analyzer] Fix for incorrect use of container and iterator checkers

2020-02-26 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

Also, //errors// should conceptually break the operation at hand, so this thing 
should be a warning instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75171



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


[PATCH] D75166: [clangd] Clean-up XRefs.cpp from Lexer usages and unnecessary SourceLoc transformations

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



Comment at: clang-tools-extra/clangd/XRefs.cpp:432
   auto References = findRefs(
-  getDeclAtPosition(AST,
-
SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
-Pos, SM, AST.getLangOpts())),
-Relations),
-  AST);
+  getDeclAtPosition(AST, IdentifierAtCursor->location(), Relations), AST);
 

sammccall wrote:
> apparently we don't have tests for non-identifier cases, but they did work. 
> let's keep them working for now :) CurLoc here
also get rid of the bail-out when no tokens were touched. (which means we can 
now possibly trigger on `^~Foo()`.)



Comment at: clang-tools-extra/clangd/XRefs.cpp:503
+auto Decls =
+getDeclAtPosition(AST, IdentifierAtCursor->location(), Relations);
 

sammccall wrote:
> again, CurLoc?
ah thanks for catching this one especially, it also means we don't need to bail 
out when there are no identifiers touching cursor(it is only necessary for 
macros).
Updated it to do that, PTAL.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75166



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


[PATCH] D75166: [clangd] Clean-up XRefs.cpp from Lexer usages and unnecessary SourceLoc transformations

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

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75166

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

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -43,6 +43,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -214,24 +215,34 @@
 }
   }
 
+  auto CurLoc = sourceLocationInMainFile(SM, Pos);
+  if (!CurLoc) {
+elog("locateSymbolAt failed to convert position to source location: {0}",
+ CurLoc.takeError());
+return {};
+  }
+
   // Macros are simple: there's no declaration/definition distinction.
   // As a consequence, there's no need to look them up in the index either.
-  SourceLocation IdentStartLoc = SM.getMacroArgExpandedLocation(
-  getBeginningOfIdentifier(Pos, AST.getSourceManager(), AST.getLangOpts()));
   std::vector Result;
-  if (auto M = locateMacroAt(IdentStartLoc, AST.getPreprocessor())) {
-if (auto Loc = makeLocation(AST.getASTContext(),
-M->Info->getDefinitionLoc(), *MainFilePath)) {
-  LocatedSymbol Macro;
-  Macro.Name = std::string(M->Name);
-  Macro.PreferredDeclaration = *Loc;
-  Macro.Definition = Loc;
-  Result.push_back(std::move(Macro));
-
-  // Don't look at the AST or index if we have a macro result.
-  // (We'd just return declarations referenced from the macro's
-  // expansion.)
-  return Result;
+  const auto *TouchedIdentifier =
+  syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
+  if (TouchedIdentifier) {
+if (auto M = locateMacroAt(TouchedIdentifier->location(),
+   AST.getPreprocessor())) {
+  if (auto Loc = makeLocation(AST.getASTContext(),
+  M->Info->getDefinitionLoc(), *MainFilePath)) {
+LocatedSymbol Macro;
+Macro.Name = std::string(M->Name);
+Macro.PreferredDeclaration = *Loc;
+Macro.Definition = Loc;
+Result.push_back(std::move(Macro));
+
+// Don't look at the AST or index if we have a macro result.
+// (We'd just return declarations referenced from the macro's
+// expansion.)
+return Result;
+  }
 }
   }
 
@@ -244,15 +255,6 @@
   // Keep track of SymbolID -> index mapping, to fill in index data later.
   llvm::DenseMap ResultIndex;
 
-  SourceLocation SourceLoc;
-  if (auto L = sourceLocationInMainFile(SM, Pos)) {
-SourceLoc = *L;
-  } else {
-elog("locateSymbolAt failed to convert position to source location: {0}",
- L.takeError());
-return Result;
-  }
-
   auto AddResultDecl = [&](const NamedDecl *D) {
 const NamedDecl *Def = getDefinition(D);
 const NamedDecl *Preferred = Def ? Def : D;
@@ -277,16 +279,15 @@
   // Emit all symbol locations (declaration or definition) from AST.
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
-  for (const NamedDecl *D : getDeclAtPosition(AST, SourceLoc, Relations)) {
+  for (const NamedDecl *D : getDeclAtPosition(AST, *CurLoc, Relations)) {
 // Special case: void foo() ^override: jump to the overridden method.
 if (const auto *CMD = llvm::dyn_cast(D)) {
-  const InheritableAttr* Attr = D->getAttr();
+  const InheritableAttr *Attr = D->getAttr();
   if (!Attr)
 Attr = D->getAttr();
-  const syntax::Token *Tok =
-  spelledIdentifierTouching(SourceLoc, AST.getTokens());
-  if (Attr && Tok &&
-  SM.getSpellingLoc(Attr->getLocation()) == Tok->location()) {
+  if (Attr && TouchedIdentifier &&
+  SM.getSpellingLoc(Attr->getLocation()) ==
+  TouchedIdentifier->location()) {
 // We may be overridding multiple methods - offer them all.
 for (const NamedDecl *ND : CMD->overridden_methods())
   AddResultDecl(ND);
@@ -296,8 +297,9 @@
 
 // Special case: the point of declaration of a template specialization,
 // it's more useful to navigate to the template declaration.
-if (SM.getMacroArgExpandedLocation(D->getLocation()) == IdentStartLoc) {
-  if (auto *CTSD = dyn_cast(D)) {
+if (auto *CTSD = dyn_cast(D)) {
+  if (TouchedIdentifier &&
+  D->getLocation() == TouchedIdentifier->location()) {
 AddResultDecl(CTSD->getSpecializedTemplate());
 continue;
   }
@@ -416,12 +418,12 @@
   // FIXME: show references to macro within file?
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
-  auto References = findRefs(
-   

[PATCH] D75022: clang-format: Extend AllowShortLoopsOnASingleLine to do ... while loops.

2020-02-26 Thread Daan De Meyer via Phabricator via cfe-commits
DaanDeMeyer added a comment.

Is there CI infra that runs for each revision? I verified all the format unit 
tests still pass but I haven't run the entire test suite on my machine.


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

https://reviews.llvm.org/D75022



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


[PATCH] D75166: [clangd] Clean-up XRefs.cpp from Lexer usages and unnecessary SourceLoc transformations

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



Comment at: clang-tools-extra/clangd/XRefs.cpp:432
   auto References = findRefs(
-  getDeclAtPosition(AST,
-
SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
-Pos, SM, AST.getLangOpts())),
-Relations),
-  AST);
+  getDeclAtPosition(AST, IdentifierAtCursor->location(), Relations), AST);
 

kadircet wrote:
> sammccall wrote:
> > apparently we don't have tests for non-identifier cases, but they did work. 
> > let's keep them working for now :) CurLoc here
> also get rid of the bail-out when no tokens were touched. (which means we can 
> now possibly trigger on `^~Foo()`.)
can I bother you to add a test for this (or some non-identifier case, assuming 
any works)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75166



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


[PATCH] D74166: [AIX][Frontend] Static init implementation for AIX considering no priority

2020-02-26 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L added a comment.

ping.


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

https://reviews.llvm.org/D74166



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


[PATCH] D72705: [analyzer] Added new checker 'alpha.unix.ErrorReturn'.

2020-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Ping !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72705



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


[PATCH] D75184: [clang-tidy] Optional inheritance of file configs from parent directories 

2020-02-26 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added reviewers: alexfh, gribozavr2.
DmitryPolukhin added projects: clang, clang-tools-extra.
Herald added subscribers: aheejin, xazax.hun.

Without this patch clang-tidy stops finding file configs on the nearest
.clang-tidy file. In some cases it is not very convenient because it
results in common parts duplication into every child .clang-tidy file.
This diff adds optional config inheritance from the parent directories
config files.

Test Plan:

Added test case in existing config test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75184

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy
  clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp


Index: clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
@@ -7,6 +7,9 @@
 // RUN: clang-tidy -dump-config %S/Inputs/config-files/2/- -- | FileCheck %s 
-check-prefix=CHECK-CHILD2
 // CHECK-CHILD2: Checks: {{.*}}from-parent
 // CHECK-CHILD2: HeaderFilterRegex: parent
+// RUN: clang-tidy -dump-config %S/Inputs/config-files/3/- -- | FileCheck %s 
-check-prefix=CHECK-CHILD3
+// CHECK-CHILD3: Checks: {{.*}}from-parent,from-child3
+// CHECK-CHILD3: HeaderFilterRegex: child3
 // RUN: clang-tidy -dump-config -checks='from-command-line' 
-header-filter='from command line' %S/Inputs/config-files/- -- | FileCheck %s 
-check-prefix=CHECK-COMMAND-LINE
 // CHECK-COMMAND-LINE: Checks: {{.*}}from-parent,from-command-line
 // CHECK-COMMAND-LINE: HeaderFilterRegex: from command line
Index: 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy
@@ -0,0 +1,3 @@
+InheritParentConfig: true
+Checks: 'from-child3'
+HeaderFilterRegex: 'child3'
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.h
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -106,6 +106,10 @@
 
   /// Add extra compilation arguments to the start of the list.
   llvm::Optional ExtraArgsBefore;
+
+  /// Config flag for FileOptionsProvider to also include config from parent
+  /// dir.
+  llvm::Optional InheritParentConfig;
 };
 
 /// Abstract interface for retrieving various ClangTidy options.
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -92,6 +92,7 @@
 IO.mapOptional("CheckOptions", NOpts->Options);
 IO.mapOptional("ExtraArgs", Options.ExtraArgs);
 IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
+IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
   }
 };
 
@@ -237,6 +238,7 @@
   DefaultOptionsProvider::getRawOptions(AbsoluteFilePath.str());
   OptionsSource CommandLineOptions(OverrideOptions,
OptionsSourceTypeCheckCommandLineOption);
+  size_t FirstFileConfig = RawOptions.size();
   // Look for a suitable configuration file in all parent directories of the
   // file. Start with the immediate parent directory and move up.
   StringRef Path = llvm::sys::path::parent_path(AbsoluteFilePath.str());
@@ -262,9 +264,14 @@
   CachedOptions[Path] = *Result;
 
   RawOptions.push_back(*Result);
-  break;
+  if (!Result->first.InheritParentConfig ||
+  !*Result->first.InheritParentConfig)
+break;
 }
   }
+  // Reverse order of file configs because closer configs should have higher
+  // priority.
+  std::reverse(RawOptions.begin() + FirstFileConfig, RawOptions.end());
   RawOptions.push_back(CommandLineOptions);
   return RawOptions;
 }


Index: clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
@@ -7,6 +7,9 @@
 // RUN: clang-tidy -dump-config %S/Inputs/config-files/2/- -- | FileCheck %s -check-prefix=CHECK-CHILD2
 // CHECK-CHILD2: Checks: {{.*}}from-parent
 // CHECK-CHILD2: HeaderFilterRegex: parent
+// RUN: clang-tidy -dump-config %S/Inputs/config-files/3/- -- | FileCheck %s -check-prefix=CHECK-CHILD3
+// CHECK-CHILD3: Checks: {{.*}}from-parent,from-child3
+// CHECK-CHILD3: HeaderFilterRegex: child3
 // RUN: clang-tidy -dump-config -checks=

[PATCH] D75077: [OpenMP5.0] Allow pointer arithmetic in motion/map clause

2020-02-26 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen marked an inline comment as done.
cchen added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:15683
   }
+  bool VisitUnaryOperator(UnaryOperator *UO) {
+if (SemaRef.getLangOpts().OpenMP < 50) {

ABataev wrote:
> cchen wrote:
> > ABataev wrote:
> > > I think you need to extend this to support paren expressions, at least.
> > I have `UO->getSubExpr()->IgnoreParenImpCasts()` here, or I might not 
> > understand what you mean by "support paren expression".
> `(*(..))` is not supported, I think. Or, maybe, `*((a)+b)`
Both cases are handled correctly. For `(*((b)+a))`, the binop in 
`VisitBinaryOperator()`does not include the outer paren and for `*((a)+b)`, the 
parens can be handled by `Expr *SubE = 
UO->getSubExpr()->IgnoreParenImpCasts();`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75077



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

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

In D73242#1893506 , @tejohnson wrote:

> In D73242#1888295 , @tejohnson wrote:
>
> > FYI I have reproduced the failure, and am starting to debug.
>
>
> I see what is going on and have a simple fix, just need to create a test 
> case. Expect to send a patch to fix this today, hopefully this morning.


Thanks! Let me know, I'll test right away.

I'm seeing another (new?) bug with latest trunk, I'm not sure if it's related 
or not. The repro is the same, just sync the latest, and do the two-stage 
build, then `ninja check-lld`, all the LTO tests fail with this stack:

   #0 0x7ff63bd7e891 `anonymous namespace'::RealFile::`scalar deleting 
dtor'(unsigned int) 
(d:\llvm-project\buildninjarelmimalloc\bin\ld.lld.exe+0x1e891)
   #1 0x7ff63c47d4ac llvm::FPPassManager::~FPPassManager 
D:\llvm-project\llvm\include\llvm\IR\LegacyPassManagers.h:461:0
   #2 0x7ff63c47c98c `anonymous namespace'::MPPassManager::~MPPassManager 
D:\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:407:0
   #3 0x7ff63c475fac llvm::PMTopLevelManager::~PMTopLevelManager(void) 
D:\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:855:0
   #4 0x7ff63c47c3bc llvm::legacy::FunctionPassManagerImpl::`scalar 
deleting dtor'(unsigned int) 
D:\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:324:0
   #5 0x7ff63c39aa41 `anonymous namespace'::codegen 
D:\llvm-project\llvm\lib\LTO\LTOBackend.cpp:373:0
   #6 0x7ff63c39732c llvm::lto::backend(struct llvm::lto::Config const &, 
class std::function<(unsigned int)>, unsigned int, class std::unique_ptr>, class 
llvm::ModuleSummaryIndex &) D:\llvm-project\llvm\lib\LTO\LTOBackend.cpp:466:0
   #7 0x7ff63be8a49a llvm::lto::LTO::run(class std::function<(unsigned 
int)>, class std::function<(unsigned int, class llvm::StringRef)>) 
D:\llvm-project\llvm\lib\LTO\LTO.cpp:942:0
   #8 0x7ff63c153eb5 lld::elf::BitcodeCompiler::compile(void) 
D:\llvm-project\lld\ELF\LTO.cpp:261:0
   #9 0x7ff63bdc0b01 lld::elf::LinkerDriver::main 
D:\llvm-project\lld\ELF\Driver.cpp:522:0
  #10 0x7ff63bdba6dc lld::elf::link(class llvm::ArrayRef, 
bool, class llvm::raw_ostream &, class llvm::raw_ostream &) 
D:\llvm-project\lld\ELF\Driver.cpp:117:0
  #11 0x7ff63bd61807 main D:\llvm-project\lld\tools\lld\lld.cpp:166:0
  #12 0x7ff63e9cf914 __scrt_common_main_seh 
d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
  #13 0x7ffa95737bd4 (C:\WINDOWS\System32\KERNEL32.DLL+0x17bd4)
  #14 0x7ffa972eced1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6ced1)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73242



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


[PATCH] D75166: [clangd] Clean-up XRefs.cpp from Lexer usages and unnecessary SourceLoc transformations

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

- Add tests for non-identifier cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75166

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -97,6 +97,15 @@
   R"cpp(// Function parameter in decl
 void foo(int [[^bar]]);
   )cpp",
+  R"cpp(// Not touching any identifiers.
+struct Foo {
+  [[~]]Foo() {};
+};
+void foo() {
+  Foo f;
+  f.[[^~]]Foo();
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
@@ -960,6 +969,15 @@
class [[Foo]] {};
void func([[Fo^o]]);
   )cpp",
+  R"cpp(// Not touching any identifiers.
+struct Foo {
+  [[~]]Foo() {};
+};
+void foo() {
+  Foo f;
+  f.[[^~]]Foo();
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -43,6 +43,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -214,24 +215,34 @@
 }
   }
 
+  auto CurLoc = sourceLocationInMainFile(SM, Pos);
+  if (!CurLoc) {
+elog("locateSymbolAt failed to convert position to source location: {0}",
+ CurLoc.takeError());
+return {};
+  }
+
   // Macros are simple: there's no declaration/definition distinction.
   // As a consequence, there's no need to look them up in the index either.
-  SourceLocation IdentStartLoc = SM.getMacroArgExpandedLocation(
-  getBeginningOfIdentifier(Pos, AST.getSourceManager(), AST.getLangOpts()));
   std::vector Result;
-  if (auto M = locateMacroAt(IdentStartLoc, AST.getPreprocessor())) {
-if (auto Loc = makeLocation(AST.getASTContext(),
-M->Info->getDefinitionLoc(), *MainFilePath)) {
-  LocatedSymbol Macro;
-  Macro.Name = std::string(M->Name);
-  Macro.PreferredDeclaration = *Loc;
-  Macro.Definition = Loc;
-  Result.push_back(std::move(Macro));
-
-  // Don't look at the AST or index if we have a macro result.
-  // (We'd just return declarations referenced from the macro's
-  // expansion.)
-  return Result;
+  const auto *TouchedIdentifier =
+  syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
+  if (TouchedIdentifier) {
+if (auto M = locateMacroAt(TouchedIdentifier->location(),
+   AST.getPreprocessor())) {
+  if (auto Loc = makeLocation(AST.getASTContext(),
+  M->Info->getDefinitionLoc(), *MainFilePath)) {
+LocatedSymbol Macro;
+Macro.Name = std::string(M->Name);
+Macro.PreferredDeclaration = *Loc;
+Macro.Definition = Loc;
+Result.push_back(std::move(Macro));
+
+// Don't look at the AST or index if we have a macro result.
+// (We'd just return declarations referenced from the macro's
+// expansion.)
+return Result;
+  }
 }
   }
 
@@ -244,15 +255,6 @@
   // Keep track of SymbolID -> index mapping, to fill in index data later.
   llvm::DenseMap ResultIndex;
 
-  SourceLocation SourceLoc;
-  if (auto L = sourceLocationInMainFile(SM, Pos)) {
-SourceLoc = *L;
-  } else {
-elog("locateSymbolAt failed to convert position to source location: {0}",
- L.takeError());
-return Result;
-  }
-
   auto AddResultDecl = [&](const NamedDecl *D) {
 const NamedDecl *Def = getDefinition(D);
 const NamedDecl *Preferred = Def ? Def : D;
@@ -277,16 +279,15 @@
   // Emit all symbol locations (declaration or definition) from AST.
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
-  for (const NamedDecl *D : getDeclAtPosition(AST, SourceLoc, Relations)) {
+  for (const NamedDecl *D : getDeclAtPosition(AST, *CurLoc, Relations)) {
 // Special case: void foo() ^override: jump to the overridden method.
 if (const auto *CMD = llvm::dyn_cast(D)) {
-  const InheritableAttr* Attr = D->getAttr();
+  const InheritableAttr *Attr = D->getAttr();
   if (!Attr)
 Attr = D->getAttr();
-  const syntax::Token *Tok =
-  spelledIdentifierTouching(SourceLoc, AST.getTokens());
-  if (Attr && Tok &&
-  SM.getSpellingLoc(Attr->getLo

[clang-tools-extra] 2011d14 - [clangd] Clean-up XRefs.cpp from Lexer usages and unnecessary SourceLoc transformations

2020-02-26 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-02-26T17:51:27+01:00
New Revision: 2011d14296eeaae911e898d11154ee5d1a5db1d6

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

LOG: [clangd] Clean-up XRefs.cpp from Lexer usages and unnecessary SourceLoc 
transformations

Summary:
Get rid of calls to lexer and unnecessary source location
transformations.

Reviewers: sammccall

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index 3e0c9f79fc57..f7702c98b38f 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -43,6 +43,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -214,24 +215,34 @@ std::vector locateSymbolAt(ParsedAST &AST, 
Position Pos,
 }
   }
 
+  auto CurLoc = sourceLocationInMainFile(SM, Pos);
+  if (!CurLoc) {
+elog("locateSymbolAt failed to convert position to source location: {0}",
+ CurLoc.takeError());
+return {};
+  }
+
   // Macros are simple: there's no declaration/definition distinction.
   // As a consequence, there's no need to look them up in the index either.
-  SourceLocation IdentStartLoc = SM.getMacroArgExpandedLocation(
-  getBeginningOfIdentifier(Pos, AST.getSourceManager(), 
AST.getLangOpts()));
   std::vector Result;
-  if (auto M = locateMacroAt(IdentStartLoc, AST.getPreprocessor())) {
-if (auto Loc = makeLocation(AST.getASTContext(),
-M->Info->getDefinitionLoc(), *MainFilePath)) {
-  LocatedSymbol Macro;
-  Macro.Name = std::string(M->Name);
-  Macro.PreferredDeclaration = *Loc;
-  Macro.Definition = Loc;
-  Result.push_back(std::move(Macro));
-
-  // Don't look at the AST or index if we have a macro result.
-  // (We'd just return declarations referenced from the macro's
-  // expansion.)
-  return Result;
+  const auto *TouchedIdentifier =
+  syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
+  if (TouchedIdentifier) {
+if (auto M = locateMacroAt(TouchedIdentifier->location(),
+   AST.getPreprocessor())) {
+  if (auto Loc = makeLocation(AST.getASTContext(),
+  M->Info->getDefinitionLoc(), *MainFilePath)) 
{
+LocatedSymbol Macro;
+Macro.Name = std::string(M->Name);
+Macro.PreferredDeclaration = *Loc;
+Macro.Definition = Loc;
+Result.push_back(std::move(Macro));
+
+// Don't look at the AST or index if we have a macro result.
+// (We'd just return declarations referenced from the macro's
+// expansion.)
+return Result;
+  }
 }
   }
 
@@ -244,15 +255,6 @@ std::vector locateSymbolAt(ParsedAST &AST, 
Position Pos,
   // Keep track of SymbolID -> index mapping, to fill in index data later.
   llvm::DenseMap ResultIndex;
 
-  SourceLocation SourceLoc;
-  if (auto L = sourceLocationInMainFile(SM, Pos)) {
-SourceLoc = *L;
-  } else {
-elog("locateSymbolAt failed to convert position to source location: {0}",
- L.takeError());
-return Result;
-  }
-
   auto AddResultDecl = [&](const NamedDecl *D) {
 const NamedDecl *Def = getDefinition(D);
 const NamedDecl *Preferred = Def ? Def : D;
@@ -277,16 +279,15 @@ std::vector locateSymbolAt(ParsedAST &AST, 
Position Pos,
   // Emit all symbol locations (declaration or definition) from AST.
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
-  for (const NamedDecl *D : getDeclAtPosition(AST, SourceLoc, Relations)) {
+  for (const NamedDecl *D : getDeclAtPosition(AST, *CurLoc, Relations)) {
 // Special case: void foo() ^override: jump to the overridden method.
 if (const auto *CMD = llvm::dyn_cast(D)) {
-  const InheritableAttr* Attr = D->getAttr();
+  const InheritableAttr *Attr = D->getAttr();
   if (!Attr)
 Attr = D->getAttr();
-  const syntax::Token *Tok =
-  spelledIdentifierTouching(SourceLoc, AST.getTokens());
-  if (Attr && Tok &&
-  SM.getSpellingLoc(Attr->getLocation()) == Tok->location()) {
+  if (Attr && TouchedIdentifier &&
+  SM.getSpellingLoc(Attr->getLocation()) ==
+  TouchedIdentifier->location()) {
 // We may be overridding multiple methods - offer them all.
 for (const NamedDecl *ND : CMD->ove

[PATCH] D75166: [clangd] Clean-up XRefs.cpp from Lexer usages and unnecessary SourceLoc transformations

2020-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2011d14296ee: [clangd] Clean-up XRefs.cpp from Lexer usages 
and unnecessary SourceLoc… (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75166

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -97,6 +97,15 @@
   R"cpp(// Function parameter in decl
 void foo(int [[^bar]]);
   )cpp",
+  R"cpp(// Not touching any identifiers.
+struct Foo {
+  [[~]]Foo() {};
+};
+void foo() {
+  Foo f;
+  f.[[^~]]Foo();
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
@@ -960,6 +969,15 @@
class [[Foo]] {};
void func([[Fo^o]]);
   )cpp",
+  R"cpp(// Not touching any identifiers.
+struct Foo {
+  [[~]]Foo() {};
+};
+void foo() {
+  Foo f;
+  f.[[^~]]Foo();
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -43,6 +43,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -214,24 +215,34 @@
 }
   }
 
+  auto CurLoc = sourceLocationInMainFile(SM, Pos);
+  if (!CurLoc) {
+elog("locateSymbolAt failed to convert position to source location: {0}",
+ CurLoc.takeError());
+return {};
+  }
+
   // Macros are simple: there's no declaration/definition distinction.
   // As a consequence, there's no need to look them up in the index either.
-  SourceLocation IdentStartLoc = SM.getMacroArgExpandedLocation(
-  getBeginningOfIdentifier(Pos, AST.getSourceManager(), AST.getLangOpts()));
   std::vector Result;
-  if (auto M = locateMacroAt(IdentStartLoc, AST.getPreprocessor())) {
-if (auto Loc = makeLocation(AST.getASTContext(),
-M->Info->getDefinitionLoc(), *MainFilePath)) {
-  LocatedSymbol Macro;
-  Macro.Name = std::string(M->Name);
-  Macro.PreferredDeclaration = *Loc;
-  Macro.Definition = Loc;
-  Result.push_back(std::move(Macro));
-
-  // Don't look at the AST or index if we have a macro result.
-  // (We'd just return declarations referenced from the macro's
-  // expansion.)
-  return Result;
+  const auto *TouchedIdentifier =
+  syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
+  if (TouchedIdentifier) {
+if (auto M = locateMacroAt(TouchedIdentifier->location(),
+   AST.getPreprocessor())) {
+  if (auto Loc = makeLocation(AST.getASTContext(),
+  M->Info->getDefinitionLoc(), *MainFilePath)) {
+LocatedSymbol Macro;
+Macro.Name = std::string(M->Name);
+Macro.PreferredDeclaration = *Loc;
+Macro.Definition = Loc;
+Result.push_back(std::move(Macro));
+
+// Don't look at the AST or index if we have a macro result.
+// (We'd just return declarations referenced from the macro's
+// expansion.)
+return Result;
+  }
 }
   }
 
@@ -244,15 +255,6 @@
   // Keep track of SymbolID -> index mapping, to fill in index data later.
   llvm::DenseMap ResultIndex;
 
-  SourceLocation SourceLoc;
-  if (auto L = sourceLocationInMainFile(SM, Pos)) {
-SourceLoc = *L;
-  } else {
-elog("locateSymbolAt failed to convert position to source location: {0}",
- L.takeError());
-return Result;
-  }
-
   auto AddResultDecl = [&](const NamedDecl *D) {
 const NamedDecl *Def = getDefinition(D);
 const NamedDecl *Preferred = Def ? Def : D;
@@ -277,16 +279,15 @@
   // Emit all symbol locations (declaration or definition) from AST.
   DeclRelationSet Relations =
   DeclRelation::TemplatePattern | DeclRelation::Alias;
-  for (const NamedDecl *D : getDeclAtPosition(AST, SourceLoc, Relations)) {
+  for (const NamedDecl *D : getDeclAtPosition(AST, *CurLoc, Relations)) {
 // Special case: void foo() ^override: jump to the overridden method.
 if (const auto *CMD = llvm::dyn_cast(D)) {
-  const InheritableAttr* Attr = D->getAttr();
+  const InheritableAttr *Attr = D->getAttr();
   if (!Attr)
 Attr = D->getAttr();
-  const syntax::Token *Tok =
-  spelledIdentifierTouching(SourceLoc, AST.getTokens());
-  if (Attr &

Re: [clang] 83f4372 - [CodeGen] fix clang test that runs the optimizer pipeline; NFC

2020-02-26 Thread Sanjay Patel via cfe-commits
The test file dates back to:
https://reviews.llvm.org/D5698
...and I'm not familiar with _Complex enough to say how to fix this
properly (seems like the check lines are already limited such that -O0
rather than -O1 would work?).

But this file keeps wiggling unexpectedly, it's going to move again with
https://reviews.llvm.org/D75130

On Tue, Feb 25, 2020 at 1:15 PM Eric Christopher  wrote:

> Is there any way to pull this test out of clang and as an opt test? What's
> it trying to test?
>
> -eric
>
> On Tue, Feb 25, 2020 at 6:15 AM Sanjay Patel via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Sanjay Patel
>> Date: 2020-02-25T09:13:49-05:00
>> New Revision: 83f4372f3a708ceaa800feff8b1bd92ae2c3be5f
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/83f4372f3a708ceaa800feff8b1bd92ae2c3be5f
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/83f4372f3a708ceaa800feff8b1bd92ae2c3be5f.diff
>>
>> LOG: [CodeGen] fix clang test that runs the optimizer pipeline; NFC
>>
>> There's already a FIXME note on this file; it can break when the
>> underlying LLVM behavior changes independently of anything in clang.
>>
>> Added:
>>
>>
>> Modified:
>> clang/test/CodeGen/complex-math.c
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/test/CodeGen/complex-math.c
>> b/clang/test/CodeGen/complex-math.c
>> index e42418ad72c2..54dee473a364 100644
>> --- a/clang/test/CodeGen/complex-math.c
>> +++ b/clang/test/CodeGen/complex-math.c
>> @@ -93,14 +93,15 @@ float _Complex mul_float_rc(float a, float _Complex
>> b) {
>>// X86: ret
>>return a * b;
>>  }
>> +
>>  float _Complex mul_float_cc(float _Complex a, float _Complex b) {
>>// X86-LABEL: @mul_float_cc(
>>// X86: %[[AC:[^ ]+]] = fmul
>>// X86: %[[BD:[^ ]+]] = fmul
>>// X86: %[[AD:[^ ]+]] = fmul
>>// X86: %[[BC:[^ ]+]] = fmul
>> -  // X86: %[[RR:[^ ]+]] = fsub float %[[AC]], %[[BD]]
>> -  // X86: %[[RI:[^ ]+]] = fadd float
>> +  // X86: %[[RR:[^ ]+]] = fsub
>> +  // X86: %[[RI:[^ ]+]] = fadd
>>// X86-DAG: %[[AD]]
>>// X86-DAG: ,
>>// X86-DAG: %[[BC]]
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75171: [Analyzer] Fix for incorrect use of container and iterator checkers

2020-02-26 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus requested changes to this revision.
Szelethus added a comment.
This revision now requires changes to proceed.

Im sorry, i though we talked about internal code and we're stuck with the 
checker interface -- this should definitely be solved by changing the parameter 
of the `shouldRegister` function to `CheckerManager`. If you want to emit 
errors for incorrect file, there is an example in `UninitializedObjectChecker` 
and maybe in `GenericTaintChecker`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75171



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


[PATCH] D75184: [clang-tidy] Optional inheritance of file configs from parent directories 

2020-02-26 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 246758.
DmitryPolukhin added a comment.

Rebase on top of master


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75184

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy
  clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp


Index: clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
@@ -7,6 +7,9 @@
 // RUN: clang-tidy -dump-config %S/Inputs/config-files/2/- -- | FileCheck %s 
-check-prefix=CHECK-CHILD2
 // CHECK-CHILD2: Checks: {{.*}}from-parent
 // CHECK-CHILD2: HeaderFilterRegex: parent
+// RUN: clang-tidy -dump-config %S/Inputs/config-files/3/- -- | FileCheck %s 
-check-prefix=CHECK-CHILD3
+// CHECK-CHILD3: Checks: {{.*}}from-parent,from-child3
+// CHECK-CHILD3: HeaderFilterRegex: child3
 // RUN: clang-tidy -dump-config -checks='from-command-line' 
-header-filter='from command line' %S/Inputs/config-files/- -- | FileCheck %s 
-check-prefix=CHECK-COMMAND-LINE
 // CHECK-COMMAND-LINE: Checks: {{.*}}from-parent,from-command-line
 // CHECK-COMMAND-LINE: HeaderFilterRegex: from command line
Index: 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy
@@ -0,0 +1,3 @@
+InheritParentConfig: true
+Checks: 'from-child3'
+HeaderFilterRegex: 'child3'
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.h
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -106,6 +106,10 @@
 
   /// Add extra compilation arguments to the start of the list.
   llvm::Optional ExtraArgsBefore;
+
+  /// Config flag for FileOptionsProvider to also include config from parent
+  /// dir.
+  llvm::Optional InheritParentConfig;
 };
 
 /// Abstract interface for retrieving various ClangTidy options.
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -92,6 +92,7 @@
 IO.mapOptional("CheckOptions", NOpts->Options);
 IO.mapOptional("ExtraArgs", Options.ExtraArgs);
 IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
+IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
   }
 };
 
@@ -237,6 +238,7 @@
   DefaultOptionsProvider::getRawOptions(AbsoluteFilePath.str());
   OptionsSource CommandLineOptions(OverrideOptions,
OptionsSourceTypeCheckCommandLineOption);
+  size_t FirstFileConfig = RawOptions.size();
   // Look for a suitable configuration file in all parent directories of the
   // file. Start with the immediate parent directory and move up.
   StringRef Path = llvm::sys::path::parent_path(AbsoluteFilePath.str());
@@ -262,9 +264,14 @@
   CachedOptions[Path] = *Result;
 
   RawOptions.push_back(*Result);
-  break;
+  if (!Result->first.InheritParentConfig ||
+  !*Result->first.InheritParentConfig)
+break;
 }
   }
+  // Reverse order of file configs because closer configs should have higher
+  // priority.
+  std::reverse(RawOptions.begin() + FirstFileConfig, RawOptions.end());
   RawOptions.push_back(CommandLineOptions);
   return RawOptions;
 }


Index: clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
@@ -7,6 +7,9 @@
 // RUN: clang-tidy -dump-config %S/Inputs/config-files/2/- -- | FileCheck %s -check-prefix=CHECK-CHILD2
 // CHECK-CHILD2: Checks: {{.*}}from-parent
 // CHECK-CHILD2: HeaderFilterRegex: parent
+// RUN: clang-tidy -dump-config %S/Inputs/config-files/3/- -- | FileCheck %s -check-prefix=CHECK-CHILD3
+// CHECK-CHILD3: Checks: {{.*}}from-parent,from-child3
+// CHECK-CHILD3: HeaderFilterRegex: child3
 // RUN: clang-tidy -dump-config -checks='from-command-line' -header-filter='from command line' %S/Inputs/config-files/- -- | FileCheck %s -check-prefix=CHECK-COMMAND-LINE
 // CHECK-COMMAND-LINE: Checks: {{.*}}from-parent,from-command-line
 // CHECK-COMMAND-LINE: HeaderFilterRegex: from command line
Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy
===

[clang] 590dc8d - Use virtual functions in ParsedAttrInfo instead of function pointers

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

Author: John Brawn
Date: 2020-02-26T17:24:30Z
New Revision: 590dc8d02cd781b110a87b82476c3557cb5957c3

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

LOG: Use virtual functions in ParsedAttrInfo instead of function pointers

This doesn't do anything on its own, but it's the first step towards
allowing plugins to define attributes. It does simplify the
ParsedAttrInfo generation in ClangAttrEmitter a little though.

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

Added: 


Modified: 
clang/lib/Sema/ParsedAttr.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index 5d0a734f237a..c814639f00ea 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -110,13 +110,26 @@ struct ParsedAttrInfo {
   unsigned IsKnownToGCC : 1;
   unsigned IsSupportedByPragmaAttribute : 1;
 
-  bool (*DiagAppertainsToDecl)(Sema &S, const ParsedAttr &Attr, const Decl *);
-  bool (*DiagLangOpts)(Sema &S, const ParsedAttr &Attr);
-  bool (*ExistsInTarget)(const TargetInfo &Target);
-  unsigned (*SpellingIndexToSemanticSpelling)(const ParsedAttr &Attr);
-  void (*GetPragmaAttributeMatchRules)(
-  llvm::SmallVectorImpl> &Rules,
-  const LangOptions &LangOpts);
+  virtual ~ParsedAttrInfo() = default;
+
+  virtual bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr,
+const Decl *) const {
+return true;
+  }
+  virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const {
+return true;
+  }
+  virtual bool existsInTarget(const TargetInfo &Target) const {
+return true;
+  }
+  virtual unsigned
+  spellingIndexToSemanticSpelling(const ParsedAttr &Attr) const {
+return UINT_MAX;
+  }
+  virtual void getPragmaAttributeMatchRules(
+llvm::SmallVectorImpl> &Rules,
+const LangOptions &LangOpts) const {
+  }
 };
 
 namespace {
@@ -126,7 +139,13 @@ namespace {
 } // namespace
 
 static const ParsedAttrInfo &getInfo(const ParsedAttr &A) {
-  return AttrInfoMap[A.getKind()];
+  // If we have a ParsedAttrInfo for this ParsedAttr then return that,
+  // otherwise return a default ParsedAttrInfo.
+  if (A.getKind() < llvm::array_lengthof(AttrInfoMap))
+return *AttrInfoMap[A.getKind()];
+
+  static ParsedAttrInfo DefaultParsedAttrInfo;
+  return DefaultParsedAttrInfo;
 }
 
 unsigned ParsedAttr::getMinArgs() const { return getInfo(*this).NumArgs; }
@@ -140,7 +159,7 @@ bool ParsedAttr::hasCustomParsing() const {
 }
 
 bool ParsedAttr::diagnoseAppertainsTo(Sema &S, const Decl *D) const {
-  return getInfo(*this).DiagAppertainsToDecl(S, *this, D);
+  return getInfo(*this).diagAppertainsToDecl(S, *this, D);
 }
 
 bool ParsedAttr::appliesToDecl(const Decl *D,
@@ -152,11 +171,11 @@ void ParsedAttr::getMatchRules(
 const LangOptions &LangOpts,
 SmallVectorImpl> &MatchRules)
 const {
-  return getInfo(*this).GetPragmaAttributeMatchRules(MatchRules, LangOpts);
+  return getInfo(*this).getPragmaAttributeMatchRules(MatchRules, LangOpts);
 }
 
 bool ParsedAttr::diagnoseLangOpts(Sema &S) const {
-  return getInfo(*this).DiagLangOpts(S, *this);
+  return getInfo(*this).diagLangOpts(S, *this);
 }
 
 bool ParsedAttr::isTargetSpecificAttr() const {
@@ -168,7 +187,7 @@ bool ParsedAttr::isTypeAttr() const { return 
getInfo(*this).IsType; }
 bool ParsedAttr::isStmtAttr() const { return getInfo(*this).IsStmt; }
 
 bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
-  return getInfo(*this).ExistsInTarget(Target);
+  return getInfo(*this).existsInTarget(Target);
 }
 
 bool ParsedAttr::isKnownToGCC() const { return getInfo(*this).IsKnownToGCC; }
@@ -178,7 +197,7 @@ bool ParsedAttr::isSupportedByPragmaAttribute() const {
 }
 
 unsigned ParsedAttr::getSemanticSpelling() const {
-  return getInfo(*this).SpellingIndexToSemanticSpelling(*this);
+  return getInfo(*this).spellingIndexToSemanticSpelling(*this);
 }
 
 bool ParsedAttr::hasVariadicArg() const {

diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 116c382c1e8f..251cbecd1c45 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1814,7 +1814,7 @@ struct PragmaClangAttributeSupport {
 
   void emitMatchRuleList(raw_ostream &OS);
 
-  std::string generateStrictConformsTo(const Record &Attr, raw_ostream &OS);
+  void generateStrictConformsTo(const Record &Attr, raw_ostream &OS);
 
   void generateParsingHelpers(raw_ostream &OS);
 };
@@ -1975,21 +1975,17 @@ static std::string 
GenerateTestExpression(ArrayRef LangOpts) {
   return Test;
 }
 
-std::string
+void
 PragmaClangAttributeSupport::generateStrictConformsTo(const Record &Attr,

[PATCH] D75193: [clangd] Get rid of lexer usage in AST.cpp

2020-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.
kadircet added a parent revision: D75176: [clangd] Get rid of 
getBeginningOfIdentifier helper.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75193

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


Index: clang-tools-extra/clangd/AST.h
===
--- clang-tools-extra/clangd/AST.h
+++ clang-tools-extra/clangd/AST.h
@@ -109,7 +109,6 @@
 QualType declaredType(const TypeDecl *D);
 
 /// Retrieves the deduced type at a given location (auto, decltype).
-/// Retuns None unless Loc starts an auto/decltype token.
 /// It will return the underlying type.
 llvm::Optional getDeducedType(ASTContext &, SourceLocation Loc);
 
Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -25,7 +25,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
 #include "clang/Index/USRGeneration.h"
-#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -417,16 +416,8 @@
 
 llvm::Optional getDeducedType(ASTContext &ASTCtx,
 SourceLocation Loc) {
-  Token Tok;
-  // Only try to find a deduced type if the token is auto or decltype.
-  if (!Loc.isValid() ||
-  Lexer::getRawToken(Loc, Tok, ASTCtx.getSourceManager(),
- ASTCtx.getLangOpts(), false) ||
-  !Tok.is(tok::raw_identifier) ||
-  !(Tok.getRawIdentifier() == "auto" ||
-Tok.getRawIdentifier() == "decltype")) {
+  if (!Loc.isValid())
 return {};
-  }
   DeducedTypeVisitor V(Loc);
   V.TraverseAST(ASTCtx);
   if (V.DeducedType.isNull())


Index: clang-tools-extra/clangd/AST.h
===
--- clang-tools-extra/clangd/AST.h
+++ clang-tools-extra/clangd/AST.h
@@ -109,7 +109,6 @@
 QualType declaredType(const TypeDecl *D);
 
 /// Retrieves the deduced type at a given location (auto, decltype).
-/// Retuns None unless Loc starts an auto/decltype token.
 /// It will return the underlying type.
 llvm::Optional getDeducedType(ASTContext &, SourceLocation Loc);
 
Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -25,7 +25,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
 #include "clang/Index/USRGeneration.h"
-#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -417,16 +416,8 @@
 
 llvm::Optional getDeducedType(ASTContext &ASTCtx,
 SourceLocation Loc) {
-  Token Tok;
-  // Only try to find a deduced type if the token is auto or decltype.
-  if (!Loc.isValid() ||
-  Lexer::getRawToken(Loc, Tok, ASTCtx.getSourceManager(),
- ASTCtx.getLangOpts(), false) ||
-  !Tok.is(tok::raw_identifier) ||
-  !(Tok.getRawIdentifier() == "auto" ||
-Tok.getRawIdentifier() == "decltype")) {
+  if (!Loc.isValid())
 return {};
-  }
   DeducedTypeVisitor V(Loc);
   V.TraverseAST(ASTCtx);
   if (V.DeducedType.isNull())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31337: Use virtual functions in ParsedAttrInfo instead of function pointers

2020-02-26 Thread John Brawn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG590dc8d02cd7: Use virtual functions in ParsedAttrInfo 
instead of function pointers (authored by john.brawn).

Changed prior to commit:
  https://reviews.llvm.org/D31337?vs=242363&id=246765#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D31337

Files:
  clang/lib/Sema/ParsedAttr.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1814,7 +1814,7 @@
 
   void emitMatchRuleList(raw_ostream &OS);
 
-  std::string generateStrictConformsTo(const Record &Attr, raw_ostream &OS);
+  void generateStrictConformsTo(const Record &Attr, raw_ostream &OS);
 
   void generateParsingHelpers(raw_ostream &OS);
 };
@@ -1975,21 +1975,17 @@
   return Test;
 }
 
-std::string
+void
 PragmaClangAttributeSupport::generateStrictConformsTo(const Record &Attr,
   raw_ostream &OS) {
-  if (!isAttributedSupported(Attr))
-return "nullptr";
+  if (!isAttributedSupported(Attr) || Attr.isValueUnset("Subjects"))
+return;
   // Generate a function that constructs a set of matching rules that describe
   // to which declarations the attribute should apply to.
-  std::string FnName = "matchRulesFor" + Attr.getName().str();
-  OS << "static void " << FnName << "(llvm::SmallVectorImpl> &MatchRules, const LangOptions &LangOpts) {\n";
-  if (Attr.isValueUnset("Subjects")) {
-OS << "}\n\n";
-return FnName;
-  }
+ << ", bool>> &MatchRules, const LangOptions &LangOpts) const {\n";
   const Record *SubjectObj = Attr.getValueAsDef("Subjects");
   std::vector Subjects = SubjectObj->getValueAsListOfDefs("Subjects");
   for (const auto *Subject : Subjects) {
@@ -2006,7 +2002,6 @@
 }
   }
   OS << "}\n\n";
-  return FnName;
 }
 
 void PragmaClangAttributeSupport::generateParsingHelpers(raw_ostream &OS) {
@@ -3300,14 +3295,8 @@
 
   // If there is a variadic argument, we will set the optional argument count
   // to its largest value. Since it's currently a 4-bit number, we set it to 15.
-  OS << ArgCount << ", " << (HasVariadic ? 15 : OptCount);
-}
-
-static void GenerateDefaultAppertainsTo(raw_ostream &OS) {
-  OS << "static bool defaultAppertainsTo(Sema &, const ParsedAttr &,";
-  OS << "const Decl *) {\n";
-  OS << "  return true;\n";
-  OS << "}\n\n";
+  OS << "NumArgs = " << ArgCount << ";\n";
+  OS << "OptArgs = " << (HasVariadic ? 15 : OptCount) << ";\n";
 }
 
 static std::string GetDiagnosticSpelling(const Record &R) {
@@ -3388,16 +3377,14 @@
   return "is" + Subject.getName().str();
 }
 
-static std::string GenerateCustomAppertainsTo(const Record &Subject,
-  raw_ostream &OS) {
+static void GenerateCustomAppertainsTo(const Record &Subject, raw_ostream &OS) {
   std::string FnName = functionNameForCustomAppertainsTo(Subject);
 
-  // If this code has already been generated, simply return the previous
-  // instance of it.
+  // If this code has already been generated, we don't need to do anything.
   static std::set CustomSubjectSet;
   auto I = CustomSubjectSet.find(FnName);
   if (I != CustomSubjectSet.end())
-return *I;
+return;
 
   // This only works with non-root Decls.
   Record *Base = Subject.getValueAsDef(BaseFieldName);
@@ -3406,7 +3393,7 @@
   if (Base->isSubClassOf("SubsetSubject")) {
 PrintFatalError(Subject.getLoc(),
 "SubsetSubjects within SubsetSubjects is not supported");
-return "";
+return;
   }
 
   OS << "static bool " << FnName << "(const Decl *D) {\n";
@@ -3418,14 +3405,13 @@
   OS << "}\n\n";
 
   CustomSubjectSet.insert(FnName);
-  return FnName;
 }
 
-static std::string GenerateAppertainsTo(const Record &Attr, raw_ostream &OS) {
+static void GenerateAppertainsTo(const Record &Attr, raw_ostream &OS) {
   // If the attribute does not contain a Subjects definition, then use the
   // default appertainsTo logic.
   if (Attr.isValueUnset("Subjects"))
-return "defaultAppertainsTo";
+return;
 
   const Record *SubjectObj = Attr.getValueAsDef("Subjects");
   std::vector Subjects = SubjectObj->getValueAsListOfDefs("Subjects");
@@ -3433,52 +3419,46 @@
   // If the list of subjects is empty, it is assumed that the attribute
   // appertains to everything.
   if (Subjects.empty())
-return "defaultAppertainsTo";
+return;
 
   bool Warn = SubjectObj->getValueAsDef("Diag")->getValueAsBit("Warn");
 
   // Otherwise, generate an appertainsTo check specific to this attribute which
-  // checks all of the given subjects against the Decl passed in. Return the
-  // name of that check to the caller.
+  // checks all of the given subjects against the Decl passed in.
   //
   // If 

[PATCH] D31338: Move ParsedAttrInfos into a registry and point to one in ParsedAttr

2020-02-26 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 246763.
john.brawn added a comment.
Herald added a subscriber: krytarowski.

This has been rewritten so that the registry is only used for attributes added 
by plugins, and everything else continues as before. This also removes the 
strange dependency I'd previously introduced, where Attributes.cpp (in 
libclangBasic.so) declared and used the registry but ParsedAttr.cpp (in 
libclangSema.so) populated it - now the registry is declared and used solely 
within ParsedAttr.cpp.


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

https://reviews.llvm.org/D31338

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Basic/Attributes.cpp
  clang/lib/Sema/ParsedAttr.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3625,9 +3625,11 @@
 
 // We need to generate struct instances based off ParsedAttrInfo from
 // ParsedAttr.cpp.
+const std::string &AttrName = I->first;
 const Record &Attr = *I->second;
 OS << "struct ParsedAttrInfo" << I->first << " : public ParsedAttrInfo {\n";
 OS << "  ParsedAttrInfo" << I->first << "() {\n";
+OS << "AttrKind = ParsedAttr::AT_" << AttrName << ";\n";
 emitArgInfo(Attr, OS);
 OS << "HasCustomParsing = ";
 OS << Attr.getValueAsBit("HasCustomParsing") << ";\n";
@@ -3642,6 +3644,20 @@
 OS << IsKnownToGCC(Attr) << ";\n";
 OS << "IsSupportedByPragmaAttribute = ";
 OS << PragmaAttributeSupport.isAttributedSupported(*I->second) << ";\n";
+for (const auto &S : GetFlattenedSpellings(Attr)) {
+  const std::string &RawSpelling = S.name();
+  std::string Spelling;
+  if (S.variety() == "CXX11" || S.variety() == "C2x") {
+Spelling += S.nameSpace();
+Spelling += "::";
+  }
+  if (S.variety() == "GNU")
+Spelling += NormalizeGNUAttrSpelling(RawSpelling);
+  else
+Spelling += RawSpelling;
+  OS << "Spellings.push_back({AttributeCommonInfo::AS_" << S.variety();
+  OS << ",\"" << Spelling << "\"});\n";
+}
 OS << "  }\n";
 GenerateAppertainsTo(Attr, OS);
 GenerateLangOptRequirements(Attr, OS);
Index: clang/lib/Sema/ParsedAttr.cpp
===
--- clang/lib/Sema/ParsedAttr.cpp
+++ clang/lib/Sema/ParsedAttr.cpp
@@ -25,6 +25,8 @@
 
 using namespace clang;
 
+LLVM_INSTANTIATE_REGISTRY(ParsedAttrInfoRegistry)
+
 IdentifierLoc *IdentifierLoc::create(ASTContext &Ctx, SourceLocation Loc,
  IdentifierInfo *Ident) {
   IdentifierLoc *Result = new (Ctx) IdentifierLoc;
@@ -100,66 +102,58 @@
   pool.Attrs.clear();
 }
 
-struct ParsedAttrInfo {
-  unsigned NumArgs : 4;
-  unsigned OptArgs : 4;
-  unsigned HasCustomParsing : 1;
-  unsigned IsTargetSpecific : 1;
-  unsigned IsType : 1;
-  unsigned IsStmt : 1;
-  unsigned IsKnownToGCC : 1;
-  unsigned IsSupportedByPragmaAttribute : 1;
-
-  virtual ~ParsedAttrInfo() = default;
-
-  virtual bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr,
-const Decl *) const {
-return true;
-  }
-  virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const {
-return true;
-  }
-  virtual bool existsInTarget(const TargetInfo &Target) const {
-return true;
-  }
-  virtual unsigned
-  spellingIndexToSemanticSpelling(const ParsedAttr &Attr) const {
-return UINT_MAX;
-  }
-  virtual void getPragmaAttributeMatchRules(
-llvm::SmallVectorImpl> &Rules,
-const LangOptions &LangOpts) const {
-  }
-};
-
 namespace {
 
 #include "clang/Sema/AttrParsedAttrImpl.inc"
 
 } // namespace
 
-static const ParsedAttrInfo &getInfo(const ParsedAttr &A) {
-  // If we have a ParsedAttrInfo for this ParsedAttr then return that,
-  // otherwise return a default ParsedAttrInfo.
-  if (A.getKind() < llvm::array_lengthof(AttrInfoMap))
-return *AttrInfoMap[A.getKind()];
-
+const ParsedAttrInfo &ParsedAttrInfo::get(const AttributeCommonInfo &A) {
+  // If we have a ParsedAttrInfo for this ParsedAttr then return that.
+  if (A.getParsedKind() < llvm::array_lengthof(AttrInfoMap))
+return *AttrInfoMap[A.getParsedKind()];
+
+  // If this is an ignored attribute then return an appropriate ParsedAttrInfo.
+  static ParsedAttrInfo IgnoredParsedAttrInfo(
+  AttributeCommonInfo::IgnoredAttribute);
+  if (A.getParsedKind() == AttributeCommonInfo::IgnoredAttribute)
+return IgnoredParsedAttrInfo;
+
+  // Otherwise this may be an attribute defined by a plugin. First instantiate
+  // all plugin attributes if we haven't already done so.
+  static std::list> PluginAttrInstances;
+  if (PluginAttrInstances.empty())
+for (auto It : ParsedAttrInfoRegistry::entries())
+  PluginAttrIns

[PATCH] D75056: [Driver] Default to -fno-common

2020-02-26 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer updated this revision to Diff 246770.
SjoerdMeijer added a comment.

minor test update


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

https://reviews.llvm.org/D75056

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/2008-07-21-mixed-var-fn-decl.c
  clang/test/CodeGen/2009-10-20-GlobalDebug.c
  clang/test/CodeGen/aarch64-sve.c
  clang/test/CodeGen/address-space.c
  clang/test/CodeGen/alias.c
  clang/test/CodeGen/align-systemz.c
  clang/test/CodeGen/alignment.c
  clang/test/CodeGen/asm-label.c
  clang/test/CodeGen/attr-weak-import.c
  clang/test/CodeGen/attr-weakref2.c
  clang/test/CodeGen/attributes.c
  clang/test/CodeGen/blocks-windows.c
  clang/test/CodeGen/bool-convert.c
  clang/test/CodeGen/c11atomics.c
  clang/test/CodeGen/cfstring-elf-cfbuild-x86_64.c
  clang/test/CodeGen/cfstring-windows.c
  clang/test/CodeGen/default-address-space.c
  clang/test/CodeGen/dllexport-1.c
  clang/test/CodeGen/dllexport.c
  clang/test/CodeGen/dllimport.c
  clang/test/CodeGen/microsoft-no-common-align.c
  clang/test/CodeGen/no-common.c
  clang/test/CodeGen/pr25786.c
  clang/test/CodeGen/pragma-pack-1.c
  clang/test/CodeGen/pragma-weak.c
  clang/test/CodeGen/private-extern-redef.c
  clang/test/CodeGen/tentative-decls.c
  clang/test/CodeGen/tls-model.c
  clang/test/CodeGen/visibility.c
  clang/test/CodeGen/vlt_to_pointer.c
  clang/test/CodeGen/volatile-1.c
  clang/test/CodeGen/weak-global.c
  clang/test/CodeGen/windows-on-arm-dllimport-dllexport.c
  clang/test/CodeGenCXX/clang-sections-tentative.c
  clang/test/CodeGenObjC/constant-string-class.m
  clang/test/CodeGenObjC/tentative-cfconstantstring.m
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
  clang/test/Driver/apple-kext-mkernel.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/fuchsia.c
  clang/test/Driver/no-common.c
  clang/test/Driver/xcore-opts.c
  clang/test/Frontend/ast-codegen.c
  clang/test/Headers/xmmintrin.c
  clang/test/PCH/chain-external-defs.c
  clang/test/PCH/external-defs.c
  clang/test/PCH/tentative-defs.c
  clang/test/Parser/pragma-visibility2.c

Index: clang/test/Parser/pragma-visibility2.c
===
--- clang/test/Parser/pragma-visibility2.c
+++ clang/test/Parser/pragma-visibility2.c
@@ -6,14 +6,14 @@
 #pragma GCC visibility push(hidden)
 
 int v1;
-// CHECK: @v1 = common hidden global i32 0, align 4
+// CHECK: @v1 = hidden global i32 0, align 4
 
 #pragma GCC visibility pop
 
 int v2;
-// CHECK: @v2 = common global i32 0, align 4
+// CHECK: @v2 = global i32 0, align 4
 
 _Pragma("GCC visibility push(hidden)");
 
 int v3;
-// CHECK: @v3 = common hidden global i32 0, align 4
+// CHECK: @v3 = hidden global i32 0, align 4
Index: clang/test/PCH/tentative-defs.c
===
--- clang/test/PCH/tentative-defs.c
+++ clang/test/PCH/tentative-defs.c
@@ -1,6 +1,6 @@
 // Test with pch.
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/tentative-defs.h
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -include-pch %t.pch -verify -emit-llvm -o %t %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fcommon -emit-pch -o %t.pch %S/tentative-defs.h
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fcommon -include-pch %t.pch -verify -emit-llvm -o %t %s
 // REQUIRES: x86-registered-target
 
 // RUN: grep "@variable = common global i32 0" %t | count 1
Index: clang/test/PCH/external-defs.c
===
--- clang/test/PCH/external-defs.c
+++ clang/test/PCH/external-defs.c
@@ -3,16 +3,16 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/external-defs.h
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -include-pch %t.pch -emit-llvm -o %t %s
 
-// RUN: grep "@x = common global i32 0" %t | count 1
+// RUN: grep "@x = global i32 0" %t | count 1
 // RUN: not grep "@z" %t
 
 // RUN: grep "@x2 = global i32 19" %t | count 1
 int x2 = 19;
 
-// RUN: grep "@incomplete_array = common global .*1 x i32" %t | count 1
-// RUN: grep "@incomplete_array2 = common global .*17 x i32" %t | count 1
+// RUN: grep "@incomplete_array = global .*1 x i32" %t | count 1
+// RUN: grep "@incomplete_array2 = global .*17 x i32" %t | count 1
 int incomplete_array2[17];
-// RUN: grep "@incomplete_array3 = common global .*1 x i32" %t | count 1
+// RUN: grep "@incomplete_array3 = global .*1 x i32" %t | count 1
 int incomplete_array3[];
 
 struct S {
Index: clang/test/PCH/chain-external-defs.c
===
--- clang/test/PCH/chain-external-defs.c
+++ clang/test/PCH/chain-external-defs.c
@@ -16,11 +16,11 @@
 
 // Z-NOT: @z
 
-// XA: @x = common global i32 0
-// XA-NOT: @x = common global i32

[PATCH] D75056: [Driver] Default to -fno-common

2020-02-26 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer updated this revision to Diff 246768.
SjoerdMeijer added a comment.
Herald added subscribers: kerbowa, nhaehnle, jvesely.

Thanks for catching that. Now it shows more changes in tests, so updated a 
bunch of tests.


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

https://reviews.llvm.org/D75056

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/2008-07-21-mixed-var-fn-decl.c
  clang/test/CodeGen/2009-10-20-GlobalDebug.c
  clang/test/CodeGen/aarch64-sve.c
  clang/test/CodeGen/address-space.c
  clang/test/CodeGen/alias.c
  clang/test/CodeGen/align-systemz.c
  clang/test/CodeGen/alignment.c
  clang/test/CodeGen/asm-label.c
  clang/test/CodeGen/attr-weak-import.c
  clang/test/CodeGen/attr-weakref2.c
  clang/test/CodeGen/attributes.c
  clang/test/CodeGen/blocks-windows.c
  clang/test/CodeGen/bool-convert.c
  clang/test/CodeGen/c11atomics.c
  clang/test/CodeGen/cfstring-elf-cfbuild-x86_64.c
  clang/test/CodeGen/cfstring-windows.c
  clang/test/CodeGen/default-address-space.c
  clang/test/CodeGen/dllexport-1.c
  clang/test/CodeGen/dllexport.c
  clang/test/CodeGen/dllimport.c
  clang/test/CodeGen/microsoft-no-common-align.c
  clang/test/CodeGen/no-common.c
  clang/test/CodeGen/pr25786.c
  clang/test/CodeGen/pragma-pack-1.c
  clang/test/CodeGen/pragma-weak.c
  clang/test/CodeGen/private-extern-redef.c
  clang/test/CodeGen/tentative-decls.c
  clang/test/CodeGen/tls-model.c
  clang/test/CodeGen/visibility.c
  clang/test/CodeGen/vlt_to_pointer.c
  clang/test/CodeGen/volatile-1.c
  clang/test/CodeGen/weak-global.c
  clang/test/CodeGen/windows-on-arm-dllimport-dllexport.c
  clang/test/CodeGenCXX/clang-sections-tentative.c
  clang/test/CodeGenObjC/constant-string-class.m
  clang/test/CodeGenObjC/tentative-cfconstantstring.m
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
  clang/test/Driver/apple-kext-mkernel.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/fuchsia.c
  clang/test/Driver/no-common.c
  clang/test/Driver/xcore-opts.c
  clang/test/Frontend/ast-codegen.c
  clang/test/Headers/xmmintrin.c
  clang/test/PCH/chain-external-defs.c
  clang/test/PCH/external-defs.c
  clang/test/PCH/tentative-defs.c
  clang/test/Parser/pragma-visibility2.c

Index: clang/test/Parser/pragma-visibility2.c
===
--- clang/test/Parser/pragma-visibility2.c
+++ clang/test/Parser/pragma-visibility2.c
@@ -6,14 +6,14 @@
 #pragma GCC visibility push(hidden)
 
 int v1;
-// CHECK: @v1 = common hidden global i32 0, align 4
+// CHECK: @v1 = hidden global i32 0, align 4
 
 #pragma GCC visibility pop
 
 int v2;
-// CHECK: @v2 = common global i32 0, align 4
+// CHECK: @v2 = global i32 0, align 4
 
 _Pragma("GCC visibility push(hidden)");
 
 int v3;
-// CHECK: @v3 = common hidden global i32 0, align 4
+// CHECK: @v3 = hidden global i32 0, align 4
Index: clang/test/PCH/tentative-defs.c
===
--- clang/test/PCH/tentative-defs.c
+++ clang/test/PCH/tentative-defs.c
@@ -1,6 +1,6 @@
 // Test with pch.
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/tentative-defs.h
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -include-pch %t.pch -verify -emit-llvm -o %t %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fcommon -emit-pch -o %t.pch %S/tentative-defs.h
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fcommon -include-pch %t.pch -verify -emit-llvm -o %t %s
 // REQUIRES: x86-registered-target
 
 // RUN: grep "@variable = common global i32 0" %t | count 1
Index: clang/test/PCH/external-defs.c
===
--- clang/test/PCH/external-defs.c
+++ clang/test/PCH/external-defs.c
@@ -3,16 +3,16 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/external-defs.h
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -include-pch %t.pch -emit-llvm -o %t %s
 
-// RUN: grep "@x = common global i32 0" %t | count 1
+// RUN: grep "@x = global i32 0" %t | count 1
 // RUN: not grep "@z" %t
 
 // RUN: grep "@x2 = global i32 19" %t | count 1
 int x2 = 19;
 
-// RUN: grep "@incomplete_array = common global .*1 x i32" %t | count 1
-// RUN: grep "@incomplete_array2 = common global .*17 x i32" %t | count 1
+// RUN: grep "@incomplete_array = global .*1 x i32" %t | count 1
+// RUN: grep "@incomplete_array2 = global .*17 x i32" %t | count 1
 int incomplete_array2[17];
-// RUN: grep "@incomplete_array3 = common global .*1 x i32" %t | count 1
+// RUN: grep "@incomplete_array3 = global .*1 x i32" %t | count 1
 int incomplete_array3[];
 
 struct S {
Index: clang/test/PCH/chain-external-defs.c
===
--- clang/test/PCH/chain-external-defs.c
+++ clang/test/PCH

  1   2   >