[clang] [clang][modules] Separate parsing of modulemaps (PR #119740)

2025-02-20 Thread Michael Spencer via cfe-commits


@@ -3157,25 +2140,18 @@ bool ModuleMap::parseModuleMapFile(FileEntryRef File, 
bool IsSystem,
   assert((!Offset || *Offset <= Buffer->getBufferSize()) &&
  "invalid buffer offset");
 
-  // Parse this module map file.
-  Lexer L(SourceMgr.getLocForStartOfFile(ID), MMapLangOpts,
-  Buffer->getBufferStart(),
-  Buffer->getBufferStart() + (Offset ? *Offset : 0),
-  Buffer->getBufferEnd());
-  SourceLocation Start = L.getSourceLocation();
-  ModuleMapParser Parser(L, SourceMgr, Target, Diags, *this, ID, Dir, 
IsSystem);
-  bool Result = Parser.parseModuleMapFile();
-  ParsedModuleMap[File] = Result;
-
-  if (Offset) {
-auto Loc = SourceMgr.getDecomposedLoc(Parser.getLocation());
-assert(Loc.first == ID && "stopped in a different file?");
-*Offset = Loc.second;
+  std::optional MMF = modulemap::parseModuleMap(
+  ID, Dir, SourceMgr, Diags, IsSystem, Offset);

Bigcheese wrote:

I plan to add a separate source manager and then remap the source locations 
when constructing the `clang::Module` instance. I plan to do it after looking 
up modules by header is also lazy.

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


[clang] [libc] [Clang] Fix cross-lane scan when given divergent lanes (PR #127703)

2025-02-20 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#128085

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


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

2025-02-20 Thread Denis Mikhailov via cfe-commits


@@ -0,0 +1,48 @@
+.. title:: clang-tidy - readability-ambiguous-smartptr-reset-call
+
+readability-ambiguous-smartptr-reset-call
+=
+
+Finds potentially erroneous calls to ``reset`` method on smart pointers when
+the pointee type also has a ``reset`` method. Having a ``reset`` method in
+both classes makes it easy to accidentally make the pointer null when
+intending to reset the underlying object.
+
+.. code-block:: c++
+
+  struct Resettable {
+void reset() { /* Own reset logic */ }
+  };
+
+  auto ptr = std::make_unique();
+
+  ptr->reset();  // Calls underlying reset method
+  ptr.reset();   // Makes the pointer null
+
+Both calls are valid C++ code, but the second one might not be what the
+developer intended, as it destroys the pointed-to object rather than resetting
+its state. It's easy to make such a typo because the difference between
+``.`` and ``->`` is really small.
+
+The recommended approach is to make the intent explicit by using either member
+access or direct assignment:
+
+.. code-block:: c++
+
+  std::unique_ptr ptr = std::make_unique();
+
+  (*ptr).reset();  // Clearly calls underlying reset method
+  ptr = nullptr;   // Clearly makes the pointer null
+
+The default smart pointers that are considered are ``std::unique_ptr``,
+``std::shared_ptr``, ``boost::unique_ptr``, ``boost::shared_ptr``. To specify
+other smart pointers or other classes use the :option:`SmartPointers` option.
+
+Options
+---
+
+.. option:: SmartPointers
+
+Semicolon-separated list of fully qualified class names of custom smart
+pointers. Default value is `::std::unique_ptr;::std::shared_ptr;

denzor200 wrote:

> consider adding std::optional here also (even that is not smart ptr)

Strictly disagree with you, optional-like classes are not assignable with 
`nullptr`.
Here is no place for them in this check otherwise it will produce wrong fix 
hints:

```
{
  std::optional o;
  o.reset(); // should produce `o = std::nullopt;` but `o = nullptr;` does
}
{
  boost::optional o;
  o.reset(); // should produce `o = boost::none;` but `o = nullptr;` does
}

```

https://godbolt.org/z/YM79G8zdP


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


[clang] fd5d1cb - [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo as well (#128106)

2025-02-20 Thread via cfe-commits

Author: Nathan Ridge
Date: 2025-02-21T00:45:51-05:00
New Revision: fd5d1cbb75e4278d9074ff105efd3ab48f778b4b

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

LOG: [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo as well 
(#128106)

Added: 


Modified: 
clang/lib/Index/IndexTypeSourceInfo.cpp

Removed: 




diff  --git a/clang/lib/Index/IndexTypeSourceInfo.cpp 
b/clang/lib/Index/IndexTypeSourceInfo.cpp
index b986ccde57452..d5d0a3c422871 100644
--- a/clang/lib/Index/IndexTypeSourceInfo.cpp
+++ b/clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
@@ -207,27 +208,8 @@ class TypeIndexer : public 
RecursiveASTVisitor {
   }
 
   bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
-const DependentNameType *DNT = TL.getTypePtr();
-const NestedNameSpecifier *NNS = DNT->getQualifier();
-const Type *T = NNS->getAsType();
-if (!T)
-  return true;
-const TemplateSpecializationType *TST =
-T->getAs();
-if (!TST)
-  return true;
-TemplateName TN = TST->getTemplateName();
-const ClassTemplateDecl *TD =
-dyn_cast_or_null(TN.getAsTemplateDecl());
-if (!TD)
-  return true;
-CXXRecordDecl *RD = TD->getTemplatedDecl();
-if (!RD->hasDefinition())
-  return true;
-RD = RD->getDefinition();
-DeclarationName Name(DNT->getIdentifier());
-std::vector Symbols = RD->lookupDependentName(
-Name, [](const NamedDecl *ND) { return isa(ND); });
+std::vector Symbols =
+IndexCtx.getResolver()->resolveDependentNameType(TL.getTypePtr());
 if (Symbols.size() != 1)
   return true;
 return IndexCtx.handleReference(Symbols[0], TL.getNameLoc(), Parent,



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


[clang] [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo as well (PR #128106)

2025-02-20 Thread Nathan Ridge via cfe-commits

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


[clang] [Clang] Implement the core language parts of P2786 - Trivial relocation (PR #127636)

2025-02-20 Thread Younan Zhang via cfe-commits


@@ -7258,6 +7261,217 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
   }
 }
 
+static bool hasSuitableConstructorForReplaceability(CXXRecordDecl *D,
+bool Implicit) {
+  assert(D->hasDefinition() && !D->isInvalidDecl());
+
+  bool HasDeletedMoveConstructor = false;
+  bool HasDeletedCopyConstructor = false;
+  bool HasMoveConstructor = D->needsImplicitMoveConstructor();
+  bool HasDefaultedMoveConstructor = D->needsImplicitMoveConstructor();
+  bool HasDefaultedCopyConstructor = D->needsImplicitMoveConstructor();
+
+  for (const Decl *D : D->decls()) {
+auto *MD = dyn_cast(D);
+if (!MD || MD->isIneligibleOrNotSelected())
+  continue;
+
+if (MD->isMoveConstructor()) {
+  HasMoveConstructor = true;
+  if (MD->isDefaulted())
+HasDefaultedMoveConstructor = true;
+  if (MD->isDeleted())
+HasDeletedMoveConstructor = true;
+}
+if (MD->isCopyConstructor()) {
+  if (MD->isDefaulted())
+HasDefaultedCopyConstructor = true;
+  if (MD->isDeleted())
+HasDeletedCopyConstructor = true;
+}
+  }
+
+  if (HasMoveConstructor)
+return !HasDeletedMoveConstructor &&
+   (Implicit ? HasDefaultedMoveConstructor : true);
+  return !HasDeletedCopyConstructor &&
+ (Implicit ? HasDefaultedCopyConstructor : true);
+  ;
+}
+
+static bool hasSuitableMoveAssignmentOperatorForReplaceability(CXXRecordDecl 
*D,
+   bool Implicit) {
+  assert(D->hasDefinition() && !D->isInvalidDecl());
+
+  if (D->hasExplicitlyDeletedMoveAssignment())
+return false;
+
+  bool HasDeletedMoveAssignment = false;
+  bool HasDeletedCopyAssignment = false;
+  bool HasMoveAssignment = D->needsImplicitMoveAssignment();
+  bool HasDefaultedMoveAssignment = D->needsImplicitMoveAssignment();
+  bool HasDefaultedCopyAssignment = D->needsImplicitCopyAssignment();
+
+  for (const Decl *D : D->decls()) {
+auto *MD = dyn_cast(D);
+if (!MD || MD->isIneligibleOrNotSelected())
+  continue;
+
+if (MD->isMoveAssignmentOperator()) {
+  HasMoveAssignment = true;
+  if (MD->isDefaulted())
+HasDefaultedMoveAssignment = true;
+  if (MD->isDeleted())
+HasDeletedMoveAssignment = true;
+}
+if (MD->isCopyAssignmentOperator()) {
+  if (MD->isDefaulted())
+HasDefaultedCopyAssignment = true;
+  if (MD->isDeleted())
+HasDeletedCopyAssignment = true;
+}
+  }
+
+  if (HasMoveAssignment)
+return !HasDeletedMoveAssignment &&
+   (Implicit ? HasDefaultedMoveAssignment : true);
+  return !HasDeletedCopyAssignment &&
+ (Implicit ? HasDefaultedCopyAssignment : true);
+}
+
+void Sema::CheckCXX2CTriviallyRelocatable(CXXRecordDecl *D) {
+  if (!D->hasDefinition() || D->isInvalidDecl())
+return;
+
+  bool MarkedTriviallyRelocatable =
+  D->getTriviallyRelocatableSpecifier().isSet();
+
+  bool IsTriviallyRelocatable = true;
+  for (const CXXBaseSpecifier &B : D->bases()) {
+const auto *BaseDecl = B.getType()->getAsCXXRecordDecl();
+if (!BaseDecl)
+  continue;
+if (B.isVirtual() ||
+(!BaseDecl->isDependentType() && !BaseDecl->isTriviallyRelocatable())) 
{
+  IsTriviallyRelocatable = false;
+}
+  }
+
+  for (const FieldDecl *Field : D->fields()) {
+if (Field->getType()->isDependentType())
+  continue;
+if (Field->getType()->isReferenceType())
+  continue;
+QualType T = getASTContext().getBaseElementType(
+Field->getType().getUnqualifiedType());
+if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) {
+  if (RD->isTriviallyRelocatable())
+continue;
+  IsTriviallyRelocatable = false;
+  break;
+}
+  }
+
+  if (!D->isDependentType() && !MarkedTriviallyRelocatable) {
+bool HasSuitableMoveCtr = D->needsImplicitMoveConstructor();
+bool HasSuitableCopyCtr = false;
+if (D->hasUserDeclaredDestructor()) {
+  const auto *Dtr = D->getDestructor();
+  if (Dtr && (!Dtr->isDefaulted() || Dtr->isDeleted()))
+IsTriviallyRelocatable = false;
+}
+if (IsTriviallyRelocatable && !HasSuitableMoveCtr) {
+  for (const CXXConstructorDecl *CD : D->ctors()) {
+if (CD->isMoveConstructor() && CD->isDefaulted() &&
+!CD->isIneligibleOrNotSelected()) {
+  HasSuitableMoveCtr = true;
+  break;
+}
+  }
+}
+if (!HasSuitableMoveCtr && !D->hasMoveConstructor()) {
+  HasSuitableCopyCtr = D->needsImplicitCopyConstructor();
+  if (!HasSuitableCopyCtr) {
+for (const CXXConstructorDecl *CD : D->ctors()) {
+  if (CD->isCopyConstructor() && CD->isDefaulted() &&
+  !CD->isIneligibleOrNotSelected()) {
+HasSuitableCopyCtr = true;
+break;
+  }
+}
+  }
+}
+
+if (D->isUnion() && !D->hasUserDeclaredCopyConstructor() &&
+!D->hasU

[clang] [Clang] Implement the core language parts of P2786 - Trivial relocation (PR #127636)

2025-02-20 Thread Younan Zhang via cfe-commits


@@ -12427,6 +12427,11 @@ def err_builtin_invalid_arg_type: Error <
   "an 'int'|"
   "a vector of floating points}1 (was %2)">;
 
+def err_builtin_trivially_relocate_invalid_arg_type: Error <
+  "first%select{||| and second}0 argument%select{|||s}0 to "

zyn0217 wrote:

Can we use `%plural` or `%s` format specifier? Moreover, we might want to 
replace `%select` with `%enum_select`

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


[clang] [Clang] Implement the core language parts of P2786 - Trivial relocation (PR #127636)

2025-02-20 Thread Younan Zhang via cfe-commits


@@ -2862,6 +2862,30 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext &Context) const {
   }
 }
 
+bool QualType::isCppTriviallyRelocatableType(const ASTContext &Context) const {
+  QualType BaseElementType = Context.getBaseElementType(*this);
+  if (BaseElementType->isIncompleteType())
+return false;
+  else if (BaseElementType->isScalarType())
+return true;
+  else if (const auto *RD = BaseElementType->getAsCXXRecordDecl())
+return RD->isTriviallyRelocatable();

zyn0217 wrote:

```suggestion
  if (BaseElementType->isScalarType())
return true;
  if (const auto *RD = BaseElementType->getAsCXXRecordDecl())
return RD->isTriviallyRelocatable();
```

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


[clang] [Clang] Implement the core language parts of P2786 - Trivial relocation (PR #127636)

2025-02-20 Thread Younan Zhang via cfe-commits


@@ -757,7 +757,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_explicit_this_parameter", "202110L");
   }
 
-  // We provide those C++23 features as extensions in earlier language modes, 
so
+  // We provide those C++2b features as extensions in earlier language modes, 
so

zyn0217 wrote:

Why c++2b?

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


[clang] [CIR] Initial implementation of lowering CIR to MLIR (PR #127835)

2025-02-20 Thread Valentin Clement バレンタイン クレメン via cfe-commits


@@ -2958,6 +2958,8 @@ defm clangir : BoolFOption<"clangir",
   BothFlags<[], [ClangOption, CC1Option], "">>;
 def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,
   Group, HelpText<"Build ASTs and then lower to ClangIR">;
+def emit_cir_mlir : Flag<["-"], "emit-cir-mlir">, Visibility<[CC1Option]>, 
Group,

clementval wrote:

I double checked in flang and we have a couple of tests (7 files) using that 
option but we can switch these to use `-emit-fir` or -`emit-hlfir`. 

@banach-space Since you are probably the initial author of this option, do you 
have any objection to make `-emit-mlir` identical for clang and flang? 



https://github.com/llvm/llvm-project/pull/127835
___
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-02-20 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] [WebAssembly] Generate invokes with llvm.wasm.(re)throw (PR #128105)

2025-02-20 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.


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


[clang] [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo as well (PR #128106)

2025-02-20 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/128106

None

>From 10edf87574f5473da01bd985cec4c7810f57c516 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 20 Feb 2025 20:44:52 -0500
Subject: [PATCH] [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo
 as well

---
 clang/lib/Index/IndexTypeSourceInfo.cpp | 24 +++-
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Index/IndexTypeSourceInfo.cpp 
b/clang/lib/Index/IndexTypeSourceInfo.cpp
index b986ccde57452..d5d0a3c422871 100644
--- a/clang/lib/Index/IndexTypeSourceInfo.cpp
+++ b/clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
@@ -207,27 +208,8 @@ class TypeIndexer : public 
RecursiveASTVisitor {
   }
 
   bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
-const DependentNameType *DNT = TL.getTypePtr();
-const NestedNameSpecifier *NNS = DNT->getQualifier();
-const Type *T = NNS->getAsType();
-if (!T)
-  return true;
-const TemplateSpecializationType *TST =
-T->getAs();
-if (!TST)
-  return true;
-TemplateName TN = TST->getTemplateName();
-const ClassTemplateDecl *TD =
-dyn_cast_or_null(TN.getAsTemplateDecl());
-if (!TD)
-  return true;
-CXXRecordDecl *RD = TD->getTemplatedDecl();
-if (!RD->hasDefinition())
-  return true;
-RD = RD->getDefinition();
-DeclarationName Name(DNT->getIdentifier());
-std::vector Symbols = RD->lookupDependentName(
-Name, [](const NamedDecl *ND) { return isa(ND); });
+std::vector Symbols =
+IndexCtx.getResolver()->resolveDependentNameType(TL.getTypePtr());
 if (Symbols.size() != 1)
   return true;
 return IndexCtx.handleReference(Symbols[0], TL.getNameLoc(), Parent,

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


[clang] [clang-tools-extra] [libcxx] [llvm] [libc++][ranges] P2542R8: Implement `views::concat` (PR #120920)

2025-02-20 Thread A. Jiang via cfe-commits


@@ -0,0 +1,646 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___RANGES_CONCAT_VIEW_H
+#define _LIBCPP___RANGES_CONCAT_VIEW_H
+
+#include <__algorithm/ranges_find_if.h>
+#include <__assert>
+#include <__concepts/common_reference_with.h>
+#include <__concepts/constructible.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/copyable.h>
+#include <__concepts/derived_from.h>
+#include <__concepts/equality_comparable.h>
+#include <__concepts/swappable.h>
+#include <__config>
+#include <__functional/bind_back.h>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/default_sentinel.h>
+#include <__iterator/distance.h>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iter_swap.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__memory/addressof.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/movable_box.h>
+#include <__ranges/non_propagating_cache.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__ranges/zip_view.h>
+#include <__type_traits/conditional.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/is_nothrow_constructible.h>
+#include <__type_traits/is_nothrow_convertible.h>
+#include <__type_traits/is_object.h>
+#include <__type_traits/make_unsigned.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
+#include 
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+namespace ranges {
+
+#  ifdef __cpp_pack_indexing
+template 
+using __extract_last _LIBCPP_NODEBUG = _Tp...[sizeof...(_Tp) - 1];
+#  else
+template 
+struct __extract_last_impl : __extract_last_impl<_Tail...> {};
+template 
+struct __extract_last_impl<_Tp> {
+  using type _LIBCPP_NODEBUG = _Tp;
+};
+
+template 
+using __extract_last _LIBCPP_NODEBUG = __extract_last_impl<_Tp...>::type;
+#  endif
+
+template 
+constexpr bool __derived_from_pack =
+__derived_from_pack<_Tp, __extract_last<_Tail...>> && 
__derived_from_pack<_Tail...>;
+
+template 
+constexpr bool __derived_from_pack<_Tp, _IterCategory> = derived_from<_Tp, 
_IterCategory>;
+
+template 
+struct __last_view : __last_view<_Views...> {};
+
+template 
+struct __last_view<_View> {
+  using type = _View;
+};
+
+template 
+concept __concat_indirectly_readable_impl = requires(const _It __it) {
+  { *__it } -> convertible_to<_Ref>;
+  { ranges::iter_move(__it) } -> convertible_to<_RRef>;
+};
+
+template 
+using __concat_reference_t _LIBCPP_NODEBUG = 
common_reference_t...>;
+
+template 
+using __concat_value_t _LIBCPP_NODEBUG = common_type_t...>;
+
+template 
+using __concat_rvalue_reference_t _LIBCPP_NODEBUG = 
common_reference_t...>;
+
+template 
+concept __concat_indirectly_readable =
+common_reference_with<__concat_reference_t<_Rs...>&&, 
__concat_value_t<_Rs...>&> &&
+common_reference_with<__concat_reference_t<_Rs...>&&, 
__concat_rvalue_reference_t<_Rs...>&&> &&
+common_reference_with<__concat_rvalue_reference_t<_Rs...>&&, 
__concat_value_t<_Rs...> const&> &&
+(__concat_indirectly_readable_impl<__concat_reference_t<_Rs...>,
+   __concat_rvalue_reference_t<_Rs...>,
+   iterator_t<_Rs>> &&
+ ...);
+
+template 
+concept __concatable = requires {
+  typename __concat_reference_t<_Rs...>;
+  typename __concat_value_t<_Rs...>;
+  typename __concat_rvalue_reference_t<_Rs...>;
+} && __concat_indirectly_readable<_Rs...>;
+
+template 
+concept __concat_is_random_access =
+(random_access_range<__maybe_const<_Const, _Rs>> && ...) && 
(sized_range<__maybe_const<_Const, _Rs>> && ...);
+
+template 
+concept __concat_is_bidirectional =
+((bidirectional_range<__maybe_const<_Const, _Rs>> && ...) && 
(common_range<__maybe_const<_Const, _Rs>> && ...));
+
+template 
+concept __all_forward = (forward_range<__maybe_const<_Const, _Views>> && ...);
+
+template 
+struct __apply_drop_first;
+
+template 
+struct __apply_drop_first<_Const, _Head, _Tail...> {
+  static constexpr bool value = (sized_range<__maybe_const<_Const, _Tail>> && 
...);
+};
+
+template 
+  requires(view<_Views> && ...) && (sizeof...(_Views) > 0) && 
__concatable<_Views...>
+class concat_view : public view

[clang] [clang] Improve module out of date error message (PR #128103)

2025-02-20 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

would you like to add a test?

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-20 Thread via cfe-commits


@@ -0,0 +1,16 @@
+/// Check the max-page-size for OHOS aarch64/loongarch64/riscv64/x86_64.

Ami-zhang wrote:

Removed the new file and added the page-size check in ohos.c, following the 
style of similar tests. Thanks!

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


[clang] [clang-tools-extra] [libcxx] [llvm] [libc++][ranges] P2542R8: Implement `views::concat` (PR #120920)

2025-02-20 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja edited 
https://github.com/llvm/llvm-project/pull/120920
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a60675d - [CodeGen][NFC] Move test builtin_signbit.cpp to CodeGen (#127814)

2025-02-20 Thread via cfe-commits

Author: Donát Nagy
Date: 2025-02-20T10:56:02+01:00
New Revision: a60675d22723d682ba66c769ccb2b42e0b825a04

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

LOG: [CodeGen][NFC] Move test builtin_signbit.cpp to CodeGen (#127814)

Because it is one of the three "misplaced" test files that appeared
under `/clang/test/Analysis` but were unrelated to the clang static
analyzer. For background see the following discourse thread:
https://discourse.llvm.org/t/taking-ownership-of-clang-test-analysis/84689/2

I placed this file in `clang/test/CodeGen` because as far as I see it
tests the code generated from `__builtin_signbit` (and there are many
other `builtin_*` test files in that directory); but I'm not familiar
with that area, so I'm not certain that it's the best place.

Added: 
clang/test/CodeGen/builtin_signbit.cpp

Modified: 


Removed: 
clang/test/Analysis/builtin_signbit.cpp



diff  --git a/clang/test/Analysis/builtin_signbit.cpp 
b/clang/test/CodeGen/builtin_signbit.cpp
similarity index 100%
rename from clang/test/Analysis/builtin_signbit.cpp
rename to clang/test/CodeGen/builtin_signbit.cpp



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


[clang] [CodeGen][NFC] Move test builtin_signbit.cpp to CodeGen (PR #127814)

2025-02-20 Thread Donát Nagy via cfe-commits

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


[clang] [Clang] Mark P1061 (Structured Bindings can introduce a Pack) as implemented (PR #127980)

2025-02-20 Thread via cfe-commits

cor3ntin wrote:

Note that there does not seem to be any appetite to backport that to 20 - 
despite limited risks - so we mark it as a Clang 21 feature

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


[clang] dc326d0 - [Clang][doc] -ffp-contract options and standard compliance (#127621)

2025-02-20 Thread via cfe-commits

Author: Sjoerd Meijer
Date: 2025-02-20T10:10:23Z
New Revision: dc326d0b01f63e49f4f11c0c332369bf109721df

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

LOG: [Clang][doc] -ffp-contract options and standard compliance (#127621)

We had an discussion about -ffp-contract, how it compared to GCC which defaults
to fast, and standard compliance. Looking at our docs, most information is
there, but this clarifies when this option is and isn't standard compliant.

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index d977868b8a2c6..8213334b61c22 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1681,19 +1681,27 @@ for more details.
permitted to produce more precise results than performing the same
operations separately.
 
-   The C standard permits intermediate floating-point results within an
+   The C and C++ standards permit intermediate floating-point results within an
expression to be computed with more precision than their type would
normally allow. This permits operation fusing, and Clang takes advantage
-   of this by default. This behavior can be controlled with the ``FP_CONTRACT``
-   and ``clang fp contract`` pragmas. Please refer to the pragma documentation
-   for a description of how the pragmas interact with this option.
+   of this by default (``on``). Fusion across statements is not compliant with
+   the C and C++ standards but can be enabled using ``-ffp-contract=fast``.
+
+   Fusion can be controlled with the ``FP_CONTRACT`` and ``clang fp contract``
+   pragmas. Please note that pragmas will be ingored with
+   ``-ffp-contract=fast``, and refer to the pragma documentation for a
+   description of how the pragmas interact with the 
diff erent ``-ffp-contract``
+   option values.
 
Valid values are:
 
-   * ``fast`` (fuse across statements disregarding pragmas, default for CUDA)
-   * ``on`` (fuse in the same statement unless dictated by pragmas, default 
for languages other than CUDA/HIP)
-   * ``off`` (never fuse)
-   * ``fast-honor-pragmas`` (fuse across statements unless dictated by 
pragmas, default for HIP)
+   * ``fast``: enable fusion across statements disregarding pragmas, breaking
+ compliance with the C and C++ standards (default for CUDA).
+   * ``on``: enable C and C++ standard complaint fusion in the same statement
+ unless dictated by pragmas (default for languages other than CUDA/HIP)
+   * ``off``: disable fusion
+   * ``fast-honor-pragmas``: fuse across statements unless dictated by pragmas
+ (default for HIP)
 
 .. option:: -f[no-]honor-infinities
 



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


[clang] [CodeGen][NFC] Move test builtin_signbit.cpp to CodeGen (PR #127814)

2025-02-20 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`clang` at step 7 "Add check check-offload".

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


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

```
Step 7 (Add check check-offload) failure: test (failure)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
offloading/pgo1.c' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test 
-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib
  -fopenmp-targets=amdgcn-amd-amdhsa 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/pgo1.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/pgo1.c.tmp
 -Xoffload-linker -lc -Xoffload-linker -lm 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
 -fprofile-generate  -Xclang "-fprofile-instrument=llvm"
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test 
-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib
 -fopenmp-targets=amdgcn-amd-amdhsa 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/pgo1.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/pgo1.c.tmp
 -Xoffload-linker -lc -Xoffload-linker -lm 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
 -fprofile-generate -Xclang -fprofile-instrument=llvm
# RUN: at line 3
env LLVM_PROFILE_FILE=llvm.profraw 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/pgo1.c.tmp
 2>&1
# executed command: env LLVM_PROFILE_FILE=llvm.profraw 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/pgo1.c.tmp
# RUN: at line 4
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/llvm-profdata
 show --all-functions --counts  amdgcn-amd-amdhsa.llvm.profraw | 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/pgo1.c
  --check-prefix="LLVM-PGO"
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/llvm-profdata
 show --all-functions --counts amdgcn-amd-amdhsa.llvm.profraw
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/pgo1.c
 --check-prefix=LLVM-PGO
# RUN: at line 8
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test 
-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offl

[clang] [Clang][doc] -ffp-contract options and standard compliance (PR #127621)

2025-02-20 Thread Sjoerd Meijer via cfe-commits

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


[clang] [flang] [flang] Align `-x f95[-cpp-input]` language modes with `gfortran` (PR #127986)

2025-02-20 Thread Iñaki Amatria Barral via cfe-commits

https://github.com/inaki-amatria created 
https://github.com/llvm/llvm-project/pull/127986

This PR may solve some of the issues described in: 
https://github.com/llvm/llvm-project/issues/127617.

The reason to revert 
https://github.com/llvm/llvm-project/commit/81d82cac8c4cbd006bf991fd7380de2d72858d1c
 is detailed in the associated issue.

From e76692d226487b4b5c6c18caedd2ee5d9a86d42b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?I=C3=B1aki=20Amatria=20Barral?= 
Date: Thu, 20 Feb 2025 10:40:22 +0100
Subject: [PATCH 1/2] Revert "[flang] Treat pre-processed input as fixed
 (#117563)"

This reverts commit 81d82cac8c4cbd006bf991fd7380de2d72858d1c.
---
 clang/lib/Driver/ToolChains/Flang.cpp |  7 ---
 flang/test/Driver/pp-fixed-form.f90   | 19 ---
 2 files changed, 26 deletions(-)
 delete mode 100644 flang/test/Driver/pp-fixed-form.f90

diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 9ad795edd724d..bb308c45eb64b 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -803,13 +803,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   addFortranDialectOptions(Args, CmdArgs);
 
-  // 'flang -E' always produces output that is suitable for use as fixed form
-  // Fortran. However it is only valid free form source if the original is also
-  // free form.
-  if (InputType == types::TY_PP_Fortran &&
-  !Args.getLastArg(options::OPT_ffixed_form, options::OPT_ffree_form))
-CmdArgs.push_back("-ffixed-form");
-
   handleColorDiagnosticsArgs(D, Args, CmdArgs);
 
   // LTO mode is parsed by the Clang driver library.
diff --git a/flang/test/Driver/pp-fixed-form.f90 
b/flang/test/Driver/pp-fixed-form.f90
deleted file mode 100644
index 4695da78763ae..0
--- a/flang/test/Driver/pp-fixed-form.f90
+++ /dev/null
@@ -1,19 +0,0 @@
-!RUN: %flang -save-temps -### %S/Inputs/free-form-test.f90  2>&1 | FileCheck 
%s --check-prefix=FREE
-FREE:   "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95-cpp-input" 
"{{.*}}/free-form-test.f90"
-FREE-NEXT:  "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "free-form-test.i"
-
-!RUN: %flang -save-temps -### %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s 
--check-prefix=FIXED
-FIXED:  "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95-cpp-input" 
"{{.*}}/fixed-form-test.f"
-FIXED-NEXT: "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "fixed-form-test.i"
-
-!RUN: %flang -save-temps -### -ffree-form %S/Inputs/free-form-test.f90  2>&1 | 
FileCheck %s --check-prefix=FREE-FLAG
-FREE-FLAG:   "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" 
"f95-cpp-input" "{{.*}}/free-form-test.f90"
-FREE-FLAG-NEXT:  "-fc1" {{.*}} "-emit-llvm-bc" "-ffree-form"
-FREE-FLAG-NOT:   "-ffixed-form"
-FREE-FLAG-SAME:  "-x" "f95" "free-form-test.i"
-
-!RUN: %flang -save-temps -### -ffixed-form %S/Inputs/fixed-form-test.f  2>&1 | 
FileCheck %s --check-prefix=FIXED-FLAG
-FIXED-FLAG:  "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" 
"f95-cpp-input" "{{.*}}/fixed-form-test.f"
-FIXED-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" "-ffixed-form"
-FIXED-FLAG-NOT:  "-ffixed-form"
-FIXED-FLAG-SAME: "-x" "f95" "fixed-form-test.i"

From a989adb98ba03742c0615a526d630b4a225503e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?I=C3=B1aki=20Amatria=20Barral?= 
Date: Thu, 20 Feb 2025 11:14:19 +0100
Subject: [PATCH 2/2] [flang] Align `-x f95-cpp-input` with `gfortran`

---
 flang/lib/Frontend/CompilerInvocation.cpp |  6 
 flang/test/Driver/dash-x-f95.f| 35 +++
 .../input-from-stdin/input-from-stdin.f90 |  2 +-
 3 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/dash-x-f95.f

diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index f3d9432c62d3b..1b68dee8b169d 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -859,6 +859,12 @@ static void 
parsePreprocessorArgs(Fortran::frontend::PreprocessorOptions &opts,
 (currentArg->getOption().matches(clang::driver::options::OPT_cpp))
 ? PPMacrosFlag::Include
 : PPMacrosFlag::Exclude;
+  // Enable -cpp based on -x unless explicitly disabled with -nocpp
+  if (const auto *dashX = args.getLastArg(clang::driver::options::OPT_x);
+  dashX && opts.macrosFlag != PPMacrosFlag::Exclude)
+opts.macrosFlag = llvm::StringSwitch(dashX->getValue())
+  .Case("f95-cpp-input", PPMacrosFlag::Include)
+  .Default(opts.macrosFlag);
 
   opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat);
   opts.preprocessIncludeLines =
diff --git a/flang/test/Driver/dash-x-f95.f b/flang/test/Driver/dash-x-f95.f
new file mode 100644
index 0..ae9a426a9d956
--- /dev/null
+++ b/flang/test/Driver/dash-x-f95.f
@@ -0,0 +1,35 @@
+program main
+  print *, __FILE__, _

[clang] Revert "[clang] Lower modf builtin using `llvm.modf` intrinsic" (PR #127987)

2025-02-20 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue created 
https://github.com/llvm/llvm-project/pull/127987

Reverts llvm/llvm-project#126750

Revering while I investigate: 
https://lab.llvm.org/buildbot/#/builders/72/builds/8406 

>From e082cbf5fd4f889762e12062d2544f862339b959 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Thu, 20 Feb 2025 10:24:31 +
Subject: [PATCH] Revert "[clang] Lower modf builtin using `llvm.modf`
 intrinsic (#126750)"

This reverts commit d804c838933b1f35ae56343afac669ffe3bbd957.
---
 clang/lib/CodeGen/CGBuiltin.cpp  | 27 
 clang/test/CodeGen/X86/math-builtins.c   | 32 ++--
 clang/test/CodeGen/aix-builtin-mapping.c |  2 +-
 clang/test/CodeGen/builtin-attributes.c  | 11 +++-
 clang/test/CodeGen/math-builtins-long.c  |  6 ++---
 clang/test/CodeGen/math-libcalls.c   | 12 -
 6 files changed, 20 insertions(+), 70 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a73ba1ff138fb..4625bf8088be6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -859,24 +859,6 @@ static void emitSincosBuiltin(CodeGenFunction &CGF, const 
CallExpr *E,
   StoreCos->setMetadata(LLVMContext::MD_noalias, AliasScopeList);
 }
 
-static llvm::Value *emitModfBuiltin(CodeGenFunction &CGF, const CallExpr *E,
-llvm::Intrinsic::ID IntrinsicID) {
-  llvm::Value *Val = CGF.EmitScalarExpr(E->getArg(0));
-  llvm::Value *IntPartDest = CGF.EmitScalarExpr(E->getArg(1));
-
-  llvm::Value *Call =
-  CGF.Builder.CreateIntrinsic(IntrinsicID, {Val->getType()}, Val);
-
-  llvm::Value *FractionalResult = CGF.Builder.CreateExtractValue(Call, 0);
-  llvm::Value *IntegralResult = CGF.Builder.CreateExtractValue(Call, 1);
-
-  QualType DestPtrType = E->getArg(1)->getType()->getPointeeType();
-  LValue IntegralLV = CGF.MakeNaturalAlignAddrLValue(IntPartDest, DestPtrType);
-  CGF.EmitStoreOfScalar(IntegralResult, IntegralLV);
-
-  return FractionalResult;
-}
-
 /// EmitFAbs - Emit a call to @llvm.fabs().
 static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
   Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
@@ -4130,15 +4112,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_frexpf128:
   case Builtin::BI__builtin_frexpf16:
 return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp));
-  case Builtin::BImodf:
-  case Builtin::BImodff:
-  case Builtin::BImodfl:
-  case Builtin::BI__builtin_modf:
-  case Builtin::BI__builtin_modff:
-  case Builtin::BI__builtin_modfl:
-if (Builder.getIsFPConstrained())
-  break; // TODO: Emit constrained modf intrinsic once one exists.
-return RValue::get(emitModfBuiltin(*this, E, Intrinsic::modf));
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:
diff --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index d5301b7bafd9c..d7bf7d57fba26 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -38,24 +38,6 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 // NO__ERRNO-NEXT: [[FREXP_F128_0:%.+]] = extractvalue { fp128, i32 } 
[[FREXP_F128]], 0
 
 
-// NO__ERRNO: [[MODF_F64:%.+]] = call { double, double } @llvm.modf.f64(double 
%{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F64_FP:%.+]] = extractvalue { double, double } 
[[MODF_F64]], 0
-// NO__ERRNO-NEXT: [[MODF_F64_IP:%.+]] = extractvalue { double, double } 
[[MODF_F64]], 1
-// NO__ERRNO-NEXT: store double [[MODF_F64_IP]], ptr %{{.+}}, align 8
-
-// NO__ERRNO: [[MODF_F32:%.+]] = call { float, float } @llvm.modf.f32(float 
%{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F32_FP:%.+]] = extractvalue { float, float } 
[[MODF_F32]], 0
-// NO__ERRNO-NEXT: [[MODF_F32_IP:%.+]] = extractvalue { float, float } 
[[MODF_F32]], 1
-// NO__ERRNO-NEXT: store float [[MODF_F32_IP]], ptr %{{.+}}, align 4
-
-// NO__ERRNO: [[MODF_F80:%.+]] = call { x86_fp80, x86_fp80 } 
@llvm.modf.f80(x86_fp80 %{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F80_FP:%.+]] = extractvalue { x86_fp80, x86_fp80 } 
[[MODF_F80]], 0
-// NO__ERRNO-NEXT: [[MODF_F80_IP:%.+]] = extractvalue { x86_fp80, x86_fp80 } 
[[MODF_F80]], 1
-// NO__ERRNO-NEXT: store x86_fp80 [[MODF_F80_IP]], ptr %{{.+}}, align 16
-
-// NO__ERRNO: call fp128 @modff128(fp128 noundef %{{.+}}, ptr noundef %{{.+}})
-
-
 // NO__ERRNO: [[SINCOS_F64:%.+]] = call { double, double } 
@llvm.sincos.f64(double %{{.+}})
 // NO__ERRNO-NEXT: [[SINCOS_F64_0:%.+]] = extractvalue { double, double } 
[[SINCOS_F64]], 0
 // NO__ERRNO-NEXT: [[SINCOS_F64_1:%.+]] = extractvalue { double, double } 
[[SINCOS_F64]], 1
@@ -157,13 +139,13 @@ void foo(double *d, float f, float *fp, long double *l, 
int *i, const char *c) {
 
   __builtin_modf(f,d);   __builtin_modff(f,fp);  __builtin_modfl(f,l); 
__builtin_modff128(f,l);
 
-// NO_

[clang] [flang] [flang] Align `-x f95[-cpp-input]` language modes with `gfortran` (PR #127986)

2025-02-20 Thread Iñaki Amatria Barral via cfe-commits

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


[clang] d595fc9 - Revert "[clang] Lower modf builtin using `llvm.modf` intrinsic" (#127987)

2025-02-20 Thread via cfe-commits

Author: Benjamin Maxwell
Date: 2025-02-20T10:25:18Z
New Revision: d595fc91aeb35cb7fad8ad37fa84a70863b09f69

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

LOG: Revert "[clang] Lower modf builtin using `llvm.modf` intrinsic" (#127987)

Reverts llvm/llvm-project#126750

Revering while I investigate:
https://lab.llvm.org/buildbot/#/builders/72/builds/8406

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/X86/math-builtins.c
clang/test/CodeGen/aix-builtin-mapping.c
clang/test/CodeGen/builtin-attributes.c
clang/test/CodeGen/math-builtins-long.c
clang/test/CodeGen/math-libcalls.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a73ba1ff138fb..4625bf8088be6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -859,24 +859,6 @@ static void emitSincosBuiltin(CodeGenFunction &CGF, const 
CallExpr *E,
   StoreCos->setMetadata(LLVMContext::MD_noalias, AliasScopeList);
 }
 
-static llvm::Value *emitModfBuiltin(CodeGenFunction &CGF, const CallExpr *E,
-llvm::Intrinsic::ID IntrinsicID) {
-  llvm::Value *Val = CGF.EmitScalarExpr(E->getArg(0));
-  llvm::Value *IntPartDest = CGF.EmitScalarExpr(E->getArg(1));
-
-  llvm::Value *Call =
-  CGF.Builder.CreateIntrinsic(IntrinsicID, {Val->getType()}, Val);
-
-  llvm::Value *FractionalResult = CGF.Builder.CreateExtractValue(Call, 0);
-  llvm::Value *IntegralResult = CGF.Builder.CreateExtractValue(Call, 1);
-
-  QualType DestPtrType = E->getArg(1)->getType()->getPointeeType();
-  LValue IntegralLV = CGF.MakeNaturalAlignAddrLValue(IntPartDest, DestPtrType);
-  CGF.EmitStoreOfScalar(IntegralResult, IntegralLV);
-
-  return FractionalResult;
-}
-
 /// EmitFAbs - Emit a call to @llvm.fabs().
 static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
   Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
@@ -4130,15 +4112,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_frexpf128:
   case Builtin::BI__builtin_frexpf16:
 return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp));
-  case Builtin::BImodf:
-  case Builtin::BImodff:
-  case Builtin::BImodfl:
-  case Builtin::BI__builtin_modf:
-  case Builtin::BI__builtin_modff:
-  case Builtin::BI__builtin_modfl:
-if (Builder.getIsFPConstrained())
-  break; // TODO: Emit constrained modf intrinsic once one exists.
-return RValue::get(emitModfBuiltin(*this, E, Intrinsic::modf));
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:

diff  --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index d5301b7bafd9c..d7bf7d57fba26 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -38,24 +38,6 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 // NO__ERRNO-NEXT: [[FREXP_F128_0:%.+]] = extractvalue { fp128, i32 } 
[[FREXP_F128]], 0
 
 
-// NO__ERRNO: [[MODF_F64:%.+]] = call { double, double } @llvm.modf.f64(double 
%{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F64_FP:%.+]] = extractvalue { double, double } 
[[MODF_F64]], 0
-// NO__ERRNO-NEXT: [[MODF_F64_IP:%.+]] = extractvalue { double, double } 
[[MODF_F64]], 1
-// NO__ERRNO-NEXT: store double [[MODF_F64_IP]], ptr %{{.+}}, align 8
-
-// NO__ERRNO: [[MODF_F32:%.+]] = call { float, float } @llvm.modf.f32(float 
%{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F32_FP:%.+]] = extractvalue { float, float } 
[[MODF_F32]], 0
-// NO__ERRNO-NEXT: [[MODF_F32_IP:%.+]] = extractvalue { float, float } 
[[MODF_F32]], 1
-// NO__ERRNO-NEXT: store float [[MODF_F32_IP]], ptr %{{.+}}, align 4
-
-// NO__ERRNO: [[MODF_F80:%.+]] = call { x86_fp80, x86_fp80 } 
@llvm.modf.f80(x86_fp80 %{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F80_FP:%.+]] = extractvalue { x86_fp80, x86_fp80 } 
[[MODF_F80]], 0
-// NO__ERRNO-NEXT: [[MODF_F80_IP:%.+]] = extractvalue { x86_fp80, x86_fp80 } 
[[MODF_F80]], 1
-// NO__ERRNO-NEXT: store x86_fp80 [[MODF_F80_IP]], ptr %{{.+}}, align 16
-
-// NO__ERRNO: call fp128 @modff128(fp128 noundef %{{.+}}, ptr noundef %{{.+}})
-
-
 // NO__ERRNO: [[SINCOS_F64:%.+]] = call { double, double } 
@llvm.sincos.f64(double %{{.+}})
 // NO__ERRNO-NEXT: [[SINCOS_F64_0:%.+]] = extractvalue { double, double } 
[[SINCOS_F64]], 0
 // NO__ERRNO-NEXT: [[SINCOS_F64_1:%.+]] = extractvalue { double, double } 
[[SINCOS_F64]], 1
@@ -157,13 +139,13 @@ void foo(double *d, float f, float *fp, long double *l, 
int *i, const char *c) {
 
   __builtin_modf(f,d);   __builtin_modff(f,fp);  __builtin_modfl(f,l); 
__builtin_modff128(f,l);
 
-// NO__ERRNO: declare { double, double }

[clang] Revert "[clang] Lower modf builtin using `llvm.modf` intrinsic" (PR #127987)

2025-02-20 Thread Benjamin Maxwell via cfe-commits

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


[clang] [flang] [flang] Align `-x f95[-cpp-input]` language modes with `gfortran` (PR #127986)

2025-02-20 Thread via cfe-commits
=?utf-8?q?Iñaki?= Amatria Barral 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-flang-driver

Author: Iñaki Amatria Barral (inaki-amatria)


Changes

This PR may solve some of the issues described in: 
https://github.com/llvm/llvm-project/issues/127617.

The reason to revert 
https://github.com/llvm/llvm-project/commit/81d82cac8c4cbd006bf991fd7380de2d72858d1c
 is detailed in the associated issue.

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


5 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Flang.cpp (-7) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+6) 
- (added) flang/test/Driver/dash-x-f95.f (+35) 
- (modified) flang/test/Driver/input-from-stdin/input-from-stdin.f90 (+1-1) 
- (removed) flang/test/Driver/pp-fixed-form.f90 (-19) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 9ad795edd724d..bb308c45eb64b 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -803,13 +803,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   addFortranDialectOptions(Args, CmdArgs);
 
-  // 'flang -E' always produces output that is suitable for use as fixed form
-  // Fortran. However it is only valid free form source if the original is also
-  // free form.
-  if (InputType == types::TY_PP_Fortran &&
-  !Args.getLastArg(options::OPT_ffixed_form, options::OPT_ffree_form))
-CmdArgs.push_back("-ffixed-form");
-
   handleColorDiagnosticsArgs(D, Args, CmdArgs);
 
   // LTO mode is parsed by the Clang driver library.
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index f3d9432c62d3b..1b68dee8b169d 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -859,6 +859,12 @@ static void 
parsePreprocessorArgs(Fortran::frontend::PreprocessorOptions &opts,
 (currentArg->getOption().matches(clang::driver::options::OPT_cpp))
 ? PPMacrosFlag::Include
 : PPMacrosFlag::Exclude;
+  // Enable -cpp based on -x unless explicitly disabled with -nocpp
+  if (const auto *dashX = args.getLastArg(clang::driver::options::OPT_x);
+  dashX && opts.macrosFlag != PPMacrosFlag::Exclude)
+opts.macrosFlag = llvm::StringSwitch(dashX->getValue())
+  .Case("f95-cpp-input", PPMacrosFlag::Include)
+  .Default(opts.macrosFlag);
 
   opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat);
   opts.preprocessIncludeLines =
diff --git a/flang/test/Driver/dash-x-f95.f b/flang/test/Driver/dash-x-f95.f
new file mode 100644
index 0..ae9a426a9d956
--- /dev/null
+++ b/flang/test/Driver/dash-x-f95.f
@@ -0,0 +1,35 @@
+program main
+  print *, __FILE__, __LINE__
+end
+
+! This test verifies that `flang`'s `-x` options behave like `gfortran`'s.
+! Specifically:
+! - `-x f95` should process the file based on its extension unless overridden.
+! - `-x f95-cpp-input` should behave like `-x f95` but with preprocessing
+!   (`-cpp`) enabled unless overridden.
+
+! ---
+! Ensure the file is treated as fixed-form unless explicitly set otherwise
+! ---
+! RUN: not %flang -Werror -x f95 -cpp -c %s 2>&1 | FileCheck 
--check-prefix=SCAN-ERROR %s
+! RUN: not %flang -Werror -x f95-cpp-input -c %s 2>&1 | FileCheck 
--check-prefix=SCAN-ERROR %s
+
+! SCAN-ERROR: error
+
+! RUN: %flang -Werror -x f95 -cpp -ffree-form -c %s 2>&1 | FileCheck 
--check-prefix=NO-SCAN-ERROR --allow-empty %s
+! RUN: %flang -Werror -x f95-cpp-input -ffree-form -c %s 2>&1 | FileCheck 
--check-prefix=NO-SCAN-ERROR --allow-empty %s
+
+! NO-SCAN-ERROR-NOT: error
+
+! ---
+! Ensure `-cpp` is not enabled by default unless explicitly requested
+! ---
+! RUN: not %flang -Werror -x f95 -ffree-form -c %s 2>&1 | FileCheck 
--check-prefix=SEMA-ERROR %s
+! RUN: not %flang -Werror -x f95-cpp-input -nocpp -ffree-form -c %s 2>&1 | 
FileCheck --check-prefix=SEMA-ERROR %s
+
+! SEMA-ERROR: error
+
+! RUN: %flang -Werror -x f95 -cpp -ffree-form -c %s 2>&1 | FileCheck 
--check-prefix=NO-SEMA-ERROR --allow-empty %s
+! RUN: %flang -Werror -x f95-cpp-input -ffree-form -c %s 2>&1 | FileCheck 
--check-prefix=NO-SEMA-ERROR --allow-empty %s
+
+! NO-SEMA-ERROR-NOT: error
diff --git a/flang/test/Driver/input-from-stdin/input-from-stdin.f90 
b/flang/test/Driver/input-from-stdin/input-from-stdin.f90
index 285f0751b35d8..1fcc0340a64ba 100644
--- a/flang/test/Driver/input-from-stdin/input-from-stdin.f90
+++ b/flang/test/Driver/input-from-stdin/input-from-stdin.f90
@@ -6,7 +6,7 @@
 ! Input type is implicit
 ! RUN: cat %s | %flang -E -cpp - | FileCheck %s --check-prefix=PP-NOT-DEFINED
 ! RUN: cat %s | %flang -DNEW -E -cpp - | FileCheck %s --check-prefix=PP-DEFINED
-! RUN: cat %s | %flang -DNEW -E - | FileCheck %s --check-prefix=PP-NOT-DEFINED
+! RUN: cat %s | %flang -DNEW -E - | FileCheck %s --check-prefix=PP-DEFINED
 ! RUN: cat %s |

[clang] [flang] [flang] Align `-x f95[-cpp-input]` language modes with `gfortran` (PR #127986)

2025-02-20 Thread Iñaki Amatria Barral via cfe-commits

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


[clang] Revert "[clang] Lower modf builtin using `llvm.modf` intrinsic" (PR #127987)

2025-02-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Benjamin Maxwell (MacDue)


Changes

Reverts llvm/llvm-project#126750

Revering while I investigate: 
https://lab.llvm.org/buildbot/#/builders/72/builds/8406 

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-27) 
- (modified) clang/test/CodeGen/X86/math-builtins.c (+7-25) 
- (modified) clang/test/CodeGen/aix-builtin-mapping.c (+1-1) 
- (modified) clang/test/CodeGen/builtin-attributes.c (+3-8) 
- (modified) clang/test/CodeGen/math-builtins-long.c (+3-3) 
- (modified) clang/test/CodeGen/math-libcalls.c (+6-6) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a73ba1ff138fb..4625bf8088be6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -859,24 +859,6 @@ static void emitSincosBuiltin(CodeGenFunction &CGF, const 
CallExpr *E,
   StoreCos->setMetadata(LLVMContext::MD_noalias, AliasScopeList);
 }
 
-static llvm::Value *emitModfBuiltin(CodeGenFunction &CGF, const CallExpr *E,
-llvm::Intrinsic::ID IntrinsicID) {
-  llvm::Value *Val = CGF.EmitScalarExpr(E->getArg(0));
-  llvm::Value *IntPartDest = CGF.EmitScalarExpr(E->getArg(1));
-
-  llvm::Value *Call =
-  CGF.Builder.CreateIntrinsic(IntrinsicID, {Val->getType()}, Val);
-
-  llvm::Value *FractionalResult = CGF.Builder.CreateExtractValue(Call, 0);
-  llvm::Value *IntegralResult = CGF.Builder.CreateExtractValue(Call, 1);
-
-  QualType DestPtrType = E->getArg(1)->getType()->getPointeeType();
-  LValue IntegralLV = CGF.MakeNaturalAlignAddrLValue(IntPartDest, DestPtrType);
-  CGF.EmitStoreOfScalar(IntegralResult, IntegralLV);
-
-  return FractionalResult;
-}
-
 /// EmitFAbs - Emit a call to @llvm.fabs().
 static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
   Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
@@ -4130,15 +4112,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_frexpf128:
   case Builtin::BI__builtin_frexpf16:
 return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp));
-  case Builtin::BImodf:
-  case Builtin::BImodff:
-  case Builtin::BImodfl:
-  case Builtin::BI__builtin_modf:
-  case Builtin::BI__builtin_modff:
-  case Builtin::BI__builtin_modfl:
-if (Builder.getIsFPConstrained())
-  break; // TODO: Emit constrained modf intrinsic once one exists.
-return RValue::get(emitModfBuiltin(*this, E, Intrinsic::modf));
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:
diff --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index d5301b7bafd9c..d7bf7d57fba26 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -38,24 +38,6 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 // NO__ERRNO-NEXT: [[FREXP_F128_0:%.+]] = extractvalue { fp128, i32 } 
[[FREXP_F128]], 0
 
 
-// NO__ERRNO: [[MODF_F64:%.+]] = call { double, double } @llvm.modf.f64(double 
%{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F64_FP:%.+]] = extractvalue { double, double } 
[[MODF_F64]], 0
-// NO__ERRNO-NEXT: [[MODF_F64_IP:%.+]] = extractvalue { double, double } 
[[MODF_F64]], 1
-// NO__ERRNO-NEXT: store double [[MODF_F64_IP]], ptr %{{.+}}, align 8
-
-// NO__ERRNO: [[MODF_F32:%.+]] = call { float, float } @llvm.modf.f32(float 
%{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F32_FP:%.+]] = extractvalue { float, float } 
[[MODF_F32]], 0
-// NO__ERRNO-NEXT: [[MODF_F32_IP:%.+]] = extractvalue { float, float } 
[[MODF_F32]], 1
-// NO__ERRNO-NEXT: store float [[MODF_F32_IP]], ptr %{{.+}}, align 4
-
-// NO__ERRNO: [[MODF_F80:%.+]] = call { x86_fp80, x86_fp80 } 
@llvm.modf.f80(x86_fp80 %{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F80_FP:%.+]] = extractvalue { x86_fp80, x86_fp80 } 
[[MODF_F80]], 0
-// NO__ERRNO-NEXT: [[MODF_F80_IP:%.+]] = extractvalue { x86_fp80, x86_fp80 } 
[[MODF_F80]], 1
-// NO__ERRNO-NEXT: store x86_fp80 [[MODF_F80_IP]], ptr %{{.+}}, align 16
-
-// NO__ERRNO: call fp128 @modff128(fp128 noundef %{{.+}}, ptr noundef %{{.+}})
-
-
 // NO__ERRNO: [[SINCOS_F64:%.+]] = call { double, double } 
@llvm.sincos.f64(double %{{.+}})
 // NO__ERRNO-NEXT: [[SINCOS_F64_0:%.+]] = extractvalue { double, double } 
[[SINCOS_F64]], 0
 // NO__ERRNO-NEXT: [[SINCOS_F64_1:%.+]] = extractvalue { double, double } 
[[SINCOS_F64]], 1
@@ -157,13 +139,13 @@ void foo(double *d, float f, float *fp, long double *l, 
int *i, const char *c) {
 
   __builtin_modf(f,d);   __builtin_modff(f,fp);  __builtin_modfl(f,l); 
__builtin_modff128(f,l);
 
-// NO__ERRNO: declare { double, double } @llvm.modf.f64(double) 
[[READNONE_INTRINSIC]]
-// NO__ERRNO: declare { float, float } @llvm.modf.f32(float) 
[[READNONE_INTRINSIC]]
-// NO__ERRNO: declare { x86_fp80, x86_fp80 } @llvm.modf.f80(x86_fp

[clang] Revert "[clang] Lower modf builtin using `llvm.modf` intrinsic" (PR #127987)

2025-02-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Benjamin Maxwell (MacDue)


Changes

Reverts llvm/llvm-project#126750

Revering while I investigate: 
https://lab.llvm.org/buildbot/#/builders/72/builds/8406 

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-27) 
- (modified) clang/test/CodeGen/X86/math-builtins.c (+7-25) 
- (modified) clang/test/CodeGen/aix-builtin-mapping.c (+1-1) 
- (modified) clang/test/CodeGen/builtin-attributes.c (+3-8) 
- (modified) clang/test/CodeGen/math-builtins-long.c (+3-3) 
- (modified) clang/test/CodeGen/math-libcalls.c (+6-6) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a73ba1ff138fb..4625bf8088be6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -859,24 +859,6 @@ static void emitSincosBuiltin(CodeGenFunction &CGF, const 
CallExpr *E,
   StoreCos->setMetadata(LLVMContext::MD_noalias, AliasScopeList);
 }
 
-static llvm::Value *emitModfBuiltin(CodeGenFunction &CGF, const CallExpr *E,
-llvm::Intrinsic::ID IntrinsicID) {
-  llvm::Value *Val = CGF.EmitScalarExpr(E->getArg(0));
-  llvm::Value *IntPartDest = CGF.EmitScalarExpr(E->getArg(1));
-
-  llvm::Value *Call =
-  CGF.Builder.CreateIntrinsic(IntrinsicID, {Val->getType()}, Val);
-
-  llvm::Value *FractionalResult = CGF.Builder.CreateExtractValue(Call, 0);
-  llvm::Value *IntegralResult = CGF.Builder.CreateExtractValue(Call, 1);
-
-  QualType DestPtrType = E->getArg(1)->getType()->getPointeeType();
-  LValue IntegralLV = CGF.MakeNaturalAlignAddrLValue(IntPartDest, DestPtrType);
-  CGF.EmitStoreOfScalar(IntegralResult, IntegralLV);
-
-  return FractionalResult;
-}
-
 /// EmitFAbs - Emit a call to @llvm.fabs().
 static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
   Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
@@ -4130,15 +4112,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_frexpf128:
   case Builtin::BI__builtin_frexpf16:
 return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp));
-  case Builtin::BImodf:
-  case Builtin::BImodff:
-  case Builtin::BImodfl:
-  case Builtin::BI__builtin_modf:
-  case Builtin::BI__builtin_modff:
-  case Builtin::BI__builtin_modfl:
-if (Builder.getIsFPConstrained())
-  break; // TODO: Emit constrained modf intrinsic once one exists.
-return RValue::get(emitModfBuiltin(*this, E, Intrinsic::modf));
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:
diff --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index d5301b7bafd9c..d7bf7d57fba26 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -38,24 +38,6 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 // NO__ERRNO-NEXT: [[FREXP_F128_0:%.+]] = extractvalue { fp128, i32 } 
[[FREXP_F128]], 0
 
 
-// NO__ERRNO: [[MODF_F64:%.+]] = call { double, double } @llvm.modf.f64(double 
%{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F64_FP:%.+]] = extractvalue { double, double } 
[[MODF_F64]], 0
-// NO__ERRNO-NEXT: [[MODF_F64_IP:%.+]] = extractvalue { double, double } 
[[MODF_F64]], 1
-// NO__ERRNO-NEXT: store double [[MODF_F64_IP]], ptr %{{.+}}, align 8
-
-// NO__ERRNO: [[MODF_F32:%.+]] = call { float, float } @llvm.modf.f32(float 
%{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F32_FP:%.+]] = extractvalue { float, float } 
[[MODF_F32]], 0
-// NO__ERRNO-NEXT: [[MODF_F32_IP:%.+]] = extractvalue { float, float } 
[[MODF_F32]], 1
-// NO__ERRNO-NEXT: store float [[MODF_F32_IP]], ptr %{{.+}}, align 4
-
-// NO__ERRNO: [[MODF_F80:%.+]] = call { x86_fp80, x86_fp80 } 
@llvm.modf.f80(x86_fp80 %{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F80_FP:%.+]] = extractvalue { x86_fp80, x86_fp80 } 
[[MODF_F80]], 0
-// NO__ERRNO-NEXT: [[MODF_F80_IP:%.+]] = extractvalue { x86_fp80, x86_fp80 } 
[[MODF_F80]], 1
-// NO__ERRNO-NEXT: store x86_fp80 [[MODF_F80_IP]], ptr %{{.+}}, align 16
-
-// NO__ERRNO: call fp128 @modff128(fp128 noundef %{{.+}}, ptr noundef %{{.+}})
-
-
 // NO__ERRNO: [[SINCOS_F64:%.+]] = call { double, double } 
@llvm.sincos.f64(double %{{.+}})
 // NO__ERRNO-NEXT: [[SINCOS_F64_0:%.+]] = extractvalue { double, double } 
[[SINCOS_F64]], 0
 // NO__ERRNO-NEXT: [[SINCOS_F64_1:%.+]] = extractvalue { double, double } 
[[SINCOS_F64]], 1
@@ -157,13 +139,13 @@ void foo(double *d, float f, float *fp, long double *l, 
int *i, const char *c) {
 
   __builtin_modf(f,d);   __builtin_modff(f,fp);  __builtin_modfl(f,l); 
__builtin_modff128(f,l);
 
-// NO__ERRNO: declare { double, double } @llvm.modf.f64(double) 
[[READNONE_INTRINSIC]]
-// NO__ERRNO: declare { float, float } @llvm.modf.f32(float) 
[[READNONE_INTRINSIC]]
-// NO__ERRNO: declare { x86_fp80, x86_fp80 } @llvm.modf.f8

[clang] Revert "[clang] Lower modf builtin using `llvm.modf` intrinsic" (PR #127987)

2025-02-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Benjamin Maxwell (MacDue)


Changes

Reverts llvm/llvm-project#126750

Revering while I investigate: 
https://lab.llvm.org/buildbot/#/builders/72/builds/8406 

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-27) 
- (modified) clang/test/CodeGen/X86/math-builtins.c (+7-25) 
- (modified) clang/test/CodeGen/aix-builtin-mapping.c (+1-1) 
- (modified) clang/test/CodeGen/builtin-attributes.c (+3-8) 
- (modified) clang/test/CodeGen/math-builtins-long.c (+3-3) 
- (modified) clang/test/CodeGen/math-libcalls.c (+6-6) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a73ba1ff138fb..4625bf8088be6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -859,24 +859,6 @@ static void emitSincosBuiltin(CodeGenFunction &CGF, const 
CallExpr *E,
   StoreCos->setMetadata(LLVMContext::MD_noalias, AliasScopeList);
 }
 
-static llvm::Value *emitModfBuiltin(CodeGenFunction &CGF, const CallExpr *E,
-llvm::Intrinsic::ID IntrinsicID) {
-  llvm::Value *Val = CGF.EmitScalarExpr(E->getArg(0));
-  llvm::Value *IntPartDest = CGF.EmitScalarExpr(E->getArg(1));
-
-  llvm::Value *Call =
-  CGF.Builder.CreateIntrinsic(IntrinsicID, {Val->getType()}, Val);
-
-  llvm::Value *FractionalResult = CGF.Builder.CreateExtractValue(Call, 0);
-  llvm::Value *IntegralResult = CGF.Builder.CreateExtractValue(Call, 1);
-
-  QualType DestPtrType = E->getArg(1)->getType()->getPointeeType();
-  LValue IntegralLV = CGF.MakeNaturalAlignAddrLValue(IntPartDest, DestPtrType);
-  CGF.EmitStoreOfScalar(IntegralResult, IntegralLV);
-
-  return FractionalResult;
-}
-
 /// EmitFAbs - Emit a call to @llvm.fabs().
 static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
   Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
@@ -4130,15 +4112,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_frexpf128:
   case Builtin::BI__builtin_frexpf16:
 return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp));
