[clang] [analyzer] Teach analzer about ms __analyzer_assume(bool) and friends (PR #80456)

2024-02-03 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/80456

>From 9065aec18b5b9c4d922b0650e709e71ed31b5a45 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Fri, 2 Feb 2024 16:24:21 +0100
Subject: [PATCH 1/2] [analyzer] Teach analzer about ms __analyzer_assume(bool)
 and friends

See the MS docs:
https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/using-the--analysis-assume-function-to-suppress-false-defects
https://learn.microsoft.com/en-us/cpp/code-quality/how-to-specify-additional-code-information-by-using-analysis-assume

TBH, I don't really know what is the difference between the two APIs.
---
 .../Checkers/BuiltinFunctionChecker.cpp   | 57 +--
 clang/test/Analysis/builtin-functions.cpp | 22 +++
 2 files changed, 62 insertions(+), 17 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index 61521c259ca90..ea874c1529b3b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -14,6 +14,7 @@
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
@@ -26,10 +27,41 @@ namespace {
 class BuiltinFunctionChecker : public Checker {
 public:
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+
+private:
+  const CallDescriptionSet MicrosoftAnalysisAssume{
+  {{"__analysis_assume"}, 1},
+  {{"_Analysis_assume_"}, 1},
+  };
+
+  void evalCallAssume(const CallEvent &Call, CheckerContext &C) const;
 };
 
 }
 
+void BuiltinFunctionChecker::evalCallAssume(const CallEvent &Call,
+CheckerContext &C) const {
+  assert(Call.getNumArgs() > 0);
+  assert(Call.getResultType()->isVoidType());
+  SVal Arg = Call.getArgSVal(0);
+
+  if (Arg.isUndef())
+return; // Return true to model purity.
+
+  ProgramStateRef State = C.getState();
+  State = State->assume(Arg.castAs(), true);
+
+  // FIXME: do we want to warn here? Not right now. The most reports might
+  // come from infeasible paths, thus being false positives.
+  if (!State) {
+C.generateSink(C.getState(), C.getPredecessor());
+return;
+  }
+
+  C.addTransition(State);
+  return;
+}
+
 bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
   CheckerContext &C) const {
   ProgramStateRef state = C.getState();
@@ -39,29 +71,20 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
 
   const LocationContext *LCtx = C.getLocationContext();
   const Expr *CE = Call.getOriginExpr();
+  bool ReturnsVoid = Call.getResultType()->isVoidType();
+
+  if (MicrosoftAnalysisAssume.contains(Call) && ReturnsVoid) {
+evalCallAssume(Call, C);
+return true;
+  }
 
   switch (FD->getBuiltinID()) {
   default:
 return false;
 
-  case Builtin::BI__builtin_assume: {
-assert (Call.getNumArgs() > 0);
-SVal Arg = Call.getArgSVal(0);
-if (Arg.isUndef())
-  return true; // Return true to model purity.
-
-state = state->assume(Arg.castAs(), true);
-// FIXME: do we want to warn here? Not right now. The most reports might
-// come from infeasible paths, thus being false positives.
-if (!state) {
-  C.generateSink(C.getState(), C.getPredecessor());
-  return true;
-}
-
-C.addTransition(state);
+  case Builtin::BI__builtin_assume:
+evalCallAssume(Call, C);
 return true;
-  }
-
   case Builtin::BI__builtin_unpredictable:
   case Builtin::BI__builtin_expect:
   case Builtin::BI__builtin_expect_with_probability:
diff --git a/clang/test/Analysis/builtin-functions.cpp 
b/clang/test/Analysis/builtin-functions.cpp
index 37e522049b174..4a26f82ffcb16 100644
--- a/clang/test/Analysis/builtin-functions.cpp
+++ b/clang/test/Analysis/builtin-functions.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
 
+void __analysis_assume(bool);
+void _Analysis_assume_(bool);
 void clang_analyzer_eval(bool);
 void clang_analyzer_warnIfReached();
 
@@ -82,3 +84,23 @@ void test_constant_p(void *ptr) {
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(ptr == 0)); // expected-warning 
{{FALSE}}
 }
+
+void test_ms_analysis_assume(int *p) {
+  __analysis_assume(p);
+  if (!p) {
+clang_analyzer_warnIfReached(); // no-warning: dead code.
+  }
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  __analysis_as

[clang] [analyzer] Teach analzer about ms __analyzer_assume(bool) and friends (PR #80456)

2024-02-03 Thread Balazs Benics via cfe-commits

steakhal wrote:

> The code LGTM with some minor remarks. (Disclaimer: I'm not familiar with 
> these MS functions.)
> 
> I'm not sure whether these "builtin by Microsoft" functions are in scope for 
> "our" BuiltinFunctionChecker which previously only checked functions that are 
> recognized as `Builtin::BI__something` by Clang. (However, I can believe that 
> there is no better place for them and I don't think that they would cause 
> problems here.)

For me, this file would be where I would look to see how `__assume` is eval 
called. This is actually an unknown function in regular mode, but with 
`-fms-extensions` it's actually defined. Check the AST for this 
[example](https://godbolt.org/z/1xdbP8scx). So, techniquely, it's not a 
builtin, but feels like it.

About the remarks, yes, let's do [Clean As You 
Code](https://docs.sonarsource.com/sonarqube/latest/user-guide/clean-as-you-code/#what-is-clean-as-you-code)!
 I'm all in.


> Hey!
> 
> Thanks for looking into this!
> 
> Did you actually encounter this call in the wild? The reason I ask, because 
> their definition looks like this in the current version of `sal.h`:
> 
> ```
> #ifndef __analysis_assume // [
> #ifdef _PREFAST_ // [
> #define __analysis_assume(expr) __assume(expr)
> #else // ][
> #define __analysis_assume(expr)
> #endif // ]
> #endif // ]
> 
> #ifndef _Analysis_assume_ // [
> #ifdef _PREFAST_ // [
> #define _Analysis_assume_(expr) __assume(expr)
> #else // ][
> #define _Analysis_assume_(expr)
> #endif // ]
> #endif // ]
> ```
> 
> The basic idea is, when MSVC's analyzer is invoked, `_PREFAST_` is defined, 
> and these macros should expand to `__assume(expr)`. This makes me a bit 
> surprised if the original names are present in the preprocessed code.
> 
> There is no difference between `__analysis_assume` and `_Analysis_assume_`. 
> The former is following the naming conventions in SAL 1, the latter is 
> following the conventions of SAL 2. The latter is preferred in user code, but 
> MSVC still supports both spellings.

I think I've seen FPs on ChakraCore and on the DotnetRuntime and on other 
Windows-related projects defining some of their assert macros by wrapping 
`__analysis_assume`. I can't exactly recall ATM where exactly I've seen that, 
but I'll do a measurment to confirm that this PR actually improves the 
situation.

Anyways, it turns out the FP I wanted to fix actually expands into using 
`__builtin_trap()`, which is still not modeled in CSA :face_with_spiral_eyes: 
I'll create a separate PR for handling that.

I think this PR stands on it's own, and improves the situation - (I'll check 
and come back of course).
I hope `__assume()` takes a single parameter (of any type) and returns `void` 
though.

Sorry for not doing my homework in the beginning, and thanks for catching that!
I though it's gonna be an easy one and I fire off a PR on my tea-break.

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


[clang] 141de74 - [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (#80395)

2024-02-03 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-02-03T16:14:48+08:00
New Revision: 141de749597c7b59ebe2c4aa7ee573d124dc903c

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

LOG: [clang][Sema] Populate function template depth at 
AddTemplateOverloadCandidate (#80395)

This is yet another one-line patch to fix crashes on constraint
substitution.

```cpp
template  struct formatter;

template  struct basic_format_context {};

template 
concept has_format_function = format(basic_format_context());

template 
  requires has_format_function
struct formatter {
  template 
  CharType format(basic_format_context);
};
```

In this case, we would build up a `RecoveryExpr` for a call within a
constraint expression due to the absence of viable functions. The
heuristic algorithm attempted to find such a function inside of a
ClassTemplatePartialSpecialization, from which we started to substitute
its requires-expression, and it succeeded with a FunctionTemplate such
that

1) It has only one parameter, which is dependent.
2) The only one parameter depends on two template parameters. They are,
in canonical form, `` and
`` respectively.

Before we emit an error, we still want to recover the most viable
functions. This goes downhill to deducing template parameters against
its arguments, where we would collect the argument type with the same
depth as the parameter type into a Deduced set. The size of the set is
presumed to be that of function template parameters, which is 1 in this
case. However, since we haven't yet properly set the template depth
before the dance, we'll end up putting the type for
`` to the second position of Deduced set, which
is unfortunately an access violation!

The bug seems to appear since clang 12.0.

This fixes [the
case](https://github.com/llvm/llvm-project/issues/58548#issuecomment-1287935336).

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaTemplate/concepts-recovery-expr.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ed1dff17f397..e634db3c718c9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -190,6 +190,9 @@ Bug Fixes to C++ Support
 - Fix for crash when using a erroneous type in a return statement.
   Fixes (`#63244 `_)
   and (`#79745 `_)
+- Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
+  function calls while substituting into constraints.
+  (`#58548 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 940bcccb9e261..6a04d68b4f041 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7623,7 +7623,8 @@ void Sema::AddTemplateOverloadCandidate(
   //   functions. In such a case, the candidate functions generated from each
   //   function template are combined with the set of non-template candidate
   //   functions.
-  TemplateDeductionInfo Info(CandidateSet.getLocation());
+  TemplateDeductionInfo Info(CandidateSet.getLocation(),
+ FunctionTemplate->getTemplateDepth());
   FunctionDecl *Specialization = nullptr;
   ConversionSequenceList Conversions;
   if (TemplateDeductionResult Result = DeduceTemplateArguments(

diff  --git a/clang/test/SemaTemplate/concepts-recovery-expr.cpp 
b/clang/test/SemaTemplate/concepts-recovery-expr.cpp
index 2f9d432ebac0e..b338f3bc271bf 100644
--- a/clang/test/SemaTemplate/concepts-recovery-expr.cpp
+++ b/clang/test/SemaTemplate/concepts-recovery-expr.cpp
@@ -180,3 +180,30 @@ void StaticMemOVCUse() {
   // expected-note@#SMEMOVC3 {{candidate template ignored: constraints not 
satisfied}}
   // expected-note@#SMEMOVC3REQ{{because substituted constraint expression is 
ill-formed: constraint depends on a previously diagnosed expression}}
 }
+
+namespace GH58548 {
+
+template  struct formatter; // #primary-template
+template  struct basic_format_context {};
+
+template 
+concept has_format_function =
+format(basic_format_context());
+
+template 
+  requires has_format_function
+struct formatter {
+  template 
+  CharType format(basic_format_context);
+};
+
+template  int handle_replacement_field(Ctx arg) {
+  formatter ctx; // expected-error {{implicit 
instantiation of undefined template}}
+  return 0;
+}
+
+int x = handle_replacement_field(0);
+// 

[clang-tools-extra] [clang] [flang] [llvm] [libc] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

2024-02-03 Thread Younan Zhang via cfe-commits

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


[clang] [X86] [iamcu] Fix wrong alignment value for attr (aligned) with -miamcu (PR #80401)

2024-02-03 Thread via cfe-commits

hstk30-hw wrote:

LGTM :)

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


[clang] 7278cb5 - [X86] [iamcu] Fix wrong alignment value for attr (aligned) with -miamcu (#80401)

2024-02-03 Thread via cfe-commits

Author: joyhou-hw
Date: 2024-02-03T16:49:47+08:00
New Revision: 7278cb5a388e0f2f4000dc8d6b3b421de66a945b

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

LOG: [X86] [iamcu] Fix wrong alignment value for attr (aligned) with -miamcu 
(#80401)

attribute ((aligned)) should be 4 for -miamcu.

relate: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66818

Added: 


Modified: 
clang/lib/Basic/Targets/X86.h
clang/test/Sema/attr-aligned.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 1845f5a747af4..0026d8781c8fa 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -672,6 +672,7 @@ class LLVM_LIBRARY_VISIBILITY MCUX86_32TargetInfo : public 
X86_32TargetInfo {
   MCUX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : X86_32TargetInfo(Triple, Opts) {
 LongDoubleWidth = 64;
+DefaultAlignForAttributeAligned = 32;
 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
 resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:32-"
 "f64:32-f128:32-n8:16:32-a:0:32-S32");

diff  --git a/clang/test/Sema/attr-aligned.c b/clang/test/Sema/attr-aligned.c
index 130840d46650d..97edfe6ac1644 100644
--- a/clang/test/Sema/attr-aligned.c
+++ b/clang/test/Sema/attr-aligned.c
@@ -1,10 +1,9 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple i586-intel-elfiamcu -fsyntax-only -verify %s
 
 int x __attribute__((aligned(3))); // expected-error {{requested alignment is 
not a power of 2}}
 int y __attribute__((aligned(1ull << 33))); // expected-error {{requested 
alignment must be 4294967296 bytes or smaller}}
 int y __attribute__((aligned(1ull << 32)));
-// GH50534
-int z __attribute__((aligned((__int128_t)0x1234567890abcde0ULL << 64))); // 
expected-error {{requested alignment must be 4294967296 bytes or smaller}}
 
 // PR26444
 int y __attribute__((aligned(1 << 29)));
@@ -12,8 +11,15 @@ int y __attribute__((aligned(1 << 28)));
 
 // PR3254
 short g0[3] __attribute__((aligned));
+#ifdef __iamcu
+short g0_chk[__alignof__(g0) == 4 ? 1 : -1];
+#else
 short g0_chk[__alignof__(g0) == 16 ? 1 : -1];
 
+// GH50534
+int z __attribute__((aligned((__int128_t)0x1234567890abcde0ULL << 64))); // 
expected-error {{requested alignment must be 4294967296 bytes or smaller}}
+#endif
+
 typedef char ueber_aligned_char __attribute__((aligned(8)));
 
 struct struct_with_ueber_char {



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


[clang] [X86] [iamcu] Fix wrong alignment value for attr (aligned) with -miamcu (PR #80401)

2024-02-03 Thread via cfe-commits

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


[llvm] [clang] [flang] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)

2024-02-03 Thread Nikita Popov via cfe-commits

nikic wrote:

@Artem-B Thanks for the report. SROA already has a bunch of special handling 
for `load(c ? p1 : p2)` as well as `load(gep(c ? p1 : p2, idx))`, so it's 
probably not too hard to also support `load(gep(p, c ? idx1 : idx2))`.

In your particular case, it seems like it's actually InstCombine itself that 
converts `load(c ? p1 : p2)` into `c ? load(p1) : load(p2)` in 
https://github.com/llvm/llvm-project/blob/141de749597c7b59ebe2c4aa7ee573d124dc903c/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp#L1068-L1087.
 So supporting additional patterns there might be a possible alternative. But I 
think we should try making SROA more powerful first.

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


[clang] [clang][CodeGen][UBSan] Fixing shift-exponent generation for _BitInt (PR #80515)

2024-02-03 Thread Björn Pettersson via cfe-commits

bjope wrote:

Make sure the commit message refers to fixing #80135.

(Github is a bit weird, so if you want to use the "squash an merge" support in 
the web UI later, then I think you need to update the first comment in the 
"Conversation", rather than updating the commits on this pull-request branch.)

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


[clang] [RISCV][clang] Add Zvfbfmin C intrinsics support (PR #79618)

2024-02-03 Thread Brandon Wu via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix warnings caused by "new check" template (PR #80537)

2024-02-03 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny created 
https://github.com/llvm/llvm-project/pull/80537

None

From 3ba9198670311c38fa145ef0af57edd60120568a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sat, 3 Feb 2024 11:31:51 +0100
Subject: [PATCH 1/2] [clang-tidy] Replace deprecated method in template

---
 clang-tools-extra/clang-tidy/add_new_check.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index ada2ee1119cf9..eecff6082f3d6 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -146,7 +146,7 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 void %(check_name)s::check(const MatchFinder::MatchResult &Result) {
   // FIXME: Add callback implementation.
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
-  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().startswith("awesome_"))
+  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().starts_with("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl

From 4b487beaef9965973c82092600eade9c57f00448 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sat, 3 Feb 2024 11:32:09 +0100
Subject: [PATCH 2/2] [clang-tidy] Omit (yet) unused include

---
 clang-tools-extra/clang-tidy/add_new_check.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index eecff6082f3d6..a6af76809af02 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -131,7 +131,6 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 
//===--===//
 
 #include "%(check_name)s.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
 using namespace clang::ast_matchers;

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


[clang-tools-extra] [clang-tidy] Fix warnings caused by "new check" template (PR #80537)

2024-02-03 Thread via cfe-commits
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:



@llvm/pr-subscribers-clang-tidy

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

Author: Danny Mösch (SimplyDanny)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/add_new_check.py (+1-2) 


``diff
diff --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index ada2ee1119cf9..a6af76809af02 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -131,7 +131,6 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 
//===--===//
 
 #include "%(check_name)s.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
 using namespace clang::ast_matchers;
@@ -146,7 +145,7 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 void %(check_name)s::check(const MatchFinder::MatchResult &Result) {
   // FIXME: Add callback implementation.
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
-  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().startswith("awesome_"))
+  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().starts_with("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl

``




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


[clang] [clang][CodeGen][UBSan] Fixing shift-exponent generation for _BitInt (PR #80515)

2024-02-03 Thread Björn Pettersson via cfe-commits


@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 %s -O0 -fsanitize=shift-exponent -emit-llvm -o - | 
FileCheck %s

bjope wrote:

I think you for example want to use `-std=c2x -triple=x86_64-unknown-linux` 
here.
(Not sure exactly if you for example need the triple, but I fear that you would 
end up with failing build bots otherwise as not all targets support C23 _BitInt 
literals by default.)

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


[clang] [clang][CodeGen][UBSan] Fixing shift-exponent generation for _BitInt (PR #80515)

2024-02-03 Thread Björn Pettersson via cfe-commits


@@ -4121,6 +4121,13 @@ Value *ScalarExprEmitter::GetWidthMinusOneValue(Value* 
LHS,Value* RHS) {
 Ty = cast(VT->getElementType());
   else
 Ty = cast(LHS->getType());
+  // Testing with small _BitInt types has shown that Ty->getBitwidth() - 1

bjope wrote:

Prefer if the code comment just help describe what it is doing, and possibly 
why here.
IMO, the "Testing with small _BitInt types has shown..." part is not really 
that interesting as a code comment.

One idea is to rename the `GetWidthMinusOneValue` helper function as we 
slightly change what it does.
It's more like a GetMaximumShiftAmount kind of helper. And there should be an 
update function description that describe a bit more about what is going on. 
I'm not sure why this static function is declared inside ScalarExprEmitter but 
the current description is far away at line 776.

It could say something like this:
Get a maximum legal shift exponent given a shift operation shifting the value 
LHS by RHS steps. The result type is given by RHS. The scalar bit width of the 
LHS value gives an upper bound on the shift exponent as it is considered 
illegal to shift more steps than "width minus one". If that value does not fit 
in the result type, then return an unsinged max for the result type.

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


[clang] [clang][CodeGen][UBSan] Fixing shift-exponent generation for _BitInt (PR #80515)

2024-02-03 Thread Björn Pettersson via cfe-commits


@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 %s -O0 -fsanitize=shift-exponent -emit-llvm -o - | 
FileCheck %s
+
+// Checking that the code generation is using the unextended/untruncated
+// exponent values and capping the values accordingly
+
+// CHECK-LABEL: define{{.*}} i32 @test_left_variable
+int test_left_variable(unsigned _BitInt(5) b, unsigned _BitInt(2) e) {
+  // CHECK: [[E_REG:%.+]] = load [[E_SIZE:i2]]
+  // CHECK: icmp ule [[E_SIZE]] [[E_REG]], -1

bjope wrote:

So this test case show something that we perhaps should follow up an optimize 
later.
Not sure if the idea is to make the frontend simple at let the middle end 
optimize it away, but it is a bit stupid to emit the check here when comparing 
with -1.

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


[clang-tools-extra] [clang-tidy] Fix warnings caused by "new check" template (PR #80537)

2024-02-03 Thread Congcong Cai via cfe-commits
Danny =?utf-8?q?M=C3=B6sch?= 
Message-ID:
In-Reply-To: 


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


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


[clang-tools-extra] 514d069 - [clang-tidy] Fix warnings caused by "new check" template (#80537)

2024-02-03 Thread via cfe-commits

Author: Danny Mösch
Date: 2024-02-03T13:49:54+01:00
New Revision: 514d0691f4da40d5bb6d618a673e975b8eacfb77

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

LOG: [clang-tidy] Fix warnings caused by "new check" template (#80537)

Added: 


Modified: 
clang-tools-extra/clang-tidy/add_new_check.py

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index ada2ee1119cf9..a6af76809af02 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -131,7 +131,6 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 
//===--===//
 
 #include "%(check_name)s.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
 using namespace clang::ast_matchers;
@@ -146,7 +145,7 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 void %(check_name)s::check(const MatchFinder::MatchResult &Result) {
   // FIXME: Add callback implementation.
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
-  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().startswith("awesome_"))
+  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().starts_with("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl



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


[clang-tools-extra] [clang-tidy] Fix warnings caused by "new check" template (PR #80537)

2024-02-03 Thread Danny Mösch via cfe-commits

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


[llvm] [clang] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-02-03 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/80540

This patch allows using the name "rdma" as an alias for "rdm". The name makes 
its way to target attributes as well as the command line via the -march and 
-mcpu options. The motivation was originally to support this in Function Multi 
Versioning but it also makes sense to align with GCC on the command line.

>From 0804c8c74d940a49c6a21722b136d0b090458242 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Tue, 30 Jan 2024 11:17:55 +
Subject: [PATCH] [TargetParser][AArch64] Add alias for FEAT_RDM.

This patch allows using the name "rdma" as an alias for "rdm".
The name makes its way to target attributes as well as the
command line via the -march and -mcpu options. The motivation
was originally to support this in Function Multi Versioning
but it also makes sense to align with GCC on the command line.
---
 clang/docs/ReleaseNotes.rst   |  6 ++
 clang/test/CodeGen/attr-target-version.c  |  6 +++---
 clang/test/Driver/aarch64-rdm.c   |  3 +++
 clang/test/Sema/attr-target-clones-aarch64.c  |  2 +-
 clang/test/SemaCXX/attr-target-version.cpp|  1 +
 .../llvm/TargetParser/AArch64TargetParser.h   | 13 -
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 15 +--
 7 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..5d525b74c056d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -222,6 +222,12 @@ X86 Support
 Arm and AArch64 Support
 ^^^
 
+- An alias identifier (rdma) has been added for targeting the AArch64
+  Architecture Extension which uses Rounding Doubling Multiply Accumulate
+  instructions (rdm). The identifier is available on the command line as
+  a feature modifier for -march and -mcpu as well as via target attributes
+  like ``target_version`` or ``target_clones``.
+
 Android Support
 ^^^
 
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 2a96697e4291b..2ad6f3a5b0c44 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -39,7 +39,7 @@ inline int 
__attribute__((target_version("memtag3+rcpc3+mops"))) fmv_inline(void
 inline int __attribute__((target_version("aes+dotprod"))) fmv_inline(void) { 
return 13; }
 inline int __attribute__((target_version("simd+fp16fml"))) fmv_inline(void) { 
return 14; }
 inline int __attribute__((target_version("fp+sm4"))) fmv_inline(void) { return 
15; }
-inline int __attribute__((target_version("lse+rdm"))) fmv_inline(void) { 
return 16; }
+inline int __attribute__((target_version("lse+rdma"))) fmv_inline(void) { 
return 16; }
 inline int __attribute__((target_version("default"))) fmv_inline(void) { 
return 3; }
 
 __attribute__((target_version("ls64"))) int fmv_e(void);
@@ -385,7 +385,7 @@ int hoo(void) {
 // CHECK-NEXT:[[TMP59:%.*]] = and i1 true, [[TMP58]]
 // CHECK-NEXT:br i1 [[TMP59]], label [[RESOLVER_RETURN27:%.*]], label 
[[RESOLVER_ELSE28:%.*]]
 // CHECK:   resolver_return27:
-// CHECK-NEXT:ret ptr @fmv_inline._MlseMrdm
+// CHECK-NEXT:ret ptr @fmv_inline._MlseMrdma
 // CHECK:   resolver_else28:
 // CHECK-NEXT:[[TMP60:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
 // CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 32
@@ -673,7 +673,7 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdm
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdma
 // CHECK-SAME: () #[[ATTR25:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 16
diff --git a/clang/test/Driver/aarch64-rdm.c b/clang/test/Driver/aarch64-rdm.c
index f2542b381e7c2..62e1a4def4ce1 100644
--- a/clang/test/Driver/aarch64-rdm.c
+++ b/clang/test/Driver/aarch64-rdm.c
@@ -1,13 +1,16 @@
 // RUN: %clang --target=aarch64-none-elf -march=armv8a+rdm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
+// RUN: %clang --target=aarch64-none-elf -march=armv8a+rdma -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=generic+rdm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=falkor -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=thunderx2t99 -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // CHECK-RDM: "-target-feature" "+rdm"
 
 // RUN: %clang --target=aarch64-none-elf -march=armv8a+nordm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-NORDM %s
+// RUN: %clang --target=aarch64-none-elf -march=armv8a+nordma -### -c %s 2>&1 
| FileCheck --check-prefix=CHECK-NORDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=generic+nordm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-NORDM %s

[clang] [llvm] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-02-03 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Alexandros Lamprineas (labrinea)


Changes

This patch allows using the name "rdma" as an alias for "rdm". The name makes 
its way to target attributes as well as the command line via the -march and 
-mcpu options. The motivation was originally to support this in Function Multi 
Versioning but it also makes sense to align with GCC on the command line.

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


7 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+6) 
- (modified) clang/test/CodeGen/attr-target-version.c (+3-3) 
- (modified) clang/test/Driver/aarch64-rdm.c (+3) 
- (modified) clang/test/Sema/attr-target-clones-aarch64.c (+1-1) 
- (modified) clang/test/SemaCXX/attr-target-version.cpp (+1) 
- (modified) llvm/include/llvm/TargetParser/AArch64TargetParser.h (+8-5) 
- (modified) llvm/lib/TargetParser/AArch64TargetParser.cpp (+13-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..5d525b74c056d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -222,6 +222,12 @@ X86 Support
 Arm and AArch64 Support
 ^^^
 
+- An alias identifier (rdma) has been added for targeting the AArch64
+  Architecture Extension which uses Rounding Doubling Multiply Accumulate
+  instructions (rdm). The identifier is available on the command line as
+  a feature modifier for -march and -mcpu as well as via target attributes
+  like ``target_version`` or ``target_clones``.
+
 Android Support
 ^^^
 
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 2a96697e4291b..2ad6f3a5b0c44 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -39,7 +39,7 @@ inline int 
__attribute__((target_version("memtag3+rcpc3+mops"))) fmv_inline(void
 inline int __attribute__((target_version("aes+dotprod"))) fmv_inline(void) { 
return 13; }
 inline int __attribute__((target_version("simd+fp16fml"))) fmv_inline(void) { 
return 14; }
 inline int __attribute__((target_version("fp+sm4"))) fmv_inline(void) { return 
15; }
-inline int __attribute__((target_version("lse+rdm"))) fmv_inline(void) { 
return 16; }
+inline int __attribute__((target_version("lse+rdma"))) fmv_inline(void) { 
return 16; }
 inline int __attribute__((target_version("default"))) fmv_inline(void) { 
return 3; }
 
 __attribute__((target_version("ls64"))) int fmv_e(void);
@@ -385,7 +385,7 @@ int hoo(void) {
 // CHECK-NEXT:[[TMP59:%.*]] = and i1 true, [[TMP58]]
 // CHECK-NEXT:br i1 [[TMP59]], label [[RESOLVER_RETURN27:%.*]], label 
[[RESOLVER_ELSE28:%.*]]
 // CHECK:   resolver_return27:
-// CHECK-NEXT:ret ptr @fmv_inline._MlseMrdm
+// CHECK-NEXT:ret ptr @fmv_inline._MlseMrdma
 // CHECK:   resolver_else28:
 // CHECK-NEXT:[[TMP60:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
 // CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 32
@@ -673,7 +673,7 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdm
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdma
 // CHECK-SAME: () #[[ATTR25:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 16
diff --git a/clang/test/Driver/aarch64-rdm.c b/clang/test/Driver/aarch64-rdm.c
index f2542b381e7c2..62e1a4def4ce1 100644
--- a/clang/test/Driver/aarch64-rdm.c
+++ b/clang/test/Driver/aarch64-rdm.c
@@ -1,13 +1,16 @@
 // RUN: %clang --target=aarch64-none-elf -march=armv8a+rdm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
+// RUN: %clang --target=aarch64-none-elf -march=armv8a+rdma -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=generic+rdm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=falkor -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=thunderx2t99 -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // CHECK-RDM: "-target-feature" "+rdm"
 
 // RUN: %clang --target=aarch64-none-elf -march=armv8a+nordm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-NORDM %s
+// RUN: %clang --target=aarch64-none-elf -march=armv8a+nordma -### -c %s 2>&1 
| FileCheck --check-prefix=CHECK-NORDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=generic+nordm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-NORDM %s
 // CHECK-NORDM-NOT: "-target-feature" "+rdm"
 //
 // RUN: %clang --target=aarch64-none-elf -march=armv8.1a -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // RUN: %clang --target=aarch64-none-elf -march=armv8.1a+nordm -### -c %s 2>&1 
| FileCheck --check-prefix=CHECK-NORDM-DEFAULT %s
+// RUN: %clang --target=aarch64-none-elf -march=armv8.1a+nordma -### -c %s 
2>&1 | FileCheck --check-prefix=CHECK-NORDM-DEFAULT %s
 //

[clang] [Clang][Sema] fix outline member function template with default align crash (PR #80288)

2024-02-03 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80288

>From cfcffbfa15959963b2b91078ec1911504811d3c1 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 1 Feb 2024 20:54:46 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/docs/ReleaseNotes.rst   |   4 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/test/SemaTemplate/default-parm-init.cpp | 190 ++
 3 files changed, 206 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..3596109bf044f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -197,6 +197,10 @@ Bug Fixes to C++ Support
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
   Fixes (`#79748 `_)
+- Fix a crash when specializing an out-of-line member function with a default
+  parameter where we did an incorrect specialization of the initialization of
+  the default parameter.
+  Fixes (`#68490 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 01b78e4424fb5..e5999fa50117e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3049,6 +3049,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+MultiLevelTemplateArgumentList NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3061,11 +3062,20 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  const FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate();
+  if (PrimaryTemplate && PrimaryTemplate->isOutOfLine()) {
+TemplateArgumentList *CurrentTemplateArgumentList =
+TemplateArgumentList::CreateCopy(getASTContext(),
+ TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), /*Final=*/false,
+CurrentTemplateArgumentList->asArray(), 
/*RelativeToPrimary=*/true);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 0..73ba8998df6a9
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,190 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+namespace std {
+
+template class function;
+
+template class invoker_base {
+public: 
+  virtual ~invoker_base() { } 
+  virtual R invoke(Args...) = 0; 
+  virtual invoker_base* clone() = 0;
+};
+
+template 
+class functor_invoker : public invoker_base {
+public: 
+  explicit functor_invoker(const F& f) : f(f) { } 
+  R invoke(Args... args) { return f(args...); } 
+  functor_invoker* clone() { return new functor_invoker(f); }
+
+private:
+  F f;
+};
+
+template
+class function {
+public: 
+  typedef R result_type;
+  function() : invoker (0) { }
+  function(const function& other) : invoker(0) { 
+if (other.invoker)
+  invoker = other.invoker->clone();
+  }
+
+  template function(const F& f) : invoker(0) {
+invoker = new functor_invoker(f);
+  }
+
+  ~function() { 
+if (invoker)
+  delete invoker;
+  }
+
+  function& operator=(const function& other) { 
+function(other).swap(*this); 
+return *this;
+  }
+
+  template 
+  function& operator=(const F& f) {
+function(f).swap(*this); 
+return *this;
+  }
+
+  void swap(function& other) { 
+invoker_base* tmp = invoker; 
+invoker = other.invoker; 
+other.invoker = tmp;
+  }
+
+  result_type operator()(Args... args) const { 
+return invoker->invoke(args...);
+  }
+
+private: 
+  invoker_base* invoker;
+};
+
+}
+
+template
+struct Problem {
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alig

[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny created 
https://github.com/llvm/llvm-project/pull/80541

Resolves #77618.

From a6f7d8f72ab4af680dc17004e9bccefbe268b712 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sat, 3 Feb 2024 13:13:50 +0100
Subject: [PATCH 1/7] Trigger on variable declarations

---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../UseDesignatedInitializersCheck.cpp| 58 +++
 .../UseDesignatedInitializersCheck.h  | 33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../modernize/use-designated-initializers.rst |  6 ++
 .../modernize/use-designated-initializers.cpp | 32 ++
 8 files changed, 139 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 28ca52f46943a..6852db6c2ee31 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
   UseDefaultMemberInitCheck.cpp
+  UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 654f4bd0c6ba4..e96cf274f58cf 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
+#include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
@@ -68,6 +69,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
 CheckFactories.registerCheck("modernize-pass-by-value");
+CheckFactories.registerCheck(
+"modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
new file mode 100644
index 0..06f0bb0dc06ea
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -0,0 +1,58 @@
+//===--- UseDesignatedInitializersCheck.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 "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static std::vector
+getAllUndesignatedInits(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(varDecl(allOf(has(initListExpr().bind("init")),
+   hasType(recordDecl().bind("type",
+ this);
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList || !Type->isAggregate())
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const auto UndesignatedParts = getAllUndesignatedInits(SyntacticInitList);
+if (UndesignatedParts.empty())
+  return;
+if (UndesignatedParts.size() == SyntacticInitList->getNumInits()) {
+  diag(InitList->getLBraceLoc(), "us

[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:



@llvm/pr-subscribers-clang-tidy

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

Author: Danny Mösch (SimplyDanny)


Changes

Resolves #77618.

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


8 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/CMakeLists.txt (+1) 
- (modified) clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
(+3) 
- (added) 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp (+77) 
- (added) 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h (+42) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
 (+44) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp
 (+48) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 28ca52f46943a..6852db6c2ee31 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
   UseDefaultMemberInitCheck.cpp
+  UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 654f4bd0c6ba4..e96cf274f58cf 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
+#include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
@@ -68,6 +69,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
 CheckFactories.registerCheck("modernize-pass-by-value");
+CheckFactories.registerCheck(
+"modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
new file mode 100644
index 0..d269cef13e6aa
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -0,0 +1,77 @@
+//===--- UseDesignatedInitializersCheck.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 "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr auto IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static constexpr auto IgnoreSingleElementAggregatesDefault = true;
+
+static std::vector
+getUndesignatedComponents(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreSingleElementAggregates(
+  Options.getLocalOrGlobal(IgnoreSingleElementAggregatesName,
+   IgnoreSingleElementAggregatesDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(hasType(recordDecl().bind("type"))).bind("init"), this);
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList || !Type->isAggregate(

[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/80541

From a6f7d8f72ab4af680dc17004e9bccefbe268b712 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sat, 3 Feb 2024 13:13:50 +0100
Subject: [PATCH 1/8] Trigger on variable declarations

---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../UseDesignatedInitializersCheck.cpp| 58 +++
 .../UseDesignatedInitializersCheck.h  | 33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../modernize/use-designated-initializers.rst |  6 ++
 .../modernize/use-designated-initializers.cpp | 32 ++
 8 files changed, 139 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 28ca52f46943a..6852db6c2ee31 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
   UseDefaultMemberInitCheck.cpp
+  UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 654f4bd0c6ba4..e96cf274f58cf 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
+#include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
@@ -68,6 +69,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
 CheckFactories.registerCheck("modernize-pass-by-value");
+CheckFactories.registerCheck(
+"modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
new file mode 100644
index 0..06f0bb0dc06ea
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -0,0 +1,58 @@
+//===--- UseDesignatedInitializersCheck.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 "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static std::vector
+getAllUndesignatedInits(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(varDecl(allOf(has(initListExpr().bind("init")),
+   hasType(recordDecl().bind("type",
+ this);
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList || !Type->isAggregate())
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const auto UndesignatedParts = getAllUndesignatedInits(SyntacticInitList);
+if (UndesignatedParts.empty())
+  return;
+if (UndesignatedParts.size() == SyntacticInitList->getNumInits()) {
+  diag(InitList->getLBraceLoc(), "use designated initi

[libcxxabi] [libunwind] [libcxx] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits


@@ -15,6 +15,7 @@
 
 #include <__libunwind_config.h>
 
+#ifndef __wasm__

trcrsired wrote:

it does not compile. all the definitions are not defined

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


[libcxxabi] [libunwind] [libcxx] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits


@@ -35,7 +32,12 @@ struct _Unwind_LandingPadContext {
 
 // Communication channel between compiler-generated user code and personality
 // function
-thread_local struct _Unwind_LandingPadContext __wasm_lpad_context;
+#if __STDC_VERSION__ >= 202311L

trcrsired wrote:

thread.h does not exist.

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


[libcxxabi] [libunwind] [libcxx] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits

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


[libcxxabi] [libunwind] [libcxx] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits


@@ -10,14 +10,11 @@
 //
 
//===--===//
 
+#if __STDC_VERSION__ < 202311L

trcrsired wrote:

stdbool.h removed in C23

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


[libcxxabi] [libunwind] [libcxx] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits


@@ -12,6 +12,7 @@
 #include 
 
 #include "config.h"
+#ifndef __wasm__

trcrsired wrote:

the problem is that the debugging code needs in libunwind

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


[libcxxabi] [libunwind] [libcxx] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits


@@ -180,6 +180,7 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)

trcrsired wrote:

What is the correct value here? I mean if you give users a number and they may 
make wrong assumptions here.

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


[clang] [clang] Add GCC-compatible code model names for sparc64 (PR #79485)

2024-02-03 Thread Brad Smith via cfe-commits

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


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


[libcxx] [libunwind] [libcxxabi] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits


@@ -36,7 +36,12 @@ struct __cxa_exception;
 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
 void*,
 std::type_info*,
-void(
+#  if defined(__USING_WASM_EXCEPTIONS__)

trcrsired wrote:

yeah. but here's a problem. __USING_WASM_EXCEPTIONS__ is not defined by clang 
19 even with -fwasm-exceptions enabled. i suggest to just use __wasi__ macro, 
instead of __USING_WASM_EXCEPTIONS__ 

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


[clang] 752c172 - [Clang][Sema] fix outline member function template with default align crash (#80288)

2024-02-03 Thread via cfe-commits

Author: Qizhi Hu
Date: 2024-02-03T21:49:09+08:00
New Revision: 752c172bc7d628fe5ce4a78f3620893b8d7bcfba

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

LOG: [Clang][Sema] fix outline member function template with default align 
crash (#80288)

Try to fix [issue](https://github.com/llvm/llvm-project/issues/68490 )
and some extented problem. Root cause of current issue is that error
handling in instantiation of function parameter with default
initialization on sizeof or align expression. When instance an
out-of-line template member function, depth of `TemplateTypeParmDecl` in
default initialization doesn't change while depth of other template
parameter does and this will lead to some template parameter
uninstanced. Also, sometime it will leader to wrong instantiation when
it uses the template parameter of the template class.
Fix it by add template args of context. This will make
MultiLevelTemplateArgumentList::getNumLevels matching the depth of
template parameter. Testcase with some static_assert demonstrates the
template parameter has been instanced correctly.
But, the default initialization of lambda expression compiles failed
when only checking if the member function is out-of-line. We should
check the `PrimaryFunctionTemplateDecl` of the funtion if it's
out-of-line.

Co-authored-by: huqizhi <836744...@qq.com>

Added: 
clang/test/SemaTemplate/default-parm-init.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateInstantiate.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..3596109bf044f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -197,6 +197,10 @@ Bug Fixes to C++ Support
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
   Fixes (`#79748 `_)
+- Fix a crash when specializing an out-of-line member function with a default
+  parameter where we did an incorrect specialization of the initialization of
+  the default parameter.
+  Fixes (`#68490 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 01b78e4424fb5..e5999fa50117e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3049,6 +3049,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+MultiLevelTemplateArgumentList NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3061,11 +3062,20 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  const FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate();
+  if (PrimaryTemplate && PrimaryTemplate->isOutOfLine()) {
+TemplateArgumentList *CurrentTemplateArgumentList =
+TemplateArgumentList::CreateCopy(getASTContext(),
+ TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), /*Final=*/false,
+CurrentTemplateArgumentList->asArray(), 
/*RelativeToPrimary=*/true);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())

diff  --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 0..73ba8998df6a9
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,190 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+namespace std {
+
+template class function;
+
+template class invoker_base {
+public: 
+  virtual ~invoker_base() { } 
+  virtual R invoke(Args...) = 0; 
+  virtual invoker_base* clone() = 0;
+};
+
+template 
+class functor_invoker : public invoker_base {
+public: 
+  explicit functor_invoker(const F& f) : f(f) { } 
+  R invoke(Args... args) { return f(args...); } 
+  functor_invoker* clone() { return new functor_invoker(f); }
+
+private:
+  F f;
+};
+
+templ

[clang] [Clang][Sema] fix outline member function template with default align crash (PR #80288)

2024-02-03 Thread Qizhi Hu via cfe-commits

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


[libcxx] [libunwind] [libcxxabi] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits


@@ -35,7 +32,12 @@ struct _Unwind_LandingPadContext {
 
 // Communication channel between compiler-generated user code and personality
 // function
-thread_local struct _Unwind_LandingPadContext __wasm_lpad_context;
+#if __STDC_VERSION__ >= 202311L

trcrsired wrote:

> ldionne

it is a c file. not a .cpp file. it compiles with C compiler not C++

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


[libcxx] [libunwind] [libcxxabi] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits


@@ -12,6 +12,7 @@
 #include 
 
 #include "config.h"
+#ifndef __wasm__

trcrsired wrote:

i have included apis with minimal code.
https://github.com/llvm/llvm-project/blob/b5fee4962c347016a732a1310275651a8c74f23a/libunwind/src/libunwind.cpp#L442
It needs logAPIs in the file

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


[libcxx] [libunwind] [libcxxabi] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits


@@ -36,7 +36,12 @@ struct __cxa_exception;
 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
 void*,
 std::type_info*,
-void(
+#  if defined(__USING_WASM_EXCEPTIONS__)

trcrsired wrote:

ok i will try to fix it.

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


[libcxxabi] [libcxx] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits

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


[libcxxabi] [libcxx] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-02-03 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,42 @@
+//===--- UseDesignatedInitializersCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEDESIGNATEDINITIALIZERSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEDESIGNATEDINITIALIZERSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::modernize {
+
+/// Triggers on initializer lists for aggregate type that could be
+/// written as designated initializers instead.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-designated-initializers.html
+class UseDesignatedInitializersCheck : public ClangTidyCheck {
+public:
+  UseDesignatedInitializersCheck(StringRef Name, ClangTidyContext *Context);
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.CPlusPlus20;
+  }

PiotrZSL wrote:

I don't think that this check should be set to C++20 only, for example in my 
project we enabled designated initializers in C++17, simply because they work, 
and in previous project we enabled them even in C++11 as GCC extension.

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 


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

Still some work is needed, like auto-fixes, and corner cases and some cleanup, 
but +- looks fine.

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,77 @@
+//===--- UseDesignatedInitializersCheck.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 "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr auto IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static constexpr auto IgnoreSingleElementAggregatesDefault = true;
+
+static std::vector
+getUndesignatedComponents(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreSingleElementAggregates(
+  Options.getLocalOrGlobal(IgnoreSingleElementAggregatesName,
+   IgnoreSingleElementAggregatesDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(hasType(recordDecl().bind("type"))).bind("init"), this);

PiotrZSL wrote:

Handle anonymous structures and unions, unions, and classes with anonymous 
fields. (ignore them, do some tests).
```

bool isAnonymousDecl(const RecordDecl* p_record) noexcept
{
return p_record and (p_record->isAnonymousStructOrUnion() or 
p_record->getIdentifier() == nullptr);
}

AST_MATCHER(RecordDecl, isUnion) { return Node.isUnion(); }
AST_MATCHER(RecordDecl, isAnonymousStructOrUnion) { return 
isAnonymousDecl(&Node); }
AST_MATCHER(RecordDecl, hasAnonymousFields) {
for(auto&& field : Node.fields())
{
if 
(isAnonymousDecl(field->getType().getCanonicalType()->getAsRecordDecl()))
{
return true;
}
}
return false;
}
```
```
struct StructWithAnonymous
{
struct {
int ala;
} value;
};


StructWithAnonymous g_value = { 5 };
```

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -100,6 +100,12 @@ Improvements to clang-tidy
 New checks
 ^^
 
+- New :doc:`modernize-use-designated-initializers
+  ` check.
+
+  Triggers on initializer lists for aggregate type that could be
+  written as designated initializers instead.

PiotrZSL wrote:

Maybe better just "Finds ..." Idea is to point what check do without referring 
to check.

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,77 @@
+//===--- UseDesignatedInitializersCheck.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 "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr auto IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static constexpr auto IgnoreSingleElementAggregatesDefault = true;
+
+static std::vector
+getUndesignatedComponents(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreSingleElementAggregates(
+  Options.getLocalOrGlobal(IgnoreSingleElementAggregatesName,
+   IgnoreSingleElementAggregatesDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(hasType(recordDecl().bind("type"))).bind("init"), this);

PiotrZSL wrote:

Consider excluding template dependent code, as for example:
```

template
T init()
{
   return {10, 11};
}

struct A
{
   int x,y;
};

struct B {
  int a,b;
};

void test()
{
   init();
   init();
}
```

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,77 @@
+//===--- UseDesignatedInitializersCheck.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 "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr auto IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static constexpr auto IgnoreSingleElementAggregatesDefault = true;
+
+static std::vector
+getUndesignatedComponents(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreSingleElementAggregates(
+  Options.getLocalOrGlobal(IgnoreSingleElementAggregatesName,

PiotrZSL wrote:

This should be just getLocal, to be honest.

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,48 @@
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-designated-initializers 
%t
+// RUN: %check_clang_tidy -check-suffixes=,SINGLE-ELEMENT -std=c++20 %s 
modernize-use-designated-initializers %t \
+// RUN: -- -config="{CheckOptions: [{key: 
modernize-use-designated-initializers.IgnoreSingleElementAggregates, value: 
false}]}" \
+// RUN: --
+
+struct S1 {};
+
+S1 s11{};
+S1 s12 = {};
+S1 s13();
+S1 s14;
+
+struct S2 { int i, j; };
+
+S2 s21{.i=1, .j =2};
+
+S2 s22 = {1, 2};
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list 
[modernize-use-designated-initializers]
+
+S2 s23{1};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use designated initializer list 
[modernize-use-designated-initializers]
+
+S2 s24{.i = 1};
+
+S2 s25 = {.i=1, 2};
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use designated init expression 
[modernize-use-designated-initializers]
+
+class S3 {
+  public:
+S2 s2;
+double d;
+};
+
+S3 s31 = {.s2 = 1, 2, 3.1};
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use designated init expression 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES: :[[@LINE-2]]:23: warning: use designated init expression 
[modernize-use-designated-initializers]
+
+S3 s32 = {{.i = 1, 2}};
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES: :[[@LINE-2]]:20: warning: use designated init expression 
[modernize-use-designated-initializers]
+
+struct S4 {
+double d;
+private: static int i;
+};
+
+S4 s41 {2.2};
+// CHECK-MESSAGES-SINGLE-ELEMENT: :[[@LINE-1]]:8: warning: use designated 
initializer list [modernize-use-designated-initializers]

PiotrZSL wrote:

Add tests that handle cases where everything is default:
```
`-InitListExpr  'B':'B'
| |-CXXDefaultInitExpr  'int'
| `-CXXDefaultInitExpr  'int'
```
```
template
T init()
{
   return {};
}

struct B {
  int a=15,b=16;
};

```

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,48 @@
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-designated-initializers 
%t
+// RUN: %check_clang_tidy -check-suffixes=,SINGLE-ELEMENT -std=c++20 %s 
modernize-use-designated-initializers %t \
+// RUN: -- -config="{CheckOptions: [{key: 
modernize-use-designated-initializers.IgnoreSingleElementAggregates, value: 
false}]}" \
+// RUN: --
+
+struct S1 {};
+
+S1 s11{};
+S1 s12 = {};
+S1 s13();
+S1 s14;
+
+struct S2 { int i, j; };
+
+S2 s21{.i=1, .j =2};
+
+S2 s22 = {1, 2};
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list 
[modernize-use-designated-initializers]
+
+S2 s23{1};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use designated initializer list 
[modernize-use-designated-initializers]
+
+S2 s24{.i = 1};
+
+S2 s25 = {.i=1, 2};
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use designated init expression 
[modernize-use-designated-initializers]
+
+class S3 {
+  public:
+S2 s2;
+double d;
+};
+
+S3 s31 = {.s2 = 1, 2, 3.1};
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use designated init expression 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES: :[[@LINE-2]]:23: warning: use designated init expression 
[modernize-use-designated-initializers]
+
+S3 s32 = {{.i = 1, 2}};
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES: :[[@LINE-2]]:20: warning: use designated init expression 
[modernize-use-designated-initializers]
+
+struct S4 {
+double d;
+private: static int i;
+};
+
+S4 s41 {2.2};
+// CHECK-MESSAGES-SINGLE-ELEMENT: :[[@LINE-1]]:8: warning: use designated 
initializer list [modernize-use-designated-initializers]

PiotrZSL wrote:

Add tests with base class like:
```
template
T init()
{
   return {10, 11};
}

struct A
{
   int x,y;
};

struct B : A {
  int a,b;
};

void test()
{
 //  init();
   init();
}
```

problem is that without designated initializers:
```
CompoundStmt 
| `-ReturnStmt 
|   `-InitListExpr  'B':'B'
| |-InitListExpr  'A':'A'
| | |-IntegerLiteral  'int' 10
| | `-IntegerLiteral  'int' 11
| |-ImplicitValueInitExpr 'int'
| `-ImplicitValueInitExpr 'int'
```

actually base class is initialized, but with designated initializers:
```
template
T init()
{
   return {.a=10, .b=11};
}

`-CompoundStmt 
| `-ReturnStmt 
|   `-InitListExpr  'B':'B'
| |-InitListExpr  'A':'A'
| | |-ImplicitValueInitExpr 'int'
| | `-ImplicitValueInitExpr 'int'
| |-IntegerLiteral  'int' 10
| `-IntegerLiteral  'int' 11
```
its ta delivered class that is initialized, to init base class double {} are 
needed:
```
template
T init()
{
   return {{.x=10, .y=11}, .a=12, .b=14};
}

but with this there is a way to properly initialize both but there is compiler 
warning triggered due to mixing.
```

Would be very good to exclude classes that got base class with fields in first 
version to avoid such problems.

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,77 @@
+//===--- UseDesignatedInitializersCheck.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 "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr auto IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static constexpr auto IgnoreSingleElementAggregatesDefault = true;
+
+static std::vector
+getUndesignatedComponents(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreSingleElementAggregates(
+  Options.getLocalOrGlobal(IgnoreSingleElementAggregatesName,
+   IgnoreSingleElementAggregatesDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(hasType(recordDecl().bind("type"))).bind("init"), this);
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList || !Type->isAggregate())
+return;
+  if (IgnoreSingleElementAggregates && InitList->getNumInits() == 1)
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const auto UndesignatedComponents =
+getUndesignatedComponents(SyntacticInitList);
+if (UndesignatedComponents.empty())
+  return;
+if (UndesignatedComponents.size() == SyntacticInitList->getNumInits()) {
+  diag(InitList->getLBraceLoc(), "use designated initializer list");

PiotrZSL wrote:

missing auto-fixes, like:
```
 << FixItHint::CreateInsertion((*currentI)->getBeginLoc(), "."+name+" = ");
```

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,77 @@
+//===--- UseDesignatedInitializersCheck.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 "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr auto IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static constexpr auto IgnoreSingleElementAggregatesDefault = true;
+
+static std::vector
+getUndesignatedComponents(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreSingleElementAggregates(
+  Options.getLocalOrGlobal(IgnoreSingleElementAggregatesName,
+   IgnoreSingleElementAggregatesDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(hasType(recordDecl().bind("type"))).bind("init"), this);

PiotrZSL wrote:

Exclude designated initializers on this level, same for 
IgnoreSingleElementAggregates, do it on AST mater level.
```
`-InitListExpr  'void'
| |   `-DesignatedInitExpr  'void'
| | `-IntegerLiteral  'int' 10
```

Simply check if there is already any DesignatedInitExpr.
Same for this isAggregate, check this also on matcher level.

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


[llvm] [clang-tools-extra] [clang] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. (PR #80269)

2024-02-03 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/80269

>From f4dabdfaa66744ecfca4c0a57472a357db9715d9 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Wed, 31 Jan 2024 14:02:38 +
Subject: [PATCH] [VPlan] Update VPInst::onlyFirstLaneUsed to check users.

A VPInstruction only has its first lane used if all users use its first
lane only. Use vputils::onlyFirstLaneUsed to continue checking the
recipe's users to handle more cases.

Besides allowing additional introduction of scalar steps when
interleaving in some cases, this also enables using an Add VPInstruction
to model the increment.
---
 llvm/lib/Transforms/Vectorize/VPlan.cpp   |   4 +-
 llvm/lib/Transforms/Vectorize/VPlan.h |  20 +--
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |  18 ++
 .../pr45679-fold-tail-by-masking.ll   | 160 +-
 .../tail-folding-vectorization-factor-1.ll|  66 
 5 files changed, 129 insertions(+), 139 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp 
b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index a1bd6aaf0e551..1ca2cfef447f6 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1397,9 +1397,9 @@ void VPSlotTracker::assignSlots(const VPBasicBlock *VPBB) 
{
   assignSlot(Def);
 }
 
-bool vputils::onlyFirstLaneUsed(VPValue *Def) {
+bool vputils::onlyFirstLaneUsed(const VPValue *Def) {
   return all_of(Def->users(),
-[Def](VPUser *U) { return U->onlyFirstLaneUsed(Def); });
+[Def](const VPUser *U) { return U->onlyFirstLaneUsed(Def); });
 }
 
 bool vputils::onlyFirstPartUsed(VPValue *Def) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 20792cb9ac7c1..30dc521947b3b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1256,23 +1256,7 @@ class VPInstruction : public VPRecipeWithIRFlags {
 }
   }
 
-  /// Returns true if the recipe only uses the first lane of operand \p Op.
-  bool onlyFirstLaneUsed(const VPValue *Op) const override {
-assert(is_contained(operands(), Op) &&
-   "Op must be an operand of the recipe");
-if (getOperand(0) != Op)
-  return false;
-switch (getOpcode()) {
-default:
-  return false;
-case VPInstruction::ActiveLaneMask:
-case VPInstruction::CalculateTripCountMinusVF:
-case VPInstruction::CanonicalIVIncrementForPart:
-case VPInstruction::BranchOnCount:
-  return true;
-};
-llvm_unreachable("switch should return");
-  }
+  bool onlyFirstLaneUsed(const VPValue *Op) const override;
 
   /// Returns true if the recipe only uses the first part of operand \p Op.
   bool onlyFirstPartUsed(const VPValue *Op) const override {
@@ -3385,7 +3369,7 @@ class VPlanSlp {
 namespace vputils {
 
 /// Returns true if only the first lane of \p Def is used.
-bool onlyFirstLaneUsed(VPValue *Def);
+bool onlyFirstLaneUsed(const VPValue *Def);
 
 /// Returns true if only the first part of \p Def is used.
 bool onlyFirstPartUsed(VPValue *Def);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index e51184b0dd1fe..21b8d1eb77bf9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -515,6 +515,24 @@ void VPInstruction::execute(VPTransformState &State) {
 State.set(this, GeneratedValue, Part);
   }
 }
+bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
+  assert(is_contained(operands(), Op) && "Op must be an operand of the 
recipe");
+  if (Instruction::isBinaryOp(getOpcode()))
+return vputils::onlyFirstLaneUsed(this);
+
+  switch (getOpcode()) {
+  default:
+return false;
+  case Instruction::ICmp:
+return vputils::onlyFirstLaneUsed(this);
+  case VPInstruction::ActiveLaneMask:
+  case VPInstruction::CalculateTripCountMinusVF:
+  case VPInstruction::CanonicalIVIncrementForPart:
+  case VPInstruction::BranchOnCount:
+return getOperand(0) == Op;
+  };
+  llvm_unreachable("switch should return");
+}
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void VPInstruction::dump() const {
diff --git a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll 
b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
index e81fb66239bd4..f05ec30619c5d 100644
--- a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
+++ b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
@@ -67,7 +67,7 @@ define void @pr45679(ptr %A) optsize {
 ; CHECK-NEXT:store i32 13, ptr [[ARRAYIDX]], align 1
 ; CHECK-NEXT:[[RIVPLUS1]] = add nuw nsw i32 [[RIV]], 1
 ; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[RIVPLUS1]], 14
-; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop 
[[LOOP2:![0-9]+]]
+; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop 
[[LOOP3:![0-9]+]]
 ; CHECK:

[clang] [clang-tools-extra] [llvm] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. (PR #80269)

2024-02-03 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/80269

>From f4dabdfaa66744ecfca4c0a57472a357db9715d9 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Wed, 31 Jan 2024 14:02:38 +
Subject: [PATCH] [VPlan] Update VPInst::onlyFirstLaneUsed to check users.

A VPInstruction only has its first lane used if all users use its first
lane only. Use vputils::onlyFirstLaneUsed to continue checking the
recipe's users to handle more cases.

Besides allowing additional introduction of scalar steps when
interleaving in some cases, this also enables using an Add VPInstruction
to model the increment.
---
 llvm/lib/Transforms/Vectorize/VPlan.cpp   |   4 +-
 llvm/lib/Transforms/Vectorize/VPlan.h |  20 +--
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |  18 ++
 .../pr45679-fold-tail-by-masking.ll   | 160 +-
 .../tail-folding-vectorization-factor-1.ll|  66 
 5 files changed, 129 insertions(+), 139 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp 
b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index a1bd6aaf0e551..1ca2cfef447f6 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1397,9 +1397,9 @@ void VPSlotTracker::assignSlots(const VPBasicBlock *VPBB) 
{
   assignSlot(Def);
 }
 
-bool vputils::onlyFirstLaneUsed(VPValue *Def) {
+bool vputils::onlyFirstLaneUsed(const VPValue *Def) {
   return all_of(Def->users(),
-[Def](VPUser *U) { return U->onlyFirstLaneUsed(Def); });
+[Def](const VPUser *U) { return U->onlyFirstLaneUsed(Def); });
 }
 
 bool vputils::onlyFirstPartUsed(VPValue *Def) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 20792cb9ac7c1..30dc521947b3b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1256,23 +1256,7 @@ class VPInstruction : public VPRecipeWithIRFlags {
 }
   }
 
-  /// Returns true if the recipe only uses the first lane of operand \p Op.
-  bool onlyFirstLaneUsed(const VPValue *Op) const override {
-assert(is_contained(operands(), Op) &&
-   "Op must be an operand of the recipe");
-if (getOperand(0) != Op)
-  return false;
-switch (getOpcode()) {
-default:
-  return false;
-case VPInstruction::ActiveLaneMask:
-case VPInstruction::CalculateTripCountMinusVF:
-case VPInstruction::CanonicalIVIncrementForPart:
-case VPInstruction::BranchOnCount:
-  return true;
-};
-llvm_unreachable("switch should return");
-  }
+  bool onlyFirstLaneUsed(const VPValue *Op) const override;
 
   /// Returns true if the recipe only uses the first part of operand \p Op.
   bool onlyFirstPartUsed(const VPValue *Op) const override {
@@ -3385,7 +3369,7 @@ class VPlanSlp {
 namespace vputils {
 
 /// Returns true if only the first lane of \p Def is used.
-bool onlyFirstLaneUsed(VPValue *Def);
+bool onlyFirstLaneUsed(const VPValue *Def);
 
 /// Returns true if only the first part of \p Def is used.
 bool onlyFirstPartUsed(VPValue *Def);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index e51184b0dd1fe..21b8d1eb77bf9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -515,6 +515,24 @@ void VPInstruction::execute(VPTransformState &State) {
 State.set(this, GeneratedValue, Part);
   }
 }
+bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
+  assert(is_contained(operands(), Op) && "Op must be an operand of the 
recipe");
+  if (Instruction::isBinaryOp(getOpcode()))
+return vputils::onlyFirstLaneUsed(this);
+
+  switch (getOpcode()) {
+  default:
+return false;
+  case Instruction::ICmp:
+return vputils::onlyFirstLaneUsed(this);
+  case VPInstruction::ActiveLaneMask:
+  case VPInstruction::CalculateTripCountMinusVF:
+  case VPInstruction::CanonicalIVIncrementForPart:
+  case VPInstruction::BranchOnCount:
+return getOperand(0) == Op;
+  };
+  llvm_unreachable("switch should return");
+}
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void VPInstruction::dump() const {
diff --git a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll 
b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
index e81fb66239bd4..f05ec30619c5d 100644
--- a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
+++ b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
@@ -67,7 +67,7 @@ define void @pr45679(ptr %A) optsize {
 ; CHECK-NEXT:store i32 13, ptr [[ARRAYIDX]], align 1
 ; CHECK-NEXT:[[RIVPLUS1]] = add nuw nsw i32 [[RIV]], 1
 ; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[RIVPLUS1]], 14
-; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop 
[[LOOP2:![0-9]+]]
+; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop 
[[LOOP3:![0-9]+]]
 ; CHECK:

[clang] [clang-tools-extra] [llvm] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. (PR #80269)

2024-02-03 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/80269

>From f4dabdfaa66744ecfca4c0a57472a357db9715d9 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Wed, 31 Jan 2024 14:02:38 +
Subject: [PATCH 1/2] [VPlan] Update VPInst::onlyFirstLaneUsed to check users.

A VPInstruction only has its first lane used if all users use its first
lane only. Use vputils::onlyFirstLaneUsed to continue checking the
recipe's users to handle more cases.

Besides allowing additional introduction of scalar steps when
interleaving in some cases, this also enables using an Add VPInstruction
to model the increment.
---
 llvm/lib/Transforms/Vectorize/VPlan.cpp   |   4 +-
 llvm/lib/Transforms/Vectorize/VPlan.h |  20 +--
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |  18 ++
 .../pr45679-fold-tail-by-masking.ll   | 160 +-
 .../tail-folding-vectorization-factor-1.ll|  66 
 5 files changed, 129 insertions(+), 139 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp 
b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index a1bd6aaf0e551..1ca2cfef447f6 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1397,9 +1397,9 @@ void VPSlotTracker::assignSlots(const VPBasicBlock *VPBB) 
{
   assignSlot(Def);
 }
 
-bool vputils::onlyFirstLaneUsed(VPValue *Def) {
+bool vputils::onlyFirstLaneUsed(const VPValue *Def) {
   return all_of(Def->users(),
-[Def](VPUser *U) { return U->onlyFirstLaneUsed(Def); });
+[Def](const VPUser *U) { return U->onlyFirstLaneUsed(Def); });
 }
 
 bool vputils::onlyFirstPartUsed(VPValue *Def) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 20792cb9ac7c1..30dc521947b3b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1256,23 +1256,7 @@ class VPInstruction : public VPRecipeWithIRFlags {
 }
   }
 
-  /// Returns true if the recipe only uses the first lane of operand \p Op.
-  bool onlyFirstLaneUsed(const VPValue *Op) const override {
-assert(is_contained(operands(), Op) &&
-   "Op must be an operand of the recipe");
-if (getOperand(0) != Op)
-  return false;
-switch (getOpcode()) {
-default:
-  return false;
-case VPInstruction::ActiveLaneMask:
-case VPInstruction::CalculateTripCountMinusVF:
-case VPInstruction::CanonicalIVIncrementForPart:
-case VPInstruction::BranchOnCount:
-  return true;
-};
-llvm_unreachable("switch should return");
-  }
+  bool onlyFirstLaneUsed(const VPValue *Op) const override;
 
   /// Returns true if the recipe only uses the first part of operand \p Op.
   bool onlyFirstPartUsed(const VPValue *Op) const override {
@@ -3385,7 +3369,7 @@ class VPlanSlp {
 namespace vputils {
 
 /// Returns true if only the first lane of \p Def is used.
-bool onlyFirstLaneUsed(VPValue *Def);
+bool onlyFirstLaneUsed(const VPValue *Def);
 
 /// Returns true if only the first part of \p Def is used.
 bool onlyFirstPartUsed(VPValue *Def);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index e51184b0dd1fe..21b8d1eb77bf9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -515,6 +515,24 @@ void VPInstruction::execute(VPTransformState &State) {
 State.set(this, GeneratedValue, Part);
   }
 }
+bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
+  assert(is_contained(operands(), Op) && "Op must be an operand of the 
recipe");
+  if (Instruction::isBinaryOp(getOpcode()))
+return vputils::onlyFirstLaneUsed(this);
+
+  switch (getOpcode()) {
+  default:
+return false;
+  case Instruction::ICmp:
+return vputils::onlyFirstLaneUsed(this);
+  case VPInstruction::ActiveLaneMask:
+  case VPInstruction::CalculateTripCountMinusVF:
+  case VPInstruction::CanonicalIVIncrementForPart:
+  case VPInstruction::BranchOnCount:
+return getOperand(0) == Op;
+  };
+  llvm_unreachable("switch should return");
+}
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void VPInstruction::dump() const {
diff --git a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll 
b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
index e81fb66239bd4..f05ec30619c5d 100644
--- a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
+++ b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
@@ -67,7 +67,7 @@ define void @pr45679(ptr %A) optsize {
 ; CHECK-NEXT:store i32 13, ptr [[ARRAYIDX]], align 1
 ; CHECK-NEXT:[[RIVPLUS1]] = add nuw nsw i32 [[RIV]], 1
 ; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[RIVPLUS1]], 14
-; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop 
[[LOOP2:![0-9]+]]
+; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop 
[[LOOP3:![0-9]+]]
 ; CHECK:

[clang] [clang-tools-extra] [llvm] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. (PR #80269)

2024-02-03 Thread Florian Hahn via cfe-commits


@@ -1256,23 +1256,7 @@ class VPInstruction : public VPRecipeWithIRFlags {
 }
   }
 

fhahn wrote:

Added back, thanks!

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


[clang] [llvm] [clang-tools-extra] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. (PR #80269)

2024-02-03 Thread Florian Hahn via cfe-commits


@@ -515,6 +515,24 @@ void VPInstruction::execute(VPTransformState &State) {
 State.set(this, GeneratedValue, Part);
   }
 }
+bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
+  assert(is_contained(operands(), Op) && "Op must be an operand of the 
recipe");
+  if (Instruction::isBinaryOp(getOpcode()))
+return vputils::onlyFirstLaneUsed(this);
+
+  switch (getOpcode()) {
+  default:
+return false;
+  case Instruction::ICmp:
+return vputils::onlyFirstLaneUsed(this);
+  case VPInstruction::ActiveLaneMask:
+  case VPInstruction::CalculateTripCountMinusVF:
+  case VPInstruction::CanonicalIVIncrementForPart:
+  case VPInstruction::BranchOnCount:
+return getOperand(0) == Op;

fhahn wrote:

Done, thanks!

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


[llvm] [clang-tools-extra] [clang] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. (PR #80269)

2024-02-03 Thread Florian Hahn via cfe-commits


@@ -1397,9 +1397,9 @@ void VPSlotTracker::assignSlots(const VPBasicBlock *VPBB) 
{
   assignSlot(Def);
 }
 
-bool vputils::onlyFirstLaneUsed(VPValue *Def) {
+bool vputils::onlyFirstLaneUsed(const VPValue *Def) {
   return all_of(Def->users(),
-[Def](VPUser *U) { return U->onlyFirstLaneUsed(Def); });
+[Def](const VPUser *U) { return U->onlyFirstLaneUsed(Def); });

fhahn wrote:

Split off to 693647902076034e7c81f380d1b937a65aef8ae6, thanks!

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


[clang] [llvm] [clang-tools-extra] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. (PR #80269)

2024-02-03 Thread Florian Hahn via cfe-commits


@@ -1397,9 +1397,9 @@ void VPSlotTracker::assignSlots(const VPBasicBlock *VPBB) 
{
   assignSlot(Def);
 }
 
-bool vputils::onlyFirstLaneUsed(VPValue *Def) {
+bool vputils::onlyFirstLaneUsed(const VPValue *Def) {
   return all_of(Def->users(),
-[Def](VPUser *U) { return U->onlyFirstLaneUsed(Def); });
+[Def](const VPUser *U) { return U->onlyFirstLaneUsed(Def); });
 }
 
 bool vputils::onlyFirstPartUsed(VPValue *Def) {

fhahn wrote:

Done in 3444240540b0b36902dc8b9b11339b8969f7bca9, thanks!

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


[clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-03 Thread via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,77 @@
+//===--- UseDesignatedInitializersCheck.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 "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr auto IgnoreSingleElementAggregatesName =

EugeneZelenko wrote:

Please do not use `auto` unless type is explicitly stated in same statement or 
iterator. Same in other places.

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


[clang] [llvm] [clang-tools-extra] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. (PR #80269)

2024-02-03 Thread Florian Hahn via cfe-commits

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


[clang] [llvm] [clang-tools-extra] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. (PR #80269)

2024-02-03 Thread Florian Hahn via cfe-commits

fhahn wrote:

> The only observable changes to existing tests involve cse'ing IV steps from 
> replicate regions when unrolling w/o vectorizing, iinm. Is there some other 
> scenario worth testing?

I wasn't able to come up with a different test with vectorizing.

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


[clang] [llvm] [clang-tools-extra] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. (PR #80269)

2024-02-03 Thread Florian Hahn via cfe-commits

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


[llvm] [clang] [clang-tools-extra] [VPlan] Consistently use (Part, 0) for first lane scalar values (PR #80271)

2024-02-03 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/80271

>From f4dabdfaa66744ecfca4c0a57472a357db9715d9 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Wed, 31 Jan 2024 14:02:38 +
Subject: [PATCH 1/2] [VPlan] Update VPInst::onlyFirstLaneUsed to check users.

A VPInstruction only has its first lane used if all users use its first
lane only. Use vputils::onlyFirstLaneUsed to continue checking the
recipe's users to handle more cases.

Besides allowing additional introduction of scalar steps when
interleaving in some cases, this also enables using an Add VPInstruction
to model the increment.
---
 llvm/lib/Transforms/Vectorize/VPlan.cpp   |   4 +-
 llvm/lib/Transforms/Vectorize/VPlan.h |  20 +--
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |  18 ++
 .../pr45679-fold-tail-by-masking.ll   | 160 +-
 .../tail-folding-vectorization-factor-1.ll|  66 
 5 files changed, 129 insertions(+), 139 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp 
b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index a1bd6aaf0e551..1ca2cfef447f6 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1397,9 +1397,9 @@ void VPSlotTracker::assignSlots(const VPBasicBlock *VPBB) 
{
   assignSlot(Def);
 }
 
-bool vputils::onlyFirstLaneUsed(VPValue *Def) {
+bool vputils::onlyFirstLaneUsed(const VPValue *Def) {
   return all_of(Def->users(),
-[Def](VPUser *U) { return U->onlyFirstLaneUsed(Def); });
+[Def](const VPUser *U) { return U->onlyFirstLaneUsed(Def); });
 }
 
 bool vputils::onlyFirstPartUsed(VPValue *Def) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 20792cb9ac7c1..30dc521947b3b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1256,23 +1256,7 @@ class VPInstruction : public VPRecipeWithIRFlags {
 }
   }
 
-  /// Returns true if the recipe only uses the first lane of operand \p Op.
-  bool onlyFirstLaneUsed(const VPValue *Op) const override {
-assert(is_contained(operands(), Op) &&
-   "Op must be an operand of the recipe");
-if (getOperand(0) != Op)
-  return false;
-switch (getOpcode()) {
-default:
-  return false;
-case VPInstruction::ActiveLaneMask:
-case VPInstruction::CalculateTripCountMinusVF:
-case VPInstruction::CanonicalIVIncrementForPart:
-case VPInstruction::BranchOnCount:
-  return true;
-};
-llvm_unreachable("switch should return");
-  }
+  bool onlyFirstLaneUsed(const VPValue *Op) const override;
 
   /// Returns true if the recipe only uses the first part of operand \p Op.
   bool onlyFirstPartUsed(const VPValue *Op) const override {
@@ -3385,7 +3369,7 @@ class VPlanSlp {
 namespace vputils {
 
 /// Returns true if only the first lane of \p Def is used.
-bool onlyFirstLaneUsed(VPValue *Def);
+bool onlyFirstLaneUsed(const VPValue *Def);
 
 /// Returns true if only the first part of \p Def is used.
 bool onlyFirstPartUsed(VPValue *Def);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index e51184b0dd1fe..21b8d1eb77bf9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -515,6 +515,24 @@ void VPInstruction::execute(VPTransformState &State) {
 State.set(this, GeneratedValue, Part);
   }
 }
+bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
+  assert(is_contained(operands(), Op) && "Op must be an operand of the 
recipe");
+  if (Instruction::isBinaryOp(getOpcode()))
+return vputils::onlyFirstLaneUsed(this);
+
+  switch (getOpcode()) {
+  default:
+return false;
+  case Instruction::ICmp:
+return vputils::onlyFirstLaneUsed(this);
+  case VPInstruction::ActiveLaneMask:
+  case VPInstruction::CalculateTripCountMinusVF:
+  case VPInstruction::CanonicalIVIncrementForPart:
+  case VPInstruction::BranchOnCount:
+return getOperand(0) == Op;
+  };
+  llvm_unreachable("switch should return");
+}
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void VPInstruction::dump() const {
diff --git a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll 
b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
index e81fb66239bd4..f05ec30619c5d 100644
--- a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
+++ b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
@@ -67,7 +67,7 @@ define void @pr45679(ptr %A) optsize {
 ; CHECK-NEXT:store i32 13, ptr [[ARRAYIDX]], align 1
 ; CHECK-NEXT:[[RIVPLUS1]] = add nuw nsw i32 [[RIV]], 1
 ; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[RIVPLUS1]], 14
-; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop 
[[LOOP2:![0-9]+]]
+; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop 
[[LOOP3:![0-9]+]]
 ; CHECK:

[llvm] [clang] [clang-tools-extra] [VPlan] Consistently use (Part, 0) for first lane scalar values (PR #80271)

2024-02-03 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/80271

>From f4dabdfaa66744ecfca4c0a57472a357db9715d9 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Wed, 31 Jan 2024 14:02:38 +
Subject: [PATCH 1/3] [VPlan] Update VPInst::onlyFirstLaneUsed to check users.

A VPInstruction only has its first lane used if all users use its first
lane only. Use vputils::onlyFirstLaneUsed to continue checking the
recipe's users to handle more cases.

Besides allowing additional introduction of scalar steps when
interleaving in some cases, this also enables using an Add VPInstruction
to model the increment.
---
 llvm/lib/Transforms/Vectorize/VPlan.cpp   |   4 +-
 llvm/lib/Transforms/Vectorize/VPlan.h |  20 +--
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |  18 ++
 .../pr45679-fold-tail-by-masking.ll   | 160 +-
 .../tail-folding-vectorization-factor-1.ll|  66 
 5 files changed, 129 insertions(+), 139 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp 
b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index a1bd6aaf0e551..1ca2cfef447f6 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1397,9 +1397,9 @@ void VPSlotTracker::assignSlots(const VPBasicBlock *VPBB) 
{
   assignSlot(Def);
 }
 
-bool vputils::onlyFirstLaneUsed(VPValue *Def) {
+bool vputils::onlyFirstLaneUsed(const VPValue *Def) {
   return all_of(Def->users(),
-[Def](VPUser *U) { return U->onlyFirstLaneUsed(Def); });
+[Def](const VPUser *U) { return U->onlyFirstLaneUsed(Def); });
 }
 
 bool vputils::onlyFirstPartUsed(VPValue *Def) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 20792cb9ac7c1..30dc521947b3b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1256,23 +1256,7 @@ class VPInstruction : public VPRecipeWithIRFlags {
 }
   }
 
-  /// Returns true if the recipe only uses the first lane of operand \p Op.
-  bool onlyFirstLaneUsed(const VPValue *Op) const override {
-assert(is_contained(operands(), Op) &&
-   "Op must be an operand of the recipe");
-if (getOperand(0) != Op)
-  return false;
-switch (getOpcode()) {
-default:
-  return false;
-case VPInstruction::ActiveLaneMask:
-case VPInstruction::CalculateTripCountMinusVF:
-case VPInstruction::CanonicalIVIncrementForPart:
-case VPInstruction::BranchOnCount:
-  return true;
-};
-llvm_unreachable("switch should return");
-  }
+  bool onlyFirstLaneUsed(const VPValue *Op) const override;
 
   /// Returns true if the recipe only uses the first part of operand \p Op.
   bool onlyFirstPartUsed(const VPValue *Op) const override {
@@ -3385,7 +3369,7 @@ class VPlanSlp {
 namespace vputils {
 
 /// Returns true if only the first lane of \p Def is used.
-bool onlyFirstLaneUsed(VPValue *Def);
+bool onlyFirstLaneUsed(const VPValue *Def);
 
 /// Returns true if only the first part of \p Def is used.
 bool onlyFirstPartUsed(VPValue *Def);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index e51184b0dd1fe..21b8d1eb77bf9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -515,6 +515,24 @@ void VPInstruction::execute(VPTransformState &State) {
 State.set(this, GeneratedValue, Part);
   }
 }
+bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
+  assert(is_contained(operands(), Op) && "Op must be an operand of the 
recipe");
+  if (Instruction::isBinaryOp(getOpcode()))
+return vputils::onlyFirstLaneUsed(this);
+
+  switch (getOpcode()) {
+  default:
+return false;
+  case Instruction::ICmp:
+return vputils::onlyFirstLaneUsed(this);
+  case VPInstruction::ActiveLaneMask:
+  case VPInstruction::CalculateTripCountMinusVF:
+  case VPInstruction::CanonicalIVIncrementForPart:
+  case VPInstruction::BranchOnCount:
+return getOperand(0) == Op;
+  };
+  llvm_unreachable("switch should return");
+}
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void VPInstruction::dump() const {
diff --git a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll 
b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
index e81fb66239bd4..f05ec30619c5d 100644
--- a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
+++ b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll
@@ -67,7 +67,7 @@ define void @pr45679(ptr %A) optsize {
 ; CHECK-NEXT:store i32 13, ptr [[ARRAYIDX]], align 1
 ; CHECK-NEXT:[[RIVPLUS1]] = add nuw nsw i32 [[RIV]], 1
 ; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[RIVPLUS1]], 14
-; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop 
[[LOOP2:![0-9]+]]
+; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop 
[[LOOP3:![0-9]+]]
 ; CHECK:

[libcxx] [llvm] [clang] [clang-tools-extra] [libc++] P2602R2 Poison Pills are Too Toxic (PR #74534)

2024-02-03 Thread Jakub Mazurkiewicz via cfe-commits

https://github.com/JMazurkiewicz updated 
https://github.com/llvm/llvm-project/pull/74534

>From aaccb9e13618517803df1230741b02b4c5ee08c7 Mon Sep 17 00:00:00 2001
From: Jakub Mazurkiewicz 
Date: Tue, 5 Dec 2023 23:36:57 +0100
Subject: [PATCH 1/5] [libc++] P2602R2 Poison Pills are Too Toxic

---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/Status/Cxx23Papers.csv|  2 +-
 libcxx/include/__compare/partial_order.h  |  2 ++
 libcxx/include/__compare/strong_order.h   |  2 ++
 libcxx/include/__compare/weak_order.h |  2 ++
 libcxx/include/__iterator/iter_move.h |  2 +-
 libcxx/include/__ranges/access.h  |  6 ++--
 libcxx/include/__ranges/rbegin.h  |  3 +-
 libcxx/include/__ranges/rend.h|  3 +-
 libcxx/include/__ranges/size.h|  3 +-
 libcxx/include/version|  4 +--
 .../iterator.cust.move/iter_move.pass.cpp | 11 +++
 .../iterator.cust.swap/iter_swap.pass.cpp |  6 
 .../ordinary_unqualified_lookup_helpers.h | 33 +++
 .../cmp/cmp.alg/partial_order.pass.cpp|  9 +
 .../cmp/cmp.alg/strong_order.pass.cpp |  9 +
 .../cmp/cmp.alg/weak_order.pass.cpp   |  9 +
 .../algorithm.version.compile.pass.cpp| 14 
 .../functional.version.compile.pass.cpp   | 14 
 .../iterator.version.compile.pass.cpp | 14 
 .../memory.version.compile.pass.cpp   | 14 
 .../ranges.version.compile.pass.cpp   | 14 
 .../version.version.compile.pass.cpp  | 14 
 .../std/ranges/range.access/begin.pass.cpp| 18 +++---
 .../test/std/ranges/range.access/end.pass.cpp | 20 +++
 .../ordinary_unqualified_lookup_helpers.h | 25 ++
 .../std/ranges/range.access/rbegin.pass.cpp   | 18 +++---
 .../std/ranges/range.access/rend.pass.cpp | 20 +++
 .../std/ranges/range.access/size.pass.cpp |  9 -
 .../generate_feature_test_macro_components.py |  2 +-
 30 files changed, 223 insertions(+), 81 deletions(-)
 create mode 100644 
libcxx/test/std/language.support/cmp/cmp.alg/ordinary_unqualified_lookup_helpers.h
 create mode 100644 
libcxx/test/std/ranges/range.access/ordinary_unqualified_lookup_helpers.h

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index d09f65b7cadc0..f4788aa574788 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -266,7 +266,7 @@ Status
 --- -
 ``__cpp_lib_polymorphic_allocator`` ``201902L``
 --- -
-``__cpp_lib_ranges````202207L``
+``__cpp_lib_ranges````202211L``
 --- -
 ``__cpp_lib_remove_cvref``  ``201711L``
 --- -
diff --git a/libcxx/docs/Status/Cxx23Papers.csv 
b/libcxx/docs/Status/Cxx23Papers.csv
index e03cbff2a08bb..7dc6f36ba1e63 100644
--- a/libcxx/docs/Status/Cxx23Papers.csv
+++ b/libcxx/docs/Status/Cxx23Papers.csv
@@ -100,7 +100,7 @@
 "`P2396R1 `__","LWG", "Concurrency TS 2 fixes ", 
"November 2022","","","|concurrency TS|"
 "`P2505R5 `__","LWG", "Monadic Functions for 
``std::expected``", "November 2022","|Complete|","17.0",""
 "`P2539R4 `__","LWG", "Should the output of 
``std::print`` to a terminal be synchronized with the underlying stream?", 
"November 2022","|In Progress|","","|format|"
-"`P2602R2 `__","LWG", "Poison Pills are Too Toxic", 
"November 2022","","","|ranges|"
+"`P2602R2 `__","LWG", "Poison Pills are Too Toxic", 
"November 2022","|Complete|","18.0","|ranges|"
 "`P2708R1 `__","LWG", "No Further Fundamentals 
TSes", "November 2022","|Nothing to do|","",""
 "","","","","","",""
 "`P0290R4 `__","LWG", "``apply()`` for 
``synchronized_value``","February 2023","","","|concurrency TS|"
diff --git a/libcxx/include/__compare/partial_order.h 
b/libcxx/include/__compare/partial_order.h
index 36a11dfaa2881..b422bdd4ef841 100644
--- a/libcxx/include/__compare/partial_order.h
+++ b/libcxx/include/__compare/partial_order.h
@@ -28,6 +28,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 // [cmp.alg]
 namespace __partial_order {
+void partial_order() = delete;
+
 struct __fn {
 // NOLINTBEGIN(libcpp-robust-against-adl) partial_order should use ADL, 
but only here
 template
diff --git a/libcxx/include/__compare/strong_order.h 
b/libcxx/include/__compare/strong_order.h
index cbfcf7316de9e..ba59cb51b86d9 100644
--- a/libcxx/include/__co

[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-03 Thread Vassil Vassilev via cfe-commits

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-03 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev commented:

This patch does too many things for me to be able to review it. This patch 
fails on our infrastructure.

I'd propose to simplify it to basically D41416 + the on-disk hash table. We 
should read all of the entries upon module loading to simplify the logic in 
reading the hashes lazily. Reading the hashes lazily could be done but I doubt 
its worth the complexity of the implementation at that stage.

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-03 Thread Vassil Vassilev via cfe-commits


@@ -603,21 +606,30 @@ class ASTReader
   llvm::DenseMap Lookups;
 
+  /// Map from decls to specialized decls.
+  llvm::DenseMap
+  SpecializationsLookups;

vgvassilev wrote:

We should probably have a mapping between a template argument hash -> vector of 
DeclIDs.


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


[clang] [clang][CodeGen][UBSan] Fixing shift-exponent generation for _BitInt (PR #80515)

2024-02-03 Thread John McCall via cfe-commits

rjmccall wrote:

> One thing I'll preemptively address is I didn't know where to put the new 
> unit testing - creating a separate file seems a little heavy handed but I see 
> that there's a test for UBSan shift generation 
> (`clang/test/CodeGen/ubsan-shift.c`) and one for UBSan + _BitInt 
> (`clang/test/CodeGen/ext-int-sanitizer.cpp`). Both seem equally "valid" but 
> neither seem to test in the same way that I'm trying to test these changes. 
> Advice on this would be appreciated.

Either one is fine as long as you aren't having to narrow the portability of a 
test case in order to use `_BitInt` in it.

Patch generally LGTM.

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


[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-03 Thread Liviu Ionescu via cfe-commits

ilg-ul wrote:

> they change the behaviour you introduced in 
> https://github.com/llvm/llvm-project/pull/70817 when -isysroot is provided.

I need to take a closer look, since at first reading I can't evaluate the 
consequences, especially if this does change the behaviour when -isysroot is 
**not** provided.

And I do not know exactly the use case you are considering. My use case was 
relatively straightforward, multiple versions of the toolchain are installed in 
versioned custom folders in user home, and different projects requiring 
different toolchain versions have symbolic links from the project folder to one 
of the clang executable.

If your change does not affect the above use case and also adds more 
consistency with Apple clang, it should be fine.


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


[mlir] [clang] [flang] [libcxx] [llvm] [clang-tools-extra] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-03 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78304

>From 9846f970b6b394ccc3af25b92f238377a8ae7807 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sun, 14 Jan 2024 18:06:36 +
Subject: [PATCH 1/2] [LV] Improve AnyOf reduction codegen.

Update AnyOf reduction code generation to only keep track of the AnyOf
property in a boolean vector in the loop, only selecting either the new
or start value in the middle block.

This fixes the #62565, as now there aren't multiple uses of the
start/new values.

Fixes https://github.com/llvm/llvm-project/issues/62565
---
 .../include/llvm/Transforms/Utils/LoopUtils.h |   9 --
 llvm/lib/Transforms/Utils/LoopUtils.cpp   |  24 +--
 .../Vectorize/LoopVectorizationPlanner.h  |   1 +
 .../Transforms/Vectorize/LoopVectorize.cpp|  44 +-
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |   7 +-
 .../LoopVectorize/AArch64/sve-select-cmp.ll   |  38 ++---
 .../RISCV/select-cmp-reduction.ll | 120 ++
 .../LoopVectorize/select-cmp-predicated.ll|  29 ++--
 .../Transforms/LoopVectorize/select-cmp.ll| 146 +-
 ...tion-start-value-may-be-undef-or-poison.ll |  43 +++---
 10 files changed, 218 insertions(+), 243 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h 
b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
index 5a1385d01d8e4..3bad7b616d9d7 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -363,15 +363,6 @@ Intrinsic::ID getMinMaxReductionIntrinsicOp(RecurKind RK);
 /// Returns the comparison predicate used when expanding a min/max reduction.
 CmpInst::Predicate getMinMaxReductionPredicate(RecurKind RK);
 
-/// See RecurrenceDescriptor::isAnyOfPattern for a description of the pattern 
we
-/// are trying to match. In this pattern, we are only ever selecting between 
two
-/// values: 1) an initial start value \p StartVal of the reduction PHI, and 2) 
a
-/// loop invariant value. If any of lane value in \p Left, \p Right is not 
equal
-/// to \p StartVal, select the loop invariant value. This is done by selecting
-/// \p Right iff \p Left is equal to \p StartVal.
-Value *createAnyOfOp(IRBuilderBase &Builder, Value *StartVal, RecurKind RK,
- Value *Left, Value *Right);
-
 /// Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
 /// The Builder's fast-math-flags must be set to propagate the expected values.
 Value *createMinMaxOp(IRBuilderBase &Builder, RecurKind RK, Value *Left,
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp 
b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 59485126b280a..c0582fb7d7e15 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -962,15 +962,6 @@ CmpInst::Predicate 
llvm::getMinMaxReductionPredicate(RecurKind RK) {
   }
 }
 
-Value *llvm::createAnyOfOp(IRBuilderBase &Builder, Value *StartVal,
-   RecurKind RK, Value *Left, Value *Right) {
-  if (auto VTy = dyn_cast(Left->getType()))
-StartVal = Builder.CreateVectorSplat(VTy->getElementCount(), StartVal);
-  Value *Cmp =
-  Builder.CreateCmp(CmpInst::ICMP_NE, Left, StartVal, "rdx.select.cmp");
-  return Builder.CreateSelect(Cmp, Left, Right, "rdx.select");
-}
-
 Value *llvm::createMinMaxOp(IRBuilderBase &Builder, RecurKind RK, Value *Left,
 Value *Right) {
   Type *Ty = Left->getType();
@@ -1079,16 +1070,13 @@ Value *llvm::createAnyOfTargetReduction(IRBuilderBase 
&Builder, Value *Src,
 NewVal = SI->getTrueValue();
   }
 
-  // Create a splat vector with the new value and compare this to the vector
-  // we want to reduce.
-  ElementCount EC = cast(Src->getType())->getElementCount();
-  Value *Right = Builder.CreateVectorSplat(EC, InitVal);
-  Value *Cmp =
-  Builder.CreateCmp(CmpInst::ICMP_NE, Src, Right, "rdx.select.cmp");
-
   // If any predicate is true it means that we want to select the new value.
-  Cmp = Builder.CreateOrReduce(Cmp);
-  return Builder.CreateSelect(Cmp, NewVal, InitVal, "rdx.select");
+  Value *AnyOf =
+  Src->getType()->isVectorTy() ? Builder.CreateOrReduce(Src) : Src;
+  // The compares in the loop may yield poison, which propagates through the
+  // bitwise ORs. Freeze it here before the condition is used.
+  AnyOf = Builder.CreateFreeze(AnyOf);
+  return Builder.CreateSelect(AnyOf, NewVal, InitVal, "rdx.select");
 }
 
 Value *llvm::createSimpleTargetReduction(IRBuilderBase &Builder, Value *Src,
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h 
b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
index a7ebf78e54ceb..9d3ef5b96c72f 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
@@ -68,6 +68,7 @@ class VPBuilder {
 public:
   VPBuilder() = default;
   VPBuilder(VPBasicBlock *InsertBB) { setInsertPoint(InsertBB); }
+  VPBuilder(VPRecipeBase *Ins

[clang] [clang] Add GCC-compatible code model names for sparc64 (PR #79485)

2024-02-03 Thread Fangrui Song via cfe-commits

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


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


[clang] [clang] Add GCC-compatible code model names for sparc64 (PR #79485)

2024-02-03 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> > I'd run 2-stage builds/tests (either with the existing machinery or by 
> > building LLVM twice explicitly: once with an external compiler and then 
> > again with the just-built one).
> 
> It does seem that at least when it comes to LLVM itself, 2-stage build/tests 
> works okay under all of the supported code models...

Can you edit the description (first comment) to include your testing?

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


[clang] [clang][AMDGPU][CUDA] Handle __builtin_printf for device printf (PR #68515)

2024-02-03 Thread Mészáros Gergely via cfe-commits

Maetveis wrote:

@jlebar @yxsamliu I don't know who could review this, but it is sitting here 
for quite some time unnoticed now, while being a simple enough change IMO.

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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-02-03 Thread Justin Hibbits via cfe-commits

chmeeedalf wrote:

> ping! @chmeeedalf @nemanjai

I know nothing about the complex ABI, so all I can say is the code looks okay 
from a structural point, can't say anything to the logic.

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


[clang] Frontend: sink vendor definitions from Basic to Frontend (PR #80364)

2024-02-03 Thread Kuba Mracek via cfe-commits


@@ -804,6 +804,11 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 }
   }
 
+  if (TI.getTriple().getVendor() == Triple::AMD)
+Builder.defineMacro("__AMD__");
+  if (TI.getTriple().getVendor() == Triple::Apple)
+Builder.defineMacro("__APPLE__");

kubamracek wrote:

👍 

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


[clang] [clang-format] Add Leave to AlwaysBreakTemplateDeclarations (PR #80569)

2024-02-03 Thread Owen Pan via cfe-commits

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

Now with a8279a8bc541, we can make the update.

>From 45b720cbda6b08ca55b7d131bb0541f38f36e7c9 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 3 Feb 2024 16:01:49 -0800
Subject: [PATCH] [clang-format] Add Leave to AlwaysBreakTemplateDeclarations

Closes #78067.
---
 clang/docs/ClangFormatStyleOptions.rst | 12 
 clang/include/clang/Format/Format.h| 10 +++
 clang/lib/Format/ContinuationIndenter.cpp  |  5 +-
 clang/lib/Format/Format.cpp|  1 +
 clang/lib/Format/TokenAnnotator.cpp|  4 +-
 clang/unittests/Format/ConfigParseTest.cpp |  2 +
 clang/unittests/Format/FormatTest.cpp  | 78 ++
 7 files changed, 110 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0b887288fe2cb..5e23b16fa5910 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1638,6 +1638,18 @@ the configuration (without a prefix: ``Auto``).
 
   Possible values:
 
+  * ``BTDS_Leave`` (in configuration: ``Leave``)
+Do not change the line breaking before the declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
   * ``BTDS_No`` (in configuration: ``No``)
 Do not force break before declaration.
 ``PenaltyBreakTemplateDeclaration`` is taken into account.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index efcb4e1d87ea4..0328854d83165 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1008,6 +1008,16 @@ struct FormatStyle {
 
   /// Different ways to break after the template declaration.
   enum BreakTemplateDeclarationsStyle : int8_t {
+/// Do not change the line breaking before the declaration.
+/// \code
+///template 
+///T foo() {
+///}
+///template  T foo(int a,
+///int b) {
+///}
+/// \endcode
+BTDS_Leave,
 /// Do not force break before declaration.
 /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
 /// \code
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index a3eb9138b2183..a4e4b7ace684d 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -561,7 +561,10 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   return true;
 }
   }
-  return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No;
+  return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No &&
+ (Style.AlwaysBreakTemplateDeclarations !=
+  FormatStyle::BTDS_Leave ||
+  Current.NewlinesBefore > 0);
 }
 if (Previous.is(TT_FunctionAnnotationRParen) &&
 State.Line->Type != LT_PreprocessorDirective) {
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 10fe35c79a4f2..7ffc73ca6629e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -296,6 +296,7 @@ template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO,
   FormatStyle::BreakTemplateDeclarationsStyle &Value) {
+IO.enumCase(Value, "Leave", FormatStyle::BTDS_Leave);
 IO.enumCase(Value, "No", FormatStyle::BTDS_No);
 IO.enumCase(Value, "MultiLine", FormatStyle::BTDS_MultiLine);
 IO.enumCase(Value, "Yes", FormatStyle::BTDS_Yes);
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d0c4273cfc7e5..fd02faf85fede 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5182,7 +5182,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 // concept ...
 if (Right.is(tok::kw_concept))
   return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
-return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes;
+return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes ||
+   (Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Leave &&
+Right.NewlinesBefore > 0);
   }
   if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
 switch (Style.RequiresClausePosition) {
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 6436581ddae5a..d32acd2bd32dc 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -691,6 +691,8 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   FormatStyle::RTBS_TopLevelDefinitions);
 
   Style.AlwaysBreakTemplateDecl

[clang] [clang-format] Add Leave to AlwaysBreakTemplateDeclarations (PR #80569)

2024-02-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Now with a8279a8bc541, we can make the update.

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


7 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+12) 
- (modified) clang/include/clang/Format/Format.h (+10) 
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+4-1) 
- (modified) clang/lib/Format/Format.cpp (+1) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+3-1) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+2) 
- (modified) clang/unittests/Format/FormatTest.cpp (+78) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0b887288fe2cb..5e23b16fa5910 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1638,6 +1638,18 @@ the configuration (without a prefix: ``Auto``).
 
   Possible values:
 
+  * ``BTDS_Leave`` (in configuration: ``Leave``)
+Do not change the line breaking before the declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
   * ``BTDS_No`` (in configuration: ``No``)
 Do not force break before declaration.
 ``PenaltyBreakTemplateDeclaration`` is taken into account.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index efcb4e1d87ea4..0328854d83165 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1008,6 +1008,16 @@ struct FormatStyle {
 
   /// Different ways to break after the template declaration.
   enum BreakTemplateDeclarationsStyle : int8_t {
+/// Do not change the line breaking before the declaration.
+/// \code
+///template 
+///T foo() {
+///}
+///template  T foo(int a,
+///int b) {
+///}
+/// \endcode
+BTDS_Leave,
 /// Do not force break before declaration.
 /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
 /// \code
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index a3eb9138b2183..a4e4b7ace684d 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -561,7 +561,10 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   return true;
 }
   }
-  return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No;
+  return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No &&
+ (Style.AlwaysBreakTemplateDeclarations !=
+  FormatStyle::BTDS_Leave ||
+  Current.NewlinesBefore > 0);
 }
 if (Previous.is(TT_FunctionAnnotationRParen) &&
 State.Line->Type != LT_PreprocessorDirective) {
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 10fe35c79a4f2..7ffc73ca6629e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -296,6 +296,7 @@ template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO,
   FormatStyle::BreakTemplateDeclarationsStyle &Value) {
+IO.enumCase(Value, "Leave", FormatStyle::BTDS_Leave);
 IO.enumCase(Value, "No", FormatStyle::BTDS_No);
 IO.enumCase(Value, "MultiLine", FormatStyle::BTDS_MultiLine);
 IO.enumCase(Value, "Yes", FormatStyle::BTDS_Yes);
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d0c4273cfc7e5..fd02faf85fede 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5182,7 +5182,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 // concept ...
 if (Right.is(tok::kw_concept))
   return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
-return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes;
+return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes ||
+   (Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Leave &&
+Right.NewlinesBefore > 0);
   }
   if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
 switch (Style.RequiresClausePosition) {
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 6436581ddae5a..d32acd2bd32dc 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -691,6 +691,8 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   FormatStyle::RTBS_TopLevelDefinitions);
 
   Style.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes;
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: Leave",
+  AlwaysBreakTemplateDeclarations, Format

[clang] [clang-format] Add Leave to AlwaysBreakTemplateDeclarations (PR #80569)

2024-02-03 Thread Owen Pan via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [clang] reject to capture variable in `RequiresExprBodyDecl` (PR #78598)

2024-02-03 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

ping @erichkeane @cor3ntin 

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


[llvm] [clang-tools-extra] [mlir] [libc] [libcxx] [lldb] [libcxxabi] [clang] [lld] [compiler-rt] [flang] [Mips] Fix unable to handle inline assembly ends with compat-branch o… (PR #77291)

2024-02-03 Thread via cfe-commits

yingopq wrote:

@MaskRay 
Hi, this issue is https://reviews.llvm.org/D158589, which you have reviewed 
before.
Could you help review this patch at your convenience? Thanks.

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


[llvm] [clang-tools-extra] [mlir] [libc] [libcxx] [lldb] [libcxxabi] [clang] [lld] [compiler-rt] [flang] [Mips] Fix unable to handle inline assembly ends with compat-branch o… (PR #77291)

2024-02-03 Thread Jessica Clarke via cfe-commits

jrtc27 wrote:

What assembly does GCC emit, and how does GNU as deal with that assembly? That 
is, how do those two tools interact in the GNU world when dealing with 
forbidden slots?

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


[clang] [llvm] [Clang][CMake] Add CSSPGO support to LLVM_BUILD_INSTRUMENTED (PR #79942)

2024-02-03 Thread Amir Ayupov via cfe-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/79942

>From cb724ca7d7740e828934c6527ca188cfbbb78c0c Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Wed, 19 Jul 2023 20:30:29 -0700
Subject: [PATCH] [Clang][CMake] Add CSSPGO support to LLVM_BUILD_INSTRUMENTED

Build on Clang-BOLT infrastructure to collect sample profiles for CSSPGO.
Add clang/cmake/caches/CSSPGO.cmake to automate CSSPGO Clang build.

Differential Revision: https://reviews.llvm.org/D155419
---
 clang/CMakeLists.txt   | 12 -
 clang/cmake/caches/CSSPGO.cmake|  3 ++
 clang/utils/perf-training/CMakeLists.txt   | 51 
 clang/utils/perf-training/lit.cfg  |  6 +++
 clang/utils/perf-training/lit.site.cfg.in  |  1 +
 clang/utils/perf-training/perf-helper.py   | 56 ++
 llvm/CMakeLists.txt|  3 ++
 llvm/cmake/modules/HandleLLVMOptions.cmake | 26 +-
 8 files changed, 137 insertions(+), 21 deletions(-)
 create mode 100644 clang/cmake/caches/CSSPGO.cmake

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 47fc2e4886cfc..5d16442ac7bc3 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -741,11 +741,21 @@ if (CLANG_ENABLE_BOOTSTRAP)
   if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps llvm-profdata)
 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
+string(TOUPPER "${BOOTSTRAP_LLVM_BUILD_INSTRUMENTED}" 
BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
+if (BOOTSTRAP_LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  add_dependencies(clang-bootstrap-deps llvm-profgen)
+  list(APPEND PGO_OPT 
-DLLVM_PROFGEN=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profgen)
+endif()
   endif()
 
   if(LLVM_BUILD_INSTRUMENTED)
+string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps generate-profdata)
-set(PGO_OPT 
-DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+if (LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  set(PGO_OPT 
-DLLVM_SPROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+else()
+  set(PGO_OPT 
-DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+endif()
 # Use the current tools for LTO instead of the instrumented ones
 list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
   CMAKE_CXX_COMPILER
diff --git a/clang/cmake/caches/CSSPGO.cmake b/clang/cmake/caches/CSSPGO.cmake
new file mode 100644
index 0..34159068d5ea3
--- /dev/null
+++ b/clang/cmake/caches/CSSPGO.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED "CSSPGO" CACHE STRING "")
+include(${CMAKE_CURRENT_LIST_DIR}/PGO.cmake)
diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index 61df987da7139..a136753f7b2ff 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -12,14 +12,49 @@ if(LLVM_BUILD_INSTRUMENTED)
 ${CMAKE_CURRENT_BINARY_DIR}/pgo-data/lit.site.cfg
 )
 
-  add_lit_testsuite(generate-profraw "Generating clang PGO data"
+  # Dependencies of generate-profraw-* targets
+  add_custom_target(generate-profraw-deps
+DEPENDS clang clear-profraw ${CLANG_PGO_TRAINING_DEPS})
+  add_lit_testsuite(generate-profraw-intree "Generating clang PGO data"
 ${CMAKE_CURRENT_BINARY_DIR}/pgo-data/
 EXCLUDE_FROM_CHECK_ALL
-DEPENDS clang clear-profraw ${CLANG_PGO_TRAINING_DEPS}
+DEPENDS generate-profraw-deps
 )
+  add_custom_target(generate-profraw DEPENDS generate-profraw-intree)
+  if (CLANG_PGO_TRAINING_DATA_SOURCE_DIR)
+llvm_ExternalProject_Add(generate-profraw-external 
${CLANG_PGO_TRAINING_DATA_SOURCE_DIR}
+USE_TOOLCHAIN EXLUDE_FROM_ALL NO_INSTALL
+DEPENDS generate-profraw-deps)
+add_dependencies(generate-profraw generate-profraw-external)
+  endif()
+
+  add_custom_target(generate-profdata-deps)
+  string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" LLVM_BUILD_INSTRUMENTED)
+  if (LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+set(PROFDATA_SAMPLE "--sample")
+if(NOT LLVM_PROFGEN)
+  find_program(LLVM_PROFGEN llvm-profgen)
+endif()
+
+if(NOT LLVM_PROFGEN)
+  message(STATUS "To enable converting CSSPGO samples LLVM_PROFGEN has to 
point to llvm-profgen")
+endif()
+
+# Convert perf profiles into profraw
+add_custom_target(convert-perf-profraw
+  COMMAND "${Python3_EXECUTABLE}"
+  ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py perf2prof ${LLVM_PROFGEN}
+  $ ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/
+  COMMENT "Converting perf profiles into profraw"
+  DEPENDS generate-profraw)
+add_dependencies(generate-profdata-deps convert-perf-profraw)
+  else()
+add_dependencies(generate-profdata-deps generate-profraw)
+  endif()
 
   add_cus

[llvm] [clang] [polly] [X86] Remove Intel Xeon Phi Supports. (PR #76383)

2024-02-03 Thread Freddy Ye via cfe-commits

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


[llvm] [polly] [clang] [X86] Remove Intel Xeon Phi Supports. (PR #76383)

2024-02-03 Thread Freddy Ye via cfe-commits

FreddyLeaf wrote:

> @FreddyLeaf Can this be abandoned now?

sure

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


[clang] a3d8b78 - [Clang][CodeGen] Mark `__dynamic_cast` as `willreturn` (#80409)

2024-02-03 Thread via cfe-commits

Author: Yingwei Zheng
Date: 2024-02-04T11:31:50+08:00
New Revision: a3d8b78333b80b47209ad0dc8f8159d70c7fcb39

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

LOG: [Clang][CodeGen] Mark `__dynamic_cast` as `willreturn` (#80409)

According to the C++ standard, `dynamic_cast` of pointers either returns
a pointer (7.6.1.7) or results in undefined behavior (11.9.5). This
patch marks `__dynamic_cast` as `willreturn` to remove unused calls.

Fixes #77606.

Added: 
clang/test/CodeGenCXX/dynamic-cast-dead.cpp

Modified: 
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
clang/test/CodeGenCXX/dynamic-cast.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index d173806ec8ce5..60b45ee78d931 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1347,9 +1347,10 @@ static llvm::FunctionCallee 
getItaniumDynamicCastFn(CodeGenFunction &CGF) {
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
 
-  // Mark the function as nounwind readonly.
+  // Mark the function as nounwind willreturn readonly.
   llvm::AttrBuilder FuncAttrs(CGF.getLLVMContext());
   FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
+  FuncAttrs.addAttribute(llvm::Attribute::WillReturn);
   FuncAttrs.addMemoryAttr(llvm::MemoryEffects::readOnly());
   llvm::AttributeList Attrs = llvm::AttributeList::get(
   CGF.getLLVMContext(), llvm::AttributeList::FunctionIndex, FuncAttrs);

diff  --git a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp 
b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
index c278988c9647b..83a408984b760 100644
--- a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
+++ b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -20,5 +20,5 @@ const B& f(A *a) {
 
 // CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), 
i64) [[NUW_RO:#[0-9]+]]
 
-// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NUW_RO]] = { nounwind willreturn memory(read) }
 // CHECK: attributes [[NR]] = { noreturn }

diff  --git a/clang/test/CodeGenCXX/dynamic-cast-dead.cpp 
b/clang/test/CodeGenCXX/dynamic-cast-dead.cpp
new file mode 100644
index 0..8154cc1ba123a
--- /dev/null
+++ b/clang/test/CodeGenCXX/dynamic-cast-dead.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -I%S %s -O3 -triple x86_64-apple-darwin10 -emit-llvm 
-fcxx-exceptions -fexceptions -std=c++11 -o - | FileCheck %s
+struct A { virtual ~A(); };
+struct B : A { };
+
+void foo(A* a) {
+  // CHECK-NOT: call {{.*}} @__dynamic_cast
+  B* b = dynamic_cast(a);
+}

diff  --git a/clang/test/CodeGenCXX/dynamic-cast.cpp 
b/clang/test/CodeGenCXX/dynamic-cast.cpp
index 1d36376a55bc7..b39186c85b60a 100644
--- a/clang/test/CodeGenCXX/dynamic-cast.cpp
+++ b/clang/test/CodeGenCXX/dynamic-cast.cpp
@@ -20,5 +20,5 @@ const B& f(A *a) {
 
 // CHECK: declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) [[NUW_RO:#[0-9]+]]
 
-// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NUW_RO]] = { nounwind willreturn memory(read) }
 // CHECK: attributes [[NR]] = { noreturn }



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


[clang] [Clang][CodeGen] Mark `__dynamic_cast` as `willreturn` (PR #80409)

2024-02-03 Thread Yingwei Zheng via cfe-commits

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


[clang] Frontend: sink vendor definitions from Basic to Frontend (PR #80364)

2024-02-03 Thread Saleem Abdulrasool via cfe-commits

https://github.com/compnerd updated 
https://github.com/llvm/llvm-project/pull/80364

>From 2bff496bd1b3c1bc5177f5072c2c7b8a4db54f14 Mon Sep 17 00:00:00 2001
From: Saleem Abdulrasool 
Date: Thu, 1 Feb 2024 15:37:39 -0800
Subject: [PATCH] Frontend: sink vendor definitions from Basic to Frontend

The vendor specific macro definitions are based on the vendor rather
than the target specific information. This ensures that `__APPLE__` is
always defined for `*-apple-*` targets. Take the opportunity to do
likewise with the `__AMD__` vendor macro.
---
 clang/lib/Basic/Targets/AMDGPU.cpp  | 1 -
 clang/lib/Basic/Targets/OSTargets.cpp   | 1 -
 clang/lib/Frontend/InitPreprocessor.cpp | 5 +
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 141501e8a4d9a..c6d68f591a5a8 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -266,7 +266,6 @@ ArrayRef 
AMDGPUTargetInfo::getTargetBuiltins() const {
 
 void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const {
-  Builder.defineMacro("__AMD__");
   Builder.defineMacro("__AMDGPU__");
 
   if (isAMDGCN(getTriple()))
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 899aefa6173ac..64b4514ba55bb 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -23,7 +23,6 @@ void getDarwinDefines(MacroBuilder &Builder, const 
LangOptions &Opts,
   const llvm::Triple &Triple, StringRef &PlatformName,
   VersionTuple &PlatformMinVersion) {
   Builder.defineMacro("__APPLE_CC__", "6000");
-  Builder.defineMacro("__APPLE__");
   Builder.defineMacro("__STDC_NO_THREADS__");
 
   // AddressSanitizer doesn't play well with source fortification, which is on
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 877e205e2e9bf..27621ee332419 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -804,6 +804,11 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 }
   }
 
+  if (TI.getTriple().getVendor() == Triple::AMD)
+Builder.defineMacro("__AMD__");
+  if (TI.getTriple().getVendor() == Triple::Apple)
+Builder.defineMacro("__APPLE__");
+
   // Define macros for the C11 / C++11 memory orderings
   Builder.defineMacro("__ATOMIC_RELAXED", "0");
   Builder.defineMacro("__ATOMIC_CONSUME", "1");

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


[clang] [clang][AMDGPU][CUDA] Handle __builtin_printf for device printf (PR #68515)

2024-02-03 Thread Justin Lebar via cfe-commits

jlebar wrote:

It looks reasonable to me, although I'm not really an AMDGPU person.  /me 
summons @arsenm ?

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


[clang] [clang] Add GCC-compatible code model names for sparc64 (PR #79485)

2024-02-03 Thread via cfe-commits

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


[clang] [clang] Add GCC-compatible code model names for sparc64 (PR #79485)

2024-02-03 Thread via cfe-commits

koachan wrote:

> Can you edit the description (first comment) to mention your testing?

Done, and thanks!

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


[clang] [clang] Add GCC-compatible code model names for sparc64 (PR #79485)

2024-02-03 Thread via cfe-commits

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


[clang] b0f0bab - [clang] Add GCC-compatible code model names for sparc64

2024-02-03 Thread via cfe-commits

Author: Koakuma
Date: 2024-02-04T11:08:00+07:00
New Revision: b0f0babff22e9c0af74535b05e2c6424392bb24a

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

LOG: [clang] Add GCC-compatible code model names for sparc64

This adds GCC-compatible names for code model selection on 64-bit SPARC
with absolute code.
Testing with a 2-stage build then running codegen tests works okay under
all of the supported code models.

(32-bit target does not have selectable code models)

Reviewed By: @brad0, @MaskRay

Added: 
clang/test/Driver/sparc64-codemodel.c

Modified: 
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 7009248bc4f02..46595852b1d80 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5781,6 +5781,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // NVPTX/AMDGPU does not care about the code model and will accept
   // whatever works for the host.
   Ok = true;
+} else if (Triple.isSPARC64()) {
+  if (CM == "medlow")
+CM = "small";
+  else if (CM == "medmid")
+CM = "medium";
+  else if (CM == "medany")
+CM = "large";
+  Ok = CM == "small" || CM == "medium" || CM == "large";
 }
 if (Ok) {
   CmdArgs.push_back(Args.MakeArgString("-mcmodel=" + CM));

diff  --git a/clang/test/Driver/sparc64-codemodel.c 
b/clang/test/Driver/sparc64-codemodel.c
new file mode 100644
index 0..e4b01fd61b6fa
--- /dev/null
+++ b/clang/test/Driver/sparc64-codemodel.c
@@ -0,0 +1,6 @@
+// RUN: %clang --target=sparc64 -mcmodel=medlow %s -### 2>&1 | FileCheck 
-check-prefix=MEDLOW %s
+// RUN: %clang --target=sparc64 -mcmodel=medmid %s -### 2>&1 | FileCheck 
-check-prefix=MEDMID %s
+// RUN: %clang --target=sparc64 -mcmodel=medany %s -### 2>&1 | FileCheck 
-check-prefix=MEDANY %s
+// MEDLOW: "-mcmodel=small"
+// MEDMID: "-mcmodel=medium"
+// MEDANY: "-mcmodel=large"



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


[llvm] [clang] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2024-02-03 Thread via cfe-commits

koachan wrote:

Ping?

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


[clang] [clang-format] Add Leave to AlwaysBreakTemplateDeclarations (PR #80569)

2024-02-03 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/80569

>From 4ce4a4ff922f393398bf62746fc59749f1679247 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 3 Feb 2024 16:01:49 -0800
Subject: [PATCH] [clang-format] Add Leave to AlwaysBreakTemplateDeclarations

Closes #78067.
---
 clang/docs/ClangFormatStyleOptions.rst | 12 
 clang/include/clang/Format/Format.h| 10 +++
 clang/lib/Format/ContinuationIndenter.cpp  |  5 +-
 clang/lib/Format/Format.cpp|  1 +
 clang/lib/Format/TokenAnnotator.cpp| 10 ++-
 clang/unittests/Format/ConfigParseTest.cpp |  2 +
 clang/unittests/Format/FormatTest.cpp  | 78 ++
 7 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0b887288fe2cb..5e23b16fa5910 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1638,6 +1638,18 @@ the configuration (without a prefix: ``Auto``).
 
   Possible values:
 
+  * ``BTDS_Leave`` (in configuration: ``Leave``)
+Do not change the line breaking before the declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
   * ``BTDS_No`` (in configuration: ``No``)
 Do not force break before declaration.
 ``PenaltyBreakTemplateDeclaration`` is taken into account.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index efcb4e1d87ea4..0328854d83165 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1008,6 +1008,16 @@ struct FormatStyle {
 
   /// Different ways to break after the template declaration.
   enum BreakTemplateDeclarationsStyle : int8_t {
+/// Do not change the line breaking before the declaration.
+/// \code
+///template 
+///T foo() {
+///}
+///template  T foo(int a,
+///int b) {
+///}
+/// \endcode
+BTDS_Leave,
 /// Do not force break before declaration.
 /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
 /// \code
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index a3eb9138b2183..a4e4b7ace684d 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -561,7 +561,10 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   return true;
 }
   }
-  return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No;
+  return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No &&
+ (Style.AlwaysBreakTemplateDeclarations !=
+  FormatStyle::BTDS_Leave ||
+  Current.NewlinesBefore > 0);
 }
 if (Previous.is(TT_FunctionAnnotationRParen) &&
 State.Line->Type != LT_PreprocessorDirective) {
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 10fe35c79a4f2..7ffc73ca6629e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -296,6 +296,7 @@ template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO,
   FormatStyle::BreakTemplateDeclarationsStyle &Value) {
+IO.enumCase(Value, "Leave", FormatStyle::BTDS_Leave);
 IO.enumCase(Value, "No", FormatStyle::BTDS_No);
 IO.enumCase(Value, "MultiLine", FormatStyle::BTDS_MultiLine);
 IO.enumCase(Value, "Yes", FormatStyle::BTDS_Yes);
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d0c4273cfc7e5..0aa2db7e7ecfa 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5182,7 +5182,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 // concept ...
 if (Right.is(tok::kw_concept))
   return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
-return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes;
+return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes ||
+   (Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Leave &&
+Right.NewlinesBefore > 0);
   }
   if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
 switch (Style.RequiresClausePosition) {
@@ -5615,7 +5617,11 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine 
&Line,
 return Style.BreakBeforeConceptDeclarations != FormatStyle::BBCDS_Never;
   if (Right.is(TT_RequiresClause))
 return true;
-  if (Left.ClosesTemplateDeclaration || Left.is(TT_FunctionAnnotationRParen))
+  if (Left.ClosesTemplateDeclaration) {
+return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_Leave ||
+   Right.Newlin

[clang] [clang-format] Add Leave to AlwaysBreakTemplateDeclarations (PR #80569)

2024-02-03 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/80569

>From 89ab06f93817a6d0e68f0549cae8836e6fd17612 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 3 Feb 2024 16:01:49 -0800
Subject: [PATCH] [clang-format] Add Leave to AlwaysBreakTemplateDeclarations

Closes #78067.
---
 clang/docs/ClangFormatStyleOptions.rst | 12 
 clang/include/clang/Format/Format.h| 10 
 clang/lib/Format/ContinuationIndenter.cpp  |  5 +-
 clang/lib/Format/Format.cpp|  1 +
 clang/lib/Format/TokenAnnotator.cpp| 10 +++-
 clang/unittests/Format/ConfigParseTest.cpp |  2 +
 clang/unittests/Format/FormatTest.cpp  | 68 ++
 7 files changed, 105 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0b887288fe2cb..5e23b16fa5910 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1638,6 +1638,18 @@ the configuration (without a prefix: ``Auto``).
 
   Possible values:
 
+  * ``BTDS_Leave`` (in configuration: ``Leave``)
+Do not change the line breaking before the declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
   * ``BTDS_No`` (in configuration: ``No``)
 Do not force break before declaration.
 ``PenaltyBreakTemplateDeclaration`` is taken into account.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index efcb4e1d87ea4..0328854d83165 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1008,6 +1008,16 @@ struct FormatStyle {
 
   /// Different ways to break after the template declaration.
   enum BreakTemplateDeclarationsStyle : int8_t {
+/// Do not change the line breaking before the declaration.
+/// \code
+///template 
+///T foo() {
+///}
+///template  T foo(int a,
+///int b) {
+///}
+/// \endcode
+BTDS_Leave,
 /// Do not force break before declaration.
 /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
 /// \code
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index a3eb9138b2183..a4e4b7ace684d 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -561,7 +561,10 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   return true;
 }
   }
-  return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No;
+  return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No &&
+ (Style.AlwaysBreakTemplateDeclarations !=
+  FormatStyle::BTDS_Leave ||
+  Current.NewlinesBefore > 0);
 }
 if (Previous.is(TT_FunctionAnnotationRParen) &&
 State.Line->Type != LT_PreprocessorDirective) {
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 10fe35c79a4f2..7ffc73ca6629e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -296,6 +296,7 @@ template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO,
   FormatStyle::BreakTemplateDeclarationsStyle &Value) {
+IO.enumCase(Value, "Leave", FormatStyle::BTDS_Leave);
 IO.enumCase(Value, "No", FormatStyle::BTDS_No);
 IO.enumCase(Value, "MultiLine", FormatStyle::BTDS_MultiLine);
 IO.enumCase(Value, "Yes", FormatStyle::BTDS_Yes);
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d0c4273cfc7e5..0aa2db7e7ecfa 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5182,7 +5182,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 // concept ...
 if (Right.is(tok::kw_concept))
   return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
-return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes;
+return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes ||
+   (Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Leave &&
+Right.NewlinesBefore > 0);
   }
   if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
 switch (Style.RequiresClausePosition) {
@@ -5615,7 +5617,11 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine 
&Line,
 return Style.BreakBeforeConceptDeclarations != FormatStyle::BBCDS_Never;
   if (Right.is(TT_RequiresClause))
 return true;
-  if (Left.ClosesTemplateDeclaration || Left.is(TT_FunctionAnnotationRParen))
+  if (Left.ClosesTemplateDeclaration) {
+return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_Leave ||
+   Right.Newl

[clang-tools-extra] [llvm] [clang] [GlobalISel][ARM] Legalze set_fpenv and get_fpenv (PR #79852)

2024-02-03 Thread Serge Pavlov via cfe-commits

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

>From b0cd3a40ecaac9ca49c7a0e697ecdbe2b6c899e2 Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Mon, 29 Jan 2024 21:09:40 +0700
Subject: [PATCH 1/2] [GlobalISel][ARM] Legalze set_fpenv and get_fpenv

Implement handling of get/set floating point environment for ARM in
Global Instruction Selector. Lowering of these intrinsics to operations
on FPSCR was previously inplemented in DAG selector, in GlobalISel it
is reused.
---
 llvm/lib/Target/ARM/ARMLegalizerInfo.cpp|  8 +++
 llvm/lib/Target/ARM/ARMRegisterBankInfo.cpp |  8 +++
 llvm/test/CodeGen/ARM/GlobalISel/fpenv.ll   | 78 +
 3 files changed, 94 insertions(+)
 create mode 100644 llvm/test/CodeGen/ARM/GlobalISel/fpenv.ll

diff --git a/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp 
b/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
index abea0fef5cdc5..7bf44abf3fa8f 100644
--- a/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
@@ -193,6 +193,11 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) 
{
 .legalForCartesianProduct({s32}, {s32, s64});
 getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
 .legalForCartesianProduct({s32, s64}, {s32});
+
+getActionDefinitionsBuilder({G_GET_FPENV, G_SET_FPENV})
+  .legalFor({s32});
+getActionDefinitionsBuilder(G_RESET_FPENV)
+  .legalIf([=](const LegalityQuery &Query) { return true; });
   } else {
 getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV})
 .libcallFor({s32, s64});
@@ -219,6 +224,9 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) {
 .libcallForCartesianProduct({s32}, {s32, s64});
 getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
 .libcallForCartesianProduct({s32, s64}, {s32});
+
+getActionDefinitionsBuilder({G_GET_FPENV, G_SET_FPENV})
+.libcall();
   }
 
   // Just expand whatever loads and stores are left.
diff --git a/llvm/lib/Target/ARM/ARMRegisterBankInfo.cpp 
b/llvm/lib/Target/ARM/ARMRegisterBankInfo.cpp
index 746a8715df0a6..5d4ae9a7648e6 100644
--- a/llvm/lib/Target/ARM/ARMRegisterBankInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMRegisterBankInfo.cpp
@@ -469,6 +469,14 @@ ARMRegisterBankInfo::getInstrMapping(const MachineInstr 
&MI) const {
 OperandsMapping = getOperandsMapping(OperandBanks);
 break;
   }
+  case G_GET_FPENV:
+  case G_SET_FPENV:
+OperandsMapping =
+getOperandsMapping({&ARM::ValueMappings[ARM::GPR3OpsIdx], nullptr});
+break;
+  case G_RESET_FPENV:
+OperandsMapping = getOperandsMapping({nullptr});
+break;
   default:
 return getInvalidInstructionMapping();
   }
diff --git a/llvm/test/CodeGen/ARM/GlobalISel/fpenv.ll 
b/llvm/test/CodeGen/ARM/GlobalISel/fpenv.ll
new file mode 100644
index 0..3d18a65bd4345
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/GlobalISel/fpenv.ll
@@ -0,0 +1,78 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc -mtriple=arm-eabi -mattr=+vfp2 -global-isel=1 
--verify-machineinstrs %s -o - | FileCheck %s
+
+declare i32 @llvm.get.fpenv.i32()
+declare void @llvm.set.fpenv.i32(i32)
+declare void @llvm.reset.fpenv()
+
+define i32 @func_get_fpenv() {
+; CHECK-LABEL: func_get_fpenv:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmrs r0, fpscr
+; CHECK-NEXT:mov pc, lr
+entry:
+  %fpenv = call i32 @llvm.get.fpenv.i32()
+  ret i32 %fpenv
+}
+
+define i32 @func_get_fpenv_soft() #0 {
+; CHECK-LABEL: func_get_fpenv_soft:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:.save {r4, lr}
+; CHECK-NEXT:push {r4, lr}
+; CHECK-NEXT:.pad #8
+; CHECK-NEXT:sub sp, sp, #8
+; CHECK-NEXT:add r4, sp, #4
+; CHECK-NEXT:mov r0, r4
+; CHECK-NEXT:bl fegetenv
+; CHECK-NEXT:ldr r0, [r4]
+; CHECK-NEXT:add sp, sp, #8
+; CHECK-NEXT:pop {r4, lr}
+; CHECK-NEXT:mov pc, lr
+entry:
+  %fpenv = call i32 @llvm.get.fpenv.i32()
+  ret i32 %fpenv
+}
+
+define void @func_set_fpenv(i32 %fpenv) {
+; CHECK-LABEL: func_set_fpenv:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr fpscr, r0
+; CHECK-NEXT:mov pc, lr
+entry:
+  call void @llvm.set.fpenv.i32(i32 %fpenv)
+  ret void
+}
+
+define void @func_set_fpenv_soft(i32 %fpenv) #0 {
+; CHECK-LABEL: func_set_fpenv_soft:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:.save {r11, lr}
+; CHECK-NEXT:push {r11, lr}
+; CHECK-NEXT:.pad #8
+; CHECK-NEXT:sub sp, sp, #8
+; CHECK-NEXT:add r1, sp, #4
+; CHECK-NEXT:str r0, [r1]
+; CHECK-NEXT:mov r0, r1
+; CHECK-NEXT:bl fesetenv
+; CHECK-NEXT:add sp, sp, #8
+; CHECK-NEXT:pop {r11, lr}
+; CHECK-NEXT:mov pc, lr
+entry:
+  call void @llvm.set.fpenv.i32(i32 %fpenv)
+  ret void
+}
+
+define void @func_reset() {
+; CHECK-LABEL: func_reset:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:mov r0, #0
+; CHECK-NEXT:vmsr fpscr, r0
+; CHECK-NEXT:mov pc, lr
+entry:
+  call void @llvm.

[clang-tools-extra] [llvm] [clang] [GlobalISel][ARM] Legalze set_fpenv and get_fpenv (PR #79852)

2024-02-03 Thread Serge Pavlov via cfe-commits

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


[clang] 3c93c03 - [Basic] Use StringRef::ends_with (NFC)

2024-02-03 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-02-03T21:43:05-08:00
New Revision: 3c93c037c9ede2eaa0bdea6924c92d646ca0cfe5

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

LOG: [Basic] Use StringRef::ends_with (NFC)

Added: 


Modified: 
clang/lib/Basic/Targets/X86.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index c6fc17fcc1b70..1966af17904d6 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -139,7 +139,7 @@ bool X86TargetInfo::initFeatureMap(
 if (Feature.substr(1, 6) == "avx10.") {
   if (Feature[0] == '+') {
 HasAVX10 = true;
-if (Feature.substr(Feature.size() - 3, 3) == "512")
+if (StringRef(Feature).ends_with("512"))
   HasAVX10_512 = true;
 LastAVX10 = Feature;
   } else if (HasAVX10 && Feature == "-avx10.1-256") {



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


[clang] 34fba4f - [Basic] Use StringRef::contains (NFC)

2024-02-03 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-02-03T21:43:06-08:00
New Revision: 34fba4fb1e32f06237e5024373cc0163cecc3fd5

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

LOG: [Basic] Use StringRef::contains (NFC)

Added: 


Modified: 
clang/lib/Basic/Sarif.cpp

Removed: 




diff  --git a/clang/lib/Basic/Sarif.cpp b/clang/lib/Basic/Sarif.cpp
index 1cae7b937bc6e..8c144df341673 100644
--- a/clang/lib/Basic/Sarif.cpp
+++ b/clang/lib/Basic/Sarif.cpp
@@ -57,8 +57,7 @@ static std::string percentEncodeURICharacter(char C) {
   // should be written out directly. Otherwise, percent
   // encode the character and write that out instead of the
   // reserved character.
-  if (llvm::isAlnum(C) ||
-  StringRef::npos != StringRef("-._~:@!$&'()*+,;=").find(C))
+  if (llvm::isAlnum(C) || StringRef("-._~:@!$&'()*+,;=").contains(C))
 return std::string(&C, 1);
   return "%" + llvm::toHex(StringRef(&C, 1));
 }



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


  1   2   >