[PATCH] D125949: [clang-tidy] modernize-avoid-bind: Fix crash when method name is not a simple identifier

2022-06-20 Thread Joachim Priesner via Phabricator via cfe-commits
jspam updated this revision to Diff 438265.
jspam added a comment.

Improve fixes

As suggested by njames93, use call syntax instead of operator().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125949

Files:
  clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
@@ -43,6 +43,7 @@
 struct D {
   D() = default;
   void operator()(int x, int y) const {}
+  operator bool() const { return true; }
 
   void MemberFunction(int x) {}
 
@@ -340,6 +341,7 @@
 
 struct E {
   void MemberFunction(int x) {}
+  int operator()(int x, int y) const { return x + y; }
 
   void testMemberFunctions() {
 D *d;
@@ -360,6 +362,26 @@
 auto DDD = std::bind(&D::MemberFunction, _1, 1);
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
 // CHECK-FIXES: auto DDD = [](auto && PH1) { PH1->MemberFunction(1); };
+
+auto EEE = std::bind(&D::operator(), d, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto EEE = [d] { (*d)(1, 2); }
+
+auto FFF = std::bind(&D::operator(), &dd, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto FFF = [ObjectPtr = &dd] { (*ObjectPtr)(1, 2); }
+
+auto GGG = std::bind(&D::operator(), _1, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto GGG = [](auto && PH1) { (*PH1)(1, 2); };
+
+auto HHH = std::bind(&D::operator bool, d);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto HHH = [d] { return d->operator bool(); }
+
+auto III = std::bind(&E::operator(), this, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto III = [this] { return (*this)(1, 2); }
   }
 };
 
Index: clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
@@ -685,12 +685,18 @@
 const BindArgument &ObjPtr = FunctionCallArgs.front();
 
 Stream << " { ";
-if (!isa(ignoreTemporariesAndPointers(ObjPtr.E))) {
-  Stream << ObjPtr.UsageIdentifier;
-  Stream << "->";
+if (!MethodDecl->getReturnType()->isVoidType()) {
+  Stream << "return ";
+}
+if (MethodDecl->getOverloadedOperator() == OO_Call) {
+  Stream << "(*" << ObjPtr.UsageIdentifier << ')';
+} else {
+  if (!isa(ignoreTemporariesAndPointers(ObjPtr.E))) {
+Stream << ObjPtr.UsageIdentifier;
+Stream << "->";
+  }
+  Stream << MethodDecl->getNameAsString();
 }
-
-Stream << MethodDecl->getName();
   } else {
 Stream << " { return ";
 switch (LP.Callable.CE) {


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
@@ -43,6 +43,7 @@
 struct D {
   D() = default;
   void operator()(int x, int y) const {}
+  operator bool() const { return true; }
 
   void MemberFunction(int x) {}
 
@@ -340,6 +341,7 @@
 
 struct E {
   void MemberFunction(int x) {}
+  int operator()(int x, int y) const { return x + y; }
 
   void testMemberFunctions() {
 D *d;
@@ -360,6 +362,26 @@
 auto DDD = std::bind(&D::MemberFunction, _1, 1);
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
 // CHECK-FIXES: auto DDD = [](auto && PH1) { PH1->MemberFunction(1); };
+
+auto EEE = std::bind(&D::operator(), d, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto EEE = [d] { (*d)(1, 2); }
+
+auto FFF = std::bind(&D::operator(), &dd, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto FFF = [ObjectPtr = &dd] { (*ObjectPtr)(1, 2); }
+
+auto GGG = std::bind(&D::operator(), _1, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto GGG = [](auto && PH1) { (*PH1)(1, 2); };
+
+auto HHH = std::bind(&D::operator bool, d);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto HHH = [d] { return d->operator bool(); }
+
+auto III = std::bind(&E::operator(), this, 1, 2);

[PATCH] D128157: cppcoreguidelines-virtual-class-destructor: Fix crash when "virtual" keyword is expanded from a macro

2022-06-20 Thread Joachim Priesner via Phabricator via cfe-commits
jspam created this revision.
Herald added subscribers: carlosgalvezp, shchenz, kbarton, nemanjai.
Herald added a project: All.
jspam requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Check llvm::Optional before dereferencing it.

Compute VirtualEndLoc differently to avoid an assertion failure
in clang::SourceManager::getFileIDLoaded:

  Assertion `0 && "Invalid SLocOffset or bad function choice"' failed


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128157

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
@@ -272,6 +272,7 @@
 } // namespace Bugzilla_51912
 
 namespace macro_tests {
+#define MY_VIRTUAL virtual
 #define CONCAT(x, y) x##y
 
 // CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar1' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
@@ -317,6 +318,15 @@
 protected:
   XMACRO(CONCAT(vir, tual), ~CONCAT(Foo, Bar5());) // no-crash, no-fixit
 };
+
+// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar6' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual
+class FooBar6 {
+protected:
+  MY_VIRTUAL ~FooBar6(); // FIXME: We should have a fixit for this.
+};
+
 #undef XMACRO
 #undef CONCAT
+#undef MY_VIRTUAL
 } // namespace macro_tests
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -53,15 +53,17 @@
 return None;
 
   SourceLocation VirtualBeginLoc = Destructor.getBeginLoc();
-  SourceLocation VirtualEndLoc = VirtualBeginLoc.getLocWithOffset(
-  Lexer::MeasureTokenLength(VirtualBeginLoc, SM, LangOpts));
+  SourceLocation VirtualBeginSpellingLoc =
+  SM.getSpellingLoc(Destructor.getBeginLoc());
+  SourceLocation VirtualEndLoc = VirtualBeginSpellingLoc.getLocWithOffset(
+  Lexer::MeasureTokenLength(VirtualBeginSpellingLoc, SM, LangOpts));
 
   /// Range ends with \c StartOfNextToken so that any whitespace after \c
   /// virtual is included.
-  SourceLocation StartOfNextToken =
-  Lexer::findNextToken(VirtualEndLoc, SM, LangOpts)
-  .getValue()
-  .getLocation();
+  Optional NextToken = Lexer::findNextToken(VirtualEndLoc, SM, 
LangOpts);
+  if (!NextToken)
+return None;
+  SourceLocation StartOfNextToken = NextToken->getLocation();
 
   return CharSourceRange::getCharRange(VirtualBeginLoc, StartOfNextToken);
 }


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
@@ -272,6 +272,7 @@
 } // namespace Bugzilla_51912
 
 namespace macro_tests {
+#define MY_VIRTUAL virtual
 #define CONCAT(x, y) x##y
 
 // CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar1' is protected and virtual [cppcoreguidelines-virtual-class-destructor]
@@ -317,6 +318,15 @@
 protected:
   XMACRO(CONCAT(vir, tual), ~CONCAT(Foo, Bar5());) // no-crash, no-fixit
 };
+
+// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar6' is protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual
+class FooBar6 {
+protected:
+  MY_VIRTUAL ~FooBar6(); // FIXME: We should have a fixit for this.
+};
+
 #undef XMACRO
 #undef CONCAT
+#undef MY_VIRTUAL
 } // namespace macro_tests
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -53,15 +53,17 @@
 return None;
 
   SourceLocation VirtualBeginLoc = Destructor.getBeginLoc();
-  SourceLocation VirtualEndLoc = VirtualBeginLoc.getLocWithOffset(
-  Lexer::MeasureTokenLength(VirtualBeginLoc, SM, LangOpts));
+  SourceLocation VirtualBeginSpellingLoc =
+  SM.getSpellingLoc(Destructor.getBeginLoc());
+  SourceLocation Virtu

[PATCH] D125885: [clang-tidy] bugprone-argument-comment: Ignore calls to user-defined literals

2022-06-20 Thread Joachim Priesner via Phabricator via cfe-commits
jspam added a comment.

Would someone be able to commit this for me, as I do not have the necessary 
rights? Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125885

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


[PATCH] D128158: [AMDGPU] Add amdgcn_sched_group_barrier builtin

2022-06-20 Thread Austin Kerbow via Phabricator via cfe-commits
kerbowa created this revision.
kerbowa added reviewers: rampitec, jrbyrnes, vangthao95, arsenm.
Herald added subscribers: kosarev, jsilvanus, foad, hiraditya, t-tye, tpr, 
dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl.
Herald added a project: All.
kerbowa requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, wdng.
Herald added projects: clang, LLVM.

This builtin allows the creation of custom scheduling pipelines on a per-region
basis. Like the sched_barrier builtin this is intended to be used either for
testing, in situations where the default scheduler heuristics cannot be
improved, or in critical kernels where users are trying to get performance that
is close to handwritten assembly. Obviously using these builtins will require
extra work from the kernel writer to maintain the desired behavior.

The builtin can be used to create groups of instructions called "scheduling
groups" where ordering between the groups is enforced by the scheduler.
__builtin_amdgcn_sched_group_barrier takes three parameters. The first parameter
is a mask that determines the types of instructions that you would like to
synchronize around and add to a scheduling group. These instructions will be
selected from the bottom up starting from the sched_group_barrier's location
during instruction scheduling. The second parameter is the number of matching
instructions that will be associated with this sched_group_barrier. The third
parameter is an identifier which is used to describe what other
sched_group_barriers should be synchronized with. Note that multiple
sched_group_barriers must be added in order for them to be useful since they
only synchronize with other sched_group_barriers. Only "scheduling groups" with
a matching third parameter will have any enforced ordering between them.

As an example, the code below tries to create a pipeline of 1 VMEM_READ
instruction followed by 1 VALU instruction followed by 5 MFMA instructions...
// 1 VMEM_READ
__builtin_amdgcn_sched_group_barrier(32, 1, 0)
// 1 VALU
__builtin_amdgcn_sched_group_barrier(2, 1, 0)
// 5 MFMA
__builtin_amdgcn_sched_group_barrier(8, 5, 0)
// 1 VMEM_READ
__builtin_amdgcn_sched_group_barrier(32, 1, 0)
// 3 VALU
__builtin_amdgcn_sched_group_barrier(2, 3, 0)
// 2 VMEM_WRITE
__builtin_amdgcn_sched_group_barrier(64, 2, 0)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128158

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/test/CodeGenOpenCL/builtins-amdgcn.cl
  clang/test/SemaOpenCL/builtins-amdgcn-error.cl
  llvm/include/llvm/IR/IntrinsicsAMDGPU.td
  llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
  llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
  llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
  llvm/lib/Target/AMDGPU/SIInstructions.td
  llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp
  llvm/test/CodeGen/AMDGPU/llvm.amdgcn.sched.group.barrier.ll
  llvm/test/CodeGen/AMDGPU/sched-group-barrier-pre-RA.mir

Index: llvm/test/CodeGen/AMDGPU/sched-group-barrier-pre-RA.mir
===
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/sched-group-barrier-pre-RA.mir
@@ -0,0 +1,173 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -march=amdgcn -mcpu=gfx908 -misched-cluster=false -amdgpu-disable-power-sched=true -run-pass=machine-scheduler -verify-misched -o - %s | FileCheck %s
+
+--- |
+  define amdgpu_kernel void @no_sched_group_barrier(i32 addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) { ret void }
+  define amdgpu_kernel void @sched_group_barrier_1_VMEM_READ_1_VALU_5_MFMA_1_VMEM_READ_3_VALU_2_VMEM_WRITE(i32 addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) { ret void }
+  define amdgpu_kernel void @sched_group_barrier_2_VMEM_1000_ALU_5_MFMA_2_VMEM_WRITE(i32 addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) { ret void }
+
+  !0 = distinct !{!0}
+  !1 = !{!1, !0}
+...
+
+---
+name: no_sched_group_barrier
+tracksRegLiveness: true
+body: |
+  bb.0:
+; CHECK-LABEL: name: no_sched_group_barrier
+; CHECK: [[DEF:%[0-9]+]]:sreg_64 = IMPLICIT_DEF
+; CHECK-NEXT: [[DEF1:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
+; CHECK-NEXT: [[GLOBAL_LOAD_DWORD_SADDR:%[0-9]+]]:vgpr_32 = GLOBAL_LOAD_DWORD_SADDR [[DEF]], [[DEF1]], 0, 0, implicit $exec :: (load (s32) from %ir.in, !alias.scope !0, addrspace 1)
+; CHECK-NEXT: [[GLOBAL_LOAD_DWORD_SADDR1:%[0-9]+]]:vgpr_32 = GLOBAL_LOAD_DWORD_SADDR [[DEF]], [[DEF1]], 512, 0, implicit $exec :: (load (s32) from %ir.in, !alias.scope !0, addrspace 1)
+; CHECK-NEXT: [[DEF2:%[0-9]+]]:areg_128 = IMPLICIT_DEF
+; CHECK-NEXT: [[V_MUL_LO_U32_e64_:%[0-9]+]]:vgpr_32 = nsw V_MUL_LO_U32_e64 [[GLOBAL_LOAD_DWORD_SADDR]], [[GLOBAL_LOAD_DWORD_SADDR]], implicit $exec
+; CHECK-NEXT: [[V_MFMA_F32_4X4X1F32_e64_:%[0-9]+]]:areg_128 = V_MFMA_F32_4X4X1F32_e64 [[DEF1]], [[GLOBAL_LOAD_DWORD_SADDR]], [[DEF2]], 0, 0, 0, implicit $mode, implicit $exec
+; CHECK-NEXT: [[V_MUL_LO_U32_e64_1:%[0-9]+]]

[PATCH] D128158: [AMDGPU] Add amdgcn_sched_group_barrier builtin

2022-06-20 Thread Austin Kerbow via Phabricator via cfe-commits
kerbowa added a comment.

Somewhat WIP needs more tests and cleanup. Posted for dependent work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128158

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


[PATCH] D112916: [clang-tidy] Confusable identifiers detection

2022-06-20 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:32-35
+/**
+ * Build a skeleton out of the Original identifier, following the algorithm
+ * described in http://www.unicode.org/reports/tr39/#def-skeleton
+ */

`/*` -> `//` or `///` (latter is for documentation comments)



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:41-42
+
+  char const *Curr = SName.c_str();
+  char const *End = Curr + SName.size();
+  while (Curr < End) {

(Nit: in LLVM we use //"const west"//)



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:48
+llvm::ConversionResult Result = llvm::convertUTF8Sequence(
+(const llvm::UTF8 **)&Curr, (const llvm::UTF8 *)End, &CodePoint,
+llvm::strictConversion);

These casts are weird when reading the code. The problem with C-style casts is 
that the compiler will try to resolve it to //some// kind of cast, which makes 
them less "explicit" than would be good for type safety. Could you replace 
these with `static_cast`s? Or are these, in fact, `reinterpret_cast`s?



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:64-68
+  llvm::UTF8 Buffer[32];
+  llvm::UTF8 *BufferStart = std::begin(Buffer);
+  llvm::UTF8 *IBuffer = BufferStart;
+  const llvm::UTF32 *ValuesStart = std::begin(Where->values);
+  const llvm::UTF32 *ValuesEnd =

(Nit: consider adding a `using namespace llvm;` **inside** the function and 
then you could reduce the length of these types.)



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:84
+  if (const auto *ND = Result.Nodes.getNodeAs("nameddecl")) {
+if(  IdentifierInfo *   II = ND->getIdentifier()) {
+  StringRef NDName = II->getName();

(Nit: formatting is broken here.)



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:86-88
+  auto &Mapped = Mapper[skeleton(NDName)];
+  auto *NDDecl = ND->getDeclContext();
+  for (auto *OND : Mapped) {

(Nit: we tend to use `auto` if and only if the type of the variable is either 
reasonably impossible to spell out (e.g. an iterator into a container with 
3784723 parameters) or immediately obvious from the initialiser expression 
(e.g. the init is a cast).)



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:93
+if (OND->getName() != NDName) {
+  diag(OND->getLocation(), "%0 is confusable with %1")
+  << OND->getName() << NDName;

Perhaps you could elaborate on "confusable" here a bit for the user?



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:94
+  diag(OND->getLocation(), "%0 is confusable with %1")
+  << OND->getName() << NDName;
+  diag(ND->getLocation(), "other definition found here",

Careful: `getName()` might assert away if the identifier isn't "trivially 
nameable", e.g. `operator==`. Is this prevented somewhere? (Otherwise, could we 
add a negative test case just to ensure no crashes start happening?) Operators 
are also `NamedDecl`s.



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:95
+  << OND->getName() << NDName;
+  diag(ND->getLocation(), "other definition found here",
+   DiagnosticIDs::Note);

Definition or declaration? "Entity"?



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.h:18
+
+class Homoglyph : public ClangTidyCheck {
+public:

This is the "top-level" check that is the addition in this patch, right?

In that case, this class is breaking naming conventions (usually the symbol 
name ends with `Check`) and the "usual" documentation comment from the class is 
also missing.

-

Also, maybe a full rename to `ConfusableIdentifierCheck` would be worth it. If 
you'd like to stick to the current summary of the patch.



Comment at: clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp:41
 "misc-misleading-bidirectional");
+CheckFactories.registerCheck("misc-homoglyph");
 CheckFactories.registerCheck(

The comment about coming up with a better name for the check I think applies 
here too. I would be comfortable with `misc-confusable-identifiers`. The 
problem with `homoglyph` is that it requires a specific understanding of 
English and (natural) language studies that we should not hard-require from our 
users. If I have to look up on Wikipedia what the name of the rule I'm using 
means then something is wrong.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:141
+
+  Detects confusable unicode identifiers.
+

**U**nicode? Isn't it a trademark?



Comment at: clang-tools-extra/docs/clang-tidy/checks/misc-homogly

[PATCH] D112916: [clang-tidy] Confusable identifiers detection

2022-06-20 Thread Whisperity via Phabricator via cfe-commits
whisperity requested changes to this revision.
whisperity added a comment.
This revision now requires changes to proceed.

Because of the stability issues related to `getName()`-like constructs I'm 
putting a temporary ❌ on this (so it doesn't show up as faux accept). However, 
I have to emphasise that I do like the idea of the check!




Comment at: clang-tools-extra/clang-tidy/misc/CMakeLists.txt:50
   omp_gen
+  genconfusable
   )

`gen_confusable_glyph_list`?



Comment at: 
clang-tools-extra/clang-tidy/misc/ConfusableTable/build_confusable_table.cpp:1
+//===--- build_confusable_table.cpp - 
clang-tidy---===//
+//

Why does this file have `snake_case` name?


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

https://reviews.llvm.org/D112916

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


[PATCH] D128098: [clang][driver] Ensure we don't accumulate entries in -MJ files

2022-06-20 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D128098#3594637 , @tschuett wrote:

> There are now several JSON fragments per file? Previously, there was one 
> fragment per file.
>
> This will fail now:
> https://sarcasm.github.io/notes/dev/compilation-database.html#clang

There are on MacOS when building fat binaries (for both x86_64 and AArch64).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128098

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


[PATCH] D126891: [clang-tidy] The check should ignore final classes

2022-06-20 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

(Please ensure a more appropriate commit message that actually mentions the 
check when committing, @steakhal.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126891

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


[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-20 Thread Diana Picus 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 rG26041e17006c: Update link job for flang on windows (authored 
by rovka).

Changed prior to commit:
  https://reviews.llvm.org/D126291?vs=436722&id=438271#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126291

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  flang/test/Driver/linker-flags.f90

Index: flang/test/Driver/linker-flags.f90
===
--- flang/test/Driver/linker-flags.f90
+++ flang/test/Driver/linker-flags.f90
@@ -2,18 +2,18 @@
 ! invocation. These libraries are added on top of other standard runtime
 ! libraries that the Clang driver will include.
 
-! NOTE: The additional linker flags tested here are currently only specified for
-! GNU and Darwin. The following line will make sure that this test is skipped on
-! Windows. If you are running this test on a yet another platform and it is
-! failing for you, please either update the following or (preferably) update the
-! linker invocation accordingly.
-! UNSUPPORTED: system-windows
+!-
+! RUN COMMANDS
+!-
+! RUN: %flang -### -flang-experimental-exec -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -flang-experimental-exec -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -flang-experimental-exec -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MINGW
 
-!
-! RUN COMMAND
-!
-! Use `--ld-path` so that the linker location (used in the LABEL below) is deterministic.
-! RUN: %flang -### -flang-experimental-exec --ld-path=/usr/bin/ld %S/Inputs/hello.f90 2>&1 | FileCheck %s
+! NOTE: Clang's driver library, clangDriver, usually adds 'libcmt' and
+!   'oldnames' on Windows, but they are not needed when compiling
+!   Fortran code and they might bring in additional dependencies.
+!   Make sure they're not added.
+! RUN: %flang -### -flang-experimental-exec -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
 
 !
 ! EXPECTED OUTPUT
@@ -23,9 +23,29 @@
 ! CHECK-SAME:  "-o" "[[object_file:.*\.o]]" {{.*}}Inputs/hello.f90
 
 ! Linker invocation to generate the executable
-! CHECK-LABEL:  "/usr/bin/ld"
-! CHECK-SAME: "[[object_file]]"
-! CHECK-SAME: -lFortran_main
-! CHECK-SAME: -lFortranRuntime
-! CHECK-SAME: -lFortranDecimal
-! CHECK-SAME: -lm
+! GNU-LABEL:  "{{.*}}ld" 
+! GNU-SAME: "[[object_file]]"
+! GNU-SAME: -lFortran_main
+! GNU-SAME: -lFortranRuntime
+! GNU-SAME: -lFortranDecimal
+! GNU-SAME: -lm
+
+! DARWIN-LABEL:  "{{.*}}ld" 
+! DARWIN-SAME: "[[object_file]]"
+! DARWIN-SAME: -lFortran_main
+! DARWIN-SAME: -lFortranRuntime
+! DARWIN-SAME: -lFortranDecimal
+
+! MINGW-LABEL:  "{{.*}}ld" 
+! MINGW-SAME: "[[object_file]]"
+! MINGW-SAME: -lFortran_main
+! MINGW-SAME: -lFortranRuntime
+! MINGW-SAME: -lFortranDecimal
+
+! NOTE: This check should also match if the default linker is lld-link.exe
+! MSVC-LABEL: link.exe
+! MSVC-SAME: Fortran_main.lib
+! MSVC-SAME: FortranRuntime.lib
+! MSVC-SAME: FortranDecimal.lib
+! MSVC-SAME: /subsystem:console
+! MSVC-SAME: "[[object_file]]"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -218,6 +218,11 @@
 
   AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
 
+  if (C.getDriver().IsFlangMode()) {
+addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
+addFortranRuntimeLibs(TC, CmdArgs);
+  }
+
   // TODO: Add profile stuff here
 
   if (TC.ShouldLinkCXXStdlib(Args)) {
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -81,7 +81,7 @@
 Args.MakeArgString(std::string("-out:") + Output.getFilename()));
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
-  !C.getDriver().IsCLMode()) {
+  !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
 CmdArgs.push_back("-defaultlib:libcmt");
 CmdArgs.push_back("-defaultlib:oldnames");
   }
@@ -130,6 +130,16 @@
   Args.MakeArgString(std::string("-libpath:") + WindowsSdkLibPath));
   }
 
+  if (C.getDriver().IsFlangMode()) {
+addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
+addFortranRunt

[clang] 26041e1 - Update link job for flang on windows

2022-06-20 Thread Diana Picus via cfe-commits

Author: Diana Picus
Date: 2022-06-20T07:25:10Z
New Revision: 26041e17006cf30e9c2d06706fe6bd3fa818e356

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

LOG: Update link job for flang on windows

When linking a Fortran program, we need to add the runtime libraries to
the command line. This is exactly what we do for Linux/Darwin, but the
MSVC interface is slightly different (e.g. -libpath instead of -L).

We also remove oldnames and libcmt, since they're not needed at the
moment and they bring in more dependencies.

We also pass `/subsystem:console` to the linker so it can figure out the
right entry point. This is only needed for MSVC's `link.exe`. For LLD it
is redundant but doesn't hurt.

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

Co-authored-by: Markus Mützel 

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/MSVC.cpp
clang/lib/Driver/ToolChains/MinGW.cpp
flang/test/Driver/linker-flags.f90

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index e2437e5787fd7..d297b808b567f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -739,15 +739,28 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, 
const ToolChain &TC,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(llvm::opt::ArgStringList &CmdArgs) {
-  CmdArgs.push_back("-lFortran_main");
-  CmdArgs.push_back("-lFortranRuntime");
-  CmdArgs.push_back("-lFortranDecimal");
+void tools::addFortranRuntimeLibs(const ToolChain &TC,
+  llvm::opt::ArgStringList &CmdArgs) {
+  if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+CmdArgs.push_back("Fortran_main.lib");
+CmdArgs.push_back("FortranRuntime.lib");
+CmdArgs.push_back("FortranDecimal.lib");
+  } else {
+CmdArgs.push_back("-lFortran_main");
+CmdArgs.push_back("-lFortranRuntime");
+CmdArgs.push_back("-lFortranDecimal");
+  }
 }
 
 void tools::addFortranRuntimeLibraryPath(const ToolChain &TC,
  const llvm::opt::ArgList &Args,
  ArgStringList &CmdArgs) {
+  // NOTE: Generating executables by Flang is considered an "experimental"
+  // feature and hence this is guarded with a command line option.
+  // TODO: Make this work unconditionally once Flang is mature enough.
+  if (!Args.hasArg(options::OPT_flang_experimental_exec))
+return;
+
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
   // this in the future. In particular, on some platforms, we may need to use
@@ -755,7 +768,10 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
&TC,
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);
   llvm::sys::path::append(DefaultLibPath, "lib");
-  CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
+  if (TC.getTriple().isKnownWindowsMSVCEnvironment())
+CmdArgs.push_back(Args.MakeArgString("-libpath:" + DefaultLibPath));
+  else
+CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
 }
 
 static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args,

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index 3052cbf1a3c38..8e62af70ff7f7 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -121,7 +121,8 @@ bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, 
const ToolChain &TC,
   bool IsOffloadingHost = false, bool GompNeedsRT = false);
 
 /// Adds Fortran runtime libraries to \p CmdArgs.
-void addFortranRuntimeLibs(llvm::opt::ArgStringList &CmdArgs);
+void addFortranRuntimeLibs(const ToolChain &TC,
+   llvm::opt::ArgStringList &CmdArgs);
 
 /// Adds the path for the Fortran runtime libraries to \p CmdArgs.
 void addFortranRuntimeLibraryPath(const ToolChain &TC,

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 5d98a6497827f..0a8a9c6eb6ff0 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -637,14 +637,9 @@ void darwin::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   // Additional linker set-up and flags for Fortran. This is required in order
   // to generate executables.
-  //
-  // NOTE: Generating executables by Flang is considered an "experimental"
-  // feature and hence this is guarded 

[PATCH] D127873: [clang-format] Fix misplacemnt of `*` in declaration of pointer to struct

2022-06-20 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2328
+}
+
 if (PrevToken->Tok.isLiteral() ||

Thank you I wish more of the clauses were commented like this


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

https://reviews.llvm.org/D127873

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


[PATCH] D127270: [clang-format] Add space in placement new expression

2022-06-20 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/docs/tools/dump_format_style.py:317
   pass
+  elif state == State.InNestedEnum:
+if line.startswith('///'):

Can you show us a screenshot of how these changes will look in HTML?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127270

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


[PATCH] D122150: [clang][analyzer] Add checker for bad use of 'errno'.

2022-06-20 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: clang/include/clang/StaticAnalyzer/Checkers/Checkers.td:553-554
+  CheckerOptions<[
+CmdLineOption Well, now I see why you marked this `Hide` previously.
> This is a //modeling// checker, thus it won't appear in the documentation nor 
> in the `-analyzer-checker-help` etc.
> 
> Interestingly, other checkers mark some options `Hide` and other times 
> `DontHide`.
> E.g. `DynamicMemoryModeling.Optimistic` is //displayed//, but the 
> `DynamicMemoryModeling.AddNoOwnershipChangeNotes` is //hidden//.
> Whatever.
It looks good now, `ErrnoChecker` is not a modeling checker and the option 
should be accessible for users.



Comment at: clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp:47
+  /// Indicates if a read (load) of \c errno is allowed in a non-condition part
+  /// of \c if, \c switch, loop and conditional statements when the errno
+  /// value may be undefined.

steakhal wrote:
> You prefixed the previous two keywords with the `\c` marker. Why is it 
> missing from the `switch`?
Is it really missing? (I do not check Doxygen documentation, probably the new 
documentation appears in the online pages after the commit.)



Comment at: clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp:100
+case Expr::BinaryConditionalOperatorClass:
+  CondFound = (S == cast(ParentS)->getCommon());
+  break;

steakhal wrote:
> Oh, so the test added for this actually uncovered a bug?
Yes: Even if it looks natural that `getCond` can be used the same way as at 
normal `ConditionalOperator` this is not true: It returns something other 
(casted or converted) than the root condition expressions.



Comment at: clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp:145
+
+  if (IsLoad) {
+switch (EState) {

steakhal wrote:
> Might be more readable to early return instead.
There is a `else` part.



Comment at: clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp:205
+  if (CallF->isExternC() && CallF->isGlobal() &&
+  C.getSourceManager().isInSystemHeader(CallF->getLocation()) &&
+  !isErrno(CallF)) {

steakhal wrote:
> Does this refer to the callsite or to the Decl location?
> I think the former, which would be a bug I think.
`CallF` is a `FunctionDecl` that should be the original (first) declaration of 
the function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122150

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


[PATCH] D124690: [clangd] add inlay hints for std::forward-ed parameter packs

2022-06-20 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks -- the patch looks quite good to me now!

I will defer to @sammccall for final approval in case he has any additional 
feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124690

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


[clang] e15fef4 - [analyzer] SATest: Ensure Docker image can be built

2022-06-20 Thread Marco Antognini via cfe-commits

Author: Marco Antognini
Date: 2022-06-20T09:43:21+02:00
New Revision: e15fef41709a226a45d321ebb9cd58260cb97b02

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

LOG: [analyzer] SATest: Ensure Docker image can be built

Solve build issues occurring when running `docker build`.

Fix the version of cmake-data to solve the following issue:

  The following packages have unmet dependencies:
   cmake : Depends: cmake-data (= 3.20.5-0kitware1) but 
3.23.1-0kitware1ubuntu18.04.1 is to be installed

Install libjpeg to solve this issue when installing Python
requirements:

  The headers or library files could not be found for jpeg,
  a required dependency when compiling Pillow from source.

Reviewed By: steakhal

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

Added: 


Modified: 
clang/utils/analyzer/Dockerfile

Removed: 




diff  --git a/clang/utils/analyzer/Dockerfile b/clang/utils/analyzer/Dockerfile
index bb1dd60eeb9b8..b92bac6796501 100644
--- a/clang/utils/analyzer/Dockerfile
+++ b/clang/utils/analyzer/Dockerfile
@@ -18,6 +18,7 @@ RUN apt-get update && apt-get install -y \
 python3=3.6.7-1~18.04 \
 python3-pip=9.0.1-2.3* \
 cmake=3.20.5* \
+cmake-data=3.20.5* \
 ninja-build=1.8.2-1
 
 # box2d dependencies
@@ -52,6 +53,9 @@ RUN apt-get install -y \
 flex=2.6.4-6 \
 bison=2:3.0.4.*
 
+RUN apt-get install -y \
+libjpeg-dev
+
 RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
 
 VOLUME /analyzer



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


[PATCH] D126196: [analyzer] SATest: Ensure Docker image can be built

2022-06-20 Thread Marco Antognini via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe15fef41709a: [analyzer] SATest: Ensure Docker image can be 
built (authored by mantognini).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126196

Files:
  clang/utils/analyzer/Dockerfile


Index: clang/utils/analyzer/Dockerfile
===
--- clang/utils/analyzer/Dockerfile
+++ clang/utils/analyzer/Dockerfile
@@ -18,6 +18,7 @@
 python3=3.6.7-1~18.04 \
 python3-pip=9.0.1-2.3* \
 cmake=3.20.5* \
+cmake-data=3.20.5* \
 ninja-build=1.8.2-1
 
 # box2d dependencies
@@ -52,6 +53,9 @@
 flex=2.6.4-6 \
 bison=2:3.0.4.*
 
+RUN apt-get install -y \
+libjpeg-dev
+
 RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
 
 VOLUME /analyzer


Index: clang/utils/analyzer/Dockerfile
===
--- clang/utils/analyzer/Dockerfile
+++ clang/utils/analyzer/Dockerfile
@@ -18,6 +18,7 @@
 python3=3.6.7-1~18.04 \
 python3-pip=9.0.1-2.3* \
 cmake=3.20.5* \
+cmake-data=3.20.5* \
 ninja-build=1.8.2-1
 
 # box2d dependencies
@@ -52,6 +53,9 @@
 flex=2.6.4-6 \
 bison=2:3.0.4.*
 
+RUN apt-get install -y \
+libjpeg-dev
+
 RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
 
 VOLUME /analyzer
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125400: [clang][Analyzer] Add errno state to standard functions modeling.

2022-06-20 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added a comment.

I did performance measurements in the past and it showed no important 
difference, run time got more with at most some percent at some of the projects.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125400

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


[clang] 0ad4f29 - [analyzer] SATest: Weaken assumption about HTML files

2022-06-20 Thread Marco Antognini via cfe-commits

Author: Marco Antognini
Date: 2022-06-20T09:46:07+02:00
New Revision: 0ad4f29b545d849820f0025736c9559c5c439032

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

LOG: [analyzer] SATest: Weaken assumption about HTML files

Instead of assuming there is an HTML file for each diagnostics, consider
the HTML files only when they exist, individually of each other.

After generating the reference data, running

  python /scripts/SATest.py build --projects simbody

was resulting in this error:

File "/scripts/CmpRuns.py", line 250, in read_single_file
  assert len(d['HTMLDiagnostics_files']) == 1
  KeyError: 'HTMLDiagnostics_files'

Reviewed By: steakhal

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

Added: 


Modified: 
clang/utils/analyzer/CmpRuns.py

Removed: 




diff  --git a/clang/utils/analyzer/CmpRuns.py b/clang/utils/analyzer/CmpRuns.py
index 7afe865d77f2b..61fd044c900fa 100644
--- a/clang/utils/analyzer/CmpRuns.py
+++ b/clang/utils/analyzer/CmpRuns.py
@@ -242,17 +242,20 @@ def read_single_file(self, path: str, delete_empty: bool):
 return
 
 # Extract the HTML reports, if they exists.
-if 'HTMLDiagnostics_files' in data['diagnostics'][0]:
-htmlFiles = []
-for d in data['diagnostics']:
+htmlFiles = []
+for d in data['diagnostics']:
+if 'HTMLDiagnostics_files' in d:
 # FIXME: Why is this named files, when does it have multiple
 # files?
 assert len(d['HTMLDiagnostics_files']) == 1
 htmlFiles.append(d.pop('HTMLDiagnostics_files')[0])
-else:
-htmlFiles = [None] * len(data['diagnostics'])
+else:
+htmlFiles.append(None)
 
 report = AnalysisReport(self, data.pop('files'))
+# Python 3.10 offers zip(..., strict=True). The following assertion
+# mimics it.
+assert len(data['diagnostics']) == len(htmlFiles)
 diagnostics = [AnalysisDiagnostic(d, report, h)
for d, h in zip(data.pop('diagnostics'), htmlFiles)]
 



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


[PATCH] D126197: [analyzer] SATest: Weaken assumption about HTML files

2022-06-20 Thread Marco Antognini via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0ad4f29b545d: [analyzer] SATest: Weaken assumption about 
HTML files (authored by mantognini).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126197

Files:
  clang/utils/analyzer/CmpRuns.py


Index: clang/utils/analyzer/CmpRuns.py
===
--- clang/utils/analyzer/CmpRuns.py
+++ clang/utils/analyzer/CmpRuns.py
@@ -242,17 +242,20 @@
 return
 
 # Extract the HTML reports, if they exists.
-if 'HTMLDiagnostics_files' in data['diagnostics'][0]:
-htmlFiles = []
-for d in data['diagnostics']:
+htmlFiles = []
+for d in data['diagnostics']:
+if 'HTMLDiagnostics_files' in d:
 # FIXME: Why is this named files, when does it have multiple
 # files?
 assert len(d['HTMLDiagnostics_files']) == 1
 htmlFiles.append(d.pop('HTMLDiagnostics_files')[0])
-else:
-htmlFiles = [None] * len(data['diagnostics'])
+else:
+htmlFiles.append(None)
 
 report = AnalysisReport(self, data.pop('files'))
+# Python 3.10 offers zip(..., strict=True). The following assertion
+# mimics it.
+assert len(data['diagnostics']) == len(htmlFiles)
 diagnostics = [AnalysisDiagnostic(d, report, h)
for d, h in zip(data.pop('diagnostics'), htmlFiles)]
 


Index: clang/utils/analyzer/CmpRuns.py
===
--- clang/utils/analyzer/CmpRuns.py
+++ clang/utils/analyzer/CmpRuns.py
@@ -242,17 +242,20 @@
 return
 
 # Extract the HTML reports, if they exists.
-if 'HTMLDiagnostics_files' in data['diagnostics'][0]:
-htmlFiles = []
-for d in data['diagnostics']:
+htmlFiles = []
+for d in data['diagnostics']:
+if 'HTMLDiagnostics_files' in d:
 # FIXME: Why is this named files, when does it have multiple
 # files?
 assert len(d['HTMLDiagnostics_files']) == 1
 htmlFiles.append(d.pop('HTMLDiagnostics_files')[0])
-else:
-htmlFiles = [None] * len(data['diagnostics'])
+else:
+htmlFiles.append(None)
 
 report = AnalysisReport(self, data.pop('files'))
+# Python 3.10 offers zip(..., strict=True). The following assertion
+# mimics it.
+assert len(data['diagnostics']) == len(htmlFiles)
 diagnostics = [AnalysisDiagnostic(d, report, h)
for d, h in zip(data.pop('diagnostics'), htmlFiles)]
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127082: [clangd] Add Macro Expansion to Hover

2022-06-20 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thank you for working on this! I've been using clangd with this patch applied 
for a week or so, and it seems to be working well, I haven't run into any 
issues.

Could you please upload a patch with context, to make it easier to review? 
(Currently, above each hunk it says "Context not available", which makes it 
harder to find what code is being changed.)

> Should we present macro expansion before definition in the hover card?

Yes, I think putting the expansion first would make sense, because it's more 
relevant (since it's specific to the invocation).

> Should we truncate/ignore macro expansion if it's too long? For performance 
> and presentation reason, it might not be a good idea to expand pages worth of 
> tokens in hover card. If so, what's the preferred threshold?

I think a good client will manage longer content by e.g. making the hover 
scrollable, so we probably don't need a very restrictive limit, but I guess 
should have //some// limit. Maybe something like 100 lines?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

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


[PATCH] D127082: [clangd] Add Macro Expansion to Hover

2022-06-20 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D127082#3560642 , @daiyousei-qz 
wrote:

> Basically, anywhere the same code action isn't available. Need this be 
> documented somewhere?

If you'd like, we could mention the ability to show macro expansions here 
, maybe with a screenshot, and then we 
could list the limitations in the same place.

The repository containing this website content is at 
https://github.com/llvm/clangd-www/blob/main/features.md


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

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


[PATCH] D112916: [clang-tidy] Confusable identifiers detection

2022-06-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

So that this doesn't get lost, I'm opposed to this change because it does not 
actually follow the TR39 guidance or algorithm.

  For an input string X, define skeleton(X) to be the following transformation 
on the string:
  
  1. Convert X to NFD format, as described in [UAX15].
  2. Concatenate the prototypes for each character in X according to the 
specified data, producing a string of exemplar characters.
  3. Reapply NFD.

Step 1 and 3 not being performed will lead to false negative.

That being said, given that it is for clang tidy and that adding decomposition 
to llvm is a bit involved (I could look into it if there is interest), this is 
not a strong opposition, but i wanted to make sure people are aware of the 
limitation.
I think we should have a fixme in the code so that we don't forget.




Comment at: 
clang-tools-extra/clang-tidy/misc/ConfusableTable/build_confusable_table.cpp:59
+  llvm::raw_fd_ostream os(argv[2], ec);
+  os << "struct {llvm::UTF32 codepoint; llvm::UTF32 values[32];} "
+"ConfusableEntries[] = {\n";

This is terribly menory inneficient - most confusables are 1-3 code point longs.
Consider
 *  Replacing the hard coded 32 by the actual maximum length that you can 
extract when buikding the table
  * Having a table for the common case of 1-3 codepoints for the common case 
and another one for the long sequence. 


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

https://reviews.llvm.org/D112916

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


[PATCH] D127579: [clang][WIP] add option to keep types of ptr args for non-kernel functions in metadata

2022-06-20 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D127579#3588626 , @Anastasia wrote:

> In D127579#3586092 , @nikic wrote:
>
>> @Anastasia Thanks, that does sound like a legitimate reason to include the 
>> information. I want to double check though, does linking the modules 
>> actually fail if the functions have signatures that differ only by pointer 
>> types? At least for normal LLVM IR this would work fine, and would just 
>> result in the insertion of a bitcast during linking (and then typically the 
>> bitcast would get shifted from the called function to the call arguments 
>> later).
>
> @nikic If I use `spirv-link` with two modules that have mismatching pointee 
> type in a function parameter I get an error:
>
>   error: 0: Type mismatch on symbol "foo" between imported variable/function 
> %6 and exported variable/function %17. 
>
> The way I understand a bitcast instruction in SPIR-V (`OpBitcast` in 
> https://www.khronos.org/registry/SPIR-V/specs/unified1/SPIRV.html#_conversion_instructions)
>  is that it can only apply to pointer types which are distinct from function 
> types. Note that I believe that function pointers are illegal, at least we 
> disallow them in OpenCL.

Okay ... can we maybe turn this around then? Always emit function parameters as 
`i8*` and bitcast them as needed, even if it is possible to guess a better type 
based on the definition? (Let's ignore the image type case here, which seems to 
have different requirements from the rest.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127579

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


[clang] 60f3b07 - [clang][analyzer] Add checker for bad use of 'errno'.

2022-06-20 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2022-06-20T10:07:31+02:00
New Revision: 60f3b071185bf4be32d5c3376856c573975c912a

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

LOG: [clang][analyzer] Add checker for bad use of 'errno'.

Extend checker 'ErrnoModeling' with a state of 'errno' to indicate
the importance of the 'errno' value and how it should be used.
Add a new checker 'ErrnoChecker' that observes use of 'errno' and
finds possible wrong uses, based on the "errno state".
The "errno state" should be set (together with value of 'errno')
by other checkers (that perform modeling of the given function)
in the future. Currently only a test function can set this value.
The new checker has no user-observable effect yet.

Reviewed By: martong, steakhal

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

Added: 
clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
clang/test/Analysis/errno-notes.c
clang/test/Analysis/errno-options.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/errno.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e37b93e573491..6b4616d43bc29 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -581,6 +581,10 @@ Static Analyzer
   `strcmp``, ``strncmp``, ``strcpy``, ``strlen``, ``strsep`` and many more. 
Although
   this checker currently is in list of alpha checkers due to a false positive.
 
+- Added a new checker ``alpha.unix.Errno``. This can find the first read
+  of ``errno`` after successful standard function calls, such use of ``errno``
+  could be unsafe.
+
 - Deprecate the ``-analyzer-store region`` and
   ``-analyzer-opt-analyze-nested-blocks`` analyzer flags.
   These flags are still accepted, but a warning will be displayed.

diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 6a73e66b0daaa..6f2486fb49dfc 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2520,6 +2520,75 @@ Check improper use of chroot.
f(); // warn: no call of chdir("/") immediately after chroot
  }
 
+.. _alpha-unix-Errno:
+
+alpha.unix.Errno (C)
+
+
+Check for improper use of ``errno``.
+This checker implements partially CERT rule
+`ERR30-C. Set errno to zero before calling a library function known to set 
errno,
+and check errno only after the function returns a value indicating failure
+`_.
+The checker can find the first read of ``errno`` after successful standard
+function calls.
+
+The C and POSIX standards often do not define if a standard library function
+may change value of ``errno`` if the call does not fail.
+Therefore, ``errno`` should only be used if it is known from the return value
+of a function that the call has failed.
+There are exceptions to this rule (for example ``strtol``) but the affected
+functions are not yet supported by the checker.
+The return values for the failure cases are documented in the standard Linux 
man
+pages of the functions and in the `POSIX standard 
`_.
+
+.. code-block:: c
+
+ int unsafe_errno_read(int sock, void *data, int data_size) {
+   if (send(sock, data, data_size, 0) != data_size) {
+ // 'send' can be successful even if not all data was sent
+ if (errno == 1) { // An undefined value may be read from 'errno'
+   return 0;
+ }
+   }
+   return 1;
+ }
+
+The supported functions are the same that are modeled by checker
+:ref:`alpha-unix-StdCLibraryFunctionArgs`.
+The ``ModelPOSIX`` option of that checker affects the set of checked functions.
+
+**Parameters**
+
+The ``AllowErrnoReadOutsideConditionExpressions`` option allows read of the
+errno value if the value is not used in a condition (in ``if`` statements,
+loops, conditional expressions, ``switch`` statements). For example ``errno``
+can be stored into a variable without getting a warning by the checker.
+
+.. code-block:: c
+
+ int unsafe_errno_read(int sock, void *data, int data_size) {
+   if (send(sock, data, data_size, 0) != data_size) {
+ int err = errno;
+ // warning if 'AllowErrnoReadOutsideConditionExpressions' is false
+ // no warning if 'AllowErrnoReadOutsideConditionExpressions' is true
+   }
+   return 1;
+ }
+
+Default value of this option is ``true``. This allows save of th

[PATCH] D122150: [clang][analyzer] Add checker for bad use of 'errno'.

2022-06-20 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
balazske marked an inline comment as done.
Closed by commit rG60f3b071185b: [clang][analyzer] Add checker for bad use of 
'errno'. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122150

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
  clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/errno-notes.c
  clang/test/Analysis/errno-options.c
  clang/test/Analysis/errno.c

Index: clang/test/Analysis/errno.c
===
--- clang/test/Analysis/errno.c
+++ clang/test/Analysis/errno.c
@@ -3,6 +3,7 @@
 // RUN:   -analyzer-checker=apiModeling.Errno \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -analyzer-checker=alpha.unix.Errno \
 // RUN:   -DERRNO_VAR
 
 // RUN: %clang_analyze_cc1 -verify %s \
@@ -10,8 +11,10 @@
 // RUN:   -analyzer-checker=apiModeling.Errno \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -analyzer-checker=alpha.unix.Errno \
 // RUN:   -DERRNO_FUNC
 
+#include "Inputs/system-header-simulator.h"
 #ifdef ERRNO_VAR
 #include "Inputs/errno_var.h"
 #endif
@@ -24,6 +27,7 @@
 int ErrnoTesterChecker_getErrno();
 int ErrnoTesterChecker_setErrnoIfError();
 int ErrnoTesterChecker_setErrnoIfErrorRange();
+int ErrnoTesterChecker_setErrnoCheckState();
 
 void something();
 
@@ -61,3 +65,199 @@
 clang_analyzer_eval(errno == 1); // expected-warning{{FALSE}} expected-warning{{TRUE}}
   }
 }
+
+void testErrnoCheck0() {
+  // If the function returns a success result code, value of 'errno'
+  // is unspecified and it is unsafe to make any decision with it.
+  // The function did not promise to not change 'errno' if no failure happens.
+  int X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 0) {
+if (errno) { // expected-warning{{An undefined value may be read from 'errno' [alpha.unix.Errno]}}
+}
+if (errno) { // no warning for second time (analysis stops at the first warning)
+}
+  }
+  X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 0) {
+if (errno) { // expected-warning{{An undefined value may be read from 'errno' [alpha.unix.Errno]}}
+}
+errno = 0;
+  }
+  X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 0) {
+errno = 0;
+if (errno) { // no warning after overwritten 'errno'
+}
+  }
+}
+
+void testErrnoCheck1() {
+  // If the function returns error result code that is out-of-band (not a valid
+  // non-error return value) the value of 'errno' can be checked but it is not
+  // required to do so.
+  int X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 1) {
+if (errno) { // no warning
+}
+  }
+  X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 1) {
+errno = 0; // no warning
+  }
+}
+
+void testErrnoCheck2() {
+  // If the function returns an in-band error result the value of 'errno' is
+  // required to be checked to verify if error happened.
+  // The same applies to other functions that can indicate failure only by
+  // change of 'errno'.
+  int X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 2) {
+errno = 0; // expected-warning{{Value of 'errno' was not checked and is overwritten here [alpha.unix.Errno]}}
+errno = 0;
+  }
+  X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 2) {
+errno = 0; // expected-warning{{Value of 'errno' was not checked and is overwritten here [alpha.unix.Errno]}}
+if (errno) {
+}
+  }
+}
+
+void testErrnoCheck3() {
+  int X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 2) {
+if (errno) {
+}
+errno = 0; // no warning after 'errno' was read
+  }
+  X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 2) {
+int A = errno;
+errno = 0; // no warning after 'errno' was read
+  }
+}
+
+void testErrnoCheckUndefinedLoad() {
+  int X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 0) {
+if (errno) { // expected-warning{{An undefined value may be read from 'errno' [alpha.unix.Errno]}}
+}
+  }
+}
+
+void testErrnoNotCheckedAtSystemCall() {
+  int X = ErrnoTesterChecker_setErrnoCheckState();
+  if (X == 2) {
+printf("%i", 1); // expected-warning{{Value of 'errno' was not checked and may be overwritten by function 'printf' [alpha.unix.Errno]}}
+printf("%i", 1); // no warning ('printf' does not change errno state)
+  }
+}
+
+void testErrnoCheckStateI

[PATCH] D128049: [mlir] move SCF headers to SCF/{IR,Transforms} respectively

2022-06-20 Thread Alex Zinenko 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 rG8b68da2c7d97: [mlir] move SCF headers to SCF/{IR,Transforms} 
respectively (authored by ftynse).

Changed prior to commit:
  https://reviews.llvm.org/D128049?vs=437955&id=438286#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128049

Files:
  flang/lib/Optimizer/Transforms/AffineDemotion.cpp
  flang/lib/Optimizer/Transforms/AffinePromotion.cpp
  flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp
  mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
  mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
  mlir/include/mlir/Dialect/Async/Transforms.h
  mlir/include/mlir/Dialect/Linalg/Utils/Utils.h
  mlir/include/mlir/Dialect/SCF/BufferizableOpInterfaceImpl.h
  mlir/include/mlir/Dialect/SCF/CMakeLists.txt
  mlir/include/mlir/Dialect/SCF/IR/CMakeLists.txt
  mlir/include/mlir/Dialect/SCF/IR/SCF.h
  mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
  mlir/include/mlir/Dialect/SCF/Passes.h
  mlir/include/mlir/Dialect/SCF/Passes.td
  mlir/include/mlir/Dialect/SCF/Patterns.h
  mlir/include/mlir/Dialect/SCF/SCF.h
  mlir/include/mlir/Dialect/SCF/SCFOps.td
  mlir/include/mlir/Dialect/SCF/TileUsingInterface.h
  mlir/include/mlir/Dialect/SCF/Transforms.h
  mlir/include/mlir/Dialect/SCF/Transforms/BufferizableOpInterfaceImpl.h
  mlir/include/mlir/Dialect/SCF/Transforms/CMakeLists.txt
  mlir/include/mlir/Dialect/SCF/Transforms/Passes.h
  mlir/include/mlir/Dialect/SCF/Transforms/Passes.td
  mlir/include/mlir/Dialect/SCF/Transforms/Patterns.h
  mlir/include/mlir/Dialect/SCF/Transforms/TileUsingInterface.h
  mlir/include/mlir/Dialect/SCF/Transforms/Transforms.h
  mlir/include/mlir/Dialect/SCF/Utils/Utils.h
  mlir/include/mlir/InitAllDialects.h
  mlir/include/mlir/InitAllPasses.h
  mlir/lib/CAPI/Dialect/SCF.cpp
  mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp
  mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
  mlir/lib/Conversion/LinalgToStandard/LinalgToStandard.cpp
  mlir/lib/Conversion/OpenACCToSCF/OpenACCToSCF.cpp
  mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
  mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
  mlir/lib/Conversion/SCFToGPU/SCFToGPUPass.cpp
  mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp
  mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
  mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRVPass.cpp
  mlir/lib/Conversion/ShapeToStandard/ConvertShapeConstraints.cpp
  mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp
  mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
  mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp
  mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamedPass.cpp
  mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp
  mlir/lib/Conversion/TosaToSCF/TosaToSCF.cpp
  mlir/lib/Conversion/TosaToSCF/TosaToSCFPass.cpp
  mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp
  mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
  mlir/lib/Dialect/Affine/Transforms/LoopCoalescing.cpp
  mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
  mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp
  mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp
  mlir/lib/Dialect/Func/Transforms/PassDetail.h
  mlir/lib/Dialect/GPU/Transforms/MemoryPromotion.cpp
  mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp
  mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
  mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp
  mlir/lib/Dialect/Linalg/Transforms/HoistPadding.cpp
  mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
  mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp
  mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
  mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
  mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
  mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
  mlir/lib/Dialect/Linalg/Utils/Utils.cpp
  mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp
  mlir/lib/Dialect/SCF/CMakeLists.txt
  mlir/lib/Dialect/SCF/IR/CMakeLists.txt
  mlir/lib/Dialect/SCF/IR/SCF.cpp
  mlir/lib/Dialect/SCF/SCF.cpp
  mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp
  mlir/lib/Dialect/SCF/Transforms/BufferizableOpInterfaceImpl.cpp
  mlir/lib/Dialect/SCF/Transforms/Bufferize.cpp
  mlir/lib/Dialect/SCF/Transforms/ForToWhile.cpp
  mlir/lib/Dialect/SCF/Transforms/LoopCanonicalization.cpp
  mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp
  mlir/lib/Dialect/SCF/Transforms/LoopRangeFolding.cpp
  mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp
  mlir/lib/Dialect/SCF/Transforms/ParallelLoopCollapsing.cpp
  mlir/lib/Dialect/SCF/Transforms/ParallelLoopFusion.cpp
  mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp
  mlir/lib/Dialect/SCF/Transforms/PassDetail.h
  mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
  mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp
  mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp
  mlir/lib/Dialect/SCF/Utils/Utils.cpp
  mlir/lib/Dialect/SparseT

[PATCH] D125885: [clang-tidy] bugprone-argument-comment: Ignore calls to user-defined literals

2022-06-20 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D125885#3595301 , @jspam wrote:

> Would someone be able to commit this for me, as I do not have the necessary 
> rights? Thanks

I can for you, what name and email address should I use?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125885

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


[PATCH] D128048: Add a new clang option "-ftime-trace-path"

2022-06-20 Thread dongjunduo via Phabricator via cfe-commits
dongjunduo updated this revision to Diff 438289.
dongjunduo added a comment.

[Clang] Restore the old behaviors when "-ftime-trace-path" is not specified


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128048

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/tools/driver/cc1_main.cpp


Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -255,7 +255,16 @@
 
   if (llvm::timeTraceProfilerEnabled()) {
 SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-llvm::sys::path::replace_extension(Path, "json");
+if (Clang->getFrontendOpts().TimeTracePath.empty()) {
+  // replace the suffix to '.json' directly
+  llvm::sys::path::replace_extension(Path, "json");
+} else {
+  // change path prefix to the aim path, then add suffix '.json'
+  Path.assign(Clang->getFrontendOpts().TimeTracePath);
+  Path.append(
+  llvm::sys::path::filename(Clang->getFrontendOpts().OutputFile));
+  Path.append(".json");
+}
 if (auto profilerOutput = Clang->createOutputFile(
 Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6183,6 +6183,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
+  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_path);
   Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
   Args.AddLastArg(CmdArgs, options::OPT_malign_double);
   Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -499,6 +499,9 @@
   /// Minimum time granularity (in microseconds) traced by time profiler.
   unsigned TimeTraceGranularity;
 
+  /// Path which stores the output files of time profiler.
+  std::string TimeTracePath;
+
 public:
   FrontendOptions()
   : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2828,6 +2828,10 @@
   HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
   Flags<[CC1Option, CoreOption]>,
   MarshallingInfoInt, "500u">;
+def ftime_trace_path : Joined<["-"], "ftime-trace-path=">, Group,
+  HelpText<"Path which stores the output files of time profiler">,
+  Flags<[CC1Option, CoreOption]>,
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,


Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -255,7 +255,16 @@
 
   if (llvm::timeTraceProfilerEnabled()) {
 SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-llvm::sys::path::replace_extension(Path, "json");
+if (Clang->getFrontendOpts().TimeTracePath.empty()) {
+  // replace the suffix to '.json' directly
+  llvm::sys::path::replace_extension(Path, "json");
+} else {
+  // change path prefix to the aim path, then add suffix '.json'
+  Path.assign(Clang->getFrontendOpts().TimeTracePath);
+  Path.append(
+  llvm::sys::path::filename(Clang->getFrontendOpts().OutputFile));
+  Path.append(".json");
+}
 if (auto profilerOutput = Clang->createOutputFile(
 Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6183,6 +6183,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
+  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_path);
   Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
   Args.AddLastArg(CmdArgs, options::OPT_malign_double);
   Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
Index: clang/include/clang/

[PATCH] D125885: [clang-tidy] bugprone-argument-comment: Ignore calls to user-defined literals

2022-06-20 Thread Joachim Priesner via Phabricator via cfe-commits
jspam added a comment.

Thanks. Please use Joachim Priesner 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125885

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


[PATCH] D128116: [clang][docs] Sync generated command line doc with td files.

2022-06-20 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv closed this revision.
ilinpv added a comment.

Commited in af6d2a0b6825e71965f3e2701a63c239fa0ad70f 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128116

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


[PATCH] D127293: [clang-tidy] Ignore other members in a union if any member of it is initialized in cppcoreguidelines-pro-type-member-init

2022-06-20 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 438295.
Sockke added a comment.

rebased.


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

https://reviews.llvm.org/D127293

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -552,3 +552,19 @@
   int A;
   // CHECK-FIXES-NOT: int A{};
 };
+
+struct S1 {
+  S1() {}
+  union {
+int a = 0;
+int b;
+  };
+};
+
+struct S2 {
+  S2() : a{} {}
+  union {
+int a;
+int b;
+  };
+};
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -61,6 +61,17 @@
   }
 }
 
+void removeFieldInitialized(const FieldDecl *M,
+SmallPtrSetImpl &FieldDecls) {
+  const RecordDecl *R = M->getParent();
+  if (R && R->isUnion()) {
+// Erase all members in a union if any member of it is initialized.
+for (const auto *F : R->fields())
+  FieldDecls.erase(F);
+  } else
+FieldDecls.erase(M);
+}
+
 void removeFieldsInitializedInBody(
 const Stmt &Stmt, ASTContext &Context,
 SmallPtrSetImpl &FieldDecls) {
@@ -70,7 +81,7 @@
 hasLHS(memberExpr(member(fieldDecl().bind("fieldDecl")),
 Stmt, Context);
   for (const auto &Match : Matches)
-FieldDecls.erase(Match.getNodeAs("fieldDecl"));
+removeFieldInitialized(Match.getNodeAs("fieldDecl"), 
FieldDecls);
 }
 
 StringRef getName(const FieldDecl *Field) { return Field->getName(); }
@@ -418,13 +429,18 @@
 
   // Gather all fields (direct and indirect) that need to be initialized.
   SmallPtrSet FieldsToInit;
-  forEachField(ClassDecl, ClassDecl.fields(), [&](const FieldDecl *F) {
+  bool AnyMemberHasInitPerUnion = false;
+  forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
+ AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
 if (IgnoreArrays && F->getType()->isArrayType())
   return;
+if (F->hasInClassInitializer() && F->getParent()->isUnion())
+  AnyMemberHasInitPerUnion = true;
 if (!F->hasInClassInitializer() &&
 utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
 Context) &&
-!isEmpty(Context, F->getType()) && !F->isUnnamedBitfield())
+!isEmpty(Context, F->getType()) && !F->isUnnamedBitfield() &&
+!AnyMemberHasInitPerUnion)
   FieldsToInit.insert(F);
   });
   if (FieldsToInit.empty())
@@ -437,7 +453,7 @@
   if (Init->isAnyMemberInitializer() && Init->isWritten()) {
 if (IsUnion)
   return; // We can only initialize one member of a union.
-FieldsToInit.erase(Init->getAnyMember());
+removeFieldInitialized(Init->getAnyMember(), FieldsToInit);
   }
 }
 removeFieldsInitializedInBody(*Ctor->getBody(), Context, FieldsToInit);
@@ -478,7 +494,7 @@
   // Collect all fields but only suggest a fix for the first member of unions,
   // as initializing more than one union member is an error.
   SmallPtrSet FieldsToFix;
-  bool AnyMemberHasInitPerUnion = false;
+  AnyMemberHasInitPerUnion = false;
   forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
  AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
 if (!FieldsToInit.count(F))


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -552,3 +552,19 @@
   int A;
   // CHECK-FIXES-NOT: int A{};
 };
+
+struct S1 {
+  S1() {}
+  union {
+int a = 0;
+int b;
+  };
+};
+
+struct S2 {
+  S2() : a{} {}
+  union {
+int a;
+int b;
+  };
+};
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -61,6 +61,17 @@
   }
 }
 
+void removeFieldInitialized(const FieldDecl *M,
+SmallPtrSetImpl &FieldDecls) {
+  const RecordDecl *R = M->getParent();
+  if (R && R->isUnion()) {
+// Erase all memb

[PATCH] D125349: [clang][sema] Generate builtin operator overloads for (volatile) _Atomic types

2022-06-20 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 438296.
jansvoboda11 added a comment.

Extract function for building type


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125349

Files:
  clang/include/clang/AST/Type.h
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.cpp
  clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.cpp

Index: clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=gnu++98 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+_Atomic unsigned an_atomic_uint;
+
+enum { an_enum_value = 1 };
+
+void enum1() { an_atomic_uint += an_enum_value; }
+
+void enum2() { an_atomic_uint |= an_enum_value; }
+
+volatile _Atomic unsigned an_volatile_atomic_uint;
+
+void enum3() { an_volatile_atomic_uint += an_enum_value; }
+
+void enum4() { an_volatile_atomic_uint |= an_enum_value; }
Index: clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=gnu++11 -emit-llvm -triple=x86_64-linux-gnu -o - %s | FileCheck %s
+
+_Atomic unsigned an_atomic_uint;
+
+enum { an_enum_value = 1 };
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum1v()
+void enum1() {
+  an_atomic_uint += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum2v()
+void enum2() {
+  an_atomic_uint |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum3RU7_Atomicj({{.*}})
+void enum3(_Atomic unsigned &an_atomic_uint_param) {
+  an_atomic_uint_param += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum4RU7_Atomicj({{.*}})
+void enum4(_Atomic unsigned &an_atomic_uint_param) {
+  an_atomic_uint_param |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
+
+volatile _Atomic unsigned an_volatile_atomic_uint;
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum5v()
+void enum5() {
+  an_volatile_atomic_uint += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum6v()
+void enum6() {
+  an_volatile_atomic_uint |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum7RVU7_Atomicj({{.*}})
+void enum7(volatile _Atomic unsigned &an_volatile_atomic_uint_param) {
+  an_volatile_atomic_uint_param += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum8RVU7_Atomicj({{.*}})
+void enum8(volatile _Atomic unsigned &an_volatile_atomic_uint_param) {
+  an_volatile_atomic_uint_param |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -8200,6 +8200,49 @@
 return VRQuals;
 }
 
+// Note: We're currently only handling qualifiers that are meaningful for the
+// LHS of compound assignment overloading.
+static void forAllQualifierCombinationsImpl(
+QualifiersAndAtomic Available, QualifiersAndAtomic Applied,
+llvm::function_ref Callback) {
+  // _Atomic
+  if (Available.hasAtomic()) {
+Available.removeAtomic();
+forAllQualifierCombinationsImpl(Available, Applied.withAtomic(), Callback);
+forAllQualifierCombinationsImpl(Available, Applied, Callback);
+return;
+  }
+
+  // volatile
+  if (Available.hasVolatile()) {
+Available.removeVolatile();
+assert(!Applied.hasVolatile());
+forAllQualifierCombinationsImpl(Available, Applied.withVolatile(),
+Callback);
+forAllQualifierCombinationsImpl(Available, Applied, Callback);
+return;
+  }
+
+  Callback(Applied);
+}
+
+static void forAllQualifierCombinations(
+QualifiersAndAtomic Quals,
+llvm::function_ref Callback) {
+  return forAllQualifierCombinationsImpl(Quals, QualifiersAndAtomic(),
+ Callback);
+}
+
+static QualType makeQualifiedLValueReferenceType(QualType Base,
+ QualifiersAndAtomic Quals,
+ Sema &S) {
+  if (Quals.hasAtomic())
+Base = S.Context.getAtomicType(Base);
+  if (Quals.hasVolatile())
+Base = S.Context.getVolatileType(Base);
+  return S.Context.getLValueReferenceType(Base);
+}
+
 namespace {
 
 /// Helper class to manage the addition of builtin operator overload
@@ -8210,7 +8253,7 @@
   // Common instance state available to all overload candidate addition methods.
   Sema &S;
   ArrayRef Args;
-  Qualifiers VisibleType

[PATCH] D125349: [clang][sema] Generate builtin operator overloads for (volatile) _Atomic types

2022-06-20 Thread Jan Svoboda 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 rGb02d970b4335: [clang][sema] Generate builtin operator 
overloads for (volatile) _Atomic types (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125349

Files:
  clang/include/clang/AST/Type.h
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.cpp
  clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.cpp

Index: clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=gnu++98 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+_Atomic unsigned an_atomic_uint;
+
+enum { an_enum_value = 1 };
+
+void enum1() { an_atomic_uint += an_enum_value; }
+
+void enum2() { an_atomic_uint |= an_enum_value; }
+
+volatile _Atomic unsigned an_volatile_atomic_uint;
+
+void enum3() { an_volatile_atomic_uint += an_enum_value; }
+
+void enum4() { an_volatile_atomic_uint |= an_enum_value; }
Index: clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=gnu++11 -emit-llvm -triple=x86_64-linux-gnu -o - %s | FileCheck %s
+
+_Atomic unsigned an_atomic_uint;
+
+enum { an_enum_value = 1 };
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum1v()
+void enum1() {
+  an_atomic_uint += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum2v()
+void enum2() {
+  an_atomic_uint |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum3RU7_Atomicj({{.*}})
+void enum3(_Atomic unsigned &an_atomic_uint_param) {
+  an_atomic_uint_param += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum4RU7_Atomicj({{.*}})
+void enum4(_Atomic unsigned &an_atomic_uint_param) {
+  an_atomic_uint_param |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
+
+volatile _Atomic unsigned an_volatile_atomic_uint;
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum5v()
+void enum5() {
+  an_volatile_atomic_uint += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum6v()
+void enum6() {
+  an_volatile_atomic_uint |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum7RVU7_Atomicj({{.*}})
+void enum7(volatile _Atomic unsigned &an_volatile_atomic_uint_param) {
+  an_volatile_atomic_uint_param += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum8RVU7_Atomicj({{.*}})
+void enum8(volatile _Atomic unsigned &an_volatile_atomic_uint_param) {
+  an_volatile_atomic_uint_param |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -8200,6 +8200,49 @@
 return VRQuals;
 }
 
+// Note: We're currently only handling qualifiers that are meaningful for the
+// LHS of compound assignment overloading.
+static void forAllQualifierCombinationsImpl(
+QualifiersAndAtomic Available, QualifiersAndAtomic Applied,
+llvm::function_ref Callback) {
+  // _Atomic
+  if (Available.hasAtomic()) {
+Available.removeAtomic();
+forAllQualifierCombinationsImpl(Available, Applied.withAtomic(), Callback);
+forAllQualifierCombinationsImpl(Available, Applied, Callback);
+return;
+  }
+
+  // volatile
+  if (Available.hasVolatile()) {
+Available.removeVolatile();
+assert(!Applied.hasVolatile());
+forAllQualifierCombinationsImpl(Available, Applied.withVolatile(),
+Callback);
+forAllQualifierCombinationsImpl(Available, Applied, Callback);
+return;
+  }
+
+  Callback(Applied);
+}
+
+static void forAllQualifierCombinations(
+QualifiersAndAtomic Quals,
+llvm::function_ref Callback) {
+  return forAllQualifierCombinationsImpl(Quals, QualifiersAndAtomic(),
+ Callback);
+}
+
+static QualType makeQualifiedLValueReferenceType(QualType Base,
+ QualifiersAndAtomic Quals,
+ Sema &S) {
+  if (Quals.hasAtomic())
+Base = S.Context.getAtomicType(Base);
+  if (Quals.hasVolatile())
+Base = S.Context.getVolatileType(Base);
+  return S.Context.getLValueReferenceType(Base);
+}
+
 namespace {
 
 /// Helper class to manage the addition of builtin operator overload
@@ -82

[clang] b02d970 - [clang][sema] Generate builtin operator overloads for (volatile) _Atomic types

2022-06-20 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-06-20T11:03:29+02:00
New Revision: b02d970b4335561940dd584f6e6497ab684c788d

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

LOG: [clang][sema] Generate builtin operator overloads for (volatile) _Atomic 
types

We observed a failed assert in overloaded compound-assignment operator 
resolution:

```
Assertion failed: (Result.isInvalid() && "C++ binary operator overloading is 
missing candidates!"), function CreateOverloadedBinOp, file SemaOverload.cpp, 
line 13944.
...
frame #4: clang` clang::Sema::CreateOverloadedBinOp(..., Opc=BO_OrAssign, ..., 
PerformADL=true, AllowRewrittenCandidates=false, ...) at SemaOverload.cpp:13943
frame #5: clang` BuildOverloadedBinOp(..., Opc=BO_OrAssign, ...) at 
SemaExpr.cpp:15228
frame #6: clang` clang::Sema::BuildBinOp(..., Opc=BO_OrAssign, ...) at 
SemaExpr.cpp:15330
frame #7: clang` clang::Sema::ActOnBinOp(..., Kind=pipeequal, ...) at 
SemaExpr.cpp:15187
frame #8: clang` clang::Parser::ParseRHSOfBinaryExpression(..., 
MinPrec=Assignment) at ParseExpr.cpp:629
frame #9: clang` clang::Parser::ParseAssignmentExpression(..., 
isTypeCast=NotTypeCast) at ParseExpr.cpp:176
frame #10: clang` clang::Parser::ParseExpression(... isTypeCast=NotTypeCast) at 
ParseExpr.cpp:124
frame #11: clang` clang::Parser::ParseExprStatement(...) at ParseStmt.cpp:464
```

A simple reproducer is:

```
_Atomic unsigned an_atomic_uint;

enum { an_enum_value = 1 };

void enum1() { an_atomic_uint += an_enum_value; }
```

This patch fixes the issue by generating builtin operator overloads for 
(volatile) _Atomic types.

Reviewed By: aaron.ballman

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

Added: 
clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.cpp
clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.cpp

Modified: 
clang/include/clang/AST/Type.h
clang/lib/Sema/SemaOverload.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 5784839f4f961..1f8086301f66e 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -265,16 +265,31 @@ class Qualifiers {
   bool hasOnlyConst() const { return Mask == Const; }
   void removeConst() { Mask &= ~Const; }
   void addConst() { Mask |= Const; }
+  Qualifiers withConst() const {
+Qualifiers Qs = *this;
+Qs.addConst();
+return Qs;
+  }
 
   bool hasVolatile() const { return Mask & Volatile; }
   bool hasOnlyVolatile() const { return Mask == Volatile; }
   void removeVolatile() { Mask &= ~Volatile; }
   void addVolatile() { Mask |= Volatile; }
+  Qualifiers withVolatile() const {
+Qualifiers Qs = *this;
+Qs.addVolatile();
+return Qs;
+  }
 
   bool hasRestrict() const { return Mask & Restrict; }
   bool hasOnlyRestrict() const { return Mask == Restrict; }
   void removeRestrict() { Mask &= ~Restrict; }
   void addRestrict() { Mask |= Restrict; }
+  Qualifiers withRestrict() const {
+Qualifiers Qs = *this;
+Qs.addRestrict();
+return Qs;
+  }
 
   bool hasCVRQualifiers() const { return getCVRQualifiers(); }
   unsigned getCVRQualifiers() const { return Mask & CVRMask; }
@@ -609,6 +624,47 @@ class Qualifiers {
   static const uint32_t AddressSpaceShift = 9;
 };
 
+class QualifiersAndAtomic {
+  Qualifiers Quals;
+  bool HasAtomic;
+
+public:
+  QualifiersAndAtomic() : HasAtomic(false) {}
+  QualifiersAndAtomic(Qualifiers Quals, bool HasAtomic)
+  : Quals(Quals), HasAtomic(HasAtomic) {}
+
+  operator Qualifiers() const { return Quals; }
+
+  bool hasVolatile() const { return Quals.hasVolatile(); }
+  bool hasConst() const { return Quals.hasConst(); }
+  bool hasRestrict() const { return Quals.hasRestrict(); }
+  bool hasAtomic() const { return HasAtomic; }
+
+  void addVolatile() { Quals.addVolatile(); }
+  void addConst() { Quals.addConst(); }
+  void addRestrict() { Quals.addRestrict(); }
+  void addAtomic() { HasAtomic = true; }
+
+  void removeVolatile() { Quals.removeVolatile(); }
+  void removeConst() { Quals.removeConst(); }
+  void removeRestrict() { Quals.removeRestrict(); }
+  void removeAtomic() { HasAtomic = false; }
+
+  QualifiersAndAtomic withVolatile() {
+return {Quals.withVolatile(), HasAtomic};
+  }
+  QualifiersAndAtomic withConst() { return {Quals.withConst(), HasAtomic}; }
+  QualifiersAndAtomic withRestrict() {
+return {Quals.withRestrict(), HasAtomic};
+  }
+  QualifiersAndAtomic withAtomic() { return {Quals, true}; }
+
+  QualifiersAndAtomic &operator+=(Qualifiers RHS) {
+Quals += RHS;
+return *this;
+  }
+};
+
 /// A std::pair-like structure for storing a qualified type split
 /// into its local qualifiers and its locally-unqualified type.
 struct SplitQualType {

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/cl

[libunwind] 8df257a - [libunwind] Ensure test/libunwind_01.pass is not completely inlined

2022-06-20 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2022-06-20T09:05:49Z
New Revision: 8df257a6d0b0b32e05e89874eff4c8ddd2a2a2a9

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

LOG: [libunwind] Ensure test/libunwind_01.pass is not completely inlined

By adding noinline and calling fprintf before returning we ensure that
every function will have a distinct call frame and that the return address
will always be saved instead of saving the target in main as the result.

Before this change all backtraces were always backtrace -> main -> _start,
i.e. always exactly three entries. This happenend because all calls were
inlined in main() and the test just happenend to pass because there is at
least _start before main.

I found this while fixing some bugs in libunwind for CHERI and noticed that
the test was passing even though the code was completely broken.

Obtained from: https://github.com/CTSRD-CHERI/llvm-project

Reviewed By: #libunwind, ldionne, MaskRay

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

Added: 


Modified: 
libunwind/test/libunwind_01.pass.cpp

Removed: 




diff  --git a/libunwind/test/libunwind_01.pass.cpp 
b/libunwind/test/libunwind_01.pass.cpp
index bbfaffd153cc2..4661ac9df8219 100644
--- a/libunwind/test/libunwind_01.pass.cpp
+++ b/libunwind/test/libunwind_01.pass.cpp
@@ -15,6 +15,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 void backtrace(int lower_bound) {
@@ -24,9 +25,17 @@ void backtrace(int lower_bound) {
   unw_cursor_t cursor;
   unw_init_local(&cursor, &context);
 
+  char buffer[1024];
+  unw_word_t offset = 0;
+
   int n = 0;
   do {
-++n;
+n++;
+if (unw_get_proc_name(&cursor, buffer, sizeof(buffer), &offset) == 0) {
+  fprintf(stderr, "Frame %d: %s+%p\n", n, buffer, (void*)offset);
+} else {
+  fprintf(stderr, "Frame %d: Could not get name for cursor\n", n);
+}
 if (n > 100) {
   abort();
 }
@@ -37,18 +46,24 @@ void backtrace(int lower_bound) {
   }
 }
 
-void test1(int i) {
+__attribute__((noinline)) void test1(int i) {
+  fprintf(stderr, "starting %s\n", __func__);
   backtrace(i);
+  fprintf(stderr, "finished %s\n", __func__); // ensure return address is saved
 }
 
-void test2(int i, int j) {
+__attribute__((noinline)) void test2(int i, int j) {
+  fprintf(stderr, "starting %s\n", __func__);
   backtrace(i);
   test1(j);
+  fprintf(stderr, "finished %s\n", __func__); // ensure return address is saved
 }
 
-void test3(int i, int j, int k) {
+__attribute__((noinline)) void test3(int i, int j, int k) {
+  fprintf(stderr, "starting %s\n", __func__);
   backtrace(i);
   test2(j, k);
+  fprintf(stderr, "finished %s\n", __func__); // ensure return address is saved
 }
 
 void test_no_info() {
@@ -142,9 +157,9 @@ void test_fpreg_get_set() {}
 #endif
 
 int main(int, char**) {
-  test1(1);
-  test2(1, 2);
-  test3(1, 2, 3);
+  test1(3);
+  test2(3, 4);
+  test3(3, 4, 5);
   test_no_info();
   test_reg_names();
   test_reg_get_set();



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


[clang] 8c3fa31 - [OpenCL][TableGen] Fix type extension guard emission

2022-06-20 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-06-20T10:07:34+01:00
New Revision: 8c3fa31701c4b874138c52266e7ab96818092f47

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

LOG: [OpenCL][TableGen] Fix type extension guard emission

For certain cases (such as for the double subtype of AGenType), the
OpenCLBuiltinFileEmitterBase would not emit the extension #if-guard.
Fix that by looking at the extension of the actual type instead of the
argument type (which could be a GenType that does not carry any
extension information).

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index dca9970444a73..cddbd7b17c5f6 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -1082,7 +1082,7 @@ void OpenCLBuiltinFileEmitterBase::expandTypesInSignature(
 // If the type requires an extension, add a TypeExtMap entry mapping
 // the full type name to the extension.
 StringRef Ext =
-Arg->getValueAsDef("Extension")->getValueAsString("ExtName");
+Type->getValueAsDef("Extension")->getValueAsString("ExtName");
 if (!Ext.empty() && TypeExtMap.find(FullType) == TypeExtMap.end()) {
   TypeExtMap.insert({FullType, Ext});
 }



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


[PATCH] D97204: [RFC] Clang 64-bit source locations

2022-06-20 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.
Herald added a project: All.

Some of this patch set has been broken by https://reviews.llvm.org/D125403 and 
https://reviews.llvm.org/D125952 - which are size optimisations for PCH 
encodings of source locations. The biggest issue is new line 90 of 
`clang/include/clang/Serialization/SourceLocationEncoding.h` in the first patch.

I see the mini-patches in @simon_tatham's last comment have not unblocked this 
patch as much as was hoped, but maybe this comment can act as a reverse-ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97204

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


[PATCH] D127873: [clang-format] Fix misplacemnt of `*` in declaration of pointer to struct

2022-06-20 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2328
+}
+
 if (PrevToken->Tok.isLiteral() ||

MyDeveloperDay wrote:
> Thank you I wish more of the clauses were commented like this
+1



Comment at: clang/unittests/Format/FormatTest.cpp:10439
+   Style);
+  verifyFormat("union {\n"
+   "}* ptr;",

Bonus points for the union. It often gets forgotten.


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

https://reviews.llvm.org/D127873

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


[PATCH] D128048: Add a new clang option "-ftime-trace-path"

2022-06-20 Thread dongjunduo via Phabricator via cfe-commits
dongjunduo updated this revision to Diff 438303.
dongjunduo marked an inline comment as done.
dongjunduo added a comment.

[Clang] change unclear help text pf "-ftime-trace-path"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128048

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/tools/driver/cc1_main.cpp


Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -255,7 +255,16 @@
 
   if (llvm::timeTraceProfilerEnabled()) {
 SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-llvm::sys::path::replace_extension(Path, "json");
+if (Clang->getFrontendOpts().TimeTracePath.empty()) {
+  // replace the suffix to '.json' directly
+  llvm::sys::path::replace_extension(Path, "json");
+} else {
+  // change path prefix to the aim path, then add suffix '.json'
+  Path.assign(Clang->getFrontendOpts().TimeTracePath);
+  Path.append(
+  llvm::sys::path::filename(Clang->getFrontendOpts().OutputFile));
+  Path.append(".json");
+}
 if (auto profilerOutput = Clang->createOutputFile(
 Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6183,6 +6183,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
+  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_path);
   Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
   Args.AddLastArg(CmdArgs, options::OPT_malign_double);
   Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -499,6 +499,9 @@
   /// Minimum time granularity (in microseconds) traced by time profiler.
   unsigned TimeTraceGranularity;
 
+  /// Path which stores the output files of time profiler.
+  std::string TimeTracePath;
+
 public:
   FrontendOptions()
   : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2828,6 +2828,10 @@
   HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
   Flags<[CC1Option, CoreOption]>,
   MarshallingInfoInt, "500u">;
+def ftime_trace_path : Joined<["-"], "ftime-trace-path=">, Group,
+  HelpText<"Path which specifies the output files for -ftime-trace">,
+  Flags<[CC1Option, CoreOption]>,
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,


Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -255,7 +255,16 @@
 
   if (llvm::timeTraceProfilerEnabled()) {
 SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-llvm::sys::path::replace_extension(Path, "json");
+if (Clang->getFrontendOpts().TimeTracePath.empty()) {
+  // replace the suffix to '.json' directly
+  llvm::sys::path::replace_extension(Path, "json");
+} else {
+  // change path prefix to the aim path, then add suffix '.json'
+  Path.assign(Clang->getFrontendOpts().TimeTracePath);
+  Path.append(
+  llvm::sys::path::filename(Clang->getFrontendOpts().OutputFile));
+  Path.append(".json");
+}
 if (auto profilerOutput = Clang->createOutputFile(
 Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6183,6 +6183,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
+  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_path);
   Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
   Args.AddLastArg(CmdArgs, options::OPT_malign_double);
   Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);

[PATCH] D128048: Add a new clang option "-ftime-trace-path"

2022-06-20 Thread dongjunduo via Phabricator via cfe-commits
dongjunduo added a comment.

In D128048#3591829 , @Whitney wrote:

> Can you please add some test cases?

I have found that new-option unit tests are not included in `clang/test` or 
`clang/unit-tests`. Could u tell me where I should write the test cases?




Comment at: clang/tools/driver/cc1_main.cpp:257
   if (llvm::timeTraceProfilerEnabled()) {
-SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-llvm::sys::path::replace_extension(Path, "json");
+SmallString<128> Path(Clang->getFrontendOpts().TimeTracePath);
+
Path.append(llvm::sys::path::filename(Clang->getFrontendOpts().OutputFile));

Whitney wrote:
> What happens when TimeTracePath is not given? Ideally the originally behavior 
> is not changed. 
The originally behavior has been restored : ) 

Time-trace file "*.json" may be saved by following the origin logic if 
"-ftime-trace-path" is not be specified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128048

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


[PATCH] D128166: ManagedStatic: Destroy from destructor

2022-06-20 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle created this revision.
Herald added a reviewer: deadalnix.
Herald added subscribers: bzcheeseman, ayermolo, sdasgup3, wenzhicui, wrengr, 
dcaballe, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, 
grosul1, jvesely, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini, mstorsjo, hiraditya, mgorny.
Herald added a reviewer: bollu.
Herald added a reviewer: MaskRay.
Herald added a reviewer: rafauler.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a project: All.
nhaehnle requested review of this revision.
Herald added subscribers: lldb-commits, cfe-commits, yota9, StephenFan, 
stephenneuendorffer, nicolasvasilache.
Herald added projects: clang, LLDB, MLIR, LLVM.

This allows LLVM to be safely loaded and unloaded as a shared library
without leaking memory:

Consider the scenario where shared library Foo links against LLVM as
a shared library, and Foo may be loaded and unloaded multiple times
in the same process. Should Foo call llvm_shutdown or not? If it does
not, and LLVM is also loaded and unloaded multiple times, then
memory is leaked. If it does call llvm_shutdown and LLVM *isn't*
also unloaded, the state of LLVM's global statics is corrupted because
while the ManagedStatics may be re-initialized, *other* global
constructors aren't re-run.

Keep in mind that Foo itself may use ManagedStatic. If Foo is unloaded
but LLVM isn't, those statics should be destroyed.

The safe solution is to skip llvm_shutdown() altogether and destroy
managed statics from their destructor.

LLD relies on being able to call _exit() and still get some side-effects
of managed static destructors. We make this expectation much more
explicit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128166

Files:
  bolt/tools/driver/llvm-bolt.cpp
  bolt/tools/merge-fdata/merge-fdata.cpp
  clang/include/clang/Frontend/CompilerInstance.h
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp
  clang/utils/TableGen/TableGen.cpp
  libclc/utils/prepare-builtins.cpp
  lld/Common/ErrorHandler.cpp
  lldb/tools/driver/Driver.cpp
  lldb/tools/lldb-test/lldb-test.cpp
  lldb/unittests/Utility/LogTest.cpp
  lldb/utils/TableGen/LLDBTableGen.cpp
  llvm/docs/ProgrammersManual.rst
  llvm/examples/BrainF/BrainFDriver.cpp
  llvm/examples/HowToUseJIT/HowToUseJIT.cpp
  llvm/include/llvm-c/Core.h
  llvm/include/llvm/ADT/Statistic.h
  llvm/include/llvm/PassRegistry.h
  llvm/include/llvm/Support/DynamicLibrary.h
  llvm/include/llvm/Support/FastShutdown.h
  llvm/include/llvm/Support/InitLLVM.h
  llvm/include/llvm/Support/ManagedStatic.h
  llvm/lib/IR/Core.cpp
  llvm/lib/IR/Pass.cpp
  llvm/lib/IR/PassRegistry.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/FastShutdown.cpp
  llvm/lib/Support/InitLLVM.cpp
  llvm/lib/Support/ManagedStatic.cpp
  llvm/lib/Support/Parallel.cpp
  llvm/lib/Support/Statistic.cpp
  llvm/lib/Support/Unix/DynamicLibrary.inc
  llvm/lib/Support/Unix/Signals.inc
  llvm/lib/Support/Windows/DynamicLibrary.inc
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
  llvm/unittests/ExecutionEngine/ExecutionEngineTest.cpp
  llvm/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
  llvm/utils/KillTheDoctor/KillTheDoctor.cpp
  mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
  polly/lib/External/isl/interface/extract_interface.cc

Index: polly/lib/External/isl/interface/extract_interface.cc
===
--- polly/lib/External/isl/interface/extract_interface.cc
+++ polly/lib/External/isl/interface/extract_interface.cc
@@ -587,7 +587,6 @@
 
 	delete sema;
 	delete Clang;
-	llvm::llvm_shutdown();
 
 	if (Diags.hasErrorOccurred())
 		return EXIT_FAILURE;
Index: mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
===
--- mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
+++ mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
@@ -61,7 +61,6 @@
 }
 
 int main(int argc, char **argv) {
-  llvm::llvm_shutdown_obj x;
   registerPassManagerCLOptions();
 
   llvm::InitLLVM y(argc, argv);
Index: llvm/utils/KillTheDoctor/KillTheDoctor.cpp
===
--- llvm/utils/KillTheDoctor/KillTheDoctor.cpp
+++ llvm/utils/KillTheDoctor/KillTheDoctor.cpp
@@ -297,7 +297,6 @@
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal(argv[0]);
   PrettyStackTraceProgram X(argc, argv);
-  llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
 
   ToolName = argv[0];
 
Index: llvm/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
===
--- llvm/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
+++ llvm/unittests/Support/DynamicLibrary/DynamicLibrary

[PATCH] D127643: [Static Analyzer] Structured bindings to data members

2022-06-20 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I missed this commit because it was not tagged by "[analyzer]".
What is the community preference about tagging CSA commits?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127643

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


[PATCH] D128120: [Clang][VE] Add missing intrinsics

2022-06-20 Thread Erich Focht via Phabricator via cfe-commits
efocht accepted this revision.
efocht added a comment.
This revision is now accepted and ready to land.

Looks ok for me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128120

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


[PATCH] D128182: [NFC] Switch FloatModeKind enum class to use bitmask enums

2022-06-20 Thread Jolanta Jensen via Phabricator via cfe-commits
jolanta.jensen created this revision.
Herald added a project: All.
jolanta.jensen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Using bitmask enums simplifies and clarifies the code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128182

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/X86.h


Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
 
 #include "OSTargets.h"
+#include "clang/Basic/BitmaskEnum.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/Triple.h"
@@ -419,8 +420,8 @@
 
 // Use fpret for all types.
 RealTypeUsesObjCFPRetMask =
-((1 << (int)FloatModeKind::Float) | (1 << (int)FloatModeKind::Double) |
- (1 << (int)FloatModeKind::LongDouble));
+(int)(FloatModeKind::Float | FloatModeKind::Double |
+  FloatModeKind::LongDouble);
 
 // x86-32 has atomics up to 8 bytes
 MaxAtomicPromoteWidth = 64;
@@ -699,7 +700,7 @@
 "64-i64:64-f80:128-n8:16:32:64-S128");
 
 // Use fpret only for long double.
-RealTypeUsesObjCFPRetMask = (1 << (int)FloatModeKind::LongDouble);
+RealTypeUsesObjCFPRetMask = (int)FloatModeKind::LongDouble;
 
 // Use fp2ret for _Complex long double.
 ComplexLongDoubleUsesFP2Ret = true;
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_BASIC_TARGETINFO_H
 
 #include "clang/Basic/AddressSpaces.h"
+#include "clang/Basic/BitmaskEnum.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
@@ -52,14 +53,14 @@
 namespace Builtin { struct Info; }
 
 enum class FloatModeKind {
-  NoFloat = 255,
-  Half = 0,
-  Float,
-  Double,
-  LongDouble,
-  Float128,
-  Ibm128,
-  Last = Ibm128
+  NoFloat = 0,
+  Half = 1 << 0,
+  Float = 1 << 1,
+  Double = 1 << 2,
+  LongDouble = 1 << 3,
+  Float128 = 1 << 4,
+  Ibm128 = 1 << 5,
+  LLVM_MARK_AS_BITMASK_ENUM(Ibm128)
 };
 
 /// Fields controlling how types are laid out in memory; these may need to
@@ -221,7 +222,8 @@
   mutable VersionTuple PlatformMinVersion;
 
   unsigned HasAlignMac68kSupport : 1;
-  unsigned RealTypeUsesObjCFPRetMask : (int)FloatModeKind::Last + 1;
+  unsigned RealTypeUsesObjCFPRetMask
+  : (int)FloatModeKind::LLVM_BITMASK_LARGEST_ENUMERATOR;
   unsigned ComplexLongDoubleUsesFP2Ret : 1;
 
   unsigned HasBuiltinMSVaList : 1;
@@ -890,9 +892,8 @@
   /// Check whether the given real type should use the "fpret" flavor of
   /// Objective-C message passing on this target.
   bool useObjCFPRetForRealType(FloatModeKind T) const {
-assert(T <= FloatModeKind::Last &&
-   "T value is larger than RealTypeUsesObjCFPRetMask can handle");
-return RealTypeUsesObjCFPRetMask & (1 << (int)T);
+int val = llvm::BitmaskEnumDetail::Underlying(T);
+return RealTypeUsesObjCFPRetMask & val;
   }
 
   /// Check whether _Complex long double should use the "fp2ret" flavor


Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
 
 #include "OSTargets.h"
+#include "clang/Basic/BitmaskEnum.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/Triple.h"
@@ -419,8 +420,8 @@
 
 // Use fpret for all types.
 RealTypeUsesObjCFPRetMask =
-((1 << (int)FloatModeKind::Float) | (1 << (int)FloatModeKind::Double) |
- (1 << (int)FloatModeKind::LongDouble));
+(int)(FloatModeKind::Float | FloatModeKind::Double |
+  FloatModeKind::LongDouble);
 
 // x86-32 has atomics up to 8 bytes
 MaxAtomicPromoteWidth = 64;
@@ -699,7 +700,7 @@
 "64-i64:64-f80:128-n8:16:32:64-S128");
 
 // Use fpret only for long double.
-RealTypeUsesObjCFPRetMask = (1 << (int)FloatModeKind::LongDouble);
+RealTypeUsesObjCFPRetMask = (int)FloatModeKind::LongDouble;
 
 // Use fp2ret for _Complex long double.
 ComplexLongDoubleUsesFP2Ret = true;
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_BASIC_TARGETINFO_H
 
 #include "clang/Basic/AddressSpaces.h"
+#include "clang/Basic/BitmaskEnum.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOpti

[PATCH] D128183: [clang][dataflow] Extend flow condition in the body of a do/while loop

2022-06-20 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev created this revision.
sgatev added reviewers: ymandel, xazax.hun, gribozavr2.
Herald added subscribers: martong, tschuett, rnkovacs.
Herald added a project: All.
sgatev requested review of this revision.
Herald added a project: clang.

Extend flow condition in the body of a do/while loop.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128183

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3628,25 +3628,77 @@
 void target(bool Foo) {
   while (Foo) {
 (void)0;
-// [[while_branch]]
+// [[loop_body]]
   }
+  (void)0;
+  // [[after_loop]]
 }
   )";
-  runDataflow(Code,
-  [](llvm::ArrayRef<
- std::pair>>
- Results,
- ASTContext &ASTCtx) {
-ASSERT_THAT(Results, ElementsAre(Pair("while_branch", _)));
-const Environment &Env = Results[0].second.Env;
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results,
+ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
+const Environment &LoopBodyEnv = Results[1].second.Env;
+const Environment &AfterLoopEnv = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
-ASSERT_THAT(FooDecl, NotNull());
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
 
-BoolValue &FooVal =
-*cast(Env.getValue(*FooDecl, SkipPast::None));
-EXPECT_TRUE(Env.flowConditionImplies(FooVal));
-  });
+BoolValue &LoopBodyFooVal =
+*cast(LoopBodyEnv.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(LoopBodyEnv.flowConditionImplies(LoopBodyFooVal));
+
+BoolValue &AfterLoopFooVal =
+*cast(AfterLoopEnv.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopFooVal)));
+  });
+}
+
+TEST_F(TransferTest, DoWhileStmtBranchExtendsFlowCondition) {
+  std::string Code = R"(
+void target(bool Foo) {
+  bool Bar = true;
+  do {
+(void)0;
+// [[loop_body]]
+Bar = false;
+  } while (Foo);
+  (void)0;
+  // [[after_loop]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results,
+ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
+const Environment &LoopBodyEnv = Results[1].second.Env;
+const Environment &AfterLoopEnv = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+BoolValue &LoopBodyFooVal =
+*cast(LoopBodyEnv.getValue(*FooDecl, SkipPast::None));
+BoolValue &LoopBodyBarVal =
+*cast(LoopBodyEnv.getValue(*BarDecl, SkipPast::None));
+EXPECT_TRUE(LoopBodyEnv.flowConditionImplies(
+LoopBodyEnv.makeOr(LoopBodyBarVal, LoopBodyFooVal)));
+
+BoolValue &AfterLoopFooVal =
+*cast(AfterLoopEnv.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopFooVal)));
+  });
 }
 
 TEST_F(TransferTest, ForStmtBranchExtendsFlowCondition) {
@@ -3654,25 +3706,34 @@
 void target(bool Foo) {
   for (; Foo;) {
 (void)0;
-// [[for_branch]]
+// [[loop_body]]
   }
+  (void)0;
+  // [[after_loop]]
 }
   )";
-  runDataflow(Code,
-  [](llvm::ArrayRef<
- std::pair>>
- Results,
- ASTContext &ASTCtx) {
-ASSERT_THAT(Results, ElementsAre(Pair("for_branch", _)));
-const Environment &Env = Results[0].second.Env;
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results,
+ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
+const Environment &LoopBodyEnv = Results[1].second.Env;
+const Environment &AfterLoopEnv = Results[0].second.Env;
 
- 

[PATCH] D127812: [AArch64] Function multiversioning support added.

2022-06-20 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added inline comments.



Comment at: clang/docs/ClangCommandLineReference.rst:1086
 
+.. option:: -mno-fmv
+

xbolva00 wrote:
> ilinpv wrote:
> > MaskRay wrote:
> > > This file is auto-generated. Don't touch it.
> > It looked out of sync with options td files:
> > 
> > ```
> > +.. option:: -gen-reproducer=, -fno-crash-diagnostics (equivalent to 
> > -gen-reproducer=off)
> > +
> > +Emit reproducer on (option: off, crash (default), error, always)
> > +
> > 
> > +.. option:: -print-diagnostic-options, --print-diagnostic-options
> > +
> > +Print all of Clang's warning options
> > +
> > 
> > +.. option:: -fdriver-only
> > +
> > +Only run the driver.
> > +
> > 
> > ...
> > ```
> But it needs to be manually autogenerated..
Done https://reviews.llvm.org/D128116, thanks to @MaskRay 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D128043: [flang][driver] Add support for `-O{0|1|2|3}`

2022-06-20 Thread Peixin Qiao via Phabricator via cfe-commits
peixin added a comment.

The CI failed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128043

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


[PATCH] D127655: [AArch64] Define __FP_FAST_FMA[F]

2022-06-20 Thread Jolanta Jensen via Phabricator via cfe-commits
jolanta.jensen updated this revision to Diff 438344.
jolanta.jensen added a comment.

Removing an unnecessary test change from aarch64-target-features.c 
as init-aarch64.c provides enough coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127655

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/test/Preprocessor/init-aarch64.c


Index: clang/test/Preprocessor/init-aarch64.c
===
--- clang/test/Preprocessor/init-aarch64.c
+++ clang/test/Preprocessor/init-aarch64.c
@@ -104,18 +104,20 @@
 // AARCH64-NEXT: #define __FLT_MIN_EXP__ (-125)
 // AARCH64-NEXT: #define __FLT_MIN__ 1.17549435e-38F
 // AARCH64-NEXT: #define __FLT_RADIX__ 2
+// AARCH64-NEXT: #define __FP_FAST_FMA 1
+// AARCH64-NEXT: #define __FP_FAST_FMAF 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
 // AARCH64_CXX-NEXT: #define __GLIBCXX_BITSIZE_INT_N_0 128
 // AARCH64_CXX-NEXT: #define __GLIBCXX_TYPE_INT_N_0 __int128
-// AARCH64-NEXT: #define __INT16_C_SUFFIX__ 
+// AARCH64-NEXT: #define __INT16_C_SUFFIX__
 // AARCH64-NEXT: #define __INT16_FMTd__ "hd"
 // AARCH64-NEXT: #define __INT16_FMTi__ "hi"
 // AARCH64-NEXT: #define __INT16_MAX__ 32767
 // AARCH64-NEXT: #define __INT16_TYPE__ short
-// AARCH64-NEXT: #define __INT32_C_SUFFIX__ 
+// AARCH64-NEXT: #define __INT32_C_SUFFIX__
 // AARCH64-NEXT: #define __INT32_FMTd__ "d"
 // AARCH64-NEXT: #define __INT32_FMTi__ "i"
 // AARCH64-NEXT: #define __INT32_MAX__ 2147483647
@@ -125,7 +127,7 @@
 // AARCH64-NEXT: #define __INT64_FMTi__ "li"
 // AARCH64-NEXT: #define __INT64_MAX__ 9223372036854775807L
 // AARCH64-NEXT: #define __INT64_TYPE__ long int
-// AARCH64-NEXT: #define __INT8_C_SUFFIX__ 
+// AARCH64-NEXT: #define __INT8_C_SUFFIX__
 // AARCH64-NEXT: #define __INT8_FMTd__ "hhd"
 // AARCH64-NEXT: #define __INT8_FMTi__ "hhi"
 // AARCH64-NEXT: #define __INT8_MAX__ 127
@@ -253,7 +255,7 @@
 // AARCH64-NEXT: #define __STDC_UTF_32__ 1
 // AARCH64_C: #define __STDC_VERSION__ 201710L
 // AARCH64-NEXT: #define __STDC__ 1
-// AARCH64-NEXT: #define __UINT16_C_SUFFIX__ 
+// AARCH64-NEXT: #define __UINT16_C_SUFFIX__
 // AARCH64-NEXT: #define __UINT16_FMTX__ "hX"
 // AARCH64-NEXT: #define __UINT16_FMTo__ "ho"
 // AARCH64-NEXT: #define __UINT16_FMTu__ "hu"
@@ -274,7 +276,7 @@
 // AARCH64-NEXT: #define __UINT64_FMTx__ "lx"
 // AARCH64-NEXT: #define __UINT64_MAX__ 18446744073709551615UL
 // AARCH64-NEXT: #define __UINT64_TYPE__ long unsigned int
-// AARCH64-NEXT: #define __UINT8_C_SUFFIX__ 
+// AARCH64-NEXT: #define __UINT8_C_SUFFIX__
 // AARCH64-NEXT: #define __UINT8_FMTX__ "hhX"
 // AARCH64-NEXT: #define __UINT8_FMTo__ "hho"
 // AARCH64-NEXT: #define __UINT8_FMTu__ "hhu"
@@ -344,7 +346,7 @@
 // AARCH64-NEXT: #define __UINT_LEAST8_FMTx__ "hhx"
 // AARCH64-NEXT: #define __UINT_LEAST8_MAX__ 255
 // AARCH64-NEXT: #define __UINT_LEAST8_TYPE__ unsigned char
-// AARCH64-NEXT: #define __USER_LABEL_PREFIX__ 
+// AARCH64-NEXT: #define __USER_LABEL_PREFIX__
 // AARCH64-NEXT: #define __VERSION__ "{{.*}}"
 // AARCH64-NEXT: #define __WCHAR_MAX__ 4294967295U
 // AARCH64-NEXT: #define __WCHAR_TYPE__ unsigned int
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -485,6 +485,10 @@
   Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
   Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
 
+  // Allow detection of fast FMA support.
+  Builder.defineMacro("__FP_FAST_FMA", "1");
+  Builder.defineMacro("__FP_FAST_FMAF", "1");
+
   if (Opts.VScaleMin && Opts.VScaleMin == Opts.VScaleMax) {
 Builder.defineMacro("__ARM_FEATURE_SVE_BITS", Twine(Opts.VScaleMin * 128));
 Builder.defineMacro("__ARM_FEATURE_SVE_VECTOR_OPERATORS");


Index: clang/test/Preprocessor/init-aarch64.c
===
--- clang/test/Preprocessor/init-aarch64.c
+++ clang/test/Preprocessor/init-aarch64.c
@@ -104,18 +104,20 @@
 // AARCH64-NEXT: #define __FLT_MIN_EXP__ (-125)
 // AARCH64-NEXT: #define __FLT_MIN__ 1.17549435e-38F
 // AARCH64-NEXT: #define __FLT_RADIX__ 2
+// AARCH64-NEXT: #define __FP_FAST_FMA 1
+// AARCH64-NEXT: #define __FP_FAST_FMAF 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
 // AARCH64_CXX-NEXT: #define __GLIBCXX_BITSIZE_INT_N_0 128
 // AARCH64_CXX-NEXT: #define __GLIBCXX_TYPE_INT_N_0 __int128
-// AARCH64-NEXT: #define __INT16_C_SUFFIX__ 
+// AARCH64-NEXT: #define __INT16_C_SUFF

[PATCH] D127856: [clangd] Support multiline semantic tokens

2022-06-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

(My first reaction was that this belongs in semanticHighlights() rather than 
toSemanticTokens, but I think you got it right - the single-line restriction is 
pretty unnatural from clang's point of view, and cuts across tokens generated 
in different places).




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:948
+} else {
+  // If a tokens length is past the end of the line, it should be treated 
as
+  // if the token ends at the end of the line and will not wrap onto the

This wording is hard for me to follow. I think it's saying:

"If the token spans a line break, truncate it to avoid this"



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:948
+} else {
+  // If a tokens length is past the end of the line, it should be treated 
as
+  // if the token ends at the end of the line and will not wrap onto the

sammccall wrote:
> This wording is hard for me to follow. I think it's saying:
> 
> "If the token spans a line break, truncate it to avoid this"
It seems it would be better to split into one token per line, rather than 
simply truncating.

Is truncation for simplicity or is there a reason to prefer it?

FWIW I think this wouldn't be too hard to implement if you reordered the 
tokenType/tokenModifiers above so this part is the last step, and just copied 
the whole SemanticToken object from the back of the Result. But on the other 
hand it's not terribly important, either.

At least I think we should have a comment for the truncate/split tradeoff.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.h:90
   uint32_t Modifiers = 0;
   Range R;
 

I think this deserves a comment like:

```
// This is clang's token bounds, which may span multiple lines.
// This may be split/truncated to a single line when required by LSP.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127856

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


[PATCH] D128043: [flang][driver] Add support for `-O{0|1|2|3}`

2022-06-20 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D128043#3596096 , @peixin wrote:

> The CI failed.

Thanks - I didn't notice any failures related to this change. Did I miss 
anything?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128043

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


[PATCH] D128043: [flang][driver] Add support for `-O{0|1|2|3}`

2022-06-20 Thread Peixin Qiao via Phabricator via cfe-commits
peixin added a comment.

OK. This seems not to be related to this patch. 
https://buildkite.com/llvm-project/premerge-checks/builds/98446#0181715d-812b-4d2a-b5d0-5c1283d78b5f
 I also see these failures in another review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128043

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


[clang-tools-extra] 541a50e - [clang-tidy] bugprone-argument-comment: Ignore calls to user-defined literals

2022-06-20 Thread Nathan James via cfe-commits

Author: Joachim Priesner
Date: 2022-06-20T13:30:30+01:00
New Revision: 541a50e20702a8046fe5076742611354cb6dd0f3

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

LOG: [clang-tidy] bugprone-argument-comment: Ignore calls to user-defined 
literals

Without this change, code such as "f(/*param=*/1_op)" will check the
comment twice, once for the parameter of f (correct) and once for
the parameter of operator""_op (likely incorrect). The change removes
only the second check.

Reviewed By: njames93, LegalizeAdulthood

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index 3836e4cf3990d..396b36d6e9afe 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -60,7 +60,7 @@ void 
ArgumentCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 
 void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  callExpr(unless(cxxOperatorCallExpr()),
+  callExpr(unless(cxxOperatorCallExpr()), unless(userDefinedLiteral()),
// NewCallback's arguments relate to the pointed function,
// don't check them against NewCallback's parameter names.
// FIXME: Make this configurable.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp
index d1f98bd0857bb..d576c187b101f 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp
@@ -29,7 +29,7 @@ void h(double b);
 void i(const char *c);
 void j(int a, int b, int c);
 
-double operator"" _km(long double);
+double operator"" _km(long double value);
 
 void test() {
   A a;
@@ -171,6 +171,8 @@ void test() {
   g((1));
   // FIXME But we should not add argument comments here.
   g(_Generic(0, int : 0));
+
+  402.0_km;
 }
 
 void f(bool _with_underscores_);



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


[PATCH] D125885: [clang-tidy] bugprone-argument-comment: Ignore calls to user-defined literals

2022-06-20 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG541a50e20702: [clang-tidy] bugprone-argument-comment: Ignore 
calls to user-defined literals (authored by jspam, committed by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125885

Files:
  clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp
@@ -29,7 +29,7 @@
 void i(const char *c);
 void j(int a, int b, int c);
 
-double operator"" _km(long double);
+double operator"" _km(long double value);
 
 void test() {
   A a;
@@ -171,6 +171,8 @@
   g((1));
   // FIXME But we should not add argument comments here.
   g(_Generic(0, int : 0));
+
+  402.0_km;
 }
 
 void f(bool _with_underscores_);
Index: clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -60,7 +60,7 @@
 
 void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  callExpr(unless(cxxOperatorCallExpr()),
+  callExpr(unless(cxxOperatorCallExpr()), unless(userDefinedLiteral()),
// NewCallback's arguments relate to the pointed function,
// don't check them against NewCallback's parameter names.
// FIXME: Make this configurable.


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-literals.cpp
@@ -29,7 +29,7 @@
 void i(const char *c);
 void j(int a, int b, int c);
 
-double operator"" _km(long double);
+double operator"" _km(long double value);
 
 void test() {
   A a;
@@ -171,6 +171,8 @@
   g((1));
   // FIXME But we should not add argument comments here.
   g(_Generic(0, int : 0));
+
+  402.0_km;
 }
 
 void f(bool _with_underscores_);
Index: clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -60,7 +60,7 @@
 
 void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  callExpr(unless(cxxOperatorCallExpr()),
+  callExpr(unless(cxxOperatorCallExpr()), unless(userDefinedLiteral()),
// NewCallback's arguments relate to the pointed function,
// don't check them against NewCallback's parameter names.
// FIXME: Make this configurable.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128190: [WinEH] Apply funclet operand bundles to nounwind intrinsics that lower to function calls

2022-06-20 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz created this revision.
sgraenitz added reviewers: rnk, theraven, DHowett-MSFT.
Herald added subscribers: jsji, pengfei, hiraditya.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

WinEHPrepare marks any function call from EH funclets as unreachable, if it's 
not a nounwind intrinsic and has no proper funclet bundle operand. This affects 
ARC intrinsics on Windows, because they are lowered to regular function calls 
in the PreISelIntrinsicLowering pass. It caused silent binary truncations and 
crashes during unwinding with the GNUstep ObjC runtime: 
https://github.com/gnustep/libobjc2/issues/222

This patch adds a new function `llvm::IntrinsicInst::mayLowerToFunctionCall()` 
that aims to collect all affected intrinsic IDs.

- Clang CodeGen uses it to determine whether or not it must emit a funclet 
bundle operand.
- PreISelIntrinsicLowering asserts that the function returns true for all ObjC 
runtime calls it lowers.
- LLVM uses it to determine whether or not a funclet bundle operand must be 
propagated to inlined call sites.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128190

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenObjCXX/arc-exceptions-seh.mm
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
  llvm/lib/IR/IntrinsicInst.cpp
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/CodeGen/X86/win64-funclet-preisel-intrinsics.ll
  llvm/test/Feature/OperandBundles/inliner-funclet-wineh.ll

Index: llvm/test/Feature/OperandBundles/inliner-funclet-wineh.ll
===
--- /dev/null
+++ llvm/test/Feature/OperandBundles/inliner-funclet-wineh.ll
@@ -0,0 +1,55 @@
+; RUN: opt -S -always-inline -mtriple=x86_64-windows-msvc < %s | FileCheck %s
+
+; WinEH doesn't require funclet tokens on nounwind intrinsics per se. ObjC++ ARC
+; intrinsics are a special case, because they are subject to pre-ISel lowering.
+; They appear as regular function calls for subsequent passes, like WinEHPrepare
+; which would consider them implausible instrucitons and mark them unreachable.
+; Affected EH funclets would get truncated silently, which causes unpredictable
+; crashes at runtime.
+;
+; Thus, when we target WinEH and generate calls to pre-ISel intrinsics from EH
+; funclets, we emit funclet tokens explicitly.
+;
+; The inliner has to propagate funclet tokens to such intrinsics, if they get
+; inlined into EH funclets.
+
+define void @inlined_fn(ptr %ex) #1 {
+entry:
+  call void @llvm.objc.storeStrong(ptr %ex, ptr null)
+  ret void
+}
+
+define void @test_catch_with_inline() personality ptr @__CxxFrameHandler3 {
+entry:
+  %exn.slot = alloca ptr, align 8
+  %ex = alloca ptr, align 8
+  invoke void @opaque() to label %invoke.cont unwind label %catch.dispatch
+
+catch.dispatch:
+  %0 = catchswitch within none [label %catch] unwind to caller
+
+invoke.cont:
+  unreachable
+
+catch:
+  %1 = catchpad within %0 [ptr null, i32 64, ptr %exn.slot]
+  call void @inlined_fn(ptr %ex) [ "funclet"(token %1) ]
+  catchret from %1 to label %catchret.dest
+
+catchret.dest:
+  ret void
+}
+
+declare void @opaque()
+declare void @llvm.objc.storeStrong(ptr, ptr) #0
+declare i32 @__CxxFrameHandler3(...)
+
+attributes #0 = { nounwind }
+attributes #1 = { alwaysinline }
+
+; CHECK-LABEL:  define void @test_catch_with_inline()
+; ...
+; CHECK:catch:
+; CHECK-NEXT: %1 = catchpad within %0 [ptr null, i32 64, ptr %exn.slot]
+; CHECK-NEXT: call void @llvm.objc.storeStrong(ptr %ex, ptr null) [ "funclet"(token %1) ]
+; CHECK-NEXT: catchret from %1 to label %catchret.dest
Index: llvm/test/CodeGen/X86/win64-funclet-preisel-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/win64-funclet-preisel-intrinsics.ll
@@ -0,0 +1,68 @@
+; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
+
+; Reduced IR generated from ObjC++ source:
+;
+; @class Ety;
+; void opaque(void);
+; void test_catch(void) {
+;   @try {
+; opaque();
+;   } @catch (Ety *ex) {
+; // Destroy ex when leaving catchpad. This emits calls to two intrinsic
+; // functions, llvm.objc.retain and llvm.objc.storeStrong, but only one
+; // is required to trigger the funclet truncation.
+;   }
+; }
+
+define void @test_catch() personality ptr @__CxxFrameHandler3 {
+entry:
+  %exn.slot = alloca ptr, align 8
+  %ex2 = alloca ptr, align 8
+  invoke void @opaque() to label %invoke.cont unwind label %catch.dispatch
+
+catch.dispatch:
+  %0 = catchswitch within none [label %catch] unwind to caller
+
+invoke.cont:
+  unreachable
+
+catch:
+  %1 = catchpad within %0 [ptr null, i32 64, ptr %exn.slot]
+  call void @llvm.objc.storeStrong(ptr %ex2, ptr null) [ "funclet"(token %1) ]
+  catchret from %1 to label %c

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

2022-06-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Apologies for not getting to this before vacation, and thanks Nathan for 
looking at this. (I'll leave for you to stamp)

This is fine with me as-is, but I think this mapping shouldn't be our 
*preferred* way to solve this problem, and should eventually go away.

We also have a mapping of **symbol** names to headers (StdSymbols.inc). This is 
obviously more portable, both in the sense that it works when editing using 
e.g. MS STL etc, and that the results don't reflect quirks of the stdlib you're 
using.
The reason this mapping fails for `std::ranges::transform` is that the mapping 
file was extracted from an old C++17 cppreference dump. The cppreference format 
has changed so to run it on a newer dump it'd need some updates.




Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.cpp:197
   {"bits/basic_string.tcc", ""},
+  {"bits/boost_concept_check.h", ""},
   {"bits/char_traits.h", ""},

nridge wrote:
> The choice of `` is pretty random here, as is already the case for 
> `bits/concept_check.h`.
> 
> Given that these headers don't declare any standard symbols, only symbols 
> which are pure libstdc++ implementation details, maybe we should just omit 
> them from the list?
< Given that these headers don't declare any standard symbols, only symbols 
which are pure libstdc++ implementation details, maybe we should just omit them 
from the list?

+1


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] D126461: [RISCV] Extract and store new vl of vleff/vlsegff iff destination isn't null

2022-06-20 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead added a comment.

Ping. Any comments?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126461

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


[PATCH] D122385: [clang][deps] Fix clang-cl output argument parsing

2022-06-20 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 438367.
jansvoboda11 added a comment.

Code review feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122385

Files:
  clang/test/ClangScanDeps/cl-output.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -462,27 +462,31 @@
   llvm::sys::path::stem(Args[0]).contains_insensitive("clang-cl") ||
   llvm::is_contained(Args, "--driver-mode=cl");
 
-  // Reverse scan, starting at the end or at the element before "--".
-  auto R = std::make_reverse_iterator(FlagsEnd);
-  for (auto I = R, E = Args.rend(); I != E; ++I) {
+  for (auto I = Args.begin(); I < FlagsEnd; ++I) {
 StringRef Arg = *I;
 if (ClangCLMode) {
   // Ignore arguments that are preceded by "-Xclang".
-  if ((I + 1) != E && I[1] == "-Xclang")
+  if (Arg == "-Xclang") {
+++I;
 continue;
-  if (LastO.empty()) {
-// With clang-cl, the output obj file can be specified with
-// "/opath", "/o path", "/Fopath", and the dash counterparts.
-// Also, clang-cl adds ".obj" extension if none is found.
-if ((Arg == "-o" || Arg == "/o") && I != R)
-  LastO = I[-1]; // Next argument (reverse iterator)
-else if (Arg.startswith("/Fo") || Arg.startswith("-Fo"))
-  LastO = Arg.drop_front(3).str();
-else if (Arg.startswith("/o") || Arg.startswith("-o"))
-  LastO = Arg.drop_front(2).str();
-
-if (!LastO.empty() && !llvm::sys::path::has_extension(LastO))
-  LastO.append(".obj");
+  }
+
+  // With clang-cl, the output obj file can be specified with
+  // "/opath", "/o path", "/Fopath", and the dash counterparts.
+  // Also, clang-cl adds ".obj" extension if none is found.
+  StringRef CurrentO;
+  if ((Arg == "/o" || Arg == "-o") && I + 1 < FlagsEnd)
+CurrentO = *++I;
+  else if (Arg.startswith("/Fo") || Arg.startswith("-Fo"))
+CurrentO = Arg.drop_front(3);
+  else if (Arg.startswith("/o") || Arg.startswith("-o"))
+CurrentO = Arg.drop_front(2);
+
+  if (!CurrentO.empty()) {
+if (!llvm::sys::path::has_extension(CurrentO))
+  LastO = (CurrentO + ".obj").str();
+else
+  LastO = CurrentO.str();
   }
 }
 if (Arg == "-resource-dir")
Index: clang/test/ClangScanDeps/cl-output.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/cl-output.c
@@ -0,0 +1,93 @@
+// This test checks that the output path is correctly deduced/recognized in clang-cl mode.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- deduce-cdb.json.template
+[{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang --driver-mode=cl /c -- DIR/test.c"
+},{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c -- DIR/test.c"
+}]
+
+//--- recognize-cdb.json.template
+[{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c -o DIR/test.o -- DIR/test.c"
+},{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c /o DIR/test.o -- DIR/test.c"
+},{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c -oDIR/test.o -- DIR/test.c"
+},{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c /oDIR/test.o -- DIR/test.c"
+},{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c -FoDIR/test.o -- DIR/test.c"
+},{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c /FoDIR/test.o -- DIR/test.c"
+}]
+
+//--- last-arg-cdb.json.template
+[{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c -o DIR/test.o -o DIR/last.o -- DIR/test.c"
+},{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c /o /opt/test.o -- DIR/test.c"
+}]
+
+//--- test.c
+
+// Check that missing output path is deduced (with both clang-cl executable and driver mode flag):
+//
+// RUN: sed -e "s|DIR|%/t|g" %t/deduce-cdb.json.template > %t/deduce-cdb.json
+// RUN: clang-scan-deps -compilation-database %t/deduce-cdb.json -j 1 > %t/deduce-result.d
+// RUN: cat %t/deduce-result.d | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix=CHECK-DEDUCE
+// CHECK-DEDUCE:  test.obj:
+// CHECK-DEDUCE-NEXT:   [[PREFIX]]/test.c
+// CHECK-DEDUCE-NEXT: test.obj:
+// CHECK-DEDUC

[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-06-20 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

I've left one minor comment. My other suggestion would be to absorb in the 
semantic restrictions work from here 
.




Comment at: llvm/lib/IR/Type.cpp:307
 
+Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
+  // pointer to opaque struct in addrspace(10)

With the move to opaque pointers, I think this and getWasm_FuncRefTy could be 
updated to just return a pointer to addrspace 10 and 20 respectively?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

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


[PATCH] D127246: [LinkerWrapper] Rework the linker wrapper and use owning binaries

2022-06-20 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

Is anyone up to review this? I'm mostly looking for some feedback on the 
interfaces I've built. If no one has time to look into it I can probably just 
land without review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127246

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


[PATCH] D127363: [Lex] Fix for char32_t literal truncation on 16 bit architectures

2022-06-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/lib/Lex/LiteralSupport.cpp:1600
 
-  llvm::APInt LitVal(PP.getTargetInfo().getIntWidth(), 0);
+  llvm::APInt LitVal(PP.getTargetInfo().getChar32Width(), 0);
 

tahonermann wrote:
> I don't think this is quite right. For the code that follows this change to 
> work as intended and issue the "Character constant too long for its type" 
> diagnostic, the width needs to match that of `int`. This is required for 
> multicharacter literals (they have type `int`) so that an appropriate 
> diagnostic is issued for `'x'` for targets that have a 32-bit int (or for 
> `'xxx'` for targets that have a 16-bit int)`.
> 
> Additionally, the type of a character constant in C is `int`.
> 
> I think what is needed is something like:
>   unsigned BitWidth = getCharWidth(Kind, PP.getTargetInfo());
>   if (IsMultiChar || !PP.getLangOpts().CPlusPlus)
> BitWidth = PP.getTargetInfo().getIntWidth();
>   llvm::APInt LitVal(BitWidth, 0);
Thanks for pointing this out.

My reading of https://eel.is/c++draft/lex.ccon#2 is that a multi-char char 
literal with a L/u8/u/U prefix is not `int` but the respective character types, 
so the conditions here are even a little *more* complicated than you suggest :-(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127363

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


[PATCH] D128197: [clangd] Handle initializers that contain =

2022-06-20 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128197

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -116,6 +116,11 @@
   "void foo(int x, int y = 5, int = 2, int (*foo)(int) = nullptr) ;",
   "void foo(int x, int y , int , int (*foo)(int) ) {}",
   },
+  {
+  "struct Bar{Bar();}; void fo^o(Bar x = {}) {}",
+  "struct Bar{Bar();}; void foo(Bar x = {}) ;",
+  "void foo(Bar x ) {}",
+  },
   // Constructors
   {
   R"cpp(
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -187,26 +187,30 @@
   // Get rid of default arguments, since they should not be specified in
   // out-of-line definition.
   for (const auto *PVD : FD->parameters()) {
-if (PVD->hasDefaultArg()) {
-  // Deletion range initially spans the initializer, excluding the `=`.
-  auto DelRange = 
CharSourceRange::getTokenRange(PVD->getDefaultArgRange());
-  // Get all tokens before the default argument.
-  auto Tokens = TokBuf.expandedTokens(PVD->getSourceRange())
-.take_while([&SM, &DelRange](const syntax::Token &Tok) 
{
-  return SM.isBeforeInTranslationUnit(
-  Tok.location(), DelRange.getBegin());
-});
-  // Find the last `=` before the default arg.
+if (!PVD->hasDefaultArg())
+  continue;
+// Deletion range initially spans the initializer, excluding the `=`.
+auto DelRange = CharSourceRange::getTokenRange(PVD->getDefaultArgRange());
+// Get all tokens before the default argument.
+auto Tokens = TokBuf.expandedTokens(PVD->getSourceRange())
+  .take_while([&SM, &DelRange](const syntax::Token &Tok) {
+return SM.isBeforeInTranslationUnit(
+Tok.location(), DelRange.getBegin());
+  });
+if (TokBuf.expandedTokens(DelRange.getAsRange()).front().kind() !=
+tok::equal) {
+  // Find the last `=` if it isn't included in the initializer, and update
+  // the DelRange to include it.
   auto Tok =
   llvm::find_if(llvm::reverse(Tokens), [](const syntax::Token &Tok) {
 return Tok.kind() == tok::equal;
   });
   assert(Tok != Tokens.rend());
   DelRange.setBegin(Tok->location());
-  if (auto Err =
-  DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
-Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
 }
+if (auto Err =
+DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
+  Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
   }
 
   auto DelAttr = [&](const Attr *A) {


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -116,6 +116,11 @@
   "void foo(int x, int y = 5, int = 2, int (*foo)(int) = nullptr) ;",
   "void foo(int x, int y , int , int (*foo)(int) ) {}",
   },
+  {
+  "struct Bar{Bar();}; void fo^o(Bar x = {}) {}",
+  "struct Bar{Bar();}; void foo(Bar x = {}) ;",
+  "void foo(Bar x ) {}",
+  },
   // Constructors
   {
   R"cpp(
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -187,26 +187,30 @@
   // Get rid of default arguments, since they should not be specified in
   // out-of-line definition.
   for (const auto *PVD : FD->parameters()) {
-if (PVD->hasDefaultArg()) {
-  // Deletion range initially spans the initializer, excluding the `=`.
-  auto DelRange = CharSourceRange::getTokenRange(PVD->getDefaultArgRange());
-  // Get all tokens before the default argument.
-  auto Tokens = TokBu

[PATCH] D128197: [clangd] Handle initializers that contain =

2022-06-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:192
+  continue;
+// Deletion range initially spans the initializer, excluding the `=`.
+auto DelRange = CharSourceRange::getTokenRange(PVD->getDefaultArgRange());

nit: usually excluding the `=`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128197

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


[PATCH] D128119: [clang] enforce instantiation of constexpr template functions

2022-06-20 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

This also seems to fix https://github.com/llvm/llvm-project/issues/37522 and 
https://github.com/llvm/llvm-project/issues/55315


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

https://reviews.llvm.org/D128119

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


[PATCH] D125728: [WebAssembly] Update supported features in -mcpu=generic

2022-06-20 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

One thing that's not ideal about this test case is that it still passes if you 
delete the changes to WebAssembly.cpp. At least for RISC-V, selecting the -mcpu 
also emits the relevant `-target-feature +foo` for features supported by that 
CPU, which doesn't seem to happen here. Haven't been able to trace through to 
see if that's due to us doing something obviously different in the RISC-V case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125728

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


[PATCH] D128202: [clangd] Include "final" when printing class declaration

2022-06-20 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
tom-anders requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added projects: clang, clang-tools-extra.

Fixes https://github.com/clangd/clangd/issues/1184


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128202

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/AST/DeclPrinter.cpp


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -1007,6 +1007,10 @@
 }
   }
 
+  if (D->isEffectivelyFinal()) {
+  Out << " final";
+  }
+
   if (D->isCompleteDefinition()) {
 // Print the base classes
 if (D->getNumBases()) {
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -198,7 +198,7 @@
 typename = char,
 int = 0,
 bool Q = false,
-class... Ts> class Foo {};
+class... Ts> class Foo final {};
   template  class T>
   [[F^oo]] foo;
   )cpp",
@@ -209,7 +209,7 @@
  HI.Definition =
  R"cpp(template  class C, typename = 
char, int = 0,
   bool Q = false, class... Ts>
-class Foo {})cpp";
+class Foo final {})cpp";
  HI.TemplateParameters = {
  {{"template  class"},
   std::string("C"),


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -1007,6 +1007,10 @@
 }
   }
 
+  if (D->isEffectivelyFinal()) {
+  Out << " final";
+  }
+
   if (D->isCompleteDefinition()) {
 // Print the base classes
 if (D->getNumBases()) {
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -198,7 +198,7 @@
 typename = char,
 int = 0,
 bool Q = false,
-class... Ts> class Foo {};
+class... Ts> class Foo final {};
   template  class T>
   [[F^oo]] foo;
   )cpp",
@@ -209,7 +209,7 @@
  HI.Definition =
  R"cpp(template  class C, typename = char, int = 0,
   bool Q = false, class... Ts>
-class Foo {})cpp";
+class Foo final {})cpp";
  HI.TemplateParameters = {
  {{"template  class"},
   std::string("C"),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105494: [clang] Introduce a union inside ProgramPoint.

2022-06-20 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.
Herald added a project: All.

This change looks fine to me (though clang-format wants a reasonable change). 
I'm not familiar with the clang static analyzer, so I'm not sure I can +2 this, 
but hopefully this message will act as a ping for the existing reviewers?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105494

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


[PATCH] D128202: [clangd] Include "final" when printing class declaration

2022-06-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/lib/AST/DeclPrinter.cpp:1010
 
+  if (D->isEffectivelyFinal()) {
+  Out << " final";

isEffectivelyFinal returns true for
`struct X { ~X() final; }`

I don't think we want to print `struct X final {}` in that case.

Probably want to replicate the check for FinalAttr instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128202

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


[PATCH] D126559: [MSVC] Fix pragma alloc_text failing for C files

2022-06-20 Thread Stephen Long via Phabricator via cfe-commits
steplong added a comment.

Hmm, it looks like MSVC is accepting:

  extern "C" {
  static void foo();
  }
  
  static int foo();
  #pragma alloc_text("s", foo)
  static void foo() {}

Ignoring the `pragma alloc_text`, it looks like GCC compiles the following 
`foo` with C linkage vs LLVM which compiles with C++ linkage (foo's name is 
mangled):

  extern "C" {
  static int foo();
  }
  
  static int foo();
  static int foo() {
return 3;
  }
  
  int bar() {
return foo();
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126559

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


[PATCH] D128202: [clangd] Include "final" when printing class declaration

2022-06-20 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added inline comments.



Comment at: clang/lib/AST/DeclPrinter.cpp:1010
 
+  if (D->isEffectivelyFinal()) {
+  Out << " final";

sammccall wrote:
> isEffectivelyFinal returns true for
> `struct X { ~X() final; }`
> 
> I don't think we want to print `struct X final {}` in that case.
> 
> Probably want to replicate the check for FinalAttr instead?
Agreed. Would probably make sense to add a `bool hasFinalAttribute() const` to 
`CXXRecordDecl`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128202

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


[PATCH] D128204: [clangd] Add fix-it for inserting IWYU pragma: keep

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

Since IncludeCleaner has some support for IWYU keep pragmas, we can suggest it 
as a fix-it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128204

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1792,7 +1792,7 @@
 
 TEST(DiagnosticsTest, IncludeCleaner) {
   Annotations Test(R"cpp(
-$fix[[  $diag[[#include "unused.h"]]
+$fix[[  $diag[[#include "unused.h"]]$insert[[]]
 ]]
   #include "used.h"
 
@@ -1831,11 +1831,13 @@
   auto AST = TU.build();
   EXPECT_THAT(
   *AST.getDiagnostics(),
-  UnorderedElementsAre(AllOf(
-  Diag(Test.range("diag"),
-   "included header unused.h is not used directly"),
-  withTag(DiagnosticTag::Unnecessary), diagSource(Diag::Clangd),
-  withFix(Fix(Test.range("fix"), "", "remove #include directive");
+  UnorderedElementsAre(
+  AllOf(Diag(Test.range("diag"),
+ "included header unused.h is not used directly"),
+withTag(DiagnosticTag::Unnecessary), diagSource(Diag::Clangd),
+withFix(Fix(Test.range("fix"), "", "remove #include 
directive"),
+Fix(Test.range("insert"), " // IWYU pragma: keep",
+"add pragma keep directive");
   auto &Diag = AST.getDiagnostics()->front();
   EXPECT_EQ(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
 std::string("https://clangd.llvm.org/guides/include-cleaner";));
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -506,6 +506,13 @@
 D.Fixes.back().Edits.emplace_back();
 D.Fixes.back().Edits.back().range.start.line = Inc->HashLine;
 D.Fixes.back().Edits.back().range.end.line = Inc->HashLine + 1;
+// Add a fix to append IWYU pragma: keep
+D.Fixes.emplace_back();
+D.Fixes.back().Message = "add pragma keep directive";
+D.Fixes.back().Edits.emplace_back();
+D.Fixes.back().Edits.back().newText = " // IWYU pragma: keep";
+D.Fixes.back().Edits.back().range.start =
+D.Fixes.back().Edits.back().range.end = D.Range.end;
 D.InsideMainFile = true;
 Result.push_back(std::move(D));
   }


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1792,7 +1792,7 @@
 
 TEST(DiagnosticsTest, IncludeCleaner) {
   Annotations Test(R"cpp(
-$fix[[  $diag[[#include "unused.h"]]
+$fix[[  $diag[[#include "unused.h"]]$insert[[]]
 ]]
   #include "used.h"
 
@@ -1831,11 +1831,13 @@
   auto AST = TU.build();
   EXPECT_THAT(
   *AST.getDiagnostics(),
-  UnorderedElementsAre(AllOf(
-  Diag(Test.range("diag"),
-   "included header unused.h is not used directly"),
-  withTag(DiagnosticTag::Unnecessary), diagSource(Diag::Clangd),
-  withFix(Fix(Test.range("fix"), "", "remove #include directive");
+  UnorderedElementsAre(
+  AllOf(Diag(Test.range("diag"),
+ "included header unused.h is not used directly"),
+withTag(DiagnosticTag::Unnecessary), diagSource(Diag::Clangd),
+withFix(Fix(Test.range("fix"), "", "remove #include directive"),
+Fix(Test.range("insert"), " // IWYU pragma: keep",
+"add pragma keep directive");
   auto &Diag = AST.getDiagnostics()->front();
   EXPECT_EQ(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
 std::string("https://clangd.llvm.org/guides/include-cleaner";));
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -506,6 +506,13 @@
 D.Fixes.back().Edits.emplace_back();
 D.Fixes.back().Edits.back().range.start.line = Inc->HashLine;
 D.Fixes.back().Edits.back().range.end.line = Inc->HashLine + 1;
+// Add a fix to append IWYU pragma: keep
+D.Fixes.emplace_back();
+D.Fixes.back().Message = "add pragma keep directive";
+D.Fixes.back().Edits.emplace_back();
+D.Fix

[PATCH] D128206: [Clang] Allow multiple comma separated arguments to `--offload-arch=`

2022-06-20 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: tra, yaxunl, jdoerfert, JonChesterfield, ye-luo.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, MaskRay.
Herald added a project: clang.

This patch updates the `--[no-]offload-arch` command line arguments to
allow the user to pass in many architectures in a single argument rather
than specifying it multiple times. This means that the following command
line,

  clang foo.cu --offload-arch=sm_70 --offload-arch=sm_80

can become:

  clang foo.cu --offload-arch=sm_70,sm_80


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128206

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/cuda-bindings.cu
  clang/test/Driver/openmp-offload-gpu-new.c


Index: clang/test/Driver/openmp-offload-gpu-new.c
===
--- clang/test/Driver/openmp-offload-gpu-new.c
+++ clang/test/Driver/openmp-offload-gpu-new.c
@@ -51,6 +51,8 @@
 // CHECK-TEMP-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Packager", 
inputs: ["[[DEVICE_OBJ:.+]]"], output: "[[BINARY:.+.out]]"
 
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda --offload-arch=sm_52 
--offload-arch=sm_70 -nogpulib %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-ARCH-BINDINGS
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda --offload-arch=sm_52,sm_70 
-nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-ARCH-BINDINGS
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda 
--offload-arch=sm_52,sm_70,sm_35,sm_80 --no-offload-arch=sm_35,sm_80 -nogpulib 
%s 2>&1 | FileCheck %s --check-prefix=CHECK-ARCH-BINDINGS
 // CHECK-ARCH-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[INPUT:.*]]"], output: "[[HOST_BC:.*]]"
 // CHECK-ARCH-BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]", 
"[[HOST_BC]]"], output: "[[DEVICE_BC_SM_52:.*]]"
 // CHECK-ARCH-BINDINGS: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: 
["[[DEVICE_BC_SM_52]]"], output: "[[DEVICE_OBJ_SM_52:.*]]"
Index: clang/test/Driver/cuda-bindings.cu
===
--- clang/test/Driver/cuda-bindings.cu
+++ clang/test/Driver/cuda-bindings.cu
@@ -40,6 +40,7 @@
 // Test two gpu architectures with complete compilation.
 //
 // RUN: %clang -target powerpc64le-ibm-linux-gnu -ccc-print-bindings 
--cuda-gpu-arch=sm_30 --cuda-gpu-arch=sm_35 %s 2>&1 \
+// RUN: %clang -target powerpc64le-ibm-linux-gnu -ccc-print-bindings 
--offload-arch=sm_30,sm_35 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=BIN2 %s
 // BIN2: # "nvptx64-nvidia-cuda" - "clang",{{.*}} output:
 // BIN2-NOT: cuda-bindings-device-cuda-nvptx64
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2973,7 +2973,7 @@
  << "--offload";
   }
 
-  // Collect all cuda_gpu_arch parameters, removing duplicates.
+  // Collect all offload arch parameters, removing duplicates.
   std::set GpuArchs;
   bool Error = false;
   for (Arg *A : Args) {
@@ -2982,21 +2982,22 @@
   continue;
 A->claim();
 
-StringRef ArchStr = A->getValue();
-if (A->getOption().matches(options::OPT_no_offload_arch_EQ) &&
-ArchStr == "all") {
-  GpuArchs.clear();
-  continue;
+for (StringRef ArchStr : llvm::split(A->getValue(), ",")) {
+  if (A->getOption().matches(options::OPT_no_offload_arch_EQ) &&
+  ArchStr == "all") {
+GpuArchs.clear();
+  } else {
+ArchStr = getCanonicalOffloadArch(ArchStr);
+if (ArchStr.empty()) {
+  Error = true;
+} else if (A->getOption().matches(options::OPT_offload_arch_EQ))
+  GpuArchs.insert(ArchStr);
+else if (A->getOption().matches(options::OPT_no_offload_arch_EQ))
+  GpuArchs.erase(ArchStr);
+else
+  llvm_unreachable("Unexpected option.");
+  }
 }
-ArchStr = getCanonicalOffloadArch(ArchStr);
-if (ArchStr.empty()) {
-  Error = true;
-} else if (A->getOption().matches(options::OPT_offload_arch_EQ))
-  GpuArchs.insert(ArchStr);
-else if (A->getOption().matches(options::OPT_no_offload_arch_EQ))
-  GpuArchs.erase(ArchStr);
-else
-  llvm_unreachable("Unexpected option.");
   }
 
   auto &&ConflictingArchs = getConflictOffloadArchCombination(GpuArchs);
@@ -4356,14 +4357,15 @@
   llvm::DenseSet Archs;
   for (auto &Arg : Args) {
 if (Arg->getOption().matches(options::OPT_offload_arch_EQ)) {

[PATCH] D128206: [Clang] Allow multiple comma separated arguments to `--offload-arch=`

2022-06-20 Thread Ye Luo via Phabricator via cfe-commits
ye-luo accepted this revision.
ye-luo added a comment.
This revision is now accepted and ready to land.

LGTM. This allows me to write concise compile lines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128206

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


[PATCH] D128207: [clang-doc][NFC] Fix reference invalidation assertion failure.

2022-06-20 Thread liushuai wang via Phabricator via cfe-commits
MTC created this revision.
MTC added reviewers: dexonsmith, mehdi_amini.
MTC added a project: clang-tools-extra.
Herald added subscribers: jsji, usaxena95, pengfei, kadircet, arphaman.
Herald added a project: All.
MTC requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.

Fix the assertion failure caused by reference invalidation in `SmallString`. It 
seems that this bug was not caught when adding the assertion, see 
https://reviews.llvm.org/D91744.

We can reproduce this bug trivially through the following usage.

  $ clang-doc  --format=html test.cpp
  Emiting docs in html format.
  clang-doc: llvm-project/llvm/include/llvm/ADT/SmallVector.h:173: void 
llvm::SmallVectorTemplateCommon 
>::assertSafeToReferenceAfterResize(const void*, size_t) [with T = char; 
 = void; size_t = long unsigned int]: Assertion 
`isSafeToReferenceAfterResize(Elt, NewSize) && "Attempting to reference an 
element of the vector in an operation " "that invalidates it"' failed.
   #0 0x55ce4806b843 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
llvm-project/llvm/lib/Support/Unix/Signals.inc:569:22
   #1 0x55ce4806b8fa PrintStackTraceSignalHandler(void*) 
llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
   #2 0x55ce4806989a llvm::sys::RunSignalHandlers() 
llvm-project/llvm/lib/Support/Signals.cpp:103:20
   #3 0x55ce4806b277 SignalHandler(int) 
llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
   #4 0x7f72a4533730 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12730)
   #5 0x7f72a3e1a7bb raise 
/build/glibc-fWwxX8/glibc-2.28/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
   #6 0x7f72a3e05535 abort 
/build/glibc-fWwxX8/glibc-2.28/stdlib/abort.c:81:7
   #7 0x7f72a3e0540f _nl_load_domain 
/build/glibc-fWwxX8/glibc-2.28/intl/loadmsgcat.c:1177:9
   #8 0x7f72a3e13102 (/lib/x86_64-linux-gnu/libc.so.6+0x30102)
   #9 0x55ce47f76f1a llvm::SmallVectorTemplateCommon::assertSafeToReferenceAfterResize(void const*, unsigned long) 
llvm-project/llvm/include/llvm/ADT/SmallVector.h:171:5
  #10 0x55ce47f79efc llvm::SmallVectorTemplateCommon::assertSafeToReferenceAfterClear(char const*, char const*) 
llvm-project/llvm/include/llvm/ADT/SmallVector.h:187:47
  #11 0x55ce47f743ed void llvm::SmallVectorImpl::assign(char const*, char const*) 
llvm-project/llvm/include/llvm/ADT/SmallVector.h:713:5
  #12 0x55ce47f6c587 llvm::SmallString<128u>::assign(llvm::StringRef) 
llvm-project/llvm/include/llvm/ADT/SmallString.h:53:3
  #13 0x55ce47f64338 llvm::SmallString<128u>::operator=(llvm::StringRef) 
llvm-project/llvm/include/llvm/ADT/SmallString.h:279:13
  #14 0x55ce47f4ab4c main 
llvm-project/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:226:28
  #15 0x7f72a3e0709b __libc_start_main 
/build/glibc-fWwxX8/glibc-2.28/csu/../csu/libc-start.c:342:3
  #16 0x55ce47f4963a _start (./bin/clang-doc+0x54563a)
  [1]1443196 abort (core dumped)  ./bin/clang-doc --format=html test.cpp


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D128207

Files:
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -222,7 +222,7 @@
 std::string ClangDocPath = GetExecutablePath(argv[0], MainAddr);
 llvm::SmallString<128> AssetsPath;
 llvm::sys::path::native(ClangDocPath, AssetsPath);
-AssetsPath = llvm::sys::path::parent_path(AssetsPath);
+AssetsPath = std::string(llvm::sys::path::parent_path(AssetsPath));
 llvm::sys::path::append(AssetsPath, "..", "share", "clang");
 llvm::SmallString<128> DefaultStylesheet;
 llvm::sys::path::native(AssetsPath, DefaultStylesheet);


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -222,7 +222,7 @@
 std::string ClangDocPath = GetExecutablePath(argv[0], MainAddr);
 llvm::SmallString<128> AssetsPath;
 llvm::sys::path::native(ClangDocPath, AssetsPath);
-AssetsPath = llvm::sys::path::parent_path(AssetsPath);
+AssetsPath = std::string(llvm::sys::path::parent_path(AssetsPath));
 llvm::sys::path::append(AssetsPath, "..", "share", "clang");
 llvm::SmallString<128> DefaultStylesheet;
 llvm::sys::path::native(AssetsPath, DefaultStylesheet);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127856: [clangd] Support multiline semantic tokens

2022-06-20 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 438387.
kadircet added a comment.

Split highlights into multiple tokens rather than trimming


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127856

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -944,7 +944,7 @@
   )");
   Tokens.front().Modifiers |= unsigned(HighlightingModifier::Declaration);
   Tokens.front().Modifiers |= unsigned(HighlightingModifier::Readonly);
-  auto Results = toSemanticTokens(Tokens);
+  auto Results = toSemanticTokens(Tokens, /*Code=*/"");
 
   ASSERT_THAT(Results, SizeIs(3));
   EXPECT_EQ(Results[0].tokenType, unsigned(HighlightingKind::Variable));
@@ -972,13 +972,15 @@
   auto Before = toSemanticTokens(tokens(R"(
 [[foo]] [[bar]] [[baz]]
 [[one]] [[two]] [[three]]
-  )"));
+  )"),
+ /*Code=*/"");
   EXPECT_THAT(diffTokens(Before, Before), IsEmpty());
 
   auto After = toSemanticTokens(tokens(R"(
 [[foo]] [[hello]] [[world]] [[baz]]
 [[one]] [[two]] [[three]]
-  )"));
+  )"),
+/*Code=*/"");
 
   // Replace [bar, baz] with [hello, world, baz]
   auto Diff = diffTokens(Before, After);
@@ -1000,6 +1002,30 @@
   EXPECT_EQ(3u, Diff.front().tokens[2].length);
 }
 
+TEST(SemanticHighlighting, MultilineTokens) {
+  llvm::StringRef AnnotatedCode = R"cpp(
+[[fo
+o
+o]] [[bar]])cpp";
+  auto Toks = toSemanticTokens(tokens(AnnotatedCode),
+   Annotations(AnnotatedCode).code());
+  ASSERT_THAT(Toks, SizeIs(4));
+  // foo
+  EXPECT_EQ(Toks[0].deltaLine, 1u);
+  EXPECT_EQ(Toks[0].deltaStart, 0u);
+  EXPECT_EQ(Toks[0].length, 2u);
+  EXPECT_EQ(Toks[1].deltaLine, 1u);
+  EXPECT_EQ(Toks[1].deltaStart, 0u);
+  EXPECT_EQ(Toks[1].length, 1u);
+  EXPECT_EQ(Toks[2].deltaLine, 1u);
+  EXPECT_EQ(Toks[2].deltaStart, 0u);
+  EXPECT_EQ(Toks[2].length, 1u);
+
+  // bar
+  EXPECT_EQ(Toks[3].deltaLine, 0u);
+  EXPECT_EQ(Toks[3].deltaStart, 2u);
+  EXPECT_EQ(Toks[3].length, 3u);
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -21,6 +21,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHTING_H
 
 #include "Protocol.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
@@ -101,7 +102,8 @@
 // main AST.
 std::vector getSemanticHighlightings(ParsedAST &AST);
 
-std::vector toSemanticTokens(llvm::ArrayRef);
+std::vector toSemanticTokens(llvm::ArrayRef,
+llvm::StringRef Code);
 llvm::StringRef toSemanticTokenType(HighlightingKind Kind);
 llvm::StringRef toSemanticTokenModifier(HighlightingModifier Modifier);
 std::vector diffTokens(llvm::ArrayRef Before,
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -30,7 +30,9 @@
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
 #include 
 
 namespace clang {
@@ -918,33 +920,64 @@
 }
 
 std::vector
-toSemanticTokens(llvm::ArrayRef Tokens) {
+toSemanticTokens(llvm::ArrayRef Tokens,
+ llvm::StringRef Code) {
   assert(std::is_sorted(Tokens.begin(), Tokens.end()));
   std::vector Result;
-  const HighlightingToken *Last = nullptr;
+  llvm::Optional Last;
   for (const HighlightingToken &Tok : Tokens) {
 Result.emplace_back();
-SemanticToken &Out = Result.back();
+SemanticToken *Out = &Result.back();
 // deltaStart/deltaLine are relative if possible.
 if (Last) {
-  assert(Tok.R.start.line >= Last->R.start.line);
-  Out.deltaLine = Tok.R.start.line - Last->R.start.line;
-  if (Out.deltaLine == 0) {
+  assert(Tok.R.start.line >= Last->R.end.line);
+  Out->deltaLine = Tok.R.start.line - Last->R.end.line;
+  if (Out->deltaLine == 0) {
 assert(Tok.R.start.character >= Last->R.start.character);
-Out.deltaStart = Tok.R.start.character - Last->R.start.character;
+Out->deltaStart = Tok.R.start.character - Last->R.start.character;
   } else {
-Out.deltaStart 

[PATCH] D127856: [clangd] Support multiline semantic tokens

2022-06-20 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:948
+} else {
+  // If a tokens length is past the end of the line, it should be treated 
as
+  // if the token ends at the end of the line and will not wrap onto the

sammccall wrote:
> sammccall wrote:
> > This wording is hard for me to follow. I think it's saying:
> > 
> > "If the token spans a line break, truncate it to avoid this"
> It seems it would be better to split into one token per line, rather than 
> simply truncating.
> 
> Is truncation for simplicity or is there a reason to prefer it?
> 
> FWIW I think this wouldn't be too hard to implement if you reordered the 
> tokenType/tokenModifiers above so this part is the last step, and just copied 
> the whole SemanticToken object from the back of the Result. But on the other 
> hand it's not terribly important, either.
> 
> At least I think we should have a comment for the truncate/split tradeoff.
> This wording is hard for me to follow. I think it's saying:

It is actually from LSP 😅 changed into a simpler version, I don't think we need 
references to LSP in here.

> Is truncation for simplicity or is there a reason to prefer it?

Yeah I didn't want to do a loop, as in theory there can be many lines not just 
two. Also we need to take care of the `Last` and delta calculations for the 
following tokens.
But it isn't as bad, i suppose. Changed into splitting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127856

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


[PATCH] D126859: [clangd] Validate clang-tidy CheckOptions in clangd config

2022-06-20 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 438388.
njames93 added a comment.

Reuse implementation from D127446 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126859

Files:
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/TidyProvider.h
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp

Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -338,7 +338,9 @@
   EXPECT_EQ(
   Conf.Diagnostics.ClangTidy.Checks,
   "bugprone-use-after-move,llvm-*,-llvm-include-order,-readability-*");
-  EXPECT_THAT(Diags.Diagnostics, IsEmpty());
+  EXPECT_THAT(Diags.Diagnostics,
+  ElementsAre(diagMessage(
+  "unknown clang-tidy option 'example-check.ExampleOption'")));
 #else // !CLANGD_TIDY_CHECKS
   EXPECT_EQ(Conf.Diagnostics.ClangTidy.Checks, "llvm-*,-readability-*");
   EXPECT_THAT(
@@ -346,7 +348,9 @@
   ElementsAre(
   diagMessage(
   "clang-tidy check 'bugprone-use-after-move' was not found"),
-  diagMessage("clang-tidy check 'llvm-include-order' was not found")));
+  diagMessage("clang-tidy check 'llvm-include-order' was not found"),
+  diagMessage(
+  "unknown clang-tidy option 'example-check.ExampleOption'")));
 #endif
 }
 
@@ -355,6 +359,15 @@
   Tidy.Add.emplace_back("unknown-check");
   Tidy.Remove.emplace_back("*");
   Tidy.Remove.emplace_back("llvm-includeorder");
+#if CLANGD_TIDY_CHECKS
+  StringRef IncludeOrderMessage =
+  "clang-tidy check 'llvm-includeorder' was not found; did you mean "
+  "'llvm-include-order'";
+#else // !CLANGD_TIDY_CHECKS
+  StringRef IncludeOrderMessage =
+  "clang-tidy check 'llvm-includeorder' was not found";
+#endif
+
   EXPECT_TRUE(compileAndApply());
   // Ensure bad checks are stripped from the glob.
   EXPECT_EQ(Conf.Diagnostics.ClangTidy.Checks, "-*");
@@ -363,9 +376,49 @@
   ElementsAre(
   AllOf(diagMessage("clang-tidy check 'unknown-check' was not found"),
 diagKind(llvm::SourceMgr::DK_Warning)),
-  AllOf(
-  diagMessage("clang-tidy check 'llvm-includeorder' was not found"),
-  diagKind(llvm::SourceMgr::DK_Warning;
+  AllOf(diagMessage(IncludeOrderMessage),
+diagKind(llvm::SourceMgr::DK_Warning;
+}
+
+TEST_F(ConfigCompileTests, TidyBadOptions) {
+  auto &Tidy = Frag.Diagnostics.ClangTidy;
+  Tidy.CheckOptions.emplace_back(
+  std::make_pair(std::string("BadGlobal"), std::string("true")));
+  Tidy.CheckOptions.emplace_back(
+  std::make_pair(std::string("StrictModes"), std::string("true")));
+  Tidy.CheckOptions.emplace_back(std::make_pair(
+  std::string("readability-braces-around-statements.ShortStatementsLines"),
+  std::string("1")));
+  Tidy.CheckOptions.emplace_back(std::make_pair(
+  std::string("readability-braces-around-statements.ShortStatementLines"),
+  std::string("1")));
+  EXPECT_TRUE(compileAndApply());
+#if CLANGD_TIDY_CHECKS
+  EXPECT_THAT(
+  Diags.Diagnostics,
+  ElementsAre(
+  diagMessage("unknown clang-tidy option 'BadGlobal'"),
+  diagMessage("unknown clang-tidy option 'StrictModes'; did you mean "
+  "'StrictMode'"),
+  diagMessage(
+  "unknown clang-tidy option "
+  "'readability-braces-around-statements.ShortStatementsLines'; "
+  "did you mean "
+  "'readability-braces-around-statements.ShortStatementLines'")));
+#else // !CLANGD_TIDY_CHECKS
+  EXPECT_THAT(
+  Diags.Diagnostics,
+  ElementsAre(
+  diagMessage("unknown clang-tidy option 'BadGlobal'"),
+  diagMessage("unknown clang-tidy option 'StrictModes'; did you mean "
+  "'StrictMode'"),
+  diagMessage(
+  "unknown clang-tidy option "
+  "'readability-braces-around-statements.ShortStatementsLines'"),
+  diagMessage(
+  "unknown clang-tidy option "
+  "'readability-braces-around-statements.ShortStatementLines'")));
+#endif
 }
 
 TEST_F(ConfigCompileTests, ExternalServerNeedsTrusted) {
Index: clang-tools-extra/clangd/TidyProvider.h
===
--- clang-tools-extra/clangd/TidyProvider.h
+++ clang-tools-extra/clangd/TidyProvider.h
@@ -58,7 +58,11 @@
 
 /// Returns if \p Check is a registered clang-tidy check
 /// \pre \p must not be empty, must not contain '*' or ',' or start with '-'.
-bool isRegisteredTidyCheck(llvm::StringRef Check);
+bool isRegisteredTidyCheck(llvm::StringRef Check,
+   llvm::Strin

[PATCH] D127593: [clang] Fix trivially copyable for copy constructor and copy assignment operator

2022-06-20 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

Is it intended that a deleted copy assignment op as in `struct S { void 
operator =(S &) = delete; };` (though, somewhat oddly, not in `struct S { void 
operator =(S) = delete; };`) is now marked as trivial?

I think that's the root cause why a build of PDFium with clang-cl against the 
MSVC standard library started to fail for me now, effectively complaining that 
`__is_trivially_assignable(std::pair &, std::pair const &)` 
is false (as expected) while `__has_trivial_assign(std::pair)` is 
(unexpectedly) true.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127593

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


[PATCH] D127873: [clang-format] Fix misplacemnt of `*` in declaration of pointer to struct

2022-06-20 Thread Jack Huang via Phabricator via cfe-commits
jackhong12 added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2328
+}
+
 if (PrevToken->Tok.isLiteral() ||

HazardyKnusperkeks wrote:
> MyDeveloperDay wrote:
> > Thank you I wish more of the clauses were commented like this
> +1
I'm not sure where I also need to add comments.


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

https://reviews.llvm.org/D127873

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


[clang-tools-extra] 1c92e06 - [clangd] Handle initializers that contain =

2022-06-20 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-06-20T16:42:54+02:00
New Revision: 1c92e06ded2da33f9ad00305af281e47cf9c584f

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

LOG: [clangd] Handle initializers that contain =

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
index 0bbf3274b3a62..298546aed3be9 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -187,26 +187,30 @@ getFunctionSourceCode(const FunctionDecl *FD, 
llvm::StringRef TargetNamespace,
   // Get rid of default arguments, since they should not be specified in
   // out-of-line definition.
   for (const auto *PVD : FD->parameters()) {
-if (PVD->hasDefaultArg()) {
-  // Deletion range initially spans the initializer, excluding the `=`.
-  auto DelRange = 
CharSourceRange::getTokenRange(PVD->getDefaultArgRange());
-  // Get all tokens before the default argument.
-  auto Tokens = TokBuf.expandedTokens(PVD->getSourceRange())
-.take_while([&SM, &DelRange](const syntax::Token &Tok) 
{
-  return SM.isBeforeInTranslationUnit(
-  Tok.location(), DelRange.getBegin());
-});
-  // Find the last `=` before the default arg.
+if (!PVD->hasDefaultArg())
+  continue;
+// Deletion range spans the initializer, usually excluding the `=`.
+auto DelRange = CharSourceRange::getTokenRange(PVD->getDefaultArgRange());
+// Get all tokens before the default argument.
+auto Tokens = TokBuf.expandedTokens(PVD->getSourceRange())
+  .take_while([&SM, &DelRange](const syntax::Token &Tok) {
+return SM.isBeforeInTranslationUnit(
+Tok.location(), DelRange.getBegin());
+  });
+if (TokBuf.expandedTokens(DelRange.getAsRange()).front().kind() !=
+tok::equal) {
+  // Find the last `=` if it isn't included in the initializer, and update
+  // the DelRange to include it.
   auto Tok =
   llvm::find_if(llvm::reverse(Tokens), [](const syntax::Token &Tok) {
 return Tok.kind() == tok::equal;
   });
   assert(Tok != Tokens.rend());
   DelRange.setBegin(Tok->location());
-  if (auto Err =
-  DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
-Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
 }
+if (auto Err =
+DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
+  Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
   }
 
   auto DelAttr = [&](const Attr *A) {

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
index 3131e2063716b..e3954e6b2faff 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -116,6 +116,11 @@ TEST_F(DefineOutlineTest, ApplyTest) {
   "void foo(int x, int y = 5, int = 2, int (*foo)(int) = nullptr) ;",
   "void foo(int x, int y , int , int (*foo)(int) ) {}",
   },
+  {
+  "struct Bar{Bar();}; void fo^o(Bar x = {}) {}",
+  "struct Bar{Bar();}; void foo(Bar x = {}) ;",
+  "void foo(Bar x ) {}",
+  },
   // Constructors
   {
   R"cpp(



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


[PATCH] D128197: [clangd] Handle initializers that contain =

2022-06-20 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
kadircet marked an inline comment as done.
Closed by commit rG1c92e06ded2d: [clangd] Handle initializers that contain = 
(authored by kadircet).

Changed prior to commit:
  https://reviews.llvm.org/D128197?vs=438369&id=438392#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128197

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -116,6 +116,11 @@
   "void foo(int x, int y = 5, int = 2, int (*foo)(int) = nullptr) ;",
   "void foo(int x, int y , int , int (*foo)(int) ) {}",
   },
+  {
+  "struct Bar{Bar();}; void fo^o(Bar x = {}) {}",
+  "struct Bar{Bar();}; void foo(Bar x = {}) ;",
+  "void foo(Bar x ) {}",
+  },
   // Constructors
   {
   R"cpp(
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -187,26 +187,30 @@
   // Get rid of default arguments, since they should not be specified in
   // out-of-line definition.
   for (const auto *PVD : FD->parameters()) {
-if (PVD->hasDefaultArg()) {
-  // Deletion range initially spans the initializer, excluding the `=`.
-  auto DelRange = 
CharSourceRange::getTokenRange(PVD->getDefaultArgRange());
-  // Get all tokens before the default argument.
-  auto Tokens = TokBuf.expandedTokens(PVD->getSourceRange())
-.take_while([&SM, &DelRange](const syntax::Token &Tok) 
{
-  return SM.isBeforeInTranslationUnit(
-  Tok.location(), DelRange.getBegin());
-});
-  // Find the last `=` before the default arg.
+if (!PVD->hasDefaultArg())
+  continue;
+// Deletion range spans the initializer, usually excluding the `=`.
+auto DelRange = CharSourceRange::getTokenRange(PVD->getDefaultArgRange());
+// Get all tokens before the default argument.
+auto Tokens = TokBuf.expandedTokens(PVD->getSourceRange())
+  .take_while([&SM, &DelRange](const syntax::Token &Tok) {
+return SM.isBeforeInTranslationUnit(
+Tok.location(), DelRange.getBegin());
+  });
+if (TokBuf.expandedTokens(DelRange.getAsRange()).front().kind() !=
+tok::equal) {
+  // Find the last `=` if it isn't included in the initializer, and update
+  // the DelRange to include it.
   auto Tok =
   llvm::find_if(llvm::reverse(Tokens), [](const syntax::Token &Tok) {
 return Tok.kind() == tok::equal;
   });
   assert(Tok != Tokens.rend());
   DelRange.setBegin(Tok->location());
-  if (auto Err =
-  DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
-Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
 }
+if (auto Err =
+DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
+  Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
   }
 
   auto DelAttr = [&](const Attr *A) {


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -116,6 +116,11 @@
   "void foo(int x, int y = 5, int = 2, int (*foo)(int) = nullptr) ;",
   "void foo(int x, int y , int , int (*foo)(int) ) {}",
   },
+  {
+  "struct Bar{Bar();}; void fo^o(Bar x = {}) {}",
+  "struct Bar{Bar();}; void foo(Bar x = {}) ;",
+  "void foo(Bar x ) {}",
+  },
   // Constructors
   {
   R"cpp(
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -187,26 +187,30 @@
   // Get rid of default arguments, since they should not be specified in
   // out-of-line definition.
   for (const auto *PVD : FD->parameters()) {
-if (PVD->hasDefaultArg()) {
-  // Deletion range initially spans the initializer, excluding the `=`.
-  auto DelRange = CharSourceRange::getTokenRange(PVD->getDefaultArgRange());
-  

[PATCH] D128183: [clang][dataflow] Extend flow condition in the body of a do/while loop

2022-06-20 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:3700
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopFooVal)));
+  });

Can we infer that after the loop bar is false?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128183

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


[PATCH] D127313: [libc++] Implement P0618R0 (Deprecating )

2022-06-20 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 438407.
philnik added a comment.

- Try to fix CI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127313

Files:
  libcxx/docs/ReleaseNotes.rst
  libcxx/docs/Status/Cxx17Papers.csv
  libcxx/include/codecvt
  libcxx/include/locale
  libcxx/src/locale.cpp
  
libcxx/test/libcxx/localization/locales/locale.convenience/conversions/conversions.string/ctor_move.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_mode.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp
  
libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_always_noconv.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_encoding.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_in.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_length.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_max_length.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_out.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_unshift.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_always_noconv.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_encoding.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_in.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_length.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_max_length.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_out.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_unshift.pass.cpp
  
libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_always_noconv.pass.cpp
  
libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_encoding.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_in.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_length.pass.cpp
  
libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_max_length.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_out.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_unshift.pass.cpp
  libcxx/test/std/localization/locale.stdcvt/depr.verify.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/depr.verify.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/overflow.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/pbackfail.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/rdbuf.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/seekoff.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/state.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/test.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/converted.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_codecvt.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_codecvt_state.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_copy.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/depr.verify.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/from_bytes.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/state.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/to_bytes.pass.cpp
  
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/types.pass.cpp
  libcxx/test/support/platform_support.h

Index: libcxx/test/support/platform_support.h
===
--- libcxx/test/support/platform_support.h
+++ libcxx/test/support/platform_support.h
@@ -14,6 +14,8 @@
 #ifndef PLATFORM_SUPPORT_H
 #define PLATFORM_SUPPORT_H
 
+#include "test_macros.h"
+
 // locale names
 #define LOCALE_en_US   "en_US"
 #define LOCALE_en_US_UTF_8 "en_US.UTF-8"
@@ -92,8 +94,11 @@
 inline
 std::wstring get_wide_temp_file_name()
 {
+TEST_DIAGNOSTIC_PUSH
+TEST_CLANG_DIAGNOSTIC_

[PATCH] D126461: [RISCV] Extract and store new vl of vleff/vlsegff iff destination isn't null

2022-06-20 Thread Philip Reames via Phabricator via cfe-commits
reames requested changes to this revision.
reames added a comment.
This revision now requires changes to proceed.

Despite the comments above, the purpose of this patch remains unclear.

Per the draft spec, the relevant wording is:
"These instructions execute as a regular load except that they will only take a 
trap caused by a synchronous exception
on element 0. If element 0 raises an exception, vl is not modied, and the trap 
is taken. If an element > 0 raises an
exception, the corresponding trap is not taken, and the vector length vl is 
reduced to the index of the element that would
have raised an exception."

Working through the scenario in this patch with the destination being null, the 
expected result is for a trap to be generated (provided null is unmapped of 
course), and VL not to be modified.  In order for this change to make any 
difference in runtime behavior, the value passed must be null (or otherwise 
guaranteed to fault).  It seems very odd to me that we are modifying code which 
only runs after an instruction which is guaranteed to fault.  Is there an 
assumed runtime here which is e.g. restarting execution?

Presumably, the actual IR instruction returns the unmodified VL in the faulting 
first access case.  (If it doesn't, that's a bug we should fix.)

The last point, and it's a critical one, is that the outparam for new_vl does 
not have to be null if dest is.  Given that, I think the entire prior 
discussion on motivation here is off base.  Unless you can point to something 
in the intrinsic docs which says *explicitly* that the new_vl param to the 
intrinsic can be null when the dest is known to fault, I think we should 
strongly reject this patch.  Even if you can, I think we should first ask if 
that's a bug in the intrinsic spec.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126461

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


[PATCH] D126461: [RISCV] Extract and store new vl of vleff/vlsegff iff destination isn't null

2022-06-20 Thread Zakk Chen via Phabricator via cfe-commits
khchen added a comment.

Could you please purpose this implement in rvv-intrinsc-doc first?
I think this feature need to have discussion because store to nullptr is UB but 
we are making it as defined behavior only for these intrinsics.
Personally I like they have consistent behavior and in document side we just 
make a note for users that vl should not be a null pointer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126461

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


[PATCH] D127890: [Docs] Update clang & llvm release notes for HLSL

2022-06-20 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 438419.
beanz added a comment.

Updates based on feeback from @MaskRay. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127890

Files:
  clang/docs/ReleaseNotes.rst
  llvm/docs/ReleaseNotes.rst


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -110,6 +110,16 @@
 
 * ...
 
+Changes to the DirectX Backend
+--
+
+* DirectX has been added as an experimental target. Specify
+  ``-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=DirectX`` in your CMake configuration
+  to enable it. The target is not packaged in pre-built binaries.
+* The DirectX backend supports the ``dxil`` architecture which is based on LLVM
+  3.6 IR encoded as bitcode and is the format used for DirectX GPU Shader
+  programs.
+
 Changes to the Hexagon Backend
 --
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -68,6 +68,12 @@
 
   Randomizing structure layout is a C-only feature.
 
+- Experimental support for HLSL has been added. The implementation is
+  incomplete and highly experimental. For more information about the ongoing
+  work to support HLSL see the `documentation
+  `_, or the `GitHub project
+  `_.
+
 Bug Fixes
 -
 - ``CXXNewExpr::getArraySize()`` previously returned a ``llvm::Optional``


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -110,6 +110,16 @@
 
 * ...
 
+Changes to the DirectX Backend
+--
+
+* DirectX has been added as an experimental target. Specify
+  ``-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=DirectX`` in your CMake configuration
+  to enable it. The target is not packaged in pre-built binaries.
+* The DirectX backend supports the ``dxil`` architecture which is based on LLVM
+  3.6 IR encoded as bitcode and is the format used for DirectX GPU Shader
+  programs.
+
 Changes to the Hexagon Backend
 --
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -68,6 +68,12 @@
 
   Randomizing structure layout is a C-only feature.
 
+- Experimental support for HLSL has been added. The implementation is
+  incomplete and highly experimental. For more information about the ongoing
+  work to support HLSL see the `documentation
+  `_, or the `GitHub project
+  `_.
+
 Bug Fixes
 -
 - ``CXXNewExpr::getArraySize()`` previously returned a ``llvm::Optional``
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127593: [clang] Fix trivially copyable for copy constructor and copy assignment operator

2022-06-20 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D127593#3596601 , @sberg wrote:

> Is it intended that a deleted copy assignment op as in `struct S { void 
> operator =(S &) = delete; };` (though, somewhat oddly, not in `struct S { 
> void operator =(S) = delete; };`) is now marked as trivial?
>
> I think that's the root cause why a build of PDFium with clang-cl against the 
> MSVC standard library started to fail for me now, effectively complaining 
> that `__is_trivially_assignable(std::pair &, std::pair 
> const &)` is false (as expected) while 
> `__has_trivial_assign(std::pair)` is (unexpectedly) true.

I don't see it on godbolt trunk: https://godbolt.org/z/KPfxWqnhd.
Did you mean other traits maybe?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127593

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


[PATCH] D128190: [WinEH] Apply funclet operand bundles to nounwind intrinsics that lower to function calls

2022-06-20 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz updated this revision to Diff 438425.
sgraenitz added a comment.

Add missing `objc_sync_exit` to fix failing test 
Transforms/PreISelIntrinsicLowering/objc-arc.ll


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128190

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenObjCXX/arc-exceptions-seh.mm
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
  llvm/lib/IR/IntrinsicInst.cpp
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/CodeGen/X86/win64-funclet-preisel-intrinsics.ll
  llvm/test/Feature/OperandBundles/inliner-funclet-wineh.ll

Index: llvm/test/Feature/OperandBundles/inliner-funclet-wineh.ll
===
--- /dev/null
+++ llvm/test/Feature/OperandBundles/inliner-funclet-wineh.ll
@@ -0,0 +1,55 @@
+; RUN: opt -S -always-inline -mtriple=x86_64-windows-msvc < %s | FileCheck %s
+
+; WinEH doesn't require funclet tokens on nounwind intrinsics per se. ObjC++ ARC
+; intrinsics are a special case, because they are subject to pre-ISel lowering.
+; They appear as regular function calls for subsequent passes, like WinEHPrepare
+; which would consider them implausible instrucitons and mark them unreachable.
+; Affected EH funclets would get truncated silently, which causes unpredictable
+; crashes at runtime.
+;
+; Thus, when we target WinEH and generate calls to pre-ISel intrinsics from EH
+; funclets, we emit funclet tokens explicitly.
+;
+; The inliner has to propagate funclet tokens to such intrinsics, if they get
+; inlined into EH funclets.
+
+define void @inlined_fn(ptr %ex) #1 {
+entry:
+  call void @llvm.objc.storeStrong(ptr %ex, ptr null)
+  ret void
+}
+
+define void @test_catch_with_inline() personality ptr @__CxxFrameHandler3 {
+entry:
+  %exn.slot = alloca ptr, align 8
+  %ex = alloca ptr, align 8
+  invoke void @opaque() to label %invoke.cont unwind label %catch.dispatch
+
+catch.dispatch:
+  %0 = catchswitch within none [label %catch] unwind to caller
+
+invoke.cont:
+  unreachable
+
+catch:
+  %1 = catchpad within %0 [ptr null, i32 64, ptr %exn.slot]
+  call void @inlined_fn(ptr %ex) [ "funclet"(token %1) ]
+  catchret from %1 to label %catchret.dest
+
+catchret.dest:
+  ret void
+}
+
+declare void @opaque()
+declare void @llvm.objc.storeStrong(ptr, ptr) #0
+declare i32 @__CxxFrameHandler3(...)
+
+attributes #0 = { nounwind }
+attributes #1 = { alwaysinline }
+
+; CHECK-LABEL:  define void @test_catch_with_inline()
+; ...
+; CHECK:catch:
+; CHECK-NEXT: %1 = catchpad within %0 [ptr null, i32 64, ptr %exn.slot]
+; CHECK-NEXT: call void @llvm.objc.storeStrong(ptr %ex, ptr null) [ "funclet"(token %1) ]
+; CHECK-NEXT: catchret from %1 to label %catchret.dest
Index: llvm/test/CodeGen/X86/win64-funclet-preisel-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/win64-funclet-preisel-intrinsics.ll
@@ -0,0 +1,68 @@
+; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
+
+; Reduced IR generated from ObjC++ source:
+;
+; @class Ety;
+; void opaque(void);
+; void test_catch(void) {
+;   @try {
+; opaque();
+;   } @catch (Ety *ex) {
+; // Destroy ex when leaving catchpad. This emits calls to two intrinsic
+; // functions, llvm.objc.retain and llvm.objc.storeStrong, but only one
+; // is required to trigger the funclet truncation.
+;   }
+; }
+
+define void @test_catch() personality ptr @__CxxFrameHandler3 {
+entry:
+  %exn.slot = alloca ptr, align 8
+  %ex2 = alloca ptr, align 8
+  invoke void @opaque() to label %invoke.cont unwind label %catch.dispatch
+
+catch.dispatch:
+  %0 = catchswitch within none [label %catch] unwind to caller
+
+invoke.cont:
+  unreachable
+
+catch:
+  %1 = catchpad within %0 [ptr null, i32 64, ptr %exn.slot]
+  call void @llvm.objc.storeStrong(ptr %ex2, ptr null) [ "funclet"(token %1) ]
+  catchret from %1 to label %catchret.dest
+
+catchret.dest:
+  ret void
+}
+
+declare void @opaque()
+declare void @llvm.objc.storeStrong(ptr, ptr) #0
+declare i32 @__CxxFrameHandler3(...)
+
+attributes #0 = { nounwind }
+
+; llvm.objc.storeStrong is a Pre-ISel intrinsic, which used to cause truncations
+; when it occurred in SEH funclets like catchpads:
+; CHECK: # %catch
+; CHECK: pushq   %rbp
+; CHECK: .seh_pushreg %rbp
+;...
+; CHECK: .seh_endprologue
+;
+; At this point the code used to be truncated (and sometimes terminated with an
+; int3 opcode):
+; CHECK-NOT: int3
+;
+; Instead, the call to objc_storeStrong should be emitted:
+; CHECK: leaq	-24(%rbp), %rcx
+; CHECK: xorl	%edx, %edx
+; CHECK: callq	objc_storeStrong
+;...
+; 
+; This is the end of the funclet:
+; CHECK: popq	%rbp
+; CHECK: retq# CATCHRET
+;...
+;  

[PATCH] D128190: [WinEH] Apply funclet operand bundles to nounwind intrinsics that lower to function calls

2022-06-20 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz added a comment.

Running `check-llvm` and `check-clang` locally found no more failing tests. The 
issue is not limited to pre-ISel intrinsics (anymore) and I have to re-phrase a 
few comments. Apart from that, is there any more feedback? Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128190

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


[PATCH] D128183: [clang][dataflow] Extend flow condition in the body of a do/while loop

2022-06-20 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 438427.
sgatev added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128183

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3628,25 +3628,81 @@
 void target(bool Foo) {
   while (Foo) {
 (void)0;
-// [[while_branch]]
+// [[loop_body]]
   }
+  (void)0;
+  // [[after_loop]]
 }
   )";
-  runDataflow(Code,
-  [](llvm::ArrayRef<
- std::pair>>
- Results,
- ASTContext &ASTCtx) {
-ASSERT_THAT(Results, ElementsAre(Pair("while_branch", _)));
-const Environment &Env = Results[0].second.Env;
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results,
+ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
+const Environment &LoopBodyEnv = Results[1].second.Env;
+const Environment &AfterLoopEnv = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
-ASSERT_THAT(FooDecl, NotNull());
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
 
-BoolValue &FooVal =
-*cast(Env.getValue(*FooDecl, SkipPast::None));
-EXPECT_TRUE(Env.flowConditionImplies(FooVal));
-  });
+BoolValue &LoopBodyFooVal =
+*cast(LoopBodyEnv.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(LoopBodyEnv.flowConditionImplies(LoopBodyFooVal));
+
+BoolValue &AfterLoopFooVal =
+*cast(AfterLoopEnv.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopFooVal)));
+  });
+}
+
+TEST_F(TransferTest, DoWhileStmtBranchExtendsFlowCondition) {
+  std::string Code = R"(
+void target(bool Foo) {
+  bool Bar = true;
+  do {
+(void)0;
+// [[loop_body]]
+Bar = false;
+  } while (Foo);
+  (void)0;
+  // [[after_loop]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results,
+ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
+const Environment &LoopBodyEnv = Results[1].second.Env;
+const Environment &AfterLoopEnv = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+BoolValue &LoopBodyFooVal =
+*cast(LoopBodyEnv.getValue(*FooDecl, SkipPast::None));
+BoolValue &LoopBodyBarVal =
+*cast(LoopBodyEnv.getValue(*BarDecl, SkipPast::None));
+EXPECT_TRUE(LoopBodyEnv.flowConditionImplies(
+LoopBodyEnv.makeOr(LoopBodyBarVal, LoopBodyFooVal)));
+
+BoolValue &AfterLoopFooVal =
+*cast(AfterLoopEnv.getValue(*FooDecl, SkipPast::None));
+BoolValue &AfterLoopBarVal =
+*cast(AfterLoopEnv.getValue(*BarDecl, SkipPast::None));
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopFooVal)));
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopBarVal)));
+  });
 }
 
 TEST_F(TransferTest, ForStmtBranchExtendsFlowCondition) {
@@ -3654,25 +3710,34 @@
 void target(bool Foo) {
   for (; Foo;) {
 (void)0;
-// [[for_branch]]
+// [[loop_body]]
   }
+  (void)0;
+  // [[after_loop]]
 }
   )";
-  runDataflow(Code,
-  [](llvm::ArrayRef<
- std::pair>>
- Results,
- ASTContext &ASTCtx) {
-ASSERT_THAT(Results, ElementsAre(Pair("for_branch", _)));
-const Environment &Env = Results[0].second.Env;
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results,
+ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
+const Environment &LoopBodyEnv = Results[1].second.Env;
+   

[PATCH] D128183: [clang][dataflow] Extend flow condition in the body of a do/while loop

2022-06-20 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev marked an inline comment as done.
sgatev added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:3700
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopFooVal)));
+  });

gribozavr2 wrote:
> Can we infer that after the loop bar is false?
Yes!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128183

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


[PATCH] D127641: [clang-cl][MSVC] Enable /Zc:alignedNew for C++17 and /Zc:sizedDealloc by default

2022-06-20 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm

(If you like, consider dropping the "-DEFAULT" part from the new filecheck 
prefixes. I don't think they really add much value.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127641

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


[PATCH] D127270: [clang-format] Add space in placement new expression

2022-06-20 Thread omar ahmed via Phabricator via cfe-commits
omarahmed updated this revision to Diff 438433.
omarahmed added a comment.

- Add version for nestedEnums and nestedFields
- Make tests valid


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127270

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10130,6 +10130,42 @@
 "void delete(link p);\n",
 format("void new (link p);\n"
"void delete (link p);\n"));
+
+  FormatStyle AfterPlacementOperator = getLLVMStyle();
+  AfterPlacementOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+  EXPECT_EQ(
+  AfterPlacementOperator.SpaceBeforeParensOptions.AfterPlacementOperator,
+  FormatStyle::SpaceBeforeParensCustom::APO_Never);
+  verifyFormat("struct A {\n"
+   "  int *a;\n"
+   "  A(int *p) : a(new(p) int) {\n"
+   "new(p) int;\n"
+   "int *b = new(p) int;\n"
+   "int *c = new(p) int(3);\n"
+   "delete(b);\n"
+   "  }\n"
+   "};",
+   AfterPlacementOperator);
+  verifyFormat("void operator new(void *foo) ATTRIB;", AfterPlacementOperator);
+
+  AfterPlacementOperator.SpaceBeforeParensOptions.AfterPlacementOperator =
+  FormatStyle::SpaceBeforeParensCustom::APO_Always;
+  verifyFormat("struct A {\n"
+   "  int *a;\n"
+   "  A(int *p) : a(new (p) int) {\n"
+   "new (p) int;\n"
+   "int *b = new (p) int;\n"
+   "int *c = new (p) int(3);\n"
+   "delete (b);\n"
+   "  }\n"
+   "};",
+   AfterPlacementOperator);
+  verifyFormat("void operator new(void *foo) ATTRIB;", AfterPlacementOperator);
+
+  AfterPlacementOperator.SpaceBeforeParensOptions.AfterPlacementOperator =
+  FormatStyle::SpaceBeforeParensCustom::APO_Leave;
+  EXPECT_EQ("new (buf) int;", format("new (buf) int;", AfterPlacementOperator));
+  EXPECT_EQ("new(buf) int;", format("new(buf) int;", AfterPlacementOperator));
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
@@ -20308,6 +20344,24 @@
   SpaceBeforeParens,
   FormatStyle::SBPO_ControlStatementsExceptControlMacros);
 
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+  Style.SpaceBeforeParensOptions.AfterPlacementOperator =
+  FormatStyle::SpaceBeforeParensCustom::APO_Always;
+  CHECK_PARSE("SpaceBeforeParensOptions:\n"
+  "  AfterPlacementOperator: Never",
+  SpaceBeforeParensOptions.AfterPlacementOperator,
+  FormatStyle::SpaceBeforeParensCustom::APO_Never);
+
+  CHECK_PARSE("SpaceBeforeParensOptions:\n"
+  "  AfterPlacementOperator: Always",
+  SpaceBeforeParensOptions.AfterPlacementOperator,
+  FormatStyle::SpaceBeforeParensCustom::APO_Always);
+
+  CHECK_PARSE("SpaceBeforeParensOptions:\n"
+  "  AfterPlacementOperator: Leave",
+  SpaceBeforeParensOptions.AfterPlacementOperator,
+  FormatStyle::SpaceBeforeParensCustom::APO_Leave);
+
   Style.ColumnLimit = 123;
   FormatStyle BaseStyle = getLLVMStyle();
   CHECK_PARSE("BasedOnStyle: LLVM", ColumnLimit, BaseStyle.ColumnLimit);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3393,6 +3393,18 @@
 if (Left.is(TT_IfMacro))
   return Style.SpaceBeforeParensOptions.AfterIfMacros ||
  spaceRequiredBeforeParens(Right);
+if (Style.SpaceBeforeParens == FormatStyle::SBPO_Custom &&
+Left.isOneOf(tok::kw_new, tok::kw_delete) &&
+Right.isNot(TT_OverloadedOperatorLParen) &&
+!(Line.MightBeFunctionDecl && Left.is(TT_FunctionDeclarationName))) {
+  if (Style.SpaceBeforeParensOptions.AfterPlacementOperator ==
+  FormatStyle::SpaceBeforeParensCustom::APO_Always ||
+  (Style.SpaceBeforeParensOptions.AfterPlacementOperator ==
+   FormatStyle::SpaceBeforeParensCustom::APO_Leave &&
+   Right.hasWhitespaceBefore()))
+return true;
+  return false;
+}
 if (Line.Type == LT_ObjCDecl)
   return true;
 if (Left.is(tok::semi))
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -936,6 +936,7 @@
Spacing.AfterFunctionDeclarationName);
 IO.mapOptional("AfterIfMacros", Spacin

[PATCH] D127270: [clang-format] Add space in placement new expression

2022-06-20 Thread omar ahmed via Phabricator via cfe-commits
omarahmed added inline comments.



Comment at: clang/docs/tools/dump_format_style.py:317
   pass
+  elif state == State.InNestedEnum:
+if line.startswith('///'):

MyDeveloperDay wrote:
> Can you show us a screenshot of how these changes will look in HTML?
{F23524556}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127270

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


[PATCH] D127270: [clang-format] Add space in placement new expression

2022-06-20 Thread omar ahmed via Phabricator via cfe-commits
omarahmed marked 3 inline comments as done and an inline comment as not done.
omarahmed added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3396
  spaceRequiredBeforeParens(Right);
+if (Style.SpaceBeforeParens == FormatStyle::SBPO_Custom &&
+Left.isOneOf(tok::kw_new, tok::kw_delete) &&

HazardyKnusperkeks wrote:
> omarahmed wrote:
> > MyDeveloperDay wrote:
> > > shouldn't the very first part of this be? 
> > > 
> > > 
> > > ```
> > > if (Style.SpaceBeforeParensOptions.AfterPlacementOperator != 
> > > FormatStyle::SpaceBeforeParensCustom::APO_Leave)
> > > {
> > > 
> > > 
> > > 
> > > }
> > > ```
> > > 
> > > i.e. don't we want a zero change if someone says "Leave"
> > The current code logic, when we do not enter this suggested condition, will 
> > switch to [this 
> > condition](https://github.com/llvm/llvm-project/blob/c2bb2e5973acd24c45c1823e95e8e33003c59484/clang/lib/Format/TokenAnnotator.cpp#L3580).
> >  And will not leave the code as it is, but will change it.
> > 
> > I have thought of getting rid of this condition entirely, but it handles 
> > the default situation suggested here, not only for cpp but for other 
> > languages like js:
> > >>As I understand, the default behavior for when the user didn't use 
> > >>`SBPO_Custom` is to add a space in placement operators based on [this 
> > >>issue](https://github.com/llvm/llvm-project/issues/54703). And, at the 
> > >>same time, the default behavior should be `APO_Never` when we have 
> > >>`SBPO_Custom` so that we handle other code that depends on that. the 
> > >>existing tests confirm this understanding. So, the current logic was 
> > >>added based on this understanding.
> > 
> > I tried to add an extra condition to [this 
> > condition](https://github.com/llvm/llvm-project/blob/c2bb2e5973acd24c45c1823e95e8e33003c59484/clang/lib/Format/TokenAnnotator.cpp#L3580)
> >  to support the main logic that we are pursuing. so that it would be like 
> > that:
> > ```
> > if (Style.SpaceBeforeParensOptions.AfterPlacementOperator != 
> > FormatStyle::SpaceBeforeParensCustom::APO_Leave && 
> > Left.isOneOf(tok::kw_new, tok::kw_delete))
> > ```
> > But that wouldn't fix the leave situation, as it will be also at the end, 
> > reach [this 
> > part](https://github.com/llvm/llvm-project/blob/c2bb2e5973acd24c45c1823e95e8e33003c59484/clang/lib/Format/TokenAnnotator.cpp#L3598)
> >  which will  
> > ```
> > return false
> > ``` 
> > and force no space.
> > 
> > I think all of that was raised because all current 
> > "SpaceBeforeParanthesesOptions" are either true or false and this is the 
> > only enum
> > 
> > However, I completely agree with this logic which is to begin our checking 
> > for leave. But I think we should refactor all the 
> > "spaceBeforeParenthesesOptions" conditions to handle this and do that after 
> > all the options have been transformed to enums.
> > 
> `SpaceBeforeParensOptions` should always be expanded, regardless of 
> `SpaceBeforeParens`, as far as I remember. `SpaceBeforeParens` is only for 
> the one configuring clang-format, the code that formats should always and 
> only check `SpaceBeforeParensOptions`.
But in general, doesn't that could create some kind of conflict like if someone 
used a specific option in `SpaceBeforeParens ` and then defined inside 
`SpaceBeforeParensOptions ` some rules that could conflict with 
`SpaceBeforeParens `, what should be the priority between them?




Comment at: clang/lib/Format/TokenAnnotator.cpp:3396
  spaceRequiredBeforeParens(Right);
+if (Style.SpaceBeforeParens == FormatStyle::SBPO_Custom &&
+Left.isOneOf(tok::kw_new, tok::kw_delete) &&

omarahmed wrote:
> HazardyKnusperkeks wrote:
> > omarahmed wrote:
> > > MyDeveloperDay wrote:
> > > > shouldn't the very first part of this be? 
> > > > 
> > > > 
> > > > ```
> > > > if (Style.SpaceBeforeParensOptions.AfterPlacementOperator != 
> > > > FormatStyle::SpaceBeforeParensCustom::APO_Leave)
> > > > {
> > > > 
> > > > 
> > > > 
> > > > }
> > > > ```
> > > > 
> > > > i.e. don't we want a zero change if someone says "Leave"
> > > The current code logic, when we do not enter this suggested condition, 
> > > will switch to [this 
> > > condition](https://github.com/llvm/llvm-project/blob/c2bb2e5973acd24c45c1823e95e8e33003c59484/clang/lib/Format/TokenAnnotator.cpp#L3580).
> > >  And will not leave the code as it is, but will change it.
> > > 
> > > I have thought of getting rid of this condition entirely, but it handles 
> > > the default situation suggested here, not only for cpp but for other 
> > > languages like js:
> > > >>As I understand, the default behavior for when the user didn't use 
> > > >>`SBPO_Custom` is to add a space in placement operators based on [this 
> > > >>issue](https://github.com/llvm/llvm-project/issues/54703). And, at the 
> > > >>same time, the default behavior should be `APO_Never` when we hav

[clang] e363c59 - [clang][dataflow] Extend flow condition in the body of a do/while loop

2022-06-20 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-06-20T17:31:00Z
New Revision: e363c5963dc3ad5d9492d3f37055ad56a84411a5

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

LOG: [clang][dataflow] Extend flow condition in the body of a do/while loop

Extend flow condition in the body of a do/while loop.

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

Reviewed-by: gribozavr2, xazax.hun

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 4759932a696f1..e8d3a4e6d4505 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -87,8 +87,13 @@ static Value *mergeDistinctValues(QualType Type, Value *Val1,
   // have mutually exclusive conditions.
   if (auto *Expr1 = dyn_cast(Val1)) {
 auto *Expr2 = cast(Val2);
-return &Env1.makeOr(Env1.makeAnd(Env1.getFlowConditionToken(), *Expr1),
-Env1.makeAnd(Env2.getFlowConditionToken(), *Expr2));
+auto &MergedVal = MergedEnv.makeAtomicBoolValue();
+MergedEnv.addToFlowCondition(MergedEnv.makeOr(
+MergedEnv.makeAnd(Env1.getFlowConditionToken(),
+  MergedEnv.makeIff(MergedVal, *Expr1)),
+MergedEnv.makeAnd(Env2.getFlowConditionToken(),
+  MergedEnv.makeIff(MergedVal, *Expr2;
+return &MergedVal;
   }
 
   // FIXME: add unit tests that cover this statement.

diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index a1ce2f6912574..68e897e035962 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -89,6 +89,12 @@ class TerminatorVisitor : public 
ConstStmtVisitor {
 extendFlowCondition(*Cond);
   }
 
+  void VisitDoStmt(const DoStmt *S) {
+auto *Cond = S->getCond();
+assert(Cond != nullptr);
+extendFlowCondition(*Cond);
+  }
+
   void VisitForStmt(const ForStmt *S) {
 auto *Cond = S->getCond();
 assert(Cond != nullptr);

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 29a45a315074d..3a8e2ac8588a5 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3628,25 +3628,81 @@ TEST_F(TransferTest, 
WhileStmtBranchExtendsFlowCondition) {
 void target(bool Foo) {
   while (Foo) {
 (void)0;
-// [[while_branch]]
+// [[loop_body]]
   }
+  (void)0;
+  // [[after_loop]]
 }
   )";
-  runDataflow(Code,
-  [](llvm::ArrayRef<
- std::pair>>
- Results,
- ASTContext &ASTCtx) {
-ASSERT_THAT(Results, ElementsAre(Pair("while_branch", _)));
-const Environment &Env = Results[0].second.Env;
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results,
+ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
+const Environment &LoopBodyEnv = Results[1].second.Env;
+const Environment &AfterLoopEnv = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
-ASSERT_THAT(FooDecl, NotNull());
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
 
-BoolValue &FooVal =
-*cast(Env.getValue(*FooDecl, SkipPast::None));
-EXPECT_TRUE(Env.flowConditionImplies(FooVal));
-  });
+BoolValue &LoopBodyFooVal =
+*cast(LoopBodyEnv.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(LoopBodyEnv.flowConditionImplies(LoopBodyFooVal));
+
+BoolValue &AfterLoopFooVal =
+*cast(AfterLoopEnv.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopFooVal)));
+  });
+}
+
+TEST_F(TransferTest, DoWhileStmtBranchExtendsFlowCondition) {
+  std::string Code = R"(
+void target(bool Foo) {
+  bool Bar = true;
+  do {
+(void)0;
+// [[loop_body]]
+Bar = false;
+  } while (Foo);
+  (void)0;
+  // [[after_loop]]
+}
+  )";

[PATCH] D128183: [clang][dataflow] Extend flow condition in the body of a do/while loop

2022-06-20 Thread Stanislav Gatev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
sgatev marked an inline comment as done.
Closed by commit rGe363c5963dc3: [clang][dataflow] Extend flow condition in the 
body of a do/while loop (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128183

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3628,25 +3628,81 @@
 void target(bool Foo) {
   while (Foo) {
 (void)0;
-// [[while_branch]]
+// [[loop_body]]
   }
+  (void)0;
+  // [[after_loop]]
 }
   )";
-  runDataflow(Code,
-  [](llvm::ArrayRef<
- std::pair>>
- Results,
- ASTContext &ASTCtx) {
-ASSERT_THAT(Results, ElementsAre(Pair("while_branch", _)));
-const Environment &Env = Results[0].second.Env;
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results,
+ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
+const Environment &LoopBodyEnv = Results[1].second.Env;
+const Environment &AfterLoopEnv = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
-ASSERT_THAT(FooDecl, NotNull());
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
 
-BoolValue &FooVal =
-*cast(Env.getValue(*FooDecl, SkipPast::None));
-EXPECT_TRUE(Env.flowConditionImplies(FooVal));
-  });
+BoolValue &LoopBodyFooVal =
+*cast(LoopBodyEnv.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(LoopBodyEnv.flowConditionImplies(LoopBodyFooVal));
+
+BoolValue &AfterLoopFooVal =
+*cast(AfterLoopEnv.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopFooVal)));
+  });
+}
+
+TEST_F(TransferTest, DoWhileStmtBranchExtendsFlowCondition) {
+  std::string Code = R"(
+void target(bool Foo) {
+  bool Bar = true;
+  do {
+(void)0;
+// [[loop_body]]
+Bar = false;
+  } while (Foo);
+  (void)0;
+  // [[after_loop]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results,
+ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
+const Environment &LoopBodyEnv = Results[1].second.Env;
+const Environment &AfterLoopEnv = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+BoolValue &LoopBodyFooVal =
+*cast(LoopBodyEnv.getValue(*FooDecl, SkipPast::None));
+BoolValue &LoopBodyBarVal =
+*cast(LoopBodyEnv.getValue(*BarDecl, SkipPast::None));
+EXPECT_TRUE(LoopBodyEnv.flowConditionImplies(
+LoopBodyEnv.makeOr(LoopBodyBarVal, LoopBodyFooVal)));
+
+BoolValue &AfterLoopFooVal =
+*cast(AfterLoopEnv.getValue(*FooDecl, SkipPast::None));
+BoolValue &AfterLoopBarVal =
+*cast(AfterLoopEnv.getValue(*BarDecl, SkipPast::None));
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopFooVal)));
+EXPECT_TRUE(AfterLoopEnv.flowConditionImplies(
+AfterLoopEnv.makeNot(AfterLoopBarVal)));
+  });
 }
 
 TEST_F(TransferTest, ForStmtBranchExtendsFlowCondition) {
@@ -3654,25 +3710,34 @@
 void target(bool Foo) {
   for (; Foo;) {
 (void)0;
-// [[for_branch]]
+// [[loop_body]]
   }
+  (void)0;
+  // [[after_loop]]
 }
   )";
-  runDataflow(Code,
-  [](llvm::ArrayRef<
- std::pair>>
- Results,
- ASTContext &ASTCtx) {
-ASSERT_THAT(Results, ElementsAre(Pair("for_branch", _)));
-const Environment &Env = Results[0].second.Env;
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   

[PATCH] D127641: [clang-cl][MSVC] Enable /Zc:alignedNew for C++17 and /Zc:sizedDealloc by default

2022-06-20 Thread Stephen Long via Phabricator via cfe-commits
steplong updated this revision to Diff 438437.
steplong added a comment.

- Remove DEFAULT from test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127641

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-zc.cpp


Index: clang/test/Driver/cl-zc.cpp
===
--- clang/test/Driver/cl-zc.cpp
+++ clang/test/Driver/cl-zc.cpp
@@ -1,6 +1,19 @@
 // Note: %s must be preceded by --, otherwise it may be interpreted as a
 // command-line option, e.g. on Mac where %s is commonly under /Users.
 
+// RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=SIZED-DEALLOC %s
+// RUN: %clang_cl /c -### -fms-compatibility-version=18 -- %s 2>&1 | FileCheck 
-check-prefix=SIZED-DEALLOC-OFF %s
+// SIZED-DEALLOC: "-fsized-deallocation"
+// SIZED-DEALLOC-OFF-NOT: "-fsized-deallocation"
+
+// RUN: %clang_cl /c /std:c++11 -### -- %s 2>&1 | FileCheck 
-check-prefix=ALIGNED-NEW-BEFORE-CPP17 %s
+// RUN: %clang_cl /c /std:c++14 -### -- %s 2>&1 | FileCheck 
-check-prefix=ALIGNED-NEW-BEFORE-CPP17 %s
+// RUN: %clang_cl /c /std:c++17 -### -- %s 2>&1 | FileCheck 
-check-prefix=ALIGNED-NEW-CPP17ONWARDS %s
+// RUN: %clang_cl /c /std:c++20 -### -- %s 2>&1 | FileCheck 
-check-prefix=ALIGNED-NEW-CPP17ONWARDS %s
+// RUN: %clang_cl /c /std:c++latest -### -- %s 2>&1 | FileCheck 
-check-prefix=ALIGNED-NEW-CPP17ONWARDS %s
+// ALIGNED-NEW-BEFORE-CPP17-NOT: "-faligned-allocation"
+// ALIGNED-NEW-CPP17ONWARDS: "-faligned-allocation"
+
 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck 
-check-prefix=TRIGRAPHS-DEFAULT %s
 // cc1 will disable trigraphs for -fms-compatibility as long as -ftrigraphs
 // isn't explicitly passed.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6470,6 +6470,7 @@
 }
 CmdArgs.push_back(LanguageStandard.data());
   }
+  bool IsCPP17Onwards = false;
   if (ImplyVCPPCXXVer) {
 StringRef LanguageStandard;
 if (const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
@@ -6493,6 +6494,9 @@
 }
 
 CmdArgs.push_back(LanguageStandard.data());
+
+IsCPP17Onwards =
+LanguageStandard != "-std=c++11" && LanguageStandard != "-std=c++14";
   }
 
   Args.addOptInFlag(CmdArgs, options::OPT_fborland_extensions,
@@ -6622,9 +6626,15 @@
 options::OPT_fno_relaxed_template_template_args);
 
   // -fsized-deallocation is off by default, as it is an ABI-breaking change 
for
-  // most platforms.
-  Args.addOptInFlag(CmdArgs, options::OPT_fsized_deallocation,
-options::OPT_fno_sized_deallocation);
+  // most platforms. MSVC turns on /Zc:sizedDealloc by default, starting in
+  // MSVC 2015.
+  if (IsWindowsMSVC && IsMSVC2015Compatible &&
+  !Args.getLastArg(options::OPT_fsized_deallocation,
+   options::OPT_fno_sized_deallocation))
+CmdArgs.push_back("-fsized-deallocation");
+  else
+Args.addOptInFlag(CmdArgs, options::OPT_fsized_deallocation,
+  options::OPT_fno_sized_deallocation);
 
   // -faligned-allocation is on by default in C++17 onwards and otherwise off
   // by default.
@@ -6635,6 +6645,8 @@
   CmdArgs.push_back("-fno-aligned-allocation");
 else
   CmdArgs.push_back("-faligned-allocation");
+  } else if (IsCPP17Onwards) {
+CmdArgs.push_back("-faligned-allocation");
   }
 
   // The default new alignment can be specified using a dedicated option or via


Index: clang/test/Driver/cl-zc.cpp
===
--- clang/test/Driver/cl-zc.cpp
+++ clang/test/Driver/cl-zc.cpp
@@ -1,6 +1,19 @@
 // Note: %s must be preceded by --, otherwise it may be interpreted as a
 // command-line option, e.g. on Mac where %s is commonly under /Users.
 
+// RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=SIZED-DEALLOC %s
+// RUN: %clang_cl /c -### -fms-compatibility-version=18 -- %s 2>&1 | FileCheck -check-prefix=SIZED-DEALLOC-OFF %s
+// SIZED-DEALLOC: "-fsized-deallocation"
+// SIZED-DEALLOC-OFF-NOT: "-fsized-deallocation"
+
+// RUN: %clang_cl /c /std:c++11 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-BEFORE-CPP17 %s
+// RUN: %clang_cl /c /std:c++14 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-BEFORE-CPP17 %s
+// RUN: %clang_cl /c /std:c++17 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-CPP17ONWARDS %s
+// RUN: %clang_cl /c /std:c++20 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-CPP17ONWARDS %s
+// RUN: %clang_cl /c /std:c++latest -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-CPP17ONWARDS %s
+// ALIGNED-NEW-BEFORE-CPP17-NOT: "-faligned-allocation"
+// ALIGNED-NEW-CPP17ONWARDS: "-faligned-allocation"
+
 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=TRIGRAPHS-DEFAULT %s
 // cc1 will disa

[clang] 452db15 - [clang] Don't use Optional::hasValue (NFC)

2022-06-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-06-20T10:51:34-07:00
New Revision: 452db157c963b2897a0882e3bb05ef845b9e4015

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

LOG: [clang] Don't use Optional::hasValue (NFC)

Added: 


Modified: 
clang/include/clang/APINotes/Types.h
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/TypeProperties.td
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
clang/lib/ARCMigrate/Transforms.cpp
clang/lib/AST/ComputeDependence.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/ASTMatchers/Dynamic/Parser.cpp
clang/lib/Analysis/ReachableCode.cpp
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/DirectoryWatcher/DirectoryScanner.cpp
clang/lib/Driver/ToolChains/AVR.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Lex/TokenLexer.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp
clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/StringChecker.cpp
clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/lib/StaticAnalyzer/Core/CallDescription.cpp
clang/lib/StaticAnalyzer/Core/CallEvent.cpp
clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/RegionStore.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
clang/lib/Tooling/Transformer/Stencil.cpp
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/APINotes/Types.h 
b/clang/include/clang/APINotes/Types.h
index 0df710152e7a9..f00e41b7c9558 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -676,7 +676,7 @@ class TagInfo : public CommonTypeInfo {
 if (!HasFlagEnum && HasFlagEnum)
   setFlagEnum(RHS.isFlagEnum());
 
-if (!EnumExtensibility.hasValue())
+if (!EnumExtensibility)
   EnumExtensibility = RHS.EnumExtensibility;
 
 return *this;
@@ -706,7 +706,7 @@ class TypedefInfo : public CommonTypeInfo {
 
   TypedefInfo &operator|=(const TypedefInfo &RHS) {
 static_cast(*this) |= RHS;
-if (!SwiftWrapper.hasValue())
+if (!SwiftWrapper)
   SwiftWrapper = RHS.SwiftWrapper;
 return *this;
   }

diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index fe22930e0fb11..7db6af9cb87d6 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2554,7 +2554,7 @@ class ASTContext : public RefCountedBase {
bool IsParam) const {
 auto SubTnullability = SubT->getNullability(*this);
 auto SuperTnullability = SuperT->getNullability(*this);
-if (SubTnullability.hasValue() == SuperTnullability.hasValue()) {
+if (SubTnullability.has_value() == SuperTnullability.has_value()) {
   // Neither has nullability; return true
   if (!SubTnullability)
 return true;

diff  --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index 54d89d43a66a7..c46b0bd68cadc 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -671,7 +671,7 @@ let Class = TemplateSpecializationType in {
 
   def : Creator<[{
 QualType result;
-if (!underlyingType.hasValue()) {
+if (!underlyingType) {
   result = ctx.getCanonicalTemplateSpecializationType(templateName,
   templateArguments);
 } else {

diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index e4878d4e01564..250ba4f528968 100644
--- 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -129,7 +129,7 @@ class SMTConstraintManager : public 
clang::ento::SimpleConstraintManager {
 
   // Constraints are unsatisfiable
   Optional isSat = Solver->check();
-

[clang] 5413bf1 - Don't use Optional::hasValue (NFC)

2022-06-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-06-20T11:33:56-07:00
New Revision: 5413bf1bac2abb9e06901686cdc959e92940143a

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

LOG: Don't use Optional::hasValue (NFC)

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/IncludeFixer.cpp
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/SemanticSelection.cpp
clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
clang-tools-extra/clangd/tool/Check.cpp
clang-tools-extra/pseudo/lib/DirectiveTree.cpp
clang-tools-extra/pseudo/lib/Forest.cpp
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
flang/include/flang/Lower/IterationSpace.h
flang/lib/Lower/Bridge.cpp
flang/lib/Lower/ConvertExpr.cpp
flang/lib/Lower/IO.cpp
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
flang/lib/Optimizer/Support/InternalNames.cpp
lld/COFF/Driver.cpp
lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/ELF/LinkerScript.cpp
lld/wasm/Driver.cpp
lld/wasm/InputFiles.cpp
lld/wasm/Writer.cpp
lldb/source/Breakpoint/BreakpointIDList.cpp
lldb/source/Commands/CommandObjectFrame.cpp
lldb/source/Core/Debugger.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp
lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Utility/SelectHelper.cpp
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/Analysis/IRSimilarityIdentifier.cpp
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/lib/DWARFLinker/DWARFLinker.cpp
llvm/lib/DebugInfo/CodeView/ContinuationRecordBuilder.cpp
llvm/lib/DebugInfo/CodeView/SymbolSerializer.cpp
llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
llvm/lib/IR/Function.cpp
llvm/lib/IR/IntrinsicInst.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/lib/Target/Mips/MipsTargetStreamer.h
llvm/lib/Transforms/IPO/IROutliner.cpp
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/utils/TableGen/GlobalISelEmitter.cpp
mlir/lib/Analysis/Presburger/Simplex.cpp
mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
mlir/lib/Dialect/Affine/Utils/Utils.cpp

mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp
mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
mlir/lib/Tools/lsp-server-support/Protocol.cpp
mlir/test/lib/IR/TestSymbolUses.cpp
mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
mlir/tools/mlir-tblgen/RewriterGen.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
index b107dd7385c65..6c5d86a69821b 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
@@ -53,7 +53,7 @@ void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS) {
 }
 
 void ClangTidyProfiling::storeProfileData() {
-  assert(Storage.hasValue() && "We should have a filename.");
+  assert(Storage && "We should have a filename.");
 
   llvm::SmallString<256> OutputDirectory(Storage->StoreFilename);
   llvm::sys::path::remove_filename(OutputDirectory);
@@ -80,7 +80,7 @@ 
ClangTidyProfiling::ClangTidyProfiling(llvm::Optional Storage)
 ClangTidyProfiling::~ClangTidyProfiling() {
   TG.emplace("clang-tidy", "clang-tidy checks profiling", Records);
 
-  if (!Storage.hasValue())
+  if (!Storage)
 printUserFriendlyTable(llvm::errs());
   else
 storeProfileData();

diff  --git

  1   2   >