[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-02 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From bd1b0b2a14afeb73755db3a7deb6bffd4f50778c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/3] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp |  2 +-
 clang/test/Interpreter/lambda.cpp   | 11 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 41d6304bd5f65..6343f17ed822a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -176,7 +176,7 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty())
   continue;
 // Check if we need to clean up the IdResolver chain.
 if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..8f49f870fddb6 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file

>From 1963cc341cd356f06a6c582235e47ac3cf144a63 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 16:43:45 +0530
Subject: [PATCH 2/3] Fix test as per review

---
 clang/test/Interpreter/lambda.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 8f49f870fddb6..7e8dcd61f20c8 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck %s
 
 extern "C" int printf(const char *, ...);
 
@@ -21,4 +21,7 @@ int x = 42;
 // expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
 auto capture = [&]() { return x * 2; };
 
+// Ensure valid C++ code before exiting
+x = 100;
+
 %quit
\ No newline at end of file

>From 45924cdddab5fdb89823792ebf5577469e474432 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 17:31:35 +0530
Subject: [PATCH 3/3] fix failing lambda.cpp

---
 clang/test/Interpreter/lambda.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 7e8dcd61f20c8..07eb6fb017360 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -18,7 +18,7 @@ auto r3 = l2();
 // Verify non-local lambda capture error is correctly reported
 int x = 42;
 
-// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+// expected-error {{non-local lambda expression cannot have a capture-default}}
 auto capture = [&]() { return x * 2; };
 
 // Ensure valid C++ code before exiting

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


