[PATCH] D145885: [clang-tidy] Support readability-redundant-string-cstr.StringParameterFunctions option

2023-03-13 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 504517.
mikecrowe marked 2 inline comments as done.
mikecrowe added a comment.

Documentation updates suggested by @PiotrZSL. Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145885

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-function.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-function.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-function.cpp
@@ -0,0 +1,148 @@
+// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: readability-redundant-string-cstr.StringParameterFunctions, \
+// RUN:   value: '::fmt::format; ::fmt::print; ::BaseLogger::operator(); ::BaseLogger::Log'}] \
+// RUN: }" \
+// RUN:   -- -isystem %clang_tidy_headers
+#include 
+
+namespace fmt {
+  inline namespace v8 {
+template
+void print(const char *, Args &&...);
+template
+std::string format(const char *, Args &&...);
+  }
+}
+
+namespace notfmt {
+  inline namespace v8 {
+template
+void print(const char *, Args &&...);
+template
+std::string format(const char *, Args &&...);
+  }
+}
+
+void fmt_print(const std::string &s1, const std::string &s2, const std::string &s3) {
+  fmt::print("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}fmt::print("One:{}\n", s1);
+
+  fmt::print("One:{} Two:{} Three:{}\n", s1.c_str(), s2, s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES: :[[@LINE-2]]:58: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}fmt::print("One:{} Two:{} Three:{}\n", s1, s2, s3);
+}
+
+// There's no c_str() call here, so it shouldn't be touched
+void fmt_print_no_cstr(const std::string &s1, const std::string &s2) {
+fmt::print("One: {}, Two: {}\n", s1, s2);
+}
+
+// This isn't fmt::print, so it shouldn't be fixed.
+void not_fmt_print(const std::string &s1) {
+notfmt::print("One: {}\n", s1.c_str());
+}
+
+void fmt_format(const std::string &s1, const std::string &s2, const std::string &s3) {
+  auto r1 = fmt::format("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}auto r1 = fmt::format("One:{}\n", s1);
+
+  auto r2 = fmt::format("One:{} Two:{} Three:{}\n", s1.c_str(), s2, s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:53: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES: :[[@LINE-2]]:69: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}auto r2 = fmt::format("One:{} Two:{} Three:{}\n", s1, s2, s3);
+}
+
+// There's are c_str() calls here, so it shouldn't be touched
+void fmt_format_no_cstr(const std::string &s1, const std::string &s2) {
+fmt::format("One: {}, Two: {}\n", s1, s2);
+}
+
+// This is not fmt::format, so it shouldn't be fixed
+std::string not_fmt_format(const std::string &s1) {
+return notfmt::format("One: {}\n", s1.c_str());
+}
+
+class BaseLogger {
+public:
+  template 
+  void operator()(const char *fmt, Args &&...args) {
+  }
+
+  template 
+  void Log(const char *fmt, Args &&...args) {
+  }
+};
+
+class DerivedLogger : public BaseLogger {};
+class DoubleDerivedLogger : public DerivedLogger {};
+typedef DerivedLogger TypedefDerivedLogger;
+
+void logger1(const std::string &s1, const std::string &s2, const std::string &s3) {
+  BaseLogger LOGGER;
+
+  LOGGER("%s\n", s1.c_str(), s2, s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}LOGGER("%s\n", s1, s2, s3);
+
+  DerivedLogger LOGGER2;
+  LOGGER2("%d %s\n", 42, s1.c_str(), s2.c_str(), s3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES: :[[@LINE-2]]:38: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}LOGGER2("%d %s\n", 42, s1, s2, s3);
+
+  DoubleDerivedLogger LOGGERD;
+  LOGGERD("%d %s\n", 42, s1.c_str(), s2, s3.c_str());
+  // CHECK-MESSA

[PATCH] D145899: [AIX][Clang] Respect -r when invoking the linker

2023-03-13 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 504518.
francii added a comment.

Move `-r` check in `CommonArgs.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145899

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1693,6 +1693,8 @@
   }
   case ToolChain::UNW_CompilerRT:
 if (TC.getTriple().isOSAIX()) {
+  if (Args.hasArg(options::OPT_r))
+break;
   // AIX only has libunwind as a shared library. So do not pass
   // anything in if -static is specified.
   if (LGT != LibGccType::StaticLibGcc)
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -175,7 +175,7 @@
   };
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
-   options::OPT_shared)) {
+   options::OPT_shared, options::OPT_r)) {
 CmdArgs.push_back(
 Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename(;
 
@@ -232,6 +232,13 @@
 CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-bE:") + ExportList));
   }
 
+  if (Args.hasArg(options::OPT_r)) {
+const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
+C.addCommand(std::make_unique(
+JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, 
Output));
+return;
+  }
+
   // Add directory to library search path.
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1693,6 +1693,8 @@
   }
   case ToolChain::UNW_CompilerRT:
 if (TC.getTriple().isOSAIX()) {
+  if (Args.hasArg(options::OPT_r))
+break;
   // AIX only has libunwind as a shared library. So do not pass
   // anything in if -static is specified.
   if (LGT != LibGccType::StaticLibGcc)
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -175,7 +175,7 @@
   };
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
-   options::OPT_shared)) {
+   options::OPT_shared, options::OPT_r)) {
 CmdArgs.push_back(
 Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename(;
 
@@ -232,6 +232,13 @@
 CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-bE:") + ExportList));
   }
 
+  if (Args.hasArg(options::OPT_r)) {
+const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
+C.addCommand(std::make_unique(
+JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output));
+return;
+  }
+
   // Add directory to library search path.
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145885: [clang-tidy] Support readability-redundant-string-cstr.StringParameterFunctions option

2023-03-13 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst:18
+   or proper overload candidates that can do so should exist. This can be
+   used to configure functions such as fmt::format, spdlog::logger::info,
+   or wrappers around these and similar functions. The default value is the

Put function names in double ``, like ``fmt::format``, ``spdlog::logger::info``


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145885

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


[PATCH] D145671: [clang] Remove legacy -m(no)-code-object-v3 options

2023-03-13 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh added a comment.

I'll wait a couple of more days and then land, if no one has any objections.
As said before this has been deprecated for a long time, and clang was already 
warning on use of those options. Removal has been pending for a while :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145671

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


[clang] 2e9977c - [C++20] [Modules] Treat module linkage as formal linkage only

2023-03-13 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-03-13T15:54:40+08:00
New Revision: 2e9977c2815653c141c6c060c4e0ab6c0db27911

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

LOG: [C++20] [Modules] Treat module linkage as formal linkage only

Close https://github.com/llvm/llvm-project/issues/61321

There are two linkage modes in clang now: one for internal linkage and
one for formal linkage. The internal linkage is for the implementation
details and the formal linkage is for the consistency with the C++
standard.

Since we previously implemented the strong ownership for modules, the
module linkage is not meaningful for linkers any more. So the module
linkage should only be used for formal linkage.

Added: 
clang/test/Modules/inconsistent-export.cppm

Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/unittests/AST/DeclTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index e213c5fe29c68..0585fda3a566c 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -395,9 +395,7 @@ class NamedDecl : public Decl {
 
   /// Get the linkage from a semantic point of view. Entities in
   /// anonymous namespaces are external (in c++98).
-  Linkage getFormalLinkage() const {
-return clang::getFormalLinkage(getLinkageInternal());
-  }
+  Linkage getFormalLinkage() const;
 
   /// True if this decl has external linkage.
   bool hasExternalFormalLinkage() const {

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 240e744ee6449..484a4a294aa5e 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -605,20 +605,6 @@ static LinkageInfo getInternalLinkageFor(const NamedDecl 
*D) {
 }
 
 static LinkageInfo getExternalLinkageFor(const NamedDecl *D) {
-  // C++ [basic.link]p4.8:
-  //   - if the declaration of the name is attached to a named module and is 
not
-  //   exported
-  // the name has module linkage;
-  //
-  // [basic.namespace.general]/p2
-  //   A namespace is never attached to a named module and never has a name 
with
-  //   module linkage.
-  if (isInModulePurview(D) &&
-  !isExportedFromModuleInterfaceUnit(
-  cast(D->getCanonicalDecl())) &&
-  !isa(D))
-return LinkageInfo(ModuleLinkage, DefaultVisibility, false);
-
   return LinkageInfo::external();
 }
 
@@ -1165,6 +1151,29 @@ Linkage NamedDecl::getLinkageInternal() const {
   .getLinkage();
 }
 
+/// Get the linkage from a semantic point of view. Entities in
+/// anonymous namespaces are external (in c++98).
+Linkage NamedDecl::getFormalLinkage() const {
+  Linkage InternalLinkage = getLinkageInternal();
+
+  // C++ [basic.link]p4.8:
+  //   - if the declaration of the name is attached to a named module and is 
not
+  //   exported
+  // the name has module linkage;
+  //
+  // [basic.namespace.general]/p2
+  //   A namespace is never attached to a named module and never has a name 
with
+  //   module linkage.
+  if (isInModulePurview(this) &&
+  InternalLinkage == ExternalLinkage &&
+  !isExportedFromModuleInterfaceUnit(
+  cast(this->getCanonicalDecl())) &&
+  !isa(this))
+InternalLinkage = ModuleLinkage;
+
+  return clang::getFormalLinkage(InternalLinkage);
+}
+
 LinkageInfo NamedDecl::getLinkageAndVisibility() const {
   return LinkageComputer{}.getDeclLinkageAndVisibility(this);
 }

diff  --git a/clang/test/Modules/inconsistent-export.cppm 
b/clang/test/Modules/inconsistent-export.cppm
new file mode 100644
index 0..5e94d2b37b757
--- /dev/null
+++ b/clang/test/Modules/inconsistent-export.cppm
@@ -0,0 +1,46 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/m-a.pcm
+// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface -o %t/m-b.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++20 %t/m.cppm -emit-module-interface -o %t/m.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++20 %t/use.cppm -fprebuilt-module-path=%t -emit-obj
+
+//--- a.cppm
+export module m:a;
+namespace n {
+export class a {
+public:
+virtual ~a() {}
+};
+}
+
+//--- b.cppm
+export module m:b;
+namespace n {
+class a;
+}
+
+//--- m.cppm
+export module m;
+export import :a;
+export import :b;
+
+//--- use.cppm
+// expected-no-diagnostics
+export module u;
+export import m;
+
+struct aa : public n::a {
+aa() {}
+};
+auto foo(n::a*) {
+return;
+}
+
+void use() {
+n::a _;
+}

diff  --git a/clang/unittests/AST/DeclTest.cpp 
b/clang/unittests/AST/DeclTest.cpp
index 119551bb44453..a6535119afb53 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -232,16 +232,16 @@ TEST(Decl, ModuleAndInternalLi

[PATCH] D145491: [clang] Replace Member Expressions During Instantiation If Necessary

2023-03-13 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 504535.
lime added a comment.

Update and ping.


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

https://reviews.llvm.org/D145491

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/decl-ref-inheritance.cpp
  clang/test/SemaCXX/decltype.cpp

Index: clang/test/SemaCXX/decltype.cpp
===
--- clang/test/SemaCXX/decltype.cpp
+++ clang/test/SemaCXX/decltype.cpp
@@ -101,6 +101,44 @@
   template void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
 }
 
+namespace GH58674 {
+  struct Foo {
+float value_;
+struct nested {
+  float value_;
+};
+  };
+
+  template 
+  struct TemplateFoo {
+float value_;
+  };
+
+  float bar;
+
+  template 
+  struct Animal{};
+
+  template 
+  class Cat : Animal {
+using okay = decltype(Foo::value_);
+using also_okay = decltype(bar);
+using okay2 = decltype(Foo::nested::value_);
+using okay3 = decltype(TemplateFoo::value_);
+  public:
+void meow() {
+  using okay = decltype(Foo::value_);
+  using also_okay = decltype(bar);
+  using okay2 = decltype(Foo::nested::value_);
+  using okay3 = decltype(TemplateFoo::value_);
+}
+  };
+
+  void baz() {
+  Cat{}.meow();
+  }
+}
+
 template
 class conditional {
 };
Index: clang/test/CodeGenCXX/decl-ref-inheritance.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/decl-ref-inheritance.cpp
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck \
+// RUN: -check-prefix=CHECK-1 %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck \
+// RUN: -check-prefix=CHECK-2 %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck \
+// RUN: -check-prefix=CHECK-3 %s
+
+// CHECK-1: [[FOO:%.+]] = type { float }
+struct foo {
+  float val;
+};
+
+template  struct bar : T {
+};
+
+struct baz : bar {
+  // CHECK-1: define{{.*}} float @_ZN3baz3getEv
+  // CHECK-1: {{%.+}} = getelementptr inbounds [[FOO]], ptr {{%.+}}, i32 0, i32 0
+  float get() {
+return val;
+  }
+};
+
+int qux() {
+  auto f = baz{};
+  return f.get();
+}
+
+// CHECK-2: [[F:%.+]] = type { ptr }
+struct f {
+  void *g;
+};
+
+template  struct k : j {
+  // CHECK-2: define{{.*}} void @_ZN1kI1fE1lEv
+  // CHECK-2: {{%.+}} = getelementptr inbounds [[F]], ptr {{%.+}}, i32 0, i32 0
+  virtual void l(){ (void)f::g; }
+};
+
+k q;
+
+// CHECK-3: [[BASE:%.+]] = type { i32 }
+class Base {
+protected:
+  int member;
+};
+
+template 
+struct Subclass : public Parent {
+  // CHECK-3: define{{.*}} i32 @_ZN8SubclassI4BaseE4funcEv
+  // CHECK-3: {{%.+}} = getelementptr inbounds [[BASE]], ptr {{%.+}}, i32 0, i32 0
+  int func() { return Base::member; }
+};
+
+using Impl = Subclass;
+
+int use() {
+  Impl i;
+  return i.func();
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -2803,6 +2803,21 @@
 R.addDecl(FoundDecl);
 R.resolveKind();
 
+if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
+isa(Member)) {
+  if (auto *ThisClass = cast(Base)
+->getType()
+->getPointeeType()
+->getAsCXXRecordDecl()) {
+auto *Class = cast(Member->getDeclContext());
+// In unevaluated contexts, an expression supposed to be a member access
+// might reference a member in an unrelated class.
+if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
+  return getSema().BuildDeclRefExpr(Member, Member->getType(),
+VK_LValue, Member->getLocation());
+  }
+}
+
 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
   SS, TemplateKWLoc,
   FirstQualifierInScope,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix an issue about ``decltype`` in the members of class templates derived from
+  templates with related parameters.
+  (`#58674 `_)
 
 Bug Fixes to AST Handling
 ^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145885: [clang-tidy] Support readability-redundant-string-cstr.StringParameterFunctions option

2023-03-13 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 504537.
mikecrowe edited the summary of this revision.
mikecrowe added a comment.

Quote types and functions correctly in redundant-string-cstr.rst.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145885

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-function.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-function.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-function.cpp
@@ -0,0 +1,148 @@
+// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: readability-redundant-string-cstr.StringParameterFunctions, \
+// RUN:   value: '::fmt::format; ::fmt::print; ::BaseLogger::operator(); ::BaseLogger::Log'}] \
+// RUN: }" \
+// RUN:   -- -isystem %clang_tidy_headers
+#include 
+
+namespace fmt {
+  inline namespace v8 {
+template
+void print(const char *, Args &&...);
+template
+std::string format(const char *, Args &&...);
+  }
+}
+
+namespace notfmt {
+  inline namespace v8 {
+template
+void print(const char *, Args &&...);
+template
+std::string format(const char *, Args &&...);
+  }
+}
+
+void fmt_print(const std::string &s1, const std::string &s2, const std::string &s3) {
+  fmt::print("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}fmt::print("One:{}\n", s1);
+
+  fmt::print("One:{} Two:{} Three:{}\n", s1.c_str(), s2, s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES: :[[@LINE-2]]:58: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}fmt::print("One:{} Two:{} Three:{}\n", s1, s2, s3);
+}
+
+// There's no c_str() call here, so it shouldn't be touched
+void fmt_print_no_cstr(const std::string &s1, const std::string &s2) {
+fmt::print("One: {}, Two: {}\n", s1, s2);
+}
+
+// This isn't fmt::print, so it shouldn't be fixed.
+void not_fmt_print(const std::string &s1) {
+notfmt::print("One: {}\n", s1.c_str());
+}
+
+void fmt_format(const std::string &s1, const std::string &s2, const std::string &s3) {
+  auto r1 = fmt::format("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}auto r1 = fmt::format("One:{}\n", s1);
+
+  auto r2 = fmt::format("One:{} Two:{} Three:{}\n", s1.c_str(), s2, s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:53: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES: :[[@LINE-2]]:69: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}auto r2 = fmt::format("One:{} Two:{} Three:{}\n", s1, s2, s3);
+}
+
+// There's are c_str() calls here, so it shouldn't be touched
+void fmt_format_no_cstr(const std::string &s1, const std::string &s2) {
+fmt::format("One: {}, Two: {}\n", s1, s2);
+}
+
+// This is not fmt::format, so it shouldn't be fixed
+std::string not_fmt_format(const std::string &s1) {
+return notfmt::format("One: {}\n", s1.c_str());
+}
+
+class BaseLogger {
+public:
+  template 
+  void operator()(const char *fmt, Args &&...args) {
+  }
+
+  template 
+  void Log(const char *fmt, Args &&...args) {
+  }
+};
+
+class DerivedLogger : public BaseLogger {};
+class DoubleDerivedLogger : public DerivedLogger {};
+typedef DerivedLogger TypedefDerivedLogger;
+
+void logger1(const std::string &s1, const std::string &s2, const std::string &s3) {
+  BaseLogger LOGGER;
+
+  LOGGER("%s\n", s1.c_str(), s2, s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}LOGGER("%s\n", s1, s2, s3);
+
+  DerivedLogger LOGGER2;
+  LOGGER2("%d %s\n", 42, s1.c_str(), s2.c_str(), s3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES: :[[@LINE-2]]:38: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}LOGGER2("%d %s\n", 42, s1, s2, s3);
+
+  DoubleDerivedLogger LOGGERD;
+  LOGGERD("%d %s\n", 42, s1.c_str(), s2, s3.c_str());
+ 

[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-13 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Why does "flang/test/Driver/target-features.f90" list all RISC-V features?  Why 
not use 
https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/target-cpu-features.f90
 instead?




Comment at: flang/test/Driver/target-features.f90:1
+! RUN: %flang --target=riscv64-linux-gnu --target=riscv64 -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64

What happens if the RISC-V backend is not available?



Comment at: flang/test/Driver/target-features.f90:4
+
+! CHECK-RV64: "-target-feature" "+m" "-target-feature" "+a" "-target-feature" 
"+c" "-target-feature" "-e" "-target-feature" "-f" "-target-feature" "-d" 
"-target-feature" "-h" "-target-feature" "-zihintpause" "-target-feature" 
"-zfhmin" "-target-feature" "-zfh" "-target-feature" "-zfinx" "-target-feature" 
"-zdinx" "-target-feature" "-zhinxmin" "-target-feature" "-zhinx" 
"-target-feature" "-zba" "-target-feature" "-zbb" "-target-feature" "-zbc" 
"-target-feature" "-zbs" "-target-feature" "-zbkb" "-target-feature" "-zbkc" 
"-target-feature" "-zbkx" "-target-feature" "-zknd" "-target-feature" "-zkne" 
"-target-feature" "-zknh" "-target-feature" "-zksed" "-target-feature" "-zksh" 
"-target-feature" "-zkr" "-target-feature" "-zkn" "-target-feature" "-zks" 
"-target-feature" "-zkt" "-target-feature" "-zk" "-target-feature" "-zmmul" 
"-target-feature" "-v" "-target-feature" "-zvl32b" "-target-feature" "-zvl64b" 
"-target-feature" "-zvl128b" "-target-feature" "-zvl256b" "-target-feature" 
"-zvl512b" "-target-feature" "-zvl1024b" "-target-feature" "-zvl2048b" 
"-target-feature" "-zvl4096b" "-target-feature" "-zvl8192b" "-target-feature" 
"-zvl16384b" "-target-feature" "-zvl32768b" "-target-feature" "-zvl65536b" 
"-target-feature" "-zve32x" "-target-feature" "-zve32f" "-target-feature" 
"-zve64x" "-target-feature" "-zve64f" "-target-feature" "-zve64d" 
"-target-feature" "-zicbom" "-target-feature" "-zicboz" "-target-feature" 
"-zicbop" "-target-feature" "-zicsr" "-target-feature" "-zifencei" 
"-target-feature" "-zawrs" "-target-feature" "-svnapot" "-target-feature" 
"-svpbmt" "-target-feature" "-svinval" "-target-feature" "-xtheadba" 
"-target-feature" "-xtheadbb" "-target-feature" "-xtheadbs" "-target-feature" 
"-xtheadcmo" "-target-feature" "-xtheadcondmov" "-target-feature" 
"-xtheadfmemidx" "-target-feature" "-xtheadmac" "-target-feature" 
"-xtheadmemidx" "-target-feature" "-xtheadmempair" "-target-feature" 
"-xtheadsync" "-target-feature" "-xtheadvdot" "-target-feature" 
"-xventanacondops" "-target-feature" "-experimental-zihintntl" 
"-target-feature" "-experimental-zca" "-target-feature" "-experimental-zcb" 
"-target-feature" "-experimental-zcd" "-target-feature" "-experimental-zcf" 
"-target-feature" "-experimental-zfa" "-target-feature" "-experimental-zvfh" 
"-target-feature" "-experimental-ztso" "-target-feature" "+relax" 
"-target-feature" "-save-restore"

 This one line will require updating once respective bit of LLVM is updated. 
Let's avoid that :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

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


[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-13 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: flang/test/Driver/target-features.f90:1
+! RUN: %flang --target=riscv64-linux-gnu --target=riscv64 -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64

awarzynski wrote:
> What happens if the RISC-V backend is not available?
Clang doesn't need a backend to be available to generate IR for that 
architecture. I would hope Flang is the same.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

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


[PATCH] D145885: [clang-tidy] Support readability-redundant-string-cstr.StringParameterFunctions option

2023-03-13 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145885

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


[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-13 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/test/Driver/target-features.f90:1
+! RUN: %flang --target=riscv64-linux-gnu --target=riscv64 -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64

jrtc27 wrote:
> awarzynski wrote:
> > What happens if the RISC-V backend is not available?
> Clang doesn't need a backend to be available to generate IR for that 
> architecture. I would hope Flang is the same.
> Clang doesn't need a backend to be available to generate IR 

This test is not generating LLVM IR. It does, however, specify the target which 
is then translated into many **LLVM**-specific flags. 

Also:
```
clang --target=riscv64-linux-gnu --target=riscv64 -c file2.c
error: unable to create target: 'No available targets are compatible with 
triple "riscv64"'
1 error generated.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

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


[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-13 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: flang/test/Driver/target-features.f90:1
+! RUN: %flang --target=riscv64-linux-gnu --target=riscv64 -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64

awarzynski wrote:
> jrtc27 wrote:
> > awarzynski wrote:
> > > What happens if the RISC-V backend is not available?
> > Clang doesn't need a backend to be available to generate IR for that 
> > architecture. I would hope Flang is the same.
> > Clang doesn't need a backend to be available to generate IR 
> 
> This test is not generating LLVM IR. It does, however, specify the target 
> which is then translated into many **LLVM**-specific flags. 
> 
> Also:
> ```
> clang --target=riscv64-linux-gnu --target=riscv64 -c file2.c
> error: unable to create target: 'No available targets are compatible with 
> triple "riscv64"'
> 1 error generated.
> ```
Because you're trying to use the backend. Pass --emit-llvm and observe it works.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

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


[clang] e264fe8 - [doc] [Modules] Document how to implement ABI compatible code in module units

2023-03-13 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-03-13T16:44:10+08:00
New Revision: e264fe89e37fc0b12e18d72ed98056cea1a9eba6

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

LOG: [doc] [Modules] Document how to implement ABI compatible code in module 
units

Added: 


Modified: 
clang/docs/StandardCPlusPlusModules.rst

Removed: 




diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index bcf2c4470c521..970803b56c8c6 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -591,6 +591,19 @@ The result would be ``NS::foo@M()``, which reads as 
``NS::foo()`` in module ``M`
 The ABI implies that we can't declare something in a module unit and define it 
in a non-module unit (or vice-versa),
 as this would result in linking errors.
 
+If we still want to implement declarations within the compatible ABI in module 
unit,
+we can use the language-linkage specifier. Since the declarations in the 
language-linkage specifier
+is attached to the global module fragments. For example:
+
+.. code-block:: c++
+
+  export module M;
+  namespace NS {
+export extern "C++" int foo();
+  }
+
+Now the linkage name of ``NS::foo()`` will be ``_ZN2NS3fooEv``.
+
 Known Problems
 --
 



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


[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-13 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce updated this revision to Diff 504548.
sunshaoce added a comment.

Based on everyone's comments, I merged the test into `target-cpu-features.f90` 
and only kept the generic `-target-feature`. At the same time, I removed the 
`switch (TC.getArch())` and passed the test on x86 and RISC-V 64.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

Files:
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/test/Driver/target-cpu-features.f90


Index: flang/test/Driver/target-cpu-features.f90
===
--- flang/test/Driver/target-cpu-features.f90
+++ flang/test/Driver/target-cpu-features.f90
@@ -22,6 +22,12 @@
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
+! RUN: %flang --target=riscv32-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV32
+
+! RUN: %flang --target=riscv64-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
+
 
 ! Test that invalid cpu and features are ignored.
 
@@ -52,5 +58,12 @@
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" 
"-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" 
"-target-feature" "-fsgsbase"
 
+! CHECK-RV32: "-fc1" "-triple" "riscv32-unknown-linux-gnu"
+! CHECK-RV32-SAME: "-target-cpu" "generic-rv32" "-target-feature" "+m" 
"-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" 
"-target-feature" "+c" "-target-feature" "-e"
+
+! CHECK-RV64: "-fc1" "-triple" "riscv64-unknown-linux-gnu"
+! CHECK-RV64-SAME: "-target-cpu" "generic-rv64" "-target-feature" "+m" 
"-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" 
"-target-feature" "+c" "-target-feature" "-e"
+
+
 ! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target 
(ignoring processor)
 ! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this 
target (ignoring feature)
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -101,15 +101,7 @@
   }
 
   // Add the target features.
-  switch (TC.getArch()) {
-  default:
-break;
-  case llvm::Triple::aarch64:
-[[fallthrough]];
-  case llvm::Triple::x86_64:
-getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
-break;
-  }
+  getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
 
   // TODO: Add target specific flags, ABI, mtune option etc.
 }


Index: flang/test/Driver/target-cpu-features.f90
===
--- flang/test/Driver/target-cpu-features.f90
+++ flang/test/Driver/target-cpu-features.f90
@@ -22,6 +22,12 @@
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
+! RUN: %flang --target=riscv32-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV32
+
+! RUN: %flang --target=riscv64-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
+
 
 ! Test that invalid cpu and features are ignored.
 
@@ -52,5 +58,12 @@
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" "-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" "-target-feature" "-fsgsbase"
 
+! CHECK-RV32: "-fc1" "-triple" "riscv32-unknown-linux-gnu"
+! CHECK-RV32-SAME: "-target-cpu" "generic-rv32" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+c" "-target-feature" "-e"
+
+! CHECK-RV64: "-fc1" "-triple" "riscv64-unknown-linux-gnu"
+! CHECK-RV64-SAME: "-target-cpu" "generic-rv64" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+c" "-target-feature" "-e"
+
+
 ! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target (ignoring processor)
 ! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this target (ignoring feature)
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -101,15 +101,7 @@
   }
 
   // Add the target features.
-  switch (TC.getArch()) {
-  default:
-break;
-  case llvm::Triple::aarch64:
-[[fallthrough]];
-  case llvm::Triple::x86_64:
-getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
-break;
-  }
+  getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
 
   // TODO: Add target specific flags, ABI, mtune option etc.
 }
___
cfe-commits mailing list
c

[PATCH] D145813: [clang-format] Respect Cpp11BraceListStyle when aligning array of structures

2023-03-13 Thread Hoe Hao Cheng via Phabricator via cfe-commits
hch12907 added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:20273
+  Style.ColumnLimit = 20;
+  EXPECT_EQ(
+  "demo = std::array<\n"

MyDeveloperDay wrote:
> any reason you didn't use verifyFormat here?
No particular reason - I simply copied other tests and modified them to suit 
the Cpp11BracedListStyle == false case, and one of those tests used EXPECT_EQ.

Should I change it to verifyFormat?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145813

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


[PATCH] D142587: [clang-tidy] Improved too-small-loop-variable with bit-field support

2023-03-13 Thread Henric Karlsson via Phabricator via cfe-commits
Henric added a comment.

Hi
With this patch, the following code gives me a warning that I don't think is 
intentional.

  typedef struct S {
int x:4;
  } S;
  
  void foo(S s) {
for (int i=10; i > s.x; --i) ;
  }
  
  loop_var.c:6:22: warning: loop variable has narrower type 'int:4' than 
iteration's upper bound 'int' [bugprone-too-small-loop-variable]
  for (int i=10; i > s.x; --i) ;
 ^

Looks like the logic i reversed here, so the loop variable gets the bit field 
type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142587

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


[PATCH] D145906: [clang-tidy] Correctly handle evaluation order of designated initializers.

2023-03-13 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

As designated initializers show up only in the syntactic form of the
InitListExpr, we need to make sure we're searching both forms of the
InitListExpr when determining successors in the evaluation order.

This fixes a bug in bugprone-use-after-move where previously we erroneously
concluded that two designated initializers were unsequenced. The newly added
tests fail without the fix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145906

Files:
  clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
@@ -1155,18 +1155,32 @@
   int i;
   A a;
 };
-A a;
-S1 s1{a.getInt(), std::move(a)};
+{
+  A a;
+  S1 s1{a.getInt(), std::move(a)};
+}
+{
+  A a;
+  S1 s1{.i = a.getInt(), .a = std::move(a)};
+}
   }
   {
 struct S2 {
   A a;
   int i;
 };
-A a;
-S2 s2{std::move(a), a.getInt()};
-// CHECK-NOTES: [[@LINE-1]]:25: warning: 'a' used after it was moved
-// CHECK-NOTES: [[@LINE-2]]:11: note: move occurred here
+{
+  A a;
+  S2 s2{std::move(a), a.getInt()};
+  // CHECK-NOTES: [[@LINE-1]]:27: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-2]]:13: note: move occurred here
+}
+{
+  A a;
+  S2 s2{.a = std::move(a), .i = a.getInt()};
+  // CHECK-NOTES: [[@LINE-1]]:37: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-2]]:13: note: move occurred here
+}
   }
 }
 
Index: clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
===
--- clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -8,6 +8,7 @@
 
 #include "ExprSequence.h"
 #include "clang/AST/ParentMapContext.h"
+#include "llvm/ADT/SmallVector.h"
 #include 
 
 namespace clang::tidy::utils {
@@ -49,6 +50,7 @@
 }
 
 namespace {
+
 bool isDescendantOrEqual(const Stmt *Descendant, const Stmt *Ancestor,
  ASTContext *Context) {
   if (Descendant == Ancestor)
@@ -60,6 +62,17 @@
 
   return false;
 }
+
+llvm::SmallVector
+allInitListExprForms(const InitListExpr *InitList) {
+  llvm::SmallVector result = {InitList};
+  if (InitList->isSemanticForm() && InitList->getSyntacticForm())
+result.push_back(InitList->getSyntacticForm());
+  if (InitList->isSyntacticForm() && InitList->getSemanticForm())
+result.push_back(InitList->getSemanticForm());
+  return result;
+}
+
 } // namespace
 
 ExprSequence::ExprSequence(const CFG *TheCFG, const Stmt *Root,
@@ -111,9 +124,12 @@
 } else if (const auto *InitList = dyn_cast(Parent)) {
   // Initializer list: Each initializer clause is sequenced after the
   // clauses that precede it.
-  for (unsigned I = 1; I < InitList->getNumInits(); ++I) {
-if (InitList->getInit(I - 1) == S)
-  return InitList->getInit(I);
+  for (const InitListExpr *Form : allInitListExprForms(InitList)) {
+for (unsigned I = 1; I < Form->getNumInits(); ++I) {
+  if (Form->getInit(I - 1) == S) {
+return Form->getInit(I);
+  }
+}
   }
 } else if (const auto *Compound = dyn_cast(Parent)) {
   // Compound statement: Each sub-statement is sequenced after the


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
@@ -1155,18 +1155,32 @@
   int i;
   A a;
 };
-A a;
-S1 s1{a.getInt(), std::move(a)};
+{
+  A a;
+  S1 s1{a.getInt(), std::move(a)};
+}
+{
+  A a;
+  S1 s1{.i = a.getInt(), .a = std::move(a)};
+}
   }
   {
 struct S2 {
   A a;
   int i;
 };
-A a;
-S2 s2{std::move(a), a.getInt()};
-// CHECK-NOTES: [[@LINE-1]]:25: warning: 'a' used after it was moved
-// CHECK-NOTES: [[@LINE-2]]:11: note: move occurred here
+{
+  A a;
+  S2 s2{std::move(a), a.getInt()};
+  // CHECK-NOTES: [[@LINE-1]]:27: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-2]]:13: note: move occurred here
+}
+{
+  A a;
+  S2 s2{.a = std::move(a), .i = a.getInt()};
+  // CHEC

[PATCH] D145505: [AArch64][SVE] Add svboolx2_t and svboolx4_t tuple types

2023-03-13 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto accepted this revision.
CarolineConcatto added a comment.
This revision is now accepted and ready to land.

Thank you Matt. It LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145505

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


[PATCH] D142587: [clang-tidy] Improved too-small-loop-variable with bit-field support

2023-03-13 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Thank you for information, I will look into this
Indeed test for this scenario is missing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142587

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


[PATCH] D145916: [clangd] Remove IWYU handling code that is used only for the old unused-include feature.

2023-03-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

The old implementation has been removed, this patch removes the clangd's IWYU
code that is only used for the old implmentation (include-cleaner library has
better support):

- IWYU export pragma
- IWYU keep pragma


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145916

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -216,7 +216,6 @@
   Field(&Inclusion::Written, "\"a.h\""),
   Field(&Inclusion::Resolved, testPath("a.h")),
   Field(&Inclusion::HeaderID, testing::Not(testing::Eq(std::nullopt))),
-  Field(&Inclusion::BehindPragmaKeep, true),
   Field(&Inclusion::FileKind, SrcMgr::CharacteristicKind::C_User;
 }
 
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -300,10 +300,9 @@
   ParsedAST AST = TU.build();
 
   EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty()));
-  // FIXME: This is not correct: foo.h is unused but is not diagnosed as such
-  // because we ignore headers with IWYU export pragmas for now.
   IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
-  EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
+  EXPECT_THAT(Findings.UnusedIncludes,
+  ElementsAre(Pointee(writtenInclusion("\"foo.h\"";
 }
 
 TEST(IncludeCleaner, NoDiagsForObjC) {
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -147,7 +147,6 @@
 MATCHER_P(resolved, Name, "") { return arg.Resolved == Name; }
 MATCHER_P(includeLine, N, "") { return arg.HashLine == N; }
 MATCHER_P(directive, D, "") { return arg.Directive == D; }
-MATCHER_P(hasPragmaKeep, H, "") { return arg.BehindPragmaKeep == H; }
 
 MATCHER_P2(Distance, File, D, "") {
   if (arg.getFirst() != File)
@@ -293,18 +292,6 @@
directive(tok::pp_include_next)));
 }
 
-TEST_F(HeadersTest, IWYUPragmaKeep) {
-  FS.Files[MainFile] = R"cpp(
-#include "bar.h" // IWYU pragma: keep
-#include "foo.h"
-)cpp";
-
-  EXPECT_THAT(
-  collectIncludes().MainFileIncludes,
-  UnorderedElementsAre(AllOf(written("\"foo.h\""), hasPragmaKeep(false)),
-   AllOf(written("\"bar.h\""), hasPragmaKeep(true;
-}
-
 TEST_F(HeadersTest, InsertInclude) {
   std::string Path = testPath("sub/bar.h");
   FS.Files[Path] = "";
@@ -457,33 +444,6 @@
   EXPECT_FALSE(Includes.isSelfContained(getID("pp_depend.h", Includes)));
 }
 
-TEST_F(HeadersTest, HasIWYUPragmas) {
-  FS.Files[MainFile] = R"cpp(
-#include "export.h"
-#include "begin_exports.h"
-#include "none.h"
-)cpp";
-  FS.Files["export.h"] = R"cpp(
-#pragma once
-#include "none.h" // IWYU pragma: export
-)cpp";
-  FS.Files["begin_exports.h"] = R"cpp(
-#pragma once
-// IWYU pragma: begin_exports
-#include "none.h"
-// IWYU pragma: end_exports
-)cpp";
-  FS.Files["none.h"] = R"cpp(
-#pragma once
-// Not a pragma.
-)cpp";
-
-  auto Includes = collectIncludes();
-  EXPECT_TRUE(Includes.hasIWYUExport(getID("export.h", Includes)));
-  EXPECT_TRUE(Includes.hasIWYUExport(getID("begin_exports.h", Includes)));
-  EXPECT_FALSE(Includes.hasIWYUExport(getID("none.h", Includes)));
-}
-
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -15,6 +15,7 @@
 #include "SourceCode.h"
 #include "URI.h"
 #include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
 #include "support/Logger.h"
 #include "support/Path.h"
@@ -90,10 +91,10 @@
 }
 
 static bool mayConsiderUnused(const Inclusion &Inc, ParsedAST &AST,
-  const Config &Cfg) {
-  if (Inc.BehindPragmaKeep)
+  const Config &Cfg,
+  const inclu

[PATCH] D145917: [clangd] Remove the IncludeStructure::isSelfContained API.

2023-03-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This API was merely used in the old unused-include implementation, with
the removal, this API is not used anymore.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145917

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/unittests/HeadersTests.cpp


Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -402,48 +402,6 @@
   Contains(AllOf(includeLine(2), written("";
 }
 
-TEST_F(HeadersTest, SelfContainedHeaders) {
-  // Including through non-builtin file has no effects.
-  FS.Files[MainFile] = R"cpp(
-#include "includeguarded.h"
-#include "nonguarded.h"
-#include "pp_depend.h"
-#include "pragmaguarded.h"
-#include "recursive.h"
-)cpp";
-  FS.Files["pragmaguarded.h"] = R"cpp(
-#pragma once
-)cpp";
-  FS.Files["includeguarded.h"] = R"cpp(
-#ifndef INCLUDE_GUARDED_H
-#define INCLUDE_GUARDED_H
-void foo();
-#endif // INCLUDE_GUARDED_H
-)cpp";
-  FS.Files["nonguarded.h"] = R"cpp(
-)cpp";
-  FS.Files["pp_depend.h"] = R"cpp(
-  #ifndef REQUIRED_PP_DIRECTIVE
-  # error You have to have PP directive set to include this one!
-  #endif
-)cpp";
-  FS.Files["recursive.h"] = R"cpp(
-  #ifndef RECURSIVE_H
-  #define RECURSIVE_H
-
-  #include "recursive.h"
-
-  #endif // RECURSIVE_H
-)cpp";
-
-  auto Includes = collectIncludes();
-  EXPECT_TRUE(Includes.isSelfContained(getID("pragmaguarded.h", Includes)));
-  EXPECT_TRUE(Includes.isSelfContained(getID("includeguarded.h", Includes)));
-  EXPECT_TRUE(Includes.isSelfContained(getID("recursive.h", Includes)));
-  EXPECT_FALSE(Includes.isSelfContained(getID("nonguarded.h", Includes)));
-  EXPECT_FALSE(Includes.isSelfContained(getID("pp_depend.h", Includes)));
-}
-
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Headers.h
===
--- clang-tools-extra/clangd/Headers.h
+++ clang-tools-extra/clangd/Headers.h
@@ -150,10 +150,6 @@
 return RealPathNames[static_cast(ID)];
   }
 
