[PATCH] D137232: [clang][Interp] Support inc/dec operators on pointers

2022-11-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I think this is pretty uncommon so I was trying to implement it without adding 
new opcodes, but looks like that's not possible.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137232

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/arrays.cpp

Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -206,9 +206,6 @@
 static_assert(b.a[1].a == 12, "");
 
 namespace IncDec {
-  // FIXME: Pointer arithmethic needs to be supported in inc/dec
-  //   unary operators
-#if 0
   constexpr int getNextElem(const int *A, int I) {
 const int *B = (A + I);
 ++B;
@@ -216,6 +213,59 @@
   }
   constexpr int E[] = {1,2,3,4};
 
-  static_assert(getNextElem(E, 1) == 3);
-#endif
+  static_assert(getNextElem(E, 1) == 3, "");
+
+  constexpr int getFirst() {
+const int *e = E;
+return *(e++);
+  }
+  static_assert(getFirst() == 1, "");
+
+  constexpr int getFirst2() {
+const int *e = E;
+e++;
+return *e;
+  }
+  static_assert(getFirst2() == 2, "");
+
+  constexpr int getSecond() {
+const int *e = E;
+return *(++e);
+  }
+  static_assert(getSecond() == 2, "");
+
+  constexpr int getSecond2() {
+const int *e = E;
+++e;
+return *e;
+  }
+  static_assert(getSecond2() == 2, "");
+
+  constexpr int getLast() {
+const int *e = E + 3;
+return *(e--);
+  }
+  static_assert(getLast() == 4, "");
+
+  constexpr int getLast2() {
+const int *e = E + 3;
+e--;
+return *e;
+  }
+  static_assert(getLast2() == 3, "");
+
+  constexpr int getSecondToLast() {
+const int *e = E + 3;
+return *(--e);
+  }
+  static_assert(getSecondToLast() == 3, "");
+
+  constexpr int getSecondToLast2() {
+const int *e = E + 3;
+--e;
+return *e;
+  }
+  static_assert(getSecondToLast2() == 3, "");
+
+
 };
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -412,12 +412,21 @@
 // [Pointer, Integral] -> [Pointer]
 def SubOffset : AluOpcode;
 
-// Pointer, Pointer] - [Integral]
+// [Pointer, Pointer] -> [Integral]
 def SubPtr : Opcode {
   let Types = [IntegerTypeClass];
   let HasGroup = 1;
 }
 
+// [Pointer] -> []
+def IncPtr : Opcode {
+  let HasGroup = 0;
+}
+// [Pointer] -> []
+def DecPtr : Opcode {
+  let HasGroup = 0;
+}
+
 //===--===//
 // Binary operators.
 //===--===//
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -110,6 +110,8 @@
 /// Interpreter entry point.
 bool Interpret(InterpState &S, APValue &Result);
 
+enum class ArithOp { Add, Sub };
+
 //===--===//
 // Add, Sub, Mul
 //===--===//
@@ -1141,6 +1143,34 @@
   return OffsetHelper(S, OpPC);
 }
 
+template 
+static inline bool IncDecPtrHelper(InterpState &S, CodePtr OpPC) {
+  using OneT = Integral<8, false>;
+  const Pointer &Ptr = S.Stk.pop();
+
+  // Get the current value on the stack.
+  S.Stk.push(Ptr.deref());
+
+  // Now the current Ptr again and a constant 1.
+  // FIXME: We shouldn't have to push these two on the stack.
+  S.Stk.push(Ptr.deref());
+  S.Stk.push(OneT::from(1));
+  if (!OffsetHelper(S, OpPC))
+return false;
+
+  // Store the new value.
+  Ptr.deref() = S.Stk.pop();
+  return true;
+}
+
+static inline bool IncPtr(InterpState &S, CodePtr OpPC) {
+  return IncDecPtrHelper(S, OpPC);
+}
+
+static inline bool DecPtr(InterpState &S, CodePtr OpPC) {
+  return IncDecPtrHelper(S, OpPC);
+}
+
 /// 1) Pops a Pointer from the stack.
 /// 2) Pops another Pointer from the stack.
 /// 3) Pushes the different of the indices of the two pointers on the stack.
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1406,24 +1406,44 @@
   const Expr *SubExpr = E->getSubExpr();
   Optional T = classify(SubExpr->getType());
 
-  // TODO: Support pointers for inc/dec operators.
   switch (E->getOpcode()) {
   case UO_PostInc: { // x++
 if (!this->visit(SubExpr))
   return false;
 
+if (T == PT_Ptr) {
+  if (!this->emitIncPtr(E))
+return false;

[PATCH] D137232: [clang][Interp] Support inc/dec operators on pointers

2022-11-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 472526.

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

https://reviews.llvm.org/D137232

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/arrays.cpp

Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -206,9 +206,6 @@
 static_assert(b.a[1].a == 12, "");
 
 namespace IncDec {
-  // FIXME: Pointer arithmethic needs to be supported in inc/dec
-  //   unary operators
-#if 0
   constexpr int getNextElem(const int *A, int I) {
 const int *B = (A + I);
 ++B;
@@ -216,6 +213,59 @@
   }
   constexpr int E[] = {1,2,3,4};
 
-  static_assert(getNextElem(E, 1) == 3);
-#endif
+  static_assert(getNextElem(E, 1) == 3, "");
+
+  constexpr int getFirst() {
+const int *e = E;
+return *(e++);
+  }
+  static_assert(getFirst() == 1, "");
+
+  constexpr int getFirst2() {
+const int *e = E;
+e++;
+return *e;
+  }
+  static_assert(getFirst2() == 2, "");
+
+  constexpr int getSecond() {
+const int *e = E;
+return *(++e);
+  }
+  static_assert(getSecond() == 2, "");
+
+  constexpr int getSecond2() {
+const int *e = E;
+++e;
+return *e;
+  }
+  static_assert(getSecond2() == 2, "");
+
+  constexpr int getLast() {
+const int *e = E + 3;
+return *(e--);
+  }
+  static_assert(getLast() == 4, "");
+
+  constexpr int getLast2() {
+const int *e = E + 3;
+e--;
+return *e;
+  }
+  static_assert(getLast2() == 3, "");
+
+  constexpr int getSecondToLast() {
+const int *e = E + 3;
+return *(--e);
+  }
+  static_assert(getSecondToLast() == 3, "");
+
+  constexpr int getSecondToLast2() {
+const int *e = E + 3;
+--e;
+return *e;
+  }
+  static_assert(getSecondToLast2() == 3, "");
+
+
 };
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -412,12 +412,21 @@
 // [Pointer, Integral] -> [Pointer]
 def SubOffset : AluOpcode;
 
-// Pointer, Pointer] - [Integral]
+// [Pointer, Pointer] -> [Integral]
 def SubPtr : Opcode {
   let Types = [IntegerTypeClass];
   let HasGroup = 1;
 }
 
+// [Pointer] -> []
+def IncPtr : Opcode {
+  let HasGroup = 0;
+}
+// [Pointer] -> []
+def DecPtr : Opcode {
+  let HasGroup = 0;
+}
+
 //===--===//
 // Binary operators.
 //===--===//
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -110,6 +110,8 @@
 /// Interpreter entry point.
 bool Interpret(InterpState &S, APValue &Result);
 
+enum class ArithOp { Add, Sub };
+
 //===--===//
 // Add, Sub, Mul
 //===--===//
@@ -1141,6 +1143,34 @@
   return OffsetHelper(S, OpPC);
 }
 
+template 
+static inline bool IncDecPtrHelper(InterpState &S, CodePtr OpPC) {
+  using OneT = Integral<8, false>;
+  const Pointer &Ptr = S.Stk.pop();
+
+  // Get the current value on the stack.
+  S.Stk.push(Ptr.deref());
+
+  // Now the current Ptr again and a constant 1.
+  // FIXME: We shouldn't have to push these two on the stack.
+  S.Stk.push(Ptr.deref());
+  S.Stk.push(OneT::from(1));
+  if (!OffsetHelper(S, OpPC))
+return false;
+
+  // Store the new value.
+  Ptr.deref() = S.Stk.pop();
+  return true;
+}
+
+static inline bool IncPtr(InterpState &S, CodePtr OpPC) {
+  return IncDecPtrHelper(S, OpPC);
+}
+
+static inline bool DecPtr(InterpState &S, CodePtr OpPC) {
+  return IncDecPtrHelper(S, OpPC);
+}
+
 /// 1) Pops a Pointer from the stack.
 /// 2) Pops another Pointer from the stack.
 /// 3) Pushes the different of the indices of the two pointers on the stack.
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1406,24 +1406,44 @@
   const Expr *SubExpr = E->getSubExpr();
   Optional T = classify(SubExpr->getType());
 
-  // TODO: Support pointers for inc/dec operators.
   switch (E->getOpcode()) {
   case UO_PostInc: { // x++
 if (!this->visit(SubExpr))
   return false;
 
+if (T == PT_Ptr) {
+  if (!this->emitIncPtr(E))
+return false;
+
+  return DiscardResult ? this->emitPopPtr(E) : true;
+}
+
 return DiscardResult ? this->emitIncPop(*T, E) : this->emitInc(*T, E);
   }
   case UO_PostDec: { // x--
 if (!this->visit(SubExpr))
   return false;
 
+if (T == PT_Ptr) {
+  if (!this->emitDecPtr(E))
+ret

[clang] c49db59 - [CLANG] XFAIL c-strings.c & volatile-1.c AArch64/Windows

2022-11-02 Thread Muhammad Omair Javaid via cfe-commits

Author: Muhammad Omair Javaid
Date: 2022-11-02T12:32:21+04:00
New Revision: c49db597a131576160ab8d1e19575853afbc7077

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

LOG: [CLANG] XFAIL c-strings.c & volatile-1.c AArch64/Windows

c-strings.c and volatile-1.c failing due to alignment issue on WoA. I am
going to mark them as XFAIL for now.

Added: 


Modified: 
clang/test/CodeGen/c-strings.c
clang/test/CodeGen/volatile-1.c

Removed: 




diff  --git a/clang/test/CodeGen/c-strings.c b/clang/test/CodeGen/c-strings.c
index 692a42d326d2e..ebb3217ca48a7 100644
--- a/clang/test/CodeGen/c-strings.c
+++ b/clang/test/CodeGen/c-strings.c
@@ -1,3 +1,4 @@
+// XFAIL: aarch64-pc-windows-msvc
 // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck 
%s --check-prefix=CHECK --check-prefix=ITANIUM
 // RUN: %clang_cc1 -triple %ms_abi_triple -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK --check-prefix=MSABI
 

diff  --git a/clang/test/CodeGen/volatile-1.c b/clang/test/CodeGen/volatile-1.c
index 3e7eacb97abd6..d27abbfdbef15 100644
--- a/clang/test/CodeGen/volatile-1.c
+++ b/clang/test/CodeGen/volatile-1.c
@@ -1,3 +1,4 @@
+// XFAIL: aarch64-pc-windows-msvc
 // RUN: %clang_cc1 -Wno-return-type -Wno-unused-value -emit-llvm %s -w -o - | 
FileCheck %s
 
 // CHECK: @i = {{(dso_local )?}}global [[INT:i[0-9]+]] 0



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


[PATCH] D136925: [clangd] Index unscoped enums inside classes for code completion

2022-11-02 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Thanks!

I don't think we need this much detail in the commit message; I think after the 
first line it would be sufficient to say:

  Fixes https://github.com/clangd/clangd/issues/1082
  See the issue for disk/memory usage measurements

(Note also that "Fixes " triggers the github issue to be closed when the 
commit is merged.)

I forget whether you have commit access -- let me know if you need me to merge 
the patch for you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136925

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


[PATCH] D137104: [clangd] Add scoped enum constants to all-scopes-completion

2022-11-02 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

The test added in the previous patch, `CompletionTest.Enums`, needs to be 
updated to reflect this change (`Scoped::Clangd3` now appears as a completion).




Comment at: clang-tools-extra/clangd/CodeComplete.cpp:2136
+  if (llvm::isa(ND.getDeclContext()))
+return true;
 

Why remove the `(InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl))` part?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137104

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


[PATCH] D137227: [asan] Default to -fsanitize-address-use-odr-indicator for non-Windows

2022-11-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 472533.
MaskRay retitled this revision from "[asan] Default to 
-fsanitize-address-use-odr-indicator" to "[asan] Default to 
-fsanitize-address-use-odr-indicator for non-Windows".
MaskRay edited the summary of this revision.
MaskRay added a comment.
Herald added a subscriber: mstorsjo.

exclude Windows for its weak symbol issue


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137227

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/asan-globals-odr.cpp
  clang/test/CodeGen/asan-static-odr.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/test/asan/TestCases/Linux/odr-violation.cpp
  compiler-rt/test/asan/TestCases/Linux/odr_indicators.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/local_alias.ll
  llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll

Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -passes=asan -S | FileCheck %s
+; RUN: opt < %s -passes=asan -asan-use-odr-indicator=0 -asan-use-private-alias=0 -S | FileCheck %s
 
 ; Generated like so:
 ; $ clang -S -emit-llvm -Xclang -disable-llvm-passes -fsanitize=address -O1 t.cpp -o t.ll
Index: llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
+++ llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
@@ -1,5 +1,5 @@
-; RUN: opt < %s -passes=asan -asan-use-private-alias=0 -S | FileCheck %s --check-prefix=NOALIAS
-; RUN: opt < %s -passes=asan -asan-use-private-alias=1 -S | FileCheck %s --check-prefix=ALIAS
+; RUN: opt < %s -passes=asan -asan-use-odr-indicator=0 -asan-use-private-alias=0 -S | FileCheck %s --check-prefix=NOALIAS
+; RUN: opt < %s -passes=asan -asan-use-odr-indicator=0 -asan-use-private-alias=1 -S | FileCheck %s --check-prefix=ALIAS
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
Index: llvm/test/Instrumentation/AddressSanitizer/local_alias.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/local_alias.ll
+++ llvm/test/Instrumentation/AddressSanitizer/local_alias.ll
@@ -1,5 +1,5 @@
 ; Defaults
-; RUN: opt < %s -passes=asan -S | FileCheck %s --check-prefixes=CHECK-NOALIAS,CHECK-NOINDICATOR
+; RUN: opt < %s -passes=asan -S | FileCheck %s --check-prefixes=CHECK-ALIAS,CHECK-INDICATOR
 
 ; {newPM,legacyPM} x {alias0,alias1} x {odr0,odr1}
 ; RUN: opt < %s -passes=asan -asan-use-private-alias=0 -asan-use-odr-indicator=0 -S | FileCheck %s --check-prefixes=CHECK-NOALIAS,CHECK-NOINDICATOR
Index: llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
+++ llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
@@ -5,9 +5,9 @@
 ; enabled as indicator symbols will cause link time odr violations.
 ; This is to fix PR 47925.
 ;
-; RUN: opt < %s -passes=asan -asan-globals-live-support=1 -S | FileCheck %s --check-prefixes=CHECK,NOCOMDAT
+; RUN: opt < %s -passes=asan -asan-globals-live-support=1 -asan-use-odr-indicator=0 -S | FileCheck %s --check-prefixes=CHECK,NOCOMDAT
 ; Check that enabling odr indicators enables comdat for globals.
-; RUN: opt < %s -passes=asan -asan-globals-live-support=1 -asan-use-odr-indicator=1 -S | FileCheck %s --check-prefixes=CHECK,COMDAT
+; RUN: opt < %s -passes=asan -asan-globals-live-support=1 -S | FileCheck %s --check-prefixes=CHECK,COMDAT
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 
@@ -43,8 +43,8 @@
 
 ; Check emitted location descriptions:
 ; CHECK: [[VARNAME:@___asan_gen_.[0-9]+]] = private unnamed_addr constant [7 x i8] c"global\00", align 1
-; COMDAT: @__asan_global_global = {{.*}}i64 ptrtoint (ptr @global to i64){{.*}} section "asan_globals"{{.*}}, !associated
-; COMDAT: @__asan_global_.str = {{.*}}i64 ptrtoint (ptr @{{.str|1}} to i64){{.*}} section "asan_globals"{{.*}}, !associated
+; COMDAT: @__asan_global_global = {{.*}}i64 ptrtoint (ptr @__odr_asan_gen_global to i64){{.*}} section "asan_globals"{{.*}}, comdat(

[PATCH] D121593: [clangd][WIP] Provide clang-include-cleaner

2022-11-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Hi @Abpostelnicu, as @nridge pointed out. we're actively working on the library 
pieces of include-cleaner and applications of the library aren't the focus yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121593

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


[PATCH] D137223: [clang-format] Remove special case for kw_operator when aligning decls

2022-11-02 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:17939
Alignment);
+  // Ensure operators are not aligned if they're being called, not declared
+  verifyFormat("int main() {\n"

Add a full stop.



Comment at: clang/unittests/Format/FormatTest.cpp:17939-17946
+  // Ensure operators are not aligned if they're being called, not declared
+  verifyFormat("int main() {\n"
+   "  intoperator()(int a);\n"
+   "  double operator+(double a);\n"
+   "  operator()(1);\n"
+   "  operator+(1.0);\n"
+   "};\n",

owenpan wrote:
> Add a full stop.
Consider using a test case similar to the examples in 
https://github.com/llvm/llvm-project/issues/55733 or not adding a test case at 
all as the added annotator tests will cover it.



Comment at: clang/unittests/Format/FormatTest.cpp:17945
+   "  operator+(1.0);\n"
+   "};\n",
+   Alignment);

Remove the newline.



Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:441-456
+  Tokens = annotate("int operator+(int);");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::plus, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("auto operator=(T&) {}");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;

Instead of adding new tests, you can add checks for `kw_operator` and 
`TT_FunctionDeclarationName` to the existing ones.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137223

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


[PATCH] D137235: [clang][Interp] Fix ImplicitValueInitExprs for pointer types

2022-11-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  This previously ran into an "unknown type" assertion when trying to emit
  a 'Zero' op for a pointer type. Emit a NullPtr op instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137235

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -49,7 +49,10 @@
   static_assert(!nu, "");
 };
 
-
+constexpr int UninitI; // expected-error {{must be initialized by a constant 
expression}} \
+   // ref-error {{must be initialized by a constant 
expression}}
+constexpr int *UninitPtr; // expected-error {{must be initialized by a 
constant expression}} \
+  // ref-error {{must be initialized by a constant 
expression}}
 
 constexpr bool getTrue() { return true; }
 constexpr bool getFalse() { return false; }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -359,10 +359,15 @@
 
 template 
 bool ByteCodeExprGen::VisitImplicitValueInitExpr(const 
ImplicitValueInitExpr *E) {
-  if (Optional T = classify(E))
-return this->emitZero(*T, E);
+  Optional T = classify(E);
 
-  return false;
+  if (!T)
+return false;
+
+  if (E->getType()->isPointerType())
+return this->emitNullPtr(E);
+
+  return this->emitZero(*T, E);
 }
 
 template 


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -49,7 +49,10 @@
   static_assert(!nu, "");
 };
 
-
+constexpr int UninitI; // expected-error {{must be initialized by a constant expression}} \
+   // ref-error {{must be initialized by a constant expression}}
+constexpr int *UninitPtr; // expected-error {{must be initialized by a constant expression}} \
+  // ref-error {{must be initialized by a constant expression}}
 
 constexpr bool getTrue() { return true; }
 constexpr bool getFalse() { return false; }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -359,10 +359,15 @@
 
 template 
 bool ByteCodeExprGen::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
-  if (Optional T = classify(E))
-return this->emitZero(*T, E);
+  Optional T = classify(E);
 
-  return false;
+  if (!T)
+return false;
+
+  if (E->getType()->isPointerType())
+return this->emitNullPtr(E);
+
+  return this->emitZero(*T, E);
 }
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136957: [AArch64] Add support for the Cortex-A715 CPU

2022-11-02 Thread Victor Campos via Phabricator via cfe-commits
vhscampos added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:699
+
+  * Arm cortex-A715 (cortex-a715).
 

Please capitalise the first cortex-A715. It should be "Arm Cortex-A715".



Comment at: llvm/docs/ReleaseNotes.rst:84
 
+* Added support for the cortex-a715 CPU.
+

Please capitalise. "Cortex-A715".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136957

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


[PATCH] D137239: [AArch64] Install arm_neon_sve_bridge.h

2022-11-02 Thread Peter Waller via Phabricator via cfe-commits
peterwaller-arm created this revision.
peterwaller-arm added reviewers: MattDevereau, benmxwl-arm, c-rhodes.
Herald added subscribers: ctetreau, kristof.beyls, tschuett.
Herald added a project: All.
peterwaller-arm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

arm_neon_sve_bridge.h is not generated, so the rules which ensure the
generated files get copied into the installation prefix don't apply to
this one.

Add it to the aarch64_only_files set instead, which ensures it ends up
both in the build directory and the installation directory.

Tested with build targets `clang-resource-headers` and
`install-clang-resource-headers`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137239

Files:
  clang/lib/Headers/CMakeLists.txt


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -33,6 +33,7 @@
 
 set(aarch64_only_files
   arm64intr.h
+  arm_neon_sve_bridge.h
   )
 
 set(cuda_files
@@ -326,10 +327,6 @@
   clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
   # Generate arm_cde.h
   clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
-  # Copy arm_neon_sve_bridge.h
-  copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR}
-arm_neon_sve_bridge.h
-  )
 
   # Add headers to target specific lists
   list(APPEND arm_common_generated_files
@@ -345,7 +342,6 @@
   list(APPEND aarch64_only_generated_files
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sve.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_bf16.h"
-"${output_dir}/arm_neon_sve_bridge.h"
 )
 endif()
 if(RISCV IN_LIST LLVM_TARGETS_TO_BUILD)


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -33,6 +33,7 @@
 
 set(aarch64_only_files
   arm64intr.h
+  arm_neon_sve_bridge.h
   )
 
 set(cuda_files
@@ -326,10 +327,6 @@
   clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
   # Generate arm_cde.h
   clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
-  # Copy arm_neon_sve_bridge.h
-  copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR}
-arm_neon_sve_bridge.h
-  )
 
   # Add headers to target specific lists
   list(APPEND arm_common_generated_files
@@ -345,7 +342,6 @@
   list(APPEND aarch64_only_generated_files
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sve.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_bf16.h"
-"${output_dir}/arm_neon_sve_bridge.h"
 )
 endif()
 if(RISCV IN_LIST LLVM_TARGETS_TO_BUILD)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136957: [AArch64] Add support for the Cortex-A715 CPU

2022-11-02 Thread Simi Pallipurath via Phabricator via cfe-commits
simpal01 updated this revision to Diff 472560.
simpal01 marked 2 inline comments as done.
simpal01 added a comment.

Comments addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136957

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-mcpu.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1016,6 +1016,19 @@
  AArch64::AEK_FLAGM | AArch64::AEK_SB |
  AArch64::AEK_I8MM | AArch64::AEK_BF16,
  "9-A"),
+ARMCPUTestParams("cortex-a715", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP | AArch64::AEK_BF16 |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ AArch64::AEK_MTE | AArch64::AEK_PAUTH |
+ AArch64::AEK_SVE | AArch64::AEK_SVE2 |
+ AArch64::AEK_SVE2BITPERM | AArch64::AEK_SSBS |
+ AArch64::AEK_SB | AArch64::AEK_I8MM |
+ AArch64::AEK_PERFMON | AArch64::AEK_PREDRES |
+ AArch64::AEK_PROFILE | AArch64::AEK_FP16FML |
+ AArch64::AEK_FP16 | AArch64::AEK_FLAGM,
+ "9-A"),
 ARMCPUTestParams(
 "neoverse-v1", "armv8.4-a", "crypto-neon-fp-armv8",
 AArch64::AEK_RAS | AArch64::AEK_SVE | AArch64::AEK_SSBS |
@@ -1296,7 +1309,7 @@
  "8.2-A")));
 
 // Note: number of CPUs includes aliases.
-static constexpr unsigned NumAArch64CPUArchs = 59;
+static constexpr unsigned NumAArch64CPUArchs = 60;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -64,6 +64,7 @@
 CortexA78,
 CortexA78C,
 CortexA710,
+CortexA715,
 CortexR82,
 CortexX1,
 CortexX1C,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -142,6 +142,7 @@
 MaxBytesForLoopAlignment = 8;
 break;
   case CortexA710:
+  case CortexA715:
   case CortexX2:
 PrefFunctionLogAlignment = 4;
 VScaleForTuning = 1;
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -764,6 +764,14 @@
FeatureLSLFast,
FeaturePostRAScheduler]>;
 
+def TuneA715 : SubtargetFeature<"a715", "ARMProcFamily", "CortexA715",
+ "Cortex-A715 ARM processors", [
+ FeatureFuseAES,
+ FeaturePostRAScheduler,
+ FeatureCmpBccFusion,
+ FeatureLSLFast,
+ FeatureFuseAdrpAdd]>;
+
 def TuneR82 : SubtargetFeature<"cortex-r82", "ARMProcFamily",
