[PATCH] D126619: [OpenMP][Clang] Fix atomic compare for signed vs. unsigned

2022-05-29 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

Thanks for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126619

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


[PATCH] D123924: [clang-apply-replacements] Added an option to ignore insert conflict.

2022-05-29 Thread gehry via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3f3a235aa2e6: [clang-apply-replacements] Added an option to 
ignore insert conflict. (authored by Sockke).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123924

Files:
  
clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
  clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
  clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
  clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
  
clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/file1.yaml
  
clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/ignore-conflict.cpp
  clang-tools-extra/test/clang-apply-replacements/ignore-conflict.cpp
  clang/include/clang/Tooling/Refactoring/AtomicChange.h

Index: clang/include/clang/Tooling/Refactoring/AtomicChange.h
===
--- clang/include/clang/Tooling/Refactoring/AtomicChange.h
+++ clang/include/clang/Tooling/Refactoring/AtomicChange.h
@@ -116,6 +116,8 @@
   /// Returns a const reference to existing replacements.
   const Replacements () const { return Replaces; }
 
+  Replacements () { return Replaces; }
+
   llvm::ArrayRef getInsertedHeaders() const {
 return InsertedHeaders;
   }
Index: clang-tools-extra/test/clang-apply-replacements/ignore-conflict.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/ignore-conflict.cpp
@@ -0,0 +1,5 @@
+// RUN: mkdir -p %T/Inputs/ignore-conflict
+// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/ignore-conflict/ignore-conflict.cpp > %T/Inputs/ignore-conflict/ignore-conflict.cpp
+// RUN: sed "s#\$(path)#%/T/Inputs/ignore-conflict#" %S/Inputs/ignore-conflict/file1.yaml > %T/Inputs/ignore-conflict/file1.yaml
+// RUN: clang-apply-replacements --ignore-insert-conflict %T/Inputs/ignore-conflict
+// RUN: FileCheck -input-file=%T/Inputs/ignore-conflict/ignore-conflict.cpp %S/Inputs/ignore-conflict/ignore-conflict.cpp
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/ignore-conflict.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/ignore-conflict.cpp
@@ -0,0 +1,4 @@
+class MyType {};
+// CHECK: #include 
+// CHECK-NEXT: #include 
+// CEHCK-NEXT: class MyType {};
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/file1.yaml
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/file1.yaml
@@ -0,0 +1,24 @@
+---
+MainSourceFile: ignore-conflict.cpp
+Diagnostics:
+  - DiagnosticName: test-ignore-conflict-insertion
+DiagnosticMessage:
+  Message: Fix
+  FilePath: $(path)/ignore-conflict.cpp
+  FileOffset: 0
+  Replacements:
+- FilePath:$(path)/ignore-conflict.cpp
+  Offset:  0
+  Length:  0
+  ReplacementText: "#include \n"
+  - DiagnosticName: test-ignore-conflict-insertion
+DiagnosticMessage:
+  Message: Fix
+  FilePath: $(path)/ignore-conflict.cpp
+  FileOffset: 0
+  Replacements:
+- FilePath:$(path)/ignore-conflict.cpp
+  Offset:  0
+  Length:  0
+  ReplacementText: "#include \n"
+...
Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -180,6 +180,7 @@
 def apply_fixes(args, clang_apply_replacements_binary, tmpdir):
   """Calls clang-apply-fixes on a given directory."""
   invocation = [clang_apply_replacements_binary]
+  invocation.append('-ignore-insert-conflict')
   if args.format:
 invocation.append('-format')
   if args.style:
Index: clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
===
--- clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
+++ clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
@@ -42,6 +42,11 @@
  "merging/replacing."),
 cl::init(false), cl::cat(ReplacementCategory));
 
