[clang-tools-extra] d211abc - [clang-tidy] Ignore non-math operators in readability-math-missing-parentheses (#94654)

2024-06-09 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-06-09T09:01:41+02:00
New Revision: d211abc625cc7bbc8616885bb8eaf4a69a9a3853

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

LOG: [clang-tidy] Ignore non-math operators in 
readability-math-missing-parentheses (#94654)

Do not emit warnings for non-math operators.

Closes #92516

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
index 65fd296094915..64ce94e3fc1db 100644
--- a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
@@ -57,7 +57,8 @@ static void addParantheses(const BinaryOperator *BinOp,
   int Precedence1 = getPrecedence(BinOp);
   int Precedence2 = getPrecedence(ParentBinOp);
 
-  if (ParentBinOp != nullptr && Precedence1 != Precedence2) {
+  if (ParentBinOp != nullptr && Precedence1 != Precedence2 && Precedence1 > 0 
&&
+  Precedence2 > 0) {
 const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
 const clang::SourceLocation EndLoc =
 clang::Lexer::getLocForEndOfToken(BinOp->getEndLoc(), 0, SM, LangOpts);

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
index a6045c079a482..4face0bb3fe68 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
@@ -140,3 +140,20 @@ void f(){
 //CHECK-MESSAGES: :[[@LINE+1]]:13: warning: '*' has higher precedence than 
'+'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
 int v = FUN5(0 + 1);
 }
+
+namespace PR92516 {
+  void f(int i) {
+int j, k;
+for (j = i + 1, k = 0; j < 1; ++j) {}
+  }
+
+  void f2(int i) {
+int j;
+for (j = i + 1; j < 1; ++j) {}
+  }
+
+  void f3(int i) {
+int j;
+for (j = i + 1, 2; j < 1; ++j) {}
+  }
+}



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


[clang-tools-extra] [clang-tidy] Ignore non-math operators in readability-math-missing-parentheses (PR #94654)

2024-06-09 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Remove redundant LINK_LIBS (PR #94588)

2024-06-09 Thread Jonas Toth via cfe-commits

JonasToth wrote:

As you requested my review:

The original linking was done for the `ExprMutAnalyzer` used in 
'misc-const-correctness'. If clang-tidy is builtin without static analyzer 
Support, you get linker failure.

If the `ExprMutAnalyzer` is moved (back) to clang-tidy, the issue is not 
existent. The original move request was from static analysis background where 
they might wanted to use the class as well.

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


[clang] [clang][Interp] Implement complex division (PR #94892)

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


https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/94892

Depends on the multiplication PR.

>From b89efd9e0e38a6e79130e0a1b9e8d0443654c6c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 9 Mar 2024 17:07:24 +0100
Subject: [PATCH 1/2] [clang][Interp] Implement Complex-complex multiplication

Share the implementation for floating-point complex-complex
multiplication with the current interpreter. This means we need a new
opcode for this, but there's no good way around that.
---
 clang/lib/AST/ExprConstShared.h  |   7 ++
 clang/lib/AST/ExprConstant.cpp   | 106 ---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp |  55 +---
 clang/lib/AST/Interp/Interp.h|  57 
 clang/lib/AST/Interp/Opcodes.td  |   4 +
 clang/test/AST/Interp/complex.cpp|  31 +++
 6 files changed, 201 insertions(+), 59 deletions(-)

diff --git a/clang/lib/AST/ExprConstShared.h b/clang/lib/AST/ExprConstShared.h
index a97eac85abc69..9decd47e41767 100644
--- a/clang/lib/AST/ExprConstShared.h
+++ b/clang/lib/AST/ExprConstShared.h
@@ -14,6 +14,9 @@
 #ifndef LLVM_CLANG_LIB_AST_EXPRCONSTSHARED_H
 #define LLVM_CLANG_LIB_AST_EXPRCONSTSHARED_H
 
+namespace llvm {
+class APFloat;
+}
 namespace clang {
 class QualType;
 class LangOptions;
@@ -56,4 +59,8 @@ enum class GCCTypeClass {
 GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
  const LangOptions &LangOpts);
 
+void HandleComplexComplexMul(llvm::APFloat A, llvm::APFloat B, llvm::APFloat C,
+ llvm::APFloat D, llvm::APFloat &ResR,
+ llvm::APFloat &ResI);
+
 #endif
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 86fb396fabe2d..7c597a238f041 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15126,6 +15126,62 @@ bool ComplexExprEvaluator::VisitCastExpr(const 
CastExpr *E) {
   llvm_unreachable("unknown cast resulting in complex value");
 }
 
+void HandleComplexComplexMul(APFloat A, APFloat B, APFloat C, APFloat D,
+ APFloat &ResR, APFloat &ResI) {
+  // This is an implementation of complex multiplication according to the
+  // constraints laid out in C11 Annex G. The implementation uses the
+  // following naming scheme:
+  //   (a + ib) * (c + id)
+
+  APFloat AC = A * C;
+  APFloat BD = B * D;
+  APFloat AD = A * D;
+  APFloat BC = B * C;
+  ResR = AC - BD;
+  ResI = AD + BC;
+  if (ResR.isNaN() && ResI.isNaN()) {
+bool Recalc = false;
+if (A.isInfinity() || B.isInfinity()) {
+  A = APFloat::copySign(APFloat(A.getSemantics(), A.isInfinity() ? 1 : 0),
+A);
+  B = APFloat::copySign(APFloat(B.getSemantics(), B.isInfinity() ? 1 : 0),
+B);
+  if (C.isNaN())
+C = APFloat::copySign(APFloat(C.getSemantics()), C);
+  if (D.isNaN())
+D = APFloat::copySign(APFloat(D.getSemantics()), D);
+  Recalc = true;
+}
+if (C.isInfinity() || D.isInfinity()) {
+  C = APFloat::copySign(APFloat(C.getSemantics(), C.isInfinity() ? 1 : 0),
+C);
+  D = APFloat::copySign(APFloat(D.getSemantics(), D.isInfinity() ? 1 : 0),
+D);
+  if (A.isNaN())
+A = APFloat::copySign(APFloat(A.getSemantics()), A);
+  if (B.isNaN())
+B = APFloat::copySign(APFloat(B.getSemantics()), B);
+  Recalc = true;
+}
+if (!Recalc && (AC.isInfinity() || BD.isInfinity() || AD.isInfinity() ||
+BC.isInfinity())) {
+  if (A.isNaN())
+A = APFloat::copySign(APFloat(A.getSemantics()), A);
+  if (B.isNaN())
+B = APFloat::copySign(APFloat(B.getSemantics()), B);
+  if (C.isNaN())
+C = APFloat::copySign(APFloat(C.getSemantics()), C);
+  if (D.isNaN())
+D = APFloat::copySign(APFloat(D.getSemantics()), D);
+  Recalc = true;
+}
+if (Recalc) {
+  ResR = APFloat::getInf(A.getSemantics()) * (A * C - B * D);
+  ResI = APFloat::getInf(A.getSemantics()) * (A * D + B * C);
+}
+  }
+}
+
 bool ComplexExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
   if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma)
 return ExprEvaluatorBaseTy::VisitBinaryOperator(E);
@@ -15225,55 +15281,7 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 !handleFloatFloatBinOp(Info, E, ResI, BO_Mul, B))
   return false;
   } else {
-// In the fully general case, we need to handle NaNs and infinities
-// robustly.
-APFloat AC = A * C;
-APFloat BD = B * D;
-APFloat AD = A * D;
-APFloat BC = B * C;
-ResR = AC - BD;
-ResI = AD + BC;
-if (ResR.isNaN() && ResI.isNaN()) {
-  bool Recalc

[clang] [clang][Interp] Implement complex division (PR #94892)

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


llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Depends on the multiplication PR.

---

Patch is 23.94 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/94892.diff


6 Files Affected:

- (modified) clang/lib/AST/ExprConstShared.h (+10) 
- (modified) clang/lib/AST/ExprConstant.cpp (+100-82) 
- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+73-10) 
- (modified) clang/lib/AST/Interp/Interp.h (+129) 
- (modified) clang/lib/AST/Interp/Opcodes.td (+8) 
- (modified) clang/test/AST/Interp/complex.cpp (+46) 


``diff
diff --git a/clang/lib/AST/ExprConstShared.h b/clang/lib/AST/ExprConstShared.h
index a97eac85abc69..2a7088e4e371a 100644
--- a/clang/lib/AST/ExprConstShared.h
+++ b/clang/lib/AST/ExprConstShared.h
@@ -14,6 +14,9 @@
 #ifndef LLVM_CLANG_LIB_AST_EXPRCONSTSHARED_H
 #define LLVM_CLANG_LIB_AST_EXPRCONSTSHARED_H
 
+namespace llvm {
+class APFloat;
+}
 namespace clang {
 class QualType;
 class LangOptions;
@@ -56,4 +59,11 @@ enum class GCCTypeClass {
 GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
  const LangOptions &LangOpts);
 
+void HandleComplexComplexMul(llvm::APFloat A, llvm::APFloat B, llvm::APFloat C,
+ llvm::APFloat D, llvm::APFloat &ResR,
+ llvm::APFloat &ResI);
+void HandleComplexComplexDiv(llvm::APFloat A, llvm::APFloat B, llvm::APFloat C,
+ llvm::APFloat D, llvm::APFloat &ResR,
+ llvm::APFloat &ResI);
+
 #endif
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 86fb396fabe2d..c4c8319b9f9f3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15126,6 +15126,104 @@ bool ComplexExprEvaluator::VisitCastExpr(const 
CastExpr *E) {
   llvm_unreachable("unknown cast resulting in complex value");
 }
 
+void HandleComplexComplexMul(APFloat A, APFloat B, APFloat C, APFloat D,
+ APFloat &ResR, APFloat &ResI) {
+  // This is an implementation of complex multiplication according to the
+  // constraints laid out in C11 Annex G. The implementation uses the
+  // following naming scheme:
+  //   (a + ib) * (c + id)
+
+  APFloat AC = A * C;
+  APFloat BD = B * D;
+  APFloat AD = A * D;
+  APFloat BC = B * C;
+  ResR = AC - BD;
+  ResI = AD + BC;
+  if (ResR.isNaN() && ResI.isNaN()) {
+bool Recalc = false;
+if (A.isInfinity() || B.isInfinity()) {
+  A = APFloat::copySign(APFloat(A.getSemantics(), A.isInfinity() ? 1 : 0),
+A);
+  B = APFloat::copySign(APFloat(B.getSemantics(), B.isInfinity() ? 1 : 0),
+B);
+  if (C.isNaN())
+C = APFloat::copySign(APFloat(C.getSemantics()), C);
+  if (D.isNaN())
+D = APFloat::copySign(APFloat(D.getSemantics()), D);
+  Recalc = true;
+}
+if (C.isInfinity() || D.isInfinity()) {
+  C = APFloat::copySign(APFloat(C.getSemantics(), C.isInfinity() ? 1 : 0),
+C);
+  D = APFloat::copySign(APFloat(D.getSemantics(), D.isInfinity() ? 1 : 0),
+D);
+  if (A.isNaN())
+A = APFloat::copySign(APFloat(A.getSemantics()), A);
+  if (B.isNaN())
+B = APFloat::copySign(APFloat(B.getSemantics()), B);
+  Recalc = true;
+}
+if (!Recalc && (AC.isInfinity() || BD.isInfinity() || AD.isInfinity() ||
+BC.isInfinity())) {
+  if (A.isNaN())
+A = APFloat::copySign(APFloat(A.getSemantics()), A);
+  if (B.isNaN())
+B = APFloat::copySign(APFloat(B.getSemantics()), B);
+  if (C.isNaN())
+C = APFloat::copySign(APFloat(C.getSemantics()), C);
+  if (D.isNaN())
+D = APFloat::copySign(APFloat(D.getSemantics()), D);
+  Recalc = true;
+}
+if (Recalc) {
+  ResR = APFloat::getInf(A.getSemantics()) * (A * C - B * D);
+  ResI = APFloat::getInf(A.getSemantics()) * (A * D + B * C);
+}
+  }
+}
+
+void HandleComplexComplexDiv(APFloat A, APFloat B, APFloat C, APFloat D,
+ APFloat &ResR, APFloat &ResI) {
+  // This is an implementation of complex division according to the
+  // constraints laid out in C11 Annex G. The implementation uses the
+  // following naming scheme:
+  //   (a + ib) / (c + id)
+
+  int DenomLogB = 0;
+  APFloat MaxCD = maxnum(abs(C), abs(D));
+  if (MaxCD.isFinite()) {
+DenomLogB = ilogb(MaxCD);
+C = scalbn(C, -DenomLogB, APFloat::rmNearestTiesToEven);
+D = scalbn(D, -DenomLogB, APFloat::rmNearestTiesToEven);
+  }
+  APFloat Denom = C * C + D * D;
+  ResR =
+  scalbn((A * C + B * D) / Denom, -DenomLogB, 
APFloat::rmNearestTiesToEven);
+  ResI =
+  scalbn((B * C - A * D) / Denom, -DenomLogB, 
APFloat::rmNearestTiesToEven);
+  if (ResR.isNaN() && ResI.isNaN()) {
+if (Denom.isPosZ

[clang] [clang] Cover CWG issues about `export template` (PR #94876)

2024-06-09 Thread via cfe-commits

cor3ntin wrote:

I would prefer we say `N/A` rather than pretend we support something that was 
never implemented (to the extend i think it might be better to have an error 
about modules rather than exported templates in older language modes)

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


[clang] [clang][Interp] Implement complex division (PR #94892)

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


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/94892

>From b89efd9e0e38a6e79130e0a1b9e8d0443654c6c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 9 Mar 2024 17:07:24 +0100
Subject: [PATCH 1/2] [clang][Interp] Implement Complex-complex multiplication

Share the implementation for floating-point complex-complex
multiplication with the current interpreter. This means we need a new
opcode for this, but there's no good way around that.
---
 clang/lib/AST/ExprConstShared.h  |   7 ++
 clang/lib/AST/ExprConstant.cpp   | 106 ---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp |  55 +---
 clang/lib/AST/Interp/Interp.h|  57 
 clang/lib/AST/Interp/Opcodes.td  |   4 +
 clang/test/AST/Interp/complex.cpp|  31 +++
 6 files changed, 201 insertions(+), 59 deletions(-)

diff --git a/clang/lib/AST/ExprConstShared.h b/clang/lib/AST/ExprConstShared.h
index a97eac85abc69..9decd47e41767 100644
--- a/clang/lib/AST/ExprConstShared.h
+++ b/clang/lib/AST/ExprConstShared.h
@@ -14,6 +14,9 @@
 #ifndef LLVM_CLANG_LIB_AST_EXPRCONSTSHARED_H
 #define LLVM_CLANG_LIB_AST_EXPRCONSTSHARED_H
 
+namespace llvm {
+class APFloat;
+}
 namespace clang {
 class QualType;
 class LangOptions;
@@ -56,4 +59,8 @@ enum class GCCTypeClass {
 GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
  const LangOptions &LangOpts);
 
+void HandleComplexComplexMul(llvm::APFloat A, llvm::APFloat B, llvm::APFloat C,
+ llvm::APFloat D, llvm::APFloat &ResR,
+ llvm::APFloat &ResI);
+
 #endif
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 86fb396fabe2d..7c597a238f041 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15126,6 +15126,62 @@ bool ComplexExprEvaluator::VisitCastExpr(const 
CastExpr *E) {
   llvm_unreachable("unknown cast resulting in complex value");
 }
 
+void HandleComplexComplexMul(APFloat A, APFloat B, APFloat C, APFloat D,
+ APFloat &ResR, APFloat &ResI) {
+  // This is an implementation of complex multiplication according to the
+  // constraints laid out in C11 Annex G. The implementation uses the
+  // following naming scheme:
+  //   (a + ib) * (c + id)
+
+  APFloat AC = A * C;
+  APFloat BD = B * D;
+  APFloat AD = A * D;
+  APFloat BC = B * C;
+  ResR = AC - BD;
+  ResI = AD + BC;
+  if (ResR.isNaN() && ResI.isNaN()) {
+bool Recalc = false;
+if (A.isInfinity() || B.isInfinity()) {
+  A = APFloat::copySign(APFloat(A.getSemantics(), A.isInfinity() ? 1 : 0),
+A);
+  B = APFloat::copySign(APFloat(B.getSemantics(), B.isInfinity() ? 1 : 0),
+B);
+  if (C.isNaN())
+C = APFloat::copySign(APFloat(C.getSemantics()), C);
+  if (D.isNaN())
+D = APFloat::copySign(APFloat(D.getSemantics()), D);
+  Recalc = true;
+}
+if (C.isInfinity() || D.isInfinity()) {
+  C = APFloat::copySign(APFloat(C.getSemantics(), C.isInfinity() ? 1 : 0),
+C);
+  D = APFloat::copySign(APFloat(D.getSemantics(), D.isInfinity() ? 1 : 0),
+D);
+  if (A.isNaN())
+A = APFloat::copySign(APFloat(A.getSemantics()), A);
+  if (B.isNaN())
+B = APFloat::copySign(APFloat(B.getSemantics()), B);
+  Recalc = true;
+}
+if (!Recalc && (AC.isInfinity() || BD.isInfinity() || AD.isInfinity() ||
+BC.isInfinity())) {
+  if (A.isNaN())
+A = APFloat::copySign(APFloat(A.getSemantics()), A);
+  if (B.isNaN())
+B = APFloat::copySign(APFloat(B.getSemantics()), B);
+  if (C.isNaN())
+C = APFloat::copySign(APFloat(C.getSemantics()), C);
+  if (D.isNaN())
+D = APFloat::copySign(APFloat(D.getSemantics()), D);
+  Recalc = true;
+}
+if (Recalc) {
+  ResR = APFloat::getInf(A.getSemantics()) * (A * C - B * D);
+  ResI = APFloat::getInf(A.getSemantics()) * (A * D + B * C);
+}
+  }
+}
+
 bool ComplexExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
   if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma)
 return ExprEvaluatorBaseTy::VisitBinaryOperator(E);
@@ -15225,55 +15281,7 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 !handleFloatFloatBinOp(Info, E, ResI, BO_Mul, B))
   return false;
   } else {
-// In the fully general case, we need to handle NaNs and infinities
-// robustly.
-APFloat AC = A * C;
-APFloat BD = B * D;
-APFloat AD = A * D;
-APFloat BC = B * C;
-ResR = AC - BD;
-ResI = AD + BC;
-if (ResR.isNaN() && ResI.isNaN()) {
-  bool Recalc = false;
-  if (A.isInfini

[clang] [clang] Cover CWG issues about `export template` (PR #94876)

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

Endilll wrote:

Using `N/A` for 204, 323, and 335 would be novel, because at the moment it's 
used for wording changes that do not affect implementations. Those Core issues 
clearly affected the implementations back when they were resolved.

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


[clang-tools-extra] e329bfc - [clang-tidy] Ignore implicit functions in readability-implicit-bool-conversion (#94512)

2024-06-09 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-06-09T11:52:46+02:00
New Revision: e329bfcb033910fc340b6da5a6307003ac6b2b01

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

LOG: [clang-tidy] Ignore implicit functions in 
readability-implicit-bool-conversion (#94512)

Ignore implicit declarations and defaulted functions. Helps with issues
in generated code like, C++
spaceship operator.

Closes #93409

Added: 

clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-cxx20.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 28f5eada6d825..aa115cd450c4f 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -279,6 +279,9 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
   hasParent(callExpr()),
   hasSourceExpression(binaryOperator(hasAnyOperatorName("==", "!=";
 
+  auto IsInCompilerGeneratedFunction = hasAncestor(namedDecl(anyOf(
+  isImplicit(), functionDecl(isDefaulted()), functionTemplateDecl(;
+
   Finder->addMatcher(
   traverse(TK_AsIs,
implicitCastExpr(
@@ -299,7 +302,7 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
// additional parens in replacement.
optionally(hasParent(stmt().bind("parentStmt"))),
unless(isInTemplateInstantiation()),
-   unless(hasAncestor(functionTemplateDecl(
+   unless(IsInCompilerGeneratedFunction))
.bind("implicitCastToBool")),
   this);
 
@@ -331,7 +334,7 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
   anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")),
 anything()),
   unless(isInTemplateInstantiation()),
-  unless(hasAncestor(functionTemplateDecl(),
+  unless(IsInCompilerGeneratedFunction))),
   this);
 }
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 277a6e75da2ac..0b03e37fc2b2c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -408,7 +408,8 @@ Changes in existing checks
   valid fix suggestions for ``static_cast`` without a preceding space and
   fixed problem with duplicate parentheses in double implicit casts. Corrected
   the fix suggestions for C23 and later by using C-style casts instead of
-  ``static_cast``.
+  ``static_cast``. Fixed false positives in C++20 spaceship operator by 
ignoring
+  casts in implicit and defaulted functions.
 
 - Improved :doc:`readability-redundant-inline-specifier
   ` check to properly

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-cxx20.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-cxx20.cpp
new file mode 100644
index 0..13aa5c5774b47
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-cxx20.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-implicit-bool-conversion %t
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+namespace PR93409 {
+  struct X
+  {
+  auto operator<=>(const X&) const = default;
+  bool m_b;
+  };
+
+  struct Y
+  {
+  auto operator<=>(const Y&) const = default;
+  X m_x;
+  };
+  
+  bool compare(const Y& y1, const Y& y2)
+  {
+ return y1 == y2 || y1 < y2 || y1 > y2;
+  }
+}



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


[clang-tools-extra] [clang-tidy] Ignore implicit functions in readability-implicit-bool-conversion (PR #94512)

2024-06-09 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] 31b84d4 - [clang-tidy] Extend modernize-use-designated-initializers with new options (#94651)

2024-06-09 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-06-09T11:53:59+02:00
New Revision: 31b84d459cea6bde7f8cb232e70ffb0cf8e5d1ed

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

LOG: [clang-tidy] Extend modernize-use-designated-initializers with new options 
(#94651)

Add StrictCStandardCompliance and StrictCppStandardCompliance options
that default to true.

Closes #83732

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h

clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst

clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index ebc5338d0a7bf..2a0cc403b726e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -32,6 +32,14 @@ static constexpr bool RestrictToPODTypesDefault = false;
 static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
 static constexpr bool IgnoreMacrosDefault = true;
 
+static constexpr char StrictCStandardComplianceName[] =
+"StrictCStandardCompliance";
+static constexpr bool StrictCStandardComplianceDefault = true;
+
+static constexpr char StrictCppStandardComplianceName[] =
+"StrictCppStandardCompliance";
+static constexpr bool StrictCppStandardComplianceDefault = true;
+
 namespace {
 
 struct Designators {
@@ -97,7 +105,12 @@ 
UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
   RestrictToPODTypes(
   Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
   IgnoreMacros(
-  Options.getLocalOrGlobal(IgnoreMacrosName, IgnoreMacrosDefault)) {}
+  Options.getLocalOrGlobal(IgnoreMacrosName, IgnoreMacrosDefault)),
+  StrictCStandardCompliance(Options.get(StrictCStandardComplianceName,
+StrictCStandardComplianceDefault)),
+  StrictCppStandardCompliance(
+  Options.get(StrictCppStandardComplianceName,
+  StrictCppStandardComplianceDefault)) {}
 
 void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasBaseWithFields =
@@ -179,6 +192,9 @@ void UseDesignatedInitializersCheck::storeOptions(
 IgnoreSingleElementAggregates);
   Options.store(Opts, RestrictToPODTypesName, RestrictToPODTypes);
   Options.store(Opts, IgnoreMacrosName, IgnoreMacros);
+  Options.store(Opts, StrictCStandardComplianceName, 
StrictCStandardCompliance);
+  Options.store(Opts, StrictCppStandardComplianceName,
+StrictCppStandardCompliance);
 }
 
 } // namespace clang::tidy::modernize

diff  --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
index 0a496f51b9576..79095ade50371 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
@@ -29,10 +29,19 @@ class UseDesignatedInitializersCheck : public 
ClangTidyCheck {
 return TK_IgnoreUnlessSpelledInSource;
   }
 
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.CPlusPlus20 || LangOpts.C99 ||
+   (LangOpts.CPlusPlus && !StrictCppStandardCompliance) ||
+   (!LangOpts.CPlusPlus && !LangOpts.ObjC &&
+!StrictCStandardCompliance);
+  }
+
 private:
   bool IgnoreSingleElementAggregates;
   bool RestrictToPODTypes;
   bool IgnoreMacros;
+  bool StrictCStandardCompliance;
+  bool StrictCppStandardCompliance;
 };
 
 } // namespace clang::tidy::modernize

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
index 22f50980baade..f101cfc6f3a2b 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
@@ -37,7 +37,7 @@ declaration of ``S``.
 
 Even when compiling in a language version older than C++20, depending on your
 compiler, designated initializers are potentially supported. Therefore, the
-check is not restricted to C++20 and newer versions. Check out the options
+check is by default restricted to C99/C++20 and above. Check out the options
 ``-Wc99-designator`` to get support for mixed designators in initializer list 
in
 C and `

[clang-tools-extra] [clang-tidy] Extend modernize-use-designated-initializers with new options (PR #94651)

2024-06-09 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] b55fb56 - [clang-tidy] Improve bugprone-multi-level-implicit-pointer-conversion (#94524)

2024-06-09 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-06-09T11:55:08+02:00
New Revision: b55fb567e49214b47b3f2e1c9b8f39a64d620ded

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

LOG: [clang-tidy] Improve bugprone-multi-level-implicit-pointer-conversion 
(#94524)

Ignore implicit pointer conversions that are part of a cast expression

Closes #93959

Added: 


Modified: 

clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone/multi-level-implicit-pointer-conversion.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
 
b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
index 4dd3cb57e6dd1..7a989b07119aa 100644
--- 
a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
@@ -48,12 +48,21 @@ AST_MATCHER(ImplicitCastExpr, 
isMultiLevelPointerConversion) {
   return SourcePtrLevel != TargetPtrLevel;
 }
 
+AST_MATCHER(QualType, isPointerType) {
+  const QualType Type =
+  Node.getCanonicalType().getNonReferenceType().getUnqualifiedType();
+
+  return !Type.isNull() && Type->isPointerType();
+}
+
 } // namespace
 
 void MultiLevelImplicitPointerConversionCheck::registerMatchers(
 MatchFinder *Finder) {
   Finder->addMatcher(
-  implicitCastExpr(hasCastKind(CK_BitCast), 
isMultiLevelPointerConversion())
+  implicitCastExpr(hasCastKind(CK_BitCast), 
isMultiLevelPointerConversion(),
+   unless(hasParent(explicitCastExpr(
+   hasDestinationType(isPointerType())
   .bind("expr"),
   this);
 }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 0b03e37fc2b2c..50edc10654dab 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -224,6 +224,10 @@ Changes in existing checks
   check by ignoring ``__func__`` macro in lambda captures, initializers of
   default parameters and nested function declarations.
 
+- Improved :doc:`bugprone-multi-level-implicit-pointer-conversion
+  ` check
+  by ignoring implicit pointer conversions that are part of a cast expression.
+
 - Improved :doc:`bugprone-non-zero-enum-to-bool-conversion
   ` check by
   eliminating false positives resulting from direct usage of bitwise operators

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/multi-level-implicit-pointer-conversion.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/multi-level-implicit-pointer-conversion.cpp
index 7a56242e4202d..6868f9e590908 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/multi-level-implicit-pointer-conversion.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/multi-level-implicit-pointer-conversion.cpp
@@ -63,3 +63,15 @@ void test()
 
   takeSecondLevelVoidPtr(getSecondLevelVoidPtr());
 }
+
+namespace PR93959 {
+  void free(void*);
+
+  void test() {
+char **p = nullptr;
+free(p);
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: multilevel pointer conversion 
from 'char **' to 'void *', please use explicit cast 
[bugprone-multi-level-implicit-pointer-conversion]
+free((void *)p);
+free(static_cast(p));
+  }
+}



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


[clang-tools-extra] [clang-tidy] Improve bugprone-multi-level-implicit-pointer-conversion (PR #94524)

2024-06-09 Thread Piotr Zegar via cfe-commits

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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-09 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From 9f906d7ec477810ad7ceea10b3f9bf1a920d6057 Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-09 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From 5bd2c89bac2d0ec4e0ab091e818ec071c8a876cb Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-09 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From a8b428e7c559d7056c2cf239c5fbe81c8df72281 Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

___
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 bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,68 @@
+//===--- ExceptionRethrowCheck.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 "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+
+  auto RefToExceptionVariable = 
declRefExpr(to(varDecl(isExceptionVariable(;
+  auto StdMoveCall =
+  callExpr(argumentCountIs(1), 
callee(functionDecl(hasName("::std::move"))),
+   hasArgument(0, RefToExceptionVariable));
+  auto CopyOrMoveConstruction = cxxConstructExpr(
+  argumentCountIs(1),

PiotrZSL wrote:

It's not redundant, it's cheaper to exclude first all calls that have more than 
1 argument, and then compare strings.

https://github.com/llvm/llvm-project/pull/86448
___
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 bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,68 @@
+//===--- ExceptionRethrowCheck.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 "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+
+  auto RefToExceptionVariable = 
declRefExpr(to(varDecl(isExceptionVariable(;
+  auto StdMoveCall =
+  callExpr(argumentCountIs(1), 
callee(functionDecl(hasName("::std::move"))),

PiotrZSL wrote:

That's not necessary. As other checks doesn't do that.

https://github.com/llvm/llvm-project/pull/86448
___
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 bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/86448
___
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 bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/86448

>From 8ed57a657d9b87bfaaa5c4394fc3fcaf670ba94c Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sun, 24 Mar 2024 18:39:54 +
Subject: [PATCH 1/7] [clang-tidy] Added bugprone-exception-rethrow check

Identifies problematic exception rethrowing, especially with caught
exception variables or empty throw statements outside catch blocks.

Closes #71292
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/ExceptionRethrowCheck.cpp| 50 ++
 .../bugprone/ExceptionRethrowCheck.h  | 37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../checks/bugprone/exception-rethrow.rst | 68 +++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/bugprone/exception-rethrow.cpp   | 60 
 8 files changed, 226 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-rethrow.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-rethrow.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 1b92d2e60cc17..7466d3f2e4fc2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -26,6 +26,7 @@
 #include "EasilySwappableParametersCheck.h"
 #include "EmptyCatchCheck.h"
 #include "ExceptionEscapeCheck.h"
+#include "ExceptionRethrowCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
 #include "ForwardingReferenceOverloadCheck.h"
@@ -127,6 +128,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck("bugprone-empty-catch");
 CheckFactories.registerCheck(
 "bugprone-exception-escape");
+CheckFactories.registerCheck(
+"bugprone-exception-rethrow");
 CheckFactories.registerCheck("bugprone-fold-init-type");
 CheckFactories.registerCheck(
 "bugprone-forward-declaration-namespace");
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 2d303191f8865..345ae420398e6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyBugproneModule
   EasilySwappableParametersCheck.cpp
   EmptyCatchCheck.cpp
   ExceptionEscapeCheck.cpp
+  ExceptionRethrowCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   ForwardingReferenceOverloadCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp
new file mode 100644
index 0..4855ccc2724a9
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp
@@ -0,0 +1,50 @@
+//===--- ExceptionRethrowCheck.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 "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(VarDecl, isExceptionVariable) { return Node.isExceptionVariable(); 
}
+} // namespace
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxThrowExpr(unless(isExpansionInSystemHeader()),
+   anyOf(unless(has(expr())),
+ has(declRefExpr(to(varDecl(isExceptionVariable()),
+   optionally(hasAncestor(cxxCatchStmt().bind("catch"
+  .bind("throw"),
+  this);
+}
+
+void ExceptionRethrowCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedThrow = Result.Nodes.getNodeAs("throw");
+
+  if (const Expr *ThrownObject = MatchedThrow->getSubExpr()) {
+diag(MatchedThrow->getThrowLoc(),
+ "throwing a copy of the caught %0 exception, remove the argument to "
+ "throw the original exception object")
+<< ThrownObject->getType().getNonReferenceType();
+return;
+  }
+
+  const bool HasCatchAnsestor =
+  Result.Nodes.getNodeAs("catch") != nullptr;
+  if (!HasCatchAnsestor) {
+diag(MatchedThrow->getThrowLoc(),
+ "empty 'throw' outside a catch block without an exception can trigger 
"
+ "'std::terminate'");
+  }
+

[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,68 @@
+//===--- ExceptionRethrowCheck.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 "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+
+  auto RefToExceptionVariable = 
declRefExpr(to(varDecl(isExceptionVariable(;
+  auto StdMoveCall =
+  callExpr(argumentCountIs(1), 
callee(functionDecl(hasName("::std::move"))),
+   hasArgument(0, RefToExceptionVariable));
+  auto CopyOrMoveConstruction = cxxConstructExpr(
+  argumentCountIs(1),
+  traverse(TK_AsIs, hasDeclaration(cxxConstructorDecl(
+anyOf(isCopyConstructor(), isMoveConstructor(),
+  hasArgument(0, anyOf(RefToExceptionVariable, StdMoveCall)));
+
+  auto HasEmptyThrowExprDescendant =
+  hasDescendant(cxxThrowExpr(equalsBoundNode("empty-throw")));
+
+  Finder->addMatcher(
+  cxxThrowExpr(
+  unless(isExpansionInSystemHeader()), unless(has(expr())),
+  expr().bind("empty-throw"),
+  anyOf(unless(hasAncestor(cxxCatchStmt())),
+hasAncestor(cxxCatchStmt(anyOf(
+hasDescendant(functionDecl(HasEmptyThrowExprDescendant)),
+
hasDescendant(lambdaExpr(HasEmptyThrowExprDescendant))),
+  this);
+  Finder->addMatcher(
+  cxxThrowExpr(unless(isExpansionInSystemHeader()),
+   has(expr(anyOf(RefToExceptionVariable, StdMoveCall,
+  CopyOrMoveConstruction
+  .bind("throw"),
+  this);
+}
+
+void ExceptionRethrowCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *MatchedThrow =
+  Result.Nodes.getNodeAs("throw")) {
+const Expr *ThrownObject = MatchedThrow->getSubExpr();
+diag(MatchedThrow->getThrowLoc(),
+ "throwing a copy of the caught %0 exception, remove the argument to "
+ "throw the original exception object")
+<< ThrownObject->getType().getNonReferenceType();
+return;
+  }
+
+  if (const auto *MatchedEmptyThrow =
+  Result.Nodes.getNodeAs("empty-throw")) {
+diag(MatchedEmptyThrow->getThrowLoc(),
+ "empty 'throw' outside a catch block with no operand triggers "

PiotrZSL wrote:

Done

https://github.com/llvm/llvm-project/pull/86448
___
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 bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,83 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad, 'e' is copied
+  }
+
+.. code-block:: c++
+
+  class derived_exception : public std::exception { ... };
+
+  void throwDerived() { throw derived_exception{}; }
+
+  try {
+throwDerived();
+  } catch (const std::exception& e) {
+throw e; // Bad, exception slicing occurs when 'derived_exception' is
+ // being rethrown as 'std::exception'
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to

PiotrZSL wrote:

Done

https://github.com/llvm/llvm-project/pull/86448
___
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 bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,83 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad, 'e' is copied
+  }
+
+.. code-block:: c++
+
+  class derived_exception : public std::exception { ... };
+
+  void throwDerived() { throw derived_exception{}; }
+
+  try {
+throwDerived();
+  } catch (const std::exception& e) {
+throw e; // Bad, exception slicing occurs when 'derived_exception' is
+ // being rethrown as 'std::exception'
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to
+rethrow the original exception object for currently handled exceptions.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception&) {
+throw; // Good
+  }
+
+However, when an empty throw statement is used outside a catch block, it

PiotrZSL wrote:

Done

https://github.com/llvm/llvm-project/pull/86448
___
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 bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,83 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad, 'e' is copied
+  }
+
+.. code-block:: c++
+
+  class derived_exception : public std::exception { ... };
+
+  void throwDerived() { throw derived_exception{}; }
+
+  try {
+throwDerived();
+  } catch (const std::exception& e) {
+throw e; // Bad, exception slicing occurs when 'derived_exception' is
+ // being rethrown as 'std::exception'
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to
+rethrow the original exception object for currently handled exceptions.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception&) {
+throw; // Good
+  }
+
+However, when an empty throw statement is used outside a catch block, it
+results in a call to ``std::terminate()``, which abruptly terminates the
+application. This behavior can lead to the abnormal termination of the
+program and is often unintended. Such occurrences may indicate errors or
+oversights in the exception handling logic, and it is essential to avoid empty
+throw statements outside catch blocks to prevent unintended program 
termination.
+
+.. code-block:: c++
+
+  void foo() {
+// std::terminate will be called because there is no exception to rethrow
+throw;
+  }
+
+  int main() {
+try {
+  foo();
+} catch(...) {
+  return 1;
+}
+return 0;
+  }
+
+The above program will be terminated with:
+
+.. code-block:: text
+
+  terminate called without an active exception
+  Aborted (core dumped)
+
+Check does not perform a call-flow analysis and may produce false positives in

PiotrZSL wrote:

Done

https://github.com/llvm/llvm-project/pull/86448
___
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 bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,83 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad, 'e' is copied
+  }
+
+.. code-block:: c++
+
+  class derived_exception : public std::exception { ... };
+
+  void throwDerived() { throw derived_exception{}; }
+
+  try {
+throwDerived();
+  } catch (const std::exception& e) {
+throw e; // Bad, exception slicing occurs when 'derived_exception' is
+ // being rethrown as 'std::exception'
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to
+rethrow the original exception object for currently handled exceptions.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception&) {
+throw; // Good
+  }
+
+However, when an empty throw statement is used outside a catch block, it
+results in a call to ``std::terminate()``, which abruptly terminates the
+application. This behavior can lead to the abnormal termination of the
+program and is often unintended. Such occurrences may indicate errors or
+oversights in the exception handling logic, and it is essential to avoid empty
+throw statements outside catch blocks to prevent unintended program 
termination.
+
+.. code-block:: c++
+
+  void foo() {
+// std::terminate will be called because there is no exception to rethrow
+throw;
+  }
+
+  int main() {
+try {
+  foo();
+} catch(...) {
+  return 1;
+}
+return 0;
+  }
+
+The above program will be terminated with:
+
+.. code-block:: text
+
+  terminate called without an active exception
+  Aborted (core dumped)
+
+Check does not perform a call-flow analysis and may produce false positives in
+lambdas or functions that are actually called from a catch block. In such 
cases,
+it is recommended to suppress the warning using the ``NOLINT`` comment.

PiotrZSL wrote:

There is entire documentation about nolints in "Suppressing Undesired 
Diagnostics" section in main documentation. It's not being duplicated in 
pre-check doc.

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


[clang] [Sema][CTAD] Allow user defined conversion for copy-list-initialization (PR #94752)

2024-06-09 Thread Gábor Spaits via cfe-commits

spaits wrote:

@zyn0217 Thank you for checking my PR. I was able to simplify the 
`std::initializer_list` definition. I have also created two different 
"categories" for the test. One test contains almost the exact code as the one 
in the reported issue with the same class names. The other one is there to test 
whether we can handle conversions correctly on multiple levels of nesting (one 
level deep and top level, I have added this since in the code in the issue 
everything interesting happens on the first level).

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


[clang] [Sema][CTAD] Allow user defined conversion for copy-list-initialization (PR #94752)

2024-06-09 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/94752

From 8e1f3aa676b891c9566344ad2be046898df34a3a Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Fri, 7 Jun 2024 14:38:08 +0200
Subject: [PATCH 1/2] [CTAD] Allow user defined conversion

---
 clang/include/clang/Sema/Initialization.h |  2 +-
 clang/lib/Sema/SemaInit.cpp   |  6 +-
 .../SemaCXX/ctad-copy-init-list-narrowing.cpp | 90 +++
 3 files changed, 93 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/SemaCXX/ctad-copy-init-list-narrowing.cpp

diff --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index f443e327eaf32..4b876db436b48 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -603,7 +603,7 @@ class InitializationKind {
 /// Normal context
 IC_Normal,
 
-/// Normal context, but allows explicit conversion functionss
+/// Normal context, but allows explicit conversion functions
 IC_ExplicitConvs,
 
 /// Implicit context (value initialization)
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ed8b226a6b39f..211b6887befa3 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10892,8 +10892,6 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
 // FIXME: The "second phase of [over.match.list] case can also
 // theoretically happen here, but it's not clear whether we can
 // ever have a parameter of the right type.
-bool SuppressUserConversions = Kind.isCopyInit();
-
 if (TD) {
   SmallVector TmpInits;
   for (Expr *E : Inits)
@@ -10903,12 +10901,12 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
   TmpInits.push_back(E);
   AddTemplateOverloadCandidate(
   TD, FoundDecl, /*ExplicitArgs=*/nullptr, TmpInits, Candidates,
-  SuppressUserConversions,
+  /*SuppressUserConversions=*/false,
   /*PartialOverloading=*/false, AllowExplicit, ADLCallKind::NotADL,
   /*PO=*/{}, AllowAggregateDeductionCandidate);
 } else {
   AddOverloadCandidate(GD, FoundDecl, Inits, Candidates,
-   SuppressUserConversions,
+   /*SuppressUserConversions=*/false,
/*PartialOverloading=*/false, AllowExplicit);
 }
   };
diff --git a/clang/test/SemaCXX/ctad-copy-init-list-narrowing.cpp 
b/clang/test/SemaCXX/ctad-copy-init-list-narrowing.cpp
new file mode 100644
index 0..21b1137158d5a
--- /dev/null
+++ b/clang/test/SemaCXX/ctad-copy-init-list-narrowing.cpp
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -std=c++20 %s
+namespace std
+{
+  typedef long unsigned int size_t;
+}
+
+namespace std
+{
+  template
+class initializer_list
+{
+public:
+  typedef _E value_type;
+  typedef const _E& reference;
+  typedef const _E& const_reference;
+  typedef size_t size_type;
+  typedef const _E* iterator;
+  typedef const _E* const_iterator;
+
+private:
+  iterator _M_array;
+  size_type _M_len;
+
+
+  constexpr initializer_list(const_iterator __a, size_type __l)
+  : _M_array(__a), _M_len(__l) { }
+
+public:
+  constexpr initializer_list() noexcept
+  : _M_array(0), _M_len(0) { }
+
+
+  constexpr size_type
+  size() const noexcept { return _M_len; }
+
+
+  constexpr const_iterator
+  begin() const noexcept { return _M_array; }
+
+
+  constexpr const_iterator
+  end() const noexcept { return begin() + size(); }
+};
+
+  template
+constexpr const _Tp*
+begin(initializer_list<_Tp> __ils) noexcept
+{ return __ils.begin(); }
+
+  template
+constexpr const _Tp*
+end(initializer_list<_Tp> __ils) noexcept
+{ return __ils.end(); }
+}
+
+template
+class pair{
+private:
+T fst;
+Y snd;
+public:
+pair(T f, Y s) : fst(f), snd(s) {}
+};
+
+template
+class map {
+public:
+map(std::initializer_list>, int a = 4, int b = 5) {}
+};
+
+template
+class Contained {
+  public:
+  Contained(T, Y) {}
+};
+
+template
+class A {
+  public:
+  A(std::initializer_list >, int) {}
+};
+
+int main() {
+map mOk ={pair{5, 'a'}, {6, 'b'}, {7, 'c'}};
+map mNarrow ={pair{5, 'a'}, {6.0f, 'b'}, {7, 'c'}}; // expected-error 
{{type 'float' cannot be narrowed to 'int' in initializer list}} // 
expected-note {{insert an explicit cast to silence this issue}}
+
+A aOk = {{Contained{5, 'c'}, {5, 'c'}}, 5};
+A aNarrowNested = {{Contained{5, 'c'}, {5.0f, 'c'}}, 5}; // expected-error 
{{type 'float' cannot be narrowed to 'int' in initializer list}} // 
expected-note {{insert an explicit cast to silence this issue}}
+A aNarrow = {{Contained{5, 'c'}, {5, 'c'}}, 5.0f}; // expected-error 
{{type 'float' cannot be narrowed to 'int' in initializer list}} // 
expected-note {{insert an explicit cast to sil

[clang] cb8e936 - [clang][Interp] Implement ~ operator for complex values

2024-06-09 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-09T14:29:12+02:00
New Revision: cb8e9360d821f4fb03d571940a7e09d750d2cf2f

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

LOG: [clang][Interp] Implement ~ operator for complex values

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/complex.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index ff2b51e3fb6fa..5eecc6921a062 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3827,6 +3827,18 @@ bool ByteCodeExprGen::VisitComplexUnaryOperator(
 // we sometimes have to do the lvalue-to-rvalue conversion here manually.
 return this->emitArrayElemPop(classifyPrim(E->getType()), 1, E);
 
+  case UO_Not: // ~x
+if (!this->visit(SubExpr))
+  return false;
+// Negate the imaginary component.
+if (!this->emitArrayElem(ElemT, 1, E))
+  return false;
+if (!this->emitNeg(ElemT, E))
+  return false;
+if (!this->emitInitElem(ElemT, 1, E))
+  return false;
+return DiscardResult ? this->emitPopPtr(E) : true;
+
   default:
 return this->emitInvalid(E);
   }

diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index 09cb620d7b7c3..ea54df38a9eb8 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -115,6 +115,8 @@ static_assert(__imag(Doubles[2]) == 0.0, "");
 static_assert(__real(Doubles[3]) == 0.0, "");
 static_assert(__imag(Doubles[3]) == 0.0, "");
 
+static_assert(~(0.5 + 1.5j) == (0.5 + -1.5j), "");
+
 void func(void) {
   __complex__ int arr;
   _Complex int result;



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


[clang] [clang] Cover CWG issues about `export template` (PR #94876)

2024-06-09 Thread via cfe-commits

cor3ntin wrote:

We never implemented `export template` - and no one did, therefore we are not 
affected by changes to it (no one did except for EDG, i don't even know if they 
shipped it)

It is perfectly reasonable not to have tests whatsoever for that either 
(although I find the pre-c++20 diagnostic funny, we would be better of saying 
that modules are a c++20 feature). 

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


[clang] 69cd2d2 - [clang][Interp] Handle __extension__ for complex values

2024-06-09 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-09T14:29:12+02:00
New Revision: 69cd2d288d465b01a120d7544e99061921c66c28

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

LOG: [clang][Interp] Handle __extension__ for complex values

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/complex.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5eecc6921a062..05921e833d7cc 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3839,6 +3839,9 @@ bool ByteCodeExprGen::VisitComplexUnaryOperator(
   return false;
 return DiscardResult ? this->emitPopPtr(E) : true;
 
+  case UO_Extension:
+return this->delegate(SubExpr);
+
   default:
 return this->emitInvalid(E);
   }

diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index ea54df38a9eb8..003f33e092d25 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -117,6 +117,9 @@ static_assert(__imag(Doubles[3]) == 0.0, "");
 
 static_assert(~(0.5 + 1.5j) == (0.5 + -1.5j), "");
 
+static_assert(__extension__ __imag(A) == 0, "");
+static_assert(__imag(__extension__ A) == 0, "");
+
 void func(void) {
   __complex__ int arr;
   _Complex int result;



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


[clang] 5bb9c08 - [clang][Interp] Reject compound assign operators pre-C++14

2024-06-09 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-09T14:58:21+02:00
New Revision: 5bb9c08d8895e9d5122411c8612521e9a84220b4

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

LOG: [clang][Interp] Reject compound assign operators pre-C++14

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/SemaCXX/for-range-examples.cpp
clang/test/SemaCXX/integer-overflow.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 05921e833d7cc..ac245e7a0f24c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1834,6 +1834,9 @@ bool 
ByteCodeExprGen::VisitCompoundAssignOperator(
   std::optional RT = classify(RHS->getType());
   std::optional ResultT = classify(E->getType());
 
+  if (!Ctx.getLangOpts().CPlusPlus14)
+return this->visit(RHS) && this->visit(LHS) && this->emitError(E);
+
   if (!LT || !RT || !ResultT || !LHSComputationT)
 return false;
 

diff  --git a/clang/test/SemaCXX/for-range-examples.cpp 
b/clang/test/SemaCXX/for-range-examples.cpp
index d129d50d673e1..c06bf0102bcfe 100644
--- a/clang/test/SemaCXX/for-range-examples.cpp
+++ b/clang/test/SemaCXX/for-range-examples.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 
-fexperimental-new-constant-interpreter
 
 namespace value_range_detail {
   template

diff  --git a/clang/test/SemaCXX/integer-overflow.cpp 
b/clang/test/SemaCXX/integer-overflow.cpp
index 6049458b93bbd..d1cc8bee566f6 100644
--- a/clang/test/SemaCXX/integer-overflow.cpp
+++ b/clang/test/SemaCXX/integer-overflow.cpp
@@ -1,6 +1,10 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only -std=gnu++98 -triple 
x86_64-pc-linux-gnu
 // RUN: %clang_cc1 %s -verify -fsyntax-only -std=gnu++2a -triple 
x86_64-pc-linux-gnu
 
+// RUN: %clang_cc1 %s -verify -fsyntax-only -std=gnu++98 -triple 
x86_64-pc-linux-gnu -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 %s -verify -fsyntax-only -std=gnu++2a -triple 
x86_64-pc-linux-gnu -fexperimental-new-constant-interpreter
+
+
 typedef unsigned long long uint64_t;
 typedef unsigned int uint32_t;
 



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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-09 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From ac4330da86a97f47e7da00192295f8866cfb41e2 Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

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


[clang] [flang] [flang] Add -mlink-builtin-bitcode option to fc1 (PR #94763)

2024-06-09 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,18 @@
+
+!--
+! RUN lines
+!--
+! Embed something that can be easily checked
+! RUN: %flang_fc1 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
-mlink-builtin-bitcode %S/Inputs/bclib.bc %s 2>&1 | FileCheck %s
+
+! CHECK: define internal void @libfun_
+
+! RUN1: not %flang_fc1 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
-mlink-builtin-bitcode %S/Inputs/no-bclib.bc %s 2>&1 | FileCheck %s

banach-space wrote:

What's RUN1?

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


[clang] [flang] [flang] Add -mlink-builtin-bitcode option to fc1 (PR #94763)

2024-06-09 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,18 @@
+
+!--
+! RUN lines
+!--

banach-space wrote:

In the past, folks asked not to add such comments in tests. Let's stick with 
that.

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


[clang] [flang] [flang] Add -mlink-builtin-bitcode option to fc1 (PR #94763)

2024-06-09 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,18 @@
+
+!--
+! RUN lines
+!--
+! Embed something that can be easily checked
+! RUN: %flang_fc1 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
-mlink-builtin-bitcode %S/Inputs/bclib.bc %s 2>&1 | FileCheck %s

banach-space wrote:

1. What's bclib.bc and what makes it easy to check?

2. Does the triple matter?

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


[clang] [flang] [flang] Add -mlink-builtin-bitcode option to fc1 (PR #94763)

2024-06-09 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,18 @@
+
+!--
+! RUN lines
+!--
+! Embed something that can be easily checked
+! RUN: %flang_fc1 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
-mlink-builtin-bitcode %S/Inputs/bclib.bc %s 2>&1 | FileCheck %s
+
+! CHECK: define internal void @libfun_
+
+! RUN1: not %flang_fc1 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
-mlink-builtin-bitcode %S/Inputs/no-bclib.bc %s 2>&1 | FileCheck %s
+
+! ERROR1: error: could not open {{.*}} no-bclib.bc

banach-space wrote:

What's ERROR1?

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


[clang] [flang] [flang] Add -mlink-builtin-bitcode option to fc1 (PR #94763)

2024-06-09 Thread Andrzej Warzyński via cfe-commits


@@ -1146,6 +1150,54 @@ void CodeGenAction::embedOffloadObjects() {
   }
 }
 
+void CodeGenAction::linkBuiltinBCLibs() {

banach-space wrote:

+1

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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

2024-06-09 Thread Emilia Kond via cfe-commits

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


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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

2024-06-09 Thread Emilia Kond via cfe-commits

rymiel wrote:

Technically also applies to attributes applied to the return type of the 
lambda, i.e.
```
int main() {
  very_long_function_name_yes_it_is_really_long(
  // also happens with constexpr specifier
  [](auto n) [[attribute]]
  -> std::enable_if_t<
  std::is_arithmetic::value &&
  !std::is_same, bool>::value> {
do_something(n * 2);
  });
}
```
...but currently at least no valid C++ attribute can go in that spot

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


[clang] fix(93512): skip alignment checks on incomplete types (PR #94542)

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

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

>From 417093b489f17b0d22701f3c3b990388997c25a0 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 6 Jun 2024 01:55:54 +0300
Subject: [PATCH] fix(93512): skip alignment checks on incomplete types

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaStmt.cpp| 2 +-
 clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++
 3 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 39a9013c75a41..819fe1811ddaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -840,6 +840,8 @@ Bug Fixes to C++ Support
 - Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 - Fixed several bugs in capturing variables within unevaluated contexts. 
(#GH63845), (#GH67260), (#GH69307),
   (#GH88081), (#GH89496), (#GH90669) and (#GH91633).
+- Fix an assertion failure caused by parsing a lambda used as a default 
argument for the value of a
+  forward-declared class. (#GH93512).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 57465d4a77ac2..56f69dd50f361 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const 
VarDecl *VD) {
 
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
-  if (!VD->hasDependentAlignment() &&
+  if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() &&
   Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType))
 Info.S = NamedReturnInfo::MoveEligible;
 
diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp 
b/clang/test/SemaCXX/lambda-as-default-parameter.cpp
new file mode 100644
index 0..1f07a7f5644b7
--- /dev/null
+++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+struct a; // expected-note {{forward declaration of 'a'}} \
+ expected-note {{forward declaration of 'a'}}
+void b(a c = [] { return c; }); // expected-error {{initialization of 
incomplete type 'a'}} \
+   expected-error {{variable has incomplete 
type 'a'}}

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


[clang-tools-extra] [llvm] [mlir] Use StringRef::starts_with (NFC) (PR #94886)

2024-06-09 Thread Mehdi Amini via cfe-commits

https://github.com/joker-eph approved this pull request.


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


[clang-tools-extra] [llvm] [mlir] Use StringRef::starts_with (NFC) (PR #94886)

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

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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-09 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From e894ff532f35647954d1ff2904c5ce4e79abc059 Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-06-09 Thread via cfe-commits

tobim wrote:

It would be great if this fix could be backported.

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


[clang] Assume a for-in loop is in bounds and cannot overflow (PR #94883)

2024-06-09 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

Why did you close this PR so soon after creating it?

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-06-09 Thread via cfe-commits

cor3ntin wrote:

> It would be great if this fix could be backported.

I think it might be too late. cc @tstellar 

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


[clang] e090bac - [clang] NFC: add new cwg2398 tests

2024-06-09 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2024-06-09T13:44:45-03:00
New Revision: e090bac638e56ff9db87e622cdf925f2b99dfc30

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

LOG: [clang] NFC: add new cwg2398 tests

Added: 


Modified: 
clang/test/SemaTemplate/cwg2398.cpp

Removed: 




diff  --git a/clang/test/SemaTemplate/cwg2398.cpp 
b/clang/test/SemaTemplate/cwg2398.cpp
index f7f69e9d4268a..7675d4287cb88 100644
--- a/clang/test/SemaTemplate/cwg2398.cpp
+++ b/clang/test/SemaTemplate/cwg2398.cpp
@@ -200,8 +200,120 @@ namespace consistency {
 template struct A, B, B>;
 // new-error@-1 {{ambiguous partial specializations}}
   } // namespace t2
+  namespace t3 {
+template struct A;
+
+template class TT1,
+ class T1, class T2, class T3, class T4>
+struct A, TT1, typename nondeduced>::type> 
{};
+// new-note@-1 {{partial specialization matches}}
+
+template class UU1,
+ class U1, class U2>
+struct A, UU1, typename nondeduced>::type>;
+// new-note@-1 {{partial specialization matches}}
+
+template struct A, B, B>;
+// new-error@-1 {{ambiguous partial specializations}}
+  } // namespace t3
+  namespace t4 {
+template struct A;
+
+template class TT1,
+ class T1, class T2, class T3, class T4>
+struct A, TT1, typename nondeduced>::type> 
{};
+// new-note@-1 {{partial specialization matches}}
+
+template class UU1,
+ class U1, class U2>
+struct A, UU1, typename nondeduced>::type>;
+// new-note@-1 {{partial specialization matches}}
+
+template struct A, B, B>;
+// new-error@-1 {{ambiguous partial specializations}}
+  } // namespace t4
+  namespace t5 {
+template struct A;
+
+template class TT1,
+ class T1, class T2, class T3, class T4>
+struct A, TT1> {};
+// new-note@-1 {{partial specialization matches}}
+
+template class UU1,
+ class U1, class U2>
+struct A, UU1>;
+// new-note@-1 {{partial specialization matches}}
+
+template struct A, B>;
+// new-error@-1 {{ambiguous partial specializations}}
+  } // namespace t5
+  namespace t6 {
+template struct A;
+
+template class TT1,
+ class T1, class T2, class T3>
+struct A, TT1> {};
+// new-note@-1 {{partial specialization matches}}
+
+template class UU1,
+ class U1, class U2>
+struct A, UU1>;
+// new-note@-1 {{partial specialization matches}}
+
+template struct A, B>;
+// new-error@-1 {{ambiguous partial specializations}}
+  } // namespace t6
 } // namespace consistency
 
+namespace classes {
+  namespace canon {
+template struct A {};
+
+template class TT> auto f(TT a) { return a; }
+// old-note@-1 2{{template template argument has 
diff erent template parameters}}
+// new-note@-2 2{{substitution failure: too few template arguments}}
+
+A v1;
+A v2;
+
+using X = decltype(f(v1));
+// expected-error@-1 {{no matching function for call}}
+
+using X = decltype(f(v2));
+// expected-error@-1 {{no matching function for call}}
+  } // namespace canon
+  namespace expr {
+template  struct A {
+  static constexpr auto val = E1;
+};
+template  class TT> void f(TT v) {
+  // old-note@-1 {{template template argument has 
diff erent template parameters}}
+  // new-note@-2 {{substitution failure: too few template arguments}}
+  static_assert(v.val == 3);
+};
+void test() {
+  f(A());
+  // expected-error@-1 {{no matching function for call}}
+}
+  } // namespace expr
+  namespace packs {
+template  struct A {
+  static constexpr auto val = sizeof...(T2s);
+};
+
+template  class TT> void f(TT v) {
+  // old-note@-1 {{template template argument has 
diff erent template parameters}}
+  // new-note@-2 {{deduced type 'A<[...], (no argument), (no argument), 
(no argument)>' of 1st parameter does not match adjusted type 'A<[...], void, 
void, void>' of argument [with TT = A]}}
+  static_assert(v.val == 3);
+};
+void test() {
+  f(A());
+  // expected-error@-1 {{no matching function for call}}
+}
+  } // namespace packs
+} // namespace classes
+
 namespace regression1 {
   template  struct map {};
   template  class foo {};



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


[clang] [clang] improve TemplateArgument and TemplateName dump methods (PR #94905)

2024-06-09 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/94905

These will work as AST Text node dumpers, as usual, instead of AST printers.

Note that for now, the TemplateName dumper is using the TemplateArgument dumper 
through an implicit conversion.
This can be fixed in a later pass.

>From fb159ba1974e9311818892950c301f590bbe6360 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 8 Jun 2024 11:07:27 -0300
Subject: [PATCH] [clang] improve TemplateArgument and TemplateName dump
 methods

These will work as AST Text node dumpers, as usual, instead of AST
printers.

Note that for now, the TemplateName dumper is using the TemplateArgument
dumper through an implicit conversion.
This can be fixed in a later pass.
---
 clang/include/clang/AST/TemplateBase.h |  2 +-
 clang/include/clang/AST/TemplateName.h |  2 +-
 clang/lib/AST/ASTDumper.cpp| 31 ++
 clang/lib/AST/TemplateBase.cpp |  9 
 clang/lib/AST/TemplateName.cpp | 11 -
 5 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/AST/TemplateBase.h 
b/clang/include/clang/AST/TemplateBase.h
index fea2c8ccfee67..0eaa4b0eedb35 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -459,7 +459,7 @@ class TemplateArgument {
  bool IncludeType) const;
 
   /// Debugging aid that dumps the template argument.
-  void dump(raw_ostream &Out) const;
+  void dump(raw_ostream &Out, const ASTContext &Context) const;
 
   /// Debugging aid that dumps the template argument to standard error.
   void dump() const;
diff --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index 489fccb2ef74d..988a55acd2252 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -340,7 +340,7 @@ class TemplateName {
  Qualified Qual = Qualified::AsWritten) const;
 
   /// Debugging aid that dumps the template name.
-  void dump(raw_ostream &OS) const;
+  void dump(raw_ostream &OS, const ASTContext &Context) const;
 
   /// Debugging aid that dumps the template name to standard
   /// error.
diff --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp
index c8973fdeda352..869527241f2c8 100644
--- a/clang/lib/AST/ASTDumper.cpp
+++ b/clang/lib/AST/ASTDumper.cpp
@@ -360,3 +360,34 @@ LLVM_DUMP_METHOD void ConceptReference::dump(raw_ostream 
&OS) const {
   ASTDumper P(OS, Ctx, Ctx.getDiagnostics().getShowColors());
   P.Visit(this);
 }
+
+//===--===//
+// TemplateName method implementations
+//===--===//
+
+// FIXME: These are using the TemplateArgument dumper.
+LLVM_DUMP_METHOD void TemplateName::dump() const {
+  ASTDumper Dumper(llvm::errs(), /*ShowColors=*/false);
+  Dumper.Visit(*this);
+}
+
+LLVM_DUMP_METHOD void TemplateName::dump(llvm::raw_ostream &OS,
+ const ASTContext &Context) const {
+  ASTDumper Dumper(OS, Context, Context.getDiagnostics().getShowColors());
+  Dumper.Visit(*this);
+}
+
+//===--===//
+// TemplateArgument method implementations
+//===--===//
+
+LLVM_DUMP_METHOD void TemplateArgument::dump() const {
+  ASTDumper Dumper(llvm::errs(), /*ShowColors=*/false);
+  Dumper.Visit(*this);
+}
+
+LLVM_DUMP_METHOD void TemplateArgument::dump(llvm::raw_ostream &OS,
+ const ASTContext &Context) const {
+  ASTDumper Dumper(OS, Context, Context.getDiagnostics().getShowColors());
+  Dumper.Visit(*this);
+}
diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 46f7b79b272ef..2e6839e948d9d 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -577,15 +577,6 @@ void TemplateArgument::print(const PrintingPolicy &Policy, 
raw_ostream &Out,
   }
 }
 
-void TemplateArgument::dump(raw_ostream &Out) const {
-  LangOptions LO; // FIXME! see also TemplateName::dump().
-  LO.CPlusPlus = true;
-  LO.Bool = true;
-  print(PrintingPolicy(LO), Out, /*IncludeType*/ true);
-}
-
-LLVM_DUMP_METHOD void TemplateArgument::dump() const { dump(llvm::errs()); }
-
 
//===--===//
 // TemplateArgumentLoc Implementation
 
//===--===//
diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
index 4fc25cb34803e..11544dbb56e31 100644
--- a/clang/lib/AST/TemplateName.cpp
+++ b/clang/lib/AST/TemplateName.cpp
@@ -360,14 +360,3 @@ const StreamingDiagnostic &clang::operator<<(const 
StreamingDiagnostic &DB,
   OS.flush();
   return DB << NameStr;
 }
-
-void TemplateName::dump(raw_ost

[clang] [clang] improve TemplateArgument and TemplateName dump methods (PR #94905)

2024-06-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

These will work as AST Text node dumpers, as usual, instead of AST printers.

Note that for now, the TemplateName dumper is using the TemplateArgument dumper 
through an implicit conversion.
This can be fixed in a later pass.

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


5 Files Affected:

- (modified) clang/include/clang/AST/TemplateBase.h (+1-1) 
- (modified) clang/include/clang/AST/TemplateName.h (+1-1) 
- (modified) clang/lib/AST/ASTDumper.cpp (+31) 
- (modified) clang/lib/AST/TemplateBase.cpp (-9) 
- (modified) clang/lib/AST/TemplateName.cpp (-11) 


``diff
diff --git a/clang/include/clang/AST/TemplateBase.h 
b/clang/include/clang/AST/TemplateBase.h
index fea2c8ccfee67..0eaa4b0eedb35 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -459,7 +459,7 @@ class TemplateArgument {
  bool IncludeType) const;
 
   /// Debugging aid that dumps the template argument.
-  void dump(raw_ostream &Out) const;
+  void dump(raw_ostream &Out, const ASTContext &Context) const;
 
   /// Debugging aid that dumps the template argument to standard error.
   void dump() const;
diff --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index 489fccb2ef74d..988a55acd2252 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -340,7 +340,7 @@ class TemplateName {
  Qualified Qual = Qualified::AsWritten) const;
 
   /// Debugging aid that dumps the template name.
-  void dump(raw_ostream &OS) const;
+  void dump(raw_ostream &OS, const ASTContext &Context) const;
 
   /// Debugging aid that dumps the template name to standard
   /// error.
diff --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp
index c8973fdeda352..869527241f2c8 100644
--- a/clang/lib/AST/ASTDumper.cpp
+++ b/clang/lib/AST/ASTDumper.cpp
@@ -360,3 +360,34 @@ LLVM_DUMP_METHOD void ConceptReference::dump(raw_ostream 
&OS) const {
   ASTDumper P(OS, Ctx, Ctx.getDiagnostics().getShowColors());
   P.Visit(this);
 }
+
+//===--===//
+// TemplateName method implementations
+//===--===//
+
+// FIXME: These are using the TemplateArgument dumper.
+LLVM_DUMP_METHOD void TemplateName::dump() const {
+  ASTDumper Dumper(llvm::errs(), /*ShowColors=*/false);
+  Dumper.Visit(*this);
+}
+
+LLVM_DUMP_METHOD void TemplateName::dump(llvm::raw_ostream &OS,
+ const ASTContext &Context) const {
+  ASTDumper Dumper(OS, Context, Context.getDiagnostics().getShowColors());
+  Dumper.Visit(*this);
+}
+
+//===--===//
+// TemplateArgument method implementations
+//===--===//
+
+LLVM_DUMP_METHOD void TemplateArgument::dump() const {
+  ASTDumper Dumper(llvm::errs(), /*ShowColors=*/false);
+  Dumper.Visit(*this);
+}
+
+LLVM_DUMP_METHOD void TemplateArgument::dump(llvm::raw_ostream &OS,
+ const ASTContext &Context) const {
+  ASTDumper Dumper(OS, Context, Context.getDiagnostics().getShowColors());
+  Dumper.Visit(*this);
+}
diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 46f7b79b272ef..2e6839e948d9d 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -577,15 +577,6 @@ void TemplateArgument::print(const PrintingPolicy &Policy, 
raw_ostream &Out,
   }
 }
 
-void TemplateArgument::dump(raw_ostream &Out) const {
-  LangOptions LO; // FIXME! see also TemplateName::dump().
-  LO.CPlusPlus = true;
-  LO.Bool = true;
-  print(PrintingPolicy(LO), Out, /*IncludeType*/ true);
-}
-
-LLVM_DUMP_METHOD void TemplateArgument::dump() const { dump(llvm::errs()); }
-
 
//===--===//
 // TemplateArgumentLoc Implementation
 
//===--===//
diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
index 4fc25cb34803e..11544dbb56e31 100644
--- a/clang/lib/AST/TemplateName.cpp
+++ b/clang/lib/AST/TemplateName.cpp
@@ -360,14 +360,3 @@ const StreamingDiagnostic &clang::operator<<(const 
StreamingDiagnostic &DB,
   OS.flush();
   return DB << NameStr;
 }
-
-void TemplateName::dump(raw_ostream &OS) const {
-  LangOptions LO;  // FIXME!
-  LO.CPlusPlus = true;
-  LO.Bool = true;
-  print(OS, PrintingPolicy(LO));
-}
-
-LLVM_DUMP_METHOD void TemplateName::dump() const {
-  dump(llvm::errs());
-}

``




https://github.com/llvm/llvm-project/pull/94905
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.

[clang] [clang] NFCI: improve TemplateArgument and TemplateName dump methods (PR #94905)

2024-06-09 Thread Matheus Izvekov via cfe-commits

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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-09 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From fa0683f976cdb04f85f28069ce35a009be0c84b1 Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-09 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From 10df14537925cbf719152e1307fe296f2037ca3b Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

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


[clang] Assume a for-in loop is in bounds and cannot overflow (PR #94883)

2024-06-09 Thread via cfe-commits

AtariDreams wrote:

> Why did you close this PR so soon after creating it?

Superseded 

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


[clang] Assume a for-in loop is in bounds and cannot overflow (PR #94883)

2024-06-09 Thread via cfe-commits

AtariDreams wrote:

> Why did you close this PR so soon after creating it?

See here: https://github.com/llvm/llvm-project/pull/94885

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


[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)

2024-06-09 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I'm not sure messing with the linkage this way will interact well with various 
C++ features.  In particular, there are various places that check the "language 
linkage", which you're not modifying: from the perspective of anything outside 
of codegen, these 
functions are just external.  So other parts of the code won't be aware of the 
correct linkage.  Off the top of my head. this affects mangling, the linkage of 
template functions, and various warnings.

I'm not sure how much we can do in terms of actually solving this, given the 
way clang is architected, but we should try to come up with some sort of plan 
going forward.

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


[clang] [clang]Add additional test coverage for `__is_trivially_relocatable(T)` (PR #91412)

2024-06-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/91412

>From 532e1c6976a1cb2abf897d0a9312813f2f1d13f1 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 8 May 2024 03:09:38 +0330
Subject: [PATCH] [clang] [test] Add additional test coverage for
 `__is_trivially_relocatable(T)`

---
 .../test/SemaCXX/is-trivially-relocatable.cpp | 332 ++
 clang/test/SemaCXX/type-traits.cpp| 102 ++
 2 files changed, 434 insertions(+)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/test/SemaCXX/is-trivially-relocatable.cpp 
b/clang/test/SemaCXX/is-trivially-relocatable.cpp
new file mode 100644
index 0..439f7a9ad49ae
--- /dev/null
+++ b/clang/test/SemaCXX/is-trivially-relocatable.cpp
@@ -0,0 +1,332 @@
+// RUN: %clang_cc1 -std=c++03 -fsyntax-only -verify %s -triple 
x86_64-windows-msvc
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s -triple 
x86_64-windows-msvc
+// RUN: %clang_cc1 -std=c++03 -fsyntax-only -verify %s -triple 
x86_64-apple-darwin10
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s -triple 
x86_64-apple-darwin10
+
+// expected-no-diagnostics
+
+#if __cplusplus < 201103L
+#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__, "")
+// cxx98-error@-1 {{variadic macros are a C99 feature}}
+#endif
+
+template 
+struct Agg {
+  T t_;
+};
+
+template 
+struct Der : T {
+};
+
+template 
+struct Mut {
+  mutable T t_;
+};
+
+template 
+struct Non {
+  Non(); // make it a non-aggregate
+  T t_;
+};
+
+struct CompletelyTrivial {
+};
+static_assert(__is_trivially_relocatable(CompletelyTrivial));
+static_assert(__is_trivially_relocatable(Agg));
+static_assert(__is_trivially_relocatable(Der));
+static_assert(__is_trivially_relocatable(Mut));
+static_assert(__is_trivially_relocatable(Non));
+
+struct NonTrivialDtor {
+  ~NonTrivialDtor();
+};
+#if defined(_WIN64) && !defined(__MINGW32__)
+static_assert(__is_trivially_relocatable(NonTrivialDtor)); // bug #69394
+static_assert(__is_trivially_relocatable(Agg));
+static_assert(__is_trivially_relocatable(Der));
+static_assert(__is_trivially_relocatable(Mut));
+static_assert(__is_trivially_relocatable(Non));
+#else
+static_assert(!__is_trivially_relocatable(NonTrivialDtor));
+static_assert(!__is_trivially_relocatable(Agg));
+static_assert(!__is_trivially_relocatable(Der));
+static_assert(!__is_trivially_relocatable(Mut));
+static_assert(!__is_trivially_relocatable(Non));
+#endif
+
+struct NonTrivialCopyCtor {
+  NonTrivialCopyCtor(const NonTrivialCopyCtor&);
+};
+static_assert(!__is_trivially_relocatable(NonTrivialCopyCtor));
+static_assert(!__is_trivially_relocatable(Agg));
+static_assert(!__is_trivially_relocatable(Der));
+static_assert(!__is_trivially_relocatable(Mut));
+static_assert(!__is_trivially_relocatable(Non));
+
+struct NonTrivialMutableCopyCtor {
+  NonTrivialMutableCopyCtor(NonTrivialMutableCopyCtor&);
+};
+static_assert(!__is_trivially_relocatable(NonTrivialMutableCopyCtor));
+static_assert(!__is_trivially_relocatable(Agg));
+static_assert(!__is_trivially_relocatable(Der));
+static_assert(!__is_trivially_relocatable(Mut));
+static_assert(!__is_trivially_relocatable(Non));
+
+#if __cplusplus >= 201103L
+struct NonTrivialMoveCtor {
+  NonTrivialMoveCtor(NonTrivialMoveCtor&&);
+};
+static_assert(!__is_trivially_relocatable(NonTrivialMoveCtor));
+static_assert(!__is_trivially_relocatable(Agg));
+static_assert(!__is_trivially_relocatable(Der));
+static_assert(!__is_trivially_relocatable(Mut));
+static_assert(!__is_trivially_relocatable(Non));
+#endif
+
+struct NonTrivialCopyAssign {
+  NonTrivialCopyAssign& operator=(const NonTrivialCopyAssign&);
+};
+static_assert(__is_trivially_relocatable(NonTrivialCopyAssign));
+static_assert(__is_trivially_relocatable(Agg));
+static_assert(__is_trivially_relocatable(Der));
+static_assert(__is_trivially_relocatable(Mut));
+static_assert(__is_trivially_relocatable(Non));
+
+struct NonTrivialMutableCopyAssign {
+  NonTrivialMutableCopyAssign& operator=(NonTrivialMutableCopyAssign&);
+};
+static_assert(__is_trivially_relocatable(NonTrivialMutableCopyAssign));
+static_assert(__is_trivially_relocatable(Agg));
+static_assert(__is_trivially_relocatable(Der));
+static_assert(__is_trivially_relocatable(Mut));
+static_assert(__is_trivially_relocatable(Non));
+
+#if __cplusplus >= 201103L
+struct NonTrivialMoveAssign {
+  NonTrivialMoveAssign& operator=(NonTrivialMoveAssign&&);
+};
+static_assert(!__is_trivially_relocatable(NonTrivialMoveAssign));
+static_assert(!__is_trivially_relocatable(Agg));
+static_assert(!__is_trivially_relocatable(Der));
+static_assert(!__is_trivially_relocatable(Mut));
+static_assert(!__is_trivially_relocatable(Non));
+#endif
+
+struct ImplicitlyDeletedAssign {
+  int& r;
+};
+static_assert(__is_trivially_relocatable(ImplicitlyDeletedAssign));
+static_assert(__is_trivially_relocatable(Agg));
+static_assert(__is_trivially_relocatable(Der));
+static_assert(__is_trivially_reloca

[clang] [llvm] [RISCV] Add riscv_atomic.h and Zawrs/Zalrsc builtins (PR #94578)

2024-06-09 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

lr/sc builtins are extremely fragile: there's no reasonable way for the 
compiler to guarantee that the sc is placed in such a way that it will 
eventually succeed.  (The equivalent intrinsics do exist on ARM, but ARM has 
significantly stronger guarantees here.  Even then, it's not completely 
reliable.)

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


[clang] Fix codegen of consteval functions returning an empty class, and related issues (PR #93115)

2024-06-09 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic updated 
https://github.com/llvm/llvm-project/pull/93115

>From 816ceb271c28ff6c4dc05485000deec087674e37 Mon Sep 17 00:00:00 2001
From: Eli Friedman 
Date: Thu, 23 May 2024 18:38:04 -0700
Subject: [PATCH] Fix codegen of consteval functions returning an empty class,
 and related issues

If a class is empty, don't store it to memory: the store might overwrite
useful data.  Similarly, if a class has tail padding that might overlap
other fields, don't store the tail padding to memory.

The problem here turned out a bit more general than I initially thought:
basically all uses of EmitAggregateStore were broken. Call lowering had
a method that did mostly the right thing, though: CreateCoercedStore.
Adapt CreateCoercedStore so it always does the conservatively right
thing, and use it for both calls and ConstantExpr.

Also, along the way, fix the "overlap" bit in AggValueSlot: the bit was
set incorrectly for empty classes in some cases.

Fixes #93040.
---
 clang/lib/CodeGen/CGCall.cpp  | 140 --
 clang/lib/CodeGen/CGExprAgg.cpp   |  23 +--
 clang/lib/CodeGen/CodeGenFunction.h   |   3 +-
 clang/test/CodeGen/arm-mve-intrinsics/vld24.c |  43 --
 clang/test/CodeGen/arm-vfp16-arguments2.cpp   |  10 +-
 .../amdgpu-kernel-arg-pointer-type.cu |  11 +-
 clang/test/CodeGenCUDA/builtins-amdgcn.cu | 121 +++
 .../CodeGenCXX/address-space-cast-coerce.cpp  |   6 +-
 clang/test/CodeGenCXX/cxx2a-consteval.cpp |  24 ++-
 clang/test/CodeGenCXX/trivial_abi.cpp |  20 +++
 clang/test/CodeGenHIP/dpp-const-fold.hip  |   8 +-
 .../CodeGenOpenCL/addr-space-struct-arg.cl|  11 +-
 .../amdgpu-abi-struct-arg-byref.cl|  42 --
 13 files changed, 255 insertions(+), 207 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 97449a5e51e73..262aa3054754c 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1336,75 +1336,56 @@ static llvm::Value *CreateCoercedLoad(Address Src, 
llvm::Type *Ty,
   return CGF.Builder.CreateLoad(Tmp);
 }
 
-// Function to store a first-class aggregate into memory.  We prefer to
-// store the elements rather than the aggregate to be more friendly to
-// fast-isel.
-// FIXME: Do we need to recurse here?
-void CodeGenFunction::EmitAggregateStore(llvm::Value *Val, Address Dest,
- bool DestIsVolatile) {
-  // Prefer scalar stores to first-class aggregate stores.
-  if (llvm::StructType *STy = dyn_cast(Val->getType())) {
-for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
-  Address EltPtr = Builder.CreateStructGEP(Dest, i);
-  llvm::Value *Elt = Builder.CreateExtractValue(Val, i);
-  Builder.CreateStore(Elt, EltPtr, DestIsVolatile);
-}
-  } else {
-Builder.CreateStore(Val, Dest, DestIsVolatile);
-  }
-}
-
 /// CreateCoercedStore - Create a store to \arg DstPtr from \arg Src,
 /// where the source and destination may have different types.  The
 /// destination is known to be aligned to \arg DstAlign bytes.
 ///
 /// This safely handles the case when the src type is larger than the
 /// destination type; the upper bits of the src will be lost.
-static void CreateCoercedStore(llvm::Value *Src,
-   Address Dst,
-   bool DstIsVolatile,
-   CodeGenFunction &CGF) {
-  llvm::Type *SrcTy = Src->getType();
-  llvm::Type *DstTy = Dst.getElementType();
-  if (SrcTy == DstTy) {
-CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
-return;
-  }
-
-  llvm::TypeSize SrcSize = CGF.CGM.getDataLayout().getTypeAllocSize(SrcTy);
-
-  if (llvm::StructType *DstSTy = dyn_cast(DstTy)) {
-Dst = EnterStructPointerForCoercedAccess(Dst, DstSTy,
- SrcSize.getFixedValue(), CGF);
-DstTy = Dst.getElementType();
-  }
-
-  llvm::PointerType *SrcPtrTy = llvm::dyn_cast(SrcTy);
-  llvm::PointerType *DstPtrTy = llvm::dyn_cast(DstTy);
-  if (SrcPtrTy && DstPtrTy &&
-  SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) {
-Src = CGF.Builder.CreateAddrSpaceCast(Src, DstTy);
-CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
+void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, Address Dst,
+ llvm::TypeSize DstSize,
+ bool DstIsVolatile) {
+  if (!DstSize)
 return;
-  }
 
-  // If the source and destination are integer or pointer types, just do an
-  // extension or truncation to the desired type.
-  if ((isa(SrcTy) || isa(SrcTy)) &&
-  (isa(DstTy) || isa(DstTy))) {
-Src = CoerceIntOrPtrToIntOrPtr(Src, DstTy, CGF);
-CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
-return;
+  llvm::Type *SrcTy = Src->getType();
+  llvm::TypeSize SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
+
+  // GEP into structs to try to 

[clang] [clang] Cover CWG issues about `export template` (PR #94876)

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

Endilll wrote:

> We never implemented export template - and no one did, therefore we are not 
> affected by changes to it (no one did except for EDG, i don't even know if 
> they shipped it)

When I said "wording changes that do not affect implementations", I meant a 
hypothetical conforming implementation. In other words, `N/A` is for wording 
changes that can't be exhibited by writing programs and feeding them into the 
compiler.

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


[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits

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


[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits

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


[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

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

owenca wrote:

This patch formats
```
void f() {
  if (foo)
bar(); // Comment
#if BAZ
  baz();
#endif
}
```
to
```
void f() {
  if (foo)
bar();
// Comment
#if BAZ
  baz();
#endif
}
```
The trailing comment shouldn't be wrapped.

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


[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits


@@ -665,867 +1312,858 @@ class CursorKind(BaseEnumeration):
 A CursorKind describes the kind of entity that a cursor points to.
 """
 
-# The required BaseEnumeration declarations.
-_kinds = []
-_name_map = None
-
 @staticmethod
-def get_all_kinds():
+def get_all_kinds() -> list[CursorKind]:
 """Return all CursorKind enumeration instances."""
-return [x for x in CursorKind._kinds if not x is None]
+return [x for x in CursorKind]
 
-def is_declaration(self):
+def is_declaration(self) -> bool:
 """Test if this is a declaration kind."""
 return conf.lib.clang_isDeclaration(self)
 
-def is_reference(self):
+def is_reference(self) -> bool:
 """Test if this is a reference kind."""
 return conf.lib.clang_isReference(self)
 
-def is_expression(self):
+def is_expression(self) -> bool:
 """Test if this is an expression kind."""
 return conf.lib.clang_isExpression(self)
 
-def is_statement(self):
+def is_statement(self) -> bool:
 """Test if this is a statement kind."""
 return conf.lib.clang_isStatement(self)
 
-def is_attribute(self):
+def is_attribute(self) -> bool:
 """Test if this is an attribute kind."""
 return conf.lib.clang_isAttribute(self)
 
-def is_invalid(self):
+def is_invalid(self) -> bool:
 """Test if this is an invalid kind."""
 return conf.lib.clang_isInvalid(self)
 
-def is_translation_unit(self):
+def is_translation_unit(self) -> bool:
 """Test if this is a translation unit kind."""
 return conf.lib.clang_isTranslationUnit(self)
 
-def is_preprocessing(self):
+def is_preprocessing(self) -> bool:
 """Test if this is a preprocessing kind."""
 return conf.lib.clang_isPreprocessing(self)
 
-def is_unexposed(self):
+def is_unexposed(self) -> bool:
 """Test if this is an unexposed kind."""
 return conf.lib.clang_isUnexposed(self)
 
-def __repr__(self):
-return "CursorKind.%s" % (self.name,)
+###
+# Declaration Kinds
 
+# A declaration whose specific kind is not exposed via this interface.
+#
+# Unexposed declarations have the same operations as any other kind of
+# declaration; one can extract their location information, spelling, find 
their
+# definitions, etc. However, the specific kind of the declaration is not
+# reported.
+UNEXPOSED_DECL = 1
 
-###
-# Declaration Kinds
+# A C or C++ struct.
+STRUCT_DECL = 2
 
-# A declaration whose specific kind is not exposed via this interface.
-#
-# Unexposed declarations have the same operations as any other kind of
-# declaration; one can extract their location information, spelling, find their
-# definitions, etc. However, the specific kind of the declaration is not
-# reported.
-CursorKind.UNEXPOSED_DECL = CursorKind(1)
+# A C or C++ union.
+UNION_DECL = 3
 
-# A C or C++ struct.
-CursorKind.STRUCT_DECL = CursorKind(2)
+# A C++ class.
+CLASS_DECL = 4
 
-# A C or C++ union.
-CursorKind.UNION_DECL = CursorKind(3)
+# An enumeration.
+ENUM_DECL = 5
 
-# A C++ class.
-CursorKind.CLASS_DECL = CursorKind(4)
+# A field (in C) or non-static data member (in C++) in a struct, union, or 
C++
+# class.
+FIELD_DECL = 6
 
-# An enumeration.
-CursorKind.ENUM_DECL = CursorKind(5)
+# An enumerator constant.
+ENUM_CONSTANT_DECL = 7
 
-# A field (in C) or non-static data member (in C++) in a struct, union, or C++
-# class.
-CursorKind.FIELD_DECL = CursorKind(6)
+# A function.
+FUNCTION_DECL = 8
 
-# An enumerator constant.
-CursorKind.ENUM_CONSTANT_DECL = CursorKind(7)
+# A variable.
+VAR_DECL = 9
 
-# A function.
-CursorKind.FUNCTION_DECL = CursorKind(8)
+# A function or method parameter.
+PARM_DECL = 10
 
-# A variable.
-CursorKind.VAR_DECL = CursorKind(9)
+# An Objective-C @interface.
+OBJC_INTERFACE_DECL = 11
 
-# A function or method parameter.
-CursorKind.PARM_DECL = CursorKind(10)
+# An Objective-C @interface for a category.
+OBJC_CATEGORY_DECL = 12
 
-# An Objective-C @interface.
-CursorKind.OBJC_INTERFACE_DECL = CursorKind(11)
+# An Objective-C @protocol declaration.
+OBJC_PROTOCOL_DECL = 13
 
-# An Objective-C @interface for a category.
-CursorKind.OBJC_CATEGORY_DECL = CursorKind(12)
+# An Objective-C @property declaration.
+OBJC_PROPERTY_DECL = 14
 
-# An Objective-C @protocol declaration.
-CursorKind.OBJC_PROTOCOL_DECL = CursorKind(13)
+# An Objective-C instance variable.
+OBJC_IVAR_DECL = 15
 
-# An Objective-C @property declaration.
-CursorKind.OBJC_PROPERTY_DECL = CursorKind(14)
+# An Objective-C instance method.
+OBJC_INSTANCE_METHOD_DECL = 16
 
-# An Objective-C instance variable.
-CursorKind.OBJC_IVAR_DECL = CursorKind(15)
+# An Objective-C class method.
+OBJC_CLASS_METHOD_DECL = 17
 
-# An Objectiv

[clang] [clang]Add additional test coverage for `__is_trivially_relocatable(T)` (PR #91412)

2024-06-09 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

ping @corentin @shafik can you help me land this additional test coverage? It 
doesn't change any behavior, just documents the behavior we currently have.

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


[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits


@@ -2286,192 +2869,151 @@ class TypeKind(BaseEnumeration):
 Describes the kind of type.
 """
 
-# The unique kind objects, indexed by id.
-_kinds = []
-_name_map = None
-
 @property
-def spelling(self):
+def spelling(self) -> str:
 """Retrieve the spelling of this TypeKind."""
 return conf.lib.clang_getTypeKindSpelling(self.value)
 
-def __repr__(self):
-return "TypeKind.%s" % (self.name,)
-
-
-TypeKind.INVALID = TypeKind(0)
-TypeKind.UNEXPOSED = TypeKind(1)
-TypeKind.VOID = TypeKind(2)
-TypeKind.BOOL = TypeKind(3)
-TypeKind.CHAR_U = TypeKind(4)
-TypeKind.UCHAR = TypeKind(5)
-TypeKind.CHAR16 = TypeKind(6)
-TypeKind.CHAR32 = TypeKind(7)
-TypeKind.USHORT = TypeKind(8)
-TypeKind.UINT = TypeKind(9)
-TypeKind.ULONG = TypeKind(10)
-TypeKind.ULONGLONG = TypeKind(11)
-TypeKind.UINT128 = TypeKind(12)
-TypeKind.CHAR_S = TypeKind(13)
-TypeKind.SCHAR = TypeKind(14)
-TypeKind.WCHAR = TypeKind(15)
-TypeKind.SHORT = TypeKind(16)
-TypeKind.INT = TypeKind(17)
-TypeKind.LONG = TypeKind(18)
-TypeKind.LONGLONG = TypeKind(19)
-TypeKind.INT128 = TypeKind(20)
-TypeKind.FLOAT = TypeKind(21)
-TypeKind.DOUBLE = TypeKind(22)
-TypeKind.LONGDOUBLE = TypeKind(23)
-TypeKind.NULLPTR = TypeKind(24)
-TypeKind.OVERLOAD = TypeKind(25)
-TypeKind.DEPENDENT = TypeKind(26)
-TypeKind.OBJCID = TypeKind(27)
-TypeKind.OBJCCLASS = TypeKind(28)
-TypeKind.OBJCSEL = TypeKind(29)
-TypeKind.FLOAT128 = TypeKind(30)
-TypeKind.HALF = TypeKind(31)
-TypeKind.IBM128 = TypeKind(40)
-TypeKind.COMPLEX = TypeKind(100)
-TypeKind.POINTER = TypeKind(101)
-TypeKind.BLOCKPOINTER = TypeKind(102)
-TypeKind.LVALUEREFERENCE = TypeKind(103)
-TypeKind.RVALUEREFERENCE = TypeKind(104)
-TypeKind.RECORD = TypeKind(105)
-TypeKind.ENUM = TypeKind(106)
-TypeKind.TYPEDEF = TypeKind(107)
-TypeKind.OBJCINTERFACE = TypeKind(108)
-TypeKind.OBJCOBJECTPOINTER = TypeKind(109)
-TypeKind.FUNCTIONNOPROTO = TypeKind(110)
-TypeKind.FUNCTIONPROTO = TypeKind(111)
-TypeKind.CONSTANTARRAY = TypeKind(112)
-TypeKind.VECTOR = TypeKind(113)
-TypeKind.INCOMPLETEARRAY = TypeKind(114)
-TypeKind.VARIABLEARRAY = TypeKind(115)
-TypeKind.DEPENDENTSIZEDARRAY = TypeKind(116)
-TypeKind.MEMBERPOINTER = TypeKind(117)
-TypeKind.AUTO = TypeKind(118)
-TypeKind.ELABORATED = TypeKind(119)
-TypeKind.PIPE = TypeKind(120)
-TypeKind.OCLIMAGE1DRO = TypeKind(121)
-TypeKind.OCLIMAGE1DARRAYRO = TypeKind(122)
-TypeKind.OCLIMAGE1DBUFFERRO = TypeKind(123)
-TypeKind.OCLIMAGE2DRO = TypeKind(124)
-TypeKind.OCLIMAGE2DARRAYRO = TypeKind(125)
-TypeKind.OCLIMAGE2DDEPTHRO = TypeKind(126)
-TypeKind.OCLIMAGE2DARRAYDEPTHRO = TypeKind(127)
-TypeKind.OCLIMAGE2DMSAARO = TypeKind(128)
-TypeKind.OCLIMAGE2DARRAYMSAARO = TypeKind(129)
-TypeKind.OCLIMAGE2DMSAADEPTHRO = TypeKind(130)
-TypeKind.OCLIMAGE2DARRAYMSAADEPTHRO = TypeKind(131)
-TypeKind.OCLIMAGE3DRO = TypeKind(132)
-TypeKind.OCLIMAGE1DWO = TypeKind(133)
-TypeKind.OCLIMAGE1DARRAYWO = TypeKind(134)
-TypeKind.OCLIMAGE1DBUFFERWO = TypeKind(135)
-TypeKind.OCLIMAGE2DWO = TypeKind(136)
-TypeKind.OCLIMAGE2DARRAYWO = TypeKind(137)
-TypeKind.OCLIMAGE2DDEPTHWO = TypeKind(138)
-TypeKind.OCLIMAGE2DARRAYDEPTHWO = TypeKind(139)
-TypeKind.OCLIMAGE2DMSAAWO = TypeKind(140)
-TypeKind.OCLIMAGE2DARRAYMSAAWO = TypeKind(141)
-TypeKind.OCLIMAGE2DMSAADEPTHWO = TypeKind(142)
-TypeKind.OCLIMAGE2DARRAYMSAADEPTHWO = TypeKind(143)
-TypeKind.OCLIMAGE3DWO = TypeKind(144)
-TypeKind.OCLIMAGE1DRW = TypeKind(145)
-TypeKind.OCLIMAGE1DARRAYRW = TypeKind(146)
-TypeKind.OCLIMAGE1DBUFFERRW = TypeKind(147)
-TypeKind.OCLIMAGE2DRW = TypeKind(148)
-TypeKind.OCLIMAGE2DARRAYRW = TypeKind(149)
-TypeKind.OCLIMAGE2DDEPTHRW = TypeKind(150)
-TypeKind.OCLIMAGE2DARRAYDEPTHRW = TypeKind(151)
-TypeKind.OCLIMAGE2DMSAARW = TypeKind(152)
-TypeKind.OCLIMAGE2DARRAYMSAARW = TypeKind(153)
-TypeKind.OCLIMAGE2DMSAADEPTHRW = TypeKind(154)
-TypeKind.OCLIMAGE2DARRAYMSAADEPTHRW = TypeKind(155)
-TypeKind.OCLIMAGE3DRW = TypeKind(156)
-TypeKind.OCLSAMPLER = TypeKind(157)
-TypeKind.OCLEVENT = TypeKind(158)
-TypeKind.OCLQUEUE = TypeKind(159)
-TypeKind.OCLRESERVEID = TypeKind(160)
-
-TypeKind.OBJCOBJECT = TypeKind(161)
-TypeKind.OBJCCLASS = TypeKind(162)
-TypeKind.ATTRIBUTED = TypeKind(163)
-
-TypeKind.OCLINTELSUBGROUPAVCMCEPAYLOAD = TypeKind(164)
-TypeKind.OCLINTELSUBGROUPAVCIMEPAYLOAD = TypeKind(165)
-TypeKind.OCLINTELSUBGROUPAVCREFPAYLOAD = TypeKind(166)
-TypeKind.OCLINTELSUBGROUPAVCSICPAYLOAD = TypeKind(167)
-TypeKind.OCLINTELSUBGROUPAVCMCERESULT = TypeKind(168)
-TypeKind.OCLINTELSUBGROUPAVCIMERESULT = TypeKind(169)
-TypeKind.OCLINTELSUBGROUPAVCREFRESULT = TypeKind(170)
-TypeKind.OCLINTELSUBGROUPAVCSICRESULT = TypeKind(171)
-TypeKind.OCLINTELSUBGROUPAVCIMERESULTSINGLEREFERENCESTREAMOUT = TypeKind(172)
-TypeKind.OCLINTELSUBGROUPAVCIMERESULTSDUALREFERENCESTREAMOUT = TypeKind(173)
-TypeKind.OCLINTELSUBGROUPAVCIMERESULTSSINGLEREFERENCESTREAMIN = TypeKind(174)
-TypeKind.OCLINTELSUBGROUPAVCIMEDUALREFERENCESTREAMIN = TypeKind(175)
-
-TypeKind.EXTVECTOR = TypeKind(176)
-TypeKind.ATOMIC = Type

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits

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


[clang] [Clang][OpenMP] throw compilation error instead of crash in Stmt::OMPScopeDirectiveClass case (#77535) (PR #84135)

2024-06-09 Thread Eli Friedman via cfe-commits

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


[clang] dbe63e3 - [Clang][OpenMP] throw compilation error instead of crash in Stmt::OMPScopeDirectiveClass case (#77535) (#84135)

2024-06-09 Thread via cfe-commits

Author: Puelloc
Date: 2024-06-09T14:29:41-07:00
New Revision: dbe63e3d4dc9e4a53c95a6f8fd24c071d0a603e2

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

LOG: [Clang][OpenMP] throw compilation error instead of crash in 
Stmt::OMPScopeDirectiveClass case (#77535) (#84135)

Fix #77535, Change unstable assertion into compilation error, and add a
test for it.

Added: 
clang/test/OpenMP/error_unsupport_feature.c

Modified: 
clang/lib/CodeGen/CGStmt.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 41ac511c52f51..39222c0e65353 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -414,7 +414,8 @@ void CodeGenFunction::EmitStmt(const Stmt *S, 
ArrayRef Attrs) {
 CGM.ErrorUnsupported(S, "OpenMP dispatch directive");
 break;
   case Stmt::OMPScopeDirectiveClass:
-llvm_unreachable("scope not supported with FE outlining");
+CGM.ErrorUnsupported(S, "scope with FE outlining");
+break;
   case Stmt::OMPMaskedDirectiveClass:
 EmitOMPMaskedDirective(cast(*S));
 break;

diff  --git a/clang/test/OpenMP/error_unsupport_feature.c 
b/clang/test/OpenMP/error_unsupport_feature.c
new file mode 100644
index 0..611a8b4639c44
--- /dev/null
+++ b/clang/test/OpenMP/error_unsupport_feature.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -emit-llvm -verify -fopenmp %s
+
+int main () {
+  int r = 0;
+#pragma omp scope reduction(+:r) // expected-error {{cannot compile this scope 
with FE outlining yet}}
+  r++;
+  return r;
+}



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


[clang] [Clang][OpenMP] throw compilation error instead of crash in Stmt::OMPScopeDirectiveClass case (#77535) (PR #84135)

2024-06-09 Thread via cfe-commits

github-actions[bot] wrote:



@Puellaquae Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [Clang][Comments] Attach comments to decl even if preproc directives are in between (PR #88367)

2024-06-09 Thread via cfe-commits

https://github.com/hdoc updated https://github.com/llvm/llvm-project/pull/88367

>From a98d117c68b33d2e6632a832ff77b0e8258469e6 Mon Sep 17 00:00:00 2001
From: hdoc 
Date: Thu, 11 Apr 2024 01:54:18 -0700
Subject: [PATCH 1/4] Attach comments to decl even if preproc directives are in
 between

---
 clang/lib/AST/ASTContext.cpp   |   7 +-
 clang/lib/Headers/amxcomplexintrin.h   |   4 +
 clang/lib/Headers/ia32intrin.h |   2 +
 clang/test/Index/annotate-comments.cpp |   5 +-
 clang/unittests/AST/DeclTest.cpp   | 310 +
 5 files changed, 323 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index bf74e56a14799..3e9131ecf12d0 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -282,9 +282,10 @@ RawComment *ASTContext::getRawCommentForDeclNoCacheImpl(
   StringRef Text(Buffer + CommentEndOffset,
  DeclLocDecomp.second - CommentEndOffset);
 
-  // There should be no other declarations or preprocessor directives between
-  // comment and declaration.
-  if (Text.find_last_of(";{}#@") != StringRef::npos)
+  // There should be no other declarations between comment and declaration.
+  // Preprocessor directives are implicitly allowed to be between a comment and
+  // its associated decl.
+  if (Text.find_last_of(";{}@") != StringRef::npos)
 return nullptr;
 
   return CommentBeforeDecl;
diff --git a/clang/lib/Headers/amxcomplexintrin.h 
b/clang/lib/Headers/amxcomplexintrin.h
index 84ef972fcadf0..19eaee10ede65 100644
--- a/clang/lib/Headers/amxcomplexintrin.h
+++ b/clang/lib/Headers/amxcomplexintrin.h
@@ -62,6 +62,8 @@
 ///The 2nd source tile. Max size is 1024 Bytes.
 #define _tile_cmmimfp16ps(dst, a, b) __builtin_ia32_tcmmimfp16ps(dst, a, b)
 
+;
+
 /// Perform matrix multiplication of two tiles containing complex elements and
 ///accumulate the results into a packed single precision tile. Each dword
 ///element in input tiles \a a and \a b is interpreted as a complex number
@@ -107,6 +109,8 @@
 ///The 2nd source tile. Max size is 1024 Bytes.
 #define _tile_cmmrlfp16ps(dst, a, b) __builtin_ia32_tcmmrlfp16ps(dst, a, b)
 
+;
+
 static __inline__ _tile1024i __DEFAULT_FN_ATTRS_COMPLEX
 _tile_cmmimfp16ps_internal(unsigned short m, unsigned short n, unsigned short 
k,
_tile1024i dst, _tile1024i src1, _tile1024i src2) {
diff --git a/clang/lib/Headers/ia32intrin.h b/clang/lib/Headers/ia32intrin.h
index 8e65f232a0def..c9c92b9ee0f99 100644
--- a/clang/lib/Headers/ia32intrin.h
+++ b/clang/lib/Headers/ia32intrin.h
@@ -533,6 +533,8 @@ __rdtscp(unsigned int *__A) {
 /// \see __rdpmc
 #define _rdpmc(A) __rdpmc(A)
 
+;
+
 static __inline__ void __DEFAULT_FN_ATTRS
 _wbinvd(void) {
   __builtin_ia32_wbinvd();
diff --git a/clang/test/Index/annotate-comments.cpp 
b/clang/test/Index/annotate-comments.cpp
index 6f9f8f0bbbc9e..bff25d46cf80e 100644
--- a/clang/test/Index/annotate-comments.cpp
+++ b/clang/test/Index/annotate-comments.cpp
@@ -204,9 +204,9 @@ void isdoxy45(void);
 /// Ggg. IS_DOXYGEN_END
 void isdoxy46(void);
 
-/// IS_DOXYGEN_NOT_ATTACHED
+/// isdoxy47 IS_DOXYGEN_SINGLE
 #define FOO
-void notdoxy47(void);
+void isdoxy47(void);
 
 /// IS_DOXYGEN_START Aaa bbb
 /// \param ccc
@@ -330,6 +330,7 @@ void isdoxy54(int);
 // CHECK: annotate-comments.cpp:185:6: FunctionDecl=isdoxy44:{{.*}} 
BriefComment=[IS_DOXYGEN_START Aaa bbb ccc.]
 // CHECK: annotate-comments.cpp:195:6: FunctionDecl=isdoxy45:{{.*}} 
BriefComment=[Ddd eee. Fff.]
 // CHECK: annotate-comments.cpp:205:6: FunctionDecl=isdoxy46:{{.*}} 
BriefComment=[Ddd eee. Fff.]
+// CHECK: annotate-comments.cpp:209:6: FunctionDecl=isdoxy47:{{.*}} isdoxy47 
IS_DOXYGEN_SINGLE
 // CHECK: annotate-comments.cpp:214:6: FunctionDecl=isdoxy48:{{.*}} 
BriefComment=[IS_DOXYGEN_START Aaa bbb]
 // CHECK: annotate-comments.cpp:218:6: FunctionDecl=isdoxy49:{{.*}} 
BriefComment=[IS_DOXYGEN_START Aaa]
 // CHECK: annotate-comments.cpp:222:6: FunctionDecl=isdoxy50:{{.*}} 
BriefComment=[Returns ddd IS_DOXYGEN_END]
diff --git a/clang/unittests/AST/DeclTest.cpp b/clang/unittests/AST/DeclTest.cpp
index 16aa2b50b7a06..8dca011ba8779 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -576,3 +576,313 @@ void instantiate_template() {
   EXPECT_EQ(GetNameInfoRange(Matches[1]), "");
   EXPECT_EQ(GetNameInfoRange(Matches[2]), "");
 }
+
+TEST(Decl, CommentsAttachedToDecl1) {
+  const SmallVector Sources{
+  R"(
+/// Test comment
+void f();
+  )",
+
+  R"(
+/// Test comment
+
+void f();
+  )",
+
+  R"(
+/// Test comment
+#if 0
+// tralala
+#endif
+void f();
+  )",
+
+  R"(
+/// Test comment
+
+#if 0
+// tralala
+#endif
+
+void f();
+  )",
+
+  R"(
+/// Test comment
+#ifdef DOCS
+template
+#endif
+void f();
+

[clang] [Clang][Comments] Attach comments to decl even if preproc directives are in between (PR #88367)

2024-06-09 Thread via cfe-commits


@@ -533,6 +533,8 @@ __rdtscp(unsigned int *__A) {
 /// \see __rdpmc
 #define _rdpmc(A) __rdpmc(A)
 
+;

hdoc wrote:

Agreed, I think it will need to change at some point and I will see if we can 
get support for doing that work.

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


[clang] [Clang][Comments] Attach comments to decl even if preproc directives are in between (PR #88367)

2024-06-09 Thread via cfe-commits

hdoc wrote:

@AaronBallman Added the blurb to the release notes, let me know if that matches 
your expectations or if any changes are required. Thank you!

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


[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits

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


[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

Since https://github.com/llvm/llvm-project/issues/83962 is now closed and the 
minimum Python version updated to 3.8, this is now finally ready for review. 
I've updated this with the changes to the Python bindings of the past couple 
months.

I have no idea idea what the error in the test failure means, so any advice 
would be appreciated.

@AaronBallman could you review this or recommend reviewers?

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


[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits

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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-09 Thread via cfe-commits

https://github.com/hdoc updated https://github.com/llvm/llvm-project/pull/84726

>From 49fd778d21adb49080d1f9b360aa5cda2b7359a6 Mon Sep 17 00:00:00 2001
From: hdoc 
Date: Mon, 11 Mar 2024 01:13:25 -0700
Subject: [PATCH 01/10] Comment parsing: add argument parsing for @throw
 @throws @exception

Doxygen allows for the @throw, @throws, and @exception commands to
have an attached argument indicating the type being thrown. Currently,
Clang's AST parsing doesn't support parsing out this argument from doc
comments. The result is missing compatibility with Doxygen.

We would find it helpful if the AST exposed these thrown types as
BlockCommandComment arguments so that we could generate better
documentation.

This PR implements parsing of arguments for the @throw, @throws, and
@exception commands. Each command can only have one argument, matching
the semantics of Doxygen. We have also added unit tests to validate
the functionality.
---
 clang/include/clang/AST/CommentCommands.td |   6 +-
 clang/include/clang/AST/CommentParser.h|   3 +
 clang/lib/AST/CommentParser.cpp| 133 
 clang/unittests/AST/CommentParser.cpp  | 235 -
 4 files changed, 373 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/CommentCommands.td 
b/clang/include/clang/AST/CommentCommands.td
index e839031752cdd..06b2fa9b5531c 100644
--- a/clang/include/clang/AST/CommentCommands.td
+++ b/clang/include/clang/AST/CommentCommands.td
@@ -132,9 +132,9 @@ def Tparam : BlockCommand<"tparam"> { let IsTParamCommand = 
1; }
 // HeaderDoc command for template parameter documentation.
 def Templatefield : BlockCommand<"templatefield"> { let IsTParamCommand = 1; }
 
-def Throws: BlockCommand<"throws"> { let IsThrowsCommand = 1; }
-def Throw : BlockCommand<"throw"> { let IsThrowsCommand = 1; }
-def Exception : BlockCommand<"exception"> { let IsThrowsCommand = 1; }
+def Throws: BlockCommand<"throws"> { let IsThrowsCommand = 1; let NumArgs 
= 1; }
+def Throw : BlockCommand<"throw"> { let IsThrowsCommand = 1; let NumArgs = 
1; }
+def Exception : BlockCommand<"exception"> { let IsThrowsCommand = 1; let 
NumArgs = 1;}
 
 def Deprecated : BlockCommand<"deprecated"> {
   let IsEmptyParagraphAllowed = 1;
diff --git a/clang/include/clang/AST/CommentParser.h 
b/clang/include/clang/AST/CommentParser.h
index e11e818b1af0a..5884a25d00785 100644
--- a/clang/include/clang/AST/CommentParser.h
+++ b/clang/include/clang/AST/CommentParser.h
@@ -100,6 +100,9 @@ class Parser {
   ArrayRef
   parseCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
 
+  ArrayRef
+  parseThrowCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
+
   BlockCommandComment *parseBlockCommand();
   InlineCommandComment *parseInlineCommand();
 
diff --git a/clang/lib/AST/CommentParser.cpp b/clang/lib/AST/CommentParser.cpp
index 8adfd85d0160c..c70fa1b05cb24 100644
--- a/clang/lib/AST/CommentParser.cpp
+++ b/clang/lib/AST/CommentParser.cpp
@@ -75,6 +75,25 @@ class TextTokenRetokenizer {
 return *Pos.BufferPtr;
   }
 
+  char peekNext(unsigned offset) const {
+assert(!isEnd());
+assert(Pos.BufferPtr != Pos.BufferEnd);
+if (Pos.BufferPtr + offset <= Pos.BufferEnd) {
+  return *(Pos.BufferPtr + offset);
+} else {
+  return '\0';
+}
+  }
+
+  void peekNextToken(SmallString<32> &WordText) const {
+unsigned offset = 1;
+char C = peekNext(offset++);
+while (!isWhitespace(C) && C != '\0') {
+  WordText.push_back(C);
+  C = peekNext(offset++);
+}
+  }
+
   void consumeChar() {
 assert(!isEnd());
 assert(Pos.BufferPtr != Pos.BufferEnd);
@@ -89,6 +108,29 @@ class TextTokenRetokenizer {
 }
   }
 
+  /// Extract a template type
+  bool lexTemplateType(SmallString<32> &WordText) {
+unsigned IncrementCounter = 0;
+while (!isEnd()) {
+  const char C = peek();
+  WordText.push_back(C);
+  consumeChar();
+  switch (C) {
+  default:
+break;
+  case '<': {
+IncrementCounter++;
+  } break;
+  case '>': {
+IncrementCounter--;
+if (!IncrementCounter)
+  return true;
+  } break;
+  }
+}
+return false;
+  }
+
   /// Add a token.
   /// Returns true on success, false if there are no interesting tokens to
   /// fetch from lexer.
@@ -149,6 +191,76 @@ class TextTokenRetokenizer {
 addToken();
   }
 
+  /// Extract a type argument
+  bool lexDataType(Token &Tok) {
+if (isEnd())
+  return false;
+Position SavedPos = Pos;
+consumeWhitespace();
+SmallString<32> NextToken;
+SmallString<32> WordText;
+const char *WordBegin = Pos.BufferPtr;
+SourceLocation Loc = getSourceLocation();
+StringRef ConstVal = StringRef("const");
+bool ConstPointer = false;
+
+while (!isEnd()) {
+  const char C = peek();
+  if (!isWhitespace(C)) {
+if (C == '<') {
+  if (!lexTemplateType(WordText))
+return false;
+

[clang-tools-extra] [clangd] Make it possible to enable misc-const-correctness clang-tidy check (PR #94920)

2024-06-09 Thread via cfe-commits

https://github.com/geza-herman created 
https://github.com/llvm/llvm-project/pull/94920

Before this PR, it wasn't possible to enable misc-const-correctness: 
disableUnusableChecks() forcefully disabled it because the check is slow.  It 
was implemented this way before clangd got the FastCheckFilter feature.  As the 
default setting of FastCheckFilter also disables misc-const-correctness, it 
makes sense to remove misc-const-correctness from disableUnusableChecks()'s 
list, to make it possible to enable misc-const-correctness by setting 
FastCheckFilter to None.  Fixes 
https://github.com/llvm/llvm-project/issues/89758.

>From 6c251aa7d749581964f279255ff03fa8b765dcbb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A9za=20Herman?= 
Date: Sun, 9 Jun 2024 23:38:42 +0200
Subject: [PATCH] [clangd] Make it possible to enable misc-const-correctness
 clang-tidy check

Before this commit, it wasn't possible to enable misc-const-correctness:
disableUnusableChecks() forcefully disabled it because the check is slow.  It
was implemented this way before clangd got the FastCheckFilter feature.  As the
default setting of FastCheckFilter also disables misc-const-correctness, it
makes sense to remove misc-const-correctness from disableUnusableChecks()'s
list, to make it possible to enable misc-const-correctness by setting
FastCheckFilter to None.  Fixes #89758.
---
 clang-tools-extra/clangd/TidyProvider.cpp | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index b658a80559937..a4121df30d3df 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -221,13 +221,7 @@ TidyProvider 
disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) {
   "-hicpp-invalid-access-moved",
   // Check uses dataflow analysis, which might hang/crash unexpectedly on
   // incomplete code.
-  "-bugprone-unchecked-optional-access",
-
-  // - Performance problems -
-
-  // This check runs expensive analysis for each variable.
-  // It has been observed to increase reparse time by 10x.
-  "-misc-const-correctness");
+  "-bugprone-unchecked-optional-access");
 
   size_t Size = BadChecks.size();
   for (const std::string &Str : ExtraBadChecks) {

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


[clang-tools-extra] [clangd] Make it possible to enable misc-const-correctness clang-tidy check (PR #94920)

2024-06-09 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang-tools-extra] [clangd] Make it possible to enable misc-const-correctness clang-tidy check (PR #94920)

2024-06-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: None (geza-herman)


Changes

Before this PR, it wasn't possible to enable misc-const-correctness: 
disableUnusableChecks() forcefully disabled it because the check is slow.  It 
was implemented this way before clangd got the FastCheckFilter feature.  As the 
default setting of FastCheckFilter also disables misc-const-correctness, it 
makes sense to remove misc-const-correctness from disableUnusableChecks()'s 
list, to make it possible to enable misc-const-correctness by setting 
FastCheckFilter to None.  Fixes 
https://github.com/llvm/llvm-project/issues/89758.

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


1 Files Affected:

- (modified) clang-tools-extra/clangd/TidyProvider.cpp (+1-7) 


``diff
diff --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index b658a80559937..a4121df30d3df 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -221,13 +221,7 @@ TidyProvider 
disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) {
   "-hicpp-invalid-access-moved",
   // Check uses dataflow analysis, which might hang/crash unexpectedly on
   // incomplete code.
-  "-bugprone-unchecked-optional-access",
-
-  // - Performance problems -
-
-  // This check runs expensive analysis for each variable.
-  // It has been observed to increase reparse time by 10x.
-  "-misc-const-correctness");
+  "-bugprone-unchecked-optional-access");
 
   size_t Size = BadChecks.size();
   for (const std::string &Str : ExtraBadChecks) {

``




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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-09 Thread via cfe-commits

https://github.com/hdoc updated https://github.com/llvm/llvm-project/pull/84726

>From 49fd778d21adb49080d1f9b360aa5cda2b7359a6 Mon Sep 17 00:00:00 2001
From: hdoc 
Date: Mon, 11 Mar 2024 01:13:25 -0700
Subject: [PATCH 01/11] Comment parsing: add argument parsing for @throw
 @throws @exception

Doxygen allows for the @throw, @throws, and @exception commands to
have an attached argument indicating the type being thrown. Currently,
Clang's AST parsing doesn't support parsing out this argument from doc
comments. The result is missing compatibility with Doxygen.

We would find it helpful if the AST exposed these thrown types as
BlockCommandComment arguments so that we could generate better
documentation.

This PR implements parsing of arguments for the @throw, @throws, and
@exception commands. Each command can only have one argument, matching
the semantics of Doxygen. We have also added unit tests to validate
the functionality.
---
 clang/include/clang/AST/CommentCommands.td |   6 +-
 clang/include/clang/AST/CommentParser.h|   3 +
 clang/lib/AST/CommentParser.cpp| 133 
 clang/unittests/AST/CommentParser.cpp  | 235 -
 4 files changed, 373 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/CommentCommands.td 
b/clang/include/clang/AST/CommentCommands.td
index e839031752cdd..06b2fa9b5531c 100644
--- a/clang/include/clang/AST/CommentCommands.td
+++ b/clang/include/clang/AST/CommentCommands.td
@@ -132,9 +132,9 @@ def Tparam : BlockCommand<"tparam"> { let IsTParamCommand = 
1; }
 // HeaderDoc command for template parameter documentation.
 def Templatefield : BlockCommand<"templatefield"> { let IsTParamCommand = 1; }
 
-def Throws: BlockCommand<"throws"> { let IsThrowsCommand = 1; }
-def Throw : BlockCommand<"throw"> { let IsThrowsCommand = 1; }
-def Exception : BlockCommand<"exception"> { let IsThrowsCommand = 1; }
+def Throws: BlockCommand<"throws"> { let IsThrowsCommand = 1; let NumArgs 
= 1; }
+def Throw : BlockCommand<"throw"> { let IsThrowsCommand = 1; let NumArgs = 
1; }
+def Exception : BlockCommand<"exception"> { let IsThrowsCommand = 1; let 
NumArgs = 1;}
 
 def Deprecated : BlockCommand<"deprecated"> {
   let IsEmptyParagraphAllowed = 1;
diff --git a/clang/include/clang/AST/CommentParser.h 
b/clang/include/clang/AST/CommentParser.h
index e11e818b1af0a..5884a25d00785 100644
--- a/clang/include/clang/AST/CommentParser.h
+++ b/clang/include/clang/AST/CommentParser.h
@@ -100,6 +100,9 @@ class Parser {
   ArrayRef
   parseCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
 
+  ArrayRef
+  parseThrowCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
+
   BlockCommandComment *parseBlockCommand();
   InlineCommandComment *parseInlineCommand();
 
diff --git a/clang/lib/AST/CommentParser.cpp b/clang/lib/AST/CommentParser.cpp
index 8adfd85d0160c..c70fa1b05cb24 100644
--- a/clang/lib/AST/CommentParser.cpp
+++ b/clang/lib/AST/CommentParser.cpp
@@ -75,6 +75,25 @@ class TextTokenRetokenizer {
 return *Pos.BufferPtr;
   }
 
+  char peekNext(unsigned offset) const {
+assert(!isEnd());
+assert(Pos.BufferPtr != Pos.BufferEnd);
+if (Pos.BufferPtr + offset <= Pos.BufferEnd) {
+  return *(Pos.BufferPtr + offset);
+} else {
+  return '\0';
+}
+  }
+
+  void peekNextToken(SmallString<32> &WordText) const {
+unsigned offset = 1;
+char C = peekNext(offset++);
+while (!isWhitespace(C) && C != '\0') {
+  WordText.push_back(C);
+  C = peekNext(offset++);
+}
+  }
+
   void consumeChar() {
 assert(!isEnd());
 assert(Pos.BufferPtr != Pos.BufferEnd);
@@ -89,6 +108,29 @@ class TextTokenRetokenizer {
 }
   }
 
+  /// Extract a template type
+  bool lexTemplateType(SmallString<32> &WordText) {
+unsigned IncrementCounter = 0;
+while (!isEnd()) {
+  const char C = peek();
+  WordText.push_back(C);
+  consumeChar();
+  switch (C) {
+  default:
+break;
+  case '<': {
+IncrementCounter++;
+  } break;
+  case '>': {
+IncrementCounter--;
+if (!IncrementCounter)
+  return true;
+  } break;
+  }
+}
+return false;
+  }
+
   /// Add a token.
   /// Returns true on success, false if there are no interesting tokens to
   /// fetch from lexer.
@@ -149,6 +191,76 @@ class TextTokenRetokenizer {
 addToken();
   }
 
+  /// Extract a type argument
+  bool lexDataType(Token &Tok) {
+if (isEnd())
+  return false;
+Position SavedPos = Pos;
+consumeWhitespace();
+SmallString<32> NextToken;
+SmallString<32> WordText;
+const char *WordBegin = Pos.BufferPtr;
+SourceLocation Loc = getSourceLocation();
+StringRef ConstVal = StringRef("const");
+bool ConstPointer = false;
+
+while (!isEnd()) {
+  const char C = peek();
+  if (!isWhitespace(C)) {
+if (C == '<') {
+  if (!lexTemplateType(WordText))
+return false;
+

[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-09 Thread via cfe-commits


@@ -89,6 +89,31 @@ class TextTokenRetokenizer {
 }
   }
 
+  /// Extract a template type
+  bool lexTemplate(SmallString<32> &WordText) {

hdoc wrote:

Added some more test cases that check this edge case behavior, like unequal 
numbers of opening and closing brackets as well as some other unusual edge 
cases.

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


[clang] [Clang][Comments] Support for parsing headers in Doxygen \par commands (PR #91100)

2024-06-09 Thread via cfe-commits

https://github.com/hdoc updated https://github.com/llvm/llvm-project/pull/91100

>From 8f150b83a3575fa612b21a2f91cb499e356b34b2 Mon Sep 17 00:00:00 2001
From: hdoc 
Date: Sat, 4 May 2024 18:50:16 -0700
Subject: [PATCH 1/3] Support for parsing headers in Doxygen \par commands

---
 .../include/clang/AST/CommentCommandTraits.h  |   4 +
 clang/include/clang/AST/CommentCommands.td|   3 +-
 clang/include/clang/AST/CommentParser.h   |   4 +-
 clang/lib/AST/CommentParser.cpp   |  77 ++
 clang/test/Index/comment-misc-tags.m  |   8 +-
 clang/unittests/AST/CommentParser.cpp | 139 +-
 .../ClangCommentCommandInfoEmitter.cpp|   1 +
 7 files changed, 228 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/AST/CommentCommandTraits.h 
b/clang/include/clang/AST/CommentCommandTraits.h
index 0c3254d84eb00..78c484fff3aed 100644
--- a/clang/include/clang/AST/CommentCommandTraits.h
+++ b/clang/include/clang/AST/CommentCommandTraits.h
@@ -88,6 +88,10 @@ struct CommandInfo {
   LLVM_PREFERRED_TYPE(bool)
   unsigned IsHeaderfileCommand : 1;
 
+  /// True if this is a \\par command.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned IsParCommand : 1;
+
   /// True if we don't want to warn about this command being passed an empty
   /// paragraph.  Meaningful only for block commands.
   LLVM_PREFERRED_TYPE(bool)
diff --git a/clang/include/clang/AST/CommentCommands.td 
b/clang/include/clang/AST/CommentCommands.td
index e839031752cdd..5fd687b0d8991 100644
--- a/clang/include/clang/AST/CommentCommands.td
+++ b/clang/include/clang/AST/CommentCommands.td
@@ -18,6 +18,7 @@ class Command {
   bit IsThrowsCommand = 0;
   bit IsDeprecatedCommand = 0;
   bit IsHeaderfileCommand = 0;
+  bit IsParCommand = 0;
 
   bit IsEmptyParagraphAllowed = 0;
 
@@ -156,7 +157,7 @@ def Date   : BlockCommand<"date">;
 def Invariant  : BlockCommand<"invariant">;
 def Li : BlockCommand<"li">;
 def Note   : BlockCommand<"note">;
-def Par: BlockCommand<"par">;
+def Par: BlockCommand<"par"> { let IsParCommand = 1; let NumArgs = 1; }
 def Post   : BlockCommand<"post">;
 def Pre: BlockCommand<"pre">;
 def Remark : BlockCommand<"remark">;
diff --git a/clang/include/clang/AST/CommentParser.h 
b/clang/include/clang/AST/CommentParser.h
index e11e818b1af0a..b5f1c6c19f0ce 100644
--- a/clang/include/clang/AST/CommentParser.h
+++ b/clang/include/clang/AST/CommentParser.h
@@ -100,6 +100,9 @@ class Parser {
   ArrayRef
   parseCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
 
+  ArrayRef
+  parseParCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
+
   BlockCommandComment *parseBlockCommand();
   InlineCommandComment *parseInlineCommand();
 
@@ -118,4 +121,3 @@ class Parser {
 } // end namespace clang
 
 #endif
-
diff --git a/clang/lib/AST/CommentParser.cpp b/clang/lib/AST/CommentParser.cpp
index 8adfd85d0160c..54760f5ba932e 100644
--- a/clang/lib/AST/CommentParser.cpp
+++ b/clang/lib/AST/CommentParser.cpp
@@ -149,6 +149,63 @@ class TextTokenRetokenizer {
 addToken();
   }
 
+  /// Check if this line starts with @par or \par
+  bool startsWithParCommand() {
+unsigned Offset = 1;
+
+/// Skip all whitespace characters at the beginning.
+/// This needs to backtrack because Pos has already advanced past the
+/// actual \par or @par command by the time this function is called.
+while (isWhitespace(*(Pos.BufferPtr - Offset)))
+  Offset++;
+
+/// Check if next four characters are \par or @par
+llvm::StringRef LineStart(Pos.BufferPtr - 5, 4);
+return LineStart.starts_with("\\par") || LineStart.starts_with("@par");
+  }
+
+  /// Extract a par command argument-header.
+  bool lexParHeading(Token &Tok) {
+if (isEnd())
+  return false;
+
+Position SavedPos = Pos;
+
+consumeWhitespace();
+SmallString<32> WordText;
+const char *WordBegin = Pos.BufferPtr;
+SourceLocation Loc = getSourceLocation();
+
+if (!startsWithParCommand())
+  return false;
+
+// Read until the end of this token, which is effectively the end of the
+// line This gets us the content of the par header, if there is one.
+while (!isEnd()) {
+  WordText.push_back(peek());
+  if (Pos.BufferPtr + 1 == Pos.BufferEnd) {
+consumeChar();
+break;
+  } else {
+consumeChar();
+  }
+}
+
+const unsigned Length = WordText.size();
+if (Length == 0) {
+  Pos = SavedPos;
+  return false;
+}
+
+char *TextPtr = Allocator.Allocate(Length + 1);
+
+memcpy(TextPtr, WordText.c_str(), Length + 1);
+StringRef Text = StringRef(TextPtr, Length);
+
+formTokenWithChars(Tok, Loc, WordBegin, Length, Text);
+return true;
+  }
+
   /// Extract a word -- sequence of non-whitespace characters.
   bool lexWord(Token &Tok) {
 if (isEnd())
@@ -304,6 +361,23 @@ Parser::parseCommandArgs(TextTokenRetokenizer 
&Retokenizer, unsigned NumArgs)

[clang] [Clang][Comments] Support for parsing headers in Doxygen \par commands (PR #91100)

2024-06-09 Thread via cfe-commits


@@ -149,6 +149,63 @@ class TextTokenRetokenizer {
 addToken();
   }
 
+  /// Check if this line starts with @par or \par
+  bool startsWithParCommand() {
+unsigned Offset = 1;
+
+/// Skip all whitespace characters at the beginning.
+/// This needs to backtrack because Pos has already advanced past the
+/// actual \par or @par command by the time this function is called.
+while (isWhitespace(*(Pos.BufferPtr - Offset)))
+  Offset++;

hdoc wrote:

The issue is that the position of `Pos.BufferPtr` is after the `@par` command 
when `lexParHeading` is called. I believe this is because the comment parser 
[consumes](https://github.com/llvm/llvm-project/blob/84dd803993fd2b6b31f8168a3f4dc729406bd3ca/clang/lib/AST/CommentParser.cpp#L407)
 the `@par` command token itself during parsing, and then based on the token 
[it decides to 
call](https://github.com/llvm/llvm-project/blob/84dd803993fd2b6b31f8168a3f4dc729406bd3ca/clang/lib/AST/CommentParser.cpp#L434-L436)
 `lexParHeading`. I've done some tests locally to verify this behavior, and my 
observations align with what I describe above.

While I agree that it'd be preferable to do a readahead instead of 
backtracking, I don't see any easy ways to refactor the PR to incorporate this 
behavior as it currently stands. It looks like we'd have to refactor a little 
more of the comment parser, which is delicate and would incorporate changes 
outside of the scope of this change.

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


[clang] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (PR #94885)

2024-06-09 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/94885

>From 46f89e7456939424b5cb740ec55a89c474f8ebfd Mon Sep 17 00:00:00 2001
From: Rose 
Date: Sat, 8 Jun 2024 22:30:53 -0400
Subject: [PATCH] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot
 overflow

When accessing data in the buffer, we know we won't overrun the buffer, so we 
know it is inbounds. In addition, we know that the addition to increase the 
index is also NUW because the buffer's end has to be unsigned-greater-than 0, 
which becomes untrue if the bounds ever has an unsigned wrap.
---
 clang/lib/CodeGen/CGObjC.cpp | 4 ++--
 clang/test/CodeGenObjC/arc-foreach.m | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 281b2d9795f6c..80a64d8e4cdd9 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -1952,7 +1952,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const 
ObjCForCollectionStmt &S){
 Builder.CreateLoad(StateItemsPtr, "stateitems");
 
   // Fetch the value at the current index from the buffer.
-  llvm::Value *CurrentItemPtr = Builder.CreateGEP(
+  llvm::Value *CurrentItemPtr = Builder.CreateInBoundsGEP(
   ObjCIdType, EnumStateItems, index, "currentitem.ptr");
   llvm::Value *CurrentItem =
 Builder.CreateAlignedLoad(ObjCIdType, CurrentItemPtr, getPointerAlign());
@@ -2028,7 +2028,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const 
ObjCForCollectionStmt &S){
 
   // First we check in the local buffer.
   llvm::Value *indexPlusOne =
-  Builder.CreateAdd(index, llvm::ConstantInt::get(NSUIntegerTy, 1));
+  Builder.CreateNUWAdd(index, llvm::ConstantInt::get(NSUIntegerTy, 1));
 
   // If we haven't overrun the buffer yet, we can continue.
   // Set the branch weights based on the simplifying assumption that this is
diff --git a/clang/test/CodeGenObjC/arc-foreach.m 
b/clang/test/CodeGenObjC/arc-foreach.m
index 71edc5161303c..9f7b60aef7a1b 100644
--- a/clang/test/CodeGenObjC/arc-foreach.m
+++ b/clang/test/CodeGenObjC/arc-foreach.m
@@ -53,7 +53,7 @@ void test0(NSArray *array) {
 
 // CHECK-LP64:  [[T0:%.*]] = getelementptr inbounds [[STATE_T]], ptr 
[[STATE]], i32 0, i32 1
 // CHECK-LP64-NEXT: [[T1:%.*]] = load ptr, ptr [[T0]]
-// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr ptr, ptr [[T1]], i64
+// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr inbounds ptr, ptr [[T1]], i64
 // CHECK-LP64-NEXT: [[T3:%.*]] = load ptr, ptr [[T2]]
 // CHECK-LP64-NEXT: store ptr [[T3]], ptr [[X]]
 
@@ -100,7 +100,7 @@ void test1(NSArray *array) {
 
 // CHECK-LP64:  [[T0:%.*]] = getelementptr inbounds [[STATE_T]], ptr 
[[STATE]], i32 0, i32 1
 // CHECK-LP64-NEXT: [[T1:%.*]] = load ptr, ptr [[T0]]
-// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr ptr, ptr [[T1]], i64
+// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr inbounds ptr, ptr [[T1]], i64
 // CHECK-LP64-NEXT: [[T3:%.*]] = load ptr, ptr [[T2]]
 // CHECK-LP64-NEXT: call ptr @llvm.objc.initWeak(ptr [[X]], ptr [[T3]])
 

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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

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


@@ -22858,6 +22858,36 @@ TEST_F(FormatTest, FormatsLambdas) {
   "  //\n"
   "});");
 
+  FormatStyle LLVMStyle = getLLVMStyleWithColumns(60);
+
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n)\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}",
+   LLVMStyle);
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n) noexcept\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}",
+   LLVMStyle);
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n) constexpr\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}",
+   LLVMStyle);

owenca wrote:

Please remove `main()`.

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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

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


@@ -22858,6 +22858,36 @@ TEST_F(FormatTest, FormatsLambdas) {
   "  //\n"
   "});");
 
+  FormatStyle LLVMStyle = getLLVMStyleWithColumns(60);
+
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n)\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}",
+   LLVMStyle);

owenca wrote:

We can drop this test.

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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

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


@@ -1457,6 +1457,11 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   !Current.isOneOf(tok::colon, tok::comment)) {
 return ContinuationIndent;
   }
+  if (Current.is(TT_TrailingReturnArrow) &&
+  Previous.isOneOf(tok::kw_noexcept, tok::kw_mutable, tok::kw_constexpr,
+   tok::kw_consteval, tok::kw_static)) {

owenca wrote:

```suggestion
   tok::kw_consteval, tok::kw_static, TT_AttributeSquare)) {
```
And move this `if` block to line 1260.

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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

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


@@ -22858,6 +22858,36 @@ TEST_F(FormatTest, FormatsLambdas) {
   "  //\n"
   "});");
 
+  FormatStyle LLVMStyle = getLLVMStyleWithColumns(60);
+
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n)\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}",
+   LLVMStyle);
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n) noexcept\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}",
+   LLVMStyle);

owenca wrote:

```suggestion
  verifyFormat("very_long_function_name_yes_it_is_really_long(\n"
   "[](auto n) noexcept [[back_attr]]\n"
   "-> std::unordered_map {\n"
   "  really_do_something();\n"
   "});",
   Style);
```
Removes `main()` and adds `[[back_attr]]`.

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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

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

owenca wrote:

> Technically also applies to attributes applied to the return type of the 
> lambda, i.e.
> 
> ```
> int main() {
>   very_long_function_name_yes_it_is_really_long(
>   // also happens with constexpr specifier
>   [](auto n) [[attribute]]
>   -> std::enable_if_t<
>   std::is_arithmetic::value &&
>   !std::is_same, bool>::value> {
> do_something(n * 2);
>   });
> }
> ```
> 
> ...but currently at least no valid C++ attribute can go in that spot

We can easily take care of it though. See 
https://github.com/llvm/llvm-project/pull/94560#discussion_r1632406068.

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


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

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


@@ -1864,7 +1894,11 @@ FormatStyle getWebKitStyle() {
   Style.ObjCSpaceAfterProperty = true;
   Style.PointerAlignment = FormatStyle::PAS_Left;
   Style.SpaceBeforeCpp11BracedList = true;
-  Style.SpaceInEmptyBlock = true;
+  Style.SpaceInEmptyBraces = FormatStyle::SIEBO_Custom;
+  Style.SpaceInEmptyBracesOptions.Block = true;
+  Style.SpaceInEmptyBracesOptions.InitList = true;
+  Style.SpacesInParensOptions.InEmptyParentheses = false;

owenca wrote:

IMO we need to go by the published [WebKit coding 
style](https://webkit.org/code-style-guidelines/), not the script.

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


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

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

owenca wrote:

> See [#93635 
> (comment)](https://github.com/llvm/llvm-project/issues/93635#issuecomment-2138778128).

@khei4 maybe an `enum` for `SpaceInEmptyBraces` with `Always`, `Never`, and 
`Custom`. (IMO `Leave` doesn't make sense.)

With `Custom`, a list of boolean suboptions e.g. `Function`, `List`, etc. can 
be set individually.

We have the following brace types now:
```
BlockLBrace
BracedListLBrace
ClassLBrace
ControlStatementLBrace
ElseLBrace
EnumLBrace
FunctionLBrace
InlineASMBrace
LambdaLBrace
NamespaceLBrace
ObjCBlockLBrace
RecordLBrace
RequiresExpressionLBrace
StructLBrace
SwitchExpressionLBrace
UnionLBrace
```
I would implement all that make sense or are applicable to WebKit.


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


[clang-tools-extra] [clang-tidy] fix false positives for the functions with the same name as standard library functions in misc-include-cleaner (PR #94923)

2024-06-09 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/94923

Fixes: #93335
For decl with body, we should provide physical locations also. Because it may 
be the function which have the same name as std library.

>From e467b03cc120eedc580c185232f000e0d8aa0cc7 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 10 Jun 2024 09:04:27 +0800
Subject: [PATCH] [clang-tidy] fix false positives for the functions with the
 same name as standard library functions in misc-include-cleaner

Fixes: #93335
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../include-cleaner/lib/LocateSymbol.cpp  |  8 ++--
 .../include-cleaner/unittests/FindHeadersTest.cpp | 11 +++
 .../test/clang-tidy/checkers/misc/include-cleaner.cpp |  2 ++
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3f0d25ec8c752..8c78d872b9a1a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -286,6 +286,10 @@ Changes in existing checks
   Additionally, the option `UseHeaderFileExtensions` is removed, so that the
   check uses the `HeaderFileExtensions` option unconditionally.
 
+- Improved :doc:`misc-include-cleaner
+  ` check by avoiding false positives 
for
+  the functions with the same name as standard library functions.
+
 - Improved :doc:`misc-unused-using-decls
   ` check by replacing the local
   option `HeaderFileExtensions` by the global option of the same name.
diff --git a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp 
b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
index 78e783a62eb27..9148d36a5038f 100644
--- a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
+++ b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
@@ -14,6 +14,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -40,8 +41,11 @@ Hints declHints(const Decl *D) {
 std::vector> locateDecl(const Decl &D) {
   std::vector> Result;
   // FIXME: Should we also provide physical locations?
-  if (auto SS = tooling::stdlib::Recognizer()(&D))
-return {{*SS, Hints::CompleteSymbol}};
+  if (auto SS = tooling::stdlib::Recognizer()(&D)) {
+Result.push_back({*SS, Hints::CompleteSymbol});
+if (!D.hasBody())
+  return Result;
+  }
   // FIXME: Signal foreign decls, e.g. a forward declaration not owned by a
   // library. Some useful signals could be derived by checking the DeclContext.
   // Most incidental forward decls look like:
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index 07302142a13e3..fdcbf25fd628c 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -628,6 +628,17 @@ TEST_F(HeadersForSymbolTest, StandardHeaders) {
tooling::stdlib::Header::named("")));
 }
 
+TEST_F(HeadersForSymbolTest, NonStandardHeaders) {
+  Inputs.Code = "void assert() {}";
+  buildAST();
+  EXPECT_THAT(
+  headersFor("assert"),
+  // Respect the ordering from the stdlib mapping.
+  UnorderedElementsAre(physicalHeader("input.mm"),
+   tooling::stdlib::Header::named(""),
+   tooling::stdlib::Header::named("")));
+}
+
 TEST_F(HeadersForSymbolTest, ExporterNoNameMatch) {
   Inputs.Code = R"cpp(
 #include "exporter/foo.h"
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
index e10ac3f46e2e9..b1e001834db5a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
@@ -15,3 +15,5 @@ std::string HelloString;
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: no header providing "std::string" 
is directly included [misc-include-cleaner]
 int FooBarResult = foobar();
 // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: no header providing "foobar" is 
directly included [misc-include-cleaner]
+
+void log2() {}

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


[clang-tools-extra] [clang-tidy] fix false positives for the functions with the same name as standard library functions in misc-include-cleaner (PR #94923)

2024-06-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes

Fixes: #93335
For decl with body, we should provide physical locations also. Because it may 
be the function which have the same name as std library.

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


4 Files Affected:

- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp (+6-2) 
- (modified) clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp 
(+11) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp (+2) 


``diff
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3f0d25ec8c752..8c78d872b9a1a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -286,6 +286,10 @@ Changes in existing checks
   Additionally, the option `UseHeaderFileExtensions` is removed, so that the
   check uses the `HeaderFileExtensions` option unconditionally.
 
+- Improved :doc:`misc-include-cleaner
+  ` check by avoiding false positives 
for
+  the functions with the same name as standard library functions.
+
 - Improved :doc:`misc-unused-using-decls
   ` check by replacing the local
   option `HeaderFileExtensions` by the global option of the same name.
diff --git a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp 
b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
index 78e783a62eb27..9148d36a5038f 100644
--- a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
+++ b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
@@ -14,6 +14,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -40,8 +41,11 @@ Hints declHints(const Decl *D) {
 std::vector> locateDecl(const Decl &D) {
   std::vector> Result;
   // FIXME: Should we also provide physical locations?
-  if (auto SS = tooling::stdlib::Recognizer()(&D))
-return {{*SS, Hints::CompleteSymbol}};
+  if (auto SS = tooling::stdlib::Recognizer()(&D)) {
+Result.push_back({*SS, Hints::CompleteSymbol});
+if (!D.hasBody())
+  return Result;
+  }
   // FIXME: Signal foreign decls, e.g. a forward declaration not owned by a
   // library. Some useful signals could be derived by checking the DeclContext.
   // Most incidental forward decls look like:
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index 07302142a13e3..fdcbf25fd628c 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -628,6 +628,17 @@ TEST_F(HeadersForSymbolTest, StandardHeaders) {
tooling::stdlib::Header::named("")));
 }
 
+TEST_F(HeadersForSymbolTest, NonStandardHeaders) {
+  Inputs.Code = "void assert() {}";
+  buildAST();
+  EXPECT_THAT(
+  headersFor("assert"),
+  // Respect the ordering from the stdlib mapping.
+  UnorderedElementsAre(physicalHeader("input.mm"),
+   tooling::stdlib::Header::named(""),
+   tooling::stdlib::Header::named("")));
+}
+
 TEST_F(HeadersForSymbolTest, ExporterNoNameMatch) {
   Inputs.Code = R"cpp(
 #include "exporter/foo.h"
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
index e10ac3f46e2e9..b1e001834db5a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
@@ -15,3 +15,5 @@ std::string HelloString;
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: no header providing "std::string" 
is directly included [misc-include-cleaner]
 int FooBarResult = foobar();
 // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: no header providing "foobar" is 
directly included [misc-include-cleaner]
+
+void log2() {}

``




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


[clang-tools-extra] [clang-tidy] fix false positives for the functions with the same name as standard library functions in misc-include-cleaner (PR #94923)

2024-06-09 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/94923

>From e467b03cc120eedc580c185232f000e0d8aa0cc7 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 10 Jun 2024 09:04:27 +0800
Subject: [PATCH] [clang-tidy] fix false positives for the functions with the
 same name as standard library functions in misc-include-cleaner

Fixes: #93335
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../include-cleaner/lib/LocateSymbol.cpp  |  8 ++--
 .../include-cleaner/unittests/FindHeadersTest.cpp | 11 +++
 .../test/clang-tidy/checkers/misc/include-cleaner.cpp |  2 ++
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3f0d25ec8c752..8c78d872b9a1a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -286,6 +286,10 @@ Changes in existing checks
   Additionally, the option `UseHeaderFileExtensions` is removed, so that the
   check uses the `HeaderFileExtensions` option unconditionally.
 
+- Improved :doc:`misc-include-cleaner
+  ` check by avoiding false positives 
for
+  the functions with the same name as standard library functions.
+
 - Improved :doc:`misc-unused-using-decls
   ` check by replacing the local
   option `HeaderFileExtensions` by the global option of the same name.
diff --git a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp 
b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
index 78e783a62eb27..9148d36a5038f 100644
--- a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
+++ b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
@@ -14,6 +14,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -40,8 +41,11 @@ Hints declHints(const Decl *D) {
 std::vector> locateDecl(const Decl &D) {
   std::vector> Result;
   // FIXME: Should we also provide physical locations?
-  if (auto SS = tooling::stdlib::Recognizer()(&D))
-return {{*SS, Hints::CompleteSymbol}};
+  if (auto SS = tooling::stdlib::Recognizer()(&D)) {
+Result.push_back({*SS, Hints::CompleteSymbol});
+if (!D.hasBody())
+  return Result;
+  }
   // FIXME: Signal foreign decls, e.g. a forward declaration not owned by a
   // library. Some useful signals could be derived by checking the DeclContext.
   // Most incidental forward decls look like:
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index 07302142a13e3..fdcbf25fd628c 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -628,6 +628,17 @@ TEST_F(HeadersForSymbolTest, StandardHeaders) {
tooling::stdlib::Header::named("")));
 }
 
+TEST_F(HeadersForSymbolTest, NonStandardHeaders) {
+  Inputs.Code = "void assert() {}";
+  buildAST();
+  EXPECT_THAT(
+  headersFor("assert"),
+  // Respect the ordering from the stdlib mapping.
+  UnorderedElementsAre(physicalHeader("input.mm"),
+   tooling::stdlib::Header::named(""),
+   tooling::stdlib::Header::named("")));
+}
+
 TEST_F(HeadersForSymbolTest, ExporterNoNameMatch) {
   Inputs.Code = R"cpp(
 #include "exporter/foo.h"
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
index e10ac3f46e2e9..b1e001834db5a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
@@ -15,3 +15,5 @@ std::string HelloString;
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: no header providing "std::string" 
is directly included [misc-include-cleaner]
 int FooBarResult = foobar();
 // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: no header providing "foobar" is 
directly included [misc-include-cleaner]
+
+void log2() {}

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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

2024-06-09 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/94560

>From 624e74b3066930a5a2bb15d6c0b2ddb4f94d3b79 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Thu, 6 Jun 2024 10:44:57 +0800
Subject: [PATCH 1/4] fix incorrectly indents lambda trailing return

---
 clang/lib/Format/ContinuationIndenter.cpp |  5 +
 clang/unittests/Format/FormatTest.cpp | 25 +++
 2 files changed, 30 insertions(+)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 6b9fbfe0ebf53..630a4ebff9843 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1457,6 +1457,11 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   !Current.isOneOf(tok::colon, tok::comment)) {
 return ContinuationIndent;
   }
+  if (Style.isCpp() && Current.is(tok::arrow) &&
+  Previous.isOneOf(tok::kw_noexcept, tok::kw_mutable, tok::kw_constexpr,
+   tok::kw_consteval, tok::kw_static)) {
+return ContinuationIndent;
+  }
   if (Current.is(TT_ProtoExtensionLSquare))
 return CurrentState.Indent;
   if (Current.isBinaryOperator() && CurrentState.UnindentOperator) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 4e427268fb82a..d117efc06c2a7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -22858,6 +22858,31 @@ TEST_F(FormatTest, FormatsLambdas) {
   "  //\n"
   "});");
 
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n)\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}");
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n) noexcept\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}");
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n) constexpr\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}");
+
   FormatStyle DoNotMerge = getLLVMStyle();
   DoNotMerge.AllowShortLambdasOnASingleLine = FormatStyle::SLS_None;
   verifyFormat("auto c = []() {\n"

>From ec319435d82f1a815206eeb51a8e6e09c5d811fe Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Fri, 7 Jun 2024 09:18:26 +0800
Subject: [PATCH 2/4] address CR issue

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

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 630a4ebff9843..9206344490b53 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1457,7 +1457,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   !Current.isOneOf(tok::colon, tok::comment)) {
 return ContinuationIndent;
   }
-  if (Style.isCpp() && Current.is(tok::arrow) &&
+  if (Style.isCpp() && Current.is(TT_TrailingReturnArrow) &&
   Previous.isOneOf(tok::kw_noexcept, tok::kw_mutable, tok::kw_constexpr,
tok::kw_consteval, tok::kw_static)) {
 return ContinuationIndent;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index d117efc06c2a7..9759d58c718b5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -22861,27 +22861,30 @@ TEST_F(FormatTest, FormatsLambdas) {
   verifyFormat("int main() {\n"
"  very_long_function_name_yes_it_is_really_long(\n"
"  [](auto n)\n"
-   "  -> std::unordered_map {\n"
+   "  -> std::unordered_map {\n"
"really_do_something();\n"
"  });\n"
-   "}");
+   "}",
+   getLLVMStyleWithColumns(60));
   verifyFormat("int main() {\n"
"  very_long_function_name_yes_it_is_really_long(\n"
"  [](auto n) noexcept\n"
-   "  -> std::unordered_map {\n"
+   "  -> std::unordered_map {\n"
"really_do_something();\n"
"  });\n"
-   "}");
+   "}",
+   getLLVMStyleWithColumns(60));
   verifyFormat("int main() {\n"
"  very_long_function_name_yes_it_is_really_long(\n"
"  [](auto n) constexpr\n"
-   "  -> std::unordered_map {\

[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

2024-06-09 Thread via cfe-commits


@@ -22858,6 +22858,36 @@ TEST_F(FormatTest, FormatsLambdas) {
   "  //\n"
   "});");
 
+  FormatStyle LLVMStyle = getLLVMStyleWithColumns(60);
+
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n)\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}",
+   LLVMStyle);
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n) noexcept\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}",
+   LLVMStyle);

c8ef wrote:

Fixed.

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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

2024-06-09 Thread via cfe-commits


@@ -22858,6 +22858,36 @@ TEST_F(FormatTest, FormatsLambdas) {
   "  //\n"
   "});");
 
+  FormatStyle LLVMStyle = getLLVMStyleWithColumns(60);
+
+  verifyFormat("int main() {\n"
+   "  very_long_function_name_yes_it_is_really_long(\n"
+   "  [](auto n)\n"
+   "  -> std::unordered_map {\n"
+   "really_do_something();\n"
+   "  });\n"
+   "}",
+   LLVMStyle);

c8ef wrote:

Fixed.

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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

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

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


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


[clang-tools-extra] [clangd] Make it possible to enable misc-const-correctness clang-tidy check (PR #94920)

2024-06-09 Thread Nathan Ridge via cfe-commits

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

Thanks!

I will wait a couple of days before merging, in case @kadircet has any 
objection :)

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


  1   2   >