"CortexR82",
"Cortex-R82 ARM processors", [
@@ -1093,6 +1101,10 @@
   list A710 = [HasV9_0aOps, FeatureNEON, FeaturePerfMon,
  FeatureETE, FeatureMTE, FeatureFP16FML,
  FeatureSVE2BitPerm, FeatureBF16, FeatureMatMulInt8];
+  list A715 = [HasV9_0aOps, FeatureNEON, FeatureMTE,
+ FeatureFP16FML, FeatureSVE, FeatureTRBE,
+ FeatureSVE2BitPerm, FeatureBF16, FeatureETE,
+ FeaturePerfMon, FeatureMatMulInt8, FeatureSPE];
   list R82  = [HasV8_0rOps, FeaturePerfMon, FeatureFullFP16,
  FeatureFP16FML, FeatureSSBS, FeaturePredRes,
  FeatureSB];
@@ -1231,6 +1243,8 @@
  [TuneA78C]>;
 def : ProcessorModel<"cortex-a710", NeoverseN2Model, ProcessorFeatures.A710,
  [TuneA710]>;
+def : ProcessorMode

[PATCH] D137240: [clang][Interp] Support alignof()

2022-11-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The test is just a copy of `clang/test/SemaCXX/class-layout.cpp`, but with the 
`__builtin_offsetof` calls commented out.

Not sure if this is the best way to test it, but adding special cases for the 
new interpreter to existing test cases doesn't seem like a good option either.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137240

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/class-layout.cpp

Index: clang/test/AST/Interp/class-layout.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/class-layout.cpp
@@ -0,0 +1,682 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
+// expected-no-diagnostics
+
+#define SA(n, p) int a##n[(p) ? 1 : -1]
+
+struct A {
+  int a;
+  char b;
+};
+
+SA(0, sizeof(A) == 8);
+
+struct B : A {
+  char c;
+};
+
+SA(1, sizeof(B) == 12);
+
+struct C {
+// Make fields private so C won't be a POD type.
+private:
+  int a;
+  char b;
+};
+
+SA(2, sizeof(C) == 8);
+
+struct D : C {
+  char c;
+};
+
+SA(3, sizeof(D) == 8);
+
+struct __attribute__((packed)) E {
+  char b;
+  int a;
+};
+
+SA(4, sizeof(E) == 5);
+
+struct __attribute__((packed)) F : E {
+  char d;
+};
+
+SA(5, sizeof(F) == 6);
+
+struct G { G(); };
+struct H : G { };
+
+SA(6, sizeof(H) == 1);
+
+struct I {
+  char b;
+  int a;
+} __attribute__((packed));
+
+SA(6_1, sizeof(I) == 5);
+
+// PR5580
+namespace PR5580 {
+
+class A { bool iv0 : 1; };
+SA(7, sizeof(A) == 1);  
+
+class B : A { bool iv0 : 1; };
+SA(8, sizeof(B) == 2);
+
+struct C { bool iv0 : 1; };
+SA(9, sizeof(C) == 1);  
+
+struct D : C { bool iv0 : 1; };
+SA(10, sizeof(D) == 2);
+
+}
+
+namespace Test1 {
+
+// Test that we don't assert on this hierarchy.
+struct A { };
+struct B : A { virtual void b(); };
+class C : virtual A { int c; };
+struct D : virtual B { };
+struct E : C, virtual D { };
+class F : virtual E { };
+struct G : virtual E, F { };
+
+SA(0, sizeof(G) == 24);
+
+}
+
+namespace Test2 {
+
+// Test that this somewhat complex class structure is laid out correctly.
+struct A { };
+struct B : A { virtual void b(); };
+struct C : virtual B { };
+struct D : virtual A { };
+struct E : virtual B, D { };
+struct F : E, virtual C { };
+struct G : virtual F, A { };
+struct H { G g; };
+
+SA(0, sizeof(H) == 24);
+
+}
+
+namespace PR16537 {
+namespace test1 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11;
+char tail_padding;
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only {
+char may_go_into_tail_padding;
+  };
+
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test2 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11 __attribute__((aligned(16)));
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only {
+char may_go_into_tail_padding;
+  };
+
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test3 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_

[PATCH] D137240: [clang][Interp] Support alignof()

2022-11-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 472562.

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

https://reviews.llvm.org/D137240

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/class-layout.cpp

Index: clang/test/AST/Interp/class-layout.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/class-layout.cpp
@@ -0,0 +1,682 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
+// expected-no-diagnostics
+
+#define SA(n, p) int a##n[(p) ? 1 : -1]
+
+struct A {
+  int a;
+  char b;
+};
+
+SA(0, sizeof(A) == 8);
+
+struct B : A {
+  char c;
+};
+
+SA(1, sizeof(B) == 12);
+
+struct C {
+// Make fields private so C won't be a POD type.
+private:
+  int a;
+  char b;
+};
+
+SA(2, sizeof(C) == 8);
+
+struct D : C {
+  char c;
+};
+
+SA(3, sizeof(D) == 8);
+
+struct __attribute__((packed)) E {
+  char b;
+  int a;
+};
+
+SA(4, sizeof(E) == 5);
+
+struct __attribute__((packed)) F : E {
+  char d;
+};
+
+SA(5, sizeof(F) == 6);
+
+struct G { G(); };
+struct H : G { };
+
+SA(6, sizeof(H) == 1);
+
+struct I {
+  char b;
+  int a;
+} __attribute__((packed));
+
+SA(6_1, sizeof(I) == 5);
+
+// PR5580
+namespace PR5580 {
+
+class A { bool iv0 : 1; };
+SA(7, sizeof(A) == 1);  
+
+class B : A { bool iv0 : 1; };
+SA(8, sizeof(B) == 2);
+
+struct C { bool iv0 : 1; };
+SA(9, sizeof(C) == 1);  
+
+struct D : C { bool iv0 : 1; };
+SA(10, sizeof(D) == 2);
+
+}
+
+namespace Test1 {
+
+// Test that we don't assert on this hierarchy.
+struct A { };
+struct B : A { virtual void b(); };
+class C : virtual A { int c; };
+struct D : virtual B { };
+struct E : C, virtual D { };
+class F : virtual E { };
+struct G : virtual E, F { };
+
+SA(0, sizeof(G) == 24);
+
+}
+
+namespace Test2 {
+
+// Test that this somewhat complex class structure is laid out correctly.
+struct A { };
+struct B : A { virtual void b(); };
+struct C : virtual B { };
+struct D : virtual A { };
+struct E : virtual B, D { };
+struct F : E, virtual C { };
+struct G : virtual F, A { };
+struct H { G g; };
+
+SA(0, sizeof(H) == 24);
+
+}
+
+namespace PR16537 {
+namespace test1 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11;
+char tail_padding;
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only {
+char may_go_into_tail_padding;
+  };
+
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test2 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11 __attribute__((aligned(16)));
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only {
+char may_go_into_tail_padding;
+  };
+
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test3 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11;
+char tail_padding;
+  };
+
+  struct second_base {
+  char foo;
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only, public second_base {
+
+  };
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test4 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11;
+char tail_padding;
+  };
+
+  struct second

[PATCH] D137240: [clang][Interp] Support alignof()

2022-11-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 472563.

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

https://reviews.llvm.org/D137240

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/class-layout.cpp

Index: clang/test/AST/Interp/class-layout.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/class-layout.cpp
@@ -0,0 +1,687 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
+// expected-no-diagnostics
+
+// FIXME: This is a copy of clang/test/SemaCXX/class-layout.cpp, but with the
+//   __builtin_offsetof calls commented out. Once that is supported in the
+//   new interpreter, we might as well remove this duplicated file and
+//   just use the one in SemaCXX/.
+
+#define SA(n, p) int a##n[(p) ? 1 : -1]
+
+struct A {
+  int a;
+  char b;
+};
+
+SA(0, sizeof(A) == 8);
+
+struct B : A {
+  char c;
+};
+
+SA(1, sizeof(B) == 12);
+
+struct C {
+// Make fields private so C won't be a POD type.
+private:
+  int a;
+  char b;
+};
+
+SA(2, sizeof(C) == 8);
+
+struct D : C {
+  char c;
+};
+
+SA(3, sizeof(D) == 8);
+
+struct __attribute__((packed)) E {
+  char b;
+  int a;
+};
+
+SA(4, sizeof(E) == 5);
+
+struct __attribute__((packed)) F : E {
+  char d;
+};
+
+SA(5, sizeof(F) == 6);
+
+struct G { G(); };
+struct H : G { };
+
+SA(6, sizeof(H) == 1);
+
+struct I {
+  char b;
+  int a;
+} __attribute__((packed));
+
+SA(6_1, sizeof(I) == 5);
+
+// PR5580
+namespace PR5580 {
+
+class A { bool iv0 : 1; };
+SA(7, sizeof(A) == 1);  
+
+class B : A { bool iv0 : 1; };
+SA(8, sizeof(B) == 2);
+
+struct C { bool iv0 : 1; };
+SA(9, sizeof(C) == 1);  
+
+struct D : C { bool iv0 : 1; };
+SA(10, sizeof(D) == 2);
+
+}
+
+namespace Test1 {
+
+// Test that we don't assert on this hierarchy.
+struct A { };
+struct B : A { virtual void b(); };
+class C : virtual A { int c; };
+struct D : virtual B { };
+struct E : C, virtual D { };
+class F : virtual E { };
+struct G : virtual E, F { };
+
+SA(0, sizeof(G) == 24);
+
+}
+
+namespace Test2 {
+
+// Test that this somewhat complex class structure is laid out correctly.
+struct A { };
+struct B : A { virtual void b(); };
+struct C : virtual B { };
+struct D : virtual A { };
+struct E : virtual B, D { };
+struct F : E, virtual C { };
+struct G : virtual F, A { };
+struct H { G g; };
+
+SA(0, sizeof(H) == 24);
+
+}
+
+namespace PR16537 {
+namespace test1 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11;
+char tail_padding;
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only {
+char may_go_into_tail_padding;
+  };
+
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test2 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11 __attribute__((aligned(16)));
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only {
+char may_go_into_tail_padding;
+  };
+
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test3 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11;
+char tail_padding;
+  };
+
+  struct second_base {
+  char foo;
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only, public second_base

[PATCH] D137240: [clang][Interp] Support alignof()

2022-11-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 472564.

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

https://reviews.llvm.org/D137240

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/class-layout.cpp

Index: clang/test/AST/Interp/class-layout.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/class-layout.cpp
@@ -0,0 +1,687 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
+// expected-no-diagnostics
+
+// FIXME: This is a copy of clang/test/SemaCXX/class-layout.cpp, but with the
+//   __builtin_offsetof calls commented out. Once that is supported in the
+//   new interpreter, we might as well remove this duplicated file and
+//   just use the one in SemaCXX/.
+
+#define SA(n, p) int a##n[(p) ? 1 : -1]
+
+struct A {
+  int a;
+  char b;
+};
+
+SA(0, sizeof(A) == 8);
+
+struct B : A {
+  char c;
+};
+
+SA(1, sizeof(B) == 12);
+
+struct C {
+// Make fields private so C won't be a POD type.
+private:
+  int a;
+  char b;
+};
+
+SA(2, sizeof(C) == 8);
+
+struct D : C {
+  char c;
+};
+
+SA(3, sizeof(D) == 8);
+
+struct __attribute__((packed)) E {
+  char b;
+  int a;
+};
+
+SA(4, sizeof(E) == 5);
+
+struct __attribute__((packed)) F : E {
+  char d;
+};
+
+SA(5, sizeof(F) == 6);
+
+struct G { G(); };
+struct H : G { };
+
+SA(6, sizeof(H) == 1);
+
+struct I {
+  char b;
+  int a;
+} __attribute__((packed));
+
+SA(6_1, sizeof(I) == 5);
+
+// PR5580
+namespace PR5580 {
+
+class A { bool iv0 : 1; };
+SA(7, sizeof(A) == 1);  
+
+class B : A { bool iv0 : 1; };
+SA(8, sizeof(B) == 2);
+
+struct C { bool iv0 : 1; };
+SA(9, sizeof(C) == 1);  
+
+struct D : C { bool iv0 : 1; };
+SA(10, sizeof(D) == 2);
+
+}
+
+namespace Test1 {
+
+// Test that we don't assert on this hierarchy.
+struct A { };
+struct B : A { virtual void b(); };
+class C : virtual A { int c; };
+struct D : virtual B { };
+struct E : C, virtual D { };
+class F : virtual E { };
+struct G : virtual E, F { };
+
+SA(0, sizeof(G) == 24);
+
+}
+
+namespace Test2 {
+
+// Test that this somewhat complex class structure is laid out correctly.
+struct A { };
+struct B : A { virtual void b(); };
+struct C : virtual B { };
+struct D : virtual A { };
+struct E : virtual B, D { };
+struct F : E, virtual C { };
+struct G : virtual F, A { };
+struct H { G g; };
+
+SA(0, sizeof(H) == 24);
+
+}
+
+namespace PR16537 {
+namespace test1 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11;
+char tail_padding;
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only {
+char may_go_into_tail_padding;
+  };
+
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test2 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11 __attribute__((aligned(16)));
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only {
+char may_go_into_tail_padding;
+  };
+
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test3 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11;
+char tail_padding;
+  };
+
+  struct second_base {
+  char foo;
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only, public second_base

[PATCH] D136925: [clangd] Index unscoped enums inside classes for code completion

2022-11-02 Thread Tom Praschan 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 rGa68bcd81dcc9: [clangd] Index unscoped enums in class scope 
for code completion (authored by tom-anders).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136925

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang-tools-extra/clangd/unittests/TestIndex.h

Index: clang-tools-extra/clangd/unittests/TestIndex.h
===
--- clang-tools-extra/clangd/unittests/TestIndex.h
+++ clang-tools-extra/clangd/unittests/TestIndex.h
@@ -27,6 +27,8 @@
 Symbol cls(llvm::StringRef Name);
 // Creates an enum symbol.
 Symbol enm(llvm::StringRef Name);
+// Creates an enum constant symbol.
+Symbol enmConstant(llvm::StringRef Name);
 // Creates a variable symbol.
 Symbol var(llvm::StringRef Name);
 // Creates a namespace symbol.
Index: clang-tools-extra/clangd/unittests/TestIndex.cpp
===
--- clang-tools-extra/clangd/unittests/TestIndex.cpp
+++ clang-tools-extra/clangd/unittests/TestIndex.cpp
@@ -69,6 +69,10 @@
   return sym(Name, index::SymbolKind::Enum, "@E@\\0");
 }
 
+Symbol enmConstant(llvm::StringRef Name) {
+  return sym(Name, index::SymbolKind::EnumConstant, "@\\0");
+}
+
 Symbol var(llvm::StringRef Name) {
   return sym(Name, index::SymbolKind::Variable, "@\\0");
 }
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1316,6 +1316,11 @@
   Black
 };
 }
+class Color3 {
+  enum {
+Blue
+  };
+};
   )";
   runSymbolCollector(Header, /*Main=*/"");
   EXPECT_THAT(Symbols,
@@ -1326,7 +1331,9 @@
   AllOf(qName("Color2"), forCodeCompletion(true)),
   AllOf(qName("Color2::Yellow"), forCodeCompletion(false)),
   AllOf(qName("ns"), forCodeCompletion(true)),
-  AllOf(qName("ns::Black"), forCodeCompletion(true;
+  AllOf(qName("ns::Black"), forCodeCompletion(true)),
+  AllOf(qName("Color3"), forCodeCompletion(true)),
+  AllOf(qName("Color3::Blue"), forCodeCompletion(true;
 }
 
 TEST_F(SymbolCollectorTest, NamelessSymbols) {
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -2967,14 +2967,20 @@
 }
   )cpp",
   {cls("nx::Clangd1"), cls("ny::Clangd2"), cls("Clangd3"),
-   cls("na::nb::Clangd4")},
+   cls("na::nb::Clangd4"), enmConstant("na::C::Clangd5")},
   Opts);
   EXPECT_THAT(
   Results.Completions,
-  UnorderedElementsAre(AllOf(qualifier("nx::"), named("Clangd1")),
-   AllOf(qualifier("ny::"), named("Clangd2")),
-   AllOf(qualifier(""), scope(""), named("Clangd3")),
-   AllOf(qualifier("nb::"), named("Clangd4";
+  UnorderedElementsAre(AllOf(qualifier("nx::"), named("Clangd1"),
+ kind(CompletionItemKind::Class)),
+   AllOf(qualifier("ny::"), named("Clangd2"),
+ kind(CompletionItemKind::Class)),
+   AllOf(qualifier(""), scope(""), named("Clangd3"),
+ kind(CompletionItemKind::Class)),
+   AllOf(qualifier("nb::"), named("Clangd4"),
+ kind(CompletionItemKind::Class)),
+   AllOf(qualifier("C::"), named("Clangd5"),
+ kind(CompletionItemKind::EnumMember;
 }
 
 TEST(CompletionTest, NoQualifierIfShadowed) {
@@ -3358,6 +3364,31 @@
 kind(CompletionItemKind::Reference;
 }
 
+TEST(CompletionTest, Enums) {
+  const char *Header(R"cpp(
+namespace ns {
+  enum Unscoped { Clangd1 };
+  class C {
+  enum Unscoped { Clangd2 };
+  };
+  enum class Scoped { Clangd3 };
+})cpp");
+  const char *Source(R"cpp(
+void bar() {
+  Clangd^
+})cpp");
+  auto Index = TestTU::withHeaderCode(Header).index();
+  clangd::CodeCompleteOptions Opts;
+  Opts.Index = Index.get();
+  Opts.AllScopes = true;
+  auto R = completions(Source, {}, Opts);
+  EXPECT_THAT(R.Completions,
+  ElementsAre(AllOf(scope("ns::"), named("Clangd1"),
+

[clang-tools-extra] a68bcd8 - [clangd] Index unscoped enums in class scope for code completion

2022-11-02 Thread Tom Praschan via cfe-commits

Author: Tom Praschan
Date: 2022-11-02T12:50:50+01:00
New Revision: a68bcd81dcc90fc7d6fbe4013569774a19097c4a

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

LOG: [clangd] Index unscoped enums in class scope for code completion

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

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

Added: 


Modified: 
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
clang-tools-extra/clangd/unittests/TestIndex.cpp
clang-tools-extra/clangd/unittests/TestIndex.h

Removed: 




diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 5612fc599fb50..a3e518b4ba054 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -2123,6 +2123,9 @@ bool isIndexedForCodeCompletion(const NamedDecl &ND, 
ASTContext &ASTCtx) {
 };
 return false;
   };
+  auto InClassScope = [](const NamedDecl &ND) {
+return ND.getDeclContext()->getDeclKind() == Decl::CXXRecord;
+  };
   // We only complete symbol's name, which is the same as the name of the
   // *primary* template in case of template specializations.
   if (isExplicitTemplateSpecialization(&ND))
@@ -2138,8 +2141,11 @@ bool isIndexedForCodeCompletion(const NamedDecl &ND, 
ASTContext &ASTCtx) {
   if (InTopLevelScope(ND))
 return true;
 
+  // Always index enum constants, even if they're not in the top level scope:
+  // when
+  // --all-scopes-completion is set, we'll want to complete those as well.
   if (const auto *EnumDecl = dyn_cast(ND.getDeclContext()))
-return InTopLevelScope(*EnumDecl) && !EnumDecl->isScoped();
+return (InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl)) && 
!EnumDecl->isScoped();
 
   return false;
 }

diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index db700556e1d24..77451bf445e0f 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -2967,14 +2967,20 @@ TEST(CompletionTest, AllScopesCompletion) {
 }
   )cpp",
   {cls("nx::Clangd1"), cls("ny::Clangd2"), cls("Clangd3"),
-   cls("na::nb::Clangd4")},
+   cls("na::nb::Clangd4"), enmConstant("na::C::Clangd5")},
   Opts);
   EXPECT_THAT(
   Results.Completions,
-  UnorderedElementsAre(AllOf(qualifier("nx::"), named("Clangd1")),
-   AllOf(qualifier("ny::"), named("Clangd2")),
-   AllOf(qualifier(""), scope(""), named("Clangd3")),
-   AllOf(qualifier("nb::"), named("Clangd4";
+  UnorderedElementsAre(AllOf(qualifier("nx::"), named("Clangd1"),
+ kind(CompletionItemKind::Class)),
+   AllOf(qualifier("ny::"), named("Clangd2"),
+ kind(CompletionItemKind::Class)),
+   AllOf(qualifier(""), scope(""), named("Clangd3"),
+ kind(CompletionItemKind::Class)),
+   AllOf(qualifier("nb::"), named("Clangd4"),
+ kind(CompletionItemKind::Class)),
+   AllOf(qualifier("C::"), named("Clangd5"),
+ kind(CompletionItemKind::EnumMember;
 }
 
 TEST(CompletionTest, NoQualifierIfShadowed) {
@@ -3358,6 +3364,31 @@ TEST(CompletionTest, UsingDecl) {
 kind(CompletionItemKind::Reference;
 }
 
+TEST(CompletionTest, Enums) {
+  const char *Header(R"cpp(
+namespace ns {
+  enum Unscoped { Clangd1 };
+  class C {
+  enum Unscoped { Clangd2 };
+  };
+  enum class Scoped { Clangd3 };
+})cpp");
+  const char *Source(R"cpp(
+void bar() {
+  Clangd^
+})cpp");
+  auto Index = TestTU::withHeaderCode(Header).index();
+  clangd::CodeCompleteOptions Opts;
+  Opts.Index = Index.get();
+  Opts.AllScopes = true;
+  auto R = completions(Source, {}, Opts);
+  EXPECT_THAT(R.Completions,
+  ElementsAre(AllOf(scope("ns::"), named("Clangd1"),
+kind(CompletionItemKind::EnumMember)),
+  AllOf(scope("ns::C::"), named("Clangd2"),
+kind(CompletionItemKind::EnumMember;
+}
+
 TEST(CompletionTest, ScopeIsUnresolved) {
   clangd::CodeCompleteOptions Opts = {};
   Opts.AllScopes = true;

diff  --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 8dc7877c17849..bb651b851afeb 

[PATCH] D136925: [clangd] Index unscoped enums inside classes for code completion

2022-11-02 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

In D136925#3901509 , @nridge wrote:

> Thanks!
>
> I don't think we need this much detail in the commit message; I think after 
> the first line it would be sufficient to say:
>
>   Fixes https://github.com/clangd/clangd/issues/1082
>   See the issue for disk/memory usage measurements
>
> (Note also that "Fixes " triggers the github issue to be closed when 
> the commit is merged.)
>
> I forget whether you have commit access -- let me know if you need me to 
> merge the patch for you.

Yep, I do have access. I adjusted the message and pushed this, but the 
corresponding Github issue is not closed automatically because I don't have the 
necessary permisions (I think we already hat that problem in another patch)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136925

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


[PATCH] D136589: [AArch64] Add support for the Cortex-X3 CPU

2022-11-02 Thread Victor Campos via Phabricator via cfe-commits
vhscampos updated this revision to Diff 472567.
vhscampos added a comment.

Added AEK_FLAM to the list of features for Cortex-X3


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136589

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-mcpu.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1073,6 +1073,19 @@
  AArch64::AEK_SVE2BITPERM | AArch64::AEK_SSBS |
  AArch64::AEK_SB | AArch64::AEK_FP16FML,
  "9-A"),
+ARMCPUTestParams("cortex-x3", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP | AArch64::AEK_BF16 |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ AArch64::AEK_MTE | AArch64::AEK_PAUTH |
+ AArch64::AEK_SVE | AArch64::AEK_SVE2 |
+ AArch64::AEK_SVE2BITPERM | AArch64::AEK_SB |
+ AArch64::AEK_PROFILE | AArch64::AEK_PERFMON |
+ AArch64::AEK_I8MM | AArch64::AEK_FP16 |
+ AArch64::AEK_FP16FML | AArch64::AEK_PREDRES |
+ AArch64::AEK_FLAGM,
+ "9-A"),
 ARMCPUTestParams("cyclone", "armv8-a", "crypto-neon-fp-armv8",
  AArch64::AEK_NONE | AArch64::AEK_CRYPTO |
  AArch64::AEK_FP | AArch64::AEK_SIMD,
@@ -1296,7 +1309,7 @@
  "8.2-A")));
 
 // Note: number of CPUs includes aliases.
-static constexpr unsigned NumAArch64CPUArchs = 59;
+static constexpr unsigned NumAArch64CPUArchs = 60;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -68,6 +68,7 @@
 CortexX1,
 CortexX1C,
 CortexX2,
+CortexX3,
 ExynosM3,
 Falkor,
 Kryo,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -143,6 +143,7 @@
 break;
   case CortexA710:
   case CortexX2:
+  case CortexX3:
 PrefFunctionLogAlignment = 4;
 VScaleForTuning = 1;
 PrefLoopLogAlignment = 5;
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -785,6 +785,13 @@
   FeatureLSLFast,
   FeaturePostRAScheduler]>;
 
+def TuneX3 : SubtargetFeature<"cortex-x3", "ARMProcFamily", "CortexX3",
+  "Cortex-X3 ARM processors", [
+   FeatureLSLFast,
+   FeatureFuseAdrpAdd,
+   FeatureFuseAES,
+   FeaturePostRAScheduler]>;
+
 def TuneA64FX : SubtargetFeature<"a64fx", "ARMProcFamily", "A64FX",
  "Fujitsu A64FX processors", [
  FeaturePostRAScheduler,
@@ -1109,6 +1116,11 @@
  FeatureMatMulInt8, FeatureBF16, FeatureAM,
  FeatureMTE, FeatureETE, FeatureSVE2BitPerm,
  FeatureFP16FML];
+  list X3 =   [HasV9_0aOps, FeatureSVE, FeatureNEON,
+ FeaturePerfMon, FeatureETE, FeatureTRBE,
+ FeatureSPE, FeatureBF16, FeatureMatMulInt8,
+ FeatureMTE, FeatureSVE2BitPerm, FeatureFullFP16,
+ FeatureFP16FML];
   list A64FX= [HasV8_2aOps, FeatureFPARMv8, FeatureNEON,
  FeatureSHA2, FeaturePerfMon, FeatureFullFP16,
  FeatureSVE, FeatureComplxNum];
@@ -1239,6 +1251,8 @@
  [TuneX1]>;
 def : ProcessorModel<"cortex-x2", NeoverseN2Model, ProcessorFeatures.X2,
  [TuneX2]>;
+def : P

[PATCH] D137104: [clangd] Add scoped enum constants to all-scopes-completion

2022-11-02 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders updated this revision to Diff 472568.
tom-anders added a comment.

Update `CompletionTest.Enums`, keep scope condition in 
isIndexedForCodeCompletion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137104

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1329,7 +1329,7 @@
   AllOf(qName("Color"), forCodeCompletion(true)),
   AllOf(qName("Green"), forCodeCompletion(true)),
   AllOf(qName("Color2"), forCodeCompletion(true)),
-  AllOf(qName("Color2::Yellow"), forCodeCompletion(false)),
+  AllOf(qName("Color2::Yellow"), forCodeCompletion(true)),
   AllOf(qName("ns"), forCodeCompletion(true)),
   AllOf(qName("ns::Black"), forCodeCompletion(true)),
   AllOf(qName("Color3"), forCodeCompletion(true)),
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3386,6 +3386,8 @@
   ElementsAre(AllOf(scope("ns::"), named("Clangd1"),
 kind(CompletionItemKind::EnumMember)),
   AllOf(scope("ns::C::"), named("Clangd2"),
+kind(CompletionItemKind::EnumMember)),
+  AllOf(scope("ns::C::Scoped"), named("Clangd3"),
 kind(CompletionItemKind::EnumMember;
 }
 
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -291,7 +291,7 @@
 // For index-based completion, we only consider:
 //   * symbols in namespaces or translation unit scopes (e.g. no class
 // members, no locals)
-//   * enum constants in unscoped enum decl (e.g. "red" in "enum {red};")
+//   * enum constants (both scoped and unscoped)
 //   * primary templates (no specializations)
 // For the other cases, we let Clang do the completion because it does not
 // need any non-local information and it will be much better at following
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -2145,7 +2145,7 @@
   // when
   // --all-scopes-completion is set, we'll want to complete those as well.
   if (const auto *EnumDecl = dyn_cast(ND.getDeclContext()))
-return (InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl)) && 
!EnumDecl->isScoped();
+return (InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl));
 
   return false;
 }


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1329,7 +1329,7 @@
   AllOf(qName("Color"), forCodeCompletion(true)),
   AllOf(qName("Green"), forCodeCompletion(true)),
   AllOf(qName("Color2"), forCodeCompletion(true)),
-  AllOf(qName("Color2::Yellow"), forCodeCompletion(false)),
+  AllOf(qName("Color2::Yellow"), forCodeCompletion(true)),
   AllOf(qName("ns"), forCodeCompletion(true)),
   AllOf(qName("ns::Black"), forCodeCompletion(true)),
   AllOf(qName("Color3"), forCodeCompletion(true)),
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3386,6 +3386,8 @@
   ElementsAre(AllOf(scope("ns::"), named("Clangd1"),
 kind(CompletionItemKind::EnumMember)),
   AllOf(scope("ns::C::"), named("Clangd2"),
+kind(CompletionItemKind::EnumMember)),
+  AllOf(scope("ns::C::Scoped"), named("Clangd3"),
 kind(CompletionItemKind::EnumMember;
 }
 
Index: clang-tools-extra/clangd/CodeComplete.h
==

[PATCH] D137104: [clangd] Add scoped enum constants to all-scopes-completion

2022-11-02 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders marked an inline comment as done.
tom-anders added inline comments.



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:2136
+  if (llvm::isa(ND.getDeclContext()))
+return true;
 

nridge wrote:
> Why remove the `(InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl))` part?
Huh, because I thought this covered all the scopes where you could declare 
enums anyway, but of course that's wrong - You can e.g. declare a 
function-local enum, which we of course don't want to index. 



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:2136
+  if (llvm::isa(ND.getDeclContext()))
+return true;
 

tom-anders wrote:
> nridge wrote:
> > Why remove the `(InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl))` 
> > part?
> Huh, because I thought this covered all the scopes where you could declare 
> enums anyway, but of course that's wrong - You can e.g. declare a 
> function-local enum, which we of course don't want to index. 
d


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137104

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


[PATCH] D136589: [AArch64] Add support for the Cortex-X3 CPU

2022-11-02 Thread Victor Campos via Phabricator via cfe-commits
vhscampos marked an inline comment as done.
vhscampos added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:696
-- Add driver and tuning support for Neoverse V2 via the flag 
``-mcpu=neoverse-v2``.
-  Native detection is also supported via ``-mcpu=native``.
 

tschuett wrote:
> dmgreen wrote:
> > tschuett wrote:
> > > What happened with native detection?
> > I think I prefer the new wording, FWIW, as we add more CPUs. The native 
> > detection should just be automatically implied.
> But the word `native` disappeared.
I've looked at https://reviews.llvm.org/D134352 and also in code related to 
-mcpu=native implementation and I couldn't find anything related to Neoverse 
V2. Can you please point me to where that release note relates to?



Comment at: llvm/unittests/Support/TargetParserTest.cpp:1083
+ AArch64::AEK_SVE | AArch64::AEK_SVE2 |
+ AArch64::AEK_SVE2BITPERM | AArch64::AEK_SB |
+ AArch64::AEK_PROFILE | AArch64::AEK_PERFMON |

dmgreen wrote:
> Should SSBS be included in here? As far as I understand it is enabled by 
> default in 8.5-A. That should mean it's included automatically, but that can 
> be said for a lot of the other features here too.
> Same for AEK_FLAGM, which I noticed as a difference between A715 and X3.
SSBS is an optional feature for all Armv8-A architectures.

But FlagM should be present here as it's mandatory in v8.4-A. Fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136589

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


[PATCH] D136589: [AArch64] Add support for the Cortex-X3 CPU

2022-11-02 Thread Dave Green via Phabricator via cfe-commits
dmgreen added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:696
-- Add driver and tuning support for Neoverse V2 via the flag 
``-mcpu=neoverse-v2``.
-  Native detection is also supported via ``-mcpu=native``.
 

vhscampos wrote:
> tschuett wrote:
> > dmgreen wrote:
> > > tschuett wrote:
> > > > What happened with native detection?
> > > I think I prefer the new wording, FWIW, as we add more CPUs. The native 
> > > detection should just be automatically implied.
> > But the word `native` disappeared.
> I've looked at https://reviews.llvm.org/D134352 and also in code related to 
> -mcpu=native implementation and I couldn't find anything related to Neoverse 
> V2. Can you please point me to where that release note relates to?
I think the comment just meant that -mcpu=native on a neoverse-v2 would 
correctly turn into -mcpu=neoverse-v2 because the code added to Host.cpp. That 
should pretty much always be true, so I'm not sure it deserves to be called out.
It sounds fine either way though, if you do think it is important.



Comment at: llvm/unittests/Support/TargetParserTest.cpp:1083
+ AArch64::AEK_SVE | AArch64::AEK_SVE2 |
+ AArch64::AEK_SVE2BITPERM | AArch64::AEK_SB |
+ AArch64::AEK_PROFILE | AArch64::AEK_PERFMON |

vhscampos wrote:
> dmgreen wrote:
> > Should SSBS be included in here? As far as I understand it is enabled by 
> > default in 8.5-A. That should mean it's included automatically, but that 
> > can be said for a lot of the other features here too.
> > Same for AEK_FLAGM, which I noticed as a difference between A715 and X3.
> SSBS is an optional feature for all Armv8-A architectures.
> 
> But FlagM should be present here as it's mandatory in v8.4-A. Fixed.
But if the CPU has SSBS, should it not be present? It seems to be mentioned in 
the TRM.

According to the reference I have it became mandatory in 8.5-A, so it should be 
enabled automatically and I'm not sure adding the AEK feature will have much 
effect. It sounds better to add it for consistency though, if we can.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136589

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


[PATCH] D137180: [LinkerWrapper] report on missing libraries

2022-11-02 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:1278
+  if (identify_magic((*BufferOrErr)->getBuffer()) != file_magic::archive)
+continue;
+

jdoerfert wrote:
> jhuber6 wrote:
> > jdoerfert wrote:
> > > So if the library is found but not an archive we silently continue still?
> > In that case it won't be used for device linking so the host linker will 
> > handle that.
> Can you add a comment, I still don't understand when/how this happens but a 
> comment might do.
Sorry I didn't explain the logic correctly. The `else` means that we will error 
on any library that's found but not present in the linker wrapper. This 
conditional simply ensures that we only attempt to extract offloading files if 
it's in a static library.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137180

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


[PATCH] D137104: [clangd] Add scoped enum constants to all-scopes-completion

2022-11-02 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders updated this revision to Diff 472578.
tom-anders marked an inline comment as done.
tom-anders added a comment.

Actually fix test...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137104

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1329,7 +1329,7 @@
   AllOf(qName("Color"), forCodeCompletion(true)),
   AllOf(qName("Green"), forCodeCompletion(true)),
   AllOf(qName("Color2"), forCodeCompletion(true)),
-  AllOf(qName("Color2::Yellow"), forCodeCompletion(false)),
+  AllOf(qName("Color2::Yellow"), forCodeCompletion(true)),
   AllOf(qName("ns"), forCodeCompletion(true)),
   AllOf(qName("ns::Black"), forCodeCompletion(true)),
   AllOf(qName("Color3"), forCodeCompletion(true)),
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3382,11 +3382,13 @@
   Opts.Index = Index.get();
   Opts.AllScopes = true;
   auto R = completions(Source, {}, Opts);
-  EXPECT_THAT(R.Completions,
-  ElementsAre(AllOf(scope("ns::"), named("Clangd1"),
-kind(CompletionItemKind::EnumMember)),
-  AllOf(scope("ns::C::"), named("Clangd2"),
-kind(CompletionItemKind::EnumMember;
+  EXPECT_THAT(R.Completions, UnorderedElementsAre(
+ AllOf(scope("ns::"), named("Clangd1"),
+   kind(CompletionItemKind::EnumMember)),
+ AllOf(scope("ns::C::"), named("Clangd2"),
+   kind(CompletionItemKind::EnumMember)),
+ AllOf(scope("ns::Scoped::"), named("Clangd3"),
+   kind(CompletionItemKind::EnumMember;
 }
 
 TEST(CompletionTest, ScopeIsUnresolved) {
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -291,7 +291,7 @@
 // For index-based completion, we only consider:
 //   * symbols in namespaces or translation unit scopes (e.g. no class
 // members, no locals)
-//   * enum constants in unscoped enum decl (e.g. "red" in "enum {red};")
+//   * enum constants (both scoped and unscoped)
 //   * primary templates (no specializations)
 // For the other cases, we let Clang do the completion because it does not
 // need any non-local information and it will be much better at following
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -2145,7 +2145,7 @@
   // when
   // --all-scopes-completion is set, we'll want to complete those as well.
   if (const auto *EnumDecl = dyn_cast(ND.getDeclContext()))
-return (InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl)) && 
!EnumDecl->isScoped();
+return (InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl));
 
   return false;
 }


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1329,7 +1329,7 @@
   AllOf(qName("Color"), forCodeCompletion(true)),
   AllOf(qName("Green"), forCodeCompletion(true)),
   AllOf(qName("Color2"), forCodeCompletion(true)),
-  AllOf(qName("Color2::Yellow"), forCodeCompletion(false)),
+  AllOf(qName("Color2::Yellow"), forCodeCompletion(true)),
   AllOf(qName("ns"), forCodeCompletion(true)),
   AllOf(qName("ns::Black"), forCodeCompletion(true)),
   AllOf(qName("Color3"), forCodeCompletion(true)),
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3382,11 +3382,13 @@
   Opts.Index 

[PATCH] D137244: [Clang] Correctly capture bindings in dependent lambdas.

2022-11-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Structured bindings were not properly marked odr-used
and therefore captured in generic lambddas.

Fixes #57826

It is unclear to me if further simplification can be gained
through the allowance described in 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0588r1.html.

Either way, I think this makes support for P0588 completes,
but we probably want to add test for that in a separate PR.
(and I lack confidence I understand P0588 sufficiently to assert
the completeness of our cnformance).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137244

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaLambda.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/ScopeInfo.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/cxx20-decomposition.cpp

Index: clang/test/SemaCXX/cxx20-decomposition.cpp
===
--- clang/test/SemaCXX/cxx20-decomposition.cpp
+++ clang/test/SemaCXX/cxx20-decomposition.cpp
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify -Wunused-variable %s
 
 template 
 constexpr bool is_same = false;
@@ -80,10 +79,21 @@
 namespace std {
 
 template 
-struct tuple_size {
+struct tuple_size;
+
+template 
+struct tuple_size : tuple_size{};
+
+template 
+requires requires { tuple_size::value; }
+struct tuple_size : tuple_size{};
+
+template <>
+struct tuple_size {
   static constexpr unsigned long value = 2;
 };
 
+
 template 
 struct tuple_element;
 
@@ -139,3 +149,37 @@
 };
   }
 }
+
+namespace ODRUseTests {
+  struct P { int a; int b; };
+  void GH57826() {
+const auto [a, b] = P{1, 2}; //expected-note 2{{'b' declared here}} \
+ //expected-note 3{{'a' declared here}}
+(void)[&](auto c) { return b + [&a] {
+return a;
+}() ; }(0);
+(void)[&](auto c) { return b + [&a](auto) {
+return a;
+}(0) ; }(0);
+(void)[=](auto c) { return b + [&a](auto) {
+return a;
+}(0) ; }(0);
+(void)[&a,&b](auto c) { return b + [&a](auto) {
+return a;
+}(0) ; }(0);
+(void)[&a,&b](auto c) { return b + [a](auto) {
+return a;
+}(0) ; }(0);
+(void)[&a](auto c) { return b + [&a](auto) { // expected-error 2{{variable 'b' cannot be implicitly captured}} \
+ // expected-note 2{{lambda expression begins here}} \
+ // expected-note 4{{capture 'b'}}
+return a;
+}(0) ; }(0); // expected-note {{in instantiation}}
+(void)[&b](auto c) { return b + [](auto) {   // expected-note 3{{lambda expression begins here}} \
+ // expected-note 6{{capture 'a'}} \
+ // expected-note 6{{default capture}} \
+ // expected-note {{in instantiation}}
+return a;  // expected-error 3{{variable 'a' cannot be implicitly captured}}
+}(0) ; }(0); // expected-note 2{{in instantiation}}
+  }
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -13312,8 +13312,8 @@
 }
 
 // Transform the captured variable.
-VarDecl *CapturedVar
-  = cast_or_null(getDerived().TransformDecl(C->getLocation(),
+ValueDecl *CapturedVar
+  = cast_or_null(getDerived().TransformDecl(C->getLocation(),
  C->getCapturedVar()));
 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
   Invalid = true;
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -62,7 +62,7 @@
 static inline Optional
 getStackIndexOfNearestEnclosingCaptureReadyLambda(
 ArrayRef FunctionScopes,
-VarDecl *VarToCapture) {
+ValueDecl *VarToCapture) {
   // Label failure to capture.
   const Optional NoLambdaIsCaptureReady;
 
@@ -172,7 +172,7 @@
 
 Optional clang::getStackIndexOfNearestEnclosingCaptureCapableLambda(
 ArrayRef FunctionScopes,
-VarDecl *VarToCapture, Sema &S) {
+ValueDecl *VarToCapture, Sema &S) {
 
   const Optional NoLambdaIsCaptureCapable;
 
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang

[clang] d7d7436 - Reenable POSIX builtin library functions in gnu2x mode

2022-11-02 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-11-02T08:00:25-04:00
New Revision: d7d743621a0d5d13ed54d358944857ccba598299

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

LOG: Reenable POSIX builtin library functions in gnu2x mode

gnu17 and earlier modes automatically expose several POSIX C APIs, and
this was accidentally disabled for gnu2x in
7d644e1215b376ec5e915df9ea2eeb56e2d94626.

This restores the behavior for gnu2x mode (without changing the
behavior in C standards modes instead of GNU modes).

Fixes #56607

Added: 
clang/test/Sema/gnu-builtins.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7697f10daeef0..1198926974bff 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -274,6 +274,10 @@ Bug Fixes
   result in a stack overflow.
   `Issue 44304 `_
   `Issue 50891 `_
+- Clang 14 predeclared some builtin POSIX library functions in ``gnu2x`` mode,
+  and Clang 15 accidentally stopped predeclaring those functions in that
+  language mode. Clang 16 now predeclares those functions again. This fixes
+  `Issue 56607 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 845fa2f56df2f..39e88bccfef64 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -941,11 +941,9 @@ bool Sema::LookupBuiltin(LookupResult &R) {
 
   // If this is a builtin on this (or all) targets, create the decl.
   if (unsigned BuiltinID = II->getBuiltinID()) {
-// In C++, C2x, and OpenCL (spec v1.2 s6.9.f), we don't have any
-// predefined library functions like 'malloc'. Instead, we'll just
-// error.
-if ((getLangOpts().CPlusPlus || getLangOpts().OpenCL ||
- getLangOpts().C2x) &&
+// In C++ and OpenCL (spec v1.2 s6.9.f), we don't have any predefined
+// library functions like 'malloc'. Instead, we'll just error.
+if ((getLangOpts().CPlusPlus || getLangOpts().OpenCL) &&
 Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
   return false;
 

diff  --git a/clang/test/Sema/gnu-builtins.c b/clang/test/Sema/gnu-builtins.c
new file mode 100644
index 0..c4da8b39363cd
--- /dev/null
+++ b/clang/test/Sema/gnu-builtins.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=gnu -std=gnu17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=gnu -std=gnu2x %s
+// RUN: %clang_cc1 -fsyntax-only -verify=std -std=c17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=std -std=c2x %s
+
+// std-no-diagnostics
+
+// 'index' is a builtin library function, but only in GNU mode. So this should
+// give an error in GNU modes but be okay in non-GNU mode.
+// FIXME: the error is correct, but these notes are pretty awful.
+int index; // gnu-error {{redefinition of 'index' as 
diff erent kind of symbol}} \
+  gnu-note {{unguarded header; consider using #ifdef guards or 
#pragma once}} \
+  gnu-note {{previous definition is here}}



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


[PATCH] D137244: [Clang] Correctly capture bindings in dependent lambdas.

2022-11-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 472581.
cor3ntin added a comment.

Forgot to clang-format!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137244

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaLambda.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/ScopeInfo.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/cxx20-decomposition.cpp

Index: clang/test/SemaCXX/cxx20-decomposition.cpp
===
--- clang/test/SemaCXX/cxx20-decomposition.cpp
+++ clang/test/SemaCXX/cxx20-decomposition.cpp
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify -Wunused-variable %s
 
 template 
 constexpr bool is_same = false;
@@ -80,10 +79,21 @@
 namespace std {
 
 template 
-struct tuple_size {
+struct tuple_size;
+
+template 
+struct tuple_size : tuple_size{};
+
+template 
+requires requires { tuple_size::value; }
+struct tuple_size : tuple_size{};
+
+template <>
+struct tuple_size {
   static constexpr unsigned long value = 2;
 };
 
+
 template 
 struct tuple_element;
 
@@ -139,3 +149,37 @@
 };
   }
 }
+
+namespace ODRUseTests {
+  struct P { int a; int b; };
+  void GH57826() {
+const auto [a, b] = P{1, 2}; //expected-note 2{{'b' declared here}} \
+ //expected-note 3{{'a' declared here}}
+(void)[&](auto c) { return b + [&a] {
+return a;
+}() ; }(0);
+(void)[&](auto c) { return b + [&a](auto) {
+return a;
+}(0) ; }(0);
+(void)[=](auto c) { return b + [&a](auto) {
+return a;
+}(0) ; }(0);
+(void)[&a,&b](auto c) { return b + [&a](auto) {
+return a;
+}(0) ; }(0);
+(void)[&a,&b](auto c) { return b + [a](auto) {
+return a;
+}(0) ; }(0);
+(void)[&a](auto c) { return b + [&a](auto) { // expected-error 2{{variable 'b' cannot be implicitly captured}} \
+ // expected-note 2{{lambda expression begins here}} \
+ // expected-note 4{{capture 'b'}}
+return a;
+}(0) ; }(0); // expected-note {{in instantiation}}
+(void)[&b](auto c) { return b + [](auto) {   // expected-note 3{{lambda expression begins here}} \
+ // expected-note 6{{capture 'a'}} \
+ // expected-note 6{{default capture}} \
+ // expected-note {{in instantiation}}
+return a;  // expected-error 3{{variable 'a' cannot be implicitly captured}}
+}(0) ; }(0); // expected-note 2{{in instantiation}}
+  }
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -13312,9 +13312,8 @@
 }
 
 // Transform the captured variable.
-VarDecl *CapturedVar
-  = cast_or_null(getDerived().TransformDecl(C->getLocation(),
- C->getCapturedVar()));
+ValueDecl *CapturedVar = cast_or_null(
+getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
   Invalid = true;
   continue;
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -62,7 +62,7 @@
 static inline Optional
 getStackIndexOfNearestEnclosingCaptureReadyLambda(
 ArrayRef FunctionScopes,
-VarDecl *VarToCapture) {
+ValueDecl *VarToCapture) {
   // Label failure to capture.
   const Optional NoLambdaIsCaptureReady;
 
@@ -172,7 +172,7 @@
 
 Optional clang::getStackIndexOfNearestEnclosingCaptureCapableLambda(
 ArrayRef FunctionScopes,
-VarDecl *VarToCapture, Sema &S) {
+ValueDecl *VarToCapture, Sema &S) {
 
   const Optional NoLambdaIsCaptureCapable;
 
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -8223,7 +8223,7 @@
   // All the potentially captureable variables in the current nested
   // lambda (within a generic outer lambda), must be captured by an
   // outer lambda that is enclosed within a non-dependent context.
-  CurrentLSI->visitPotentialCaptures([&] (VarDecl *Var, Expr *VarExpr) {
+  CurrentLSI->visitPotentialCaptures([&](ValueDecl *Var, Expr *VarExpr) {
 // If the variable is clearly identified as non-odr-used and the full
 // expression is not instantiatio

[PATCH] D137244: [Clang] Correctly capture bindings in dependent lambdas.

2022-11-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

(No changelog, this fixes an unreleased feature)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137244

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


[PATCH] D136589: [AArch64] Add support for the Cortex-X3 CPU

2022-11-02 Thread Victor Campos via Phabricator via cfe-commits
vhscampos updated this revision to Diff 472583.
vhscampos added a comment.

Added SSBS


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136589

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-mcpu.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1073,6 +1073,19 @@
  AArch64::AEK_SVE2BITPERM | AArch64::AEK_SSBS |
  AArch64::AEK_SB | AArch64::AEK_FP16FML,
  "9-A"),
+ARMCPUTestParams("cortex-x3", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP | AArch64::AEK_BF16 |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ AArch64::AEK_MTE | AArch64::AEK_PAUTH |
+ AArch64::AEK_SVE | AArch64::AEK_SVE2 |
+ AArch64::AEK_SVE2BITPERM | AArch64::AEK_SB |
+ AArch64::AEK_PROFILE | AArch64::AEK_PERFMON |
+ AArch64::AEK_I8MM | AArch64::AEK_FP16 |
+ AArch64::AEK_FP16FML | AArch64::AEK_PREDRES |
+ AArch64::AEK_FLAGM | AArch64::AEK_SSBS,
+ "9-A"),
 ARMCPUTestParams("cyclone", "armv8-a", "crypto-neon-fp-armv8",
  AArch64::AEK_NONE | AArch64::AEK_CRYPTO |
  AArch64::AEK_FP | AArch64::AEK_SIMD,
@@ -1296,7 +1309,7 @@
  "8.2-A")));
 
 // Note: number of CPUs includes aliases.
-static constexpr unsigned NumAArch64CPUArchs = 59;
+static constexpr unsigned NumAArch64CPUArchs = 60;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -68,6 +68,7 @@
 CortexX1,
 CortexX1C,
 CortexX2,
+CortexX3,
 ExynosM3,
 Falkor,
 Kryo,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -143,6 +143,7 @@
 break;
   case CortexA710:
   case CortexX2:
+  case CortexX3:
 PrefFunctionLogAlignment = 4;
 VScaleForTuning = 1;
 PrefLoopLogAlignment = 5;
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -785,6 +785,13 @@
   FeatureLSLFast,
   FeaturePostRAScheduler]>;
 
+def TuneX3 : SubtargetFeature<"cortex-x3", "ARMProcFamily", "CortexX3",
+  "Cortex-X3 ARM processors", [
+   FeatureLSLFast,
+   FeatureFuseAdrpAdd,
+   FeatureFuseAES,
+   FeaturePostRAScheduler]>;
+
 def TuneA64FX : SubtargetFeature<"a64fx", "ARMProcFamily", "A64FX",
  "Fujitsu A64FX processors", [
  FeaturePostRAScheduler,
@@ -1109,6 +1116,11 @@
  FeatureMatMulInt8, FeatureBF16, FeatureAM,
  FeatureMTE, FeatureETE, FeatureSVE2BitPerm,
  FeatureFP16FML];
+  list X3 =   [HasV9_0aOps, FeatureSVE, FeatureNEON,
+ FeaturePerfMon, FeatureETE, FeatureTRBE,
+ FeatureSPE, FeatureBF16, FeatureMatMulInt8,
+ FeatureMTE, FeatureSVE2BitPerm, FeatureFullFP16,
+ FeatureFP16FML];
   list A64FX= [HasV8_2aOps, FeatureFPARMv8, FeatureNEON,
  FeatureSHA2, FeaturePerfMon, FeatureFullFP16,
  FeatureSVE, FeatureComplxNum];
@@ -1239,6 +1251,8 @@
  [TuneX1]>;
 def : ProcessorModel<"cortex-x2", NeoverseN2Model, ProcessorFeatures.X2,
  [TuneX2]>;
+def : ProcessorModel<"cortex-

[PATCH] D137246: Add clang_CXXMethod_isMoveAssignmentOperator to libclang

2022-11-02 Thread Luca Di sera via Phabricator via cfe-commits
diseraluca created this revision.
diseraluca added a reviewer: aaron.ballman.
Herald added a subscriber: arphaman.
Herald added a project: All.
diseraluca requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The new method is a wrapper of `CXXMethodDecl::isMoveAssignmentOperator` and
can be used to recognized move-assignment operators in libclang.

An export for the function, together with its documentation, was added to
"clang/include/clang-c/Index.h" with an implementation provided in
"clang/tools/libclang/CIndex.cpp". The implementation was based on
similar `clang_CXXMethod.*` implementations, following the same
structure but calling `CXXMethodDecl::isMoveAssignmentOperator` for its
main logic.

The new symbol was further added to "clang/tools/libclang/libclang.map"
to be exported, under the LLVM16 tag.

"clang/tools/c-index-test/c-index-test.c" was modified to print a
specific tag, "(move-assignment operator)", for cursors that are
recognized by `clang_CXXMethod_isMoveAssignmentOperator`.
A new regression test file,
"clang/test/Index/move-assignment-operator.cpp", was added to ensure
whether the correct constructs were recognized or not by the new function.

The "clang/test/Index/get-cursor.cpp" regression test file was updated
as it was affected by the new "(move-assignment operator)" tag.

A binding for the new function was added to libclang's python's
bindings, in "clang/bindings/python/clang/cindex.py", adding a new
method for `Cursor`, `is_move_assignment_operator_method`.
An accompanying test was added to
`clang/bindings/python/tests/cindex/test_cursor.py`, testing the new
function with the same methodology as the corresponding libclang test.

The current release note, `clang/docs/ReleaseNotes.rst`, was modified to
report the new addition under the "libclang" section.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137246

Files:
  clang/bindings/python/clang/cindex.py
  clang/bindings/python/tests/cindex/test_cursor.py
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/test/Index/get-cursor.cpp
  clang/test/Index/move-assignment-operator.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -411,6 +411,7 @@
 clang_getNonReferenceType;
 clang_CXXMethod_isDeleted;
 clang_CXXMethod_isCopyAssignmentOperator;
+clang_CXXMethod_isMoveAssignmentOperator;
 };
 
 # Example of how to add a new symbol version entry.  If you do add a new symbol
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -8910,6 +8910,17 @@
   return (Method && Method->isCopyAssignmentOperator()) ? 1 : 0;
 }
 
+unsigned clang_CXXMethod_isMoveAssignmentOperator(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+return 0;
+
+  const Decl *D = cxcursor::getCursorDecl(C);
+  const CXXMethodDecl *Method =
+  D ? dyn_cast_or_null(D->getAsFunction()) : nullptr;
+
+  return (Method && Method->isMoveAssignmentOperator()) ? 1 : 0;
+}
+
 unsigned clang_CXXRecord_isAbstract(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
 return 0;
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -912,6 +912,8 @@
   printf(" (pure)");
 if (clang_CXXMethod_isCopyAssignmentOperator(Cursor))
   printf(" (copy-assignment operator)");
+if (clang_CXXMethod_isMoveAssignmentOperator(Cursor))
+  printf(" (move-assignment operator)");
 if (clang_CXXRecord_isAbstract(Cursor))
   printf(" (abstract)");
 if (clang_EnumDecl_isScoped(Cursor))
Index: clang/test/Index/move-assignment-operator.cpp
===
--- /dev/null
+++ clang/test/Index/move-assignment-operator.cpp
@@ -0,0 +1,45 @@
+struct Foo {
+// Those are move-assignment operators
+bool operator=(const Foo&&);
+bool operator=(Foo&&);
+bool operator=(volatile Foo&&);
+bool operator=(const volatile Foo&&);
+
+// Those are not move-assignment operators
+template
+bool operator=(const T&&);
+bool operator=(const bool&&);
+bool operator=(char&&);
+bool operator=(volatile unsigned int&&);
+bool operator=(const volatile unsigned char&&);
+bool operator=(int);
+bool operator=(Foo);
+};
+
+// Positive-check that the recognition works for templated classes too
+template 
+class Bar {
+bool operator=(const Bar&&);
+bool operator=(Bar&&);
+bool operator=(volatile Bar&&);
+bool operator=(const volatile Bar&&);
+};
+
+// RUN: 

[PATCH] D136589: [AArch64] Add support for the Cortex-X3 CPU

2022-11-02 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

Thanks. LGTM if there are not other comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136589

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


[PATCH] D137172: [Clang] Implement CWG2358 Explicit capture of value

2022-11-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:162
+// Init captures are always VarDecl.
+auto *D = cast(LC.getCapturedVar());
+Invalid |= Visit(D->getInit());

Can you add a test case showing what happens with structured bindings? e.g.,
```
int array[] = { 1, 2 };
auto [a, b] = array; 

void func(int c = [x = a] { return x; }());
```
Note, I think Clang has a bug here so you might have to write the test with a 
FIXME comment. (I don't think we implement https://wg21.link/cwg2358 or 
http://eel.is/c++draft/expr.prim.lambda#capture-3 properly yet.)

The part that worries me there specifically is that a `BindingDecl` is a 
`ValueDecl` and not a `VarDecl`, so I think that `cast<>` may assert in this 
case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137172

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


[PATCH] D137209: [OPENMP]Initial support for error directive.

2022-11-02 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/AST/StmtOpenMP.h:6229
+/// \endcode
+class OMPErrorDirective : public OMPExecutableDirective {
+  friend class ASTStmtReader;

final



Comment at: llvm/include/llvm/Frontend/OpenMP/OMP.td:529
 def OMP_Barrier : Directive<"barrier"> {}
+def OMP_Terror : Directive<"error"> {}
 def OMP_TaskWait : Directive<"taskwait"> {

OMP_error


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137209

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


[PATCH] D137251: [clang][cuda/hip] Allow `__noinline__` lambdas

2022-11-02 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh created this revision.
Pierre-vh added reviewers: yaxunl, tra, aaron.ballman, rsmith.
Herald added a subscriber: mattd.
Herald added a project: All.
Pierre-vh requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

D124866  seem to have had an unintended side 
effect: __noinline__ on lambdas was no longer accepted.

This fixes the regression and adds a test case for it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137251

Files:
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/lambda-attr.cu


Index: clang/test/Parser/lambda-attr.cu
===
--- clang/test/Parser/lambda-attr.cu
+++ clang/test/Parser/lambda-attr.cu
@@ -18,6 +18,10 @@
   ([&](int) __attribute__((device)){ device_fn(); })(0);
   // expected-warning@-1 {{nvcc does not allow '__device__' to appear after 
the parameter list in lambdas}}
   ([&] __attribute__((device)) (int) { device_fn(); })(0);
+
+  // test that noinline can appear anywhere.
+  ([&] __attribute__((device)) __noinline__ () { device_fn(); })();
+  ([&] __noinline__ __attribute__((device)) () { device_fn(); })();
 }
 
 __attribute__((host)) __attribute__((device)) void host_device_attrs() {
@@ -37,6 +41,11 @@
   // expected-warning@-1 {{nvcc does not allow '__host__' to appear after the 
parameter list in lambdas}}
   // expected-warning@-2 {{nvcc does not allow '__device__' to appear after 
the parameter list in lambdas}}
   ([&] __attribute__((host)) __attribute__((device)) (int) { hd_fn(); })(0);
+
+  // test that noinline can also appear anywhere.
+  ([] __attribute__((host)) __attribute__((device)) () { hd_fn(); })();
+  ([] __attribute__((host)) __noinline__ __attribute__((device)) () { hd_fn(); 
})();
+  ([] __attribute__((host)) __attribute__((device)) __noinline__ () { hd_fn(); 
})();
 }
 
 // TODO: Add tests for __attribute__((global)) once we support global lambdas.
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1291,7 +1291,23 @@
   if (getLangOpts().CUDA) {
 // In CUDA code, GNU attributes are allowed to appear immediately after the
 // "[...]", even if there is no "(...)" before the lambda body.
-MaybeParseGNUAttributes(D);
+//
+// Note that we support __noinline__ as a keyword in this mode and thus
+// it has to be separately handled.
+while (true) {
+  if (Tok.is(tok::kw___attribute)) {
+ParseGNUAttributes(Attr, nullptr, &D);
+  } else if (Tok.is(tok::kw___noinline__)) {
+IdentifierInfo *AttrName = Tok.getIdentifierInfo();
+SourceLocation AttrNameLoc = ConsumeToken();
+Attr.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
+ParsedAttr::AS_Keyword);
+  } else {
+break;
+  }
+}
+
+D.takeAttributes(Attr);
   }
 
   // Helper to emit a warning if we see a CUDA host/device/global attribute


Index: clang/test/Parser/lambda-attr.cu
===
--- clang/test/Parser/lambda-attr.cu
+++ clang/test/Parser/lambda-attr.cu
@@ -18,6 +18,10 @@
   ([&](int) __attribute__((device)){ device_fn(); })(0);
   // expected-warning@-1 {{nvcc does not allow '__device__' to appear after the parameter list in lambdas}}
   ([&] __attribute__((device)) (int) { device_fn(); })(0);
+
+  // test that noinline can appear anywhere.
+  ([&] __attribute__((device)) __noinline__ () { device_fn(); })();
+  ([&] __noinline__ __attribute__((device)) () { device_fn(); })();
 }
 
 __attribute__((host)) __attribute__((device)) void host_device_attrs() {
@@ -37,6 +41,11 @@
   // expected-warning@-1 {{nvcc does not allow '__host__' to appear after the parameter list in lambdas}}
   // expected-warning@-2 {{nvcc does not allow '__device__' to appear after the parameter list in lambdas}}
   ([&] __attribute__((host)) __attribute__((device)) (int) { hd_fn(); })(0);
+
+  // test that noinline can also appear anywhere.
+  ([] __attribute__((host)) __attribute__((device)) () { hd_fn(); })();
+  ([] __attribute__((host)) __noinline__ __attribute__((device)) () { hd_fn(); })();
+  ([] __attribute__((host)) __attribute__((device)) __noinline__ () { hd_fn(); })();
 }
 
 // TODO: Add tests for __attribute__((global)) once we support global lambdas.
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1291,7 +1291,23 @@
   if (getLangOpts().CUDA) {
 // In CUDA code, GNU attributes are allowed to appear immediately after the
 // "[...]", even if there is no "(...)" before the lambda body.
-MaybeParseGNUAttributes(D);
+//
+// Note that we support __noinline__ as a keyword in this

[PATCH] D137252: [include-cleaner] Testing helpers for ast walking

2022-11-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: hokein, sammccall.
Herald added a subscriber: mgrang.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Address comments around verbosity of tests.

Depends on D135859 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137252

Files:
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -6,19 +6,25 @@
 //
 //===--===//
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Testing/TestAST.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -40,23 +46,16 @@
   llvm_unreachable("Unexpected RefType");
 }
 
-// Specifies a test of which symbols are referenced by a piece of code.
-// If `// c++-header` is present, treats referencing code as a header file.
-// Target should contain points annotated with the reference kind.
-// Example:
-//   Target:  int $explicit^foo();
-//   Referencing: int x = ^foo();
-// There must be exactly one referencing location marked.
-void testWalk(llvm::StringRef TargetCode, llvm::StringRef ReferencingCode) {
-  llvm::Annotations Target(TargetCode);
-  llvm::Annotations Referencing(ReferencingCode);
-
-  TestInputs Inputs(Referencing.code());
-  Inputs.ExtraFiles["target.h"] = Target.code().str();
+// Finds all the references to Target from Referencing.point().
+std::vector>
+referencedPoints(llvm::StringRef TargetCode, llvm::StringRef ReferencingCode,
+ size_t ReferencingOffset) {
+  TestInputs Inputs(ReferencingCode);
+  Inputs.ExtraFiles["target.h"] = TargetCode.str();
   Inputs.ExtraArgs.push_back("-include");
   Inputs.ExtraArgs.push_back("target.h");
   Inputs.ExtraArgs.push_back("-std=c++17");
-  if (Referencing.code().contains("// c++-header\n"))
+  if (ReferencingCode.contains("// c++-header\n"))
 Inputs.ExtraArgs.push_back("-xc++-header");
   TestAST AST(Inputs);
   const auto &SM = AST.sourceManager();
@@ -65,12 +64,12 @@
   // to the target file.
   FileID ReferencingFile = SM.getMainFileID();
   SourceLocation ReferencingLoc =
-  SM.getComposedLoc(ReferencingFile, Referencing.point());
+  SM.getComposedLoc(ReferencingFile, ReferencingOffset);
   FileID TargetFile = SM.translateFile(
   llvm::cantFail(AST.fileManager().getFileRef("target.h")));
 
   // Perform the walk, and capture the offsets of the referenced targets.
-  std::unordered_map> ReferencedOffsets;
+  std::map ActualPoints;
   for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
 if (ReferencingFile != SM.getDecomposedExpansionLoc(D->getLocation()).first)
   continue;
@@ -80,12 +79,24 @@
   auto NDLoc = SM.getDecomposedLoc(SM.getFileLoc(ND.getLocation()));
   if (NDLoc.first != TargetFile)
 return;
-  ReferencedOffsets[RT].push_back(NDLoc.second);
+  ActualPoints[NDLoc.second] = RT;
 });
   }
-  for (auto &Entry : ReferencedOffsets)
-llvm::sort(Entry.second);
+  return {ActualPoints.begin(), ActualPoints.end()};
+}
 
+// Runs on the output of referencedPoints. Compares it to offsets n TargetCode
+// and reftype sequence in Types.
+MATCHER_P2(TargetsWithTypes, /*llvm::Annotations*/ Target,
+   /*std::vector*/ Types, "") {
+  auto TargetPoints = Target.points();
+  if (TargetPoints.size() != Types.size()) {
+*result_listener << "Mismatched annotations(" << TargetPoints.size()
+ << ") vs types(" << Types.size() << ")";
+return false;
+  }
+  auto ExpectedPoints = llvm::zip(TargetPoints, Types);
+  std::vector> ActualPoints = arg;
   // Compare results to the expected points.
   // For each difference, show the target point in context, like a diagnostic.
   std::string DiagBuf;
@@ -93,127 +104,198 @@
   auto *DiagOpts = new DiagnosticOptions();
   DiagOpts->ShowLevel = 0;
   DiagOpts->ShowNoteIncludeStack = 0;
-  TextDiagnostic Diag(DiagOS, AST.context().getLangOpts(), DiagOpts);
-  auto DiagnosePoint = [&](llvm::StringRef Message, unsigned Offset) {
+  TextDiagnostic Dia

[PATCH] D137172: [Clang] Implement CWG2358 Explicit capture of value

2022-11-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:162
+// Init captures are always VarDecl.
+auto *D = cast(LC.getCapturedVar());
+Invalid |= Visit(D->getInit());

aaron.ballman wrote:
> Can you add a test case showing what happens with structured bindings? e.g.,
> ```
> int array[] = { 1, 2 };
> auto [a, b] = array; 
> 
> void func(int c = [x = a] { return x; }());
> ```
> Note, I think Clang has a bug here so you might have to write the test with a 
> FIXME comment. (I don't think we implement https://wg21.link/cwg2358 or 
> http://eel.is/c++draft/expr.prim.lambda#capture-3 properly yet.)
> 
> The part that worries me there specifically is that a `BindingDecl` is a 
> `ValueDecl` and not a `VarDecl`, so I think that `cast<>` may assert in this 
> case.
*sigh* this is implementing CWG2358...

So no FIXME comment, I think we should add a test to demonstrate that this 
works.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137172

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


[PATCH] D137172: [Clang] Implement CWG2358 Explicit capture of value

2022-11-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 472601.
cor3ntin added a comment.

Properly handle structured bindings in init capture


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137172

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/drs/dr23xx.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -13956,7 +13956,7 @@
 https://wg21.link/cwg2358";>2358
 CD5
 Explicit capture of value
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2359";>2359
Index: clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
@@ -1,4 +1,8 @@
-// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -Wno-c++14-extensions -verify
+
+const int global = 0;
+int global_array[] = { 1, 2 };
+auto [ga, gb] = global_array;
 
 void f2() {
   int i = 1;
@@ -7,6 +11,15 @@
   void g3(int = ([=]{ return i; })()); // expected-error{{lambda expression in default argument cannot capture any entity}}
   void g4(int = ([=]{ return 0; })());
   void g5(int = ([]{ return sizeof i; })());
+  void g6(int = ([x=1, y = global, &z = global]{ return x; })());
+  void g7(int = ([x=i, &y=i]{ return x; })()); // expected-error 2{{default argument references local variable 'i' of enclosing function}}
+}
+
+
+void structured_bindings() {
+  int array[] = { 1, 2 };
+  auto [a, b] = array;
+  void func(int c = [x = a, &xref = a, y = ga, &yref = ga] { return x; }()); // expected-error {{default argument references local variable 'a' of enclosing function}}
 }
 
 namespace lambda_in_default_args {
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -89,6 +89,16 @@
 #pragma clang __debug dump not_use_2
 }
 
+#if __cplusplus >= 201402L
+namespace dr2358 { // dr2358: 16
+  void f2() {
+int i = 1;
+void g1(int = [xxx=1] { return xxx; }());  // OK
+void g2(int = [xxx=i] { return xxx; }());  // expected-error {{default argument references local variable 'i' of enclosing function}}
+  }
+}
+#endif
+
 #if __cplusplus >= 201707L
 // Otherwise, if the qualified-id std::tuple_size names a complete class
 // type **with a member value**, the expression std::tuple_size::value shall
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -102,24 +102,31 @@
   return S.Diag(DRE->getBeginLoc(),
 diag::err_param_default_argument_references_param)
  << Param->getDeclName() << DefaultArg->getSourceRange();
-  } else if (const auto *VDecl = dyn_cast(Decl)) {
-// C++ [dcl.fct.default]p7:
-//   Local variables shall not be used in default argument
-//   expressions.
-//
-// C++17 [dcl.fct.default]p7 (by CWG 2082):
-//   A local variable shall not appear as a potentially-evaluated
-//   expression in a default argument.
-//
-// C++20 [dcl.fct.default]p7 (DR as part of P0588R1, see also CWG 2346):
-//   Note: A local variable cannot be odr-used (6.3) in a default argument.
-//
-if (VDecl->isLocalVarDecl() && !DRE->isNonOdrUse())
-  return S.Diag(DRE->getBeginLoc(),
-diag::err_param_default_argument_references_local)
- << VDecl->getDeclName() << DefaultArg->getSourceRange();
+  } else {
+const VarDecl *VD = nullptr;
+if (const auto *BD = dyn_cast(Decl))
+  VD = dyn_cast_if_present(BD->getDecomposedDecl());
+else
+  VD = dyn_cast(Decl);
+if (VD) {
+  // C++ [dcl.fct.default]p7:
+  //   Local variables shall not be used in default argument
+  //   expressions.
+  //
+  // C++17 [dcl.fct.default]p7 (by CWG 2082):
+  //   A local variable shall not appear as a potentially-evaluated
+  //   expression in a default argument.
+  //
+  // C++20 [dcl.fct.default]p7 (DR as part of P0588R1, see also CWG 2346):
+  //   Note: A local variable cannot be odr-used (6.3) in a default
+  //   argument.
+  //
+  if (VD->isLocalVarDecl() && !DRE->isNonOdrUse())
+return S.Diag(DRE->getBeginLoc(),
+  diag::err_param_default_argument_references_local)
+   << Decl->getDeclName() << DefaultArg->getSourceRange();
+}
   }
-
   return false;
 }
 
@@ -149,13 +156,20 @@
 }
 
 bool CheckDefaultArgumentVisitor

[PATCH] D137172: [Clang] Implement CWG2358 Explicit capture of value

2022-11-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:107-111
+if (const auto *BD = dyn_cast(Decl))
+  VD = dyn_cast_if_present(BD->getDecomposedDecl());
+else
+  VD = dyn_cast(Decl);
+if (VD) {

Note that https://reviews.llvm.org/D137244 introduces a utility to do that, but 
i''d rather avoid having to many dependencies between these patches. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137172

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


[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-11-02 Thread Jan Sjödin via Phabricator via cfe-commits
jsjodin added a comment.

@jdoerfert do you have any other comments?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136872

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


[PATCH] D137251: [clang][cuda/hip] Allow `__noinline__` lambdas

2022-11-02 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

need a CodeGenCUDA test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137251

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


[PATCH] D137258: [clang] Optimize storage and lookup of analyzer options

2022-11-02 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: Szelethus.
Herald added subscribers: steakhal, manas, ASDenysPetrov, ributzka, dkrupp, 
donat.nagy, a.sidorin, mgrang, baloghadamsoftware.
Herald added a reviewer: NoQ.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch removes `std::vector`, `std::sort()` and `std::binary_search()` in 
`AnalyzerOptions` with a static `llvm::StringSwitch`.

This avoids unnecessary work, which can speed up Clang tools that initialize 
lots of `CompilerInvocation`s (and therefore `AnalyzerOptions`).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137258

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1014,7 +1014,7 @@
 
   // TODO: Check checker options too, possibly in CheckerRegistry.
   // Leave unknown non-checker configs unclaimed.
-  if (!key.contains(":") && Opts.isUnknownAnalyzerConfig(key)) {
+  if (!key.contains(":") && AnalyzerOptions::isUnknownAnalyzerConfig(key)) 
{
 if (Opts.ShouldEmitErrorsOnInvalidConfigValue)
   Diags.Report(diag::err_analyzer_config_unknown) << key;
 continue;
Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -261,26 +261,17 @@
 #undef ANALYZER_OPTION
 #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
 
-  // Create an array of all -analyzer-config command line options. Sort it in
-  // the constructor.
-  std::vector AnalyzerConfigCmdFlags = {
+  static bool isUnknownAnalyzerConfig(StringRef Name) {
+return llvm::StringSwitch(Name)
 #define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,
\
  SHALLOW_VAL, DEEP_VAL)
\
   ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL)
-
 #define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)
\
-  llvm::StringLiteral(CMDFLAG),
-
+  .Case(CMDFLAG, false)
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
 #undef ANALYZER_OPTION
 #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
-  };
-
-  bool isUnknownAnalyzerConfig(StringRef Name) const {
-assert(llvm::is_sorted(AnalyzerConfigCmdFlags));
-
-return !std::binary_search(AnalyzerConfigCmdFlags.begin(),
-   AnalyzerConfigCmdFlags.end(), Name);
+.Default(true);
   }
 
   AnalyzerOptions()
@@ -293,9 +284,7 @@
 AnalyzerDisplayProgress(false), eagerlyAssumeBinOpBifurcation(false),
 TrimGraph(false), visualizeExplodedGraphWithGraphViz(false),
 UnoptimizedCFG(false), PrintStats(false), NoRetryExhausted(false),
-AnalyzerWerror(false) {
-llvm::sort(AnalyzerConfigCmdFlags);
-  }
+AnalyzerWerror(false) {}
 
   /// Interprets an option's string value as a boolean. The "true" string is
   /// interpreted as true and the "false" string is interpreted as false.


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1014,7 +1014,7 @@
 
   // TODO: Check checker options too, possibly in CheckerRegistry.
   // Leave unknown non-checker configs unclaimed.
-  if (!key.contains(":") && Opts.isUnknownAnalyzerConfig(key)) {
+  if (!key.contains(":") && AnalyzerOptions::isUnknownAnalyzerConfig(key)) {
 if (Opts.ShouldEmitErrorsOnInvalidConfigValue)
   Diags.Report(diag::err_analyzer_config_unknown) << key;
 continue;
Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -261,26 +261,17 @@
 #undef ANALYZER_OPTION
 #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
 
-  // Create an array of all -analyzer-config command line options. Sort it in
-  // the constructor.
-  std::vector AnalyzerConfigCmdFlags = {
+  static bool isUnknownAnalyzerConfig(StringRef Name) {
+return llvm::StringSwitch(Name)
 #define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,\
  SHALLOW_VAL, DEEP_VAL)\
   ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL)
-
 #define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)\
-  llvm::StringLiteral(CMDFLAG),
-
+  .

[PATCH] D137259: [clang][modules][deps] WIP: In-memory module transfer

2022-11-02 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Let's not create PCM files in the dependency scanner.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137259

Files:
  clang/include/clang/Frontend/CompilerInstance.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -424,6 +424,7 @@
 MD.ClangModuleMapFile = std::string(Path);
   }
 
+  if (MDC.ScanInstance.SortedFiles.find(M->getFullModuleName()) == MDC.ScanInstance.SortedFiles.end()) {
   serialization::ModuleFile *MF =
   MDC.ScanInstance.getASTReader()->getModuleManager().lookup(
   M->getASTFile());
@@ -452,12 +453,32 @@
   return;
 MD.ModuleMapFileDeps.emplace_back(FE->getName());
   });
+  } else {
+for (const auto &E : MDC.ScanInstance.SortedFiles[M->getFullModuleName()]) {
+  if (E.FE->getName().endswith("__inferred_module.map")) {
+MDC.addFileDep(MD, ModuleMap->getName());
+continue;
+  }
+  MDC.addFileDep(MD, E.FE->getName());
+}
+if (M->NoUndeclaredIncludes) {
+  for (const auto &E : MDC.ScanInstance.SortedFiles[M->getFullModuleName()]) {
+if (E.FE->getName().endswith("__inferred_module.map"))
+  continue;
+// The top-level modulemap of this module will be the input file. We
+// don't need to specify it as a module map.
+if (E.FE == ModuleMap)
+  continue;
+MD.ModuleMapFileDeps.push_back(E.FE->getName().str());
+  }
+}
+  }
 
   CompilerInvocation CI = MDC.makeInvocationForModuleBuildWithoutOutputs(
   MD, [&](CompilerInvocation &BuildInvocation) {
-if (MDC.OptimizeArgs)
-  optimizeHeaderSearchOpts(BuildInvocation.getHeaderSearchOpts(),
-   *MDC.ScanInstance.getASTReader(), *MF);
+//if (MDC.OptimizeArgs)
+//  optimizeHeaderSearchOpts(BuildInvocation.getHeaderSearchOpts(),
+//   *MDC.ScanInstance.getASTReader(), *MF);
   });
 
   MDC.associateWithContextHash(CI, MD);
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -1129,6 +1129,226 @@
   return LangOpts.CPlusPlus ? Language::CXX : Language::C;
 }
 
+class Translator {
+  CompilerInstance &A;
+  const CompilerInstance &B;
+
+  llvm::StringSet<> TranslatedModules;
+
+public:
+  Translator(CompilerInstance &A, const CompilerInstance &B) : A(A), B(B) {}
+
+  template  Optional translate(const Optional &BO) {
+if (!BO)
+  return None;
+return translate(*BO);
+  }
+
+  template  const T *translate(const T *BP) {
+if (!BP)
+  return nullptr;
+return &translate(*BP);
+  }
+
+  template  T *translate(T *BP) {
+if (!BP)
+  return nullptr;
+return &translate(*BP);
+  }
+
+  template  llvm::PointerUnion translate(llvm::PointerUnion BPU) {
+if (!BPU)
+  return nullptr;
+if (BPU.template is())
+  return translate(BPU.template get());
+return translate(BPU.template get());
+  }
+
+  template 
+  SmallVector translate(const SmallVector &BV) {
+SmallVector AV;
+AV.reserve(BV.size());
+for (const T &Entry : BV)
+  AV.push_back(translate(Entry));
+return AV;
+  }
+
+  template 
+  llvm::SmallSetVector translate(const llvm::SmallSetVector& BSSV) {
+llvm::SmallSetVector ASSV;
+for (const auto &Entry : BSSV)
+  ASSV.insert(translate(Entry));
+return ASSV;
+  }
+
+  const FileEntry &translate(const FileEntry &BFE) {
+return **A.getFileManager().getFile(BFE.getName());
+  }
+
+  FileEntryRef translate(FileEntryRef BFE) {
+return *A.getFileManager().getOptionalFileRef(BFE.getName());
+  }
+
+  const DirectoryEntry &translate(const DirectoryEntry &BDE) {
+return **A.getFileManager().getDirectory(BDE.getName());
+  }
+
+  SourceLocation translate(SourceLocation BLoc) {
+auto &ASM = A.getSourceManager();
+auto &BSM = B.getSourceManager();
+
+auto BFileID = BSM.getFileID(BLoc);
+auto BFileCharacteristic = BSM.getFileCharacteristic(BLoc);
+auto *AFileEntry = translate(BSM.getFileEntryForID(BFileID));
+auto AFileID = ASM.getOrCreateFileID(AFileEntry, BFileCharacteristic);
+
+auto AOffset = BSM.getFileOffset(BLoc);
+
+return ASM.getComposedLoc(AFileID, AOffset);
+  }
+
+  Module::Header translate(const Module::Header &BHeader) {
+return Module::Header{BHeader.NameAsWritten,
+   

[PATCH] D133052: [clang] Avoid crash when expanding conversion templates in concepts.

2022-11-02 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google abandoned this revision.
luken-google added a comment.

Abandoned in favor of Erich's patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133052

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


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-11-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

It looks like precommit CI caught a relevant issue that should be addressed.

Also, there's an in-progress patch that might be worth keeping an eye on in 
case it changes the behavior for clang-repl in bad ways: 
https://reviews.llvm.org/D137020 -- the patch causes unknown declaration 
specifiers to be parsed as if they were a type specifier rather than an 
expression, which could potentially change repl behavior.




Comment at: clang/include/clang/AST/Decl.h:4255
 
+/// A declaration that models statements on the global scope. This declaration
+/// supports incremental and interactive C/C++.





Comment at: clang/include/clang/AST/Decl.h:4258
+///
+///\note This is used in libInterpreter, clang -cc1 -fincremental-extensions 
and
+/// in tools such as clang-repl.





Comment at: clang/include/clang/AST/Decl.h:4271-4276
+  void setStmts(ASTContext &C, ArrayRef Statements) {
+if (!Statements.empty()) {
+  Stmts = new (C) Stmt *[Statements.size()];
+  std::copy(Statements.begin(), Statements.end(), Stmts);
+  NumStmts = Statements.size();
+}

I think we probably want this to `assert(Statements.empty())` rather than 
silently fail to set the statements.



Comment at: clang/include/clang/AST/Decl.h:4274
+  Stmts = new (C) Stmt *[Statements.size()];
+  std::copy(Statements.begin(), Statements.end(), Stmts);
+  NumStmts = Statements.size();

It's a noop change, but perhaps `std::unitialized_copy` instead?



Comment at: clang/include/clang/AST/Decl.h:4287
+  FunctionDecl *getOrConvertToFunction();
+  ArrayRef statements() const { return {Stmts, NumStmts}; }
+

Should we add an overload pair here for better const correctness? e.g.,
```
ArrayRef statements() const { return {Stmts, NumStmts}; }
ArrayRef statements() { return {Stmts, NumStmts}; }
```



Comment at: clang/include/clang/Basic/DeclNodes.td:98
 def FileScopeAsm : DeclNode;
+def TopLevelStmt : DeclNode;
 def AccessSpec : DeclNode;

Oh boy, that node name is a hoot. It ends in `Stmt` but it's a `Decl`. :-D I 
think it's fine because it matches the convention used for all the other 
identifiers here, but it may be worth thinking about whether we want a 
different name for the AST node like `TopLevelPseudoStmtDecl` or 
`FileScopePseudoStatementDecl`. I don't insist on a change here though, just 
something to consider.



Comment at: clang/include/clang/Lex/Preprocessor.h:1782-1785
   void enableIncrementalProcessing(bool value = true) {
-IncrementalProcessing = value;
+// FIXME: Drop this interface.
+const_cast(getLangOpts()).IncrementalExtensions = value;
   }

We should be able to drop this as part of this patch, right? (I think you can 
modify the `IncrementalAction` object so that it calls 
`CI.getLangOpts().IncrementalExtensions = true;` if needed, but you're passing 
the cc1 flag to the invocation and so I think you can maybe remove this call 
entirely.)



Comment at: clang/lib/AST/Decl.cpp:5244
+   llvm::ArrayRef Stmts) {
+  assert(Stmts.size());
+  assert(C.getLangOpts().IncrementalExtensions &&





Comment at: clang/lib/AST/Decl.cpp:5251
+
+  TopLevelStmtDecl *TLSD = new (C, DC) TopLevelStmtDecl(DC, BeginLoc);
+  TLSD->setStmts(C, Stmts);





Comment at: clang/lib/AST/Decl.cpp:5270-5273
+  IdentifierInfo *name =
+  &C.Idents.get("_stmts_" + llvm::utostr((uintptr_t)this));
+  SourceLocation noLoc;
+  SourceLocation beginLoc = Stmts[0]->getBeginLoc();

Some renaming for style, but also, this gets a name that's actually a reserved 
identifier instead of one that the user could potentially be using.



Comment at: clang/lib/AST/Decl.cpp:5276-5277
+  QualType FunctionTy = C.getFunctionType(C.VoidTy, llvm::None, EPI);
+  auto *TSI = C.getTrivialTypeSourceInfo(FunctionTy);
+  TranslationUnitDecl *TUDecl = cast(getDeclContext());
+  FD = FunctionDecl::Create(C, TUDecl, getBeginLoc(), noLoc, name, FunctionTy,





Comment at: clang/lib/AST/Decl.cpp:5282
+  auto StmtArrayRef = llvm::makeArrayRef(Stmts, NumStmts);
+  CompoundStmt *Body = CompoundStmt::Create(
+  C, StmtArrayRef, FPOptionsOverride(), beginLoc, getEndLoc());





Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6358
+  case Decl::TopLevelStmt: {
+FunctionDecl *FD = cast(D)->getOrConvertToFunction();
+EmitTopLevelDecl(FD);





Comment at: clang/lib/Parse/ParseDecl.cpp:5388-5389
+
+  // FIXME: Remove the incremental processing pre-condition and verify clang
+  // still can pass its test suite, which will harden `isDeclarationStatement`.

[PATCH] D137172: [Clang] Implement CWG2358 Explicit capture of value

2022-11-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 472637.
cor3ntin added a comment.

Fix tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137172

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
  clang/test/CXX/drs/dr23xx.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -13956,7 +13956,7 @@
 https://wg21.link/cwg2358";>2358
 CD5
 Explicit capture of value
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2359";>2359
Index: clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
@@ -1,4 +1,8 @@
-// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -Wno-c++14-extensions -verify
+// RUN: %clang_cc1 -std=c++17 %s -Wunused -Wno-unused-lambda-capture -Wno-c++14-extensions -verify
+
+
+const int global = 0;
 
 void f2() {
   int i = 1;
@@ -7,7 +11,20 @@
   void g3(int = ([=]{ return i; })()); // expected-error{{lambda expression in default argument cannot capture any entity}}
   void g4(int = ([=]{ return 0; })());
   void g5(int = ([]{ return sizeof i; })());
+  void g6(int = ([x=1, y = global, &z = global]{ return x; })());
+  void g7(int = ([x=i, &y=i]{ return x; })()); // expected-error 2{{default argument references local variable 'i' of enclosing function}}
+}
+
+#if __cplusplus >= 201703L
+int global_array[] = { 1, 2 };
+auto [ga, gb] = global_array;
+
+void structured_bindings() {
+  int array[] = { 1, 2 };
+  auto [a, b] = array;
+  void func(int c = [x = a, &xref = a, y = ga, &yref = ga] { return x; }()); // expected-error 2{{default argument references local variable 'a' of enclosing function}}
 }
+#endif
 
 namespace lambda_in_default_args {
   int f(int = [] () -> int { int n; return ++n; } ());
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -89,6 +89,16 @@
 #pragma clang __debug dump not_use_2
 }
 
+#if __cplusplus >= 201402L
+namespace dr2358 { // dr2358: 16
+  void f2() {
+int i = 1;
+void g1(int = [xxx=1] { return xxx; }());  // OK
+void g2(int = [xxx=i] { return xxx; }());  // expected-error {{default argument references local variable 'i' of enclosing function}}
+  }
+}
+#endif
+
 #if __cplusplus >= 201707L
 // Otherwise, if the qualified-id std::tuple_size names a complete class
 // type **with a member value**, the expression std::tuple_size::value shall
Index: clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
===
--- clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
+++ clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
@@ -27,5 +27,7 @@
   struct S { int i; };
   auto [x] = S();
 
-  extern void h7(int = x); // FIXME: reject
+  extern void h7(int = x);
+  // expected-error@-1 {{default argument references local variable 'x' of enclosing function}}
+
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -102,24 +102,31 @@
   return S.Diag(DRE->getBeginLoc(),
 diag::err_param_default_argument_references_param)
  << Param->getDeclName() << DefaultArg->getSourceRange();
-  } else if (const auto *VDecl = dyn_cast(Decl)) {
-// C++ [dcl.fct.default]p7:
-//   Local variables shall not be used in default argument
-//   expressions.
-//
-// C++17 [dcl.fct.default]p7 (by CWG 2082):
-//   A local variable shall not appear as a potentially-evaluated
-//   expression in a default argument.
-//
-// C++20 [dcl.fct.default]p7 (DR as part of P0588R1, see also CWG 2346):
-//   Note: A local variable cannot be odr-used (6.3) in a default argument.
-//
-if (VDecl->isLocalVarDecl() && !DRE->isNonOdrUse())
-  return S.Diag(DRE->getBeginLoc(),
-diag::err_param_default_argument_references_local)
- << VDecl->getDeclName() << DefaultArg->getSourceRange();
+  } else {
+const VarDecl *VD = nullptr;
+if (const auto *BD = dyn_cast(Decl))
+  VD = dyn_cast_if_present(BD->getDecomposedDecl());
+else
+  VD = dyn_cast(Decl);
+if (VD) {
+  // C++ [dcl.fct.default]p7:
+  //   Local variables shall not be used in default argument
+  //   expressions.
+   

[PATCH] D137263: add boundary check for ASTUnresolvedSet::erase

2022-11-02 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou created this revision.
zhouyizhou added reviewers: chandlerc, aprantl, rsmith, rjmccall.
Herald added a project: All.
zhouyizhou requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When compile following code with clang (Debug build), Assertion will be 
triggered.

struct A
{

  struct Nested {};
  operator Nested*() {return 0;};

};

struct B : A
{

  using A::operator typename A::Nested*;
  operator typename A::Nested *() {
  struct A * thi = this;
  return *thi;
  };

};

The assertion fail is caused by:
void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
when size of Decls is 1 before erase.

clang-14 build on Ubuntu 22.04 don't trigger above assertion because clang-14 
using g++ -std=c++14 by default:

_ZN5clang16ASTUnresolvedSet5eraseEj:
.LFB3970:
.cfi_startproc
endbr64
pushq   %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq%rsp, %rbp
.cfi_def_cfa_register 6
pushq   %r12
pushq   %rbx
subq$16, %rsp
.cfi_offset 12, -24
.cfi_offset 3, -32
movq%rdi, -24(%rbp)
movl%esi, -28(%rbp)
movq-24(%rbp), %r12
movq-24(%rbp), %rax
movl-28(%rbp), %edx
movl%edx, %esi
movq%rax, %rdi
call_ZN5clang9ASTVectorINS_14DeclAccessPairEEixEj
movq%rax, %rbx
movq%r12, %rdi
call_ZN5clang9ASTVectorINS_14DeclAccessPairEE12pop_back_valEv
movq%rax, (%rbx)

We can see when compile with -std=c++14 
_ZN5clang9ASTVectorINS_14DeclAccessPairEEixEj is called before 
_ZN5clang9ASTVectorINS_14DeclAccessPairEE12pop_back_valEv, so above assertion 
will not trigger

Thanks for review my patch
Zhouyi Zhou
zhouzho...@gmail.com


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137263

Files:
  clang/include/clang/AST/ASTUnresolvedSet.h


Index: clang/include/clang/AST/ASTUnresolvedSet.h
===
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (Decls.size() == 1) /// Let else branch complain when size < 1
+  Decls.pop_back_val();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 


Index: clang/include/clang/AST/ASTUnresolvedSet.h
===
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (Decls.size() == 1) /// Let else branch complain when size < 1
+  Decls.pop_back_val();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137209: [OPENMP]Initial support for error directive.

2022-11-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 472640.
jyu2 added a comment.

Thanks Alexey for the review.  This is to address his comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137209

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/OpenMP/error_ast_print.cpp
  clang/test/OpenMP/error_message.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -526,6 +526,7 @@
 }
 def OMP_TaskYield : Directive<"taskyield"> {}
 def OMP_Barrier : Directive<"barrier"> {}
+def OMP_Error : Directive<"error"> {}
 def OMP_TaskWait : Directive<"taskwait"> {
   let allowedClauses = [
 VersionedClause
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -712,6 +712,9 @@
   case Stmt::OMPTaskwaitDirectiveClass:
 K = CXCursor_OMPTaskwaitDirective;
 break;
+  case Stmt::OMPErrorDirectiveClass:
+K = CXCursor_OMPErrorDirective;
+break;
   case Stmt::OMPTaskgroupDirectiveClass:
 K = CXCursor_OMPTaskgroupDirective;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2164,6 +2164,7 @@
   void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D);
   void VisitOMPBarrierDirective(const OMPBarrierDirective *D);
   void VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D);
+  void VisitOMPErrorDirective(const OMPErrorDirective *D);
   void VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *D);
   void
   VisitOMPCancellationPointDirective(const OMPCancellationPointDirective *D);
@@ -3114,6 +3115,10 @@
   VisitOMPExecutableDirective(D);
 }
 
+void EnqueueVisitor::VisitOMPErrorDirective(const OMPErrorDirective *D) {
+  VisitOMPExecutableDirective(D);
+}
+
 void EnqueueVisitor::VisitOMPTaskgroupDirective(
 const OMPTaskgroupDirective *D) {
   VisitOMPExecutableDirective(D);
@@ -5819,6 +5824,8 @@
 return cxstring::createRef("OMPBarrierDirective");
   case CXCursor_OMPTaskwaitDirective:
 return cxstring::createRef("OMPTaskwaitDirective");
+  case CXCursor_OMPErrorDirective:
+return cxstring::createRef("OMPErrorDirective");
   case CXCursor_OMPTaskgroupDirective:
 return cxstring::createRef("OMPTaskgroupDirective");
   case CXCursor_OMPFlushDirective:
Index: clang/test/OpenMP/error_message.cpp
===
--- /dev/null
+++ clang/test/OpenMP/error_message.cpp
@@ -0,0 +1,114 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+
+template 
+T tmain(T argc) {
+  if (argc)
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+if (argc) {
+#pragma omp error
+}
+  while (argc)
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+while (argc) {
+#pragma omp error
+}
+  do
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+while (argc)
+  ;
+  do {
+#pragma omp error
+  } while (argc);
+  switch (argc)
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+switch (argc)
+case 1:
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+  switch (argc)
+  case 1: {
+#pragma omp error
+  }
+  switch (argc) {
+#pragma omp error
+  case 1:
+#pragma omp error
+break;
+  default: {
+#pragma omp error
+  } break;
+  }
+  for (;;)
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+for (;;) {
+#pragma omp error
+}
+label:
+#pragma omp error
+label1 : {
+#pragma omp error
+}
+if (1)
+  label2:
+#pragma omp erro

[PATCH] D137209: [OPENMP]Initial support for error directive.

2022-11-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/include/clang/AST/StmtOpenMP.h:6229
+/// \endcode
+class OMPErrorDirective : public OMPExecutableDirective {
+  friend class ASTStmtReader;

ABataev wrote:
> final
Sorry, forget that.  Changed.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMP.td:529
 def OMP_Barrier : Directive<"barrier"> {}
+def OMP_Terror : Directive<"error"> {}
 def OMP_TaskWait : Directive<"taskwait"> {

ABataev wrote:
> OMP_error
:-(   Thank you so much!  Changed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137209

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


[PATCH] D137263: add boundary check for ASTUnresolvedSet::erase

2022-11-02 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou updated this revision to Diff 472642.
zhouyizhou added a comment.

We should also consider the situation of erasing the size - 1th element


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

https://reviews.llvm.org/D137263

Files:
  clang/include/clang/AST/ASTUnresolvedSet.h


Index: clang/include/clang/AST/ASTUnresolvedSet.h
===
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (I == (Decls.size() - 1))
+  Decls.pop_back_val();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 


Index: clang/include/clang/AST/ASTUnresolvedSet.h
===
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (I == (Decls.size() - 1))
+  Decls.pop_back_val();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134267: [C++] [Modules] Support one phase compilation model for named modules

2022-11-02 Thread Ben Boeckel via Phabricator via cfe-commits
ben.boeckel added a comment.

I tried applying this patch to your MyP1689 branch (fixing conflicts with 
attempts there), but it seems that something isn't being plumbed properly:

  clang-15: error: unknown argument: 
'-fc++-module-file-output=CMakeFiles/export_bmi_and_interfaces.dir/importable.pcm'
  clang-15: error: unable to create default module cache path 
"/home/boeckb/.cache/clang/ModuleCache": No such file or direc
  tory

There's no way to disable the "module cache path" either (it fails here because 
I symlinked it to `/dev/null` to avoid things "working" behind my back).


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

https://reviews.llvm.org/D134267

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


[PATCH] D137266: [RISCV] Move RVVBitsPerBlock to TargetParser.h so we can use it in clang. NFC

2022-11-02 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: reames, frasercrmck, rogfer01, kito-cheng.
Herald added subscribers: sunshaoce, VincentWu, StephenFan, vkmr, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, 
arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137266

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Target/RISCV/RISCVISelLowering.h


Index: llvm/lib/Target/RISCV/RISCVISelLowering.h
===
--- llvm/lib/Target/RISCV/RISCVISelLowering.h
+++ llvm/lib/Target/RISCV/RISCVISelLowering.h
@@ -18,6 +18,7 @@
 #include "llvm/CodeGen/CallingConvLower.h"
 #include "llvm/CodeGen/SelectionDAG.h"
 #include "llvm/CodeGen/TargetLowering.h"
+#include "llvm/Support/TargetParser.h"
 
 namespace llvm {
 class RISCVSubtarget;
@@ -325,11 +326,6 @@
 };
 } // namespace RISCVISD
 
-namespace RISCV {
-// We use 64 bits as the known part in the scalable vector types.
-static constexpr unsigned RVVBitsPerBlock = 64;
-} // namespace RISCV
-
 class RISCVTargetLowering : public TargetLowering {
   const RISCVSubtarget &Subtarget;
 
Index: llvm/include/llvm/Support/TargetParser.h
===
--- llvm/include/llvm/Support/TargetParser.h
+++ llvm/include/llvm/Support/TargetParser.h
@@ -157,6 +157,9 @@
 
 namespace RISCV {
 
+// We use 64 bits as the known part in the scalable vector types.
+static constexpr unsigned RVVBitsPerBlock = 64;
+
 enum CPUKind : unsigned {
 #define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH) CK_##ENUM,
 #define TUNE_PROC(ENUM, NAME) CK_##ENUM,
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -255,7 +255,8 @@
   if (unsigned MinVLen = ISAInfo->getMinVLen()) {
 unsigned MaxVLen = ISAInfo->getMaxVLen();
 // RISCV::RVVBitsPerBlock is 64.
-return std::pair(MinVLen/64, MaxVLen/64);
+return std::make_pair(MinVLen / llvm::RISCV::RVVBitsPerBlock,
+  MaxVLen / llvm::RISCV::RVVBitsPerBlock);
   }
 
   return None;


Index: llvm/lib/Target/RISCV/RISCVISelLowering.h
===
--- llvm/lib/Target/RISCV/RISCVISelLowering.h
+++ llvm/lib/Target/RISCV/RISCVISelLowering.h
@@ -18,6 +18,7 @@
 #include "llvm/CodeGen/CallingConvLower.h"
 #include "llvm/CodeGen/SelectionDAG.h"
 #include "llvm/CodeGen/TargetLowering.h"
+#include "llvm/Support/TargetParser.h"
 
 namespace llvm {
 class RISCVSubtarget;
@@ -325,11 +326,6 @@
 };
 } // namespace RISCVISD
 
-namespace RISCV {
-// We use 64 bits as the known part in the scalable vector types.
-static constexpr unsigned RVVBitsPerBlock = 64;
-} // namespace RISCV
-
 class RISCVTargetLowering : public TargetLowering {
   const RISCVSubtarget &Subtarget;
 
Index: llvm/include/llvm/Support/TargetParser.h
===
--- llvm/include/llvm/Support/TargetParser.h
+++ llvm/include/llvm/Support/TargetParser.h
@@ -157,6 +157,9 @@
 
 namespace RISCV {
 
+// We use 64 bits as the known part in the scalable vector types.
+static constexpr unsigned RVVBitsPerBlock = 64;
+
 enum CPUKind : unsigned {
 #define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH) CK_##ENUM,
 #define TUNE_PROC(ENUM, NAME) CK_##ENUM,
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -255,7 +255,8 @@
   if (unsigned MinVLen = ISAInfo->getMinVLen()) {
 unsigned MaxVLen = ISAInfo->getMaxVLen();
 // RISCV::RVVBitsPerBlock is 64.
-return std::pair(MinVLen/64, MaxVLen/64);
+return std::make_pair(MinVLen / llvm::RISCV::RVVBitsPerBlock,
+  MaxVLen / llvm::RISCV::RVVBitsPerBlock);
   }
 
   return None;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

2022-11-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

I think this is basically good to go, but I'll let other people give it a look 
too




Comment at: clang/lib/AST/ExprConstant.cpp:9987-9990
+} else {
+  llvm_unreachable(
+  "Expression is neither an init list nor a C++ paren list");
+}





Comment at: clang/lib/CodeGen/CGExprAgg.cpp:91
+  void EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, QualType 
ArrayQTy,
+ Expr *E, ArrayRef InitExprs);
 

Could you give `E` a better name?



Comment at: clang/lib/CodeGen/CGExprAgg.cpp:479
 void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
-   QualType ArrayQTy, InitListExpr *E) {
-  uint64_t NumInitElements = E->getNumInits();
+   QualType ArrayQTy, Expr *E,
+   ArrayRef InitExprs) {

Ditto


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

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


[PATCH] D135128: [clang][cli] Simplify repetitive macro invocations

2022-11-02 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG12d8e7c6ade5: [cmake][msvc] Enable standards-conforming 
preprocessor (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D135128?vs=465112&id=472651#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135128

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -481,6 +481,10 @@
 
   append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 
+  # Enable standards-conforming preprocessor.
+  # https://learn.microsoft.com/en-us/cpp/build/reference/zc-preprocessor
+  append("/Zc:preprocessor" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+
   # Some projects use the __cplusplus preprocessor macro to check support for
   # a particular version of the C++ standard. When this option is not specified
   # explicitly, macro's value is "199711L" that implies C++98 Standard.


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -481,6 +481,10 @@
 
   append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 
+  # Enable standards-conforming preprocessor.
+  # https://learn.microsoft.com/en-us/cpp/build/reference/zc-preprocessor
+  append("/Zc:preprocessor" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+
   # Some projects use the __cplusplus preprocessor macro to check support for
   # a particular version of the C++ standard. When this option is not specified
   # explicitly, macro's value is "199711L" that implies C++98 Standard.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137263: add boundary check for ASTUnresolvedSet::erase

2022-11-02 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou added a comment.

Following is the back trace when the assertion fires before my fix:
#6  0x77960e96 in __GI___assert_fail (assertion=0x656ed285 "Begin + 
idx < End",

  file=0x656ed240 
"/tmp/llvm-test/llvm-project.save/clang/include/clang/AST/ASTVector.h", 
line=112, 
  function=0x656ed1b0 "T& clang::ASTVector::operator[](unsigned int) 
[with T = clang::DeclAccessPair; clang::ASTVector::reference = 
clang::DeclAccessPair&]") at ./assert/assert.c:101

#7  0x5f448c05 in clang::ASTVector::operator[] 
(this=0x691a19b8, idx=0)

  at /tmp/llvm-test/llvm-project.save/clang/include/clang/AST/ASTVector.h:112

#8  0x5f446e26 in clang::ASTUnresolvedSet::erase (this=0x691a19b8, 
I=0)

  at 
/tmp/llvm-test/llvm-project.save/clang/include/clang/AST/ASTUnresolvedSet.h:72

#9  0x5f43e7a3 in clang::CXXRecordDecl::removeConversion 
(this=0x691a18d8, ConvDecl=0x691a1c48)

  at /tmp/llvm-test/llvm-project.save/clang/lib/AST/DeclCXX.cpp:1797

#10 0x5e121349 in clang::Sema::HideUsingShadowDecl 
(this=0x6918f990, S=0x691acce0, Shadow=0x691a1c48)

  at /tmp/llvm-test/llvm-project.save/clang/lib/Sema/SemaDeclCXX.cpp:12158

#11 0x5e80bc89 in clang::Sema::CheckOverload (this=0x6918f990, 
S=0x691acce0, New=0x691a1da0, Old=...,

  Match=@0x7fff72b8: 0x0, NewIsUsingDecl=false) at 
/tmp/llvm-test/llvm-project.save/clang/lib/Sema/SemaOverload.cpp:1063

#12 0x5dfdb925 in clang::Sema::CheckFunctionDeclaration 
(this=0x6918f990, S=0x691acce0, NewFD=0x691a1da0,

  Previous=..., IsMemberSpecialization=false, DeclIsDefn=true)
  at /tmp/llvm-test/llvm-project.save/clang/lib/Sema/SemaDecl.cpp:11356

#13 0x5dfd64f3 in clang::Sema::ActOnFunctionDeclarator 
(this=0x6918f990, S=0x691acce0, D=...,

  DC=0x691a1918, TInfo=0x691a1d68, Previous=..., 
TemplateParamListsRef=..., AddToScope=@0x7fff7b30: true)
  at /tmp/llvm-test/llvm-project.save/clang/lib/Sema/SemaDecl.cpp:10205

#14 0x5dfc57cb in clang::Sema::HandleDeclarator (this=0x6918f990, 
S=0x691acce0, D=..., TemplateParamLists=...)

  at /tmp/llvm-test/llvm-project.save/clang/lib/Sema/SemaDecl.cpp:6348

--Type  for more, q to quit, c to continue without paging--
#15 0x5e0fa7bc in clang::Sema::ActOnCXXMemberDeclarator 
(this=0x6918f990, S=0x691acce0, AS=clang::AS_public,

  D=..., TemplateParameterLists=..., BW=0x0, VS=..., 
InitStyle=clang::ICIS_NoInit)
  at /tmp/llvm-test/llvm-project.save/clang/lib/Sema/SemaDeclCXX.cpp:3477

#16 0x5dc5b40a in clang::Parser::ParseCXXInlineMethodDef 
(this=0x6919b200, AS=clang::AS_public, AccessAttrs=...,

  D=..., TemplateInfo=..., VS=..., PureSpecLoc=...)
  at 
/tmp/llvm-test/llvm-project.save/clang/lib/Parse/ParseCXXInlineMethods.cpp:42

#17 0x5dc9b22b in clang::Parser::ParseCXXClassMemberDeclaration 
(this=0x6919b200, AS=clang::AS_public,

  AccessAttrs=..., TemplateInfo=..., TemplateDiags=0x0)
  at /tmp/llvm-test/llvm-project.save/clang/lib/Parse/ParseDeclCXX.cpp:2912

#18 0x5dc9d149 in 
clang::Parser::ParseCXXClassMemberDeclarationWithPragmas (this=0x6919b200,

  AS=@0x7fff94f0: clang::AS_public, AccessAttrs=..., 
TagType=clang::TST_struct, TagDecl=0x691a18d8)
  at /tmp/llvm-test/llvm-project.save/clang/lib/Parse/ParseDeclCXX.cpp:3343

#19 0x5dc9df12 in clang::Parser::ParseCXXMemberSpecification 
(this=0x6919b200, RecordLoc=..., AttrFixitLoc=...,

  Attrs=..., TagType=25, TagDecl=0x691a18d8) at 
/tmp/llvm-test/llvm-project.save/clang/lib/Parse/ParseDeclCXX.cpp:3547

#20 0x5dc97ce3 in clang::Parser::ParseClassSpecifier 
(this=0x6919b200, TagTokKind=clang::tok::kw_struct,

  StartLoc=..., DS=..., TemplateInfo=..., AS=clang::AS_none, 
EnteringContext=true, 
  DSC=clang::Parser::DeclSpecContext::DSC_top_level, Attributes=...)
  at /tmp/llvm-test/llvm-project.save/clang/lib/Parse/ParseDeclCXX.cpp:2063

#21 0x5dc7504a in clang::Parser::ParseDeclarationSpecifiers 
(this=0x6919b200, DS=..., TemplateInfo=...,

  AS=clang::AS_none, DSContext=clang::Parser::DeclSpecContext::DSC_top_level, 
LateAttrs=0x0)
  at /tmp/llvm-test/llvm-project.save/clang/lib/Parse/ParseDecl.cpp:4144

#22 0x5dc4a70e in clang::Parser::ParseDeclOrFunctionDefInternal 
(this=0x6919b200, Attrs=..., DS=...,

  AS=clang::AS_none) at 
/tmp/llvm-test/llvm-project.save/clang/lib/Parse/Parser.cpp:1087

#23 0x5dc4adb1 in clang::Parser::ParseDeclarationOrFunctionDefinition 
(this=0x6919b200, Attrs=..., DS=0x0,

  AS=clang::AS_none) at 
/tmp/llvm-test/llvm-project.save/clang/lib/Parse/Parser.cpp:1193

#24 0x5dc4a260 in clang::Parser::ParseExternalDeclaration 
(this=0x6919b200, Attrs=..., DS=0x0)

  at /tmp/llvm-test/llvm-project.save/clang/lib/Parse/Parser.cpp:1019

#25 0x5dc48fac in clang::Parser::ParseTopLevelDecl 
(this=0x6919b200, Result=...,

  ImportState=@0x7fffa97c: clang:

[PATCH] D135404: [clang-tidy] Add a checker for converting into C++17 variable template type traits

2022-11-02 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 472660.
royjacobson marked 4 inline comments as done.
royjacobson added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135404

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
@@ -0,0 +1,73 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-type-traits %t
+
+namespace std {
+
+template 
+struct integral_constant {
+static constexpr inline T value = x;
+};
+
+template 
+struct is_same : integral_constant {};
+
+template 
+struct is_trivially_default_constructible : integral_constant {};
+
+template 
+struct alignment_of : integral_constant {};
+
+}
+
+
+template 
+void f() {
+auto x = std::is_same::value;
+auto y = std::is_trivially_default_constructible::value;
+auto z = std::alignment_of::value;
+
+// CHECK-FIXES:  auto x = std::is_same_v;
+// CHECK-FIXES-NEXT: auto y = std::is_trivially_default_constructible_v;
+// CHECK-FIXES-NEXT: auto z = std::alignment_of_v;
+// Test that we don't get this twice or something weird like that because
+// we're in a dependant context.
+// CHECK-FIXES-NOT:  auto x = std::is_same_v;
+}
+
+void g() {
+f();
+f();
+}
+
+void h() {
+auto x = std::is_same::value;
+auto y = std::is_trivially_default_constructible::value;
+auto z = std::alignment_of::value;
+// CHECK-FIXES:  auto x = std::is_same_v;
+// CHECK-FIXES-NEXT: auto y = std::is_trivially_default_constructible_v;
+// CHECK-FIXES-NEXT: auto z = std::alignment_of_v;
+}
+
+
+template 
+struct NonDiagnosableTemplate : std::integral_constant {};
+
+struct NonDiagnosable1 : std::integral_constant {};
+struct NonDiagnosable2 {
+using value = int;
+};
+
+#define IN_A_MACRO std::is_same::value
+void macro_use() {
+bool a = IN_A_MACRO;
+}
+// Don't fix-it if we use it inside a macro.
+// CHECK-FIXES: #define IN_A_MACRO std::is_same::value
+
+void test_no_diagnostic() {
+auto x = NonDiagnosableTemplate::value;
+auto y = NonDiagnosable1::value;
+auto z = NonDiagnosable2::value(4);
+// CHECK-FIXES:  auto x = NonDiagnosableTemplate::value;
+// CHECK-FIXES-NEXT: auto y = NonDiagnosable1::value;
+// CHECK-FIXES-NEXT: auto z = NonDiagnosable2::value(4);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
@@ -0,0 +1,33 @@
+.. title:: clang-tidy - modernize-type-traits
+
+modernize-type-traits
+=
+
+
+Convert type traits from the form ``trait<...>::value`` into ``trait_v<...>``
+The template variable traits from C++17 can improve compile times, as in
+modern library implementations they don't instantiate structs.
+
+For example, this:
+
+.. code-block:: c++
+
+  std::is_same::value
+  std::is_integral::value
+
+is replaced by:
+
+.. code-block:: c++
+
+  std::is_same_v
+  std::is_integral_v
+
+Options
+---
+
+.. option:: ValueTypeTraits
+
+Specifies a list of type traits which are used with a static ``::value``
+member for metaprogramming instead of the regular one of traits available
+in the STL. This check assumes that a matching version exists with the
+same name and a ``_v`` suffix.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -276,6 +276,7 @@
`modernize-replace-random-shuffle `_, "Yes"
`modernize-return-braced-init-list `_, "Yes"
`modernize-shrink-to-fit `_, "Yes"
+   `modernize-type-traits `_, "Yes"
`modernize-unary-static-assert `_, "Yes"
`modernize-use-auto `_, "Yes"
`modernize-use-bool-literals `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,13 @@
 
   Warns when using ``do-while`` loops.
 
+- New :doc:`modernize-type-traits
+  ` check.
+
+  Finds usages of C++11 style type traits like ``std::is_same<...>::value`` and replaces
+  them with th

[PATCH] D135404: [clang-tidy] Add a checker for converting into C++17 variable template type traits

2022-11-02 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D135404#3899904 , @njames93 wrote:

> I'd also suggest using the `IgnoreUnlessSpelledInSource` traversal kind here. 
> Given that most of the time these will be instantiated we don't want to warn 
> and emit a fix for each instantiation, Or you could just add 
> `unless(isInTemplateInstantiation())` to your matcher.

I'm not sure what to do here... Until this is instantiated, I have only a 
DependentScopeDeclRefExpr that is not resolved yet. And it's important to have 
this check for dependent contexts because that's how it's usually used.




Comment at: clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp:86
+auto CurrentText = tooling::fixit::getText(*MatchedDecl, *Result.Context);
+if (replacement_regex.match(CurrentText))
+  IssuedDiag << FixItHint::CreateReplacement(

njames93 wrote:
> royjacobson wrote:
> > njames93 wrote:
> > > This fixit logic looks cumbersome, just replace the qualifier loc(::)to 
> > > the declared with an `_v`. But only iff the qualified name loc is not a 
> > > macro.
> > I think to do that I have to get the location of the template-id of the 
> > qualifier from the ClassTemplateSpecializationDecl, but I haven't really 
> > managed to do that. Or is there maybe a way to get the lexer tokens list of 
> > a source range or something like that?
> Take a look here https://godbolt.org/z/Wj5bjbqGh
> You'd want to create an insertion of `_v` at the start of the `<`
> `getQualifierLoc().getTypeLoc().getAs().getLAngleLoc()`
> Then a removal from the start of the `::` until the end of the whole expr
> `{getQualifierLoc().getEndLoc(), getEndLoc()}`
That's great debugging tool, thanks! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135404

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


[PATCH] D135128: [clang][cli] Simplify repetitive macro invocations

2022-11-02 Thread Stella Stamenova via Phabricator via cfe-commits
stella.stamenova added a comment.

This caused some failures on the windows mlir buildbot: 
https://lab.llvm.org/buildbot/#/builders/13/builds/27829


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135128

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


[PATCH] D129298: Add denormal-fp-math attribute for f16

2022-11-02 Thread David Candler via Phabricator via cfe-commits
dcandler abandoned this revision.
dcandler added a comment.

Sorry for the quiet on this. I'm going to abandon this for the moment, as what 
I eventually found was that there was some ambiguity in the ARM ABI regarding 
half-floats which would be better to address first, so that the attributes can 
map directly. There is currently only one ARM build attribute for denormals 
which reads as though it affects all precisions, but may not have been updated 
after half-float support was added. Since that maps to denormal-fp-math, which 
also controls all precisions, both may need splitting rather than just the 
function level attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129298

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


[PATCH] D137267: [clang][Headers] Only define FLT_EVAL_METHOD for C99 and later

2022-11-02 Thread Adhemerval Zanella via Phabricator via cfe-commits
zatrazz created this revision.
zatrazz added reviewers: jfb, eli.friedman, MaskRay.
Herald added a subscriber: StephenFan.
Herald added a project: All.
zatrazz requested review of this revision.
Herald added a project: clang.

It was reported by glibc conform test [1].

[1] 
https://sourceware.org/git/?p=glibc.git;a=blob;f=conform/data/float.h-data;h=7b98fc03447b8918da4a0cf47d41fb3e17f4f791;hb=HEAD


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137267

Files:
  clang/lib/Headers/float.h


Index: clang/lib/Headers/float.h
===
--- clang/lib/Headers/float.h
+++ clang/lib/Headers/float.h
@@ -86,7 +86,10 @@
 
 /* Characteristics of floating point types, C99 5.2.4.2.2 */
 
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) ||  
\
+(defined(__cplusplus) && __cplusplus >= 201103L)
 #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
+#endif
 #define FLT_ROUNDS (__builtin_flt_rounds())
 #define FLT_RADIX __FLT_RADIX__
 


Index: clang/lib/Headers/float.h
===
--- clang/lib/Headers/float.h
+++ clang/lib/Headers/float.h
@@ -86,7 +86,10 @@
 
 /* Characteristics of floating point types, C99 5.2.4.2.2 */
 
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) ||  \
+(defined(__cplusplus) && __cplusplus >= 201103L)
 #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
+#endif
 #define FLT_ROUNDS (__builtin_flt_rounds())
 #define FLT_RADIX __FLT_RADIX__
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137268: [clang][Headers] Do not define varargs macros for __need___va_list

2022-11-02 Thread Adhemerval Zanella via Phabricator via cfe-commits
zatrazz created this revision.
zatrazz added reviewers: jfb, eli.friedman, MaskRay.
Herald added subscribers: Enna1, StephenFan.
Herald added a project: All.
zatrazz requested review of this revision.
Herald added projects: clang, Sanitizers.
Herald added a subscriber: Sanitizers.

The glibc uses the define to avoid namespace polution on headers
that requires variadic argument, where the inclusion of stdarg.h is
required to obtain the va_list definition.

For such cases only __gnuc_va_list is required.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137268

Files:
  clang/lib/Headers/stdarg.h
  compiler-rt/test/sanitizer_common/TestCases/Linux/signal_send.cpp


Index: compiler-rt/test/sanitizer_common/TestCases/Linux/signal_send.cpp
===
--- compiler-rt/test/sanitizer_common/TestCases/Linux/signal_send.cpp
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/signal_send.cpp
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
Index: clang/lib/Headers/stdarg.h
===
--- clang/lib/Headers/stdarg.h
+++ clang/lib/Headers/stdarg.h
@@ -8,7 +8,17 @@
  */
 
 #ifndef __STDARG_H
+#ifndef __need___va_list
 #define __STDARG_H
+#endif /* __need___va_list */
+#undef __need___va_list
+
+#ifndef __GNUC_VA_LIST
+#define __GNUC_VA_LIST 1
+typedef __builtin_va_list __gnuc_va_list;
+#endif
+
+#ifdef __STDARG_H
 
 #ifndef _VA_LIST
 typedef __builtin_va_list va_list;
@@ -29,9 +39,6 @@
 #define va_copy(dest, src)  __builtin_va_copy(dest, src)
 #endif
 
-#ifndef __GNUC_VA_LIST
-#define __GNUC_VA_LIST 1
-typedef __builtin_va_list __gnuc_va_list;
-#endif
-
 #endif /* __STDARG_H */
+
+#endif /* not __STDARG_H */


Index: compiler-rt/test/sanitizer_common/TestCases/Linux/signal_send.cpp
===
--- compiler-rt/test/sanitizer_common/TestCases/Linux/signal_send.cpp
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/signal_send.cpp
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
Index: clang/lib/Headers/stdarg.h
===
--- clang/lib/Headers/stdarg.h
+++ clang/lib/Headers/stdarg.h
@@ -8,7 +8,17 @@
  */
 
 #ifndef __STDARG_H
+#ifndef __need___va_list
 #define __STDARG_H
+#endif /* __need___va_list */
+#undef __need___va_list
+
+#ifndef __GNUC_VA_LIST
+#define __GNUC_VA_LIST 1
+typedef __builtin_va_list __gnuc_va_list;
+#endif
+
+#ifdef __STDARG_H
 
 #ifndef _VA_LIST
 typedef __builtin_va_list va_list;
@@ -29,9 +39,6 @@
 #define va_copy(dest, src)  __builtin_va_copy(dest, src)
 #endif
 
-#ifndef __GNUC_VA_LIST
-#define __GNUC_VA_LIST 1
-typedef __builtin_va_list __gnuc_va_list;
-#endif
-
 #endif /* __STDARG_H */
+
+#endif /* not __STDARG_H */
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136022: [clang] Add time profile for constant evaluation

2022-11-02 Thread Trass3r via Phabricator via cfe-commits
Trass3r added a comment.

Thanks for this!
When I experimented 

 with this for #42754  I 
also came across functions like
Expr::isConstantInitializer
ExprConstant.cpp HandleFunctionCall/HandleConstructorCall
ByteCodeEmitter::compileFunc

Worth checking out if these are already covered or potentially useful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136022

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


[clang] c10a847 - [Assignment Tracking][2/*] Add flags to enable Assignment Tracking

2022-11-02 Thread via cfe-commits

Author: OCHyams
Date: 2022-11-02T17:06:43Z
New Revision: c10a8473f48bca32ef5e8ab78d30e3557e66d431

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

LOG: [Assignment Tracking][2/*] Add flags to enable Assignment Tracking

The Assignment Tracking debug-info feature is outlined in this RFC:

https://discourse.llvm.org/t/
rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir

Enable in clang: -Xclang -fexperimental-assignment-tracking
Enable in llvm tools: -experimental-assignment-tracking

When assignment tracking is enabled in clang it will pass on the flag to enable
the feature in lllvm. It's undefined behaviour to read IR that contains
assignment tracking metadata without specifying the feature flags.

Tests will come with later patches that add assignment tracking features.

Reviewed By: jmorse

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

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
llvm/include/llvm/IR/DebugInfo.h
llvm/lib/IR/DebugInfo.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 258ba1298f90c..183cb0c71a117 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -331,6 +331,10 @@ VALUE_CODEGENOPT(StackProbeSize, 32, 4096) ///< 
Overrides default stack
 VALUE_CODEGENOPT(WarnStackSize , 32, UINT_MAX) ///< Set via 
-fwarn-stack-size.
 CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
 CODEGENOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF 
info.
+
+CODEGENOPT(EnableAssignmentTracking, 1,0) ///< Enable the Assignment Tracking
+  ///< debug info feature feature.
+
 CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
   ///< in debug info.
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d660a2b886033..b2f334f9f8144 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5638,6 +5638,11 @@ def fctor_dtor_return_this : Flag<["-"], 
"fctor-dtor-return-this">,
 
 } // let Flags = [CC1Option, NoDriverOption]
 
+def fexperimental_assignment_tracking :
+  Flag<["-"], "fexperimental-assignment-tracking">, Group,
+  HelpText<"Enable assignment tracking debug info">,
+  MarshallingInfoFlag>;
+
 
//===--===//
 // Dependency Output Options
 
//===--===//

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 160eb1f23fba2..f87325141b7eb 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6987,18 +6987,21 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
-  // -finclude-default-header flag is for preprocessor,
-  // do not pass it to other cc1 commands when save-temps is enabled
-  if (C.getDriver().isSaveTempsEnabled() &&
-  !isa(JA)) {
-for (auto *Arg : Args.filtered(options::OPT_Xclang)) {
-  Arg->claim();
-  if (StringRef(Arg->getValue()) != "-finclude-default-header")
-CmdArgs.push_back(Arg->getValue());
+  for (auto Arg : Args.filtered(options::OPT_Xclang)) {
+Arg->claim();
+// -finclude-default-header flag is for preprocessor,
+// do not pass it to other cc1 commands when save-temps is enabled
+if (C.getDriver().isSaveTempsEnabled() &&
+!isa(JA)) {
+  if (StringRef(Arg->getValue()) == "-finclude-default-header")
+continue;
 }
-  }
-  else {
-Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+if (StringRef(Arg->getValue()) == "-fexperimental-assignment-tracking") {
+  // Add the llvm version of this flag too.
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-experimental-assignment-tracking");
+}
+CmdArgs.push_back(Arg->getValue());
   }
   for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
 A->claim();

diff  --git a/llvm/include/llvm/IR/DebugInfo.h 
b/llvm/include/llvm/IR/DebugInfo.h
index 730c69d0c622e..b35d447a7c891 100644
--- a/llvm/include/llvm/IR/DebugInfo.h
+++ b/llvm/include/llvm/IR/DebugInfo.h
@@ -159,6 +159,8 @@ class DebugInfoFinder {
   SmallPtrSet NodesSeen;
 };
 
+/// Return true if assignment tracking is enabled.
+bool getEnableAssignmentTracking();
 } // end namespace llvm
 
 #endif // LLVM_IR_DEB

[PATCH] D132221: [Assignment Tracking][2/*] Add flags to enable Assignment Tracking

2022-11-02 Thread Orlando Cazalet-Hyams via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Orlando marked an inline comment as done.
Closed by commit rGc10a8473f48b: [Assignment Tracking][2/*] Add flags to enable 
Assignment Tracking (authored by Orlando).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D132221?vs=456658&id=472669#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132221

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/include/llvm/IR/DebugInfo.h
  llvm/lib/IR/DebugInfo.cpp


Index: llvm/lib/IR/DebugInfo.cpp
===
--- llvm/lib/IR/DebugInfo.cpp
+++ llvm/lib/IR/DebugInfo.cpp
@@ -39,6 +39,13 @@
 using namespace llvm;
 using namespace llvm::dwarf;
 
+static cl::opt
+ExperimentalAssignmentTracking("experimental-assignment-tracking",
+   cl::init(false));
+bool llvm::getEnableAssignmentTracking() {
+  return ExperimentalAssignmentTracking;
+}
+
 /// Finds all intrinsics declaring local variables as living in the memory that
 /// 'V' points to. This may include a mix of dbg.declare and
 /// dbg.addr intrinsics.
Index: llvm/include/llvm/IR/DebugInfo.h
===
--- llvm/include/llvm/IR/DebugInfo.h
+++ llvm/include/llvm/IR/DebugInfo.h
@@ -159,6 +159,8 @@
   SmallPtrSet NodesSeen;
 };
 
+/// Return true if assignment tracking is enabled.
+bool getEnableAssignmentTracking();
 } // end namespace llvm
 
 #endif // LLVM_IR_DEBUGINFO_H
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6987,18 +6987,21 @@
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
-  // -finclude-default-header flag is for preprocessor,
-  // do not pass it to other cc1 commands when save-temps is enabled
-  if (C.getDriver().isSaveTempsEnabled() &&
-  !isa(JA)) {
-for (auto *Arg : Args.filtered(options::OPT_Xclang)) {
-  Arg->claim();
-  if (StringRef(Arg->getValue()) != "-finclude-default-header")
-CmdArgs.push_back(Arg->getValue());
+  for (auto Arg : Args.filtered(options::OPT_Xclang)) {
+Arg->claim();
+// -finclude-default-header flag is for preprocessor,
+// do not pass it to other cc1 commands when save-temps is enabled
+if (C.getDriver().isSaveTempsEnabled() &&
+!isa(JA)) {
+  if (StringRef(Arg->getValue()) == "-finclude-default-header")
+continue;
 }
-  }
-  else {
-Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+if (StringRef(Arg->getValue()) == "-fexperimental-assignment-tracking") {
+  // Add the llvm version of this flag too.
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-experimental-assignment-tracking");
+}
+CmdArgs.push_back(Arg->getValue());
   }
   for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
 A->claim();
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5638,6 +5638,11 @@
 
 } // let Flags = [CC1Option, NoDriverOption]
 
+def fexperimental_assignment_tracking :
+  Flag<["-"], "fexperimental-assignment-tracking">, Group,
+  HelpText<"Enable assignment tracking debug info">,
+  MarshallingInfoFlag>;
+
 
//===--===//
 // Dependency Output Options
 
//===--===//
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -331,6 +331,10 @@
 VALUE_CODEGENOPT(WarnStackSize , 32, UINT_MAX) ///< Set via 
-fwarn-stack-size.
 CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
 CODEGENOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF 
info.
+
+CODEGENOPT(EnableAssignmentTracking, 1,0) ///< Enable the Assignment Tracking
+  ///< debug info feature feature.
+
 CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
   ///< in debug info.
 


Index: llvm/lib/IR/DebugInfo.cpp
===
--- llvm/lib/IR/DebugInfo.cpp
+++ llvm/lib/IR/DebugInfo.cpp
@@ -39,6 +39,13 @@
 using namespace llvm;
 using namespace llvm::dwarf;
 
+static cl::opt
+  

[PATCH] D137269: [Clang][AArch64][Darwin] Enable GlobalISel by default for Darwin ARM64 platforms.

2022-11-02 Thread Amara Emerson via Phabricator via cfe-commits
aemerson created this revision.
aemerson added reviewers: paquette, Gerolf, ab, t.p.northover, arsenm.
aemerson added a project: LLVM.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
aemerson requested review of this revision.
Herald added subscribers: MaskRay, wdng.
Herald added a project: clang.

We do this in the front-end instead of the backend so as to not change the 
default behavior for llc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137269

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/global-isel.c


Index: clang/test/Driver/global-isel.c
===
--- clang/test/Driver/global-isel.c
+++ clang/test/Driver/global-isel.c
@@ -6,6 +6,7 @@
 // RUN: %clang -target aarch64 -fglobal-isel -S %s -### 2>&1 | FileCheck 
--check-prefix=ARM64-DEFAULT %s
 // RUN: %clang -target aarch64 -fglobal-isel -S -O0 %s -### 2>&1 | FileCheck 
--check-prefix=ARM64-O0 %s
 // RUN: %clang -target aarch64 -fglobal-isel -S -O2 %s -### 2>&1 | FileCheck 
--check-prefix=ARM64-O2 %s
+// RUN: %clang -arch arm64 -fglobal-isel -S -O2 %s -### 2>&1 | FileCheck 
--check-prefixes=DARWIN-ARM64-O2,ENABLED %s
 // RUN: %clang -target aarch64 -fglobal-isel -Wno-global-isel -S -O2 %s -### 
2>&1 | FileCheck --check-prefix=ARM64-O2-NOWARN %s
 
 // RUN: %clang -target x86_64 -fglobal-isel -S %s -### 2>&1 | FileCheck 
--check-prefix=X86_64 %s
@@ -27,6 +28,7 @@
 // ARM64-DEFAULT-NOT: warning: -fglobal-isel
 // ARM64-DEFAULT-NOT: "-global-isel-abort=2"
 // ARM64-O0-NOT: warning: -fglobal-isel
+// DARWIN-ARM64-O2-NOT: warning: -fglobal-isel
 // ARM64-O2: warning: -fglobal-isel support is incomplete for this 
architecture at the current optimization level
 // ARM64-O2: "-mllvm" "-global-isel-abort=2"
 // ARM64-O2-NOWARN-NOT: warning: -fglobal-isel
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -381,10 +381,11 @@
   D.Diag(diag::err_drv_bitcode_unsupported_on_toolchain);
   }
 
-  // If GlobalISel is enabled, pass it through to LLVM.
-  if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
-   options::OPT_fno_global_isel)) {
-if (A->getOption().matches(options::OPT_fglobal_isel)) {
+  // GlobalISel is enabled by default on AArch64 Darwin.
+  if (getToolChain().getArch() == llvm::Triple::aarch64) {
+Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
+ options::OPT_fno_global_isel);
+if (!A || !A->getOption().matches(options::OPT_fno_global_isel)) {
   CmdArgs.push_back("-mllvm");
   CmdArgs.push_back("-global-isel");
   // Disable abort and fall back to SDAG silently.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7203,15 +7203,29 @@
   if (SplitLTOUnit)
 CmdArgs.push_back("-fsplit-lto-unit");
 
-  if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
-   options::OPT_fno_global_isel)) {
+  A = Args.getLastArg(options::OPT_fglobal_isel, options::OPT_fno_global_isel);
+  // If a configuration is fully supported, we don't issue any warnings or
+  // remarks.
+  bool IsFullySupported = getToolChain().getTriple().isOSDarwin() &&
+  Triple.getArch() == llvm::Triple::aarch64;
+  if (IsFullySupported) {
+if (A && A->getOption().matches(options::OPT_fno_global_isel)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-global-isel=0");
+} else {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-global-isel=1");
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-global-isel-abort=0");
+}
+  } else if (A) {
 CmdArgs.push_back("-mllvm");
 if (A->getOption().matches(options::OPT_fglobal_isel)) {
   CmdArgs.push_back("-global-isel=1");
 
   // GISel is on by default on AArch64 -O0, so don't bother adding
   // the fallback remarks for it. Other combinations will add a warning of
-  // some kind.
+  // some kind, unless we're on Darwin.
   bool IsArchSupported = Triple.getArch() == llvm::Triple::aarch64;
   bool IsOptLevelSupported = false;
 


Index: clang/test/Driver/global-isel.c
===
--- clang/test/Driver/global-isel.c
+++ clang/test/Driver/global-isel.c
@@ -6,6 +6,7 @@
 // RUN: %clang -target aarch64 -fglobal-isel -S %s -### 2>&1 | FileCheck --check-prefix=ARM64-DEFAULT %s
 // RUN: %clang -target aarch64 -fglobal-isel -S -O0 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O0 %s
 // RUN: %clang -target aarch64 -fglobal-isel -S -O2 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O2 %s
+// RUN: %clang -arch arm64 -

[PATCH] D137227: [asan] Default to -fsanitize-address-use-odr-indicator for non-Windows

2022-11-02 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov accepted this revision.
kstoimenov added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll:8
 ;
-; RUN: opt < %s -passes=asan -asan-globals-live-support=1 -S | 
FileCheck %s --check-prefixes=CHECK,NOCOMDAT
+; RUN: opt < %s -passes=asan -asan-globals-live-support=1 
-asan-use-odr-indicator=0 -S | FileCheck %s --check-prefixes=CHECK,NOCOMDAT
 ; Check that enabling odr indicators enables comdat for globals.

Remove extra space? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137227

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


[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-11-02 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D137269: [Clang][AArch64][Darwin] Enable GlobalISel by default for Darwin ARM64 platforms.

2022-11-02 Thread Jessica Paquette via Phabricator via cfe-commits
paquette added a comment.

maybe link back to the discourse thread in the commit message?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137269

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


[PATCH] D137269: [Clang][AArch64][Darwin] Enable GlobalISel by default for Darwin ARM64 platforms.

2022-11-02 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7218-7219
+  CmdArgs.push_back("-global-isel=1");
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-global-isel-abort=0");
+}

Why abort=0? I can understand abort=1 or 2


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137269

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


[PATCH] D135128: [clang][cli] Simplify repetitive macro invocations

2022-11-02 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D135128#3902698 , 
@stella.stamenova wrote:

> This caused some failures on the windows mlir buildbot: 
> https://lab.llvm.org/buildbot/#/builders/13/builds/27829

Thanks for the heads-up. Who would be the best person to look into this? Seems 
like this patch exposes an UB in Windows Kits 
(https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5105).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135128

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


[PATCH] D137269: [Clang][AArch64][Darwin] Enable GlobalISel by default for Darwin ARM64 platforms.

2022-11-02 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:388
+ options::OPT_fno_global_isel);
+if (!A || !A->getOption().matches(options::OPT_fno_global_isel)) {
   CmdArgs.push_back("-mllvm");

Actually I'm confused why we're duplicating this logic in both these places 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137269

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


[PATCH] D120175: [Driver] Re-run lld with --reproduce when it crashes

2022-11-02 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I noticed that when using `-fcrash-diagnostics=all` and the linker crashes, 
clang creates both preprocessor and linker repros:

  clang: note: diagnostic msg: 
/var/folders/w6/wpbtszrs7jl9dc9l5qtdkvg0gn/T/main-241332.c
  clang: note: diagnostic msg: 
/var/folders/w6/wpbtszrs7jl9dc9l5qtdkvg0gn/T/linker-crash-945b07.tar
  clang: note: diagnostic msg: 
/var/folders/w6/wpbtszrs7jl9dc9l5qtdkvg0gn/T/main-241332.sh

Is that intentional? I would've expected to only get the linker repro when the 
linker crashes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120175

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


[PATCH] D135128: [clang][cli] Simplify repetitive macro invocations

2022-11-02 Thread Stella Stamenova via Phabricator via cfe-commits
stella.stamenova added a comment.

In D135128#3902772 , @jansvoboda11 
wrote:

> In D135128#3902698 , 
> @stella.stamenova wrote:
>
>> This caused some failures on the windows mlir buildbot: 
>> https://lab.llvm.org/buildbot/#/builders/13/builds/27829
>
> Thanks for the heads-up. Who would be the best person to look into this? 
> Seems like this patch exposes an UB in Windows Kits 
> (https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5105).

We can have a look - but let's revert this change in the meantime to make the 
bot green again. We'll try to have a fix or a workaround sometime next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135128

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


[PATCH] D120175: [Driver] Re-run lld with --reproduce when it crashes

2022-11-02 Thread Alex Brachet via Phabricator via cfe-commits
abrachet added a comment.

In D120175#3902789 , @thakis wrote:

> I noticed that when using `-fcrash-diagnostics=all` and the linker crashes, 
> clang creates both preprocessor and linker repros:
>
>   clang: note: diagnostic msg: 
> /var/folders/w6/wpbtszrs7jl9dc9l5qtdkvg0gn/T/main-241332.c
>   clang: note: diagnostic msg: 
> /var/folders/w6/wpbtszrs7jl9dc9l5qtdkvg0gn/T/linker-crash-945b07.tar
>   clang: note: diagnostic msg: 
> /var/folders/w6/wpbtszrs7jl9dc9l5qtdkvg0gn/T/main-241332.sh
>
> Is that intentional? I would've expected to only get the linker repro when 
> the linker crashes.

I didn't really make a conscious decision one way or the other. I guess 
reproing all jobs leading to a crash somewhat makes sense, though it also 
doesn't seem that helpful to get the preprocessed source file. I'll send out a 
patch to fix this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120175

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


[PATCH] D135128: [clang][cli] Simplify repetitive macro invocations

2022-11-02 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Thanks, that sounds good. Reverting shortly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135128

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


[PATCH] D137104: [clangd] Add scoped enum constants to all-scopes-completion

2022-11-02 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Looks good, thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137104

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


[PATCH] D137251: [clang][cuda/hip] Allow `__noinline__` lambdas

2022-11-02 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

LGTM in principle. Please wait for @rsmith's OK.




Comment at: clang/lib/Parse/ParseExprCXX.cpp:1297-1308
+while (true) {
+  if (Tok.is(tok::kw___attribute)) {
+ParseGNUAttributes(Attr, nullptr, &D);
+  } else if (Tok.is(tok::kw___noinline__)) {
+IdentifierInfo *AttrName = Tok.getIdentifierInfo();
+SourceLocation AttrNameLoc = ConsumeToken();
+Attr.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,

Nit. I'd rearrange it a bit.
 
```
while (true) {
  if (Tok.is(tok::kw___noinline__)) {
IdentifierInfo *AttrName = Tok.getIdentifierInfo();
SourceLocation AttrNameLoc = ConsumeToken();
Attr.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
ParsedAttr::AS_Keyword);
  } else if (Tok.is(tok::kw___attribute))
ParseGNUAttributes(Attr, nullptr, &D);
  else 
break;
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137251

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


[PATCH] D120175: [Driver] Re-run lld with --reproduce when it crashes

2022-11-02 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

> I didn't really make a conscious decision one way or the other. I guess 
> reproing all jobs leading to a crash somewhat makes sense, though it also 
> doesn't seem that helpful to get the preprocessed source file. I'll send out 
> a patch to fix this

Great, thanks :)

For context, we're trying to use this flag In Production to try and debug a 
linker crash, but making the compiler repro failed for some reason – and then 
we wondered why that step has to happen at all :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120175

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


[PATCH] D136811: WIP: RFC: NFC: C++ Buffer Hardening user documentation.

2022-11-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for getting a start on this documentation, this adds a lot of clarity 
to what was being proposed! I have some questions, and some minor things to fix.




Comment at: clang/docs/SafeBuffers.rst:19
+guidelines, and it provides runtime mitigations for the situations when
+following guidelines isn’t sufficient.
+

For consistency with the rest of our docs, you should make this change 
throughout.



Comment at: clang/docs/SafeBuffers.rst:25
+a potentially unsafe operation is performed in your code;
+  - Pragmas ``unsafe_buffer_usage`` and ``only_safe_buffers`` and allow you to
+annotate sections of code as either already-hardened or not-to-be-hardened,





Comment at: clang/docs/SafeBuffers.rst:31
+convert large amounts of old code to conform to the warning;
+  - Attribute ``[[unsafe_buffer_usage]]`` lets you annotate custom functions as
+unsafe, while providing a safe alternative that can often be suggested by

H that attribute name looks problematic (more below in that section).



Comment at: clang/docs/SafeBuffers.rst:47
+not tied to this programming model. The warning may be desired independently,
+even in plain C code, if you’re hard-bent on isolating, annotating and auditing
+all buffer-related code in your codebase. That said, some of these guidelines





Comment at: clang/docs/SafeBuffers.rst:58
+operations crash on out-of-bounds accesses at runtime. And in case of C, this
+may be the only way to achieve safety. The main problem with such solution lies
+in dealing with the fact that most pointers in the code don’t have bounds





Comment at: clang/docs/SafeBuffers.rst:63-64
+either in a system of attributes significantly more advanced than
+the current solution, or a significant change in runtime representation
+of all pointers.
+

It would be helpful to have some details here about why a user would pick these 
proposed features over use of a sanitizer like asan or hwasan, which also finds 
out of bounds accesses.



Comment at: clang/docs/SafeBuffers.rst:69-70
+containers such as ``std::span``, you can achieve bounds safety by
+*simply writing good modern C++ code*. This is what this solution is designed
+to help your codebase with.
+

This makes it sound like the proposal doesn't cover C because there is no 
version of `std::span` there.



Comment at: clang/docs/SafeBuffers.rst:76
+
+Let’s start with how your code would need to look like to comply with
+the programming model.





Comment at: clang/docs/SafeBuffers.rst:90
+   manually ``delete[]`` it when appropriate.
+   (TODO: What about things like ``std::shared_ptr``)?
+2. When you deal with function or class interfaces that accept or return

We should mention as part of the model description that pointer-chasing 
structures like linked lists, trees, etc are not covered by the model.

(That said, I suspect the *implementation* of such things might be covered. 
e.g., a tree with `Node *Children[]`)



Comment at: clang/docs/SafeBuffers.rst:95
+   ``std::span``, which helps you deal with different container classes
+   uniformly.
+3. If you deal with interfaces you cannot change, such as an interface of

And what should C users do?



Comment at: clang/docs/SafeBuffers.rst:98
+   a third-party library you’re using, and these interfaces require you to pass
+   buffers as raw pointers, make sure you “containerize” these buffers
+   *as soon as possible*. For example, if the library returns a raw buffer

Similar to the single quote situation.



Comment at: clang/docs/SafeBuffers.rst:114
+   insufficient without such hardening.
+   (TODO: Will automatic fixits be able to suggest custom containers or views?)
+   (TODO: Explain how to implement such checks in a custom container?)

I would be surprised if we can find a heuristic that we'd feel confident is 
correct for most situations. e.g., `Foo buffer[10];` might be a flat array... 
or it might be a ring buffer without benefit of a wrapper class... or it may be 
a sparse matrix... and so on.



Comment at: clang/docs/SafeBuffers.rst:115
+   (TODO: Will automatic fixits be able to suggest custom containers or views?)
+   (TODO: Explain how to implement such checks in a custom container?)
+

I think this would be a good idea, especially if you can use an example of a 
more involved (but still common) container. Like, how does someone harden a 
ring buffer?



Comment at: clang/docs/SafeBuffers.rst:128
+  ``+``, ``-``, ``+=``, ``-=``,
+  - unless that number is a compile time constant ``0``;
+  - subtracti

[PATCH] D137269: [Clang][AArch64][Darwin] Enable GlobalISel by default for Darwin ARM64 platforms.

2022-11-02 Thread Amara Emerson via Phabricator via cfe-commits
aemerson added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7218-7219
+  CmdArgs.push_back("-global-isel=1");
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-global-isel-abort=0");
+}

arsenm wrote:
> Why abort=0? I can understand abort=1 or 2
Abort=1 would mean the compiler crashes on fallback, and `2` would mean we emit 
diagnostics, neither of which we want for an on-by-default configuration.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:388
+ options::OPT_fno_global_isel);
+if (!A || !A->getOption().matches(options::OPT_fno_global_isel)) {
   CmdArgs.push_back("-mllvm");

arsenm wrote:
> Actually I'm confused why we're duplicating this logic in both these places 
This one is for adding linker args which we need for LTO builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137269

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


[PATCH] D137224: clang/cmake: Simplify lit detection for standalone builds

2022-11-02 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 accepted this revision.
Ericson2314 added a comment.

LGTM. I also can't see why it would act differently.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137224

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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-02 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe marked 10 inline comments as done.
Febbe added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst:6
+
+Finds variables of non-trivially-copyable types, that are used in a copy 
construction on their last usage and suggest to wrap the usage in a `std::move`.
+The usage just before an assignment is interpreted as last usage.  

Eugene.Zelenko wrote:
> Please synchronize with Release Notes, follow 80 characters limit and use 
> double back-ticks for language constructs.
Do you mean, to add this short description to the release notes?
Is the 80 characters limit for the line, or the whole description?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D137259: [clang][modules][deps] WIP: In-memory module transfer

2022-11-02 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 472697.
jansvoboda11 added a comment.

Improve SourceLocation handling: invalid & inside predefines buffer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137259

Files:
  clang/include/clang/Frontend/CompilerInstance.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-basic.c

Index: clang/test/ClangScanDeps/modules-basic.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-basic.c
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- include/module.modulemap
+module m { header "m.h"}
+//--- include/m.h
+// empty
+
+//--- tu.c
+#include "m.h"
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -fimplicit-module-maps -I DIR/include"
+}]
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -424,6 +424,26 @@
 MD.ClangModuleMapFile = std::string(Path);
   }
 
+  if (MDC.ScanInstance.InMemoryModuleTransfer) {
+for (const auto &E : MDC.ScanInstance.SortedFiles[M->getFullModuleName()]) {
+  if (E.FE->getName().endswith("__inferred_module.map")) {
+MDC.addFileDep(MD, ModuleMap->getName());
+continue;
+  }
+  MDC.addFileDep(MD, E.FE->getName());
+}
+if (M->NoUndeclaredIncludes) {
+  for (const auto &E : MDC.ScanInstance.SortedFiles[M->getFullModuleName()]) {
+if (E.FE->getName().endswith("__inferred_module.map"))
+  continue;
+// The top-level modulemap of this module will be the input file. We
+// don't need to specify it as a module map.
+if (E.FE == ModuleMap)
+  continue;
+MD.ModuleMapFileDeps.push_back(E.FE->getName().str());
+  }
+}
+  } else {
   serialization::ModuleFile *MF =
   MDC.ScanInstance.getASTReader()->getModuleManager().lookup(
   M->getASTFile());
@@ -452,12 +472,13 @@
   return;
 MD.ModuleMapFileDeps.emplace_back(FE->getName());
   });
+  }
 
   CompilerInvocation CI = MDC.makeInvocationForModuleBuildWithoutOutputs(
   MD, [&](CompilerInvocation &BuildInvocation) {
-if (MDC.OptimizeArgs)
-  optimizeHeaderSearchOpts(BuildInvocation.getHeaderSearchOpts(),
-   *MDC.ScanInstance.getASTReader(), *MF);
+//if (MDC.OptimizeArgs)
+//  optimizeHeaderSearchOpts(BuildInvocation.getHeaderSearchOpts(),
+//   *MDC.ScanInstance.getASTReader(), *MF);
   });
 
   MDC.associateWithContextHash(CI, MD);
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -178,6 +178,8 @@
 CompilerInstance &ScanInstance = *ScanInstanceStorage;
 ScanInstance.setInvocation(std::move(Invocation));
 
+ScanInstance.InMemoryModuleTransfer = true;
+
 // Create the compiler's actual diagnostics engine.
 sanitizeDiagOpts(ScanInstance.getDiagnosticOpts());
 ScanInstance.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false);
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -1129,6 +1129,242 @@
   return LangOpts.CPlusPlus ? Language::CXX : Language::C;
 }
 
+class Translator {
+  CompilerInstance &A;
+  const CompilerInstance &B;
+
+  llvm::StringSet<> TranslatedModules;
+
+public:
+  Translator(CompilerInstance &A, const CompilerInstance &B) : A(A), B(B) {}
+
+  template  Optional translate(const Optional &BO) {
+if (!BO)
+  return None;
+return translate(*BO);
+  }
+
+  template  const T *translate(const T *BP) {
+if (!BP)
+  return nullptr;
+return &translate(*BP);
+  }
+
+  template  T *translate(T *BP) {
+if (!BP)
+  return nullptr;
+return &translate(*BP);
+  }
+
+  template 
+  llvm::PointerUnion translate(llvm::PointerUnion BPU) {
+if (!BPU)
+  return nullptr;
+if (BPU.template is())
+  return translate(BPU.template get());
+return translate(BPU.template get());
+  }
+
+  template

[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-02 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst:6
+
+Finds variables of non-trivially-copyable types, that are used in a copy 
construction on their last usage and suggest to wrap the usage in a `std::move`.
+The usage just before an assignment is interpreted as last usage.  

Febbe wrote:
> Eugene.Zelenko wrote:
> > Please synchronize with Release Notes, follow 80 characters limit and use 
> > double back-ticks for language constructs.
> Do you mean, to add this short description to the release notes?
> Is the 80 characters limit for the line, or the whole description?
> 
I meant that first sentence in documentation should be same as Release Notes 
record.

80-characters limit should be followed in code and documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D137172: [Clang] Implement CWG2358 Explicit capture of value

2022-11-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a reviewer: clang-language-wg.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!

Adding the language WG in case there are reviews coming from the peanut 
gallery. Please wait a day before landing just in case.




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:107-111
+if (const auto *BD = dyn_cast(Decl))
+  VD = dyn_cast_if_present(BD->getDecomposedDecl());
+else
+  VD = dyn_cast(Decl);
+if (VD) {

cor3ntin wrote:
> Note that https://reviews.llvm.org/D137244 introduces a utility to do that, 
> but i''d rather avoid having to many dependencies between these patches. 
So the plan is to land this change, then in D137244 change this usage to the 
helper function introduced by that patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137172

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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-02 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe updated this revision to Diff 472698.
Febbe added a comment.

Applied feedback,
Also added the documentation for the second option ``BlockedFunctions``


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst
  
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp
@@ -0,0 +1,87 @@
+// RUN: %check_clang_tidy %s -std=c++17 performance-unnecessary-copy-on-last-use %t
+// RUN: %check_clang_tidy %s -std=c++11 performance-unnecessary-copy-on-last-use %t
+#include 
+// CHECK-FIXES: #include 
+
+struct Movable {
+  Movable() = default;
+  Movable(Movable const &) = default;
+  Movable(Movable &&) = default;
+  Movable &operator=(Movable const &) = default;
+  Movable &operator=(Movable &&) = default;
+  ~Movable();
+
+  void memberUse() {}
+};
+static_assert(!std::is_trivially_copyable_v, "Movable must not be trivially copyable");
+
+void valueReceiver(Movable Mov);
+void constRefReceiver(Movable const &Mov);
+
+void valueTester() {
+  Movable Mov{};
+  valueReceiver(Mov);
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+  Mov = Movable{};
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+}
+
+void testUsageInBranch(bool Splitter) {
+  Movable Mov{};
+
+  valueReceiver(Mov);
+  if(Splitter){
+Mov.memberUse();
+  } else {
+Mov = Movable{};
+  }
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+
+  if(Splitter){
+Mov = Movable{};
+  } else {
+Mov = Movable{};
+  }
+  valueReceiver(Mov);
+  Mov.memberUse();
+}
+
+void testExplicitCopy() {
+  Movable Mov{};
+  constRefReceiver(Movable{Mov});
+  // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: constRefReceiver(Movable{std::move(Mov)});
+}
+
+Movable testReturn() {
+  Movable Mov{};
+  return Mov; // no warning, copy elision
+}
+
+Movable testReturn2(Movable && Mov, bool F) {
+  return F? Mov: Movable{}; 
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use] 
+  // CHECK-FIXES: return F? std::move(Mov): Movable{};
+}
+
+/*
+Currently a heuristic detection of guards is not implemented, so this test is disabled
+But before this is done, the check should not be used for automatic fixing
+
+using NoMove = std::shared_ptr>;
+
+void shareMutex(NoMove Nmov);
+
+void testNoMove(std::mutex& M, int& I) {
+NoMove Nmov = std::make_shared>(M);
+shareMutex(Nmov);
+I = 42;
+}
+
+*/
Index: clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst
@@ -0,0 +1,45 @@
+.. title:: clang-tidy - performance-unnecessary-copy-on-last-use
+
+performance-unnecessary-copy-on-last-use
+
+
+Finds variables of non-trivially-copyable types, that are used in a copy
+construction on their last usage and suggest to wrap the usage in a
+``std::move``. The usage just before an assignment is interpreted as last usage.
+
+Many programmers tend to forget ``std::move`` for variables that can be moved.
+Instead, the compiler creates implicit copies, which can significantly decrease
+performance.
+
+Example:
+
+.. code-block:: c++
+
+  void acceptor(std::vector v);
+  void Function() {
+std::vector v;
+v.emplace_back(20);
+// The warning will suggest passing this as a rvalue-reference
+acceptor(v);
+  }
+
+Options
+---
+
+.. o

[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-02 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:1
+//===--- UnnecessaryCopyOnLastUseCheck.cpp - 
clang-tidy===//
+//

Please put space after `clang-tidy`.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:124
+  ``std::move``.
+  The usage just before an assignment is interpreted as last usage.
+

One sentence is enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D137251: [clang][cuda/hip] Allow `__noinline__` lambdas

2022-11-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Can you also add a release note for the fix?




Comment at: clang/lib/Parse/ParseExprCXX.cpp:1300
+ParseGNUAttributes(Attr, nullptr, &D);
+  } else if (Tok.is(tok::kw___noinline__)) {
+IdentifierInfo *AttrName = Tok.getIdentifierInfo();

Any other keyword attributes that are missing?

`alignas`/`_Alignas`
`__forceinline`
`__cdecl`/`__stdcall`/etc



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137251

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


[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

2022-11-02 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 472702.
ayzhao marked 3 inline comments as done.
ayzhao added a comment.

addressed code review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Initialization.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  clang/test/CodeGen/paren-list-agg-init.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/PCH/cxx_paren_init.cpp
  clang/test/PCH/cxx_paren_init.h
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1156,7 +1156,7 @@
 
   Parenthesized initialization of aggregates
   https://wg21.link/p0960r3";>P0960R3
-  No
+  Clang 16
 

 https://wg21.link/p1975r0";>P1975R0
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -643,6 +643,10 @@
 K = CXCursor_RequiresExpr;
 break;
 
+  case Stmt::CXXParenListInitExprClass:
+K = CXCursor_CXXParenListInitExpr;
+break;
+
   case Stmt::MSDependentExistsStmtClass:
 K = CXCursor_UnexposedStmt;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2139,6 +2139,7 @@
   void VisitLambdaExpr(const LambdaExpr *E);
   void VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E);
   void VisitRequiresExpr(const RequiresExpr *E);
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *E);
   void VisitOMPExecutableDirective(const OMPExecutableDirective *D);
   void VisitOMPLoopBasedDirective(const OMPLoopBasedDirective *D);
   void VisitOMPLoopDirective(const OMPLoopDirective *D);
@@ -2999,6 +3000,9 @@
   for (ParmVarDecl *VD : E->getLocalParameters())
 AddDecl(VD);
 }
+void EnqueueVisitor::VisitCXXParenListInitExpr(const CXXParenListInitExpr *E) {
+  EnqueueChildren(E);
+}
 void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) {
   // Treat the expression like its syntactic form.
   Visit(E->getSyntacticForm());
@@ -5574,6 +5578,8 @@
 return cxstring::createRef("ConceptSpecializationExpr");
   case CXCursor_RequiresExpr:
 return cxstring::createRef("RequiresExpr");
+  case CXCursor_CXXParenListInitExpr:
+return cxstring::createRef("CXXParenListInitExpr");
   case CXCursor_UnexposedStmt:
 return cxstring::createRef("UnexposedStmt");
   case CXCursor_DeclStmt:
Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -0,0 +1,172 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
+// RUN: %clang_cc1 -verify=expected,beforecxx20 -Wc++20-extensions -std=c++20 %s -fsyntax-only
+
+struct A { // expected-note 4{{candidate constructor}}
+  char i;
+  double j;
+};
+
+struct B {
+  A a;
+  int b[20];
+  int &&c; // expected-note {{reference member declared here}}
+};
+
+struct C { // expected-note 2{{candidate constructor}}
+  A a;
+  int b[20];
+};
+
+struct D : public C, public A {
+  int a;
+};
+
+struct E { // expected-note 3{{candidate constructor}}
+  struct F {
+F(int, int);
+  };
+  int a;
+  F f;
+};
+
+int getint(); // expected-note {{declared here}}
+
+struct F {
+  int a;
+  int b = getint(); // expected-note {{non-constexpr function 'get

[PATCH] D137251: [clang][cuda/hip] Allow `__noinline__` lambdas

2022-11-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D137251#3902835 , @tra wrote:

> LGTM in principle. Please wait for @rsmith's OK.

I'm happy to defer to @aaron.ballman on this :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137251

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


[PATCH] D137266: [RISCV] Move RVVBitsPerBlock to TargetParser.h so we can use it in clang. NFC

2022-11-02 Thread Philip Reames via Phabricator via cfe-commits
reames accepted this revision.
reames added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137266

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


[PATCH] D137275: [Driver][test] Fix test by creating empty archive instead of empty file

2022-11-02 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j created this revision.
lamb-j added a reviewer: yaxunl.
Herald added a project: All.
lamb-j requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137275

Files:
  clang/test/Driver/hip-link-bc-to-bc.hip


Index: clang/test/Driver/hip-link-bc-to-bc.hip
===
--- clang/test/Driver/hip-link-bc-to-bc.hip
+++ clang/test/Driver/hip-link-bc-to-bc.hip
@@ -1,6 +1,4 @@
 // REQUIRES: x86-registered-target, amdgpu-registered-target
-// See issue #58711
-// XFAIL: *
 
 // Check that clang unbundles the two bitcodes and links via llvm-link
 // RUN: rm -rf %t && mkdir %t
@@ -21,7 +19,7 @@
 // BITCODE: "{{.*}}llvm-link" "-o" "bundle1-hip-amdgcn-amd-amdhsa-gfx906.bc" 
"[[B1DEV2]]" "[[B2DEV2]]"
 
 // Check that clang unbundles the bitcode and archive and links via llvm-link
-// RUN: touch %t/libhipbundle.a
+// RUN: ar rc %t/libhipbundle.a
 // RUN: touch %t/bundle.bc
 
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu --offload-arch=gfx906 
--hip-link \


Index: clang/test/Driver/hip-link-bc-to-bc.hip
===
--- clang/test/Driver/hip-link-bc-to-bc.hip
+++ clang/test/Driver/hip-link-bc-to-bc.hip
@@ -1,6 +1,4 @@
 // REQUIRES: x86-registered-target, amdgpu-registered-target
-// See issue #58711
-// XFAIL: *
 
 // Check that clang unbundles the two bitcodes and links via llvm-link
 // RUN: rm -rf %t && mkdir %t
@@ -21,7 +19,7 @@
 // BITCODE: "{{.*}}llvm-link" "-o" "bundle1-hip-amdgcn-amd-amdhsa-gfx906.bc" "[[B1DEV2]]" "[[B2DEV2]]"
 
 // Check that clang unbundles the bitcode and archive and links via llvm-link
-// RUN: touch %t/libhipbundle.a
+// RUN: ar rc %t/libhipbundle.a
 // RUN: touch %t/bundle.bc
 
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu --offload-arch=gfx906 --hip-link \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136790: [Clang][Sema] Add -Wincompatible-function-pointer-types-strict

2022-11-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8217
+  err_typecheck_convert_incompatible_function_pointer.Text>,
+  InGroup>, 
DefaultIgnore;
 def ext_typecheck_convert_discards_qualifiers : ExtWarn<

samitolvanen wrote:
> nathanchance wrote:
> > aaron.ballman wrote:
> > > samitolvanen wrote:
> > > > aaron.ballman wrote:
> > > > > We don't typically add new off-by-default warnings because we have 
> > > > > evidence that users don't enable them enough to be worth adding them. 
> > > > > Is there a way we can enable this warning by default for CFI 
> > > > > compilation units (or when the cfi sanitizer is enabled) so that it's 
> > > > > only off by default for non-CFI users? I don't think we have any 
> > > > > examples of doing this in the code base, so I believe this would be 
> > > > > breaking new ground (and thus is worth thinking about more, perhaps 
> > > > > it's a bad idea for some reason).
> > > > > Is there a way we can enable this warning by default for CFI 
> > > > > compilation units (or when the cfi sanitizer is enabled) so that it's 
> > > > > only off by default for non-CFI users?
> > > > 
> > > > I can look into it, but I'm not sure if there's a convenient way to do 
> > > > that. An alternative to this could be to enable the warning by default, 
> > > > but only actually perform the check if CFI is enabled. This way non-CFI 
> > > > users would never see the warning because this really isn't a concern 
> > > > for them, but CFI users would still get the warning without explicitly 
> > > > enabling it. Or do you think this behavior would be confusing?
> > > Heh, sorry for not being clear, that's actually somewhat along the lines 
> > > of how I envisioned you'd implement it (we don't have a way in tablegen 
> > > to tie `DefaultIgnore` to some language options or a target).
> > > 
> > > I was thinking the diagnostic would be left as `DefaultIgnore` in the .td 
> > > file, but we'd take note in the driver that CFI was enabled and pass 
> > > `-Wincompatible-function-pointer-types-strict` to the `-cc1` invocation. 
> > > If the user wrote `-Wno-incompatible-function-pointer-types-strict` at 
> > > the driver level, that would come *after* the automatically generated 
> > > flag for cc1 and would still disable the diagnostic in the cc1 invocation 
> > > (because the last flag wins). WDYT?
> > I do not think that is unreasonable behavior in the generic case but 
> > specifically for the Linux kernel, kCFI is disabled by default 
> > (`CONFIG_CFI_CLANG` has to be specifically enabled) but we want to see this 
> > warning regardless of the value of that configuration so that driver 
> > authors who test with clang and automated testers are more likely to find 
> > them. As a result, if the warning is not going to be default on, we would 
> > still need to specifically enable it in our CFLAGS. I suppose your 
> > suggestion would help out folks using CFI in production though so maybe it 
> > is still worth considering doing?
> > I was thinking the diagnostic would be left as `DefaultIgnore` in the .td 
> > file, but we'd take note in the driver that CFI was enabled and pass 
> > `-Wincompatible-function-pointer-types-strict` to the `-cc1` invocation.
> 
> Thanks for clarifying, that sounds reasonable. Of course, enabling it by 
> default with CFI would still mean that we'll have to either explicitly 
> disable this in the kernel (or fix all the existing warnings) before 
> submitting the Clang change.
> As a result, if the warning is not going to be default on, we would still 
> need to specifically enable it in our CFLAGS. I suppose your suggestion would 
> help out folks using CFI in production though so maybe it is still worth 
> considering doing?

It sounds like either approach will require you to specifically enable it in 
your CFLAGS, right? Either it's off-by-default for everyone, or it's only 
on-by-default for CFI enabled builds (which the Linux kernel disables by 
default).



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8217
+  err_typecheck_convert_incompatible_function_pointer.Text>,
+  InGroup>, 
DefaultIgnore;
 def ext_typecheck_convert_discards_qualifiers : ExtWarn<

aaron.ballman wrote:
> samitolvanen wrote:
> > nathanchance wrote:
> > > aaron.ballman wrote:
> > > > samitolvanen wrote:
> > > > > aaron.ballman wrote:
> > > > > > We don't typically add new off-by-default warnings because we have 
> > > > > > evidence that users don't enable them enough to be worth adding 
> > > > > > them. Is there a way we can enable this warning by default for CFI 
> > > > > > compilation units (or when the cfi sanitizer is enabled) so that 
> > > > > > it's only off by default for non-CFI users? I don't think we have 
> > > > > > any examples of doing this in the code base, so I believe this 
> > > > > > would be breaking new ground (and thus is worth thinking 

[PATCH] D137209: [OPENMP]Initial support for error directive.

2022-11-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 472707.
jyu2 added a comment.

Fix clang format problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137209

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/OpenMP/error_ast_print.cpp
  clang/test/OpenMP/error_message.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -526,6 +526,7 @@
 }
 def OMP_TaskYield : Directive<"taskyield"> {}
 def OMP_Barrier : Directive<"barrier"> {}
+def OMP_Error : Directive<"error"> {}
 def OMP_TaskWait : Directive<"taskwait"> {
   let allowedClauses = [
 VersionedClause
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -712,6 +712,9 @@
   case Stmt::OMPTaskwaitDirectiveClass:
 K = CXCursor_OMPTaskwaitDirective;
 break;
+  case Stmt::OMPErrorDirectiveClass:
+K = CXCursor_OMPErrorDirective;
+break;
   case Stmt::OMPTaskgroupDirectiveClass:
 K = CXCursor_OMPTaskgroupDirective;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2164,6 +2164,7 @@
   void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D);
   void VisitOMPBarrierDirective(const OMPBarrierDirective *D);
   void VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D);
+  void VisitOMPErrorDirective(const OMPErrorDirective *D);
   void VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *D);
   void
   VisitOMPCancellationPointDirective(const OMPCancellationPointDirective *D);
@@ -3114,6 +3115,10 @@
   VisitOMPExecutableDirective(D);
 }
 
+void EnqueueVisitor::VisitOMPErrorDirective(const OMPErrorDirective *D) {
+  VisitOMPExecutableDirective(D);
+}
+
 void EnqueueVisitor::VisitOMPTaskgroupDirective(
 const OMPTaskgroupDirective *D) {
   VisitOMPExecutableDirective(D);
@@ -5819,6 +5824,8 @@
 return cxstring::createRef("OMPBarrierDirective");
   case CXCursor_OMPTaskwaitDirective:
 return cxstring::createRef("OMPTaskwaitDirective");
+  case CXCursor_OMPErrorDirective:
+return cxstring::createRef("OMPErrorDirective");
   case CXCursor_OMPTaskgroupDirective:
 return cxstring::createRef("OMPTaskgroupDirective");
   case CXCursor_OMPFlushDirective:
Index: clang/test/OpenMP/error_message.cpp
===
--- /dev/null
+++ clang/test/OpenMP/error_message.cpp
@@ -0,0 +1,114 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+
+template 
+T tmain(T argc) {
+  if (argc)
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+if (argc) {
+#pragma omp error
+}
+  while (argc)
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+while (argc) {
+#pragma omp error
+}
+  do
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+while (argc)
+  ;
+  do {
+#pragma omp error
+  } while (argc);
+  switch (argc)
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+switch (argc)
+case 1:
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+  switch (argc)
+  case 1: {
+#pragma omp error
+  }
+  switch (argc) {
+#pragma omp error
+  case 1:
+#pragma omp error
+break;
+  default: {
+#pragma omp error
+  } break;
+  }
+  for (;;)
+#pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
+for (;;) {
+#pragma omp error
+}
+label:
+#pragma omp error
+label1 : {
+#pragma omp error
+}
+if (1)
+  label2:
+#pragma omp error // expected-error {{'#pragma omp err

[PATCH] D137082: [clang][Interp] Fix dereferencing arrays with no offset applied

2022-11-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/Interp.h:966-967
 return false;
-  S.Stk.push(Ptr.deref());
+  // When getting the first value of an array, we need to offset to the
+  // first element.
+  if (Ptr.inArray() && Ptr.isRoot())

So why don't we need to do this dance for `Store`/`StorePop`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137082

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


[PATCH] D137104: [clangd] Add scoped enum constants to all-scopes-completion

2022-11-02 Thread Tom Praschan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG990c18937967: [clangd] Add scoped enum constants to 
all-scopes-completion (authored by tom-anders).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137104

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1329,7 +1329,7 @@
   AllOf(qName("Color"), forCodeCompletion(true)),
   AllOf(qName("Green"), forCodeCompletion(true)),
   AllOf(qName("Color2"), forCodeCompletion(true)),
-  AllOf(qName("Color2::Yellow"), forCodeCompletion(false)),
+  AllOf(qName("Color2::Yellow"), forCodeCompletion(true)),
   AllOf(qName("ns"), forCodeCompletion(true)),
   AllOf(qName("ns::Black"), forCodeCompletion(true)),
   AllOf(qName("Color3"), forCodeCompletion(true)),
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3382,11 +3382,13 @@
   Opts.Index = Index.get();
   Opts.AllScopes = true;
   auto R = completions(Source, {}, Opts);
-  EXPECT_THAT(R.Completions,
-  ElementsAre(AllOf(scope("ns::"), named("Clangd1"),
-kind(CompletionItemKind::EnumMember)),
-  AllOf(scope("ns::C::"), named("Clangd2"),
-kind(CompletionItemKind::EnumMember;
+  EXPECT_THAT(R.Completions, UnorderedElementsAre(
+ AllOf(scope("ns::"), named("Clangd1"),
+   kind(CompletionItemKind::EnumMember)),
+ AllOf(scope("ns::C::"), named("Clangd2"),
+   kind(CompletionItemKind::EnumMember)),
+ AllOf(scope("ns::Scoped::"), named("Clangd3"),
+   kind(CompletionItemKind::EnumMember;
 }
 
 TEST(CompletionTest, ScopeIsUnresolved) {
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -291,7 +291,7 @@
 // For index-based completion, we only consider:
 //   * symbols in namespaces or translation unit scopes (e.g. no class
 // members, no locals)
-//   * enum constants in unscoped enum decl (e.g. "red" in "enum {red};")
+//   * enum constants (both scoped and unscoped)
 //   * primary templates (no specializations)
 // For the other cases, we let Clang do the completion because it does not
 // need any non-local information and it will be much better at following
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -2145,7 +2145,7 @@
   // when
   // --all-scopes-completion is set, we'll want to complete those as well.
   if (const auto *EnumDecl = dyn_cast(ND.getDeclContext()))
-return (InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl)) && 
!EnumDecl->isScoped();
+return (InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl));
 
   return false;
 }


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1329,7 +1329,7 @@
   AllOf(qName("Color"), forCodeCompletion(true)),
   AllOf(qName("Green"), forCodeCompletion(true)),
   AllOf(qName("Color2"), forCodeCompletion(true)),
-  AllOf(qName("Color2::Yellow"), forCodeCompletion(false)),
+  AllOf(qName("Color2::Yellow"), forCodeCompletion(true)),
   AllOf(qName("ns"), forCodeCompletion(true)),
   AllOf(qName("ns::Black"), forCodeCompletion(true)),
   AllOf(qName("Color3"), forCodeCompletion(true)),
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeComplet

[clang-tools-extra] 990c189 - [clangd] Add scoped enum constants to all-scopes-completion

2022-11-02 Thread Tom Praschan via cfe-commits

Author: Tom Praschan
Date: 2022-11-02T20:38:01+01:00
New Revision: 990c189379679f92cd9af4cd384e476a94c0e819

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

LOG: [clangd] Add scoped enum constants to all-scopes-completion

This was originally part of https://reviews.llvm.org/D136925, but we decided to 
move it to a separate patch.
In case it turns out to be controversial, it can be reverted more easily.

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

Added: 


Modified: 
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/CodeComplete.h
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index a3e518b4ba054..e52cb2643babd 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -2145,7 +2145,7 @@ bool isIndexedForCodeCompletion(const NamedDecl &ND, 
ASTContext &ASTCtx) {
   // when
   // --all-scopes-completion is set, we'll want to complete those as well.
   if (const auto *EnumDecl = dyn_cast(ND.getDeclContext()))
-return (InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl)) && 
!EnumDecl->isScoped();
+return (InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl));
 
   return false;
 }

diff  --git a/clang-tools-extra/clangd/CodeComplete.h 
b/clang-tools-extra/clangd/CodeComplete.h
index 269be8944df17..19ef4c17d3b0f 100644
--- a/clang-tools-extra/clangd/CodeComplete.h
+++ b/clang-tools-extra/clangd/CodeComplete.h
@@ -291,7 +291,7 @@ SignatureHelp signatureHelp(PathRef FileName, Position Pos,
 // For index-based completion, we only consider:
 //   * symbols in namespaces or translation unit scopes (e.g. no class
 // members, no locals)
-//   * enum constants in unscoped enum decl (e.g. "red" in "enum {red};")
+//   * enum constants (both scoped and unscoped)
 //   * primary templates (no specializations)
 // For the other cases, we let Clang do the completion because it does not
 // need any non-local information and it will be much better at following

diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 77451bf445e0f..99d09ad43466a 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3382,11 +3382,13 @@ TEST(CompletionTest, Enums) {
   Opts.Index = Index.get();
   Opts.AllScopes = true;
   auto R = completions(Source, {}, Opts);
-  EXPECT_THAT(R.Completions,
-  ElementsAre(AllOf(scope("ns::"), named("Clangd1"),
-kind(CompletionItemKind::EnumMember)),
-  AllOf(scope("ns::C::"), named("Clangd2"),
-kind(CompletionItemKind::EnumMember;
+  EXPECT_THAT(R.Completions, UnorderedElementsAre(
+ AllOf(scope("ns::"), named("Clangd1"),
+   kind(CompletionItemKind::EnumMember)),
+ AllOf(scope("ns::C::"), named("Clangd2"),
+   kind(CompletionItemKind::EnumMember)),
+ AllOf(scope("ns::Scoped::"), named("Clangd3"),
+   kind(CompletionItemKind::EnumMember;
 }
 
 TEST(CompletionTest, ScopeIsUnresolved) {

diff  --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index bb651b851afeb..62564b989a186 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1329,7 +1329,7 @@ TEST_F(SymbolCollectorTest, IncludeEnums) {
   AllOf(qName("Color"), forCodeCompletion(true)),
   AllOf(qName("Green"), forCodeCompletion(true)),
   AllOf(qName("Color2"), forCodeCompletion(true)),
-  AllOf(qName("Color2::Yellow"), forCodeCompletion(false)),
+  AllOf(qName("Color2::Yellow"), forCodeCompletion(true)),
   AllOf(qName("ns"), forCodeCompletion(true)),
   AllOf(qName("ns::Black"), forCodeCompletion(true)),
   AllOf(qName("Color3"), forCodeCompletion(true)),



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


[PATCH] D136936: [clang][Interp] Handle undefined functions better

2022-11-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeEmitter.cpp:30
   if (!FuncDecl->isDefined(FuncDecl) ||
-  (!FuncDecl->hasBody() && FuncDecl->willHaveBody()))
-return nullptr;
+  (FuncDecl->hasBody() && FuncDecl->willHaveBody()))
+HasBody = false;

tbaeder wrote:
> aaron.ballman wrote:
> > `hasBody()` returns `true` if any body in the redeclaration chain already 
> > has a body, so I'm surprised to see this change -- I don't know if we reset 
> > `willHaveBody()` when we give the function a body, but the logic here seems 
> > wrong to me.
> I was confused by your question, but it's just about `hasBody()` vs 
> `!hasBody()`, right? The old code used a negation and of course that way it 
> makes sense, at least the way I read it. Yes I forgot the negation. :)
Heh, you managed to decipher my word salad correctly -- I was tying to figure 
out if you dropped the `!` for a reason. :-D


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

https://reviews.llvm.org/D136936

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


[PATCH] D137280: [RISCV] Prevent autovectorization using vscale with Zvl32b.

2022-11-02 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: reames, frasercrmck, rogfer01, kito-cheng.
Herald added subscribers: sunshaoce, VincentWu, StephenFan, vkmr, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, 
arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added projects: clang, LLVM.

RVVBitsPerBlock is 64. If VLen==32, VLen/RVVBitsPerBlock is 0.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137280

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/CodeGen/riscv-vector-bits-vscale-range.c
  llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
  llvm/test/Transforms/LoopVectorize/RISCV/zvl32b.ll

Index: llvm/test/Transforms/LoopVectorize/RISCV/zvl32b.ll
===
--- /dev/null
+++ llvm/test/Transforms/LoopVectorize/RISCV/zvl32b.ll
@@ -0,0 +1,69 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -loop-vectorize -scalable-vectorization=on -mtriple riscv64-linux-gnu -mattr=+zve32f,+f -S 2>%t | FileCheck %s
+
+target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
+target triple = "riscv64"
+
+; We can't use scalable vectorization for Zvl32b due to RVVBitsPerBlock being
+; 64. Since our vscale value is vlen/RVVBitsPerBlock this makes vscale 0.
+; Make sure we fall back to fixed vectorization instead.
+define void @vector_add_i16(ptr noalias nocapture %a, i16 %v, i64 %n) {
+; CHECK-LABEL: @vector_add_i16(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
+; CHECK:   vector.ph:
+; CHECK-NEXT:[[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i16> poison, i16 [[V:%.*]], i32 0
+; CHECK-NEXT:[[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i16> [[BROADCAST_SPLATINSERT]], <2 x i16> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:[[BROADCAST_SPLATINSERT3:%.*]] = insertelement <2 x i16> poison, i16 [[V]], i32 0
+; CHECK-NEXT:[[BROADCAST_SPLAT4:%.*]] = shufflevector <2 x i16> [[BROADCAST_SPLATINSERT3]], <2 x i16> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:br label [[VECTOR_BODY:%.*]]
+; CHECK:   vector.body:
+; CHECK-NEXT:[[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
+; CHECK-NEXT:[[VEC_IND:%.*]] = phi <2 x i64> [ , [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
+; CHECK-NEXT:[[STEP_ADD:%.*]] = add <2 x i64> [[VEC_IND]], 
+; CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], <2 x i64> [[VEC_IND]]
+; CHECK-NEXT:[[TMP1:%.*]] = getelementptr inbounds i32, ptr [[A]], <2 x i64> [[STEP_ADD]]
+; CHECK-NEXT:[[WIDE_MASKED_GATHER:%.*]] = call <2 x i16> @llvm.masked.gather.v2i16.v2p0(<2 x ptr> [[TMP0]], i32 2, <2 x i1> , <2 x i16> poison)
+; CHECK-NEXT:[[WIDE_MASKED_GATHER2:%.*]] = call <2 x i16> @llvm.masked.gather.v2i16.v2p0(<2 x ptr> [[TMP1]], i32 2, <2 x i1> , <2 x i16> poison)
+; CHECK-NEXT:[[TMP2:%.*]] = add <2 x i16> [[WIDE_MASKED_GATHER]], [[BROADCAST_SPLAT]]
+; CHECK-NEXT:[[TMP3:%.*]] = add <2 x i16> [[WIDE_MASKED_GATHER2]], [[BROADCAST_SPLAT4]]
+; CHECK-NEXT:call void @llvm.masked.scatter.v2i16.v2p0(<2 x i16> [[TMP2]], <2 x ptr> [[TMP0]], i32 2, <2 x i1> )
+; CHECK-NEXT:call void @llvm.masked.scatter.v2i16.v2p0(<2 x i16> [[TMP3]], <2 x ptr> [[TMP1]], i32 2, <2 x i1> )
+; CHECK-NEXT:[[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
+; CHECK-NEXT:[[VEC_IND_NEXT]] = add <2 x i64> [[STEP_ADD]], 
+; CHECK-NEXT:[[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
+; CHECK-NEXT:br i1 [[TMP4]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
+; CHECK:   middle.block:
+; CHECK-NEXT:[[CMP_N:%.*]] = icmp eq i64 1024, 1024
+; CHECK-NEXT:br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
+; CHECK:   scalar.ph:
+; CHECK-NEXT:[[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
+; CHECK-NEXT:br label [[FOR_BODY:%.*]]
+; CHECK:   for.body:
+; CHECK-NEXT:[[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
+; CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[IV]]
+; CHECK-NEXT:[[ELEM:%.*]] = load i16, ptr [[ARRAYIDX]], align 2
+; CHECK-NEXT:[[ADD:%.*]] = add i16 [[ELEM]], [[V]]
+; CHECK-NEXT:store i16 [[ADD]], ptr [[ARRAYIDX]], align 2
+; CHECK-NEXT:[[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
+; CHECK-NEXT:[[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
+; CHECK-NEXT:br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP2:![0-9]+]]
+; CHECK:   for.end:
+; CHECK-NEXT:ret void

  1   2   >