-  case Builtin::BImodf:
-  case Builtin::BImodff:
-  case Builtin::BImodfl:
-  case Builtin::BI__builtin_modf:
-  case Builtin::BI__builtin_modff:
-  case Builtin::BI__builtin_modfl:
-if (Builder.getIsFPConstrained())
-  break; // TODO: Emit constrained modf intrinsic once one exists.
-return RValue::get(emitModfBuiltin(*this, E, Intrinsic::modf));
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:
diff --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index d5301b7bafd9c..d7bf7d57fba26 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -38,24 +38,6 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 // NO__ERRNO-NEXT: [[FREXP_F128_0:%.+]] = extractvalue { fp128, i32 } 
[[FREXP_F128]], 0
 
 
-// NO__ERRNO: [[MODF_F64:%.+]] = call { double, double } @llvm.modf.f64(double 
%{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F64_FP:%.+]] = extractvalue { double, double } 
[[MODF_F64]], 0
-// NO__ERRNO-NEXT: [[MODF_F64_IP:%.+]] = extractvalue { double, double } 
[[MODF_F64]], 1
-// NO__ERRNO-NEXT: store double [[MODF_F64_IP]], ptr %{{.+}}, align 8
-
-// NO__ERRNO: [[MODF_F32:%.+]] = call { float, float } @llvm.modf.f32(float 
%{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F32_FP:%.+]] = extractvalue { float, float } 
[[MODF_F32]], 0
-// NO__ERRNO-NEXT: [[MODF_F32_IP:%.+]] = extractvalue { float, float } 
[[MODF_F32]], 1
-// NO__ERRNO-NEXT: store float [[MODF_F32_IP]], ptr %{{.+}}, align 4
-
-// NO__ERRNO: [[MODF_F80:%.+]] = call { x86_fp80, x86_fp80 } 
@llvm.modf.f80(x86_fp80 %{{.+}})
-// NO__ERRNO-NEXT: [[MODF_F80_FP:%.+]] = extractvalue { x86_fp80, x86_fp80 } 
[[MODF_F80]], 0
-// NO__ERRNO-NEXT: [[MODF_F80_IP:%.+]] = extractvalue { x86_fp80, x86_fp80 } 
[[MODF_F80]], 1
-// NO__ERRNO-NEXT: store x86_fp80 [[MODF_F80_IP]], ptr %{{.+}}, align 16
-
-// NO__ERRNO: call fp128 @modff128(fp128 noundef %{{.+}}, ptr noundef %{{.+}})
-
-
 // NO__ERRNO: [[SINCOS_F64:%.+]] = call { double, double } 
