[PATCH] D92148: [clangd] Do not treat line as inactive if skipped range ends at character position 0

2020-11-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92148

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


[PATCH] D92155: Load plugins when creating a CompilerInvocation.

2020-11-25 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Is it possible to write tests for this, obviously they will only work with 
plugin support on the current platform.
Also now that this is loaded from the command line, how will this play nicely 
with other tools that haven't been built with plugin support?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92155

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


[PATCH] D92155: Load plugins when creating a CompilerInvocation.

2020-11-25 Thread Yafei Liu via Phabricator via cfe-commits
psionic12 updated this revision to Diff 307763.
psionic12 added a comment.

Fix some syntax


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92155

Files:
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/tools/clang-check/CMakeLists.txt


Index: clang/tools/clang-check/CMakeLists.txt
===
--- clang/tools/clang-check/CMakeLists.txt
+++ clang/tools/clang-check/CMakeLists.txt
@@ -19,3 +19,8 @@
   clangStaticAnalyzerFrontend
   clangTooling
   )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+export_executable_symbols_for_plugins(clang-check)
+endif()
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -203,25 +203,6 @@
 return true;
   }
 
-  // Load any requested plugins.
-  for (const std::string  : Clang->getFrontendOpts().Plugins) {
-std::string Error;
-if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), 
))
-  Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
-<< Path << Error;
-  }
-
-  // Check if any of the loaded plugins replaces the main AST action
-  for (const FrontendPluginRegistry::entry  :
-   FrontendPluginRegistry::entries()) {
-std::unique_ptr P(Plugin.instantiate());
-if (P->getActionType() == PluginASTAction::ReplaceAction) {
-  Clang->getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
-  Clang->getFrontendOpts().ActionName = Plugin.getName().str();
-  break;
-}
-  }
-
   // Honor -mllvm.
   //
   // FIXME: Remove this, one day.
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3899,6 +3899,24 @@
   Res.getCodeGenOpts().Argv0 = Argv0;
   Res.getCodeGenOpts().CommandLineArgs = CommandLineArgs;
 
+  // Load any requested plugins.
+  for (const std::string  : Res.getFrontendOpts().Plugins) {
+std::string Error;
+if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), 
))
+  Diags.Report(diag::err_fe_unable_to_load_plugin) << Path << Error;
+  }
+
+  // Check if any of the loaded plugins replaces the main AST action
+  for (const FrontendPluginRegistry::entry  :
+   FrontendPluginRegistry::entries()) {
+std::unique_ptr P(Plugin.instantiate());
+if (P->getActionType() == PluginASTAction::ReplaceAction) {
+  Res.getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
+  Res.getFrontendOpts().ActionName = Plugin.getName().str();
+  break;
+}
+  }
+
   return Success;
 }
 
Index: clang-tools-extra/clangd/tool/CMakeLists.txt
===
--- clang-tools-extra/clangd/tool/CMakeLists.txt
+++ clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -39,3 +39,8 @@
   clangdSupport
   ${CLANGD_XPC_LIBS}
   )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(clangd)
+endif()


Index: clang/tools/clang-check/CMakeLists.txt
===
--- clang/tools/clang-check/CMakeLists.txt
+++ clang/tools/clang-check/CMakeLists.txt
@@ -19,3 +19,8 @@
   clangStaticAnalyzerFrontend
   clangTooling
   )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+export_executable_symbols_for_plugins(clang-check)
+endif()
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -203,25 +203,6 @@
 return true;
   }
 
-  // Load any requested plugins.
-  for (const std::string  : Clang->getFrontendOpts().Plugins) {
-std::string Error;
-if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), ))
-  Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
-<< Path << Error;
-  }
-
-  // Check if any of the loaded plugins replaces the main AST action
-  for (const FrontendPluginRegistry::entry  :
-   FrontendPluginRegistry::entries()) {
-std::unique_ptr P(Plugin.instantiate());
-if (P->getActionType() == PluginASTAction::ReplaceAction) {
-  Clang->getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
-  Clang->getFrontendOpts().ActionName = Plugin.getName().str();
-  break;
-}
-  }
-
   // Honor -mllvm.
   //
   // FIXME: Remove this, one day.
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- 

[PATCH] D92155: Load plugins when creating a CompilerInvocation.

2020-11-25 Thread Yafei Liu via Phabricator via cfe-commits
psionic12 created this revision.
psionic12 added reviewers: njames93, grosser, chapuni, john.brawn, alexfh, 
sammccall, nridge.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, mgorny.
Herald added a project: clang.
psionic12 requested review of this revision.
Herald added a subscriber: ilya-biryukov.

Since frontend plugins can report diagnostics nowadays,
the old way of loading plugins only fits for clang it self,
tools like clang-check and clangd will not load plugins
even if the `getFrontendOpts().Plugins` has paths of plugins.

To make all tools to report diagnostics from plugins,
move the loading into `CompilerInvocation::CreateFromArgs()`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92155

Files:
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/tools/clang-check/CMakeLists.txt


Index: clang/tools/clang-check/CMakeLists.txt
===
--- clang/tools/clang-check/CMakeLists.txt
+++ clang/tools/clang-check/CMakeLists.txt
@@ -19,3 +19,8 @@
   clangStaticAnalyzerFrontend
   clangTooling
   )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+export_executable_symbols_for_plugins(clang-check)
+endif()
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -203,25 +203,6 @@
 return true;
   }
 
-  // Load any requested plugins.
-  for (const std::string  : Clang->getFrontendOpts().Plugins) {
-std::string Error;
-if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), 
))
-  Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
-<< Path << Error;
-  }
-
-  // Check if any of the loaded plugins replaces the main AST action
-  for (const FrontendPluginRegistry::entry  :
-   FrontendPluginRegistry::entries()) {
-std::unique_ptr P(Plugin.instantiate());
-if (P->getActionType() == PluginASTAction::ReplaceAction) {
-  Clang->getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
-  Clang->getFrontendOpts().ActionName = Plugin.getName().str();
-  break;
-}
-  }
-
   // Honor -mllvm.
   //
   // FIXME: Remove this, one day.
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3899,6 +3899,24 @@
   Res.getCodeGenOpts().Argv0 = Argv0;
   Res.getCodeGenOpts().CommandLineArgs = CommandLineArgs;
 
+  // Load any requested plugins.
+  for (const std::string  : Res.getFrontendOpts().Plugins) {
+std::string Error;
+if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), 
))
+  Diags.Report(diag::err_fe_unable_to_load_plugin) << Path << Error;
+  }
+
+  // Check if any of the loaded plugins replaces the main AST action
+  for (const FrontendPluginRegistry::entry  :
+   FrontendPluginRegistry::entries()) {
+std::unique_ptr P(Plugin.instantiate());
+if (P->getActionType() == PluginASTAction::ReplaceAction) {
+  Res.getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
+  Res.getFrontendOpts().ActionName = Plugin.getName().str();
+  break;
+}
+  }
+
   return Success;
 }
 
Index: clang-tools-extra/clangd/tool/CMakeLists.txt
===
--- clang-tools-extra/clangd/tool/CMakeLists.txt
+++ clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -39,3 +39,8 @@
   clangdSupport
   ${CLANGD_XPC_LIBS}
   )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(clangd)
+endif()
\ No newline at end of file
Index: clang-tools-extra/clangd/Compiler.cpp
===
--- clang-tools-extra/clangd/Compiler.cpp
+++ clang-tools-extra/clangd/Compiler.cpp
@@ -9,6 +9,8 @@
 #include "Compiler.h"
 #include "support/Logger.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendPluginRegistry.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/PCHContainerOperations.h"
 #include "llvm/ADT/StringRef.h"


Index: clang/tools/clang-check/CMakeLists.txt
===
--- clang/tools/clang-check/CMakeLists.txt
+++ clang/tools/clang-check/CMakeLists.txt
@@ -19,3 +19,8 @@
   clangStaticAnalyzerFrontend
   clangTooling
   )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+export_executable_symbols_for_plugins(clang-check)
+endif()
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

[PATCH] D91651: [clang] Add a warning (à la gcc) for too small enum bitfields

2020-11-25 Thread Faisal Vali via Phabricator via cfe-commits
faisalv added a comment.

In D91651#2416423 , @thakis wrote:

> Do you have any numbers on false positives / true positives uncovered by this 
> tweak?

That's a great question - and unfortunately not only do I have no hard data to 
support or discourage the addition of such a warning - I don't even know how 
some of those incredible folks (who make data based claims about programming 
smells and needs) gather such data (leave alone making sure the data is a 
representative sample for the "right" kind of programmers) - and would love to 
be shown how to run such studies :)

> In general, warning at use time instead of at declaration time tends to be 
> much better for this rate, and we do this differently than gcc in several 
> instances, because the gcc way has so many false positives that it makes 
> warnings unusable, while warning on use makes the warning useful. So I'd like 
> to see a better justification than "gcc does it" :)

Aah - i did not realize that it was a deliberate decision not to implement such 
a warning at definition time.  My justification (asides from gcc being the 
light for us in dark places, when all other lights go out ;) for implementing a 
warning at definition time probably just stems from an instinctual preference 
for early diagnostics - i suppose there is no one size that fits all here - for 
e.g. some folks prefer run-time (duck-typing) operation checking vs 
compile-time checking, and others who prefer diagnosing fundamental issues with 
template-code when they are first parsed, as opposed to waiting for some 
instantiation - and then there is the entire C++0X concepts vs concepts-lite 
discussion ...

So, since I feel I lack the authority to justify such a warning (asides from my 
ideological propensities) in the face of your valid concerns (either anecdotal 
or fueled by sufficient data) - I would prefer to defer to you and withdraw the 
patch :)  (unless someone else feels they are able to provide justification 
that might resonate with you).

Thanks for chiming in!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91651

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


[PATCH] D91944: OpenMP 5.0 metadirective

2020-11-25 Thread Alok Mishra via Phabricator via cfe-commits
alokmishra.besu added a comment.

I have replied to the comments and will update the code accordingly. Some of 
the codes are intentionally left to be update in 5.1 implementation. Will add 
TODO comments there.
I will revisit the implementation of getBestWhenMatchForContext and also add 
more test cases over the weekend and submit new code by next week.




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:10493
+  "misplaced default clause! Only one default clause is allowed in "
+  "metadirective in the end">;
 } // end of OpenMP category

jdoerfert wrote:
> no `!`. The default clause doesn't need to be in the end either.
OK. Will update accordingly.



Comment at: clang/include/clang/Serialization/ASTBitCodes.h:1952
-  STMT_MS_DEPENDENT_EXISTS,   // MSDependentExistsStmt
-  EXPR_LAMBDA,// LambdaExpr
   STMT_COROUTINE_BODY,

jdoerfert wrote:
> Unrelated.
Only STMT_OMP_META_DIRECTIVE was added. Rest was formatted by git clang-format



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10211
+return;
+  }
+

jdoerfert wrote:
> Can you explain this, this seems odd to me.
Good catch. This was an experimental code for 5.1. Got committed by mistake. 
Will update.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2186
+// parse and get condition expression to pass to the When clause
+parseOMPContextSelectors(Loc, TI);
+

jdoerfert wrote:
> Usually you would check the return value in case we later actually propagate 
> errors while parsing the context selector.
OK. Will update accordingly.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2193
+  Diag(Tok, diag::warn_pragma_expected_colon) << "when clause";
+  return Directive;
+}

jdoerfert wrote:
> If we give up it should be an error, I think. If we issue a warning we just 
> pretend the colon was there afterwards.
OK. Will update accordingly.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2204
+ConsumeAnyToken();
+  }
+  // Parse ')'

jdoerfert wrote:
> We have balanced trackers for this that also deal with the fact that there 
> might be a `)` missing. This code will probably crash.
Come to think of it, in case of a missing ')' this code might end up in an 
infinite loop. Will update accordingly.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2216
+TPA.Revert();
+TargetOMPContext OMPCtx(ASTContext, nullptr, nullptr);
+int BestIdx = getBestWhenMatchForContext(VMIs, OMPCtx);

jdoerfert wrote:
> Add a TODO that `nullptr` should be replaced as per the use in 
> `Sema::ActOnOpenMPCall`.
Will do



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2254
+// Parse ':'
+ConsumeAnyToken();
+  }

jdoerfert wrote:
> If you warn and continue above you need to check for `:` here again.
Will update accordingly.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2264
+  Actions.StartOpenMPDSABlock(DirKind, DirName, Actions.getCurScope(),
+  Loc);
+  int paren = 0;

jdoerfert wrote:
> Should we not go back to the original code handling "directives" instead? 
> This looks like it is copied here.
Unfortunately we cannot go to the original code handling since the original 
code handling assumes that the directive always ends with 
annot_pragma_openmp_end, while here it will always end with ')'.
In specification 5.0, since we are choosing only 1 directive, the body of the 
while block remains the same as the original code. Only the condition of the 
while block changes. In specification 5.1, we will need to generate code for 
dynamic handling and even the body will differ as we might need to generate AST 
node for multiple directives. It is best if we handle this code here for easier 
handling of 5.1 code, than in the original code space.
I will add a TODO comment here.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2317
+  ConsumeAnnotationToken();
+}
+  } else {

jdoerfert wrote:
> Same as below, change the order. Also, the "skipping" part is always the 
> same, put it in a helper function or lambda.
OK



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2324
+ConsumeAnnotationToken();
+  }
+  break;

jdoerfert wrote:
> Move the smaller case first and use an early exit. That will reduce the 
> indention of the larger case by 1.
OK



Comment at: clang/test/OpenMP/metadirective_empty.cpp:1
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda 
-emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics

jdoerfert wrote:
> no -fopenmp-targets please.
OK



Comment at: 

[PATCH] D92041: [clangd] Add hover info for `this` expr

2020-11-25 Thread xndcn via Phabricator via cfe-commits
xndcn updated this revision to Diff 307749.
xndcn added a comment.

Thanks! Update the commit as review comments.


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

https://reviews.llvm.org/D92041

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2019,6 +2019,61 @@
 HI.NamespaceScope = "";
 HI.Definition = "@interface MYObject\n@end";
   }},
+  {
+  R"cpp(// this expr
+  namespace ns {
+// comment
+class Foo {
+  Foo* bar() {
+return [[t^his]];
+  }
+};
+  }
+  )cpp",
+  [](HoverInfo ) {
+HI.Name = "Foo";
+HI.Kind = index::SymbolKind::Class;
+HI.NamespaceScope = "ns::";
+HI.Definition = "class Foo {}";
+HI.Documentation = "comment";
+  }},
+  {
+  R"cpp(// this expr for template class
+  namespace ns {
+template 
+class Foo {
+  Foo* bar() {
+return [[t^his]];
+  }
+};
+  }
+  )cpp",
+  [](HoverInfo ) {
+HI.Name = "Foo";
+HI.Kind = index::SymbolKind::Class;
+HI.NamespaceScope = "ns::";
+HI.Definition = "template  class Foo {}";
+HI.TemplateParameters = {
+{std::string("typename"), std::string("T"), llvm::None}};
+  }},
+  {
+  R"cpp(// this expr for specialization struct
+  namespace ns {
+template  struct Foo {};
+template <>
+struct Foo {
+  Foo* bar() {
+return [[thi^s]];
+  }
+};
+  }
+  )cpp",
+  [](HoverInfo ) {
+HI.Name = "Foo";
+HI.Kind = index::SymbolKind::Struct;
+HI.NamespaceScope = "ns::";
+HI.Definition = "template <> struct Foo {}";
+  }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -628,15 +628,22 @@
   return llvm::StringLiteral("expression");
 }
 
-// Generates hover info for evaluatable expressions.
+// Generates hover info for `this` and evaluatable expressions.
 // FIXME: Support hover for literals (esp user-defined)
-llvm::Optional getHoverContents(const Expr *E, ParsedAST ) {
+llvm::Optional getHoverContents(const Expr *E, ParsedAST ,
+   const SymbolIndex *Index) {
   // There's not much value in hovering over "42" and getting a hover card
   // saying "42 is an int", similar for other literals.
   if (isLiteral(E))
 return llvm::None;
 
   HoverInfo HI;
+  // For `this` expr we currently generate hover with class declaration.
+  if (const CXXThisExpr *CTE = dyn_cast(E)) {
+const NamedDecl *D = CTE->getType()->getPointeeType()->getAsTagDecl();
+HI = getHoverContents(D, Index);
+return HI;
+  }
   // For expressions we currently print the type and the value, iff it is
   // evaluatable.
   if (auto Val = printExprValue(E, AST.getASTContext())) {
@@ -861,7 +868,7 @@
   HI->Value = printExprValue(N, AST.getASTContext());
 maybeAddCalleeArgInfo(N, *HI, AST.getASTContext().getPrintingPolicy());
   } else if (const Expr *E = N->ASTNode.get()) {
-HI = getHoverContents(E, AST);
+HI = getHoverContents(E, AST, Index);
   }
   // FIXME: support hovers for other nodes?
   //  - built-in types
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92080: [Clang] Mutate long-double math builtins into f128 under IEEE-quad

2020-11-25 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

In D92080#2416625 , @craig.topper 
wrote:

> gcc calls the *l version with -mlong-double-128 on x86. Should we match gcc 
> here?

Ah, yes, so this should be PPC-only change.

But I see under x86 `-mlong-double-128`, std functions (`printf/sqrtl/...`) 
can't provide correct results (seems they're just for fp80). Is this expected?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92080

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


[PATCH] D92117: [AIX] Enabling vector types for AIX

2020-11-25 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA updated this revision to Diff 307748.
ZarkoCA added a comment.

Added regex and variable for function attribute


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92117

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aix-altivec.c
  clang/test/CodeGen/aix-vector.c

Index: clang/test/CodeGen/aix-vector.c
===
--- clang/test/CodeGen/aix-vector.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// REQUIRES: powerpc-registered-target
-// RUN: not %clang_cc1 -triple powerpc-unknown-aix  -target-feature +altivec \
-// RUN:   -emit-llvm -o - %s 2>&1 | FileCheck %s
-// RUN: not %clang_cc1 -triple powerpc64-unknown-aix  -target-feature +altivec \
-// RUN:   -emit-llvm -o - %s 2>&1 | FileCheck %s
-
-// CHECK: fatal error: error in backend: vector type is not supported on AIX yet
-vector signed int retVector(vector signed int x) {
-  return x;
-}
Index: clang/test/CodeGen/aix-altivec.c
===
--- /dev/null
+++ clang/test/CodeGen/aix-altivec.c
@@ -0,0 +1,44 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-feature +altivec -target-cpu pwr8 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -target-feature +altivec -target-cpu pwr8 -emit-llvm %s -o - | FileCheck %s
+vector float foo1(vector float x) { return x; }
+// CHECK:  define <4 x float> @foo1(<4 x float> %x) [[ATTR:#[0-9]+]] {
+// CHECK:  entry:
+// CHECK:%x.addr = alloca <4 x float>, align 16
+// CHECK:store <4 x float> %x, <4 x float>* %x.addr, align 16
+// CHECK:%0 = load <4 x float>, <4 x float>* %x.addr, align 16
+// CHECK:ret <4 x float> %0
+// CHECK:  }
+vector double foo2(vector double x) { return x; }
+// CHECK:  define <2 x double> @foo2(<2 x double> %x) [[ATTR]] {
+// CHECK:  entry:
+// CHECK:%x.addr = alloca <2 x double>, align 16
+// CHECK:store <2 x double> %x, <2 x double>* %x.addr, align 16
+// CHECK:%0 = load <2 x double>, <2 x double>* %x.addr, align 16
+// CHECK:ret <2 x double> %0
+// CHECK:  }
+vector int foo3(vector int x) { return x; }
+// CHECK:  define <4 x i32> @foo3(<4 x i32> %x) [[ATTR]] {
+// CHECK:  entry:
+// CHECK:%x.addr = alloca <4 x i32>, align 16
+// CHECK:store <4 x i32> %x, <4 x i32>* %x.addr, align 16
+// CHECK:%0 = load <4 x i32>, <4 x i32>* %x.addr, align 16
+// CHECK:ret <4 x i32> %0
+// CHECK:  }
+vector short int foo4(vector short int x) { return x; }
+// CHECK:  define <8 x i16> @foo4(<8 x i16> %x) [[ATTR]] {
+// CHECK:  entry:
+// CHECK:%x.addr = alloca <8 x i16>, align 16
+// CHECK:store <8 x i16> %x, <8 x i16>* %x.addr, align 16
+// CHECK:%0 = load <8 x i16>, <8 x i16>* %x.addr, align 16
+// CHECK:ret <8 x i16> %0
+// CHECK:  }
+vector char foo5(vector char x) { return x; }
+// CHECK:  define <16 x i8> @foo5(<16 x i8> %x) [[ATTR]] {
+// CHECK:  entry:
+// CHECK:%x.addr = alloca <16 x i8>, align 16
+// CHECK:store <16 x i8> %x, <16 x i8>* %x.addr, align 16
+// CHECK:%0 = load <16 x i8>, <16 x i8>* %x.addr, align 16
+// CHECK:ret <16 x i8> %0
+// CHECK:  }
+
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4514,7 +4514,7 @@
 return ABIArgInfo::getDirect();
 
   if (RetTy->isVectorType())
-llvm::report_fatal_error("vector type is not supported on AIX yet");
+return ABIArgInfo::getDirect();
 
   if (RetTy->isVoidType())
 return ABIArgInfo::getIgnore();
@@ -4533,7 +4533,7 @@
 return ABIArgInfo::getDirect();
 
   if (Ty->isVectorType())
-llvm::report_fatal_error("vector type is not supported on AIX yet");
+return ABIArgInfo::getDirect();
 
   if (isAggregateTypeForABI(Ty)) {
 // Records with non-trivial destructors/copy-constructors should not be
@@ -4558,7 +4558,7 @@
 Ty = CTy->getElementType();
 
   if (Ty->isVectorType())
-llvm::report_fatal_error("vector type is not supported on AIX yet");
+return CharUnits::fromQuantity(16);
 
   // If the structure contains a vector type, the alignment is 16.
   if (isRecordWithSIMDVectorType(getContext(), Ty))
@@ -4573,7 +4573,8 @@
 llvm::report_fatal_error("complex type is not supported on AIX yet");
 
   if (Ty->isVectorType())
-llvm::report_fatal_error("vector type is not supported on AIX yet");
+llvm::report_fatal_error(
+"vector types are not yet supported for variadic functions on AIX");
 
   auto TypeInfo = getContext().getTypeInfoInChars(Ty);
   TypeInfo.Align = getParamTypeAlignment(Ty);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


LLVM buildmaster will be updated and restarted tonight

2020-11-25 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be updated and restarted after 8PM PST today.

Thanks

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


[PATCH] D92148: [clangd] Do not treat line as inactive if skipped range ends at character position 0

2020-11-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added a project: clang.
nridge requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Fixes https://github.com/clangd/clangd/issues/602


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92148

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -623,18 +623,23 @@
   // Code after the preamble.
   // Code inside inactive blocks does not get regular highlightings
   // because it's not part of the AST.
-$InactiveCode[[#ifdef test]]
+  #define $Macro[[test2]]
+$InactiveCode[[#if defined(test)]]
 $InactiveCode[[int Inactive2;]]
+$InactiveCode[[#elif defined(test2)]]
+  int $Variable[[Active1]];
+$InactiveCode[[#else]]
+$InactiveCode[[int Inactive3;]]
 $InactiveCode[[#endif]]
 
   #ifndef $Macro[[test]]
-  int $Variable[[Active1]];
+  int $Variable[[Active2]];
   #endif
 
 $InactiveCode[[#ifdef test]]
-$InactiveCode[[int Inactive3;]]
+$InactiveCode[[int Inactive4;]]
 $InactiveCode[[#else]]
-  int $Variable[[Active2]];
+  int $Variable[[Active3]];
   #endif
 )cpp",
   // Argument to 'sizeof...'
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -234,6 +234,10 @@
   // with line-based diffing.
   assert(R.start.line <= R.end.line);
   for (int Line = R.start.line; Line <= R.end.line; ++Line) {
+// If the end of the inactive range is at the beginning
+// of a line, that line is not inactive.
+if (Line == R.end.line && R.end.character == 0)
+  continue;
 // Copy tokens before the inactive line
 for (; It != NonConflicting.end() && It->R.start.line < Line; ++It)
   WithInactiveLines.push_back(std::move(*It));


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -623,18 +623,23 @@
   // Code after the preamble.
   // Code inside inactive blocks does not get regular highlightings
   // because it's not part of the AST.
-$InactiveCode[[#ifdef test]]
+  #define $Macro[[test2]]
+$InactiveCode[[#if defined(test)]]
 $InactiveCode[[int Inactive2;]]
+$InactiveCode[[#elif defined(test2)]]
+  int $Variable[[Active1]];
+$InactiveCode[[#else]]
+$InactiveCode[[int Inactive3;]]
 $InactiveCode[[#endif]]
 
   #ifndef $Macro[[test]]
-  int $Variable[[Active1]];
+  int $Variable[[Active2]];
   #endif
 
 $InactiveCode[[#ifdef test]]
-$InactiveCode[[int Inactive3;]]
+$InactiveCode[[int Inactive4;]]
 $InactiveCode[[#else]]
-  int $Variable[[Active2]];
+  int $Variable[[Active3]];
   #endif
 )cpp",
   // Argument to 'sizeof...'
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -234,6 +234,10 @@
   // with line-based diffing.
   assert(R.start.line <= R.end.line);
   for (int Line = R.start.line; Line <= R.end.line; ++Line) {
+// If the end of the inactive range is at the beginning
+// of a line, that line is not inactive.
+if (Line == R.end.line && R.end.character == 0)
+  continue;
 // Copy tokens before the inactive line
 for (; It != NonConflicting.end() && It->R.start.line < Line; ++It)
   WithInactiveLines.push_back(std::move(*It));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92000: [clangd] Collect main file refs by default

2020-11-25 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc6cb47b640ff: [clangd] Collect main file refs by default 
(authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92000

Files:
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp


Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -188,8 +188,10 @@
   size_t CacheHits = 0;
   MemoryShardStorage MSS(Storage, CacheHits);
   OverlayCDB CDB(/*Base=*/nullptr);
-  BackgroundIndex Idx(FS, CDB, [&](llvm::StringRef) { return  },
-  /*Opts=*/{});
+  BackgroundIndex::Options Opts;
+  Opts.CollectMainFileRefs = true;
+  BackgroundIndex Idx(
+  FS, CDB, [&](llvm::StringRef) { return  }, Opts);
 
   tooling::CompileCommand Cmd;
   Cmd.Filename = testPath("root/A.cc");
@@ -201,7 +203,7 @@
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(1U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),
+   AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(),
  Not(Defined()), NumReferences(0U;
 
@@ -214,7 +216,7 @@
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(5U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),
+   AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(), Defined(),
  NumReferences(1U;
 
@@ -238,7 +240,8 @@
   FS.Files[testPath("root/A.cc")] =
   "#include \"A.h\"\nstatic void main_sym() { (void)header_sym; }";
 
-  // Check the behaviour with CollectMainFileRefs = false (the default).
+  // Check the behaviour with CollectMainFileRefs = false (the default
+  // at the SymbolCollector level).
   {
 llvm::StringMap Storage;
 size_t CacheHits = 0;
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -494,7 +494,7 @@
 "collect-main-file-refs",
 cat(Misc),
 desc("Store references to main-file-only symbols in the index"),
-init(false),
+init(ClangdServer::Options().CollectMainFileRefs),
 };
 
 #if CLANGD_ENABLE_REMOTE
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -106,7 +106,7 @@
 bool BackgroundIndex = false;
 
 /// Store refs to main-file symbols in the index.
-bool CollectMainFileRefs = false;
+bool CollectMainFileRefs = true;
 
 /// If set, use this index to augment code completion results.
 SymbolIndex *StaticIndex = nullptr;


Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -188,8 +188,10 @@
   size_t CacheHits = 0;
   MemoryShardStorage MSS(Storage, CacheHits);
   OverlayCDB CDB(/*Base=*/nullptr);
-  BackgroundIndex Idx(FS, CDB, [&](llvm::StringRef) { return  },
-  /*Opts=*/{});
+  BackgroundIndex::Options Opts;
+  Opts.CollectMainFileRefs = true;
+  BackgroundIndex Idx(
+  FS, CDB, [&](llvm::StringRef) { return  }, Opts);
 
   tooling::CompileCommand Cmd;
   Cmd.Filename = testPath("root/A.cc");
@@ -201,7 +203,7 @@
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(1U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),
+   AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(),
  Not(Defined()), NumReferences(0U;
 
@@ -214,7 +216,7 @@
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(5U)),

[clang-tools-extra] c6cb47b - [clangd] Collect main file refs by default

2020-11-25 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2020-11-25T20:33:57-05:00
New Revision: c6cb47b640ffafda113581c488a73fb62b6ea38a

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

LOG: [clangd] Collect main file refs by default

This is needed for call hierarchy to be able to find callers of
main-file-only functions.

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index b6a1bd757894..35ba4686cc9a 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -106,7 +106,7 @@ class ClangdServer {
 bool BackgroundIndex = false;
 
 /// Store refs to main-file symbols in the index.
-bool CollectMainFileRefs = false;
+bool CollectMainFileRefs = true;
 
 /// If set, use this index to augment code completion results.
 SymbolIndex *StaticIndex = nullptr;

diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 5c89e423cde4..d0eab3650750 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -494,7 +494,7 @@ opt CollectMainFileRefs{
 "collect-main-file-refs",
 cat(Misc),
 desc("Store references to main-file-only symbols in the index"),
-init(false),
+init(ClangdServer::Options().CollectMainFileRefs),
 };
 
 #if CLANGD_ENABLE_REMOTE

diff  --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp 
b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
index b25d3fde0002..f4a9b2fa2d13 100644
--- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -188,8 +188,10 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
   size_t CacheHits = 0;
   MemoryShardStorage MSS(Storage, CacheHits);
   OverlayCDB CDB(/*Base=*/nullptr);
-  BackgroundIndex Idx(FS, CDB, [&](llvm::StringRef) { return  },
-  /*Opts=*/{});
+  BackgroundIndex::Options Opts;
+  Opts.CollectMainFileRefs = true;
+  BackgroundIndex Idx(
+  FS, CDB, [&](llvm::StringRef) { return  }, Opts);
 
   tooling::CompileCommand Cmd;
   Cmd.Filename = testPath("root/A.cc");
@@ -201,7 +203,7 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(1U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),
+   AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(),
  Not(Defined()), NumReferences(0U;
 
@@ -214,7 +216,7 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(5U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),
+   AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(), Defined(),
  NumReferences(1U;
 
@@ -238,7 +240,8 @@ TEST_F(BackgroundIndexTest, MainFileRefs) {
   FS.Files[testPath("root/A.cc")] =
   "#include \"A.h\"\nstatic void main_sym() { (void)header_sym; }";
 
-  // Check the behaviour with CollectMainFileRefs = false (the default).
+  // Check the behaviour with CollectMainFileRefs = false (the default
+  // at the SymbolCollector level).
   {
 llvm::StringMap Storage;
 size_t CacheHits = 0;



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


[PATCH] D92000: [clangd] Collect main file refs by default

2020-11-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 307730.
nridge added a comment.

Address review comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92000

Files:
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp


Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -188,8 +188,10 @@
   size_t CacheHits = 0;
   MemoryShardStorage MSS(Storage, CacheHits);
   OverlayCDB CDB(/*Base=*/nullptr);
-  BackgroundIndex Idx(FS, CDB, [&](llvm::StringRef) { return  },
-  /*Opts=*/{});
+  BackgroundIndex::Options Opts;
+  Opts.CollectMainFileRefs = true;
+  BackgroundIndex Idx(
+  FS, CDB, [&](llvm::StringRef) { return  }, Opts);
 
   tooling::CompileCommand Cmd;
   Cmd.Filename = testPath("root/A.cc");
@@ -201,7 +203,7 @@
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(1U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),
+   AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(),
  Not(Defined()), NumReferences(0U;
 
@@ -214,7 +216,7 @@
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(5U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),
+   AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(), Defined(),
  NumReferences(1U;
 
@@ -238,7 +240,8 @@
   FS.Files[testPath("root/A.cc")] =
   "#include \"A.h\"\nstatic void main_sym() { (void)header_sym; }";
 
-  // Check the behaviour with CollectMainFileRefs = false (the default).
+  // Check the behaviour with CollectMainFileRefs = false (the default
+  // at the SymbolCollector level).
   {
 llvm::StringMap Storage;
 size_t CacheHits = 0;
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -493,7 +493,7 @@
 "collect-main-file-refs",
 cat(Misc),
 desc("Store references to main-file-only symbols in the index"),
-init(false),
+init(ClangdServer::Options().CollectMainFileRefs),
 };
 
 #if CLANGD_ENABLE_REMOTE
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -113,7 +113,7 @@
 bool BackgroundIndex = false;
 
 /// Store refs to main-file symbols in the index.
-bool CollectMainFileRefs = false;
+bool CollectMainFileRefs = true;
 
 /// If set, use this index to augment code completion results.
 SymbolIndex *StaticIndex = nullptr;


Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -188,8 +188,10 @@
   size_t CacheHits = 0;
   MemoryShardStorage MSS(Storage, CacheHits);
   OverlayCDB CDB(/*Base=*/nullptr);
-  BackgroundIndex Idx(FS, CDB, [&](llvm::StringRef) { return  },
-  /*Opts=*/{});
+  BackgroundIndex::Options Opts;
+  Opts.CollectMainFileRefs = true;
+  BackgroundIndex Idx(
+  FS, CDB, [&](llvm::StringRef) { return  }, Opts);
 
   tooling::CompileCommand Cmd;
   Cmd.Filename = testPath("root/A.cc");
@@ -201,7 +203,7 @@
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(1U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),
+   AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(),
  Not(Defined()), NumReferences(0U;
 
@@ -214,7 +216,7 @@
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(5U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),

[clang] 7c327db - Part of C++ DR 39: a class member lookup is not ambiguous if it finds the

2020-11-25 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-11-25T17:03:11-08:00
New Revision: 7c327db3ef73d771bc022d0723672fc356dc9017

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

LOG: Part of C++ DR 39: a class member lookup is not ambiguous if it finds the
same type in multiple base classes.

Not even if the type is introduced by distinct declarations (for
example, two typedef declarations, or a typedef and a class definition).

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaLookup.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/temp/temp.res/temp.local/p3.cpp
clang/test/SemaCXX/member-name-lookup.cpp
clang/test/SemaTemplate/dependent-base-classes.cpp
clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp
clang/test/SemaTemplate/temp.cpp
clang/test/SemaTemplate/typename-specifier-4.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2e479307ce22..f2b2b1d3ab6f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8640,6 +8640,8 @@ def err_ambiguous_member_multiple_subobjects : Error<
 def err_ambiguous_member_multiple_subobject_types : Error<
   "member %0 found in multiple base classes of 
diff erent types">;
 def note_ambiguous_member_found : Note<"member found by ambiguous name 
lookup">;
+def note_ambiguous_member_type_found : Note<
+  "member type %0 found by ambiguous name lookup">;
 def err_ambiguous_reference : Error<"reference to %0 is ambiguous">;
 def note_ambiguous_candidate : Note<"candidate found by name lookup is %q0">;
 def err_ambiguous_tag_hiding : Error<"a type named %0 is hidden by a "

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 9a1312af42eb..16dd8f510596 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -2228,11 +2228,10 @@ bool Sema::LookupQualifiedName(LookupResult , 
DeclContext *LookupCtx,
 
   // Determine whether two sets of members contain the same members, as
   // required by C++ [class.member.lookup]p6.
-  auto HasSameDeclarations = [IDNS,
-  TemplateNameLookup](DeclContextLookupResult A,
-  DeclContextLookupResult B) {
+  auto HasSameDeclarations = [&](DeclContextLookupResult A,
+ DeclContextLookupResult B) {
 using Iterator = DeclContextLookupResult::iterator;
-using Result = const Decl *;
+using Result = const void *;
 
 auto Next = [&](Iterator , Iterator End) -> Result {
   while (It != End) {
@@ -2252,14 +2251,15 @@ bool Sema::LookupQualifiedName(LookupResult , 
DeclContext *LookupCtx,
   if (auto *TD = getAsTemplateNameDecl(ND))
 ND = TD;
 
-// FIXME: Per C++ [class.member.lookup]p3:
-//   type declarations (including injected-class-names are replaced by 
the
-//   types they designate
-// So two 
diff erent typedef declarations with the same name from two
-// 
diff erent base classes declaring the same type do not introduce an
-// ambiguity.
+// C++ [class.member.lookup]p3:
+//   type declarations (including injected-class-names) are replaced by
+//   the types they designate
+if (const TypeDecl *TD = dyn_cast(ND->getUnderlyingDecl())) {
+  QualType T = Context.getTypeDeclType(TD);
+  return T.getCanonicalType().getAsOpaquePtr();
+}
 
-return cast(ND->getUnderlyingDecl()->getCanonicalDecl());
+return ND->getUnderlyingDecl()->getCanonicalDecl();
   }
   return nullptr;
 };
@@ -2509,13 +2509,23 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult 
) {
   << Name << LookupRange;
 
 CXXBasePaths *Paths = Result.getBasePaths();
-std::set DeclsPrinted;
+std::set DeclsPrinted;
 for (CXXBasePaths::paths_iterator Path = Paths->begin(),
   PathEnd = Paths->end();
  Path != PathEnd; ++Path) {
-  Decl *D = Path->Decls.front();
-  if (DeclsPrinted.insert(D).second)
-Diag(D->getLocation(), diag::note_ambiguous_member_found);
+  const NamedDecl *D = Path->Decls.front();
+  if (!D->isInIdentifierNamespace(Result.getIdentifierNamespace()))
+continue;
+  if (DeclsPrinted.insert(D).second) {
+if (const auto *TD = dyn_cast(D->getUnderlyingDecl()))
+  Diag(D->getLocation(), diag::note_ambiguous_member_type_found)
+  << TD->getUnderlyingType();
+else if (const auto *TD = dyn_cast(D->getUnderlyingDecl()))
+  Diag(D->getLocation(), 

[PATCH] D92141: Fix noderef for AddrOf on MemberExpr

2020-11-25 Thread Jann Horn via Phabricator via cfe-commits
thejh marked an inline comment as done.
thejh added inline comments.



Comment at: clang/test/Frontend/noderef.c:75-76
+  // enclosing AddrOf.
+  p = >a;// ok
+  p = &(*s).a;  // ok
+  p2 = >a;   // expected-warning{{casting to dereferenceable pointer 
removes 'noderef' attribute}}

leonardchan wrote:
> These two can probably be removed since we have
> 
> ```
>   p = >a;
>   p = &(*s).b;
> ```
> 
> above. 
Good point, I've removed them now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92141

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


[PATCH] D92141: Fix noderef for AddrOf on MemberExpr

2020-11-25 Thread Jann Horn via Phabricator via cfe-commits
thejh updated this revision to Diff 307728.
thejh added a comment.

Removed duplicate tests as suggested by leonardchan


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92141

Files:
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/Frontend/noderef.c


Index: clang/test/Frontend/noderef.c
===
--- clang/test/Frontend/noderef.c
+++ clang/test/Frontend/noderef.c
@@ -70,6 +70,12 @@
   x = sizeof(s->a + (s->b)); // ok
   x = sizeof(int[++s->a]);   // expected-warning{{dereferencing s; was 
declared with a 'noderef' type}}
 
+  // Struct member access should carry NoDeref type information through to an
+  // enclosing AddrOf.
+  p2 = >a;   // expected-warning{{casting to dereferenceable pointer 
removes 'noderef' attribute}}
+  p2 = &(*s).a; // expected-warning{{casting to dereferenceable pointer 
removes 'noderef' attribute}}
+  x = *>a;   // expected-warning{{dereferencing expression marked as 
'noderef'}}
+
   // Nested struct access
   struct S2 NODEREF *s2_noderef;// expected-note 5 {{s2_noderef declared 
here}}
   p = s2_noderef->a;  // ok since result is an array in a struct
@@ -113,7 +119,7 @@
 
   p = s2_arr[1]->a;
   p = s2_arr[1]->b; // expected-warning{{dereferencing expression marked as 
'noderef'}}
-  int **bptr = _arr[1]->b;
+  int *NODEREF *bptr = _arr[1]->b;
 
   x = s2->s2->a;// expected-warning{{dereferencing expression marked 
as 'noderef'}}
   x = s2_noderef->a[1]; // expected-warning{{dereferencing s2_noderef; was 
declared with a 'noderef' type}}
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -1810,6 +1810,14 @@
 Qualifiers Combined = BaseQuals + MemberQuals;
 if (Combined != MemberQuals)
   MemberType = Context.getQualifiedType(MemberType, Combined);
+
+// Pick up NoDeref from the base in case we end up using AddrOf on the
+// result. E.g. the expression
+// >pointerMember
+// should be a noderef pointer again.
+if (BaseType->hasAttr(attr::NoDeref))
+  MemberType =
+  Context.getAttributedType(attr::NoDeref, MemberType, MemberType);
   }
 
   auto *CurMethod = dyn_cast(CurContext);


Index: clang/test/Frontend/noderef.c
===
--- clang/test/Frontend/noderef.c
+++ clang/test/Frontend/noderef.c
@@ -70,6 +70,12 @@
   x = sizeof(s->a + (s->b)); // ok
   x = sizeof(int[++s->a]);   // expected-warning{{dereferencing s; was declared with a 'noderef' type}}
 
+  // Struct member access should carry NoDeref type information through to an
+  // enclosing AddrOf.
+  p2 = >a;   // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}}
+  p2 = &(*s).a; // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}}
+  x = *>a;   // expected-warning{{dereferencing expression marked as 'noderef'}}
+
   // Nested struct access
   struct S2 NODEREF *s2_noderef;// expected-note 5 {{s2_noderef declared here}}
   p = s2_noderef->a;  // ok since result is an array in a struct
@@ -113,7 +119,7 @@
 
   p = s2_arr[1]->a;
   p = s2_arr[1]->b; // expected-warning{{dereferencing expression marked as 'noderef'}}
-  int **bptr = _arr[1]->b;
+  int *NODEREF *bptr = _arr[1]->b;
 
   x = s2->s2->a;// expected-warning{{dereferencing expression marked as 'noderef'}}
   x = s2_noderef->a[1]; // expected-warning{{dereferencing s2_noderef; was declared with a 'noderef' type}}
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -1810,6 +1810,14 @@
 Qualifiers Combined = BaseQuals + MemberQuals;
 if (Combined != MemberQuals)
   MemberType = Context.getQualifiedType(MemberType, Combined);
+
+// Pick up NoDeref from the base in case we end up using AddrOf on the
+// result. E.g. the expression
+// >pointerMember
+// should be a noderef pointer again.
+if (BaseType->hasAttr(attr::NoDeref))
+  MemberType =
+  Context.getAttributedType(attr::NoDeref, MemberType, MemberType);
   }
 
   auto *CurMethod = dyn_cast(CurContext);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92141: Fix noderef for AddrOf on MemberExpr

2020-11-25 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan accepted this revision.
leonardchan added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks




Comment at: clang/test/Frontend/noderef.c:75-76
+  // enclosing AddrOf.
+  p = >a;// ok
+  p = &(*s).a;  // ok
+  p2 = >a;   // expected-warning{{casting to dereferenceable pointer 
removes 'noderef' attribute}}

These two can probably be removed since we have

```
  p = >a;
  p = &(*s).b;
```

above. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92141

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


[PATCH] D92140: Fix noderef for array member of deref expr

2020-11-25 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan accepted this revision.
leonardchan added a comment.
This revision is now accepted and ready to land.

Thanks for catching this. LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92140

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


[clang] 3fb0879 - Refactor and simplify class scope name lookup.

2020-11-25 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-11-25T16:25:33-08:00
New Revision: 3fb0879867d7039cb61ffb6287ac17ac949adfa9

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

LOG: Refactor and simplify class scope name lookup.

This is partly in preparation for an upcoming change that can change the
order in which DeclContext lookup results are presented.

In passing, fix some obvious errors where name lookup's notion of a
"static member function" missed static member function templates, and
where its notion of "same set of declarations" was confused by the same
declarations appearing in a different order.

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/CXXInheritance.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
clang/test/SemaCXX/lookup-member.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index efc683c6c05d..ef8f54913ed9 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -611,12 +611,10 @@ static StyleKind findStyleKind(
 
 // If this method has the same name as any base method, this is likely
 // necessary even if it's not an override. e.g. CRTP.
-auto FindHidden = [&](const CXXBaseSpecifier *S, clang::CXXBasePath ) {
-  return CXXRecordDecl::FindOrdinaryMember(S, P, Decl->getDeclName());
-};
-CXXBasePaths UnusedPaths;
-if (Decl->getParent()->lookupInBases(FindHidden, UnusedPaths))
-  return SK_Invalid;
+for (const CXXBaseSpecifier  : Decl->getParent()->bases())
+  if (const auto *RD = Base.getType()->getAsCXXRecordDecl())
+if (RD->hasMemberName(Decl->getDeclName()))
+  return SK_Invalid;
 
 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprMethod])
   return SK_ConstexprMethod;

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 36f42c06a300..568eeb614a76 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1622,58 +1622,6 @@ class CXXRecordDecl : public RecordDecl {
CXXBasePath ,
const CXXRecordDecl *BaseRecord);
 
-  /// Base-class lookup callback that determines whether there exists
-  /// a tag with the given name.
-  ///
-  /// This callback can be used with \c lookupInBases() to find tag members
-  /// of the given name within a C++ class hierarchy.
-  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
-CXXBasePath , DeclarationName Name);
-
-  /// Base-class lookup callback that determines whether there exists
-  /// a member with the given name.
-  ///
-  /// This callback can be used with \c lookupInBases() to find members
-  /// of the given name within a C++ class hierarchy.
-  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
- CXXBasePath , DeclarationName Name);
-
-  /// Base-class lookup callback that determines whether there exists
-  /// a member with the given name.
-  ///
-  /// This callback can be used with \c lookupInBases() to find members
-  /// of the given name within a C++ class hierarchy, including dependent
-  /// classes.
-  static bool
-  FindOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier,
-   CXXBasePath , DeclarationName 
Name);
-
-  /// Base-class lookup callback that determines whether there exists
-  /// an OpenMP declare reduction member with the given name.
-  ///
-  /// This callback can be used with \c lookupInBases() to find members
-  /// of the given name within a C++ class hierarchy.
-  static bool FindOMPReductionMember(const CXXBaseSpecifier *Specifier,
- CXXBasePath , DeclarationName Name);
-
-  /// Base-class lookup callback that determines whether there exists
-  /// an OpenMP declare mapper member with the given name.
-  ///
-  /// This callback can be used with \c lookupInBases() to find members
-  /// of the given name within a C++ class hierarchy.
-  static bool FindOMPMapperMember(const CXXBaseSpecifier *Specifier,
-  CXXBasePath , DeclarationName Name);
-
-  /// Base-class lookup callback that determines whether there exists
-  /// a member with the given name that can be used in a nested-name-specifier.
-  ///
-  /// This callback can be used 

[PATCH] D92141: Fix noderef for AddrOf on MemberExpr

2020-11-25 Thread Jann Horn via Phabricator via cfe-commits
thejh added a comment.

(I marked this as depending on D92140  because 
if you apply this patch to the current HEAD directly, the tests will break.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92141

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


[PATCH] D92141: Fix noderef for AddrOf on MemberExpr

2020-11-25 Thread Jann Horn via Phabricator via cfe-commits
thejh created this revision.
thejh added reviewers: leonardchan, aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
thejh requested review of this revision.

As part of this change, one existing test case has to be adjusted
because it accidentally stripped the NoDeref attribute without
getting caught.

Depends on D92140 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92141

Files:
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/Frontend/noderef.c


Index: clang/test/Frontend/noderef.c
===
--- clang/test/Frontend/noderef.c
+++ clang/test/Frontend/noderef.c
@@ -70,6 +70,14 @@
   x = sizeof(s->a + (s->b)); // ok
   x = sizeof(int[++s->a]);   // expected-warning{{dereferencing s; was 
declared with a 'noderef' type}}
 
+  // Struct member access should carry NoDeref type information through to an
+  // enclosing AddrOf.
+  p = >a;// ok
+  p = &(*s).a;  // ok
+  p2 = >a;   // expected-warning{{casting to dereferenceable pointer 
removes 'noderef' attribute}}
+  p2 = &(*s).a; // expected-warning{{casting to dereferenceable pointer 
removes 'noderef' attribute}}
+  x = *>a;   // expected-warning{{dereferencing expression marked as 
'noderef'}}
+
   // Nested struct access
   struct S2 NODEREF *s2_noderef;// expected-note 5 {{s2_noderef declared 
here}}
   p = s2_noderef->a;  // ok since result is an array in a struct
@@ -113,7 +121,7 @@
 
   p = s2_arr[1]->a;
   p = s2_arr[1]->b; // expected-warning{{dereferencing expression marked as 
'noderef'}}
-  int **bptr = _arr[1]->b;
+  int *NODEREF *bptr = _arr[1]->b;
 
   x = s2->s2->a;// expected-warning{{dereferencing expression marked 
as 'noderef'}}
   x = s2_noderef->a[1]; // expected-warning{{dereferencing s2_noderef; was 
declared with a 'noderef' type}}
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -1810,6 +1810,14 @@
 Qualifiers Combined = BaseQuals + MemberQuals;
 if (Combined != MemberQuals)
   MemberType = Context.getQualifiedType(MemberType, Combined);
+
+// Pick up NoDeref from the base in case we end up using AddrOf on the
+// result. E.g. the expression
+// >pointerMember
+// should be a noderef pointer again.
+if (BaseType->hasAttr(attr::NoDeref))
+  MemberType =
+  Context.getAttributedType(attr::NoDeref, MemberType, MemberType);
   }
 
   auto *CurMethod = dyn_cast(CurContext);


Index: clang/test/Frontend/noderef.c
===
--- clang/test/Frontend/noderef.c
+++ clang/test/Frontend/noderef.c
@@ -70,6 +70,14 @@
   x = sizeof(s->a + (s->b)); // ok
   x = sizeof(int[++s->a]);   // expected-warning{{dereferencing s; was declared with a 'noderef' type}}
 
+  // Struct member access should carry NoDeref type information through to an
+  // enclosing AddrOf.
+  p = >a;// ok
+  p = &(*s).a;  // ok
+  p2 = >a;   // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}}
+  p2 = &(*s).a; // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}}
+  x = *>a;   // expected-warning{{dereferencing expression marked as 'noderef'}}
+
   // Nested struct access
   struct S2 NODEREF *s2_noderef;// expected-note 5 {{s2_noderef declared here}}
   p = s2_noderef->a;  // ok since result is an array in a struct
@@ -113,7 +121,7 @@
 
   p = s2_arr[1]->a;
   p = s2_arr[1]->b; // expected-warning{{dereferencing expression marked as 'noderef'}}
-  int **bptr = _arr[1]->b;
+  int *NODEREF *bptr = _arr[1]->b;
 
   x = s2->s2->a;// expected-warning{{dereferencing expression marked as 'noderef'}}
   x = s2_noderef->a[1]; // expected-warning{{dereferencing s2_noderef; was declared with a 'noderef' type}}
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -1810,6 +1810,14 @@
 Qualifiers Combined = BaseQuals + MemberQuals;
 if (Combined != MemberQuals)
   MemberType = Context.getQualifiedType(MemberType, Combined);
+
+// Pick up NoDeref from the base in case we end up using AddrOf on the
+// result. E.g. the expression
+// >pointerMember
+// should be a noderef pointer again.
+if (BaseType->hasAttr(attr::NoDeref))
+  MemberType =
+  Context.getAttributedType(attr::NoDeref, MemberType, MemberType);
   }
 
   auto *CurMethod = dyn_cast(CurContext);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92140: Fix noderef for array member of deref expr

2020-11-25 Thread Jann Horn via Phabricator via cfe-commits
thejh created this revision.
thejh added reviewers: leonardchan, aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
thejh requested review of this revision.

Given an __attribute__((noderef)) pointer "p" to the struct

  struct s { int a[2]; };

ensure that the following expressions are treated the same way by the
noderef logic:

  p->a
  (*p).a

Until now, the first expression would be treated correctly (nothing is
added to PossibleDerefs because CheckMemberAccessOfNoDeref() bails out
on array members), but the second expression would incorrectly warn
because "*p" creates a PossibleDerefs entry.

Handle this case the same way as for the AddrOf operator.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92140

Files:
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/Frontend/noderef.c


Index: clang/test/Frontend/noderef.c
===
--- clang/test/Frontend/noderef.c
+++ clang/test/Frontend/noderef.c
@@ -73,6 +73,7 @@
   // Nested struct access
   struct S2 NODEREF *s2_noderef;// expected-note 5 {{s2_noderef declared 
here}}
   p = s2_noderef->a;  // ok since result is an array in a struct
+  p = (*s2_noderef).a; // ok since result is an array in a struct
   p = s2_noderef->a2; // ok
   p = s2_noderef->b;  // expected-warning{{dereferencing s2_noderef; was 
declared with a 'noderef' type}}
   p = s2_noderef->b2; // expected-warning{{dereferencing s2_noderef; was 
declared with a 'noderef' type}}
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -1739,12 +1739,23 @@
 
   QualType ResultTy = E->getType();
 
