[clang-tools-extra] [clangd] Resolve the dependent type from its single instantiation. Take 1 (PR #71279)

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

HighCommander4 wrote:

I thought some more about this.

I appreciate better now the question you asked here:

> I realized that we had to tackle synthesized types e.g.
> > ```c++
> > template  typename C, typename D, int E>
> > void work() {
> >   C complicated_type;
> >   // ^ Shall we perform the type substitution once again? ;)
> > }
> > ```

My previous suggestion side-steps this by saying that we're only going to do 
lookups in the primary template scope of the argument for `C`, so we don't need 
to worry about substituting the arguments for `D` and `E`.

However, if in the future we want to be more accurate and e.g. handle cases 
where a template specialization resolves to something different than the 
primary template (e.g. a partial specialization), then your question becomes 
relevant: do we perform type substitution again with the arguments for `D` and 
`E`, or do we just fish out the already-substituted type from the "only 
instantiation"?

I realized that this consideration actually applies to any other "resolution" 
step performed in `HeuristicResolver`, including steps it already does today 
such as name lookup.

To illustrate, let's go back to the `vector` example:

```c++
template 
void work() {
  std::vector a;
  a.pop_back();
}
```

To resolve the dependent member expression `a.pop_back`, `HeuristicResolver` 
currently performs name lookup in the primary template scope of `std::vector` 
for the name `pop_back`.

The name lookup step could also be avoided in principle if we had an "only 
instantiation": if we find the non-dependent `MemberExpr` that `a.pop_back` 
instantiates to in the "only instantiation", that will point directly to a 
`CXXMethoDecl`, and we have our result without having done the work of a name 
lookup in the primary template scope.

And this method can lead to more accurate results, e.g. if instead of 
`pop_back` we have an overloaded method name, the name lookup in the primary 
template scope will just return all overloads (since we're not using 
information about the argument types), whereas the instantiated expression in 
the "only instantiation" will point to the correct overload resolution result.

---

So, I think we could consider two alternative approaches to this:

**Approach 1**: What I suggested in the previous review: a limited use of the 
"only instantiation" in `HeuristicResolver` to map template parameter types to 
the type of their argument in the "only instantiation".

**Approach 2**: If there is an "only instantiation", then resolve any 
expression, type, etc. in the template body to the corresponding expression, 
type, etc. in the "only instantiation".

The implementation of "Approach 2" could look similar to the current 
`InstantiatedDeclVisitor` in the patch, except the node type we are searching 
for is not limited to a Decl, it can also be other node types like Stmt etc.

"Approach 2" can be largely independent of `HeuristicResolver`: since we are 
finding a concrete result for the thing we're trying to resolve in the "only 
instantiation", no further resolution steps (e.g. name lookup, or anything else 
that `HeuristicResolver` does) should be necessary. However, the entry point to 
the check can be the same (e.g. for resolving a dependent member expr, we'd 
want to do the "only instantiation" check in the same cases where we call 
`HeuristicResolver::resolveMemberExpr()` from external code), so the 
functionality could still live in `HeuristicResolver` for organizational 
purposes.

https://github.com/llvm/llvm-project/pull/71279
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Don't show inlay hints for __builtin_dump_struct (PR #71366)

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


@@ -1724,6 +1724,33 @@ TEST(InlayHints, RestrictRange) {
   ElementsAre(labelIs(": int"), labelIs(": char")));
 }
 