@llvm.sincos.f64(double %{{.+}})
 // NO__ERRNO-NEXT: [[SINCOS_F64_0:%.+]] = extractvalue { double, double } 
[[SINCOS_F64]], 0
 // NO__ERRNO-NEXT: [[SINCOS_F64_1:%.+]] = extractvalue { double, double } 
[[SINCOS_F64]], 1
@@ -157,13 +139,13 @@ void foo(double *d, float f, float *fp, long double *l, 
int *i, const char *c) {
 
   __builtin_modf(f,d);   __builtin_modff(f,fp);  __builtin_modfl(f,l); 
__builtin_modff128(f,l);
 
-// NO__ERRNO: declare { double, double } @llvm.modf.f64(double) 
[[READNONE_INTRINSIC]]
-// NO__ERRNO: declare { float, float } @llvm.modf.f32(float) 
[[READNONE_INTRINSIC]]
-// NO__ERRNO: declare { x86_fp80, x86_fp80 } @llvm.modf.f80(

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

2025-02-20 Thread Matheus Izvekov via cfe-commits


@@ -11714,27 +11714,51 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
-  int index = 0;
-  if (TemplateTypeParmDecl *TTP = dyn_cast(ParamD))
-index = TTP->getIndex();
-  else if (NonTypeTemplateParmDecl *NTTP
-  = dyn_cast(ParamD))
-index = NTTP->getIndex();
-  else
-index = cast(ParamD)->getIndex();
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_unnamed)
-  << (index + 1);
-}
+TemplateArgument FirstArg = *DeductionFailure.getFirstArg();
+TemplateArgument SecondArg = *DeductionFailure.getSecondArg();
+
+auto TupleResult = [&]() -> std::tuple {
+  switch (ParamD->getKind()) {
+  case Decl::TemplateTypeParm: {
+auto *TTPD = cast(ParamD);
+return {1, 0, 1, TTPD->getIndex(), QualType()};
+  }
+  case Decl::NonTypeTemplateParm: {
+auto *NTTPD = cast(ParamD);
+if (SecondArg.isNull()) {
+  return {1, 1, 0, NTTPD->getIndex(), NTTPD->getType()};
+} else {
+  // FIXME: This is a hack. We should emit a better message
+  // for ill-formed const exprs in >=C++20.
+  QualType qt = NTTPD->getType();
+  if (qt.getCanonicalType() ==
+  SecondArg.getAsType().getCanonicalType()) {
+return {3, -1, -1, NTTPD->getIndex(), NTTPD->getType()};
+  } else {
+return {2, -1, -1, NTTPD->getIndex(), NTTPD->getType()};
+  }
+}
+  }
+  case Decl::TemplateTemplateParm: {
+auto *TTempPD = cast(ParamD);
+return {3, -1, -1, TTempPD->getIndex(), QualType()};
+  }
+  default:
+llvm_unreachable("unexpected param decl kind");
+  }
+};
+auto [Which, Provided, Expected, Index, Type] = TupleResult();
+S.NoteTemplateParameterLocation(*ParamD);
+S.Diag(Templated->getLocation(),
+   diag::note_ovl_candidate_explicit_arg_mismatch)
+<< Which << Provided << Expected << FirstArg << SecondArg << Type
+<< (Index + 1);

mizvekov wrote:

```suggestion
S.Diag(Templated->getLocation(),
   diag::note_ovl_candidate_explicit_arg_mismatch)
<< Which << Provided << Expected << FirstArg << SecondArg << Type
<< (Index + 1);
S.NoteTemplateParameterLocation(*ParamD);
```

The note must always come after the error, otherwise it becomes attached to 
whatever diagnostic we emitted previously.

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


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

2025-02-20 Thread Matheus Izvekov via cfe-commits


@@ -11714,27 +11714,51 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
-  int index = 0;
-  if (TemplateTypeParmDecl *TTP = dyn_cast(ParamD))
-index = TTP->getIndex();
-  else if (NonTypeTemplateParmDecl *NTTP
-  = dyn_cast(ParamD))
-index = NTTP->getIndex();
-  else
-index = cast(ParamD)->getIndex();
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_unnamed)
-  << (index + 1);
-}
+TemplateArgument FirstArg = *DeductionFailure.getFirstArg();
+TemplateArgument SecondArg = *DeductionFailure.getSecondArg();
+
+auto TupleResult = [&]() -> std::tuple {
+  switch (ParamD->getKind()) {
+  case Decl::TemplateTypeParm: {
+auto *TTPD = cast(ParamD);
+return {1, 0, 1, TTPD->getIndex(), QualType()};
+  }
+  case Decl::NonTypeTemplateParm: {
+auto *NTTPD = cast(ParamD);
+if (SecondArg.isNull()) {
+  return {1, 1, 0, NTTPD->getIndex(), NTTPD->getType()};
+} else {
+  // FIXME: This is a hack. We should emit a better message
+  // for ill-formed const exprs in >=C++20.
+  QualType qt = NTTPD->getType();
+  if (qt.getCanonicalType() ==
+  SecondArg.getAsType().getCanonicalType()) {
+return {3, -1, -1, NTTPD->getIndex(), NTTPD->getType()};
+  } else {
+return {2, -1, -1, NTTPD->getIndex(), NTTPD->getType()};
+  }
+}
+  }
+  case Decl::TemplateTemplateParm: {
+auto *TTempPD = cast(ParamD);
+return {3, -1, -1, TTempPD->getIndex(), QualType()};
+  }
+  default:
+llvm_unreachable("unexpected param decl kind");
+  }
+};
+auto [Which, Provided, Expected, Index, Type] = TupleResult();

mizvekov wrote:

I would drop the `TupleResult` thing and just immediately invoke and decompose 
the lambda.

This would be fine for me and you don't need to change, but here is another 
idea in case you like it, or other people prefer it:
```suggestion
SemaDiagnosticBuilder DB = S.Diag(Templated->getLocation(),
   diag::note_ovl_candidate_explicit_arg_mismatch);
switch (ParamD->getKind()) {
case Decl::TemplateTypeParm:
  DB << 1 << 0 << 1 << cast(ParamD)->getIndex() << 
QualType();
  break;
...
}
```
And so on. You would need to introduce an extra scope here for 'DB', as it 
needs to be destroyed for the diagnostic to be emitted, and this needs to 
happen before we emit any notes.

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


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

2025-02-20 Thread Matheus Izvekov via cfe-commits


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

mizvekov wrote:

Since you are adding new parameters for a `InvalidExplicitArguments`, did you 
audit all the users, in order to include the new information as well?

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


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

2025-02-20 Thread Matheus Izvekov via cfe-commits


@@ -4870,14 +4870,17 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "candidate template ignored: deduced values %diff{"
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
-def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+
+def note_ovl_candidate_explicit_arg_mismatch : Note<
+"candidate template ignored: invalid explicitly-specified argument"
+"%select{"
+"|: %select{non-type|type}1 argument %select{'%3'|%3}1 is not compatible 
with "
+"%select{non-type|type}2 parameter %select{%5|%4}2"
+"|: could not convert '%3' from %4 to %5"
+"| for %ordinal6 template parameter}0">;

mizvekov wrote:

You don't need to talk about the parameter since we emit a separate note for 
it, that should make this diagnostic a bit simpler, as right now it's 
stretching it on complexity.

If we are talking about argument / parameter kinds, it would make sense to talk 
about 'template' kind, besides non-type and type, otherwise some mismatches 
could happen between non-type kinds and that's a bit confusing.

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


