[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-04-09 Thread via cfe-commits

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


[clang] Rework the printing of attributes (PR #87281)

2024-04-09 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

And `final` as well as `override`? (This is why I'm not convinced we should be 
backporting anything -- the problem is with printing in general and will crop 
up in various places, so we're not really fixing a regression so much as 
playing whack-a-mole with a few cases.) 

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


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-09 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

This seems to have had an unexpected effect. In a build where I don't use the 
new path style, I used to get the old path style returned like this:
```
$ clang -target x86_64-w64-mingw32 -print-runtime-dir
/home/martin/clang-nightly/lib/clang/19/lib/windows
```
However after this change, now I'm getting the new style path, even if it 
doesn't exist, and if the old one actually did exist:
```
$ clang -target x86_64-w64-mingw32 -print-runtime-dir
/home/martin/clang-nignhtly/lib/clang/19/lib/x86_64-w64-windows-gnu
```
I'm ok with changing the default if the old path style doesn't exist - but if 
it does exist, we should still return that. (I haven't dig into it to see why 
this is, yet.)

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


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-09 Thread Aaron Ballman via cfe-commits

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

LGTM! Do you need someone to land this on your behalf?

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


[clang] Rework the printing of attributes (PR #87281)

2024-04-09 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Maybe you can open a PR against the branch?

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


[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)

2024-04-09 Thread Edwin Vane via cfe-commits

revane wrote:

Indeed. I can add some tests to make sure nested macros aren't affected but my 
thought was since this change allows renaming _arguments_ (i.e. not the macro 
parameters) then it was safe since the code is not really "inside a macro". 
There are already other means to filter out system headers and other 
user-defined headers. I couldn't come up with other classes of errors where 
this replacement would be invalid.

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


[clang] Rework the printing of attributes (PR #87281)

2024-04-09 Thread Giuliano Belinassi via cfe-commits

giulianobelinassi wrote:

We would like this fixed in 18.1 as well. We are expanding to support C++ and 
we will hit this bug at some point.

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


[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

2024-04-09 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/85786

>From 239b404203c66ab5336ffdfb45969a50c439a1c0 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Tue, 19 Mar 2024 06:22:17 -0700
Subject: [PATCH 01/10] [RISCV][FMV] Support target_clones

---
 clang/include/clang/Basic/TargetInfo.h|   3 +-
 clang/lib/AST/ASTContext.cpp  |   9 ++
 clang/lib/Basic/Targets/RISCV.cpp |  10 +-
 clang/lib/Basic/Targets/RISCV.h   |   2 +
 clang/lib/CodeGen/CodeGenFunction.cpp | 102 -
 clang/lib/CodeGen/CodeGenFunction.h   |   3 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   2 +
 clang/lib/CodeGen/Targets/RISCV.cpp   |  23 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  22 +++
 clang/test/CodeGen/attr-target-clones-riscv.c | 135 +
 .../CodeGenCXX/attr-target-clones-riscv.cpp   | 136 ++
 .../test/SemaCXX/attr-target-clones-riscv.cpp |  19 +++
 12 files changed, 462 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-target-clones-riscv.c
 create mode 100644 clang/test/CodeGenCXX/attr-target-clones-riscv.cpp
 create mode 100644 clang/test/SemaCXX/attr-target-clones-riscv.cpp

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 374595edd2ce4a..aa48596fbce07d 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1445,7 +1445,8 @@ class TargetInfo : public TransferrableTargetInfo,
   /// Identify whether this target supports multiversioning of functions,
   /// which requires support for cpu_supports and cpu_is functionality.
   bool supportsMultiVersioning() const {
-return getTriple().isX86() || getTriple().isAArch64();
+return getTriple().isX86() || getTriple().isAArch64() ||
+   getTriple().isRISCV();
   }
 
   /// Identify whether this target supports IFuncs.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5a8fae76a43a4d..0fd75e0b36b123 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13636,6 +13636,15 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap ,
   Features.insert(Features.begin(),
   Target->getTargetOpts().FeaturesAsWritten.begin(),
   Target->getTargetOpts().FeaturesAsWritten.end());
+} else if (Target->getTriple().isRISCV()) {
+  if (VersionStr != "default") {
+ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(VersionStr);
+Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+ParsedAttr.Features.end());
+  }
+  Features.insert(Features.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.end());
 } else {
   if (VersionStr.starts_with("arch="))
 TargetCPU = VersionStr.drop_front(sizeof("arch=") - 1);
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index a6d4af2b88111a..8e9132c9191a3c 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -257,7 +257,7 @@ bool RISCVTargetInfo::initFeatureMap(
 
   // If a target attribute specified a full arch string, override all the ISA
   // extension target features.
-  const auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
+  const auto I = llvm::find(FeaturesVec, "+__RISCV_TargetAttrNeedOverride");
   if (I != FeaturesVec.end()) {
 std::vector OverrideFeatures(std::next(I), FeaturesVec.end());
 
@@ -366,6 +366,12 @@ bool 
RISCVTargetInfo::handleTargetFeatures(std::vector ,
   return true;
 }
 
+bool RISCVTargetInfo::isValidFeatureName(StringRef Feature) const {
+  if (Feature.starts_with("__RISCV_TargetAttrNeedOverride"))
+return true;
+  return llvm::RISCVISAInfo::isSupportedExtensionFeature(Feature);
+}
+
 bool RISCVTargetInfo::isValidCPUName(StringRef Name) const {
   bool Is64Bit = getTriple().isArch64Bit();
   return llvm::RISCV::parseCPU(Name, Is64Bit);
@@ -390,7 +396,7 @@ void RISCVTargetInfo::fillValidTuneCPUList(
 
 static void handleFullArchString(StringRef FullArchStr,
  std::vector ) {
-  Features.push_back("__RISCV_TargetAttrNeedOverride");
+  Features.push_back("+__RISCV_TargetAttrNeedOverride");
   auto RII = llvm::RISCVISAInfo::parseArchString(
   FullArchStr, /* EnableExperimentalExtension */ true);
   if (llvm::errorToBool(RII.takeError())) {
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index bfbdafb682c851..ef8f59185d753c 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -106,6 +106,8 @@ class RISCVTargetInfo : public TargetInfo {
   bool handleTargetFeatures(std::vector ,
 DiagnosticsEngine ) override;
 
+  bool isValidFeatureName(StringRef Feature) const 

[clang] [llvm] demangle function names in trace files (PR #87626)

2024-04-09 Thread Jamie Schmeiser via cfe-commits

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

LGTM, thanks

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


[clang] Rework the printing of attributes (PR #87281)

2024-04-09 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Great idea! That’d make sense to me. 

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


[clang] Rework the printing of attributes (PR #87281)

2024-04-09 Thread Giuliano Belinassi via cfe-commits

giulianobelinassi wrote:

> > > > > @erichkeane, thank you. What's the process of including this in the 
> > > > > next release?
> > > > 
> > > > 
> > > > After CI is complete, you can click "Squash and Merge" below (if you 
> > > > cannot, let us know and someone can do it for you), and it'll be 
> > > > included in the 19.1 release this summer.
> > > 
> > > 
> > > I have commit access. I want this to be part of the 18.x releases as that 
> > > breaks our downstream clients.
> > 
> > 
> > Ah, hmm... I am not sure this qualifies for inclusion in the current 
> > release branch. Perhaps @AaronBallman can comment here.
> 
> I'm not particularly comfortable putting this into 18.x; we should only be 
> pushing very safe fixes to regressions and this one doesn't really qualify. 
> It's debatable whether it's a regression (it sort of is, sort of isn't), but 
> the changes are also relatively involved. I'd feel more comfortable with this 
> in 19.x so we have more time to find and fix remaining edge cases.

How about this single-line fix? It would fix the override regression for now.
```
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 80e607525a0a..a39288464040 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2511,6 +2511,7 @@ def Overloadable : Attr {
 }
 
 def Override : InheritableAttr {
+  let CanPrintOnLeft = 0;
   let Spellings = [CustomKeyword<"override">];
   let SemaHandler = 0;
   // Omitted from docs, since this is language syntax, not an attribute, as far
   ```

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


[clang] [Clang][Sema] Implement approved resolution for CWG2858 (PR #88042)

2024-04-09 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/88042

>From e850ae0982efbb7cec7c33d6b927844d89128743 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 8 Apr 2024 09:46:08 -0400
Subject: [PATCH 1/3] [Clang][Sema] Implement approved resolution for CWG2858

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  7 +++
 clang/lib/Sema/SemaDecl.cpp  | 13 ++---
 .../expr.prim.id/expr.prim.id.qual/p3.cpp| 16 
 3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4fbbc42273ba93..2ce2013aac7362 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2402,10 +2402,6 @@ def err_selected_explicit_constructor : Error<
 def note_explicit_ctor_deduction_guide_here : Note<
   "explicit %select{constructor|deduction guide}0 declared here">;
 
-// C++11 decltype
-def err_decltype_in_declarator : Error<
-"'decltype' cannot be used to name a declaration">;
-
 // C++11 auto
 def warn_cxx98_compat_auto_type_specifier : Warning<
   "'auto' type specifier is incompatible with C++98">,
@@ -8302,6 +8298,9 @@ def ext_template_after_declarative_nns : ExtWarn<
 def ext_alias_template_in_declarative_nns : ExtWarn<
   "a declarative nested name specifier cannot name an alias template">,
   InGroup>;
+def err_computed_type_in_declarative_nns  : Error<
+  "%select{a pack indexing type|'decltype'}0 cannot be used in "
+  "a declarative nested name specifier">;
 
 def err_no_typeid_with_fno_rtti : Error<
   "use of typeid requires -frtti">;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c790dab72dd721..1ba6b3beb1c758 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6335,16 +6335,15 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec 
, DeclContext *DC,
 if (TST->isDependentType() && TST->isTypeAlias())
   Diag(Loc, diag::ext_alias_template_in_declarative_nns)
   << SpecLoc.getLocalSourceRange();
-  } else if (T->isDecltypeType()) {
+  } else if (T->isDecltypeType() || T->getAsAdjusted()) {
 // C++23 [expr.prim.id.qual]p2:
 //   [...] A declarative nested-name-specifier shall not have a
-//   decltype-specifier.
+//   computed-type-specifier.
 //
-// FIXME: This wording appears to be defective as it does not forbid
-// declarative nested-name-specifiers with pack-index-specifiers.
-// See https://github.com/cplusplus/CWG/issues/499.
-Diag(Loc, diag::err_decltype_in_declarator)
-<< SpecLoc.getTypeLoc().getSourceRange();
+// CWG2858 changed this from 'decltype-specifier' to
+// 'computed-type-specifier'.
+Diag(Loc, diag::err_computed_type_in_declarative_nns)
+<< T->isDecltypeType() << SpecLoc.getTypeLoc().getSourceRange();
   }
 }
   } while ((SpecLoc = SpecLoc.getPrefix()));
diff --git 
a/clang/test/CXX/expr/expr.prim/expr.prim.id/expr.prim.id.qual/p3.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.id/expr.prim.id.qual/p3.cpp
index c73ffa55a26a31..5da13cc22abef2 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.id/expr.prim.id.qual/p3.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.id/expr.prim.id.qual/p3.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -std=c++2c -verify %s
 
 template
 struct A {
@@ -27,3 +28,18 @@ namespace N {
 
 template
 void N::E::f() { } // expected-warning {{a declarative nested name 
specifier cannot name an alias template}}
+
+#if __cplusplus > 202302L
+template
+struct A {
+  // FIXME: The nested-name-specifier in the following friend declarations are 
declarative,
+  // but we don't treat them as such (yet).
+  friend void Ts...[0]::f();
+  template
+  friend void Ts...[0]::g();
+
+  friend struct Ts...[0]::B;
+  template
+  friend struct Ts...[0]::C; // expected-warning{{is not supported; ignoring 
this friend declaration}}
+};
+#endif

>From e0646d2098f567ca0cd5642c8694d3d8980134c7 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Tue, 9 Apr 2024 09:03:25 -0400
Subject: [PATCH 2/3] [FOLD] apply review changes

---
 clang/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp |  4 ++--
 clang/test/CXX/drs/dr28xx.cpp | 21 +++
 .../expr.prim.id/expr.prim.id.qual/p3.cpp | 16 --
 clang/test/Parser/cxx-class.cpp   |  6 +++---
 4 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp
index fbe9c0895aeae8..3e67fca9ad7376 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp
@@ -6,8 +6,8 @@ class foo {
   void func();
 };
 
-int decltype(foo())::i; // 

[clang] [Clang][Sema] Implement approved resolution for CWG2858 (PR #88042)

2024-04-09 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/88042




  
Unicorn!  GitHub

  body {
background-color: #f1f1f1;
margin: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  }

  .container { margin: 50px auto 40px auto; width: 600px; text-align: 
center; }

  a { color: #4183c4; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { letter-spacing: -1px; line-height: 60px; font-size: 60px; 
font-weight: 100; margin: 0px; text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 10px 0 10px; font-size: 18px; 
font-weight: 200; line-height: 1.6em;}

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  


  

  

  We had issues producing the response to your 
request.
  Sorry about that. Please try refreshing and contact us if the problem 
persists.
  
https://github.com/contact;>Contact Support 
https://www.githubstatus.com;>GitHub Status 
https://twitter.com/githubstatus;>@githubstatus
  

  

  

  

  

  


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


[clang] [openmp] [Libomp] Place generated OpenMP headers into build resource directory (PR #88007)

2024-04-09 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> I should have mentioned, I'm building with GCC 9.3.0. Most of my team uses 
> this compiler.

Yeah, that's fine for building LLVM but in the future we'll probably require 
building the offloading runtime with an up-to-date clang. I think for now I can 
just restrict this patch to runtimes builds.

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


[clang] [Clang] [Sema] Fix dependence of DREs in lambdas with an explicit object parameter (PR #84473)

2024-04-09 Thread via cfe-commits

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


[clang] 38824f2 - [Clang] [Sema] Fix dependence of DREs in lambdas with an explicit object parameter (#84473)

2024-04-09 Thread via cfe-commits

Author: Sirraide
Date: 2024-04-09T14:52:52+02:00
New Revision: 38824f285f1459cb890337d2df1a3cafd3fd109d

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

LOG: [Clang] [Sema] Fix dependence of DREs in lambdas with an explicit object 
parameter (#84473)

This fixes some problems wrt dependence of captures in lambdas with
an explicit object parameter.

[temp.dep.expr] states that
> An id-expression is type-dependent if [...] its terminal name is
>   - associated by name lookup with an entity captured by copy
> ([expr.prim.lambda.capture]) in a lambda-expression that has
> an explicit object parameter whose type is dependent [dcl.fct].

There were several issues with our implementation of this:
1. we were treating by-reference captures as dependent rather than
   by-value captures;
2. tree transform wasn't checking whether referring to such a
   by-value capture should make a DRE dependent;
3. when checking whether a DRE refers to such a by-value capture, we
   were only looking at the immediately enclosing lambda, and not
   at any parent lambdas;
4. we also forgot to check for implicit by-value captures;
5. lastly, we were attempting to determine whether a lambda has an
   explicit object parameter by checking the `LambdaScopeInfo`'s
   `ExplicitObjectParameter`, but it seems that that simply wasn't
   set (yet) by the time we got to the check.

All of these should be fixed now.

This fixes #70604, #79754, #84163, #84425, #86054, #86398, and #86399.

Added: 
clang/test/PCH/cxx23-deducing-this-lambda.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/Stmt.h
clang/lib/AST/ComputeDependence.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/CodeGenCXX/cxx2b-deducing-this.cpp
clang/test/SemaCXX/cxx2b-deducing-this.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 30cedbe774be96..5708e691d08498 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -513,6 +513,9 @@ Bug Fixes to C++ Support
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)
 - Fix a crash when the using enum declaration uses an anonymous enumeration. 
Fixes (#GH86790).
+- Clang now correctly tracks type dependence of by-value captures in lambdas 
with an explicit
+  object parameter.
+  Fixes (#GH70604), (#GH79754), (#GH84163), (#GH84425), (#GH86054), 
(#GH86398), and (#GH86399).
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 6003b866c9f564..7eb99a75e1fc9d 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1149,6 +1149,7 @@ class CXXThisExpr : public Expr {
   CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit, ExprValueKind VK)
   : Expr(CXXThisExprClass, Ty, VK, OK_Ordinary) {
 CXXThisExprBits.IsImplicit = IsImplicit;
+CXXThisExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = false;
 CXXThisExprBits.Loc = L;
 setDependence(computeDependence(this));
   }
@@ -1170,6 +1171,15 @@ class CXXThisExpr : public Expr {
   bool isImplicit() const { return CXXThisExprBits.IsImplicit; }
   void setImplicit(bool I) { CXXThisExprBits.IsImplicit = I; }
 
+  bool isCapturedByCopyInLambdaWithExplicitObjectParameter() const {
+return CXXThisExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter;
+  }
+
+  void setCapturedByCopyInLambdaWithExplicitObjectParameter(bool Set) {
+CXXThisExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = Set;
+setDependence(computeDependence(this));
+  }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == CXXThisExprClass;
   }

diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 8892518d58e853..1b9c9231047717 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -784,6 +784,11 @@ class alignas(void *) Stmt {
 LLVM_PREFERRED_TYPE(bool)
 unsigned IsImplicit : 1;
 
+/// Whether there is a lambda with an explicit object parameter that
+/// captures this "this" by copy.
+LLVM_PREFERRED_TYPE(bool)
+unsigned CapturedByCopyInLambdaWithExplicitObjectParameter : 1;
+
 /// The location of the "this".
 SourceLocation Loc;
   };

diff  --git a/clang/lib/AST/ComputeDependence.cpp 
b/clang/lib/AST/ComputeDependence.cpp
index 86b77b49a0fbc4..5ec3013fabba9a 

[clang] [Clang][Sema] Implement approved resolution for CWG2858 (PR #88042)

2024-04-09 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@cor3ntin Should I just move the test from 
`test/CXX/expr/expr.prim/expr.prim.id/expr.prim.id.qual/p3.cpp` to 
`test/CXX/drs/dr28xx.cpp`?

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


[clang] Rework the printing of attributes (PR #87281)

2024-04-09 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Ok. Fair enough. 

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


[clang] [Clang] [Sema] Fix dependence of DREs in lambdas with an explicit object parameter (PR #84473)

2024-04-09 Thread via cfe-commits

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

>From 870e6a6def8c17859ffbb30906f91912268f872d Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 8 Mar 2024 11:55:42 +0100
Subject: [PATCH 01/10] [Clang] Fix dependence of DREs in lambdas with an
 explicit object parameter

---
 clang/lib/Sema/SemaExpr.cpp| 44 +---
 clang/lib/Sema/TreeTransform.h |  4 +-
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 81 ++
 3 files changed, 116 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 47bb263f56aade..700769860aa806 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -20687,20 +20687,42 @@ void Sema::MarkVariableReferenced(SourceLocation Loc, 
VarDecl *Var) {
 static void FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter(
 Sema , ValueDecl *D, Expr *E) {
   auto *ID = dyn_cast(E);
-  if (!ID || ID->isTypeDependent())
+  if (!ID || ID->isTypeDependent() || 
!ID->refersToEnclosingVariableOrCapture())
 return;
 
+  // If any enclosing lambda with a dependent explicit object parameter either
+  // explicitly captures the variable by value, or has a capture default of '='
+  // and does not capture the variable by reference, then the type of the DRE
+  // is dependent on the type of that lambda's explicit object parameter.
   auto IsDependent = [&]() {
-const LambdaScopeInfo *LSI = SemaRef.getCurLambda();
-if (!LSI)
-  return false;
-if (!LSI->ExplicitObjectParameter ||
-!LSI->ExplicitObjectParameter->getType()->isDependentType())
-  return false;
-if (!LSI->CaptureMap.count(D))
-  return false;
-const Capture  = LSI->getCapture(D);
-return !Cap.isCopyCapture();
+for (auto *Scope : llvm::reverse(SemaRef.FunctionScopes)) {
+  auto *LSI = dyn_cast(Scope);
+  if (!LSI)
+continue;
+
+  if (LSI->Lambda && !LSI->Lambda->Encloses(SemaRef.CurContext) &&
+  LSI->AfterParameterList)
+return false;
+
+  const auto *MD = LSI->CallOperator;
+  if (MD->getType().isNull())
+continue;
+
+  const auto *Ty = cast(MD->getType());
+  if (!Ty || !MD->isExplicitObjectMemberFunction() ||
+  !Ty->getParamType(0)->isDependentType())
+continue;
+
+  if (auto *C = LSI->CaptureMap.count(D) ? >getCapture(D) : nullptr) {
+if (C->isCopyCapture())
+  return true;
+continue;
+  }
+
+  if (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByval)
+return true;
+}
+return false;
   }();
 
   ID->setCapturedByCopyInLambdaWithExplicitObjectParameter(
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7389a48fe56fcc..867efd1ce5c80a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -11099,8 +11099,8 @@ 
TreeTransform::TransformDeclRefExpr(DeclRefExpr *E) {
   }
 
   if (!getDerived().AlwaysRebuild() &&
-  QualifierLoc == E->getQualifierLoc() &&
-  ND == E->getDecl() &&
+  E->getDependence() == ExprDependence::None &&
+  QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
   Found == E->getFoundDecl() &&
   NameInfo.getName() == E->getDecl()->getDeclName() &&
   !E->hasExplicitTemplateArgs()) {
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index b8ddb9ad300034..6c21954554d281 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -200,6 +200,87 @@ void TestMutationInLambda() {
 [i = 0](this auto){ i++; }();
 [i = 0](this const auto&){ i++; }();
 // expected-error@-1 {{cannot assign to a variable captured by copy in a 
non-mutable lambda}}
+// expected-note@-2 {{in instantiation of}}
+
+int x;
+const auto l1 = [x](this auto&) { x = 42; }; // expected-error {{cannot 
assign to a variable captured by copy in a non-mutable lambda}}
+const auto l2 = [=](this auto&) { x = 42; }; // expected-error {{cannot 
assign to a variable captured by copy in a non-mutable lambda}}
+
+const auto l3 = [](this auto&) {
+const auto l3a = [x](this auto&) { x = 42; }; // expected-error 
{{cannot assign to a variable captured by copy in a non-mutable lambda}}
+l3a(); // expected-note {{in instantiation of}}
+};
+
+const auto l4 = [](this auto&) {
+const auto l4a = [=](this auto&) { x = 42; }; // expected-error 
{{cannot assign to a variable captured by copy in a non-mutable lambda}}
+l4a(); // expected-note {{in instantiation of}}
+};
+
+const auto l5 = [x](this auto&) {
+const auto l5a = [x](this auto&) { x = 42; }; // expected-error 
{{cannot assign to a variable captured by copy in a non-mutable lambda}}
+l5a(); // expected-note {{in instantiation of}}
+};
+
+const auto l6 = [=](this auto&) {
+   

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

2024-04-09 Thread via cfe-commits


@@ -12,6 +12,7 @@
 #ifndef __LIBUNWIND_EXT__
 #define __LIBUNWIND_EXT__
 
+#ifndef __wasm__

trcrsired wrote:

wasm has its own exception handling mechanism. i do not know why 
__USING_WASM_EXCEPTION__ is not defined, because the author of the code did not 
change the upstream code correctly i guess.

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


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

2024-04-09 Thread via cfe-commits

trcrsired wrote:

> @trcrsired Could you please describe what bits of libunwind WASM uses? It 
> seems to me almost all of the functionality is stripped out?
> 
> Could you also provide instructions to build and test libunwind under WASM so 
> we could add CI coverage? And so I can test this change myself.

ok. i will add CI

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] [Sema] Fix dependence of DREs in lambdas with an explicit object parameter (PR #84473)

2024-04-09 Thread via cfe-commits

Sirraide wrote:

It’s been about week, so I’m going to merge this now.

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


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

2024-04-09 Thread via cfe-commits


@@ -39,3 +40,5 @@ extern void *__libunwind_cet_get_registers(unw_cursor_t *);
 extern void *__libunwind_cet_get_jump_target(void);

trcrsired wrote:

there are no registers. so what would you expect for cet_get_jump_target? there 
is no setjmp/longjmp

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] [Sema] Improve support for `__restrict`-qualified member functions (PR #83855)

2024-04-09 Thread via cfe-commits

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

>From eb5ebe31657fc82fe3810beff8d4cfff2201bf54 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 1 Mar 2024 13:56:32 +0100
Subject: [PATCH 01/13] [Clang] [Sema] Strip `__restrict` in cv-qualifier-list
 of member functions in canonical type

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

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5a8fae76a43a4d..91f1ccf429521f 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4418,7 +4418,8 @@ QualType ASTContext::getFunctionTypeInternal(
 
   // Determine whether the type being created is already canonical or not.
   bool isCanonical = !Unique && IsCanonicalExceptionSpec &&
- isCanonicalResultType(ResultTy) && !EPI.HasTrailingReturn;
+ isCanonicalResultType(ResultTy) &&
+ !EPI.HasTrailingReturn && !EPI.TypeQuals.hasRestrict();
   for (unsigned i = 0; i != NumArgs && isCanonical; ++i)
 if (!ArgArray[i].isCanonicalAsParam())
   isCanonical = false;
@@ -4439,6 +4440,7 @@ QualType ASTContext::getFunctionTypeInternal(
 llvm::SmallVector ExceptionTypeStorage;
 FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI;
 CanonicalEPI.HasTrailingReturn = false;
+CanonicalEPI.TypeQuals.removeRestrict();
 
 if (IsCanonicalExceptionSpec) {
   // Exception spec is already OK.

>From 68e633ea0d26195b2aa4ced5f541497e8e5ae13a Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 1 Mar 2024 15:05:17 +0100
Subject: [PATCH 02/13] [Clang] Tests for new `__restrict` behaviour

---
 clang/test/CodeGenCXX/mangle-ms-cxx11.cpp | 15 +---
 clang/test/CodeGenCXX/mangle-ms.cpp   | 36 +++
 .../SemaCXX/addr-of-overloaded-function.cpp   |  8 -
 .../restrict-member-function-matching.cpp | 21 +++
 4 files changed, 67 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/SemaCXX/restrict-member-function-matching.cpp

diff --git a/clang/test/CodeGenCXX/mangle-ms-cxx11.cpp 
b/clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
index 312c70cc740eb3..4900c4ad272bc3 100644
--- a/clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ b/clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -16,7 +16,8 @@ S b;
 
 using C = int () __restrict;
 S c;
-// CHECK-DAG: @"?c@FTypeWithQuals@@3U?$S@$$A8@@IAAHXZ@1@A"
+// FIXME: `__restrict` needs to be included in the mangled name:
+// FIXME-CHECK-DAG: @"?c@FTypeWithQuals@@3U?$S@$$A8@@IAAHXZ@1@A"
 
 using D = int () const &;
 S d;
@@ -28,7 +29,8 @@ S e;
 
 using F = int () __restrict &;
 S f;
-// CHECK-DAG: @"?f@FTypeWithQuals@@3U?$S@$$A8@@IGAAHXZ@1@A"
+// FIXME: See comment above.
+// FIXME-CHECK-DAG: @"?f@FTypeWithQuals@@3U?$S@$$A8@@IGAAHXZ@1@A"
 
 using G = int () const &&;
 S g;
@@ -40,7 +42,8 @@ S h;
 
 using I = int () __restrict &&;
 S i;
-// CHECK-DAG: @"?i@FTypeWithQuals@@3U?$S@$$A8@@IHAAHXZ@1@A"
+// FIXME: See comment above.
+// FIXME-CHECK-DAG: @"?i@FTypeWithQuals@@3U?$S@$$A8@@IHAAHXZ@1@A"
 
 using J = int ();
 S j;
@@ -205,9 +208,11 @@ struct A {
   void foo() __restrict &&;
 };
 void A::foo() __restrict & {}
-// CHECK-DAG: @"?foo@A@PR19361@@QIGAEXXZ"
+// FIXME: See comment above
+// FIXME-CHECK-DAG: @"?foo@A@PR19361@@QIGAEXXZ"
 void A::foo() __restrict && {}
-// CHECK-DAG: @"?foo@A@PR19361@@QIHAEXXZ"
+// FIXME: See comment above
+// FIXME-CHECK-DAG: @"?foo@A@PR19361@@QIHAEXXZ"
 }
 
 int operator"" _deg(long double) { return 0; }
diff --git a/clang/test/CodeGenCXX/mangle-ms.cpp 
b/clang/test/CodeGenCXX/mangle-ms.cpp
index cf69a83bbdf8c6..4cd28970f8094c 100644
--- a/clang/test/CodeGenCXX/mangle-ms.cpp
+++ b/clang/test/CodeGenCXX/mangle-ms.cpp
@@ -504,3 +504,39 @@ void runOnFunction() {
 }
 // CHECK-DAG: call {{.*}} @"??0?$L@V?$H@PAH@PR26029@@@PR26029@@QAE@XZ"
 }
+
+namespace CVRMemberFunctionQuals {
+struct S {
+  void a() const;
+  void b() volatile;
+  void c() __restrict;
+  void d() const volatile;
+  void e() const __restrict;
+  void f() volatile __restrict;
+  void g() const volatile __restrict;
+
+  void h();
+};
+
+// X64-DAG: define dso_local void @"?a@S@CVRMemberFunctionQuals@@QEBAXXZ"
+// X64-DAG: define dso_local void @"?b@S@CVRMemberFunctionQuals@@QECAXXZ"
+// X64-DAG: define dso_local void @"?c@S@CVRMemberFunctionQuals@@QEIAAXXZ"
+// X64-DAG: define dso_local void @"?d@S@CVRMemberFunctionQuals@@QEDAXXZ"
+// X64-DAG: define dso_local void @"?e@S@CVRMemberFunctionQuals@@QEIBAXXZ"
+// X64-DAG: define dso_local void @"?f@S@CVRMemberFunctionQuals@@QEICAXXZ"
+// X64-DAG: define dso_local void @"?g@S@CVRMemberFunctionQuals@@QEIDAXXZ"
+void S::a() const {}
+void S::b() volatile {}
+void S::c() __restrict {}
+void S::d() const volatile {}
+void S::e() const __restrict {}
+void S::f() volatile __restrict {}
+void S::g() const volatile __restrict {}
+
+// MSVC allows a mismatch in `__restrict`-qualification between a function
+// declaration and 

[clang] [Clang] [Sema] Improve support for `__restrict`-qualified member functions (PR #83855)

2024-04-09 Thread via cfe-commits


@@ -5052,6 +5052,21 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
   Function->setInnerLocStart(PatternDecl->getInnerLocStart());
   Function->setRangeEnd(PatternDecl->getEndLoc());
 
+  // Propagate '__restrict' properly.
+  if (auto MD = dyn_cast(Function)) {
+bool Restrict = cast(PatternDecl)->isEffectivelyRestrict();
+if (Restrict != MD->getMethodQualifiers().hasRestrict()) {
+  const auto *FPT = MD->getType()->getAs();
+  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+  if (Restrict)
+EPI.TypeQuals.addRestrict();
+  else
+EPI.TypeQuals.removeRestrict();
+  MD->setType(Context.getFunctionType(FPT->getReturnType(),
+  FPT->getParamTypes(), EPI));
+}
+  }
+

Sirraide wrote:

Actually, I think that’s not it. I got confused by this too just now: this here 
is about propagating `__restrict`-ness (or lack thereof since we may have to 
remove it again if the declaration is `__restrict`, but the definition isn’t, 
and we’re in GCC mode) to the definition of the function only.

Specifically, we can’t just make the declaration `__restrict` when we first 
create it; the declaration needs to be `__restrict` iff the template 
declaration is `__restrict`, and the definition needs to be `__restrict` iff 
the template defintion is `__restrict`; the former should happen automatically 
as part of template instantiation; this here is only about the latter.

I’m going to expand this comment a bit more to elaborate on this.

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


[clang] [Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (PR #87541)

2024-04-09 Thread Krystian Stasiowski via cfe-commits

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


[clang] 4657ab1 - [Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541)

2024-04-09 Thread via cfe-commits

Author: Krystian Stasiowski
Date: 2024-04-09T08:31:52-04:00
New Revision: 4657ab1c968e486e9f45329daa07340ebcf3bffd

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

LOG: [Clang][Sema] Fix crash when 'this' is used in a dependent class scope 
function template specialization that instantiates to a static member function 
(#87541)

This patch fixes a crash that happens when '`this`' is referenced
(implicitly or explicitly) in a dependent class scope function template
specialization that instantiates to a static member function. For
example:
```
template
struct A 
{
template
static void f();

template<>
void f() 
{
this; // causes crash during instantiation
}
};

template struct A;
```
This happens because during instantiation of the function body,
`Sema::getCurrentThisType` will return a null `QualType` which we
rebuild the `CXXThisExpr` with. A similar problem exists for implicit
class member access expressions in such contexts (which shouldn't really
happen within templates anyways per [class.mfct.non.static]
p2, but changing that is non-trivial). This patch fixes the crash by building
`UnresolvedLookupExpr`s instead of `MemberExpr`s for these implicit
member accesses, which will then be correctly rebuilt as `MemberExpr`s
during instantiation.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaExprMember.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8d9ccf789d9cb8..30cedbe774be96 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -507,6 +507,8 @@ Bug Fixes to C++ Support
 - Fix an issue caused by not handling invalid cases when substituting into the 
parameter mapping of a constraint. Fixes (#GH86757).
 - Fixed a bug that prevented member function templates of class templates 
declared with a deduced return type
   from being explicitly specialized for a given implicit instantiation of the 
class template.
+- Fixed a crash when ``this`` is used in a dependent class scope function 
template specialization
+  that instantiates to a static member function.
 
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9769d36900664c..f311f9f3743454 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5439,7 +5439,8 @@ class Sema final : public SemaBase {
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec , LookupResult ,
   bool NeedsADL,
-  bool AcceptInvalidDecl = false);
+  bool AcceptInvalidDecl = false,
+  bool NeedUnresolved = false);
   ExprResult BuildDeclarationNameExpr(
   const CXXScopeSpec , const DeclarationNameInfo , NamedDecl 
*D,
   NamedDecl *FoundD = nullptr,
@@ -6591,7 +6592,10 @@ class Sema final : public SemaBase {
 SourceLocation RParenLoc);
 
    ActOnCXXThis -  Parse 'this' pointer.
-  ExprResult ActOnCXXThis(SourceLocation loc);
+  ExprResult ActOnCXXThis(SourceLocation Loc);
+
+  /// Check whether the type of 'this' is valid in the current context.
+  bool CheckCXXThisType(SourceLocation Loc, QualType Type);
 
   /// Build a CXXThisExpr and mark it referenced in the current context.
   Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit);

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8db4fffeecfe35..7b91bbe0b2054d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3442,10 +3442,11 @@ static bool 
ShouldLookupResultBeMultiVersionOverload(const LookupResult ) {
 
 ExprResult Sema::BuildDeclarationNameExpr(const CXXScopeSpec ,
   LookupResult , bool NeedsADL,
-  bool AcceptInvalidDecl) {
+  bool AcceptInvalidDecl,
+  bool NeedUnresolved) {
   // If this is a single, fully-resolved result and we don't need ADL,
   // just build an ordinary singleton decl ref.
-  if (!NeedsADL && R.isSingleResult() &&
+  if (!NeedUnresolved && !NeedsADL && R.isSingleResult() &&
   !R.getAsSingle() &&
   !ShouldLookupResultBeMultiVersionOverload(R))
 return 

[clang] [Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (PR #87541)

2024-04-09 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/87541

>From 6ad6b5e698c3ae6fd8e881582fcfa4c8bb231da4 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 3 Apr 2024 14:33:27 -0400
Subject: [PATCH 1/4] [Clang][Sema] Fix crash when 'this' is used in a
 dependent class scope function template specialization that instantiates to a
 static member function

---
 clang/include/clang/Sema/Sema.h   |  8 +++-
 clang/lib/Sema/SemaExpr.cpp   |  5 ++-
 clang/lib/Sema/SemaExprCXX.cpp| 44 +--
 clang/lib/Sema/SemaExprMember.cpp | 44 ++-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  8 
 clang/lib/Sema/TreeTransform.h|  7 +--
 ...ms-function-specialization-class-scope.cpp | 38 ++--
 7 files changed, 118 insertions(+), 36 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 56d66a4486e0e74..57117963d84f1d2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5428,7 +5428,8 @@ class Sema final : public SemaBase {
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec , LookupResult ,
   bool NeedsADL,
-  bool AcceptInvalidDecl = false);
+  bool AcceptInvalidDecl = false,
+  bool NeedUnresolved = false);
   ExprResult BuildDeclarationNameExpr(
   const CXXScopeSpec , const DeclarationNameInfo , NamedDecl 
*D,
   NamedDecl *FoundD = nullptr,
@@ -6580,7 +6581,10 @@ class Sema final : public SemaBase {
 SourceLocation RParenLoc);
 
    ActOnCXXThis -  Parse 'this' pointer.
-  ExprResult ActOnCXXThis(SourceLocation loc);
+  ExprResult ActOnCXXThis(SourceLocation Loc);
+
+  /// Check whether the type of 'this' is valid in the current context.
+  bool CheckCXXThisType(SourceLocation Loc, QualType Type);
 
   /// Build a CXXThisExpr and mark it referenced in the current context.
   Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8db4fffeecfe35f..7b91bbe0b2054d3 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3442,10 +3442,11 @@ static bool 
ShouldLookupResultBeMultiVersionOverload(const LookupResult ) {
 
 ExprResult Sema::BuildDeclarationNameExpr(const CXXScopeSpec ,
   LookupResult , bool NeedsADL,
-  bool AcceptInvalidDecl) {
+  bool AcceptInvalidDecl,
+  bool NeedUnresolved) {
   // If this is a single, fully-resolved result and we don't need ADL,
   // just build an ordinary singleton decl ref.
-  if (!NeedsADL && R.isSingleResult() &&
+  if (!NeedUnresolved && !NeedsADL && R.isSingleResult() &&
   !R.getAsSingle() &&
   !ShouldLookupResultBeMultiVersionOverload(R))
 return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), 
R.getFoundDecl(),
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index cfb5c6b6f283373..d84c66e5969f74a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1415,26 +1415,42 @@ bool Sema::CheckCXXThisCapture(SourceLocation Loc, 
const bool Explicit,
 }
 
 ExprResult Sema::ActOnCXXThis(SourceLocation Loc) {
-  /// C++ 9.3.2: In the body of a non-static member function, the keyword this
-  /// is a non-lvalue expression whose value is the address of the object for
-  /// which the function is called.
+  // C++20 [expr.prim.this]p1:
+  //   The keyword this names a pointer to the object for which an
+  //   implicit object member function is invoked or a non-static
+  //   data member's initializer is evaluated.
   QualType ThisTy = getCurrentThisType();
 
-  if (ThisTy.isNull()) {
-DeclContext *DC = getFunctionLevelDeclContext();
+  if (CheckCXXThisType(Loc, ThisTy))
+return ExprError();
 
-if (const auto *Method = dyn_cast(DC);
-Method && Method->isExplicitObjectMemberFunction()) {
-  return Diag(Loc, diag::err_invalid_this_use) << 1;
-}
+  return BuildCXXThisExpr(Loc, ThisTy, /*IsImplicit=*/false);
+}
 
-if (isLambdaCallWithExplicitObjectParameter(CurContext))
-  return Diag(Loc, diag::err_invalid_this_use) << 1;
+bool Sema::CheckCXXThisType(SourceLocation Loc, QualType Type) {
+  if (!Type.isNull())
+return false;
 
-return Diag(Loc, diag::err_invalid_this_use) << 0;
+  // C++20 [expr.prim.this]p3:
+  //   If a declaration declares a member function or member function template
+  //   of a class X, the expression this is a prvalue of type
+  //   "pointer to cv-qualifier-seq X" wherever X is the current class between
+  //   the optional cv-qualifier-seq and the end of 

[clang] [clang][UBSan] Remove rigid metadata checks for `ubsan-bitfield-conversion` (PR #88116)

2024-04-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Michael Halkenhäuser (mhalk)


Changes

Follow-up to discussion: https://github.com/llvm/llvm-project/pull/87761

As discussed after landing the original PR:
Since fails could happen w.r.t. checking `!6`, these checks should be removed.

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


2 Files Affected:

- (modified) clang/test/CodeGen/ubsan-bitfield-conversion.c (+4-4) 
- (modified) clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp (+8-8) 


``diff
diff --git a/clang/test/CodeGen/ubsan-bitfield-conversion.c 
b/clang/test/CodeGen/ubsan-bitfield-conversion.c
index ea9bdd7da6bc26..61d7634f9a3362 100644
--- a/clang/test/CodeGen/ubsan-bitfield-conversion.c
+++ b/clang/test/CodeGen/ubsan-bitfield-conversion.c
@@ -17,7 +17,7 @@ void foo1(int x) {
   // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 5
   // CHECK-NEXT: [[BFRESULTCAST:%.*]] = sext i8 [[BFRESULTASHR]] to i32
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
@@ -29,7 +29,7 @@ void foo2(int x) {
   // CHECK-NEXT: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 6
   // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 6
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
@@ -42,7 +42,7 @@ void foo3() {
   // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 5
   // CHECK-NEXT: [[BFRESULTCAST:%.*]] = sext i8 [[BFRESULTASHR]] to i32
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
@@ -55,7 +55,7 @@ void foo4(int x) {
   // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 5
   // CHECK-NEXT: [[BFRESULTCAST:%.*]] = sext i8 [[BFRESULTASHR]] to i32
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
\ No newline at end of file
diff --git a/clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp 
b/clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp
index 92f6e247c5f5ba..c0248871ddc269 100644
--- a/clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp
+++ b/clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp
@@ -23,14 +23,14 @@ void foo1(int x) {
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 
[[BFRESULTSHL]], 5
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTCAST:%.*]] = sext i8 
[[BFRESULTASHR]] to i32
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   c.a = x;
   // CHECK: store i8 %{{.*}}
   // CHECK-BITFIELD-CONVERSION: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 5
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 
[[BFRESULTSHL]], 5
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTCAST:%.*]] = sext i8 
[[BFRESULTASHR]] to i32
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
@@ -42,13 +42,13 @@ void foo2(int x) {
   // CHECK-BITFIELD-CONVERSION: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 6
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 
[[BFRESULTSHL]], 6
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   c.b = x;
   // CHECK: store i8 %{{.*}}
   // CHECK-BITFIELD-CONVERSION: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 6
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 
[[BFRESULTSHL]], 6
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
@@ -61,14 

[clang] [clang][UBSan] Remove rigid metadata checks for `ubsan-bitfield-conversion` (PR #88116)

2024-04-09 Thread Michael Halkenhäuser via cfe-commits

https://github.com/mhalk created https://github.com/llvm/llvm-project/pull/88116

Follow-up to discussion: https://github.com/llvm/llvm-project/pull/87761

As discussed after landing the original PR:
Since fails could happen w.r.t. checking `!6`, these checks should be removed.

From 00c84d5187bf167642806c836677cbd10916814e Mon Sep 17 00:00:00 2001
From: Michael Halkenhaeuser 
Date: Tue, 9 Apr 2024 08:20:53 -0400
Subject: [PATCH] [clang][UBSan] Remove rigid metadata checks for
 `ubsan-bitfield-conversion`

Follow-up to: https://github.com/llvm/llvm-project/pull/87761

As discussed after landing the original PR:
Since fails could happen w.r.t. checking `!6`, these checks will be removed.
---
 clang/test/CodeGen/ubsan-bitfield-conversion.c   |  8 
 .../CodeGenCXX/ubsan-bitfield-conversion.cpp | 16 
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/clang/test/CodeGen/ubsan-bitfield-conversion.c 
b/clang/test/CodeGen/ubsan-bitfield-conversion.c
index ea9bdd7da6bc26..61d7634f9a3362 100644
--- a/clang/test/CodeGen/ubsan-bitfield-conversion.c
+++ b/clang/test/CodeGen/ubsan-bitfield-conversion.c
@@ -17,7 +17,7 @@ void foo1(int x) {
   // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 5
   // CHECK-NEXT: [[BFRESULTCAST:%.*]] = sext i8 [[BFRESULTASHR]] to i32
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
@@ -29,7 +29,7 @@ void foo2(int x) {
   // CHECK-NEXT: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 6
   // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 6
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
@@ -42,7 +42,7 @@ void foo3() {
   // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 5
   // CHECK-NEXT: [[BFRESULTCAST:%.*]] = sext i8 [[BFRESULTASHR]] to i32
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
@@ -55,7 +55,7 @@ void foo4(int x) {
   // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 5
   // CHECK-NEXT: [[BFRESULTCAST:%.*]] = sext i8 [[BFRESULTASHR]] to i32
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
\ No newline at end of file
diff --git a/clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp 
b/clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp
index 92f6e247c5f5ba..c0248871ddc269 100644
--- a/clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp
+++ b/clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp
@@ -23,14 +23,14 @@ void foo1(int x) {
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 
[[BFRESULTSHL]], 5
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTCAST:%.*]] = sext i8 
[[BFRESULTASHR]] to i32
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   c.a = x;
   // CHECK: store i8 %{{.*}}
   // CHECK-BITFIELD-CONVERSION: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 5
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 
[[BFRESULTSHL]], 5
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTCAST:%.*]] = sext i8 
[[BFRESULTASHR]] to i32
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   // CHECK-BITFIELD-CONVERSION: [[CONT]]:
   // CHECK-NEXT: ret void
 }
@@ -42,13 +42,13 @@ void foo2(int x) {
   // CHECK-BITFIELD-CONVERSION: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 6
   // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 
[[BFRESULTSHL]], 6
   // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
-  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
   c.b = x;
   // CHECK: store i8 %{{.*}}
   // CHECK-BITFIELD-CONVERSION: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 6
   // CHECK-BITFIELD-CONVERSION-NEXT: 

[clang] [clang] Add tests for some CWG 5xx issues (PR #87909)

2024-04-09 Thread Aaron Ballman via cfe-commits


@@ -661,6 +680,10 @@ namespace dr553 {
 }
 
 // dr554: na
+
+// dr555: na

AaronBallman wrote:

Avoiding copying tests is a good idea, that just means we need to come up with 
different tests. ;-)

CWG466 is solely about cv-qualification and pseudo destructors. CWG555 is more 
about lookup issues and was resolved by P1131R2. We should be able to devise a 
different set of tests for both, unless I'm missing something?

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


[clang] [openmp] [Libomp] Place generated OpenMP headers into build resource directory (PR #88007)

2024-04-09 Thread Pete Steinfeld via cfe-commits

psteinfeld wrote:

I should have mentioned, I'm building with GCC 9.3.0.  Most of my team uses 
this compiler.




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


[clang] [llvm] [AArch64][SME] Add intrinsics for vector groups ZERO (PR #88114)

2024-04-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: None (Lukacma)


Changes

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics:

```
  void svzero_za64_vg1x2(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg1x4(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg2x1(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg2x2(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg2x4(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg4x1(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg4x2(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg4x4(uint32_t slice)
__arm_streaming __arm_inout("za");
```

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


5 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+20-1) 
- (added) clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c 
(+139) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+6) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+37-9) 
- (added) llvm/test/CodeGen/AArch64/sme2p1-intrinsics-zero.ll (+94) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 1ac6d5170ea283..9bcfbf8c4f5c5e 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -146,6 +146,25 @@ let TargetGuard = "sme" in {
  [IsOverloadNone, IsStreamingCompatible, IsOutZA]>;
 }
 
+let TargetGuard = "sme2p1" in {
+  def SVZERO_ZA64_VG1x2 : SInst<"svzero_za64_vg1x2", "vm", "", MergeNone, 
"aarch64_sme_zero_za64_vg1x2",
+[IsOverloadNone, IsStreaming, IsInOutZA]>;
+  def SVZERO_ZA64_VG1x4 : SInst<"svzero_za64_vg1x4", "vm", "", MergeNone, 
"aarch64_sme_zero_za64_vg1x4",
+[IsOverloadNone, IsStreaming, IsInOutZA]>;
+  def SVZERO_ZA64_VG2x1 : SInst<"svzero_za64_vg2x1", "vm", "", MergeNone, 
"aarch64_sme_zero_za64_vg2x1",
+[IsOverloadNone, IsStreaming, IsInOutZA]>;
+  def SVZERO_ZA64_VG2x2 : SInst<"svzero_za64_vg2x2", "vm", "", MergeNone, 
"aarch64_sme_zero_za64_vg2x2",
+[IsOverloadNone, IsStreaming, IsInOutZA]>;
+  def SVZERO_ZA64_VG2x4 : SInst<"svzero_za64_vg2x4", "vm", "", MergeNone, 
"aarch64_sme_zero_za64_vg2x4",
+[IsOverloadNone, IsStreaming, IsInOutZA]>;
+  def SVZERO_ZA64_VG4x1 : SInst<"svzero_za64_vg4x1", "vm", "", MergeNone, 
"aarch64_sme_zero_za64_vg4x1",
+[IsOverloadNone, IsStreaming, IsInOutZA]>;
+  def SVZERO_ZA64_VG4x2 : SInst<"svzero_za64_vg4x2", "vm", "", MergeNone, 
"aarch64_sme_zero_za64_vg4x2",
+[IsOverloadNone, IsStreaming, IsInOutZA]>;
+  def SVZERO_ZA64_VG4x4 : SInst<"svzero_za64_vg4x4", "vm", "", MergeNone, 
"aarch64_sme_zero_za64_vg4x4",
+[IsOverloadNone, IsStreaming, IsInOutZA]>;
+}
+
 

 // SME - Counting elements in a streaming vector
 
@@ -673,4 +692,4 @@ let TargetGuard = "sme2" in {
 let TargetGuard = "sme2" in {
   def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
-}
+}
\ No newline at end of file
diff --git a/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c 
b/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c
new file mode 100644
index 00..bdd75798554148
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c
@@ -0,0 +1,139 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2p1 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
+
+// CHECK-LABEL: define dso_local void @test_svzero_za64_vg1x2(
+// CHECK-SAME: i32 noundef [[SLICE:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT: 

[clang] [llvm] [AArch64][SME] Add intrinsics for vector groups ZERO (PR #88114)

2024-04-09 Thread via cfe-commits

https://github.com/Lukacma created 
https://github.com/llvm/llvm-project/pull/88114

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics:

```
  void svzero_za64_vg1x2(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg1x4(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg2x1(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg2x2(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg2x4(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg4x1(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg4x2(uint32_t slice)
__arm_streaming __arm_inout("za");

  void svzero_za64_vg4x4(uint32_t slice)
__arm_streaming __arm_inout("za");
```

>From c44bd42f8011dd09771fda50a76a7321342c2b2f Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Thu, 4 Apr 2024 14:36:54 +
Subject: [PATCH 1/2] WIP

---
 clang/include/clang/Basic/arm_sme.td  |  29 ++-
 .../acle_sme2p1_zero.c|  91 +
 .../acle_sme2p1_imm.cpp   | 190 ++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |   6 +
 4 files changed, 315 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c
 create mode 100644 
clang/test/Sema/aarch64-sme2p1-intrinsics/acle_sme2p1_imm.cpp

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 1ac6d5170ea283..b00eabe331169f 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -146,6 +146,33 @@ let TargetGuard = "sme" in {
  [IsOverloadNone, IsStreamingCompatible, IsOutZA]>;
 }
 
+let TargetGuard = "sme2p1" in {
+  def SVZERO_ZA64_VG1x2 : SInst<"svzero_za64_vg1x2", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg1x2",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_7>]>;
+  def SVZERO_ZA64_VG1x4 : SInst<"svzero_za64_vg1x4", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg1x4",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_7>]>;
+  def SVZERO_ZA64_VG2x1 : SInst<"svzero_za64_vg2x1", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg2x1",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_7>]>;
+  def SVZERO_ZA64_VG2x2 : SInst<"svzero_za64_vg2x2", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg2x2",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_3>]>;
+  def SVZERO_ZA64_VG2x4 : SInst<"svzero_za64_vg2x4", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg2x4",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_3>]>;
+  def SVZERO_ZA64_VG4x1 : SInst<"svzero_za64_vg4x1", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg4x1",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_3>]>;
+  def SVZERO_ZA64_VG4x2 : SInst<"svzero_za64_vg4x2", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg4x2",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_1>]>;
+  def SVZERO_ZA64_VG4x4 : SInst<"svzero_za64_vg4x4", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg4x4",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_1>]>;
+}
+
 

 // SME - Counting elements in a streaming vector
 
@@ -673,4 +700,4 @@ let TargetGuard = "sme2" in {
 let TargetGuard = "sme2" in {
   def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
-}
+}
\ No newline at end of file
diff --git a/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c 
b/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c
new file mode 100644
index 00..3b661ec425cda5
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c
@@ -0,0 +1,91 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o 

[clang] [clang-format] Remove trailing newlines in TableGen formatting test. (PR #87983)

2024-04-09 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you!

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


[clang] [clang-format] Remove trailing newlines in TableGen formatting test. (PR #87983)

2024-04-09 Thread Hirofumi Nakamura via cfe-commits

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


[clang] bf0b21a - [clang-format] Remove trailing newlines in TableGen formatting test. (#87983)

2024-04-09 Thread via cfe-commits

Author: Hirofumi Nakamura
Date: 2024-04-09T21:17:01+09:00
New Revision: bf0b21aa685264c65a2d7fd4a8b86e3c42dfd729

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

LOG: [clang-format] Remove trailing newlines in TableGen formatting test. 
(#87983)

Added: 


Modified: 
clang/unittests/Format/FormatTestTableGen.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTestTableGen.cpp 
b/clang/unittests/Format/FormatTestTableGen.cpp
index d235c85c8eaa0f..79b6961b00b42a 100644
--- a/clang/unittests/Format/FormatTestTableGen.cpp
+++ b/clang/unittests/Format/FormatTestTableGen.cpp
@@ -72,7 +72,7 @@ TEST_F(FormatTestTableGen, LiteralsAndIdentifiers) {
"  let 0startID = $TokVarName;\n"
"  let 0xstartInteger = 0x42;\n"
"  let someIdentifier = $TokVarName;\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, BangOperators) {
@@ -101,22 +101,22 @@ TEST_F(FormatTestTableGen, BangOperators) {
"  \"zerozero\",\n"
"  true:  // default\n"
"  \"positivepositive\");\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, Include) {
-  verifyFormat("include \"test/IncludeFile.h\"\n");
+  verifyFormat("include \"test/IncludeFile.h\"");
 }
 
 TEST_F(FormatTestTableGen, Types) {
-  verifyFormat("def Types : list, bits<3>, list> {}\n");
+  verifyFormat("def Types : list, bits<3>, list> {}");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue1_SingleLiterals) {
   verifyFormat("def SimpleValue {\n"
"  let Integer = 42;\n"
"  let String = \"some string\";\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue1_MultilineString) {
@@ -129,7 +129,7 @@ TEST_F(FormatTestTableGen, SimpleValue1_MultilineString) {
   "delimited by \\[{ and }\\]. It  can break across lines and the line "
   "breaks are retained in the string. \n"
   
"(https://llvm.org/docs/TableGen/ProgRef.html#grammar-token-TokCode)}];\n"
-  "}\n";
+  "}";
   StringRef DefWithCodeMessedUp =
   "def SimpleValueCode {  let  \n"
   "Code=   \n"
@@ -139,7 +139,7 @@ TEST_F(FormatTestTableGen, SimpleValue1_MultilineString) {
   "breaks are retained in the string. \n"
   "(https://llvm.org/docs/TableGen/ProgRef.html#grammar-token-TokCode)}] 
\n"
   " ;  \n"
-  "   }\n";
+  "   }";
   verifyFormat(DefWithCode, DefWithCodeMessedUp);
 }
 
@@ -147,15 +147,15 @@ TEST_F(FormatTestTableGen, SimpleValue2) {
   verifyFormat("def SimpleValue2 {\n"
"  let True = true;\n"
"  let False = false;\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue3) {
-  verifyFormat("class SimpleValue3 { int Question = ?; }\n");
+  verifyFormat("class SimpleValue3 { int Question = ?; }");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue4) {
-  verifyFormat("def SimpleValue4 { let ValueList = {1, 2, 3}; }\n");
+  verifyFormat("def SimpleValue4 { let ValueList = {1, 2, 3}; }");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue5) {
@@ -166,7 +166,7 @@ TEST_F(FormatTestTableGen, SimpleValue5) {
"  list>;\n"
"  let SquareBitsListWithType = [ {1, 2},\n"
" {3, 4} ]>>;\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue6) {
@@ -184,15 +184,15 @@ TEST_F(FormatTestTableGen, SimpleValue6) {
"  );\n"
"  let DAGArgBang = (!cast(\"Some\") i32:$src1,\n"
"  i32:$src2);\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue7) {
-  verifyFormat("def SimpleValue7 { let Identifier = SimpleValue; }\n");
+  verifyFormat("def SimpleValue7 { let Identifier = SimpleValue; }");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue8) {
-  verifyFormat("def SimpleValue8 { let Class = SimpleValue3<3>; }\n");
+  verifyFormat("def SimpleValue8 { let Class = SimpleValue3<3>; }");
 }
 
 TEST_F(FormatTestTableGen, ValueSuffix) {
@@ -203,19 +203,18 @@ TEST_F(FormatTestTableGen, ValueSuffix) {
"  let Slice1 = value[1, ];\n"
"  let Slice2 = value[4...7, 17, 2...3, 4];\n"
"  let Field = value.field;\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, PasteOperator) {
-  verifyFormat(
-  "def Paste#\"Operator\" { string Paste = \"Paste\"#operator; }\n");
+  verifyFormat("def Paste#\"Operator\" { string Paste = \"Paste\"#operator; 
}");
 
   verifyFormat("def [\"Traring\", \"Paste\"]# {\n"
   

[clang] [clang] Add tests for some CWG 5xx issues (PR #87909)

2024-04-09 Thread Vlad Serebrennikov via cfe-commits


@@ -661,6 +680,10 @@ namespace dr553 {
 }
 
 // dr554: na
+
+// dr555: na

Endilll wrote:

Ah, I confused this with CWG550, which is a duplicate.
I still would like to avoid copying tests, though.

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


[clang] [compiler-rt] Fix "[clang][UBSan] Add implicit conversion check for bitfields" (PR #87761)

2024-04-09 Thread Michael Halkenhäuser via cfe-commits

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


[clang] [compiler-rt] Fix "[clang][UBSan] Add implicit conversion check for bitfields" (PR #87761)

2024-04-09 Thread Michael Halkenhäuser via cfe-commits


@@ -0,0 +1,94 @@
+// RUN: %clang -x c++ -fsanitize=implicit-bitfield-conversion -target 
x86_64-linux -S -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-BITFIELD-CONVERSION
+// RUN: %clang -x c++ -fsanitize=implicit-integer-conversion -target 
x86_64-linux -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang -x c++ -fsanitize=implicit-conversion -target x86_64-linux -S 
-emit-llvm -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-BITFIELD-CONVERSION
+
+struct S {
+  int a:3;
+  char b:2;
+};
+
+class C : public S {
+  public:
+short c:3;
+};
+
+S s;
+C c;
+
+// CHECK-LABEL: define{{.*}} void @{{.*foo1.*}}
+void foo1(int x) {
+  s.a = x;
+  // CHECK: store i8 %{{.*}}
+  // CHECK-BITFIELD-CONVERSION: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 5
+  // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 
[[BFRESULTSHL]], 5
+  // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTCAST:%.*]] = sext i8 
[[BFRESULTASHR]] to i32
+  // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6

mhalk wrote:

@Zonotora
**Q1: Is checking `!nosanitize` necessary?**
**Q2: Is checking `!6` necessary?**

Regarding the metadata, it's not always `!6` (at leat for us).
So, if we could simply remove at least this metadata check `!6` (or even both, 
if possible), it would probably solve the `check-clang` failures we are 
encountering.
Also, when looking at the output, the referred metadata is empty, in my case it 
was `!4`, with `!4 = !{}`.

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


[clang] Rework the printing of attributes (PR #87281)

2024-04-09 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > > > @erichkeane, thank you. What's the process of including this in the 
> > > > next release?
> > > 
> > > 
> > > After CI is complete, you can click "Squash and Merge" below (if you 
> > > cannot, let us know and someone can do it for you), and it'll be included 
> > > in the 19.1 release this summer.
> > 
> > 
> > I have commit access. I want this to be part of the 18.x releases as that 
> > breaks our downstream clients.
> 
> Ah, hmm... I am not sure this qualifies for inclusion in the current release 
> branch. Perhaps @AaronBallman can comment here.

I'm not particularly comfortable putting this into 18.x; we should only be 
pushing very safe fixes to regressions and this one doesn't really qualify. 
It's debatable whether it's a regression (it sort of is, sort of isn't), but 
the changes are also relatively involved. I'd feel more comfortable with this 
in 19.x so we have more time to find and fix remaining edge cases.

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


[clang] [clang] Add tests for some CWG 5xx issues (PR #87909)

2024-04-09 Thread Aaron Ballman via cfe-commits


@@ -661,6 +680,10 @@ namespace dr553 {
 }
 
 // dr554: na
+
+// dr555: na

AaronBallman wrote:

https://cplusplus.github.io/CWG/issues/555.html is not a duplicate, it's marked 
CD5 not dup?

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


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-04-09 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/83774

>From 1e556e00e59377c76c168293d6c2678f7a874742 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Fri, 14 Jul 2023 10:38:14 +0800
Subject: [PATCH 1/2] [clang] Enable sized deallocation by default in C++14
 onwards

Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

Differential Revision: https://reviews.llvm.org/D112921
---
 .../clangd/unittests/FindTargetTests.cpp  |   4 +-
 .../checkers/misc/new-delete-overloads.cpp|  10 -
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/Driver/Options.td |   7 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  13 +-
 clang/lib/Driver/ToolChains/Darwin.cpp|  58 -
 clang/lib/Driver/ToolChains/Darwin.h  |   4 +
 clang/lib/Driver/ToolChains/ZOS.cpp   |   6 +
 clang/test/AST/ast-dump-expr-json.cpp |   2 +-
 clang/test/AST/ast-dump-expr.cpp  |   2 +-
 clang/test/AST/ast-dump-stmt-json.cpp | 244 +-
 clang/test/Analysis/cxxnewexpr-callback.cpp   |   4 +-
 .../basic.stc.dynamic.deallocation/p2.cpp |   2 +-
 clang/test/CXX/drs/dr292.cpp  |  17 +-
 .../test/CXX/expr/expr.unary/expr.new/p14.cpp |   2 +-
 .../CodeGenCXX/cxx1y-sized-deallocation.cpp   |  10 +-
 .../CodeGenCXX/cxx1z-aligned-allocation.cpp   |   6 +-
 .../CodeGenCXX/cxx2a-destroying-delete.cpp|   4 +-
 clang/test/CodeGenCXX/delete-two-arg.cpp  |   4 +-
 clang/test/CodeGenCXX/delete.cpp  |  12 +-
 clang/test/CodeGenCXX/dllimport.cpp   |   4 +-
 clang/test/CodeGenCXX/new.cpp |   6 +-
 .../coro-aligned-alloc-2.cpp  |   2 -
 .../CodeGenCoroutines/coro-aligned-alloc.cpp  |   6 +-
 clang/test/CodeGenCoroutines/coro-alloc.cpp   |   6 +-
 clang/test/CodeGenCoroutines/coro-cleanup.cpp |   6 +-
 clang/test/CodeGenCoroutines/coro-dealloc.cpp |   2 -
 clang/test/CodeGenCoroutines/coro-gro.cpp |   3 +-
 clang/test/CodeGenCoroutines/pr56919.cpp  |   9 +-
 clang/test/Lexer/cxx-features.cpp |  20 +-
 clang/test/PCH/cxx1z-aligned-alloc.cpp|  10 +-
 clang/test/SemaCXX/MicrosoftExtensions.cpp|   8 +-
 .../SemaCXX/builtin-operator-new-delete.cpp   |   2 +-
 .../test/SemaCXX/cxx1y-sized-deallocation.cpp |   2 +-
 .../unavailable_aligned_allocation.cpp|  15 +-
 clang/tools/clang-repl/CMakeLists.txt |  59 +
 clang/unittests/Interpreter/CMakeLists.txt|  59 +
 .../StaticAnalyzer/CallEventTest.cpp  |   2 +-
 clang/www/cxx_status.html |  11 +-
 .../support.dynamic/libcpp_deallocate.sh.cpp  |   3 +
 .../sized_delete_array14.pass.cpp |   8 +-
 .../new.delete.single/sized_delete14.pass.cpp |   8 +-
 42 files changed, 555 insertions(+), 112 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 0af6036734ba53..1b7b96281dfaa5 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -839,7 +839,9 @@ TEST_F(TargetDeclTest, OverloadExpr) {
   [[delete]] x;
 }
   )cpp";
-  EXPECT_DECLS("CXXDeleteExpr", "void operator delete(void *) noexcept");
+  // Sized deallocation is enabled by default in C++14 onwards.
+  EXPECT_DECLS("CXXDeleteExpr",
+   "void operator delete(void *, unsigned long) noexcept");
 }
 
 TEST_F(TargetDeclTest, DependentExprs) {
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
index 78f021144b2e19..f86fe8a4c5b14f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
@@ -12,16 +12,6 @@ struct S {
 // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: declaration of 'operator new' has 
no matching declaration of 'operator delete' at the same scope
 void *operator new(size_t size) noexcept(false);
 
-struct T {
-  // Sized deallocations are not enabled by default, and so this new/delete 
pair
-  // does not match. However, we expect only one warning, for the new, because
-  // the operator delete is a placement delete and we do not warn on 
mismatching
-  // placement operations.
-  // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' 
has no matching declaration of 'operator delete' at the same scope
-  void *operator new(size_t size) noexcept;
-  void operator delete(void *ptr, size_t) noexcept; // ok only if sized 
deallocation is enabled
-};
-
 struct U {
   void *operator new(size_t size) noexcept;
   void operator delete(void *ptr) noexcept;
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 

[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-09 Thread via cfe-commits

Sirraide wrote:

Just added the deleted message to the ODR hash as well. Not too familiar w/ ODR 
checking though, so I wasn’t sure whether to include it only if `SkipBody` is 
`false`.

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


[clang] [clang]Treat arguments to builtin type traits as template type arguments (PR #87132)

2024-04-09 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@shafik, gentle ping!

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


[clang] 5d7d6ad - [clang][Interp] Add toAPValue unittests

2024-04-09 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-04-09T12:36:28+02:00
New Revision: 5d7d6ad663f80fbc6161da1175476bb663301c46

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

LOG: [clang][Interp] Add toAPValue unittests

Added: 
clang/unittests/AST/Interp/toAPValue.cpp

Modified: 
clang/unittests/AST/Interp/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/AST/Interp/CMakeLists.txt 
b/clang/unittests/AST/Interp/CMakeLists.txt
index 8fa5c85064dbce..ea727cdd4412be 100644
--- a/clang/unittests/AST/Interp/CMakeLists.txt
+++ b/clang/unittests/AST/Interp/CMakeLists.txt
@@ -1,5 +1,6 @@
 add_clang_unittest(InterpTests
   Descriptor.cpp
+  toAPValue.cpp
   )
 
 clang_target_link_libraries(InterpTests

diff  --git a/clang/unittests/AST/Interp/toAPValue.cpp 
b/clang/unittests/AST/Interp/toAPValue.cpp
new file mode 100644
index 00..d0dfb40d514953
--- /dev/null
+++ b/clang/unittests/AST/Interp/toAPValue.cpp
@@ -0,0 +1,90 @@
+#include "../../../lib/AST/Interp/Context.h"
+#include "../../../lib/AST/Interp/Descriptor.h"
+#include "../../../lib/AST/Interp/Program.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace clang::interp;
+using namespace clang::ast_matchers;
+
+/// Test the various toAPValue implementations.
+TEST(ToAPValue, Pointers) {
+  constexpr char Code[] =
+  "struct A { bool a; bool z; };\n"
+  "struct S {\n"
+  "  A a[3];\n"
+  "};\n"
+  "constexpr S d = {{{true, false}, {false, true}, {false, false}}};\n"
+  "constexpr const bool *b = [1].z;\n";
+
+  auto AST = tooling::buildASTFromCodeWithArgs(
+  Code, {"-fexperimental-new-constant-interpreter"});
+
+  auto  = AST->getASTContext().getInterpContext();
+  Program  = Ctx.getProgram();
+
+  auto getDecl = [&](const char *Name) -> const ValueDecl * {
+auto Nodes =
+match(valueDecl(hasName(Name)).bind("var"), AST->getASTContext());
+assert(Nodes.size() == 1);
+const auto *D = Nodes[0].getNodeAs("var");
+assert(D);
+return D;
+  };
+  auto getGlobalPtr = [&](const char *Name) -> Pointer {
+const VarDecl *D = cast(getDecl(Name));
+return Prog.getPtrGlobal(*Prog.getGlobal(D));
+  };
+
+  const Pointer  = getGlobalPtr("b");
+  const Pointer  = GP.deref();
+  ASSERT_TRUE(P.isLive());
+  APValue A = P.toAPValue();
+  ASSERT_TRUE(A.isLValue());
+  ASSERT_TRUE(A.hasLValuePath());
+  const auto  = A.getLValuePath();
+  ASSERT_EQ(Path.size(), 3u);
+  ASSERT_EQ(A.getLValueBase(), getDecl("d"));
+}
+
+TEST(ToAPValue, FunctionPointers) {
+  constexpr char Code[] = " constexpr bool foo() { return true; }\n"
+  " constexpr bool (*func)() = foo;\n";
+
+  auto AST = tooling::buildASTFromCodeWithArgs(
+  Code, {"-fexperimental-new-constant-interpreter"});
+
+  auto  = AST->getASTContext().getInterpContext();
+  Program  = Ctx.getProgram();
+
+  auto getDecl = [&](const char *Name) -> const ValueDecl * {
+auto Nodes =
+match(valueDecl(hasName(Name)).bind("var"), AST->getASTContext());
+assert(Nodes.size() == 1);
+const auto *D = Nodes[0].getNodeAs("var");
+assert(D);
+return D;
+  };
+
+  auto getGlobalPtr = [&](const char *Name) -> Pointer {
+const VarDecl *D = cast(getDecl(Name));
+return Prog.getPtrGlobal(*Prog.getGlobal(D));
+  };
+
+  const Pointer  = getGlobalPtr("func");
+  const FunctionPointer  = GP.deref();
+  ASSERT_FALSE(FP.isZero());
+  APValue A = FP.toAPValue();
+  ASSERT_TRUE(A.hasValue());
+  ASSERT_TRUE(A.isLValue());
+  ASSERT_TRUE(A.hasLValuePath());
+  const auto  = A.getLValuePath();
+  ASSERT_EQ(Path.size(), 0u);
+  ASSERT_FALSE(A.getLValueBase().isNull());
+  ASSERT_EQ(A.getLValueBase().dyn_cast(), getDecl("foo"));
+}



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


[clang] [llvm] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (PR #88105)

2024-04-09 Thread via cfe-commits

Lukacma wrote:

I noticed that file names and file location are using sme2 as prefix. Shouldn't 
we use sme2p1 prefix for this intrinsic ?

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


[clang] [NFC][OpenMP] Split nesting_of_regions test (PR #87842)

2024-04-09 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Thank you for improving test run times, that's really appreciated!

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


[clang] [clang] Catch missing format attributes (PR #70024)

2024-04-09 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovicsyrmia updated 
https://github.com/llvm/llvm-project/pull/70024

From c77435557c7b933f4e997b0fed64b37bb98fd8dd Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/Sema/SemaChecking.cpp   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 119 +++-
 clang/test/Sema/attr-format-missing.c | 244 
 clang/test/Sema/attr-format-missing.cpp   | 261 ++
 8 files changed, 634 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a84ff16a1e4d4..c6cd05da32332d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -381,6 +381,9 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now diagnoses missing format attributes for non-template functions and
+  class/struct/union members. Fixes #GH70024
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 520168f01fd846..5c6a69ff1586db 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -505,7 +505,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index df57f5e6ce11ba..d32bf4c8a9549e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1008,6 +1008,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8c98d8c7fef7a7..2bf2537027d728 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3885,6 +3885,10 @@ class Sema final {
   bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc,
  const ParsedAttr , bool IsAsync);
 
+  void DiagnoseMissingFormatAttributes(const FunctionDecl *FDecl,
+   ArrayRef Args,
+   SourceLocation Loc);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo ,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3dcd18b3afc8b4..77e01ba344e5a5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8034,8 +8034,10 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
-  if (FD)
+  if (FD) {
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
+DiagnoseMissingFormatAttributes(FD, Args, Range.getBegin());
+  }
 }
 
 /// CheckConstructorCall - Check a constructor call for correctness and safety
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 8bce04640e748e..fbf6f8f6f9534d 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -159,6 +159,13 @@ static bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+static bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 static inline bool isNSStringType(QualType T, ASTContext ,
   bool AllowNSAttributedString = false) {
   const auto *PT = T->getAs();
@@ -308,7 +315,7 

[clang] 321f831 - [clang][Interp] Diagnose comparisons with weak pointers

2024-04-09 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-04-09T12:36:28+02:00
New Revision: 321f8312b98620131ebb3b71fe15c0d6b2267488

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

LOG: [clang][Interp] Diagnose comparisons with weak pointers

Added: 
clang/test/AST/Interp/weak.cpp

Modified: 
clang/lib/AST/Interp/Interp.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 3dc223f97a8cce..2c733c90f5f2b6 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -801,6 +801,18 @@ inline bool CmpHelperEQ(InterpState , CodePtr 
OpPC, CompareFn Fn) {
 return true;
   }
 
+  for (const auto  : {LHS, RHS}) {
+if (P.isZero())
+  continue;
+if (const ValueDecl *VD = P.getDeclDesc()->asValueDecl();
+VD && VD->isWeak()) {
+  const SourceInfo  = S.Current->getSource(OpPC);
+  S.FFDiag(Loc, diag::note_constexpr_pointer_weak_comparison)
+  << P.toDiagnosticString(S.getCtx());
+  return false;
+}
+  }
+
   if (!Pointer::hasSameBase(LHS, RHS)) {
 S.Stk.push(BoolT::from(Fn(ComparisonCategoryResult::Unordered)));
 return true;

diff  --git a/clang/test/AST/Interp/weak.cpp b/clang/test/AST/Interp/weak.cpp
new file mode 100644
index 00..d4aac3ff764dde
--- /dev/null
+++ b/clang/test/AST/Interp/weak.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter 
-verify=expected,both %s
+// RUN: %clang_cc1 -std=c++20 -verify=ref,both %s
+
+
+
+
+/// FIXME: The new interpreter also emits the "address of weak declaration" 
note in the pointer-to-bool case.
+
+[[gnu::weak]] extern int a;
+int ha[(bool)]; // both-warning {{variable length arrays in C++ are a Clang 
extension}} \
+  // expected-note {{comparison against address of weak 
declaration}} \
+  // both-error {{variable length array declaration not 
allowed at file scope}}
+int ha2[ == nullptr]; // both-warning {{variable length arrays in C++ are a 
Clang extension}} \
+// both-note {{comparison against address of weak 
declaration '' can only be performed at runtime}} \
+// both-error {{variable length array declaration not 
allowed at file scope}}



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


[clang] [llvm] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (PR #88105)

2024-04-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Momchil Velikov (momchil-velikov)


Changes

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

void svmopa_za16[_f16]_m(uint64_t tile, svbool_t pn, svbool_t pm,
 svfloat16_t zn, svfloat16_t zm)
__arm_streaming __arm_inout("za");
void svmops_za16[_f16]_m(uint64_t tile, svbool_t pn,
 svbool_t pm, svfloat16_t zn, svfloat16_t zm)
__arm_streaming __arm_inout("za");

as well as the corresponding `bf16` variants.

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


7 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+24) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c 
(+97) 
- (added) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c 
(+34) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+4-1) 
- (modified) llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td (+5-5) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+14-2) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-mopa.ll (+42) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 1ac6d5170ea283..e60a400b094850 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -674,3 +674,27 @@ let TargetGuard = "sme2" in {
   def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
 }
+
+
+// SME2p1 - FMOPA, FMOPS (non-widening)
+let TargetGuard = "sme,b16b16" in {
+  def SVMOPA_BF16_NW : SInst<"svmopa_za16[_bf16]", "viPPdd", "b",
+ MergeOp1, "aarch64_sme_mopa_nonwide",
+ [IsStreaming, IsInOutZA],
+ [ImmCheck<0, ImmCheck0_1>]>;
+  def SVMOPS_BF16_NW : SInst<"svmops_za16[_bf16]", "viPPdd", "b",
+ MergeOp1, "aarch64_sme_mops_nonwide",
+ [IsStreaming, IsInOutZA],
+ [ImmCheck<0, ImmCheck0_1>]>;
+}
+
+let TargetGuard = "sme2,sme-f16f16" in {
+  def SVMOPA_F16_NW : SInst<"svmopa_za16[_f16]", "viPPdd", "h",
+MergeOp1, "aarch64_sme_mopa_nonwide",
+[IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_1>]>;
+  def SVMOPS_F16_NW : SInst<"svmops_za16[_f16]", "viPPdd", "h",
+MergeOp1, "aarch64_sme_mops_nonwide",
+[IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_1>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
new file mode 100644
index 00..36a75609534653
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
@@ -0,0 +1,97 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1   -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK
+// RUN: %clang_cc1-x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK-CXX
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS-fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK-CXX
+
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -o /dev/null %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+#ifdef SME_OVERLOADED_FORMS
+#define SME_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SME_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-LABEL: define dso_local 

[clang] [llvm] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (PR #88105)

2024-04-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Momchil Velikov (momchil-velikov)


Changes

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

void svmopa_za16[_f16]_m(uint64_t tile, svbool_t pn, svbool_t pm,
 svfloat16_t zn, svfloat16_t zm)
__arm_streaming __arm_inout("za");
void svmops_za16[_f16]_m(uint64_t tile, svbool_t pn,
 svbool_t pm, svfloat16_t zn, svfloat16_t zm)
__arm_streaming __arm_inout("za");

as well as the corresponding `bf16` variants.

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


7 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+24) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c 
(+97) 
- (added) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c 
(+34) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+4-1) 
- (modified) llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td (+5-5) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+14-2) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-mopa.ll (+42) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 1ac6d5170ea283..e60a400b094850 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -674,3 +674,27 @@ let TargetGuard = "sme2" in {
   def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
 }
+
+
+// SME2p1 - FMOPA, FMOPS (non-widening)
+let TargetGuard = "sme,b16b16" in {
+  def SVMOPA_BF16_NW : SInst<"svmopa_za16[_bf16]", "viPPdd", "b",
+ MergeOp1, "aarch64_sme_mopa_nonwide",
+ [IsStreaming, IsInOutZA],
+ [ImmCheck<0, ImmCheck0_1>]>;
+  def SVMOPS_BF16_NW : SInst<"svmops_za16[_bf16]", "viPPdd", "b",
+ MergeOp1, "aarch64_sme_mops_nonwide",
+ [IsStreaming, IsInOutZA],
+ [ImmCheck<0, ImmCheck0_1>]>;
+}
+
+let TargetGuard = "sme2,sme-f16f16" in {
+  def SVMOPA_F16_NW : SInst<"svmopa_za16[_f16]", "viPPdd", "h",
+MergeOp1, "aarch64_sme_mopa_nonwide",
+[IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_1>]>;
+  def SVMOPS_F16_NW : SInst<"svmops_za16[_f16]", "viPPdd", "h",
+MergeOp1, "aarch64_sme_mops_nonwide",
+[IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_1>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
new file mode 100644
index 00..36a75609534653
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
@@ -0,0 +1,97 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1   -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK
+// RUN: %clang_cc1-x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK-CXX
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS-fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK-CXX
+
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -o /dev/null %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+#ifdef SME_OVERLOADED_FORMS
+#define SME_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SME_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-LABEL: define dso_local 

[clang] [llvm] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (PR #88105)

2024-04-09 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov created 
https://github.com/llvm/llvm-project/pull/88105

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

void svmopa_za16[_f16]_m(uint64_t tile, svbool_t pn, svbool_t pm,
 svfloat16_t zn, svfloat16_t zm)
__arm_streaming __arm_inout("za");
void svmops_za16[_f16]_m(uint64_t tile, svbool_t pn,
 svbool_t pm, svfloat16_t zn, svfloat16_t zm)
__arm_streaming __arm_inout("za");

as well as the corresponding `bf16` variants.

>From ee78ad565158c2d1301265415992511ea559e7a6 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Tue, 9 Apr 2024 10:52:41 +0100
Subject: [PATCH] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

void svmopa_za16[_f16]_m(uint64_t tile, svbool_t pn, svbool_t pm,
 svfloat16_t zn, svfloat16_t zm)
__arm_streaming __arm_inout("za");
void svmops_za16[_f16]_m(uint64_t tile, svbool_t pn,
 svbool_t pm, svfloat16_t zn, svfloat16_t zm)
__arm_streaming __arm_inout("za");

as well as the corresponding `bf16` variants.
---
 clang/include/clang/Basic/arm_sme.td  | 24 +
 .../acle_sme2_mopa_nonwide.c  | 97 +++
 .../acle_sme2_mopa_nonwide.c  | 34 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  5 +-
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td | 10 +-
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 16 ++-
 .../CodeGen/AArch64/sme2-intrinsics-mopa.ll   | 42 
 7 files changed, 220 insertions(+), 8 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
 create mode 100644 
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-mopa.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 1ac6d5170ea283..e60a400b094850 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -674,3 +674,27 @@ let TargetGuard = "sme2" in {
   def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
 }
+
+
+// SME2p1 - FMOPA, FMOPS (non-widening)
+let TargetGuard = "sme,b16b16" in {
+  def SVMOPA_BF16_NW : SInst<"svmopa_za16[_bf16]", "viPPdd", "b",
+ MergeOp1, "aarch64_sme_mopa_nonwide",
+ [IsStreaming, IsInOutZA],
+ [ImmCheck<0, ImmCheck0_1>]>;
+  def SVMOPS_BF16_NW : SInst<"svmops_za16[_bf16]", "viPPdd", "b",
+ MergeOp1, "aarch64_sme_mops_nonwide",
+ [IsStreaming, IsInOutZA],
+ [ImmCheck<0, ImmCheck0_1>]>;
+}
+
+let TargetGuard = "sme2,sme-f16f16" in {
+  def SVMOPA_F16_NW : SInst<"svmopa_za16[_f16]", "viPPdd", "h",
+MergeOp1, "aarch64_sme_mopa_nonwide",
+[IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_1>]>;
+  def SVMOPS_F16_NW : SInst<"svmops_za16[_f16]", "viPPdd", "h",
+MergeOp1, "aarch64_sme_mops_nonwide",
+[IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_1>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
new file mode 100644
index 00..36a75609534653
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c
@@ -0,0 +1,97 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1   -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK
+// RUN: %clang_cc1-x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature  +b16b16 
-target-feature +sme-f16f16 -S -O2 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK-CXX
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS-fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1 

[clang] 45aec9a - [NFC] [Serialization] Remove redundant hasPendingBody member

2024-04-09 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-09T17:50:23+08:00
New Revision: 45aec9a0b54e6d87abf75e960c96f59408edc706

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

LOG: [NFC] [Serialization] Remove redundant hasPendingBody member

The hasPendingBody member is redundant with the
PendingBodies.count(Decl*) method. This patch removes the redundant
hasPendingBody member and the corresponding InterestingDecl struct.

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 370d8037a4da17..1911252b34cd1c 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1089,27 +1089,13 @@ class ASTReader
   /// the last time we loaded information about this identifier.
   llvm::DenseMap IdentifierGeneration;
 
-  class InterestingDecl {
-Decl *D;
-bool DeclHasPendingBody;
-
-  public:
-InterestingDecl(Decl *D, bool HasBody)
-: D(D), DeclHasPendingBody(HasBody) {}
-
-Decl *getDecl() { return D; }
-
-/// Whether the declaration has a pending body.
-bool hasPendingBody() { return DeclHasPendingBody; }
-  };
-
   /// Contains declarations and definitions that could be
   /// "interesting" to the ASTConsumer, when we get that AST consumer.
   ///
   /// "Interesting" declarations are those that have data that may
   /// need to be emitted, such as inline function definitions or
   /// Objective-C protocols.
-  std::deque PotentiallyInterestingDecls;
+  std::deque PotentiallyInterestingDecls;
 
   /// The list of deduced function types that we have not yet read, because
   /// they might contain a deduced return type that refers to a local type

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index a22f760408c634..78448855fba09c 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -94,8 +94,6 @@ namespace clang {
 GlobalDeclID NamedDeclForTagDecl = 0;
 IdentifierInfo *TypedefNameForLinkage = nullptr;
 
-bool HasPendingBody = false;
-
 ///A flag to carry the information for a decl from the entity is
 /// used. We use it to delay the marking of the canonical decl as used 
until
 /// the entire declaration is deserialized and merged.
@@ -314,9 +312,6 @@ namespace clang {
 static void markIncompleteDeclChainImpl(Redeclarable *D);
 static void markIncompleteDeclChainImpl(...);
 
-/// Determine whether this declaration has a pending body.
-bool hasPendingBody() const { return HasPendingBody; }
-
 void ReadFunctionDefinition(FunctionDecl *FD);
 void Visit(Decl *D);
 
@@ -541,7 +536,6 @@ void ASTDeclReader::ReadFunctionDefinition(FunctionDecl 
*FD) {
   }
   // Store the offset of the body so we can lazily load it later.
   Reader.PendingBodies[FD] = GetCurrentCursorOffset();
-  HasPendingBody = true;
 }
 
 void ASTDeclReader::Visit(Decl *D) {
@@ -1164,7 +1158,6 @@ void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl 
*MD) {
 // Load the body on-demand. Most clients won't care, because method
 // definitions rarely show up in headers.
 Reader.PendingBodies[MD] = GetCurrentCursorOffset();
-HasPendingBody = true;
   }
   MD->setSelfDecl(readDeclAs());
   MD->setCmdDecl(readDeclAs());
@@ -4156,8 +4149,7 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
   // AST consumer might need to know about, queue it.
   // We don't pass it to the consumer immediately because we may be in 
recursive
   // loading, and some declarations may still be initializing.
-  PotentiallyInterestingDecls.push_back(
-  InterestingDecl(D, Reader.hasPendingBody()));
+  PotentiallyInterestingDecls.push_back(D);
 
   return D;
 }
@@ -4179,10 +4171,10 @@ void ASTReader::PassInterestingDeclsToConsumer() {
   EagerlyDeserializedDecls.clear();
 
   while (!PotentiallyInterestingDecls.empty()) {
-InterestingDecl D = PotentiallyInterestingDecls.front();
+Decl *D = PotentiallyInterestingDecls.front();
 PotentiallyInterestingDecls.pop_front();
-if (isConsumerInterestedIn(getContext(), D.getDecl(), D.hasPendingBody()))
-  PassInterestingDeclToConsumer(D.getDecl());
+if (isConsumerInterestedIn(getContext(), D, PendingBodies.count(D)))
+  PassInterestingDeclToConsumer(D);
   }
 }
 
@@ -4239,9 +4231,8 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord 
) {
   // We might have made this declaration interesting. If so, remember that
   // we need to hand it off to the consumer.
   if (!WasInteresting &&
-  isConsumerInterestedIn(getContext(), D, 

[clang] [clang] Catch missing format attributes (PR #70024)

2024-04-09 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovicsyrmia updated 
https://github.com/llvm/llvm-project/pull/70024

From 24d342d4d3a432a6f8e1e01e410a6e9dbeb5e0dd Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/Sema/SemaChecking.cpp   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 119 +++-
 clang/test/Sema/attr-format-missing.c | 244 
 clang/test/Sema/attr-format-missing.cpp   | 261 ++
 8 files changed, 634 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a84ff16a1e4d4..c6cd05da32332d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -381,6 +381,9 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now diagnoses missing format attributes for non-template functions and
+  class/struct/union members. Fixes #GH70024
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 520168f01fd846..5c6a69ff1586db 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -505,7 +505,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index df57f5e6ce11ba..d32bf4c8a9549e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1008,6 +1008,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8c98d8c7fef7a7..2bf2537027d728 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3885,6 +3885,10 @@ class Sema final {
   bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc,
  const ParsedAttr , bool IsAsync);
 
+  void DiagnoseMissingFormatAttributes(const FunctionDecl *FDecl,
+   ArrayRef Args,
+   SourceLocation Loc);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo ,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3dcd18b3afc8b4..77e01ba344e5a5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8034,8 +8034,10 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
-  if (FD)
+  if (FD) {
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
+DiagnoseMissingFormatAttributes(FD, Args, Range.getBegin());
+  }
 }
 
 /// CheckConstructorCall - Check a constructor call for correctness and safety
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 8bce04640e748e..4ea2167b1ed472 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -159,6 +159,13 @@ static bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+static bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 static inline bool isNSStringType(QualType T, ASTContext ,
   bool AllowNSAttributedString = false) {
   const auto *PT = T->getAs();
@@ -308,7 +315,7 

[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-04-09 Thread Pengcheng Wang via cfe-commits


@@ -7238,10 +7238,15 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   Args.addOptInFlag(CmdArgs, options::OPT_frelaxed_template_template_args,
 options::OPT_fno_relaxed_template_template_args);
 
-  // -fsized-deallocation is off by default, as it is an ABI-breaking change 
for
-  // most platforms.
-  Args.addOptInFlag(CmdArgs, options::OPT_fsized_deallocation,
-options::OPT_fno_sized_deallocation);
+  // -fsized-deallocation is on by default in C++14 onwards and otherwise off
+  // by default.
+  if (Arg *A = Args.getLastArg(options::OPT_fsized_deallocation,
+   options::OPT_fno_sized_deallocation)) {
+if (A->getOption().matches(options::OPT_fno_sized_deallocation))
+  CmdArgs.push_back("-fno-sized-deallocation");

wangpc-pp wrote:

I don't know if I understand correctly, but I think we need both clang and cc1 
options for `sized_deallocation`. Please see `aligned_allocation` case, which 
is the same as `sized_deallocation`:
https://github.com/llvm/llvm-project/blob/24e8c6a09b7d226dbe706aeae7aebf479a1e5087/clang/include/clang/Driver/Options.td#L3355-L3358
And there are a lot of tests assumed we have cc1 options 
`-fno-sized-deallocation` and `-fsized-deallocation` like 
[`clang/test/SemaCXX/builtin-operator-new-delete.cpp`](https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/builtin-operator-new-delete.cpp).

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


[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)

2024-04-09 Thread via cfe-commits

https://github.com/ealcdan updated 
https://github.com/llvm/llvm-project/pull/85060

>From 681f04d6cff2c1b2000deaee2f209dd73c1fc42d Mon Sep 17 00:00:00 2001
From: Daniel Alcaide Nombela 
Date: Wed, 13 Mar 2024 11:28:34 +0100
Subject: [PATCH] [clang-tidy] Avoid overflow when dumping unsigned integer
 values

Some options take the maximum unsigned integer value as default, but
they are being dumped to a string as integers. This makes -dump-config
write invalid '-1' values for these options. This change fixes this
issue by using utostr if the option is unsigned.

Change-Id: I551e6bc616071cf7aa10a8c0220d2076ed3d40e6
---
 clang-tools-extra/clang-tidy/ClangTidyCheck.cpp  |  6 ++
 clang-tools-extra/clang-tidy/ClangTidyCheck.h| 12 ++--
 .../infrastructure/Inputs/config-files/5/.clang-tidy |  4 
 .../test/clang-tidy/infrastructure/config-files.cpp  |  8 
 4 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy

diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 3e926236adb451..710b361e16c0a7 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -139,6 +139,12 @@ void 
ClangTidyCheck::OptionsView::storeInt(ClangTidyOptions::OptionMap ,
   store(Options, LocalName, llvm::itostr(Value));
 }
 
+void ClangTidyCheck::OptionsView::storeUnsigned(
+ClangTidyOptions::OptionMap , StringRef LocalName,
+uint64_t Value) const {
+  store(Options, LocalName, llvm::utostr(Value));
+}
+
 template <>
 void ClangTidyCheck::OptionsView::store(
 ClangTidyOptions::OptionMap , StringRef LocalName,
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
index 656a2f008f6e0e..0654aec3b9a7f6 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -411,7 +411,10 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 std::enable_if_t>
 store(ClangTidyOptions::OptionMap , StringRef LocalName,
   T Value) const {
-  storeInt(Options, LocalName, Value);
+  if constexpr (std::is_signed_v)
+storeInt(Options, LocalName, Value);
+  else
+storeUnsigned(Options, LocalName, Value);
 }
 
 /// Stores an option with the check-local name \p LocalName with
@@ -422,7 +425,10 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 store(ClangTidyOptions::OptionMap , StringRef LocalName,
   std::optional Value) const {
   if (Value)
-storeInt(Options, LocalName, *Value);
+if constexpr (std::is_signed_v)
+  storeInt(Options, LocalName, *Value);
+else
+  storeUnsigned(Options, LocalName, *Value);
   else
 store(Options, LocalName, "none");
 }
@@ -470,6 +476,8 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 void storeInt(ClangTidyOptions::OptionMap , StringRef LocalName,
   int64_t Value) const;
 
+void storeUnsigned(ClangTidyOptions::OptionMap ,
+   StringRef LocalName, uint64_t Value) const;
 
 std::string NamePrefix;
 const ClangTidyOptions::OptionMap 
diff --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy
new file mode 100644
index 00..e33f0f8bb33218
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy
@@ -0,0 +1,4 @@
+InheritParentConfig: true
+Checks: 'misc-throw-by-value-catch-by-reference'
+CheckOptions:
+  misc-throw-by-value-catch-by-reference.MaxSize: '1152921504606846976'
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
index ab4f3becb7a9fc..cb0f0bc4d13308 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
@@ -64,3 +64,11 @@
 
 // Validate that check options are printed in alphabetical order:
 // RUN: clang-tidy --checks="-*,readability-identifier-naming" --dump-config 
%S/Inputs/config-files/- -- | grep "readability-identifier-naming\." | sort 
--check
+
+// Dumped config does not overflow for unsigned options
+// RUN: clang-tidy --dump-config \
+// RUN: --checks="-*,misc-throw-by-value-catch-by-reference" \
+// RUN: -- | grep -v -q "misc-throw-by-value-catch-by-reference.MaxSize: '-1'"
+
+// RUN: clang-tidy --dump-config %S/Inputs/config-files/5/- \
+// RUN: -- | grep -q "misc-throw-by-value-catch-by-reference.MaxSize: 
'1152921504606846976'"

___
cfe-commits mailing list

[clang] [clang] Improve source location in binary type traits diagnostics (PR #88097)

2024-04-09 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> Do we now have enough information to pass a source range as well?

Yes, `TypeLoc` inside `TypeSourceInfo` has two `SourceLocation` object that 
represent the range.
In order to limit the scope of the PR, I'm not refactoring 
`RequireCompleteType` and friends to accept `TypeSourceInfo`, but that's an 
obvious next step. Diagnostics would benefit from source range.

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


[clang] [clang] Improve source location in binary type traits diagnostics (PR #88097)

2024-04-09 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Do we now have enough information to pass a source range as well?

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


[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-09 Thread Fraser Cormack via cfe-commits

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

>From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 3 Apr 2024 16:09:30 +0100
Subject: [PATCH 1/3] [libclc] Refactor build system to allow in-tree builds

The previous build system was adding custom "OpenCL" and "LLVM IR"
languages in CMake to build the builtin libraries. This was making it
harder to build in-tree because the tool binaries needed to be present
at configure time.

This commit refactors the build system to use custom commands to build
the bytecode files one by one, and link them all together into the final
bytecode library. It also enables in-tree builds by aliasing the
clang/llvm-link/etc. tool targets to internal targets, which are
imported from the LLVM installation directory when building out of tree.

Diffing (with llvm-diff) all of the final bytecode libraries in an
out-of-tree configuration against those built using the current tip
system shows no changes. Note that there are textual changes to metadata
IDs which confuse regular diff, and that llvm-diff 14 and below may show
false-positives.

This commit also removes a file listed in one of the SOURCEs which
didn't exist and which was preventing the use of
ENABLE_RUNTIME_SUBNORMAL when configuring CMake.
---
 libclc/CMakeLists.txt | 257 ++
 libclc/cmake/CMakeCLCCompiler.cmake.in|   9 -
 libclc/cmake/CMakeCLCInformation.cmake|  12 -
 libclc/cmake/CMakeDetermineCLCCompiler.cmake  |  18 --
 .../cmake/CMakeDetermineLLAsmCompiler.cmake   |  24 --
 libclc/cmake/CMakeLLAsmCompiler.cmake.in  |  10 -
 libclc/cmake/CMakeLLAsmInformation.cmake  |  12 -
 libclc/cmake/CMakeTestCLCCompiler.cmake   |  56 
 libclc/cmake/CMakeTestLLAsmCompiler.cmake |  56 
 libclc/cmake/modules/AddLibclc.cmake  | 153 +++
 libclc/generic/lib/SOURCES|   1 -
 llvm/tools/CMakeLists.txt |   3 +
 12 files changed, 305 insertions(+), 306 deletions(-)
 delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake
 delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake
 create mode 100644 libclc/cmake/modules/AddLibclc.cmake

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c6e3cdf23fe0c8..ff4e4369a7af39 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C)
 
 set(CMAKE_CXX_STANDARD 17)
 
+# Add path for custom modules
+list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" )
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
+set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
+
+include( AddLibclc )
+
 include( GNUInstallDirs )
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   amdgcn-amdhsa/lib/SOURCES;
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DIR )
+  # Out-of-tree configuration
+  set( LIBCLC_STANDALONE_BUILD TRUE )
 
-message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
+  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+  include(AddLLVM)
 
-if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
-  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
-endif()
+  message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
+message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  endif()
 
-# Print toolchain
-message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" )
-message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" )
-message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" )
-message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" )
-message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" )
-if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR 

[clang] 4ae33c5 - Fix MSVC "switch statement contains 'default' but no 'case' labels" warning. NFC.

2024-04-09 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2024-04-09T09:59:57+01:00
New Revision: 4ae33c52f794dbd64924dd006570cdc409c297bc

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

LOG: Fix MSVC "switch statement contains 'default' but no 'case' labels" 
warning. NFC.

Added: 


Modified: 
clang/lib/Sema/SemaOpenACC.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index f520b9bfe81193..2ba1e49b5739db 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -39,14 +39,11 @@ bool diagnoseConstructAppertainment(SemaOpenACC , 
OpenACCDirectiveKind K,
 
 bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind,
 OpenACCClauseKind ClauseKind) {
-  switch (ClauseKind) {
-// FIXME: For each clause as we implement them, we can add the
-// 'legalization' list here.
-  default:
-// Do nothing so we can go to the 'unimplemented' diagnostic instead.
-return true;
-  }
-  llvm_unreachable("Invalid clause kind");
+  // FIXME: For each clause as we implement them, we can add the
+  // 'legalization' list here.
+
+  // Do nothing so we can go to the 'unimplemented' diagnostic instead.
+  return true;
 }
 } // namespace
 



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


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-09 Thread via cfe-commits

Sirraide wrote:

> did you see this comment? [#86526 
> (review)](https://github.com/llvm/llvm-project/pull/86526#pullrequestreview-1976690810)

Thanks for reminding me; I did see that one but ended up forgetting about it 
because I was sick for pretty much all of last week; I’ll take a look at it 
later.


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


[clang] [llvm] [PowerPC] Implement 32-bit expansion for rldimi (PR #86783)

2024-04-09 Thread Qiu Chaofan via cfe-commits

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


[clang] a4558a4 - [PowerPC] Implement 32-bit expansion for rldimi (#86783)

2024-04-09 Thread via cfe-commits

Author: Qiu Chaofan
Date: 2024-04-09T16:43:49+08:00
New Revision: a4558a4a53eda8d170bbd2c358d383bb0a13f91f

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

LOG: [PowerPC] Implement 32-bit expansion for rldimi (#86783)

rldimi is 64-bit instruction, due to backward compatibility, it needs to
be expanded into series of rotate and masking in 32-bit environment. In
the future, we may improve bit permutation selector and remove such
direct codegen.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c
llvm/include/llvm/IR/IntrinsicsPowerPC.td
llvm/test/CodeGen/PowerPC/rldimi.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index df7502b8def531..c052367d287820 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17288,6 +17288,16 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 Value *Op1 = EmitScalarExpr(E->getArg(1));
 Value *Op2 = EmitScalarExpr(E->getArg(2));
 Value *Op3 = EmitScalarExpr(E->getArg(3));
+// rldimi is 64-bit instruction, expand the intrinsic before isel to
+// leverage peephole and avoid legalization efforts.
+if (BuiltinID == PPC::BI__builtin_ppc_rldimi &&
+!getTarget().getTriple().isPPC64()) {
+  Function *F = CGM.getIntrinsic(Intrinsic::fshl, Op0->getType());
+  Op2 = Builder.CreateZExt(Op2, Int64Ty);
+  Value *Shift = Builder.CreateCall(F, {Op0, Op0, Op2});
+  return Builder.CreateOr(Builder.CreateAnd(Shift, Op3),
+  Builder.CreateAnd(Op1, Builder.CreateNot(Op3)));
+}
 return Builder.CreateCall(
 CGM.getIntrinsic(BuiltinID == PPC::BI__builtin_ppc_rldimi
  ? Intrinsic::ppc_rldimi

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f4746647b96546..b84a779b7189c0 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5232,7 +5232,6 @@ static bool isPPC_64Builtin(unsigned BuiltinID) {
   case PPC::BI__builtin_ppc_fetch_and_andlp:
   case PPC::BI__builtin_ppc_fetch_and_orlp:
   case PPC::BI__builtin_ppc_fetch_and_swaplp:
-  case PPC::BI__builtin_ppc_rldimi:
 return true;
   }
   return false;

diff  --git a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c
index 272e0222dc9e41..f7f357df62af16 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c
@@ -24,7 +24,6 @@ void test_trap(void) {
   __tw(ia, ib, 0); //expected-error {{argument value 0 is outside the valid 
range [1, 31]}}
 }
 
-#ifdef __PPC64__
 void test_builtin_ppc_rldimi() {
   unsigned int shift;
   unsigned long long mask;
@@ -33,7 +32,6 @@ void test_builtin_ppc_rldimi() {
   res = __builtin_ppc_rldimi(ull, ull, 63, 0x0F00);  // 
expected-error {{argument 3 value should represent a contiguous bit field}}
   res = __builtin_ppc_rldimi(ull, ull, 64, 0x);  // 
expected-error {{argument value 64 is outside the valid range [0, 63]}}
 }
-#endif
 
 void test_builtin_ppc_rlwimi() {
   unsigned int shift;
@@ -86,10 +84,6 @@ void testalignx(const void *pointer, unsigned int alignment) 
{
 }
 
 #ifndef __PPC64__
-unsigned long long testrldimi32() {
-  return __rldimi(ull, ui, 3, 0x78ULL); //expected-error {{this builtin is 
only available on 64-bit targets}}
-}
-
 long long testbpermd(long long bit_selector, long long source) {
   return __bpermd(bit_selector, source); //expected-error {{this builtin is 
only available on 64-bit targets}}
 }

diff  --git a/llvm/include/llvm/IR/IntrinsicsPowerPC.td 
b/llvm/include/llvm/IR/IntrinsicsPowerPC.td
index ee9a04241ac2ec..aff1fc7f085c43 100644
--- a/llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ b/llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -182,10 +182,6 @@ let TargetPrefix = "ppc" in {  // All intrinsics start 
with "llvm.ppc.".
   def int_ppc_fctuwz
   : ClangBuiltin<"__builtin_ppc_fctuwz">,
 DefaultAttrsIntrinsic<[llvm_double_ty], [llvm_double_ty], [IntrNoMem]>;
-  def int_ppc_rldimi
-  : ClangBuiltin<"__builtin_ppc_rldimi">,
-DefaultAttrsIntrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty, 
llvm_i32_ty, llvm_i64_ty],
-  [IntrNoMem, ImmArg>, 
ImmArg>]>;
   def int_ppc_rlwimi
   : ClangBuiltin<"__builtin_ppc_rlwimi">,
 DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, 
llvm_i32_ty, llvm_i32_ty],
@@ -194,6 +190,9 @@ let TargetPrefix = "ppc" in {  // All intrinsics start with 
"llvm.ppc.".
   : 

[clang] [compiler-rt] Fix "[clang][UBSan] Add implicit conversion check for bitfields" (PR #87761)

2024-04-09 Thread Axel Lundberg via cfe-commits


@@ -0,0 +1,94 @@
+// RUN: %clang -x c++ -fsanitize=implicit-bitfield-conversion -target 
x86_64-linux -S -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-BITFIELD-CONVERSION
+// RUN: %clang -x c++ -fsanitize=implicit-integer-conversion -target 
x86_64-linux -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang -x c++ -fsanitize=implicit-conversion -target x86_64-linux -S 
-emit-llvm -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-BITFIELD-CONVERSION
+
+struct S {
+  int a:3;
+  char b:2;
+};
+
+class C : public S {
+  public:
+short c:3;
+};
+
+S s;
+C c;
+
+// CHECK-LABEL: define{{.*}} void @{{.*foo1.*}}
+void foo1(int x) {
+  s.a = x;
+  // CHECK: store i8 %{{.*}}
+  // CHECK-BITFIELD-CONVERSION: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 5
+  // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 
[[BFRESULTSHL]], 5
+  // CHECK-BITFIELD-CONVERSION-NEXT: [[BFRESULTCAST:%.*]] = sext i8 
[[BFRESULTASHR]] to i32
+  // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
+  // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize !6

Zonotora wrote:

No, feel free to update

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


[clang] [clang] Improve source location in binary type traits diagnostics (PR #88097)

2024-04-09 Thread via cfe-commits

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


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


[clang] [SEH] Ignore async exception flag when the environment is not MSVC (PR #88101)

2024-04-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Phoebe Wang (phoebewang)


Changes

Fixes #62449

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+20-8) 
- (added) clang/test/Driver/windows-seh-async-verify.cpp (+24) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 766a9b91e3c0ad..c1ed4bd2dcda06 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -346,11 +346,14 @@ static bool addExceptionArgs(const ArgList , 
types::ID InputType,
   bool EH = Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
  false);
 
-  bool EHa = Args.hasFlag(options::OPT_fasync_exceptions,
-  options::OPT_fno_async_exceptions, false);
-  if (EHa) {
-CmdArgs.push_back("-fasync-exceptions");
-EH = true;
+  // Async exceptions are Windows MSVC only.
+  if (Triple.isWindowsMSVCEnvironment()) {
+bool EHa = Args.hasFlag(options::OPT_fasync_exceptions,
+options::OPT_fno_async_exceptions, false);
+if (EHa) {
+  CmdArgs.push_back("-fasync-exceptions");
+  EH = true;
+}
   }
 
   // Obj-C exceptions are enabled by default, regardless of -fexceptions. This
@@ -8084,7 +8087,8 @@ struct EHFlags {
 ///  The 'a' modifier is unimplemented and fundamentally hard in LLVM IR.
 /// - c: Assume that extern "C" functions are implicitly nounwind.
 /// The default is /EHs-c-, meaning cleanups are disabled.
-static EHFlags parseClangCLEHFlags(const Driver , const ArgList ) {
+static EHFlags parseClangCLEHFlags(const Driver , const ArgList ,
+   bool isWindowsMSVC) {
   EHFlags EH;
 
   std::vector EHArgs =
@@ -8094,8 +8098,15 @@ static EHFlags parseClangCLEHFlags(const Driver , 
const ArgList ) {
   switch (EHVal[I]) {
   case 'a':
 EH.Asynch = maybeConsumeDash(EHVal, I);
-if (EH.Asynch)
+if (EH.Asynch) {
+  // Async exceptions are Windows MSVC only.
+  if (!isWindowsMSVC) {
+EH.Asynch = false;
+D.Diag(clang::diag::warn_drv_unused_argument) << "/EHa" << EHVal;
+continue;
+  }
   EH.Synch = false;
+}
 continue;
   case 'c':
 EH.NoUnwindC = maybeConsumeDash(EHVal, I);
@@ -8159,7 +8170,8 @@ void Clang::AddClangCLArgs(const ArgList , types::ID 
InputType,
 
   const Driver  = getToolChain().getDriver();
 
-  EHFlags EH = parseClangCLEHFlags(D, Args);
+  bool IsWindowsMSVC = getToolChain().getTriple().isWindowsMSVCEnvironment();
+  EHFlags EH = parseClangCLEHFlags(D, Args, IsWindowsMSVC);
   if (!isNVPTX && (EH.Synch || EH.Asynch)) {
 if (types::isCXX(InputType))
   CmdArgs.push_back("-fcxx-exceptions");
diff --git a/clang/test/Driver/windows-seh-async-verify.cpp 
b/clang/test/Driver/windows-seh-async-verify.cpp
new file mode 100644
index 00..5fda6a77dba049
--- /dev/null
+++ b/clang/test/Driver/windows-seh-async-verify.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang --target=x86_64-pc-windows -fasync-exceptions -fsyntax-only %s 
-### 2>&1 | FileCheck %s
+// RUN: %clang_cl --target=x86_64-pc-windows /EHa -fsyntax-only %s -### 2>&1 | 
FileCheck %s
+// RUN: %clang --target=x86_64-pc-windows-gnu -fasync-exceptions -fsyntax-only 
%s -### 2>&1 | FileCheck %s --check-prefixes=GNU-ALL,GNU
+// RUN: %clang_cl --target=x86_64-pc-windows-gnu /EHa -fsyntax-only %s -### 
2>&1 | FileCheck %s --check-prefixes=GNU-ALL,CL-GNU
+
+// CHECK-NOT: warning
+// GNU: warning: argument unused during compilation: '-fasync-exceptions' 
[-Wunused-command-line-argument]
+// CL-GNU: warning: argument unused during compilation: '/EHa' 
[-Wunused-command-line-argument]
+
+// CHECK: -fasync-exceptions
+// GNU-ALL-NOT: -fasync-exceptions
+struct S {
+union _Un {
+~_Un() {}
+char _Buf[12];
+};
+_Un _un;
+};
+
+struct Embed {
+S v2;
+};
+
+void PR62449() { Embed v{}; }

``




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


[clang] [SEH] Ignore async exception flag when the environment is not MSVC (PR #88101)

2024-04-09 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang created 
https://github.com/llvm/llvm-project/pull/88101

Fixes #62449

>From 66c4383e58cab7cf893edfa3f3507be166116fa6 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Tue, 9 Apr 2024 16:08:55 +0800
Subject: [PATCH] [SEH] Ignore async exception flag when the environment is not
 MSVC

Fixes #62449
---
 clang/lib/Driver/ToolChains/Clang.cpp | 28 +--
 .../test/Driver/windows-seh-async-verify.cpp  | 24 
 2 files changed, 44 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/Driver/windows-seh-async-verify.cpp

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 766a9b91e3c0ad..c1ed4bd2dcda06 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -346,11 +346,14 @@ static bool addExceptionArgs(const ArgList , 
types::ID InputType,
   bool EH = Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
  false);
 
-  bool EHa = Args.hasFlag(options::OPT_fasync_exceptions,
-  options::OPT_fno_async_exceptions, false);
-  if (EHa) {
-CmdArgs.push_back("-fasync-exceptions");
-EH = true;
+  // Async exceptions are Windows MSVC only.
+  if (Triple.isWindowsMSVCEnvironment()) {
+bool EHa = Args.hasFlag(options::OPT_fasync_exceptions,
+options::OPT_fno_async_exceptions, false);
+if (EHa) {
+  CmdArgs.push_back("-fasync-exceptions");
+  EH = true;
+}
   }
 
   // Obj-C exceptions are enabled by default, regardless of -fexceptions. This
@@ -8084,7 +8087,8 @@ struct EHFlags {
 ///  The 'a' modifier is unimplemented and fundamentally hard in LLVM IR.
 /// - c: Assume that extern "C" functions are implicitly nounwind.
 /// The default is /EHs-c-, meaning cleanups are disabled.
-static EHFlags parseClangCLEHFlags(const Driver , const ArgList ) {
+static EHFlags parseClangCLEHFlags(const Driver , const ArgList ,
+   bool isWindowsMSVC) {
   EHFlags EH;
 
   std::vector EHArgs =
@@ -8094,8 +8098,15 @@ static EHFlags parseClangCLEHFlags(const Driver , 
const ArgList ) {
   switch (EHVal[I]) {
   case 'a':
 EH.Asynch = maybeConsumeDash(EHVal, I);
-if (EH.Asynch)
+if (EH.Asynch) {
+  // Async exceptions are Windows MSVC only.
+  if (!isWindowsMSVC) {
+EH.Asynch = false;
+D.Diag(clang::diag::warn_drv_unused_argument) << "/EHa" << EHVal;
+continue;
+  }
   EH.Synch = false;
+}
 continue;
   case 'c':
 EH.NoUnwindC = maybeConsumeDash(EHVal, I);
@@ -8159,7 +8170,8 @@ void Clang::AddClangCLArgs(const ArgList , types::ID 
InputType,
 
   const Driver  = getToolChain().getDriver();
 
-  EHFlags EH = parseClangCLEHFlags(D, Args);
+  bool IsWindowsMSVC = getToolChain().getTriple().isWindowsMSVCEnvironment();
+  EHFlags EH = parseClangCLEHFlags(D, Args, IsWindowsMSVC);
   if (!isNVPTX && (EH.Synch || EH.Asynch)) {
 if (types::isCXX(InputType))
   CmdArgs.push_back("-fcxx-exceptions");
diff --git a/clang/test/Driver/windows-seh-async-verify.cpp 
b/clang/test/Driver/windows-seh-async-verify.cpp
new file mode 100644
index 00..5fda6a77dba049
--- /dev/null
+++ b/clang/test/Driver/windows-seh-async-verify.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang --target=x86_64-pc-windows -fasync-exceptions -fsyntax-only %s 
-### 2>&1 | FileCheck %s
+// RUN: %clang_cl --target=x86_64-pc-windows /EHa -fsyntax-only %s -### 2>&1 | 
FileCheck %s
+// RUN: %clang --target=x86_64-pc-windows-gnu -fasync-exceptions -fsyntax-only 
%s -### 2>&1 | FileCheck %s --check-prefixes=GNU-ALL,GNU
+// RUN: %clang_cl --target=x86_64-pc-windows-gnu /EHa -fsyntax-only %s -### 
2>&1 | FileCheck %s --check-prefixes=GNU-ALL,CL-GNU
+
+// CHECK-NOT: warning
+// GNU: warning: argument unused during compilation: '-fasync-exceptions' 
[-Wunused-command-line-argument]
+// CL-GNU: warning: argument unused during compilation: '/EHa' 
[-Wunused-command-line-argument]
+
+// CHECK: -fasync-exceptions
+// GNU-ALL-NOT: -fasync-exceptions
+struct S {
+union _Un {
+~_Un() {}
+char _Buf[12];
+};
+_Un _un;
+};
+
+struct Embed {
+S v2;
+};
+
+void PR62449() { Embed v{}; }

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


[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-09 Thread Fraser Cormack via cfe-commits

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

>From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 3 Apr 2024 16:09:30 +0100
Subject: [PATCH 1/2] [libclc] Refactor build system to allow in-tree builds

The previous build system was adding custom "OpenCL" and "LLVM IR"
languages in CMake to build the builtin libraries. This was making it
harder to build in-tree because the tool binaries needed to be present
at configure time.

This commit refactors the build system to use custom commands to build
the bytecode files one by one, and link them all together into the final
bytecode library. It also enables in-tree builds by aliasing the
clang/llvm-link/etc. tool targets to internal targets, which are
imported from the LLVM installation directory when building out of tree.

Diffing (with llvm-diff) all of the final bytecode libraries in an
out-of-tree configuration against those built using the current tip
system shows no changes. Note that there are textual changes to metadata
IDs which confuse regular diff, and that llvm-diff 14 and below may show
false-positives.

This commit also removes a file listed in one of the SOURCEs which
didn't exist and which was preventing the use of
ENABLE_RUNTIME_SUBNORMAL when configuring CMake.
---
 libclc/CMakeLists.txt | 257 ++
 libclc/cmake/CMakeCLCCompiler.cmake.in|   9 -
 libclc/cmake/CMakeCLCInformation.cmake|  12 -
 libclc/cmake/CMakeDetermineCLCCompiler.cmake  |  18 --
 .../cmake/CMakeDetermineLLAsmCompiler.cmake   |  24 --
 libclc/cmake/CMakeLLAsmCompiler.cmake.in  |  10 -
 libclc/cmake/CMakeLLAsmInformation.cmake  |  12 -
 libclc/cmake/CMakeTestCLCCompiler.cmake   |  56 
 libclc/cmake/CMakeTestLLAsmCompiler.cmake |  56 
 libclc/cmake/modules/AddLibclc.cmake  | 153 +++
 libclc/generic/lib/SOURCES|   1 -
 llvm/tools/CMakeLists.txt |   3 +
 12 files changed, 305 insertions(+), 306 deletions(-)
 delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake
 delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake
 create mode 100644 libclc/cmake/modules/AddLibclc.cmake

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c6e3cdf23fe0c8..ff4e4369a7af39 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C)
 
 set(CMAKE_CXX_STANDARD 17)
 
+# Add path for custom modules
+list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" )
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
+set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
+
+include( AddLibclc )
+
 include( GNUInstallDirs )
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   amdgcn-amdhsa/lib/SOURCES;
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DIR )
+  # Out-of-tree configuration
+  set( LIBCLC_STANDALONE_BUILD TRUE )
 
-message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
+  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+  include(AddLLVM)
 
-if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
-  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
-endif()
+  message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
+message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  endif()
 
-# Print toolchain
-message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" )
-message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" )
-message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" )
-message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" )
-message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" )
-if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR 

[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-09 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

CC @mgorny -  I was unsure whether you are actively using and interested 
`libclc` or you were just looking after build bots or some other reason. I've 
successfully built the SPIR-V libraries out-of-tree but another pair of eyes 
can't hurt.

I was wondering - if we `libclc` building in-tree, would there be interest in 
building the SPIR-V targets with the LLVM SPIRV backend, rather than the 
external `llvm-spirv` tool?

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


[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-09 Thread Fraser Cormack via cfe-commits

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

>From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 3 Apr 2024 16:09:30 +0100
Subject: [PATCH] [libclc] Refactor build system to allow in-tree builds

The previous build system was adding custom "OpenCL" and "LLVM IR"
languages in CMake to build the builtin libraries. This was making it
harder to build in-tree because the tool binaries needed to be present
at configure time.

This commit refactors the build system to use custom commands to build
the bytecode files one by one, and link them all together into the final
bytecode library. It also enables in-tree builds by aliasing the
clang/llvm-link/etc. tool targets to internal targets, which are
imported from the LLVM installation directory when building out of tree.

Diffing (with llvm-diff) all of the final bytecode libraries in an
out-of-tree configuration against those built using the current tip
system shows no changes. Note that there are textual changes to metadata
IDs which confuse regular diff, and that llvm-diff 14 and below may show
false-positives.

This commit also removes a file listed in one of the SOURCEs which
didn't exist and which was preventing the use of
ENABLE_RUNTIME_SUBNORMAL when configuring CMake.
---
 libclc/CMakeLists.txt | 257 ++
 libclc/cmake/CMakeCLCCompiler.cmake.in|   9 -
 libclc/cmake/CMakeCLCInformation.cmake|  12 -
 libclc/cmake/CMakeDetermineCLCCompiler.cmake  |  18 --
 .../cmake/CMakeDetermineLLAsmCompiler.cmake   |  24 --
 libclc/cmake/CMakeLLAsmCompiler.cmake.in  |  10 -
 libclc/cmake/CMakeLLAsmInformation.cmake  |  12 -
 libclc/cmake/CMakeTestCLCCompiler.cmake   |  56 
 libclc/cmake/CMakeTestLLAsmCompiler.cmake |  56 
 libclc/cmake/modules/AddLibclc.cmake  | 153 +++
 libclc/generic/lib/SOURCES|   1 -
 llvm/tools/CMakeLists.txt |   3 +
 12 files changed, 305 insertions(+), 306 deletions(-)
 delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake
 delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake
 create mode 100644 libclc/cmake/modules/AddLibclc.cmake

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c6e3cdf23fe0c8..ff4e4369a7af39 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C)
 
 set(CMAKE_CXX_STANDARD 17)
 
+# Add path for custom modules
+list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" )
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
+set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
+
+include( AddLibclc )
+
 include( GNUInstallDirs )
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   amdgcn-amdhsa/lib/SOURCES;
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DIR )
+  # Out-of-tree configuration
+  set( LIBCLC_STANDALONE_BUILD TRUE )
 
-message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
+  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+  include(AddLLVM)
 
-if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
-  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
-endif()
+  message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
+message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  endif()
 
-# Print toolchain
-message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" )
-message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" )
-message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" )
-message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" )
-message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" )
-if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT 

[clang] [clang] Improve source location in binary type traits diagnostics (PR #88097)

2024-04-09 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/88097

>From 3bc2d71cbe5e5613b430968fe84023a736072e54 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Tue, 9 Apr 2024 10:20:10 +0300
Subject: [PATCH 1/2] [clang] Improve source location in binary type traits
 diagnostics

---
 clang/lib/Sema/SemaExprCXX.cpp | 21 -
 clang/test/SemaCXX/type-traits.cpp |  1 +
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index dee6b658cd0054..7d7be27a862c2a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5843,7 +5843,7 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
 return false;
 
   if (Self.RequireCompleteType(
-  KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr))
+  Rhs->getTypeLoc().getBeginLoc(), RhsT, 
diag::err_incomplete_type_used_in_type_trait_expr))
 return false;
 
   return BaseInterface->isSuperClassOf(DerivedInterface);
@@ -5866,7 +5866,7 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
 //   If Base and Derived are class types and are different types
 //   (ignoring possible cv-qualifiers) then Derived shall be a
 //   complete type.
-if (Self.RequireCompleteType(KeyLoc, RhsT,
+if (Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
   diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 
@@ -5919,7 +5919,7 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
   return LhsT->isVoidType();
 
 // A function definition requires a complete, non-abstract return type.
-if (!Self.isCompleteType(KeyLoc, RhsT) || Self.isAbstractType(KeyLoc, 
RhsT))
+if (!Self.isCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT) || 
Self.isAbstractType(Rhs->getTypeLoc().getBeginLoc(), RhsT))
   return false;
 
 // Compute the result of add_rvalue_reference.
@@ -5969,11 +5969,11 @@ static bool EvaluateBinaryTypeTrait(Sema , 
TypeTrait BTT, const TypeSourceI
 //   For both, T and U shall be complete types, (possibly cv-qualified)
 //   void, or arrays of unknown bound.
 if (!LhsT->isVoidType() && !LhsT->isIncompleteArrayType() &&
-Self.RequireCompleteType(KeyLoc, LhsT,
+Self.RequireCompleteType(Lhs->getTypeLoc().getBeginLoc(), LhsT,
   diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 if (!RhsT->isVoidType() && !RhsT->isIncompleteArrayType() &&
-Self.RequireCompleteType(KeyLoc, RhsT,
+Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
   diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 
@@ -6029,12 +6029,15 @@ static bool EvaluateBinaryTypeTrait(Sema , 
TypeTrait BTT, const TypeSourceI
   }
   case BTT_IsLayoutCompatible: {
 if (!LhsT->isVoidType() && !LhsT->isIncompleteArrayType())
-  Self.RequireCompleteType(KeyLoc, LhsT, diag::err_incomplete_type);
+  Self.RequireCompleteType(Lhs->getTypeLoc().getBeginLoc(), LhsT, 
diag::err_incomplete_type);
 if (!RhsT->isVoidType() && !RhsT->isIncompleteArrayType())
-  Self.RequireCompleteType(KeyLoc, RhsT, diag::err_incomplete_type);
+  Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT, 
diag::err_incomplete_type);
 
-if (LhsT->isVariableArrayType() || RhsT->isVariableArrayType())
-  Self.Diag(KeyLoc, diag::err_vla_unsupported)
+if (LhsT->isVariableArrayType())
+  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
+  << 1 << tok::kw___is_layout_compatible;
+if (RhsT->isVariableArrayType())
+  Self.Diag(Rhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
   << 1 << tok::kw___is_layout_compatible;
 return Self.IsLayoutCompatible(LhsT, RhsT);
   }
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index e29763714341e7..421d3007d27ffe 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1759,6 +1759,7 @@ void is_layout_compatible(int n)
   // expected-error@-1 {{variable length arrays are not supported in 
'__is_layout_compatible'}}
   static_assert(!__is_layout_compatible(int[n], int[n]));
   // expected-error@-1 {{variable length arrays are not supported in 
'__is_layout_compatible'}}
+  // expected-error@-2 {{variable length arrays are not supported in 
'__is_layout_compatible'}}
   static_assert(__is_layout_compatible(int&, int&));
   static_assert(!__is_layout_compatible(int&, char&));
   static_assert(__is_layout_compatible(void(int), void(int)));

>From 7767807a6eef31010e72a803b171b1d43b44fcca Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Tue, 9 Apr 2024 10:32:36 +0300
Subject: [PATCH 2/2] Run clang-format

---
 clang/lib/Sema/SemaExprCXX.cpp | 27 

[clang] [clang] Improve source location in binary type traits diagnostics (PR #88097)

2024-04-09 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff c7db450e5c1a83ea768765dcdedfd50f3358d418 
3bc2d71cbe5e5613b430968fe84023a736072e54 -- clang/lib/Sema/SemaExprCXX.cpp 
clang/test/SemaCXX/type-traits.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 7d7be27a86..ed18c9021e 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5843,7 +5843,8 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
 return false;
 
   if (Self.RequireCompleteType(
-  Rhs->getTypeLoc().getBeginLoc(), RhsT, 
diag::err_incomplete_type_used_in_type_trait_expr))
+  Rhs->getTypeLoc().getBeginLoc(), RhsT,
+  diag::err_incomplete_type_used_in_type_trait_expr))
 return false;
 
   return BaseInterface->isSuperClassOf(DerivedInterface);
@@ -5866,8 +5867,9 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
 //   If Base and Derived are class types and are different types
 //   (ignoring possible cv-qualifiers) then Derived shall be a
 //   complete type.
-if (Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
-  diag::err_incomplete_type_used_in_type_trait_expr))
+if (Self.RequireCompleteType(
+Rhs->getTypeLoc().getBeginLoc(), RhsT,
+diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 
 return cast(rhsRecord->getDecl())
@@ -5919,7 +5921,8 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
   return LhsT->isVoidType();
 
 // A function definition requires a complete, non-abstract return type.
-if (!Self.isCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT) || 
Self.isAbstractType(Rhs->getTypeLoc().getBeginLoc(), RhsT))
+if (!Self.isCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT) ||
+Self.isAbstractType(Rhs->getTypeLoc().getBeginLoc(), RhsT))
   return false;
 
 // Compute the result of add_rvalue_reference.
@@ -5969,12 +5972,14 @@ static bool EvaluateBinaryTypeTrait(Sema , 
TypeTrait BTT, const TypeSourceI
 //   For both, T and U shall be complete types, (possibly cv-qualified)
 //   void, or arrays of unknown bound.
 if (!LhsT->isVoidType() && !LhsT->isIncompleteArrayType() &&
-Self.RequireCompleteType(Lhs->getTypeLoc().getBeginLoc(), LhsT,
-  diag::err_incomplete_type_used_in_type_trait_expr))
+Self.RequireCompleteType(
+Lhs->getTypeLoc().getBeginLoc(), LhsT,
+diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 if (!RhsT->isVoidType() && !RhsT->isIncompleteArrayType() &&
-Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
-  diag::err_incomplete_type_used_in_type_trait_expr))
+Self.RequireCompleteType(
+Rhs->getTypeLoc().getBeginLoc(), RhsT,
+diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 
 // cv void is never assignable.
@@ -6029,9 +6034,11 @@ static bool EvaluateBinaryTypeTrait(Sema , 
TypeTrait BTT, const TypeSourceI
   }
   case BTT_IsLayoutCompatible: {
 if (!LhsT->isVoidType() && !LhsT->isIncompleteArrayType())
-  Self.RequireCompleteType(Lhs->getTypeLoc().getBeginLoc(), LhsT, 
diag::err_incomplete_type);
+  Self.RequireCompleteType(Lhs->getTypeLoc().getBeginLoc(), LhsT,
+   diag::err_incomplete_type);
 if (!RhsT->isVoidType() && !RhsT->isIncompleteArrayType())
-  Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT, 
diag::err_incomplete_type);
+  Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
+   diag::err_incomplete_type);
 
 if (LhsT->isVariableArrayType())
   Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)

``




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


[clang] 9391ff8 - Reland "Rework the printing of attributes (#87281)"

2024-04-09 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2024-04-09T07:26:48Z
New Revision: 9391ff8c86007562d40c240ea082b7c0cbf35947

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

LOG: Reland "Rework the printing of attributes (#87281)"

Original commit message:
"

Commit https://github.com/llvm/llvm-project/commit/46f3ade introduced a notion
of printing the attributes on the left to improve the printing of attributes
attached to variable declarations. The intent was to produce more GCC compatible
code because clang tends to print the attributes on the right hand side which is
not accepted by gcc.

This approach has increased the complexity in tablegen and the attrubutes
themselves as now the are supposed to know where they could appear. That lead to
mishandling of the `override` keyword which is modelled as an attribute in
clang.

This patch takes an inspiration from the existing approach and tries to keep the
position of the attributes as they were written. To do so we use simpler
heuristic which checks if the source locations of the attribute precedes the
declaration. If so, it is considered to be printed before the declaration.

Fixes https://github.com/llvm/llvm-project/issues/87151
"

The reason for the bot breakage is that attributes coming from ApiNotes are not
marked implicit even though they do not have source locations. This caused an
assert to trigger. This patch forces attributes with no source location
information to be printed on the left. That change is consistent to the overall
intent of the change to increase the chances for attributes to compile across
toolchains and at the same time the produced code to be as close as possible to
the one written by the user.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/CMakeLists.txt
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/StmtPrinter.cpp
clang/test/APINotes/retain-count-convention.m
clang/test/APINotes/versioned.m
clang/test/AST/ast-print-method-decl.cpp
clang/test/AST/ast-print-no-sanitize.cpp
clang/test/AST/attr-print-emit.cpp
clang/test/Analysis/scopes-cfg-output.cpp
clang/test/OpenMP/assumes_codegen.cpp
clang/test/OpenMP/assumes_print.cpp
clang/test/OpenMP/assumes_template_print.cpp
clang/test/OpenMP/declare_simd_ast_print.cpp
clang/test/SemaCXX/attr-no-sanitize.cpp
clang/test/SemaCXX/cxx11-attr-print.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
clang/utils/TableGen/TableGen.cpp
clang/utils/TableGen/TableGenBackends.h

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 6584460cf5685e..dc87a8c6f022dc 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -324,13 +324,10 @@ class Spelling {
 }
 
 class GNU : Spelling;
-class Declspec : Spelling {
-  bit PrintOnLeft = 1;
-}
+class Declspec : Spelling;
 class Microsoft : Spelling;
 class CXX11
 : Spelling {
-  bit CanPrintOnLeft = 0;
   string Namespace = namespace;
 }
 class C23
@@ -596,12 +593,6 @@ class AttrSubjectMatcherAggregateRule 
{
 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule;
 
 class Attr {
-  // Specifies that when printed, this attribute is meaningful on the
-  // 'left side' of the declaration.
-  bit CanPrintOnLeft = 1;
-  // Specifies that when printed, this attribute is required to be printed on
-  // the 'left side' of the declaration.
-  bit PrintOnLeft = 0;
   // The various ways in which an attribute can be spelled in source
   list Spellings;
   // The things to which an attribute can appertain
@@ -937,7 +928,6 @@ def AVRSignal : InheritableAttr, 
TargetSpecificAttr {
 }
 
 def AsmLabel : InheritableAttr {
-  let CanPrintOnLeft = 0;
   let Spellings = [CustomKeyword<"asm">, CustomKeyword<"__asm__">];
   let Args = [
 // Label specifies the mangled name for the decl.
@@ -1534,7 +1524,6 @@ def AllocSize : InheritableAttr {
 }
 
 def EnableIf : InheritableAttr {
-  let CanPrintOnLeft = 0;
   // Does not have a [[]] spelling because this attribute requires the ability
   // to parse function arguments but the attribute is not written in the type
   // position.
@@ -3171,7 +3160,6 @@ def Unavailable : InheritableAttr {
 }
 
 def DiagnoseIf : InheritableAttr {
-  let CanPrintOnLeft = 0;
   // Does not have a [[]] spelling because this attribute requires the ability
   // to parse function arguments but the attribute is not written in the type
   // position.

diff  --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 7d53c751c13ac4..2ef6ddc68f4bf3 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -31,16 +31,6 @@ clang_tablegen(AttrList.inc 

[clang] [llvm] [InstCombine] Infer nsw/nuw for trunc (PR #87910)

2024-04-09 Thread Yingwei Zheng via cfe-commits


@@ -897,7 +897,20 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst 
) {
 }
   }
 
-  return nullptr;
+  bool Changed = false;
+  if (!Trunc.hasNoSignedWrap() &&
+  ComputeMaxSignificantBits(Src, /*Depth=*/0, ) <= DestWidth) {
+Trunc.setHasNoSignedWrap(true);
+Changed = true;
+  }
+  if (!Trunc.hasNoUnsignedWrap() &&
+  MaskedValueIsZero(Src, APInt::getBitsSetFrom(SrcWidth, DestWidth),
+/*Depth=*/0, )) {
+Trunc.setHasNoUnsignedWrap(true);
+Changed = true;

dtcxzyw wrote:

> We can't infer nsw, but we can infer nuw.

I prefer to infer both flags here, then we may reuse KnownBits in further 
patches.

> Do you see any reason why doing this in SimplifyDemanded would be problematic?

`SimplifyDemanded` is context-sensitive. IMO it is not the right place to infer 
flags.


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


[clang] [clang] Improve source location in binary type traits diagnostics (PR #88097)

2024-04-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch takes advantage of a recent NFC change that refactored 
`EvaluateBinaryTypeTrait()` to accept `TypeSourceInfo` instead of `QualType` 
c7db450e5c1a83ea768765dcdedfd50f3358d418.
Before:
```
test2.cpp:105:55: error: variable length arrays are not supported in 
'__is_layout_compatible'
  105 |   static_assert(!__is_layout_compatible(int[n], int[n]));
  |   ^
test2.cpp:125:76: error: incomplete type 'CStructIncomplete' where a complete 
type is required
  125 |   static_assert(__is_layout_compatible(CStructIncomplete, 
CStructIncomplete));
  | 
   ^
``` 
After:
```
test2.cpp:105:41: error: variable length arrays are not supported in 
'__is_layout_compatible'
  105 |   static_assert(!__is_layout_compatible(int[n], int[n]));
  | ^
test2.cpp:125:40: error: incomplete type 'CStructIncomplete' where a complete 
type is required
  125 |   static_assert(__is_layout_compatible(CStructIncomplete, 
CStructIncomplete));
  |^
```

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaExprCXX.cpp (+12-9) 
- (modified) clang/test/SemaCXX/type-traits.cpp (+1) 


``diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index dee6b658cd0054..7d7be27a862c2a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5843,7 +5843,7 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
 return false;
 
   if (Self.RequireCompleteType(
-  KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr))
+  Rhs->getTypeLoc().getBeginLoc(), RhsT, 
diag::err_incomplete_type_used_in_type_trait_expr))
 return false;
 
   return BaseInterface->isSuperClassOf(DerivedInterface);
@@ -5866,7 +5866,7 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
 //   If Base and Derived are class types and are different types
 //   (ignoring possible cv-qualifiers) then Derived shall be a
 //   complete type.
-if (Self.RequireCompleteType(KeyLoc, RhsT,
+if (Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
   diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 
@@ -5919,7 +5919,7 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
   return LhsT->isVoidType();
 
 // A function definition requires a complete, non-abstract return type.
-if (!Self.isCompleteType(KeyLoc, RhsT) || Self.isAbstractType(KeyLoc, 
RhsT))
+if (!Self.isCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT) || 
Self.isAbstractType(Rhs->getTypeLoc().getBeginLoc(), RhsT))
   return false;
 
 // Compute the result of add_rvalue_reference.
@@ -5969,11 +5969,11 @@ static bool EvaluateBinaryTypeTrait(Sema , 
TypeTrait BTT, const TypeSourceI
 //   For both, T and U shall be complete types, (possibly cv-qualified)
 //   void, or arrays of unknown bound.
 if (!LhsT->isVoidType() && !LhsT->isIncompleteArrayType() &&
-Self.RequireCompleteType(KeyLoc, LhsT,
+Self.RequireCompleteType(Lhs->getTypeLoc().getBeginLoc(), LhsT,
   diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 if (!RhsT->isVoidType() && !RhsT->isIncompleteArrayType() &&
-Self.RequireCompleteType(KeyLoc, RhsT,
+Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
   diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 
@@ -6029,12 +6029,15 @@ static bool EvaluateBinaryTypeTrait(Sema , 
TypeTrait BTT, const TypeSourceI
   }
   case BTT_IsLayoutCompatible: {
 if (!LhsT->isVoidType() && !LhsT->isIncompleteArrayType())
-  Self.RequireCompleteType(KeyLoc, LhsT, diag::err_incomplete_type);
+  Self.RequireCompleteType(Lhs->getTypeLoc().getBeginLoc(), LhsT, 
diag::err_incomplete_type);
 if (!RhsT->isVoidType() && !RhsT->isIncompleteArrayType())
-  Self.RequireCompleteType(KeyLoc, RhsT, diag::err_incomplete_type);
+  Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT, 
diag::err_incomplete_type);
 
-if (LhsT->isVariableArrayType() || RhsT->isVariableArrayType())
-  Self.Diag(KeyLoc, diag::err_vla_unsupported)
+if (LhsT->isVariableArrayType())
+  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
+  << 1 << tok::kw___is_layout_compatible;
+if (RhsT->isVariableArrayType())
+  Self.Diag(Rhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
   << 1 << tok::kw___is_layout_compatible;
 return Self.IsLayoutCompatible(LhsT, RhsT);
   }
diff --git 

[clang] [clang] Improve source location in binary type traits diagnostics (PR #88097)

2024-04-09 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/88097

This patch takes advantage of a recent NFC change that refactored 
`EvaluateBinaryTypeTrait()` to accept `TypeSourceInfo` instead of `QualType` 
c7db450e5c1a83ea768765dcdedfd50f3358d418.
Before:
```
test2.cpp:105:55: error: variable length arrays are not supported in 
'__is_layout_compatible'
  105 |   static_assert(!__is_layout_compatible(int[n], int[n]));
  |   ^
test2.cpp:125:76: error: incomplete type 'CStructIncomplete' where a complete 
type is required
  125 |   static_assert(__is_layout_compatible(CStructIncomplete, 
CStructIncomplete));
  | 
   ^
``` 
After:
```
test2.cpp:105:41: error: variable length arrays are not supported in 
'__is_layout_compatible'
  105 |   static_assert(!__is_layout_compatible(int[n], int[n]));
  | ^
test2.cpp:125:40: error: incomplete type 'CStructIncomplete' where a complete 
type is required
  125 |   static_assert(__is_layout_compatible(CStructIncomplete, 
CStructIncomplete));
  |^
```

>From 3bc2d71cbe5e5613b430968fe84023a736072e54 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Tue, 9 Apr 2024 10:20:10 +0300
Subject: [PATCH] [clang] Improve source location in binary type traits
 diagnostics

---
 clang/lib/Sema/SemaExprCXX.cpp | 21 -
 clang/test/SemaCXX/type-traits.cpp |  1 +
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index dee6b658cd0054..7d7be27a862c2a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5843,7 +5843,7 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
 return false;
 
   if (Self.RequireCompleteType(
-  KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr))
+  Rhs->getTypeLoc().getBeginLoc(), RhsT, 
diag::err_incomplete_type_used_in_type_trait_expr))
 return false;
 
   return BaseInterface->isSuperClassOf(DerivedInterface);
@@ -5866,7 +5866,7 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
 //   If Base and Derived are class types and are different types
 //   (ignoring possible cv-qualifiers) then Derived shall be a
 //   complete type.
-if (Self.RequireCompleteType(KeyLoc, RhsT,
+if (Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
   diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 
@@ -5919,7 +5919,7 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, const TypeSourceI
   return LhsT->isVoidType();
 
 // A function definition requires a complete, non-abstract return type.
-if (!Self.isCompleteType(KeyLoc, RhsT) || Self.isAbstractType(KeyLoc, 
RhsT))
+if (!Self.isCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT) || 
Self.isAbstractType(Rhs->getTypeLoc().getBeginLoc(), RhsT))
   return false;
 
 // Compute the result of add_rvalue_reference.
@@ -5969,11 +5969,11 @@ static bool EvaluateBinaryTypeTrait(Sema , 
TypeTrait BTT, const TypeSourceI
 //   For both, T and U shall be complete types, (possibly cv-qualified)
 //   void, or arrays of unknown bound.
 if (!LhsT->isVoidType() && !LhsT->isIncompleteArrayType() &&
-Self.RequireCompleteType(KeyLoc, LhsT,
+Self.RequireCompleteType(Lhs->getTypeLoc().getBeginLoc(), LhsT,
   diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 if (!RhsT->isVoidType() && !RhsT->isIncompleteArrayType() &&
-Self.RequireCompleteType(KeyLoc, RhsT,
+Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
   diag::err_incomplete_type_used_in_type_trait_expr))
   return false;
 
@@ -6029,12 +6029,15 @@ static bool EvaluateBinaryTypeTrait(Sema , 
TypeTrait BTT, const TypeSourceI
   }
   case BTT_IsLayoutCompatible: {
 if (!LhsT->isVoidType() && !LhsT->isIncompleteArrayType())
-  Self.RequireCompleteType(KeyLoc, LhsT, diag::err_incomplete_type);
+  Self.RequireCompleteType(Lhs->getTypeLoc().getBeginLoc(), LhsT, 
diag::err_incomplete_type);
 if (!RhsT->isVoidType() && !RhsT->isIncompleteArrayType())
-  Self.RequireCompleteType(KeyLoc, RhsT, diag::err_incomplete_type);
+  Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT, 
diag::err_incomplete_type);
 
-if (LhsT->isVariableArrayType() || RhsT->isVariableArrayType())
-  Self.Diag(KeyLoc, diag::err_vla_unsupported)
+if (LhsT->isVariableArrayType())
+  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
+  << 1 << tok::kw___is_layout_compatible;
+if (RhsT->isVariableArrayType())
+  

[clang] [llvm] [InstCombine] Infer nsw/nuw for trunc (PR #87910)

2024-04-09 Thread Nikita Popov via cfe-commits


@@ -897,7 +897,20 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst 
) {
 }
   }
 
-  return nullptr;
+  bool Changed = false;
+  if (!Trunc.hasNoSignedWrap() &&
+  ComputeMaxSignificantBits(Src, /*Depth=*/0, ) <= DestWidth) {
+Trunc.setHasNoSignedWrap(true);
+Changed = true;
+  }
+  if (!Trunc.hasNoUnsignedWrap() &&
+  MaskedValueIsZero(Src, APInt::getBitsSetFrom(SrcWidth, DestWidth),
+/*Depth=*/0, )) {
+Trunc.setHasNoUnsignedWrap(true);
+Changed = true;

nikic wrote:

We can't infer nsw, but we can infer nuw. Do you see any reason why doing this 
in SimplifyDemanded would be problematic?

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


[clang] [ASTMatchers] fix captureVars assertion failure on capturesVariables (PR #76619)

2024-04-09 Thread Ding Fei via cfe-commits

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


[clang] dbb9749 - [ASTMatchers] fix captureVars assertion failure on capturesVariables (#76619)

2024-04-09 Thread via cfe-commits

Author: Ding Fei
Date: 2024-04-09T15:11:29+08:00
New Revision: dbb9749862481ad6aa82c96f6889b2ebba6f6062

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

LOG: [ASTMatchers] fix captureVars assertion failure on capturesVariables 
(#76619)

Matcher `capturesVar` should check for `capturesVariables()` before
calling `getCaptureVar()` since it asserts this `LambdaCapture` does
capture a variable.

Fixes #76425

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index abf15c8dc49d9e..8d9ccf789d9cb8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -633,6 +633,7 @@ AST Matchers
 - Add ``isExplicitObjectMemberFunction``.
 - Fixed ``forEachArgumentWithParam`` and ``forEachArgumentWithParamType`` to
   not skip the explicit object parameter for operator calls.
+- Fixed captureVars assertion failure if not capturesVariables. (#GH76425)
 
 clang-format
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..8a2bbfff9e9e6b 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4961,6 +4961,8 @@ AST_MATCHER_P(LambdaExpr, hasAnyCapture, 
internal::Matcher,
 /// capturesVar(hasName("x")) matches `x` and `x = 1`.
 AST_MATCHER_P(LambdaCapture, capturesVar, internal::Matcher,
   InnerMatcher) {
+  if (!Node.capturesVariable())
+return false;
   auto *capturedVar = Node.getCapturedVar();
   return capturedVar && InnerMatcher.matches(*capturedVar, Finder, Builder);
 }

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 0edc65162fbe3f..b76627cb9be637 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2321,6 +2321,8 @@ TEST_P(ASTMatchersTest, 
LambdaCaptureTest_BindsToCaptureOfVarDecl) {
   matches("int main() { int cc; auto f = [=](){ return cc; }; }", 
matcher));
   EXPECT_TRUE(
   matches("int main() { int cc; auto f = [&](){ return cc; }; }", 
matcher));
+  EXPECT_TRUE(matches(
+  "void f(int a) { int cc[a]; auto f = [&](){ return cc;}; }", matcher));
 }
 
 TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureWithInitializer) {



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


[clang] [Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (PR #87541)

2024-04-09 Thread via cfe-commits

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

LGTM

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


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-09 Thread via cfe-commits

cor3ntin wrote:

Thanks for the new tests. did you see this comment? 
https://github.com/llvm/llvm-project/pull/86526#pullrequestreview-1976690810

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


[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #85564)

2024-04-09 Thread via cfe-commits

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


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


[clang] [polly] [clang-format] Correctly annotate braces in macros (PR #87953)

2024-04-09 Thread via cfe-commits

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

LGTM

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


[clang] [Clang] Refactor implementation of "Lifetime extension in range-based for loops" (PR #87930)

2024-04-09 Thread via cfe-commits

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

Give @hubert-reinterpretcast a few days to possibly review, otherwise LGTM

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


[clang] [Clang][Sema] Implement approved resolution for CWG2858 (PR #88042)

2024-04-09 Thread via cfe-commits

cor3ntin wrote:

This needs a release note and a test in test/CXX/drs/dr28xx.cpp (and a rerun of 
www/make_cxx_dr_status )

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


[clang] [clang-format] instanceof is a keyword only in Java/JavaScript (PR #88085)

2024-04-09 Thread via cfe-commits

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

LGTM

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


[clang] [clang] Emit bad shift warnings (PR #70307)

2024-04-09 Thread Timm Baeder via cfe-commits


@@ -11444,9 +11444,12 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
, ExprResult ,
   llvm::APSInt Right = RHSResult.Val.getInt();
 
   if (Right.isNegative()) {
-S.DiagRuntimeBehavior(Loc, RHS.get(),
-  S.PDiag(diag::warn_shift_negative)
-<< RHS.get()->getSourceRange());
+if (S.ExprEvalContexts.back().isConstantEvaluated())
+  S.Diag(Loc, diag::warn_shift_negative) << RHS.get()->getSourceRange();
+else
+  S.DiagRuntimeBehavior(Loc, RHS.get(),
+S.PDiag(diag::warn_shift_negative)
+  << RHS.get()->getSourceRange());

tbaederr wrote:

The constant interpreter already diagnoses this:
https://github.com/llvm/llvm-project/blob/51089e360e37962c7841fe0a494ba9fb5368bab2/clang/lib/AST/ExprConstant.cpp#L2850-L2851

and for the test case with the `(-1 << 29)` enum value, this is evaluated in 
`Sema::VerifyIntegerConstantExpresssion()` and it's also diagnosed here:
https://github.com/llvm/llvm-project/blob/51089e360e37962c7841fe0a494ba9fb5368bab2/clang/lib/Sema/SemaExpr.cpp#L18158-L18159

But the diagnostic doesn't show up. Not sure why. If I modify the constant 
interpreter to `return false` in the negative LHS case, I get the expected 
diagnostic:
```console
/home/tbaeder/test.cpp:2:9: error: expression is not an integral constant 
expression
2 | X = (-1<<29) // expected-warning {{shifting a negative signed value 
is undefined}}
  | ^~~~
/home/tbaeder/test.cpp:2:12: note: left shift of negative value -1
2 | X = (-1<<29) // expected-warning {{shifting a negative signed value 
is undefined}}
  |^
```


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


[clang] [llvm] [InstCombine] Infer nsw/nuw for trunc (PR #87910)

2024-04-09 Thread Yingwei Zheng via cfe-commits


@@ -897,7 +897,20 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst 
) {
 }
   }
 
-  return nullptr;
+  bool Changed = false;
+  if (!Trunc.hasNoSignedWrap() &&
+  ComputeMaxSignificantBits(Src, /*Depth=*/0, ) <= DestWidth) {
+Trunc.setHasNoSignedWrap(true);
+Changed = true;
+  }
+  if (!Trunc.hasNoUnsignedWrap() &&
+  MaskedValueIsZero(Src, APInt::getBitsSetFrom(SrcWidth, DestWidth),
+/*Depth=*/0, )) {
+Trunc.setHasNoUnsignedWrap(true);
+Changed = true;

dtcxzyw wrote:

We cannot infer nsw flags from KnownBits (e.g., `trunc (ashr i64 X, 32) to 
i32`). BTW we never set poison-generating flags in `SimplifyDemanded`.


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


<    1   2   3   4