+TEST(ParameterHints, PseudoObjectExpr) {
+  Annotations Code(R"cpp(
+struct S {
+  __declspec(property(get=GetX, put=PutX)) int x[];
+  int GetX(int y, int z) { return 42 + y; }
+  void PutX(int y) { x = $one[[y]]; } // FIXME: Undesired `x = y: y` for 
this ill-formed expression.

HighCommander4 wrote:

I'm not sure what other bad cases there might be, but excluding cases where the 
syntactic form is a `BinaryOperator` to avoid this case sounds fine to me.

https://github.com/llvm/llvm-project/pull/71366
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Don't show inlay hints for __builtin_dump_struct (PR #71366)

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


@@ -1724,6 +1724,36 @@ TEST(InlayHints, RestrictRange) {
   ElementsAre(labelIs(": int"), labelIs(": char")));
 }
 
+TEST(ParameterHints, PseudoObjectExpr) {
+  Annotations Code(R"cpp(
+struct S {
+  __declspec(property(get=GetX, put=PutX)) int x[];
+  int GetX(int y, int z) { return 42 + y; }
+  // FIXME: Undesired hint `x = y: y`. This builds a PseudoObjectExpr too.
+  void PutX(int y) { x = $one[[y]]; }

HighCommander4 wrote:

While it may not be ill-formed, I think the fact that this causes an infinite 
recursion at runtime is a distraction for someone reading the test.

I would suggest instead something like:

```
void PutX(int y) {}

// FIXME: Undesired hint `x = y: y`. This builds a PseudoObjectExpr too.
void SomeOtherFunction(int y) { x = $one[[y]]; }
```

https://github.com/llvm/llvm-project/pull/71366
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Don't show inlay hints for __builtin_dump_struct (PR #71366)

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


@@ -589,6 +589,24 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool TraversePseudoObjectExpr(PseudoObjectExpr *E) {
+// Do not show inlay hints for the __builtin_dump_struct, which would
+// expand to a PseudoObjectExpr that includes a couple of calls to a
+// printf function. Printing parameter names for that anyway would end up
+// with duplicate parameter names (which, however, got de-duplicated after
+// visiting) for the printf function.
+if (auto *CE = dyn_cast(E->getSyntacticForm());
+CE && CE->getBuiltinCallee() == Builtin::BI__builtin_dump_struct)
+  // Only traverse the syntactic forms. This leaves the door open in case
+  // the arguments in the syntactic form for __builtin_dump_struct could
+  // possibly get parameter names.
+  return RecursiveASTVisitor::TraverseStmt(
+  E->getSyntacticForm());
+// FIXME: Shall we ignore semantic forms for other pseudo object

HighCommander4 wrote:

This is not a case where the **syntactic** form is a `CallExpr` (here the 
syntactic form is an `MSPropertySubscriptExpr`), so here the hints would be 
retained.

https://github.com/llvm/llvm-project/pull/71366
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [clang] Fix #41439: Update the documentation with the correct information. (PR #69377)

2023-11-25 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69377

>From 0e0a3e7ad1a0a7098e05a5164413369eaa58c55b Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Tue, 17 Oct 2023 20:49:47 +0100
Subject: [PATCH 1/2] Fix #41439: Update the documentation with the correct
 information.

---
 .../clang-tidy/checks/readability/named-parameter.rst| 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
index 8d28c0aa02169a7..7e7099b3df251d1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
@@ -10,7 +10,12 @@ Guide:
 
 
https://google.github.io/styleguide/cppguide.html#Function_Declarations_and_Definitions
 
-All parameters should be named, with identical names in the declaration and
-implementation.
+A parameter name may be omitted only if the parameter is not used in the
+function's definition.
+
+.. code-block:: c++
+int doingSomething(int a, int b, int) {  // Ok: the third paramet is not used
+return a + b;
+}
 
 Corresponding cpplint.py check name: `readability/function`.

>From 9c6bb278d10264d3a47752062e754dba5a372cec Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sat, 11 Nov 2023 20:27:05 +
Subject: [PATCH 2/2] Fix: Add the recommended explanation

---
 .../docs/clang-tidy/checks/readability/named-parameter.rst| 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
index 7e7099b3df251d1..603a186862451be 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
@@ -10,8 +10,8 @@ Guide:
 
 
https://google.github.io/styleguide/cppguide.html#Function_Declarations_and_Definitions
 
-A parameter name may be omitted only if the parameter is not used in the
-function's definition.
+All parameters should have the same name in both the function declaration and 
definition.
+If a parameter is not utilized, its name can be commented out in a function 
definition.
 
 .. code-block:: c++
 int doingSomething(int a, int b, int) {  // Ok: the third paramet is not used

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


[libc] [llvm] [flang] [lld] [libcxx] [lldb] [libcxxabi] [clang] [flang] Pass Argv0 to getIntriniscDir and getOpenMPHeadersDir (PR #73254)

2023-11-25 Thread via cfe-commits

https://github.com/madanial0 updated 
https://github.com/llvm/llvm-project/pull/73254

>From 81d1e05dd084dd5bb88dab88d2f23008b8dc6cfb Mon Sep 17 00:00:00 2001
From: Mark Danial 
Date: Tue, 21 Nov 2023 12:18:40 -0500
Subject: [PATCH] Pass the correct path to getIntriniscDir and
 getOpenMPHeadersDir

---
 .../include/flang/Frontend/CompilerInvocation.h  |  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp| 16 ++--
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/flang/include/flang/Frontend/CompilerInvocation.h 
b/flang/include/flang/Frontend/CompilerInvocation.h
index 229aa75748f725d..b345806586e04ef 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -101,6 +101,8 @@ class CompilerInvocation : public CompilerInvocationBase {
 
   bool warnAsErr = false;
 
+  const char *argv0;
+
   /// This flag controls the unparsing and is used to decide whether to print
   /// out the semantically analyzed version of an object or expression or the
   /// plain version that does not include any information from semantic
@@ -190,6 +192,8 @@ class CompilerInvocation : public CompilerInvocationBase {
 return enableConformanceChecks;
   }
 
+  const char *getArgv0() { return argv0; }
+
   bool () { return enableUsageChecks; }
   const bool () const { return enableUsageChecks; }
 
@@ -223,6 +227,8 @@ class CompilerInvocation : public CompilerInvocationBase {
   void setEnableUsageChecks() { enableUsageChecks = true; }
 
   /// Useful setters
+  void setArgv0(const char *dir) { argv0 = dir; }
+
   void setModuleDir(std::string ) { moduleDir = dir; }
 
   void setModuleFileSuffix(const char *suffix) {
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index cb4f2d6a6225205..2afea5ad6b9d97c 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -687,19 +687,19 @@ static bool parseFrontendArgs(FrontendOptions , 
llvm::opt::ArgList ,
 }
 
 // Generate the path to look for intrinsic modules
-static std::string getIntrinsicDir() {
+static std::string getIntrinsicDir(const char *argv) {
   // TODO: Find a system independent API
   llvm::SmallString<128> driverPath;
-  driverPath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr));
+  driverPath.assign(llvm::sys::fs::getMainExecutable(argv, nullptr));
   llvm::sys::path::remove_filename(driverPath);
   driverPath.append("/../include/flang/");
   return std::string(driverPath);
 }
 
 // Generate the path to look for OpenMP headers
-static std::string getOpenMPHeadersDir() {
+static std::string getOpenMPHeadersDir(const char *argv) {
   llvm::SmallString<128> includePath;
-  includePath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr));
+  includePath.assign(llvm::sys::fs::getMainExecutable(argv, nullptr));
   llvm::sys::path::remove_filename(includePath);
   includePath.append("/../include/flang/OpenMP/");
   return std::string(includePath);
@@ -1203,6 +1203,8 @@ bool CompilerInvocation::createFromArgs(
 }
   }
 
+  res.setArgv0(argv0);
+
   return success;
 }
 
@@ -1245,7 +1247,8 @@ void CompilerInvocation::setDefaultFortranOpts() {
 
   // Add the location of omp_lib.h to the search directories. Currently this is
   // identical to the modules' directory.
-  fortranOptions.searchDirectories.emplace_back(getOpenMPHeadersDir());
+  fortranOptions.searchDirectories.emplace_back(
+  getOpenMPHeadersDir(getArgv0()));
 
   fortranOptions.isFixedForm = false;
 }
@@ -1310,7 +1313,8 @@ void CompilerInvocation::setFortranOpts() {
   preprocessorOptions.searchDirectoriesFromIntrModPath.end());
 
   //  Add the default intrinsic module directory
-  fortranOptions.intrinsicModuleDirectories.emplace_back(getIntrinsicDir());
+  fortranOptions.intrinsicModuleDirectories.emplace_back(
+  getIntrinsicDir(getArgv0()));
 
   // Add the directory supplied through -J/-module-dir to the list of search
   // directories

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


[clang-tools-extra] [llvm] [clang] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-11-25 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69102

>From 21156656433fb8d2dc5a805d97cbd20fa916fff9 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 15 Oct 2023 11:39:42 +0100
Subject: [PATCH 1/8] Fix #35272: Don't replace typedefs in extern c scope

---
 .../clang-tidy/modernize/UseUsingCheck.cpp   | 16 
 .../clang-tidy/checkers/modernize/use-using.cpp  | 14 ++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index e6293ed48bfddbb..841ffb4c9bfe66e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -11,6 +11,12 @@
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
+namespace {
+
+AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
+  return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
+}
+} // namespace
 
 namespace clang::tidy::modernize {
 
@@ -27,10 +33,12 @@ void 
UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap ) {
 }
 
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(typedefDecl(unless(isInstantiated()),
- hasParent(decl().bind(ParentDeclName)))
- .bind(TypedefName),
- this);
+  Finder->addMatcher(
+  typedefDecl(unless(anyOf(isInstantiated(), hasAncestor(linkageSpecDecl(
+ isExternCLinkage(),
+  hasParent(decl().bind(ParentDeclName)))
+  .bind(TypedefName),
+  this);
 
   // This matcher is used to find tag declarations in source code within
   // typedefs. They appear in the AST just *prior* to the typedefs.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 422abee11a71962..0f8f14502d5ca3c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -325,3 +325,17 @@ typedef bool (*ISSUE_65055_2)(int);
 typedef class ISSUE_67529_1 *ISSUE_67529;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;
+
+// Some Header
+extern "C" {
+
+typedef int InExternC;
+}
+
+extern "C++" {
+
+typedef int InExternCPP;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+// CHECK-FIXES: using InExternCPP = int;
+
+}

>From 521dec9325285d1e1819a8bee1bd20eadb7c4158 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Mon, 16 Oct 2023 23:26:25 +0100
Subject: [PATCH 2/8] Add: Update docs with the new changes. Update
 ReleaseNotes.rst with the changes made

---
 clang-tools-extra/docs/ReleaseNotes.rst  | 5 +
 .../docs/clang-tidy/checks/modernize/use-using.rst   | 9 +
 2 files changed, 14 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c1b926b296b055a..af6b20369c9dcff 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -285,6 +285,10 @@ Changes in existing checks
   ` check to fix function pointer and
   forward declared ``typedef`` correctly.
 
+- Improved :doc:`modernize-use-using
+  ` by ignoring ``typedef`` declaration 
in
+  ``extern "C"`` scope.
+
 - Improved :doc:`performance-faster-string-find
   ` check to properly escape
   single quotes.
@@ -325,6 +329,7 @@ Changes in existing checks
   identify calls to static member functions with out-of-class inline 
definitions.
 
 
+
 Removed checks
 ^^
 
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
index eeddaf8d8d65abe..048fc26617b7b73 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
@@ -28,6 +28,15 @@ After:
   using R_t = struct { int a; };
   using R_p = R_t*;
 
+The checker ignores `typedef` within `extern "C" { ... }` blocks.
+
+.. code-block:: c++
+
+  extern "C" {
+
+typedef int InExternC; // Left intact.
+  }
+
 This check requires using C++11 or higher to run.
 
 Options

>From 3426e0a36606a7e3eeb38c0f436c25aa2fde2b36 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 22 Oct 2023 20:02:20 +0100
Subject: [PATCH 3/8] Update: commit with review requested changes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 6 +-
 .../docs/clang-tidy/checks/modernize/use-using.rst  | 2 --
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 

[clang-tools-extra] [llvm] [clang] [LLVM] Add IRNormalizer Pass (PR #68176)

2023-11-25 Thread Justin Fargnoli via cfe-commits

justinfargnoli wrote:

Pinging @nikic for another round of review. 

https://github.com/llvm/llvm-project/pull/68176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-25 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/73124

>From ba38aec7ac04c63fd5167908fe7f91d6ac7bceed Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 14:22:20 +0100
Subject: [PATCH 01/11] Let the linker fail on multiple definitions of main()

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 5d2cd1959b06925..30c249d05677ce5 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1018,7 +1018,20 @@ void tools::addFortranRuntimeLibs(const ToolChain , 
const ArgList ,
   break;
 }
   } else {
+// --whole-archive needs to be part of the link line to make sure
+// that the main() function from Fortran_main.a is pulled in by
+// the linker.
+//
+// We are using this --whole-archive/--no-whole-archive bracket w/o
+// any further checks, because -Wl,--whole-archive at the flang-new new
+// line will not sucessfully complete, unless the user correctly specified
+// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
+// -Wl,--no-whole-archive).
+CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
+CmdArgs.push_back("--no-whole-archive");
+
+// Perform regular linkage of the remaining runtime libraries.
 CmdArgs.push_back("-lFortranRuntime");
 CmdArgs.push_back("-lFortranDecimal");
   }
@@ -1029,7 +1042,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
,
  ArgStringList ) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to use
+  // this in the future. In particular, on some platforms, we may need to useq
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 7d1180b11ed02cedf1c9fea56bf2ff329274c066 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 15:18:51 +0100
Subject: [PATCH 02/11] Improve comments and remove accidental typo

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 30c249d05677ce5..12e3ce184898250 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1023,10 +1023,10 @@ void tools::addFortranRuntimeLibs(const ToolChain , 
const ArgList ,
 // the linker.
 //
 // We are using this --whole-archive/--no-whole-archive bracket w/o
-// any further checks, because -Wl,--whole-archive at the flang-new new
-// line will not sucessfully complete, unless the user correctly specified
-// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
-// -Wl,--no-whole-archive).
+// any further checks, because -Wl,--whole-archive at the flang
+// driver's link line will not sucessfully complete, unless the user
+// correctly specified -Wl,--whole-archive/-Wl,--no-whole-archive
+// (e.g., -Wl,--whole-archive -ldummy -Wl,--no-whole-archive).
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
 CmdArgs.push_back("--no-whole-archive");
@@ -1042,7 +1042,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
,
  ArgStringList ) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to useq
+  // this in the future. In particular, on some platforms, we may need to use
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 30dab7ebddf1de4836fc3d532fc33b4a7e58837d Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 20:26:02 +0100
Subject: [PATCH 03/11] Correct link line test for flang-new (for Linux)

---
 flang/test/Driver/linker-flags.f90 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index a1417057d4da068..55b13952db43c17 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -31,7 +31,7 @@
 !   executable and may find the GNU linker from MinGW or Cygwin.
 ! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! UNIX-SAME: "[[object_file]]"
-! UNIX-SAME: "-lFortran_main" "-lFortranRuntime" "-lFortranDecimal" "-lm"
+! UNIX-SAME: "--whole-archive" "-lFortran_main" "--no-whole-archive" 
"-lFortranRuntime" "-lFortranDecimal" "-lm"
 
 ! 

[clang] bee78b8 - Reland "[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes" (#73087)

2023-11-25 Thread via cfe-commits

Author: antangelo
Date: 2023-11-25T14:26:44-05:00
New Revision: bee78b88f8effdb378a809e0416988ce9c37f5ac

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

LOG: Reland "[clang][Sema] Use original template pattern when declaring 
implicit deduction guides for nested template classes" (#73087)

Reland of f418319730341e9d41ce8ead6fbfe5603c343985 with proper handling
of template constructors

When a nested template is instantiated, the template pattern of the
inner class is not copied into the outer class
ClassTemplateSpecializationDecl. The specialization contains a
ClassTemplateDecl with an empty record that points to the original
template pattern instead.

As a result, when looking up the constructors of the inner class, no
results are returned. This patch finds the original template pattern and
uses that for the lookup instead.

Based on CWG2471 we must also substitute the known outer template
arguments when creating deduction guides for the inner class.

Changes from last iteration:

1. In template constructors, arguments are first rewritten to depth - 1
relative to the constructor as compared to depth 0 originally. These
arguments are needed for substitution into constraint expressions.
2. Outer arguments are then applied with the template instantiator to
produce a template argument at depth zero for use in the deduction
guide. This substitution does not evaluate constraints, which preserves
constraint arguments at the correct depth for later evaluation.
3. Tests are added that cover template constructors within nested
deduction guides for all special substitution cases.
4. Computation of the template pattern and outer instantiation arguments
are pulled into the constructor of
`ConvertConstructorToDeductionGuideTransform`.

Added: 
clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/nested-deduction-guides.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ce15169d49bcce..29a06d0f713f588 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -741,6 +741,11 @@ Bug Fixes to C++ Support
   declaration definition. Fixes:
   (`#61763 `_)
 
+- Fix a bug where implicit deduction guides are not correctly generated for 
nested template
+  classes. Fixes:
+  (`#46200 `_)
+  (`#57812 `_)
+
 - Diagnose use of a variable-length array in a coroutine. The design of
   coroutines is such that it is not possible to support VLA use. Fixes:
   (`#65858 `_)

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c188dd34014a4b3..34d7b8c731e9076 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2250,10 +2250,24 @@ class ExtractTypeForDeductionGuide
 struct ConvertConstructorToDeductionGuideTransform {
   ConvertConstructorToDeductionGuideTransform(Sema ,
   ClassTemplateDecl *Template)
-  : SemaRef(S), Template(Template) {}
+  : SemaRef(S), Template(Template) {
+// If the template is nested, then we need to use the original
+// pattern to iterate over the constructors.
+ClassTemplateDecl *Pattern = Template;
+while (Pattern->getInstantiatedFromMemberTemplate()) {
+  if (Pattern->isMemberSpecialization())
+break;
+  Pattern = Pattern->getInstantiatedFromMemberTemplate();
+  NestedPattern = Pattern;
+}
+
+if (NestedPattern)
+  OuterInstantiationArgs = SemaRef.getTemplateInstantiationArgs(Template);
+  }
 
   Sema 
   ClassTemplateDecl *Template;
+  ClassTemplateDecl *NestedPattern = nullptr;
 
   DeclContext *DC = Template->getDeclContext();
   CXXRecordDecl *Primary = Template->getTemplatedDecl();
@@ -2266,6 +2280,10 @@ struct ConvertConstructorToDeductionGuideTransform {
   // depth-0 template parameters.
   unsigned Depth1IndexAdjustment = Template->getTemplateParameters()->size();
 
+  // Instantiation arguments for the outermost depth-1 templates
+  // when the template is nested
+  MultiLevelTemplateArgumentList OuterInstantiationArgs;
+
   /// Transform a constructor declaration into a deduction guide.
   NamedDecl *transformConstructor(FunctionTemplateDecl *FTD,
   CXXConstructorDecl *CD) {
@@ -2284,21 +2302,43 @@ struct ConvertConstructorToDeductionGuideTransform {
 if (FTD) {
   TemplateParameterList *InnerParams = FTD->getTemplateParameters();
   SmallVector AllParams;
+  SmallVector Depth1Args;
 

[clang] Reland "[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes" (PR #73087)

2023-11-25 Thread via cfe-commits

https://github.com/antangelo closed 
https://github.com/llvm/llvm-project/pull/73087
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits


@@ -0,0 +1,110 @@
+// RUN: %check_clang_tidy %s readability-redundant-inline-specifier %t
+
+template  inline T f()
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: function 'f' has inline specifier 
but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: template  T f()
+{
+return T{};
+}
+
+template <> inline double f() = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: template <> double f() = delete;
+
+inline int g(float a)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:1: warning: function 'g' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return static_cast(a - 5.F);
+}
+
+inline int g(double) = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: function 'g' has inline specifier 
but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: int g(double) = delete;
+
+class C
+{
+  public:
+inline C& operator=(const C&) = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'operator=' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+// CHECK-FIXES: C& operator=(const C&) = delete;
+
+constexpr inline C& operator=(int a);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'operator=' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr C& operator=(int a);
+
+inline C() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'C' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: C() {}
+
+constexpr inline C(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'C' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr C(int);
+
+inline int Get42() const { return 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'Get42' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: int Get42() const { return 42; }
+
+static inline constexpr int C_STATIC = 42;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'C_STATIC' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+// CHECK-FIXES: static constexpr int C_STATIC = 42;
+
+static constexpr int C_STATIC_2 = 42;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: variable 'C_STATIC_2' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+};
+
+constexpr inline int Get42() { return 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: function 'Get42' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr int Get42() { return 42; }
+
+
+static constexpr inline int NAMESPACE_STATIC = 42;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:18: warning: variable 'NAMESPACE_STATIC' 
has inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+
+inline static int fn0(int i)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:1: warning: function 'fn0' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return i - 1;
+}
+
+static constexpr inline int fn1(int i)
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: function 'fn1' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: static constexpr int fn1(int i)
+{
+return i - 1;
+}
+
+namespace
+{
+inline int fn2(int i)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: function 'fn2' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return i - 1;
+}
+
+inline constexpr int fn3(int i)
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'fn3' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr int fn3(int i)
+{
+return i - 1;
+}
+}
+
+namespace ns
+{
+inline int fn4(int i)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: function 'fn4' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return i - 1;
+}
+
+inline constexpr int fn5(int i)
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'fn5' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr int fn5(int i)
+{
+return i - 1;
+}
+}
+
+auto fn6 = [](){};
+//CHECK-MESSAGES-NOT: :[[@LINE-1]]:1: warning: function 'operator()' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+

felix642 wrote:

The current implementation does not raise any warnings if the inline 

[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/73069

From 89281ccb5354e3d6349d10e6f9446194d2d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 16 Nov 2023 22:03:15 -0500
Subject: [PATCH 01/10] =?UTF-8?q?[clang-tidy]=C2=A0Added=20check=20to=20de?=
 =?UTF-8?q?tect=20redundant=20inline=20keyword?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This checks find usages of the inline keywork where it is
already implicitly defined by the compiler and suggests it's removal.

Fixes #72397
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../RedundantInlineSpecifierCheck.cpp |  99 
 .../RedundantInlineSpecifierCheck.h   |  36 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../redundant-inline-specifier.rst|  34 ++
 .../redundant-inline-specifier.cpp| 110 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h |   2 +-
 9 files changed, 290 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..811310db8c721a6 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyReadabilityModule
   IdentifierLengthCheck.cpp
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
+  RedundantInlineSpecifierCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..3ce7bfecaecba64 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
+#include "RedundantInlineSpecifierCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantPreprocessorCheck.h"
 #include "RedundantSmartptrGetCheck.h"
@@ -93,6 +94,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-identifier-naming");
 CheckFactories.registerCheck(
 "readability-implicit-bool-conversion");
+CheckFactories.registerCheck(
+"readability-redundant-inline-specifier");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
new file mode 100644
index 000..e73b570df759153
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if 

[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/73069

From 89281ccb5354e3d6349d10e6f9446194d2d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 16 Nov 2023 22:03:15 -0500
Subject: [PATCH 1/9] =?UTF-8?q?[clang-tidy]=C2=A0Added=20check=20to=20dete?=
 =?UTF-8?q?ct=20redundant=20inline=20keyword?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This checks find usages of the inline keywork where it is
already implicitly defined by the compiler and suggests it's removal.

Fixes #72397
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../RedundantInlineSpecifierCheck.cpp |  99 
 .../RedundantInlineSpecifierCheck.h   |  36 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../redundant-inline-specifier.rst|  34 ++
 .../redundant-inline-specifier.cpp| 110 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h |   2 +-
 9 files changed, 290 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..811310db8c721a6 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyReadabilityModule
   IdentifierLengthCheck.cpp
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
+  RedundantInlineSpecifierCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..3ce7bfecaecba64 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
+#include "RedundantInlineSpecifierCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantPreprocessorCheck.h"
 #include "RedundantSmartptrGetCheck.h"
@@ -93,6 +94,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-identifier-naming");
 CheckFactories.registerCheck(
 "readability-implicit-bool-conversion");
+CheckFactories.registerCheck(
+"readability-redundant-inline-specifier");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
new file mode 100644
index 000..e73b570df759153
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if 

[clang] fix: C++ empty record with align lead to va_list out of sync (PR #72197)

2023-11-25 Thread John McCall via cfe-commits

https://github.com/rjmccall edited 
https://github.com/llvm/llvm-project/pull/72197
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/73069

From 89281ccb5354e3d6349d10e6f9446194d2d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 16 Nov 2023 22:03:15 -0500
Subject: [PATCH 1/8] =?UTF-8?q?[clang-tidy]=C2=A0Added=20check=20to=20dete?=
 =?UTF-8?q?ct=20redundant=20inline=20keyword?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This checks find usages of the inline keywork where it is
already implicitly defined by the compiler and suggests it's removal.

Fixes #72397
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../RedundantInlineSpecifierCheck.cpp |  99 
 .../RedundantInlineSpecifierCheck.h   |  36 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../redundant-inline-specifier.rst|  34 ++
 .../redundant-inline-specifier.cpp| 110 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h |   2 +-
 9 files changed, 290 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..811310db8c721a6 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyReadabilityModule
   IdentifierLengthCheck.cpp
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
+  RedundantInlineSpecifierCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..3ce7bfecaecba64 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
+#include "RedundantInlineSpecifierCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantPreprocessorCheck.h"
 #include "RedundantSmartptrGetCheck.h"
@@ -93,6 +94,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-identifier-naming");
 CheckFactories.registerCheck(
 "readability-implicit-bool-conversion");
+CheckFactories.registerCheck(
+"readability-redundant-inline-specifier");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
new file mode 100644
index 000..e73b570df759153
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if 

[clang] fix: C++ empty record with align lead to va_list out of sync (PR #72197)

2023-11-25 Thread John McCall via cfe-commits


@@ -307,7 +307,12 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 // 0.
 if (IsEmpty && Size == 0)
   return ABIArgInfo::getIgnore();
-return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));
+// An empty struct can have size greater than one byte if alignment is
+// involved.
+// When size <= 64, we still hold it by i8 in IR and lowering to registers.
+// When Size > 64, just fall through to avoid va_list out of sync.

rjmccall wrote:

It looks like Tim is just implementing the standard rule from the PCS here and 
just didn't think about the fact that he could let the handling fall through to 
the main path.

`va_arg` would not require empty structs to occupy space for parameter passing; 
at worst, it would require us to recognize empty structs in the `va_arg` logic. 
 Even if it were unimplementable, though, that'd be a psABI problem, not a 
compiler one.

https://github.com/llvm/llvm-project/pull/72197
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits


@@ -0,0 +1,25 @@
+.. title:: clang-tidy - readability-redundant-inline-specifier
+
+readability-redundant-inline-specifier
+==
+
+Checks for instances of the ``inline`` keyword in code where it is redundant

felix642 wrote:

Right, I was looking at the wrong file hence why I was confused.

https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bc6b632 - [CGOpenMPRuntimeGPU] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-25 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-25T11:28:18-06:00
New Revision: bc6b632723f8a025c7daa78c82f7d2ad1962a4e9

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

LOG: [CGOpenMPRuntimeGPU] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 9b8fbbdf8046787..7ddc67e8a04ab64 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1837,12 +1837,7 @@ static llvm::Value 
*emitInterWarpCopyFunction(CodeGenModule ,
   {llvm::Constant::getNullValue(CGM.Int64Ty), WarpID});
   // Casting to actual data type.
   // MediumPtr = (CopyType*)MediumPtrAddr;
-  Address MediumPtr(
-  Bld.CreateBitCast(
-  MediumPtrVal,
-  CopyType->getPointerTo(
-  MediumPtrVal->getType()->getPointerAddressSpace())),
-  CopyType, Align);
+  Address MediumPtr(MediumPtrVal, CopyType, Align);
 
   // elem = *elemptr
   //*MediumPtr = elem
@@ -1889,12 +1884,7 @@ static llvm::Value 
*emitInterWarpCopyFunction(CodeGenModule ,
   TransferMedium->getValueType(), TransferMedium,
   {llvm::Constant::getNullValue(CGM.Int64Ty), ThreadID});
   // SrcMediumVal = *SrcMediumPtr;
-  Address SrcMediumPtr(
-  Bld.CreateBitCast(
-  SrcMediumPtrVal,
-  CopyType->getPointerTo(
-  SrcMediumPtrVal->getType()->getPointerAddressSpace())),
-  CopyType, Align);
+  Address SrcMediumPtr(SrcMediumPtrVal, CopyType, Align);
 
   // TargetElemPtr = (CopyType*)(SrcDataAddr[i]) + I
   Address TargetElemPtrPtr = Bld.CreateConstArrayGEP(LocalReduceList, Idx);



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


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/73069

From 89281ccb5354e3d6349d10e6f9446194d2d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 16 Nov 2023 22:03:15 -0500
Subject: [PATCH 1/7] =?UTF-8?q?[clang-tidy]=C2=A0Added=20check=20to=20dete?=
 =?UTF-8?q?ct=20redundant=20inline=20keyword?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This checks find usages of the inline keywork where it is
already implicitly defined by the compiler and suggests it's removal.

Fixes #72397
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../RedundantInlineSpecifierCheck.cpp |  99 
 .../RedundantInlineSpecifierCheck.h   |  36 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../redundant-inline-specifier.rst|  34 ++
 .../redundant-inline-specifier.cpp| 110 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h |   2 +-
 9 files changed, 290 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..811310db8c721a6 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyReadabilityModule
   IdentifierLengthCheck.cpp
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
+  RedundantInlineSpecifierCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..3ce7bfecaecba64 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
+#include "RedundantInlineSpecifierCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantPreprocessorCheck.h"
 #include "RedundantSmartptrGetCheck.h"
@@ -93,6 +94,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-identifier-naming");
 CheckFactories.registerCheck(
 "readability-implicit-bool-conversion");
+CheckFactories.registerCheck(
+"readability-redundant-inline-specifier");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
new file mode 100644
index 000..e73b570df759153
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if 

[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits


@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),

felix642 wrote:

Same here, it should now match on functions in anonymous namespace.

https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits


@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),
+   anyOf(isConstexpr(), isDeleted(),
+ allOf(isDefinition(), hasAncestor(recordDecl()
+  .bind("fun_decl"),
+  this);
+
+  Finder->addMatcher(
+  varDecl(isInlineSpecified(),
+  anyOf(allOf(isConstexpr(), unless(isStaticStorageClass())),

felix642 wrote:

I've adjusted the matcher to match on variables in anonymous namespace.

https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/73069

From 89281ccb5354e3d6349d10e6f9446194d2d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 16 Nov 2023 22:03:15 -0500
Subject: [PATCH 1/6] =?UTF-8?q?[clang-tidy]=C2=A0Added=20check=20to=20dete?=
 =?UTF-8?q?ct=20redundant=20inline=20keyword?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This checks find usages of the inline keywork where it is
already implicitly defined by the compiler and suggests it's removal.

Fixes #72397
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../RedundantInlineSpecifierCheck.cpp |  99 
 .../RedundantInlineSpecifierCheck.h   |  36 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../redundant-inline-specifier.rst|  34 ++
 .../redundant-inline-specifier.cpp| 110 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h |   2 +-
 9 files changed, 290 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..811310db8c721a6 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyReadabilityModule
   IdentifierLengthCheck.cpp
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
+  RedundantInlineSpecifierCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..3ce7bfecaecba64 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
+#include "RedundantInlineSpecifierCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantPreprocessorCheck.h"
 #include "RedundantSmartptrGetCheck.h"
@@ -93,6 +94,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-identifier-naming");
 CheckFactories.registerCheck(
 "readability-implicit-bool-conversion");
+CheckFactories.registerCheck(
+"readability-redundant-inline-specifier");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
new file mode 100644
index 000..e73b570df759153
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if 

[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),
+   anyOf(isConstexpr(), isDeleted(),
+ allOf(isDefinition(), hasAncestor(recordDecl()
+  .bind("fun_decl"),
+  this);
+
+  Finder->addMatcher(
+  varDecl(isInlineSpecified(),
+  anyOf(allOf(isConstexpr(), unless(isStaticStorageClass())),
+hasAncestor(recordDecl(
+  .bind("var_decl"),
+  this);
+
+  Finder->addMatcher(
+  functionTemplateDecl(has(functionDecl(isInlineSpecified(

PiotrZSL wrote:

Please add both those as an tests, and we can see.

https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits


@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),
+   anyOf(isConstexpr(), isDeleted(),

felix642 wrote:

From what I can see default methods are implicitly inlined : 
https://cppinsights.io/s/fb9b0f8e. I've adjusted my matcher to take them into 
consideration. Let me know if it's ok with you.

https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits


@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),
+   anyOf(isConstexpr(), isDeleted(),
+ allOf(isDefinition(), hasAncestor(recordDecl()
+  .bind("fun_decl"),
+  this);
+
+  Finder->addMatcher(
+  varDecl(isInlineSpecified(),
+  anyOf(allOf(isConstexpr(), unless(isStaticStorageClass())),
+hasAncestor(recordDecl(
+  .bind("var_decl"),
+  this);
+
+  Finder->addMatcher(
+  functionTemplateDecl(has(functionDecl(isInlineSpecified(

felix642 wrote:

Well, I think that it's fair to emit a warning if either a forward declaration 
of a function definition has a redundant inline specifier. In both case we want 
to suggest to remove it don't we ? 

https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread via cfe-commits
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin
Message-ID:
In-Reply-To: 

Cj09PT09PT09PT09PT09PT0KQEAgLTAsMCArMSwyNSBAQAorLi4gdGl0bGU6OiBjbGFuZy10aWR5
IC0gcmVhZGFiaWxpdHktcmVkdW5kYW50LWlubGluZS1zcGVjaWZpZXIKKworcmVhZGFiaWxpdHkt
cmVkdW5kYW50LWlubGluZS1zcGVjaWZpZXIKKz09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09CisKK0NoZWNrcyBmb3IgaW5zdGFuY2VzIG9mIHRoZSBgYGlubGluZWBgIGtleXdv
cmQgaW4gY29kZSB3aGVyZSBpdCBpcyByZWR1bmRhbnQKLS0tLS0tLS0tLS0tLS0tLQpFdWdlbmVa
ZWxlbmtvIHdyb3RlOgoKSnVzdCBtYWtlIGZpcnN0IHN0YXRlbWVudCBpbiBkb2N1bWVudGF0aW9u
IGFuZCBzdGF0ZW1lbnQgaW4gUmVsZWFzZSBOb3RlcyBzYW1lLgoKaHR0cHM6Ly9naXRodWIuY29t
L2xsdm0vbGx2bS1wcm9qZWN0L3B1bGwvNzMwNjkK
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-25 Thread Félix-Antoine Constantin via cfe-commits


@@ -0,0 +1,25 @@
+.. title:: clang-tidy - readability-redundant-inline-specifier
+
+readability-redundant-inline-specifier
+==
+
+Checks for instances of the ``inline`` keyword in code where it is redundant

felix642 wrote:

I apologies, but I'm not quite sure to understand what you're asking me to do 
here? Would you be able to give me more info? 

https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Remove support for FreeBSD 11.x (PR #73392)

2023-11-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Brad Smith (brad0)


Changes

Now that FreeBSD 14.0 has been released make the 12.x branch the oldest
supported releases. -fuse-init-array defaults to on. DWARF 4 is now the
default.

---
Full diff: https://github.com/llvm/llvm-project/pull/73392.diff


5 Files Affected:

- (modified) clang/lib/Driver/ToolChains/FreeBSD.cpp (-17) 
- (modified) clang/lib/Driver/ToolChains/FreeBSD.h (+1-5) 
- (modified) clang/test/Driver/clang-g-opts.c (+4-4) 
- (modified) clang/test/Driver/constructors.c (-4) 
- (modified) clang/test/Driver/debug-options.c (+1-12) 


``diff
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index d08764aeef77539..3be0bf3789e1c40 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -400,13 +400,6 @@ FreeBSD::FreeBSD(const Driver , const llvm::Triple 
,
 getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
 }
 
-unsigned FreeBSD::GetDefaultDwarfVersion() const {
-  unsigned Major = getTriple().getOSMajorVersion();
-  if (Major >= 12 || Major == 0)
-return 4;
-  return 2;
-}
-
 void FreeBSD::AddClangSystemIncludeArgs(
 const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const {
@@ -510,13 +503,3 @@ SanitizerMask FreeBSD::getSupportedSanitizers() const {
   }
   return Res;
 }
-
-void FreeBSD::addClangTargetOptions(const ArgList ,
-ArgStringList ,
-Action::OffloadKind) const {
-  unsigned Major = getTriple().getOSMajorVersion();
-  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
-  options::OPT_fno_use_init_array,
-  (Major >= 12 || Major == 0)))
-CC1Args.push_back("-fno-use-init-array");
-}
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.h 
b/clang/lib/Driver/ToolChains/FreeBSD.h
index 959cbf78ddc79d1..7ab63905ed4f991 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.h
+++ b/clang/lib/Driver/ToolChains/FreeBSD.h
@@ -82,14 +82,10 @@ class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
   getDefaultUnwindTableLevel(const llvm::opt::ArgList ) const override;
   bool isPIEDefault(const llvm::opt::ArgList ) const override;
   SanitizerMask getSupportedSanitizers() const override;
-  unsigned GetDefaultDwarfVersion() const override;
+  unsigned GetDefaultDwarfVersion() const override { return 4; }
   // Until dtrace (via CTF) and LLDB can deal with distributed debug info,
   // FreeBSD defaults to standalone/full debug info.
   bool GetDefaultStandaloneDebug() const override { return true; }
-  void
-  addClangTargetOptions(const llvm::opt::ArgList ,
-llvm::opt::ArgStringList ,
-Action::OffloadKind DeviceOffloadKind) const override;
 
 protected:
   Tool *buildAssembler() const override;
diff --git a/clang/test/Driver/clang-g-opts.c b/clang/test/Driver/clang-g-opts.c
index b1cdf411925aea1..b73602a155b0094 100644
--- a/clang/test/Driver/clang-g-opts.c
+++ b/clang/test/Driver/clang-g-opts.c
@@ -7,8 +7,8 @@
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g -target i686-pc-openbsd 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
-// RUN: %clang -### -S %s -g -target x86_64-pc-freebsd10.0 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g -target x86_64-pc-freebsd 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF4 %s
 // RUN: %clang -### -S %s -g --target=x86_64-unknown-haiku 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF4 %s
 
@@ -27,8 +27,8 @@
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-STANDALONE %s
 // RUN: %clang -### -S %s -g0 -g -target i686-pc-openbsd 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
-// RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd10.0 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF4 %s
 // RUN: %clang -### -S %s -g0 -g --target=x86_64-unknown-haiku 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF4 %s
 // RUN: %clang -### -S %s -g0 -g --target=i386-pc-solaris 2>&1 \
diff --git a/clang/test/Driver/constructors.c b/clang/test/Driver/constructors.c
index 45d6dd6cb171e46..1cb3aec840c2d91 100644
--- a/clang/test/Driver/constructors.c
+++ b/clang/test/Driver/constructors.c
@@ -75,10 +75,6 @@
 // RUN: --target=arm64-none-none-eabi \
 // RUN:   | FileCheck --check-prefix=CHECK-INIT-ARRAY %s
 
-// RUN: %clang -### %s -fsyntax-only 2>&1   \
-// RUN: --target=i386-unknown-freebsd11 \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-INIT-ARRAY %s
-//
 // RUN: %clang -### %s 

[clang] [Driver] Remove support for FreeBSD 11.x (PR #73392)

2023-11-25 Thread Brad Smith via cfe-commits

https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/73392

Now that FreeBSD 14.0 has been released make the 12.x branch the oldest
supported releases. -fuse-init-array defaults to on. DWARF 4 is now the
default.

>From 95e05a6a5d78c7914e3dd2e77e6a44b95dc2eac2 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sat, 25 Nov 2023 09:46:43 -0500
Subject: [PATCH] [Driver] Remove support for FreeBSD 11.x

Now that FreeBSD 14.0 has been released make the 12.x branch the oldest
supported releases. -fuse-init-array defaults to on. DWARF 4 is now the
default.
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 17 -
 clang/lib/Driver/ToolChains/FreeBSD.h   |  6 +-
 clang/test/Driver/clang-g-opts.c|  8 
 clang/test/Driver/constructors.c|  4 
 clang/test/Driver/debug-options.c   | 13 +
 5 files changed, 6 insertions(+), 42 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index d08764aeef77539..3be0bf3789e1c40 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -400,13 +400,6 @@ FreeBSD::FreeBSD(const Driver , const llvm::Triple 
,
 getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
 }
 
-unsigned FreeBSD::GetDefaultDwarfVersion() const {
-  unsigned Major = getTriple().getOSMajorVersion();
-  if (Major >= 12 || Major == 0)
-return 4;
-  return 2;
-}
-
 void FreeBSD::AddClangSystemIncludeArgs(
 const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const {
@@ -510,13 +503,3 @@ SanitizerMask FreeBSD::getSupportedSanitizers() const {
   }
   return Res;
 }
-
-void FreeBSD::addClangTargetOptions(const ArgList ,
-ArgStringList ,
-Action::OffloadKind) const {
-  unsigned Major = getTriple().getOSMajorVersion();
-  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
-  options::OPT_fno_use_init_array,
-  (Major >= 12 || Major == 0)))
-CC1Args.push_back("-fno-use-init-array");
-}
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.h 
b/clang/lib/Driver/ToolChains/FreeBSD.h
index 959cbf78ddc79d1..7ab63905ed4f991 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.h
+++ b/clang/lib/Driver/ToolChains/FreeBSD.h
@@ -82,14 +82,10 @@ class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
   getDefaultUnwindTableLevel(const llvm::opt::ArgList ) const override;
   bool isPIEDefault(const llvm::opt::ArgList ) const override;
   SanitizerMask getSupportedSanitizers() const override;
-  unsigned GetDefaultDwarfVersion() const override;
+  unsigned GetDefaultDwarfVersion() const override { return 4; }
   // Until dtrace (via CTF) and LLDB can deal with distributed debug info,
   // FreeBSD defaults to standalone/full debug info.
   bool GetDefaultStandaloneDebug() const override { return true; }
-  void
-  addClangTargetOptions(const llvm::opt::ArgList ,
-llvm::opt::ArgStringList ,
-Action::OffloadKind DeviceOffloadKind) const override;
 
 protected:
   Tool *buildAssembler() const override;
diff --git a/clang/test/Driver/clang-g-opts.c b/clang/test/Driver/clang-g-opts.c
index b1cdf411925aea1..b73602a155b0094 100644
--- a/clang/test/Driver/clang-g-opts.c
+++ b/clang/test/Driver/clang-g-opts.c
@@ -7,8 +7,8 @@
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g -target i686-pc-openbsd 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
-// RUN: %clang -### -S %s -g -target x86_64-pc-freebsd10.0 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g -target x86_64-pc-freebsd 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF4 %s
 // RUN: %clang -### -S %s -g --target=x86_64-unknown-haiku 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF4 %s
 
@@ -27,8 +27,8 @@
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-STANDALONE %s
 // RUN: %clang -### -S %s -g0 -g -target i686-pc-openbsd 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
-// RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd10.0 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF4 %s
 // RUN: %clang -### -S %s -g0 -g --target=x86_64-unknown-haiku 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF4 %s
 // RUN: %clang -### -S %s -g0 -g --target=i386-pc-solaris 2>&1 \
diff --git a/clang/test/Driver/constructors.c b/clang/test/Driver/constructors.c
index 45d6dd6cb171e46..1cb3aec840c2d91 100644
--- a/clang/test/Driver/constructors.c
+++ b/clang/test/Driver/constructors.c
@@ -75,10 +75,6 @@
 // RUN: 

[clang] [flang] [llvm] [compiler-rt] [llvm][WebAssembly] mark BR_TABLE as isIndirectBranch (PR #72755)

2023-11-25 Thread Xu Jun via cfe-commits

https://github.com/xujuntwt95329 closed 
https://github.com/llvm/llvm-project/pull/72755
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2023-11-25 Thread via cfe-commits


@@ -3,8 +3,8 @@ extern groupshared float f;
 extern float groupshared f; // Ok, redeclaration?
 
 
-// NOTE:lambda is not enabled except for hlsl202x.
-// expected-error@+2 {{expected expression}}
+// expected-warning@+3 {{lambdas are a C++11 extension}}
+// expected-error@+2   {{expected body of lambda expression}}

philnik777 wrote:

Should this work? I don't know much about HLSL, so I have no idea whether this 
is expected behaviour or a bug in my patch.

https://github.com/llvm/llvm-project/pull/73376
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2023-11-25 Thread via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/73376

>From a53b7e23c8e37227cda1cea8d87800ca7ac432d1 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 25 Nov 2023 04:00:57 +0100
Subject: [PATCH] [clang] Accept lambdas in C++03 as an extensions

This is a fairly simple extension, but makes the life for people who
have to support C++03 a lot easier. As a nice bonus, this also improves
diagnostics, since lambdas are now properly recognized when parsing
C++03 code.
---
 .../clang/Basic/DiagnosticParseKinds.td   |   1 +
 clang/lib/Parse/ParseExpr.cpp |   2 +-
 clang/lib/Parse/ParseExprCXX.cpp  |   9 +-
 clang/lib/Parse/ParseInit.cpp |   2 +-
 .../OpenMP/declare_reduction_messages.cpp |  14 +--
 clang/test/OpenMP/openmp_check.cpp|   2 +-
 clang/test/Parser/cxx03-lambda-extension.cpp  |   5 +
 .../test/Parser/cxx0x-lambda-expressions.cpp  | 116 +++---
 .../Parser/objcxx-lambda-expressions-neg.mm   |   5 -
 clang/test/ParserHLSL/group_shared.hlsl   |   4 +-
 clang/test/SemaCXX/new-delete.cpp |   7 +-
 11 files changed, 68 insertions(+), 99 deletions(-)
 create mode 100644 clang/test/Parser/cxx03-lambda-extension.cpp

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index b66ecf0724b1c77..89bacb0a302d10a 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1017,6 +1017,7 @@ def err_expected_lambda_body : Error<"expected body of 
lambda expression">;
 def warn_cxx98_compat_lambda : Warning<
   "lambda expressions are incompatible with C++98">,
   InGroup, DefaultIgnore;
+def ext_lambda : ExtWarn<"lambdas are a C++11 extension">, InGroup;
 def err_lambda_decl_specifier_repeated : Error<
   "%select{'mutable'|'static'|'constexpr'|'consteval'}0 cannot "
   "appear multiple times in a lambda declarator">;
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 897810557976151..c453d77329111f6 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1799,7 +1799,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 }
 goto ExpectedExpression;
   case tok::l_square:
-if (getLangOpts().CPlusPlus11) {
+if (getLangOpts().CPlusPlus) {
   if (getLangOpts().ObjC) {
 // C++11 lambda expressions and Objective-C message sends both start 
with a
 // square bracket.  There are three possibilities here:
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 79db094e098f8e6..2b6044f29fdd8e5 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -751,9 +751,8 @@ ExprResult Parser::ParseLambdaExpression() {
 ///
 /// If we are not looking at a lambda expression, returns ExprError().
 ExprResult Parser::TryParseLambdaExpression() {
-  assert(getLangOpts().CPlusPlus11
- && Tok.is(tok::l_square)
- && "Not at the start of a possible lambda expression.");
+  assert(getLangOpts().CPlusPlus && Tok.is(tok::l_square) &&
+ "Not at the start of a possible lambda expression.");
 
   const Token Next = NextToken();
   if (Next.is(tok::eof)) // Nothing else to lookup here...
@@ -1271,7 +1270,9 @@ static void DiagnoseStaticSpecifierRestrictions(Parser ,
 ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
  LambdaIntroducer ) {
   SourceLocation LambdaBeginLoc = Intro.Range.getBegin();
-  Diag(LambdaBeginLoc, diag::warn_cxx98_compat_lambda);
+  Diag(LambdaBeginLoc, getLangOpts().CPlusPlus11
+   ? diag::warn_cxx98_compat_lambda
+   : diag::ext_lambda);
 
   PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
 "lambda expression parsing");
diff --git a/clang/lib/Parse/ParseInit.cpp b/clang/lib/Parse/ParseInit.cpp
index 637f21176792b6b..423497bfcb6621a 100644
--- a/clang/lib/Parse/ParseInit.cpp
+++ b/clang/lib/Parse/ParseInit.cpp
@@ -35,7 +35,7 @@ bool Parser::MayBeDesignationStart() {
 return true;
 
   case tok::l_square: {  // designator: array-designator
-if (!PP.getLangOpts().CPlusPlus11)
+if (!PP.getLangOpts().CPlusPlus)
   return true;
 
 // C++11 lambda expressions and C99 designators can be ambiguous all the
diff --git a/clang/test/OpenMP/declare_reduction_messages.cpp 
b/clang/test/OpenMP/declare_reduction_messages.cpp
index 38a5d766eeadf7d..752cc4fb05a1239 100644
--- a/clang/test/OpenMP/declare_reduction_messages.cpp
+++ b/clang/test/OpenMP/declare_reduction_messages.cpp
@@ -58,16 +58,10 @@ class Class2 : public Class1 {
 #pragma omp declare reduction(fun1 : long : omp_out += omp_in) initializer 
 // expected-error {{expected '(' after 'initializer'}}
 #pragma omp declare reduction(fun2 : long : omp_out += omp_in) 

[flang] [llvm] [compiler-rt] [clang] [llvm][WebAssembly] mark BR_TABLE as isIndirectBranch (PR #72755)

2023-11-25 Thread Xu Jun via cfe-commits

https://github.com/xujuntwt95329 updated 
https://github.com/llvm/llvm-project/pull/72755

>From 1f7588ce6a473204e102c03cf94b3ebcafcbca78 Mon Sep 17 00:00:00 2001
From: Xu Jun <693788...@qq.com>
Date: Sat, 18 Nov 2023 18:29:18 +
Subject: [PATCH] [llvm][WebAssembly] mark BR_TABLE as isIndirectBranch

Signed-off-by: Xu Jun <693788...@qq.com>
---
 llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td 
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
index be6547007aaf7a7..a94e7f9f829a347 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
@@ -45,7 +45,7 @@ def brlist : Operand {
 // Duplicating a BR_TABLE is almost never a good idea. In particular, it can
 // lead to some nasty irreducibility due to tail merging when the br_table is 
in
 // a loop.
-let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1, isNotDuplicable = 1 in {
+let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1, isNotDuplicable = 1, 
isIndirectBranch = 1 in {
 
 defm BR_TABLE_I32 : I<(outs), (ins I32:$index, variable_ops),
   (outs), (ins brlist:$brl),
@@ -60,7 +60,7 @@ defm BR_TABLE_I64 : I<(outs), (ins I64:$index, variable_ops),
   [(WebAssemblybr_table I64:$index)],
   "br_table \t$index", "br_table \t$brl",
   0x0e>;
-} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1, isNotDuplicable = 1
+} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1, isNotDuplicable = 1, 
isIndirectBranch = 1
 
 // This is technically a control-flow instruction, since all it affects is the
 // IP.

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


[clang] Do not report -Wasm-operand-widths for Aarch64 ilp32 operands (PR #73385)

2023-11-25 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-aarch64

Author: None (joyhou-hw)


Changes

Since width of pointer type is 32 bits in ILP32 while memory instruction shall 
'x' registers. msr/mrs likewise.

Now Wasm-operand-widths in ILP32 will warning below asm code with a WRONG 
massage. 
 
```
void atomicAdd32(int *ptr, int lIncr)
{
  int  result = 0;
  unsigned int tmp = 0;

  __asm__ volatile(
 "1: ldxr   %w0, [%2]\n\t"
 "   add%w0, %w0, %w3\n\t"
 "   stxr   %w1, %w0, [%2]   \n\t"
 "   cbnz   %w1, 1b  \n\t"
 : "=r"(result), "=r"(tmp)
 : "r"(ptr), "Ir"(lIncr)
 :"memory","cc"
  );
}
```
The [%2]  shall be 'x' rregister for ldxr inst., not the %w2.
```
warning: value size does not match register size specified by the constraint 
and modifier [-Wasm-operand-widths]
: "r"(ptr), "Ir"(lIncr)
  ^
: note: use constraint modifier "w"
"1: ldxr   %w0, [%2]\n\t"
 ^~
 %w2
```


---
Full diff: https://github.com/llvm/llvm-project/pull/73385.diff


1 Files Affected:

- (modified) clang/lib/Basic/Targets/AArch64.cpp (+4) 


``diff
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c31f2e0bee54393..180c5f17d7835a4 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1362,6 +1362,10 @@ bool AArch64TargetInfo::validateAsmConstraint(
 bool AArch64TargetInfo::validateConstraintModifier(
 StringRef Constraint, char Modifier, unsigned Size,
 std::string ) const {
+  // Ignore in ILP32 since width of pointer type is 32 bits
+  // while memory instruction shall 'x' registers.
+  if (getTriple().getEnvironment() == llvm::Triple::GNUILP32)
+return true;
   // Strip off constraint modifiers.
   while (Constraint[0] == '=' || Constraint[0] == '+' || Constraint[0] == '&')
 Constraint = Constraint.substr(1);

``




https://github.com/llvm/llvm-project/pull/73385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Do not report -Wasm-operand-widths for Aarch64 ilp32 operands (PR #73385)

2023-11-25 Thread via cfe-commits

https://github.com/joyhou-hw created 
https://github.com/llvm/llvm-project/pull/73385

Since width of pointer type is 32 bits in ILP32 while memory instruction shall 
'x' registers. msr/mrs likewise.

Now Wasm-operand-widths in ILP32 will warning below asm code with a WRONG 
massage. 
 
```
void atomicAdd32(int *ptr, int lIncr)
{
  int  result = 0;
  unsigned int tmp = 0;

  __asm__ volatile(
 "1: ldxr   %w0, [%2]\n\t"
 "   add%w0, %w0, %w3\n\t"
 "   stxr   %w1, %w0, [%2]   \n\t"
 "   cbnz   %w1, 1b  \n\t"
 : "="(result), "="(tmp)
 : "r"(ptr), "Ir"(lIncr)
 :"memory","cc"
  );
}
```
The [%2]  shall be 'x' rregister for ldxr inst., not the %w2.
```
warning: value size does not match register size specified by the constraint 
and modifier [-Wasm-operand-widths]
: "r"(ptr), "Ir"(lIncr)
  ^
: note: use constraint modifier "w"
"1: ldxr   %w0, [%2]\n\t"
 ^~
 %w2
```


>From 1791f378d887179d8fc0bfa5a8e2531f078bda37 Mon Sep 17 00:00:00 2001
From: houzhenyu 
Date: Sat, 25 Nov 2023 19:38:21 +0800
Subject: [PATCH] Do not report -Wasm-operand-widths for Aarch64 ilp32 operands

Since width of pointer type is 32 bits in ILP32 while memory instruction shall 
'x' registers.
msr/mrs likewise.
---
 clang/lib/Basic/Targets/AArch64.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c31f2e0bee54393..180c5f17d7835a4 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1362,6 +1362,10 @@ bool AArch64TargetInfo::validateAsmConstraint(
 bool AArch64TargetInfo::validateConstraintModifier(
 StringRef Constraint, char Modifier, unsigned Size,
 std::string ) const {
+  // Ignore in ILP32 since width of pointer type is 32 bits
+  // while memory instruction shall 'x' registers.
+  if (getTriple().getEnvironment() == llvm::Triple::GNUILP32)
+return true;
   // Strip off constraint modifiers.
   while (Constraint[0] == '=' || Constraint[0] == '+' || Constraint[0] == '&')
 Constraint = Constraint.substr(1);

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


[clang] [clang-format] Fix a bug in formating `#define A x:` (PR #73220)

2023-11-25 Thread via cfe-commits

https://github.com/mydeveloperday approved this pull request.


https://github.com/llvm/llvm-project/pull/73220
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-25 Thread Jonas Paulsson via cfe-commits

JonPsson1 wrote:

Sorry for the confusion of the files: the tests for __atomic_is_lock_free() and 
friends are now in back a single file atomic_is_lock_free-i128.c. The C library 
call is also included as it also changes behavior with this patch.
Current test output in CHECKs, with previous problems remaining.
I see that these can be called for `long double / Atomic` as well, and clang is 
now changing output with the patch. GCC however seems to return 'true' for any 
such calls, regardless of alignment / type, so I suspect this is not really 
expected to work. IIUC, the builtins are only intended for use with integral 
types. The library call may not be limited to ints. Waiting with these until 
later.

https://github.com/llvm/llvm-project/pull/73134
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-25 Thread Jonas Paulsson via cfe-commits

https://github.com/JonPsson1 updated 
https://github.com/llvm/llvm-project/pull/73134

>From bf9b6b735c131833ec9457f23b72322fd50ef821 Mon Sep 17 00:00:00 2001
From: Jonas Paulsson 
Date: Fri, 3 Feb 2023 14:32:58 +0100
Subject: [PATCH 1/3] [SystemZ] Improve support for 16 byte atomic int/fp types
 and operations.

- Clang FE now has MaxAtomicPromoteWidth and MaxAtomicInlineWidth with a value
  of 128. It now produces IR instead of calls to __atomic instrinsics for 16
  bytes as well. FP loads are first loaded as i128 and then casted to fp128.
- Atomic __int128 (and long double) variables are aligned to 16 bytes
  (like gcc 14).
- AtomicExpand pass now expands also 16 byte operations.

- tests for __atomic builtins for all integer widths, with test for i128 in
  both align=8 and align=16 cases.
- Resulting behavior of __atomic_is_lock_free / __atomic_always_lock_free /
  __c11_atomic_is_lock_free is tested in gnu-atomic_is_lock_free.c
- shouldExpandAtomicRMWInIR() was already returning true for any FP type. Now
  that the backend is acepting 16 byte atomics, 16 byte FP atomicrmw:s now also
  get expanded by AtomicExpand. The default (and used)
  shouldCastAtomicRMWIInIR() says that if the type is FP, it is casted to
  integer (see atomicrmw-xchg-07.ll).
- TODO: AtomicExpand pass handles with this patch expansion of i128 atomicrmw:s.
  As a next step smaller integer types should also be possible to handle this
  way instead of in backend.

Original patch rebased.
Remove the regalloc handling for CDSG loops.
Tests improved.
---
 clang/lib/Basic/Targets/SystemZ.h |   2 +-
 clang/test/CodeGen/SystemZ/atomic-alignment.c |  35 ++
 .../SystemZ/gnu-atomic-builtins-i128-16Al.c   | 257 +
 .../SystemZ/gnu-atomic-builtins-i128-8Al.c| 301 +++
 .../CodeGen/SystemZ/gnu-atomic-builtins-i16.c | 219 
 .../CodeGen/SystemZ/gnu-atomic-builtins-i32.c | 219 
 .../CodeGen/SystemZ/gnu-atomic-builtins-i64.c | 219 
 .../CodeGen/SystemZ/gnu-atomic-builtins-i8.c  | 219 
 .../gnu-atomic_is_lock_free-i128-16Al.c   |  54 ++
 .../gnu-atomic_is_lock_free-i128-8Al.c|  28 +
 .../Target/SystemZ/SystemZISelLowering.cpp|   6 +-
 .../CodeGen/SystemZ/atomicrmw-ops-i128.ll | 496 --
 .../test/CodeGen/SystemZ/atomicrmw-xchg-07.ll |  37 +-
 13 files changed, 2030 insertions(+), 62 deletions(-)
 create mode 100644 clang/test/CodeGen/SystemZ/atomic-alignment.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i128-16Al.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i128-8Al.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i16.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i32.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i64.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i8.c
 create mode 100644 
clang/test/CodeGen/SystemZ/gnu-atomic_is_lock_free-i128-16Al.c
 create mode 100644 
clang/test/CodeGen/SystemZ/gnu-atomic_is_lock_free-i128-8Al.c

diff --git a/clang/lib/Basic/Targets/SystemZ.h 
b/clang/lib/Basic/Targets/SystemZ.h
index 9ba255745cf2cc5..e4ec338880f2109 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -60,7 +60,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public 
TargetInfo {
   resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
   "-v128:64-a:8:16-n32:64");
 }
-MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
+MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128;
 HasStrictFP = true;
   }
 
diff --git a/clang/test/CodeGen/SystemZ/atomic-alignment.c 
b/clang/test/CodeGen/SystemZ/atomic-alignment.c
new file mode 100644
index 000..da478842ca31b2b
--- /dev/null
+++ b/clang/test/CodeGen/SystemZ/atomic-alignment.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O3 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test alignment of 128 bit Atomic int/fp types, as well as loading
+// from memory with a simple addition. The fp128 is loaded as i128 and
+// then casted.
+
+// CHECK: @Atomic_int128 = {{.*}} i128 0, align 16
+// CHECK: @Atomic_fp128 = {{.*}} fp128 0xL, 
align 16
+
+// CHECK-LABEL:  @f1
+// CHECK:  %atomic-load = load atomic i128, ptr @Atomic_int128 seq_cst, 
align 16
+// CHECK-NEXT: %add = add nsw i128 %atomic-load, 1
+// CHECK-NEXT: store i128 %add, ptr %agg.result, align 8
+// CHECK-NEXT: ret void
+
+// CHECK-LABEL:  @f2
+// CHECK:  %atomic-load = load atomic i128, ptr @Atomic_fp128 seq_cst, 
align 16
+// CHECK-NEXT: %0 = bitcast i128 %atomic-load to fp128
+// CHECK-NEXT: %add = fadd fp128 %0, 0xL3FFF
+// CHECK-NEXT: store fp128 %add, ptr %agg.result, align 8
+// CHECK-NEXT: ret void
+
+
+#include 
+
+_Atomic __int128Atomic_int128;
+_Atomic long double Atomic_fp128;
+
+__int128 f1() {
+  return Atomic_int128 + 1;
+}
+
+long double 

[clang] [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute (PR #71300)

2023-11-25 Thread Richard Dzenis via cfe-commits

RIscRIpt wrote:

Rebased onto main, resolved conflicts, re-run lit locally.
Please let me know if I could speed-up review in any way.

https://github.com/llvm/llvm-project/pull/71300
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute (PR #71300)

2023-11-25 Thread Richard Dzenis via cfe-commits

https://github.com/RIscRIpt updated 
https://github.com/llvm/llvm-project/pull/71300

>From 65c306e94e9b749ef0d38ef709ddb8b23dac987a Mon Sep 17 00:00:00 2001
From: Richard Dzenis 
Date: Thu, 20 Jul 2023 00:18:50 +0300
Subject: [PATCH 1/2] [clang-cl] Add support for [[msvc::constexpr]] C++11
 attribute

Differential Revision: https://reviews.llvm.org/D134475
---
 clang/include/clang/Basic/Attr.td |  8 +++
 clang/include/clang/Basic/AttrDocs.td | 16 ++
 .../clang/Basic/DiagnosticSemaKinds.td| 10 +++-
 clang/include/clang/Basic/LangOptions.h   |  1 +
 clang/lib/AST/ExprConstant.cpp| 34 +---
 clang/lib/Basic/Targets/OSTargets.cpp |  3 ++
 clang/lib/Sema/SemaDecl.cpp   |  4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 24 +
 clang/lib/Sema/SemaDeclCXX.cpp|  5 +-
 clang/lib/Sema/SemaStmtAttr.cpp   | 16 ++
 clang/test/AST/ms-constexpr.cpp   | 28 ++
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/SemaCXX/ms-constexpr-invalid.cpp   | 52 +++
 clang/test/SemaCXX/ms-constexpr-new.cpp   | 16 ++
 clang/test/SemaCXX/ms-constexpr.cpp   | 37 +
 15 files changed, 245 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/AST/ms-constexpr.cpp
 create mode 100644 clang/test/SemaCXX/ms-constexpr-invalid.cpp
 create mode 100644 clang/test/SemaCXX/ms-constexpr-new.cpp
 create mode 100644 clang/test/SemaCXX/ms-constexpr.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 03ed6accf700c4e6..08730e4dfd67feca 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3638,6 +3638,14 @@ def : MutualExclusions<[Owner, Pointer]>;
 
 // Microsoft-related attributes
 
+def MSConstexpr : InheritableAttr {
+  let LangOpts = [MicrosoftExt];
+  let Spellings = [CXX11<"msvc", "constexpr">];
+  let Subjects = SubjectList<[Function, Stmt], ErrorDiag,
+ "functions and statements">;
+  let Documentation = [MSConstexprDocs];
+}
+
 def MSNoVTable : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"novtable">];
   let Subjects = SubjectList<[CXXRecord]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index be74535e28d8a60d..709a376bec9fbe95 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3612,6 +3612,22 @@ an error:
 }];
 }
 
+def MSConstexprDocs : Documentation {
+  let Category = DocCatStmt;
+  let Content = [{
+The ``[[msvc::constexpr]]`` attribute can be applied only to a function
+definition or a ``return`` statement. It does not impact function declarations.
+A ``[[msvc::constexpr]]`` function cannot be ``constexpr`` or ``consteval``.
+A ``[[msvc::constexpr]]`` function is treated in the same way as a 
``constexpr``
+function if it is evaluated in a constant context of
+``[[msvc::constexpr]] return`` statement.
+Otherwise, it is treated as a regular function.
+
+Semantics of this attribute is enabled only under MSVC compatibility
+(``-fms-compatibility-version``) 19.33 and later.
+  }];
+}
+
 def MSNoVTableDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6894e22da34e0c74..43349cdfaea75c9a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2861,8 +2861,8 @@ def warn_cxx17_compat_constexpr_local_var_no_init : 
Warning<
   "is incompatible with C++ standards before C++20">,
   InGroup, DefaultIgnore;
 def ext_constexpr_function_never_constant_expr : ExtWarn<
-  "%select{constexpr|consteval}1 %select{function|constructor}0 never produces 
a "
-  "constant expression">, InGroup>, 
DefaultError;
+  "%select{constexpr|consteval|[[msvc::constexpr]]}1 
%select{function|constructor}0 "
+  "never produces a constant expression">, 
InGroup>, DefaultError;
 def err_attr_cond_never_constant_expr : Error<
   "%0 attribute expression never produces a constant expression">;
 def err_diagnose_if_invalid_diagnostic_type : Error<
@@ -2884,6 +2884,12 @@ def warn_cxx11_compat_constexpr_body_multiple_return : 
Warning<
   InGroup, DefaultIgnore;
 def note_constexpr_body_previous_return : Note<
   "previous return statement is here">;
+def err_ms_constexpr_not_distinct : Error<
+  "[[msvc::constexpr]] cannot be applied to a %select{constexpr|consteval}0 
function %1">;
+def err_ms_constexpr_virtual : Error<"virtual function cannot be 
[[msvc::constexpr]]">;
+def warn_ms_constexpr_no_effect : Warning<
+  "[[msvc::constexpr]] has effect only on function definitions and return 
statements">,
+  InGroup;
 
 // C++20 function try blocks in constexpr
 def ext_constexpr_function_try_block_cxx20 : ExtWarn<
diff --git 

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-11-25 Thread via cfe-commits

hstk30-hw wrote:

> For example, Folks at google advise against using `default` when switching 
> over an enum https://abseil.io/tips/147.
> Misra requires a default statement, but makes an exception for enums. (6.4.6 
> in misra 2008)

I see it's easy to implement in LLVM like clang tidy (not warning for enum and 
constant expr).

The clang tidy may seperate the `switch` warning ( I have to use tidy to see 
`switch-default`, but I can see `switch-enum` `switch-bool` in compiler).

IMAO, if we can implement it together in compiler, why not?

https://github.com/llvm/llvm-project/pull/73077
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits