[mlir] [compiler-rt] [libc] [clang] [flang] [llvm] [openmp] [lldb] [hwasan] Respect strip_path_prefix printing locals (PR #76132)

2023-12-22 Thread antoine moynault via cfe-commits

antmox wrote:

Hello, this patch broke several aarch64 bots:
https://lab.llvm.org/buildbot/#/builders/198/builds/7522
https://lab.llvm.org/buildbot/#/builders/176/builds/7521
https://lab.llvm.org/buildbot/#/builders/197/builds/11545
https://lab.llvm.org/buildbot/#/builders/184/builds/8762
https://lab.llvm.org/buildbot/#/builders/185/builds/5675
Could you please look at this ?



https://github.com/llvm/llvm-project/pull/76132
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [lldb] [openmp] [mlir] [clang] [libc] [libcxx] [compiler-rt] [llvm] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-22 Thread antoine moynault via cfe-commits

antmox wrote:

Hi, looks like patch broke 2 aarch64 bots:
https://lab.llvm.org/buildbot/#/builders/185/builds/5675
https://lab.llvm.org/buildbot/#/builders/179/builds/8880
Could you please look at this?

https://github.com/llvm/llvm-project/pull/76133
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Avoid need for SLocEntryLoaded BitVector (PR #67960)

2023-12-22 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

@ktf what is the fate of this PR?

https://github.com/llvm/llvm-project/pull/67960
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)

2023-12-22 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev created 
https://github.com/llvm/llvm-project/pull/76218

This patch brings back the basic support for C by inserting the required for 
value printing runtime only when we are in C++ mode. Additionally, it defines a 
new overload of operator placement new because we can't really forward declare 
it in a library-agnostic way.

Fixes the issue described in llvm/llvm-project#69072.

>From 114b93d587509acde0f65b50e7abbf571c5d2613 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Fri, 22 Dec 2023 08:38:23 +
Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator
 new for C++.

This patch brings back the basic support for C by inserting the required for
value printing runtime only when we are in C++ mode. Additionally, it defines
a new overload of operator placement new because we can't really forward declare
it in a library-agnostic way.

Fixes the issue described in llvm/llvm-project#69072.
---
 clang/lib/Interpreter/Interpreter.cpp   | 18 --
 clang/test/Interpreter/incremental-mode.cpp |  3 ++-
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index c9fcef5b5b5af1..daceabafe4c938 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,7 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
+#ifdef __cplusplus
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
@@ -256,15 +256,18 @@ const char *const Runtimes = R"(
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
 void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
+struct __clang_Interpreter_NewTag{};
+void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) 
noexcept;
 template 
 void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
   for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
+new ((void*)(((T*)Placement) + Idx), __clang_Interpreter_NewTag()) 
T(Src[Idx]);
 }
 template 
 void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size) {
   __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
 }
+#endif // __cplusplus
 )";
 
 llvm::Expected>
@@ -814,3 +817,14 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void 
*OutVal, void *OpaqueType,
   VRef = Value(static_cast(This), OpaqueType);
   VRef.setLongDouble(Val);
 }
+
+// A trampoline to work around the fact that operator placement new cannot
+// really be forward declared due to libc++ and libstdc++ declaration mismatch.
+// FIXME: __clang_Interpreter_NewTag is ODR violation because we get the same
+// definition in the interpreter runtime. We should move it in a runtime header
+// which gets included by the interpreter and here.
+struct __clang_Interpreter_NewTag{};
+void* operator new(__SIZE_TYPE__ __sz, void* __p, __clang_Interpreter_NewTag) 
noexcept {
+  // Just forward to the standard operator placement new.
+  return operator new(__sz, __p);
+}
diff --git a/clang/test/Interpreter/incremental-mode.cpp 
b/clang/test/Interpreter/incremental-mode.cpp
index e6350d237ef578..d63cee0dd6d15f 100644
--- a/clang/test/Interpreter/incremental-mode.cpp
+++ b/clang/test/Interpreter/incremental-mode.cpp
@@ -1,3 +1,4 @@
 // RUN: clang-repl -Xcc -E
-// RUN: clang-repl -Xcc -emit-llvm 
+// RUN: clang-repl -Xcc -emit-llvm
+// RUN: clang-repl -Xcc -xc
 // expected-no-diagnostics

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


[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)

2023-12-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vassil Vassilev (vgvassilev)


Changes

This patch brings back the basic support for C by inserting the required for 
value printing runtime only when we are in C++ mode. Additionally, it defines a 
new overload of operator placement new because we can't really forward declare 
it in a library-agnostic way.

Fixes the issue described in llvm/llvm-project#69072.

---
Full diff: https://github.com/llvm/llvm-project/pull/76218.diff


2 Files Affected:

- (modified) clang/lib/Interpreter/Interpreter.cpp (+16-2) 
- (modified) clang/test/Interpreter/incremental-mode.cpp (+2-1) 


``diff
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index c9fcef5b5b5af1..daceabafe4c938 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,7 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
+#ifdef __cplusplus
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
@@ -256,15 +256,18 @@ const char *const Runtimes = R"(
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
 void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
+struct __clang_Interpreter_NewTag{};
+void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) 
noexcept;
 template 
 void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
   for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
+new ((void*)(((T*)Placement) + Idx), __clang_Interpreter_NewTag()) 
T(Src[Idx]);
 }
 template 
 void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size) {
   __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
 }
+#endif // __cplusplus
 )";
 
 llvm::Expected>
@@ -814,3 +817,14 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void 
*OutVal, void *OpaqueType,
   VRef = Value(static_cast(This), OpaqueType);
   VRef.setLongDouble(Val);
 }
+
+// A trampoline to work around the fact that operator placement new cannot
+// really be forward declared due to libc++ and libstdc++ declaration mismatch.
+// FIXME: __clang_Interpreter_NewTag is ODR violation because we get the same
+// definition in the interpreter runtime. We should move it in a runtime header
+// which gets included by the interpreter and here.
+struct __clang_Interpreter_NewTag{};
+void* operator new(__SIZE_TYPE__ __sz, void* __p, __clang_Interpreter_NewTag) 
noexcept {
+  // Just forward to the standard operator placement new.
+  return operator new(__sz, __p);
+}
diff --git a/clang/test/Interpreter/incremental-mode.cpp 
b/clang/test/Interpreter/incremental-mode.cpp
index e6350d237ef578..d63cee0dd6d15f 100644
--- a/clang/test/Interpreter/incremental-mode.cpp
+++ b/clang/test/Interpreter/incremental-mode.cpp
@@ -1,3 +1,4 @@
 // RUN: clang-repl -Xcc -E
-// RUN: clang-repl -Xcc -emit-llvm 
+// RUN: clang-repl -Xcc -emit-llvm
+// RUN: clang-repl -Xcc -xc
 // expected-no-diagnostics

``




https://github.com/llvm/llvm-project/pull/76218
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)

2023-12-22 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev updated 
https://github.com/llvm/llvm-project/pull/76218

>From 0578f4c1582abdc6d4695d5c3c460213d1f02f00 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Fri, 22 Dec 2023 08:38:23 +
Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator
 new for C++.

This patch brings back the basic support for C by inserting the required for
value printing runtime only when we are in C++ mode. Additionally, it defines
a new overload of operator placement new because we can't really forward declare
it in a library-agnostic way.

Fixes the issue described in llvm/llvm-project#69072.
---
 clang/lib/Interpreter/Interpreter.cpp   | 19 +--
 clang/test/Interpreter/incremental-mode.cpp |  3 ++-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index c9fcef5b5b5af1..b94493699f7fb9 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,7 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
+#ifdef __cplusplus
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
@@ -256,15 +256,18 @@ const char *const Runtimes = R"(
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
 void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
+struct __clang_Interpreter_NewTag{};
+void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) 
noexcept;
 template 
 void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
   for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
+new ((void*)(((T*)Placement) + Idx), __clang_Interpreter_NewTag()) 
T(Src[Idx]);
 }
 template 
 void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size) {
   __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
 }
+#endif // __cplusplus
 )";
 
 llvm::Expected>
@@ -814,3 +817,15 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void 
*OutVal, void *OpaqueType,
   VRef = Value(static_cast(This), OpaqueType);
   VRef.setLongDouble(Val);
 }
+
+// A trampoline to work around the fact that operator placement new cannot
+// really be forward declared due to libc++ and libstdc++ declaration mismatch.
+// FIXME: __clang_Interpreter_NewTag is ODR violation because we get the same
+// definition in the interpreter runtime. We should move it in a runtime header
+// which gets included by the interpreter and here.
+struct __clang_Interpreter_NewTag {};
+void *operator new(__SIZE_TYPE__ __sz, void *__p,
+   __clang_Interpreter_NewTag) noexcept {
+  // Just forward to the standard operator placement new.
+  return operator new(__sz, __p);
+}
diff --git a/clang/test/Interpreter/incremental-mode.cpp 
b/clang/test/Interpreter/incremental-mode.cpp
index e6350d237ef578..d63cee0dd6d15f 100644
--- a/clang/test/Interpreter/incremental-mode.cpp
+++ b/clang/test/Interpreter/incremental-mode.cpp
@@ -1,3 +1,4 @@
 // RUN: clang-repl -Xcc -E
-// RUN: clang-repl -Xcc -emit-llvm 
+// RUN: clang-repl -Xcc -emit-llvm
+// RUN: clang-repl -Xcc -xc
 // expected-no-diagnostics

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


[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)

2023-12-22 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

This PR should help compiler-research/CppInterOp#173 move forward.

cc: @makslevental, @alexander-penev, @mcbarton