[clang] [Clang] Separate implicit int conversion on negation sign to new diagnostic group (PR #139429)

2025-06-02 Thread Aaron Ballman via cfe-commits

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


[clang] 0ada5c7 - [Clang] Separate implicit int conversion on negation sign to new diagnostic group (#139429)

2025-06-02 Thread via cfe-commits

Author: Yutong Zhu
Date: 2025-06-02T07:27:32-04:00
New Revision: 0ada5c7b1a52afb668bc42dd2d5573e5805433d1

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

LOG: [Clang] Separate implicit int conversion on negation sign to new 
diagnostic group (#139429)

This PR reverts a change made in #126846. 

#126846 introduced an ``-Wimplicit-int-conversion`` diagnosis for 
```c++
int8_t x = something;
x = -x; // warning here
```

This is technically correct since -x could have a width of 9, but this
pattern is common in codebases.

Reverting this change would also introduce the false positive I fixed in
#126846:
```c++
bool b(signed char c) {
  return -c >= 128; // -c can be 128
}
```

This false positive is uncommon, so I think it makes sense to revert the
change.

Added: 
clang/test/Sema/implicit-int-conversion-on-int.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dc97883de05d0..91b89a0946555 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -601,6 +601,10 @@ Improvements to Clang's diagnostics
   trigger a ``'Blue' is deprecated`` warning, which can be turned off with
   ``-Wno-deprecated-declarations-switch-case``.
 
+- Split diagnosis of implicit integer comparison on negation to a new
+  diagnostic group ``-Wimplicit-int-comparison-on-negation``, grouped under
+  ``-Wimplicit-int-conversion``, so user can turn it off independently.
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 60c650583801a..be75b9ee6e3f6 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -116,9 +116,11 @@ def DeprecatedOFast : DiagGroup<"deprecated-ofast">;
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
+def ImplicitIntConversionOnNegation : 
DiagGroup<"implicit-int-conversion-on-negation">;
 def ImplicitIntConversion : DiagGroup<"implicit-int-conversion",
  [Shorten64To32,
-  
ObjCSignedCharBoolImplicitIntConversion]>;
+  ObjCSignedCharBoolImplicitIntConversion,
+  ImplicitIntConversionOnNegation]>;
 def ImplicitConstIntFloatConversion : 
DiagGroup<"implicit-const-int-float-conversion">;
 def ImplicitIntFloatConversion : DiagGroup<"implicit-int-float-conversion",
  [ImplicitConstIntFloatConversion]>;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index efc842bb4c42e..6f1e8d9fc74e6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4288,6 +4288,9 @@ def warn_impcast_integer_sign_conditional : Warning<
 def warn_impcast_integer_precision : Warning<
   "implicit conversion loses integer precision: %0 to %1">,
   InGroup, DefaultIgnore;
+def warn_impcast_integer_precision_on_negation : Warning<
+  "implicit conversion loses integer precision: %0 to %1 on negation">,
+  InGroup, DefaultIgnore;
 def warn_impcast_high_order_zero_bits : Warning<
   "higher order bits are zeroes after implicit conversion">,
   InGroup, DefaultIgnore;

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index aba39c0eb3299..3193359923fdb 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12304,6 +12304,12 @@ void Sema::CheckImplicitConversion(Expr *E, QualType 
T, SourceLocation CC,
 if (SourceMgr.isInSystemMacro(CC))
   return;
 
+if (const auto *UO = dyn_cast(E)) {
+  if (UO->getOpcode() == UO_Minus)
+return DiagnoseImpCast(
+*this, E, T, CC, diag::warn_impcast_integer_precision_on_negation);
+}
+
 if (TargetRange.Width == 32 && Context.getIntWidth(E->getType()) == 64)
   return DiagnoseImpCast(*this, E, T, CC, diag::warn_impcast_integer_64_32,
  /* pruneControlFlow */ true);

diff  --git a/clang/test/Sema/implicit-int-conversion-on-int.c 
b/clang/test/Sema/implicit-int-conversion-on-int.c
new file mode 100644
index 0..f555893d9e17a
--- /dev/null
+++ b/clang/test/Sema/implicit-int-conversion-on-int.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 %s -verify=expected -Wimplicit-int-conversion
+// RUN: %clang_cc1 %s -verify=none -Wimplicit-int-conversion 

[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-02 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From bd1b0b2a14afeb73755db3a7deb6bffd4f50778c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/4] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp |  2 +-
 clang/test/Interpreter/lambda.cpp   | 11 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 41d6304bd5f65..6343f17ed822a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -176,7 +176,7 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty())
   continue;
 // Check if we need to clean up the IdResolver chain.
 if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..8f49f870fddb6 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file

>From 1963cc341cd356f06a6c582235e47ac3cf144a63 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 16:43:45 +0530
Subject: [PATCH 2/4] Fix test as per review

---
 clang/test/Interpreter/lambda.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 8f49f870fddb6..7e8dcd61f20c8 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck %s
 
 extern "C" int printf(const char *, ...);
 
@@ -21,4 +21,7 @@ int x = 42;
 // expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
 auto capture = [&]() { return x * 2; };
 
+// Ensure valid C++ code before exiting
+x = 100;
+
 %quit
\ No newline at end of file

>From 45924cdddab5fdb89823792ebf5577469e474432 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 17:31:35 +0530
Subject: [PATCH 3/4] fix failing lambda.cpp

---
 clang/test/Interpreter/lambda.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 7e8dcd61f20c8..07eb6fb017360 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -18,7 +18,7 @@ auto r3 = l2();
 // Verify non-local lambda capture error is correctly reported
 int x = 42;
 
-// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+// expected-error {{non-local lambda expression cannot have a capture-default}}
 auto capture = [&]() { return x * 2; };
 
 // Ensure valid C++ code before exiting

>From 056555cb8ae70d01de6258aaf10cae754b33714c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 2 Jun 2025 16:59:55 +0530
Subject: [PATCH 4/4] print the value for x after the parsing failed error on
 capture

---
 clang/test/Interpreter/lambda.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 07eb6fb017360..7e5e1057e4c9e 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -21,7 +21,8 @@ int x = 42;
 // expected-error {{non-local lambda expression cannot have a capture-default}}
 auto capture = [&]() { return x * 2; };
 
-// Ensure valid C++ code before exiting
-x = 100;
+// Ensure interpreter continues and x is still valid
+printf("x = %d\n", x);
+// CHECK: x = 42
 
 %quit
\ No newline at end of file

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


[clang] e04e140 - [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (#122423)

2025-06-02 Thread via cfe-commits

Author: Younan Zhang
Date: 2025-06-02T17:10:07+08:00
New Revision: e04e140adb600add79b414f137a13af9d89c8c0d

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

LOG: [Clang] Reapply CWG2369 "Ordering between constraints and substitution" 
(#122423)

The previous approach broke code generation for the MS ABI due to an
unintended code path during constraint substitution. This time we
address the issue by inspecting the evaluation contexts and thereby
avoiding that code path.

This reapplies 96eced624 (#102857).

Added: 
clang/test/CodeGenCXX/ms-mangle-requires.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/Template.h
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateDeductionGuide.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CXX/drs/cwg23xx.cpp
clang/test/CXX/drs/cwg26xx.cpp
clang/test/CXX/drs/cwg27xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp

clang/test/CXX/temp/temp.constr/temp.constr.atomic/constrant-satisfaction-conversions.cpp
clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
clang/test/SemaCXX/cxx23-assume.cpp
clang/test/SemaCXX/cxx2c-fold-exprs.cpp
clang/test/SemaCXX/lambda-unevaluated.cpp
clang/test/SemaCXX/overload-resolution-deferred-templates.cpp
clang/test/SemaTemplate/concepts-recursive-inst.cpp
clang/test/SemaTemplate/concepts.cpp
clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp
clang/test/SemaTemplate/deduction-guide.cpp
clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ce9ae588b637..8040f1ac6af01 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10505,13 +10505,34 @@ class Sema final : public SemaBase {
   OverloadCandidateParamOrder PO = {},
   bool AggregateCandidateDeduction = false);
 
+  struct CheckNonDependentConversionsFlag {
+/// Do not consider any user-defined conversions when constructing the
+/// initializing sequence.
+bool SuppressUserConversions;
+
+/// Before constructing the initializing sequence, we check whether the
+/// parameter type and argument type contain any user defined conversions.
+/// If so, do not initialize them. This effectively bypasses some undesired
+/// instantiation before checking constaints, which might otherwise result
+/// in non-SFINAE errors e.g. recursive constraints.
+bool OnlyInitializeNonUserDefinedConversions;
+
+CheckNonDependentConversionsFlag(
+bool SuppressUserConversions,
+bool OnlyInitializeNonUserDefinedConversions)
+: SuppressUserConversions(SuppressUserConversions),
+  OnlyInitializeNonUserDefinedConversions(
+  OnlyInitializeNonUserDefinedConversions) {}
+  };
+
   /// Check that implicit conversion sequences can be formed for each argument
   /// whose corresponding parameter has a non-dependent type, per DR1391's
   /// [temp.deduct.call]p10.
   bool CheckNonDependentConversions(
   FunctionTemplateDecl *FunctionTemplate, ArrayRef ParamTypes,
   ArrayRef Args, OverloadCandidateSet &CandidateSet,
-  ConversionSequenceList &Conversions, bool SuppressUserConversions,
+  ConversionSequenceList &Conversions,
+  CheckNonDependentConversionsFlag UserConversionFlag,
   CXXRecordDecl *ActingContext = nullptr, QualType ObjectType = QualType(),
   Expr::Classification ObjectClassification = {},
   OverloadCandidateParamOrder PO = {});
@@ -12555,6 +12576,11 @@ class Sema final : public SemaBase {
   ///
   /// \param OriginalCallArgs If non-NULL, the original call arguments against
   /// which the deduced argument types should be compared.
+  /// \param CheckNonDependent Callback before substituting into the 
declaration
+  /// with the deduced template arguments.
+  /// \param OnlyInitializeNonUserDefinedConversions is used as a workaround 
for
+  /// some breakages introduced by CWG2369, where non-user-defined conversions
+  /// are checked first before the constraints.
   TemplateDeductionResult FinishTemplateArgumentDeduction(
   FunctionTemplateDecl *FunctionTemplate,
   SmallVectorImpl &Deduced,
@@ -12562,7 +12588,10 @@ class Sema final : public SemaBase {
   sema::TemplateDeductionInfo &Info,
   SmallVectorImpl const *OriginalCallArgs,
   bool PartialOverloading, bool PartialOrdering,
-  llvm::function_ref CheckNonDepende

[clang] [llvm] [llvm][DebugInfo][clang] Finalize all declaration subprograms in DIBuilder::finalize() (PR #139914)

2025-06-02 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

Gentle ping

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


[clang] [clang][python][test] Check if libclang.so is loadable (PR #142353)

2025-06-02 Thread Rainer Orth via cfe-commits

rorth wrote:

> Thank you for the PR. Several points:
> 
> 1. What happens on Windows?

I have no idea, knowing nothing at all about Windows.  I cannot even tell if a 
similar situation can arise there, i.e. if you can execute 32-bit programs on a 
64-bit Windows and, if you can, what the message would be if you tried.  
However, fixing an issue on one set of targets shouldn't force me to fix it 
everywhere: if/when such a situation arises elsewhere, any interested party can 
augment the code as necessary.  Btw., Darwin could be similarly affected, but 
the last Darwin versions that could build and execute 32-bit programs are so 
old that I have no idea if they are still supported in LLVM.

> 2. `check-clang-python` is just one of the ways to run into this. 
> `cindex.py` is a user-facing interface, so we shouldn't emit messages that 
> make sense only during development.

I tried several different routes:
- Add a check if `cdll.LoadLibrary` works to `tests/CMakeLists.txt`, setting 
`RUN_PYTHON_TESTS` to `FALSE` if not.  However, this cannot work since 
`libclang.so` doesn't even exist at `cmake` time.
- Alternatively (although I haven't tried that yet), one could a a similar 
small python script to the `check-clang-python` rule, not running the actual 
test if the library cannot be loaded.

Besides, one could just change the wording of the warning message: trying to 
load a 32-bit `libclang.so` into a 64-bit python is always an error, testsuite 
or no.

> 3. Given the fact that `OSError` already contains the message that 
> indicates the problem, I think we should explore why it's not properly 
> emitted in the first place, before introducing bespoke ways of delivering 
> error messages. @DeinAlptraum any thoughts here?

Even if the error message were emitted, this doesn't help because `ninja 
check-all` is still broken, there being no way to disable `check-clang-python` 
even manually.

IMO the testsuite integration of `check-clang-python` is broken in various ways:
- Any failure in this target aborts all of the testsuite run, as has been seen 
several times in the past, even without the issue at hand.
- The result is reported in a very non-standard way: instead of emitting (say) 
`PASS: libclang :: python bindings` or whatever, you just get `Ran 165 tests in 
...` unlike any other test.  Instead, the tests should be reported like the 
`PASS` above (or `UNSUPPORTED`, `XFAIL`, ...).  A failing test **must not** 
abort the whole testsuite, just report an appropriate result.



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


[clang] [lldb] [lldb] Add filter option to AST dump command (PR #142164)

2025-06-02 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/142164

>From 662e07aa9bb6560f37c079ba6f13be17e7885b48 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 30 May 2025 15:44:09 +0100
Subject: [PATCH 1/6] [clang][Frontend] Add overload to ASTPrinter that doesn't
 own output stream

We're planning on using the ASTPrinter in LLDB for AST dumping. But it
currently takes the output stream via `unique_ptr`. In LLDB we don't
have the output stream available in this form and instead it would be
convenient if we could just pass a reference to the stream.

This patch adds that overload.

(cherry picked from commit 9bd15ee7ed44adc836bcd07ff7e856d7a32ba6a9)
---
 clang/include/clang/Frontend/ASTConsumers.h |  5 +
 clang/lib/Frontend/ASTConsumers.cpp | 20 
 2 files changed, 25 insertions(+)

diff --git a/clang/include/clang/Frontend/ASTConsumers.h 
b/clang/include/clang/Frontend/ASTConsumers.h
index 0e068bf5cccb5..890701b6ff188 100644
--- a/clang/include/clang/Frontend/ASTConsumers.h
+++ b/clang/include/clang/Frontend/ASTConsumers.h
@@ -35,6 +35,11 @@ CreateASTDumper(std::unique_ptr OS, StringRef 
FilterString,
 bool DumpDecls, bool Deserialize, bool DumpLookups,
 bool DumpDeclTypes, ASTDumpOutputFormat Format);
 
+std::unique_ptr
+CreateASTDumper(raw_ostream &OS, StringRef FilterString, bool DumpDecls,
+bool Deserialize, bool DumpLookups, bool DumpDeclTypes,
+ASTDumpOutputFormat Format);
+
 // AST Decl node lister: prints qualified names of all filterable AST Decl
 // nodes.
 std::unique_ptr CreateASTDeclNodeLister();
diff --git a/clang/lib/Frontend/ASTConsumers.cpp 
b/clang/lib/Frontend/ASTConsumers.cpp
index a6e35452b4fbe..a5ff4d44592d4 100644
--- a/clang/lib/Frontend/ASTConsumers.cpp
+++ b/clang/lib/Frontend/ASTConsumers.cpp
@@ -41,6 +41,13 @@ namespace {
   OutputKind(K), OutputFormat(Format), FilterString(FilterString),
   DumpLookups(DumpLookups), DumpDeclTypes(DumpDeclTypes) {}
 
+ASTPrinter(raw_ostream &Out, Kind K, ASTDumpOutputFormat Format,
+   StringRef FilterString, bool DumpLookups = false,
+   bool DumpDeclTypes = false)
+: Out(Out), OwnedOut(nullptr), OutputKind(K), OutputFormat(Format),
+  FilterString(FilterString), DumpLookups(DumpLookups),
+  DumpDeclTypes(DumpDeclTypes) {}
+
 void HandleTranslationUnit(ASTContext &Context) override {
   TranslationUnitDecl *D = Context.getTranslationUnitDecl();
 
@@ -176,6 +183,19 @@ clang::CreateASTDumper(std::unique_ptr Out, 
StringRef FilterString,
   Format, FilterString, DumpLookups, DumpDeclTypes);
 }
 
+std::unique_ptr
+clang::CreateASTDumper(raw_ostream &Out, StringRef FilterString, bool 
DumpDecls,
+   bool Deserialize, bool DumpLookups, bool DumpDeclTypes,
+   ASTDumpOutputFormat Format) {
+  assert((DumpDecls || Deserialize || DumpLookups) && "nothing to dump");
+  return std::make_unique(Out,
+  Deserialize ? ASTPrinter::DumpFull
+  : DumpDecls ? ASTPrinter::Dump
+  : ASTPrinter::None,
+  Format, FilterString, DumpLookups,
+  DumpDeclTypes);
+}
+
 std::unique_ptr clang::CreateASTDeclNodeLister() {
   return std::make_unique(nullptr);
 }

>From 0ba5a4f09caeb54008594adfb3b8efa2a740e5e6 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 30 May 2025 15:46:27 +0100
Subject: [PATCH 2/6] [lldb] Add filter option to AST dump command

This patch makes the `-ast-dump-filter` Clang option available to the
`target modules dump ast` command. This allows us to selectively dump
parts of the AST by name.

The AST can quickly grow way too large to skim on the console. This will
aid in debugging AST related issues.

Example:
```
(lldb) target modules dump ast --filter func
Dumping clang ast for 48 modules.
Dumping func:
FunctionDecl 0xc4b785008 <>  func 'void (int)' 
extern
|-ParmVarDecl 0xc4b7853d8 <>  x 'int'
`-AsmLabelAttr 0xc4b785358 <> Implicit "_Z4funcIiEvT_"

Dumping func:
FunctionDecl 0xc4b7850b8 <>  func 'void (int)' 
implicit_instantiation extern
|-TemplateArgument type 'int'
| `-BuiltinType 0xc4b85b110 'int'
`-ParmVarDecl 0xc4b7853d8 <>  x 'int'
```
---
 lldb/include/lldb/Symbol/SymbolFile.h |  2 +-
 lldb/include/lldb/Symbol/SymbolFileOnDemand.h |  2 +-
 lldb/include/lldb/Symbol/TypeSystem.h |  3 ++-
 lldb/source/Commands/CommandObjectTarget.cpp  | 23 +++
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  |  4 ++--
 .../SymbolFile/DWARF/SymbolFileDWARF.h|  2 +-
 .../DWARF/SymbolFileDWARFDebugMap.cpp |  6 ++---
 .../DWARF/SymbolFileDWARFDebugMap.h   |  2 +-
 .../SymbolFile/NativePDB/PdbAstBuilder.cpp|  4 ++--
 .../SymbolFile/NativePDB/PdbAstBuilder.h  |  2 +-
 

[clang] [clang][python][test] Check if libclang.so is loadable (PR #142353)

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

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread Shamshura Egor via cfe-commits


@@ -2083,6 +2086,97 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+  << B.getSourceRange();
+}
+  }
+  for (const FieldDecl *Field : D->fields()) {
+if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCField << Field
+  << Field->getType() << Field->getSourceRange();
+  }
+  if (D->hasDeletedDestructor())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
+<< D->getDestructor()->getSourceRange();
+
+  if (D->isUnion()) {
+auto DiagSPM = [&](CXXSpecialMemberKind K, bool Has) {
+  if (Has)
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::UnionWithUserDeclaredSMF << K;
+};
+DiagSPM(CXXSpecialMemberKind::CopyConstructor,
+D->hasUserDeclaredCopyConstructor());
+DiagSPM(CXXSpecialMemberKind::CopyAssignment,
+D->hasUserDeclaredCopyAssignment());
+DiagSPM(CXXSpecialMemberKind::MoveConstructor,
+D->hasUserDeclaredMoveConstructor());
+DiagSPM(CXXSpecialMemberKind::MoveAssignment,
+D->hasUserDeclaredMoveAssignment());
+return;
+  }

egorshamshura wrote:

Removed

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread Shamshura Egor via cfe-commits


@@ -2083,6 +2086,97 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+  << B.getSourceRange();
+}
+  }
+  for (const FieldDecl *Field : D->fields()) {
+if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCField << Field
+  << Field->getType() << Field->getSourceRange();
+  }
+  if (D->hasDeletedDestructor())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
+<< D->getDestructor()->getSourceRange();
+
+  if (D->isUnion()) {
+auto DiagSPM = [&](CXXSpecialMemberKind K, bool Has) {
+  if (Has)
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::UnionWithUserDeclaredSMF << K;
+};
+DiagSPM(CXXSpecialMemberKind::CopyConstructor,
+D->hasUserDeclaredCopyConstructor());
+DiagSPM(CXXSpecialMemberKind::CopyAssignment,
+D->hasUserDeclaredCopyAssignment());
+DiagSPM(CXXSpecialMemberKind::MoveConstructor,
+D->hasUserDeclaredMoveConstructor());
+DiagSPM(CXXSpecialMemberKind::MoveAssignment,
+D->hasUserDeclaredMoveAssignment());
+return;
+  }
+
+  if (!D->hasSimpleMoveConstructor() && !D->hasSimpleCopyConstructor()) {
+const auto *Decl = cast(
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false));
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedCtr
+  << Decl->isMoveConstructor() << Decl->getSourceRange();
+  }
+  if (!D->hasSimpleMoveAssignment() && !D->hasSimpleCopyAssignment()) {
+CXXMethodDecl *Decl =
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/true);
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedAssign
+  << Decl->isMoveAssignmentOperator() << Decl->getSourceRange();
+  }
+  CXXDestructorDecl *Dtr = D->getDestructor();
+  if (Dtr && Dtr->isUserProvided() && !Dtr->isDefaulted())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 1
+<< Dtr->getSourceRange();

egorshamshura wrote:

Fixed, now using Dtr->isTrivial()

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


[clang] [llvm] [ARM, AArch64] Don't put BTI at asm goto branch targets (PR #141562)

2025-06-02 Thread Peter Smith via cfe-commits

https://github.com/smithp35 commented:

Thanks for the updates. I've resolved my comments.

I've asked internally to see if I can find anyone else that would like to 
comment. If I don't get any takers I'll set approved from my side later in the 
week.

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread Shamshura Egor via cfe-commits


@@ -2083,6 +2086,97 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+  << B.getSourceRange();
+}
+  }
+  for (const FieldDecl *Field : D->fields()) {
+if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCField << Field
+  << Field->getType() << Field->getSourceRange();
+  }
+  if (D->hasDeletedDestructor())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
+<< D->getDestructor()->getSourceRange();
+
+  if (D->isUnion()) {
+auto DiagSPM = [&](CXXSpecialMemberKind K, bool Has) {
+  if (Has)
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::UnionWithUserDeclaredSMF << K;
+};
+DiagSPM(CXXSpecialMemberKind::CopyConstructor,
+D->hasUserDeclaredCopyConstructor());
+DiagSPM(CXXSpecialMemberKind::CopyAssignment,
+D->hasUserDeclaredCopyAssignment());
+DiagSPM(CXXSpecialMemberKind::MoveConstructor,
+D->hasUserDeclaredMoveConstructor());
+DiagSPM(CXXSpecialMemberKind::MoveAssignment,
+D->hasUserDeclaredMoveAssignment());
+return;
+  }
+
+  if (!D->hasSimpleMoveConstructor() && !D->hasSimpleCopyConstructor()) {
+const auto *Decl = cast(
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false));
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedCtr
+  << Decl->isMoveConstructor() << Decl->getSourceRange();
+  }
+  if (!D->hasSimpleMoveAssignment() && !D->hasSimpleCopyAssignment()) {
+CXXMethodDecl *Decl =
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/true);
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedAssign
+  << Decl->isMoveAssignmentOperator() << Decl->getSourceRange();
+  }

egorshamshura wrote:

Fixed it, now I'm iterating over all special member functions

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


[clang] [CIR] Implement folder for VecShuffleDynamicOp (PR #142315)

2025-06-02 Thread Erich Keane via cfe-commits


@@ -1579,6 +1579,38 @@ OpFoldResult cir::VecExtractOp::fold(FoldAdaptor 
adaptor) {
 // VecShuffleDynamicOp
 
//===--===//
 
+OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute vec = adaptor.getVec();
+  mlir::Attribute indices = adaptor.getIndices();
+  if (mlir::isa_and_nonnull(vec) &&
+  mlir::isa_and_nonnull(indices)) {
+auto vecAttr = mlir::cast(vec);
+auto indicesAttr = mlir::cast(indices);
+auto vecTy = cast(vecAttr.getType());
+
+mlir::ArrayAttr vecElts = vecAttr.getElts();
+mlir::ArrayAttr indicesElts = indicesAttr.getElts();
+
+const uint64_t numElements = vecElts.size();
+
+SmallVector elements;
+elements.reserve(numElements);
+
+const uint64_t maskBits = llvm::NextPowerOf2(numElements - 1) - 1;
+for (uint64_t i = 0; i < numElements; i++) {
+  cir::IntAttr idxAttr = mlir::cast(indicesElts[i]);
+  uint64_t idxValue = idxAttr.getUInt();
+  uint64_t newIdx = idxValue & maskBits;
+  elements.push_back(vecElts[newIdx]);
+}
+
+return cir::ConstVectorAttr::get(
+vecTy, mlir::ArrayAttr::get(getContext(), elements));
+  }
+
+  return {};

erichkeane wrote:

Should this branch have a 'not yet implemented' thing here? 

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


[clang] [CIR] Implement folder for VecShuffleDynamicOp (PR #142315)

2025-06-02 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

Others should approve, but I only have 1 concern.

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


[clang] [CIR] Upstream ShuffleOp for VectorType (PR #142288)

2025-06-02 Thread Henrich Lauko via cfe-commits


@@ -0,0 +1,21 @@
+//===--===//
+//
+// 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 defines the CIR dialect attributes constraints.
+//
+//===--===//
+
+#ifndef CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
+#define CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
+
+include "clang/CIR/Dialect/IR/CIRAttrs.td"
+include "mlir/IR/CommonAttrConstraints.td"
+
+def CIR_IntArrayAttr : TypedArrayAttrBase;

xlauko wrote:

My bad, it should have been `TypedArrayAttrBase`.

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


[clang] [HLSL] Add __spirv__ macro (PR #132848)

2025-06-02 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Hi! I'm wondering why this macro needs to be exposed outside of HLSL given that 
there's already `__SPIRV__` exposed for this exact purpose. These changes turn 
out to be disruptive in a downstream SYCL implementation 
(https://github.com/intel/llvm/issues/18219) because of a namespace named 
`__spirv`.

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


[clang] [clang][docs] Fix docs-clang-html. (PR #142387)

2025-06-02 Thread via cfe-commits

Mr-Anyone wrote:

I think I am seeing something similar on CI: 

https://github.com/llvm/llvm-project/actions/runs/15387162550/job/43288136977?pr=140278

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


[clang] [CIR] Implement folder for VecShuffleDynamicOp (PR #142315)

2025-06-02 Thread Amr Hesham via cfe-commits


@@ -1579,6 +1579,38 @@ OpFoldResult cir::VecExtractOp::fold(FoldAdaptor 
adaptor) {
 // VecShuffleDynamicOp
 
//===--===//
 
+OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute vec = adaptor.getVec();
+  mlir::Attribute indices = adaptor.getIndices();
+  if (mlir::isa_and_nonnull(vec) &&
+  mlir::isa_and_nonnull(indices)) {
+auto vecAttr = mlir::cast(vec);
+auto indicesAttr = mlir::cast(indices);
+auto vecTy = cast(vecAttr.getType());
+
+mlir::ArrayAttr vecElts = vecAttr.getElts();
+mlir::ArrayAttr indicesElts = indicesAttr.getElts();
+
+const uint64_t numElements = vecElts.size();
+
+SmallVector elements;
+elements.reserve(numElements);
+
+const uint64_t maskBits = llvm::NextPowerOf2(numElements - 1) - 1;
+for (uint64_t i = 0; i < numElements; i++) {
+  cir::IntAttr idxAttr = mlir::cast(indicesElts[i]);
+  uint64_t idxValue = idxAttr.getUInt();
+  uint64_t newIdx = idxValue & maskBits;
+  elements.push_back(vecElts[newIdx]);
+}
+
+return cir::ConstVectorAttr::get(
+vecTy, mlir::ArrayAttr::get(getContext(), elements));
+  }
+
+  return {};

AmrDeveloper wrote:

As far as I understood, no, it should be null because that means we can't fold 
`VecShuffleDynamicOp` with non Const vec operands

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


[clang] [clang][docs] Add docs for CCC_OVERRIDE_OPTIONS. (PR #142396)

2025-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Abid Qadeer (abidh)


Changes

As was noted in 
https://github.com/llvm/llvm-project/pull/140556#discussion_r2118160690, there 
is no documentation for `CCC_OVERRIDE_OPTIONS`. This adds the missing 
documentation. The information is duplicate of what we have for 
`FCC_OVERRIDE_OPTIONS` in flang. Once this goes in and available at 
https://clang.llvm.org/docs/UsersManual.html then the flang documentation can 
be changed to refer to it.

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


1 Files Affected:

- (modified) clang/docs/UsersManual.rst (+29) 


``diff
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index eb9a812f0c1c9..8c72f95b94095 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3743,6 +3743,35 @@ Doxygen-style comments and ignores ordinary comments 
starting with ``//`` and
   ``-fcomment-block-commands=foo -fcomment-block-commands=bar`` does the same
   as above.
 
+.. _ccc-override-options:
+
+CCC_OVERRIDE_OPTIONS
+
+The environment variable ``CCC_OVERRIDE_OPTIONS`` can be used to edit clang's
+command line arguments. The value of this variable is a space-separated list of
+edits to perform. The edits are applied in the order in which they appear in
+``CCC_OVERRIDE_OPTIONS``. Each edit should be one of the following forms:
+
+- ``#``: Silence information about the changes to the command line arguments.
+
+- ``^FOO``: Add ``FOO`` as a new argument at the beginning of the command line
+  right after the name of the compiler executable.
+
+- ``+FOO``: Add ``FOO`` as a new argument at the end of the command line.
+
+- ``s/XXX/YYY/``: Substitute the regular expression ``XXX`` with ``YYY`` in the
+  command line.
+
+- ``xOPTION``: Removes all instances of the literal argument ``OPTION``.
+
+- ``XOPTION``: Removes all instances of the literal argument ``OPTION``, and 
the
+  following argument.
+
+- ``Ox``: Removes all flags matching ``O`` or ``O[sz0-9]`` and adds ``Ox`` at
+  the end of the command line.
+
+This environment variable does not affect the options added by the config 
files.
+
 .. _c:
 
 C Language Features

``




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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread Erich Keane via cfe-commits


@@ -1922,6 +1924,7 @@ static std::optional 
StdNameToTypeTrait(StringRef Name) {
   return llvm::StringSwitch>(Name)
   .Case("is_trivially_relocatable",
 TypeTrait::UTT_IsCppTriviallyRelocatable)
+  .Case("is_trivially_copyable", TypeTrait::UTT_IsTriviallyCopyable)

erichkeane wrote:

2 isnt the number, but at a certain number of entries here, we're going to want 
to tablegen/.def file this.  Perhaps in `TokenKinds.def`?

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread Erich Keane via cfe-commits

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


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


[clang] [Clang] Fix crash on template-specialization (PR #142338)

2025-06-02 Thread Erich Keane via cfe-commits


@@ -5120,6 +5121,10 @@ bool Sema::addInstantiatedParametersToScope(
   // Simple case: not a parameter pack.
   assert(FParamIdx < Function->getNumParams());
   ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
+  DeclarationName name = FunctionParam->getDeclName();
+  auto _ = llvm::make_scope_exit([&]() {
+FunctionParam->setDeclName(name);

erichkeane wrote:

Something about this being done at scope-exist makes me think this is a smell.  
I don't think I understand what is going on here enough with the various names 
enough to know whether this is OK.  Could @zygoloid take a quick look and see 
if this is crazy or not?

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


[clang] [Clang] Improve infrastructure for libstdc++ workarounds (PR #141977)

2025-06-02 Thread via cfe-commits

cor3ntin wrote:

I'm looking into that

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


[clang] [Clang] Preserve CXXParenListInitExpr in TreeTransform. (PR #138518)

2025-06-02 Thread Erich Keane via cfe-commits

erichkeane wrote:

> @alexfh I don't have the resources to look into this issue. Please revert if 
> you need to.

This has been in trunk for a long time, a revert here would be HIGHLY 
unfortunate.  I would vastly prefer someone spend time trying to figure out why 
we are confused with the variable init here instead.  So:

`q.Push(new Node(0));`

Seems to be the line that isn't producing the same value.  We're initializing 
it with an int instead of a 64-bit-`long`.  I see here:
https://godbolt.org/z/KofsM8hdj

```
|   `-CXXMemberCallExpr  'void'
| |-MemberExpr  '' 
.Push 0x28726e38
| | `-DeclRefExpr  'IntrusiveMPSCQueue' lvalue Var 
0x28735d18 'q' 'IntrusiveMPSCQueue' refers_to_enclosing_variable_or_capture
| `-CXXNewExpr  'Node *' Function 0x28731c68 
'operator new' 'void *(unsigned long)'
|   `-CXXParenListInitExpr  'Node'
| |-IntegerLiteral  'int' 0
```

IN a non-template version (i removed the template head itself), we get:
```
|   `-CXXNewExpr  'Node *' Function 0x22566848 
'operator new' 'void *(unsigned long)'
| `-CXXParenListInitExpr  'Node'
|   |-ImplicitCastExpr  'long' 
|   | `-IntegerLiteral  'int' 0
|   `-ImplicitValueInitExpr 'Node *'
```

In the primary template we have:

```
| |   |   `-CXXNewExpr  'Node *' Function 0x22566848 
'operator new' 'void *(unsigned long)'
| |   | `-CXXParenListInitExpr  'Node'
| |   |   |-ImplicitCastExpr  'long' 
| |   |   | `-IntegerLiteral  'int' 0
```

SO something about instantiating the expressions lost their cast?  I'm not sure 
how that happens?

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


[clang] [CIR] Upstream TernaryOp for VectorType (PR #142393)

2025-06-02 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/142393

This change adds support for the Ternary op for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487

>From 120e9a69f16545b67c98a0e881183e989ceb9a1e Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Mon, 2 Jun 2025 15:11:17 +0200
Subject: [PATCH] [CIR] Upstream TernaryOp for VectorType

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 36 +++
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp| 30 
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   | 18 ++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 17 -
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.h   | 10 ++
 clang/test/CIR/CodeGen/vector-ext.cpp | 15 
 clang/test/CIR/CodeGen/vector.cpp | 17 -
 7 files changed, 141 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 07851610a2abd..eb02d849b79f6 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2190,4 +2190,40 @@ def VecShuffleDynamicOp : CIR_Op<"vec.shuffle.dynamic",
   let hasVerifier = 1;
 }
 
+//===--===//
+// VecTernaryOp
+//===--===//
+
+def VecTernaryOp : CIR_Op<"vec.ternary",
+   [Pure, AllTypesMatch<["result", "vec1", "vec2"]>]> {
+  let summary = "The `cond ? a : b` ternary operator for vector types";
+  let description = [{
+The `cir.vec.ternary` operation represents the C/C++ ternary operator,
+`?:`, for vector types, which does a `select` on individual elements of the
+vectors. Unlike a regular `?:` operator, there is no short circuiting. All
+three arguments are always evaluated.  Because there is no short
+circuiting, there are no regions in this operation, unlike cir.ternary.
+
+The first argument is a vector of integral type. The second and third
+arguments are vectors of the same type and have the same number of elements
+as the first argument.
+
+The result is a vector of the same type as the second and third arguments.
+Each element of the result is `(bool)a[n] ? b[n] : c[n]`.
+  }];
+
+  let arguments = (ins
+IntegerVector:$cond,
+CIR_VectorType:$vec1,
+CIR_VectorType:$vec2
+  );
+
+  let results = (outs CIR_VectorType:$result);
+  let assemblyFormat = [{
+`(` $cond `,` $vec1 `,` $vec2 `)` `:` qualified(type($cond)) `,`
+qualified(type($vec1)) attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 8448c164a5e58..5ae727dff1095 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -193,6 +193,36 @@ class ScalarExprEmitter : public 
StmtVisitor {
 e->getSourceRange().getBegin());
   }
 
+  mlir::Value
+  VisitAbstractConditionalOperator(const AbstractConditionalOperator *e) {
+mlir::Location loc = cgf.getLoc(e->getSourceRange());
+Expr *condExpr = e->getCond();
+Expr *lhsExpr = e->getTrueExpr();
+Expr *rhsExpr = e->getFalseExpr();
+
+// OpenCL: If the condition is a vector, we can treat this condition like
+// the select function.
+if ((cgf.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) ||
+condExpr->getType()->isExtVectorType()) {
+  cgf.getCIRGenModule().errorNYI(loc,
+ "TernaryOp OpenCL VectorType condition");
+  return {};
+}
+
+if (condExpr->getType()->isVectorType() ||
+condExpr->getType()->isSveVLSBuiltinType()) {
+  assert(condExpr->getType()->isVectorType() && "?: op for SVE vector 
NYI");
+  mlir::Value condValue = Visit(condExpr);
+  mlir::Value lhsValue = Visit(lhsExpr);
+  mlir::Value rhsValue = Visit(rhsExpr);
+  return builder.create(loc, condValue, lhsValue,
+   rhsValue);
+}
+
+cgf.getCIRGenModule().errorNYI(loc, "TernaryOp for non vector types");
+return {};
+  }
+
   mlir::Value VisitMemberExpr(MemberExpr *e);
 
   mlir::Value VisitInitListExpr(InitListExpr *e);
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 36f050de9f8bb..1236c455304a9 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1589,6 +1589,24 @@ LogicalResult cir::VecShuffleDynamicOp::verify() {
   return success();
 }
 
+//===--===//
+// VecTernaryOp
+//===--===//
+
+LogicalResult cir::VecTernaryOp::verify() {
+  /

[clang] [CIR] Upstream TernaryOp for VectorType (PR #142393)

2025-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds support for the Ternary op for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487

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


7 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+36) 
- (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+30) 
- (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+18) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+16-1) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h (+10) 
- (modified) clang/test/CIR/CodeGen/vector-ext.cpp (+15) 
- (modified) clang/test/CIR/CodeGen/vector.cpp (+16-1) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 07851610a2abd..eb02d849b79f6 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2190,4 +2190,40 @@ def VecShuffleDynamicOp : CIR_Op<"vec.shuffle.dynamic",
   let hasVerifier = 1;
 }
 
+//===--===//
+// VecTernaryOp
+//===--===//
+
+def VecTernaryOp : CIR_Op<"vec.ternary",
+   [Pure, AllTypesMatch<["result", "vec1", "vec2"]>]> {
+  let summary = "The `cond ? a : b` ternary operator for vector types";
+  let description = [{
+The `cir.vec.ternary` operation represents the C/C++ ternary operator,
+`?:`, for vector types, which does a `select` on individual elements of the
+vectors. Unlike a regular `?:` operator, there is no short circuiting. All
+three arguments are always evaluated.  Because there is no short
+circuiting, there are no regions in this operation, unlike cir.ternary.
+
+The first argument is a vector of integral type. The second and third
+arguments are vectors of the same type and have the same number of elements
+as the first argument.
+
+The result is a vector of the same type as the second and third arguments.
+Each element of the result is `(bool)a[n] ? b[n] : c[n]`.
+  }];
+
+  let arguments = (ins
+IntegerVector:$cond,
+CIR_VectorType:$vec1,
+CIR_VectorType:$vec2
+  );
+
+  let results = (outs CIR_VectorType:$result);
+  let assemblyFormat = [{
+`(` $cond `,` $vec1 `,` $vec2 `)` `:` qualified(type($cond)) `,`
+qualified(type($vec1)) attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 8448c164a5e58..5ae727dff1095 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -193,6 +193,36 @@ class ScalarExprEmitter : public 
StmtVisitor {
 e->getSourceRange().getBegin());
   }
 
+  mlir::Value
+  VisitAbstractConditionalOperator(const AbstractConditionalOperator *e) {
+mlir::Location loc = cgf.getLoc(e->getSourceRange());
+Expr *condExpr = e->getCond();
+Expr *lhsExpr = e->getTrueExpr();
+Expr *rhsExpr = e->getFalseExpr();
+
+// OpenCL: If the condition is a vector, we can treat this condition like
+// the select function.
+if ((cgf.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) ||
+condExpr->getType()->isExtVectorType()) {
+  cgf.getCIRGenModule().errorNYI(loc,
+ "TernaryOp OpenCL VectorType condition");
+  return {};
+}
+
+if (condExpr->getType()->isVectorType() ||
+condExpr->getType()->isSveVLSBuiltinType()) {
+  assert(condExpr->getType()->isVectorType() && "?: op for SVE vector 
NYI");
+  mlir::Value condValue = Visit(condExpr);
+  mlir::Value lhsValue = Visit(lhsExpr);
+  mlir::Value rhsValue = Visit(rhsExpr);
+  return builder.create(loc, condValue, lhsValue,
+   rhsValue);
+}
+
+cgf.getCIRGenModule().errorNYI(loc, "TernaryOp for non vector types");
+return {};
+  }
+
   mlir::Value VisitMemberExpr(MemberExpr *e);
 
   mlir::Value VisitInitListExpr(InitListExpr *e);
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 36f050de9f8bb..1236c455304a9 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1589,6 +1589,24 @@ LogicalResult cir::VecShuffleDynamicOp::verify() {
   return success();
 }
 
+//===--===//
+// VecTernaryOp
+//===--===//
+
+LogicalResult cir::VecTernaryOp::verify() {
+  // Verify that the condition operand has the same number of elements as the
+  // other operands.  (The automatic verification already chec

[clang] [CIR] Upstream TernaryOp for VectorType (PR #142393)

2025-06-02 Thread Amr Hesham via cfe-commits

AmrDeveloper wrote:

- `IntegerVector:$cond` will replaced by `CIR_VectorOfIntType` after merging 
https://github.com/llvm/llvm-project/pull/14/

- there will be a follow up PR for the folder

https://github.com/llvm/llvm-project/pull/142393
___
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 performance-bool-bitwise-operation check (PR #142324)

2025-06-02 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,200 @@
+//===--- BoolBitwiseOperationCheck.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 "BoolBitwiseOperationCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+namespace {
+bool hasExplicitParentheses(const Expr *E, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  if (!E)
+return false;
+
+  const SourceLocation Start = E->getBeginLoc();
+  const SourceLocation End = E->getEndLoc();
+
+  if (Start.isMacroID() || End.isMacroID() || !Start.isValid() ||
+  !End.isValid()) {
+return false;
+  }

vbvictor wrote:

```suggestion
  !End.isValid())
return false;
```
No parentheses for single stmt ifs 

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


[clang] [CIR] Implement folder for VecShuffleDynamicOp (PR #142315)

2025-06-02 Thread Erich Keane via cfe-commits

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


[clang] [clang][docs] Add docs for CCC_OVERRIDE_OPTIONS. (PR #142396)

2025-06-02 Thread Abid Qadeer via cfe-commits

https://github.com/abidh created 
https://github.com/llvm/llvm-project/pull/142396

As was noted in 
https://github.com/llvm/llvm-project/pull/140556#discussion_r2118160690, there 
is no documentation for `CCC_OVERRIDE_OPTIONS`. This adds the missing 
documentation. The information is duplicate of what we have for 
`FCC_OVERRIDE_OPTIONS` in flang. Once this goes in and available at 
https://clang.llvm.org/docs/UsersManual.html then the flang documentation can 
be changed to refer to it.

>From b2171eec20e356d4e37920e4b6c740a3c3a4b239 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 2 Jun 2025 12:44:37 +0100
Subject: [PATCH] [clang][docs] Add docs for CCC_OVERRIDE_OPTIONS.

As was noted in 
https://github.com/llvm/llvm-project/pull/140556#discussion_r2118160690,
there is no documentation for `CCC_OVERRIDE_OPTIONS`. This adds the
missing documentation. The information is duplicate of what we have for
`FCC_OVERRIDE_OPTIONS` in flang. Once this goes in and available at
https://clang.llvm.org/docs/UsersManual.html then the flang
documentation can be changed to refer to it.
---
 clang/docs/UsersManual.rst | 29 +
 1 file changed, 29 insertions(+)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index eb9a812f0c1c9..8c72f95b94095 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3743,6 +3743,35 @@ Doxygen-style comments and ignores ordinary comments 
starting with ``//`` and
   ``-fcomment-block-commands=foo -fcomment-block-commands=bar`` does the same
   as above.
 
+.. _ccc-override-options:
+
+CCC_OVERRIDE_OPTIONS
+
+The environment variable ``CCC_OVERRIDE_OPTIONS`` can be used to edit clang's
+command line arguments. The value of this variable is a space-separated list of
+edits to perform. The edits are applied in the order in which they appear in
+``CCC_OVERRIDE_OPTIONS``. Each edit should be one of the following forms:
+
+- ``#``: Silence information about the changes to the command line arguments.
+
+- ``^FOO``: Add ``FOO`` as a new argument at the beginning of the command line
+  right after the name of the compiler executable.
+
+- ``+FOO``: Add ``FOO`` as a new argument at the end of the command line.
+
+- ``s/XXX/YYY/``: Substitute the regular expression ``XXX`` with ``YYY`` in the
+  command line.
+
+- ``xOPTION``: Removes all instances of the literal argument ``OPTION``.
+
+- ``XOPTION``: Removes all instances of the literal argument ``OPTION``, and 
the
+  following argument.
+
+- ``Ox``: Removes all flags matching ``O`` or ``O[sz0-9]`` and adds ``Ox`` at
+  the end of the command line.
+
+This environment variable does not affect the options added by the config 
files.
+
 .. _c:
 
 C Language Features

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


[clang] [clang][docs] Fix docs-clang-html. (PR #142387)

2025-06-02 Thread Abid Qadeer via cfe-commits

abidh wrote:

> I think I am seeing something similar on CI:
> 
> https://github.com/llvm/llvm-project/actions/runs/15387162550/job/43288136977?pr=140278

Thanks for reporting this. I think I will reopen it.


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


[clang] [libclang/python] Properly report errors when test fails (PR #142371)

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

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


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


[clang] [clang][docs] Fix docs-clang-html. (PR #142387)

2025-06-02 Thread Abid Qadeer via cfe-commits

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


[clang] c5da471 - [libclang/python] Properly report errors when test fails (#142371)

2025-06-02 Thread via cfe-commits

Author: Jannick Kremer
Date: 2025-06-02T16:14:39+02:00
New Revision: c5da47108ab77358f5fa5d43fd4d8344086c831f

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

LOG: [libclang/python] Properly report errors when test fails (#142371)

test_cdb.py's test_create_fail captures stderr to suppress output but
did not release it in case the test fails.

Added: 


Modified: 
clang/bindings/python/tests/cindex/test_cdb.py

Removed: 




diff  --git a/clang/bindings/python/tests/cindex/test_cdb.py 
b/clang/bindings/python/tests/cindex/test_cdb.py
index 757a14fbaef2c..5abe56f0d65f8 100644
--- a/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/clang/bindings/python/tests/cindex/test_cdb.py
@@ -21,13 +21,16 @@ def test_create_fail(self):
 
 # clang_CompilationDatabase_fromDirectory calls fprintf(stderr, ...)
 # Suppress its output.
-stderr = os.dup(2)
-with open(os.devnull, "wb") as null:
-os.dup2(null.fileno(), 2)
-with self.assertRaises(CompilationDatabaseError) as cm:
-CompilationDatabase.fromDirectory(path)
-os.dup2(stderr, 2)
-os.close(stderr)
+try:
+stderr = os.dup(2)
+with open(os.devnull, "wb") as null:
+os.dup2(null.fileno(), 2)
+with self.assertRaises(CompilationDatabaseError) as cm:
+CompilationDatabase.fromDirectory(path)
+# Ensures that stderr is reset even if the above code crashes
+finally:
+os.dup2(stderr, 2)
+os.close(stderr)
 
 e = cm.exception
 self.assertEqual(e.cdb_error, 
CompilationDatabaseError.ERROR_CANNOTLOADDATABASE)



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


[clang] [libclang/python] Properly report errors when test fails (PR #142371)

2025-06-02 Thread Jannick Kremer via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [clang] Simplify device kernel attributes (PR #137882)

2025-06-02 Thread Nick Sarnie via cfe-commits

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


[clang] [clang][Sema] Fix and reapply 'Declare builtins used in #pragma intrinsic #138205' (PR #142019)

2025-06-02 Thread Nick Sarnie via cfe-commits

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


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

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

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

LGTM! Thank you.

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


[clang] [clang][Sema] Fix and reapply 'Declare builtins used in #pragma intrinsic #138205' (PR #142019)

2025-06-02 Thread Nick Sarnie via cfe-commits

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


[clang] [clang][docs] Add docs for CCC_OVERRIDE_OPTIONS. (PR #142396)

2025-06-02 Thread Abid Qadeer via cfe-commits

abidh wrote:

The CI failure seems to be for a separate issue. I have opened 
https://github.com/llvm/llvm-project/pull/142387 for it.

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


[clang] [Sema] Fix bug in builtin AS override (PR #138141)

2025-06-02 Thread Matt Arsenault via cfe-commits

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


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


[clang] [SPIR-V] Only emit __spirv__ when targeting HLSL (PR #142401)

2025-06-02 Thread Nathan Gauër via cfe-commits

https://github.com/Keenuts created 
https://github.com/llvm/llvm-project/pull/142401

OpenCL translator had a __spirv namespace, and defining the __spirv__ macro 
causes issues downstream on the OpenCL side. This macro is needed to keep 
compatibility with HLSL/DXC, but can be avoided for other targets/languages.

From dd39504683a0f7f12ef787de12d9751a5b8056bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= 
Date: Mon, 2 Jun 2025 16:14:56 +0200
Subject: [PATCH] [SPIR-V] Only emit __spirv__ when targeting HLSL

OpenCL translator had a __spirv namespace, and defining the __spirv__
macro causes issues downstream on the OpenCL side.
This macro is needed to keep compatibility with HLSL/DXC, but can
be avoided for other targets/languages.
---
 clang/lib/Basic/Targets/SPIR.cpp| 3 ++-
 clang/test/Preprocessor/predefined-macros.c | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/SPIR.cpp b/clang/lib/Basic/Targets/SPIR.cpp
index 7ab5014a06647..2336fb3ef0495 100644
--- a/clang/lib/Basic/Targets/SPIR.cpp
+++ b/clang/lib/Basic/Targets/SPIR.cpp
@@ -87,7 +87,8 @@ void SPIR64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 void BaseSPIRVTargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
   DefineStd(Builder, "SPIRV", Opts);
-  DefineStd(Builder, "spirv", Opts);
+  if (Opts.HLSL)
+DefineStd(Builder, "spirv", Opts);
 }
 
 void SPIRVTargetInfo::getTargetDefines(const LangOptions &Opts,
diff --git a/clang/test/Preprocessor/predefined-macros.c 
b/clang/test/Preprocessor/predefined-macros.c
index b7765bfa2fb14..da25b1efa3984 100644
--- a/clang/test/Preprocessor/predefined-macros.c
+++ b/clang/test/Preprocessor/predefined-macros.c
@@ -228,6 +228,7 @@
 // CHECK-SPIRV32-DAG: #define __SPIRV__ 1
 // CHECK-SPIRV32-DAG: #define __SPIRV32__ 1
 // CHECK-SPIRV32-NOT: #define __SPIRV64__ 1
+// CHECK-SPIRV32-NOT: #define __spirv__ 1
 
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64
@@ -235,6 +236,7 @@
 // CHECK-SPIRV64-DAG: #define __SPIRV__ 1
 // CHECK-SPIRV64-DAG: #define __SPIRV64__ 1
 // CHECK-SPIRV64-NOT: #define __SPIRV32__ 1
+// CHECK-SPIRV64-NOT: #define __spirv__ 1
 
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-amd-amdhsa \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64-AMDGCN
@@ -245,6 +247,7 @@
 // CHECK-SPIRV64-AMDGCN-DAG: #define __AMDGCN__ 1
 // CHECK-SPIRV64-AMDGCN-DAG: #define __AMDGPU__ 1
 // CHECK-SPIRV64-AMDGCN-NOT: #define __SPIRV32__ 1
+// CHECK-SPIRV64-AMDGCN-NOT: #define __spirv__ 1
 
 // RUN: %clang_cc1 %s -E -dM -o - -x hip -triple x86_64-unknown-linux-gnu \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread Erich Keane via cfe-commits


@@ -1776,6 +1777,8 @@ def note_unsatisfied_trait_reason
"%VBase{has a virtual base %1}|"
"%NRBase{has a non-trivially-relocatable base %1}|"
"%NRField{has a non-trivially-relocatable member %1 of type %2}|"
+   "%NTCBase{has a non-trivially-copyable base %1}|"

erichkeane wrote:

The enum names here are inconsistent... `non-trivially-relocatable` took only 
`NR` whereas this is taking `NTC`.  That said, I VASTLY prefer the `T` be 
present.  Not in the scope here of course, but a followup tochange those `NR` 
to `NTR` perhaps is valuable.

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


[clang] [SPIR-V] Only emit __spirv__ when targeting HLSL (PR #142401)

2025-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nathan Gauër (Keenuts)


Changes

OpenCL translator had a __spirv namespace, and defining the __spirv__ macro 
causes issues downstream on the OpenCL side. This macro is needed to keep 
compatibility with HLSL/DXC, but can be avoided for other targets/languages.

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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/SPIR.cpp (+2-1) 
- (modified) clang/test/Preprocessor/predefined-macros.c (+3) 


``diff
diff --git a/clang/lib/Basic/Targets/SPIR.cpp b/clang/lib/Basic/Targets/SPIR.cpp
index 7ab5014a06647..2336fb3ef0495 100644
--- a/clang/lib/Basic/Targets/SPIR.cpp
+++ b/clang/lib/Basic/Targets/SPIR.cpp
@@ -87,7 +87,8 @@ void SPIR64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 void BaseSPIRVTargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
   DefineStd(Builder, "SPIRV", Opts);
-  DefineStd(Builder, "spirv", Opts);
+  if (Opts.HLSL)
+DefineStd(Builder, "spirv", Opts);
 }
 
 void SPIRVTargetInfo::getTargetDefines(const LangOptions &Opts,
diff --git a/clang/test/Preprocessor/predefined-macros.c 
b/clang/test/Preprocessor/predefined-macros.c
index b7765bfa2fb14..da25b1efa3984 100644
--- a/clang/test/Preprocessor/predefined-macros.c
+++ b/clang/test/Preprocessor/predefined-macros.c
@@ -228,6 +228,7 @@
 // CHECK-SPIRV32-DAG: #define __SPIRV__ 1
 // CHECK-SPIRV32-DAG: #define __SPIRV32__ 1
 // CHECK-SPIRV32-NOT: #define __SPIRV64__ 1
+// CHECK-SPIRV32-NOT: #define __spirv__ 1
 
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64
@@ -235,6 +236,7 @@
 // CHECK-SPIRV64-DAG: #define __SPIRV__ 1
 // CHECK-SPIRV64-DAG: #define __SPIRV64__ 1
 // CHECK-SPIRV64-NOT: #define __SPIRV32__ 1
+// CHECK-SPIRV64-NOT: #define __spirv__ 1
 
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-amd-amdhsa \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64-AMDGCN
@@ -245,6 +247,7 @@
 // CHECK-SPIRV64-AMDGCN-DAG: #define __AMDGCN__ 1
 // CHECK-SPIRV64-AMDGCN-DAG: #define __AMDGPU__ 1
 // CHECK-SPIRV64-AMDGCN-NOT: #define __SPIRV32__ 1
+// CHECK-SPIRV64-AMDGCN-NOT: #define __spirv__ 1
 
 // RUN: %clang_cc1 %s -E -dM -o - -x hip -triple x86_64-unknown-linux-gnu \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP

``




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


[clang] [HLSL] Add __spirv__ macro (PR #132848)

2025-06-02 Thread Nathan Gauër via cfe-commits

Keenuts wrote:

Hi, I don't think there is an issue with only emitting the `__spirv__` macro 
with HLSL. Sent out https://github.com/llvm/llvm-project/pull/142401

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


[clang] [clang-tools-extra] [llvm] [clang] Simplify device kernel attributes (PR #137882)

2025-06-02 Thread Nick Sarnie via cfe-commits


@@ -3541,7 +3541,7 @@ bool FunctionDecl::isExternC() const {
 }
 
 bool FunctionDecl::isInExternCContext() const {
-  if (hasAttr())
+  if (hasAttr() && getASTContext().getLangOpts().OpenCL)

sarnex wrote:

Thanks for the review. In an ideal world we would just be able to use the fact 
it's been specified as a device kernel do to the checks but right now it's not 
that simple, one case is the multiple language like you mentioned. I tried 
OpenCL + SYCL and that worked, so there is some ambiguity there.

Let me update these checks to use the spelling just to simplify this change. 
Thanks again.

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


[clang] [SPIR-V] Only emit __spirv__ when targeting HLSL (PR #142401)

2025-06-02 Thread Nathan Gauër via cfe-commits

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


[clang] [Clang] Fix crash on template-specialization (PR #142338)

2025-06-02 Thread Mark de Wever via cfe-commits


@@ -5120,6 +5121,10 @@ bool Sema::addInstantiatedParametersToScope(
   // Simple case: not a parameter pack.
   assert(FParamIdx < Function->getNumParams());
   ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
+  DeclarationName name = FunctionParam->getDeclName();
+  auto _ = llvm::make_scope_exit([&]() {
+FunctionParam->setDeclName(name);

mark-de-wever-sonarsource wrote:

This approach is based on what Richard suggested in 
https://github.com/llvm/llvm-project/issues/54279#issuecomment-2623325977 " for 
example, we need to set the name back when we're done with it.".

The crash is caused due to another scope-exit. In that scope a `FETokenInfo` 
"attached" to the name of the function argument. This function is unaware of 
that scope so the "rename" is unknown to that scope and at that scope's 
scope-exit the information "attached" to the current name (_not_ the original 
name) is removed. This is where an assertion triggers.

So this change basically restores the original name so the other scope-exit 
will "detach" the `FETokenInfo` using the original name and the crash is 
resolved.

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


[clang] [Clang] add fix-it hints for unknown attributes (PR #141305)

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

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

>From 77641f88c5047c990df649658b6bd5fba0d395cd Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Sat, 31 May 2025 15:59:59 +0300
Subject: [PATCH] [Clang] add fix-it hints for unknown attributes

---
 .../include/clang/Basic/AttributeCommonInfo.h |  50 +++--
 .../include/clang/Basic/AttributeScopeInfo.h  |  35 
 clang/include/clang/Sema/ParsedAttr.h | 184 +-
 clang/lib/AST/ASTImporter.cpp |   5 +-
 clang/lib/Basic/Attributes.cpp|  55 --
 clang/lib/Parse/ParseDecl.cpp |  96 -
 clang/lib/Parse/ParseDeclCXX.cpp  |  37 ++--
 clang/lib/Parse/ParseExprCXX.cpp  |   4 +-
 clang/lib/Parse/ParseHLSL.cpp |   4 +-
 clang/lib/Parse/ParseObjc.cpp |   2 +-
 clang/lib/Parse/ParsePragma.cpp   |   2 +-
 clang/lib/Parse/ParseStmt.cpp |   4 +-
 clang/lib/Sema/SemaAPINotes.cpp   |   7 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  58 --
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/lib/Sema/SemaStmtAttr.cpp   |  14 +-
 clang/lib/Sema/SemaType.cpp   |  10 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |   4 +-
 .../dcl.module/dcl.module.import/p1.cppm  |   2 +-
 clang/test/FixIt/fixit-unknown-attributes.cpp |  68 +++
 .../Parser/cxx11-base-spec-attributes.cpp |   2 +-
 clang/test/Parser/objcxx11-attributes.mm  |   2 +-
 clang/test/Sema/unknown-attributes.c  |  11 +-
 ...attr-non-x86-no_caller_saved_registers.cpp |   2 +-
 24 files changed, 413 insertions(+), 248 deletions(-)
 create mode 100644 clang/include/clang/Basic/AttributeScopeInfo.h
 create mode 100644 clang/test/FixIt/fixit-unknown-attributes.cpp

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index b4b8345b4ed40..5501c7fe07d76 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H
 #define LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H
 
+#include "clang/Basic/AttributeScopeInfo.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TokenKinds.h"
 
@@ -61,6 +62,7 @@ class AttributeCommonInfo {
 /// implicitly.
 AS_Implicit
   };
+
   enum Kind {
 #define PARSED_ATTR(NAME) AT_##NAME,
 #include "clang/Basic/AttrParsedAttrList.inc"
@@ -78,9 +80,9 @@ class AttributeCommonInfo {
 
 private:
   const IdentifierInfo *AttrName = nullptr;
-  const IdentifierInfo *ScopeName = nullptr;
+  AttributeScopeInfo AttrScope;
   SourceRange AttrRange;
-  const SourceLocation ScopeLoc;
+
   // Corresponds to the Kind enum.
   LLVM_PREFERRED_TYPE(Kind)
   unsigned AttrKind : 16;
@@ -146,11 +148,10 @@ class AttributeCommonInfo {
   };
 
   AttributeCommonInfo(const IdentifierInfo *AttrName,
-  const IdentifierInfo *ScopeName, SourceRange AttrRange,
-  SourceLocation ScopeLoc, Kind AttrKind, Form FormUsed)
-  : AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange),
-ScopeLoc(ScopeLoc), AttrKind(AttrKind),
-SyntaxUsed(FormUsed.getSyntax()),
+  AttributeScopeInfo AttrScope, SourceRange AttrRange,
+  Kind AttrKind, Form FormUsed)
+  : AttrName(AttrName), AttrScope(AttrScope), AttrRange(AttrRange),
+AttrKind(AttrKind), SyntaxUsed(FormUsed.getSyntax()),
 SpellingIndex(FormUsed.getSpellingIndex()),
 IsAlignas(FormUsed.isAlignas()),
 IsRegularKeywordAttribute(FormUsed.isRegularKeywordAttribute()) {
@@ -158,21 +159,20 @@ class AttributeCommonInfo {
"Invalid syntax!");
   }
 
-  AttributeCommonInfo(const IdentifierInfo *AttrName,
-  const IdentifierInfo *ScopeName, SourceRange AttrRange,
-  SourceLocation ScopeLoc, Form FormUsed)
+  AttributeCommonInfo(const IdentifierInfo *AttrName, AttributeScopeInfo Scope,
+  SourceRange AttrRange, Form FormUsed)
   : AttributeCommonInfo(
-AttrName, ScopeName, AttrRange, ScopeLoc,
-getParsedKind(AttrName, ScopeName, FormUsed.getSyntax()),
+AttrName, Scope, AttrRange,
+getParsedKind(AttrName, Scope.getName(), FormUsed.getSyntax()),
 FormUsed) {}
 
   AttributeCommonInfo(const IdentifierInfo *AttrName, SourceRange AttrRange,
   Form FormUsed)
-  : AttributeCommonInfo(AttrName, nullptr, AttrRange, SourceLocation(),
+  : AttributeCommonInfo(AttrName, AttributeScopeInfo(), AttrRange,
 FormUsed) {}
 
   AttributeCommonInfo(SourceRange AttrRange, Kind K, Form FormUsed)
-  : AttributeCommonInfo(nullptr, nullptr, AttrRange, SourceLocation(), K,
+  : AttributeCommonInfo(nullptr, A

[clang] [clang-tools-extra] [llvm] [clang] Simplify device kernel attributes (PR #137882)

2025-06-02 Thread Nick Sarnie via cfe-commits

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


[clang] [clang][Sema] Fix and reapply 'Declare builtins used in #pragma intrinsic #138205' (PR #142019)

2025-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nick Sarnie (sarnex)


Changes

I had to revert https://github.com/llvm/llvm-project/pull/138205 in 
https://github.com/llvm/llvm-project/pull/138205 because it broke the Chrome 
build.

The problem came down to the following:

```c++
unsigned __int64 _umul128(unsigned __int64, unsigned __int64,
  unsigned __int64 *);

namespace {}
#pragma intrinsic(_umul128)

 void foo() {
   unsigned __int64 carry;
   unsigned __int64 low = _umul128(0, 0, &carry);
 }
```

When processing the `#pragma intrinsic` line, we do a name lookup to see if the 
builtin was previously declared. In this case the lookup fails because the 
current namespace of the parser and sema is the above namespace scope. The 
processing of the pragma happens as part of the namespace close parsing. This 
is usually fine because most pragmas don't care about scopes. However, that's 
not true for this and other MS pragmas.

To fix this, we change the `#pragma intrinsic` processing to be the same as 
other MS pragmas such as "optimize". Those are processed like a declaration, 
and because of that we have the correct current scope, so the lookup succeeds.

I added a test case that locks down the Chrome fix, as well as manually tested 
the Chrome build and confirmed it passed.

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


5 Files Affected:

- (modified) clang/include/clang/Parse/Parser.h (+4) 
- (modified) clang/lib/Parse/ParsePragma.cpp (+53-58) 
- (added) clang/test/Sema/Inputs/builtin-system-header.h (+9) 
- (added) clang/test/Sema/builtin-pragma-intrinsic-namespace.cpp (+32) 
- (added) clang/test/Sema/builtin-pragma-intrinsic.c (+25) 


``diff
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index c4bef4729fd36..98db8201390be 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -7074,6 +7074,10 @@ class Parser : public CodeCompletionHandler {
   bool HandlePragmaMSOptimize(StringRef PragmaName,
   SourceLocation PragmaLocation);
 
+  // #pragma intrinsic("foo")
+  bool HandlePragmaMSIntrinsic(StringRef PragmaName,
+   SourceLocation PragmaLocation);
+
   /// Handle the annotation token produced for
   /// #pragma align...
   void HandlePragmaAlign();
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 77b61af768993..6341e565b5042 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -300,12 +300,6 @@ struct PragmaMSRuntimeChecksHandler : public 
EmptyPragmaHandler {
   PragmaMSRuntimeChecksHandler() : EmptyPragmaHandler("runtime_checks") {}
 };
 
-struct PragmaMSIntrinsicHandler : public PragmaHandler {
-  PragmaMSIntrinsicHandler() : PragmaHandler("intrinsic") {}
-  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
-Token &FirstToken) override;
-};
-
 // "\#pragma fenv_access (on)".
 struct PragmaMSFenvAccessHandler : public PragmaHandler {
   PragmaMSFenvAccessHandler() : PragmaHandler("fenv_access") {}
@@ -517,7 +511,7 @@ void Parser::initializePragmaHandlers() {
 PP.AddPragmaHandler(MSOptimize.get());
 MSRuntimeChecks = std::make_unique();
 PP.AddPragmaHandler(MSRuntimeChecks.get());
-MSIntrinsic = std::make_unique();
+MSIntrinsic = std::make_unique("intrinsic");
 PP.AddPragmaHandler(MSIntrinsic.get());
 MSFenvAccess = std::make_unique();
 PP.AddPragmaHandler(MSFenvAccess.get());
@@ -1046,7 +1040,8 @@ void Parser::HandlePragmaMSPragma() {
   .Case("strict_gs_check", 
&Parser::HandlePragmaMSStrictGuardStackCheck)
   .Case("function", &Parser::HandlePragmaMSFunction)
   .Case("alloc_text", &Parser::HandlePragmaMSAllocText)
-  .Case("optimize", &Parser::HandlePragmaMSOptimize);
+  .Case("optimize", &Parser::HandlePragmaMSOptimize)
+  .Case("intrinsic", &Parser::HandlePragmaMSIntrinsic);
 
   if (!(this->*Handler)(PragmaName, PragmaLocation)) {
 // Pragma handling failed, and has been diagnosed.  Slurp up the tokens
@@ -3762,56 +3757,6 @@ void PragmaUnrollHintHandler::HandlePragma(Preprocessor 
&PP,
   /*DisableMacroExpansion=*/false, /*IsReinject=*/false);
 }
 
-/// Handle the Microsoft \#pragma intrinsic extension.
-///
-/// The syntax is:
-/// \code
-///  #pragma intrinsic(memset)
-///  #pragma intrinsic(strlen, memcpy)
-/// \endcode
-///
-/// Pragma intrisic tells the compiler to use a builtin version of the
-/// function. Clang does it anyway, so the pragma doesn't really do anything.
-/// Anyway, we emit a warning if the function specified in \#pragma intrinsic
-/// isn't an intrinsic in clang and suggest to include intrin.h.
-void PragmaMSIntrinsicHandler::HandlePragma(Preprocessor &PP,
-PragmaIntroducer Introducer,
-

[clang] [SPIR-V] Only emit __spirv__ when targeting HLSL (PR #142401)

2025-06-02 Thread Aaron Ballman via cfe-commits

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

LGTM! @jsji does  this resolve the issue on your end?

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


[clang] [ASTMatchers] Remove unused includes (NFC) (PR #142407)

2025-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.


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


5 Files Affected:

- (modified) clang/lib/ASTMatchers/ASTMatchersInternal.cpp (-3) 
- (modified) clang/lib/ASTMatchers/Dynamic/Parser.cpp (-1) 
- (modified) clang/lib/ASTMatchers/Dynamic/Registry.cpp (-2) 
- (modified) clang/lib/ASTMatchers/Dynamic/VariantValue.cpp (-1) 
- (modified) clang/lib/ASTMatchers/GtestMatchers.cpp (-5) 


``diff
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 9c7943a98d652..9cc50a656d37f 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -26,13 +26,10 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
 #include 
 #include 
 #include 
diff --git a/clang/lib/ASTMatchers/Dynamic/Parser.cpp 
b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
index 6a16c2184fcfb..8a5ac4d0f9d0c 100644
--- a/clang/lib/ASTMatchers/Dynamic/Parser.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
@@ -19,7 +19,6 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
-#include 
 #include 
 #include 
 #include 
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 336d3a14f7955..562df715e08ae 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -17,13 +17,11 @@
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/ASTMatchers/Dynamic/Diagnostics.h"
 #include "clang/ASTMatchers/Dynamic/VariantValue.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp 
b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
index 4f6b021b26f05..2309c8a9b556b 100644
--- a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
@@ -13,7 +13,6 @@
 
 #include "clang/ASTMatchers/Dynamic/VariantValue.h"
 #include "clang/Basic/LLVM.h"
-#include "llvm/ADT/STLExtras.h"
 #include 
 
 namespace clang {
diff --git a/clang/lib/ASTMatchers/GtestMatchers.cpp 
b/clang/lib/ASTMatchers/GtestMatchers.cpp
index a556d8ef2da06..7c135bbfe7cb0 100644
--- a/clang/lib/ASTMatchers/GtestMatchers.cpp
+++ b/clang/lib/ASTMatchers/GtestMatchers.cpp
@@ -16,11 +16,6 @@
 
//===--===//
 
 #include "clang/ASTMatchers/GtestMatchers.h"
-#include "clang/AST/ASTConsumer.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace clang {

``




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


[clang] 3b4c51b - [clang-repl] Fix error recovery while PTU cleanup (#127467)

2025-06-02 Thread via cfe-commits

Author: Anutosh Bhat
Date: 2025-06-02T20:14:28+05:30
New Revision: 3b4c51bb3243a02526313c51207a674139b67a00

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

LOG: [clang-repl] Fix error recovery while PTU cleanup (#127467)

Fixes #123300

What is seen 
```
clang-repl> int x = 42;
clang-repl> auto capture = [&]() { return x * 2; };
In file included from <<< inputs >>>:1:
input_line_4:1:17: error: non-local lambda expression cannot have a 
capture-default
1 | auto capture = [&]() { return x * 2; };
  | ^
zsh: segmentation fault  clang-repl --Xcc="-v"

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS 
(code=1, address=0x8)
  * frame #0: 0x000107b4f8b8 
libclang-cpp.19.1.dylib`clang::IncrementalParser::CleanUpPTU(clang::PartialTranslationUnit&)
 + 988
frame #1: 0x000107b4f1b4 
libclang-cpp.19.1.dylib`clang::IncrementalParser::ParseOrWrapTopLevelDecl() + 
416
frame #2: 0x000107b4fb94 
libclang-cpp.19.1.dylib`clang::IncrementalParser::Parse(llvm::StringRef) + 612
frame #3: 0x000107b52fec 
libclang-cpp.19.1.dylib`clang::Interpreter::ParseAndExecute(llvm::StringRef, 
clang::Value*) + 180
frame #4: 0x00013498 clang-repl`main + 3560
frame #5: 0x00018d39a0e0 dyld`start + 2360
```

Though the error is justified, we shouldn't be interested in exiting
through a segfault in such cases.

The issue is that empty named decls weren't being taken care of
resulting into this assert


https://github.com/llvm/llvm-project/blob/c1a229252617ed58f943bf3f4698bd8204ee0f04/clang/include/clang/AST/DeclarationName.h#L503

Can also be seen when the example is attempted through xeus-cpp-lite.


![image](https://github.com/user-attachments/assets/9b0e6ead-138e-4b06-9ad9-fcb9f8d5bf6e)

Added: 


Modified: 
clang/lib/Interpreter/IncrementalParser.cpp
clang/test/Interpreter/lambda.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 41d6304bd5f65..6343f17ed822a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -176,7 +176,7 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty())
   continue;
 // Check if we need to clean up the IdResolver chain.
 if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&

diff  --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..7e5e1057e4c9e 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck %s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,14 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error {{non-local lambda expression cannot have a capture-default}}
+auto capture = [&]() { return x * 2; };
+
+// Ensure interpreter continues and x is still valid
+printf("x = %d\n", x);
+// CHECK: x = 42
+
+%quit
\ No newline at end of file



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


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-02 Thread Anutosh Bhat via cfe-commits

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


[clang] [clang][python][test] Check if libclang.so is loadable (PR #142353)

2025-06-02 Thread Rainer Orth via cfe-commits

rorth wrote:

> > trying to load a 32-bit libclang.so into a 64-bit python is always an 
> > error, testsuite or no.
> 
> That's why you shouldn't return an exit code of 0 when this error occurs. 
> Moreover, this seems like a workaround for that one specific issue you 
> encountered. To connect this with:
> 
> > Even if the error message were emitted, this doesn't help because ninja 
> > check-all is still broken, there being no way to disable check-clang-python 
> > even manually.
> 
> Wouldn't it be a better solution to wrap the `check-clang-python` target 
> somehow as to change the exit code to 0? E.g. just pipe to `true` or `echo` 
> or something like that. (is there an issue with that approach? I'm not that 
> familiar with cmake)

That might work, though I'm not sure if this also works on Windows or non-Unix 
systems in general.  Alternatively, as I suggested, one could wrap the actual 
`python -m unittest discover` invocation with a check if `libclang.so` is 
loadable at all, only then running the actual test.  I had something like
```
import os
from clang.cindex import Config
conf = Config()
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
conf.lib
```
initially until I realized that doing this at `cmake` time would disable the 
test everywhere (no `libclang.so` exists at that point).

One problem with all these approaches, as I'd already mentioned, is that the 
test outcome isn't properly reported, nor can one use the usual machinery to 
`XFAIL` the test or declare it `UNSUPPORTED`.  That's all hardcoded inside 
`test/CMakeLists.txt`.

> Probably not relevant then, but is there a reason you called `os._exit` 
> instead of `sys.exit`? `os._exit` skips exit handlers etc. so `sys.exit` is 
> usually preferred (though I doubt it makes a difference here)

I tried that at first, but got the `warning: ` many times for every single 
subtest, which seems excessively verbose to me ;-)


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


[clang] [APINotes] Remove unused includes (NFC) (PR #142406)

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

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/142406

These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.


>From 6fe2dd8eb56b768f4e22a04c1affb1d7f767bb68 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Mon, 2 Jun 2025 07:16:08 -0700
Subject: [PATCH] [APINotes] Remove unused includes (NFC)

These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
---
 clang/lib/APINotes/APINotesManager.cpp | 2 --
 clang/lib/APINotes/APINotesReader.cpp  | 2 --
 2 files changed, 4 deletions(-)

diff --git a/clang/lib/APINotes/APINotesManager.cpp 
b/clang/lib/APINotes/APINotesManager.cpp
index 7f8a126ffaa03..4dc6ffd66bd53 100644
--- a/clang/lib/APINotes/APINotesManager.cpp
+++ b/clang/lib/APINotes/APINotesManager.cpp
@@ -15,9 +15,7 @@
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/SourceMgrAdapter.h"
-#include "clang/Basic/Version.h"
 #include "llvm/ADT/APInt.h"
-#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index b55872446ac43..7cc4df2a99369 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -16,10 +16,8 @@
 #include "APINotesFormat.h"
 #include "clang/APINotes/Types.h"
 #include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/Bitstream/BitstreamReader.h"
 #include "llvm/Support/DJB.h"
-#include "llvm/Support/EndianStream.h"
 #include "llvm/Support/OnDiskHashTable.h"
 
 namespace clang {

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


[clang] [ASTMatchers] Remove unused includes (NFC) (PR #142407)

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

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/142407

These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.


>From c1aa2cb687eb4e14373fbb60931f086305fae2f1 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Mon, 2 Jun 2025 07:16:24 -0700
Subject: [PATCH] [ASTMatchers] Remove unused includes (NFC)

These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
---
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp  | 3 ---
 clang/lib/ASTMatchers/Dynamic/Parser.cpp   | 1 -
 clang/lib/ASTMatchers/Dynamic/Registry.cpp | 2 --
 clang/lib/ASTMatchers/Dynamic/VariantValue.cpp | 1 -
 clang/lib/ASTMatchers/GtestMatchers.cpp| 5 -
 5 files changed, 12 deletions(-)

diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 9c7943a98d652..9cc50a656d37f 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -26,13 +26,10 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
 #include 
 #include 
 #include 
diff --git a/clang/lib/ASTMatchers/Dynamic/Parser.cpp 
b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
index 6a16c2184fcfb..8a5ac4d0f9d0c 100644
--- a/clang/lib/ASTMatchers/Dynamic/Parser.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
@@ -19,7 +19,6 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
-#include 
 #include 
 #include 
 #include 
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 336d3a14f7955..562df715e08ae 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -17,13 +17,11 @@
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/ASTMatchers/Dynamic/Diagnostics.h"
 #include "clang/ASTMatchers/Dynamic/VariantValue.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp 
b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
index 4f6b021b26f05..2309c8a9b556b 100644
--- a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
@@ -13,7 +13,6 @@
 
 #include "clang/ASTMatchers/Dynamic/VariantValue.h"
 #include "clang/Basic/LLVM.h"
-#include "llvm/ADT/STLExtras.h"
 #include 
 
 namespace clang {
diff --git a/clang/lib/ASTMatchers/GtestMatchers.cpp 
b/clang/lib/ASTMatchers/GtestMatchers.cpp
index a556d8ef2da06..7c135bbfe7cb0 100644
--- a/clang/lib/ASTMatchers/GtestMatchers.cpp
+++ b/clang/lib/ASTMatchers/GtestMatchers.cpp
@@ -16,11 +16,6 @@
 
//===--===//
 
 #include "clang/ASTMatchers/GtestMatchers.h"
-#include "clang/AST/ASTConsumer.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace clang {

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


[clang] [clang-format] Correctly annotate token-pasted function decl names (PR #142337)

2025-06-02 Thread Björn Schäpers via cfe-commits

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


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


[clang] [APINotes] Remove unused includes (NFC) (PR #142406)

2025-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.


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


2 Files Affected:

- (modified) clang/lib/APINotes/APINotesManager.cpp (-2) 
- (modified) clang/lib/APINotes/APINotesReader.cpp (-2) 


``diff
diff --git a/clang/lib/APINotes/APINotesManager.cpp 
b/clang/lib/APINotes/APINotesManager.cpp
index 7f8a126ffaa03..4dc6ffd66bd53 100644
--- a/clang/lib/APINotes/APINotesManager.cpp
+++ b/clang/lib/APINotes/APINotesManager.cpp
@@ -15,9 +15,7 @@
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/SourceMgrAdapter.h"
-#include "clang/Basic/Version.h"
 #include "llvm/ADT/APInt.h"
-#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index b55872446ac43..7cc4df2a99369 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -16,10 +16,8 @@
 #include "APINotesFormat.h"
 #include "clang/APINotes/Types.h"
 #include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/Bitstream/BitstreamReader.h"
 #include "llvm/Support/DJB.h"
-#include "llvm/Support/EndianStream.h"
 #include "llvm/Support/OnDiskHashTable.h"
 
 namespace clang {

``




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


[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (MaggieYingYi)


Changes

As part of the mixed host bring up, the support of PCH (precompiled headers) 
has been raised as a potential issue. Visual Studio has an argument to ignore 
all PCH related switches. clang-cl has also support option /Y-. Having the same 
option in clang would be helpful. This commit is to add support for ignoring 
PCH options (-ignore-pch).

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


6 Files Affected:

- (modified) clang/docs/PCHInternals.rst (+10) 
- (modified) clang/docs/UsersManual.rst (+14) 
- (modified) clang/include/clang/Driver/Options.td (+2) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+9) 
- (added) clang/test/PCH/Inputs/ignored-pch.h (+6) 
- (added) clang/test/PCH/ignored-pch.c (+114) 


``diff
diff --git a/clang/docs/PCHInternals.rst b/clang/docs/PCHInternals.rst
index 079fba16711dc..de0b341460cac 100644
--- a/clang/docs/PCHInternals.rst
+++ b/clang/docs/PCHInternals.rst
@@ -31,6 +31,16 @@ option:
 
   $ clang -cc1 -include-pch test.h.pch test.c -o test.s
 
+To ignore PCH options using ``clang -cc1``, use the option `-ignore-pch`:
+
+.. code-block:: bash
+
+  $ clang -cc1 test.h -emit-pch -ignore-pch -o test.h.pch
+  $ clang -cc1 -include-pch test.h.pch -ignore-pch test.c -o test.s
+
+This option disables precompiled headers, overrides -emit-pch and -include-pch.
+test.h.pch is not generated and not used as a prefix header.
+
 Design Philosophy
 -
 
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index eb9a812f0c1c9..f12b6b4c02193 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1458,6 +1458,20 @@ will be processed from the PCH file. Otherwise, Clang 
will report an error.
   ``test.h`` since ``test.h`` was included directly in the source file and not
   specified on the command line using ``-include-pch``.
 
+Ignoring a PCH File
+^^^
+
+To ignore a PCH file using Clang, the `-Xclang -ignore-pch` option is passed to
+``clang``:
+
+.. code-block:: console
+
+  $ clang -x c-header test.h -Xclang -ignore-pch -o test.h.pch
+  $ clang -include-pch test.h.pch -Xclang -ignore-pch test.c -o test
+
+This option disables precompiled headers, overrides -emit-pch and -include-pch.
+test.h.pch is not generated and not used as a prefix header.
+
 Relocatable PCH Files
 ^
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5ca31c253ed8f..3ed87608bf592 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8127,6 +8127,8 @@ def emit_header_unit : Flag<["-"], "emit-header-unit">,
   HelpText<"Generate C++20 header units from header files">;
 def emit_pch : Flag<["-"], "emit-pch">,
   HelpText<"Generate pre-compiled header file">;
+def ignore_pch : Flag<["-"], "ignore-pch">,
+  HelpText<"Ignore pre-compiled header options">;
 def emit_llvm_only : Flag<["-"], "emit-llvm-only">,
   HelpText<"Build ASTs and convert to LLVM, discarding output">;
 def emit_codegen_only : Flag<["-"], "emit-codegen-only">,
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2c02719121c73..19f81ff2fbe9d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2982,6 +2982,15 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
 #undef FRONTEND_OPTION_WITH_MARSHALLING
 
   Opts.ProgramAction = frontend::ParseSyntaxOnly;
+
+  // If -ignore-pch is used, all pch handling is disabled. clang pch-related
+  // flags are removed.
+  if (Args.hasArg(options::OPT_ignore_pch)) {
+Args.eraseArg(options::OPT_emit_pch);
+Args.eraseArg(options::OPT_include_pch);
+Args.eraseArg(options::OPT_ignore_pch);
+  }
+
   if (const Arg *A = Args.getLastArg(OPT_Action_Group)) {
 OptSpecifier Opt = OptSpecifier(A->getOption().getID());
 std::optional ProgramAction = getFrontendAction(Opt);
diff --git a/clang/test/PCH/Inputs/ignored-pch.h 
b/clang/test/PCH/Inputs/ignored-pch.h
new file mode 100644
index 0..0956f9da1cb16
--- /dev/null
+++ b/clang/test/PCH/Inputs/ignored-pch.h
@@ -0,0 +1,6 @@
+#ifndef IGNORED_PCH_H
+#define IGNORED_PCH_H
+inline int f() {
+  return 42;
+}
+#endif // IGNORED_PCH_H
\ No newline at end of file
diff --git a/clang/test/PCH/ignored-pch.c b/clang/test/PCH/ignored-pch.c
new file mode 100644
index 0..198ad0fde7d05
--- /dev/null
+++ b/clang/test/PCH/ignored-pch.c
@@ -0,0 +1,114 @@
+// RUN: rm -rf %t.pch %t.ll
+// RUN: %clang_cc1 -x c-header %S/Inputs/ignored-pch.h -emit-pch -o %t.pch
+// RUN: %clang_cc1 %s -include-pch %t.pch -emit-llvm -o %t.ll
+// RUN: ls %t.pch | FileCheck --check-prefix=CHECK-PCH %s
+// RUN: ls %t.ll | FileCheck --check-prefix=CHECK-OBJ %s
+
+// Check that -ignore-pch causes -emit-pch and -include-pch options to be 
ignored.
+// RUN: rm

[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-02 Thread via cfe-commits

https://github.com/MaggieYingYi created 
https://github.com/llvm/llvm-project/pull/142409

As part of the mixed host bring up, the support of PCH (precompiled headers) 
has been raised as a potential issue. Visual Studio has an argument to ignore 
all PCH related switches. clang-cl has also support option /Y-. Having the same 
option in clang would be helpful. This commit is to add support for ignoring 
PCH options (-ignore-pch).

>From 6eb6900243f4561d071656d39dcaa4759b074d34 Mon Sep 17 00:00:00 2001
From: Ying Yi 
Date: Mon, 2 Jun 2025 10:21:22 +0100
Subject: [PATCH] [Frontend][PCH]-Add support for ignoring PCH options
 (-ignore-pch).

As part of the mixed host bring up, the support of PCH (precompiled headers) 
has been raised as a potential issue. Visual Studio has an argument to ignore 
all PCH related switches. clang-cl has also support option /Y-. Having the same 
option in clang would be helpful. This commit is to add support for ignoring 
PCH options (-ignore-pch).
---
 clang/docs/PCHInternals.rst   |  10 ++
 clang/docs/UsersManual.rst|  14 +++
 clang/include/clang/Driver/Options.td |   2 +
 clang/lib/Frontend/CompilerInvocation.cpp |   9 ++
 clang/test/PCH/Inputs/ignored-pch.h   |   6 ++
 clang/test/PCH/ignored-pch.c  | 114 ++
 6 files changed, 155 insertions(+)
 create mode 100644 clang/test/PCH/Inputs/ignored-pch.h
 create mode 100644 clang/test/PCH/ignored-pch.c

diff --git a/clang/docs/PCHInternals.rst b/clang/docs/PCHInternals.rst
index 079fba16711dc..de0b341460cac 100644
--- a/clang/docs/PCHInternals.rst
+++ b/clang/docs/PCHInternals.rst
@@ -31,6 +31,16 @@ option:
 
   $ clang -cc1 -include-pch test.h.pch test.c -o test.s
 
+To ignore PCH options using ``clang -cc1``, use the option `-ignore-pch`:
+
+.. code-block:: bash
+
+  $ clang -cc1 test.h -emit-pch -ignore-pch -o test.h.pch
+  $ clang -cc1 -include-pch test.h.pch -ignore-pch test.c -o test.s
+
+This option disables precompiled headers, overrides -emit-pch and -include-pch.
+test.h.pch is not generated and not used as a prefix header.
+
 Design Philosophy
 -
 
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index eb9a812f0c1c9..f12b6b4c02193 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1458,6 +1458,20 @@ will be processed from the PCH file. Otherwise, Clang 
will report an error.
   ``test.h`` since ``test.h`` was included directly in the source file and not
   specified on the command line using ``-include-pch``.
 
+Ignoring a PCH File
+^^^
+
+To ignore a PCH file using Clang, the `-Xclang -ignore-pch` option is passed to
+``clang``:
+
+.. code-block:: console
+
+  $ clang -x c-header test.h -Xclang -ignore-pch -o test.h.pch
+  $ clang -include-pch test.h.pch -Xclang -ignore-pch test.c -o test
+
+This option disables precompiled headers, overrides -emit-pch and -include-pch.
+test.h.pch is not generated and not used as a prefix header.
+
 Relocatable PCH Files
 ^
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5ca31c253ed8f..3ed87608bf592 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8127,6 +8127,8 @@ def emit_header_unit : Flag<["-"], "emit-header-unit">,
   HelpText<"Generate C++20 header units from header files">;
 def emit_pch : Flag<["-"], "emit-pch">,
   HelpText<"Generate pre-compiled header file">;
+def ignore_pch : Flag<["-"], "ignore-pch">,
+  HelpText<"Ignore pre-compiled header options">;
 def emit_llvm_only : Flag<["-"], "emit-llvm-only">,
   HelpText<"Build ASTs and convert to LLVM, discarding output">;
 def emit_codegen_only : Flag<["-"], "emit-codegen-only">,
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2c02719121c73..19f81ff2fbe9d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2982,6 +2982,15 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
 #undef FRONTEND_OPTION_WITH_MARSHALLING
 
   Opts.ProgramAction = frontend::ParseSyntaxOnly;
+
+  // If -ignore-pch is used, all pch handling is disabled. clang pch-related
+  // flags are removed.
+  if (Args.hasArg(options::OPT_ignore_pch)) {
+Args.eraseArg(options::OPT_emit_pch);
+Args.eraseArg(options::OPT_include_pch);
+Args.eraseArg(options::OPT_ignore_pch);
+  }
+
   if (const Arg *A = Args.getLastArg(OPT_Action_Group)) {
 OptSpecifier Opt = OptSpecifier(A->getOption().getID());
 std::optional ProgramAction = getFrontendAction(Opt);
diff --git a/clang/test/PCH/Inputs/ignored-pch.h 
b/clang/test/PCH/Inputs/ignored-pch.h
new file mode 100644
index 0..0956f9da1cb16
--- /dev/null
+++ b/clang/test/PCH/Inputs/ignored-pch.h
@@ -0,0 +1,6 @@
+#ifndef IGNORED_PCH_H
+#define IGNORED_PCH_H
+inline int f() {
+  return 42;
+}
+#endif // IGN

[clang] [clang][AIX] Fix -print-runtime-dir fallback on AIX (PR #141439)

2025-06-02 Thread Daniel Chen via cfe-commits

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

LGTM.
Thanks.

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


[clang] [clang][Basic] Optimize getDiagnosticSeverity() (PR #141950)

2025-06-02 Thread via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


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


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


[clang] [clang][Basic] Optimize getDiagnosticSeverity() (PR #141950)

2025-06-02 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [llvm] Global string alignment (PR #142346)

2025-06-02 Thread Dominik Steenken via cfe-commits

dominik-steenken wrote:

@uweigand FYI

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread via cfe-commits


@@ -2083,6 +2086,97 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+  << B.getSourceRange();
+}
+  }
+  for (const FieldDecl *Field : D->fields()) {
+if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCField << Field
+  << Field->getType() << Field->getSourceRange();
+  }
+  if (D->hasDeletedDestructor())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
+<< D->getDestructor()->getSourceRange();
+
+  if (D->isUnion()) {
+auto DiagSPM = [&](CXXSpecialMemberKind K, bool Has) {
+  if (Has)
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::UnionWithUserDeclaredSMF << K;
+};
+DiagSPM(CXXSpecialMemberKind::CopyConstructor,
+D->hasUserDeclaredCopyConstructor());
+DiagSPM(CXXSpecialMemberKind::CopyAssignment,
+D->hasUserDeclaredCopyAssignment());
+DiagSPM(CXXSpecialMemberKind::MoveConstructor,
+D->hasUserDeclaredMoveConstructor());
+DiagSPM(CXXSpecialMemberKind::MoveAssignment,
+D->hasUserDeclaredMoveAssignment());
+return;
+  }
+
+  if (!D->hasSimpleMoveConstructor() && !D->hasSimpleCopyConstructor()) {
+const auto *Decl = cast(
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false));
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedCtr
+  << Decl->isMoveConstructor() << Decl->getSourceRange();
+  }
+  if (!D->hasSimpleMoveAssignment() && !D->hasSimpleCopyAssignment()) {
+CXXMethodDecl *Decl =
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/true);
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedAssign
+  << Decl->isMoveAssignmentOperator() << Decl->getSourceRange();
+  }
+  CXXDestructorDecl *Dtr = D->getDestructor();
+  if (Dtr && Dtr->isUserProvided() && !Dtr->isDefaulted())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 1
+<< Dtr->getSourceRange();

cor3ntin wrote:

It might be better to check that the destructor is trivial (`Dtr->isTrivial()`)

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread via cfe-commits


@@ -2083,6 +2086,97 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+  << B.getSourceRange();
+}
+  }
+  for (const FieldDecl *Field : D->fields()) {
+if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCField << Field
+  << Field->getType() << Field->getSourceRange();
+  }
+  if (D->hasDeletedDestructor())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
+<< D->getDestructor()->getSourceRange();
+
+  if (D->isUnion()) {
+auto DiagSPM = [&](CXXSpecialMemberKind K, bool Has) {
+  if (Has)
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::UnionWithUserDeclaredSMF << K;
+};
+DiagSPM(CXXSpecialMemberKind::CopyConstructor,
+D->hasUserDeclaredCopyConstructor());
+DiagSPM(CXXSpecialMemberKind::CopyAssignment,
+D->hasUserDeclaredCopyAssignment());
+DiagSPM(CXXSpecialMemberKind::MoveConstructor,
+D->hasUserDeclaredMoveConstructor());
+DiagSPM(CXXSpecialMemberKind::MoveAssignment,
+D->hasUserDeclaredMoveAssignment());
+return;
+  }

cor3ntin wrote:

There is no special rules for unions for trivially copyable

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread via cfe-commits

https://github.com/cor3ntin commented:

Thanks a lot for working on that!

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread via cfe-commits

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread via cfe-commits


@@ -2083,6 +2086,97 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+  << B.getSourceRange();
+}
+  }
+  for (const FieldDecl *Field : D->fields()) {
+if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCField << Field
+  << Field->getType() << Field->getSourceRange();
+  }
+  if (D->hasDeletedDestructor())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
+<< D->getDestructor()->getSourceRange();
+
+  if (D->isUnion()) {
+auto DiagSPM = [&](CXXSpecialMemberKind K, bool Has) {
+  if (Has)
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::UnionWithUserDeclaredSMF << K;
+};
+DiagSPM(CXXSpecialMemberKind::CopyConstructor,
+D->hasUserDeclaredCopyConstructor());
+DiagSPM(CXXSpecialMemberKind::CopyAssignment,
+D->hasUserDeclaredCopyAssignment());
+DiagSPM(CXXSpecialMemberKind::MoveConstructor,
+D->hasUserDeclaredMoveConstructor());
+DiagSPM(CXXSpecialMemberKind::MoveAssignment,
+D->hasUserDeclaredMoveAssignment());
+return;
+  }
+
+  if (!D->hasSimpleMoveConstructor() && !D->hasSimpleCopyConstructor()) {
+const auto *Decl = cast(
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false));
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedCtr
+  << Decl->isMoveConstructor() << Decl->getSourceRange();
+  }
+  if (!D->hasSimpleMoveAssignment() && !D->hasSimpleCopyAssignment()) {
+CXXMethodDecl *Decl =
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/true);
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedAssign
+  << Decl->isMoveAssignmentOperator() << Decl->getSourceRange();
+  }
+  CXXDestructorDecl *Dtr = D->getDestructor();
+  if (Dtr && Dtr->isUserProvided() && !Dtr->isDefaulted())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 1
+<< Dtr->getSourceRange();
+}
+
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc, QualType T) 
{
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait)
+  << T << diag::TraitName::TriviallyCopyable;
+
+  if (T->isReferenceType())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::Ref;
+
+  T = T.getNonReferenceType();
+
+  if (T.hasNonTrivialObjCLifetime())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::HasArcLifetime;

cor3ntin wrote:

Arc lifetimes do not impact the ability to copy a type afaik (but they might 
impact the ability to copy a class containing them, in which case they should 
have a deleted constructor) @ojhunt 

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread via cfe-commits


@@ -2083,6 +2086,97 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+  << B.getSourceRange();
+}
+  }
+  for (const FieldDecl *Field : D->fields()) {
+if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCField << Field
+  << Field->getType() << Field->getSourceRange();
+  }
+  if (D->hasDeletedDestructor())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
+<< D->getDestructor()->getSourceRange();
+
+  if (D->isUnion()) {
+auto DiagSPM = [&](CXXSpecialMemberKind K, bool Has) {
+  if (Has)
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::UnionWithUserDeclaredSMF << K;
+};
+DiagSPM(CXXSpecialMemberKind::CopyConstructor,
+D->hasUserDeclaredCopyConstructor());
+DiagSPM(CXXSpecialMemberKind::CopyAssignment,
+D->hasUserDeclaredCopyAssignment());
+DiagSPM(CXXSpecialMemberKind::MoveConstructor,
+D->hasUserDeclaredMoveConstructor());
+DiagSPM(CXXSpecialMemberKind::MoveAssignment,
+D->hasUserDeclaredMoveAssignment());
+return;
+  }
+
+  if (!D->hasSimpleMoveConstructor() && !D->hasSimpleCopyConstructor()) {
+const auto *Decl = cast(
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false));
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedCtr
+  << Decl->isMoveConstructor() << Decl->getSourceRange();
+  }
+  if (!D->hasSimpleMoveAssignment() && !D->hasSimpleCopyAssignment()) {
+CXXMethodDecl *Decl =
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/true);
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedAssign
+  << Decl->isMoveAssignmentOperator() << Decl->getSourceRange();
+  }

cor3ntin wrote:

For trivially copyable, the rule is that _all_ special members that exist must 
be trivial.
https://eel.is/c++draft/class.prop#1 

I think it would be better to iterate over all eligible special member 
functions, and emit a diagnostic for any one that is not trivial (using 
`D->methods()`, `FunctionDecl::isIneligibleOrNotSelected`, 
`FunctionDecl::getDefaultedFunctionKind`, and `FunctionDecl::isTrivial`

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


[clang] [llvm] Global string alignment (PR #142346)

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

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


[clang-tools-extra] [clang-tidy] Added check 'bugprone-function-visibility-change' (PR #140086)

2025-06-02 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/140086

From 65d44a4eb9621e49a96f1ac43e5a1bbd6691dc13 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Thu, 15 May 2025 17:41:16 +0200
Subject: [PATCH 1/6] [clang-tidy] Added check
 'bugprone-function-visibility-change'

---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 .../FunctionVisibilityChangeCheck.cpp |  74 ++
 .../bugprone/FunctionVisibilityChangeCheck.h  |  33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../bugprone/function-visibility-change.rst   |  43 
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../bugprone/function-visibility-change.cpp   | 234 ++
 8 files changed, 394 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/FunctionVisibilityChangeCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/FunctionVisibilityChangeCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/function-visibility-change.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/function-visibility-change.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index b780a85bdf3fe..7cf58c5218969 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -30,6 +30,7 @@
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
 #include "ForwardingReferenceOverloadCheck.h"
+#include "FunctionVisibilityChangeCheck.h"
 #include "ImplicitWideningOfMultiplicationResultCheck.h"
 #include "InaccurateEraseCheck.h"
 #include "IncDecInConditionsCheck.h"
@@ -143,6 +144,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-forward-declaration-namespace");
 CheckFactories.registerCheck(
 "bugprone-forwarding-reference-overload");
+CheckFactories.registerCheck(
+"bugprone-function-visibility-change");
 CheckFactories.registerCheck(
 "bugprone-implicit-widening-of-multiplication-result");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index e310ea9c94543..b4f7ba76f4cee 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   ForwardingReferenceOverloadCheck.cpp
+  FunctionVisibilityChangeCheck.cpp
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/FunctionVisibilityChangeCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/FunctionVisibilityChangeCheck.cpp
new file mode 100644
index 0..7ea4ed20705ed
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/FunctionVisibilityChangeCheck.cpp
@@ -0,0 +1,74 @@
+//===--- FunctionVisibilityChangeCheck.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 "FunctionVisibilityChangeCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void FunctionVisibilityChangeCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxMethodDecl(
+  ofClass(cxxRecordDecl().bind("class")),
+  
forEachOverridden(cxxMethodDecl(ofClass(cxxRecordDecl().bind("base")))
+.bind("base_func")))
+  .bind("func"),
+  this);
+}
+
+void FunctionVisibilityChangeCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MatchedFunction = Result.Nodes.getNodeAs("func");
+  const auto *ParentClass = Result.Nodes.getNodeAs("class");
+  const auto *OverriddenFunction =
+  Result.Nodes.getNodeAs("base_func");
+  const auto *BaseClass = Result.Nodes.getNodeAs("base");
+
+  if (!MatchedFunction->isCanonicalDecl())
+return;
+
+  AccessSpecifier ActualAccess = MatchedFunction->getAccess();
+  AccessSpecifier OverriddenAccess = OverriddenFunction->getAccess();
+
+  CXXBasePaths Paths;
+  if (!ParentClass->isDerivedFrom(BaseClass, Paths))
+return;
+  const CXXBaseSpecifier *InheritanceWithStrictVisibility = nullptr;
+  for (const CXXBasePath &Path : Paths) {
+for (auto Elem : Path) {
+  if (Elem.Base->getAccessSpecifier() > OverriddenAccess) {
+OverriddenAccess = Elem

[clang] [clang-format] Correctly annotate token-pasted function decl names (PR #142337)

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

owenca wrote:

@prj- I understand. If you use `AlignFunctionDeclarations`, you might see 
formatting changes as the first token in a token-pasted function decl name was 
not annotated correctly before this patch.

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


[clang] 016d578 - [clang][Tooling] Add symbol mappings for unwrap_reference_t

2025-06-02 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2025-06-02T10:30:00+02:00
New Revision: 016d57804ad6ee8012a5fdf1700c938ef3b7baf0

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

LOG: [clang][Tooling] Add symbol mappings for unwrap_reference_t

Tool is missing them as cppreference lists these under a section without
associated headers (`Helper types`).

Added: 


Modified: 
clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc

Removed: 




diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
index 44ad4a0d96844..a2c12007134d6 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -452,6 +452,8 @@ SYMBOL(equal_range, std::ranges::, )
 SYMBOL(lower_bound, std::ranges::, )
 SYMBOL(upper_bound, std::ranges::, )
 
+SYMBOL(unwrap_reference_t, std::, )
+
 // These are C symbols that are not under std namespace.
 SYMBOL(localtime_r, None, )
 SYMBOL(localtime_r, None, )



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


[clang] [clang-format] Correctly annotate token-pasted function decl names (PR #142337)

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


@@ -3848,6 +3848,8 @@ static bool isFunctionDeclarationName(const LangOptions 
&LangOpts,
   } else {
 if (Current.isNot(TT_StartOfName) || Current.NestingLevel != 0)
   return false;
+while (Next && Next->startsSequence(tok::hashhash, tok::identifier))

owenca wrote:

+1. Updated the test case.

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


[clang] [lldb] [lldb] Add filter option to AST dump command (PR #142164)

2025-06-02 Thread Pavel Labath via cfe-commits


@@ -8511,8 +8512,16 @@ TypeSystemClang::dump(lldb::opaque_compiler_type_t type) 
const {
 }
 #endif
 
-void TypeSystemClang::Dump(llvm::raw_ostream &output) {
-  GetTranslationUnitDecl()->dump(output);
+void TypeSystemClang::Dump(llvm::raw_ostream &output, llvm::StringRef filter) {
+  auto consumer =
+  clang::CreateASTDumper(output, filter,
+ /*DumpDecls=*/true,
+ /*Deserialize=*/false,
+ /*DumpLookups=*/false,
+ /*DumpDeclTypes=*/false, clang::ADOF_Default);
+  lldbassert(consumer);
+  lldbassert(m_ast_up);

labath wrote:

Use a plain assert? lldbassert is not going to help if you're going to 
dereference the pointer anyway.

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


[clang] [clang-format] Correctly annotate token-pasted function decl names (PR #142337)

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

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/142337

>From d088a50da78e67ee182074af594dd4f230d98357 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 1 Jun 2025 23:56:32 -0700
Subject: [PATCH 1/2] [clang-format] Correctly annotate token-pasted function
 decl names

Fix #142178
---
 clang/lib/Format/TokenAnnotator.cpp   | 2 ++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 7 +++
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index da1b6dd5254b8..da279d07b5918 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3848,6 +3848,8 @@ static bool isFunctionDeclarationName(const LangOptions 
&LangOpts,
   } else {
 if (Current.isNot(TT_StartOfName) || Current.NestingLevel != 0)
   return false;
+while (Next && Next->startsSequence(tok::hashhash, tok::identifier))
+  Next = Next->Next->Next;
 for (; Next; Next = Next->Next) {
   if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
 Next = Next->MatchingParen;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 1a5ed4b9040c2..9637085c70502 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2257,6 +2257,13 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsFunctionDeclarationNames) {
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_FunctionDeclarationLParen);
 
+  Tokens = annotate("#define FUNC(foo, bar) \\\n"
+"  auto foo##bar() -> Type {}");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_paren, TT_FunctionDeclarationLParen);
+  EXPECT_TOKEN(Tokens[14], tok::arrow, TT_TrailingReturnArrow);
+
   Tokens = annotate("int iso_time(time_t);");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);

>From 0138f9e990e47a6de2177ac8fa70942cbac1e673 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 2 Jun 2025 01:36:40 -0700
Subject: [PATCH 2/2] Enhance the added test case

---
 clang/unittests/Format/TokenAnnotatorTest.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 9637085c70502..8731dc36d371e 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2257,12 +2257,12 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsFunctionDeclarationNames) {
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_FunctionDeclarationLParen);
 
-  Tokens = annotate("#define FUNC(foo, bar) \\\n"
-"  auto foo##bar() -> Type {}");
-  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
-  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
-  EXPECT_TOKEN(Tokens[12], tok::l_paren, TT_FunctionDeclarationLParen);
-  EXPECT_TOKEN(Tokens[14], tok::arrow, TT_TrailingReturnArrow);
+  Tokens = annotate("#define FUNC(foo, bar, baz) \\\n"
+"  auto foo##bar##baz() -> Type {}");
+  ASSERT_EQ(Tokens.size(), 23u) << Tokens;
+  EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[16], tok::l_paren, TT_FunctionDeclarationLParen);
+  EXPECT_TOKEN(Tokens[18], tok::arrow, TT_TrailingReturnArrow);
 
   Tokens = annotate("int iso_time(time_t);");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;

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


[clang] [lldb] [lldb] Add filter option to AST dump command (PR #142164)

2025-06-02 Thread Pavel Labath via cfe-commits

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


[clang] [lldb] [lldb] Add filter option to AST dump command (PR #142164)

2025-06-02 Thread Pavel Labath via cfe-commits

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

The LLDB parts look good.

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


[clang] [clang][python][test] Check if libclang.so is loadable (PR #142353)

2025-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rainer Orth (rorth)


Changes

When building a 32-bit `clang` on a 64-bit system (like `i686-pc-linux-gnu` on 
a Linux/x86_64 system), `ninja check-all` fails:

```
FAILED: tools/clang/bindings/python/tests/CMakeFiles/check-clang-python 
tools/clang/bindings/python/tests/CMakeFiles/check-clang-python
cd clang/bindings/python && /usr/bin/cmake -E env 
CLANG_NO_DEFAULT_CONFIG=1 CLANG_LIBRARY_PATH=lib /usr/bin/python3.11 -m 
unittest discover

```
and stops with `exit 1`.

Further investigation shows that, `python3.11`, a 64-bit binary, tries to load 
the freshly build 32-bit `libclang.so`, which cannot work, thus breaking the 
build.

Rather than trying to second-guess this situation, which seems very fragile, 
it's better to actually handle this situation when trying the load, which is 
what this patch does.  The exact error message from `cdll.LoadLibrary` differs 
between systems:

- On Linux, you get ``` clang.cindex.LibclangError: lib/libclang.so: wrong ELF 
class: ELFCLASS32. ``` while
- on Solaris, there's ``` clang.cindex.LibclangError: ld.so.1: python3.11: 
lib/libclang.so: wrong ELF class: ELFCLASS32. ```

To allow for both cases, this patch just looks for the common `"wrong ELF 
class: ELFCLASS32"`.

Tested on `amd64-pc-solaris2.11`, `i386-pc-solaris2.11`, 
`sparcv9-sun-solaris2.11`, `sparc-sun-solaris2.11`, `x86_64-pc-linux-gnu`, and 
`i686-pc-linux-gnu`.

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


1 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+11-6) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 6f7243cdf80ac..b4e5898223f0f 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -4370,12 +4370,17 @@ def get_cindex_library(self) -> CDLL:
 try:
 library = cdll.LoadLibrary(self.get_filename())
 except OSError as e:
-msg = (
-str(e) + ". To provide a path to libclang use "
-"Config.set_library_path() or "
-"Config.set_library_file()."
-)
-raise LibclangError(msg)
+if "wrong ELF class: ELFCLASS32" in str(e):
+print("warning: skipping check-clang-python"
+  " since libclang cannot be loaded", file=sys.stderr)
+os._exit(0)
+else:
+msg = (
+str(e) + ". To provide a path to libclang use "
+"Config.set_library_path() or "
+"Config.set_library_file()."
+)
+raise LibclangError(msg)
 
 return library
 

``




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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread Shamshura Egor via cfe-commits


@@ -2083,6 +2086,97 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+  << B.getSourceRange();
+}
+  }
+  for (const FieldDecl *Field : D->fields()) {
+if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCField << Field
+  << Field->getType() << Field->getSourceRange();
+  }
+  if (D->hasDeletedDestructor())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
+<< D->getDestructor()->getSourceRange();
+
+  if (D->isUnion()) {
+auto DiagSPM = [&](CXXSpecialMemberKind K, bool Has) {
+  if (Has)
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::UnionWithUserDeclaredSMF << K;
+};
+DiagSPM(CXXSpecialMemberKind::CopyConstructor,
+D->hasUserDeclaredCopyConstructor());
+DiagSPM(CXXSpecialMemberKind::CopyAssignment,
+D->hasUserDeclaredCopyAssignment());
+DiagSPM(CXXSpecialMemberKind::MoveConstructor,
+D->hasUserDeclaredMoveConstructor());
+DiagSPM(CXXSpecialMemberKind::MoveAssignment,
+D->hasUserDeclaredMoveAssignment());
+return;
+  }
+
+  if (!D->hasSimpleMoveConstructor() && !D->hasSimpleCopyConstructor()) {
+const auto *Decl = cast(
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false));
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedCtr
+  << Decl->isMoveConstructor() << Decl->getSourceRange();
+  }
+  if (!D->hasSimpleMoveAssignment() && !D->hasSimpleCopyAssignment()) {
+CXXMethodDecl *Decl =
+LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/true);
+if (Decl && Decl->isUserProvided())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::UserProvidedAssign
+  << Decl->isMoveAssignmentOperator() << Decl->getSourceRange();
+  }
+  CXXDestructorDecl *Dtr = D->getDestructor();
+  if (Dtr && Dtr->isUserProvided() && !Dtr->isDefaulted())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 1
+<< Dtr->getSourceRange();
+}
+
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc, QualType T) 
{
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait)
+  << T << diag::TraitName::TriviallyCopyable;
+
+  if (T->isReferenceType())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::Ref;
+
+  T = T.getNonReferenceType();
+
+  if (T.hasNonTrivialObjCLifetime())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::HasArcLifetime;

egorshamshura wrote:

Removed

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


[clang] [libclang/python] Properly report errors when test fails (PR #142371)

2025-06-02 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

This issue has been raised in 
https://github.com/llvm/llvm-project/pull/142353#pullrequestreview-2887698305

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


[clang] [Clang] Separate implicit int conversion on negation sign to new diagnostic group (PR #139429)

2025-06-02 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-m68k-linux-cross` 
running on `suse-gary-m68k-cross` while building `clang` at step 5 "ninja check 
1".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/27/builds/10928


Here is the relevant piece of the build log for the reference

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
...
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include/clang/Sema/Sema.h:839:7:
 warning: ‘clang::Sema’ declared with greater visibility than the type of its 
field ‘clang::Sema::ExtVectorDecls’ [-Wattributes]
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include/clang/Sema/Sema.h:839:7:
 warning: ‘clang::Sema’ declared with greater visibility than the type of its 
field ‘clang::Sema::DelegatingCtorDecls’ [-Wattributes]
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include/clang/Serialization/ASTReader.h:245:16:
 warning: ‘virtual bool 
clang::ASTReaderListener::visitInputFile(llvm::StringRef, llvm::StringRef, 
bool, bool, bool)’ was hidden [-Woverloaded-virtual=]
  245 |   virtual bool visitInputFile(StringRef FilenameAsRequested, StringRef 
Filename,
  |^~
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include/clang/Serialization/ASTReader.h:306:8:
 note:   by ‘virtual bool 
clang::ChainedASTReaderListener::visitInputFile(llvm::StringRef, bool, bool, 
bool)’
  306 |   bool visitInputFile(StringRef Filename, bool isSystem,
  |^~
[261/412] Building CXX object 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp.o
[262/412] Building CXX object 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/AST/ASTImporterTest.cpp.o
FAILED: 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/AST/ASTImporterTest.cpp.o
 
/usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/tools/clang/unittests
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/unittests
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/tools/clang/include
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/include
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/llvm/include
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/unittests/Tooling
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/third-party/unittest/googletest/include
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/third-party/unittest/googlemock/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings 
-Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long 
-Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull 
-Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move 
-Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-fno-strict-aliasing -O3 -DNDEBUG -std=c++17  -Wno-variadic-macros 
-fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -Wno-suggest-override -MD 
-MT 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/AST/ASTImporterTest.cpp.o
 -MF 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/AST/ASTImporterTest.cpp.o.d
 -o 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/AST/ASTImporterTest.cpp.o
 -c 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/unittests/AST/ASTImporterTest.cpp
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
[263/412] Building CXX object 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/Tooling/RefactoringActionRulesTest.cpp.o
[264/412] Building CXX object 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/Tooling/ReplacementsYamlTest.cpp.o
[265/412] Building CXX object 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/Tooling/Syntax/MutationsTest.cpp.o
[266/412] Building CXX object 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/Tooling/RecursiveASTVisitorTests/Attr.cpp.o
[267/412] Building CXX object 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/Tooling/RecursiveASTVisitorTests/InitListExprPostOrderNoQueue.cpp.o
[268/412] Building CXX object 
tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/Tooling/RecursiveASTVisi

[clang] [libclang/python] Properly report errors when test fails (PR #142371)

2025-06-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

test_cdb.py's test_create_fail captures stderr to suppress output but did not 
release it in case the test fails.

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


1 Files Affected:

- (modified) clang/bindings/python/tests/cindex/test_cdb.py (+10-7) 


``diff
diff --git a/clang/bindings/python/tests/cindex/test_cdb.py 
b/clang/bindings/python/tests/cindex/test_cdb.py
index 757a14fbaef2c..5abe56f0d65f8 100644
--- a/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/clang/bindings/python/tests/cindex/test_cdb.py
@@ -21,13 +21,16 @@ def test_create_fail(self):
 
 # clang_CompilationDatabase_fromDirectory calls fprintf(stderr, ...)
 # Suppress its output.
-stderr = os.dup(2)
-with open(os.devnull, "wb") as null:
-os.dup2(null.fileno(), 2)
-with self.assertRaises(CompilationDatabaseError) as cm:
-CompilationDatabase.fromDirectory(path)
-os.dup2(stderr, 2)
-os.close(stderr)
+try:
+stderr = os.dup(2)
+with open(os.devnull, "wb") as null:
+os.dup2(null.fileno(), 2)
+with self.assertRaises(CompilationDatabaseError) as cm:
+CompilationDatabase.fromDirectory(path)
+# Ensures that stderr is reset even if the above code crashes
+finally:
+os.dup2(stderr, 2)
+os.close(stderr)
 
 e = cm.exception
 self.assertEqual(e.cdb_error, 
CompilationDatabaseError.ERROR_CANNOTLOADDATABASE)

``




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


[clang] [Sema] Fix bug in builtin AS override (PR #138141)

2025-06-02 Thread Shilei Tian via cfe-commits

shiltian wrote:

Can you also remove all `t`? They don't seem to be necessary here.

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


[clang] [clang][python][test] Check if libclang.so is loadable (PR #142353)

2025-06-02 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

> Given the fact that OSError already contains the message that indicates the 
> problem, I think we should explore why it's not properly emitted in the first 
> place, before introducing bespoke ways of delivering error messages. 
> @DeinAlptraum any thoughts here?

This has been bothering me for a while but I didn't think too much about it. 
Took this opportunity to finally take a look and opened a fix PR #142371 .
TLDR; one of our tests captures `stderr` to keep the test output clean, but if 
the test crashes before it is released (usually when loading libclang.so raises 
as is the case here), the remaining tests in the run are effectively silenced. 
So this is an issue that only affected the tests.

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread Shamshura Egor via cfe-commits

https://github.com/egorshamshura updated 
https://github.com/llvm/llvm-project/pull/142341

>From 2e423a75e5ee8b5ecc450d4457fc677fd0c08ad2 Mon Sep 17 00:00:00 2001
From: Shamshura Egor 
Date: Mon, 2 Jun 2025 07:25:26 +
Subject: [PATCH 1/4] [Clang] Added explanation why a is trivial copyable
 evaluated to false.

---
 .../clang/Basic/DiagnosticSemaKinds.td|  5 +-
 clang/lib/Sema/SemaTypeTraits.cpp | 97 +++
 .../type-traits-unsatisfied-diags-std.cpp | 72 ++
 .../SemaCXX/type-traits-unsatisfied-diags.cpp | 80 +++
 4 files changed, 253 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index efc842bb4c42e..748e0720c5ef5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1764,7 +1764,8 @@ def err_user_defined_msg_constexpr : Error<
 
 // Type traits explanations
 def note_unsatisfied_trait : Note<"%0 is not %enum_select{"
-  "%TriviallyRelocatable{trivially 
relocatable}"
+  "%TriviallyRelocatable{trivially 
relocatable}|"
+  "%TriviallyCopyable{trivially copyable}"
   "}1">;
 
 def note_unsatisfied_trait_reason
@@ -1776,6 +1777,8 @@ def note_unsatisfied_trait_reason
"%VBase{has a virtual base %1}|"
"%NRBase{has a non-trivially-relocatable base %1}|"
"%NRField{has a non-trivially-relocatable member %1 of type %2}|"
+   "%NTCBase{has a non-trivially-copyable base %1}|"
+   "%NTCField{has a non-trivially-copyable member %1 of type %2}|"
"%DeletedDtr{has a %select{deleted|user-provided}1 destructor}|"
"%UserProvidedCtr{has a user provided %select{copy|move}1 "
"constructor}|"
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp 
b/clang/lib/Sema/SemaTypeTraits.cpp
index 7bf3c8eaabf4b..aaa5aff53fbc5 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -11,8 +11,10 @@
 
//===--===//
 
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "clang/Basic/TypeTraits.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
@@ -1922,6 +1924,7 @@ static std::optional 
StdNameToTypeTrait(StringRef Name) {
   return llvm::StringSwitch>(Name)
   .Case("is_trivially_relocatable",
 TypeTrait::UTT_IsCppTriviallyRelocatable)
+  .Case("is_trivially_copyable", TypeTrait::UTT_IsTriviallyCopyable)
   .Default(std::nullopt);
 }
 
@@ -2083,6 +2086,97 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+  << B.getSourceRange();
+}
+  }
+  for (const FieldDecl *Field : D->fields()) {
+if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCField << Field
+  << Field->getType() << Field->getSourceRange();
+  }
+  if (D->hasDeletedDestructor())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
+<< D->getDestructor()->getSourceRange();
+
+  if (D->isUnion()) {
+auto DiagSPM = [&](CXXSpecialMemberKind K, bool Has) {
+  if (Has)
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::UnionWithUserDeclaredSMF << K;
+};
+DiagSPM(CXXSpecialMemberKind::CopyConstructor,
+D->hasUserDeclaredCopyConstructor());
+DiagSPM(CXXSpecialMemberKind::CopyAssignment,
+D->hasUserDeclaredCopyAssignment());
+DiagSPM(CXXSpecialMemberKind::MoveConstructor,
+D->hasUserDeclaredMoveConstructor());
+DiagSPM(CXXSpecialMemberKind::MoveAssignment,
+D->hasUserDeclaredMoveAssignment());
+return;
+  }
+
+  if (

[libclc] libclc: clspv: do not set generic_addrspace_val (PR #141912)

2025-06-02 Thread Fraser Cormack via cfe-commits

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-02 Thread Shamshura Egor via cfe-commits

https://github.com/egorshamshura updated 
https://github.com/llvm/llvm-project/pull/142341

>From 2e423a75e5ee8b5ecc450d4457fc677fd0c08ad2 Mon Sep 17 00:00:00 2001
From: Shamshura Egor 
Date: Mon, 2 Jun 2025 07:25:26 +
Subject: [PATCH 1/3] [Clang] Added explanation why a is trivial copyable
 evaluated to false.

---
 .../clang/Basic/DiagnosticSemaKinds.td|  5 +-
 clang/lib/Sema/SemaTypeTraits.cpp | 97 +++
 .../type-traits-unsatisfied-diags-std.cpp | 72 ++
 .../SemaCXX/type-traits-unsatisfied-diags.cpp | 80 +++
 4 files changed, 253 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index efc842bb4c42e..748e0720c5ef5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1764,7 +1764,8 @@ def err_user_defined_msg_constexpr : Error<
 
 // Type traits explanations
 def note_unsatisfied_trait : Note<"%0 is not %enum_select{"
-  "%TriviallyRelocatable{trivially 
relocatable}"
+  "%TriviallyRelocatable{trivially 
relocatable}|"
+  "%TriviallyCopyable{trivially copyable}"
   "}1">;
 
 def note_unsatisfied_trait_reason
@@ -1776,6 +1777,8 @@ def note_unsatisfied_trait_reason
"%VBase{has a virtual base %1}|"
"%NRBase{has a non-trivially-relocatable base %1}|"
"%NRField{has a non-trivially-relocatable member %1 of type %2}|"
+   "%NTCBase{has a non-trivially-copyable base %1}|"
+   "%NTCField{has a non-trivially-copyable member %1 of type %2}|"
"%DeletedDtr{has a %select{deleted|user-provided}1 destructor}|"
"%UserProvidedCtr{has a user provided %select{copy|move}1 "
"constructor}|"
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp 
b/clang/lib/Sema/SemaTypeTraits.cpp
index 7bf3c8eaabf4b..aaa5aff53fbc5 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -11,8 +11,10 @@
 
//===--===//
 
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "clang/Basic/TypeTraits.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
@@ -1922,6 +1924,7 @@ static std::optional 
StdNameToTypeTrait(StringRef Name) {
   return llvm::StringSwitch>(Name)
   .Case("is_trivially_relocatable",
 TypeTrait::UTT_IsCppTriviallyRelocatable)
+  .Case("is_trivially_copyable", TypeTrait::UTT_IsTriviallyCopyable)
   .Default(std::nullopt);
 }
 
@@ -2083,6 +2086,97 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+  << B.getSourceRange();
+}
+  }
+  for (const FieldDecl *Field : D->fields()) {
+if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::NTCField << Field
+  << Field->getType() << Field->getSourceRange();
+  }
+  if (D->hasDeletedDestructor())
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
+<< D->getDestructor()->getSourceRange();
+
+  if (D->isUnion()) {
+auto DiagSPM = [&](CXXSpecialMemberKind K, bool Has) {
+  if (Has)
+SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+<< diag::TraitNotSatisfiedReason::UnionWithUserDeclaredSMF << K;
+};
+DiagSPM(CXXSpecialMemberKind::CopyConstructor,
+D->hasUserDeclaredCopyConstructor());
+DiagSPM(CXXSpecialMemberKind::CopyAssignment,
+D->hasUserDeclaredCopyAssignment());
+DiagSPM(CXXSpecialMemberKind::MoveConstructor,
+D->hasUserDeclaredMoveConstructor());
+DiagSPM(CXXSpecialMemberKind::MoveAssignment,
+D->hasUserDeclaredMoveAssignment());
+return;
+  }
+
+  if (

[clang] [libclang/python] Properly report errors when test fails (PR #142371)

2025-06-02 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum created 
https://github.com/llvm/llvm-project/pull/142371

test_cdb.py's test_create_fail captures stderr to suppress output but did not 
release it in case the test fails.

>From 4b16005e56a631c4459bca55fb396483eeea3ac6 Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Mon, 2 Jun 2025 20:58:09 +0900
Subject: [PATCH] [libclang/python] Properly report errors when test fails
 test_cdb.py's test_create_fail captures stderr to suppress output but did not
 release it in case the test fails.

---
 clang/bindings/python/tests/cindex/test_cdb.py | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/clang/bindings/python/tests/cindex/test_cdb.py 
b/clang/bindings/python/tests/cindex/test_cdb.py
index 757a14fbaef2c..5abe56f0d65f8 100644
--- a/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/clang/bindings/python/tests/cindex/test_cdb.py
@@ -21,13 +21,16 @@ def test_create_fail(self):
 
 # clang_CompilationDatabase_fromDirectory calls fprintf(stderr, ...)
 # Suppress its output.
-stderr = os.dup(2)
-with open(os.devnull, "wb") as null:
-os.dup2(null.fileno(), 2)
-with self.assertRaises(CompilationDatabaseError) as cm:
-CompilationDatabase.fromDirectory(path)
-os.dup2(stderr, 2)
-os.close(stderr)
+try:
+stderr = os.dup(2)
+with open(os.devnull, "wb") as null:
+os.dup2(null.fileno(), 2)
+with self.assertRaises(CompilationDatabaseError) as cm:
+CompilationDatabase.fromDirectory(path)
+# Ensures that stderr is reset even if the above code crashes
+finally:
+os.dup2(stderr, 2)
+os.close(stderr)
 
 e = cm.exception
 self.assertEqual(e.cdb_error, 
CompilationDatabaseError.ERROR_CANNOTLOADDATABASE)

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


[clang] [Clang] Separate implicit int conversion on negation sign to new diagnostic group (PR #139429)

2025-06-02 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-remote-linux-ubuntu` 
running on `as-builder-9` while building `clang` at step 16 
"test-check-lldb-api".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/195/builds/9873


Here is the relevant piece of the build log for the reference

```
Step 16 (test-check-lldb-api) failure: Test just built components: 
check-lldb-api completed (failure)
...
PASS: lldb-api :: types/TestCharTypeExpr.py (1270 of 1279)
PASS: lldb-api :: types/TestIntegerType.py (1271 of 1279)
PASS: lldb-api :: types/TestRecursiveTypes.py (1272 of 1279)
UNSUPPORTED: lldb-api :: windows/launch/missing-dll/TestMissingDll.py (1273 of 
1279)
PASS: lldb-api :: types/TestIntegerTypeExpr.py (1274 of 1279)
PASS: lldb-api :: types/TestShortType.py (1275 of 1279)
PASS: lldb-api :: types/TestShortTypeExpr.py (1276 of 1279)
PASS: lldb-api :: types/TestLongTypes.py (1277 of 1279)
PASS: lldb-api :: types/TestLongTypesExpr.py (1278 of 1279)
TIMEOUT: lldb-api :: python_api/process/cancel_attach/TestCancelAttach.py (1279 
of 1279)
 TEST 'lldb-api :: 
python_api/process/cancel_attach/TestCancelAttach.py' FAILED 

Script:
--
/usr/bin/python3.12 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib
 --env 
LLVM_INCLUDE_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include
 --env 
LLVM_TOOLS_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin
 --libcxx-include-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include/c++/v1
 --libcxx-include-target-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include/aarch64-unknown-linux-gnu/c++/v1
 --libcxx-library-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib/aarch64-unknown-linux-gnu
 --arch aarch64 --build-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex
 --lldb-module-cache-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin/lldb 
--compiler 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang 
--dsymutil 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin/dsymutil
 --make /usr/bin/gmake --llvm-tools-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin 
--lldb-obj-root 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb 
--lldb-libs-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib 
--cmake-build-type Release --platform-url 
connect://jetson-agx-2198.lab.llvm.org:1234 --platform-working-dir 
/home/ubuntu/lldb-tests --sysroot /mnt/fs/jetson-agx-ubuntu --env 
ARCH_CFLAGS=-mcpu=cortex-a78 --platform-name remote-linux 
--skip-category=lldb-server 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/python_api/process/cancel_attach
 -p TestCancelAttach.py
--
Exit Code: -9
Timeout: Reached timeout of 600 seconds

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
0ada5c7b1a52afb668bc42dd2d5573e5805433d1)
  clang revision 0ada5c7b1a52afb668bc42dd2d5573e5805433d1
  llvm revision 0ada5c7b1a52afb668bc42dd2d5573e5805433d1

--
Command Output (stderr):
--
WARNING:root:Custom libc++ is not supported for remote runs: ignoring --libcxx 
arguments
FAIL: LLDB 
(/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang-aarch64)
 :: test_scripted_implementation 
(TestCancelAttach.AttachCancelTestCase.test_scripted_implementation)

--


Slowest Tests:
--
600.04s: lldb-api :: python_api/process/cancel_attach/TestCancelAttach.py
180.97s: lldb-api :: commands/command/script_alias/TestCommandScriptAlias.py
70.51s: lldb-api :: commands/process/attach/TestProcessAttach.py
39.35s: lldb-api :: 
functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
35.32s: lldb-api :: functionalities/completion/TestCompletion.py
34.59s: lldb-api :: 
functionalities/single-thread-step/TestSingleThreadStepTimeout.py
23.42s: lldb-api :: 
python_api/watchpoint/watchlocation/TestTargetWatchAddress.py
22.11s: lldb-api :: commands/statistics/basic/TestStats.py
20.67s: lldb-api :: functionalities/gdb_remote_client/TestPlatformClient.py
18.08s: lldb-api :: commands/dwim-print/TestDWIMPrint.py
16.76s: lldb-api :: functionalities/thread/state/Te

[clang] [Clang] Fix crash on template-specialization (PR #142338)

2025-06-02 Thread via cfe-commits

cor3ntin wrote:

This change needs a release note.
Please add an entry to `clang/docs/ReleaseNotes.rst` in the section the most 
adapted to the change, and referencing any Github issue this change fixes. 
Thanks!

https://github.com/llvm/llvm-project/pull/142338
___
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 performance-bool-bitwise-operation check (PR #142324)

2025-06-02 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,40 @@
+.. title:: clang-tidy - performance-bool-bitwise-operation
+
+performance-bool-bitwise-operation
+==
+
+Finds potentially inefficient use of bitwise operators such as ``&``, 
+``|`` and their compound analogues on boolean values where logical 
+operators like ``&&`` and ``||`` would be more appropriate. Bitwise 
+operations on booleans can incur unnecessary performance overhead 
+due to implicit integer conversions and missed short-circuit evaluation.
+
+.. code-block:: c++
+
+  bool invalid = false;
+  invalid |= x > limit.x; // warning: use logical operator instead of bitwise 
one for bool
+  invalid |= y > limit.y; // warning: use logical operator instead of bitwise 
one for bool
+  invalid |= z > limit.z; // warning: use logical operator instead of bitwise 
one for bool
+  if (invalid) {
+// error handling
+  }
+
+These 3 warnings suggest to assign result of logical ``||`` operation instead 
of using ``|=`` operator:
+
+.. code-block:: c++
+
+  bool invalid = false;
+  invalid = invalid || x > limit.x;
+  invalid = invalid || y > limit.x;
+  invalid = invalid || z > limit.z;
+  if (invalid) {
+// error handling
+  }
+
+Options
+---
+
+.. option:: ChangePossibleSideEffects

vbvictor wrote:

Note that `StrictMode` default value should be `true`.

https://github.com/llvm/llvm-project/pull/142324
___
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 performance-bool-bitwise-operation check (PR #142324)

2025-06-02 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,200 @@
+//===--- BoolBitwiseOperationCheck.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 "BoolBitwiseOperationCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+namespace {
+bool hasExplicitParentheses(const Expr *E, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  if (!E)
+return false;
+
+  const SourceLocation Start = E->getBeginLoc();
+  const SourceLocation End = E->getEndLoc();
+
+  if (Start.isMacroID() || End.isMacroID() || !Start.isValid() ||
+  !End.isValid()) {
+return false;
+  }
+
+  const std::optional PrevTok =
+  Lexer::findPreviousToken(Start, SM, LangOpts, /*IncludeComments=*/false);
+  const std::optional NextTok =
+  Lexer::findNextToken(End, SM, LangOpts, /*IncludeComments=*/false);
+
+  return (PrevTok && PrevTok->is(tok::l_paren)) &&
+ (NextTok && NextTok->is(tok::r_paren));
+}
+
+template 
+bool isInTemplateFunction(const AstNode *AN, ASTContext &Context) {

vbvictor wrote:

ditto

https://github.com/llvm/llvm-project/pull/142324
___
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 performance-bool-bitwise-operation check (PR #142324)

2025-06-02 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,40 @@
+.. title:: clang-tidy - performance-bool-bitwise-operation
+
+performance-bool-bitwise-operation
+==
+
+Finds potentially inefficient use of bitwise operators such as ``&``, 
+``|`` and their compound analogues on boolean values where logical 
+operators like ``&&`` and ``||`` would be more appropriate. Bitwise 
+operations on booleans can incur unnecessary performance overhead 
+due to implicit integer conversions and missed short-circuit evaluation.
+
+.. code-block:: c++
+
+  bool invalid = false;
+  invalid |= x > limit.x; // warning: use logical operator instead of bitwise 
one for bool
+  invalid |= y > limit.y; // warning: use logical operator instead of bitwise 
one for bool
+  invalid |= z > limit.z; // warning: use logical operator instead of bitwise 
one for bool
+  if (invalid) {
+// error handling
+  }
+
+These 3 warnings suggest to assign result of logical ``||`` operation instead 
of using ``|=`` operator:

vbvictor wrote:

Please make lines no more than 80 characters

https://github.com/llvm/llvm-project/pull/142324
___
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 performance-bool-bitwise-operation check (PR #142324)

2025-06-02 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,38 @@
+//===--- BoolBitwiseOperationCheck.h - clang-tidy ---*- 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_BOOLBITWISEOPERATIONCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_BOOLBITWISEOPERATIONCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::performance {
+
+/// Finds potentially unefficient uses of bitwise operators such as `|`,
+/// `&` and their compound analogues with `bool` type and suggests replacing
+/// them with logical ones, like `||` and `&&`.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/performance/bool-bitwise-operation.html
+class BoolBitwiseOperationCheck : public ClangTidyCheck {
+public:
+  BoolBitwiseOperationCheck(StringRef Name, ClangTidyContext *Context);
+  void storeOptions(ClangTidyOptions::OptionMap &Options) override;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.CPlusPlus;

vbvictor wrote:

Could this check be also for pure C? (I guess so)

https://github.com/llvm/llvm-project/pull/142324
___
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 performance-bool-bitwise-operation check (PR #142324)

2025-06-02 Thread Baranov Victor via cfe-commits

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


  1   2   3   4   5   6   >