-  bool isSelfContained(HeaderID ID) const {
-return !NonSelfContained.contains(ID);
-  }
-
   // Return all transitively reachable files.
   llvm::ArrayRef allHeaders() const { return RealPathNames; }
 
@@ -196,9 +192,6 @@
   // and RealPathName and UniqueID are not preserved in
   // the preamble.
   llvm::DenseMap UIDToIndex;
-  // Contains HeaderIDs of all non self-contained entries in the
-  // IncludeStructure.
-  llvm::DenseSet NonSelfContained;
 
   // Maps written includes to indices in MainFileInclude for easier lookup by
   // spelling.
Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -105,17 +105,6 @@
   --Level;
   if (PrevFID == BuiltinFile)
 InBuiltinFile = false;
-  // At file exit time HeaderSearchInfo is valid and can be used to
-  // determine whether the file was a self-contained header or not.
-  if (const FileEntry *FE = SM.getFileEntryForID(PrevFID)) {
-// isSelfContainedHeader only returns true once the full header-guard
-// structure has been seen, i.e. when exiting the *outer* copy of the
-// file. So last result wins.
-if (tooling::isSelfContainedHeader(FE, SM, HeaderInfo))
-  Out->NonSelfContained.erase(*Out->getID(FE));
-else
-  Out->NonSelfContained.insert(*Out->getID(FE));
-  }
   break;
 }
 case PPCallbacks::RenameFile:


Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -402,48 +402,6 @@
   Contains(AllOf(includeLine(2), written("";
 }
 
-TEST_F(HeadersTest, SelfContainedHeaders) {
-  // Including through non-builtin file has no effects.
-  FS.Files[MainFile] = R"cpp(
-#include "includeguarded.h"
-#include "nonguarded.h"
-#include "pp_depend.h"
-#include "pragmaguarded.h"
-#include "recursive.h"
-)cpp";
-  FS.Files["pragmaguarded.h"] = R"cpp(
-#pragma once
-)cpp";
-  FS.Files["includeguarded.h"] = R"cpp(
-#ifndef INCLUDE_GUARDED_H
-#define INCLUDE_GUARDED_H
-void foo();
-#endif // INCLUDE_GUARDED_H
-)cpp";
-  FS.Files["nonguarded.h"] = R"cpp(
-)cpp";
-  FS.Files["pp_depend.h"] = R"cpp(
-  #ifndef REQUIRED_PP_DIRECTIVE
-  # error You have to have PP directive set to include this o

[PATCH] D145815: [Flang][Driver] Add support for fopenmp-is-device and fembed-offload-object to Flang ToolChain

2023-03-13 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak added inline comments.



Comment at: flang/test/Driver/omp-frontend-forwarding.f90:15
+! CHECK: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa" {{.*}} 
"-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
+! CHECK: "{{[^"]*}}clang-offload-packager" {{.*}} 
"--image=file={{.*}}gfx90a.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"
+! CHECK-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 
{{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.bc"

This unit test seems to be failing due to the pattern you've used here. 
Probably a simple fix to get working, this is the test output: 
https://reviews.llvm.org/harbormaster/unit/view/6153283/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145815

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


[PATCH] D145869: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-13 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/test/ExtractAPI/ignored-symbols-multifile.c:34
+//--- ignores-list1
+IGNORED_FILE1_1
+IGNORED_FILE1_2

This test doesn't check the symbol name sorting behavior across multiple files, 
which is crucial `APIIgnoresList::shouldIgnore(StringRef SymbolName)` because 
it uses binary search to find the symbol in the list. Would you be able to 
shuffle the order of the macros so that they aren't pre-sorted?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145869

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


[PATCH] D145069: [analyzer][NFC] Split the no state change logic and bug report suppression into two visitors

2023-03-13 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:449
   // No diagnostic if region was modified inside the frame.
   if (!CallExitLoc || isModifiedInFrame(N))
 return nullptr;

We also lost this, unfortunately, and this is kind of the point where we check 
whether the std function has anything to do with the uninitialized value (its 
been passed as parameter or something).

Please investigate whether losing this has any effect (and it very likely does).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145069

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


[PATCH] D144453: [clangd] Fix a bug in TweakTest::decorate()

2023-03-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Good catch, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144453

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


[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-13 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.
Herald added a subscriber: jobnoorman.

> Fix the issue of .o file generated by Flang with Flags info is 0x0 under 
> RISC-V.

TBH, I don't see how this is addressed in this patch. If that's something that 
this patch is intending to fix, then there should be a regression test added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

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


[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-13 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added inline comments.



Comment at: clang/lib/Driver/ToolChains/Flang.cpp:112-114
+  case llvm::Triple::riscv64:
+getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
+break;

jrtc27 wrote:
> mnadeem wrote:
> > identical code, could just do a fallthrough
> Why is this even conditional??
There could be other ways to do this. But it provided a way to understand the 
list of supported architectures.



Comment at: flang/test/Driver/target-cpu-features.f90:25-26
 
+! RUN: %flang --target=riscv32-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV32
+

32-bit architectures are generally not supported. This test could be misleading.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

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


[PATCH] D145919: [libc++] Add missing include in exception_ptr.h

2023-03-13 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.
hans added a reviewer: philnik.
hans added a project: libc++.
Herald added a project: All.
hans requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Windows builds were failing due to missing include for std::addressof after 
D145095 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145919

Files:
  libcxx/include/__exception/exception_ptr.h


Index: libcxx/include/__exception/exception_ptr.h
===
--- libcxx/include/__exception/exception_ptr.h
+++ libcxx/include/__exception/exception_ptr.h
@@ -11,6 +11,7 @@
 
 #include <__config>
 #include <__exception/operations.h>
+#include <__memory/addressof.h>
 #include 
 #include 
 


Index: libcxx/include/__exception/exception_ptr.h
===
--- libcxx/include/__exception/exception_ptr.h
+++ libcxx/include/__exception/exception_ptr.h
@@ -11,6 +11,7 @@
 
 #include <__config>
 #include <__exception/operations.h>
+#include <__memory/addressof.h>
 #include 
 #include 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145868: [clang][ASTImporter] Fix import of anonymous structures

2023-03-13 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

@balazske and I discussed, he will be commandeering this patch to improve.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145868

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


[PATCH] D145921: [clangd] Add missing unittests to build graph

2023-03-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: sammccall, hokein.
Herald added a subscriber: arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Also fix tests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145921

Files:
  clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
@@ -7,8 +7,6 @@
 //===--===//
 
 #include "TweakTesting.h"
-#include "gmock/gmock-matchers.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -20,24 +18,24 @@
 TEST_F(SpecialMembersTest, Test) {
   EXPECT_AVAILABLE("struct ^S {};");
   EXPECT_UNAVAILABLE("struct S { ^ };");
-  EXPECT_UNAVAILABLE("union ^U {};");
+  EXPECT_AVAILABLE("union ^U {};");
   EXPECT_AVAILABLE("struct ^S { S(const S&); S(S&&); };");
   EXPECT_UNAVAILABLE("struct ^S {"
  "S(const S&); S(S&&);"
  "S &operator=(S&&); S &operator=(const S&);"
  "};");
 
-  const char *Output = R"cpp(struct S{S(const S &) = default;
-  S(S &&) = default;
-  S &operator=(const S &) = default;
-  S &operator=(S &&) = default;
+  const char *Output = R"cpp(struct S{S(const S&) = default;
+S(S&&) = default;
+S &operator=(const S&) = default;
+S &operator=(S&&) = default;
 };)cpp";
   EXPECT_EQ(apply("struct ^S{};"), Output);
 
-  Output = R"cpp(struct S{S(const S &) = default;
-S(S &&) = default;
-S &operator=(const S &) = delete;
-S &operator=(S &&) = delete;
+  Output = R"cpp(struct S{S(const S&) = default;
+S(S&&) = default;
+S &operator=(const S&) = delete;
+S &operator=(S&&) = delete;
 int& ref;};)cpp";
   EXPECT_EQ(apply("struct ^S{int& ref;};"), Output);
 }
Index: clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
+++ clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
@@ -11,9 +11,9 @@
 #include "TestFS.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
-#include 
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -34,10 +34,10 @@
   FS.Files.erase(testPath("foo.cc"));
   }
 
-  std::string get(std::chrono::steady_clock::time_point FreshTime,
-  bool ExpectParse) const {
+  std::pair
+  get(std::chrono::steady_clock::time_point FreshTime) const {
 bool GotParse = false;
-bool GotRead;
+bool GotRead = false;
 std::string Result;
 read(
 FS, FreshTime,
@@ -49,12 +49,14 @@
   GotRead = true;
   Result = Value;
 });
-EXPECT_EQ(GotParse, ExpectParse);
 EXPECT_TRUE(GotRead);
-return Result;
+return {Result, GotParse};
   }
 };
 
+MATCHER_P(Parsed, Value, "") { return arg.second && arg.first == Value; }
+MATCHER_P(Cached, Value, "") { return !arg.second && arg.first == Value; }
+
 TEST(FileCacheTest, Invalidation) {
   TestCache C;
 
@@ -62,20 +64,20 @@
   auto MustBeFresh = StaleOK + std::chrono::hours(1);
 
   C.setContents("a");
-  EXPECT_EQ("a", C.get(StaleOK, /*ExpectParse=*/true)) << "Parsed first time";
-  EXPECT_EQ("a", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("a", C.get(MustBeFresh, /*ExpectParse=*/false)) << "Cached (stat)";
+  EXPECT_THAT(C.get(StaleOK), Parsed("a")) << "Parsed first time";
+  EXPECT_THAT(C.get(StaleOK), Cached("a")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh), Cached("a")) << "Cached (stat)";
   C.setContents("bb");
-  EXPECT_EQ("a", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("bb", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Size changed";
-  EXPECT_EQ("bb", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Cached (stat)";
+  EXPECT_THAT(C.get(StaleOK), Cached("a")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh), Parsed("bb")) << "Size changed";
+  EXPECT_THAT(C.get(MustBeFresh), Cached("bb")) << "Cached (stat)";
   C.setContents(nullptr);
-  EXPECT_EQ("bb", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Stat failed";
-  EXPECT_EQ("", C.get(MustBeFresh, /*ExpectParse=*/false)) << "Cached (404)";
+  EXPECT_THAT(C.get(StaleOK), Cached("bb")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh), Parsed("")) << "stat failed";
+  EXPECT_THAT(C.get(MustBeFresh), C

[PATCH] D145922: [clangd] Include SpecialMembersTests.cpp to the unittest.

2023-03-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This file was missing to be included in the unittest.
And the unittest was failing, this patch fixes some broken issues.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145922

Files:
  clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
@@ -7,17 +7,15 @@
 
//===--===//
 
 #include "TweakTesting.h"
-#include "gmock/gmock-matchers.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
-TWEAK_TEST(SpecialMembers);
+TWEAK_TEST(DeclareCopyMove);
 
-TEST_F(SpecialMembersTest, Test) {
+TEST_F(DeclareCopyMoveTest, Test) {
   EXPECT_AVAILABLE("struct ^S {};");
   EXPECT_UNAVAILABLE("struct S { ^ };");
   EXPECT_UNAVAILABLE("union ^U {};");
@@ -27,17 +25,17 @@
  "S &operator=(S&&); S &operator=(const S&);"
  "};");
 
-  const char *Output = R"cpp(struct S{S(const S &) = default;
-  S(S &&) = default;
-  S &operator=(const S &) = default;
-  S &operator=(S &&) = default;
+  const char *Output = R"cpp(struct S{S(const S&) = default;
+S(S&&) = default;
+S &operator=(const S&) = default;
+S &operator=(S&&) = default;
 };)cpp";
   EXPECT_EQ(apply("struct ^S{};"), Output);
 
-  Output = R"cpp(struct S{S(const S &) = default;
-S(S &&) = default;
-S &operator=(const S &) = delete;
-S &operator=(S &&) = delete;
+  Output = R"cpp(struct S{S(const S&) = default;
+S(S&&) = default;
+S &operator=(const S&) = delete;
+S &operator=(S&&) = delete;
 int& ref;};)cpp";
   EXPECT_EQ(apply("struct ^S{int& ref;};"), Output);
 }
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -130,6 +130,7 @@
   tweaks/RawStringLiteralTests.cpp
   tweaks/RemoveUsingNamespaceTests.cpp
   tweaks/ShowSelectionTreeTests.cpp
+  tweaks/SpecialMembersTests.cpp
   tweaks/SwapIfBranchesTests.cpp
   tweaks/TweakTesting.cpp
   tweaks/TweakTests.cpp
Index: clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
@@ -103,7 +103,8 @@
 // Trigger only on class definitions.
 if (auto *N = Inputs.ASTSelection.commonAncestor())
   Class = const_cast(N->ASTNode.get());
-if (!Class || !Class->isThisDeclarationADefinition())
+if (!Class || !Class->isThisDeclarationADefinition() ||
+!(Class->isClass() || Class->isStruct()))
   return false;
 
 // Tweak is only available if some members are missing.


Index: clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
@@ -7,17 +7,15 @@
 //===--===//
 
 #include "TweakTesting.h"
-#include "gmock/gmock-matchers.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
-TWEAK_TEST(SpecialMembers);
+TWEAK_TEST(DeclareCopyMove);
 
-TEST_F(SpecialMembersTest, Test) {
+TEST_F(DeclareCopyMoveTest, Test) {
   EXPECT_AVAILABLE("struct ^S {};");
   EXPECT_UNAVAILABLE("struct S { ^ };");
   EXPECT_UNAVAILABLE("union ^U {};");
@@ -27,17 +25,17 @@
  "S &operator=(S&&); S &operator=(const S&);"
  "};");
 
-  const char *Output = R"cpp(struct S{S(const S &) = default;
-  S(S &&) = default;
-  S &operator=(const S &) = default;
-  S &operator=(S &&) = default;
+  const char *Output = R"cpp(struct S{S(const S&) = default;
+S(S&&) = default;
+S &operator=(const S&) = default;
+S &operator=(S&&) = default;
 };)cpp";
   EXPECT_EQ(apply("struct ^S{};"), Output);
 
-  Output = R"cpp(struct S{S(const S &) = default;
-S(S &&) = default;
-S &operator=(const S &) = delete;
-S &operator=(S &&) = delete;
+  Output = R"cpp(struct S{S(const S&) = default;
+S(S&&) = default;
+S &operator=(const S&) = delete;
+S &operator=(

[PATCH] D144878: __builtin_FILE_NAME()

2023-03-13 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 504577.
karapsinie marked an inline comment as done.
karapsinie added a comment.

Fulfilled the wishes of cor3ntin


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

https://reviews.llvm.org/D144878

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/AST/Expr.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Preprocessor/feature_tests.cpp
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/Inputs/source-location-file.h
  clang/test/SemaCXX/source_location.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -259,6 +259,10 @@
  Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
  sourceLocExpr(hasBuiltinStr("__builtin_FILE");
+  testImport("void declToImport() { (void)__builtin_FILE_NAME(); }", Lang_CXX03,
+ "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(
+ sourceLocExpr(hasBuiltinStr("__builtin_FILE_NAME");
   testImport("void declToImport() { (void)__builtin_COLUMN(); }", Lang_CXX03,
  "", Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -84,6 +84,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
 
@@ -91,6 +92,7 @@
 static_assert(noexcept(__builtin_LINE()));
 static_assert(noexcept(__builtin_COLUMN()));
 static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
 static_assert(noexcept(__builtin_source_location()));
 
@@ -346,6 +348,54 @@
 
 } // namespace test_file
 
+//===--===//
+//__builtin_FILE_NAME()
+//===--===//
+
+namespace test_file_name {
+constexpr const char *test_file_name_simple(
+  const char *__f = __builtin_FILE_NAME()) {
+  return __f;
+}
+void test_function() {
+#line 900
+  static_assert(is_equal(test_file_name_simple(), __FILE_NAME__));
+  static_assert(is_equal(SLF::test_function_filename(), __FILE_NAME__), "");
+  static_assert(is_equal(SLF::test_function_filename_template(42),
+ __FILE_NAME__), "");
+
+  static_assert(is_equal(SLF::test_function_filename_indirect(),
+ SLF::global_info_filename), "");
+  static_assert(is_equal(SLF::test_function_filename_template_indirect(42),
+ SLF::global_info_filename), "");
+
+  static_assert(test_file_name_simple() != nullptr);
+  static_assert(is_equal(test_file_name_simple(), "source_location.cpp"));
+}
+
+void test_class() {
+#line 315
+  using SLF::TestClass;
+  constexpr TestClass Default;
+  constexpr TestClass InParam{42};
+  constexpr TestClass Template{42, 42};
+  constexpr auto *F = Default.info_file_name;
+  constexpr auto Char = F[0];
+  static_assert(is_equal(Default.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.ctor_info_file_name, __FILE_NAME__), "");
+}
+
+void test_aggr_class() {
+  using Agg = SLF::AggrClass<>;
+  constexpr Agg Default{};
+  constexpr Agg InitOne{42};
+  static_assert(is_equal(Default.init_info_file_name, __FILE_NAME__), "");
+  static_assert(is_equal(InitOne.init_info_file_name, __FILE_NAME__), "");
+}
+
+} // namespace test_file_name
+
 //===--===//
 //__builtin_FUNCTION()
 //===--===//
@@ -487,6 +537,7 @@
 #line 44 "test_file.c"
 static_assert(is_equal("test_file.c", __FILE__));
 static_assert(is_equal("test_file.c", __builtin_FILE()));
+static_assert(is_equal("test_file.c", __builtin_FILE_NAME()));
 static_assert(is_equal("test_file.c", SL::current().file()));
 static_assert(is_equal("test_file.c", SLF::test_function().file()));
 static_assert(is_equal(SLF::FILE, SLF::test_function_indirect().file()));
Index: clang/test/SemaCXX/Inputs/source-location-file.h
===
--- clang/test/SemaCXX/Inputs/source-location-file.h
+++ clang/test/SemaCXX/Inputs/source-location-file.h
@@ -4,8 +4,10 @@
 namespace source_lo

[PATCH] D145922: [clangd] Include SpecialMembersTests.cpp to the unittest.

2023-03-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein abandoned this revision.
hokein added a comment.

I didn't notice https://reviews.llvm.org/D145921, let's deprecate this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145922

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


[PATCH] D145921: [clangd] Add missing unittests to build graph

2023-03-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp:21
   EXPECT_UNAVAILABLE("struct S { ^ };");
-  EXPECT_UNAVAILABLE("union ^U {};");
+  EXPECT_AVAILABLE("union ^U {};");
   EXPECT_AVAILABLE("struct ^S { S(const S&); S(S&&); };");

the old behavior (UNAVAILABLE) seems more reasonable to me, I have a fix in 
https://reviews.llvm.org/D145922.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145921

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


[PATCH] D145869: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-13 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic updated this revision to Diff 504590.
Arsenic added a comment.

Update clang/test/ExtractAPI/ignored-symbols-multifile.c :
Shuffle the order of ignored symbols in test to check the sorting behaviour of 
APIIgnoresList


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145869

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/ExtractAPI/APIIgnoresList.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/ExtractAPI/APIIgnoresList.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/ignored-symbols-multifile.c

Index: clang/test/ExtractAPI/ignored-symbols-multifile.c
===
--- /dev/null
+++ clang/test/ExtractAPI/ignored-symbols-multifile.c
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   --extract-api-ignores=%t/ignores-list1,%t/ignores-list2,%t/ignores-list3 \
+// RUN:   -x c-header %t/input.h -verify -o - | FileCheck %t/input.h
+
+//--- input.h
+#define IGNORED_6_FILE1 6
+#define IGNORED_2_FILE1 2
+#define IGNORED_5_FILE1 5
+
+#define IGNORED_4_FILE2 4
+#define IGNORED_3_FILE2 3
+
+typedef double IGNORED_1_FILE3;
+typedef int IGNORED_7_FILE3;
+
+typedef float NonIgnored;
+
+// CHECK-NOT: IGNORED_1_FILE1
+// CHECK-NOT: IGNORED_2_FILE1
+// CHECK-NOT: IGNORED_3_FILE1
+
+// CHECK-NOT: IGNORED_4_FILE2
+// CHECK-NOT: IGNORED_5_FILE2
+
+// CHECK-NOT: IGNORED_1_FILE3
+// CHECK-NOT: IGNORED_7_FILE3
+// CHECK: NonIgnored
+
+// expected-no-diagnostics
+
+//--- ignores-list1
+IGNORED_6_FILE1
+IGNORED_2_FILE1
+IGNORED_5_FILE1
+
+//--- ignores-list2
+IGNORED_4_FILE2
+IGNORED_3_FILE2
+
+//--- ignores-list3
+IGNORED_1_FILE3
+IGNORED_7_FILE3
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -339,9 +339,9 @@
   Policy.AnonymousTagLocations = false;
   CI.getASTContext().setPrintingPolicy(Policy);
 
-  if (!CI.getFrontendOpts().ExtractAPIIgnoresFile.empty()) {
+  if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
 llvm::handleAllErrors(
-APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFile,
+APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFileList,
CI.getFileManager())
 .moveInto(IgnoresList),
 [&CI](const IgnoresFileNotFound &Err) {
Index: clang/lib/ExtractAPI/APIIgnoresList.cpp
===
--- clang/lib/ExtractAPI/APIIgnoresList.cpp
+++ clang/lib/ExtractAPI/APIIgnoresList.cpp
@@ -31,20 +31,29 @@
   return llvm::inconvertibleErrorCode();
 }
 
-Expected APIIgnoresList::create(StringRef IgnoresFilePath,
-FileManager &FM) {
-  auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
-  if (!BufferOrErr)
-return make_error(IgnoresFilePath);
-
-  auto Buffer = std::move(BufferOrErr.get());
+Expected
+APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
+   FileManager &FM) {
   SmallVector Lines;
-  Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, /*KeepEmpty*/ false);
-  // Symbol names don't have spaces in them, let's just remove these in case the
-  // input is slighlty malformed.
+  BufferList symbolBufferList;
+
+  for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {
+auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);
+
+if (!BufferOrErr)
+  return make_error(CurrentIgnoresFilePath);
+
+auto Buffer = std::move(BufferOrErr.get());
+Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,
+  /*KeepEmpty*/ false);
+symbolBufferList.push_back(std::move(Buffer));
+  }
+
+  // Symbol names don't have spaces in them, let's just remove these in case
+  // the input is slighlty malformed.
   transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });
   sort(Lines);
-  return APIIgnoresList(std::move(Lines), std::move(Buffer));
+  return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));
 }
 
 bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -453,8 +453,9 @@
   std::string ProductName;
 
   // Currently this is only used as part of the `-extract-api` action.
-  /// The file providing a list of APIs to ignore when extracting documentation
-  std::string ExtractAPIIgnoresFile;
+  // A comma seperated list of files providing a list of APIs to
+  // ignore when extracting documentation.
+  std::vec

[PATCH] D145505: [AArch64][SVE] Add svboolx2_t and svboolx4_t tuple types

2023-03-13 Thread Matt Devereau via Phabricator via cfe-commits
MattDevereau updated this revision to Diff 504588.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145505

Files:
  clang/include/clang/Basic/AArch64SVEACLETypes.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/test/CodeGen/svboolx2_t.cpp
  clang/test/CodeGen/svboolx4_t.cpp
  clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
  clang/utils/TableGen/SveEmitter.cpp

Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -1140,7 +1140,9 @@
   OS << "typedef __clang_svfloat16x4_t svfloat16x4_t;\n";
   OS << "typedef __clang_svfloat32x4_t svfloat32x4_t;\n";
   OS << "typedef __clang_svfloat64x4_t svfloat64x4_t;\n";
-  OS << "typedef __SVBool_t  svbool_t;\n\n";
+  OS << "typedef __SVBool_t  svbool_t;\n";
+  OS << "typedef __clang_svboolx2_t  svboolx2_t;\n";
+  OS << "typedef __clang_svboolx4_t  svboolx4_t;\n\n";
 
   OS << "typedef __clang_svbfloat16x2_t svbfloat16x2_t;\n";
   OS << "typedef __clang_svbfloat16x3_t svbfloat16x3_t;\n";
Index: clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
===
--- clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
+++ clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
@@ -108,3 +108,7 @@
 void f47(S<__clang_svbfloat16x3_t>) {}
 // CHECK: _Z3f481SI14svbfloat16x4_tE
 void f48(S<__clang_svbfloat16x4_t>) {}
+// CHECK: _Z3f491SI10svboolx2_tE
+void f49(S<__clang_svboolx2_t>) {}
+// CHECK: _Z3f501SI10svboolx4_tE
+void f50(S<__clang_svboolx4_t>) {}
Index: clang/test/CodeGen/svboolx4_t.cpp
===
--- /dev/null
+++ clang/test/CodeGen/svboolx4_t.cpp
@@ -0,0 +1,31 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -S -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: @_Z3foo10svboolx4_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARG_ADDR:%.*]] = alloca , align 2
+// CHECK-NEXT:store  [[ARG:%.*]], ptr [[ARG_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load , ptr [[ARG_ADDR]], align 2
+// CHECK-NEXT:ret  [[TMP0]]
+//
+__clang_svboolx4_t foo(__clang_svboolx4_t arg) { return arg; }
+
+__clang_svboolx4_t bar();
+// CHECK-LABEL: @_Z4foo2v(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = call  @_Z3barv()
+// CHECK-NEXT:ret  [[CALL]]
+//
+__clang_svboolx4_t foo2() { return bar(); }
+
+__clang_svboolx4_t bar2(__clang_svboolx4_t);
+// CHECK-LABEL: @_Z4foo310svboolx4_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARG_ADDR:%.*]] = alloca , align 2
+// CHECK-NEXT:store  [[ARG:%.*]], ptr [[ARG_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load , ptr [[ARG_ADDR]], align 2
+// CHECK-NEXT:[[CALL:%.*]] = call  @_Z4bar210svboolx4_t( [[TMP0]])
+// CHECK-NEXT:ret  [[CALL]]
+//
+__clang_svboolx4_t foo3(__clang_svboolx4_t arg) { return bar2(arg); }
+
Index: clang/test/CodeGen/svboolx2_t.cpp
===
--- /dev/null
+++ clang/test/CodeGen/svboolx2_t.cpp
@@ -0,0 +1,31 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -S -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: @_Z3foo10svboolx2_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARG_ADDR:%.*]] = alloca , align 2
+// CHECK-NEXT:store  [[ARG:%.*]], ptr [[ARG_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load , ptr [[ARG_ADDR]], align 2
+// CHECK-NEXT:ret  [[TMP0]]
+//
+__clang_svboolx2_t foo(__clang_svboolx2_t arg) { return arg; }
+
+__clang_svboolx2_t bar();
+// CHECK-LABEL: @_Z4foo2v(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = call  @_Z3barv()
+// CHECK-NEXT:ret  [[CALL]]
+//
+__clang_svboolx2_t foo2() { return bar(); }
+
+__clang_svboolx2_t bar2(__clang_svboolx2_t);
+// CHECK-LABEL: @_Z4foo310svboolx2_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARG_ADDR:%.*]] = alloca , align 2
+// CHECK-NEXT:store  [[ARG:%.*]], ptr [[ARG_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load , ptr [[ARG_ADDR]], align 2
+// CHECK-NEXT:[[CALL:%.*]] = call  @_Z4bar210svboolx2_t( [[TMP0]])
+// CHECK-NEXT:ret  [[CALL]]
+//
+__clang_svboolx2_t foo3(__clang_svboolx2_t arg) { return bar2(arg); }
+
Index: clang/lib/CodeGen/CodeGenTypes.cpp
===
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -596,6 +596,8 @@
 case BuiltinType::SveInt64x4:
 case BuiltinType::SveUint64x4:
 case BuiltinType::SveBool:
+case BuiltinType::SveBoolx2:
+case BuiltinType::SveBoolx4:
 cas

[PATCH] D145815: [Flang][Driver] Add support for fopenmp-is-device and fembed-offload-object to Flang ToolChain

2023-03-13 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 504592.
agozillon added a comment.

- [Flang][Driver] Try to fix failing omp-frontend-forwarding.f90 test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145815

Files:
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  clang/test/Driver/flang/flang-omp.f90
  flang/test/Driver/omp-frontend-forwarding.f90

Index: flang/test/Driver/omp-frontend-forwarding.f90
===
--- /dev/null
+++ flang/test/Driver/omp-frontend-forwarding.f90
@@ -0,0 +1,17 @@
+! REQUIRES: amdgpu-registered-target
+
+! Test that flang-new OpenMP and OpenMP offload related 
+! commands forward or expand to the appropriate commands 
+! for flang-new -fc1 as expected.
+
+! Testing fembed-offload-object and fopenmp-is-device
+! RUN: %flang -S -### %s -o %t 2>&1 \
+! RUN: -fopenmp --offload-arch=gfx90a \
+! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN:   | FileCheck %s
+! CHECK: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}}.f90"
+! CHECK-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
+! CHECK: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
+! CHECK: "{{[^"]*}}clang-offload-packager" {{.*}} "--image=file={{.*}}.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"
+! CHECK-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.bc"
+! CHECK: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}} "-fembed-offload-object={{.*}}.out" {{.*}}.bc"
Index: clang/test/Driver/flang/flang-omp.f90
===
--- /dev/null
+++ clang/test/Driver/flang/flang-omp.f90
@@ -0,0 +1,20 @@
+! Check that flang -fc1 is invoked when in --driver-mode=flang 
+! and the relevant openmp and openmp offload flags are utilised
+! and passed down correctly
+
+! Test regular -fopenmp with no offload
+! RUN: %clang --driver-mode=flang -### -fopenmp %s 2>&1 | FileCheck --check-prefixes=CHECK-OPENMP %s
+! CHECK-OPENMP: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}}.f90"
+! CHECK-OPENMP-NOT: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
+
+! Test regular -fopenmp with offload for basic fopenmp-is-device flag addition and correct fopenmp 
+! RUN: %clang --driver-mode=flang -### -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa %s 2>&1 | FileCheck --check-prefixes=CHECK-OPENMP-IS-DEVICE %s
+! CHECK-OPENMP-IS-DEVICE: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
+
+! Test -fembed-object, -fopenmp-is-device and -fopenmp carry through when offload-arch is provided 
+! RUN: %clang --driver-mode=flang -### -S --target=aarch64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a %s 2>&1 | FileCheck --check-prefixes=CHECK-EMBED-OBJ-WITH-OARCH %s
+! CHECK-EMBED-OBJ-WITH-OARCH: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}}.f90"
+! CHECK-EMBED-OBJ-WITH-OARCH-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
+! CHECK-EMBED-OBJ-WITH-OARCH: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
+! CHECK-EMBED-OBJ-WITH-OARCH-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.bc"
+! CHECK-EMBED-OBJ-WITH-OARCH: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}} "-fembed-offload-object={{.*}}.out" {{.*}}.bc"
Index: clang/lib/Driver/ToolChains/Flang.h
===
--- clang/lib/Driver/ToolChains/Flang.h
+++ clang/lib/Driver/ToolChains/Flang.h
@@ -56,6 +56,17 @@
   void addTargetOptions(const llvm::opt::ArgList &Args,
 llvm::opt::ArgStringList &CmdArgs) const;
 
+  /// Extract offload options from the driver arguments and add them to
+  /// the command arguments.
+  /// \param [in] C The current compilation for the driver invocation
+  /// \param [in] Inputs The input infomration on the current file inputs
+  /// \param [in] JA The job action
+  /// \param [in] Args The list of input driver arguments
+  /// \param [out] CmdArgs The list of output command arguments
+  void addOffloadOptions(Compilation &C, const InputInfoList &Inputs,
+ const JobAction &JA, const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const;
+
   /// Extract other compilation options from the driver arguments and add them
   /// to the command arguments.
   

[PATCH] D145869: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-13 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/test/ExtractAPI/ignored-symbols-multifile.c:27
+
+// CHECK-NOT: IGNORED_1_FILE3
+// CHECK-NOT: IGNORED_7_FILE3

Should this not be a 6?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145869

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


[PATCH] D145869: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-13 Thread Daniel Grumberg via Phabricator via cfe-commits
dang accepted this revision.
dang added a comment.
This revision is now accepted and ready to land.

LGTM once you fix the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145869

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


[PATCH] D145916: [clangd] Remove IWYU handling code that is used only for the old unused-include feature.

2023-03-13 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbe39daea846e: [clangd] Remove IWYU handling code that is 
used only for the old unused-include… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145916

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -216,7 +216,6 @@
   Field(&Inclusion::Written, "\"a.h\""),
   Field(&Inclusion::Resolved, testPath("a.h")),
   Field(&Inclusion::HeaderID, testing::Not(testing::Eq(std::nullopt))),
-  Field(&Inclusion::BehindPragmaKeep, true),
   Field(&Inclusion::FileKind, SrcMgr::CharacteristicKind::C_User;
 }
 
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -300,10 +300,9 @@
   ParsedAST AST = TU.build();
 
   EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty()));
-  // FIXME: This is not correct: foo.h is unused but is not diagnosed as such
-  // because we ignore headers with IWYU export pragmas for now.
   IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