https://github.com/llvm/llvm-project/pull/76218
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ASTImporter] Import AlignValueAttr correctly. (PR #75308)

2023-12-22 Thread Balázs Kéri via cfe-commits

https://github.com/balazske closed 
https://github.com/llvm/llvm-project/pull/75308
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0d903b6 - [clang][ASTImporter] Import AlignValueAttr correctly. (#75308)

2023-12-22 Thread via cfe-commits

Author: Balázs Kéri
Date: 2023-12-22T10:07:38+01:00
New Revision: 0d903b689ab984d6e7d8e1919a5b37658ae94518

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

LOG: [clang][ASTImporter] Import AlignValueAttr correctly. (#75308)

Expression of attribute `align_value` was not imported. Import of the
attribute is corrected, a test for it is added, other related tests with
FIXME are updated.
Fixes #75054.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 1cc47de675bf33..88b8c6abb6d5fd 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -9103,6 +9103,12 @@ Expected ASTImporter::Import(const Attr 
*FromAttr) {
 break;
   }
 
+  case attr::AlignValue: {
+auto *From = cast(FromAttr);
+AI.importAttr(From, AI.importArg(From->getAlignment()).value());
+break;
+  }
+
   case attr::Format: {
 const auto *From = cast(FromAttr);
 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 4c06152d3eb563..9fa7660cde6593 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -7445,67 +7445,46 @@ void ImportAttributes::checkImported(const Decl 
*From, const Decl *To) {
 ToAST->getASTContext().getTranslationUnitDecl());
 }
 
-// FIXME: Use ImportAttributes for this test.
-TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
-  // Test if import of these packed and aligned attributes does not trigger an
-  // error situation where source location from 'From' context is referenced in
-  // 'To' context through evaluation of the alignof attribute.
-  // This happens if the 'alignof(A)' expression is not imported correctly.
-  Decl *FromTU = getTuDecl(
+TEST_P(ImportAttributes, ImportAligned) {
+  AlignedAttr *FromAttr, *ToAttr;
+  importAttr(
   R"(
   struct __attribute__((packed)) A { int __attribute__((aligned(8))) X; };
-  struct alignas(alignof(A)) S {};
+  struct alignas(alignof(A)) test {};
   )",
-  Lang_CXX11, "input.cc");
-  auto *FromD = FirstDeclMatcher().match(
-  FromTU, cxxRecordDecl(hasName("S"), unless(isImplicit(;
-  ASSERT_TRUE(FromD);
-
-  auto *ToD = Import(FromD, Lang_CXX11);
-  ASSERT_TRUE(ToD);
-
-  auto *FromAttr = FromD->getAttr();
-  auto *ToAttr = ToD->getAttr();
-  EXPECT_EQ(FromAttr->isInherited(), ToAttr->isInherited());
-  EXPECT_EQ(FromAttr->isPackExpansion(), ToAttr->isPackExpansion());
-  EXPECT_EQ(FromAttr->isImplicit(), ToAttr->isImplicit());
-  EXPECT_EQ(FromAttr->getSyntax(), ToAttr->getSyntax());
-  EXPECT_EQ(FromAttr->getSemanticSpelling(), ToAttr->getSemanticSpelling());
-  EXPECT_TRUE(ToAttr->getAlignmentExpr());
+  FromAttr, ToAttr);
+  checkImported(FromAttr->getAlignmentExpr(), ToAttr->getAlignmentExpr());
 
   auto *ToA = FirstDeclMatcher().match(
-  ToD->getTranslationUnitDecl(),
+  ToAST->getASTContext().getTranslationUnitDecl(),
   cxxRecordDecl(hasName("A"), unless(isImplicit(;
   // Ensure that 'struct A' was imported (through reference from attribute of
-  // 'S').
+  // struct 'test').
   EXPECT_TRUE(ToA);
 }
 
-// FIXME: Use ImportAttributes for this test.
-TEST_P(ASTImporterOptionSpecificTestBase, ImportFormatAttr) {
-  Decl *FromTU = getTuDecl(
+TEST_P(ImportAttributes, ImportAlignValue) {
+  AlignValueAttr *FromAttr, *ToAttr;
+  importAttr(
+  R"(
+  void *test __attribute__((align_value(64)));
+  )",
+  FromAttr, ToAttr);
+  checkImported(FromAttr->getAlignment(), ToAttr->getAlignment());
+}
+
+TEST_P(ImportAttributes, ImportFormat) {
+  FormatAttr *FromAttr, *ToAttr;
+  importAttr(
   R"(
-  int foo(const char * fmt, ...)
+  int test(const char * fmt, ...)
   __attribute__ ((__format__ (__scanf__, 1, 2)));
   )",
-  Lang_CXX03, "input.cc");
-  auto *FromD = FirstDeclMatcher().match(
-  FromTU, functionDecl(hasName("foo")));
-  ASSERT_TRUE(FromD);
+  FromAttr, ToAttr);
 
-  auto *ToD = Import(FromD, Lang_CXX03);
-  ASSERT_TRUE(ToD);
-  ToD->dump(); // Should not crash!
-
-  auto *FromAttr = FromD->getAttr();
-  auto *ToAttr = ToD->getAttr();
-  EXPECT_EQ(FromAttr->isInherited(), ToAttr->isInherited());
-  EXPECT_EQ(FromAttr->isPackExpansion(), ToAttr->isPackExpansion());
-  EXPECT_EQ(FromAttr->isImplicit(), ToAttr->isImplicit());
-  EXPECT_EQ(FromAttr->getSyntax(), ToAttr->getSyntax());
-  EXPECT_EQ(FromAttr->getAttributeSpellingListIndex(),
-ToAttr->getAttributeSpellingListIndex());
   EXPECT_EQ(FromAttr->getType()->getName(), ToAttr->getType()->getName())

[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

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

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

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

https://github.com/PiotrZSL requested changes to this pull request.

Minor tuning needed, some changes to documentation, options, default 
configuration.


https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

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


@@ -149,6 +149,7 @@ Clang-Tidy Checks
:doc:`bugprone-unhandled-self-assignment 
`,
:doc:`bugprone-unique-ptr-array-mismatch 
`, "Yes"
:doc:`bugprone-unsafe-functions `,
+   :doc:`bugprone-unused-local-non-trivial-variable 
`, "Yes"

PiotrZSL wrote:

check does not provide fixes, remove "Yes"

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

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


@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy %s bugprone-unused-local-non-trivial-variable %t -- \
+// RUN:   -config="{CheckOptions: 
{bugprone-unused-local-non-trivial-variable.IncludeTypeRegex: 
'::async::Future'}}"
+
+
+namespace async {
+template 
+class Ptr {
+  public:
+  explicit Ptr(T Arg) : Underlying(new T(Arg)) {}
+  T& operator->() {
+return Underlying;
+  }
+  ~Ptr() {
+delete Underlying;
+  }
+  private:
+T* Underlying;
+};
+
+template
+class Future {
+public:
+T get() {
+return Pending;
+}
+~Future();
+private:
+T Pending;
+};
+
+
+} // namespace async
+
+// Warning is still emitted if there are type aliases.
+namespace a {
+template
+using Future = async::Future;
+} // namespace a
+
+void releaseUnits();
+struct Units {
+  ~Units() {
+releaseUnits();
+  }
+};
+a::Future acquireUnits();
+
+template
+T qux(T Generic) {
+async::Future PendingA = acquireUnits();
+auto PendingB = acquireUnits();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: unused local variable 
'PendingB' of type 'a::Future' (aka 'Future') 
[bugprone-unused-local-non-trivial-variable]
+async::Future MustBeUsed;
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: unused local variable 
'MustBeUsed' of type 'async::Future' 
[bugprone-unused-local-non-trivial-variable]
+PendingA.get();
+return Generic;
+}
+
+async::Future Global;
+
+int bar(int Num) {
+a::Future PendingA = acquireUnits();
+a::Future PendingB = acquireUnits(); // not used at all, unused 
variable not fired because of destructor side effect
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: unused local variable 
'PendingB' of type 'a::Future' (aka 'Future') 
[bugprone-unused-local-non-trivial-variable]
+auto Num2 = PendingA.get();
+auto Num3 = qux(Num);
+async::Ptr> Shared = 
async::Ptr>(acquireUnits());
+static auto UnusedStatic = async::Future();
+thread_local async::Future UnusedThreadLocal;
+auto Captured = acquireUnits();
+Num3 += [Captured]() {
+  return 1;
+}();
+a::Future Referenced = acquireUnits();
+a::Future* Pointer = &Referenced;
+a::Future& Reference = Referenced;
+const a::Future& ConstReference = Referenced;
+return Num * Num3;
+}

PiotrZSL wrote:

Add test with unused exception variable.

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

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


@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy %s bugprone-unused-local-non-trivial-variable %t -- \
+// RUN:   -config="{CheckOptions: 
{bugprone-unused-local-non-trivial-variable.IncludeTypeRegex: 
'::async::Future'}}"
+
+
+namespace async {
+template 
+class Ptr {
+  public:
+  explicit Ptr(T Arg) : Underlying(new T(Arg)) {}
+  T& operator->() {
+return Underlying;
+  }
+  ~Ptr() {
+delete Underlying;
+  }
+  private:
+T* Underlying;
+};
+
+template
+class Future {
+public:
+T get() {
+return Pending;
+}
+~Future();
+private:
+T Pending;
+};
+
+
+} // namespace async
+
+// Warning is still emitted if there are type aliases.
+namespace a {
+template
+using Future = async::Future;
+} // namespace a
+
+void releaseUnits();
+struct Units {
+  ~Units() {
+releaseUnits();
+  }
+};
+a::Future acquireUnits();
+
+template
+T qux(T Generic) {
+async::Future PendingA = acquireUnits();
+auto PendingB = acquireUnits();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: unused local variable 
'PendingB' of type 'a::Future' (aka 'Future') 
[bugprone-unused-local-non-trivial-variable]
+async::Future MustBeUsed;
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: unused local variable 
'MustBeUsed' of type 'async::Future' 
[bugprone-unused-local-non-trivial-variable]
+PendingA.get();
+return Generic;
+}
+
+async::Future Global;
+
+int bar(int Num) {
+a::Future PendingA = acquireUnits();
+a::Future PendingB = acquireUnits(); // not used at all, unused 
variable not fired because of destructor side effect
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: unused local variable 
'PendingB' of type 'a::Future' (aka 'Future') 
[bugprone-unused-local-non-trivial-variable]
+auto Num2 = PendingA.get();
+auto Num3 = qux(Num);
+async::Ptr> Shared = 
async::Ptr>(acquireUnits());
+static auto UnusedStatic = async::Future();
+thread_local async::Future UnusedThreadLocal;
+auto Captured = acquireUnits();
+Num3 += [Captured]() {
+  return 1;
+}();
+a::Future Referenced = acquireUnits();
+a::Future* Pointer = &Referenced;
+a::Future& Reference = Referenced;
+const a::Future& ConstReference = Referenced;
+return Num * Num3;
+}

PiotrZSL wrote:

add test with C++17 bind variable:
https://en.cppreference.com/w/cpp/language/structured_binding

May be good to exclude them.

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

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


@@ -0,0 +1,89 @@
+//===--- UnusedLocalNonTrivialVariableCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UnusedLocalNonTrivialVariableCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+static constexpr StringRef DefaultIncludeTypeRegex = 
"std::.*mutex;std::future";
+
+AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
+AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
+AST_MATCHER(Type, isReferenceType) { return Node.isReferenceType(); }
+} // namespace
+
+UnusedLocalNonTrivialVariableCheck::UnusedLocalNonTrivialVariableCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeTypeRegex(utils::options::parseStringList(
+  Options.get("IncludeTypeRegex", DefaultIncludeTypeRegex))),
+  ExcludeTypeRegex(utils::options::parseStringList(
+  Options.get("ExcludeTypeRegex", ""))) {}
+
+void UnusedLocalNonTrivialVariableCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeTypeRegex",
+utils::options::serializeStringList(IncludeTypeRegex));
+  Options.store(Opts, "ExcludeTypeRegex",
+utils::options::serializeStringList(ExcludeTypeRegex));
+}
+
+void UnusedLocalNonTrivialVariableCheck::registerMatchers(MatchFinder *Finder) 
{
+  if (IncludeTypeRegex.empty())
+return;
+
+  Finder->addMatcher(
+  varDecl(
+  isLocalVarDecl(), unless(isReferenced()),
+  unless(isExpansionInSystemHeader()), unless(isImplicit()),
+  unless(isExceptionVariable()), hasLocalStorage(), isDefinition(),
+  unless(hasType(isReferenceType())),
+  hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+  recordDecl(matchesAnyListedName(IncludeTypeRegex)),
+  unless(hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+  recordDecl(matchesAnyListedName(ExcludeTypeRegex

PiotrZSL wrote:

merge those two:
```
 hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
  recordDecl(matchesAnyListedName(IncludeTypeRegex), 
unless(matchesAnyListedName(ExcludeTypeRegex)))
```

Also in this place you could also exclude all recordDecl that aren't Trivial, 
maybe by puting that trivial check into matcher.

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

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


@@ -0,0 +1,89 @@
+//===--- UnusedLocalNonTrivialVariableCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UnusedLocalNonTrivialVariableCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+static constexpr StringRef DefaultIncludeTypeRegex = 
"std::.*mutex;std::future";
+
+AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
+AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
+AST_MATCHER(Type, isReferenceType) { return Node.isReferenceType(); }
+} // namespace
+
+UnusedLocalNonTrivialVariableCheck::UnusedLocalNonTrivialVariableCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeTypeRegex(utils::options::parseStringList(
+  Options.get("IncludeTypeRegex", DefaultIncludeTypeRegex))),

PiotrZSL wrote:

Maybe it should be IncludeTypes, ExcludeTypes, simply because it's not just one 
regexp

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

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


@@ -0,0 +1,29 @@
+.. title:: clang-tidy - bugprone-unused-local-non-trivial-variable
+
+bugprone-unused-local-non-trivial-variable
+==
+
+Warns when a local non trivial variable is unused within a function.
+
+In the following example, `future2` would generate a warning that it is unused.
+
+.. code-block:: c++
+

PiotrZSL wrote:

add other example, more straight forward, like one with std::mutex.
Point in documentation what types of variables are ignored (trivially copyable, 
trivial, references, exception variables).
Provide description how to configure check to work on all types of non-trivial 
(put .* into IncludeTypeRegex)

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

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


@@ -0,0 +1,89 @@
+//===--- UnusedLocalNonTrivialVariableCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UnusedLocalNonTrivialVariableCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+static constexpr StringRef DefaultIncludeTypeRegex = 
"std::.*mutex;std::future";
+
+AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
+AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
+AST_MATCHER(Type, isReferenceType) { return Node.isReferenceType(); }
+} // namespace
+
+UnusedLocalNonTrivialVariableCheck::UnusedLocalNonTrivialVariableCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeTypeRegex(utils::options::parseStringList(
+  Options.get("IncludeTypeRegex", DefaultIncludeTypeRegex))),
+  ExcludeTypeRegex(utils::options::parseStringList(
+  Options.get("ExcludeTypeRegex", ""))) {}
+
+void UnusedLocalNonTrivialVariableCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeTypeRegex",
+utils::options::serializeStringList(IncludeTypeRegex));
+  Options.store(Opts, "ExcludeTypeRegex",
+utils::options::serializeStringList(ExcludeTypeRegex));
+}
+
+void UnusedLocalNonTrivialVariableCheck::registerMatchers(MatchFinder *Finder) 
{
+  if (IncludeTypeRegex.empty())
+return;
+
+  Finder->addMatcher(
+  varDecl(
+  isLocalVarDecl(), unless(isReferenced()),
+  unless(isExpansionInSystemHeader()), unless(isImplicit()),

PiotrZSL wrote:

isImplicit isn't needed because you use getCheckTraversalKind

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

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


@@ -0,0 +1,89 @@
+//===--- UnusedLocalNonTrivialVariableCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UnusedLocalNonTrivialVariableCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+static constexpr StringRef DefaultIncludeTypeRegex = 
"std::.*mutex;std::future";

PiotrZSL wrote:

I think that probably we could put here also things like std::string, and other 
that do not carry other object ownership. Also probably better would be list 
those classes as `::std::.*mutex;::std::future`

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Improve modeling of `fileno` in the StreamChecker (PR #76207)

2023-12-22 Thread Balázs Kéri via cfe-commits

balazske wrote:

I do not see much benefit of adding `fileno` to the checker in the current 
state. If the `StdLibraryFunctionsChecker` is turned on it will anyway do a 
similar modeling of `fileno` (this applied to `ftell` too). The `fileno` and 
`ftell` are semantically different and `fileno` can be more complicated if we 
want to ensure that the returned file numbers are different from each other, 
and special values for `stdin`, `stdout`, `stderr` should be taken into account.
Adding `fileno` in the current way makes a small improvement for the case when 
`StdLibraryFunctionsChecker` is not used. A combined function for `fileno` and 
`ftell` can be used, but in a way that works with any function that returns -1 
on error and >=0 value on success. The type of the return value can be get from 
the declaration of the function or from the `CallEvent` in some way, a type 
parameter to the function is not needed.
Adding the standard streams to the checker has some difficulties and requires 
more work (at least there must be a checker parameter to assume that standard 
streams are not changed by the program, otherwise no modeling can be done 
because these are global variables).

https://github.com/llvm/llvm-project/pull/76207
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2023-12-22 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky created 
https://github.com/llvm/llvm-project/pull/76226

Types comparison in `StructuralEquivalence` ignores its `DeclContext` when they 
are generated by template specialization implicitly and this will produce 
incorrect result. Add comparison of `DeclContext` of 
ClassTemplateSpecializationDecl to improve result.

>From 8d57b196a90fe8454d815617924b6b363aa4cb87 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 22 Dec 2023 17:56:32 +0800
Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve
 StructuralEquivalence on recordType

---
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 ++---
 .../AST/StructuralEquivalenceTest.cpp | 22 +++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7..7c04c09bb80874 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1107,11 +1107,20 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   }
 
   case Type::Record:
-  case Type::Enum:
-if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(),
-  cast(T2)->getDecl()))
+  case Type::Enum: {
+auto *D1 = cast(T1)->getDecl();
+auto *D2 = cast(T2)->getDecl();
+if (!IsStructurallyEquivalent(Context, D1, D2))
+  return false;
+auto *D1Spec =
+
dyn_cast_or_null(D1->getDeclContext());
+auto *D2Spec =
+
dyn_cast_or_null(D2->getDeclContext());
+if (nullptr != D1Spec && nullptr != D2Spec &&
+!IsStructurallyEquivalent(Context, D1Spec, D2Spec))
   return false;
 break;
+  }
 
   case Type::TemplateTypeParm: {
 const auto *Parm1 = cast(T1);
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 44d950cfe758f1..b54d149152e105 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, 
TransparentContextInNamespace) {
   EXPECT_TRUE(testStructuralMatch(Decls));
 }
 
+TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) {
+  std::string Code =
+  R"(
+  template  struct O {
+struct M {};
+  };
+  )";
+  auto t = makeDecls(Code + R"(
+  typedef O::M MT1;
+  MT1 A;
+  )",
+  Code + R"(
+  namespace {
+struct I {};
+  } // namespace
+  typedef O::M MT2;
+  MT2 A;
+  )",
+  Lang_CXX11, varDecl(hasName("A")));
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) {
   auto Decls = makeNamedDecls(
   R"(

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


[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2023-12-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)


Changes

Types comparison in `StructuralEquivalence` ignores its `DeclContext` when they 
are generated by template specialization implicitly and this will produce 
incorrect result. Add comparison of `DeclContext` of 
ClassTemplateSpecializationDecl to improve result.

---
Full diff: https://github.com/llvm/llvm-project/pull/76226.diff


2 Files Affected:

- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+12-3) 
- (modified) clang/unittests/AST/StructuralEquivalenceTest.cpp (+22) 


``diff
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7..7c04c09bb80874 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1107,11 +1107,20 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   }
 
   case Type::Record:
-  case Type::Enum:
-if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(),
-  cast(T2)->getDecl()))
+  case Type::Enum: {
+auto *D1 = cast(T1)->getDecl();
+auto *D2 = cast(T2)->getDecl();
+if (!IsStructurallyEquivalent(Context, D1, D2))
+  return false;
+auto *D1Spec =
+
dyn_cast_or_null(D1->getDeclContext());
+auto *D2Spec =
+
dyn_cast_or_null(D2->getDeclContext());
+if (nullptr != D1Spec && nullptr != D2Spec &&
+!IsStructurallyEquivalent(Context, D1Spec, D2Spec))
   return false;
 break;
+  }
 
   case Type::TemplateTypeParm: {
 const auto *Parm1 = cast(T1);
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 44d950cfe758f1..b54d149152e105 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, 
TransparentContextInNamespace) {
   EXPECT_TRUE(testStructuralMatch(Decls));
 }
 
+TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) {
+  std::string Code =
+  R"(
+  template  struct O {
+struct M {};
+  };
+  )";
+  auto t = makeDecls(Code + R"(
+  typedef O::M MT1;
+  MT1 A;
+  )",
+  Code + R"(
+  namespace {
+struct I {};
+  } // namespace
+  typedef O::M MT2;
+  MT2 A;
+  )",
+  Lang_CXX11, varDecl(hasName("A")));
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) {
   auto Decls = makeNamedDecls(
   R"(

``




https://github.com/llvm/llvm-project/pull/76226
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2023-12-22 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/76226
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 625197d - [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (#74813)

2023-12-22 Thread via cfe-commits

Author: Qizhi Hu
Date: 2023-12-22T18:06:59+08:00
New Revision: 625197d39cf9d56a295f8e6ee2584c825b461db9

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

LOG: [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (#74813)

Since import `ExplicitCastExpr` lacks of processing
`BuiltinBitCastExprClass` type, it would reach to the 'unreachable' code
and produce the crash. This patch aims to fix the
[crash](https://github.com/llvm/llvm-project/issues/74774) and try to
handle `BuiltinBitCastExpr`.

Co-authored-by: huqizhi <836744...@qq.com>

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 88b8c6abb6d5fd..949310856562cd 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -7826,6 +7826,18 @@ ExpectedStmt 
ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
   }
+  case Stmt::BuiltinBitCastExprClass: {
+auto *BBC = cast(E);
+ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
+if (!ToKWLocOrErr)
+  return ToKWLocOrErr.takeError();
+ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
+if (!ToRParenLocOrErr)
+  return ToRParenLocOrErr.takeError();
+return new (Importer.getToContext()) BuiltinBitCastExpr(
+ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
+ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
+  }
   default:
 llvm_unreachable("Cast expression of unsupported type!");
 return make_error(ASTImportError::UnsupportedConstruct);

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 9fa7660cde6593..6c7b2b64ca2d1d 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -561,6 +561,18 @@ TEST_P(ImportExpr, ImportVAArgExpr) {
  cStyleCastExpr(hasSourceExpression(vaArgExpr());
 }
 
+const internal::VariadicDynCastAllOfMatcher
+builtinBitCastExpr;
+
+TEST_P(ImportExpr, ImportBuiltinBitCastExpr) {
+  MatchVerifier Verifier;
+  testImport("void declToImport(int X) {"
+ "  (void)__builtin_bit_cast(float, X); }",
+ Lang_CXX20, "", Lang_CXX20, Verifier,
+ functionDecl(hasDescendant(
+ cStyleCastExpr(hasSourceExpression(builtinBitCastExpr());
+}
+
 TEST_P(ImportExpr, CXXTemporaryObjectExpr) {
   MatchVerifier Verifier;
   testImport(



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


[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)

2023-12-22 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/74813
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [lldb] [clang-tools-extra] [compiler-rt] [libc] [llvm] [clang] [libcxx] [RegAllocFast] Refactor dominates algorithm for large basic block (PR #72250)

2023-12-22 Thread via cfe-commits

https://github.com/yubingex007-a11y approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/72250
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a bug in annotating function declaration names (PR #76206)

2023-12-22 Thread Matt Mundell via cfe-commits

mattmundell wrote:

Thanks for doing this. Does it mean we would have to add every type we use to 
our config? It would be much more convenient if clang-format treated the 
argument list the same way as it does for definitions. For example

```
printf "int\niso_time(time_t) { return 1; }\n" | clang-format -style='{ 
AlwaysBreakAfterReturnType: All }'
```

gives

```
int
iso_time(time_t) {
  return 1;
}
```

whereas

```
printf "int\niso_time(time_t);\n" | clang-format -style='{ 
AlwaysBreakAfterReturnType: All }'
```

will need a config edit to work.

Other examples that are currently failing to line break:

```
printf "int\niso_time(struct example);\n" | clang-format -style='{ 
AlwaysBreakAfterReturnType: All }'
printf "typedef long long int rowid_t;\nint\niso_time(rowid_t);\n" | 
clang-format -style='{ AlwaysBreakAfterReturnType: All }'
```


https://github.com/llvm/llvm-project/pull/76206
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [libc] [llvm] [clang] [libcxx] [lldb] [compiler-rt] [clang-tools-extra] [RegAllocFast] Refactor dominates algorithm for large basic block (PR #72250)

2023-12-22 Thread Wei Xiao via cfe-commits

https://github.com/williamweixiao approved this pull request.


https://github.com/llvm/llvm-project/pull/72250
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)

2023-12-22 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev updated 
https://github.com/llvm/llvm-project/pull/76218

>From c5f5ea4b38e7248a404c0e591d16145faeac388f Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Fri, 22 Dec 2023 08:38:23 +
Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator
 new for C++.

This patch brings back the basic support for C by inserting the required for
value printing runtime only when we are in C++ mode. Additionally, it defines
a new overload of operator placement new because we can't really forward declare
it in a library-agnostic way.

Fixes the issue described in llvm/llvm-project#69072.
---
 clang/include/clang/Interpreter/Interpreter.h |  4 +--
 clang/lib/Interpreter/Interpreter.cpp | 33 +++
 clang/test/Interpreter/incremental-mode.cpp   |  3 +-
 .../unittests/Interpreter/InterpreterTest.cpp | 29 +++-
 4 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 01858dfcc90ac5..292fa566ae7037 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -129,7 +129,7 @@ class Interpreter {
   llvm::Expected
   getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
 
-  enum InterfaceKind { NoAlloc, WithAlloc, CopyArray };
+  enum InterfaceKind { NoAlloc, WithAlloc, CopyArray, NewTag };
 
   const llvm::SmallVectorImpl &getValuePrintingInfo() const {
 return ValuePrintingInfo;
@@ -144,7 +144,7 @@ class Interpreter {
 
   llvm::DenseMap Dtors;
 
-  llvm::SmallVector ValuePrintingInfo;
+  llvm::SmallVector ValuePrintingInfo;
 };
 } // namespace clang
 
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index c9fcef5b5b5af1..83ca750e299792 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,7 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
+#ifdef __cplusplus
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
@@ -256,15 +256,18 @@ const char *const Runtimes = R"(
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
 void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
+struct __clang_Interpreter_NewTag{} __ci_newtag;
+void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) 
noexcept;
 template 
 void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
   for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
+new ((void*)(((T*)Placement) + Idx), __ci_newtag) T(Src[Idx]);
 }
 template 
 void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size) {
   __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
 }
+#endif // __cplusplus
 )";
 
 llvm::Expected>
@@ -279,7 +282,7 @@ Interpreter::create(std::unique_ptr CI) {
   if (!PTU)
 return PTU.takeError();
 
-  Interp->ValuePrintingInfo.resize(3);
+  Interp->ValuePrintingInfo.resize(4);
   // FIXME: This is a ugly hack. Undo command checks its availability by 
looking
   // at the size of the PTU list. However we have parsed something in the
   // beginning of the REPL so we have to mark them as 'Irrevocable'.
@@ -500,7 +503,7 @@ Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) {
 static constexpr llvm::StringRef MagicRuntimeInterface[] = {
 "__clang_Interpreter_SetValueNoAlloc",
 "__clang_Interpreter_SetValueWithAlloc",
-"__clang_Interpreter_SetValueCopyArr"};
+"__clang_Interpreter_SetValueCopyArr", "__ci_newtag"};
 
 bool Interpreter::FindRuntimeInterface() {
   if (llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E != nullptr; }))
@@ -530,6 +533,9 @@ bool Interpreter::FindRuntimeInterface() {
   if (!LookupInterface(ValuePrintingInfo[CopyArray],
MagicRuntimeInterface[CopyArray]))
 return false;
+  if (!LookupInterface(ValuePrintingInfo[NewTag],
+   MagicRuntimeInterface[NewTag]))
+return false;
   return true;
 }
 
@@ -607,7 +613,9 @@ class RuntimeInterfaceBuilder
 .getValuePrintingInfo()[Interpreter::InterfaceKind::CopyArray],
 SourceLocation(), Args, SourceLocation());
   }
-  Expr *Args[] = {AllocCall.get()};
+  Expr *Args[] = {
+  AllocCall.get(),
+  Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]};
   ExprResult CXXNewC

[llvm] [clang] Avoid need for SLocEntryLoaded BitVector (PR #67960)

2023-12-22 Thread Giulio Eulisse via cfe-commits

ktf wrote:

 I was carried away by the heavy ion run and other priorities. i can try to
have a look again after Christmas. Feel free to close if you prefer.

Ciao,
Giulio

On Fri, Dec 22 2023 at 9:32 AM, Vassil Vassilev ***@***.***>
wrote:

> @ktf  what is the fate of this PR?
>
> —
> Reply to this email directly, view it on GitHub
> ,
> or unsubscribe
> 
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>


https://github.com/llvm/llvm-project/pull/67960
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 95b423e - [Sema] NFC. Simplify code in a few places of TryOrBuildParenListInitialization

2023-12-22 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2023-12-22T12:41:52+01:00
New Revision: 95b423e44f6f35651bb1e7d4f6e0591df71360af

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

LOG: [Sema] NFC. Simplify code in a few places of 
TryOrBuildParenListInitialization

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 0fbd87ce34db90..d5ba7fd3413718 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -25,6 +25,7 @@
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
+#include "clang/Sema/Ownership.h"
 #include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/FoldingSet.h"
@@ -5429,18 +5430,12 @@ static void TryOrBuildParenListInitialization(
   auto HandleInitializedEntity = [&](const InitializedEntity &SubEntity,
  const InitializationKind &SubKind,
  Expr *Arg, Expr **InitExpr = nullptr) {
-InitializationSequence IS = [&]() {
-  if (Arg)
-return InitializationSequence(S, SubEntity, SubKind, Arg);
-  return InitializationSequence(S, SubEntity, SubKind, std::nullopt);
-}();
+InitializationSequence IS = InitializationSequence(
+S, SubEntity, SubKind, Arg ? MultiExprArg(Arg) : std::nullopt);
 
 if (IS.Failed()) {
   if (!VerifyOnly) {
-if (Arg)
-  IS.Diagnose(S, SubEntity, SubKind, Arg);
-else
-  IS.Diagnose(S, SubEntity, SubKind, std::nullopt);
+IS.Diagnose(S, SubEntity, SubKind, Arg ? ArrayRef(Arg) : std::nullopt);
   } else {
 Sequence.SetFailed(
 InitializationSequence::FK_ParenthesizedListInitFailed);
@@ -5450,10 +5445,8 @@ static void TryOrBuildParenListInitialization(
 }
 if (!VerifyOnly) {
   ExprResult ER;
-  if (Arg)
-ER = IS.Perform(S, SubEntity, SubKind, Arg);
-  else
-ER = IS.Perform(S, SubEntity, SubKind, std::nullopt);
+  ER = IS.Perform(S, SubEntity, SubKind,
+  Arg ? MultiExprArg(Arg) : std::nullopt);
   if (InitExpr)
 *InitExpr = ER.get();
   else



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


[clang] [Sema] Fix crash on invalid code with parenthesized aggregate initialization (PR #76232)

2023-12-22 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov created 
https://github.com/llvm/llvm-project/pull/76232

Fixes #76228.
Use the same logic as braced init lists, also adds a test that puts incomplete 
types in various positions to check for regressions in the future.

>From 491f3b09a2064c82c1646ca1d0c2987478bb4f51 Mon Sep 17 00:00:00 2001
From: Ilya Biryukov 
Date: Fri, 22 Dec 2023 12:33:34 +0100
Subject: [PATCH] [Sema] Fix crash on invalid code with parenthesized aggregate
 initialization

Fixes #76228.
Use the same logic as braced init lists, also adds a test that puts
incomplete types in various positions to check for regressions in the
future.
---
 clang/lib/Sema/SemaInit.cpp  |  8 
 clang/test/SemaCXX/crash-GH76228.cpp | 28 
 2 files changed, 36 insertions(+)
 create mode 100644 clang/test/SemaCXX/crash-GH76228.cpp

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d5ba7fd3413718..f768d2726b0a1c 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,6 +5512,14 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
+if (RD->isInvalidDecl()) {
+  // Exit early to avoid confusion when processing members.
+  // We do the same for braced list initialization in
+  // `CheckStructUnionTypes`.
+  Sequence.SetFailed(
+  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
+  return;
+}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier &Base : RD->bases()) {
diff --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
new file mode 100644
index 00..a10b9994c5e532
--- /dev/null
+++ b/clang/test/SemaCXX/crash-GH76228.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
+class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
+struct foo {
+  int a;
+  incomplete b;
+  // expected-error@-1 {{incomplete type}}
+};
+foo a1(0);
+
+struct one_int {
+int a;
+};
+struct bar : one_int, incomplete {};
+// expected-error@-1 {{incomplete type}}
+bar a2(0);
+
+incomplete a3[3](1,2,3);
+// expected-error@-1 {{incomplete type}}
+
+struct qux : foo {
+};
+qux a4(0);
+
+struct fred {
+foo a[3];
+};
+fred a5(0);
\ No newline at end of file

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


[clang] [Sema] Fix crash on invalid code with parenthesized aggregate initialization (PR #76232)

2023-12-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ilya Biryukov (ilya-biryukov)


Changes

Fixes #76228.
Use the same logic as braced init lists, also adds a test that puts incomplete 
types in various positions to check for regressions in the future.

---
Full diff: https://github.com/llvm/llvm-project/pull/76232.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaInit.cpp (+8) 
- (added) clang/test/SemaCXX/crash-GH76228.cpp (+28) 


``diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d5ba7fd3413718..f768d2726b0a1c 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,6 +5512,14 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
+if (RD->isInvalidDecl()) {
+  // Exit early to avoid confusion when processing members.
+  // We do the same for braced list initialization in
+  // `CheckStructUnionTypes`.
+  Sequence.SetFailed(
+  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
+  return;
+}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier &Base : RD->bases()) {
diff --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
new file mode 100644
index 00..a10b9994c5e532
--- /dev/null
+++ b/clang/test/SemaCXX/crash-GH76228.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
+class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
+struct foo {
+  int a;
+  incomplete b;
+  // expected-error@-1 {{incomplete type}}
+};
+foo a1(0);
+
+struct one_int {
+int a;
+};
+struct bar : one_int, incomplete {};
+// expected-error@-1 {{incomplete type}}
+bar a2(0);
+
+incomplete a3[3](1,2,3);
+// expected-error@-1 {{incomplete type}}
+
+struct qux : foo {
+};
+qux a4(0);
+
+struct fred {
+foo a[3];
+};
+fred a5(0);
\ No newline at end of file

``




https://github.com/llvm/llvm-project/pull/76232
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix crash on invalid code with parenthesized aggregate initialization (PR #76232)

2023-12-22 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov updated 
https://github.com/llvm/llvm-project/pull/76232

>From 491f3b09a2064c82c1646ca1d0c2987478bb4f51 Mon Sep 17 00:00:00 2001
From: Ilya Biryukov 
Date: Fri, 22 Dec 2023 12:33:34 +0100
Subject: [PATCH 1/2] [Sema] Fix crash on invalid code with parenthesized
 aggregate initialization

Fixes #76228.
Use the same logic as braced init lists, also adds a test that puts
incomplete types in various positions to check for regressions in the
future.
---
 clang/lib/Sema/SemaInit.cpp  |  8 
 clang/test/SemaCXX/crash-GH76228.cpp | 28 
 2 files changed, 36 insertions(+)
 create mode 100644 clang/test/SemaCXX/crash-GH76228.cpp

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d5ba7fd3413718..f768d2726b0a1c 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,6 +5512,14 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
+if (RD->isInvalidDecl()) {
+  // Exit early to avoid confusion when processing members.
+  // We do the same for braced list initialization in
+  // `CheckStructUnionTypes`.
+  Sequence.SetFailed(
+  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
+  return;
+}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier &Base : RD->bases()) {
diff --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
new file mode 100644
index 00..a10b9994c5e532
--- /dev/null
+++ b/clang/test/SemaCXX/crash-GH76228.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
+class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
+struct foo {
+  int a;
+  incomplete b;
+  // expected-error@-1 {{incomplete type}}
+};
+foo a1(0);
+
+struct one_int {
+int a;
+};
+struct bar : one_int, incomplete {};
+// expected-error@-1 {{incomplete type}}
+bar a2(0);
+
+incomplete a3[3](1,2,3);
+// expected-error@-1 {{incomplete type}}
+
+struct qux : foo {
+};
+qux a4(0);
+
+struct fred {
+foo a[3];
+};
+fred a5(0);
\ No newline at end of file

>From c8b0de00c1836cb6eaf864081139886ead3f20cc Mon Sep 17 00:00:00 2001
From: Ilya Biryukov 
Date: Fri, 22 Dec 2023 12:55:51 +0100
Subject: [PATCH 2/2] Add a trailing newline to the test file

---
 clang/test/SemaCXX/crash-GH76228.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
index a10b9994c5e532..33a9395823127e 100644
--- a/clang/test/SemaCXX/crash-GH76228.cpp
+++ b/clang/test/SemaCXX/crash-GH76228.cpp
@@ -25,4 +25,4 @@ qux a4(0);
 struct fred {
 foo a[3];
 };
-fred a5(0);
\ No newline at end of file
+fred a5(0);

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


[clang] [Sema] Fix crash on invalid code with parenthesized aggregate initialization (PR #76232)

2023-12-22 Thread Haojian Wu via cfe-commits

https://github.com/hokein approved this pull request.

Thanks, looks good.

https://github.com/llvm/llvm-project/pull/76232
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 86dc6e1 - [Sema] Fix crash on invalid code with parenthesized aggregate initialization (#76232)

2023-12-22 Thread via cfe-commits

Author: Ilya Biryukov
Date: 2023-12-22T13:11:27+01:00
New Revision: 86dc6e15f22610bbb53eb4efda0a178ecefc933a

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

LOG: [Sema] Fix crash on invalid code with parenthesized aggregate 
initialization (#76232)

Fixes #76228.
Use the same logic as braced init lists, also adds a test that puts
incomplete types in various positions to check for regressions in the
future.

Added: 
clang/test/SemaCXX/crash-GH76228.cpp

Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d5ba7fd3413718..f768d2726b0a1c 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,6 +5512,14 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
+if (RD->isInvalidDecl()) {
+  // Exit early to avoid confusion when processing members.
+  // We do the same for braced list initialization in
+  // `CheckStructUnionTypes`.
+  Sequence.SetFailed(
+  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
+  return;
+}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier &Base : RD->bases()) {

diff  --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
new file mode 100644
index 00..33a9395823127e
--- /dev/null
+++ b/clang/test/SemaCXX/crash-GH76228.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
+class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
+struct foo {
+  int a;
+  incomplete b;
+  // expected-error@-1 {{incomplete type}}
+};
+foo a1(0);
+
+struct one_int {
+int a;
+};
+struct bar : one_int, incomplete {};
+// expected-error@-1 {{incomplete type}}
+bar a2(0);
+
+incomplete a3[3](1,2,3);
+// expected-error@-1 {{incomplete type}}
+
+struct qux : foo {
+};
+qux a4(0);
+
+struct fred {
+foo a[3];
+};
+fred a5(0);



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


[clang] [Sema] Fix crash on invalid code with parenthesized aggregate initialization (PR #76232)

2023-12-22 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov closed 
https://github.com/llvm/llvm-project/pull/76232
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang-tools-extra] [compiler-rt] [lldb] [flang] [libcxx] [libc] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

2023-12-22 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/71222

>From e0d99fb5baa4231ab351f7fd5abf0a1ffe589547 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:55:06 +
Subject: [PATCH 01/15] FDATE extension implementation: get date and time in
 ctime format

reference to gfortran fdate https://gcc.gnu.org/onlinedocs/gfortran/FDATE.html
usage:
CHARACTER(32) :: time
CALL fdate(time)
WRITE(*,*) time
---
 flang/docs/Intrinsics.md |  2 +-
 flang/include/flang/Runtime/command.h|  5 +
 flang/include/flang/Runtime/extensions.h |  2 ++
 flang/runtime/command.cpp| 28 
 flang/runtime/extensions.cpp |  5 +
 flang/unittests/Runtime/CommandTest.cpp  | 14 
 6 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e553..982be820816429 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, FDATE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec628939054547..07f6d8e169ead6 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -23,6 +23,11 @@ extern "C" {
 // integer kind.
 std::int32_t RTNAME(ArgumentCount)();
 
+// Try to get the the current date (same format as CTIME: convert to a string)
+// Return a STATUS as described in the standard.
+std::int32_t RTNAME(FDate)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 // 16.9.82 GET_COMMAND
 // Try to get the value of the whole command. All of the parameters are
 // optional.
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb7..92b9907860121a 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -24,6 +24,8 @@ void FORTRAN_PROCEDURE_NAME(flush)(const int &unit);
 // GNU Fortran 77 compatibility function IARGC.
 std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 
+void FORTRAN_PROCEDURE_NAME(fdate)(std::int8_t *string, std::int64_t length);
+
 // GNU Fortran 77 compatibility subroutine GETARG(N, ARG).
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571..da0803c39f49b6 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -14,6 +14,7 @@
 #include "flang/Runtime/descriptor.h"
 #include 
 #include 
+#include 
 
 namespace Fortran::runtime {
 std::int32_t RTNAME(ArgumentCount)() {
@@ -125,6 +126,33 @@ static bool FitsInDescriptor(
   kind, terminator, value);
 }
 
+void removeNewLine(char *str) {
+  char *newlinePos = strchr(str, '\n');
+  if (newlinePos != NULL) {
+*newlinePos = '\0'; // Replace with null terminator
+  }
+}
+
+std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
+  FillWithSpaces(*value);
+
+  time_t current_time;
+  time(¤t_time);
+
+  char *time_string = ctime(¤t_time);
+  removeNewLine(time_string);
+  std::int64_t stringLen{StringLength(time_string)};
+  if (stringLen <= 0) {
+return ToErrmsg(errmsg, StatMissingArgument);
+  }
+
+  if (value) {
+return CopyToDescriptor(*value, time_string, stringLen, errmsg);
+  }
+
+  return StatOk;
+}
+
 std::int32_t RTNAME(GetCommandArgument)(std::int32_t n, const Descriptor 
*value,
 const Descriptor *length, const Descriptor *errmsg, const char *sourceFile,
 int line) {
diff --git a/flang/runtime/e

[clang] 7ab16fb - [Sema] Update test for previous change

2023-12-22 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2023-12-22T13:30:43+01:00
New Revision: 7ab16fb5207fe187ab999f882069bd632d2e68e5

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

LOG: [Sema] Update test for previous change

The warning for C++20 extension does not fire in on specific instance
because conversion now fails as class is invalid because of an invalid
member.

The new behavior is expected, so updating the test accordingly

Added: 


Modified: 
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index f60b20e0d46568..c1964a5a9eb005 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -289,7 +289,7 @@ int test() {
   // used to crash
   S a(0, 1);
   S b(0);
-  S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' 
from a parenthesized list of values is a C++20 extension}}
+  S c(0, 0, 1);
 
   S d {0, 1};
   S e {0};



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


[clang-tools-extra] [clang] [Sema][clangd] add noexcept to override functions during code completion (PR #75937)

2023-12-22 Thread Sirui Mu via cfe-commits

https://github.com/Lancern updated 
https://github.com/llvm/llvm-project/pull/75937

>From 6e5e6986559a8d8a72901baf60cbc3b9163a7cd7 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Tue, 19 Dec 2023 22:24:23 +0800
Subject: [PATCH 1/3] [clangd][Sema] add noexcept to override functions during
 code completion

---
 .../test/completion-override-except-spec.test | 69 +++
 clang/lib/Sema/SemaCodeComplete.cpp   | 22 ++
 2 files changed, 91 insertions(+)
 create mode 100644 
clang-tools-extra/clangd/test/completion-override-except-spec.test

diff --git a/clang-tools-extra/clangd/test/completion-override-except-spec.test 
b/clang-tools-extra/clangd/test/completion-override-except-spec.test
new file mode 100644
index 00..19c7f84bc679d8
--- /dev/null
+++ b/clang-tools-extra/clangd/test/completion-override-except-spec.test
@@ -0,0 +1,69 @@
+# RUN: clangd -lit-test < %s | FileCheck %s
+# RUN: clangd -lit-test -pch-storage=memory < %s | FileCheck %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"struct
 Base {\n  virtual void virt_method() noexcept = 0;\n};\n\nstruct Derived : 
Base {\n  virt_\n};"}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":5,"character":6}}}
+#  CHECK:  "id": 1,
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"isIncomplete": false,
+# CHECK-NEXT:"items": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"filterText": "virt_method() noexcept override",
+# CHECK-NEXT:"insertText": "void virt_method() noexcept override",
+# CHECK-NEXT:"insertTextFormat": 1,
+# CHECK-NEXT:"kind": 2,
+# CHECK-NEXT:"label": " void virt_method() noexcept override",
+# CHECK-NEXT:"score": {{[0-9]+.[0-9]+}},
+# CHECK-NEXT:"sortText": "{{.*}}virt_method() noexcept override",
+# CHECK-NEXT:"textEdit": {
+# CHECK-NEXT:  "newText": "void virt_method() noexcept override",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 6,
+# CHECK-NEXT:  "line": 5
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 2,
+# CHECK-NEXT:  "line": 5
+# CHECK-NEXT:}
+# CHECK-NEXT:  }
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+---
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///main.cpp","version":2},"contentChanges":[{"text":"struct
 Base {\n  virtual void virt_method() = 0;\n};\n\nstruct Derived : Base {\n  
virt_\n};"}]}}
+---
+{"jsonrpc":"2.0","id":3,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":5,"character":6}}}
+#  CHECK:  "id": 3,
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"isIncomplete": false,
+# CHECK-NEXT:"items": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"filterText": "virt_method() override",
+# CHECK-NEXT:"insertText": "void virt_method() override",
+# CHECK-NEXT:"insertTextFormat": 1,
+# CHECK-NEXT:"kind": 2,
+# CHECK-NEXT:"label": " void virt_method() override",
+# CHECK-NEXT:"score": {{[0-9]+.[0-9]+}},
+# CHECK-NEXT:"sortText": "{{.*}}virt_method() override",
+# CHECK-NEXT:"textEdit": {
+# CHECK-NEXT:  "newText": "void virt_method() override",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 6,
+# CHECK-NEXT:  "line": 5
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 2,
+# CHECK-NEXT:  "line": 5
+# CHECK-NEXT:}
+# CHECK-NEXT:  }
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+---
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index c44be0df9b0a85..516936311a278d 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -25,6 +25,7 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/AttributeCommonInfo.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/Specifiers.h"
 #include "clang/Lex/HeaderSearch.h"
@@ -3292,6 +3293,25 @@ 
AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result,
   Result.AddInformativeChunk(Result.getAllocator().CopyString(QualsStr));
 }
 
+static void
+AddFunctionExceptSpecToCompletionString(CodeCompletionBuilder &Result,
+ 

[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)

2023-12-22 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev updated 
https://github.com/llvm/llvm-project/pull/76218

>From 50a08a2a04c97b0ed5630c53f549a1331e18aee7 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Fri, 22 Dec 2023 08:38:23 +
Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator
 new for C++.

This patch brings back the basic support for C by inserting the required for
value printing runtime only when we are in C++ mode. Additionally, it defines
a new overload of operator placement new because we can't really forward declare
it in a library-agnostic way.

Fixes the issue described in llvm/llvm-project#69072.
---
 clang/include/clang/Interpreter/Interpreter.h |  4 +--
 clang/lib/Interpreter/Interpreter.cpp | 33 +++
 clang/test/Interpreter/incremental-mode.cpp   |  3 +-
 .../unittests/Interpreter/InterpreterTest.cpp | 29 +++-
 4 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 01858dfcc90ac5..292fa566ae7037 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -129,7 +129,7 @@ class Interpreter {
   llvm::Expected
   getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
 
-  enum InterfaceKind { NoAlloc, WithAlloc, CopyArray };
+  enum InterfaceKind { NoAlloc, WithAlloc, CopyArray, NewTag };
 
   const llvm::SmallVectorImpl &getValuePrintingInfo() const {
 return ValuePrintingInfo;
@@ -144,7 +144,7 @@ class Interpreter {
 
   llvm::DenseMap Dtors;
 
-  llvm::SmallVector ValuePrintingInfo;
+  llvm::SmallVector ValuePrintingInfo;
 };
 } // namespace clang
 
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index c9fcef5b5b5af1..82a4217ad37aa2 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,7 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
+#ifdef __cplusplus
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
@@ -256,15 +256,18 @@ const char *const Runtimes = R"(
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
 void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
+struct __clang_Interpreter_NewTag{} __ci_newtag;
+void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) 
noexcept;
 template 
 void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
   for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
+new ((void*)(((T*)Placement) + Idx), __ci_newtag) T(Src[Idx]);
 }
 template 
 void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size) {
   __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
 }
+#endif // __cplusplus
 )";
 
 llvm::Expected>
@@ -279,7 +282,7 @@ Interpreter::create(std::unique_ptr CI) {
   if (!PTU)
 return PTU.takeError();
 
-  Interp->ValuePrintingInfo.resize(3);
+  Interp->ValuePrintingInfo.resize(4);
   // FIXME: This is a ugly hack. Undo command checks its availability by 
looking
   // at the size of the PTU list. However we have parsed something in the
   // beginning of the REPL so we have to mark them as 'Irrevocable'.
@@ -500,7 +503,7 @@ Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) {
 static constexpr llvm::StringRef MagicRuntimeInterface[] = {
 "__clang_Interpreter_SetValueNoAlloc",
 "__clang_Interpreter_SetValueWithAlloc",
-"__clang_Interpreter_SetValueCopyArr"};
+"__clang_Interpreter_SetValueCopyArr", "__ci_newtag"};
 
 bool Interpreter::FindRuntimeInterface() {
   if (llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E != nullptr; }))
@@ -530,6 +533,9 @@ bool Interpreter::FindRuntimeInterface() {
   if (!LookupInterface(ValuePrintingInfo[CopyArray],
MagicRuntimeInterface[CopyArray]))
 return false;
+  if (!LookupInterface(ValuePrintingInfo[NewTag],
+   MagicRuntimeInterface[NewTag]))
+return false;
   return true;
 }
 
@@ -607,7 +613,9 @@ class RuntimeInterfaceBuilder
 .getValuePrintingInfo()[Interpreter::InterfaceKind::CopyArray],
 SourceLocation(), Args, SourceLocation());
   }
-  Expr *Args[] = {AllocCall.get()};
+  Expr *Args[] = {
+  AllocCall.get(),
+  Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]};
   ExprResult CXXNewC

[clang] [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (PR #74943)

2023-12-22 Thread via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/74943

>From b80f8579dbc745ddfaa3d60770dd0d3e79e6c641 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Sat, 9 Dec 2023 14:31:12 -0300
Subject: [PATCH 1/8] Fixes overload operator in BreakAfterAttributes

---
 clang/lib/Format/ContinuationIndenter.cpp |  3 ++-
 clang/unittests/Format/FormatTest.cpp | 14 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 9e4e939503dfe4..de3768d475e7b2 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -593,7 +593,8 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
 // name.
 !Style.isJavaScript()) ||
(Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
-  Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter) {
+  Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter &&
+  (Style.isCpp() && Current.Tok.isNot(tok::kw_operator))) {
 return true;
   }
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 24b2fd599dc397..a1f3beed475ff3 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26417,6 +26417,20 @@ TEST_F(FormatTest, BreakAfterAttributes) {
"void g() {}",
CtorDtorCode, Style);
 
+  Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
+  constexpr StringRef OperatorOverloadCode(
+  "struct Foo {\n"
+  "[[maybe_unused]] void operator+();\n"
+  "};\n"
+  "[[nodiscard]] Foo& operator-(Foo&);");
+  verifyFormat("struct Foo {\n"
+   "  [[maybe_unused]]\n"
+   "  void operator+();\n"
+   "};\n"
+   "[[nodiscard]]\n"
+   "Foo& operator-(Foo&);",
+   OperatorOverloadCode, Style);
+
   Style.BreakBeforeBraces = FormatStyle::BS_Linux;
   verifyFormat("struct Foo {\n"
"  [[deprecated]]\n"

>From 67a018f8c27f547fdea3443100ec7255e7aa4f2e Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Sat, 9 Dec 2023 16:05:12 -0300
Subject: [PATCH 2/8] Addresses 1, 2 and 4 comments

---
 clang/lib/Format/ContinuationIndenter.cpp |  2 +-
 clang/unittests/Format/FormatTest.cpp | 20 
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index de3768d475e7b2..d05a16f87038ce 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -594,7 +594,7 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
 !Style.isJavaScript()) ||
(Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
   Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter &&
-  (Style.isCpp() && Current.Tok.isNot(tok::kw_operator))) {
+  Current.Tok.isNot(tok::kw_operator)) {
 return true;
   }
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a1f3beed475ff3..bccc3162c34367 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26418,18 +26418,14 @@ TEST_F(FormatTest, BreakAfterAttributes) {
CtorDtorCode, Style);
 
   Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
-  constexpr StringRef OperatorOverloadCode(
-  "struct Foo {\n"
-  "[[maybe_unused]] void operator+();\n"
-  "};\n"
-  "[[nodiscard]] Foo& operator-(Foo&);");
-  verifyFormat("struct Foo {\n"
-   "  [[maybe_unused]]\n"
-   "  void operator+();\n"
-   "};\n"
-   "[[nodiscard]]\n"
-   "Foo& operator-(Foo&);",
-   OperatorOverloadCode, Style);
+  verifyNoChange("struct Foo {\n"
+ "  [[maybe_unused]]\n"
+ "  void operator+();\n"
+ "};\n"
+ "[[nodiscard]]\n"
+ "Foo& operator-(Foo&);",
+ Style);
+  Style.ReferenceAlignment = getLLVMStyle().ReferenceAlignment;
 
   Style.BreakBeforeBraces = FormatStyle::BS_Linux;
   verifyFormat("struct Foo {\n"

>From f9b8d8cee9cf1fd313497c72e7829114a5d4b083 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Sat, 9 Dec 2023 18:46:15 -0300
Subject: [PATCH 3/8] Addresses comment 3

---
 clang/lib/Format/ContinuationIndenter.cpp | 25 +--
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index d05a16f87038ce..a9ce3d20142984 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -584,20 +584,23 @@ bool ContinuationIndenter::mustBreak(const LineSta

[llvm] [clang] [CMake] Move check for dlfcn.h and dladdr to clang (PR #76163)

2023-12-22 Thread Abhina Sree via cfe-commits

abhina-sree wrote:

CI failure is unrelated to my patch, so I will go ahead and commit

https://github.com/llvm/llvm-project/pull/76163
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d430c14 - [CMake] Move check for dlfcn.h and dladdr to clang (#76163)

2023-12-22 Thread via cfe-commits

Author: Abhina Sree
Date: 2023-12-22T08:12:19-05:00
New Revision: d430c145ba92328e8363fab7adca4fc1e61e6637

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

LOG: [CMake] Move check for dlfcn.h and dladdr to clang (#76163)

This patch checks for the presence of dlfcn.h and dladdr in clang to be used in 
clang/tools/libclang/CIndexer.cpp

Added: 


Modified: 
clang/CMakeLists.txt
clang/include/clang/Config/config.h.cmake
clang/tools/libclang/CIndexer.cpp
llvm/include/llvm/Config/config.h.cmake
llvm/include/llvm/Config/llvm-config.h.cmake

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 2ca6db02e58791..9f814478c45503 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -167,6 +167,23 @@ endif()
 include(CheckIncludeFile)
 check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
 
+# This check requires _GNU_SOURCE on linux
+check_include_file(dlfcn.h CLANG_HAVE_DLFCN_H)
+if( CLANG_HAVE_DLFCN_H )
+  include(CheckLibraryExists)
+  include(CheckSymbolExists)
+  check_library_exists(dl dlopen "" HAVE_LIBDL)
+  if( HAVE_LIBDL )
+list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
+  endif()
+  list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
+  check_symbol_exists(dladdr dlfcn.h CLANG_HAVE_DLADDR)
+  list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
+  if( HAVE_LIBDL )
+list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
+  endif()
+endif()
+
 set(CLANG_RESOURCE_DIR "" CACHE STRING
   "Relative directory from the Clang binary to its resource files.")
 

diff  --git a/clang/include/clang/Config/config.h.cmake 
b/clang/include/clang/Config/config.h.cmake
index a54a26cd32ffe4..4015ac8040861c 100644
--- a/clang/include/clang/Config/config.h.cmake
+++ b/clang/include/clang/Config/config.h.cmake
@@ -57,6 +57,12 @@
 /* Define if we have sys/resource.h (rlimits) */
 #cmakedefine CLANG_HAVE_RLIMITS ${CLANG_HAVE_RLIMITS}
 
+/* Define if we have dlfcn.h */
+#cmakedefine CLANG_HAVE_DLFCN_H ${CLANG_HAVE_DLFCN_H}
+
+/* Define if dladdr() is available on this platform. */
+#cmakedefine CLANG_HAVE_DLADDR ${CLANG_HAVE_DLADDR}
+
 /* Linker version detected at compile time. */
 #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}"
 

diff  --git a/clang/tools/libclang/CIndexer.cpp 
b/clang/tools/libclang/CIndexer.cpp
index 430147b2aa77af..12d9d418dea51d 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -14,10 +14,10 @@
 #include "CXString.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
-#include "llvm/Config/llvm-config.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
@@ -127,7 +127,7 @@ const std::string &CIndexer::getClangResourcesPath() {
   getClangResourcesPathImplAIX(LibClangPath);
 #else
   bool PathFound = false;
-#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR)
+#if defined(CLANG_HAVE_DLFCN_H) && defined(CLANG_HAVE_DLADDR)
   Dl_info info;
   // This silly cast below avoids a C++ warning.
   if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) {

diff  --git a/llvm/include/llvm/Config/config.h.cmake 
b/llvm/include/llvm/Config/config.h.cmake
index d464263c190a73..fc1f9bf342f8d5 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -50,9 +50,15 @@
don't. */
 #cmakedefine01 HAVE_DECL_STRERROR_S
 
+/* Define to 1 if you have the  header file. */
+#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H}
+
 /* Define if dlopen() is available on this platform. */
 #cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN}
 
+/* Define if dladdr() is available on this platform. */
+#cmakedefine HAVE_DLADDR ${HAVE_DLADDR}
+
 /* Define to 1 if we can register EH frames on this platform. */
 #cmakedefine HAVE_REGISTER_FRAME ${HAVE_REGISTER_FRAME}
 

diff  --git a/llvm/include/llvm/Config/llvm-config.h.cmake 
b/llvm/include/llvm/Config/llvm-config.h.cmake
index 483c5adc99ca80..6605ea60df99e1 100644
--- a/llvm/include/llvm/Config/llvm-config.h.cmake
+++ b/llvm/include/llvm/Config/llvm-config.h.cmake
@@ -198,10 +198,4 @@
 /* Define if plugins enabled */
 #cmakedefine LLVM_ENABLE_PLUGINS
 
-/* Define to 1 if you have the  header file. */
-#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H}
-
-/* Define if dladdr() is available on this platform. */
-#cmakedefine HAVE_DLADDR ${HAVE_DLADDR}
-
 #endif



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


[llvm] [clang] [CMake] Move check for dlfcn.h and dladdr to clang (PR #76163)

2023-12-22 Thread Abhina Sree via cfe-commits

https://github.com/abhina-sree closed 
https://github.com/llvm/llvm-project/pull/76163
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [lldb] [libc] [llvm] [clang-tools-extra] [compiler-rt] [libcxx] [clang] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

2023-12-22 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/71222

>From e0d99fb5baa4231ab351f7fd5abf0a1ffe589547 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:55:06 +
Subject: [PATCH 01/16] FDATE extension implementation: get date and time in
 ctime format

reference to gfortran fdate https://gcc.gnu.org/onlinedocs/gfortran/FDATE.html
usage:
CHARACTER(32) :: time
CALL fdate(time)
WRITE(*,*) time
---
 flang/docs/Intrinsics.md |  2 +-
 flang/include/flang/Runtime/command.h|  5 +
 flang/include/flang/Runtime/extensions.h |  2 ++
 flang/runtime/command.cpp| 28 
 flang/runtime/extensions.cpp |  5 +
 flang/unittests/Runtime/CommandTest.cpp  | 14 
 6 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e553..982be820816429 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, FDATE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec628939054547..07f6d8e169ead6 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -23,6 +23,11 @@ extern "C" {
 // integer kind.
 std::int32_t RTNAME(ArgumentCount)();
 
+// Try to get the the current date (same format as CTIME: convert to a string)
+// Return a STATUS as described in the standard.
+std::int32_t RTNAME(FDate)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 // 16.9.82 GET_COMMAND
 // Try to get the value of the whole command. All of the parameters are
 // optional.
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb7..92b9907860121a 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -24,6 +24,8 @@ void FORTRAN_PROCEDURE_NAME(flush)(const int &unit);
 // GNU Fortran 77 compatibility function IARGC.
 std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 
+void FORTRAN_PROCEDURE_NAME(fdate)(std::int8_t *string, std::int64_t length);
+
 // GNU Fortran 77 compatibility subroutine GETARG(N, ARG).
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571..da0803c39f49b6 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -14,6 +14,7 @@
 #include "flang/Runtime/descriptor.h"
 #include 
 #include 
+#include 
 
 namespace Fortran::runtime {
 std::int32_t RTNAME(ArgumentCount)() {
@@ -125,6 +126,33 @@ static bool FitsInDescriptor(
   kind, terminator, value);
 }
 
+void removeNewLine(char *str) {
+  char *newlinePos = strchr(str, '\n');
+  if (newlinePos != NULL) {
+*newlinePos = '\0'; // Replace with null terminator
+  }
+}
+
+std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
+  FillWithSpaces(*value);
+
+  time_t current_time;
+  time(¤t_time);
+
+  char *time_string = ctime(¤t_time);
+  removeNewLine(time_string);
+  std::int64_t stringLen{StringLength(time_string)};
+  if (stringLen <= 0) {
+return ToErrmsg(errmsg, StatMissingArgument);
+  }
+
+  if (value) {
+return CopyToDescriptor(*value, time_string, stringLen, errmsg);
+  }
+
+  return StatOk;
+}
+
 std::int32_t RTNAME(GetCommandArgument)(std::int32_t n, const Descriptor 
*value,
 const Descriptor *length, const Descriptor *errmsg, const char *sourceFile,
 int line) {
diff --git a/flang/runtime/e

[clang] [clang-format] Do not break on JS fields like on goto labels (PR #76233)

2023-12-22 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov created 
https://github.com/llvm/llvm-project/pull/76233

This regressions was introduced in 70d7ea0cebcf363cd0ddcfb76375fb5fada87dd5. 
The commit moved some code and correctly picked up an explicit check for not 
running on Verilog.
However, the moved code also never ran for JavaScript and after the commit we 
run it there and
this causes the wrong formatting of:

```js
export type Params = Config&{
  columns: Column[];
};
```
into
```js
export type Params = Config&{
columns:
  Column[];
};
```

>From a21ed6f78f305a4910dc355d8ad31da04d81b86e Mon Sep 17 00:00:00 2001
From: Ilya Biryukov 
Date: Fri, 22 Dec 2023 14:09:22 +0100
Subject: [PATCH] [clang-format] Do not break on JS fields like on goto labels

This regressions was introduced in 70d7ea0cebcf363cd0ddcfb76375fb5fada87dd5.
In addition to an explicit check for Verilog, the moved code also never
ran for JavaScript, which causes unwanted formatting turning:

```js
export type Params = Config&{
  columns: Column[];
};
```
into
```js
export type Params = Config&{
columns:
  Column[];
};
```
---
 clang/lib/Format/UnwrappedLineParser.cpp | 6 --
 clang/unittests/Format/FormatTestJS.cpp  | 6 ++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c38b4c884070bb..684609747a5513 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1650,8 +1650,10 @@ void UnwrappedLineParser::parseStructuralElement(
   return;
 }
 // In Verilog labels can be any expression, so we don't do them here.
-if (!Style.isVerilog() && Tokens->peekNextToken()->is(tok::colon) &&
-!Line->MustBeDeclaration) {
+// JS doesn't have macros, and within classes colons indicate fields, not
+// labels.
+if (!Style.isJavaScript() && !Style.isVerilog() &&
+Tokens->peekNextToken()->is(tok::colon) && !Line->MustBeDeclaration) {
   nextToken();
   Line->Tokens.begin()->Tok->MustBreakBefore = true;
   FormatTok->setFinalizedType(TT_GotoLabelColon);
diff --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index e185eceb353057..3aded8f3726d8b 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -2836,5 +2836,11 @@ TEST_F(FormatTestJS, 
AlignConsecutiveAssignmentsAndDeclarations) {
Style);
 }
 
+TEST_F(FormatTestJS, DontBreakFieldsAsGoToLabels) {
+  verifyFormat("export type Params = Config&{\n"
+   "  columns: Column[];\n"
+   "};");
+}
+
 } // namespace format
 } // end namespace clang

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


[clang] [clang-format] Do not break on JS fields like on goto labels (PR #76233)

2023-12-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Ilya Biryukov (ilya-biryukov)


Changes

This regressions was introduced in 70d7ea0cebcf363cd0ddcfb76375fb5fada87dd5. 
The commit moved some code and correctly picked up an explicit check for not 
running on Verilog.
However, the moved code also never ran for JavaScript and after the commit we 
run it there and
this causes the wrong formatting of:

```js
export type Params = Config&{
  columns: Column[];
};
```
into
```js
export type Params = Config&{
columns:
  Column[];
};
```

---
Full diff: https://github.com/llvm/llvm-project/pull/76233.diff


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+4-2) 
- (modified) clang/unittests/Format/FormatTestJS.cpp (+6) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c38b4c884070bb..684609747a5513 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1650,8 +1650,10 @@ void UnwrappedLineParser::parseStructuralElement(
   return;
 }
 // In Verilog labels can be any expression, so we don't do them here.
-if (!Style.isVerilog() && Tokens->peekNextToken()->is(tok::colon) &&
-!Line->MustBeDeclaration) {
+// JS doesn't have macros, and within classes colons indicate fields, not
+// labels.
+if (!Style.isJavaScript() && !Style.isVerilog() &&
+Tokens->peekNextToken()->is(tok::colon) && !Line->MustBeDeclaration) {
   nextToken();
   Line->Tokens.begin()->Tok->MustBreakBefore = true;
   FormatTok->setFinalizedType(TT_GotoLabelColon);
diff --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index e185eceb353057..3aded8f3726d8b 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -2836,5 +2836,11 @@ TEST_F(FormatTestJS, 
AlignConsecutiveAssignmentsAndDeclarations) {
Style);
 }
 
+TEST_F(FormatTestJS, DontBreakFieldsAsGoToLabels) {
+  verifyFormat("export type Params = Config&{\n"
+   "  columns: Column[];\n"
+   "};");
+}
+
 } // namespace format
 } // end namespace clang

``




https://github.com/llvm/llvm-project/pull/76233
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Do not break on JS fields like on goto labels (PR #76233)

2023-12-22 Thread Krasimir Georgiev via cfe-commits

https://github.com/krasimirgg approved this pull request.

thank you!

https://github.com/llvm/llvm-project/pull/76233
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2023-12-22 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/75440

>From 5a746e97989ba795264d20aef4f056db0c17bc2c Mon Sep 17 00:00:00 2001
From: hstk30-hw 
Date: Thu, 14 Dec 2023 15:40:03 +0800
Subject: [PATCH] feat: arm_acle.h add Coprocessor Instrinsics

---
 clang/lib/Basic/Targets/ARM.cpp   |  72 
 clang/lib/Headers/arm_acle.h  |  53 +++
 clang/test/CodeGen/arm-acle-coproc.c  | 346 ++
 .../Preprocessor/aarch64-target-features.c|   1 +
 4 files changed, 472 insertions(+)
 create mode 100644 clang/test/CodeGen/arm-acle-coproc.c

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index ce7e4d4639ceac..c7962210e4563b 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -836,6 +836,78 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (Opts.RWPI)
 Builder.defineMacro("__ARM_RWPI", "1");
 
+  // Macros for enabling co-proc intrinsics
+  if ((ArchKind == llvm::ARM::ArchKind::ARMV4 ||
+   ArchKind == llvm::ARM::ArchKind::ARMV4T) &&
+  !isThumb()) {
+Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
+Builder.defineMacro("__ARM_FEATURE_COPROC_V4", "1");
+  }
+
+  if (ArchKind == llvm::ARM::ArchKind::ARMV5T &&
+  !isThumb()) {
+Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
+Builder.defineMacro("__ARM_FEATURE_COPROC_V5", "1");
+  }
+
+  if ((ArchKind == llvm::ARM::ArchKind::ARMV5TE ||
+   ArchKind == llvm::ARM::ArchKind::ARMV5TEJ) &&
+   !isThumb()) {
+Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
+Builder.defineMacro("__ARM_FEATURE_COPROC_V5TE", "1");
+  }
+
+  if ((ArchKind == llvm::ARM::ArchKind::ARMV6 ||
+  ArchKind == llvm::ARM::ArchKind::ARMV6K ||
+  ArchKind == llvm::ARM::ArchKind::ARMV6KZ) &&
+  !isThumb()) {
+Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
+Builder.defineMacro("__ARM_FEATURE_COPROC_V6", "1");
+  }
+
+  if (ArchKind == llvm::ARM::ArchKind::ARMV6T2) {
+Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
+Builder.defineMacro("__ARM_FEATURE_COPROC_V6", "1");
+  }
+
+  if (ArchKind == llvm::ARM::ArchKind::ARMV7A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV7R ||
+  ArchKind == llvm::ARM::ArchKind::ARMV7M ||
+  ArchKind == llvm::ARM::ArchKind::ARMV7S ||
+  ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
+Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
+Builder.defineMacro("__ARM_FEATURE_COPROC_V7", "1");
+  }
+
+  if (ArchKind == llvm::ARM::ArchKind::ARMV8A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8R ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_1A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_2A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_3A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_4A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_5A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_6A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_7A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_8A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_9A) {
+Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
+Builder.defineMacro("__ARM_FEATURE_COPROC_V8", "1");
+  }
+
+  if (ArchKind == llvm::ARM::ArchKind::ARMV9A   ||
+  ArchKind == llvm::ARM::ArchKind::ARMV9_1A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV9_2A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV9_3A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV9_4A) {
+Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
+Builder.defineMacro("__ARM_FEATURE_COPROC_V9", "1");
+  }
+
+  if (ArchKind == llvm::ARM::ArchKind::ARMV8MMainline) {
+Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
+Builder.defineMacro("__ARM_FEATURE_COPROC_V8M", "1");
+  }
+
   if (ArchKind == llvm::ARM::ArchKind::XSCALE)
 Builder.defineMacro("__XSCALE__");
 
diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 61d80258d166a1..6852337c38038b 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -756,6 +756,59 @@ __arm_st64bv0(void *__addr, data512_t __value) {
   __builtin_arm_mops_memset_tag(__tagged_address, __value, __size)
 #endif
 
+/* Coprocessor Intrinsics */
+#if __ARM_FEATURE_COPROC
+
+#ifndef __ARM_TARGET_COPROC_V8
+#define __arm_cdp(coproc, opc1, CRd, CRn, CRm, opc2) __builtin_arm_cdp(coproc, 
opc1, CRd, CRn, CRm, opc2)
+#endif
+
+#define __arm_ldc(coproc, CRd, p) __builtin_arm_ldc(coproc, CRd, p)
+#define __arm_stc(coproc, CRd, p) __builtin_arm_stc(coproc, CRd, p)
+
+#if !defined(__ARM_TARGET_COPROC_V4) && !defined(__ARM_TARGET_COPROC_V8)
+#define __arm_ldcl(coproc, CRd, p) __builtin_arm_ldcl(coproc, CRd, p)
+#define __arm_stcl(coproc, CRd, p) __builtin_arm_stcl(coproc, CRd, p)
+#endif
+
+
+#define __arm_mcr(coproc, opc1, value, CRn, CRm, opc2) 
__builtin_arm_mcr(coproc, opc1, value, CRn, CRm, opc2)
+#define __arm_mrc(coproc, opc1, CRn, CRm, opc2) __builtin_arm_mrc(coproc, 
opc1, CRn, CRm, opc2)
+
+#if !def

[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2023-12-22 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 88d319a29ff5d3be1bb9a7e88ef6e17df1dfe607 
5a746e97989ba795264d20aef4f056db0c17bc2c -- 
clang/test/CodeGen/arm-acle-coproc.c clang/lib/Basic/Targets/ARM.cpp 
clang/lib/Headers/arm_acle.h clang/test/Preprocessor/aarch64-target-features.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index c7962210e4..bada097555 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -844,22 +844,21 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__ARM_FEATURE_COPROC_V4", "1");
   }
 
-  if (ArchKind == llvm::ARM::ArchKind::ARMV5T &&
-  !isThumb()) {
+  if (ArchKind == llvm::ARM::ArchKind::ARMV5T && !isThumb()) {
 Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
 Builder.defineMacro("__ARM_FEATURE_COPROC_V5", "1");
   }
 
   if ((ArchKind == llvm::ARM::ArchKind::ARMV5TE ||
ArchKind == llvm::ARM::ArchKind::ARMV5TEJ) &&
-   !isThumb()) {
+  !isThumb()) {
 Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
 Builder.defineMacro("__ARM_FEATURE_COPROC_V5TE", "1");
   }
 
   if ((ArchKind == llvm::ARM::ArchKind::ARMV6 ||
-  ArchKind == llvm::ARM::ArchKind::ARMV6K ||
-  ArchKind == llvm::ARM::ArchKind::ARMV6KZ) &&
+   ArchKind == llvm::ARM::ArchKind::ARMV6K ||
+   ArchKind == llvm::ARM::ArchKind::ARMV6KZ) &&
   !isThumb()) {
 Builder.defineMacro("__ARM_FEATURE_COPROC", "1");
 Builder.defineMacro("__ARM_FEATURE_COPROC_V6", "1");
@@ -894,7 +893,7 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__ARM_FEATURE_COPROC_V8", "1");
   }
 
-  if (ArchKind == llvm::ARM::ArchKind::ARMV9A   ||
+  if (ArchKind == llvm::ARM::ArchKind::ARMV9A ||
   ArchKind == llvm::ARM::ArchKind::ARMV9_1A ||
   ArchKind == llvm::ARM::ArchKind::ARMV9_2A ||
   ArchKind == llvm::ARM::ArchKind::ARMV9_3A ||
diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 6852337c38..b91e227655 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -760,7 +760,8 @@ __arm_st64bv0(void *__addr, data512_t __value) {
 #if __ARM_FEATURE_COPROC
 
 #ifndef __ARM_TARGET_COPROC_V8
-#define __arm_cdp(coproc, opc1, CRd, CRn, CRm, opc2) __builtin_arm_cdp(coproc, 
opc1, CRd, CRn, CRm, opc2)
+#define __arm_cdp(coproc, opc1, CRd, CRn, CRm, opc2)   
\
+  __builtin_arm_cdp(coproc, opc1, CRd, CRn, CRm, opc2)
 #endif
 
 #define __arm_ldc(coproc, CRd, p) __builtin_arm_ldc(coproc, CRd, p)
@@ -771,28 +772,34 @@ __arm_st64bv0(void *__addr, data512_t __value) {
 #define __arm_stcl(coproc, CRd, p) __builtin_arm_stcl(coproc, CRd, p)
 #endif
 
-
-#define __arm_mcr(coproc, opc1, value, CRn, CRm, opc2) 
__builtin_arm_mcr(coproc, opc1, value, CRn, CRm, opc2)
-#define __arm_mrc(coproc, opc1, CRn, CRm, opc2) __builtin_arm_mrc(coproc, 
opc1, CRn, CRm, opc2)
+#define __arm_mcr(coproc, opc1, value, CRn, CRm, opc2) 
\
+  __builtin_arm_mcr(coproc, opc1, value, CRn, CRm, opc2)
+#define __arm_mrc(coproc, opc1, CRn, CRm, opc2)
\
+  __builtin_arm_mrc(coproc, opc1, CRn, CRm, opc2)
 
 #if !defined(__ARM_TARGET_COPROC_V4) && !defined(__ARM_TARGET_COPROC_V8)
-#define __arm_cdp2(coproc, opc1, CRd, CRn, CRm, opc2) 
__builtin_arm_cdp2(coproc, opc1, CRd, CRn, CRm, opc2)
+#define __arm_cdp2(coproc, opc1, CRd, CRn, CRm, opc2)  
\
+  __builtin_arm_cdp2(coproc, opc1, CRd, CRn, CRm, opc2)
 
 #define __arm_ldc2(coproc, CRd, p) __builtin_arm_ldc2(coproc, CRd, p)
 #define __arm_ldc2l(coproc, CRd, p) __builtin_arm_ldc2l(coproc, CRd, p)
 #define __arm_stc2(coproc, CRd, p) __builtin_arm_stc2(coproc, CRd, p)
 #define __arm_stc2l(coproc, CRd, p) __builtin_arm_stc2l(coproc, CRd, p)
 
-#define __arm_mcr2(coproc, opc1, value, CRn, CRm, opc2) 
__builtin_arm_mcr2(coproc, opc1, value, CRn, CRm, opc2)
-#define __arm_mrc2(coproc, opc1, CRn, CRm, opc2) __builtin_arm_mrc2(coproc, 
opc1, CRn, CRm, opc2)
+#define __arm_mcr2(coproc, opc1, value, CRn, CRm, opc2)
\
+  __builtin_arm_mcr2(coproc, opc1, value, CRn, CRm, opc2)
+#define __arm_mrc2(coproc, opc1, CRn, CRm, opc2)   
\
+  __builtin_arm_mrc2(coproc, opc1, CRn, CRm, opc2)
 
 #ifndef __ARM_TARGET_COPROC_V5
 
-#define __arm_mcrr(coproc, opc1, value, CRm) __builtin_arm_mcrr(coproc, opc1, 
value, CRm)
+#define __arm_mcrr(coproc, opc1, value, CRm)   
\
+  __builtin_arm_mcrr(coproc, opc1, value, CRm)
 #define __arm_mrrc(coproc, opc1, CRm) __builtin_arm_mrrc(coproc, opc1, CRm)
 
 #ifndef __ARM_TARGET_COPROC_V5TE
-#define __arm_mcrr2(coproc, opc1, value, CRm) __builtin_arm_m

[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2023-12-22 Thread David Green via cfe-commits

davemgreen wrote:

Thanks for doing this.
I think that __ARM_FEATURE_COPROC should be a bitfield, as defined in 
https://arm-software.github.io/acle/main/acle.html#coprocessor-intrinsics. That 
would remove the need for the other macros.

https://github.com/llvm/llvm-project/pull/75440
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Do not break on JS fields like on goto labels (PR #76233)

2023-12-22 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

There is no way for me to fix the formatting presubmit as it can't run on new 
clang-format code.
Submitting as is.

https://github.com/llvm/llvm-project/pull/76233
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d03beb9 - [clang-format] Do not break on JS fields like on goto labels (#76233)

2023-12-22 Thread via cfe-commits

Author: Ilya Biryukov
Date: 2023-12-22T14:41:38+01:00
New Revision: d03beb94195ae6889d3075dabe64d58c9ab5d1d2

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

LOG: [clang-format] Do not break on JS fields like on goto labels (#76233)

This regressions was introduced in
70d7ea0cebcf363cd0ddcfb76375fb5fada87dd5.
The commit moved some code and correctly picked up an explicit check for
not running on Verilog.
However, the moved code also never ran for JavaScript and after the
commit we run it there and
this causes the wrong formatting of:

```js
export type Params = Config&{
  columns: Column[];
};
```
into
```js
export type Params = Config&{
columns:
  Column[];
};
```

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestJS.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c38b4c884070bb..684609747a5513 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1650,8 +1650,10 @@ void UnwrappedLineParser::parseStructuralElement(
   return;
 }
 // In Verilog labels can be any expression, so we don't do them here.
-if (!Style.isVerilog() && Tokens->peekNextToken()->is(tok::colon) &&
-!Line->MustBeDeclaration) {
+// JS doesn't have macros, and within classes colons indicate fields, not
+// labels.
+if (!Style.isJavaScript() && !Style.isVerilog() &&
+Tokens->peekNextToken()->is(tok::colon) && !Line->MustBeDeclaration) {
   nextToken();
   Line->Tokens.begin()->Tok->MustBreakBefore = true;
   FormatTok->setFinalizedType(TT_GotoLabelColon);

diff  --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index e185eceb353057..3aded8f3726d8b 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -2836,5 +2836,11 @@ TEST_F(FormatTestJS, 
AlignConsecutiveAssignmentsAndDeclarations) {
Style);
 }
 
+TEST_F(FormatTestJS, DontBreakFieldsAsGoToLabels) {
+  verifyFormat("export type Params = Config&{\n"
+   "  columns: Column[];\n"
+   "};");
+}
+
 } // namespace format
 } // end namespace clang



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


[clang] [clang-format] Do not break on JS fields like on goto labels (PR #76233)

2023-12-22 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov closed 
https://github.com/llvm/llvm-project/pull/76233
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)

2023-12-22 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev updated 
https://github.com/llvm/llvm-project/pull/76218

>From a3f213ef4a7e293152c272cce78ad5d10a3ede52 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Fri, 22 Dec 2023 08:38:23 +
Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator
 new for C++.

This patch brings back the basic support for C by inserting the required for
value printing runtime only when we are in C++ mode. Additionally, it defines
a new overload of operator placement new because we can't really forward declare
it in a library-agnostic way.

Fixes the issue described in llvm/llvm-project#69072.
---
 clang/include/clang/Interpreter/Interpreter.h |  4 +--
 clang/lib/Interpreter/Interpreter.cpp | 33 +++
 clang/test/Interpreter/incremental-mode.cpp   |  3 +-
 .../unittests/Interpreter/InterpreterTest.cpp | 29 +++-
 4 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 01858dfcc90ac5..292fa566ae7037 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -129,7 +129,7 @@ class Interpreter {
   llvm::Expected
   getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
 
-  enum InterfaceKind { NoAlloc, WithAlloc, CopyArray };
+  enum InterfaceKind { NoAlloc, WithAlloc, CopyArray, NewTag };
 
   const llvm::SmallVectorImpl &getValuePrintingInfo() const {
 return ValuePrintingInfo;
@@ -144,7 +144,7 @@ class Interpreter {
 
   llvm::DenseMap Dtors;
 
-  llvm::SmallVector ValuePrintingInfo;
+  llvm::SmallVector ValuePrintingInfo;
 };
 } // namespace clang
 
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index c9fcef5b5b5af1..9f97a3c6b0be9e 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,7 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
+#ifdef __cplusplus
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
@@ -256,15 +256,18 @@ const char *const Runtimes = R"(
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
 void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
+struct __clang_Interpreter_NewTag{} __ci_newtag;
+void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) 
noexcept;
 template 
 void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
   for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
+new ((void*)(((T*)Placement) + Idx), __ci_newtag) T(Src[Idx]);
 }
 template 
 void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size) {
   __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
 }
+#endif // __cplusplus
 )";
 
 llvm::Expected>
@@ -279,7 +282,7 @@ Interpreter::create(std::unique_ptr CI) {
   if (!PTU)
 return PTU.takeError();
 
-  Interp->ValuePrintingInfo.resize(3);
+  Interp->ValuePrintingInfo.resize(4);
   // FIXME: This is a ugly hack. Undo command checks its availability by 
looking
   // at the size of the PTU list. However we have parsed something in the
   // beginning of the REPL so we have to mark them as 'Irrevocable'.
@@ -500,7 +503,7 @@ Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) {
 static constexpr llvm::StringRef MagicRuntimeInterface[] = {
 "__clang_Interpreter_SetValueNoAlloc",
 "__clang_Interpreter_SetValueWithAlloc",
-"__clang_Interpreter_SetValueCopyArr"};
+"__clang_Interpreter_SetValueCopyArr", "__ci_newtag"};
 
 bool Interpreter::FindRuntimeInterface() {
   if (llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E != nullptr; }))
@@ -530,6 +533,9 @@ bool Interpreter::FindRuntimeInterface() {
   if (!LookupInterface(ValuePrintingInfo[CopyArray],
MagicRuntimeInterface[CopyArray]))
 return false;
+  if (!LookupInterface(ValuePrintingInfo[NewTag],
+   MagicRuntimeInterface[NewTag]))
+return false;
   return true;
 }
 
@@ -607,7 +613,9 @@ class RuntimeInterfaceBuilder
 .getValuePrintingInfo()[Interpreter::InterfaceKind::CopyArray],
 SourceLocation(), Args, SourceLocation());
   }
-  Expr *Args[] = {AllocCall.get()};
+  Expr *Args[] = {
+  AllocCall.get(),
+  Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]};
   ExprResult CXXNewC

[llvm] [clang] [AArch64] Assembly support for the Armv9.5-A Memory System Extensions (PR #76237)

2023-12-22 Thread Lucas Duarte Prates via cfe-commits

https://github.com/pratlucas created 
https://github.com/llvm/llvm-project/pull/76237

This implements assembly support for the Memory Systems Extensions
introduced as part of the Armv9.5-A architecture version.
The changes include:
* New subtarget feature for FEAT_TLBIW.
* New system registers for FEAT_HDBSS:
  * HDBSSBR_EL2 and HDBSSPROD_EL2.
* New system registers for FEAT_HACDBS:
  * HACDBSBR_EL2 and HACDBSCONS_EL2.
* New TLBI instructions for FEAT_TLBIW:
  * VMALLWS2E1(nXS), VMALLWS2E1IS(nXS) and VMALLWS2E1OS(nXS).
* New system register for FEAT_FGWTE3:
  * FGWTE3_EL3.


>From 4f2834cd78430ac69418f307cb54e9e583c7c7fd Mon Sep 17 00:00:00 2001
From: Lucas Prates 
Date: Fri, 22 Dec 2023 12:05:26 +
Subject: [PATCH] [AArch64] Assembly support for the Armv9.5-A Memory System
 Extensions

This implements assembly support for the Memory Systems Extensions
introduced as part of the Armv9.5-A architecture version.
The changes include:
* New subtarget feature for FEAT_TLBIW.
* New system registers for FEAT_HDBSS:
  * HDBSSBR_EL2 and HDBSSPROD_EL2.
* New system registers for FEAT_HACDBS:
  * HACDBSBR_EL2 and HACDBSCONS_EL2.
* New TLBI instructions for FEAT_TLBIW:
  * VMALLWS2E1(nXS), VMALLWS2E1IS(nXS) and VMALLWS2E1OS(nXS).
* New system register for FEAT_FGWTE3:
  * FGWTE3_EL3.
---
 clang/test/Driver/aarch64-v95a.c  |  4 +++
 .../llvm/TargetParser/AArch64TargetParser.h   |  2 ++
 llvm/lib/Target/AArch64/AArch64.td|  3 +++
 .../Target/AArch64/AArch64SystemOperands.td   | 22 +++
 .../AArch64/AsmParser/AArch64AsmParser.cpp|  1 +
 llvm/test/MC/AArch64/armv9.5a-fgwte3.s|  6 +
 llvm/test/MC/AArch64/armv9.5a-hacdbs.s| 12 +
 llvm/test/MC/AArch64/armv9.5a-hdbss.s | 12 +
 llvm/test/MC/AArch64/armv9.5a-tlbiw.s | 27 +++
 .../Disassembler/AArch64/armv9.5a-fgwte3.txt  |  7 +
 .../Disassembler/AArch64/armv9.5a-hacdbs.txt  | 14 ++
 .../Disassembler/AArch64/armv9.5a-hdbss.txt   | 14 ++
 .../Disassembler/AArch64/armv9.5a-tlbiw.txt   | 27 +++
 .../TargetParser/TargetParserTest.cpp |  2 ++
 14 files changed, 153 insertions(+)
 create mode 100644 llvm/test/MC/AArch64/armv9.5a-fgwte3.s
 create mode 100644 llvm/test/MC/AArch64/armv9.5a-hacdbs.s
 create mode 100644 llvm/test/MC/AArch64/armv9.5a-hdbss.s
 create mode 100644 llvm/test/MC/AArch64/armv9.5a-tlbiw.s
 create mode 100644 llvm/test/MC/Disassembler/AArch64/armv9.5a-fgwte3.txt
 create mode 100644 llvm/test/MC/Disassembler/AArch64/armv9.5a-hacdbs.txt
 create mode 100644 llvm/test/MC/Disassembler/AArch64/armv9.5a-hdbss.txt
 create mode 100644 llvm/test/MC/Disassembler/AArch64/armv9.5a-tlbiw.txt

diff --git a/clang/test/Driver/aarch64-v95a.c b/clang/test/Driver/aarch64-v95a.c
index 6fac62e8b389a6..13069c04c8d1c8 100644
--- a/clang/test/Driver/aarch64-v95a.c
+++ b/clang/test/Driver/aarch64-v95a.c
@@ -25,3 +25,7 @@
 // RUN: %clang -target aarch64 -march=armv9.5a+pauth-lr -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-PAUTHLR %s
 // RUN: %clang -target aarch64 -march=armv9.5-a+pauth-lr -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-PAUTHLR %s
 // V95A-PAUTHLR: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+neon" "-target-feature" "+v9.5a" 
"-target-feature" "+pauth-lr"
+
+// RUN: %clang -target aarch64 -march=armv9.5a+tlbiw -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-TLBIW %s
+// RUN: %clang -target aarch64 -march=armv9.5-a+tlbiw -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-TLBIW %s
+// V95A-TLBIW: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+neon" "-target-feature" "+v9.5a" "-target-feature" "+tlbiw"
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 6c7410a8b8f792..53dc2be825f28e 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -175,6 +175,7 @@ enum ArchExtKind : unsigned {
   AEK_SMEFA64 =   71, // FEAT_SME_FA64
   AEK_CPA =   72, // FEAT_CPA
   AEK_PAUTHLR =   73, // FEAT_PAuth_LR
+  AEK_TLBIW = 74, // FEAT_TLBIW
   AEK_NUM_EXTENSIONS
 };
 using ExtensionBitset = Bitset;
@@ -299,6 +300,7 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"sme-fa64",  AArch64::AEK_SMEFA64,  "+sme-fa64", "-sme-fa64",  FEAT_INIT, 
"", 0},
 {"cpa", AArch64::AEK_CPA, "+cpa", "-cpa", FEAT_INIT, "", 0},
 {"pauth-lr", AArch64::AEK_PAUTHLR, "+pauth-lr", "-pauth-lr", FEAT_INIT, 
"", 0},
+{"tlbiw", AArch64::AEK_TLBIW, "+tlbiw", "-tlbiw", FEAT_INIT, "", 0},
 // Special cases
 {"none", AArch64::AEK_NONE, {}, {}, FEAT_INIT, "", 
ExtensionInfo::MaxFMVPriority},
 };
diff --git a/llvm/lib/Target/AArch64/AArch64.td 
b/llvm/lib/Target/AArch64/AArch64.td
index 97e92a57a7ff4b..68f452039c9b68 100644
--- a/llvm/lib/Target/AArch64/AArch64.td
+++ b/llvm/lib/Target/AArch64/AArch64.td
@@

[clang] [llvm] [AArch64] Assembly support for the Armv9.5-A Memory System Extensions (PR #76237)

2023-12-22 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-mc

Author: Lucas Duarte Prates (pratlucas)


Changes

This implements assembly support for the Memory Systems Extensions
introduced as part of the Armv9.5-A architecture version.
The changes include:
* New subtarget feature for FEAT_TLBIW.
* New system registers for FEAT_HDBSS:
  * HDBSSBR_EL2 and HDBSSPROD_EL2.
* New system registers for FEAT_HACDBS:
  * HACDBSBR_EL2 and HACDBSCONS_EL2.
* New TLBI instructions for FEAT_TLBIW:
  * VMALLWS2E1(nXS), VMALLWS2E1IS(nXS) and VMALLWS2E1OS(nXS).
* New system register for FEAT_FGWTE3:
  * FGWTE3_EL3.


---
Full diff: https://github.com/llvm/llvm-project/pull/76237.diff


14 Files Affected:

- (modified) clang/test/Driver/aarch64-v95a.c (+4) 
- (modified) llvm/include/llvm/TargetParser/AArch64TargetParser.h (+2) 
- (modified) llvm/lib/Target/AArch64/AArch64.td (+3) 
- (modified) llvm/lib/Target/AArch64/AArch64SystemOperands.td (+22) 
- (modified) llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp (+1) 
- (added) llvm/test/MC/AArch64/armv9.5a-fgwte3.s (+6) 
- (added) llvm/test/MC/AArch64/armv9.5a-hacdbs.s (+12) 
- (added) llvm/test/MC/AArch64/armv9.5a-hdbss.s (+12) 
- (added) llvm/test/MC/AArch64/armv9.5a-tlbiw.s (+27) 
- (added) llvm/test/MC/Disassembler/AArch64/armv9.5a-fgwte3.txt (+7) 
- (added) llvm/test/MC/Disassembler/AArch64/armv9.5a-hacdbs.txt (+14) 
- (added) llvm/test/MC/Disassembler/AArch64/armv9.5a-hdbss.txt (+14) 
- (added) llvm/test/MC/Disassembler/AArch64/armv9.5a-tlbiw.txt (+27) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+2) 


``diff
diff --git a/clang/test/Driver/aarch64-v95a.c b/clang/test/Driver/aarch64-v95a.c
index 6fac62e8b389a6..13069c04c8d1c8 100644
--- a/clang/test/Driver/aarch64-v95a.c
+++ b/clang/test/Driver/aarch64-v95a.c
@@ -25,3 +25,7 @@
 // RUN: %clang -target aarch64 -march=armv9.5a+pauth-lr -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-PAUTHLR %s
 // RUN: %clang -target aarch64 -march=armv9.5-a+pauth-lr -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-PAUTHLR %s
 // V95A-PAUTHLR: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+neon" "-target-feature" "+v9.5a" 
"-target-feature" "+pauth-lr"
+
+// RUN: %clang -target aarch64 -march=armv9.5a+tlbiw -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-TLBIW %s
+// RUN: %clang -target aarch64 -march=armv9.5-a+tlbiw -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-TLBIW %s
+// V95A-TLBIW: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+neon" "-target-feature" "+v9.5a" "-target-feature" "+tlbiw"
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 6c7410a8b8f792..53dc2be825f28e 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -175,6 +175,7 @@ enum ArchExtKind : unsigned {
   AEK_SMEFA64 =   71, // FEAT_SME_FA64
   AEK_CPA =   72, // FEAT_CPA
   AEK_PAUTHLR =   73, // FEAT_PAuth_LR
+  AEK_TLBIW = 74, // FEAT_TLBIW
   AEK_NUM_EXTENSIONS
 };
 using ExtensionBitset = Bitset;
@@ -299,6 +300,7 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"sme-fa64",  AArch64::AEK_SMEFA64,  "+sme-fa64", "-sme-fa64",  FEAT_INIT, 
"", 0},
 {"cpa", AArch64::AEK_CPA, "+cpa", "-cpa", FEAT_INIT, "", 0},
 {"pauth-lr", AArch64::AEK_PAUTHLR, "+pauth-lr", "-pauth-lr", FEAT_INIT, 
"", 0},
+{"tlbiw", AArch64::AEK_TLBIW, "+tlbiw", "-tlbiw", FEAT_INIT, "", 0},
 // Special cases
 {"none", AArch64::AEK_NONE, {}, {}, FEAT_INIT, "", 
ExtensionInfo::MaxFMVPriority},
 };
diff --git a/llvm/lib/Target/AArch64/AArch64.td 
b/llvm/lib/Target/AArch64/AArch64.td
index 97e92a57a7ff4b..68f452039c9b68 100644
--- a/llvm/lib/Target/AArch64/AArch64.td
+++ b/llvm/lib/Target/AArch64/AArch64.td
@@ -630,6 +630,9 @@ def FeatureCPA : SubtargetFeature<"cpa", "HasCPA", "true",
 def FeaturePAuthLR : SubtargetFeature<"pauth-lr", "HasPAuthLR",
 "true", "Enable Armv9.5-A PAC enhancements (FEAT_PAuth_LR)">;
 
+def FeatureTLBIW : SubtargetFeature<"tlbiw", "HasTLBIW", "true",
+  "Enable ARMv9.5-A TLBI VMALL for Dirty State (FEAT_TLBIW)">;
+
 
//===--===//
 // Architectures.
 //
diff --git a/llvm/lib/Target/AArch64/AArch64SystemOperands.td 
b/llvm/lib/Target/AArch64/AArch64SystemOperands.td
index 28a5776a3089cf..0b80f263e12ee1 100644
--- a/llvm/lib/Target/AArch64/AArch64SystemOperands.td
+++ b/llvm/lib/Target/AArch64/AArch64SystemOperands.td
@@ -643,6 +643,14 @@ defm : TLBI<"PAALLOS",  0b110, 0b1000, 0b0001, 0b100, 
0>;
 defm : TLBI<"PAALL",0b110, 0b1000, 0b0111, 0b100, 0>;
 }
 
+// Armv9.5-A TLBI VMALL for Dirty State
+let Requires = ["AArch64::FeatureTLBIW"] in {
+//   op1,   CRn,CRm,op2,   needsreg
+defm : TLBI<"VMALLWS2E1",0b100, 0b1000,

[clang] [llvm] [AArch64] Assembly support for the Armv9.5-A Memory System Extensions (PR #76237)

2023-12-22 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 86dc6e15f22610bbb53eb4efda0a178ecefc933a 
4f2834cd78430ac69418f307cb54e9e583c7c7fd -- clang/test/Driver/aarch64-v95a.c 
llvm/include/llvm/TargetParser/AArch64TargetParser.h 
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp 
llvm/unittests/TargetParser/TargetParserTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp 
b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
index be66790c42..e490e6f416 100644
--- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -3704,7 +3704,7 @@ static const struct Extension {
 {"sme-lutv2", {AArch64::FeatureSME_LUTv2}},
 {"sme-f8f16", {AArch64::FeatureSMEF8F16}},
 {"sme-f8f32", {AArch64::FeatureSMEF8F32}},
-{"sme-fa64",  {AArch64::FeatureSMEFA64}},
+{"sme-fa64", {AArch64::FeatureSMEFA64}},
 {"cpa", {AArch64::FeatureCPA}},
 {"tlbiw", {AArch64::FeatureTLBIW}},
 };

``




https://github.com/llvm/llvm-project/pull/76237
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [AArch64] Assembly support for the Armv9.5-A Memory System Extensions (PR #76237)

2023-12-22 Thread Rodolfo Wottrich via cfe-commits

https://github.com/rgwott approved this pull request.

Great patch, looks good to me.

https://github.com/llvm/llvm-project/pull/76237
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [AArch64] Assembly support for the Armv9.5-A Memory System Extensions (PR #76237)

2023-12-22 Thread Jonathan Thackray via cfe-commits

https://github.com/jthackray approved this pull request.

Looks great! :)

https://github.com/llvm/llvm-project/pull/76237
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [AArch64] Assembly support for the Armv9.5-A Memory System Extensions (PR #76237)

2023-12-22 Thread Tomas Matheson via cfe-commits

https://github.com/tmatheson-arm approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/76237
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add common attribute macros to Google style (PR #76239)

2023-12-22 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov created 
https://github.com/llvm/llvm-project/pull/76239

We have found that 199fc973ced20016b04ba540cf63a1d4914fa513 regresses 
formatting of our codebases because we do not properly configure the names of 
attribute macros.

`GUARDED_BY` and `ABSL_GUARDED_BY` are very commoon in Google codebases so it 
is reasonable to include them by default to avoid the need for extra 
configuration in every Google repository.

>From 24a33d72af0392e1d2c1908aa727b2d4b6c06d80 Mon Sep 17 00:00:00 2001
From: Ilya Biryukov 
Date: Fri, 22 Dec 2023 14:54:56 +0100
Subject: [PATCH] [clang-format] Add common attribute macros to Google style

We have found that 199fc973ced20016b04ba540cf63a1d4914fa513 regresses
formatting of our codebases because we do not properly configure the
names of attribute macros.

`GUARDED_BY` and `ABSL_GUARDED_BY` are very commoon in Google codebases
so it is reasonable to include them by default to avoid the need for
extra configuration in every Google repository.
---
 clang/lib/Format/Format.cpp   |  3 +++
 clang/unittests/Format/FormatTest.cpp | 27 ---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 28271181e07d0c..f798d555bf9929 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1698,6 +1698,9 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind 
Language) {
   /*BasedOnStyle=*/"google",
   },
   };
+  GoogleStyle.AttributeMacros.push_back("GUARDED_BY");
+  GoogleStyle.AttributeMacros.push_back("ABSL_GUARDED_BY");
+
   GoogleStyle.SpacesBeforeTrailingComments = 2;
   GoogleStyle.Standard = FormatStyle::LS_Auto;
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 0e08723aa9e947..9772c3be71877f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "FormatTestBase.h"
+#include "gmock/gmock.h"
 
 #define DEBUG_TYPE "format-test"
 
@@ -8497,7 +8498,10 @@ TEST_F(FormatTest, 
BreaksFunctionDeclarationsWithTrailingTokens) {
"__attribute__((unused));");
 
   Style = getGoogleStyle();
-  Style.AttributeMacros.push_back("GUARDED_BY");
+  ASSERT_THAT(Style.AttributeMacros,
+  testing::AllOf(testing::Contains("GUARDED_BY"),
+ testing::Contains("ABSL_GUARDED_BY")));
+
   verifyFormat(
   "bool 
a\n"
   "GUARDED_BY();",
@@ -8514,6 +8518,23 @@ TEST_F(FormatTest, 
BreaksFunctionDeclarationsWithTrailingTokens) {
   "bool aa GUARDED_BY() =\n"
   "a;",
   Style);
+
+  verifyFormat(
+  "bool 
a\n"
+  "ABSL_GUARDED_BY();",
+  Style);
+  verifyFormat(
+  "bool a\n"
+  "ABSL_GUARDED_BY();",
+  Style);
+  verifyFormat(
+  "bool aa ABSL_GUARDED_BY() =\n"
+  "::aaa;",
+  Style);
+  verifyFormat(
+  "bool aa ABSL_GUARDED_BY() =\n"
+  "a;",
+  Style);
 }
 
 TEST_F(FormatTest, FunctionAnnotations) {
@@ -10072,11 +10093,11 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
getGoogleStyleWithColumns(40));
   verifyFormat("Tttt ppp\n"
"ABSL_GUARDED_BY(mutex1)\n"
-   "ABSL_GUARDED_BY(mutex2);",
+   "ABSL_GUARDED_BY(mutex2);",
getGoogleStyleWithColumns(40));
   verifyFormat("Tt f(int a, int b)\n"
"ABSL_GUARDED_BY(mutex1)\n"
-   "ABSL_GUARDED_BY(mutex2);",
+   "ABSL_GUARDED_BY(mutex2);",
getGoogleStyleWithColumns(40));
   // * typedefs
   verifyGoogleFormat("typedef ATTR(X) char x;");

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


[clang] [clang-format] Add common attribute macros to Google style (PR #76239)

2023-12-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Ilya Biryukov (ilya-biryukov)


Changes

We have found that 199fc973ced20016b04ba540cf63a1d4914fa513 regresses 
formatting of our codebases because we do not properly configure the names of 
attribute macros.

`GUARDED_BY` and `ABSL_GUARDED_BY` are very commoon in Google codebases so it 
is reasonable to include them by default to avoid the need for extra 
configuration in every Google repository.

---
Full diff: https://github.com/llvm/llvm-project/pull/76239.diff


2 Files Affected:

- (modified) clang/lib/Format/Format.cpp (+3) 
- (modified) clang/unittests/Format/FormatTest.cpp (+24-3) 


``diff
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 28271181e07d0c..f798d555bf9929 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1698,6 +1698,9 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind 
Language) {
   /*BasedOnStyle=*/"google",
   },
   };
+  GoogleStyle.AttributeMacros.push_back("GUARDED_BY");
+  GoogleStyle.AttributeMacros.push_back("ABSL_GUARDED_BY");
+
   GoogleStyle.SpacesBeforeTrailingComments = 2;
   GoogleStyle.Standard = FormatStyle::LS_Auto;
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 0e08723aa9e947..9772c3be71877f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "FormatTestBase.h"
+#include "gmock/gmock.h"
 
 #define DEBUG_TYPE "format-test"
 
@@ -8497,7 +8498,10 @@ TEST_F(FormatTest, 
BreaksFunctionDeclarationsWithTrailingTokens) {
"__attribute__((unused));");
 
   Style = getGoogleStyle();
-  Style.AttributeMacros.push_back("GUARDED_BY");
+  ASSERT_THAT(Style.AttributeMacros,
+  testing::AllOf(testing::Contains("GUARDED_BY"),
+ testing::Contains("ABSL_GUARDED_BY")));
+
   verifyFormat(
   "bool 
a\n"
   "GUARDED_BY();",
@@ -8514,6 +8518,23 @@ TEST_F(FormatTest, 
BreaksFunctionDeclarationsWithTrailingTokens) {
   "bool aa GUARDED_BY() =\n"
   "a;",
   Style);
+
+  verifyFormat(
+  "bool 
a\n"
+  "ABSL_GUARDED_BY();",
+  Style);
+  verifyFormat(
+  "bool a\n"
+  "ABSL_GUARDED_BY();",
+  Style);
+  verifyFormat(
+  "bool aa ABSL_GUARDED_BY() =\n"
+  "::aaa;",
+  Style);
+  verifyFormat(
+  "bool aa ABSL_GUARDED_BY() =\n"
+  "a;",
+  Style);
 }
 
 TEST_F(FormatTest, FunctionAnnotations) {
@@ -10072,11 +10093,11 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
getGoogleStyleWithColumns(40));
   verifyFormat("Tttt ppp\n"
"ABSL_GUARDED_BY(mutex1)\n"
-   "ABSL_GUARDED_BY(mutex2);",
+   "ABSL_GUARDED_BY(mutex2);",
getGoogleStyleWithColumns(40));
   verifyFormat("Tt f(int a, int b)\n"
"ABSL_GUARDED_BY(mutex1)\n"
-   "ABSL_GUARDED_BY(mutex2);",
+   "ABSL_GUARDED_BY(mutex2);",
getGoogleStyleWithColumns(40));
   // * typedefs
   verifyGoogleFormat("typedef ATTR(X) char x;");

``




https://github.com/llvm/llvm-project/pull/76239
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add common attribute macros to Google style (PR #76239)

2023-12-22 Thread Krasimir Georgiev via cfe-commits

https://github.com/krasimirgg approved this pull request.

thank you!

https://github.com/llvm/llvm-project/pull/76239
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] efeb546 - [clang-format] Add common attribute macros to Google style (#76239)

2023-12-22 Thread via cfe-commits

Author: Ilya Biryukov
Date: 2023-12-22T15:07:43+01:00
New Revision: efeb546865c233dfa7706ee0316c676de9f69897

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

LOG: [clang-format] Add common attribute macros to Google style (#76239)

We have found that 199fc973ced20016b04ba540cf63a1d4914fa513 regresses
formatting of our codebases because we do not properly configure the
names of attribute macros.

`GUARDED_BY` and `ABSL_GUARDED_BY` are very commoon in Google codebases
so it is reasonable to include them by default to avoid the need for
extra configuration in every Google repository.

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 28271181e07d0c..f798d555bf9929 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1698,6 +1698,9 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind 
Language) {
   /*BasedOnStyle=*/"google",
   },
   };
+  GoogleStyle.AttributeMacros.push_back("GUARDED_BY");
+  GoogleStyle.AttributeMacros.push_back("ABSL_GUARDED_BY");
+
   GoogleStyle.SpacesBeforeTrailingComments = 2;
   GoogleStyle.Standard = FormatStyle::LS_Auto;
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 0e08723aa9e947..9772c3be71877f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "FormatTestBase.h"
+#include "gmock/gmock.h"
 
 #define DEBUG_TYPE "format-test"
 
@@ -8497,7 +8498,10 @@ TEST_F(FormatTest, 
BreaksFunctionDeclarationsWithTrailingTokens) {
"__attribute__((unused));");
 
   Style = getGoogleStyle();
-  Style.AttributeMacros.push_back("GUARDED_BY");
+  ASSERT_THAT(Style.AttributeMacros,
+  testing::AllOf(testing::Contains("GUARDED_BY"),
+ testing::Contains("ABSL_GUARDED_BY")));
+
   verifyFormat(
   "bool 
a\n"
   "GUARDED_BY();",
@@ -8514,6 +8518,23 @@ TEST_F(FormatTest, 
BreaksFunctionDeclarationsWithTrailingTokens) {
   "bool aa GUARDED_BY() =\n"
   "a;",
   Style);
+
+  verifyFormat(
+  "bool 
a\n"
+  "ABSL_GUARDED_BY();",
+  Style);
+  verifyFormat(
+  "bool a\n"
+  "ABSL_GUARDED_BY();",
+  Style);
+  verifyFormat(
+  "bool aa ABSL_GUARDED_BY() =\n"
+  "::aaa;",
+  Style);
+  verifyFormat(
+  "bool aa ABSL_GUARDED_BY() =\n"
+  "a;",
+  Style);
 }
 
 TEST_F(FormatTest, FunctionAnnotations) {
@@ -10072,11 +10093,11 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
getGoogleStyleWithColumns(40));
   verifyFormat("Tttt ppp\n"
"ABSL_GUARDED_BY(mutex1)\n"
-   "ABSL_GUARDED_BY(mutex2);",
+   "ABSL_GUARDED_BY(mutex2);",
getGoogleStyleWithColumns(40));
   verifyFormat("Tt f(int a, int b)\n"
"ABSL_GUARDED_BY(mutex1)\n"
-   "ABSL_GUARDED_BY(mutex2);",
+   "ABSL_GUARDED_BY(mutex2);",
getGoogleStyleWithColumns(40));
   // * typedefs
   verifyGoogleFormat("typedef ATTR(X) char x;");



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


[clang] [clang-format] Add common attribute macros to Google style (PR #76239)

2023-12-22 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov closed 
https://github.com/llvm/llvm-project/pull/76239
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add an fnmatch-like function for .clang-format-ignore (PR #76021)

2023-12-22 Thread Emilia Kond via cfe-commits

https://github.com/rymiel approved this pull request.

Are we going to use this specific implementation on all platforms for parity?
The logic on its own looks good as far as I can tell, but, for example, POSIX 
Section 2.13 mentions that a leading period (hidden files) isn't matched by `*`.
This sort of divergence from the strict POSIX spec is fine in my opinion, just 
confirming we won't cause parity issues.

https://github.com/llvm/llvm-project/pull/76021
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e4f1c52 - [AArch64] Assembly support for the Armv9.5-A Memory System Extensions (#76237)

2023-12-22 Thread via cfe-commits

Author: Lucas Duarte Prates
Date: 2023-12-22T14:40:29Z
New Revision: e4f1c528326ff1b32ea4b9cdf496312da385cc47

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

LOG: [AArch64] Assembly support for the Armv9.5-A Memory System Extensions 
(#76237)

This implements assembly support for the Memory Systems Extensions
introduced as part of the Armv9.5-A architecture version.
The changes include:
* New subtarget feature for FEAT_TLBIW.
* New system registers for FEAT_HDBSS:
  * HDBSSBR_EL2 and HDBSSPROD_EL2.
* New system registers for FEAT_HACDBS:
  * HACDBSBR_EL2 and HACDBSCONS_EL2.
* New TLBI instructions for FEAT_TLBIW:
  * VMALLWS2E1(nXS), VMALLWS2E1IS(nXS) and VMALLWS2E1OS(nXS).
* New system register for FEAT_FGWTE3:
  * FGWTE3_EL3.

Added: 
llvm/test/MC/AArch64/armv9.5a-fgwte3.s
llvm/test/MC/AArch64/armv9.5a-hacdbs.s
llvm/test/MC/AArch64/armv9.5a-hdbss.s
llvm/test/MC/AArch64/armv9.5a-tlbiw.s
llvm/test/MC/Disassembler/AArch64/armv9.5a-fgwte3.txt
llvm/test/MC/Disassembler/AArch64/armv9.5a-hacdbs.txt
llvm/test/MC/Disassembler/AArch64/armv9.5a-hdbss.txt
llvm/test/MC/Disassembler/AArch64/armv9.5a-tlbiw.txt

Modified: 
clang/test/Driver/aarch64-v95a.c
llvm/include/llvm/TargetParser/AArch64TargetParser.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64SystemOperands.td
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/unittests/TargetParser/TargetParserTest.cpp

Removed: 




diff  --git a/clang/test/Driver/aarch64-v95a.c 
b/clang/test/Driver/aarch64-v95a.c
index 6fac62e8b389a6..13069c04c8d1c8 100644
--- a/clang/test/Driver/aarch64-v95a.c
+++ b/clang/test/Driver/aarch64-v95a.c
@@ -25,3 +25,7 @@
 // RUN: %clang -target aarch64 -march=armv9.5a+pauth-lr -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-PAUTHLR %s
 // RUN: %clang -target aarch64 -march=armv9.5-a+pauth-lr -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-PAUTHLR %s
 // V95A-PAUTHLR: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+neon" "-target-feature" "+v9.5a" 
"-target-feature" "+pauth-lr"
+
+// RUN: %clang -target aarch64 -march=armv9.5a+tlbiw -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-TLBIW %s
+// RUN: %clang -target aarch64 -march=armv9.5-a+tlbiw -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-TLBIW %s
+// V95A-TLBIW: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+neon" "-target-feature" "+v9.5a" "-target-feature" "+tlbiw"

diff  --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 6c7410a8b8f792..53dc2be825f28e 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -175,6 +175,7 @@ enum ArchExtKind : unsigned {
   AEK_SMEFA64 =   71, // FEAT_SME_FA64
   AEK_CPA =   72, // FEAT_CPA
   AEK_PAUTHLR =   73, // FEAT_PAuth_LR
+  AEK_TLBIW = 74, // FEAT_TLBIW
   AEK_NUM_EXTENSIONS
 };
 using ExtensionBitset = Bitset;
@@ -299,6 +300,7 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"sme-fa64",  AArch64::AEK_SMEFA64,  "+sme-fa64", "-sme-fa64",  FEAT_INIT, 
"", 0},
 {"cpa", AArch64::AEK_CPA, "+cpa", "-cpa", FEAT_INIT, "", 0},
 {"pauth-lr", AArch64::AEK_PAUTHLR, "+pauth-lr", "-pauth-lr", FEAT_INIT, 
"", 0},
+{"tlbiw", AArch64::AEK_TLBIW, "+tlbiw", "-tlbiw", FEAT_INIT, "", 0},
 // Special cases
 {"none", AArch64::AEK_NONE, {}, {}, FEAT_INIT, "", 
ExtensionInfo::MaxFMVPriority},
 };

diff  --git a/llvm/lib/Target/AArch64/AArch64.td 
b/llvm/lib/Target/AArch64/AArch64.td
index 97e92a57a7ff4b..68f452039c9b68 100644
--- a/llvm/lib/Target/AArch64/AArch64.td
+++ b/llvm/lib/Target/AArch64/AArch64.td
@@ -630,6 +630,9 @@ def FeatureCPA : SubtargetFeature<"cpa", "HasCPA", "true",
 def FeaturePAuthLR : SubtargetFeature<"pauth-lr", "HasPAuthLR",
 "true", "Enable Armv9.5-A PAC enhancements (FEAT_PAuth_LR)">;
 
+def FeatureTLBIW : SubtargetFeature<"tlbiw", "HasTLBIW", "true",
+  "Enable ARMv9.5-A TLBI VMALL for Dirty State (FEAT_TLBIW)">;
+
 
//===--===//
 // Architectures.
 //

diff  --git a/llvm/lib/Target/AArch64/AArch64SystemOperands.td 
b/llvm/lib/Target/AArch64/AArch64SystemOperands.td
index 28a5776a3089cf..0b80f263e12ee1 100644
--- a/llvm/lib/Target/AArch64/AArch64SystemOperands.td
+++ b/llvm/lib/Target/AArch64/AArch64SystemOperands.td
@@ -643,6 +643,14 @@ defm : TLBI<"PAALLOS",  0b110, 0b1000, 0b0001, 0b100, 
0>;
 defm : TLBI<"PAALL",0b110, 0b1000, 0b0111, 0b100, 0>;
 }
 
+// Armv9.5-A TLBI VMALL for Dirty State
+let Requires = ["AArch64::FeatureTLBIW"] in {
+//   op1,   CRn,CRm,op2,

[clang] [llvm] [AArch64] Assembly support for the Armv9.5-A Memory System Extensions (PR #76237)

2023-12-22 Thread Lucas Duarte Prates via cfe-commits

https://github.com/pratlucas closed 
https://github.com/llvm/llvm-project/pull/76237
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/76059

>From b0080a41c1802517e4a02976058231cf37a82adb Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Fri, 3 Nov 2023 20:58:17 +0900
Subject: [PATCH] [clang-format] Support of TableGen formatting.

Currently, TableGen has its language style but the it does not works
well. This patch adds total support of TableGen formatting including
the support for the code (multi line string), DAG args, bang operators,
the cond operator, and the paste operators.
---
 clang/include/clang/Format/Format.h   |  47 ++
 clang/lib/Format/ContinuationIndenter.cpp |  18 +-
 clang/lib/Format/Format.cpp   |  29 ++
 clang/lib/Format/FormatToken.h|  98 
 clang/lib/Format/FormatTokenLexer.cpp | 142 ++
 clang/lib/Format/FormatTokenLexer.h   |   6 +
 clang/lib/Format/TokenAnnotator.cpp   | 426 +-
 clang/lib/Format/UnwrappedLineParser.cpp  |  54 ++-
 clang/lib/Format/WhitespaceManager.cpp|  31 +-
 clang/lib/Format/WhitespaceManager.h  |  14 +
 clang/unittests/Format/FormatTestTableGen.cpp | 307 +
 clang/unittests/Format/TokenAnnotatorTest.cpp |  50 ++
 12 files changed, 1197 insertions(+), 25 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 8604dea689f937..30a38aed99866e 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -396,6 +396,36 @@ struct FormatStyle {
   /// \version 17
   ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements;
 
+  /// Style of aligning consecutive TableGen cond operator colons.
+  /// \code
+  ///   !cond(!eq(size, 1) : 1,
+  /// !eq(size, 16): 1,
+  /// true : 0)
+  /// \endcode
+  /// \version 18
+  AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons;
+
+  /// Style of aligning consecutive TableGen DAGArg operator colons.
+  /// Intended to be used with TableGenBreakInsideDAGArgList
+  /// \code
+  ///   let dagarg = (ins
+  ///   a  :$src1,
+  ///   aa :$src2,
+  ///   aaa:$src3
+  ///   )
+  /// \endcode
+  /// \version 18
+  AlignConsecutiveStyle AlignConsecutiveTableGenBreakingDAGArgColons;
+
+  /// Style of aligning consecutive TableGen def colons.
+  /// \code
+  ///   def Def   : Parent {}
+  ///   def DefDef: Parent {}
+  ///   def DefDefDef : Parent {}
+  /// \endcode
+  /// \version 18
+  AlignConsecutiveStyle AlignConsecutiveTableGenDefinitions;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle : int8_t {
 /// Don't align escaped newlines.
@@ -3037,6 +3067,7 @@ struct FormatStyle {
   bool isProto() const {
 return Language == LK_Proto || Language == LK_TextProto;
   }
+  bool isTableGen() const { return Language == LK_TableGen; }
 
   /// Language, this format style is targeted at.
   /// \version 3.5
@@ -4656,6 +4687,15 @@ struct FormatStyle {
   /// \version 8
   std::vector StatementMacros;
 
+  /// Tablegen
+  bool TableGenAllowBreakBeforeInheritColon;
+  bool TableGenAllowBreakAfterInheritColon;
+  bool TableGenBreakInsideCondOperator;
+  bool TableGenBreakInsideDAGArgList;
+  bool TableGenPreferBreakInsideSquareBracket;
+  bool TableGenSpaceAroundDAGArgColon;
+  std::vector TableGenBreakingDAGArgOperators;
+
   /// The number of columns used for tab stops.
   /// \version 3.7
   unsigned TabWidth;
@@ -4753,6 +4793,13 @@ struct FormatStyle {
AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
AlignConsecutiveShortCaseStatements ==
R.AlignConsecutiveShortCaseStatements &&
+   AlignConsecutiveTableGenCondOperatorColons ==
+   R.AlignConsecutiveTableGenCondOperatorColons &&
+   AlignConsecutiveTableGenBreakingDAGArgColons ==
+   R.AlignConsecutiveTableGenBreakingDAGArgColons &&
+   AlignConsecutiveTableGenDefinitions ==
+   R.AlignConsecutiveTableGenDefinitions &&
+   AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
AlignEscapedNewlines == R.AlignEscapedNewlines &&
AlignOperands == R.AlignOperands &&
AlignTrailingComments == R.AlignTrailingComments &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index bd319f21b05f86..176dc7744a5576 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -800,6 +800,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (

[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2023-12-22 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/76226

>From 08a2bb64e19fe244361cb58a1e8eed64a2c1f0cd Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 22 Dec 2023 17:56:32 +0800
Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve
 StructuralEquivalence on recordType

---
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 ++---
 .../AST/StructuralEquivalenceTest.cpp | 22 +++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7..7c04c09bb80874 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1107,11 +1107,20 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   }
 
   case Type::Record:
-  case Type::Enum:
-if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(),
-  cast(T2)->getDecl()))
+  case Type::Enum: {
+auto *D1 = cast(T1)->getDecl();
+auto *D2 = cast(T2)->getDecl();
+if (!IsStructurallyEquivalent(Context, D1, D2))
+  return false;
+auto *D1Spec =
+
dyn_cast_or_null(D1->getDeclContext());
+auto *D2Spec =
+
dyn_cast_or_null(D2->getDeclContext());
+if (nullptr != D1Spec && nullptr != D2Spec &&
+!IsStructurallyEquivalent(Context, D1Spec, D2Spec))
   return false;
 break;
+  }
 
   case Type::TemplateTypeParm: {
 const auto *Parm1 = cast(T1);
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 44d950cfe758f1..b54d149152e105 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, 
TransparentContextInNamespace) {
   EXPECT_TRUE(testStructuralMatch(Decls));
 }
 
+TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) {
+  std::string Code =
+  R"(
+  template  struct O {
+struct M {};
+  };
+  )";
+  auto t = makeDecls(Code + R"(
+  typedef O::M MT1;
+  MT1 A;
+  )",
+  Code + R"(
+  namespace {
+struct I {};
+  } // namespace
+  typedef O::M MT2;
+  MT2 A;
+  )",
+  Lang_CXX11, varDecl(hasName("A")));
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) {
   auto Decls = makeNamedDecls(
   R"(

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


[clang] [clang][analyzer] Improve modeling of `fileno` in the StreamChecker (PR #76207)

2023-12-22 Thread Ben Shi via cfe-commits

https://github.com/benshi001 closed 
https://github.com/llvm/llvm-project/pull/76207
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [flang] [llvm] [compiler-rt] [clang] [lldb] [libc] [libcxx] [RegAllocFast] Refactor dominates algorithm for large basic block (PR #72250)

2023-12-22 Thread via cfe-commits

https://github.com/HaohaiWen closed 
https://github.com/llvm/llvm-project/pull/72250
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits

https://github.com/rymiel edited https://github.com/llvm/llvm-project/pull/76059
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits




rymiel wrote:

Your edits in Format.h won't show up in the documentation until after you've 
run the script in `clang/docs/tools/dump_format_style.py`

https://github.com/llvm/llvm-project/pull/76059
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -111,6 +111,9 @@ const tooling::Replacements 
&WhitespaceManager::generateReplacements() {
   alignConsecutiveDeclarations();
   alignConsecutiveBitFields();
   alignConsecutiveAssignments();
+  alignConsecutiveTableGenCondOperatorColons();
+  AlignConsecutiveTableGenBreakingDAGArgColons();
+  alignConsecutiveTableGenDefinition();

rymiel wrote:

Shouldn't these replacements be guarded behind an `isTableGen`? At the very 
least, `alignConsecutiveTableGenDefinition` aligns on TT_InheritanceColon and 
that can appear in non-tablegen code too

https://github.com/llvm/llvm-project/pull/76059
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits

https://github.com/rymiel commented:

Hi, this is quite a big patch. I had a very quick look and noticed a few 
nit-picky thingy, mostly about formatting or naming and whatnot, mostly minor 
things.
However since I've never used tablegen, I'm not sure if I can actually review 
any of the logic in here, but I'll try to have another look later

https://github.com/llvm/llvm-project/pull/76059
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -111,6 +111,9 @@ const tooling::Replacements 
&WhitespaceManager::generateReplacements() {
   alignConsecutiveDeclarations();
   alignConsecutiveBitFields();
   alignConsecutiveAssignments();
+  alignConsecutiveTableGenCondOperatorColons();
+  AlignConsecutiveTableGenBreakingDAGArgColons();

rymiel wrote:

This one has different capitalization from all the others

https://github.com/llvm/llvm-project/pull/76059
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -40,6 +40,13 @@ class FormatTestTableGen : public ::testing::Test {
 EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable";
 EXPECT_EQ(Code.str(), format(test::messUp(Code)));
   }
+
+  static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {

rymiel wrote:

It seems like this file was never brought up to date with all the other tests 
when f8d10d5ac9ab4b45b388c74357fc82fb96562e66 happened

https://github.com/llvm/llvm-project/pull/76059
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -4753,6 +4793,13 @@ struct FormatStyle {
AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
AlignConsecutiveShortCaseStatements ==
R.AlignConsecutiveShortCaseStatements &&
+   AlignConsecutiveTableGenCondOperatorColons ==
+   R.AlignConsecutiveTableGenCondOperatorColons &&
+   AlignConsecutiveTableGenBreakingDAGArgColons ==
+   R.AlignConsecutiveTableGenBreakingDAGArgColons &&
+   AlignConsecutiveTableGenDefinitions ==
+   R.AlignConsecutiveTableGenDefinitions &&
+   AlignConsecutiveMacros == R.AlignConsecutiveMacros &&

rymiel wrote:

Small copy paste error, I'm assuming, AlignConsecutiveMacros has already been 
checked.
Also, these options should be alphabetical in order

https://github.com/llvm/llvm-project/pull/76059
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -1124,6 +1130,20 @@ template <> struct MappingTraits {
 IO.mapOptional("StatementAttributeLikeMacros",
Style.StatementAttributeLikeMacros);
 IO.mapOptional("StatementMacros", Style.StatementMacros);
+IO.mapOptional("TableGenAllowBreakAfterInheritColon",
+   Style.TableGenAllowBreakAfterInheritColon);
+IO.mapOptional("TableGenAllowBreakBeforeInheritColon",
+   Style.TableGenAllowBreakBeforeInheritColon);
+IO.mapOptional("TableGenBreakInsideCondOperator",
+   Style.TableGenBreakInsideCondOperator);
+IO.mapOptional("TableGenBreakInsideDAGArgList",
+   Style.TableGenBreakInsideDAGArgList);
+IO.mapOptional("TableGenPreferBreakInsideSquareBracket",
+   Style.TableGenPreferBreakInsideSquareBracket);
+IO.mapOptional("TableGenSpaceAroundDAGArgColon",
+   Style.TableGenSpaceAroundDAGArgColon);
+IO.mapOptional("TableGenBreakingDAGArgOperators",
+   Style.TableGenBreakingDAGArgOperators);

rymiel wrote:

I'm a little confused by these undocumented style options?

https://github.com/llvm/llvm-project/pull/76059
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -272,6 +276,38 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
+  if (Style.isTableGen()) {
+if (tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+  Tokens.back()->Tok.setKind(tok::string_literal);
+  return;
+}
+if (Tokens.size() > 1 && Tokens.end()[-2]->is(tok::exclaim)) {
+  if (Tokens.back()->is(tok::identifier) ||
+  (Tokens.back()->is(tok::kw_if) && Tokens.back())) {
+  }
+}

rymiel wrote:

This if statement does nothing, or am I misunderstanding it?

https://github.com/llvm/llvm-project/pull/76059
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [libcxx] [clang] [clang-tools-extra] [libc] [llvm] [compiler-rt] [flang] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

2023-12-22 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/71222

>From e0d99fb5baa4231ab351f7fd5abf0a1ffe589547 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:55:06 +
Subject: [PATCH 01/17] FDATE extension implementation: get date and time in
 ctime format

reference to gfortran fdate https://gcc.gnu.org/onlinedocs/gfortran/FDATE.html
usage:
CHARACTER(32) :: time
CALL fdate(time)
WRITE(*,*) time
---
 flang/docs/Intrinsics.md |  2 +-
 flang/include/flang/Runtime/command.h|  5 +
 flang/include/flang/Runtime/extensions.h |  2 ++
 flang/runtime/command.cpp| 28 
 flang/runtime/extensions.cpp |  5 +
 flang/unittests/Runtime/CommandTest.cpp  | 14 
 6 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e553..982be820816429 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, FDATE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec628939054547..07f6d8e169ead6 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -23,6 +23,11 @@ extern "C" {
 // integer kind.
 std::int32_t RTNAME(ArgumentCount)();
 
+// Try to get the the current date (same format as CTIME: convert to a string)
+// Return a STATUS as described in the standard.
+std::int32_t RTNAME(FDate)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 // 16.9.82 GET_COMMAND
 // Try to get the value of the whole command. All of the parameters are
 // optional.
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb7..92b9907860121a 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -24,6 +24,8 @@ void FORTRAN_PROCEDURE_NAME(flush)(const int &unit);
 // GNU Fortran 77 compatibility function IARGC.
 std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 
+void FORTRAN_PROCEDURE_NAME(fdate)(std::int8_t *string, std::int64_t length);
+
 // GNU Fortran 77 compatibility subroutine GETARG(N, ARG).
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571..da0803c39f49b6 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -14,6 +14,7 @@
 #include "flang/Runtime/descriptor.h"
 #include 
 #include 
+#include 
 
 namespace Fortran::runtime {
 std::int32_t RTNAME(ArgumentCount)() {
@@ -125,6 +126,33 @@ static bool FitsInDescriptor(
   kind, terminator, value);
 }
 
+void removeNewLine(char *str) {
+  char *newlinePos = strchr(str, '\n');
+  if (newlinePos != NULL) {
+*newlinePos = '\0'; // Replace with null terminator
+  }
+}
+
+std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
+  FillWithSpaces(*value);
+
+  time_t current_time;
+  time(¤t_time);
+
+  char *time_string = ctime(¤t_time);
+  removeNewLine(time_string);
+  std::int64_t stringLen{StringLength(time_string)};
+  if (stringLen <= 0) {
+return ToErrmsg(errmsg, StatMissingArgument);
+  }
+
+  if (value) {
+return CopyToDescriptor(*value, time_string, stringLen, errmsg);
+  }
+
+  return StatOk;
+}
+
 std::int32_t RTNAME(GetCommandArgument)(std::int32_t n, const Descriptor 
*value,
 const Descriptor *length, const Descriptor *errmsg, const char *sourceFile,
 int line) {
diff --git a/flang/runtime/e

[clang-tools-extra] [llvm] [CodeGen][DebugInfo] Add missing DebugLoc for SplitCriticalEdge (PR #72192)

2023-12-22 Thread via cfe-commits

https://github.com/HaohaiWen updated 
https://github.com/llvm/llvm-project/pull/72192

>From 9df51ffb48d3da8654d857508f0edbcfa0d48245 Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Mon, 13 Nov 2023 21:57:30 +0800
Subject: [PATCH] [CodeGen][DebugInfo] Add missing DebugLoc for
 SplitCriticalEdge

In SplitCriticalEdge, DebugLoc of the branch instruction in new created
MBB was set to empty. It should be set and we can find proper DebugLoc
for it in most cases. This patch set it to non empty merged DebugLoc of
current MBB branches.
---
 llvm/lib/CodeGen/MachineBasicBlock.cpp | 10 +-
 llvm/test/CodeGen/X86/fsafdo_test1.ll  |  2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp 
b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index d9e22685faf5f5..9c6a77f34314f4 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1137,7 +1137,6 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
 
   MachineFunction *MF = getParent();
   MachineBasicBlock *PrevFallthrough = getNextNode();
-  DebugLoc DL;  // FIXME: this is nowhere
 
   MachineBasicBlock *NMBB = MF->CreateMachineBasicBlock();
   NMBB->setCallFrameSize(Succ->getCallFrameSize());
@@ -1218,6 +1217,15 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
 SlotIndexUpdateDelegate SlotUpdater(*MF, Indexes);
 SmallVector Cond;
 const TargetInstrInfo *TII = getParent()->getSubtarget().getInstrInfo();
+
+// In original 'this' BB, there must be a branch instruction targeting at
+// Succ. We can not find it out since currently getBranchDestBlock was not
+// implemented for all targets. However, if the merged DL has column or 
line
+// number, the scope and non-zero column and line number is same with that
+// branch instruction so we can safely use it.
+DebugLoc DL, MergedDL = findBranchDebugLoc();
+if (MergedDL && (MergedDL.getLine() || MergedDL.getCol()))
+  DL = MergedDL;
 TII->insertBranch(*NMBB, Succ, nullptr, Cond, DL);
   }
 
diff --git a/llvm/test/CodeGen/X86/fsafdo_test1.ll 
b/llvm/test/CodeGen/X86/fsafdo_test1.ll
index b5ae3915294cd7..61c0f59aba6f81 100644
--- a/llvm/test/CodeGen/X86/fsafdo_test1.ll
+++ b/llvm/test/CodeGen/X86/fsafdo_test1.ll
@@ -6,7 +6,7 @@
 ; V01: .loc1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5
 ; V0: .loc1 9 5 is_stmt 0 discriminator 11266 # foo.c:9:5
 ; V0: .loc1 7 3 is_stmt 1 discriminator 11266 # foo.c:7:3
-; V1: .loc1 9 5 is_stmt 0 discriminator 258 # foo.c:9:5
+; V1: .loc1 9 5 is_stmt 0 discriminator 514 # foo.c:9:5
 ; V1: .loc1 7 3 is_stmt 1 discriminator 258 # foo.c:7:3
 ; Check that variable __llvm_fs_discriminator__ is generated.
 ; V01: .type   __llvm_fs_discriminator__,@object # @__llvm_fs_discriminator__

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


[lldb] [mlir] [libunwind] [libcxx] [clang] [clang-tools-extra] [openmp] [lld] [libc] [llvm] [compiler-rt] [flang] [OpenMP] Improve omp offload profiler (PR #68016)

2023-12-22 Thread Felipe Cabarcas via cfe-commits

https://github.com/fel-cab updated 
https://github.com/llvm/llvm-project/pull/68016

>From dd44de067c26ba94b6561c5ed7fa4a5d812a3d1a Mon Sep 17 00:00:00 2001
From: Felipe Cabarcas 
Date: Mon, 18 Sep 2023 12:07:12 +
Subject: [PATCH 01/14] testing Profiler features

---
 openmp/libomptarget/src/interface.cpp | 5 -
 openmp/libomptarget/src/private.h | 3 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/openmp/libomptarget/src/interface.cpp 
b/openmp/libomptarget/src/interface.cpp
index 5f21b16b3fbfb1..f64e1e268a3952 100644
--- a/openmp/libomptarget/src/interface.cpp
+++ b/openmp/libomptarget/src/interface.cpp
@@ -252,7 +252,10 @@ static inline int targetKernel(ident_t *Loc, int64_t 
DeviceId, int32_t NumTeams,
   static_assert(std::is_convertible_v,
 "Target AsyncInfoTy must be convertible to AsyncInfoTy.");
 
-  TIMESCOPE_WITH_IDENT(Loc);
+  //TIMESCOPE_WITH_IDENT(Loc);
+  TIMESCOPE();
+  //TIMESCOPE_WITH_NAME_AND_IDENT("Hello", Loc);
+  //TIMESCOPE_WITH_RTM_AND_IDENT("Hello", Loc);
 
   DP("Entering target region for device %" PRId64 " with entry point " DPxMOD
  "\n",
diff --git a/openmp/libomptarget/src/private.h 
b/openmp/libomptarget/src/private.h
index cbce15b63a3eba..dc6cd394423395 100644
--- a/openmp/libomptarget/src/private.h
+++ b/openmp/libomptarget/src/private.h
@@ -433,7 +433,8 @@ class ExponentialBackoff {
   SourceInfo SI(IDENT);
\
   std::string ProfileLocation = SI.getProfileLocation();   
\
   std::string RTM = RegionTypeMsg; 
\
-  llvm::TimeTraceScope TimeScope(__FUNCTION__, ProfileLocation + RTM)
+  llvm::TimeTraceScope TimeScope(ProfileLocation, ProfileLocation + RTM)
+  //llvm::TimeTraceScope TimeScope(__FUNCTION__, ProfileLocation + RTM)
 #else
 #define TIMESCOPE()
 #define TIMESCOPE_WITH_IDENT(IDENT)

>From 92586bca6364100c7511ad38a30f41b0f86dea9c Mon Sep 17 00:00:00 2001
From: Felipe Cabarcas 
Date: Tue, 19 Sep 2023 12:02:53 +
Subject: [PATCH 02/14] Improve Profiler 1

---
 llvm/lib/Support/TimeProfiler.cpp |  2 +-
 openmp/libomptarget/src/interface.cpp | 17 +
 openmp/libomptarget/src/omptarget.cpp | 10 +-
 openmp/libomptarget/src/private.h |  5 +++--
 4 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/llvm/lib/Support/TimeProfiler.cpp 
b/llvm/lib/Support/TimeProfiler.cpp
index 4d625b3eb5b170..e1458116f64ab4 100644
--- a/llvm/lib/Support/TimeProfiler.cpp
+++ b/llvm/lib/Support/TimeProfiler.cpp
@@ -227,7 +227,7 @@ struct llvm::TimeTraceProfiler {
 J.attribute("ph", "X");
 J.attribute("ts", 0);
 J.attribute("dur", DurUs);
-J.attribute("name", "Total " + Total.first);
+J.attribute("name", "Total: " + Total.first);
 J.attributeObject("args", [&] {
   J.attribute("count", int64_t(Count));
   J.attribute("avg ms", int64_t(DurUs / Count / 1000));
diff --git a/openmp/libomptarget/src/interface.cpp 
b/openmp/libomptarget/src/interface.cpp
index f64e1e268a3952..b8892cbe689107 100644
--- a/openmp/libomptarget/src/interface.cpp
+++ b/openmp/libomptarget/src/interface.cpp
@@ -33,14 +33,14 @@ using namespace llvm::omp::target::ompt;
 

 /// adds requires flags
 EXTERN void __tgt_register_requires(int64_t Flags) {
-  TIMESCOPE();
+  //TIMESCOPE();
   PM->RTLs.registerRequires(Flags);
 }
 
 

 /// adds a target shared library to the target execution image
 EXTERN void __tgt_register_lib(__tgt_bin_desc *Desc) {
-  TIMESCOPE();
+  //TIMESCOPE();
   if (PM->maybeDelayRegisterLib(Desc))
 return;
 
@@ -61,7 +61,7 @@ EXTERN void __tgt_init_all_rtls() { PM->RTLs.initAllRTLs(); }
 

 /// unloads a target shared library
 EXTERN void __tgt_unregister_lib(__tgt_bin_desc *Desc) {
-  TIMESCOPE();
+  //TIMESCOPE();
   PM->RTLs.unregisterLib(Desc);
   for (auto &RTL : PM->RTLs.UsedRTLs) {
 if (RTL->unregister_lib) {
@@ -82,7 +82,8 @@ targetData(ident_t *Loc, int64_t DeviceId, int32_t ArgNum, 
void **ArgsBase,
   static_assert(std::is_convertible_v,
 "TargetAsyncInfoTy must be convertible to AsyncInfoTy.");
 
-  TIMESCOPE_WITH_RTM_AND_IDENT(RegionTypeMsg, Loc);
+  //TIMESCOPE_WITH_RTM_AND_IDENT(RegionTypeMsg, Loc);
+  TIMESCOPE_WITH_RTM_AND_IDENT("targetData", Loc);
 
   DP("Entering data %s region for device %" PRId64 " with %d mappings\n",
  RegionName, DeviceId, ArgNum);
@@ -253,9 +254,9 @@ static inline int targetKernel(ident_t *Loc, int64_t 
DeviceId, int32_t NumTeams,
 "Target AsyncInfoTy must be convertible to AsyncInfoTy.");
 
   //TIMESCOPE_WITH_IDENT(Loc);
-  TIMESCOPE();
+  //TIMESCOPE();
   //TIMESCOPE_WITH_NAME_AND_IDENT("Hello", Loc);
-  //TIME

[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-22 Thread Tyler Rockwood via cfe-commits

https://github.com/rockwotj updated 
https://github.com/llvm/llvm-project/pull/76101

>From fff68e1854d16a166088d7199af09a7aeb19b4c4 Mon Sep 17 00:00:00 2001
From: Tyler Rockwood 
Date: Thu, 21 Dec 2023 16:31:12 -0600
Subject: [PATCH] clang-tidy/bugprone: introduce
 unused-local-non-trivial-variable check

Signed-off-by: Tyler Rockwood 
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../UnusedLocalNonTrivialVariableCheck.cpp| 86 ++
 .../UnusedLocalNonTrivialVariableCheck.h  | 44 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../unused-local-non-trivial-variable.rst | 45 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../unused-local-non-trivial-variable.cpp | 87 +++
 8 files changed, 272 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 7a910037368c83..435cb1e3fbcff3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -83,6 +83,7 @@
 #include "UnhandledSelfAssignmentCheck.h"
 #include "UniquePtrArrayMismatchCheck.h"
 #include "UnsafeFunctionsCheck.h"
+#include "UnusedLocalNonTrivialVariableCheck.h"
 #include "UnusedRaiiCheck.h"
 #include "UnusedReturnValueCheck.h"
 #include "UseAfterMoveCheck.h"
@@ -235,6 +236,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-unique-ptr-array-mismatch");
 CheckFactories.registerCheck(
 "bugprone-unsafe-functions");
+CheckFactories.registerCheck(
+"bugprone-unused-local-non-trivial-variable");
 CheckFactories.registerCheck("bugprone-unused-raii");
 CheckFactories.registerCheck(
 "bugprone-unused-return-value");
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index d443fd8d1452f1..70e7fbc7ec0c14 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -79,6 +79,7 @@ add_clang_library(clangTidyBugproneModule
   UnhandledSelfAssignmentCheck.cpp
   UniquePtrArrayMismatchCheck.cpp
   UnsafeFunctionsCheck.cpp
+  UnusedLocalNonTrivialVariableCheck.cpp
   UnusedRaiiCheck.cpp
   UnusedReturnValueCheck.cpp
   UseAfterMoveCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
new file mode 100644
index 00..5ad3bb03c58a60
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
@@ -0,0 +1,86 @@
+//===--- UnusedLocalNonTrivialVariableCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UnusedLocalNonTrivialVariableCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+static constexpr StringRef DefaultIncludeTypeRegex =
+"::std::.*mutex;::std::future;::std::string;::std::regex";
+
+AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
+AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
+AST_MATCHER(Type, isReferenceType) { return Node.isReferenceType(); }
+AST_MATCHER(QualType, isTrivial) {
+  return Node.isTrivialType(Finder->getASTContext()) ||
+ Node.isTriviallyCopyableType(Finder->getASTContext());
+}
+} // namespace
+
+UnusedLocalNonTrivialVariableCheck::UnusedLocalNonTrivialVariableCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeTypes(utils::options::parseStringList(
+  Options.get("IncludeTypes", DefaultIncludeTypeRegex))),
+  ExcludeTypes(
+  utils::options::parseStringList(Options.get("ExcludeTypes", ""))) {}
+
+void UnusedLocalNonTrivialV

[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-22 Thread Tyler Rockwood via cfe-commits


@@ -0,0 +1,89 @@
+//===--- UnusedLocalNonTrivialVariableCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UnusedLocalNonTrivialVariableCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+static constexpr StringRef DefaultIncludeTypeRegex = 
"std::.*mutex;std::future";
+
+AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
+AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
+AST_MATCHER(Type, isReferenceType) { return Node.isReferenceType(); }
+} // namespace
+
+UnusedLocalNonTrivialVariableCheck::UnusedLocalNonTrivialVariableCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeTypeRegex(utils::options::parseStringList(
+  Options.get("IncludeTypeRegex", DefaultIncludeTypeRegex))),

rockwotj wrote:

Done.

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-22 Thread Tyler Rockwood via cfe-commits


@@ -0,0 +1,89 @@
+//===--- UnusedLocalNonTrivialVariableCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UnusedLocalNonTrivialVariableCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+static constexpr StringRef DefaultIncludeTypeRegex = 
"std::.*mutex;std::future";
+
+AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
+AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
+AST_MATCHER(Type, isReferenceType) { return Node.isReferenceType(); }
+} // namespace
+
+UnusedLocalNonTrivialVariableCheck::UnusedLocalNonTrivialVariableCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeTypeRegex(utils::options::parseStringList(
+  Options.get("IncludeTypeRegex", DefaultIncludeTypeRegex))),
+  ExcludeTypeRegex(utils::options::parseStringList(
+  Options.get("ExcludeTypeRegex", ""))) {}
+
+void UnusedLocalNonTrivialVariableCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeTypeRegex",
+utils::options::serializeStringList(IncludeTypeRegex));
+  Options.store(Opts, "ExcludeTypeRegex",
+utils::options::serializeStringList(ExcludeTypeRegex));
+}
+
+void UnusedLocalNonTrivialVariableCheck::registerMatchers(MatchFinder *Finder) 
{
+  if (IncludeTypeRegex.empty())
+return;
+
+  Finder->addMatcher(
+  varDecl(
+  isLocalVarDecl(), unless(isReferenced()),
+  unless(isExpansionInSystemHeader()), unless(isImplicit()),

rockwotj wrote:

Thanks, done.

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-22 Thread Tyler Rockwood via cfe-commits


@@ -0,0 +1,29 @@
+.. title:: clang-tidy - bugprone-unused-local-non-trivial-variable
+
+bugprone-unused-local-non-trivial-variable
+==
+
+Warns when a local non trivial variable is unused within a function.
+
+In the following example, `future2` would generate a warning that it is unused.
+
+.. code-block:: c++
+

rockwotj wrote:

Took a shot at this. PTAL.

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-22 Thread Tyler Rockwood via cfe-commits


@@ -0,0 +1,89 @@
+//===--- UnusedLocalNonTrivialVariableCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UnusedLocalNonTrivialVariableCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+static constexpr StringRef DefaultIncludeTypeRegex = 
"std::.*mutex;std::future";

rockwotj wrote:

Added std::string and std::regex, let me know if you think of others.

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-22 Thread Tyler Rockwood via cfe-commits


@@ -149,6 +149,7 @@ Clang-Tidy Checks
:doc:`bugprone-unhandled-self-assignment 
`,
:doc:`bugprone-unique-ptr-array-mismatch 
`, "Yes"
:doc:`bugprone-unsafe-functions `,
+   :doc:`bugprone-unused-local-non-trivial-variable 
`, "Yes"

rockwotj wrote:

Done, thanks.

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-22 Thread Tyler Rockwood via cfe-commits


@@ -0,0 +1,89 @@
+//===--- UnusedLocalNonTrivialVariableCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UnusedLocalNonTrivialVariableCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+static constexpr StringRef DefaultIncludeTypeRegex = 
"std::.*mutex;std::future";
+
+AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
+AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
+AST_MATCHER(Type, isReferenceType) { return Node.isReferenceType(); }
+} // namespace
+
+UnusedLocalNonTrivialVariableCheck::UnusedLocalNonTrivialVariableCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeTypeRegex(utils::options::parseStringList(
+  Options.get("IncludeTypeRegex", DefaultIncludeTypeRegex))),
+  ExcludeTypeRegex(utils::options::parseStringList(
+  Options.get("ExcludeTypeRegex", ""))) {}
+
+void UnusedLocalNonTrivialVariableCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeTypeRegex",
+utils::options::serializeStringList(IncludeTypeRegex));
+  Options.store(Opts, "ExcludeTypeRegex",
+utils::options::serializeStringList(ExcludeTypeRegex));
+}
+
+void UnusedLocalNonTrivialVariableCheck::registerMatchers(MatchFinder *Finder) 
{
+  if (IncludeTypeRegex.empty())
+return;
+
+  Finder->addMatcher(
+  varDecl(
+  isLocalVarDecl(), unless(isReferenced()),
+  unless(isExpansionInSystemHeader()), unless(isImplicit()),
+  unless(isExceptionVariable()), hasLocalStorage(), isDefinition(),
+  unless(hasType(isReferenceType())),
+  hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+  recordDecl(matchesAnyListedName(IncludeTypeRegex)),
+  unless(hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+  recordDecl(matchesAnyListedName(ExcludeTypeRegex

rockwotj wrote:

Done, thanks!

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-22 Thread Tyler Rockwood via cfe-commits


@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy %s bugprone-unused-local-non-trivial-variable %t -- \
+// RUN:   -config="{CheckOptions: 
{bugprone-unused-local-non-trivial-variable.IncludeTypeRegex: 
'::async::Future'}}"
+
+
+namespace async {
+template 
+class Ptr {
+  public:
+  explicit Ptr(T Arg) : Underlying(new T(Arg)) {}
+  T& operator->() {
+return Underlying;
+  }
+  ~Ptr() {
+delete Underlying;
+  }
+  private:
+T* Underlying;
+};
+
+template
+class Future {
+public:
+T get() {
+return Pending;
+}
+~Future();
+private:
+T Pending;
+};
+
+
+} // namespace async
+
+// Warning is still emitted if there are type aliases.
+namespace a {
+template
+using Future = async::Future;
+} // namespace a
+
+void releaseUnits();
+struct Units {
+  ~Units() {
+releaseUnits();
+  }
+};
+a::Future acquireUnits();
+
+template
+T qux(T Generic) {
+async::Future PendingA = acquireUnits();
+auto PendingB = acquireUnits();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: unused local variable 
'PendingB' of type 'a::Future' (aka 'Future') 
[bugprone-unused-local-non-trivial-variable]
+async::Future MustBeUsed;
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: unused local variable 
'MustBeUsed' of type 'async::Future' 
[bugprone-unused-local-non-trivial-variable]
+PendingA.get();
+return Generic;
+}
+
+async::Future Global;
+
+int bar(int Num) {
+a::Future PendingA = acquireUnits();
+a::Future PendingB = acquireUnits(); // not used at all, unused 
variable not fired because of destructor side effect
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: unused local variable 
'PendingB' of type 'a::Future' (aka 'Future') 
[bugprone-unused-local-non-trivial-variable]
+auto Num2 = PendingA.get();
+auto Num3 = qux(Num);
+async::Ptr> Shared = 
async::Ptr>(acquireUnits());
+static auto UnusedStatic = async::Future();
+thread_local async::Future UnusedThreadLocal;
+auto Captured = acquireUnits();
+Num3 += [Captured]() {
+  return 1;
+}();
+a::Future Referenced = acquireUnits();
+a::Future* Pointer = &Referenced;
+a::Future& Reference = Referenced;
+const a::Future& ConstReference = Referenced;
+return Num * Num3;
+}

rockwotj wrote:

Done.

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-22 Thread Tyler Rockwood via cfe-commits


@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy %s bugprone-unused-local-non-trivial-variable %t -- \
+// RUN:   -config="{CheckOptions: 
{bugprone-unused-local-non-trivial-variable.IncludeTypeRegex: 
'::async::Future'}}"
+
+
+namespace async {
+template 
+class Ptr {
+  public:
+  explicit Ptr(T Arg) : Underlying(new T(Arg)) {}
+  T& operator->() {
+return Underlying;
+  }
+  ~Ptr() {
+delete Underlying;
+  }
+  private:
+T* Underlying;
+};
+
+template
+class Future {
+public:
+T get() {
+return Pending;
+}
+~Future();
+private:
+T Pending;
+};
+
+
+} // namespace async
+
+// Warning is still emitted if there are type aliases.
+namespace a {
+template
+using Future = async::Future;
+} // namespace a
+
+void releaseUnits();
+struct Units {
+  ~Units() {
+releaseUnits();
+  }
+};
+a::Future acquireUnits();
+
+template
+T qux(T Generic) {
+async::Future PendingA = acquireUnits();
+auto PendingB = acquireUnits();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: unused local variable 
'PendingB' of type 'a::Future' (aka 'Future') 
[bugprone-unused-local-non-trivial-variable]
+async::Future MustBeUsed;
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: unused local variable 
'MustBeUsed' of type 'async::Future' 
[bugprone-unused-local-non-trivial-variable]
+PendingA.get();
+return Generic;
+}
+
+async::Future Global;
+
+int bar(int Num) {
+a::Future PendingA = acquireUnits();
+a::Future PendingB = acquireUnits(); // not used at all, unused 
variable not fired because of destructor side effect
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: unused local variable 
'PendingB' of type 'a::Future' (aka 'Future') 
[bugprone-unused-local-non-trivial-variable]
+auto Num2 = PendingA.get();
+auto Num3 = qux(Num);
+async::Ptr> Shared = 
async::Ptr>(acquireUnits());
+static auto UnusedStatic = async::Future();
+thread_local async::Future UnusedThreadLocal;
+auto Captured = acquireUnits();
+Num3 += [Captured]() {
+  return 1;
+}();
+a::Future Referenced = acquireUnits();
+a::Future* Pointer = &Referenced;
+a::Future& Reference = Referenced;
+const a::Future& ConstReference = Referenced;
+return Num * Num3;
+}

rockwotj wrote:

Done.

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

2023-12-22 Thread via cfe-commits

https://github.com/r4nt created https://github.com/llvm/llvm-project/pull/76245

1. There are multiple calls to addFakeParenthesis; move the guard to not
   assign fake parenthesis into the function to make sure we cover all
   calls.
2. MustBreakBefore can be set on a token in two cases: either during
   unwrapped line parsing, or later, during token annotation. We must
   keep the latter, but reset the former.
3. Added a test to document that the intended behavior of preferring not to
   break between a return type and a function identifier.
   For example, with MOCK_METHOD(r, n, a)=r n a, the code
   MOCK_METHOD(void, f, (int a, int b)) should prefer the same breaks as
   the expanded void f(int a, int b).


>From 52cb11f0279dbd9f65f15e81f44869cfac00d544 Mon Sep 17 00:00:00 2001
From: Manuel Klimek 
Date: Thu, 2 Mar 2023 14:00:35 +
Subject: [PATCH] [ClangFormat] Fix formatting bugs.

1. There are multiple calls to addFakeParenthesis; move the guard to not
   assign fake parenthesis into the function to make sure we cover all
   calls.
2. MustBreakBefore can be set on a token in two cases: either during
   unwrapped line parsing, or later, during token annotation. We must
   keep the latter, but reset the former.
3. Added a test to document that the intended behavior of preferring not to
   break between a return type and a function identifier.
   For example, with MOCK_METHOD(r, n, a)=r n a, the code
   MOCK_METHOD(void, f, (int a, int b)) should prefer the same breaks as
   the expanded void f(int a, int b).
---
 clang/lib/Format/FormatToken.h| 26 +
 clang/lib/Format/TokenAnnotator.cpp   | 13 +++
 clang/lib/Format/UnwrappedLineFormatter.cpp   | 10 +++--
 clang/lib/Format/UnwrappedLineParser.cpp  |  2 +
 .../Format/FormatTestMacroExpansion.cpp   | 38 +++
 5 files changed, 70 insertions(+), 19 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 3f9664f8f78a3e..b1e3ae8ab303d6 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -275,14 +275,15 @@ class AnnotatedLine;
 struct FormatToken {
   FormatToken()
   : HasUnescapedNewline(false), IsMultiline(false), IsFirst(false),
-MustBreakBefore(false), IsUnterminatedLiteral(false),
-CanBreakBefore(false), ClosesTemplateDeclaration(false),
-StartsBinaryExpression(false), EndsBinaryExpression(false),
-PartOfMultiVariableDeclStmt(false), ContinuesLineCommentSection(false),
-Finalized(false), ClosesRequiresClause(false),
-EndsCppAttributeGroup(false), BlockKind(BK_Unknown),
-Decision(FD_Unformatted), PackingKind(PPK_Inconclusive),
-TypeIsFinalized(false), Type(TT_Unknown) {}
+MustBreakBefore(false), MustBreakBeforeFinalized(false),
+IsUnterminatedLiteral(false), CanBreakBefore(false),
+ClosesTemplateDeclaration(false), StartsBinaryExpression(false),
+EndsBinaryExpression(false), PartOfMultiVariableDeclStmt(false),
+ContinuesLineCommentSection(false), Finalized(false),
+ClosesRequiresClause(false), EndsCppAttributeGroup(false),
+BlockKind(BK_Unknown), Decision(FD_Unformatted),
+PackingKind(PPK_Inconclusive), TypeIsFinalized(false),
+Type(TT_Unknown) {}
 
   /// The \c Token.
   Token Tok;
@@ -318,6 +319,10 @@ struct FormatToken {
   /// before the token.
   unsigned MustBreakBefore : 1;
 
+  /// Whether MustBreakBefore is finalized during parsing and must not
+  /// be reset between runs.
+  unsigned MustBreakBeforeFinalized : 1;
+
   /// Set to \c true if this token is an unterminated literal.
   unsigned IsUnterminatedLiteral : 1;
 
@@ -416,10 +421,15 @@ struct FormatToken {
   /// to another one please use overwriteFixedType, or even better remove the
   /// need to reassign the type.
   void setFinalizedType(TokenType T) {
+if (MacroCtx && MacroCtx->Role == MR_UnexpandedArg)
+  return;
+
 Type = T;
 TypeIsFinalized = true;
   }
   void overwriteFixedType(TokenType T) {
+if (MacroCtx && MacroCtx->Role == MR_UnexpandedArg)
+  return;
 TypeIsFinalized = false;
 setType(T);
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f3551af3424396..c26b248a3b2d40 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2769,13 +2769,6 @@ class ExpressionParser {
   // Consume operators with higher precedence.
   parse(Precedence + 1);
 
-  // Do not assign fake parenthesis to tokens that are part of an
-  // unexpanded macro call. The line within the macro call contains
-  // the parenthesis and commas, and we will not find operators within
-  // that structure.
-  if (Current && Current->MacroParent)
-break;
-
   int CurrentPrecedence = getCurrentPrecedence();
 
   if (Precedence == CurrentPrecedence && Current &&
@@ -2919,6 +2912,12 

[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

2023-12-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (r4nt)


Changes

1. There are multiple calls to addFakeParenthesis; move the guard to not
   assign fake parenthesis into the function to make sure we cover all
   calls.
2. MustBreakBefore can be set on a token in two cases: either during
   unwrapped line parsing, or later, during token annotation. We must
   keep the latter, but reset the former.
3. Added a test to document that the intended behavior of preferring not to
   break between a return type and a function identifier.
   For example, with MOCK_METHOD(r, n, a)=r n a, the code
   MOCK_METHOD(void, f, (int a, int b)) should prefer the same breaks as
   the expanded void f(int a, int b).


---
Full diff: https://github.com/llvm/llvm-project/pull/76245.diff


5 Files Affected:

- (modified) clang/lib/Format/FormatToken.h (+18-8) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+6-7) 
- (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+6-4) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+2) 
- (modified) clang/unittests/Format/FormatTestMacroExpansion.cpp (+38) 


``diff
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 3f9664f8f78a3e..b1e3ae8ab303d6 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -275,14 +275,15 @@ class AnnotatedLine;
 struct FormatToken {
   FormatToken()
   : HasUnescapedNewline(false), IsMultiline(false), IsFirst(false),
-MustBreakBefore(false), IsUnterminatedLiteral(false),
-CanBreakBefore(false), ClosesTemplateDeclaration(false),
-StartsBinaryExpression(false), EndsBinaryExpression(false),
-PartOfMultiVariableDeclStmt(false), ContinuesLineCommentSection(false),
-Finalized(false), ClosesRequiresClause(false),
-EndsCppAttributeGroup(false), BlockKind(BK_Unknown),
-Decision(FD_Unformatted), PackingKind(PPK_Inconclusive),
-TypeIsFinalized(false), Type(TT_Unknown) {}
+MustBreakBefore(false), MustBreakBeforeFinalized(false),
+IsUnterminatedLiteral(false), CanBreakBefore(false),
+ClosesTemplateDeclaration(false), StartsBinaryExpression(false),
+EndsBinaryExpression(false), PartOfMultiVariableDeclStmt(false),
+ContinuesLineCommentSection(false), Finalized(false),
+ClosesRequiresClause(false), EndsCppAttributeGroup(false),
+BlockKind(BK_Unknown), Decision(FD_Unformatted),
+PackingKind(PPK_Inconclusive), TypeIsFinalized(false),
+Type(TT_Unknown) {}
 
   /// The \c Token.
   Token Tok;
@@ -318,6 +319,10 @@ struct FormatToken {
   /// before the token.
   unsigned MustBreakBefore : 1;
 
+  /// Whether MustBreakBefore is finalized during parsing and must not
+  /// be reset between runs.
+  unsigned MustBreakBeforeFinalized : 1;
+
   /// Set to \c true if this token is an unterminated literal.
   unsigned IsUnterminatedLiteral : 1;
 
@@ -416,10 +421,15 @@ struct FormatToken {
   /// to another one please use overwriteFixedType, or even better remove the
   /// need to reassign the type.
   void setFinalizedType(TokenType T) {
+if (MacroCtx && MacroCtx->Role == MR_UnexpandedArg)
+  return;
+
 Type = T;
 TypeIsFinalized = true;
   }
   void overwriteFixedType(TokenType T) {
+if (MacroCtx && MacroCtx->Role == MR_UnexpandedArg)
+  return;
 TypeIsFinalized = false;
 setType(T);
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f3551af3424396..c26b248a3b2d40 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2769,13 +2769,6 @@ class ExpressionParser {
   // Consume operators with higher precedence.
   parse(Precedence + 1);
 
-  // Do not assign fake parenthesis to tokens that are part of an
-  // unexpanded macro call. The line within the macro call contains
-  // the parenthesis and commas, and we will not find operators within
-  // that structure.
-  if (Current && Current->MacroParent)
-break;
-
   int CurrentPrecedence = getCurrentPrecedence();
 
   if (Precedence == CurrentPrecedence && Current &&
@@ -2919,6 +2912,12 @@ class ExpressionParser {
 
   void addFakeParenthesis(FormatToken *Start, prec::Level Precedence,
   FormatToken *End = nullptr) {
+// Do not assign fake parenthesis to tokens that are part of an
+// unexpanded macro call. The line within the macro call contains
+// the parenthesis and commas, and we will not find operators within
+// that structure.
+if (Start->MacroParent) return;
+
 Start->FakeLParens.push_back(Precedence);
 if (Precedence > prec::Unknown)
   Start->StartsBinaryExpression = true;
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 56077499c39d53..27983a330ac40a 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/cla

[clang] [Sema] Fix crash on invalid code with parenthesized aggregate initialization (PR #76232)

2023-12-22 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

This is missing a release note.

https://github.com/llvm/llvm-project/pull/76232
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [IR] Fix GEP offset computations for vector GEPs (PR #75448)

2023-12-22 Thread Nikita Popov via cfe-commits

nikic wrote:

> > Alternative would be to forbid GEP indexing into vectors entirely.
> 
> I agree that it would be better if there just were no vector GEPs, but that 
> breaks importing older modules, and that cannot be easily auto-upgraded 
> (convert to byte-GEPs?).

Yes, upgrade would be to byte-GEPs.

> Even worse, DXIL uses different vector semantics where alignment in vectors 
> is respected, so importing DXIL already is a challenge, but if vector GEPs in 
> DXIL were to be replaced by byte-GEPs as part of auto-upgrade, preserving 
> DXIL semantics becomes difficult.

Would probably need a bitcode parser hook for the conversion of GEP indices to 
offsets. You'll have to deal with this problem at some point anyway, once we 
start upgrading *all* GEPs to byte-GEPs in the not-so-distant future.

https://github.com/llvm/llvm-project/pull/75448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [IR] Fix GEP offset computations for vector GEPs (PR #75448)

2023-12-22 Thread Nikita Popov via cfe-commits

https://github.com/nikic approved this pull request.

LGTM

I think this is a reasonable change in any case.

https://github.com/llvm/llvm-project/pull/75448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >