[clang] [clang][bytecode] Implement __builtin_{memchr,strchr,char_memchr} (PR #130420)

2025-03-09 Thread Timm Baeder via cfe-commits


@@ -1960,13 +1960,103 @@ static bool interp__builtin_memcmp(InterpState &S, 
CodePtr OpPC,
 
   // However, if we read all the available bytes but were instructed to read
   // even more, diagnose this as a "read of dereferenced one-past-the-end
-  // pointer". This is what would happen if we called CheckRead() on every 
array
+  // pointer". This is what would happen if we called CheckLoad() on every 
array
   // element.
   S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_past_end)
   << AK_Read << S.Current->getRange(OpPC);
   return false;
 }
 
+static bool interp__builtin_memchr(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call) 
{
+  unsigned ID = Func->getBuiltinID();
+  if (ID == Builtin::BImemchr || ID == Builtin::BIwcschr ||
+  ID == Builtin::BIstrchr || ID == Builtin::BIwmemchr)
+diagnoseNonConstexprBuiltin(S, OpPC, ID);
+
+  const Pointer &Ptr = getParam(Frame, 0);
+  APSInt Desired;
+  std::optional MaxLength;
+  if (Call->getNumArgs() == 3) {
+MaxLength =
+peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)), 0);
+Desired = peekToAPSInt(
+S.Stk, *S.getContext().classify(Call->getArg(1)),
+align(primSize(*S.getContext().classify(Call->getArg(2 +
+align(primSize(*S.getContext().classify(Call->getArg(1);
+  } else {
+Desired = peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(1)));
+  }
+
+  if (MaxLength && MaxLength->isZero()) {
+S.Stk.push();
+return true;
+  }
+
+  if (Ptr.isDummy())
+return false;
+
+  // Null is only okay if the given size is 0.
+  if (Ptr.isZero()) {
+S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_null)
+<< AK_Read;
+return false;
+  }
+
+  QualType ElemTy = Ptr.getFieldDesc()->isArray()
+? Ptr.getFieldDesc()->getElemQualType()
+: Ptr.getFieldDesc()->getType();
+  bool IsRawByte = ID == Builtin::BImemchr || ID == 
Builtin::BI__builtin_memchr;
+
+  // Give up on byte-oriented matching against multibyte elements.
+  if (IsRawByte && !isOneByteCharacterType(ElemTy)) {
+S.FFDiag(S.Current->getSource(OpPC),
+ diag::note_constexpr_memchr_unsupported)
+<< S.getASTContext().BuiltinInfo.getQuotedName(ID) << ElemTy;
+return false;
+  }
+
+  if (ID == Builtin::BIstrchr || ID == Builtin::BI__builtin_strchr) {
+// strchr compares directly to the passed integer, and therefore
+// always fails if given an int that is not a char.
+if (Desired !=
+Desired.trunc(S.getASTContext().getCharWidth()).getSExtValue()) {

tbaederr wrote:

This is from `ExprConstant.cpp`: 
https://github.com/llvm/llvm-project/blob/0f732481acccb3ac22b70e326feae854cf972126/clang/lib/AST/ExprConstant.cpp#L10017-L10023

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


[clang-tools-extra] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-03-09 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

Thanks for you contributions!

Some tips: 
1. run git-clang-format -f before commit change
2. actually you don't need to rebase often. but in past several weeks we have a 
major release and it causes release notes are cleared. in this case, rebase is 
needed.
3. After several successfully land, you can request write access. then you can 
merge it by yourself.

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


[clang-tools-extra] 2a3e782 - [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (#127162)

2025-03-09 Thread via cfe-commits

Author: Andrewyuan34
Date: 2025-03-09T20:09:59+08:00
New Revision: 2a3e782f4053d8ecb98dc110ebb6bacdb7bb17c7

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

LOG: [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used 
with std::unique_ptr (#127162)

This PR fixes issue #124815 by correcting the handling of `nullptr` with
`std::unique_ptr` in the `modernize-use-ranges` check.

Updated the logic to suppress warnings for `nullptr` in `std::find`.

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035..f7a19cd72d500 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -215,6 +215,19 @@ void UseRangesCheck::check(const MatchFinder::MatchResult 
&Result) {
 const auto *Call = Result.Nodes.getNodeAs(Buffer);
 if (!Call)
   continue;
+
+// FIXME: This check specifically handles `CXXNullPtrLiteralExpr`, but
+// a more general solution might be needed.
+if (Function->getName() == "find") {
+  const unsigned ValueArgIndex = 2;
+  if (Call->getNumArgs() <= ValueArgIndex)
+continue;
+  const Expr *ValueExpr =
+  Call->getArg(ValueArgIndex)->IgnoreParenImpCasts();
+  if (isa(ValueExpr))
+return;
+}
+
 auto Diag = createDiag(*Call);
 if (auto ReplaceName = Replacer->getReplaceName(*Function))
   Diag << FixItHint::CreateReplacement(Call->getCallee()->getSourceRange(),

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 951b7f20af4c8..a0cef3abb275f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -131,6 +131,10 @@ Changes in existing checks
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional
   examples and fixing some macro related false positives.
+  
+- Improved :doc:`modernize-use-ranges
+  ` check by updating suppress 
+  warnings logic for ``nullptr`` in ``std::find``.
 
 - Improved :doc:`misc-use-internal-linkage
   ` check by fix false positives

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index b022efebfdf4d..5aa026038b1cd 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -1,14 +1,25 @@
-// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/use-ranges/
-// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/use-ranges/
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/
+// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/
+// Example: ./check_clang_tidy.py -std=c++20 checkers/modernize/use-ranges.cpp 
modernize-use-ranges temp.txt -- -- -I 
~/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/
 
 // CHECK-FIXES: #include 
 // CHECK-FIXES-CPP23: #include 
 // CHECK-FIXES: #include 
 
-#include "fake_std.h"
+#include "use-ranges/fake_std.h"
+#include "smart-ptr/unique_ptr.h"
 
 void Positives() {
   std::vector I, J;
+  std::vector> K;
+
+  // Expect to have no check messages
+  std::find(K.begin(), K.end(), nullptr);
+
+  std::find(K.begin(), K.end(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(K, std::unique_ptr());
+
   std::find(I.begin(), I.end(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(I, 0);
@@ -76,6 +87,15 @@ void Positives() {
 
 void Reverse(){
   std::vector I, J;
+  std::vector> K;
+  
+  // Expect to have no check messages
+  std::find(K.rbegin(), K.rend(), nullptr);
+
+  std::find(K.rbegin(), K.rend(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(K), 
std::unique_ptr());
+
   std::find(I.rbegin(), I.rend(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), 0);



___
cfe-commits mailing list
cfe-commits@lists.llvm.or

[clang-tools-extra] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-03-09 Thread Congcong Cai via cfe-commits

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


[clang] [clang][bytecode] Fix getting pointer element type in __builtin_memcmp (PR #130485)

2025-03-09 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `openmp-s390x-linux` 
running on `systemz-1` while building `clang` at step 6 "test-openmp".

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


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

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang 
-fopenmp   -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test 
-L 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -mbackchain -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt
 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang 
-fopenmp -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test 
-L 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -mbackchain -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt
 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# executed command: 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


[clang-tools-extra] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-03-09 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang-tools-extra] [clang-tidy] 'modernize-use-starts-ends-with': fixed false positives on `find` and `rfind` (PR #129564)

2025-03-09 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor updated 
https://github.com/llvm/llvm-project/pull/129564

>From c3f21bb654d2980955f2c37a5dc7a02a1ced7891 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Mon, 3 Mar 2025 21:00:32 +0300
Subject: [PATCH 1/5] [clang-tidy] fixed false positives on find and rfind

---
 .../modernize/UseStartsEndsWithCheck.cpp  |  7 ---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../checks/modernize/use-starts-ends-with.rst |  1 +
 .../checkers/modernize/use-starts-ends-with.cpp   | 15 +++
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
index ab72c6796bb4c..02a537430 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
@@ -113,9 +113,10 @@ void UseStartsEndsWithCheck::registerMatchers(MatchFinder 
*Finder) {
   const auto OnClassWithEndsWithFunction = ClassTypeWithMethod(
   "ends_with_fun", "ends_with", "endsWith", "endswith", "EndsWith");
 
-  // Case 1: X.find(Y) [!=]= 0 -> starts_with.
+  // Case 1: X.find(Y, [0]) [!=]= 0 -> starts_with.
   const auto FindExpr = cxxMemberCallExpr(
-  anyOf(argumentCountIs(1), hasArgument(1, ZeroLiteral)),
+  anyOf(argumentCountIs(1),
+allOf(argumentCountIs(2), hasArgument(1, ZeroLiteral))),
   callee(
   cxxMethodDecl(hasName("find"), 
ofClass(OnClassWithStartsWithFunction))
   .bind("find_fun")),
@@ -123,7 +124,7 @@ void UseStartsEndsWithCheck::registerMatchers(MatchFinder 
*Finder) {
 
   // Case 2: X.rfind(Y, 0) [!=]= 0 -> starts_with.
   const auto RFindExpr = cxxMemberCallExpr(
-  hasArgument(1, ZeroLiteral),
+  argumentCountIs(2), hasArgument(1, ZeroLiteral),
   callee(cxxMethodDecl(hasName("rfind"),
ofClass(OnClassWithStartsWithFunction))
  .bind("find_fun")),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 07a79d6bbe807..e29598ccf0b43 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -137,6 +137,10 @@ Changes in existing checks
   ` check by fixing false 
negatives
   on ternary operators calling ``std::move``.
 
+- Improved :doc:`modernize-use-starts-ends-with
+  ` check by fixing false
+  positives on methods ``find`` and ``rfind`` called with three arguments.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst
index 78cd900885ac3..bad1952db22f9 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst
@@ -13,6 +13,7 @@ Covered scenarios:
 Expression   Replacement
  -
 ``u.find(v) == 0``   ``u.starts_with(v)``
+``u.find(v, 0) == 0````u.starts_with(v)``
 ``u.rfind(v, 0) != 0``   ``!u.starts_with(v)``
 ``u.compare(0, v.size(), v) == 0``   ``u.starts_with(v)``
 ``u.substr(0, v.size()) == v``   ``u.starts_with(v)``
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-starts-ends-with.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-starts-ends-with.cpp
index 8699ca03ba331..4d61709eff463 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-starts-ends-with.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-starts-ends-with.cpp
@@ -236,6 +236,18 @@ void test(std::string s, std::string_view sv, sub_string 
ss, sub_sub_string sss,
   // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use ends_with
   // CHECK-FIXES: s.ends_with(suffix);
 
+  s.find("a", 0) == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: s.starts_with("a");
+  
+  s.find(s, ZERO) == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: s.starts_with(s);
+
+  s.find(s, 0) == ZERO;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: s.starts_with(s);
+
   struct S {
 std::string s;
   } t;
@@ -261,6 +273,9 @@ void test(std::string s, std::string_view sv, sub_string 
ss, sub_sub_string sss,
 
   #define STRING s
   if (0 == STRING.find("ala")) { /* do something */}
+
+  s.find("aaa", 0, 3) == 0;
+  s.rfind("aaa", std::string::npos, 3) == 0;
 }
 
 void test_substr() {

>From e379faf582f3dea5072f6a7c86a44ea6aeed6749 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Thu, 6 Mar 2025 00:21:16 +0300

[clang-tools-extra] [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (PR #129370)

2025-03-09 Thread Baranov Victor via cfe-commits


@@ -132,11 +132,15 @@ Changes in existing checks
   ` check by providing additional
   examples and fixing some macro related false positives.
 
+- Improved :doc:`modernize-use-default-member-init

vbvictor wrote:

Please place this below `misc-use-internal-linkage` to follow alphabetical order

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


[clang-tools-extra] [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (PR #129370)

2025-03-09 Thread Baranov Victor via cfe-commits

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


[clang-tools-extra] [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (PR #129370)

2025-03-09 Thread Baranov Victor via cfe-commits

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

LGTM, but please address a nit

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


[clang-tools-extra] [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (PR #129370)

2025-03-09 Thread Congcong Cai via cfe-commits

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


[clang] [clang] fix matching of nested template template parameters (PR #130447)

2025-03-09 Thread via cfe-commits


@@ -11363,14 +11363,17 @@ class Sema final : public SemaBase {
 
   /// The context in which we are checking a template parameter list.
   enum TemplateParamListContext {
-TPC_ClassTemplate,
-TPC_VarTemplate,
+// For this context, Class, Variable, TypeAlias, and non-pack Template
+// Template
+// Parameters are the same.
+TPC_Normal,

cor3ntin wrote:

"Normal" doesn't make sense to me. I believe that we are better off just adding 
`TPC_TemplateTemplateParameterPack` and keeping everything else the same (even 
though _today_ these contexts are not differentiated anywhere)

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


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Younan Zhang via cfe-commits

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


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


[clang] [clang] fix matching of nested template template parameters (PR #130447)

2025-03-09 Thread Matheus Izvekov via cfe-commits


@@ -11363,14 +11363,17 @@ class Sema final : public SemaBase {
 
   /// The context in which we are checking a template parameter list.
   enum TemplateParamListContext {
-TPC_ClassTemplate,
-TPC_VarTemplate,
+// For this context, Class, Variable, TypeAlias, and non-pack Template
+// Template
+// Parameters are the same.
+TPC_Normal,

mizvekov wrote:

No would be needing to add two actually, TPC_TemplateTemplateParameter and 
TPC_TemplateTemplateParameterPack.

I think the simplification is worth it, as otherwise we would always be testing 
four kinds together everywhere.

There is no point in differentiating these cases for the current 
implementation, and I hope we can find a better name and keep the 
simplification.

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


[clang] [Clang] Force expressions with UO_Not to not be non-negative (PR #126846)

2025-03-09 Thread Yutong Zhu via cfe-commits

YutongZhuu wrote:

> Can you update the first comment on this PR to reflect what you want to be in 
> the commit message? I notice that it doesn't describe what you're doing with 
> negation yet. Thanks!

Addressed

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


[clang] C89 doesn't have `math.h` functions (PR #129979)

2025-03-09 Thread Vinay Deshmukh via cfe-commits

https://github.com/vinay-deshmukh updated 
https://github.com/llvm/llvm-project/pull/129979

>From e9c7869550d9fd1eba4d4d42ee644540e6b6d445 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Tue, 4 Mar 2025 22:30:34 -0500
Subject: [PATCH 1/5] add failing test

---
 clang/test/C/drs/c89_with_c99_functions.c | 7 +++
 1 file changed, 7 insertions(+)
 create mode 100644 clang/test/C/drs/c89_with_c99_functions.c

diff --git a/clang/test/C/drs/c89_with_c99_functions.c 
b/clang/test/C/drs/c89_with_c99_functions.c
new file mode 100644
index 0..d848727001562
--- /dev/null
+++ b/clang/test/C/drs/c89_with_c99_functions.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c89 -verify %s
+
+// From: https://github.com/llvm/llvm-project/issues/15522#issue-1071059939
+int logf = 5;
+int main() {
+return logf;
+}

>From 966aa6a735722063d7ea9727e36136f4f39c3d88 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Wed, 5 Mar 2025 22:09:02 -0500
Subject: [PATCH 2/5] Update test to `expect-no-diagnostics`

---
 clang/test/C/drs/c89_with_c99_functions.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/test/C/drs/c89_with_c99_functions.c 
b/clang/test/C/drs/c89_with_c99_functions.c
index d848727001562..de525313fbba5 100644
--- a/clang/test/C/drs/c89_with_c99_functions.c
+++ b/clang/test/C/drs/c89_with_c99_functions.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c89 -verify %s
+// expected-no-diagnostics
 
 // From: https://github.com/llvm/llvm-project/issues/15522#issue-1071059939
 int logf = 5;

>From 28c58718d76be9c62635cdeffebc9d812b192e50 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Wed, 5 Mar 2025 22:13:50 -0500
Subject: [PATCH 3/5] Add exclusion for C89 / math.h functions

---
 clang/lib/Basic/Builtins.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index e7829a461bbc5..cfcbefdce2a24 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -14,6 +14,7 @@
 #include "BuiltinTargetFeatures.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringRef.h"
 using namespace clang;
@@ -148,7 +149,7 @@ static bool builtinIsSupported(const llvm::StringTable 
&Strings,
   if (!LangOpts.Coroutines && (BuiltinInfo.Langs & COR_LANG))
 return false;
   /* MathBuiltins Unsupported */
-  if (LangOpts.NoMathBuiltin && BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
+  if ((LangOpts.NoMathBuiltin || /*C89*/ LangOpts.LangStd == 
LangStandard::lang_c89)&& BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
 return false;
   /* GnuMode Unsupported */
   if (!LangOpts.GNUMode && (BuiltinInfo.Langs & GNU_LANG))

>From 6e790580b3859cd68ca6ea87c1601979047310ab Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Wed, 5 Mar 2025 22:25:07 -0500
Subject: [PATCH 4/5] clang-format

---
 clang/lib/Basic/Builtins.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index cfcbefdce2a24..81f85bb5454e4 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -149,7 +149,9 @@ static bool builtinIsSupported(const llvm::StringTable 
&Strings,
   if (!LangOpts.Coroutines && (BuiltinInfo.Langs & COR_LANG))
 return false;
   /* MathBuiltins Unsupported */
-  if ((LangOpts.NoMathBuiltin || /*C89*/ LangOpts.LangStd == 
LangStandard::lang_c89)&& BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
+  if ((LangOpts.NoMathBuiltin ||
+   /*C89*/ LangOpts.LangStd == LangStandard::lang_c89) &&
+  BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
 return false;
   /* GnuMode Unsupported */
   if (!LangOpts.GNUMode && (BuiltinInfo.Langs & GNU_LANG))

>From 160d719b7ed5997d39accb110df873e6200991d4 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Sun, 9 Mar 2025 14:14:37 -0400
Subject: [PATCH 5/5] exclude c99 symbols from builtins when std=c89

---
 clang/lib/Basic/Builtins.cpp  | 20 ++--
 clang/test/C/drs/c89_with_c99_functions.c | 14 ++
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index 81f85bb5454e4..70ea34da1f9e6 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -17,6 +17,7 @@
 #include "clang/Basic/LangStandard.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringTable.h"
 using namespace clang;
 
 const char *HeaderDesc::getName() const {
@@ -136,6 +137,18 @@ bool Builtin::Context::isBuiltinFunc(llvm::StringRef 
FuncName) {
   return false;
 }
 
+static bool isSymbolAvai

[clang] [llvm] [alpha.webkit.UnretainedLambdaCapturesChecker] Add a WebKit checker for lambda capturing NS or CF types. (PR #128651)

2025-03-09 Thread Ryosuke Niwa via cfe-commits


@@ -3487,6 +3487,18 @@ Raw pointers and references to an object which supports 
CheckedPtr or CheckedRef
 
 See `WebKit Guidelines for Safer C++ Programming 
`_ for details.
 
+alpha.webkit.UnretainedLambdaCapturesChecker
+
+Raw pointers and references to unretained types can't be captured in lambdas. 
Only RetainPtr is allowed.

rniwa wrote:

Added.

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


[clang] [HLSL] select scalar overloads for vector conditions (PR #129396)

2025-03-09 Thread Chris B via cfe-commits

https://github.com/llvm-beanz updated 
https://github.com/llvm/llvm-project/pull/129396

>From 7620f9fac9932a13f1da0468b02c1aeceb212a0b Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Wed, 19 Feb 2025 17:18:20 -0600
Subject: [PATCH 1/6] [HLSL] select scalar overloads for vector conditions

This PR adds scalar/vector overloads for vector conditions to the
`select` builtin, and updates the sema checking and codegen to allow
scalars to extend to vectors.

Fixes #126570

clang-format
clang-format
'cbieneman/select' on '44f0fe9a2806'.
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  8 ++
 .../lib/Headers/hlsl/hlsl_alias_intrinsics.h  | 36 +++
 clang/lib/Headers/hlsl/hlsl_detail.h  |  5 +
 clang/lib/Sema/SemaHLSL.cpp   | 56 ++-
 clang/test/CodeGenHLSL/builtins/select.hlsl   | 29 ++
 .../test/SemaHLSL/BuiltIns/select-errors.hlsl | 98 +--
 7 files changed, 135 insertions(+), 100 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 21be7c358a61d..2514fb68bf5b0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12707,6 +12707,9 @@ def err_hlsl_param_qualifier_mismatch :
 def err_hlsl_vector_compound_assignment_truncation : Error<
   "left hand operand of type %0 to compound assignment cannot be truncated "
   "when used with right hand operand of type %1">;
+def err_hlsl_builtin_scalar_vector_mismatch : Error<
+  "%select{all|second and third}0 arguments to %1 must be of scalar or "
+  "vector type with matching scalar element type%diff{: $ vs $|}2,3">;
 
 def warn_hlsl_impcast_vector_truncation : Warning<
   "implicit conversion truncates vector: %0 to %1">, InGroup;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index b86bb242755be..ba78de049ce96 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19836,6 +19836,14 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 RValFalse.isScalar()
 ? RValFalse.getScalarVal()
 : RValFalse.getAggregatePointer(E->getArg(2)->getType(), *this);
+if (auto *VTy = E->getType()->getAs()) {
+  if (!OpTrue->getType()->isVectorTy())
+OpTrue =
+Builder.CreateVectorSplat(VTy->getNumElements(), OpTrue, "splat");
+  if (!OpFalse->getType()->isVectorTy())
+OpFalse =
+Builder.CreateVectorSplat(VTy->getNumElements(), OpFalse, "splat");
+}
 
 Value *SelectVal =
 Builder.CreateSelect(OpCond, OpTrue, OpFalse, "hlsl.select");
diff --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
index 7573f6e024167..7a550a58e705c 100644
--- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
@@ -2123,6 +2123,42 @@ template 
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
 vector select(vector, vector, vector);
 
+
+/// \fn vector select(vector Conds, T TrueVal,
+/// vector FalseVals)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVal The scalar value to splat from when conditions are true.
+/// \param FalseVals The vector values are chosen from when conditions are
+/// false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+vector select(vector, T, vector);
+
+/// \fn vector select(vector Conds, vector TrueVals,
+/// T FalseVal)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVals The vector values are chosen from when conditions are true.
+/// \param FalseVal The scalar value to splat from when conditions are false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+vector select(vector, vector, T);
+
+/// \fn vector select(vector Conds, vector TrueVals,
+/// T FalseVal)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVal The scalar value to splat from when conditions are true.
+/// \param FalseVal The scalar value to splat from when conditions are false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+__detail::enable_if_t<__detail::is_arithmetic::Value, vector> select(
+vector, T, T);
+
 
//===--===//
 // sin builtins
 
//===--===//
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 39254a3cc3a0a..086c527614a43 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -97,6 +97,11 @@ constexpr

[clang] [llvm] [alpha.webkit.UnretainedLambdaCapturesChecker] Add a WebKit checker for lambda capturing NS or CF types. (PR #128651)

2025-03-09 Thread Ryosuke Niwa via cfe-commits

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

>From dc53e0602fcec63bdd1bc84325ecc16a3f3e293b Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 24 Feb 2025 23:39:13 -0800
Subject: [PATCH 1/3] [alpha.webkit.UnretainedLambdaCapturesChecker] Add a
 WebKit checker for lambda capturing NS or CF types.

Add a new WebKit checker for checking that lambda captures of CF types use 
RetainPtr either when ARC is
disabled or enabled, and those of NS types use RetainPtr when ARC is disabled.
---
 clang/docs/analyzer/checkers.rst  |  12 +
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   4 +-
 ...cpp => RawPtrRefLambdaCapturesChecker.cpp} | 136 ++--
 .../Checkers/WebKit/objc-mock-types.h | 146 -
 ...mbda-captures-decl-protects-this-crash.cpp |   4 +-
 .../WebKit/uncounted-lambda-captures.cpp  |  34 +-
 .../WebKit/unretained-lambda-captures-arc.mm  | 273 
 .../WebKit/unretained-lambda-captures.mm  | 296 ++
 .../lib/StaticAnalyzer/Checkers/BUILD.gn  |   2 +-
 10 files changed, 851 insertions(+), 60 deletions(-)
 rename 
clang/lib/StaticAnalyzer/Checkers/WebKit/{UncountedLambdaCapturesChecker.cpp => 
RawPtrRefLambdaCapturesChecker.cpp} (77%)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/unretained-lambda-captures-arc.mm
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/unretained-lambda-captures.mm

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index c1eedb33e74d2..57733d45167f5 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3487,6 +3487,18 @@ Raw pointers and references to an object which supports 
CheckedPtr or CheckedRef
 
 See `WebKit Guidelines for Safer C++ Programming 
`_ for details.
 
+alpha.webkit.UnretainedLambdaCapturesChecker
+
+Raw pointers and references to unretained types can't be captured in lambdas. 
Only RetainPtr is allowed.
+
+.. code-block:: cpp
+
+ void foo(NSObject *a, NSObject *b) {
+   [&, a](){ // warn about 'a'
+ do_something(b); // warn about 'b'
+   };
+ };
+
 .. _alpha-webkit-UncountedCallArgsChecker:
 
 alpha.webkit.UncountedCallArgsChecker
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 410f841630660..06aa083671b7a 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1766,6 +1766,10 @@ def NoUncheckedPtrMemberChecker : 
Checker<"NoUncheckedPtrMemberChecker">,
   HelpText<"Check for no unchecked member variables.">,
   Documentation;
 
+def UnretainedLambdaCapturesChecker : 
Checker<"UnretainedLambdaCapturesChecker">,
+  HelpText<"Check unretained lambda captures.">,
+  Documentation;
+
 def UncountedCallArgsChecker : Checker<"UncountedCallArgsChecker">,
   HelpText<"Check uncounted call arguments.">,
   Documentation;
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 5910043440987..9aac200cd7370 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -128,14 +128,14 @@ add_clang_library(clangStaticAnalyzerCheckers
   VLASizeChecker.cpp
   ValistChecker.cpp
   VirtualCallChecker.cpp
-  WebKit/RawPtrRefMemberChecker.cpp
   WebKit/ASTUtils.cpp
   WebKit/MemoryUnsafeCastChecker.cpp
   WebKit/PtrTypesSemantics.cpp
   WebKit/RefCntblBaseVirtualDtorChecker.cpp
   WebKit/RawPtrRefCallArgsChecker.cpp
-  WebKit/UncountedLambdaCapturesChecker.cpp
+  WebKit/RawPtrRefLambdaCapturesChecker.cpp
   WebKit/RawPtrRefLocalVarsChecker.cpp
+  WebKit/RawPtrRefMemberChecker.cpp
 
   LINK_LIBS
   clangAST
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
similarity index 77%
rename from 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
rename to 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
index 506442f352288..314b3dc72c8e5 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
@@ -21,15 +21,23 @@ using namespace clang;
 using namespace ento;
 
 namespace {
-class UncountedLambdaCapturesChecker
+class RawPtrRefLambdaCapturesChecker
 : public Checker> {
 private:
-  BugType Bug{this, "Lambda capture of uncounted variable",
-  "WebKit coding guidelines"};
+  BugType Bug;
   mutable BugReporter *BR = nullptr;
   TrivialFunctionAnalysis TFA;
 
+protected:
+  mutable std::optional RTC;
+
 public:
+  RawPtrRefLambdaCapturesChecker(const char *des

[clang] a7d5b3f - [HLSL] Disallow virtual inheritance and functions (#127346)

2025-03-09 Thread via cfe-commits

Author: Chris B
Date: 2025-03-09T12:18:44-05:00
New Revision: a7d5b3f711b7c852aa1337e329661dd36025865a

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

LOG: [HLSL] Disallow virtual inheritance and functions (#127346)

This PR disallows virtual inheritance and virtual functions in HLSL.

Added: 
clang/test/SemaHLSL/Language/NoVirtual.hlsl

Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..a9a8b272bef15 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1817,5 +1817,9 @@ def ext_hlsl_access_specifiers : ExtWarn<
   InGroup;
 def err_hlsl_unsupported_component : Error<"invalid component '%0' used; 
expected 'x', 'y', 'z', or 'w'">;
 def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier 
'%0' for packoffset, expected 'c'">;
+def err_hlsl_virtual_function
+: Error<"virtual functions are unsupported in HLSL">;
+def err_hlsl_virtual_inheritance
+: Error<"virtual inheritance is unsupported in HLSL">;
 
 } // end of Parser diagnostics

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 31cb4a24ad97e..82b394d5b4ca6 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4411,6 +4411,10 @@ void Parser::ParseDeclarationSpecifiers(
 DiagID = diag::err_openclcxx_virtual_function;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
+  } else if (getLangOpts().HLSL) {
+DiagID = diag::err_hlsl_virtual_function;
+PrevSpec = Tok.getIdentifierInfo()->getNameStart();
+isInvalid = true;
   } else {
 isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
   }

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index e48a35078892d..9384f9ab10af0 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2492,6 +2492,9 @@ BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) {
 IsVirtual = true;
   }
 
+  if (getLangOpts().HLSL && IsVirtual)
+Diag(Tok.getLocation(), diag::err_hlsl_virtual_inheritance);
+
   CheckMisplacedCXX11Attribute(Attributes, StartLoc);
 
   // Parse the class-name.

diff  --git a/clang/test/SemaHLSL/Language/NoVirtual.hlsl 
b/clang/test/SemaHLSL/Language/NoVirtual.hlsl
new file mode 100644
index 0..8d61bde7d836e
--- /dev/null
+++ b/clang/test/SemaHLSL/Language/NoVirtual.hlsl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -verify %s
+
+struct Base {
+  int X;
+  void MemberFunction();  // valid
+  virtual void MemberFunction2(); // expected-error{{virtual functions are 
unsupported in HLSL}}
+};
+
+struct Derived : virtual Base { // expected-error{{virtual inheritance is 
unsupported in HLSL}}
+  int Y;
+
+  void MemberFunction2() override; // expected-error{{only virtual member 
functions can be marked 'override'}}
+};
+



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


[clang] C89 doesn't have `math.h` functions (PR #129979)

2025-03-09 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 91aac7c379fb92348593d51e3f2d9e490ff67526 
160d719b7ed5997d39accb110df873e6200991d4 --extensions cpp,c -- 
clang/test/C/drs/c89_with_c99_functions.c clang/lib/Basic/Builtins.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index 70ea34da1f..4795a7fca6 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -137,12 +137,13 @@ bool Builtin::Context::isBuiltinFunc(llvm::StringRef 
FuncName) {
   return false;
 }
 
-static bool isSymbolAvailableInC89(const llvm::StringTable& Strings, const 
Builtin::Info & BuiltinInfo) {
+static bool isSymbolAvailableInC89(const llvm::StringTable &Strings,
+   const Builtin::Info &BuiltinInfo) {
 
   auto NameStr = Strings[BuiltinInfo.Offsets.Name];
 
   // FIXME: add other C89 symbols here
-  if(NameStr == "log") {
+  if (NameStr == "log") {
 return true;
   }
 
@@ -166,8 +167,7 @@ static bool builtinIsSupported(const llvm::StringTable 
&Strings,
 return false;
   }
   /* MathBuiltins Unsupported */
-  if (LangOpts.NoMathBuiltin &&
-  BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
+  if (LangOpts.NoMathBuiltin && BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
 return false;
   /* GnuMode Unsupported */
   if (!LangOpts.GNUMode && (BuiltinInfo.Langs & GNU_LANG))

``




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


[clang] [clang][NFC] Clean up Expr::EvaluateAsConstantExpr (PR #130498)

2025-03-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

The Info.EnableNewConstInterp case is already handled above.

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


1 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+12-17) 


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d9a1e5bb42343..759df64da6215 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -16892,24 +16892,19 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   APValue::LValueBase Base(&BaseMTE);
   Info.setEvaluatingDecl(Base, Result.Val);
 
-  if (Info.EnableNewConstInterp) {
-if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, this, Result.Val))
-  return false;
-  } else {
-LValue LVal;
-LVal.set(Base);
-// C++23 [intro.execution]/p5
-// A full-expression is [...] a constant-expression
-// So we need to make sure temporary objects are destroyed after having
-// evaluating the expression (per C++23 [class.temporary]/p4).
-FullExpressionRAII Scope(Info);
-if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
-Result.HasSideEffects || !Scope.destroy())
-  return false;
+  LValue LVal;
+  LVal.set(Base);
+  // C++23 [intro.execution]/p5
+  // A full-expression is [...] a constant-expression
+  // So we need to make sure temporary objects are destroyed after having
+  // evaluating the expression (per C++23 [class.temporary]/p4).
+  FullExpressionRAII Scope(Info);
+  if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
+  Result.HasSideEffects || !Scope.destroy())
+return false;
 
-if (!Info.discardCleanups())
-  llvm_unreachable("Unhandled cleanup; missing full expression marker?");
-  }
+  if (!Info.discardCleanups())
+llvm_unreachable("Unhandled cleanup; missing full expression marker?");
 
   if (!CheckConstantExpression(Info, getExprLoc(), getStorageType(Ctx, this),
Result.Val, Kind))

``




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


[clang] C89 doesn't have `math.h` functions (PR #129979)

2025-03-09 Thread Vinay Deshmukh via cfe-commits

vinay-deshmukh wrote:


I'm a bit confused about the whole what is not UB/IFNDR in C89, but is in C99. 
Based on my current understanding the simplest way to resolve the issue seems 
to what I've done as of: 
7572c21

Is not define builtins for symbols available in C89?

let me know if that looks good.

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


[clang] [CIR] Upstream basic support for ArrayType (PR #130502)

2025-03-09 Thread Amr Hesham via cfe-commits

AmrDeveloper wrote:

There will be two upcoming patches.

1 - Initializing const array and zero initializing support (Depends on 
upstreaming `ConstantEmitter` and `ZeroAttr`)
2 - Dynamic-size arrays, and accessing arrays using the `cir.ptr_stride` 
operation (Depends on upstreaming `CastOp`)


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


[clang] [HLSL] select scalar overloads for vector conditions (PR #129396)

2025-03-09 Thread Chris B via cfe-commits

https://github.com/llvm-beanz updated 
https://github.com/llvm/llvm-project/pull/129396

>From 7620f9fac9932a13f1da0468b02c1aeceb212a0b Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Wed, 19 Feb 2025 17:18:20 -0600
Subject: [PATCH 1/5] [HLSL] select scalar overloads for vector conditions

This PR adds scalar/vector overloads for vector conditions to the
`select` builtin, and updates the sema checking and codegen to allow
scalars to extend to vectors.

Fixes #126570

clang-format
clang-format
'cbieneman/select' on '44f0fe9a2806'.
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  8 ++
 .../lib/Headers/hlsl/hlsl_alias_intrinsics.h  | 36 +++
 clang/lib/Headers/hlsl/hlsl_detail.h  |  5 +
 clang/lib/Sema/SemaHLSL.cpp   | 56 ++-
 clang/test/CodeGenHLSL/builtins/select.hlsl   | 29 ++
 .../test/SemaHLSL/BuiltIns/select-errors.hlsl | 98 +--
 7 files changed, 135 insertions(+), 100 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 21be7c358a61d..2514fb68bf5b0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12707,6 +12707,9 @@ def err_hlsl_param_qualifier_mismatch :
 def err_hlsl_vector_compound_assignment_truncation : Error<
   "left hand operand of type %0 to compound assignment cannot be truncated "
   "when used with right hand operand of type %1">;
+def err_hlsl_builtin_scalar_vector_mismatch : Error<
+  "%select{all|second and third}0 arguments to %1 must be of scalar or "
+  "vector type with matching scalar element type%diff{: $ vs $|}2,3">;
 
 def warn_hlsl_impcast_vector_truncation : Warning<
   "implicit conversion truncates vector: %0 to %1">, InGroup;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index b86bb242755be..ba78de049ce96 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19836,6 +19836,14 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 RValFalse.isScalar()
 ? RValFalse.getScalarVal()
 : RValFalse.getAggregatePointer(E->getArg(2)->getType(), *this);
+if (auto *VTy = E->getType()->getAs()) {
+  if (!OpTrue->getType()->isVectorTy())
+OpTrue =
+Builder.CreateVectorSplat(VTy->getNumElements(), OpTrue, "splat");
+  if (!OpFalse->getType()->isVectorTy())
+OpFalse =
+Builder.CreateVectorSplat(VTy->getNumElements(), OpFalse, "splat");
+}
 
 Value *SelectVal =
 Builder.CreateSelect(OpCond, OpTrue, OpFalse, "hlsl.select");
diff --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
index 7573f6e024167..7a550a58e705c 100644
--- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
@@ -2123,6 +2123,42 @@ template 
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
 vector select(vector, vector, vector);
 
+
+/// \fn vector select(vector Conds, T TrueVal,
+/// vector FalseVals)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVal The scalar value to splat from when conditions are true.
+/// \param FalseVals The vector values are chosen from when conditions are
+/// false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+vector select(vector, T, vector);
+
+/// \fn vector select(vector Conds, vector TrueVals,
+/// T FalseVal)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVals The vector values are chosen from when conditions are true.
+/// \param FalseVal The scalar value to splat from when conditions are false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+vector select(vector, vector, T);
+
+/// \fn vector select(vector Conds, vector TrueVals,
+/// T FalseVal)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVal The scalar value to splat from when conditions are true.
+/// \param FalseVal The scalar value to splat from when conditions are false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+__detail::enable_if_t<__detail::is_arithmetic::Value, vector> select(
+vector, T, T);
+
 
//===--===//
 // sin builtins
 
//===--===//
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 39254a3cc3a0a..086c527614a43 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -97,6 +97,11 @@ constexpr

[clang] [CIR] Upstream basic support for ArrayType (PR #130502)

2025-03-09 Thread Amr Hesham via cfe-commits

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

This change adds the basic support for ArrayType

Issue #130197

>From 0b00b1b477f7d81220350669ecb43f87d2667a6d Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sun, 9 Mar 2025 19:14:34 +0100
Subject: [PATCH] [CIR] Upstream basic support for ArrayType

---
 clang/include/clang/CIR/Dialect/IR/CIRAttrs.h |  4 
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  | 21 ++-
 clang/lib/CIR/CodeGen/CIRGenBuilder.h |  8 +++
 clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 12 +++
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   |  3 +++
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 16 ++
 clang/test/CIR/CodeGen/array.cpp  | 12 +++
 7 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CIR/CodeGen/array.cpp

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
index 438fb7d09608d..1451ea47c50c8 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
@@ -30,6 +30,10 @@ class VarDecl;
 class RecordDecl;
 } // namespace clang
 
+namespace cir {
+class ArrayType;
+} // namespace cir
+
 #define GET_ATTRDEF_CLASSES
 #include "clang/CIR/Dialect/IR/CIROpsAttributes.h.inc"
 
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index a78e5eae08e33..b2bac643b62da 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -280,6 +280,25 @@ def CIR_BoolType :
   }];
 }
 
+//===--===//
+// ArrayType
+//===--===//
+
+def CIR_ArrayType : CIR_Type<"Array", "array",
+[DeclareTypeInterfaceMethods]> {
+
+  let summary = "CIR array type";
+  let description = [{
+`CIR.array` represents C/C++ constant arrays.
+  }];
+
+  let parameters = (ins "mlir::Type":$eltType, "uint64_t":$size);
+
+  let assemblyFormat = [{
+`<` $eltType `x` $size `>`
+  }];
+}
+
 
//===--===//
 // FuncType
 
//===--===//
@@ -386,7 +405,7 @@ def VoidPtr : Type<
 
//===--===//
 
 def CIR_AnyType : AnyTypeOf<[
-  CIR_VoidType, CIR_BoolType, CIR_IntType, CIR_AnyFloat, CIR_PointerType,
+  CIR_VoidType, CIR_BoolType, CIR_ArrayType, CIR_IntType, CIR_AnyFloat, 
CIR_PointerType,
   CIR_FuncType
 ]>;
 
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index 01d56963883cc..250192ec254d1 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -33,6 +33,14 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
   llvm_unreachable("NYI: PPC double-double format for long double");
 llvm_unreachable("Unsupported format for long double");
   }
+
+  bool isSized(mlir::Type ty) {
+if (mlir::isa(ty))
+  return true;
+assert(0 && "Unimplemented size for type");
+return false;
+  }
 };
 
 } // namespace clang::CIRGen
diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp 
b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
index dcfaaedc2ef57..78e894dee0071 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
@@ -202,6 +202,18 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
 break;
   }
 
+  case Type::ConstantArray: {
+const ConstantArrayType *arrTy = cast(ty);
+mlir::Type elemTy = convertTypeForMem(arrTy->getElementType());
+
+// FIXME: In LLVM, "lower arrays of undefined struct type to arrays of
+// i8 just to have a concrete type". Not sure this makes sense in CIR yet.
+assert(builder.isSized(elemTy) && "not implemented");
+resultType = cir::ArrayType::get(builder.getContext(), elemTy,
+ arrTy->getSize().getZExtValue());
+break;
+  }
+
   case Type::FunctionNoProto:
   case Type::FunctionProto:
 resultType = convertFunctionTypeInternal(type);
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 5ad369b40cda1..1e078e2797270 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -166,6 +166,9 @@ static LogicalResult checkConstantTypes(mlir::Operation 
*op, mlir::Type opType,
 return success();
   }
 
+  if (mlir::isa(opType))
+return success();
+
   assert(isa(attrType) && "What else could we be looking at here?");
   return op->emitOpError("global with type ")
  << cast(attrType).getType() << " not yet supported";
diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp 
b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
index 8b

[clang] [clang] fix matching of nested template template parameters (PR #130447)

2025-03-09 Thread Matheus Izvekov via cfe-commits


@@ -11363,14 +11363,17 @@ class Sema final : public SemaBase {
 
   /// The context in which we are checking a template parameter list.
   enum TemplateParamListContext {
-TPC_ClassTemplate,
-TPC_VarTemplate,
+// For this context, Class, Variable, TypeAlias, and non-pack Template
+// Template
+// Parameters are the same.
+TPC_Normal,

mizvekov wrote:

It isn't used, but every other case is defined by some sort of exception, 
either in the current standard, or previous versions.

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


[clang] [clang] fix matching of nested template template parameters (PR #130447)

2025-03-09 Thread Younan Zhang via cfe-commits


@@ -11363,14 +11363,17 @@ class Sema final : public SemaBase {
 
   /// The context in which we are checking a template parameter list.
   enum TemplateParamListContext {
-TPC_ClassTemplate,
-TPC_VarTemplate,
+// For this context, Class, Variable, TypeAlias, and non-pack Template
+// Template
+// Parameters are the same.
+TPC_Normal,

zyn0217 wrote:

+1 "normal" sounds odd and I suppose it isn't a term used by the standard?

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


[clang] [clang] fix matching of nested template template parameters (PR #130447)

2025-03-09 Thread Younan Zhang via cfe-commits


@@ -11363,14 +11363,17 @@ class Sema final : public SemaBase {
 
   /// The context in which we are checking a template parameter list.
   enum TemplateParamListContext {
-TPC_ClassTemplate,
-TPC_VarTemplate,
+// For this context, Class, Variable, TypeAlias, and non-pack Template
+// Template
+// Parameters are the same.
+TPC_Normal,
+
 TPC_FunctionTemplate,
 TPC_ClassTemplateMember,
 TPC_FriendClassTemplate,
 TPC_FriendFunctionTemplate,
 TPC_FriendFunctionTemplateDefinition,
-TPC_TypeAliasTemplate
+TPC_TemplateTemplateParameterPack

zyn0217 wrote:

nit: Can we have a trailing comma here?

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


[clang-tools-extra] [clang-tidy] support pointee mutation check in misc-const-correctness (PR #130492)

2025-03-09 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

* **#130492** https://app.graphite.dev/github/pr/llvm/llvm-project/130492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/130492?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


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


[clang] [Clang] Implement P0963R3 "Structured binding declaration as a condition" (PR #130228)

2025-03-09 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/130228

>From 295b8173b6913d9014c5786eb4af0112384afa65 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 7 Mar 2025 11:38:11 +0800
Subject: [PATCH 1/3] [Clang] Implement P0963R3 "Structured binding declaration
 as a condition"

---
 clang/include/clang/AST/DeclCXX.h | 23 +++---
 .../clang/Basic/DiagnosticSemaKinds.td|  8 +--
 clang/lib/AST/ASTImporter.cpp |  7 +++---
 clang/lib/AST/DeclCXX.cpp | 21 +---
 clang/lib/AST/ExprConstant.cpp| 24 +++
 clang/lib/CodeGen/CGDecl.cpp  | 13 ++
 clang/lib/CodeGen/CGStmt.cpp  | 17 ++---
 clang/lib/CodeGen/CodeGenFunction.cpp |  7 +-
 clang/lib/CodeGen/CodeGenFunction.h   |  5 +++-
 clang/lib/Sema/SemaDecl.cpp   |  6 ++---
 clang/lib/Sema/SemaDeclCXX.cpp| 17 +++--
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  8 ---
 clang/lib/Serialization/ASTReaderDecl.cpp |  9 ---
 clang/lib/Serialization/ASTWriterDecl.cpp |  1 +
 clang/test/AST/ByteCode/if.cpp|  2 +-
 clang/test/Parser/cxx1z-decomposition.cpp | 12 +-
 clang/test/Parser/decomposed-condition.cpp| 24 +--
 clang/test/SemaCXX/decomposed-condition.cpp   |  4 ++--
 18 files changed, 136 insertions(+), 72 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index dbd02ef7f8011..414a5aea32566 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -4224,15 +4224,18 @@ class DecompositionDecl final
 : public VarDecl,
   private llvm::TrailingObjects {
   /// The number of BindingDecl*s following this object.
-  unsigned NumBindings;
+  unsigned NumBindings : 31;
+
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned IsDecisionVariable : 1;
 
   DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
 SourceLocation LSquareLoc, QualType T,
 TypeSourceInfo *TInfo, StorageClass SC,
-ArrayRef Bindings)
+ArrayRef Bindings, bool IsDecisionVariable)
   : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
 SC),
-NumBindings(Bindings.size()) {
+NumBindings(Bindings.size()), IsDecisionVariable(IsDecisionVariable) {
 std::uninitialized_copy(Bindings.begin(), Bindings.end(),
 getTrailingObjects());
 for (auto *B : Bindings) {
@@ -4253,12 +4256,14 @@ class DecompositionDecl final
 
   static DecompositionDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation StartLoc,
-   SourceLocation LSquareLoc,
-   QualType T, TypeSourceInfo *TInfo,
-   StorageClass S,
-   ArrayRef Bindings);
+   SourceLocation LSquareLoc, QualType T,
+   TypeSourceInfo *TInfo, StorageClass S,
+   ArrayRef Bindings,
+   bool IsDecisionVariable);
+
   static DecompositionDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
-   unsigned NumBindings);
+   unsigned NumBindings,
+   bool IsDecisionVariable);
 
   // Provide the range of bindings which may have a nested pack.
   llvm::ArrayRef bindings() const {
@@ -4285,6 +4290,8 @@ class DecompositionDecl final
 std::move(Bindings));
   }
 
+  bool isDecisionVariable() const { return IsDecisionVariable; }
+
   void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0b121c04cd3c0..fbc91f2eb8dd6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -529,8 +529,12 @@ def warn_cxx14_compat_decomp_decl : Warning<
 def ext_decomp_decl : ExtWarn<
   "decomposition declarations are a C++17 extension">, InGroup;
 def ext_decomp_decl_cond : ExtWarn<
-  "ISO C++17 does not permit structured binding declaration in a condition">,
-  InGroup>;
+  "structured binding declaration in a condition is a C++2c extenstion">,
+  InGroup;
+def warn_cxx26_decomp_decl_cond : Warning<
+  "structured binding declaration in a condition is incompatible with "
+  "C++ standards before C++2c">,
+  InGroup, DefaultIgnore;
 def err_decomp_decl_spec : Error<
   "decomposition decl

[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-03-09 Thread Jonas Paulsson via cfe-commits

JonPsson1 wrote:

> 
> If this is not set, you need to figure out why it is not using the correct 
> host compiler. I think it should be using the clang built from the same 
> sources, which _should_ now support `_Float16` - if it doesn't, this may 
> cause other problems, potentially even explaining the wrong results you're 
> seeing.

It seems that with a completely new build with the new cmake config the test 
actually passes:
  
```
-- Performing Test COMPILER_RT_HAS_s390x_FLOAT16
-- Performing Test COMPILER_RT_HAS_s390x_FLOAT16 - Success
```

I previously got confused here after rerunning cmake in the same folder as I 
thought it was enough to see the newly built clang being used (ninja -v) with 
compiler-rt. It seems maybe cmake itself got confused and used system gcc for 
its checks while building with clang? Anyway, it works now, sorry.

I also found the problem with the miscompile (after some debugging, sigh), that 
the file I copied (extendhfsf.c) has float hard coded as return type, even 
though it defines DST_SINGLE. extendhftf2.c uses dst_t as return type, but I 
see other files using the type directly, so I will leave those files and 
extendhftf2.c as they were. I guess I have a motivating case to use dst_t and 
src_t everywhere, but that's another issue. So the miscompile was due to a 
final conversion from double to float before returning. My bad.

While adding the corresponding (to extendsfdf2_test.c) test I tried inserting 
an obvious error, but this did not cause it to fail, not even with ninja 
check-all, which I thought covered all tests (ninja check-compiler-rt did not 
report it either). How can I run these tests?

I tried building (same way as before) and running the existing 
extendhfsf2_test.c but got:

`error in test__extendhfsf2(0x7e00) = 0.00, expected nan`

This was unexpected, and I get the same error with libgcc.

> By the way, these sites are pretty helpful for double checking float reprs 
> https://float.exposed https://weitz.de/ieee/.

I tried float.exposed but I couldn't really convert an f16 hex to a double hex. 
Is it supposed to be able to do this?



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


[clang] [clang] fix matching of nested template template parameters (PR #130447)

2025-03-09 Thread Younan Zhang via cfe-commits


@@ -11363,14 +11363,17 @@ class Sema final : public SemaBase {
 
   /// The context in which we are checking a template parameter list.
   enum TemplateParamListContext {
-TPC_ClassTemplate,
-TPC_VarTemplate,
+// For this context, Class, Variable, TypeAlias, and non-pack Template
+// Template
+// Parameters are the same.
+TPC_Normal,

zyn0217 wrote:

Oh if that is the case then I don't think I have a better naming option :P

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


[clang-tools-extra] [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (PR #129370)

2025-03-09 Thread David Rivera via cfe-commits


@@ -132,11 +132,15 @@ Changes in existing checks
   ` check by providing additional
   examples and fixing some macro related false positives.
 
+- Improved :doc:`modernize-use-default-member-init

RiverDave wrote:

Done

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


[clang-tools-extra] [clang-tidy] support pointee mutation check in misc-const-correctness (PR #130492)

2025-03-09 Thread via cfe-commits

llvmbot wrote:




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

Author: Congcong Cai (HerrCai0907)


Changes



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


9 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
(+103-55) 
- (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h (+3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst (+44) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp
 (+50) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-values.cpp
 (+1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp
 (+1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
(+1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
 (+4-3) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 6e412e576e5f9..523dfbfd06138 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -13,6 +13,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/Support/Casting.h"
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -39,34 +41,47 @@ ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
 : ClangTidyCheck(Name, Context),
   AnalyzeValues(Options.get("AnalyzeValues", true)),
   AnalyzeReferences(Options.get("AnalyzeReferences", true)),
+  AnalyzePointers(Options.get("AnalyzePointers", true)),
   WarnPointersAsValues(Options.get("WarnPointersAsValues", false)),
+  WarnPointersAsPointers(Options.get("WarnPointersAsPointers", true)),
   TransformValues(Options.get("TransformValues", true)),
   TransformReferences(Options.get("TransformReferences", true)),
   TransformPointersAsValues(
   Options.get("TransformPointersAsValues", false)),
+  TransformPointersAsPointers(
+  Options.get("TransformPointersAsPointers", true)),
   AllowedTypes(
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
-  if (AnalyzeValues == false && AnalyzeReferences == false)
+  if (AnalyzeValues == false && AnalyzeReferences == false &&
+  AnalyzePointers == false)
 this->configurationDiag(
 "The check 'misc-const-correctness' will not "
-"perform any analysis because both 'AnalyzeValues' and "
-"'AnalyzeReferences' are false.");
+"perform any analysis because both 'AnalyzeValues', "
+"'AnalyzeReferences' and 'AnalyzePointers' are false.");
 }
 
 void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AnalyzeValues", AnalyzeValues);
   Options.store(Opts, "AnalyzeReferences", AnalyzeReferences);
+  Options.store(Opts, "AnalyzePointers", AnalyzePointers);
   Options.store(Opts, "WarnPointersAsValues", WarnPointersAsValues);
+  Options.store(Opts, "WarnPointersAsPointers", WarnPointersAsPointers);
 
   Options.store(Opts, "TransformValues", TransformValues);
   Options.store(Opts, "TransformReferences", TransformReferences);
   Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
+  Options.store(Opts, "TransformPointersAsPointers",
+TransformPointersAsPointers);
   Options.store(Opts, "AllowedTypes",
 utils::options::serializeStringList(AllowedTypes));
 }
 
 void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ConstType = hasType(isConstQualified());
+  const auto ConstType = hasType(
+  qualType(isConstQualified(),
+   // pointee check will check the const pointer and const array
+   unless(pointerType()), unless(arrayType(;
+
   const auto ConstReference = hasType(references(isConstQualified()));
   const auto RValueReference = hasType(
   referenceType(anyOf(rValueReferenceType(), 
unless(isSpelledAsLValue();
@@ -124,6 +139,11 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
+  const auto *VarDeclStmt = Result.Nodes.getNodeAs("decl-stmt");
+  // It can not be guaranteed that the variable is declared isolated,
+  // therefore a transformation might effect the other variables as well and
+  // be incorrect.
+  const bool CanBeFixIt = VarDeclStmt != nullptr && 
VarDeclStmt->isSingleDecl();
 
   /// If the variable was declared in a template it might be

[clang] [clang] Reject constexpr-unknown values as constant expressions more consistently (PR #129952)

2025-03-09 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] support pointee mutation check in misc-const-correctness (PR #130492)

2025-03-09 Thread Congcong Cai via cfe-commits

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


[clang] [clang] fix matching of nested template template parameters (PR #130447)

2025-03-09 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/130447

>From b225cdcfcb008ffa80b6f48476665980de66eac0 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 8 Mar 2025 20:32:14 -0300
Subject: [PATCH] [clang] fix matching of nested template template parameters

When checking the template template parameters of template template
parameters, the PartialOrdering context was not correctly propagated.

This also has a few drive-by fixes, such as checking the template parameter
lists of template template parameters, which was previously missing and
would have been it's own bug, but we need to fix it in order to
prevent crashes in error recovery in a simple way.

Fixes #130362
---
 clang/docs/ReleaseNotes.rst   |  7 ++--
 clang/include/clang/Sema/Sema.h   |  9 +++--
 clang/lib/Sema/SemaDecl.cpp   |  2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|  2 +-
 clang/lib/Sema/SemaTemplate.cpp   | 36 ---
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 16 +
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  2 +-
 clang/test/SemaTemplate/cwg2398.cpp   | 17 -
 .../SemaTemplate/temp_arg_template_p0522.cpp  |  3 +-
 clang/unittests/AST/DeclPrinterTest.cpp   | 16 -
 10 files changed, 64 insertions(+), 46 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7859871b0493a..d6627d21e5e3d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -161,8 +161,8 @@ related warnings within the method body.
   ``__attribute__((model("large")))`` on non-TLS globals in x86-64 
compilations.
   This forces the global to be considered small or large in regards to the
   x86-64 code model, regardless of the code model specified for the 
compilation.
-- Clang now emits a warning ``-Wreserved-init-priority`` instead of a hard 
error 
-  when ``__attribute__((init_priority(n)))`` is used with values of n in the 
+- Clang now emits a warning ``-Wreserved-init-priority`` instead of a hard 
error
+  when ``__attribute__((init_priority(n)))`` is used with values of n in the
   reserved range [0, 100]. The warning will be treated as an error by default.
 
 - There is a new ``format_matches`` attribute to complement the existing
@@ -294,6 +294,9 @@ Bug Fixes to C++ Support
   direct-list-initialized from an array is corrected to direct-initialization.
 - Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. 
(#GH127327)
 - Clang now uses the parameter location for abbreviated function templates in 
``extern "C"``. (#GH46386)
+- Fixes matching of nested template template parameters. (#GH130362)
+- Correctly diagnoses template template paramters which have a pack parameter
+  not in the last position.
 
 Improvements to C++ diagnostics
 ^^^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index fdef57e84ee3d..25fd41b20185e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11363,14 +11363,17 @@ class Sema final : public SemaBase {
 
   /// The context in which we are checking a template parameter list.
   enum TemplateParamListContext {
-TPC_ClassTemplate,
-TPC_VarTemplate,
+// For this context, Class, Variable, TypeAlias, and non-pack Template
+// Template
+// Parameters are the same.
+TPC_Other,
+
 TPC_FunctionTemplate,
 TPC_ClassTemplateMember,
 TPC_FriendClassTemplate,
 TPC_FriendFunctionTemplate,
 TPC_FriendFunctionTemplateDefinition,
-TPC_TypeAliasTemplate
+TPC_TemplateTemplateParameterPack,
   };
 
   /// Checks the validity of a template parameter list, possibly
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5716eb61d4ae8..02817775215f7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8165,7 +8165,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
   (D.getCXXScopeSpec().isSet() && DC && DC->isRecord() &&
DC->isDependentContext())
   ? TPC_ClassTemplateMember
-  : TPC_VarTemplate))
+  : TPC_Other))
 NewVD->setInvalidDecl();
 
   // If we are providing an explicit specialization of a static variable
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index fd5f0443fa894..1edbe62f1c79a 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -13586,7 +13586,7 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S, 
AccessSpecifier AS,
 // Merge any previous default template arguments into our parameters,
 // and check the parameter list.
 if (CheckTemplateParameterList(TemplateParams, OldTemplateParams,
-   TPC_TypeAliasTemplate))
+   TPC_Other))
   return nullptr;
 
 TypeAliasTemplateDecl *NewDecl =
diff --git a/cla

[clang] [clang] fix matching of nested template template parameters (PR #130447)

2025-03-09 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/130447

>From 0a41cc6f9e931df2a7dcbcf0ec35b2b7af8ad0d7 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 8 Mar 2025 20:32:14 -0300
Subject: [PATCH] [clang] fix matching of nested template template parameters

When checking the template template parameters of template template
parameters, the PartialOrdering context was not correctly propagated.

This also has a few drive-by fixes, such as checking the template parameter
lists of template template parameters, which was previously missing and
would have been it's own bug, but we need to fix it in order to
prevent crashes in error recovery in a simple way.

Fixes #130362
---
 clang/docs/ReleaseNotes.rst   |  7 ++--
 clang/include/clang/Sema/Sema.h   |  9 +++--
 clang/lib/Sema/SemaDecl.cpp   |  2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|  2 +-
 clang/lib/Sema/SemaTemplate.cpp   | 36 ---
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 16 +
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  2 +-
 clang/test/SemaTemplate/cwg2398.cpp   | 17 -
 .../SemaTemplate/temp_arg_template_p0522.cpp  |  3 +-
 clang/unittests/AST/DeclPrinterTest.cpp   | 16 -
 10 files changed, 64 insertions(+), 46 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7859871b0493a..d6627d21e5e3d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -161,8 +161,8 @@ related warnings within the method body.
   ``__attribute__((model("large")))`` on non-TLS globals in x86-64 
compilations.
   This forces the global to be considered small or large in regards to the
   x86-64 code model, regardless of the code model specified for the 
compilation.
-- Clang now emits a warning ``-Wreserved-init-priority`` instead of a hard 
error 
-  when ``__attribute__((init_priority(n)))`` is used with values of n in the 
+- Clang now emits a warning ``-Wreserved-init-priority`` instead of a hard 
error
+  when ``__attribute__((init_priority(n)))`` is used with values of n in the
   reserved range [0, 100]. The warning will be treated as an error by default.
 
 - There is a new ``format_matches`` attribute to complement the existing
@@ -294,6 +294,9 @@ Bug Fixes to C++ Support
   direct-list-initialized from an array is corrected to direct-initialization.
 - Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. 
(#GH127327)
 - Clang now uses the parameter location for abbreviated function templates in 
``extern "C"``. (#GH46386)
+- Fixes matching of nested template template parameters. (#GH130362)
+- Correctly diagnoses template template paramters which have a pack parameter
+  not in the last position.
 
 Improvements to C++ diagnostics
 ^^^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index fdef57e84ee3d..f60391a7606b7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11363,14 +11363,17 @@ class Sema final : public SemaBase {
 
   /// The context in which we are checking a template parameter list.
   enum TemplateParamListContext {
-TPC_ClassTemplate,
-TPC_VarTemplate,
+// For this context, Class, Variable, TypeAlias, and non-pack Template
+// Template
+// Parameters are the same.
+TPC_Other,
+
 TPC_FunctionTemplate,
 TPC_ClassTemplateMember,
 TPC_FriendClassTemplate,
 TPC_FriendFunctionTemplate,
 TPC_FriendFunctionTemplateDefinition,
-TPC_TypeAliasTemplate
+TPC_TemplateTemplateParameterPack
   };
 
   /// Checks the validity of a template parameter list, possibly
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5716eb61d4ae8..02817775215f7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8165,7 +8165,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
   (D.getCXXScopeSpec().isSet() && DC && DC->isRecord() &&
DC->isDependentContext())
   ? TPC_ClassTemplateMember
-  : TPC_VarTemplate))
+  : TPC_Other))
 NewVD->setInvalidDecl();
 
   // If we are providing an explicit specialization of a static variable
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index fd5f0443fa894..1edbe62f1c79a 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -13586,7 +13586,7 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S, 
AccessSpecifier AS,
 // Merge any previous default template arguments into our parameters,
 // and check the parameter list.
 if (CheckTemplateParameterList(TemplateParams, OldTemplateParams,
-   TPC_TypeAliasTemplate))
+   TPC_Other))
   return nullptr;
 
 TypeAliasTemplateDecl *NewDecl =
diff --git a/clan

[clang-tools-extra] [clang-tidy] support pointee mutation check in misc-const-correctness (PR #130492)

2025-03-09 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy][NFC]clean ConstCorrectnessCheck (PR #130493)

2025-03-09 Thread Congcong Cai via cfe-commits

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


[clang] [clang] fix matching of nested template template parameters (PR #130447)

2025-03-09 Thread via cfe-commits


@@ -11363,14 +11363,17 @@ class Sema final : public SemaBase {
 
   /// The context in which we are checking a template parameter list.
   enum TemplateParamListContext {
-TPC_ClassTemplate,
-TPC_VarTemplate,
+// For this context, Class, Variable, TypeAlias, and non-pack Template
+// Template
+// Parameters are the same.
+TPC_Normal,

cor3ntin wrote:

"Other" is what we use elsewhere

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


[clang-tools-extra] [clang-tidy][NFC]clean ConstCorrectnessCheck (PR #130493)

2025-03-09 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

* **#130494** https://app.graphite.dev/github/pr/llvm/llvm-project/130494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#130493** https://app.graphite.dev/github/pr/llvm/llvm-project/130493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/130493?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


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


[clang-tools-extra] [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (PR #129370)

2025-03-09 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/129370

>From 08049760b837d026fe9a69b8b6019c6d2bed06b1 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Sat, 1 Mar 2025 02:09:02 -0500
Subject: [PATCH] [clang-tidy] detect arithmetic operations within member list
 initialization in modernize-use-default-member-init

---
 .../modernize/UseDefaultMemberInitCheck.cpp   | 27 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 -
 .../modernize/use-default-member-init.cpp | 26 ++
 3 files changed, 50 insertions(+), 9 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
index 6c06b0af342f6..6ce6c6af3fbb2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -159,6 +159,13 @@ static bool sameValue(const Expr *E1, const Expr *E2) {
   case Stmt::UnaryOperatorClass:
 return sameValue(cast(E1)->getSubExpr(),
  cast(E2)->getSubExpr());
+  case Stmt::BinaryOperatorClass: {
+const auto *BinOp1 = cast(E1);
+const auto *BinOp2 = cast(E2);
+return BinOp1->getOpcode() == BinOp2->getOpcode() &&
+   sameValue(BinOp1->getLHS(), BinOp2->getLHS()) &&
+   sameValue(BinOp1->getRHS(), BinOp2->getRHS());
+  }
   case Stmt::CharacterLiteralClass:
 return cast(E1)->getValue() ==
cast(E2)->getValue();
@@ -194,15 +201,19 @@ void UseDefaultMemberInitCheck::storeOptions(
 }
 
 void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
+  auto NumericLiteral = anyOf(integerLiteral(), floatLiteral());
+  auto UnaryNumericLiteral = unaryOperator(hasAnyOperatorName("+", "-"),
+   hasUnaryOperand(NumericLiteral));
+  auto EnumRef = declRefExpr(to(enumConstantDecl()));
+
+  auto BinaryNumericExpr = binaryOperator(
+  hasOperands(anyOf(NumericLiteral, EnumRef, binaryOperator()),
+  anyOf(NumericLiteral, EnumRef, binaryOperator(;
+
   auto InitBase =
-  anyOf(stringLiteral(), characterLiteral(), integerLiteral(),
-unaryOperator(hasAnyOperatorName("+", "-"),
-  hasUnaryOperand(integerLiteral())),
-floatLiteral(),
-unaryOperator(hasAnyOperatorName("+", "-"),
-  hasUnaryOperand(floatLiteral())),
-cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
-declRefExpr(to(enumConstantDecl(;
+  anyOf(stringLiteral(), characterLiteral(), NumericLiteral,
+UnaryNumericLiteral, cxxBoolLiteral(), cxxNullPtrLiteralExpr(),
+implicitValueInitExpr(), EnumRef, BinaryNumericExpr);
 
   auto Init =
   anyOf(initListExpr(anyOf(allOf(initCountIs(1), hasInit(0, InitBase)),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 951b7f20af4c8..66d2d63eb079b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -136,7 +136,11 @@ Changes in existing checks
   ` check by fix false positives
   for function or variable in header file which contains macro expansion.
 
-- Improved :doc:`performance/unnecessary-value-param
+- Improved :doc:`modernize-use-default-member-init
+  ` check by matching
+  arithmetic operations within member list initialization.
+
+- Improved :doc:`performance-unnecessary-value-param
   ` check performance by
   tolerating fix-it breaking compilation when functions is used as pointers
   to avoid matching usage of functions within the current compilation unit.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
index 81c980e0217e6..ff8c80b682bdb 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
@@ -518,3 +518,29 @@ class ArrayBraceInitMultipleValues {
 };
 
 } // namespace PR63285
+
+namespace PR122480 {
+
+#define ARITHMETIC_MACRO (44 - 2)
+
+class DefaultMemberInitWithArithmetic {
+  DefaultMemberInitWithArithmetic() : a{1 + 1},  b{1 + 11 + 123 + 1234},  c{2 
+ (4 / 2) + 3 + (7 / 11)},  d{ARITHMETIC_MACRO * 2}, e{1.2 + 3.4} {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: member initializer for 'a' is 
redundant [modernize-use-default-member-init]
+  // CHECK-FIXES: DefaultMemberInitWithArithmetic()  {}
+
+  int a{1 + 1};
+  int b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer 
for 'b' [modernize-use-default-member-init]
+  // CHECK-FIXES:  int b{1 + 11 + 123 + 1234};
+  int c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer 
for 'c' [modernize-us

[clang] [clang] fix matching of nested template template parameters (PR #130447)

2025-03-09 Thread Matheus Izvekov via cfe-commits


@@ -11363,14 +11363,17 @@ class Sema final : public SemaBase {
 
   /// The context in which we are checking a template parameter list.
   enum TemplateParamListContext {
-TPC_ClassTemplate,
-TPC_VarTemplate,
+// For this context, Class, Variable, TypeAlias, and non-pack Template
+// Template
+// Parameters are the same.
+TPC_Normal,

mizvekov wrote:

Yep, I was grasping to remember. That's better, thanks.

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


[clang-tools-extra] [clang-tidy] support pointee mutation check in misc-const-correctness (PR #130492)

2025-03-09 Thread Congcong Cai via cfe-commits

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

>From cf55439ce8af415138e618f2d8b4af1180319586 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 9 Mar 2025 16:05:52 +
Subject: [PATCH 1/2] [clang-tidy][NFC]clean ConstCorrectnessCheck

---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp  | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 6e412e576e5f9..dbe59233df699 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -136,16 +136,14 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
 
   VariableCategory VC = VariableCategory::Value;
-  if (Variable->getType()->isReferenceType())
+  const QualType VT = Variable->getType();
+  if (VT->isReferenceType())
 VC = VariableCategory::Reference;
-  if (Variable->getType()->isPointerType())
+  else if (VT->isPointerType())
 VC = VariableCategory::Pointer;
-  if (Variable->getType()->isArrayType()) {
-if (const auto *ArrayT = dyn_cast(Variable->getType())) {
-  if (ArrayT->getElementType()->isPointerType())
-VC = VariableCategory::Pointer;
-}
-  }
+  else if (const auto *ArrayT = dyn_cast(VT))
+if (ArrayT->getElementType()->isPointerType())
+  VC = VariableCategory::Pointer;
 
   // Each variable can only be in one category: Value, Pointer, Reference.
   // Analysis can be controlled for every category.

>From 4c1a7915fca1933773d3e9f3cf0b8c07916f1dcf Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 9 Mar 2025 15:43:37 +
Subject: [PATCH 2/2] [clang-tidy] support pointee mutation check in
 misc-const-correctness

---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp | 156 --
 .../clang-tidy/misc/ConstCorrectnessCheck.h   |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +-
 .../checks/misc/const-correctness.rst |  44 +
 .../const-correctness-pointer-as-pointers.cpp |  50 ++
 .../const-correctness-transform-values.cpp|   1 +
 .../const-correctness-values-before-cxx23.cpp |   1 +
 .../misc/const-correctness-values.cpp |   1 +
 .../misc/const-correctness-wrong-config.cpp   |   7 +-
 9 files changed, 207 insertions(+), 59 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index dbe59233df699..023c834d5700f 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -13,6 +13,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/Support/Casting.h"
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -39,34 +41,47 @@ ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
 : ClangTidyCheck(Name, Context),
   AnalyzeValues(Options.get("AnalyzeValues", true)),
   AnalyzeReferences(Options.get("AnalyzeReferences", true)),
+  AnalyzePointers(Options.get("AnalyzePointers", true)),
   WarnPointersAsValues(Options.get("WarnPointersAsValues", false)),
+  WarnPointersAsPointers(Options.get("WarnPointersAsPointers", true)),
   TransformValues(Options.get("TransformValues", true)),
   TransformReferences(Options.get("TransformReferences", true)),
   TransformPointersAsValues(
   Options.get("TransformPointersAsValues", false)),
+  TransformPointersAsPointers(
+  Options.get("TransformPointersAsPointers", true)),
   AllowedTypes(
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
-  if (AnalyzeValues == false && AnalyzeReferences == false)
+  if (AnalyzeValues == false && AnalyzeReferences == false &&
+  AnalyzePointers == false)
 this->configurationDiag(
 "The check 'misc-const-correctness' will not "
-"perform any analysis because both 'AnalyzeValues' and "
-"'AnalyzeReferences' are false.");
+"perform any analysis because both 'AnalyzeValues', "
+"'AnalyzeReferences' and 'AnalyzePointers' are false.");
 }
 
 void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AnalyzeValues", AnalyzeValues);
   Options.store(Opts, "AnalyzeReferences", AnalyzeReferences);
+  Options.store(Opts, "AnalyzePointers", AnalyzePointers);
   Options.store(Opts, "WarnPointersAsValues", WarnPointersAsValues);
+  Options.store(Opts, "WarnPointersAsPointers", WarnPointersAsPointers);
 
   Options.store(Opts, "TransformValues", TransformValues);
   Options.store(Opts, "TransformReferences", TransformReferences

[clang-tools-extra] [clang-tidy][NFC]clean ConstCorrectnessCheck (PR #130493)

2025-03-09 Thread via cfe-commits

llvmbot wrote:




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

Author: Congcong Cai (HerrCai0907)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp (+6-8) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 6e412e576e5f9..dbe59233df699 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -136,16 +136,14 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
 
   VariableCategory VC = VariableCategory::Value;
-  if (Variable->getType()->isReferenceType())
+  const QualType VT = Variable->getType();
+  if (VT->isReferenceType())
 VC = VariableCategory::Reference;
-  if (Variable->getType()->isPointerType())
+  else if (VT->isPointerType())
 VC = VariableCategory::Pointer;
-  if (Variable->getType()->isArrayType()) {
-if (const auto *ArrayT = dyn_cast(Variable->getType())) {
-  if (ArrayT->getElementType()->isPointerType())
-VC = VariableCategory::Pointer;
-}
-  }
+  else if (const auto *ArrayT = dyn_cast(VT))
+if (ArrayT->getElementType()->isPointerType())
+  VC = VariableCategory::Pointer;
 
   // Each variable can only be in one category: Value, Pointer, Reference.
   // Analysis can be controlled for every category.

``




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


[clang-tools-extra] [clang-tidy][NFC]clean ConstCorrectnessCheck (PR #130493)

2025-03-09 Thread Congcong Cai via cfe-commits

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

None

>From cf55439ce8af415138e618f2d8b4af1180319586 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 9 Mar 2025 16:05:52 +
Subject: [PATCH] [clang-tidy][NFC]clean ConstCorrectnessCheck

---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp  | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 6e412e576e5f9..dbe59233df699 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -136,16 +136,14 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
 
   VariableCategory VC = VariableCategory::Value;
-  if (Variable->getType()->isReferenceType())
+  const QualType VT = Variable->getType();
+  if (VT->isReferenceType())
 VC = VariableCategory::Reference;
-  if (Variable->getType()->isPointerType())
+  else if (VT->isPointerType())
 VC = VariableCategory::Pointer;
-  if (Variable->getType()->isArrayType()) {
-if (const auto *ArrayT = dyn_cast(Variable->getType())) {
-  if (ArrayT->getElementType()->isPointerType())
-VC = VariableCategory::Pointer;
-}
-  }
+  else if (const auto *ArrayT = dyn_cast(VT))
+if (ArrayT->getElementType()->isPointerType())
+  VC = VariableCategory::Pointer;
 
   // Each variable can only be in one category: Value, Pointer, Reference.
   // Analysis can be controlled for every category.

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


[clang-tools-extra] [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (PR #129370)

2025-03-09 Thread David Rivera via cfe-commits

RiverDave wrote:

> LGTM, but please address a nit

Should be done now, thanks!

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


[clang] [HLSL] select scalar overloads for vector conditions (PR #129396)

2025-03-09 Thread Chris B via cfe-commits

https://github.com/llvm-beanz updated 
https://github.com/llvm/llvm-project/pull/129396

>From 7620f9fac9932a13f1da0468b02c1aeceb212a0b Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Wed, 19 Feb 2025 17:18:20 -0600
Subject: [PATCH 1/4] [HLSL] select scalar overloads for vector conditions

This PR adds scalar/vector overloads for vector conditions to the
`select` builtin, and updates the sema checking and codegen to allow
scalars to extend to vectors.

Fixes #126570

clang-format
clang-format
'cbieneman/select' on '44f0fe9a2806'.
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  8 ++
 .../lib/Headers/hlsl/hlsl_alias_intrinsics.h  | 36 +++
 clang/lib/Headers/hlsl/hlsl_detail.h  |  5 +
 clang/lib/Sema/SemaHLSL.cpp   | 56 ++-
 clang/test/CodeGenHLSL/builtins/select.hlsl   | 29 ++
 .../test/SemaHLSL/BuiltIns/select-errors.hlsl | 98 +--
 7 files changed, 135 insertions(+), 100 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 21be7c358a61d..2514fb68bf5b0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12707,6 +12707,9 @@ def err_hlsl_param_qualifier_mismatch :
 def err_hlsl_vector_compound_assignment_truncation : Error<
   "left hand operand of type %0 to compound assignment cannot be truncated "
   "when used with right hand operand of type %1">;
+def err_hlsl_builtin_scalar_vector_mismatch : Error<
+  "%select{all|second and third}0 arguments to %1 must be of scalar or "
+  "vector type with matching scalar element type%diff{: $ vs $|}2,3">;
 
 def warn_hlsl_impcast_vector_truncation : Warning<
   "implicit conversion truncates vector: %0 to %1">, InGroup;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index b86bb242755be..ba78de049ce96 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19836,6 +19836,14 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 RValFalse.isScalar()
 ? RValFalse.getScalarVal()
 : RValFalse.getAggregatePointer(E->getArg(2)->getType(), *this);
+if (auto *VTy = E->getType()->getAs()) {
+  if (!OpTrue->getType()->isVectorTy())
+OpTrue =
+Builder.CreateVectorSplat(VTy->getNumElements(), OpTrue, "splat");
+  if (!OpFalse->getType()->isVectorTy())
+OpFalse =
+Builder.CreateVectorSplat(VTy->getNumElements(), OpFalse, "splat");
+}
 
 Value *SelectVal =
 Builder.CreateSelect(OpCond, OpTrue, OpFalse, "hlsl.select");
diff --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
index 7573f6e024167..7a550a58e705c 100644
--- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
@@ -2123,6 +2123,42 @@ template 
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
 vector select(vector, vector, vector);
 
+
+/// \fn vector select(vector Conds, T TrueVal,
+/// vector FalseVals)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVal The scalar value to splat from when conditions are true.
+/// \param FalseVals The vector values are chosen from when conditions are
+/// false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+vector select(vector, T, vector);
+
+/// \fn vector select(vector Conds, vector TrueVals,
+/// T FalseVal)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVals The vector values are chosen from when conditions are true.
+/// \param FalseVal The scalar value to splat from when conditions are false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+vector select(vector, vector, T);
+
+/// \fn vector select(vector Conds, vector TrueVals,
+/// T FalseVal)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVal The scalar value to splat from when conditions are true.
+/// \param FalseVal The scalar value to splat from when conditions are false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+__detail::enable_if_t<__detail::is_arithmetic::Value, vector> select(
+vector, T, T);
+
 
//===--===//
 // sin builtins
 
//===--===//
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 39254a3cc3a0a..086c527614a43 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -97,6 +97,11 @@ constexpr

[clang] [alpha.webkit.NoUnretainedMemberChecker] Add a new WebKit checker for unretained member variables and ivars. (PR #128641)

2025-03-09 Thread Ryosuke Niwa via cfe-commits


@@ -0,0 +1,57 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.NoUnretainedMemberChecker -verify %s
+
+#include "objc-mock-types.h"
+
+namespace members {
+
+  struct Foo {
+  private:
+SomeObj* a = nullptr;
+// expected-warning@-1{{Member variable 'a' in 'members::Foo' is a raw pointer 
to retainable type}}
+
+[[clang::suppress]]

rniwa wrote:

Done that.

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


[clang] [alpha.webkit.NoUnretainedMemberChecker] Add a new WebKit checker for unretained member variables and ivars. (PR #128641)

2025-03-09 Thread Ryosuke Niwa via cfe-commits

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

>From a4cd301d6176a8ee3441d0c74f6d2c4e32a50cdd Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 24 Feb 2025 23:01:31 -0800
Subject: [PATCH 1/3] [alpha.webkit.NoUnretainedMemberChecker] Add a new WebKit
 checker for unretained member variables and ivars.

Add a new WebKit checker for member variables and instance variables of NS and 
CF types.
A member variable or instance variable to a CF type should be RetainPtr 
regardless of whether
ARC is enabled or disabled, and that of a NS type should be RetainPtr when ARC 
is disabled.
---
 clang/docs/analyzer/checkers.rst  |  13 ++
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../WebKit/RawPtrRefMemberChecker.cpp | 117 +++---
 .../Checkers/WebKit/unretained-members-arc.mm |  39 ++
 .../Checkers/WebKit/unretained-members.mm |  57 +
 5 files changed, 210 insertions(+), 20 deletions(-)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/unretained-members-arc.mm
 create mode 100644 clang/test/Analysis/Checkers/WebKit/unretained-members.mm

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index c1eedb33e74d2..78372c3f1ca66 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3487,6 +3487,19 @@ Raw pointers and references to an object which supports 
CheckedPtr or CheckedRef
 
 See `WebKit Guidelines for Safer C++ Programming 
`_ for details.
 
+alpha.webkit.NoUnretainedMemberChecker
+
+Raw pointers and references to a NS or CF object can't be used as class 
members or ivars. Only RetainPtr is allowed.
+
+.. code-block:: cpp
+
+ struct Foo {
+   NSObject *ptr; // warn
+   // ...
+ };
+
+See `WebKit Guidelines for Safer C++ Programming 
`_ for details.
+
 .. _alpha-webkit-UncountedCallArgsChecker:
 
 alpha.webkit.UncountedCallArgsChecker
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 410f841630660..578b377cb0849 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1766,6 +1766,10 @@ def NoUncheckedPtrMemberChecker : 
Checker<"NoUncheckedPtrMemberChecker">,
   HelpText<"Check for no unchecked member variables.">,
   Documentation;
 
+def NoUnretainedMemberChecker : Checker<"NoUnretainedMemberChecker">,
+  HelpText<"Check for no unretained member variables.">,
+  Documentation;
+
 def UncountedCallArgsChecker : Checker<"UncountedCallArgsChecker">,
   HelpText<"Check uncounted call arguments.">,
   Documentation;
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index 963f59831c8ed..0e0fd95e1d79d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -31,12 +31,16 @@ class RawPtrRefMemberChecker
   BugType Bug;
   mutable BugReporter *BR;
 
+protected:
+  mutable std::optional RTC;
+
 public:
   RawPtrRefMemberChecker(const char *description)
   : Bug(this, description, "WebKit coding guidelines") {}
 
   virtual std::optional
-  isPtrCompatible(const clang::CXXRecordDecl *) const = 0;
+  isPtrCompatible(const clang::QualType,
+  const clang::CXXRecordDecl *R) const = 0;
   virtual bool isPtrCls(const clang::CXXRecordDecl *) const = 0;
   virtual const char *typeName() const = 0;
   virtual const char *invariant() const = 0;
@@ -57,6 +61,12 @@ class RawPtrRefMemberChecker
 ShouldVisitImplicitCode = false;
   }
 
+  bool VisitTypedefDecl(const TypedefDecl *TD) override {
+if (Checker->RTC)
+  Checker->RTC->visitTypedef(TD);
+return true;
+  }
+
   bool VisitRecordDecl(const RecordDecl *RD) override {
 Checker->visitRecordDecl(RD);
 return true;
@@ -69,6 +79,8 @@ class RawPtrRefMemberChecker
 };
 
 LocalVisitor visitor(this);
+if (RTC)
+  RTC->visitTranslationUnitDecl(TUD);
 visitor.TraverseDecl(TUD);
   }
 
@@ -77,16 +89,22 @@ class RawPtrRefMemberChecker
   return;
 
 for (auto *Member : RD->fields()) {
-  const Type *MemberType = Member->getType().getTypePtrOrNull();
+  auto QT = Member->getType();
+  const Type *MemberType = QT.getTypePtrOrNull();
   if (!MemberType)
 continue;
 
   if (auto *MemberCXXRD = MemberType->getPointeeCXXRecordDecl()) {
-// If we don't see the definition we just don't know.
-if (MemberCXXRD->hasDefinition()) {
-  std::optional isRCAble = isPtrCompatible(MemberCXXRD);
-  if (isRCAble && *isRCAble)
-reportBug(Member, Memb

[clang] [alpha.webkit.NoUnretainedMemberChecker] Add a new WebKit checker for unretained member variables and ivars. (PR #128641)

2025-03-09 Thread Ryosuke Niwa via cfe-commits


@@ -3487,6 +3487,19 @@ Raw pointers and references to an object which supports 
CheckedPtr or CheckedRef
 
 See `WebKit Guidelines for Safer C++ Programming 
`_ for details.
 
+alpha.webkit.NoUnretainedMemberChecker
+
+Raw pointers and references to a NS or CF object can't be used as class 
members or ivars. Only RetainPtr is allowed.

rniwa wrote:

Sure, added.

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


[clang] [clang][NFC] Clean up Expr::EvaluateAsConstantExpr (PR #130498)

2025-03-09 Thread Timm Baeder via cfe-commits

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

The Info.EnableNewConstInterp case is already handled above.

>From c3a736fbd6f6844053c31fc4599053d1ed647706 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 9 Mar 2025 18:05:48 +0100
Subject: [PATCH] [clang][NFC] Clean up Expr::EvaluateAsConstantExpr

The Info.EnableNewConstInterp case is already handled above.
---
 clang/lib/AST/ExprConstant.cpp | 29 -
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d9a1e5bb42343..759df64da6215 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -16892,24 +16892,19 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   APValue::LValueBase Base(&BaseMTE);
   Info.setEvaluatingDecl(Base, Result.Val);
 
-  if (Info.EnableNewConstInterp) {
-if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, this, Result.Val))
-  return false;
-  } else {
-LValue LVal;
-LVal.set(Base);
-// C++23 [intro.execution]/p5
-// A full-expression is [...] a constant-expression
-// So we need to make sure temporary objects are destroyed after having
-// evaluating the expression (per C++23 [class.temporary]/p4).
-FullExpressionRAII Scope(Info);
-if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
-Result.HasSideEffects || !Scope.destroy())
-  return false;
+  LValue LVal;
+  LVal.set(Base);
+  // C++23 [intro.execution]/p5
+  // A full-expression is [...] a constant-expression
+  // So we need to make sure temporary objects are destroyed after having
+  // evaluating the expression (per C++23 [class.temporary]/p4).
+  FullExpressionRAII Scope(Info);
+  if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
+  Result.HasSideEffects || !Scope.destroy())
+return false;
 
-if (!Info.discardCleanups())
-  llvm_unreachable("Unhandled cleanup; missing full expression marker?");
-  }
+  if (!Info.discardCleanups())
+llvm_unreachable("Unhandled cleanup; missing full expression marker?");
 
   if (!CheckConstantExpression(Info, getExprLoc(), getStorageType(Ctx, this),
Result.Val, Kind))

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


[clang-tools-extra] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-03-09 Thread via cfe-commits

Andrewyuan34 wrote:

@HerrCai0907 Sorry for requesting your approval again, I really have no 
experience sending a PR.  
I appreciate your patience and feedback on my changes. Let me know if there's 
anything else I should improve.  
Thanks for your time! 😊

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


[clang] Forbid co_await and co_yield in invalid expr contexts (PR #130455)

2025-03-09 Thread via cfe-commits

https://github.com/NewSigma updated 
https://github.com/llvm/llvm-project/pull/130455

>From 85a40587375533ac8fcd842395c923895c5debaf Mon Sep 17 00:00:00 2001
From: NewSigma 
Date: Sun, 9 Mar 2025 10:27:24 +0800
Subject: [PATCH 1/2] Fobbid co_await in invalid expr context

---
 clang/lib/Sema/SemaCoroutine.cpp | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index 0e4f3b20c78cd..53536b0d14037 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -788,7 +788,11 @@ static bool checkSuspensionContext(Sema &S, SourceLocation 
Loc,
   // First emphasis of [expr.await]p2: must be a potentially evaluated context.
   // That is, 'co_await' and 'co_yield' cannot appear in subexpressions of
   // \c sizeof.
-  if (S.isUnevaluatedContext()) {
+  const auto ExprContext = S.currentEvaluationContext().ExprContext;
+  const bool BadContext =
+  S.isUnevaluatedContext() ||
+  ExprContext != Sema::ExpressionEvaluationContextRecord::EK_Other;
+  if (BadContext) {
 S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword;
 return false;
   }
@@ -798,7 +802,6 @@ static bool checkSuspensionContext(Sema &S, SourceLocation 
Loc,
 S.Diag(Loc, diag::err_coroutine_within_handler) << Keyword;
 return false;
   }
-
   return true;
 }
 

>From eeb51f2775739390596b69a33eeae17ecf069148 Mon Sep 17 00:00:00 2001
From: NewSigma 
Date: Sun, 9 Mar 2025 19:35:16 +0800
Subject: [PATCH 2/2] Add test for unevaluate context

---
 .../{coroutine-decltype.cpp => coroutine-unevaluate.cpp}  | 8 
 1 file changed, 8 insertions(+)
 rename clang/test/SemaCXX/{coroutine-decltype.cpp => coroutine-unevaluate.cpp} 
(78%)

diff --git a/clang/test/SemaCXX/coroutine-decltype.cpp 
b/clang/test/SemaCXX/coroutine-unevaluate.cpp
similarity index 78%
rename from clang/test/SemaCXX/coroutine-decltype.cpp
rename to clang/test/SemaCXX/coroutine-unevaluate.cpp
index 7cbe6688d4155..164caed2836a1 100644
--- a/clang/test/SemaCXX/coroutine-decltype.cpp
+++ b/clang/test/SemaCXX/coroutine-unevaluate.cpp
@@ -32,3 +32,11 @@ MyTask DoAnotherthing() {
   static_assert(__is_same(void, decltype(co_yield 0))); // expected-error 
{{'co_yield' cannot be used in an unevaluated context}}
   co_return;
 }
+
+template
+struct Task {};
+
+void BracedInitListCXX26() {
+  []() -> Task<{ co_await 1 }> {}; // expected-error {{'co_await' cannot be 
used in an unevaluated context}}
+  []() -> Task<{ co_yield 1 }> {}; // expected-error {{'co_yield' cannot be 
used in an unevaluated context}}
+}

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


[clang] Forbid co_await and co_yield in invalid expr contexts (PR #130455)

2025-03-09 Thread via cfe-commits

NewSigma wrote:

Of course. Please feel free to remind me if I forget anything.

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


[clang] [clang][bytecode] Fix getting pointer element type in __builtin_memcmp (PR #130485)

2025-03-09 Thread Timm Baeder via cfe-commits

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

When such a pointer is heap allocated, the type we get is a pointer type. Take 
the pointee type in that case.

>From eb19b865be45021df556d5dfa247abfb6e129e76 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 9 Mar 2025 12:30:04 +0100
Subject: [PATCH] [clang][bytecode] Fix getting pointer element type in
 __builtin_memcmp

When such a pointer is heap allocated, the type we get is a pointer
type. Take the pointee type in that case.
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  | 14 --
 clang/test/AST/ByteCode/builtin-functions.cpp | 15 +++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index b8c4ef2f48a79..70c7fe5b714cb 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1881,11 +1881,21 @@ static bool interp__builtin_memcmp(InterpState &S, 
CodePtr OpPC,
   bool IsWide =
   (ID == Builtin::BIwmemcmp || ID == Builtin::BI__builtin_wmemcmp);
 
+  auto getElemType = [](const Pointer &P) -> QualType {
+const Descriptor *Desc = P.getFieldDesc();
+QualType T = Desc->getType();
+if (T->isPointerType())
+  return T->getAs()->getPointeeType();
+if (Desc->isArray())
+  return Desc->getElemQualType();
+return T;
+  };
+
   const ASTContext &ASTCtx = S.getASTContext();
   // FIXME: This is an arbitrary limitation the current constant interpreter
   // had. We could remove this.
-  if (!IsWide && (!isOneByteCharacterType(PtrA.getType()) ||
-  !isOneByteCharacterType(PtrB.getType( {
+  if (!IsWide && (!isOneByteCharacterType(getElemType(PtrA)) ||
+  !isOneByteCharacterType(getElemType(PtrB {
 S.FFDiag(S.Current->getSource(OpPC),
  diag::note_constexpr_memcmp_unsupported)
 << ASTCtx.BuiltinInfo.getQuotedName(ID) << PtrA.getType()
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index dbff9164a91c1..29812553af9f0 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1352,6 +1352,21 @@ namespace Memcmp {
   static_assert(__builtin_wmemcmp(L"abab\0banana", L"abab\0canada", 7) == -1);
   static_assert(__builtin_wmemcmp(L"abab\0banana", L"abab\0canada", 6) == -1);
   static_assert(__builtin_wmemcmp(L"abab\0banana", L"abab\0canada", 5) == 0);
+
+#if __cplusplus >= 202002L
+  constexpr bool f() {
+char *c = new char[12];
+c[0] = 'b';
+
+char n = 'a';
+bool b = __builtin_memcmp(c, &n, 1) == 0;
+
+delete[] c;
+return !b;
+  }
+  static_assert(f());
+#endif
+
 }
 
 namespace Memchr {

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


[clang] [clang][bytecode] Fix getting pointer element type in __builtin_memcmp (PR #130485)

2025-03-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

When such a pointer is heap allocated, the type we get is a pointer type. Take 
the pointee type in that case.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+12-2) 
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+15) 


``diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index b8c4ef2f48a79..70c7fe5b714cb 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1881,11 +1881,21 @@ static bool interp__builtin_memcmp(InterpState &S, 
CodePtr OpPC,
   bool IsWide =
   (ID == Builtin::BIwmemcmp || ID == Builtin::BI__builtin_wmemcmp);
 
+  auto getElemType = [](const Pointer &P) -> QualType {
+const Descriptor *Desc = P.getFieldDesc();
+QualType T = Desc->getType();
+if (T->isPointerType())
+  return T->getAs()->getPointeeType();
+if (Desc->isArray())
+  return Desc->getElemQualType();
+return T;
+  };
+
   const ASTContext &ASTCtx = S.getASTContext();
   // FIXME: This is an arbitrary limitation the current constant interpreter
   // had. We could remove this.
-  if (!IsWide && (!isOneByteCharacterType(PtrA.getType()) ||
-  !isOneByteCharacterType(PtrB.getType( {
+  if (!IsWide && (!isOneByteCharacterType(getElemType(PtrA)) ||
+  !isOneByteCharacterType(getElemType(PtrB {
 S.FFDiag(S.Current->getSource(OpPC),
  diag::note_constexpr_memcmp_unsupported)
 << ASTCtx.BuiltinInfo.getQuotedName(ID) << PtrA.getType()
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index dbff9164a91c1..29812553af9f0 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1352,6 +1352,21 @@ namespace Memcmp {
   static_assert(__builtin_wmemcmp(L"abab\0banana", L"abab\0canada", 7) == -1);
   static_assert(__builtin_wmemcmp(L"abab\0banana", L"abab\0canada", 6) == -1);
   static_assert(__builtin_wmemcmp(L"abab\0banana", L"abab\0canada", 5) == 0);
+
+#if __cplusplus >= 202002L
+  constexpr bool f() {
+char *c = new char[12];
+c[0] = 'b';
+
+char n = 'a';
+bool b = __builtin_memcmp(c, &n, 1) == 0;
+
+delete[] c;
+return !b;
+  }
+  static_assert(f());
+#endif
+
 }
 
 namespace Memchr {

``




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


[clang] [clang][bytecode] Fix getting pointer element type in __builtin_memcmp (PR #130485)

2025-03-09 Thread Timm Baeder via cfe-commits

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


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Younan Zhang via cfe-commits


@@ -309,6 +309,7 @@ Bug Fixes to AST Handling
 ^
 - Fixed type checking when a statement expression ends in an l-value of atomic 
type. (#GH106576)
 - Fixed uninitialized use check in a lambda within CXXOperatorCallExpr. 
(#GH129198)
+- Clang now correctly parses ``if constexpr`` expressions in immediate 
function context. (#GH123524)

zyn0217 wrote:

This should go in the "Bug fixes to C++ support" column

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


[clang] [clang][WebAssembly] Support the `-m(no-)red-zone` flag. (PR #119997)

2025-03-09 Thread Alex Rønne Petersen via cfe-commits

alexrp wrote:

@sunfishcode would you mind reviewing this one? (I've pinged a few times here 
but I'm not sure any of the relevant WASM folks are actually seeing it due to 
the labels...)

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


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Oleksandr T. via cfe-commits

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

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/6] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d6..cd16ce13a4e6b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42..e174d9a24e744 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 0..1832086fee42d
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/6] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d..494fc45c55c4e 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

>From bba89e7dc79d4d78a794ccf0e7e5196a22b72820 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:35:54 +0200
Subject: [PATCH 3/6] ensure context is applied only during expression parsing

---
 clang/lib/Parse/ParseExprCXX.cpp | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index e174d9a24e744..5d5e015d548f5 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,14 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
-EnterExpressionEvaluationContext Eval(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
-/*LambdaContextDecl=*/nullptr,
-/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
-/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
-
-// Parse the expression.
-ExprResult Expr = ParseExpression(); // expression
+ExprResult Expr;
+{
+  EnterExpressionEvaluationContext Eval(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+  /*LambdaContextDecl=*/nullptr,
+  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
+  // Parse the expression.
+  Expr = ParseExpression(); // expression
+}
+
 if (Expr.isInvalid())
   return Sema::ConditionError();
 

>From 666d5bf9574fb583f9da27331545c861eed66488 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:36:11 +0200
Subject: [PATCH 4/6] update release notes

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(

[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Oleksandr T. via cfe-commits


@@ -309,6 +309,7 @@ Bug Fixes to AST Handling
 ^
 - Fixed type checking when a statement expression ends in an l-value of atomic 
type. (#GH106576)
 - Fixed uninitialized use check in a lambda within CXXOperatorCallExpr. 
(#GH129198)
+- Clang now correctly parses ``if constexpr`` expressions in immediate 
function context. (#GH123524)

a-tarasyuk wrote:

Thanks. I've moved to `Bug fixes to C++ support` section

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


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Oleksandr T. via cfe-commits

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

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/7] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d6..cd16ce13a4e6b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42..e174d9a24e744 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 0..1832086fee42d
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/7] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d..494fc45c55c4e 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

>From bba89e7dc79d4d78a794ccf0e7e5196a22b72820 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:35:54 +0200
Subject: [PATCH 3/7] ensure context is applied only during expression parsing

---
 clang/lib/Parse/ParseExprCXX.cpp | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index e174d9a24e744..5d5e015d548f5 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,14 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
-EnterExpressionEvaluationContext Eval(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
-/*LambdaContextDecl=*/nullptr,
-/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
-/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
-
-// Parse the expression.
-ExprResult Expr = ParseExpression(); // expression
+ExprResult Expr;
+{
+  EnterExpressionEvaluationContext Eval(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+  /*LambdaContextDecl=*/nullptr,
+  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
+  // Parse the expression.
+  Expr = ParseExpression(); // expression
+}
+
 if (Expr.isInvalid())
   return Sema::ConditionError();
 

>From 666d5bf9574fb583f9da27331545c861eed66488 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:36:11 +0200
Subject: [PATCH 4/7] update release notes

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(

[clang] [llvm] [alpha.webkit.UnretainedLambdaCapturesChecker] Add a WebKit checker for lambda capturing NS or CF types. (PR #128651)

2025-03-09 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

Thanks for the review!

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


[clang] [HLSL] Disallow virtual inheritance and functions (PR #127346)

2025-03-09 Thread Chris B via cfe-commits


@@ -1817,5 +1817,9 @@ def ext_hlsl_access_specifiers : ExtWarn<
   InGroup;
 def err_hlsl_unsupported_component : Error<"invalid component '%0' used; 
expected 'x', 'y', 'z', or 'w'">;
 def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier 
'%0' for packoffset, expected 'c'">;
+def err_hlsl_virtual_function

llvm-beanz wrote:

Unfortunately sharing the diagnostic would require a significant reworking of 
ParseDecl. The diagnostic for virtual functions is not emitted directly at the 
place where we encounter the keyword, instead we set the decl to invalid and 
provide the diagnostic ID. There isn't a way currently to also provide 
diagnostic arguments.

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


[clang] [HLSL] Disallow virtual inheritance and functions (PR #127346)

2025-03-09 Thread Chris B via cfe-commits

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


[clang] [llvm] [alpha.webkit.UnretainedLambdaCapturesChecker] Add a WebKit checker for lambda capturing NS or CF types. (PR #128651)

2025-03-09 Thread Ryosuke Niwa via cfe-commits

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

>From dc53e0602fcec63bdd1bc84325ecc16a3f3e293b Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 24 Feb 2025 23:39:13 -0800
Subject: [PATCH 1/3] [alpha.webkit.UnretainedLambdaCapturesChecker] Add a
 WebKit checker for lambda capturing NS or CF types.

Add a new WebKit checker for checking that lambda captures of CF types use 
RetainPtr either when ARC is
disabled or enabled, and those of NS types use RetainPtr when ARC is disabled.
---
 clang/docs/analyzer/checkers.rst  |  12 +
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   4 +-
 ...cpp => RawPtrRefLambdaCapturesChecker.cpp} | 136 ++--
 .../Checkers/WebKit/objc-mock-types.h | 146 -
 ...mbda-captures-decl-protects-this-crash.cpp |   4 +-
 .../WebKit/uncounted-lambda-captures.cpp  |  34 +-
 .../WebKit/unretained-lambda-captures-arc.mm  | 273 
 .../WebKit/unretained-lambda-captures.mm  | 296 ++
 .../lib/StaticAnalyzer/Checkers/BUILD.gn  |   2 +-
 10 files changed, 851 insertions(+), 60 deletions(-)
 rename 
clang/lib/StaticAnalyzer/Checkers/WebKit/{UncountedLambdaCapturesChecker.cpp => 
RawPtrRefLambdaCapturesChecker.cpp} (77%)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/unretained-lambda-captures-arc.mm
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/unretained-lambda-captures.mm

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index c1eedb33e74d2..57733d45167f5 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3487,6 +3487,18 @@ Raw pointers and references to an object which supports 
CheckedPtr or CheckedRef
 
 See `WebKit Guidelines for Safer C++ Programming 
`_ for details.
 
+alpha.webkit.UnretainedLambdaCapturesChecker
+
+Raw pointers and references to unretained types can't be captured in lambdas. 
Only RetainPtr is allowed.
+
+.. code-block:: cpp
+
+ void foo(NSObject *a, NSObject *b) {
+   [&, a](){ // warn about 'a'
+ do_something(b); // warn about 'b'
+   };
+ };
+
 .. _alpha-webkit-UncountedCallArgsChecker:
 
 alpha.webkit.UncountedCallArgsChecker
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 410f841630660..06aa083671b7a 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1766,6 +1766,10 @@ def NoUncheckedPtrMemberChecker : 
Checker<"NoUncheckedPtrMemberChecker">,
   HelpText<"Check for no unchecked member variables.">,
   Documentation;
 
+def UnretainedLambdaCapturesChecker : 
Checker<"UnretainedLambdaCapturesChecker">,
+  HelpText<"Check unretained lambda captures.">,
+  Documentation;
+
 def UncountedCallArgsChecker : Checker<"UncountedCallArgsChecker">,
   HelpText<"Check uncounted call arguments.">,
   Documentation;
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 5910043440987..9aac200cd7370 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -128,14 +128,14 @@ add_clang_library(clangStaticAnalyzerCheckers
   VLASizeChecker.cpp
   ValistChecker.cpp
   VirtualCallChecker.cpp
-  WebKit/RawPtrRefMemberChecker.cpp
   WebKit/ASTUtils.cpp
   WebKit/MemoryUnsafeCastChecker.cpp
   WebKit/PtrTypesSemantics.cpp
   WebKit/RefCntblBaseVirtualDtorChecker.cpp
   WebKit/RawPtrRefCallArgsChecker.cpp
-  WebKit/UncountedLambdaCapturesChecker.cpp
+  WebKit/RawPtrRefLambdaCapturesChecker.cpp
   WebKit/RawPtrRefLocalVarsChecker.cpp
+  WebKit/RawPtrRefMemberChecker.cpp
 
   LINK_LIBS
   clangAST
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
similarity index 77%
rename from 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
rename to 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
index 506442f352288..314b3dc72c8e5 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp
@@ -21,15 +21,23 @@ using namespace clang;
 using namespace ento;
 
 namespace {
-class UncountedLambdaCapturesChecker
+class RawPtrRefLambdaCapturesChecker
 : public Checker> {
 private:
-  BugType Bug{this, "Lambda capture of uncounted variable",
-  "WebKit coding guidelines"};
+  BugType Bug;
   mutable BugReporter *BR = nullptr;
   TrivialFunctionAnalysis TFA;
 
+protected:
+  mutable std::optional RTC;
+
 public:
+  RawPtrRefLambdaCapturesChecker(const char *des

[clang] [HLSL] Disallow virtual inheritance and functions (PR #127346)

2025-03-09 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-quick` 
running on `linaro-clang-aarch64-quick` while building `clang` at step 5 "ninja 
check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'lit :: googletest-timeout.py' FAILED 

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 9
not env -u FILECHECK_OPTS "/usr/bin/python3.10" 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/llvm/utils/lit/lit.py -j1 
--order=lexical -v Inputs/googletest-timeout--param 
gtest_filter=InfiniteLoopSubTest --timeout=1 > 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/Output/googletest-timeout.py.tmp.cmd.out
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3.10 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/llvm/utils/lit/lit.py -j1 
--order=lexical -v Inputs/googletest-timeout --param 
gtest_filter=InfiniteLoopSubTest --timeout=1
# .---command stderr
# | lit.py: 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 1 seconds was requested on the command line. Forcing 
timeout to be 1 seconds.
# `-
# RUN: at line 11
FileCheck --check-prefix=CHECK-INF < 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/Output/googletest-timeout.py.tmp.cmd.out
 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/googletest-timeout.py
# executed command: FileCheck --check-prefix=CHECK-INF 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/googletest-timeout.py
# .---command stderr
# | 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/googletest-timeout.py:34:14:
 error: CHECK-INF: expected string not found in input
# | # CHECK-INF: Timed Out: 1
# |  ^
# | :13:29: note: scanning from here
# | Reached timeout of 1 seconds
# | ^
# | :37:2: note: possible intended match here
# |  Timed Out: 2 (100.00%)
# |  ^
# | 
# | Input file: 
# | Check file: 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/googletest-timeout.py
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# | .
# | .
# | .
# | 8:  
# | 9:  
# |10: -- 
# |11: exit: -9 
# |12: -- 
# |13: Reached timeout of 1 seconds 
# | check:34'0 X error: no match found
# |14:  
# | check:34'0 ~
# |15: TIMEOUT: googletest-timeout :: DummySubDir/OneTest.py/1/2 (2 
of 2) 
# | check:34'0 
~~~
# |16:  TEST 'googletest-timeout :: 
DummySubDir/OneTest.py/1/2' FAILED  
# | check:34'0 
~
# |17: Script(shard): 
# | check:34'0 ~~~
...

```



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


[clang] [clang] Fix typos in options text. (PR #130129)

2025-03-09 Thread Ryan Mansfield via cfe-commits

https://github.com/rjmansfield created 
https://github.com/llvm/llvm-project/pull/130129

None

>From 1e3acaedf9e6a163c737c7ae279339be8d2ec7bc Mon Sep 17 00:00:00 2001
From: Ryan Mansfield 
Date: Thu, 6 Mar 2025 11:03:22 -0500
Subject: [PATCH] [clang] Fix typos in options text.

---
 clang/include/clang/Basic/LangOptions.def | 2 +-
 clang/include/clang/Driver/Options.td | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 383440ddbc0ea..d6748f8ede36f 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -515,7 +515,7 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
 // on large _BitInts.
 BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
 
-COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process 
statements"
+COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process 
statements "
 "on the global scope, ignore EOF token and continue later on (thus "
 "avoid tearing the Lexer and etc. down). Controlled by "
 "-fincremental-extensions.")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d0414aba35209..02844be2205aa 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -876,7 +876,7 @@ def Wa_COMMA : CommaJoined<["-"], "Wa,">,
   MetaVarName<"">;
 def warning_suppression_mappings_EQ : Joined<["--"],
   "warning-suppression-mappings=">, Group,
-  HelpText<"File containing diagnostic suppresion mappings. See user manual "
+  HelpText<"File containing diagnostic suppression mappings. See user manual "
   "for file format.">, Visibility<[ClangOption, CC1Option]>;
 def Wall : Flag<["-"], "Wall">, Group, Flags<[HelpHidden]>,
   Visibility<[ClangOption, CC1Option, FlangOption]>;
@@ -941,7 +941,7 @@ def Xarch__
   target matches the specified architecture. This can be used with the target
   CPU, triple architecture, or offloading host and device. It is most useful
   for separating behavior undesirable on one of the targets when combining many
-  compilation jobs, as is commong with offloading. For example, -Xarch_x86_64,
+  compilation jobs, as is common with offloading. For example, -Xarch_x86_64,
   -Xarch_gfx90a, and -Xarch_device are all valid selectors. -Xarch_device will
   forward the argument to the offloading device while -Xarch_host will target
   the host system, which can be used to suppress incompatible GPU 
arguments.}]>,
@@ -1678,7 +1678,7 @@ def fsample_profile_use_profi : Flag<["-"], 
"fsample-profile-use-profi">,
 HelpText<"Use profi to infer block and edge counts">,
 DocBrief<[{Infer block and edge counts. If the profiles have errors or 
missing
blocks caused by sampling, profile inference (profi) can convert
-   basic block counts to branch probabilites to fix them by 
extended
+   basic block counts to branch probabilities to fix them by 
extended
and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
 def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, 
Group;
 def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group,

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


[clang] [llvm] [Support] Remove output file checks from `LockFileManager` (PR #130395)

2025-03-09 Thread Michael Spencer via cfe-commits

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

lgtm. This makes a lot more sense.

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


[clang] Fix mtp (PR #130022)

2025-03-09 Thread via cfe-commits

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


[clang] [clang][bytecode] Implement __builtin_{memchr,strchr,char_memchr} (PR #130420)

2025-03-09 Thread Nikolas Klauser via cfe-commits


@@ -1960,13 +1960,103 @@ static bool interp__builtin_memcmp(InterpState &S, 
CodePtr OpPC,
 
   // However, if we read all the available bytes but were instructed to read
   // even more, diagnose this as a "read of dereferenced one-past-the-end
-  // pointer". This is what would happen if we called CheckRead() on every 
array
+  // pointer". This is what would happen if we called CheckLoad() on every 
array
   // element.
   S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_past_end)
   << AK_Read << S.Current->getRange(OpPC);
   return false;
 }
 
+static bool interp__builtin_memchr(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call) 
{
+  unsigned ID = Func->getBuiltinID();
+  if (ID == Builtin::BImemchr || ID == Builtin::BIwcschr ||
+  ID == Builtin::BIstrchr || ID == Builtin::BIwmemchr)
+diagnoseNonConstexprBuiltin(S, OpPC, ID);
+
+  const Pointer &Ptr = getParam(Frame, 0);
+  APSInt Desired;
+  std::optional MaxLength;
+  if (Call->getNumArgs() == 3) {
+MaxLength =
+peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)), 0);
+Desired = peekToAPSInt(
+S.Stk, *S.getContext().classify(Call->getArg(1)),
+align(primSize(*S.getContext().classify(Call->getArg(2 +
+align(primSize(*S.getContext().classify(Call->getArg(1);
+  } else {
+Desired = peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(1)));
+  }
+
+  if (MaxLength && MaxLength->isZero()) {
+S.Stk.push();
+return true;
+  }
+
+  if (Ptr.isDummy())
+return false;
+
+  // Null is only okay if the given size is 0.
+  if (Ptr.isZero()) {
+S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_null)
+<< AK_Read;
+return false;
+  }
+
+  QualType ElemTy = Ptr.getFieldDesc()->isArray()
+? Ptr.getFieldDesc()->getElemQualType()
+: Ptr.getFieldDesc()->getType();
+  bool IsRawByte = ID == Builtin::BImemchr || ID == 
Builtin::BI__builtin_memchr;
+
+  // Give up on byte-oriented matching against multibyte elements.
+  if (IsRawByte && !isOneByteCharacterType(ElemTy)) {
+S.FFDiag(S.Current->getSource(OpPC),
+ diag::note_constexpr_memchr_unsupported)
+<< S.getASTContext().BuiltinInfo.getQuotedName(ID) << ElemTy;
+return false;
+  }
+
+  if (ID == Builtin::BIstrchr || ID == Builtin::BI__builtin_strchr) {
+// strchr compares directly to the passed integer, and therefore
+// always fails if given an int that is not a char.
+if (Desired !=
+Desired.trunc(S.getASTContext().getCharWidth()).getSExtValue()) {

philnik777 wrote:

Are you sure about this? cppreference seems to disagree with you: 
https://en.cppreference.com/w/cpp/string/byte/strchr

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-03-09 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov commented:

This needs a rebase, I believe because of one of my patches.

Just remove the call to 'S.NoteTemplateParameterLocation(*ParamD);', since that 
note is now emitted automatically.

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-03-09 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-03-09 Thread Matheus Izvekov via cfe-commits


@@ -35,31 +35,27 @@ namespace ConstDestruction {
 
 constexpr ~D() {
   if (!can_destroy)
-throw "oh no"; // expected-note {{subexpression not valid}}
+throw "oh no";
 }
   };
 
-  template
-  void f() {} // expected-note 2{{invalid explicitly-specified argument}}
+  template // expected-note 2{{template parameter is declared here}}
+  void f() {} // expected-note 2{{candidate template ignored: invalid 
explicitly-specified argument}}
 
   void g() {
 f();
 f(); // expected-error {{no matching function}}
   }
 
   // We can SFINAE on constant destruction.
-  template auto h(T t) -> decltype(f());
-  template auto h(T t) -> decltype(f());
+  // template auto h(T t) -> decltype(f());
+  // template auto h(T t) -> decltype(f());
 
   void i() {
-h(D());
+//h(D());
 // Ensure we don't cache an invalid template argument after we've already
 // seen it in a SFINAE context.
 f(); // expected-error {{no matching function}}
 f();
   }
-
-  template struct Z {};
-  Z z1;
-  Z z2; // expected-error {{non-type template argument is not a 
constant expression}} expected-note-re {{in call to '{{.*}}.~D()'}}

mizvekov wrote:

What is up with these commented and removed tests?

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


[clang-tools-extra] [clang-tidy] `modernize-use-trailing-return-type`: add an option to apply to `void`-returning functions as well (PR #129406)

2025-03-09 Thread Baranov Victor via cfe-commits

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

LGTM, few nits

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


[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-03-09 Thread Yanzuo Liu via cfe-commits

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


[clang] 0f73248 - [clang][bytecode] Fix getting pointer element type in __builtin_memcmp (#130485)

2025-03-09 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-09T12:57:42+01:00
New Revision: 0f732481acccb3ac22b70e326feae854cf972126

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

LOG: [clang][bytecode] Fix getting pointer element type in __builtin_memcmp 
(#130485)

When such a pointer is heap allocated, the type we get is a pointer
type. Take the pointee type in that case.

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 14e716daa3f12..3e8a9a77d26bf 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1881,11 +1881,21 @@ static bool interp__builtin_memcmp(InterpState &S, 
CodePtr OpPC,
   bool IsWide =
   (ID == Builtin::BIwmemcmp || ID == Builtin::BI__builtin_wmemcmp);
 
+  auto getElemType = [](const Pointer &P) -> QualType {
+const Descriptor *Desc = P.getFieldDesc();
+QualType T = Desc->getType();
+if (T->isPointerType())
+  return T->getAs()->getPointeeType();
+if (Desc->isArray())
+  return Desc->getElemQualType();
+return T;
+  };
+
   const ASTContext &ASTCtx = S.getASTContext();
   // FIXME: This is an arbitrary limitation the current constant interpreter
   // had. We could remove this.
-  if (!IsWide && (!isOneByteCharacterType(PtrA.getType()) ||
-  !isOneByteCharacterType(PtrB.getType( {
+  if (!IsWide && (!isOneByteCharacterType(getElemType(PtrA)) ||
+  !isOneByteCharacterType(getElemType(PtrB {
 S.FFDiag(S.Current->getSource(OpPC),
  diag::note_constexpr_memcmp_unsupported)
 << ASTCtx.BuiltinInfo.getQuotedName(ID) << PtrA.getType()

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index dbff9164a91c1..29812553af9f0 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1352,6 +1352,21 @@ namespace Memcmp {
   static_assert(__builtin_wmemcmp(L"abab\0banana", L"abab\0canada", 7) == -1);
   static_assert(__builtin_wmemcmp(L"abab\0banana", L"abab\0canada", 6) == -1);
   static_assert(__builtin_wmemcmp(L"abab\0banana", L"abab\0canada", 5) == 0);
+
+#if __cplusplus >= 202002L
+  constexpr bool f() {
+char *c = new char[12];
+c[0] = 'b';
+
+char n = 'a';
+bool b = __builtin_memcmp(c, &n, 1) == 0;
+
+delete[] c;
+return !b;
+  }
+  static_assert(f());
+#endif
+
 }
 
 namespace Memchr {



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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-03-09 Thread Matheus Izvekov via cfe-commits


@@ -3572,10 +3572,17 @@ TemplateDeductionResult 
Sema::SubstituteExplicitTemplateArguments(
 SugaredBuilder, CanonicalBuilder,
 /*UpdateArgsWithConversions=*/false) ||
   Trap.hasErrorOccurred()) {
+
 unsigned Index = SugaredBuilder.size();
 if (Index >= TemplateParams->size())
   return TemplateDeductionResult::SubstitutionFailure;
 Info.Param = makeTemplateParameter(TemplateParams->getParam(Index));
+Info.FirstArg = ExplicitTemplateArgs[Index].getArgument();
+if (ExplicitTemplateArgs[Index].getArgument().getKind() ==
+TemplateArgument::Expression)
+  Info.SecondArg =
+  ExplicitTemplateArgs[Index].getSourceExpression()->getType();

mizvekov wrote:

If you can't, or otherwise this new signature doesn't make sense for the 
pre-existing callers, you should create a new result kind instead.

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


[clang-tools-extra] [clang-tidy] `modernize-use-trailing-return-type`: add an option to apply to `void`-returning functions as well (PR #129406)

2025-03-09 Thread Baranov Victor via cfe-commits


@@ -25,6 +25,14 @@ transforms to:
   inline auto f2(int arg) -> int noexcept;
   virtual auto f3() const && -> float = delete;
 
+Options
+---
+
+.. option:: WarnOnNontrailingVoid
+
+  If the option is set to `true`, the check will apply even to function 
signatures

vbvictor wrote:

Please, make lines no more than 80 characters long.

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


[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

2025-03-09 Thread Baranov Victor via cfe-commits

vbvictor wrote:

Ping @HerrCai0907, could you please address 
https://github.com/llvm/llvm-project/pull/121291#issuecomment-2702153354. Thank 
you!
Can I ask someone to grant me write access to repository?
Since you basically the only one who merges PRs of other people, this could 
lower amount of work you need to do.
Also, I'd be happy to help new contributors in merging their PRs. 

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


[clang] Forbid co_await and co_yield in invalid expr contexts (PR #130455)

2025-03-09 Thread via cfe-commits

cor3ntin wrote:

Can you add some tests? Thanks!

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


[clang] Forbid co_await and co_yield in invalid expr contexts (PR #130455)

2025-03-09 Thread via cfe-commits

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


[clang] [clang][analyzer][NFC] Fix typos in comments (PR #130456)

2025-03-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ben Shi (benshi001)


Changes



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


6 Files Affected:

- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h (+3-3) 
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
(+1-1) 
- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h (+3-3) 
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
(+8-8) 
- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h (+2-3) 
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h 
(+1-1) 


``diff
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
index 168983fd5cb68..bb33a6912bec7 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -7,7 +7,7 @@
 
//===--===//
 //
 //  This file defines CheckerContext that provides contextual info for
-// path-sensitive checkers.
+//  path-sensitive checkers.
 //
 
//===--===//
 
@@ -152,7 +152,7 @@ class CheckerContext {
   }
 
   /// Returns true if the value of \p E is greater than or equal to \p
-  /// Val under unsigned comparison
+  /// Val under unsigned comparison.
   bool isGreaterOrEqual(const Expr *E, unsigned long long Val);
 
   /// Returns true if the value of \p E is negative.
@@ -392,7 +392,7 @@ class CheckerContext {
   /// hardened variant that's not yet covered by it.
   static bool isHardenedVariantOf(const FunctionDecl *FD, StringRef Name);
 
-  /// Depending on wither the location corresponds to a macro, return
+  /// Depending on whether the location corresponds to a macro, return
   /// either the macro name or the token spelling.
   ///
   /// This could be useful when checkers' logic depends on whether a function
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 80b79fd4e928f..b2b4e8729af25 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -156,7 +156,7 @@ class CoreEngine {
   void dispatchWorkItem(ExplodedNode* Pred, ProgramPoint Loc,
 const WorkListUnit& WU);
 
-  // Functions for external checking of whether we have unfinished work
+  // Functions for external checking of whether we have unfinished work.
   bool wasBlockAborted() const { return !blocksAborted.empty(); }
   bool wasBlocksExhausted() const { return !blocksExhausted.empty(); }
   bool hasWorkRemaining() const { return wasBlocksExhausted() ||
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
index 2fb05ac46e8fa..967b25e5696f6 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
@@ -7,7 +7,7 @@
 
//===--===//
 //
 //  This file defines the template classes ExplodedNode and ExplodedGraph,
-//  which represent a path-sensitive, intra-procedural "exploded graph."
+//  which represent a path-sensitive, intra-procedural "exploded graph".
 //  See "Precise interprocedural dataflow analysis via graph reachability"
 //  by Reps, Horwitz, and Sagiv
 //  (http://portal.acm.org/citation.cfm?id=199462) for the definition of an
@@ -426,8 +426,8 @@ class ExplodedGraph {
   ///
   /// \param Nodes The nodes which must appear in the final graph. Presumably
   ///  these are end-of-path nodes (i.e. they have no successors).
-  /// \param[out] ForwardMap A optional map from nodes in this graph to nodes 
in
-  ///the returned graph.
+  /// \param[out] ForwardMap An optional map from nodes in this graph to nodes
+  ///in the returned graph.
   /// \param[out] InverseMap An optional map from nodes in the returned graph 
to
   ///nodes in this graph.
   /// \returns The trimmed graph
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index 804fc74b009df..2c95a6d16afe7 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -429,7 +429,7 @@ class ExprEngine {
 
   DataTag::Factory &getDataTags() { return Engine.getDataTags()

[clang-tools-extra] [clang-tidy] `modernize-use-trailing-return-type`: add an option to apply to `void`-returning functions as well (PR #129406)

2025-03-09 Thread Baranov Victor via cfe-commits


@@ -1,4 +1,12 @@
-// RUN: %check_clang_tidy -std=c++14-or-later %s 
modernize-use-trailing-return-type %t -- -- -fdeclspec -fexceptions 
-DCOMMAND_LINE_INT=int
+// RUN: %check_clang_tidy  
  \
+// RUN:   -std=c++14-or-later %s modernize-use-trailing-return-type %t --  
  \
+// RUN:   -- -fdeclspec -fexceptions -DCOMMAND_LINE_INT=int
+// RUN: %check_clang_tidy -check-suffixes=,EVEN-WHEN-VOID  
  \

vbvictor wrote:

Please, use new suffix, not `EVEN-WHEN-VOID`

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


[clang-tools-extra] [clang-tidy] `modernize-use-trailing-return-type`: add an option to apply to `void`-returning functions as well (PR #129406)

2025-03-09 Thread Baranov Victor via cfe-commits

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


[clang-tools-extra] [clang-tidy] 'modernize-use-starts-ends-with': fixed false positives on `find` and `rfind` (PR #129564)

2025-03-09 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor updated 
https://github.com/llvm/llvm-project/pull/129564

>From c3f21bb654d2980955f2c37a5dc7a02a1ced7891 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Mon, 3 Mar 2025 21:00:32 +0300
Subject: [PATCH 1/6] [clang-tidy] fixed false positives on find and rfind

---
 .../modernize/UseStartsEndsWithCheck.cpp  |  7 ---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../checks/modernize/use-starts-ends-with.rst |  1 +
 .../checkers/modernize/use-starts-ends-with.cpp   | 15 +++
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
index ab72c6796bb4c..02a537430 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
@@ -113,9 +113,10 @@ void UseStartsEndsWithCheck::registerMatchers(MatchFinder 
*Finder) {
   const auto OnClassWithEndsWithFunction = ClassTypeWithMethod(
   "ends_with_fun", "ends_with", "endsWith", "endswith", "EndsWith");
 
-  // Case 1: X.find(Y) [!=]= 0 -> starts_with.
+  // Case 1: X.find(Y, [0]) [!=]= 0 -> starts_with.
   const auto FindExpr = cxxMemberCallExpr(
-  anyOf(argumentCountIs(1), hasArgument(1, ZeroLiteral)),
+  anyOf(argumentCountIs(1),
+allOf(argumentCountIs(2), hasArgument(1, ZeroLiteral))),
   callee(
   cxxMethodDecl(hasName("find"), 
ofClass(OnClassWithStartsWithFunction))
   .bind("find_fun")),
@@ -123,7 +124,7 @@ void UseStartsEndsWithCheck::registerMatchers(MatchFinder 
*Finder) {
 
   // Case 2: X.rfind(Y, 0) [!=]= 0 -> starts_with.
   const auto RFindExpr = cxxMemberCallExpr(
-  hasArgument(1, ZeroLiteral),
+  argumentCountIs(2), hasArgument(1, ZeroLiteral),
   callee(cxxMethodDecl(hasName("rfind"),
ofClass(OnClassWithStartsWithFunction))
  .bind("find_fun")),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 07a79d6bbe807..e29598ccf0b43 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -137,6 +137,10 @@ Changes in existing checks
   ` check by fixing false 
negatives
   on ternary operators calling ``std::move``.
 
+- Improved :doc:`modernize-use-starts-ends-with
+  ` check by fixing false
+  positives on methods ``find`` and ``rfind`` called with three arguments.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst
index 78cd900885ac3..bad1952db22f9 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst
@@ -13,6 +13,7 @@ Covered scenarios:
 Expression   Replacement
  -
 ``u.find(v) == 0``   ``u.starts_with(v)``
+``u.find(v, 0) == 0````u.starts_with(v)``
 ``u.rfind(v, 0) != 0``   ``!u.starts_with(v)``
 ``u.compare(0, v.size(), v) == 0``   ``u.starts_with(v)``
 ``u.substr(0, v.size()) == v``   ``u.starts_with(v)``
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-starts-ends-with.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-starts-ends-with.cpp
index 8699ca03ba331..4d61709eff463 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-starts-ends-with.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-starts-ends-with.cpp
@@ -236,6 +236,18 @@ void test(std::string s, std::string_view sv, sub_string 
ss, sub_sub_string sss,
   // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use ends_with
   // CHECK-FIXES: s.ends_with(suffix);
 
+  s.find("a", 0) == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: s.starts_with("a");
+  
+  s.find(s, ZERO) == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: s.starts_with(s);
+
+  s.find(s, 0) == ZERO;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: s.starts_with(s);
+
   struct S {
 std::string s;
   } t;
@@ -261,6 +273,9 @@ void test(std::string s, std::string_view sv, sub_string 
ss, sub_sub_string sss,
 
   #define STRING s
   if (0 == STRING.find("ala")) { /* do something */}
+
+  s.find("aaa", 0, 3) == 0;
+  s.rfind("aaa", std::string::npos, 3) == 0;
 }
 
 void test_substr() {

>From e379faf582f3dea5072f6a7c86a44ea6aeed6749 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Thu, 6 Mar 2025 00:21:16 +0300

[clang-tools-extra] [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (PR #129370)

2025-03-09 Thread Congcong Cai via cfe-commits

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

LGTM

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


[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-03-09 Thread Yanzuo Liu via cfe-commits


@@ -8361,6 +8361,17 @@ class ExprEvaluatorBase
 return false;
 }
 
+// If an assertion fails during constant evaluation, give a specific note 
explaining that
+if (FD->getName() == "__assert_fail") {

zwuis wrote:

The name of corresponding function in Microsoft CRT is `_wassert`.

Can you handle this case?

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


[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-03-09 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis commented:

Thank you for the patch! You should add a release note in 
clang/docs/ReleaseNotes.rst so that users can know the improvement.

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


[clang] [Clang] Implement P0963R3 "Structured binding declaration as a condition" (PR #130228)

2025-03-09 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/130228

>From 295b8173b6913d9014c5786eb4af0112384afa65 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 7 Mar 2025 11:38:11 +0800
Subject: [PATCH 1/2] [Clang] Implement P0963R3 "Structured binding declaration
 as a condition"

---
 clang/include/clang/AST/DeclCXX.h | 23 +++---
 .../clang/Basic/DiagnosticSemaKinds.td|  8 +--
 clang/lib/AST/ASTImporter.cpp |  7 +++---
 clang/lib/AST/DeclCXX.cpp | 21 +---
 clang/lib/AST/ExprConstant.cpp| 24 +++
 clang/lib/CodeGen/CGDecl.cpp  | 13 ++
 clang/lib/CodeGen/CGStmt.cpp  | 17 ++---
 clang/lib/CodeGen/CodeGenFunction.cpp |  7 +-
 clang/lib/CodeGen/CodeGenFunction.h   |  5 +++-
 clang/lib/Sema/SemaDecl.cpp   |  6 ++---
 clang/lib/Sema/SemaDeclCXX.cpp| 17 +++--
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  8 ---
 clang/lib/Serialization/ASTReaderDecl.cpp |  9 ---
 clang/lib/Serialization/ASTWriterDecl.cpp |  1 +
 clang/test/AST/ByteCode/if.cpp|  2 +-
 clang/test/Parser/cxx1z-decomposition.cpp | 12 +-
 clang/test/Parser/decomposed-condition.cpp| 24 +--
 clang/test/SemaCXX/decomposed-condition.cpp   |  4 ++--
 18 files changed, 136 insertions(+), 72 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index dbd02ef7f8011..414a5aea32566 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -4224,15 +4224,18 @@ class DecompositionDecl final
 : public VarDecl,
   private llvm::TrailingObjects {
   /// The number of BindingDecl*s following this object.
-  unsigned NumBindings;
+  unsigned NumBindings : 31;
+
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned IsDecisionVariable : 1;
 
   DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
 SourceLocation LSquareLoc, QualType T,
 TypeSourceInfo *TInfo, StorageClass SC,
-ArrayRef Bindings)
+ArrayRef Bindings, bool IsDecisionVariable)
   : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
 SC),
-NumBindings(Bindings.size()) {
+NumBindings(Bindings.size()), IsDecisionVariable(IsDecisionVariable) {
 std::uninitialized_copy(Bindings.begin(), Bindings.end(),
 getTrailingObjects());
 for (auto *B : Bindings) {
@@ -4253,12 +4256,14 @@ class DecompositionDecl final
 
   static DecompositionDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation StartLoc,
-   SourceLocation LSquareLoc,
-   QualType T, TypeSourceInfo *TInfo,
-   StorageClass S,
-   ArrayRef Bindings);
+   SourceLocation LSquareLoc, QualType T,
+   TypeSourceInfo *TInfo, StorageClass S,
+   ArrayRef Bindings,
+   bool IsDecisionVariable);
+
   static DecompositionDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
-   unsigned NumBindings);
+   unsigned NumBindings,
+   bool IsDecisionVariable);
 
   // Provide the range of bindings which may have a nested pack.
   llvm::ArrayRef bindings() const {
@@ -4285,6 +4290,8 @@ class DecompositionDecl final
 std::move(Bindings));
   }
 
+  bool isDecisionVariable() const { return IsDecisionVariable; }
+
   void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0b121c04cd3c0..fbc91f2eb8dd6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -529,8 +529,12 @@ def warn_cxx14_compat_decomp_decl : Warning<
 def ext_decomp_decl : ExtWarn<
   "decomposition declarations are a C++17 extension">, InGroup;
 def ext_decomp_decl_cond : ExtWarn<
-  "ISO C++17 does not permit structured binding declaration in a condition">,
-  InGroup>;
+  "structured binding declaration in a condition is a C++2c extenstion">,
+  InGroup;
+def warn_cxx26_decomp_decl_cond : Warning<
+  "structured binding declaration in a condition is incompatible with "
+  "C++ standards before C++2c">,
+  InGroup, DefaultIgnore;
 def err_decomp_decl_spec : Error<
   "decomposition decl

[clang] [Clang] Implement P0963R3 "Structured binding declaration as a condition" (PR #130228)

2025-03-09 Thread Younan Zhang via cfe-commits


@@ -4285,6 +4290,8 @@ class DecompositionDecl final
 std::move(Bindings));
   }
 
+  bool isDecisionVariable() const { return IsDecisionVariable; }

zyn0217 wrote:

Done, I was referring to https://eel.is/c++draft/dcl.struct.bind#4.sentence-1

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


[clang] [Clang] Implement P0963R3 "Structured binding declaration as a condition" (PR #130228)

2025-03-09 Thread Younan Zhang via cfe-commits

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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-03-09 Thread Jonas Paulsson via cfe-commits


@@ -0,0 +1,27 @@
+//===-- lib/extendhfdf2.c - half -> single conversion -*- C 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#define SRC_HALF
+#define DST_DOUBLE
+#include "fp_extend_impl.inc"
+
+// Use a forwarding definition and noinline to implement a poor man's alias,
+// as there isn't a good cross-platform way of defining one.
+COMPILER_RT_ABI NOINLINE float __extendhfdf2(src_t a) {
+  return __extendXfYf2__(a);
+}
+
+COMPILER_RT_ABI float __gnu_h2d_ieee(src_t a) { return __extendhfdf2(a); }

JonPsson1 wrote:

ok - removed.

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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-03-09 Thread Trevor Gross via cfe-commits

tgross35 wrote:

> > By the way, these sites are pretty helpful for double checking float reprs 
> > https://float.exposed https://weitz.de/ieee/.
> 
> I tried float.exposed but I couldn't really convert an f16 hex to a double 
> hex. Is it supposed to be able to do this?

It should, on the `half` page you can paste the int repr into "Raw Hexadecimal 
Integer Value", then click `float` or `double` at the top. I don't use it too 
much for that though, mostly exploding into sign/exponent/mantissa when 
debugging soft floats. 

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


[clang] [HLSL] Disallow virtual inheritance and functions (PR #127346)

2025-03-09 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-s390x-linux-lnt` 
running on `systemz-1` while building `clang` at step 7 "ninja check 1".

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


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

```
Step 7 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'libFuzzer-s390x-default-Linux :: 
fuzzer-timeout.test' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer
  
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
+ /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
RUN: at line 2: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer
  
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest
+ /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest
RUN: at line 3: not  
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 2>&1 | FileCheck 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test
 --check-prefix=TimeoutTest
+ not 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1
+ FileCheck 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test
 --check-prefix=TimeoutTest
RUN: at line 12: not  
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/hi.txt
 2>&1 | FileCheck 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test
 --check-prefix=SingleInputTimeoutTest
+ not 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/hi.txt
+ FileCheck 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test
 --check-prefix=SingleInputTimeoutTest
RUN: at line 16: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 -timeout_exitcode=0
+ 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 -timeout_exitcode=0
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 25640769

[clang-tools-extra] added Conflicting Global Accesses checker (PR #130421)

2025-03-09 Thread via cfe-commits

https://github.com/ConcreteCactus updated 
https://github.com/llvm/llvm-project/pull/130421

>From 290d0db1ddad65a4162bca367dd0807c039d8a42 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81ron=20H=C3=A1rn=C3=A1si?= 
Date: Fri, 22 Nov 2024 21:43:04 +0100
Subject: [PATCH] Added Conflicting Global Accesses checker

This checker attempts to detect unsequenced accesses to global
variables. It recurses into function calls in the same translation unit,
and can handle fields on global structs/unions.
---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 .../bugprone/ConflictingGlobalAccesses.cpp| 728 ++
 .../bugprone/ConflictingGlobalAccesses.h  |  61 ++
 .../bugprone/conflicting-global-accesses.cpp  | 267 +++
 5 files changed, 1060 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ConflictingGlobalAccesses.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ConflictingGlobalAccesses.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/conflicting-global-accesses.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 0a3376949b6e5..5418e718a404e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -19,6 +19,7 @@
 #include "CastingThroughVoidCheck.h"
 #include "ChainedComparisonCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
+#include "ConflictingGlobalAccesses.h"
 #include "CopyConstructorInitCheck.h"
 #include "CrtpConstructorAccessibilityCheck.h"
 #include "DanglingHandleCheck.h"
@@ -124,6 +125,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-chained-comparison");
 CheckFactories.registerCheck(
 "bugprone-compare-pointer-to-member-virtual-function");
+CheckFactories.registerCheck(
+"bugprone-conflicting-global-accesses");
 CheckFactories.registerCheck(
 "bugprone-copy-constructor-init");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index dab139b77c770..b66ef8ea3634b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -15,6 +15,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   CastingThroughVoidCheck.cpp
   ChainedComparisonCheck.cpp
   ComparePointerToMemberVirtualFunctionCheck.cpp
+  ConflictingGlobalAccesses.cpp
   CopyConstructorInitCheck.cpp
   CrtpConstructorAccessibilityCheck.cpp
   DanglingHandleCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ConflictingGlobalAccesses.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ConflictingGlobalAccesses.cpp
new file mode 100644
index 0..c6eb42ca57519
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/ConflictingGlobalAccesses.cpp
@@ -0,0 +1,728 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ConflictingGlobalAccesses.h"
+
+#include "clang/AST/RecursiveASTVisitor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+// An AccesKind represents one access to a global variable.
+//
+// The unchecked versions represent reads/writes that are not handled by
+// -Wunsequenced. (e.g. accesses inside functions).
+using AccessKind = uint8_t;
+static constexpr AccessKind AkRead = 0;
+static constexpr AccessKind AkWrite = 1;
+static constexpr AccessKind AkUncheckedRead = 2;
+static constexpr AccessKind AkUncheckedWrite = 3;
+
+static constexpr uint8_t AkCount = 4;
+
+// The TraversalResultKind represents a set of accesses.
+// Bits are corresponding to the AccessKind enum values.
+using TraversalResultKind = uint8_t;
+static constexpr TraversalResultKind TrInvalid = 0;
+static constexpr TraversalResultKind TrRead = 1 << AkRead;
+static constexpr TraversalResultKind TrWrite = 1 << AkWrite;
+static constexpr TraversalResultKind TrUncheckedWrite = 1 << AkUncheckedWrite;
+
+// To represent fields in structs or unions we use numbered FieldIndices. The
+// FieldIndexArray represents one field inside a global struct/union system.
+// The FieldIndexArray can be thought of as a path inside a tree.
+using FieldIndex = uint16_t;
+static constexpr FieldIndex FiUnion = 0x8000;
+
+// Note: This bit signals whether the field is a *field of* a struct or a
+// union, not whether the type of the field itself is a struct or a union.
+using FieldIndexArray = SmallVector;
+
+/// One traversal recurses i

[clang] [flang] [lldb] [llvm] [mlir] [polly] [IR] Store Triple in Module (NFC) (PR #129868)

2025-03-09 Thread Matt Arsenault via cfe-commits

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


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


  1   2   >