+static cl::opt IgnoreInsertConflict(
+"ignore-insert-conflict",
+cl::desc("Ignore insert conflict and keep running to fix."),
+cl::init(false), cl::cat(ReplacementCategory));
+
 static cl::opt DoFormat(
 "format",
 cl::desc("Enable formatting of code changed by applying replacements.\n"
@@ -131,7 +136,7 @@
   SourceManager SM(Diagnostics, Files);
 
   

[clang-tools-extra] 3f3a235 - [clang-apply-replacements] Added an option to ignore insert conflict.

2022-05-29 Thread via cfe-commits

Author: Sockke
Date: 2022-05-30T13:02:25+08:00
New Revision: 3f3a235aa2e610b5ba393228a666d55a8135ef4a

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

LOG: [clang-apply-replacements] Added an option to ignore insert conflict.

If two different texts are inserted at the same offset, 
clang-apply-replacements prints the conflict error and discards all fixes. This 
patch adds support for adjusting conflict offset and keeps running to 
continually fix them.

https://godbolt.org/z/P938EGoxj doesn't have any fixes when I run 
run-clang-tidy.py to generate a YAML file with clang-tidy and fix them with 
clang-apply-replacements. The YAML file has two different header texts 
insertions at the same offset, unlike clang-tidy with '-fix', 
clang-apply-replacements does not adjust for this conflict.

Reviewed By: aaron.ballman

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

Added: 

clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/file1.yaml

clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/ignore-conflict.cpp
clang-tools-extra/test/clang-apply-replacements/ignore-conflict.cpp

Modified: 

clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
clang/include/clang/Tooling/Refactoring/AtomicChange.h

Removed: 




diff  --git 
a/clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
 
b/clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
index e37768277c5a4..b0cf7317c0ed8 100644
--- 
a/clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
+++ 
b/clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
@@ -87,7 +87,8 @@ std::error_code collectReplacementsFromDirectory(
 ///  \li false If there were conflicts.
 bool mergeAndDeduplicate(const TUReplacements , const TUDiagnostics ,
  FileToChangesMap ,
- clang::SourceManager );
+ clang::SourceManager ,
+ bool IgnoreInsertConflict = false);
 
 /// Apply \c AtomicChange on File and rewrite it.
 ///

diff  --git 
a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp 
b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
index b13b83cf3f000..e25c8e2449dc8 100644
--- 
a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
+++ 
b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
@@ -202,7 +202,7 @@ groupReplacements(const TUReplacements , const 
TUDiagnostics ,
 
 bool mergeAndDeduplicate(const TUReplacements , const TUDiagnostics ,
  FileToChangesMap ,
- clang::SourceManager ) {
+ clang::SourceManager , bool IgnoreInsertConflict) {
   auto GroupedReplacements = groupReplacements(TUs, TUDs, SM);
   bool ConflictDetected = false;
 
@@ -231,7 +231,24 @@ bool mergeAndDeduplicate(const TUReplacements , const 
TUDiagnostics ,
 // For now, printing directly the error reported by `AtomicChange` is
 // the easiest solution.
 errs() << llvm::toString(std::move(Err)) << "\n";
-ConflictDetected = true;
+if (IgnoreInsertConflict) {
+  tooling::Replacements  = FileChange.getReplacements();
+  unsigned NewOffset =
+  Replacements.getShiftedCodePosition(R.getOffset());
+  unsigned NewLength = Replacements.getShiftedCodePosition(
+   R.getOffset() + R.getLength()) -
+   NewOffset;
+  if (NewLength == R.getLength()) {
+tooling::Replacement RR = tooling::Replacement(
+R.getFilePath(), NewOffset, NewLength, R.getReplacementText());
+Replacements = Replacements.merge(tooling::Replacements(RR));
+  } else {
+llvm::errs()
+<< "Can't resolve conflict, skipping the replacement.\n";
+ConflictDetected = true;
+  }
+} else
+  ConflictDetected = true;
   }
 }
 FileChanges.try_emplace(Entry,

diff  --git 
a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
 
b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
index 52ef725352d0b..68e7feaa3baed 100644
--- 

[PATCH] D123924: [clang-apply-replacements] Added an option to ignore insert conflict.

2022-05-29 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 432829.

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

https://reviews.llvm.org/D123924

Files:
  
clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
  clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
  clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
  clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
  
clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/file1.yaml
  
clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/ignore-conflict.cpp
  clang-tools-extra/test/clang-apply-replacements/ignore-conflict.cpp
  clang/include/clang/Tooling/Refactoring/AtomicChange.h

Index: clang/include/clang/Tooling/Refactoring/AtomicChange.h
===
--- clang/include/clang/Tooling/Refactoring/AtomicChange.h
+++ clang/include/clang/Tooling/Refactoring/AtomicChange.h
@@ -116,6 +116,8 @@
   /// Returns a const reference to existing replacements.
   const Replacements () const { return Replaces; }
 
+  Replacements () { return Replaces; }
+
   llvm::ArrayRef getInsertedHeaders() const {
 return InsertedHeaders;
   }
Index: clang-tools-extra/test/clang-apply-replacements/ignore-conflict.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/ignore-conflict.cpp
@@ -0,0 +1,5 @@
+// RUN: mkdir -p %T/Inputs/ignore-conflict
+// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/ignore-conflict/ignore-conflict.cpp > %T/Inputs/ignore-conflict/ignore-conflict.cpp
+// RUN: sed "s#\$(path)#%/T/Inputs/ignore-conflict#" %S/Inputs/ignore-conflict/file1.yaml > %T/Inputs/ignore-conflict/file1.yaml
+// RUN: clang-apply-replacements --ignore-insert-conflict %T/Inputs/ignore-conflict
+// RUN: FileCheck -input-file=%T/Inputs/ignore-conflict/ignore-conflict.cpp %S/Inputs/ignore-conflict/ignore-conflict.cpp
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/ignore-conflict.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/ignore-conflict.cpp
@@ -0,0 +1,4 @@
+class MyType {};
+// CHECK: #include 
+// CHECK-NEXT: #include 
+// CEHCK-NEXT: class MyType {};
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/file1.yaml
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/file1.yaml
@@ -0,0 +1,24 @@
+---
+MainSourceFile: ignore-conflict.cpp
+Diagnostics:
+  - DiagnosticName: test-ignore-conflict-insertion
+DiagnosticMessage:
+  Message: Fix
+  FilePath: $(path)/ignore-conflict.cpp
+  FileOffset: 0
+  Replacements:
+- FilePath:$(path)/ignore-conflict.cpp
+  Offset:  0
+  Length:  0
+  ReplacementText: "#include \n"
+  - DiagnosticName: test-ignore-conflict-insertion
+DiagnosticMessage:
+  Message: Fix
+  FilePath: $(path)/ignore-conflict.cpp
+  FileOffset: 0
+  Replacements:
+- FilePath:$(path)/ignore-conflict.cpp
+  Offset:  0
+  Length:  0
+  ReplacementText: "#include \n"
+...
Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -180,6 +180,7 @@
 def apply_fixes(args, clang_apply_replacements_binary, tmpdir):
   """Calls clang-apply-fixes on a given directory."""
   invocation = [clang_apply_replacements_binary]
+  invocation.append('-ignore-insert-conflict')
   if args.format:
 invocation.append('-format')
   if args.style:
Index: clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
===
--- clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
+++ clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
@@ -42,6 +42,11 @@
  "merging/replacing."),
 cl::init(false), cl::cat(ReplacementCategory));
 
+static cl::opt IgnoreInsertConflict(
+"ignore-insert-conflict",
+cl::desc("Ignore insert conflict and keep running to fix."),
+cl::init(false), cl::cat(ReplacementCategory));
+
 static cl::opt DoFormat(
 "format",
 cl::desc("Enable formatting of code changed by applying replacements.\n"
@@ -131,7 +136,7 @@
   SourceManager SM(Diagnostics, Files);
 
   FileToChangesMap Changes;
-  if (!mergeAndDeduplicate(TURs, TUDs, Changes, SM))
+  if (!mergeAndDeduplicate(TURs, TUDs, Changes, SM, IgnoreInsertConflict))
 return 1;
 
   

[PATCH] D126451: [Clang][CSKY] Add support about CSKYABIInfo

2022-05-29 Thread Zixuan Wu via Phabricator via cfe-commits
zixuan-wu updated this revision to Diff 432820.

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

https://reviews.llvm.org/D126451

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/CSKY/csky-abi.c
  clang/test/CodeGen/CSKY/csky-hard-abi.c
  clang/test/CodeGen/CSKY/csky-soft-abi.c

Index: clang/test/CodeGen/CSKY/csky-soft-abi.c
===
--- /dev/null
+++ clang/test/CodeGen/CSKY/csky-soft-abi.c
@@ -0,0 +1,395 @@
+// RUN: %clang_cc1 -no-opaque-pointers -triple csky -target-feature +fpuv2_sf -target-feature +fpuv2_df -target-feature +hard-float -emit-llvm %s -o - | FileCheck %s
+
+#include 
+
+// Verify that the tracking of used GPRs and FPRs works correctly by checking
+// that small integers are sign/zero extended when passed in registers.
+
+// Doubles are passed in FPRs, so argument 'i' will be passed zero-extended
+// because it will be passed in a GPR.
+
+// CHECK: define{{.*}} void @f_fpr_tracking(double noundef %a, double noundef %b, double noundef %c, double noundef %d, i8 noundef zeroext %i)
+void f_fpr_tracking(double a, double b, double c, double d, uint8_t i) {}
+
+// A struct containing just one floating-point real is passed as though it
+// were a standalone floating-point real.
+struct double_s {
+  double f;
+};
+
+// CHECK: define{{.*}} void @f_double_s_arg(double %a.coerce)
+void f_double_s_arg(struct double_s a) {}
+
+// CHECK: define{{.*}} double @f_ret_double_s()
+struct double_s f_ret_double_s(void) {
+  return (struct double_s){1.0};
+}
+
+// A struct containing a double and any number of zero-width bitfields is
+// passed as though it were a standalone floating-point real.
+
+struct zbf_double_s {
+  int : 0;
+  double f;
+};
+struct zbf_double_zbf_s {
+  int : 0;
+  double f;
+  int : 0;
+};
+
+// CHECK: define{{.*}} void @f_zbf_double_s_arg(double %a.coerce)
+void f_zbf_double_s_arg(struct zbf_double_s a) {}
+
+// CHECK: define{{.*}} double @f_ret_zbf_double_s()
+struct zbf_double_s f_ret_zbf_double_s(void) {
+  return (struct zbf_double_s){1.0};
+}
+
+// CHECK: define{{.*}} void @f_zbf_double_zbf_s_arg(double %a.coerce)
+void f_zbf_double_zbf_s_arg(struct zbf_double_zbf_s a) {}
+
+// CHECK: define{{.*}} double @f_ret_zbf_double_zbf_s()
+struct zbf_double_zbf_s f_ret_zbf_double_zbf_s(void) {
+  return (struct zbf_double_zbf_s){1.0};
+}
+
+// For argument type, the first 4*XLen parts of aggregate will be passed
+// in registers, and the rest will be passed in stack.
+// So we can coerce to integers directly and let backend handle it correctly.
+// For return type, aggregate which <= 2*XLen will be returned in registers.
+// Otherwise, aggregate will be returned indirectly.
+
+struct double_double_s {
+  double f;
+  double g;
+};
+struct double_float_s {
+  double f;
+  float g;
+};
+
+// CHECK: define{{.*}} void @f_double_double_s_arg([4 x i32] %a.coerce)
+void f_double_double_s_arg(struct double_double_s a) {}
+
+// CHECK: define{{.*}} void @f_ret_double_double_s(%struct.double_double_s* noalias sret(%struct.double_double_s) align 4 %agg.result)
+struct double_double_s f_ret_double_double_s(void) {
+  return (struct double_double_s){1.0, 2.0};
+}
+
+// CHECK: define{{.*}} void @f_double_float_s_arg([3 x i32] %a.coerce)
+void f_double_float_s_arg(struct double_float_s a) {}
+
+// CHECK: define{{.*}} void @f_ret_double_float_s(%struct.double_float_s* noalias sret(%struct.double_float_s) align 4 %agg.result)
+struct double_float_s f_ret_double_float_s(void) {
+  return (struct double_float_s){1.0, 2.0};
+}
+
+// CHECK: define{{.*}} void @f_double_double_s_arg_insufficient_fprs(float noundef %a, double noundef %b, double noundef %c, double noundef %d, double noundef %e, double noundef %f, double noundef %g, double noundef %i, [4 x i32] %h.coerce)
+void f_double_double_s_arg_insufficient_fprs(float a, double b, double c, double d,
+ double e, double f, double g, double i, struct double_double_s h) {}
+
+struct double_int8_s {
+  double f;
+  int8_t i;
+};
+struct double_uint8_s {
+  double f;
+  uint8_t i;
+};
+struct double_int32_s {
+  double f;
+  int32_t i;
+};
+struct double_int64_s {
+  double f;
+  int64_t i;
+};
+struct double_int64bf_s {
+  double f;
+  int64_t i : 32;
+};
+struct double_int8_zbf_s {
+  double f;
+  int8_t i;
+  int : 0;
+};
+
+// CHECK: define{{.*}}  @f_double_int8_s_arg([3 x i32] %a.coerce)
+void f_double_int8_s_arg(struct double_int8_s a) {}
+
+// CHECK: define{{.*}} void @f_ret_double_int8_s(%struct.double_int8_s* noalias sret(%struct.double_int8_s) align 4 %agg.result)
+struct double_int8_s f_ret_double_int8_s(void) {
+  return (struct double_int8_s){1.0, 2};
+}
+
+// CHECK: define{{.*}} void @f_double_uint8_s_arg([3 x i32] %a.coerce)
+void f_double_uint8_s_arg(struct double_uint8_s a) {}
+
+// CHECK: define{{.*}} void @f_ret_double_uint8_s(%struct.double_uint8_s* noalias sret(%struct.double_uint8_s) align 4 %agg.result)

[clang] 42c3c70 - Revert "[Driver] Enable to use C++20 standalne by -fcxx-modules"

2022-05-29 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2022-05-30T10:43:13+08:00
New Revision: 42c3c70a9e3f0a697b8794f4e8b603091ffb12a4

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

LOG: Revert "[Driver] Enable to use C++20 standalne by -fcxx-modules"

This reverts commit 99eca8353808f63670c647aeae03e0ce66eb21e0.

Since it would cause clang-tools-extra fail.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/modules.cpp

Removed: 
clang/test/Modules/cxx-modules.cppm



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0343e48c1a9d1..e19baac5860aa 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1410,7 +1410,7 @@ defm async_exceptions: BoolFOption<"async-exceptions",
   PosFlag, 
NegFlag>;
 defm cxx_modules : BoolFOption<"cxx-modules",
   LangOpts<"CPlusPlusModules">, Default,
-  NegFlag, PosFlag,
+  NegFlag, PosFlag,
   BothFlags<[NoXarchOption], " modules for C++">>,
   ShouldParseIf;
 def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, 
Group;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5106c0e327b87..936682e49299e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3627,12 +3627,6 @@ static void RenderModulesOptions(Compilation , const 
Driver ,
 HaveModules = true;
   }
 
-  if (Args.hasFlag(options::OPT_fcxx_modules, options::OPT_fno_cxx_modules,
-   false)) {
-CmdArgs.push_back("-fcxx-modules");
-HaveModules = true;
-  }
-
   // -fmodule-maps enables implicit reading of module map files. By default,
   // this is enabled if we are using Clang's flavor of precompiled modules.
   if (Args.hasFlag(options::OPT_fimplicit_module_maps,

diff  --git a/clang/test/Driver/modules.cpp b/clang/test/Driver/modules.cpp
index bac9f715f13a4..87b6cc640cb0d 100644
--- a/clang/test/Driver/modules.cpp
+++ b/clang/test/Driver/modules.cpp
@@ -73,14 +73,3 @@ import "foo.h";
 // CHECK-HEADER-UNIT-USE: BAR;
 FOO;
 #endif
-
-// Check the independent use of -fcxx-modules
-//
-// RUN: %clang++ -fcxx-modules -std=c++17 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX17-MODULES
-// CHECK-CXX17-MODULES: "-fcxx-modules"
-// RUN: %clang++ -fcxx-modules -std=c++14 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX14-MODULES
-// CHECK-CXX14-MODULES: "-fcxx-modules"
-// RUN: %clang++ -fcxx-modules -std=c++11 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX11-MODULES
-// CHECK-CXX11-MODULES: "-fcxx-modules"
-// RUN: %clang++ -fcxx-modules -std=c++03 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX03-MODULES
-// CHECK-CXX03-MODULES: "-fcxx-modules"

diff  --git a/clang/test/Modules/cxx-modules.cppm 
b/clang/test/Modules/cxx-modules.cppm
deleted file mode 100644
index be17f85f8d17d..0
--- a/clang/test/Modules/cxx-modules.cppm
+++ /dev/null
@@ -1,7 +0,0 @@
-// This tests that we could use C++20 modules standalone.
-// RUN: %clang -std=c++03 -fcxx-modules -fsyntax-only -Xclang -verify %s
-// RUN: %clang -std=c++11 -fcxx-modules -fsyntax-only -Xclang -verify %s
-// RUN: %clang -std=c++14 -fcxx-modules -fsyntax-only -Xclang -verify %s
-// RUN: %clang -std=c++17 -fcxx-modules -fsyntax-only -Xclang -verify %s
-// expected-no-diagnostics
-export module M;



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


[PATCH] D120495: [clang][dataflow] Add transfer functions for structured bindings

2022-05-29 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.

Looks good, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120495

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


[PATCH] D120540: [Driver] Enable to use C++20 modules standalone by -fcxx-modules

2022-05-29 Thread Chuanqi Xu 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 rG99eca8353808: [Driver] Enable to use C++20 standalne by 
-fcxx-modules (authored by ChuanqiXu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120540

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/modules.cpp
  clang/test/Modules/cxx-modules.cppm


Index: clang/test/Modules/cxx-modules.cppm
===
--- /dev/null
+++ clang/test/Modules/cxx-modules.cppm
@@ -0,0 +1,7 @@
+// This tests that we could use C++20 modules standalone.
+// RUN: %clang -std=c++03 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++11 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++14 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++17 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// expected-no-diagnostics
+export module M;
Index: clang/test/Driver/modules.cpp
===
--- clang/test/Driver/modules.cpp
+++ clang/test/Driver/modules.cpp
@@ -73,3 +73,14 @@
 // CHECK-HEADER-UNIT-USE: BAR;
 FOO;
 #endif
+
+// Check the independent use of -fcxx-modules
+//
+// RUN: %clang++ -fcxx-modules -std=c++17 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX17-MODULES
+// CHECK-CXX17-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++14 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX14-MODULES
+// CHECK-CXX14-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++11 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX11-MODULES
+// CHECK-CXX11-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++03 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX03-MODULES
+// CHECK-CXX03-MODULES: "-fcxx-modules"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3627,6 +3627,12 @@
 HaveModules = true;
   }
 
+  if (Args.hasFlag(options::OPT_fcxx_modules, options::OPT_fno_cxx_modules,
+   false)) {
+CmdArgs.push_back("-fcxx-modules");
+HaveModules = true;
+  }
+
   // -fmodule-maps enables implicit reading of module map files. By default,
   // this is enabled if we are using Clang's flavor of precompiled modules.
   if (Args.hasFlag(options::OPT_fimplicit_module_maps,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1410,7 +1410,7 @@
   PosFlag, 
NegFlag>;
 defm cxx_modules : BoolFOption<"cxx-modules",
   LangOpts<"CPlusPlusModules">, Default,
-  NegFlag, PosFlag,
+  NegFlag, PosFlag,
   BothFlags<[NoXarchOption], " modules for C++">>,
   ShouldParseIf;
 def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, 
Group;


Index: clang/test/Modules/cxx-modules.cppm
===
--- /dev/null
+++ clang/test/Modules/cxx-modules.cppm
@@ -0,0 +1,7 @@
+// This tests that we could use C++20 modules standalone.
+// RUN: %clang -std=c++03 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++11 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++14 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++17 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// expected-no-diagnostics
+export module M;
Index: clang/test/Driver/modules.cpp
===
--- clang/test/Driver/modules.cpp
+++ clang/test/Driver/modules.cpp
@@ -73,3 +73,14 @@
 // CHECK-HEADER-UNIT-USE: BAR;
 FOO;
 #endif
+
+// Check the independent use of -fcxx-modules
+//
+// RUN: %clang++ -fcxx-modules -std=c++17 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-CXX17-MODULES
+// CHECK-CXX17-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++14 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-CXX14-MODULES
+// CHECK-CXX14-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++11 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-CXX11-MODULES
+// CHECK-CXX11-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++03 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-CXX03-MODULES
+// CHECK-CXX03-MODULES: "-fcxx-modules"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3627,6 +3627,12 @@
 HaveModules = true;
   }
 
+  if (Args.hasFlag(options::OPT_fcxx_modules, options::OPT_fno_cxx_modules,
+   false)) {
+

[clang] 99eca83 - [Driver] Enable to use C++20 standalne by -fcxx-modules

2022-05-29 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2022-05-30T10:24:09+08:00
New Revision: 99eca8353808f63670c647aeae03e0ce66eb21e0

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

LOG: [Driver] Enable to use C++20 standalne by -fcxx-modules

This patch allows user to use C++20 module by -fcxx-modules. Previously,
we could only use it under -std=c++20. Given that user could use C++20
coroutine standalonel by -fcoroutines-ts. It makes sense to offer an
option to use C++20 modules without enabling C++20.

Reviewed By: iains, MaskRay

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

Added: 
clang/test/Modules/cxx-modules.cppm

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/modules.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e19baac5860aa..0343e48c1a9d1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1410,7 +1410,7 @@ defm async_exceptions: BoolFOption<"async-exceptions",
   PosFlag, 
NegFlag>;
 defm cxx_modules : BoolFOption<"cxx-modules",
   LangOpts<"CPlusPlusModules">, Default,
-  NegFlag, PosFlag,
+  NegFlag, PosFlag,
   BothFlags<[NoXarchOption], " modules for C++">>,
   ShouldParseIf;
 def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, 
Group;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 936682e49299e..5106c0e327b87 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3627,6 +3627,12 @@ static void RenderModulesOptions(Compilation , const 
Driver ,
 HaveModules = true;
   }
 
+  if (Args.hasFlag(options::OPT_fcxx_modules, options::OPT_fno_cxx_modules,
+   false)) {
+CmdArgs.push_back("-fcxx-modules");
+HaveModules = true;
+  }
+
   // -fmodule-maps enables implicit reading of module map files. By default,
   // this is enabled if we are using Clang's flavor of precompiled modules.
   if (Args.hasFlag(options::OPT_fimplicit_module_maps,

diff  --git a/clang/test/Driver/modules.cpp b/clang/test/Driver/modules.cpp
index 87b6cc640cb0d..bac9f715f13a4 100644
--- a/clang/test/Driver/modules.cpp
+++ b/clang/test/Driver/modules.cpp
@@ -73,3 +73,14 @@ import "foo.h";
 // CHECK-HEADER-UNIT-USE: BAR;
 FOO;
 #endif
+
+// Check the independent use of -fcxx-modules
+//
+// RUN: %clang++ -fcxx-modules -std=c++17 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX17-MODULES
+// CHECK-CXX17-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++14 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX14-MODULES
+// CHECK-CXX14-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++11 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX11-MODULES
+// CHECK-CXX11-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++03 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX03-MODULES
+// CHECK-CXX03-MODULES: "-fcxx-modules"

diff  --git a/clang/test/Modules/cxx-modules.cppm 
b/clang/test/Modules/cxx-modules.cppm
new file mode 100644
index 0..be17f85f8d17d
--- /dev/null
+++ b/clang/test/Modules/cxx-modules.cppm
@@ -0,0 +1,7 @@
+// This tests that we could use C++20 modules standalone.
+// RUN: %clang -std=c++03 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++11 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++14 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++17 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// expected-no-diagnostics
+export module M;



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


[PATCH] D116593: Fix `performance-unnecessary-value-param` for template specialization

2022-05-29 Thread gehry via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc98b3a8cd985: Fix `performance-unnecessary-value-param` for 
template specialization (authored by Sockke).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116593

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -- -fno-delayed-template-parsing
 
 // CHECK-FIXES: #include 
 
@@ -109,7 +109,7 @@
 
 template  void templateWithNonTemplatizedParameter(const ExpensiveToCopyType S, T V) {
   // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
-  // CHECK-FIXES: template  void templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
+  // CHECK-FIXES-NOT: template  void templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
 }
 
 void instantiated() {
@@ -381,3 +381,24 @@
   // CHECK-FIXES: void templateFunction(ExpensiveToCopyType E) {
   E.constReference();
 }
+
+template 
+T templateSpecializationFunction(ExpensiveToCopyType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:54: warning: the parameter 'E' is copied
+  // CHECK-FIXES-NOT: T templateSpecializationFunction(const ExpensiveToCopyType& E) {
+  return T();
+}
+
+template <>
+bool templateSpecializationFunction(ExpensiveToCopyType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:57: warning: the parameter 'E' is copied
+  // CHECK-FIXES-NOT: bool templateSpecializationFunction(const ExpensiveToCopyType& E) {
+  return true;
+}
+
+template <>
+int templateSpecializationFunction(ExpensiveToCopyType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:56: warning: the parameter 'E' is copied
+  // CHECK-FIXES-NOT: int templateSpecializationFunction(const ExpensiveToCopyType& E) {
+  return 0;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
@@ -69,7 +69,7 @@
 
 template  void templateWithNonTemplatizedParameter(const ExpensiveToCopyType S, T V) {
   // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
-  // CHECK-FIXES: template  void templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
+  // CHECK-FIXES-NOT: template  void templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
 }
 
 void instantiated() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -202,6 +202,10 @@
   ` to simplify expressions
   using DeMorgan's Theorem.
 
+- Fixed a crash in :doc:`performance-unnecessary-value-param
+  ` when the specialization
+  template has an unnecessary value paramter. Removed the fix for a template.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -51,18 +51,6 @@
   return Matches.empty();
 }
 
-bool isExplicitTemplateSpecialization(const FunctionDecl ) {
-  if (const auto *SpecializationInfo = Function.getTemplateSpecializationInfo())
-if (SpecializationInfo->getTemplateSpecializationKind() ==
-TSK_ExplicitSpecialization)
-  return true;
-  if (const auto *Method = llvm::dyn_cast())
-if (Method->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization &&
-Method->getMemberSpecializationInfo()->isExplicitSpecialization())
-  return true;
-  return false;
-}
-
 } // namespace
 
 UnnecessaryValueParamCheck::UnnecessaryValueParamCheck(
@@ -147,11 +135,12 @@
   // 2. the function is virtual as it might break overrides
   // 3. the function is referenced outside of a call expression within the
   //compilation unit as the signature change could introduce build errors.
-  // 4. the function is 

[clang-tools-extra] c98b3a8 - Fix `performance-unnecessary-value-param` for template specialization

2022-05-29 Thread via cfe-commits

Author: Sockke
Date: 2022-05-30T09:55:53+08:00
New Revision: c98b3a8cd9856f2fcc7ba1f9ed9896b291bbab7b

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

LOG: Fix `performance-unnecessary-value-param` for template specialization

The checker missed a check for parameter type of primary template of 
specialization template and this could cause build breakages.

Reviewed By: aaron.ballman, flx

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp

clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
index ba2b89c291214..00f4b00f53819 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -51,18 +51,6 @@ bool hasLoopStmtAncestor(const DeclRefExpr , const 
Decl ,
   return Matches.empty();
 }
 
-bool isExplicitTemplateSpecialization(const FunctionDecl ) {
-  if (const auto *SpecializationInfo = 
Function.getTemplateSpecializationInfo())
-if (SpecializationInfo->getTemplateSpecializationKind() ==
-TSK_ExplicitSpecialization)
-  return true;
-  if (const auto *Method = llvm::dyn_cast())
-if (Method->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization &&
-Method->getMemberSpecializationInfo()->isExplicitSpecialization())
-  return true;
-  return false;
-}
-
 } // namespace
 
 UnnecessaryValueParamCheck::UnnecessaryValueParamCheck(
@@ -147,11 +135,12 @@ void UnnecessaryValueParamCheck::check(const 
MatchFinder::MatchResult ) {
   // 2. the function is virtual as it might break overrides
   // 3. the function is referenced outside of a call expression within the
   //compilation unit as the signature change could introduce build errors.
-  // 4. the function is an explicit template specialization.
+  // 4. the function is a primary template or an explicit template
+  // specialization.
   const auto *Method = llvm::dyn_cast(Function);
   if (Param->getBeginLoc().isMacroID() || (Method && Method->isVirtual()) ||
   isReferencedOutsideOfCallExpr(*Function, *Result.Context) ||
-  isExplicitTemplateSpecialization(*Function))
+  (Function->getTemplatedKind() != FunctionDecl::TK_NonTemplate))
 return;
   for (const auto *FunctionDecl = Function; FunctionDecl != nullptr;
FunctionDecl = FunctionDecl->getPreviousDecl()) {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 787f535dedb64..5196c53291d19 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -202,6 +202,10 @@ Changes in existing checks
   ` to simplify 
expressions
   using DeMorgan's Theorem.
 
+- Fixed a crash in :doc:`performance-unnecessary-value-param
+  ` when the 
specialization
+  template has an unnecessary value paramter. Removed the fix for a template.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
index 623bf8b30829e..53ec8713be338 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
@@ -69,7 +69,7 @@ struct PositiveConstValueConstructor {
 
 template  void templateWithNonTemplatizedParameter(const 
ExpensiveToCopyType S, T V) {
   // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
-  // CHECK-FIXES: template  void 
templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
+  // CHECK-FIXES-NOT: template  void 
templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
 }
 
 void instantiated() {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
index f801494cf0ff5..d578eedd94a39 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t
+// RUN: %check_clang_tidy %s 

[PATCH] D126619: [OpenMP][Clang] Fix atomic compare for signed vs. unsigned

2022-05-29 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126619

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


[PATCH] D126619: [OpenMP][Clang] Fix atomic compare for signed vs. unsigned

2022-05-29 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: tianshilei1992, ABataev, jdoerfert.
jdenny added projects: OpenMP, clang.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
jdenny requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.

Without this patch, arguments to the
`llvm::OpenMPIRBuilder::AtomicOpValue` initializer are reversed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126619

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/atomic_compare_codegen.cpp
  openmp/libomptarget/test/offloading/atomic-compare-signedness.c
  openmp/runtime/test/atomic/omp-atomic-compare-signedness.c

Index: openmp/runtime/test/atomic/omp-atomic-compare-signedness.c
===
--- /dev/null
+++ openmp/runtime/test/atomic/omp-atomic-compare-signedness.c
@@ -0,0 +1,40 @@
+// Check that omp atomic compare handles signedness of integer comparisons
+// correctly.
+//
+// At one time, a bug sometimes reversed the signedness.
+
+// RUN: %libomp-compile -fopenmp-version=51
+// RUN: %libomp-run | FileCheck %s
+
+// High parallelism increases our chances of detecting a lack of atomicity.
+#define NUM_THREADS_TRY 256
+
+#include 
+#include 
+#include 
+
+int main() {
+  //  CHECK: signed: num_threads=[[#NUM_THREADS:]]{{$}}
+  // CHECK-NEXT: signed: xs=[[#NUM_THREADS-1]]{{$}}
+  int xs = -1;
+  int numThreads;
+  #pragma omp parallel for num_threads(NUM_THREADS_TRY)
+  for (int i = 0; i < omp_get_num_threads(); ++i) {
+#pragma omp atomic compare
+if (xs < i) { xs = i; }
+if (i == 0)
+  numThreads = omp_get_num_threads();
+  }
+  printf("signed: num_threads=%d\n", numThreads);
+  printf("signed: xs=%d\n", xs);
+
+  // CHECK-NEXT: unsigned: xu=0x0{{$}}
+  unsigned xu = UINT_MAX;
+  #pragma omp parallel for num_threads(NUM_THREADS_TRY)
+  for (int i = 0; i < omp_get_num_threads(); ++i) {
+#pragma omp atomic compare
+if (xu > i) { xu = i; }
+  }
+  printf("unsigned: xu=0x%x\n", xu);
+  return 0;
+}
Index: openmp/libomptarget/test/offloading/atomic-compare-signedness.c
===
--- /dev/null
+++ openmp/libomptarget/test/offloading/atomic-compare-signedness.c
@@ -0,0 +1,42 @@
+// Check that omp atomic compare handles signedness of integer comparisons
+// correctly.
+//
+// At one time, a bug sometimes reversed the signedness.
+
+// RUN: %libomptarget-compile-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic | %fcheck-generic
+
+// High parallelism increases our chances of detecting a lack of atomicity.
+#define NUM_THREADS_TRY 256
+
+#include 
+#include 
+#include 
+
+int main() {
+  //  CHECK: signed: num_threads=[[#NUM_THREADS:]]{{$}}
+  // CHECK-NEXT: signed: xs=[[#NUM_THREADS-1]]{{$}}
+  int xs = -1;
+  int numThreads;
+  #pragma omp target parallel for num_threads(NUM_THREADS_TRY) \
+  map(tofrom:xs, numThreads)
+  for (int i = 0; i < omp_get_num_threads(); ++i) {
+#pragma omp atomic compare
+if (xs < i) { xs = i; }
+if (i == 0)
+  numThreads = omp_get_num_threads();
+  }
+  printf("signed: num_threads=%d\n", numThreads);
+  printf("signed: xs=%d\n", xs);
+
+  // CHECK-NEXT: unsigned: xu=0x0{{$}}
+  unsigned xu = UINT_MAX;
+  #pragma omp target parallel for num_threads(NUM_THREADS_TRY) \
+  map(tofrom:xu)
+  for (int i = 0; i < omp_get_num_threads(); ++i) {
+#pragma omp atomic compare
+if (xu > i) { xu = i; }
+  }
+  printf("unsigned: xu=0x%x\n", xu);
+  return 0;
+}
Index: clang/test/OpenMP/atomic_compare_codegen.cpp
===
--- clang/test/OpenMP/atomic_compare_codegen.cpp
+++ clang/test/OpenMP/atomic_compare_codegen.cpp
@@ -1979,21 +1979,21 @@
 // CHECK-NEXT:[[ULLE:%.*]] = alloca i64, align 8
 // CHECK-NEXT:[[ULLD:%.*]] = alloca i64, align 8
 // CHECK-NEXT:[[TMP0:%.*]] = load i8, i8* [[CE]], align 1
-// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP0]] monotonic, align 1
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw min i8* [[CX]], i8 [[TMP0]] monotonic, align 1
 // CHECK-NEXT:[[TMP2:%.*]] = load i8, i8* [[CE]], align 1
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw umax i8* [[CX]], i8 [[TMP2]] monotonic, align 1
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw max i8* [[CX]], i8 [[TMP2]] monotonic, align 1
 // CHECK-NEXT:[[TMP4:%.*]] = load i8, i8* [[CE]], align 1
-// CHECK-NEXT:[[TMP5:%.*]] = atomicrmw umax i8* [[CX]], i8 [[TMP4]] monotonic, align 1
+// CHECK-NEXT:[[TMP5:%.*]] = atomicrmw max i8* [[CX]], i8 [[TMP4]] monotonic, align 1
 // CHECK-NEXT:[[TMP6:%.*]] = load i8, i8* [[CE]], align 1
-// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP6]] monotonic, align 1
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw min i8* [[CX]], i8 [[TMP6]] monotonic, align 1
 // CHECK-NEXT:[[TMP8:%.*]] = load i8, i8* [[CE]], align 1
-// 

[PATCH] D125946: Handles failing driver tests of clang

2022-05-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/Interpreter/clangtests.cpp:1
+// RUN: clang-repl %S/../Lexer/badstring_in_if0.c -Xcc -E -Xcc -verify
+// RUN: clang-repl %S/../Lexer/unknown-char.c -Xcc -E -Xcc -verify

v.g.vassilev wrote:
> dblaikie wrote:
> > dblaikie wrote:
> > > v.g.vassilev wrote:
> > > > @rsmith, would it be acceptable to have a test that refers other tests 
> > > > from the repo in that manner?
> > > Generally that's not done - and the inputs should be moved into an 
> > > "Inputs" subdirectory and shared from there. Tests that are in different 
> > > subdirectories - not sure if there's a good way to share those, maybe 
> > > with an "Inputs" directory in a parent directory of both tests? We might 
> > > not have precednt for that
> > But more broadly, could you explain what the goal of these tests are? 
> > Generally I would discourage what I think of as "shotgun" testing - taking 
> > some existing comprehensive test for a particular feature and using it to 
> > test a mostly orthogonal feature. The orthogonal feature should have more 
> > targeted tests/it shouldn't be using such broad testing in the regression 
> > suite here.
> My take is that `clang-repl` is basically clang that takes inputs 
> incrementally. Being that, means that we should be in a position to process 
> whatever clang processes and thus we run against all of the existing tests. 
> We planned to add the ones which we did not support as regression tests.
> 
> We can add more targeted tests but they would be copies or simplifications of 
> already existing ones. Hence there is my hesitation - reuse or duplication...
> 
> My take is that clang-repl is basically clang that takes inputs 
> incrementally. Being that, means that we should be in a position to process 
> whatever clang processes and thus we run against all of the existing tests.

Yeah, that's sort of the "proof by absurdity" - we wouldn't want every clang 
test running in both ahead of time and incremental mode in the usual 
"check-clang" regression suite (I wouldn't mind having a separate mode for 
testing - more of an integration test that some buildbots or those working on 
more comprehensive clang-repl support could run, but most people/especially 
fast bots would not). So then the question for me is which tests should we have 
running all the time in "check-clang" - and my general answer is: Situations 
that have motivated code changes/support in clang-repl: If no code was 
added/changed/etc to clang-repl, then no test should be added to "check-clang" 
for that test case.

If that "run everything under check-clang run under clang-repl to find missing 
functionality" found some clang test that didn't work with clang-repl, yeah, 
I'd generally be in favour of not reusing an input or duplicating in its 
entirety - but reducing the test case to test only the specific clang-repl 
functionality issue, and testing that in particular.

Like we shouldn't test every feature of static-assert with clang-repl and clang 
in every "clang-check" if most of those features aren't distinctly interesting 
in both cases. Just enough in clang-repl to test what makes static-assert 
interesting in clang-repl.


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

https://reviews.llvm.org/D125946

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


[PATCH] D102122: Support warn_unused_result on typedefs

2022-05-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie marked an inline comment as done.
dblaikie added a comment.

In D102122#3539812 , @aaron.ballman 
wrote:

> In D102122#3538668 , @dblaikie 
> wrote:
>
>> Sorry, with all the layers in the previous messages I'm not sure what the 
>> summary is. Sounds like the summary is "this is OK to continue work in the 
>> direction of supporting [[clang::warn_unused_result]] (only that spelling) 
>> for typedefs in C and C++ (for compatibility with C/so that C headers, like 
>> LLVM C's APIs can still be parsed as C++), while considering some of the 
>> complications raised in the WG21 discussion"?
>
> Yup! Though I agree with Richard's later comment that we could maybe also 
> extend the `__attribute__((warn_unused_result))` spelling as well.
>
>> OK, so I updated this patch with a very first draft/attempt at that - I 
>> wasn't sure how to add typedef support to only the clang spelling - so I 
>> created a new attribute name in the .td file (is there a better/more 
>> suitable way?)
>
> I would not go that route. Instead, I'd add it as a subject to the existing 
> attribute, and then add a spelling-based restriction in 
> `handleWarnUnusedResult()` to give an appropriate diagnostic if the subject 
> is wrong based on the spelling used. Something like:
>
>   if ((!AL.isGNUAttributeSyntax() || !(AL.isStandardAttributeSyntax() && 
> AL.isClangScope())) && isa(D))
> Diag(...);
>
> (Note, you may need to extend ParsedAttr somewhat, I don't recall if we have 
> all those helper functions explicitly.)

Ah, OK. Added those (& I think the first `||` was meant to be a `&&` there, 
then it seems to do what's expected)

How's this look now, then?

One drawback is the built-in attribute warnings that mention which entities the 
attribute is valid on will mention typedefs even when the user uses a spelling 
that wouldn't be valid there - so the user might try it there, then get the 
follow-on warning (totally open to wordsmithing that warning, too - just 
placeholder words - also made it part of the same group as the 
warn_unused_result warning itself - if you disable that warning, then 
presumably you don't care about the warning being in the wrong place either, to 
some extent).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102122

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


[PATCH] D102122: Support warn_unused_result on typedefs

2022-05-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 432804.
dblaikie added a comment.

Use a single attribute, with a filter in the sema parsing code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102122

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Expr.cpp
  clang/lib/Basic/Attributes.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/c2x-nodiscard.c
  clang/test/Sema/unused-expr.c
  clang/test/SemaCXX/warn-unused-result.cpp

Index: clang/test/SemaCXX/warn-unused-result.cpp
===
--- clang/test/SemaCXX/warn-unused-result.cpp
+++ clang/test/SemaCXX/warn-unused-result.cpp
@@ -254,3 +254,29 @@
 
 void i([[nodiscard]] bool (*fp)()); // expected-warning {{'nodiscard' attribute only applies to functions, classes, or enumerations}}
 }
+
+namespace unused_typedef_result {
+[[clang::warn_unused_result]] typedef void *a;
+a af1();
+void af2() {
+  af1(); // expected-warning {{ignoring return value}}
+  void *(*a1)();
+  a1(); // no warning
+  a (*a2)();
+  a2(); // expected-warning {{ignoring return value}}
+}
+[[nodiscard]] typedef void *b; // expected-warning {{warn_unused_result on typedefs only supported with gnu or clang scoped standard spelling}}
+b bf1();
+void bf2() {
+  bf1(); // no warning
+}
+__attribute__((warn_unused_result)) typedef void *c;
+c cf1();
+void cf2() {
+  cf1(); // expected-warning {{ignoring return value}}
+  void *(*c1)();
+  c1();
+  c (*c2)();
+  c2(); // expected-warning {{ignoring return value}}
+}
+}
Index: clang/test/Sema/unused-expr.c
===
--- clang/test/Sema/unused-expr.c
+++ clang/test/Sema/unused-expr.c
@@ -96,7 +96,7 @@
   return 0;
 }
 
-int t7 __attribute__ ((warn_unused_result)); // expected-warning {{'warn_unused_result' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, and function pointers}}
+int t7 __attribute__ ((warn_unused_result)); // expected-warning {{'warn_unused_result' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, function pointers, and typedefs}}
 
 // PR4010
 int (*fn4)(void) __attribute__ ((warn_unused_result));
Index: clang/test/Sema/c2x-nodiscard.c
===
--- clang/test/Sema/c2x-nodiscard.c
+++ clang/test/Sema/c2x-nodiscard.c
@@ -15,7 +15,7 @@
 [[nodiscard]] int f1(void);
 enum [[nodiscard]] E1 { One };
 
-[[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, and function pointers}}
+[[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, function pointers, and typedefs}}
 
 struct [[nodiscard]] S4 {
   int i;
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -185,7 +185,7 @@
 // CHECK-NEXT: VecReturn (SubjectMatchRule_record)
 // CHECK-NEXT: VecTypeHint (SubjectMatchRule_function)
 // CHECK-NEXT: WarnUnused (SubjectMatchRule_record)
-// CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType, SubjectMatchRule_type_alias)
 // CHECK-NEXT: Weak (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: WeakRef (SubjectMatchRule_variable, SubjectMatchRule_function)
 // CHECK-NEXT: WebAssemblyExportName (SubjectMatchRule_function)
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
@@ -7,4 +7,4 @@
 [[nodiscard]] int f();
 enum [[nodiscard]] E {};
 
-namespace [[nodiscard]] N {} // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, and function pointers}}
+namespace [[nodiscard]] N {} // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, function pointers, and typedefs}}
Index: clang/lib/Sema/SemaDeclAttr.cpp

[PATCH] D125946: Handles failing driver tests of clang

2022-05-29 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/test/Interpreter/clangtests.cpp:1
+// RUN: clang-repl %S/../Lexer/badstring_in_if0.c -Xcc -E -Xcc -verify
+// RUN: clang-repl %S/../Lexer/unknown-char.c -Xcc -E -Xcc -verify

dblaikie wrote:
> dblaikie wrote:
> > v.g.vassilev wrote:
> > > @rsmith, would it be acceptable to have a test that refers other tests 
> > > from the repo in that manner?
> > Generally that's not done - and the inputs should be moved into an "Inputs" 
> > subdirectory and shared from there. Tests that are in different 
> > subdirectories - not sure if there's a good way to share those, maybe with 
> > an "Inputs" directory in a parent directory of both tests? We might not 
> > have precednt for that
> But more broadly, could you explain what the goal of these tests are? 
> Generally I would discourage what I think of as "shotgun" testing - taking 
> some existing comprehensive test for a particular feature and using it to 
> test a mostly orthogonal feature. The orthogonal feature should have more 
> targeted tests/it shouldn't be using such broad testing in the regression 
> suite here.
My take is that `clang-repl` is basically clang that takes inputs 
incrementally. Being that, means that we should be in a position to process 
whatever clang processes and thus we run against all of the existing tests. We 
planned to add the ones which we did not support as regression tests.

We can add more targeted tests but they would be copies or simplifications of 
already existing ones. Hence there is my hesitation - reuse or duplication...



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

https://reviews.llvm.org/D125946

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


[PATCH] D125946: Handles failing driver tests of clang

2022-05-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/Interpreter/clangtests.cpp:1
+// RUN: clang-repl %S/../Lexer/badstring_in_if0.c -Xcc -E -Xcc -verify
+// RUN: clang-repl %S/../Lexer/unknown-char.c -Xcc -E -Xcc -verify

dblaikie wrote:
> v.g.vassilev wrote:
> > @rsmith, would it be acceptable to have a test that refers other tests from 
> > the repo in that manner?
> Generally that's not done - and the inputs should be moved into an "Inputs" 
> subdirectory and shared from there. Tests that are in different 
> subdirectories - not sure if there's a good way to share those, maybe with an 
> "Inputs" directory in a parent directory of both tests? We might not have 
> precednt for that
But more broadly, could you explain what the goal of these tests are? Generally 
I would discourage what I think of as "shotgun" testing - taking some existing 
comprehensive test for a particular feature and using it to test a mostly 
orthogonal feature. The orthogonal feature should have more targeted tests/it 
shouldn't be using such broad testing in the regression suite here.


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

https://reviews.llvm.org/D125946

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


[PATCH] D125946: Handles failing driver tests of clang

2022-05-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/Interpreter/clangtests.cpp:1
+// RUN: clang-repl %S/../Lexer/badstring_in_if0.c -Xcc -E -Xcc -verify
+// RUN: clang-repl %S/../Lexer/unknown-char.c -Xcc -E -Xcc -verify

v.g.vassilev wrote:
> @rsmith, would it be acceptable to have a test that refers other tests from 
> the repo in that manner?
Generally that's not done - and the inputs should be moved into an "Inputs" 
subdirectory and shared from there. Tests that are in different subdirectories 
- not sure if there's a good way to share those, maybe with an "Inputs" 
directory in a parent directory of both tests? We might not have precednt for 
that


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

https://reviews.llvm.org/D125946

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


[clang] 0bd645d - [libclang] Fix error message capitalization

2022-05-29 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2022-05-29T13:42:22+02:00
New Revision: 0bd645d3707dce452663d4634495155321a6fd1c

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

LOG: [libclang] Fix error message capitalization

This was a review suggestion from MaskRay that I forgot to incorporate
in the patch.

See: https://reviews.llvm.org/D124815

Added: 


Modified: 
clang/tools/libclang/CIndexer.cpp

Removed: 




diff  --git a/clang/tools/libclang/CIndexer.cpp 
b/clang/tools/libclang/CIndexer.cpp
index 41f06a83553a..dab3fc4e201d 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -139,7 +139,7 @@ const std::string ::getClangResourcesPath() {
   } else {
 // It's rather unlikely we end up here. But it could happen, so report an
 // error instead of crashing.
-llvm::report_fatal_error("Could not locate Clang resource path");
+llvm::report_fatal_error("could not locate Clang resource path");
   }
 
 #endif



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


[PATCH] D124815: [libclang] Fall back to getMainExecutable when dladdr fails

2022-05-29 Thread Ayke 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 rG75d12e49c729: [libclang] Fall back to getMainExecutable when 
dladdr fails (authored by aykevl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124815

Files:
  clang/tools/libclang/CIndexer.cpp


Index: clang/tools/libclang/CIndexer.cpp
===
--- clang/tools/libclang/CIndexer.cpp
+++ clang/tools/libclang/CIndexer.cpp
@@ -125,13 +125,23 @@
 #elif defined(_AIX)
   getClangResourcesPathImplAIX(LibClangPath);
 #else
-  // This silly cast below avoids a C++ warning.
   Dl_info info;
-  if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, ) == 0)
-llvm_unreachable("Call to dladdr() failed");
+  std::string Path;
+  // This silly cast below avoids a C++ warning.
+  if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, ) != 0) {
+// We now have the CIndex directory, locate clang relative to it.
+LibClangPath += info.dli_fname;
+  } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, 
nullptr)).empty()) {
+// If we can't get the path using dladdr, try to get the main executable
+// path. This may be needed when we're statically linking libclang with
+// musl libc, for example.
+LibClangPath += Path;
+  } else {
+// It's rather unlikely we end up here. But it could happen, so report an
+// error instead of crashing.
+llvm::report_fatal_error("Could not locate Clang resource path");
+  }
 
-  // We now have the CIndex directory, locate clang relative to it.
-  LibClangPath += info.dli_fname;
 #endif
 
   // Cache our result.


Index: clang/tools/libclang/CIndexer.cpp
===
--- clang/tools/libclang/CIndexer.cpp
+++ clang/tools/libclang/CIndexer.cpp
@@ -125,13 +125,23 @@
 #elif defined(_AIX)
   getClangResourcesPathImplAIX(LibClangPath);
 #else
-  // This silly cast below avoids a C++ warning.
   Dl_info info;
-  if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, ) == 0)
-llvm_unreachable("Call to dladdr() failed");
+  std::string Path;
+  // This silly cast below avoids a C++ warning.
+  if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, ) != 0) {
+// We now have the CIndex directory, locate clang relative to it.
+LibClangPath += info.dli_fname;
+  } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) {
+// If we can't get the path using dladdr, try to get the main executable
+// path. This may be needed when we're statically linking libclang with
+// musl libc, for example.
+LibClangPath += Path;
+  } else {
+// It's rather unlikely we end up here. But it could happen, so report an
+// error instead of crashing.
+llvm::report_fatal_error("Could not locate Clang resource path");
+  }
 
-  // We now have the CIndex directory, locate clang relative to it.
-  LibClangPath += info.dli_fname;
 #endif
 
   // Cache our result.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 75d12e4 - [libclang] Fall back to getMainExecutable when dladdr fails

2022-05-29 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2022-05-29T13:40:43+02:00
New Revision: 75d12e49c729e65f77bfdfe65b16df8c39944d35

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

LOG: [libclang] Fall back to getMainExecutable when dladdr fails

musl-libc doesn't support dladdr in statically linked binaries:

> Are you using static or dynamic linking? If static, dladdr is just a
> stub that always fails. It could be implemented to work under some
> conditions, but it would be highly dependent on what options you
> compile the binary with, since by default static binaries do not
> contain the bloat that would be needed to perform introspection.

Source: https://www.openwall.com/lists/musl/2013/01/15/25 (in response
to a bug report).

Libclang unfortunately uses dladdr to find the ResourcesPath so will
fail if it is linked statically on Alpine Linux. This patch fixes this
issue by falling back to getMainExecutable if dladdr returns an error.

Reference: 
https://github.com/llvm/llvm-project/issues/40641#issuecomment-981011427

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

Added: 


Modified: 
clang/tools/libclang/CIndexer.cpp

Removed: 




diff  --git a/clang/tools/libclang/CIndexer.cpp 
b/clang/tools/libclang/CIndexer.cpp
index c7baab3a2c470..41f06a83553ad 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -125,13 +125,23 @@ const std::string ::getClangResourcesPath() {
 #elif defined(_AIX)
   getClangResourcesPathImplAIX(LibClangPath);
 #else
-  // This silly cast below avoids a C++ warning.
   Dl_info info;
-  if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, ) == 0)
-llvm_unreachable("Call to dladdr() failed");
+  std::string Path;
+  // This silly cast below avoids a C++ warning.
+  if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, ) != 0) {
+// We now have the CIndex directory, locate clang relative to it.
+LibClangPath += info.dli_fname;
+  } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, 
nullptr)).empty()) {
+// If we can't get the path using dladdr, try to get the main executable
+// path. This may be needed when we're statically linking libclang with
+// musl libc, for example.
+LibClangPath += Path;
+  } else {
+// It's rather unlikely we end up here. But it could happen, so report an
+// error instead of crashing.
+llvm::report_fatal_error("Could not locate Clang resource path");
+  }
 
