[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-06-02 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From ba9b31041671099434570c6d3301782bc41c2c4a Mon Sep 17 00:00:00 2001
From: cqwrteur <100043421+trcrsi...@users.noreply.github.com>
Date: Sat, 1 Jun 2024 02:55:50 -0400
Subject: [PATCH] [libunwind][libcxx][libcxxabi] Fix Exception Handling build
 for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change

Merge remote-tracking branch 'parent/main' into wasmlibunwindfix

remove unwanted changes in unwind-wasm.c

Make Unwind-wasm.c compile correctly without workaround in
CMakeLists.txt

using __wasm__ macro to guard against all wasm eh build

fix UnwindLevel.c's formatting issue

ISO C requires a translation unit to contain at least one declaration 
[-Werror,-Wempty-translation-unit]

compiler-rt does not define CMP_RESULT correct on wasm64
Fixed

Merge code
---
 compiler-rt/lib/builtins/fp_compare_impl.inc |   2 +-
 libcxx/include/__exception/exception_ptr.h   |  21 +-
 libcxxabi/include/cxxabi.h   | 179 ++---
 libcxxabi/src/cxa_exception.cpp  | 712 ---
 libcxxabi/src/cxa_exception.h|   7 +-
 libunwind/include/libunwind.h|   2 +
 libunwind/src/Unwind-wasm.c  |  13 +-
 libunwind/src/UnwindRegistersRestore.S   |   3 +-
 libunwind/src/UnwindRegistersSave.S  |   3 +
 libunwind/src/assembly.h |   2 +
 libunwind/src/cet_unwind.h   |   3 +
 libunwind/src/config.h   |  15 +-
 libunwind/src/libunwind.cpp  |   2 +
 libunwind/src/libunwind_ext.h|   2 +
 14 files changed, 423 insertions(+), 543 deletions(-)

diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe..83bdea46a45da 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -12,7 +12,7 @@
 // functions. We need to ensure that the return value is sign-extended in the
 // same way as GCC expects (since otherwise GCC-generated __builtin_isinf
 // returns true for finite 128-bit floating-point numbers).
-#ifdef __aarch64__
+#if defined(__aarch64__) || defined(__wasm__)
 // AArch64 GCC overrides libgcc_cmp_return to use int instead of long.
 typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 0a8337fa39de3..01f340a587ec3 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -29,22 +29,21 @@
 
 namespace __cxxabiv1 {
 
+#if defined(__wasm__)
+typedef void* (*__libcpp_exception_destructor_func)(void*);
+#elif defined(_WIN32)
+typedef void(__thiscall* __libcpp_exception_destructor_func)(void*);
+#else
+typedef void (*__libcpp_exception_destructor_func)(void*);
+#endif
+
 extern "C" {
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
 
 struct __cxa_exception;
-_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
-void*,
-std::type_info*,
-#if defined(_WIN32)
-void(__thiscall*)(void*)) throw();
-#elif defined(__wasm__)
-// In Wasm, a destructor returns its argument
-void* (*)(void*)) throw();
-#else
-void (*)(void*)) throw();
-#endif
+_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception*
+__cxa_init_primary_exception(void*, std::type_info*, 
__libcpp_exception_destructor_func) throw();
 }
 
 } // namespace __cxxabiv1
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index 0e3969084e04f..4162fd7ec2ba7 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -20,62 +20,51 @@
 #include <__cxxabi_config.h>
 
 #define _LIBCPPABI_VERSION 15000
-#define _LIBCXXABI_NORETURN  __attribute__((noreturn))
+#define _LIBCXXABI_NORETURN __attribute__((noreturn))
 #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
 
 #ifdef __cplusplus
 
 namespace std {
-#if defined(_WIN32)
+#  if defined(_WIN32)
 class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
-#else
+#  else
 class type_info; // forward declaration
-#endif
-}
-
+#  endif
+} // namespace std
 
 // runtime routines use C calling conventions, but are in __cxxabiv1 namespace
 namespace __cxxabiv1 {
 
 struct __cxa_exception;
+#  if defined(__wasm__)
+typedef void*

[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-06-02 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From 4f1ce895254dd9505150c1f5f5cb77454b9aca68 Mon Sep 17 00:00:00 2001
From: cqwrteur <100043421+trcrsi...@users.noreply.github.com>
Date: Sat, 1 Jun 2024 02:55:50 -0400
Subject: [PATCH] [libunwind][libcxx][libcxxabi] Fix Exception Handling build
 for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change

Merge remote-tracking branch 'parent/main' into wasmlibunwindfix

remove unwanted changes in unwind-wasm.c

Make Unwind-wasm.c compile correctly without workaround in
CMakeLists.txt

using __wasm__ macro to guard against all wasm eh build

fix UnwindLevel.c's formatting issue

ISO C requires a translation unit to contain at least one declaration 
[-Werror,-Wempty-translation-unit]

compiler-rt does not define CMP_RESULT correct on wasm64
Fixed

Merge code
---
 compiler-rt/lib/builtins/fp_compare_impl.inc |   2 +-
 libcxx/include/__exception/exception_ptr.h   |  21 +-
 libcxxabi/include/cxxabi.h   | 179 ++---
 libcxxabi/src/cxa_exception.cpp  | 712 ---
 libcxxabi/src/cxa_exception.h|   7 +-
 libunwind/include/libunwind.h|   2 +
 libunwind/src/Unwind-wasm.c  |  13 +-
 libunwind/src/UnwindRegistersRestore.S   |   3 +-
 libunwind/src/UnwindRegistersSave.S  |   3 +
 libunwind/src/assembly.h |   2 +
 libunwind/src/cet_unwind.h   |   3 +
 libunwind/src/config.h   |  15 +-
 libunwind/src/libunwind.cpp  |   2 +
 libunwind/src/libunwind_ext.h|   2 +
 14 files changed, 423 insertions(+), 543 deletions(-)

diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe..83bdea46a45da 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -12,7 +12,7 @@
 // functions. We need to ensure that the return value is sign-extended in the
 // same way as GCC expects (since otherwise GCC-generated __builtin_isinf
 // returns true for finite 128-bit floating-point numbers).
-#ifdef __aarch64__
+#if defined(__aarch64__) || defined(__wasm__)
 // AArch64 GCC overrides libgcc_cmp_return to use int instead of long.
 typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 0a8337fa39de3..01f340a587ec3 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -29,22 +29,21 @@
 
 namespace __cxxabiv1 {
 
+#if defined(__wasm__)
+typedef void* (*__libcpp_exception_destructor_func)(void*);
+#elif defined(_WIN32)
+typedef void(__thiscall* __libcpp_exception_destructor_func)(void*);
+#else
+typedef void (*__libcpp_exception_destructor_func)(void*);
+#endif
+
 extern "C" {
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
 
 struct __cxa_exception;
-_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
-void*,
-std::type_info*,
-#if defined(_WIN32)
-void(__thiscall*)(void*)) throw();
-#elif defined(__wasm__)
-// In Wasm, a destructor returns its argument
-void* (*)(void*)) throw();
-#else
-void (*)(void*)) throw();
-#endif
+_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception*
+__cxa_init_primary_exception(void*, std::type_info*, 
__libcpp_exception_destructor_func) throw();
 }
 
 } // namespace __cxxabiv1
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index 0e3969084e04f..4162fd7ec2ba7 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -20,62 +20,51 @@
 #include <__cxxabi_config.h>
 
 #define _LIBCPPABI_VERSION 15000
-#define _LIBCXXABI_NORETURN  __attribute__((noreturn))
+#define _LIBCXXABI_NORETURN __attribute__((noreturn))
 #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
 
 #ifdef __cplusplus
 
 namespace std {
-#if defined(_WIN32)
+#  if defined(_WIN32)
 class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
-#else
+#  else
 class type_info; // forward declaration
-#endif
-}
-
+#  endif
+} // namespace std
 
 // runtime routines use C calling conventions, but are in __cxxabiv1 namespace
 namespace __cxxabiv1 {
 
 struct __cxa_exception;
+#  if defined(__wasm__)
+typedef void*

[clang] [z/OS] Set the default arch for z/OS to be arch10 (PR #89854)

2024-06-02 Thread Dimitri John Ledkov via cfe-commits

xnox wrote:

Requiring a config file when previously was not needed is a regression in 
behaviour for distributions.

I guess Ubuntu would have to continue to patch this back in.

Built-in defaults exist for a reason and yes at times need to be higher.

This change risks performance regressions for RHEL SUSE and Ubuntu. Please call 
out this change in release notes.

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


[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-02 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/93113

>From d1507bf2be71940c795925cdc8159cbc90b17f0d Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 23 May 2024 01:48:06 +0200
Subject: [PATCH] [Clang] Fix __is_trivially_equality_comparable returning true
 with ineligebile defaulted overloads

---
 clang/docs/ReleaseNotes.rst|  3 ++
 clang/include/clang/AST/Type.h |  3 --
 clang/lib/AST/Type.cpp | 60 ---
 clang/lib/Sema/SemaExprCXX.cpp | 78 +-
 clang/test/SemaCXX/type-traits.cpp | 43 
 5 files changed, 123 insertions(+), 64 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 22b4dc172c840..fabc0fdbcc551 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -640,6 +640,9 @@ Bug Fixes in This Version
 - Correctly reject declarations where a statement is required in C.
   Fixes #GH92775
 
+- ``__is_trivially_equality_comparable`` no longer returns true for types which
+  have a constrained defaulted comparison operator (#GH89293).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 263b632df23ce..53d2ae2905a56 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1126,9 +1126,6 @@ class QualType {
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext &Context) const;
 
-  /// Return true if this is a trivially equality comparable type.
-  bool isTriviallyEqualityComparableType(const ASTContext &Context) const;
-
   /// Returns true if it is a class and it might be dynamic.
   bool mayBeDynamicClass() const;
 
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 2097b29b7e0b6..6121612687f55 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2778,66 +2778,6 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext &Context) const {
   }
 }
 
-static bool
-HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
-  if (Decl->isUnion())
-return false;
-  if (Decl->isLambda())
-return Decl->isCapturelessLambda();
-
-  auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
-return Function->getOverloadedOperator() ==
-   OverloadedOperatorKind::OO_EqualEqual &&
-   Function->isDefaulted() && Function->getNumParams() > 0 &&
-   (Function->getParamDecl(0)->getType()->isReferenceType() ||
-Decl->isTriviallyCopyable());
-  };
-
-  if (llvm::none_of(Decl->methods(), IsDefaultedOperatorEqualEqual) &&
-  llvm::none_of(Decl->friends(), [&](const FriendDecl *Friend) {
-if (NamedDecl *ND = Friend->getFriendDecl()) {
-  return ND->isFunctionOrFunctionTemplate() &&
- IsDefaultedOperatorEqualEqual(ND->getAsFunction());
-}
-return false;
-  }))
-return false;
-
-  return llvm::all_of(Decl->bases(),
-  [](const CXXBaseSpecifier &BS) {
-if (const auto *RD = 
BS.getType()->getAsCXXRecordDecl())
-  return HasNonDeletedDefaultedEqualityComparison(RD);
-return true;
-  }) &&
- llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
-   auto Type = FD->getType();
-   if (Type->isArrayType())
- Type = 
Type->getBaseElementTypeUnsafe()->getCanonicalTypeUnqualified();
-
-   if (Type->isReferenceType() || Type->isEnumeralType())
- return false;
-   if (const auto *RD = Type->getAsCXXRecordDecl())
- return HasNonDeletedDefaultedEqualityComparison(RD);
-   return true;
- });
-}
-
-bool QualType::isTriviallyEqualityComparableType(
-const ASTContext &Context) const {
-  QualType CanonicalType = getCanonicalType();
-  if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType() ||
-  CanonicalType->isEnumeralType() || CanonicalType->isArrayType())
-return false;
-
-  if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
-if (!HasNonDeletedDefaultedEqualityComparison(RD))
-  return false;
-  }
-
-  return Context.hasUniqueObjectRepresentations(
-  CanonicalType, /*CheckIfTriviallyCopyable=*/false);
-}
-
 bool QualType::isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const {
   return !Context.getLangOpts().ObjCAutoRefCount &&
  Context.getLangOpts().ObjCWeak &&
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4487c618862c5..f4461ecf44a37 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5197,6 +5197,82 @@ static bool HasNoThrowOperator(const RecordType *RT, 
OverloadedOperatorKind Op,
   return false;
 }
 
+static bool
+HasNonDeletedDefaultedEqualityComparison(Sema 

[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 created 
https://github.com/llvm/llvm-project/pull/94159

Resolves #93066

>From 9c90d4a83a913566d782774700a06dd640722dfd Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 2 Jun 2024 18:33:37 +0530
Subject: [PATCH] [clang] Fix-it hint for `++this` -> `++*this` when deref is
 modifiable

Resolves #93066
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaExpr.cpp  | 15 +--
 clang/test/Sema/debug-93066.cpp  | 14 ++
 3 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Sema/debug-93066.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 270b0a1e01307..0f5445296e45f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8777,6 +8777,9 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : 
Error<
 def err_typecheck_lvalue_casts_not_supported : Error<
   "assignment to cast is illegal, lvalue casts are not supported">;
 
+def note_typecheck_expression_not_modifiable_lvalue : Note<
+  "dereference the pointer to modify">; 
+
 def err_typecheck_duplicate_vector_components_not_mlvalue : Error<
   "vector is not assignable (contains duplicate components)">;
 def err_block_decl_ref_not_modifiable_lvalue : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ff9c5ead36dcf..39e7962fcb2a6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13587,10 +13587,21 @@ static bool CheckForModifiableLvalue(Expr *E, 
SourceLocation Loc, Sema &S) {
   SourceRange Assign;
   if (Loc != OrigLoc)
 Assign = SourceRange(OrigLoc, OrigLoc);
-  if (NeedType)
+  if (NeedType) {
 S.Diag(Loc, DiagID) << E->getType() << E->getSourceRange() << Assign;
-  else
+  } else {
+ExprResult Deref;
+unsigned FixitDiagID = 0;
+{
+  Sema::TentativeAnalysisScope Trap(S);
+  Deref = S.ActOnUnaryOp(S.getCurScope(), Loc, tok::star, E);
+}
 S.Diag(Loc, DiagID) << E->getSourceRange() << Assign;
+if (Deref.isUsable() && Deref.get()->isModifiableLvalue(S.Context, &Loc) 
== Expr::MLV_Valid) {
+  FixitDiagID = diag::note_typecheck_expression_not_modifiable_lvalue;
+  S.Diag(Loc, FixitDiagID) << E->getSourceRange() << Assign;
+}
+  }
   return true;
 }
 
diff --git a/clang/test/Sema/debug-93066.cpp b/clang/test/Sema/debug-93066.cpp
new file mode 100644
index 0..7abedcd0d4d80
--- /dev/null
+++ b/clang/test/Sema/debug-93066.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+
+struct S {
+  void f() {
+++this;
+// expected-error@-1 {{expression is not assignable}}
+// expected-note@-2 {{dereference the pointer to modify}}
+  }
+
+  void g() const {
+++this;
+// expected-error@-1 {{expression is not assignable}}
+  }
+};

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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rajveer Singh Bharadwaj (Rajveer100)


Changes

Resolves #93066

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


3 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+13-2) 
- (added) clang/test/Sema/debug-93066.cpp (+14) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 270b0a1e01307..0f5445296e45f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8777,6 +8777,9 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : 
Error<
 def err_typecheck_lvalue_casts_not_supported : Error<
   "assignment to cast is illegal, lvalue casts are not supported">;
 
+def note_typecheck_expression_not_modifiable_lvalue : Note<
+  "dereference the pointer to modify">; 
+
 def err_typecheck_duplicate_vector_components_not_mlvalue : Error<
   "vector is not assignable (contains duplicate components)">;
 def err_block_decl_ref_not_modifiable_lvalue : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ff9c5ead36dcf..39e7962fcb2a6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13587,10 +13587,21 @@ static bool CheckForModifiableLvalue(Expr *E, 
SourceLocation Loc, Sema &S) {
   SourceRange Assign;
   if (Loc != OrigLoc)
 Assign = SourceRange(OrigLoc, OrigLoc);
-  if (NeedType)
+  if (NeedType) {
 S.Diag(Loc, DiagID) << E->getType() << E->getSourceRange() << Assign;
-  else
+  } else {
+ExprResult Deref;
+unsigned FixitDiagID = 0;
+{
+  Sema::TentativeAnalysisScope Trap(S);
+  Deref = S.ActOnUnaryOp(S.getCurScope(), Loc, tok::star, E);
+}
 S.Diag(Loc, DiagID) << E->getSourceRange() << Assign;
+if (Deref.isUsable() && Deref.get()->isModifiableLvalue(S.Context, &Loc) 
== Expr::MLV_Valid) {
+  FixitDiagID = diag::note_typecheck_expression_not_modifiable_lvalue;
+  S.Diag(Loc, FixitDiagID) << E->getSourceRange() << Assign;
+}
+  }
   return true;
 }
 
diff --git a/clang/test/Sema/debug-93066.cpp b/clang/test/Sema/debug-93066.cpp
new file mode 100644
index 0..7abedcd0d4d80
--- /dev/null
+++ b/clang/test/Sema/debug-93066.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+
+struct S {
+  void f() {
+++this;
+// expected-error@-1 {{expression is not assignable}}
+// expected-note@-2 {{dereference the pointer to modify}}
+  }
+
+  void g() const {
+++this;
+// expected-error@-1 {{expression is not assignable}}
+  }
+};

``




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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

cc @Sirraide 

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


[clang] [llvm] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/94159

>From e637dc83ec205f7e4dde356b8f5d06ce3abc899e Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 2 Jun 2024 18:33:37 +0530
Subject: [PATCH] [clang] Fix-it hint for `++this` -> `++*this` when deref is
 modifiable

Resolves #93066
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaExpr.cpp  | 16 ++--
 clang/test/Sema/debug-93066.cpp  | 14 ++
 debug-84072.cpp  | 16 
 4 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Sema/debug-93066.cpp
 create mode 100644 debug-84072.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 270b0a1e01307..0f5445296e45f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8777,6 +8777,9 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : 
Error<
 def err_typecheck_lvalue_casts_not_supported : Error<
   "assignment to cast is illegal, lvalue casts are not supported">;
 
+def note_typecheck_expression_not_modifiable_lvalue : Note<
+  "dereference the pointer to modify">; 
+
 def err_typecheck_duplicate_vector_components_not_mlvalue : Error<
   "vector is not assignable (contains duplicate components)">;
 def err_block_decl_ref_not_modifiable_lvalue : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ff9c5ead36dcf..62cbc8a3a6a45 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13587,10 +13587,22 @@ static bool CheckForModifiableLvalue(Expr *E, 
SourceLocation Loc, Sema &S) {
   SourceRange Assign;
   if (Loc != OrigLoc)
 Assign = SourceRange(OrigLoc, OrigLoc);
-  if (NeedType)
+  if (NeedType) {
 S.Diag(Loc, DiagID) << E->getType() << E->getSourceRange() << Assign;
-  else
+  } else {
+ExprResult Deref;
+unsigned FixitDiagID = 0;
+{
+  Sema::TentativeAnalysisScope Trap(S);
+  Deref = S.ActOnUnaryOp(S.getCurScope(), Loc, tok::star, E);
+}
 S.Diag(Loc, DiagID) << E->getSourceRange() << Assign;
+if (Deref.isUsable() &&
+Deref.get()->isModifiableLvalue(S.Context, &Loc) == Expr::MLV_Valid) {
+  FixitDiagID = diag::note_typecheck_expression_not_modifiable_lvalue;
+  S.Diag(Loc, FixitDiagID) << E->getSourceRange() << Assign;
+}
+  }
   return true;
 }
 
diff --git a/clang/test/Sema/debug-93066.cpp b/clang/test/Sema/debug-93066.cpp
new file mode 100644
index 0..7abedcd0d4d80
--- /dev/null
+++ b/clang/test/Sema/debug-93066.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+
+struct S {
+  void f() {
+++this;
+// expected-error@-1 {{expression is not assignable}}
+// expected-note@-2 {{dereference the pointer to modify}}
+  }
+
+  void g() const {
+++this;
+// expected-error@-1 {{expression is not assignable}}
+  }
+};
diff --git a/debug-84072.cpp b/debug-84072.cpp
new file mode 100644
index 0..c024f50019f8c
--- /dev/null
+++ b/debug-84072.cpp
@@ -0,0 +1,16 @@
+void Func(int x) {
+switch (x) {
+[[likely]] case 0:
+case 1:
+int i = 3;
+case 2:
+break;
+}
+switch (x) {
+case 0:
+case 1:
+int i = 3;
+case 2:
+break;
+}
+}

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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/94159

>From 95ce40b0336cda8c5a352d8abb824906b1d643d9 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 2 Jun 2024 18:33:37 +0530
Subject: [PATCH] [clang] Fix-it hint for `++this` -> `++*this` when deref is
 modifiable

Resolves #93066
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaExpr.cpp  | 16 ++--
 clang/test/Sema/debug-93066.cpp  | 14 ++
 3 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Sema/debug-93066.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 270b0a1e01307..0f5445296e45f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8777,6 +8777,9 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : 
Error<
 def err_typecheck_lvalue_casts_not_supported : Error<
   "assignment to cast is illegal, lvalue casts are not supported">;
 
+def note_typecheck_expression_not_modifiable_lvalue : Note<
+  "dereference the pointer to modify">; 
+
 def err_typecheck_duplicate_vector_components_not_mlvalue : Error<
   "vector is not assignable (contains duplicate components)">;
 def err_block_decl_ref_not_modifiable_lvalue : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ff9c5ead36dcf..62cbc8a3a6a45 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13587,10 +13587,22 @@ static bool CheckForModifiableLvalue(Expr *E, 
SourceLocation Loc, Sema &S) {
   SourceRange Assign;
   if (Loc != OrigLoc)
 Assign = SourceRange(OrigLoc, OrigLoc);
-  if (NeedType)
+  if (NeedType) {
 S.Diag(Loc, DiagID) << E->getType() << E->getSourceRange() << Assign;
-  else
+  } else {
+ExprResult Deref;
+unsigned FixitDiagID = 0;
+{
+  Sema::TentativeAnalysisScope Trap(S);
+  Deref = S.ActOnUnaryOp(S.getCurScope(), Loc, tok::star, E);
+}
 S.Diag(Loc, DiagID) << E->getSourceRange() << Assign;
+if (Deref.isUsable() &&
+Deref.get()->isModifiableLvalue(S.Context, &Loc) == Expr::MLV_Valid) {
+  FixitDiagID = diag::note_typecheck_expression_not_modifiable_lvalue;
+  S.Diag(Loc, FixitDiagID) << E->getSourceRange() << Assign;
+}
+  }
   return true;
 }
 
diff --git a/clang/test/Sema/debug-93066.cpp b/clang/test/Sema/debug-93066.cpp
new file mode 100644
index 0..7abedcd0d4d80
--- /dev/null
+++ b/clang/test/Sema/debug-93066.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+
+struct S {
+  void f() {
+++this;
+// expected-error@-1 {{expression is not assignable}}
+// expected-note@-2 {{dereference the pointer to modify}}
+  }
+
+  void g() const {
+++this;
+// expected-error@-1 {{expression is not assignable}}
+  }
+};

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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 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 14304055e0d223a6dd224625b8fd128e6f711eb5 
e637dc83ec205f7e4dde356b8f5d06ce3abc899e -- clang/test/Sema/debug-93066.cpp 
debug-84072.cpp clang/lib/Sema/SemaExpr.cpp
``





View the diff from clang-format here.


``diff
diff --git a/debug-84072.cpp b/debug-84072.cpp
index c024f50019..7fda310d1c 100644
--- a/debug-84072.cpp
+++ b/debug-84072.cpp
@@ -1,16 +1,16 @@
 void Func(int x) {
-switch (x) {
-[[likely]] case 0:
-case 1:
-int i = 3;
-case 2:
-break;
-}
-switch (x) {
-case 0:
-case 1:
-int i = 3;
-case 2:
-break;
-}
+  switch (x) {
+  [[likely]] case 0:
+  case 1:
+int i = 3;
+  case 2:
+break;
+  }
+  switch (x) {
+  case 0:
+  case 1:
+int i = 3;
+  case 2:
+break;
+  }
 }

``




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


[clang] [X86] Enable constexpr on LZCNT & BMI intrinsics (PR #94161)

2024-06-02 Thread via cfe-commits

https://github.com/aniplcc created 
https://github.com/llvm/llvm-project/pull/94161

Closes  #86128.

>From ad4c0e737f3d8de3202e027646c05d916a695e30 Mon Sep 17 00:00:00 2001
From: aniplcc 
Date: Sun, 2 Jun 2024 19:47:10 +0530
Subject: [PATCH 1/2] [X86] Enable constexpr on LZCNT & BMI intrinsics

---
 clang/lib/Headers/bmiintrin.h   |  50 ++
 clang/lib/Headers/lzcntintrin.h |  13 ++-
 clang/test/CodeGen/X86/bmi-builtins.c   | 125 +++-
 clang/test/CodeGen/X86/lzcnt-builtins.c |  37 ++-
 4 files changed, 198 insertions(+), 27 deletions(-)

diff --git a/clang/lib/Headers/bmiintrin.h b/clang/lib/Headers/bmiintrin.h
index 78bffe68e221a..c5b57a1d1e43c 100644
--- a/clang/lib/Headers/bmiintrin.h
+++ b/clang/lib/Headers/bmiintrin.h
@@ -19,6 +19,11 @@
to use it as a potentially faster version of BSF. */
 #define __RELAXED_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
 
+#if defined (__cplusplus) && (__cplusplus >= 201103L)
+#define __RELAXED_FN_ATTRS_CONSTEXPR __RELAXED_FN_ATTRS constexpr
+#else
+#define __RELAXED_FN_ATTRS_CONSTEXPR __RELAXED_FN_ATTRS
+
 /// Counts the number of trailing zero bits in the operand.
 ///
 /// \headerfile 
@@ -30,7 +35,7 @@
 /// \returns An unsigned 16-bit integer containing the number of trailing zero
 ///bits in the operand.
 /// \see _tzcnt_u16
-static __inline__ unsigned short __RELAXED_FN_ATTRS
+static __inline__ unsigned short __RELAXED_FN_ATTRS_CONSTEXPR
 __tzcnt_u16(unsigned short __X)
 {
   return __builtin_ia32_tzcnt_u16(__X);
@@ -64,7 +69,7 @@ __tzcnt_u16(unsigned short __X)
 /// \returns An unsigned 32-bit integer containing the number of trailing zero
 ///bits in the operand.
 /// \see { _mm_tzcnt_32 _tzcnt_u32 }
-static __inline__ unsigned int __RELAXED_FN_ATTRS
+static __inline__ unsigned int __RELAXED_FN_ATTRS_CONSTEXPR
 __tzcnt_u32(unsigned int __X)
 {
   return __builtin_ia32_tzcnt_u32(__X);
@@ -81,7 +86,7 @@ __tzcnt_u32(unsigned int __X)
 /// \returns A 32-bit integer containing the number of trailing zero bits in
 ///the operand.
 /// \see { __tzcnt_u32 _tzcnt_u32 }
-static __inline__ int __RELAXED_FN_ATTRS
+static __inline__ int __RELAXED_FN_ATTRS_CONSTEXPR
 _mm_tzcnt_32(unsigned int __X)
 {
   return (int)__builtin_ia32_tzcnt_u32(__X);
@@ -117,7 +122,7 @@ _mm_tzcnt_32(unsigned int __X)
 /// \returns An unsigned 64-bit integer containing the number of trailing zero
 ///bits in the operand.
 /// \see { _mm_tzcnt_64 _tzcnt_u64 }
-static __inline__ unsigned long long __RELAXED_FN_ATTRS
+static __inline__ unsigned long long __RELAXED_FN_ATTRS_CONSTEXPR
 __tzcnt_u64(unsigned long long __X)
 {
   return __builtin_ia32_tzcnt_u64(__X);
@@ -134,7 +139,7 @@ __tzcnt_u64(unsigned long long __X)
 /// \returns An 64-bit integer containing the number of trailing zero bits in
 ///the operand.
 /// \see { __tzcnt_u64 _tzcnt_u64 }
-static __inline__ long long __RELAXED_FN_ATTRS
+static __inline__ long long __RELAXED_FN_ATTRS_CONSTEXPR
 _mm_tzcnt_64(unsigned long long __X)
 {
   return (long long)__builtin_ia32_tzcnt_u64(__X);
@@ -160,12 +165,18 @@ _mm_tzcnt_64(unsigned long long __X)
 #endif /* __x86_64__ */
 
 #undef __RELAXED_FN_ATTRS
+#undef __RELAXED_FN_ATTRS_CONSTEXPR
 
 #if !defined(__SCE__) || __has_feature(modules) || defined(__BMI__)
 
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("bmi")))
 
+#if defined (__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+
 /// Performs a bitwise AND of the second operand with the one's
 ///complement of the first operand.
 ///
@@ -180,7 +191,7 @@ _mm_tzcnt_64(unsigned long long __X)
 /// \returns An unsigned integer containing the bitwise AND of the second
 ///operand with the one's complement of the first operand.
 /// \see _andn_u32
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
+static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
 __andn_u32(unsigned int __X, unsigned int __Y)
 {
   return ~__X & __Y;
@@ -223,7 +234,7 @@ __andn_u32(unsigned int __X, unsigned int __Y)
 /// \returns An unsigned integer whose least significant bits contain the
 ///extracted bits.
 /// \see _bextr_u32
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
+static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
 __bextr_u32(unsigned int __X, unsigned int __Y)
 {
   return __builtin_ia32_bextr_u32(__X, __Y);
@@ -248,7 +259,7 @@ __bextr_u32(unsigned int __X, unsigned int __Y)
 /// \returns An unsigned integer whose least significant bits contain the
 ///extracted bits.
 /// \see __bextr_u32
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
+static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
 _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z)
 {
   return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) |

[clang] [X86] Enable constexpr on LZCNT & BMI intrinsics (PR #94161)

2024-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: aniplcc (aniplcc)


Changes

Closes  #86128.

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


4 Files Affected:

- (modified) clang/lib/Headers/bmiintrin.h (+31-19) 
- (modified) clang/lib/Headers/lzcntintrin.h (+13-9) 
- (modified) clang/test/CodeGen/X86/bmi-builtins.c (+122-3) 
- (modified) clang/test/CodeGen/X86/lzcnt-builtins.c (+35-2) 


``diff
diff --git a/clang/lib/Headers/bmiintrin.h b/clang/lib/Headers/bmiintrin.h
index 78bffe68e221a..56e62fc98d6dc 100644
--- a/clang/lib/Headers/bmiintrin.h
+++ b/clang/lib/Headers/bmiintrin.h
@@ -19,6 +19,11 @@
to use it as a potentially faster version of BSF. */
 #define __RELAXED_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __RELAXED_FN_ATTRS_CONSTEXPR __RELAXED_FN_ATTRS constexpr
+#else
+#define __RELAXED_FN_ATTRS_CONSTEXPR __RELAXED_FN_ATTRS
+
 /// Counts the number of trailing zero bits in the operand.
 ///
 /// \headerfile 
@@ -30,7 +35,7 @@
 /// \returns An unsigned 16-bit integer containing the number of trailing zero
 ///bits in the operand.
 /// \see _tzcnt_u16
-static __inline__ unsigned short __RELAXED_FN_ATTRS
+static __inline__ unsigned short __RELAXED_FN_ATTRS_CONSTEXPR
 __tzcnt_u16(unsigned short __X)
 {
   return __builtin_ia32_tzcnt_u16(__X);
@@ -64,7 +69,7 @@ __tzcnt_u16(unsigned short __X)
 /// \returns An unsigned 32-bit integer containing the number of trailing zero
 ///bits in the operand.
 /// \see { _mm_tzcnt_32 _tzcnt_u32 }
-static __inline__ unsigned int __RELAXED_FN_ATTRS
+static __inline__ unsigned int __RELAXED_FN_ATTRS_CONSTEXPR
 __tzcnt_u32(unsigned int __X)
 {
   return __builtin_ia32_tzcnt_u32(__X);
@@ -81,7 +86,7 @@ __tzcnt_u32(unsigned int __X)
 /// \returns A 32-bit integer containing the number of trailing zero bits in
 ///the operand.
 /// \see { __tzcnt_u32 _tzcnt_u32 }
-static __inline__ int __RELAXED_FN_ATTRS
+static __inline__ int __RELAXED_FN_ATTRS_CONSTEXPR
 _mm_tzcnt_32(unsigned int __X)
 {
   return (int)__builtin_ia32_tzcnt_u32(__X);
@@ -117,7 +122,7 @@ _mm_tzcnt_32(unsigned int __X)
 /// \returns An unsigned 64-bit integer containing the number of trailing zero
 ///bits in the operand.
 /// \see { _mm_tzcnt_64 _tzcnt_u64 }
-static __inline__ unsigned long long __RELAXED_FN_ATTRS
+static __inline__ unsigned long long __RELAXED_FN_ATTRS_CONSTEXPR
 __tzcnt_u64(unsigned long long __X)
 {
   return __builtin_ia32_tzcnt_u64(__X);
@@ -134,7 +139,7 @@ __tzcnt_u64(unsigned long long __X)
 /// \returns An 64-bit integer containing the number of trailing zero bits in
 ///the operand.
 /// \see { __tzcnt_u64 _tzcnt_u64 }
-static __inline__ long long __RELAXED_FN_ATTRS
+static __inline__ long long __RELAXED_FN_ATTRS_CONSTEXPR
 _mm_tzcnt_64(unsigned long long __X)
 {
   return (long long)__builtin_ia32_tzcnt_u64(__X);
@@ -160,12 +165,18 @@ _mm_tzcnt_64(unsigned long long __X)
 #endif /* __x86_64__ */
 
 #undef __RELAXED_FN_ATTRS
+#undef __RELAXED_FN_ATTRS_CONSTEXPR
 
 #if !defined(__SCE__) || __has_feature(modules) || defined(__BMI__)
 
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("bmi")))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+
 /// Performs a bitwise AND of the second operand with the one's
 ///complement of the first operand.
 ///
@@ -180,7 +191,7 @@ _mm_tzcnt_64(unsigned long long __X)
 /// \returns An unsigned integer containing the bitwise AND of the second
 ///operand with the one's complement of the first operand.
 /// \see _andn_u32
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
+static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
 __andn_u32(unsigned int __X, unsigned int __Y)
 {
   return ~__X & __Y;
@@ -223,7 +234,7 @@ __andn_u32(unsigned int __X, unsigned int __Y)
 /// \returns An unsigned integer whose least significant bits contain the
 ///extracted bits.
 /// \see _bextr_u32
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
+static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
 __bextr_u32(unsigned int __X, unsigned int __Y)
 {
   return __builtin_ia32_bextr_u32(__X, __Y);
@@ -248,7 +259,7 @@ __bextr_u32(unsigned int __X, unsigned int __Y)
 /// \returns An unsigned integer whose least significant bits contain the
 ///extracted bits.
 /// \see __bextr_u32
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
+static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
 _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z)
 {
   return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
@@ -271,7 +282,7 @@ _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int 
__Z)
 /// \returns An unsigned integer whose 

[clang] [X86] Enable constexpr on LZCNT & BMI intrinsics (PR #94161)

2024-06-02 Thread via cfe-commits

https://github.com/aniplcc updated 
https://github.com/llvm/llvm-project/pull/94161

>From ad4c0e737f3d8de3202e027646c05d916a695e30 Mon Sep 17 00:00:00 2001
From: aniplcc 
Date: Sun, 2 Jun 2024 19:47:10 +0530
Subject: [PATCH 1/3] [X86] Enable constexpr on LZCNT & BMI intrinsics

---
 clang/lib/Headers/bmiintrin.h   |  50 ++
 clang/lib/Headers/lzcntintrin.h |  13 ++-
 clang/test/CodeGen/X86/bmi-builtins.c   | 125 +++-
 clang/test/CodeGen/X86/lzcnt-builtins.c |  37 ++-
 4 files changed, 198 insertions(+), 27 deletions(-)

diff --git a/clang/lib/Headers/bmiintrin.h b/clang/lib/Headers/bmiintrin.h
index 78bffe68e221a..c5b57a1d1e43c 100644
--- a/clang/lib/Headers/bmiintrin.h
+++ b/clang/lib/Headers/bmiintrin.h
@@ -19,6 +19,11 @@
to use it as a potentially faster version of BSF. */
 #define __RELAXED_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
 
+#if defined (__cplusplus) && (__cplusplus >= 201103L)
+#define __RELAXED_FN_ATTRS_CONSTEXPR __RELAXED_FN_ATTRS constexpr
+#else
+#define __RELAXED_FN_ATTRS_CONSTEXPR __RELAXED_FN_ATTRS
+
 /// Counts the number of trailing zero bits in the operand.
 ///
 /// \headerfile 
@@ -30,7 +35,7 @@
 /// \returns An unsigned 16-bit integer containing the number of trailing zero
 ///bits in the operand.
 /// \see _tzcnt_u16
-static __inline__ unsigned short __RELAXED_FN_ATTRS
+static __inline__ unsigned short __RELAXED_FN_ATTRS_CONSTEXPR
 __tzcnt_u16(unsigned short __X)
 {
   return __builtin_ia32_tzcnt_u16(__X);
@@ -64,7 +69,7 @@ __tzcnt_u16(unsigned short __X)
 /// \returns An unsigned 32-bit integer containing the number of trailing zero
 ///bits in the operand.
 /// \see { _mm_tzcnt_32 _tzcnt_u32 }
-static __inline__ unsigned int __RELAXED_FN_ATTRS
+static __inline__ unsigned int __RELAXED_FN_ATTRS_CONSTEXPR
 __tzcnt_u32(unsigned int __X)
 {
   return __builtin_ia32_tzcnt_u32(__X);
@@ -81,7 +86,7 @@ __tzcnt_u32(unsigned int __X)
 /// \returns A 32-bit integer containing the number of trailing zero bits in
 ///the operand.
 /// \see { __tzcnt_u32 _tzcnt_u32 }
-static __inline__ int __RELAXED_FN_ATTRS
+static __inline__ int __RELAXED_FN_ATTRS_CONSTEXPR
 _mm_tzcnt_32(unsigned int __X)
 {
   return (int)__builtin_ia32_tzcnt_u32(__X);
@@ -117,7 +122,7 @@ _mm_tzcnt_32(unsigned int __X)
 /// \returns An unsigned 64-bit integer containing the number of trailing zero
 ///bits in the operand.
 /// \see { _mm_tzcnt_64 _tzcnt_u64 }
-static __inline__ unsigned long long __RELAXED_FN_ATTRS
+static __inline__ unsigned long long __RELAXED_FN_ATTRS_CONSTEXPR
 __tzcnt_u64(unsigned long long __X)
 {
   return __builtin_ia32_tzcnt_u64(__X);
@@ -134,7 +139,7 @@ __tzcnt_u64(unsigned long long __X)
 /// \returns An 64-bit integer containing the number of trailing zero bits in
 ///the operand.
 /// \see { __tzcnt_u64 _tzcnt_u64 }
-static __inline__ long long __RELAXED_FN_ATTRS
+static __inline__ long long __RELAXED_FN_ATTRS_CONSTEXPR
 _mm_tzcnt_64(unsigned long long __X)
 {
   return (long long)__builtin_ia32_tzcnt_u64(__X);
@@ -160,12 +165,18 @@ _mm_tzcnt_64(unsigned long long __X)
 #endif /* __x86_64__ */
 
 #undef __RELAXED_FN_ATTRS
+#undef __RELAXED_FN_ATTRS_CONSTEXPR
 
 #if !defined(__SCE__) || __has_feature(modules) || defined(__BMI__)
 
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("bmi")))
 
+#if defined (__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+
 /// Performs a bitwise AND of the second operand with the one's
 ///complement of the first operand.
 ///
@@ -180,7 +191,7 @@ _mm_tzcnt_64(unsigned long long __X)
 /// \returns An unsigned integer containing the bitwise AND of the second
 ///operand with the one's complement of the first operand.
 /// \see _andn_u32
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
+static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
 __andn_u32(unsigned int __X, unsigned int __Y)
 {
   return ~__X & __Y;
@@ -223,7 +234,7 @@ __andn_u32(unsigned int __X, unsigned int __Y)
 /// \returns An unsigned integer whose least significant bits contain the
 ///extracted bits.
 /// \see _bextr_u32
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
+static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
 __bextr_u32(unsigned int __X, unsigned int __Y)
 {
   return __builtin_ia32_bextr_u32(__X, __Y);
@@ -248,7 +259,7 @@ __bextr_u32(unsigned int __X, unsigned int __Y)
 /// \returns An unsigned integer whose least significant bits contain the
 ///extracted bits.
 /// \see __bextr_u32
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
+static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
 _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z)
 {
   return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) <<

[clang] [llvm] [mlir] Use llvm::less_first (NFC) (PR #94136)

2024-06-02 Thread Kazu Hirata via cfe-commits

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


[clang] 197c3a3 - Use llvm::less_first (NFC) (#94136)

2024-06-02 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-06-02T07:45:50-07:00
New Revision: 197c3a3efc703711ac8f14bc4f1765eaadb8e5bc

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

LOG: Use llvm::less_first (NFC) (#94136)

Added: 


Modified: 
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
llvm/lib/MC/MCPseudoProbe.cpp
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
mlir/lib/Dialect/SparseTensor/Transforms/SparseReinterpretMap.cpp
mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index e830c4026ea78..eb41a205bc82c 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -3205,9 +3205,7 @@ void ASTWriter::WritePragmaDiagnosticMappings(const 
DiagnosticsEngine &Diag,
   }
 
   // Sort by diag::kind for deterministic output.
-  llvm::sort(Mappings, [](const auto &LHS, const auto &RHS) {
-return LHS.first < RHS.first;
-  });
+  llvm::sort(Mappings, llvm::less_first());
 
   for (const auto &I : Mappings) {
 Record.push_back(I.first);

diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 0c047b6c5da2f..0f82f22d8b9a8 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -259,9 +259,7 @@ static void canonicalizeDefines(PreprocessorOptions 
&PPOpts) {
 ++Index;
   }
 
-  llvm::stable_sort(SimpleNames, [](const MacroOpt &A, const MacroOpt &B) {
-return A.first < B.first;
-  });
+  llvm::stable_sort(SimpleNames, llvm::less_first());
   // Keep the last instance of each macro name by going in reverse
   auto NewEnd = std::unique(
   SimpleNames.rbegin(), SimpleNames.rend(),

diff  --git a/llvm/lib/MC/MCPseudoProbe.cpp b/llvm/lib/MC/MCPseudoProbe.cpp
index cec50322bb9f9..040f3aab88128 100644
--- a/llvm/lib/MC/MCPseudoProbe.cpp
+++ b/llvm/lib/MC/MCPseudoProbe.cpp
@@ -182,13 +182,10 @@ void MCPseudoProbeInlineTree::emit(MCObjectStreamer *MCOS,
   // Emit sorted descendant. InlineSite is unique for each pair, so there will
   // be no ordering of Inlinee based on MCPseudoProbeInlineTree*
   using InlineeType = std::pair;
-  auto Comparer = [](const InlineeType &A, const InlineeType &B) {
-return A.first < B.first;
-  };
   std::vector Inlinees;
   for (const auto &Child : Children)
 Inlinees.emplace_back(Child.first, Child.second.get());
-  std::sort(Inlinees.begin(), Inlinees.end(), Comparer);
+  llvm::sort(Inlinees, llvm::less_first());
 
   for (const auto &Inlinee : Inlinees) {
 // Emit probe index
@@ -230,13 +227,10 @@ void MCPseudoProbeSections::emit(MCObjectStreamer *MCOS) {
   // Emit sorted descendant. InlineSite is unique for each pair, so there
   // will be no ordering of Inlinee based on MCPseudoProbeInlineTree*
   using InlineeType = std::pair;
-  auto Comparer = [](const InlineeType &A, const InlineeType &B) {
-return A.first < B.first;
-  };
   std::vector Inlinees;
   for (const auto &Child : Root.getChildren())
 Inlinees.emplace_back(Child.first, Child.second.get());
-  std::sort(Inlinees.begin(), Inlinees.end(), Comparer);
+  llvm::sort(Inlinees, llvm::less_first());
 
   for (const auto &Inlinee : Inlinees) {
 // Emit the group guarded by a sentinel probe.

diff  --git a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h 
b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
index 8c014832f5e46..9fe02e24c8a15 100644
--- a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
@@ -597,10 +597,7 @@ class SIMachineFunctionInfo final : public 
AMDGPUMachineFunction,
   const ReservedRegSet &getWWMReservedRegs() const { return WWMReservedRegs; }
 
   ArrayRef getPrologEpilogSGPRSpills() const {
-assert(
-is_sorted(PrologEpilogSGPRSpills, [](const auto &LHS, const auto &RHS) 
{
-  return LHS.first < RHS.first;
-}));
+assert(is_sorted(PrologEpilogSGPRSpills, llvm::less_first()));
 return PrologEpilogSGPRSpills;
   }
 

diff  --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseReinterpretMap.cpp 
b/mlir/lib/Dialect/SparseTensor/Transforms/SparseReinterpretMap.cpp
index 36ecf692b02c5..ce7f6b2865375 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseReinterpretMap.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseReinterpretMap.cpp
@@ -557,9 +557,7 @@ struct GenericOpScheduler : public 
OpRewritePattern {
 unsigned lvl = llvm::cast(expr).getPosition();

[clang] [X86] Enable constexpr on LZCNT & BMI intrinsics (PR #94161)

2024-06-02 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 0310f7f2d0c56a5697710251cec9803cbf7b4d56 
7ede5764c9279a64cd36a5703255ec94a8109341 -- clang/lib/Headers/bmiintrin.h 
clang/lib/Headers/lzcntintrin.h clang/test/CodeGen/X86/bmi-builtins.c 
clang/test/CodeGen/X86/lzcnt-builtins.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/bmiintrin.h b/clang/lib/Headers/bmiintrin.h
index 801da6584f..a65e20605a 100644
--- a/clang/lib/Headers/bmiintrin.h
+++ b/clang/lib/Headers/bmiintrin.h
@@ -37,8 +37,7 @@
 ///bits in the operand.
 /// \see _tzcnt_u16
 static __inline__ unsigned short __RELAXED_FN_ATTRS_CONSTEXPR
-__tzcnt_u16(unsigned short __X)
-{
+__tzcnt_u16(unsigned short __X) {
   return __builtin_ia32_tzcnt_u16(__X);
 }
 
@@ -71,8 +70,7 @@ __tzcnt_u16(unsigned short __X)
 ///bits in the operand.
 /// \see { _mm_tzcnt_32 _tzcnt_u32 }
 static __inline__ unsigned int __RELAXED_FN_ATTRS_CONSTEXPR
-__tzcnt_u32(unsigned int __X)
-{
+__tzcnt_u32(unsigned int __X) {
   return __builtin_ia32_tzcnt_u32(__X);
 }
 
@@ -88,8 +86,7 @@ __tzcnt_u32(unsigned int __X)
 ///the operand.
 /// \see { __tzcnt_u32 _tzcnt_u32 }
 static __inline__ int __RELAXED_FN_ATTRS_CONSTEXPR
-_mm_tzcnt_32(unsigned int __X)
-{
+_mm_tzcnt_32(unsigned int __X) {
   return (int)__builtin_ia32_tzcnt_u32(__X);
 }
 
@@ -124,8 +121,7 @@ _mm_tzcnt_32(unsigned int __X)
 ///bits in the operand.
 /// \see { _mm_tzcnt_64 _tzcnt_u64 }
 static __inline__ unsigned long long __RELAXED_FN_ATTRS_CONSTEXPR
-__tzcnt_u64(unsigned long long __X)
-{
+__tzcnt_u64(unsigned long long __X) {
   return __builtin_ia32_tzcnt_u64(__X);
 }
 
@@ -141,8 +137,7 @@ __tzcnt_u64(unsigned long long __X)
 ///the operand.
 /// \see { __tzcnt_u64 _tzcnt_u64 }
 static __inline__ long long __RELAXED_FN_ATTRS_CONSTEXPR
-_mm_tzcnt_64(unsigned long long __X)
-{
+_mm_tzcnt_64(unsigned long long __X) {
   return (long long)__builtin_ia32_tzcnt_u64(__X);
 }
 
@@ -194,8 +189,7 @@ _mm_tzcnt_64(unsigned long long __X)
 ///operand with the one's complement of the first operand.
 /// \see _andn_u32
 static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
-__andn_u32(unsigned int __X, unsigned int __Y)
-{
+__andn_u32(unsigned int __X, unsigned int __Y) {
   return ~__X & __Y;
 }
 
@@ -237,8 +231,7 @@ __andn_u32(unsigned int __X, unsigned int __Y)
 ///extracted bits.
 /// \see _bextr_u32
 static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
-__bextr_u32(unsigned int __X, unsigned int __Y)
-{
+__bextr_u32(unsigned int __X, unsigned int __Y) {
   return __builtin_ia32_bextr_u32(__X, __Y);
 }
 
@@ -262,8 +255,7 @@ __bextr_u32(unsigned int __X, unsigned int __Y)
 ///extracted bits.
 /// \see __bextr_u32
 static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
-_bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z)
-{
+_bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z) {
   return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
 }
 
@@ -302,8 +294,7 @@ _bextr2_u32(unsigned int __X, unsigned int __Y) {
 ///the source operand.
 /// \see _blsi_u32
 static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
-__blsi_u32(unsigned int __X)
-{
+__blsi_u32(unsigned int __X) {
   return __X & -__X;
 }
 
@@ -338,8 +329,7 @@ __blsi_u32(unsigned int __X)
 /// \returns An unsigned integer containing the newly created mask.
 /// \see _blsmsk_u32
 static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
-__blsmsk_u32(unsigned int __X)
-{
+__blsmsk_u32(unsigned int __X) {
   return __X ^ (__X - 1);
 }
 
@@ -374,8 +364,7 @@ __blsmsk_u32(unsigned int __X)
 ///operand.
 /// \see _blsr_u32
 static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
-__blsr_u32(unsigned int __X)
-{
+__blsr_u32(unsigned int __X) {
   return __X & (__X - 1);
 }
 
@@ -414,8 +403,7 @@ __blsr_u32(unsigned int __X)
 ///operand with the one's complement of the first operand.
 /// \see _andn_u64
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CONSTEXPR
-__andn_u64 (unsigned long long __X, unsigned long long __Y)
-{
+__andn_u64(unsigned long long __X, unsigned long long __Y) {
   return ~__X & __Y;
 }
 
@@ -458,8 +446,7 @@ __andn_u64 (unsigned long long __X, unsigned long long __Y)
 ///extracted bits.
 /// \see _bextr_u64
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CONSTEXPR
-__bextr_u64(unsigned long long __X, unsigned long long __Y)
-{
+__bextr_u64(unsigned long long __X, unsigned long long __Y) {
   return __builtin_ia32_bextr_u64(__X, __Y);
 }
 
@@ -483,8 +470,7 @@ __bextr_u64(unsigned long long __X, unsigned long long __Y)
 ///extracted bits.
 /// \see __bextr_u64
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CONSTEXPR
-_bextr_u64(unsigned long long __X, unsigned int __Y, unsigned int __Z)
-{
+_b

[clang] [clang-format] Handle attributes before lambda return arrow (PR #94119)

2024-06-02 Thread via cfe-commits

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


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


[clang] [X86] Enable constexpr on LZCNT & BMI intrinsics (PR #94161)

2024-06-02 Thread via cfe-commits

aniplcc wrote:

forgot to update ExprConstant with builtins



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


[clang] c26a993 - [clang][NFC] Update CWG issues list

2024-06-02 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-06-02T19:23:42+03:00
New Revision: c26a99384bce5719107d26f4617d6e3b1e9253ff

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

LOG: [clang][NFC] Update CWG issues list

Added: 


Modified: 
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 4c5f922e52954..744d22959db42 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -12670,7 +12670,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2144.html";>2144
-drafting
+tentatively ready
 Function/variable declaration ambiguity
 Not resolved
   
@@ -17081,7 +17081,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2879.html";>2879
-open
+drafting
 Undesired outcomes with const_cast
 Not resolved
   
@@ -17099,13 +17099,13 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2882.html";>2882
-open
+tentatively ready
 Unclear treatment of conversion to void
 Not resolved
   
   
 https://cplusplus.github.io/CWG/issues/2883.html";>2883
-open
+tentatively ready
 Definition of "odr-usable" ignores lambda scopes
 Not resolved
   
@@ -17117,25 +17117,25 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2885.html";>2885
-review
+tentatively ready
 Non-eligible trivial default constructors
 Not resolved
   
   
 https://cplusplus.github.io/CWG/issues/2886.html";>2886
-open
+tentatively ready
 Temporaries and trivial potentially-throwing special member 
functions
 Not resolved
   
   
 https://cplusplus.github.io/CWG/issues/2887.html";>2887
-open
+tentatively ready
 Missing compatibility entries for xvalues
 Not resolved
   
   
 https://cplusplus.github.io/CWG/issues/2888.html";>2888
-open
+review
 Missing cases for reference and array types for argument-dependent 
lookup
 Not resolved
   
@@ -17153,9 +17153,39 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2891.html";>2891
-review
+tentatively ready
 Normative status of implementation limits
 Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2892.html";>2892
+tentatively ready
+Unclear usual arithmetic conversions
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2893.html";>2893
+open
+Instantiations in discarded if constexpr substatements
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2894.html";>2894
+open
+Functional casts create prvalues of reference type
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2895.html";>2895
+open
+Initialization should ignore the destination type's 
cv-qualification
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2896.html";>2896
+open
+Template argument deduction involving exception specifications
+Not resolved
   
 
 



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


[clang] [X86] Enable constexpr on LZCNT & BMI intrinsics (PR #94161)

2024-06-02 Thread via cfe-commits

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


[clang] [lldb] [clang][Modules] Move `ASTSourceDescriptor` into its own file (PR #67930)

2024-06-02 Thread David Stone via cfe-commits

davidstone wrote:

Could I get someone to merge this for me if there are no other changes required?

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


[clang] [clang-tools-extra] [libcxx] [clang][Modules] Remove unnecessary includes of `Module.h` (PR #93417)

2024-06-02 Thread David Stone via cfe-commits

davidstone wrote:

Is there any additional work needed on this before it can be merged?

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


[clang] [clang-repl] Teach clang-repl how to load PCHs. (PR #94166)

2024-06-02 Thread Vassil Vassilev via cfe-commits

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

None

>From 896f3090ca2eadf650459caee9a4106fc7dd381d Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Thu, 30 May 2024 05:05:41 +
Subject: [PATCH] [clang-repl] Teach clang-repl how to load PCHs.

---
 clang/include/clang/CodeGen/ModuleBuilder.h |  6 ++
 clang/lib/CodeGen/BackendConsumer.h |  5 -
 clang/lib/CodeGen/CodeGenAction.cpp |  6 +-
 clang/lib/CodeGen/ModuleBuilder.cpp |  8 
 clang/lib/Interpreter/IncrementalParser.cpp |  4 
 clang/test/Interpreter/execute-pch.cpp  | 14 ++
 6 files changed, 33 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Interpreter/execute-pch.cpp

diff --git a/clang/include/clang/CodeGen/ModuleBuilder.h 
b/clang/include/clang/CodeGen/ModuleBuilder.h
index edacd82bf899d..cb5919d1c8af5 100644
--- a/clang/include/clang/CodeGen/ModuleBuilder.h
+++ b/clang/include/clang/CodeGen/ModuleBuilder.h
@@ -48,6 +48,12 @@ namespace CodeGen {
 class CodeGenerator : public ASTConsumer {
   virtual void anchor();
 
+protected:
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
 public:
   /// Return an opaque reference to the CodeGenModule object, which can
   /// be used in various secondary APIs.  It is valid as long as the
diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index 0fe9929dca2b3..76ab5add603b7 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -41,11 +41,6 @@ class BackendConsumer : public ASTConsumer {
   llvm::Timer LLVMIRGeneration;
   unsigned LLVMIRGenerationRefCount;
 
-  /// True if we've finished generating IR. This prevents us from generating
-  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
-  /// can happen when Clang plugins trigger additional AST deserialization.
-  bool IRGenFinished = false;
-
   bool TimerIsEnabled = false;
 
   std::unique_ptr Gen;
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 6d3efdb5ffe34..6e2204d2dba0c 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -221,9 +221,7 @@ void 
BackendConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
 }
 
 void BackendConsumer::HandleInterestingDecl(DeclGroupRef D) {
-  // Ignore interesting decls from the AST reader after IRGen is finished.
-  if (!IRGenFinished)
-HandleTopLevelDecl(D);
+  HandleTopLevelDecl(D);
 }
 
 // Links each entry in LinkModules into our module.  Returns true on error.
@@ -285,8 +283,6 @@ void BackendConsumer::HandleTranslationUnit(ASTContext &C) {
   if (LLVMIRGenerationRefCount == 0)
 LLVMIRGeneration.stopTimer();
 }
-
-IRGenFinished = true;
   }
 
   // Silently ignore if we weren't initialized for some reason.
diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp 
b/clang/lib/CodeGen/ModuleBuilder.cpp
index df85295cfb2e2..768d2ffd2d8d9 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -138,6 +138,8 @@ namespace {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
 
+  IRGenFinished = false;
+
   std::unique_ptr OldBuilder = std::move(Builder);
 
   Initialize(*Ctx);
@@ -179,6 +181,10 @@ namespace {
 }
 
 bool HandleTopLevelDecl(DeclGroupRef DG) override {
+  // Ignore interesting decls from the AST reader after IRGen is finished.
+  if (IRGenFinished)
+return true; // We can't CodeGen more but pass to other consumers.
+
   // FIXME: Why not return false and abort parsing?
   if (Diags.hasUnrecoverableErrorOccurred())
 return true;
@@ -282,6 +288,8 @@ namespace {
 }
 
 void HandleTranslationUnit(ASTContext &Ctx) override {
+  IRGenFinished = true;
+
   // Release the Builder when there is no error.
   if (!Diags.hasUnrecoverableErrorOccurred() && Builder)
 Builder->Release();
diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index ef90fe9e6f545..eddd4f356c5af 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -219,6 +219,10 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
   Consumer = &CI->getASTConsumer();
   P.reset(
   new Parser(CI->getPreprocessor(), CI->getSema(), /*SkipBodies=*/false));
+
+  if (ExternalASTSource *External = CI->getASTContext().getExternalSource())
+External->StartTranslationUnit(Consumer);
+
   P->Initialize();
 
   // An initial PTU is needed as CUDA includes some headers automatically
diff --git a/clang/test/Interpret

[clang] [clang-repl] Teach clang-repl how to load PCHs. (PR #94166)

2024-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Vassil Vassilev (vgvassilev)


Changes



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


6 Files Affected:

- (modified) clang/include/clang/CodeGen/ModuleBuilder.h (+6) 
- (modified) clang/lib/CodeGen/BackendConsumer.h (-5) 
- (modified) clang/lib/CodeGen/CodeGenAction.cpp (+1-5) 
- (modified) clang/lib/CodeGen/ModuleBuilder.cpp (+8) 
- (modified) clang/lib/Interpreter/IncrementalParser.cpp (+4) 
- (added) clang/test/Interpreter/execute-pch.cpp (+14) 


``diff
diff --git a/clang/include/clang/CodeGen/ModuleBuilder.h 
b/clang/include/clang/CodeGen/ModuleBuilder.h
index edacd82bf899d..cb5919d1c8af5 100644
--- a/clang/include/clang/CodeGen/ModuleBuilder.h
+++ b/clang/include/clang/CodeGen/ModuleBuilder.h
@@ -48,6 +48,12 @@ namespace CodeGen {
 class CodeGenerator : public ASTConsumer {
   virtual void anchor();
 
+protected:
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
 public:
   /// Return an opaque reference to the CodeGenModule object, which can
   /// be used in various secondary APIs.  It is valid as long as the
diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index 0fe9929dca2b3..76ab5add603b7 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -41,11 +41,6 @@ class BackendConsumer : public ASTConsumer {
   llvm::Timer LLVMIRGeneration;
   unsigned LLVMIRGenerationRefCount;
 
-  /// True if we've finished generating IR. This prevents us from generating
-  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
-  /// can happen when Clang plugins trigger additional AST deserialization.
-  bool IRGenFinished = false;
-
   bool TimerIsEnabled = false;
 
   std::unique_ptr Gen;
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 6d3efdb5ffe34..6e2204d2dba0c 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -221,9 +221,7 @@ void 
BackendConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
 }
 
 void BackendConsumer::HandleInterestingDecl(DeclGroupRef D) {
-  // Ignore interesting decls from the AST reader after IRGen is finished.
-  if (!IRGenFinished)
-HandleTopLevelDecl(D);
+  HandleTopLevelDecl(D);
 }
 
 // Links each entry in LinkModules into our module.  Returns true on error.
@@ -285,8 +283,6 @@ void BackendConsumer::HandleTranslationUnit(ASTContext &C) {
   if (LLVMIRGenerationRefCount == 0)
 LLVMIRGeneration.stopTimer();
 }
-
-IRGenFinished = true;
   }
 
   // Silently ignore if we weren't initialized for some reason.
diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp 
b/clang/lib/CodeGen/ModuleBuilder.cpp
index df85295cfb2e2..768d2ffd2d8d9 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -138,6 +138,8 @@ namespace {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
 
+  IRGenFinished = false;
+
   std::unique_ptr OldBuilder = std::move(Builder);
 
   Initialize(*Ctx);
@@ -179,6 +181,10 @@ namespace {
 }
 
 bool HandleTopLevelDecl(DeclGroupRef DG) override {
+  // Ignore interesting decls from the AST reader after IRGen is finished.
+  if (IRGenFinished)
+return true; // We can't CodeGen more but pass to other consumers.
+
   // FIXME: Why not return false and abort parsing?
   if (Diags.hasUnrecoverableErrorOccurred())
 return true;
@@ -282,6 +288,8 @@ namespace {
 }
 
 void HandleTranslationUnit(ASTContext &Ctx) override {
+  IRGenFinished = true;
+
   // Release the Builder when there is no error.
   if (!Diags.hasUnrecoverableErrorOccurred() && Builder)
 Builder->Release();
diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index ef90fe9e6f545..eddd4f356c5af 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -219,6 +219,10 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
   Consumer = &CI->getASTConsumer();
   P.reset(
   new Parser(CI->getPreprocessor(), CI->getSema(), /*SkipBodies=*/false));
+
+  if (ExternalASTSource *External = CI->getASTContext().getExternalSource())
+External->StartTranslationUnit(Consumer);
+
   P->Initialize();
 
   // An initial PTU is needed as CUDA includes some headers automatically
diff --git a/clang/test/Interpreter/execute-pch.cpp 
b/clang/test/Interpreter/execute-pch.cpp
new file mode 100644
index 0..30390d02f8c5c
--- /dev/null
+++ b/clang/test/Interpreter/execute-pch.cpp
@@ -0,0 +1,14 @@
+// R

[clang] [clang-repl] Teach clang-repl how to load PCHs. (PR #94166)

2024-06-02 Thread Vassil Vassilev via cfe-commits


@@ -0,0 +1,14 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+
+// RUN: rm -f %t.pch
+// RUN: %clang_cc1 -fmax-type-align=16 -pic-level 2 -fdeprecated-macro 
-stack-protector 1 -fblocks -fskip-odr-check-in-gmf -fexceptions 
-fcxx-exceptions -fgnuc-version=0 -triple=%target_triple -DPCH 
-fincremental-extensions -emit-pch -x c++-header -o %t.pch %s
+// RUN: clang-repl -Xcc -fgnuc-version=0 -Xcc -triple=%target_triple -Xcc 
-include-pch -Xcc %t.pch '#include "%s"' | FileCheck %s

vgvassilev wrote:

@weliveindetail, it seems that clang-repl prefers the process triple:

https://github.com/llvm/llvm-project/blob/c26a99384bce5719107d26f4617d6e3b1e9253ff/clang/lib/Interpreter/Interpreter.cpp#L188

What should we do here? Should we implement a lit version of 
`host-supports-jit` but `host-jit-triple`? Is there something smarter we could 
do?

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


[clang] [clang-repl] Support wasm execution (PR #86402)

2024-06-02 Thread Vassil Vassilev via cfe-commits

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

>From 4434ceeef152b95998ebd0a3b09a56d105490c4d Mon Sep 17 00:00:00 2001
From: Anubhab Ghosh 
Date: Sat, 23 Mar 2024 15:13:57 +
Subject: [PATCH 1/3] [clang-repl] Support wasm execution.

This commit introduces support for running clang-repl and executing C++ code
interactively inside a Javascript engine using WebAssembly when built with
Emscripten. This is achieved by producing WASM "shared libraries" that can be
loaded by the Emscripten runtime using dlopen()

More discussion is available in https://reviews.llvm.org/D158140
---
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/IncrementalExecutor.cpp |   2 +
 clang/lib/Interpreter/IncrementalExecutor.h   |  11 +-
 clang/lib/Interpreter/Interpreter.cpp |  11 ++
 clang/lib/Interpreter/WASM.cpp| 107 ++
 clang/lib/Interpreter/WASM.h  |  33 ++
 6 files changed, 161 insertions(+), 4 deletions(-)
 create mode 100644 clang/lib/Interpreter/WASM.cpp
 create mode 100644 clang/lib/Interpreter/WASM.h

diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 9065f998f73c4..a8a287edf5b04 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterUtils.cpp
   Value.cpp
+  WASM.cpp
 
   DEPENDS
   intrinsics_gen
diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 6f036107c14a9..1824a5b4570a9 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -36,6 +36,8 @@ LLVM_ATTRIBUTE_USED void linkComponents() {
 }
 
 namespace clang {
+IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC)
+: TSCtx(TSC) {}
 
 llvm::Expected>
 IncrementalExecutor::createDefaultJITBuilder(
diff --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index b4347209e14fe..7954cde36588b 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -43,16 +43,19 @@ class IncrementalExecutor {
   llvm::DenseMap
   ResourceTrackers;
 
+protected:
+  IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC);
+
 public:
   enum SymbolNameKind { IRName, LinkerName };
 
   IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
   llvm::orc::LLJITBuilder &JITBuilder, llvm::Error &Err);
-  ~IncrementalExecutor();
+  virtual ~IncrementalExecutor();
 
-  llvm::Error addModule(PartialTranslationUnit &PTU);
-  llvm::Error removeModule(PartialTranslationUnit &PTU);
-  llvm::Error runCtors() const;
+  virtual llvm::Error addModule(PartialTranslationUnit &PTU);
+  virtual llvm::Error removeModule(PartialTranslationUnit &PTU);
+  virtual llvm::Error runCtors() const;
   llvm::Error cleanUp();
   llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index cf31456b6950a..7d572b20cd828 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -15,6 +15,7 @@
 #include "IncrementalExecutor.h"
 #include "IncrementalParser.h"
 #include "InterpreterUtils.h"
+#include "WASM.h"
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Mangle.h"
@@ -183,6 +184,12 @@ IncrementalCompilerBuilder::CreateCpp() {
   std::vector Argv;
   Argv.reserve(5 + 1 + UserArgs.size());
   Argv.push_back("-xc++");
+#ifdef __EMSCRIPTEN__
+  Argv.push_back("-target");
+  Argv.push_back("wasm32-unknown-emscripten");
+  Argv.push_back("-pie");
+  Argv.push_back("-shared");
+#endif
   Argv.insert(Argv.end(), UserArgs.begin(), UserArgs.end());
 
   std::string TT = TargetTriple ? *TargetTriple : 
llvm::sys::getProcessTriple();
@@ -400,7 +407,11 @@ llvm::Error Interpreter::CreateExecutor() {
   if (!JB)
 return JB.takeError();
   llvm::Error Err = llvm::Error::success();
+#ifdef __EMSCRIPTEN__
+  auto Executor = std::make_unique(*TSCtx, **JB, Err);
+#else
   auto Executor = std::make_unique(*TSCtx, **JB, Err);
+#endif
   if (!Err)
 IncrExecutor = std::move(Executor);
 
diff --git a/clang/lib/Interpreter/WASM.cpp b/clang/lib/Interpreter/WASM.cpp
new file mode 100644
index 0..d21d0ada1eafa
--- /dev/null
+++ b/clang/lib/Interpreter/WASM.cpp
@@ -0,0 +1,107 @@
+//===- WASM.cpp - WASM Interpreter --*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements interpreter support for code e

[clang] [clang-repl] Support wasm execution (PR #86402)

2024-06-02 Thread Vassil Vassilev via cfe-commits

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

>From 6b94e0cd67e59a7fcde2a327d6565a3850dc5f50 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Thu, 30 May 2024 05:08:17 +
Subject: [PATCH 1/2] Revert "Revert "[clang-repl] Extend the C support.
 (#89804)""

This reverts commit dfdf1c5fe45a82b9c578306f3d7627fd251d63f8.
---
 clang/lib/Interpreter/IncrementalParser.cpp | 13 +++--
 clang/lib/Sema/SemaDecl.cpp | 10 +++---
 clang/test/Interpreter/execute.c| 21 +
 3 files changed, 39 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Interpreter/execute.c

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index ef90fe9e6f545..5bc8385d874a1 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -387,8 +387,7 @@ std::unique_ptr 
IncrementalParser::GenModule() {
 
 void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) {
   TranslationUnitDecl *MostRecentTU = PTU.TUPart;
-  TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl();
-  if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) {
+  if (StoredDeclsMap *Map = MostRecentTU->getPrimaryContext()->getLookupPtr()) 
{
 for (auto &&[Key, List] : *Map) {
   DeclContextLookupResult R = List.getLookupResult();
   std::vector NamedDeclsToRemove;
@@ -407,6 +406,16 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit 
&PTU) {
   }
 }
   }
+
+  // FIXME: We should de-allocate MostRecentTU
+  for (Decl *D : MostRecentTU->decls()) {
+auto *ND = dyn_cast(D);
+if (!ND)
+  continue;
+// Check if we need to clean up the IdResolver chain.
+if (ND->getDeclName().getFETokenInfo())
+  getCI()->getSema().IdResolver.RemoveDecl(ND);
+  }
 }
 
 llvm::StringRef IncrementalParser::GetMangledName(GlobalDecl GD) const {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e29ddd81a3f88..521ae4467877d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2282,9 +2282,13 @@ void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) {
 if (LabelDecl *LD = dyn_cast(D))
   CheckPoppedLabel(LD, *this, addDiag);
 
-// Remove this name from our lexical scope, and warn on it if we haven't
-// already.
-IdResolver.RemoveDecl(D);
+// Partial translation units that are created in incremental processing 
must
+// not clean up the IdResolver because PTUs should take into account the
+// declarations that came from previous PTUs.
+if (!PP.isIncrementalProcessingEnabled())
+  IdResolver.RemoveDecl(D);
+
+// Warn on it if we are shadowing a declaration.
 auto ShadowI = ShadowingDecls.find(D);
 if (ShadowI != ShadowingDecls.end()) {
   if (const auto *FD = dyn_cast(ShadowI->second)) {
diff --git a/clang/test/Interpreter/execute.c b/clang/test/Interpreter/execute.c
new file mode 100644
index 0..44a3a32c93011
--- /dev/null
+++ b/clang/test/Interpreter/execute.c
@@ -0,0 +1,21 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+
+// RUN: cat %s | clang-repl -Xcc -xc -Xcc -Xclang -Xcc -verify | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -xc -Xcc -O2 -Xcc -Xclang -Xcc -verify| 
FileCheck %s
+int printf(const char *, ...);
+int i = 42; err // expected-error{{use of undeclared identifier}}
+int i = 42;
+struct S { float f; struct S *m;} s = {1.0, 0};
+// FIXME: Making foo inline fails to emit the function.
+int foo() { return 42; }
+void run() {\
+  printf("i = %d\n", i);\
+  printf("S[f=%f, m=0x%llx]\n", s.f, (unsigned long long)s.m);  \
+  int r3 = foo();   \
+}
+run();
+// CHECK: i = 42
+// CHECK-NEXT: S[f=1.00, m=0x0]
+
+%quit

>From 3bf886259a85dc7670ff0cab2fd70f8386cd1752 Mon Sep 17 00:00:00 2001
From: Anubhab Ghosh 
Date: Sat, 23 Mar 2024 15:13:57 +
Subject: [PATCH 2/2] [clang-repl] Support wasm execution.

This commit introduces support for running clang-repl and executing C++ code
interactively inside a Javascript engine using WebAssembly when built with
Emscripten. This is achieved by producing WASM "shared libraries" that can be
loaded by the Emscripten runtime using dlopen()

More discussion is available in https://reviews.llvm.org/D158140
---
 clang/lib/Interpreter/CMakeLists.txt  |   6 +
 clang/lib/Interpreter/IncrementalExecutor.cpp |   2 +
 clang/lib/Interpreter/IncrementalExecutor.h   |  11 +-
 clang/lib/Interpreter/Interpreter.cpp |  13 ++
 clang/lib/Interpreter/Wasm.cpp| 114 ++
 clang/lib/Interpreter/Wasm.h  |  37 ++
 6 files changed, 179 insertions(+), 4 deletions(-)
 create mode 100644 clang/lib/Interpreter/Wasm.cpp
 create mode 100644 clang/lib/Interprete

[clang] [clang] Add tests for some CWG issues from 2024-05-31 telecon (PR #94167)

2024-06-02 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/94167

This patch adds tests for some CWG issues that were discussed at 2024-05-31 
telecon. While all of them are tentatively ready at the moment, I'm expecting 
them to be moved to DRs without changes. CWG issues that are expected to have 
follow-ups are not included in this PR.

The following CWG issues are covered:
[CWG2877](https://cplusplus.github.io/CWG/issues/2877.html) "Type-only lookup 
for _using-enum-declarator_"
[CWG2882](https://cplusplus.github.io/CWG/issues/2882.html) "Unclear treatment 
of conversion to `void`"
[CWG2883](https://cplusplus.github.io/CWG/issues/2883.html) "Definition of 
"odr-usable" ignores lambda scopes"
[CWG2885](https://cplusplus.github.io/CWG/issues/2885.html) "Non-eligible 
trivial default constructors"
[CWG2886](https://cplusplus.github.io/CWG/issues/2886.html) "Temporaries and 
trivial potentially-throwing special member functions"

>From df8a393cc378daa00dc47408736afb0dd3ae0682 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 2 Jun 2024 22:06:10 +0300
Subject: [PATCH] [clang] Add tests for some CWG issues from 2024-05-31 telecon

---
 clang/test/CXX/drs/cwg28xx.cpp | 95 +++---
 clang/www/cxx_dr_status.html   | 10 ++--
 2 files changed, 93 insertions(+), 12 deletions(-)

diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp
index 8469a065ccaa0..da81eccc8dc22 100644
--- a/clang/test/CXX/drs/cwg28xx.cpp
+++ b/clang/test/CXX/drs/cwg28xx.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -std=c++98 -verify=expected %s
-// RUN: %clang_cc1 -std=c++11 -verify=expected %s
-// RUN: %clang_cc1 -std=c++14 -verify=expected %s
-// RUN: %clang_cc1 -std=c++17 -verify=expected %s
-// RUN: %clang_cc1 -std=c++20 -verify=expected,since-cxx20 %s
-// RUN: %clang_cc1 -std=c++23 -verify=expected,since-cxx20,since-cxx23 %s
-// RUN: %clang_cc1 -std=c++2c 
-verify=expected,since-cxx20,since-cxx23,since-cxx26 %s
+// RUN: %clang_cc1 -std=c++98 -pedantic-errors -verify=expected,cxx98 %s
+// RUN: %clang_cc1 -std=c++11 -pedantic-errors -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -pedantic-errors -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -pedantic-errors -verify=expected %s
+// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify=expected,since-cxx20 %s
+// RUN: %clang_cc1 -std=c++23 -pedantic-errors 
-verify=expected,since-cxx20,since-cxx23 %s
+// RUN: %clang_cc1 -std=c++2c -pedantic-errors 
-verify=expected,since-cxx20,since-cxx23,since-cxx26 %s
 
 namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01
 #if __cpp_constexpr >= 202306L
@@ -110,6 +110,26 @@ struct A {
 
 } // namespace cwg2858
 
+namespace cwg2877 { // cwg2877: no tentatively ready 2024-05-31
+#if __cplusplus >= 202002L
+enum E { x };
+void f() {
+  int E;
+  // FIXME: OK, names ::E
+  using enum E;
+  // since-cxx20-error@-1 {{unknown type name E}}
+}
+using F = E;
+using enum F; // OK, designates ::E
+template using EE = T;
+void g() {
+  // FIXME: OK, designates ::E
+  using enum EE;
+  // since-cxx20-error@-1 {{using enum requires an enum or typedef name}}
+}
+#endif
+} // namespace cwg2877
+
 namespace cwg2881 { // cwg2881: 19 tentatively ready 2024-04-19
 
 #if __cplusplus >= 202302L
@@ -180,3 +200,64 @@ void f() {
 
 } // namespace cwg2881
 
+namespace cwg2882 { // cwg2882: 2.7 tentatively ready 2024-05-31
+struct C {
+  operator void() = delete;
+  // expected-warning@-1 {{conversion function converting 'cwg2882::C' to 
'void' will never be used}}
+  // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}
+};
+
+void f(C c) {
+  (void)c;
+}
+} // namespace cwg2882
+
+namespace cwg2883 { // cwg2883: no tentatively ready 2024-05-31
+#if __cplusplus >= 201103L
+void f() {
+  int x;
+  (void)[&] {
+return x;
+  };
+}
+#endif
+#if __cplusplus >= 202002L
+struct A {
+  A() = default;
+  A(const A &) = delete; // #cwg2883-A-copy-ctor
+  constexpr operator int() { return 42; }
+};
+void g() {
+  constexpr A a;
+  // FIXME: OK, not odr-usable from a default template argument, and not 
odr-used
+  (void)[=] {};
+  // since-cxx20-error@-1 {{call to deleted constructor of 'const A'}}
+  //   since-cxx20-note@#cwg2883-A-copy-ctor {{'A' has been explicitly marked 
deleted here}}
+}
+#endif
+} // namespace cwg2883
+
+namespace cwg2885 { // cwg2885: 16 tentatively ready 2024-05-31
+#if __cplusplus >= 202002L
+template 
+struct A {
+  A() requires (false) = default;
+  A() : t(42) {}
+  T t;
+};
+
+struct B : A {};
+static_assert(!__is_trivially_constructible(B));
+#endif
+} // namespace cwg2885
+
+namespace cwg2886 { // cwg2886: 9 tentatively ready 2024-05-31
+#if __cplusplus >= 201103L
+struct C {
+  C() = default;
+  ~C() noexcept(false) = default;
+};
+
+static_assert(noexcept(C()), "");
+#endif
+} // namespace cwg2886
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 744d22959db42..4d94ac5a1ac1d 100755
--- a/clang/www/cxx_dr_sta

[clang] [clang] Add tests for some CWG issues from 2024-05-31 telecon (PR #94167)

2024-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch adds tests for some CWG issues that were discussed at 2024-05-31 
telecon. While all of them are tentatively ready at the moment, I'm expecting 
them to be moved to DRs without changes. CWG issues that are expected to have 
follow-ups are not included in this PR.

The following CWG issues are covered:
[CWG2877](https://cplusplus.github.io/CWG/issues/2877.html) "Type-only lookup 
for _using-enum-declarator_"
[CWG2882](https://cplusplus.github.io/CWG/issues/2882.html) "Unclear treatment 
of conversion to `void`"
[CWG2883](https://cplusplus.github.io/CWG/issues/2883.html) "Definition of 
"odr-usable" ignores lambda scopes"
[CWG2885](https://cplusplus.github.io/CWG/issues/2885.html) "Non-eligible 
trivial default constructors"
[CWG2886](https://cplusplus.github.io/CWG/issues/2886.html) "Temporaries and 
trivial potentially-throwing special member functions"

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


2 Files Affected:

- (modified) clang/test/CXX/drs/cwg28xx.cpp (+88-7) 
- (modified) clang/www/cxx_dr_status.html (+5-5) 


``diff
diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp
index 8469a065ccaa0..da81eccc8dc22 100644
--- a/clang/test/CXX/drs/cwg28xx.cpp
+++ b/clang/test/CXX/drs/cwg28xx.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -std=c++98 -verify=expected %s
-// RUN: %clang_cc1 -std=c++11 -verify=expected %s
-// RUN: %clang_cc1 -std=c++14 -verify=expected %s
-// RUN: %clang_cc1 -std=c++17 -verify=expected %s
-// RUN: %clang_cc1 -std=c++20 -verify=expected,since-cxx20 %s
-// RUN: %clang_cc1 -std=c++23 -verify=expected,since-cxx20,since-cxx23 %s
-// RUN: %clang_cc1 -std=c++2c 
-verify=expected,since-cxx20,since-cxx23,since-cxx26 %s
+// RUN: %clang_cc1 -std=c++98 -pedantic-errors -verify=expected,cxx98 %s
+// RUN: %clang_cc1 -std=c++11 -pedantic-errors -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -pedantic-errors -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -pedantic-errors -verify=expected %s
+// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify=expected,since-cxx20 %s
+// RUN: %clang_cc1 -std=c++23 -pedantic-errors 
-verify=expected,since-cxx20,since-cxx23 %s
+// RUN: %clang_cc1 -std=c++2c -pedantic-errors 
-verify=expected,since-cxx20,since-cxx23,since-cxx26 %s
 
 namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01
 #if __cpp_constexpr >= 202306L
@@ -110,6 +110,26 @@ struct A {
 
 } // namespace cwg2858
 
+namespace cwg2877 { // cwg2877: no tentatively ready 2024-05-31
+#if __cplusplus >= 202002L
+enum E { x };
+void f() {
+  int E;
+  // FIXME: OK, names ::E
+  using enum E;
+  // since-cxx20-error@-1 {{unknown type name E}}
+}
+using F = E;
+using enum F; // OK, designates ::E
+template using EE = T;
+void g() {
+  // FIXME: OK, designates ::E
+  using enum EE;
+  // since-cxx20-error@-1 {{using enum requires an enum or typedef name}}
+}
+#endif
+} // namespace cwg2877
+
 namespace cwg2881 { // cwg2881: 19 tentatively ready 2024-04-19
 
 #if __cplusplus >= 202302L
@@ -180,3 +200,64 @@ void f() {
 
 } // namespace cwg2881
 
+namespace cwg2882 { // cwg2882: 2.7 tentatively ready 2024-05-31
+struct C {
+  operator void() = delete;
+  // expected-warning@-1 {{conversion function converting 'cwg2882::C' to 
'void' will never be used}}
+  // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}
+};
+
+void f(C c) {
+  (void)c;
+}
+} // namespace cwg2882
+
+namespace cwg2883 { // cwg2883: no tentatively ready 2024-05-31
+#if __cplusplus >= 201103L
+void f() {
+  int x;
+  (void)[&] {
+return x;
+  };
+}
+#endif
+#if __cplusplus >= 202002L
+struct A {
+  A() = default;
+  A(const A &) = delete; // #cwg2883-A-copy-ctor
+  constexpr operator int() { return 42; }
+};
+void g() {
+  constexpr A a;
+  // FIXME: OK, not odr-usable from a default template argument, and not 
odr-used
+  (void)[=] {};
+  // since-cxx20-error@-1 {{call to deleted constructor of 'const A'}}
+  //   since-cxx20-note@#cwg2883-A-copy-ctor {{'A' has been explicitly marked 
deleted here}}
+}
+#endif
+} // namespace cwg2883
+
+namespace cwg2885 { // cwg2885: 16 tentatively ready 2024-05-31
+#if __cplusplus >= 202002L
+template 
+struct A {
+  A() requires (false) = default;
+  A() : t(42) {}
+  T t;
+};
+
+struct B : A {};
+static_assert(!__is_trivially_constructible(B));
+#endif
+} // namespace cwg2885
+
+namespace cwg2886 { // cwg2886: 9 tentatively ready 2024-05-31
+#if __cplusplus >= 201103L
+struct C {
+  C() = default;
+  ~C() noexcept(false) = default;
+};
+
+static_assert(noexcept(C()), "");
+#endif
+} // namespace cwg2886
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 744d22959db42..4d94ac5a1ac1d 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -17071,7 +17071,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2877.html";>28

[clang] [clang] Add tests for some CWG issues from 2024-05-31 telecon (PR #94167)

2024-06-02 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 80303cb - [clang-format] Handle attributes before lambda return arrow (#94119)

2024-06-02 Thread via cfe-commits

Author: Owen Pan
Date: 2024-06-02T12:26:10-07:00
New Revision: 80303cb287e2c52c7bf4923bc61ebe25b2421bdc

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

LOG: [clang-format] Handle attributes before lambda return arrow (#94119)

Fixes #92657.

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 5c0ff0f6132b2..053fd3d4df559 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2236,7 +2236,7 @@ bool UnwrappedLineParser::tryToParseLambda() {
   bool InTemplateParameterList = false;
 
   while (FormatTok->isNot(tok::l_brace)) {
-if (FormatTok->isTypeName(LangOpts)) {
+if (FormatTok->isTypeName(LangOpts) || FormatTok->isAttribute()) {
   nextToken();
   continue;
 }

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 59f1ff6a4b296..6057d5b724bf9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -22664,6 +22664,7 @@ TEST_F(FormatTest, FormatsLambdas) {
   verifyFormat("SomeFunction({[]() -> int *[] { return {}; }});");
   verifyFormat("SomeFunction({[]() -> int (*)[] { return {}; }});");
   verifyFormat("SomeFunction({[]() -> ns::type { return {}; }});");
+  verifyFormat("foo([&](u32 bar) __attribute__((always_inline)) -> void {});");
   verifyFormat("return int{[x = x]() { return x; }()};");
 
   // Lambdas with explicit template argument lists.

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 3339a749df3a5..df268f49e1eca 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1577,6 +1577,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   EXPECT_TOKEN(Tokens[2], tok::arrow, TT_TrailingReturnArrow);
   EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_LambdaLBrace);
 
+  Tokens = annotate("foo([&](u32 bar) __attribute__((attr)) -> void {});");
+  ASSERT_EQ(Tokens.size(), 22u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[15], tok::arrow, TT_TrailingReturnArrow);
+  EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace);
+
   Tokens = annotate("[]  () {}");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);



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


[clang] [clang-format] Handle attributes before lambda return arrow (PR #94119)

2024-06-02 Thread Owen Pan via cfe-commits

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


[clang] f06f016 - [clang-format][NFC] Add missing parens of __attribute in unit tests

2024-06-02 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-06-02T12:44:40-07:00
New Revision: f06f0164199d4a968d8336937cd5ef2c05946d8d

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

LOG: [clang-format][NFC] Add missing parens of __attribute in unit tests

Added: 


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

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 6057d5b724bf9..004ecb63f6620 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -14928,7 +14928,7 @@ TEST_F(FormatTest, 
UnderstandContextOfRecordTypeKeywords) {
   verifyFormat("union Z {\n  int n;\n} x;");
   verifyFormat("class MACRO Z {\n} n;");
   verifyFormat("class MACRO(X) Z {\n} n;");
-  verifyFormat("class __attribute__(X) Z {\n} n;");
+  verifyFormat("class __attribute__((X)) Z {\n} n;");
   verifyFormat("class __declspec(X) Z {\n} n;");
   verifyFormat("class A##B##C {\n} n;");
   verifyFormat("class alignas(16) Z {\n} n;");

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index df268f49e1eca..a3b2569d80633 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1994,11 +1994,11 @@ TEST_F(TokenAnnotatorTest, UnderstandHashInMacro) {
 
 TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacros) {
   // '__attribute__' has special handling.
-  auto Tokens = annotate("__attribute__(X) void Foo(void);");
-  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  auto Tokens = annotate("__attribute__((X)) void Foo(void);");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::kw___attribute, TT_Unknown);
   EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeLParen);
-  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_AttributeRParen);
 
   // Generic macro has no special handling in this location.
   Tokens = annotate("A(X) void Foo(void);");
@@ -2020,11 +2020,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacros) {
 
 TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCDecl) {
   // '__attribute__' has special handling.
-  auto Tokens = annotate("__attribute__(X) @interface Foo");
-  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  auto Tokens = annotate("__attribute__((X)) @interface Foo");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::kw___attribute, TT_Unknown);
   EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeLParen);
-  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_AttributeRParen);
 
   // Generic macro has no special handling in this location.
   Tokens = annotate("A(X) @interface Foo");
@@ -2048,11 +2048,11 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsAttributeMacrosOnObjCDecl) {
 
 TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCMethodDecl) {
   // '__attribute__' has special handling.
-  auto Tokens = annotate("- (id)init __attribute__(X);");
-  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  auto Tokens = annotate("- (id)init __attribute__((X));");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
   EXPECT_TOKEN(Tokens[5], tok::kw___attribute, TT_Unknown);
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_AttributeLParen);
-  EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_AttributeRParen);
 
   // Generic macro has no special handling in this location.
   Tokens = annotate("- (id)init A(X);");
@@ -2076,11 +2076,11 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsAttributeMacrosOnObjCMethodDecl) {
 
 TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCProperty) {
   // '__attribute__' has special handling.
-  auto Tokens = annotate("@property(weak) id delegate __attribute__(X);");
-  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  auto Tokens = annotate("@property(weak) id delegate __attribute__((X));");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
   EXPECT_TOKEN(Tokens[7], tok::kw___attribute, TT_Unknown);
   EXPECT_TOKEN(Tokens[8], tok::l_paren, TT_AttributeLParen);
-  EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TOKEN(Tokens[12], tok::r_paren, TT_AttributeRParen);
 
   // Generic macro has no special handling in this location.
   Tokens = annotate("@property(weak) id delegate A(X);");



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


[clang-tools-extra] fix(clang-tools-extra/**.py): fix comparison to None (PR #94013)

2024-06-02 Thread Eisuke Kawashima via cfe-commits

https://github.com/e-kwsm updated 
https://github.com/llvm/llvm-project/pull/94013

>From 0697c7c7976eb3c01c0f51495560ce6000176434 Mon Sep 17 00:00:00 2001
From: Eisuke Kawashima 
Date: Sat, 11 May 2024 23:57:11 +0900
Subject: [PATCH] fix(clang-tools-extra/**.py): fix comparison to None

from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations):

> Comparisons to singletons like None should always be done with is or
> is not, never the equality operators.
---
 .../docs/clang-tidy/checks/gen-static-analyzer-docs.py  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py 
b/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py
index 6545a3906fa50..53ecb60dec539 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py
+++ b/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py
@@ -47,7 +47,7 @@ def get_checkers(checkers_td, checkers_rst):
 parent_package_ = package["ParentPackage"]
 hidden = (checker["Hidden"] != 0) or (package["Hidden"] != 0)
 
-while parent_package_ != None:
+while parent_package_ is not None:
 parent_package = table_entries[parent_package_["def"]]
 checker_package_prefix = (
 parent_package["PackageName"] + "." + checker_package_prefix

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


[clang-tools-extra] fix(clang-tools-extra/**.py): fix comparison to None (PR #94013)

2024-06-02 Thread Eisuke Kawashima via cfe-commits


@@ -1071,7 +1071,7 @@ bool IdentifierNamingCheck::isParamInMainLikeFunction(
   if (!IsIntType(FDecl->parameters()[0]->getType()))
 return false;
   MainType Type = IsCharPtrPtr(FDecl->parameters()[1]->getType());
-  if (Type == None)
+  if (Type is None)

e-kwsm wrote:

Thank you for your review.

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


[clang] fix(80474): Clang crash on improper use of __array_extent (PR #94173)

2024-06-02 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/94173

Fixes #80474

>From b4f5d6d43d369649711cece6057c8fe2758a5a89 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 3 Jun 2024 00:22:02 +0300
Subject: [PATCH] fix(80474): use expression error on incomplete __array_extent

---
 clang/docs/ReleaseNotes.rst| 1 +
 clang/lib/Parse/ParseExprCXX.cpp   | 3 +++
 clang/test/SemaCXX/incomplete-array-extent.cpp | 5 +
 3 files changed, 9 insertions(+)
 create mode 100644 clang/test/SemaCXX/incomplete-array-extent.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c700d23257bf..32515fbac64f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -823,6 +823,7 @@ Bug Fixes to C++ Support
   differering by their constraints when only one of these function was 
variadic.
 - Fix a crash when a variable is captured by a block nested inside a lambda. 
(Fixes #GH93625).
 - Fixed a type constraint substitution issue involving a generic lambda 
expression. (#GH93821)
+- Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 1558e3dcb8974..6f21a4f9bd826 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -4011,6 +4011,9 @@ ExprResult Parser::ParseArrayTypeTrait() {
 ExprResult DimExpr = ParseExpression();
 T.consumeClose();
 
+if (DimExpr.isInvalid())
+  return ExprError();
+
 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(),
T.getCloseLocation());
   }
diff --git a/clang/test/SemaCXX/incomplete-array-extent.cpp 
b/clang/test/SemaCXX/incomplete-array-extent.cpp
new file mode 100644
index 0..d59800f67a6ae
--- /dev/null
+++ b/clang/test/SemaCXX/incomplete-array-extent.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -std=c++11 %s
+
+auto f() { // expected-error {{'auto' return without trailing return type; 
deduced return types are a C++14 extension}}
+  return __array_extent(int, ); // expected-error {{expected expression}}
+}

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


[clang] fix(80474): Clang crash on improper use of __array_extent (PR #94173)

2024-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #80474

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Parse/ParseExprCXX.cpp (+3) 
- (added) clang/test/SemaCXX/incomplete-array-extent.cpp (+5) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c700d23257bf..32515fbac64f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -823,6 +823,7 @@ Bug Fixes to C++ Support
   differering by their constraints when only one of these function was 
variadic.
 - Fix a crash when a variable is captured by a block nested inside a lambda. 
(Fixes #GH93625).
 - Fixed a type constraint substitution issue involving a generic lambda 
expression. (#GH93821)
+- Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 1558e3dcb8974..6f21a4f9bd826 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -4011,6 +4011,9 @@ ExprResult Parser::ParseArrayTypeTrait() {
 ExprResult DimExpr = ParseExpression();
 T.consumeClose();
 
+if (DimExpr.isInvalid())
+  return ExprError();
+
 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(),
T.getCloseLocation());
   }
diff --git a/clang/test/SemaCXX/incomplete-array-extent.cpp 
b/clang/test/SemaCXX/incomplete-array-extent.cpp
new file mode 100644
index 0..d59800f67a6ae
--- /dev/null
+++ b/clang/test/SemaCXX/incomplete-array-extent.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -std=c++11 %s
+
+auto f() { // expected-error {{'auto' return without trailing return type; 
deduced return types are a C++14 extension}}
+  return __array_extent(int, ); // expected-error {{expected expression}}
+}

``




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


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

2024-06-02 Thread Owen Pan via cfe-commits


@@ -3850,6 +3850,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
&Style) {
   // the sequence "<::" will be unconditionally treated as "[:".
   // Cf. Lexer::LexTokenInternal.
   LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.RawStringLiterals = LexingStd >= FormatStyle::LS_Cpp11;

owenca wrote:

So can undo the change to Format.cpp?

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


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

2024-06-02 Thread Owen Pan via cfe-commits

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


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

2024-06-02 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-06-02 Thread Owen Pan via cfe-commits


@@ -803,6 +803,60 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
   tok::kw_switch);
   };
+  // Detecting functions is brittle. It would be better if we could annotate
+  // the LParen type of functions/calls.
+  const auto IsFunctionDeclParen = [&](const FormatToken &Tok) {
+return Tok.is(tok::l_paren) && Tok.Previous &&
+   (Tok.Previous->is(TT_FunctionDeclarationName) ||
+(Tok.Previous->Previous &&
+ Tok.Previous->Previous->is(tok::coloncolon) &&
+ Tok.Previous->Previous->Previous &&
+ 
Tok.Previous->Previous->Previous->is(TT_FunctionDeclarationName)));

owenca wrote:

Use `endsSequence()` instead.

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


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-06-02 Thread Owen Pan via cfe-commits


@@ -803,6 +803,60 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
   tok::kw_switch);
   };
+  // Detecting functions is brittle. It would be better if we could annotate
+  // the LParen type of functions/calls.
+  const auto IsFunctionDeclParen = [&](const FormatToken &Tok) {

owenca wrote:

Drop the first `const`.

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


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-06-02 Thread Owen Pan via cfe-commits


@@ -803,6 +803,60 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
   tok::kw_switch);
   };
+  // Detecting functions is brittle. It would be better if we could annotate
+  // the LParen type of functions/calls.
+  const auto IsFunctionDeclParen = [&](const FormatToken &Tok) {
+return Tok.is(tok::l_paren) && Tok.Previous &&
+   (Tok.Previous->is(TT_FunctionDeclarationName) ||
+(Tok.Previous->Previous &&
+ Tok.Previous->Previous->is(tok::coloncolon) &&
+ Tok.Previous->Previous->Previous &&
+ 
Tok.Previous->Previous->Previous->is(TT_FunctionDeclarationName)));
+  };
+  const auto IsLambdaParameterList = [](const FormatToken *Left) {

owenca wrote:

Drop the first `const`.

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


[clang] 2fbc9f2 - [clang-format][doc] Clean up quotes, etc.

2024-06-02 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-06-02T16:45:17-07:00
New Revision: 2fbc9f217e5fe8db8444a87dbd7138a768b8aa85

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

LOG: [clang-format][doc] Clean up quotes, etc.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 1a7d0e6a05e31..677dac25df68e 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1799,8 +1799,8 @@ the configuration (without a prefix: ``Auto``).
 Never merge functions into a single line.
 
   * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
-Only merge functions defined inside a class. Same as "inline",
-except it does not implies "empty": i.e. top level empty functions
+Only merge functions defined inside a class. Same as ``inline``,
+except it does not implies ``empty``: i.e. top level empty functions
 are not merged either.
 
 .. code-block:: c++
@@ -1825,7 +1825,7 @@ the configuration (without a prefix: ``Auto``).
   }
 
   * ``SFS_Inline`` (in configuration: ``Inline``)
-Only merge functions defined inside a class. Implies "empty".
+Only merge functions defined inside a class. Implies ``empty``.
 
 .. code-block:: c++
 
@@ -2042,7 +2042,7 @@ the configuration (without a prefix: ``Auto``).
 
   .. code-block:: yaml
 
-AttributeMacros: ['__capability', '__output', '__unused']
+AttributeMacros: [__capability, __output, __unused]
 
 .. _BinPackArguments:
 
@@ -3802,7 +3802,7 @@ the configuration (without a prefix: ``Auto``).
 
   .. code-block:: yaml
 
-ForEachMacros: ['RANGES_FOR', 'FOREACH']
+ForEachMacros: [RANGES_FOR, FOREACH]
 
   For example: BOOST_FOREACH.
 
@@ -3825,7 +3825,7 @@ the configuration (without a prefix: ``Auto``).
 
   .. code-block:: yaml
 
-IfMacros: ['IF']
+IfMacros: [IF]
 
   For example: `KJ_IF_MAYBE
   `_
@@ -4374,7 +4374,7 @@ the configuration (without a prefix: ``Auto``).
 
   .. code-block:: yaml
 
-JavaImportGroups: ['com.example', 'com', 'org']
+JavaImportGroups: [com.example, com, org]
 
 
   .. code-block:: java
@@ -4438,7 +4438,7 @@ the configuration (without a prefix: ``Auto``).
  VeryLongImportsAreAnnoying,
  VeryLongImportsAreAnnoying,
  VeryLongImportsAreAnnoying,
- } from 'some/module.js'
+ } from "some/module.js"
 
  false:
  import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, 
VeryLongImportsAreAnnoying,} from "some/module.js"
@@ -5088,7 +5088,7 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: yaml
 
-  QualifierOrder: ['inline', 'static', 'type', 'const']
+  QualifierOrder: [inline, static, type, const]
 
 
 .. code-block:: c++
@@ -5117,16 +5117,16 @@ the configuration (without a prefix: ``Auto``).
 
   .. note::
 
-   it MUST contain 'type'.
+   It must contain ``type``.
 
-  Items to the left of 'type' will be placed to the left of the type and
-  aligned in the order supplied. Items to the right of 'type' will be
+  Items to the left of ``type`` will be placed to the left of the type and
+  aligned in the order supplied. Items to the right of ``type`` will be
   placed to the right of the type and aligned in the order supplied.
 
 
   .. code-block:: yaml
 
-QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
+QualifierOrder: [inline, static, type, const, volatile]
 
 .. _RawStringFormats:
 
@@ -5138,10 +5138,10 @@ the configuration (without a prefix: ``Auto``).
   name will be reformatted assuming the specified language based on the
   style for that language defined in the .clang-format file. If no style has
   been defined in the .clang-format file for the specific language, a
-  predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
-  found, the formatting is based on llvm style. A matching delimiter takes
-  precedence over a matching enclosing function name for determining the
-  language of the raw string contents.
+  predefined style given by ``BasedOnStyle`` is used. If ``BasedOnStyle`` is
+  not found, the formatting is based on ``LLVM`` style. A matching delimiter
+  takes precedence over a matching enclosing function name for determining
+  the language of the raw string contents.
 
   If a canonical delimiter is specified, occurrences of other delimiters for
   the same language will be updated to the canonical if possible.
@@ -5156,17 +5156,17 @@ the configuration (without a prefix: ``Auto``).
 RawStringFormats:
   - Language: TextProto
   Delimiters:
-  

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-02 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From b55d09f4baa5f0a5cbe9b2614c23cc0ab5f2ef58 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  | 78 +-
 clang/include/clang/Format/Format.h | 89 +++--
 clang/lib/Format/Format.cpp | 36 -
 clang/lib/Format/TokenAnnotator.cpp | 12 ++-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  6 +-
 clang/unittests/Format/ConfigParseTest.cpp  |  9 ++-
 clang/unittests/Format/FormatTest.cpp   | 42 +-
 7 files changed, 253 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6d092219877f9..bf0088203dd54 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6028,12 +6028,84 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting Record
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBlock:
+
+**SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
+  If ``true``, spaces will be inserted into ``{}`` for record declarations
+  and blocks. This option is **deprecated**. The previous behavior is
+  preserved by using ``SpaceInEmptyBraces`` with ``Custom`` and by setting
+  ``Record`` on ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   T x{};
+   while (true) {}
+   struct Unit {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Block: true
+  Record: true
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Block: true
+  Record: true
+
+  * ``bool Block`` Put a space in empty braces of code blocks and record 
declarations.
+
+.. code-block:: c++
+
+   true:  false:
+   int f() { }vs. int f() {}
+   struct Unit {};struct Unit {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 274b45d1bc586..8b623eb2cb4bc 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4487,13 +4487,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved by 
using
+  /// ``SpaceInEmptyBraces`` with ``Custom`` and by setting Record
+  /// ``SpaceInEmptyBracesOptions`` to ``true``.
   /// \version 10
-  bool SpaceInEmptyBlock;
+  // bool SpaceInEmptyBlock;
 
   /// If ``true``, spaces may be inserted into ``()``.
   /// This option is **deprecated**. See ``InEmptyParentheses`` of
@@ -4715,6 +4713,82 @@ struct FormatStyle {
   /// \version 17
   SpacesInParensCustom SpacesInParensOptions;
 
+  /// Different ways to put a space in empty braces.
+  enum SpaceInEmptyBracesStyle : int8_t {

[clang] d7d2d4f - [clang-format] Fix documentation build error

2024-06-02 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-06-02T18:03:12-07:00
New Revision: d7d2d4f53fc79b4b58e8d8d08151b577c3699d4a

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

LOG: [clang-format] Fix documentation build error

https://github.com/llvm/llvm-project/actions/runs/9342063971/job/25709589592

Added: 


Modified: 
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 1e220ce0749b0..9bae252df366c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4806,6 +4806,7 @@ struct FormatStyle {
   ///   TableGenBreakInsideDAGArg: BreakAll
   ///   TableGenBreakingDAGArgOperators: [ins, outs]
   /// \endcode
+  ///
   /// makes the line break only occurs inside DAGArgs beginning with the
   /// specified identifiers ``ins`` and ``outs``.
   ///



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


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-02 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 5d409bcd0966a7581effdf1488c2f4cfa32aebc6 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  | 78 +++-
 clang/include/clang/Format/Format.h | 82 +++--
 clang/lib/Format/Format.cpp | 36 -
 clang/lib/Format/TokenAnnotator.cpp | 12 ++-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  6 +-
 clang/unittests/Format/ConfigParseTest.cpp  |  9 ++-
 clang/unittests/Format/FormatTest.cpp   | 42 ++-
 7 files changed, 246 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6d092219877f9..bf0088203dd54 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6028,12 +6028,84 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting Record
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBlock:
+
+**SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
+  If ``true``, spaces will be inserted into ``{}`` for record declarations
+  and blocks. This option is **deprecated**. The previous behavior is
+  preserved by using ``SpaceInEmptyBraces`` with ``Custom`` and by setting
+  ``Record`` on ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   T x{};
+   while (true) {}
+   struct Unit {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Block: true
+  Record: true
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Block: true
+  Record: true
+
+  * ``bool Block`` Put a space in empty braces of code blocks and record 
declarations.
+
+.. code-block:: c++
+
+   true:  false:
+   int f() { }vs. int f() {}
+   struct Unit {};struct Unit {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 274b45d1bc586..b63ddd7e2b92b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4487,13 +4487,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved by 
using
+  /// ``SpaceInEmptyBraces`` with ``Custom`` and by setting Record
+  /// ``SpaceInEmptyBracesOptions`` to ``true``.
   /// \version 10
-  bool SpaceInEmptyBlock;
+  // bool SpaceInEmptyBlock;
 
   /// If ``true``, spaces may be inserted into ``()``.
   /// This option is **deprecated**. See ``InEmptyParentheses`` of
@@ -4715,6 +4713,75 @@ struct FormatStyle {
   /// \version 17
   SpacesInParensCustom SpacesInParensOptions;
 
+  /// Different ways to put a space in empty braces.
+  enum SpaceInEmptyBracesStyle : int8_t

[clang] [llvm] [RISCV] Add Smcsrind and Sscsrind extension (PR #93952)

2024-06-02 Thread Pengcheng Wang via cfe-commits

wangpc-pp wrote:

> Specification link: https://github.com/riscvarchive/riscv-indirect-csr-access

You may need to update link to 
https://github.com/riscv/riscv-isa-manual/blob/main/src/indirect-csr.adoc.

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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 Thread via cfe-commits

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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 Thread via cfe-commits

https://github.com/Sirraide commented:

In addition to what I’ve pointed out below, there are a few more things to be 
done:
- This needs a release note (in `clang/docs/ReleaseNotes.rst`, probably under 
the ‘Improvements to Clang’s Diagnostics’ section).
- I find it hard to believe that the test you added is the only thing affected 
by this; it’s very likely that there are other tests that are failing now 
because you also need to add the diagnostic there; please run the Clang test 
suite locally (e.g. `ninja check-clang` if you’re using Ninja as your 
generator) and fix any tests that this is probably breaking.
- Some more tests, including tests involving templates, would also be a good 
idea.

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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 Thread via cfe-commits


@@ -13587,10 +13587,22 @@ static bool CheckForModifiableLvalue(Expr *E, 
SourceLocation Loc, Sema &S) {
   SourceRange Assign;
   if (Loc != OrigLoc)
 Assign = SourceRange(OrigLoc, OrigLoc);
-  if (NeedType)
+  if (NeedType) {
 S.Diag(Loc, DiagID) << E->getType() << E->getSourceRange() << Assign;
-  else
+  } else {
+ExprResult Deref;
+unsigned FixitDiagID = 0;
+{
+  Sema::TentativeAnalysisScope Trap(S);
+  Deref = S.ActOnUnaryOp(S.getCurScope(), Loc, tok::star, E);
+}
 S.Diag(Loc, DiagID) << E->getSourceRange() << Assign;
+if (Deref.isUsable() &&
+Deref.get()->isModifiableLvalue(S.Context, &Loc) == Expr::MLV_Valid) {
+  FixitDiagID = diag::note_typecheck_expression_not_modifiable_lvalue;
+  S.Diag(Loc, FixitDiagID) << E->getSourceRange() << Assign;

Sirraide wrote:

The `FixitDiagID` can just be inlined here.

This is also missing the actual fix-it hint; I’d suggest looking for uses of 
`FixItHint::CreateInsertion` and working with that.

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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 Thread via cfe-commits


@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+

Sirraide wrote:

Judging by these here, this is going in the right direction, though I would 
also want to see some more tests for other expressions that are not themselves 
modifiable lvalues, and also in other contexts that require modifiable lvalues, 
e.g.
```c++
reinterpret_cast(42) += 3;
```
There are some more in the description of the issue iirc, but feel also free to 
think of some more cases to test.

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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-02 Thread via cfe-commits


@@ -8777,6 +8777,9 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : 
Error<
 def err_typecheck_lvalue_casts_not_supported : Error<
   "assignment to cast is illegal, lvalue casts are not supported">;
 
+def note_typecheck_expression_not_modifiable_lvalue : Note<
+  "dereference the pointer to modify">; 

Sirraide wrote:

```suggestion
  "add '*' to dereference it">; 
```
There is a chance that this isn’t a pointer, so something like this might work 
a bit better, though it is admittedly also a bit more vague...

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


[clang] [llvm] [RISCV] Add Smcsrind and Sscsrind extension (PR #93952)

2024-06-02 Thread via cfe-commits

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


[clang] fix(80474): Clang crash on improper use of __array_extent (PR #94173)

2024-06-02 Thread via cfe-commits


@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -std=c++11 %s
+
+auto f() { // expected-error {{'auto' return without trailing return type; 
deduced return types are a C++14 extension}}

Sirraide wrote:

I’d set the standard version to `C++14` or later to avoid unrelated diagnostics

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


[clang] fix(80474): Clang crash on improper use of __array_extent (PR #94173)

2024-06-02 Thread via cfe-commits

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


[clang] fix(80474): Clang crash on improper use of __array_extent (PR #94173)

2024-06-02 Thread via cfe-commits

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

LGTM 

Though I do wonder how many other type traits are also affected by this, 
because at least the function below this one also doesn’t seem to check for 
parse errors... it would probably make sense to take a look at the rest of them 
too, but that can also be a separate pr.

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


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

2024-06-02 Thread via cfe-commits


@@ -3850,6 +3850,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
&Style) {
   // the sequence "<::" will be unconditionally treated as "[:".
   // Cf. Lexer::LexTokenInternal.
   LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.RawStringLiterals = LexingStd >= FormatStyle::LS_Cpp11;

Sirraide wrote:

I think I’ve already done that; I just haven’t commited that yet iirc.

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


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

2024-06-02 Thread via cfe-commits

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


[clang] remove goma support from clang (PR #93942)

2024-06-02 Thread Takuto Ikuta via cfe-commits

atetubou wrote:

I don't have merge permission. Could someone merge this PR if this looks good?

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


[clang-tools-extra] [clang-tidy] Add `bugprone-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

2024-06-02 Thread via cfe-commits

https://github.com/Discookie updated 
https://github.com/llvm/llvm-project/pull/91951

>From 69cbd3da19eb0f8eb6758782b46daf99b5b79ea4 Mon Sep 17 00:00:00 2001
From: Viktor 
Date: Mon, 6 May 2024 06:11:58 +
Subject: [PATCH 01/14] Add `bugprone-virtual-arithmetic` check

Finds pointer arithmetic on classes that declare a virtual function.
---
 .../bugprone/BugproneTidyModule.cpp   |  3 ++
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/VirtualArithmeticCheck.cpp   | 46 +
 .../bugprone/VirtualArithmeticCheck.h | 30 +++
 .../checks/bugprone/virtual-arithmetic.rst| 50 +++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/bugprone/virtual-arithmetic.cpp  | 45 +
 7 files changed, 176 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/VirtualArithmeticCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/VirtualArithmeticCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/virtual-arithmetic.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/virtual-arithmetic.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 1b92d2e60cc17..813f6720074ae 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -91,6 +91,7 @@
 #include "UnusedRaiiCheck.h"
 #include "UnusedReturnValueCheck.h"
 #include "UseAfterMoveCheck.h"
+#include "VirtualArithmeticCheck.h"
 #include "VirtualNearMissCheck.h"
 
 namespace clang::tidy {
@@ -254,6 +255,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "bugprone-unused-return-value");
 CheckFactories.registerCheck("bugprone-use-after-move");
+CheckFactories.registerCheck(
+"bugprone-virtual-arithmetic");
 CheckFactories.registerCheck(
 "bugprone-virtual-near-miss");
   }
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 2d303191f8865..ec1f3231e7990 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -87,6 +87,7 @@ add_clang_library(clangTidyBugproneModule
   UnusedRaiiCheck.cpp
   UnusedReturnValueCheck.cpp
   UseAfterMoveCheck.cpp
+  VirtualArithmeticCheck.cpp
   VirtualNearMissCheck.cpp
 
   LINK_LIBS
diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualArithmeticCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/VirtualArithmeticCheck.cpp
new file mode 100644
index 0..57347af2b5881
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualArithmeticCheck.cpp
@@ -0,0 +1,46 @@
+//===--- VirtualArithmeticCheck.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 "VirtualArithmeticCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void VirtualArithmeticCheck::registerMatchers(MatchFinder *Finder) {
+  const auto PointerExprWithVirtualMethod =
+  expr(hasType(pointerType(pointee(hasDeclaration(
+   cxxRecordDecl(hasMethod(isVirtualAsWritten(
+  .bind("pointer");
+
+  const auto ArraySubscript =
+  arraySubscriptExpr(hasBase(PointerExprWithVirtualMethod));
+
+  const auto BinaryOperators =
+  binaryOperator(hasAnyOperatorName("+", "-", "+=", "-="),
+ hasEitherOperand(PointerExprWithVirtualMethod));
+
+  const auto UnaryOperators =
+  unaryOperator(hasAnyOperatorName("++", "--"),
+hasUnaryOperand(PointerExprWithVirtualMethod));
+
+  Finder->addMatcher(
+  expr(anyOf(ArraySubscript, BinaryOperators, UnaryOperators)), this);
+}
+
+void VirtualArithmeticCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *PointerExpr = Result.Nodes.getNodeAs("pointer");
+
+  diag(PointerExpr->getBeginLoc(),
+   "pointer arithmetic on class that declares a virtual function, "
+   "undefined behavior if the pointee is a different class");
+}
+
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualArithmeticCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/VirtualArithmeticCheck.h
new file mode 100644
index 0..6a5f86a391747
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualArithmeticCheck.h
@@ -0,0 +1,30 @@
+//===--- VirtualArithmeticCheck.h - clang-tidy---*- C++ 
-*-===//
+//
+/

[clang-tools-extra] [clang-tidy] Add `bugprone-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

2024-06-02 Thread via cfe-commits


@@ -0,0 +1,49 @@
+//===--- VirtualArithmeticCheck.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 "VirtualArithmeticCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void VirtualArithmeticCheck::registerMatchers(MatchFinder *Finder) {
+  const auto PointerExprWithVirtualMethod =
+  expr(hasType(pointerType(pointee(hasDeclaration(
+   cxxRecordDecl(hasMethod(isVirtualAsWritten(
+  .bind("pointer");
+
+  const auto ArraySubscript =
+  arraySubscriptExpr(hasBase(PointerExprWithVirtualMethod));
+
+  const auto BinaryOperators =
+  binaryOperator(hasAnyOperatorName("+", "-", "+=", "-="),
+ hasEitherOperand(PointerExprWithVirtualMethod));
+
+  const auto UnaryOperators =
+  unaryOperator(hasAnyOperatorName("++", "--"),
+hasUnaryOperand(PointerExprWithVirtualMethod));
+
+  Finder->addMatcher(
+  expr(anyOf(ArraySubscript, BinaryOperators, UnaryOperators)), this);
+}
+
+void VirtualArithmeticCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *PointerExpr = Result.Nodes.getNodeAs("pointer");
+  const CXXRecordDecl *PointeeType =
+  PointerExpr->getType()->getPointeeType()->getAsCXXRecordDecl();
+
+  diag(PointerExpr->getBeginLoc(),
+   "pointer arithmetic on class '%0' that declares a virtual function, "
+   "undefined behavior if the pointee is a different class")
+  << PointeeType->getName();

Discookie wrote:

Tidy supports source ranges like that!? I never knew, thank you! Added.
I don't think I've seen support for it in CodeChecker, that's why I was 
surprised. Will have to follow up on that.

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


[clang-tools-extra] [clang-tidy] Add `bugprone-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

2024-06-02 Thread via cfe-commits


@@ -0,0 +1,60 @@
+.. title:: clang-tidy - bugprone-pointer-arithmetic-on-polymorphic-object
+
+bugprone-pointer-arithmetic-on-polymorphic-object
+=
+
+Finds pointer arithmetic performed on classes that declare a virtual function.
+
+Pointer arithmetic on polymorphic objects where the pointer's static type is 
+different from its dynamic type is undefined behavior, as the two types can
+have different sizes.
+Finding pointers where the static type contains a virtual member function is a
+good heuristic, as the pointer is likely to point to a different, derived 
class.
+
+Example:
+
+.. code-block:: c++
+
+  struct Base {
+virtual void ~Base();
+  };
+
+  struct Derived : public Base {};
+
+  void foo() {
+Base *b = new Derived[10];
+
+b += 1;
+// warning: pointer arithmetic on class that declares a virtual function,
+//  which can result in undefined behavior if the pointee is a
+//  different class
+
+delete[] static_cast(b);
+  }
+
+This check corresponds to the SEI Cert rule `CTR56-CPP: Do not use pointer 
arithmetic on polymorphic objects 
`_.

Discookie wrote:

Even after the `Options` subheading? `bugprone-reserved-identifier` has it 
before the `Options`, would look weirder at the end of it.

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


[clang-tools-extra] [clang-tidy] Add `bugprone-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

2024-06-02 Thread via cfe-commits


@@ -0,0 +1,60 @@
+.. title:: clang-tidy - bugprone-pointer-arithmetic-on-polymorphic-object
+
+bugprone-pointer-arithmetic-on-polymorphic-object
+=
+
+Finds pointer arithmetic performed on classes that declare a virtual function.
+
+Pointer arithmetic on polymorphic objects where the pointer's static type is 
+different from its dynamic type is undefined behavior, as the two types can
+have different sizes.
+Finding pointers where the static type contains a virtual member function is a
+good heuristic, as the pointer is likely to point to a different, derived 
class.
+
+Example:
+
+.. code-block:: c++
+
+  struct Base {
+virtual void ~Base();
+  };
+
+  struct Derived : public Base {};
+
+  void foo() {
+Base *b = new Derived[10];
+
+b += 1;
+// warning: pointer arithmetic on class that declares a virtual function,
+//  which can result in undefined behavior if the pointee is a
+//  different class
+
+delete[] static_cast(b);
+  }
+
+This check corresponds to the SEI Cert rule `CTR56-CPP: Do not use pointer 
arithmetic on polymorphic objects 
`_.
+
+Options
+---
+
+.. option:: MatchInheritedVirtualFunctions
+
+  When ``true``, all classes with a virtual function are considered,
+  even if the function is inherited.
+  Classes that do not declare a new virtual function are excluded
+  by default, as they make up the majority of false positives.

Discookie wrote:

Default `false`, added.

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


[clang-tools-extra] [clang-tidy] Add `bugprone-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

2024-06-02 Thread via cfe-commits


@@ -0,0 +1,49 @@
+//===--- VirtualArithmeticCheck.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 "VirtualArithmeticCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void VirtualArithmeticCheck::registerMatchers(MatchFinder *Finder) {
+  const auto PointerExprWithVirtualMethod =
+  expr(hasType(pointerType(pointee(hasDeclaration(
+   cxxRecordDecl(hasMethod(isVirtualAsWritten(
+  .bind("pointer");
+
+  const auto ArraySubscript =
+  arraySubscriptExpr(hasBase(PointerExprWithVirtualMethod));
+
+  const auto BinaryOperators =
+  binaryOperator(hasAnyOperatorName("+", "-", "+=", "-="),
+ hasEitherOperand(PointerExprWithVirtualMethod));
+
+  const auto UnaryOperators =
+  unaryOperator(hasAnyOperatorName("++", "--"),
+hasUnaryOperand(PointerExprWithVirtualMethod));
+
+  Finder->addMatcher(
+  expr(anyOf(ArraySubscript, BinaryOperators, UnaryOperators)), this);

Discookie wrote:

Added `isAbstract`, and fixed `unless(isFinal())` as well (although with the 
amount of `final` classes in my test projects, it might even be slower in 
practice...).

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


[clang] [cmake] Respect CLANG_LINK_CLANG_DYLIB for objlibs (PR #93454)

2024-06-02 Thread Nikita Popov via cfe-commits

nikic wrote:

ping

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


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-06-02 Thread Chuanqi Xu via cfe-commits

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

I feel good with this too. 

But if later you have similar multiple consecutive large NFC patches like this, 
I'll recommend you send the PR as stacked PR and then we can land the 
continuously. It'll help the downstream project slightly.

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


[clang] [clang-tools-extra] [libcxx] [clang][Modules] Remove unnecessary includes of `Module.h` (PR #93417)

2024-06-02 Thread Chuanqi Xu via cfe-commits

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

LGTM

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


[clang] [clang-tools-extra] [libcxx] [clang][Modules] Remove unnecessary includes of `Module.h` (PR #93417)

2024-06-02 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> Is there any additional work needed on this before it can be merged?

No, it looks good. I'll merge this.

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


[clang] aaa4ff8 - [clang][Modules] Remove unnecessary includes of `Module.h` (#93417)

2024-06-02 Thread via cfe-commits

Author: David Stone
Date: 2024-06-03T14:49:04+08:00
New Revision: aaa4ff88d6a2ef69053211e7bbee623f24723b51

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

LOG: [clang][Modules] Remove unnecessary includes of `Module.h` (#93417)

Added: 


Modified: 
clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp
clang/include/clang/APINotes/APINotesManager.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/include/clang/Serialization/ASTWriter.h
clang/include/clang/Serialization/ModuleManager.h
clang/lib/APINotes/APINotesManager.cpp
clang/lib/AST/ASTDumper.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/ExtractAPI/API.cpp
libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp 
b/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp
index 147d9abe69137..32942e6bbfdc8 100644
--- a/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp
@@ -25,7 +25,6 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/LLVM.h"
-#include "clang/Basic/Module.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
@@ -42,7 +41,11 @@
 #include 
 #include 
 
-namespace clang::clangd {
+namespace clang {
+
+class Module;
+
+namespace clangd {
 namespace {
 struct Inclusion {
   Inclusion(const SourceManager &SM, SourceLocation HashLoc,
@@ -170,4 +173,5 @@ TEST(ReplayPreambleTest, IncludesAndSkippedFiles) {
   }
 }
 } // namespace
-} // namespace clang::clangd
+} // namespace clangd
+} // namespace clang

diff  --git a/clang/include/clang/APINotes/APINotesManager.h 
b/clang/include/clang/APINotes/APINotesManager.h
index 18375c9e51a17..98592438e90ea 100644
--- a/clang/include/clang/APINotes/APINotesManager.h
+++ b/clang/include/clang/APINotes/APINotesManager.h
@@ -9,7 +9,6 @@
 #ifndef LLVM_CLANG_APINOTES_APINOTESMANAGER_H
 #define LLVM_CLANG_APINOTES_APINOTESMANAGER_H
 
-#include "clang/Basic/Module.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -24,6 +23,7 @@ namespace clang {
 class DirectoryEntry;
 class FileEntry;
 class LangOptions;
+class Module;
 class SourceManager;
 
 namespace api_notes {

diff  --git 
a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h 
b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
index 27e9167ca1ad0..f8759bf2d8f25 100644
--- a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
+++ b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
@@ -17,7 +17,6 @@
 #ifndef LLVM_CLANG_EXTRACTAPI_SERIALIZATION_SYMBOLGRAPHSERIALIZER_H
 #define LLVM_CLANG_EXTRACTAPI_SERIALIZATION_SYMBOLGRAPHSERIALIZER_H
 
-#include "clang/Basic/Module.h"
 #include "clang/ExtractAPI/API.h"
 #include "clang/ExtractAPI/APIIgnoresList.h"
 #include "clang/ExtractAPI/Serialization/APISetVisitor.h"

diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 88192e439a3f0..fcc007d6f8637 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -18,7 +18,6 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/LLVM.h"
-#include "clang/Basic/Module.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/SemaConsumer.h"

diff  --git a/clang/include/clang/Serialization/ModuleManager.h 
b/clang/include/clang/Serialization/ModuleManager.h
index 3bd379acf7eda..d770bc52eaf4f 100644
--- a/clang/include/clang/Serialization/ModuleManager.h
+++ b/clang/include/clang/Serialization/ModuleManager.h
@@ -15,7 +15,6 @@
 #define LLVM_CLANG_SERIALIZATION_MODULEMANAGER_H
 
 #include "clang/Basic/LLVM.h"
-#include "clang/Basic/Module.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Serialization/ModuleFile.h"
 #include "llvm/ADT/DenseMap.h"

diff  --git a/clang/lib/APINotes/APINotesManager.cpp 
b/clang/lib/APINotes/APINotesManager.cpp
index 789bb97d81de0..039d09fa7cf57 100644
--- a/clang/lib/APINotes/APINotesManager.cpp
+++ b/clang/lib/APINotes/APINotesManager.cpp
@@ -12,6 +12,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/Module.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/SourceMgrAdapter.h"
 #include "clang/Basic/Version.h"

diff  --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp
index 6efc5bb92e28d..c8973fdeda352 100644
--- a/clang/lib/AST/

[clang] [clang-tools-extra] [libcxx] [clang][Modules] Remove unnecessary includes of `Module.h` (PR #93417)

2024-06-02 Thread Chuanqi Xu via cfe-commits

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


[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-06-02 Thread Chuanqi Xu via cfe-commits


@@ -1180,6 +1185,21 @@ bool CodeGenVTables::isVTableExternal(const 
CXXRecordDecl *RD) {
   TSK == TSK_ExplicitInstantiationDefinition)
 return false;
 
+  // Itanium C++ ABI [5.2.3]:
+  // Virtual tables for dynamic classes are emitted as follows:
+  //
+  // - If the class is templated, the tables are emitted in every object that
+  // references any of them.
+  // - Otherwise, if the class is attached to a module, the tables are uniquely
+  // emitted in the object for the module unit in which it is defined.
+  // - Otherwise, if the class has a key function (see below), the tables are
+  // emitted in the object for the translation unit containing the definition 
of
+  // the key function. This is unique if the key function is not inline.
+  // - Otherwise, the tables are emitted in every object that references any of
+  // them.
+  if (Module *M = RD->getOwningModule(); M && M->isNamedModule())

ChuanqiXu9 wrote:

Yeah, I agree it might be good conceptly. But given the clang header modules 
with object files are not widely used and the current patch may be somewhat 
impactful, I feel better to do that in the future when we really need to.

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


[clang] fix(80474): Clang crash on improper use of __array_extent (PR #94173)

2024-06-02 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/94173

>From b4f5d6d43d369649711cece6057c8fe2758a5a89 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 3 Jun 2024 00:22:02 +0300
Subject: [PATCH 1/2] fix(80474): use expression error on incomplete
 __array_extent

---
 clang/docs/ReleaseNotes.rst| 1 +
 clang/lib/Parse/ParseExprCXX.cpp   | 3 +++
 clang/test/SemaCXX/incomplete-array-extent.cpp | 5 +
 3 files changed, 9 insertions(+)
 create mode 100644 clang/test/SemaCXX/incomplete-array-extent.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c700d23257bf..32515fbac64f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -823,6 +823,7 @@ Bug Fixes to C++ Support
   differering by their constraints when only one of these function was 
variadic.
 - Fix a crash when a variable is captured by a block nested inside a lambda. 
(Fixes #GH93625).
 - Fixed a type constraint substitution issue involving a generic lambda 
expression. (#GH93821)
+- Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 1558e3dcb8974..6f21a4f9bd826 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -4011,6 +4011,9 @@ ExprResult Parser::ParseArrayTypeTrait() {
 ExprResult DimExpr = ParseExpression();
 T.consumeClose();
 
+if (DimExpr.isInvalid())
+  return ExprError();
+
 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(),
T.getCloseLocation());
   }
diff --git a/clang/test/SemaCXX/incomplete-array-extent.cpp 
b/clang/test/SemaCXX/incomplete-array-extent.cpp
new file mode 100644
index 0..d59800f67a6ae
--- /dev/null
+++ b/clang/test/SemaCXX/incomplete-array-extent.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -std=c++11 %s
+
+auto f() { // expected-error {{'auto' return without trailing return type; 
deduced return types are a C++14 extension}}
+  return __array_extent(int, ); // expected-error {{expected expression}}
+}

>From 5415766441ece7516cfea6d577988e73047873de Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 3 Jun 2024 09:58:00 +0300
Subject: [PATCH 2/2] use c++14 to reduce unnecessary diagnostics

---
 clang/test/SemaCXX/incomplete-array-extent.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/SemaCXX/incomplete-array-extent.cpp 
b/clang/test/SemaCXX/incomplete-array-extent.cpp
index d59800f67a6ae..8134af6b9251b 100644
--- a/clang/test/SemaCXX/incomplete-array-extent.cpp
+++ b/clang/test/SemaCXX/incomplete-array-extent.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -verify -std=c++11 %s
+// RUN: %clang_cc1 -verify -std=c++14 %s
 
-auto f() { // expected-error {{'auto' return without trailing return type; 
deduced return types are a C++14 extension}}
+auto f() {
   return __array_extent(int, ); // expected-error {{expected expression}}
 }

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


[clang] fix(80474): Clang crash on improper use of __array_extent (PR #94173)

2024-06-02 Thread Oleksandr T. via cfe-commits


@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -std=c++11 %s
+
+auto f() { // expected-error {{'auto' return without trailing return type; 
deduced return types are a C++14 extension}}

a-tarasyuk wrote:

Thanks for the review. I've updated test

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


[clang] 5161a3f - [clang][dataflow] Rewrite `getReferencedDecls()` with a `RecursiveASTVisitor`. (#93461)

2024-06-02 Thread via cfe-commits

Author: martinboehme
Date: 2024-06-03T08:59:09+02:00
New Revision: 5161a3f6e5e92c78c33aed5e38e0680a1a9b088e

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

LOG: [clang][dataflow] Rewrite `getReferencedDecls()` with a 
`RecursiveASTVisitor`. (#93461)

We previously had a hand-rolled recursive traversal here that was
exactly what
`RecursiveASTVistor` does anyway. Using the visitor not only eliminates
the
explicit traversal logic but also allows us to introduce a common
visitor base
class for `getReferencedDecls()` and `ResultObjectVisitor`, ensuring
that the
two are consistent in terms of the nodes they visit. Inconsistency
between these
two has caused crashes in the past when `ResultObjectVisitor` tried to
propagate
result object locations to entities that weren't modeled becasue
`getReferencedDecls()` didn't visit them.

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/ASTOps.h
clang/lib/Analysis/FlowSensitive/ASTOps.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h 
b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
index 05748f300a932..925b99af9141a 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
@@ -15,6 +15,7 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
 #include "llvm/ADT/DenseSet.h"
@@ -80,6 +81,52 @@ class RecordInitListHelper {
   std::optional ImplicitValueInitForUnion;
 };
 
+/// Specialization of `RecursiveASTVisitor` that visits those nodes that are
+/// relevant to the dataflow analysis; generally, these are the ones that also
+/// appear in the CFG.
+/// To start the traversal, call `TraverseStmt()` on the statement or body of
+/// the function to analyze. Don't call `TraverseDecl()` on the function 
itself;
+/// this won't work as `TraverseDecl()` contains code to avoid traversing 
nested
+/// functions.
+template 
+class AnalysisASTVisitor : public RecursiveASTVisitor {
+public:
+  bool shouldVisitImplicitCode() { return true; }
+
+  bool shouldVisitLambdaBody() const { return false; }
+
+  bool TraverseDecl(Decl *D) {
+// Don't traverse nested record or function declarations.
+// - We won't be analyzing code contained in these anyway
+// - We don't model fields that are used only in these nested declaration,
+//   so trying to propagate a result object to initializers of such fields
+//   would cause an error.
+if (isa_and_nonnull(D) || isa_and_nonnull(D))
+  return true;
+
+return RecursiveASTVisitor::TraverseDecl(D);
+  }
+
+  // Don't traverse expressions in unevaluated contexts, as we don't model
+  // fields that are only used in these.
+  // Note: The operand of the `noexcept` operator is an unevaluated operand, 
but
+  // nevertheless it appears in the Clang CFG, so we don't exclude it here.
+  bool TraverseDecltypeTypeLoc(DecltypeTypeLoc) { return true; }
+  bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc) { return true; }
+  bool TraverseCXXTypeidExpr(CXXTypeidExpr *) { return true; }
+  bool TraverseUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *) {
+return true;
+  }
+
+  bool TraverseBindingDecl(BindingDecl *BD) {
+// `RecursiveASTVisitor` doesn't traverse holding variables for
+// `BindingDecl`s by itself, so we need to tell it to.
+if (VarDecl *HoldingVar = BD->getHoldingVar())
+  TraverseDecl(HoldingVar);
+return RecursiveASTVisitor::TraverseBindingDecl(BD);
+  }
+};
+
 /// A collection of several types of declarations, all referenced from the same
 /// function.
 struct ReferencedDecls {

diff  --git a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp 
b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
index bd1676583eccc..38b5f51b7b2f0 100644
--- a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
@@ -188,90 +188,96 @@ static MemberExpr *getMemberForAccessor(const 
CXXMemberCallExpr &C) {
   return nullptr;
 }
 
-static void getReferencedDecls(const Decl &D, ReferencedDecls &Referenced) {
-  insertIfGlobal(D, Referenced.Globals);
-  insertIfFunction(D, Referenced.Functions);
-  if (const auto *Decomp = dyn_cast(&D))
-for (const auto *B : Decomp->bindings())
-  if (auto *ME = dyn_cast_or_null(B->getBinding()))
-// FIXME: should we be using `E->getFoundDecl()`?
-if (const auto *FD = dyn_cast(ME->getMemberDecl()))
-  Referenced.Fields.insert(FD);
-}
+class ReferencedDeclsVisitor
+: public AnalysisASTVisitor {
+public:
+  ReferencedDeclsVisitor(ReferencedDecls &Referenced)
+  : 

[clang] [clang][dataflow] Rewrite `getReferencedDecls()` with a `RecursiveASTVisitor`. (PR #93461)

2024-06-02 Thread via cfe-commits

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