[PATCH] D97137: Bug fix of https://bugs.llvm.org/show_bug.cgi?id=49175

2021-02-20 Thread Darwin Xu via Phabricator via cfe-commits
darwin created this revision.
darwin added a reviewer: clang-format.
darwin added a project: clang-format.
darwin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The AlignConsecutiveDeclarations option doesn't handle pointer properly:

The expected code format:

  unsigned int*   a;
  int*b;
  unsigned int Const* c;

The actual code after formatting:

  unsigned int* a;
  int*  b;
  unsigned int Const* c;

>From the code of clang-format, it seems the WhitespaceManager miss treated 
>`Const` as one of the token and which leads to the faulty behavior. So I added 
>an extra check that if the next token is a pointer or a reference, then the 
>current token is not the aligned token (the `matcher` lambda returns false).

Unit test passed:

  darwin@Darwins-iMac build % cmake --build . -j24 -t check-clang-unit
  ...
  [100%] Running lit suite /Volumes/silo/Projects/llvm-project/clang/test/Unit
  
  Testing Time: 270.81s
Passed: 13848
  [100%] Built target check-clang-unit


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97137

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13945,6 +13945,10 @@
   verifyFormat("int  oneTwoThree{0}; // comment\n"
"unsigned oneTwo; // comment",
Alignment);
+  verifyFormat("unsigned int *  a;\n"
+   "int *   b;\n"
+   "unsigned int Const *c;",
+   Alignment);
   EXPECT_EQ("float const a = 5;\n"
 "\n"
 "int oneTwoThree = 123;",
@@ -14249,6 +14253,12 @@
   EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n"
 "foo(int a);",
 format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style));
+
+  Alignment.PointerAlignment = FormatStyle::PAS_Left;
+  verifyFormat("unsigned int*   a;\n"
+   "int*b;\n"
+   "unsigned int Const* c;",
+   Alignment);
 }
 
 TEST_F(FormatTest, LinuxBraceBreaking) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -709,6 +709,8 @@
 for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) {
   if (Next->is(tok::comment))
 continue;
+  if (Next->is(TT_PointerOrReference))
+return false;
   if (!Next->Tok.getIdentifierInfo())
 break;
   if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName,


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13945,6 +13945,10 @@
   verifyFormat("int  oneTwoThree{0}; // comment\n"
"unsigned oneTwo; // comment",
Alignment);
+  verifyFormat("unsigned int *  a;\n"
+   "int *   b;\n"
+   "unsigned int Const *c;",
+   Alignment);
   EXPECT_EQ("float const a = 5;\n"
 "\n"
 "int oneTwoThree = 123;",
@@ -14249,6 +14253,12 @@
   EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n"
 "foo(int a);",
 format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style));
+
+  Alignment.PointerAlignment = FormatStyle::PAS_Left;
+  verifyFormat("unsigned int*   a;\n"
+   "int*b;\n"
+   "unsigned int Const* c;",
+   Alignment);
 }
 
 TEST_F(FormatTest, LinuxBraceBreaking) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -709,6 +709,8 @@
 for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) {
   if (Next->is(tok::comment))
 continue;
+  if (Next->is(TT_PointerOrReference))
+return false;
   if (!Next->Tok.getIdentifierInfo())
 break;
   if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.
Herald added a subscriber: shchenz.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:184
+bool AddComma = false;
+if (!Ctor->getNumCtorInitializers() && FirstToCtorInits) {
+  SourceLocation BodyPos = Ctor->getBody()->getBeginLoc();

Rechi wrote:
> The following example generates invalid fixes, if 
> modernize-use-default-member-init check isn't enabled, because 
> `Ctor->getNumCtorInitializers()` returns 1.
> 
> ```lang=cpp
> class Example
> {
> public:
>   Example() { a = 0; };
>   int a;
>   std::string string;
> };
> ```
I've done a little work trying to fix some issues I've noticed while running 
this check in the wild. I have a feeling this shortcoming has been addressed in 
there - D97132.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71199

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


[PATCH] D93800: [clangd] Add caching behaviour for clang-format config

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 325267.
njames93 added a comment.

Update to support inheriting configurations from D93844 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93800

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/FormatProvider.cpp
  clang-tools-extra/clangd/FormatProvider.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/support/FileCache.h
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/FormatTests.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
@@ -19,6 +19,7 @@
 
 #include "../TidyProvider.h"
 #include "Compiler.h"
+#include "FormatProvider.h"
 #include "ParsedAST.h"
 #include "TestFS.h"
 #include "index/Index.h"
@@ -60,6 +61,8 @@
   std::vector ExtraArgs;
 
   TidyProvider ClangTidyProvider = {};
+
+  mutable FormatProvider ClangFormatProvider = formatFallbackProvider;
   // 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
@@ -9,6 +9,7 @@
 #include "TestTU.h"
 #include "Compiler.h"
 #include "Diagnostics.h"
+#include "FormatProvider.h"
 #include "TestFS.h"
 #include "index/FileIndex.h"
 #include "index/MemIndex.h"
@@ -61,6 +62,9 @@
   Inputs.Opts = ParseOptions();
   if (ClangTidyProvider)
 Inputs.ClangTidyProvider = ClangTidyProvider;
+  ClangFormatProvider =
+  getClangFormatProvider(FS, format::DefaultFallbackStyle);
+  Inputs.ClangFormatProvider = ClangFormatProvider;
   Inputs.Index = ExternalIndex;
   return Inputs;
 }
Index: clang-tools-extra/clangd/unittests/FormatTests.cpp
===
--- clang-tools-extra/clangd/unittests/FormatTests.cpp
+++ clang-tools-extra/clangd/unittests/FormatTests.cpp
@@ -303,6 +303,64 @@
 )cpp");
 }
 
+TEST(FormatProvider, NestedDirectories) {
+  MockFS FS;
+  FS.Files[testPath("project/.clang-format")] = R"yaml(
+  BasedOnStyle: llvm
+)yaml";
+  FS.Files[testPath("project/test/.clang-format")] = R"yaml(
+  BasedOnStyle: llvm
+  ColumnLimit: 0
+)yaml";
+  FS.Files[testPath("project/test/sub1/.clang-format")] = R"yaml(
+  BasedOnStyle: InheritParentConfig
+  UseTab: Always
+)yaml";
+  FS.Files[testPath("project/test/sub1/sub2/.clang-format")] = R"yaml(
+  BasedOnStyle: InheritParentConfig
+  AccessModifierOffset: -1
+)yaml";
+
+  auto Provider = getClangFormatProvider(FS, "google");
+  auto LLVMStyle = format::getLLVMStyle(format::FormatStyle::LK_Cpp);
+
+  EXPECT_EQ(*Provider(testPath("project/File.cpp"), ""), LLVMStyle);
+
+  LLVMStyle.ColumnLimit = 0U;
+  EXPECT_EQ(*Provider(testPath("project/test/File.cpp"), ""), LLVMStyle);
+
+  LLVMStyle.UseTab = format::FormatStyle::UT_Always;
+  EXPECT_EQ(*Provider(testPath("project/test/sub1/File.cpp"), ""), LLVMStyle);
+
+  auto DefAccess = LLVMStyle.AccessModifierOffset;
+  LLVMStyle.AccessModifierOffset = -1;
+  EXPECT_EQ(*Provider(testPath("project/test/sub1/sub2/File.cpp"), ""),
+LLVMStyle);
+  LLVMStyle.AccessModifierOffset = DefAccess;
+
+  // FS reads can be stale by 5 seconds, so wait to force re polling when we
+  // have updated the files.
+  std::this_thread::sleep_for(std::chrono::seconds(6));
+
+  FS.Files[testPath("project/test/sub1/.clang-format")] = R"yaml(
+  BasedOnStyle: InheritParentConfig
+  UseTab: ForContinuationAndIndentation
+)yaml";
+  ++FS.Timestamps[testPath("project/test/sub1/.clang-format")];
+
+  LLVMStyle.UseTab = format::FormatStyle::UT_ForContinuationAndIndentation;
+  EXPECT_EQ(*Provider(testPath("project/test/sub1/File.cpp"), ""), LLVMStyle);
+
+  LLVMStyle.AccessModifierOffset = -1;
+  EXPECT_EQ(*Provider(testPath("project/test/sub1/sub2/File.cpp"), ""),
+LLVMStyle);
+
+  // This shouldn't find a config file and instead fallback to using google
+  // style.
+  EXPECT_EQ(*Provider(testPath("File.cpp"), ""),
+format::getGoogleStyle(format::FormatStyle::LK_Cpp));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: 

[clang] b42d57a - [clang][Driver][OpenBSD] libcxx also requires pthread

2021-02-20 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2021-02-20T20:53:25-05:00
New Revision: b42d57a100c5df6ace68f686f5adaabeafe8a0f6

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

LOG: [clang][Driver][OpenBSD] libcxx also requires pthread

Added: 


Modified: 
clang/lib/Driver/ToolChains/OpenBSD.cpp
clang/test/Driver/openbsd.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index f155d74632f9..e162165b2561 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -296,6 +296,7 @@ void OpenBSD::AddCXXStdlibLibArgs(const ArgList ,
 
   CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
   CmdArgs.push_back(Profiling ? "-lc++abi_p" : "-lc++abi");
+  CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
 }
 
 std::string OpenBSD::getCompilerRT(const ArgList ,

diff  --git a/clang/test/Driver/openbsd.cpp b/clang/test/Driver/openbsd.cpp
index 9293148680c8..23c365d28e7e 100644
--- a/clang/test/Driver/openbsd.cpp
+++ b/clang/test/Driver/openbsd.cpp
@@ -6,7 +6,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-CXX %s
 // RUN: %clangxx %s -### -o %t.o -target arm-unknown-openbsd 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-CXX %s
-// CHECK-CXX: "-lc++" "-lc++abi" "-lm"
+// CHECK-CXX: "-lc++" "-lc++abi" "-lpthread" "-lm"
 
 // RUN: %clangxx %s -### -pg -o %t.o -target amd64-pc-openbsd 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PG-CXX %s
@@ -16,4 +16,4 @@
 // RUN:   | FileCheck --check-prefix=CHECK-PG-CXX %s
 // RUN: %clangxx %s -### -pg -o %t.o -target arm-unknown-openbsd 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PG-CXX %s
-// CHECK-PG-CXX: "-lc++_p" "-lc++abi_p" "-lm_p"
+// CHECK-PG-CXX: "-lc++_p" "-lc++abi_p" "-lpthread_p" "-lm_p"



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


[PATCH] D96286: [clangd] Change TidyProvider cache to use a linked list approach

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Ping @sammccall Any issues with this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96286

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


[PATCH] D96286: [clangd] Change TidyProvider cache to use a linked list approach

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 325266.
njames93 added a comment.

Update using absoluteParent helper


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96286

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
@@ -77,12 +77,24 @@
   }
 };
 
+llvm::SmallString<256> pathAppend(PathRef Path, llvm::StringRef Tail) {
+  llvm::SmallString<256> ConfigPath(Path);
+  llvm::sys::path::append(ConfigPath, Tail);
+  return ConfigPath;
+}
+
 // 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 {
+  struct DirectoryNode {
+DirectoryNode(PathRef File) : Cache(File), Parent(nullptr) {}
+DotClangTidyCache Cache;
+DirectoryNode *Parent;
+  };
+
   const ThreadsafeFS 
   std::string RelPath;
   std::chrono::steady_clock::duration MaxStaleness;
@@ -91,45 +103,79 @@
   // 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;
-
-public:
-  DotClangTidyTree(const ThreadsafeFS )
-  : FS(FS), RelPath(".clang-tidy"), MaxStaleness(std::chrono::seconds(5)) {}
+  // We store values as linked lists pointing to their parent directories nodes,
+  // this saves quering the map for each component of a path.
+  mutable llvm::StringMap Cache;
 