-  // Do not warn on member accesses to arrays since this returns an array
-  // lvalue and does not actually dereference memory.
-  if (isa(ResultTy))
-return;
-
-  if (E->isArrow()) {
+  // Member accesses have four cases:
+  // 1: non-array member via "->": dereferences
+  // 2: non-array member via ".": nothing interesting happens
+  // 3: array member access via "->": nothing interesting happens
+  //(this returns an array lvalue and does not actually dereference memory)
+  // 4: array member access via ".": *adds* a layer of indirection
+  if (ResultTy->isArrayType()) {
+if (!E->isArrow()) {
+  // This might be something like:
+  // (*structPtr).arrayMember
+  // which behaves roughly like:
+  // &(*structPtr).pointerMember
+  // in that the apparent dereference in the base expression does not
+  // actually happen.
+  CheckAddressOfNoDeref(E->getBase());
+}
+  } else if (E->isArrow()) {
 if (const auto *Ptr = dyn_cast(
 E->getBase()->getType().getDesugaredType(Context))) {
   if (Ptr->getPointeeType()->hasAttr(attr::NoDeref))


Index: clang/test/Frontend/noderef.c
===
--- clang/test/Frontend/noderef.c
+++ clang/test/Frontend/noderef.c
@@ -73,6 +73,7 @@
   // Nested struct access
   struct S2 NODEREF *s2_noderef;// expected-note 5 {{s2_noderef declared here}}
   p = s2_noderef->a;  // ok since result is an array in a struct
+  p = (*s2_noderef).a; // ok since result is an array in a struct
   p = s2_noderef->a2; // ok
   p = s2_noderef->b;  // expected-warning{{dereferencing s2_noderef; was declared with a 'noderef' type}}
   p = s2_noderef->b2; // expected-warning{{dereferencing s2_noderef; was declared with a 'noderef' type}}
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -1739,12 +1739,23 @@
 
   QualType ResultTy = E->getType();
 
-  // Do not warn on member accesses to arrays since this returns an array
-  // lvalue and does not actually dereference memory.
-  if (isa(ResultTy))
-return;
-
-  if (E->isArrow()) {
+  // Member accesses have four cases:
+  // 1: non-array member via "->": dereferences
+  // 2: non-array member via ".": nothing interesting happens
+  // 3: array member access via "->": nothing interesting happens
+  //(this returns an array lvalue and does not actually dereference memory)
+  // 4: array member access via ".": *adds* a layer of indirection
+  if (ResultTy->isArrayType()) {
+if (!E->isArrow()) {
+  // This might be something like:
+  // (*structPtr).arrayMember
+  // which behaves roughly like:
+  // &(*structPtr).pointerMember
+  // in that the apparent dereference in the base expression does not
+  // actually happen.
+  CheckAddressOfNoDeref(E->getBase());
+}
+  } else if (E->isArrow()) {
 if (const auto *Ptr = dyn_cast(
 E->getBase()->getType().getDesugaredType(Context))) {
   if (Ptr->getPointeeType()->hasAttr(attr::NoDeref))

[PATCH] D91311: Add new 'preferred_name' attribute.

2020-11-25 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D91311#2416940 , @ldionne wrote:

> LGTM from the libc++ point of view. The CI is passing -- those failures are 
> flaky modules tests that we need to fix.

Perhaps we need to specify `-fmodules-validate-system-headers` in the test so 
Clang doesn't assume that system headers are unchanged?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91311

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


[PATCH] D92133: [clangd] Cache .clang-tidy files again.

2020-11-25 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clangd/TidyProvider.cpp:34
+  llvm::Optional
+  get(const ThreadsafeFS ,
+  std::chrono::steady_clock::time_point FreshTime) const {

To save a copy, could this not return a const pointer to whats stored in 
`Value`, nullptr if `Value` is empty.
In `DotClangTidyTree`, `OptionStack` could then store pointers instead of 
values.
Considering the size of ClangTidyOptions (312 bytes in x64 with libstdc++) this 
is definitely a worthwhile saving.

One slight issue is I'm not sure how nicely this approach would play with the 
mutex.



Comment at: clang-tools-extra/clangd/TidyProvider.cpp:61-62
+  const ThreadsafeFS 
+  std::string RelPath;
+  std::chrono::steady_clock::duration MaxStaleness;
 

Should these both be const?



Comment at: clang-tools-extra/clangd/TidyProvider.cpp:76
+namespace path = llvm::sys::path;
+assert(llvm::sys::path::is_absolute(AbsPath));
 

Given path has been brought into scope in the line above can probably remove 
excess qualifiers.



Comment at: clang-tools-extra/clangd/TidyProvider.cpp:84-87
+  // Avoid weird non-substring cases like phantom "." components.
+  // In practice, Component is a substring for all "normal" ancestors.
+  if (I->end() < Parent.begin() && I->end() > Parent.end())
+continue;

How does this work with `..` components. Or does clangd ensure all absolute 
paths have those removed?



Comment at: clang-tools-extra/clangd/TidyProvider.cpp:113
+OptionStack.push_back(std::move(*Config));
+if (!OptionStack.back().InheritParentConfig)
+  break;

This will result in incorrect behaviour if a config specifies 
`InheritParentConfig` as `false`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92133

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


[PATCH] D91895: [Clang] improve -Wimplicit-fallthrough GCC compat

2020-11-25 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

In D91895#2417170 , @kees wrote:

> I think this should warn too. While this won't turn into a "missing break" 
> error, there's no way to know (from looking at code) what the _intent_ is 
> here.

Hear, hear. +1 on everything @kees said but especially this.
(Also: 

 "The job of the compiler-diagnostic-developer is to create some separation 
between the space of inputs that the compiler considers “clearly X” and the 
space of inputs that the compiler considers “clearly Y.” Essentially, we create 
an error-correcting code by deliberately increasing the edit distance between 
pairs of inequivalent C++ programs — deliberately increasing the number of 
keystrokes the programmer would have to screw up in order to transform a 
working (and warning-free) C++ program into an inequivalent broken (yet 
warning-free) C++ program.")


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91895

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


[PATCH] D91980: [OpenMP] Add initial support for `omp [begin/end] assumes`

2020-11-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:1569-1593
+int idx = -1;
+if (Tok.isAnyIdentifier()) {
+  II = Tok.getIdentifierInfo();
+  llvm::StringSwitch SS(II->getName());
+  for (const AssumptionClauseMappingInfo  : AssumptionClauseMappings) 
{
+if (ACMI.StartsWith)
+  SS.StartsWith(ACMI.Identifier, ++idx);

jdoerfert wrote:
> ABataev wrote:
> > jdoerfert wrote:
> > > ABataev wrote:
> > > > ABataev wrote:
> > > > > `Idx`
> > > > Better to outline it into function/lambda
> > > Which part? Assuming you mean the 9 line conditional above, I'm not 
> > > convinced. Even if I do outline it, 4 lines will have to stay here and I 
> > > don't see any reuse.
> > The part that searches over the table.
> > The part that searches over the table.
> 
> I don't follow. Where is a search? The part that builds a string switch? line 
> 1569 - 1579?
Yes.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3218
+  DeclContext *DC = DeclContexts.pop_back_val();
+  for (auto *SubDC : DC->decls()) {
+if (auto *CTD = dyn_cast(SubDC)) {

I would also add a check that the decl is valid here before checking it and 
applying the attributes.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3225
+}
+if (isa(SubDC) || isa(SubDC)) {
+  DeclContexts.push_back(cast(SubDC));

```
if (auto *SubCtx = dyn_cast(SubDC)) {
  DeclContexts.push_back(cast(SubCtx));
 continue;
}
```
?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3210
+
+SmallVector DeclContexts;
+DeclContexts.push_back(CurContext);

jdoerfert wrote:
> ABataev wrote:
> > jdoerfert wrote:
> > > ABataev wrote:
> > > > What are you trying to do here? Scan all the decls in the current 
> > > > context and mark all the functions with the assumption attributes?
> > > Pretty much, yeah. Find all function declarations and add the attribute. 
> > > I'll add a comment.
> > Does it mean that for this code
> > ```
> > void foo();
> >  #pragma omp assume ...
> > void bar();
> >  #pragma omp end assume
> > ```
> > `foo()` must have the same assumptions like `bar()`? It looks to me, 
> > currently we'll end up with the same attributes for both functions. But I'm 
> > not sure that this is correct to mark the function outside of the `assumes` 
> > region with the same attributes just like the function inside.
> Your example mixes the global `omp assumes` with the scoped `begin/end omp 
> assumes`. The former has the effect to be added to prior declarations, the 
> latter does not have this effect. This is how it is supposed to work:
> ```
> void foo();  // no assumption
>  #pragma omp begin assumes ext_XYZ
> void bar();  // XYZ assumption
>  #pragma omp end assumes
> ```
> ```
> void foo();  // XYZ assumption
>  #pragma omp assumes ext_XYZ
> void bar();  // XYZ assumption
> ```
> 
> 
> 
Ah, I see. `omp assumes` looks weird. :( It may lead to conflicts
PS. What about lambdas? Could add a test that lambdas get annotations too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91980

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


[PATCH] D91980: [OpenMP] Add initial support for `omp [begin/end] assumes`

2020-11-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D91980#2417129 , @ABataev wrote:

> In D91980#2417049 , @jdoerfert wrote:
>
>> In D91980#2416950 , @ABataev wrote:
>>
>>> Why don't yo want to try to implement the scheme similar to the declare 
>>> target?
>>
>> Because it is not clear that the standard even says that right now. Also, 
>> what is the user expectation here.
>> The scheme now is conservative but consistent. I'd prefer to use something 
>> like that first before we clarify edge cases.
>
> I don't think that it will affect the implementation significantly. Still, 
> OpenMP standard must preserve visibility etc. rules of C/C++, so the changes 
> should not be critical (I think).

We can add more support later, once it is clear how that will look like. As the 
person that wrote the OpenMP standard section, I'm trying to tell you it is not 
clear what the expected behavior is supposed to be. Not applying assumes is 
*always* correct. Applying them for some cases that is not easy to argue about, 
is at least confusing. If you feel we should add assumes in more cases, I'm 
happy to bring up the discussion in the OpenMP standards committee and look at 
a follow up patch.




Comment at: clang/lib/Parse/ParseOpenMP.cpp:1569-1593
+int idx = -1;
+if (Tok.isAnyIdentifier()) {
+  II = Tok.getIdentifierInfo();
+  llvm::StringSwitch SS(II->getName());
+  for (const AssumptionClauseMappingInfo  : AssumptionClauseMappings) 
{
+if (ACMI.StartsWith)
+  SS.StartsWith(ACMI.Identifier, ++idx);

ABataev wrote:
> jdoerfert wrote:
> > ABataev wrote:
> > > ABataev wrote:
> > > > `Idx`
> > > Better to outline it into function/lambda
> > Which part? Assuming you mean the 9 line conditional above, I'm not 
> > convinced. Even if I do outline it, 4 lines will have to stay here and I 
> > don't see any reuse.
> The part that searches over the table.
> The part that searches over the table.

I don't follow. Where is a search? The part that builds a string switch? line 
1569 - 1579?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3210
+
+SmallVector DeclContexts;
+DeclContexts.push_back(CurContext);

ABataev wrote:
> jdoerfert wrote:
> > ABataev wrote:
> > > What are you trying to do here? Scan all the decls in the current context 
> > > and mark all the functions with the assumption attributes?
> > Pretty much, yeah. Find all function declarations and add the attribute. 
> > I'll add a comment.
> Does it mean that for this code
> ```
> void foo();
>  #pragma omp assume ...
> void bar();
>  #pragma omp end assume
> ```
> `foo()` must have the same assumptions like `bar()`? It looks to me, 
> currently we'll end up with the same attributes for both functions. But I'm 
> not sure that this is correct to mark the function outside of the `assumes` 
> region with the same attributes just like the function inside.
Your example mixes the global `omp assumes` with the scoped `begin/end omp 
assumes`. The former has the effect to be added to prior declarations, the 
latter does not have this effect. This is how it is supposed to work:
```
void foo();  // no assumption
 #pragma omp begin assumes ext_XYZ
void bar();  // XYZ assumption
 #pragma omp end assumes
```
```
void foo();  // XYZ assumption
 #pragma omp assumes ext_XYZ
void bar();  // XYZ assumption
```





Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91980

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


[PATCH] D92136: [clang] Enhanced test for --relocatable-pch, and corresponding fixes for Windows

2020-11-25 Thread Sylvain Audi via Phabricator via cfe-commits
saudi created this revision.
saudi added reviewers: rnk, thakis, rsmith, AndyG.
saudi added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith, ormris, 
hiraditya.
Herald added a project: LLVM.
saudi requested review of this revision.

The test now moves the header files between the pch creation and its use.
This change caused failures under Windows:

- The `-isysroot` path matching was failing when given variations of casing or 
separators (`/` vs `\`)
- clang `-verify` checks "`// expected-[note/warning/...]@[file]:[line] ...`" 
would fail when `file` is an absolute path, since the `:` character was 
interpreted as the delimiter between `[file]` and `[line]`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92136

Files:
  clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/PCH/reloc-windows.c
  clang/test/PCH/reloc.c
  llvm/include/llvm/Support/Path.h
  llvm/lib/Support/Path.cpp
  llvm/unittests/Support/Path.cpp

Index: llvm/unittests/Support/Path.cpp
===
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -1474,6 +1474,21 @@
   EXPECT_EQ("c", Path2);
 }
 
+TEST(Support, StartsWith) {
+  EXPECT_FALSE(starts_with("/foo/bar", "/bar", path::Style::posix));
+  EXPECT_FALSE(starts_with("/foo/bar", "/bar", path::Style::windows));
+  EXPECT_TRUE(starts_with("/foo/bar", "/fo", path::Style::posix));
+  EXPECT_TRUE(starts_with("/foo/bar", "/fo", path::Style::windows));
+  EXPECT_FALSE(starts_with("/foo/bar", "/Fo", path::Style::posix));
+  EXPECT_TRUE(starts_with("/foo/bar", "/Fo", path::Style::windows));
+  EXPECT_TRUE(starts_with("/foo/bar", "/foo", path::Style::posix));
+  EXPECT_TRUE(starts_with("/foo/bar", "/foo", path::Style::windows));
+  EXPECT_TRUE(starts_with("/foo/bar", "/foo/", path::Style::posix));
+  EXPECT_TRUE(starts_with("/foo/bar", "/foo/", path::Style::windows));
+  EXPECT_FALSE(starts_with("A:\\Foo\\Bar", "a:\\foo/bar", path::Style::posix));
+  EXPECT_TRUE(starts_with("A:\\Foo\\Bar", "a:\\foo/bar", path::Style::windows));
+}
+
 TEST(Support, ReplacePathPrefix) {
   SmallString<64> Path1("/foo");
   SmallString<64> Path2("/old/foo");
Index: llvm/lib/Support/Path.cpp
===
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -494,8 +494,7 @@
   path.append(ext.begin(), ext.end());
 }
 
-static bool starts_with(StringRef Path, StringRef Prefix,
-Style style = Style::native) {
+bool starts_with(StringRef Path, StringRef Prefix, Style style) {
   // Windows prefix matching : case and separator insensitive
   if (real_style(style) == Style::windows) {
 if (Path.size() < Prefix.size())
Index: llvm/include/llvm/Support/Path.h
===
--- llvm/include/llvm/Support/Path.h
+++ llvm/include/llvm/Support/Path.h
@@ -148,6 +148,29 @@
 void replace_extension(SmallVectorImpl , const Twine ,
Style style = Style::native);
 
+
+/// Test for matching path with a prefix.
+///
+/// @code
+///   /foo, /old, /new => /foo
+///   /old, /old, /new => /new
+///   /old, /old/, /new => /old
+///   /old/foo, /old, /new => /new/foo
+///   /old/foo, /old/, /new => /new/foo
+///   /old/foo, /old/, /new/ => /new/foo
+///   /oldfoo, /old, /new => /oldfoo
+///   /foo, , /new => /new/foo
+///   /foo, , new => new/foo
+///   /old/foo, /old,  => /foo
+/// @endcode
+///
+/// @param Path The path to check for the prefix
+/// @param Prefix The path prefix to match in \a Path.
+/// @param style The style used to match the prefix. Exact match using
+/// Posix style, case/separator insensitive match for Windows style.
+/// @result true if \a Path begins with Prefix, false otherwise
+bool starts_with(StringRef Path, StringRef Prefix, Style style = Style::native);
+
 /// Replace matching path prefix with another path.
 ///
 /// @code
Index: clang/test/PCH/reloc.c
===
--- clang/test/PCH/reloc.c
+++ clang/test/PCH/reloc.c
@@ -1,8 +1,18 @@
-// RUN: %clang -target x86_64-apple-darwin10 --relocatable-pch -o %t \
-// RUN:   -isysroot %S/Inputs/libroot %S/Inputs/libroot/usr/include/reloc.h
-// RUN: %clang -target x86_64-apple-darwin10 -fsyntax-only \
-// RUN:   -include-pch %t -isysroot %S/Inputs/libroot %s -Xclang -verify
-// RUN: not %clang -target x86_64-apple-darwin10 -include-pch %t %s
+// RUN: rm -rf %t.dir
+// RUN: mkdir -p %t.dir/Inputs
+// RUN: cp -R %S/Inputs/libroot %t.dir/Inputs/libroot
+// RUN: sed -e "s|TMPDIR|%/t.dir|g" %s > %t.dir/reloc.c
+
+// For this test, we rename the -isysroot folder between the pch file creation and its use.
+// We create the pch using a relative path to avoid introducing absolute file paths in it.
+// Renaming the folder leaves the .h files mtime unchanged, so it doesn't break the 

[PATCH] D92117: [AIX] Enabling vector types for AIX

2020-11-25 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L accepted this revision.
Xiangling_L added a comment.
This revision is now accepted and ready to land.

Just a minor suggestion: Maybe `Enabling return and argument vector types for 
AIX` is more accurate. Otherwise, LGTM.




Comment at: clang/test/CodeGen/aix-altivec.c:5
+vector float foo1(vector float x) { return x; }
+// CHECK:  define <4 x float> @foo1(<4 x float> %x) #0 {
+// CHECK:  entry:

minor:
you can use `[[ATTR:#[0-9]+]]` to replace `#0`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92117

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


[PATCH] D91895: [Clang] improve -Wimplicit-fallthrough GCC compat

2020-11-25 Thread Kees Cook via Phabricator via cfe-commits
kees added a comment.

The kernel's [[ 
https://www.kernel.org/doc/html/latest/process/deprecated.html#implicit-switch-case-fall-through

| stance ]] on switch statements reads: |
|



  All switch/case blocks must end in one of:
  
  break;
  fallthrough;
  continue;
  goto ;
  return [expression];

And we've had multiple real bugs now of the "missing break before default 
return" style:

https://git.kernel.org/linus/291ddeb621e4a9f1ced8302a777fbd7fbda058c6

So, from the kernel's perspective, please don't make `-Wimplicit-fallthrough` 
more permissive -- we're finding real bugs. :)

And to speak to another example in the thread:

  // drivers/hid/usbhid/hid-core.c
   490   case -ESHUTDOWN:  /* unplug */ 

 
   491 unplug = 1; 
   492   case -EILSEQ:   /* protocol error or unplug */ // 
-Wimplicit-fallthrough...how?!  

   
   493   case -EPROTO:   /* protocol error or unplug */ 

 
   494   case -ECONNRESET: /* unlink */ 

 
   495   case -ENOENT:  

 
   496   case -EPIPE:/* report not available */ 

 
   497 break;

I think this should warn too. While this won't turn into a "missing break" 
error, there's no way to know (from looking at code) what the _intent_ is here. 
Should it have done "return?" Why is "break" assumed to be safe here, etc?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91895

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


[PATCH] D92133: [clangd] Cache .clang-tidy files again.

2020-11-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: njames93, kbobyrev.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added a project: clang.
sammccall requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

This cache went away in 73fdd998701cce3aa6c4d8d2a73ab97351a0313b 


This time, the cache is periodically validated against disk, so config
is still mostly "live".

The per-file cache reuses FileCache, but the tree-of-file-caches is
duplicated from ConfigProvider. .clangd, .clang-tidy, .clang-format, and
compile_commands.json all have this pattern, we should extract it at some point.
TODO for now though.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92133

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

Index: clang-tools-extra/clangd/TidyProvider.cpp
===
--- clang-tools-extra/clangd/TidyProvider.cpp
+++ clang-tools-extra/clangd/TidyProvider.cpp
@@ -8,7 +8,9 @@
 
 #include "TidyProvider.h"
 #include "Config.h"
+#include "support/FileCache.h"
 #include "support/Logger.h"
+#include "support/ThreadsafeFS.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
@@ -19,53 +21,115 @@
 
 namespace clang {
 namespace clangd {
+namespace {
 
-static void mergeCheckList(llvm::Optional ,
-   llvm::StringRef List) {
-  if (List.empty())
-return;
-  if (!Checks || Checks->empty()) {
-Checks.emplace(List);
-return;
+// Access to config from a .clang-tidy file, caching IO and parsing.
+class DotClangTidyCache : private FileCache {
+  mutable llvm::Optional Value;
+
+public:
+  DotClangTidyCache(PathRef Path) : FileCache(Path) {}
+
+  llvm::Optional
+  get(const ThreadsafeFS ,
+  std::chrono::steady_clock::time_point FreshTime) const {
+llvm::Optional Result;
+read(
+TFS, FreshTime,
+[this](llvm::Optional Data) {
+  Value.reset();
+  if (Data && !Data->empty()) {
+if (auto Parsed = tidy::parseConfiguration(*Data))
+  Value = std::move(*Parsed);
+else
+  elog("Error parsing clang-tidy configuration in {0}: {1}", path(),
+   Parsed.getError().message());
+  }
+},
+[&]() { Result = Value; });
+return Result;
   }
-  *Checks = llvm::join_items(",", *Checks, List);
-}
+};
 
-static llvm::Optional
-tryReadConfigFile(llvm::vfs::FileSystem *FS, llvm::StringRef Directory) {
-  assert(!Directory.empty());
-  // We guaranteed that child directories of Directory exist, so this assert
-  // should hopefully never fail.
-  assert(FS->exists(Directory));
+// Access to combined config from .clang-tidy files governing a source file.
+// Each config file is cached and the caches are shared for affected sources.
+//
+// FIXME: largely duplicates config::Provider::fromAncestorRelativeYAMLFiles.
+// Potentially useful for compile_commands.json too. Extract?
+class DotClangTidyTree {
+  const ThreadsafeFS 
+  std::string RelPath;
+  std::chrono::steady_clock::duration MaxStaleness;
 
-  llvm::SmallString<128> ConfigFile(Directory);
-  llvm::sys::path::append(ConfigFile, ".clang-tidy");
+  mutable std::mutex Mu;
+  // Keys are the ancestor directory, not the actual config path within it.
+  // We only insert into this map, so pointers to values are stable forever.
+  // Mutex guards the map itself, not the values (which are threadsafe).
+  mutable llvm::StringMap Cache;
 
-  llvm::ErrorOr FileStatus = FS->status(ConfigFile);
+public:
+  DotClangTidyTree(const ThreadsafeFS )
+  : FS(FS), RelPath(".clang-tidy"), MaxStaleness(std::chrono::seconds(5)) {}
 
-  if (!FileStatus || !FileStatus->isRegularFile())
-return llvm::None;
+  void apply(tidy::ClangTidyOptions , PathRef AbsPath) {
+namespace path = llvm::sys::path;
+assert(llvm::sys::path::is_absolute(AbsPath));
 
-  llvm::ErrorOr> Text =
-  FS->getBufferForFile(ConfigFile);
-  if (std::error_code EC = Text.getError()) {
-elog("Can't read '{0}': {1}", ConfigFile, EC.message());
-return llvm::None;
+// Compute absolute paths to all ancestors (substrings of P.Path).
+llvm::StringRef Parent = path::parent_path(AbsPath);
+llvm::SmallVector Ancestors;
+for (auto I = path::begin(Parent, path::Style::posix),
+  E = path::end(Parent);
+ I != E; ++I) {
+  // Avoid weird non-substring cases like phantom "." components.
+  // In practice, Component is a substring for all "normal" ancestors.
+  if (I->end() < Parent.begin() && I->end() > Parent.end())
+continue;
+  Ancestors.emplace_back(Parent.begin(), I->end() - Parent.begin());
+}
+// Ensure corresponding cache entries exist in the map.
+llvm::SmallVector Caches;
+{
+  std::lock_guard Lock(Mu);
+  

[PATCH] D91980: [OpenMP] Add initial support for `omp [begin/end] assumes`

2020-11-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D91980#2417049 , @jdoerfert wrote:

> In D91980#2416950 , @ABataev wrote:
>
>> Why don't yo want to try to implement the scheme similar to the declare 
>> target?
>
> Because it is not clear that the standard even says that right now. Also, 
> what is the user expectation here.
> The scheme now is conservative but consistent. I'd prefer to use something 
> like that first before we clarify edge cases.

I don't think that it will affect the implementation significantly. Still, 
OpenMP standard must preserve visibility etc. rules of C/C++, so the changes 
should not be critical (I think).




Comment at: clang/lib/Parse/ParseOpenMP.cpp:1531
+
+  auto SkipBraces = [&](llvm::StringRef Spelling, bool IssueNote) {
+BalancedDelimiterTracker T(*this, tok::l_paren,

jdoerfert wrote:
> ABataev wrote:
> > I think you will need just capture `this` by value here
> I've never done that. Could you explain why? Is it just an "optimization"? A 
> simple test doesn't really show a difference https://godbolt.org/z/bfr47f
Yes, this is just the optimization.It is not for the current implementation but 
for possible future changes. There is no difference for `this` but might be 
difference if you'll need to capture something else.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:1550-1555
+  {"absent", false, true, false},
+  {"contains", false, true, false},
+  {"holds", false, false, true},
+  {"no_openmp", false, false, false},
+  {"no_openmp_routines", false, false, false},
+  {"no_parallelism", false, false, false},

jdoerfert wrote:
> ABataev wrote:
> > Why not express it as clauses?
> Various reasons actually:
> 
> - It is a lot of boilerplate code, if we would auto-generate them from the 
> tablegen definition the situation might be different.
> - There seems to be no immediate benefit.
> - We want to be in-sync with the generic assumption handling not develop two 
> systems for the same thing.
> 
Just it is always to have and to maintain just one design rather than 2 or 
more. But it is up to you.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:1569-1593
+int idx = -1;
+if (Tok.isAnyIdentifier()) {
+  II = Tok.getIdentifierInfo();
+  llvm::StringSwitch SS(II->getName());
+  for (const AssumptionClauseMappingInfo  : AssumptionClauseMappings) 
{
+if (ACMI.StartsWith)
+  SS.StartsWith(ACMI.Identifier, ++idx);

jdoerfert wrote:
> ABataev wrote:
> > ABataev wrote:
> > > `Idx`
> > Better to outline it into function/lambda
> Which part? Assuming you mean the 9 line conditional above, I'm not 
> convinced. Even if I do outline it, 4 lines will have to stay here and I 
> don't see any reuse.
The part that searches over the table.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3210
+
+SmallVector DeclContexts;
+DeclContexts.push_back(CurContext);

jdoerfert wrote:
> ABataev wrote:
> > What are you trying to do here? Scan all the decls in the current context 
> > and mark all the functions with the assumption attributes?
> Pretty much, yeah. Find all function declarations and add the attribute. I'll 
> add a comment.
Does it mean that for this code
```
void foo();
 #pragma omp assume ...
void bar();
 #pragma omp end assume
```
`foo()` must have the same assumptions like `bar()`? It looks to me, currently 
we'll end up with the same attributes for both functions. But I'm not sure that 
this is correct to mark the function outside of the `assumes` region with the 
same attributes just like the function inside.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91980

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


[PATCH] D91980: [OpenMP] Add initial support for `omp [begin/end] assumes`

2020-11-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D91980#2416950 , @ABataev wrote:

> Why don't yo want to try to implement the scheme similar to the declare 
> target?

Because it is not clear that the standard even says that right now. Even if, as 
you noted, what is the user expectation here.
The scheme now is conservative but consistent. I'd prefer to use something like 
that first before we clarify edge cases.




Comment at: clang/lib/Parse/ParseOpenMP.cpp:1531
+
+  auto SkipBraces = [&](llvm::StringRef Spelling, bool IssueNote) {
+BalancedDelimiterTracker T(*this, tok::l_paren,

ABataev wrote:
> I think you will need just capture `this` by value here
I've never done that. Could you explain why? Is it just an "optimization"? A 
simple test doesn't really show a difference https://godbolt.org/z/bfr47f



Comment at: clang/lib/Parse/ParseOpenMP.cpp:1550-1555
+  {"absent", false, true, false},
+  {"contains", false, true, false},
+  {"holds", false, false, true},
+  {"no_openmp", false, false, false},
+  {"no_openmp_routines", false, false, false},
+  {"no_parallelism", false, false, false},

ABataev wrote:
> Why not express it as clauses?
Various reasons actually:

- It is a lot of boilerplate code, if we would auto-generate them from the 
tablegen definition the situation might be different.
- There seems to be no immediate benefit.
- We want to be in-sync with the generic assumption handling not develop two 
systems for the same thing.




Comment at: clang/lib/Parse/ParseOpenMP.cpp:1569-1593
+int idx = -1;
+if (Tok.isAnyIdentifier()) {
+  II = Tok.getIdentifierInfo();
+  llvm::StringSwitch SS(II->getName());
+  for (const AssumptionClauseMappingInfo  : AssumptionClauseMappings) 
{
+if (ACMI.StartsWith)
+  SS.StartsWith(ACMI.Identifier, ++idx);

ABataev wrote:
> ABataev wrote:
> > `Idx`
> Better to outline it into function/lambda
Which part? Assuming you mean the 9 line conditional above, I'm not convinced. 
Even if I do outline it, 4 lines will have to stay here and I don't see any 
reuse.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3210
+
+SmallVector DeclContexts;
+DeclContexts.push_back(CurContext);

ABataev wrote:
> What are you trying to do here? Scan all the decls in the current context and 
> mark all the functions with the assumption attributes?
Pretty much, yeah. Find all function declarations and add the attribute. I'll 
add a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91980

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


[PATCH] D91980: [OpenMP] Add initial support for `omp [begin/end] assumes`

2020-11-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 307697.
jdoerfert marked 8 inline comments as done.
jdoerfert added a comment.

Addressed comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91980

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/assumes_codegen.cpp
  clang/test/OpenMP/assumes_include_nvptx.cpp
  clang/test/OpenMP/assumes_messages.c
  clang/test/OpenMP/assumes_print.cpp
  clang/test/OpenMP/assumes_template_print.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -1590,6 +1590,9 @@
 VersionedClause
   ];
 }
+def OMP_Assumes : Directive<"assumes"> {}
+def OMP_BeginAssumes : Directive<"begin assumes"> {}
+def OMP_EndAssumes : Directive<"end assumes"> {}
 def OMP_BeginDeclareVariant : Directive<"begin declare variant"> {}
 def OMP_EndDeclareVariant : Directive<"end declare variant"> {}
 def OMP_ParallelWorkshare : Directive<"parallel workshare"> {
Index: clang/test/OpenMP/assumes_template_print.cpp
===
--- /dev/null
+++ clang/test/OpenMP/assumes_template_print.cpp
@@ -0,0 +1,91 @@
+// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+// expected-no-diagnostics
+
+// It is unclear if we want to annotate the template instantiations, e.g., S::foo, or not in the two
+// situations shown below. Since it is always fair to drop assumptions, we do that for now.
+
+#ifndef HEADER
+#define HEADER
+
+template 
+struct S {
+  int a;
+// CHECK: template  struct S {
+// CHECK: void foo() __attribute__((assume("global_assumption"))) {
+  void foo() {
+#pragma omp parallel
+{}
+  }
+};
+
+// CHECK: template<> struct S {
+// CHECK: void foo() __attribute__((assume("global_assumption"))) {
+
+#pragma omp begin assumes no_openmp
+// CHECK: void S_with_assumes_no_call() __attribute__((assume("no_openmp"))) __attribute__((assume("global_assumption"))) {
+void S_with_assumes_no_call() {
+  S s;
+  s.a = 0;
+}
+// CHECK: void S_with_assumes_call() __attribute__((assume("no_openmp"))) __attribute__((assume("global_assumption"))) {
+void S_with_assumes_call() {
+  S s;
+  s.a = 0;
+  // If this is executed we have UB!
+  s.foo();
+}
+#pragma omp end assumes
+
+// CHECK: void S_without_assumes() __attribute__((assume("global_assumption"))) {
+void S_without_assumes() {
+  S s;
+  s.foo();
+}
+
+#pragma omp assumes ext_global_assumption
+
+// Same as the struct S above but the order in which we instantiate P is different, first outside of an assumes.
+template 
+struct P {
+// CHECK: template  struct P {
+// CHECK: void foo() __attribute__((assume("global_assumption"))) {
+  int a;
+  void foo() {
+#pragma omp parallel
+{}
+  }
+};
+
+// TODO: Avoid the duplication here:
+
+// CHECK: template<> struct P {
+// CHECK: void foo() __attribute__((assume("global_assumption"))) __attribute__((assume("global_assumption"))) {
+
+// CHECK: void P_without_assumes() __attribute__((assume("global_assumption"))) {
+void P_without_assumes() {
+  P p;
+  p.foo();
+}
+
+#pragma omp begin assumes no_openmp
+// CHECK: void P_with_assumes_no_call() __attribute__((assume("no_openmp"))) __attribute__((assume("global_assumption"))) {
+void P_with_assumes_no_call() {
+  P p;
+  p.a = 0;
+}
+// CHECK: void P_with_assumes_call() __attribute__((assume("no_openmp"))) __attribute__((assume("global_assumption"))) {
+void P_with_assumes_call() {
+  P p;
+  p.a = 0;
+  // If this is executed we have UB!
+  p.foo();
+}
+#pragma omp end assumes
+
+#endif
Index: clang/test/OpenMP/assumes_print.cpp
===
--- /dev/null
+++ clang/test/OpenMP/assumes_print.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 

[PATCH] D91261: [OPENMP]Do not use OMP_MAP_TARGET_PARAM for data movement directives.

2020-11-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 307694.
ABataev added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91261

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_map_pointer_array_subscript_codegen.cpp
  clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  clang/test/OpenMP/target_data_use_device_ptr_if_codegen.cpp
  clang/test/OpenMP/target_enter_data_codegen.cpp
  clang/test/OpenMP/target_enter_data_depend_codegen.cpp
  clang/test/OpenMP/target_exit_data_codegen.cpp
  clang/test/OpenMP/target_exit_data_depend_codegen.cpp
  clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
  clang/test/OpenMP/target_update_codegen.cpp
  clang/test/OpenMP/target_update_depend_codegen.cpp

Index: clang/test/OpenMP/target_update_depend_codegen.cpp
===
--- clang/test/OpenMP/target_update_depend_codegen.cpp
+++ clang/test/OpenMP/target_update_depend_codegen.cpp
@@ -30,15 +30,15 @@
 double gc[100];
 
 // CK1: [[SIZE00:@.+]] = {{.+}}constant [1 x i64] [i64 800]
-// CK1: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 34]
+// CK1: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 2]
 
 // CK1: [[SIZE02:@.+]] = {{.+}}constant [1 x i64] [i64 4]
-// CK1: [[MTYPE02:@.+]] = {{.+}}constant [1 x i64] [i64 33]
+// CK1: [[MTYPE02:@.+]] = {{.+}}constant [1 x i64] [i64 1]
 
-// CK1: [[MTYPE03:@.+]] = {{.+}}constant [1 x i64] [i64 34]
+// CK1: [[MTYPE03:@.+]] = {{.+}}constant [1 x i64] [i64 2]
 
 // CK1: [[SIZE04:@.+]] = {{.+}}constant [2 x i64] [i64 sdiv exact (i64 sub (i64 ptrtoint (double** getelementptr (double*, double** getelementptr inbounds (%struct.ST, %struct.ST* @gb, i32 0, i32 1), i32 1) to i64), i64 ptrtoint (double** getelementptr inbounds (%struct.ST, %struct.ST* @gb, i32 0, i32 1) to i64)), i64 ptrtoint (i8* getelementptr (i8, i8* null, i32 1) to i64)), i64 24]
-// CK1: [[MTYPE04:@.+]] = {{.+}}constant [2 x i64] [i64 32, i64 281474976710673]
+// CK1: [[MTYPE04:@.+]] = {{.+}}constant [2 x i64] [i64 0, i64 281474976710673]
 
 // CK1-LABEL: _Z3fooi
 void foo(int arg) {
Index: clang/test/OpenMP/target_update_codegen.cpp
===
--- clang/test/OpenMP/target_update_codegen.cpp
+++ clang/test/OpenMP/target_update_codegen.cpp
@@ -36,15 +36,15 @@
 // CK1-64: [[KMP_PRIVATES_T]] = type { [1 x i8*], [1 x i8*], [1 x i64] }
 
 // CK1: [[SIZE00:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 800]
-// CK1: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 34]
+// CK1: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 2]
 
 // CK1: [[SIZE02:@.+]] = {{.+}}constant [1 x i[[sz]]] [i[[sz]] 4]
-// CK1: [[MTYPE02:@.+]] = {{.+}}constant [1 x i64] [i64 33]
+// CK1: [[MTYPE02:@.+]] = {{.+}}constant [1 x i64] [i64 1]
 
-// CK1: [[MTYPE03:@.+]] = {{.+}}constant [1 x i64] [i64 34]
+// CK1: [[MTYPE03:@.+]] = {{.+}}constant [1 x i64] [i64 2]
 
 // CK1: [[SIZE04:@.+]] = {{.+}}constant [2 x i64] [i64 sdiv exact (i64 sub (i64 ptrtoint (double** getelementptr (double*, double** getelementptr inbounds (%struct.ST, %struct.ST* @gb, i32 0, i32 1), i32 1) to i64), i64 ptrtoint (double** getelementptr inbounds (%struct.ST, %struct.ST* @gb, i32 0, i32 1) to i64)), i64 ptrtoint (i8* getelementptr (i8, i8* null, i32 1) to i64)), i64 24]
-// CK1: [[MTYPE04:@.+]] = {{.+}}constant [2 x i64] [i64 32, i64 281474976710673]
+// CK1: [[MTYPE04:@.+]] = {{.+}}constant [2 x i64] [i64 0, i64 281474976710673]
 
 // CK1-LABEL: _Z3fooi
 void foo(int arg) {
@@ -205,7 +205,7 @@
   }
 };
 
-// CK2: [[MTYPE00:@.+]] = {{.+}}constant [2 x i64] [i64 32, i64 281474976710674]
+// CK2: [[MTYPE00:@.+]] = {{.+}}constant [2 x i64] [i64 0, i64 281474976710674]
 
 // CK2-LABEL: _Z3bari
 int bar(int arg){
@@ -342,7 +342,7 @@
 #ifdef CK5
 
 // CK5: [[SIZE00:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
-// CK5: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 33]
+// CK5: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 1]
 
 // CK5-LABEL: lvalue
 void lvalue(int *B, int l, int e) {
@@ -384,7 +384,7 @@
 #ifdef CK6
 
 // CK6: [[SIZE00:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
-// CK6: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 33]
+// CK6: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 1]
 
 // CK6-LABEL: lvalue
 void lvalue(int *B, int l, int e) {
@@ -431,7 +431,7 @@
 #ifdef CK7
 
 // CK7: [[SIZE00:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
-// CK7: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 33]
+// CK7: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 1]
 
 // CK7-LABEL: lvalue
 void lvalue(int *B, int l, int e) {
@@ -481,7 +481,7 @@
 
 #ifdef CK8
 // CK8: [[SIZE00:@.+]] = {{.+}}constant [2 x i[[sz:64|32]]] [i{{64|32}} 

[PATCH] D87702: [Frontend] Add pragma align natural and sort out pragma pack stack effect

2020-11-25 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L updated this revision to Diff 307685.
Xiangling_L added a comment.

Update the logic to tell if two AlignPackInfo are equal;


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

https://reviews.llvm.org/D87702

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Driver/aix-pragma-pack.c
  clang/test/Layout/aix-double-struct-member.cpp
  clang/test/Layout/aix-power-natural-interaction.cpp
  clang/test/PCH/aix-pragma-pack.c
  clang/test/Sema/aix-pragma-pack-and-align.c

Index: clang/test/Sema/aix-pragma-pack-and-align.c
===
--- /dev/null
+++ clang/test/Sema/aix-pragma-pack-and-align.c
@@ -0,0 +1,231 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -faix-pragma-pack -verify -fsyntax-only -x c++ %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -faix-pragma-pack -verify -fsyntax-only -x c++ %s | \
+// RUN:   FileCheck %s
+
+namespace test1 {
+#pragma align(natural)
+#pragma pack(4)
+#pragma pack(2)
+struct A {
+  int i;
+  double d;
+};
+
+int a = sizeof(A);
+#pragma pack()
+#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 4}}
+#pragma pack(pop)
+#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
+struct B {
+  int i;
+  double d;
+};
+#pragma align(reset)
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test1::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=2, preferredalign=2,
+// CHECK-NEXT:|  nvsize=12, nvalign=2, preferrednvalign=2]
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test1::B
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  8 |   double d
+// CHECK-NEXT:| [sizeof=16, dsize=16, align=4, preferredalign=8,
+// CHECK-NEXT:|  nvsize=16, nvalign=4, preferrednvalign=8]
+
+} // namespace test1
+
+namespace test2 {
+#pragma align(natural)
+#pragma pack(2)
+struct A {
+  int i;
+  double d;
+};
+
+int a = sizeof(A);
+#pragma align(reset)
+
+struct B {
+  int i;
+  double d;
+};
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test2::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=2, preferredalign=2,
+// CHECK-NEXT:|  nvsize=12, nvalign=2, preferrednvalign=2]
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test2::B
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=12, nvalign=4, preferrednvalign=4]
+
+} // namespace test2
+
+namespace test3 {
+#pragma pack(2)
+#pragma align(natural)
+struct A {
+  double d;
+};
+#pragma align(reset)
+#pragma pack(pop)
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test3::A
+// CHECK-NEXT:  0 |   double d
+// CHECK-NEXT:| [sizeof=8, dsize=8, align=4, preferredalign=8,
+// CHECK-NEXT:|  nvsize=8, nvalign=4, preferrednvalign=8]
+
+} // namespace test3
+
+namespace test4 {
+#pragma pack(2)
+#pragma align(natural)
+#pragma pack(pop)
+
+struct A {
+  int i;
+  double d;
+} a;
+#pragma align(reset)
+#pragma pack(pop)
+
+int i = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test4::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  8 |   double d
+// CHECK-NEXT:| [sizeof=16, dsize=16, align=4, preferredalign=8,
+// CHECK-NEXT:|  nvsize=16, nvalign=4, preferrednvalign=8]
+
+} // namespace test4
+
+namespace test5 {
+#pragma align(power)
+#pragma align(natural)
+#pragma pack(2)
+#pragma align(reset)
+struct A {
+  int i;
+  double d;
+};
+#pragma align(reset)
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test5::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=4, preferredalign=4,
+// CHECK-NEXT:| 

[clang-tools-extra] cbf336a - [clangd] Track deprecation of 'member' semantic token type in LSP.

2020-11-25 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-11-25T21:31:46+01:00
New Revision: cbf336ad76cd619495b213e8364acaccb7a7c0d6

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

LOG: [clangd] Track deprecation of 'member' semantic token type in LSP.

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 1a78e7a8c0da..44d74f387dd1 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -556,12 +556,11 @@ llvm::StringRef toSemanticTokenType(HighlightingKind 
Kind) {
   case HighlightingKind::Function:
 return "function";
   case HighlightingKind::Method:
-return "member";
+return "method";
   case HighlightingKind::StaticMethod:
-// FIXME: better function/member with static modifier?
+// FIXME: better method with static modifier?
 return "function";
   case HighlightingKind::Field:
-// Not "member": https://github.com/clangd/vscode-clangd/issues/105
 return "property";
   case HighlightingKind::Class:
 return "class";



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


[PATCH] D91980: [OpenMP] Add initial support for `omp [begin/end] assumes`

2020-11-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Why don't yo want to try to implement the scheme similar to the declare target?




Comment at: clang/include/clang/Sema/Sema.h:10333
+  /// Check if there is an active global `omp begin assumes` directive.
+  bool isInOpenMPAssumeScope() { return !OMPAssumeScoped.empty(); }
+

`const` member function



Comment at: clang/include/clang/Sema/Sema.h:10336
+  /// Check if there is an active global `omp assumes` directive.
+  bool hasGlobalOpenMPAssumes() { return !OMPAssumeGlobal.empty(); }
+

`const` member function



Comment at: clang/lib/Parse/ParseOpenMP.cpp:1531
+
+  auto SkipBraces = [&](llvm::StringRef Spelling, bool IssueNote) {
+BalancedDelimiterTracker T(*this, tok::l_paren,

I think you will need just capture `this` by value here



Comment at: clang/lib/Parse/ParseOpenMP.cpp:1550-1555
+  {"absent", false, true, false},
+  {"contains", false, true, false},
+  {"holds", false, false, true},
+  {"no_openmp", false, false, false},
+  {"no_openmp_routines", false, false, false},
+  {"no_parallelism", false, false, false},

Why not express it as clauses?



Comment at: clang/lib/Parse/ParseOpenMP.cpp:1560
+  auto GetAllowedClauseStartValues = [&]() {
+std::string s;
+for (const AssumptionClauseMappingInfo  : AssumptionClauseMappings)

`S`



Comment at: clang/lib/Parse/ParseOpenMP.cpp:1569
+SourceLocation StartLoc = Tok.getLocation();
+int idx = -1;
+if (Tok.isAnyIdentifier()) {

`Idx`



Comment at: clang/lib/Parse/ParseOpenMP.cpp:1569-1593
+int idx = -1;
+if (Tok.isAnyIdentifier()) {
+  II = Tok.getIdentifierInfo();
+  llvm::StringSwitch SS(II->getName());
+  for (const AssumptionClauseMappingInfo  : AssumptionClauseMappings) 
{
+if (ACMI.StartsWith)
+  SS.StartsWith(ACMI.Identifier, ++idx);

ABataev wrote:
> `Idx`
Better to outline it into function/lambda



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3210
+
+SmallVector DeclContexts;
+DeclContexts.push_back(CurContext);

What are you trying to do here? Scan all the decls in the current context and 
mark all the functions with the assumption attributes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91980

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


[PATCH] D91311: Add new 'preferred_name' attribute.

2020-11-25 Thread Louis Dionne via Phabricator via cfe-commits
ldionne accepted this revision as: libc++.
ldionne added a comment.

LGTM from the libc++ point of view. The CI is passing -- those failures are 
flaky modules tests that we need to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91311

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


[PATCH] D92062: [MS] Add more 128bit cmpxchg intrinsics for AArch64

2020-11-25 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e843a987d84: [MS] Add more 128bit cmpxchg intrinsics for 
AArch64 (authored by rnk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92062

Files:
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/intrin.h
  clang/test/CodeGen/ms-intrinsics.c

Index: clang/test/CodeGen/ms-intrinsics.c
===
--- clang/test/CodeGen/ms-intrinsics.c
+++ clang/test/CodeGen/ms-intrinsics.c
@@ -6,10 +6,10 @@
 // RUN: | FileCheck %s --check-prefixes CHECK,CHECK-ARM,CHECK-ARM-ARM64,CHECK-ARM-X64
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
 // RUN: -triple x86_64--windows -Oz -emit-llvm -target-feature +cx16 %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-X64,CHECK-ARM-X64,CHECK-INTEL
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-X64,CHECK-ARM-X64,CHECK-INTEL,CHECK-64
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
 // RUN: -triple aarch64-windows -Oz -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK-ARM-ARM64,CHECK-ARM-X64,CHECK-ARM64
+// RUN: | FileCheck %s --check-prefixes CHECK-ARM-ARM64,CHECK-ARM-X64,CHECK-ARM64,CHECK-64
 
 // intrin.h needs size_t, but -ffreestanding prevents us from getting it from
 // stddef.h.  Work around it with this typedef.
@@ -432,32 +432,59 @@
 // CHECK: ret i64 [[RESULT]]
 // CHECK: }
 
-#if defined(__x86_64__)
+#if defined(__x86_64__) || defined(__aarch64__)
 unsigned char test_InterlockedCompareExchange128(
 __int64 volatile *Destination, __int64 ExchangeHigh,
 __int64 ExchangeLow, __int64 *ComparandResult) {
   return _InterlockedCompareExchange128(++Destination, ++ExchangeHigh,
 ++ExchangeLow, ++ComparandResult);
 }
-// CHECK-X64: define{{.*}}i8 @test_InterlockedCompareExchange128(i64*{{[a-z_ ]*}}%Destination, i64{{[a-z_ ]*}}%ExchangeHigh, i64{{[a-z_ ]*}}%ExchangeLow, i64*{{[a-z_ ]*}}%ComparandResult){{.*}}{
-// CHECK-X64: %incdec.ptr = getelementptr inbounds i64, i64* %Destination, i64 1
-// CHECK-X64: %inc = add nsw i64 %ExchangeHigh, 1
-// CHECK-X64: %inc1 = add nsw i64 %ExchangeLow, 1
-// CHECK-X64: %incdec.ptr2 = getelementptr inbounds i64, i64* %ComparandResult, i64 1
-// CHECK-X64: [[DST:%[0-9]+]] = bitcast i64* %incdec.ptr to i128*
-// CHECK-X64: [[EH:%[0-9]+]] = zext i64 %inc to i128
-// CHECK-X64: [[EL:%[0-9]+]] = zext i64 %inc1 to i128
-// CHECK-X64: [[CNR:%[0-9]+]] = bitcast i64* %incdec.ptr2 to i128*
-// CHECK-X64: [[EHS:%[0-9]+]] = shl nuw i128 [[EH]], 64
-// CHECK-X64: [[EXP:%[0-9]+]] = or i128 [[EHS]], [[EL]]
-// CHECK-X64: [[ORG:%[0-9]+]] = load i128, i128* [[CNR]], align 16
-// CHECK-X64: [[RES:%[0-9]+]] = cmpxchg volatile i128* [[DST]], i128 [[ORG]], i128 [[EXP]] seq_cst seq_cst
-// CHECK-X64: [[OLD:%[0-9]+]] = extractvalue { i128, i1 } [[RES]], 0
-// CHECK-X64: store i128 [[OLD]], i128* [[CNR]], align 16
-// CHECK-X64: [[SUC1:%[0-9]+]] = extractvalue { i128, i1 } [[RES]], 1
-// CHECK-X64: [[SUC8:%[0-9]+]] = zext i1 [[SUC1]] to i8
-// CHECK-X64: ret i8 [[SUC8]]
-// CHECK-X64: }
+// CHECK-64: define{{.*}}i8 @test_InterlockedCompareExchange128(i64*{{[a-z_ ]*}}%Destination, i64{{[a-z_ ]*}}%ExchangeHigh, i64{{[a-z_ ]*}}%ExchangeLow, i64*{{[a-z_ ]*}}%ComparandResult){{.*}}{
+// CHECK-64: %incdec.ptr = getelementptr inbounds i64, i64* %Destination, i64 1
+// CHECK-64: %inc = add nsw i64 %ExchangeHigh, 1
+// CHECK-64: %inc1 = add nsw i64 %ExchangeLow, 1
+// CHECK-64: %incdec.ptr2 = getelementptr inbounds i64, i64* %ComparandResult, i64 1
+// CHECK-64: [[DST:%[0-9]+]] = bitcast i64* %incdec.ptr to i128*
+// CHECK-64: [[CNR:%[0-9]+]] = bitcast i64* %incdec.ptr2 to i128*
+// CHECK-64: [[EH:%[0-9]+]] = zext i64 %inc to i128
+// CHECK-64: [[EL:%[0-9]+]] = zext i64 %inc1 to i128
+// CHECK-64: [[EHS:%[0-9]+]] = shl nuw i128 [[EH]], 64
+// CHECK-64: [[EXP:%[0-9]+]] = or i128 [[EHS]], [[EL]]
+// CHECK-64: [[ORG:%[0-9]+]] = load i128, i128* [[CNR]], align 16
+// CHECK-64: [[RES:%[0-9]+]] = cmpxchg volatile i128* [[DST]], i128 [[ORG]], i128 [[EXP]] seq_cst seq_cst
+// CHECK-64: [[OLD:%[0-9]+]] = extractvalue { i128, i1 } [[RES]], 0
+// CHECK-64: store i128 [[OLD]], i128* [[CNR]], align 16
+// CHECK-64: [[SUC1:%[0-9]+]] = extractvalue { i128, i1 } [[RES]], 1
+// CHECK-64: [[SUC8:%[0-9]+]] = zext i1 [[SUC1]] to i8
+// CHECK-64: ret i8 [[SUC8]]
+// CHECK-64: }
+#endif
+
+#if defined(__aarch64__)
+unsigned char test_InterlockedCompareExchange128_acq(
+__int64 volatile *Destination, __int64 ExchangeHigh,
+__int64 ExchangeLow, __int64 *ComparandResult) {
+  return 

[clang] 1e843a9 - [MS] Add more 128bit cmpxchg intrinsics for AArch64

2020-11-25 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2020-11-25T12:07:28-08:00
New Revision: 1e843a987d847da48aaf41801b79cfb364937e8f

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

LOG: [MS] Add more 128bit cmpxchg intrinsics for AArch64

The MSVC STL for requires this on ARM64.
Requested in https://llvm.org/pr47099

Depends on D92061

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAArch64.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/intrin.h
clang/test/CodeGen/ms-intrinsics.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index f07c567053de..c684105908de 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -153,6 +153,11 @@ TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_acq, 
"LLiLLiD*LLiLLi", "nh",
 TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_nf,  "LLiLLiD*LLiLLi", 
"nh", "intrin.h", ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_rel, "LLiLLiD*LLiLLi", 
"nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
+TARGET_HEADER_BUILTIN(_InterlockedCompareExchange128,"UcLLiD*LLiLLiLLi*", 
"nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_InterlockedCompareExchange128_acq,"UcLLiD*LLiLLiLLi*", 
"nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_InterlockedCompareExchange128_nf ,"UcLLiD*LLiLLiLLi*", 
"nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_InterlockedCompareExchange128_rel,"UcLLiD*LLiLLiLLi*", 
"nh", "intrin.h", ALL_MS_LANGUAGES, "")
+
 TARGET_HEADER_BUILTIN(_InterlockedOr8_acq,  "ccD*c",   "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedOr8_nf,   "ccD*c",   "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedOr8_rel,  "ccD*c",   "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index b2bfc3c84322..828d66f83de9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -304,6 +304,10 @@ Value *EmitAtomicCmpXchgForMSIntrin(CodeGenFunction , 
const CallExpr *E,
  AtomicOrdering::Monotonic :
  SuccessOrdering;
 
+  // The atomic instruction is marked volatile for consistency with MSVC. This
+  // blocks the few atomics optimizations that LLVM has. If we want to optimize
+  // _Interlocked* operations in the future, we will have to remove the 
volatile
+  // marker.
   auto *Result = CGF.Builder.CreateAtomicCmpXchg(
Destination, Comparand, Exchange,
SuccessOrdering, FailureOrdering);
@@ -311,6 +315,68 @@ Value *EmitAtomicCmpXchgForMSIntrin(CodeGenFunction , 
const CallExpr *E,
   return CGF.Builder.CreateExtractValue(Result, 0);
 }
 
+// 64-bit Microsoft platforms support 128 bit cmpxchg operations. They are
+// prototyped like this:
+//
+// unsigned char _InterlockedCompareExchange128...(
+// __int64 volatile * _Destination,
+// __int64 _ExchangeHigh,
+// __int64 _ExchangeLow,
+// __int64 * _ComparandResult);
+static Value *EmitAtomicCmpXchg128ForMSIntrin(CodeGenFunction ,
+  const CallExpr *E,
+  AtomicOrdering SuccessOrdering) {
+  assert(E->getNumArgs() == 4);
+  llvm::Value *Destination = CGF.EmitScalarExpr(E->getArg(0));
+  llvm::Value *ExchangeHigh = CGF.EmitScalarExpr(E->getArg(1));
+  llvm::Value *ExchangeLow = CGF.EmitScalarExpr(E->getArg(2));
+  llvm::Value *ComparandPtr = CGF.EmitScalarExpr(E->getArg(3));
+
+  assert(Destination->getType()->isPointerTy());
+  assert(!ExchangeHigh->getType()->isPointerTy());
+  assert(!ExchangeLow->getType()->isPointerTy());
+  assert(ComparandPtr->getType()->isPointerTy());
+
+  // For Release ordering, the failure ordering should be Monotonic.
+  auto FailureOrdering = SuccessOrdering == AtomicOrdering::Release
+ ? AtomicOrdering::Monotonic
+ : SuccessOrdering;
+
+  // Convert to i128 pointers and values.
+  llvm::Type *Int128Ty = llvm::IntegerType::get(CGF.getLLVMContext(), 128);
+  llvm::Type *Int128PtrTy = Int128Ty->getPointerTo();
+  Destination = CGF.Builder.CreateBitCast(Destination, Int128PtrTy);
+  Address ComparandResult(CGF.Builder.CreateBitCast(ComparandPtr, Int128PtrTy),
+  CGF.getContext().toCharUnitsFromBits(128));
+
+  // (((i128)hi) << 64) | ((i128)lo)
+  ExchangeHigh = CGF.Builder.CreateZExt(ExchangeHigh, Int128Ty);
+  ExchangeLow = CGF.Builder.CreateZExt(ExchangeLow, Int128Ty);
+  ExchangeHigh =
+  

[PATCH] D92000: [clangd] Collect main file refs by default

2020-11-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

nope, as it doesn't change the serialization format. but any existing shards 
won't have refs from the main file, they'll accumulate over time as sources 
gets modified. (i don't think it is worth bumping the version to invalidate 
existing shards, if a user cares enough they can manually delete their cache)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92000

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


[PATCH] D92062: [MS] Add more 128bit cmpxchg intrinsics for AArch64

2020-11-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk marked an inline comment as done.
rnk added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:336
+
+  // For Release ordering, the failure ordering should be Monotonic.
+  auto FailureOrdering = SuccessOrdering == AtomicOrdering::Release

thakis wrote:
> Why?
Honestly, I don't know. It's copied from above.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:360
+  SuccessOrdering, 
FailureOrdering);
+  CXI->setVolatile(true);
+

thakis wrote:
> why?
Truly, I don't think we should mark these volatile, but MSVC marks the 
destination pointer as volatile. I think it would be fine if we treated 
_Interlocked* atomic instructions as regular atomic instructions. I guess we 
just mark them volatile for safety. There are a few atomic instr optimizations, 
and volatile blocks them.



Comment at: clang/test/CodeGen/ms-intrinsics.c:441
 ++ExchangeLow, ++ComparandResult);
 }
+// CHECK-64: define{{.*}}i8 @test_InterlockedCompareExchange128(i64*{{[a-z_ 
]*}}%Destination, i64{{[a-z_ ]*}}%ExchangeHigh, i64{{[a-z_ ]*}}%ExchangeLow, 
i64*{{[a-z_ ]*}}%ComparandResult){{.*}}{

thakis wrote:
> should this test some of the new aarc64-only intrins too if `__aarch64__`?
Yeah, let's add them, but just check for the key cmpxchg instruction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92062

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


[PATCH] D92062: [MS] Add more 128bit cmpxchg intrinsics for AArch64

2020-11-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 307678.
rnk marked an inline comment as done.
rnk added a comment.

- add tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92062

Files:
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/intrin.h
  clang/test/CodeGen/ms-intrinsics.c

Index: clang/test/CodeGen/ms-intrinsics.c
===
--- clang/test/CodeGen/ms-intrinsics.c
+++ clang/test/CodeGen/ms-intrinsics.c
@@ -6,10 +6,10 @@
 // RUN: | FileCheck %s --check-prefixes CHECK,CHECK-ARM,CHECK-ARM-ARM64,CHECK-ARM-X64
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
 // RUN: -triple x86_64--windows -Oz -emit-llvm -target-feature +cx16 %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-X64,CHECK-ARM-X64,CHECK-INTEL
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-X64,CHECK-ARM-X64,CHECK-INTEL,CHECK-64
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
 // RUN: -triple aarch64-windows -Oz -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK-ARM-ARM64,CHECK-ARM-X64,CHECK-ARM64
+// RUN: | FileCheck %s --check-prefixes CHECK-ARM-ARM64,CHECK-ARM-X64,CHECK-ARM64,CHECK-64
 
 // intrin.h needs size_t, but -ffreestanding prevents us from getting it from
 // stddef.h.  Work around it with this typedef.
@@ -432,32 +432,59 @@
 // CHECK: ret i64 [[RESULT]]
 // CHECK: }
 
-#if defined(__x86_64__)
+#if defined(__x86_64__) || defined(__aarch64__)
 unsigned char test_InterlockedCompareExchange128(
 __int64 volatile *Destination, __int64 ExchangeHigh,
 __int64 ExchangeLow, __int64 *ComparandResult) {
   return _InterlockedCompareExchange128(++Destination, ++ExchangeHigh,
 ++ExchangeLow, ++ComparandResult);
 }
-// CHECK-X64: define{{.*}}i8 @test_InterlockedCompareExchange128(i64*{{[a-z_ ]*}}%Destination, i64{{[a-z_ ]*}}%ExchangeHigh, i64{{[a-z_ ]*}}%ExchangeLow, i64*{{[a-z_ ]*}}%ComparandResult){{.*}}{
-// CHECK-X64: %incdec.ptr = getelementptr inbounds i64, i64* %Destination, i64 1
-// CHECK-X64: %inc = add nsw i64 %ExchangeHigh, 1
-// CHECK-X64: %inc1 = add nsw i64 %ExchangeLow, 1
-// CHECK-X64: %incdec.ptr2 = getelementptr inbounds i64, i64* %ComparandResult, i64 1
-// CHECK-X64: [[DST:%[0-9]+]] = bitcast i64* %incdec.ptr to i128*
-// CHECK-X64: [[EH:%[0-9]+]] = zext i64 %inc to i128
-// CHECK-X64: [[EL:%[0-9]+]] = zext i64 %inc1 to i128
-// CHECK-X64: [[CNR:%[0-9]+]] = bitcast i64* %incdec.ptr2 to i128*
-// CHECK-X64: [[EHS:%[0-9]+]] = shl nuw i128 [[EH]], 64
-// CHECK-X64: [[EXP:%[0-9]+]] = or i128 [[EHS]], [[EL]]
-// CHECK-X64: [[ORG:%[0-9]+]] = load i128, i128* [[CNR]], align 16
-// CHECK-X64: [[RES:%[0-9]+]] = cmpxchg volatile i128* [[DST]], i128 [[ORG]], i128 [[EXP]] seq_cst seq_cst
-// CHECK-X64: [[OLD:%[0-9]+]] = extractvalue { i128, i1 } [[RES]], 0
-// CHECK-X64: store i128 [[OLD]], i128* [[CNR]], align 16
-// CHECK-X64: [[SUC1:%[0-9]+]] = extractvalue { i128, i1 } [[RES]], 1
-// CHECK-X64: [[SUC8:%[0-9]+]] = zext i1 [[SUC1]] to i8
-// CHECK-X64: ret i8 [[SUC8]]
-// CHECK-X64: }
+// CHECK-64: define{{.*}}i8 @test_InterlockedCompareExchange128(i64*{{[a-z_ ]*}}%Destination, i64{{[a-z_ ]*}}%ExchangeHigh, i64{{[a-z_ ]*}}%ExchangeLow, i64*{{[a-z_ ]*}}%ComparandResult){{.*}}{
+// CHECK-64: %incdec.ptr = getelementptr inbounds i64, i64* %Destination, i64 1
+// CHECK-64: %inc = add nsw i64 %ExchangeHigh, 1
+// CHECK-64: %inc1 = add nsw i64 %ExchangeLow, 1
+// CHECK-64: %incdec.ptr2 = getelementptr inbounds i64, i64* %ComparandResult, i64 1
+// CHECK-64: [[DST:%[0-9]+]] = bitcast i64* %incdec.ptr to i128*
+// CHECK-64: [[CNR:%[0-9]+]] = bitcast i64* %incdec.ptr2 to i128*
+// CHECK-64: [[EH:%[0-9]+]] = zext i64 %inc to i128
+// CHECK-64: [[EL:%[0-9]+]] = zext i64 %inc1 to i128
+// CHECK-64: [[EHS:%[0-9]+]] = shl nuw i128 [[EH]], 64
+// CHECK-64: [[EXP:%[0-9]+]] = or i128 [[EHS]], [[EL]]
+// CHECK-64: [[ORG:%[0-9]+]] = load i128, i128* [[CNR]], align 16
+// CHECK-64: [[RES:%[0-9]+]] = cmpxchg volatile i128* [[DST]], i128 [[ORG]], i128 [[EXP]] seq_cst seq_cst
+// CHECK-64: [[OLD:%[0-9]+]] = extractvalue { i128, i1 } [[RES]], 0
+// CHECK-64: store i128 [[OLD]], i128* [[CNR]], align 16
+// CHECK-64: [[SUC1:%[0-9]+]] = extractvalue { i128, i1 } [[RES]], 1
+// CHECK-64: [[SUC8:%[0-9]+]] = zext i1 [[SUC1]] to i8
+// CHECK-64: ret i8 [[SUC8]]
+// CHECK-64: }
+#endif
+
+#if defined(__aarch64__)
+unsigned char test_InterlockedCompareExchange128_acq(
+__int64 volatile *Destination, __int64 ExchangeHigh,
+__int64 ExchangeLow, __int64 *ComparandResult) {
+  return _InterlockedCompareExchange128_acq(Destination, ExchangeHigh,
+ExchangeLow, ComparandResult);
+}
+unsigned 

[PATCH] D92122: [FPEnv] clang should get from the AST the metadata for constrained FP builtins

2020-11-25 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn created this revision.
kpn added reviewers: sepavloff, mibintc, rjmccall.
kpn added a project: clang.
Herald added a subscriber: cfe-commits.
kpn requested review of this revision.

Currently clang is not correctly retrieving from the AST the metadata for 
constrained FP builtins. This patch fixes that for the non-target specific 
builtins.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92122

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtin_float_strictfp.c
  clang/test/CodeGen/constrained-math-builtins.c
  clang/test/CodeGen/strictfp_fpclassify.c

Index: clang/test/CodeGen/strictfp_fpclassify.c
===
--- /dev/null
+++ clang/test/CodeGen/strictfp_fpclassify.c
@@ -0,0 +1,130 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap -o - -triple x86_64-unknown-unknown | FileCheck %s
+
+// Test that the constrained intrinsics are picking up the exception
+// metadata from the AST instead of the global default from the command line.
+// FIXME: these functions shouldn't trap on SNaN.
+
+#pragma float_control(except, on)
+
+int printf(const char *, ...);
+
+// CHECK-LABEL: @p(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[STR_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i8* [[STR:%.*]], i8** [[STR_ADDR]], align 8
+// CHECK-NEXT:store i32 [[X:%.*]], i32* [[X_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i8*, i8** [[STR_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* [[X_ADDR]], align 4
+// CHECK-NEXT:[[CALL:%.*]] = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* [[TMP0]], i32 [[TMP1]]) [[ATTR4:#.*]]
+// CHECK-NEXT:ret void
+//
+void p(char *str, int x) {
+  printf("%s: %d\n", str, x);
+}
+
+#define P(n,args) p(#n #args, __builtin_##n args)
+
+// CHECK-LABEL: @test_fpclassify(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[D_ADDR:%.*]] = alloca double, align 8
+// CHECK-NEXT:store double [[D:%.*]], double* [[D_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load double, double* [[D_ADDR]], align 8
+// CHECK-NEXT:[[ISZERO:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double [[TMP0]], double 0.00e+00, metadata !"oeq", metadata !"fpexcept.strict") [[ATTR4]]
+// CHECK-NEXT:br i1 [[ISZERO]], label [[FPCLASSIFY_END:%.*]], label [[FPCLASSIFY_NOT_ZERO:%.*]]
+// CHECK:   fpclassify_end:
+// CHECK-NEXT:[[FPCLASSIFY_RESULT:%.*]] = phi i32 [ 4, [[ENTRY:%.*]] ], [ 0, [[FPCLASSIFY_NOT_ZERO]] ], [ 1, [[FPCLASSIFY_NOT_NAN:%.*]] ], [ [[TMP2:%.*]], [[FPCLASSIFY_NOT_INF:%.*]] ]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 [[FPCLASSIFY_RESULT]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+// CHECK:   fpclassify_not_zero:
+// CHECK-NEXT:[[CMP:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double [[TMP0]], double [[TMP0]], metadata !"uno", metadata !"fpexcept.strict") [[ATTR4]]
+// CHECK-NEXT:br i1 [[CMP]], label [[FPCLASSIFY_END]], label [[FPCLASSIFY_NOT_NAN]]
+// CHECK:   fpclassify_not_nan:
+// CHECK-NEXT:[[TMP1:%.*]] = call double @llvm.fabs.f64(double [[TMP0]]) [[ATTR5:#.*]]
+// CHECK-NEXT:[[ISINF:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double [[TMP1]], double 0x7FF0, metadata !"oeq", metadata !"fpexcept.strict") [[ATTR4]]
+// CHECK-NEXT:br i1 [[ISINF]], label [[FPCLASSIFY_END]], label [[FPCLASSIFY_NOT_INF]]
+// CHECK:   fpclassify_not_inf:
+// CHECK-NEXT:[[ISNORMAL:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double [[TMP1]], double 0x10, metadata !"uge", metadata !"fpexcept.strict") [[ATTR4]]
+// CHECK-NEXT:[[TMP2]] = select i1 [[ISNORMAL]], i32 2, i32 3
+// CHECK-NEXT:br label [[FPCLASSIFY_END]]
+//
+void test_fpclassify(double d) {
+  P(fpclassify, (0, 1, 2, 3, 4, d));
+
+  return;
+}
+
+// CHECK-LABEL: @test_isinf(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[D_ADDR:%.*]] = alloca double, align 8
+// CHECK-NEXT:store double [[D:%.*]], double* [[D_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load double, double* [[D_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = call double @llvm.fabs.f64(double [[TMP0]]) [[ATTR5]]
+// CHECK-NEXT:[[CMPINF:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double [[TMP1]], double 0x7FF0, metadata !"oeq", metadata !"fpexcept.strict") [[ATTR4]]
+// CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[CMPINF]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 [[TMP2]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+//
+void test_isinf(double d) {
+  P(isinf, (d));
+
+  return;
+}
+
+// CHECK-LABEL: @test_isinf_sign(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[D_ADDR:%.*]] = 

[clang] 3bd0672 - [MS] Fix double evaluation of MSVC builtin arguments

2020-11-25 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2020-11-25T11:55:01-08:00
New Revision: 3bd06727267184223464f11d4e2470048ac40cb1

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

LOG: [MS] Fix double evaluation of MSVC builtin arguments

This code got quite twisted because we consider some MSVC builtins to be
target agnostic, and some to be target specific. Target specific
intrinsics have a pattern of doing up-front argument evaluation, while
general intrinsics do not evaluate their arguments up front. As we tried
to share codepaths between the target-specific and target-agnostic
handling, we ended up doing double evaluation.

Instead, have each target handle MSVC intrinsics consistently before up
front argument evaluation. This requires passing less data around and is
more consistent with target independent intrinsic handling.

See D50979 for past examples of this bug. I noticed this while looking
into adding some more intrinsics.

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/CodeGen/ms-intrinsics.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e98ec3e35e37..b2bfc3c84322 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1011,16 +1011,342 @@ enum class CodeGenFunction::MSVCIntrin {
   __fastfail,
 };
 
+static Optional
+translateArmToMsvcIntrin(unsigned BuiltinID) {
+  using MSVCIntrin = CodeGenFunction::MSVCIntrin;
+  switch (BuiltinID) {
+  default:
+return None;
+  case ARM::BI_BitScanForward:
+  case ARM::BI_BitScanForward64:
+return MSVCIntrin::_BitScanForward;
+  case ARM::BI_BitScanReverse:
+  case ARM::BI_BitScanReverse64:
+return MSVCIntrin::_BitScanReverse;
+  case ARM::BI_InterlockedAnd64:
+return MSVCIntrin::_InterlockedAnd;
+  case ARM::BI_InterlockedExchange64:
+return MSVCIntrin::_InterlockedExchange;
+  case ARM::BI_InterlockedExchangeAdd64:
+return MSVCIntrin::_InterlockedExchangeAdd;
+  case ARM::BI_InterlockedExchangeSub64:
+return MSVCIntrin::_InterlockedExchangeSub;
+  case ARM::BI_InterlockedOr64:
+return MSVCIntrin::_InterlockedOr;
+  case ARM::BI_InterlockedXor64:
+return MSVCIntrin::_InterlockedXor;
+  case ARM::BI_InterlockedDecrement64:
+return MSVCIntrin::_InterlockedDecrement;
+  case ARM::BI_InterlockedIncrement64:
+return MSVCIntrin::_InterlockedIncrement;
+  case ARM::BI_InterlockedExchangeAdd8_acq:
+  case ARM::BI_InterlockedExchangeAdd16_acq:
+  case ARM::BI_InterlockedExchangeAdd_acq:
+  case ARM::BI_InterlockedExchangeAdd64_acq:
+return MSVCIntrin::_InterlockedExchangeAdd_acq;
+  case ARM::BI_InterlockedExchangeAdd8_rel:
+  case ARM::BI_InterlockedExchangeAdd16_rel:
+  case ARM::BI_InterlockedExchangeAdd_rel:
+  case ARM::BI_InterlockedExchangeAdd64_rel:
+return MSVCIntrin::_InterlockedExchangeAdd_rel;
+  case ARM::BI_InterlockedExchangeAdd8_nf:
+  case ARM::BI_InterlockedExchangeAdd16_nf:
+  case ARM::BI_InterlockedExchangeAdd_nf:
+  case ARM::BI_InterlockedExchangeAdd64_nf:
+return MSVCIntrin::_InterlockedExchangeAdd_nf;
+  case ARM::BI_InterlockedExchange8_acq:
+  case ARM::BI_InterlockedExchange16_acq:
+  case ARM::BI_InterlockedExchange_acq:
+  case ARM::BI_InterlockedExchange64_acq:
+return MSVCIntrin::_InterlockedExchange_acq;
+  case ARM::BI_InterlockedExchange8_rel:
+  case ARM::BI_InterlockedExchange16_rel:
+  case ARM::BI_InterlockedExchange_rel:
+  case ARM::BI_InterlockedExchange64_rel:
+return MSVCIntrin::_InterlockedExchange_rel;
+  case ARM::BI_InterlockedExchange8_nf:
+  case ARM::BI_InterlockedExchange16_nf:
+  case ARM::BI_InterlockedExchange_nf:
+  case ARM::BI_InterlockedExchange64_nf:
+return MSVCIntrin::_InterlockedExchange_nf;
+  case ARM::BI_InterlockedCompareExchange8_acq:
+  case ARM::BI_InterlockedCompareExchange16_acq:
+  case ARM::BI_InterlockedCompareExchange_acq:
+  case ARM::BI_InterlockedCompareExchange64_acq:
+return MSVCIntrin::_InterlockedCompareExchange_acq;
+  case ARM::BI_InterlockedCompareExchange8_rel:
+  case ARM::BI_InterlockedCompareExchange16_rel:
+  case ARM::BI_InterlockedCompareExchange_rel:
+  case ARM::BI_InterlockedCompareExchange64_rel:
+return MSVCIntrin::_InterlockedCompareExchange_rel;
+  case ARM::BI_InterlockedCompareExchange8_nf:
+  case ARM::BI_InterlockedCompareExchange16_nf:
+  case ARM::BI_InterlockedCompareExchange_nf:
+  case ARM::BI_InterlockedCompareExchange64_nf:
+return MSVCIntrin::_InterlockedCompareExchange_nf;
+  case ARM::BI_InterlockedOr8_acq:
+  case ARM::BI_InterlockedOr16_acq:
+  case ARM::BI_InterlockedOr_acq:
+  case ARM::BI_InterlockedOr64_acq:
+return MSVCIntrin::_InterlockedOr_acq;
+  case 

[PATCH] D92061: [MS] Fix double evaluation of MSVC builtin arguments

2020-11-25 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3bd067272671: [MS] Fix double evaluation of MSVC builtin 
arguments (authored by rnk).

Changed prior to commit:
  https://reviews.llvm.org/D92061?vs=307468=307674#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92061

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/ms-intrinsics.c

Index: clang/test/CodeGen/ms-intrinsics.c
===
--- clang/test/CodeGen/ms-intrinsics.c
+++ clang/test/CodeGen/ms-intrinsics.c
@@ -147,7 +147,7 @@
 #endif
 
 unsigned char test_BitScanForward(unsigned long *Index, unsigned long Mask) {
-  return _BitScanForward(Index, Mask);
+  return _BitScanForward(++Index, Mask);
 }
 // CHECK: define{{.*}}i8 @test_BitScanForward(i32* {{[a-z_ ]*}}%Index, i32 {{[a-z_ ]*}}%Mask){{.*}}{
 // CHECK:   [[ISNOTZERO:%[a-z0-9._]+]] = icmp eq i32 %Mask, 0
@@ -156,12 +156,13 @@
 // CHECK:   [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
 // CHECK:   ret i8 [[RESULT]]
 // CHECK:   [[ISNOTZERO_LABEL]]:
+// CHECK:   [[IDXGEP:%[a-z0-9._]+]] = getelementptr inbounds i32, i32* %Index, {{i64|i32}} 1
 // CHECK:   [[INDEX:%[0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %Mask, i1 true)
-// CHECK:   store i32 [[INDEX]], i32* %Index, align 4
+// CHECK:   store i32 [[INDEX]], i32* [[IDXGEP]], align 4
 // CHECK:   br label %[[END_LABEL]]
 
 unsigned char test_BitScanReverse(unsigned long *Index, unsigned long Mask) {
-  return _BitScanReverse(Index, Mask);
+  return _BitScanReverse(++Index, Mask);
 }
 // CHECK: define{{.*}}i8 @test_BitScanReverse(i32* {{[a-z_ ]*}}%Index, i32 {{[a-z_ ]*}}%Mask){{.*}}{
 // CHECK:   [[ISNOTZERO:%[0-9]+]] = icmp eq i32 %Mask, 0
@@ -170,9 +171,10 @@
 // CHECK:   [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
 // CHECK:   ret i8 [[RESULT]]
 // CHECK:   [[ISNOTZERO_LABEL]]:
+// CHECK:   [[IDXGEP:%[a-z0-9._]+]] = getelementptr inbounds i32, i32* %Index, {{i64|i32}} 1
 // CHECK:   [[REVINDEX:%[0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %Mask, i1 true)
 // CHECK:   [[INDEX:%[0-9]+]] = xor i32 [[REVINDEX]], 31
-// CHECK:   store i32 [[INDEX]], i32* %Index, align 4
+// CHECK:   store i32 [[INDEX]], i32* [[IDXGEP]], align 4
 // CHECK:   br label %[[END_LABEL]]
 
 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
@@ -459,19 +461,21 @@
 #endif
 
 short test_InterlockedIncrement16(short volatile *Addend) {
-  return _InterlockedIncrement16(Addend);
+  return _InterlockedIncrement16(++Addend);
 }
 // CHECK: define{{.*}}i16 @test_InterlockedIncrement16(i16*{{[a-z_ ]*}}%Addend){{.*}}{
-// CHECK: [[TMP:%[0-9]+]] = atomicrmw add i16* %Addend, i16 1 seq_cst
+// CHECK: %incdec.ptr = getelementptr inbounds i16, i16* %Addend, {{i64|i32}} 1
+// CHECK: [[TMP:%[0-9]+]] = atomicrmw add i16* %incdec.ptr, i16 1 seq_cst
 // CHECK: [[RESULT:%[0-9]+]] = add i16 [[TMP]], 1
 // CHECK: ret i16 [[RESULT]]
 // CHECK: }
 
 long test_InterlockedIncrement(long volatile *Addend) {
-  return _InterlockedIncrement(Addend);
+  return _InterlockedIncrement(++Addend);
 }
 // CHECK: define{{.*}}i32 @test_InterlockedIncrement(i32*{{[a-z_ ]*}}%Addend){{.*}}{
-// CHECK: [[TMP:%[0-9]+]] = atomicrmw add i32* %Addend, i32 1 seq_cst
+// CHECK: %incdec.ptr = getelementptr inbounds i32, i32* %Addend, {{i64|i32}} 1
+// CHECK: [[TMP:%[0-9]+]] = atomicrmw add i32* %incdec.ptr, i32 1 seq_cst
 // CHECK: [[RESULT:%[0-9]+]] = add i32 [[TMP]], 1
 // CHECK: ret i32 [[RESULT]]
 // CHECK: }
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -4120,10 +4120,7 @@
llvm::AtomicOrdering ,
llvm::SyncScope::ID );
 
-private:
   enum class MSVCIntrin;
-
-public:
   llvm::Value *EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, const CallExpr *E);
 
   llvm::Value *EmitBuiltinAvailable(const VersionTuple );
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1011,16 +1011,342 @@
   __fastfail,
 };
 
+static Optional
+translateArmToMsvcIntrin(unsigned BuiltinID) {
+  using MSVCIntrin = CodeGenFunction::MSVCIntrin;
+  switch (BuiltinID) {
+  default:
+return None;
+  case ARM::BI_BitScanForward:
+  case ARM::BI_BitScanForward64:
+return MSVCIntrin::_BitScanForward;
+  case ARM::BI_BitScanReverse:
+  case ARM::BI_BitScanReverse64:
+return MSVCIntrin::_BitScanReverse;
+  case ARM::BI_InterlockedAnd64:
+return MSVCIntrin::_InterlockedAnd;
+  case ARM::BI_InterlockedExchange64:
+return 

[PATCH] D92000: [clangd] Collect main file refs by default

2020-11-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

One thing that just occurred to me: does this need an index version bump?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92000

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


[PATCH] D92061: [MS] Fix double evaluation of MSVC builtin arguments

2020-11-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk marked an inline comment as done.
rnk added a comment.

Thanks!




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:1019
+  default:
+break;
+  case ARM::BI_BitScanForward:

thakis wrote:
> Maybe `return None` here and LLVM_UNREACHABLE at the bottom?
Sure, why not. Why do you like this version better?



Comment at: clang/lib/CodeGen/CodeGenFunction.h:4126
+  llvm::Value *EmitEvaluatedMSVCBuiltin(MSVCIntrin BuiltinID, const CallExpr 
*E,
+ArrayRef Ops);
 

thakis wrote:
> ...where's the definition of this function? I can't see calls either. I guess 
> this is a remnant from an earlier approach?
Yeah, it is. I'll zap it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92061

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


[PATCH] D90188: Add support for attribute 'using_if_exists'

2020-11-25 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:1704-1707
+void ASTDeclReader::VisitUnresolvedUsingIfExistsDecl(
+UnresolvedUsingIfExistsDecl *D) {
+  VisitNamedDecl(D);
+}

aaron.ballman wrote:
> I'm not super familiar with this code, but is this change actually necessary? 
> I would have expected this to be handled via `VisitNamedDecl` by virtue of 
> `UnresolvedUsingIfExistsDecl` inheriting from `NamedDecl`.
I think its necessary -- `DeclVisitor` doesn't automatically visit the base 
classes. Every other `Visit*` function here manually visits the base classes 
too FWIW.


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

https://reviews.llvm.org/D90188

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


[PATCH] D90188: Add support for attribute 'using_if_exists'

2020-11-25 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 307670.
erik.pilkington marked 4 inline comments as done.
erik.pilkington added a comment.

Address review comments.


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

https://reviews.llvm.org/D90188

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DeclNodes.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/DeclBase.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Parser/using-if-exists-attr.cpp
  clang/test/SemaCXX/attr-deprecated.cpp
  clang/test/SemaCXX/using-if-exists.cpp
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -6414,6 +6414,7 @@
   case Decl::Concept:
   case Decl::LifetimeExtendedTemporary:
   case Decl::RequiresExprBody:
+  case Decl::UnresolvedUsingIfExists:
 return C;
 
   // Declaration kinds that don't make any sense here, but are
Index: clang/test/SemaCXX/using-if-exists.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/using-if-exists.cpp
@@ -0,0 +1,207 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify
+
+#define UIE __attribute__((using_if_exists))
+
+namespace test_basic {
+namespace NS {}
+
+using NS::x UIE; // expected-note{{using declaration annotated with 'using_if_exists' here}}
+x usex(); // expected-error{{reference to unresolved using declaration}}
+
+using NotNS::x UIE; // expected-error{{use of undeclared identifier 'NotNS'}}
+} // test_basic
+
+namespace test_redecl {
+namespace NS {}
+
+using NS::x UIE;
+using NS::x UIE;
+
+namespace NS1 {}
+namespace NS2 {}
+namespace NS3 {
+int A(); // expected-note{{target of using declaration}}
+struct B {}; // expected-note{{target of using declaration}}
+int C(); // expected-note{{conflicting declaration}}
+struct D {}; // expected-note{{conflicting declaration}}
+}
+
+using NS1::A UIE;
+using NS2::A UIE; // expected-note{{using declaration annotated with 'using_if_exists' here}} expected-note{{conflicting declaration}}
+using NS3::A UIE; // expected-error{{target of using declaration conflicts with declaration already in scope}}
+int i = A(); // expected-error{{reference to unresolved using declaration}}
+
+using NS1::B UIE;
+using NS2::B UIE; // expected-note{{conflicting declaration}} expected-note{{using declaration annotated with 'using_if_exists' here}}
+using NS3::B UIE; // expected-error{{target of using declaration conflicts with declaration already in scope}}
+B myB; // expected-error{{reference to unresolved using declaration}}
+
+using NS3::C UIE;
+using NS2::C UIE; // expected-error{{target of using declaration conflicts with declaration already in scope}} expected-note{{target of using declaration}}
+int j = C();
+
+using NS3::D UIE;
+using NS2::D UIE; // expected-error{{target of using declaration conflicts with declaration already in scope}} expected-note{{target of using declaration}}
+D myD;
+} // test_redecl
+
+namespace test_dependent {
+template 
+struct S : B {
+  using B::mf UIE; // expected-note 3 {{using declaration annotated with 'using_if_exists' here}}
+  using typename B::mt UIE; // expected-note{{using declaration annotated with 'using_if_exists' here}}
+};
+
+struct BaseEmpty {
+};
+struct BaseNonEmpty {
+  void mf();
+  typedef int mt;
+};
+
+void f() {
+  S empty;
+  S nonempty;
+  empty.mf(); // expected-error {{reference to unresolved using declaration}}
+  nonempty.mf();
+  ()->mf(); // expected-error {{reference to unresolved using declaration}}
+  ()->mf();
+
+  S::mt y; // expected-error {{reference to unresolved using declaration}}
+  S::mt z;
+
+  S::mf(); // expected-error {{reference to unresolved using declaration}}
+}
+
+template 
+struct Implicit : B {
+  using B::mf UIE; // expected-note {{using declaration annotated with 'using_if_exists' here}}
+  using typename B::mt UIE; // expected-note 2 {{using declaration annotated with 'using_if_exists' here}}
+
+  void use() {
+mf(); // expected-error {{reference to unresolved using declaration}}
+mt x; // expected-error {{reference to unresolved using declaration}}
+  }
+
+  mt alsoUse(); // expected-error {{reference to unresolved using declaration}}
+};
+
+void testImplicit() {
+  Implicit nonempty;
+  Implicit empty; // 

[PATCH] D91630: [Parse] Add parsing support for C++ attributes on using-declarations

2020-11-25 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added a comment.

In D91630#235 , @aaron.ballman 
wrote:

> Can you mention this change in the release notes? Also, should we document it 
> explicitly in the Language Extensions documentation, or do you think this is 
> too tiny of a feature to warrant that?

Sure, I added release notes and language extension docs. I also added a 
__has_extension for this. That might all be a little overkill, I'm happy to 
pull out those changes if so.

In D91630#2400731 , @rsmith wrote:

> Do `[[deprecated]]` and `[[maybe_unused]]` now work for 
> //using-declarator//s? If so, a test for that would be useful.

`[[deprecated]]` gets applied, but it doesn't have any effect, since we don't 
attach an attribute to the UsingShadowDecl, and regardless, we already look 
past the UsingShadowDecl before we reach DiagnoseUseOfDecl. I added a 
-Wignored-attributes diagnostic to call this out.




Comment at: clang/lib/Parse/ParseDeclCXX.cpp:714
 
-  // C++11 attributes are not allowed on a using-declaration, but GNU ones
-  // are.
   ProhibitAttributes(MisplacedAttrs);
+  DiagnoseCXX11AttributeExtension(PrefixAttrs);

rsmith wrote:
> Should we suggest moving the attributes after the identifier in this case 
> (even though that will leave the program ill-formed), as we do for 
> alias-declarations?
Sure, I added this in the new patch.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:737
+DiagnoseCXX11AttributeExtension(Attrs);
+Attrs.addAll(PrefixAttrs.begin(), PrefixAttrs.end());
 

rsmith wrote:
> Should the prefix attributes go before the suffix attributes? (I could 
> imagine there might be attributes for which order matters.) What do we do in 
> the simple-declaration case?
Surprisingly, this does apply attributes to the beginning of the list:

```
void addAll(iterator B, iterator E) {
  AttrList.insert(AttrList.begin(), B.I, E.I);
}
```

This is consistent with simple-declarations.



Comment at: clang/test/Parser/cxx0x-attributes.cpp:134
 
-[[]] using ns::i; // expected-error {{an attribute list cannot appear here}}
+[[]] using ns::i;
 [[unknown]] using namespace ns; // expected-warning {{unknown attribute 
'unknown' ignored}}

aaron.ballman wrote:
> Btw, a `-pedantic` test for the parser behavior would be useful so that we 
> can be sure the new diagnostic is firing as expected.
Sure, I added that in a new test file.


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

https://reviews.llvm.org/D91630

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


[PATCH] D91630: [Parse] Add parsing support for C++ attributes on using-declarations

2020-11-25 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 307669.
erik.pilkington marked 6 inline comments as done.
erik.pilkington added a comment.
Herald added a subscriber: dexonsmith.

Address review comments.


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

https://reviews.llvm.org/D91630

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/SemaCXX/cxx11-attributes-on-using-declaration.cpp

Index: clang/test/SemaCXX/cxx11-attributes-on-using-declaration.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx11-attributes-on-using-declaration.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -pedantic -triple x86_64-apple-macos11 -std=c++20 -fsyntax-only -verify %s
+
+static_assert(__has_extension(cxx_attributes_on_using_declarations), "");
+
+namespace NS { typedef int x; }
+
+[[clang::annotate("foo")]] using NS::x; // expected-warning{{ISO C++ does not allow an attribute list to appear here}}
+
+
+[[deprecated]] using NS::x; // expected-warning {{'deprecated' currently has no effect on using-declarations}} expected-warning{{ISO C++ does not allow}}
+using NS::x [[deprecated]]; // expected-warning {{'deprecated' currently has no effect on using-declarations}} expected-warning{{ISO C++ does not allow}}
+using NS::x __attribute__((deprecated)); // expected-warning {{'deprecated' currently has no effect on using-declarations}}
+using NS::x __attribute__((availability(macos,introduced=1))); // expected-warning {{'availability' currently has no effect on using-declarations}}
+
+[[clang::availability(macos,introduced=1)]] using NS::x; // expected-warning {{'availability' currently has no effect on using-declarations}} expected-warning{{ISO C++ does not allow}}
+
+// expected-warning@+1 3 {{ISO C++ does not allow an attribute list to appear here}}
+[[clang::annotate("A")]] using NS::x [[clang::annotate("Y")]], NS::x [[clang::annotate("Z")]];
+
+template 
+struct S : T {
+  [[deprecated]] using typename T::x; // expected-warning{{ISO C++ does not allow}} expected-warning {{'deprecated' currently has no effect on using-declarations}}
+  [[deprecated]] using T::y; // expected-warning{{ISO C++ does not allow}} expected-warning {{'deprecated' currently has no effect on using-declarations}}
+
+  using typename T::z [[deprecated]]; // expected-warning{{ISO C++ does not allow}} expected-warning {{'deprecated' currently has no effect on using-declarations}}
+  using T::a [[deprecated]]; // expected-warning{{ISO C++ does not allow}} expected-warning {{'deprecated' currently has no effect on using-declarations}}
+};
Index: clang/test/Parser/cxx0x-attributes.cpp
===
--- clang/test/Parser/cxx0x-attributes.cpp
+++ clang/test/Parser/cxx0x-attributes.cpp
@@ -131,12 +131,12 @@
 [[]] static_assert(true, ""); //expected-error {{an attribute list cannot appear here}}
 [[]] asm(""); // expected-error {{an attribute list cannot appear here}}
 
-[[]] using ns::i; // expected-error {{an attribute list cannot appear here}}
+[[]] using ns::i;
 [[unknown]] using namespace ns; // expected-warning {{unknown attribute 'unknown' ignored}}
 [[noreturn]] using namespace ns; // expected-error {{'noreturn' attribute only applies to functions}}
 namespace [[]] ns2 {} // expected-warning {{attributes on a namespace declaration are a C++17 extension}}
 
-using [[]] alignas(4) [[]] ns::i; // expected-error {{an attribute list cannot appear here}}
+using [[]] alignas(4) [[]] ns::i; // expected-error {{an attribute list cannot appear here}} expected-error {{'alignas' attribute only applies to variables, data members and tag types}} expected-warning {{ISO C++}}
 using [[]] alignas(4) [[]] foobar = int; // expected-error {{an attribute list cannot appear here}} expected-error {{'alignas' attribute only applies to}}
 
 void bad_attributes_in_do_while() {
@@ -157,7 +157,16 @@
 [[]] using T = int; // expected-error {{an attribute list cannot appear here}}
 using T [[]] = int; // ok
 template using U [[]] = T;
-using ns::i [[]]; // expected-error {{an attribute list cannot appear here}}
+using ns::i [[]];
+using ns::i [[]], ns::i [[]]; // expected-warning {{use of multiple declarators in a single using declaration is a C++17 extension}}
+struct using_in_struct_base {
+  typedef int i, j, k, l;
+};
+struct using_in_struct : using_in_struct_base {
+  [[]] using using_in_struct_base::i;
+  using using_in_struct_base::j [[]];
+  [[]] using using_in_struct_base::k [[]], using_in_struct_base::l [[]]; // expected-warning {{use of multiple declarators in a 

[PATCH] D89065: [clang] Tweaked fixit for static assert with no message

2020-11-25 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89065

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


[PATCH] D91980: [OpenMP] Add initial support for `omp [begin/end] assumes`

2020-11-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:10333
+  /// Check if there is an active global `omp begin assumes` directive.
+  bool isInOpenMPAssumeScope() { return !OMPAssumeScoped.empty(); }
+

ABataev wrote:
> jdoerfert wrote:
> > ABataev wrote:
> > > jdoerfert wrote:
> > > > ABataev wrote:
> > > > > jdoerfert wrote:
> > > > > > ABataev wrote:
> > > > > > > ABataev wrote:
> > > > > > > > `const` member functions.
> > > > > > > It may have side-effects with template instantiations. What if we 
> > > > > > > have something like this:
> > > > > > > ```
> > > > > > > #pragma omp begin assumes ...
> > > > > > > template 
> > > > > > > struct S {
> > > > > > > ...
> > > > > > > }
> > > > > > > #pragma omp end assumes
> > > > > > > 
> > > > > > > void bar() {
> > > > > > > #pragma omp assumes ...
> > > > > > >   {
> > > > > > > S s;
> > > > > > > s.foo();
> > > > > > >   }
> > > > > > > }
> > > > > > > ```
> > > > > > > ?
> > > > > > > 
> > > > > > > `struct S` will be instantiated in the second assume region 
> > > > > > > context though I doubt this is the user intention.
> > > > > > I'm not sure what problem you expect here. Could you elaborate what 
> > > > > > you think should happen or should not?
> > > > > May it lead to the wrong compiler assumptions and result in the 
> > > > > incorrect codegen?
> > > > I'm still not following your example. What wrong assumptions and/or 
> > > > incorrect code generation do you expect? Could you provide an example 
> > > > with actual assumptions and then describe what the problem is please.
> > > Say, you have something like this:
> > > ```
> > > template 
> > > struct S {
> > >   int a;
> > >   void foo() {
> > > #pragma omp parallel
> > > ...
> > >   }
> > > };
> > > 
> > > void bar() {
> > > #pragma omp assumems no_openmp
> > >   S s; // S is instantiated here and function S::foo() 
> > > gets no_openmp attribute.
> > >   s.a = 0; // S::foo is instantiated here but not used and the 
> > > attribute no_openmp should not be propagated for this function.
> > > #pragma omp end assumes
> > > 
> > >   S b; // S already instantiated and S::foo is 
> > > instantiated with attribute no_openmp
> > >   b.foo(); // calls function S::foo with no_openmp attribute.
> > > }
> > > ```
> > > What do you think?
> > Thanks for the extra information. I'll add a test based on this for sure, 
> > no matter what we come up with for now.
> > 
> > ```
> > #pragma omp begin assumes no_openmp
> >   S s; // S is instantiated here and function S::foo() gets 
> > no_openmp attribute.
> >   s.a = 0;
> > #pragma omp end assumes
> > ```
> > 
> > Hm, I guess the question is: 
> > Is `S::foo()` a function defined in between the `begin`/`end` or not. 
> > If we say it is, the behavior right now seems consistent but the standard 
> > might need some clarifications. If we say it is not, we should not annotate 
> > it. Though, if it is not, where is it defined? I could avoid annotating 
> > template instantiations I guess. I might start with that. Update is coming.
> > 
> > 
> Yep, this is what I'm asking about. I would check С++ standard, I believe we 
> shall follow С++ rules here about the instantiation context.
I think the new solution, that is not to use scoped assumptions during template 
instantiations, is a conservative approximation of what people would assume and 
also matches the standard wrt. "defintition-declaration-seq". I included your 
example as a test.

WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91980

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


[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl

2020-11-25 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor requested changes to this revision.
teemperor added a comment.
This revision now requires changes to proceed.

You think it's worth it to have a test for a user-specified deduction guide? I 
think this is missing an 'explicit' deduction guide test, so maybe we could 
test both things in a single additional test case.

Also, IIUC we ignore the IsCopyDeductionCandidate bit when importing and that 
seems like a potential bug to me (the value is apparently used for some 
overload resolution logic)?

Beside those two things this looks good to me.




Comment at: clang/lib/AST/ASTImporter.cpp:3332
 
+  // Common code to import an explicit specifier of different kind of 
funcitons.
+  auto ImportExplicitExpr = [this, ](auto *Fun) -> ExpectedExpr {

typo "funcitons"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92109

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


[PATCH] D92117: [AIX] Enabling vectory types for AIX

2020-11-25 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA created this revision.
ZarkoCA added reviewers: cebowleratibm, sfertile, jasonliu, Xiangling_L, 
hubert.reinterpretcast.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ZarkoCA requested review of this revision.

This patch enables vector types for AIX.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92117

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aix-altivec.c
  clang/test/CodeGen/aix-vector.c

Index: clang/test/CodeGen/aix-vector.c
===
--- clang/test/CodeGen/aix-vector.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// REQUIRES: powerpc-registered-target
-// RUN: not %clang_cc1 -triple powerpc-unknown-aix  -target-feature +altivec \
-// RUN:   -emit-llvm -o - %s 2>&1 | FileCheck %s
-// RUN: not %clang_cc1 -triple powerpc64-unknown-aix  -target-feature +altivec \
-// RUN:   -emit-llvm -o - %s 2>&1 | FileCheck %s
-
-// CHECK: fatal error: error in backend: vector type is not supported on AIX yet
-vector signed int retVector(vector signed int x) {
-  return x;
-}
Index: clang/test/CodeGen/aix-altivec.c
===
--- /dev/null
+++ clang/test/CodeGen/aix-altivec.c
@@ -0,0 +1,44 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-feature +altivec -target-cpu pwr8 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -target-feature +altivec -target-cpu pwr8 -emit-llvm %s -o - | FileCheck %s
+vector float foo1(vector float x) { return x; }
+// CHECK:  define <4 x float> @foo1(<4 x float> %x) #0 {
+// CHECK:  entry:
+// CHECK:%x.addr = alloca <4 x float>, align 16
+// CHECK:store <4 x float> %x, <4 x float>* %x.addr, align 16
+// CHECK:%0 = load <4 x float>, <4 x float>* %x.addr, align 16
+// CHECK:ret <4 x float> %0
+// CHECK:  }
+vector double foo2(vector double x) { return x; }
+// CHECK:  define <2 x double> @foo2(<2 x double> %x) #0 {
+// CHECK:  entry:
+// CHECK:%x.addr = alloca <2 x double>, align 16
+// CHECK:store <2 x double> %x, <2 x double>* %x.addr, align 16
+// CHECK:%0 = load <2 x double>, <2 x double>* %x.addr, align 16
+// CHECK:ret <2 x double> %0
+// CHECK:  }
+vector int foo3(vector int x) { return x; }
+// CHECK:  define <4 x i32> @foo3(<4 x i32> %x) #0 {
+// CHECK:  entry:
+// CHECK:%x.addr = alloca <4 x i32>, align 16
+// CHECK:store <4 x i32> %x, <4 x i32>* %x.addr, align 16
+// CHECK:%0 = load <4 x i32>, <4 x i32>* %x.addr, align 16
+// CHECK:ret <4 x i32> %0
+// CHECK:  }
+vector short int foo4(vector short int x) { return x; }
+// CHECK:  define <8 x i16> @foo4(<8 x i16> %x) #0 {
+// CHECK:  entry:
+// CHECK:%x.addr = alloca <8 x i16>, align 16
+// CHECK:store <8 x i16> %x, <8 x i16>* %x.addr, align 16
+// CHECK:%0 = load <8 x i16>, <8 x i16>* %x.addr, align 16
+// CHECK:ret <8 x i16> %0
+// CHECK:  }
+vector char foo5(vector char x) { return x; }
+// CHECK:  define <16 x i8> @foo5(<16 x i8> %x) #0 {
+// CHECK:  entry:
+// CHECK:%x.addr = alloca <16 x i8>, align 16
+// CHECK:store <16 x i8> %x, <16 x i8>* %x.addr, align 16
+// CHECK:%0 = load <16 x i8>, <16 x i8>* %x.addr, align 16
+// CHECK:ret <16 x i8> %0
+// CHECK:  }
+
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4514,7 +4514,7 @@
 return ABIArgInfo::getDirect();
 
   if (RetTy->isVectorType())
-llvm::report_fatal_error("vector type is not supported on AIX yet");
+return ABIArgInfo::getDirect();
 
   if (RetTy->isVoidType())
 return ABIArgInfo::getIgnore();
@@ -4533,7 +4533,7 @@
 return ABIArgInfo::getDirect();
 
   if (Ty->isVectorType())
-llvm::report_fatal_error("vector type is not supported on AIX yet");
+return ABIArgInfo::getDirect();
 
   if (isAggregateTypeForABI(Ty)) {
 // Records with non-trivial destructors/copy-constructors should not be
@@ -4558,7 +4558,7 @@
 Ty = CTy->getElementType();
 
   if (Ty->isVectorType())
-llvm::report_fatal_error("vector type is not supported on AIX yet");
+return CharUnits::fromQuantity(16);
 
   // If the structure contains a vector type, the alignment is 16.
   if (isRecordWithSIMDVectorType(getContext(), Ty))
@@ -4573,7 +4573,8 @@
 llvm::report_fatal_error("complex type is not supported on AIX yet");
 
   if (Ty->isVectorType())
-llvm::report_fatal_error("vector type is not supported on AIX yet");
+llvm::report_fatal_error(
+"vector types are not yet supported for variadic functions on AIX");
 
   auto TypeInfo = getContext().getTypeInfoInChars(Ty);
   TypeInfo.Align = getParamTypeAlignment(Ty);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92041: [clangd] Add hover info for `this` expr

2020-11-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:610
+/// Generate a \p Hover object given the \p this pointer.
+HoverInfo getHoverContents(const CXXThisExpr *CTE, const SymbolIndex *Index) {
+  const NamedDecl *D = CTE->getType()->getPointeeType()->getAsCXXRecordDecl();

xndcn wrote:
> kadircet wrote:
> > xndcn wrote:
> > > xndcn wrote:
> > > > kadircet wrote:
> > > > > what about using the existing `getHoverContents(QualType ..)` 
> > > > > overload instead ?
> > > > > what about using the existing `getHoverContents(QualType ..)` 
> > > > > overload instead ?
> > > > 
> > > > 
> > > Thanks, I tried using `getHoverContents(QualType ..)` overload and the 
> > > result looks more simplicity:
> > > {F14312230}
> > > 
> > > The origin patch HoverInfo looks like:
> > > {F14312245}
> > > 
> > > Both seems reasonable, not sure which one is better.
> > I am not sure if there's much value in repeating `this` and `type 
> > definition`. So I would go with using the `QualType` overload here.
> > But, rather than providing `CTE->getType()` directly, i believe we should 
> > display information for the `PointeeType`, as it will also display comments 
> > and such for `TagDecls`, rather than just providing the type-name.
> Thanks! It looks more simplicity with `PointeeType`. Shall we keep the 
> additional information like namespace and template parameters? So we can use 
> `getHoverInfo(const NamedDecl ..)` overload?
> {F14313888}
i was thinking those would be just repeating what's already available but you 
seem to be right. especially namespace and template arguments might be useful.



Comment at: clang-tools-extra/clangd/Hover.cpp:631
 
 // Generates hover info for evaluatable expressions.
 // FIXME: Support hover for literals (esp user-defined)

let's update the comment too. "Generates hover info for `this` and evaluatable 
expressions."



Comment at: clang-tools-extra/clangd/Hover.cpp:651
 return HI;
+  } else if (const CXXThisExpr *CTE = dyn_cast(E)) {
+const NamedDecl *D = 
CTE->getType()->getPointeeType()->getAsCXXRecordDecl();

can you put this above `printExprValue`, also the else is unnecessary as branch 
ends with return, i.e:

```
if(thisexpr) {
...
return ..;
}
if(printExprValue..) {
...
return ..;
}
```



Comment at: clang-tools-extra/clangd/Hover.cpp:652
+  } else if (const CXXThisExpr *CTE = dyn_cast(E)) {
+const NamedDecl *D = 
CTE->getType()->getPointeeType()->getAsCXXRecordDecl();
+HI = getHoverContents(D, Index);

s/getAsCXXRecordDecl/getAsTagDecl/



Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:2023
+  {
+  R"cpp(// this expr
+   namespace ns {

can you add two more test cases, one for a template class and one for a 
specialization:

```
template  
struct Foo {
  Foo* bar() { return [[thi^s]]; }
};
template <> 
struct Foo {
  Foo* bar() { return [[thi^s]]; }
};
```


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

https://reviews.llvm.org/D92041

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


[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-25 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Whoops, probably should've updated the summary before pushing, ah well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91029

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


[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-25 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG73fdd998701c: [clangd] Implement clang-tidy options from 
config (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91029

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/TidyProvider.h
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h

Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 
+#include "../TidyProvider.h"
 #include "Compiler.h"
 #include "ParsedAST.h"
 #include "TestFS.h"
@@ -58,8 +59,7 @@
   // Extra arguments for the compiler invocation.
   std::vector ExtraArgs;
 
-  llvm::Optional ClangTidyChecks;
-  llvm::Optional ClangTidyWarningsAsErrors;
+  TidyProvider ClangTidyProvider = {};
   // Index to use when building AST.
   const SymbolIndex *ExternalIndex = nullptr;
 
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -59,8 +59,8 @@
 FS.OverlayRealFileSystemForModules = true;
   Inputs.TFS = 
   Inputs.Opts = ParseOptions();
-  Inputs.Opts.ClangTidyOpts.Checks = ClangTidyChecks;
-  Inputs.Opts.ClangTidyOpts.WarningsAsErrors = ClangTidyWarningsAsErrors;
+  if (ClangTidyProvider)
+Inputs.ClangTidyProvider = ClangTidyProvider;
   Inputs.Index = ExternalIndex;
   if (Inputs.Index)
 Inputs.Opts.SuggestMissingIncludes = true;
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -24,6 +24,7 @@
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "TidyProvider.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
@@ -250,7 +251,7 @@
   TestTU TU;
   // this check runs the preprocessor, we need to make sure it does not break
   // our recording logic.
-  TU.ClangTidyChecks = "modernize-use-trailing-return-type";
+  TU.ClangTidyProvider = addTidyChecks("modernize-use-trailing-return-type");
   TU.Code = "inline int foo() {}";
 
   auto AST = TU.build();
@@ -406,7 +407,7 @@
   "replay-preamble-module", "");
   TestTU TU;
   // This check records inclusion directives replayed by clangd.
-  TU.ClangTidyChecks = "replay-preamble-check";
+  TU.ClangTidyProvider = addTidyChecks("replay-preamble-check");
   llvm::Annotations Test(R"cpp(
 $hash^#$include[[import]] $filebegin^"$filerange[[bar.h]]"
 $hash^#$include[[include_next]] $filebegin^"$filerange[[baz.h]]"
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -14,6 +14,7 @@
 #include "TestFS.h"
 #include "TestIndex.h"
 #include "TestTU.h"
+#include "TidyProvider.h"
 #include "index/MemIndex.h"
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
@@ -129,7 +130,7 @@
 }
   )cpp");
   auto TU = TestTU::withCode(Test.code());
-  TU.ClangTidyChecks = "-*,google-explicit-constructor";
+  TU.ClangTidyProvider = addTidyChecks("google-explicit-constructor");
   EXPECT_THAT(
   TU.build().getDiagnostics(),
   ElementsAre(
@@ -201,8 +202,8 @@
   auto TU = TestTU::withCode(Test.code());
   // Enable alias clang-tidy checks, these check emits the same diagnostics
   // (except the check name).
-  TU.ClangTidyChecks = "-*, readability-uppercase-literal-suffix, "
-   "hicpp-uppercase-literal-suffix";
+  TU.ClangTidyProvider = addTidyChecks("readability-uppercase-literal-suffix,"
+   "hicpp-uppercase-literal-suffix");
   // Verify that we filter out the duplicated diagnostic message.
   EXPECT_THAT(
   TU.build().getDiagnostics(),
@@ -245,9 +246,10 @@
   )cpp");
   auto TU = TestTU::withCode(Test.code());

[clang-tools-extra] 73fdd99 - [clangd] Implement clang-tidy options from config

2020-11-25 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-11-25T18:35:35Z
New Revision: 73fdd998701cce3aa6c4d8d2a73ab97351a0313b

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

LOG: [clangd] Implement clang-tidy options from config

Added some new ClangTidyOptionsProvider like classes designed for clangd work 
flow.
These providers are designed to source the options on the worker thread but in 
a thread safe manner.
This is done through making the options getter take a pointer to the filesystem 
used by the worker thread which natuarally is from a ThreadsafeFS.
Internal caching in the providers is also guarded.

The providers don't inherit from `ClangTidyOptionsProvider` instead they share 
a base class which is able to create a provider for the `ClangTidyContext` 
using a specific FileSystem.
This approach means one provider can be used for multiple contexts even though 
`ClangTidyContext` owns its provider.

Depends on D90531

Reviewed By: sammccall

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

Added: 
clang-tools-extra/clangd/TidyProvider.cpp
clang-tools-extra/clangd/TidyProvider.h

Modified: 
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Compiler.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/tool/Check.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/ClangdTests.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp
clang-tools-extra/clangd/unittests/TestTU.h

Removed: 




diff  --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index 2ce5d31e623e..919457f216c1 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -81,6 +81,7 @@ add_clang_library(clangDaemon
   SemanticSelection.cpp
   SourceCode.cpp
   QueryDriverDatabase.cpp
+  TidyProvider.cpp
   TUScheduler.cpp
   URI.cpp
   XRefs.cpp

diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 502078c776db..aa19a9485e17 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -114,40 +114,6 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
   bool TheiaSemanticHighlighting;
 };
 
-// Set of clang-tidy checks that don't work well in clangd, either due to
-// crashes or false positives.
-// Returns a clang-tidy filter string: -check1,-check2.
-llvm::StringRef getUnusableTidyChecks() {
-  static const std::string FalsePositives =
-  llvm::join_items(", ",
-   // Check relies on seeing ifndef/define/endif 
directives,
-   // clangd doesn't replay those when using a preamble.
-   "-llvm-header-guard");
-  static const std::string CrashingChecks =
-  llvm::join_items(", ",
-   // Check can choke on invalid (intermediate) c++ code,
-   // which is often the case when clangd tries to build an
-   // AST.
-   "-bugprone-use-after-move");
-  static const std::string UnusableTidyChecks =
-  llvm::join_items(", ", FalsePositives, CrashingChecks);
-  return UnusableTidyChecks;
-}
-
-// Returns a clang-tidy options string: check1,check2.
-llvm::StringRef getDefaultTidyChecks() {
-  // These default checks are chosen for:
-  //  - low false-positive rate
-  //  - providing a lot of value
-  //  - being reasonably efficient
-  static const std::string DefaultChecks = llvm::join_items(
-  ",", "readability-misleading-indentation", "readability-deleted-default",
-  "bugprone-integer-division", "bugprone-sizeof-expression",
-  "bugprone-suspicious-missing-comma", "bugprone-unused-raii",
-  "bugprone-unused-return-value", "misc-unused-using-decls",
-  "misc-unused-alias-decls", "misc-definitions-in-headers");
-  return DefaultChecks;
-}
 } // namespace
 
 ClangdServer::Options ClangdServer::optsForTest() {
@@ -178,7 +144,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase 
,
  ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex,
  Opts.CollectMainFileRefs)
  : nullptr),
-  GetClangTidyOptions(Opts.GetClangTidyOptions),
+  ClangTidyProvider(Opts.ClangTidyProvider),
   SuggestMissingIncludes(Opts.SuggestMissingIncludes),
   BuildRecoveryAST(Opts.BuildRecoveryAST),
   PreserveRecoveryASTType(Opts.PreserveRecoveryASTType),
@@ -236,20 +202,6 @@ void ClangdServer::addDocument(PathRef File, 

[PATCH] D92115: AMDGPU - Add diagnostic for compiling modules with AMD HSA OS type and GFX 6 arch

2020-11-25 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added a comment.

You need to add a new test for this new error.




Comment at: llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp:134
+  if (isAmdHsaOS() && getGeneration() == AMDGPUSubtarget::SOUTHERN_ISLANDS) {
+report_fatal_error("GFX6 (SI) ASICs does not support AMD HSA OS type \n",
+   false);

"do not support". I would also drop "(SI)" from the message. Maybe even better 
just "GFX6 does not support AMD HSA".



Comment at: llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp:201
+  TargetTriple(TT), Gen(initializeGen(TT, GPU)),
+  InstrItins(getInstrItineraryForCPU(GPU)), LDSBankCount(0),
+  MaxPrivateElementSize(0),

Please keep original formatting.



Comment at: llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll:1
-; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx600 < %s | FileCheck 
--check-prefixes=GFX600 %s
-; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=tahiti < %s | FileCheck 
--check-prefixes=GFX600 %s

You probably just need to change triple for these targets, not just drop them 
from the test.



Comment at: llvm/test/CodeGen/AMDGPU/lower-kernargs-si-mesa.ll:2
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; FIXME: Manually added checks for metadata nodes at bottom
+; RUN: opt -mtriple=amdgcn-- -S -o - -amdgpu-lower-kernel-arguments %s | 
FileCheck -check-prefix=MESA %s

There are no such checks?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92115

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


[PATCH] D92115: AMDGPU - Add diagnostic for compiling modules with AMD HSA OS type and GFX 6 arch

2020-11-25 Thread praveen velliengiri via Phabricator via cfe-commits
pvellien created this revision.
pvellien added reviewers: rampitec, arsenm, sameerds.
Herald added subscribers: llvm-commits, cfe-commits, kerbowa, jfb, hiraditya, 
t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl.
Herald added projects: clang, LLVM.
pvellien requested review of this revision.
Herald added a subscriber: wdng.

Bail out from compiling modules for GFX6 + AMD HSA OS type as HSA is not 
supported for SI ASICs. Currently gfx6+hsa setup crashing during ISel for 
global load/stores due to lack of FLAT instructions. This patch add a check to 
report error when modules are compiled with -mtriple=amdgcn-amd-amdhsa 
-mcpu=gfx600 and exit from compilation pipeline.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92115

Files:
  clang/test/CodeGenOpenCL/amdgpu-attrs.cl
  llvm/docs/AMDGPUUsage.rst
  llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp
  llvm/test/Analysis/DivergenceAnalysis/AMDGPU/inline-asm.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-and.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-or.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-xor.mir
  llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
  llvm/test/CodeGen/AMDGPU/flat-error-unsupported-gpu-hsa.ll
  llvm/test/CodeGen/AMDGPU/lower-kernargs-si-mesa.ll
  llvm/test/CodeGen/AMDGPU/lower-kernargs.ll

Index: llvm/test/CodeGen/AMDGPU/lower-kernargs.ll
===
--- llvm/test/CodeGen/AMDGPU/lower-kernargs.ll
+++ llvm/test/CodeGen/AMDGPU/lower-kernargs.ll
@@ -530,24 +530,6 @@
   ret void
 }
 
-define amdgpu_kernel void @kern_lds_ptr_si(i32 addrspace(3)* %lds) #2 {
-; HSA-LABEL: @kern_lds_ptr_si(
-; HSA-NEXT:[[KERN_LDS_PTR_SI_KERNARG_SEGMENT:%.*]] = call nonnull align 16 dereferenceable(8) i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr()
-; HSA-NEXT:[[LDS_KERNARG_OFFSET:%.*]] = getelementptr inbounds i8, i8 addrspace(4)* [[KERN_LDS_PTR_SI_KERNARG_SEGMENT]], i64 0
-; HSA-NEXT:[[LDS_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[LDS_KERNARG_OFFSET]] to i32 addrspace(3)* addrspace(4)*
-; HSA-NEXT:[[LDS_LOAD:%.*]] = load i32 addrspace(3)*, i32 addrspace(3)* addrspace(4)* [[LDS_KERNARG_OFFSET_CAST]], align 16, !invariant.load !0
-; HSA-NEXT:store i32 0, i32 addrspace(3)* [[LDS_LOAD]], align 4
-; HSA-NEXT:ret void
-;
-; MESA-LABEL: @kern_lds_ptr_si(
-; MESA-NEXT:[[KERN_LDS_PTR_SI_KERNARG_SEGMENT:%.*]] = call nonnull align 16 dereferenceable(44) i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr()
-; MESA-NEXT:store i32 0, i32 addrspace(3)* [[LDS:%.*]], align 4
-; MESA-NEXT:ret void
-;
-  store i32 0, i32 addrspace(3)* %lds, align 4
-  ret void
-}
-
 define amdgpu_kernel void @kern_realign_i8_i8(i8 %arg0, i8 %arg1) #0 {
 ; HSA-LABEL: @kern_realign_i8_i8(
 ; HSA-NEXT:[[KERN_REALIGN_I8_I8_KERNARG_SEGMENT:%.*]] = call nonnull align 16 dereferenceable(4) i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr()
@@ -1914,7 +1896,6 @@
 
 attributes #0 = { nounwind "target-cpu"="kaveri" }
 attributes #1 = { nounwind "target-cpu"="kaveri" "amdgpu-implicitarg-num-bytes"="40" }
-attributes #2 = { nounwind "target-cpu"="tahiti" }
 
 ; GCN: 0 = !{}
 ; GCN: !1 = !{i64 42}
Index: llvm/test/CodeGen/AMDGPU/lower-kernargs-si-mesa.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/lower-kernargs-si-mesa.ll
@@ -0,0 +1,17 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; FIXME: Manually added checks for metadata nodes at bottom
+; RUN: opt -mtriple=amdgcn-- -S -o - -amdgpu-lower-kernel-arguments %s | FileCheck -check-prefix=MESA %s
+
+target datalayout = "A5"
+
+define amdgpu_kernel void @kern_lds_ptr_si(i32 addrspace(3)* %lds) #0 {
+; MESA-LABEL: @kern_lds_ptr_si(
+; MESA-NEXT:[[KERN_LDS_PTR_SI_KERNARG_SEGMENT:%.*]] = call nonnull align 16 dereferenceable(44) i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr()
+; MESA-NEXT:store i32 0, i32 addrspace(3)* [[LDS:%.*]], align 4
+; MESA-NEXT:ret void
+;
+  store i32 0, i32 addrspace(3)* %lds, align 4
+  ret void
+}
+
+attributes #0 = { nounwind "target-cpu"="tahiti" }
Index: llvm/test/CodeGen/AMDGPU/flat-error-unsupported-gpu-hsa.ll
===
--- llvm/test/CodeGen/AMDGPU/flat-error-unsupported-gpu-hsa.ll
+++ llvm/test/CodeGen/AMDGPU/flat-error-unsupported-gpu-hsa.ll
@@ -1,4 +1,3 @@
-; RUN: not --crash llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx600 -filetype=obj -o /dev/null %s 2>&1 | FileCheck -check-prefix=ERROR %s
 ; RUN: not --crash llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx600 -filetype=obj -o /dev/null %s 2>&1 | FileCheck -check-prefix=ERROR %s
 
 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -o - %s | FileCheck -check-prefix=HSA-DEFAULT %s
Index: llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
===
--- llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
+++ 

[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

Hooray, ship it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91029

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


[PATCH] D91495: [clang-tidy] false-positive for bugprone-redundant-branch-condition in case of passed-by-ref params

2020-11-25 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 307646.
zinovy.nis added a comment.

Handle ref & val mixed cases.


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

https://reviews.llvm.org/D91495

Files:
  clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
@@ -6,7 +6,8 @@
 bool isBurning();
 bool isReallyBurning();
 bool isCollapsing();
-void tryToExtinguish(bool&);
+bool tryToExtinguish(bool&);
+bool tryToExtinguishByVal(bool);
 void tryPutFireOut();
 bool callTheFD();
 void scream();
@@ -948,6 +949,30 @@
   }
 }
 
+void negative_by_ref(bool onFire) {
+  if (tryToExtinguish(onFire) && onFire) {
+if (tryToExtinguish(onFire) && onFire) {
+  // NO-MESSAGE: fire may have been extinguished
+  scream();
+}
+  }
+}
+
+void negative_by_val(bool onFire) {
+  if (tryToExtinguishByVal(onFire) && onFire) {
+if (tryToExtinguish(onFire) && onFire) {
+  // NO-MESSAGE: fire may have been extinguished
+  scream();
+}
+  }
+  if (tryToExtinguish(onFire) && onFire) {
+if (tryToExtinguishByVal(onFire) && onFire) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'onFire' [bugprone-redundant-branch-condition]
+  scream();
+}
+  }
+}
+
 void negative_reassigned() {
   bool onFire = isBurning();
   if (onFire) {
@@ -1077,9 +1102,9 @@
 int positive_expr_with_cleanups() {
   class RetT {
   public:
-RetT(const int _code) : code_(_code) {}
-bool Ok() const { return code_ == 0; }
-static RetT Test(bool &_isSet) { return 0; }
+RetT(const int code);
+bool Ok() const;
+static RetT Test(bool isSet);
 
   private:
 int code_;
Index: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -23,15 +23,23 @@
 static const char CondVarStr[] = "cond_var";
 static const char OuterIfStr[] = "outer_if";
 static const char InnerIfStr[] = "inner_if";
+static const char OuterIfVar1Str[] = "outer_if_var1";
+static const char OuterIfVar2Str[] = "outer_if_var2";
+static const char InnerIfVar1Str[] = "inner_if_var1";
+static const char InnerIfVar2Str[] = "inner_if_var2";
 static const char FuncStr[] = "func";
 
 /// Returns whether `Var` is changed in `S` before `NextS`.
-static bool isChangedBefore(const Stmt *S, const Stmt *NextS,
+static bool isChangedBefore(const Stmt *S, const Stmt *NextS, const Stmt *PrevS,
 const VarDecl *Var, ASTContext *Context) {
   ExprMutationAnalyzer MutAn(*S, *Context);
   const auto  = Context->getSourceManager();
   const Stmt *MutS = MutAn.findMutation(Var);
+
+  // Check if PrevS < Mut < NextS
   return MutS &&
+ SM.isBeforeInTranslationUnit(PrevS->getEndLoc(),
+  MutS->getBeginLoc()) &&
  SM.isBeforeInTranslationUnit(MutS->getEndLoc(), NextS->getBeginLoc());
 }
 
@@ -43,19 +51,21 @@
   Finder->addMatcher(
   ifStmt(
   hasCondition(ignoringParenImpCasts(anyOf(
-  declRefExpr(hasDeclaration(ImmutableVar)),
+  declRefExpr(hasDeclaration(ImmutableVar)).bind(OuterIfVar1Str),
   binaryOperator(hasOperatorName("&&"),
- hasEitherOperand(ignoringParenImpCasts(declRefExpr(
- hasDeclaration(ImmutableVar,
+ hasEitherOperand(ignoringParenImpCasts(declRefExpr(hasDeclaration(ImmutableVar))
+.bind(OuterIfVar2Str))),
   hasThen(hasDescendant(
   ifStmt(hasCondition(ignoringParenImpCasts(
- anyOf(declRefExpr(hasDeclaration(
-   varDecl(equalsBoundNode(CondVarStr,
+ anyOf(declRefExpr(hasDeclaration(varDecl(
+equalsBoundNode(CondVarStr
+.bind(InnerIfVar1Str),
binaryOperator(
hasAnyOperatorName("&&", "||"),
hasEitherOperand(ignoringParenImpCasts(
declRefExpr(hasDeclaration(varDecl(
-   equalsBoundNode(CondVarStr)))
+ equalsBoundNode(CondVarStr
+ 

[PATCH] D92080: [Clang] Mutate long-double math builtins into f128 under IEEE-quad

2020-11-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

gcc calls the *l version with -mlong-double-128 on x86. Should we match gcc 
here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92080

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


[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-25 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 307642.
njames93 added a comment.

Removed CWD references.
Added some fixme comments about function_ref<->unique_function and null values.
Added asserts in provideClangTidyFiles ensuring path is absolute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91029

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/TidyProvider.h
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h

Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 
+#include "../TidyProvider.h"
 #include "Compiler.h"
 #include "ParsedAST.h"
 #include "TestFS.h"
@@ -58,8 +59,7 @@
   // Extra arguments for the compiler invocation.
   std::vector ExtraArgs;
 
-  llvm::Optional ClangTidyChecks;
-  llvm::Optional ClangTidyWarningsAsErrors;
+  TidyProvider ClangTidyProvider = {};
   // Index to use when building AST.
   const SymbolIndex *ExternalIndex = nullptr;
 
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -59,8 +59,8 @@
 FS.OverlayRealFileSystemForModules = true;
   Inputs.TFS = 
   Inputs.Opts = ParseOptions();
-  Inputs.Opts.ClangTidyOpts.Checks = ClangTidyChecks;
-  Inputs.Opts.ClangTidyOpts.WarningsAsErrors = ClangTidyWarningsAsErrors;
+  if (ClangTidyProvider)
+Inputs.ClangTidyProvider = ClangTidyProvider;
   Inputs.Index = ExternalIndex;
   if (Inputs.Index)
 Inputs.Opts.SuggestMissingIncludes = true;
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -24,6 +24,7 @@
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "TidyProvider.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
@@ -250,7 +251,7 @@
   TestTU TU;
   // this check runs the preprocessor, we need to make sure it does not break
   // our recording logic.
-  TU.ClangTidyChecks = "modernize-use-trailing-return-type";
+  TU.ClangTidyProvider = addTidyChecks("modernize-use-trailing-return-type");
   TU.Code = "inline int foo() {}";
 
   auto AST = TU.build();
@@ -406,7 +407,7 @@
   "replay-preamble-module", "");
   TestTU TU;
   // This check records inclusion directives replayed by clangd.
-  TU.ClangTidyChecks = "replay-preamble-check";
+  TU.ClangTidyProvider = addTidyChecks("replay-preamble-check");
   llvm::Annotations Test(R"cpp(
 $hash^#$include[[import]] $filebegin^"$filerange[[bar.h]]"
 $hash^#$include[[include_next]] $filebegin^"$filerange[[baz.h]]"
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -14,6 +14,7 @@
 #include "TestFS.h"
 #include "TestIndex.h"
 #include "TestTU.h"
+#include "TidyProvider.h"
 #include "index/MemIndex.h"
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
@@ -129,7 +130,7 @@
 }
   )cpp");
   auto TU = TestTU::withCode(Test.code());
-  TU.ClangTidyChecks = "-*,google-explicit-constructor";
+  TU.ClangTidyProvider = addTidyChecks("google-explicit-constructor");
   EXPECT_THAT(
   TU.build().getDiagnostics(),
   ElementsAre(
@@ -201,8 +202,8 @@
   auto TU = TestTU::withCode(Test.code());
   // Enable alias clang-tidy checks, these check emits the same diagnostics
   // (except the check name).
-  TU.ClangTidyChecks = "-*, readability-uppercase-literal-suffix, "
-   "hicpp-uppercase-literal-suffix";
+  TU.ClangTidyProvider = addTidyChecks("readability-uppercase-literal-suffix,"
+   "hicpp-uppercase-literal-suffix");
   // Verify that we filter out the duplicated diagnostic message.
   EXPECT_THAT(
   TU.build().getDiagnostics(),
@@ -245,9 

[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl

2020-11-25 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: teemperor, shafik, balazske.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a project: clang.
martong requested review of this revision.

CXXDeductionGuideDecl is a FunctionDecl, but its constructor should be called
appropriately, at least to set the kind variable properly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92109

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5884,6 +5884,21 @@
   EXPECT_EQ(Record, CompletedTags.front());
 }
 
+TEST_P(ImportFunctions, CTAD) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  template  struct A {
+A(T);
+  };
+  A a{(int)0};
+  )",
+  Lang_CXX17, "input.cc");
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, cxxDeductionGuideDecl());
+  auto *ToD = Import(FromD, Lang_CXX17);
+  ASSERT_TRUE(ToD);
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -499,6 +499,7 @@
 ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D);
 ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D);
 ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D);
+ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D);
 ExpectedDecl VisitFieldDecl(FieldDecl *D);
 ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D);
 ExpectedDecl VisitFriendDecl(FriendDecl *D);
@@ -3328,6 +3329,17 @@
   return ToPOrErr.takeError();
   }
 
+  // Common code to import an explicit specifier of different kind of funcitons.
+  auto ImportExplicitExpr = [this, ](auto *Fun) -> ExpectedExpr {
+Expr *ExplicitExpr = nullptr;
+if (Fun->getExplicitSpecifier().getExpr()) {
+  ExplicitExpr = importChecked(Err, Fun->getExplicitSpecifier().getExpr());
+  if (Err)
+return std::move(Err);
+}
+return ExplicitExpr;
+  };
+
   // Create the imported function.
   FunctionDecl *ToFunction = nullptr;
   if (auto *FromConstructor = dyn_cast(D)) {
@@ -3369,17 +3381,13 @@
 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
   } else if (CXXConversionDecl *FromConversion =
  dyn_cast(D)) {
-Expr *ExplicitExpr = nullptr;
-if (FromConversion->getExplicitSpecifier().getExpr()) {
-  auto Imp = import(FromConversion->getExplicitSpecifier().getExpr());
-  if (!Imp)
-return Imp.takeError();
-  ExplicitExpr = *Imp;
-}
+ExpectedExpr ExplicitExpr = ImportExplicitExpr(FromConversion);
+if (!ExplicitExpr)
+  return ExplicitExpr.takeError();
 if (GetImportedOrCreateDecl(
 ToFunction, D, Importer.getToContext(), cast(DC),
 ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(),
-ExplicitSpecifier(ExplicitExpr,
+ExplicitSpecifier(*ExplicitExpr,
   FromConversion->getExplicitSpecifier().getKind()),
 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
   return ToFunction;
@@ -3390,6 +3398,16 @@
 Method->isInlineSpecified(), D->getConstexprKind(),
 SourceLocation(), TrailingRequiresClause))
   return ToFunction;
+  } else if (auto *Guide = dyn_cast(D)) {
+ExpectedExpr ExplicitExpr = ImportExplicitExpr(Guide);
+if (!ExplicitExpr)
+  return ExplicitExpr.takeError();
+if (GetImportedOrCreateDecl(
+ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
+ExplicitSpecifier(*ExplicitExpr,
+  Guide->getExplicitSpecifier().getKind()),
+NameInfo, T, TInfo, ToEndLoc))
+  return ToFunction;
   } else {
 if (GetImportedOrCreateDecl(
 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
@@ -3517,6 +3535,11 @@
   return VisitCXXMethodDecl(D);
 }
 
+ExpectedDecl
+ASTNodeImporter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
+  return VisitFunctionDecl(D);
+}
+
 ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
   // Import the major distinguishing characteristics of a variable.
   DeclContext *DC, *LexicalDC;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92108: Fix inconsistent availability attribute message string literal check.

2020-11-25 Thread Nigel Perks via Phabricator via cfe-commits
nigelp-xmos updated this revision to Diff 307638.
nigelp-xmos added a comment.

Run clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92108

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/test/Parser/attr-availability-xcore.c
  clang/test/Parser/attr-availability.c


Index: clang/test/Parser/attr-availability.c
===
--- clang/test/Parser/attr-availability.c
+++ clang/test/Parser/attr-availability.c
@@ -22,6 +22,14 @@
 
 void f8() __attribute__((availability(macosx,message="a" L"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
 
+void f9() __attribute__((availability(macosx,message=u8"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f10() __attribute__((availability(macosx,message="a" u8"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f11() __attribute__((availability(macosx,message=u"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f12() __attribute__((availability(macosx,message="a" u"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
 // rdar://10095131
 enum E{
 gorf __attribute__((availability(macosx,introduced=8.5, message = 10.0))), 
// expected-error {{expected string literal for optional message in 
'availability' attribute}}
Index: clang/test/Parser/attr-availability-xcore.c
===
--- /dev/null
+++ clang/test/Parser/attr-availability-xcore.c
@@ -0,0 +1,11 @@
+// Test availability message string type when wide characters are 1 byte.
+// REQUIRES: xcore-registered-target
+// RUN: %clang_cc1 -triple xcore -fsyntax-only -verify %s
+
+#if !__has_feature(attribute_availability)
+#  error 'availability' attribute is not available
+#endif
+
+void f7() __attribute__((availability(macosx,message=L"wide"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f8() __attribute__((availability(macosx,message="a" L"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1118,7 +1118,7 @@
   // Also reject wide string literals.
   if (StringLiteral *MessageStringLiteral =
   cast_or_null(MessageExpr.get())) {
-if (MessageStringLiteral->getCharByteWidth() != 1) {
+if (!MessageStringLiteral->isAscii()) {
   Diag(MessageStringLiteral->getSourceRange().getBegin(),
diag::err_expected_string_literal)
 << /*Source='availability attribute'*/ 2;


Index: clang/test/Parser/attr-availability.c
===
--- clang/test/Parser/attr-availability.c
+++ clang/test/Parser/attr-availability.c
@@ -22,6 +22,14 @@
 
 void f8() __attribute__((availability(macosx,message="a" L"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
 
+void f9() __attribute__((availability(macosx,message=u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f10() __attribute__((availability(macosx,message="a" u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f11() __attribute__((availability(macosx,message=u"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f12() __attribute__((availability(macosx,message="a" u"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
 // rdar://10095131
 enum E{
 gorf __attribute__((availability(macosx,introduced=8.5, message = 10.0))), // expected-error {{expected string literal for optional message in 'availability' attribute}}
Index: clang/test/Parser/attr-availability-xcore.c
===
--- /dev/null
+++ clang/test/Parser/attr-availability-xcore.c
@@ -0,0 +1,11 @@
+// Test availability message string type when wide characters are 1 byte.
+// REQUIRES: xcore-registered-target
+// RUN: %clang_cc1 -triple xcore -fsyntax-only -verify %s
+
+#if !__has_feature(attribute_availability)
+#  error 'availability' attribute is not available
+#endif
+
+void f7() __attribute__((availability(macosx,message=L"wide"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f8() __attribute__((availability(macosx,message="a" L"b"))); // 

[PATCH] D92108: Fix inconsistent availability attribute message string literal check.

2020-11-25 Thread Nigel Perks via Phabricator via cfe-commits
nigelp-xmos updated this revision to Diff 307636.
nigelp-xmos added a comment.

Run clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92108

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/test/Parser/attr-availability-xcore.c
  clang/test/Parser/attr-availability.c


Index: clang/test/Parser/attr-availability.c
===
--- clang/test/Parser/attr-availability.c
+++ clang/test/Parser/attr-availability.c
@@ -22,6 +22,14 @@
 
 void f8() __attribute__((availability(macosx,message="a" L"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
 
+void f9() __attribute__((availability(macosx,message=u8"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f10() __attribute__((availability(macosx,message="a" u8"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f11() __attribute__((availability(macosx,message=u"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f12() __attribute__((availability(macosx,message="a" u"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
 // rdar://10095131
 enum E{
 gorf __attribute__((availability(macosx,introduced=8.5, message = 10.0))), 
// expected-error {{expected string literal for optional message in 
'availability' attribute}}
Index: clang/test/Parser/attr-availability-xcore.c
===
--- /dev/null
+++ clang/test/Parser/attr-availability-xcore.c
@@ -0,0 +1,11 @@
+// Test availability message string type when wide characters are 1 byte.
+// REQUIRES: xcore-registered-target
+// RUN: %clang_cc1 -triple xcore -fsyntax-only -verify %s
+
+#if !__has_feature(attribute_availability)
+#  error 'availability' attribute is not available
+#endif
+
+void f7() __attribute__((availability(macosx,message=L"wide"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f8() __attribute__((availability(macosx,message="a" L"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1118,7 +1118,7 @@
   // Also reject wide string literals.
   if (StringLiteral *MessageStringLiteral =
   cast_or_null(MessageExpr.get())) {
-if (MessageStringLiteral->getCharByteWidth() != 1) {
+if (!MessageStringLiteral->isAscii()) {
   Diag(MessageStringLiteral->getSourceRange().getBegin(),
diag::err_expected_string_literal)
 << /*Source='availability attribute'*/ 2;


Index: clang/test/Parser/attr-availability.c
===
--- clang/test/Parser/attr-availability.c
+++ clang/test/Parser/attr-availability.c
@@ -22,6 +22,14 @@
 
 void f8() __attribute__((availability(macosx,message="a" L"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
 
+void f9() __attribute__((availability(macosx,message=u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f10() __attribute__((availability(macosx,message="a" u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f11() __attribute__((availability(macosx,message=u"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f12() __attribute__((availability(macosx,message="a" u"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
 // rdar://10095131
 enum E{
 gorf __attribute__((availability(macosx,introduced=8.5, message = 10.0))), // expected-error {{expected string literal for optional message in 'availability' attribute}}
Index: clang/test/Parser/attr-availability-xcore.c
===
--- /dev/null
+++ clang/test/Parser/attr-availability-xcore.c
@@ -0,0 +1,11 @@
+// Test availability message string type when wide characters are 1 byte.
+// REQUIRES: xcore-registered-target
+// RUN: %clang_cc1 -triple xcore -fsyntax-only -verify %s
+
+#if !__has_feature(attribute_availability)
+#  error 'availability' attribute is not available
+#endif
+
+void f7() __attribute__((availability(macosx,message=L"wide"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f8() __attribute__((availability(macosx,message="a" L"b"))); // 

[PATCH] D89031: [SVE] Add support to vectorize_width loop pragma for scalable vectors

2020-11-25 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

Thanks @david-arm for posting this proposal to the cfe list.
My confusion has been cleared up. The (new) proposal is to have:

1. vectorize_width(X) where X is an integer.
2. vectorize_width(X, fixed|scalable)
3. vectorize_width(fixed|scalable)

And with that 3rd option I agree that this allows us to express everything we 
want, and this patch needs adapting to this new proposal (just stating the 
obvious for clarity/completeness)

If scalable is used on a target that doesn't support this, a warning and 
falling back to fixed seems like the right thing to do.

I did have concerns about this, similarly like @fhahn:

> Hm, I am just a bit worried that it might be a bit confusing to users that do 
> not know what scalable vectors are (it is obvious when knowing all about SVE, 
> but I would assume most people don't necessarily know what this means). I 
> guess that is not the biggest deal, as long vectorize_width(X, scalable) 
> works for every target.

But since the new scalable option is opt-in, people don't need know about this 
if they don't want/need to, this should (hopefully) not be the case.


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

https://reviews.llvm.org/D89031

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


[PATCH] D89528: [clang][test] Fix prefix operator++ signature in iterators

2020-11-25 Thread Endre Fülöp via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdc96cc33c13e: [clang][test] Fix prefix operator++ signature 
in iterators (authored by gamesh411).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89528

Files:
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h


Index: clang/test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -46,7 +46,7 @@
 
   __vector_iterator(const Ptr p = 0) : ptr(p) {}
   __vector_iterator(const iterator ): ptr(rhs.base()) {}
-  __vector_iterator operator++() { ++ ptr; return *this; }
+  __vector_iterator& operator++() { ++ ptr; return *this; }
   __vector_iterator operator++(int) {
 auto tmp = *this;
 ++ ptr;
@@ -109,7 +109,7 @@
 
   __deque_iterator(const Ptr p = 0) : ptr(p) {}
   __deque_iterator(const iterator ): ptr(rhs.base()) {}
-  __deque_iterator operator++() { ++ ptr; return *this; }
+  __deque_iterator& operator++() { ++ ptr; return *this; }
   __deque_iterator operator++(int) {
 auto tmp = *this;
 ++ ptr;
@@ -169,7 +169,7 @@
 
   __list_iterator(T* it = 0) : item(it) {}
   __list_iterator(const iterator ): item(rhs.item) {}
-  __list_iterator operator++() { item = item->next; return *this; 
}
+  __list_iterator& operator++() { item = item->next; return 
*this; }
   __list_iterator operator++(int) {
 auto tmp = *this;
 item = item->next;
@@ -212,7 +212,7 @@
 
   __fwdl_iterator(T* it = 0) : item(it) {}
   __fwdl_iterator(const iterator ): item(rhs.item) {}
-  __fwdl_iterator operator++() { item = item->next; return *this; 
}
+  __fwdl_iterator& operator++() { item = item->next; return 
*this; }
   __fwdl_iterator operator++(int) {
 auto tmp = *this;
 item = item->next;
@@ -1079,7 +1079,7 @@
 class iterator {
 public:
   iterator(Key *key): ptr(key) {}
-  iterator operator++() { ++ptr; return *this; }
+  iterator& operator++() { ++ptr; return *this; }
   bool operator!=(const iterator ) const { return ptr != other.ptr; }
   const Key *() const { return *ptr; }
 private:
@@ -1104,7 +1104,7 @@
 class iterator {
 public:
   iterator(Key *key): ptr(key) {}
-  iterator operator++() { ++ptr; return *this; }
+  iterator& operator++() { ++ptr; return *this; }
   bool operator!=(const iterator ) const { return ptr != other.ptr; }
   const Key *() const { return *ptr; }
 private:


Index: clang/test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -46,7 +46,7 @@
 
   __vector_iterator(const Ptr p = 0) : ptr(p) {}
   __vector_iterator(const iterator ): ptr(rhs.base()) {}
-  __vector_iterator operator++() { ++ ptr; return *this; }
+  __vector_iterator& operator++() { ++ ptr; return *this; }
   __vector_iterator operator++(int) {
 auto tmp = *this;
 ++ ptr;
@@ -109,7 +109,7 @@
 
   __deque_iterator(const Ptr p = 0) : ptr(p) {}
   __deque_iterator(const iterator ): ptr(rhs.base()) {}
-  __deque_iterator operator++() { ++ ptr; return *this; }
+  __deque_iterator& operator++() { ++ ptr; return *this; }
   __deque_iterator operator++(int) {
 auto tmp = *this;
 ++ ptr;
@@ -169,7 +169,7 @@
 
   __list_iterator(T* it = 0) : item(it) {}
   __list_iterator(const iterator ): item(rhs.item) {}
-  __list_iterator operator++() { item = item->next; return *this; }
+  __list_iterator& operator++() { item = item->next; return *this; }
   __list_iterator operator++(int) {
 auto tmp = *this;
 item = item->next;
@@ -212,7 +212,7 @@
 
   __fwdl_iterator(T* it = 0) : item(it) {}
   __fwdl_iterator(const iterator ): item(rhs.item) {}
-  __fwdl_iterator operator++() { item = item->next; return *this; }
+  __fwdl_iterator& operator++() { item = item->next; return *this; }
   __fwdl_iterator operator++(int) {
 auto tmp = *this;
 item = item->next;
@@ -1079,7 +1079,7 @@
 class iterator {
 public:
   iterator(Key *key): ptr(key) {}
-  iterator operator++() { ++ptr; return *this; }
+  iterator& operator++() { ++ptr; return *this; }
   bool operator!=(const iterator ) const { return ptr != other.ptr; }
   const Key *() const { return *ptr; }
 private:
@@ -1104,7 +1104,7 @@
 class iterator {
 public:
   iterator(Key *key): ptr(key) {}
-  iterator operator++() { ++ptr; return *this; }
+  iterator& operator++() { ++ptr; return *this; }
   bool operator!=(const iterator ) const { return ptr != other.ptr; }
   const Key *() const { return *ptr; }
 private:
___
cfe-commits mailing 

[clang] dc96cc3 - [clang][test] Fix prefix operator++ signature in iterators

2020-11-25 Thread Endre Fülöp via cfe-commits

Author: Endre Fülöp
Date: 2020-11-25T18:05:11+01:00
New Revision: dc96cc33c13e1e38382118c25bf26de480eb2b12

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

LOG: [clang][test] Fix prefix operator++ signature in iterators

Prefix operator++ should return the iterator incremented by reference.

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

Added: 


Modified: 
clang/test/Analysis/Inputs/system-header-simulator-cxx.h

Removed: 




diff  --git a/clang/test/Analysis/Inputs/system-header-simulator-cxx.h 
b/clang/test/Analysis/Inputs/system-header-simulator-cxx.h
index f2b148cbc692..87984d02c2f6 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -46,7 +46,7 @@ template  struct 
__vector_iterator {
 
   __vector_iterator(const Ptr p = 0) : ptr(p) {}
   __vector_iterator(const iterator ): ptr(rhs.base()) {}
-  __vector_iterator operator++() { ++ ptr; return *this; }
+  __vector_iterator& operator++() { ++ ptr; return *this; }
   __vector_iterator operator++(int) {
 auto tmp = *this;
 ++ ptr;
@@ -109,7 +109,7 @@ template  struct 
__deque_iterator {
 
   __deque_iterator(const Ptr p = 0) : ptr(p) {}
   __deque_iterator(const iterator ): ptr(rhs.base()) {}
-  __deque_iterator operator++() { ++ ptr; return *this; }
+  __deque_iterator& operator++() { ++ ptr; return *this; }
   __deque_iterator operator++(int) {
 auto tmp = *this;
 ++ ptr;
@@ -169,7 +169,7 @@ template  struct 
__list_iterator {
 
   __list_iterator(T* it = 0) : item(it) {}
   __list_iterator(const iterator ): item(rhs.item) {}
-  __list_iterator operator++() { item = item->next; return *this; 
}
+  __list_iterator& operator++() { item = item->next; return 
*this; }
   __list_iterator operator++(int) {
 auto tmp = *this;
 item = item->next;
@@ -212,7 +212,7 @@ template  struct 
__fwdl_iterator {
 
   __fwdl_iterator(T* it = 0) : item(it) {}
   __fwdl_iterator(const iterator ): item(rhs.item) {}
-  __fwdl_iterator operator++() { item = item->next; return *this; 
}
+  __fwdl_iterator& operator++() { item = item->next; return 
*this; }
   __fwdl_iterator operator++(int) {
 auto tmp = *this;
 item = item->next;
@@ -1079,7 +1079,7 @@ template<
 class iterator {
 public:
   iterator(Key *key): ptr(key) {}
-  iterator operator++() { ++ptr; return *this; }
+  iterator& operator++() { ++ptr; return *this; }
   bool operator!=(const iterator ) const { return ptr != other.ptr; }
   const Key *() const { return *ptr; }
 private:
@@ -1104,7 +1104,7 @@ template<
 class iterator {
 public:
   iterator(Key *key): ptr(key) {}
-  iterator operator++() { ++ptr; return *this; }
+  iterator& operator++() { ++ptr; return *this; }
   bool operator!=(const iterator ) const { return ptr != other.ptr; }
   const Key *() const { return *ptr; }
 private:



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


[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-25 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clangd/TidyProvider.h:25
+/*Filename=*/llvm::StringRef,
+/*CWD*/ PathRef) const>;
+

sammccall wrote:
> sammccall wrote:
> > njames93 wrote:
> > > sammccall wrote:
> > > > CWD is now effectively unused and can be dropped
> > > So I tried removing CWD and it leads to assertions failing in the 
> > > tests(the ones with the extension `.test`). 
> > > I do know that the TFS has some issues in those tests anyway:
> > > ```
> > > [build] E[16:04:40.948] VFS: failed to set CWD to /clangd-test: No such 
> > > file or directory.```
> > > I could remove the CWD but not have assertions, instead just bail out if 
> > > we encounter those cases, maybe with a log. WDYT?
> > It's a bit hard to say without more details - what assertions/cases?
> > 
> > AFAICT:
> >  - Filename now only ever has the value passed from ParsedAST::build().
> >  - That should always be absolute
> >  - CWD is only used for the filesystem examining Filename and its parents, 
> > and if they're absolute it should be irrelevant
> > One of these is clearly not true, though :-)
> (FWIW I patched in the latest revision of this patch, deleted CWD and 
> check-clangd passed without assertion failures)
Oh I added some assertions to ensure that it was a directory, those are the 
ones that failed. The ones ensuring its absolute ran without a hitch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91029

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


[PATCH] D92108: Fix inconsistent availability attribute message string literal check.

2020-11-25 Thread Nigel Perks via Phabricator via cfe-commits
nigelp-xmos added a comment.

Alternatively, if all 1-byte-character strings are acceptable, should I remove 
the check that the first token is a string literal, and omit the failing test 
case on XCore?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92108

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


[PATCH] D92108: Fix inconsistent availability attribute message string literal check.

2020-11-25 Thread Nigel Perks via Phabricator via cfe-commits
nigelp-xmos created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nigelp-xmos requested review of this revision.

Function Parser::ParseAvailabilityAttribute checks that the message string of
an availability attribute is not a wide string literal. Test case
clang/test/Parser/attr-availability.c specifies that a string literal is
expected.

The code checked that the first token in a string concatenation is a string
literal, and then that the concatenated string consists of 1-byte characters.
On a target where wide character is 1 byte, a string concatenation "a" L"b"
passes both those checks, but L"b" alone is rejected. More generally, "a" u8"b"
passes the checks, but u8"b" alone is rejected.

So check isAscii() instead of character size.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92108

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/test/Parser/attr-availability-xcore.c
  clang/test/Parser/attr-availability.c


Index: clang/test/Parser/attr-availability.c
===
--- clang/test/Parser/attr-availability.c
+++ clang/test/Parser/attr-availability.c
@@ -22,6 +22,14 @@
 
 void f8() __attribute__((availability(macosx,message="a" L"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
 
+void f9() __attribute__((availability(macosx,message=u8"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f10() __attribute__((availability(macosx,message="a" u8"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f11() __attribute__((availability(macosx,message=u"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f12() __attribute__((availability(macosx,message="a" u"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
 // rdar://10095131
 enum E{
 gorf __attribute__((availability(macosx,introduced=8.5, message = 10.0))), 
// expected-error {{expected string literal for optional message in 
'availability' attribute}}
Index: clang/test/Parser/attr-availability-xcore.c
===
--- /dev/null
+++ clang/test/Parser/attr-availability-xcore.c
@@ -0,0 +1,11 @@
+// Test availability message string type when wide characters are 1 byte.
+// REQUIRES: xcore-registered-target
+// RUN: %clang_cc1 -triple xcore -fsyntax-only -verify %s
+
+#if !__has_feature(attribute_availability)
+#  error 'availability' attribute is not available
+#endif
+
+void f7() __attribute__((availability(macosx,message=L"wide"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
+
+void f8() __attribute__((availability(macosx,message="a" L"b"))); // 
expected-error {{expected string literal for optional message in 'availability' 
attribute}}
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1118,7 +1118,7 @@
   // Also reject wide string literals.
   if (StringLiteral *MessageStringLiteral =
   cast_or_null(MessageExpr.get())) {
-if (MessageStringLiteral->getCharByteWidth() != 1) {
+if (!MessageStringLiteral->isAscii()) {
   Diag(MessageStringLiteral->getSourceRange().getBegin(),
diag::err_expected_string_literal)
 << /*Source='availability attribute'*/ 2;


Index: clang/test/Parser/attr-availability.c
===
--- clang/test/Parser/attr-availability.c
+++ clang/test/Parser/attr-availability.c
@@ -22,6 +22,14 @@
 
 void f8() __attribute__((availability(macosx,message="a" L"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
 
+void f9() __attribute__((availability(macosx,message=u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f10() __attribute__((availability(macosx,message="a" u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f11() __attribute__((availability(macosx,message=u"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
+void f12() __attribute__((availability(macosx,message="a" u"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+
 // rdar://10095131
 enum E{
 gorf __attribute__((availability(macosx,introduced=8.5, message = 10.0))), // expected-error {{expected string literal for optional message in 'availability' attribute}}
Index: clang/test/Parser/attr-availability-xcore.c

[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/TidyProvider.h:25
+/*Filename=*/llvm::StringRef,
+/*CWD*/ PathRef) const>;
+

sammccall wrote:
> njames93 wrote:
> > sammccall wrote:
> > > CWD is now effectively unused and can be dropped
> > So I tried removing CWD and it leads to assertions failing in the tests(the 
> > ones with the extension `.test`). 
> > I do know that the TFS has some issues in those tests anyway:
> > ```
> > [build] E[16:04:40.948] VFS: failed to set CWD to /clangd-test: No such 
> > file or directory.```
> > I could remove the CWD but not have assertions, instead just bail out if we 
> > encounter those cases, maybe with a log. WDYT?
> It's a bit hard to say without more details - what assertions/cases?
> 
> AFAICT:
>  - Filename now only ever has the value passed from ParsedAST::build().
>  - That should always be absolute
>  - CWD is only used for the filesystem examining Filename and its parents, 
> and if they're absolute it should be irrelevant
> One of these is clearly not true, though :-)
(FWIW I patched in the latest revision of this patch, deleted CWD and 
check-clangd passed without assertion failures)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91029

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


[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/TidyProvider.h:25
+/*Filename=*/llvm::StringRef,
+/*CWD*/ PathRef) const>;
+

njames93 wrote:
> sammccall wrote:
> > CWD is now effectively unused and can be dropped
> So I tried removing CWD and it leads to assertions failing in the tests(the 
> ones with the extension `.test`). 
> I do know that the TFS has some issues in those tests anyway:
> ```
> [build] E[16:04:40.948] VFS: failed to set CWD to /clangd-test: No such file 
> or directory.```
> I could remove the CWD but not have assertions, instead just bail out if we 
> encounter those cases, maybe with a log. WDYT?
It's a bit hard to say without more details - what assertions/cases?

AFAICT:
 - Filename now only ever has the value passed from ParsedAST::build().
 - That should always be absolute
 - CWD is only used for the filesystem examining Filename and its parents, and 
if they're absolute it should be irrelevant
One of these is clearly not true, though :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91029

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


[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-25 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clangd/TidyProvider.h:25
+/*Filename=*/llvm::StringRef,
+/*CWD*/ PathRef) const>;
+

sammccall wrote:
> CWD is now effectively unused and can be dropped
So I tried removing CWD and it leads to assertions failing in the tests(the 
ones with the extension `.test`). 
I do know that the TFS has some issues in those tests anyway:
```
[build] E[16:04:40.948] VFS: failed to set CWD to /clangd-test: No such file or 
directory.```
I could remove the CWD but not have assertions, instead just bail out if we 
encounter those cases, maybe with a log. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91029

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


[PATCH] D92041: [clangd] Add hover info for `this` expr

2020-11-25 Thread xndcn via Phabricator via cfe-commits
xndcn updated this revision to Diff 307622.
xndcn added a comment.

Update the diff with `getHoverContents(const NamedDecl ..)` overload function.


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

https://reviews.llvm.org/D92041

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2019,6 +2019,22 @@
 HI.NamespaceScope = "";
 HI.Definition = "@interface MYObject\n@end";
   }},
+  {
+  R"cpp(// this expr
+   namespace ns {
+ class Foo {
+   Foo* bar() {
+ return [[t^his]];
+   }
+ };
+   };
+  )cpp",
+  [](HoverInfo ) {
+HI.Name = "Foo";
+HI.Kind = index::SymbolKind::Class;
+HI.NamespaceScope = "ns::";
+HI.Definition = "class Foo {}";
+  }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -630,7 +630,8 @@
 
 // Generates hover info for evaluatable expressions.
 // FIXME: Support hover for literals (esp user-defined)
-llvm::Optional getHoverContents(const Expr *E, ParsedAST ) {
+llvm::Optional getHoverContents(const Expr *E, ParsedAST ,
+   const SymbolIndex *Index) {
   // There's not much value in hovering over "42" and getting a hover card
   // saying "42 is an int", similar for other literals.
   if (isLiteral(E))
@@ -647,6 +648,10 @@
 HI.Value = *Val;
 HI.Name = std::string(getNameForExpr(E));
 return HI;
+  } else if (const CXXThisExpr *CTE = dyn_cast(E)) {
+const NamedDecl *D = 
CTE->getType()->getPointeeType()->getAsCXXRecordDecl();
+HI = getHoverContents(D, Index);
+return HI;
   }
   return llvm::None;
 }
@@ -861,7 +866,7 @@
   HI->Value = printExprValue(N, AST.getASTContext());
 maybeAddCalleeArgInfo(N, *HI, AST.getASTContext().getPrintingPolicy());
   } else if (const Expr *E = N->ASTNode.get()) {
-HI = getHoverContents(E, AST);
+HI = getHoverContents(E, AST, Index);
   }
   // FIXME: support hovers for other nodes?
   //  - built-in types


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2019,6 +2019,22 @@
 HI.NamespaceScope = "";
 HI.Definition = "@interface MYObject\n@end";
   }},
+  {
+  R"cpp(// this expr
+   namespace ns {
+ class Foo {
+   Foo* bar() {
+ return [[t^his]];
+   }
+ };
+   };
+  )cpp",
+  [](HoverInfo ) {
+HI.Name = "Foo";
+HI.Kind = index::SymbolKind::Class;
+HI.NamespaceScope = "ns::";
+HI.Definition = "class Foo {}";
+  }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -630,7 +630,8 @@
 
 // Generates hover info for evaluatable expressions.
 // FIXME: Support hover for literals (esp user-defined)
-llvm::Optional getHoverContents(const Expr *E, ParsedAST ) {
+llvm::Optional getHoverContents(const Expr *E, ParsedAST ,
+   const SymbolIndex *Index) {
   // There's not much value in hovering over "42" and getting a hover card
   // saying "42 is an int", similar for other literals.
   if (isLiteral(E))
@@ -647,6 +648,10 @@
 HI.Value = *Val;
 HI.Name = std::string(getNameForExpr(E));
 return HI;
+  } else if (const CXXThisExpr *CTE = dyn_cast(E)) {
+const NamedDecl *D = CTE->getType()->getPointeeType()->getAsCXXRecordDecl();
+HI = getHoverContents(D, Index);
+return HI;
   }
   return llvm::None;
 }
@@ -861,7 +866,7 @@
   HI->Value = printExprValue(N, AST.getASTContext());
 maybeAddCalleeArgInfo(N, *HI, AST.getASTContext().getPrintingPolicy());
   } else if (const Expr *E = N->ASTNode.get()) {
-HI = getHoverContents(E, AST);
+HI = getHoverContents(E, AST, Index);
   }
   // FIXME: support hovers for other nodes?
   //  - built-in types
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D91651: [clang] Add a warning (à la gcc) for too small enum bitfields

2020-11-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Do you have any numbers on false positives / true positives uncovered by this 
tweak? In general, warning at use time instead of at declaration time tends to 
be much better for this rate, and we do this differently than gcc in several 
instances, because the gcc way has so many false positives that it makes 
warnings unusable, while warning on use makes the warning useful. So I'd like 
to see a better justification than "gcc does it" :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91651

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


[PATCH] D92101: [Clang][Sema] Attempt to fix CTAD faulty copy of non-local typedefs

2020-11-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:5906
+  Lang_CXX17, "input.cc");
+  TU->dump();
+  auto *Guide = FirstDeclMatcher().match(

These `dump` calls should be removed (in the other case too)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92101

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


[PATCH] D87702: [Frontend] Add pragma align natural and sort out pragma pack stack effect

2020-11-25 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:637
   PragmaStack VtorDispStack;
-  // #pragma pack.
-  // Sentinel to represent when the stack is set to mac68k alignment.
-  static const unsigned kMac68kAlignmentSentinel = ~0U;
-  PragmaStack PackStack;
+  PragmaStack PackStack;
   // The current #pragma pack values and locations at each #include.

jasonliu wrote:
> We should consider renaming PackStack to AlignPackStack across Clang. Maybe 
> even as a NFC first. As it is right now, clang already uses one stack to 
> record those two informations from `Pragma align` and `Pragma pack`. Leave it 
> as PackStack is too confusing, and people could actually ignore the pragma 
> Align when developing with PackStack. 
That's a good point. I will create a NFC accordingly.


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

https://reviews.llvm.org/D87702

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


[PATCH] D87702: [Frontend] Add pragma align natural and sort out pragma pack stack effect

2020-11-25 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L updated this revision to Diff 307617.
Xiangling_L marked an inline comment as done.
Xiangling_L added a comment.
Herald added a subscriber: dexonsmith.

Addressed the comments;
Handle PCH for AIX;


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

https://reviews.llvm.org/D87702

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Driver/aix-pragma-pack.c
  clang/test/Layout/aix-double-struct-member.cpp
  clang/test/Layout/aix-power-natural-interaction.cpp
  clang/test/PCH/aix-pragma-pack.c
  clang/test/Sema/aix-pragma-pack-and-align.c

Index: clang/test/Sema/aix-pragma-pack-and-align.c
===
--- /dev/null
+++ clang/test/Sema/aix-pragma-pack-and-align.c
@@ -0,0 +1,231 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -faix-pragma-pack -verify -fsyntax-only -x c++ %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -faix-pragma-pack -verify -fsyntax-only -x c++ %s | \
+// RUN:   FileCheck %s
+
+namespace test1 {
+#pragma align(natural)
+#pragma pack(4)
+#pragma pack(2)
+struct A {
+  int i;
+  double d;
+};
+
+int a = sizeof(A);
+#pragma pack()
+#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 4}}
+#pragma pack(pop)
+#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
+struct B {
+  int i;
+  double d;
+};
+#pragma align(reset)
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test1::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=2, preferredalign=2,
+// CHECK-NEXT:|  nvsize=12, nvalign=2, preferrednvalign=2]
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test1::B
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  8 |   double d
+// CHECK-NEXT:| [sizeof=16, dsize=16, align=4, preferredalign=8,
+// CHECK-NEXT:|  nvsize=16, nvalign=4, preferrednvalign=8]
+
+} // namespace test1
+
+namespace test2 {
+#pragma align(natural)
+#pragma pack(2)
+struct A {
+  int i;
+  double d;
+};
+
+int a = sizeof(A);
+#pragma align(reset)
+
+struct B {
+  int i;
+  double d;
+};
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test2::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=2, preferredalign=2,
+// CHECK-NEXT:|  nvsize=12, nvalign=2, preferrednvalign=2]
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test2::B
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=12, nvalign=4, preferrednvalign=4]
+
+} // namespace test2
+
+namespace test3 {
+#pragma pack(2)
+#pragma align(natural)
+struct A {
+  double d;
+};
+#pragma align(reset)
+#pragma pack(pop)
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test3::A
+// CHECK-NEXT:  0 |   double d
+// CHECK-NEXT:| [sizeof=8, dsize=8, align=4, preferredalign=8,
+// CHECK-NEXT:|  nvsize=8, nvalign=4, preferrednvalign=8]
+
+} // namespace test3
+
+namespace test4 {
+#pragma pack(2)
+#pragma align(natural)
+#pragma pack(pop)
+
+struct A {
+  int i;
+  double d;
+} a;
+#pragma align(reset)
+#pragma pack(pop)
+
+int i = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test4::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  8 |   double d
+// CHECK-NEXT:| [sizeof=16, dsize=16, align=4, preferredalign=8,
+// CHECK-NEXT:|  nvsize=16, nvalign=4, preferrednvalign=8]
+
+} // namespace test4
+
+namespace test5 {
+#pragma align(power)
+#pragma align(natural)
+#pragma pack(2)
+#pragma align(reset)
+struct A {
+  int i;
+  double d;
+};
+#pragma align(reset)
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test5::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| 

[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-25 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 307615.
njames93 added a comment.

Removed duplicated logging of options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91029

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/TidyProvider.h
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h

Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 
+#include "../TidyProvider.h"
 #include "Compiler.h"
 #include "ParsedAST.h"
 #include "TestFS.h"
@@ -58,8 +59,7 @@
   // Extra arguments for the compiler invocation.
   std::vector ExtraArgs;
 
-  llvm::Optional ClangTidyChecks;
-  llvm::Optional ClangTidyWarningsAsErrors;
+  TidyProvider ClangTidyProvider = {};
   // Index to use when building AST.
   const SymbolIndex *ExternalIndex = nullptr;
 
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -59,8 +59,8 @@
 FS.OverlayRealFileSystemForModules = true;
   Inputs.TFS = 
   Inputs.Opts = ParseOptions();
-  Inputs.Opts.ClangTidyOpts.Checks = ClangTidyChecks;
-  Inputs.Opts.ClangTidyOpts.WarningsAsErrors = ClangTidyWarningsAsErrors;
+  if (ClangTidyProvider)
+Inputs.ClangTidyProvider = ClangTidyProvider;
   Inputs.Index = ExternalIndex;
   if (Inputs.Index)
 Inputs.Opts.SuggestMissingIncludes = true;
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -24,6 +24,7 @@
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "TidyProvider.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
@@ -250,7 +251,7 @@
   TestTU TU;
   // this check runs the preprocessor, we need to make sure it does not break
   // our recording logic.
-  TU.ClangTidyChecks = "modernize-use-trailing-return-type";
+  TU.ClangTidyProvider = addTidyChecks("modernize-use-trailing-return-type");
   TU.Code = "inline int foo() {}";
 
   auto AST = TU.build();
@@ -406,7 +407,7 @@
   "replay-preamble-module", "");
   TestTU TU;
   // This check records inclusion directives replayed by clangd.
-  TU.ClangTidyChecks = "replay-preamble-check";
+  TU.ClangTidyProvider = addTidyChecks("replay-preamble-check");
   llvm::Annotations Test(R"cpp(
 $hash^#$include[[import]] $filebegin^"$filerange[[bar.h]]"
 $hash^#$include[[include_next]] $filebegin^"$filerange[[baz.h]]"
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -14,6 +14,7 @@
 #include "TestFS.h"
 #include "TestIndex.h"
 #include "TestTU.h"
+#include "TidyProvider.h"
 #include "index/MemIndex.h"
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
@@ -129,7 +130,7 @@
 }
   )cpp");
   auto TU = TestTU::withCode(Test.code());
-  TU.ClangTidyChecks = "-*,google-explicit-constructor";
+  TU.ClangTidyProvider = addTidyChecks("google-explicit-constructor");
   EXPECT_THAT(
   TU.build().getDiagnostics(),
   ElementsAre(
@@ -201,8 +202,8 @@
   auto TU = TestTU::withCode(Test.code());
   // Enable alias clang-tidy checks, these check emits the same diagnostics
   // (except the check name).
-  TU.ClangTidyChecks = "-*, readability-uppercase-literal-suffix, "
-   "hicpp-uppercase-literal-suffix";
+  TU.ClangTidyProvider = addTidyChecks("readability-uppercase-literal-suffix,"
+   "hicpp-uppercase-literal-suffix");
   // Verify that we filter out the duplicated diagnostic message.
   EXPECT_THAT(
   TU.build().getDiagnostics(),
@@ -245,9 +246,10 @@
   )cpp");
   auto TU = TestTU::withCode(Test.code());
   TU.HeaderFilename = "assert.h"; // Suppress "not found" error.
- 

[PATCH] D92101: [Clang][Sema] Attempt to fix CTAD faulty copy of non-local typedefs

2020-11-25 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:5893
+  // in the global scope.
+  EXPECT_EQ(Param->getType()->getAs()->getDecl(), Typedef);
+}

Note, this "expectation" fails in baseline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92101

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


[PATCH] D92101: [Clang][Sema] Attempt to fix CTAD faulty copy of non-local typedefs

2020-11-25 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added a reviewer: rsmith.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp, rnkovacs.
Herald added a reviewer: shafik.
Herald added a project: clang.
martong requested review of this revision.

http://lists.llvm.org/pipermail/cfe-dev/2020-November/067252.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92101

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5865,6 +5865,56 @@
   EXPECT_EQ(Record, CompletedTags.front());
 }
 
+// FIXME Move these tests out of ASTImporterTest. For that we need to factor
+// out the ASTImporter specific pars from ASTImporterOptionSpecificTestBase
+// into a new test Fixture. Then we should lift up this Fixture to its own
+// implementation file and only then could we reuse the Fixture in other AST
+// unitttests.
+struct CTAD : ASTImporterOptionSpecificTestBase {};
+
+TEST_P(CTAD, DeductionGuideShouldReferToANonLocalTypedef) {
+  Decl *TU = getTuDecl(
+  R"(
+  typedef int U;
+  template  struct A {
+A(U, T);
+  };
+  A a{(int)0, (int)0};
+  )",
+  Lang_CXX17, "input.cc");
+  TU->dump();
+  auto *Guide = FirstDeclMatcher().match(
+  TU, cxxDeductionGuideDecl());
+  auto *Typedef = FirstDeclMatcher().match(
+  TU, typedefNameDecl(hasName("U")));
+  ParmVarDecl *Param = Guide->getParamDecl(0);
+  // The type of the first param (which is a typedef) should match the typedef
+  // in the global scope.
+  EXPECT_EQ(Param->getType()->getAs()->getDecl(), Typedef);
+}
+
+TEST_P(CTAD, DeductionGuideShouldCopyALocalTypedef) {
+  Decl *TU = getTuDecl(
+  R"(
+  template  struct A {
+typedef T U;
+A(U, T);
+  };
+  A a{(int)0, (int)0};
+  )",
+  Lang_CXX17, "input.cc");
+  TU->dump();
+  auto *Guide = FirstDeclMatcher().match(
+  TU, cxxDeductionGuideDecl());
+  auto *Typedef = FirstDeclMatcher().match(
+  TU, typedefNameDecl(hasName("U")));
+  ParmVarDecl *Param = Guide->getParamDecl(0);
+  EXPECT_NE(Param->getType()->getAs()->getDecl(), Typedef);
+}
+
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, CTAD,
+DefaultTestValuesForRunOptions, );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -2350,6 +2350,15 @@
   ParmVarDecl *OldParam, MultiLevelTemplateArgumentList ,
   llvm::SmallVectorImpl ) {
 TypeSourceInfo *OldDI = OldParam->getTypeSourceInfo();
+
+if (auto *OldTypedefT = OldParam->getType()->getAs()) {
+  TypedefNameDecl *OldTypedefDecl = OldTypedefT->getDecl();
+  auto *CD = cast(OldParam->getDeclContext());
+  // If the typedef is not a local typedef, then skip the transform.
+  if (OldTypedefDecl->getDeclContext() != CD->getDeclContext())
+return OldParam;
+}
+
 TypeSourceInfo *NewDI;
 if (auto PackTL = OldDI->getTypeLoc().getAs()) {
   // Expand out the one and only element in each inner pack.


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5865,6 +5865,56 @@
   EXPECT_EQ(Record, CompletedTags.front());
 }
 
+// FIXME Move these tests out of ASTImporterTest. For that we need to factor
+// out the ASTImporter specific pars from ASTImporterOptionSpecificTestBase
+// into a new test Fixture. Then we should lift up this Fixture to its own
+// implementation file and only then could we reuse the Fixture in other AST
+// unitttests.
+struct CTAD : ASTImporterOptionSpecificTestBase {};
+
+TEST_P(CTAD, DeductionGuideShouldReferToANonLocalTypedef) {
+  Decl *TU = getTuDecl(
+  R"(
+  typedef int U;
+  template  struct A {
+A(U, T);
+  };
+  A a{(int)0, (int)0};
+  )",
+  Lang_CXX17, "input.cc");
+  TU->dump();
+  auto *Guide = FirstDeclMatcher().match(
+  TU, cxxDeductionGuideDecl());
+  auto *Typedef = FirstDeclMatcher().match(
+  TU, typedefNameDecl(hasName("U")));
+  ParmVarDecl *Param = Guide->getParamDecl(0);
+  // The type of the first param (which is a typedef) should match the typedef
+  // in the global scope.
+  EXPECT_EQ(Param->getType()->getAs()->getDecl(), Typedef);
+}
+
+TEST_P(CTAD, DeductionGuideShouldCopyALocalTypedef) {
+  Decl *TU = getTuDecl(
+  R"(
+  template  struct A {
+typedef T U;
+A(U, T);
+  };
+  A a{(int)0, (int)0};
+  )",
+  Lang_CXX17, "input.cc");
+  TU->dump();
+  

[PATCH] D92062: [MS] Add more 128bit cmpxchg intrinsics for AArch64

2020-11-25 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:336
+
+  // For Release ordering, the failure ordering should be Monotonic.
+  auto FailureOrdering = SuccessOrdering == AtomicOrdering::Release

Why?



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:360
+  SuccessOrdering, 
FailureOrdering);
+  CXI->setVolatile(true);
+

why?



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:14059
-AtomicOrdering::SequentiallyConsistent);
-CXI->setVolatile(true);
-

Oh, I guess it just moved around. Still not obvious to me :)



Comment at: clang/test/CodeGen/ms-intrinsics.c:441
 ++ExchangeLow, ++ComparandResult);
 }
+// CHECK-64: define{{.*}}i8 @test_InterlockedCompareExchange128(i64*{{[a-z_ 
]*}}%Destination, i64{{[a-z_ ]*}}%ExchangeHigh, i64{{[a-z_ ]*}}%ExchangeLow, 
i64*{{[a-z_ ]*}}%ComparandResult){{.*}}{

should this test some of the new aarc64-only intrins too if `__aarch64__`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92062

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


[PATCH] D92061: [MS] Fix double evaluation of MSVC builtin arguments

2020-11-25 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Nice!




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:1019
+  default:
+break;
+  case ARM::BI_BitScanForward:

Maybe `return None` here and LLVM_UNREACHABLE at the bottom?



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:1165
+  default:
+break;
+  case AArch64::BI_BitScanForward:

same suggestion



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:1311
+  default:
+break;
+  case clang::X86::BI_BitScanForward:

Same suggestion



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:7175
 
+  // Handle MSVC intrinsics before argument evaluation.
+  if (Optional MsvcIntId = translateArmToMsvcIntrin(BuiltinID))

This comment could answer "why" too: "...because EmitSMVCBuiltinExpr() 
evaluates arguments and they shouldn't be evaluated twice" (maybe worded better)



Comment at: clang/lib/CodeGen/CodeGenFunction.h:4126
+  llvm::Value *EmitEvaluatedMSVCBuiltin(MSVCIntrin BuiltinID, const CallExpr 
*E,
+ArrayRef Ops);
 

...where's the definition of this function? I can't see calls either. I guess 
this is a remnant from an earlier approach?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92061

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


[PATCH] D91789: [clang-tidy] find/fix unneeded trailing semicolons in macros

2020-11-25 Thread Tom Rix via Phabricator via cfe-commits
trixirt updated this revision to Diff 307602.
trixirt added a comment.

Addresses issues before refactoring.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91789

Files:
  clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt
  clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MacroTrailingSemiCheck.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MacroTrailingSemiCheck.h
  clang-tools-extra/test/clang-tidy/checkers/linuxkernel-macro-trailing-semi.c

Index: clang-tools-extra/test/clang-tidy/checkers/linuxkernel-macro-trailing-semi.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/linuxkernel-macro-trailing-semi.c
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s linuxkernel-macro-trailing-semi %t
+
+#define M(a) a++;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: unneeded semicolon
+// CHECK-FIXES: #define M(a) a++{{$}}
+
+int f() {
+  int v = 0;
+  M(v);
+  return v;
+}
+
+// A corner case
+// An empty macro could conditionally contain another path so
+// do not warn or fix.
+#ifdef UNSET_CONDITION
+#define E() ;
+#else
+#define E()
+#endif
+#define N(a) a++;
+
+int g() {
+  int v = 0;
+  N(v) E();
+  return v;
+}
Index: clang-tools-extra/clang-tidy/linuxkernel/MacroTrailingSemiCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/linuxkernel/MacroTrailingSemiCheck.h
@@ -0,0 +1,40 @@
+//===--- MacroTrailingSemiCheck.h - clang-tidy --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LINUXKERNEL_MACROTRAILINGSEMICHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LINUXKERNEL_MACROTRAILINGSEMICHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "clang/Lex/MacroInfo.h"
+#include 
+
+namespace clang {
+namespace tidy {
+namespace linuxkernel {
+
+class MacroTrailingSemiCheck : public ClangTidyCheck {
+public:
+  MacroTrailingSemiCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager , Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override final;
+
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void checkMacro(SourceManager , const Token ,
+  const MacroInfo *MI);
+
+private:
+  std::vector SuspectMacros;
+};
+
+} // namespace linuxkernel
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LINUXKERNEL_MACROTRAILINGSEMI_CHECK_H
Index: clang-tools-extra/clang-tidy/linuxkernel/MacroTrailingSemiCheck.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/linuxkernel/MacroTrailingSemiCheck.cpp
@@ -0,0 +1,135 @@
+//===--- MacroTrailingSemiCheck.cpp - clang-tidy---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MacroTrailingSemiCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace linuxkernel {
+
+class MacroTrailingSemiCheckPPCallbacks : public PPCallbacks {
+public:
+  MacroTrailingSemiCheckPPCallbacks(Preprocessor *PP,
+MacroTrailingSemiCheck *Check)
+  : PP(PP), Check(Check) {}
+
+  void MacroDefined(const Token ,
+const MacroDirective *MD) override {
+const MacroInfo *MI = MD->getMacroInfo();
+
+if (MI->isBuiltinMacro() || MI->isObjectLike())
+  return;
+Check->checkMacro(PP->getSourceManager(), MacroNameTok, MI);
+  }
+
+private:
+  Preprocessor *PP;
+  MacroTrailingSemiCheck *Check;
+};
+
+void MacroTrailingSemiCheck::registerMatchers(MatchFinder *Finder) {
+  // From the reproducer
+  // #define M(a) a++;
+  // int f() {
+  //   int v = 0;
+  //   M(v);
+  //   return v;
+  // }
+  // The AST
+  // `-FunctionDecl
+  //   `-CompoundStmt <--- "comp", 'C'
+  // ...
+  // |-UnaryOperator
+  // | `-DeclRefExpr < 'E'
+  // |-NullStmt <-- "null" 'N'
+  // ...
+  

[PATCH] D92039: [-Wcalled-once-parameter] Introduce 'called_once' attribute

2020-11-25 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 307594.
vsavchenko marked an inline comment as done.
vsavchenko added a comment.

Add another comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92039

Files:
  clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Analysis/CalledOnceCheck.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaObjC/attr-called-once.m
  clang/test/SemaObjC/warn-called-once.m

Index: clang/test/SemaObjC/warn-called-once.m
===
--- /dev/null
+++ clang/test/SemaObjC/warn-called-once.m
@@ -0,0 +1,887 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fblocks -fobjc-exceptions -Wcompletion-handler %s
+
+#define NULL (void *)0
+#define CALLED_ONCE __attribute__((called_once))
+#define NORETURN __attribute__((noreturn))
+
+@protocol NSObject
+@end
+@interface NSObject 
+- (id)copy;
+- (id)class;
+- autorelease;
+@end
+
+typedef unsigned int NSUInteger;
+typedef struct {
+} NSFastEnumerationState;
+
+@interface NSArray <__covariant NSFastEnumeration>
+- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
+@end
+@interface NSMutableArray : NSArray 
+- addObject:anObject;
+@end
+@class NSString, Protocol;
+extern void NSLog(NSString *format, ...);
+
+void escape(void (^callback)(void));
+void escape_void(void *);
+void indirect_call(void (^callback)(void) CALLED_ONCE);
+void indirect_conv(void (^completionHandler)(void));
+void filler(void);
+void exit(int) NORETURN;
+
+void double_call_one_block(void (^callback)(void) CALLED_ONCE) {
+  callback(); // expected-note{{previous call is here}}
+  callback(); // expected-warning{{'callback' parameter marked 'called_once' is called twice}}
+}
+
+void double_call_one_block_parens(void (^callback)(void) CALLED_ONCE) {
+  (callback)(); // expected-note{{previous call is here}}
+  (callback)(); // expected-warning{{'callback' parameter marked 'called_once' is called twice}}
+}
+
+void double_call_one_block_ptr(void (*callback)(void) CALLED_ONCE) {
+  callback(); // expected-note{{previous call is here}}
+  callback(); // expected-warning{{'callback' parameter marked 'called_once' is called twice}}
+}
+
+void double_call_one_block_ptr_deref(void (*callback)(void) CALLED_ONCE) {
+  (*callback)(); // expected-note{{previous call is here}}
+  (*callback)(); // expected-warning{{'callback' parameter marked 'called_once' is called twice}}
+}
+
+void multiple_call_one_block(void (^callback)(void) CALLED_ONCE) {
+  // We don't really need to repeat the same warning for the same parameter.
+  callback(); // no-warning
+  callback(); // no-warning
+  callback(); // no-warning
+  callback(); // expected-note{{previous call is here}}
+  callback(); // expected-warning{{'callback' parameter marked 'called_once' is called twice}}
+}
+
+void double_call_branching_1(int cond, void (^callback)(void) CALLED_ONCE) {
+  if (cond) {
+callback(); // expected-note{{previous call is here}}
+  } else {
+cond += 42;
+  }
+  callback(); // expected-warning{{'callback' parameter marked 'called_once' is called twice}}
+}
+
+void double_call_branching_2(int cond, void (^callback)(void) CALLED_ONCE) {
+  callback(); // expected-note{{previous call is here}}
+
+  if (cond) {
+callback(); // expected-warning{{'callback' parameter marked 'called_once' is called twice}}
+  } else {
+cond += 42;
+  }
+}
+
+void double_call_branching_3(int cond, void (^callback)(void) CALLED_ONCE) {
+  if (cond) {
+callback();
+  } else {
+callback();
+  }
+  // no-warning
+}
+
+void double_call_branching_4(int cond1, int cond2, void (^callback)(void) CALLED_ONCE) {
+  if (cond1) {
+cond2 = !cond2;
+  } else {
+callback(); // expected-note{{previous call is here}}
+  }
+
+  if (cond2) {
+callback(); // expected-warning{{'callback' parameter marked 'called_once' is called twice}}
+  }
+}
+
+void double_call_loop(int counter, void (^callback)(void) CALLED_ONCE) {
+  while (counter > 0) {
+counter--;
+// Both note and warning are on the same line, which is a common situation
+// in loops.
+callback(); // expected-note{{previous call is here}}
+// expected-warning@-1{{'callback' parameter marked 'called_once' is called twice}}
+  }
+}
+
+void never_called_trivial(void (^callback)(void) CALLED_ONCE) {
+  // expected-warning@-1{{'callback' parameter marked 'called_once' is never called}}
+}
+
+int never_called_branching(int x, void (^callback)(void) CALLED_ONCE) {
+  // expected-warning@-1{{'callback' parameter marked 

[PATCH] D92051: [clangd] PopulateSwitch: disable on dependent enums.

2020-11-25 Thread Adam Czachorowski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf6970503d291: [clangd] PopulateSwitch: disable on dependent 
enums. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92051

Files:
  clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -3084,6 +3084,12 @@
   R""(enum Enum {A,B,b=B}; ^switch (A) {case A:case B:break;})"",
   "unavailable",
   },
+  {
+  // Enum is dependent type
+  File,
+  R""(template void f() {enum Enum {A}; ^switch (A) {}})"",
+  "unavailable",
+  },
   };
 
   for (const auto  : Cases) {
Index: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -126,7 +126,7 @@
 return false;
 
   EnumD = EnumT->getDecl();
-  if (!EnumD)
+  if (!EnumD || EnumD->isDependentType())
 return false;
 
   // We trigger if there are any values in the enum that aren't covered by the


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -3084,6 +3084,12 @@
   R""(enum Enum {A,B,b=B}; ^switch (A) {case A:case B:break;})"",
   "unavailable",
   },
+  {
+  // Enum is dependent type
+  File,
+  R""(template void f() {enum Enum {A}; ^switch (A) {}})"",
+  "unavailable",
+  },
   };
 
   for (const auto  : Cases) {
Index: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -126,7 +126,7 @@
 return false;
 
   EnumD = EnumT->getDecl();
-  if (!EnumD)
+  if (!EnumD || EnumD->isDependentType())
 return false;
 
   // We trigger if there are any values in the enum that aren't covered by the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] f697050 - [clangd] PopulateSwitch: disable on dependent enums.

2020-11-25 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2020-11-25T14:12:29+01:00
New Revision: f6970503d291b7cae70fe583bed392387f93f9e4

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

LOG: [clangd] PopulateSwitch: disable on dependent enums.

If the enum is a dependent type, we would crash somewhere in
getIntWidth(). -Wswitch diagnostic doesn't work on dependent enums
either.

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
index 852888f6a043..bae80cdecf59 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -126,7 +126,7 @@ bool PopulateSwitch::prepare(const Selection ) {
 return false;
 
   EnumD = EnumT->getDecl();
-  if (!EnumD)
+  if (!EnumD || EnumD->isDependentType())
 return false;
 
   // We trigger if there are any values in the enum that aren't covered by the

diff  --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp 
b/clang-tools-extra/clangd/unittests/TweakTests.cpp
index fd815d2c4c27..4a2360dda739 100644
--- a/clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -3084,6 +3084,12 @@ TEST_F(PopulateSwitchTest, Test) {
   R""(enum Enum {A,B,b=B}; ^switch (A) {case A:case B:break;})"",
   "unavailable",
   },
+  {
+  // Enum is dependent type
+  File,
+  R""(template void f() {enum Enum {A}; ^switch (A) {}})"",
+  "unavailable",
+  },
   };
 
   for (const auto  : Cases) {



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


[PATCH] D88712: [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-11-25 Thread Venkataramanan Kumar via Phabricator via cfe-commits
venkataramanan.kumar.llvm added a comment.

In D88712#2414171 , @spatel wrote:

> In D88712#2413877 , 
> @venkataramanan.kumar.llvm wrote:
>
>> In D88712#2413688 , @spatel wrote:
>>
>>> In D88712#2412874 , 
>>> @venkataramanan.kumar.llvm wrote:
>>>
 In D88712#2412366 , @MaskRay 
 wrote:

> In D88712#2411841 , 
> @venkataramanan.kumar.llvm wrote:
>
>> 
>
> For your example:
>
>   extern double log (double) asm ("" "log_finite") __attribute__ 
> ((nothrow));
>   
>   double mylog (double d) { return log(d); }
>
> The intention is to emit `log_finite`, no matter the `-ffast-math`. Both 
> GCC and Clang (after this patch) emit `jmp log_finite`.
>
> The previous behavior (according to your comment, with an older glibc) 
> was undesired. So I think the right suggestion is to upgrade glibc.

 Then there optimizations like vectorization, inst combine which works on 
 the LLVM intrinsics.  But they will be not happening now  with  log_finite 
 calls.
>>>
>>> I'm not sure about the expected semantics/lowering for the finite calls, 
>>> but can you add something under 
>>> LibCallSimplifier::optimizeFloatingPointLibCall() that would turn it into 
>>> the LLVM log intrinsic with appropriate FMF? Codegen would need to be 
>>> responsible for converting it back to finite call(s) if those are available?
>>
>> Hi Sanjay I thought codegen no longer lowers them back to finite calls 
>> https://reviews.llvm.org/rGcd0926d087a85c5ee1222ca80980b4440214a822
>
> There was a comment in D74712  that we might 
> be moving too fast. If you would like to revert/adjust that patch, raise a 
> bug or post a patch to discuss? If the goal is to be able to vectorize the 
> finite calls, then we will need some way to represent those. Alternatively, 
> we could change something in the cost models to enable more unrolling, etc?

The goal is able to vectorize the finite call.  On a newer glibc 2.31 same test 
case would undergo all the optimizations.   As you said we can try to lower in 
to intrinsic in LibCallSimplifier and then generate the finite calls in code 
generator again.

I will raise a bug as of now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88712

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


[PATCH] D77598: Integral template argument suffix and cast printing

2020-11-25 Thread Pratyush Das via Phabricator via cfe-commits
reikdas marked 25 inline comments as done.
reikdas added inline comments.



Comment at: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp:471
+  template  struct X {};
+  X<1, 1u>::type y; // expected-error {{no type named 'type' in 
'TypeSuffix::X<1, 1u>'}}
+  X<1, 1>::type z; // expected-error {{no type named 'type' in 
'TypeSuffix::X<1, 1>'}}

@rsmith This test fails and we are unable to print the suffix here because the 
length of the TemplateParameterList is less than the length of the 
corresponding list of Template Arguments. Do you have any suggestions on how we 
can fix this?


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

https://reviews.llvm.org/D77598

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


[PATCH] D92012: [clangd][query-driver] Extract target

2020-11-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Sorry, code reviews are racy :-)




Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:134
 elog("System include extraction: end marker missing: {0}", Output);
-return {};
-  }
-
-  for (llvm::StringRef Line : llvm::make_range(StartIt, EndIt)) {
-SystemIncludes.push_back(Line.trim().str());
-vlog("System include extraction: adding {0}", Line);
+return llvm::None;
   }

ArcsinX wrote:
> Unsure about this.
> Should we toss all collected data if end markes was not found?
Yup, at least for this patch (this is the existing behavior).
I think the logic is "this is a fragile text protocol, we've never seen this 
happen, so don't really know what it would mean".



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:212
+  if (!Target.empty()) {
+Cmd.CommandLine.push_back("-target");
+Cmd.CommandLine.push_back(Target);

sammccall wrote:
> kadircet wrote:
> > ArcsinX wrote:
> > > ArcsinX wrote:
> > > > kadircet wrote:
> > > > > sammccall wrote:
> > > > > > `clang -target foo test.cc` seems to be a hard error in the driver 
> > > > > > if the target is unknown.
> > > > > > (vs likely *some* functionality if we just didn't set the driver)
> > > > > > 
> > > > > > so this could regress some scenarios. Can we mitigate that?
> > > > > > (It's possible that we're running the driver in a mode where we 
> > > > > > proceed anyway, but I can't remember :-()
> > > > > what if target already exists in `Cmd`?
> > > > > 
> > > > > also it would be nice to use `--target=X` format to be consistent 
> > > > > with target inference from invocation name as in 
> > > > > https://github.com/llvm/llvm-project/blob/master/clang/lib/Tooling/Tooling.cpp#L278.
> > > > I failed to find options to process in case of invalid target,  so 
> > > > added target validation.
> > > We could specify several --target options, the last one will be used. But 
> > > I am not sure should we override existing or not.
> > > We could specify several --target options, the last one will be used. But 
> > > I am not sure should we override existing or not.
> > 
> > Having multiple targets sounds confusing. I would prefer keeping a target 
> > specifically mentioned by the user but it is also possible for the target 
> > to be inferred by clang (and that might be wrong). This is similar to our 
> > stand against predefined macros though, i think we should fix clang's 
> > inference logic if it has any false positives. So i am slightly leaning 
> > towards not overriding the target if it exists.
> I think the question of "target already explicitly set" should probably be 
> answered.
> Checking for an arg equal to "-target" or beginning with "--target" is 
> probably enough.
I think we should definitely not override the target if it already exists.

The scenario is: compile_commands.json has `/my/driver --target=bar foo.cc`.
`/my/driver reports "Target: foo"`

So foo is the default target, but it's being overridden on the command-line as 
part of the build.

Now if we add the extracted target to the end of the compile command, to 
produce `/my/driver --target=bar foo.cc --target=foo`, we're effectively 
reversing the precedence: now the default target is used even if the compile 
command overrode it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92012

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


[PATCH] D92012: [clangd][query-driver] Extract target

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

Thanks! just nits, apart from the "-target already explicitly set" issue Kadir 
raised.




Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:99
+  }
+  if (!Info.Target.empty())
+break;

I'm not sure these early returns are worth the complexity



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:102
+  LLVM_FALLTHROUGH;
+case IncludesExtracted:
+  if (Line.trim().startswith(TS)) {

also not sure whether initial vs includesextracted is worth distinguishing - 
this doesn't scale well if we add a third thing we're tracking (do we need a 
state for each combination that we could have seen already?)

Maybe just a bool for SeenIncludes or something to detect duplicate/missing 
sections would be simpler



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:106
+TargetLine.consume_front(TS);
+// Use only valid target
+if (!isValidTarget(TargetLine)) {

this mostly echoes the code: "Only detect targets that clang understands"?



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:108
+if (!isValidTarget(TargetLine)) {
+  vlog("Invalid target \"{0}\", ignoring", TargetLine);
+  break;

I'd prefix with "System include extraction: " and bump up to elog - this is 
fairly likely to break things (and we'll only log it ~once thanks to caching)



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:112
+Info.Target = TargetLine.str();
+vlog("Target extracted: \"{0}\"", TargetLine);
+  }

also add a prefix here so it's clear what the context is in the log



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:227
+  if (!Info->SystemIncludes.empty())
+log("System includes extractor: successfully executed {0}, got includes: "
+"\"{1}\"",

we want to log this even if the set is empty, so the reader can tell the 
extraction worked
(it's fine to only optionally log target)



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:231
+  if (!Info->Target.empty())
+log("Target extractor: successfully executed {0}, got target: "
+"\"{1}\"",

The target extractor isn't a separate component from the system includes 
extractor, so the log message seems a bit misleading.
I'd suggest just using "System includes extractor" for both, even if it's not 
totally accurate



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:212
+  if (!Target.empty()) {
+Cmd.CommandLine.push_back("-target");
+Cmd.CommandLine.push_back(Target);

kadircet wrote:
> ArcsinX wrote:
> > ArcsinX wrote:
> > > kadircet wrote:
> > > > sammccall wrote:
> > > > > `clang -target foo test.cc` seems to be a hard error in the driver if 
> > > > > the target is unknown.
> > > > > (vs likely *some* functionality if we just didn't set the driver)
> > > > > 
> > > > > so this could regress some scenarios. Can we mitigate that?
> > > > > (It's possible that we're running the driver in a mode where we 
> > > > > proceed anyway, but I can't remember :-()
> > > > what if target already exists in `Cmd`?
> > > > 
> > > > also it would be nice to use `--target=X` format to be consistent with 
> > > > target inference from invocation name as in 
> > > > https://github.com/llvm/llvm-project/blob/master/clang/lib/Tooling/Tooling.cpp#L278.
> > > I failed to find options to process in case of invalid target,  so added 
> > > target validation.
> > We could specify several --target options, the last one will be used. But I 
> > am not sure should we override existing or not.
> > We could specify several --target options, the last one will be used. But I 
> > am not sure should we override existing or not.
> 
> Having multiple targets sounds confusing. I would prefer keeping a target 
> specifically mentioned by the user but it is also possible for the target to 
> be inferred by clang (and that might be wrong). This is similar to our stand 
> against predefined macros though, i think we should fix clang's inference 
> logic if it has any false positives. So i am slightly leaning towards not 
> overriding the target if it exists.
I think the question of "target already explicitly set" should probably be 
answered.
Checking for an arg equal to "-target" or beginning with "--target" is probably 
enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92012

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


[PATCH] D92012: [clangd][query-driver] Extract target

2020-11-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:67
+
+bool isValidTarget(llvm::StringRef Triple) {
+  std::shared_ptr TargetOpts(new TargetOptions);

i think you can just do `TargetRegistry::lookupTarget`



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:230
+Driver, llvm::join(Info->SystemIncludes, ", "));
+  if (!Info->Target.empty())
+log("Target extractor: successfully executed {0}, got target: "

nit: I would fold these two into a single log statement.



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:337
 
-std::vector SystemIncludes =
+llvm::Optional Info =
 QueriedDrivers.get(/*Key=*/(Driver + ":" + Lang).str(), [&] {

nit:
```
if(auto Info = ...)
  setTarget(addSystemIncludes(...), ...);
return std::move(Cmd);
```



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:212
+  if (!Target.empty()) {
+Cmd.CommandLine.push_back("-target");
+Cmd.CommandLine.push_back(Target);

ArcsinX wrote:
> ArcsinX wrote:
> > kadircet wrote:
> > > sammccall wrote:
> > > > `clang -target foo test.cc` seems to be a hard error in the driver if 
> > > > the target is unknown.
> > > > (vs likely *some* functionality if we just didn't set the driver)
> > > > 
> > > > so this could regress some scenarios. Can we mitigate that?
> > > > (It's possible that we're running the driver in a mode where we proceed 
> > > > anyway, but I can't remember :-()
> > > what if target already exists in `Cmd`?
> > > 
> > > also it would be nice to use `--target=X` format to be consistent with 
> > > target inference from invocation name as in 
> > > https://github.com/llvm/llvm-project/blob/master/clang/lib/Tooling/Tooling.cpp#L278.
> > I failed to find options to process in case of invalid target,  so added 
> > target validation.
> We could specify several --target options, the last one will be used. But I 
> am not sure should we override existing or not.
> We could specify several --target options, the last one will be used. But I 
> am not sure should we override existing or not.

Having multiple targets sounds confusing. I would prefer keeping a target 
specifically mentioned by the user but it is also possible for the target to be 
inferred by clang (and that might be wrong). This is similar to our stand 
against predefined macros though, i think we should fix clang's inference logic 
if it has any false positives. So i am slightly leaning towards not overriding 
the target if it exists.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92012

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


[PATCH] D77598: Integral template argument suffix and cast printing

2020-11-25 Thread Pratyush Das via Phabricator via cfe-commits
reikdas updated this revision to Diff 307587.
reikdas added a comment.

Address @rsmith 's comments.


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

https://reviews.llvm.org/D77598

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/StmtDataCollectors.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTTypeTraits.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/NestedNameSpecifier.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Analysis/PathDiagnostic.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/Analysis/eval-predefined-exprs.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p12.cpp
  clang/test/CXX/temp/temp.param/p10-2a.cpp
  clang/test/SemaCXX/builtin-align-cxx.cpp
  clang/test/SemaCXX/cxx11-ast-print.cpp
  clang/test/SemaCXX/matrix-type-builtins.cpp
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/test/SemaTemplate/delegating-constructors.cpp
  clang/test/SemaTemplate/matrix-type.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  clang/tools/libclang/CIndex.cpp
  
clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp

Index: clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
===
--- clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
@@ -20,7 +20,7 @@
 llvm::raw_string_ostream Stream(ArgStr);
 const TemplateArgument  = ArgLoc.getArgument();
 
-Arg.print(Context->getPrintingPolicy(), Stream);
+Arg.print(Context->getPrintingPolicy(), Stream, /*IncludeType*/ true);
 Match(Stream.str(), ArgLoc.getLocation());
 return ExpectedLocationVisitor::
   TraverseTemplateArgumentLoc(ArgLoc);
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5144,8 +5144,9 @@
 SmallString<128> Str;
 llvm::raw_svector_ostream OS(Str);
 OS << *ClassSpec;
-printTemplateArgumentList(OS, ClassSpec->getTemplateArgs().asArray(),
-  Policy);
+printTemplateArgumentList(
+OS, ClassSpec->getTemplateArgs().asArray(), Policy,
+ClassSpec->getSpecializedTemplate()->getTemplateParameters());
 return cxstring::createDup(OS.str());
   }
 
Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -457,3 +457,17 @@
   X y;
   int n = y.call(); // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'void *'}}
 }
+
+namespace TypeSuffix {
+  template  struct S {};
+  template <> struct S<1> { using type = int; }; // expected-note {{'S<1>::type' declared here}}
+  S<1L>::type t; // expected-error {{no type named 'type' in 'TypeSuffix::S<1L>'; did you mean 'S<1>::type'?}}
+
+  template  struct A {};
+  template <> struct A<1> { using type = int; }; // expected-note {{'A<1>::type' declared here}}
+  A<2>::type x;  // expected-error {{no type named 'type' in 'TypeSuffix::A<2>'; did you mean 'A<1>::type'?}}
+
+  template  struct X {};
+  X<1, 1u>::type y; // expected-error {{no type named 'type' in 'TypeSuffix::X<1, 1u>'}}
+  X<1, 1>::type z; // expected-error {{no type named 'type' in 'TypeSuffix::X<1, 1>'}}
+}
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -270,6 +270,23 @@
   void test_char_possibly_negative() { enable_if_char<'\x02'>::type i; } // expected-error{{enable_if_char<'\x02'>'; did you mean 'enable_if_char<'a'>::type'?}}
   void test_char_single_quote() { enable_if_char<'\''>::type i; } // expected-error{{enable_if_char<'\''>'; did you mean 'enable_if_char<'a'>::type'?}}
   void test_char_backslash() { enable_if_char<'\\'>::type i; } // expected-error{{enable_if_char<'\\'>'; did you mean 'enable_if_char<'a'>::type'?}}
+
+  template  struct enable_if_int {};
+  template <> struct enable_if_int<1> { typedef int type; }; // expected-note{{'enable_if_int<1>::type' declared here}}
+  void test_int() { enable_if_int<2>::type i; } // 

  1   2   >