-  // We now have the CIndex directory, locate clang relative to it.
-  LibClangPath += info.dli_fname;
 #endif
 
   // Cache our result.



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


[PATCH] D54943: [clang-tidy] implement new check 'misc-const-correctness' to add 'const' to unmodified variables

2022-05-29 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 432774.
JonasToth added a comment.

- addded `CHECK-FIXES` in clang-tidy tests
- merged latest main into branch


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

https://reviews.llvm.org/D54943

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-const-correctness.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-const-correctness-cxx17.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-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-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc-const-correctness-unaligned.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-const-correctness-values.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -1251,13 +1251,13 @@
   AST =
   buildASTFromCode("void f() { int* x[2]; for (int* e : x) e = nullptr; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_TRUE(isMutated(Results, AST.get()));
 
   AST = buildASTFromCode(
   "typedef int* IntPtr;"
   "void f() { int* x[2]; for (IntPtr e : x) e = nullptr; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, RangeForArrayByConstRef) {
Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -455,14 +455,16 @@
   // array is considered modified if the loop-variable is a non-const reference.
   const auto DeclStmtToNonRefToArray = declStmt(hasSingleDecl(varDecl(hasType(
   hasUnqualifiedDesugaredType(referenceType(pointee(arrayType(;
-  const auto RefToArrayRefToElements = match(
-  findAll(stmt(cxxForRangeStmt(
-   hasLoopVariable(varDecl(hasType(nonConstReferenceType()))
-   .bind(NodeID::value)),
-   hasRangeStmt(DeclStmtToNonRefToArray),
-   hasRangeInit(canResolveToExpr(equalsNode(Exp)
-  .bind("stmt")),
-  Stm, Context);
+  const auto RefToArrayRefToElements =
+  match(findAll(stmt(cxxForRangeStmt(
+ hasLoopVariable(
+ varDecl(anyOf(hasType(nonConstReferenceType()),
+   hasType(nonConstPointerType(
+ .bind(NodeID::value)),
+ hasRangeStmt(DeclStmtToNonRefToArray),
+ hasRangeInit(canResolveToExpr(equalsNode(Exp)
+.bind("stmt")),
+Stm, Context);
 
   if (const auto *BadRangeInitFromArray =
   selectFirst("stmt", RefToArrayRefToElements))
Index: clang-tools-extra/test/clang-tidy/checkers/misc-const-correctness-values.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-const-correctness-values.cpp
@@ -0,0 +1,1030 @@
+// RUN: %check_clang_tidy %s misc-const-correctness %t -- \
+// RUN:   -config="{CheckOptions: [\
+// RUN:   {key: 'misc-const-correctness.TransformValues', value: true}, \
+// RUN:   {key: 'misc-const-correctness.WarnPointersAsValues', value: false}, \
+// RUN:   {key: 'misc-const-correctness.TransformPointersAsValues', value: false}, \
+// RUN:   ]}" -- -fno-delayed-template-parsing
+
+// --- Provide test samples for primitive builtins -
+// - every 'p_*' variable is a 'potential_const_*' variable
+// - every 'np_*' variable is a 'non_potential_const_*' variable
+
+bool global;
+char np_global = 0; // globals can't be known to be const
+
+// FIXME: 'static' globals are not matched right now. They could be analyzed but aren't right now.
+static int p_static_global = 42;
+
+namespace foo {
+int scoped;
+float np_scoped = 1; // namespace variables are like globals
+}