-  void apply(tidy::ClangTidyOptions , PathRef AbsPath) {
+  /// Ensures there is a FileCache for each .clang-tidy file in the directory
+  /// tree up to \p AbsPath and returns a linked list structure pointing to the
+  /// first item.
+  /// \pre \p AbsPath is an absolute path to a file.
+  DirectoryNode *getNode(PathRef AbsPath) {
 namespace path = llvm::sys::path;
 assert(path::is_absolute(AbsPath));
 
-// Compute absolute paths to all ancestors (substrings of P.Path).
-// Ensure cache entries for each ancestor exist in the map.
-llvm::SmallVector Caches;
-{
-  std::lock_guard Lock(Mu);
-  for (auto Ancestor = absoluteParent(AbsPath); !Ancestor.empty();
-   Ancestor = absoluteParent(Ancestor)) {
-auto It = Cache.find(Ancestor);
-// Assemble the actual config file path only if needed.
-if (It == Cache.end()) {
-  llvm::SmallString<256> ConfigPath = Ancestor;
-  path::append(ConfigPath, RelPath);
-  It = Cache.try_emplace(Ancestor, ConfigPath.str()).first;
-}
-Caches.push_back(>second);
+// AbsPath should be pointing to a file, get the directory.
+auto Ancestor = absoluteParent(AbsPath);
+assert(!Ancestor.empty() &&
+   "There should be at least 1 path component to traverse");
+
+std::lock_guard Lock(Mu);
+
+auto It = Cache.find(Ancestor);
+// This is the hot path. After invoking this method on a given path once,
+// The path will stay in the map for the life of this object, saving any
+// further lookup.
+if (LLVM_LIKELY(It != Cache.end()))
+  return >getValue();
+
+// Build the FileCache for this item and store a pointer to its parent node,
+// this will be filled in when we process the next component in the path.
+DirectoryNode *Result =
+_emplace(Ancestor, pathAppend(Ancestor, RelPath).str())
+ .first->getValue();
+DirectoryNode **ParentPtr = >Parent;
+
+// Skip the first item as we have already processed it.
+for (Ancestor = absoluteParent(Ancestor); !Ancestor.empty();
+ Ancestor = absoluteParent(Ancestor)) {
+
+  It = Cache.find(Ancestor);
+  if (It != Cache.end()) {
+// We have found a relative parent already in the map. Update the childs
+// parent pointer to this, then stop. This items Parent should contain
+// the tree below it already.
+*ParentPtr = >getValue();
+break;
   }
+
+  // The item isn't in the cache, so assemble it.
+  auto *Node =
+  _emplace(Ancestor, pathAppend(Ancestor, RelPath).str())
+   .first->getValue();
+  *ParentPtr = Node;
+  // Keep track of this nodes parent pointer for the next iteration.
+  ParentPtr = >Parent;
 }
-// Finally query each individual file.
-// This will take a (per-file) lock for each file that actually exists.
+return Result;
+  }
+
+public:
+  DotClangTidyTree(const ThreadsafeFS )
+  : FS(FS), RelPath(".clang-tidy"), MaxStaleness(std::chrono::seconds(5)) {}
+

[PATCH] D96853: [clang][AVR] Support variable decorator '__flash'

2021-02-20 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

In D96853#2577133 , @aykevl wrote:

> I am not very familiar with Clang so I can't say much about it. Although I 
> wonder whether a macro is the right way to implement this? Is there something 
> similar in other targets? (GPUs tend to have lots of address spaces, you 
> could take a look there).

A macro definition is the simplest way, an alias to 
`__attribute__((address_space(0)))`. I do not find any other easy way for a 
plain keyword `__flash`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96853

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


[PATCH] D97132: [clang-tidy] Harden PreferMemberInitializerCheck

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, baloghadamsoftware, gribozavr2.
Herald added subscribers: rnkovacs, kbarton, xazax.hun, nemanjai.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Prevent warning when the values are initialized using fields that will be 
initialized later or VarDecls defined in the constructors body.
Both of these cases can't be safely fixed.
Also improve logic of finding where to insert member initializers, previously 
it could be confused by in class member initializers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97132

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
@@ -488,3 +488,48 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
 // CHECK-FIXES: {{^\ *$}}
 }
+
+struct SafeDependancy {
+  int m;
+  int n;
+  SafeDependancy(int M) : m(M) {
+// CHECK-FIXES: SafeDependancy(int M) : m(M), n(m) {
+n = m;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor
+  }
+  // We match against direct field dependancy as well as descendant field
+  // dependancy, ensure both are accounted for.
+  SafeDependancy(short M) : m(M) {
+// CHECK-FIXES: SafeDependancy(short M) : m(M), n(m + 1) {
+n = m + 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor
+  }
+};
+
+struct BadDependancy {
+  int m;
+  int n;
+  BadDependancy(int N) : n(N) {
+m = n;
+  }
+  BadDependancy(short N) : n(N) {
+m = n + 1;
+  }
+};
+
+struct InitFromVarDecl {
+  int m;
+  InitFromVarDecl() {
+// Can't apply this fix as n is declared in the body of the constructor.
+int n = 3;
+m = n;
+  }
+};
+
+struct AlreadyHasInit {
+  int m = 4;
+  AlreadyHasInit() {
+m = 3;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'm' should be initialized in a member initializer of the constructor
+  }
+};
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -8,7 +8,9 @@
 
 #include "PreferMemberInitializerCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
@@ -55,8 +57,37 @@
   return false;
 }
 
+namespace {
+AST_MATCHER_P(FieldDecl, indexNotLessThan, unsigned, Index) {
+  return Node.getFieldIndex() >= Index;
+}
+} // namespace
+
+// Checks if Field is initialised using a field that will be initialised after
+// it.
+// TODO: Probably should guard against function calls that could have side
+// effects or if they do reference another field that's initialized before this
+// field, but is modified before the assignment.
+static bool isSafeAssignment(const FieldDecl *Field, const Expr *Init,
+ const CXXConstructorDecl *Context) {
+
+  auto MemberMatcher =
+  memberExpr(hasObjectExpression(cxxThisExpr()),
+ member(fieldDecl(indexNotLessThan(Field->getFieldIndex();
+
+  auto DeclMatcher = declRefExpr(
+  to(varDecl(unless(parmVarDecl()), hasDeclContext(equalsNode(Context);
+
+  return match(expr(anyOf(MemberMatcher, DeclMatcher,
+  hasDescendant(MemberMatcher),
+  hasDescendant(DeclMatcher))),
+   *Init, Field->getASTContext())
+  .empty();
+}
+
 static const std::pair
-isAssignmentToMemberOf(const RecordDecl *Rec, const Stmt *S) {
+isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S,
+   const CXXConstructorDecl *Ctor) {
   if (const auto *BO = dyn_cast(S)) {
 if (BO->getOpcode() != BO_Assign)
   return std::make_pair(nullptr, nullptr);
@@ -69,8 +100,11 @@
 if (!Field)
   return std::make_pair(nullptr, nullptr);
 
-if (isa(ME->getBase()))
-  return std::make_pair(Field, BO->getRHS()->IgnoreParenImpCasts());
+if (!isa(ME->getBase()))
+  return std::make_pair(nullptr, nullptr);
+const auto *Init = 

[PATCH] D97003: [Clang][OpenMP] Require CUDA 9.2+ for OpenMP offloading on NVPTX target

2021-02-20 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 325262.
tianshilei1992 added a comment.

optimize error handle process


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97003

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_102-sm_35.bc
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc
  clang/test/Driver/openmp-offload-gpu.c

Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -154,17 +154,17 @@
 /// Check that the runtime bitcode library is part of the compile line. Create a bogus
 /// bitcode library and add it to the LIBRARY_PATH.
 // RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 /// The user can override default detection using --libomptarget-nvptx-bc-path=.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
 // RUN:   --libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-test.bc \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-USER %s
 
-// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_35.bc
+// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_102-sm_35.bc
 // CHK-BCLIB-USER: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
 // CHK-BCLIB-NOT: {{error:|warning:}}
 
@@ -173,23 +173,33 @@
 /// Check that the warning is thrown when the libomptarget bitcode library is not found.
 /// Libomptarget requires sm_35 or newer so an sm_35 bitcode library should never exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_102-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
 
 /// ###
 
 /// Check that the error is thrown when the libomptarget bitcode library does not exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s
 
 // CHK-BCLIB-ERROR: Bitcode library 'not-exist.bc' does not exist.
 
+/// ###
+
+/// Check that the error is thrown when CUDA 9.1 or lower version is used.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_90/usr/local/cuda \
+// RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-CUDA-VERSION-ERROR %s
+
+// CHK-CUDA-VERSION-ERROR: NVPTX target requires CUDA 9.2 or above. CUDA 9.0 is detected.
+
 /// Check that debug info is emitted in dwarf-2
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O1 --no-cuda-noopt-device-debug 2>&1 \
 // RUN:   | FileCheck -check-prefix=DEBUG_DIRECTIVES %s
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- 

[PATCH] D97003: [Clang][OpenMP] Require CUDA 9.2+ for OpenMP offloading on NVPTX target

2021-02-20 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 325261.
tianshilei1992 added a comment.

update test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97003

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_102-sm_35.bc
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc
  clang/test/Driver/openmp-offload-gpu.c

Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -154,17 +154,17 @@
 /// Check that the runtime bitcode library is part of the compile line. Create a bogus
 /// bitcode library and add it to the LIBRARY_PATH.
 // RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 /// The user can override default detection using --libomptarget-nvptx-bc-path=.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
 // RUN:   --libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-test.bc \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-USER %s
 
-// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_35.bc
+// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_102-sm_35.bc
 // CHK-BCLIB-USER: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
 // CHK-BCLIB-NOT: {{error:|warning:}}
 
@@ -173,23 +173,33 @@
 /// Check that the warning is thrown when the libomptarget bitcode library is not found.
 /// Libomptarget requires sm_35 or newer so an sm_35 bitcode library should never exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_102-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
 
 /// ###
 
 /// Check that the error is thrown when the libomptarget bitcode library does not exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s
 
 // CHK-BCLIB-ERROR: Bitcode library 'not-exist.bc' does not exist.
 
+/// ###
+
+/// Check that the error is thrown when CUDA 9.1 or lower version is used.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_90/usr/local/cuda \
+// RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-CUDA-VERSION-ERROR %s
+
+// CHK-CUDA-VERSION-ERROR: NVPTX target requires CUDA 9.2 or above. CUDA 9.0 is detected.
+
 /// Check that debug info is emitted in dwarf-2
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O1 --no-cuda-noopt-device-debug 2>&1 \
 // RUN:   | FileCheck -check-prefix=DEBUG_DIRECTIVES %s
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- 

[PATCH] D96838: Add GNU attribute 'retain'

2021-02-20 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/test/CodeGen/attr-retain.c:11
+/// Set !retain only on ELF platforms.
+// NORETAIN-NOT: !retain
+

There are no `FileCheck --check-prefixes=NORETAIN` invocations so this is 
unused.



Comment at: clang/test/CodeGen/attr-retain.c:21
+int g1 __attribute__((retain));
+__attribute__((retain)) static int g2;
+__attribute__((used,retain)) static int g3;

Would it be possible to also include negative check for `g2`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96838

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


[PATCH] D96853: [clang][AVR] Support variable decorator '__flash'

2021-02-20 Thread Ayke via Phabricator via cfe-commits
aykevl added a comment.

I am not very familiar with Clang so I can't say much about it. Although I 
wonder whether the macro is the right way to implement this? Is there something 
similar in other targets? (GPUs tend to have lots of address spaces, you could 
take a look there).




Comment at: clang/test/CodeGen/address-space-avr.c:3-4
 
 // Test that function declarations in nonzero address spaces without prototype
 // are called correctly.
 

This comment is now out of date.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96853

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


[PATCH] D96147: [SEMA] Added warn_decl_shadow support for structured bindings

2021-02-20 Thread David Crook via Phabricator via cfe-commits
Vexthil updated this revision to Diff 325256.
Vexthil added a comment.

Fixing clang format issues. The SemaDecl.cpp has a pile of incorrect clang 
format issues but i've only updated changes relevant to changes I have made


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96147

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/warn-shadow.cpp

Index: clang/test/SemaCXX/warn-shadow.cpp
===
--- clang/test/SemaCXX/warn-shadow.cpp
+++ clang/test/SemaCXX/warn-shadow.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -Wshadow-all %s
+// RUN: %clang_cc1 -verify -fsyntax-only -std=c++17 -Wshadow-all %s
 
 namespace {
   int i; // expected-note {{previous declaration is here}}
@@ -265,3 +265,34 @@
 PR24718_1 // Does not shadow a type.
   };
 };
+
+namespace structured_binding_tests {
+int x; // expected-note {{previous declaration is here}}
+int y; // expected-note {{previous declaration is here}}
+struct S {
+  int a, b;
+};
+
+void test1() {
+  const auto [x, y] = S(); // expected-warning 2 {{declaration shadows a variable in namespace 'structured_binding_tests'}}
+}
+
+void test2() {
+  int a; // expected-note {{previous declaration is here}}
+  bool b; // expected-note {{previous declaration is here}}
+  {
+auto [a, b] = S(); // expected-warning 2 {{declaration shadows a local variable}}
+  }
+}
+
+class A
+{
+  int m_a; // expected-note {{previous declaration is here}}
+  int m_b; // expected-note {{previous declaration is here}}
+
+  void test3() {
+auto [m_a, m_b] = S(); // expected-warning 2 {{declaration shadows a field of 'structured_binding_tests::A'}}
+  }
+};
+
+}; // namespace structured_binding_tests
\ No newline at end of file
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -857,17 +857,25 @@
   Previous.clear();
 }
 
+auto *BD = BindingDecl::Create(Context, DC, B.NameLoc, B.Name);
+
+// Find the shadowed declaration before filtering for scope.
+NamedDecl *ShadowedDecl = D.getCXXScopeSpec().isEmpty()
+  ? getShadowedDeclaration(BD, Previous)
+  : nullptr;
+
 bool ConsiderLinkage = DC->isFunctionOrMethod() &&
DS.getStorageClassSpec() == DeclSpec::SCS_extern;
 FilterLookupForScope(Previous, DC, S, ConsiderLinkage,
  /*AllowInlineNamespace*/false);
+
 if (!Previous.empty()) {
   auto *Old = Previous.getRepresentativeDecl();
   Diag(B.NameLoc, diag::err_redefinition) << B.Name;
   Diag(Old->getLocation(), diag::note_previous_definition);
+} else if (ShadowedDecl && !D.isRedeclaration()) {
+  CheckShadow(BD, ShadowedDecl, Previous);
 }
-
-auto *BD = BindingDecl::Create(Context, DC, B.NameLoc, B.Name);
 PushOnScopeChains(BD, S, true);
 Bindings.push_back(BD);
 ParsingInitForAutoVars.insert(BD);
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -7540,9 +7540,8 @@
 return nullptr;
 
   NamedDecl *ShadowedDecl = R.getFoundDecl();
-  return isa(ShadowedDecl) || isa(ShadowedDecl)
- ? ShadowedDecl
- : nullptr;
+  return isa(ShadowedDecl) ? ShadowedDecl
+: nullptr;
 }
 
 /// Return the declaration shadowed by the given typedef \p D, or null
@@ -7560,6 +7559,18 @@
   return isa(ShadowedDecl) ? ShadowedDecl : nullptr;
 }
 
+/// Return the declaration shadowed by the given variable \p D, or null
+/// if it doesn't shadow any declaration or shadowing warnings are disabled.
+NamedDecl *Sema::getShadowedDeclaration(const BindingDecl *D,
+const LookupResult ) {
+  if (!shouldWarnIfShadowedDecl(Diags, R))
+return nullptr;
+
+  NamedDecl *ShadowedDecl = R.getFoundDecl();
+  return isa(ShadowedDecl) ? ShadowedDecl
+: nullptr;
+}
+
 /// Diagnose variable or built-in function shadowing.  Implements
 /// -Wshadow.
 ///
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -2598,6 +2598,8 @@
   NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D,
 const LookupResult );
   NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult );
+  NamedDecl *getShadowedDeclaration(const BindingDecl *D,
+const 

[clang-tools-extra] 557d2ad - [NFC] Refactor PreferMemberInitializerCheck

2021-02-20 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-02-20T23:35:58Z
New Revision: 557d2ade016f3e228e90aab317b94f804e0bc1cd

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

LOG: [NFC] Refactor PreferMemberInitializerCheck

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index 2d7500943860..55d3576612d0 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -151,20 +151,16 @@ void PreferMemberInitializerCheck::check(
   (!isa(Class->getDeclContext()) ||
!cast(Class->getDeclContext())->isUnion()) &&
   shouldBeDefaultMemberInitializer(InitValue)) {
-auto Diag =
-diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
-   " default member initializer")
-<< Field;
 
 SourceLocation FieldEnd =
 Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
*Result.SourceManager, getLangOpts());
-Diag << FixItHint::CreateInsertion(FieldEnd,
-   UseAssignment ? " = " : "{")
- << FixItHint::CreateInsertionFromRange(
-FieldEnd,
-CharSourceRange(InitValue->getSourceRange(), true))
- << FixItHint::CreateInsertion(FieldEnd, UseAssignment ? "" : "}");
+SmallString<128> Insertion(
+{UseAssignment ? " = " : "{",
+ Lexer::getSourceText(
+ CharSourceRange(InitValue->getSourceRange(), true),
+ *Result.SourceManager, getLangOpts()),
+ UseAssignment ? "" : "}"});
 
 SourceLocation SemiColonEnd =
 Lexer::findNextToken(S->getEndLoc(), *Result.SourceManager,
@@ -173,13 +169,12 @@ void PreferMemberInitializerCheck::check(
 CharSourceRange StmtRange =
 CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);
 
-Diag << FixItHint::CreateRemoval(StmtRange);
+diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
+   " default member initializer")
+<< Field << FixItHint::CreateInsertion(FieldEnd, Insertion)
+<< FixItHint::CreateRemoval(StmtRange);
   } else {
-auto Diag =
-diag(S->getBeginLoc(), "%0 should be initialized in a member"
-   " initializer of the constructor")
-<< Field;
-
+SmallString<128> Insertion;
 bool AddComma = false;
 if (!Ctor->getNumCtorInitializers() && FirstToCtorInits) {
   SourceLocation BodyPos = Ctor->getBody()->getBeginLoc();
@@ -193,13 +188,13 @@ void PreferMemberInitializerCheck::check(
   InsertPos = Lexer::getLocForEndOfToken(
   InsertPos, 0, *Result.SourceManager, getLangOpts());
 
-  Diag << FixItHint::CreateInsertion(InsertPos, " : ");
+  Insertion = " : ";
 } else {
   bool Found = false;
+  unsigned Index = Field->getFieldIndex();
   for (const auto *Init : Ctor->inits()) {
 if (Init->isMemberInitializer()) {
-  if (Result.SourceManager->isBeforeInTranslationUnit(
-  Field->getLocation(), Init->getMember()->getLocation())) 
{
+  if (Index < Init->getMember()->getFieldIndex()) {
 InsertPos = Init->getSourceLocation();
 Found = true;
 break;
@@ -213,19 +208,17 @@ void PreferMemberInitializerCheck::check(
   (*Ctor->init_rbegin())->getSourceRange().getEnd(), 0,
   *Result.SourceManager, getLangOpts());
 }
-Diag << FixItHint::CreateInsertion(InsertPos, ", ");
+Insertion = ", ";
   } else {
 AddComma = true;
   }
 }
-Diag << FixItHint::CreateInsertion(InsertPos, Field->getName())
- << FixItHint::CreateInsertion(InsertPos, "(")
- << FixItHint::CreateInsertionFromRange(
-InsertPos,
-CharSourceRange(InitValue->getSourceRange(), true))
- << FixItHint::CreateInsertion(InsertPos, ")");
-if (AddComma)
-  Diag << FixItHint::CreateInsertion(InsertPos, ", ");
+Insertion.append(
+{Field->getName(), "(",
+ Lexer::getSourceText(
+ 

[PATCH] D96147: [SEMA] Added warn_decl_shadow support for structured bindings

2021-02-20 Thread David Crook via Phabricator via cfe-commits
Vexthil updated this revision to Diff 325252.
Vexthil added a comment.

Update with changes suggested by @rsmith .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96147

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/warn-shadow.cpp

Index: clang/test/SemaCXX/warn-shadow.cpp
===
--- clang/test/SemaCXX/warn-shadow.cpp
+++ clang/test/SemaCXX/warn-shadow.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -Wshadow-all %s
+// RUN: %clang_cc1 -verify -fsyntax-only -std=c++17 -Wshadow-all %s
 
 namespace {
   int i; // expected-note {{previous declaration is here}}
@@ -265,3 +265,34 @@
 PR24718_1 // Does not shadow a type.
   };
 };
+
+namespace structured_binding_tests {
+int x; // expected-note {{previous declaration is here}}
+int y; // expected-note {{previous declaration is here}}
+struct S {
+  int a, b;
+};
+
+void test1() {
+  const auto [x, y] = S(); // expected-warning 2 {{declaration shadows a variable in namespace 'structured_binding_tests'}}
+}
+
+void test2() {
+  int a; // expected-note {{previous declaration is here}}
+  bool b; // expected-note {{previous declaration is here}}
+  {
+auto [a, b] = S(); // expected-warning 2 {{declaration shadows a local variable}}
+  }
+}
+
+class A
+{
+  int m_a; // expected-note {{previous declaration is here}}
+  int m_b; // expected-note {{previous declaration is here}}
+
+  void test3() {
+auto [m_a, m_b] = S(); // expected-warning 2 {{declaration shadows a field of 'structured_binding_tests::A'}}
+  }
+};
+
+}; // namespace structured_binding_tests
\ No newline at end of file
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -857,17 +857,25 @@
   Previous.clear();
 }
 
+auto *BD = BindingDecl::Create(Context, DC, B.NameLoc, B.Name);
+
+// Find the shadowed declaration before filtering for scope.
+NamedDecl *ShadowedDecl = D.getCXXScopeSpec().isEmpty()
+  ? getShadowedDeclaration(BD, Previous)
+  : nullptr;
+
 bool ConsiderLinkage = DC->isFunctionOrMethod() &&
DS.getStorageClassSpec() == DeclSpec::SCS_extern;
 FilterLookupForScope(Previous, DC, S, ConsiderLinkage,
  /*AllowInlineNamespace*/false);
+
 if (!Previous.empty()) {
   auto *Old = Previous.getRepresentativeDecl();
   Diag(B.NameLoc, diag::err_redefinition) << B.Name;
   Diag(Old->getLocation(), diag::note_previous_definition);
+} else if (ShadowedDecl && !D.isRedeclaration()) {
+  CheckShadow(BD, ShadowedDecl, Previous);
 }
-
-auto *BD = BindingDecl::Create(Context, DC, B.NameLoc, B.Name);
 PushOnScopeChains(BD, S, true);
 Bindings.push_back(BD);
 ParsingInitForAutoVars.insert(BD);
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -7540,7 +7540,7 @@
 return nullptr;
 
   NamedDecl *ShadowedDecl = R.getFoundDecl();
-  return isa(ShadowedDecl) || isa(ShadowedDecl)
+  return isa(ShadowedDecl)
  ? ShadowedDecl
  : nullptr;
 }
@@ -7560,6 +7560,19 @@
   return isa(ShadowedDecl) ? ShadowedDecl : nullptr;
 }
 
+/// Return the declaration shadowed by the given variable \p D, or null
+/// if it doesn't shadow any declaration or shadowing warnings are disabled.
+NamedDecl *Sema::getShadowedDeclaration(const BindingDecl *D,
+const LookupResult ) {
+  if (!shouldWarnIfShadowedDecl(Diags, R))
+return nullptr;
+
+  NamedDecl *ShadowedDecl = R.getFoundDecl();
+  return isa(ShadowedDecl)
+ ? ShadowedDecl
+ : nullptr;
+}
+
 /// Diagnose variable or built-in function shadowing.  Implements
 /// -Wshadow.
 ///
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -2598,6 +2598,8 @@
   NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D,
 const LookupResult );
   NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult );
+  NamedDecl *getShadowedDeclaration(const BindingDecl *D,
+const LookupResult );
   void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
const LookupResult );
   void CheckShadow(Scope *S, VarDecl *D);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ 

[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-02-20 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:908
 
+CodeGenerator *CodeGenAction::getCodeGenerator() const {
+  return BEConsumer->getCodeGenerator();

lhames wrote:
> v.g.vassilev wrote:
> > sgraenitz wrote:
> > > v.g.vassilev wrote:
> > > > @rjmccall, we were wondering if there is a better way to ask CodeGen to 
> > > > start a new module. The current approach seems to be drilling hole in a 
> > > > number of abstraction layers.
> > > > 
> > > > In the past we have touched that area a little in 
> > > > https://reviews.llvm.org/D3 and the answer may be already there but 
> > > > I fail to connect the dots.
> > > > 
> > > > Recently, we thought about having a new FrontendAction callback for 
> > > > beginning a new phase when compiling incremental input. We need to keep 
> > > > track of the created objects (needed for error recovery) in our 
> > > > Transaction. We can have a map of `Transaction*` to `llvm::Module*` in 
> > > > CodeGen. The issue is that new JITs take ownership of the 
> > > > `llvm::Module*` which seems to make it impossible to support jitted 
> > > > code removal with that model (cc: @lhames, @rsmith).
> > > When compiling incrementally, doeas a "new phase" mean that all 
> > > subsequent code will go into a new module from then on? How will 
> > > dependencies to previous symbols be handled? Are all symbols external?
> > > 
> > > > The issue is that new JITs take ownership of the llvm::Module*
> > > 
> > > That's true, but you can still keep a raw pointer to it, which will be 
> > > valid at least as long as the module wasn't linked. Afterwards it depends 
> > > on the linker:
> > > * RuntimeDyld can return ownership of the object's memory range via 
> > > `NotifyEmittedFunction`
> > > * JITLink provides the `ReturnObjectBufferFunction` for the same purpose
> > > 
> > > > seems to make it impossible to support jitted code removal with that 
> > > > model
> > > 
> > > Can you figure out what symbols are affected and remove these? A la: 
> > > https://github.com/llvm/llvm-project/blob/13f4448ae7db1a47/llvm/include/llvm/ExecutionEngine/Orc/Core.h#L1020
> > > 
> > > I think @anarazel has ported a client with code removal to OrcV2 
> > > successfully in the past. Maybe there's something we can learn from it.
> > > When compiling incrementally, doeas a "new phase" mean that all 
> > > subsequent code will go into a new module from then on? How will 
> > > dependencies to previous symbols be handled? Are all symbols external?
> > 
> > There is some discussion on this here https://reviews.llvm.org/D3#812418
> > 
> > I think the relevant bit is that 'we have just one ever growing TU [...] 
> > which we send to the RuntimeDyLD allowing only JIT to resolve symbols from 
> > it.  We aid the JIT when resolving symbols with internal linkage by 
> > changing all internal linkage to external (We haven't seen issues with that 
> > approach)'.
> > 
> > > 
> > > > The issue is that new JITs take ownership of the llvm::Module*
> > > 
> > > That's true, but you can still keep a raw pointer to it, which will be 
> > > valid at least as long as the module wasn't linked. 
> > 
> > That was my first implementation when I upgraded cling to llvm9 where the 
> > `shared_ptr`s went to `unique_ptr`s. This was quite problematic for many of 
> > the use cases we support as the JIT is somewhat unpredictable to the 
> > high-level API user. 
> > 
> > 
> > >Afterwards it depends on the linker:
> > > * RuntimeDyld can return ownership of the object's memory range via 
> > > `NotifyEmittedFunction`
> > > * JITLink provides the `ReturnObjectBufferFunction` for the same purpose
> > > 
> > 
> > That's exactly what we ended up doing (I would like to thank Lang here who 
> > gave a similar advice).
> > 
> > > > seems to make it impossible to support jitted code removal with that 
> > > > model
> > > 
> > > Can you figure out what symbols are affected and remove these? A la: 
> > > https://github.com/llvm/llvm-project/blob/13f4448ae7db1a47/llvm/include/llvm/ExecutionEngine/Orc/Core.h#L1020
> > > 
> > > I think @anarazel has ported a client with code removal to OrcV2 
> > > successfully in the past. Maybe there's something we can learn from it.
> > 
> > Indeed. That's not yet on my radar as seemed somewhat distant in time.
> > 
> > Recently, we thought about having a new FrontendAction callback for 
> > beginning a new phase when compiling incremental input. We need to keep 
> > track of the created objects (needed for error recovery) in our 
> > Transaction. We can have a map of Transaction* to llvm::Module* in CodeGen. 
> > The issue is that new JITs take ownership of the llvm::Module* which seems 
> > to make it impossible to support jitted code removal with that model (cc: 
> > @lhames, @rsmith).
> 
> In the new APIs, in order to enable removable code, you can associate Modules 
> with ResourceTrackers when they're added to the JIT. The 

[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-02-20 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 325249.
v.g.vassilev marked 7 inline comments as done.
v.g.vassilev added a comment.

Address Lang's comments.


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

https://reviews.llvm.org/D96033

Files:
  clang/include/clang/CodeGen/CodeGenAction.h
  clang/include/clang/Frontend/FrontendAction.h
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Transaction.h
  clang/lib/CMakeLists.txt
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/CMakeLists.txt
  clang/test/Interpreter/execute.c
  clang/test/Interpreter/sanity.c
  clang/tools/CMakeLists.txt
  clang/tools/clang-repl/CMakeLists.txt
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/CMakeLists.txt
  clang/unittests/CodeGen/CMakeLists.txt
  clang/unittests/CodeGen/IncrementalProcessingTest.cpp
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- /dev/null
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -0,0 +1,92 @@
+//===- unittests/Interpreter/InterpreterTest.cpp --- Interpreter tests ===//
+//
+// 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
+//
+//===--===//
+//
+// Unit tests for Clang's Interpreter library.
+//
+//===--===//
+
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+
+#include "llvm/ADT/ArrayRef.h"
+
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+
+static std::unique_ptr createInterpreter() {
+  std::vector ClangArgs = {"-Xclang", "-emit-llvm-only"};
+  auto CI = cantFail(clang::IncrementalCompilerBuilder::create(ClangArgs));
+  return cantFail(clang::Interpreter::create(std::move(CI)));
+}
+
+TEST(InterpreterTest, Sanity) {
+  std::unique_ptr Interp = createInterpreter();
+  Transaction (cantFail(Interp->Parse("void g(); void g() {}")));
+  EXPECT_EQ(2U, R1.Decls.size());
+
+  Transaction (cantFail(Interp->Parse("int i;")));
+  EXPECT_EQ(1U, R2.Decls.size());
+}
+
+static std::string DeclToString(DeclGroupRef DGR) {
+  return llvm::cast(DGR.getSingleDecl())->getQualifiedNameAsString();
+}
+
+TEST(InterpreterTest, IncrementalInputTopLevelDecls) {
+  std::unique_ptr Interp = createInterpreter();
+  auto R1OrErr = Interp->Parse("int var1 = 42; int f() { return var1; }");
+  // gtest doesn't expand into explicit bool conversions.
+  EXPECT_TRUE(!!R1OrErr);
+  auto R1 = R1OrErr->Decls;
+  EXPECT_EQ(2U, R1.size());
+  EXPECT_EQ("var1", DeclToString(R1[0]));
+  EXPECT_EQ("f", DeclToString(R1[1]));
+
+  auto R2OrErr = Interp->Parse("int var2 = f();");
+  EXPECT_TRUE(!!R2OrErr);
+  auto R2 = R2OrErr->Decls;
+  EXPECT_EQ(1U, R2.size());
+  EXPECT_EQ("var2", DeclToString(R2[0]));
+}
+
+
+TEST(InterpreterTest, Errors) {
+  std::unique_ptr Interp = createInterpreter();
+  auto Err = Interp->Parse("intentional_error v1 = 42; ").takeError();
+  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+
+  EXPECT_DEATH((void)Interp->Parse("int var1 = 42;"), "");
+}
+
+// Here we test whether the user can mix declarations and statements. The
+// interpreter should be smart enough to recognize the declarations from the
+// statements and wrap the latter into a declaration, producing valid code.
+TEST(InterpreterTest, DeclsAndStatements) {
+  std::unique_ptr Interp = createInterpreter();
+  auto R1OrErr = Interp->Parse(
+  "int var1 = 42; extern \"C\" int printf(const char*, ...);");
+  // gtest doesn't expand into explicit bool conversions.
+  EXPECT_TRUE(!!R1OrErr);
+
+  auto R1 = R1OrErr->Decls;
+  EXPECT_EQ(2U, R1.size());
+
+  // FIXME: Add support for wrapping and running statements.
+  auto R2OrErr =
+Interp->Parse("var1++; printf(\"var1 value is %d\\n\", var1);");
+  EXPECT_FALSE(!!R2OrErr);
+  auto Err = R2OrErr.takeError();
+  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+}
+
+} // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- /dev/null
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -0,0 +1,10 @@
+set(LLVM_LINK_COMPONENTS
+  )
+
+add_clang_unittest(ClangReplInterpreterTests
+  InterpreterTest.cpp
+  )

[PATCH] D97125: Stop traping on sNaN in __builtin_isinf

2021-02-20 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre created this revision.
thopre added reviewers: kpn, efriedma, mibintc, sepavloff, rjmccall.
Herald added a subscriber: pengfei.
thopre requested review of this revision.
Herald added a project: clang.

__builtin_isinf currently generates a floating-point compare operation
which triggers a trap when faced with a signaling NaN in StrictFP mode.
This commit uses integer operations instead to not generate any trap in
such a case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97125

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/X86/strictfp_builtins.c
  clang/test/CodeGen/aarch64-strictfp-builtins.c
  clang/test/CodeGen/strictfp_builtins.c

Index: clang/test/CodeGen/strictfp_builtins.c
===
--- clang/test/CodeGen/strictfp_builtins.c
+++ clang/test/CodeGen/strictfp_builtins.c
@@ -55,18 +55,37 @@
   return;
 }
 
-// CHECK-LABEL: @test_isinf(
+// CHECK-LABEL: @test_float_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:[[LD_ADDR:%.*]] = alloca float, align 4
+// CHECK-NEXT:store float [[F:%.*]], float* [[LD_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load float, float* [[LD_ADDR]], align 4
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast float [[TMP0]] to i32
+// CHECK-NEXT:[[SHL1:%.*]] = shl i32 [[BITCAST]], 1
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[SHL1]], -16777216
+// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+//
+void test_float_isinf(float f) {
+  P(isinf, (f));
+
+  return;
+}
+
+// CHECK-LABEL: @test_double_isinf(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LD_ADDR:%.*]] = alloca double, align 8
+// CHECK-NEXT:store double [[D:%.*]], double* [[LD_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load double, double* [[LD_ADDR]], align 8
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast double [[TMP0]] to i64
+// CHECK-NEXT:[[SHL1:%.*]] = shl i64 [[BITCAST]], 1
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq i64 [[SHL1]], -9007199254740992
+// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
-void test_isinf(double d) {
+void test_double_isinf(double d) {
   P(isinf, (d));
 
   return;
@@ -83,7 +102,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = icmp slt i64 [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = select i1 [[TMP3]], i32 -1, i32 1
 // CHECK-NEXT:[[TMP5:%.*]] = select i1 [[ISINF]], i32 [[TMP4]], i32 0
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 [[TMP5]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 [[TMP5]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_isinf_sign(double d) {
@@ -101,7 +120,7 @@
 // CHECK-NEXT:[[ABS:%.*]] = and i32 [[BITCAST]], [[#%u,0x7FFF]]
 // CHECK-NEXT:[[TMP1:%.*]] = sub i32 [[#%u,0x7F80]], [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i32 [[TMP1]], 31
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 [[ISNAN]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 [[ISNAN]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_float_isnan(float f) {
@@ -120,7 +139,7 @@
 // CHECK-NEXT:[[TMP1:%.*]] = sub i64 [[#%u,0x7FF0]], [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i64 [[TMP1]], 63
 // CHECK-NEXT:[[RES:%.*]] = trunc i64 [[ISNAN]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_double_isnan(double d) {
@@ -141,7 +160,7 @@
 // CHECK-NEXT:[[AND:%.*]] = and i1 [[ISEQ]], [[ISINF]]
 // CHECK-NEXT:[[AND1:%.*]] = and i1 [[AND]], [[ISNORMAL]]
 // CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[AND1]] to i32
-// CHECK-NEXT:call void @p(i8* 

[PATCH] D96132: [clang-tidy] Simplify throw keyword missing check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG77056fe58e83: [clang-tidy] Simplify throw keyword missing 
check (authored by stephenkelly).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96132

Files:
  clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -94,8 +94,17 @@
 template 
 void f(int i, Exception excToBeThrown) {}
 
+template 
+void templ(int i) {
+  if (i > 0)
+SomeType();
+}
+
 void funcCallWithTempExcTest() {
   f(5, RegularException());
+
+  templ(4);
+  templ(4);
 }
 
 // Global variable initialization test.
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
@@ -29,6 +29,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -21,17 +21,16 @@
   cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
 
   Finder->addMatcher(
-  expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
- cxxTemporaryObjectExpr()),
-   hasType(cxxRecordDecl(
-   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
-   unless(anyOf(hasAncestor(stmt(
-anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-hasAncestor(varDecl()),
-allOf(hasAncestor(CtorInitializerList),
-  unless(hasAncestor(cxxCatchStmt()))
+  cxxConstructExpr(
+  hasType(cxxRecordDecl(
+  isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
+  unless(anyOf(hasAncestor(stmt(
+   anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
+   hasAncestor(varDecl()),
+   allOf(hasAncestor(CtorInitializerList),
+ unless(hasAncestor(cxxCatchStmt()))
   .bind("temporary-exception-not-thrown"),
-  this); 
+  this);
 }
 
 void ThrowKeywordMissingCheck::check(const MatchFinder::MatchResult ) {


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -94,8 +94,17 @@
 template 
 void f(int i, Exception excToBeThrown) {}
 
+template 
+void templ(int i) {
+  if (i > 0)
+SomeType();
+}
+
 void funcCallWithTempExcTest() {
   f(5, RegularException());
+
+  templ(4);
+  templ(4);
 }
 
 // Global variable initialization test.
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
@@ -29,6 +29,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -21,17 +21,16 @@
   cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
 
   Finder->addMatcher(
-  expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
- 

[clang-tools-extra] 77056fe - [clang-tidy] Simplify throw keyword missing check

2021-02-20 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-20T22:07:20Z
New Revision: 77056fe58e83100b902216d7bc6274129f80abda

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

LOG: [clang-tidy] Simplify throw keyword missing check

Extend test to verify that it does not match in template instantiations.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h

clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
index 25e7bc9d91e0..462a33a374a5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -21,17 +21,16 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder 
*Finder) {
   cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
 
   Finder->addMatcher(
-  expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
- cxxTemporaryObjectExpr()),
-   hasType(cxxRecordDecl(
-   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
-   unless(anyOf(hasAncestor(stmt(
-anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-hasAncestor(varDecl()),
-allOf(hasAncestor(CtorInitializerList),
-  unless(hasAncestor(cxxCatchStmt()))
+  cxxConstructExpr(
+  hasType(cxxRecordDecl(
+  isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
+  unless(anyOf(hasAncestor(stmt(
+   anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
+   hasAncestor(varDecl()),
+   allOf(hasAncestor(CtorInitializerList),
+ unless(hasAncestor(cxxCatchStmt()))
   .bind("temporary-exception-not-thrown"),
-  this); 
+  this);
 }
 
 void ThrowKeywordMissingCheck::check(const MatchFinder::MatchResult ) {

diff  --git a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
index 0ea1faab249c..fc2203765f1c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
@@ -29,6 +29,9 @@ class ThrowKeywordMissingCheck : public ClangTidyCheck {
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace bugprone

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
index 7780089ce8f3..5fae036fc5a3 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -94,8 +94,17 @@ void nameContainsExceptionThrownTest(int i) {
 template 
 void f(int i, Exception excToBeThrown) {}
 
+template 
+void templ(int i) {
+  if (i > 0)
+SomeType();
+}
+
 void funcCallWithTempExcTest() {
   f(5, RegularException());
+
+  templ(4);
+  templ(4);
 }
 
 // Global variable initialization test.



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


[PATCH] D96131: [clang-tidy] Simplify function complexity check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6852a29a3b5b: [clang-tidy] Simplify function complexity 
check (authored by stephenkelly).

Changed prior to commit:
  https://reviews.llvm.org/D96131?vs=325226=325241#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96131

Files:
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -666,7 +666,7 @@
 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, 
nesting level increased to 2{{$}}
 }
   };
-// CHECK-NOTES: :[[@LINE-6]]:14: warning: function 'operator()' has cognitive 
complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
+// CHECK-NOTES: :[[@LINE-6]]:14: warning: lambda has cognitive complexity of 1 
(threshold 0) [readability-function-cognitive-complexity]
 // CHECK-NOTES: :[[@LINE-5]]:5: note: +1, including nesting penalty of 0, 
nesting level increased to 1{{$}}
 }
 
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
===
--- clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
+++ clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
@@ -31,6 +31,9 @@
   void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   const unsigned Threshold;
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -502,27 +502,40 @@
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   functionDecl(isDefinition(),
-   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
-isInstantiated(), isWeak(
+   unless(anyOf(isDefaulted(), isDeleted(), isWeak(
   .bind("func"),
   this);
+  Finder->addMatcher(lambdaExpr().bind("lambda"), this);
 }
 
 void FunctionCognitiveComplexityCheck::check(
 const MatchFinder::MatchResult ) {
-  const auto *Func = Result.Nodes.getNodeAs("func");
-  assert(Func->hasBody() && "The matchers should only match the functions that 
"
-"have user-provided body.");
 
   FunctionASTVisitor Visitor;
-  Visitor.TraverseDecl(const_cast(Func), true);
+  SourceLocation Loc;
+
+  const auto *TheDecl = Result.Nodes.getNodeAs("func");
+  const auto *TheLambdaExpr = Result.Nodes.getNodeAs("lambda");
+  if (TheDecl) {
+assert(TheDecl->hasBody() &&
+   "The matchers should only match the functions that "
+   "have user-provided body.");
+Loc = TheDecl->getLocation();
+Visitor.TraverseDecl(const_cast(TheDecl), true);
+  } else {
+Loc = TheLambdaExpr->getBeginLoc();
+Visitor.TraverseLambdaExpr(const_cast(TheLambdaExpr));
+  }
 
   if (Visitor.CC.Total <= Threshold)
 return;
 
-  diag(Func->getLocation(),
-   "function %0 has cognitive complexity of %1 (threshold %2)")
-  << Func << Visitor.CC.Total << Threshold;
+  if (TheDecl)
+diag(Loc, "function %0 has cognitive complexity of %1 (threshold %2)")
+<< TheDecl << Visitor.CC.Total << Threshold;
+  else
+diag(Loc, "lambda has cognitive complexity of %0 (threshold %1)")
+<< Visitor.CC.Total << Threshold;
 
   // Output all the basic increments of complexity.
   for (const auto  : Visitor.CC.Details) {


Index: clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -666,7 +666,7 @@
 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
 }
   };
-// CHECK-NOTES: 

[clang-tools-extra] 6852a29 - [clang-tidy] Simplify function complexity check

2021-02-20 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-20T22:06:16Z
New Revision: 6852a29a3b5b7858757c175f39e04676fb856dab

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

LOG: [clang-tidy] Simplify function complexity check

Update test to note use of lambda instead of the invisible operator().

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

Added: 


Modified: 

clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h

clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index 88a422ab45a3..3a4758302406 100644
--- 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -502,27 +502,40 @@ void FunctionCognitiveComplexityCheck::storeOptions(
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   functionDecl(isDefinition(),
-   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
-isInstantiated(), isWeak(
+   unless(anyOf(isDefaulted(), isDeleted(), isWeak(
   .bind("func"),
   this);
+  Finder->addMatcher(lambdaExpr().bind("lambda"), this);
 }
 
 void FunctionCognitiveComplexityCheck::check(
 const MatchFinder::MatchResult ) {
-  const auto *Func = Result.Nodes.getNodeAs("func");
-  assert(Func->hasBody() && "The matchers should only match the functions that 
"
-"have user-provided body.");
 
   FunctionASTVisitor Visitor;
-  Visitor.TraverseDecl(const_cast(Func), true);
+  SourceLocation Loc;
+
+  const auto *TheDecl = Result.Nodes.getNodeAs("func");
+  const auto *TheLambdaExpr = Result.Nodes.getNodeAs("lambda");
+  if (TheDecl) {
+assert(TheDecl->hasBody() &&
+   "The matchers should only match the functions that "
+   "have user-provided body.");
+Loc = TheDecl->getLocation();
+Visitor.TraverseDecl(const_cast(TheDecl), true);
+  } else {
+Loc = TheLambdaExpr->getBeginLoc();
+Visitor.TraverseLambdaExpr(const_cast(TheLambdaExpr));
+  }
 
   if (Visitor.CC.Total <= Threshold)
 return;
 
-  diag(Func->getLocation(),
-   "function %0 has cognitive complexity of %1 (threshold %2)")
-  << Func << Visitor.CC.Total << Threshold;
+  if (TheDecl)
+diag(Loc, "function %0 has cognitive complexity of %1 (threshold %2)")
+<< TheDecl << Visitor.CC.Total << Threshold;
+  else
+diag(Loc, "lambda has cognitive complexity of %0 (threshold %1)")
+<< Visitor.CC.Total << Threshold;
 
   // Output all the basic increments of complexity.
   for (const auto  : Visitor.CC.Details) {

diff  --git 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
index 96b6723d2a6a..a21b8447029b 100644
--- 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
+++ 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
@@ -31,6 +31,9 @@ class FunctionCognitiveComplexityCheck : public 
ClangTidyCheck {
   void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   const unsigned Threshold;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
index 79bc0c3dc4de..021330ccf9fd 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -666,7 +666,7 @@ void unittest_b2_08_02() {
 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, 
nesting level increased to 2{{$}}
 }
   };
-// CHECK-NOTES: :[[@LINE-6]]:14: warning: function 'operator()' has cognitive 
complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
+// CHECK-NOTES: :[[@LINE-6]]:14: warning: lambda has cognitive complexity of 1 
(threshold 0) [readability-function-cognitive-complexity]
 // CHECK-NOTES: :[[@LINE-5]]:5: note: +1, including nesting penalty of 0, 

[PATCH] D96224: [clang-itdy] Simplify virtual near-miss check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9a4b574dd6a0: [clang-itdy] Simplify virtual near-miss check 
(authored by stephenkelly).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96224

Files:
  clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
@@ -44,9 +44,8 @@
 struct TDerived : TBase {
   virtual void tfunk(T t);
   // Should not apply fix for template.
-  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 'TDerived::tfunk' 
has {{.*}} 'TBase::tfunc'
-  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: method 'TDerived::tfunk' 
has {{.*}} 'TBase::tfunc'
-  // CHECK-FIXES: virtual void tfunk(T t);
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 'TDerived::tfunk' has 
{{.*}} 'TBase::tfunc'
+  // CHECK-FIXES: virtual void tfunc(T t);
 };
 
 TDerived T1;
Index: clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
@@ -32,6 +32,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   /// Check if the given method is possible to be overridden by some other
Index: clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
@@ -216,10 +216,9 @@
 
 void VirtualNearMissCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  cxxMethodDecl(
-  unless(anyOf(isOverride(), isImplicit(), cxxConstructorDecl(),
-   cxxDestructorDecl(), cxxConversionDecl(), isStatic(),
-   isOverloadedOperator(
+  cxxMethodDecl(unless(anyOf(isOverride(), cxxConstructorDecl(),
+ cxxDestructorDecl(), cxxConversionDecl(),
+ isStatic(), isOverloadedOperator(
   .bind("method"),
   this);
 }
@@ -234,7 +233,15 @@
   assert(DerivedRD);
 
   for (const auto  : DerivedRD->bases()) {
-if (const auto *BaseRD = BaseSpec.getType()->getAsCXXRecordDecl()) {
+const auto *BaseRD = BaseSpec.getType()->getAsCXXRecordDecl();
+if (const auto *TST =
+dyn_cast(BaseSpec.getType())) {
+  auto TN = TST->getTemplateName();
+  BaseRD =
+  dyn_cast(TN.getAsTemplateDecl()->getTemplatedDecl());
+}
+
+if (BaseRD) {
   for (const auto *BaseMD : BaseRD->methods()) {
 if (!isPossibleToBeOverridden(BaseMD))
   continue;
@@ -250,16 +257,12 @@
 auto Range = CharSourceRange::getTokenRange(
 SourceRange(DerivedMD->getLocation()));
 
-bool ApplyFix = !BaseMD->isTemplateInstantiation() &&
-!DerivedMD->isTemplateInstantiation();
-auto Diag =
-diag(DerivedMD->getBeginLoc(),
- "method '%0' has a similar name and the same signature as 
"
- "virtual method '%1'; did you mean to override it?")
+diag(DerivedMD->getBeginLoc(),
+ "method '%0' has a similar name and the same signature as "
+ "virtual method '%1'; did you mean to override it?")
 << DerivedMD->getQualifiedNameAsString()
-<< BaseMD->getQualifiedNameAsString();
-if (ApplyFix)
-  Diag << FixItHint::CreateReplacement(Range, BaseMD->getName());
+<< BaseMD->getQualifiedNameAsString()
+<< FixItHint::CreateReplacement(Range, BaseMD->getName());
   }
 }
   }


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
@@ -44,9 +44,8 @@
 struct TDerived : TBase {
   virtual void tfunk(T t);
   // Should not apply fix for template.
-  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 

[clang-tools-extra] 9a4b574 - [clang-itdy] Simplify virtual near-miss check

2021-02-20 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-20T22:02:00Z
New Revision: 9a4b574dd6a07d6811356529ebb8a3f15d6e40a2

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

LOG: [clang-itdy] Simplify virtual near-miss check

Diagnose the problem in templates in the context of the template
declaration instead of in the context of all of the (possibly very many)
template instantiations.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
index 150b517811b6..dc810c694874 100644
--- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
@@ -216,10 +216,9 @@ bool VirtualNearMissCheck::isOverriddenByDerivedClass(
 
 void VirtualNearMissCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  cxxMethodDecl(
-  unless(anyOf(isOverride(), isImplicit(), cxxConstructorDecl(),
-   cxxDestructorDecl(), cxxConversionDecl(), isStatic(),
-   isOverloadedOperator(
+  cxxMethodDecl(unless(anyOf(isOverride(), cxxConstructorDecl(),
+ cxxDestructorDecl(), cxxConversionDecl(),
+ isStatic(), isOverloadedOperator(
   .bind("method"),
   this);
 }
@@ -234,7 +233,15 @@ void VirtualNearMissCheck::check(const 
MatchFinder::MatchResult ) {
   assert(DerivedRD);
 
   for (const auto  : DerivedRD->bases()) {
-if (const auto *BaseRD = BaseSpec.getType()->getAsCXXRecordDecl()) {
+const auto *BaseRD = BaseSpec.getType()->getAsCXXRecordDecl();
+if (const auto *TST =
+dyn_cast(BaseSpec.getType())) {
+  auto TN = TST->getTemplateName();
+  BaseRD =
+  dyn_cast(TN.getAsTemplateDecl()->getTemplatedDecl());
+}
+
+if (BaseRD) {
   for (const auto *BaseMD : BaseRD->methods()) {
 if (!isPossibleToBeOverridden(BaseMD))
   continue;
@@ -250,16 +257,12 @@ void VirtualNearMissCheck::check(const 
MatchFinder::MatchResult ) {
 auto Range = CharSourceRange::getTokenRange(
 SourceRange(DerivedMD->getLocation()));
 
-bool ApplyFix = !BaseMD->isTemplateInstantiation() &&
-!DerivedMD->isTemplateInstantiation();
-auto Diag =
-diag(DerivedMD->getBeginLoc(),
- "method '%0' has a similar name and the same signature as 
"
- "virtual method '%1'; did you mean to override it?")
+diag(DerivedMD->getBeginLoc(),
+ "method '%0' has a similar name and the same signature as "
+ "virtual method '%1'; did you mean to override it?")
 << DerivedMD->getQualifiedNameAsString()
-<< BaseMD->getQualifiedNameAsString();
-if (ApplyFix)
-  Diag << FixItHint::CreateReplacement(Range, BaseMD->getName());
+<< BaseMD->getQualifiedNameAsString()
+<< FixItHint::CreateReplacement(Range, BaseMD->getName());
   }
 }
   }

diff  --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
index 69ae278f2e2c..ec902515f706 100644
--- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
@@ -32,6 +32,9 @@ class VirtualNearMissCheck : public ClangTidyCheck {
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   /// Check if the given method is possible to be overridden by some other

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
index 553d2f45a98b..f3f8d3225847 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
@@ -44,9 +44,8 @@ template 
 struct TDerived : TBase {
   virtual void tfunk(T t);
   // Should not apply fix for template.
-  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 'TDerived::tfunk' 
has {{.*}} 'TBase::tfunc'
-  // 

[PATCH] D97003: [Clang][OpenMP] Require CUDA 9.2+ for OpenMP offloading on NVPTX target

2021-02-20 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 325235.
tianshilei1992 added a comment.

fixed the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97003

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_102-sm_35.bc
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc
  clang/test/Driver/openmp-offload-gpu.c

Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -154,17 +154,17 @@
 /// Check that the runtime bitcode library is part of the compile line. Create a bogus
 /// bitcode library and add it to the LIBRARY_PATH.
 // RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 /// The user can override default detection using --libomptarget-nvptx-bc-path=.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
 // RUN:   --libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-test.bc \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-USER %s
 
-// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_35.bc
+// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_102-sm_35.bc
 // CHK-BCLIB-USER: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
 // CHK-BCLIB-NOT: {{error:|warning:}}
 
@@ -173,23 +173,33 @@
 /// Check that the warning is thrown when the libomptarget bitcode library is not found.
 /// Libomptarget requires sm_35 or newer so an sm_35 bitcode library should never exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_102-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
 
 /// ###
 
 /// Check that the error is thrown when the libomptarget bitcode library does not exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s
 
 // CHK-BCLIB-ERROR: Bitcode library 'not-exist.bc' does not exist.
 
+/// ###
+
+/// Check that the error is thrown when CUDA 9.1 or lower version is used.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_90/usr/local/cuda \
+// RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-CUDA-VERSION-ERROR %s
+
+// CHK-CUDA-VERSION-ERROR: NVPTX target requires CUDA 9.2 or above. CUDA 9.0 is detected.
+
 /// Check that debug info is emitted in dwarf-2
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O1 --no-cuda-noopt-device-debug 2>&1 \
 // RUN:   | FileCheck -check-prefix=DEBUG_DIRECTIVES %s
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- 

[PATCH] D96224: [clang-itdy] Simplify virtual near-miss check

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

Fair enough, LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96224

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


[PATCH] D96838: Add GNU attribute 'retain'

2021-02-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 325233.
MaskRay retitled this revision from "CodeGen: Set !retain metadata on UsedAttr 
definitions for FreeBSD/Fuchsia/Linux" to "Add GNU attribute 'retain'".
MaskRay edited the summary of this revision.
MaskRay added a comment.
Herald added a reviewer: aaron.ballman.

Add 'retain' instead (latest GCC resolution)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96838

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/attr-retain.c
  clang/test/CodeGenCXX/attr-retain.cpp
  clang/test/CodeGenCXX/extern-c.cpp
  clang/test/Sema/attr-retain.c

Index: clang/test/Sema/attr-retain.c
===
--- /dev/null
+++ clang/test/Sema/attr-retain.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+extern char test1[] __attribute__((retain)); // expected-warning {{'retain' attribute ignored}}
+extern const char test2[] __attribute__((retain)); // expected-warning {{'retain' attribute ignored}}
+const char test3[] __attribute__((retain)) = "";
+
+void foo() {
+  int l __attribute__((retain)); // expected-warning {{'retain' attribute only applies to variables with non-local storage, functions, and Objective-C methods}}
+}
Index: clang/test/CodeGenCXX/extern-c.cpp
===
--- clang/test/CodeGenCXX/extern-c.cpp
+++ clang/test/CodeGenCXX/extern-c.cpp
@@ -75,11 +75,14 @@
   // CHECK-NOT: @unused
   // CHECK-NOT: @duplicate_internal
   // CHECK: @internal_var = internal alias i32, i32* @_ZL12internal_var
+  // CHECK-NOT: !retain
   // CHECK-NOT: @unused
   // CHECK-NOT: @duplicate_internal
   // CHECK: @internal_fn = internal alias i32 (), i32 ()* @_ZL11internal_fnv
+  // CHECK-NOT: !retain
   // CHECK-NOT: @unused
   // CHECK-NOT: @duplicate_internal
+  // CHECK: define internal i32 @_ZL11internal_fnv()
 }
 
 namespace PR19411 {
Index: clang/test/CodeGenCXX/attr-retain.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/attr-retain.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - | FileCheck %s
+
+struct X0 {
+  // RETAIN: define linkonce_odr{{.*}} @_ZN2X0C1Ev({{.*}} !retain
+  __attribute__((used,retain)) X0() {}
+  // RETAIN: define linkonce_odr{{.*}} @_ZN2X0D1Ev({{.*}} !retain
+  __attribute__((used,retain)) ~X0() {}
+};
+
+struct X1 {
+  struct Nested {
+// RETAIN-NOT: 2f0Ev
+// RETAIN: define linkonce_odr{{.*}} @_ZN2X16Nested2f1Ev({{.*}} !retain
+void __attribute__((retain)) f0() {}
+void __attribute__((used,retain)) f1() {}
+  };
+};
+
+// CHECK: define internal void @_ZN10merge_declL4funcEv(){{.*}} !retain
+namespace merge_decl {
+static void func();
+void bar() { void func() __attribute__((used,retain)); }
+static void func() {}
+}
+
+namespace instantiate_member {
+template 
+struct S {
+  void __attribute__((used,retain)) f() {}
+};
+
+void test() {
+  // CHECK: define linkonce_odr{{.*}} void @_ZN18instantiate_member1SIiE1fEv({{.*}} !retain
+  S a;
+}
+}
Index: clang/test/CodeGen/attr-retain.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-retain.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+// CHECK:  @c0 ={{.*}} constant i32 {{.*}} !retain ![[#EMPTY:]]
+// CHECK:  @foo.l0 = internal global i32 {{.*}} !retain ![[#EMPTY]]
+// CHECK:  @g0 ={{.*}} global i32 {{.*}} !retain ![[#EMPTY]]
+// CHECK-NEXT: @g1 ={{.*}} global i32 {{.*}} !retain ![[#EMPTY]]
+// CHECK-NEXT: @g3 = internal global i32 {{.*}} !retain ![[#EMPTY]]
+// CHECK-NEXT: @g4 = internal global i32 0, section ".data.g"{{.*}} !retain ![[#EMPTY]]
+
+/// Set !retain only on ELF platforms.
+// NORETAIN-NOT: !retain
+
+const int c0 __attribute__((retain)) = 42;
+
+void foo() {
+  static int l0 __attribute__((retain)) = 2;
+}
+
+__attribute__((retain)) int g0;
+int g1 __attribute__((retain));
+__attribute__((retain)) static int g2;
+__attribute__((used,retain)) static int g3;
+__attribute__((used,retain,section(".data.g"))) static int g4;
+
+// CHECK:  define dso_local void @f0(){{.*}} !retain ![[#EMPTY]]
+// CHECK-NOT:  @f1
+// CHECK:  define internal void @f2(){{.*}} !retain ![[#EMPTY]]
+
+void __attribute__((retain)) f0(void) {}
+static void __attribute__((retain)) f1(void) {}
+static void __attribute__((used,retain)) f2(void) {}
+
+// CHECK:  [[#EMPTY]] = !{}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2831,6 +2831,11 @@
 NewAttr->setInherited(true);
 

[PATCH] D96224: [clang-itdy] Simplify virtual near-miss check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

> What happens when TBase is an explicit specialization.

It's not changed before or after this patch. This check is documented as 
changing code based on the derived classes based on typos of methods overridden 
from the base.

Your suggestion makes sense to me, but it is orthogonal to this patch.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp:49
-  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: method 'TDerived::tfunk' 
has {{.*}} 'TBase::tfunc'
-  // CHECK-FIXES: virtual void tfunk(T t);
 };

njames93 wrote:
> Can this be left in to show no fix was applied.
After this patch it actually does apply the fixit. I can see why the fixit 
would have been skipped when it was based on the template instantiation 
(because a specialization could do unexpected things), but I don't see why it 
should be excluded when matching based on the template declaration.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96224

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


[PATCH] D96224: [clang-itdy] Simplify virtual near-miss check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 325232.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96224

Files:
  clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
@@ -44,9 +44,8 @@
 struct TDerived : TBase {
   virtual void tfunk(T t);
   // Should not apply fix for template.
-  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 'TDerived::tfunk' 
has {{.*}} 'TBase::tfunc'
-  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: method 'TDerived::tfunk' 
has {{.*}} 'TBase::tfunc'
-  // CHECK-FIXES: virtual void tfunk(T t);
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 'TDerived::tfunk' has 
{{.*}} 'TBase::tfunc'
+  // CHECK-FIXES: virtual void tfunc(T t);
 };
 
 TDerived T1;
Index: clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
@@ -32,6 +32,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   /// Check if the given method is possible to be overridden by some other
Index: clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
@@ -216,10 +216,9 @@
 
 void VirtualNearMissCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  cxxMethodDecl(
-  unless(anyOf(isOverride(), isImplicit(), cxxConstructorDecl(),
-   cxxDestructorDecl(), cxxConversionDecl(), isStatic(),
-   isOverloadedOperator(
+  cxxMethodDecl(unless(anyOf(isOverride(), cxxConstructorDecl(),
+ cxxDestructorDecl(), cxxConversionDecl(),
+ isStatic(), isOverloadedOperator(
   .bind("method"),
   this);
 }
@@ -234,7 +233,15 @@
   assert(DerivedRD);
 
   for (const auto  : DerivedRD->bases()) {
-if (const auto *BaseRD = BaseSpec.getType()->getAsCXXRecordDecl()) {
+const auto *BaseRD = BaseSpec.getType()->getAsCXXRecordDecl();
+if (const auto *TST =
+dyn_cast(BaseSpec.getType())) {
+  auto TN = TST->getTemplateName();
+  BaseRD =
+  dyn_cast(TN.getAsTemplateDecl()->getTemplatedDecl());
+}
+
+if (BaseRD) {
   for (const auto *BaseMD : BaseRD->methods()) {
 if (!isPossibleToBeOverridden(BaseMD))
   continue;
@@ -250,16 +257,12 @@
 auto Range = CharSourceRange::getTokenRange(
 SourceRange(DerivedMD->getLocation()));
 
-bool ApplyFix = !BaseMD->isTemplateInstantiation() &&
-!DerivedMD->isTemplateInstantiation();
-auto Diag =
-diag(DerivedMD->getBeginLoc(),
- "method '%0' has a similar name and the same signature as 
"
- "virtual method '%1'; did you mean to override it?")
+diag(DerivedMD->getBeginLoc(),
+ "method '%0' has a similar name and the same signature as "
+ "virtual method '%1'; did you mean to override it?")
 << DerivedMD->getQualifiedNameAsString()
-<< BaseMD->getQualifiedNameAsString();
-if (ApplyFix)
-  Diag << FixItHint::CreateReplacement(Range, BaseMD->getName());
+<< BaseMD->getQualifiedNameAsString()
+<< FixItHint::CreateReplacement(Range, BaseMD->getName());
   }
 }
   }


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp
@@ -44,9 +44,8 @@
 struct TDerived : TBase {
   virtual void tfunk(T t);
   // Should not apply fix for template.
-  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 'TDerived::tfunk' has {{.*}} 'TBase::tfunc'
-  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: method 

[PATCH] D97003: [Clang][OpenMP] Require CUDA 9.2+ for OpenMP offloading on NVPTX target

2021-02-20 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 325229.
tianshilei1992 added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97003

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_102-sm_20.bc
  clang/test/Driver/openmp-offload-gpu.c

Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -154,17 +154,17 @@
 /// Check that the runtime bitcode library is part of the compile line. Create a bogus
 /// bitcode library and add it to the LIBRARY_PATH.
 // RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 /// The user can override default detection using --libomptarget-nvptx-bc-path=.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
 // RUN:   --libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-test.bc \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-USER %s
 
-// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_35.bc
+// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_102-sm_35.bc
 // CHK-BCLIB-USER: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
 // CHK-BCLIB-NOT: {{error:|warning:}}
 
@@ -173,23 +173,33 @@
 /// Check that the warning is thrown when the libomptarget bitcode library is not found.
 /// Libomptarget requires sm_35 or newer so an sm_35 bitcode library should never exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_102-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
 
 /// ###
 
 /// Check that the error is thrown when the libomptarget bitcode library does not exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s
 
 // CHK-BCLIB-ERROR: Bitcode library 'not-exist.bc' does not exist.
 
+/// ###
+
+/// Check that the error is thrown when CUDA 9.1 or lower version is used.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_90/usr/local/cuda \
+// RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-CUDA-VERSION-ERROR %s
+
+// CHK-CUDA-VERSION-ERROR: NVPTX target requires CUDA 9.2 or above. CUDA 9.0 is detected.
+
 /// Check that debug info is emitted in dwarf-2
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O1 --no-cuda-noopt-device-debug 2>&1 \
 // RUN:   | FileCheck -check-prefix=DEBUG_DIRECTIVES %s
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -710,13 +710,14 @@
   

[PATCH] D97120: [Clang][OpenMP] Update driver test case for OpenMP offload to use sm_35

2021-02-20 Thread Shilei Tian via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33d660939d9a: [Clang][OpenMP] Update driver test case for 
OpenMP offload to use sm_35 (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97120

Files:
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_20.bc
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc
  clang/test/Driver/openmp-offload-gpu.c


Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -154,36 +154,36 @@
 /// Check that the runtime bitcode library is part of the compile line. Create 
a bogus
 /// bitcode library and add it to the LIBRARY_PATH.
 // RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 /// The user can override default detection using 
--libomptarget-nvptx-bc-path=.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
 // RUN:   
--libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-test.bc \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-USER %s
 
-// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_20.bc
+// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_35.bc
 // CHK-BCLIB-USER: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
 // CHK-BCLIB-NOT: {{error:|warning:}}
 
 /// ###
 
 /// Check that the warning is thrown when the libomptarget bitcode library is 
not found.
-/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should 
never exist.
+/// Libomptarget requires sm_35 or newer so an sm_35 bitcode library should 
never exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_20.bc' found in 
the default clang lib directory or in LIBRARY_PATH. Please use 
--libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_35.bc' found in 
the default clang lib directory or in LIBRARY_PATH. Please use 
--libomptarget-nvptx-bc-path to specify nvptx bitcode library.
 
 /// ###
 
 /// Check that the error is thrown when the libomptarget bitcode library does 
not exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s


Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -154,36 +154,36 @@
 /// Check that the runtime bitcode library is part of the compile line. Create a bogus
 /// bitcode library and add it to the LIBRARY_PATH.
 // RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 /// The user can override default detection using 

[clang] 33d6609 - [Clang][OpenMP] Update driver test case for OpenMP offload to use sm_35

2021-02-20 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2021-02-20T15:14:13-05:00
New Revision: 33d660939d9acb027f9941f037802936124dad8c

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

LOG: [Clang][OpenMP] Update driver test case for OpenMP offload to use sm_35

`sm_35` is the minimum requirement for OpenMP offloading on NVPTX device.
Current driver test case is using `sm_20`. D97003 is going to switch the minimum
CUDA version to 9.2, which only supports `sm_30+`. This patch makes step for the
change.

Reviewed By: JonChesterfield

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

Added: 
clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc

Modified: 
clang/test/Driver/openmp-offload-gpu.c

Removed: 
clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_20.bc



diff  --git 
a/clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_20.bc 
b/clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc
similarity index 100%
rename from 
clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_20.bc
rename to 
clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc

diff  --git a/clang/test/Driver/openmp-offload-gpu.c 
b/clang/test/Driver/openmp-offload-gpu.c
index a2ffd83b9cb8..796b094f97ea 100644
--- a/clang/test/Driver/openmp-offload-gpu.c
+++ b/clang/test/Driver/openmp-offload-gpu.c
@@ -154,36 +154,36 @@
 /// Check that the runtime bitcode library is part of the compile line. Create 
a bogus
 /// bitcode library and add it to the LIBRARY_PATH.
 // RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 /// The user can override default detection using 
--libomptarget-nvptx-bc-path=.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
 // RUN:   
--libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-test.bc \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-USER %s
 
-// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_20.bc
+// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_35.bc
 // CHK-BCLIB-USER: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
 // CHK-BCLIB-NOT: {{error:|warning:}}
 
 /// ###
 
 /// Check that the warning is thrown when the libomptarget bitcode library is 
not found.
-/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should 
never exist.
+/// Libomptarget requires sm_35 or newer so an sm_35 bitcode library should 
never exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_20.bc' found in 
the default clang lib directory or in LIBRARY_PATH. Please use 
--libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_35.bc' found in 
the default clang lib directory or in LIBRARY_PATH. Please use 
--libomptarget-nvptx-bc-path to specify nvptx bitcode library.
 
 /// ###
 
 /// Check that the error is thrown when the libomptarget bitcode library does 
not exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s




[PATCH] D97120: [Clang][OpenMP] Update driver test case for OpenMP offload to use sm_35

2021-02-20 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

LG.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97120

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


[PATCH] D96135: [clang-tidy] Simplify braced init check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe8b8f8960246: [clang-tidy] Simplify braced init check 
(authored by stephenkelly).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96135

Files:
  clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++14 %s modernize-return-braced-init-list %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++14-or-later %s 
modernize-return-braced-init-list %t
 
 namespace std {
 typedef decltype(sizeof(int)) size_t;
Index: clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
@@ -29,6 +29,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace modernize
Index: clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
@@ -23,21 +23,14 @@
   auto ConstructExpr =
   cxxConstructExpr(
   unless(anyOf(hasDeclaration(cxxConstructorDecl(isExplicit())),
-   isListInitialization(), hasDescendant(initListExpr()),
-   isInTemplateInstantiation(
+   isListInitialization(), hasDescendant(initListExpr()
   .bind("ctor");
 
-  auto CtorAsArgument = materializeTemporaryExpr(anyOf(
-  has(ConstructExpr), has(cxxFunctionalCastExpr(has(ConstructExpr);
-
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   functionDecl(
-   isDefinition(), // Declarations don't have return 
statements.
-   returns(unless(anyOf(builtinType(), autoType(,
-   hasDescendant(returnStmt(hasReturnValue(
-   has(cxxConstructExpr(has(CtorAsArgument)))
-   .bind("fn")),
+  returnStmt(hasReturnValue(ConstructExpr),
+ forFunction(functionDecl(returns(unless(anyOf(builtinType(),
+   autoType()
+ .bind("fn"))),
   this);
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++14 %s modernize-return-braced-init-list %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-return-braced-init-list %t
 
 namespace std {
 typedef decltype(sizeof(int)) size_t;
Index: clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
@@ -29,6 +29,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace modernize
Index: clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
@@ -23,21 +23,14 @@
   auto ConstructExpr =
   cxxConstructExpr(
   unless(anyOf(hasDeclaration(cxxConstructorDecl(isExplicit())),
-   isListInitialization(), 

[clang-tools-extra] e8b8f89 - [clang-tidy] Simplify braced init check

2021-02-20 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-20T20:09:13Z
New Revision: e8b8f896024620eb86bf924be73100d83c74c736

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

LOG: [clang-tidy] Simplify braced init check

The normalization of matchers means that this now works in all language
modes.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h

clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
index 6dc91e91ffde..4c8b9571e4c7 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
@@ -23,21 +23,14 @@ void 
ReturnBracedInitListCheck::registerMatchers(MatchFinder *Finder) {
   auto ConstructExpr =
   cxxConstructExpr(
   unless(anyOf(hasDeclaration(cxxConstructorDecl(isExplicit())),
-   isListInitialization(), hasDescendant(initListExpr()),
-   isInTemplateInstantiation(
+   isListInitialization(), hasDescendant(initListExpr()
   .bind("ctor");
 
-  auto CtorAsArgument = materializeTemporaryExpr(anyOf(
-  has(ConstructExpr), has(cxxFunctionalCastExpr(has(ConstructExpr);
-
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   functionDecl(
-   isDefinition(), // Declarations don't have return 
statements.
-   returns(unless(anyOf(builtinType(), autoType(,
-   hasDescendant(returnStmt(hasReturnValue(
-   has(cxxConstructExpr(has(CtorAsArgument)))
-   .bind("fn")),
+  returnStmt(hasReturnValue(ConstructExpr),
+ forFunction(functionDecl(returns(unless(anyOf(builtinType(),
+   autoType()
+ .bind("fn"))),
   this);
 }
 

diff  --git 
a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h 
b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
index 12bd694cd3ae..da863891bdee 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
@@ -29,6 +29,9 @@ class ReturnBracedInitListCheck : public ClangTidyCheck {
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace modernize

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
index 29d81c6df1f0..4db1d49da2ea 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++14 %s modernize-return-braced-init-list %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++14-or-later %s 
modernize-return-braced-init-list %t
 
 namespace std {
 typedef decltype(sizeof(int)) size_t;



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


[PATCH] D96131: [clang-tidy] Simplify function complexity check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 325226.
steveire added a comment.

Fix test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96131

Files:
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -666,8 +666,8 @@
 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, 
nesting level increased to 2{{$}}
 }
   };
-// CHECK-NOTES: :[[@LINE-6]]:14: warning: function 'operator()' has cognitive 
complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
-// CHECK-NOTES: :[[@LINE-5]]:5: note: +1, including nesting penalty of 0, 
nesting level increased to 1{{$}}
+  // CHECK-NOTES: :[[@LINE-6]]:14: warning: lambda has cognitive complexity of 
1 (threshold 0) [readability-function-cognitive-complexity]
+  // CHECK-NOTES: :[[@LINE-5]]:5: note: +1, including nesting penalty of 0, 
nesting level increased to 1{{$}}
 }
 
 void unittest_b2_09() {
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
===
--- clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
+++ clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
@@ -31,6 +31,9 @@
   void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   const unsigned Threshold;
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -502,27 +502,40 @@
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   functionDecl(isDefinition(),
-   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
-isInstantiated(), isWeak(
+   unless(anyOf(isDefaulted(), isDeleted(), isWeak(
   .bind("func"),
   this);
+  Finder->addMatcher(lambdaExpr().bind("lambda"), this);
 }
 
 void FunctionCognitiveComplexityCheck::check(
 const MatchFinder::MatchResult ) {
-  const auto *Func = Result.Nodes.getNodeAs("func");
-  assert(Func->hasBody() && "The matchers should only match the functions that 
"
-"have user-provided body.");
 
   FunctionASTVisitor Visitor;
-  Visitor.TraverseDecl(const_cast(Func), true);
+  SourceLocation Loc;
+
+  const auto *TheDecl = Result.Nodes.getNodeAs("func");
+  const auto *TheLambdaExpr = Result.Nodes.getNodeAs("lambda");
+  if (TheDecl) {
+assert(TheDecl->hasBody() &&
+   "The matchers should only match the functions that "
+   "have user-provided body.");
+Loc = TheDecl->getLocation();
+Visitor.TraverseDecl(const_cast(TheDecl), true);
+  } else {
+Loc = TheLambdaExpr->getBeginLoc();
+Visitor.TraverseLambdaExpr(const_cast(TheLambdaExpr));
+  }
 
   if (Visitor.CC.Total <= Threshold)
 return;
 
-  diag(Func->getLocation(),
-   "function %0 has cognitive complexity of %1 (threshold %2)")
-  << Func << Visitor.CC.Total << Threshold;
+  if (TheDecl)
+diag(Loc, "function %0 has cognitive complexity of %1 (threshold %2)")
+<< TheDecl << Visitor.CC.Total << Threshold;
+  else
+diag(Loc, "lambda has cognitive complexity of %0 (threshold %1)")
+<< Visitor.CC.Total << Threshold;
 
   // Output all the basic increments of complexity.
   for (const auto  : Visitor.CC.Details) {


Index: clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -666,8 +666,8 @@
 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
 }
   };
-// CHECK-NOTES: :[[@LINE-6]]:14: warning: function 

[PATCH] D95746: clang: Exclude efi_main from -Wmissing-prototypes

2021-02-20 Thread Daan De Meyer 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 rG7dd42ecfa2a2: clang: Exclude efi_main from 
-Wmissing-prototypes (authored by DaanDeMeyer).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95746

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/no-warn-missing-prototype.c


Index: clang/test/Sema/no-warn-missing-prototype.c
===
--- clang/test/Sema/no-warn-missing-prototype.c
+++ clang/test/Sema/no-warn-missing-prototype.c
@@ -4,3 +4,7 @@
 int main() {
   return 0;
 }
+
+int efi_main() {
+  return 0;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13873,7 +13873,7 @@
   // Don't warn about 'main'.
   if (isa(FD->getDeclContext()->getRedeclContext()))
 if (IdentifierInfo *II = FD->getIdentifier())
-  if (II->isStr("main"))
+  if (II->isStr("main") || II->isStr("efi_main"))
 return false;
 
   // Don't warn about inline functions.


Index: clang/test/Sema/no-warn-missing-prototype.c
===
--- clang/test/Sema/no-warn-missing-prototype.c
+++ clang/test/Sema/no-warn-missing-prototype.c
@@ -4,3 +4,7 @@
 int main() {
   return 0;
 }
+
+int efi_main() {
+  return 0;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13873,7 +13873,7 @@
   // Don't warn about 'main'.
   if (isa(FD->getDeclContext()->getRedeclContext()))
 if (IdentifierInfo *II = FD->getIdentifier())
-  if (II->isStr("main"))
+  if (II->isStr("main") || II->isStr("efi_main"))
 return false;
 
   // Don't warn about inline functions.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7dd42ec - clang: Exclude efi_main from -Wmissing-prototypes

2021-02-20 Thread Daan De Meyer via cfe-commits

Author: Daan De Meyer
Date: 2021-02-20T20:00:50Z
New Revision: 7dd42ecfa2a29bac89c965544c14b32805c8f02b

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

LOG: clang: Exclude efi_main from -Wmissing-prototypes

When compiling UEFI applications, the main function is named
efi_main() instead of main(). Let's exclude efi_main() from
-Wmissing-prototypes as well to avoid warnings when working
on UEFI applications.

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/no-warn-missing-prototype.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index cee107096947..0f5b5332364a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13873,7 +13873,7 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
   // Don't warn about 'main'.
   if (isa(FD->getDeclContext()->getRedeclContext()))
 if (IdentifierInfo *II = FD->getIdentifier())
-  if (II->isStr("main"))
+  if (II->isStr("main") || II->isStr("efi_main"))
 return false;
 
   // Don't warn about inline functions.

diff  --git a/clang/test/Sema/no-warn-missing-prototype.c 
b/clang/test/Sema/no-warn-missing-prototype.c
index 4dbc25755922..6059b6aa0f14 100644
--- a/clang/test/Sema/no-warn-missing-prototype.c
+++ b/clang/test/Sema/no-warn-missing-prototype.c
@@ -4,3 +4,7 @@
 int main() {
   return 0;
 }
+
+int efi_main() {
+  return 0;
+}



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


[PATCH] D95746: clang: Exclude efi_main from -Wmissing-prototypes

2021-02-20 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.

Reaffirming approval with the test change - looks great!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95746

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


[PATCH] D95746: clang: Exclude efi_main from -Wmissing-prototypes

2021-02-20 Thread Daan De Meyer via Phabricator via cfe-commits
DaanDeMeyer added a comment.

I should be able to commit it myself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95746

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


[PATCH] D95746: clang: Exclude efi_main from -Wmissing-prototypes

2021-02-20 Thread Daan De Meyer via Phabricator via cfe-commits
DaanDeMeyer updated this revision to Diff 325224.
DaanDeMeyer added a comment.

Moved the test into the no-warn-missing-prototype test as requested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95746

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/no-warn-missing-prototype.c


Index: clang/test/Sema/no-warn-missing-prototype.c
===
--- clang/test/Sema/no-warn-missing-prototype.c
+++ clang/test/Sema/no-warn-missing-prototype.c
@@ -4,3 +4,7 @@
 int main() {
   return 0;
 }
+
+int efi_main() {
+  return 0;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13873,7 +13873,7 @@
   // Don't warn about 'main'.
   if (isa(FD->getDeclContext()->getRedeclContext()))
 if (IdentifierInfo *II = FD->getIdentifier())
-  if (II->isStr("main"))
+  if (II->isStr("main") || II->isStr("efi_main"))
 return false;
 
   // Don't warn about inline functions.


Index: clang/test/Sema/no-warn-missing-prototype.c
===
--- clang/test/Sema/no-warn-missing-prototype.c
+++ clang/test/Sema/no-warn-missing-prototype.c
@@ -4,3 +4,7 @@
 int main() {
   return 0;
 }
+
+int efi_main() {
+  return 0;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13873,7 +13873,7 @@
   // Don't warn about 'main'.
   if (isa(FD->getDeclContext()->getRedeclContext()))
 if (IdentifierInfo *II = FD->getIdentifier())
-  if (II->isStr("main"))
+  if (II->isStr("main") || II->isStr("efi_main"))
 return false;
 
   // Don't warn about inline functions.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: sammccall, kadircet.
Herald added subscribers: usaxena95, arphaman.
njames93 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Currently clangd will ignore FixItHint::InsertFromRange when computing edits.
This leads to malformed fixes for diagnostics that choose to use it.
In this patch we will try to grab source text if CodeToInsert is empty.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97123

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/SourceCode.cpp


Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -549,6 +549,12 @@
   Result.range =
   halfOpenToRange(M, Lexer::makeFileCharRange(FixIt.RemoveRange, M, L));
   Result.newText = FixIt.CodeToInsert;
+  if (Result.newText.empty() && FixIt.InsertFromRange.isValid()) {
+bool Invalid = false;
+auto Insert = Lexer::getSourceText(FixIt.InsertFromRange, M, L, );
+if (!Invalid)
+  Result.newText = Insert.str();
+  }
   return Result;
 }
 
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -691,6 +691,12 @@
   llvm::StringRef Remove =
   Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, );
   llvm::StringRef Insert = FixIt.CodeToInsert;
+  if (Insert.empty() && FixIt.InsertFromRange.isValid()) {
+bool InvalidInsert = false;
+Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts,
+  );
+Invalid |= InvalidInsert;
+  }
   if (!Invalid) {
 llvm::raw_svector_ostream M(Message);
 if (!Remove.empty() && !Insert.empty()) {


Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -549,6 +549,12 @@
   Result.range =
   halfOpenToRange(M, Lexer::makeFileCharRange(FixIt.RemoveRange, M, L));
   Result.newText = FixIt.CodeToInsert;
+  if (Result.newText.empty() && FixIt.InsertFromRange.isValid()) {
+bool Invalid = false;
+auto Insert = Lexer::getSourceText(FixIt.InsertFromRange, M, L, );
+if (!Invalid)
+  Result.newText = Insert.str();
+  }
   return Result;
 }
 
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -691,6 +691,12 @@
   llvm::StringRef Remove =
   Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, );
   llvm::StringRef Insert = FixIt.CodeToInsert;
+  if (Insert.empty() && FixIt.InsertFromRange.isValid()) {
+bool InvalidInsert = false;
+Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts,
+  );
+Invalid |= InvalidInsert;
+  }
   if (!Invalid) {
 llvm::raw_svector_ostream M(Message);
 if (!Remove.empty() && !Insert.empty()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97119: [flang][driver] Add options for -std=2018

2021-02-20 Thread Tim Keith via Phabricator via cfe-commits
tskeith added a comment.

Please make sure the test works with f18 also.




Comment at: flang/lib/Frontend/CompilerInvocation.cpp:294
+// We only allow 2018 as the given standard
+if (standard.equals("2018")) {
+  res.SetStandard();

This should be "f2018", not "2018".



Comment at: flang/test/Flang-Driver/std2018.f90:18
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+

Can you verify this message is not produced when there is no -std option?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97119

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


[PATCH] D96224: [clang-itdy] Simplify virtual near-miss check

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

What happens when TBase is an explicit specialization. In that situation a 
warning for the explicit specialization may be useful.

  template <> struct TBase {
virtual void tfunt(T t);
  };




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-virtual-near-miss.cpp:49
-  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: method 'TDerived::tfunk' 
has {{.*}} 'TBase::tfunc'
-  // CHECK-FIXES: virtual void tfunk(T t);
 };

Can this be left in to show no fix was applied.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96224

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


[PATCH] D97120: [Clang][OpenMP] Update driver test case for OpenMP offload to use sm_35

2021-02-20 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, JonChesterfield.
Herald added subscribers: guansong, yaxunl.
tianshilei1992 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

`sm_35` is the minimum requirement for OpenMP offloading on NVPTX device.
Current driver test case is using `sm_20`. D97003 
 is going to switch the minimum
CUDA version to 9.2, which only supports `sm_30+`. This patch makes step for the
change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97120

Files:
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_20.bc
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc
  clang/test/Driver/openmp-offload-gpu.c


Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -154,36 +154,36 @@
 /// Check that the runtime bitcode library is part of the compile line. Create 
a bogus
 /// bitcode library and add it to the LIBRARY_PATH.
 // RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 /// The user can override default detection using 
--libomptarget-nvptx-bc-path=.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
 // RUN:   
--libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-test.bc \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-USER %s
 
-// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_20.bc
+// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_35.bc
 // CHK-BCLIB-USER: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
 // CHK-BCLIB-NOT: {{error:|warning:}}
 
 /// ###
 
 /// Check that the warning is thrown when the libomptarget bitcode library is 
not found.
-/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should 
never exist.
+/// Libomptarget requires sm_35 or newer so an sm_35 bitcode library should 
never exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_20.bc' found in 
the default clang lib directory or in LIBRARY_PATH. Please use 
--libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_35.bc' found in 
the default clang lib directory or in LIBRARY_PATH. Please use 
--libomptarget-nvptx-bc-path to specify nvptx bitcode library.
 
 /// ###
 
 /// Check that the error is thrown when the libomptarget bitcode library does 
not exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 
--cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s


Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -154,36 +154,36 @@
 /// Check that the runtime bitcode library is part of the compile line. Create a bogus
 /// bitcode library and add it to the LIBRARY_PATH.
 // RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   

[PATCH] D96131: [clang-tidy] Simplify function complexity check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 325216.
steveire added a comment.

Trigger rebuild


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96131

Files:
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -666,8 +666,8 @@
 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, 
nesting level increased to 2{{$}}
 }
   };
-// CHECK-NOTES: :[[@LINE-6]]:14: warning: function 'operator()' has cognitive 
complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
-// CHECK-NOTES: :[[@LINE-5]]:5: note: +1, including nesting penalty of 0, 
nesting level increased to 1{{$}}
+  // CHECK-NOTES: :[[@LINE-6]]:14: warning: lambda has cognitive complexity of 
1 (threshold 0) [readability-function-cognitive-complexity]
+  // CHECK-NOTES: :[[@LINE-5]]:5: note: +1, including nesting penalty of 0, 
nesting level increased to 1{{$}}
 }
 
 void unittest_b2_09() {
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
===
--- clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
+++ clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h
@@ -31,6 +31,9 @@
   void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  llvm::Optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   const unsigned Threshold;
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,28 +501,38 @@
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(isDefinition(),
-   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
-isInstantiated(), isWeak(
-  .bind("func"),
-  this);
+  functionDecl(isDefinition(), unless(isWeak())).bind("func"), this);
+  Finder->addMatcher(lambdaExpr().bind("lambda"), this);
 }
 
 void FunctionCognitiveComplexityCheck::check(
 const MatchFinder::MatchResult ) {
-  const auto *Func = Result.Nodes.getNodeAs("func");
-  assert(Func->hasBody() && "The matchers should only match the functions that 
"
-"have user-provided body.");
 
   FunctionASTVisitor Visitor;
-  Visitor.TraverseDecl(const_cast(Func), true);
+  SourceLocation Loc;
+
+  const auto *TheDecl = Result.Nodes.getNodeAs("func");
+  const auto *TheLambdaExpr = Result.Nodes.getNodeAs("lambda");
+  if (TheDecl) {
+assert(TheDecl->hasBody() &&
+   "The matchers should only match the functions that "
+   "have user-provided body.");
+Loc = TheDecl->getLocation();
+Visitor.TraverseDecl(const_cast(TheDecl), true);
+  } else {
+Loc = TheLambdaExpr->getBeginLoc();
+Visitor.TraverseLambdaExpr(const_cast(TheLambdaExpr));
+  }
 
   if (Visitor.CC.Total <= Threshold)
 return;
 
-  diag(Func->getLocation(),
-   "function %0 has cognitive complexity of %1 (threshold %2)")
-  << Func << Visitor.CC.Total << Threshold;
+  if (TheDecl)
+diag(Loc, "function %0 has cognitive complexity of %1 (threshold %2)")
+<< TheDecl << Visitor.CC.Total << Threshold;
+  else
+diag(Loc, "lambda has cognitive complexity of %0 (threshold %1)")
+<< Visitor.CC.Total << Threshold;
 
   // Output all the basic increments of complexity.
   for (const auto  : Visitor.CC.Details) {


Index: clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -666,8 +666,8 @@
 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
 }
   };
-// CHECK-NOTES: :[[@LINE-6]]:14: warning: 

[PATCH] D96131: [clang-tidy] Simplify function complexity check

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Can you have a look at the failed tests, they seem to be related.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96131

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


[PATCH] D97095: [ASTMatchers] Fix hasUnaryOperand matcher for postfix operators

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG559f3728441d: [ASTMatchers] Fix hasUnaryOperand matcher for 
postfix operators (authored by stephenkelly).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97095

Files:
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1630,6 +1630,84 @@
cxxOperatorCallExpr(forFunction(functionDecl(hasName("opFree"))),
hasAnyOperatorName("+", "!"),
hasUnaryOperand(s1Expr);
+
+  Code = R"cpp(
+struct HasIncOperatorsMem
+{
+HasIncOperatorsMem& operator++();
+HasIncOperatorsMem operator++(int);
+};
+struct HasIncOperatorsFree
+{
+};
+HasIncOperatorsFree& operator++(HasIncOperatorsFree&);
+HasIncOperatorsFree operator++(HasIncOperatorsFree&, int);
+
+void prefixIncOperatorMem()
+{
+HasIncOperatorsMem s1;
+++s1;
+}
+void prefixIncOperatorFree()
+{
+HasIncOperatorsFree s1;
+++s1;
+}
+void postfixIncOperatorMem()
+{
+HasIncOperatorsMem s1;
+s1++;
+}
+void postfixIncOperatorFree()
+{
+HasIncOperatorsFree s1;
+s1++;
+}
+
+struct HasOpPlusInt
+{
+HasOpPlusInt& operator+(int);
+};
+void plusIntOperator()
+{
+HasOpPlusInt s1;
+s1+1;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   cxxOperatorCallExpr(
+   forFunction(functionDecl(hasName("prefixIncOperatorMem"))),
+   hasOperatorName("++"), hasUnaryOperand(declRefExpr());
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   cxxOperatorCallExpr(
+   forFunction(functionDecl(hasName("prefixIncOperatorFree"))),
+   hasOperatorName("++"), hasUnaryOperand(declRefExpr());
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   cxxOperatorCallExpr(
+   forFunction(functionDecl(hasName("postfixIncOperatorMem"))),
+   hasOperatorName("++"), hasUnaryOperand(declRefExpr());
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   cxxOperatorCallExpr(
+   forFunction(functionDecl(hasName("postfixIncOperatorFree"))),
+   hasOperatorName("++"), hasUnaryOperand(declRefExpr());
+
+  EXPECT_FALSE(matches(
+  Code, traverse(TK_IgnoreUnlessSpelledInSource,
+ cxxOperatorCallExpr(
+ forFunction(functionDecl(hasName("plusIntOperator"))),
+ hasOperatorName("+"), hasUnaryOperand(expr());
 }
 
 TEST(Matcher, UnaryOperatorTypes) {
Index: clang/include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -2039,7 +2039,8 @@
 template <>
 inline Optional
 equivalentUnaryOperator(const CXXOperatorCallExpr ) {
-  if (Node.getNumArgs() != 1)
+  if (Node.getNumArgs() != 1 && Node.getOperator() != OO_PlusPlus &&
+  Node.getOperator() != OO_MinusMinus)
 return None;
   switch (Node.getOperator()) {
   default:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 559f372 - [ASTMatchers] Fix hasUnaryOperand matcher for postfix operators

2021-02-20 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-20T17:54:12Z
New Revision: 559f3728441d4b8342c71ef554d84a2804575d9d

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

LOG: [ASTMatchers] Fix hasUnaryOperand matcher for postfix operators

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

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 2af4e6e88109..5e3af4a2a34b 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -2039,7 +2039,8 @@ equivalentUnaryOperator(const NodeType ) {
 template <>
 inline Optional
 equivalentUnaryOperator(const CXXOperatorCallExpr ) {
-  if (Node.getNumArgs() != 1)
+  if (Node.getNumArgs() != 1 && Node.getOperator() != OO_PlusPlus &&
+  Node.getOperator() != OO_MinusMinus)
 return None;
   switch (Node.getOperator()) {
   default:

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 8a6e94cf5624..9909cec2065c 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1630,6 +1630,84 @@ void opFree()

cxxOperatorCallExpr(forFunction(functionDecl(hasName("opFree"))),
hasAnyOperatorName("+", "!"),
hasUnaryOperand(s1Expr);
+
+  Code = R"cpp(
+struct HasIncOperatorsMem
+{
+HasIncOperatorsMem& operator++();
+HasIncOperatorsMem operator++(int);
+};
+struct HasIncOperatorsFree
+{
+};
+HasIncOperatorsFree& operator++(HasIncOperatorsFree&);
+HasIncOperatorsFree operator++(HasIncOperatorsFree&, int);
+
+void prefixIncOperatorMem()
+{
+HasIncOperatorsMem s1;
+++s1;
+}
+void prefixIncOperatorFree()
+{
+HasIncOperatorsFree s1;
+++s1;
+}
+void postfixIncOperatorMem()
+{
+HasIncOperatorsMem s1;
+s1++;
+}
+void postfixIncOperatorFree()
+{
+HasIncOperatorsFree s1;
+s1++;
+}
+
+struct HasOpPlusInt
+{
+HasOpPlusInt& operator+(int);
+};
+void plusIntOperator()
+{
+HasOpPlusInt s1;
+s1+1;
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   cxxOperatorCallExpr(
+   forFunction(functionDecl(hasName("prefixIncOperatorMem"))),
+   hasOperatorName("++"), hasUnaryOperand(declRefExpr());
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   cxxOperatorCallExpr(
+   forFunction(functionDecl(hasName("prefixIncOperatorFree"))),
+   hasOperatorName("++"), hasUnaryOperand(declRefExpr());
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   cxxOperatorCallExpr(
+   forFunction(functionDecl(hasName("postfixIncOperatorMem"))),
+   hasOperatorName("++"), hasUnaryOperand(declRefExpr());
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   cxxOperatorCallExpr(
+   
forFunction(functionDecl(hasName("postfixIncOperatorFree"))),
+   hasOperatorName("++"), hasUnaryOperand(declRefExpr());
+
+  EXPECT_FALSE(matches(
+  Code, traverse(TK_IgnoreUnlessSpelledInSource,
+ cxxOperatorCallExpr(
+ forFunction(functionDecl(hasName("plusIntOperator"))),
+ hasOperatorName("+"), hasUnaryOperand(expr());
 }
 
 TEST(Matcher, UnaryOperatorTypes) {



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


[PATCH] D96665: Revert "Implement nullPointerConstant() using a better API."

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6984e0d43985: Revert Implement nullPointerConstant() 
using a better API. (authored by stephenkelly).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96665

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3663,7 +3663,7 @@
   expr(nullPointerConstant(;
   EXPECT_TRUE(matches("char *cp = (char *)0;", expr(nullPointerConstant(;
   EXPECT_TRUE(matches("int *ip = 0;", expr(nullPointerConstant(;
-  EXPECT_TRUE(matches("int i = 0;", expr(nullPointerConstant(;
+  EXPECT_FALSE(matches("int i = 0;", expr(nullPointerConstant(;
 }
 
 TEST_P(ASTMatchersTest, NullPointerConstant_GNUNull) {
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7384,9 +7384,10 @@
 /// expr(nullPointerConstant())
 ///   matches the initializer for v1, v2, v3, cp, and ip. Does not match the
 ///   initializer for i.
-AST_MATCHER(Expr, nullPointerConstant) {
-  return Node.isNullPointerConstant(Finder->getASTContext(),
-Expr::NPC_ValueDependentIsNull);
+AST_MATCHER_FUNCTION(internal::Matcher, nullPointerConstant) {
+  return anyOf(
+  gnuNullExpr(), cxxNullPtrLiteralExpr(),
+  integerLiteral(equals(0), hasParent(expr(hasType(pointerType());
 }
 
 /// Matches the DecompositionDecl the binding belongs to.


Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3663,7 +3663,7 @@
   expr(nullPointerConstant(;
   EXPECT_TRUE(matches("char *cp = (char *)0;", expr(nullPointerConstant(;
   EXPECT_TRUE(matches("int *ip = 0;", expr(nullPointerConstant(;
-  EXPECT_TRUE(matches("int i = 0;", expr(nullPointerConstant(;
+  EXPECT_FALSE(matches("int i = 0;", expr(nullPointerConstant(;
 }
 
 TEST_P(ASTMatchersTest, NullPointerConstant_GNUNull) {
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7384,9 +7384,10 @@
 /// expr(nullPointerConstant())
 ///   matches the initializer for v1, v2, v3, cp, and ip. Does not match the
 ///   initializer for i.
-AST_MATCHER(Expr, nullPointerConstant) {
-  return Node.isNullPointerConstant(Finder->getASTContext(),
-Expr::NPC_ValueDependentIsNull);
+AST_MATCHER_FUNCTION(internal::Matcher, nullPointerConstant) {
+  return anyOf(
+  gnuNullExpr(), cxxNullPtrLiteralExpr(),
+  integerLiteral(equals(0), hasParent(expr(hasType(pointerType());
 }
 
 /// Matches the DecompositionDecl the binding belongs to.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6984e0d - Revert "Implement nullPointerConstant() using a better API."

2021-02-20 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-20T17:33:07Z
New Revision: 6984e0d4398592a20055cb12842fc72462ce01a5

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

LOG: Revert "Implement nullPointerConstant() using a better API."

This reverts commit 9148302a (2019-08-22) which broke the pre-existing
unit test for the matcher.  Also revert commit 518b2266 (Fix the
nullPointerConstant() test to get bots back to green., 2019-08-22) which
incorrectly changed the test to expect the broken behavior.

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

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 6cd4d26768b5..b82929019f6c 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7384,9 +7384,10 @@ extern const internal::VariadicDynCastAllOfMatcher
 /// expr(nullPointerConstant())
 ///   matches the initializer for v1, v2, v3, cp, and ip. Does not match the
 ///   initializer for i.
-AST_MATCHER(Expr, nullPointerConstant) {
-  return Node.isNullPointerConstant(Finder->getASTContext(),
-Expr::NPC_ValueDependentIsNull);
+AST_MATCHER_FUNCTION(internal::Matcher, nullPointerConstant) {
+  return anyOf(
+  gnuNullExpr(), cxxNullPtrLiteralExpr(),
+  integerLiteral(equals(0), hasParent(expr(hasType(pointerType());
 }
 
 /// Matches the DecompositionDecl the binding belongs to.

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 1c6947acf0ab..c26e8f8d4d22 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3663,7 +3663,7 @@ TEST_P(ASTMatchersTest, NullPointerConstant) {
   expr(nullPointerConstant(;
   EXPECT_TRUE(matches("char *cp = (char *)0;", expr(nullPointerConstant(;
   EXPECT_TRUE(matches("int *ip = 0;", expr(nullPointerConstant(;
-  EXPECT_TRUE(matches("int i = 0;", expr(nullPointerConstant(;
+  EXPECT_FALSE(matches("int i = 0;", expr(nullPointerConstant(;
 }
 
 TEST_P(ASTMatchersTest, NullPointerConstant_GNUNull) {



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


[PATCH] D96665: Revert "Implement nullPointerConstant() using a better API."

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

As discussed elsewhere, the bots are not broken. The changes reverted here were 
made in 2019.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96665

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


[PATCH] D96132: [clang-tidy] Simplify throw keyword missing check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp:97-107
+template 
+void templ(int i) {
+  if (i > 0)
+SomeType();
+}
+
 void funcCallWithTempExcTest() {

steveire wrote:
> njames93 wrote:
> > Can I ask what the reason for these extra tests are.
> Did you miss the commit message/MR description?
Ah, sorry, the local commit message I have wasn't here. I'll add it now.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96132

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


[PATCH] D96132: [clang-tidy] Simplify throw keyword missing check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp:97-107
+template 
+void templ(int i) {
+  if (i > 0)
+SomeType();
+}
+
 void funcCallWithTempExcTest() {

njames93 wrote:
> Can I ask what the reason for these extra tests are.
Did you miss the commit message/MR description?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96132

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


[PATCH] D96131: [clang-tidy] Simplify function complexity check

2021-02-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp:505
+  functionDecl(isDefinition(), unless(isWeak())).bind("func"), this);
+  Finder->addMatcher(lambdaExpr().bind("lambda"), this);
 }

njames93 wrote:
> Am I right in assuming lambdas need to be explicitly matched because in the 
> traversal mode their operator() isn't matched as a functionDecl?
Yes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96131

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


[PATCH] D95754: [clang] Print 32 candidates on the first failure, with -fshow-overloads=best.

2021-02-20 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added a comment.

Thank you for the review!

I'll put a note in my cal to land this in a few days if I don't hear from 
@rsmith


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95754

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


[PATCH] D52050: [Driver] Fix architecture triplets and search paths for Linux x32

2021-02-20 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D52050#2576679 , @alsoijw wrote:

> In D52050#2369838 , @dschuff wrote:
>
>> One other question then: do you know if Debian and/or Ubuntu still have the 
>> same support for running x32 programs on the regular x86-64 distribution?
>
> I am not sure that I right understand reason of this question, but there is 
> gentoo x32 profile that allow execute all arch x86, x32, x64.

There are two ways to use x32. Either as a sub-architecture of x86_64 with 
x32-subfolders in /usr/lib/gcc/x86_64-linux-gnu/ (and so on) and as a separate, 
dedicated port.

Debian supports both and I am trying to fix the separate port with this patch.

I think I will resume working on this next week as I would like to finally get 
this fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

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


[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-02-20 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 325208.
arnamoy10 added a comment.

Updating the test case to include `-fc1` as well


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

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/ieee_arithmetic.mod
  flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/intrinsic_module_path.f90

Index: flang/test/Flang-Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/intrinsic_module_path.f90
@@ -0,0 +1,33 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fc1 -fsyntax-only %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT: 'ieee_arithmetic.mod' was not found
+! WITHOUT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN-NOT: 'ieee_arithmetic.mod' was not found
+! GIVEN-NOT: 'iso_fortran_env.mod' was not found
+
+
+program test_intrinsic_module_path
+   use,intrinsic :: ieee_arithmetic
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
+  
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -32,6 +32,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify the location of pre-compiled intrinsic modules.
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -fopenacc  Enable OpenACC
@@ -71,6 +73,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify the location of pre-compiled intrinsic modules.
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -32,6 +32,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify the location of pre-compiled intrinsic modules.
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
@@ -0,0 +1,87 @@
+!mod$ v1 sum:2bc045d927f2d22c
+module iso_fortran_env
+use __fortran_builtins,only:event_type=>__builtin_event_type
+use __fortran_builtins,only:lock_type=>__builtin_lock_type
+use __fortran_builtins,only:team_type=>__builtin_team_type
+integer(4),parameter::atomic_int_kind=8_4
+intrinsic::selected_int_kind
+integer(4),parameter::atomic_logical_kind=8_4

[PATCH] D97119: [flang][driver] Add options for -std=2018

2021-02-20 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 created this revision.
arnamoy10 added reviewers: awarzynski, sscalpone, clementval, tskeith.
Herald added subscribers: jansvoboda11, dang.
arnamoy10 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add support for the following Fortran dialect options:

-std=2018

It also adds one test cases.  Currently only `2018` is allowed as the standard.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/std2018.f90

Index: flang/test/Flang-Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/std2018.f90
@@ -0,0 +1,33 @@
+! Ensure argument -std=2018 works as expected.
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only -std=2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: not %flang-new -fsyntax-only -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+!  RUN: %flang-new -fc1 -fsyntax-only -std=2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+!  RUN: not %flang-new -fc1 -fsyntax-only -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=2018 is allowed currently.
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -38,6 +38,7 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 
@@ -64,6 +65,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
 
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -38,6 +38,7 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -286,6 +286,21 @@
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+
+  //-std=2018
+  if (args.hasArg(clang::driver::options::OPT_std_EQ)) {
+auto standard = args.getLastArgValue(clang::driver::options::OPT_std_EQ);
+// We only allow 2018 as the given standard
+if (standard.equals("2018")) {
+  res.SetStandard();
+}
+else {
+  const unsigned diagID =
+  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only -std=2018 is allowed currently.");
+  diags.Report(diagID);
+}
+  }
   return;
 }
 
@@ -423,6 +438,11 @@
   // directories
   if (moduleDirJ.compare(".") != 0)
 fortranOptions.searchDirectories.emplace_back(moduleDirJ);
+
+  // Set the standard
+  if (standard_) {
+fortranOptions.features.WarnOnAllNonstandard();
+  }
 }
 
 void CompilerInvocation::setSemanticsOpts(
Index: 

[PATCH] D96131: [clang-tidy] Simplify function complexity check

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp:505
+  functionDecl(isDefinition(), unless(isWeak())).bind("func"), this);
+  Finder->addMatcher(lambdaExpr().bind("lambda"), this);
 }

Am I right in assuming lambdas need to be explicitly matched because in the 
traversal mode their operator() isn't matched as a functionDecl?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96131

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


[PATCH] D96132: [clang-tidy] Simplify throw keyword missing check

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp:97-107
+template 
+void templ(int i) {
+  if (i > 0)
+SomeType();
+}
+
 void funcCallWithTempExcTest() {

Can I ask what the reason for these extra tests are.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96132

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


[PATCH] D52050: [Driver] Fix architecture triplets and search paths for Linux x32

2021-02-20 Thread alsoijw via Phabricator via cfe-commits
alsoijw added a comment.

In D52050#2369838 , @dschuff wrote:

> One other question then: do you know if Debian and/or Ubuntu still have the 
> same support for running x32 programs on the regular x86-64 distribution?

I am not sure that I right understand reason of this question, but there is 
gentoo x32 profile that allow execute all arch x86, x32, x64.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

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


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

2021-02-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:874
 /// [C++0x] static_assert-declaration:
 ///   static_assert ( constant-expression  ,  string-literal  ) ;
 ///

xbolva00 wrote:
> Do we warn for:
> 
> static_assert(“my msg”)? 
> 
> I remember some long time ago bug in llvm itself -  assert(“my msg”) - 
> condition expr was missing.
We don't, but that would be a reasonable warning to add (not necessarily as 
part of this patch).


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] D95754: [clang] Print 32 candidates on the first failure, with -fshow-overloads=best.

2021-02-20 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert accepted this revision.
aaronpuchert added a comment.
This revision is now accepted and ready to land.

Thanks, this looks good to me. Maybe wait a few days whether @rsmith has a 
comment before you land it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95754

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


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

2021-02-20 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:874
 /// [C++0x] static_assert-declaration:
 ///   static_assert ( constant-expression  ,  string-literal  ) ;
 ///

Do we warn for:

static_assert(“my msg”)? 

I remember some long time ago bug in llvm itself -  assert(“my msg”) - 
condition expr was missing.


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] D96974: [clang][patch] Inclusive language, modify filename SanitizerBlacklist.h to NoSanitizeList.h

2021-02-20 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 325191.
mibintc added a comment.
Herald added a subscriber: mgorny.

What do you recommend as next steps, incrementally?  Is there more clarity 
about option names?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96974

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/NoSanitizeList.h
  clang/include/clang/Basic/SanitizerBlacklist.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Basic/NoSanitizeList.cpp
  clang/lib/Basic/SanitizerBlacklist.cpp
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3610,7 +3610,7 @@
 GenerateArg(Args, OPT_fsanitize_EQ, Sanitizer, SA);
 
   // Conflating '-fsanitize-system-blacklist' and '-fsanitize-blacklist'.
-  for (const std::string  : Opts.SanitizerBlacklistFiles)
+  for (const std::string  : Opts.NoSanitizeFiles)
 GenerateArg(Args, OPT_fsanitize_blacklist, F, SA);
 
   if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver3_8)
@@ -4009,12 +4009,11 @@
   // Parse -fsanitize= arguments.
   parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
   Diags, Opts.Sanitize);
-  Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist);
+  Opts.NoSanitizeFiles = Args.getAllArgValues(OPT_fsanitize_blacklist);
   std::vector systemBlacklists =
   Args.getAllArgValues(OPT_fsanitize_system_blacklist);
-  Opts.SanitizerBlacklistFiles.insert(Opts.SanitizerBlacklistFiles.end(),
-  systemBlacklists.begin(),
-  systemBlacklists.end());
+  Opts.NoSanitizeFiles.insert(Opts.NoSanitizeFiles.end(),
+  systemBlacklists.begin(), systemBlacklists.end());
 
   if (Arg *A = Args.getLastArg(OPT_fclang_abi_compat_EQ)) {
 Opts.setClangABICompat(LangOptions::ClangABI::Latest);
Index: clang/lib/CodeGen/SanitizerMetadata.cpp
===
--- clang/lib/CodeGen/SanitizerMetadata.cpp
+++ clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -1,4 +1,4 @@
-//===--- SanitizerMetadata.cpp - Blacklist for sanitizers -===//
+//===--- SanitizerMetadata.cpp - Ignored entities for sanitizers --===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -34,15 +34,15 @@
bool IsExcluded) {
   if (!isAsanHwasanOrMemTag(CGM.getLangOpts().Sanitize))
 return;
-  IsDynInit &= !CGM.isInSanitizerBlacklist(GV, Loc, Ty, "init");
-  IsExcluded |= CGM.isInSanitizerBlacklist(GV, Loc, Ty);
+  IsDynInit &= !CGM.isInNoSanitizeList(GV, Loc, Ty, "init");
+  IsExcluded |= CGM.isInNoSanitizeList(GV, Loc, Ty);
 
   llvm::Metadata *LocDescr = nullptr;
   llvm::Metadata *GlobalName = nullptr;
   llvm::LLVMContext  = CGM.getLLVMContext();
   if (!IsExcluded) {
-// Don't generate source location and global name if it is blacklisted -
-// it won't be instrumented anyway.
+// Don't generate source location and global name if it is on
+// the NoSanitizeList - it won't be instrumented anyway.
 LocDescr = getLocationMetadata(Loc);
 if (!Name.empty())
   GlobalName = llvm::MDString::get(VMContext, Name);
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -25,7 +25,7 @@
 #include "clang/Basic/ABI.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Module.h"
-#include "clang/Basic/SanitizerBlacklist.h"
+#include "clang/Basic/NoSanitizeList.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/XRayLists.h"
 #include "llvm/ADT/DenseMap.h"
@@ -1267,12 +1267,11 @@
   /// annotations are emitted during finalization of the LLVM code.
   void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
 
-  bool isInSanitizerBlacklist(SanitizerMask Kind, llvm::Function *Fn,
-  SourceLocation Loc) const;
+  bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
+  SourceLocation Loc) const;
 
-  bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,

[PATCH] D96974: [clang][patch] Inclusive language, modify filename SanitizerBlacklist.h to NoSanitizeList.h

2021-02-20 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added inline comments.



Comment at: clang/lib/Basic/SanitizerBlacklist.cpp:15
 #include "clang/Basic/FileManager.h"
+#include "clang/Basic/NoSanitizeList.h"
 #include "clang/Basic/SanitizerSpecialCaseList.h"

vitalybuka wrote:
> dexonsmith wrote:
> > vitalybuka wrote:
> > > Own header should go first.
> > Probably a good idea to move the file 
> > `clang/lib/Basic/SanitizerBlacklist.cpp` at the same time as its header 
> > `clang/include/clang/Basic/SanitizerBlacklist.h`; then you won't be 
> > fighting clang-format on this.
> Oh, right, I didn't noticed that. It needs to be fixed.
Oops, good catch, thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96974

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


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

2021-02-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D89065#2320031 , @njames93 wrote:

> I don't see any support for verifying fix-its in the test cases so unsure how 
> i could go about testing this change.

We usually test fix-its with `-fdiagnostics-parseable-fixits` as in the tests 
here: https://github.com/llvm/llvm-project/tree/main/clang/test/FixIt (not 
saying the test has to go into the `FixIt` directory, it should probably live 
in `test/Parser` given the changes.)

Btw, this is going to cause merge conflicts with 
https://reviews.llvm.org/D95396 and I sort of wonder if we should combine the 
two patches into one given that they're fixing the same code in different ways.


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


Re: [PATCH] [clang-tidy] ensure run-clang-tidy reports children killed by signals

2021-02-20 Thread Ian Campbell via cfe-commits
Hi Alexander,

Would it be better if I signed up for Phabricator and sent this there?
I was trying to avoid signing up to yet another service if it wasn't
strictly needed but happy to do it if that's what is expected.

Thanks,
Ian

On Thu, 2021-02-11 at 10:22 +, Ian Campbell wrote:
If a clang-tidy child process exits with a signal then run-clang-tidy
will exit
with an error but there is no hint why in the output, since the clang-
tidy
doesn't log anything and may not even have had the opportunity to do so
depending on the signal used.

`subprocess.CompletedProcess.returncode` is the negative signal number
in this
case.

I hit this in a CI system where the parallelism used exceeded the RAM
assigned
to the container causing the OOM killer to SIGKILL clang-tidy
processes.

Cc: Alexander Kornienko 
---
Please Cc me, I'm not subscribed to cfe-commits
---
 clang-tools-extra/clang-tidy/tool/run-clang-tidy.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 313ecd2f9571..8b2a5bf60d13 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -170,6 +170,9 @@ def run_tidy(args, tmpdir, build_path, queue, lock,
failed_files):
 proc = subprocess.Popen(invocation, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
 output, err = proc.communicate()
 if proc.returncode != 0:
+  if proc.returncode < 0:
+    msg = "%s: terminated by signal %d\n" % (name, -
proc.returncode)
+    err += msg.encode('utf-8')
   failed_files.append(name)
 with lock:
   sys.stdout.write(' '.join(invocation) + '\n' +
output.decode('utf-8'))


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


[PATCH] D96906: [AMDGPU] gfx90a support

2021-02-20 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp:191-199
+  MCRegister RepReg;
+  for (MCRegister R : *MRI->getRegClass(Reg)) {
+if (!MRI->isReserved(R)) {
+  RepReg = R;
+  break;
+}
+  }

rampitec wrote:
> arsenm wrote:
> > rampitec wrote:
> > > arsenm wrote:
> > > > rampitec wrote:
> > > > > arsenm wrote:
> > > > > > This is a problem because I've removed forAllLanes.
> > > > > > 
> > > > > > This is a hack, we should be using a different register class for 
> > > > > > cases that don't support a given subregister index not scanning for 
> > > > > > an example non-reserved register
> > > > > This would be massive duplication of all instructions with such 
> > > > > operands, isn't it?
> > > > Ideally yes. We can still use register classes for this, with special 
> > > > care to make sure we never end up with the unaligned virtual registers 
> > > > in the wrong contexts.
> > > > 
> > > >  The less that's tracked by the instruction definitions, the more 
> > > > special case code we have to right. I've been thinking of swapping out 
> > > > the entire MCInstrDesc table per-subtarget to make this easier, 
> > > > although that may be a painful change.
> > > I do not see how it can be less code. You will need to duplicate all VALU 
> > > pseudos, not just real instructions. Which means every time you write in 
> > > the source something like AMDGPU::FLAT_LOAD_DWORDX2 you would have to 
> > > write an if. For every VALU instruction.
> > It's less code because the code that's already there is supposed to rely on 
> > the static operand definitions. Every time we want to deviate from those, 
> > we end up writing manual code in the verifier and fixup things here and 
> > there that differ.
> > 
> > The point of swapping out the table would be to eliminate all the VALU 
> > pseudos. We would just have the same enum values referring to different 
> > physical instruction definitions
> This makes sense, although as you said also quite painful and to me also 
> sounds like a hack. There is still a lot of legalization needed even with 
> this approach. Every time you hit an instruction not supported by a target 
> you will need to do something about it. In a worst case expanding. Sounds 
> like another year of work. Especially when you look at highly specialized 
> ASICs which can do this but cannot do that, and you have a lot them.
JBTW it will not help anyway. Not for this problem. You may create an operand 
of a different RC or you may just reserve every other register like I did, the 
net result will be the same, you will end up using prohibited register. Imagine 
you are using an RC where only even tuples are added. And then you are using 
sub1_sub2 subreg of it. RA will happily allocate forbidden register just like 
it does now. To me this is RA bug in the first place to allocate a reserved 
register.

The only thing which could help is an another register info without odd wide 
subregs, but that you cannot achieve just by duplication of instruction 
definitions, for that you would need to duplicate register info as well. This 
is almost a new BE.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96906

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


[PATCH] D96906: [AMDGPU] gfx90a support

2021-02-20 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp:191-199
+  MCRegister RepReg;
+  for (MCRegister R : *MRI->getRegClass(Reg)) {
+if (!MRI->isReserved(R)) {
+  RepReg = R;
+  break;
+}
+  }

arsenm wrote:
> rampitec wrote:
> > arsenm wrote:
> > > rampitec wrote:
> > > > arsenm wrote:
> > > > > This is a problem because I've removed forAllLanes.
> > > > > 
> > > > > This is a hack, we should be using a different register class for 
> > > > > cases that don't support a given subregister index not scanning for 
> > > > > an example non-reserved register
> > > > This would be massive duplication of all instructions with such 
> > > > operands, isn't it?
> > > Ideally yes. We can still use register classes for this, with special 
> > > care to make sure we never end up with the unaligned virtual registers in 
> > > the wrong contexts.
> > > 
> > >  The less that's tracked by the instruction definitions, the more special 
> > > case code we have to right. I've been thinking of swapping out the entire 
> > > MCInstrDesc table per-subtarget to make this easier, although that may be 
> > > a painful change.
> > I do not see how it can be less code. You will need to duplicate all VALU 
> > pseudos, not just real instructions. Which means every time you write in 
> > the source something like AMDGPU::FLAT_LOAD_DWORDX2 you would have to write 
> > an if. For every VALU instruction.
> It's less code because the code that's already there is supposed to rely on 
> the static operand definitions. Every time we want to deviate from those, we 
> end up writing manual code in the verifier and fixup things here and there 
> that differ.
> 
> The point of swapping out the table would be to eliminate all the VALU 
> pseudos. We would just have the same enum values referring to different 
> physical instruction definitions
This makes sense, although as you said also quite painful and to me also sounds 
like a hack. There is still a lot of legalization needed even with this 
approach. Every time you hit an instruction not supported by a target you will 
need to do something about it. In a worst case expanding. Sounds like another 
year of work. Especially when you look at highly specialized ASICs which can do 
this but cannot do that, and you have a lot them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96906

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


[PATCH] D96906: [AMDGPU] gfx90a support

2021-02-20 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp:191-199
+  MCRegister RepReg;
+  for (MCRegister R : *MRI->getRegClass(Reg)) {
+if (!MRI->isReserved(R)) {
+  RepReg = R;
+  break;
+}
+  }

rampitec wrote:
> arsenm wrote:
> > rampitec wrote:
> > > arsenm wrote:
> > > > This is a problem because I've removed forAllLanes.
> > > > 
> > > > This is a hack, we should be using a different register class for cases 
> > > > that don't support a given subregister index not scanning for an 
> > > > example non-reserved register
> > > This would be massive duplication of all instructions with such operands, 
> > > isn't it?
> > Ideally yes. We can still use register classes for this, with special care 
> > to make sure we never end up with the unaligned virtual registers in the 
> > wrong contexts.
> > 
> >  The less that's tracked by the instruction definitions, the more special 
> > case code we have to right. I've been thinking of swapping out the entire 
> > MCInstrDesc table per-subtarget to make this easier, although that may be a 
> > painful change.
> I do not see how it can be less code. You will need to duplicate all VALU 
> pseudos, not just real instructions. Which means every time you write in the 
> source something like AMDGPU::FLAT_LOAD_DWORDX2 you would have to write an 
> if. For every VALU instruction.
It's less code because the code that's already there is supposed to rely on the 
static operand definitions. Every time we want to deviate from those, we end up 
writing manual code in the verifier and fixup things here and there that differ.

The point of swapping out the table would be to eliminate all the VALU pseudos. 
We would just have the same enum values referring to different physical 
instruction definitions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96906

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


[PATCH] D96906: [AMDGPU] gfx90a support

2021-02-20 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp:191-199
+  MCRegister RepReg;
+  for (MCRegister R : *MRI->getRegClass(Reg)) {
+if (!MRI->isReserved(R)) {
+  RepReg = R;
+  break;
+}
+  }

arsenm wrote:
> rampitec wrote:
> > arsenm wrote:
> > > This is a problem because I've removed forAllLanes.
> > > 
> > > This is a hack, we should be using a different register class for cases 
> > > that don't support a given subregister index not scanning for an example 
> > > non-reserved register
> > This would be massive duplication of all instructions with such operands, 
> > isn't it?
> Ideally yes. We can still use register classes for this, with special care to 
> make sure we never end up with the unaligned virtual registers in the wrong 
> contexts.
> 
>  The less that's tracked by the instruction definitions, the more special 
> case code we have to right. I've been thinking of swapping out the entire 
> MCInstrDesc table per-subtarget to make this easier, although that may be a 
> painful change.
I do not see how it can be less code. You will need to duplicate all VALU 
pseudos, not just real instructions. Which means every time you write in the 
source something like AMDGPU::FLAT_LOAD_DWORDX2 you would have to write an if. 
For every VALU instruction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96906

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


[PATCH] D96906: [AMDGPU] gfx90a support

2021-02-20 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp:191-199
+  MCRegister RepReg;
+  for (MCRegister R : *MRI->getRegClass(Reg)) {
+if (!MRI->isReserved(R)) {
+  RepReg = R;
+  break;
+}
+  }

rampitec wrote:
> arsenm wrote:
> > This is a problem because I've removed forAllLanes.
> > 
> > This is a hack, we should be using a different register class for cases 
> > that don't support a given subregister index not scanning for an example 
> > non-reserved register
> This would be massive duplication of all instructions with such operands, 
> isn't it?
Ideally yes. We can still use register classes for this, with special care to 
make sure we never end up with the unaligned virtual registers in the wrong 
contexts.

 The less that's tracked by the instruction definitions, the more special case 
code we have to right. I've been thinking of swapping out the entire 
MCInstrDesc table per-subtarget to make this easier, although that may be a 
painful change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96906

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


[PATCH] D97109: [clangd] Add support for auxiliary triple specification

2021-02-20 Thread Tommy Chiang via Phabricator via cfe-commits
oToToT added inline comments.



Comment at: clang/lib/Frontend/PrecompiledPreamble.cpp:311
 
 llvm::ErrorOr PrecompiledPreamble::Build(
 const CompilerInvocation ,

Though this file is in clang, clangd use this function to prepare preamble in 
`Preamble.cpp`, and I think it is OK to add support for auxiliary triple here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97109

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


[PATCH] D97109: [clangd] Add support for auxiliary triple specification

2021-02-20 Thread Tommy Chiang via Phabricator via cfe-commits
oToToT updated this revision to Diff 325186.
oToToT added a comment.

re-upload diff with full context, sorry for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97109

Files:
  clang-tools-extra/clangd/Compiler.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp


Index: clang/lib/Frontend/PrecompiledPreamble.cpp
===
--- clang/lib/Frontend/PrecompiledPreamble.cpp
+++ clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -370,12 +370,33 @@
   if (!Clang->hasTarget())
 return BuildPreambleError::CouldntCreateTargetInfo;
 
+  // Correctly set AuxTarget. The code is borrowed from
+  // `CompilerInstance::ExecuteAction(FrontendAction &)` inside
+  // "clang/lib/Frontend/CompilerInstance.cpp"
+  if ((Clang->getLangOpts().CUDA || Clang->getLangOpts().OpenMPIsDevice ||
+   Clang->getLangOpts().SYCLIsDevice) &&
+  !Clang->getFrontendOpts().AuxTriple.empty()) {
+auto TO = std::make_shared();
+TO->Triple = llvm::Triple::normalize(Clang->getFrontendOpts().AuxTriple);
+if (Clang->getFrontendOpts().AuxTargetCPU)
+  TO->CPU = Clang->getFrontendOpts().AuxTargetCPU.getValue();
+if (Clang->getFrontendOpts().AuxTargetFeatures)
+  TO->FeaturesAsWritten =
+  Clang->getFrontendOpts().AuxTargetFeatures.getValue();
+TO->HostTriple = Clang->getTarget().getTriple().str();
+Clang->setAuxTarget(
+TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), TO));
+  }
+
   // Inform the target of the language options.
   //
   // FIXME: We shouldn't need to do this, the target should be immutable once
   // created. This complexity should be lifted elsewhere.
   Clang->getTarget().adjust(Clang->getLangOpts());
 
+  if (auto *Aux = Clang->getAuxTarget())
+Clang->getTarget().setAuxTarget(Aux);
+
   if (Clang->getFrontendOpts().Inputs.size() != 1 ||
   Clang->getFrontendOpts().Inputs[0].getKind().getFormat() !=
   InputKind::Source ||
Index: clang-tools-extra/clangd/Compiler.cpp
===
--- clang-tools-extra/clangd/Compiler.cpp
+++ clang-tools-extra/clangd/Compiler.cpp
@@ -123,6 +123,33 @@
   if (!Clang->hasTarget())
 return nullptr;
 
+  // Correctly set AuxTarget. The code is borrowed from
+  // `CompilerInstance::ExecuteAction(FrontendAction &)` inside
+  // "clang/lib/Frontend/CompilerInstance.cpp"
+  if ((Clang->getLangOpts().CUDA || Clang->getLangOpts().OpenMPIsDevice ||
+   Clang->getLangOpts().SYCLIsDevice) &&
+  !Clang->getFrontendOpts().AuxTriple.empty()) {
+auto TO = std::make_shared();
+TO->Triple = llvm::Triple::normalize(Clang->getFrontendOpts().AuxTriple);
+if (Clang->getFrontendOpts().AuxTargetCPU)
+  TO->CPU = Clang->getFrontendOpts().AuxTargetCPU.getValue();
+if (Clang->getFrontendOpts().AuxTargetFeatures)
+  TO->FeaturesAsWritten =
+  Clang->getFrontendOpts().AuxTargetFeatures.getValue();
+TO->HostTriple = Clang->getTarget().getTriple().str();
+Clang->setAuxTarget(
+TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), TO));
+  }
+
+  // Inform the target of the language options.
+  //
+  // FIXME: We shouldn't need to do this, the target should be immutable once
+  // created. This complexity should be lifted elsewhere.
+  Clang->getTarget().adjust(Clang->getLangOpts());
+
+  if (auto *Aux = Clang->getAuxTarget())
+Clang->getTarget().setAuxTarget(Aux);
+
   // RemappedFileBuffers will handle the lifetime of the Buffer pointer,
   // release it.
   Buffer.release();


Index: clang/lib/Frontend/PrecompiledPreamble.cpp
===
--- clang/lib/Frontend/PrecompiledPreamble.cpp
+++ clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -370,12 +370,33 @@
   if (!Clang->hasTarget())
 return BuildPreambleError::CouldntCreateTargetInfo;
 
+  // Correctly set AuxTarget. The code is borrowed from
+  // `CompilerInstance::ExecuteAction(FrontendAction &)` inside
+  // "clang/lib/Frontend/CompilerInstance.cpp"
+  if ((Clang->getLangOpts().CUDA || Clang->getLangOpts().OpenMPIsDevice ||
+   Clang->getLangOpts().SYCLIsDevice) &&
+  !Clang->getFrontendOpts().AuxTriple.empty()) {
+auto TO = std::make_shared();
+TO->Triple = llvm::Triple::normalize(Clang->getFrontendOpts().AuxTriple);
+if (Clang->getFrontendOpts().AuxTargetCPU)
+  TO->CPU = Clang->getFrontendOpts().AuxTargetCPU.getValue();
+if (Clang->getFrontendOpts().AuxTargetFeatures)
+  TO->FeaturesAsWritten =
+  Clang->getFrontendOpts().AuxTargetFeatures.getValue();
+TO->HostTriple = Clang->getTarget().getTriple().str();
+Clang->setAuxTarget(
+TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), TO));
+  }
+
   // Inform the target of the language options.
   //
   // FIXME: We shouldn't need to do this, the target should be immutable once
   

[PATCH] D97109: [clangd] Add support for auxiliary triple specification

2021-02-20 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Please upload diffs with full context. This can be done by passing `-U99` 
to diff or by using arcanist 
 to upload 
your patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97109

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


[PATCH] D97094: [Driver] Print process statistics report on CC_PRINT_PROC_STAT env variable.

2021-02-20 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/include/clang/Driver/Driver.h:210
 
+  /// Set CC_PRINT_PROC_STAT mode, which causes the frontend to dump
+  /// performance report to CC_PRINT_PROC_STAT_FILE or to stdout.

Strictly speaking it is driver that dumps performance report, not frontend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97094

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


[PATCH] D96110: [X86] Pass to transform tdpbf16ps intrinsics to scalar operation.

2021-02-20 Thread Bing Yu via Phabricator via cfe-commits
yubing updated this revision to Diff 325170.
yubing edited the summary of this revision.
yubing added a comment.

Address comments above and refactor some code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96110

Files:
  clang/include/clang/Basic/BuiltinsX86_64.def
  clang/lib/Headers/amxintrin.h
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/lib/Target/X86/X86ExpandPseudo.cpp
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86InstrAMX.td
  llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp
  llvm/lib/Target/X86/X86LowerAMXType.cpp
  llvm/lib/Target/X86/X86PreTileConfig.cpp
  llvm/lib/Target/X86/X86RegisterInfo.cpp

Index: llvm/lib/Target/X86/X86RegisterInfo.cpp
===
--- llvm/lib/Target/X86/X86RegisterInfo.cpp
+++ llvm/lib/Target/X86/X86RegisterInfo.cpp
@@ -878,6 +878,7 @@
   // We only collect the tile shape that is defined.
   case X86::PTILELOADDV:
   case X86::PTDPBSSDV:
+  case X86::PTDPBF16PSV:
   case X86::PTILEZEROV:
 MachineOperand  = MI->getOperand(1);
 MachineOperand  = MI->getOperand(2);
Index: llvm/lib/Target/X86/X86PreTileConfig.cpp
===
--- llvm/lib/Target/X86/X86PreTileConfig.cpp
+++ llvm/lib/Target/X86/X86PreTileConfig.cpp
@@ -127,6 +127,7 @@
 llvm_unreachable("Unexpected machine instruction on tile");
   case X86::PTILELOADDV:
   case X86::PTDPBSSDV:
+  case X86::PTDPBF16PSV:
   case X86::PTILEZEROV:
 MachineOperand  = const_cast(MI.getOperand(1));
 MachineOperand  = const_cast(MI.getOperand(2));
@@ -221,6 +222,7 @@
   case X86::PTILELOADDV:
   case X86::PTILESTOREDV:
   case X86::PTDPBSSDV:
+  case X86::PTDPBF16PSV:
   case X86::PTILEZEROV:
 return true;
   }
Index: llvm/lib/Target/X86/X86LowerAMXType.cpp
===
--- llvm/lib/Target/X86/X86LowerAMXType.cpp
+++ llvm/lib/Target/X86/X86LowerAMXType.cpp
@@ -69,7 +69,8 @@
   }
   // a * b + c
   // The shape depends on which operand.
-  case Intrinsic::x86_tdpbssd_internal: {
+  case Intrinsic::x86_tdpbssd_internal:
+  case Intrinsic::x86_tdpbf16ps_internal: {
 switch (OpNo) {
 case 3:
   Row = II->getArgOperand(0);
Index: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp
===
--- llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp
+++ llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp
@@ -22,7 +22,6 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/CodeGen/Passes.h"
-
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/CodeGen/ValueTypes.h"
 #include "llvm/IR/DataLayout.h"
@@ -209,11 +208,11 @@
   B.CreateStore(Elt, EltPtr);
 }
 
-static Value *createTileDPBSSDLoops(BasicBlock *Start, BasicBlock *End,
-IRBuilderBase , DomTreeUpdater ,
-LoopInfo , Value *Row, Value *Col,
-Value *K, Value *Acc, Value *LHS,
-Value *RHS) {
+template 
+static Value *createTileDPLoops(BasicBlock *Start, BasicBlock *End,
+IRBuilderBase , DomTreeUpdater ,
+LoopInfo , Value *Row, Value *Col, Value *K,
+Value *Acc, Value *LHS, Value *RHS) {
   Loop *RowLoop = LI.AllocateLoop();
   Loop *ColLoop = LI.AllocateLoop();
   Loop *InnerLoop = LI.AllocateLoop();
@@ -321,17 +320,40 @@
   B.CreateAdd(B.CreateMul(CurrentRow, B.getInt16(16)), CurrentInner);
   Value *IdxB =
   B.CreateAdd(B.CreateMul(CurrentInner, B.getInt16(16)), CurrentCol);
-
-  FixedVectorType *V4I8Ty = FixedVectorType::get(B.getInt8Ty(), 4);
-  FixedVectorType *V4I32Ty = FixedVectorType::get(B.getInt32Ty(), 4);
-  Value *EltC = B.CreateExtractElement(VecCPhi, IdxC);
-  Value *EltA = B.CreateExtractElement(VecA, IdxA);
-  Value *SubVecA = B.CreateBitCast(EltA, V4I8Ty);
-  Value *EltB = B.CreateExtractElement(VecB, IdxB);
-  Value *SubVecB = B.CreateBitCast(EltB, V4I8Ty);
-  Value *SubVecR = B.CreateAddReduce(B.CreateMul(
-  B.CreateSExt(SubVecA, V4I32Ty), B.CreateSExt(SubVecB, V4I32Ty)));
-  Value *ResElt = B.CreateAdd(EltC, SubVecR);
+  Value *ResElt = nullptr;
+  if (IntrID == Intrinsic::x86_tdpbssd_internal) {
+FixedVectorType *V4I8Ty = FixedVectorType::get(B.getInt8Ty(), 4);
+FixedVectorType *V4I32Ty = FixedVectorType::get(B.getInt32Ty(), 4);
+Value *EltC = B.CreateExtractElement(VecCPhi, IdxC);
+Value *EltA = B.CreateExtractElement(VecA, IdxA);
+Value *SubVecA = B.CreateBitCast(EltA, V4I8Ty);
+Value *EltB = B.CreateExtractElement(VecB, IdxB);
+Value *SubVecB = B.CreateBitCast(EltB, V4I8Ty);
+Value *SubVecR = B.CreateAddReduce(B.CreateMul(
+B.CreateSExt(SubVecA, V4I32Ty), 

[PATCH] D93594: [X86] Pass to transform amx intrinsics to scalar operation.

2021-02-20 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added inline comments.



Comment at: llvm/include/llvm/CodeGen/Passes.h:496
+
+  FunctionPass *createX86LowerAMXIntrinsicsPass();
 } // End llvm namespace

Add comments to describe what the pass does?



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:1
+//===- llvm/CodeGen/TileShapeInfo.h - ---*- C++ 
-*-===//
+//

This seems wrong file name.



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:11
+/// This pass is only enabled with -O0. With -O0, the def of shape to amx
+/// intrinsics is near the amx intrinsics code. We are not bale to find a
+/// point which post-dominate all the shape and dominate all amx intrinsics.

Type 'able'.



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:159
+ Value *Ptr, Value *Stride, Value *Tile) {
+  Loop *RowLoop = LI.AllocateLoop();
+  Loop *ColLoop = LI.AllocateLoop();

Not sure if we can extract the common code of createTileLoadLoops and 
createTileStoreLoops, so that it can be used by both and some other functions.



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:250
+  FixedVectorType *V256I32Ty = FixedVectorType::get(B.getInt32Ty(), 256);
+  // Type *EltTy = V256I32Ty->getElementType();
+  Value *VecC, *VecA, *VecB;

Delete the dead code.



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:267
+  // %vec.c.phi.row = phi <256 x i32> [ %VecC, %continue ], [ %NewVecC,
+  // %tiledpbssd.scalarize.rows.latch ] %vec.d.phi.row = phi <256 x i32> [
+  // zeroinitializer, %continue ], [ %NewVecD, %tiledpbssd.scalarize.rows.latch

It should be in another line.



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:280
+  // %tiledpbssd.scalarize.rows.body ], [ %NewVecC,
+  // %tiledpbssd.scalarize.cols.latch ] %vec.d.phi.col = phi <256 x i32> [
+  // %vec.d.phi.row, %tiledpbssd.scalarize.rows.body ], [ %NewVecD,

Better to be in a new line.



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:292
+  // %tiledpbssd.scalarize.cols.body ], [ %NewVecC,
+  // %tiledpbssd.scalarize.inner.latch ] %vec.d.inner.phi = phi <256 x i32> [
+  // %vec.d.phi.col, %tiledpbssd.scalarize.cols.body ], [ %NewVecD,

Better to be in a new line.



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:372
+  Instruction *InsertI = TileDPBSSD;
+  IRBuilder<> BuilderPrepare(TileDPBSSD);
+  BuilderPrepare.SetInsertPoint(TileDPBSSD);

The name seems not good. Is "PreBuilder" better? And why we need two builder in 
the function?



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:377
+  // %k_dword = udiv i16 %k, 4
+  Value *NDWord = BuilderPrepare.CreateUDiv(N, BuilderPrepare.getInt16(4));
+  Value *KDWord = BuilderPrepare.CreateUDiv(K, BuilderPrepare.getInt16(4));

Maybe use right shift instruction which is more efficient. Don't the following 
pass can optimize the operation.



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:411
+  Instruction *InsertI = TileLoad;
+  IRBuilder<> BuilderPrepare(TileLoad);
+  BuilderPrepare.SetInsertPoint(TileLoad);

Is "PreBuilder" better?



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:415
+  Value *StrideDWord =
+  BuilderPrepare.CreateUDiv(Stride, BuilderPrepare.getInt64(4));
+  BasicBlock *Start = InsertI->getParent();

Shift?



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:448
+  Instruction *InsertI = TileStore;
+  IRBuilder<> BuilderPrepare(TileStore);
+  BuilderPrepare.SetInsertPoint(TileStore);

PreBuilder?



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:487
+  SmallVector WorkList;
+  for (BasicBlock *BB : depth_first()) {
+for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE;) {

Do we iterate the instructions in topology order or in post order?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93594

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


[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-02-20 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov marked 3 inline comments as done.
azabaznov added inline comments.



Comment at: clang/lib/Basic/OpenCLOptions.cpp:24
+  auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
+  return CLVer >= 300 ? isEnabled("__opencl_c_fp64") : 
isEnabled("cl_khr_fp64");
+}

Anastasia wrote:
> azabaznov wrote:
> > Anastasia wrote:
> > > We should at least be checking for `isSupported("__opencl_c_fp64")`, but 
> > > frankly I would prefer to check for supported and not for enabled for 
> > > `cl_khr_fp64` too. Note that we don't break backward compatibility if we 
> > > change this because the existing kernels will still be valid and it makes 
> > > things easier for writing new kernels too.
> > I think everything fine with this for now because 
> > `OpenCLOptions::enableSupportedCore` is called to set all supported core or 
> > optional core features to enabled state. So you suggest to removing this 
> > method at all too?
> > 
> > I think with your approach things will be unobvious in code: for some 
> > extensions there will be check for `isSupported` for some other there will 
> > be check for `isEnabled`. I think we should stay consistent here and check 
> > availability of all options in the same manner.
> > I think everything fine with this for now because 
> > OpenCLOptions::enableSupportedCore is called to set all supported core or 
> > optional core features to enabled state. So you suggest to removing this 
> > method at all too?
> 
> Yes, I find it redundant somehow. Maybe it's best to indeed remove enabling 
> functionality for features since we definitely don't plan to use pragmas for 
> those? However, I appreciate it might be better to do as a separate change.
> 
>  
> > I think with your approach things will be unobvious in code: for some 
> > extensions there will be check for isSupported for some other there will be 
> > check for isEnabled. I think we should stay consistent here and check 
> > availability of all options in the same manner.
> 
> That's right, we might get some inconsistency at the start. But I think we 
> should drive towards checking `isSupported` rather than `isEnabled`. I don't 
> think we will have many cases for `isEnabled` at the end.
Thanks for feedback. I did some refactoring needed for this patch to proceed: 
https://reviews.llvm.org/D97058. AFAIU it doesn't conflict with the one you did 
(https://reviews.llvm.org/D97052). 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96524

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


[PATCH] D97052: [OpenCL] Prevent adding extension pragma by default

2021-02-20 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:71
+OPENCL_EXTENSION(cl_khr_int64_extended_atomics, true, 100)
+OPENCL_COREFEATURE(cl_khr_3d_image_writes, true, 100, OCL_C_20)
 

Anastasia wrote:
> azabaznov wrote:
> > I think core and optional core features do not require pragma too. So for 
> > example 3d image writes or fp64 do not require pragma in OpenCL C 2.0. 
> > Isn't that so?
> Well to be honest nothing seems to need pragma but we have to accept it for 
> the backward compatibility. :)
> 
> In case of the core features if pragma would have been useful we would have 
> to still accept it for the backward compatibility even if the feature became 
> core.
I'm just wondering if this new field needed in the file to maintain backward 
compatibility. Maybe we can highlight OpenCL C 3.0 features with some other 
way? Is it seems that check for name starting with "__opencl_c" is a bad idea?



Comment at: clang/lib/Parse/ParsePragma.cpp:785
+  // Therefore, it should never be added by default.
+  Opt.acceptsPragma(Name);
 }

Anastasia wrote:
> svenvh wrote:
> > I fail to understand why this is needed, so perhaps this needs a bit more 
> > explanation.  Extensions that should continue to support pragmas already 
> > have their `WithPragma` field set to `true` via `OpenCLExtensions.def`.  
> > Why do we need to dynamically modify the field?
> It is a bit twisty here to be honest. Because we have also introduced the 
> pragma `begin` and `end` that would add pragma `enable`/`disable` by default. 
> So any extension added dynamically using `begin`/`end` would have to accept 
> the pragma `enable`/`disable`. 
> 
> https://clang.llvm.org/docs/UsersManual.html#opencl-extensions
> 
> But in the subsequent patches, I hope to remove this because I just don't see 
> where it is useful but it is very confusing.
Is it ok not to track this situation here:

```
#pragma OPENCL EXTENSION __opencl_c_feature : begin
#pragma OPENCL EXTENSION __opencl_c_feature: end
```

This is some of a corner case, but still...


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

https://reviews.llvm.org/D97052

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