[clang] [clang] constexpr built-in elementwise popcount function. (PR #117473)

2024-11-24 Thread via cfe-commits

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

>From 95f2b6b0742b9b5b675f5d2f24aa4eb90c03b18c Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sun, 24 Nov 2024 18:14:51 +0800
Subject: [PATCH 1/4] constexpr elementwise popcount

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/include/clang/Basic/Builtins.td|  2 +-
 clang/lib/AST/ExprConstant.cpp   | 27 
 clang/test/Sema/constant_builtins_vector.cpp |  5 
 4 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bd06fadfdc984..16a151da38bb5d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -370,6 +370,7 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_mul`` function can now be used in constant expressions.
 - ``__builtin_reduce_and`` function can now be used in constant expressions.
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
+- ``__builtin_elementwise_popcount`` function can now be used in constant 
expressions.
 
 New Compiler Flags
 --
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 83c90b3d6e681b..246250442ef62c 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1354,7 +1354,7 @@ def ElementwiseLog10 : Builtin {
 
 def ElementwisePopcount : Builtin {
   let Spellings = ["__builtin_elementwise_popcount"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index c6a210459240a8..bdd056d0618c6d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11005,6 +11005,7 @@ namespace {
 bool VisitUnaryImag(const UnaryOperator *E);
 bool VisitBinaryOperator(const BinaryOperator *E);
 bool VisitUnaryOperator(const UnaryOperator *E);
+bool VisitCallExpr(const CallExpr *E);
 bool VisitConvertVectorExpr(const ConvertVectorExpr *E);
 bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E);
 
@@ -11302,6 +11303,32 @@ static bool handleVectorElementCast(EvalInfo &Info, 
const FPOptions FPO,
   return false;
 }
 
+bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
+  switch (E->getBuiltinCallee()) {
+  default:
+return false;
+  case Builtin::BI__builtin_elementwise_popcount: {
+APValue Source;
+if (!EvaluateAsRValue(Info, E->getArg(0), Source))
+  return false;
+
+QualType DestTy = E->getType()->castAs()->getElementType();
+unsigned SourceLen = Source.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+  APSInt Elt = Source.getVectorElt(EltNum).getInt();
+  ResultElements.push_back(
+  APValue(APSInt(APInt(Info.Ctx.getIntWidth(DestTy), Elt.popcount()),
+ DestTy->isUnsignedIntegerOrEnumerationType(;
+}
+
+return Success(APValue(ResultElements.data(), ResultElements.size()), E);
+  }
+  }
+}
+
 bool VectorExprEvaluator::VisitConvertVectorExpr(const ConvertVectorExpr *E) {
   APValue Source;
   QualType SourceVecType = E->getSrcExpr()->getType();
diff --git a/clang/test/Sema/constant_builtins_vector.cpp 
b/clang/test/Sema/constant_builtins_vector.cpp
index e84d09b24672b4..76d8bdfda3690a 100644
--- a/clang/test/Sema/constant_builtins_vector.cpp
+++ b/clang/test/Sema/constant_builtins_vector.cpp
@@ -797,3 +797,8 @@ 
static_assert(__builtin_reduce_xor((vector4int){(int)0x, (int)0x
 static_assert(__builtin_reduce_xor((vector4long){(long 
long)0xL, (long long)0xL, (long 
long)0xL, (long long)0xL}) == (long 
long)0xL);
 static_assert(__builtin_reduce_xor((vector4uint){0xU, 0xU, 
0xU, 0xU}) == 0xU);
 static_assert(__builtin_reduce_xor((vector4ulong){0xUL, 
0xUL, 0xUL, 0xUL}) == 
0xUL);
+
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4int){1,
 2, 3, 4})) == 5);
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4int){0,
 0xF0F0, ~0, ~0xF0F0})) == 16 * sizeof(int));
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4long){1L,
 2L, 3L, 4L})) == 5L);
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4long){0L,
 0xF0F0L, ~0L, ~0xF0F0L})) == 16 * sizeof(long long));

>From 316f6085fb129de24da3297c1bd8b110d763b23d Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sun, 24 Nov 2024 18:27:55 +0800
Subject: [PATCH 2/4] fix bug

---
 clang/lib/AST/ExprConstant.cpp | 3 +++
 1 fi

[clang-tools-extra] [clang-tidy] fix cppcoreguidelines-narrowing-conversions false positives when narrowing integer to signed integer in C++20 (PR #116591)

2024-11-24 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/116591
___
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 cppcoreguidelines-narrowing-conversions false positives when narrowing integer to signed integer in C++20 (PR #116591)

2024-11-24 Thread Piotr Zegar via cfe-commits

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

Consider just changing default value of WarnOnIntegerNarrowingConversion option.

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


[clang] [Sema] Migrate away from PointerUnion::{is, get} (NFC) (PR #117498)

2024-11-24 Thread Kazu Hirata via cfe-commits

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

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


>From fbd12a03e436eaf22766e64afff36a21d3b88fd6 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 24 Nov 2024 08:05:21 -0800
Subject: [PATCH] [Sema] Migrate away from PointerUnion::{is,get} (NFC)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
---
 clang/lib/Sema/SemaAPINotes.cpp   |  2 +-
 clang/lib/Sema/SemaCodeComplete.cpp   | 16 +++
 clang/lib/Sema/SemaConcept.cpp|  7 +++
 clang/lib/Sema/SemaDecl.cpp   |  6 +++---
 clang/lib/Sema/SemaDeclAttr.cpp   |  6 +++---
 clang/lib/Sema/SemaDeclCXX.cpp|  6 +++---
 clang/lib/Sema/SemaDeclObjC.cpp   |  2 +-
 clang/lib/Sema/SemaFunctionEffects.cpp| 14 ++---
 clang/lib/Sema/SemaOpenMP.cpp |  8 
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 +--
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 10 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   | 20 +--
 clang/lib/Sema/TreeTransform.h|  2 +-
 13 files changed, 54 insertions(+), 57 deletions(-)

diff --git a/clang/lib/Sema/SemaAPINotes.cpp b/clang/lib/Sema/SemaAPINotes.cpp
index 028bf82f3e8040..0dedfc490c86fd 100644
--- a/clang/lib/Sema/SemaAPINotes.cpp
+++ b/clang/lib/Sema/SemaAPINotes.cpp
@@ -482,7 +482,7 @@ static void ProcessAPINotes(Sema &S, FunctionOrMethod 
AnyFunc,
   Decl *D = FD;
   ObjCMethodDecl *MD = nullptr;
   if (!D) {
-MD = AnyFunc.get();
+MD = cast(AnyFunc);
 D = MD;
   }
 
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 12da3a2cbca314..bc038acc88855f 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -131,8 +131,8 @@ class ResultBuilder {
   }
 
   // Add the new element to the end of the vector.
-  DeclOrVector.get()->push_back(
-  DeclIndexPair(ND, Index));
+  cast(DeclOrVector)
+  ->push_back(DeclIndexPair(ND, Index));
 }
 
 ~ShadowMapEntry() {
@@ -659,13 +659,13 @@ class ResultBuilder::ShadowMapEntry::iterator {
   : DeclOrIterator(Iterator), SingleDeclIndex(0) {}
 
   iterator &operator++() {
-if (DeclOrIterator.is()) {
+if (isa(DeclOrIterator)) {
   DeclOrIterator = (NamedDecl *)nullptr;
   SingleDeclIndex = 0;
   return *this;
 }
 
-const DeclIndexPair *I = DeclOrIterator.get();
+const DeclIndexPair *I = cast(DeclOrIterator);
 ++I;
 DeclOrIterator = I;
 return *this;
@@ -681,7 +681,7 @@ class ResultBuilder::ShadowMapEntry::iterator {
 if (const NamedDecl *ND = DeclOrIterator.dyn_cast())
   return reference(ND, SingleDeclIndex);
 
-return *DeclOrIterator.get();
+return *cast(DeclOrIterator);
   }
 
   pointer operator->() const { return pointer(**this); }
@@ -705,15 +705,15 @@ ResultBuilder::ShadowMapEntry::begin() const {
   if (const NamedDecl *ND = DeclOrVector.dyn_cast())
 return iterator(ND, SingleDeclIndex);
 
-  return iterator(DeclOrVector.get()->begin());
+  return iterator(cast(DeclOrVector)->begin());
 }
 
 ResultBuilder::ShadowMapEntry::iterator
 ResultBuilder::ShadowMapEntry::end() const {
-  if (DeclOrVector.is() || DeclOrVector.isNull())
+  if (isa(DeclOrVector) || DeclOrVector.isNull())
 return iterator();
 
-  return iterator(DeclOrVector.get()->end());
+  return iterator(cast(DeclOrVector)->end());
 }
 
 /// Compute the qualification required to get from the current context
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 1bdf3a02b2924a..ff1df7b71b1a4f 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1384,8 +1384,7 @@ static void diagnoseUnsatisfiedConstraintExpr(
 return;
   }
 
-  diagnoseWellFormedUnsatisfiedConstraintExpr(S,
-  Record.template get(), First);
+  diagnoseWellFormedUnsatisfiedConstraintExpr(S, cast(Record), First);
 }
 
 void
@@ -1557,12 +1556,12 @@ NormalizedConstraint::NormalizedConstraint(ASTContext 
&C,
 
 NormalizedConstraint &NormalizedConstraint::getLHS() const {
   assert(isCompound() && "getLHS called on a non-compound constraint.")

[libunwind] [libunwind] Fix compilation for the x32 ABI. (PR #116608)

2024-11-24 Thread Alex Rønne Petersen via cfe-commits

https://github.com/alexrp updated 
https://github.com/llvm/llvm-project/pull/116608

From 23a2f6900fb838ffdbad177839d3f2da6d5cf52f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= 
Date: Mon, 18 Nov 2024 13:12:30 +0100
Subject: [PATCH] [libunwind] Fix compilation for the x32 ABI.

This would previously fail the static assertions in UnwindCursor.hpp due to
UnwindCursor's size not matching unw_cursor_t's size. As is done for MIPS N32,
this just declares the appropriate size in __libunwind_config.h.
---
 libunwind/include/__libunwind_config.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 028b9e3baa8065..bb7fe4c83a3c17 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -53,6 +53,9 @@
 #else
 #  define _LIBUNWIND_CURSOR_SIZE 66
 #endif
+#  elif defined(__ILP32__)
+#define _LIBUNWIND_CONTEXT_SIZE 21
+#define _LIBUNWIND_CURSOR_SIZE 28
 #  else
 #define _LIBUNWIND_CONTEXT_SIZE 21
 #define _LIBUNWIND_CURSOR_SIZE 33

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


[clang] [AST] Remove clang/AST/CommentDiagnostic.h (PR #117499)

2024-11-24 Thread Kazu Hirata via cfe-commits

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

Since:

  commit d076608d58d1ec55016eb747a995511e3a3f72aa
  Author: Richard Trieu 
  Date:   Sat Dec 8 05:05:03 2018 +

clang/AST/CommentDiagnostic.h has been forwarding to
clang/Basic/DiagnosticParse.h.  This patch removes the indirection and
clang/AST/CommentDiagnostic.h.


>From e9427756de508dc386a10ee9ee19cc4733a40465 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 24 Nov 2024 09:14:54 -0800
Subject: [PATCH] [AST] Remove clang/AST/CommentDiagnostic.h

Since:

  commit d076608d58d1ec55016eb747a995511e3a3f72aa
  Author: Richard Trieu 
  Date:   Sat Dec 8 05:05:03 2018 +

clang/AST/CommentDiagnostic.h has been forwarding to
clang/Basic/DiagnosticParse.h.  This patch removes the indirection and
clang/AST/CommentDiagnostic.h.
---
 clang/include/clang/AST/CommentDiagnostic.h | 15 ---
 clang/include/module.modulemap  |  1 -
 clang/lib/AST/CommentLexer.cpp  |  2 +-
 clang/lib/AST/CommentParser.cpp |  2 +-
 clang/lib/AST/CommentSema.cpp   |  2 +-
 clang/lib/Sema/SemaDecl.cpp |  2 +-
 6 files changed, 4 insertions(+), 20 deletions(-)
 delete mode 100644 clang/include/clang/AST/CommentDiagnostic.h

diff --git a/clang/include/clang/AST/CommentDiagnostic.h 
b/clang/include/clang/AST/CommentDiagnostic.h
deleted file mode 100644
index 2e498d5db38648..00
--- a/clang/include/clang/AST/CommentDiagnostic.h
+++ /dev/null
@@ -1,15 +0,0 @@
-//===--- CommentDiagnostic.h - Diagnostics for the AST library --*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_CLANG_AST_COMMENTDIAGNOSTIC_H
-#define LLVM_CLANG_AST_COMMENTDIAGNOSTIC_H
-
-#include "clang/Basic/DiagnosticComment.h"
-
-#endif
-
diff --git a/clang/include/module.modulemap b/clang/include/module.modulemap
index b399f0beee59a1..56b0409e74a150 100644
--- a/clang/include/module.modulemap
+++ b/clang/include/module.modulemap
@@ -111,7 +111,6 @@ module Clang_Diagnostics {
   module All { header "clang/Basic/AllDiagnostics.h" export * }
   module Analysis { textual header 
"clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def" }
   module AST { header "clang/AST/ASTDiagnostic.h" export * }
-  module Comment { header "clang/AST/CommentDiagnostic.h" export * }
   module Driver { header "clang/Driver/DriverDiagnostic.h" export * }
   module Frontend { header "clang/Frontend/FrontendDiagnostic.h" export * }
   module Lex { header "clang/Lex/LexDiagnostic.h" export * }
diff --git a/clang/lib/AST/CommentLexer.cpp b/clang/lib/AST/CommentLexer.cpp
index f0250fc9fd55eb..ec9a5b480aa295 100644
--- a/clang/lib/AST/CommentLexer.cpp
+++ b/clang/lib/AST/CommentLexer.cpp
@@ -8,8 +8,8 @@
 
 #include "clang/AST/CommentLexer.h"
 #include "clang/AST/CommentCommandTraits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ConvertUTF.h"
diff --git a/clang/lib/AST/CommentParser.cpp b/clang/lib/AST/CommentParser.cpp
index 61508fe886efc0..12ed8e3f1b79a0 100644
--- a/clang/lib/AST/CommentParser.cpp
+++ b/clang/lib/AST/CommentParser.cpp
@@ -8,9 +8,9 @@
 
 #include "clang/AST/CommentParser.h"
 #include "clang/AST/CommentCommandTraits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/AST/CommentSema.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Support/ErrorHandling.h"
 
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index 69eda00643a8fa..bd2206bb8a3bc7 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -9,9 +9,9 @@
 #include "clang/AST/CommentSema.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/CommentCommandTraits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Preprocessor.h"
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 74b0e5ad23bd48..1e9db39a7fb579 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16,7 +16,6 @@
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/CharUnits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
@@ -30,6 +29,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/

[clang] [AST] Remove clang/AST/CommentDiagnostic.h (PR #117499)

2024-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Since:

  commit d076608d58d1ec55016eb747a995511e3a3f72aa
  Author: Richard Trieu 
  Date:   Sat Dec 8 05:05:03 2018 +

clang/AST/CommentDiagnostic.h has been forwarding to
clang/Basic/DiagnosticParse.h.  This patch removes the indirection and
clang/AST/CommentDiagnostic.h.


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


6 Files Affected:

- (removed) clang/include/clang/AST/CommentDiagnostic.h (-15) 
- (modified) clang/include/module.modulemap (-1) 
- (modified) clang/lib/AST/CommentLexer.cpp (+1-1) 
- (modified) clang/lib/AST/CommentParser.cpp (+1-1) 
- (modified) clang/lib/AST/CommentSema.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/CommentDiagnostic.h 
b/clang/include/clang/AST/CommentDiagnostic.h
deleted file mode 100644
index 2e498d5db38648..00
--- a/clang/include/clang/AST/CommentDiagnostic.h
+++ /dev/null
@@ -1,15 +0,0 @@
-//===--- CommentDiagnostic.h - Diagnostics for the AST library --*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_CLANG_AST_COMMENTDIAGNOSTIC_H
-#define LLVM_CLANG_AST_COMMENTDIAGNOSTIC_H
-
-#include "clang/Basic/DiagnosticComment.h"
-
-#endif
-
diff --git a/clang/include/module.modulemap b/clang/include/module.modulemap
index b399f0beee59a1..56b0409e74a150 100644
--- a/clang/include/module.modulemap
+++ b/clang/include/module.modulemap
@@ -111,7 +111,6 @@ module Clang_Diagnostics {
   module All { header "clang/Basic/AllDiagnostics.h" export * }
   module Analysis { textual header 
"clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def" }
   module AST { header "clang/AST/ASTDiagnostic.h" export * }
-  module Comment { header "clang/AST/CommentDiagnostic.h" export * }
   module Driver { header "clang/Driver/DriverDiagnostic.h" export * }
   module Frontend { header "clang/Frontend/FrontendDiagnostic.h" export * }
   module Lex { header "clang/Lex/LexDiagnostic.h" export * }
diff --git a/clang/lib/AST/CommentLexer.cpp b/clang/lib/AST/CommentLexer.cpp
index f0250fc9fd55eb..ec9a5b480aa295 100644
--- a/clang/lib/AST/CommentLexer.cpp
+++ b/clang/lib/AST/CommentLexer.cpp
@@ -8,8 +8,8 @@
 
 #include "clang/AST/CommentLexer.h"
 #include "clang/AST/CommentCommandTraits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ConvertUTF.h"
diff --git a/clang/lib/AST/CommentParser.cpp b/clang/lib/AST/CommentParser.cpp
index 61508fe886efc0..12ed8e3f1b79a0 100644
--- a/clang/lib/AST/CommentParser.cpp
+++ b/clang/lib/AST/CommentParser.cpp
@@ -8,9 +8,9 @@
 
 #include "clang/AST/CommentParser.h"
 #include "clang/AST/CommentCommandTraits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/AST/CommentSema.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Support/ErrorHandling.h"
 
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index 69eda00643a8fa..bd2206bb8a3bc7 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -9,9 +9,9 @@
 #include "clang/AST/CommentSema.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/CommentCommandTraits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Preprocessor.h"
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 74b0e5ad23bd48..1e9db39a7fb579 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16,7 +16,6 @@
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/CharUnits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
@@ -30,6 +29,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"

``




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


[clang-tools-extra] [clang-tidy] fix false positive use-internal-linkage for func decl without body (PR #117490)

2024-11-24 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.


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


[clang] [clang-tools-extra] [clang][analysis] refactor the unevaluated api (PR #117474)

2024-11-24 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.


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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Andrew Pinski via cfe-commits

pinskia wrote:

>From my point of view this looks like a decent documentation of this 
>extension. Note I filed the original bug because I noticed both GCC and clang 
>didn't document this extension. (I filed GCC here: 
>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117689 which I got try fix next 
>week).

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


[clang] [Wunsafe-buffer-usage] Fix false positives in handling array indices that are decidably correct (PR #117370)

2024-11-24 Thread via cfe-commits

https://github.com/mxms0 updated 
https://github.com/llvm/llvm-project/pull/117370

>From 8fed333cf4221dbf1826351da80164db5d209c21 Mon Sep 17 00:00:00 2001
From: mxms 
Date: Fri, 22 Nov 2024 15:09:07 -0500
Subject: [PATCH 1/5] [Wunsafe-buffer-usage] Fix false positives in handling
 enums

Do not warn if the index is an enum and we an determine statically that
it's within bounds.
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp|  7 +++
 .../SemaCXX/warn-unsafe-buffer-usage-array.cpp  | 17 +
 2 files changed, 24 insertions(+)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 5f36ffa926b269..addb724e2e2c9a 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -463,6 +463,13 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   return true;
   }
 
+  // Array index wasn't an integer literal, let's see if it was an enum or
+  // something similar
+  const auto IntConst = 
Node.getIdx()->getIntegerConstantExpr(Finder->getASTContext());
+  if (IntConst && *IntConst > 0 && *IntConst < size) {
+return true;
+  }
+
   return false;
 }
 
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
index c6c93a27e4b969..a65ecdf39edfcc 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
@@ -39,6 +39,23 @@ void constant_idx_unsafe(unsigned idx) {
   buffer[10] = 0;   // expected-note{{used in buffer access here}}
 }
 
+enum FooEnum {
+  A = 0,
+  B = 1,
+  C = 2,
+  D
+};
+
+void constant_enum_safe() {
+  int buffer[FooEnum::D] = { 0, 1, 2 };
+  buffer[C] = 0; // no-warning
+}
+
+void constant_enum_unsafe(FooEnum e) {
+  int buffer[FooEnum::D] = { 0, 1, 2 };
+  buffer[e] = 0; // expected-warning{{unsafe buffer access}}
+}
+
 void constant_id_string(unsigned idx) {
   char safe_char = "abc"[1]; // no-warning
   safe_char = ""[0];

>From 35207ea84425902a70b46f153e9619cc9d544f46 Mon Sep 17 00:00:00 2001
From: mxms 
Date: Fri, 22 Nov 2024 23:45:39 -0500
Subject: [PATCH 2/5] Detect when the buffer is a member access, fix tests

Add a case for when it's a member variable access and we can statically
determine the size. Also add new test to ensure the change works
reliably and update old tests to not expect this warning.
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp  |  2 +-
 .../warn-unsafe-buffer-usage-array.cpp|  5 -
 .../warn-unsafe-buffer-usage-field-attr.cpp   |  1 -
 .../test/SemaCXX/warn-unsafe-buffer-usage.cpp | 21 +--
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index addb724e2e2c9a..c005b34c2f63ad 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -466,7 +466,7 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   // Array index wasn't an integer literal, let's see if it was an enum or
   // something similar
   const auto IntConst = 
Node.getIdx()->getIntegerConstantExpr(Finder->getASTContext());
-  if (IntConst && *IntConst > 0 && *IntConst < size) {
+  if (IntConst && *IntConst >= 0 && *IntConst < size) {
 return true;
   }
 
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
index a65ecdf39edfcc..f5672db18de0ca 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
@@ -47,8 +47,11 @@ enum FooEnum {
 };
 
 void constant_enum_safe() {
-  int buffer[FooEnum::D] = { 0, 1, 2 };
+  int buffer[FooEnum::D] = { 0, 1, 2 }; // expected-warning{{'buffer' is an 
unsafe buffer that does not perform bounds checks}}
+// expected-note@-1{{change type of 
'buffer' to 'std::array' to label it for hardening}}
+  buffer[A] = 0; // no-warning
   buffer[C] = 0; // no-warning
+  buffer[D] = 0; // expected-note{{used in buffer access here}}
 }
 
 void constant_enum_unsafe(FooEnum e) {
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp
index 0ba605475925b9..1636c948da075a 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp
@@ -96,7 +96,6 @@ void test_attribute_multiple_fields (D d) {
 
int v = d.buf[0]; //expected-warning{{field 'buf' prone to unsafe buffer 
manipulation}}
 
-   //expected-warning@+1{{unsafe buffer access}}
v = d.buf[5]; //expected-warning{{field 'buf' prone to unsafe buffer 
manipulation}}
 }
 
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
index 642db0e9d3c632..41194a8e3f5222 100644
--- a/clang/test/SemaCXX/warn-unsafe

[clang] [Wunsafe-buffer-usage] Address some positives in handling array indices that are decidably correct (PR #117370)

2024-11-24 Thread via cfe-commits

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


[clang] [Driver] Pass `--no-cuda-version-check` to test (PR #117415)

2024-11-24 Thread Kai Luo via cfe-commits

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


[clang] [llvm] [SanitizerCoverage] Add gated tracing callbacks support to trace-cmp (PR #113227)

2024-11-24 Thread via cfe-commits

https://github.com/thetruestblue updated 
https://github.com/llvm/llvm-project/pull/113227

>From 5dbb79145b669e2478b61402fa95fed0385c6a95 Mon Sep 17 00:00:00 2001
From: thetruestblue <92476612+thetruestb...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 14:57:40 -0800
Subject: [PATCH] [SanitizerCoverage] Add gated tracing callbacks support to
 trace-cmp

The option -sanitizer-coverage-gated-trace-callbacks gates the invocation of the
trace-pc-guard callbacks based on the value of a global variable, which is 
stored
in a specific section.
In this commit, we extend this feature to trace-cmp and gate the cmp callbacks 
to
the same variable used for trace-pc-guard.

Update SanitizerCoverage doc with this flag.

rdar://135404160

Patch by: Andrea Fioraldi
---
 clang/docs/SanitizerCoverage.rst  | 14 ++
 .../sanitize-coverage-gated-callbacks.c   | 13 -
 .../Instrumentation/SanitizerCoverage.cpp | 50 +--
 3 files changed, 59 insertions(+), 18 deletions(-)

diff --git a/clang/docs/SanitizerCoverage.rst b/clang/docs/SanitizerCoverage.rst
index 45ad03cb43774c..6ea1d14829005c 100644
--- a/clang/docs/SanitizerCoverage.rst
+++ b/clang/docs/SanitizerCoverage.rst
@@ -385,6 +385,20 @@ Users need to implement a single function to capture the 
CF table at startup:
 // the collected control flow.
   }
 
+Gated Trace Callbacks
+=
+
+Gate the invocation of the tracing callbacks with
+``-sanitizer-coverage-gated-trace-callbacks``.
+
+When this option is enabled, the instrumentation will not call into the
+runtime-provided callbacks for tracing, thus only incurring in a trivial
+branch without going through a function call.
+
+It is up to the runtime to toggle the value of the global variable in order to
+enable tracing.
+
+This option is only supported for trace-pc-guard and trace-cmp.
 
 Disabling instrumentation with ``__attribute__((no_sanitize("coverage")))``
 ===
diff --git a/clang/test/CodeGen/sanitize-coverage-gated-callbacks.c 
b/clang/test/CodeGen/sanitize-coverage-gated-callbacks.c
index 9a00d91d5ad086..e226591d80d077 100644
--- a/clang/test/CodeGen/sanitize-coverage-gated-callbacks.c
+++ b/clang/test/CodeGen/sanitize-coverage-gated-callbacks.c
@@ -1,5 +1,7 @@
 // RUN: %clang %s -target arm64-apple-darwin -emit-llvm -S 
-fsanitize-coverage=trace-pc-guard -mllvm 
-sanitizer-coverage-gated-trace-callbacks=1 -o - | FileCheck %s 
--check-prefixes=CHECK,GATED
 // RUN: %clang %s -target arm64-apple-darwin -emit-llvm -S 
-fsanitize-coverage=trace-pc-guard -mllvm 
-sanitizer-coverage-gated-trace-callbacks=0 -o - | FileCheck %s 
--check-prefixes=CHECK,PLAIN
+// RUN: %clang %s -target arm64-apple-darwin -emit-llvm -S 
-fsanitize-coverage=trace-pc-guard,trace-cmp -mllvm 
-sanitizer-coverage-gated-trace-callbacks=1 -o - | FileCheck %s 
--check-prefixes=CHECK,GATED,GATEDCMP
+// RUN: %clang %s -target arm64-apple-darwin -emit-llvm -S 
-fsanitize-coverage=trace-pc-guard,trace-cmp -mllvm 
-sanitizer-coverage-gated-trace-callbacks=0 -o - | FileCheck %s 
--check-prefixes=CHECK,PLAIN,PLAINCMP
 // RUN: not %clang %s -target arm64-apple-darwin -emit-llvm -S 
-fsanitize-coverage=trace-pc -mllvm -sanitizer-coverage-gated-trace-callbacks=1 
-o /dev/null 2>&1 | FileCheck %s --check-prefixes=INCOMPATIBLE
 // RUN: not %clang %s -target arm64-apple-darwin -emit-llvm -S 
-fsanitize-coverage=inline-8bit-counters -mllvm 
-sanitizer-coverage-gated-trace-callbacks=1 -o /dev/null 2>&1 | FileCheck %s 
--check-prefixes=INCOMPATIBLE
 // RUN: not %clang %s -target arm64-apple-darwin -emit-llvm -S 
-fsanitize-coverage=inline-bool-flag -mllvm 
-sanitizer-coverage-gated-trace-callbacks=1 -o /dev/null 2>&1 | FileCheck %s 
--check-prefixes=INCOMPATIBLE
@@ -9,7 +11,7 @@
 // PLAIN-NOT: section "__DATA,__sancov_gate"
 
 // Produce an error for all incompatible sanitizer coverage modes.
-// INCOMPATIBLE: error: 'sanitizer-coverage-gated-trace-callbacks' is only 
supported with trace-pc-guard
+// INCOMPATIBLE: error: 'sanitizer-coverage-gated-trace-callbacks' is only 
supported with trace-pc-guard or trace-cmp
 
 int x[10];
 
@@ -23,6 +25,11 @@ void foo(int n, int m) {
   // GATED-NEXT: br i1 [[CMP]], label %[[L_TRUE:.*]], label %[[L_FALSE:.*]], 
!prof [[WEIGHTS:!.+]]
   // GATED: [[L_TRUE]]:
   // GATED-NEXT:   call void @__sanitizer_cov_trace_pc_guard
+  // COM: Check the trace-cmp instrumentation of the if (n) branch
+  // GATEDCMP: [[OPERAND:%.*]] = load i32, {{.*}}
+  // GATEDCMP-NEXT: br i1 [[CMP]], label %[[L_TRUE_1:.*]], label 
%[[L_FALSE_1:.*]]
+  // GATEDCMP: [[L_TRUE_1]]:
+  // GATEDCMP-NEXT:   call void @__sanitizer_cov_trace_const_cmp4(i32 0, i32 
[[OPERAND]])
   // GATED:   br i1 [[CMP]], label %[[L_TRUE_2:.*]], label %[[L_FALSE_2:.*]]
   // GATED: [[L_TRUE_2]]:
   // GATED-NEXT:   call void @__sanitizer_cov_trace_pc_guard
@@ -33,10 +40,12 @@ void foo(int n, int m) {
   // PLAIN-NOT: __sancov_should_track
   //

[clang] [llvm] [SanitizerCoverage] Add gated tracing callbacks support to trace-cmp (PR #113227)

2024-11-24 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 e26af0938c7a272cf0de11c92aa069485868e130 
7c771b793b36e5c8d0d8d4963d0356123054e9e4 --extensions c,cpp -- 
clang/test/CodeGen/sanitize-coverage-gated-callbacks.c 
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp 
b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 9afe1d0589..22acf59c78 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -246,8 +246,7 @@ private:
 ArrayRef SwitchTraceTargets,
 Value *&FunctionGateCmp);
   bool InjectCoverage(Function &F, ArrayRef AllBlocks,
-  Value *&FunctionGateCmp,
-  bool IsLeafFunc);
+  Value *&FunctionGateCmp, bool IsLeafFunc);
   GlobalVariable *CreateFunctionLocalArrayInSection(size_t NumElements,
 Function &F, Type *Ty,
 const char *Section);

``




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


[clang] [clang] hexagon: fix link order for libc/builtins (PR #117057)

2024-11-24 Thread Brian Cain via cfe-commits

https://github.com/androm3da updated 
https://github.com/llvm/llvm-project/pull/117057

>From 8ec280dc6c15d7279afe332615497704739aee63 Mon Sep 17 00:00:00 2001
From: Brian Cain 
Date: Wed, 20 Nov 2024 13:23:39 -0800
Subject: [PATCH] [clang] hexagon: fix link order for libc/builtins

When linking programs with eld, we get a link error like below:

Error: 
/inst/clang+llvm-19.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/bin/../target/hexagon-unknown-linux-musl//usr/lib/libc.a(scalbn.lo)(.text.scalbn+0x3c):
 undefined reference to `__hexagon_muldf3'

libc has references to the clang_rt builtins library, so the order of the
libraries should be reversed.
---
 clang/lib/Driver/ToolChains/Hexagon.cpp |  2 +-
 clang/test/Driver/hexagon-toolchain-linux.c | 10 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 29781399cbab44..383dc8387e75e7 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -378,9 +378,9 @@ constructHexagonLinkArgs(Compilation &C, const JobAction 
&JA,
   if (NeedsXRayDeps)
 linkXRayRuntimeDeps(HTC, Args, CmdArgs);
 
-  CmdArgs.push_back("-lclang_rt.builtins-hexagon");
   if (!Args.hasArg(options::OPT_nolibc))
 CmdArgs.push_back("-lc");
+  CmdArgs.push_back("-lclang_rt.builtins-hexagon");
 }
 if (D.CCCIsCXX()) {
   if (HTC.ShouldLinkCXXStdlib(Args))
diff --git a/clang/test/Driver/hexagon-toolchain-linux.c 
b/clang/test/Driver/hexagon-toolchain-linux.c
index 86cc9a30e932c6..6f7f3b20f9141f 100644
--- a/clang/test/Driver/hexagon-toolchain-linux.c
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -11,7 +11,7 @@
 // CHECK000-NOT:  
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o
 // CHECK000:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
 // CHECK000:  
"{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o"
-// CHECK000:  "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK000:  "-lc" "-lclang_rt.builtins-hexagon"
 // 
-
 // Passing --musl --shared
 // 
-
@@ -21,7 +21,7 @@
 // RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -shared %s 2>&1 | 
FileCheck -check-prefix=CHECK001 %s
 // CHECK001-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
 // CHECK001:
"{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o"
-// CHECK001:"-lclang_rt.builtins-hexagon" "-lc"
+// CHECK001:"-lc" "-lclang_rt.builtins-hexagon"
 // CHECK001-NOT:
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
 // 
-
 // Passing --musl -nostdlib
@@ -33,8 +33,8 @@
 // CHECK002:   
"-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
 // CHECK002-NOT:   
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o
 // CHECK002-NOT:   
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
-// CHECK002-NOT:   "-lclang_rt.builtins-hexagon"
 // CHECK002-NOT:   "-lc"
+// CHECK002-NOT:   "-lclang_rt.builtins-hexagon"
 // 
-
 // Passing --musl -nostartfiles
 // 
-
@@ -45,7 +45,7 @@
 // CHECK003:   
"-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
 // CHECK003-NOT:   
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}Scrt1.o
 // CHECK003-NOT:   
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
-// CHECK003:   "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK003:   "-lc" "-lclang_rt.builtins-hexagon"
 // 
-
 // Passing --musl -nodefaultlibs
 // 
-
@@ -55,8 +55,8 @@
 // RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -nodefaultlibs %s 2>&1 | 
FileCheck -check-prefix=CHECK004 %s
 // CHECK004:   
"-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
 // CHECK004:   
"{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o"
-// CHECK004-NOT:   "-lclang_rt.builtins-hexagon"
 // CHECK004-NOT:   "-lc"
+// CHECK004-NOT:   "-lclang_rt.builtins-hexagon"
 // 
-
 // Passing --musl -nolibc
 // 
-

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


[clang] [Wunsafe-buffer-usage] Address some false positives in handling array indices that are decidably correct (PR #117370)

2024-11-24 Thread via cfe-commits

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


[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)

2024-11-24 Thread Zhengxing li via cfe-commits

https://github.com/lizhengxing updated 
https://github.com/llvm/llvm-project/pull/115911

>From 6418461717614d5879688d32a0ab9bf9d9137328 Mon Sep 17 00:00:00 2001
From: Zhengxing Li 
Date: Tue, 1 Oct 2024 15:13:34 -0700
Subject: [PATCH 1/4] [HLSL] Implement SV_GroupID semantic

Support SV_GroupID attribute.
Translate it into dx.group.id in clang codeGen.

Fixes: #70120
---
 clang/include/clang/Basic/Attr.td |  7 ++
 clang/include/clang/Basic/AttrDocs.td | 11 
 clang/include/clang/Sema/SemaHLSL.h   |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  4 +++
 clang/lib/Parse/ParseHLSL.cpp |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 +++
 clang/lib/Sema/SemaHLSL.cpp   | 16 ++--
 .../CodeGenHLSL/semantics/SV_GroupID.hlsl | 21 
 .../SemaHLSL/Semantics/entry_parameter.hlsl   | 11 +---
 .../Semantics/invalid_entry_parameter.hlsl| 22 
 .../Semantics/valid_entry_parameter.hlsl  | 25 +++
 11 files changed, 116 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index a631e81d40aa68..52df814deecc02 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4587,6 +4587,13 @@ def HLSLNumThreads: InheritableAttr {
   let Documentation = [NumThreadsDocs];
 }
 
+def HLSLSV_GroupID: HLSLAnnotationAttr {
+  let Spellings = [HLSLAnnotation<"SV_GroupID">];
+  let Subjects = SubjectList<[ParmVar, Field]>;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLSV_GroupIDDocs];
+}
+
 def HLSLSV_GroupIndex: HLSLAnnotationAttr {
   let Spellings = [HLSLAnnotation<"SV_GroupIndex">];
   let Subjects = SubjectList<[ParmVar, GlobalVar]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b64dbef6332e6a..0a20f87d0ddb37 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7816,6 +7816,17 @@ randomized.
   }];
 }
 
+def HLSLSV_GroupIDDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``SV_GroupID`` semantic, when applied to an input parameter, specifies a
+data binding to map the group id to the specified parameter. This attribute is
+only supported in compute shaders.
+
+The full documentation is available here: 
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupid
+  }];
+}
+
 def HLSLSV_GroupIndexDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 06c541dec08cc8..f36b46d0c7ad43 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase {
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
+  void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL);
   void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
   void handleShaderAttr(Decl *D, const ParsedAttr &AL);
   void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 7ba0d615018181..2c293523fca8ca 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -389,6 +389,10 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> 
&B,
 CGM.getIntrinsic(getThreadIdIntrinsic());
 return buildVectorInput(B, ThreadIDIntrinsic, Ty);
   }
+  if (D.hasAttr()) {
+llvm::Function *GroupIDIntrinsic = 
CGM.getIntrinsic(Intrinsic::dx_group_id);
+return buildVectorInput(B, GroupIDIntrinsic, Ty);
+  }
   assert(false && "Unhandled parameter attribute");
   return nullptr;
 }
diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp
index b36ea4012c26e1..2f67718f94c68c 100644
--- a/clang/lib/Parse/ParseHLSL.cpp
+++ b/clang/lib/Parse/ParseHLSL.cpp
@@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs,
   case ParsedAttr::UnknownAttribute:
 Diag(Loc, diag::err_unknown_hlsl_semantic) << II;
 return;
+  case ParsedAttr::AT_HLSLSV_GroupID:
   case ParsedAttr::AT_HLSLSV_GroupIndex:
   case ParsedAttr::AT_HLSLSV_DispatchThreadID:
 break;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index d05d326178e1b8..cea51bd507f288 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6990,6 +6990,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
   case ParsedAttr::AT_HLSLWaveSize:
 S.HLSL().handleWaveSizeAttr(D, AL);
 break;
+  case ParsedAttr::AT_HLSLSV_GroupID:
+S.HLSL().handleSV_GroupIDAttr(D, AL);
+b

[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)

2024-11-24 Thread Zhengxing li via cfe-commits


@@ -784,6 +785,17 @@ void SemaHLSL::handleSV_DispatchThreadIDAttr(Decl *D, 
const ParsedAttr &AL) {
  HLSLSV_DispatchThreadIDAttr(getASTContext(), AL));
 }
 
+void SemaHLSL::handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL) {
+  auto *VD = cast(D);
+  if (!isLegalTypeForHLSLSV_ThreadOrGroupID(VD->getType())) {
+Diag(AL.getLoc(), diag::err_hlsl_attr_invalid_type)
+<< AL << "uint/uint2/uint3";

lizhengxing wrote:

@llvm-beanz  Done. Renamed the function name to `diagnoseInputIDType`

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

AidanGoldfarb wrote:

ping @pinskia @AaronBallman 

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


[clang] [clang-tools-extra] Move isLocal AST matcher to ASTMatchers for reusability (PR #117521)

2024-11-24 Thread Marie Zhussupova via cfe-commits

https://github.com/phychee created 
https://github.com/llvm/llvm-project/pull/117521

Fixes #<117431>

>From ee0c3b11c93dc8d95f521cda7c2ac9acc7c184f7 Mon Sep 17 00:00:00 2001
From: Marie Zhussupova <102762019+phyc...@users.noreply.github.com>
Date: Sun, 24 Nov 2024 22:45:11 -0600
Subject: [PATCH] Move isLocal AST matcher to ASTMatchers for reusability

---
 clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp | 3 ---
 clang/include/clang/ASTMatchers/ASTMatchers.h   | 5 +
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 71a4cee4bdc6ef..7c159d8dd8659b 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -17,9 +17,6 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::misc {
 
 namespace {
-// FIXME: This matcher exists in some other code-review as well.
-// It should probably move to ASTMatchers.
-AST_MATCHER(VarDecl, isLocal) { return Node.isLocalVarDecl(); }
 AST_MATCHER_P(DeclStmt, containsAnyDeclaration,
   ast_matchers::internal::Matcher, InnerMatcher) {
   return ast_matchers::internal::matchesFirstInPointerRange(
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 4bcaa953a61af2..f8388028d2ccbe 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -739,6 +739,11 @@ AST_MATCHER(FunctionDecl, isMain) {
   return Node.isMain();
 }
 
+// Matches variable declarations that represent local variables.
+AST_MATCHER(VarDecl, isLocal) { 
+return Node.isLocalVarDecl(); 
+}
+
 /// Matches the specialized template of a specialization declaration.
 ///
 /// Given

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


[clang] [clang-tools-extra] Move isLocal AST matcher to ASTMatchers for reusability (PR #117521)

2024-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Marie Zhussupova (phychee)


Changes

Fixes #<117431>

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


2 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp (-3) 
- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+5) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 71a4cee4bdc6ef..7c159d8dd8659b 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -17,9 +17,6 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::misc {
 
 namespace {
-// FIXME: This matcher exists in some other code-review as well.
-// It should probably move to ASTMatchers.
-AST_MATCHER(VarDecl, isLocal) { return Node.isLocalVarDecl(); }
 AST_MATCHER_P(DeclStmt, containsAnyDeclaration,
   ast_matchers::internal::Matcher, InnerMatcher) {
   return ast_matchers::internal::matchesFirstInPointerRange(
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 4bcaa953a61af2..f8388028d2ccbe 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -739,6 +739,11 @@ AST_MATCHER(FunctionDecl, isMain) {
   return Node.isMain();
 }
 
+// Matches variable declarations that represent local variables.
+AST_MATCHER(VarDecl, isLocal) { 
+return Node.isLocalVarDecl(); 
+}
+
 /// Matches the specialized template of a specialization declaration.
 ///
 /// Given

``




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


[clang] [clang-tools-extra] Move isLocal AST matcher to ASTMatchers for reusability (PR #117521)

2024-11-24 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [clang-tools-extra] Move isLocal AST matcher to ASTMatchers for reusability (PR #117521)

2024-11-24 Thread Marie Zhussupova via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Justin Fargnoli via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Aidan Goldfarb (AidanGoldfarb)


Changes

This PR addresses #116880 

Updated 
[LanguageExtensions.rst](https://github.com/llvm/llvm-project/blob/main/clang/docs/LanguageExtensions.rst)
 to include support for C++11 enumerations with a fixed underlying type in C. 
Included a note that this is only a language extension prior to C23. 

Updated 
[Features.def](https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/Features.def)
 to support for `__has_extension(c_fixed_enum)` by added it as a feature (for 
C23) and an extension (for `_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 9088c867d53ce4..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -308,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 4f6d04ba7f9182..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -121,6 +121,15 @@ int NegativeShortTest[NegativeShort == -1 ? 1 : -1];
 enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag 
type that does not match previous declaration}}
 
+// Enumerations with a fixed underlying type. 
+// https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in 


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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)

2024-11-24 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/114062

>From d2d2d3d5db3f639aab178f9ca9a20db2842d2b65 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 29 Oct 2024 14:20:44 +
Subject: [PATCH 01/11] `sret` args should always point to the `alloca` AS, so
 we can use that.

---
 clang/lib/CodeGen/CGCall.cpp   | 15 ---
 clang/test/CodeGen/partial-reinitialization2.c |  4 ++--
 clang/test/CodeGen/sret.c  | 11 +++
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 8f4f5d3ed81601..56acfae7ae9e51 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1672,8 +1672,7 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) {
 
   // Add type for sret argument.
   if (IRFunctionArgs.hasSRetArg()) {
-QualType Ret = FI.getReturnType();
-unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(Ret);
+unsigned AddressSpace = CGM.getDataLayout().getAllocaAddrSpace();
 ArgTypes[IRFunctionArgs.getSRetArgNo()] =
 llvm::PointerType::get(getLLVMContext(), AddressSpace);
   }
@@ -5145,7 +5144,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   // If the call returns a temporary with struct return, create a temporary
   // alloca to hold the result, unless one is given to us.
   Address SRetPtr = Address::invalid();
-  RawAddress SRetAlloca = RawAddress::invalid();
   llvm::Value *UnusedReturnSizePtr = nullptr;
   if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) {
 // For virtual function pointer thunks and musttail calls, we must always
@@ -5159,16 +5157,19 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 } else if (!ReturnValue.isNull()) {
   SRetPtr = ReturnValue.getAddress();
 } else {
-  SRetPtr = CreateMemTemp(RetTy, "tmp", &SRetAlloca);
+  SRetPtr = CreateMemTempWithoutCast(RetTy, "tmp");
   if (HaveInsertPoint() && ReturnValue.isUnused()) {
 llvm::TypeSize size =
 CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy));
-UnusedReturnSizePtr = EmitLifetimeStart(size, SRetAlloca.getPointer());
+UnusedReturnSizePtr = EmitLifetimeStart(size, 
SRetPtr.getBasePointer());
   }
 }
 if (IRFunctionArgs.hasSRetArg()) {
+  // If the caller allocated the return slot, it is possible that the
+  // alloca was AS casted to the default as, so we ensure the cast is
+  // stripped before binding to the sret arg, which is in the allocaAS.
   IRCallArgs[IRFunctionArgs.getSRetArgNo()] =
-  getAsNaturalPointerTo(SRetPtr, RetTy);
+  getAsNaturalPointerTo(SRetPtr, RetTy)->stripPointerCasts();
 } else if (RetAI.isInAlloca()) {
   Address Addr =
   Builder.CreateStructGEP(ArgMemory, RetAI.getInAllocaFieldIndex());
@@ -5740,7 +5741,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   // pop this cleanup later on. Being eager about this is OK, since this
   // temporary is 'invisible' outside of the callee.
   if (UnusedReturnSizePtr)
-pushFullExprCleanup(NormalEHLifetimeMarker, SRetAlloca,
+pushFullExprCleanup(NormalEHLifetimeMarker, SRetPtr,
  UnusedReturnSizePtr);
 
   llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
diff --git a/clang/test/CodeGen/partial-reinitialization2.c 
b/clang/test/CodeGen/partial-reinitialization2.c
index e709c1d4ad1ee1..7949a69555031e 100644
--- a/clang/test/CodeGen/partial-reinitialization2.c
+++ b/clang/test/CodeGen/partial-reinitialization2.c
@@ -91,8 +91,8 @@ void test5(void)
 // CHECK-LABEL: test6
 void test6(void)
 {
-  // CHECK: [[LP:%[a-z0-9]+]] = getelementptr{{.*}}%struct.LLP2P2, ptr{{.*}}, 
i32 0, i32 0
-  // CHECK: call {{.*}}get456789(ptr {{.*}}[[LP]])
+  // CHECK: [[VAR:%[a-z0-9]+]] = alloca
+  // CHECK: call {{.*}}get456789(ptr {{.*}}sret{{.*}} [[VAR]])
 
   // CHECK: [[CALL:%[a-z0-9]+]] = call {{.*}}@get235()
   // CHECK: store{{.*}}[[CALL]], {{.*}}[[TMP0:%[a-z0-9.]+]]
diff --git a/clang/test/CodeGen/sret.c b/clang/test/CodeGen/sret.c
index 6d905e89b2c6fd..3b4914f29d2bfe 100644
--- a/clang/test/CodeGen/sret.c
+++ b/clang/test/CodeGen/sret.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -Wno-strict-prototypes -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-strict-prototypes -triple amdgcn-amd-amdhsa 
-emit-llvm -o - | FileCheck --check-prefix=NONZEROALLOCAAS %s
 
 struct abc {
  long a;
@@ -6,18 +7,28 @@ struct abc {
  long c;
  long d;
  long e;
+ long f;
+ long g;
+ long h;
+ long i;
+ long j;
 };
 
 struct abc foo1(void);
 // CHECK-DAG: declare {{.*}} @foo1(ptr dead_on_unwind writable 
sret(%struct.abc)
+// NONZEROALLOCAAS-DAG: declare {{.*}} @foo1(ptr addrspace(5) dead_on_unwind 
writable sret(%struct.abc)
 struct abc foo2();
 // CHECK-DAG: declare {{.*}} @foo2(ptr dead_on_unwind wri

[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)

2024-11-24 Thread Alex Voicu via cfe-commits


@@ -5158,14 +5155,17 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 } else if (!ReturnValue.isNull()) {
   SRetPtr = ReturnValue.getAddress();
 } else {
-  SRetPtr = CreateMemTemp(RetTy, "tmp", &SRetAlloca);
+  SRetPtr = CreateMemTempWithoutCast(RetTy, "tmp");
   if (HaveInsertPoint() && ReturnValue.isUnused()) {
 llvm::TypeSize size =
 CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy));
-UnusedReturnSizePtr = EmitLifetimeStart(size, SRetAlloca.getPointer());
+UnusedReturnSizePtr = EmitLifetimeStart(size, 
SRetPtr.getBasePointer());
   }
 }
 if (IRFunctionArgs.hasSRetArg()) {
+  // If the caller allocated the return slot, it is possible that the

AlexVlx wrote:

Done.

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


[clang] [llvm] [llvm][AMDGPU] Fold `llvm.amdgcn.wavefrontsize` early (PR #114481)

2024-11-24 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/114481

>From 3ba88ce598aaab269169f0a5db5981c9a9ac8603 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Thu, 31 Oct 2024 22:38:36 +
Subject: [PATCH 01/11] Add pass to handle AMDGCN pseudo-intrinsics (abstract
 placeholders for target specific info), and add handling for
 `llvm.amdgcn.wavefrontsize`.

---
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  5 +-
 llvm/lib/Target/AMDGPU/AMDGPU.h   |  9 ++
 .../AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp   | 49 +
 llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def |  2 +
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |  3 +-
 llvm/lib/Target/AMDGPU/CMakeLists.txt |  1 +
 .../AMDGPU/llvm.amdgcn.wavefrontsize.ll   | 99 ++-
 7 files changed, 139 insertions(+), 29 deletions(-)
 create mode 100644 llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp

diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
index bf5f2971cf118c..de6a06dad6a08d 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-unknown-unknown -target-cpu 
tahiti -emit-llvm -o - %s | FileCheck -enable-var-scope 
--check-prefixes=CHECK-AMDGCN,CHECK %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -triple spirv64-amd-amdhsa -emit-llvm -o - %s 
| FileCheck -enable-var-scope --check-prefix=CHECK %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple spirv64-amd-amdhsa -emit-llvm -o - %s 
| FileCheck -enable-var-scope --check-prefixes=CHECK,CHECK-SPIRV %s
 
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
@@ -866,7 +866,8 @@ void test_atomic_inc_dec(__attribute__((address_space(3))) 
uint *lptr, __attribu
 // CHECK-LABEL test_wavefrontsize(
 unsigned test_wavefrontsize() {
 
-  // CHECK: {{.*}}call{{.*}} i32 @llvm.amdgcn.wavefrontsize()
+  // CHECK-AMDGCN: ret i32 {{[0-9]+}}
+  // CHECK-SPIRV: {{.*}}call{{.*}} i32 @llvm.amdgcn.wavefrontsize()
   return __builtin_amdgcn_wavefrontsize();
 }
 
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.h b/llvm/lib/Target/AMDGPU/AMDGPU.h
index 95d0ad0f9dc96a..17d3e6ab7c65ab 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.h
@@ -345,6 +345,15 @@ extern char &AMDGPUPrintfRuntimeBindingID;
 void initializeAMDGPUResourceUsageAnalysisPass(PassRegistry &);
 extern char &AMDGPUResourceUsageAnalysisID;
 
+struct AMDGPUExpandPseudoIntrinsicsPass
+: PassInfoMixin {
+  const AMDGPUTargetMachine &TM;
+  AMDGPUExpandPseudoIntrinsicsPass(const AMDGPUTargetMachine &ATM) : TM(ATM) {}
+  PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+
+  static bool isRequired() { return true; }
+};
+
 struct AMDGPUPrintfRuntimeBindingPass
 : PassInfoMixin {
   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp
new file mode 100644
index 00..faa23bb8550dbc
--- /dev/null
+++ b/llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp
@@ -0,0 +1,49 @@
+//===- AMDGPUExpandPseudoIntrinsics.cpp - Pseudo Intrinsic Expander Pass 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+// This file implements a pass that deals with expanding AMDGCN generic pseudo-
+// intrinsics into target specific quantities / sequences. In this context, a
+// pseudo-intrinsic is an AMDGCN intrinsic that does not directly map to a
+// specific instruction, but rather is intended as a mechanism for abstractly
+// conveying target specific info to a HLL / the FE, without concretely
+// impacting the AST. An example of such an intrinsic is amdgcn.wavefrontsize.
+// This pass should run as early as possible / immediately after Clang CodeGen,
+// so that the optimisation pipeline and the BE operate with concrete target
+// data.
+//===--===//
+
+#include "AMDGPU.h"
+#include "AMDGPUTargetMachine.h"
+#include "GCNSubtarget.h"
+
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+
+using namespace llvm;
+
+static inline PreservedAnalyses expandWaveSizeIntrinsic(const GCNSubtarget &ST,
+Function *WaveSize) {
+  if (WaveSize->hasZeroLiveUses())
+return PreservedAnalyses::all();
+
+  for (auto &&U : WaveSize->users())
+U->replaceAllUsesWith(ConstantInt::get(WaveSize->getReturnType(),
+   ST.getWavefrontSize()));
+
+  return PreservedAnalyses::none();
+}
+
+Preserv

[clang] [flang] [clang][driver] When -fveclib=ArmPL flag is in use, always link against libamath (PR #116432)

2024-11-24 Thread Paul Osmialowski via cfe-commits

pawosm-arm wrote:

As I prepared a piece of code which makes the `-l` flags being treated properly 
when read from a config file (so it won't result in unresolved symbols e.g. 
when used with `-static`), I realized that going the config file way still 
creates a problem: with `-fveclib=ArmPL -lamath` put into a config file, it 
will always be linked with `libamath`, even if the user decides to use 
`-fveclib=none` to override this. And situation of this kind can only be solved 
properly by the patch discussed in this PR.

And there's another rationale behind it I can think of: using `-fopenmp` does 
not require the user to add `-lomp` to the command line, it just happens 
automatically. The sheer logic demands that `-fveclib=ArmPL` should result in 
the same treatment. There is no other provider for ArmPL's veclib functions 
these days than libamath.


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


[clang] [PAC][Driver] Add `-faarch64-jump-table-hardening` flag (PR #113149)

2024-11-24 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/113149

>From 06b865d888142acf2c7a66ea487a14f34169 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Mon, 21 Oct 2024 11:32:02 +0300
Subject: [PATCH] [PAC][clang] Add `-faarch64-jump-table-hardening` driver flag

---
 clang/include/clang/Basic/LangOptions.def| 1 +
 clang/include/clang/Basic/PointerAuthOptions.h   | 3 +++
 clang/include/clang/Driver/Options.td| 1 +
 clang/lib/CodeGen/CodeGenFunction.cpp| 2 ++
 clang/lib/Driver/ToolChains/Clang.cpp| 2 ++
 clang/lib/Frontend/CompilerInvocation.cpp| 8 +++-
 clang/test/CodeGen/ptrauth-function-attributes.c | 5 +
 clang/test/Driver/aarch64-ptrauth.c  | 6 --
 8 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..3b833240e5b68c 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -178,6 +178,7 @@ LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers 
in init/fini arrays")
 LANGOPT(PointerAuthInitFiniAddressDiscrimination, 1, 0,
 "incorporate address discrimination in authenticated function pointers 
in init/fini arrays")
 LANGOPT(PointerAuthELFGOT, 1, 0, "authenticate pointers from GOT")
+LANGOPT(AArch64JumpTableHardening, 1, 0, "use hardened lowering for jump-table 
dispatch")
 
 LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for 
all language standard modes")
 LANGOPT(ExperimentalLateParseAttributes, 1, 0, "experimental late parsing of 
attributes")
diff --git a/clang/include/clang/Basic/PointerAuthOptions.h 
b/clang/include/clang/Basic/PointerAuthOptions.h
index 3deb666b375136..a3a3e50bcde5dc 100644
--- a/clang/include/clang/Basic/PointerAuthOptions.h
+++ b/clang/include/clang/Basic/PointerAuthOptions.h
@@ -172,6 +172,9 @@ struct PointerAuthOptions {
   /// Do indirect goto label addresses need to be authenticated?
   bool IndirectGotos = false;
 
+  /// Use hardened lowering for jump-table dispatch?
+  bool AArch64JumpTableHardening = false;
+
   /// The ABI for C function pointers.
   PointerAuthSchema FunctionPointers;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 40fd48761928b3..1880f3f89bf636 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4353,6 +4353,7 @@ defm ptrauth_init_fini : 
OptInCC1FFlag<"ptrauth-init-fini", "Enable signing of f
 defm ptrauth_init_fini_address_discrimination : 
OptInCC1FFlag<"ptrauth-init-fini-address-discrimination",
   "Enable address discrimination of function pointers in init/fini arrays">;
 defm ptrauth_elf_got : OptInCC1FFlag<"ptrauth-elf-got", "Enable authentication 
of pointers from GOT (ELF only)">;
+defm aarch64_jump_table_hardening: 
OptInCC1FFlag<"aarch64-jump-table-hardening", "Use hardened lowering for 
jump-table dispatch">;
 }
 
 def fenable_matrix : Flag<["-"], "fenable-matrix">, Group,
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index ef6bb4f049d6e8..06a7c3691924ff 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -899,6 +899,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType 
RetTy,
 Fn->addFnAttr("ptrauth-auth-traps");
   if (CodeGenOpts.PointerAuth.IndirectGotos)
 Fn->addFnAttr("ptrauth-indirect-gotos");
+  if (CodeGenOpts.PointerAuth.AArch64JumpTableHardening)
+Fn->addFnAttr("aarch64-jump-table-hardening");
 
   // Apply xray attributes to the function (as a string, for now)
   bool AlwaysXRayAttr = false;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index d3eec9fea0d498..b9f288c2b06647 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1875,6 +1875,8 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
   Args.addOptInFlag(CmdArgs,
 options::OPT_fptrauth_init_fini_address_discrimination,
 options::OPT_fno_ptrauth_init_fini_address_discrimination);
+  Args.addOptInFlag(CmdArgs, options::OPT_faarch64_jump_table_hardening,
+options::OPT_fno_aarch64_jump_table_hardening);
 }
 
 void Clang::AddLoongArchTargetArgs(const ArgList &Args,
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 3dd94c31b2bc7a..98136b7a455d9c 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1511,6 +1511,7 @@ void CompilerInvocation::setDefaultPointerAuthOptions(
   Opts.ReturnAddresses = LangOpts.PointerAuthReturns;
   Opts.AuthTraps = LangOpts.PointerAuthAuthTraps;
   Opts.IndirectGotos = LangOpts.PointerAuthIndirectGotos;
+  Opts.AArch64JumpTableHardening = LangOpts.AArch64JumpTable

[clang-tools-extra] e3aafe4 - [clang-tidy] fix false positive use-internal-linkage for func decl without body (#117490)

2024-11-24 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-11-25T06:46:10+08:00
New Revision: e3aafe407af36f580148d3ceccd1aa13a490f7c9

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

LOG: [clang-tidy] fix false positive use-internal-linkage for func decl without 
body (#117490)

If in one TU, function only have declaration without body, this function
should be external linkage.
Fixed #117488

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst

clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
index d900978f65a944..71eb2d94cd4f26 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
@@ -8,14 +8,12 @@
 
 #include "UseInternalLinkageCheck.h"
 #include "../utils/FileExtensionsUtils.h"
-#include "../utils/LexerUtils.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/ASTMatchers/ASTMatchersMacros.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/STLExtras.h"
 
@@ -47,6 +45,8 @@ namespace {
 
 AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
 
+AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); }
+
 static bool isInMainFile(SourceLocation L, SourceManager &SM,
  const FileExtensionsSet &HeaderFileExtensions) {
   for (;;) {
@@ -103,7 +103,7 @@ void UseInternalLinkageCheck::registerMatchers(MatchFinder 
*Finder) {
 // 4. friend
 hasAncestor(friendDecl();
   Finder->addMatcher(
-  functionDecl(Common, unless(cxxMethodDecl()), unless(isMain()))
+  functionDecl(Common, hasBody(), unless(cxxMethodDecl()), 
unless(isMain()))
   .bind("fn"),
   this);
   Finder->addMatcher(varDecl(Common, hasGlobalStorage()).bind("var"), this);

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 8c9fedf4b4406c..1f338f23f4e6ea 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -229,8 +229,9 @@ Changes in existing checks
   false positive for C++23 deducing this.
 
 - Improved :doc:`misc-use-internal-linkage
-  ` check to insert ``static`` 
keyword
-  before type qualifiers such as ``const`` and ``volatile``.
+  ` check to insert ``static``
+  keyword before type qualifiers such as ``const`` and ``volatile`` and fix
+  false positives for function declaration without body.
 
 - Improved :doc:`modernize-avoid-c-arrays
   ` check to suggest using 

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst 
b/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
index 7147af9a7919bc..b8bbcc62706101 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
@@ -16,7 +16,7 @@ Example:
 
   int v1; // can be marked as static
 
-  void fn1(); // can be marked as static
+  void fn1() {} // can be marked as static
 
   namespace {
 // already in anonymous namespace
@@ -26,6 +26,9 @@ Example:
   // already declared as extern
   extern int v2;
 
+  void fn3(); // without function body in all declaration, maybe external 
linkage
+  void fn3();
+
 Options
 ---
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp
index 8dc739da3a2734..bf0d2c2513e562 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp
@@ -13,59 +13,59 @@ void func_template() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_template'
 // CHECK-FIXES: static void func_template() {}
 
-void func_cpp_inc();
+void func_cpp_inc() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc'
-// CHECK-FIXES: static void func_cpp_inc();
+// CHECK-FIXES: static void func_cpp_inc() {}
 
-int* func_cpp_inc_return_ptr();
+int* func_cpp_inc_return_ptr() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc_return_ptr'
-// CHECK-FIXES: static int* func_cpp_inc_return_ptr();
+// CHECK-FIXES: static int* func_cpp_inc_return_ptr() {}
 
-co

[clang] ae20dbd - [clang][analysis] refactor the unevaluated api (#117474)

2024-11-24 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-11-25T06:46:47+08:00
New Revision: ae20dbdd63d97c342b89a72e9e839556d0deed07

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

LOG: [clang][analysis] refactor the unevaluated api (#117474)

It is hard to understand for `ExprMutationAnalyzer::isUnevaluated` to
accept 2 Stmt as parameters.
This patch wants to redesign the API to accept only 1 Stmt. Now it will
only check whether stmt is a sub-stmt of an unevaluated stmt.

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
clang/lib/Analysis/ExprMutationAnalyzer.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index e329588290cd4b..2b2d80ea9346bd 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -303,7 +303,7 @@ void InfiniteLoopCheck::check(const 
MatchFinder::MatchResult &Result) {
 }
   }
 
-  if (ExprMutationAnalyzer::isUnevaluated(LoopStmt, *LoopStmt, 
*Result.Context))
+  if (ExprMutationAnalyzer::isUnevaluated(LoopStmt, *Result.Context))
 return;
 
   if (isAtLeastOneCondVarChanged(Func, LoopStmt, Cond, Result.Context))

diff  --git a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h 
b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
index c7a5b016c949d0..7442f4aad531b7 100644
--- a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -47,8 +47,6 @@ class ExprMutationAnalyzer {
 
 const Stmt *findPointeeMutation(const Expr *Exp);
 const Stmt *findPointeeMutation(const Decl *Dec);
-static bool isUnevaluated(const Stmt *Smt, const Stmt &Stm,
-  ASTContext &Context);
 
   private:
 using MutationFinder = const Stmt *(Analyzer::*)(const Expr *);
@@ -58,8 +56,6 @@ class ExprMutationAnalyzer {
  Memoized::ResultMap &MemoizedResults);
 const Stmt *tryEachDeclRef(const Decl *Dec, MutationFinder Finder);
 
-bool isUnevaluated(const Expr *Exp);
-
 const Stmt *findExprMutation(ArrayRef Matches);
 const Stmt *findDeclMutation(ArrayRef Matches);
 const Stmt *
@@ -83,6 +79,10 @@ class ExprMutationAnalyzer {
   ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context)
   : Memorized(), A(Stm, Context, Memorized) {}
 
+  /// check whether stmt is unevaluated. mutation analyzer will ignore the
+  /// content in unevaluated stmt.
+  static bool isUnevaluated(const Stmt *Stm, ASTContext &Context);
+
   bool isMutated(const Expr *Exp) { return findMutation(Exp) != nullptr; }
   bool isMutated(const Decl *Dec) { return findMutation(Dec) != nullptr; }
   const Stmt *findMutation(const Expr *Exp) { return A.findMutation(Exp); }
@@ -101,11 +101,6 @@ class ExprMutationAnalyzer {
 return A.findPointeeMutation(Dec);
   }
 
-  static bool isUnevaluated(const Stmt *Smt, const Stmt &Stm,
-ASTContext &Context) {
-return Analyzer::isUnevaluated(Smt, Stm, Context);
-  }
-
 private:
   Memoized Memorized;
   Analyzer A;

diff  --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index a94b22e051d0e1..be0e8aa5743dd9 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -236,7 +236,7 @@ const Stmt 
*ExprMutationAnalyzer::Analyzer::findMutationMemoized(
   if (!Inserted)
 return Memoized->second;
 
-  if (isUnevaluated(Exp))
+  if (ExprMutationAnalyzer::isUnevaluated(Exp, Context))
 return nullptr;
 
   for (const auto &Finder : Finders) {
@@ -268,41 +268,29 @@ ExprMutationAnalyzer::Analyzer::tryEachDeclRef(const Decl 
*Dec,
   return nullptr;
 }
 
-bool ExprMutationAnalyzer::Analyzer::isUnevaluated(const Stmt *Exp,
-   const Stmt &Stm,
-   ASTContext &Context) {
-  return selectFirst(
- NodeID::value,
- match(
- findFirst(
- stmt(canResolveToExpr(Exp),
-  anyOf(
-  // `Exp` is part of the underlying expression of
-  // decltype/typeof if it has an ancestor of
-  // typeLoc.
-  hasAncestor(typeLoc(unless(
-  hasAncestor(unaryExprOrTypeTraitExpr(),
-  hasAncestor(expr(anyOf(
-  // `UnaryExprOrTypeTraitEx

[clang] [clang-tools-extra] [clang][analysis] refactor the unevaluated api (PR #117474)

2024-11-24 Thread Congcong Cai via cfe-commits

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


[clang] [clang][NFC]add static for internal linkage function (PR #117482)

2024-11-24 Thread Congcong Cai via cfe-commits

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


[clang] 3c344f9 - [clang][tablegen][NFC]add static for internal linkage function (#117479)

2024-11-24 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-11-25T06:48:09+08:00
New Revision: 3c344f92e62ac07faf5df68d73ad765b11f465f2

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

LOG: [clang][tablegen][NFC]add static for internal linkage function (#117479)

Detected by misc-use-internal-linkage

Added: 


Modified: 
clang/utils/TableGen/ClangASTNodesEmitter.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangASTNodesEmitter.cpp 
b/clang/utils/TableGen/ClangASTNodesEmitter.cpp
index 16749d11836246..5971b0012305d9 100644
--- a/clang/utils/TableGen/ClangASTNodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangASTNodesEmitter.cpp
@@ -207,8 +207,9 @@ void clang::EmitClangASTNodes(const RecordKeeper &RK, 
raw_ostream &OS,
   ClangASTNodesEmitter(RK, N, S, PriorizeIfSubclassOf).run(OS);
 }
 
-void printDeclContext(const std::multimap 
&Tree,
-  const Record *DeclContext, raw_ostream &OS) {
+static void
+printDeclContext(const std::multimap &Tree,
+ const Record *DeclContext, raw_ostream &OS) {
   if (!DeclContext->getValueAsBit(AbstractFieldName))
 OS << "DECL_CONTEXT(" << DeclContext->getName() << ")\n";
   auto [II, E] = Tree.equal_range(DeclContext);

diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 4aa7594ffa6eb7..534bf2d01d7957 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1821,9 +1821,9 @@ CreateSemanticSpellings(const 
std::vector &Spellings,
   return Ret;
 }
 
-void WriteSemanticSpellingSwitch(StringRef VarName,
- const SemanticSpellingMap &Map,
- raw_ostream &OS) {
+static void WriteSemanticSpellingSwitch(StringRef VarName,
+const SemanticSpellingMap &Map,
+raw_ostream &OS) {
   OS << "  switch (" << VarName << ") {\ndefault: "
 << "llvm_unreachable(\"Unknown spelling list index\");\n";
   for (const auto &I : Map)
@@ -2367,12 +2367,12 @@ template  static void 
forEachSpelling(const Record &Attr, Fn &&F) {
   }
 }
 
-std::map> NameToAttrsMap;
+static std::map> NameToAttrsMap;
 
 /// Build a map from the attribute name to the Attrs that use that name. If 
more
 /// than one Attr use a name, the arguments could be 
diff erent so a more complex
 /// check is needed in the generated switch.
-void generateNameToAttrsMap(const RecordKeeper &Records) {
+static void generateNameToAttrsMap(const RecordKeeper &Records) {
   for (const auto *A : Records.getAllDerivedDefinitions("Attr")) {
 for (const FlattenedSpelling &S : GetFlattenedSpellings(*A)) {
   auto [It, Inserted] = NameToAttrsMap.try_emplace(S.name());
@@ -3965,9 +3965,9 @@ void EmitClangAttrASTVisitor(const RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "#endif  // ATTR_VISITOR_DECLS_ONLY\n";
 }
 
-void EmitClangAttrTemplateInstantiateHelper(ArrayRef Attrs,
-raw_ostream &OS,
-bool AppliesToDecl) {
+static void
+EmitClangAttrTemplateInstantiateHelper(ArrayRef Attrs,
+   raw_ostream &OS, bool AppliesToDecl) {
 
   OS << "  switch (At->getKind()) {\n";
   for (const auto *Attr : Attrs) {
@@ -4622,7 +4622,7 @@ static bool isParamExpr(const Record *Arg) {
  .Default(false);
 }
 
-void GenerateIsParamExpr(const Record &Attr, raw_ostream &OS) {
+static void GenerateIsParamExpr(const Record &Attr, raw_ostream &OS) {
   OS << "bool isParamExpr(size_t N) const override {\n";
   OS << "  return ";
   auto Args = Attr.getValueAsListOfDefs("Args");
@@ -4633,8 +4633,8 @@ void GenerateIsParamExpr(const Record &Attr, raw_ostream 
&OS) {
   OS << "}\n\n";
 }
 
-void GenerateHandleAttrWithDelayedArgs(const RecordKeeper &Records,
-   raw_ostream &OS) {
+static void GenerateHandleAttrWithDelayedArgs(const RecordKeeper &Records,
+  raw_ostream &OS) {
   OS << "static void handleAttrWithDelayedArgs(Sema &S, Decl *D, ";
   OS << "const ParsedAttr &Attr) {\n";
   OS << "  SmallVector ArgExprs;\n";



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


[clang] [clang][tablegen][NFC]add static for internal linkage function (PR #117479)

2024-11-24 Thread Congcong Cai via cfe-commits

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


[clang] cbdd14e - [clang][NFC]add static for internal linkage function (#117482)

2024-11-24 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-11-25T06:48:33+08:00
New Revision: cbdd14ee9de72c277d9f89a6aa57c54a495f5458

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

LOG: [clang][NFC]add static for internal linkage function (#117482)

Detected by misc-use-internal-linkage

Added: 


Modified: 
clang/lib/AST/APValue.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ByteCode/Disasm.cpp
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumCXXABI.cpp
clang/lib/AST/ParentMapContext.cpp
clang/lib/Basic/Attributes.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/lib/Sema/SemaHLSL.cpp

Removed: 




diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 4f5d14cbd59bbf..bc5b05fde425ac 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -1087,7 +1087,7 @@ void APValue::MakeArray(unsigned InitElts, unsigned Size) 
{
   Kind = Array;
 }
 
-MutableArrayRef
+static MutableArrayRef
 setLValueUninit(APValue::LValueBase B, const CharUnits &O, unsigned Size,
 bool OnePastTheEnd, bool IsNullPtr);
 

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index baed1416635432..a0cd57e2e5ee0d 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -104,8 +104,8 @@ namespace clang {
   char ASTImportError::ID;
 
   template 
-  SmallVector
-  getCanonicalForwardRedeclChain(Redeclarable* D) {
+  static SmallVector
+  getCanonicalForwardRedeclChain(Redeclarable *D) {
 SmallVector Redecls;
 for (auto *R : D->getFirstDecl()->redecls()) {
   if (R != D->getFirstDecl())
@@ -126,7 +126,7 @@ namespace clang {
 llvm_unreachable("Bad declaration kind");
   }
 
-  void updateFlags(const Decl *From, Decl *To) {
+  static void updateFlags(const Decl *From, Decl *To) {
 // Check if some flags or attrs are new in 'From' and copy into 'To'.
 // FIXME: Other flags or attrs?
 if (From->isUsed(false) && !To->isUsed(false))

diff  --git a/clang/lib/AST/ByteCode/Disasm.cpp 
b/clang/lib/AST/ByteCode/Disasm.cpp
index 85522ffd32dcc6..496c1dcef59b51 100644
--- a/clang/lib/AST/ByteCode/Disasm.cpp
+++ b/clang/lib/AST/ByteCode/Disasm.cpp
@@ -33,7 +33,7 @@
 using namespace clang;
 using namespace clang::interp;
 
-template  inline T ReadArg(Program &P, CodePtr &OpPC) {
+template  inline static T ReadArg(Program &P, CodePtr &OpPC) {
   if constexpr (std::is_pointer_v) {
 uint32_t ID = OpPC.read();
 return reinterpret_cast(P.getNativePointer(ID));

diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 144f2291651ccf..b450d8263c30bf 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -47,7 +47,7 @@ static APSInt getAPSIntParam(const InterpFrame *Frame, 
unsigned Index) {
   return R;
 }
 
-PrimType getIntPrimType(const InterpState &S) {
+static PrimType getIntPrimType(const InterpState &S) {
   const TargetInfo &TI = S.getASTContext().getTargetInfo();
   unsigned IntWidth = TI.getIntWidth();
 
@@ -58,7 +58,7 @@ PrimType getIntPrimType(const InterpState &S) {
   llvm_unreachable("Int isn't 16 or 32 bit?");
 }
 
-PrimType getLongPrimType(const InterpState &S) {
+static PrimType getLongPrimType(const InterpState &S) {
   const TargetInfo &TI = S.getASTContext().getTargetInfo();
   unsigned LongWidth = TI.getLongWidth();
 

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 96638b85c452b4..fb701f76231bcd 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1500,7 +1500,8 @@ DeclContext *DeclContext::getPrimaryContext() {
 }
 
 template 
-void collectAllContextsImpl(T *Self, SmallVectorImpl &Contexts) 
{
+static void collectAllContextsImpl(T *Self,
+   SmallVectorImpl &Contexts) {
   for (T *D = Self->getMostRecentDecl(); D; D = D->getPreviousDecl())
 Contexts.push_back(D);
 

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index c6a210459240a8..c6d003073966f3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3824,8 +3824,8 @@ static QualType getSubobjectType(QualType ObjType, 
QualType SubobjType,
 }
 
 /// Find the designated sub-object of an rvalue.
-template
-typename SubobjectHandler::result_type
+template 
+static typename SubobjectHandler::result_type
 findSubobject(EvalInfo &Info, const Expr *E, const CompleteObject &Obj,
   const SubobjectDesignator &Sub, SubobjectHandler &handler) {
   if (Sub.Invalid)
@@ -7106,7 +7106,7 @@ static std::optional CheckDeleteKind(EvalInfo 
&Info, const Expr *E,
 }
 

[clang-tools-extra] [clang-tidy] Fix false positive in cppcoreguidelines-avoid-const-or-ref-data-members when detecting templated classes with inheritance (PR #115180)

2024-11-24 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 closed 
https://github.com/llvm/llvm-project/pull/115180
___
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] fix release note order (PR #117484)

2024-11-24 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-aarch64-sve-vla-2stage` running on `linaro-g3-04` while building 
`clang-tools-extra` at step 11 "build stage 2".

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


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

```
Step 11 (build stage 2) failure: 'ninja' (failure)
...
[7877/8759] Building CXX object 
tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/prescan.cpp.o
[7878/8759] Building CXX object 
tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/preprocessor.cpp.o
[7879/8759] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertExprToHLFIR.cpp.o
[7880/8759] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertVariable.cpp.o
[7881/8759] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Bridge.cpp.o
[7882/8759] Building CXX object 
tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/tools.cpp.o
[7883/8759] Building CXX object 
tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/instrumented-parser.cpp.o
[7884/8759] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/canonicalize-do.cpp.o
[7885/8759] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/canonicalize-omp.cpp.o
[7886/8759] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/DumpEvaluateExpr.cpp.o
FAILED: 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/DumpEvaluateExpr.cpp.o 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage1.install/bin/clang++
 -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/flang/lib/Lower
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/lib/Lower 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/flang/include
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/include 
-isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/../mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/clang/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/../clang/include
 -mcpu=neoverse-512tvb -mllvm -scalable-vectorization=preferred -mllvm 
-treat-scalable-fixed-error-as-warning=false -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion 
-Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument 
-Wstring-conversion   -Wcovered-switch-default -Wno-nested-anon-types 
-O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD 
-MT tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/DumpEvaluateExpr.cpp.o 
-MF tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/DumpEvaluateExpr.cpp.o.d 
-o tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/DumpEvaluateExpr.cpp.o -c 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/lib/Lower/DumpEvaluateExpr.cpp
Killed
[7887/8759] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-namelist.cpp.o
[7888/8759] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/HostAssociations.cpp.o
FAILED: 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/HostAssociations.cpp.o 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage1.install/bin/clang++
 -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/flang/lib/Lower
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/lib/Lower 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/flang/include
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/include 
-isystem 
/home/

[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-11-24 Thread via cfe-commits

yronglin wrote:

Thanks for your review! The latest update add a RecoveryExpr for invalid 
in-class-initializer. But I have some concerns about the inconsistency between 
`RecordDecl::hasInClassInitializer()` and  
`FieldDecl::hasInClassInitializer()`. FieldDecl has a method 
`removeInClassInitializer` to modifiy the AST Node.

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


[clang] [Sema] Migrate away from PointerUnion::{is, get} (NFC) (PR #117498)

2024-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


---

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


13 Files Affected:

- (modified) clang/lib/Sema/SemaAPINotes.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+8-8) 
- (modified) clang/lib/Sema/SemaConcept.cpp (+3-4) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaFunctionEffects.cpp (+6-8) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+4-4) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+6-6) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+5-5) 
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+10-10) 
- (modified) clang/lib/Sema/TreeTransform.h (+1-1) 


``diff
diff --git a/clang/lib/Sema/SemaAPINotes.cpp b/clang/lib/Sema/SemaAPINotes.cpp
index 028bf82f3e8040..0dedfc490c86fd 100644
--- a/clang/lib/Sema/SemaAPINotes.cpp
+++ b/clang/lib/Sema/SemaAPINotes.cpp
@@ -482,7 +482,7 @@ static void ProcessAPINotes(Sema &S, FunctionOrMethod 
AnyFunc,
   Decl *D = FD;
   ObjCMethodDecl *MD = nullptr;
   if (!D) {
-MD = AnyFunc.get();
+MD = cast(AnyFunc);
 D = MD;
   }
 
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 12da3a2cbca314..bc038acc88855f 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -131,8 +131,8 @@ class ResultBuilder {
   }
 
   // Add the new element to the end of the vector.
-  DeclOrVector.get()->push_back(
-  DeclIndexPair(ND, Index));
+  cast(DeclOrVector)
+  ->push_back(DeclIndexPair(ND, Index));
 }
 
 ~ShadowMapEntry() {
@@ -659,13 +659,13 @@ class ResultBuilder::ShadowMapEntry::iterator {
   : DeclOrIterator(Iterator), SingleDeclIndex(0) {}
 
   iterator &operator++() {
-if (DeclOrIterator.is()) {
+if (isa(DeclOrIterator)) {
   DeclOrIterator = (NamedDecl *)nullptr;
   SingleDeclIndex = 0;
   return *this;
 }
 
-const DeclIndexPair *I = DeclOrIterator.get();
+const DeclIndexPair *I = cast(DeclOrIterator);
 ++I;
 DeclOrIterator = I;
 return *this;
@@ -681,7 +681,7 @@ class ResultBuilder::ShadowMapEntry::iterator {
 if (const NamedDecl *ND = DeclOrIterator.dyn_cast())
   return reference(ND, SingleDeclIndex);
 
-return *DeclOrIterator.get();
+return *cast(DeclOrIterator);
   }
 
   pointer operator->() const { return pointer(**this); }
@@ -705,15 +705,15 @@ ResultBuilder::ShadowMapEntry::begin() const {
   if (const NamedDecl *ND = DeclOrVector.dyn_cast())
 return iterator(ND, SingleDeclIndex);
 
-  return iterator(DeclOrVector.get()->begin());
+  return iterator(cast(DeclOrVector)->begin());
 }
 
 ResultBuilder::ShadowMapEntry::iterator
 ResultBuilder::ShadowMapEntry::end() const {
-  if (DeclOrVector.is() || DeclOrVector.isNull())
+  if (isa(DeclOrVector) || DeclOrVector.isNull())
 return iterator();
 
-  return iterator(DeclOrVector.get()->end());
+  return iterator(cast(DeclOrVector)->end());
 }
 
 /// Compute the qualification required to get from the current context
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 1bdf3a02b2924a..ff1df7b71b1a4f 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1384,8 +1384,7 @@ static void diagnoseUnsatisfiedConstraintExpr(
 return;
   }
 
-  diagnoseWellFormedUnsatisfiedConstraintExpr(S,
-  Record.template get(), First);
+  diagnoseWellFormedUnsatisfiedConstraintExpr(S, cast(Record), First);
 }
 
 void
@@ -1557,12 +1556,12 @@ NormalizedConstraint::NormalizedConstraint(ASTContext 
&C,
 
 NormalizedConstraint &NormalizedConstraint::getLHS() const {
   assert(isCompound() && "getLHS called on a non-compound constraint.");
-  return Constraint.get().getPointer()->LHS;
+  return cast(Constraint).getPointer()->LHS;
 }
 
 NormalizedConstraint &NormalizedConstraint::getRHS() const {
   assert(isCompound() && "getRHS called on a non-compound constraint.");
-  return Constraint.get().getPointer()->RHS;
+  return cast(Constraint).getPointer()->RHS;
 }
 
 std::optional
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 74b0e5ad23bd48..63897dd7a319c2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17276,7 +17276,7 @@

[clang-tools-extra] [clang-tidy] Add recursion protection in ExceptionSpecAnalyzer (PR #66810)

2024-11-24 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Actually only thing that were missing were example.
Added test. I'm not adding release notes as this is crash on invalid anyway, 
and I don't want to add multiple entrys, as this impact multiple checks.

https://github.com/llvm/llvm-project/pull/66810
___
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 recursion protection in ExceptionSpecAnalyzer (PR #66810)

2024-11-24 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)

2024-11-24 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.

LGTM, thanks

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


[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)

2024-11-24 Thread Julian Schmidt via cfe-commits


@@ -240,6 +240,9 @@ void UseStartsEndsWithCheck::check(const 
MatchFinder::MatchResult &Result) {
ReplacementFunction->getName());
 
   // Replace arguments and everything after the function call.
+  if (FindExpr->getNumArgs() == 0) {
+return;
+  }

5chmidti wrote:

IMO it should be after the diagnostic, before the first fixit, because the 
access to the first parameter is only needed to emit the fixit, not the 
warning. On the other hand, the situation should never occur.

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


[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)

2024-11-24 Thread Julian Schmidt via cfe-commits


@@ -183,40 +210,47 @@ void UseStartsEndsWithCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *EndsWithFunction =
   Result.Nodes.getNodeAs("ends_with_fun");
   assert(bool(StartsWithFunction) != bool(EndsWithFunction));
+
   const CXXMethodDecl *ReplacementFunction =
   StartsWithFunction ? StartsWithFunction : EndsWithFunction;
 
-  if (ComparisonExpr->getBeginLoc().isMacroID())
+  if (ComparisonExpr->getBeginLoc().isMacroID() ||
+  FindExpr->getBeginLoc().isMacroID())
 return;
 
-  const bool Neg = ComparisonExpr->getOpcode() == BO_NE;
+  const bool Neg = isNegativeComparison(ComparisonExpr);
 
-  auto Diagnostic =
-  diag(FindExpr->getExprLoc(), "use %0 instead of %1() %select{==|!=}2 0")
-  << ReplacementFunction->getName() << FindFun->getName() << Neg;
+  // Retrieve the source text of the search expression.
+  const auto SearchExprText = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(SearchExpr->getSourceRange()),
+  *Result.SourceManager, Result.Context->getLangOpts());

5chmidti wrote:

> shouldn't that skip macros?

Only at the checked positions. E.g., the needle may still be a macro (as per 
the test you've added from my comment).

https://github.com/llvm/llvm-project/pull/116033
___
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 recursion protection in ExceptionSpecAnalyzer (PR #66810)

2024-11-24 Thread Piotr Zegar via cfe-commits

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

>From c808abe4dcba2a523552863bf7a32736e6bbbc37 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Tue, 19 Sep 2023 19:05:00 +
Subject: [PATCH] [clang-tidy] Add recursion protection in
 ExceptionSpecAnalyzer

Normally endless recursion should not happen in ExceptionSpecAnalyzer,
but if AST would be malformed (missing include), this could cause crash.
---
 .../clang-tidy/utils/ExceptionSpecAnalyzer.cpp  | 13 +++--
 .../performance/noexcept-move-constructor-crash.cpp |  8 
 2 files changed, 15 insertions(+), 6 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor-crash.cpp

diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp 
b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
index 4a9426ee7e8bbb..0637d0eff688cd 100644
--- a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
@@ -14,13 +14,14 @@ namespace clang::tidy::utils {
 
 ExceptionSpecAnalyzer::State
 ExceptionSpecAnalyzer::analyze(const FunctionDecl *FuncDecl) {
-  // Check if the function has already been analyzed and reuse that result.
-  const auto CacheEntry = FunctionCache.find(FuncDecl);
-  if (CacheEntry == FunctionCache.end()) {
+  // Check if function exist in cache or add temporary value to cache to 
protect
+  // against endless recursion.
+  const auto [CacheEntry, NotFound] =
+  FunctionCache.try_emplace(FuncDecl, State::NotThrowing);
+  if (NotFound) {
 ExceptionSpecAnalyzer::State State = analyzeImpl(FuncDecl);
-
-// Cache the result of the analysis.
-FunctionCache.try_emplace(FuncDecl, State);
+// Update result with calculated value
+FunctionCache[FuncDecl] = State;
 return State;
   }
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor-crash.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor-crash.cpp
new file mode 100644
index 00..8cbf1ccbde1505
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor-crash.cpp
@@ -0,0 +1,8 @@
+// RUN: %check_clang_tidy -std=c++17 -expect-clang-tidy-error  %s 
performance-noexcept-move-constructor %t 
+
+template  class set {
+  set(set &&) = default;
+  set(initializer_list __l) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: error: member 'initializer_list' cannot 
have template arguments [clang-diagnostic-error]
+// CHECK-MESSAGES: :[[@LINE-2]]:36: error: expected ')' 
[clang-diagnostic-error]
+};

___
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 recursion protection in ExceptionSpecAnalyzer (PR #66810)

2024-11-24 Thread Piotr Zegar via cfe-commits

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-24 Thread Julian Schmidt via cfe-commits


@@ -102,6 +102,210 @@ void BranchCloneCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
   Finder->addMatcher(switchStmt().bind("switch"), this);
   Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+  
Finder->addMatcher(ifStmt(hasDescendant(ifStmt())).bind("ifWithDescendantIf"),

5chmidti wrote:

The current matcher will check for `if`s as descendants, not only as direct 
children. So code like
```c++
void foo() {
if (true) {
[]() {
if (false) {
}
};
}
}
```

will still produce a match, that you filter out later, instead of in the 
matcher.
A matcher like `ifStmt(anyOf(has(ifStmt().bind("inner_if")), 
has(compoundStmt(has(ifStmt().bind("inner_if").bind("ifWithDescendantIf")` 
will ensure that only direct children are looked at. To enforce the requirement 
of the first statement inside a compound statement, adding a custom matcher 
would be best IMO.

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-24 Thread Julian Schmidt via cfe-commits

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-24 Thread Julian Schmidt via cfe-commits

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


[clang] [llvm] [llvm][AMDGPU] Fold `llvm.amdgcn.wavefrontsize` early (PR #114481)

2024-11-24 Thread Joseph Huber via cfe-commits


@@ -1024,6 +1024,15 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, 
IntrinsicInst &II) const {
 }
 break;
   }
+  case Intrinsic::amdgcn_wavefrontsize: {
+// TODO: this is a workaround for the pseudo-generic target one gets with 
no
+// specified mcpu, which spoofs its wave size to 64; it should be removed.
+if ((ST->getCPU().empty() || ST->getCPU().starts_with("generic")) &&
+!ST->getFeatureString().contains("+wavefrontsize"))
+  break;
+return IC.replaceInstUsesWith(
+II, ConstantInt::get(II.getType(), ST->getWavefrontSize()));
+  }

jhuber6 wrote:

I suppose this is now this?
```
if (ST->isWaveSizeKnown())
 return IC.replaceInstUsesWith(
II, ConstantInt::get(II.getType(), ST->getWavefrontSize()));
```

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-24 Thread Congcong Cai via cfe-commits


@@ -102,6 +102,211 @@ void BranchCloneCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
   Finder->addMatcher(switchStmt().bind("switch"), this);
   Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+  Finder->addMatcher(
+  ifStmt((hasThen(hasDescendant(ifStmt().bind("ifWithDescendantIf"),
+  this);
+}
+
+/// Determines whether two statement trees are identical regarding
+/// operators and symbols.
+///
+/// Exceptions: expressions containing macros or functions with possible side
+/// effects are never considered identical.
+/// Limitations: (t + u) and (u + t) are not considered identical.
+/// t*(u + t) and t*u + t*t are not considered identical.
+///
+static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
+const Stmt *Stmt2, bool IgnoreSideEffects) {
+
+  if (!Stmt1 || !Stmt2)
+return !Stmt1 && !Stmt2;
+
+  // If Stmt1 & Stmt2 are of different class then they are not
+  // identical statements.
+  if (Stmt1->getStmtClass() != Stmt2->getStmtClass())
+return false;
+
+  const auto *Expr1 = dyn_cast(Stmt1);
+  const auto *Expr2 = dyn_cast(Stmt2);
+
+  if (Expr1 && Expr2) {
+// If Stmt1 has side effects then don't warn even if expressions
+// are identical.
+if (!IgnoreSideEffects && Expr1->HasSideEffects(Ctx))
+  return false;
+// If either expression comes from a macro then don't warn even if
+// the expressions are identical.
+if ((Expr1->getExprLoc().isMacroID()) || (Expr2->getExprLoc().isMacroID()))
+  return false;
+
+// If all children of two expressions are identical, return true.
+Expr::const_child_iterator I1 = Expr1->child_begin();
+Expr::const_child_iterator I2 = Expr2->child_begin();
+while (I1 != Expr1->child_end() && I2 != Expr2->child_end()) {
+  if (!*I1 || !*I2 || !isIdenticalStmt(Ctx, *I1, *I2, IgnoreSideEffects))

HerrCai0907 wrote:

`!*I1 || !*I2` already be handled in `isIdenticalStmt`

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-24 Thread Congcong Cai via cfe-commits


@@ -102,6 +102,211 @@ void BranchCloneCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
   Finder->addMatcher(switchStmt().bind("switch"), this);
   Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+  Finder->addMatcher(
+  ifStmt((hasThen(hasDescendant(ifStmt().bind("ifWithDescendantIf"),
+  this);
+}
+
+/// Determines whether two statement trees are identical regarding
+/// operators and symbols.
+///
+/// Exceptions: expressions containing macros or functions with possible side
+/// effects are never considered identical.
+/// Limitations: (t + u) and (u + t) are not considered identical.
+/// t*(u + t) and t*u + t*t are not considered identical.
+///
+static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
+const Stmt *Stmt2, bool IgnoreSideEffects) {
+
+  if (!Stmt1 || !Stmt2)
+return !Stmt1 && !Stmt2;
+
+  // If Stmt1 & Stmt2 are of different class then they are not
+  // identical statements.
+  if (Stmt1->getStmtClass() != Stmt2->getStmtClass())
+return false;
+
+  const auto *Expr1 = dyn_cast(Stmt1);
+  const auto *Expr2 = dyn_cast(Stmt2);
+
+  if (Expr1 && Expr2) {
+// If Stmt1 has side effects then don't warn even if expressions
+// are identical.
+if (!IgnoreSideEffects && Expr1->HasSideEffects(Ctx))

HerrCai0907 wrote:

How about Stmt2 has side effects?

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-24 Thread Congcong Cai via cfe-commits

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


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


[clang] [clang][RISCV] __riscv_v_intrinsic macro doesn't need zve32x (PR #117356)

2024-11-24 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp approved this pull request.

LGTM.

https://github.com/llvm/llvm-project/pull/117356
___
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 recursion protection in ExceptionSpecAnalyzer (PR #66810)

2024-11-24 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti commented:

> Being totally unfamiliar with the code, I have a feeling that we shouldn't be 
> fixing in the analyze function. analyze has 1 single responsibility: wrap 
> `analyzeImpl` in order to add cacheability for performance reasons, it does 
> so simply and well, and it does exactly what one would expect - no more no 
> less.

This class could maintain a stack-like `SmallVector` to check for an infinite 
recursion., so instead of checking the function cache (which might be large), 
only a few functions have to be compared this way.

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


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/3] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/3] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/3] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

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


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Justin Fargnoli via cfe-commits


@@ -121,6 +121,17 @@ int NegativeShortTest[NegativeShort == -1 ? 1 : -1];
 enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag 
type that does not match previous declaration}}
 
+// Enumerations with a fixed underlying type. 
+// https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in https://github.com/llvm/llvm-project/pull/117507
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Justin Fargnoli via cfe-commits

https://github.com/justinfargnoli commented:

Add a title. 

And welcome to the LLVM community :) 

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


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Justin Fargnoli via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/4] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/4] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/4] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 4/4] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

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


[clang-tools-extra] [clang-tidy] Fix false positive in cppcoreguidelines-avoid-const-or-ref-data-members when detecting templated classes with inheritance (PR #115180)

2024-11-24 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.


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


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb created 
https://github.com/llvm/llvm-project/pull/117507

This PR addresses #116880 

Updated 
[LanguageExtensions.rst](https://github.com/llvm/llvm-project/blob/main/clang/docs/LanguageExtensions.rst)
 to include support for C++11 enumerations with a fixed underlying type in C. 
Included a note that this is only a language extension in https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/Features.def)
 to support for `__has_extension(c_fixed_enum)`.

Updated 
[enum.c](https://github.com/llvm/llvm-project/blob/main/clang/test/Sema/enum.c) 
to ensure support of C++11 enumerations with a fixed underlying type in both 
From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/2] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/2] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

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


[clang] [Wunsafe-buffer-usage] Fix false positives in handling array indices that are decidably correct (PR #117370)

2024-11-24 Thread via cfe-commits

https://github.com/mxms0 updated 
https://github.com/llvm/llvm-project/pull/117370

>From 8fed333cf4221dbf1826351da80164db5d209c21 Mon Sep 17 00:00:00 2001
From: mxms 
Date: Fri, 22 Nov 2024 15:09:07 -0500
Subject: [PATCH 1/4] [Wunsafe-buffer-usage] Fix false positives in handling
 enums

Do not warn if the index is an enum and we an determine statically that
it's within bounds.
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp|  7 +++
 .../SemaCXX/warn-unsafe-buffer-usage-array.cpp  | 17 +
 2 files changed, 24 insertions(+)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 5f36ffa926b269..addb724e2e2c9a 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -463,6 +463,13 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   return true;
   }
 
+  // Array index wasn't an integer literal, let's see if it was an enum or
+  // something similar
+  const auto IntConst = 
Node.getIdx()->getIntegerConstantExpr(Finder->getASTContext());
+  if (IntConst && *IntConst > 0 && *IntConst < size) {
+return true;
+  }
+
   return false;
 }
 
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
index c6c93a27e4b969..a65ecdf39edfcc 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
@@ -39,6 +39,23 @@ void constant_idx_unsafe(unsigned idx) {
   buffer[10] = 0;   // expected-note{{used in buffer access here}}
 }
 
+enum FooEnum {
+  A = 0,
+  B = 1,
+  C = 2,
+  D
+};
+
+void constant_enum_safe() {
+  int buffer[FooEnum::D] = { 0, 1, 2 };
+  buffer[C] = 0; // no-warning
+}
+
+void constant_enum_unsafe(FooEnum e) {
+  int buffer[FooEnum::D] = { 0, 1, 2 };
+  buffer[e] = 0; // expected-warning{{unsafe buffer access}}
+}
+
 void constant_id_string(unsigned idx) {
   char safe_char = "abc"[1]; // no-warning
   safe_char = ""[0];

>From 35207ea84425902a70b46f153e9619cc9d544f46 Mon Sep 17 00:00:00 2001
From: mxms 
Date: Fri, 22 Nov 2024 23:45:39 -0500
Subject: [PATCH 2/4] Detect when the buffer is a member access, fix tests

Add a case for when it's a member variable access and we can statically
determine the size. Also add new test to ensure the change works
reliably and update old tests to not expect this warning.
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp  |  2 +-
 .../warn-unsafe-buffer-usage-array.cpp|  5 -
 .../warn-unsafe-buffer-usage-field-attr.cpp   |  1 -
 .../test/SemaCXX/warn-unsafe-buffer-usage.cpp | 21 +--
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index addb724e2e2c9a..c005b34c2f63ad 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -466,7 +466,7 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   // Array index wasn't an integer literal, let's see if it was an enum or
   // something similar
   const auto IntConst = 
Node.getIdx()->getIntegerConstantExpr(Finder->getASTContext());
-  if (IntConst && *IntConst > 0 && *IntConst < size) {
+  if (IntConst && *IntConst >= 0 && *IntConst < size) {
 return true;
   }
 
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
index a65ecdf39edfcc..f5672db18de0ca 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
@@ -47,8 +47,11 @@ enum FooEnum {
 };
 
 void constant_enum_safe() {
-  int buffer[FooEnum::D] = { 0, 1, 2 };
+  int buffer[FooEnum::D] = { 0, 1, 2 }; // expected-warning{{'buffer' is an 
unsafe buffer that does not perform bounds checks}}
+// expected-note@-1{{change type of 
'buffer' to 'std::array' to label it for hardening}}
+  buffer[A] = 0; // no-warning
   buffer[C] = 0; // no-warning
+  buffer[D] = 0; // expected-note{{used in buffer access here}}
 }
 
 void constant_enum_unsafe(FooEnum e) {
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp
index 0ba605475925b9..1636c948da075a 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp
@@ -96,7 +96,6 @@ void test_attribute_multiple_fields (D d) {
 
int v = d.buf[0]; //expected-warning{{field 'buf' prone to unsafe buffer 
manipulation}}
 
-   //expected-warning@+1{{unsafe buffer access}}
v = d.buf[5]; //expected-warning{{field 'buf' prone to unsafe buffer 
manipulation}}
 }
 
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
index 642db0e9d3c632..41194a8e3f5222 100644
--- a/clang/test/SemaCXX/warn-unsafe

[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)

2024-11-24 Thread Lu Weining via cfe-commits


@@ -2011,8 +2011,9 @@ const StringMap sys::getHostCPUFeatures() {
 const StringMap sys::getHostCPUFeatures() {
   unsigned long hwcap = getauxval(AT_HWCAP);
   bool HasFPU = hwcap & (1UL << 3); // HWCAP_LOONGARCH_FPU
-  uint32_t cpucfg2 = 0x2;
+  const uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3;

SixWeining wrote:

Oh, my bad. I'll fix it now.

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


[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)

2024-11-24 Thread Lu Weining via cfe-commits


@@ -2011,8 +2011,9 @@ const StringMap sys::getHostCPUFeatures() {
 const StringMap sys::getHostCPUFeatures() {
   unsigned long hwcap = getauxval(AT_HWCAP);
   bool HasFPU = hwcap & (1UL << 3); // HWCAP_LOONGARCH_FPU
-  uint32_t cpucfg2 = 0x2;
+  const uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3;

SixWeining wrote:

Should already be fixed.

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


[clang] [clang] constexpr built-in elementwise popcount function. (PR #117473)

2024-11-24 Thread via cfe-commits


@@ -797,3 +797,8 @@ 
static_assert(__builtin_reduce_xor((vector4int){(int)0x, (int)0x
 static_assert(__builtin_reduce_xor((vector4long){(long 
long)0xL, (long long)0xL, (long 
long)0xL, (long long)0xL}) == (long 
long)0xL);
 static_assert(__builtin_reduce_xor((vector4uint){0xU, 0xU, 
0xU, 0xU}) == 0xU);
 static_assert(__builtin_reduce_xor((vector4ulong){0xUL, 
0xUL, 0xUL, 0xUL}) == 
0xUL);
+
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4int){1,
 2, 3, 4})) == 5);
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4int){0,
 0xF0F0, ~0, ~0xF0F0})) == 16 * sizeof(int));
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4long){1L,
 2L, 3L, 4L})) == 5L);
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4long){0L,
 0xF0F0L, ~0L, ~0xF0F0L})) == 16 * sizeof(long long));

c8ef wrote:

Done.

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


[clang] [clang-tools-extra] [clang][analysis] refactor the unevaluated api (PR #117474)

2024-11-24 Thread Piotr Zegar via cfe-commits

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

LGTM

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


[clang] [clang][tablegen][NFC]add static for internal linkage function (PR #117479)

2024-11-24 Thread Congcong Cai via cfe-commits

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

Detected by misc-use-internal-linkage


>From c3c37db297c2db4e8e4d8009e30819cdabf05df8 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 24 Nov 2024 19:42:51 +0800
Subject: [PATCH] [clang][tablegen][NFC]add static for internal linkage
 function

Detected by misc-use-internal-linkage
---
 clang/utils/TableGen/ClangASTNodesEmitter.cpp |  5 +++--
 clang/utils/TableGen/ClangAttrEmitter.cpp | 22 +--
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/clang/utils/TableGen/ClangASTNodesEmitter.cpp 
b/clang/utils/TableGen/ClangASTNodesEmitter.cpp
index 16749d11836246..5971b0012305d9 100644
--- a/clang/utils/TableGen/ClangASTNodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangASTNodesEmitter.cpp
@@ -207,8 +207,9 @@ void clang::EmitClangASTNodes(const RecordKeeper &RK, 
raw_ostream &OS,
   ClangASTNodesEmitter(RK, N, S, PriorizeIfSubclassOf).run(OS);
 }
 
-void printDeclContext(const std::multimap 
&Tree,
-  const Record *DeclContext, raw_ostream &OS) {
+static void
+printDeclContext(const std::multimap &Tree,
+ const Record *DeclContext, raw_ostream &OS) {
   if (!DeclContext->getValueAsBit(AbstractFieldName))
 OS << "DECL_CONTEXT(" << DeclContext->getName() << ")\n";
   auto [II, E] = Tree.equal_range(DeclContext);
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 4aa7594ffa6eb7..534bf2d01d7957 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1821,9 +1821,9 @@ CreateSemanticSpellings(const 
std::vector &Spellings,
   return Ret;
 }
 
-void WriteSemanticSpellingSwitch(StringRef VarName,
- const SemanticSpellingMap &Map,
- raw_ostream &OS) {
+static void WriteSemanticSpellingSwitch(StringRef VarName,
+const SemanticSpellingMap &Map,
+raw_ostream &OS) {
   OS << "  switch (" << VarName << ") {\ndefault: "
 << "llvm_unreachable(\"Unknown spelling list index\");\n";
   for (const auto &I : Map)
@@ -2367,12 +2367,12 @@ template  static void 
forEachSpelling(const Record &Attr, Fn &&F) {
   }
 }
 
-std::map> NameToAttrsMap;
+static std::map> NameToAttrsMap;
 
 /// Build a map from the attribute name to the Attrs that use that name. If 
more
 /// than one Attr use a name, the arguments could be different so a more 
complex
 /// check is needed in the generated switch.
-void generateNameToAttrsMap(const RecordKeeper &Records) {
+static void generateNameToAttrsMap(const RecordKeeper &Records) {
   for (const auto *A : Records.getAllDerivedDefinitions("Attr")) {
 for (const FlattenedSpelling &S : GetFlattenedSpellings(*A)) {
   auto [It, Inserted] = NameToAttrsMap.try_emplace(S.name());
@@ -3965,9 +3965,9 @@ void EmitClangAttrASTVisitor(const RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "#endif  // ATTR_VISITOR_DECLS_ONLY\n";
 }
 
-void EmitClangAttrTemplateInstantiateHelper(ArrayRef Attrs,
-raw_ostream &OS,
-bool AppliesToDecl) {
+static void
+EmitClangAttrTemplateInstantiateHelper(ArrayRef Attrs,
+   raw_ostream &OS, bool AppliesToDecl) {
 
   OS << "  switch (At->getKind()) {\n";
   for (const auto *Attr : Attrs) {
@@ -4622,7 +4622,7 @@ static bool isParamExpr(const Record *Arg) {
  .Default(false);
 }
 
-void GenerateIsParamExpr(const Record &Attr, raw_ostream &OS) {
+static void GenerateIsParamExpr(const Record &Attr, raw_ostream &OS) {
   OS << "bool isParamExpr(size_t N) const override {\n";
   OS << "  return ";
   auto Args = Attr.getValueAsListOfDefs("Args");
@@ -4633,8 +4633,8 @@ void GenerateIsParamExpr(const Record &Attr, raw_ostream 
&OS) {
   OS << "}\n\n";
 }
 
-void GenerateHandleAttrWithDelayedArgs(const RecordKeeper &Records,
-   raw_ostream &OS) {
+static void GenerateHandleAttrWithDelayedArgs(const RecordKeeper &Records,
+  raw_ostream &OS) {
   OS << "static void handleAttrWithDelayedArgs(Sema &S, Decl *D, ";
   OS << "const ParsedAttr &Attr) {\n";
   OS << "  SmallVector ArgExprs;\n";

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


[clang] [clang][tablegen][NFC]add static for internal linkage function (PR #117479)

2024-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Congcong Cai (HerrCai0907)


Changes

Detected by misc-use-internal-linkage


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


2 Files Affected:

- (modified) clang/utils/TableGen/ClangASTNodesEmitter.cpp (+3-2) 
- (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (+11-11) 


``diff
diff --git a/clang/utils/TableGen/ClangASTNodesEmitter.cpp 
b/clang/utils/TableGen/ClangASTNodesEmitter.cpp
index 16749d11836246..5971b0012305d9 100644
--- a/clang/utils/TableGen/ClangASTNodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangASTNodesEmitter.cpp
@@ -207,8 +207,9 @@ void clang::EmitClangASTNodes(const RecordKeeper &RK, 
raw_ostream &OS,
   ClangASTNodesEmitter(RK, N, S, PriorizeIfSubclassOf).run(OS);
 }
 
-void printDeclContext(const std::multimap 
&Tree,
-  const Record *DeclContext, raw_ostream &OS) {
+static void
+printDeclContext(const std::multimap &Tree,
+ const Record *DeclContext, raw_ostream &OS) {
   if (!DeclContext->getValueAsBit(AbstractFieldName))
 OS << "DECL_CONTEXT(" << DeclContext->getName() << ")\n";
   auto [II, E] = Tree.equal_range(DeclContext);
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 4aa7594ffa6eb7..534bf2d01d7957 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1821,9 +1821,9 @@ CreateSemanticSpellings(const 
std::vector &Spellings,
   return Ret;
 }
 
-void WriteSemanticSpellingSwitch(StringRef VarName,
- const SemanticSpellingMap &Map,
- raw_ostream &OS) {
+static void WriteSemanticSpellingSwitch(StringRef VarName,
+const SemanticSpellingMap &Map,
+raw_ostream &OS) {
   OS << "  switch (" << VarName << ") {\ndefault: "
 << "llvm_unreachable(\"Unknown spelling list index\");\n";
   for (const auto &I : Map)
@@ -2367,12 +2367,12 @@ template  static void 
forEachSpelling(const Record &Attr, Fn &&F) {
   }
 }
 
-std::map> NameToAttrsMap;
+static std::map> NameToAttrsMap;
 
 /// Build a map from the attribute name to the Attrs that use that name. If 
more
 /// than one Attr use a name, the arguments could be different so a more 
complex
 /// check is needed in the generated switch.
-void generateNameToAttrsMap(const RecordKeeper &Records) {
+static void generateNameToAttrsMap(const RecordKeeper &Records) {
   for (const auto *A : Records.getAllDerivedDefinitions("Attr")) {
 for (const FlattenedSpelling &S : GetFlattenedSpellings(*A)) {
   auto [It, Inserted] = NameToAttrsMap.try_emplace(S.name());
@@ -3965,9 +3965,9 @@ void EmitClangAttrASTVisitor(const RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "#endif  // ATTR_VISITOR_DECLS_ONLY\n";
 }
 
-void EmitClangAttrTemplateInstantiateHelper(ArrayRef Attrs,
-raw_ostream &OS,
-bool AppliesToDecl) {
+static void
+EmitClangAttrTemplateInstantiateHelper(ArrayRef Attrs,
+   raw_ostream &OS, bool AppliesToDecl) {
 
   OS << "  switch (At->getKind()) {\n";
   for (const auto *Attr : Attrs) {
@@ -4622,7 +4622,7 @@ static bool isParamExpr(const Record *Arg) {
  .Default(false);
 }
 
-void GenerateIsParamExpr(const Record &Attr, raw_ostream &OS) {
+static void GenerateIsParamExpr(const Record &Attr, raw_ostream &OS) {
   OS << "bool isParamExpr(size_t N) const override {\n";
   OS << "  return ";
   auto Args = Attr.getValueAsListOfDefs("Args");
@@ -4633,8 +4633,8 @@ void GenerateIsParamExpr(const Record &Attr, raw_ostream 
&OS) {
   OS << "}\n\n";
 }
 
-void GenerateHandleAttrWithDelayedArgs(const RecordKeeper &Records,
-   raw_ostream &OS) {
+static void GenerateHandleAttrWithDelayedArgs(const RecordKeeper &Records,
+  raw_ostream &OS) {
   OS << "static void handleAttrWithDelayedArgs(Sema &S, Decl *D, ";
   OS << "const ParsedAttr &Attr) {\n";
   OS << "  SmallVector ArgExprs;\n";

``




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


[clang] [Clang][Driver] report unsupported option error when link + compile in same process (PR #116476)

2024-11-24 Thread Reno Dakota via cfe-commits

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


[clang-tools-extra] [clang-tidy] fix false positive use-internal-linkage for func decl without body (PR #117490)

2024-11-24 Thread Congcong Cai via cfe-commits

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

If in one TU, function only have declaration without body, this function should 
be external linkage.
Fixed #117488


>From a1f2a6523c69bf09f39e478a8108a621ba959c20 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 24 Nov 2024 21:55:15 +0800
Subject: [PATCH] [clang-tidy] fix false positive use-internal-linkage for func
 decl without body

If in one TU, function only have declaration without body, this function should 
be external linkage.
Fixed #117488
---
 .../misc/UseInternalLinkageCheck.cpp  |  6 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +-
 .../checks/misc/use-internal-linkage.rst  |  5 +-
 .../misc/use-internal-linkage-func.cpp| 56 +++
 4 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
index d900978f65a944..71eb2d94cd4f26 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
@@ -8,14 +8,12 @@
 
 #include "UseInternalLinkageCheck.h"
 #include "../utils/FileExtensionsUtils.h"
-#include "../utils/LexerUtils.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/ASTMatchers/ASTMatchersMacros.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/STLExtras.h"
 
@@ -47,6 +45,8 @@ namespace {
 
 AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
 
+AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); }
+
 static bool isInMainFile(SourceLocation L, SourceManager &SM,
  const FileExtensionsSet &HeaderFileExtensions) {
   for (;;) {
@@ -103,7 +103,7 @@ void UseInternalLinkageCheck::registerMatchers(MatchFinder 
*Finder) {
 // 4. friend
 hasAncestor(friendDecl();
   Finder->addMatcher(
-  functionDecl(Common, unless(cxxMethodDecl()), unless(isMain()))
+  functionDecl(Common, hasBody(), unless(cxxMethodDecl()), 
unless(isMain()))
   .bind("fn"),
   this);
   Finder->addMatcher(varDecl(Common, hasGlobalStorage()).bind("var"), this);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 8c9fedf4b4406c..1f338f23f4e6ea 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -229,8 +229,9 @@ Changes in existing checks
   false positive for C++23 deducing this.
 
 - Improved :doc:`misc-use-internal-linkage
-  ` check to insert ``static`` 
keyword
-  before type qualifiers such as ``const`` and ``volatile``.
+  ` check to insert ``static``
+  keyword before type qualifiers such as ``const`` and ``volatile`` and fix
+  false positives for function declaration without body.
 
 - Improved :doc:`modernize-avoid-c-arrays
   ` check to suggest using 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst 
b/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
index 7147af9a7919bc..b8bbcc62706101 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
@@ -16,7 +16,7 @@ Example:
 
   int v1; // can be marked as static
 
-  void fn1(); // can be marked as static
+  void fn1() {} // can be marked as static
 
   namespace {
 // already in anonymous namespace
@@ -26,6 +26,9 @@ Example:
   // already declared as extern
   extern int v2;
 
+  void fn3(); // without function body in all declaration, maybe external 
linkage
+  void fn3();
+
 Options
 ---
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp
index 8dc739da3a2734..bf0d2c2513e562 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp
@@ -13,59 +13,59 @@ void func_template() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_template'
 // CHECK-FIXES: static void func_template() {}
 
-void func_cpp_inc();
+void func_cpp_inc() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc'
-// CHECK-FIXES: static void func_cpp_inc();
+// CHECK-FIXES: static void func_cpp_inc() {}
 
-int* func_cpp_inc_return_ptr();
+int* func_cpp_inc_return_ptr() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc_return_ptr'
-// CHECK-FIXES: static int* func_cpp_inc_return_ptr();
+// CHECK-FIXES: static int* func_cpp_inc_return_ptr() {}
 
-const int* func_cpp_inc_return_const_ptr();
+const int* func_cpp_

[clang] [Clang][Driver] report unsupported option error when link + compile in same process (PR #116476)

2024-11-24 Thread Reno Dakota via cfe-commits

paparodeo wrote:

Ping

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


[clang-tools-extra] [clang-tidy] fix false positive use-internal-linkage for func decl without body (PR #117490)

2024-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes

If in one TU, function only have declaration without body, this function should 
be external linkage.
Fixed #117488


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


4 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp 
(+3-3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+3-2) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst (+4-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp 
(+33-23) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
index d900978f65a944..71eb2d94cd4f26 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
@@ -8,14 +8,12 @@
 
 #include "UseInternalLinkageCheck.h"
 #include "../utils/FileExtensionsUtils.h"
-#include "../utils/LexerUtils.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/ASTMatchers/ASTMatchersMacros.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/STLExtras.h"
 
@@ -47,6 +45,8 @@ namespace {
 
 AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
 
+AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); }
+
 static bool isInMainFile(SourceLocation L, SourceManager &SM,
  const FileExtensionsSet &HeaderFileExtensions) {
   for (;;) {
@@ -103,7 +103,7 @@ void UseInternalLinkageCheck::registerMatchers(MatchFinder 
*Finder) {
 // 4. friend
 hasAncestor(friendDecl();
   Finder->addMatcher(
-  functionDecl(Common, unless(cxxMethodDecl()), unless(isMain()))
+  functionDecl(Common, hasBody(), unless(cxxMethodDecl()), 
unless(isMain()))
   .bind("fn"),
   this);
   Finder->addMatcher(varDecl(Common, hasGlobalStorage()).bind("var"), this);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 8c9fedf4b4406c..1f338f23f4e6ea 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -229,8 +229,9 @@ Changes in existing checks
   false positive for C++23 deducing this.
 
 - Improved :doc:`misc-use-internal-linkage
-  ` check to insert ``static`` 
keyword
-  before type qualifiers such as ``const`` and ``volatile``.
+  ` check to insert ``static``
+  keyword before type qualifiers such as ``const`` and ``volatile`` and fix
+  false positives for function declaration without body.
 
 - Improved :doc:`modernize-avoid-c-arrays
   ` check to suggest using 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst 
b/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
index 7147af9a7919bc..b8bbcc62706101 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
@@ -16,7 +16,7 @@ Example:
 
   int v1; // can be marked as static
 
-  void fn1(); // can be marked as static
+  void fn1() {} // can be marked as static
 
   namespace {
 // already in anonymous namespace
@@ -26,6 +26,9 @@ Example:
   // already declared as extern
   extern int v2;
 
+  void fn3(); // without function body in all declaration, maybe external 
linkage
+  void fn3();
+
 Options
 ---
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp
index 8dc739da3a2734..bf0d2c2513e562 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp
@@ -13,59 +13,59 @@ void func_template() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_template'
 // CHECK-FIXES: static void func_template() {}
 
-void func_cpp_inc();
+void func_cpp_inc() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc'
-// CHECK-FIXES: static void func_cpp_inc();
+// CHECK-FIXES: static void func_cpp_inc() {}
 
-int* func_cpp_inc_return_ptr();
+int* func_cpp_inc_return_ptr() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc_return_ptr'
-// CHECK-FIXES: static int* func_cpp_inc_return_ptr();
+// CHECK-FIXES: static int* func_cpp_inc_return_ptr() {}
 
-const int* func_cpp_inc_return_const_ptr();
+const int* func_cpp_inc_return_const_ptr() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: function 
'func_cpp_inc_return_const_ptr'
-// CHECK-FIXES: static const int* func_cpp_inc_return_const_ptr();
+

[clang] [clang][NFC]add static for internal linkage function (PR #117482)

2024-11-24 Thread via cfe-commits

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


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


[libunwind] [unwind] Make sure `__STDC_FORMAT_MACROS` is defined to ensure `PRId64` is available (PR #117491)

2024-11-24 Thread via cfe-commits

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


[libunwind] [unwind] Make sure `__STDC_FORMAT_MACROS` is defined to ensure `PRId6… (PR #117491)

2024-11-24 Thread via cfe-commits

https://github.com/Zentrik created 
https://github.com/llvm/llvm-project/pull/117491

…4` is available

See https://github.com/llvm/llvm-project/pull/102980 for further details.

>From 65a74d7dd7ef066430f2cf327d0a9ac5aa3adbe9 Mon Sep 17 00:00:00 2001
From: Zentrik 
Date: Sun, 24 Nov 2024 14:44:17 +
Subject: [PATCH] [unwind] Make sure `__STDC_FORMAT_MACROS` is defined to
 ensure `PRId64` is available

See https://github.com/llvm/llvm-project/pull/102980 for further details.
---
 libunwind/src/DwarfParser.hpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 7e85025dd054d5..54357f56494330 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -12,6 +12,10 @@
 #ifndef __DWARF_PARSER_HPP__
 #define __DWARF_PARSER_HPP__
 
+#ifndef __STDC_FORMAT_MACROS
+// Ensure PRId64 macro is available
+#define __STDC_FORMAT_MACROS 1
+#endif
 #include 
 #include 
 #include 

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


[libunwind] [unwind] Make sure `__STDC_FORMAT_MACROS` is defined to ensure `PRId6… (PR #117491)

2024-11-24 Thread via cfe-commits

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


[libunwind] [libunwind] Make sure `__STDC_FORMAT_MACROS` is defined to ensure `PRId64` is available (PR #117491)

2024-11-24 Thread via cfe-commits

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


[clang] [clang] constexpr built-in elementwise popcount function. (PR #117473)

2024-11-24 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon commented:

`__builtin_elementwise_popcount` can be used with a scalar value - please test 
that as well

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


[clang] [clang] constexpr built-in elementwise popcount function. (PR #117473)

2024-11-24 Thread Simon Pilgrim via cfe-commits

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


[clang] [clang] constexpr built-in elementwise popcount function. (PR #117473)

2024-11-24 Thread Simon Pilgrim via cfe-commits


@@ -797,3 +797,8 @@ 
static_assert(__builtin_reduce_xor((vector4int){(int)0x, (int)0x
 static_assert(__builtin_reduce_xor((vector4long){(long 
long)0xL, (long long)0xL, (long 
long)0xL, (long long)0xL}) == (long 
long)0xL);
 static_assert(__builtin_reduce_xor((vector4uint){0xU, 0xU, 
0xU, 0xU}) == 0xU);
 static_assert(__builtin_reduce_xor((vector4ulong){0xUL, 
0xUL, 0xUL, 0xUL}) == 
0xUL);
+
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4int){1,
 2, 3, 4})) == 5);
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4int){0,
 0xF0F0, ~0, ~0xF0F0})) == 16 * sizeof(int));
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4long){1L,
 2L, 3L, 4L})) == 5L);
+static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4long){0L,
 0xF0F0L, ~0L, ~0xF0F0L})) == 16 * sizeof(long long));

RKSimon wrote:

please can you add unsigned test coverage as well

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


[libunwind] [libunwind] Make sure `__STDC_FORMAT_MACROS` is defined to ensure `PRId64` is available (PR #117491)

2024-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: None (Zentrik)


Changes

See https://github.com/llvm/llvm-project/pull/102980 for further details.

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


1 Files Affected:

- (modified) libunwind/src/DwarfParser.hpp (+4) 


``diff
diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 7e85025dd054d5..54357f56494330 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -12,6 +12,10 @@
 #ifndef __DWARF_PARSER_HPP__
 #define __DWARF_PARSER_HPP__
 
+#ifndef __STDC_FORMAT_MACROS
+// Ensure PRId64 macro is available
+#define __STDC_FORMAT_MACROS 1
+#endif
 #include 
 #include 
 #include 

``




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


[clang] [Clang-REPL] Fix crash during `__run_exit_handlers` with dynamic libraries. (PR #117475)

2024-11-24 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

It is worth adding a test here. 

https://github.com/llvm/llvm-project/pull/117475
___
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] fix release note order (PR #117484)

2024-11-24 Thread Congcong Cai via cfe-commits

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

None

>From 35938c24d9adf12ef6276dd3c7fb25ab1f40c33c Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 24 Nov 2024 21:46:13 +0800
Subject: [PATCH] [clang-tidy][NFC] fix release note order

---
 clang-tools-extra/docs/ReleaseNotes.rst | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index dcfe68e020fc93..8c9fedf4b4406c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -228,6 +228,10 @@ Changes in existing checks
   ` check to avoid
   false positive for C++23 deducing this.
 
+- Improved :doc:`misc-use-internal-linkage
+  ` check to insert ``static`` 
keyword
+  before type qualifiers such as ``const`` and ``volatile``.
+
 - Improved :doc:`modernize-avoid-c-arrays
   ` check to suggest using 
   ``std::span`` as a replacement for parameters of incomplete C array type in
@@ -237,10 +241,6 @@ Changes in existing checks
   ` check to fix false positive when
   using loop variable in initializer of lambda capture.
 
-- Improved :doc:`misc-use-internal-linkage
-  ` check to insert ``static`` 
keyword
-  before type qualifiers such as ``const`` and ``volatile``.
-
 - Improved :doc:`modernize-min-max-use-initializer-list
   ` check by fixing
   a false positive when only an implicit conversion happened inside an

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


[clang-tools-extra] 0c21ed4 - [clang-tidy][NFC] fix release note order (#117484)

2024-11-24 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-11-24T21:46:39+08:00
New Revision: 0c21ed48f40b2a6e3aa7e5d1873cf2455e847786

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

LOG: [clang-tidy][NFC] fix release note order (#117484)

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index dcfe68e020fc93..8c9fedf4b4406c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -228,6 +228,10 @@ Changes in existing checks
   ` check to avoid
   false positive for C++23 deducing this.
 
+- Improved :doc:`misc-use-internal-linkage
+  ` check to insert ``static`` 
keyword
+  before type qualifiers such as ``const`` and ``volatile``.
+
 - Improved :doc:`modernize-avoid-c-arrays
   ` check to suggest using 
   ``std::span`` as a replacement for parameters of incomplete C array type in
@@ -237,10 +241,6 @@ Changes in existing checks
   ` check to fix false positive when
   using loop variable in initializer of lambda capture.
 
-- Improved :doc:`misc-use-internal-linkage
-  ` check to insert ``static`` 
keyword
-  before type qualifiers such as ``const`` and ``volatile``.
-
 - Improved :doc:`modernize-min-max-use-initializer-list
   ` check by fixing
   a false positive when only an implicit conversion happened inside an



___
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] fix release note order (PR #117484)

2024-11-24 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/117484.diff


1 Files Affected:

- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4-4) 


``diff
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index dcfe68e020fc93..8c9fedf4b4406c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -228,6 +228,10 @@ Changes in existing checks
   ` check to avoid
   false positive for C++23 deducing this.
 
+- Improved :doc:`misc-use-internal-linkage
+  ` check to insert ``static`` 
keyword
+  before type qualifiers such as ``const`` and ``volatile``.
+
 - Improved :doc:`modernize-avoid-c-arrays
   ` check to suggest using 
   ``std::span`` as a replacement for parameters of incomplete C array type in
@@ -237,10 +241,6 @@ Changes in existing checks
   ` check to fix false positive when
   using loop variable in initializer of lambda capture.
 
-- Improved :doc:`misc-use-internal-linkage
-  ` check to insert ``static`` 
keyword
-  before type qualifiers such as ``const`` and ``volatile``.
-
 - Improved :doc:`modernize-min-max-use-initializer-list
   ` check by fixing
   a false positive when only an implicit conversion happened inside an

``




https://github.com/llvm/llvm-project/pull/117484
___
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] fix release note order (PR #117484)

2024-11-24 Thread Congcong Cai via cfe-commits

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


[clang] [Clang] [Sema] Reject non-power-of-2 `_BitInt` matrix element types (PR #117487)

2024-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

Essentially, this pr makes this ill-formed:
```c++
using mat4 = _BitInt(12) [[clang::matrix_type(3, 3)]];
```

This matches preexisting behaviour for vector types (e.g. `ext_vector_type`), 
and given that LLVM IR intrinsics for matrices also take vector types, it seems 
like a sensible thing to do.

This is currently especially problematic since we sometimes lower matrix types 
to LLVM array types instead, and while e.g. `[4 x i32]` and `<4 x i32>` 
*probably* have the same similar memory layout (though I don’t think it’s sound 
to rely on that either, see #117486), `[4 x i12]` and `<4 x i12>` 
definitely don’t.

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2-2) 
- (modified) clang/lib/Sema/SemaType.cpp (+23-18) 
- (modified) clang/test/SemaCXX/matrix-type.cpp (+11-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bd06fadfdc984..1c0e4043bbe276 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -371,6 +371,9 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_and`` function can now be used in constant expressions.
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 
+- Clang now rejects ``_BitInt`` matrix element types if the bit width is less 
than ``CHAR_WIDTH`` or
+  not a power of two, matching preexisting behaviour for vector types.
+
 New Compiler Flags
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eb05a6a77978af..f049e72a6b8694 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3233,8 +3233,8 @@ def err_attribute_too_few_arguments : Error<
   "%0 attribute takes at least %1 argument%s1">;
 def err_attribute_invalid_vector_type : Error<"invalid vector element type 
%0">;
 def err_attribute_invalid_bitint_vector_type : Error<
-  "'_BitInt' vector element width must be %select{a power of 2|"
-  "at least as wide as 'CHAR_BIT'}0">;
+  "'_BitInt' %select{vector|matrix}0 element width must be %select{a power of 
2|"
+  "at least as wide as 'CHAR_BIT'}1">;
 def err_attribute_invalid_matrix_type : Error<"invalid matrix element type 
%0">;
 def err_attribute_bad_neon_vector_size : Error<
   "Neon vector size must be 64 or 128 bits">;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index f32edc5ac06440..06b779f5ef3aa2 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2312,6 +2312,18 @@ QualType Sema::BuildArrayType(QualType T, 
ArraySizeModifier ASM,
   return T;
 }
 
+bool CheckBitIntElementType(Sema &S, SourceLocation AttrLoc,
+const BitIntType *BIT, bool ForMatrixType = false) 
{
+  // Only support _BitInt elements with byte-sized power of 2 NumBits.
+  unsigned NumBits = BIT->getNumBits();
+  if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
+S.Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
+<< ForMatrixType << (NumBits < 8);
+return true;
+  }
+  return false;
+}
+
 QualType Sema::BuildVectorType(QualType CurType, Expr *SizeExpr,
SourceLocation AttrLoc) {
   // The base type must be integer (not Boolean or enumeration) or float, and
@@ -2324,15 +2336,10 @@ QualType Sema::BuildVectorType(QualType CurType, Expr 
*SizeExpr,
 Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << CurType;
 return QualType();
   }
-  // Only support _BitInt elements with byte-sized power of 2 NumBits.
-  if (const auto *BIT = CurType->getAs()) {
-unsigned NumBits = BIT->getNumBits();
-if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
-  Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
-  << (NumBits < 8);
-  return QualType();
-}
-  }
+
+  if (const auto *BIT = CurType->getAs();
+  BIT && CheckBitIntElementType(*this, AttrLoc, BIT))
+return QualType();
 
   if (SizeExpr->isTypeDependent() || SizeExpr->isValueDependent())
 return Context.getDependentVectorType(CurType, SizeExpr, AttrLoc,
@@ -2402,15 +2409,9 @@ QualType Sema::BuildExtVectorType(QualType T, Expr 
*ArraySize,
 return QualType();
   }
 
-  // Only support _BitInt elements with byte-sized power of 2 NumBits.
-  if (T->isBitIntType()) {
-unsigned NumBits = T->castAs()->getNumBits();
-if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
-  Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
-  << (NumBits < 8);
-  return QualType();
-}
-  }
+  if (const auto *BIT = T->getAs();
+  BIT && CheckBitIntElementType(*this, AttrLoc, BIT))
+return QualType();
 
   if (!Ar

[clang] [Clang] [Sema] Reject non-power-of-2 `_BitInt` matrix element types (PR #117487)

2024-11-24 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/117487

Essentially, this pr makes this ill-formed:
```c++
using mat4 = _BitInt(12) [[clang::matrix_type(3, 3)]];
```

This matches preexisting behaviour for vector types (e.g. `ext_vector_type`), 
and given that LLVM IR intrinsics for matrices also take vector types, it seems 
like a sensible thing to do.

This is currently especially problematic since we sometimes lower matrix types 
to LLVM array types instead, and while e.g. `[4 x i32]` and `<4 x i32>` 
*probably* have the same similar memory layout (though I don’t think it’s sound 
to rely on that either, see #117486), `[4 x i12]` and `<4 x i12>` definitely 
don’t.

>From a612c8f0a78dd1f29a4885f57efbdd4a9cca374e Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sun, 24 Nov 2024 14:36:41 +0100
Subject: [PATCH 1/2] [Clang] [Sema] Reject non-power-of-2 `_BitInt` matrix
 element types

---
 clang/docs/ReleaseNotes.rst   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/lib/Sema/SemaType.cpp   | 41 +++
 clang/test/SemaCXX/matrix-type.cpp| 10 +
 4 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bd06fadfdc984..1c0e4043bbe276 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -371,6 +371,9 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_and`` function can now be used in constant expressions.
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 
+- Clang now rejects ``_BitInt`` matrix element types if the bit width is less 
than ``CHAR_WIDTH`` or
+  not a power of two, matching preexisting behaviour for vector types.
+
 New Compiler Flags
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eb05a6a77978af..f049e72a6b8694 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3233,8 +3233,8 @@ def err_attribute_too_few_arguments : Error<
   "%0 attribute takes at least %1 argument%s1">;
 def err_attribute_invalid_vector_type : Error<"invalid vector element type 
%0">;
 def err_attribute_invalid_bitint_vector_type : Error<
-  "'_BitInt' vector element width must be %select{a power of 2|"
-  "at least as wide as 'CHAR_BIT'}0">;
+  "'_BitInt' %select{vector|matrix}0 element width must be %select{a power of 
2|"
+  "at least as wide as 'CHAR_BIT'}1">;
 def err_attribute_invalid_matrix_type : Error<"invalid matrix element type 
%0">;
 def err_attribute_bad_neon_vector_size : Error<
   "Neon vector size must be 64 or 128 bits">;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index f32edc5ac06440..06b779f5ef3aa2 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2312,6 +2312,18 @@ QualType Sema::BuildArrayType(QualType T, 
ArraySizeModifier ASM,
   return T;
 }
 
+bool CheckBitIntElementType(Sema &S, SourceLocation AttrLoc,
+const BitIntType *BIT, bool ForMatrixType = false) 
{
+  // Only support _BitInt elements with byte-sized power of 2 NumBits.
+  unsigned NumBits = BIT->getNumBits();
+  if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
+S.Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
+<< ForMatrixType << (NumBits < 8);
+return true;
+  }
+  return false;
+}
+
 QualType Sema::BuildVectorType(QualType CurType, Expr *SizeExpr,
SourceLocation AttrLoc) {
   // The base type must be integer (not Boolean or enumeration) or float, and
@@ -2324,15 +2336,10 @@ QualType Sema::BuildVectorType(QualType CurType, Expr 
*SizeExpr,
 Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << CurType;
 return QualType();
   }
-  // Only support _BitInt elements with byte-sized power of 2 NumBits.
-  if (const auto *BIT = CurType->getAs()) {
-unsigned NumBits = BIT->getNumBits();
-if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
-  Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
-  << (NumBits < 8);
-  return QualType();
-}
-  }
+
+  if (const auto *BIT = CurType->getAs();
+  BIT && CheckBitIntElementType(*this, AttrLoc, BIT))
+return QualType();
 
   if (SizeExpr->isTypeDependent() || SizeExpr->isValueDependent())
 return Context.getDependentVectorType(CurType, SizeExpr, AttrLoc,
@@ -2402,15 +2409,9 @@ QualType Sema::BuildExtVectorType(QualType T, Expr 
*ArraySize,
 return QualType();
   }
 
-  // Only support _BitInt elements with byte-sized power of 2 NumBits.
-  if (T->isBitIntType()) {
-unsigned NumBits = T->castAs()->getNumBits();
-if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
-  Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
-  <

[clang-tools-extra] [clang-tidy] Fix false positive in cppcoreguidelines-avoid-const-or-ref-data-members when detecting templated classes with inheritance (PR #115180)

2024-11-24 Thread Carlos Galvez via cfe-commits

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

LGTM!

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


[clang] [clang-format] Fix an assertion failure in RemoveSemicolon (PR #117472)

2024-11-24 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/117472

Fixes #117290.

>From 9a2a93fbb50163e593f6b48a279bea9f70424c06 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 24 Nov 2024 00:43:29 -0800
Subject: [PATCH] [clang-format] Fix an assertion failure in RemoveSemicolon

Fixes #117290.
---
 clang/lib/Format/Format.cpp   | 8 +---
 clang/unittests/Format/FormatTest.cpp | 7 +++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 0cf4cdbeab31f3..0c3c4de6f00e1d 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2325,7 +2325,7 @@ class SemiRemover : public TokenAnalyzer {
 private:
   void removeSemi(TokenAnnotator &Annotator,
   SmallVectorImpl &Lines,
-  tooling::Replacements &Result) {
+  tooling::Replacements &Result, bool Children = false) {
 auto PrecededByFunctionRBrace = [](const FormatToken &Tok) {
   const auto *Prev = Tok.Previous;
   if (!Prev || Prev->isNot(tok::r_brace))
@@ -2337,10 +2337,12 @@ class SemiRemover : public TokenAnalyzer {
 const auto End = Lines.end();
 for (auto I = Lines.begin(); I != End; ++I) {
   const auto Line = *I;
-  removeSemi(Annotator, Line->Children, Result);
+  if (!Line->Children.empty())
+removeSemi(Annotator, Line->Children, Result, /*Children=*/true);
   if (!Line->Affected)
 continue;
-  Annotator.calculateFormattingInformation(*Line);
+  if (!Children)
+Annotator.calculateFormattingInformation(*Line);
   const auto NextLine = I + 1 == End ? nullptr : I[1];
   for (auto Token = Line->First; Token && !Token->Finalized;
Token = Token->Next) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 250e51b5421664..63d8dc2486e45f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -27386,6 +27386,13 @@ TEST_F(FormatTest, RemoveSemicolon) {
Style);
 #endif
 
+  verifyFormat("auto sgf = [] {\n"
+   "  ogl = {\n"
+   "  a, b, c, d, e,\n"
+   "  };\n"
+   "};",
+   Style);
+
   Style.TypenameMacros.push_back("STRUCT");
   verifyFormat("STRUCT(T, B) { int i; };", Style);
 }

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


  1   2   >