-  EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
+  EXPECT_THAT(Findings.UnusedIncludes,
+  ElementsAre(Pointee(writtenInclusion("\"foo.h\"";
 }
 
 TEST(IncludeCleaner, NoDiagsForObjC) {
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -147,7 +147,6 @@
 MATCHER_P(resolved, Name, "") { return arg.Resolved == Name; }
 MATCHER_P(includeLine, N, "") { return arg.HashLine == N; }
 MATCHER_P(directive, D, "") { return arg.Directive == D; }
-MATCHER_P(hasPragmaKeep, H, "") { return arg.BehindPragmaKeep == H; }
 
 MATCHER_P2(Distance, File, D, "") {
   if (arg.getFirst() != File)
@@ -293,18 +292,6 @@
directive(tok::pp_include_next)));
 }
 
-TEST_F(HeadersTest, IWYUPragmaKeep) {
-  FS.Files[MainFile] = R"cpp(
-#include "bar.h" // IWYU pragma: keep
-#include "foo.h"
-)cpp";
-
-  EXPECT_THAT(
-  collectIncludes().MainFileIncludes,
-  UnorderedElementsAre(AllOf(written("\"foo.h\""), hasPragmaKeep(false)),
-   AllOf(written("\"bar.h\""), hasPragmaKeep(true;
-}
-
 TEST_F(HeadersTest, InsertInclude) {
   std::string Path = testPath("sub/bar.h");
   FS.Files[Path] = "";
@@ -457,33 +444,6 @@
   EXPECT_FALSE(Includes.isSelfContained(getID("pp_depend.h", Includes)));
 }
 
-TEST_F(HeadersTest, HasIWYUPragmas) {
-  FS.Files[MainFile] = R"cpp(
-#include "export.h"
-#include "begin_exports.h"
-#include "none.h"
-)cpp";
-  FS.Files["export.h"] = R"cpp(
-#pragma once
-#include "none.h" // IWYU pragma: export
-)cpp";
-  FS.Files["begin_exports.h"] = R"cpp(
-#pragma once
-// IWYU pragma: begin_exports
-#include "none.h"
-// IWYU pragma: end_exports
-)cpp";
-  FS.Files["none.h"] = R"cpp(
-#pragma once
-// Not a pragma.
-)cpp";
-
-  auto Includes = collectIncludes();
-  EXPECT_TRUE(Includes.hasIWYUExport(getID("export.h", Includes)));
-  EXPECT_TRUE(Includes.hasIWYUExport(getID("begin_exports.h", Includes)));
-  EXPECT_FALSE(Includes.hasIWYUExport(getID("none.h", Includes)));
-}
-
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -15,6 +15,7 @@
 #include "SourceCode.h"
 #include "URI.h"
 #include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
 #include "support/Logger.h"
 #include "support/Path.h"
@@ -90,10 +91,10 @@
 }
 
 static bool mayConsiderUnused(const Inclusion &Inc, ParsedAST &AST,
-  const Config &Cfg) {
-  if (Inc.BehindPragmaKeep)
+  const Config &Cfg,
+  const include_cleaner::PragmaIncludes *PI) {
+  if (PI && PI->shouldKeep(Inc.HashLine + 1))
 return false;
-
   // FIXME(kirillbobyrev): We currently do not support the umbrella headers.
   // System headers are

[clang-tools-extra] be39dae - [clangd] Remove IWYU handling code that is used only for the old unused-include feature.

2023-03-13 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-03-13T12:34:34+01:00
New Revision: be39daea846e6b5d43a8ee0c387feb0a556ff386

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

LOG: [clangd] Remove IWYU handling code that is used only for the old 
unused-include feature.

The old implementation has been removed, this patch removes the clangd's IWYU
code that is only used for the old implmentation (include-cleaner library has
better support):

- IWYU export pragma
- IWYU keep pragma

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

Added: 


Modified: 
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/Headers.h
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/unittests/HeadersTests.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
clang-tools-extra/clangd/unittests/PreambleTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Headers.cpp 
b/clang-tools-extra/clangd/Headers.cpp
index 7000c1cbf4513..35525a73a2fef 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -25,8 +25,7 @@
 namespace clang {
 namespace clangd {
 
-class IncludeStructure::RecordHeaders : public PPCallbacks,
-public CommentHandler {
+class IncludeStructure::RecordHeaders : public PPCallbacks {
 public:
   RecordHeaders(const CompilerInstance &CI, IncludeStructure *Out)
   : SM(CI.getSourceManager()),
@@ -61,8 +60,6 @@ class IncludeStructure::RecordHeaders : public PPCallbacks,
   SM.getLineNumber(SM.getFileID(HashLoc), Inc.HashOffset) - 1;
   Inc.FileKind = FileKind;
   Inc.Directive = IncludeTok.getIdentifierInfo()->getPPKeywordID();
-  if (LastPragmaKeepInMainFileLine == Inc.HashLine)
-Inc.BehindPragmaKeep = true;
   if (File) {
 IncludeStructure::HeaderID HID = Out->getOrCreateID(*File);
 Inc.HeaderID = static_cast(HID);
@@ -127,47 +124,6 @@ class IncludeStructure::RecordHeaders : public PPCallbacks,
 }
   }
 
-  bool HandleComment(Preprocessor &PP, SourceRange Range) override {
-auto Pragma =
-tooling::parseIWYUPragma(SM.getCharacterData(Range.getBegin()));
-if (!Pragma)
-  return false;
-
-if (inMainFile()) {
-  // Given:
-  //
-  // #include "foo.h"
-  // #include "bar.h" // IWYU pragma: keep
-  //
-  // The order in which the callbacks will be triggered:
-  //
-  // 1. InclusionDirective("foo.h")
-  // 2. handleCommentInMainFile("// IWYU pragma: keep")
-  // 3. InclusionDirective("bar.h")
-  //
-  // This code stores the last location of "IWYU pragma: keep" (or export)
-  // comment in the main file, so that when InclusionDirective is called, 
it
-  // will know that the next inclusion is behind the IWYU pragma.
-  // FIXME: Support "IWYU pragma: begin_exports" and "IWYU pragma:
-  // end_exports".
-  if (!Pragma->startswith("export") && !Pragma->startswith("keep"))
-return false;
-  unsigned Offset = SM.getFileOffset(Range.getBegin());
-  LastPragmaKeepInMainFileLine =
-  SM.getLineNumber(SM.getMainFileID(), Offset) - 1;
-} else {
-  // Memorize headers that have export pragmas in them. Include Cleaner
-  // does not support them properly yet, so they will be not marked as
-  // unused.
-  // FIXME: Once IncludeCleaner supports export pragmas, remove this.
-  if (!Pragma->startswith("export") && 
!Pragma->startswith("begin_exports"))
-return false;
-  Out->HasIWYUExport.insert(
-  *Out->getID(SM.getFileEntryForID(SM.getFileID(Range.getBegin();
-}
-return false;
-  }
-
 private:
   // Keeps track of include depth for the current file. It's 1 for main file.
   int Level = 0;
@@ -181,9 +137,6 @@ class IncludeStructure::RecordHeaders : public PPCallbacks,
   bool InBuiltinFile = false;
 
   IncludeStructure *Out;
-
-  // The last line "IWYU pragma: keep" was seen in the main file, 0-indexed.
-  int LastPragmaKeepInMainFileLine = -1;
 };
 
 bool isLiteralInclude(llvm::StringRef Include) {
@@ -234,7 +187,6 @@ void IncludeStructure::collect(const CompilerInstance &CI) {
   auto &SM = CI.getSourceManager();
   MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());
   auto Collector = std::make_unique(CI, this);
-  CI.getPreprocessor().addCommentHandler(Collector.get());
   CI.getPreprocessor().addPPCallbacks(std::move(Collector));
 }
 

diff  --git a/clang-tools-extra/clangd/Headers.h 
b/clang-tools-extra/clangd/Headers.h
index a21ea851831aa..8abea21a98e0f 100644
--- a/clang-tools-extra/clangd/Headers.h
+++ b/clang-tools-extra/clangd/Headers.h
@@ -73,7 +73,6 @@ struct Inclusion {
   int HashLine = 0;// Line number containing the dir

[PATCH] D145869: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-13 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic updated this revision to Diff 504594.
Arsenic added a comment.

fix test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145869

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/ExtractAPI/APIIgnoresList.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/ExtractAPI/APIIgnoresList.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/ignored-symbols-multifile.c

Index: clang/test/ExtractAPI/ignored-symbols-multifile.c
===
--- /dev/null
+++ clang/test/ExtractAPI/ignored-symbols-multifile.c
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   --extract-api-ignores=%t/ignores-list1,%t/ignores-list2,%t/ignores-list3 \
+// RUN:   -x c-header %t/input.h -verify -o - | FileCheck %t/input.h
+
+//--- input.h
+#define IGNORED_6_FILE1 6
+#define IGNORED_2_FILE1 2
+#define IGNORED_5_FILE1 5
+
+#define IGNORED_4_FILE2 4
+#define IGNORED_3_FILE2 3
+
+typedef double IGNORED_1_FILE3;
+typedef int IGNORED_7_FILE3;
+
+typedef float NonIgnored;
+
+// CHECK-NOT: IGNORED_6_FILE1
+// CHECK-NOT: IGNORED_2_FILE1
+// CHECK-NOT: IGNORED_5_FILE1
+
+// CHECK-NOT: IGNORED_4_FILE2
+// CHECK-NOT: IGNORED_3_FILE2
+
+// CHECK-NOT: IGNORED_1_FILE3
+// CHECK-NOT: IGNORED_7_FILE3
+// CHECK: NonIgnored
+
+// expected-no-diagnostics
+
+//--- ignores-list1
+IGNORED_6_FILE1
+IGNORED_2_FILE1
+IGNORED_5_FILE1
+
+//--- ignores-list2
+IGNORED_4_FILE2
+IGNORED_3_FILE2
+
+//--- ignores-list3
+IGNORED_1_FILE3
+IGNORED_7_FILE3
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -339,9 +339,9 @@
   Policy.AnonymousTagLocations = false;
   CI.getASTContext().setPrintingPolicy(Policy);
 
-  if (!CI.getFrontendOpts().ExtractAPIIgnoresFile.empty()) {
+  if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
 llvm::handleAllErrors(
-APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFile,
+APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFileList,
CI.getFileManager())
 .moveInto(IgnoresList),
 [&CI](const IgnoresFileNotFound &Err) {
Index: clang/lib/ExtractAPI/APIIgnoresList.cpp
===
--- clang/lib/ExtractAPI/APIIgnoresList.cpp
+++ clang/lib/ExtractAPI/APIIgnoresList.cpp
@@ -31,20 +31,29 @@
   return llvm::inconvertibleErrorCode();
 }
 
-Expected APIIgnoresList::create(StringRef IgnoresFilePath,
-FileManager &FM) {
-  auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
-  if (!BufferOrErr)
-return make_error(IgnoresFilePath);
-
-  auto Buffer = std::move(BufferOrErr.get());
+Expected
+APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
+   FileManager &FM) {
   SmallVector Lines;
-  Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, /*KeepEmpty*/ false);
-  // Symbol names don't have spaces in them, let's just remove these in case the
-  // input is slighlty malformed.
+  BufferList symbolBufferList;
+
+  for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {
+auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);
+
+if (!BufferOrErr)
+  return make_error(CurrentIgnoresFilePath);
+
+auto Buffer = std::move(BufferOrErr.get());
+Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,
+  /*KeepEmpty*/ false);
+symbolBufferList.push_back(std::move(Buffer));
+  }
+
+  // Symbol names don't have spaces in them, let's just remove these in case
+  // the input is slighlty malformed.
   transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });
   sort(Lines);
-  return APIIgnoresList(std::move(Lines), std::move(Buffer));
+  return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));
 }
 
 bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -453,8 +453,9 @@
   std::string ProductName;
 
   // Currently this is only used as part of the `-extract-api` action.
-  /// The file providing a list of APIs to ignore when extracting documentation
-  std::string ExtractAPIIgnoresFile;
+  // A comma seperated list of files providing a list of APIs to
+  // ignore when extracting documentation.
+  std::vector ExtractAPIIgnoresFileList;
 
   /// Args to pass to the plugins
   std::map> PluginArgs;
Index: clang/include/clang/ExtractAPI/APIIgnoresList

[clang-tools-extra] fd299a7 - [clangd] Remove the IncludeStructure::isSelfContained API.

2023-03-13 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-03-13T12:37:38+01:00
New Revision: fd299a7880ae80911001590242e2cbdb55f24a37

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

LOG: [clangd] Remove the IncludeStructure::isSelfContained API.

This API was merely used in the old unused-include implementation, with
the removal, this API is not used anymore.

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

Added: 


Modified: 
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/Headers.h
clang-tools-extra/clangd/unittests/HeadersTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Headers.cpp 
b/clang-tools-extra/clangd/Headers.cpp
index 35525a73a2fe..8a71f0ece17c 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -105,17 +105,6 @@ class IncludeStructure::RecordHeaders : public PPCallbacks 
{
   --Level;
   if (PrevFID == BuiltinFile)
 InBuiltinFile = false;
-  // At file exit time HeaderSearchInfo is valid and can be used to
-  // determine whether the file was a self-contained header or not.
-  if (const FileEntry *FE = SM.getFileEntryForID(PrevFID)) {
-// isSelfContainedHeader only returns true once the full header-guard
-// structure has been seen, i.e. when exiting the *outer* copy of the
-// file. So last result wins.
-if (tooling::isSelfContainedHeader(FE, SM, HeaderInfo))
-  Out->NonSelfContained.erase(*Out->getID(FE));
-else
-  Out->NonSelfContained.insert(*Out->getID(FE));
-  }
   break;
 }
 case PPCallbacks::RenameFile:

diff  --git a/clang-tools-extra/clangd/Headers.h 
b/clang-tools-extra/clangd/Headers.h
index 8abea21a98e0..f6aeab1dbfd3 100644
--- a/clang-tools-extra/clangd/Headers.h
+++ b/clang-tools-extra/clangd/Headers.h
@@ -150,10 +150,6 @@ class IncludeStructure {
 return RealPathNames[static_cast(ID)];
   }
 
-  bool isSelfContained(HeaderID ID) const {
-return !NonSelfContained.contains(ID);
-  }
-
   // Return all transitively reachable files.
   llvm::ArrayRef allHeaders() const { return RealPathNames; }
 
@@ -196,9 +192,6 @@ class IncludeStructure {
   // and RealPathName and UniqueID are not preserved in
   // the preamble.
   llvm::DenseMap UIDToIndex;
-  // Contains HeaderIDs of all non self-contained entries in the
-  // IncludeStructure.
-  llvm::DenseSet NonSelfContained;
 
   // Maps written includes to indices in MainFileInclude for easier lookup by
   // spelling.

diff  --git a/clang-tools-extra/clangd/unittests/HeadersTests.cpp 
b/clang-tools-extra/clangd/unittests/HeadersTests.cpp
index 728b06db684d..8c0eae6bb3cc 100644
--- a/clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -402,48 +402,6 @@ TEST_F(HeadersTest, PresumedLocations) {
   Contains(AllOf(includeLine(2), written("";
 }
 
-TEST_F(HeadersTest, SelfContainedHeaders) {
-  // Including through non-builtin file has no effects.
-  FS.Files[MainFile] = R"cpp(
-#include "includeguarded.h"
-#include "nonguarded.h"
-#include "pp_depend.h"
-#include "pragmaguarded.h"
-#include "recursive.h"
-)cpp";
-  FS.Files["pragmaguarded.h"] = R"cpp(
-#pragma once
-)cpp";
-  FS.Files["includeguarded.h"] = R"cpp(
-#ifndef INCLUDE_GUARDED_H
-#define INCLUDE_GUARDED_H
-void foo();
-#endif // INCLUDE_GUARDED_H
-)cpp";
-  FS.Files["nonguarded.h"] = R"cpp(
-)cpp";
-  FS.Files["pp_depend.h"] = R"cpp(
-  #ifndef REQUIRED_PP_DIRECTIVE
-  # error You have to have PP directive set to include this one!
-  #endif
-)cpp";
-  FS.Files["recursive.h"] = R"cpp(
-  #ifndef RECURSIVE_H
-  #define RECURSIVE_H
-
-  #include "recursive.h"
-
-  #endif // RECURSIVE_H
-)cpp";
-
-  auto Includes = collectIncludes();
-  EXPECT_TRUE(Includes.isSelfContained(getID("pragmaguarded.h", Includes)));
-  EXPECT_TRUE(Includes.isSelfContained(getID("includeguarded.h", Includes)));
-  EXPECT_TRUE(Includes.isSelfContained(getID("recursive.h", Includes)));
-  EXPECT_FALSE(Includes.isSelfContained(getID("nonguarded.h", Includes)));
-  EXPECT_FALSE(Includes.isSelfContained(getID("pp_depend.h", Includes)));
-}
-
 } // namespace
 } // namespace clangd
 } // namespace clang



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


[PATCH] D145917: [clangd] Remove the IncludeStructure::isSelfContained API.

2023-03-13 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd299a7880ae: [clangd] Remove the 
IncludeStructure::isSelfContained API. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145917

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/unittests/HeadersTests.cpp


Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -402,48 +402,6 @@
   Contains(AllOf(includeLine(2), written("";
 }
 
-TEST_F(HeadersTest, SelfContainedHeaders) {
-  // Including through non-builtin file has no effects.
-  FS.Files[MainFile] = R"cpp(
-#include "includeguarded.h"
-#include "nonguarded.h"
-#include "pp_depend.h"
-#include "pragmaguarded.h"
-#include "recursive.h"
-)cpp";
-  FS.Files["pragmaguarded.h"] = R"cpp(
-#pragma once
-)cpp";
-  FS.Files["includeguarded.h"] = R"cpp(
-#ifndef INCLUDE_GUARDED_H
-#define INCLUDE_GUARDED_H
-void foo();
-#endif // INCLUDE_GUARDED_H
-)cpp";
-  FS.Files["nonguarded.h"] = R"cpp(
-)cpp";
-  FS.Files["pp_depend.h"] = R"cpp(
-  #ifndef REQUIRED_PP_DIRECTIVE
-  # error You have to have PP directive set to include this one!
-  #endif
-)cpp";
-  FS.Files["recursive.h"] = R"cpp(
-  #ifndef RECURSIVE_H
-  #define RECURSIVE_H
-
-  #include "recursive.h"
-
-  #endif // RECURSIVE_H
-)cpp";
-
-  auto Includes = collectIncludes();
-  EXPECT_TRUE(Includes.isSelfContained(getID("pragmaguarded.h", Includes)));
-  EXPECT_TRUE(Includes.isSelfContained(getID("includeguarded.h", Includes)));
-  EXPECT_TRUE(Includes.isSelfContained(getID("recursive.h", Includes)));
-  EXPECT_FALSE(Includes.isSelfContained(getID("nonguarded.h", Includes)));
-  EXPECT_FALSE(Includes.isSelfContained(getID("pp_depend.h", Includes)));
-}
-
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Headers.h
===
--- clang-tools-extra/clangd/Headers.h
+++ clang-tools-extra/clangd/Headers.h
@@ -150,10 +150,6 @@
 return RealPathNames[static_cast(ID)];
   }
 
-  bool isSelfContained(HeaderID ID) const {
-return !NonSelfContained.contains(ID);
-  }
-
   // Return all transitively reachable files.
   llvm::ArrayRef allHeaders() const { return RealPathNames; }
 
@@ -196,9 +192,6 @@
   // and RealPathName and UniqueID are not preserved in
   // the preamble.
   llvm::DenseMap UIDToIndex;
-  // Contains HeaderIDs of all non self-contained entries in the
-  // IncludeStructure.
-  llvm::DenseSet NonSelfContained;
 
   // Maps written includes to indices in MainFileInclude for easier lookup by
   // spelling.
Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -105,17 +105,6 @@
   --Level;
   if (PrevFID == BuiltinFile)
 InBuiltinFile = false;
-  // At file exit time HeaderSearchInfo is valid and can be used to
-  // determine whether the file was a self-contained header or not.
-  if (const FileEntry *FE = SM.getFileEntryForID(PrevFID)) {
-// isSelfContainedHeader only returns true once the full header-guard
-// structure has been seen, i.e. when exiting the *outer* copy of the
-// file. So last result wins.
-if (tooling::isSelfContainedHeader(FE, SM, HeaderInfo))
-  Out->NonSelfContained.erase(*Out->getID(FE));
-else
-  Out->NonSelfContained.insert(*Out->getID(FE));
-  }
   break;
 }
 case PPCallbacks::RenameFile:


Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -402,48 +402,6 @@
   Contains(AllOf(includeLine(2), written("";
 }
 
-TEST_F(HeadersTest, SelfContainedHeaders) {
-  // Including through non-builtin file has no effects.
-  FS.Files[MainFile] = R"cpp(
-#include "includeguarded.h"
-#include "nonguarded.h"
-#include "pp_depend.h"
-#include "pragmaguarded.h"
-#include "recursive.h"
-)cpp";
-  FS.Files["pragmaguarded.h"] = R"cpp(
-#pragma once
-)cpp";
-  FS.Files["includeguarded.h"] = R"cpp(
-#ifndef INCLUDE_GUARDED_H
-#define INCLUDE_GUARDED_H
-void foo();
-#endif // INCLUDE_GUARDED_H
-)cpp";
-  FS.Files["nonguarded.h"] = R"cpp(
-)cpp";
-  FS.Files["pp_depend.h"] = R"cpp(
-  #ifndef REQUIRED_PP_DIRECTIVE
-  # error You have to have PP directive set to include this one!
-  #endif
-)cpp";
-  FS.Files["recursive.h"] = R"cpp(
-  #ifndef RE

[PATCH] D127184: [clangd] Add to header map

2023-03-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

we can also handle them through the stdlib symbol mappings, see 
https://github.com/llvm/llvm-project/issues/61373


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127184

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


[PATCH] D145921: [clangd] Add missing unittests to build graph

2023-03-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 504597.
kadircet marked an inline comment as done.
kadircet added a comment.

- Disable special members tweaks on unions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145921

Files:
  clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
@@ -7,8 +7,6 @@
 //===--===//
 
 #include "TweakTesting.h"
-#include "gmock/gmock-matchers.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -27,17 +25,17 @@
  "S &operator=(S&&); S &operator=(const S&);"
  "};");
 
-  const char *Output = R"cpp(struct S{S(const S &) = default;
-  S(S &&) = default;
-  S &operator=(const S &) = default;
-  S &operator=(S &&) = default;
+  const char *Output = R"cpp(struct S{S(const S&) = default;
+S(S&&) = default;
+S &operator=(const S&) = default;
+S &operator=(S&&) = default;
 };)cpp";
   EXPECT_EQ(apply("struct ^S{};"), Output);
 
-  Output = R"cpp(struct S{S(const S &) = default;
-S(S &&) = default;
-S &operator=(const S &) = delete;
-S &operator=(S &&) = delete;
+  Output = R"cpp(struct S{S(const S&) = default;
+S(S&&) = default;
+S &operator=(const S&) = delete;
+S &operator=(S&&) = delete;
 int& ref;};)cpp";
   EXPECT_EQ(apply("struct ^S{int& ref;};"), Output);
 }
Index: clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
+++ clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
@@ -11,9 +11,9 @@
 #include "TestFS.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
-#include 
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -34,10 +34,10 @@
   FS.Files.erase(testPath("foo.cc"));
   }
 
-  std::string get(std::chrono::steady_clock::time_point FreshTime,
-  bool ExpectParse) const {
+  std::pair
+  get(std::chrono::steady_clock::time_point FreshTime) const {
 bool GotParse = false;
-bool GotRead;
+bool GotRead = false;
 std::string Result;
 read(
 FS, FreshTime,
@@ -49,12 +49,14 @@
   GotRead = true;
   Result = Value;
 });
-EXPECT_EQ(GotParse, ExpectParse);
 EXPECT_TRUE(GotRead);
-return Result;
+return {Result, GotParse};
   }
 };
 
+MATCHER_P(Parsed, Value, "") { return arg.second && arg.first == Value; }
+MATCHER_P(Cached, Value, "") { return !arg.second && arg.first == Value; }
+
 TEST(FileCacheTest, Invalidation) {
   TestCache C;
 
@@ -62,20 +64,20 @@
   auto MustBeFresh = StaleOK + std::chrono::hours(1);
 
   C.setContents("a");
-  EXPECT_EQ("a", C.get(StaleOK, /*ExpectParse=*/true)) << "Parsed first time";
-  EXPECT_EQ("a", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("a", C.get(MustBeFresh, /*ExpectParse=*/false)) << "Cached (stat)";
+  EXPECT_THAT(C.get(StaleOK), Parsed("a")) << "Parsed first time";
+  EXPECT_THAT(C.get(StaleOK), Cached("a")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh), Cached("a")) << "Cached (stat)";
   C.setContents("bb");
-  EXPECT_EQ("a", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("bb", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Size changed";
-  EXPECT_EQ("bb", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Cached (stat)";
+  EXPECT_THAT(C.get(StaleOK), Cached("a")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh), Parsed("bb")) << "Size changed";
+  EXPECT_THAT(C.get(MustBeFresh), Cached("bb")) << "Cached (stat)";
   C.setContents(nullptr);
-  EXPECT_EQ("bb", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Stat failed";
-  EXPECT_EQ("", C.get(MustBeFresh, /*ExpectParse=*/false)) << "Cached (404)";
+  EXPECT_THAT(C.get(StaleOK), Cached("bb")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh), Parsed("")) << "stat failed";
+  EXPECT_THAT(C.get(MustBeFresh), Cached("")) << "Cached (404)";
   C.setContents("bb"); // Match the previous stat values!
-  EXPECT_EQ("", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("bb", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Size changed";
+  EXPECT_THAT(C.get(StaleOK), Cached("")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh), Parsed("bb")) << "Size changed";
 }
 
 } // namespace
Index: clang-tools

[PATCH] D145921: [clangd] Add missing unittests to build graph

2023-03-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked an inline comment as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp:21
   EXPECT_UNAVAILABLE("struct S { ^ };");
-  EXPECT_UNAVAILABLE("union ^U {};");
+  EXPECT_AVAILABLE("union ^U {};");
   EXPECT_AVAILABLE("struct ^S { S(const S&); S(S&&); };");

hokein wrote:
> the old behavior (UNAVAILABLE) seems more reasonable to me, I have a fix in 
> https://reviews.llvm.org/D145922.
i don't see much reason for disabling on unions, but don't have a strong 
preference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145921

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


[PATCH] D145868: [clang][ASTImporter] Fix import of anonymous structures

2023-03-13 Thread Balázs Kéri via Phabricator via cfe-commits
balazske commandeered this revision.
balazske edited reviewers, added: vabridgers; removed: balazske.
balazske added a comment.
Herald added subscribers: steakhal, Szelethus, dkrupp.

My opinion is that we can not omit importing the "underlying type". The 
`TypedefType` has the type of the declaration (type of `getDecl()`) and the 
"underlying type" that may be different (this is the thing that comes from 
commit D133468 ). This is exactly different 
if `TypedefType::typeMatchesDecl()` (returns a stored value in `TypedefDecl`) 
returns true. In this case the type object is stored in the `TypedefDecl` node 
and is not the same as the type of declaration `getDecl()`. If function 
`getTypeDeclType` is used it creates the typedef type always with the type of 
`getDecl()` and the `typeMatchesDecl` will always return true for this type 
even if at the to-be-imported type it was false.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145868

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


[PATCH] D145921: [clangd] Add missing unittests to build graph

2023-03-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

doh, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145921

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


[PATCH] D143436: [clangd] Move standard options adaptor to CommandMangler

2023-03-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!




Comment at: clang-tools-extra/clangd/CompileCommands.cpp:199
+  // use/change working directory, which ExpandResponseFiles doesn't).
+  FS = llvm::vfs::getRealFileSystem();
+}

DmitryPolukhin wrote:
> kadircet wrote:
> > getting real filesystem is cheap, no need to make this part of the state, 
> > just inline it into `tooling::addExpandedResponseFiles` call.
> We need version of `tooling::addExpandedResponseFiles` with FS as an argument 
> for testing at least, see 
> https://github.com/llvm/llvm-project/blob/main/clang/unittests/Tooling/CompilationDatabaseTest.cpp#L968
>  switching it to using real filesystem IMHO makes things worse. So moved this 
> code to the call site.
> So moved this code to the call site.

I was also trying to say that. so all good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

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


[clang-tools-extra] e26dad0 - [clangd] Add missing unittests to build graph

2023-03-13 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-03-13T13:06:31+01:00
New Revision: e26dad0a661e055076002d0de4ceb713b8ca6917

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

LOG: [clangd] Add missing unittests to build graph

Also fix tests

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
clang-tools-extra/clangd/unittests/CMakeLists.txt
clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
index e15605191c75..0b86b4842270 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
@@ -8,10 +8,7 @@
 #include "ParsedAST.h"
 #include "refactor/InsertionPoint.h"
 #include "refactor/Tweak.h"
-#include "support/Logger.h"
 #include "clang/AST/DeclCXX.h"
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceManager.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/StringRef.h"
@@ -84,7 +81,7 @@ std::string buildSpecialMemberDeclarations(const 
CXXRecordDecl &Class) {
 //  - to understand the implicit behavior
 //  - to avoid relying on the implicit behavior
 //  - as a baseline for explicit modification
-class DeclareCopyMove : public Tweak {
+class SpecialMembers : public Tweak {
 public:
   const char *id() const final;
   llvm::StringLiteral kind() const override {
@@ -103,7 +100,7 @@ class DeclareCopyMove : public Tweak {
 // Trigger only on class definitions.
 if (auto *N = Inputs.ASTSelection.commonAncestor())
   Class = const_cast(N->ASTNode.get());
-if (!Class || !Class->isThisDeclarationADefinition())
+if (!Class || !Class->isThisDeclarationADefinition() || Class->isUnion())
   return false;
 
 // Tweak is only available if some members are missing.
@@ -146,7 +143,7 @@ class DeclareCopyMove : public Tweak {
   bool NeedCopy = false, NeedMove = false;
   CXXRecordDecl *Class = nullptr;
 };
-REGISTER_TWEAK(DeclareCopyMove)
+REGISTER_TWEAK(SpecialMembers)
 
 } // namespace
 } // namespace clangd

diff  --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index a68d8cb0b78f..39fd6ee85378 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -104,12 +104,13 @@ add_unittest(ClangdUnitTests ClangdTests
 
   support/CancellationTests.cpp
   support/ContextTests.cpp
+  support/FileCacheTests.cpp
   support/FunctionTests.cpp
   support/MarkupTests.cpp
   support/MemoryTreeTests.cpp
   support/PathTests.cpp
-  support/ThreadingTests.cpp
   support/TestTracer.cpp
+  support/ThreadingTests.cpp
   support/TraceTests.cpp
 
   tweaks/AddUsingTests.cpp
@@ -130,6 +131,7 @@ add_unittest(ClangdUnitTests ClangdTests
   tweaks/RawStringLiteralTests.cpp
   tweaks/RemoveUsingNamespaceTests.cpp
   tweaks/ShowSelectionTreeTests.cpp
+  tweaks/SpecialMembersTests.cpp
   tweaks/SwapIfBranchesTests.cpp
   tweaks/TweakTesting.cpp
   tweaks/TweakTests.cpp

diff  --git a/clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp 
b/clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
index 840cad623d77..3cdaceb5cf23 100644
--- a/clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
+++ b/clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
@@ -11,9 +11,9 @@
 #include "TestFS.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
-#include 
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -34,10 +34,10 @@ class TestCache : public FileCache {
   FS.Files.erase(testPath("foo.cc"));
   }
 
-  std::string get(std::chrono::steady_clock::time_point FreshTime,
-  bool ExpectParse) const {
+  std::pair
+  get(std::chrono::steady_clock::time_point FreshTime) const {
 bool GotParse = false;
-bool GotRead;
+bool GotRead = false;
 std::string Result;
 read(
 FS, FreshTime,
@@ -49,12 +49,14 @@ class TestCache : public FileCache {
   GotRead = true;
   Result = Value;
 });
-EXPECT_EQ(GotParse, ExpectParse);
 EXPECT_TRUE(GotRead);
-return Result;
+return {Result, GotParse};
   }
 };
 
+MATCHER_P(Parsed, Value, "") { return arg.second && arg.first == Value; }
+MATCHER_P(Cached, Value, "") { return !arg.second && arg.first == Value; }
+
 TEST(FileCacheTest, Invalidation) {
   TestCache C;
 
@@ -62,20 +64,20 @@ TEST(FileCacheTest, Invalidation) {
   auto MustBeFresh = StaleOK + std::c

[PATCH] D145921: [clangd] Add missing unittests to build graph

2023-03-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe26dad0a661e: [clangd] Add missing unittests to build graph 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145921

Files:
  clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
@@ -7,8 +7,6 @@
 //===--===//
 
 #include "TweakTesting.h"
-#include "gmock/gmock-matchers.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -27,17 +25,17 @@
  "S &operator=(S&&); S &operator=(const S&);"
  "};");
 
-  const char *Output = R"cpp(struct S{S(const S &) = default;
-  S(S &&) = default;
-  S &operator=(const S &) = default;
-  S &operator=(S &&) = default;
+  const char *Output = R"cpp(struct S{S(const S&) = default;
+S(S&&) = default;
+S &operator=(const S&) = default;
+S &operator=(S&&) = default;
 };)cpp";
   EXPECT_EQ(apply("struct ^S{};"), Output);
 
-  Output = R"cpp(struct S{S(const S &) = default;
-S(S &&) = default;
-S &operator=(const S &) = delete;
-S &operator=(S &&) = delete;
+  Output = R"cpp(struct S{S(const S&) = default;
+S(S&&) = default;
+S &operator=(const S&) = delete;
+S &operator=(S&&) = delete;
 int& ref;};)cpp";
   EXPECT_EQ(apply("struct ^S{int& ref;};"), Output);
 }
Index: clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
+++ clang-tools-extra/clangd/unittests/support/FileCacheTests.cpp
@@ -11,9 +11,9 @@
 #include "TestFS.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
-#include 
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -34,10 +34,10 @@
   FS.Files.erase(testPath("foo.cc"));
   }
 
-  std::string get(std::chrono::steady_clock::time_point FreshTime,
-  bool ExpectParse) const {
+  std::pair
+  get(std::chrono::steady_clock::time_point FreshTime) const {
 bool GotParse = false;
-bool GotRead;
+bool GotRead = false;
 std::string Result;
 read(
 FS, FreshTime,
@@ -49,12 +49,14 @@
   GotRead = true;
   Result = Value;
 });
-EXPECT_EQ(GotParse, ExpectParse);
 EXPECT_TRUE(GotRead);
-return Result;
+return {Result, GotParse};
   }
 };
 