[clang] [ARM] Fix lane ordering for AdvSIMD intrinsics on big-endian targets (PR #127068)

2025-02-20 Thread Oliver Stannard via cfe-commits

ostannard wrote:

Ping

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


[clang] [ARM, AArch64] Fix ABI bugs with over-sized bitfields (PR #126774)

2025-02-20 Thread Oliver Stannard via cfe-commits

ostannard wrote:

Ping

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


[clang] 0948fc8 - [clang] print correct context for diagnostics suppressed by deduction (#125453)

2025-02-20 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2025-02-20T08:50:03-03:00
New Revision: 0948fc85aa99a8fd193d2d66a517e31b8b639f20

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

LOG: [clang] print correct context for diagnostics suppressed by deduction 
(#125453)

This patch makes it so the correct instantiation context is printed for
diagnostics suppessed by template argument deduction.

The context is saved along with the suppressed diagnostic, and when the
declaration they were attached to becomes used, we print the correct
context, instead of whatever context was at this point.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/CXX/drs/cwg0xx.cpp
clang/test/CXX/drs/cwg4xx.cpp
clang/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp
clang/test/SemaCXX/anonymous-struct.cpp
clang/test/SemaCXX/bool-increment-SFINAE.cpp
clang/test/SemaCXX/cxx98-compat-flags.cpp
clang/test/SemaCXX/cxx98-compat.cpp
clang/test/SemaCXX/deprecated.cpp
clang/test/SemaCXX/lambda-expressions.cpp
clang/test/SemaCXX/undefined-internal.cpp
clang/test/SemaTemplate/recovery-crash.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 62a64ff57599d..1659c4e1f5ea2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -168,6 +168,8 @@ Bug Fixes to C++ Support
 
 
 - Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
+- Clang now prints the correct instantiation context for diagnostics suppressed
+  by template argument deduction.
 - The initialization kind of elements of structured bindings
   direct-list-initialized from an array is corrected to direct-initialization.
 - Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. 
(#GH127327)
@@ -275,7 +277,7 @@ Code Completion
 Static Analyzer
 ---
 
-- Clang currently support extending lifetime of object bound to 
+- Clang currently support extending lifetime of object bound to
   reference members of aggregates in CFG and ExprEngine, that are
   created from default member initializer.
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c55b964650323..093e9a06b00ce 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1908,7 +1908,23 @@ class Sema final : public SemaBase {
   /// '\#pragma clang attribute push' directives to the given declaration.
   void AddPragmaAttributes(Scope *S, Decl *D);
 
-  void PrintPragmaAttributeInstantiationPoint();
+  using InstantiationContextDiagFuncRef =
+  llvm::function_ref;
+  auto getDefaultDiagFunc() {
+return [this](SourceLocation Loc, PartialDiagnostic PD) {
+  // This bypasses a lot of the filters in the diag engine, as it's
+  // to be used to attach notes to diagnostics which have already
+  // been filtered through.
+  DiagnosticBuilder Builder(Diags.Report(Loc, PD.getDiagID()));
+  PD.Emit(Builder);
+};
+  }
+
+  void PrintPragmaAttributeInstantiationPoint(
+  InstantiationContextDiagFuncRef DiagFunc);
+  void PrintPragmaAttributeInstantiationPoint() {
+PrintPragmaAttributeInstantiationPoint(getDefaultDiagFunc());
+  }
 
   void DiagnoseUnterminatedPragmaAttribute();
 
@@ -13263,18 +13279,22 @@ class Sema final : public SemaBase {
   void pushCodeSynthesisContext(CodeSynthesisContext Ctx);
   void popCodeSynthesisContext();
 
-  void PrintContextStack() {
+  void PrintContextStack(InstantiationContextDiagFuncRef DiagFunc) {
 if (!CodeSynthesisContexts.empty() &&
 CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) {
-  PrintInstantiationStack();
+  PrintInstantiationStack(DiagFunc);
   LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size();
 }
 if (PragmaAttributeCurrentTargetDecl)
-  PrintPragmaAttributeInstantiationPoint();
+  PrintPragmaAttributeInstantiationPoint(DiagFunc);
   }
+  void PrintContextStack() { PrintContextStack(getDefaultDiagFunc()); }
   /// Prints the current instantiation stack through a series of
   /// notes.
-  void PrintInstantiationStack();
+  void PrintInstantiationStack(InstantiationContextDiagFuncRef DiagFunc);
+  void PrintInstantiationStack() {
+PrintInstantiationStack(getDefaultDiagFunc());
+  }
 
   /// Determines whether we are currently in a context where
   /// template argument substitution failures are not considered

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index a

[clang] [clang] Implement instantiation context note for checking template parameters (PR #126088)

2025-02-20 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] print correct context for diagnostics suppressed by deduction (PR #125453)

2025-02-20 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-20 Thread Lu Weining via cfe-commits

SixWeining wrote:

Could you add some tests in ohos.c with the `--sysroot` option specified?

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


[clang] Revert "[clang] Lower modf builtin using `llvm.modf` intrinsic" (PR #127987)

2025-02-20 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`clang` at step 6 "test-openmp".

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


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

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

Exit Code: -11

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

--




```



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


[libunwind] [libunwind][NFC] Remove the CET keyword in shadow stack-related stuffs (PR #126663)

2025-02-20 Thread Ming-Yi Lai via cfe-commits

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


[clang] [Clang] Add BuiltinTemplates.td to generate code for builtin templates (PR #123736)

2025-02-20 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/123736

>From 586dd4edfc79c88cc1583b64d186c1481fbd6ce1 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Wed, 4 Sep 2024 13:31:39 +0200
Subject: [PATCH 1/7] [Clang] Add BuiltinTemplates.td to generate code for
 builtin templates

---
 clang/include/clang/AST/ASTContext.h  |  35 ++--
 clang/include/clang/AST/DeclID.h  |  10 +-
 clang/include/clang/Basic/BuiltinTemplates.td |  23 +++
 clang/include/clang/Basic/Builtins.h  |  10 +-
 clang/include/clang/Basic/CMakeLists.txt  |   4 +
 clang/lib/AST/ASTContext.cpp  |  30 +--
 clang/lib/AST/ASTImporter.cpp |  12 +-
 clang/lib/AST/DeclTemplate.cpp| 133 +
 clang/lib/Lex/PPMacroExpansion.cpp|   5 +-
 clang/lib/Sema/SemaLookup.cpp |  18 +-
 clang/lib/Serialization/ASTReader.cpp |  22 +--
 clang/lib/Serialization/ASTWriter.cpp |   8 +-
 clang/utils/TableGen/CMakeLists.txt   |   1 +
 .../TableGen/ClangBuiltinTemplatesEmitter.cpp | 184 ++
 clang/utils/TableGen/TableGen.cpp |   6 +
 clang/utils/TableGen/TableGenBackends.h   |   2 +
 16 files changed, 269 insertions(+), 234 deletions(-)
 create mode 100644 clang/include/clang/Basic/BuiltinTemplates.td
 create mode 100644 clang/utils/TableGen/ClangBuiltinTemplatesEmitter.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 0e07c5d6ce8fb..98db5522d564e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -410,11 +410,8 @@ class ASTContext : public RefCountedBase {
   /// The identifier 'NSCopying'.
   IdentifierInfo *NSCopyingName = nullptr;
 
-  /// The identifier '__make_integer_seq'.
-  mutable IdentifierInfo *MakeIntegerSeqName = nullptr;
-
-  /// The identifier '__type_pack_element'.
-  mutable IdentifierInfo *TypePackElementName = nullptr;
+#define BuiltinTemplate(BTName) mutable IdentifierInfo *Name##BTName = nullptr;
+#include "clang/Basic/BuiltinTemplates.inc"
 
   /// The identifier '__builtin_common_type'.
   mutable IdentifierInfo *BuiltinCommonTypeName = nullptr;
@@ -624,9 +621,9 @@ class ASTContext : public RefCountedBase {
 
   TranslationUnitDecl *TUDecl = nullptr;
   mutable ExternCContextDecl *ExternCContext = nullptr;
-  mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
-  mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
-  mutable BuiltinTemplateDecl *BuiltinCommonTypeDecl = nullptr;
+
+#define BuiltinTemplate(Name) mutable BuiltinTemplateDecl *Decl##Name = 
nullptr;
+#include "clang/Basic/BuiltinTemplates.inc"
 
   /// The associated SourceManager object.
   SourceManager &SourceMgr;
@@ -1152,9 +1149,9 @@ class ASTContext : public RefCountedBase {
   }
 
   ExternCContextDecl *getExternCContextDecl() const;
-  BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
-  BuiltinTemplateDecl *getTypePackElementDecl() const;
-  BuiltinTemplateDecl *getBuiltinCommonTypeDecl() const;
+
+#define BuiltinTemplate(Name) BuiltinTemplateDecl *get##Name##Decl() const;
+#include "clang/Basic/BuiltinTemplates.inc"
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -2054,17 +2051,13 @@ class ASTContext : public RefCountedBase {
 return BoolName;
   }
 
-  IdentifierInfo *getMakeIntegerSeqName() const {
-if (!MakeIntegerSeqName)
-  MakeIntegerSeqName = &Idents.get("__make_integer_seq");
-return MakeIntegerSeqName;
-  }
-
-  IdentifierInfo *getTypePackElementName() const {
-if (!TypePackElementName)
-  TypePackElementName = &Idents.get("__type_pack_element");
-return TypePackElementName;
+#define BuiltinTemplate(BTName)
\
+  IdentifierInfo *get##BTName##Name() const {  
\
+if (!Name##BTName) 
\
+  Name##BTName = &Idents.get(#BTName); 
\
+return Name##BTName;   
\
   }
+#include "clang/Basic/BuiltinTemplates.inc"
 
   IdentifierInfo *getBuiltinCommonTypeName() const {
 if (!BuiltinCommonTypeName)
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index 49964b43c7d1d..71e28ec1f9c65 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -71,20 +71,14 @@ enum PredefinedDeclIDs {
   /// The extern "C" context.
   PREDEF_DECL_EXTERN_C_CONTEXT_ID,
 
-  /// The internal '__make_integer_seq' template.
-  PREDEF_DECL_MAKE_INTEGER_SEQ_ID,
-
   /// The internal '__NSConstantString' typedef.
   PREDEF_DECL_CF_CONSTANT_STRING_ID,
 
   /// The internal '__NSConstantString' tag type.
   PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID,
 
-  /// The internal '__type_pack_element' template.
-  PREDEF_DECL_TYPE_PACK_ELEMENT_ID,
-
-  /// The internal '__builtin_common

[libunwind] 507e413 - [libunwind][NFC] Remove the CET keyword in shadow stack-related stuffs (#126663)

2025-02-20 Thread via cfe-commits

Author: Ming-Yi Lai
Date: 2025-02-20T16:12:16+08:00
New Revision: 507e413a2d85fb25f70caa9ef843f7c7cffb94c6

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

LOG: [libunwind][NFC] Remove the CET keyword in shadow stack-related stuffs 
(#126663)

libunwind currently supports shadow stack based on the Intel CET and
AArch64 GCS technology, but throughout related codes, the Intel-specific
keyword, "CET", is used to refer to the generic concept of control-flow
integrity/shadow stack. This patch replaces such wordings with
architecture-neutral term "shadow stack" (abbr. "shstk") to allow future
implementation to avoid using the Intel-specific "CET" term.

Added: 
libunwind/src/shadow_stack_unwind.h

Modified: 
libunwind/src/CMakeLists.txt
libunwind/src/Registers.hpp
libunwind/src/UnwindCursor.hpp
libunwind/src/UnwindLevel1.c

Removed: 
libunwind/src/cet_unwind.h



diff  --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index ecbd019bb29ea..d69013e5dace1 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -36,7 +36,6 @@ set(LIBUNWIND_HEADERS
 AddressSpace.hpp
 assembly.h
 CompactUnwinder.hpp
-cet_unwind.h
 config.h
 dwarf2.h
 DwarfInstructions.hpp
@@ -46,6 +45,7 @@ set(LIBUNWIND_HEADERS
 libunwind_ext.h
 Registers.hpp
 RWMutex.hpp
+shadow_stack_unwind.h
 Unwind-EHABI.h
 UnwindCursor.hpp
 ../include/libunwind.h

diff  --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index 861e6b5f6f2c5..452f46a0d56ea 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -15,9 +15,9 @@
 #include 
 #include 
 
-#include "cet_unwind.h"
 #include "config.h"
 #include "libunwind.h"
+#include "shadow_stack_unwind.h"
 
 namespace libunwind {
 
@@ -48,7 +48,7 @@ class _LIBUNWIND_HIDDEN Registers_x86;
 extern "C" void __libunwind_Registers_x86_jumpto(Registers_x86 *);
 
 #if defined(_LIBUNWIND_USE_CET)
-extern "C" void *__libunwind_cet_get_jump_target() {
+extern "C" void *__libunwind_shstk_get_jump_target() {
   return reinterpret_cast(&__libunwind_Registers_x86_jumpto);
 }
 #endif
@@ -268,7 +268,7 @@ class _LIBUNWIND_HIDDEN Registers_x86_64;
 extern "C" void __libunwind_Registers_x86_64_jumpto(Registers_x86_64 *);
 
 #if defined(_LIBUNWIND_USE_CET)
-extern "C" void *__libunwind_cet_get_jump_target() {
+extern "C" void *__libunwind_shstk_get_jump_target() {
   return reinterpret_cast(&__libunwind_Registers_x86_64_jumpto);
 }
 #endif
@@ -1817,7 +1817,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64;
 extern "C" void __libunwind_Registers_arm64_jumpto(Registers_arm64 *);
 
 #if defined(_LIBUNWIND_USE_GCS)
-extern "C" void *__libunwind_cet_get_jump_target() {
+extern "C" void *__libunwind_shstk_get_jump_target() {
   return reinterpret_cast(&__libunwind_Registers_arm64_jumpto);
 }
 #endif

diff  --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 0923052b1b588..ca9927edc9990 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -11,7 +11,7 @@
 #ifndef __UNWINDCURSOR_HPP__
 #define __UNWINDCURSOR_HPP__
 
-#include "cet_unwind.h"
+#include "shadow_stack_unwind.h"
 #include 
 #include 
 #include 
@@ -3122,7 +3122,7 @@ bool UnwindCursor::isReadableAddr(const pint_t 
addr) const {
 #endif
 
 #if defined(_LIBUNWIND_USE_CET) || defined(_LIBUNWIND_USE_GCS)
-extern "C" void *__libunwind_cet_get_registers(unw_cursor_t *cursor) {
+extern "C" void *__libunwind_shstk_get_registers(unw_cursor_t *cursor) {
   AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
   return co->get_registers();
 }

diff  --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 7e785f4d31e71..a258a832a9c31 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -25,10 +25,10 @@
 #include 
 #include 
 
-#include "cet_unwind.h"
 #include "config.h"
 #include "libunwind.h"
 #include "libunwind_ext.h"
+#include "shadow_stack_unwind.h"
 #include "unwind.h"
 
 #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) &&   
\
@@ -36,14 +36,17 @@
 
 #ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND
 
-// When CET is enabled, each "call" instruction will push return address to
-// CET shadow stack, each "ret" instruction will pop current CET shadow stack
-// top and compare it with target address which program will return.
-// In exception handing, some stack frames will be skipped before jumping to
-// landing pad and we must adjust CET shadow stack accordingly.
-// _LIBUNWIND_POP_CET_SSP is used to adjust CET shadow stack pointer and we
-// directly jump to __libunwind_Registers_x86/x86_64_jumpto instead of using
-// a regular function call to avoid pushing to CET shadow stack again.
+// When shadow st

[clang] [Clang] Add BuiltinTemplates.td to generate code for builtin templates (PR #123736)

2025-02-20 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,162 @@
+//=- ClangBuiltinsEmitter.cpp - Generate Clang builtin templates-*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits Clang's builtin templates.
+//
+//===--===//
+
+#include "TableGenBackends.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/TableGenBackend.h"
+
+#include 
+
+using namespace llvm;
+
+static std::string TemplateNameList;
+static std::string CreateBuiltinTemplateParameterList;
+
+namespace {
+struct ParserState {
+  size_t UniqueCounter = 0;
+  size_t CurrentDepth = 0;
+  bool EmittedSizeTInfo = false;
+};
+
+std::pair
+ParseTemplateParameterList(ParserState &PS,
+   ArrayRef TemplateArgs) {
+  std::vector Params;
+  std::unordered_map TemplateNameToParmName;
+
+  std::ostringstream Code;
+  Code << std::boolalpha;
+
+  size_t Position = 0;
+  for (const Record *Arg : TemplateArgs) {
+std::string ParmName = "Parm" + std::to_string(PS.UniqueCounter++);
+if (Arg->isSubClassOf("Template")) {
+  ++PS.CurrentDepth;
+  auto [TemplateCode, TPLName] =
+  ParseTemplateParameterList(PS, Arg->getValueAsListOfDefs("Args"));
+  --PS.CurrentDepth;
+  Code << TemplateCode << " auto *" << ParmName
+   << " = TemplateTemplateParmDecl::Create(C, DC, SourceLocation(), "
+   << PS.CurrentDepth << ", " << Position++
+   << ", /*ParameterPack=*/false, /*Id=*/nullptr, /*Typename=*/false, "
+   << TPLName << ");\n";
+} else if (Arg->isSubClassOf("Class")) {
+  Code << " auto *" << ParmName
+   << " = TemplateTypeParmDecl::Create(C, DC, SourceLocation(), "
+  "SourceLocation(), "
+   << PS.CurrentDepth << ", " << Position++
+   << ", /*Id=*/nullptr, /*Typename=*/false, "
+   << Arg->getValueAsBit("IsVariadic") << ");\n";
+} else if (Arg->isSubClassOf("NTTP")) {
+  auto Type = Arg->getValueAsString("TypeName");
+
+  if (TemplateNameToParmName.find(Type.str()) ==
+  TemplateNameToParmName.end()) {
+PrintFatalError("Unkown Type Name");
+  }
+
+  auto TSIName = "TSI" + std::to_string(PS.UniqueCounter++);
+  Code << " auto *" << TSIName << " = C.getTrivialTypeSourceInfo(QualType("
+   << TemplateNameToParmName[Type.str()] << "->getTypeForDecl(), 
0));\n"
+   << " auto *" << ParmName
+   << " = NonTypeTemplateParmDecl::Create(C, DC, SourceLocation(), "
+  "SourceLocation(), "
+   << PS.CurrentDepth << ", " << Position++ << ", /*Id=*/nullptr, "
+   << TSIName << "->getType(), " << Arg->getValueAsBit("IsVariadic")
+   << ", " << TSIName << ");\n";
+} else if (Arg->isSubClassOf("BuiltinNTTP")) {
+  if (Arg->getValueAsString("TypeName") != "size_t")
+PrintFatalError("Unkown Type Name");
+  if (!PS.EmittedSizeTInfo) {
+Code << "TypeSourceInfo *SizeTInfo = "
+"C.getTrivialTypeSourceInfo(C.getSizeType());\n";
+PS.EmittedSizeTInfo = true;
+  }
+  Code << " auto *" << ParmName
+   << " = NonTypeTemplateParmDecl::Create(C, DC, SourceLocation(), "
+  "SourceLocation(), "
+   << PS.CurrentDepth << ", " << Position++
+   << ", /*Id=*/nullptr, SizeTInfo->getType(), "
+  "/*ParameterPack=*/false, SizeTInfo);\n";
+} else {
+  PrintFatalError("Unknown Argument Type");
+}
+
+TemplateNameToParmName[Arg->getValueAsString("Name").str()] = ParmName;
+Params.emplace_back(std::move(ParmName));
+  }
+
+  auto TPLName = "TPL" + std::to_string(PS.UniqueCounter++);
+  Code << " auto *" << TPLName
+   << " = TemplateParameterList::Create(C, SourceLocation(), "
+  "SourceLocation(), {";
+
+  if (Params.empty()) {
+PrintFatalError(
+"Expected at least one argument in template parameter list");
+  }
+
+  bool First = true;
+  for (auto e : Params) {
+if (First) {
+  First = false;
+  Code << e;
+} else {
+  Code << ", " << e;
+}
+  }
+  Code << "}, SourceLocation(), nullptr);\n";
+
+  return {std::move(Code).str(), std::move(TPLName)};
+}
+
+static void
+EmitCreateBuiltinTemplateParameterList(std::vector 
TemplateArgs,
+   StringRef Name) {
+  using namespace std::string_literals;
+  CreateBuiltinTemplateParameterList +=
+  "case BTK"s + std::string{Name} + ": {\n"s;
+
+  ParserState PS;
+  auto [Code, TPLName] = ParseTemplateParameterList(PS, TemplateArgs);
+  CreateBuiltinTemplateParameterList += Code + "\n  return " + TPLName + ";\n";
+
+  CreateBuiltinTemplateParameterList += "  }\n";
+}
+
+void E

[clang] [Clang] Add BuiltinTemplates.td to generate code for builtin templates (PR #123736)

2025-02-20 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,46 @@
+//===--- BuiltinTemplates.td - Clang builtin template aliases ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+class TemplateArg {
+  string Name = name;
+}
+
+class Template args, string name> : TemplateArg {
+  list Args = args;
+}
+
+class Class : TemplateArg {

philnik777 wrote:

I'm not quite sure what you're asking. Do you mean it doesn't need to be in the 
`name`?

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


[clang] [Clang] Add BuiltinTemplates.td to generate code for builtin templates (PR #123736)

2025-02-20 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,162 @@
+//=- ClangBuiltinsEmitter.cpp - Generate Clang builtin templates-*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits Clang's builtin templates.
+//
+//===--===//
+
+#include "TableGenBackends.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/TableGenBackend.h"
+
+#include 
+
+using namespace llvm;
+
+static std::string TemplateNameList;
+static std::string CreateBuiltinTemplateParameterList;
+
+namespace {
+struct ParserState {
+  size_t UniqueCounter = 0;
+  size_t CurrentDepth = 0;
+  bool EmittedSizeTInfo = false;
+};
+
+std::pair
+ParseTemplateParameterList(ParserState &PS,
+   ArrayRef TemplateArgs) {
+  std::vector Params;
+  std::unordered_map TemplateNameToParmName;

philnik777 wrote:

I'm really not familiar with the LLVM containers, so I don't know. Does it make 
much of a difference for a tablegen emitter?

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


[clang] [CIR] Initial implementation of lowering CIR to MLIR (PR #127835)

2025-02-20 Thread Henrich Lauko via cfe-commits


@@ -2958,6 +2958,8 @@ defm clangir : BoolFOption<"clangir",
   BothFlags<[], [ClangOption, CC1Option], "">>;
 def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,
   Group, HelpText<"Build ASTs and then lower to ClangIR">;
+def emit_cir_mlir : Flag<["-"], "emit-cir-mlir">, Visibility<[CC1Option]>, 
Group,

xlauko wrote:

This is being reworked in incubator: https://github.com/llvm/clangir/pull/1316

I agree that `-emit-mlir` is ambiguous, though @bcardosolopes wanted to keep 
original semantics there for now.
TLDR we are working towards `-emit-mlir=`, e.g., 
`-emit-mlir=std` (can be renamed to core), `-emit-mlir=cir`, `-emit-mlir=llvm`.

Where these need to cooperate with `-f[no]-clangir-direct-lowering` to 
translate through `core` dialects or directly from `cir` to `llvm dialect`.


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


[clang] [Clang][doc] -ffp-contract options and standard compliance (PR #127621)

2025-02-20 Thread Sjoerd Meijer via cfe-commits

sjoerdmeijer wrote:

Thanks for your reviews! I will make those changes before merging this.

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


[clang] [Clang] Mark P1061 (Structured Bindings can introduce a Pack) as implemented (PR #127980)

2025-02-20 Thread via cfe-commits

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

None

>From 5dc1b59e2739ac3af24e05723f8d6240d6e8e139 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 20 Feb 2025 10:51:15 +0100
Subject: [PATCH] [Clang] Mark P1061 (Structured Bindings can introduce a Pack)
 as implemented.

---
 clang/docs/LanguageExtensions.rst   | 1 +
 clang/docs/ReleaseNotes.rst | 4 +++-
 clang/lib/Frontend/InitPreprocessor.cpp | 2 +-
 clang/test/Lexer/cxx-features.cpp   | 2 +-
 clang/www/cxx_status.html   | 2 +-
 5 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 2a956ad5b2909..573977d81805a 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1640,6 +1640,7 @@ Conditional ``explicit`` 
__cpp_conditional_explicit   C+
 ``static operator()``__cpp_static_call_operator   
C++23 C++03
 Attributes on Lambda-Expressions  
C++23 C++11
 Attributes on Structured Bindings__cpp_structured_bindings
C++26 C++03
+Packs in Structured Bindings __cpp_structured_bindings
C++26 C++03
 Static assert with user-generated message__cpp_static_assert >= 202306L   
C++26 C++11
 Pack Indexing__cpp_pack_indexing  
C++26 C++03
 ``= delete ("should have a reason");``   __cpp_deleted_function   
C++26 C++03
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a91c764860ccd..c286e01fbc0f8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -71,6 +71,8 @@ C++ Language Changes
 C++2c Feature Support
 ^
 
+- Implemented `P1061R10 Structured Bindings can introduce a Pack 
`_.
+
 C++23 Feature Support
 ^
 
@@ -271,7 +273,7 @@ Code Completion
 Static Analyzer
 ---
 
-- Clang currently support extending lifetime of object bound to 
+- Clang currently support extending lifetime of object bound to
   reference members of aggregates in CFG and ExprEngine, that are
   created from default member initializer.
 
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 77833f5d1defb..e1dc728558def 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -720,7 +720,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_nested_namespace_definitions", "201411L");
 Builder.defineMacro("__cpp_variadic_using", "201611L");
 Builder.defineMacro("__cpp_aggregate_bases", "201603L");
-Builder.defineMacro("__cpp_structured_bindings", "202403L");
+Builder.defineMacro("__cpp_structured_bindings", "202411L");
 Builder.defineMacro("__cpp_nontype_template_args",
 "201411L"); // (not latest)
 Builder.defineMacro("__cpp_fold_expressions", "201603L");
diff --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index b423e94b26aca..ff9a1a1210c44 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -229,7 +229,7 @@
 #error "wrong value for __cpp_aggregate_bases"
 #endif
 
-#if check(structured_bindings, 0, 0, 0, 202403L, 202403L, 202403L, 202403L)
+#if check(structured_bindings, 0, 0, 0, 202411L, 202411L, 202411L, 202411L)
 #error "wrong value for __cpp_structured_bindings"
 #endif
 
diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 2d5b96b47fe2d..2e2fecc418504 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -244,7 +244,7 @@ C++2c implementation status
  
   Structured Bindings can introduce a Pack
   https://wg21.link/P1061R10";>P1061R10
-  No
+  Clang 21
  
  
   The Oxford variadic comma

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


[clang] [Clang] Mark P1061 (Structured Bindings can introduce a Pack) as implemented (PR #127980)

2025-02-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes



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


5 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+1) 
- (modified) clang/docs/ReleaseNotes.rst (+3-1) 
- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+1-1) 
- (modified) clang/test/Lexer/cxx-features.cpp (+1-1) 
- (modified) clang/www/cxx_status.html (+1-1) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 2a956ad5b2909..573977d81805a 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1640,6 +1640,7 @@ Conditional ``explicit`` 
__cpp_conditional_explicit   C+
 ``static operator()``__cpp_static_call_operator   
C++23 C++03
 Attributes on Lambda-Expressions  
C++23 C++11
 Attributes on Structured Bindings__cpp_structured_bindings
C++26 C++03
+Packs in Structured Bindings __cpp_structured_bindings
C++26 C++03
 Static assert with user-generated message__cpp_static_assert >= 202306L   
C++26 C++11
 Pack Indexing__cpp_pack_indexing  
C++26 C++03
 ``= delete ("should have a reason");``   __cpp_deleted_function   
C++26 C++03
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a91c764860ccd..c286e01fbc0f8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -71,6 +71,8 @@ C++ Language Changes
 C++2c Feature Support
 ^
 
+- Implemented `P1061R10 Structured Bindings can introduce a Pack 
`_.
+
 C++23 Feature Support
 ^
 
@@ -271,7 +273,7 @@ Code Completion
 Static Analyzer
 ---
 
-- Clang currently support extending lifetime of object bound to 
+- Clang currently support extending lifetime of object bound to
   reference members of aggregates in CFG and ExprEngine, that are
   created from default member initializer.
 
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 77833f5d1defb..e1dc728558def 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -720,7 +720,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_nested_namespace_definitions", "201411L");
 Builder.defineMacro("__cpp_variadic_using", "201611L");
 Builder.defineMacro("__cpp_aggregate_bases", "201603L");
-Builder.defineMacro("__cpp_structured_bindings", "202403L");
+Builder.defineMacro("__cpp_structured_bindings", "202411L");
 Builder.defineMacro("__cpp_nontype_template_args",
 "201411L"); // (not latest)
 Builder.defineMacro("__cpp_fold_expressions", "201603L");
diff --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index b423e94b26aca..ff9a1a1210c44 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -229,7 +229,7 @@
 #error "wrong value for __cpp_aggregate_bases"
 #endif
 
-#if check(structured_bindings, 0, 0, 0, 202403L, 202403L, 202403L, 202403L)
+#if check(structured_bindings, 0, 0, 0, 202411L, 202411L, 202411L, 202411L)
 #error "wrong value for __cpp_structured_bindings"
 #endif
 
diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 2d5b96b47fe2d..2e2fecc418504 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -244,7 +244,7 @@ C++2c implementation status
  
   Structured Bindings can introduce a Pack
   https://wg21.link/P1061R10";>P1061R10
-  No
+  Clang 21
  
  
   The Oxford variadic comma

``




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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-20 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/125648

>From 189dd3cc2230ea5752969f02f119b6ee30e3df69 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 4 Feb 2025 01:35:41 -0600
Subject: [PATCH 1/6] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 
 clang/lib/Parse/ParseOpenMP.cpp   | 15 ++
 clang/test/OpenMP/metadirective_ast_print.c   | 20 +--
 .../metadirective_device_arch_codegen.cpp |  2 +-
 .../metadirective_device_isa_codegen.cpp  |  4 ++--
 ...etadirective_device_isa_codegen_amdgcn.cpp |  4 ++--
 .../metadirective_device_kind_codegen.c   |  2 +-
 .../metadirective_device_kind_codegen.cpp |  2 +-
 clang/test/OpenMP/metadirective_empty.cpp |  4 ++--
 .../metadirective_implementation_codegen.c| 12 +--
 .../metadirective_implementation_codegen.cpp  | 12 +--
 clang/test/OpenMP/metadirective_messages.cpp  | 12 +++
 12 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352d..673806ef28b9f 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+return Directive;
+  }
+  if(CKind == OMPC_default) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == 
"otherwise") {
+ConsumeToken();  // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c 
b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e7645216..28efaac594942 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
 #define N 10
 void foo(void) {
 #pragma omp metadirective when(device = {kind(cpu)} \
-   : parallel) default()
+   : parallel) otherwise()
   bar();
 #pragma omp metadirective when(implementation = {vendor(score(0)  \
 : llvm)}, \
device = {kind(cpu)}   \
-   : parallel) default(target teams)
+   : parallel) otherwise(target teams)
   bar();
 #pragma omp metadirective when(device = {kind(gpu)}
 \
: target teams) when(implementation = 
{vendor(llvm)} \
-: parallel) default()
+: parallel) otherwise()
   bar();
-#pragma omp metadirective default(target) when(implementation = 
{vendor(score(5)  \
+#pragma omp metadirective otherwise(target) when(implementation = 
{vendor(score(5)  \
 : 
llvm)}, \
device = {kind(cpu, host)}  
   \
: parallel)
@@ -40,15 +40,15 @@ void foo(void) {
   for (int i = 0; i < 100; i++)
 ;
 #pra

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-20 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

> Did anybody run the OpenMP VV suite before and after this change? Curious to 
> know if that improves results.

The changes I implemented are related to parsing, specifically addressing the 
deprecation of the default clause. These modifications do not impact the 
results, as they primarily refine how parsing is handled. Previously, keywords 
such as default, otherwise, or other variations were all parsed without 
distinction. With my changes, the parsing behavior now aligns with the expected 
standard—supporting default for OpenMP versions lower than 5.2 and otherwise 
for higher versions. Additionally, a warning is now generated when default is 
used in higher versions.

I also validated these changes by running the OpenMP VV suite to ensure 
correctness.

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


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

2025-02-20 Thread Nikita Popov via cfe-commits


@@ -255,4 +255,9 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
 }
 setLibcallName(RTLIB::MULO_I128, nullptr);
   }
+
+  if (TT.isSystemZ()) {
+setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
+setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
+  }

nikic wrote:

Since 
https://github.com/llvm/llvm-project/commit/cc539138acf742f53ef455147182a8de11980a02
 these are the defaults, so you don't need to reset them at all.

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-20 Thread Lu Weining via cfe-commits


@@ -235,3 +235,24 @@
 
 // CHECK-OHOS-PTHREAD-NOT: -lpthread
 
+// RUN: %clang -### --target=aarch64-linux-ohos %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-MAXPAGESIZE-4KB %s
+// RUN: %clang -### --target=aarch64-none-linux-gnu %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-NO-MAXPAGESIZE %s
+// RUN: %clang -### --target=loongarch64-linux-ohos %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-MAXPAGESIZE-16KB %s
+// RUN: %clang -### --target=loongarch64-linux-gnu %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-NO-MAXPAGESIZE %s
+// RUN: %clang -### --target=riscv64-linux-ohos %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-MAXPAGESIZE-4KB %s
+// RUN: %clang -### --target=riscv64-unknown-linux-gnu %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-NO-MAXPAGESIZE %s
+// RUN: %clang -### --target=x86_64-linux-ohos %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-MAXPAGESIZE-4KB %s
+// RUN: %clang -### --target=x86_64-none-linux-gnu %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-NO-MAXPAGESIZE %s
+
+
+// CHECK-MAXPAGESIZE-4KB: "-z" "max-page-size=4096"
+// CHECK-MAXPAGESIZE-16KB: "-z" "max-page-size=16384"
+// CHECK-NO-MAXPAGESIZE-NOT: "-z" "max-page-size=4096" "-z" 
"max-page-size=16384"

SixWeining wrote:

Seems this is not a good check. This check will always success no matter what 
the output is. I think the `gnu` checks could be removed.

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


[clang] [flang] [flang][OpenMP] Upstream `do concurrent` loop-nest detection. (PR #127595)

2025-02-20 Thread Kareem Ergawy via cfe-commits

ergawy wrote:

@clementval @jeanPerier can you please take a look at the PR and 
@kiranchandramohan's comment above? 🙏

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


[clang] [HLSL][Sema] Fix Struct Size Calculation containing 16/32 bit scalars (PR #128086)

2025-02-20 Thread Ashley Coleman via cfe-commits

https://github.com/V-FEXrt created 
https://github.com/llvm/llvm-project/pull/128086

Fixes #119641

Update SemaHLSL to correctly calculate the alignment barrier for scalars that 
are not 4 bytes wide

>From bebfc20fac6b27d02bca9af328d0568018672c71 Mon Sep 17 00:00:00 2001
From: Ashley Coleman 
Date: Thu, 20 Feb 2025 16:16:16 -0700
Subject: [PATCH 1/2] [hlsl][Sema] Fix Struct Size Calculation containing 16
 and 32 bit wide scalars

---
 clang/lib/Sema/SemaHLSL.cpp   | 26 --
 clang/test/CodeGenHLSL/cbuffer_align.hlsl | 60 +++
 2 files changed, 81 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/cbuffer_align.hlsl

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index d26d85d5861b1..6f99b7899891d 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -172,6 +172,26 @@ Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool 
CBuffer,
   return Result;
 }
 
+static unsigned calculateLegacyCbufferFieldAlign(const ASTContext &Context,
+   QualType T) {
+  // Aggregate types are always aligned to new buffer rows
+  if (T->isAggregateType())
+return 16;
+
+  assert(Context.getTypeSize(T) <= 64 && "Scalar bit widths larger than 64 not 
supported");
+
+  // 64 bit types such as double and uint64_t align to 8 bytes
+  if (Context.getTypeSize(T) == 64)
+return 8;
+
+  // Half types align to 2 bytes only if native half is available
+  if (T->isHalfType() && Context.getLangOpts().NativeHalfType)
+return 2;
+
+  // Everything else aligns to 4 bytes
+  return 4;
+}
+
 // Calculate the size of a legacy cbuffer type in bytes based on
 // 
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-packing-rules
 static unsigned calculateLegacyCbufferSize(const ASTContext &Context,
@@ -183,11 +203,7 @@ static unsigned calculateLegacyCbufferSize(const 
ASTContext &Context,
 for (const FieldDecl *Field : RD->fields()) {
   QualType Ty = Field->getType();
   unsigned FieldSize = calculateLegacyCbufferSize(Context, Ty);
-  // FIXME: This is not the correct alignment, it does not work for 16-bit
-  // types. See llvm/llvm-project#119641.
-  unsigned FieldAlign = 4;
-  if (Ty->isAggregateType())
-FieldAlign = CBufferAlign;
+  unsigned FieldAlign = calculateLegacyCbufferFieldAlign(Context, Ty);
   Size = llvm::alignTo(Size, FieldAlign);
   Size += FieldSize;
 }
diff --git a/clang/test/CodeGenHLSL/cbuffer_align.hlsl 
b/clang/test/CodeGenHLSL/cbuffer_align.hlsl
new file mode 100644
index 0..31db2e0726020
--- /dev/null
+++ b/clang/test/CodeGenHLSL/cbuffer_align.hlsl
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s 
--check-prefix=CHECK-HALF
+
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s 
--check-prefix=CHECK-FLOAT
+
+
+struct S1 {
+  half a;   // 2 bytes + 2 bytes pad or 4 bytes
+  float b;  // 4 bytes
+  half c;   // 2 bytes + 2 bytes pad or 4 bytes
+  float d;  // 4 bytes
+  double e; // 8 bytes
+};
+
+struct S2 {
+  half a;   // 2 bytes or 4 bytes
+  half b;   // 2 bytes or 4 bytes
+  float e;  // 4 bytes or 4 bytes + 4 padding
+  double f; // 8 bytes
+};
+
+struct S3 {
+  half a; // 2 bytes + 6 bytes pad or 4 bytes + 4 bytes pad
+  uint64_t b; // 8 bytes
+};
+
+struct S4 {
+  float a;  // 4 bytes
+  half b;   // 2 bytes or 4 bytes
+  half c;   // 2 bytes or 4 bytes + 4 bytes pad
+  double d; // 8 bytes
+};
+
+
+cbuffer CB0 {
+  // CHECK-HALF: @CB0.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB0, 24, 0))
+  // CHECK-FLOAT: @CB0.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB0, 24, 0))
+  S1 s1;
+}
+
+cbuffer CB1 {
+  // CHECK-HALF: @CB1.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB1, 16, 0))
+  // CHECK-FLOAT: @CB1.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB1, 24, 0))
+  S2 s2;
+}
+
+cbuffer CB2 {
+  // CHECK-HALF: @CB2.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB2, 16, 0))
+  // CHECK-FLOAT: @CB2.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB2, 16, 0))
+  S3 s3;
+}
+
+cbuffer CB3 {
+  // CHECK-HALF: @CB3.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB3, 16, 0))
+  // CHECK-FLOAT: @CB3.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB3, 24, 0))
+  S4 s4;
+}

>From e8b3032cbf09e2e3170a212b35ac0ad2f755ca9f Mon Sep 17 00:00:00 2001
From: Ashley Coleman 
Date: Thu, 20 Feb 2025 16:16:47 -0700
Subject: [PATCH 2/2] format

[clang] [Fix] Speedup -Wunsafe-buffer-usage when using clang modules. (PR #127161)

2025-02-20 Thread via cfe-commits

https://github.com/matts1 updated 
https://github.com/llvm/llvm-project/pull/127161

>From 46dc2732948e2776909d2ec752a235f22ac471f3 Mon Sep 17 00:00:00 2001
From: Matt Stark 
Date: Fri, 14 Feb 2025 14:14:03 +1100
Subject: [PATCH] [Fix] Speedup -Wunsafe-buffer-usage when using clang modules.

See https://issues.chromium.org/issues/351909443 for details and benchmarks.

This improves the performance of a file containing a single line, `#include 
`, from ~1 second to ~100ms on my machine.
---
 clang/lib/Sema/AnalysisBasedWarnings.cpp   | 18 +++---
 clang/test/Modules/safe_buffers_optout.cpp | 28 +++---
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 589869d018657..bd9164df090b2 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2546,14 +2546,25 @@ static void flushDiagnostics(Sema &S, const 
sema::FunctionScopeInfo *fscope) {
 class CallableVisitor : public DynamicRecursiveASTVisitor {
 private:
   llvm::function_ref Callback;
+  const Module *const TUModule;
 
 public:
-  CallableVisitor(llvm::function_ref Callback)
-  : Callback(Callback) {
+  CallableVisitor(llvm::function_ref Callback,
+  const Module *const TUModule)
+  : Callback(Callback), TUModule(TUModule) {
 ShouldVisitTemplateInstantiations = true;
 ShouldVisitImplicitCode = false;
   }
 
+  bool TraverseDecl(Decl *Node) override {
+// For performance reasons, only validate the current translation unit's
+// module, and not modules it depends on.
+// See https://issues.chromium.org/issues/351909443 for details.
+if (Node && Node->getOwningModule() == TUModule)
+  return DynamicRecursiveASTVisitor::TraverseDecl(Node);
+return true;
+  }
+
   bool VisitFunctionDecl(FunctionDecl *Node) override {
 if (cast(Node)->isDependentContext())
   return true; // Not to analyze dependent decl
@@ -2633,7 +2644,8 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
SourceLocation()) ||
   (!Diags.isIgnored(diag::warn_unsafe_buffer_libc_call, SourceLocation()) 
&&
S.getLangOpts().CPlusPlus /* only warn about libc calls in C++ */)) {
-CallableVisitor(CallAnalyzers).TraverseTranslationUnitDecl(TU);
+CallableVisitor(CallAnalyzers, TU->getOwningModule())
+.TraverseTranslationUnitDecl(TU);
   }
 }
 
diff --git a/clang/test/Modules/safe_buffers_optout.cpp 
b/clang/test/Modules/safe_buffers_optout.cpp
index 2129db65da752..8c3d6a235d399 100644
--- a/clang/test/Modules/safe_buffers_optout.cpp
+++ b/clang/test/Modules/safe_buffers_optout.cpp
@@ -95,18 +95,10 @@ int textual(int *p) {
 // `safe_buffers_test_optout`, which uses another top-level module
 // `safe_buffers_test_base`. (So the module dependencies form a DAG.)
 
-// No expected warnings from base.h because base.h is a separate
-// module and in a separate TU that is not textually included.  The
-// explicit command that builds base.h has no `-Wunsafe-buffer-usage`.
-
-// expected-warning@base.h:3{{unsafe buffer access}}
-// expected-note@base.h:3{{pass -fsafe-buffer-usage-suggestions to receive 
code hardening suggestions}}
-// expected-warning@test_sub1.h:5{{unsafe buffer access}}
-// expected-note@test_sub1.h:5{{pass -fsafe-buffer-usage-suggestions to 
receive code hardening suggestions}}
-// expected-warning@test_sub1.h:14{{unsafe buffer access}}
-// expected-note@test_sub1.h:14{{pass -fsafe-buffer-usage-suggestions to 
receive code hardening suggestions}}
-// expected-warning@test_sub2.h:5{{unsafe buffer access}}
-// expected-note@test_sub2.h:5{{pass -fsafe-buffer-usage-suggestions to 
receive code hardening suggestions}}
+// No expected warnings from base.h, test_sub1, or test_sub2 because they are
+// in seperate modules, and the explicit commands that builds them have no
+// `-Wunsafe-buffer-usage`.
+
 int foo(int * p) {
   int x = p[5]; // expected-warning{{unsafe buffer access}} 
expected-note{{pass -fsafe-buffer-usage-suggestions to receive code hardening 
suggestions}}
 #pragma clang unsafe_buffer_usage begin
@@ -129,14 +121,10 @@ int foo(int * p) {
 // `safe_buffers_test_optout`, which uses another top-level module
 // `safe_buffers_test_base`. (So the module dependencies form a DAG.)
 
-// expected-warning@base.h:3{{unsafe buffer access}}
-// expected-note@base.h:3{{pass -fsafe-buffer-usage-suggestions to receive 
code hardening suggestions}}
-// expected-warning@test_sub1.h:5{{unsafe buffer access}}
-// expected-note@test_sub1.h:5{{pass -fsafe-buffer-usage-suggestions to 
receive code hardening suggestions}}
-// expected-warning@test_sub1.h:14{{unsafe buffer access}}
-// expected-note@test_sub1.h:14{{pass -fsafe-buffer-usage-suggestions to 
receive code hardening suggestions}}
-// expected-warning@test_sub2.h:5{{unsafe buffer access}}
-// expected-note@test_sub2.h:5{{pass -fsafe-buffer-usage-sugge

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

2025-02-20 Thread Denis Mikhailov via cfe-commits


@@ -0,0 +1,131 @@
+//===--- AmbiguousSmartptrResetCallCheck.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 "AmbiguousSmartptrResetCallCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+
+AST_MATCHER(CXXMethodDecl, hasOnlyDefaultParameters) {
+  for (const auto *Param : Node.parameters()) {
+if (!Param->hasDefaultArg())
+  return false;
+  }
+
+  return true;
+}
+
+const auto DefaultSmartPointers =
+"::std::shared_ptr;::std::unique_ptr;::std::optional;"

denzor200 wrote:

remove `std::optional` from this check

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


[clang] [HLSL][Sema] Fix Struct Size Calculation containing 16/32 bit scalars (PR #128086)

2025-02-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ashley Coleman (V-FEXrt)


Changes

Fixes #119641

Update SemaHLSL to correctly calculate the alignment barrier for scalars that 
are not 4 bytes wide

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaHLSL.cpp (+22-5) 
- (added) clang/test/CodeGenHLSL/cbuffer_align.hlsl (+60) 


``diff
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index d26d85d5861b1..cccfd4aec7eb2 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -172,6 +172,27 @@ Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool 
CBuffer,
   return Result;
 }
 
+static unsigned calculateLegacyCbufferFieldAlign(const ASTContext &Context,
+ QualType T) {
+  // Aggregate types are always aligned to new buffer rows
+  if (T->isAggregateType())
+return 16;
+
+  assert(Context.getTypeSize(T) <= 64 &&
+ "Scalar bit widths larger than 64 not supported");
+
+  // 64 bit types such as double and uint64_t align to 8 bytes
+  if (Context.getTypeSize(T) == 64)
+return 8;
+
+  // Half types align to 2 bytes only if native half is available
+  if (T->isHalfType() && Context.getLangOpts().NativeHalfType)
+return 2;
+
+  // Everything else aligns to 4 bytes
+  return 4;
+}
+
 // Calculate the size of a legacy cbuffer type in bytes based on
 // 
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-packing-rules
 static unsigned calculateLegacyCbufferSize(const ASTContext &Context,
@@ -183,11 +204,7 @@ static unsigned calculateLegacyCbufferSize(const 
ASTContext &Context,
 for (const FieldDecl *Field : RD->fields()) {
   QualType Ty = Field->getType();
   unsigned FieldSize = calculateLegacyCbufferSize(Context, Ty);
-  // FIXME: This is not the correct alignment, it does not work for 16-bit
-  // types. See llvm/llvm-project#119641.
-  unsigned FieldAlign = 4;
-  if (Ty->isAggregateType())
-FieldAlign = CBufferAlign;
+  unsigned FieldAlign = calculateLegacyCbufferFieldAlign(Context, Ty);
   Size = llvm::alignTo(Size, FieldAlign);
   Size += FieldSize;
 }
diff --git a/clang/test/CodeGenHLSL/cbuffer_align.hlsl 
b/clang/test/CodeGenHLSL/cbuffer_align.hlsl
new file mode 100644
index 0..31db2e0726020
--- /dev/null
+++ b/clang/test/CodeGenHLSL/cbuffer_align.hlsl
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s 
--check-prefix=CHECK-HALF
+
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s 
--check-prefix=CHECK-FLOAT
+
+
+struct S1 {
+  half a;   // 2 bytes + 2 bytes pad or 4 bytes
+  float b;  // 4 bytes
+  half c;   // 2 bytes + 2 bytes pad or 4 bytes
+  float d;  // 4 bytes
+  double e; // 8 bytes
+};
+
+struct S2 {
+  half a;   // 2 bytes or 4 bytes
+  half b;   // 2 bytes or 4 bytes
+  float e;  // 4 bytes or 4 bytes + 4 padding
+  double f; // 8 bytes
+};
+
+struct S3 {
+  half a; // 2 bytes + 6 bytes pad or 4 bytes + 4 bytes pad
+  uint64_t b; // 8 bytes
+};
+
+struct S4 {
+  float a;  // 4 bytes
+  half b;   // 2 bytes or 4 bytes
+  half c;   // 2 bytes or 4 bytes + 4 bytes pad
+  double d; // 8 bytes
+};
+
+
+cbuffer CB0 {
+  // CHECK-HALF: @CB0.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB0, 24, 0))
+  // CHECK-FLOAT: @CB0.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB0, 24, 0))
+  S1 s1;
+}
+
+cbuffer CB1 {
+  // CHECK-HALF: @CB1.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB1, 16, 0))
+  // CHECK-FLOAT: @CB1.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB1, 24, 0))
+  S2 s2;
+}
+
+cbuffer CB2 {
+  // CHECK-HALF: @CB2.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB2, 16, 0))
+  // CHECK-FLOAT: @CB2.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB2, 16, 0))
+  S3 s3;
+}
+
+cbuffer CB3 {
+  // CHECK-HALF: @CB3.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB3, 16, 0))
+  // CHECK-FLOAT: @CB3.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB3, 24, 0))
+  S4 s4;
+}

``




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


[clang] [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo as well (PR #128106)

2025-02-20 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`cross-project-tests-sie-ubuntu-dwarf5` running on `doug-worker-1b` while 
building `clang` at step 2 "checkout".

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


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

```
Step 2 (checkout) failure: update (failure)
...
 * [new tag]   llvmorg-5.0.1-rc1  -> llvmorg-5.0.1-rc1
 * [new tag]   llvmorg-5.0.1-rc2  -> llvmorg-5.0.1-rc2
 * [new tag]   llvmorg-5.0.1-rc3  -> llvmorg-5.0.1-rc3
 * [new tag]   llvmorg-5.0.2  -> llvmorg-5.0.2
 * [new tag]   llvmorg-5.0.2-rc1  -> llvmorg-5.0.2-rc1
 * [new tag]   llvmorg-5.0.2-rc2  -> llvmorg-5.0.2-rc2
 * [new tag]   llvmorg-6.0.0  -> llvmorg-6.0.0
 * [new tag]   llvmorg-6.0.0-rc1  -> llvmorg-6.0.0-rc1
 * [new tag]   llvmorg-6.0.0-rc2  -> llvmorg-6.0.0-rc2
 * [new tag]   llvmorg-6.0.0-rc3  -> llvmorg-6.0.0-rc3
 * [new tag]   llvmorg-6.0.1  -> llvmorg-6.0.1
 * [new tag]   llvmorg-6.0.1-rc1  -> llvmorg-6.0.1-rc1
 * [new tag]   llvmorg-6.0.1-rc2  -> llvmorg-6.0.1-rc2
 * [new tag]   llvmorg-6.0.1-rc3  -> llvmorg-6.0.1-rc3
 * [new tag]   llvmorg-7.0.0  -> llvmorg-7.0.0
 * [new tag]   llvmorg-7.0.0-rc1  -> llvmorg-7.0.0-rc1
 * [new tag]   llvmorg-7.0.0-rc2  -> llvmorg-7.0.0-rc2
 * [new tag]   llvmorg-7.0.0-rc3  -> llvmorg-7.0.0-rc3
 * [new tag]   llvmorg-7.0.1  -> llvmorg-7.0.1
 * [new tag]   llvmorg-7.0.1-rc1  -> llvmorg-7.0.1-rc1
 * [new tag]   llvmorg-7.0.1-rc2  -> llvmorg-7.0.1-rc2
 * [new tag]   llvmorg-7.0.1-rc3  -> llvmorg-7.0.1-rc3
 * [new tag]   llvmorg-7.1.0  -> llvmorg-7.1.0
 * [new tag]   llvmorg-7.1.0-rc1  -> llvmorg-7.1.0-rc1
 * [new tag]   llvmorg-8.0.0  -> llvmorg-8.0.0
 * [new tag]   llvmorg-8.0.0-rc1  -> llvmorg-8.0.0-rc1
 * [new tag]   llvmorg-8.0.0-rc2  -> llvmorg-8.0.0-rc2
 * [new tag]   llvmorg-8.0.0-rc3  -> llvmorg-8.0.0-rc3
 * [new tag]   llvmorg-8.0.0-rc4  -> llvmorg-8.0.0-rc4
 * [new tag]   llvmorg-8.0.0-rc5  -> llvmorg-8.0.0-rc5
 * [new tag]   llvmorg-8.0.1  -> llvmorg-8.0.1
 * [new tag]   llvmorg-8.0.1-rc1  -> llvmorg-8.0.1-rc1
 * [new tag]   llvmorg-8.0.1-rc2  -> llvmorg-8.0.1-rc2
 * [new tag]   llvmorg-8.0.1-rc3  -> llvmorg-8.0.1-rc3
 * [new tag]   llvmorg-8.0.1-rc4  -> llvmorg-8.0.1-rc4
 * [new tag]   llvmorg-9.0.0  -> llvmorg-9.0.0
 * [new tag]   llvmorg-9.0.0-rc1  -> llvmorg-9.0.0-rc1
 * [new tag]   llvmorg-9.0.0-rc2  -> llvmorg-9.0.0-rc2
 * [new tag]   llvmorg-9.0.0-rc3  -> llvmorg-9.0.0-rc3
 * [new tag]   llvmorg-9.0.0-rc4  -> llvmorg-9.0.0-rc4
 * [new tag]   llvmorg-9.0.0-rc5  -> llvmorg-9.0.0-rc5
 * [new tag]   llvmorg-9.0.0-rc6  -> llvmorg-9.0.0-rc6
 * [new tag]   llvmorg-9.0.1  -> llvmorg-9.0.1
 * [new tag]   llvmorg-9.0.1-rc1  -> llvmorg-9.0.1-rc1
 * [new tag]   llvmorg-9.0.1-rc2  -> llvmorg-9.0.1-rc2
 * [new tag]   llvmorg-9.0.1-rc3  -> llvmorg-9.0.1-rc3
fatal: reference is not a tree: fd5d1cbb75e4278d9074ff105efd3ab48f778b4b
>From https://github.com/llvm/llvm-project
 * branch  main   -> FETCH_HEAD
fatal: reference is not a tree: fd5d1cbb75e4278d9074ff105efd3ab48f778b4b

```



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


[clang] [llvm] [AMDGPU] Add builtins for wave reduction intrinsics (PR #127013)

2025-02-20 Thread via cfe-commits


@@ -346,6 +346,24 @@ BUILTIN(__builtin_amdgcn_endpgm, "v", "nr")
 BUILTIN(__builtin_amdgcn_get_fpenv, "WUi", "n")
 BUILTIN(__builtin_amdgcn_set_fpenv, "vWUi", "n")
 
+//===--===//
+
+// Wave Reduction builtins.
+
+//===--===//
+
+BUILTIN(__builtin_amdgcn_wave_reduce_add_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_uadd_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_sub_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_usub_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_min_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_umin_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_max_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_umax_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_and_i32, "ii", "nc")

easyonaadit wrote:

got it.

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


[clang] [llvm] [AMDGPU] Add builtins for wave reduction intrinsics (PR #127013)

2025-02-20 Thread via cfe-commits


@@ -346,6 +346,24 @@ BUILTIN(__builtin_amdgcn_endpgm, "v", "nr")
 BUILTIN(__builtin_amdgcn_get_fpenv, "WUi", "n")
 BUILTIN(__builtin_amdgcn_set_fpenv, "vWUi", "n")
 
+//===--===//
+
+// Wave Reduction builtins.
+
+//===--===//
+
+BUILTIN(__builtin_amdgcn_wave_reduce_add_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_uadd_i32, "ii", "nc")

easyonaadit wrote:

Got it.

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


[clang] [clang][bytecode] Use ExtendingDecl mechanism for primitives as well (PR #128141)

2025-02-20 Thread Timm Baeder via cfe-commits

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

... when creating the temporary variables for a
MaterializeTemporaryExpr.

>From c097cff3502bf0fbbbd2a1c8c791f578fd1ce507 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 20 Feb 2025 20:22:15 +0100
Subject: [PATCH] [clang][bytecode] Use ExtendingDecl mechanism for primitives
 as well

... when creating the temporary variables for a
MaterializeTemporaryExpr.
---
 clang/lib/AST/ByteCode/Compiler.cpp   |  89 +++---
 clang/lib/AST/ByteCode/Compiler.h |   2 +-
 .../ByteCode/libcxx/primitive-temporary.cpp   | 271 ++
 3 files changed, 319 insertions(+), 43 deletions(-)
 create mode 100644 clang/test/AST/ByteCode/libcxx/primitive-temporary.cpp

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 503c58a67adeb..ec18f9d72b66f 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -567,8 +567,8 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 // Location for the SubExpr.
 // Since SubExpr is of complex type, visiting it results in a pointer
 // anyway, so we just create a temporary pointer variable.
-unsigned SubExprOffset = allocateLocalPrimitive(
-SubExpr, PT_Ptr, /*IsConst=*/true, /*IsExtended=*/false);
+unsigned SubExprOffset =
+allocateLocalPrimitive(SubExpr, PT_Ptr, /*IsConst=*/true);
 if (!this->visit(SubExpr))
   return false;
 if (!this->emitSetLocal(PT_Ptr, SubExprOffset, CE))
@@ -611,8 +611,8 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 
 const auto *VT = CE->getType()->getAs();
 PrimType ElemT = classifyPrim(SubExpr->getType());
-unsigned ElemOffset = allocateLocalPrimitive(
-SubExpr, ElemT, /*IsConst=*/true, /*IsExtended=*/false);
+unsigned ElemOffset =
+allocateLocalPrimitive(SubExpr, ElemT, /*IsConst=*/true);
 
 // Prepare a local variable for the scalar value.
 if (!this->visit(SubExpr))
@@ -1104,7 +1104,7 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
   PrimType ResultElemT = this->classifyComplexElementType(E->getType());
   unsigned ResultOffset = ~0u;
   if (!DiscardResult)
-ResultOffset = this->allocateLocalPrimitive(E, PT_Ptr, true, false);
+ResultOffset = this->allocateLocalPrimitive(E, PT_Ptr, /*IsConst=*/true);
 
   // Save result pointer in ResultOffset
   if (!this->DiscardResult) {
@@ -1178,14 +1178,14 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
 
   // Evaluate LHS and save value to LHSOffset.
   if (LHSType->isAnyComplexType()) {
-LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
+LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, /*IsConst=*/true);
 if (!this->visit(LHS))
   return false;
 if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
   return false;
   } else {
 PrimType LHST = classifyPrim(LHSType);
-LHSOffset = this->allocateLocalPrimitive(LHS, LHST, true, false);
+LHSOffset = this->allocateLocalPrimitive(LHS, LHST, /*IsConst=*/true);
 if (!this->visit(LHS))
   return false;
 if (!this->emitSetLocal(LHST, LHSOffset, E))
@@ -1195,14 +1195,14 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
   // Same with RHS.
   unsigned RHSOffset;
   if (RHSType->isAnyComplexType()) {
-RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
+RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, /*IsConst=*/true);
 if (!this->visit(RHS))
   return false;
 if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
   return false;
   } else {
 PrimType RHST = classifyPrim(RHSType);
-RHSOffset = this->allocateLocalPrimitive(RHS, RHST, true, false);
+RHSOffset = this->allocateLocalPrimitive(RHS, RHST, /*IsConst=*/true);
 if (!this->visit(RHS))
   return false;
 if (!this->emitSetLocal(RHST, RHSOffset, E))
@@ -1342,14 +1342,16 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   PrimType ResultElemT = this->classifyVectorElementType(E->getType());
 
   // Evaluate LHS and save value to LHSOffset.
-  unsigned LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
+  unsigned LHSOffset =
+  this->allocateLocalPrimitive(LHS, PT_Ptr, /*IsConst=*/true);
   if (!this->visit(LHS))
 return false;
   if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
 return false;
 
   // Evaluate RHS and save value to RHSOffset.
-  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
+  unsigned RHSOffset =
+  this->allocateLocalPrimitive(RHS, PT_Ptr, /*IsConst=*/true);
   if (!this->visit(RHS))
 return false;
   if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
@@ -2710,8 +2712,8 @@ bool Compiler::VisitMaterializeTemporaryExpr(
   // For everyhing else, use local variables.
   if (SubExprT) {
 bool IsConst = SubExpr->getType().isConstQualified();
-unsign

[clang] [clang][bytecode] Use ExtendingDecl mechanism for primitives as well (PR #128141)

2025-02-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

... when creating the temporary variables for a
MaterializeTemporaryExpr.

---

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


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+47-42) 
- (modified) clang/lib/AST/ByteCode/Compiler.h (+1-1) 
- (added) clang/test/AST/ByteCode/libcxx/primitive-temporary.cpp (+271) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 503c58a67adeb..ec18f9d72b66f 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -567,8 +567,8 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 // Location for the SubExpr.
 // Since SubExpr is of complex type, visiting it results in a pointer
 // anyway, so we just create a temporary pointer variable.
-unsigned SubExprOffset = allocateLocalPrimitive(
-SubExpr, PT_Ptr, /*IsConst=*/true, /*IsExtended=*/false);
+unsigned SubExprOffset =
+allocateLocalPrimitive(SubExpr, PT_Ptr, /*IsConst=*/true);
 if (!this->visit(SubExpr))
   return false;
 if (!this->emitSetLocal(PT_Ptr, SubExprOffset, CE))
@@ -611,8 +611,8 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 
 const auto *VT = CE->getType()->getAs();
 PrimType ElemT = classifyPrim(SubExpr->getType());
-unsigned ElemOffset = allocateLocalPrimitive(
-SubExpr, ElemT, /*IsConst=*/true, /*IsExtended=*/false);
+unsigned ElemOffset =
+allocateLocalPrimitive(SubExpr, ElemT, /*IsConst=*/true);
 
 // Prepare a local variable for the scalar value.
 if (!this->visit(SubExpr))
@@ -1104,7 +1104,7 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
   PrimType ResultElemT = this->classifyComplexElementType(E->getType());
   unsigned ResultOffset = ~0u;
   if (!DiscardResult)
-ResultOffset = this->allocateLocalPrimitive(E, PT_Ptr, true, false);
+ResultOffset = this->allocateLocalPrimitive(E, PT_Ptr, /*IsConst=*/true);
 
   // Save result pointer in ResultOffset
   if (!this->DiscardResult) {
@@ -1178,14 +1178,14 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
 
   // Evaluate LHS and save value to LHSOffset.
   if (LHSType->isAnyComplexType()) {
-LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
+LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, /*IsConst=*/true);
 if (!this->visit(LHS))
   return false;
 if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
   return false;
   } else {
 PrimType LHST = classifyPrim(LHSType);
-LHSOffset = this->allocateLocalPrimitive(LHS, LHST, true, false);
+LHSOffset = this->allocateLocalPrimitive(LHS, LHST, /*IsConst=*/true);
 if (!this->visit(LHS))
   return false;
 if (!this->emitSetLocal(LHST, LHSOffset, E))
@@ -1195,14 +1195,14 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
   // Same with RHS.
   unsigned RHSOffset;
   if (RHSType->isAnyComplexType()) {
-RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
+RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, /*IsConst=*/true);
 if (!this->visit(RHS))
   return false;
 if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
   return false;
   } else {
 PrimType RHST = classifyPrim(RHSType);
-RHSOffset = this->allocateLocalPrimitive(RHS, RHST, true, false);
+RHSOffset = this->allocateLocalPrimitive(RHS, RHST, /*IsConst=*/true);
 if (!this->visit(RHS))
   return false;
 if (!this->emitSetLocal(RHST, RHSOffset, E))
@@ -1342,14 +1342,16 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   PrimType ResultElemT = this->classifyVectorElementType(E->getType());
 
   // Evaluate LHS and save value to LHSOffset.
-  unsigned LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
+  unsigned LHSOffset =
+  this->allocateLocalPrimitive(LHS, PT_Ptr, /*IsConst=*/true);
   if (!this->visit(LHS))
 return false;
   if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
 return false;
 
   // Evaluate RHS and save value to RHSOffset.
-  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
+  unsigned RHSOffset =
+  this->allocateLocalPrimitive(RHS, PT_Ptr, /*IsConst=*/true);
   if (!this->visit(RHS))
 return false;
   if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
@@ -2710,8 +2712,8 @@ bool Compiler::VisitMaterializeTemporaryExpr(
   // For everyhing else, use local variables.
   if (SubExprT) {
 bool IsConst = SubExpr->getType().isConstQualified();
-unsigned LocalIndex = allocateLocalPrimitive(E, *SubExprT, IsConst,
- /*IsExtended=*/true);
+unsigned LocalIndex =
+allocateLocalPrimitive(E, *SubExprT, IsConst, E->getExtendingDecl());
 if (!this->visit(SubExpr))
   

[clang] [clang-format] Allow specifying the language for `.h` files (PR #128122)

2025-02-20 Thread Owen Pan via cfe-commits

owenca wrote:

> a bit old school..
> 
> ```
> /* -*- Mode: C++; -*- */
> /* -*- Mode: C; -*- */
> /* -*- Mode: objc; -*- */
> ```

We support the following now:
```cpp
// clang-format off
// clang-format off: reason
// clang-format on
// clang-format on: reason
/* clang-format off */
/* clang-format on */
```
and in configuration:
```
Language: Cpp
Language: ObjC
# After adding LK_C:
# Language: C
```
So to make it simple and consistent, I chose `// clang-format Language: ObjC`, 
etc. IMO, we must include `// clang-format` as a prefix in order to not 
interfere with comment directives from other tools like clang-tidy and lint.

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


[clang] [libc] [Clang] Fix cross-lane scan when given divergent lanes (PR #127703)

2025-02-20 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

/cherry-pick 
https://github.com/llvm/llvm-project/commit/6cc7ca084a5bbb7ccf606cab12065604453dde59

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


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

2025-02-20 Thread Denis Mikhailov via cfe-commits

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


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


[clang] [HLSL] Implement default constant buffer `$Globals` (PR #125807)

2025-02-20 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-asan` running on `sanitizer-buildbot7` while 
building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:510:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:510:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:510:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:510:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:510:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:510:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:510:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 86614 tests, 72 workers --
Testing:  0.. 
FAIL: Clang :: CodeGenHLSL/basic_types.hlsl (9619 of 86614)
 TEST 'Clang :: CodeGenHLSL/basic_types.hlsl' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/21/include
 -nostdsysteminc -std=hlsl2021 -finclude-default-header -x hlsl -triple
dxil-pc-shadermodel6.3-library 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/CodeGenHLSL/basic_types.hlsl
 -fnative-half-type-emit-llvm -disable-llvm-passes -o - | 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/CodeGenHLSL/basic_types.hlsl
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/21/include
 -nostdsysteminc -std=hlsl2021 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.3-library 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/CodeGenHLSL/basic_types.hlsl
 -fnative-half-type -emit-llvm -disable-llvm-passes -o -
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/CodeGenHLSL/basic_types.hlsl
warning: support for HLSL language version hlsl2021 is incomplete, recommend 
using hlsl202x instead
1 warning generated.

--


Testing:  0.. 10.. 20
FAIL: Clang :: SemaHLSL/BuiltIns/RWBuffers.hlsl (19163 of 86614)
 TEST 'Clang :: SemaHLSL/BuiltIns/RWBuffers.hlsl' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/21/include
 -nostdsysteminc -triple dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only 
-verify 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/21/include
 -nostdsysteminc -triple dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only 
-verify 
/home/b/san

[clang] 24c06a1 - [C++20] [Modules] handling selectAny attribute for vardecl

2025-02-20 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2025-02-21T10:48:30+08:00
New Revision: 24c06a19be7bcf28b37e5eabbe65df95a2c0265a

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

LOG: [C++20] [Modules] handling selectAny attribute for vardecl

Close https://github.com/llvm/llvm-project/issues/127963

The root cause of the problem seems to be that we didn't realize it
simply.

Added: 
clang/test/Modules/pr127943.cppm

Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d95763b22a819..32cc9d33730d5 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4803,7 +4803,8 @@ bool Sema::checkVarDeclRedefinition(VarDecl *Old, VarDecl 
*New) {
   (New->getFormalLinkage() == Linkage::Internal || New->isInline() ||
isa(New) ||
New->getDescribedVarTemplate() || New->getNumTemplateParameterLists() ||
-   New->getDeclContext()->isDependentContext())) {
+   New->getDeclContext()->isDependentContext() ||
+   New->hasAttr())) {
 // The previous definition is hidden, and multiple definitions are
 // permitted (in separate TUs). Demote this to a declaration.
 New->demoteThisDefinitionToDeclaration();

diff  --git a/clang/test/Modules/pr127943.cppm 
b/clang/test/Modules/pr127943.cppm
new file mode 100644
index 0..7cc3be6903e6a
--- /dev/null
+++ b/clang/test/Modules/pr127943.cppm
@@ -0,0 +1,31 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/repro.cppm -fdeclspec -emit-module-interface 
-o %t/repro.pcm
+// RUN: %clang_cc1 -std=c++20 %t/source.cpp -fdeclspec -fsyntax-only -verify 
-fprebuilt-module-path=%t
+
+//--- repro_decl.hpp
+#pragma once
+
+extern "C"
+{
+__declspec(selectany) int foo = 0;
+}
+
+//--- repro.cppm
+module;
+#include "repro_decl.hpp"
+
+export module repro;
+
+export inline int func()
+{
+return foo;
+}
+
+//--- source.cpp
+// expected-no-diagnostics
+import repro;
+
+#include "repro_decl.hpp"



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


[clang] Revert "[HLSL] Implement default constant buffer `$Globals`" (PR #128112)

2025-02-20 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-arm-ubuntu` running 
on `linaro-lldb-arm-ubuntu` while building `clang` at step 6 "test".

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


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

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: tools/lldb-dap/exception/TestDAP_exception.py (1151 of 2910)
PASS: lldb-api :: tools/lldb-dap/exception/cpp/TestDAP_exception_cpp.py (1152 
of 2910)
UNSUPPORTED: lldb-api :: 
tools/lldb-dap/exception/objc/TestDAP_exception_objc.py (1153 of 2910)
PASS: lldb-api :: tools/lldb-dap/databreakpoint/TestDAP_setDataBreakpoints.py 
(1154 of 2910)
UNSUPPORTED: lldb-api :: 
tools/lldb-dap/extendedStackTrace/TestDAP_extendedStackTrace.py (1155 of 2910)
PASS: lldb-api :: 
tools/lldb-dap/instruction-breakpoint/TestDAP_instruction_breakpoint.py (1156 
of 2910)
PASS: lldb-api :: tools/lldb-dap/disconnect/TestDAP_disconnect.py (1157 of 2910)
PASS: lldb-api :: tools/lldb-dap/locations/TestDAP_locations.py (1158 of 2910)
PASS: lldb-api :: tools/lldb-dap/memory/TestDAP_memory.py (1159 of 2910)
PASS: lldb-api :: tools/lldb-dap/optimized/TestDAP_optimized.py (1160 of 2910)
FAIL: lldb-api :: tools/lldb-dap/output/TestDAP_output.py (1161 of 2910)
 TEST 'lldb-api :: tools/lldb-dap/output/TestDAP_output.py' 
FAILED 
Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py 
-u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env 
LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch 
armv8l --build-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil 
--make /usr/bin/gmake --llvm-tools-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/output
 -p TestDAP_output.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
6e5f26bba87be02ea4c1220898031c441c2562fc)
  clang revision 6e5f26bba87be02ea4c1220898031c441c2562fc
  llvm revision 6e5f26bba87be02ea4c1220898031c441c2562fc
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']
= DEBUG ADAPTER PROTOCOL LOGS =
1740106519.131071329 --> 
Content-Length: 344

{
  "arguments": {
"adapterID": "lldb-native",
"clientID": "vscode",
"columnsStartAt1": true,
"linesStartAt1": true,
"locale": "en-us",
"pathFormat": "path",
"sourceInitFile": false,
"supportsRunInTerminalRequest": true,
"supportsStartDebuggingRequest": true,
"supportsVariablePaging": true,
"supportsVariableType": true
  },
  "command": "initialize",
  "seq": 1,
  "type": "request"
}
1740106519.133443594 <-- 
Content-Length: 1631


```



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


[clang] [lld] [llvm] Integrated Distributed ThinLTO (DTLTO): Initial support (PR #126654)

2025-02-20 Thread Katya Romanova via cfe-commits

romanova-ekaterina wrote:

> > I don't have a strong opinion on this but I have basically the same 
> > concerns with completely opposite conclusions. To me, the distributed 
> > thinLTO makes you think there is a distributed full LTO, while just call it 
> > distributed LTO will eliminate that confusion. Distributed LTO is by nature 
> > based on thin LTO infrastructure but that doesn't need to be exposed.
> 
> Accepted. I think it might be worth appealing to authority here. I wonder if 
> @MaskRay or @teresajohnson have an opinion?
> 
> > Isn't the LTO option to be `Full/Thin/Distributed` cleaner?
> 
> Sorry, I don't entirely understand this bit, could you expand on this a bit. 
> Are you envisioning an interface like: clang -flto -> FullLTO clang 
> -flto=thin -> ThinLTO clang -flto=distributed -> DTLTO
> 
> > You can still keep `DTLTO` for `DisTributed LTO`
> 
> :)

We prefer to keep DTLTO name. One of the reason is to distinguish our 
"integrated" distributed 
appoach from "non-integrated" distributed approach that has been supported for 
a while.
Another reason is to avoid confusion. We have been using this acronim for a 
while,
referring to it in RFCs and in a couple of lightning talks on developer 
conferences. When we had a round table last LLVM developers conference we 
brought up this topic about naming one more time and we all agreed to keep 
DTLTO name.


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


[clang] [lld] [llvm] Integrated Distributed ThinLTO (DTLTO): Initial support (PR #126654)

2025-02-20 Thread Katya Romanova via cfe-commits

romanova-ekaterina wrote:

> I'm fine with DTLTO as a shorthand for "integrated distributed ThinLTO".
Great! I'm glad that you support this acronim too. :)


> BTW thanks for sending the LLVM patch, I will review that tonight or more 
> likely tomorrow.

Teresa, when reviewing, could you please focus on the design/idea rather than 
doing a full-fledged code review? In a day or two we will submit another PR for 
"no-backend" DTLTO implementation. We are doing final "touches" to this PR now. 

No-backend DLTO implementation has some important benefits/advantages. So, I 
guess, at this time, it will be most important to understand both designs (i.e. 
current implementation with DTLTO backend that Ben submitted and the 
alternative "no DTLTO backend" implementation that we submit a couple of from 
now), rather than focusing on details of implementations/nikpicks of this 
particular PR. 

I will try to do my best to explain the differences between both designs at the 
time of submission.

Hopefully, it will help us to choose the best design for using upstream or 
potentially do a hybrid solution, choosing the best ideas from both designs.



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


[clang] [clang-format] Allow specifying the language for `.h` files (PR #128122)

2025-02-20 Thread via cfe-commits

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

I think this should help, I wonder if there is a equivalent of this (but for 
C/ObjC) that we can support

```
# -*-Mode: Makefile;-*-
```


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


[clang] [clang-format] Allow specifying the language for `.h` files (PR #128122)

2025-02-20 Thread via cfe-commits

mydeveloperday wrote:

a bit old school..

```
/* -*- Mode: C++; -*- */
/* -*- Mode: C; -*- */
/* -*- Mode: objc; -*- */
```

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


[clang] [clang][modules] Fix local submodule visibility of macros from transitive import (PR #122955)

2025-02-20 Thread Michael Spencer via cfe-commits

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


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


[clang] 204dcaf - [clang-format] Fix a bug in BCIS_AfterColon and `ColumnLimit: 0` (#127964)

2025-02-20 Thread via cfe-commits

Author: Owen Pan
Date: 2025-02-20T19:06:51-08:00
New Revision: 204dcafec0ecf0db81d420d2de57b02ada6b09ec

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

LOG: [clang-format] Fix a bug in BCIS_AfterColon and `ColumnLimit: 0` (#127964)

Fixes #127622

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 3e51b4aab1082..d49128c2b40f8 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -473,9 +473,8 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   (State.Column + State.Line->Last->TotalLength - Previous.TotalLength >
getColumnLimit(State) ||
CurrentState.BreakBeforeParameter) &&
-  (!Current.isTrailingComment() || Current.NewlinesBefore > 0) &&
-  (Style.BreakConstructorInitializers != FormatStyle::BCIS_BeforeColon ||
-   Style.ColumnLimit > 0 || Current.NewlinesBefore > 0)) {
+  ((!Current.isTrailingComment() && Style.ColumnLimit > 0) ||
+   Current.NewlinesBefore > 0)) {
 return true;
   }
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index d6d028436d39c..132264486100d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8292,31 +8292,40 @@ TEST_F(FormatTest, 
BreakConstructorInitializersAfterColon) {
Style);
 
   Style.ColumnLimit = 0;
-  verifyFormat("SomeClass::Constructor() :\n"
-   "a(a) {}",
-   Style);
-  verifyFormat("SomeClass::Constructor() noexcept :\n"
-   "a(a) {}",
-   Style);
-  verifyFormat("SomeClass::Constructor() :\n"
-   "a(a), b(b), c(c) {}",
-   Style);
-  verifyFormat("SomeClass::Constructor() :\n"
-   "a(a) {\n"
-   "  foo();\n"
-   "  bar();\n"
-   "}",
+  verifyNoChange("SomeClass::Constructor() :\n"
+ "a(a) {}",
+ Style);
+  verifyNoChange("SomeClass::Constructor() noexcept :\n"
+ "a(a) {}",
+ Style);
+  verifyNoChange("SomeClass::Constructor() :\n"
+ "a(a), b(b), c(c) {}",
+ Style);
+  verifyNoChange("SomeClass::Constructor() :\n"
+ "a(a) {\n"
+ "  foo();\n"
+ "  bar();\n"
+ "}",
+ Style);
+  verifyFormat("struct Foo {\n"
+   "  int x;\n"
+   "  Foo() : x(0) {}\n"
+   "};",
+   "struct Foo {\n"
+   "  int x;\n"
+   "  Foo():x(0) {}\n"
+   "};",
Style);
 
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
-  verifyFormat("SomeClass::Constructor() :\n"
-   "a(a), b(b), c(c) {\n"
-   "}",
-   Style);
-  verifyFormat("SomeClass::Constructor() :\n"
-   "a(a) {\n"
-   "}",
-   Style);
+  verifyNoChange("SomeClass::Constructor() :\n"
+ "a(a), b(b), c(c) {\n"
+ "}",
+ Style);
+  verifyNoChange("SomeClass::Constructor() :\n"
+ "a(a) {\n"
+ "}",
+ Style);
 
   Style.ColumnLimit = 80;
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;



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


[clang] [clang-format] Fix a bug in BCIS_AfterColon and `ColumnLimit: 0` (PR #127964)

2025-02-20 Thread Owen Pan via cfe-commits

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


[clang] Revert "[HLSL] Implement default constant buffer `$Globals`" (PR #128112)

2025-02-20 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-remote-linux-win` 
running on `as-builder-10` while building `clang` at step 17 
"test-check-lldb-api".

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


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

```
Step 17 (test-check-lldb-api) failure: Test just built components: 
check-lldb-api completed (failure)
...
UNSUPPORTED: lldb-api :: 
functionalities/tail_call_frames/unambiguous_sequence/TestUnambiguousTailCalls.py
 (600 of 1232)
PASS: lldb-api :: functionalities/testid/TestTestId.py (601 of 1232)
PASS: lldb-api :: 
functionalities/tail_call_frames/sbapi_support/TestTailCallFrameSBAPI.py (602 
of 1232)
PASS: lldb-api :: functionalities/target_var/no_vars/TestTargetVarNoVars.py 
(603 of 1232)
PASS: lldb-api :: 
functionalities/tail_call_frames/thread_step_out_or_return/TestSteppingOutWithArtificialFrames.py
 (604 of 1232)
PASS: lldb-api :: functionalities/thread/backtrace_limit/TestBacktraceLimit.py 
(605 of 1232)
PASS: lldb-api :: 
functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py (606 
of 1232)
PASS: lldb-api :: functionalities/target_var/TestTargetVar.py (607 of 1232)
PASS: lldb-api :: 
functionalities/thread/concurrent_events/TestConcurrentCrashWithBreak.py (608 
of 1232)
UNRESOLVED: lldb-api :: 
functionalities/thread/concurrent_events/TestConcurrentCrashWithWatchpoint.py 
(609 of 1232)
 TEST 'lldb-api :: 
functionalities/thread/concurrent_events/TestConcurrentCrashWithWatchpoint.py' 
FAILED 
Script:
--
C:/Python312/python.exe 
C:/buildbot/as-builder-10/lldb-x-aarch64/llvm-project/lldb\test\API\dotest.py 
-u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=C:/buildbot/as-builder-10/lldb-x-aarch64/build/./lib --env 
LLVM_INCLUDE_DIR=C:/buildbot/as-builder-10/lldb-x-aarch64/build/include --env 
LLVM_TOOLS_DIR=C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin --arch 
aarch64 --build-dir 
C:/buildbot/as-builder-10/lldb-x-aarch64/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
C:/buildbot/as-builder-10/lldb-x-aarch64/build/lldb-test-build.noindex/module-cache-lldb\lldb-api
 --clang-module-cache-dir 
C:/buildbot/as-builder-10/lldb-x-aarch64/build/lldb-test-build.noindex/module-cache-clang\lldb-api
 --executable C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin/lldb.exe 
--compiler C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin/clang.exe 
--dsymutil C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin/dsymutil.exe 
--make C:/ninja/make.exe --llvm-tools-dir 
C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin --lldb-obj-root 
C:/buildbot/as-builder-10/lldb-x-aarch64/build/tools/lldb --lldb-libs-dir 
C:/buildbot/as-builder-10/lldb-x-aarch64/build/./lib --platform-url 
connect://jetson-agx-0086.lab.llvm.org:1234 --platform-working-dir 
/home/ubuntu/lldb-tests --sysroot c:/buildbot/fs/jetson-agx-ubuntu --env 
ARCH_CFLAGS=-mcpu=cortex-a78 --platform-name remote-linux 
--skip-category=lldb-server 
C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\test\API\functionalities\thread\concurrent_events
 -p TestConcurrentCrashWithWatchpoint.py
--
Exit Code: 2147483651

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
6e5f26bba87be02ea4c1220898031c441c2562fc)
  clang revision 6e5f26bba87be02ea4c1220898031c441c2562fc
  llvm revision 6e5f26bba87be02ea4c1220898031c441c2562fc

--
Command Output (stderr):
--
Assertion failed: 
m_gdb_client_up->IsConnected(), file 
C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\source\Plugins\Platform\gdb-server\PlatformRemoteGDBServer.cpp,
 line 210
Windows fatal exception: code 0x8003

Current thread 0x336c (most recent call first):
  File 
"C:\buildbot\as-builder-10\lldb-x-aarch64\build\Lib\site-packages\lldb\__init__.py",
 line 3522 in HandleCommand
  File 
"C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\packages\Python\lldbsuite\test\lldbtest.py",
 line 971 in runCmd
  File 
"C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\packages\Python\lldbsuite\test\concurrent_base.py",
 line 158 in do_thread_actions
  File 
"C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\test\API\functionalities\thread\concurrent_events\TestConcurrentCrashWithWatchpoint.py",
 line 14 in test
  File 
"C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\packages\Python\lldbsuite\test\decorators.py",
 line 148 in wrapper
  File "C:\Python312\Lib\unittest\case.py", line 589 in _callTestMethod
  File "C:\Python312\Lib\unittest\case.py", line 634 in run
  File "C:\Python312\Lib\unittest\case.py", line 690 in __call__
  File "C:\Python312\Lib\unittest\suite.py", line 122 in run
  File "C:\Python312\Lib\unittest\sui

[clang] Revert "[HLSL] Implement default constant buffer `$Globals`" (PR #128112)

2025-02-20 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`clang` at step 7 "Add check check-offload".

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


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

```
Step 7 (Add check check-offload) failure: 1200 seconds without output running 
[b'ninja', b'-j 32', b'check-offload'], attempting to kill
...
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49779.cpp 
(1001 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/test_libc.cpp 
(1002 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug47654.cpp 
(1003 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/wtime.c (1004 
of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug50022.cpp 
(1005 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/bug49021.cpp (1006 
of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: 
offloading/std_complex_arithmetic.cpp (1007 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: 
offloading/complex_reduction.cpp (1008 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49021.cpp 
(1009 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: 
offloading/std_complex_arithmetic.cpp (1010 of 1011)
command timed out: 1200 seconds without output running [b'ninja', b'-j 32', 
b'check-offload'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1235.716039

```



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


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

2025-02-20 Thread Baranov Victor via cfe-commits

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

>From 42e03bb9cc9bd815476b0a3f06ac5f58826e3708 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Fri, 31 Jan 2025 19:29:05 +0300
Subject: [PATCH 1/6] [clang-tidy] add new check bugprone-reset-ambiguous-call

---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 .../SmartptrResetAmbiguousCallCheck.cpp   | 146 +++
 .../SmartptrResetAmbiguousCallCheck.h |  37 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../smartptr-reset-ambiguous-call.rst |  47 
 .../docs/clang-tidy/checks/list.rst   |   1 +
 ...r-reset-ambiguous-call-custom-pointers.cpp |  72 ++
 .../smartptr-reset-ambiguous-call.cpp | 239 ++
 9 files changed, 552 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/SmartptrResetAmbiguousCallCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/SmartptrResetAmbiguousCallCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/smartptr-reset-ambiguous-call.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/smartptr-reset-ambiguous-call-custom-pointers.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/smartptr-reset-ambiguous-call.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index c5f0b5b28418f..a01d0e384ab73 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -64,6 +64,7 @@
 #include "SignedCharMisuseCheck.h"
 #include "SizeofContainerCheck.h"
 #include "SizeofExpressionCheck.h"
+#include "SmartptrResetAmbiguousCallCheck.h"
 #include "SpuriouslyWakeUpFunctionsCheck.h"
 #include "StandaloneEmptyCheck.h"
 #include "StringConstructorCheck.h"
@@ -207,6 +208,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-sizeof-container");
 CheckFactories.registerCheck(
 "bugprone-sizeof-expression");
+CheckFactories.registerCheck(
+"bugprone-smartptr-reset-ambiguous-call");
 CheckFactories.registerCheck(
 "bugprone-spuriously-wake-up-functions");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index e8309c68b7fca..7fd6f4994f537 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -65,6 +65,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp
   SmartPtrArrayMismatchCheck.cpp
+  SmartptrResetAmbiguousCallCheck.cpp
   SpuriouslyWakeUpFunctionsCheck.cpp
   StandaloneEmptyCheck.cpp
   StringConstructorCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/SmartptrResetAmbiguousCallCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SmartptrResetAmbiguousCallCheck.cpp
new file mode 100644
index 0..326a5665179d7
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/SmartptrResetAmbiguousCallCheck.cpp
@@ -0,0 +1,146 @@
+//===--- SmartptrResetAmbiguousCallCheck.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 "SmartptrResetAmbiguousCallCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+AST_MATCHER_P(CallExpr, everyArgumentMatches,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : Node.arguments()) {
+if (!InnerMatcher.matches(*Arg, Finder, Builder))
+  return false;
+  }
+
+  return true;
+}
+
+AST_MATCHER(CXXMethodDecl, hasOnlyDefaultParameters) {
+  for (const auto *Param : Node.parameters()) {
+if (!Param->hasDefaultArg())
+  return false;
+  }
+
+  return true;
+}
+
+const auto DefaultSmartPointers = "::std::shared_ptr;::std::unique_ptr";
+} // namespace
+
+SmartptrResetAmbiguousCallCheck::SmartptrResetAmbiguousCallCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SmartPointers(utils::options::parseStringList(
+  Options.get("SmartPointers", DefaultSmartPointers))) {}
+
+void SmartptrResetAmbiguousCallCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "SmartPointers",
+utils::options::seriali

[clang] [Clang] Implement CWG2918 'Consideration of constraints for address of overloaded function' (PR #127773)

2025-02-20 Thread Younan Zhang via cfe-commits

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

>From 2d9c248c70b6d24f277982a32f36e2ef1bde2829 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Wed, 19 Feb 2025 17:13:56 +0800
Subject: [PATCH 1/3] [Clang] Implement CWG2918 'Consideration of constraints
 for address of overloaded function'

---
 clang/docs/ReleaseNotes.rst  |   4 +
 clang/include/clang/Sema/Sema.h  |   3 +-
 clang/lib/Sema/SemaConcept.cpp   |   5 +-
 clang/lib/Sema/SemaOverload.cpp  | 110 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp |   9 +-
 clang/test/CXX/drs/cwg29xx.cpp   |  84 +
 clang/www/cxx_dr_status.html |   2 +-
 7 files changed, 187 insertions(+), 30 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a91c764860ccd..b876b48c63717 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,10 @@ Resolutions to C++ Defect Reports
   two releases. The improvements to template template parameter matching 
implemented
   in the previous release, as described in P3310 and P3579, made this flag 
unnecessary.
 
+- Implemented `CWG2918 Consideration of constraints for address of overloaded `
+  `function `_
+
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c55b964650323..3270e7afb3796 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10466,7 +10466,8 @@ class Sema final : public SemaBase {
   /// returned.
   FunctionDecl *ResolveSingleFunctionTemplateSpecialization(
   OverloadExpr *ovl, bool Complain = false, DeclAccessPair *Found = 
nullptr,
-  TemplateSpecCandidateSet *FailedTSC = nullptr);
+  TemplateSpecCandidateSet *FailedTSC = nullptr,
+  bool ForTypeDeduction = false);
 
   // Resolve and fix an overloaded expression that can be resolved
   // because it identifies a single function template specialization.
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 8a77cbf8c9477..f8bc176c1d8b5 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1773,6 +1773,7 @@ bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
   NamedDecl *D2,
   MutableArrayRef AC2,
   bool &Result) {
+#ifndef NDEBUG
   if (const auto *FD1 = dyn_cast(D1)) {
 auto IsExpectedEntity = [](const FunctionDecl *FD) {
   FunctionDecl::TemplatedKind Kind = FD->getTemplatedKind();
@@ -1780,13 +1781,11 @@ bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
  Kind == FunctionDecl::TK_FunctionTemplate;
 };
 const auto *FD2 = dyn_cast(D2);
-(void)IsExpectedEntity;
-(void)FD1;
-(void)FD2;
 assert(IsExpectedEntity(FD1) && FD2 && IsExpectedEntity(FD2) &&
"use non-instantiated function declaration for constraints partial "
"ordering");
   }
+#endif
 
   if (AC1.empty()) {
 Result = AC2.empty();
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 8d5b5ac190b5b..77fc78dd8ce99 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10369,20 +10369,16 @@ static bool allowAmbiguity(ASTContext &Context, const 
FunctionDecl *F1,
 /// [over.match.best.general]p2.6
 /// F1 and F2 are non-template functions with the same
 /// non-object-parameter-type-lists, and F1 is more constrained than F2 [...]
-static bool sameFunctionParameterTypeLists(Sema &S,
-   const OverloadCandidate &Cand1,
-   const OverloadCandidate &Cand2) {
-  if (!Cand1.Function || !Cand2.Function)
-return false;
-
-  FunctionDecl *Fn1 = Cand1.Function;
-  FunctionDecl *Fn2 = Cand2.Function;
-
+static bool sameFunctionParameterTypeLists(Sema &S, FunctionDecl *Fn1,
+   FunctionDecl *Fn2,
+   bool IsFn1Reversed,
+   bool IsFn2Reversed) {
+  assert(Fn1 && Fn2);
   if (Fn1->isVariadic() != Fn2->isVariadic())
 return false;
 
-  if (!S.FunctionNonObjectParamTypesAreEqual(
-  Fn1, Fn2, nullptr, Cand1.isReversed() ^ Cand2.isReversed()))
+  if (!S.FunctionNonObjectParamTypesAreEqual(Fn1, Fn2, nullptr,
+ IsFn1Reversed ^ IsFn2Reversed))
 return false;
 
   auto *Mem1 = dyn_cast(Fn1);
@@ -10403,6 +10399,30 @@ static bool sameFunctionParameterTypeLists(Sema &S,
   return true;
 }
 
+static FunctionDecl *
+getMorePartialOrderingConstrained(Sema &S, FunctionDecl *Fn1, FunctionDecl 
*Fn2,
+  bool IsFn1Reversed, bool IsFn2Reversed) {
+  if (!Fn1 || !Fn2)
+return nullptr;
+
+  // C++ [te

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

2025-02-20 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,49 @@
+.. title:: clang-tidy - readability-ambiguous-smartptr-reset-call
+
+readability-ambiguous-smartptr-reset-call
+=
+
+Finds potentially erroneous calls to ``reset`` method on smart pointers when
+the pointee type also has a ``reset`` method. Having a ``reset`` method in
+both classes makes it easy to accidentally make the pointer null when
+intending to reset the underlying object.
+
+.. code-block:: c++
+
+  struct Resettable {
+void reset() { /* Own reset logic */ }
+  };
+
+  auto ptr = std::make_unique();
+
+  ptr->reset();  // Calls underlying reset method
+  ptr.reset();   // Makes the pointer null
+
+Both calls are valid C++ code, but the second one might not be what the
+developer intended, as it destroys the pointed-to object rather than resetting
+its state. It's easy to make such a typo because the difference between
+``.`` and ``->`` is really small.
+
+The recommended approach is to make the intent explicit by using either member
+access or direct assignment:
+
+.. code-block:: c++
+
+  std::unique_ptr ptr = std::make_unique();
+
+  (*ptr).reset();  // Clearly calls underlying reset method
+  ptr = nullptr;   // Clearly makes the pointer null
+
+The default smart pointers and classes that are considered are
+``std::unique_ptr``, ``std::shared_ptr``, ``std::optional``,
+``boost::shared_ptr``, ``boost::scoped_ptr``. To specify other smart pointers
+or other classes use the :option:`SmartPointers` option.
+
+Options
+---
+
+.. option:: SmartPointers
+
+Semicolon-separated list of fully qualified class names of custom smart
+pointers. Default value is `::std::unique_ptr;::std::shared_ptr;
+::std::optional;::boost::unique_ptr;::boost::shared_ptr`.

vbvictor wrote:

Done

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


[clang] [Clang] Implement CWG2918 'Consideration of constraints for address of overloaded function' (PR #127773)

2025-02-20 Thread Younan Zhang via cfe-commits

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

>From 2d9c248c70b6d24f277982a32f36e2ef1bde2829 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Wed, 19 Feb 2025 17:13:56 +0800
Subject: [PATCH 1/4] [Clang] Implement CWG2918 'Consideration of constraints
 for address of overloaded function'

---
 clang/docs/ReleaseNotes.rst  |   4 +
 clang/include/clang/Sema/Sema.h  |   3 +-
 clang/lib/Sema/SemaConcept.cpp   |   5 +-
 clang/lib/Sema/SemaOverload.cpp  | 110 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp |   9 +-
 clang/test/CXX/drs/cwg29xx.cpp   |  84 +
 clang/www/cxx_dr_status.html |   2 +-
 7 files changed, 187 insertions(+), 30 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a91c764860ccd..b876b48c63717 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,10 @@ Resolutions to C++ Defect Reports
   two releases. The improvements to template template parameter matching 
implemented
   in the previous release, as described in P3310 and P3579, made this flag 
unnecessary.
 
+- Implemented `CWG2918 Consideration of constraints for address of overloaded `
+  `function `_
+
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c55b964650323..3270e7afb3796 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10466,7 +10466,8 @@ class Sema final : public SemaBase {
   /// returned.
   FunctionDecl *ResolveSingleFunctionTemplateSpecialization(
   OverloadExpr *ovl, bool Complain = false, DeclAccessPair *Found = 
nullptr,
-  TemplateSpecCandidateSet *FailedTSC = nullptr);
+  TemplateSpecCandidateSet *FailedTSC = nullptr,
+  bool ForTypeDeduction = false);
 
   // Resolve and fix an overloaded expression that can be resolved
   // because it identifies a single function template specialization.
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 8a77cbf8c9477..f8bc176c1d8b5 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1773,6 +1773,7 @@ bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
   NamedDecl *D2,
   MutableArrayRef AC2,
   bool &Result) {
+#ifndef NDEBUG
   if (const auto *FD1 = dyn_cast(D1)) {
 auto IsExpectedEntity = [](const FunctionDecl *FD) {
   FunctionDecl::TemplatedKind Kind = FD->getTemplatedKind();
@@ -1780,13 +1781,11 @@ bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
  Kind == FunctionDecl::TK_FunctionTemplate;
 };
 const auto *FD2 = dyn_cast(D2);
-(void)IsExpectedEntity;
-(void)FD1;
-(void)FD2;
 assert(IsExpectedEntity(FD1) && FD2 && IsExpectedEntity(FD2) &&
"use non-instantiated function declaration for constraints partial "
"ordering");
   }
+#endif
 
   if (AC1.empty()) {
 Result = AC2.empty();
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 8d5b5ac190b5b..77fc78dd8ce99 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10369,20 +10369,16 @@ static bool allowAmbiguity(ASTContext &Context, const 
FunctionDecl *F1,
 /// [over.match.best.general]p2.6
 /// F1 and F2 are non-template functions with the same
 /// non-object-parameter-type-lists, and F1 is more constrained than F2 [...]
-static bool sameFunctionParameterTypeLists(Sema &S,
-   const OverloadCandidate &Cand1,
-   const OverloadCandidate &Cand2) {
-  if (!Cand1.Function || !Cand2.Function)
-return false;
-
-  FunctionDecl *Fn1 = Cand1.Function;
-  FunctionDecl *Fn2 = Cand2.Function;
-
+static bool sameFunctionParameterTypeLists(Sema &S, FunctionDecl *Fn1,
+   FunctionDecl *Fn2,
+   bool IsFn1Reversed,
+   bool IsFn2Reversed) {
+  assert(Fn1 && Fn2);
   if (Fn1->isVariadic() != Fn2->isVariadic())
 return false;
 
-  if (!S.FunctionNonObjectParamTypesAreEqual(
-  Fn1, Fn2, nullptr, Cand1.isReversed() ^ Cand2.isReversed()))
+  if (!S.FunctionNonObjectParamTypesAreEqual(Fn1, Fn2, nullptr,
+ IsFn1Reversed ^ IsFn2Reversed))
 return false;
 
   auto *Mem1 = dyn_cast(Fn1);
@@ -10403,6 +10399,30 @@ static bool sameFunctionParameterTypeLists(Sema &S,
   return true;
 }
 
+static FunctionDecl *
+getMorePartialOrderingConstrained(Sema &S, FunctionDecl *Fn1, FunctionDecl 
*Fn2,
+  bool IsFn1Reversed, bool IsFn2Reversed) {
+  if (!Fn1 || !Fn2)
+return nullptr;
+
+  // C++ [te

[clang] Add clang atomic control options and attribute (PR #114841)

2025-02-20 Thread Yaxun Liu via cfe-commits


@@ -313,6 +313,8 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+FEATURE(atomic_attributes, true)

yxsamliu wrote:

will change

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


[clang] [clang-format] Allow specifying the language for `.h` files (PR #128122)

2025-02-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Owen Pan (owenca)


Changes

Closes #128119

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


5 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+7-1) 
- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Format/Format.h (+6-1) 
- (modified) clang/lib/Format/Format.cpp (+33) 
- (modified) clang/unittests/Format/FormatTest.cpp (+9) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bf6dd9e13915f..2d4ead76cfef2 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4782,7 +4782,13 @@ the configuration (without a prefix: ``Auto``).
 .. _Language:
 
 **Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`¶ 
`
-  Language, this format style is targeted at.
+  The language that this format style targets.
+
+  .. note::
+
+   You can also specify the language (``Cpp`` or ``ObjC``) for ``.h`` files
+   by adding a ``// clang-format Language:`` line before the first
+   non-comment and non-empty line, e.g. ``// clang-format Language: ObjC``.
 
   Possible values:
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e1c61992512b5..0e65f72623f28 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -269,6 +269,9 @@ clang-format
 - Adds ``BreakBeforeTemplateCloser`` option.
 - Adds ``BinPackLongBracedList`` option to override bin packing options in
   long (20 item or more) braced list initializer lists.
+- Allow specifying the language (C++ or Objective-C) for a ``.h`` file by 
adding
+  a special comment (e.g. ``// clang-format Language: ObjC``) near the top of
+  the file.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 16956b4e0fbd4..55709a0261b12 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3353,7 +3353,12 @@ struct FormatStyle {
   }
   bool isTableGen() const { return Language == LK_TableGen; }
 
-  /// Language, this format style is targeted at.
+  /// The language that this format style targets.
+  /// \note
+  ///  You can also specify the language (``Cpp`` or ``ObjC``) for ``.h`` files
+  ///  by adding a ``// clang-format Language:`` line before the first
+  ///  non-comment and non-empty line, e.g. ``// clang-format Language: ObjC``.
+  /// \endnote
   /// \version 3.5
   LanguageKind Language;
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 0898b69528ebc..400f39ecc5483 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -4021,6 +4021,35 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
   return FormatStyle::LK_Cpp;
 }
 
+static FormatStyle::LanguageKind getLanguageByComment(const Environment &Env) {
+  const auto ID = Env.getFileID();
+  const auto &SourceMgr = Env.getSourceManager();
+
+  LangOptions LangOpts;
+  LangOpts.CPlusPlus = 1;
+  LangOpts.LineComment = 1;
+
+  Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
+  Lex.SetCommentRetentionState(true);
+
+  for (Token Tok; !Lex.LexFromRawLexer(Tok) && Tok.is(tok::comment);) {
+auto Text = StringRef(SourceMgr.getCharacterData(Tok.getLocation()),
+  Tok.getLength());
+if (!Text.consume_front("// clang-format Language:"))
+  continue;
+
+Text = Text.trim();
+// if (Text == "C")
+//   return FormatStyle::LK_C;
+if (Text == "Cpp")
+  return FormatStyle::LK_Cpp;
+if (Text == "ObjC")
+  return FormatStyle::LK_ObjC;
+  }
+
+  return FormatStyle::LK_None;
+}
+
 FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code) {
   const auto GuessedLanguage = getLanguageByFileName(FileName);
   if (GuessedLanguage == FormatStyle::LK_Cpp) {
@@ -4030,6 +4059,10 @@ FormatStyle::LanguageKind guessLanguage(StringRef 
FileName, StringRef Code) {
 if (!Code.empty() && (Extension.empty() || Extension == ".h")) {
   auto NonEmptyFileName = FileName.empty() ? "guess.h" : FileName;
   Environment Env(Code, NonEmptyFileName, /*Ranges=*/{});
+  if (const auto Language = getLanguageByComment(Env);
+  Language != FormatStyle::LK_None) {
+return Language;
+  }
   ObjCHeaderStyleGuesser Guesser(Env, getLLVMStyle());
   Guesser.process();
   if (Guesser.isObjC())
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 132264486100d..05febf12c17ba 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25136,6 +25136,15 @@ TEST_F(FormatTest, GuessLanguageWithChildLines) {
   guessLanguage("foo.h", "#define FOO ({ foo(); ({ NSString *s; }) })"));
 }
 
+TEST_F(FormatTest, GetLanguageByComment) {
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLangu

[clang] [clang-format] Allow specifying the language for `.h` files (PR #128122)

2025-02-20 Thread Owen Pan via cfe-commits

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

Closes #128119

>From 507c54acac3e73826f63691c901ceba9c569869f Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 20 Feb 2025 20:02:44 -0800
Subject: [PATCH] [clang-format] Allow specifying the language for `.h` files

Closes #128119
---
 clang/docs/ClangFormatStyleOptions.rst |  8 ++-
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/include/clang/Format/Format.h|  7 +-
 clang/lib/Format/Format.cpp| 33 ++
 clang/unittests/Format/FormatTest.cpp  |  9 +++
 5 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bf6dd9e13915f..2d4ead76cfef2 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4782,7 +4782,13 @@ the configuration (without a prefix: ``Auto``).
 .. _Language:
 
 **Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`¶ 
`
-  Language, this format style is targeted at.
+  The language that this format style targets.
+
+  .. note::
+
+   You can also specify the language (``Cpp`` or ``ObjC``) for ``.h`` files
+   by adding a ``// clang-format Language:`` line before the first
+   non-comment and non-empty line, e.g. ``// clang-format Language: ObjC``.
 
   Possible values:
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e1c61992512b5..0e65f72623f28 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -269,6 +269,9 @@ clang-format
 - Adds ``BreakBeforeTemplateCloser`` option.
 - Adds ``BinPackLongBracedList`` option to override bin packing options in
   long (20 item or more) braced list initializer lists.
+- Allow specifying the language (C++ or Objective-C) for a ``.h`` file by 
adding
+  a special comment (e.g. ``// clang-format Language: ObjC``) near the top of
+  the file.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 16956b4e0fbd4..55709a0261b12 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3353,7 +3353,12 @@ struct FormatStyle {
   }
   bool isTableGen() const { return Language == LK_TableGen; }
 
-  /// Language, this format style is targeted at.
+  /// The language that this format style targets.
+  /// \note
+  ///  You can also specify the language (``Cpp`` or ``ObjC``) for ``.h`` files
+  ///  by adding a ``// clang-format Language:`` line before the first
+  ///  non-comment and non-empty line, e.g. ``// clang-format Language: ObjC``.
+  /// \endnote
   /// \version 3.5
   LanguageKind Language;
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 0898b69528ebc..400f39ecc5483 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -4021,6 +4021,35 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
   return FormatStyle::LK_Cpp;
 }
 
+static FormatStyle::LanguageKind getLanguageByComment(const Environment &Env) {
+  const auto ID = Env.getFileID();
+  const auto &SourceMgr = Env.getSourceManager();
+
+  LangOptions LangOpts;
+  LangOpts.CPlusPlus = 1;
+  LangOpts.LineComment = 1;
+
+  Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
+  Lex.SetCommentRetentionState(true);
+
+  for (Token Tok; !Lex.LexFromRawLexer(Tok) && Tok.is(tok::comment);) {
+auto Text = StringRef(SourceMgr.getCharacterData(Tok.getLocation()),
+  Tok.getLength());
+if (!Text.consume_front("// clang-format Language:"))
+  continue;
+
+Text = Text.trim();
+// if (Text == "C")
+//   return FormatStyle::LK_C;
+if (Text == "Cpp")
+  return FormatStyle::LK_Cpp;
+if (Text == "ObjC")
+  return FormatStyle::LK_ObjC;
+  }
+
+  return FormatStyle::LK_None;
+}
+
 FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code) {
   const auto GuessedLanguage = getLanguageByFileName(FileName);
   if (GuessedLanguage == FormatStyle::LK_Cpp) {
@@ -4030,6 +4059,10 @@ FormatStyle::LanguageKind guessLanguage(StringRef 
FileName, StringRef Code) {
 if (!Code.empty() && (Extension.empty() || Extension == ".h")) {
   auto NonEmptyFileName = FileName.empty() ? "guess.h" : FileName;
   Environment Env(Code, NonEmptyFileName, /*Ranges=*/{});
+  if (const auto Language = getLanguageByComment(Env);
+  Language != FormatStyle::LK_None) {
+return Language;
+  }
   ObjCHeaderStyleGuesser Guesser(Env, getLLVMStyle());
   Guesser.process();
   if (Guesser.isObjC())
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 132264486100d..05febf12c17ba 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25136,6 +25136,15 @@ TEST_F(FormatTest, GuessLanguageWithChildLines) {
  

[clang] [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo as well (PR #128106)

2025-02-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nathan Ridge (HighCommander4)


Changes



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


1 Files Affected:

- (modified) clang/lib/Index/IndexTypeSourceInfo.cpp (+3-21) 


``diff
diff --git a/clang/lib/Index/IndexTypeSourceInfo.cpp 
b/clang/lib/Index/IndexTypeSourceInfo.cpp
index b986ccde57452..d5d0a3c422871 100644
--- a/clang/lib/Index/IndexTypeSourceInfo.cpp
+++ b/clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
@@ -207,27 +208,8 @@ class TypeIndexer : public 
RecursiveASTVisitor {
   }
 
   bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
-const DependentNameType *DNT = TL.getTypePtr();
-const NestedNameSpecifier *NNS = DNT->getQualifier();
-const Type *T = NNS->getAsType();
-if (!T)
-  return true;
-const TemplateSpecializationType *TST =
-T->getAs();
-if (!TST)
-  return true;
-TemplateName TN = TST->getTemplateName();
-const ClassTemplateDecl *TD =
-dyn_cast_or_null(TN.getAsTemplateDecl());
-if (!TD)
-  return true;
-CXXRecordDecl *RD = TD->getTemplatedDecl();
-if (!RD->hasDefinition())
-  return true;
-RD = RD->getDefinition();
-DeclarationName Name(DNT->getIdentifier());
-std::vector Symbols = RD->lookupDependentName(
-Name, [](const NamedDecl *ND) { return isa(ND); });
+std::vector Symbols =
+IndexCtx.getResolver()->resolveDependentNameType(TL.getTypePtr());
 if (Symbols.size() != 1)
   return true;
 return IndexCtx.handleReference(Symbols[0], TL.getNameLoc(), Parent,

``




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


[clang] [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo as well (PR #128106)

2025-02-20 Thread Nathan Ridge via cfe-commits

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


[clang] [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo as well (PR #128106)

2025-02-20 Thread Younan Zhang via cfe-commits

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


[clang] [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo as well (PR #128106)

2025-02-20 Thread Younan Zhang via cfe-commits

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

Thanks, this is a nice improvement.

not: I think it'd be better to say NFC in the PR title.

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


[clang] [clang-format] Allow specifying the language for `.h` files (PR #128122)

2025-02-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Closes #128119

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


5 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+7-1) 
- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Format/Format.h (+6-1) 
- (modified) clang/lib/Format/Format.cpp (+33) 
- (modified) clang/unittests/Format/FormatTest.cpp (+9) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bf6dd9e13915f..2d4ead76cfef2 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4782,7 +4782,13 @@ the configuration (without a prefix: ``Auto``).
 .. _Language:
 
 **Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`¶ 
`
-  Language, this format style is targeted at.
+  The language that this format style targets.
+
+  .. note::
+
+   You can also specify the language (``Cpp`` or ``ObjC``) for ``.h`` files
+   by adding a ``// clang-format Language:`` line before the first
+   non-comment and non-empty line, e.g. ``// clang-format Language: ObjC``.
 
   Possible values:
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e1c61992512b5..0e65f72623f28 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -269,6 +269,9 @@ clang-format
 - Adds ``BreakBeforeTemplateCloser`` option.
 - Adds ``BinPackLongBracedList`` option to override bin packing options in
   long (20 item or more) braced list initializer lists.
+- Allow specifying the language (C++ or Objective-C) for a ``.h`` file by 
adding
+  a special comment (e.g. ``// clang-format Language: ObjC``) near the top of
+  the file.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 16956b4e0fbd4..55709a0261b12 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3353,7 +3353,12 @@ struct FormatStyle {
   }
   bool isTableGen() const { return Language == LK_TableGen; }
 
-  /// Language, this format style is targeted at.
+  /// The language that this format style targets.
+  /// \note
+  ///  You can also specify the language (``Cpp`` or ``ObjC``) for ``.h`` files
+  ///  by adding a ``// clang-format Language:`` line before the first
+  ///  non-comment and non-empty line, e.g. ``// clang-format Language: ObjC``.
+  /// \endnote
   /// \version 3.5
   LanguageKind Language;
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 0898b69528ebc..400f39ecc5483 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -4021,6 +4021,35 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
   return FormatStyle::LK_Cpp;
 }
 
+static FormatStyle::LanguageKind getLanguageByComment(const Environment &Env) {
+  const auto ID = Env.getFileID();
+  const auto &SourceMgr = Env.getSourceManager();
+
+  LangOptions LangOpts;
+  LangOpts.CPlusPlus = 1;
+  LangOpts.LineComment = 1;
+
+  Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
+  Lex.SetCommentRetentionState(true);
+
+  for (Token Tok; !Lex.LexFromRawLexer(Tok) && Tok.is(tok::comment);) {
+auto Text = StringRef(SourceMgr.getCharacterData(Tok.getLocation()),
+  Tok.getLength());
+if (!Text.consume_front("// clang-format Language:"))
+  continue;
+
+Text = Text.trim();
+// if (Text == "C")
+//   return FormatStyle::LK_C;
+if (Text == "Cpp")
+  return FormatStyle::LK_Cpp;
+if (Text == "ObjC")
+  return FormatStyle::LK_ObjC;
+  }
+
+  return FormatStyle::LK_None;
+}
+
 FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code) {
   const auto GuessedLanguage = getLanguageByFileName(FileName);
   if (GuessedLanguage == FormatStyle::LK_Cpp) {
@@ -4030,6 +4059,10 @@ FormatStyle::LanguageKind guessLanguage(StringRef 
FileName, StringRef Code) {
 if (!Code.empty() && (Extension.empty() || Extension == ".h")) {
   auto NonEmptyFileName = FileName.empty() ? "guess.h" : FileName;
   Environment Env(Code, NonEmptyFileName, /*Ranges=*/{});
+  if (const auto Language = getLanguageByComment(Env);
+  Language != FormatStyle::LK_None) {
+return Language;
+  }
   ObjCHeaderStyleGuesser Guesser(Env, getLLVMStyle());
   Guesser.process();
   if (Guesser.isObjC())
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 132264486100d..05febf12c17ba 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25136,6 +25136,15 @@ TEST_F(FormatTest, GuessLanguageWithChildLines) {
   guessLanguage("foo.h", "#define FOO ({ foo(); ({ NSString *s; }) })"));
 }
 
+TEST_F(FormatTest, GetLanguageByComment) {
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+gue

[clang] [Clang][CodeGen] Bail out on constexpr unknown values in ConstantEmitter (PR #127525)

2025-02-20 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/127525

>From d931667e3b7e18f8ba6f054405ffc5fe2fac36b4 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 18 Feb 2025 01:26:26 +0800
Subject: [PATCH 1/3] [Clang][CodeGen] Bail out on constexpr unknown values in
 ConstantEmitter

---
 clang/lib/CodeGen/CGExprConstant.cpp|  6 --
 clang/test/CodeGenCXX/cxx23-p2280r4.cpp | 13 +
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/cxx23-p2280r4.cpp

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index ee5874b26f534..075f3f435ad74 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1883,8 +1883,10 @@ llvm::Constant 
*ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) {
 
   // Try to emit the initializer.  Note that this can allow some things that
   // are not allowed by tryEmitPrivateForMemory alone.
-  if (APValue *value = D.evaluateValue())
-return tryEmitPrivateForMemory(*value, destType);
+  if (APValue *value = D.evaluateValue()) {
+if (!value->allowConstexprUnknown())
+  return tryEmitPrivateForMemory(*value, destType);
+  }
 
   return nullptr;
 }
diff --git a/clang/test/CodeGenCXX/cxx23-p2280r4.cpp 
b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp
new file mode 100644
index 0..bb9a90ba18ece
--- /dev/null
+++ b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++23 %s -emit-llvm -o - | 
FileCheck %s
+
+extern int& s;
+
+// CHECK: @_Z4testv()
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[I:%.*]] = alloca ptr, align {{.*}}
+// CHECK-NEXT: [[X:%.*]] = load ptr, ptr @s, align {{.*}}
+// CHECK-NEXT: store ptr [[X]], ptr [[I]], align {{.*}}
+int& test() {
+  auto &i = s;
+  return i;
+}

>From 9eb4a88e25f2d9a7e8799955a7b45abeb1808b39 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 18 Feb 2025 19:20:39 +0800
Subject: [PATCH 2/3] Address review comments. NFC.

---
 clang/test/CodeGenCXX/cxx23-p2280r4.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/CodeGenCXX/cxx23-p2280r4.cpp 
b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp
index bb9a90ba18ece..d5409be451df0 100644
--- a/clang/test/CodeGenCXX/cxx23-p2280r4.cpp
+++ b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++23 %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++17 %s -emit-llvm -o - | 
FileCheck %s
 
 extern int& s;
 

>From 269f93fa37dc054c1670c8d2d6b60ca48cf07e93 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Fri, 21 Feb 2025 12:15:29 +0800
Subject: [PATCH 3/3] [Clang][CodeGen] Address review comments. NFC.

---
 clang/lib/CodeGen/CGExprConstant.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 075f3f435ad74..7d44a9f583eca 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1883,10 +1883,10 @@ llvm::Constant 
*ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) {
 
   // Try to emit the initializer.  Note that this can allow some things that
   // are not allowed by tryEmitPrivateForMemory alone.
-  if (APValue *value = D.evaluateValue()) {
-if (!value->allowConstexprUnknown())
-  return tryEmitPrivateForMemory(*value, destType);
-  }
+  // Bail out on constexpr-unknown values since they are invalid in CodeGen.
+  if (APValue *value = D.evaluateValue();
+  value && !value->allowConstexprUnknown())
+return tryEmitPrivateForMemory(*value, destType);
 
   return nullptr;
 }

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


[clang] Add clang atomic control options and attribute (PR #114841)

2025-02-20 Thread Yaxun Liu via cfe-commits


@@ -5400,6 +5400,151 @@ third argument, can only occur at file scope.
 a = b[i] * c[i] + e;
   }
 
+Extensions for controlling atomic code generation
+=
+
+The ``[[clang::atomic]]`` statement attribute enables users to control how
+atomic operations are lowered in LLVM IR by conveying additional metadata to
+the backend. The primary goal is to allow users to specify certain options,
+like whether atomic operations may be performed on specific types of memory or
+whether to ignore denormal mode correctness in floating-point operations,
+without affecting the correctness of code that does not rely on these 
behaviors.
+
+In LLVM, lowering of atomic operations (e.g., ``atomicrmw``) can differ based
+on the target's capabilities. Some backends support native atomic instructions
+only for certain operation types or alignments, or only in specific memory
+regions. Likewise, floating-point atomic instructions may or may not respect
+IEEE denormal requirements. When the user is unconcerned about denormal-mode
+compliance (for performance reasons) or knows that certain atomic operations
+will not be performed on a particular type of memory, extra hints are needed to
+tell the backend how to proceed.
+
+A classic example is an architecture where floating-point atomic add does not
+fully conform to IEEE denormal-mode handling. If the user does not mind 
ignoring
+that aspect, they would prefer to still emit a faster hardware atomic 
instruction,
+rather than a fallback or CAS loop. Conversely, on certain GPUs (e.g., AMDGPU),
+memory accessed via PCIe may only support a subset of atomic operations. To 
ensure
+correct and efficient lowering, the compiler must know whether the user wants 
to
+allow atomic operations on that type of memory.
+
+The allowed atomic attribute values are now ``remote_memory``, 
``fine_grained_memory``,
+and ``ignore_denormal_mode``, each optionally prefixed with ``no_``. The 
meanings
+are as follows:
+ 
+- ``remote_memory`` means atomic operations may be performed on remote memory.
+  Prefixing with ``no_`` (i.e. ``no_remote_memory``) indicates that atomic
+  operations should not be performed on remote memory.
+- ``fine_grained_memory`` means atomic operations may be performed on 
fine-grained
+  memory. Prefixing with ``no_`` (i.e. ``no_fine_grained_memory``) indicates 
that
+  atomic operations should not be performed on fine-grained memory.
+- ``ignore_denormal_mode`` means that atomic operations are allowed to ignore
+  correctness for denormal mode in floating-point operations, potentially 
improving
+  performance on architectures that handle denormals inefficiently. The 
negated form,
+  if specified as ``no_ignore_denormal_mode``, would enforce strict denormal 
mode
+  correctness.
+
+Without any atomic metadata, LLVM IR defaults to conservative settings for
+correctness: atomic operations are assumed to use remote memory, fine-grained
+memory, and enforce denormal mode correctness (i.e. the equivalent of
+``remote_memory``, ``fine_grained_memory``, and ``no_ignore_denormal_mode``).
+
+The attribute may be applied only to a compound statement and looks like:
+
+.. code-block:: c++
+
+   [[clang::atomic(remote_memory, fine_grained_memory, ignore_denormal_mode)]]
+   {
+   // Atomic instructions in this block carry extra metadata reflecting
+   // these user-specified options.
+   }
+
+You can provide one or more of these options, each optionally prefixed with

yxsamliu wrote:

Within the same atomic attribute, duplicate and conflict values are accepted 
and the
last value of conflicting values wins. Multiple atomic attributes are allowed
for the same compound statement and the last atomic attribute wins.

will document these and add lit tests.

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


[clang] [clang][Index] Use HeuristicResolver in IndexTypeSourceInfo as well (PR #128106)

2025-02-20 Thread Younan Zhang via cfe-commits

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


[clang] [HLSL][Sema] Fix Struct Size Calculation containing 16/32 bit scalars (PR #128086)

2025-02-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Ashley Coleman (V-FEXrt)


Changes

Fixes #119641

Update SemaHLSL to correctly calculate the alignment barrier for scalars that 
are not 4 bytes wide

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaHLSL.cpp (+22-5) 
- (added) clang/test/CodeGenHLSL/cbuffer_align.hlsl (+60) 


``diff
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index d26d85d5861b1..cccfd4aec7eb2 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -172,6 +172,27 @@ Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool 
CBuffer,
   return Result;
 }
 
+static unsigned calculateLegacyCbufferFieldAlign(const ASTContext &Context,
+ QualType T) {
+  // Aggregate types are always aligned to new buffer rows
+  if (T->isAggregateType())
+return 16;
+
+  assert(Context.getTypeSize(T) <= 64 &&
+ "Scalar bit widths larger than 64 not supported");
+
+  // 64 bit types such as double and uint64_t align to 8 bytes
+  if (Context.getTypeSize(T) == 64)
+return 8;
+
+  // Half types align to 2 bytes only if native half is available
+  if (T->isHalfType() && Context.getLangOpts().NativeHalfType)
+return 2;
+
+  // Everything else aligns to 4 bytes
+  return 4;
+}
+
 // Calculate the size of a legacy cbuffer type in bytes based on
 // 
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-packing-rules
 static unsigned calculateLegacyCbufferSize(const ASTContext &Context,
@@ -183,11 +204,7 @@ static unsigned calculateLegacyCbufferSize(const 
ASTContext &Context,
 for (const FieldDecl *Field : RD->fields()) {
   QualType Ty = Field->getType();
   unsigned FieldSize = calculateLegacyCbufferSize(Context, Ty);
-  // FIXME: This is not the correct alignment, it does not work for 16-bit
-  // types. See llvm/llvm-project#119641.
-  unsigned FieldAlign = 4;
-  if (Ty->isAggregateType())
-FieldAlign = CBufferAlign;
+  unsigned FieldAlign = calculateLegacyCbufferFieldAlign(Context, Ty);
   Size = llvm::alignTo(Size, FieldAlign);
   Size += FieldSize;
 }
diff --git a/clang/test/CodeGenHLSL/cbuffer_align.hlsl 
b/clang/test/CodeGenHLSL/cbuffer_align.hlsl
new file mode 100644
index 0..31db2e0726020
--- /dev/null
+++ b/clang/test/CodeGenHLSL/cbuffer_align.hlsl
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s 
--check-prefix=CHECK-HALF
+
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s 
--check-prefix=CHECK-FLOAT
+
+
+struct S1 {
+  half a;   // 2 bytes + 2 bytes pad or 4 bytes
+  float b;  // 4 bytes
+  half c;   // 2 bytes + 2 bytes pad or 4 bytes
+  float d;  // 4 bytes
+  double e; // 8 bytes
+};
+
+struct S2 {
+  half a;   // 2 bytes or 4 bytes
+  half b;   // 2 bytes or 4 bytes
+  float e;  // 4 bytes or 4 bytes + 4 padding
+  double f; // 8 bytes
+};
+
+struct S3 {
+  half a; // 2 bytes + 6 bytes pad or 4 bytes + 4 bytes pad
+  uint64_t b; // 8 bytes
+};
+
+struct S4 {
+  float a;  // 4 bytes
+  half b;   // 2 bytes or 4 bytes
+  half c;   // 2 bytes or 4 bytes + 4 bytes pad
+  double d; // 8 bytes
+};
+
+
+cbuffer CB0 {
+  // CHECK-HALF: @CB0.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB0, 24, 0))
+  // CHECK-FLOAT: @CB0.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB0, 24, 0))
+  S1 s1;
+}
+
+cbuffer CB1 {
+  // CHECK-HALF: @CB1.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB1, 16, 0))
+  // CHECK-FLOAT: @CB1.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB1, 24, 0))
+  S2 s2;
+}
+
+cbuffer CB2 {
+  // CHECK-HALF: @CB2.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB2, 16, 0))
+  // CHECK-FLOAT: @CB2.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB2, 16, 0))
+  S3 s3;
+}
+
+cbuffer CB3 {
+  // CHECK-HALF: @CB3.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB3, 16, 0))
+  // CHECK-FLOAT: @CB3.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB3, 24, 0))
+  S4 s4;
+}

``




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


[clang] [llvm] [Coroutines] Mark parameter allocas with coro.outside.frame metadata (PR #127653)

2025-02-20 Thread Reid Kleckner via cfe-commits

https://github.com/rnk commented:

In the issue (#127499) you pointed out that this issue applies to the MSVC ABI 
where all parameters are destroyed in the callee. Is it reasonable to construct 
the analogous test case in that environment? I tried to do this locally, but 
can't for unrelated build configuration reasons.

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


  1   2   3   4   5   >