[clang] [Clang] Added check for unexpanded pack in attribute [[assume]] (PR #91841)

2024-05-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Azmat Yusuf (azmat-y)


Changes

Added check for unexpanded parameter pack in attribute [[assume]]. This solves 
#91232. 

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaStmtAttr.cpp (+5) 


``diff
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 1c84830b6ddd2..36f8ecadcfab7 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -670,6 +670,11 @@ ExprResult Sema::ActOnCXXAssumeAttr(Stmt *St, const 
ParsedAttr ,
   }
 
   auto *Assumption = A.getArgAsExpr(0);
+
+  if (DiagnoseUnexpandedParameterPack(Assumption)) {
+return ExprError();
+  }
+
   if (Assumption->getDependence() == ExprDependence::None) {
 ExprResult Res = BuildCXXAssumeExpr(Assumption, A.getAttrName(), Range);
 if (Res.isInvalid())

``




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


[clang] [Clang] Added check for unexpanded pack in attribute [[assume]] (PR #91841)

2024-05-10 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/91841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Added check for unexpanded pack in attribute [[assume]] (PR #91841)

2024-05-10 Thread Azmat Yusuf via cfe-commits

https://github.com/azmat-y created 
https://github.com/llvm/llvm-project/pull/91841

Added check for unexpanded parameter pack in attribute [[assume]]. This solves 
#91232. 

>From c9f0887b5af64387938e0d80a4210af296e68f31 Mon Sep 17 00:00:00 2001
From: Azmat Yusuf 
Date: Sat, 11 May 2024 09:56:02 +0530
Subject: [PATCH] [Clang] Added check for unexpanded pack in attribute
 [[assume]]

---
 clang/lib/Sema/SemaStmtAttr.cpp | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 1c84830b6ddd2..36f8ecadcfab7 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -670,6 +670,11 @@ ExprResult Sema::ActOnCXXAssumeAttr(Stmt *St, const 
ParsedAttr ,
   }
 
   auto *Assumption = A.getArgAsExpr(0);
+
+  if (DiagnoseUnexpandedParameterPack(Assumption)) {
+return ExprError();
+  }
+
   if (Assumption->getDependence() == ExprDependence::None) {
 ExprResult Res = BuildCXXAssumeExpr(Assumption, A.getAttrName(), Range);
 if (Res.isInvalid())

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


[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)

2024-05-10 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/91101

>From 33b4371e5285bea629eb51ed69b5664ea17c0383 Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Sat, 4 May 2024 18:12:34 -0500
Subject: [PATCH 1/3] [Inliner] Add tests for propagating more parameter
 attributes; NFC

---
 .../Inline/access-attributes-prop.ll  | 116 +-
 1 file changed, 114 insertions(+), 2 deletions(-)

diff --git a/llvm/test/Transforms/Inline/access-attributes-prop.ll 
b/llvm/test/Transforms/Inline/access-attributes-prop.ll
index ffd31fbe8ae10..125d3f963e133 100644
--- a/llvm/test/Transforms/Inline/access-attributes-prop.ll
+++ b/llvm/test/Transforms/Inline/access-attributes-prop.ll
@@ -46,7 +46,6 @@ define dso_local void @foo3_writable(ptr %p) {
   ret void
 }
 
-
 define dso_local void @foo1_bar_aligned64_deref512(ptr %p) {
 ; CHECK-LABEL: define {{[^@]+}}@foo1_bar_aligned64_deref512
 ; CHECK-SAME: (ptr [[P:%.*]]) {
@@ -322,6 +321,16 @@ define void @prop_param_nonnull_and_align(ptr %p) {
   ret void
 }
 
+define void @prop_param_nofree_and_align(ptr %p) {
+; CHECK-LABEL: define {{[^@]+}}@prop_param_nofree_and_align
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:call void @bar1(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+  call void @foo1(ptr nofree align 32 %p)
+  ret void
+}
+
 define void @prop_param_deref_align_no_update(ptr %p) {
 ; CHECK-LABEL: define {{[^@]+}}@prop_param_deref_align_no_update
 ; CHECK-SAME: (ptr [[P:%.*]]) {
@@ -528,7 +537,6 @@ define void @prop_no_conflict_writable(ptr %p) {
   ret void
 }
 
-
 define void @prop_no_conflict_writable2(ptr %p) {
 ; CHECK-LABEL: define {{[^@]+}}@prop_no_conflict_writable2
 ; CHECK-SAME: (ptr [[P:%.*]]) {
@@ -539,3 +547,107 @@ define void @prop_no_conflict_writable2(ptr %p) {
   ret void
 }
 
+declare void @bar4(i32)
+
+define dso_local void @foo4_range_0_10(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@foo4_range_0_10
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar4(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @bar4(i32 range(i32 0, 10) %v)
+  ret void
+}
+
+define dso_local void @foo4_2_range_0_10(i32 range(i32 0, 10) %v) {
+; CHECK-LABEL: define {{[^@]+}}@foo4_2_range_0_10
+; CHECK-SAME: (i32 range(i32 0, 10) [[V:%.*]]) {
+; CHECK-NEXT:call void @bar4(i32 [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @bar4(i32 %v)
+  ret void
+}
+
+
+define dso_local void @foo4(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@foo4
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar4(i32 [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @bar4(i32 %v)
+  ret void
+}
+
+
+
+define void @prop_range_empty_intersect(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_empty_intersect
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar4(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_range_0_10(i32 range(i32 11, 50) %v)
+  ret void
+}
+
+define void @prop_range_empty(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_empty
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar4(i32 [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4(i32 range(i32 1, 0) %v)
+  ret void
+}
+
+define void @prop_range_empty_with_intersect(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_empty_with_intersect
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar4(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_range_0_10(i32 range(i32 1, 0) %v)
+  ret void
+}
+
+define void @prop_range_intersect1(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_intersect1
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar4(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_range_0_10(i32 range(i32 0, 9) %v)
+  ret void
+}
+
+define void @prop_range_intersect2(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_intersect2
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar4(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_range_0_10(i32 range(i32 1, 9) %v)
+  ret void
+}
+
+define void @prop_range_intersect3(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_intersect3
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar4(i32 [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_2_range_0_10(i32 range(i32 0, 11) %v)
+  ret void
+}
+
+define void @prop_range_direct(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_direct
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar4(i32 [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4(i32 range(i32 1, 11) %v)
+  ret void
+}

>From 79a445ea7aed06a78c1dfc9e39a4466af15b8be2 Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Sat, 4 May 2024 13:57:45 -0500
Subject: [PATCH 2/3] [Inliner] Propagate more attributes to params when
 inlining

Add support for propagating:
- `derefereancable`
- `derefereancable_or_null`
- `align`
- 

[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)

2024-05-10 Thread via cfe-commits

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


[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)

2024-05-10 Thread via cfe-commits


@@ -1352,20 +1352,43 @@ static void AddParamAndFnBasicAttributes(const CallBase 
,
   auto  = CalledFunction->getContext();
 
   // Collect valid attributes for all params.
-  SmallVector ValidParamAttrs;
+  SmallVector ValidObjParamAttrs, ValidExactParamAttrs;
   bool HasAttrToPropagate = false;
 
   for (unsigned I = 0, E = CB.arg_size(); I < E; ++I) {
-ValidParamAttrs.emplace_back(AttrBuilder{CB.getContext()});
+ValidObjParamAttrs.emplace_back(AttrBuilder{CB.getContext()});
+ValidExactParamAttrs.emplace_back(AttrBuilder{CB.getContext()});
 // Access attributes can be propagated to any param with the same 
underlying
 // object as the argument.
 if (CB.paramHasAttr(I, Attribute::ReadNone))
-  ValidParamAttrs.back().addAttribute(Attribute::ReadNone);
+  ValidObjParamAttrs.back().addAttribute(Attribute::ReadNone);
 if (CB.paramHasAttr(I, Attribute::ReadOnly))
-  ValidParamAttrs.back().addAttribute(Attribute::ReadOnly);
+  ValidObjParamAttrs.back().addAttribute(Attribute::ReadOnly);
 if (CB.paramHasAttr(I, Attribute::WriteOnly))
-  ValidParamAttrs.back().addAttribute(Attribute::WriteOnly);
-HasAttrToPropagate |= ValidParamAttrs.back().hasAttributes();
+  ValidObjParamAttrs.back().addAttribute(Attribute::WriteOnly);
+
+// Attributes we can only propagate if the exact parameter is forwarded.
+
+// We can propagate both poison generating an UB generating attributes
+// without any extra checks. The only attribute that is tricky to propagate
+// is `noundef` (skipped for now) as that can create new UB where previous
+// behavior was just using a poison value.
+if (auto DerefBytes = CB.getParamDereferenceableBytes(I))
+  ValidExactParamAttrs.back().addDereferenceableAttr(DerefBytes);

goldsteinn wrote:

Some opposed to this. The current code is a bit verbose, but think that 
aliasing is typically harder to read/more bug prone. If you feel strongly Ill 
change though.

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


[clang] [lldb] [llvm] [BOLT] Set entry counts in BAT YAML profile (PR #91775)

2024-05-10 Thread Amir Ayupov via cfe-commits

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


[clang] [lldb] [llvm] [BOLT] Set entry counts in BAT YAML profile (PR #91775)

2024-05-10 Thread Amir Ayupov via cfe-commits

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


[clang] [lldb] [llvm] [BOLT] Use disambiguated local names in BAT YAML (PR #91773)

2024-05-10 Thread Amir Ayupov via cfe-commits

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


[clang] [lldb] [llvm] [BOLT] Use disambiguated local names in BAT YAML (PR #91773)

2024-05-10 Thread Amir Ayupov via cfe-commits

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


[clang-tools-extra] 3676b09 - [clang-tidy] `readability-simplify-boolean-expr` avoid to warn expression expand from macro when ``IgnoreMacro`` option is enabled. (#91757)

2024-05-10 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-05-11T12:15:24+08:00
New Revision: 3676b0945c800e3105f648d178b331953246716a

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

LOG: [clang-tidy] `readability-simplify-boolean-expr` avoid to warn expression 
expand from macro when ``IgnoreMacro`` option is enabled. (#91757)

Fixes: #91487

Added: 


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

clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index edb67614bd558..fd4730d9c8b9c 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "SimplifyBooleanExprCheck.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/Support/SaveAndRestore.h"
@@ -280,9 +281,8 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
 if (!S) {
   return true;
 }
-if (Check->IgnoreMacros && S->getBeginLoc().isMacroID()) {
+if (Check->canBeBypassed(S))
   return false;
-}
 if (!shouldIgnore(S))
   StmtStack.push_back(S);
 return true;
@@ -513,17 +513,23 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
 return true;
   }
 
-  static bool isUnaryLNot(const Expr *E) {
-return isa(E) &&
+  bool isExpectedUnaryLNot(const Expr *E) {
+return !Check->canBeBypassed(E) && isa(E) &&
cast(E)->getOpcode() == UO_LNot;
   }
 
+  bool isExpectedBinaryOp(const Expr *E) {
+const auto *BinaryOp = dyn_cast(E);
+return !Check->canBeBypassed(E) && BinaryOp && BinaryOp->isLogicalOp() &&
+   BinaryOp->getType()->isBooleanType();
+  }
+
   template 
   static bool checkEitherSide(const BinaryOperator *BO, Functor Func) {
 return Func(BO->getLHS()) || Func(BO->getRHS());
   }
 
-  static bool nestedDemorgan(const Expr *E, unsigned NestingLevel) {
+  bool nestedDemorgan(const Expr *E, unsigned NestingLevel) {
 const auto *BO = 
dyn_cast(E->IgnoreUnlessSpelledInSource());
 if (!BO)
   return false;
@@ -539,15 +545,13 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
   return true;
 case BO_LAnd:
 case BO_LOr:
-  if (checkEitherSide(BO, isUnaryLNot))
-return true;
-  if (NestingLevel) {
-if (checkEitherSide(BO, [NestingLevel](const Expr *E) {
-  return nestedDemorgan(E, NestingLevel - 1);
-}))
-  return true;
-  }
-  return false;
+  return checkEitherSide(
+ BO,
+ [this](const Expr *E) { return isExpectedUnaryLNot(E); }) ||
+ (NestingLevel &&
+  checkEitherSide(BO, [this, NestingLevel](const Expr *E) {
+return nestedDemorgan(E, NestingLevel - 1);
+  }));
 default:
   return false;
 }
@@ -556,19 +560,19 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
   bool TraverseUnaryOperator(UnaryOperator *Op) {
 if (!Check->SimplifyDeMorgan || Op->getOpcode() != UO_LNot)
   return Base::TraverseUnaryOperator(Op);
-Expr *SubImp = Op->getSubExpr()->IgnoreImplicit();
-auto *Parens = dyn_cast(SubImp);
-auto *BinaryOp =
-Parens
-? dyn_cast(Parens->getSubExpr()->IgnoreImplicit())
-: dyn_cast(SubImp);
-if (!BinaryOp || !BinaryOp->isLogicalOp() ||
-!BinaryOp->getType()->isBooleanType())
+const Expr *SubImp = Op->getSubExpr()->IgnoreImplicit();
+const auto *Parens = dyn_cast(SubImp);
+const Expr *SubExpr =
+Parens ? Parens->getSubExpr()->IgnoreImplicit() : SubImp;
+if (!isExpectedBinaryOp(SubExpr))
   return Base::TraverseUnaryOperator(Op);
+const auto *BinaryOp = cast(SubExpr);
 if (Check->SimplifyDeMorganRelaxed ||
-checkEitherSide(BinaryOp, isUnaryLNot) ||
-checkEitherSide(BinaryOp,
-[](const Expr *E) { return nestedDemorgan(E, 1); })) {
+checkEitherSide(
+BinaryOp,
+[this](const Expr *E) { return isExpectedUnaryLNot(E); }) ||
+checkEitherSide(
+BinaryOp, [this](const Expr *E) { return nestedDemorgan(E, 1); })) 
{
   if (Check->reportDeMorgan(Context, Op, BinaryOp, 

[clang-tools-extra] [clang-tidy] `readability-simplify-boolean-expr` avoid to warn expression expand from macro when ``IgnoreMacro`` option is enabled. (PR #91757)

2024-05-10 Thread Congcong Cai via cfe-commits

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


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-05-10 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@sam-mccall @bgra8 @ericniebler I believe this MR should fix your issues: 
https://github.com/llvm/llvm-project/pull/91833

Can you double check?

You might consider applying https://github.com/llvm/llvm-project/pull/91837,
since that is stacked on that and will revert the default back to enabling 
relaxed matching by default. Otherwise, you have to compile with 
`-frelaxed-template-template-args`.

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


[clang] [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (PR #91628)

2024-05-10 Thread Younan Zhang via cfe-commits


@@ -2583,11 +2580,27 @@ struct ConvertConstructorToDeductionGuideTransform {
 
 //-- The types of the function parameters are those of the constructor.
 for (auto *OldParam : TL.getParams()) {
-  ParmVarDecl *NewParam =
-  transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
-  if (NestedPattern && NewParam)
+  ParmVarDecl *NewParam = OldParam;
+  // Given
+  //   template  struct C {
+  // template  struct D {
+  //   template  D(U, V);
+  // };
+  //   };
+  // First, transform all the references to template parameters that are
+  // defined outside of the surrounding class template. That is T in the
+  // above example.
+  if (NestedPattern) {
 NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs,
   MaterializedTypedefs);
+if (!NewParam)
+  return QualType();
+  }
+  // Then, transform all the references to template parameters that are
+  // defined at the class template and the constructor. In this example,
+  // they're U and V, respectively.
+  NewParam =
+  transformFunctionTypeParam(NewParam, Args, MaterializedTypedefs);

zyn0217 wrote:

@antangelo : thanks for the explanation. I was considering if we can reuse the 
`transformTemplateTypeParam` stuff instead of a `TemplateDeclInstantiator` (we 
can make the constraint evaluation opt-in in that function; I presumed this 
would behave like what `setEvaluateConstraints(false)` does.), but doing that 
doesn't look like it would simplify the logic here significantly, so I 
hesitated to do so.

The other part `Depth1Args` also prevents us from combining these substitution 
into one call - I think I have to go through it further. Anyhow, this shouldn't 
block a backport.

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


[clang] [clang] Allow pack expansions when partial ordering against template template parameters (PR #91833)

2024-05-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

When partial ordering alias templates against template template parameters, 
allow pack expansions when the alias has a fixed-size parameter list.

These expansions were generally disallowed by proposed resolution for CWG1430.

By previously diagnosing these when checking template template parameters, we 
would be too strict in trying to prevent any potential invalid use.

This flows against the more general idea that template template parameters are 
weakly typed, that we would rather allow an argument that might be possibly 
misused, and only diagnose the actual misuses during instantiation.

Since this interaction between P0522R0 and CWG1430 is also a backwards-compat 
breaking change, we implement provisional wording to allow these.

Fixes https://github.com/llvm/llvm-project/issues/62529

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


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Sema/Sema.h (+7-1) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+9-3) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+3-1) 
- (renamed) clang/test/SemaTemplate/temp_arg_template_p0522.cpp (+10-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c5dcc59c7016..ddc5d5ff16a34 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -707,6 +707,7 @@ Bug Fixes to C++ Support
   initialized, rather than evaluating them as a part of the larger manifestly 
constant evaluated
   expression.
 - Fix a bug in access control checking due to dealyed checking of friend 
declaration. Fixes (#GH12361).
+- When partial ordering alias templates against template template parameters, 
allow pack expansions when the alias has a fixed-size parameter list. Fixes 
(#GH62529).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4efd3878e861b..3fc59488243e5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9216,6 +9216,12 @@ class Sema final : public SemaBase {
   /// receive true if the cause for the error is the associated constraints of
   /// the template not being satisfied by the template arguments.
   ///
+  /// \param PartialOrderTTP If true, assume these template arguments are
+  /// the injected template arguments for a template template parameter.
+  /// This will relax the requirement that all it's possible uses are valid.
+  /// TTP checking is loose, and assumes that invalid uses will be diagnosed
+  /// during instantiation.
+  ///
   /// \returns true if an error occurred, false otherwise.
   bool CheckTemplateArgumentList(
   TemplateDecl *Template, SourceLocation TemplateLoc,
@@ -9223,7 +9229,7 @@ class Sema final : public SemaBase {
   SmallVectorImpl ,
   SmallVectorImpl ,
   bool UpdateArgsWithConversions = true,
-  bool *ConstraintsNotSatisfied = nullptr);
+  bool *ConstraintsNotSatisfied = nullptr, bool PartialOrderTTP = false);
 
   bool CheckTemplateTypeArgument(
   TemplateTypeParmDecl *Param, TemplateArgumentLoc ,
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 480c0103ae335..88d0af191e6c8 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6436,7 +6436,8 @@ bool Sema::CheckTemplateArgumentList(
 TemplateArgumentListInfo , bool PartialTemplateArgs,
 SmallVectorImpl ,
 SmallVectorImpl ,
-bool UpdateArgsWithConversions, bool *ConstraintsNotSatisfied) {
+bool UpdateArgsWithConversions, bool *ConstraintsNotSatisfied,
+bool PartialOrderTTP) {
 
   if (ConstraintsNotSatisfied)
 *ConstraintsNotSatisfied = false;
@@ -6507,8 +6508,13 @@ bool Sema::CheckTemplateArgumentList(
   bool PackExpansionIntoNonPack =
   NewArgs[ArgIdx].getArgument().isPackExpansion() &&
   (!(*Param)->isTemplateParameterPack() || 
getExpandedPackSize(*Param));
-  if (PackExpansionIntoNonPack && (isa(Template) ||
-   isa(Template))) {
+  // Core issue 1430: Don't diagnose this pack expansion when partial
+  // ordering template template parameters. Some uses of the template could
+  // be valid, and invalid uses will be diagnosed later during
+  // instantiation.
+  if (PackExpansionIntoNonPack && !PartialOrderTTP &&
+  (isa(Template) ||
+   isa(Template))) {
 // Core issue 1430: we have a pack expansion as an argument to an
 // alias template, and it's not part of a parameter pack. This
 // can't be canonicalized, so reject it now.
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index fe7e35d841510..853c0e1b50619 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ 

[clang] [clang] Allow pack expansions when partial ordering against template template parameters (PR #91833)

2024-05-10 Thread Matheus Izvekov via cfe-commits

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

When partial ordering alias templates against template template parameters, 
allow pack expansions when the alias has a fixed-size parameter list.

These expansions were generally disallowed by proposed resolution for CWG1430.

By previously diagnosing these when checking template template parameters, we 
would be too strict in trying to prevent any potential invalid use.

This flows against the more general idea that template template parameters are 
weakly typed, that we would rather allow an argument that might be possibly 
misused, and only diagnose the actual misuses during instantiation.

Since this interaction between P0522R0 and CWG1430 is also a backwards-compat 
breaking change, we implement provisional wording to allow these.

Fixes https://github.com/llvm/llvm-project/issues/62529

>From 98fdfb900582cb5f69c56b5c00106dbeff238338 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 10 May 2024 23:21:22 -0300
Subject: [PATCH] [clang] Allow pack expansions when partial ordering against
 template template parameters

When partial ordering alias templates against template template parameters,
allow pack expansions when the alias has a fixed-size parameter list.

These expansions were generally disallowed by proposed resolution for CWG1430.

By previously diagnosing these when checking template template parameters, we
would be too strict in trying to prevent any potential invalid use.

This flows against the more general idea that template template parameters are
weakly typed, that we would rather allow an argument that might be possibly
misused, and only diagnose the actual misuses during instantiation.

Since this interaction between P0522R0 and CWG1430 is also a backwards-compat
breaking change, we implement provisional wording to allow these.

Fixes https://github.com/llvm/llvm-project/issues/62529
---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/include/clang/Sema/Sema.h  |  8 +++-
 clang/lib/Sema/SemaTemplate.cpp  | 12 +---
 clang/lib/Sema/SemaTemplateDeduction.cpp |  4 +++-
 ...emplate_cxx1z.cpp => temp_arg_template_p0522.cpp} | 12 ++--
 5 files changed, 30 insertions(+), 7 deletions(-)
 rename clang/test/SemaTemplate/{temp_arg_template_cxx1z.cpp => 
temp_arg_template_p0522.cpp} (91%)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c5dcc59c7016..ddc5d5ff16a34 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -707,6 +707,7 @@ Bug Fixes to C++ Support
   initialized, rather than evaluating them as a part of the larger manifestly 
constant evaluated
   expression.
 - Fix a bug in access control checking due to dealyed checking of friend 
declaration. Fixes (#GH12361).
+- When partial ordering alias templates against template template parameters, 
allow pack expansions when the alias has a fixed-size parameter list. Fixes 
(#GH62529).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4efd3878e861b..3fc59488243e5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9216,6 +9216,12 @@ class Sema final : public SemaBase {
   /// receive true if the cause for the error is the associated constraints of
   /// the template not being satisfied by the template arguments.
   ///
+  /// \param PartialOrderTTP If true, assume these template arguments are
+  /// the injected template arguments for a template template parameter.
+  /// This will relax the requirement that all it's possible uses are valid.
+  /// TTP checking is loose, and assumes that invalid uses will be diagnosed
+  /// during instantiation.
+  ///
   /// \returns true if an error occurred, false otherwise.
   bool CheckTemplateArgumentList(
   TemplateDecl *Template, SourceLocation TemplateLoc,
@@ -9223,7 +9229,7 @@ class Sema final : public SemaBase {
   SmallVectorImpl ,
   SmallVectorImpl ,
   bool UpdateArgsWithConversions = true,
-  bool *ConstraintsNotSatisfied = nullptr);
+  bool *ConstraintsNotSatisfied = nullptr, bool PartialOrderTTP = false);
 
   bool CheckTemplateTypeArgument(
   TemplateTypeParmDecl *Param, TemplateArgumentLoc ,
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 480c0103ae335..88d0af191e6c8 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6436,7 +6436,8 @@ bool Sema::CheckTemplateArgumentList(
 TemplateArgumentListInfo , bool PartialTemplateArgs,
 SmallVectorImpl ,
 SmallVectorImpl ,
-bool UpdateArgsWithConversions, bool *ConstraintsNotSatisfied) {
+bool UpdateArgsWithConversions, bool *ConstraintsNotSatisfied,
+bool PartialOrderTTP) {
 
   if (ConstraintsNotSatisfied)
 *ConstraintsNotSatisfied = false;
@@ -6507,8 

[clang] [analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. (PR #91830)

2024-05-10 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91830

>From 7773b0635aabeba769c0050e243f26008795d84b Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 10 May 2024 18:42:07 -0700
Subject: [PATCH 1/5] [analyzer] Treat bitwise_cast, std::addressof, and new as
 trivial in WebKit checkers.

---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |  7 +-
 .../Checkers/WebKit/uncounted-obj-arg.cpp | 22 +++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 3abfa4cbb295d..23d97819a8bcd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -351,7 +351,8 @@ class TrivialFunctionAnalysisVisitor
 
 if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
 Name == "WTFReportAssertionFailure" ||
-Name == "compilerFenceForCrash" || Name.find("__builtin") == 0)
+Name == "compilerFenceForCrash" || Name == "bitwise_cast" ||
+Name == "addressof" || Name.find("__builtin") == 0)
   return true;
 
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
@@ -428,6 +429,10 @@ class TrivialFunctionAnalysisVisitor
 return TrivialFunctionAnalysis::isTrivialImpl(CE->getConstructor(), Cache);
   }
 
+  bool VisitCXXNewExpr(const CXXNewExpr* NE) {
+return VisitChildren(NE);
+  }
+
   bool VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
 return Visit(ICE->getSubExpr());
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 6ca7677511d73..197b2ee8a7359 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -47,6 +47,12 @@ void isIntegralOrPointerType(T, Types... types)
 void WTFCrashWithInfoImpl(int line, const char* file, const char* function, 
int counter, unsigned long reason);
 void WTFCrashWithInfo(int line, const char* file, const char* function, int 
counter);
 
+template
+ToType bitwise_cast(FromType from);
+
+template
+T* addressof(T& arg);
+
 template
 ALWAYS_INLINE unsigned long wtfCrashArg(T* arg) { return 
reinterpret_cast(arg); }
 
@@ -234,6 +240,11 @@ class RefCounted {
   void trivial38() { v++; if (__builtin_expect(!!(number), 1)) (*number)++; }
   int trivial39() { return -v; }
   int trivial40() { return v << 2; }
+  unsigned trivial41() { v = ++s_v; return v; }
+  unsigned trivial42() { return bitwise_cast(nullptr); }
+  Number* trivial43() { return addressof(*number); }
+  Number* trivial44() { return new Number(1); }
+  ComplexNumber* trivial45() { return new ComplexNumber(); }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -312,13 +323,17 @@ class RefCounted {
   void nonTrivial16() { complex++; }
   ComplexNumber nonTrivial17() { return complex << 2; }
   ComplexNumber nonTrivial18() { return +complex; }
+  ComplexNumber* nonTrivial19() { return new ComplexNumber(complex); }
 
+  static unsigned s_v;
   unsigned v { 0 };
   Number* number { nullptr };
   ComplexNumber complex;
   Enum enumValue { Enum::Value1 };
 };
 
+unsigned RefCounted::s_v = 0;
+
 RefCounted* refCountedObj();
 
 void test()
@@ -377,6 +392,11 @@ class UnrelatedClass {
 getFieldTrivial().trivial38(); // no-warning
 getFieldTrivial().trivial39(); // no-warning
 getFieldTrivial().trivial40(); // no-warning
+getFieldTrivial().trivial41(); // no-warning
+getFieldTrivial().trivial42(); // no-warning
+getFieldTrivial().trivial43(); // no-warning
+getFieldTrivial().trivial44(); // no-warning
+getFieldTrivial().trivial45(); // no-warning
 
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
@@ -419,6 +439,8 @@ class UnrelatedClass {
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial18();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial19();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
   }
 };
 

>From f630c7233926d5512817fbda500d127ebfa0e231 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 10 May 2024 18:47:36 -0700
Subject: [PATCH 2/5] Fix formatting.

---
 .../lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp  | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 23d97819a8bcd..6a6ffa43c1323 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ 

[clang] [analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. (PR #91830)

2024-05-10 Thread Artem Dergachev via cfe-commits

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


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


[clang] [analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. (PR #91830)

2024-05-10 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91830

>From 7773b0635aabeba769c0050e243f26008795d84b Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 10 May 2024 18:42:07 -0700
Subject: [PATCH 1/4] [analyzer] Treat bitwise_cast, std::addressof, and new as
 trivial in WebKit checkers.

---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |  7 +-
 .../Checkers/WebKit/uncounted-obj-arg.cpp | 22 +++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 3abfa4cbb295d..23d97819a8bcd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -351,7 +351,8 @@ class TrivialFunctionAnalysisVisitor
 
 if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
 Name == "WTFReportAssertionFailure" ||
-Name == "compilerFenceForCrash" || Name.find("__builtin") == 0)
+Name == "compilerFenceForCrash" || Name == "bitwise_cast" ||
+Name == "addressof" || Name.find("__builtin") == 0)
   return true;
 
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
@@ -428,6 +429,10 @@ class TrivialFunctionAnalysisVisitor
 return TrivialFunctionAnalysis::isTrivialImpl(CE->getConstructor(), Cache);
   }
 
+  bool VisitCXXNewExpr(const CXXNewExpr* NE) {
+return VisitChildren(NE);
+  }
+
   bool VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
 return Visit(ICE->getSubExpr());
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 6ca7677511d73..197b2ee8a7359 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -47,6 +47,12 @@ void isIntegralOrPointerType(T, Types... types)
 void WTFCrashWithInfoImpl(int line, const char* file, const char* function, 
int counter, unsigned long reason);
 void WTFCrashWithInfo(int line, const char* file, const char* function, int 
counter);
 
+template
+ToType bitwise_cast(FromType from);
+
+template
+T* addressof(T& arg);
+
 template
 ALWAYS_INLINE unsigned long wtfCrashArg(T* arg) { return 
reinterpret_cast(arg); }
 
@@ -234,6 +240,11 @@ class RefCounted {
   void trivial38() { v++; if (__builtin_expect(!!(number), 1)) (*number)++; }
   int trivial39() { return -v; }
   int trivial40() { return v << 2; }
+  unsigned trivial41() { v = ++s_v; return v; }
+  unsigned trivial42() { return bitwise_cast(nullptr); }
+  Number* trivial43() { return addressof(*number); }
+  Number* trivial44() { return new Number(1); }
+  ComplexNumber* trivial45() { return new ComplexNumber(); }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -312,13 +323,17 @@ class RefCounted {
   void nonTrivial16() { complex++; }
   ComplexNumber nonTrivial17() { return complex << 2; }
   ComplexNumber nonTrivial18() { return +complex; }
+  ComplexNumber* nonTrivial19() { return new ComplexNumber(complex); }
 
+  static unsigned s_v;
   unsigned v { 0 };
   Number* number { nullptr };
   ComplexNumber complex;
   Enum enumValue { Enum::Value1 };
 };
 
+unsigned RefCounted::s_v = 0;
+
 RefCounted* refCountedObj();
 
 void test()
@@ -377,6 +392,11 @@ class UnrelatedClass {
 getFieldTrivial().trivial38(); // no-warning
 getFieldTrivial().trivial39(); // no-warning
 getFieldTrivial().trivial40(); // no-warning
+getFieldTrivial().trivial41(); // no-warning
+getFieldTrivial().trivial42(); // no-warning
+getFieldTrivial().trivial43(); // no-warning
+getFieldTrivial().trivial44(); // no-warning
+getFieldTrivial().trivial45(); // no-warning
 
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
@@ -419,6 +439,8 @@ class UnrelatedClass {
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial18();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial19();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
   }
 };
 

>From f630c7233926d5512817fbda500d127ebfa0e231 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 10 May 2024 18:47:36 -0700
Subject: [PATCH 2/4] Fix formatting.

---
 .../lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp  | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 23d97819a8bcd..6a6ffa43c1323 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ 

[clang] [analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. (PR #91830)

2024-05-10 Thread Artem Dergachev via cfe-commits

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

LGTM thanks!

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


[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-10 Thread Owen Pan via cfe-commits

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


[clang] e62ce1f - [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)

2024-05-10 Thread via cfe-commits

Author: Owen Pan
Date: 2024-05-10T19:27:02-07:00
New Revision: e62ce1f8842cca36eb14126d79dcca0a85bf6d36

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

LOG: [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)

Remove FormatToken::isSimpleTypeSpecifier() and call
Token::isSimpleTypeSpecifier(LangOpts) instead.

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/lib/Format/QualifierAlignmentFixer.h
clang/lib/Format/TokenAnalyzer.cpp
clang/lib/Format/TokenAnalyzer.h
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/TokenAnnotator.h
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c4eac1c99a663..c5c79dd0f883e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3858,8 +3858,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
) {
   LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
 
   LangOpts.LineComment = 1;
-  bool AlternativeOperators = Style.isCpp();
-  LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
+  LangOpts.CXXOperatorNames = Style.isCpp();
   LangOpts.Bool = 1;
   LangOpts.ObjC = 1;
   LangOpts.MicrosoftExt = 1;// To get kw___try, kw___finally.

diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index 4fb70ffac706d..85bec71ffbbc8 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,43 +34,6 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy from Sema. Put it in a common place and remove
-// duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
-}
-
 // Sorted common C++ non-keyword types.
 static SmallVector CppNonKeywordTypes = {
 "clock_t",  "int16_t",   "int32_t", "int64_t",   "int8_t",
@@ -78,15 +41,16 @@ static SmallVector CppNonKeywordTypes = {
 "uint32_t", "uint64_t",  "uint8_t", "uintptr_t",
 };
 
-bool FormatToken::isTypeName(bool IsCpp) const {
-  return is(TT_TypeName) || isSimpleTypeSpecifier() ||
+bool FormatToken::isTypeName(const LangOptions ) const {
+  const bool IsCpp = LangOpts.CXXOperatorNames;
+  return is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts) ||
  (IsCpp && is(tok::identifier) &&
   std::binary_search(CppNonKeywordTypes.begin(),
  CppNonKeywordTypes.end(), TokenText));
 }
 
-bool FormatToken::isTypeOrIdentifier(bool IsCpp) const {
-  return isTypeName(IsCpp) || isOneOf(tok::kw_auto, tok::identifier);
+bool FormatToken::isTypeOrIdentifier(const LangOptions ) const {
+  return isTypeName(LangOpts) || isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle ) const {

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 95f16fde5005f..8792f4c750748 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -684,12 +684,8 @@ struct FormatToken {
isAttribute();
   }
 
-  /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
-
-  [[nodiscard]] bool isTypeName(bool IsCpp) const;
-
-  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
+  [[nodiscard]] bool isTypeName(const LangOptions ) const;
+  [[nodiscard]] bool isTypeOrIdentifier(const LangOptions ) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index f430d3764babe..e21b5a882b777 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ 

[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-10 Thread Owen Pan via cfe-commits

owenca wrote:

> I think this will stop people introducing extra arguments to function
> 
> ...isCpp,isThis,isThat)

I meant to fix the FIXME after I had langded a8279a8bc541, but my previous 
attempts didn't quite work. Now it seems this solution will stick.

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


[clang] df88d61 - [Driver] Remove unused getInstalledDir

2024-05-10 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-05-10T19:15:17-07:00
New Revision: df88d610ab10c1e3f22d7f5daf3794158972c584

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

LOG: [Driver] Remove unused getInstalledDir

The uses have been removed by commit 2b5cd8be3af43e5aa5b76b6aeb1edd3141b803ca

Added: 


Modified: 
clang/include/clang/Driver/Driver.h

Removed: 




diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 2ffc52bcb7ad3..cc1538372d5f8 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -424,11 +424,6 @@ class Driver {
 return ClangExecutable.c_str();
   }
 
-  /// Get the path to where the clang executable was installed.
-  const char *getInstalledDir() const {
-return Dir.c_str();
-  }
-
   bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
   bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }
 



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


[clang] [clang-format] Add option to remove leading blank lines (PR #91221)

2024-05-10 Thread Owen Pan via cfe-commits

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

See https://github.com/llvm/llvm-project/pull/91221#issuecomment-2105454428.

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


[clang] [clang-format] Add option to remove leading blank lines (PR #91221)

2024-05-10 Thread Owen Pan via cfe-commits

owenca wrote:

> Should I make dropping leading blank lines the default?

We should keep leading blank lines (up to `MaxEmptyLinesToKeep`) by default as 
before.

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


[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -819,6 +819,43 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   }
 };
 
+// x86-64 UEFI target
+class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
+: public UEFITargetInfo {
+public:
+  UEFIX86_64TargetInfo(const llvm::Triple , const TargetOptions )
+  : UEFITargetInfo(Triple, Opts) {

MaskRay wrote:

Still waiting for a calling convention test

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


[clang] [clang-format] Add option to remove leading blank lines (PR #91221)

2024-05-10 Thread Owen Pan via cfe-commits

owenca wrote:

I think this is a good time to combine the `KeepEmptyLines...` options. For 
example:
```
KeepEmptyLines:
  AtStartOfBlock: true
  AtStartOfFile: false
  AtEndOfFile: true
```

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


[clang] [analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. (PR #91830)

2024-05-10 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91830

>From 7773b0635aabeba769c0050e243f26008795d84b Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 10 May 2024 18:42:07 -0700
Subject: [PATCH 1/3] [analyzer] Treat bitwise_cast, std::addressof, and new as
 trivial in WebKit checkers.

---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |  7 +-
 .../Checkers/WebKit/uncounted-obj-arg.cpp | 22 +++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 3abfa4cbb295d..23d97819a8bcd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -351,7 +351,8 @@ class TrivialFunctionAnalysisVisitor
 
 if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
 Name == "WTFReportAssertionFailure" ||
-Name == "compilerFenceForCrash" || Name.find("__builtin") == 0)
+Name == "compilerFenceForCrash" || Name == "bitwise_cast" ||
+Name == "addressof" || Name.find("__builtin") == 0)
   return true;
 
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
@@ -428,6 +429,10 @@ class TrivialFunctionAnalysisVisitor
 return TrivialFunctionAnalysis::isTrivialImpl(CE->getConstructor(), Cache);
   }
 
+  bool VisitCXXNewExpr(const CXXNewExpr* NE) {
+return VisitChildren(NE);
+  }
+
   bool VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
 return Visit(ICE->getSubExpr());
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 6ca7677511d73..197b2ee8a7359 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -47,6 +47,12 @@ void isIntegralOrPointerType(T, Types... types)
 void WTFCrashWithInfoImpl(int line, const char* file, const char* function, 
int counter, unsigned long reason);
 void WTFCrashWithInfo(int line, const char* file, const char* function, int 
counter);
 
+template
+ToType bitwise_cast(FromType from);
+
+template
+T* addressof(T& arg);
+
 template
 ALWAYS_INLINE unsigned long wtfCrashArg(T* arg) { return 
reinterpret_cast(arg); }
 
@@ -234,6 +240,11 @@ class RefCounted {
   void trivial38() { v++; if (__builtin_expect(!!(number), 1)) (*number)++; }
   int trivial39() { return -v; }
   int trivial40() { return v << 2; }
+  unsigned trivial41() { v = ++s_v; return v; }
+  unsigned trivial42() { return bitwise_cast(nullptr); }
+  Number* trivial43() { return addressof(*number); }
+  Number* trivial44() { return new Number(1); }
+  ComplexNumber* trivial45() { return new ComplexNumber(); }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -312,13 +323,17 @@ class RefCounted {
   void nonTrivial16() { complex++; }
   ComplexNumber nonTrivial17() { return complex << 2; }
   ComplexNumber nonTrivial18() { return +complex; }
+  ComplexNumber* nonTrivial19() { return new ComplexNumber(complex); }
 
+  static unsigned s_v;
   unsigned v { 0 };
   Number* number { nullptr };
   ComplexNumber complex;
   Enum enumValue { Enum::Value1 };
 };
 
+unsigned RefCounted::s_v = 0;
+
 RefCounted* refCountedObj();
 
 void test()
@@ -377,6 +392,11 @@ class UnrelatedClass {
 getFieldTrivial().trivial38(); // no-warning
 getFieldTrivial().trivial39(); // no-warning
 getFieldTrivial().trivial40(); // no-warning
+getFieldTrivial().trivial41(); // no-warning
+getFieldTrivial().trivial42(); // no-warning
+getFieldTrivial().trivial43(); // no-warning
+getFieldTrivial().trivial44(); // no-warning
+getFieldTrivial().trivial45(); // no-warning
 
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
@@ -419,6 +439,8 @@ class UnrelatedClass {
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial18();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial19();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
   }
 };
 

>From f630c7233926d5512817fbda500d127ebfa0e231 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 10 May 2024 18:47:36 -0700
Subject: [PATCH 2/3] Fix formatting.

---
 .../lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp  | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 23d97819a8bcd..6a6ffa43c1323 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ 

[clang] [analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. (PR #91830)

2024-05-10 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91830

>From 7773b0635aabeba769c0050e243f26008795d84b Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 10 May 2024 18:42:07 -0700
Subject: [PATCH 1/2] [analyzer] Treat bitwise_cast, std::addressof, and new as
 trivial in WebKit checkers.

---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |  7 +-
 .../Checkers/WebKit/uncounted-obj-arg.cpp | 22 +++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 3abfa4cbb295d..23d97819a8bcd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -351,7 +351,8 @@ class TrivialFunctionAnalysisVisitor
 
 if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
 Name == "WTFReportAssertionFailure" ||
-Name == "compilerFenceForCrash" || Name.find("__builtin") == 0)
+Name == "compilerFenceForCrash" || Name == "bitwise_cast" ||
+Name == "addressof" || Name.find("__builtin") == 0)
   return true;
 
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
@@ -428,6 +429,10 @@ class TrivialFunctionAnalysisVisitor
 return TrivialFunctionAnalysis::isTrivialImpl(CE->getConstructor(), Cache);
   }
 
+  bool VisitCXXNewExpr(const CXXNewExpr* NE) {
+return VisitChildren(NE);
+  }
+
   bool VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
 return Visit(ICE->getSubExpr());
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 6ca7677511d73..197b2ee8a7359 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -47,6 +47,12 @@ void isIntegralOrPointerType(T, Types... types)
 void WTFCrashWithInfoImpl(int line, const char* file, const char* function, 
int counter, unsigned long reason);
 void WTFCrashWithInfo(int line, const char* file, const char* function, int 
counter);
 
+template
+ToType bitwise_cast(FromType from);
+
+template
+T* addressof(T& arg);
+
 template
 ALWAYS_INLINE unsigned long wtfCrashArg(T* arg) { return 
reinterpret_cast(arg); }
 
@@ -234,6 +240,11 @@ class RefCounted {
   void trivial38() { v++; if (__builtin_expect(!!(number), 1)) (*number)++; }
   int trivial39() { return -v; }
   int trivial40() { return v << 2; }
+  unsigned trivial41() { v = ++s_v; return v; }
+  unsigned trivial42() { return bitwise_cast(nullptr); }
+  Number* trivial43() { return addressof(*number); }
+  Number* trivial44() { return new Number(1); }
+  ComplexNumber* trivial45() { return new ComplexNumber(); }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -312,13 +323,17 @@ class RefCounted {
   void nonTrivial16() { complex++; }
   ComplexNumber nonTrivial17() { return complex << 2; }
   ComplexNumber nonTrivial18() { return +complex; }
+  ComplexNumber* nonTrivial19() { return new ComplexNumber(complex); }
 
+  static unsigned s_v;
   unsigned v { 0 };
   Number* number { nullptr };
   ComplexNumber complex;
   Enum enumValue { Enum::Value1 };
 };
 
+unsigned RefCounted::s_v = 0;
+
 RefCounted* refCountedObj();
 
 void test()
@@ -377,6 +392,11 @@ class UnrelatedClass {
 getFieldTrivial().trivial38(); // no-warning
 getFieldTrivial().trivial39(); // no-warning
 getFieldTrivial().trivial40(); // no-warning
+getFieldTrivial().trivial41(); // no-warning
+getFieldTrivial().trivial42(); // no-warning
+getFieldTrivial().trivial43(); // no-warning
+getFieldTrivial().trivial44(); // no-warning
+getFieldTrivial().trivial45(); // no-warning
 
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
@@ -419,6 +439,8 @@ class UnrelatedClass {
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial18();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial19();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
   }
 };
 

>From f630c7233926d5512817fbda500d127ebfa0e231 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 10 May 2024 18:47:36 -0700
Subject: [PATCH 2/2] Fix formatting.

---
 .../lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp  | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 23d97819a8bcd..6a6ffa43c1323 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ 

[clang] [analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. (PR #91830)

2024-05-10 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 21be8182239a9c87a50071d122d5532037fd8305 
7773b0635aabeba769c0050e243f26008795d84b -- 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 23d97819a8..cb22de9d11 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -429,9 +429,7 @@ public:
 return TrivialFunctionAnalysis::isTrivialImpl(CE->getConstructor(), Cache);
   }
 
-  bool VisitCXXNewExpr(const CXXNewExpr* NE) {
-return VisitChildren(NE);
-  }
+  bool VisitCXXNewExpr(const CXXNewExpr *NE) { return VisitChildren(NE); }
 
   bool VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
 return Visit(ICE->getSubExpr());

``




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


[clang] [analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. (PR #91830)

2024-05-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes



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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+6-1) 
- (modified) clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp (+22) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 3abfa4cbb295d..23d97819a8bcd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -351,7 +351,8 @@ class TrivialFunctionAnalysisVisitor
 
 if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
 Name == "WTFReportAssertionFailure" ||
-Name == "compilerFenceForCrash" || Name.find("__builtin") == 0)
+Name == "compilerFenceForCrash" || Name == "bitwise_cast" ||
+Name == "addressof" || Name.find("__builtin") == 0)
   return true;
 
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
@@ -428,6 +429,10 @@ class TrivialFunctionAnalysisVisitor
 return TrivialFunctionAnalysis::isTrivialImpl(CE->getConstructor(), Cache);
   }
 
+  bool VisitCXXNewExpr(const CXXNewExpr* NE) {
+return VisitChildren(NE);
+  }
+
   bool VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
 return Visit(ICE->getSubExpr());
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 6ca7677511d73..197b2ee8a7359 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -47,6 +47,12 @@ void isIntegralOrPointerType(T, Types... types)
 void WTFCrashWithInfoImpl(int line, const char* file, const char* function, 
int counter, unsigned long reason);
 void WTFCrashWithInfo(int line, const char* file, const char* function, int 
counter);
 
+template
+ToType bitwise_cast(FromType from);
+
+template
+T* addressof(T& arg);
+
 template
 ALWAYS_INLINE unsigned long wtfCrashArg(T* arg) { return 
reinterpret_cast(arg); }
 
@@ -234,6 +240,11 @@ class RefCounted {
   void trivial38() { v++; if (__builtin_expect(!!(number), 1)) (*number)++; }
   int trivial39() { return -v; }
   int trivial40() { return v << 2; }
+  unsigned trivial41() { v = ++s_v; return v; }
+  unsigned trivial42() { return bitwise_cast(nullptr); }
+  Number* trivial43() { return addressof(*number); }
+  Number* trivial44() { return new Number(1); }
+  ComplexNumber* trivial45() { return new ComplexNumber(); }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -312,13 +323,17 @@ class RefCounted {
   void nonTrivial16() { complex++; }
   ComplexNumber nonTrivial17() { return complex << 2; }
   ComplexNumber nonTrivial18() { return +complex; }
+  ComplexNumber* nonTrivial19() { return new ComplexNumber(complex); }
 
+  static unsigned s_v;
   unsigned v { 0 };
   Number* number { nullptr };
   ComplexNumber complex;
   Enum enumValue { Enum::Value1 };
 };
 
+unsigned RefCounted::s_v = 0;
+
 RefCounted* refCountedObj();
 
 void test()
@@ -377,6 +392,11 @@ class UnrelatedClass {
 getFieldTrivial().trivial38(); // no-warning
 getFieldTrivial().trivial39(); // no-warning
 getFieldTrivial().trivial40(); // no-warning
+getFieldTrivial().trivial41(); // no-warning
+getFieldTrivial().trivial42(); // no-warning
+getFieldTrivial().trivial43(); // no-warning
+getFieldTrivial().trivial44(); // no-warning
+getFieldTrivial().trivial45(); // no-warning
 
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
@@ -419,6 +439,8 @@ class UnrelatedClass {
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial18();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial19();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
   }
 };
 

``




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


[clang] [analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. (PR #91830)

2024-05-10 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/91830

None

>From 7773b0635aabeba769c0050e243f26008795d84b Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 10 May 2024 18:42:07 -0700
Subject: [PATCH] [analyzer] Treat bitwise_cast, std::addressof, and new as
 trivial in WebKit checkers.

---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |  7 +-
 .../Checkers/WebKit/uncounted-obj-arg.cpp | 22 +++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 3abfa4cbb295d..23d97819a8bcd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -351,7 +351,8 @@ class TrivialFunctionAnalysisVisitor
 
 if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
 Name == "WTFReportAssertionFailure" ||
-Name == "compilerFenceForCrash" || Name.find("__builtin") == 0)
+Name == "compilerFenceForCrash" || Name == "bitwise_cast" ||
+Name == "addressof" || Name.find("__builtin") == 0)
   return true;
 
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
@@ -428,6 +429,10 @@ class TrivialFunctionAnalysisVisitor
 return TrivialFunctionAnalysis::isTrivialImpl(CE->getConstructor(), Cache);
   }
 
+  bool VisitCXXNewExpr(const CXXNewExpr* NE) {
+return VisitChildren(NE);
+  }
+
   bool VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
 return Visit(ICE->getSubExpr());
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 6ca7677511d73..197b2ee8a7359 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -47,6 +47,12 @@ void isIntegralOrPointerType(T, Types... types)
 void WTFCrashWithInfoImpl(int line, const char* file, const char* function, 
int counter, unsigned long reason);
 void WTFCrashWithInfo(int line, const char* file, const char* function, int 
counter);
 
+template
+ToType bitwise_cast(FromType from);
+
+template
+T* addressof(T& arg);
+
 template
 ALWAYS_INLINE unsigned long wtfCrashArg(T* arg) { return 
reinterpret_cast(arg); }
 
@@ -234,6 +240,11 @@ class RefCounted {
   void trivial38() { v++; if (__builtin_expect(!!(number), 1)) (*number)++; }
   int trivial39() { return -v; }
   int trivial40() { return v << 2; }
+  unsigned trivial41() { v = ++s_v; return v; }
+  unsigned trivial42() { return bitwise_cast(nullptr); }
+  Number* trivial43() { return addressof(*number); }
+  Number* trivial44() { return new Number(1); }
+  ComplexNumber* trivial45() { return new ComplexNumber(); }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -312,13 +323,17 @@ class RefCounted {
   void nonTrivial16() { complex++; }
   ComplexNumber nonTrivial17() { return complex << 2; }
   ComplexNumber nonTrivial18() { return +complex; }
+  ComplexNumber* nonTrivial19() { return new ComplexNumber(complex); }
 
+  static unsigned s_v;
   unsigned v { 0 };
   Number* number { nullptr };
   ComplexNumber complex;
   Enum enumValue { Enum::Value1 };
 };
 
+unsigned RefCounted::s_v = 0;
+
 RefCounted* refCountedObj();
 
 void test()
@@ -377,6 +392,11 @@ class UnrelatedClass {
 getFieldTrivial().trivial38(); // no-warning
 getFieldTrivial().trivial39(); // no-warning
 getFieldTrivial().trivial40(); // no-warning
+getFieldTrivial().trivial41(); // no-warning
+getFieldTrivial().trivial42(); // no-warning
+getFieldTrivial().trivial43(); // no-warning
+getFieldTrivial().trivial44(); // no-warning
+getFieldTrivial().trivial45(); // no-warning
 
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
@@ -419,6 +439,8 @@ class UnrelatedClass {
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial18();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial19();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
   }
 };
 

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


[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)

2024-05-10 Thread Vadim D. via cfe-commits

https://github.com/vvd170501 updated 
https://github.com/llvm/llvm-project/pull/87208

>From 35db92dfd0c2b43fc7afde5b093598763c4b8c89 Mon Sep 17 00:00:00 2001
From: Vadim Dudkin 
Date: Mon, 1 Apr 2024 02:26:14 +0300
Subject: [PATCH 1/4] Add config option to analyze unused system headers

---
 clang-tools-extra/clangd/Config.h |  1 +
 clang-tools-extra/clangd/ConfigCompile.cpp| 57 +++
 clang-tools-extra/clangd/ConfigFragment.h |  4 ++
 clang-tools-extra/clangd/ConfigYAML.cpp   |  4 ++
 clang-tools-extra/clangd/IncludeCleaner.cpp   | 34 +++
 clang-tools-extra/clangd/IncludeCleaner.h | 13 +
 clang-tools-extra/clangd/ParsedAST.cpp|  3 +-
 .../clangd/unittests/ConfigCompileTests.cpp   |  6 ++
 .../clangd/unittests/ConfigYAMLTests.cpp  | 15 +
 .../clangd/unittests/IncludeCleanerTests.cpp  | 15 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 11 files changed, 112 insertions(+), 45 deletions(-)

diff --git a/clang-tools-extra/clangd/Config.h 
b/clang-tools-extra/clangd/Config.h
index 4371c80a6c587..9629854abff31 100644
--- a/clang-tools-extra/clangd/Config.h
+++ b/clang-tools-extra/clangd/Config.h
@@ -114,6 +114,7 @@ struct Config {
 /// these regexes.
 struct {
   std::vector> IgnoreHeader;
+  bool AnalyzeSystemHeaders = false;
 } Includes;
   } Diagnostics;
 
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp 
b/clang-tools-extra/clangd/ConfigCompile.cpp
index 5bb2eb4a9f803..f74c870adfb73 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -572,32 +572,43 @@ struct FragmentCompiler {
 #else
 static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags;
 #endif
-auto Filters = std::make_shared>();
-for (auto  : F.IgnoreHeader) {
-  // Anchor on the right.
-  std::string AnchoredPattern = "(" + *HeaderPattern + ")$";
-  llvm::Regex CompiledRegex(AnchoredPattern, Flags);
-  std::string RegexError;
-  if (!CompiledRegex.isValid(RegexError)) {
-diag(Warning,
- llvm::formatv("Invalid regular expression '{0}': {1}",
-   *HeaderPattern, RegexError)
- .str(),
- HeaderPattern.Range);
-continue;
+std::shared_ptr> Filters;
+if (!F.IgnoreHeader.empty()) {
+  Filters = std::make_shared>();
+  for (auto  : F.IgnoreHeader) {
+// Anchor on the right.
+std::string AnchoredPattern = "(" + *HeaderPattern + ")$";
+llvm::Regex CompiledRegex(AnchoredPattern, Flags);
+std::string RegexError;
+if (!CompiledRegex.isValid(RegexError)) {
+  diag(Warning,
+   llvm::formatv("Invalid regular expression '{0}': {1}",
+ *HeaderPattern, RegexError)
+   .str(),
+   HeaderPattern.Range);
+  continue;
+}
+Filters->push_back(std::move(CompiledRegex));
   }
-  Filters->push_back(std::move(CompiledRegex));
 }
-if (Filters->empty())
+std::optional AnalyzeSystemHeaders;
+if (F.AnalyzeSystemHeaders.has_value())
+  AnalyzeSystemHeaders = **F.AnalyzeSystemHeaders;
+if (!Filters && !AnalyzeSystemHeaders.has_value())
   return;
-auto Filter = [Filters](llvm::StringRef Path) {
-  for (auto  : *Filters)
-if (Regex.match(Path))
-  return true;
-  return false;
-};
-Out.Apply.push_back([Filter](const Params &, Config ) {
-  C.Diagnostics.Includes.IgnoreHeader.emplace_back(Filter);
+Out.Apply.push_back([Filters = std::move(Filters),
+ AnalyzeSystemHeaders](const Params &, Config ) {
+  if (Filters) {
+auto Filter = [Filters](llvm::StringRef Path) {
+  for (auto  : *Filters)
+if (Regex.match(Path))
+  return true;
+  return false;
+};
+C.Diagnostics.Includes.IgnoreHeader.emplace_back(std::move(Filter));
+  }
+  if (AnalyzeSystemHeaders.has_value())
+C.Diagnostics.Includes.AnalyzeSystemHeaders = *AnalyzeSystemHeaders;
 });
   }
 
diff --git a/clang-tools-extra/clangd/ConfigFragment.h 
b/clang-tools-extra/clangd/ConfigFragment.h
index 7fa61108c78a0..ac8b88c245412 100644
--- a/clang-tools-extra/clangd/ConfigFragment.h
+++ b/clang-tools-extra/clangd/ConfigFragment.h
@@ -254,6 +254,10 @@ struct Fragment {
   /// unused or missing. These can match any suffix of the header file in
   /// question.
   std::vector> IgnoreHeader;
+
+  /// If false (default), unused system headers will be ignored.
+  /// Standard library headers are analyzed regardless of this option.
+  std::optional> AnalyzeSystemHeaders;
 };
 IncludesBlock Includes;
 
diff --git a/clang-tools-extra/clangd/ConfigYAML.cpp 
b/clang-tools-extra/clangd/ConfigYAML.cpp
index ce09af819247a..7608af4200538 100644
--- a/clang-tools-extra/clangd/ConfigYAML.cpp
+++ 

[clang] [Clang] Add support for [[msvc::noinline]] attribute. (PR #91720)

2024-05-10 Thread Xu Zhang via cfe-commits

https://github.com/simonzgx updated 
https://github.com/llvm/llvm-project/pull/91720

>From 2dd3d3385642d88d538bc37673018f1231a56b14 Mon Sep 17 00:00:00 2001
From: Xu Zhang 
Date: Fri, 10 May 2024 01:24:24 +0800
Subject: [PATCH 1/2] [Clang] Add support for [[msvc::noinline]] attribute.
 (#90941)

---
 clang/include/clang/Basic/Attr.td   | 5 -
 clang/include/clang/Basic/AttrDocs.td   | 2 ++
 clang/test/CodeGen/attr-ms-noinline.cpp | 0
 clang/test/Sema/attr-ms-noinline.cpp| 0
 4 files changed, 6 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/attr-ms-noinline.cpp
 create mode 100644 clang/test/Sema/attr-ms-noinline.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..81fcb8aba04f3 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1997,9 +1997,12 @@ def Convergent : InheritableAttr {
 def NoInline : DeclOrStmtAttr {
   let Spellings = [CustomKeyword<"__noinline__">, GCC<"noinline">,
CXX11<"clang", "noinline">, C23<"clang", "noinline">,
+   CXX11<"msvc", "noinline">, C23<"msvc", "noinline">,
Declspec<"noinline">];
   let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">,
-C23<"clang", "noinline">]>];
+C23<"clang", "noinline">,
+CXX11<"msvc", "noinline">,
+C23<"msvc", "noinline">]>];
   let Documentation = [NoInlineDocs];
   let Subjects = SubjectList<[Function, Stmt], WarnDiag,
  "functions and statements">;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f351822ac74bd..d5540f70ac927 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -597,6 +597,8 @@ spellings of the attribute are not supported on statements. 
If a statement is
 marked ``[[clang::noinline]]`` and contains calls, those calls inside the
 statement will not be inlined by the compiler.
 
+``[[msvc::noinline]]`` 
+
 ``__noinline__`` can be used as a keyword in CUDA/HIP languages. This is to
 avoid diagnostics due to usage of ``__attribute__((__noinline__))``
 with ``__noinline__`` defined as a macro as ``__attribute__((noinline))``.
diff --git a/clang/test/CodeGen/attr-ms-noinline.cpp 
b/clang/test/CodeGen/attr-ms-noinline.cpp
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/test/Sema/attr-ms-noinline.cpp 
b/clang/test/Sema/attr-ms-noinline.cpp
new file mode 100644
index 0..e69de29bb2d1d

>From 2029279c3c8fe13920f92547ddc2a5db305f Mon Sep 17 00:00:00 2001
From: Xu Zhang 
Date: Fri, 10 May 2024 17:46:40 +0800
Subject: [PATCH 2/2] add unit test

---
 clang/include/clang/Basic/AttrDocs.td   |  2 -
 clang/test/CodeGen/attr-ms-noinline.cpp | 53 
 clang/test/Sema/attr-ms-noinline.cpp| 66 +
 3 files changed, 119 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index d5540f70ac927..f351822ac74bd 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -597,8 +597,6 @@ spellings of the attribute are not supported on statements. 
If a statement is
 marked ``[[clang::noinline]]`` and contains calls, those calls inside the
 statement will not be inlined by the compiler.
 
-``[[msvc::noinline]]`` 
-
 ``__noinline__`` can be used as a keyword in CUDA/HIP languages. This is to
 avoid diagnostics due to usage of ``__attribute__((__noinline__))``
 with ``__noinline__`` defined as a macro as ``__attribute__((noinline))``.
diff --git a/clang/test/CodeGen/attr-ms-noinline.cpp 
b/clang/test/CodeGen/attr-ms-noinline.cpp
index e69de29bb2d1d..99b0a05af715d 100644
--- a/clang/test/CodeGen/attr-ms-noinline.cpp
+++ b/clang/test/CodeGen/attr-ms-noinline.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | 
FileCheck %s
+
+bool bar();
+void f(bool, bool);
+void g(bool);
+
+static int baz(int x) {
+return x * 10;
+}
+
+[[msvc::noinline]] bool noi() { }
+
+void foo(int i) {
+  [[msvc::noinline]] bar();
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR:[0-9]+]]
+  [[msvc::noinline]] i = baz(i);
+// CHECK: call noundef i32 @_ZL3bazi({{.*}}) #[[NOINLINEATTR]]
+  [[msvc::noinline]] (i = 4, bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+  [[msvc::noinline]] (void)(bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+  [[msvc::noinline]] f(bar(), bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call void @_Z1fbb({{.*}}) #[[NOINLINEATTR]]
+  [[msvc::noinline]] [] { bar(); 

[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)

2024-05-10 Thread Yingwei Zheng via cfe-commits


@@ -1383,15 +1406,54 @@ static void AddParamAndFnBasicAttributes(const CallBase 
,
   AttributeList AL = NewInnerCB->getAttributes();
   for (unsigned I = 0, E = InnerCB->arg_size(); I < E; ++I) {
 // Check if the underlying value for the parameter is an argument.
-const Value *UnderlyingV =
-getUnderlyingObject(InnerCB->getArgOperand(I));
-const Argument *Arg = dyn_cast(UnderlyingV);
-if (!Arg)
-  continue;
+const Argument *Arg = dyn_cast(InnerCB->getArgOperand(I));
+unsigned ArgNo;
+if (Arg) {
+  ArgNo = Arg->getArgNo();
+  // For dereferenceable, dereferenceable_or_null, align, etc...
+  // we don't want to propagate if the existing param has the same
+  // attribute with "better" constraints. So, only remove from the
+  // existing AL if the region of the existing param is smaller than
+  // what we can propagate. AttributeList's merge API honours the
+  // already existing attribute value so we choose the "better"
+  // attribute by removing if the existing one is worse.
+  if (AL.getParamDereferenceableBytes(I) <
+  ValidExactParamAttrs[ArgNo].getDereferenceableBytes())
+AL =
+AL.removeParamAttribute(Context, I, 
Attribute::Dereferenceable);
+  if (AL.getParamDereferenceableOrNullBytes(I) <
+  ValidExactParamAttrs[ArgNo].getDereferenceableOrNullBytes())
+AL =
+AL.removeParamAttribute(Context, I, 
Attribute::Dereferenceable);
+  if (AL.getParamAlignment(I).valueOrOne() <
+  ValidExactParamAttrs[ArgNo].getAlignment().valueOrOne())
+AL = AL.removeParamAttribute(Context, I, Attribute::Alignment);
+
+  auto ExistingRange = AL.getParamRange(I);
+  AL = AL.addParamAttributes(Context, I, ValidExactParamAttrs[ArgNo]);
+
+  // For range we use the exact intersection.
+  if (ExistingRange.has_value()) {
+if (auto NewRange = ValidExactParamAttrs[ArgNo].getRange()) {
+  auto CombinedRange = 
ExistingRange->exactIntersectWith(*NewRange);
+  if (!CombinedRange.has_value())
+CombinedRange =
+ConstantRange::getEmpty(NewRange->getBitWidth());
+  AL = AL.removeParamAttribute(Context, I, Attribute::Range);
+  AL = AL.addRangeParamAttr(Context, I, *CombinedRange);
+}
+  }
+} else {
+  const Value *UnderlyingV =

dtcxzyw wrote:

```suggestion
  // Check if the underlying value for the parameter is an argument.
  const Value *UnderlyingV =
```


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


[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)

2024-05-10 Thread Yingwei Zheng via cfe-commits


@@ -1352,20 +1352,43 @@ static void AddParamAndFnBasicAttributes(const CallBase 
,
   auto  = CalledFunction->getContext();
 
   // Collect valid attributes for all params.
-  SmallVector ValidParamAttrs;
+  SmallVector ValidObjParamAttrs, ValidExactParamAttrs;
   bool HasAttrToPropagate = false;
 
   for (unsigned I = 0, E = CB.arg_size(); I < E; ++I) {
-ValidParamAttrs.emplace_back(AttrBuilder{CB.getContext()});
+ValidObjParamAttrs.emplace_back(AttrBuilder{CB.getContext()});
+ValidExactParamAttrs.emplace_back(AttrBuilder{CB.getContext()});
 // Access attributes can be propagated to any param with the same 
underlying
 // object as the argument.
 if (CB.paramHasAttr(I, Attribute::ReadNone))
-  ValidParamAttrs.back().addAttribute(Attribute::ReadNone);
+  ValidObjParamAttrs.back().addAttribute(Attribute::ReadNone);
 if (CB.paramHasAttr(I, Attribute::ReadOnly))
-  ValidParamAttrs.back().addAttribute(Attribute::ReadOnly);
+  ValidObjParamAttrs.back().addAttribute(Attribute::ReadOnly);
 if (CB.paramHasAttr(I, Attribute::WriteOnly))
-  ValidParamAttrs.back().addAttribute(Attribute::WriteOnly);
-HasAttrToPropagate |= ValidParamAttrs.back().hasAttributes();
+  ValidObjParamAttrs.back().addAttribute(Attribute::WriteOnly);
+
+// Attributes we can only propagate if the exact parameter is forwarded.
+
+// We can propagate both poison generating an UB generating attributes
+// without any extra checks. The only attribute that is tricky to propagate
+// is `noundef` (skipped for now) as that can create new UB where previous
+// behavior was just using a poison value.
+if (auto DerefBytes = CB.getParamDereferenceableBytes(I))
+  ValidExactParamAttrs.back().addDereferenceableAttr(DerefBytes);

dtcxzyw wrote:

```suggestion
auto  = ValidExactParamAttrs.back();
if (auto DerefBytes = CB.getParamDereferenceableBytes(I))
  ExactAttr.addDereferenceableAttr(DerefBytes);
```


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


[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)

2024-05-10 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw commented:

Oops I forgot to submit my review comment :(


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


[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)

2024-05-10 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)

2024-05-10 Thread Vadim D. via cfe-commits


@@ -135,6 +135,21 @@ TEST(IncludeCleaner, GetUnusedHeaders) {
Pointee(writtenInclusion("\"dir/unused.h\"";
 }
 
+TEST(IncludeCleaner, SystemUnusedHeaders) {
+  auto TU = TestTU::withCode(R"cpp(
+#include 
+#include 
+SystemClass x;
+  )cpp");
+  TU.AdditionalFiles["system/system_header.h"] = guard("class SystemClass 
{};");
+  TU.AdditionalFiles["system/system_unused.h"] = guard("");
+  TU.ExtraArgs = {"-isystem", testPath("system")};

vvd170501 wrote:

I've copied `-isystem` from the `GetUnusedHeaders` test.
If `AnalyzeSystemHeaders` / `AnalyzeAngledIncludes` must work for inclusions of 
any type, then maybe it'd be better to test both `-I` and `-isystem`?

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


[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)

2024-05-10 Thread Vadim D. via cfe-commits


@@ -135,6 +135,21 @@ TEST(IncludeCleaner, GetUnusedHeaders) {
Pointee(writtenInclusion("\"dir/unused.h\"";
 }
 
+TEST(IncludeCleaner, SystemUnusedHeaders) {
+  auto TU = TestTU::withCode(R"cpp(
+#include 
+#include 
+SystemClass x;
+  )cpp");
+  TU.AdditionalFiles["system/system_header.h"] = guard("class SystemClass 
{};");
+  TU.AdditionalFiles["system/system_unused.h"] = guard("");
+  TU.ExtraArgs = {"-isystem", testPath("system")};
+  auto AST = TU.build();
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST, true);

vvd170501 wrote:

Isn;t this already covered by the `GetUnusedHeaders` test? There's an unused 
`` which must not present in `UnusedIncludes`.

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


[clang] 504cf55 - [InstallAPI] Pass explicit module cache to avoid permissions issues.

2024-05-10 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2024-05-10T17:17:38-07:00
New Revision: 504cf554639360525c3f746e7296a242350b2af9

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

LOG: [InstallAPI] Pass explicit module cache to avoid permissions issues.

Fixes: https://lab.llvm.org/buildbot/#/builders/192/builds/9313

Added: 


Modified: 
clang/test/InstallAPI/project-header-only-args.test
clang/tools/clang-installapi/Options.cpp

Removed: 




diff  --git a/clang/test/InstallAPI/project-header-only-args.test 
b/clang/test/InstallAPI/project-header-only-args.test
index 7147c83b0f5d4..76fecce5b4a26 100644
--- a/clang/test/InstallAPI/project-header-only-args.test
+++ b/clang/test/InstallAPI/project-header-only-args.test
@@ -1,11 +1,13 @@
 ; RUN: rm -rf %t
 ; RUN: split-file %s %t
 ; RUN: sed -e "s|DSTROOT|%/t|g" %t/inputs.json.in > %t/inputs.json
+; RUN: mkdir -p %t/modules.cache
 
 ; RUN: clang-installapi \
 ; RUN: -target arm64-apple-macos12 -install_name @rpath/libfoo.dylib \
 ; RUN: -current_version 1 -compatibility_version 1 \
 ; RUN: -Xproject -fmodules -I%t/usr/include \
+; RUN: -Xproject -fmodules-cache-path=%t/modules.cache \
 ; RUN: -F %S/Inputs/Foundation/ \
 ; RUN: -exclude-public-header %t/usr/include/public.h \
 ; RUN: -extra-project-header %t/project.h -I%t -dynamiclib \
@@ -17,6 +19,7 @@
 ; RUN: -target arm64-apple-macos12 -install_name @rpath/libfoo.dylib \
 ; RUN: -current_version 1 -compatibility_version 1 \
 ; RUN: -Xproject -fmodules -I%t/usr/include \
+; RUN: -Xproject -fmodules-cache-path=%t/modules.cache \
 ; RUN: -extra-project-header %t/project.h \
 ; RUN: -F %S/Inputs/Foundation/ \
 ; RUN: %t/inputs.json \

diff  --git a/clang/tools/clang-installapi/Options.cpp 
b/clang/tools/clang-installapi/Options.cpp
index 5396ad23620b9..53340da704fc0 100644
--- a/clang/tools/clang-installapi/Options.cpp
+++ b/clang/tools/clang-installapi/Options.cpp
@@ -299,8 +299,11 @@ bool Options::processXprojectOption(InputArgList , 
arg_iterator Curr) {
 return false;
   }
 
-  ProjectLevelArgs.push_back(NextA->getSpelling().str());
-  llvm::copy(NextA->getValues(), std::back_inserter(ProjectLevelArgs));
+  std::string ArgString = NextA->getSpelling().str();
+  for (const StringRef Val : NextA->getValues())
+ArgString += Val.str();
+
+  ProjectLevelArgs.push_back(ArgString);
   A->claim();
   NextA->claim();
 



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


[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)

2024-05-10 Thread Vadim D. via cfe-commits


@@ -572,32 +572,43 @@ struct FragmentCompiler {
 #else
 static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags;
 #endif
-auto Filters = std::make_shared>();
-for (auto  : F.IgnoreHeader) {
-  // Anchor on the right.
-  std::string AnchoredPattern = "(" + *HeaderPattern + ")$";
-  llvm::Regex CompiledRegex(AnchoredPattern, Flags);
-  std::string RegexError;
-  if (!CompiledRegex.isValid(RegexError)) {
-diag(Warning,
- llvm::formatv("Invalid regular expression '{0}': {1}",
-   *HeaderPattern, RegexError)
- .str(),
- HeaderPattern.Range);
-continue;
+std::shared_ptr> Filters;
+if (!F.IgnoreHeader.empty()) {
+  Filters = std::make_shared>();
+  for (auto  : F.IgnoreHeader) {
+// Anchor on the right.
+std::string AnchoredPattern = "(" + *HeaderPattern + ")$";
+llvm::Regex CompiledRegex(AnchoredPattern, Flags);
+std::string RegexError;
+if (!CompiledRegex.isValid(RegexError)) {
+  diag(Warning,
+   llvm::formatv("Invalid regular expression '{0}': {1}",
+ *HeaderPattern, RegexError)
+   .str(),
+   HeaderPattern.Range);
+  continue;
+}
+Filters->push_back(std::move(CompiledRegex));
   }
-  Filters->push_back(std::move(CompiledRegex));
 }
-if (Filters->empty())
+std::optional AnalyzeSystemHeaders;
+if (F.AnalyzeSystemHeaders.has_value())
+  AnalyzeSystemHeaders = **F.AnalyzeSystemHeaders;

vvd170501 wrote:

Yes, it's intentional.
`F.AnalyzeSystemHeaders` is a `std::optional>`, but the lambda 
only needs to capture a `std::optional`.
Lines 594-596 are equivalent to the following c++23 code:
```cpp
auto AnalyzeSystemHeaders = F.AnalyzeSystemHeaders.transform(
[](const auto& LocatedValue) { return *LocatedValue; }
);
```

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


[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)

2024-05-10 Thread Dan Liew via cfe-commits

delcypher wrote:

> It's not a lie, because the contents of a pointer don't contribute to the 
> size of the struct containing that pointer.

Consider this example. It tries to illustrate why putting `__counted_by()` on a 
pointer to a structs containing flexible array members doesn't make sense. 

```
struct HasFAM {
int count;
char buffer[] __counted_by(count); // This is OK
};

struct BufferOfFAMS {
int count;
struct HasFAM* fams __counted_by(count); // This is invalid
};

struct BufferOfFAMS* setup(void) {
const int numFams = 2;
const int famSizes[] = { 8, 16};

struct BufferOfFAMS *f = (struct BufferOfFAMS *)malloc(
sizeof(struct BufferOfFAMS) + (sizeof(struct HasFam *) * numFams));

f->count = numFams;

size_t famsBufferSize = 0;
for (int i=0; i < numFams; ++i) {
famsBufferSize += sizeof(struct HasFAM) + sizeof(char)* famSizes[i];
}
f->fams = (struct HasFAM*) malloc(famsBufferSize);
memset(f->fams, 0, famsBufferSize);

size_t byteOffset = 0;
for (int i=0; i < numFams; ++i) {
struct HasFAM* cur = (struct HasFAM*) (((char*)f->fams) + byteOffset);
cur->count = famSizes[i];
byteOffset = sizeof(struct HasFAM) + (sizeof(char) * famSizes[i]);
}
return f;
}

int main(void) {
// How would we compute the bounds of f::fams here??
// `sizeof(struct HasFAM) * f->count` is WRONG. It's too small but this
// is what writing `__counted_by(count)` on `HasFAM::buffer` means.
//
// It's actually
// `(sizeof(struct HasFAM) * f->count) + (sizeof(char) * (8 + 16))`
//
// This means we can't use the `__counted_by()` attribute on
// `BufferOfFAMS::fams` to compute its bounds. That's the whole
// point of the attribute.
struct BufferOfFAMS* f = setup();

// Similary doing any kind of indexing on the pointer 
// is extremely problematic for exactly the same reason.
// 
// The address is completely wrong because the offset is computed using
// `sizeof(struct HasFAM)` which won't include the array at the end.
//
// So `bogus_ptr` points to the first byte of the first `HasFAM::buffer`,
// instead of the second `struct HasFAM`.
struct HasFAM* bogus_ptr = >fams[1];
return 0;
}
```

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


[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)

2024-05-10 Thread Vadim D. via cfe-commits


@@ -572,32 +572,43 @@ struct FragmentCompiler {
 #else
 static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags;
 #endif
-auto Filters = std::make_shared>();
-for (auto  : F.IgnoreHeader) {
-  // Anchor on the right.
-  std::string AnchoredPattern = "(" + *HeaderPattern + ")$";
-  llvm::Regex CompiledRegex(AnchoredPattern, Flags);
-  std::string RegexError;
-  if (!CompiledRegex.isValid(RegexError)) {
-diag(Warning,
- llvm::formatv("Invalid regular expression '{0}': {1}",
-   *HeaderPattern, RegexError)
- .str(),
- HeaderPattern.Range);
-continue;
+std::shared_ptr> Filters;
+if (!F.IgnoreHeader.empty()) {

vvd170501 wrote:

But then if `F.IgnoreHeader` is empty, we'll be allocating and deallocating an 
unneeded vector.

It's also possible to use `if (Filters->empty() && 
!AnalyzeSystemHeaders.has_value()) return;` and check `Filters->empty()`again  
in line 601, but I wanted to remove the unneeded allocation.

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


[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)

2024-05-10 Thread Kees Cook via cfe-commits

kees wrote:


> As @apple-fcloutier @rapidsna noted this is how `-fbounds-safety` is 
> currently implemented (because its much simpler) but it is a restriction that 
> could be lifted in future by only requiring `struct bar` to be defined at the 
> point that `foo::bar` is used rather than when the `__counted_by` attribute 
> is applied. Given that this PR is allowing `__counted_by` in a new place 
> (pointers in structs) I think its reasonable for us to place restrictions on 
> that until we've proved its actually necessary to have the more complicated 
> implementation.

The main concern I have with delaying support for this is that header files 
could find themselves in a state where they could not be refactored without 
removing counted_by attributes that refer to now-incomplete structs.

For example, in Linux we've been separating structs from implementations, and 
that usually means using incomplete structs as much as possible to avoid lots 
of #includes.

So, no objection on this PR, but I think the more complete behavior needs to 
follow soonish. :)


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


[clang-tools-extra] Add option to exclude headers from clang-tidy analysis (PR #91400)

2024-05-10 Thread Congcong Cai via cfe-commits

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

LGTM

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


[clang-tools-extra] [clang-tidy] `readability-simplify-boolean-expr` avoid to warn expression expand from macro when ``IgnoreMacro`` option is enabled. (PR #91757)

2024-05-10 Thread Congcong Cai via cfe-commits

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

>From e23675eae31ed9c3cc4bbf31d3bc43b492ef5eac Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 9 May 2024 00:51:58 +0800
Subject: [PATCH 1/2] [clang-tidy] avoid false postive when ignore macro

Fixes: #91487
---
 .../readability/SimplifyBooleanExprCheck.cpp  | 61 +++
 .../readability/SimplifyBooleanExprCheck.h|  2 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +
 .../simplify-boolean-expr-macros.cpp  | 18 --
 4 files changed, 55 insertions(+), 29 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index edb67614bd558..4b4ffc3fe0074 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "SimplifyBooleanExprCheck.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/Support/SaveAndRestore.h"
@@ -280,9 +281,8 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
 if (!S) {
   return true;
 }
-if (Check->IgnoreMacros && S->getBeginLoc().isMacroID()) {
+if (Check->canBeBypassed(S))
   return false;
-}
 if (!shouldIgnore(S))
   StmtStack.push_back(S);
 return true;
@@ -513,17 +513,25 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
 return true;
   }
 
-  static bool isUnaryLNot(const Expr *E) {
-return isa(E) &&
+  static bool isExpectedUnaryLNot(SimplifyBooleanExprCheck *Check,
+  const Expr *E) {
+return !Check->canBeBypassed(E) && isa(E) &&
cast(E)->getOpcode() == UO_LNot;
   }
 
+  static bool isExpectedBinaryOp(SimplifyBooleanExprCheck *Check,
+ const Expr *E) {
+const auto *BinaryOp = dyn_cast(E);
+return !Check->canBeBypassed(E) && BinaryOp && BinaryOp->isLogicalOp() &&
+   BinaryOp->getType()->isBooleanType();
+  }
+
   template 
   static bool checkEitherSide(const BinaryOperator *BO, Functor Func) {
 return Func(BO->getLHS()) || Func(BO->getRHS());
   }
 
-  static bool nestedDemorgan(const Expr *E, unsigned NestingLevel) {
+  bool nestedDemorgan(const Expr *E, unsigned NestingLevel) {
 const auto *BO = 
dyn_cast(E->IgnoreUnlessSpelledInSource());
 if (!BO)
   return false;
@@ -539,15 +547,14 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
   return true;
 case BO_LAnd:
 case BO_LOr:
-  if (checkEitherSide(BO, isUnaryLNot))
-return true;
-  if (NestingLevel) {
-if (checkEitherSide(BO, [NestingLevel](const Expr *E) {
-  return nestedDemorgan(E, NestingLevel - 1);
-}))
-  return true;
-  }
-  return false;
+  return checkEitherSide(BO,
+ [this](const Expr *E) {
+   return isExpectedUnaryLNot(Check, E);
+ }) ||
+ (NestingLevel &&
+  checkEitherSide(BO, [this, NestingLevel](const Expr *E) {
+return nestedDemorgan(E, NestingLevel - 1);
+  }));
 default:
   return false;
 }
@@ -556,19 +563,19 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
   bool TraverseUnaryOperator(UnaryOperator *Op) {
 if (!Check->SimplifyDeMorgan || Op->getOpcode() != UO_LNot)
   return Base::TraverseUnaryOperator(Op);
-Expr *SubImp = Op->getSubExpr()->IgnoreImplicit();
-auto *Parens = dyn_cast(SubImp);
-auto *BinaryOp =
-Parens
-? dyn_cast(Parens->getSubExpr()->IgnoreImplicit())
-: dyn_cast(SubImp);
-if (!BinaryOp || !BinaryOp->isLogicalOp() ||
-!BinaryOp->getType()->isBooleanType())
+const Expr *SubImp = Op->getSubExpr()->IgnoreImplicit();
+const auto *Parens = dyn_cast(SubImp);
+const Expr *SubExpr =
+Parens ? Parens->getSubExpr()->IgnoreImplicit() : SubImp;
+if (!isExpectedBinaryOp(Check, SubExpr))
   return Base::TraverseUnaryOperator(Op);
+const auto *BinaryOp = cast(SubExpr);
 if (Check->SimplifyDeMorganRelaxed ||
-checkEitherSide(BinaryOp, isUnaryLNot) ||
-checkEitherSide(BinaryOp,
-[](const Expr *E) { return nestedDemorgan(E, 1); })) {
+checkEitherSide(
+BinaryOp,
+[this](const Expr *E) { return isExpectedUnaryLNot(Check, E); }) ||
+checkEitherSide(
+BinaryOp, [this](const Expr *E) { return nestedDemorgan(E, 1); })) 
{
   if (Check->reportDeMorgan(Context, Op, BinaryOp, !IsProcessing, parent(),
   

[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)

2024-05-10 Thread Dan Liew via cfe-commits

delcypher wrote:

> @rapidsna @delcypher @apple-fcloutier @kees:
> 
> Okay, I think I see what the complication is. Are you trying to prevent the 
> use case of someone writing something like:
> 
> ```c
> struct bar;
> 
> struct foo {
>   size_t count;
>   struct bar *ptr __counted_by(count);
> };
> ```
> 
> where `ptr` is a pointer to one large space that the user splits up into 
> `count` number of `struct bar` objects?
> 
> ```c
> struct foo *alloc_foo(size_t count) {
>   struct foo *p = malloc(sizeof(struct foo));
> 
>   p->count;
>   p->ptr = malloc(sizeof(struct bar) * count); // struct bar can't be 
> incomplete here
>   return p;
> }
> ```

With the PR in its current form we **are** preventing this code but **only** 
because `struct bar` is an incomplete type at the point the attribute is 
applied. If `struct bar` was defined at the point `struct foo` was defined then 
this would be allowed. So this restriction has nothing to do with how the user 
wants to allocate their memory. It's all about the pointee type having a 
defined size when the `__counted_by` attribute is applied.

As @apple-fcloutier @rapidsna noted this is how `-fbounds-safety` is currently 
implemented (because its much simpler) but it is a restriction that could be 
lifted in future by only requiring `struct bar` to be defined at the point that 
`foo::bar` is used rather than when the `__counted_by` attribute is applied. 
Given that this PR is allowing `__counted_by` in a new place (pointers in 
structs) I think its reasonable for us to place restrictions on that until 
we've proved its actually necessary to have the more complicated implementation.

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


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-05-10 Thread NAKAMURA Takumi via cfe-commits


@@ -190,18 +190,30 @@ class SourceMappingRegion {
 
   bool isBranch() const { return FalseCount.has_value(); }
 
+  bool isMCDCBranch() const {
+const auto *BranchParams = 
std::get_if();
+assert(BranchParams == nullptr || BranchParams->ID >= 0);
+return (BranchParams != nullptr);
+  }
+
+  const auto () const {
+return mcdc::getParams(MCDCParams);
+  }
+
   bool isMCDCDecision() const {
 const auto *DecisionParams =
 std::get_if();
-assert(!DecisionParams || DecisionParams->NumConditions > 0);
-return DecisionParams;
+assert(DecisionParams == nullptr || DecisionParams->NumConditions > 0);

chapuni wrote:

I committed 2a61eebc66c0903cf3834a520b1f975ac3cdf92b as well.

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


[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-05-10 Thread Jessica Clarke via cfe-commits


@@ -35,6 +35,8 @@ class RISCVTargetStreamer : public MCTargetStreamer {
   RISCVABI::ABI TargetABI = RISCVABI::ABI_Unknown;
   bool HasRVC = false;
   bool HasTSO = false;
+  bool HasZICFILP = false;

jrtc27 wrote:

Make the fields and methods all Zifoo

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


[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-05-10 Thread Jessica Clarke via cfe-commits


@@ -118,6 +147,19 @@ void RISCVTargetELFStreamer::finish() {
   }
 
   MCA.setELFHeaderEFlags(EFlags);
+
+  unsigned GNUNoteFlags = 0;
+
+  // check ZICFILP or ZICFISS with features

jrtc27 wrote:

Not sure this adds anything, but if it's staying please properly style it (e.g. 
start with a capital letter)

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


[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-05-10 Thread Jessica Clarke via cfe-commits


@@ -118,6 +147,19 @@ void RISCVTargetELFStreamer::finish() {
   }
 
   MCA.setELFHeaderEFlags(EFlags);
+
+  unsigned GNUNoteFlags = 0;
+
+  // check ZICFILP or ZICFISS with features
+  // TODO should we check with codegen enable ex. -mllvm

jrtc27 wrote:

This seems like it should be resolved before merging?

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


[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-05-10 Thread Jessica Clarke via cfe-commits


@@ -5283,14 +5291,21 @@ static std::string getGNUProperty(uint32_t Type, 
uint32_t DataSize,
   OS << "";
   return OS.str();
 }
+
 if (Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
-  DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_BTI, "BTI");
-  DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_PAC, "PAC");
-  DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_GCS, "GCS");
+  if (Target == ELF::EM_RISCV) {
+DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_SIMPLE, "ZICFILP");
+DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS, "ZICFISS");

jrtc27 wrote:

```suggestion
DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_SIMPLE, "Zicfilp");
DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS, "Zicfiss");
```
I assume the others are all-caps because that's what their canonical names are, 
not because that's desirable

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


[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-05-10 Thread Jessica Clarke via cfe-commits


@@ -85,6 +85,35 @@ void RISCVTargetELFStreamer::finishAttributeSection() {
   ELF::SHT_RISCV_ATTRIBUTES, AttributeSection);
 }
 
+void RISCVTargetELFStreamer::emitNoteSection(unsigned Flags) {

jrtc27 wrote:

I know this is what AArch64 calls it, but it's a very vague name that could 
cover any number of note sections. Can we do better and make ours specific to 
what it's actually doing, i.e. something about it being a GNU properties note?

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


[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-05-10 Thread Jessica Clarke via cfe-commits


@@ -5272,8 +5272,16 @@ static std::string getGNUProperty(uint32_t Type, 
uint32_t DataSize,
 return OS.str();
   case GNU_PROPERTY_AARCH64_FEATURE_1_AND:
   case GNU_PROPERTY_X86_FEATURE_1_AND:
-OS << ((Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) ? "aarch64 feature: "
-: "x86 feature: ");
+

jrtc27 wrote:

```suggestion
```

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


[clang] [Bounds-Safety] Reserve slot in SanitizerHandler enum for Bounds-Safety (PR #91032)

2024-05-10 Thread Dan Liew via cfe-commits

delcypher wrote:

@vitalybuka Ping

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


[clang] [Clang] Fix tests broken by #91811 (PR #91822)

2024-05-10 Thread via cfe-commits

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


[clang] 4198aeb - [Clang] Fix tests broken by #91811 (#91822)

2024-05-10 Thread via cfe-commits

Author: cor3ntin
Date: 2024-05-11T00:42:56+02:00
New Revision: 4198aebc96cb0236fc63e29a92d886e6a2e3fedb

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

LOG: [Clang] Fix tests broken by #91811 (#91822)

A few tests were checking for all driver flags.
We should revert this commit when we revert #91811

Added: 


Modified: 
clang/test/Driver/rewrite-legacy-objc.m
clang/test/Driver/rewrite-objc.m

Removed: 




diff  --git a/clang/test/Driver/rewrite-legacy-objc.m 
b/clang/test/Driver/rewrite-legacy-objc.m
index 413a7a7a61f05..d45fb8c405c52 100644
--- a/clang/test/Driver/rewrite-legacy-objc.m
+++ b/clang/test/Driver/rewrite-legacy-objc.m
@@ -3,11 +3,11 @@
 // TEST0: "-cc1"
 // TEST0: "-rewrite-objc"
 // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency 
instead.
-// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fmax-type-align=16"
+// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fno-relaxed-template-template-args" "-fmax-type-align=16"
 // TEST0: rewrite-legacy-objc.m"
 // RUN: %clang --target=i386-apple-macosx10.9.0 -rewrite-legacy-objc %s -o - 
-### 2>&1 | \
 // RUN:   FileCheck -check-prefix=TEST1 %s
 // RUN: %clang --target=i386-apple-macosx10.6.0 -rewrite-legacy-objc %s -o - 
-### 2>&1 | \
 // RUN:   FileCheck -check-prefix=TEST2 %s
-// TEST1: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fmax-type-align=16"
-// TEST2: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fmax-type-align=16"
+// TEST1: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fno-relaxed-template-template-args" "-fmax-type-align=16"
+// TEST2: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fno-relaxed-template-template-args" "-fmax-type-align=16"

diff  --git a/clang/test/Driver/rewrite-objc.m 
b/clang/test/Driver/rewrite-objc.m
index de3577a770df8..d19d38d8ab839 100644
--- a/clang/test/Driver/rewrite-objc.m
+++ b/clang/test/Driver/rewrite-objc.m
@@ -2,4 +2,4 @@
 // RUN:   FileCheck -check-prefix=TEST0 %s
 // TEST0: "-cc1" {{.*}} "-rewrite-objc"
 // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency 
instead.
-// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fmax-type-align=16"
+// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fno-relaxed-template-template-args" "-fmax-type-align=16"



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


[clang] Revert "Revert "[OpenMP][TR12] change property of map-type modifier."… (PR #91426)

2024-05-10 Thread via cfe-commits

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


[clang] Revert "Revert "[OpenMP][TR12] change property of map-type modifier."… (PR #91821)

2024-05-10 Thread via cfe-commits

jyu2-git wrote:

Hi @alexey-bataev, 

Sorry for bother you again.  This is just re-check in the change you review 
before.  Plus a I need remove -fsyntex-only for my test target_ast_print.cpp 
due to resent community change of e74a7a9fd79.

Thanks.
Jennifer

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


[clang] [Clang] Fix tests broken by #91811 (PR #91822)

2024-05-10 Thread Matheus Izvekov via cfe-commits

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


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


[clang] [Clang] Fix tests broken by #91811 (PR #91822)

2024-05-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: cor3ntin (cor3ntin)


Changes

A few tests were checking for all driver flags.
We should revert this commit when we revert #91811

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


2 Files Affected:

- (modified) clang/test/Driver/rewrite-legacy-objc.m (+3-3) 
- (modified) clang/test/Driver/rewrite-objc.m (+1-1) 


``diff
diff --git a/clang/test/Driver/rewrite-legacy-objc.m 
b/clang/test/Driver/rewrite-legacy-objc.m
index 413a7a7a61f05..d45fb8c405c52 100644
--- a/clang/test/Driver/rewrite-legacy-objc.m
+++ b/clang/test/Driver/rewrite-legacy-objc.m
@@ -3,11 +3,11 @@
 // TEST0: "-cc1"
 // TEST0: "-rewrite-objc"
 // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency 
instead.
-// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fmax-type-align=16"
+// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fno-relaxed-template-template-args" "-fmax-type-align=16"
 // TEST0: rewrite-legacy-objc.m"
 // RUN: %clang --target=i386-apple-macosx10.9.0 -rewrite-legacy-objc %s -o - 
-### 2>&1 | \
 // RUN:   FileCheck -check-prefix=TEST1 %s
 // RUN: %clang --target=i386-apple-macosx10.6.0 -rewrite-legacy-objc %s -o - 
-### 2>&1 | \
 // RUN:   FileCheck -check-prefix=TEST2 %s
-// TEST1: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fmax-type-align=16"
-// TEST2: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fmax-type-align=16"
+// TEST1: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fno-relaxed-template-template-args" "-fmax-type-align=16"
+// TEST2: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fno-relaxed-template-template-args" "-fmax-type-align=16"
diff --git a/clang/test/Driver/rewrite-objc.m b/clang/test/Driver/rewrite-objc.m
index de3577a770df8..d19d38d8ab839 100644
--- a/clang/test/Driver/rewrite-objc.m
+++ b/clang/test/Driver/rewrite-objc.m
@@ -2,4 +2,4 @@
 // RUN:   FileCheck -check-prefix=TEST0 %s
 // TEST0: "-cc1" {{.*}} "-rewrite-objc"
 // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency 
instead.
-// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fmax-type-align=16"
+// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fno-relaxed-template-template-args" "-fmax-type-align=16"

``




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


[clang] [Clang] Fix tests broken by #91811 (PR #91822)

2024-05-10 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/91822

A few tests were checking for all driver flags.
We should revert this commit when we revert #91811

>From f2acd718bf4e24441a214309a1896771fe6c9fc9 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sat, 11 May 2024 00:26:32 +0200
Subject: [PATCH] [Clang] Fix tests broken by #91811

A few tests were checking for all driver flags.
We should revert this commit when we revert #91811
---
 clang/test/Driver/rewrite-legacy-objc.m | 6 +++---
 clang/test/Driver/rewrite-objc.m| 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/test/Driver/rewrite-legacy-objc.m 
b/clang/test/Driver/rewrite-legacy-objc.m
index 413a7a7a61f05..d45fb8c405c52 100644
--- a/clang/test/Driver/rewrite-legacy-objc.m
+++ b/clang/test/Driver/rewrite-legacy-objc.m
@@ -3,11 +3,11 @@
 // TEST0: "-cc1"
 // TEST0: "-rewrite-objc"
 // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency 
instead.
-// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fmax-type-align=16"
+// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fno-relaxed-template-template-args" "-fmax-type-align=16"
 // TEST0: rewrite-legacy-objc.m"
 // RUN: %clang --target=i386-apple-macosx10.9.0 -rewrite-legacy-objc %s -o - 
-### 2>&1 | \
 // RUN:   FileCheck -check-prefix=TEST1 %s
 // RUN: %clang --target=i386-apple-macosx10.6.0 -rewrite-legacy-objc %s -o - 
-### 2>&1 | \
 // RUN:   FileCheck -check-prefix=TEST2 %s
-// TEST1: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fmax-type-align=16"
-// TEST2: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fmax-type-align=16"
+// TEST1: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fno-relaxed-template-template-args" "-fmax-type-align=16"
+// TEST2: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" 
"-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" 
"-fobjc-exceptions" "-fno-relaxed-template-template-args" "-fmax-type-align=16"
diff --git a/clang/test/Driver/rewrite-objc.m b/clang/test/Driver/rewrite-objc.m
index de3577a770df8..d19d38d8ab839 100644
--- a/clang/test/Driver/rewrite-objc.m
+++ b/clang/test/Driver/rewrite-objc.m
@@ -2,4 +2,4 @@
 // RUN:   FileCheck -check-prefix=TEST0 %s
 // TEST0: "-cc1" {{.*}} "-rewrite-objc"
 // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency 
instead.
-// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fmax-type-align=16"
+// TEST0: "-stack-protector" "1" "-fblocks" 
"-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" 
"-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx" 
"-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" 
"-fno-relaxed-template-template-args" "-fmax-type-align=16"

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


[clang] [clang] Fix self-capturing `__block` variables (PR #89475)

2024-05-10 Thread via cfe-commits

ille-apple wrote:

Ping :)

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


[clang] Revert "Revert "[OpenMP][TR12] change property of map-type modifier."… (PR #91821)

2024-05-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (jyu2-git)


Changes

… (#90885)"

This reverts commit eea81aa29848361eb5b24f24d2af643fdeb9adfd.

---

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


4 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+5) 
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+43-8) 
- (modified) clang/test/OpenMP/target_ast_print.cpp (+58) 
- (modified) clang/test/OpenMP/target_map_messages.cpp (+59-46) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index bc9d7cacc50b7..8316845844cb2 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1438,6 +1438,9 @@ def err_omp_decl_in_declare_simd_variant : Error<
 def err_omp_sink_and_source_iteration_not_allowd: Error<" '%0 
%select{sink:|source:}1' must be with '%select{omp_cur_iteration - 
1|omp_cur_iteration}1'">;
 def err_omp_unknown_map_type : Error<
   "incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 
'release', or 'delete'">;
+def err_omp_more_one_map_type : Error<"map type is already specified">;
+def note_previous_map_type_specified_here
+: Note<"map type '%0' is previous specified here">;
 def err_omp_unknown_map_type_modifier : Error<
   "incorrect map type modifier, expected one of: 'always', 'close', 'mapper'"
   "%select{|, 'present'|, 'present', 'iterator'}0%select{|, 'ompx_hold'}1">;
@@ -1445,6 +1448,8 @@ def err_omp_map_type_missing : Error<
   "missing map type">;
 def err_omp_map_type_modifier_missing : Error<
   "missing map type modifier">;
+def err_omp_map_modifier_specification_list : Error<
+  "empty modifier-specification-list is not allowed">;
 def err_omp_declare_simd_inbranch_notinbranch : Error<
   "unexpected '%0' clause, '%1' is specified already">;
 def err_omp_expected_clause_argument
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 18ba1185ee8de..5265d8f1922c3 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4228,13 +4228,20 @@ bool 
Parser::parseMapperModifier(SemaOpenMP::OpenMPVarListDataTy ) {
   return T.consumeClose();
 }
 
+static OpenMPMapClauseKind isMapType(Parser );
+
 /// Parse map-type-modifiers in map clause.
-/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list)
+/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] [map-type] : ] list)
 /// where, map-type-modifier ::= always | close | mapper(mapper-identifier) |
 /// present
+/// where, map-type ::= alloc | delete | from | release | to | tofrom
 bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) {
+  bool HasMapType = false;
+  SourceLocation PreMapLoc = Tok.getLocation();
+  StringRef PreMapName = "";
   while (getCurToken().isNot(tok::colon)) {
 OpenMPMapModifierKind TypeModifier = isMapModifier(*this);
+OpenMPMapClauseKind MapKind = isMapType(*this);
 if (TypeModifier == OMPC_MAP_MODIFIER_always ||
 TypeModifier == OMPC_MAP_MODIFIER_close ||
 TypeModifier == OMPC_MAP_MODIFIER_present ||
@@ -4257,6 +4264,19 @@ bool 
Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) {
 Diag(Data.MapTypeModifiersLoc.back(), diag::err_omp_missing_comma)
 << "map type modifier";
 
+} else if (getLangOpts().OpenMP >= 60 && MapKind != OMPC_MAP_unknown) {
+  if (!HasMapType) {
+HasMapType = true;
+Data.ExtraModifier = MapKind;
+MapKind = OMPC_MAP_unknown;
+PreMapLoc = Tok.getLocation();
+PreMapName = Tok.getIdentifierInfo()->getName();
+  } else {
+Diag(Tok, diag::err_omp_more_one_map_type);
+Diag(PreMapLoc, diag::note_previous_map_type_specified_here)
+<< PreMapName;
+  }
+  ConsumeToken();
 } else {
   // For the case of unknown map-type-modifier or a map-type.
   // Map-type is followed by a colon; the function returns when it
@@ -4267,8 +4287,14 @@ bool 
Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) {
 continue;
   }
   // Potential map-type token as it is followed by a colon.
-  if (PP.LookAhead(0).is(tok::colon))
-return false;
+  if (PP.LookAhead(0).is(tok::colon)) {
+if (getLangOpts().OpenMP >= 60) {
+  break;
+} else {
+  return false;
+}
+  }
+
   Diag(Tok, diag::err_omp_unknown_map_type_modifier)
   << (getLangOpts().OpenMP >= 51 ? (getLangOpts().OpenMP >= 52 ? 2 : 1)
  : 0)
@@ -4278,6 +4304,14 @@ bool 
Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) {
 if (getCurToken().is(tok::comma))
   ConsumeToken();
   }
+  if (getLangOpts().OpenMP >= 60 && !HasMapType) {
+if (!Tok.is(tok::colon)) {
+  Diag(Tok, 

[clang] Revert "Revert "[OpenMP][TR12] change property of map-type modifier."… (PR #91821)

2024-05-10 Thread via cfe-commits

https://github.com/jyu2-git created 
https://github.com/llvm/llvm-project/pull/91821

… (#90885)"

This reverts commit eea81aa29848361eb5b24f24d2af643fdeb9adfd.

>From f1b80dab94d13ef6d2425fdbae5b0ca532490584 Mon Sep 17 00:00:00 2001
From: Jennifer Yu 
Date: Tue, 7 May 2024 18:24:53 -0700
Subject: [PATCH] Revert "Revert "[OpenMP][TR12] change property of map-type
 modifier." (#90885)"

This reverts commit eea81aa29848361eb5b24f24d2af643fdeb9adfd.
---
 .../clang/Basic/DiagnosticParseKinds.td   |   5 +
 clang/lib/Parse/ParseOpenMP.cpp   |  51 +++--
 clang/test/OpenMP/target_ast_print.cpp|  58 ++
 clang/test/OpenMP/target_map_messages.cpp | 105 ++
 4 files changed, 165 insertions(+), 54 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index bc9d7cacc50b7..8316845844cb2 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1438,6 +1438,9 @@ def err_omp_decl_in_declare_simd_variant : Error<
 def err_omp_sink_and_source_iteration_not_allowd: Error<" '%0 
%select{sink:|source:}1' must be with '%select{omp_cur_iteration - 
1|omp_cur_iteration}1'">;
 def err_omp_unknown_map_type : Error<
   "incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 
'release', or 'delete'">;
+def err_omp_more_one_map_type : Error<"map type is already specified">;
+def note_previous_map_type_specified_here
+: Note<"map type '%0' is previous specified here">;
 def err_omp_unknown_map_type_modifier : Error<
   "incorrect map type modifier, expected one of: 'always', 'close', 'mapper'"
   "%select{|, 'present'|, 'present', 'iterator'}0%select{|, 'ompx_hold'}1">;
@@ -1445,6 +1448,8 @@ def err_omp_map_type_missing : Error<
   "missing map type">;
 def err_omp_map_type_modifier_missing : Error<
   "missing map type modifier">;
+def err_omp_map_modifier_specification_list : Error<
+  "empty modifier-specification-list is not allowed">;
 def err_omp_declare_simd_inbranch_notinbranch : Error<
   "unexpected '%0' clause, '%1' is specified already">;
 def err_omp_expected_clause_argument
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 18ba1185ee8de..5265d8f1922c3 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4228,13 +4228,20 @@ bool 
Parser::parseMapperModifier(SemaOpenMP::OpenMPVarListDataTy ) {
   return T.consumeClose();
 }
 
+static OpenMPMapClauseKind isMapType(Parser );
+
 /// Parse map-type-modifiers in map clause.
-/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list)
+/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] [map-type] : ] list)
 /// where, map-type-modifier ::= always | close | mapper(mapper-identifier) |
 /// present
+/// where, map-type ::= alloc | delete | from | release | to | tofrom
 bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) {
+  bool HasMapType = false;
+  SourceLocation PreMapLoc = Tok.getLocation();
+  StringRef PreMapName = "";
   while (getCurToken().isNot(tok::colon)) {
 OpenMPMapModifierKind TypeModifier = isMapModifier(*this);
+OpenMPMapClauseKind MapKind = isMapType(*this);
 if (TypeModifier == OMPC_MAP_MODIFIER_always ||
 TypeModifier == OMPC_MAP_MODIFIER_close ||
 TypeModifier == OMPC_MAP_MODIFIER_present ||
@@ -4257,6 +4264,19 @@ bool 
Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) {
 Diag(Data.MapTypeModifiersLoc.back(), diag::err_omp_missing_comma)
 << "map type modifier";
 
+} else if (getLangOpts().OpenMP >= 60 && MapKind != OMPC_MAP_unknown) {
+  if (!HasMapType) {
+HasMapType = true;
+Data.ExtraModifier = MapKind;
+MapKind = OMPC_MAP_unknown;
+PreMapLoc = Tok.getLocation();
+PreMapName = Tok.getIdentifierInfo()->getName();
+  } else {
+Diag(Tok, diag::err_omp_more_one_map_type);
+Diag(PreMapLoc, diag::note_previous_map_type_specified_here)
+<< PreMapName;
+  }
+  ConsumeToken();
 } else {
   // For the case of unknown map-type-modifier or a map-type.
   // Map-type is followed by a colon; the function returns when it
@@ -4267,8 +4287,14 @@ bool 
Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) {
 continue;
   }
   // Potential map-type token as it is followed by a colon.
-  if (PP.LookAhead(0).is(tok::colon))
-return false;
+  if (PP.LookAhead(0).is(tok::colon)) {
+if (getLangOpts().OpenMP >= 60) {
+  break;
+} else {
+  return false;
+}
+  }
+
   Diag(Tok, diag::err_omp_unknown_map_type_modifier)
   << (getLangOpts().OpenMP >= 51 ? (getLangOpts().OpenMP >= 52 ? 2 : 1)
  : 0)
@@ -4278,6 +4304,14 @@ bool 

[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)

2024-05-10 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Some older toolchains were probably contributed with a lot of 
`CmdArgs.push_back` uncovered by tests. They are not good examples to follow. 
For new toolchains, we do want all constructed `CmdArgs.push_back` to be 
covered. This allows refactoring by someone who is unfamiliar with your usage 
pattern.

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


[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)

2024-05-10 Thread Bill Wendling via cfe-commits

bwendling wrote:

@rapidsna @delcypher @apple-fcloutier @kees:

Okay, I think I see what the complication is. Are you trying to prevent the use 
case of someone writing something like:

```c
struct bar;

struct foo {
  size_t count;
  struct bar *ptr __counted_by(count);
};
```

where `ptr` is a pointer to one large space where that the user splits up into 
`count` number of `struct bar` objects?

```c
struct foo *alloc_foo(size_t count) {
  struct foo *p = malloc(sizeof(struct foo));

  p->count;
  p->ptr = malloc(sizeof(struct bar) * count); // struct bar can't be 
incomplete here
  return p;
}
```


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


[clang] [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (PR #91628)

2024-05-10 Thread via cfe-commits


@@ -2583,11 +2580,27 @@ struct ConvertConstructorToDeductionGuideTransform {
 
 //-- The types of the function parameters are those of the constructor.
 for (auto *OldParam : TL.getParams()) {
-  ParmVarDecl *NewParam =
-  transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
-  if (NestedPattern && NewParam)
+  ParmVarDecl *NewParam = OldParam;
+  // Given
+  //   template  struct C {
+  // template  struct D {
+  //   template  D(U, V);
+  // };
+  //   };
+  // First, transform all the references to template parameters that are
+  // defined outside of the surrounding class template. That is T in the
+  // above example.
+  if (NestedPattern) {
 NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs,
   MaterializedTypedefs);
+if (!NewParam)
+  return QualType();
+  }
+  // Then, transform all the references to template parameters that are
+  // defined at the class template and the constructor. In this example,
+  // they're U and V, respectively.
+  NewParam =
+  transformFunctionTypeParam(NewParam, Args, MaterializedTypedefs);

antangelo wrote:

The `TemplateDeclInstantiator` is used for that substitution to avoid 
evaluating constraints at that point. Without this, the constraint template 
argument depths on `NewParam` would be as if the parameter were at depth 0 
(instead of the nested template depth), causing a crash when evaluated later.

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


[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)

2024-05-10 Thread Bill Wendling via cfe-commits

bwendling wrote:

@apple-fcloutier:

> think that there's room to allow `__counted_by` on incomplete types so that a 
> TU where it's complete could use it (and we have use cases where that would 
> be handy), but our implementation doesn't support it at this time. This can 
> be added without disruptions at a later time. FWIW, the point of 
> bounds-checking an index is moot at least while the type is incomplete, since 
> it's an error to dereference a pointer to an incomplete type. Aside from 
> indexing, operations that would cast the pointer (such as `memset(x->foo, 0, 
> some_value)`, assuming `memset(void *__sized_by(n), int, size_t n)`) would 
> still have to be illegal when `struct foo` is incomplete because there's no 
> way to know how many bytes we have at x->foo without `sizeof(struct foo)`.

What I'm thinking is something like:

```c
a.c:
struct foo;

struct bar {
  size_t count;
  struct foo *ptr __counted_by(count);
};

struct bar *alloc_bar(size_t num_elems) {
  struct bar *p = malloc(sizeof(bar));

  p->count = num_elems;
  p->ptr = malloc(sizeof(struct foo *) * num_elems);
  return p;
}

/* later on, or in another TU */

struct foo {
  /* fields */
};

void bork(size_t num_elems) {
  struct bar *p = alloc_bar(num_elems);

  for (size_t i = 0; i < num_elems; ++i) {
p->ptr[i] = alloc_foo();
  }

  /* some use of p */
}
}
```

I was incorrect about `void *`. It's valid to cast any pointer to `void *` and 
back to the original type.

> For structs with a flexible array member, the reason is that sizeof(struct 
> bar) is a lie. How would we reconcile, for instance, a count of 1 (implying 
> there's like 4 bytes at x->bar) with a x->bar->a of 10 (implying that 
> x->bar->fam[8] is in bounds)? How do we feel that x->bar[0]->fam[0] aliases 
> with x->bar[1]->a?

It's not a lie, because the contents of a pointer don't contribute to the size 
of the struct containing that pointer.

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


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-05-10 Thread via cfe-commits

cor3ntin wrote:

We operated a partial revert here 
https://github.com/llvm/llvm-project/pull/91811
That should fix the issues in trunk while we investigate the regression more 
thoroughly 

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


[clang] [clang] Revert default behavior change of P0522R0 implementation (PR #91811)

2024-05-10 Thread via cfe-commits

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


[clang] 2d5634a - [clang] Revert default behavior change of P0522R0 implementation (#91811)

2024-05-10 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-10T23:32:34+02:00
New Revision: 2d5634a4b39d8e5497b6a67caa54049b3cfade8e

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

LOG: [clang] Revert default behavior change of P0522R0 implementation (#91811)

This partially reverts b86e0992bfa6c58be077d82d824016f590ac5d90.

Just the default is changed back, on the Driver side.
No Frontend changes.
The positive spelling of the flag is undeprecated.

No documentation changes or changelog entries because we plan to revert
this revert as soon as https://github.com/llvm/llvm-project/issues/62529
is fixed.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/frelaxed-template-template-args.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 42feb1650574e..f0cc018b6668f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7249,15 +7249,15 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables,
  options::OPT_fno_assume_unique_vtables);
 
-  // -frelaxed-template-template-args is deprecated.
-  if (Arg *A =
-  Args.getLastArg(options::OPT_frelaxed_template_template_args,
-  options::OPT_fno_relaxed_template_template_args)) {
+  // -fno-relaxed-template-template-args is deprecated.
+  if (Arg *A = Args.getLastArg(options::OPT_frelaxed_template_template_args,
+   
options::OPT_fno_relaxed_template_template_args);
+  A &&
+  A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
 D.Diag(diag::warn_drv_deprecated_arg)
 << A->getAsString(Args) << /*hasReplacement=*/false;
-if 
(A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
-  CmdArgs.push_back("-fno-relaxed-template-template-args");
-  }
+  else
+CmdArgs.push_back("-fno-relaxed-template-template-args");
 
   // -fsized-deallocation is off by default, as it is an ABI-breaking change 
for
   // most platforms.

diff  --git a/clang/test/Driver/frelaxed-template-template-args.cpp 
b/clang/test/Driver/frelaxed-template-template-args.cpp
index dd6265ba8375e..136c360276a15 100644
--- a/clang/test/Driver/frelaxed-template-template-args.cpp
+++ b/clang/test/Driver/frelaxed-template-template-args.cpp
@@ -1,5 +1,7 @@
-// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-ON %s
+// RUN: %clang -fsyntax-only -### %s 2>&1 | FileCheck --check-prefix=CHECK-DEF 
%s
+// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-ON --allow-empty %s
 // RUN: %clang -fsyntax-only -fno-relaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-OFF %s
 
-// CHECK-ON:  warning: argument '-frelaxed-template-template-args' is 
deprecated [-Wdeprecated]
+// CHECK-DEF: "-cc1"{{.*}} "-fno-relaxed-template-template-args"
+// CHECK-ON-NOT: warning: argument '-frelaxed-template-template-args' is 
deprecated [-Wdeprecated]
 // CHECK-OFF: warning: argument '-fno-relaxed-template-template-args' is 
deprecated [-Wdeprecated]



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


[clang] [clang] Revert default behavior change of P0522R0 implementation (PR #91811)

2024-05-10 Thread via cfe-commits

cor3ntin wrote:

@erichkeane The goal is to provide a temporary working default, and a proper 
fix next fix, so that folks who are impacted by the break (everyone working on 
stdexec) isn't impacted longer than necessary. So I'll go and merge that and we 
can discuss a longer-term solution monday

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


[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #90310)

2024-05-10 Thread Reid Kleckner via cfe-commits

rnk wrote:

Hey, I went ahead and reverted this patch in 
aa0776de464984e78ae1cc329bf541e9dd43631f  because it is incompatible with ASan 
ThinLTO builds. I think you have uncovered a latent issue in the ASan + thinlto 
configuration that is not really the fault of this change, but I didn't see a 
path to fixing forward in the short term, so I reverted this to get this 
configuration working again.

I think the next step is to follow up with @vitalybuka to figure out how to 
reorder the ASan instrumentation pass in the thinlto pipeline.

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


[clang] aa0776d - Revert "[Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (#90310)" and related patches

2024-05-10 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2024-05-10T21:28:13Z
New Revision: aa0776de464984e78ae1cc329bf541e9dd43631f

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

LOG: Revert "[Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link 
pipeline (#90310)" and related patches

This change is incorrect when thinlto and asan are enabled, and this can
be observed by adding `-fsanitize=address` to the provided
coro-elide-thinlto.cpp test. It results in the error "Coroutines cannot
handle non static allocas yet", and ASan introduces a dynamic alloca.

In other words, we must preserve the invariant that CoroSplit runs
before ASan. If we move CoroSplit to the post post-link compile stage,
ASan has to be moved to the post-link compile stage first.  It would
also be correct to make CoroSplit handle dynamic allocas so the pass
ordering doesn't matter, but sanitizer instrumentation really ought to
be last, after coroutine splitting.

This reverts commit bafc5f42c0132171287d7cba7f5c14459be1f7b7.
This reverts commit b1b1bfa7bea0ce489b5ea9134e17a43c695df5ec.
This reverts commit 0232b77e145577ab78e3ed1fdbb7eacc5a7381ab.
This reverts commit fb2d3056618e3d03ba9a695627c7b002458e59f0.
This reverts commit 1cb33713910501c6352d0eb2a15b7a15e6e18695.
This reverts commit cd68d7b3c0ebf6da5e235cfabd5e6381737eb7fe.

Added: 


Modified: 
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/test/Other/new-pm-thinlto-prelink-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll

Removed: 
clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp



diff  --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
deleted file mode 100644
index 5b2d014657843..0
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-// REQUIRES: x86_64-linux
-// This tests that the coroutine elide optimization could happen succesfully 
with ThinLTO.
-// This test is adapted from coro-elide.cpp and splits functions into two 
files.
-//
-// RUN: split-file %s %t
-// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o %t/coro-elide-callee.o
-// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o %t/coro-elide-caller.o
-// RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
%t/summary
-// RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -x ir 
%t/coro-elide-caller.o -fthinlto-index=%t/summary.thinlto.bc -emit-llvm -o - | 
FileCheck %s
-
-//--- coro-elide-task.h
-#pragma once
-#include "Inputs/coroutine.h"
-
-struct Task {
-  struct promise_type {
-struct FinalAwaiter {
-  bool await_ready() const noexcept { return false; }
-  template 
-  std::coroutine_handle<> await_suspend(std::coroutine_handle 
h) noexcept {
-if (!h)
-  return std::noop_coroutine();
-return h.promise().continuation;
-  }
-  void await_resume() noexcept {}
-};
-Task get_return_object() noexcept {
-  return std::coroutine_handle::from_promise(*this);
-}
-std::suspend_always initial_suspend() noexcept { return {}; }
-FinalAwaiter final_suspend() noexcept { return {}; }
-void unhandled_exception() noexcept {}
-void return_value(int x) noexcept {
-  _value = x;
-}
-std::coroutine_handle<> continuation;
-int _value;
-  };
-
-  Task(std::coroutine_handle handle) : handle(handle) {}
-  ~Task() {
-if (handle)
-  handle.destroy();
-  }
-
-  struct Awaiter {
-bool await_ready() const noexcept { return false; }
-void await_suspend(std::coroutine_handle continuation) noexcept {}
-int await_resume() noexcept {
-  return 43;
-}
-  };
-
-  auto operator co_await() {
-return Awaiter{};
-  }
-
-private:
-  std::coroutine_handle handle;
-};
-
-//--- coro-elide-callee.cpp
-#include "coro-elide-task.h"
-Task task0() {
-  co_return 43;
-}
-
-//--- coro-elide-caller.cpp
-#include "coro-elide-task.h"
-
-Task task0();
-
-Task task1() {
-  co_return co_await task0();
-}
-
-// CHECK-LABEL: define{{.*}} void @_Z5task1v.resume
-// CHECK-NOT: {{.*}}_Znwm

diff  --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 1d7f0510450c9..72f273972f2f7 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -968,8 +968,7 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
   RequireAnalysisPass()));
 
-  if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink)
-MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
+  

[clang] [clang] Revert default behavior change of P0522R0 implementation (PR #91811)

2024-05-10 Thread Erich Keane via cfe-commits


@@ -7249,15 +7249,15 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables,
  options::OPT_fno_assume_unique_vtables);
 
-  // -frelaxed-template-template-args is deprecated.
-  if (Arg *A =
-  Args.getLastArg(options::OPT_frelaxed_template_template_args,
-  options::OPT_fno_relaxed_template_template_args)) {
+  // -fno-relaxed-template-template-args is deprecated.

erichkeane wrote:

I'm not sure I get the case for marking this deprecated?  

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


[clang] [clang] Revert default behavior change of P0522R0 implementation (PR #91811)

2024-05-10 Thread Erich Keane via cfe-commits

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


[clang] [clang] Revert default behavior change of P0522R0 implementation (PR #91811)

2024-05-10 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

This should probably also change the release note that still says we've changed 
this to on by default.  

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


[clang] [clang] Revert default behavior change of P0522R0 implementation (PR #91811)

2024-05-10 Thread via cfe-commits

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


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


[clang] [clang] Revert default behavior change of P0522R0 implementation (PR #91811)

2024-05-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

This partially reverts b86e0992bfa6c58be077d82d824016f590ac5d90.

Just the default is changed back, on the Driver side.
No Frontend changes.
The positive spelling of the flag is undeprecated.

No documentation changes or changelog entries because we plan to revert this 
revert as soon as https://github.com/llvm/llvm-project/issues/62529 is fixed.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+7-7) 
- (modified) clang/test/Driver/frelaxed-template-template-args.cpp (+4-2) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 42feb1650574e..f0cc018b6668f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7249,15 +7249,15 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables,
  options::OPT_fno_assume_unique_vtables);
 
-  // -frelaxed-template-template-args is deprecated.
-  if (Arg *A =
-  Args.getLastArg(options::OPT_frelaxed_template_template_args,
-  options::OPT_fno_relaxed_template_template_args)) {
+  // -fno-relaxed-template-template-args is deprecated.
+  if (Arg *A = Args.getLastArg(options::OPT_frelaxed_template_template_args,
+   
options::OPT_fno_relaxed_template_template_args);
+  A &&
+  A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
 D.Diag(diag::warn_drv_deprecated_arg)
 << A->getAsString(Args) << /*hasReplacement=*/false;
-if 
(A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
-  CmdArgs.push_back("-fno-relaxed-template-template-args");
-  }
+  else
+CmdArgs.push_back("-fno-relaxed-template-template-args");
 
   // -fsized-deallocation is off by default, as it is an ABI-breaking change 
for
   // most platforms.
diff --git a/clang/test/Driver/frelaxed-template-template-args.cpp 
b/clang/test/Driver/frelaxed-template-template-args.cpp
index dd6265ba8375e..136c360276a15 100644
--- a/clang/test/Driver/frelaxed-template-template-args.cpp
+++ b/clang/test/Driver/frelaxed-template-template-args.cpp
@@ -1,5 +1,7 @@
-// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-ON %s
+// RUN: %clang -fsyntax-only -### %s 2>&1 | FileCheck --check-prefix=CHECK-DEF 
%s
+// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-ON --allow-empty %s
 // RUN: %clang -fsyntax-only -fno-relaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-OFF %s
 
-// CHECK-ON:  warning: argument '-frelaxed-template-template-args' is 
deprecated [-Wdeprecated]
+// CHECK-DEF: "-cc1"{{.*}} "-fno-relaxed-template-template-args"
+// CHECK-ON-NOT: warning: argument '-frelaxed-template-template-args' is 
deprecated [-Wdeprecated]
 // CHECK-OFF: warning: argument '-fno-relaxed-template-template-args' is 
deprecated [-Wdeprecated]

``




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


[clang] [clang] Revert default behavior change of P0522R0 implementation (PR #91811)

2024-05-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Matheus Izvekov (mizvekov)


Changes

This partially reverts b86e0992bfa6c58be077d82d824016f590ac5d90.

Just the default is changed back, on the Driver side.
No Frontend changes.
The positive spelling of the flag is undeprecated.

No documentation changes or changelog entries because we plan to revert this 
revert as soon as https://github.com/llvm/llvm-project/issues/62529 is fixed.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+7-7) 
- (modified) clang/test/Driver/frelaxed-template-template-args.cpp (+4-2) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 42feb1650574e..f0cc018b6668f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7249,15 +7249,15 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables,
  options::OPT_fno_assume_unique_vtables);
 
-  // -frelaxed-template-template-args is deprecated.
-  if (Arg *A =
-  Args.getLastArg(options::OPT_frelaxed_template_template_args,
-  options::OPT_fno_relaxed_template_template_args)) {
+  // -fno-relaxed-template-template-args is deprecated.
+  if (Arg *A = Args.getLastArg(options::OPT_frelaxed_template_template_args,
+   
options::OPT_fno_relaxed_template_template_args);
+  A &&
+  A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
 D.Diag(diag::warn_drv_deprecated_arg)
 << A->getAsString(Args) << /*hasReplacement=*/false;
-if 
(A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
-  CmdArgs.push_back("-fno-relaxed-template-template-args");
-  }
+  else
+CmdArgs.push_back("-fno-relaxed-template-template-args");
 
   // -fsized-deallocation is off by default, as it is an ABI-breaking change 
for
   // most platforms.
diff --git a/clang/test/Driver/frelaxed-template-template-args.cpp 
b/clang/test/Driver/frelaxed-template-template-args.cpp
index dd6265ba8375e..136c360276a15 100644
--- a/clang/test/Driver/frelaxed-template-template-args.cpp
+++ b/clang/test/Driver/frelaxed-template-template-args.cpp
@@ -1,5 +1,7 @@
-// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-ON %s
+// RUN: %clang -fsyntax-only -### %s 2>&1 | FileCheck --check-prefix=CHECK-DEF 
%s
+// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-ON --allow-empty %s
 // RUN: %clang -fsyntax-only -fno-relaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-OFF %s
 
-// CHECK-ON:  warning: argument '-frelaxed-template-template-args' is 
deprecated [-Wdeprecated]
+// CHECK-DEF: "-cc1"{{.*}} "-fno-relaxed-template-template-args"
+// CHECK-ON-NOT: warning: argument '-frelaxed-template-template-args' is 
deprecated [-Wdeprecated]
 // CHECK-OFF: warning: argument '-fno-relaxed-template-template-args' is 
deprecated [-Wdeprecated]

``




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


[clang] [clang] Revert default behavior change of P0522R0 implementation (PR #91811)

2024-05-10 Thread Matheus Izvekov via cfe-commits

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

This partially reverts b86e0992bfa6c58be077d82d824016f590ac5d90.

Just the default is changed back, on the Driver side.
No Frontend changes.
The positive spelling of the flag is undeprecated.

No documentation changes or changelog entries because we plan to revert this 
revert as soon as https://github.com/llvm/llvm-project/issues/62529 is fixed.

>From 553dcf394229a67371ad84e7eb477691346136e9 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 10 May 2024 18:00:41 -0300
Subject: [PATCH] [clang] Revert default behavior change of P0522R0
 implementation

This partially reverts b86e0992bfa6c58be077d82d824016f590ac5d90
Just the default is changed back, on the Driver side.
No Frontend changes.
The positive spelling of the flag is undeprecated.

No documentation changes or changelog entries because we plan to revert
this revert as soon as https://github.com/llvm/llvm-project/issues/62529
is fixed.
---
 clang/lib/Driver/ToolChains/Clang.cpp  | 14 +++---
 .../Driver/frelaxed-template-template-args.cpp |  6 --
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 42feb1650574e..f0cc018b6668f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7249,15 +7249,15 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables,
  options::OPT_fno_assume_unique_vtables);
 
-  // -frelaxed-template-template-args is deprecated.
-  if (Arg *A =
-  Args.getLastArg(options::OPT_frelaxed_template_template_args,
-  options::OPT_fno_relaxed_template_template_args)) {
+  // -fno-relaxed-template-template-args is deprecated.
+  if (Arg *A = Args.getLastArg(options::OPT_frelaxed_template_template_args,
+   
options::OPT_fno_relaxed_template_template_args);
+  A &&
+  A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
 D.Diag(diag::warn_drv_deprecated_arg)
 << A->getAsString(Args) << /*hasReplacement=*/false;
-if 
(A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
-  CmdArgs.push_back("-fno-relaxed-template-template-args");
-  }
+  else
+CmdArgs.push_back("-fno-relaxed-template-template-args");
 
   // -fsized-deallocation is off by default, as it is an ABI-breaking change 
for
   // most platforms.
diff --git a/clang/test/Driver/frelaxed-template-template-args.cpp 
b/clang/test/Driver/frelaxed-template-template-args.cpp
index dd6265ba8375e..136c360276a15 100644
--- a/clang/test/Driver/frelaxed-template-template-args.cpp
+++ b/clang/test/Driver/frelaxed-template-template-args.cpp
@@ -1,5 +1,7 @@
-// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-ON %s
+// RUN: %clang -fsyntax-only -### %s 2>&1 | FileCheck --check-prefix=CHECK-DEF 
%s
+// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-ON --allow-empty %s
 // RUN: %clang -fsyntax-only -fno-relaxed-template-template-args %s 2>&1 | 
FileCheck --check-prefix=CHECK-OFF %s
 
-// CHECK-ON:  warning: argument '-frelaxed-template-template-args' is 
deprecated [-Wdeprecated]
+// CHECK-DEF: "-cc1"{{.*}} "-fno-relaxed-template-template-args"
+// CHECK-ON-NOT: warning: argument '-frelaxed-template-template-args' is 
deprecated [-Wdeprecated]
 // CHECK-OFF: warning: argument '-fno-relaxed-template-template-args' is 
deprecated [-Wdeprecated]

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


[clang] [llvm] [AArch64] Support preserve_none calling convention (PR #91046)

2024-05-10 Thread via cfe-commits

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


[clang] [Driver] Clean up fp-contract handling in clang driver (PR #91271)

2024-05-10 Thread Fangrui Song via cfe-commits


@@ -238,3 +238,17 @@
 // RUN: %clang -### -fno-unsafe-math-optimizations -funsafe-math-optimizations 
\
 // RUN: -ffp-contract=off -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF 
%s
 
+// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off -c %s 2>&1 \

MaskRay wrote:

Some folks prefer `git merge origin/main` while some just use `git rebase 
origin/main` and force push.

I am fine with either style, but someone really dislike force push (perhaps not 
for such a trivial change).

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


[clang] [Clang][HIP] Warn when __AMDGCN_WAVEFRONT_SIZE is used in host code (PR #91478)

2024-05-10 Thread Siu Chi Chan via cfe-commits

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

LGTM

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


[clang] [Clang][HIP] Warn when __AMDGCN_WAVEFRONT_SIZE is used in host code (PR #91478)

2024-05-10 Thread Siu Chi Chan via cfe-commits


@@ -0,0 +1,55 @@
+/*=== __clang_hip_device_macro_guards.h - guards for HIP device macros -===
+ *
+ * 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
+ *
+ *===---===
+ */
+
+/*
+ * WARNING: This header is intended to be directly -include'd by
+ * the compiler and is not supposed to be included by users.
+ *
+ */
+
+#ifndef __CLANG_HIP_DEVICE_MACRO_GUARDS_H__
+#define __CLANG_HIP_DEVICE_MACRO_GUARDS_H__
+
+#if __HIP__
+#if !defined(__HIP_DEVICE_COMPILE__)
+// The __AMDGCN_WAVEFRONT_SIZE macros cannot hold meaningful values during host
+// compilation as devices are not initialized when the macros are defined and
+// there may indeed be devices with differing wavefront sizes in the same
+// system. This code issues diagnostics when the macros are used in host code.
+
+#undef __AMDGCN_WAVEFRONT_SIZE
+#undef __AMDGCN_WAVEFRONT_SIZE__
+
+// Reference __hip_device_macro_guard in a way that is legal in preprocessor
+// directives and does not affect the value so that appropriate diagnostics are
+// issued. Function calls, casts, or the comma operator would make the macro
+// illegal for use in preprocessor directives.
+#define __AMDGCN_WAVEFRONT_SIZE (!__hip_device_macro_guard ? 64 : 64)
+#define __AMDGCN_WAVEFRONT_SIZE__ (!__hip_device_macro_guard ? 64 : 64)
+
+// This function is referenced by the macro in device functions during host
+// compilation, it SHOULD NOT cause a diagnostic.
+__attribute__((device)) static constexpr int __hip_device_macro_guard(void) {
+  return -1;
+}
+
+// This function is referenced by the macro in host functions during host
+// compilation, it SHOULD cause a diagnostic.
+__attribute__((
+host, deprecated("The __AMDGCN_WAVEFRONT_SIZE macros do not correspond "
+ "to the device(s) when used in host code and may only "
+ "be used in device code."))) static constexpr int

scchan wrote:

pre-C++11 HIP shouldn't be a concern anymore.

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


[clang] [clang][static analyzer] ignore try statements in dead code checker (PR #91675)

2024-05-10 Thread Andrew Sukach via cfe-commits

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


[clang] [clang] Use constant rounding mode for floating literals (PR #90877)

2024-05-10 Thread Joshua Cranmer via cfe-commits

https://github.com/jcranmer-intel commented:

I'm generally happy with the testing and semantics at this point.

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


[clang] [test] Move RISCV tests to clang/test/CodeGen/RISCV/ (PR #91783)

2024-05-10 Thread Fangrui Song via cfe-commits

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


[clang] e9f53e4 - [test] Move RISCV tests to clang/test/CodeGen/RISCV/

2024-05-10 Thread via cfe-commits

Author: Fangrui Song
Date: 2024-05-10T13:22:07-07:00
New Revision: e9f53e4095d8a8600b5c5d445c73e2d5a6f45abb

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

LOG: [test] Move RISCV tests to clang/test/CodeGen/RISCV/

The directory was created by 2f1fe9a3a60d6f18998c5f3b7e643d4cbaa4e65d
(2020).

Pull Request: https://github.com/llvm/llvm-project/pull/91783

Added: 
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-bitcast.c
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-call.c
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-cast.c
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-codegen.c
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-globals.c
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-types.c
clang/test/CodeGen/RISCV/riscv32-ilp32d-abi.cpp
clang/test/CodeGen/RISCV/rvv-vls-arith-ops.c
clang/test/CodeGen/RISCV/rvv-vls-bitwise-ops.c
clang/test/CodeGen/RISCV/rvv-vls-compare-ops.c
clang/test/CodeGen/RISCV/rvv-vls-shift-ops.c
clang/test/CodeGen/RISCV/rvv-vls-subscript-ops.c
clang/test/CodeGen/RISCV/vector-bits-vscale-range.c

Modified: 


Removed: 
clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c
clang/test/CodeGen/attr-riscv-rvv-vector-bits-call.c
clang/test/CodeGen/attr-riscv-rvv-vector-bits-cast.c
clang/test/CodeGen/attr-riscv-rvv-vector-bits-codegen.c
clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c
clang/test/CodeGen/attr-riscv-rvv-vector-bits-types.c
clang/test/CodeGen/riscv-rvv-vls-arith-ops.c
clang/test/CodeGen/riscv-rvv-vls-bitwise-ops.c
clang/test/CodeGen/riscv-rvv-vls-compare-ops.c
clang/test/CodeGen/riscv-rvv-vls-shift-ops.c
clang/test/CodeGen/riscv-rvv-vls-subscript-ops.c
clang/test/CodeGen/riscv-vector-bits-vscale-range.c
clang/test/CodeGen/riscv32-ilp32d-abi.cpp



diff  --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-bitcast.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-bitcast.c

diff  --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-call.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-call.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-call.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-call.c

diff  --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-cast.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-cast.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-cast.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-cast.c

diff  --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-codegen.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-codegen.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-codegen.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-codegen.c

diff  --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-globals.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-globals.c

diff  --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-types.c 
b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-types.c
similarity index 100%
rename from clang/test/CodeGen/attr-riscv-rvv-vector-bits-types.c
rename to clang/test/CodeGen/RISCV/attr-rvv-vector-bits-types.c

diff  --git a/clang/test/CodeGen/riscv32-ilp32d-abi.cpp 
b/clang/test/CodeGen/RISCV/riscv32-ilp32d-abi.cpp
similarity index 100%
rename from clang/test/CodeGen/riscv32-ilp32d-abi.cpp
rename to clang/test/CodeGen/RISCV/riscv32-ilp32d-abi.cpp

diff  --git a/clang/test/CodeGen/riscv-rvv-vls-arith-ops.c 
b/clang/test/CodeGen/RISCV/rvv-vls-arith-ops.c
similarity index 100%
rename from clang/test/CodeGen/riscv-rvv-vls-arith-ops.c
rename to clang/test/CodeGen/RISCV/rvv-vls-arith-ops.c

diff  --git a/clang/test/CodeGen/riscv-rvv-vls-bitwise-ops.c 
b/clang/test/CodeGen/RISCV/rvv-vls-bitwise-ops.c
similarity index 100%
rename from clang/test/CodeGen/riscv-rvv-vls-bitwise-ops.c
rename to clang/test/CodeGen/RISCV/rvv-vls-bitwise-ops.c

diff  --git a/clang/test/CodeGen/riscv-rvv-vls-compare-ops.c 
b/clang/test/CodeGen/RISCV/rvv-vls-compare-ops.c
similarity index 100%
rename from clang/test/CodeGen/riscv-rvv-vls-compare-ops.c
rename to clang/test/CodeGen/RISCV/rvv-vls-compare-ops.c

diff  --git a/clang/test/CodeGen/riscv-rvv-vls-shift-ops.c 
b/clang/test/CodeGen/RISCV/rvv-vls-shift-ops.c
similarity index 100%
rename from clang/test/CodeGen/riscv-rvv-vls-shift-ops.c
rename to clang/test/CodeGen/RISCV/rvv-vls-shift-ops.c

diff  --git 

[clang] [test] Move RISCV tests to clang/test/CodeGen/RISCV/ (PR #91783)

2024-05-10 Thread Fangrui Song via cfe-commits

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


[clang] [clang] CTAD alias: fix the transformation for the require-clause expr (PR #90961)

2024-05-10 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 099c1527f6088305fc253e9598685faa85544a8e 
9cc438e2def2fa98af71ba79eb82e033f3d5905a -- 
clang/test/AST/ast-dump-ctad-alias.cpp clang/lib/Sema/SemaTemplate.cpp 
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 1b0b854216..a1e79eaf7c 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2776,21 +2776,18 @@ NamedDecl *transformTemplateParameter(Sema , 
DeclContext *DC,
 return transformTemplateTypeParam(SemaRef, DC, TTP, Args, NewDepth,
   NewIndex);
   if (auto *TTP = dyn_cast(TemplateParam))
-return transformTemplateParam(SemaRef, DC, TTP, Args, NewIndex,
-  NewDepth);
+return transformTemplateParam(SemaRef, DC, TTP, Args, NewIndex, NewDepth);
   if (auto *NTTP = dyn_cast(TemplateParam))
-return transformTemplateParam(SemaRef, DC, NTTP, Args, NewIndex,
-  NewDepth);
+return transformTemplateParam(SemaRef, DC, NTTP, Args, NewIndex, NewDepth);
   llvm_unreachable("Unhandled template parameter types");
 }
 
 // Transform the require-clause of F if any.
 // The return result is expected to be the require-clause for the synthesized
 // alias deduction guide.
-Expr *transformRequireClause(
-Sema , FunctionTemplateDecl *F,
-TypeAliasTemplateDecl *AliasTemplate,
-ArrayRef DeduceResults) {
+Expr *transformRequireClause(Sema , FunctionTemplateDecl *F,
+ TypeAliasTemplateDecl *AliasTemplate,
+ ArrayRef DeduceResults) {
   Expr *RC = F->getTemplateParameters()->getRequiresClause();
   if (!RC)
 return nullptr;
@@ -2816,7 +2813,8 @@ Expr *transformRequireClause(
   // For 1), if the alias template is nested within a class template, we
   // calcualte the 'uninstantiated' depth by adding the substitution level 
back.
   unsigned AdjustDepth = 0;
-  if (auto *PrimaryTemplate = 
AliasTemplate->getInstantiatedFromMemberTemplate())
+  if (auto *PrimaryTemplate =
+  AliasTemplate->getInstantiatedFromMemberTemplate())
 AdjustDepth = PrimaryTemplate->getTemplateDepth();
 
   // We rebuild all template parameters with the uninstantiated depth, and
@@ -3040,7 +3038,8 @@ BuildDeductionGuideForTypeAlias(Sema ,
 Args.addOuterTemplateArguments(TransformedDeducedAliasArgs);
 NamedDecl *NewParam = transformTemplateParameter(
 SemaRef, AliasTemplate->getDeclContext(), TP, Args,
-/*NewIndex=*/FPrimeTemplateParams.size(), 
getTemplateParameterDepth(TP));
+/*NewIndex=*/FPrimeTemplateParams.size(),
+getTemplateParameterDepth(TP));
 FPrimeTemplateParams.push_back(NewParam);
 
 auto NewTemplateArgument = Context.getCanonicalTemplateArgument(
@@ -3113,8 +3112,8 @@ BuildDeductionGuideForTypeAlias(Sema ,
   Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
 auto *GG = cast(FPrime);
 
-Expr *RequiresClause = transformRequireClause(
-SemaRef, F, AliasTemplate, DeduceResults);
+Expr *RequiresClause =
+transformRequireClause(SemaRef, F, AliasTemplate, DeduceResults);
 
 // FIXME: implement the is_deducible constraint per C++
 // [over.match.class.deduct]p3.3:

``




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


[clang] [clang] CTAD alias: fix the transformation for the require-clause expr (PR #90961)

2024-05-10 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/90961

>From 9cc438e2def2fa98af71ba79eb82e033f3d5905a Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 3 May 2024 11:04:21 +0200
Subject: [PATCH] [clang] CTAD alias: refine the transformation for the
 require-clause expr.

In the clang AST, constraint nodes are deliberately not instantiated unless they
are actively being evaluated. Consequently, occurrences of template parameters
in the require-clause expression have a subtle "depth" difference compared to
normal occurrences in place contexts, such as function parameters. When
transforming the require-clause, we must take this distinction into account.

The existing implementation overlooks this consideration. This patch is
to rewrite the implementation of the require-clause transformation to
address this issue.
---
 clang/lib/Sema/SemaTemplate.cpp  | 147 +--
 clang/test/AST/ast-dump-ctad-alias.cpp   |  40 +
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp |  68 +
 3 files changed, 242 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-ctad-alias.cpp

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 480c0103ae335..1b0b8542164d6 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2758,31 +2758,151 @@ bool hasDeclaredDeductionGuides(DeclarationName Name, 
DeclContext *DC) {
   return false;
 }
 
+unsigned getTemplateParameterDepth(NamedDecl *TemplateParam) {
+  if (auto *TTP = dyn_cast(TemplateParam))
+return TTP->getDepth();
+  if (auto *TTP = dyn_cast(TemplateParam))
+return TTP->getDepth();
+  if (auto *NTTP = dyn_cast(TemplateParam))
+return NTTP->getDepth();
+  llvm_unreachable("Unhandled template parameter types");
+}
+
 NamedDecl *transformTemplateParameter(Sema , DeclContext *DC,
   NamedDecl *TemplateParam,
   MultiLevelTemplateArgumentList ,
-  unsigned NewIndex) {
+  unsigned NewIndex, unsigned NewDepth) {
   if (auto *TTP = dyn_cast(TemplateParam))
-return transformTemplateTypeParam(SemaRef, DC, TTP, Args, TTP->getDepth(),
+return transformTemplateTypeParam(SemaRef, DC, TTP, Args, NewDepth,
   NewIndex);
   if (auto *TTP = dyn_cast(TemplateParam))
 return transformTemplateParam(SemaRef, DC, TTP, Args, NewIndex,
-  TTP->getDepth());
+  NewDepth);
   if (auto *NTTP = dyn_cast(TemplateParam))
 return transformTemplateParam(SemaRef, DC, NTTP, Args, NewIndex,
-  NTTP->getDepth());
+  NewDepth);
   llvm_unreachable("Unhandled template parameter types");
 }
 
-Expr *transformRequireClause(Sema , FunctionTemplateDecl *FTD,
- llvm::ArrayRef TransformedArgs) 
{
-  Expr *RC = FTD->getTemplateParameters()->getRequiresClause();
+// Transform the require-clause of F if any.
+// The return result is expected to be the require-clause for the synthesized
+// alias deduction guide.
+Expr *transformRequireClause(
+Sema , FunctionTemplateDecl *F,
+TypeAliasTemplateDecl *AliasTemplate,
+ArrayRef DeduceResults) {
+  Expr *RC = F->getTemplateParameters()->getRequiresClause();
   if (!RC)
 return nullptr;
+
+  auto  = SemaRef.Context;
+  LocalInstantiationScope Scope(SemaRef);
+
+  // In the clang AST, constraint nodes are deliberately not instantiated 
unless
+  // they are actively being evaluated. Consequently, occurrences of template
+  // parameters in the require-clause expression have a subtle "depth"
+  // difference compared to normal occurrences in places, such as function
+  // parameters. When transforming the require-clause, we must take this
+  // distinction into account:
+  //
+  //   1) In the transformed require-clause, occurrences of template parameters
+  //   must use the "uninstantiated" depth;
+  //   2) When substituting on the require-clause expr of the underlying
+  //   deduction guide, we must use the entire set of template argument lists;
+  //
+  // It's important to note that we're performing this transformation on an
+  // *instantiated* AliasTemplate.
+
+  // For 1), if the alias template is nested within a class template, we
+  // calcualte the 'uninstantiated' depth by adding the substitution level 
back.
+  unsigned AdjustDepth = 0;
+  if (auto *PrimaryTemplate = 
AliasTemplate->getInstantiatedFromMemberTemplate())
+AdjustDepth = PrimaryTemplate->getTemplateDepth();
+
+  // We rebuild all template parameters with the uninstantiated depth, and
+  // build template arguments refer to them.
+  SmallVector AdjustedAliasTemplateArgs;
+
+  for (auto *TP : *AliasTemplate->getTemplateParameters()) {
+// Rebuild any internal references to earlier 

[clang] [clang] Add test for CWG1820 "Qualified typedef names" (PR #91765)

2024-05-10 Thread via cfe-commits

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


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


[clang-tools-extra] Add option to exclude headers from clang-tidy analysis (PR #91400)

2024-05-10 Thread Justin Cady via cfe-commits


@@ -311,7 +311,12 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(
 : Context(Ctx), ExternalDiagEngine(ExternalDiagEngine),
   RemoveIncompatibleErrors(RemoveIncompatibleErrors),
   GetFixesFromNotes(GetFixesFromNotes),
-  EnableNolintBlocks(EnableNolintBlocks) {}
+  EnableNolintBlocks(EnableNolintBlocks) {
+
+  if (Context.getOptions().ExcludeHeaderFilterRegex)
+ExcludeHeaderFilter = std::make_unique(
+*Context.getOptions().ExcludeHeaderFilterRegex);
+}

justincady wrote:

The change to make `HeaderFilter` mirror `ExcludeHeaderFilter` was not too bad, 
so I went ahead with it. I thought it might actually be better to do now while 
everything is fresh in my mind.  

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


[clang-tools-extra] Add option to exclude headers from clang-tidy analysis (PR #91400)

2024-05-10 Thread Justin Cady via cfe-commits


@@ -311,7 +311,12 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(
 : Context(Ctx), ExternalDiagEngine(ExternalDiagEngine),
   RemoveIncompatibleErrors(RemoveIncompatibleErrors),
   GetFixesFromNotes(GetFixesFromNotes),
-  EnableNolintBlocks(EnableNolintBlocks) {}
+  EnableNolintBlocks(EnableNolintBlocks) {
+
+  if (Context.getOptions().ExcludeHeaderFilterRegex)
+ExcludeHeaderFilter = std::make_unique(
+*Context.getOptions().ExcludeHeaderFilterRegex);

justincady wrote:

After further testing I came to understand what you meant and made this 
adjustment as suggested.

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


[clang] [clang-repl] Extend the C support. (PR #89804)

2024-05-10 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

@AaronBallman, can you take a look at that patch, hopefully to move forward as 
seems the other reviewers are busy.

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


[clang-tools-extra] Add option to exclude headers from clang-tidy analysis (PR #91400)

2024-05-10 Thread Justin Cady via cfe-commits

https://github.com/justincady updated 
https://github.com/llvm/llvm-project/pull/91400

>From a5de583aa94ef794a083c8b27df6dc6fc0762cb7 Mon Sep 17 00:00:00 2001
From: Justin Cady 
Date: Tue, 7 May 2024 16:54:35 -0400
Subject: [PATCH 1/5] Add option to exclude headers from clang-tidy analysis

This is a renewed attempt to land @toddlipcon's D34654. The comments on
that patch indicate a broad desire for some ability to ignore headers.

After considering various options, including migrating to std::regex, I
believe this is the best path forward. It's intuitive to have separate
regexes for including headers versus excluding them, and this approach
has the added benefit of being completely opt-in. No existing configs
will break, regardless of existing HeaderFilterRegex values.

This functionality is useful for improving performance when analyzing a
targeted subset of code, as well as in cases where some collection of
headers cannot be modified (third party source, for example).
---
 .../clang-tidy/ClangTidyDiagnosticConsumer.cpp   | 10 +-
 .../clang-tidy/ClangTidyDiagnosticConsumer.h |  5 +
 .../clang-tidy/ClangTidyOptions.cpp  |  4 
 clang-tools-extra/clang-tidy/ClangTidyOptions.h  |  4 
 .../clang-tidy/tool/ClangTidyMain.cpp| 16 
 .../clang-tidy/infrastructure/file-filter.cpp|  7 +++
 6 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index de2a3b51422a5..3cde0d2d68874 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -564,7 +564,8 @@ void 
ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
   StringRef FileName(File->getName());
   LastErrorRelatesToUserCode = LastErrorRelatesToUserCode ||
Sources.isInMainFile(Location) ||
-   getHeaderFilter()->match(FileName);
+   (getHeaderFilter()->match(FileName) &&
+!getExcludeHeaderFilter()->match(FileName));
 
   unsigned LineNumber = Sources.getExpansionLineNumber(Location);
   LastErrorPassesLineFilter =
@@ -578,6 +579,13 @@ llvm::Regex 
*ClangTidyDiagnosticConsumer::getHeaderFilter() {
   return HeaderFilter.get();
 }
 
+llvm::Regex *ClangTidyDiagnosticConsumer::getExcludeHeaderFilter() {
+  if (!ExcludeHeaderFilter)
+ExcludeHeaderFilter = std::make_unique(
+*Context.getOptions().ExcludeHeaderFilterRegex);
+  return ExcludeHeaderFilter.get();
+}
+
 void ClangTidyDiagnosticConsumer::removeIncompatibleErrors() {
   // Each error is modelled as the set of intervals in which it applies
   // replacements. To detect overlapping replacements, we use a sweep line
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index 9280eb1e1f218..a3add5d52778d 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -299,6 +299,10 @@ class ClangTidyDiagnosticConsumer : public 
DiagnosticConsumer {
   /// context.
   llvm::Regex *getHeaderFilter();
 
+  /// \brief Returns the \c ExcludeHeaderFilter constructed for the options set
+  /// in the context.
+  llvm::Regex *getExcludeHeaderFilter();
+
   /// Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter
   /// according to the diagnostic \p Location.
   void checkFilters(SourceLocation Location, const SourceManager );
@@ -313,6 +317,7 @@ class ClangTidyDiagnosticConsumer : public 
DiagnosticConsumer {
   bool EnableNolintBlocks;
   std::vector Errors;
   std::unique_ptr HeaderFilter;
+  std::unique_ptr ExcludeHeaderFilter;
   bool LastErrorRelatesToUserCode = false;
   bool LastErrorPassesLineFilter = false;
   bool LastErrorWasIgnored = false;
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index cbf21a0e2ae34..254ce7fc60fc9 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -170,6 +170,8 @@ template <> struct MappingTraits {
 IO.mapOptional("ImplementationFileExtensions",
Options.ImplementationFileExtensions);
 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
+IO.mapOptional("ExcludeHeaderFilterRegex",
+   Options.ExcludeHeaderFilterRegex);
 IO.mapOptional("FormatStyle", Options.FormatStyle);
 IO.mapOptional("User", Options.User);
 IO.mapOptional("CheckOptions", Options.CheckOptions);
@@ -192,6 +194,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
   Options.HeaderFileExtensions = {"", "h", "hh", "hpp", "hxx"};
   Options.ImplementationFileExtensions = {"c", "cc", "cpp", "cxx"};
   

  1   2   3   4   >