[clang] [MS][clang] Add support for vector deleting destructors (PR #126240)

2025-03-19 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> I've uploaded a stand-alone from-source reproducer of the run time crash 
> here: https://crbug.com/402425841#comment10

Reproduced. Seems limited to 32-bit build (only reproducible with -m32 option) 
and lld linker. Fine with either standard linker or 64-bit build.

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


[clang] [Clang][Diagnostics] Update select uses in DiagnosticXKinds.td to use enum_select (PR #130868)

2025-03-19 Thread Ayokunle Amodu via cfe-commits

https://github.com/ayokunle321 updated 
https://github.com/llvm/llvm-project/pull/130868

>From dfc517be06531af965dc51b09a0f1ae7965e3e20 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle...@users.noreply.github.com>
Date: Fri, 14 Mar 2025 15:13:05 -0600
Subject: [PATCH 1/4] revert changes in ASTKinds.td file

---
 clang/include/clang/Basic/DiagnosticASTKinds.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index ac53778339a20..9faa8eec56b40 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -1041,4 +1041,4 @@ def warn_unpacked_field
 def warn_unaligned_access : Warning<
   "field %1 within %0 is less aligned than %2 and is usually due to %0 being "
   "packed, which can lead to unaligned accesses">, InGroup, 
DefaultIgnore;
-}
+}
\ No newline at end of file

>From 9e08ddfb5931d06fa0e725ae7dea8de781489ab7 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle...@users.noreply.github.com>
Date: Wed, 19 Mar 2025 00:12:11 -0600
Subject: [PATCH 2/4] refactor select in note_constexpr_invalid_cast

---
 clang/include/clang/Basic/DiagnosticASTKinds.td |  5 +++--
 clang/lib/AST/ByteCode/Interp.h |  6 +++---
 clang/lib/AST/ExprConstant.cpp  | 16 
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 9faa8eec56b40..7167f95e88296 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -11,8 +11,9 @@ let Component = "AST" in {
 // Constant expression diagnostics. These (and their users) belong in Sema.
 def note_expr_divide_by_zero : Note<"division by zero">;
 def note_constexpr_invalid_cast : Note<
-  "%select{reinterpret_cast|dynamic_cast|%select{this conversion|cast that"
-  " performs the conversions of a reinterpret_cast}1|cast from %1}0"
+  
"%enum_select{%Reinterpret{reinterpret_cast}|%Dynamic{dynamic_cast}|"
+  "%ThisCastOrReinterpret{%select{this conversion|cast that performs the 
conversions "
+  "of a reinterpret_cast}1}|%CastFrom{cast from %1}}0"
   " is not allowed in a constant expression"
   "%select{| in C++ standards before C++20||}0">;
 def note_constexpr_invalid_void_star_cast : Note<
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index f2ddeac99cd7e..8956a69c7124c 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2366,12 +2366,12 @@ static inline bool PtrPtrCast(InterpState &S, CodePtr 
OpPC, bool SrcIsVoidPtr) {
 } else if (!S.getLangOpts().CPlusPlus26) {
   const SourceInfo &E = S.Current->getSource(OpPC);
   S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-  << 3 << "'void *'" << S.Current->getRange(OpPC);
+  << diag::CastKind::CastFrom << "'void *'" << 
S.Current->getRange(OpPC);
 }
   } else {
 const SourceInfo &E = S.Current->getSource(OpPC);
 S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-<< 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
+<< diag::CastKind::ThisCastOrReinterpret << S.getLangOpts().CPlusPlus 
<< S.Current->getRange(OpPC);
   }
 
   return true;
@@ -2736,7 +2736,7 @@ inline bool GetIntPtr(InterpState &S, CodePtr OpPC, const 
Descriptor *Desc) {
 
   if (Desc)
 S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
-<< 2 << S.getLangOpts().CPlusPlus;
+<< diag::CastKind::ThisCastOrReinterpret << S.getLangOpts().CPlusPlus;
 
   S.Stk.push(static_cast(IntVal), Desc);
   return true;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f8e8aaddbfdbd..9eb8c6717900b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8103,12 +8103,12 @@ class ExprEvaluatorBase
   }
 
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) {
-CCEDiag(E, diag::note_constexpr_invalid_cast) << 0;
+CCEDiag(E, diag::note_constexpr_invalid_cast) << 
diag::CastKind::Reinterpret;
 return static_cast(this)->VisitCastExpr(E);
   }
   bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E) {
 if (!Info.Ctx.getLangOpts().CPlusPlus20)
-  CCEDiag(E, diag::note_constexpr_invalid_cast) << 1;
+  CCEDiag(E, diag::note_constexpr_invalid_cast) << diag::CastKind::Dynamic;
 return static_cast(this)->VisitCastExpr(E);
   }
   bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E) {
@@ -8833,7 +8833,7 @@ class LValueExprEvaluator
 
 case CK_LValueBitCast:
   this->CCEDiag(E, diag::note_constexpr_invalid_cast)
-  << 2 << Info.Ctx.getLangOpts().CPlusPlus;
+  << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus;
   if (!Visit(E->getSubExpr()))
 return 

[clang] [Clang] Increase the default expression nesting limit (PR #132021)

2025-03-19 Thread Erich Keane via cfe-commits

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


[clang] [Clang][Diagnostics] Update select uses in DiagnosticXKinds.td to use enum_select (PR #130868)

2025-03-19 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

This one looks like a good candiate and the application is much clearer.

There are 2 comments (1 i think the name could be clearer, and the 2nd, we 
still need a newline at the end fo the file).

Else, let me know how you want to proceed.  We can rename this pull request to 
just rename this ONE (change the PR subject & message) and merge it, or we can 
wait for you to do quite a few at a time, your choice.

https://github.com/llvm/llvm-project/pull/130868
___
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 new check: modernize-use-scoped-lock (PR #126434)

2025-03-19 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,342 @@
+//===--- UseScopedLockCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseScopedLockCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+
+bool isLockGuard(const QualType &Type) {
+  if (const auto *Record = Type->getAs())
+if (const RecordDecl *Decl = Record->getDecl())
+  return Decl->getName() == "lock_guard" && Decl->isInStdNamespace();
+
+  if (const auto *TemplateSpecType = Type->getAs())
+if (const TemplateDecl *Decl =
+TemplateSpecType->getTemplateName().getAsTemplateDecl())
+  return Decl->getName() == "lock_guard" && Decl->isInStdNamespace();
+
+  return false;
+}
+
+llvm::SmallVector getLockGuardsFromDecl(const DeclStmt *DS) {
+  llvm::SmallVector LockGuards;
+
+  for (const Decl *Decl : DS->decls()) {
+if (const auto *VD = dyn_cast(Decl)) {
+  const QualType Type =
+  VD->getType().getUnqualifiedType().getCanonicalType();
+  if (isLockGuard(Type))
+LockGuards.push_back(VD);
+}
+  }
+
+  return LockGuards;
+}
+
+// Scans through the statements in a block and groups consecutive
+// 'std::lock_guard' variable declarations together.
+llvm::SmallVector>
+findLocksInCompoundStmt(const CompoundStmt *Block,
+const ast_matchers::MatchFinder::MatchResult &Result) {
+  // store groups of consecutive 'std::lock_guard' declarations
+  llvm::SmallVector> LockGuardGroups;
+  llvm::SmallVector CurrentLockGuardGroup;
+
+  auto AddAndClearCurrentGroup = [&]() {
+if (!CurrentLockGuardGroup.empty()) {
+  LockGuardGroups.push_back(CurrentLockGuardGroup);
+  CurrentLockGuardGroup.clear();
+}
+  };
+
+  for (const Stmt *Stmt : Block->body()) {
+if (const auto *DS = dyn_cast(Stmt)) {
+  llvm::SmallVector LockGuards = 
getLockGuardsFromDecl(DS);
+
+  if (!LockGuards.empty()) {
+CurrentLockGuardGroup.insert(
+CurrentLockGuardGroup.end(),
+std::make_move_iterator(LockGuards.begin()),
+std::make_move_iterator(LockGuards.end()));
+continue;
+  }
+}
+AddAndClearCurrentGroup();
+  }
+
+  AddAndClearCurrentGroup();
+
+  return LockGuardGroups;
+}
+
+TemplateSpecializationTypeLoc
+getTemplateLockGuardTypeLoc(const TypeSourceInfo *SourceInfo) {
+  const TypeLoc Loc = SourceInfo->getTypeLoc();
+
+  const auto ElaboratedLoc = Loc.getAs();
+  if (!ElaboratedLoc)
+return {};
+
+  return 
ElaboratedLoc.getNamedTypeLoc().getAs();
+}
+
+// Find the exact source range of the 'lock_guard' token
+SourceRange getLockGuardRange(const TypeSourceInfo *SourceInfo) {
+  const TypeLoc LockGuardTypeLoc = SourceInfo->getTypeLoc();
+
+  return SourceRange(LockGuardTypeLoc.getBeginLoc(),
+ LockGuardTypeLoc.getEndLoc());
+}
+
+// Find the exact source range of the 'lock_guard' name token
+SourceRange getLockGuardNameRange(const TypeSourceInfo *SourceInfo) {
+  const TemplateSpecializationTypeLoc TemplateLoc =
+  getTemplateLockGuardTypeLoc(SourceInfo);
+  if (!TemplateLoc)
+return {};
+
+  return SourceRange(TemplateLoc.getTemplateNameLoc(),
+ TemplateLoc.getLAngleLoc().getLocWithOffset(-1));
+}
+
+AST_MATCHER_P(CompoundStmt, hasMultiple, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  size_t Count = 0;
+
+  for (const Stmt *Stmt : Node.body())
+if (InnerMatcher.matches(*Stmt, Finder, Builder))

PiotrZSL wrote:

i'm not sure if this will work correctly, if new Builder shouldn't be 
constructed for every match, otherwise some binding could leak between matchers.

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


[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)

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

HerrCai0907 wrote:

> Main reason is simple, easy to modify check and add new check in subconfigs.

It is also support to add new check in subconfigs, to modify check is thing I 
did not implement yet. (There are FIXME in merge config part of code)
In theory, these two configurations are equivalent. I think flattening the 
configuration items will only reduce readability, because we cannot define a 
YAML schema for it.

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


[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)

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

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


[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)

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

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


[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)

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

HerrCai0907 wrote:

> I do not see need for errors, always someone can use warnings as errors.

Agree. I will remove it if no one against it.

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


[clang-tools-extra] [clang-tidy][C++20] Add support for aggregate types within modernize-use-emplace (PR #131969)

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


@@ -202,19 +202,36 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   // overloaded functions and template names.
   auto SoughtConstructExpr =
   cxxConstructExpr(
-  unless(anyOf(IsCtorOfSmartPtr, HasInitList, BitFieldAsArgument,
-   InitializerListAsArgument, NewExprAsArgument,
-   ConstructingDerived, IsPrivateOrProtectedCtor)))
+  unless(anyOf(hasDeclaration(IsCtorOfSmartPtr), HasInitList,
+   hasAnyArgument(BitFieldAsArgument),
+   hasAnyArgument(InitializerListAsArgument),
+   hasAnyArgument(NewExprAsArgument), ConstructingDerived,
+   IsPrivateOrProtectedCtor)))
   .bind("ctor");
-  auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
+
+  auto IsPrimitiveType = hasType(builtinType());
+
+  auto AggregateInitExpr =
+  getLangOpts().CPlusPlus20
+  ? initListExpr(unless(anyOf(HasInitList, has(IsCtorOfSmartPtr),
+  has(BitFieldAsArgument),
+  has(InitializerListAsArgument),
+  has(NewExprAsArgument), 
IsPrimitiveType)))
+.bind("agg_init")
+  : unless(anything());
+
+  auto HasConstructExpr =
+  has(ignoringImplicit(anyOf(SoughtConstructExpr, AggregateInitExpr)));
 
   // allow for T{} to be replaced, even if no CTOR is declared
   auto HasConstructInitListExpr = has(initListExpr(
-  initCountLeq(1), anyOf(allOf(has(SoughtConstructExpr),
-   has(cxxConstructExpr(argumentCountIs(0,
- has(cxxBindTemporaryExpr(
- has(SoughtConstructExpr),
- 
has(cxxConstructExpr(argumentCountIs(0;
+  initCountLeq(1),
+  anyOf(allOf(has(SoughtConstructExpr),
+  has(cxxConstructExpr(argumentCountIs(0,
+has(cxxBindTemporaryExpr(has(SoughtConstructExpr),
+ has(cxxConstructExpr(argumentCountIs(0)))
+

vbvictor wrote:

unintended line?

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


[clang] [clang-format] Recognize wait fork in Verilog (PR #132042)

2025-03-19 Thread via cfe-commits

https://github.com/sstwcw created 
https://github.com/llvm/llvm-project/pull/132042

before

```Verilog
wait fork
  ;
  wait fork
;
wait fork
  ;
```

after

```Verilog
wait fork;
wait fork;
wait fork;
```

The `wait fork` statement should not start a block.  Previously the formatter 
treated the `fork` part as the start of a new block.  Now the problem is fixed.

>From 15cecc7e1b4845b077b8923f08825b1828aa1a73 Mon Sep 17 00:00:00 2001
From: sstwcw 
Date: Wed, 19 Mar 2025 14:12:59 +
Subject: [PATCH] [clang-format] Recognize wait fork in Verilog

before

```Verilog
wait fork
  ;
  wait fork
;
wait fork
  ;
```

after

```Verilog
wait fork;
wait fork;
wait fork;
```

The `wait fork` statement should not start a block.  Previously the
formatter treated the `fork` part as the start of a new block.  Now the
problem is fixed.
---
 clang/lib/Format/FormatToken.h   | 110 ---
 clang/unittests/Format/FormatTestVerilog.cpp |   2 +
 2 files changed, 48 insertions(+), 64 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 3808872d227a9..90c85b1a4e3d6 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -1243,6 +1243,7 @@ struct AdditionalKeywords {
 kw_unique0 = &IdentTable.get("unique0");
 kw_uwire = &IdentTable.get("uwire");
 kw_vectored = &IdentTable.get("vectored");
+kw_wait = &IdentTable.get("wait");
 kw_wand = &IdentTable.get("wand");
 kw_weak0 = &IdentTable.get("weak0");
 kw_weak1 = &IdentTable.get("weak1");
@@ -1299,70 +1300,49 @@ struct AdditionalKeywords {
 // treatment like `showcancelled` or they should be treated as identifiers
 // like `int` and `logic`.
 VerilogExtraKeywords = std::unordered_set(
-{kw_always,   kw_always_comb,
- kw_always_ff,kw_always_latch,
- kw_assert,   kw_assign,
- kw_assume,   kw_automatic,
- kw_before,   kw_begin,
- kw_bins, kw_binsof,
- kw_casex,kw_casez,
- kw_celldefine,   kw_checker,
- kw_clocking, kw_constraint,
- kw_cover,kw_covergroup,
- kw_coverpoint,   kw_disable,
- kw_dist, kw_edge,
- kw_end,  kw_endcase,
- kw_endchecker,   kw_endclass,
- kw_endclocking,  kw_endfunction,
- kw_endgenerate,  kw_endgroup,
- kw_endinterface, kw_endmodule,
- kw_endpackage,   kw_endprimitive,
- kw_endprogram,   kw_endproperty,
- kw_endsequence,  kw_endspecify,
- kw_endtable, kw_endtask,
- kw_extends,  kw_final,
- kw_foreach,  kw_forever,
- kw_fork, kw_function,
- kw_generate, kw_highz0,
- kw_highz1,   kw_iff,
- kw_ifnone,   kw_ignore_bins,
- kw_illegal_bins, kw_implements,
- kw_import,   kw_initial,
- kw_inout,kw_input,
- kw_inside,   kw_interconnect,
- kw_interface,kw_intersect,
- kw_join, kw_join_any,
- kw_join_none,kw_large,
- kw_let,  kw_local,
- kw_localparam,   kw_macromodule,
- kw_matches,  kw_medium,
- kw_negedge,  kw_output,
- kw_package,  kw_packed,
- kw_parameter,kw_posedge,
- kw_primitive,kw_priority,
- kw_program,  kw_property,
- kw_pull0,kw_pull1,
- kw_pure, kw_rand,
- kw_randc,kw_randcase,
- kw_randsequence, kw_ref,
- kw_repeat,   kw_sample,
- kw_scalared, kw_sequence,
- kw_small,kw_soft,
- kw_solve,kw_specify,
- kw_specparam,kw_strong0,
- kw_strong1,  kw_supply0,
- kw_supply1,  kw_table,
- kw_tagged,   kw_task,
- kw_tri,  kw_tri0,
- kw_tri1, kw_triand,
- kw_trior,kw_trireg,
- kw_unique,   kw_unique0,
- kw_uwire,kw_var,
- kw_vectored, kw_wand,
- kw_weak0,kw_weak1,
- kw_wildcard, kw_wire,
- kw_with, kw_wor,
- kw_verilogHash,  kw_verilogHashHash});
+{kw_always,   kw_always_comb,  kw_always_ff,
+ kw_always_latch, kw_assert,   kw_assign,
+ kw_assume,   kw_automatic,kw_before,
+ kw_begin,kw_bins, kw_binsof,
+ kw_casex,kw_casez,kw_celldefine,
+ kw_checker,  kw_clocking, kw_constraint,
+ kw_cover,kw_covergroup,   kw_coverpoint,
+ kw_disable,  kw_dist, kw_edge,
+ kw_end,  kw_endcase,  kw_endchecker,
+ kw_endclass, kw_endclocking,  kw_endfunction,
+ kw_endgenerate,  kw_endgroup, kw_endinterface,
+ kw_endmodule,kw_endpackage,   kw_endprimitive,
+   

[clang] e9988c3 - [clang][Sema] Propagate qualifiers during derived-to-base conversion

2025-03-19 Thread Antonio Frighetto via cfe-commits

Author: Antonio Frighetto
Date: 2025-03-19T09:04:29+01:00
New Revision: e9988c36ed788b2d1ce00b028bed51169bd8b02c

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

LOG: [clang][Sema] Propagate qualifiers during derived-to-base conversion

When accessing a field member through a derived-to-base conversion,
ensure qualifiers are propagated to the base class subobject.

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

Added: 
clang/test/SemaCXX/derived-to-base-propagate-qualifiers.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenCXX/derived-to-base.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ce4336acb806a..1c0504d831e3f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -340,6 +340,8 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure affecting code that uses C++23 "deducing this". 
(#GH130272)
 - Clang now properly instantiates destructors for initialized members within 
non-delegating constructors. (#GH93251)
 - Correctly diagnoses if unresolved using declarations shadows template 
paramters (#GH129411)
+- Clang was previously coalescing volatile writes to members of volatile base 
class subobjects.
+  The issue has been addressed by propagating qualifiers during 
derived-to-base conversions in the AST. (#GH127824)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3ff372bdc9d0c..a03acb5fbd273 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3113,8 +3113,15 @@ Sema::PerformObjectMemberConversion(Expr *From,
/*IgnoreAccess=*/true))
 return ExprError();
 
-  return ImpCastExprToType(From, DestType, CK_UncheckedDerivedToBase,
-   VK, &BasePath);
+  // Propagate qualifiers to base subobjects as per:
+  // C++ [basic.type.qualifier]p1.2:
+  //   A volatile object is [...] a subobject of a volatile object.
+  Qualifiers FromTypeQuals = FromType.getQualifiers();
+  FromTypeQuals.setAddressSpace(DestType.getAddressSpace());
+  DestType = Context.getQualifiedType(DestType, FromTypeQuals);
+
+  return ImpCastExprToType(From, DestType, CK_UncheckedDerivedToBase, VK,
+   &BasePath);
 }
 
 bool Sema::UseArgumentDependentLookup(const CXXScopeSpec &SS,

diff  --git a/clang/test/CodeGenCXX/derived-to-base.cpp 
b/clang/test/CodeGenCXX/derived-to-base.cpp
index c8dbd5bf5cb05..c09a12b728bbb 100644
--- a/clang/test/CodeGenCXX/derived-to-base.cpp
+++ b/clang/test/CodeGenCXX/derived-to-base.cpp
@@ -46,4 +46,29 @@ namespace test3 {
   }
 }
 
+// Ensure volatile is preserved during derived-to-base conversion. 
+namespace PR127683 {
+
+struct Base {
+  int Val;
+};
+  
+struct Derived : Base { };
+  
+volatile Derived Obj;
+
+// CHECK-LABEL: define void @_ZN8PR12768319test_volatile_storeEv()
+// CHECK: store volatile i32 0, ptr @_ZN8PR1276833ObjE, align 4
+void test_volatile_store() {
+  Obj.Val = 0;
+}
+
+// CHECK-LABEL: define void @_ZN8PR12768318test_volatile_loadEv()
+// CHECK: %0 = load volatile i32, ptr @_ZN8PR1276833ObjE, align 4
+void test_volatile_load() {
+  [[maybe_unused]] int Val = Obj.Val;
+}
+
+}
+
 // CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }

diff  --git a/clang/test/SemaCXX/derived-to-base-propagate-qualifiers.cpp 
b/clang/test/SemaCXX/derived-to-base-propagate-qualifiers.cpp
new file mode 100644
index 0..8a3b944ab1cb6
--- /dev/null
+++ b/clang/test/SemaCXX/derived-to-base-propagate-qualifiers.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-dump -verify %s | FileCheck %s
+
+// Ensure qualifiers are preserved during derived-to-base conversion. 
+namespace PR127683 {
+
+struct Base {
+  int Val;
+};
+
+struct Derived : Base { };
+
+// Value-initialize base class subobjects with type qualifiers.
+volatile Derived VObj;
+const Derived CObj{}; // expected-note{{variable 'CObj' declared const here}}
+const volatile Derived CVObj{}; // expected-note{{variable 'CVObj' declared 
const here}}
+__attribute__((address_space(1))) Derived AddrSpaceObj{};
+
+void test_store() {
+  // CHECK: `-ImplicitCastExpr {{.*}} 'volatile PR127683::Base' lvalue 

+  VObj.Val = 0;
+
+  // CHECK: `-ImplicitCastExpr {{.*}} 'const PR127683::Base' lvalue 

+  CObj.Val = 1; // expected-error {{cannot assign to variable 'CObj' with 
const-qualified type 'const Derived'}}
+
+  // CHECK: `-ImplicitCastExpr {{.*}} 'const volatile PR127683::Base' lvalue 

+  CVObj.Val = 1; // expected-error {{cannot assign to variable 'CVObj' with 
const-qualified type 'const volatile Derived'}}
+
+  // CHECK: `-ImplicitCas

[clang] [clang-format] Recognize wait fork in Verilog (PR #132042)

2025-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (sstwcw)


Changes

before

```Verilog
wait fork
  ;
  wait fork
;
wait fork
  ;
```

after

```Verilog
wait fork;
wait fork;
wait fork;
```

The `wait fork` statement should not start a block.  Previously the formatter 
treated the `fork` part as the start of a new block.  Now the problem is fixed.

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


2 Files Affected:

- (modified) clang/lib/Format/FormatToken.h (+46-64) 
- (modified) clang/unittests/Format/FormatTestVerilog.cpp (+2) 


``diff
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 3808872d227a9..90c85b1a4e3d6 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -1243,6 +1243,7 @@ struct AdditionalKeywords {
 kw_unique0 = &IdentTable.get("unique0");
 kw_uwire = &IdentTable.get("uwire");
 kw_vectored = &IdentTable.get("vectored");
+kw_wait = &IdentTable.get("wait");
 kw_wand = &IdentTable.get("wand");
 kw_weak0 = &IdentTable.get("weak0");
 kw_weak1 = &IdentTable.get("weak1");
@@ -1299,70 +1300,49 @@ struct AdditionalKeywords {
 // treatment like `showcancelled` or they should be treated as identifiers
 // like `int` and `logic`.
 VerilogExtraKeywords = std::unordered_set(
-{kw_always,   kw_always_comb,
- kw_always_ff,kw_always_latch,
- kw_assert,   kw_assign,
- kw_assume,   kw_automatic,
- kw_before,   kw_begin,
- kw_bins, kw_binsof,
- kw_casex,kw_casez,
- kw_celldefine,   kw_checker,
- kw_clocking, kw_constraint,
- kw_cover,kw_covergroup,
- kw_coverpoint,   kw_disable,
- kw_dist, kw_edge,
- kw_end,  kw_endcase,
- kw_endchecker,   kw_endclass,
- kw_endclocking,  kw_endfunction,
- kw_endgenerate,  kw_endgroup,
- kw_endinterface, kw_endmodule,
- kw_endpackage,   kw_endprimitive,
- kw_endprogram,   kw_endproperty,
- kw_endsequence,  kw_endspecify,
- kw_endtable, kw_endtask,
- kw_extends,  kw_final,
- kw_foreach,  kw_forever,
- kw_fork, kw_function,
- kw_generate, kw_highz0,
- kw_highz1,   kw_iff,
- kw_ifnone,   kw_ignore_bins,
- kw_illegal_bins, kw_implements,
- kw_import,   kw_initial,
- kw_inout,kw_input,
- kw_inside,   kw_interconnect,
- kw_interface,kw_intersect,
- kw_join, kw_join_any,
- kw_join_none,kw_large,
- kw_let,  kw_local,
- kw_localparam,   kw_macromodule,
- kw_matches,  kw_medium,
- kw_negedge,  kw_output,
- kw_package,  kw_packed,
- kw_parameter,kw_posedge,
- kw_primitive,kw_priority,
- kw_program,  kw_property,
- kw_pull0,kw_pull1,
- kw_pure, kw_rand,
- kw_randc,kw_randcase,
- kw_randsequence, kw_ref,
- kw_repeat,   kw_sample,
- kw_scalared, kw_sequence,
- kw_small,kw_soft,
- kw_solve,kw_specify,
- kw_specparam,kw_strong0,
- kw_strong1,  kw_supply0,
- kw_supply1,  kw_table,
- kw_tagged,   kw_task,
- kw_tri,  kw_tri0,
- kw_tri1, kw_triand,
- kw_trior,kw_trireg,
- kw_unique,   kw_unique0,
- kw_uwire,kw_var,
- kw_vectored, kw_wand,
- kw_weak0,kw_weak1,
- kw_wildcard, kw_wire,
- kw_with, kw_wor,
- kw_verilogHash,  kw_verilogHashHash});
+{kw_always,   kw_always_comb,  kw_always_ff,
+ kw_always_latch, kw_assert,   kw_assign,
+ kw_assume,   kw_automatic,kw_before,
+ kw_begin,kw_bins, kw_binsof,
+ kw_casex,kw_casez,kw_celldefine,
+ kw_checker,  kw_clocking, kw_constraint,
+ kw_cover,kw_covergroup,   kw_coverpoint,
+ kw_disable,  kw_dist, kw_edge,
+ kw_end,  kw_endcase,  kw_endchecker,
+ kw_endclass, kw_endclocking,  kw_endfunction,
+ kw_endgenerate,  kw_endgroup, kw_endinterface,
+ kw_endmodule,kw_endpackage,   kw_endprimitive,
+ kw_endprogram,   kw_endproperty,  kw_endsequence,
+ kw_endspecify,   kw_endtable, kw_endtask,
+ kw_extends,  kw_final,kw_foreach,
+ kw_forever,  kw_fork, kw_function,
+ kw_generate, kw_highz0,   kw_highz1,
+ kw_iff,  kw_ifnone,   kw_ignore_bins,
+ kw_illegal_bins, kw_implements,   kw_import,
+ kw_initial,  kw_inout, 

[clang] [clang] Introduce elementwise clz/ctz builtins (PR #131995)

2025-03-19 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/131995

>From c0eef87f4301a9725b7d81e78875a816d3cdf7cb Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Mon, 3 Feb 2025 16:54:17 +
Subject: [PATCH 1/2] [clang] Introduce elementwise clz/ctz builtins

These builtins are modeled on the clzg/ctzg builtins, which accept an
optional second argument. This second argument is returned if the first
argument is 0.
---
 clang/docs/LanguageExtensions.rst |  8 ++
 clang/include/clang/Basic/Builtins.td | 12 +++
 clang/lib/CodeGen/CGBuiltin.cpp   | 18 ++--
 clang/lib/Sema/SemaChecking.cpp   | 13 +++
 .../test/CodeGen/builtins-elementwise-math.c  | 96 +++
 clang/test/Sema/builtins-elementwise-math.c   | 44 +
 6 files changed, 185 insertions(+), 6 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index d4771775c9739..f5d4ec49a1dd2 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -831,6 +831,14 @@ of different sizes and signs is forbidden in binary and 
ternary builtins.
 semantics, see `LangRef
 
`_
 for the comparison.
+ T __builtin_elementwise_clz(T x[, T y])return the number of leading 0 
bits in the first argument. If  integer types
+the first argument is 0 and an 
optional second argument is provided,
+the second argument is 
returned. If the first argument is 0 but only
+one argument is provided, the 
behaviour is undefined.
+ T __builtin_elementwise_ctz(T x[, T y])return the number of trailing 
0 bits in the first argument. If integer types
+the first argument is 0 and an 
optional second argument is provided,
+the second argument is 
returned. If the first argument is 0 but only
+one argument is provided, the 
behaviour is undefined.
 == 
== 
=
 
 
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 72a5e495c4059..0bc506d977186 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1484,6 +1484,18 @@ def ElementwiseSubSat : Builtin {
   let Prototype = "void(...)";
 }
 
+def ElementwiseClz : Builtin {
+  let Spellings = ["__builtin_elementwise_clz"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
+  let Prototype = "void(...)";
+}
+
+def ElementwiseCtz : Builtin {
+  let Spellings = ["__builtin_elementwise_ctz"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
+  let Prototype = "void(...)";
+}
+
 def ReduceMax : Builtin {
   let Spellings = ["__builtin_reduce_max"];
   let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c126f88b9e3a5..c48e1cf54f3f9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3673,9 +3673,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_ctz:
   case Builtin::BI__builtin_ctzl:
   case Builtin::BI__builtin_ctzll:
-  case Builtin::BI__builtin_ctzg: {
-bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_ctzg &&
-   E->getNumArgs() > 1;
+  case Builtin::BI__builtin_ctzg:
+  case Builtin::BI__builtin_elementwise_ctz: {
+bool HasFallback =
+(BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_ctzg ||
+ BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_elementwise_ctz) &&
+E->getNumArgs() > 1;
 
 Value *ArgValue =
 HasFallback ? EmitScalarExpr(E->getArg(0))
@@ -3705,9 +3708,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_clz:
   case Builtin::BI__builtin_clzl:
   case Builtin::BI__builtin_clzll:
-  case Builtin::BI__builtin_clzg: {
-bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_clzg &&
-   E->getNumArgs() > 1;
+  case Builtin::BI__builtin_clzg:
+  case Builtin::BI__builtin_elementwise_clz: {
+bool HasFallback =
+(BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_clzg ||
+ BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_elementwise_clz) &&
+E->getNumArgs() > 1;
 
 Value *ArgValue =
 HasFallback ? Em

[clang] [clang] Introduce elementwise clz/ctz builtins (PR #131995)

2025-03-19 Thread Fraser Cormack via cfe-commits


@@ -1484,6 +1484,18 @@ def ElementwiseSubSat : Builtin {
   let Prototype = "void(...)";
 }
 
+def ElementwiseClz : Builtin {
+  let Spellings = ["__builtin_elementwise_clz"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
+  let Prototype = "void(...)";
+}
+
+def ElementwiseCtz : Builtin {
+  let Spellings = ["__builtin_elementwise_ctz"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];

frasercrmck wrote:

Done - it now supports constexpr evaluation.

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


[clang] [clang][bytecode] Fix initializing array struct fields from an APValue (PR #131983)

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

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


[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)

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

vbvictor wrote:

> Do you know how much build times and binary size are affected by this change?

Binary size comparison was addressed in discussion on previous PR, here is 
comment for reference 
https://github.com/llvm/llvm-project/pull/123734#discussion_r1925090946.
However, this may have changed now because of new architecture.

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


[clang] [Clang] Increase the default expression nesting limit (PR #132021)

2025-03-19 Thread Erich Keane via cfe-commits


@@ -169,6 +169,8 @@ Modified Compiler Flags
   the behavior of ``-mtp`` in gcc. This changes the default behavior for ARM 
targets that provide the ``TPIDRURO`` register as this will be used instead of 
a call to the ``__aeabi_read_tp``.
   Programs that use ``__aeabi_read_tp`` but do not use the ``TPIDRURO`` 
register must use ``-mtp=soft``. Fixes #123864
 
+- The compiler flag `-fbracket-depth` default value is increased from 256 to 
2048. (#GH94728)

erichkeane wrote:

Wow, this is an aggressive change :) 

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


[clang] [Clang] Increase the default expression nesting limit (PR #132021)

2025-03-19 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

This seems reasonable to me.  All of the changes look sound.  Good job finding 
room here!

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


[clang-tools-extra] [clang-tidy][C++20] Add support for aggregate types within modernize-use-emplace (PR #131969)

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

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


[clang] 614d855 - [OffloadBundler] Expose function to parse compressed bundle headers (#130284)

2025-03-19 Thread via cfe-commits

Author: Juan Manuel Martinez Caamaño
Date: 2025-03-19T09:10:40+01:00
New Revision: 614d8557dcd41aae31bd50e93fed3487f235ef11

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

LOG: [OffloadBundler] Expose function to parse compressed bundle headers 
(#130284)

In COMGR we hash the header of compressed bundles. For this we take the
first bytes of the buffer (according to the maximum header size) and
hash them.

To have a more stable API, and to be able to pick only the hash field (which is
the only one we are actually interested in) of the header, we propose
a version independent header version that is common to all versions.

Added: 


Modified: 
clang/include/clang/Driver/OffloadBundler.h
clang/lib/Driver/OffloadBundler.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/OffloadBundler.h 
b/clang/include/clang/Driver/OffloadBundler.h
index cbe507c000601..667156a524b79 100644
--- a/clang/include/clang/Driver/OffloadBundler.h
+++ b/clang/include/clang/Driver/OffloadBundler.h
@@ -107,50 +107,20 @@ struct OffloadTargetInfo {
 // - Compressed Data (variable length).
 class CompressedOffloadBundle {
 private:
-  static inline const size_t MagicSize = 4;
-  static inline const size_t VersionFieldSize = sizeof(uint16_t);
-  static inline const size_t MethodFieldSize = sizeof(uint16_t);
-  // Legacy size fields for V1/V2
-  static inline const size_t FileSizeFieldSizeV2 = sizeof(uint32_t);
-  static inline const size_t UncompressedSizeFieldSizeV2 = sizeof(uint32_t);
-  // New size fields for V3
-  static inline const size_t FileSizeFieldSizeV3 = sizeof(uint64_t);
-  static inline const size_t UncompressedSizeFieldSizeV3 = sizeof(uint64_t);
-  static inline const size_t HashFieldSize = sizeof(uint64_t);
-
-  // Keep V1 header size for backward compatibility
-  static inline const size_t V1HeaderSize =
-  MagicSize + VersionFieldSize + MethodFieldSize +
-  UncompressedSizeFieldSizeV2 + HashFieldSize;
-
-  // Keep V2 header size for backward compatibility
-  static inline const size_t V2HeaderSize =
-  MagicSize + VersionFieldSize + FileSizeFieldSizeV2 + MethodFieldSize +
-  UncompressedSizeFieldSizeV2 + HashFieldSize;
-
-  // Add V3 header size with 64-bit fields
-  static inline const size_t V3HeaderSize =
-  MagicSize + VersionFieldSize + FileSizeFieldSizeV3 + MethodFieldSize +
-  UncompressedSizeFieldSizeV3 + HashFieldSize;
-
   static inline const llvm::StringRef MagicNumber = "CCOB";
 
 public:
-  static inline const uint16_t DefaultVersion = 2;
+  struct CompressedBundleHeader {
+unsigned Version;
+llvm::compression::Format CompressionFormat;
+std::optional FileSize;
+size_t UncompressedFileSize;
+uint64_t Hash;
 
-  // Helper method to get header size based on version
-  static size_t getHeaderSize(uint16_t Version) {
-switch (Version) {
-case 1:
-  return V1HeaderSize;
-case 2:
-  return V2HeaderSize;
-case 3:
-  return V3HeaderSize;
-default:
-  llvm_unreachable("Unsupported version");
-}
-  }
+static llvm::Expected tryParse(llvm::StringRef);
+  };
+
+  static inline const uint16_t DefaultVersion = 2;
 
   static llvm::Expected>
   compress(llvm::compression::Params P, const llvm::MemoryBuffer &Input,

diff  --git a/clang/lib/Driver/OffloadBundler.cpp 
b/clang/lib/Driver/OffloadBundler.cpp
index 6dfb72fb223ce..859e44fb9bdb2 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/EndianStream.h"
@@ -1127,13 +1128,116 @@ 
CompressedOffloadBundle::compress(llvm::compression::Params P,
   llvm::StringRef(FinalBuffer.data(), FinalBuffer.size()));
 }
 
+// Use packed structs to avoid padding, such that the structs map the 
serialized
+// format.
+LLVM_PACKED_START
+union RawCompressedBundleHeader {
+  struct CommonFields {
+uint32_t Magic;
+uint16_t Version;
+uint16_t Method;
+  };
+
+  struct V1Header {
+CommonFields Common;
+uint32_t UncompressedFileSize;
+uint64_t Hash;
+  };
+
+  struct V2Header {
+CommonFields Common;
+uint32_t FileSize;
+uint32_t UncompressedFileSize;
+uint64_t Hash;
+  };
+
+  struct V3Header {
+CommonFields Common;
+uint64_t FileSize;
+uint64_t UncompressedFileSize;
+uint64_t Hash;
+  };
+
+  CommonFields Common;
+  V1Header V1;
+  V2Header V2;
+  V3Header V3;
+};
+LLVM_PACKED_END
+
+// Helper method to get header size based on version
+static size_t getHeaderSize(uint16_t Version) {
+  switch (Version) {
+  case 1:
+   

[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)

2025-03-19 Thread Ibraim Ganiev via cfe-commits

olologin wrote:

I like it if it does not break anything :)
One small nitpick: Maybe word "custom" is too broad for this. Maybe something 
that mentions "clang-query" is more specific.
But it is just my opinion and I am not related to clang-tidy, so whatever you 
guys decide.

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


[clang] [Clang] emit -Wunused-variable warning for unused structured bindings without the [[maybe_unused]] attribute (PR #127061)

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

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

>From a76ee008bdb87655da465e21d09c840edecc2b1b Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 13 Feb 2025 15:24:09 +0200
Subject: [PATCH 1/2] [Clang] emit -Wunused-variable warning for unused
 structured bindings without the [[maybe_unused]] attribute

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaDecl.cpp|  9 +
 clang/test/SemaCXX/unused-bindings.cpp | 17 +
 clang/test/SemaCXX/unused.cpp  |  3 ++-
 4 files changed, 26 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/SemaCXX/unused-bindings.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6344c4b36e357..4f20415ec006d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -160,6 +160,8 @@ Bug Fixes to C++ Support
 - Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
 - The initialization kind of elements of structured bindings
   direct-list-initialized from an array is corrected to direct-initialization.
+- Clang now emits the ``-Wunused-variable`` warning when some structured 
bindings are unused
+  and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6eedc77ed20a0..19a73a66be5af 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1921,13 +1921,14 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions 
&LangOpts,
 // For a decomposition declaration, warn if none of the bindings are
 // referenced, instead of if the variable itself is referenced (which
 // it is, by the bindings' expressions).
-bool IsAllPlaceholders = true;
+bool IsAllIgnored = true;
 for (const auto *BD : DD->bindings()) {
-  if (BD->isReferenced() || BD->hasAttr())
+  if (BD->isReferenced())
 return false;
-  IsAllPlaceholders = IsAllPlaceholders && BD->isPlaceholderVar(LangOpts);
+  IsAllIgnored = IsAllIgnored && (BD->isPlaceholderVar(LangOpts) ||
+  BD->hasAttr());
 }
-if (IsAllPlaceholders)
+if (IsAllIgnored)
   return false;
   } else if (!D->getDeclName()) {
 return false;
diff --git a/clang/test/SemaCXX/unused-bindings.cpp 
b/clang/test/SemaCXX/unused-bindings.cpp
new file mode 100644
index 0..01f2126133a20
--- /dev/null
+++ b/clang/test/SemaCXX/unused-bindings.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2c -Wunused %s
+
+namespace GH125810 {
+struct S {
+  int a, b;
+};
+
+void t(S s) {
+  auto &[_, _] = s;
+  auto &[a1, _] = s; // expected-warning {{unused variable '[a1, _]'}}
+  auto &[_, b2] = s; // expected-warning {{unused variable '[_, b2]'}}
+
+  auto &[a3 [[maybe_unused]], b3 [[maybe_unused]]] = s;
+  auto &[a4, b4 [[maybe_unused]]] = s; // expected-warning {{unused variable 
'[a4, b4]'}}
+  auto &[a5 [[maybe_unused]], b5] = s; // expected-warning {{unused variable 
'[a5, b5]'}}
+}
+}
diff --git a/clang/test/SemaCXX/unused.cpp b/clang/test/SemaCXX/unused.cpp
index 1f40c1b1ca903..ab728069f2faf 100644
--- a/clang/test/SemaCXX/unused.cpp
+++ b/clang/test/SemaCXX/unused.cpp
@@ -114,7 +114,8 @@ namespace maybe_unused_binding {
 
 void test() {
   struct X { int a, b; } x;
-  auto [a [[maybe_unused]], b] = x; // expected-warning {{an attribute 
specifier sequence attached to a structured binding declaration is a C++2c 
extension}}
+  auto [a [[maybe_unused]], b] = x; // expected-warning {{an attribute 
specifier sequence attached to a structured binding declaration is a C++2c 
extension}} \
+// expected-warning {{unused variable '[a, 
b]'}}
 }
 
 }

>From c600c2a2378310c3f2fc82edaca66ca80b40284d Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 14 Feb 2025 13:43:53 +0200
Subject: [PATCH 2/2] update test to use std c++26

---
 clang/test/SemaCXX/unused-bindings.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/unused-bindings.cpp 
b/clang/test/SemaCXX/unused-bindings.cpp
index 01f2126133a20..83250dd4b0a11 100644
--- a/clang/test/SemaCXX/unused-bindings.cpp
+++ b/clang/test/SemaCXX/unused-bindings.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2c -Wunused %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++26 -Wunused %s
 
 namespace GH125810 {
 struct S {

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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcibi (Branch Immediate) extension (PR #130779)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `premerge-monolithic-linux` 
running on `premerge-linux-1` while building `clang,llvm` at step 6 
"build-unified-tree".

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


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

```
Step 6 (build-unified-tree) failure: build (failure)
...
15.417 [3715/58/156] Building CXX object 
lib/Target/RISCV/MCTargetDesc/CMakeFiles/LLVMRISCVDesc.dir/RISCVAsmBackend.cpp.o
15.450 [3714/58/157] Linking CXX executable bin/dexp
15.463 [3713/58/158] Building CXX object 
lib/Target/RISCV/MCTargetDesc/CMakeFiles/LLVMRISCVDesc.dir/RISCVMCCodeEmitter.cpp.o
15.478 [3712/58/159] Linking CXX executable bin/clangd-fuzzer
15.741 [3711/58/160] Building CXX object 
lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/AsmPrinter.cpp.o
15.742 [3710/58/161] Linking CXX executable bin/clangd-indexer
15.788 [3709/58/162] Linking CXX executable bin/llvm-cxxdump
15.801 [3709/57/163] Building CXX object 
lib/Target/RISCV/MCTargetDesc/CMakeFiles/LLVMRISCVDesc.dir/RISCVBaseInfo.cpp.o
15.962 [3709/56/164] Linking CXX static library lib/libLLVMAsmPrinter.a
16.092 [3706/58/165] Building CXX object 
lib/Target/RISCV/AsmParser/CMakeFiles/LLVMRISCVAsmParser.dir/RISCVAsmParser.cpp.o
FAILED: 
lib/Target/RISCV/AsmParser/CMakeFiles/LLVMRISCVAsmParser.dir/RISCVAsmParser.cpp.o
 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/clang++ 
-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/build/buildbot/premerge-monolithic-linux/build/lib/Target/RISCV/AsmParser 
-I/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/lib/Target/RISCV/AsmParser
 -I/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/lib/Target/RISCV 
-I/build/buildbot/premerge-monolithic-linux/build/lib/Target/RISCV 
-I/build/buildbot/premerge-monolithic-linux/build/include 
-I/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include -gmlt 
-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 -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -O3 -DNDEBUG -fvisibility=hidden  
-fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT 
lib/Target/RISCV/AsmParser/CMakeFiles/LLVMRISCVAsmParser.dir/RISCVAsmParser.cpp.o
 -MF 
lib/Target/RISCV/AsmParser/CMakeFiles/LLVMRISCVAsmParser.dir/RISCVAsmParser.cpp.o.d
 -o 
lib/Target/RISCV/AsmParser/CMakeFiles/LLVMRISCVAsmParser.dir/RISCVAsmParser.cpp.o
 -c 
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:826:48:
 error: no member named 'VK_RISCV_None' in 'llvm::RISCVMCExpr'
RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
  ~^
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:831:31:
 error: no member named 'VK_RISCV_None' in 'llvm::RISCVMCExpr'
   VK == RISCVMCExpr::VK_RISCV_None;
 ~^
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:1024:48:
 error: no member named 'VK_RISCV_None' in 'llvm::RISCVMCExpr'
RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
  ~^
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:1029:31:
 error: no member named 'VK_RISCV_None' in 'llvm::RISCVMCExpr'
   VK == RISCVMCExpr::VK_RISCV_None;
 ~^
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:1036:48:
 error: no member named 'VK_RISCV_None' in 'llvm::RISCVMCExpr'
RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
  ~^
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:1039:31:
 error: no member named 'VK_RISCV_None' in 'llvm::RISCVMCExpr'
   VK == RISCVMCExpr::VK_RISCV_None;
 ~^
6 errors generated.
16.430 [3706/57/166] Linking CXX executable bin/clangd
17.039 [3706/56/167] Linking CXX executable bin/BuildingAJIT-Ch2
17.058 [3706/55/168] Linking CXX executable bin/BuildingAJIT-Ch1
17.112 [3706/54/169] Building CXX object 
lib/Target/RISCV/CMakeFiles/LLVMRISCVCodeGen.dir/R

[clang-tools-extra] [clang-tidy] add new check: modernize-use-scoped-lock (PR #126434)

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


@@ -0,0 +1,342 @@
+//===--- UseScopedLockCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseScopedLockCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+
+bool isLockGuard(const QualType &Type) {
+  if (const auto *Record = Type->getAs())
+if (const RecordDecl *Decl = Record->getDecl())
+  return Decl->getName() == "lock_guard" && Decl->isInStdNamespace();
+
+  if (const auto *TemplateSpecType = Type->getAs())
+if (const TemplateDecl *Decl =
+TemplateSpecType->getTemplateName().getAsTemplateDecl())
+  return Decl->getName() == "lock_guard" && Decl->isInStdNamespace();
+
+  return false;
+}
+
+llvm::SmallVector getLockGuardsFromDecl(const DeclStmt *DS) {
+  llvm::SmallVector LockGuards;
+
+  for (const Decl *Decl : DS->decls()) {
+if (const auto *VD = dyn_cast(Decl)) {
+  const QualType Type =
+  VD->getType().getUnqualifiedType().getCanonicalType();
+  if (isLockGuard(Type))
+LockGuards.push_back(VD);
+}
+  }
+
+  return LockGuards;
+}
+
+// Scans through the statements in a block and groups consecutive
+// 'std::lock_guard' variable declarations together.
+llvm::SmallVector>
+findLocksInCompoundStmt(const CompoundStmt *Block,
+const ast_matchers::MatchFinder::MatchResult &Result) {
+  // store groups of consecutive 'std::lock_guard' declarations
+  llvm::SmallVector> LockGuardGroups;
+  llvm::SmallVector CurrentLockGuardGroup;
+
+  auto AddAndClearCurrentGroup = [&]() {
+if (!CurrentLockGuardGroup.empty()) {
+  LockGuardGroups.push_back(CurrentLockGuardGroup);
+  CurrentLockGuardGroup.clear();
+}
+  };
+
+  for (const Stmt *Stmt : Block->body()) {
+if (const auto *DS = dyn_cast(Stmt)) {
+  llvm::SmallVector LockGuards = 
getLockGuardsFromDecl(DS);
+
+  if (!LockGuards.empty()) {
+CurrentLockGuardGroup.insert(
+CurrentLockGuardGroup.end(),
+std::make_move_iterator(LockGuards.begin()),
+std::make_move_iterator(LockGuards.end()));
+continue;
+  }
+}
+AddAndClearCurrentGroup();
+  }
+
+  AddAndClearCurrentGroup();
+
+  return LockGuardGroups;
+}
+
+TemplateSpecializationTypeLoc
+getTemplateLockGuardTypeLoc(const TypeSourceInfo *SourceInfo) {
+  const TypeLoc Loc = SourceInfo->getTypeLoc();
+
+  const auto ElaboratedLoc = Loc.getAs();
+  if (!ElaboratedLoc)
+return {};
+
+  return 
ElaboratedLoc.getNamedTypeLoc().getAs();
+}
+
+// Find the exact source range of the 'lock_guard' token
+SourceRange getLockGuardRange(const TypeSourceInfo *SourceInfo) {
+  const TypeLoc LockGuardTypeLoc = SourceInfo->getTypeLoc();
+
+  return SourceRange(LockGuardTypeLoc.getBeginLoc(),
+ LockGuardTypeLoc.getEndLoc());
+}
+
+// Find the exact source range of the 'lock_guard' name token
+SourceRange getLockGuardNameRange(const TypeSourceInfo *SourceInfo) {
+  const TemplateSpecializationTypeLoc TemplateLoc =
+  getTemplateLockGuardTypeLoc(SourceInfo);
+  if (!TemplateLoc)
+return {};
+
+  return SourceRange(TemplateLoc.getTemplateNameLoc(),
+ TemplateLoc.getLAngleLoc().getLocWithOffset(-1));
+}
+
+AST_MATCHER_P(CompoundStmt, hasMultiple, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  size_t Count = 0;
+
+  for (const Stmt *Stmt : Node.body())
+if (InnerMatcher.matches(*Stmt, Finder, Builder))
+  Count++;
+
+  return Count > 1;
+}
+
+AST_MATCHER_P(CompoundStmt, hasSingle, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  size_t Count = 0;
+  ast_matchers::internal::BoundNodesTreeBuilder Result;
+
+  for (const Stmt *Stmt : Node.body()) {
+ast_matchers::internal::BoundNodesTreeBuilder TB(*Builder);
+if (InnerMatcher.matches(*Stmt, Finder, &TB)) {
+  Count++;
+  if (Count == 1)
+Result.addMatch(TB);
+}
+  }
+
+  if (Count > 1) {
+Builder->removeBindings(
+[](const ast_matchers::internal::BoundNodesMap &) { return true; });
+return false;
+  }
+
+  *Builder = std::move(Result);
+  return true;
+}
+
+const StringRef UseScopedLockMessage =
+"use 'std::scoped_lock' instead of 'std::lock_guard'";
+
+} // namespace
+
+UseScopedLockCheck::UseScopedLockCheck(StringRef Name,
+   

[clang] [Clang][Diagnostics] Update select uses in DiagnosticXKinds.td to use enum_select (PR #130868)

2025-03-19 Thread Erich Keane via cfe-commits


@@ -11,8 +11,9 @@ let Component = "AST" in {
 // Constant expression diagnostics. These (and their users) belong in Sema.
 def note_expr_divide_by_zero : Note<"division by zero">;
 def note_constexpr_invalid_cast : Note<
-  "%select{reinterpret_cast|dynamic_cast|%select{this conversion|cast that"
-  " performs the conversions of a reinterpret_cast}1|cast from %1}0"
+  
"%enum_select{%Reinterpret{reinterpret_cast}|%Dynamic{dynamic_cast}|"
+  "%ThisCastOrReinterpret{%select{this conversion|cast that performs the 
conversions "

erichkeane wrote:

```suggestion
  "%ThisConversionOrReinterpret{%select{this conversion|cast that performs the 
conversions "
```

https://github.com/llvm/llvm-project/pull/130868
___
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 new check: modernize-use-scoped-lock (PR #126434)

2025-03-19 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,342 @@
+//===--- UseScopedLockCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseScopedLockCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+
+bool isLockGuard(const QualType &Type) {
+  if (const auto *Record = Type->getAs())
+if (const RecordDecl *Decl = Record->getDecl())
+  return Decl->getName() == "lock_guard" && Decl->isInStdNamespace();
+
+  if (const auto *TemplateSpecType = Type->getAs())
+if (const TemplateDecl *Decl =
+TemplateSpecType->getTemplateName().getAsTemplateDecl())
+  return Decl->getName() == "lock_guard" && Decl->isInStdNamespace();
+
+  return false;
+}
+
+llvm::SmallVector getLockGuardsFromDecl(const DeclStmt *DS) {
+  llvm::SmallVector LockGuards;
+
+  for (const Decl *Decl : DS->decls()) {
+if (const auto *VD = dyn_cast(Decl)) {
+  const QualType Type =
+  VD->getType().getUnqualifiedType().getCanonicalType();
+  if (isLockGuard(Type))
+LockGuards.push_back(VD);
+}
+  }
+
+  return LockGuards;
+}
+
+// Scans through the statements in a block and groups consecutive
+// 'std::lock_guard' variable declarations together.
+llvm::SmallVector>
+findLocksInCompoundStmt(const CompoundStmt *Block,
+const ast_matchers::MatchFinder::MatchResult &Result) {
+  // store groups of consecutive 'std::lock_guard' declarations
+  llvm::SmallVector> LockGuardGroups;
+  llvm::SmallVector CurrentLockGuardGroup;
+
+  auto AddAndClearCurrentGroup = [&]() {
+if (!CurrentLockGuardGroup.empty()) {
+  LockGuardGroups.push_back(CurrentLockGuardGroup);
+  CurrentLockGuardGroup.clear();
+}
+  };
+
+  for (const Stmt *Stmt : Block->body()) {
+if (const auto *DS = dyn_cast(Stmt)) {
+  llvm::SmallVector LockGuards = 
getLockGuardsFromDecl(DS);
+
+  if (!LockGuards.empty()) {
+CurrentLockGuardGroup.insert(
+CurrentLockGuardGroup.end(),
+std::make_move_iterator(LockGuards.begin()),

PiotrZSL wrote:

there is nothing to move that are just pointers

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


[clang-tools-extra] [clang-tidy] Skip system macros in readability-identifier-naming check (PR #132016)

2025-03-19 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/132016

>From 6e1a50025c75cc5c3835046c66b720a75a6715f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 19 Mar 2025 12:28:49 +
Subject: [PATCH] [clang-tidy] Skip system macros in
 readability-identifier-naming check

Currently, the check is processing system macros. Most importantly,
it tries to find .clang-tidy files associated with those files, if
the option GetConfigPerFile (on by default) is active.

This is problematic for a number of reasons:

- System macros cannot be acted upon (renamed), so it's wasted work.
- When the main .cpp file includes a system header, clang-tidy tries
  to find the .clang-tidy file for that system header. When that system
  header is a 3rd-party repository, they may have their own .clang-tidy
  file, which may not be compatible with the current version of
  clang-tidy. So, clang-tidy may fail to analyze our main.cpp file,
  only because it includes a 3rd-party system header whose .clang-tidy
  file is incompatible with our clang-tidy binary.

Therefore, skip system macros in this check.
---
 .../clang-tidy/utils/RenamerClangTidyCheck.cpp  | 6 +-
 clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h  | 3 +++
 clang-tools-extra/docs/ReleaseNotes.rst | 4 
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 9104723c7f1c0..d47403fe96b68 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -194,6 +194,9 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks 
{
   return;
 if (SM.isWrittenInCommandLineFile(MacroNameTok.getLocation()))
   return;
+if (Check->skipSystemMacros() &&
+SM.isInSystemHeader(MacroNameTok.getLocation()))
+  return;
 Check->checkMacro(MacroNameTok, Info, SM);
   }
 
@@ -397,7 +400,8 @@ RenamerClangTidyCheck::RenamerClangTidyCheck(StringRef 
CheckName,
  ClangTidyContext *Context)
 : ClangTidyCheck(CheckName, Context),
   AggressiveDependentMemberLookup(
-  Options.get("AggressiveDependentMemberLookup", false)) {}
+  Options.get("AggressiveDependentMemberLookup", false)),
+  SkipSystemMacros(!Context->getOptions().SystemHeaders.value_or(false)) {}
 RenamerClangTidyCheck::~RenamerClangTidyCheck() = default;
 
 void RenamerClangTidyCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
index 3d5721b789ac2..5f59d14bf370e 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
@@ -118,6 +118,8 @@ class RenamerClangTidyCheck : public ClangTidyCheck {
   void addUsage(const NamedDecl *Decl, SourceRange Range,
 const SourceManager &SourceMgr);
 
+  bool skipSystemMacros() const { return SkipSystemMacros; }
+
 protected:
   /// Overridden by derived classes, returns information about if and how a 
Decl
   /// failed the check. A 'std::nullopt' result means the Decl did not fail the
@@ -162,6 +164,7 @@ class RenamerClangTidyCheck : public ClangTidyCheck {
 
   NamingCheckFailureMap NamingCheckFailures;
   const bool AggressiveDependentMemberLookup;
+  const bool SkipSystemMacros;
 };
 
 } // namespace tidy
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 72aa05eb4dcd1..205655c59c48c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -188,6 +188,10 @@ Changes in existing checks
   tolerating fix-it breaking compilation when functions is used as pointers
   to avoid matching usage of functions within the current compilation unit.
 
+- Improved :doc:`readability-identifier-naming
+  ` to avoid processing system
+  macros (unless the `SystemHeaders` option is enabled).
+
 Removed checks
 ^^
 

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


[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)

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

HerrCai0907 wrote:

> However, this may have changed now because of new architecture.

It will be too much differences because dependences are the same. only some 
wrapper code in clangtidy changed.

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


[clang] [clang] ASTContext: flesh out implementation of getCommonNNS (PR #131964)

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


@@ -13462,13 +13462,114 @@ static ElaboratedTypeKeyword 
getCommonTypeKeyword(const T *X, const T *Y) {
 : ElaboratedTypeKeyword::None;
 }
 
+static NestedNameSpecifier *getCommonNNS(ASTContext &Ctx,
+ NestedNameSpecifier *X,
+ NestedNameSpecifier *Y, bool IsSame) {
+  if (X == Y)
+return X;
+
+  NestedNameSpecifier *Canon = Ctx.getCanonicalNestedNameSpecifier(X);
+  if (Canon != Ctx.getCanonicalNestedNameSpecifier(Y)) {
+assert(!IsSame && "Should be the same NestedNameSpecifier");
+return nullptr;

mizvekov wrote:

I would actually prefer to trap here, the original behavior with unreachable, 
instead of assert is more desirable.

If we get here, we probably have a canonicalization bug somewhere, and in any 
case we could produce a different type instead of a different sugaring as 
intended.

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


[clang] [llvm] [Clang][AMDGPU] Expose buffer load lds as a clang builtin (PR #132048)

2025-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Juan Manuel Martinez Caamaño (jmmartinez)


Changes

CK is using either inline assembly or inline LLVM-IR builtins to generate 
buffer_load_dword lds instructions.

This patch exposes this instruction as a Clang builtin.

Limitations in this patch: these instructions are not available for 
gfx11/gfx12. I wasn't able to identify a target feature that we could use to 
predicate the builtin availability, in the same way as it is done for 
global_load_lds.

Related to SWDEV-519702 and SWDEV-518861

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


6 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsAMDGPU.def (+2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2-2) 
- (modified) clang/lib/Sema/SemaAMDGPU.cpp (+3-4) 
- (modified) clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-load.cl (+9) 
- (added) 
clang/test/SemaOpenCL/builtins-amdgcn-raw-ptr-buffer-load-lds-error.cl (+15) 
- (modified) llvm/include/llvm/IR/IntrinsicsAMDGPU.td (+3-1) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 44ef404aee72f..4117e8d67330b 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -162,6 +162,8 @@ BUILTIN(__builtin_amdgcn_raw_buffer_load_b64, "V2UiQbiiIi", 
"n")
 BUILTIN(__builtin_amdgcn_raw_buffer_load_b96, "V3UiQbiiIi", "n")
 BUILTIN(__builtin_amdgcn_raw_buffer_load_b128, "V4UiQbiiIi", "n")
 
+BUILTIN(__builtin_amdgcn_raw_ptr_buffer_load_lds, "vQbv*3IUiiiIiIi", "t")
+
 
//===--===//
 // Ballot builtins.
 
//===--===//
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1536a3b8c920a..e17d6b530141d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -13132,6 +13132,6 @@ def err_acc_duplicate_bind
 "permitted to refer to the same function">;
 
 // AMDGCN builtins diagnostics
-def err_amdgcn_global_load_lds_size_invalid_value : Error<"invalid size 
value">;
-def note_amdgcn_global_load_lds_size_valid_value : Note<"size must be 
%select{1, 2, or 4|1, 2, 4, 12 or 16}0">;
+def err_amdgcn_load_lds_size_invalid_value : Error<"invalid size value">;
+def note_amdgcn_load_lds_size_valid_value : Note<"size must be %select{1, 2, 
or 4|1, 2, 4, 12 or 16}0">;
 } // end of sema component.
diff --git a/clang/lib/Sema/SemaAMDGPU.cpp b/clang/lib/Sema/SemaAMDGPU.cpp
index a4d075dfd0768..7fec099374152 100644
--- a/clang/lib/Sema/SemaAMDGPU.cpp
+++ b/clang/lib/Sema/SemaAMDGPU.cpp
@@ -35,6 +35,7 @@ bool SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(unsigned 
BuiltinID,
   Builtin::evaluateRequiredTargetFeatures("gfx950-insts", 
CallerFeatureMap);
 
   switch (BuiltinID) {
+  case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_load_lds:
   case AMDGPU::BI__builtin_amdgcn_global_load_lds: {
 constexpr const int SizeIdx = 2;
 llvm::APSInt Size;
@@ -54,11 +55,9 @@ bool SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(unsigned 
BuiltinID,
   [[fallthrough]];
 }
 default:
-  Diag(ArgExpr->getExprLoc(),
-   diag::err_amdgcn_global_load_lds_size_invalid_value)
+  Diag(ArgExpr->getExprLoc(), diag::err_amdgcn_load_lds_size_invalid_value)
   << ArgExpr->getSourceRange();
-  Diag(ArgExpr->getExprLoc(),
-   diag::note_amdgcn_global_load_lds_size_valid_value)
+  Diag(ArgExpr->getExprLoc(), diag::note_amdgcn_load_lds_size_valid_value)
   << HasGFX950Insts << ArgExpr->getSourceRange();
   return true;
 }
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-load.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-load.cl
index 3403b69e07e4b..5e3ed9027c17a 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-load.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-load.cl
@@ -170,3 +170,12 @@ v3u32 
test_amdgcn_raw_ptr_buffer_load_b96_non_const_soffset(__amdgpu_buffer_rsrc
 v4u32 
test_amdgcn_raw_ptr_buffer_load_b128_non_const_soffset(__amdgpu_buffer_rsrc_t 
rsrc, int offset, int soffset) {
   return __builtin_amdgcn_raw_buffer_load_b128(rsrc, /*offset=*/0, soffset, 
/*aux=*/0);
 }
+
+// CHECK-LABEL: @test_amdgcn_raw_ptr_buffer_load_lds(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.amdgcn.raw.ptr.buffer.load.lds(ptr 
addrspace(8) [[RSRC:%.*]], ptr addrspace(3) [[LDS:%.*]], i32 1, i32 
[[OFFSET:%.*]], i32 [[SOFFSET:%.*]], i32 2, i32 3)
+// CHECK-NEXT:ret void
+//
+void test_amdgcn_raw_ptr_buffer_load_lds(__amdgpu_buffer_rsrc_t rsrc, __local 
void * lds, int offset, int soffset) {
+__builtin_amdgcn_raw_ptr_buffer_load_lds(rsrc, lds, 1, offset, soffset, 2, 
3);
+}
diff --git 
a/clang/test/SemaOpenCL/builtins-

[clang] [llvm] [Clang][AMDGPU] Expose buffer load lds as a clang builtin (PR #132048)

2025-03-19 Thread Juan Manuel Martinez Caamaño via cfe-commits

https://github.com/jmmartinez created 
https://github.com/llvm/llvm-project/pull/132048

CK is using either inline assembly or inline LLVM-IR builtins to generate 
buffer_load_dword lds instructions.

This patch exposes this instruction as a Clang builtin.

Limitations in this patch: these instructions are not available for 
gfx11/gfx12. I wasn't able to identify a target feature that we could use to 
predicate the builtin availability, in the same way as it is done for 
global_load_lds.

Related to SWDEV-519702 and SWDEV-518861

From c89ffa43c68454ba07af248e345078d6a70b856b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Thu, 13 Mar 2025 10:00:28 +0100
Subject: [PATCH] [Clang][AMDGPU] Expose buffer load lds as a clang builtin

CK is using either inline assembly or inline llvm-ir builtins to
generate buffer_load_dword lds instructions.

This patch exposes this instruction as a builtin.

Related to SWDEV-519702 and SWDEV-518861
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |  2 ++
 clang/include/clang/Basic/DiagnosticSemaKinds.td  |  4 ++--
 clang/lib/Sema/SemaAMDGPU.cpp |  7 +++
 .../builtins-amdgcn-raw-buffer-load.cl|  9 +
 ...iltins-amdgcn-raw-ptr-buffer-load-lds-error.cl | 15 +++
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |  4 +++-
 6 files changed, 34 insertions(+), 7 deletions(-)
 create mode 100644 
clang/test/SemaOpenCL/builtins-amdgcn-raw-ptr-buffer-load-lds-error.cl

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 44ef404aee72f..4117e8d67330b 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -162,6 +162,8 @@ BUILTIN(__builtin_amdgcn_raw_buffer_load_b64, "V2UiQbiiIi", 
"n")
 BUILTIN(__builtin_amdgcn_raw_buffer_load_b96, "V3UiQbiiIi", "n")
 BUILTIN(__builtin_amdgcn_raw_buffer_load_b128, "V4UiQbiiIi", "n")
 
+BUILTIN(__builtin_amdgcn_raw_ptr_buffer_load_lds, "vQbv*3IUiiiIiIi", "t")
+
 
//===--===//
 // Ballot builtins.
 
//===--===//
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1536a3b8c920a..e17d6b530141d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -13132,6 +13132,6 @@ def err_acc_duplicate_bind
 "permitted to refer to the same function">;
 
 // AMDGCN builtins diagnostics
-def err_amdgcn_global_load_lds_size_invalid_value : Error<"invalid size 
value">;
-def note_amdgcn_global_load_lds_size_valid_value : Note<"size must be 
%select{1, 2, or 4|1, 2, 4, 12 or 16}0">;
+def err_amdgcn_load_lds_size_invalid_value : Error<"invalid size value">;
+def note_amdgcn_load_lds_size_valid_value : Note<"size must be %select{1, 2, 
or 4|1, 2, 4, 12 or 16}0">;
 } // end of sema component.
diff --git a/clang/lib/Sema/SemaAMDGPU.cpp b/clang/lib/Sema/SemaAMDGPU.cpp
index a4d075dfd0768..7fec099374152 100644
--- a/clang/lib/Sema/SemaAMDGPU.cpp
+++ b/clang/lib/Sema/SemaAMDGPU.cpp
@@ -35,6 +35,7 @@ bool SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(unsigned 
BuiltinID,
   Builtin::evaluateRequiredTargetFeatures("gfx950-insts", 
CallerFeatureMap);
 
   switch (BuiltinID) {
+  case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_load_lds:
   case AMDGPU::BI__builtin_amdgcn_global_load_lds: {
 constexpr const int SizeIdx = 2;
 llvm::APSInt Size;
@@ -54,11 +55,9 @@ bool SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(unsigned 
BuiltinID,
   [[fallthrough]];
 }
 default:
-  Diag(ArgExpr->getExprLoc(),
-   diag::err_amdgcn_global_load_lds_size_invalid_value)
+  Diag(ArgExpr->getExprLoc(), diag::err_amdgcn_load_lds_size_invalid_value)
   << ArgExpr->getSourceRange();
-  Diag(ArgExpr->getExprLoc(),
-   diag::note_amdgcn_global_load_lds_size_valid_value)
+  Diag(ArgExpr->getExprLoc(), diag::note_amdgcn_load_lds_size_valid_value)
   << HasGFX950Insts << ArgExpr->getSourceRange();
   return true;
 }
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-load.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-load.cl
index 3403b69e07e4b..5e3ed9027c17a 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-load.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-load.cl
@@ -170,3 +170,12 @@ v3u32 
test_amdgcn_raw_ptr_buffer_load_b96_non_const_soffset(__amdgpu_buffer_rsrc
 v4u32 
test_amdgcn_raw_ptr_buffer_load_b128_non_const_soffset(__amdgpu_buffer_rsrc_t 
rsrc, int offset, int soffset) {
   return __builtin_amdgcn_raw_buffer_load_b128(rsrc, /*offset=*/0, soffset, 
/*aux=*/0);
 }
+
+// CHECK-LABEL: @test_amdgcn_raw_ptr_buffer_load_lds(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.amdgc

[clang-tools-extra] [clang-tidy] Skip system macros in readability-identifier-naming check (PR #132016)

2025-03-19 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/132016

>From 0d4f53cefc223a116b25f9106d37dc707c58ec0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 19 Mar 2025 12:28:49 +
Subject: [PATCH] [clang-tidy] Skip system macros in
 readability-identifier-naming check

Currently, the check is processing system macros. Most importantly,
it tries to find .clang-tidy files associated with those files, if
the option GetConfigPerFile (on by default) is active.

This is problematic for a number of reasons:

- System macros cannot be acted upon (renamed), so it's wasted work.
- When the main .cpp file includes a system header, clang-tidy tries
  to find the .clang-tidy file for that system header. When that system
  header is a 3rd-party repository, they may have their own .clang-tidy
  file, which may not be compatible with the current version of
  clang-tidy. So, clang-tidy may fail to analyze our main.cpp file,
  only because it includes a 3rd-party system header whose .clang-tidy
  file is incompatible with our clang-tidy binary.

Therefore, skip system macros in this check.
---
 .../clang-tidy/utils/RenamerClangTidyCheck.cpp  | 6 +-
 clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h  | 3 +++
 clang-tools-extra/docs/ReleaseNotes.rst | 4 
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 9104723c7f1c0..b8cf14c20ea2e 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -194,6 +194,8 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks 
{
   return;
 if (SM.isWrittenInCommandLineFile(MacroNameTok.getLocation()))
   return;
+if (Check->skipSystemMacros() && 
SM.isInSystemHeader(MacroNameTok.getLocation()))
+  return;
 Check->checkMacro(MacroNameTok, Info, SM);
   }
 
@@ -397,7 +399,9 @@ RenamerClangTidyCheck::RenamerClangTidyCheck(StringRef 
CheckName,
  ClangTidyContext *Context)
 : ClangTidyCheck(CheckName, Context),
   AggressiveDependentMemberLookup(
-  Options.get("AggressiveDependentMemberLookup", false)) {}
+  Options.get("AggressiveDependentMemberLookup", false)),
+  SkipSystemMacros(!Context->getOptions().SystemHeaders.value_or(false))
+{}
 RenamerClangTidyCheck::~RenamerClangTidyCheck() = default;
 
 void RenamerClangTidyCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
index 3d5721b789ac2..5f59d14bf370e 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
@@ -118,6 +118,8 @@ class RenamerClangTidyCheck : public ClangTidyCheck {
   void addUsage(const NamedDecl *Decl, SourceRange Range,
 const SourceManager &SourceMgr);
 
+  bool skipSystemMacros() const { return SkipSystemMacros; }
+
 protected:
   /// Overridden by derived classes, returns information about if and how a 
Decl
   /// failed the check. A 'std::nullopt' result means the Decl did not fail the
@@ -162,6 +164,7 @@ class RenamerClangTidyCheck : public ClangTidyCheck {
 
   NamingCheckFailureMap NamingCheckFailures;
   const bool AggressiveDependentMemberLookup;
+  const bool SkipSystemMacros;
 };
 
 } // namespace tidy
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 72aa05eb4dcd1..205655c59c48c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -188,6 +188,10 @@ Changes in existing checks
   tolerating fix-it breaking compilation when functions is used as pointers
   to avoid matching usage of functions within the current compilation unit.
 
+- Improved :doc:`readability-identifier-naming
+  ` to avoid processing system
+  macros (unless the `SystemHeaders` option is enabled).
+
 Removed checks
 ^^
 

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


[clang] [clang][deps] Implement efficient in-process `ModuleCache` (PR #129751)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-with-thin-lto-ubuntu` running on `as-worker-92` while building `clang` 
at step 6 "build-stage1-compiler".

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


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

```
Step 6 (build-stage1-compiler) failure: build (failure)
...
617.932 [1782/72/4635] Building CXX object 
tools/clang/lib/Tooling/Syntax/CMakeFiles/obj.clangToolingSyntax.dir/TokenBufferTokenManager.cpp.o
617.958 [1781/72/4636] Building CXX object 
tools/clang/lib/Frontend/CMakeFiles/obj.clangFrontend.dir/ASTMerge.cpp.o
617.998 [1780/72/4637] Building CXX object 
tools/clang/lib/Frontend/Rewrite/CMakeFiles/obj.clangRewriteFrontend.dir/RewriteModernObjC.cpp.o
618.028 [1779/72/4638] Building CXX object 
tools/clang/lib/Tooling/Refactoring/CMakeFiles/obj.clangToolingRefactoring.dir/Extract/SourceExtraction.cpp.o
618.121 [1778/72/4639] Building CXX object 
tools/clang/lib/Tooling/Core/CMakeFiles/obj.clangToolingCore.dir/Replacement.cpp.o
618.147 [1777/72/4640] Linking CXX static library lib/libclangToolingCore.a
618.173 [1776/72/4641] Linking CXX static library 
lib/libclangToolingInclusions.a
618.446 [1775/72/4642] Building CXX object 
tools/clang/lib/Frontend/Rewrite/CMakeFiles/obj.clangRewriteFrontend.dir/RewriteObjC.cpp.o
618.978 [1774/72/4643] Building CXX object 
tools/clang/lib/Tooling/Refactoring/CMakeFiles/obj.clangToolingRefactoring.dir/ASTSelectionRequirements.cpp.o
619.195 [1773/72/4644] Building CXX object 
tools/clang/lib/Tooling/DependencyScanning/CMakeFiles/obj.clangDependencyScanning.dir/DependencyScanningService.cpp.o
FAILED: 
tools/clang/lib/Tooling/DependencyScanning/CMakeFiles/obj.clangDependencyScanning.dir/DependencyScanningService.cpp.o
 
/usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/build/stage1/tools/clang/lib/Tooling/DependencyScanning
 
-I/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/lib/Tooling/DependencyScanning
 
-I/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/include
 
-I/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/build/stage1/tools/clang/include
 -I/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/build/stage1/include 
-I/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/llvm/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings 
-Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long 
-Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess 
-Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-fno-strict-aliasing -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti 
-std=c++17 -MD -MT 
tools/clang/lib/Tooling/DependencyScanning/CMakeFiles/obj.clangDependencyScanning.dir/DependencyScanningService.cpp.o
 -MF 
tools/clang/lib/Tooling/DependencyScanning/CMakeFiles/obj.clangDependencyScanning.dir/DependencyScanningService.cpp.o.d
 -o 
tools/clang/lib/Tooling/DependencyScanning/CMakeFiles/obj.clangDependencyScanning.dir/DependencyScanningService.cpp.o
 -c 
/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
In file included from 
/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp:9:
/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h:117:22:
 error: declaration of ‘clang::tooling::dependencies::ModuleCacheMutexes 
clang::tooling::dependencies::DependencyScanningService::ModuleCacheMutexes’ 
changes meaning of ‘ModuleCacheMutexes’ [-fpermissive]
  117 |   ModuleCacheMutexes ModuleCacheMutexes;
  |  ^~
In file included from 
/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h:13,
 from 
/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp:9:
/home/buildbot/as-worker-92/clang-with-thin-lto-ubuntu/llvm-project/clang/include/clang/Tooling/DependencyScanning/InProcessModuleCache.h:20:8:
 note: ‘ModuleCacheMutexes’ declared here as ‘struct 
clang::tooling::dependencies::ModuleCacheMutexes’
   20 | struct ModuleCacheMutexes {
  |^~
619.528 [1773/71/4645] Building CXX object 
tools/clang/lib/T

[clang] [clang] Do not infer lifetimebound for functions with void return type (PR #131997)

2025-03-19 Thread Ilya Biryukov via cfe-commits

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


[clang] dd17c64 - [HLSL] Implement min and max overloads using templates (#131666)

2025-03-19 Thread via cfe-commits

Author: Sarah Spall
Date: 2025-03-19T09:57:46-07:00
New Revision: dd17c649abbfc7e4052e45d3240b23feb6530a31

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

LOG: [HLSL] Implement min and max overloads using templates (#131666)

Replace min and max overload implementation using macros with one using
templates.
Enable overloads of the forms:
 vector min/max(vector p0, T p1)
 vector min/max(T p0, vector p1)
 Add new tests.
Closes #131170

Added: 
clang/test/SemaHLSL/BuiltIns/max-errors-16bit.hlsl
clang/test/SemaHLSL/BuiltIns/min-errors-16bit.hlsl

Modified: 
clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
clang/lib/Headers/hlsl/hlsl_compat_overloads.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
index 62054b368691d..585e905c7bf5d 100644
--- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
@@ -35,26 +35,6 @@ namespace hlsl {
 #define _HLSL_16BIT_AVAILABILITY_STAGE(environment, version, stage)
 #endif
 
-#define GEN_VEC_SCALAR_OVERLOADS(FUNC_NAME, BASE_TYPE, AVAIL)  
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##2, AVAIL)
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##3, AVAIL)
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##4, AVAIL)
-
-#define GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, VECTOR_TYPE, AVAIL)   
\
-  IF_TRUE_##AVAIL( 
\
-  _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_TYPE
\
-  FUNC_NAME(VECTOR_TYPE p0, BASE_TYPE p1) {
\
-return __builtin_elementwise_##FUNC_NAME(p0, (VECTOR_TYPE)p1); 
\
-  }
\
-  IF_TRUE_##AVAIL( 
\
-  _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_TYPE
\
-  FUNC_NAME(BASE_TYPE p0, VECTOR_TYPE p1) {
\
-return __builtin_elementwise_##FUNC_NAME((VECTOR_TYPE)p0, p1); 
\
-  }
-
-#define IF_TRUE_0(EXPR)
-#define IF_TRUE_1(EXPR) EXPR
-
 
//===--===//
 // abs builtins
 
//===--===//
@@ -1563,7 +1543,6 @@ half3 max(half3, half3);
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 half4 max(half4, half4);
-GEN_VEC_SCALAR_OVERLOADS(max, half, 1)
 
 #ifdef __HLSL_ENABLE_16_BIT
 _HLSL_AVAILABILITY(shadermodel, 6.2)
@@ -1578,7 +1557,6 @@ int16_t3 max(int16_t3, int16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int16_t4 max(int16_t4, int16_t4);
-GEN_VEC_SCALAR_OVERLOADS(max, int16_t, 1)
 
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
@@ -1592,7 +1570,6 @@ uint16_t3 max(uint16_t3, uint16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint16_t4 max(uint16_t4, uint16_t4);
-GEN_VEC_SCALAR_OVERLOADS(max, uint16_t, 1)
 #endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
@@ -1603,7 +1580,6 @@ _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int3 max(int3, int3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int4 max(int4, int4);
-GEN_VEC_SCALAR_OVERLOADS(max, int, 0)
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint max(uint, uint);
@@ -1613,7 +1589,6 @@ _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint3 max(uint3, uint3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint4 max(uint4, uint4);
-GEN_VEC_SCALAR_OVERLOADS(max, uint, 0)
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int64_t max(int64_t, int64_t);
@@ -1623,7 +1598,6 @@ _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int64_t3 max(int64_t3, int64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int64_t4 max(int64_t4, int64_t4);
-GEN_VEC_SCALAR_OVERLOADS(max, int64_t, 0)
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint64_t max(uint64_t, uint64_t);
@@ -1633,7 +1607,6 @@ _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint64_t3 max(uint64_t3, uint64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint64_t4 max(uint64_t4, uint64_t4);
-GEN_VEC_SCALAR_OVERLOADS(max, uint64_t, 0)
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 float max(float, float);
@@ -1643,7 +1616,6 @@ _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 float3 max(float3, float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 float4 max(float4, float4);
-GEN_VEC_SCALAR_OVERLOADS(max, float, 0)
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwis

[clang] [clang] Fix array types comparison in getCommonSugaredType (PR #131649)

2025-03-19 Thread Serge Pavlov via cfe-commits

https://github.com/spavloff updated 
https://github.com/llvm/llvm-project/pull/131649

>From cdf9f1a5b960d2561a7c4415313b397578de0f8b Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Mon, 17 Mar 2025 21:33:24 +0700
Subject: [PATCH 1/2] [clang] Fix array types comparison in
 getCommonSugaredType

Const-qualification of an array caused by constexpr specifier can
produce QualType, where the const qualifier is set both as fast
qualifier and as a qualifier of the array element type. It can result in
a compiler crash, because such QualType does not compare equal to the
same type but without extra qualification.

To avoid the crash, the redundant qualifiers are removed while searching
for common sugar.

It fixes https://github.com/llvm/llvm-project/issues/97005 (Clang
crashed in ASTContext::getCommonSugaredType).
---
 clang/lib/AST/ASTContext.cpp  |  9 +
 clang/test/SemaCXX/constexpr-implicit-const-97005.cpp | 10 ++
 2 files changed, 19 insertions(+)
 create mode 100644 clang/test/SemaCXX/constexpr-implicit-const-97005.cpp

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7ed5b033d9bd8..2614c4235c994 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14171,6 +14171,15 @@ static QualType getCommonSugarTypeNode(ASTContext 
&Ctx, const Type *X,
 static auto unwrapSugar(SplitQualType &T, Qualifiers &QTotal) {
   SmallVector R;
   while (true) {
+if (const auto *ATy = dyn_cast(T.Ty)) {
+  // C++ 9.3.3.4p3: Any type of the form "cv-qualifier-seq array of N U" is
+  // adjusted to "array of N cv-qualifier-seq U".
+  // C23 6.7.3p10: If the specification of an array type includes any type
+  // qualifiers, both the array and the element type are so-qualified.
+  //
+  // To simplify comparison remove the redundant qualifiers from the array.
+  T.Quals.removeCVRQualifiers(Qualifiers::Const | Qualifiers::Volatile);
+}
 QTotal.addConsistentQualifiers(T.Quals);
 QualType NT = T.Ty->getLocallyUnqualifiedSingleStepDesugaredType();
 if (NT == QualType(T.Ty, 0))
diff --git a/clang/test/SemaCXX/constexpr-implicit-const-97005.cpp 
b/clang/test/SemaCXX/constexpr-implicit-const-97005.cpp
new file mode 100644
index 0..db6106998d02b
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-implicit-const-97005.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s
+
+bool a;
+constexpr const unsigned char c[] = { 5 };
+constexpr const unsigned char d[1] = { 0 };
+auto b = (a ? d : c);
+
+constexpr const unsigned char c1[][1] = {{ 5 }};
+constexpr const unsigned char d1[1][1] = {{ 0 }};
+auto b1 = (a ? d1 : c1);

>From 9bc13aee5775af148941826b74e5c9fbaab907c7 Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Wed, 19 Mar 2025 23:50:19 +0700
Subject: [PATCH 2/2] Address review comments

- Now only qualifiers that are found in array element are cleared,
- Test are moved into a new location.
---
 clang/lib/AST/ASTContext.cpp  | 39 ++-
 .../constexpr-implicit-const-97005.cpp| 10 -
 clang/test/SemaCXX/sugar-common-types.cpp | 10 +
 3 files changed, 40 insertions(+), 19 deletions(-)
 delete mode 100644 clang/test/SemaCXX/constexpr-implicit-const-97005.cpp

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 2614c4235c994..28f43321622e9 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14168,18 +14168,39 @@ static QualType getCommonSugarTypeNode(ASTContext 
&Ctx, const Type *X,
   llvm_unreachable("Unhandled Type Class");
 }
 
+/// Returns element type of the array, probably multidimensional, specified by
+/// the given ArrayType.
+/// \returns Canonical type of the array element.
+static QualType getNonArrayElementType(const ArrayType* ATy) {
+  QualType ElTy = ATy->getElementType().getCanonicalType();
+  while (auto *SubArr = dyn_cast(ElTy.getTypePtr()))
+ElTy = SubArr->getElementType();
+  return ElTy;
+}
+
+/// Given a qualified type, returns an equivalent type, which has cv-qualifiers
+/// only at array element type.
+static SplitQualType normalizeArrayQualifiers(const SplitQualType &T) {
+  if (const auto *ATy = dyn_cast(T.Ty)) {
+// C++ 9.3.3.4p3: Any type of the form "cv-qualifier-seq array of N U" is
+// adjusted to "array of N cv-qualifier-seq U".
+// C23 6.7.3p10: If the specification of an array type includes any type
+// qualifiers, both the array and the element type are so-qualified.
+//
+// If cv-qualifier is present in both array and element type, remove the
+// redundant qualifiers from the array.
+QualType ElTy = getNonArrayElementType(ATy);
+unsigned Quals =
+ElTy.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile);
+return SplitQualType(ATy, Qualifiers::fromCVRMask(Quals));
+  }
+  return T;
+}
+
 static auto unwrapSugar(SplitQualType &T, Qualifiers &QTotal) {
   SmallVector R;
   while

[clang] [CIR] Upstream global initialization for ArrayType (PR #131657)

2025-03-19 Thread Erich Keane via cfe-commits

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

Happy when Andy is as well!

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


[clang] [clang] Fix array types comparison in getCommonSugaredType (PR #131649)

2025-03-19 Thread Serge Pavlov via cfe-commits


@@ -14171,6 +14171,15 @@ static QualType getCommonSugarTypeNode(ASTContext 
&Ctx, const Type *X,
 static auto unwrapSugar(SplitQualType &T, Qualifiers &QTotal) {
   SmallVector R;
   while (true) {
+if (const auto *ATy = dyn_cast(T.Ty)) {
+  // C++ 9.3.3.4p3: Any type of the form "cv-qualifier-seq array of N U" is
+  // adjusted to "array of N cv-qualifier-seq U".
+  // C23 6.7.3p10: If the specification of an array type includes any type
+  // qualifiers, both the array and the element type are so-qualified.
+  //
+  // To simplify comparison remove the redundant qualifiers from the array.
+  T.Quals.removeCVRQualifiers(Qualifiers::Const | Qualifiers::Volatile);

spavloff wrote:

In the updated version, only qualifiers found in element type are removed.

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


[clang] [CIR] Upstream a basic version of class LexicalScope (PR #131945)

2025-03-19 Thread Erich Keane via cfe-commits

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

Want those nits from my last patch fixed, but forgot to click the 'approve' 
button.

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


[clang] [HLSL] Implement min and max overloads using templates (PR #131666)

2025-03-19 Thread Sarah Spall via cfe-commits

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


[clang] [libc] [llvm] Reapply "[AMDGPU] Use COV6 by default (#118515)" (PR #130963)

2025-03-19 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/130963

>From 576596fb09e3f497858da0f922d746914a0c5c3d Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Wed, 12 Mar 2025 09:39:45 -0400
Subject: [PATCH] Reapply "[AMDGPU] Use COV6 by default (#118515)"

This reverts commit 68bcba6d7a1cc18996c0bcb7c62267c62d2040d0.
---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/include/clang/Driver/Options.td  | 4 ++--
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 +-
 clang/test/CodeGen/amdgpu-address-spaces.cpp   | 2 +-
 clang/test/CodeGenCUDA/amdgpu-code-object-version.cu   | 2 +-
 clang/test/CodeGenCXX/dynamic-cast-address-space.cpp   | 6 +++---
 clang/test/CodeGenHIP/default-attributes.hip   | 4 ++--
 clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl  | 6 +++---
 .../amdgcn/bitcode/oclc_abi_version_600.bc | 0
 .../lib/amdgcn/bitcode/oclc_abi_version_600.bc | 0
 .../lib64/amdgcn/bitcode/oclc_abi_version_600.bc   | 0
 clang/test/Driver/hip-device-libs.hip  | 2 +-
 clang/test/OpenMP/amdgcn_target_global_constructor.cpp | 4 ++--
 libc/cmake/modules/prepare_libc_gpu_build.cmake| 2 +-
 llvm/docs/ReleaseNotes.md  | 2 ++
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp| 2 +-
 .../CodeGen/AMDGPU/default_amdhsa_code_object_version.ll   | 7 +++
 17 files changed, 29 insertions(+), 18 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_600.bc
 create mode 100644 
clang/test/Driver/Inputs/rocm_resource_dir/lib/amdgcn/bitcode/oclc_abi_version_600.bc
 create mode 100644 
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_abi_version_600.bc
 create mode 100644 
llvm/test/CodeGen/AMDGPU/default_amdhsa_code_object_version.ll

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 666bbf22acc93..afb729c514108 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -372,6 +372,8 @@ Target Specific Changes
 AMDGPU Support
 ^^
 
+- Bump the default code object version to 6. ROCm 6.3 is required to run any 
program compiled with COV6.
+
 NVPTX Support
 ^^
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ee783f8b09c24..591cc0a3e13ee 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5162,12 +5162,12 @@ defm amdgpu_ieee : BoolMOption<"amdgpu-ieee",
   NegFlag>;
 
 def mcode_object_version_EQ : Joined<["-"], "mcode-object-version=">, 
Group,
-  HelpText<"Specify code object ABI version. Defaults to 5. (AMDGPU only)">,
+  HelpText<"Specify code object ABI version. Defaults to 6. (AMDGPU only)">,
   Visibility<[ClangOption, FlangOption, CC1Option, FC1Option]>,
   Values<"none,4,5,6">,
   NormalizedValuesScope<"llvm::CodeObjectVersionKind">,
   NormalizedValues<["COV_None", "COV_4", "COV_5", "COV_6"]>,
-  MarshallingInfoEnum, "COV_5">;
+  MarshallingInfoEnum, "COV_6">;
 
 defm cumode : SimpleMFlag<"cumode",
   "Specify CU wavefront", "Specify WGP wavefront",
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index bb553806d2eef..3075907365a60 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2757,7 +2757,7 @@ void tools::checkAMDGPUCodeObjectVersion(const Driver &D,
 
 unsigned tools::getAMDGPUCodeObjectVersion(const Driver &D,
const llvm::opt::ArgList &Args) {
-  unsigned CodeObjVer = 5; // default
+  unsigned CodeObjVer = 6; // default
   if (auto *CodeObjArg = getAMDGPUCodeObjectArgument(D, Args))
 StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
   return CodeObjVer;
diff --git a/clang/test/CodeGen/amdgpu-address-spaces.cpp 
b/clang/test/CodeGen/amdgpu-address-spaces.cpp
index ae2c61439f4ca..b121b559f58dc 100644
--- a/clang/test/CodeGen/amdgpu-address-spaces.cpp
+++ b/clang/test/CodeGen/amdgpu-address-spaces.cpp
@@ -29,7 +29,7 @@ int [[clang::address_space(999)]] bbb = 1234;
 // CHECK: @u = addrspace(5) global i32 undef, align 4
 // CHECK: @aaa = addrspace(6) global i32 1000, align 4
 // CHECK: @bbb = addrspace(999) global i32 1234, align 4
-// CHECK: @__oclc_ABI_version = weak_odr hidden local_unnamed_addr 
addrspace(4) constant i32 500
+// CHECK: @__oclc_ABI_version = weak_odr hidden local_unnamed_addr 
addrspace(4) constant i32 600
 //.
 // CHECK-LABEL: define dso_local amdgpu_kernel void @foo(
 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
diff --git a/clang/test/CodeGenCUDA/amdgpu-code-object-version.cu 
b/clang/test/CodeGenCUDA/amdgpu-code-object-version.cu
index ffe12544917f7..aa0e3edec3f6a 100644
--- a/clang/test/CodeGenCUDA/amdgpu-code-objec

[clang] [clang] Fix array types comparison in getCommonSugaredType (PR #131649)

2025-03-19 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 3f62718c4a907125af31faa62365bdf11ddef7b6 
9bc13aee5775af148941826b74e5c9fbaab907c7 --extensions cpp -- 
clang/lib/AST/ASTContext.cpp clang/test/SemaCXX/sugar-common-types.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 28f4332162..5429cdc704 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14171,7 +14171,7 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, 
const Type *X,
 /// Returns element type of the array, probably multidimensional, specified by
 /// the given ArrayType.
 /// \returns Canonical type of the array element.
-static QualType getNonArrayElementType(const ArrayType* ATy) {
+static QualType getNonArrayElementType(const ArrayType *ATy) {
   QualType ElTy = ATy->getElementType().getCanonicalType();
   while (auto *SubArr = dyn_cast(ElTy.getTypePtr()))
 ElTy = SubArr->getElementType();

``




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


[clang] [compiler-rt] [llvm] [PGO][Offload] Allow PGO flags to be used on GPU targets (PR #94268)

2025-03-19 Thread Ethan Luis McDonough via cfe-commits

https://github.com/EthanLuisMcDonough updated 
https://github.com/llvm/llvm-project/pull/94268

>From 3a2047c273d948d035b50eb486b772d5b3bdc401 Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough 
Date: Tue, 18 Mar 2025 16:20:14 -0500
Subject: [PATCH 1/5] [PGO][Offload] Allow PGO flags to be used on GPU targets

---
 clang/lib/Driver/ToolChains/Clang.cpp |  6 +-
 clang/test/Driver/cuda-no-pgo-or-coverage.cu  | 33 
 compiler-rt/include/profile/InstrProfData.inc |  2 +-
 compiler-rt/lib/profile/InstrProfiling.h  |  3 +-
 .../lib/profile/InstrProfilingBuffer.c|  3 +-
 compiler-rt/lib/profile/InstrProfilingFile.c  | 22 +++--
 .../lib/profile/InstrProfilingInternal.h  |  3 +-
 .../lib/profile/InstrProfilingWriter.c| 20 ++---
 .../llvm/ProfileData/InstrProfData.inc|  2 +-
 .../Instrumentation/PGOInstrumentation.cpp|  5 +-
 .../llvm-profdata/binary-ids-padding.test |  2 +-
 ...alformed-not-space-for-another-header.test |  2 +-
 .../malformed-num-counters-zero.test  |  2 +-
 .../malformed-ptr-to-counter-array.test   |  2 +-
 .../common/include/GlobalHandler.h|  6 +-
 .../common/src/GlobalHandler.cpp  | 18 +++-
 offload/test/offloading/gpupgo/pgo1.c | 84 +++
 offload/test/offloading/gpupgo/pgo2.c | 76 +
 offload/test/offloading/pgo1.c| 66 ---
 19 files changed, 220 insertions(+), 137 deletions(-)
 delete mode 100644 clang/test/Driver/cuda-no-pgo-or-coverage.cu
 create mode 100644 offload/test/offloading/gpupgo/pgo1.c
 create mode 100644 offload/test/offloading/gpupgo/pgo2.c
 delete mode 100644 offload/test/offloading/pgo1.c

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1012128085c7a..e0f1206496486 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6387,11 +6387,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.AddLastArg(CmdArgs, options::OPT_fconvergent_functions,
   options::OPT_fno_convergent_functions);
 
-  // NVPTX/AMDGCN doesn't support PGO or coverage. There's no runtime support
-  // for sampling, overhead of call arc collection is way too high and there's
-  // no way to collect the output.
-  if (!Triple.isNVPTX() && !Triple.isAMDGCN())
-addPGOAndCoverageFlags(TC, C, JA, Output, Args, SanitizeArgs, CmdArgs);
+  addPGOAndCoverageFlags(TC, C, JA, Output, Args, SanitizeArgs, CmdArgs);
 
   Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
 
diff --git a/clang/test/Driver/cuda-no-pgo-or-coverage.cu 
b/clang/test/Driver/cuda-no-pgo-or-coverage.cu
deleted file mode 100644
index b84587e1e182b..0
--- a/clang/test/Driver/cuda-no-pgo-or-coverage.cu
+++ /dev/null
@@ -1,33 +0,0 @@
-// Check that profiling/coverage arguments doen't get passed down to 
device-side
-// compilation.
-//
-//
-// XRUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
-// XRUN:   -fprofile-generate %s 2>&1 | \
-// XRUN:   FileCheck --check-prefixes=CHECK,PROF %s
-//
-// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
-// RUN:   -fprofile-instr-generate %s 2>&1 | \
-// RUN:   FileCheck --check-prefixes=CHECK,PROF %s
-//
-// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
-// RUN:   -coverage %s 2>&1 | \
-// RUN:   FileCheck --check-prefixes=CHECK,GCOV %s
-//
-// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
-// RUN:   -ftest-coverage %s 2>&1 | \
-// RUN:   FileCheck --check-prefixes=CHECK,GCOV %s
-//
-// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20   \
-// RUN:   -fprofile-instr-generate -fcoverage-mapping %s 2>&1 | \
-// RUN:   FileCheck --check-prefixes=CHECK,PROF %s
-//
-//
-// CHECK-NOT: error: unsupported option '-fprofile
-// CHECK-NOT: error: invalid argument
-// CHECK-DAG: "-fcuda-is-device"
-// CHECK-NOT: "-f{{[^"/]*coverage.*}}"
-// CHECK-NOT: "-fprofile{{[^"]*}}"
-// CHECK: "-triple" "x86_64-unknown-linux-gnu"
-// PROF:  "-fprofile{{.*}}"
-// GCOV:  "-coverage-notes-file=
diff --git a/compiler-rt/include/profile/InstrProfData.inc 
b/compiler-rt/include/profile/InstrProfData.inc
index 2cdfea9a579a4..d51b58386f168 100644
--- a/compiler-rt/include/profile/InstrProfData.inc
+++ b/compiler-rt/include/profile/InstrProfData.inc
@@ -152,7 +152,7 @@ INSTR_PROF_VALUE_NODE(PtrToNodeT, 
llvm::PointerType::getUnqual(Ctx), Next, \
 #define INSTR_PROF_DATA_DEFINED
 #endif
 INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
-INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
+INSTR_PROF_RAW_HEADER(uint64_t, Version, Version)
 INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
 INSTR_PROF_RAW_HEADER(uint64_t, NumData, NumData)
 INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesBeforeCounters, 
PaddingBytesBeforeCounters)
diff 

[clang] [clang][modules] Fix filesystem races in `ModuleManager` (PR #131354)

2025-03-19 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/131354

>From 7e5de89fa20b9fe7c07ab0d05a5caaec3ac31255 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Mon, 17 Mar 2025 08:11:52 -0700
Subject: [PATCH 1/2] [clang][modules] Fix filesystem races in `ModuleManager`

The `ModuleManager` uses `FileEntry` objects to uniquely identify module files. 
This requires first consulting the `FileManager` (and therefore the file 
system) when loading PCM files. This is problematic, as this may load a 
different PCM file to what's already in the `InMemoryModuleCache` and fail the 
size and mtime checks.

This PR changes things so that module files are identified by their file system 
path. This removes the need of knowing the file entry at the start and allows 
us to fix the race. The downside is that we no longer get the `FileManager` 
inode-based uniquing, meaning symlinks in the module cache no longer work. I 
think this is fine, since Clang itself never creates symlinks in that 
directory. Moreover, we already had to work around filesystems recycling inode 
numbers, so this actually seems like a win to me (and resolves a long-standing 
FIXME-like comment).

Note that this change also requires that all places calling into 
`ModuleManager` from within a single `CompilerInstance` use consistent paths to 
refer to module files. This might be problematic if there are concurrent Clang 
processes operating on the same module cache directory but with different 
spellings - the `IMPORT` records in PCM files will be valid and consistent 
within single process, but may break uniquing in another process. We might need 
to do some canonicalization of the module cache paths to avoid this issue.
---
 .../clang/Serialization/ModuleManager.h   |  25 +--
 clang/lib/Serialization/ModuleManager.cpp | 165 ++
 2 files changed, 60 insertions(+), 130 deletions(-)

diff --git a/clang/include/clang/Serialization/ModuleManager.h 
b/clang/include/clang/Serialization/ModuleManager.h
index 1eb74aee9787c..84b0276428dbf 100644
--- a/clang/include/clang/Serialization/ModuleManager.h
+++ b/clang/include/clang/Serialization/ModuleManager.h
@@ -22,6 +22,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator.h"
 #include "llvm/ADT/iterator_range.h"
@@ -58,7 +59,7 @@ class ModuleManager {
   SmallVector Roots;
 
   /// All loaded modules, indexed by name.
-  llvm::DenseMap Modules;
+  llvm::StringMap Modules;
 
   /// FileManager that handles translating between filenames and
   /// FileEntry *.
@@ -179,7 +180,7 @@ class ModuleManager {
   ModuleFile *lookupByModuleName(StringRef ModName) const;
 
   /// Returns the module associated with the given module file.
-  ModuleFile *lookup(const FileEntry *File) const;
+  ModuleFile *lookup(FileEntryRef File) const;
 
   /// Returns the in-memory (virtual file) buffer with the given name
   std::unique_ptr lookupBuffer(StringRef Name);
@@ -283,26 +284,6 @@ class ModuleManager {
   void visit(llvm::function_ref Visitor,
  llvm::SmallPtrSetImpl *ModuleFilesHit = nullptr);
 
-  /// Attempt to resolve the given module file name to a file entry.
-  ///
-  /// \param FileName The name of the module file.
-  ///
-  /// \param ExpectedSize The size that the module file is expected to have.
-  /// If the actual size differs, the resolver should return \c true.
-  ///
-  /// \param ExpectedModTime The modification time that the module file is
-  /// expected to have. If the actual modification time differs, the resolver
-  /// should return \c true.
-  ///
-  /// \param File Will be set to the file if there is one, or null
-  /// otherwise.
-  ///
-  /// \returns True if a file exists but does not meet the size/
-  /// modification time criteria, false if the file is either available and
-  /// suitable, or is missing.
-  bool lookupModuleFile(StringRef FileName, off_t ExpectedSize,
-time_t ExpectedModTime, OptionalFileEntryRef &File);
-
   /// View the graphviz representation of the module graph.
   void viewGraph();
 
diff --git a/clang/lib/Serialization/ModuleManager.cpp 
b/clang/lib/Serialization/ModuleManager.cpp
index 61c4e9ed88e9d..4fb23f92463ac 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -59,8 +59,8 @@ ModuleFile *ModuleManager::lookupByModuleName(StringRef Name) 
const {
   return nullptr;
 }
 
-ModuleFile *ModuleManager::lookup(const FileEntry *File) const {
-  return Modules.lookup(File);
+ModuleFile *ModuleManager::lookup(FileEntryRef File) const {
+  return Modules.lookup(File.getName());
 }
 
 std::unique_ptr
@@ -107,109 +107,51 @@ ModuleManager::addModule(StringRef FileName, ModuleKind 
Type,
  std::string &ErrorStr) {
   Module = nullptr;
 
-  // Look for the file entry. This only f

[clang] [clang] Fix array types comparison in getCommonSugaredType (PR #131649)

2025-03-19 Thread Serge Pavlov via cfe-commits


@@ -14171,6 +14171,15 @@ static QualType getCommonSugarTypeNode(ASTContext 
&Ctx, const Type *X,
 static auto unwrapSugar(SplitQualType &T, Qualifiers &QTotal) {
   SmallVector R;
   while (true) {
+if (const auto *ATy = dyn_cast(T.Ty)) {
+  // C++ 9.3.3.4p3: Any type of the form "cv-qualifier-seq array of N U" is
+  // adjusted to "array of N cv-qualifier-seq U".
+  // C23 6.7.3p10: If the specification of an array type includes any type
+  // qualifiers, both the array and the element type are so-qualified.
+  //
+  // To simplify comparison remove the redundant qualifiers from the array.
+  T.Quals.removeCVRQualifiers(Qualifiers::Const | Qualifiers::Volatile);

spavloff wrote:

This change makes sense, it can fix te case of "array of arry", but it cannot 
fix the case from https://github.com/llvm/llvm-project/issues/97005:
```
bool a;
constexpr const unsigned char c[] = { 5 };
constexpr const unsigned char d[1] = { 0 };
auto b = (a ? d : c);
```
Here types of `d` and `d` do not contain sugar, corresponding canonical types 
are identical, `getCommonNonSugarTypeNode` is not called and 
`getCommonArrayElementType` is not called. However their types are not equal 
and `assert(QX == QY)` fails.

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


[clang] [Clang] Fix various bugs in alias CTAD transform (PR #132061)

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

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/132061

(I'll add more details to the description tomorrow)

Fixes #123591
Fixes #127539
Fixes #129077
Fixes #129998

>From fb9fa67da10a7dbfb2db5520d2773085585f4c14 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Thu, 20 Mar 2025 00:54:54 +0800
Subject: [PATCH] [Clang] Fix various bugs in alias CTAD transform

---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp |  11 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  31 +++--
 clang/lib/Sema/TreeTransform.h|   6 +
 clang/test/SemaCXX/ctad.cpp   | 115 +-
 4 files changed, 149 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index ee89ee8594bc4..63a100545b5e7 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -1077,7 +1077,11 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
   // !!NOTE: DeduceResults respects the sequence of template parameters of
   // the deduction guide f.
   for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
-if (const auto &D = DeduceResults[Index]; !D.isNull()) // Deduced
+const auto &D = DeduceResults[Index];
+bool NonDeduced =
+D.isNull() || (D.getKind() == TemplateArgument::Pack &&
+   D.pack_size() == 1 && D.pack_begin()->isNull());
+if (!NonDeduced)
   DeducedArgs.push_back(D);
 else
   NonDeducedTemplateParamsInFIndex.push_back(Index);
@@ -1141,7 +1145,10 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
   Args.addOuterTemplateArguments(TransformedDeducedAliasArgs);
   for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
 const auto &D = DeduceResults[Index];
-if (D.isNull()) {
+bool NonDeduced =
+D.isNull() || (D.getKind() == TemplateArgument::Pack &&
+   D.pack_size() == 1 && D.pack_begin()->isNull());
+if (NonDeduced) {
   // 2): Non-deduced template parameters would be substituted later.
   continue;
 }
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 19c27a76b182c..9371b578c8558 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1348,6 +1348,16 @@ std::optional 
Sema::isSFINAEContext() const {
   return std::nullopt;
 }
 
+static TemplateArgument
+getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) {
+  assert(S.ArgumentPackSubstitutionIndex >= 0);
+  assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size());
+  Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex];
+  if (Arg.isPackExpansion())
+Arg = Arg.getPackExpansionPattern();
+  return Arg;
+}
+
 //===--===/
 // Template Instantiation for Types
 //===--===/
@@ -1467,10 +1477,16 @@ namespace {
   }
 }
 
-static TemplateArgument
+bool HeuristicallyComputeSizeOfPackExpr() const {
+  return !TemplateArgs.isRewrite();
+}
+
+TemplateArgument
 getTemplateArgumentPackPatternForRewrite(const TemplateArgument &TA) {
   if (TA.getKind() != TemplateArgument::Pack)
 return TA;
+  if (SemaRef.ArgumentPackSubstitutionIndex != -1)
+return getPackSubstitutedTemplateArgument(SemaRef, TA);
   assert(TA.pack_size() == 1 &&
  "unexpected pack arguments in template rewrite");
   TemplateArgument Arg = *TA.pack_begin();
@@ -1630,6 +1646,9 @@ namespace {
   std::vector TArgs;
   switch (Arg.getKind()) {
   case TemplateArgument::Pack:
+assert(SemaRef.CodeSynthesisContexts.empty() ||
+   SemaRef.CodeSynthesisContexts.back().Kind ==
+   Sema::CodeSynthesisContext::BuildingDeductionGuides);
 // Literally rewrite the template argument pack, instead of unpacking
 // it.
 for (auto &pack : Arg.getPackAsArray()) {
@@ -1869,16 +1888,6 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   return true;
 }
 
-static TemplateArgument
-getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) {
-  assert(S.ArgumentPackSubstitutionIndex >= 0);
-  assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size());
-  Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex];
-  if (Arg.isPackExpansion())
-Arg = Arg.getPackExpansionPattern();
-  return Arg;
-}
-
 Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
   if (!D)
 return nullptr;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index b5de98e3989ea..5d96c3fcf92e3 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -3660,6 +3660,8 @@ class TreeTransform {
 return SemaRef.BuildCXXNoexceptExpr(Range.getBeg

[clang] [Clang] Fix various bugs in alias CTAD transform (PR #132061)

2025-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

(I'll add more details to the description tomorrow)

Fixes #123591
Fixes #127539
Fixes #129077
Fixes #129998

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


4 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateDeductionGuide.cpp (+9-2) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+20-11) 
- (modified) clang/lib/Sema/TreeTransform.h (+6) 
- (modified) clang/test/SemaCXX/ctad.cpp (+114-1) 


``diff
diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index ee89ee8594bc4..63a100545b5e7 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -1077,7 +1077,11 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
   // !!NOTE: DeduceResults respects the sequence of template parameters of
   // the deduction guide f.
   for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
-if (const auto &D = DeduceResults[Index]; !D.isNull()) // Deduced
+const auto &D = DeduceResults[Index];
+bool NonDeduced =
+D.isNull() || (D.getKind() == TemplateArgument::Pack &&
+   D.pack_size() == 1 && D.pack_begin()->isNull());
+if (!NonDeduced)
   DeducedArgs.push_back(D);
 else
   NonDeducedTemplateParamsInFIndex.push_back(Index);
@@ -1141,7 +1145,10 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
   Args.addOuterTemplateArguments(TransformedDeducedAliasArgs);
   for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
 const auto &D = DeduceResults[Index];
-if (D.isNull()) {
+bool NonDeduced =
+D.isNull() || (D.getKind() == TemplateArgument::Pack &&
+   D.pack_size() == 1 && D.pack_begin()->isNull());
+if (NonDeduced) {
   // 2): Non-deduced template parameters would be substituted later.
   continue;
 }
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 19c27a76b182c..9371b578c8558 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1348,6 +1348,16 @@ std::optional 
Sema::isSFINAEContext() const {
   return std::nullopt;
 }
 
+static TemplateArgument
+getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) {
+  assert(S.ArgumentPackSubstitutionIndex >= 0);
+  assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size());
+  Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex];
+  if (Arg.isPackExpansion())
+Arg = Arg.getPackExpansionPattern();
+  return Arg;
+}
+
 //===--===/
 // Template Instantiation for Types
 //===--===/
@@ -1467,10 +1477,16 @@ namespace {
   }
 }
 
-static TemplateArgument
+bool HeuristicallyComputeSizeOfPackExpr() const {
+  return !TemplateArgs.isRewrite();
+}
+
+TemplateArgument
 getTemplateArgumentPackPatternForRewrite(const TemplateArgument &TA) {
   if (TA.getKind() != TemplateArgument::Pack)
 return TA;
+  if (SemaRef.ArgumentPackSubstitutionIndex != -1)
+return getPackSubstitutedTemplateArgument(SemaRef, TA);
   assert(TA.pack_size() == 1 &&
  "unexpected pack arguments in template rewrite");
   TemplateArgument Arg = *TA.pack_begin();
@@ -1630,6 +1646,9 @@ namespace {
   std::vector TArgs;
   switch (Arg.getKind()) {
   case TemplateArgument::Pack:
+assert(SemaRef.CodeSynthesisContexts.empty() ||
+   SemaRef.CodeSynthesisContexts.back().Kind ==
+   Sema::CodeSynthesisContext::BuildingDeductionGuides);
 // Literally rewrite the template argument pack, instead of unpacking
 // it.
 for (auto &pack : Arg.getPackAsArray()) {
@@ -1869,16 +1888,6 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   return true;
 }
 
-static TemplateArgument
-getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) {
-  assert(S.ArgumentPackSubstitutionIndex >= 0);
-  assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size());
-  Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex];
-  if (Arg.isPackExpansion())
-Arg = Arg.getPackExpansionPattern();
-  return Arg;
-}
-
 Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
   if (!D)
 return nullptr;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index b5de98e3989ea..5d96c3fcf92e3 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -3660,6 +3660,8 @@ class TreeTransform {
 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
   }
 
+  bool HeuristicallyComputeSizeOfPackExpr() const { return true; }
+
   /// Build a new expression to compute the len

[clang] 297f0b3 - [CudaSPIRV] Allow using integral non-type template parameters as attribute args (#131546)

2025-03-19 Thread via cfe-commits

Author: Alexander Shaposhnikov
Date: 2025-03-19T10:11:18-07:00
New Revision: 297f0b3f4c05c6ef40183809eac5ccac9ca8c4ce

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

LOG: [CudaSPIRV] Allow using integral non-type template parameters as attribute 
args (#131546)

Allow using integral non-type template parameters as attribute arguments
of
reqd_work_group_size and work_group_size_hint.

Test plan:
ninja check-all

Added: 
clang/test/SemaCUDA/spirv-attrs-diag.cu

Modified: 
clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.cpp
clang/include/clang/Basic/Attr.td
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/Targets/AMDGPU.cpp
clang/lib/CodeGen/Targets/TCE.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CodeGenCUDASPIRV/spirv-attrs.cu
clang/test/SemaCUDA/spirv-attrs.cu

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.cpp 
b/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.cpp
index df21c425ea956..c5da66a1f28b6 100644
--- a/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.cpp
@@ -54,8 +54,12 @@ void SingleWorkItemBarrierCheck::check(const 
MatchFinder::MatchResult &Result) {
 bool IsNDRange = false;
 if (MatchedDecl->hasAttr()) {
   const auto *Attribute = MatchedDecl->getAttr();
-  if (Attribute->getXDim() > 1 || Attribute->getYDim() > 1 ||
-  Attribute->getZDim() > 1)
+  auto Eval = [&](Expr *E) {
+return E->EvaluateKnownConstInt(MatchedDecl->getASTContext())
+.getExtValue();
+  };
+  if (Eval(Attribute->getXDim()) > 1 || Eval(Attribute->getYDim()) > 1 ||
+  Eval(Attribute->getZDim()) > 1)
 IsNDRange = true;
 }
 if (IsNDRange) // No warning if kernel is treated as an NDRange.

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index d9840dad6a5e2..b8cd3475bb88a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3044,8 +3044,7 @@ def NoDeref : TypeAttr {
 def ReqdWorkGroupSize : InheritableAttr {
   // Does not have a [[]] spelling because it is an OpenCL-related attribute.
   let Spellings = [GNU<"reqd_work_group_size">];
-  let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
-  UnsignedArgument<"ZDim">];
+  let Args = [ExprArgument<"XDim">, ExprArgument<"YDim">, 
ExprArgument<"ZDim">];
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [Undocumented];
 }
@@ -3053,9 +3052,7 @@ def ReqdWorkGroupSize : InheritableAttr {
 def WorkGroupSizeHint :  InheritableAttr {
   // Does not have a [[]] spelling because it is an OpenCL-related attribute.
   let Spellings = [GNU<"work_group_size_hint">];
-  let Args = [UnsignedArgument<"XDim">,
-  UnsignedArgument<"YDim">,
-  UnsignedArgument<"ZDim">];
+  let Args = [ExprArgument<"XDim">, ExprArgument<"YDim">, 
ExprArgument<"ZDim">];
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [Undocumented];
 }

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index a7fdfa6273dd4..dcf523f56bf1e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -649,18 +649,24 @@ void CodeGenFunction::EmitKernelMetadata(const 
FunctionDecl *FD,
   }
 
   if (const WorkGroupSizeHintAttr *A = FD->getAttr()) {
+auto Eval = [&](Expr *E) {
+  return E->EvaluateKnownConstInt(FD->getASTContext()).getExtValue();
+};
 llvm::Metadata *AttrMDArgs[] = {
-llvm::ConstantAsMetadata::get(Builder.getInt32(A->getXDim())),
-llvm::ConstantAsMetadata::get(Builder.getInt32(A->getYDim())),
-llvm::ConstantAsMetadata::get(Builder.getInt32(A->getZDim()))};
+llvm::ConstantAsMetadata::get(Builder.getInt32(Eval(A->getXDim(,
+llvm::ConstantAsMetadata::get(Builder.getInt32(Eval(A->getYDim(,
+llvm::ConstantAsMetadata::get(Builder.getInt32(Eval(A->getZDim(};
 Fn->setMetadata("work_group_size_hint", llvm::MDNode::get(Context, 
AttrMDArgs));
   }
 
   if (const ReqdWorkGroupSizeAttr *A = FD->getAttr()) {
+auto Eval = [&](Expr *E) {
+  return E->EvaluateKnownConstInt(FD->getASTContext()).getExtValue();
+};
 llvm::Metadata *AttrMDArgs[] = {
-llvm::ConstantAsMetadata::get(Builder.getInt32(A->getXDim())),
-llvm::ConstantAsMetadata::get(Builder.getInt32(A->getYDim())),
-llvm::ConstantAsMetadata::get(Builder.getInt32(A->getZDim()))};
+llvm::ConstantAsMetadata::get(Builder.getInt32(Eval(A->getXDim(,
+ 

[clang] [clang-tools-extra] [CudaSPIRV] Allow using integral non-type template parameters as attribute args (PR #131546)

2025-03-19 Thread Alexander Shaposhnikov via cfe-commits

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


[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)

2025-03-19 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Sorry for being late for the review. This is a major new feature of clang-tidy, 
so I believe it would be good to have an RFC before looking at the detailed 
implementation. What problem does it solve, why should clang-tidy solve it, 
what the API towards the user should be, etc. Should we do that?



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


[clang] [clang] Fix array types comparison in getCommonSugaredType (PR #131649)

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


@@ -14171,6 +14171,15 @@ static QualType getCommonSugarTypeNode(ASTContext 
&Ctx, const Type *X,
 static auto unwrapSugar(SplitQualType &T, Qualifiers &QTotal) {
   SmallVector R;
   while (true) {
+if (const auto *ATy = dyn_cast(T.Ty)) {
+  // C++ 9.3.3.4p3: Any type of the form "cv-qualifier-seq array of N U" is
+  // adjusted to "array of N cv-qualifier-seq U".
+  // C23 6.7.3p10: If the specification of an array type includes any type
+  // qualifiers, both the array and the element type are so-qualified.
+  //
+  // To simplify comparison remove the redundant qualifiers from the array.
+  T.Quals.removeCVRQualifiers(Qualifiers::Const | Qualifiers::Volatile);

mizvekov wrote:

Alright, this needs more thought, but regardless, getCommonArrayElementType is 
the correct place to fix the problem.

We don't want to add special cases for ArrayTypes in unwrapSugar, because it's 
in the fast path, and most type nodes are not ArrayTypes, and most types don't 
even have ArrayTypes in them.

So this is why things are layered this way.

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


[clang] [clang] Remove deprecated `FileManager` APIs (PR #132063)

2025-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)


Changes

This PR removes the `FileManager` APIs that have been deprecated for a while.

LLVM 20.1.0 that was released earlier this month contains the formal 
deprecation of these APIs, so these should be fine to remove in the next major 
release.

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


2 Files Affected:

- (modified) clang/include/clang/Basic/FileManager.h (-37) 
- (modified) clang/lib/Basic/FileManager.cpp (-16) 


``diff
diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 6cc6c2bfd2b6b..e83a61d6ff00c 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -177,43 +177,6 @@ class FileManager : public RefCountedBase {
 return llvm::expectedToOptional(getDirectoryRef(DirName, CacheFailure));
   }
 
-  /// Lookup, cache, and verify the specified directory (real or
-  /// virtual).
-  ///
-  /// This function is deprecated and will be removed at some point in the
-  /// future, new clients should use
-  ///  \c getDirectoryRef.
-  ///
-  /// This returns a \c std::error_code if there was an error reading the
-  /// directory. If there is no error, the DirectoryEntry is guaranteed to be
-  /// non-NULL.
-  ///
-  /// \param CacheFailure If true and the file does not exist, we'll cache
-  /// the failure to find this file.
-  LLVM_DEPRECATED("Functions returning DirectoryEntry are deprecated.",
-  "getOptionalDirectoryRef()")
-  llvm::ErrorOr
-  getDirectory(StringRef DirName, bool CacheFailure = true);
-
-  /// Lookup, cache, and verify the specified file (real or
-  /// virtual).
-  ///
-  /// This function is deprecated and will be removed at some point in the
-  /// future, new clients should use
-  ///  \c getFileRef.
-  ///
-  /// This returns a \c std::error_code if there was an error loading the file.
-  /// If there is no error, the FileEntry is guaranteed to be non-NULL.
-  ///
-  /// \param OpenFile if true and the file exists, it will be opened.
-  ///
-  /// \param CacheFailure If true and the file does not exist, we'll cache
-  /// the failure to find this file.
-  LLVM_DEPRECATED("Functions returning FileEntry are deprecated.",
-  "getOptionalFileRef()")
-  llvm::ErrorOr
-  getFile(StringRef Filename, bool OpenFile = false, bool CacheFailure = true);
-
   /// Lookup, cache, and verify the specified file (real or virtual). Return 
the
   /// reference to the file entry together with the exact path that was used to
   /// access a file by a particular call to getFileRef. If the underlying VFS 
is
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index f0b6f7be6c84f..ec84aad72e6be 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -196,22 +196,6 @@ FileManager::getDirectoryRef(StringRef DirName, bool 
CacheFailure) {
   return DirectoryEntryRef(NamedDirEnt);
 }
 
-llvm::ErrorOr
-FileManager::getDirectory(StringRef DirName, bool CacheFailure) {
-  auto Result = getDirectoryRef(DirName, CacheFailure);
-  if (Result)
-return &Result->getDirEntry();
-  return llvm::errorToErrorCode(Result.takeError());
-}
-
-llvm::ErrorOr
-FileManager::getFile(StringRef Filename, bool openFile, bool CacheFailure) {
-  auto Result = getFileRef(Filename, openFile, CacheFailure);
-  if (Result)
-return &Result->getFileEntry();
-  return llvm::errorToErrorCode(Result.takeError());
-}
-
 llvm::Expected FileManager::getFileRef(StringRef Filename,
  bool openFile,
  bool CacheFailure,

``




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


[clang] [clang] Remove deprecated `FileManager` APIs (PR #132063)

2025-03-19 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 created 
https://github.com/llvm/llvm-project/pull/132063

This PR removes the `FileManager` APIs that have been deprecated for a while.

LLVM 20.1.0 that was released earlier this month contains the formal 
deprecation of these APIs, so these should be fine to remove in the next major 
release.

>From b6faf42be60acc164f8e0c98bc7c41ab7524c94b Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Wed, 19 Mar 2025 10:14:17 -0700
Subject: [PATCH] [clang] Remove deprecated `FileManager` APIs

This PR removes the `FileManager` APIs that have been deprecated for a while.

LLVM 20.1.0 that was released earlier this month contains the formal 
deprecation of these APIs, so these should be fine to remove in the next major 
release.
---
 clang/include/clang/Basic/FileManager.h | 37 -
 clang/lib/Basic/FileManager.cpp | 16 ---
 2 files changed, 53 deletions(-)

diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 6cc6c2bfd2b6b..e83a61d6ff00c 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -177,43 +177,6 @@ class FileManager : public RefCountedBase {
 return llvm::expectedToOptional(getDirectoryRef(DirName, CacheFailure));
   }
 
-  /// Lookup, cache, and verify the specified directory (real or
-  /// virtual).
-  ///
-  /// This function is deprecated and will be removed at some point in the
-  /// future, new clients should use
-  ///  \c getDirectoryRef.
-  ///
-  /// This returns a \c std::error_code if there was an error reading the
-  /// directory. If there is no error, the DirectoryEntry is guaranteed to be
-  /// non-NULL.
-  ///
-  /// \param CacheFailure If true and the file does not exist, we'll cache
-  /// the failure to find this file.
-  LLVM_DEPRECATED("Functions returning DirectoryEntry are deprecated.",
-  "getOptionalDirectoryRef()")
-  llvm::ErrorOr
-  getDirectory(StringRef DirName, bool CacheFailure = true);
-
-  /// Lookup, cache, and verify the specified file (real or
-  /// virtual).
-  ///
-  /// This function is deprecated and will be removed at some point in the
-  /// future, new clients should use
-  ///  \c getFileRef.
-  ///
-  /// This returns a \c std::error_code if there was an error loading the file.
-  /// If there is no error, the FileEntry is guaranteed to be non-NULL.
-  ///
-  /// \param OpenFile if true and the file exists, it will be opened.
-  ///
-  /// \param CacheFailure If true and the file does not exist, we'll cache
-  /// the failure to find this file.
-  LLVM_DEPRECATED("Functions returning FileEntry are deprecated.",
-  "getOptionalFileRef()")
-  llvm::ErrorOr
-  getFile(StringRef Filename, bool OpenFile = false, bool CacheFailure = true);
-
   /// Lookup, cache, and verify the specified file (real or virtual). Return 
the
   /// reference to the file entry together with the exact path that was used to
   /// access a file by a particular call to getFileRef. If the underlying VFS 
is
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index f0b6f7be6c84f..ec84aad72e6be 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -196,22 +196,6 @@ FileManager::getDirectoryRef(StringRef DirName, bool 
CacheFailure) {
   return DirectoryEntryRef(NamedDirEnt);
 }
 
-llvm::ErrorOr
-FileManager::getDirectory(StringRef DirName, bool CacheFailure) {
-  auto Result = getDirectoryRef(DirName, CacheFailure);
-  if (Result)
-return &Result->getDirEntry();
-  return llvm::errorToErrorCode(Result.takeError());
-}
-
-llvm::ErrorOr
-FileManager::getFile(StringRef Filename, bool openFile, bool CacheFailure) {
-  auto Result = getFileRef(Filename, openFile, CacheFailure);
-  if (Result)
-return &Result->getFileEntry();
-  return llvm::errorToErrorCode(Result.takeError());
-}
-
 llvm::Expected FileManager::getFileRef(StringRef Filename,
  bool openFile,
  bool CacheFailure,

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


[clang] [Clang][NFC] Code cleanup in CGBuiltin.cpp (PR #132060)

2025-03-19 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/132060

- Use `Intrinsic::` directly instead of `llvm::Intrinsic::`.
- Eliminate redundant `nullptr` for some `CreateIntrinsic` calls.
- Eliminate redundant `ArrayRef` casts.
- Use C++17 structured binding instead of `std::tie`.

>From 17c36a35d4cb54773e808ca0876ba4f42265f379 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Wed, 19 Mar 2025 09:54:12 -0700
Subject: [PATCH] [Clang][NFC] Code cleanup in CGBuiltin.cpp

- Use `Intrinsic::` directly instead of `llvm::Intrinsic::`.
- Eliminate redundant `nullptr` for some `CreateIntrinsic` calls.
- Eliminate redundant `ArrayRef` casts.
- Use C++17 structured binding instead of `std::tie`.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 497 +++-
 1 file changed, 232 insertions(+), 265 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c126f88b9e3a5..3536bdd91ebc6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -113,13 +113,13 @@ static Value *handleHlslClip(const CallExpr *E, 
CodeGenFunction *CGF) {
 auto *FCompInst = CGF->Builder.CreateFCmpOLT(Op0, FZeroConst);
 CMP = CGF->Builder.CreateIntrinsic(
 CGF->Builder.getInt1Ty(), CGF->CGM.getHLSLRuntime().getAnyIntrinsic(),
-{FCompInst}, nullptr);
+{FCompInst});
   } else
 CMP = CGF->Builder.CreateFCmpOLT(Op0, FZeroConst);
 
   if (CGF->CGM.getTarget().getTriple().isDXIL())
-LastInstr = CGF->Builder.CreateIntrinsic(
-CGF->VoidTy, llvm::Intrinsic::dx_discard, {CMP}, nullptr);
+LastInstr =
+CGF->Builder.CreateIntrinsic(CGF->VoidTy, Intrinsic::dx_discard, 
{CMP});
   else if (CGF->CGM.getTarget().getTriple().isSPIRV()) {
 BasicBlock *LT0 = CGF->createBasicBlock("lt0", CGF->CurFn);
 BasicBlock *End = CGF->createBasicBlock("end", CGF->CurFn);
@@ -127,12 +127,9 @@ static Value *handleHlslClip(const CallExpr *E, 
CodeGenFunction *CGF) {
 CGF->Builder.CreateCondBr(CMP, LT0, End);
 
 CGF->Builder.SetInsertPoint(LT0);
-
-CGF->Builder.CreateIntrinsic(CGF->VoidTy, llvm::Intrinsic::spv_discard, {},
- nullptr);
+CGF->Builder.CreateIntrinsic(CGF->VoidTy, Intrinsic::spv_discard, {});
 
 LastInstr = CGF->Builder.CreateBr(End);
-
 CGF->Builder.SetInsertPoint(End);
   } else {
 llvm_unreachable("Backend Codegen not supported.");
@@ -228,7 +225,7 @@ static Value *handleAsDoubleBuiltin(CodeGenFunction &CGF, 
const CallExpr *E) {
   if (CGF.CGM.getTarget().getTriple().isDXIL())
 return CGF.Builder.CreateIntrinsic(
 /*ReturnType=*/ResultType, Intrinsic::dx_asdouble,
-ArrayRef{OpLowBits, OpHighBits}, nullptr, "hlsl.asdouble");
+{OpLowBits, OpHighBits}, nullptr, "hlsl.asdouble");
 
   if (!E->getArg(0)->getType()->isVectorType()) {
 OpLowBits = CGF.Builder.CreateVectorSplat(1, OpLowBits);
@@ -254,7 +251,7 @@ Value *readX18AsPtr(CodeGenFunction &CGF) {
   llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
   llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
   llvm::Function *F =
-  CGF.CGM.getIntrinsic(llvm::Intrinsic::read_register, {CGF.Int64Ty});
+  CGF.CGM.getIntrinsic(Intrinsic::read_register, {CGF.Int64Ty});
   llvm::Value *X18 = CGF.Builder.CreateCall(F, Metadata);
   return CGF.Builder.CreateIntToPtr(X18, CGF.Int8PtrTy);
 }
@@ -706,9 +703,10 @@ static Value 
*emitBinaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
 }
 
 // Has second type mangled argument.
-static Value *emitBinaryExpMaybeConstrainedFPBuiltin(
-CodeGenFunction &CGF, const CallExpr *E, llvm::Intrinsic::ID IntrinsicID,
-llvm::Intrinsic::ID ConstrainedIntrinsicID) {
+static Value *
+emitBinaryExpMaybeConstrainedFPBuiltin(CodeGenFunction &CGF, const CallExpr *E,
+   Intrinsic::ID IntrinsicID,
+   Intrinsic::ID ConstrainedIntrinsicID) {
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
@@ -810,7 +808,7 @@ emitMaybeConstrainedFPToIntRoundBuiltin(CodeGenFunction 
&CGF, const CallExpr *E,
 }
 
 static Value *emitFrexpBuiltin(CodeGenFunction &CGF, const CallExpr *E,
-   llvm::Intrinsic::ID IntrinsicID) {
+   Intrinsic::ID IntrinsicID) {
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
@@ -828,7 +826,7 @@ static Value *emitFrexpBuiltin(CodeGenFunction &CGF, const 
CallExpr *E,
 }
 
 static void emitSincosBuiltin(CodeGenFunction &CGF, const CallExpr *E,
-  llvm::Intrinsic::ID IntrinsicID) {
+  Intrinsic::ID IntrinsicID) {
   llvm::Value *Val = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Dest0 = CGF.EmitScalarExpr(E->getArg(1));
   llvm::Value *Dest1 = CGF.EmitScalarExpr(E->getArg(

[clang] [clang][modules] Correctly set module map systemness (PR #131940)

2025-03-19 Thread Ben Langmuir via cfe-commits

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


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


[clang] [compiler-rt] [llvm] [PGO][Offload] Allow PGO flags to be used on GPU targets (PR #94268)

2025-03-19 Thread Ethan Luis McDonough via cfe-commits


@@ -152,7 +152,7 @@ INSTR_PROF_VALUE_NODE(PtrToNodeT, 
llvm::PointerType::getUnqual(Ctx), Next, \
 #define INSTR_PROF_DATA_DEFINED
 #endif
 INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
-INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
+INSTR_PROF_RAW_HEADER(uint64_t, Version, Version)

EthanLuisMcDonough wrote:

I fixed the version detection and made sure to set the `Version` property the 
custom value instead of changing the default value.

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


[clang] [llvm] [MIPS] Add MIPS i6400 and i6500 processors (PR #130587)

2025-03-19 Thread Djordje Todorovic via cfe-commits

djtodoro wrote:

Lets wait another day or two, since someone may have additional comments. 
Thanks @mgoudar!

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


[clang] [llvm] [MIPS] Add MIPS i6400 and i6500 processors (PR #130587)

2025-03-19 Thread Djordje Todorovic via cfe-commits

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


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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)

2025-03-19 Thread David Tenty via cfe-commits

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


[clang] [Clang][Diagnostics] Update select uses in DiagnosticXKinds.td to use enum_select (PR #130868)

2025-03-19 Thread Ayokunle Amodu via cfe-commits

ayokunle321 wrote:

@erichkeane Hey! So I was able to change one, could you please take a look.

Also for this case:

Instruction:
%select{classdesign|coclass|dependency|helper"
  "|helperclass|helps|instancesize|ownership|performance|security|superclass}1

Use:
https://github.com/user-attachments/assets/4a2433f9-058c-482c-a452-1f89e2cbb0c0";
 />

I was wondering if it was okay for a replacement since the names of the 
CommandTraits options are the same


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


[clang] [compiler-rt] [llvm] [PGO][Offload] Allow PGO flags to be used on GPU targets (PR #94268)

2025-03-19 Thread Ethan Luis McDonough via cfe-commits

https://github.com/EthanLuisMcDonough updated 
https://github.com/llvm/llvm-project/pull/94268

>From 3a2047c273d948d035b50eb486b772d5b3bdc401 Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough 
Date: Tue, 18 Mar 2025 16:20:14 -0500
Subject: [PATCH 1/4] [PGO][Offload] Allow PGO flags to be used on GPU targets

---
 clang/lib/Driver/ToolChains/Clang.cpp |  6 +-
 clang/test/Driver/cuda-no-pgo-or-coverage.cu  | 33 
 compiler-rt/include/profile/InstrProfData.inc |  2 +-
 compiler-rt/lib/profile/InstrProfiling.h  |  3 +-
 .../lib/profile/InstrProfilingBuffer.c|  3 +-
 compiler-rt/lib/profile/InstrProfilingFile.c  | 22 +++--
 .../lib/profile/InstrProfilingInternal.h  |  3 +-
 .../lib/profile/InstrProfilingWriter.c| 20 ++---
 .../llvm/ProfileData/InstrProfData.inc|  2 +-
 .../Instrumentation/PGOInstrumentation.cpp|  5 +-
 .../llvm-profdata/binary-ids-padding.test |  2 +-
 ...alformed-not-space-for-another-header.test |  2 +-
 .../malformed-num-counters-zero.test  |  2 +-
 .../malformed-ptr-to-counter-array.test   |  2 +-
 .../common/include/GlobalHandler.h|  6 +-
 .../common/src/GlobalHandler.cpp  | 18 +++-
 offload/test/offloading/gpupgo/pgo1.c | 84 +++
 offload/test/offloading/gpupgo/pgo2.c | 76 +
 offload/test/offloading/pgo1.c| 66 ---
 19 files changed, 220 insertions(+), 137 deletions(-)
 delete mode 100644 clang/test/Driver/cuda-no-pgo-or-coverage.cu
 create mode 100644 offload/test/offloading/gpupgo/pgo1.c
 create mode 100644 offload/test/offloading/gpupgo/pgo2.c
 delete mode 100644 offload/test/offloading/pgo1.c

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1012128085c7a..e0f1206496486 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6387,11 +6387,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.AddLastArg(CmdArgs, options::OPT_fconvergent_functions,
   options::OPT_fno_convergent_functions);
 
-  // NVPTX/AMDGCN doesn't support PGO or coverage. There's no runtime support
-  // for sampling, overhead of call arc collection is way too high and there's
-  // no way to collect the output.
-  if (!Triple.isNVPTX() && !Triple.isAMDGCN())
-addPGOAndCoverageFlags(TC, C, JA, Output, Args, SanitizeArgs, CmdArgs);
+  addPGOAndCoverageFlags(TC, C, JA, Output, Args, SanitizeArgs, CmdArgs);
 
   Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
 
diff --git a/clang/test/Driver/cuda-no-pgo-or-coverage.cu 
b/clang/test/Driver/cuda-no-pgo-or-coverage.cu
deleted file mode 100644
index b84587e1e182b..0
--- a/clang/test/Driver/cuda-no-pgo-or-coverage.cu
+++ /dev/null
@@ -1,33 +0,0 @@
-// Check that profiling/coverage arguments doen't get passed down to 
device-side
-// compilation.
-//
-//
-// XRUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
-// XRUN:   -fprofile-generate %s 2>&1 | \
-// XRUN:   FileCheck --check-prefixes=CHECK,PROF %s
-//
-// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
-// RUN:   -fprofile-instr-generate %s 2>&1 | \
-// RUN:   FileCheck --check-prefixes=CHECK,PROF %s
-//
-// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
-// RUN:   -coverage %s 2>&1 | \
-// RUN:   FileCheck --check-prefixes=CHECK,GCOV %s
-//
-// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
-// RUN:   -ftest-coverage %s 2>&1 | \
-// RUN:   FileCheck --check-prefixes=CHECK,GCOV %s
-//
-// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20   \
-// RUN:   -fprofile-instr-generate -fcoverage-mapping %s 2>&1 | \
-// RUN:   FileCheck --check-prefixes=CHECK,PROF %s
-//
-//
-// CHECK-NOT: error: unsupported option '-fprofile
-// CHECK-NOT: error: invalid argument
-// CHECK-DAG: "-fcuda-is-device"
-// CHECK-NOT: "-f{{[^"/]*coverage.*}}"
-// CHECK-NOT: "-fprofile{{[^"]*}}"
-// CHECK: "-triple" "x86_64-unknown-linux-gnu"
-// PROF:  "-fprofile{{.*}}"
-// GCOV:  "-coverage-notes-file=
diff --git a/compiler-rt/include/profile/InstrProfData.inc 
b/compiler-rt/include/profile/InstrProfData.inc
index 2cdfea9a579a4..d51b58386f168 100644
--- a/compiler-rt/include/profile/InstrProfData.inc
+++ b/compiler-rt/include/profile/InstrProfData.inc
@@ -152,7 +152,7 @@ INSTR_PROF_VALUE_NODE(PtrToNodeT, 
llvm::PointerType::getUnqual(Ctx), Next, \
 #define INSTR_PROF_DATA_DEFINED
 #endif
 INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
-INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
+INSTR_PROF_RAW_HEADER(uint64_t, Version, Version)
 INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
 INSTR_PROF_RAW_HEADER(uint64_t, NumData, NumData)
 INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesBeforeCounters, 
PaddingBytesBeforeCounters)
diff 

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcilb (Long Branch) extension (PR #131996)

2025-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: quic_hchandel (hchandel)


Changes

This extension adds two long branch instructions.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.

Co-authored-by: Sudharsan Veeravalli 


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


12 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+1) 
- (modified) llvm/docs/RISCVUsage.rst (+3) 
- (modified) llvm/docs/ReleaseNotes.md (+2) 
- (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+16) 
- (modified) llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp (+4-4) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+8) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td (+40) 
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+4-3) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+2) 
- (added) llvm/test/MC/RISCV/xqcilb-invalid.s (+24) 
- (added) llvm/test/MC/RISCV/xqcilb-valid.s (+26) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+3-1) 


``diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 019106abfabc3..6ddb118004134 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -203,6 +203,7 @@
 // CHECK-NEXT: xqcics   0.2   'Xqcics' (Qualcomm uC 
Conditional Select Extension)
 // CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-NEXT: xqciint  0.4   'Xqciint' (Qualcomm uC 
Interrupts Extension)
+// CHECK-NEXT: xqcilb   0.2   'Xqcilb' (Qualcomm uC Long 
Branch Extension)
 // CHECK-NEXT: xqcili   0.2   'Xqcili' (Qualcomm uC Load 
Large Immediate Extension)
 // CHECK-NEXT: xqcilia  0.2   'Xqcilia' (Qualcomm uC Large 
Immediate Arithmetic Extension)
 // CHECK-NEXT: xqcilo   0.2   'Xqcilo' (Qualcomm uC Large 
Offset Load Store Extension)
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index cf7be8b2c5c96..2966c887caae2 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -459,6 +459,9 @@ The current vendor extensions supported are:
 ``experimental-Xqciint``
   LLVM implements `version 0.4 of the Qualcomm uC Interrupts extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 
+``experimental-Xqcilb``
+  LLVM implements `version 0.2 of the Qualcomm uC Long Branch extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
+
 ``experimental-Xqcili``
   LLVM implements `version 0.2 of the Qualcomm uC Load Large Immediate 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index b191a840d9803..8fb24cc850a55 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -114,6 +114,8 @@ Changes to the PowerPC Backend
 Changes to the RISC-V Backend
 -
 
+* Adds experimental assembler support for the Qualcomm uC 'Xqcilb` (Long 
Branch)
+  extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcili` (Load Large 
Immediate)
   extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcilia` (Large 
Immediate Arithmetic)
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 433e95d2bca19..a71594de4e8ca 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1132,6 +1132,17 @@ struct RISCVOperand final : public MCParsedAsmOperand {
VK == RISCVMCExpr::VK_None;
   }
 
+  bool isSImm32Lsb0() const {
+if (!isImm())
+  return false;
+RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_None;
+int64_t Imm;
+bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
+return IsConstantImm &&
+   isShiftedInt<31, 1>(fixImmediateForRV32(Imm, isRV64Imm())) &&
+   VK == RISCVMCExpr::VK_None;
+  }
+
   /// getStartLoc - Gets location of the first token of this operand
   SMLoc getStartLoc() const override { return StartLoc; }
   /// getEndLoc - Gets location of the last token of this operand
@@ -1765,6 +1776,11 @@ bool RISCVAsmParser:

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcilb (Long Branch) extension (PR #131996)

2025-03-19 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-mc

@llvm/pr-subscribers-clang

Author: quic_hchandel (hchandel)


Changes

This extension adds two long branch instructions.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.

Co-authored-by: Sudharsan Veeravalli 


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


12 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+1) 
- (modified) llvm/docs/RISCVUsage.rst (+3) 
- (modified) llvm/docs/ReleaseNotes.md (+2) 
- (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+16) 
- (modified) llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp (+4-4) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+8) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td (+40) 
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+4-3) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+2) 
- (added) llvm/test/MC/RISCV/xqcilb-invalid.s (+24) 
- (added) llvm/test/MC/RISCV/xqcilb-valid.s (+26) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+3-1) 


``diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 019106abfabc3..6ddb118004134 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -203,6 +203,7 @@
 // CHECK-NEXT: xqcics   0.2   'Xqcics' (Qualcomm uC 
Conditional Select Extension)
 // CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-NEXT: xqciint  0.4   'Xqciint' (Qualcomm uC 
Interrupts Extension)
+// CHECK-NEXT: xqcilb   0.2   'Xqcilb' (Qualcomm uC Long 
Branch Extension)
 // CHECK-NEXT: xqcili   0.2   'Xqcili' (Qualcomm uC Load 
Large Immediate Extension)
 // CHECK-NEXT: xqcilia  0.2   'Xqcilia' (Qualcomm uC Large 
Immediate Arithmetic Extension)
 // CHECK-NEXT: xqcilo   0.2   'Xqcilo' (Qualcomm uC Large 
Offset Load Store Extension)
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index cf7be8b2c5c96..2966c887caae2 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -459,6 +459,9 @@ The current vendor extensions supported are:
 ``experimental-Xqciint``
   LLVM implements `version 0.4 of the Qualcomm uC Interrupts extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 
+``experimental-Xqcilb``
+  LLVM implements `version 0.2 of the Qualcomm uC Long Branch extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
+
 ``experimental-Xqcili``
   LLVM implements `version 0.2 of the Qualcomm uC Load Large Immediate 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index b191a840d9803..8fb24cc850a55 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -114,6 +114,8 @@ Changes to the PowerPC Backend
 Changes to the RISC-V Backend
 -
 
+* Adds experimental assembler support for the Qualcomm uC 'Xqcilb` (Long 
Branch)
+  extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcili` (Load Large 
Immediate)
   extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcilia` (Large 
Immediate Arithmetic)
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 433e95d2bca19..a71594de4e8ca 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1132,6 +1132,17 @@ struct RISCVOperand final : public MCParsedAsmOperand {
VK == RISCVMCExpr::VK_None;
   }
 
+  bool isSImm32Lsb0() const {
+if (!isImm())
+  return false;
+RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_None;
+int64_t Imm;
+bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
+return IsConstantImm &&
+   isShiftedInt<31, 1>(fixImmediateForRV32(Imm, isRV64Imm())) &&
+   VK == RISCVMCExpr::VK_None;
+  }
+
   /// getStartLoc - Gets location of the first token of this operand
   SMLoc getStartLoc() const override { return StartLoc; }
   /// getEndLoc - Gets location of the last token of this operand
@@ -1765,6 +1776,11 @@ bool 

[clang] [clang] Introduce elementwise clz/ctz builtins (PR #131995)

2025-03-19 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/131995

These builtins are modeled on the clzg/ctzg builtins, which accept an optional 
second argument. This second argument is returned if the first argument is 0.

>From c0eef87f4301a9725b7d81e78875a816d3cdf7cb Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Mon, 3 Feb 2025 16:54:17 +
Subject: [PATCH] [clang] Introduce elementwise clz/ctz builtins

These builtins are modeled on the clzg/ctzg builtins, which accept an
optional second argument. This second argument is returned if the first
argument is 0.
---
 clang/docs/LanguageExtensions.rst |  8 ++
 clang/include/clang/Basic/Builtins.td | 12 +++
 clang/lib/CodeGen/CGBuiltin.cpp   | 18 ++--
 clang/lib/Sema/SemaChecking.cpp   | 13 +++
 .../test/CodeGen/builtins-elementwise-math.c  | 96 +++
 clang/test/Sema/builtins-elementwise-math.c   | 44 +
 6 files changed, 185 insertions(+), 6 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index d4771775c9739..f5d4ec49a1dd2 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -831,6 +831,14 @@ of different sizes and signs is forbidden in binary and 
ternary builtins.
 semantics, see `LangRef
 
`_
 for the comparison.
+ T __builtin_elementwise_clz(T x[, T y])return the number of leading 0 
bits in the first argument. If  integer types
+the first argument is 0 and an 
optional second argument is provided,
+the second argument is 
returned. If the first argument is 0 but only
+one argument is provided, the 
behaviour is undefined.
+ T __builtin_elementwise_ctz(T x[, T y])return the number of trailing 
0 bits in the first argument. If integer types
+the first argument is 0 and an 
optional second argument is provided,
+the second argument is 
returned. If the first argument is 0 but only
+one argument is provided, the 
behaviour is undefined.
 == 
== 
=
 
 
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 72a5e495c4059..0bc506d977186 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1484,6 +1484,18 @@ def ElementwiseSubSat : Builtin {
   let Prototype = "void(...)";
 }
 
+def ElementwiseClz : Builtin {
+  let Spellings = ["__builtin_elementwise_clz"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
+  let Prototype = "void(...)";
+}
+
+def ElementwiseCtz : Builtin {
+  let Spellings = ["__builtin_elementwise_ctz"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
+  let Prototype = "void(...)";
+}
+
 def ReduceMax : Builtin {
   let Spellings = ["__builtin_reduce_max"];
   let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c126f88b9e3a5..c48e1cf54f3f9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3673,9 +3673,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_ctz:
   case Builtin::BI__builtin_ctzl:
   case Builtin::BI__builtin_ctzll:
-  case Builtin::BI__builtin_ctzg: {
-bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_ctzg &&
-   E->getNumArgs() > 1;
+  case Builtin::BI__builtin_ctzg:
+  case Builtin::BI__builtin_elementwise_ctz: {
+bool HasFallback =
+(BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_ctzg ||
+ BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_elementwise_ctz) &&
+E->getNumArgs() > 1;
 
 Value *ArgValue =
 HasFallback ? EmitScalarExpr(E->getArg(0))
@@ -3705,9 +3708,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_clz:
   case Builtin::BI__builtin_clzl:
   case Builtin::BI__builtin_clzll:
-  case Builtin::BI__builtin_clzg: {
-bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_clzg &&
-   E->getNumArgs() > 1;
+  case Builtin::BI__builtin_clzg:
+  case Builtin::BI__builtin_elementwise_clz: {
+bool HasFallback =
+(BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_clzg ||
+

[clang] [llvm] [clang][DebugInfo] Add symbol for debugger with VTable information. (PR #130255)

2025-03-19 Thread Carlos Alberto Enciso via cfe-commits

CarlosAlbertoEnciso wrote:

As pointed out by @Michael137 

> If we're given the `_vtable$` artificial member, there's nothing useful we 
> can do with it right?
```
0x0042:   DW_TAG_variable
DW_AT_specification (0x005c "_vtable$")
DW_AT_alignment (8)
DW_AT_location  (DW_OP_addrx 0x1)
DW_AT_linkage_name  ("_ZTV8CDerived")

0x004c:   DW_TAG_structure_type ("CDerived")
...
0x005c: DW_TAG_variable
  DW_AT_name  ("_vtable$")
  DW_AT_type  (0x0041 "void *")
  DW_AT_external(true)
  DW_AT_declaration (true)
  DW_AT_artificial  (true)
  DW_AT_accessibility (DW_ACCESS_private)
  DW_AT_containing_type <0x0042>  --> VTable global variable
  ...

.debug_addr contents:
Addrs: [
0x
0x  <- DW_OP_addrx 0x1
0x
]
```
And taking a variation of what @tromey described, maybe we can add a 
`DW_AT_containing_type` pointing back to the global variable, providing 2 ways 
to use the new vtable information entry:
- Given the `_vtable$` artificial member: use the `DW_AT_containing_type` to 
find the vtable global variable.
- Given the vtable global variable: use the `DW_AT_specification` to find the 
object definition.


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


[clang] [clang] Do not infer lifetimebound for functions with void return type (PR #131997)

2025-03-19 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created 
https://github.com/llvm/llvm-project/pull/131997

None

>From 9220b14a8147850a39e2c9bdf1188f2135b7a0ae Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 19 Mar 2025 10:25:07 +
Subject: [PATCH] [clang] Do not infer lifetimebound for functions with void
 return type

---
 clang/lib/Sema/SemaAttr.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index defdda17c32de..a6e827a421134 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -217,7 +217,7 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
 }
 
 void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
-  if (FD->getNumParams() == 0)
+  if (FD->getNumParams() == 0 || FD->getReturnType()->isVoidType())
 return;
 
   if (unsigned BuiltinID = FD->getBuiltinID()) {

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


[clang] [clang] Do not infer lifetimebound for functions with void return type (PR #131997)

2025-03-19 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Do not infer lifetimebound for functions with void return type (PR #131997)

2025-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Utkarsh Saxena (usx95)


Changes



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


1 Files Affected:

- (modified) clang/lib/Sema/SemaAttr.cpp (+1-1) 


``diff
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index defdda17c32de..a6e827a421134 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -217,7 +217,7 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
 }
 
 void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
-  if (FD->getNumParams() == 0)
+  if (FD->getNumParams() == 0 || FD->getReturnType()->isVoidType())
 return;
 
   if (unsigned BuiltinID = FD->getBuiltinID()) {

``




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


[clang] [clang] Do not infer lifetimebound for functions with void return type (PR #131997)

2025-03-19 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/131997

>From 9220b14a8147850a39e2c9bdf1188f2135b7a0ae Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 19 Mar 2025 10:25:07 +
Subject: [PATCH] [clang] Do not infer lifetimebound for functions with void
 return type

---
 clang/lib/Sema/SemaAttr.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index defdda17c32de..a6e827a421134 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -217,7 +217,7 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
 }
 
 void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
-  if (FD->getNumParams() == 0)
+  if (FD->getNumParams() == 0 || FD->getReturnType()->isVoidType())
 return;
 
   if (unsigned BuiltinID = FD->getBuiltinID()) {

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


[clang] [llvm] [RISC-V] Add support for MIPS P8700 CPU (PR #117865)

2025-03-19 Thread Djordje Todorovic via cfe-commits

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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcilb (Long Branch) extension (PR #131996)

2025-03-19 Thread via cfe-commits

https://github.com/hchandel created 
https://github.com/llvm/llvm-project/pull/131996

This extension adds two long branch instructions.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.

Co-authored-by: Sudharsan Veeravalli 


>From e3f9548f1ccdf1bb85d0c540c7bdea6094019278 Mon Sep 17 00:00:00 2001
From: Harsh Chandel 
Date: Mon, 17 Mar 2025 17:29:09 +0530
Subject: [PATCH 1/4] [RISCV] Add Qualcomm uC Xqcilb (Long Branch) extension
 This extension adds two long branch instructions.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.

Change-Id: I262d59edc8c7266800badc82d6496619ce2aeabf
---
 .../Driver/print-supported-extensions-riscv.c |  1 +
 llvm/docs/RISCVUsage.rst  |  3 ++
 llvm/docs/ReleaseNotes.md |  2 +
 .../Target/RISCV/AsmParser/RISCVAsmParser.cpp | 16 
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  6 +--
 llvm/lib/Target/RISCV/RISCVFeatures.td|  8 
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td   | 40 +++
 llvm/lib/TargetParser/RISCVISAInfo.cpp|  6 +--
 llvm/test/CodeGen/RISCV/attributes.ll |  2 +
 llvm/test/MC/RISCV/xqcilb-invalid.s   | 24 +++
 llvm/test/MC/RISCV/xqcilb-valid.s | 26 
 .../TargetParser/RISCVISAInfoTest.cpp |  3 +-
 12 files changed, 130 insertions(+), 7 deletions(-)
 create mode 100644 llvm/test/MC/RISCV/xqcilb-invalid.s
 create mode 100644 llvm/test/MC/RISCV/xqcilb-valid.s

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 912a3ad4b6d6e..12337912a6695 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -202,6 +202,7 @@
 // CHECK-NEXT: xqcics   0.2   'Xqcics' (Qualcomm uC 
Conditional Select Extension)
 // CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-NEXT: xqciint  0.4   'Xqciint' (Qualcomm uC 
Interrupts Extension)
+// CHECK-NEXT: xqcilb   0.2   'Xqcilb' (Qualcomm uC Long 
Branch Extension)
 // CHECK-NEXT: xqcili   0.2   'Xqcili' (Qualcomm uC Load 
Large Immediate Extension)
 // CHECK-NEXT: xqcilia  0.2   'Xqcilia' (Qualcomm uC Large 
Immediate Arithmetic Extension)
 // CHECK-NEXT: xqcilo   0.2   'Xqcilo' (Qualcomm uC Large 
Offset Load Store Extension)
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 32a65d898bb31..9ce78a6673bfe 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -456,6 +456,9 @@ The current vendor extensions supported are:
 ``experimental-Xqciint``
   LLVM implements `version 0.4 of the Qualcomm uC Interrupts extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 
+``experimental-Xqcilb``
+  LLVM implements `version 0.2 of the Qualcomm uC Long Branch extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
+
 ``experimental-Xqcili``
   LLVM implements `version 0.2 of the Qualcomm uC Load Large Immediate 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index eb050e2747bc5..b4f2c7f792bd2 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -110,6 +110,8 @@ Changes to the PowerPC Backend
 Changes to the RISC-V Backend
 -
 
+* Adds experimental assembler support for the Qualcomm uC 'Xqcilb` (Long 
Branch)
+  extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcili` (Load Large 
Immediate)
   extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcilia` (Large 
Immediate Arithmetic)
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 7c5f1fc08cd0b..6163b27a35d3b 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1106,6 +1106,17 @@ struct RISCVOperand final : public MCParsedAsmOperand {
VK == RISCVMCExpr::VK_RISCV_None;
   }
 
+  bool isSImm32Lsb0() const {
+if (!isImm())
+  return false;
+RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
+  

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

2025-03-19 Thread Richard Smith via cfe-commits

zygoloid wrote:

> Would it be possible to provide better fine grained control over the 
> `-Wsign-compare` so the clang could still flag the the cases like the one in 
> the summary but ignore the cases where implicit conversion has no side 
> effects or UB?

The warning being produced is a `-Wimplicit-int-conversion` warning, not a 
`-Wsign-compare` warning, caused by us now noticing that if `shift` is `-128`, 
`-shift` will be `(int)128`, and the conversion back to `int8_t` changes the 
value. I could be wrong, but I don't think `-Wimplicit-int-conversion` flags 
any cases where the conversion has UB or side effects, so you could perhaps 
work around this by turning off that flag.

That said, it looks strange that this warns:
```c++
int8_t n = ...;
n = -n;
```
but this does not:
```c++
int8_t n = ...;
n = n + 1;
```
Both have the property that the right-hand side is sometimes 128, and if so, it 
gets implicitly wrapped to `-128` by the conversion back to `int8_t`. Perhaps 
we should look at what `+` and `-` are doing and make `-n` behave the same as 
`0 - n`?

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


[clang] 01d28c1 - [Clang] emit -Wunused-variable warning for unused structured bindings without the [[maybe_unused]] attribute (#127061)

2025-03-19 Thread via cfe-commits

Author: Oleksandr T.
Date: 2025-03-19T23:06:10+02:00
New Revision: 01d28c1cd7862fb75c8e353b2b18d13f9801b327

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

LOG: [Clang] emit -Wunused-variable warning for unused structured bindings 
without the [[maybe_unused]] attribute (#127061)

Fixes #125810 

---

This patch resolves an issue in Clang where the `-Wunused-variable`
warning was suppressed for structured bindings with elements marked
`[[maybe_unused]]`, causing the entire declaration to be treated as used
and preventing the warning from being emitted.

Added: 
clang/test/SemaCXX/unused-bindings.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/unused.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0af4f71dfbac9..9b0680c68b83a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -348,6 +348,8 @@ Bug Fixes to C++ Support
 - Correctly diagnoses if unresolved using declarations shadows template 
paramters (#GH129411)
 - Clang was previously coalescing volatile writes to members of volatile base 
class subobjects.
   The issue has been addressed by propagating qualifiers during 
derived-to-base conversions in the AST. (#GH127824)
+- Clang now emits the ``-Wunused-variable`` warning when some structured 
bindings are unused
+  and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 61e3cd4066a8d..fdfba48ab4b1c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1934,13 +1934,14 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions 
&LangOpts,
 // For a decomposition declaration, warn if none of the bindings are
 // referenced, instead of if the variable itself is referenced (which
 // it is, by the bindings' expressions).
-bool IsAllPlaceholders = true;
+bool IsAllIgnored = true;
 for (const auto *BD : DD->bindings()) {
-  if (BD->isReferenced() || BD->hasAttr())
+  if (BD->isReferenced())
 return false;
-  IsAllPlaceholders = IsAllPlaceholders && BD->isPlaceholderVar(LangOpts);
+  IsAllIgnored = IsAllIgnored && (BD->isPlaceholderVar(LangOpts) ||
+  BD->hasAttr());
 }
-if (IsAllPlaceholders)
+if (IsAllIgnored)
   return false;
   } else if (!D->getDeclName()) {
 return false;

diff  --git a/clang/test/SemaCXX/unused-bindings.cpp 
b/clang/test/SemaCXX/unused-bindings.cpp
new file mode 100644
index 0..83250dd4b0a11
--- /dev/null
+++ b/clang/test/SemaCXX/unused-bindings.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++26 -Wunused %s
+
+namespace GH125810 {
+struct S {
+  int a, b;
+};
+
+void t(S s) {
+  auto &[_, _] = s;
+  auto &[a1, _] = s; // expected-warning {{unused variable '[a1, _]'}}
+  auto &[_, b2] = s; // expected-warning {{unused variable '[_, b2]'}}
+
+  auto &[a3 [[maybe_unused]], b3 [[maybe_unused]]] = s;
+  auto &[a4, b4 [[maybe_unused]]] = s; // expected-warning {{unused variable 
'[a4, b4]'}}
+  auto &[a5 [[maybe_unused]], b5] = s; // expected-warning {{unused variable 
'[a5, b5]'}}
+}
+}

diff  --git a/clang/test/SemaCXX/unused.cpp b/clang/test/SemaCXX/unused.cpp
index 1f40c1b1ca903..ab728069f2faf 100644
--- a/clang/test/SemaCXX/unused.cpp
+++ b/clang/test/SemaCXX/unused.cpp
@@ -114,7 +114,8 @@ namespace maybe_unused_binding {
 
 void test() {
   struct X { int a, b; } x;
-  auto [a [[maybe_unused]], b] = x; // expected-warning {{an attribute 
specifier sequence attached to a structured binding declaration is a C++2c 
extension}}
+  auto [a [[maybe_unused]], b] = x; // expected-warning {{an attribute 
specifier sequence attached to a structured binding declaration is a C++2c 
extension}} \
+// expected-warning {{unused variable '[a, 
b]'}}
 }
 
 }



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


[clang] [HLSL] error on out of bounds vector accesses (PR #128952)

2025-03-19 Thread Eli Friedman via cfe-commits


@@ -14054,6 +14054,23 @@ void Sema::CheckCastAlign(Expr *Op, QualType T, 
SourceRange TRange) {
 << TRange << Op->getSourceRange();
 }
 
+void Sema::CheckVectorAccess(const Expr *BaseExpr, const Expr *IndexExpr) {
+  const auto *VTy = BaseExpr->getType()->getAs();
+  if (!VTy)
+return;
+
+  Expr::EvalResult Result;
+  if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects))

efriedma-quic wrote:

Generally, if a value is not required to be a constant, we don't want different 
semantic rules depending on whether the value is in fact constant.  (There are 
a few places that do in fact work like this, like array bounds, but it causes 
weird results. Especially when people do stuff with macros.)  So I don't think 
we want to reject here.

A DiagRuntimeBehavior() is probably appropriate, though.

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


[clang] [Offload] Handle `BoundArchitecture` for non-GPU targets (PR #132037)

2025-03-19 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> Please take a look at the sanitizer buildbot failure above.

I don't know how a clang driver change that only affects SYCL and OpenMP 
offloading could cause JIT to fail.

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


[clang] [C23] Fix compound literals within function prototype (PR #132097)

2025-03-19 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/132097

>From 7882bfbbe7ada59de91625c5f0365cec1fbe3c5b Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 19 Mar 2025 16:50:12 -0400
Subject: [PATCH 1/4] [C23] Fix compound literals within function prototype

WG14 N2819 clarified that a compound literal within a function
prototype has a lifetime similar to that of a local variable within the
function, not a file scope variable.
---
 clang/docs/ReleaseNotes.rst  |  4 
 clang/lib/Sema/SemaExpr.cpp  |  8 +++-
 clang/test/AST/ByteCode/literals.cpp |  6 ++
 clang/test/C/C23/n2819.c | 17 +
 clang/www/c_status.html  |  2 +-
 5 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 666bbf22acc93..768ba480a7ee7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -148,6 +148,10 @@ C23 Feature Support
   better diagnostic behavior for the ``va_start()`` macro in C23 and later.
   This also updates the definition of ``va_start()`` in  to use
   the new builtin. Fixes #GH124031.
+- Implemented ``WG14 N2819 
isFunctionOrMethod();
+  // We treat the compound literal as being at file scope if it's not in a
+  // function or method body, or within the function's prototype scope. This
+  // means the following compound literal is not at file scope:
+  //   void func(char *para[(int [1]){ 0 }[0]);
+  const Scope *S = getCurScope();
+  bool isFileScope = !CurContext->isFunctionOrMethod() &&
+ (!S || !S->isFunctionPrototypeScope());
 
   // In C, compound literals are l-values for some reason.
   // For GCC compatibility, in C++, file-scope array compound literals with
diff --git a/clang/test/AST/ByteCode/literals.cpp 
b/clang/test/AST/ByteCode/literals.cpp
index f206f020ecb47..a9b787892eff2 100644
--- a/clang/test/AST/ByteCode/literals.cpp
+++ b/clang/test/AST/ByteCode/literals.cpp
@@ -849,13 +849,11 @@ namespace CompoundLiterals {
   }
   static_assert(get5() == 5, "");
 
-  constexpr int get6(int f = (int[]){1,2,6}[2]) { // ref-note {{subexpression 
not valid in a constant expression}} \
-  // ref-note {{declared here}}
+  constexpr int get6(int f = (int[]){1,2,6}[2]) {
 return f;
   }
   static_assert(get6(6) == 6, "");
-  // FIXME: Who's right here?
-  static_assert(get6() == 6, ""); // ref-error {{not an integral constant 
expression}}
+  static_assert(get6() == 6, "");
 
   constexpr int x = (int){3};
   static_assert(x == 3, "");
diff --git a/clang/test/C/C23/n2819.c b/clang/test/C/C23/n2819.c
index c428fbba80245..eb0f64a69f375 100644
--- a/clang/test/C/C23/n2819.c
+++ b/clang/test/C/C23/n2819.c
@@ -1,4 +1,4 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 /* WG14 N2819: No
@@ -6,9 +6,10 @@
  */
 
 int *escaped;
+
 // CHECK-LABEL: define dso_local i32 @f(
 // CHECK-SAME: ptr noundef [[PTR:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT:  entry:
+// CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:[[PTR_ADDR:%.*]] = alloca ptr, align 8
 // CHECK-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR]], align 8
@@ -19,23 +20,23 @@ int f(int *ptr) { escaped = ptr; return 1; }
 
 // CHECK-LABEL: define dso_local i32 @g(
 // CHECK-SAME: ptr noundef [[PARA:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
+// CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:[[PARA_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTCOMPOUNDLITERAL:%.*]] = alloca [27 x i32], align 4
 // CHECK-NEXT:store ptr [[PARA]], ptr [[PARA_ADDR]], align 8
-// CHECK-NEXT:[[CALL:%.*]] = call i32 @f(ptr noundef @.compoundliteral)
+// CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 4 
[[DOTCOMPOUNDLITERAL]], i8 0, i64 108, i1 false)
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [27 x i32], ptr 
[[DOTCOMPOUNDLITERAL]], i64 0, i64 0
+// CHECK-NEXT:[[CALL:%.*]] = call i32 @

[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)

2025-03-19 Thread Ibraim Ganiev via cfe-commits

olologin wrote:

Splitting config to multiple files is potentially bad because caching wrappers 
need to be adjusted to take into account this new type of input file (they only 
know about .clang-tidy file).

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


[clang] [C23] Fix compound literals within function prototype (PR #132097)

2025-03-19 Thread Aaron Ballman via cfe-commits


@@ -849,13 +849,11 @@ namespace CompoundLiterals {
   }
   static_assert(get5() == 5, "");
 
-  constexpr int get6(int f = (int[]){1,2,6}[2]) { // ref-note {{subexpression 
not valid in a constant expression}} \
-  // ref-note {{declared here}}
+  constexpr int get6(int f = (int[]){1,2,6}[2]) {

AaronBallman wrote:

Thanks, I'll add more tests.

> `constinit int* a1 = f(); // error: pointer points to local variable`

Yes, this should fail (and it does).

> `constexpr int f2(int *x, int (*y)[*(x=(int[]){1,2,3})]) {`

You are a bad person who should feel bad. :-D I do think that should evaluate 
to 1 (but only when calling `f2(0)`), but that's a pile of VLA code which we 
don't always handle well, especially in C++. I think a non-VLA example that's 
similar would be:
```
  constexpr int f2(int *x =(int[]){1,2,3}) {
return x[0];
  }
  constexpr int g = f2(); // Should evaluate to 1?
  static_assert(g == 1, "");
```
which does behave how you'd expect.

The VLA example says `object backing the pointer x will be destroyed at the end 
of the full-expression` which may be a C++'ism not impacted by the C wording?


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


[clang] [CIR] Upstream a basic version of class LexicalScope (PR #131945)

2025-03-19 Thread David Olsen via cfe-commits

https://github.com/dkolsen-pgi updated 
https://github.com/llvm/llvm-project/pull/131945

>From ef54ceca65c8a62544651cbbd30967efc7adec36 Mon Sep 17 00:00:00 2001
From: David Olsen 
Date: Tue, 18 Mar 2025 17:37:26 -0700
Subject: [PATCH 1/2] [CIR] Upstream a basic version of class LexicalScope

Upstream the parts of class `CIRGenFunction::LexicalScope` that
implement function return values.  There is a bit of other functionality
in here, such as the implicit `cir.yield` at the end of a non-function
scope, but this is mostly about function returns.

The parts of `LexicalScope` that handle calling destructors, switch
statements, ternary expressions, and exception handling still need to be
upstreamed.

There is a change in the generated ClangIR (which is why many of the
tests needed updating).  Return values are stored in the
compiler-generated variable `__retval` rather than being passed to the
`cir.return` op directly.  But there should be no change in the behavior
of the generated code.
---
 clang/include/clang/CIR/Dialect/IR/CIROps.td |  16 ++
 clang/include/clang/CIR/MissingFeatures.h|   1 +
 clang/lib/CIR/CodeGen/CIRGenFunction.cpp | 219 +++
 clang/lib/CIR/CodeGen/CIRGenFunction.h   | 156 -
 clang/lib/CIR/CodeGen/CIRGenStmt.cpp |  33 ++-
 clang/test/CIR/CodeGen/basic.c   |  46 +++-
 clang/test/CIR/CodeGen/basic.cpp |  20 +-
 clang/test/CIR/CodeGen/cast.cpp  |   9 +-
 clang/test/CIR/CodeGen/unary.cpp |  15 ++
 clang/test/CIR/Lowering/basic.cpp|  20 +-
 clang/test/CIR/Lowering/func-simple.cpp  |  51 +++--
 clang/test/CIR/func-simple.cpp   |  74 +--
 12 files changed, 544 insertions(+), 116 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 2a5caf1bf1f63..352d72ff31a8a 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -832,6 +832,22 @@ def FuncOp : CIR_Op<"func", [
   let hasVerifier = 1;
 }
 
+//===--===//
+// UnreachableOp
+//===--===//
+
+def UnreachableOp : CIR_Op<"unreachable", [Terminator]> {
+  let summary = "invoke immediate undefined behavior";
+  let description = [{
+If the program control flow reaches a `cir.unreachable` operation, the
+program exhibits undefined behavior immediately. This operation is useful
+in cases where the unreachability of a program point needs to be explicitly
+marked.
+  }];
+
+  let assemblyFormat = "attr-dict";
+}
+
 
//===--===//
 // TrapOp
 
//===--===//
diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 6adff30f5c91a..e37bff1f548c9 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -89,6 +89,7 @@ struct MissingFeatures {
   static bool astVarDeclInterface() { return false; }
   static bool stackSaveOp() { return false; }
   static bool aggValueSlot() { return false; }
+  static bool generateDebugInfo() { return false; }
 
   static bool fpConstraints() { return false; }
   static bool sanitizers() { return false; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp 
b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
index 2338ec9cd952a..5685339c9e637 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
@@ -135,6 +135,13 @@ mlir::Location CIRGenFunction::getLoc(mlir::Location lhs, 
mlir::Location rhs) {
   return mlir::FusedLoc::get(locs, metadata, &getMLIRContext());
 }
 
+void CIRGenFunction::emitAndUpdateRetAlloca(QualType type, mlir::Location loc,
+CharUnits alignment) {
+  if (!type->isVoidType()) {
+fnRetAlloca = emitAlloca("__retval", convertType(type), loc, alignment);
+  }
+}
+
 void CIRGenFunction::declare(mlir::Value addrVal, const Decl *var, QualType ty,
  mlir::Location loc, CharUnits alignment,
  bool isParam) {
@@ -149,6 +156,118 @@ void CIRGenFunction::declare(mlir::Value addrVal, const 
Decl *var, QualType ty,
 allocaOp.setConstantAttr(mlir::UnitAttr::get(&getMLIRContext()));
 }
 
+void CIRGenFunction::LexicalScope::cleanup() {
+  CIRGenBuilderTy &builder = cgf.builder;
+  LexicalScope *localScope = cgf.currLexScope;
+
+  if (returnBlock != nullptr) {
+// Write out the return block, which loads the value from `__retval` and
+// issues the `cir.return`.
+mlir::OpBuilder::InsertionGuard guard(builder);
+builder.setInsertionPointToEnd(returnBlock);
+(void)emitReturn(*returnLoc);
+  }
+
+  mlir::Block *currBlock = builder.getBlock();
+

[clang] [llvm] Hlsl asint16 intrinsic (PR #131900)

2025-03-19 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,55 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-unknown %s -o - | 
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - 
-filetype=obj | spirv-val %}
+
+; CHECK: OpCapability Int16
+; CHECK: OpCapability Float16
+; CHECK-DAG: %[[#int_16:]] = OpTypeInt 16 0
+; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16
+; CHECK-DAG: %[[#vec4_int_16:]] = OpTypeVector %[[#int_16]] 4
+; CHECK-DAG: %[[#vec4_float_16:]] = OpTypeVector %[[#float_16]] 4
+
+
+define i16 @test_int16(i16 returned %p0) {
+entry:
+  ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#int_16]]
+  ; CHECK: OpReturnValue %[[#arg0]]
+  ret i16 %p0
+}
+
+define i16 @test_half(half nofpclass(nan inf) %p0) {
+entry:
+  ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#float_16:]]
+  ; CHECK: %[[#]] = OpBitcast %[[#int_16]] %[[#arg0]]

farzonl wrote:

this case is already covered by `llvm/test/CodeGen/SPIRV/bitcast.ll`

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


[clang] [Clang] Fix UB in #131515 (PR #132091)

2025-03-19 Thread Florian Mayer via cfe-commits


@@ -1681,7 +1681,7 @@ std::optional 
Sema::GetDecompositionElementCount(QualType T,
   llvm::APSInt TupleSize(Ctx.getTypeSize(Ctx.getSizeType()));
   switch (isTupleLike(*this, Loc, T, TupleSize)) {
   case IsTupleLike::Error:
-return {};
+return std::nullopt;

fmayer wrote:

doesn't the change on 1709 change the return value?

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


[clang] [OpenMP 6.0] Parse/Sema support for reduction over private variable with reduction clause. (PR #129938)

2025-03-19 Thread Alexey Bataev via cfe-commits


@@ -1160,6 +1162,12 @@ class SemaOpenMP : public SemaBase {
 SmallVector
 AllocClauseModifiersLoc;
 Expr *AllocateAlignment = nullptr;
+struct OpenMPReductionClauseModifiers {
+  int ExtraModifier;
+  int OriginalSharingModifier;
+  OpenMPReductionClauseModifiers(int extra, int original)

alexey-bataev wrote:

```suggestion
  OpenMPReductionClauseModifiers(int Extra, int Original)
```


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


[clang] [OpenMP 6.0] Parse/Sema support for reduction over private variable with reduction clause. (PR #129938)

2025-03-19 Thread Alexey Bataev via cfe-commits


@@ -3854,6 +3890,7 @@ class OMPReductionClause final
   /// region with this clause.
   /// \param PostUpdate Expression that must be executed after exit from the
   /// OpenMP region with this clause.
+  /// \pram IsPrivateVarReduction array for private variable reduction flags

alexey-bataev wrote:

```suggestion
  /// \param IsPrivateVarReduction array for private variable reduction flags
```


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


[clang] [OpenMP 6.0] Parse/Sema support for reduction over private variable with reduction clause. (PR #129938)

2025-03-19 Thread Alexey Bataev via cfe-commits


@@ -3757,6 +3768,31 @@ class OMPReductionClause final
   /// reduction copies.
   void setRHSExprs(ArrayRef RHSExprs);
 
+  /// Set the list private reduction flags
+  void setPrivateVariableReductionFlags(ArrayRef Flags) {
+assert(Flags.size() == varlist_size() &&
+   "Number of private flags does not match vars");
+llvm::copy(Flags, getTrailingObjects());
+  }
+
+  /// Get the list of help private variable reduction flags
+  MutableArrayRef getPrivateVariableReductionFlags() {
+return MutableArrayRef(getTrailingObjects(), varlist_size());

alexey-bataev wrote:

```suggestion
return MutableArrayRef(getTrailingObjects(), varlist_size());
```
?

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


[clang] [compiler-rt] Revert "[Coverage] Fix region termination for GNU statement expressions" (PR #132095)

2025-03-19 Thread Justin Cady via cfe-commits

https://github.com/justincady created 
https://github.com/llvm/llvm-project/pull/132095

Reverts llvm/llvm-project#130976

Breaks clang-cmake-x86_64-avx512-linux bot.

>From 2f37c9ec685b8ba82fdc3bd8387ce59b3f8a77dc Mon Sep 17 00:00:00 2001
From: Justin Cady 
Date: Wed, 19 Mar 2025 16:45:26 -0400
Subject: [PATCH] =?UTF-8?q?Revert=20"[Coverage]=20Fix=20region=20terminati?=
 =?UTF-8?q?on=20for=20GNU=20statement=20expressions=20(#130=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 0827e3aae6eb69c2a6fa842ffa780881feb45b5d.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  8 ---
 .../CoverageMapping/terminate-statements.cpp  |  7 ---
 .../Linux/coverage-statement-expression.cpp   | 21 ---
 3 files changed, 36 deletions(-)
 delete mode 100644 
compiler-rt/test/profile/Linux/coverage-statement-expression.cpp

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 73811d15979d5..f09157771d2b5 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1505,14 +1505,6 @@ struct CounterCoverageMappingBuilder
 handleFileExit(getEnd(S));
   }
 
-  void VisitStmtExpr(const StmtExpr *E) {
-Visit(E->getSubStmt());
-// Any region termination (such as a noreturn CallExpr) within the 
statement
-// expression has been handled by visiting the sub-statement. The visitor
-// cannot be at a terminate statement leaving the statement expression.
-HasTerminateStmt = false;
-  }
-
   void VisitDecl(const Decl *D) {
 Stmt *Body = D->getBody();
 
diff --git a/clang/test/CoverageMapping/terminate-statements.cpp 
b/clang/test/CoverageMapping/terminate-statements.cpp
index 3f8e43f0fbcb6..0067185fee8e6 100644
--- a/clang/test/CoverageMapping/terminate-statements.cpp
+++ b/clang/test/CoverageMapping/terminate-statements.cpp
@@ -346,12 +346,6 @@ int elsecondnoret(void) {
   return 0;
 }
 
-// CHECK-LABEL: _Z18statementexprnoretb
-int statementexprnoret(bool crash) {
-  int rc = ({ if (crash) abort(); 0; }); // CHECK: File 0, 351:35 -> 352:12 = 
(#0 - #1)
-  return rc; // CHECK-NOT: Gap
-}
-
 int main() {
   foo(0);
   foo(1);
@@ -374,6 +368,5 @@ int main() {
   ornoret();
   abstractcondnoret();
   elsecondnoret();
-  statementexprnoret(false);
   return 0;
 }
diff --git a/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp 
b/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp
deleted file mode 100644
index 7c76555e3300b..0
--- a/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// RUN: %clangxx_profgen -std=gnu++17 -fuse-ld=lld -fcoverage-mapping -o %t %s
-// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
-// RUN: llvm-profdata merge -o %t.profdata %t.profraw
-// RUN: llvm-cov show %t -instr-profile=%t.profdata 2>&1 | FileCheck %s
-
-#include 
-
-// clang-format off
-__attribute__ ((__noreturn__))
-void foo(void) { while (1); }   // CHECK:  [[@LINE]]| 0|void 
foo(void)
-_Noreturn void bar(void) { while (1); } // CHECK:  [[@LINE]]| 
0|_Noreturn void bar(void)
-// CHECK:  [[@LINE]]|  |
-int main(int argc, char **argv) {   // CHECK:  [[@LINE]]| 1|int 
main(
-  int rc = ({ if (argc > 3) foo(); 0; });   // CHECK:  [[@LINE]]| 1|  int 
rc =
-  printf("coverage after foo is present\n");// CHECK:  [[@LINE]]| 1|  
printf(
-// CHECK:  [[@LINE]]|  |
-  int rc2 = ({ if (argc > 3) bar(); 0; });  // CHECK:  [[@LINE]]| 1|  int 
rc2 =
-  printf("coverage after bar is present\n");// CHECK:  [[@LINE]]| 1|  
printf(
-  return rc + rc2;  // CHECK:  [[@LINE]]| 1|  
return rc
-}   // CHECK:  [[@LINE]]| 1|}
-// clang-format on

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


[clang] [Clang] emit -Wunused-variable warning for unused structured bindings without the [[maybe_unused]] attribute (PR #127061)

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

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


[clang] [Clang] Fix UB in #131515 (PR #132091)

2025-03-19 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/132091

>From 68ebbf821176dd17a757c32771fa728f21d4dd11 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 19 Mar 2025 21:05:38 +0100
Subject: [PATCH] [Clang] Fix UB in #131515

It turns out trailing objects are uninitialized
and APValue assignment operator requires a fully initialized object.
---
 clang/include/clang/AST/ExprCXX.h|  2 +-
 clang/lib/AST/ExprCXX.cpp| 12 ++--
 clang/lib/Sema/SemaDeclCXX.cpp   |  4 ++--
 .../test/SemaCXX/builtin-structured-binding-size.cpp |  4 ++--
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 724ed437f1075..223d74993e9e6 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2777,7 +2777,7 @@ class TypeTraitExpr final
 ArrayRef Args, SourceLocation RParenLoc,
 std::variant Value);
 
-  TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {}
+  TypeTraitExpr(EmptyShell Empty, bool IsStoredAsBool);
 
   size_t numTrailingObjects(OverloadToken) const {
 return getNumArgs();
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index c2cf4ffe506c6..a000e988e6834 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1868,7 +1868,8 @@ TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation 
Loc, TypeTrait Kind,
   if (TypeTraitExprBits.IsBooleanTypeTrait)
 TypeTraitExprBits.Value = std::get(Value);
   else
-*getTrailingObjects() = std::get(std::move(Value));
+::new (getTrailingObjects())
+APValue(std::get(std::move(Value)));
 
   TypeTraitExprBits.NumArgs = Args.size();
   assert(Args.size() == TypeTraitExprBits.NumArgs &&
@@ -1884,6 +1885,13 @@ TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation 
Loc, TypeTrait Kind,
  "Only int values are supported by clang");
 }
 
+TypeTraitExpr::TypeTraitExpr(EmptyShell Empty, bool IsStoredAsBool)
+: Expr(TypeTraitExprClass, Empty) {
+  TypeTraitExprBits.IsBooleanTypeTrait = IsStoredAsBool;
+  if (!IsStoredAsBool)
+::new (getTrailingObjects()) APValue();
+}
+
 TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T,
  SourceLocation Loc,
  TypeTrait Kind,
@@ -1909,7 +1917,7 @@ TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const 
ASTContext &C,
  unsigned NumArgs) {
   void *Mem = C.Allocate(totalSizeToAlloc(
   IsStoredAsBool ? 0 : 1, NumArgs));
-  return new (Mem) TypeTraitExpr(EmptyShell());
+  return new (Mem) TypeTraitExpr(EmptyShell(), IsStoredAsBool);
 }
 
 CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config,
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index bd6321c46a78f..a1551e8027cd3 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1681,7 +1681,7 @@ std::optional 
Sema::GetDecompositionElementCount(QualType T,
   llvm::APSInt TupleSize(Ctx.getTypeSize(Ctx.getSizeType()));
   switch (isTupleLike(*this, Loc, T, TupleSize)) {
   case IsTupleLike::Error:
-return {};
+return std::nullopt;
   case IsTupleLike::TupleLike:
 return TupleSize.getExtValue();
   case IsTupleLike::NotTupleLike:
@@ -1706,7 +1706,7 @@ std::optional 
Sema::GetDecompositionElementCount(QualType T,
   RD->fields(), [](FieldDecl *FD) { return !FD->isUnnamedBitField(); });
 
   if (CheckMemberDecompositionFields(*this, Loc, OrigRD, T, BasePair))
-return true;
+return std::nullopt;
 
   return NumFields;
 }
diff --git a/clang/test/SemaCXX/builtin-structured-binding-size.cpp 
b/clang/test/SemaCXX/builtin-structured-binding-size.cpp
index 85b1d81e08e33..53576048754ab 100644
--- a/clang/test/SemaCXX/builtin-structured-binding-size.cpp
+++ b/clang/test/SemaCXX/builtin-structured-binding-size.cpp
@@ -40,9 +40,9 @@ static_assert(__builtin_structured_binding_size(S5) == 2);
 // expected-error@-1 {{static assertion failed due to requirement 
'__builtin_structured_binding_size(S5) == 2'}} \
 // expected-note@-1 {{expression evaluates to '1 == 2'}}
 static_assert(__builtin_structured_binding_size(S6) == 2);
-// expected-error@-1 {{static assertion failed due to requirement 
'__builtin_structured_binding_size(S6) == 2'}} \
 // expected-error@-1 {{cannot decompose class type 'S6' because it has an 
anonymous union member}} \
-// expected-note@-1 {{expression evaluates to '1 == 2'}}
+// expected-error@-1 {{type 'S6' cannot be decomposed}} \
+// expected-error@-1 {{static assertion expression is not an integral constant 
expression}} \
 // expected-note@#note-anon-union {{declared here}}
 static_assert(__builtin_structured_binding_size(S7) == 1);
 

___
cfe-commits mailing list
cfe-commits@

[clang] [clang-tools-extra] [Clang] [Sema] Make -Wreturn-type an error by default (PR #131207)

2025-03-19 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/131207

>From bff3db4f6a7fdff572b662048f395c280a11d94b Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Thu, 13 Mar 2025 21:18:14 +0100
Subject: [PATCH 1/3] [Clang] [Sema] Make -Wreturn-type an error by default

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 clang/test/Index/warning-flags.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8e6e6e892cdd7..113e684a53c2b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -722,7 +722,7 @@ def warn_falloff_nonvoid : Warning<
   "non-void "
   
"%enum_select{%Function{function}|%Block{block}|%Lambda{lambda}|%Coroutine{coroutine}}0"
   " does not return a value%select{| in all control paths}1">,
-  InGroup;
+  InGroup, DefaultError;
 def err_falloff_nonvoid : Error<
   "non-void %select{function|block|lambda|coroutine}0 "
   "does not return a value%select{| in all control paths}1">;
diff --git a/clang/test/Index/warning-flags.c b/clang/test/Index/warning-flags.c
index 1694c6abab562..3229f000c4ae0 100644
--- a/clang/test/Index/warning-flags.c
+++ b/clang/test/Index/warning-flags.c
@@ -9,7 +9,7 @@ int *bar(float *f) { return f; }
 // RUN: c-index-test -test-load-source-reparse 5 all -w %s 2>&1 | FileCheck 
-check-prefix=NOWARNINGS %s
 // RUN: c-index-test -test-load-source all -w -O4 %s 2>&1 | FileCheck 
-check-prefix=NOWARNINGS %s
 
-// CHECK-BOTH-WARNINGS: warning: non-void function does not return a value
+// CHECK-BOTH-WARNINGS: error: non-void function does not return a value
 // CHECK-BOTH-WARNINGS: warning: incompatible pointer types returning 'float 
*' from a function with result type 'int *'
 
 // CHECK-SECOND-WARNING-NOT:non-void function does not return a value

>From a8523d15a4c790fe1fb58a6fe41da571cb11ba47 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Tue, 18 Mar 2025 17:52:36 +0100
Subject: [PATCH 2/3] Fix clang-tidy warning

---
 .../test/clang-tidy/checkers/misc/unused-using-decls.cpp| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
index 62aa17b0b1c22..40451167c5809 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -233,7 +233,7 @@ namespace my_literals {
 
 using my_literals::operator"" _r;
 
-int foo() {
+void foo() {
   auto x2 = 123_r;
 }
 

>From f830db193424913aec7e355d39af68de8560adfb Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 19 Mar 2025 19:13:01 +0100
Subject: [PATCH 3/3] Add release note

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8989124611e66..1d81b5e191e89 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -38,6 +38,7 @@ Potentially Breaking Changes
 - Fix missing diagnostics for uses of declarations when performing typename 
access,
   such as when performing member access on a '[[deprecated]]' type alias.
   (#GH58547)
+- The `-Wreturn-type` warning now defaults to an error in all language modes.
 
 C/C++ Language Potentially Breaking Changes
 ---

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


[clang-tools-extra] [clang-doc] Avoid deref of invalid std::optional (PR #131939)

2025-03-19 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/131939

>From d7fe558c1c7a3f18bc4019e6edcd86e2a98a46a0 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 18 Mar 2025 23:38:09 +
Subject: [PATCH] [clang-doc] Avoid deref of invalid std::optional

Since our existing guard is insufficient to prevent accessing the
std::optional when in an invalid state, guard the access with
`.value_or()`. This maintains the desired behavior, without running into
UB.

The new test should prevent regressions.

Fixes #131697
---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp |  2 +-
 .../test/clang-doc/DR-131697.cpp  | 22 +++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang-tools-extra/test/clang-doc/DR-131697.cpp

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 18a0de826630c..a8404479569f9 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -498,7 +498,7 @@ writeFileDefinition(const Location &L,
 return std::make_unique(
 HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
 " of file " + L.Filename);
-  SmallString<128> FileURL(*RepositoryUrl);
+  SmallString<128> FileURL(RepositoryUrl.value_or(""));
   llvm::sys::path::append(
   FileURL, llvm::sys::path::Style::posix,
   // If we're on Windows, the file name will be in the wrong format, and
diff --git a/clang-tools-extra/test/clang-doc/DR-131697.cpp 
b/clang-tools-extra/test/clang-doc/DR-131697.cpp
new file mode 100644
index 0..50556ecd2635b
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/DR-131697.cpp
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: split-file %s %t
+// RUN: clang-doc -format=html %t/compile-commands.json %t/main.cpp
+
+//--- main.cpp
+
+class Foo {
+  void getFoo();
+};
+
+int main() {
+  return 0;
+}
+
+//--- compile-commands.json
+[
+{
+  "directory": "foo",
+  "file":"main.cpp",
+  "command":"clang main.cpp -c"
+}
+]

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


[clang] [CIR] Upstream global initialization for ArrayType (PR #131657)

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

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


[clang] [llvm] Hlsl asint16 intrinsic (PR #131900)

2025-03-19 Thread via cfe-commits


@@ -80,6 +80,34 @@ void asuint(double3, out uint3, out uint3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
 void asuint(double4, out uint4, out uint4);
 
+//===--===//
+// asint16 builtins
+//===--===//
+
+/// \fn int16_t asint16(T Val)

metkarpoonam wrote:

I've replaced Val with X as suggested. Thanks for the clarification.

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


[clang] 6aeae62 - [CIR] Upstream global initialization for ArrayType (#131657)

2025-03-19 Thread via cfe-commits

Author: Amr Hesham
Date: 2025-03-19T21:29:37+01:00
New Revision: 6aeae62aef63c7c11ab67a880716afdc92ac8422

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

LOG: [CIR] Upstream global initialization for ArrayType (#131657)

This change adds global initialization for ArrayType

Issue #130197

Added: 


Modified: 
clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
clang/lib/CIR/CodeGen/CIRGenBuilder.h
clang/lib/CIR/CodeGen/CIRGenConstantEmitter.h
clang/lib/CIR/CodeGen/CIRGenDecl.cpp
clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
clang/lib/CIR/CodeGen/CIRGenModule.cpp
clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
clang/lib/CIR/Dialect/IR/CIRDialect.cpp
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
clang/test/CIR/CodeGen/array.cpp
clang/test/CIR/IR/array.cir
clang/test/CIR/Lowering/array.cpp

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 7b3741de29075..3680ded4afafe 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -154,6 +154,48 @@ def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
   }];
 }
 
+
+//===--===//
+// ConstArrayAttr
+//===--===//
+
+def ConstArrayAttr : CIR_Attr<"ConstArray", "const_array", 
[TypedAttrInterface]> {
+  let summary = "A constant array from ArrayAttr or StringRefAttr";
+  let description = [{
+An CIR array attribute is an array of literals of the specified attr types.
+  }];
+
+  let parameters = (ins AttributeSelfTypeParameter<"">:$type,
+"mlir::Attribute":$elts,
+"int":$trailingZerosNum);
+
+  // Define a custom builder for the type; that removes the need to pass
+  // in an MLIRContext instance, as it can be infered from the `type`.
+  let builders = [
+AttrBuilderWithInferredContext<(ins "cir::ArrayType":$type,
+"mlir::Attribute":$elts), [{
+  int zeros = 0;
+  auto typeSize = mlir::cast(type).getSize();
+  if (auto str = mlir::dyn_cast(elts))
+zeros = typeSize - str.size();
+  else
+zeros = typeSize - mlir::cast(elts).size();
+
+  return $_get(type.getContext(), type, elts, zeros);
+}]>
+  ];
+
+  // Printing and parsing available in CIRDialect.cpp
+  let hasCustomAssemblyFormat = 1;
+
+  // Enable verifier.
+  let genVerifyDecl = 1;
+
+  let extraClassDeclaration = [{
+bool hasTrailingZeros() const { return getTrailingZerosNum() != 0; };
+  }];
+}
+
 
//===--===//
 // ConstPtrAttr
 
//===--===//

diff  --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index 85f6a00e596a7..fef290612149a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -45,6 +45,42 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
 return false;
   }
 
+  // Return true if the value is a null constant such as null pointer, (+0.0)
+  // for floating-point or zero initializer
+  bool isNullValue(mlir::Attribute attr) const {
+if (mlir::isa(attr))
+  return true;
+
+if (const auto ptrVal = mlir::dyn_cast(attr))
+  return ptrVal.isNullValue();
+
+if (const auto intVal = mlir::dyn_cast(attr))
+  return intVal.isNullValue();
+
+if (const auto boolVal = mlir::dyn_cast(attr))
+  return !boolVal.getValue();
+
+if (auto fpAttr = mlir::dyn_cast(attr)) {
+  auto fpVal = fpAttr.getValue();
+  bool ignored;
+  llvm::APFloat fv(+0.0);
+  fv.convert(fpVal.getSemantics(), llvm::APFloat::rmNearestTiesToEven,
+ &ignored);
+  return fv.bitwiseIsEqual(fpVal);
+}
+
+if (const auto arrayVal = mlir::dyn_cast(attr)) {
+  if (mlir::isa(arrayVal.getElts()))
+return false;
+  for (const auto elt : mlir::cast(arrayVal.getElts())) {
+if (!isNullValue(elt))
+  return false;
+  }
+  return true;
+}
+return false;
+  }
+
   bool isInt(mlir::Type i) { return mlir::isa(i); }
 
   // Creates constant nullptr for pointer type ty.

diff  --git a/clang/lib/CIR/CodeGen/CIRGenConstantEmitter.h 
b/clang/lib/CIR/CodeGen/CIRGenConstantEmitter.h
index 5b22a8e59908d..ca4e607992bbc 100644
--- a/clang/lib/CIR/CodeGen/CIRGenConstantEmitter.h
+++ b/clang/lib/CIR/CodeGen/CIRGenConstantEmitter.h
@@ -20,7 +20,6 @@
 
 #include "CIRGenFunction.h"
 #include "CIRGenModule.

[clang] [CIR] Follow up for addressing style comment (PR #132093)

2025-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)


Changes

Follow up PR to address style comment 
(https://github.com/llvm/llvm-project/pull/131657#discussion_r2004197917)

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


1 Files Affected:

- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+1-1) 


``diff
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 83226ed8680bb..9a3f956ecbebe 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -288,7 +288,7 @@ mlir::Value 
CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
 
 /// ZeroAttr visitor.
 mlir::Value CIRAttrToValue::visitCirAttr(cir::ZeroAttr attr) {
-  auto loc = parentOp->getLoc();
+  mlir::Location loc = parentOp->getLoc();
   return rewriter.create(
   loc, converter->convertType(attr.getType()));
 }

``




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


[clang] [CIR] Follow up for addressing style comment (PR #132093)

2025-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

Follow up PR to address style comment 
(https://github.com/llvm/llvm-project/pull/131657#discussion_r2004197917)

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


1 Files Affected:

- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+1-1) 


``diff
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 83226ed8680bb..9a3f956ecbebe 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -288,7 +288,7 @@ mlir::Value 
CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
 
 /// ZeroAttr visitor.
 mlir::Value CIRAttrToValue::visitCirAttr(cir::ZeroAttr attr) {
-  auto loc = parentOp->getLoc();
+  mlir::Location loc = parentOp->getLoc();
   return rewriter.create(
   loc, converter->convertType(attr.getType()));
 }

``




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


[clang] [clang-format] Recognize wait fork in Verilog (PR #132042)

2025-03-19 Thread Björn Schäpers via cfe-commits

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


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


[clang] [compiler-rt] [Coverage] Fix region termination for GNU statement expressions (PR #130976)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-cmake-x86_64-avx512-linux` running on `avx512-intel64` while building 
`clang,compiler-rt` at step 7 "ninja check 1".

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


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

```
Step 7 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Profile-i386 :: 
Linux/coverage-statement-expression.cpp' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/./bin/clang
  --driver-mode=g++  -m32  -ldl  -fprofile-instr-generate -std=gnu++17 
-fuse-ld=lld -fcoverage-mapping -o 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-i386/Linux/Output/coverage-statement-expression.cpp.tmp
 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp
+ 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/./bin/clang
 --driver-mode=g++ -m32 -ldl -fprofile-instr-generate -std=gnu++17 -fuse-ld=lld 
-fcoverage-mapping -o 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-i386/Linux/Output/coverage-statement-expression.cpp.tmp
 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp
clang: error: invalid linker name in argument '-fuse-ld=lld'

--




```



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


[clang] 0f7bd60 - [NFC] Add a leading comment to boolean arguments. (#131746)

2025-03-19 Thread via cfe-commits

Author: Michael Park
Date: 2025-03-19T13:43:16-07:00
New Revision: 0f7bd60791ed18b98f84916d0dd371508cbf208c

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

LOG: [NFC] Add a leading comment to boolean arguments. (#131746)

Addressing [nit 
comments](https://github.com/llvm/llvm-project/pull/129982#discussion_r1997914387)
 from @shafik

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 2c73501821bff..2b03446aaa30e 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10825,7 +10825,8 @@ void ASTReader::FinishedDeserializing() {
 {
   // Guard variable to avoid recursively entering the process of passing
   // decls to consumer.
-  SaveAndRestore GuardPassingDeclsToConsumer(CanPassDeclsToConsumer, 
false);
+  SaveAndRestore GuardPassingDeclsToConsumer(CanPassDeclsToConsumer,
+ /*NewValue=*/false);
 
   // Propagate exception specification and deduced type updates along
   // redeclaration chains.

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 79bd41aa2644e..c3341e00bacef 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4314,7 +4314,8 @@ void ASTReader::PassInterestingDeclsToConsumer() {
 
   // Guard variable to avoid recursively redoing the process of passing
   // decls to consumer.
-  SaveAndRestore GuardPassingDeclsToConsumer(CanPassDeclsToConsumer, false);
+  SaveAndRestore GuardPassingDeclsToConsumer(CanPassDeclsToConsumer,
+ /*NewValue=*/false);
 
   // Ensure that we've loaded all potentially-interesting declarations
   // that need to be eagerly loaded.



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


[clang] [Clang] Fix UB in #131515 (PR #132091)

2025-03-19 Thread via cfe-commits

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


[clang] [C23] Fix compound literals within function prototype (PR #132097)

2025-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)


Changes

WG14 N2819 clarified that a compound literal within a function prototype has a 
lifetime similar to that of a local variable within the function, not a file 
scope variable.

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


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+7-1) 
- (modified) clang/test/AST/ByteCode/literals.cpp (+2-4) 
- (modified) clang/test/C/C23/n2819.c (+9-8) 
- (modified) clang/www/c_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 666bbf22acc93..768ba480a7ee7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -148,6 +148,10 @@ C23 Feature Support
   better diagnostic behavior for the ``va_start()`` macro in C23 and later.
   This also updates the definition of ``va_start()`` in  to use
   the new builtin. Fixes #GH124031.
+- Implemented ``WG14 N2819 
isFunctionOrMethod();
+  // We treat the compound literal as being at file scope if it's not in a
+  // function or method body, or within the function's prototype scope. This
+  // means the following compound literal is not at file scope:
+  //   void func(char *para[(int [1]){ 0 }[0]);
+  const Scope *S = getCurScope();
+  bool isFileScope = !CurContext->isFunctionOrMethod() &&
+ (!S || !S->isFunctionPrototypeScope());
 
   // In C, compound literals are l-values for some reason.
   // For GCC compatibility, in C++, file-scope array compound literals with
diff --git a/clang/test/AST/ByteCode/literals.cpp 
b/clang/test/AST/ByteCode/literals.cpp
index f206f020ecb47..a9b787892eff2 100644
--- a/clang/test/AST/ByteCode/literals.cpp
+++ b/clang/test/AST/ByteCode/literals.cpp
@@ -849,13 +849,11 @@ namespace CompoundLiterals {
   }
   static_assert(get5() == 5, "");
 
-  constexpr int get6(int f = (int[]){1,2,6}[2]) { // ref-note {{subexpression 
not valid in a constant expression}} \
-  // ref-note {{declared here}}
+  constexpr int get6(int f = (int[]){1,2,6}[2]) {
 return f;
   }
   static_assert(get6(6) == 6, "");
-  // FIXME: Who's right here?
-  static_assert(get6() == 6, ""); // ref-error {{not an integral constant 
expression}}
+  static_assert(get6() == 6, "");
 
   constexpr int x = (int){3};
   static_assert(x == 3, "");
diff --git a/clang/test/C/C23/n2819.c b/clang/test/C/C23/n2819.c
index c428fbba80245..eb0f64a69f375 100644
--- a/clang/test/C/C23/n2819.c
+++ b/clang/test/C/C23/n2819.c
@@ -1,4 +1,4 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 /* WG14 N2819: No
@@ -6,9 +6,10 @@
  */
 
 int *escaped;
+
 // CHECK-LABEL: define dso_local i32 @f(
 // CHECK-SAME: ptr noundef [[PTR:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT:  entry:
+// CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:[[PTR_ADDR:%.*]] = alloca ptr, align 8
 // CHECK-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR]], align 8
@@ -19,23 +20,23 @@ int f(int *ptr) { escaped = ptr; return 1; }
 
 // CHECK-LABEL: define dso_local i32 @g(
 // CHECK-SAME: ptr noundef [[PARA:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
+// CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:[[PARA_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTCOMPOUNDLITERAL:%.*]] = alloca [27 x i32], align 4
 // CHECK-NEXT:store ptr [[PARA]], ptr [[PARA_ADDR]], align 8
-// CHECK-NEXT:[[CALL:%.*]] = call i32 @f(ptr noundef @.compoundliteral)
+// CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 4 
[[DOTCOMPOUNDLITERAL]], i8 0, i64 108, i1 false)
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [27 x i32], ptr 
[[DOTCOMPOUNDLITERAL]], i64 0, i64 0
+// CHECK-NEXT:[[CALL:%.*]] = call i32 @f(ptr noundef [[ARRAYDECAY]])
 // CHECK-NEXT:[[TMP0:%.*]] = zext i32 [[CALL]] to i64
 // CHECK-NEXT:ret i32 0
 //
-// FIXME: notice the we are using the g

  1   2   3   4   >