[clang] 7488dd2 - Revert "[Clang][AIX][p] Manually Claim -p in front end"

2023-03-12 Thread Michael Francis via cfe-commits

Author: Michael Francis
Date: 2023-03-12T08:14:33Z
New Revision: 7488dd25e1613894d79d69f153469545b9bf660a

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

LOG: Revert "[Clang][AIX][p] Manually Claim -p in front end"

This reverts commit 59848b9ebae6a92a4342b1e8aa32feaf5c9c4b51, as it
causes some failures in AIX-related Lit tests.

Added: 
clang/test/Driver/zos-profiling-error.c

Modified: 
clang/lib/Driver/ToolChains/AIX.cpp
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
clang/test/Driver/ibm-profiling.c



diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index 57234f235156e..15560e1c81bca 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -164,12 +164,11 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   }
 
   auto getCrt0Basename = [&Args, IsArch32Bit] {
-Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg);
 // Enable gprofiling when "-pg" is specified.
-if (A->getOption().matches(options::OPT_pg))
+if (Args.hasArg(options::OPT_pg))
   return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o";
 // Enable profiling when "-p" is specified.
-else if (A->getOption().matches(options::OPT_p))
+else if (Args.hasArg(options::OPT_p))
   return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o";
 else
   return IsArch32Bit ? "crt0.o" : "crt0_64.o";
@@ -272,7 +271,7 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
 CmdArgs.push_back("-lc");
 
-if (Args.hasArgNoClaim(options::OPT_p, options::OPT_pg)) {
+if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
"/lib/profiled"));
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 87862e028636f..79fcf4526df3e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6322,26 +6322,20 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
 << A->getAsString(Args) << TripleStr;
 }
   }
-
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
-if (TC.getTriple().isOSzOS()) {
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+if (TC.getTriple().isOSAIX()) {
+  CmdArgs.push_back("-pg");
+} else if (!TC.getTriple().isOSOpenBSD()) {
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
-if (!(TC.getTriple().isOSAIX() || TC.getTriple().isOSOpenBSD())) {
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
+if (TC.getTriple().isOSzOS()) {
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) {
-if (A->getOption().matches(options::OPT_p)) {
-  A->claim();
-  if (TC.getTriple().isOSAIX() && !Args.hasArgNoClaim(options::OPT_pg))
-CmdArgs.push_back("-pg");
-}
-  }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
   (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))

diff  --git a/clang/test/Driver/ibm-profiling.c 
b/clang/test/Driver/ibm-profiling.c
deleted file mode 100644
index 26bc0d7784373..0
--- a/clang/test/Driver/ibm-profiling.c
+++ /dev/null
@@ -1,27 +0,0 @@
-// Check that -pg throws an error on z/OS.
-// RUN: %clang -### 2>&1 --target=s390x-none-zos -S -pg %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
-
-// Check that -p is still used when not linking on AIX.
-// RUN: %clang -### 2>&1 --target=powerpc-ibm-aix7.1.0.0 -S -p -S %s \
-// RUN:   | FileCheck --check-prefix=CHECK %s
-// CHECK-NOT: warning: argument unused during compilation: '-p'
-
-// Check precedence: -pg is unused when passed first on AIX.
-// RUN: %clang -### 2>&1 --target=powerpc-ibm-aix7.1.0.0 --sysroot 
%S/Inputs/aix_ppc_tree -pg -p %s \
-// RUN:| FileCheck --check-prefix=CHECK2 %s
-// CHECK2-NOT: warning: argument unused during compilation: '-p' 
[-Wunused-command-line-argument]
-// CHECK2: "-isysroot" "[[SYSROOT:[^"]+]]"
-// CHECK2: "[[SYSROOT]]/usr/lib{{/|}}mcrt0.o"
-// CHECK2: "-L[[SYSROOT]]/lib/profiled"
-// CHECK2: "-L[[SYSROOT]]/usr/lib/profiled"
-
-// Check precedence: -p is unused when passed first on AIX.
-// RUN: %clang -### 2>&1 --target=powerpc-ibm-aix7.1.0.0 --sysroot 
%S/Inputs/aix_ppc_tree -p -pg %s \
-// RUN:| Fi

[PATCH] D145856: [clang-tidy] Let misc-const-correctness detect auto local variables that can be made const

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL requested changes to this revision.
PiotrZSL added a comment.
This revision now requires changes to proceed.

- Failed tests
- Missing tests for this change
- Missing configuration option for this change (changing default behavior)
- Missing release notes
- Missing documentation update
- auto& , auto&&, auto* still wont be ignored (that's also auto type).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145856

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


[PATCH] D145865: [clang-tidy] Multiple fixes to bugprone-exception-escape

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

- Added support for C++17 or later in tests and added new tests
- Pointers to member functions are now handled correctly in C++20
- Move constructors and operators that are explicitly declared with 
`noexcept(false)` or `throw(XYZ)` are now allowed
- It is now assumed that called noexcept functions won't throw exceptions
- Warnings will now only be printed for function definitions, not declarations
- The throw exception types are now printed as a note

  Fixes:
  - https://github.com/llvm/llvm-project/issues/40583
  - https://github.com/llvm/llvm-project/issues/43667
  - https://github.com/llvm/llvm-project/issues/46282
  - https://github.com/llvm/llvm-project/issues/49151
  - https://github.com/llvm/llvm-project/issues/51596
  - https://github.com/llvm/llvm-project/issues/54668
  - https://github.com/llvm/llvm-project/issues/54956
  - https://github.com/llvm/llvm-project/issues/55143
  - https://github.com/llvm/llvm-project/issues/56411


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145865

Files:
  clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-throw.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -1,10 +1,9 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-exception-escape %t -- \
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-exception-escape %t -- \
 // RUN: -config="{CheckOptions: [ \
 // RUN: {key: bugprone-exception-escape.IgnoredExceptions, value: 'ignored1,ignored2'}, \
 // RUN: {key: bugprone-exception-escape.FunctionsThatShouldNotThrow, value: 'enabled1,enabled2,enabled3'} \
 // RUN: ]}" \
 // RUN: -- -fexceptions
-// FIXME: Fix the checker to work in C++17 or later mode.
 
 struct throwing_destructor {
   ~throwing_destructor() {
@@ -32,11 +31,6 @@
   throw 1;
 }
 
-void throwing_throw_nothing() throw() {
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_throw_nothing' which should not throw exceptions
-  throw 1;
-}
-
 void throw_and_catch() noexcept {
   // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch' which should not throw exceptions
   try {
@@ -157,7 +151,7 @@
 }
 
 // FIXME: In this case 'a' is convertible to the handler and should be caught
-// but in reality it's thrown. Note that clang doesn't report a warning for 
+// but in reality it's thrown. Note that clang doesn't report a warning for
 // this either.
 void throw_catch_multi_ptr_5() noexcept {
   try {
@@ -254,7 +248,7 @@
 void throw_derived_catch_base_ptr_c() noexcept {
   try {
 derived d;
-throw &d; 
+throw &d;
   } catch(const base *) {
   }
 }
@@ -264,7 +258,7 @@
   try {
 derived d;
 const derived *p = &d;
-throw p; 
+throw p;
   } catch(base *) {
   }
 }
@@ -287,7 +281,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private' which should not throw exceptions
   try {
 B b;
-throw b; 
+throw b;
   } catch(A) {
   }
 }
@@ -296,7 +290,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private_ptr' which should not throw exceptions
   try {
 B b;
-throw &b; 
+throw &b;
   } catch(A *) {
   }
 }
@@ -305,7 +299,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected' which should not throw exceptions
   try {
 C c;
-throw c; 
+throw c;
   } catch(A) {
   }
 }
@@ -314,7 +308,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected_ptr' which should not throw exceptions
   try {
 C c;
-throw &c; 
+throw &c;
   } catch(A *) {
   }
 }
@@ -323,7 +317,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous' which should not throw exceptions
   try {
 E e;
-throw e; 
+throw e;
   } catch(A) {
   }
 }
@@ -332,7 +326,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception m

[PATCH] D49864: [clang-tidy] The script clang-tidy-diff.py doesn't accept 'pass by' options (--)

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.
Herald added a reviewer: njames93.
Herald added a project: All.

This need to be rebase due to conflict to land.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D49864

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


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

2023-03-12 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



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

any reason you didn't use verifyFormat here?


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] D145312: [clang-tidy] Make readability-string-compare check use header

2023-03-12 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

@PiotrZSL I believe you have landed some patches of this chain. Would you mind 
sharing how you do it? I'm not an expert in Phabricator and simply doing `arc 
patch D145312` leads to cherry-pick conflicts, and when I solve them I don't 
end up having this patch as `HEAD`. With this knowledge I will be able to help 
out closing these patches!


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

https://reviews.llvm.org/D145312

___
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-12 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: a.sidorin, shafik, donat.nagy, gamesh411, balazske.
Herald added a subscriber: martong.
Herald added a project: All.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix crash in ASTImporter for anonymous structures. There was a series of
problems exposed by https://reviews.llvm.org/D133468 (commit
69a6417406a1b0316a1fa6aeb63339d0e1d2abbd 
) in the 
ASTImporter breaking
cross-translation unit analysis. This change fixes the problem exposed
by that change for importing anonymous structures. The problem was
discovered when running clang static analysis on open source projects
using cross-translation unit analysis.

Simple test command. Produces crash without change, passes all tests
with change.

ninja ASTTests && ./tools/clang/unittests/AST/ASTTests

  --gtest_filter="*/*ImportAnonymousStruct/0"

Formatted crash stack:

ASTTests: /clang/lib/AST/ASTContext.cpp:4787:

  clang::QualType clang::ASTContext::getTypedefType(const 
clang::TypedefNameDecl*,
  clang::QualType) const: Assertion `hasSameType(Decl->getUnderlyingType(), 
Underlying)' failed.

...
 #9  clang::ASTContext::getTypedefType(clang::TypedefNameDecl const*, 
clang::QualType) const

  /clang/lib/AST/ASTContext.cpp:4789:26
  /clang/lib/AST/ASTImporter.cpp:1374:71
  /tools/clang/include/clang/AST/TypeNodes.inc:75:1
  /clang/lib/AST/ASTImporter.cpp:8663:8


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145868

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


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8474,6 +8474,45 @@
   ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportAnonymousStruct) {
+  // Tests importing of anonymous structures. This is a reduction of a real
+  // issue found in the wild into unittest case form. This crashes without
+  // the fix. Just don't crash when this unittest case is run.
+  Decl *ToTU = getToTuDecl(
+  R"(  
+  typedef struct _XDisplay Display;
+  typedef struct {
+int var;
+  } *_XPrivDisplay;
+  extern Display  *xterm_dpy;
+  int function(int);
+  int internal(Display *dpy) {
+return function(((_XPrivDisplay)dpy)->var );
+  }
+  )",
+  Lang_C99);
+  auto *ToX = FirstDeclMatcher().match(
+  ToTU, functionDecl(hasName("internal"), isDefinition()));
+  ASSERT_TRUE(ToX);
+
+  Decl *FromTU = getTuDecl(
+  R"(  
+  typedef struct _XDisplay Display;
+  typedef struct {
+int var;
+  } *_XPrivDisplay;
+  extern Display  *xterm_dpy;
+  int function(int var) {
+return ((_XPrivDisplay)xterm_dpy)->var;
+  }
+  )",
+  Lang_C99, "input1.c");
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("function"), isDefinition()));
+  auto *ToF = Import(FromF, Lang_C99);
+  EXPECT_TRUE(ToF);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1363,12 +1363,7 @@
   Expected ToDeclOrErr = import(T->getDecl());
   if (!ToDeclOrErr)
 return ToDeclOrErr.takeError();