+MATCHER_P(Parsed, Value, "") { return arg.second && arg.first == Value; }
+MATCHER_P(Cached, Value, "") { return !arg.second && arg.first == Value; }
+
 TEST(FileCacheTest, Invalidation) {
   TestCache C;
 
@@ -62,20 +64,20 @@
   auto MustBeFresh = StaleOK + std::chrono::hours(1);
 
   C.setContents("a");
-  EXPECT_EQ("a", C.get(StaleOK, /*ExpectParse=*/true)) << "Parsed first time";
-  EXPECT_EQ("a", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("a", C.get(MustBeFresh, /*ExpectParse=*/false)) << "Cached (stat)";
+  EXPECT_THAT(C.get(StaleOK), Parsed("a")) << "Parsed first time";
+  EXPECT_THAT(C.get(StaleOK), Cached("a")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh), Cached("a")) << "Cached (stat)";
   C.setContents("bb");
-  EXPECT_EQ("a", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("bb", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Size changed";
-  EXPECT_EQ("bb", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Cached (stat)";
+  EXPECT_THAT(C.get(StaleOK), Cached("a")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh), Parsed("bb")) << "Size changed";
+  EXPECT_THAT(C.get(MustBeFresh), Cached("bb")) << "Cached (stat)";
   C.setContents(nullptr);
-  EXPECT_EQ("bb", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Stat failed";
-  EXPECT_EQ("", C.get(MustBeFresh, /*ExpectParse=*/false)) << "Cached (404)";
+  EXPECT_THAT(C.get(StaleOK), Cached("bb")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh), Parsed("")) << "stat failed";
+  EXPECT_THAT(C.get(MustBeFresh), Cached("")) << "Cached (404)";
   C.setContents("bb"); // Match the previous stat values!
-  EXPECT_EQ("", C.get(StaleOK, /*ExpectParse=*/false)) << "Cached (time)";
-  EXPECT_EQ("bb", C.get(MustBeFresh, /*ExpectParse=*/true)) << "Size changed";
+  EXPECT_THAT(C.get(StaleOK), Cached("")) << "Cached (time)";
+  EXPECT_THAT(C.get(MustBeFresh),

[PATCH] D143984: [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)

2023-03-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 504602.
krisb added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143984

Files:
  clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/debug-info-cxx1y.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/CodeGenObjC/debug-info-category.m
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/IR/DIBuilder.cpp

Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -57,23 +57,11 @@
 }
 
 void DIBuilder::finalizeSubprogram(DISubprogram *SP) {
-  MDTuple *Temp = SP->getRetainedNodes().get();
-  if (!Temp || !Temp->isTemporary())
-return;
-
-  SmallVector RetainedNodes;
-
-  auto PV = PreservedVariables.find(SP);
-  if (PV != PreservedVariables.end())
-RetainedNodes.append(PV->second.begin(), PV->second.end());
-
-  auto PL = PreservedLabels.find(SP);
-  if (PL != PreservedLabels.end())
-RetainedNodes.append(PL->second.begin(), PL->second.end());
-
-  DINodeArray Node = getOrCreateArray(RetainedNodes);
-
-  TempMDTuple(Temp)->replaceAllUsesWith(Node.get());
+  auto PN = SubprogramTrackedNodes.find(SP);
+  if (PN != SubprogramTrackedNodes.end())
+SP->replaceRetainedNodes(
+MDTuple::get(VMContext, SmallVector(PN->second.begin(),
+PN->second.end(;
 }
 
 void DIBuilder::finalize() {
@@ -772,26 +760,20 @@
 
 static DILocalVariable *createLocalVariable(
 LLVMContext &VMContext,
-DenseMap> &PreservedVariables,
-DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
+SmallVectorImpl &PreservedNodes,
+DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File,
 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
 uint32_t AlignInBits, DINodeArray Annotations = nullptr) {
-  // FIXME: Why getNonCompileUnitScope()?
-  // FIXME: Why is "!Context" okay here?
   // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
   // the only valid scopes)?
-  DIScope *Context = getNonCompileUnitScope(Scope);
-
-  auto *Node = DILocalVariable::get(
-  VMContext, cast_or_null(Context), Name, File, LineNo, Ty,
-  ArgNo, Flags, AlignInBits, Annotations);
+  auto *Scope = cast(Context);
+  auto *Node = DILocalVariable::get(VMContext, Scope, Name, File, LineNo, Ty,
+ArgNo, Flags, AlignInBits, Annotations);
   if (AlwaysPreserve) {
 // The optimizer may remove local variables. If there is an interest
 // to preserve variable info in such situation then stash it in a
 // named mdnode.
-DISubprogram *Fn = getDISubprogram(Scope);
-assert(Fn && "Missing subprogram for local variable");
-PreservedVariables[Fn].emplace_back(Node);
+PreservedNodes.emplace_back(Node);
   }
   return Node;
 }
@@ -801,9 +783,11 @@
DIType *Ty, bool AlwaysPreserve,
DINode::DIFlags Flags,
uint32_t AlignInBits) {
-  return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
- /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
- Flags, AlignInBits);
+  assert(Scope && isa(Scope) &&
+ "Unexpected scope for a local variable.");
+  return createLocalVariable(
+  VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name,
+  /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);
 }
 
 DILocalVariable *DIBuilder::createParameterVariable(
@@ -811,25 +795,23 @@
 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
 DINodeArray Annotations) {
   assert(ArgNo && "Expected non-zero argument number for parameter");
-  return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
- File, LineNo, Ty, AlwaysPreserve, Flags,
- /*AlignInBits=*/0, Annotations);
+  assert(Scope && isa(Scope) &&
+ "Unexpected scope for a local variable.");
+  return createLocalVariable(
+  VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name, ArgNo,
+  File, LineNo, Ty, AlwaysPreserve, Flags, /*AlignInBits=*/0, Annotations);
 }
 
-DILabel *DIBuilder::createLabel(DIScope *Scope, StringRef Name, DIFile *File,
-unsigned LineNo, bool AlwaysPreserve) {
-  DIScope *Context = getNonCompileUnitScope(Scope);
-
-  auto *Node = DILabel::get(VMContext, cast_or_null(Context),
-Name, File, LineNo);
+DILabel *DIBuilder::createLabel(DIScope *Context, StringRef Name, DIFile *File,
+

[PATCH] D144004: [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

2023-03-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 504605.
krisb added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144004

Files:
  clang/test/CodeGenCXX/debug-info-namespace.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
  llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Linker/IRMover.cpp
  llvm/test/CodeGen/Generic/DbgValueAggregate.ll
  llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
  llvm/test/DebugInfo/Generic/imported-name-inlined.ll
  llvm/test/DebugInfo/Generic/namespace.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
  llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
  llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
  llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
  llvm/test/DebugInfo/X86/fission-inline.ll
  llvm/test/DebugInfo/X86/fission-local-import.ll
  llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
  llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
  llvm/test/DebugInfo/X86/namelist2.ll
  llvm/test/DebugInfo/omit-empty.ll
  llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Index: llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
===
--- llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
+++ llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
@@ -5,15 +5,13 @@
 ; RUN: opt -module-summary %p/Inputs/debuginfo-cu-import.ll -o %t2.bc
 ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc
 
-; Don't import enums, macros, retainedTypes or globals lists.
-; Only import local scope imported entities.
+; Don't import enums, macros, retainedTypes, globals or imports lists.
 ; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t.index.bc -o - | llvm-dis -o - | FileCheck %s
 ; CHECK-NOT: DICompileUnit{{.*}} enums:
 ; CHECK-NOT: DICompileUnit{{.*}} macros:
 ; CHECK-NOT: DICompileUnit{{.*}} retainedTypes:
 ; CHECK-NOT: DICompileUnit{{.*}} globals:
-; CHECK: DICompileUnit{{.*}} imports: ![[IMP:[0-9]+]]
-; CHECK: ![[IMP]] = !{!{{[0-9]+}}}
+; CHECK-NOT: DICompileUnit{{.*}} imports:
 
 ; ModuleID = 'debuginfo-cu-import.c'
 source_filename = "debuginfo-cu-import.c"
@@ -50,14 +48,14 @@
 !8 = !{!9}
 !9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
 !10 = !DIGlobalVariable(name: "version", scope: !4, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true)
-!11 = !{!12, !16}
+!11 = !{!12}
 !12 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !4, entity: !13, file: !1, line: 8)
 !13 = distinct !DISubprogram(name: "a", linkageName: "_ZN1A1aEv", scope: !4, file: !1, line: 7, type: !14, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !14 = !DISubroutineType(types: !15)
 !15 = !{null}
 !16 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !17, entity: !19, file: !1, line: 8)
 !17 = distinct !DILexicalBlock(scope: !18, file: !1, line: 9, column: 8)
-!18 = distinct !DISubprogram(name: "c", linkageName: "_ZN1A1cEv", scope: !4, file: !1, line: 9, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
+!18 = distinct !DISubprogram(name: "c", linkageName: "_ZN1A1cEv", scope: !4, file: !1, line: 9, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !33)
 !19 = distinct !DILexicalBlock(scope: !20, file: !1, line: 10, column: 8)
 !20 = distinct !DISubprogram(name: "d", linkageName: "_ZN1A1dEv", scope: !4, file: !1, line: 10, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !21 = !{!22}
@@ -72,4 +70,4 @@
 !30 = !DILocation(line: 7, column: 12, scope: !13)
 !31 = distinct !DISubprogram(name: "b", linkageName: "_ZN1A1bEv", scope: !4, file: !1, line: 8, type: !14, isLocal: true, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !32 = !DILocation(line: 8, column: 24, scope: !31)
-
+!33 = !{!16}
Index: llvm/test/DebugInfo/omit-empty.ll
===
--- llvm/test/DebugInfo/omit-empty.ll
+++ llvm/test/DebugInfo/omit-empty.ll
@@ -6,15 +6,15 @@
 !llvm.dbg.cu = !{!0, !5}
 !llvm.module.flags = !{!3, !4}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "LLVM", isOptimized: false, run

[PATCH] D144006: [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (5/7)

2023-03-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb marked 2 inline comments as done.
krisb added inline comments.



Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp:698
+  // an inlined function: if a local variable has a templated type with
+  // a function-local type as a template parameter. See PR55680 for details.
+  if (!Scope->isAbstractScope() && !Scope->getInlinedAt()) {

jmmartinez wrote:
> I cannot find the link to PR55680. Would you mind sharing it?
> 
> You could also reference `local-type-as-template-parameter.ll`, your test 
> depicts the issue very clearly.
> I cannot find the link to PR55680. Would you mind sharing it?
> 
> You could also reference `local-type-as-template-parameter.ll`, your test 
> depicts the issue very clearly.

Here is the link to the issue https://github.com/llvm/llvm-project/issues/55680.
Mentioned the test in the comment. Thank you!



Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp:712-714
+  assert(!getAbstractScopeDIEs().count(DS) &&
+ "Abstract DIE for this scope exists!");
+  getAbstractScopeDIEs()[DS] = ScopeDIE;

jmmartinez wrote:
> NIT: You could use `insert/try_emplace` instead of using `count` and 
> `operator[]`. The assertion would become something like:
> ```
> auto Inserted = getAbstractScopeDIEs().try_emplace(DS, ScopeDIE);
> assert(Inserted.second && "Abstract DIE for this scope exists!");
> return ScopeDIE;
> ```
I'd slightly prefer to keep the original code as it looks a bit more readable 
to me (in your example, there should be another line to void out unused 
`Inserted` variable, otherwise it'd cause a warning). 
Additional `count()` call in the `assert()` doesn't seem too expensive to me, 
but if you still think `try_emplace()` is better, I'll change to it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144006

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


[PATCH] D144006: [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (5/7)

2023-03-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 504608.
krisb marked an inline comment as done.
krisb added a comment.

Apply review comments and rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144006

Files:
  clang/test/CodeGen/debug-info-codeview-unnamed.c
  clang/test/CodeGen/debug-info-unused-types.c
  clang/test/CodeGen/debug-info-unused-types.cpp
  clang/test/CodeGenCXX/debug-info-access.cpp
  clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
  clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
  clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
  clang/test/CodeGenCXX/debug-lambda-this.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/DebugInfo/Generic/inlined-local-type.ll
  llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
  llvm/test/DebugInfo/Generic/lexical-block-types.ll
  llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
  llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
  llvm/test/DebugInfo/X86/set.ll

Index: llvm/test/DebugInfo/X86/set.ll
===
--- llvm/test/DebugInfo/X86/set.ll
+++ llvm/test/DebugInfo/X86/set.ll
@@ -68,11 +68,11 @@
 !llvm.module.flags = !{!18, !19, !20}
 
 !0 = !{!"versions- cm3: d5.10.0 llvm: 9.0"}
-!1 = distinct !DICompileUnit(language: DW_LANG_Modula3, file: !2, producer: "cm3", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3)
+!1 = distinct !DICompileUnit(language: DW_LANG_Modula3, file: !2, producer: "cm3", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
 !2 = !DIFile(filename: "Main.m3", directory: "/home/cm3/settest/src")
 !3 = !{!4}
 !4 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", scope: !5, file: !2, line: 11, size: 8, align: 8, elements: !9)
-!5 = distinct !DISubprogram(name: "Test", linkageName: "Main__Test", scope: !2, file: !2, line: 11, type: !6, scopeLine: 11, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !8)
+!5 = distinct !DISubprogram(name: "Test", linkageName: "Main__Test", scope: !2, file: !2, line: 11, type: !6, scopeLine: 11, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !3)
 !6 = !DISubroutineType(types: !7)
 !7 = !{null}
 !8 = !{}
Index: llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
===
--- llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
+++ llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
@@ -38,7 +38,7 @@
 define void @invalid_retained_nodes_list() !dbg !10 { ret void }
 !10 = distinct !DISubprogram(retainedNodes: !0)
 
-; CHECK: invalid retained nodes, expected DILocalVariable, DILabel or DIImportedEntity
+; CHECK: invalid retained nodes, expected DILocalVariable, DILabel, DIImportedEntity or DIType
 define void @invalid_retained_nodes_expected() !dbg !11 { ret void }
 !11 = distinct !DISubprogram(retainedNodes: !{!0})
 
Index: llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
@@ -0,0 +1,160 @@
+; RUN: %llc_dwarf -O0 -filetype=obj < %s  \
+; RUN:  | llvm-dwarfdump --show-children --name=foo - \
+; RUN:  | FileCheck --implicit-check-not "{{DW_TAG|NULL}}" %s
+
+; The test ensures that AsmPrinter doesn't crashed compiling this.
+; It also demostrates misplacement for a local type (see PR55680 for details).
+
+; The test compiled from:
+
+; template
+; struct A {
+;   A(T &in) : a(in) {}
+;   T a;
+; };
+;
+; __attribute__((always_inline))
+; void foo() {
+;   struct B { int i; };
+;   B objB;
+;   A objA(objB);
+; }
+;
+; int main() {
+;   foo();
+; }
+
+; Concrete out-of-line tree of foo().
+; CHECK: DW_TAG_subprogram
+; CHECK:   DW_AT_abstract_origin {{.*}} "_Z3foov"
+;
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_abstract_origin {{.*}} "objB"
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_abstract_origin {{.*}} "objA"
+
+; FIXME: 'struct B' should be in the abstract tree below, not here.
+; CHECK:   DW_TAG_structure_type
+; CHECK: DW_AT_name	("B")
+; CHECK: DW_TAG_member
+; CHECK: NULL
+
+; CHECK:   NULL
+
+; Abstract tree of foo().
+; CHECK: DW_TAG_subprogram
+; CHECK:   DW_AT_name	("foo")
+; CHECK:   DW_AT_inline	(DW_INL_inlined)
+
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_name	("objB")
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_name	("objA")
+
+; CHECK:   NULL
+
+; CHECK: DW_TAG_inlined_subroutine
+; CHECK:   DW_AT_abstract_origin {{.*}} "_Z3foov"
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_abstract_origin {{.*}} "objB"
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_a

[PATCH] D145848: [Driver] Correct -f(no-)xray-function-index behavior

2023-03-13 Thread Oleksii Lozovskyi via Phabricator via cfe-commits
ilammy updated this revision to Diff 504609.
ilammy added a comment.

Addressed feedback by @MaskRay. Thanks!


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

https://reviews.llvm.org/D145848

Files:
  clang/include/clang/Driver/Options.td
  clang/test/CodeGen/xray-function-index.cpp


Index: clang/test/CodeGen/xray-function-index.cpp
===
--- /dev/null
+++ clang/test/CodeGen/xray-function-index.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fxray-instrument  -x c++ 
-std=c++11 -triple x86_64-unknown-linux-gnu -S -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-ENABLED
+// RUN: %clang_cc1 -fxray-instrument -fno-xray-function-index -x c++ 
-std=c++11 -triple x86_64-unknown-linux-gnu -S -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-DISABLED
+// REQUIRES: x86-registered-target
+
+[[clang::xray_always_instrument]] void foo() {}
+
+// CHECK-LABEL: .section xray_instr_map,"ao",@progbits,_Z3foov
+// CHECK-ENABLED: .section xray_fn_idx,"awo",@progbits,_Z3foov
+// CHECK-DISABLED-NOT: .section xray_fn_idx
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2173,10 +2173,10 @@
   NegFlag>;
 
 defm xray_function_index : BoolFOption<"xray-function-index",
-  CodeGenOpts<"XRayOmitFunctionIndex">, DefaultTrue,
-  NegFlag, DefaultFalse,
+  NegFlag,
-  PosFlag>;
+  PosFlag>;
 
 def fxray_link_deps : Flag<["-"], "fxray-link-deps">, Group,
   Flags<[CC1Option]>,


Index: clang/test/CodeGen/xray-function-index.cpp
===
--- /dev/null
+++ clang/test/CodeGen/xray-function-index.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fxray-instrument  -x c++ -std=c++11 -triple x86_64-unknown-linux-gnu -S -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-ENABLED
+// RUN: %clang_cc1 -fxray-instrument -fno-xray-function-index -x c++ -std=c++11 -triple x86_64-unknown-linux-gnu -S -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-DISABLED
+// REQUIRES: x86-registered-target
+
+[[clang::xray_always_instrument]] void foo() {}
+
+// CHECK-LABEL: .section xray_instr_map,"ao",@progbits,_Z3foov
+// CHECK-ENABLED: .section xray_fn_idx,"awo",@progbits,_Z3foov
+// CHECK-DISABLED-NOT: .section xray_fn_idx
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2173,10 +2173,10 @@
   NegFlag>;
 
 defm xray_function_index : BoolFOption<"xray-function-index",
-  CodeGenOpts<"XRayOmitFunctionIndex">, DefaultTrue,
-  NegFlag, DefaultFalse,
+  NegFlag,
-  PosFlag>;
+  PosFlag>;
 
 def fxray_link_deps : Flag<["-"], "fxray-link-deps">, Group,
   Flags<[CC1Option]>,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 58825d2 - [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-13 Thread via cfe-commits

Author: Ankur
Date: 2023-03-13T18:05:16+05:30
New Revision: 58825d2cf947d0b4fb6590c17212c388cd3ff5cf

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

LOG: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

- Modify -extract-api-ignores command line option to accept multiple
  arguments
- Update APIIgnoresList to operate on a file list instead of a single file
- Add new test verifying the functionality
- fix #61242 on GitHub issue tracker

Reviewed By: dang

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

Added: 
clang/test/ExtractAPI/ignored-symbols-multifile.c

Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/ExtractAPI/APIIgnoresList.h
clang/include/clang/Frontend/FrontendOptions.h
clang/lib/ExtractAPI/APIIgnoresList.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 52f58f045e8c..5c49450914a6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1167,9 +1167,9 @@ def extract_api : Flag<["-"], "extract-api">, 
Flags<[CC1Option]>, Group;
 def product_name_EQ: Joined<["--"], "product-name=">, Flags<[CC1Option]>,
   MarshallingInfoString>;
-def extract_api_ignores_EQ: Joined<["--"], "extract-api-ignores=">, 
Flags<[CC1Option]>,
-HelpText<"File containing a new line separated list of API symbols to 
ignore when extracting API information.">,
-MarshallingInfoString>;
+def extract_api_ignores_EQ: CommaJoined<["--"], "extract-api-ignores=">, 
Flags<[CC1Option]>,
+HelpText<"Comma separated list of files containing a new line separated 
list of API symbols to ignore when extracting API information.">,
+MarshallingInfoStringVector>;
 def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group, 
Flags<[CC1Option]>,
   HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,

diff  --git a/clang/include/clang/ExtractAPI/APIIgnoresList.h 
b/clang/include/clang/ExtractAPI/APIIgnoresList.h
index 43c546102a2d..3eee8e336cb6 100644
--- a/clang/include/clang/ExtractAPI/APIIgnoresList.h
+++ b/clang/include/clang/ExtractAPI/APIIgnoresList.h
@@ -7,7 +7,7 @@
 
//===--===//
 ///
 /// \file This file defines APIIgnoresList which is a type that allows querying
-/// a file containing symbols to ignore when extracting API information.
+/// files containing symbols to ignore when extracting API information.
 ///
 
//===--===//
 
@@ -44,11 +44,13 @@ struct IgnoresFileNotFound : public 
llvm::ErrorInfo {
 /// A type that provides access to a new line separated list of symbol names to
 /// ignore when extracting API information.
 struct APIIgnoresList {
-  /// The API to use for generating from the file at \p IgnoresFilePath.
+  using FilePathList = std::vector;
+
+  /// The API to use for generating from the files at \p IgnoresFilePathList.
   ///
   /// \returns an initialized APIIgnoresList or an Error.
-  static llvm::Expected create(llvm::StringRef IgnoresFilePath,
-   FileManager &FM);
+  static llvm::Expected
+  create(const FilePathList &IgnoresFilePathList, FileManager &FM);
 
   APIIgnoresList() = default;
 
@@ -58,14 +60,14 @@ struct APIIgnoresList {
 
 private:
   using SymbolNameList = llvm::SmallVector;
+  using BufferList = llvm::SmallVector>;
 
-  APIIgnoresList(SymbolNameList SymbolsToIgnore,
- std::unique_ptr Buffer)
-  : SymbolsToIgnore(std::move(SymbolsToIgnore)), Buffer(std::move(Buffer)) 
{
-  }
+  APIIgnoresList(SymbolNameList SymbolsToIgnore, BufferList Buffers)
+  : SymbolsToIgnore(std::move(SymbolsToIgnore)),
+Buffers(std::move(Buffers)) {}
 
   SymbolNameList SymbolsToIgnore;
-  std::unique_ptr Buffer;
+  BufferList Buffers;
 };
 
 } // namespace extractapi

diff  --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 6efe3cdd5802..ef04f3b236d8 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -453,8 +453,9 @@ class FrontendOptions {
   std::string ProductName;
 
   // Currently this is only used as part of the `-extract-api` action.
-  /// The file providing a list of APIs to ignore when extracting documentation
-  std::string ExtractAPIIgnoresFile;
+  // A comma seperated list of files providing a list of APIs to
+  // ignore when extracting documentation.
+  std::vector ExtractAPIIgnoresFileList;
 
   /// Args to pass to the plugins
   s

[PATCH] D145869: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-13 Thread Ankur Saini via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58825d2cf947: [clang][ExtractAPI] Add multiple file support 
to --extract-api-ignores (authored by Arsenic).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145869

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/ExtractAPI/APIIgnoresList.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/ExtractAPI/APIIgnoresList.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/ignored-symbols-multifile.c

Index: clang/test/ExtractAPI/ignored-symbols-multifile.c
===
--- /dev/null
+++ clang/test/ExtractAPI/ignored-symbols-multifile.c
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   --extract-api-ignores=%t/ignores-list1,%t/ignores-list2,%t/ignores-list3 \
+// RUN:   -x c-header %t/input.h -verify -o - | FileCheck %t/input.h
+
+//--- input.h
+#define IGNORED_6_FILE1 6
+#define IGNORED_2_FILE1 2
+#define IGNORED_5_FILE1 5
+
+#define IGNORED_4_FILE2 4
+#define IGNORED_3_FILE2 3
+
+typedef double IGNORED_1_FILE3;
+typedef int IGNORED_7_FILE3;
+
+typedef float NonIgnored;
+
+// CHECK-NOT: IGNORED_6_FILE1
+// CHECK-NOT: IGNORED_2_FILE1
+// CHECK-NOT: IGNORED_5_FILE1
+
+// CHECK-NOT: IGNORED_4_FILE2
+// CHECK-NOT: IGNORED_3_FILE2
+
+// CHECK-NOT: IGNORED_1_FILE3
+// CHECK-NOT: IGNORED_7_FILE3
+// CHECK: NonIgnored
+
+// expected-no-diagnostics
+
+//--- ignores-list1
+IGNORED_6_FILE1
+IGNORED_2_FILE1
+IGNORED_5_FILE1
+
+//--- ignores-list2
+IGNORED_4_FILE2
+IGNORED_3_FILE2
+
+//--- ignores-list3
+IGNORED_1_FILE3
+IGNORED_7_FILE3
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -339,9 +339,9 @@
   Policy.AnonymousTagLocations = false;
   CI.getASTContext().setPrintingPolicy(Policy);
 
-  if (!CI.getFrontendOpts().ExtractAPIIgnoresFile.empty()) {
+  if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
 llvm::handleAllErrors(
-APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFile,
+APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFileList,
CI.getFileManager())
 .moveInto(IgnoresList),
 [&CI](const IgnoresFileNotFound &Err) {
Index: clang/lib/ExtractAPI/APIIgnoresList.cpp
===
--- clang/lib/ExtractAPI/APIIgnoresList.cpp
+++ clang/lib/ExtractAPI/APIIgnoresList.cpp
@@ -31,20 +31,29 @@
   return llvm::inconvertibleErrorCode();
 }
 
-Expected APIIgnoresList::create(StringRef IgnoresFilePath,
-FileManager &FM) {
-  auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
-  if (!BufferOrErr)
-return make_error(IgnoresFilePath);
-
-  auto Buffer = std::move(BufferOrErr.get());
+Expected
+APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
+   FileManager &FM) {
   SmallVector Lines;
-  Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, /*KeepEmpty*/ false);
-  // Symbol names don't have spaces in them, let's just remove these in case the
-  // input is slighlty malformed.
+  BufferList symbolBufferList;
+
+  for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {
+auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);
+
+if (!BufferOrErr)
+  return make_error(CurrentIgnoresFilePath);
+
+auto Buffer = std::move(BufferOrErr.get());
+Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,
+  /*KeepEmpty*/ false);
+symbolBufferList.push_back(std::move(Buffer));
+  }
+
+  // Symbol names don't have spaces in them, let's just remove these in case
+  // the input is slighlty malformed.
   transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });
   sort(Lines);
-  return APIIgnoresList(std::move(Lines), std::move(Buffer));
+  return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));
 }
 
 bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -453,8 +453,9 @@
   std::string ProductName;
 
   // Currently this is only used as part of the `-extract-api` action.
-  /// The file providing a list of APIs to ignore when extracting documentation
-  std::string ExtractAPIIgnoresFile;
+  // A comma seperated list of files providing a list of APIs to
+  // ignore when extrac

[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-03-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:2817
+// unique representation.
+if (Field->isUnnamedBitfield() && BitfieldSize > 0)
+  return std::nullopt;

I think the check for a non-zero bit-field width might not be completely 
correct in cases where it's used to split an allocation unit. I suggested a 
test case below.



Comment at: clang/test/SemaCXX/type-traits.cpp:2886-2889
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};

I think there's one more test to add:
```
struct UnnamedEmptyBitfieldSplit {
  short named;
  int : 0;
  short also_named;
};
static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2));
static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

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


[PATCH] D145861: [clang][Interp] Ignore more non-VarDecl declarations

2023-03-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeStmtGen.cpp:224
   for (auto *D : DS->decls()) {
-if (isa(D))
+if (isa(D))
   continue;

What about other kinds of declarations, such as typedefs or functions?
```
typedef int foo, bar;
extern int a(), b();
```
(and so on)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145861

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


[PATCH] D141907: [CMake] Ensure `CLANG_RESOURCE_DIR` is respected

2023-03-13 Thread Junchang Liu via Phabricator via cfe-commits
paperchalice added a comment.

Ping.




Comment at: lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp:56
+  const std::string clang_resource_path =
+  clang::driver::Driver::GetResourcesPath("bin/lldb", CLANG_RESOURCE_DIR);
 

Should be "${CMAKE_INSTALL_BINDIR}/lldb" here, but need another variable in 
`config.h`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141907

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


[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-13 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce updated this revision to Diff 504616.
sunshaoce added a comment.

Add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

Files:
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/test/Driver/code-gen-rv64.f90
  flang/test/Driver/target-cpu-features.f90


Index: flang/test/Driver/target-cpu-features.f90
===
--- flang/test/Driver/target-cpu-features.f90
+++ flang/test/Driver/target-cpu-features.f90
@@ -22,6 +22,9 @@
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
+! RUN: %flang --target=riscv64-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
+
 
 ! Test that invalid cpu and features are ignored.
 
@@ -52,5 +55,9 @@
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" 
"-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" 
"-target-feature" "-fsgsbase"
 
+! CHECK-RV64: "-fc1" "-triple" "riscv64-unknown-linux-gnu"
+! CHECK-RV64-SAME: "-target-cpu" "generic-rv64" "-target-feature" "+m" 
"-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" 
"-target-feature" "+c"
+
+
 ! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target 
(ignoring processor)
 ! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this 
target (ignoring feature)
Index: flang/test/Driver/code-gen-rv64.f90
===
--- /dev/null
+++ flang/test/Driver/code-gen-rv64.f90
@@ -0,0 +1,13 @@
+! Test -emit-obj (RISC-V 64)
+
+! RUN: rm -f %t.o
+! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu \
+! RUN:   -target-feature +d -target-feature +c -emit-obj %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! RUN: rm -f %t.o
+! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! CHECK: Flags: 0x5, RVC, double-float ABI
+end program
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -106,6 +106,8 @@
 break;
   case llvm::Triple::aarch64:
 [[fallthrough]];
+  case llvm::Triple::riscv64:
+[[fallthrough]];
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
 break;


Index: flang/test/Driver/target-cpu-features.f90
===
--- flang/test/Driver/target-cpu-features.f90
+++ flang/test/Driver/target-cpu-features.f90
@@ -22,6 +22,9 @@
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
+! RUN: %flang --target=riscv64-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
+
 
 ! Test that invalid cpu and features are ignored.
 
@@ -52,5 +55,9 @@
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" "-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" "-target-feature" "-fsgsbase"
 
+! CHECK-RV64: "-fc1" "-triple" "riscv64-unknown-linux-gnu"
+! CHECK-RV64-SAME: "-target-cpu" "generic-rv64" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+c"
+
+
 ! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target (ignoring processor)
 ! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this target (ignoring feature)
Index: flang/test/Driver/code-gen-rv64.f90
===
--- /dev/null
+++ flang/test/Driver/code-gen-rv64.f90
@@ -0,0 +1,13 @@
+! Test -emit-obj (RISC-V 64)
+
+! RUN: rm -f %t.o
+! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu \
+! RUN:   -target-feature +d -target-feature +c -emit-obj %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! RUN: rm -f %t.o
+! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! CHECK: Flags: 0x5, RVC, double-float ABI
+end program
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -106,6 +106,8 @@
 break;
   case llvm::Triple::aarch64:
 [[fallthrough]];
+  case llvm::Triple::riscv64:
+[[fallthrough]];
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-13 Thread Alexander Hederstaf via Phabricator via cfe-commits
AlexanderHederstaf added a comment.

What is the next step in the process? Anything I should do?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-03-13 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added a comment.

Ping for review. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

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


[clang] 34de7da - [clangd] Move standard options adaptor to CommandMangler

2023-03-13 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2023-03-13T06:08:22-07:00
New Revision: 34de7da6246cdfa6ff6f3d3c514583cddc0a10ec

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

LOG: [clangd] Move standard options adaptor to CommandMangler

There is a discrepancy between how clangd processes CDB loaded from
JSON file on disk and pushed via LSP. Thus the same CDB pushed via
LSP protocol may not work as expected. Some difference between these two
paths is expected but we still need to insert driver mode and target from
binary name and expand response files.

Test Plan: check-clang-tools

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

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/CompileCommands.h
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
clang/include/clang/Tooling/Tooling.h
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/lib/Tooling/Tooling.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index bcd39b2d38ba5..39b180e002a68 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -14,6 +14,7 @@
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -27,6 +28,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
+#include "llvm/TargetParser/Host.h"
 #include 
 #include 
 #include 
@@ -185,6 +187,12 @@ static std::string resolveDriver(llvm::StringRef Driver, 
bool FollowSymlink,
 
 } // namespace
 
+CommandMangler::CommandMangler() {
+  Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
+  ? llvm::cl::TokenizeWindowsCommandLine
+  : llvm::cl::TokenizeGNUCommandLine;
+}
+
 CommandMangler CommandMangler::detect() {
   CommandMangler Result;
   Result.ClangPath = detectClangPath();
@@ -201,9 +209,18 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
   trace::Span S("AdjustCompileFlags");
   // Most of the modifications below assumes the Cmd starts with a driver name.
   // We might consider injecting a generic driver name like "cc" or "c++", but
-  // a Cmd missing the driver is probably rare enough in practice and errnous.
+  // a Cmd missing the driver is probably rare enough in practice and 
erroneous.
   if (Cmd.empty())
 return;
+
+  // FS used for expanding response files.
+  // FIXME: ExpandResponseFiles appears not to provide the usual
+  // thread-safety guarantees, as the access to FS is not locked!
+  // For now, use the real FS, which is known to be threadsafe (if we don't
+  // use/change working directory, which ExpandResponseFiles doesn't).
+  auto FS = llvm::vfs::getRealFileSystem();
+  tooling::addExpandedResponseFiles(Cmd, Command.Directory, Tokenizer, *FS);
+
   auto &OptTable = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
   llvm::SmallVector OriginalArgs;
@@ -212,7 +229,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
 OriginalArgs.push_back(S.c_str());
   bool IsCLMode = driver::IsClangCL(driver::getDriverMode(
   OriginalArgs[0], llvm::ArrayRef(OriginalArgs).slice(1)));
-  // ParseArgs propagates missig arg/opt counts on error, but preserves
+  // ParseArgs propagates missing arg/opt counts on error, but preserves
   // everything it could parse in ArgList. So we just ignore those counts.
   unsigned IgnoredCount;
   // Drop the executable name, as ParseArgs doesn't expect it. This means
@@ -307,12 +324,16 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
   //necessary for the system include extractor to identify the file type
   //  - AFTER applying CompileFlags.Edits, because the name of the compiler
   //that needs to be invoked may come from the CompileFlags->Compiler key
+  //  - BEFORE addTargetAndModeForProgramName(), because gcc doesn't support
+  //the target flag that might be added.
   //  - BEFORE resolveDriver() because that can mess up the driver path,
   //e.g. changing gcc to /path/to/clang/bin/gcc
   if (SystemIncludeExtractor) {
 SystemIncludeExtractor(Command, File);
   }
 
+  tooling::addTargetAndModeForProgramName(Cmd, Cmd.front());
+
   // Check whether the flag exists, either as -flag or -flag=*
   auto Has = [&](llvm::StringRef Flag) {
 

[PATCH] D143436: [clangd] Move standard options adaptor to CommandMangler

2023-03-13 Thread Dmitry Polukhin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG34de7da6246c: [clangd] Move standard options adaptor to 
CommandMangler (authored by DmitryPolukhin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/Tooling.cpp

Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -299,6 +300,31 @@
   }
 }
 
+void addExpandedResponseFiles(std::vector &CommandLine,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem &FS) {
+  bool SeenRSPFile = false;
+  llvm::SmallVector Argv;
+  Argv.reserve(CommandLine.size());
+  for (auto &Arg : CommandLine) {
+Argv.push_back(Arg.c_str());
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
+  }
+  if (!SeenRSPFile)
+return;
+  llvm::BumpPtrAllocator Alloc;
+  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
+  llvm::Error Err =
+  ECtx.setVFS(&FS).setCurrentDir(WorkingDir).expandResponseFiles(Argv);
+  if (Err)
+llvm::errs() << Err;
+  // Don't assign directly, Argv aliases CommandLine.
+  std::vector ExpandedArgv(Argv.begin(), Argv.end());
+  CommandLine = std::move(ExpandedArgv);
+}
+
 } // namespace tooling
 } // namespace clang
 
@@ -684,7 +710,7 @@
 
   if (!Invocation.run())
 return nullptr;
- 
+
   assert(ASTs.size() == 1);
   return std::move(ASTs[0]);
 }
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -48,28 +49,9 @@
 
 private:
   std::vector expand(std::vector Cmds) const {
-for (auto &Cmd : Cmds) {
-  bool SeenRSPFile = false;
-  llvm::SmallVector Argv;
-  Argv.reserve(Cmd.CommandLine.size());
-  for (auto &Arg : Cmd.CommandLine) {
-Argv.push_back(Arg.c_str());
-if (!Arg.empty())
-  SeenRSPFile |= Arg.front() == '@';
-  }
-  if (!SeenRSPFile)
-continue;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
-  llvm::Error Err = ECtx.setVFS(FS.get())
-.setCurrentDir(Cmd.Directory)
-.expandResponseFiles(Argv);
-  if (Err)
-llvm::errs() << Err;
-  // Don't assign directly, Argv aliases CommandLine.
-  std::vector ExpandedArgv(Argv.begin(), Argv.end());
-  Cmd.CommandLine = std::move(ExpandedArgv);
-}
+for (auto &Cmd : Cmds)
+  tooling::addExpandedResponseFiles(Cmd.CommandLine, Cmd.Directory,
+Tokenizer, *FS);
 return Cmds;
   }
 
Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -506,6 +506,12 @@
 void addTargetAndModeForProgramName(std::vector &CommandLine,
 StringRef InvokedAs);
 
+/// Helper function that expands response files in command line.
+void addExpandedResponseFiles(std::vector &CommandLine,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem &FS);
+
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
   ArrayRef CC1Args,
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd

[PATCH] D145842: [clang][Sema] Avoid duplicate diagnostics for unreachable fallthrough attribute

2023-03-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Analysis/Analyses/ReachableCode.h:65
+ Callback &CB,
+ const bool UnreachableFallThroughDiagIsEnabled);
 }} // end namespace clang::reachable_code

We don't typically use `const` on value types in the project, so dropping this 
for style consistency. You should make the same edit elsewhere in the patch as 
well.



Comment at: clang/lib/Analysis/ReachableCode.cpp:680
   SourceLocation Loc = GetUnreachableLoc(S, R1, R2);
   CB.HandleUnreachable(UK, Loc, SilenceableCondVal, R1, R2);
 }

Would it be cleaner (less changes) to pass a boolean into this callback to say 
"the statement had a fallthrough attribute on it" so that 
`UnreachableCodeHandler::HandleUnreachable()` can check to see whether the 
unreachable fallthrough diagnostic is enabled or not? It has access to a `Sema` 
object, so it should be able to do the work. `FindUnreachableCode()` would then 
not have to change its signature and it keeps the "should I suppress this 
diagnostic logic" nearby where we issue the diagnostic along with the other 
duplicate handling logic.


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

https://reviews.llvm.org/D145842

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


[PATCH] D145886: [C++2x][Modules] Amend module purview constant linkage [P2788R0].

2023-03-13 Thread Iain Sandoe via Phabricator via cfe-commits
iains created this revision.
Herald added a project: All.
iains added a reviewer: ChuanqiXu.
iains updated this revision to Diff 504524.
iains added a comment.
iains updated this revision to Diff 504591.
iains added a reviewer: rsmith.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

rebase, remove use of fmodule-file=X=path to attempt to resolve Windows fail.


iains added a comment.

rebased, try to fix Windows CI, take 2.


iains added a comment.

I should definitely check to make sure that this was adopted as a DR against 
C++20 (otherwise we would need to use the previous test conditionally on < 2b).


This paper has been applied to the working draft and is believed to be
a DR against C++20, so that the patch here makes the change unconditionally.

for:

  export module A;
  
  const int mod_cst = 10;

Before the change, mod_cst would have internal linkage; after the change it
has module linkage.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145886

Files:
  clang/lib/AST/Decl.cpp
  clang/test/CXX/module/basic/basic.def.odr/p4.cppm
  clang/test/CXX/module/basic/basic.link/p3.cppm


Index: clang/test/CXX/module/basic/basic.link/p3.cppm
===
--- clang/test/CXX/module/basic/basic.link/p3.cppm
+++ clang/test/CXX/module/basic/basic.link/p3.cppm
@@ -3,7 +3,7 @@
 
 export module M;
 
-// CHECK-NOT: @_ZW1M1a ={{.*}}
+// CHECK: @_ZW1M1a ={{.*}} constant i32 1
 const int a = 1;
 // CHECK: @_ZW1M1b ={{.*}} constant i32 2
 export const int b = 2;
Index: clang/test/CXX/module/basic/basic.def.odr/p4.cppm
===
--- clang/test/CXX/module/basic/basic.def.odr/p4.cppm
+++ clang/test/CXX/module/basic/basic.def.odr/p4.cppm
@@ -5,9 +5,9 @@
 // RUN: %clang_cc1 -std=c++20 %t/Module.cppm -triple %itanium_abi_triple 
-emit-llvm -o - | FileCheck %t/Module.cppm --implicit-check-not unused
 //
 // RUN: %clang_cc1 -std=c++20 %t/Module.cppm -triple %itanium_abi_triple 
-emit-module-interface -o %t/Module.pcm
-// RUN: %clang_cc1 -std=c++20 %t/module.cpp -triple %itanium_abi_triple 
-fmodule-file=%t/Module.pcm -emit-llvm -o - | FileCheck %t/module.cpp 
--implicit-check-not=unused --implicit-check-not=global_module
+// RUN: %clang_cc1 -std=c++20 %t/module.cpp -triple %itanium_abi_triple 
-fmodule-file=Module=%t/Module.pcm -emit-llvm -o - | FileCheck %t/module.cpp 
--implicit-check-not=unused --implicit-check-not=global_module
 //
-// RUN: %clang_cc1 -std=c++20 %t/user.cpp -triple %itanium_abi_triple 
-fmodule-file=%t/Module.pcm -emit-llvm -o - | FileCheck %t/user.cpp 
--implicit-check-not=unused --implicit-check-not=global_module
+// RUN: %clang_cc1 -std=c++20 %t/user.cpp -triple %itanium_abi_triple 
-fmodule-file=Module=%t/Module.pcm -emit-llvm -o - | FileCheck %t/user.cpp 
--implicit-check-not=unused --implicit-check-not=global_module
 
 //--- Module.cppm
 // CHECK-DAG: @extern_var_global_module = external {{(dso_local )?}}global
@@ -30,7 +30,7 @@
 // permitted to run the initializer for this variable.
 // CHECK-DAG: @_ZW6Module25inline_var_module_linkage = linkonce_odr 
{{(dso_local )?}}global
 // CHECK-DAG: @_ZL25static_var_module_linkage = internal
-// CHECK-DAG: @_ZL24const_var_module_linkage = internal
+// CHECK-DAG: @_ZW6Module24const_var_module_linkage = {{(dso_local )?}}constant
 //
 // CHECK-DAG: @_ZW6Module25unused_var_module_linkage = {{(dso_local )?}}global 
i32 4
 
@@ -129,7 +129,7 @@
 // CHECK-DAG: @_ZW6Module25extern_var_module_linkage = external {{(dso_local 
)?}}global
 // CHECK-DAG: @_ZW6Module25inline_var_module_linkage = linkonce_odr 
{{(dso_local )?}}global
 // CHECK-DAG: @_ZL25static_var_module_linkage = internal {{(dso_local 
)?}}global i32 0,
-// CHECK-DAG: @_ZL24const_var_module_linkage = internal {{(dso_local 
)?}}constant i32 3,
+// CHECK-DAG: @_ZW6Module24const_var_module_linkage = available_externally 
{{(dso_local )?}}constant i32 3,
 
 module Module;
 
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -600,6 +600,12 @@
   llvm_unreachable("unexpected module ownership kind");
 }
 
+static bool isDeclaredInModuleInterfaceOrPartition(const NamedDecl *D) {
+  if (auto *M = D->getOwningModule())
+return M->isInterfaceOrPartition();
+  return false;
+}
+
 static LinkageInfo getInternalLinkageFor(const NamedDecl *D) {
   return LinkageInfo::internal();
 }
@@ -642,15 +648,15 @@
   if (const auto *Var = dyn_cast(D)) {
 // - a non-template variable of non-volatile const-qualified type, unless
 //   - it is explicitly declared extern, or
-//   - it is inline or exported, or
+//   - it is declared in the purview of a module interface unit
+// (outside the private-module-fragment, if any) or module partition, 
or
+//   - it is inline, or
 //   - it was previously declar

[PATCH] D144878: __builtin_FILE_NAME()

2023-03-13 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 504625.
karapsinie marked 3 inline comments as done.
karapsinie added a comment.

Fulfilled the wishes of cor3ntin №2


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

https://reviews.llvm.org/D144878

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/AST/Expr.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Preprocessor/feature_tests.cpp
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/Inputs/source-location-file.h
  clang/test/SemaCXX/source_location.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -259,6 +259,10 @@
  Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
  sourceLocExpr(hasBuiltinStr("__builtin_FILE");
+  testImport("void declToImport() { (void)__builtin_FILE_NAME(); }", Lang_CXX03,
+ "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(
+ sourceLocExpr(hasBuiltinStr("__builtin_FILE_NAME");
   testImport("void declToImport() { (void)__builtin_COLUMN(); }", Lang_CXX03,
  "", Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -84,6 +84,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
 
@@ -91,6 +92,7 @@
 static_assert(noexcept(__builtin_LINE()));
 static_assert(noexcept(__builtin_COLUMN()));
 static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
 static_assert(noexcept(__builtin_source_location()));
 
@@ -346,6 +348,54 @@
 
 } // namespace test_file
 
+//===--===//
+//__builtin_FILE_NAME()
+//===--===//
+
+namespace test_file_name {
+constexpr const char *test_file_name_simple(
+  const char *__f = __builtin_FILE_NAME()) {
+  return __f;
+}
+void test_function() {
+#line 900
+  static_assert(is_equal(test_file_name_simple(), __FILE_NAME__));
+  static_assert(is_equal(SLF::test_function_filename(), __FILE_NAME__), "");
+  static_assert(is_equal(SLF::test_function_filename_template(42),
+ __FILE_NAME__), "");
+
+  static_assert(is_equal(SLF::test_function_filename_indirect(),
+ SLF::global_info_filename), "");
+  static_assert(is_equal(SLF::test_function_filename_template_indirect(42),
+ SLF::global_info_filename), "");
+
+  static_assert(test_file_name_simple() != nullptr);
+  static_assert(is_equal(test_file_name_simple(), "source_location.cpp"));
+}
+
+void test_class() {
+#line 315
+  using SLF::TestClass;
+  constexpr TestClass Default;
+  constexpr TestClass InParam{42};
+  constexpr TestClass Template{42, 42};
+  constexpr auto *F = Default.info_file_name;
+  constexpr auto Char = F[0];
+  static_assert(is_equal(Default.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.ctor_info_file_name, __FILE_NAME__), "");
+}
+
+void test_aggr_class() {
+  using Agg = SLF::AggrClass<>;
+  constexpr Agg Default{};
+  constexpr Agg InitOne{42};
+  static_assert(is_equal(Default.init_info_file_name, __FILE_NAME__), "");
+  static_assert(is_equal(InitOne.init_info_file_name, __FILE_NAME__), "");
+}
+
+} // namespace test_file_name
+
 //===--===//
 //__builtin_FUNCTION()
 //===--===//
@@ -487,6 +537,7 @@
 #line 44 "test_file.c"
 static_assert(is_equal("test_file.c", __FILE__));
 static_assert(is_equal("test_file.c", __builtin_FILE()));
+static_assert(is_equal("test_file.c", __builtin_FILE_NAME()));
 static_assert(is_equal("test_file.c", SL::current().file()));
 static_assert(is_equal("test_file.c", SLF::test_function().file()));
 static_assert(is_equal(SLF::FILE, SLF::test_function_indirect().file()));
Index: clang/test/SemaCXX/Inputs/source-location-file.h
===
--- clang/test/SemaCXX/Inputs/source-location-file.h
+++ clang/test/SemaCXX/Inputs/source-location-file.h
@@ -4,8 +4,10 @@
 namespace source

[PATCH] D145284: WIP [clang] adds capabilities for SARIF to be written to file

2023-03-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a subscriber: jansvoboda11.
erichkeane added a comment.

Patch topic needs "WIP" out of it I think?

Just some WIP comments, I don't believe I'd be the one to approve this anyway.




Comment at: clang/include/clang/Basic/DiagnosticOptions.h:109
 
+  /// The file to serialise text diagnostics to (non-appending).
+  std::string FilePath;

typically Clang uses the 'American' spelling of things.



Comment at: clang/include/clang/Basic/DiagnosticOptions.h:110
+  /// The file to serialise text diagnostics to (non-appending).
+  std::string FilePath;
+

I'm a touch disturbed by there being 3 very similar file names with very 
similar comments here. Is there a reason we need all 3?



Comment at: clang/include/clang/Driver/Options.td:5851
+def fdiagnostics_file_path : Separate<["-"], "fdiagnostics-file-path">,
+  HelpText<"FIX BEFORE MERGING">,
+  MarshallingInfoString>;

Another 'TODO' here?



Comment at: clang/include/clang/Frontend/CompilerInstance.h:610
+  ///
+  /// \param ToFile Determines if Clang should write diagnostics to a file.
   void createDiagnostics(DiagnosticConsumer *Client = nullptr,

This comment seems inaccurate.



Comment at: clang/include/clang/Frontend/SARIFDiagnosticPrinter.h:39
+  /// name suffixed with `.sarif`.
+  SARIFDiagnosticPrinter(StringRef TargetPath, DiagnosticOptions *Diags);
+

What do we do with the DiagnosticsOptions here?  Does this have to be a 
pointer, instead of a ref?

EDIT: I see the rest of the printers seem to do this, but I don't know if we 
ever have a case where these are null.  I guess having them consistent here is 
important, but if the next person came through and made these all 'refs', it 
would be nice :)



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:4036
+CmdArgs.push_back(Format->getValue());
+if (StringRef(Format->getValue()).starts_with("sarif"))
   D.Diag(diag::warn_drv_sarif_format_unstable);

are we intentionally getting rid of the SARIF spellings intentionally?  If so, 
and because we have this warning, should we report they are no longer supported?



Comment at: clang/lib/Frontend/CompilerInstance.cpp:357
+if (OutputPath.empty())
+  goto Default;
+Diags->setClient(new SARIFDiagnosticPrinter(OutputPath, Opts));

Oh my... I'll leave it to the Clang code owner/driver code owner 
(@jansvoboda11) to decide what they think of this.



Comment at: clang/lib/Frontend/SARIFDiagnosticPrinter.cpp:37
+  return std::make_unique(
+  std::string(TargetPath) + ".sarif", EC);
+}

Isn't TargetPath a 'Path'?  If so, are you just creating a dot-file?  Aren't 
those really nasty on Windows, and not a nice thing to do here on Linux?



Comment at: clang/lib/Frontend/SARIFDiagnosticPrinter.cpp:45
+  if (*EC) {
+assert(false and "not implemented yet: not even sure what to do");
+  }

I know these are nice/readable/etc, but llvm doesn't use these.

Also, you KNOW what EC equals here: it is a default constructed 
`std::error_code`, so the 'if' condition here is always hit.  I suspect just 
removing the whole body and replacing with an `llvm_unreachable` is appropriate 
instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145284

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


[PATCH] D145659: [clang] Add AVR specific inline assembly escaped characters

2023-03-13 Thread Ben Shi via Phabricator via cfe-commits
benshi001 updated this revision to Diff 504631.

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

https://reviews.llvm.org/D145659

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/AVR.h
  clang/test/CodeGen/avr/avr-inline-asm-constraints.c


Index: clang/test/CodeGen/avr/avr-inline-asm-constraints.c
===
--- clang/test/CodeGen/avr/avr-inline-asm-constraints.c
+++ clang/test/CodeGen/avr/avr-inline-asm-constraints.c
@@ -1,5 +1,10 @@
 // REQUIRES: avr-registered-target
-// RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck 
%s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu at90s8515 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR25 %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu atmega328 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR51 %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu atmega2560 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR6 %s
 
 int data;
 
@@ -122,3 +127,23 @@
   // CHECK: call addrspace(0) i16 asm "subi r30, $0", "=ra"()
   asm("subi r30, %0" : "=ra"(data));
 }
+
+void escapeChar(void) {
+  asm("_foo:");
+  // AVR25: call addrspace(0) void asm sideeffect "rcall _foo"
+  // AVR51: call addrspace(0) void asm sideeffect "call _foo"
+  // AVR6:  call addrspace(0) void asm sideeffect "call _foo"
+  asm("%~call _foo" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "rjmp _foo"
+  // AVR51: call addrspace(0) void asm sideeffect "jmp _foo"
+  // AVR6:  call addrspace(0) void asm sideeffect "jmp _foo"
+  asm("%~jmp _foo" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "icall"
+  // AVR51: call addrspace(0) void asm sideeffect "icall"
+  // AVR6:  call addrspace(0) void asm sideeffect "eicall"
+  asm("%!icall" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "ijmp"
+  // AVR51: call addrspace(0) void asm sideeffect "ijmp"
+  // AVR6:  call addrspace(0) void asm sideeffect "eijmp"
+  asm("%!ijmp" ::);
+}
Index: clang/lib/Basic/Targets/AVR.h
===
--- clang/lib/Basic/Targets/AVR.h
+++ clang/lib/Basic/Targets/AVR.h
@@ -170,6 +170,7 @@
   bool isValidCPUName(StringRef Name) const override;
   void fillValidCPUList(SmallVectorImpl &Values) const override;
   bool setCPU(const std::string &Name) override;
+  std::optional handleAsmEscapedChar(char EscChar) const override;
   StringRef getABI() const override { return ABI; }
 
 protected:
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -428,6 +428,23 @@
   return false;
 }
 
+std::optional
+AVRTargetInfo::handleAsmEscapedChar(char EscChar) const {
+  switch (EscChar) {
+  // "%~" represents for 'r' depends on the device has long jump/call.
+  case '~':
+return ArchHasJMPCALL(Arch) ? std::string("") : std::string(1, 'r');
+
+  // "%!" represents for 'e' depends on the PC register size.
+  case '!':
+return ArchHas3BytePC(Arch) ? std::string(1, 'e') : std::string("");
+
+  // This is an invalid escape character for AVR.
+  default:
+return std::nullopt;
+  }
+}
+
 void AVRTargetInfo::getTargetDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
   Builder.defineMacro("AVR");


Index: clang/test/CodeGen/avr/avr-inline-asm-constraints.c
===
--- clang/test/CodeGen/avr/avr-inline-asm-constraints.c
+++ clang/test/CodeGen/avr/avr-inline-asm-constraints.c
@@ -1,5 +1,10 @@
 // REQUIRES: avr-registered-target
-// RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu at90s8515 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR25 %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu atmega328 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR51 %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu atmega2560 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR6 %s
 
 int data;
 
@@ -122,3 +127,23 @@
   // CHECK: call addrspace(0) i16 asm "subi r30, $0", "=ra"()
   asm("subi r30, %0" : "=ra"(data));
 }
+
+void escapeChar(void) {
+  asm("_foo:");
+  // AVR25: call addrspace(0) void asm sideeffect "rcall _foo"
+  // AVR51: call addrspace(0) void asm sideeffect "call _foo"
+  // AVR6:  call addrspace(0) void asm sideeffect "call _foo"
+  asm("%~call _foo" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "rjmp _foo"
+  // AVR51: call addrspace(0) void asm sideeffect "jmp _foo"
+  // AVR6:  call addrspace(0) void asm sideeffect "jmp _foo"
+  asm("%~jmp _foo" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "icall"
+  // AVR51: call addrspace(0) void asm sideeffect "icall"
+  // AVR6:  c

[PATCH] D145659: [clang] Add AVR specific inline assembly escaped characters

2023-03-13 Thread Ben Shi via Phabricator via cfe-commits
benshi001 marked an inline comment as done.
benshi001 added inline comments.



Comment at: clang/lib/Basic/Targets/AVR.cpp:433
+AVRTargetInfo::handleAsmEscapedChar(char EscChar) const {
+  char C;
+  switch (EscChar) {

jacquesguan wrote:
> redundant variable?
Removed. Thanks!


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

https://reviews.llvm.org/D145659

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


[PATCH] D145227: [LLVM][OHOS] Clang toolchain and targets

2023-03-13 Thread Pavel Kosov via Phabricator via cfe-commits
kpdev42 updated this revision to Diff 504632.
kpdev42 marked an inline comment as done.
kpdev42 added a comment.

Address review comments and rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145227

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/OHOS.cpp
  clang/lib/Driver/ToolChains/OHOS.h
  clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c
  clang/test/Driver/Inputs/ohos_native_tree/llvm/bin/.keep
  clang/test/Driver/Inputs/ohos_native_tree/llvm/include/c++/v1/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/a7_soft/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/c++/a7_hard_neon-vfpv4/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/c++/a7_soft/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/c++/a7_softfp_neon-vfpv4/libc++.so
  clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/libclang_rt.profile.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/libclang_rt.profile.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/libclang_rt.profile.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/libclang_rt.profile.a
  clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/include/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/include/arm-liteos-ohos/.keep
  clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/a7_soft/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/.keep
  clang/test/Driver/ohos.c
  clang/test/Driver/ohos.cpp
  clang/test/Preprocessor/ohos.c

Index: clang/test/Preprocessor/ohos.c
===
--- /dev/null
+++ clang/test/Preprocessor/ohos.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding 

[clang-tools-extra] 2a84c53 - Revert "[clangd] Move standard options adaptor to CommandMangler"

2023-03-13 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2023-03-13T07:00:56-07:00
New Revision: 2a84c53ccdc015a7f53a144aa4f7c0dddf839604

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

LOG: Revert "[clangd] Move standard options adaptor to CommandMangler"

This reverts commit 34de7da6246cdfa6ff6f3d3c514583cddc0a10ec.

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/CompileCommands.h
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
clang/include/clang/Tooling/Tooling.h
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/lib/Tooling/Tooling.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 39b180e002a68..bcd39b2d38ba5 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -14,7 +14,6 @@
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/CompilationDatabase.h"
-#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -28,7 +27,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
-#include "llvm/TargetParser/Host.h"
 #include 
 #include 
 #include 
@@ -187,12 +185,6 @@ static std::string resolveDriver(llvm::StringRef Driver, 
bool FollowSymlink,
 
 } // namespace
 
-CommandMangler::CommandMangler() {
-  Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
-  ? llvm::cl::TokenizeWindowsCommandLine
-  : llvm::cl::TokenizeGNUCommandLine;
-}
-
 CommandMangler CommandMangler::detect() {
   CommandMangler Result;
   Result.ClangPath = detectClangPath();
@@ -209,18 +201,9 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
   trace::Span S("AdjustCompileFlags");
   // Most of the modifications below assumes the Cmd starts with a driver name.
   // We might consider injecting a generic driver name like "cc" or "c++", but
-  // a Cmd missing the driver is probably rare enough in practice and 
erroneous.
+  // a Cmd missing the driver is probably rare enough in practice and errnous.
   if (Cmd.empty())
 return;
-
-  // FS used for expanding response files.
-  // FIXME: ExpandResponseFiles appears not to provide the usual
-  // thread-safety guarantees, as the access to FS is not locked!
-  // For now, use the real FS, which is known to be threadsafe (if we don't
-  // use/change working directory, which ExpandResponseFiles doesn't).
-  auto FS = llvm::vfs::getRealFileSystem();
-  tooling::addExpandedResponseFiles(Cmd, Command.Directory, Tokenizer, *FS);
-
   auto &OptTable = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
   llvm::SmallVector OriginalArgs;
@@ -229,7 +212,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
 OriginalArgs.push_back(S.c_str());
   bool IsCLMode = driver::IsClangCL(driver::getDriverMode(
   OriginalArgs[0], llvm::ArrayRef(OriginalArgs).slice(1)));
-  // ParseArgs propagates missing arg/opt counts on error, but preserves
+  // ParseArgs propagates missig arg/opt counts on error, but preserves
   // everything it could parse in ArgList. So we just ignore those counts.
   unsigned IgnoredCount;
   // Drop the executable name, as ParseArgs doesn't expect it. This means
@@ -324,16 +307,12 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
   //necessary for the system include extractor to identify the file type
   //  - AFTER applying CompileFlags.Edits, because the name of the compiler
   //that needs to be invoked may come from the CompileFlags->Compiler key
-  //  - BEFORE addTargetAndModeForProgramName(), because gcc doesn't support
-  //the target flag that might be added.
   //  - BEFORE resolveDriver() because that can mess up the driver path,
   //e.g. changing gcc to /path/to/clang/bin/gcc
   if (SystemIncludeExtractor) {
 SystemIncludeExtractor(Command, File);
   }
 
-  tooling::addTargetAndModeForProgramName(Cmd, Cmd.front());
-
   // Check whether the flag exists, either as -flag or -flag=*
   auto Has = [&](llvm::StringRef Flag) {
 for (llvm::StringRef Arg : Cmd) {

diff  --git a/clang-tools-extra/clangd/CompileCommands.h 
b/clang-tools-extra/clangd/CompileCommands.h
index 1b37f44f0b9db..eb318d18baf63 100644
--- a/clang-tools-extra/clangd/CompileCommands.h
+++ b/clang-tools-extra/clangd/CompileCommands.h
@@ -12,7 +12,6 @@
 #include "support/Threading.h"
 #include

[PATCH] D143436: [clangd] Move standard options adaptor to CommandMangler

2023-03-13 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

Had to revert this diff temporary due to broken ARM builds. It seems that X86 
targets are disabled for that bots so tests are not passing. I'll fix upload 
new version for review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

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


[PATCH] D145491: [clang] Replace Member Expressions During Instantiation If Necessary

2023-03-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Thanks for the ping.  I don't have any better ideas/other thoughts, so LGTM.


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

https://reviews.llvm.org/D145491

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


[PATCH] D145765: Add __builtin_set_flt_rounds

2023-03-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for the additional tests! Can you also add a release note to 
`clang/docs/ReleaseNotes.rst` and document the new builtin in 
`clang\docs\LanguageExtensions.rst`?




Comment at: clang/test/Sema/builtin_set_flt_rounds.c:1-11
+// RUN: %clang_cc1 -triple mipsel-unknown-linux  -fsyntax-only %s -verify
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -fsyntax-only %s -verify
+struct S {int a;};
+void test_builtin_set_flt_rounds() {
+#ifndef __x86_64__
+  __builtin_set_flt_rounds(1); // expected-error {{builtin is not supported on 
this target}}
+#else

Simplify the test somewhat.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145765

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


[PATCH] D145851: [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Generally looks good to me.  Do we do anything special if there are multiple 
initializers?  Also, can we have a codegen test that validates that we actually 
construct it correctly (and perhaps a constexpr test for the same!)?




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:9163
+  // members has an explicit initializer.
+  auto* RD = dyn_cast(Field->getParent());
+  assert(RD);

This way you don't need the assert!



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:9167
+DiagKind = 4;
+} else
+  DiagKind = 4;

else needs curleys, since its associated 'if' has them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145851

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


[clang] 4d55a0b - Fix include order in CXType.cpp

2023-03-13 Thread Aaron Ballman via cfe-commits

Author: Collin Baker
Date: 2023-03-13T10:11:05-04:00
New Revision: 4d55a0b512a17dfaa2461b8803d37b79f6c9691d

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

LOG: Fix include order in CXType.cpp

Handle template parameter-dependent bit field widths in libclang

In a class template, a bit field's width may depend on a template
parameter. In this case the width expression cannot be evaluated.

Previously clang_getFieldDeclBitWidth() would assert, or cause memory
unsafety and return an invalid result if assertions are disabled.

This adds a check for this case which returns an error code. An
additional function clang_isBitFieldDecl() is added to disambiguate
between error code meanings.

Fixes: https://github.com/llvm/llvm-project/issues/56644
Differential Revision: https://reviews.llvm.org/D130303

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang-c/Index.h
clang/tools/libclang/CXType.cpp
clang/tools/libclang/libclang.map

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 76e0a71931c1c..dac81ecd48e34 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -296,6 +296,11 @@ libclang
 - Introduced the new function ``clang_CXXMethod_isExplicit``,
   which identifies whether a constructor or conversion function cursor
   was marked with the explicit identifier.
+- Added check in ``clang_getFieldDeclBitWidth`` for whether a bit field
+  has an evaluable bit width. Fixes undefined behavior when called on a
+  bit field whose width depends on a template paramter.
+- Added function ``clang_isBitFieldDecl`` to check if a struct/class field is a
+  bit field.
 
 - Introduced the new ``CXIndex`` constructor function
   ``clang_createIndexWithOptions``, which allows overriding precompiled 
preamble

diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 7cd35e9b2a7d4..88d719d32c21f 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3023,10 +3023,18 @@ CINDEX_LINKAGE long long 
clang_getEnumConstantDeclValue(CXCursor C);
 CINDEX_LINKAGE unsigned long long
 clang_getEnumConstantDeclUnsignedValue(CXCursor C);
 
+/**
+ * Returns non-zero if a field declaration has a bit width expression.
+ *
+ * If the cursor does not reference a bit field declaration 0 is returned.
+ */
+CINDEX_LINKAGE unsigned clang_isBitFieldDecl(CXCursor C);
+
 /**
  * Retrieve the bit width of a bit field declaration as an integer.
  *
- * If a cursor that is not a bit field declaration is passed in, -1 is 
returned.
+ * If the cursor does not reference a bit field, or if the bit field's width
+ * expression cannot be evaluated, -1 is returned.
  */
 CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
 

diff  --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index a1d157c63995b..9358e3e5f14e5 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -10,11 +10,11 @@
 //
 //======//
 
+#include "CXType.h"
 #include "CIndexer.h"
 #include "CXCursor.h"
 #include "CXString.h"
 #include "CXTranslationUnit.h"
-#include "CXType.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
@@ -371,14 +371,27 @@ unsigned long long 
clang_getEnumConstantDeclUnsignedValue(CXCursor C) {
   return ULLONG_MAX;
 }
 
+unsigned clang_isBitFieldDecl(CXCursor C) {
+  using namespace cxcursor;
+
+  if (clang_isDeclaration(C.kind)) {
+const Decl *D = getCursorDecl(C);
+
+if (const auto *FD = dyn_cast_or_null(D))
+  return FD->isBitField();
+  }
+
+  return 0;
+}
+
 int clang_getFieldDeclBitWidth(CXCursor C) {
   using namespace cxcursor;
 
   if (clang_isDeclaration(C.kind)) {
 const Decl *D = getCursorDecl(C);
 
-if (const FieldDecl *FD = dyn_cast_or_null(D)) {
-  if (FD->isBitField())
+if (const auto *FD = dyn_cast_or_null(D)) {
+  if (FD->isBitField() && !FD->getBitWidth()->isValueDependent())
 return FD->getBitWidthValue(getCursorContext(C));
 }
   }

diff  --git a/clang/tools/libclang/libclang.map 
b/clang/tools/libclang/libclang.map
index 34b1ef1a54514..f6cc157d7fb83 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -422,6 +422,7 @@ LLVM_17 {
   global:
 clang_CXXMethod_isExplicit;
 clang_createIndexWithOptions;
+clang_isBitFieldDecl;
 };
 
 # Example of how to add a new symbol version entry.  If you do add a new symbol



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


[PATCH] D130303: Fix include order in CXType.cpp

2023-03-13 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d55a0b512a1: Fix include order in CXType.cpp (authored by 
collinbaker, committed by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130303

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/tools/libclang/CXType.cpp
  clang/tools/libclang/libclang.map


Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -422,6 +422,7 @@
   global:
 clang_CXXMethod_isExplicit;
 clang_createIndexWithOptions;
+clang_isBitFieldDecl;
 };
 
 # Example of how to add a new symbol version entry.  If you do add a new symbol
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -10,11 +10,11 @@
 //
 //======//
 
+#include "CXType.h"
 #include "CIndexer.h"
 #include "CXCursor.h"
 #include "CXString.h"
 #include "CXTranslationUnit.h"
-#include "CXType.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
@@ -371,14 +371,27 @@
   return ULLONG_MAX;
 }
 
+unsigned clang_isBitFieldDecl(CXCursor C) {
+  using namespace cxcursor;
+
+  if (clang_isDeclaration(C.kind)) {
+const Decl *D = getCursorDecl(C);
+
+if (const auto *FD = dyn_cast_or_null(D))
+  return FD->isBitField();
+  }
+
+  return 0;
+}
+
 int clang_getFieldDeclBitWidth(CXCursor C) {
   using namespace cxcursor;
 
   if (clang_isDeclaration(C.kind)) {
 const Decl *D = getCursorDecl(C);
 
-if (const FieldDecl *FD = dyn_cast_or_null(D)) {
-  if (FD->isBitField())
+if (const auto *FD = dyn_cast_or_null(D)) {
+  if (FD->isBitField() && !FD->getBitWidth()->isValueDependent())
 return FD->getBitWidthValue(getCursorContext(C));
 }
   }
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -3023,10 +3023,18 @@
 CINDEX_LINKAGE unsigned long long
 clang_getEnumConstantDeclUnsignedValue(CXCursor C);
 
+/**
+ * Returns non-zero if a field declaration has a bit width expression.
+ *
+ * If the cursor does not reference a bit field declaration 0 is returned.
+ */
+CINDEX_LINKAGE unsigned clang_isBitFieldDecl(CXCursor C);
+
 /**
  * Retrieve the bit width of a bit field declaration as an integer.
  *
- * If a cursor that is not a bit field declaration is passed in, -1 is 
returned.
+ * If the cursor does not reference a bit field, or if the bit field's width
+ * expression cannot be evaluated, -1 is returned.
  */
 CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -296,6 +296,11 @@
 - Introduced the new function ``clang_CXXMethod_isExplicit``,
   which identifies whether a constructor or conversion function cursor
   was marked with the explicit identifier.
+- Added check in ``clang_getFieldDeclBitWidth`` for whether a bit field
+  has an evaluable bit width. Fixes undefined behavior when called on a
+  bit field whose width depends on a template paramter.
+- Added function ``clang_isBitFieldDecl`` to check if a struct/class field is a
+  bit field.
 
 - Introduced the new ``CXIndex`` constructor function
   ``clang_createIndexWithOptions``, which allows overriding precompiled 
preamble


Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -422,6 +422,7 @@
   global:
 clang_CXXMethod_isExplicit;
 clang_createIndexWithOptions;
+clang_isBitFieldDecl;
 };
 
 # Example of how to add a new symbol version entry.  If you do add a new symbol
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -10,11 +10,11 @@
 //
 //======//
 
+#include "CXType.h"
 #include "CIndexer.h"
 #include "CXCursor.h"
 #include "CXString.h"
 #include "CXTranslationUnit.h"
-#include "CXType.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
@@ -371,14 +371,27 @@
   return ULLONG_MAX;
 }
 
+unsigned clang_isBitFieldDecl(CXCursor C) {
+  using namespace cxcursor;
+
+  if (clang_isDeclaration(C.kind)) {
+const Decl *D = getCursorDecl(C);
+
+if (const auto *FD = dyn_cast_or_null(D))
+  r

[clang] 3951c28 - [clang] Replace Member Expressions During Instantiation If Necessary

2023-03-13 Thread Liming Liu via cfe-commits

Author: Liming Liu
Date: 2023-03-13T22:22:06+08:00
New Revision: 3951c28b37ff67c87da59df961c4af19818c24c2

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

LOG: [clang] Replace Member Expressions During Instantiation If Necessary

This patch replaces member accesses to declaration references during template
instantiation if the context is the unevaluated context and the class does not
contain the declaration.

The replacement fixes the issue #58674. Unlike previous fixes such as D143840,
it checks the membership during instantiation rather than right after parsing,
so the check is more accurate and efficient.

This patch also includes cases that previous fixes had once failed on.

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

Added: 
clang/test/CodeGenCXX/decl-ref-inheritance.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/TreeTransform.h
clang/test/SemaCXX/decltype.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dac81ecd48e34..47fee3ef6b248 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@ Bug Fixes to C++ Support
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix an issue about ``decltype`` in the members of class templates derived 
from
+  templates with related parameters.
+  (`#58674 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 590f0b4d2474c..e9b35f658c206 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -2803,6 +2803,21 @@ class TreeTransform {
 R.addDecl(FoundDecl);
 R.resolveKind();
 
+if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
+isa(Member)) {
+  if (auto *ThisClass = cast(Base)
+->getType()
+->getPointeeType()
+->getAsCXXRecordDecl()) {
+auto *Class = cast(Member->getDeclContext());
+// In unevaluated contexts, an expression supposed to be a member 
access
+// might reference a member in an unrelated class.
+if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
+  return getSema().BuildDeclRefExpr(Member, Member->getType(),
+VK_LValue, Member->getLocation());
+  }
+}
+
 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
   SS, TemplateKWLoc,
   FirstQualifierInScope,

diff  --git a/clang/test/CodeGenCXX/decl-ref-inheritance.cpp 
b/clang/test/CodeGenCXX/decl-ref-inheritance.cpp
new file mode 100644
index 0..9206ee5ac9369
--- /dev/null
+++ b/clang/test/CodeGenCXX/decl-ref-inheritance.cpp
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck 
\
+// RUN: -check-prefix=CHECK-1 %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck 
\
+// RUN: -check-prefix=CHECK-2 %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck 
\
+// RUN: -check-prefix=CHECK-3 %s
+
+// CHECK-1: [[FOO:%.+]] = type { float }
+struct foo {
+  float val;
+};
+
+template  struct bar : T {
+};
+
+struct baz : bar {
+  // CHECK-1: define{{.*}} float @_ZN3baz3getEv
+  // CHECK-1: {{%.+}} = getelementptr inbounds [[FOO]], ptr {{%.+}}, i32 0, 
i32 0
+  float get() {
+return val;
+  }
+};
+
+int qux() {
+  auto f = baz{};
+  return f.get();
+}
+
+// CHECK-2: [[F:%.+]] = type { ptr }
+struct f {
+  void *g;
+};
+
+template  struct k : j {
+  // CHECK-2: define{{.*}} void @_ZN1kI1fE1lEv
+  // CHECK-2: {{%.+}} = getelementptr inbounds [[F]], ptr {{%.+}}, i32 0, i32 0
+  virtual void l(){ (void)f::g; }
+};
+
+k q;
+
+// CHECK-3: [[BASE:%.+]] = type { i32 }
+class Base {
+protected:
+  int member;
+};
+
+template 
+struct Subclass : public Parent {
+  // CHECK-3: define{{.*}} i32 @_ZN8SubclassI4BaseE4funcEv
+  // CHECK-3: {{%.+}} = getelementptr inbounds [[BASE]], ptr {{%.+}}, i32 0, 
i32 0
+  int func() { return Base::member; }
+};
+
+using Impl = Subclass;
+
+int use() {
+  Impl i;
+  return i.func();
+}

diff  --git a/clang/test/SemaCXX/decltype.cpp b/clang/test/SemaCXX/decltype.cpp
index 32c61bbccc842..96abb60836e40 100644
--- a/clang/test/SemaCXX/decltype.cpp
+++ b/clang/test/SemaCXX/decltype.cpp
@@ -101,6 +101,44 @@ namespace D5789 {
   template void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
 }

[PATCH] D145491: [clang] Replace Member Expressions During Instantiation If Necessary

2023-03-13 Thread Liming Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3951c28b37ff: [clang] Replace Member Expressions During 
Instantiation If Necessary (authored by lime).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145491

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/decl-ref-inheritance.cpp
  clang/test/SemaCXX/decltype.cpp

Index: clang/test/SemaCXX/decltype.cpp
===
--- clang/test/SemaCXX/decltype.cpp
+++ clang/test/SemaCXX/decltype.cpp
@@ -101,6 +101,44 @@
   template void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
 }
 
+namespace GH58674 {
+  struct Foo {
+float value_;
+struct nested {
+  float value_;
+};
+  };
+
+  template 
+  struct TemplateFoo {
+float value_;
+  };
+
+  float bar;
+
+  template 
+  struct Animal{};
+
+  template 
+  class Cat : Animal {
+using okay = decltype(Foo::value_);
+using also_okay = decltype(bar);
+using okay2 = decltype(Foo::nested::value_);
+using okay3 = decltype(TemplateFoo::value_);
+  public:
+void meow() {
+  using okay = decltype(Foo::value_);
+  using also_okay = decltype(bar);
+  using okay2 = decltype(Foo::nested::value_);
+  using okay3 = decltype(TemplateFoo::value_);
+}
+  };
+
+  void baz() {
+  Cat{}.meow();
+  }
+}
+
 template
 class conditional {
 };
Index: clang/test/CodeGenCXX/decl-ref-inheritance.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/decl-ref-inheritance.cpp
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck \
+// RUN: -check-prefix=CHECK-1 %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck \
+// RUN: -check-prefix=CHECK-2 %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck \
+// RUN: -check-prefix=CHECK-3 %s
+
+// CHECK-1: [[FOO:%.+]] = type { float }
+struct foo {
+  float val;
+};
+
+template  struct bar : T {
+};
+
+struct baz : bar {
+  // CHECK-1: define{{.*}} float @_ZN3baz3getEv
+  // CHECK-1: {{%.+}} = getelementptr inbounds [[FOO]], ptr {{%.+}}, i32 0, i32 0
+  float get() {
+return val;
+  }
+};
+
+int qux() {
+  auto f = baz{};
+  return f.get();
+}
+
+// CHECK-2: [[F:%.+]] = type { ptr }
+struct f {
+  void *g;
+};
+
+template  struct k : j {
+  // CHECK-2: define{{.*}} void @_ZN1kI1fE1lEv
+  // CHECK-2: {{%.+}} = getelementptr inbounds [[F]], ptr {{%.+}}, i32 0, i32 0
+  virtual void l(){ (void)f::g; }
+};
+
+k q;
+
+// CHECK-3: [[BASE:%.+]] = type { i32 }
+class Base {
+protected:
+  int member;
+};
+
+template 
+struct Subclass : public Parent {
+  // CHECK-3: define{{.*}} i32 @_ZN8SubclassI4BaseE4funcEv
+  // CHECK-3: {{%.+}} = getelementptr inbounds [[BASE]], ptr {{%.+}}, i32 0, i32 0
+  int func() { return Base::member; }
+};
+
+using Impl = Subclass;
+
+int use() {
+  Impl i;
+  return i.func();
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -2803,6 +2803,21 @@
 R.addDecl(FoundDecl);
 R.resolveKind();
 
+if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
+isa(Member)) {
+  if (auto *ThisClass = cast(Base)
+->getType()
+->getPointeeType()
+->getAsCXXRecordDecl()) {
+auto *Class = cast(Member->getDeclContext());
+// In unevaluated contexts, an expression supposed to be a member access
+// might reference a member in an unrelated class.
+if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
+  return getSema().BuildDeclRefExpr(Member, Member->getType(),
+VK_LValue, Member->getLocation());
+  }
+}
+
 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
   SS, TemplateKWLoc,
   FirstQualifierInScope,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix an issue about ``decltype`` in the members of class templates derived from
+  templates with related parameters.
+  (`#58674 `_)
 
 Bug Fixes to AST Handling
 ^
___
cfe-commits mailing list
cfe-commi

[PATCH] D145919: [libc++] Add missing include in exception_ptr.h

2023-03-13 Thread Hans Wennborg via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc341d5030503: [libc++] Add missing include in 
exception_ptr.h (authored by hans).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145919

Files:
  libcxx/include/__exception/exception_ptr.h


Index: libcxx/include/__exception/exception_ptr.h
===
--- libcxx/include/__exception/exception_ptr.h
+++ libcxx/include/__exception/exception_ptr.h
@@ -11,6 +11,7 @@
 
 #include <__config>
 #include <__exception/operations.h>
+#include <__memory/addressof.h>
 #include 
 #include 
 


Index: libcxx/include/__exception/exception_ptr.h
===
--- libcxx/include/__exception/exception_ptr.h
+++ libcxx/include/__exception/exception_ptr.h
@@ -11,6 +11,7 @@
 
 #include <__config>
 #include <__exception/operations.h>
+#include <__memory/addressof.h>
 #include 
 #include 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145227: [LLVM][OHOS] Clang toolchain and targets

2023-03-13 Thread Pavel Kosov via Phabricator via cfe-commits
kpdev42 updated this revision to Diff 504647.
kpdev42 added a comment.

Fix test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145227

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/OHOS.cpp
  clang/lib/Driver/ToolChains/OHOS.h
  clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c
  clang/test/Driver/Inputs/ohos_native_tree/llvm/bin/.keep
  clang/test/Driver/Inputs/ohos_native_tree/llvm/include/c++/v1/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/a7_soft/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/c++/a7_hard_neon-vfpv4/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/c++/a7_soft/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/c++/a7_softfp_neon-vfpv4/libc++.so
  clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/libclang_rt.profile.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/libclang_rt.profile.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/libclang_rt.profile.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/libclang_rt.profile.a
  clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/include/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/include/arm-liteos-ohos/.keep
  clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/a7_soft/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/.keep
  clang/test/Driver/ohos.c
  clang/test/Driver/ohos.cpp
  clang/test/Preprocessor/ohos.c

Index: clang/test/Preprocessor/ohos.c
===
--- /dev/null
+++ clang/test/Preprocessor/ohos.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=arm-linux-ohos < /dev/null | FileCheck %s -match-full-l

[PATCH] D145886: [C++2x][Modules] Amend module purview constant linkage [P2788R0].

2023-03-13 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145886

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


[PATCH] D142692: [clang] Store the template param list of an explicit variable template specialization

2023-03-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

sorry for the delay, just started unburying myself from the 16.0 release 
process.  Its unfortunate we don't have a great way to test this, but I can see 
the value of having it anyway in clangd.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142692

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


[PATCH] D145793: [clang][AST] Improve diagnostic for `nullptr` constexpr function pointer call

2023-03-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM, though please add a release note for the fix. If you need someone to land 
on your behalf, let us know what name and email address you'd like used for 
patch attribution.




Comment at: clang/lib/AST/ExprConstant.cpp:7673
+Info.FFDiag(Callee, diag::note_constexpr_null_callee)
+<< const_cast(Callee);
+return false;

shafik wrote:
> hazohelet wrote:
> > tbaeder wrote:
> > > Is the `const_cast` really necessary?
> > > Is the `const_cast` really necessary?
> > Without `const_cast`, it did not compile.
> > I searched the existing codebase to find this line 
> > https://github.com/llvm/llvm-project/blob/151d3b607e1e3256ed901e02b48b92e79a77021d/clang/lib/Sema/SemaConcept.cpp#L300
> >  and I did the same here.
> > 
> Yeah, we do seem to `const_cast` on `const Expr*` all over and in some places 
> it is obviously harmless but others it is far from clear, at least on a 
> cursory examination. 
Clang has historically had very poor const-correctness, and trying to retrofit 
it is always an exercise in avoiding viral changes. So new interfaces tend to 
be more likely to be const-correct, while older ones (like the diagnostics 
engine) tend to not be.

The `const_cast<>` looks necessary to me, but if someone wanted to explore 
fixing up the interface so we can remove the const_casts from multiple places 
(as a follow-up patch, not as part of this work), that could be fruitful.


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

https://reviews.llvm.org/D145793

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


[PATCH] D144878: __builtin_FILE_NAME()

2023-03-13 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 504648.
karapsinie added a comment.

Updated a release note and documentation.


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

https://reviews.llvm.org/D144878

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/AST/Expr.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Preprocessor/feature_tests.cpp
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/Inputs/source-location-file.h
  clang/test/SemaCXX/source_location.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -259,6 +259,10 @@
  Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
  sourceLocExpr(hasBuiltinStr("__builtin_FILE");
+  testImport("void declToImport() { (void)__builtin_FILE_NAME(); }", Lang_CXX03,
+ "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(
+ sourceLocExpr(hasBuiltinStr("__builtin_FILE_NAME");
   testImport("void declToImport() { (void)__builtin_COLUMN(); }", Lang_CXX03,
  "", Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -84,6 +84,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
 
@@ -91,6 +92,7 @@
 static_assert(noexcept(__builtin_LINE()));
 static_assert(noexcept(__builtin_COLUMN()));
 static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
 static_assert(noexcept(__builtin_source_location()));
 
@@ -346,6 +348,54 @@
 
 } // namespace test_file
 
+//===--===//
+//__builtin_FILE_NAME()
+//===--===//
+
+namespace test_file_name {
+constexpr const char *test_file_name_simple(
+  const char *__f = __builtin_FILE_NAME()) {
+  return __f;
+}
+void test_function() {
+#line 900
+  static_assert(is_equal(test_file_name_simple(), __FILE_NAME__));
+  static_assert(is_equal(SLF::test_function_filename(), __FILE_NAME__), "");
+  static_assert(is_equal(SLF::test_function_filename_template(42),
+ __FILE_NAME__), "");
+
+  static_assert(is_equal(SLF::test_function_filename_indirect(),
+ SLF::global_info_filename), "");
+  static_assert(is_equal(SLF::test_function_filename_template_indirect(42),
+ SLF::global_info_filename), "");
+
+  static_assert(test_file_name_simple() != nullptr);
+  static_assert(is_equal(test_file_name_simple(), "source_location.cpp"));
+}
+
+void test_class() {
+#line 315
+  using SLF::TestClass;
+  constexpr TestClass Default;
+  constexpr TestClass InParam{42};
+  constexpr TestClass Template{42, 42};
+  constexpr auto *F = Default.info_file_name;
+  constexpr auto Char = F[0];
+  static_assert(is_equal(Default.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.ctor_info_file_name, __FILE_NAME__), "");
+}
+
+void test_aggr_class() {
+  using Agg = SLF::AggrClass<>;
+  constexpr Agg Default{};
+  constexpr Agg InitOne{42};
+  static_assert(is_equal(Default.init_info_file_name, __FILE_NAME__), "");
+  static_assert(is_equal(InitOne.init_info_file_name, __FILE_NAME__), "");
+}
+
+} // namespace test_file_name
+
 //===--===//
 //__builtin_FUNCTION()
 //===--===//
@@ -487,6 +537,7 @@
 #line 44 "test_file.c"
 static_assert(is_equal("test_file.c", __FILE__));
 static_assert(is_equal("test_file.c", __builtin_FILE()));
+static_assert(is_equal("test_file.c", __builtin_FILE_NAME()));
 static_assert(is_equal("test_file.c", SL::current().file()));
 static_assert(is_equal("test_file.c", SLF::test_function().file()));
 static_assert(is_equal(SLF::FILE, SLF::test_function_indirect().file()));
Index: clang/test/SemaCXX/Inputs/source-location-file.h
===
--- clang/test/SemaCXX/Inputs/source-location-file.h
+++ clang/test/SemaCXX/Inputs/source-location-file.h
@@ -4,8

[PATCH] D145815: [Flang][Driver] Add support for fopenmp-is-device and fembed-offload-object to Flang ToolChain

2023-03-13 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added inline comments.



Comment at: flang/test/Driver/omp-frontend-forwarding.f90:15
+! CHECK: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa" {{.*}} 
"-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
+! CHECK: "{{[^"]*}}clang-offload-packager" {{.*}} 
"--image=file={{.*}}gfx90a.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"
+! CHECK-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 
{{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.bc"

skatrak wrote:
> This unit test seems to be failing due to the pattern you've used here. 
> Probably a simple fix to get working, this is the test output: 
> https://reviews.llvm.org/harbormaster/unit/view/6153283/
Thank you! Hopefully it's working now. Not sure how it got passed me running 
check-all the first time... 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145815

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


[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-13 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/test/Driver/code-gen-rv64.f90:12
+
+! CHECK: Flags: 0x5, RVC, double-float ABI
+end program

For those of us less familiar with RISC-V - could you explain what's 
significant about this line? For example, [[ 
https://github.com/llvm/llvm-project/blob/0aac9a2875bad4f065367e4a6553fad78605f895/flang/test/Driver/code-gen-aarch64.f90#L18
 | here ]] it is made clear that with the right triple used, one should see a 
`ret` instruction within the main function (`_QQmain`). In here, I just see a 
"magic" number :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

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


[PATCH] D145834: typo statment to statement

2023-03-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! Do you need someone to land this on your behalf? If so, what name and 
email address would you like used for patch attribution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145834

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


[PATCH] D145941: [Clang] Always use -zdefs when linking AMDGPU images

2023-03-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield, arsenm, yaxunl, MaskRay.
Herald added subscribers: kosarev, kerbowa, tpr, dstuttard, jvesely, kzhuravl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, wdng.
Herald added a project: clang.

AMDGPU uses ELF shared libraries to implement their executable device
images. One downside to this method is that it disables regular warnings
on undefined symbols. This is because shared libraries expect these to
be resolves by later loads. However, the GPU images do not support
dynamic linking so any undefined symbol is going to cause a runtime
error. This patch adds `-zdefs` to the `ld.lld` invocation to guaruntee
that undefined symbols are always caught as linking errors rather than
runtime errors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145941

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/test/Driver/amdgpu-toolchain.c


Index: clang/test/Driver/amdgpu-toolchain.c
===
--- clang/test/Driver/amdgpu-toolchain.c
+++ clang/test/Driver/amdgpu-toolchain.c
@@ -6,7 +6,7 @@
 // RUN: %clang -### -g --target=amdgcn-mesa-mesa3d -mcpu=kaveri %s 2>&1 | 
FileCheck -check-prefix=DWARF_VER %s
 
 // AS_LINK: "-cc1as"
-// AS_LINK: ld.lld{{.*}} "-shared"
+// AS_LINK: ld.lld{{.*}} "-shared" "-zdefs"
 
 // DWARF_VER: "-dwarf-version=5"
 
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -544,6 +544,7 @@
 addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
   C.getDriver().getLTOMode() == LTOK_Thin);
   CmdArgs.push_back("-shared");
+  CmdArgs.push_back("-zdefs");
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
   C.addCommand(std::make_unique(


Index: clang/test/Driver/amdgpu-toolchain.c
===
--- clang/test/Driver/amdgpu-toolchain.c
+++ clang/test/Driver/amdgpu-toolchain.c
@@ -6,7 +6,7 @@
 // RUN: %clang -### -g --target=amdgcn-mesa-mesa3d -mcpu=kaveri %s 2>&1 | FileCheck -check-prefix=DWARF_VER %s
 
 // AS_LINK: "-cc1as"
-// AS_LINK: ld.lld{{.*}} "-shared"
+// AS_LINK: ld.lld{{.*}} "-shared" "-zdefs"
 
 // DWARF_VER: "-dwarf-version=5"
 
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -544,6 +544,7 @@
 addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
   C.getDriver().getLTOMode() == LTOK_Thin);
   CmdArgs.push_back("-shared");
+  CmdArgs.push_back("-zdefs");
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
   C.addCommand(std::make_unique(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145941: [Clang] Always use -zdefs when linking AMDGPU images

2023-03-13 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a reviewer: AMDGPU.
JonChesterfield added a comment.

Adding the amdgpu reviewer group. This change might be contentious - we 
currently treat various broken code as calls to trap on the grounds that those 
functions might not be executed. By analogy, functions that call undefined 
functions but are not themselves called might be considered not a problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145941

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


[PATCH] D145227: [LLVM][OHOS] Clang toolchain and targets

2023-03-13 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.
This revision is now accepted and ready to land.

Looks good in general. If there are some incorrect details you'll find them 
later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145227

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


[PATCH] D145944: [Clang] Add --version and --help messages to amdgpu/nvptx-arch

2023-03-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield, ye-luo.
Herald added subscribers: kosarev, mattd, gchakrabarti, asavonic, kerbowa, tpr, 
dstuttard, yaxunl, jvesely, kzhuravl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, wdng, jholewinski.
Herald added a project: clang.

Summray:
These clang tools should print some basic help and version messages so
they are less opaque.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145944

Files:
  clang/tools/amdgpu-arch/AMDGPUArch.cpp
  clang/tools/amdgpu-arch/CMakeLists.txt
  clang/tools/nvptx-arch/CMakeLists.txt
  clang/tools/nvptx-arch/NVPTXArch.cpp

Index: clang/tools/nvptx-arch/NVPTXArch.cpp
===
--- clang/tools/nvptx-arch/NVPTXArch.cpp
+++ clang/tools/nvptx-arch/NVPTXArch.cpp
@@ -11,12 +11,25 @@
 //
 //===--===//
 
+#include "clang/Basic/Version.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/DynamicLibrary.h"
 #include "llvm/Support/Error.h"
 #include 
 #include 
 #include 
 
+using namespace llvm;
+
+static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+
+static void PrintVersion(raw_ostream &OS) {
+  OS << clang::getClangToolFullVersion("nvptx-arch") << '\n';
+}
+// Mark all our options with this category, everything else (except for -version
+// and -help) will be hidden.
+static cl::OptionCategory NVPTXArchCategory("nvptx-arch options");
+
 #if DYNAMIC_CUDA
 typedef enum cudaError_enum {
   CUDA_SUCCESS = 0,
@@ -79,6 +92,16 @@
 }
 
 int main(int argc, char *argv[]) {
+  cl::HideUnrelatedOptions(NVPTXArchCategory);
+
+  cl::SetVersionPrinter(PrintVersion);
+  cl::ParseCommandLineOptions(
+  argc, argv,
+  "A tool to detect the presence of NVIDIA devices on the system. \n\n"
+  "The tool will output each detected GPU architecture separated by a\n"
+  "newline character. If multiple GPUs of the same architecture are found\n"
+  "a string will be printed for each\n");
+
   // Attempt to load the NVPTX driver runtime.
   if (llvm::Error Err = loadCUDA()) {
 logAllUnhandledErrors(std::move(Err), llvm::errs());
Index: clang/tools/nvptx-arch/CMakeLists.txt
===
--- clang/tools/nvptx-arch/CMakeLists.txt
+++ clang/tools/nvptx-arch/CMakeLists.txt
@@ -14,6 +14,7 @@
 # If we found the CUDA library directly we just dynamically link against it.
 if(CUDAToolkit_FOUND AND NOT (LLVM_BUILD_32_BITS OR CMAKE_SIZEOF_VOID_P EQUAL 4))
   target_link_libraries(nvptx-arch PRIVATE CUDA::cuda_driver)
+  clang_target_link_libraries(nvptx-arch PRIVATE clangBasic)
 else()
   target_compile_definitions(nvptx-arch PRIVATE "DYNAMIC_CUDA")
 endif()
Index: clang/tools/amdgpu-arch/CMakeLists.txt
===
--- clang/tools/amdgpu-arch/CMakeLists.txt
+++ clang/tools/amdgpu-arch/CMakeLists.txt
@@ -15,6 +15,7 @@
 if(hsa-runtime64_FOUND AND NOT (LLVM_BUILD_32_BITS OR CMAKE_SIZEOF_VOID_P EQUAL 4))
   set_target_properties(amdgpu-arch PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON)
   target_link_libraries(amdgpu-arch PRIVATE hsa-runtime64::hsa-runtime64)
+  clang_target_link_libraries(amdgpu-arch PRIVATE clangBasic)
 else()
   target_compile_definitions(amdgpu-arch PRIVATE "DYNAMIC_HSA")
 endif()
Index: clang/tools/amdgpu-arch/AMDGPUArch.cpp
===
--- clang/tools/amdgpu-arch/AMDGPUArch.cpp
+++ clang/tools/amdgpu-arch/AMDGPUArch.cpp
@@ -11,12 +11,25 @@
 //
 //===--===//
 
+#include "clang/Basic/Version.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/DynamicLibrary.h"
 #include "llvm/Support/Error.h"
 #include 
 #include 
 #include 
 
+using namespace llvm;
+
+static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+
+// Mark all our options with this category.
+static cl::OptionCategory AMDGPUArchCategory("amdgpu-arch options");
+
+static void PrintVersion(raw_ostream &OS) {
+  OS << clang::getClangToolFullVersion("amdgpu-arch") << '\n';
+}
+
 #if DYNAMIC_HSA
 typedef enum {
   HSA_STATUS_SUCCESS = 0x0,
@@ -102,6 +115,16 @@
 }
 
 int main(int argc, char *argv[]) {
+  cl::HideUnrelatedOptions(AMDGPUArchCategory);
+
+  cl::SetVersionPrinter(PrintVersion);
+  cl::ParseCommandLineOptions(
+  argc, argv,
+  "A tool to detect the presence of AMDGPU devices on the system. \n\n"
+  "The tool will output each detected GPU architecture separated by a\n"
+  "newline character. If multiple GPUs of the same architecture are found\n"
+  "a string will be printed for each\n");
+
   // Attempt to load the HSA runtime.
   if (llvm::Error Err = loadHSA()) {
 logAllUnhandledErrors(std::move(Err), llvm::errs())

[PATCH] D145944: [Clang] Add --version and --help messages to amdgpu/nvptx-arch

2023-03-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 504670.
jhuber6 added a comment.

Add help print.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145944

Files:
  clang/tools/amdgpu-arch/AMDGPUArch.cpp
  clang/tools/amdgpu-arch/CMakeLists.txt
  clang/tools/nvptx-arch/CMakeLists.txt
  clang/tools/nvptx-arch/NVPTXArch.cpp

Index: clang/tools/nvptx-arch/NVPTXArch.cpp
===
--- clang/tools/nvptx-arch/NVPTXArch.cpp
+++ clang/tools/nvptx-arch/NVPTXArch.cpp
@@ -11,12 +11,25 @@
 //
 //===--===//
 
+#include "clang/Basic/Version.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/DynamicLibrary.h"
 #include "llvm/Support/Error.h"
 #include 
 #include 
 #include 
 
+using namespace llvm;
+
+static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+
+static void PrintVersion(raw_ostream &OS) {
+  OS << clang::getClangToolFullVersion("nvptx-arch") << '\n';
+}
+// Mark all our options with this category, everything else (except for -version
+// and -help) will be hidden.
+static cl::OptionCategory NVPTXArchCategory("nvptx-arch options");
+
 #if DYNAMIC_CUDA
 typedef enum cudaError_enum {
   CUDA_SUCCESS = 0,
@@ -79,6 +92,21 @@
 }
 
 int main(int argc, char *argv[]) {
+  cl::HideUnrelatedOptions(NVPTXArchCategory);
+
+  cl::SetVersionPrinter(PrintVersion);
+  cl::ParseCommandLineOptions(
+  argc, argv,
+  "A tool to detect the presence of NVIDIA devices on the system. \n\n"
+  "The tool will output each detected GPU architecture separated by a\n"
+  "newline character. If multiple GPUs of the same architecture are found\n"
+  "a string will be printed for each\n");
+
+  if (Help) {
+cl::PrintHelpMessage();
+return 0;
+  }
+
   // Attempt to load the NVPTX driver runtime.
   if (llvm::Error Err = loadCUDA()) {
 logAllUnhandledErrors(std::move(Err), llvm::errs());
Index: clang/tools/nvptx-arch/CMakeLists.txt
===
--- clang/tools/nvptx-arch/CMakeLists.txt
+++ clang/tools/nvptx-arch/CMakeLists.txt
@@ -14,6 +14,7 @@
 # If we found the CUDA library directly we just dynamically link against it.
 if(CUDAToolkit_FOUND AND NOT (LLVM_BUILD_32_BITS OR CMAKE_SIZEOF_VOID_P EQUAL 4))
   target_link_libraries(nvptx-arch PRIVATE CUDA::cuda_driver)
+  clang_target_link_libraries(nvptx-arch PRIVATE clangBasic)
 else()
   target_compile_definitions(nvptx-arch PRIVATE "DYNAMIC_CUDA")
 endif()
Index: clang/tools/amdgpu-arch/CMakeLists.txt
===
--- clang/tools/amdgpu-arch/CMakeLists.txt
+++ clang/tools/amdgpu-arch/CMakeLists.txt
@@ -15,6 +15,7 @@
 if(hsa-runtime64_FOUND AND NOT (LLVM_BUILD_32_BITS OR CMAKE_SIZEOF_VOID_P EQUAL 4))
   set_target_properties(amdgpu-arch PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON)
   target_link_libraries(amdgpu-arch PRIVATE hsa-runtime64::hsa-runtime64)
+  clang_target_link_libraries(amdgpu-arch PRIVATE clangBasic)
 else()
   target_compile_definitions(amdgpu-arch PRIVATE "DYNAMIC_HSA")
 endif()
Index: clang/tools/amdgpu-arch/AMDGPUArch.cpp
===
--- clang/tools/amdgpu-arch/AMDGPUArch.cpp
+++ clang/tools/amdgpu-arch/AMDGPUArch.cpp
@@ -11,12 +11,25 @@
 //
 //===--===//
 
+#include "clang/Basic/Version.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/DynamicLibrary.h"
 #include "llvm/Support/Error.h"
 #include 
 #include 
 #include 
 
+using namespace llvm;
+
+static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+
+// Mark all our options with this category.
+static cl::OptionCategory AMDGPUArchCategory("amdgpu-arch options");
+
+static void PrintVersion(raw_ostream &OS) {
+  OS << clang::getClangToolFullVersion("amdgpu-arch") << '\n';
+}
+
 #if DYNAMIC_HSA
 typedef enum {
   HSA_STATUS_SUCCESS = 0x0,
@@ -102,6 +115,21 @@
 }
 
 int main(int argc, char *argv[]) {
+  cl::HideUnrelatedOptions(AMDGPUArchCategory);
+
+  cl::SetVersionPrinter(PrintVersion);
+  cl::ParseCommandLineOptions(
+  argc, argv,
+  "A tool to detect the presence of AMDGPU devices on the system. \n\n"
+  "The tool will output each detected GPU architecture separated by a\n"
+  "newline character. If multiple GPUs of the same architecture are found\n"
+  "a string will be printed for each\n");
+
+  if (Help) {
+cl::PrintHelpMessage();
+return 0;
+  }
+
   // Attempt to load the HSA runtime.
   if (llvm::Error Err = loadHSA()) {
 logAllUnhandledErrors(std::move(Err), llvm::errs());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-13 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce updated this revision to Diff 504672.
sunshaoce marked an inline comment as done.
sunshaoce added a comment.

Address @awarzynski's comment. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

Files:
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/test/Driver/code-gen-rv64.f90
  flang/test/Driver/target-cpu-features.f90


Index: flang/test/Driver/target-cpu-features.f90
===
--- flang/test/Driver/target-cpu-features.f90
+++ flang/test/Driver/target-cpu-features.f90
@@ -22,6 +22,9 @@
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
+! RUN: %flang --target=riscv64-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
+
 
 ! Test that invalid cpu and features are ignored.
 
@@ -52,5 +55,9 @@
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" 
"-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" 
"-target-feature" "-fsgsbase"
 
+! CHECK-RV64: "-fc1" "-triple" "riscv64-unknown-linux-gnu"
+! CHECK-RV64-SAME: "-target-cpu" "generic-rv64" "-target-feature" "+m" 
"-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" 
"-target-feature" "+c"
+
+
 ! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target 
(ignoring processor)
 ! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this 
target (ignoring feature)
Index: flang/test/Driver/code-gen-rv64.f90
===
--- /dev/null
+++ flang/test/Driver/code-gen-rv64.f90
@@ -0,0 +1,14 @@
+! Test -emit-obj (RISC-V 64)
+
+! RUN: rm -f %t.o
+! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu \
+! RUN:   -target-feature +d -target-feature +c -emit-obj %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! RUN: rm -f %t.o
+! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! If Flang failed to emit target-feature info, then Flags will be 0x0.
+! CHECK: Flags: 0x5, RVC, double-float ABI
+end program
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -106,6 +106,8 @@
 break;
   case llvm::Triple::aarch64:
 [[fallthrough]];
+  case llvm::Triple::riscv64:
+[[fallthrough]];
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
 break;


Index: flang/test/Driver/target-cpu-features.f90
===
--- flang/test/Driver/target-cpu-features.f90
+++ flang/test/Driver/target-cpu-features.f90
@@ -22,6 +22,9 @@
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
+! RUN: %flang --target=riscv64-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
+
 
 ! Test that invalid cpu and features are ignored.
 
@@ -52,5 +55,9 @@
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" "-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" "-target-feature" "-fsgsbase"
 
+! CHECK-RV64: "-fc1" "-triple" "riscv64-unknown-linux-gnu"
+! CHECK-RV64-SAME: "-target-cpu" "generic-rv64" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+c"
+
+
 ! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target (ignoring processor)
 ! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this target (ignoring feature)
Index: flang/test/Driver/code-gen-rv64.f90
===
--- /dev/null
+++ flang/test/Driver/code-gen-rv64.f90
@@ -0,0 +1,14 @@
+! Test -emit-obj (RISC-V 64)
+
+! RUN: rm -f %t.o
+! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu \
+! RUN:   -target-feature +d -target-feature +c -emit-obj %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! RUN: rm -f %t.o
+! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! If Flang failed to emit target-feature info, then Flags will be 0x0.
+! CHECK: Flags: 0x5, RVC, double-float ABI
+end program
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -106,6 +106,8 @@
 break;
   case llvm::Triple::aarch64:
 [[fallthrough]];
+  case llvm::Triple::riscv64:
+[[fallthrough]];
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Tr

[PATCH] D145941: [Clang] Always use -zdefs when linking AMDGPU images

2023-03-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

This can be turned off with `-zundefs`. So we could instruct people to use 
`-Wl,-zundefs` or `-Xoffload-linker -zundefs` if the old behavior is desired.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145941

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


[PATCH] D145401: [AMDGPU] Reserve extra SGPR blocks wth XNACK "any" TID Setting

2023-03-13 Thread Austin Kerbow via Phabricator via cfe-commits
kerbowa added a comment.

Added AMDGPU group to reviewers.

Is there any objection to changing the defaults for subtargets that support 
XNACK to always reserve extra SGPRs unless -xnack is explicitly requested? This 
would impact graphics as well. The old defaults were doing the opposite and 
only reserving the extra SGPRs with +xnack, meaning the default in the absence 
of either +/-xnack will be changing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145401

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


  1   2   3   4   >