-  ExpectedType ToUnderlyingTypeOrErr = import(T->desugar());
-  if (!ToUnderlyingTypeOrErr)
-return ToUnderlyingTypeOrErr.takeError();
-
-  return Importer.getToContext().getTypedefType(*ToDeclOrErr,
-*ToUnderlyingTypeOrErr);
+  return Importer.getToContext().getTypeDeclType(*ToDeclOrErr);
 }
 
 ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8474,6 +8474,45 @@
   ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportAnonymousStruct) {
+  // Tests importing of anonymous structures. This is a reduction of a real
+  // issue found in the wild into unittest case form. This crashes without
+  // the fix. Just don't crash when this unittest case is run.
+  Decl *ToTU = getToTuDecl(
+  R"(  
+  typedef struct _XDisplay Display;
+  typedef struct {
+int var;
+  } *_XPrivDisplay;
+  extern Display  *xterm_dpy;
+  int function(int);
+  int internal(Display *dpy) {
+return function(((_XPrivDisplay)dpy)->v

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

2023-03-12 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic created this revision.
Herald added a reviewer: ributzka.
Herald added a project: All.
Arsenic requested review of this revision.
Herald added a reviewer: dang.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- 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


Repository:
  rG LLVM Github Monorepo

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_FILE1_1 1
+#define IGNORED_FILE1_2 2
+#define IGNORED_FILE1_3 3
+
+#define IGNORED_FILE2_4 4
+#define IGNORED_FILE2_5 5
+
+typedef double IGNORED_FILE3_6;
+typedef int IGNORED_FILE3_7;
+
+typedef float NonIgnored;
+
+// CHECK-NOT: IGNORED_FILE1_1
+// CHECK-NOT: IGNORED_FILE1_2
+// CHECK-NOT: IGNORED_FILE1_3
+
+// CHECK-NOT: IGNORED_FILE2_4
+// CHECK-NOT: IGNORED_FILE2_5
+
+// CHECK-NOT: IGNORED_FILE3_6
+// CHECK-NOT: IGNORED_FILE3_7
+// CHECK: NonIgnored
+
+// expected-no-diagnostics
+
+//--- ignores-list1
+IGNORED_FILE1_1
+IGNORED_FILE1_2
+IGNORED_FILE1_3
+
+//--- ignores-list2
+IGNORED_FILE2_4
+IGNORED_FILE2_5
+
+//--- ignores-list3
+IGNORED_FILE3_6
+IGNORED_FILE3_7
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 ex

[PATCH] D145312: [clang-tidy] Make readability-string-compare check use header

2023-03-12 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

@mikecrowe I seems I cannot land this until it's rebased on top of `main`, 
would you be able to do that? Thanks!


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

https://reviews.llvm.org/D145312

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


[PATCH] D145312: [clang-tidy] Make readability-string-compare check use header

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

In D145312#4187195 , @carlosgalvezp 
wrote:

> @PiotrZSL I believe you have landed some patches of this chain. Would you 
> mind sharing how you do it? I'm not an expert in Phabricator and simply doing 
> `arc patch D145312` leads to cherry-pick conflicts, and when I solve them I 
> don't end up having this patch as `HEAD`. With this knowledge I will be able 
> to help out closing these patches!

arc patch --nobranch --skip-dependencies D145312 



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

https://reviews.llvm.org/D145312

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


[clang-tools-extra] f9dc14c - [clang-tidy] Make readability-string-compare check use header

2023-03-12 Thread Piotr Zegar via cfe-commits

Author: Mike Crowe
Date: 2023-03-12T13:32:05Z
New Revision: f9dc14cf1f7eadffa7b11b86aaeaee5af26a21c0

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

LOG: [clang-tidy] Make readability-string-compare check use  header

Improve the generic  header by adding another constructor,
std::basic_string::empty and operator!= overload set so that it can be
used to replace the custom implementation in the
readability-string-compare check.

Depends on D145311

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp

Removed: 




diff  --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
index 5cc9cd367e4d..ea9d1f9c32bf 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -18,12 +18,15 @@ struct basic_string {
   typedef basic_string _Type;
   basic_string();
   basic_string(const C *p, const A &a = A());
+  basic_string(const C *p, size_type count);
 
   ~basic_string();
 
   const C *c_str() const;
   const C *data() const;
 
+  bool empty() const;
+
   _Type& append(const C *s);
   _Type& append(const C *s, size_type n);
   _Type& assign(const C *s);
@@ -72,6 +75,10 @@ std::string operator+(const char*, const std::string&);
 bool operator==(const std::string&, const std::string&);
 bool operator==(const std::string&, const char*);
 bool operator==(const char*, const std::string&);
+
+bool operator!=(const std::string&, const std::string&);
+bool operator!=(const std::string&, const char*);
+bool operator!=(const char*, const std::string&);
 }
 
 #endif // _STRING_

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
index 45114edf2f0b..2c08b86cf72f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
@@ -1,25 +1,5 @@
-// RUN: %check_clang_tidy %s readability-string-compare %t
-
-namespace std {
-template 
-class allocator {};
-template 
-class char_traits {};
-template , typename A = 
std::allocator>
-class basic_string {
-public:
-  basic_string();
-  basic_string(const C *, unsigned int size);
-  int compare(const basic_string &str) const;
-  int compare(const C *) const;
-  int compare(int, int, const basic_string &str) const;
-  bool empty();
-};
-bool operator==(const basic_string &lhs, const basic_string &rhs);
-bool operator!=(const basic_string &lhs, const basic_string &rhs);
-bool operator==(const basic_string &lhs, const char *&rhs);
-typedef basic_string string;
-}
+// RUN: %check_clang_tidy %s readability-string-compare %t -- -- -isystem 
%clang_tidy_headers
+#include 
 
 void func(bool b);
 



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


[clang-tools-extra] c4918cb - [clang-tidy] Provide default template arguments in

2023-03-12 Thread Piotr Zegar via cfe-commits

Author: Mike Crowe
Date: 2023-03-12T13:32:45Z
New Revision: c4918cbf3ba3f6f0caefae3f283b5c05c3baf7ec

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

LOG: [clang-tidy] Provide default template arguments in 

Simplify the use of the basic_string and basic_string_view types by
providing default template arguments.

Depends on D145311

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string

Removed: 




diff  --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
index 91ae2af4d132..e9d31b929c6c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -12,7 +12,7 @@ template 
 class allocator {};
 template 
 class char_traits {};
-template 
+template , typename A = allocator>
 struct basic_string {
   typedef size_t size_type;
   typedef basic_string _Type;
@@ -55,19 +55,19 @@ struct basic_string {
   _Type& operator=(const C* s);
 };
 
-typedef basic_string, std::allocator> 
string;
-typedef basic_string, 
std::allocator> wstring;
-typedef basic_string, std::allocator> 
u16string;
-typedef basic_string, std::allocator> 
u32string;
+typedef basic_string string;
+typedef basic_string wstring;
+typedef basic_string u16string;
+typedef basic_string u32string;
 
-template 
+template >
 struct basic_string_view {
   basic_string_view(const C* s);
 };
-typedef basic_string_view> string_view;
-typedef basic_string_view> wstring_view;
-typedef basic_string_view> u16string_view;
-typedef basic_string_view> u32string_view;
+typedef basic_string_view string_view;
+typedef basic_string_view wstring_view;
+typedef basic_string_view u16string_view;
+typedef basic_string_view u32string_view;
 
 std::string operator+(const std::string&, const std::string&);
 std::string operator+(const std::string&, const char*);



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


[PATCH] D145312: [clang-tidy] Make readability-string-compare check use header

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf9dc14cf1f7e: [clang-tidy] Make readability-string-compare 
check use  header (authored by mikecrowe, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145312

Files:
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
@@ -1,25 +1,5 @@
-// RUN: %check_clang_tidy %s readability-string-compare %t
-
-namespace std {
-template 
-class allocator {};
-template 
-class char_traits {};
-template , typename A = 
std::allocator>
-class basic_string {
-public:
-  basic_string();
-  basic_string(const C *, unsigned int size);
-  int compare(const basic_string &str) const;
-  int compare(const C *) const;
-  int compare(int, int, const basic_string &str) const;
-  bool empty();
-};
-bool operator==(const basic_string &lhs, const basic_string &rhs);
-bool operator!=(const basic_string &lhs, const basic_string &rhs);
-bool operator==(const basic_string &lhs, const char *&rhs);
-typedef basic_string string;
-}
+// RUN: %check_clang_tidy %s readability-string-compare %t -- -- -isystem 
%clang_tidy_headers
+#include 
 
 void func(bool b);
 
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -18,12 +18,15 @@
   typedef basic_string _Type;
   basic_string();
   basic_string(const C *p, const A &a = A());
+  basic_string(const C *p, size_type count);
 
   ~basic_string();
 
   const C *c_str() const;
   const C *data() const;
 
+  bool empty() const;
+
   _Type& append(const C *s);
   _Type& append(const C *s, size_type n);
   _Type& assign(const C *s);
@@ -72,6 +75,10 @@
 bool operator==(const std::string&, const std::string&);
 bool operator==(const std::string&, const char*);
 bool operator==(const char*, const std::string&);
+
+bool operator!=(const std::string&, const std::string&);
+bool operator!=(const std::string&, const char*);
+bool operator!=(const char*, const std::string&);
 }
 
 #endif // _STRING_


Index: clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
@@ -1,25 +1,5 @@
-// RUN: %check_clang_tidy %s readability-string-compare %t
-
-namespace std {
-template 
-class allocator {};
-template 
-class char_traits {};
-template , typename A = std::allocator>
-class basic_string {
-public:
-  basic_string();
-  basic_string(const C *, unsigned int size);
-  int compare(const basic_string &str) const;
-  int compare(const C *) const;
-  int compare(int, int, const basic_string &str) const;
-  bool empty();
-};
-bool operator==(const basic_string &lhs, const basic_string &rhs);
-bool operator!=(const basic_string &lhs, const basic_string &rhs);
-bool operator==(const basic_string &lhs, const char *&rhs);
-typedef basic_string string;
-}
+// RUN: %check_clang_tidy %s readability-string-compare %t -- -- -isystem %clang_tidy_headers
+#include 
 
 void func(bool b);
 
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -18,12 +18,15 @@
   typedef basic_string _Type;
   basic_string();
   basic_string(const C *p, const A &a = A());
+  basic_string(const C *p, size_type count);
 
   ~basic_string();
 
   const C *c_str() const;
   const C *data() const;
 
+  bool empty() const;
+
   _Type& append(const C *s);
   _Type& append(const C *s, size_type n);
   _Type& assign(const C *s);
@@ -72,6 +75,10 @@
 bool operator==(const std::string&, const std::string&);
 bool operator==(const std::string&, const char*);
 bool operator==(const char*, const std::string&);
+
+bool operator!=(const std::string&, const std::string&);
+bool operator!=(const std::string&, const char*);
+bool operator!=(const char*, const std::string&);
 }
 
 #endif // _STRING_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 0a93abd - [clang-tidy] Make readability-container-size-empty check using header

2023-03-12 Thread Piotr Zegar via cfe-commits

Author: Mike Crowe
Date: 2023-03-12T13:32:29Z
New Revision: 0a93abd9765809bb13cfdb43794bf17e9ad5e137

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

LOG: [clang-tidy] Make readability-container-size-empty check using  
header

Improve the generic  header by adding the size() method so that
it can be used to replace the custom implementation in the
readability-container-size-empty check.

This requires fixing an incorrect comparison of a std::wstring with a
char string literal.

Unfortunately, removing the custom basic_string implementation means
fixing the line numbers for many of the checks.

Depends on D145312

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string

clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Removed: 




diff  --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
index ea9d1f9c32bf..91ae2af4d132 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -26,6 +26,7 @@ struct basic_string {
   const C *data() const;
 
   bool empty() const;
+  size_type size() const;
 
   _Type& append(const C *s);
   _Type& append(const C *s, size_type n);
@@ -79,6 +80,10 @@ bool operator==(const char*, const std::string&);
 bool operator!=(const std::string&, const std::string&);
 bool operator!=(const std::string&, const char*);
 bool operator!=(const char*, const std::string&);
+
+bool operator==(const std::wstring&, const std::wstring&);
+bool operator==(const std::wstring&, const wchar_t*);
+bool operator==(const wchar_t*, const std::wstring&);
 }
 
 #endif // _STRING_

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
index 47606070d69c..28ce8d5f8cd3 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -1,6 +1,7 @@
 // RUN: %check_clang_tidy %s readability-container-size-empty %t -- \
 // RUN: -config="{CheckOptions: [{key: 
readability-container-size-empty.ExcludedComparisonTypes , value: 
'::std::array;::IgnoredDummyType'}]}" \
-// RUN: -- -fno-delayed-template-parsing
+// RUN: -- -fno-delayed-template-parsing -isystem %clang_tidy_headers
+#include 
 
 namespace std {
 template  struct vector {
@@ -11,20 +12,6 @@ template  struct vector {
   bool empty() const;
 };
 
-template  struct basic_string {
-  basic_string();
-  bool operator==(const basic_string& other) const;
-  bool operator!=(const basic_string& other) const;
-  bool operator==(const char *) const;
-  bool operator!=(const char *) const;
-  basic_string operator+(const basic_string& other) const;
-  unsigned long size() const;
-  bool empty() const;
-};
-
-typedef basic_string string;
-typedef basic_string wstring;
-
 inline namespace __v2 {
 template  struct set {
   set();
@@ -125,12 +112,12 @@ bool returnsBool() {
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be 
used to check for emptiness instead of 'size' [readability-container-size-empty]
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :34:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :21:8: note: method 'set'::empty() defined here
   if (intSet == std::set())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be 
used to check for emptiness
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :34:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :21:8: note: method 'set'::empty() defined here
   if (s_func() == "")
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
@@ -155,7 +142,7 @@ bool returnsBool() {
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
   // CHECK-FIXES: {{^  }}if (wstr.empty()){{$}}
-  if (wstr == "")
+  if (wstr == L"")
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
   // CHECK-FIXES: {{^  }}if (wstr.empty()){{$}}
@@ -452,7 +439,7 @@ class ConstructWithBoolField {
 public:
   ConstructWithBoolField(const std::vector &C) : B(C.size()) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:57: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :12:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}Construct

[PATCH] D145313: [clang-tidy] Make readability-container-size-empty check using header

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0a93abd97658: [clang-tidy] Make 
readability-container-size-empty check using  header (authored by 
mikecrowe, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145313

Files:
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -1,6 +1,7 @@
 // RUN: %check_clang_tidy %s readability-container-size-empty %t -- \
 // RUN: -config="{CheckOptions: [{key: readability-container-size-empty.ExcludedComparisonTypes , value: '::std::array;::IgnoredDummyType'}]}" \
-// RUN: -- -fno-delayed-template-parsing
+// RUN: -- -fno-delayed-template-parsing -isystem %clang_tidy_headers
+#include 
 
 namespace std {
 template  struct vector {
@@ -11,20 +12,6 @@
   bool empty() const;
 };
 
-template  struct basic_string {
-  basic_string();
-  bool operator==(const basic_string& other) const;
-  bool operator!=(const basic_string& other) const;
-  bool operator==(const char *) const;
-  bool operator!=(const char *) const;
-  basic_string operator+(const basic_string& other) const;
-  unsigned long size() const;
-  bool empty() const;
-};
-
-typedef basic_string string;
-typedef basic_string wstring;
-
 inline namespace __v2 {
 template  struct set {
   set();
@@ -125,12 +112,12 @@
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :34:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :21:8: note: method 'set'::empty() defined here
   if (intSet == std::set())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :34:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :21:8: note: method 'set'::empty() defined here
   if (s_func() == "")
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
@@ -155,7 +142,7 @@
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
   // CHECK-FIXES: {{^  }}if (wstr.empty()){{$}}
-  if (wstr == "")
+  if (wstr == L"")
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
   // CHECK-FIXES: {{^  }}if (wstr.empty()){{$}}
@@ -452,7 +439,7 @@
 public:
   ConstructWithBoolField(const std::vector &C) : B(C.size()) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:57: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :12:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}ConstructWithBoolField(const std::vector &C) : B(!C.empty()) {}
 };
 
@@ -460,21 +447,21 @@
   std::vector C;
   bool B = C.size();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :12:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}bool B = !C.empty();
 };
 
 int func(const std::vector &C) {
   return C.size() ? 0 : 1;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :12:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}return !C.empty() ? 0 : 1;
 }
 
 constexpr Lazy L;
 static_assert(!L.size(), "");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :103:18: note: method 'Lazy'::empty() defined here
+// CHECK-MESSAGES: :90:18: note: method 'Lazy'::empty() defined here
 // CHECK-FIXES: {{^}}static_assert(L.empty(), "");
 
 struct StructWithLazyNoexcept {
@@ -489,7 +476,7 @@
   if (v.size())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
-  // CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
+  // CHECK-MESSAGES: :12:8: note: method 'vector'::empty() defined here
   // CHECK-FIXES: {{^  }}if (!v.empty()){{$}}
   if (v == std::vector())
 ;
@@ -498,24 +485,24 @@
   // CHECK-FIXES-NEXT: ;
   CHECKSIZE(v);
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
-  // CHECK-MESSAGES: :11:8: note: metho

[PATCH] D145724: [clang-tidy] Provide default template arguments in

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4918cbf3ba3: [clang-tidy] Provide default template 
arguments in  (authored by mikecrowe, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145724

Files:
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string


Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -12,7 +12,7 @@
 class allocator {};
 template 
 class char_traits {};
-template 
+template , typename A = allocator>
 struct basic_string {
   typedef size_t size_type;
   typedef basic_string _Type;
@@ -55,19 +55,19 @@
   _Type& operator=(const C* s);
 };
 
-typedef basic_string, std::allocator> 
string;
-typedef basic_string, 
std::allocator> wstring;
-typedef basic_string, std::allocator> 
u16string;
-typedef basic_string, std::allocator> 
u32string;
+typedef basic_string string;
+typedef basic_string wstring;
+typedef basic_string u16string;
+typedef basic_string u32string;
 
-template 
+template >
 struct basic_string_view {
   basic_string_view(const C* s);
 };
-typedef basic_string_view> string_view;
-typedef basic_string_view> wstring_view;
-typedef basic_string_view> u16string_view;
-typedef basic_string_view> u32string_view;
+typedef basic_string_view string_view;
+typedef basic_string_view wstring_view;
+typedef basic_string_view u16string_view;
+typedef basic_string_view u32string_view;
 
 std::string operator+(const std::string&, const std::string&);
 std::string operator+(const std::string&, const char*);


Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -12,7 +12,7 @@
 class allocator {};
 template 
 class char_traits {};
-template 
+template , typename A = allocator>
 struct basic_string {
   typedef size_t size_type;
   typedef basic_string _Type;
@@ -55,19 +55,19 @@
   _Type& operator=(const C* s);
 };
 
-typedef basic_string, std::allocator> string;
-typedef basic_string, std::allocator> wstring;
-typedef basic_string, std::allocator> u16string;
-typedef basic_string, std::allocator> u32string;
+typedef basic_string string;
+typedef basic_string wstring;
+typedef basic_string u16string;
+typedef basic_string u32string;
 
-template 
+template >
 struct basic_string_view {
   basic_string_view(const C* s);
 };
-typedef basic_string_view> string_view;
-typedef basic_string_view> wstring_view;
-typedef basic_string_view> u16string_view;
-typedef basic_string_view> u32string_view;
+typedef basic_string_view string_view;
+typedef basic_string_view wstring_view;
+typedef basic_string_view u16string_view;
+typedef basic_string_view u32string_view;
 
 std::string operator+(const std::string&, const std::string&);
 std::string operator+(const std::string&, const char*);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

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

@ccotter Do we commit this, or you plan to still change something here ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D145479: [clang][ASTImporter] Import typedefs to distinct records as distinct nodes.

2023-03-12 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers accepted this revision.
vabridgers 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/D145479/new/

https://reviews.llvm.org/D145479

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


[PATCH] D145312: [clang-tidy] Make readability-string-compare check use header

2023-03-12 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D145312#4187247 , @PiotrZSL wrote:

> In D145312#4187195 , @carlosgalvezp 
> wrote:
>
>> @PiotrZSL I believe you have landed some patches of this chain. Would you 
>> mind sharing how you do it? I'm not an expert in Phabricator and simply 
>> doing `arc patch D145312` leads to cherry-pick conflicts, and when I solve 
>> them I don't end up having this patch as `HEAD`. With this knowledge I will 
>> be able to help out closing these patches!
>
> arc patch --nobranch --skip-dependencies D145312 
> 
> I will push them...

Ahh that was it, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145312

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


[PATCH] D129070: [clang-tidy] Fixed an issue in readability-identifier-naming not using options specified.

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 504434.
PiotrZSL added a comment.

Rebase on top of main + Change llvm::Optional into std::optional


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129070

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-empty-options.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-empty-options.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-empty-options.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: { \
+// RUN: readability-identifier-naming.GlobalConstantPrefix: "", \
+// RUN: readability-identifier-naming.GlobalVariablePrefix: g_ }}'
+
+int BadGlobalVariable;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global 
variable 'BadGlobalVariable' [readability-identifier-naming]
+// CHECK-FIXES: int g_BadGlobalVariable;
+int g_GoodGlobalVariable;
+
+const int GoodGlobalConstant = 0;
+const int g_IgnoreGlobalConstant = 0;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -208,6 +208,11 @@
   ` check when warning would be
   emitted in constructor for virtual base class initialization.
 
+- Fixed an issue in :doc:`readability-identifier-naming
+  ` when specifying an empty
+  string for ``Prefix`` or ``Suffix`` options could result in the style not
+  being used.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -68,8 +68,8 @@
   struct NamingStyle {
 NamingStyle() = default;
 
-NamingStyle(std::optional Case, const std::string &Prefix,
-const std::string &Suffix, const std::string &IgnoredRegexpStr,
+NamingStyle(std::optional Case, StringRef Prefix,
+StringRef Suffix, StringRef IgnoredRegexpStr,
 HungarianPrefixType HPType);
 NamingStyle(const NamingStyle &O) = delete;
 NamingStyle &operator=(NamingStyle &&O) = default;
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -230,9 +230,8 @@
 // clang-format on
 
 IdentifierNamingCheck::NamingStyle::NamingStyle(
-std::optional Case,
-const std::string &Prefix, const std::string &Suffix,
-const std::string &IgnoredRegexpStr, HungarianPrefixType HPType)
+std::optional Case, StringRef Prefix,
+StringRef Suffix, StringRef IgnoredRegexpStr, HungarianPrefixType HPType)
 : Case(Case), Prefix(Prefix), Suffix(Suffix),
   IgnoredRegexpStr(IgnoredRegexpStr), HPType(HPType) {
   if (!IgnoredRegexpStr.empty()) {
@@ -265,22 +264,21 @@
 
 memcpy(&StyleString[StyleSize], "IgnoredRegexp", 13);
 StyleString.truncate(StyleSize + 13);
-StringRef IgnoredRegexpStr = Options.get(StyleString, "");
+std::optional IgnoredRegexpStr = Options.get(StyleString);
 memcpy(&StyleString[StyleSize], "Prefix", 6);
 StyleString.truncate(StyleSize + 6);
-std::string Prefix(Options.get(StyleString, ""));
+std::optional Prefix(Options.get(StyleString));
 // Fast replacement of [Pre]fix -> [Suf]fix.
 memcpy(&StyleString[StyleSize], "Suf", 3);
-std::string Postfix(Options.get(StyleString, ""));
+std::optional Postfix(Options.get(StyleString));
 memcpy(&StyleString[StyleSize], "Case", 4);
 StyleString.pop_back_n(2);
-auto CaseOptional =
+std::optional CaseOptional =
 Options.get(StyleString);
 
-if (CaseOptional || !Prefix.empty() || !Postfix.empty() ||
-!IgnoredRegexpStr.empty() || HPTOpt)
-  Styles[I].emplace(std::move(CaseOptional), std::move(Prefix),
-std::move(Postfix), IgnoredRegexpStr.str(),
+if (CaseOptional || Prefix || Postfix || IgnoredRegexpStr || HPTOpt)
+  Styles[I].emplace(std::move(CaseOptional), Prefix.value_or(""),
+Postfix.value_or(""), IgnoredRegexpStr.value_or(""),
 HPTOpt.value_or(IdentifierNamingCheck::HPT_Off));
   }
   bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false);


Index: clang-too

[PATCH] D145865: [clang-tidy] Multiple fixes to bugprone-exception-escape

2023-03-12 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:491
 if (const auto *ThrownExpr = Throw->getSubExpr()) {
-  const auto *ThrownType =
-  ThrownExpr->getType()->getUnqualifiedDesugaredType();
-  if (ThrownType->isReferenceType())
-ThrownType = ThrownType->castAs()
- ->getPointeeType()
- ->getUnqualifiedDesugaredType();
-  Results.registerException(
-  ThrownExpr->getType()->getUnqualifiedDesugaredType());
+  const auto *ThrownType = ThrownExpr->getType()
+   .getCanonicalType()

Please don't use `auto` unless type is explicitly stated in same statement or 
iterator.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:514
   } else {
-const auto *CaughtType =
-Catch->getCaughtType()->getUnqualifiedDesugaredType();
-if (CaughtType->isReferenceType()) {
-  CaughtType = CaughtType->castAs()
-   ->getPointeeType()
-   ->getUnqualifiedDesugaredType();
-}
-
+const auto *CaughtType = Catch->getCaughtType()
+ .getCanonicalType()

Ditto.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:211
 
+- Improved :doc:`bugprone-exception-escape
+  ` by excluding explicitly

Please keep alphabetical order (by check name) in this section.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145865

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


[PATCH] D145865: [clang-tidy] Multiple fixes to bugprone-exception-escape

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 50.
PiotrZSL added a comment.

Review fixes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145865

Files:
  clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-throw.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -1,10 +1,9 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-exception-escape %t -- \
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-exception-escape %t -- \
 // RUN: -config="{CheckOptions: [ \
 // RUN: {key: bugprone-exception-escape.IgnoredExceptions, value: 'ignored1,ignored2'}, \
 // RUN: {key: bugprone-exception-escape.FunctionsThatShouldNotThrow, value: 'enabled1,enabled2,enabled3'} \
 // RUN: ]}" \
 // RUN: -- -fexceptions
-// FIXME: Fix the checker to work in C++17 or later mode.
 
 struct throwing_destructor {
   ~throwing_destructor() {
@@ -32,11 +31,6 @@
   throw 1;
 }
 
-void throwing_throw_nothing() throw() {
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_throw_nothing' which should not throw exceptions
-  throw 1;
-}
-
 void throw_and_catch() noexcept {
   // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch' which should not throw exceptions
   try {
@@ -157,7 +151,7 @@
 }
 
 // FIXME: In this case 'a' is convertible to the handler and should be caught
-// but in reality it's thrown. Note that clang doesn't report a warning for 
+// but in reality it's thrown. Note that clang doesn't report a warning for
 // this either.
 void throw_catch_multi_ptr_5() noexcept {
   try {
@@ -254,7 +248,7 @@
 void throw_derived_catch_base_ptr_c() noexcept {
   try {
 derived d;
-throw &d; 
+throw &d;
   } catch(const base *) {
   }
 }
@@ -264,7 +258,7 @@
   try {
 derived d;
 const derived *p = &d;
-throw p; 
+throw p;
   } catch(base *) {
   }
 }
@@ -287,7 +281,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private' which should not throw exceptions
   try {
 B b;
-throw b; 
+throw b;
   } catch(A) {
   }
 }
@@ -296,7 +290,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private_ptr' which should not throw exceptions
   try {
 B b;
-throw &b; 
+throw &b;
   } catch(A *) {
   }
 }
@@ -305,7 +299,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected' which should not throw exceptions
   try {
 C c;
-throw c; 
+throw c;
   } catch(A) {
   }
 }
@@ -314,7 +308,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected_ptr' which should not throw exceptions
   try {
 C c;
-throw &c; 
+throw &c;
   } catch(A *) {
   }
 }
@@ -323,7 +317,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous' which should not throw exceptions
   try {
 E e;
-throw e; 
+throw e;
   } catch(A) {
   }
 }
@@ -332,7 +326,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous_ptr' which should not throw exceptions
   try {
 E e;
-throw e; 
+throw e;
   } catch(A) {
   }
 }
@@ -401,7 +395,7 @@
 }
 
 namespace b {
-  inline int foo() { return 0; };
+  int foo() { return 0; };
 
   void throw_inline_catch_regular() noexcept {
 try {
@@ -412,12 +406,12 @@
 }
 
 namespace c {
-  inline int foo() noexcept { return 0; };
+  int foo() noexcept { return 0; };
 
   void throw_noexcept_catch_regular() noexcept {
 try {
   throw &foo;
-} catch(int (*)()) {
+} catch(int (*)() noexcept) {
 }
   }
 }
@@ -557,7 +551,9 @@
   throw 1;
 }
 
-void explicit_int_thrower() throw(int);
+void explicit_thrower() noexcept(false) {
+  throw 1;
+}
 
 void indirect_implicit() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_implicit' which should not throw exceptions
@@ -566,7 +562,7 @@
 
 void indirect_explicit() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in functi

[PATCH] D145865: [clang-tidy] Multiple fixes to bugprone-exception-escape

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 504448.
PiotrZSL added a comment.

Update documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145865

Files:
  clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-throw.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -1,10 +1,9 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-exception-escape %t -- \
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-exception-escape %t -- \
 // RUN: -config="{CheckOptions: [ \
 // RUN: {key: bugprone-exception-escape.IgnoredExceptions, value: 'ignored1,ignored2'}, \
 // RUN: {key: bugprone-exception-escape.FunctionsThatShouldNotThrow, value: 'enabled1,enabled2,enabled3'} \
 // RUN: ]}" \
 // RUN: -- -fexceptions
-// FIXME: Fix the checker to work in C++17 or later mode.
 
 struct throwing_destructor {
   ~throwing_destructor() {
@@ -32,11 +31,6 @@
   throw 1;
 }
 
-void throwing_throw_nothing() throw() {
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_throw_nothing' which should not throw exceptions
-  throw 1;
-}
-
 void throw_and_catch() noexcept {
   // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch' which should not throw exceptions
   try {
@@ -157,7 +151,7 @@
 }
 
 // FIXME: In this case 'a' is convertible to the handler and should be caught
-// but in reality it's thrown. Note that clang doesn't report a warning for 
+// but in reality it's thrown. Note that clang doesn't report a warning for
 // this either.
 void throw_catch_multi_ptr_5() noexcept {
   try {
@@ -254,7 +248,7 @@
 void throw_derived_catch_base_ptr_c() noexcept {
   try {
 derived d;
-throw &d; 
+throw &d;
   } catch(const base *) {
   }
 }
@@ -264,7 +258,7 @@
   try {
 derived d;
 const derived *p = &d;
-throw p; 
+throw p;
   } catch(base *) {
   }
 }
@@ -287,7 +281,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private' which should not throw exceptions
   try {
 B b;
-throw b; 
+throw b;
   } catch(A) {
   }
 }
@@ -296,7 +290,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private_ptr' which should not throw exceptions
   try {
 B b;
-throw &b; 
+throw &b;
   } catch(A *) {
   }
 }
@@ -305,7 +299,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected' which should not throw exceptions
   try {
 C c;
-throw c; 
+throw c;
   } catch(A) {
   }
 }
@@ -314,7 +308,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected_ptr' which should not throw exceptions
   try {
 C c;
-throw &c; 
+throw &c;
   } catch(A *) {
   }
 }
@@ -323,7 +317,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous' which should not throw exceptions
   try {
 E e;
-throw e; 
+throw e;
   } catch(A) {
   }
 }
@@ -332,7 +326,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous_ptr' which should not throw exceptions
   try {
 E e;
-throw e; 
+throw e;
   } catch(A) {
   }
 }
@@ -401,7 +395,7 @@
 }
 
 namespace b {
-  inline int foo() { return 0; };
+  int foo() { return 0; };
 
   void throw_inline_catch_regular() noexcept {
 try {
@@ -412,12 +406,12 @@
 }
 
 namespace c {
-  inline int foo() noexcept { return 0; };
+  int foo() noexcept { return 0; };
 
   void throw_noexcept_catch_regular() noexcept {
 try {
   throw &foo;
-} catch(int (*)()) {
+} catch(int (*)() noexcept) {
 }
   }
 }
@@ -557,7 +551,9 @@
   throw 1;
 }
 
-void explicit_int_thrower() throw(int);
+void explicit_thrower() noexcept(false) {
+  throw 1;
+}
 
 void indirect_implicit() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_implicit' which should not throw exceptions
@@ -566,7 +562,7 @@
 
 void indirect_explicit() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown i

[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-03-12 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

Yes, I'm ready for this to be committed. I don't have commit access, but if 
anyone could commit this on my behalf with `Chris Cotter 
` that'd be great!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-03-12 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp:189
+  getLangOpts().CPlusPlus2b
+  ? hasAnyName("::std::print", "::std::format")
+  : hasName("::std::format"))),

PiotrZSL wrote:
> mikecrowe wrote:
> > mikecrowe wrote:
> > > PiotrZSL wrote:
> > > > Please introduce configuration option to specify custom functions.
> > > > For example if some project (like mine) is wrapping fmt::format with 
> > > > some variadic template function, then such function could be specified.
> > > > Same goes to things like some loggers.
> > > > 
> > > > Check utils/OptionsUtils.h for configuration, and  utils/Matchers.h 
> > > > (matchesAnyListedName)
> > > > Please introduce configuration option to specify custom functions.
> > > > For example if some project (like mine) is wrapping fmt::format with 
> > > > some variadic template function, then such function could be specified.
> > > 
> > > That's exactly where this change originated (as part of [[ 
> > > https://github.com/mikecrowe/clang-tidy-fmt | my clang-tidy fmt fork ]], 
> > > which I hope to submit for review soon once I've made it configurable too 
> > > and improved the test cases.)
> > > 
> > > > Same goes to things like some loggers.
> > > > 
> > > > Check utils/OptionsUtils.h for configuration, and  utils/Matchers.h 
> > > > (matchesAnyListedName)
> > > 
> > > Thanks for the pointer. I shall study those files for how to support this.
> > > 
> > > Do you think that the change can land like in its current state first? Or 
> > > would you prefer that the configuration option is added at the same time?
> > > Please introduce configuration option to specify custom functions.
> > > For example if some project (like mine) is wrapping fmt::format with some 
> > > variadic template function, then such function could be specified.
> > 
> > I could add some sort of `readability-redundant-string-cstr.PrintFunction` 
> > option or `readability-redundant-string-cstr.FormatFunction` option, but 
> > reducing this to its fundamental behaviour would be "a function that takes 
> > `const char *` arguments that is also willing to take `std::string` 
> > arguments". I'm struggling to find a sensible name for such an option. 
> > Maybe 
> > `readability-redundant-string-cstr.StdStringAcceptingFunction=::fmt::format`?
> >  Or just `readability-redundant-string-cstr.FunctionCall=::fmt::format`?
> > 
> > > Same goes to things like some loggers.
> > 
> > Loggers may be classes, so there would need to be an option that specifies 
> > a class name (or even a base class name) and a method name (which may be an 
> > operator.) See [[ 
> > https://github.com/mikecrowe/clang-tidy-fmt/blob/7ace8a3ff41e9679104fe558835b0ef3cb33d969/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp#L196
> >  | this hard-coded example ]] (If it's not obvious, there's a description 
> > in the [[ 
> > https://github.com/mikecrowe/clang-tidy-fmt/blob/7ace8a3ff41e9679104fe558835b0ef3cb33d969/README.md?plain=1#L103
> >  | README ]]. In such cases the options could be 
> > `readability-redundant-string-cstr.Class=::BaseTrace` and 
> > `readability-redundant-string-cstr.Method=Log` or 
> > `readability-redundant-string-cstr.Operator=()`, but then it would be hard 
> > to tie together the right classes and methods. That could be avoided with 
> > something like 
> > `readability-redundant-string-cstr.MemberFunctionCall=::BaseTrace::operator(),::NullTrace::operator()`
> >  and some parsing I suppose.
> > 
> > Regardless, I'll try and get the simple case working and await suggestions 
> > for appropriate option names.
> > 
> > Thanks again for the suggestions.
> > 
> I asked AI, and it suggested 
> readability-redundant-string-cstr.FormattingFunctionsList.
> Also, I thing that matchesAnyListedName should support things like 
> '::NullTrace::operator()', so one option should be sufficient.
> 
> FormattingFunctionsList:
> A semicolon-separated list of (fully qualified) function/method/operator 
> names, with the requirement that 
> any parameter capable of accepting a 'const char*' input should also be able 
> to accept 'std::string' or 
> 'std::string_view' inputs, or proper overload candidates that can do so 
> should exist.
Far be it from me to question the wisdom of the AI :) , but my point was that 
the check works for any function that accepts `const char *` parameters that 
could equally well be `std::string` parameters. It's not limitted to formatting 
functions. Despite this, I suspect that if the majority use case is formatting 
functions then maybe it's more helpful to use a name connected with that for 
discoverability.

In my prototype (which is proving easier to implement than I expected so far), 
I've used `readability-redundant-string-cstr.StringParameterFunctions`, which I 
can't say I'm entirely 

[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

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



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp:189
+  getLangOpts().CPlusPlus2b
+  ? hasAnyName("::std::print", "::std::format")
+  : hasName("::std::format"))),

mikecrowe wrote:
> PiotrZSL wrote:
> > mikecrowe wrote:
> > > mikecrowe wrote:
> > > > PiotrZSL wrote:
> > > > > Please introduce configuration option to specify custom functions.
> > > > > For example if some project (like mine) is wrapping fmt::format with 
> > > > > some variadic template function, then such function could be 
> > > > > specified.
> > > > > Same goes to things like some loggers.
> > > > > 
> > > > > Check utils/OptionsUtils.h for configuration, and  utils/Matchers.h 
> > > > > (matchesAnyListedName)
> > > > > Please introduce configuration option to specify custom functions.
> > > > > For example if some project (like mine) is wrapping fmt::format with 
> > > > > some variadic template function, then such function could be 
> > > > > specified.
> > > > 
> > > > That's exactly where this change originated (as part of [[ 
> > > > https://github.com/mikecrowe/clang-tidy-fmt | my clang-tidy fmt fork 
> > > > ]], which I hope to submit for review soon once I've made it 
> > > > configurable too and improved the test cases.)
> > > > 
> > > > > Same goes to things like some loggers.
> > > > > 
> > > > > Check utils/OptionsUtils.h for configuration, and  utils/Matchers.h 
> > > > > (matchesAnyListedName)
> > > > 
> > > > Thanks for the pointer. I shall study those files for how to support 
> > > > this.
> > > > 
> > > > Do you think that the change can land like in its current state first? 
> > > > Or would you prefer that the configuration option is added at the same 
> > > > time?
> > > > Please introduce configuration option to specify custom functions.
> > > > For example if some project (like mine) is wrapping fmt::format with 
> > > > some variadic template function, then such function could be specified.
> > > 
> > > I could add some sort of 
> > > `readability-redundant-string-cstr.PrintFunction` option or 
> > > `readability-redundant-string-cstr.FormatFunction` option, but reducing 
> > > this to its fundamental behaviour would be "a function that takes `const 
> > > char *` arguments that is also willing to take `std::string` arguments". 
> > > I'm struggling to find a sensible name for such an option. Maybe 
> > > `readability-redundant-string-cstr.StdStringAcceptingFunction=::fmt::format`?
> > >  Or just `readability-redundant-string-cstr.FunctionCall=::fmt::format`?
> > > 
> > > > Same goes to things like some loggers.
> > > 
> > > Loggers may be classes, so there would need to be an option that 
> > > specifies a class name (or even a base class name) and a method name 
> > > (which may be an operator.) See [[ 
> > > https://github.com/mikecrowe/clang-tidy-fmt/blob/7ace8a3ff41e9679104fe558835b0ef3cb33d969/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp#L196
> > >  | this hard-coded example ]] (If it's not obvious, there's a description 
> > > in the [[ 
> > > https://github.com/mikecrowe/clang-tidy-fmt/blob/7ace8a3ff41e9679104fe558835b0ef3cb33d969/README.md?plain=1#L103
> > >  | README ]]. In such cases the options could be 
> > > `readability-redundant-string-cstr.Class=::BaseTrace` and 
> > > `readability-redundant-string-cstr.Method=Log` or 
> > > `readability-redundant-string-cstr.Operator=()`, but then it would be 
> > > hard to tie together the right classes and methods. That could be avoided 
> > > with something like 
> > > `readability-redundant-string-cstr.MemberFunctionCall=::BaseTrace::operator(),::NullTrace::operator()`
> > >  and some parsing I suppose.
> > > 
> > > Regardless, I'll try and get the simple case working and await 
> > > suggestions for appropriate option names.
> > > 
> > > Thanks again for the suggestions.
> > > 
> > I asked AI, and it suggested 
> > readability-redundant-string-cstr.FormattingFunctionsList.
> > Also, I thing that matchesAnyListedName should support things like 
> > '::NullTrace::operator()', so one option should be sufficient.
> > 
> > FormattingFunctionsList:
> > A semicolon-separated list of (fully qualified) function/method/operator 
> > names, with the requirement that 
> > any parameter capable of accepting a 'const char*' input should also be 
> > able to accept 'std::string' or 
> > 'std::string_view' inputs, or proper overload candidates that can do so 
> > should exist.
> Far be it from me to question the wisdom of the AI :) , but my point was that 
> the check works for any function that accepts `const char *` parameters that 
> could equally well be `std::string` parameters. It's not limitted to 
> formatting functions. Despite this, I suspect that if the majority use case 
> is formatting functions then maybe it's more helpful to use a name connect

[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 504454.
PiotrZSL added a comment.

Rebase + Fix order of checks in ReleaseNotes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
@@ -0,0 +1,328 @@
+// RUN: %check_clang_tidy -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes, value: true}]}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffix=,CXX14 -std=c++14 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes, value: true}]}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffix=,NOSUBEXPR -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove, value: false},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes, value: true}]}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffix=,UNNAMED -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: false},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes, value: true}]}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffix=,NONDEDUCED -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes, value: false}]}" -- -fno-delayed-template-parsing
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct remove_reference;
+
+template  struct remove_reference { typedef _Tp type; };
+template  struct remove_reference<_Tp&> { typedef _Tp type; };
+template  struct remove_reference<_Tp&&> { typedef _Tp type; };
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept;
+
+template 
+constexpr _Tp &&
+forward(typename remove_reference<_Tp>::type &__t) noexcept;
+
+}
+// NOLINTEND
+
+struct Obj {
+  Obj();
+  Obj(const Obj&);
+  Obj& operator=(const Obj&);
+  Obj(Obj&&);
+  Obj& operator=(Obj&&);
+  void member() const;
+};
+
+void consumes_object(Obj);
+
+void never_moves_param(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void just_a_declaration(Obj&& o);
+
+void copies_object(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  Obj copy = o;
+}
+
+template 
+void never_moves_param_template(Obj&& o, T t) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void never_moves_params(Obj&& o1, Obj&& o2) {
+  // CHECK-ME

[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-03-12 Thread Piotr Zegar 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 rGc491c9170239: [clang-tidy] Implement CppCoreGuideline F.18 
(authored by ccotter, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
@@ -0,0 +1,328 @@
+// RUN: %check_clang_tidy -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes, value: true}]}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffix=,CXX14 -std=c++14 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes, value: true}]}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffix=,NOSUBEXPR -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove, value: false},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes, value: true}]}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffix=,UNNAMED -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: false},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes, value: true}]}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffix=,NONDEDUCED -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: true},{key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes, value: false}]}" -- -fno-delayed-template-parsing
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct remove_reference;
+
+template  struct remove_reference { typedef _Tp type; };
+template  struct remove_reference<_Tp&> { typedef _Tp type; };
+template  struct remove_reference<_Tp&&> { typedef _Tp type; };
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept;
+
+template 
+constexpr _Tp &&
+forward(typename remove_reference<_Tp>::type &__t) noexcept;
+
+}
+// NOLINTEND
+
+struct Obj {
+  Obj();
+  Obj(const Obj&);
+  Obj& operator=(const Obj&);
+  Obj(Obj&&);
+  Obj& operator=(Obj&&);
+  void member() const;
+};
+
+void consumes_object(Obj);
+
+void never_moves_param(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void just_a_declaration(Obj&& o);
+
+void copies_object(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  Obj copy = o;
+}
+
+template 
+void never_moves_param_template(Obj&& o, T t) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: rvalue reference parameter 'o' is never moved from inside the function body

[clang-tools-extra] c491c91 - [clang-tidy] Implement CppCoreGuideline F.18

2023-03-12 Thread Piotr Zegar via cfe-commits

Author: Chris Cotter
Date: 2023-03-12T16:58:08Z
New Revision: c491c917023905815d6b4b81f4c5f632b02895c3

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

LOG: [clang-tidy] Implement CppCoreGuideline F.18

Warn when an rvalue reference function paramter is never moved
from within the function body.

Reviewed By: carlosgalvezp

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

Added: 

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

clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
index 4210c3ea03fc8..0804675c63949 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
@@ -29,6 +29,7 @@ add_clang_library(clangTidyCppCoreGuidelinesModule
   ProTypeStaticCastDowncastCheck.cpp
   ProTypeUnionAccessCheck.cpp
   ProTypeVarargCheck.cpp
+  RvalueReferenceParamNotMovedCheck.cpp
   SlicingCheck.cpp
   SpecialMemberFunctionsCheck.cpp
   VirtualClassDestructorCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
index ac4b8d7b01d7a..5bd9648fe8371 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -38,6 +38,7 @@
 #include "ProTypeStaticCastDowncastCheck.h"
 #include "ProTypeUnionAccessCheck.h"
 #include "ProTypeVarargCheck.h"
+#include "RvalueReferenceParamNotMovedCheck.h"
 #include "SlicingCheck.h"
 #include "SpecialMemberFunctionsCheck.h"
 #include "VirtualClassDestructorCheck.h"
@@ -104,6 +105,8 @@ class CppCoreGuidelinesModule : public ClangTidyModule {
 "cppcoreguidelines-pro-type-union-access");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-type-vararg");
+CheckFactories.registerCheck(
+"cppcoreguidelines-rvalue-reference-param-not-moved");
 CheckFactories.registerCheck(
 "cppcoreguidelines-special-member-functions");
 CheckFactories.registerCheck("cppcoreguidelines-slicing");

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
new file mode 100644
index 0..eb67df05411a0
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
@@ -0,0 +1,128 @@
+//===--- RvalueReferenceParamNotMovedCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RvalueReferenceParamNotMovedCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+namespace {
+AST_MATCHER_P(LambdaExpr, valueCapturesVar, DeclarationMatcher, VarMatcher) {
+  return std::find_if(Node.capture_begin(), Node.capture_end(),
+  [&](const LambdaCapture &Capture) {
+return Capture.capturesVariable() &&
+   VarMatcher.matches(*Capture.getCapturedVar(),
+  Finder, Builder) &&
+   Capture.getCaptureKind() == LCK_ByCopy;
+  }) != Node.capture_end();
+}
+AST_MATCHER_P2(Stmt, argumentOf, bool, AllowPartialMove, StatementMatcher,
+   Ref) {
+  if (AllowPartialMove) {
+return stmt(anyOf(Ref, hasDescendant(Ref))).matches(Node, Finder, Builder);
+  } else {
+return Ref.matches(Node, Finder, Builder);
+  }
+}
+} // namespace
+
+void RvalueReferenceParamNotMovedCheck::registerMatchers(MatchFinder *Finder) {
+  auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("para

[clang] c8e2dd8 - [clang][darwin] An OS version preprocessor define is added for any darwin OS

2023-03-12 Thread Alex Lorenz via cfe-commits

Author: Alex Lorenz
Date: 2023-03-12T10:58:33-07:00
New Revision: c8e2dd8c6f490b68e41fe663b44535a8a21dfeab

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

LOG: [clang][darwin] An OS version preprocessor define is added for any darwin 
OS

This change generalizes the OS version macro for all darwin OSes. The 
OS-specific OS version macros are still defined to preserve compatibility.

Added: 


Modified: 
clang/lib/Basic/Targets/OSTargets.cpp
clang/test/Frontend/darwin-version.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 33a5b500e2d1c..763235fb10a52 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -108,9 +108,16 @@ void getDarwinDefines(MacroBuilder &Builder, const 
LangOptions &Opts,
 Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
   }
 
-  // Tell users about the kernel if there is one.
-  if (Triple.isOSDarwin())
+  if (Triple.isOSDarwin()) {
+// Any darwin OS defines a general darwin OS version macro in addition
+// to the other OS specific macros.
+assert(OsVersion.getMinor().value_or(0) < 100 &&
+   OsVersion.getSubminor().value_or(0) < 100 && "Invalid version!");
+Builder.defineMacro("__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__", Str);
+
+// Tell users about the kernel if there is one.
 Builder.defineMacro("__MACH__");
+  }
 
   PlatformMinVersion = OsVersion;
 }

diff  --git a/clang/test/Frontend/darwin-version.c 
b/clang/test/Frontend/darwin-version.c
index 67f087feafe25..28826014e39f1 100644
--- a/clang/test/Frontend/darwin-version.c
+++ b/clang/test/Frontend/darwin-version.c
@@ -59,6 +59,11 @@
 
 // RUN: %clang_cc1 -triple arm64-apple-ios99.99.99 -dM -E %s | FileCheck 
--check-prefix=IOS99 %s
 // IOS99: __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ 99
+// IOS99-NEXT: __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ 99
 
 // RUN: %clang_cc1 -triple arm64-apple-watchos99.9 -dM -E %s | FileCheck 
--check-prefix=WATCHOS99 %s
-// WATCHOS99: __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ 990900
+// WATCHOS99: __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ 990900
+// WATCHOS99-NEXT: __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ 990900
+
+// RUN: %clang_cc1 -triple arm64-apple-macos12.4 -dM -E %s | FileCheck 
--check-prefix=MACOS124 %s
+// MACOS124: __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ 120400



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


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

2023-03-12 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Analysis/ReachableCode.cpp:674
+  if (AS && hasSpecificAttr(AS->getAttrs()) &&
+  !Diag.isIgnored(diag::warn_unreachable_fallthrough_attr,
+  SourceLocation())) {

Your passing through `DiagnosticsEngine` just to check if 
`diag::warn_unreachable_fallthrough_attr` is ignored. I think it would be 
better just to pass through a boolean flag. This would avoid one include as 
well.


Repository:
  rG LLVM Github Monorepo

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] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-12 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce created this revision.
sunshaoce added reviewers: awarzynski, klausler, clementval, sscalpone, 
craig.topper, jrtc27, kito-cheng.
Herald added subscribers: VincentWu, vkmr, evandro, luismarques, 
sameer.abuasal, s.egerton, Jim, benna, psnobl, PkmX, rogfer01, shiva0217, 
simoncook, arichardson.
Herald added projects: Flang, All.
sunshaoce requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, jdoerfert, MaskRay.
Herald added a project: clang.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145883

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


Index: flang/test/Driver/target-features.f90
===
--- /dev/null
+++ flang/test/Driver/target-features.f90
@@ -0,0 +1,4 @@
+! RUN: %flang --target=riscv64-linux-gnu --target=riscv64 -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
+
+! 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"
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -109,6 +109,9 @@
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
 break;
+  case llvm::Triple::riscv64:
+getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
+break;
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.


Index: flang/test/Driver/target-features.f90
===
--- /dev/null
+++ flang/test/Driver/target-features.f90
@@ -0,0 +1,4 @@
+! RUN: %flang --target=riscv64-linux-gnu --target=riscv64 -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
+
+! 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-fe

[PATCH] D145435: Choose style (file) from within code for use in IDEs

2023-03-12 Thread bers via Phabricator via cfe-commits
bersbersbers added a comment.

In D145435#4179662 , @owenpan wrote:

> Are the settings above hypothetical or are they real-world use cases?

Real-world - actually, all of them.

> IMO, if people really want to have per-file configurations, they can do so 
> outside of clang-format, e.g. using grep in a shell script.

My main use case would be IDE integration - is there a way to achieve what you 
propose from within Visual Studio, for example? The beauty of the current setup 
(I believe) is that clang-format is pre-configured, so there is nothing to do 
except check out the code, and formatting works out of the box.

In D145435#4183507 , @owenpan wrote:

> It would add extra runtime (especially for large files).

That is a good point. It's probably an argument for restricting the search for 
that comment to the first N lines of the file, in which case the performance 
impact would be largely independent of file size. (I believe it would even be 
beneficial for this comment to be required to be placed near the top of the 
file, to reduce the amount of surprised users down the road.)

> We would also run the risk of regressions (though unlikely) if for whatever 
> reason an existing codebase has files starting with `// clang-format style=`.

If that is any indication, that is not the case on GitHub at least:
https://cs.github.com/?scopeName=All+repos&scope=&q=%22%2F%2F+clang-format+style%22


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145435

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


[clang-tools-extra] d5fd6a3 - [clang-tidy] Fix rename_check.py

2023-03-12 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-03-12T19:51:40Z
New Revision: d5fd6a376a7c0a880ccce43fa407177942ce6488

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

LOG: [clang-tidy] Fix rename_check.py

Fix checks renaming after directory structure
of clang-tidy has changed.

Added: 


Modified: 
clang-tools-extra/clang-tidy/rename_check.py

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/rename_check.py 
b/clang-tools-extra/clang-tidy/rename_check.py
index 764960e04421..f56776fdb729 100755
--- a/clang-tools-extra/clang-tidy/rename_check.py
+++ b/clang-tools-extra/clang-tidy/rename_check.py
@@ -94,10 +94,14 @@ def deleteMatchingLines(fileName, pattern):
 
 def getListOfFiles(clang_tidy_path):
   files = glob.glob(os.path.join(clang_tidy_path, '**'), recursive=True)
+  files += [os.path.normpath(os.path.join(clang_tidy_path,
+   '../docs/ReleaseNotes.rst'))]
   files += glob.glob(os.path.join(clang_tidy_path, '..', 'test',
   'clang-tidy', 'checkers', '**'), 
recursive=True)
   files += glob.glob(os.path.join(clang_tidy_path, '..', 'docs',
-  'clang-tidy', 'checks', '*'))
+  'clang-tidy', 'checks', '*.rst'))
+  files += glob.glob(os.path.join(clang_tidy_path, '..', 'docs',
+  'clang-tidy', 'checks', "*", "*.rst"), 
recursive=True)
   return [filename for filename in files if os.path.isfile(filename)]
 
 
@@ -213,9 +217,11 @@ def add_release_notes(clang_tidy_path, old_check_name, 
new_check_name):
 if header_found and add_note_here:
   if not line.startswith(''):
 f.write("""- The '%s' check was renamed to :doc:`%s
-  `
+  `
 
-""" % (old_check_name, new_check_name, new_check_name))
+""" % (old_check_name, new_check_name,
+   new_check_name.split('-', 1)[0],
+   '-'.join(new_check_name.split('-')[1:])))
 note_added = True
 
   f.write(line)
@@ -232,15 +238,18 @@ def main():
 
   old_module = args.old_check_name.split('-')[0]
   new_module = args.new_check_name.split('-')[0]
+  old_name = '-'.join(args.old_check_name.split('-')[1:])
+  new_name  = '-'.join(args.new_check_name.split('-')[1:])
+
   if args.check_class_name:
 check_name_camel = args.check_class_name
   else:
 check_name_camel = (''.join(map(lambda elem: elem.capitalize(),
-args.old_check_name.split('-')[1:])) +
+old_name.split('-'))) +
 'Check')
 
   new_check_name_camel = (''.join(map(lambda elem: elem.capitalize(),
-  args.new_check_name.split('-')[1:])) +
+  new_name.split('-'))) +
   'Check')
 
   clang_tidy_path = os.path.dirname(__file__)
@@ -255,7 +264,7 @@ def main():
   old_module_path = os.path.join(clang_tidy_path, old_module)
   new_module_path = os.path.join(clang_tidy_path, new_module)
 
-  if (args.old_check_name != args.new_check_name):
+  if (old_module != new_module):
 # Remove the check from the old module.
 cmake_lists = os.path.join(old_module_path, 'CMakeLists.txt')
 check_found = deleteMatchingLines(cmake_lists, '\\b' + check_name_camel)
@@ -270,12 +279,10 @@ def main():
 deleteMatchingLines(os.path.join(old_module_path, modulecpp),
   '\\b' + check_name_camel + '|\\b' + args.old_check_name)
 
-  old_check_filename = '-'.join(args.old_check_name.split('-')[1:])
-  new_check_filename = '-'.join(args.new_check_name.split('-')[1:])
-
   for filename in getListOfFiles(clang_tidy_path):
 originalName = filename
-filename = fileRename(filename, old_check_filename, new_check_filename)
+filename = fileRename(filename, old_module + "/" + old_name, new_module + 
"/" + new_name)
+filename = fileRename(filename, args.old_check_name, args.new_check_name)
 filename = fileRename(filename, check_name_camel, new_check_name_camel)
 replaceInFile(filename, generateCommentLineHeader(originalName),
   generateCommentLineHeader(filename))
@@ -284,7 +291,7 @@ def main():
 for header_guard in header_guard_variants:
   replaceInFile(filename, header_guard, header_guard_new)
 
-if args.new_check_name + '.rst' in filename:
+if new_module + '/'+ new_name + '.rst' in filename:
   replaceInFile(
   filename,
   args.old_check_name + '\n' + '=' * len(args.old_check_name) + '\n',
@@ -295,6 +302,8 @@ def main():
   new_module + '::' + new_check_name_camel)
 replaceInFile(filename, old_module + '/' + check_name_camel,

[clang-tools-extra] 55f8a28 - [clang-tidy][NFC] Update docs/clang-tidy/checks/list.rst

2023-03-12 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-03-12T20:01:36Z
New Revision: 55f8a287e9e8a137a400349b91426d02d6570b37

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

LOG: [clang-tidy][NFC] Update docs/clang-tidy/checks/list.rst
Mark fixes to Yes for 
cppcoreguidelines-avoid-capture-default-when-capturing-this
check, as it provides fixes

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 1919458cfc87..f1945c1b5bf0 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -179,7 +179,7 @@ Clang-Tidy Checks
`clang-analyzer-valist.Unterminated 
`_,
`concurrency-mt-unsafe `_,
`concurrency-thread-canceltype-asynchronous 
`_,
-   `cppcoreguidelines-avoid-capture-default-when-capturing-this 
`_,
+   `cppcoreguidelines-avoid-capture-default-when-capturing-this 
`_, "Yes"
`cppcoreguidelines-avoid-capturing-lambda-coroutines 
`_,
`cppcoreguidelines-avoid-const-or-ref-data-members 
`_,
`cppcoreguidelines-avoid-do-while `_,



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


[PATCH] D145865: [clang-tidy] Multiple fixes to bugprone-exception-escape

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

This change obsoletes D115118  and D134588 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145865

___
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-12 Thread Usman Nadeem via Phabricator via cfe-commits
mnadeem added a comment.

There is an existing test `flang/test/Driver/target-cpu-features.f90` added in 
D137995 

Would it be better to add RISCV to that file? or perhaps rename the tests to 
have target specific files?


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-12 Thread Usman Nadeem via Phabricator via cfe-commits
mnadeem 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;

identical code, could just do a fallthrough


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-12 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 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;

mnadeem wrote:
> identical code, could just do a fallthrough
Why is this even conditional??


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-12 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe created this revision.
mikecrowe added reviewers: PiotrZSL, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
mikecrowe requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Many libraries and code bases have functions that work like std::format
and std::print and it would be useful for the
readability-redundant-string-cstr check to work with these functions to
remove unnecessary calls to c_str() among their arguments.

The StringParameterFunctions option contains a semicolon-separated list
of function names for which any arguments which are the result of
calling std::string::c_str() or std::string::data() should be changed to
pass the object directly.

For example, when using the {fmt}[1] library, this option can be used to
change arguments to fmt::format and fmt::print.

Depends on D143342 


Repository:
  rG LLVM Github Monorepo

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,124 @@
+// 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());
+  // 

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

2023-03-12 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

I can squash this with https://reviews.llvm.org/D143342 if required.


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] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-03-12 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp:189
+  getLangOpts().CPlusPlus2b
+  ? hasAnyName("::std::print", "::std::format")
+  : hasName("::std::format"))),

PiotrZSL wrote:
> mikecrowe wrote:
> > PiotrZSL wrote:
> > > mikecrowe wrote:
> > > > mikecrowe wrote:
> > > > > PiotrZSL wrote:
> > > > > > Please introduce configuration option to specify custom functions.
> > > > > > For example if some project (like mine) is wrapping fmt::format 
> > > > > > with some variadic template function, then such function could be 
> > > > > > specified.
> > > > > > Same goes to things like some loggers.
> > > > > > 
> > > > > > Check utils/OptionsUtils.h for configuration, and  utils/Matchers.h 
> > > > > > (matchesAnyListedName)
> > > > > > Please introduce configuration option to specify custom functions.
> > > > > > For example if some project (like mine) is wrapping fmt::format 
> > > > > > with some variadic template function, then such function could be 
> > > > > > specified.
> > > > > 
> > > > > That's exactly where this change originated (as part of [[ 
> > > > > https://github.com/mikecrowe/clang-tidy-fmt | my clang-tidy fmt fork 
> > > > > ]], which I hope to submit for review soon once I've made it 
> > > > > configurable too and improved the test cases.)
> > > > > 
> > > > > > Same goes to things like some loggers.
> > > > > > 
> > > > > > Check utils/OptionsUtils.h for configuration, and  utils/Matchers.h 
> > > > > > (matchesAnyListedName)
> > > > > 
> > > > > Thanks for the pointer. I shall study those files for how to support 
> > > > > this.
> > > > > 
> > > > > Do you think that the change can land like in its current state 
> > > > > first? Or would you prefer that the configuration option is added at 
> > > > > the same time?
> > > > > Please introduce configuration option to specify custom functions.
> > > > > For example if some project (like mine) is wrapping fmt::format with 
> > > > > some variadic template function, then such function could be 
> > > > > specified.
> > > > 
> > > > I could add some sort of 
> > > > `readability-redundant-string-cstr.PrintFunction` option or 
> > > > `readability-redundant-string-cstr.FormatFunction` option, but reducing 
> > > > this to its fundamental behaviour would be "a function that takes 
> > > > `const char *` arguments that is also willing to take `std::string` 
> > > > arguments". I'm struggling to find a sensible name for such an option. 
> > > > Maybe 
> > > > `readability-redundant-string-cstr.StdStringAcceptingFunction=::fmt::format`?
> > > >  Or just `readability-redundant-string-cstr.FunctionCall=::fmt::format`?
> > > > 
> > > > > Same goes to things like some loggers.
> > > > 
> > > > Loggers may be classes, so there would need to be an option that 
> > > > specifies a class name (or even a base class name) and a method name 
> > > > (which may be an operator.) See [[ 
> > > > https://github.com/mikecrowe/clang-tidy-fmt/blob/7ace8a3ff41e9679104fe558835b0ef3cb33d969/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp#L196
> > > >  | this hard-coded example ]] (If it's not obvious, there's a 
> > > > description in the [[ 
> > > > https://github.com/mikecrowe/clang-tidy-fmt/blob/7ace8a3ff41e9679104fe558835b0ef3cb33d969/README.md?plain=1#L103
> > > >  | README ]]. In such cases the options could be 
> > > > `readability-redundant-string-cstr.Class=::BaseTrace` and 
> > > > `readability-redundant-string-cstr.Method=Log` or 
> > > > `readability-redundant-string-cstr.Operator=()`, but then it would be 
> > > > hard to tie together the right classes and methods. That could be 
> > > > avoided with something like 
> > > > `readability-redundant-string-cstr.MemberFunctionCall=::BaseTrace::operator(),::NullTrace::operator()`
> > > >  and some parsing I suppose.
> > > > 
> > > > Regardless, I'll try and get the simple case working and await 
> > > > suggestions for appropriate option names.
> > > > 
> > > > Thanks again for the suggestions.
> > > > 
> > > I asked AI, and it suggested 
> > > readability-redundant-string-cstr.FormattingFunctionsList.
> > > Also, I thing that matchesAnyListedName should support things like 
> > > '::NullTrace::operator()', so one option should be sufficient.
> > > 
> > > FormattingFunctionsList:
> > > A semicolon-separated list of (fully qualified) function/method/operator 
> > > names, with the requirement that 
> > > any parameter capable of accepting a 'const char*' input should also be 
> > > able to accept 'std::string' or 
> > > 'std::string_view' inputs, or proper overload candidates that can do so 
> > > should exist.
> > Far be it from me to question the wisdom of the AI :) , but my point was 
> > that the check works for any function that accepts `const char *` 
> > parameters that could equally well

[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.

Correct commit message and this could land.


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

https://reviews.llvm.org/D143342

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


[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-03-12 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

In D143342#4187641 , @PiotrZSL wrote:

> Correct commit message and this could land.

I've read through all the comments and the commit message itself and I can't 
spot what's wrong with the commit message, except perhaps for its verbosity. 
What would you like me to correct?


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

https://reviews.llvm.org/D143342

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-03-12 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

___
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-12 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:146-148
+  arguments to ``std::print`` and ``std::format``. The same check can be
+  used for functions that behave similarly by using the
+  ``StringParameterFunction`` option.

``std::print``, ``std::format`` or other functions listed in 
``StringParameterFunction`` check option.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst:14-30
+   A semicolon-separated list of function names for which any arguments
+   which are the result of calling ``std::string::c_str()`` or
+   ``std::string::data()`` should be changed to pass the object directly.
+   This is particularly useful for functions that behave like
+   ``std::format`` and ``std::print`` (though arguments to both of those
+   are already detected automatically in C++20 and C++2b mode
+   respectively.) The names may be free functions, member functions, or

too much noise in this, configuration example is not needed.
reference to C++20 or std::format/std::print also...

Strongly consider something like:
"A semicolon-separated list of (fully qualified) function/method/operator 
names, with the requirement that
any parameter currently accepting a 'const char*' input should also be able to 
accept 'std::string' inputs, 
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. Default value is empty string."


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] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

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

"The dummy implementations of std::format and std::print require C++20,
so it's easier to test them in a separate
redundant-string-cstr-format.cpp check file. This also requires a small
improvement to the basic_string_view implementation in the 
dummy header.

With these changes, I was able to successfully run the
readability-redundant-string-cstr check on a real source file that
compiled successfully with what is destined to become GCC 13, and saw
the expected:"

You shouldn't explain your self why you choose this or other implementation, or 
pasting output from console.
Commit message should contain only description about changes.
All those explanation you can always put into review as comment.

https://llvm.org/docs/DeveloperPolicy.html#commit-messages:
"The body should be concise, but explanatory, including a complete reasoning. 
Unless it is required to understand the change, examples, code snippets and 
gory details should be left to bug comments, web review or the mailing list."


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

https://reviews.llvm.org/D143342

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


[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-03-12 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

Thank you for your patience.


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

https://reviews.llvm.org/D143342

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


[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

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

You will need to rebase this, there are conflicts...


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

https://reviews.llvm.org/D143342

___
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-12 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL requested changes to this revision.
PiotrZSL added a comment.
This revision now requires changes to proceed.

My only complain is documentation, changes in code and tests are correct.
Build failed mainly due to conflicts in previous change.
It should get green once prev patch will land, and this will be re-based.

I strongly suggest using arc (less issues with patches).


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] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

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

Rebase. No conflicts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143342

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp
@@ -0,0 +1,214 @@
+// RUN: %check_clang_tidy -check-suffix=STDFORMAT -std=c++20 %s readability-redundant-string-cstr %t -- --  -isystem %clang_tidy_headers -DTEST_STDFORMAT
+// RUN: %check_clang_tidy -check-suffixes=STDFORMAT,STDPRINT -std=c++2b %s readability-redundant-string-cstr %t -- --  -isystem %clang_tidy_headers -DTEST_STDFORMAT -DTEST_STDPRINT
+#include 
+
+namespace std {
+  template
+struct type_identity { using type = T; };
+  template
+using type_identity_t = typename type_identity::type;
+
+  template 
+  struct basic_format_string {
+consteval basic_format_string(const CharT *format) : str(format) {}
+basic_string_view> str;
+  };
+
+  template
+using format_string = basic_format_string...>;
+
+  template
+using wformat_string = basic_format_string...>;
+
+#if defined(TEST_STDFORMAT)
+  template
+  std::string format(format_string, Args &&...);
+  template
+  std::string format(wformat_string, Args &&...);
+#endif // TEST_STDFORMAT
+
+#if defined(TEST_STDPRINT)
+  template
+  void print(format_string, Args &&...);
+  template
+  void print(wformat_string, Args &&...);
+#endif // TEST_STDPRINT
+}
+
+namespace notstd {
+#if defined(TEST_STDFORMAT)
+  template
+  std::string format(const char *, Args &&...);
+  template
+  std::string format(const wchar_t *, Args &&...);
+#endif // TEST_STDFORMAT
+#if defined(TEST_STDPRINT)
+  template
+  void print(const char *, Args &&...);
+  template
+  void print(const wchar_t *, Args &&...);
+#endif // TEST_STDPRINT
+}
+
+std::string return_temporary();
+std::wstring return_wtemporary();
+
+#if defined(TEST_STDFORMAT)
+void std_format(const std::string &s1, const std::string &s2, const std::string &s3) {
+  auto r1 = std::format("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:37: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r1 = std::format("One:{}\n", s1);
+
+  auto r2 = std::format("One:{} Two:{} Three:{} Four:{}\n", s1.c_str(), s2, s3.c_str(), return_temporary().c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:61: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-2]]:77: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-3]]:89: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r2 = std::format("One:{} Two:{} Three:{} Four:{}\n", s1, s2, s3, return_temporary());
+
+  using namespace std;
+  auto r3 = format("Four:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:33: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r3 = format("Four:{}\n", s1);
+}
+
+void std_format_wide(const std::wstring &s1, const std::wstring &s2, const std::wstring &s3) {
+  auto r1 = std::format(L"One:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:38: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r1 = std::format(L"One:{}\n", s1);
+
+  auto r2 = std::format(L"One:{} Two:{} Three:{} Four:{}\n", s1.c_str(), s2, s3.c_str(), return_wtemporary().c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:62: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-2]]:78: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-3]]:90: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r2 = std::format(L"One:{} Two:{} Three:{} Four:{}\n", s1, s2, s3, return_wtemporary());
+
+  using namespace std;
+  auto r3 = format(L"Four:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:34: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r3 = format(L"Four:{}\n", s1);
+}
+
+// There's are c_str() calls here, so it shouldn't be touched.
+std::string std_format_no_cstr(const std::stri

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

2023-03-12 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 504475.
mikecrowe added a comment.

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,124 @@
+// 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-MESSAGES: :[[@LINE-1]]:26: warning: redundant call to 'c_str' [readability-redundant-string-cst

[clang-tools-extra] 57b78fa - [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-03-12 Thread Piotr Zegar via cfe-commits

Author: Mike Crowe
Date: 2023-03-12T21:42:53Z
New Revision: 57b78faa9eb08017d95bb4e43242648953b08c13

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

LOG: [clang-tidy] Support std::format and std::print in 
readability-redundant-string-cstr

std::format (C++20) and std::print (C++23) are perfectly happy to accept
std::string arguments. Converting them to C-style strings by calling
c_str() is unnecessary and may cause extra walking of the string to
determine its length.

Depends on D144216

Reviewed By: carlosgalvezp, PiotrZSL

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
index 1b21f70f0bf64..d1fdf8341f710 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -182,6 +182,20 @@ void RedundantStringCStrCheck::registerMatchers(
   // directly.
   hasArgument(0, StringCStrCallExpr))),
   this);
+
+  if (getLangOpts().CPlusPlus20) {
+// Detect redundant 'c_str()' calls in parameters passed to std::format in
+// C++20 onwards and std::print in C++23 onwards.
+Finder->addMatcher(
+traverse(TK_AsIs,
+ callExpr(callee(functionDecl(
+  getLangOpts().CPlusPlus2b
+  ? hasAnyName("::std::print", "::std::format")
+  : hasName("::std::format"))),
+  forEachArgumentWithParam(StringCStrCallExpr,
+   parmVarDecl(,
+this);
+  }
 }
 
 void RedundantStringCStrCheck::check(const MatchFinder::MatchResult &Result) {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c0b2d118ec4b6..6d48ff7bf7eb1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -146,6 +146,10 @@ New check aliases
 
 Changes in existing checks
 ^^
+- Improved :doc:`readability-redundant-string-cstr
+  ` check to recognise
+  unnecessary ``std::string::c_str()`` and ``std::string::data()`` calls in
+  arguments to ``std::print`` and ``std::format``.
 
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`bugprone-dynamic-static-initializers

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
index e9d31b929c6c4..80b41da61c2e3 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -62,7 +62,8 @@ typedef basic_string u32string;
 
 template >
 struct basic_string_view {
-  basic_string_view(const C* s);
+  const C *str;
+  constexpr basic_string_view(const C* s) : str(s) {}
 };
 typedef basic_string_view string_view;
 typedef basic_string_view wstring_view;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp
new file mode 100644
index 0..e58c8d8b69c05
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp
@@ -0,0 +1,214 @@
+// RUN: %check_clang_tidy -check-suffix=STDFORMAT -std=c++20 %s 
readability-redundant-string-cstr %t -- --  -isystem %clang_tidy_headers 
-DTEST_STDFORMAT
+// RUN: %check_clang_tidy -check-suffixes=STDFORMAT,STDPRINT -std=c++2b %s 
readability-redundant-string-cstr %t -- --  -isystem %clang_tidy_headers 
-DTEST_STDFORMAT -DTEST_STDPRINT
+#include 
+
+namespace std {
+  template
+struct type_identity { using type = T; };
+  template
+using type_identity_t = typename type_identity::type;
+
+  template 
+  struct basic_format_string {
+consteval basic_format_string(const CharT *format) : str(format) {}
+basic_string_view> str;
+  };
+
+  template
+using format_string = basic_format_string...>;
+
+  template
+using wformat_string = basic_format_string...>;
+
+#if defined(TEST_STDFORMAT)
+  template
+  std::string format(format_string, Args &&...);
+  template
+  std::string format(wformat_string, Args &&...);
+#endif // TEST_STDFORMAT
+
+#if defined(TEST_

[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-03-12 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG57b78faa9eb0: [clang-tidy] Support std::format and 
std::print in readability-redundant-string… (authored by mikecrowe, committed 
by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143342

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp
@@ -0,0 +1,214 @@
+// RUN: %check_clang_tidy -check-suffix=STDFORMAT -std=c++20 %s readability-redundant-string-cstr %t -- --  -isystem %clang_tidy_headers -DTEST_STDFORMAT
+// RUN: %check_clang_tidy -check-suffixes=STDFORMAT,STDPRINT -std=c++2b %s readability-redundant-string-cstr %t -- --  -isystem %clang_tidy_headers -DTEST_STDFORMAT -DTEST_STDPRINT
+#include 
+
+namespace std {
+  template
+struct type_identity { using type = T; };
+  template
+using type_identity_t = typename type_identity::type;
+
+  template 
+  struct basic_format_string {
+consteval basic_format_string(const CharT *format) : str(format) {}
+basic_string_view> str;
+  };
+
+  template
+using format_string = basic_format_string...>;
+
+  template
+using wformat_string = basic_format_string...>;
+
+#if defined(TEST_STDFORMAT)
+  template
+  std::string format(format_string, Args &&...);
+  template
+  std::string format(wformat_string, Args &&...);
+#endif // TEST_STDFORMAT
+
+#if defined(TEST_STDPRINT)
+  template
+  void print(format_string, Args &&...);
+  template
+  void print(wformat_string, Args &&...);
+#endif // TEST_STDPRINT
+}
+
+namespace notstd {
+#if defined(TEST_STDFORMAT)
+  template
+  std::string format(const char *, Args &&...);
+  template
+  std::string format(const wchar_t *, Args &&...);
+#endif // TEST_STDFORMAT
+#if defined(TEST_STDPRINT)
+  template
+  void print(const char *, Args &&...);
+  template
+  void print(const wchar_t *, Args &&...);
+#endif // TEST_STDPRINT
+}
+
+std::string return_temporary();
+std::wstring return_wtemporary();
+
+#if defined(TEST_STDFORMAT)
+void std_format(const std::string &s1, const std::string &s2, const std::string &s3) {
+  auto r1 = std::format("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:37: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r1 = std::format("One:{}\n", s1);
+
+  auto r2 = std::format("One:{} Two:{} Three:{} Four:{}\n", s1.c_str(), s2, s3.c_str(), return_temporary().c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:61: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-2]]:77: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-3]]:89: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r2 = std::format("One:{} Two:{} Three:{} Four:{}\n", s1, s2, s3, return_temporary());
+
+  using namespace std;
+  auto r3 = format("Four:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:33: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r3 = format("Four:{}\n", s1);
+}
+
+void std_format_wide(const std::wstring &s1, const std::wstring &s2, const std::wstring &s3) {
+  auto r1 = std::format(L"One:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:38: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r1 = std::format(L"One:{}\n", s1);
+
+  auto r2 = std::format(L"One:{} Two:{} Three:{} Four:{}\n", s1.c_str(), s2, s3.c_str(), return_wtemporary().c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:62: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-2]]:78: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-3]]:90: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r2 = std::format(L"One:{} Two:{} Three:{} Four:{}\n", s1, s2, s3, return_wtemporary());
+
+  using namespace std;
+  auto r3 = format(L"Four:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:34: warning: redundant call to '

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

2023-03-12 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

In D145885#4187679 , @PiotrZSL wrote:

> My only complain is documentation, changes in code and tests are correct.
> Build failed mainly due to conflicts in previous change.
> It should get green once prev patch will land, and this will be re-based.

Thanks for the comments. I will address them. I've rebased this change on top 
of the rebase of the previous one. Maybe that will help. Git didn't report any 
conflicts when I rebased.

> I strongly suggest using arc (less issues with patches).

I have been using arc. I couldn't find a way to make it submit updates to more 
than one change at a time. I've done these two with `git checkout HEAD~1 ; arc 
diff ; git checkout mybranch; arc diff`. Is there a better way?


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] D141008: [Clang][SPIR-V] Emit target extension types for OpenCL types on SPIR-V.

2023-03-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks




Comment at: clang/lib/CodeGen/TargetInfo.h:383
+
+  /// Return an LLVM target extension type that corresponds to an OpenCL type,
+  /// if such a type is necessary.

The default behaviour doesn't return a target extension type so maybe it's 
better to change the comment to:


```
Return an LLVM type that corresponds to an OpenCL type
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141008

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


[PATCH] D143849: [Clang][OpenCL] Allow pointers in structs as kernel arguments from 2.0

2023-03-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


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

https://reviews.llvm.org/D143849

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


[PATCH] D145888: [clang-format] Fix non-case colons in Verilog case lines

2023-03-12 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, owenpan, rymiel.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Back in D128714 , we should have replaced the 
old rule about colons when
we added the new one.  Because we didn't, all colons got mistaken as
case colons as long as the line began with `case` or `default`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145888

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestVerilog.cpp


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -250,6 +250,33 @@
"  end\n"
"endcase",
Style);
+  // Other colons should not be mistaken as case colons.
+  Style = getLLVMStyle(FormatStyle::LK_Verilog);
+  Style.BitFieldColonSpacing = FormatStyle::BFCS_None;
+  verifyFormat("case (x[1:0])\n"
+   "endcase", Style);
+  verifyFormat("default:\n"
+   "  x[1:0] = x[1:0];", Style);
+  Style.BitFieldColonSpacing = FormatStyle::BFCS_Both;
+  verifyFormat("case (x[1 : 0])\n"
+   "endcase", Style);
+  verifyFormat("default:\n"
+   "  x[1 : 0] = x[1 : 0];", Style);
+  Style = getLLVMStyle(FormatStyle::LK_Verilog);
+  Style.SpacesInContainerLiterals = true;
+  verifyFormat("case ('{x : x, default : 9})\n"
+   "endcase", Style);
+  verifyFormat("x = '{x : x, default : 9};\n", Style);
+  verifyFormat("default:\n"
+   "  x = '{x : x, default : 9};\n",
+   Style);
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("case ('{x: x, default: 9})\n"
+   "endcase", Style);
+  verifyFormat("x = '{x: x, default: 9};\n", Style);
+  verifyFormat("default:\n"
+   "  x = '{x: x, default: 9};\n",
+   Style);
 }
 
 TEST_F(FormatTestVerilog, Declaration) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4420,8 +4420,6 @@
  Line.First->isOneOf(tok::kw_default, tok::kw_case))) {
   return Style.SpaceBeforeCaseColon;
 }
-if (Line.First->isOneOf(tok::kw_default, tok::kw_case))
-  return Style.SpaceBeforeCaseColon;
 const FormatToken *Next = Right.getNextNonComment();
 if (!Next || Next->is(tok::semi))
   return false;


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -250,6 +250,33 @@
"  end\n"
"endcase",
Style);
+  // Other colons should not be mistaken as case colons.
+  Style = getLLVMStyle(FormatStyle::LK_Verilog);
+  Style.BitFieldColonSpacing = FormatStyle::BFCS_None;
+  verifyFormat("case (x[1:0])\n"
+   "endcase", Style);
+  verifyFormat("default:\n"
+   "  x[1:0] = x[1:0];", Style);
+  Style.BitFieldColonSpacing = FormatStyle::BFCS_Both;
+  verifyFormat("case (x[1 : 0])\n"
+   "endcase", Style);
+  verifyFormat("default:\n"
+   "  x[1 : 0] = x[1 : 0];", Style);
+  Style = getLLVMStyle(FormatStyle::LK_Verilog);
+  Style.SpacesInContainerLiterals = true;
+  verifyFormat("case ('{x : x, default : 9})\n"
+   "endcase", Style);
+  verifyFormat("x = '{x : x, default : 9};\n", Style);
+  verifyFormat("default:\n"
+   "  x = '{x : x, default : 9};\n",
+   Style);
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("case ('{x: x, default: 9})\n"
+   "endcase", Style);
+  verifyFormat("x = '{x: x, default: 9};\n", Style);
+  verifyFormat("default:\n"
+   "  x = '{x: x, default: 9};\n",
+   Style);
 }
 
 TEST_F(FormatTestVerilog, Declaration) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4420,8 +4420,6 @@
  Line.First->isOneOf(tok::kw_default, tok::kw_case))) {
   return Style.SpaceBeforeCaseColon;
 }
-if (Line.First->isOneOf(tok::kw_default, tok::kw_case))
-  return Style.SpaceBeforeCaseColon;
 const FormatToken *Next = Right.getNextNonComment();
 if (!Next || Next->is(tok::semi))
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145856: [clang-tidy] Let misc-const-correctness detect auto local variables that can be made const

2023-03-12 Thread Chris Thrasher via Phabricator via cfe-commits
ChrisThrasher added a comment.

I'm working on the test failures and improved test coverage. Where can I learn 
more about how to update the release notes and documentation?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145856

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


[PATCH] D145856: [clang-tidy] Let misc-const-correctness detect auto local variables that can be made const

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

Tests:
./clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-values.cpp
./clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-cxx17.cpp
./clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
./clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-pointer-as-values.cpp
./clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-unaligned.cpp
./clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp
./clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
./clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp

Documentation:
./clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst

Release notes:
./clang-tools-extra/docs/ReleaseNotes.rst

For things like options, look how other checks do that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145856

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


[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros

2023-03-12 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb updated this revision to Diff 504486.
jaredgrubb added a comment.

- Fixed an issue in `TokenAnnotator` about it not breaking between macros 
properly (it was catching in an ObjC selector-check too early)
- Add more ObjC tests, covering method and property declarations too. There are 
still some quirks about reflowing multiple attributes, but those quirks exist 
in C++ too, so I think those are best left for another patch. I added checks 
for existing behavior so that patch can improve the ObjC version too.


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

https://reviews.llvm.org/D145262

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/ContinuationIndenter.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestObjC.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1296,6 +1296,121 @@
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GenericSelectionColon);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacros) {
+  // '__attribute__' has special handling.
+  auto Tokens = annotate("__attribute__(X) void Foo(void);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw___attribute, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeParen);
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeParen);
+
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("A(X) void Foo(void);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  // 'TT_FunctionAnnotationRParen' doesn't seem right; fix?
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_FunctionAnnotationRParen);
+
+  // Add a custom AttributeMacro. Test that it has the same behavior.
+  FormatStyle Style = getLLVMStyle();
+  Style.AttributeMacros.push_back("A");
+
+  // An "AttributeMacro" gets annotated like '__attribute__'.
+  Tokens = annotate("A(X) void Foo(void);", Style);
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_AttributeMacro);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeParen);
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeParen);
+}
+
+TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCDecl) {
+  // '__attribute__' has special handling.
+  auto Tokens = annotate("__attribute__(X) @interface Foo");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw___attribute, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeParen);
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeParen);
+
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("A(X) @interface Foo");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  // Note: Don't check token-type as a random token in this position is hard to
+  // reason about.
+  EXPECT_TOKEN_KIND(Tokens[0], tok::identifier);
+  EXPECT_TOKEN_KIND(Tokens[1], tok::l_paren);
+  EXPECT_TOKEN_KIND(Tokens[3], tok::r_paren);
+
+  // Add a custom AttributeMacro. Test that it has the same behavior.
+  FormatStyle Style = getLLVMStyle();
+  Style.AttributeMacros.push_back("A");
+
+  // An "AttributeMacro" gets annotated like '__attribute__'.
+  Tokens = annotate("A(X) @interface Foo", Style);
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_AttributeMacro);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeParen);
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeParen);
+}
+
+TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCMethodDecl) {
+  // '__attribute__' has special handling.
+  auto Tokens = annotate("- (id)init __attribute__(X);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw___attribute, TT_Unknown);
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_AttributeParen);
+  EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_AttributeParen);
+
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("- (id)init A(X);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  // Note: Don't check token-type as a random token in this position is hard to
+  // reason about.
+  EXPECT_TOKEN_KIND(Tokens[5], tok::identifier);
+  EXPECT_TOKEN_KIND(Tokens[6], tok::l_paren);
+  EXPECT_TOKEN_KIND(Tokens[8], tok::r_paren);
+
+  // Add a custom AttributeMacro. Test that it has the same behavior.
+  FormatStyle Style = getLLVMStyle();
+  Style.AttributeMacros.push_back("A");
+
+  // An "AttributeMacro" gets annotated like '__attribute__'.
+  Tokens = annotate("- (id)init A(X);", Style);
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_AttributeMacro);
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_AttributeParen);
+

[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros

2023-03-12 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:5329
+  if (Right.is(tok::l_square) && Right.is(TT_AttributeSquare))
 return !Left.is(TT_AttributeSquare);
 

I broke this `if` into two pieces and restored an original `return true` for 
this part of the `if` that was changed in 2020 (via 
5a4ddbd69db2b0e09398214510501d0e59a0c30b).

The `return !Left...` was added to avoid breaking `[[` apart when reflowing a 
function-arg with C++11-style attribute (eg, `[[unused]]`). As far as I can 
tell, this check _really_ only matters if the code-path is the second-half of 
the original if (`Right.is(tok::l_square)...`). 

I couldn't imagine how there `Right.is(tok::kw___attribute)` needs the 
`Left`-check, so I think that patch is better split to differentiate (even 
though originally it didn't really have any conflicting effect).

Please let me know if my logic here is wrong (or I'm not making sense :) )


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

https://reviews.llvm.org/D145262

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


[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros

2023-03-12 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb added inline comments.



Comment at: clang/unittests/Format/FormatTestObjC.cpp:1619
+  // Reflow after first macro.
+  // FIXME: these should indent but don't.
+  verifyFormat("- (id)init ATTRIBUTE_MACRO(X)\n"

I don't love this FIXME, but I was afraid to add more to this patch, as fixing 
this will require digging into things that have nothing to do with 
`__attribute__` vs `AttributeMacros`.

For example, suffix macros in C/C++ also are broken in the same way with just 
plain `__attribute__`. For example, for `ColumnWidth: 50`:
```
int f(double) __attribute__((overloadable))
__attribute__((overloadable));

int ff(double)
__attribute__((overloadable))
__attribute__((overloadable));
```

I think fixing reflowing of suffix macros is best done in another PR (which I 
can take a stab at!)


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

https://reviews.llvm.org/D145262

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


[PATCH] D83906: [CodeGen] Emit a call instruction instead of an invoke if the called llvm function is marked nounwind

2023-03-12 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D83906#4186887 , @hoy wrote:

> In D83906#4184916 , @dexonsmith 
> wrote:
>
>> In D83906#4183453 , @hoy wrote:
>>
>>> Wondering if we can come up with a way to tell the optimizer about that, 
>>> e.g., through a new module flag. When it comes to LTO, the selection of 
>>> linkonce_odr symbols should already been done and the optimizer may be able 
>>> to recompute the attributes based on pre-LTO attributes, or at least we can 
>>> allow IPO to one module only, which should still do a better job than FE 
>>> does?
>>
>> I don't think there's much point in passing anything to LTO. There are very 
>> few `linkonce_odr` symbols in LTO, since LTO has the advantage of an export 
>> list from the link. Symbols not on the export list are internalized (they're 
>> given local linkage).
>
> That sounds to me an opportunity to get a broader IPO done precisely in the 
> prelink optimizer, as long as we find a way to tell it the incoming IR has 
> source fidelity. What do you think about idea of introducing a module flag? 
> Maybe it's worth discussing in the forum as a followup of introducing a cc1 
> flag for a stable IR gen.

I'm not sure I'm following.

The prelink optimizer will already be internalizing (i.e., NOT exporting) these 
symbols. That should be enough. AFAICT, it's non-LTO pipelines that might have 
headroom after this is reverted.

I'm also not sure what the module flag would be for. If "this module has source 
fidelity", it won't work, because the gadgets I'm aware of are implemented in 
function passes (probably `-instcombine`?). A function pass isn't allowed to 
touch module state. Were you thinking of a different module flag? (But, I 
repeat, I think LTO pipelines have nothing to worry about anyway.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83906

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


[PATCH] D145857: [X86] Make triple ArchName override OS for i686 and i786

2023-03-12 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 504497.
pengfei added a comment.

Only make OS override i386.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145857

Files:
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  clang/test/Driver/cl-x86-flags.c
  clang/test/Driver/nacl-direct.c


Index: clang/test/Driver/nacl-direct.c
===
--- clang/test/Driver/nacl-direct.c
+++ clang/test/Driver/nacl-direct.c
@@ -6,7 +6,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-I686 %s
 // CHECK-I686: "-cc1"
 // CHECK-I686-NOT: "-fno-use-init-array"
-// CHECK-I686: "-target-cpu" "pentium4"
+// CHECK-I686: "-target-cpu" "i686"
 // CHECK-I686: "-resource-dir" "foo"
 // CHECK-I686: "-internal-isystem" "foo{{/|}}include"
 // CHECK-I686: "-internal-isystem" 
"{{.*}}{{/|}}..{{/|}}i686-nacl{{/|}}usr{{/|}}include"
Index: clang/test/Driver/cl-x86-flags.c
===
--- clang/test/Driver/cl-x86-flags.c
+++ clang/test/Driver/cl-x86-flags.c
@@ -133,5 +133,11 @@
 // tune: "-target-cpu" "sandybridge"
 // tune-SAME: "-tune-cpu" "haswell"
 
+// RUN: %clang_cl --target=i686-unknown-unknown -### -- 2>&1 %s | FileCheck 
-check-prefix=i686 %s
+// i686: "-target-cpu" "i686"
+
+// RUN: %clang_cl --target=i786-unknown-unknown -### -- 2>&1 %s | FileCheck 
-check-prefix=i786 %s
+// i786: "-target-cpu" "pentium4"
+
 void f(void) {
 }
Index: clang/lib/Driver/ToolChains/Arch/X86.cpp
===
--- clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -102,18 +102,25 @@
   if (Is64Bit)
 return "x86-64";
 
-  switch (Triple.getOS()) {
-  case llvm::Triple::NetBSD:
-return "i486";
-  case llvm::Triple::Haiku:
-  case llvm::Triple::OpenBSD:
-return "i586";
-  case llvm::Triple::FreeBSD:
-return "i686";
-  default:
-// Fallback to p4.
-return "pentium4";
+  if (Triple.getArchName() == "i386") {
+switch (Triple.getOS()) {
+case llvm::Triple::NetBSD:
+  return "i486";
+case llvm::Triple::Haiku:
+case llvm::Triple::OpenBSD:
+  return "i586";
+case llvm::Triple::FreeBSD:
+  return "i686";
+default:
+  // Fallback to p4.
+  return "pentium4";
+}
   }
+
+  if (Triple.getArchName() == "i786")
+return "pentium4";
+
+  return std::string(Triple.getArchName());
 }
 
 void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,


Index: clang/test/Driver/nacl-direct.c
===
--- clang/test/Driver/nacl-direct.c
+++ clang/test/Driver/nacl-direct.c
@@ -6,7 +6,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-I686 %s
 // CHECK-I686: "-cc1"
 // CHECK-I686-NOT: "-fno-use-init-array"
-// CHECK-I686: "-target-cpu" "pentium4"
+// CHECK-I686: "-target-cpu" "i686"
 // CHECK-I686: "-resource-dir" "foo"
 // CHECK-I686: "-internal-isystem" "foo{{/|}}include"
 // CHECK-I686: "-internal-isystem" "{{.*}}{{/|}}..{{/|}}i686-nacl{{/|}}usr{{/|}}include"
Index: clang/test/Driver/cl-x86-flags.c
===
--- clang/test/Driver/cl-x86-flags.c
+++ clang/test/Driver/cl-x86-flags.c
@@ -133,5 +133,11 @@
 // tune: "-target-cpu" "sandybridge"
 // tune-SAME: "-tune-cpu" "haswell"
 
+// RUN: %clang_cl --target=i686-unknown-unknown -### -- 2>&1 %s | FileCheck -check-prefix=i686 %s
+// i686: "-target-cpu" "i686"
+
+// RUN: %clang_cl --target=i786-unknown-unknown -### -- 2>&1 %s | FileCheck -check-prefix=i786 %s
+// i786: "-target-cpu" "pentium4"
+
 void f(void) {
 }
Index: clang/lib/Driver/ToolChains/Arch/X86.cpp
===
--- clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -102,18 +102,25 @@
   if (Is64Bit)
 return "x86-64";
 
-  switch (Triple.getOS()) {
-  case llvm::Triple::NetBSD:
-return "i486";
-  case llvm::Triple::Haiku:
-  case llvm::Triple::OpenBSD:
-return "i586";
-  case llvm::Triple::FreeBSD:
-return "i686";
-  default:
-// Fallback to p4.
-return "pentium4";
+  if (Triple.getArchName() == "i386") {
+switch (Triple.getOS()) {
+case llvm::Triple::NetBSD:
+  return "i486";
+case llvm::Triple::Haiku:
+case llvm::Triple::OpenBSD:
+  return "i586";
+case llvm::Triple::FreeBSD:
+  return "i686";
+default:
+  // Fallback to p4.
+  return "pentium4";
+}
   }
+
+  if (Triple.getArchName() == "i786")
+return "pentium4";
+
+  return std::string(Triple.getArchName());
 }
 
 void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commi

[PATCH] D145857: [X86] Make triple ArchName override OS for i686 and i786

2023-03-12 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 504498.
pengfei added a comment.

Support i886 and i986.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145857

Files:
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  clang/test/Driver/cl-x86-flags.c
  clang/test/Driver/nacl-direct.c


Index: clang/test/Driver/nacl-direct.c
===
--- clang/test/Driver/nacl-direct.c
+++ clang/test/Driver/nacl-direct.c
@@ -6,7 +6,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-I686 %s
 // CHECK-I686: "-cc1"
 // CHECK-I686-NOT: "-fno-use-init-array"
-// CHECK-I686: "-target-cpu" "pentium4"
+// CHECK-I686: "-target-cpu" "i686"
 // CHECK-I686: "-resource-dir" "foo"
 // CHECK-I686: "-internal-isystem" "foo{{/|}}include"
 // CHECK-I686: "-internal-isystem" 
"{{.*}}{{/|}}..{{/|}}i686-nacl{{/|}}usr{{/|}}include"
Index: clang/test/Driver/cl-x86-flags.c
===
--- clang/test/Driver/cl-x86-flags.c
+++ clang/test/Driver/cl-x86-flags.c
@@ -133,5 +133,11 @@
 // tune: "-target-cpu" "sandybridge"
 // tune-SAME: "-tune-cpu" "haswell"
 
+// RUN: %clang_cl --target=i686-unknown-unknown -### -- 2>&1 %s | FileCheck 
-check-prefix=i686 %s
+// i686: "-target-cpu" "i686"
+
+// RUN: %clang_cl --target=i786-unknown-unknown -### -- 2>&1 %s | FileCheck 
-check-prefix=i786 %s
+// i786: "-target-cpu" "pentium4"
+
 void f(void) {
 }
Index: clang/lib/Driver/ToolChains/Arch/X86.cpp
===
--- clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -102,18 +102,27 @@
   if (Is64Bit)
 return "x86-64";
 
-  switch (Triple.getOS()) {
-  case llvm::Triple::NetBSD:
-return "i486";
-  case llvm::Triple::Haiku:
-  case llvm::Triple::OpenBSD:
-return "i586";
-  case llvm::Triple::FreeBSD:
-return "i686";
-  default:
-// Fallback to p4.
-return "pentium4";
+  StringRef ArchName = Triple.getArchName();
+
+  if (ArchName == "i386") {
+switch (Triple.getOS()) {
+case llvm::Triple::NetBSD:
+  return "i486";
+case llvm::Triple::Haiku:
+case llvm::Triple::OpenBSD:
+  return "i586";
+case llvm::Triple::FreeBSD:
+  return "i686";
+default:
+  // Fallback to p4.
+  return "pentium4";
+}
   }
+
+  if (ArchName == "i786" || ArchName == "i886" || ArchName == "i986")
+return "pentium4";
+
+  return std::string(ArchName);
 }
 
 void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,


Index: clang/test/Driver/nacl-direct.c
===
--- clang/test/Driver/nacl-direct.c
+++ clang/test/Driver/nacl-direct.c
@@ -6,7 +6,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-I686 %s
 // CHECK-I686: "-cc1"
 // CHECK-I686-NOT: "-fno-use-init-array"
-// CHECK-I686: "-target-cpu" "pentium4"
+// CHECK-I686: "-target-cpu" "i686"
 // CHECK-I686: "-resource-dir" "foo"
 // CHECK-I686: "-internal-isystem" "foo{{/|}}include"
 // CHECK-I686: "-internal-isystem" "{{.*}}{{/|}}..{{/|}}i686-nacl{{/|}}usr{{/|}}include"
Index: clang/test/Driver/cl-x86-flags.c
===
--- clang/test/Driver/cl-x86-flags.c
+++ clang/test/Driver/cl-x86-flags.c
@@ -133,5 +133,11 @@
 // tune: "-target-cpu" "sandybridge"
 // tune-SAME: "-tune-cpu" "haswell"
 
+// RUN: %clang_cl --target=i686-unknown-unknown -### -- 2>&1 %s | FileCheck -check-prefix=i686 %s
+// i686: "-target-cpu" "i686"
+
+// RUN: %clang_cl --target=i786-unknown-unknown -### -- 2>&1 %s | FileCheck -check-prefix=i786 %s
+// i786: "-target-cpu" "pentium4"
+
 void f(void) {
 }
Index: clang/lib/Driver/ToolChains/Arch/X86.cpp
===
--- clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -102,18 +102,27 @@
   if (Is64Bit)
 return "x86-64";
 
-  switch (Triple.getOS()) {
-  case llvm::Triple::NetBSD:
-return "i486";
-  case llvm::Triple::Haiku:
-  case llvm::Triple::OpenBSD:
-return "i586";
-  case llvm::Triple::FreeBSD:
-return "i686";
-  default:
-// Fallback to p4.
-return "pentium4";
+  StringRef ArchName = Triple.getArchName();
+
+  if (ArchName == "i386") {
+switch (Triple.getOS()) {
+case llvm::Triple::NetBSD:
+  return "i486";
+case llvm::Triple::Haiku:
+case llvm::Triple::OpenBSD:
+  return "i586";
+case llvm::Triple::FreeBSD:
+  return "i686";
+default:
+  // Fallback to p4.
+  return "pentium4";
+}
   }
+
+  if (ArchName == "i786" || ArchName == "i886" || ArchName == "i986")
+return "pentium4";
+
+  return std::string(ArchName);
 }
 
 void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
___
cf

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

2023-03-12 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan added inline comments.



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

redundant variable?


Repository:
  rG LLVM Github Monorepo

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] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-12 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

PR #61326
CorrectDelayedTyposInExpr will clean all typo error and should only
happen when return invalid ExprResult


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145892

Files:
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded 
parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 
'Unknown'}}
+}
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-03-12 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 504501.
hazohelet added a comment.

Address comments from @shafik

- Pass bool flag `UnreachableFallThroughDiagIsEnabled` instead of 
`DiagnosticsEngine`


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

https://reviews.llvm.org/D145842

Files:
  clang/include/clang/Analysis/Analyses/ReachableCode.h
  clang/lib/Analysis/ReachableCode.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/Sema/warn-unreachable-fallthrough.c

Index: clang/test/Sema/warn-unreachable-fallthrough.c
===
--- /dev/null
+++ clang/test/Sema/warn-unreachable-fallthrough.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x -Wunreachable-code-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x -Wunreachable-code %s
+// RUN: %clang_cc1 -fsyntax-only -verify=code -std=c2x -Wunreachable-code -Wno-unreachable-code-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x -Wno-unreachable-code -Wunreachable-code-fallthrough %s
+
+int n;
+void f(void){
+ switch (n){
+ [[fallthrough]]; // expected-warning{{fallthrough annotation in unreachable code}}
+  // code-warning@-1{{never be executed}}
+ case 1:;
+ }
+}
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -123,7 +123,10 @@
 return;
 
   UnreachableCodeHandler UC(S);
-  reachable_code::FindUnreachableCode(AC, S.getPreprocessor(), UC);
+  reachable_code::FindUnreachableCode(
+  AC, S.getPreprocessor(), UC,
+  !S.getDiagnostics().isIgnored(diag::warn_unreachable_fallthrough_attr,
+SourceLocation()));
 }
 
 namespace {
Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -12,6 +12,7 @@
 //===--===//
 
 #include "clang/Analysis/Analyses/ReachableCode.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -409,15 +410,16 @@
 
 void enqueue(const CFGBlock *block);
 unsigned scanBackwards(const CFGBlock *Start,
-clang::reachable_code::Callback &CB);
+   clang::reachable_code::Callback &CB,
+   const bool UnreachableFallThroughDiagIsEnabled);
 
 bool isDeadCodeRoot(const CFGBlock *Block);
 
 const Stmt *findDeadCode(const CFGBlock *Block);
 
-void reportDeadCode(const CFGBlock *B,
-const Stmt *S,
-clang::reachable_code::Callback &CB);
+void reportDeadCode(const CFGBlock *B, const Stmt *S,
+clang::reachable_code::Callback &CB,
+const bool UnreachableFallThroughDiagIsEnabled);
   };
 }
 
@@ -487,8 +489,10 @@
   return 0;
 }
 
-unsigned DeadCodeScan::scanBackwards(const clang::CFGBlock *Start,
- clang::reachable_code::Callback &CB) {
+unsigned
+DeadCodeScan::scanBackwards(const clang::CFGBlock *Start,
+clang::reachable_code::Callback &CB,
+const bool UnreachableFallThroughDiagIsEnabled) {
 
   unsigned count = 0;
   enqueue(Start);
@@ -521,7 +525,7 @@
 }
 
 if (isDeadCodeRoot(Block)) {
-  reportDeadCode(Block, S, CB);
+  reportDeadCode(Block, S, CB, UnreachableFallThroughDiagIsEnabled);
   count += scanMaybeReachableFromBlock(Block, PP, Reachable);
 }
 else {
@@ -540,7 +544,7 @@
   const CFGBlock *Block = I.first;
   if (Reachable[Block->getBlockID()])
 continue;
-  reportDeadCode(Block, I.second, CB);
+  reportDeadCode(Block, I.second, CB, UnreachableFallThroughDiagIsEnabled);
   count += scanMaybeReachableFromBlock(Block, PP, Reachable);
 }
   }
@@ -613,9 +617,9 @@
   return S->getBeginLoc();
 }
 
-void DeadCodeScan::reportDeadCode(const CFGBlock *B,
-  const Stmt *S,
-  clang::reachable_code::Callback &CB) {
+void DeadCodeScan::reportDeadCode(
+const CFGBlock *B, const Stmt *S, clang::reachable_code::Callback &CB,
+const bool UnreachableFallThroughDiagIsEnabled) {
   // Classify the unreachable code found, or suppress it in some cases.
   reachable_code::UnreachableKind UK = reachable_code::UK_Other;
 
@@ -663,6 +667,14 @@
 }
   }
 
+  // If S is `[[fallthrough]];` and `-Wunreachable-code-fallthrough` is enabled,
+  // suppress `code will never be executed` warning to avoid generating
+  // diagnostic twice
+  const AttributedStmt *AS = dyn_cast(S);
+  if (AS && hasSpecificAttr(AS->getAttrs()) &&
+  Unreach

[PATCH] D145765: Add __builtin_set_flt_rounds

2023-03-12 Thread xiongji90 via Phabricator via cfe-commits
xiongji90 updated this revision to Diff 504504.
xiongji90 added a comment.

Add semachecking test for unsupported platform.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145765

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin_set_flt_rounds.c
  clang/test/Sema/builtin_set_flt_rounds.c


Index: clang/test/Sema/builtin_set_flt_rounds.c
===
--- /dev/null
+++ clang/test/Sema/builtin_set_flt_rounds.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple mipsel-unknown-linux  -fsyntax-only %s -verify
+void test_builtin_set_flt_rounds() {
+  __builtin_set_flt_rounds(1); // expected-error {{builtin is not supported on 
this target}}
+}
+
+
+
+
Index: clang/test/CodeGen/builtin_set_flt_rounds.c
===
--- /dev/null
+++ clang/test/CodeGen/builtin_set_flt_rounds.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-gnu-linux %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang_cc1 -triple aarch64-gnu-linux %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-windows-msvc %s -emit-llvm -o - | FileCheck 
%s
+void test_builtin_set_flt_rounds() {
+  __builtin_set_flt_rounds(1);
+  // CHECK: call void @llvm.set.rounding(i32 1)
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2146,6 +2146,14 @@
   return ExprError();
 break;
 
+  case Builtin::BI__builtin_set_flt_rounds:
+if (CheckBuiltinTargetInSupported(*this, BuiltinID, TheCall,
+  {llvm::Triple::x86, llvm::Triple::x86_64,
+   llvm::Triple::arm, llvm::Triple::thumb,
+   llvm::Triple::aarch64}))
+  return ExprError();
+break;
+
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3381,6 +3381,15 @@
 return RValue::get(Result);
   }
 
+  case Builtin::BI__builtin_set_flt_rounds: {
+Function *F = CGM.getIntrinsic(Intrinsic::set_rounding);
+
+Value *V = EmitScalarExpr(E->getArg(0));
+Builder.CreateCall(F, V);
+return RValue::get(nullptr);
+  }
+
+
   case Builtin::BI__builtin_fpclassify: {
 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
 // FIXME: for strictfp/IEEE-754 we need to not trap on SNaN here.
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -397,6 +397,7 @@
 
 // Access to floating point environment
 BUILTIN(__builtin_flt_rounds, "i", "n")
+BUILTIN(__builtin_set_flt_rounds, "vi", "n")
 
 // C99 complex builtins
 BUILTIN(__builtin_cabs, "dXd", "Fne")


Index: clang/test/Sema/builtin_set_flt_rounds.c
===
--- /dev/null
+++ clang/test/Sema/builtin_set_flt_rounds.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple mipsel-unknown-linux  -fsyntax-only %s -verify
+void test_builtin_set_flt_rounds() {
+  __builtin_set_flt_rounds(1); // expected-error {{builtin is not supported on this target}}
+}
+
+
+
+
Index: clang/test/CodeGen/builtin_set_flt_rounds.c
===
--- /dev/null
+++ clang/test/CodeGen/builtin_set_flt_rounds.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-gnu-linux %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-gnu-linux %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-windows-msvc %s -emit-llvm -o - | FileCheck %s
+void test_builtin_set_flt_rounds() {
+  __builtin_set_flt_rounds(1);
+  // CHECK: call void @llvm.set.rounding(i32 1)
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2146,6 +2146,14 @@
   return ExprError();
 break;
 
+  case Builtin::BI__builtin_set_flt_rounds:
+if (CheckBuiltinTargetInSupported(*this, BuiltinID, TheCall,
+  {llvm::Triple::x86, llvm::Triple::x86_64,
+   llvm::Triple::arm, llvm::Triple::thumb,
+   llvm::Triple::aarch64}))
+  return ExprError();
+   

[PATCH] D145319: [clangd] Refine logic on $0 in completion snippets

2023-03-12 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks for the patch!

In the future we may want to add other cursor kinds for which 
`ShouldPatchPlaceholder0` should be false, but I think this is a good start 
which addresses the case from the bug.




Comment at: clang-tools-extra/clangd/CodeComplete.cpp:441
   getSignature(*SemaCCS, &S.Signature, &S.SnippetSuffix,
-   &Completion.RequiredQualifier, IsPattern);
+   &Completion.RequiredQualifier, IsPattern, C.SemaResult);
   if (!C.SemaResult->FunctionCanBeCall)

Since we are now passing in the entire `C.SemaResult`, can we remove the 
`CompletingPattern` parameter, and compute that boolean inside the function 
instead?



Comment at: clang-tools-extra/clangd/CodeCompletionStrings.cpp:104
   unsigned CursorSnippetArg = std::numeric_limits::max();
   if (CompletingPattern) {
 // In patterns, it's best to place the cursor at the last placeholder, to

Can we move this check after the declaration of `ShouldPatchPlaceholder0`, and 
change the condition to `if (ShouldPatchPlaceholder0)`?

(And at the usage site, swap the operands to `if (ShouldPatchPlaceholder0 && 
SnippetArg == CursorSnippetArg)`?)

This would avoid doing the count_if when not necessary.



Comment at: clang-tools-extra/clangd/CodeCompletionStrings.cpp:130
+  return false;
+return true;
+  }();

zyounan wrote:
> I was cringed that if we should refine the logic based on `CursorKind`: It is 
> from libclang; The meaning is sometimes kind of opaque (to me, I don't know 
> it very clearly TBH) like `CXCursor_NotImplemented`...
It does seem like a layering violation that a libSema interface 
(CodeCompletionResult) uses a libclang type (CXCursorKind), but that's a 
pre-existing issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145319

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


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

2023-03-12 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

What is the status of this patch --  is it still relevant, and if so are there 
plans to finish/merge it?


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] D139277: [clangd] Use all query-driver arguments in cache key

2023-03-12 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

@ehntoo hi! are you planning to update this patch to address Kadir's comments?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139277

___
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-12 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Review ping :)


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] D145765: Add __builtin_set_flt_rounds

2023-03-12 Thread xiongji90 via Phabricator via cfe-commits
xiongji90 marked an inline comment as done.
xiongji90 added inline comments.



Comment at: clang/test/CodeGen/builtin_set_flt_rounds.c:5-7
+void test_builtin_set_flt_rounds() {
+  __builtin_set_flt_rounds(1);
+  // CHECK: call void @llvm.set.rounding(i32 1)

aaron.ballman wrote:
> I think you should also add some Sema tests for correct and misuse of the 
> builtin:
> ```
> __builtin_set_flt_rounds(1); // OK
> 
> struct S { int a; } s;
> __builtin_set_flt_rounds(s); // This should diagnose, right?
> 
> __builtin_set_flt_rounds(1.0f); // Should this implicitly convert or is this 
> an error?
> ```
> and that sema test can additionally test what happens when you call the 
> builtin on an unsupported architecture.
Hi, @aaron.ballman 
I added a new test in test/Sema to check the builtin on platforms unsupported.
Thanks very much.


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] D145765: Add __builtin_set_flt_rounds

2023-03-12 Thread xiongji90 via Phabricator via cfe-commits
xiongji90 updated this revision to Diff 504508.
xiongji90 added a comment.

Add SemaChecking test for incompatible input arguments for 
__builtin_set_flt_rounds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145765

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin_set_flt_rounds.c
  clang/test/Sema/builtin_set_flt_rounds.c


Index: clang/test/Sema/builtin_set_flt_rounds.c
===
--- /dev/null
+++ clang/test/Sema/builtin_set_flt_rounds.c
@@ -0,0 +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
+struct S s;
+__builtin_set_flt_rounds(s); // expected-error {{passing 'struct S' to 
parameter of incompatible type}}
+#endif
+}
Index: clang/test/CodeGen/builtin_set_flt_rounds.c
===
--- /dev/null
+++ clang/test/CodeGen/builtin_set_flt_rounds.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-gnu-linux %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang_cc1 -triple aarch64-gnu-linux %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-windows-msvc %s -emit-llvm -o - | FileCheck 
%s
+void test_builtin_set_flt_rounds() {
+  __builtin_set_flt_rounds(1);
+  // CHECK: call void @llvm.set.rounding(i32 1)
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2146,6 +2146,14 @@
   return ExprError();
 break;
 
+  case Builtin::BI__builtin_set_flt_rounds:
+if (CheckBuiltinTargetInSupported(*this, BuiltinID, TheCall,
+  {llvm::Triple::x86, llvm::Triple::x86_64,
+   llvm::Triple::arm, llvm::Triple::thumb,
+   llvm::Triple::aarch64}))
+  return ExprError();
+break;
+
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3381,6 +3381,15 @@
 return RValue::get(Result);
   }
 
+  case Builtin::BI__builtin_set_flt_rounds: {
+Function *F = CGM.getIntrinsic(Intrinsic::set_rounding);
+
+Value *V = EmitScalarExpr(E->getArg(0));
+Builder.CreateCall(F, V);
+return RValue::get(nullptr);
+  }
+
+
   case Builtin::BI__builtin_fpclassify: {
 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
 // FIXME: for strictfp/IEEE-754 we need to not trap on SNaN here.
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -397,6 +397,7 @@
 
 // Access to floating point environment
 BUILTIN(__builtin_flt_rounds, "i", "n")
+BUILTIN(__builtin_set_flt_rounds, "vi", "n")
 
 // C99 complex builtins
 BUILTIN(__builtin_cabs, "dXd", "Fne")


Index: clang/test/Sema/builtin_set_flt_rounds.c
===
--- /dev/null
+++ clang/test/Sema/builtin_set_flt_rounds.c
@@ -0,0 +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
+struct S s;
+__builtin_set_flt_rounds(s); // expected-error {{passing 'struct S' to parameter of incompatible type}}
+#endif
+}
Index: clang/test/CodeGen/builtin_set_flt_rounds.c
===
--- /dev/null
+++ clang/test/CodeGen/builtin_set_flt_rounds.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-gnu-linux %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-gnu-linux %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-windows-msvc %s -emit-llvm -o - | FileCheck %s
+void test_builtin_set_flt_rounds() {
+  __builtin_set_flt_rounds(1);
+  // CHECK: call void @llvm.set.rounding(i32 1)
+}
Index: clang/lib/Sema/SemaChecking.cpp
=

[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-03-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

It looks like that the `Create` template functions get merged expectedly. And 
the dummy variable shouldn't get merged since it is not in a mergeable primary 
context (function context is not a mergeable primary context) (see 
https://github.com/llvm/llvm-project/blob/23bd0e037b744d1f93bdfad59b7575017725a96c/clang/lib/Serialization/ASTReaderDecl.cpp#L3107-L3151).

When I remove the use of `dummy` in the captures list, 
https://github.com/llvm/llvm-project/blob/23bd0e037b744d1f93bdfad59b7575017725a96c/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L6079
 is not executed. No matter if the `dummy` variable is captured or not, 
https://github.com/llvm/llvm-project/blob/23bd0e037b744d1f93bdfad59b7575017725a96c/clang/lib/Sema/SemaTemplateInstantiate.cpp#L4069-L4088
 will execute twice for the `dummy` variable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


[PATCH] D145899: [AIX][Clang] Respect -r when invoking the linker On AIX, libraries are still being linked when `-r` is passed to the driver. This patch corrects this error.

2023-03-12 Thread Michael Francis via Phabricator via cfe-commits
francii created this revision.
Herald added a project: All.
francii requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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
@@ -1692,6 +1692,8 @@
 break;
   }
   case ToolChain::UNW_CompilerRT:
+if (Args.hasArg(options::OPT_r))
+  break;
 if (TC.getTriple().isOSAIX()) {
   // AIX only has libunwind as a shared library. So do not pass
   // anything in if -static is specified.
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(;
 
@@ -233,6 +233,13 @@
   }
 
   // Add directory to library search path.
+  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;
+  }
+
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
   ToolChain.addProfileRTLibs(Args, CmdArgs);


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1692,6 +1692,8 @@
 break;
   }
   case ToolChain::UNW_CompilerRT:
+if (Args.hasArg(options::OPT_r))
+  break;
 if (TC.getTriple().isOSAIX()) {
   // AIX only has libunwind as a shared library. So do not pass
   // anything in if -static is specified.
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(;
 
@@ -233,6 +233,13 @@
   }
 
   // Add directory to library search path.
+  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;
+  }
+
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
   ToolChain.addProfileRTLibs(Args, CmdArgs);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145820: [Clang][OpenMP] Insert alloca for kernel args at function entry block instead of the launch point.

2023-03-12 Thread Dhruva Chakrabarti via Phabricator via cfe-commits
dhruvachak updated this revision to Diff 504515.
dhruvachak added a comment.
Herald added subscribers: mattd, asavonic.

Addressed comment. Using the alloca insert point for kernel args alloca.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145820

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/align_clause_codegen.cpp
  clang/test/OpenMP/atomic_compare_codegen.cpp
  clang/test/OpenMP/distribute_codegen.cpp
  clang/test/OpenMP/distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_reduction_codegen.cpp
  clang/test/OpenMP/for_non_rectangular_codegen.c
  clang/test/OpenMP/irbuilder_nested_openmp_parallel_empty.c
  clang/test/OpenMP/nested_loop_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/reduction_compound_op.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/target_codegen_global_capture.cpp
  clang/test/OpenMP/target_has_device_addr_codegen.cpp
  clang/test/OpenMP/target_has_device_addr_codegen_01.cpp
  clang/test/OpenMP/target_map_codegen_03.cpp
  clang/test/OpenMP/target_map_codegen_hold.cpp
  clang/test/OpenMP/target_map_deref_array_codegen.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  clang/test/OpenMP/target_offload_mandatory_codegen.cpp
  clang/test/OpenMP/target_ompx_dyn_cgroup_mem_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_if_codegen.cpp
  clang/test/OpenMP/target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/target_task_affinity_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_collapse_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_proc_bind_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_collapse_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_dist_schedule_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_lastprivate_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_private_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_proc_bind_codegen.cpp
  
clang/test/OpenMP/target_teams_dis

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

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

Move comment


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
@@ -1692,6 +1692,8 @@
 break;
   }
   case ToolChain::UNW_CompilerRT:
+if (Args.hasArg(options::OPT_r))
+  break;
 if (TC.getTriple().isOSAIX()) {
   // AIX only has libunwind as a shared library. So do not pass
   // anything in if -static is specified.
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
@@ -1692,6 +1692,8 @@
 break;
   }
   case ToolChain::UNW_CompilerRT:
+if (Args.hasArg(options::OPT_r))
+  break;
 if (TC.getTriple().isOSAIX()) {
   // AIX only has libunwind as a shared library. So do not pass
   // anything in if -static is specified.
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